Skip to content

Commit 2d6064f

Browse files
committed
README: add examples for BIP39 wallet path derivation
1 parent 83b5b71 commit 2d6064f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Example:
8282
uglifyjs ... --mangle --reserved 'Array,BigInteger,Boolean,ECPair,Function,Number,Point'
8383
```
8484

85-
**NOTE**: If you expect this library to run on an iOS 10 device, ensure that you are using [[email protected]](https://www.npmjs.com/package/buffer) or greater.
85+
**NOTE**: If you expect this library to run on an iOS 10 device, ensure that you are using [[email protected]](https://www.npmjs.com/package/buffer) or greater.
8686

8787
### Flow
8888

@@ -116,6 +116,7 @@ The below examples are implemented as integration tests, they should be very eas
116116
- [Create a CLTV locked transaction where the expiry is past](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/cltv.js#L36)
117117
- [Create a CLTV locked transaction where the parties bypass the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/cltv.js#L70)
118118
- [Create a CLTV locked transaction which fails due to expiry in the future](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/cltv.js#L102)
119+
- [Use BIP39 to generate a BIP32 wallet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/14f983b/test/integration/bip32.js)
119120

120121
If you have a use case that you feel could be listed here, please [ask for it](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new)!
121122

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
},
6868
"devDependencies": {
6969
"async": "^2.0.1",
70+
"bip39": "^2.3.0",
7071
"bs58": "^4.0.0",
7172
"cb-http-client": "^0.2.0",
7273
"coinselect": "^3.1.1",

test/integration/bip32.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var assert = require('assert')
44
var bigi = require('bigi')
5+
var bip39 = require('bip39')
56
var bitcoin = require('../../')
67
var crypto = require('crypto')
78

@@ -94,4 +95,19 @@ describe('bitcoinjs-lib (BIP32)', function () {
9495
var recovered = recoverParent(neuteredMaster, child)
9596
assert.strictEqual(recovered.toBase58(), master.toBase58())
9697
})
98+
99+
it('can use BIP39 to generate BIP32 wallet address', function () {
100+
// var mnemonic = bip39.generateMnemonic()
101+
var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
102+
assert(bip39.validateMnemonic(mnemonic))
103+
104+
var seed = bip39.mnemonicToSeed(mnemonic)
105+
var root = bitcoin.HDNode.fromSeedBuffer(seed)
106+
107+
// 1st receive address
108+
assert.strictEqual(root.derivePath("m/0'/0/0").getAddress(), '1AVQHbGuES57wD68AJi7Gcobc3RZrfYWTC')
109+
110+
// 1st change address
111+
assert.strictEqual(root.derivePath("m/0'/1/0").getAddress(), '1349KVc5NgedaK7DvuD4xDFxL86QN1Hvdn')
112+
})
97113
})

0 commit comments

Comments
 (0)