Skip to content

Commit 1a629fc

Browse files
authored
Merge pull request #473 from csralvall/patch-17_3
Fix typo and add syntax highlighting in chapter 17.3
2 parents bb9be87 + 2a4485f commit 1a629fc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

17_3_Using_BIP32_in_Libwally.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In [§17.2](17_2_Using_BIP39_in_Libwally.md), you were able to use entropy to ge
99
To create a HD address requires starting with a seed, and then walking down the hierarchy until the point that you create addresses.
1010

1111
That starts off easily enough, you just generate a seed, which you already did in the previous section:
12-
```
12+
```c
1313
unsigned char entropy[16];
1414
randombytes_buf(entropy, 16);
1515

@@ -23,7 +23,7 @@ That starts off easily enough, you just generate a seed, which you already did i
2323
### Generate a Root Key
2424
2525
With a seed in hand, you can then generate a master extended key with the `bip32_key_from_seed_alloc` function (or alternatively the `bip32_key_from_seed`, which doesn't do the `alloc`):
26-
```
26+
```c
2727
struct ext_key *key_root;
2828
lw_response = bip32_key_from_seed_alloc(seed,sizeof(seed),BIP32_VER_TEST_PRIVATE,0,&key_root);
2929
```
@@ -34,7 +34,7 @@ As you can see, you'll need to tell it what version of the key to return, in thi
3434
### Generate xpub & xprv
3535

3636
Whenever you have a key in hand, you can turn it into xpub or xprv keys for distribution with the `bip32_key_to_base58` command. You just tell it whether you want a `PRIVATE` (xprv) or `PUBLIC` (xpub) key:
37-
```
37+
```c
3838
char *xprv;
3939
lw_response = bip32_key_to_base58(key_root, BIP32_FLAG_KEY_PRIVATE, &xprv);
4040

@@ -71,38 +71,38 @@ To generate an address, you thus have to dig down through the whole hierarchy.
7171
### Generate an Account Key
7272

7373
One way to do this is to use the `bip32_key_from_parent_path_alloc` function to drop down several levels of a hierarchy. You embed the levels in an array:
74-
```
74+
```c
7575
uint32_t path_account[] = {BIP32_INITIAL_HARDENED_CHILD+84, BIP32_INITIAL_HARDENED_CHILD+1, BIP32_INITIAL_HARDENED_CHILD};
7676
```
7777
Here we'll be looking at the zeroth hardened child (that's the account) or the first hardened child (that's testnet coins) of the 84th hardened child (that's the BIP84 standard): `[m/84'/1'/0']`.
7878
7979
You can then use that path to generate a new key from your old key:
80-
```
80+
```c
8181
struct ext_key *key_account;
8282
lw_response = bip32_key_from_parent_path_alloc(key_root,path_account,sizeof(path_account),BIP32_FLAG_KEY_PRIVATE,&key_account);
8383
```
8484
Every time you have a new key, you can use that to generate new xprv and xpub keys, if you desire:
85-
```
85+
```c
8686
lw_response = bip32_key_to_base58(key_account, BIP32_FLAG_KEY_PRIVATE, &a_xprv);
8787
lw_response = bip32_key_to_base58(key_account, BIP32_FLAG_KEY_PUBLIC, &a_xpub);
8888
```
8989

9090
### Generate an Address Key
9191

9292
Alternatively, you can use the `bip32_key_from_parent_alloc` function, which just drops down one level of the hierarchy at a time. The following example drops down to the 0th child of the account key (which is the external address) and then the 0th child of that. This would be useful because then you could continue generating the 1st address, the 2nd address, and so on from that external key:
93-
```
93+
```c
9494
struct ext_key *key_external;
9595
lw_response = bip32_key_from_parent_alloc(key_account,0,BIP32_FLAG_KEY_PRIVATE,&key_external);
9696

9797
struct ext_key *key_address;
9898
lw_response = bip32_key_from_parent_alloc(key_external,0,BIP32_FLAG_KEY_PRIVATE,&key_address);
9999
```
100-
> :warning: **WARNING::** At some point in this hierarchy, you might decide to generate `BIP32_FLAG_KEY_PUBLIC` instead of `BIP32_FLAG_KEY_PRIVATE`. Obviously this decision will be based on your security and your needs, but remember that you only need a public key to generate the actual address.
100+
> :warning: **WARNING:** At some point in this hierarchy, you might decide to generate `BIP32_FLAG_KEY_PUBLIC` instead of `BIP32_FLAG_KEY_PRIVATE`. Obviously this decision will be based on your security and your needs, but remember that you only need a public key to generate the actual address.
101101
102102
### Generate an Address
103103

104104
Finally, you're ready to generate an address from your final key. All you do is run `wally_bip32_to_addr_segwit` using your final key and a description of what sort of address this is.
105-
```
105+
```c
106106
char *segwit;
107107
lw_response = wally_bip32_key_to_addr_segwit(key_address,"tb",0,&segwit);
108108

0 commit comments

Comments
 (0)