You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 17_3_Using_BIP32_in_Libwally.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ In [§17.2](17_2_Using_BIP39_in_Libwally.md), you were able to use entropy to ge
9
9
To create a HD address requires starting with a seed, and then walking down the hierarchy until the point that you create addresses.
10
10
11
11
That starts off easily enough, you just generate a seed, which you already did in the previous section:
12
-
```
12
+
```c
13
13
unsignedchar entropy[16];
14
14
randombytes_buf(entropy, 16);
15
15
@@ -23,7 +23,7 @@ That starts off easily enough, you just generate a seed, which you already did i
23
23
### Generate a Root Key
24
24
25
25
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`):
@@ -34,7 +34,7 @@ As you can see, you'll need to tell it what version of the key to return, in thi
34
34
### Generate xpub & xprv
35
35
36
36
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:
@@ -71,38 +71,38 @@ To generate an address, you thus have to dig down through the whole hierarchy.
71
71
### Generate an Account Key
72
72
73
73
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:
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']`.
78
78
79
79
You can then use that path to generate a new key from your old key:
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:
> :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.
101
101
102
102
### Generate an Address
103
103
104
104
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.
0 commit comments