README: add examples for BIP39 wallet path derivation
This commit is contained in:
parent
83b5b71e46
commit
2d6064f8d1
3 changed files with 19 additions and 1 deletions
|
@ -82,7 +82,7 @@ Example:
|
|||
uglifyjs ... --mangle --reserved 'Array,BigInteger,Boolean,ECPair,Function,Number,Point'
|
||||
```
|
||||
|
||||
**NOTE**: If you expect this library to run on an iOS 10 device, ensure that you are using [buffer@5.0.5](https://www.npmjs.com/package/buffer) or greater.
|
||||
**NOTE**: If you expect this library to run on an iOS 10 device, ensure that you are using [buffer@5.0.5](https://www.npmjs.com/package/buffer) or greater.
|
||||
|
||||
### Flow
|
||||
|
||||
|
@ -116,6 +116,7 @@ The below examples are implemented as integration tests, they should be very eas
|
|||
- [Create a CLTV locked transaction where the expiry is past](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/cltv.js#L36)
|
||||
- [Create a CLTV locked transaction where the parties bypass the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/cltv.js#L70)
|
||||
- [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)
|
||||
- [Use BIP39 to generate a BIP32 wallet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/14f983b/test/integration/bip32.js)
|
||||
|
||||
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)!
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"async": "^2.0.1",
|
||||
"bip39": "^2.3.0",
|
||||
"bs58": "^4.0.0",
|
||||
"cb-http-client": "^0.2.0",
|
||||
"coinselect": "^3.1.1",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
var assert = require('assert')
|
||||
var bigi = require('bigi')
|
||||
var bip39 = require('bip39')
|
||||
var bitcoin = require('../../')
|
||||
var crypto = require('crypto')
|
||||
|
||||
|
@ -94,4 +95,19 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
var recovered = recoverParent(neuteredMaster, child)
|
||||
assert.strictEqual(recovered.toBase58(), master.toBase58())
|
||||
})
|
||||
|
||||
it('can use BIP39 to generate BIP32 wallet address', function () {
|
||||
// var mnemonic = bip39.generateMnemonic()
|
||||
var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
assert(bip39.validateMnemonic(mnemonic))
|
||||
|
||||
var seed = bip39.mnemonicToSeed(mnemonic)
|
||||
var root = bitcoin.HDNode.fromSeedBuffer(seed)
|
||||
|
||||
// 1st receive address
|
||||
assert.strictEqual(root.derivePath("m/0'/0/0").getAddress(), '1AVQHbGuES57wD68AJi7Gcobc3RZrfYWTC')
|
||||
|
||||
// 1st change address
|
||||
assert.strictEqual(root.derivePath("m/0'/1/0").getAddress(), '1349KVc5NgedaK7DvuD4xDFxL86QN1Hvdn')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue