tests/README: add BIP32/BIP44 derivation examples
This commit is contained in:
parent
3635a9f078
commit
228a2c1879
2 changed files with 34 additions and 0 deletions
test/integration
|
@ -9,6 +9,38 @@ var ecurve = require('ecurve')
|
|||
var secp256k1 = ecurve.getCurveByName('secp256k1')
|
||||
|
||||
describe('bitcoinjs-lib (BIP32)', function () {
|
||||
it('can create a BIP32 wallet external address', function () {
|
||||
var path = "m/0'/0/0"
|
||||
var root = bitcoin.HDNode.fromSeedHex('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')
|
||||
|
||||
var child1 = root.derivePath(path)
|
||||
|
||||
// option 2, manually
|
||||
var child2 = root.deriveHardened(0)
|
||||
.derive(0)
|
||||
.derive(0)
|
||||
|
||||
assert.equal(child1.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
|
||||
assert.equal(child2.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
|
||||
})
|
||||
|
||||
it('can create a BIP44, bitcoin, account 0, external address', function () {
|
||||
var path = "m/44'/0'/0'/0/0"
|
||||
var root = bitcoin.HDNode.fromSeedHex('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')
|
||||
|
||||
var child1 = root.derivePath(path)
|
||||
|
||||
// option 2, manually
|
||||
var child2 = root.deriveHardened(44)
|
||||
.deriveHardened(0)
|
||||
.deriveHardened(0)
|
||||
.derive(0)
|
||||
.derive(0)
|
||||
|
||||
assert.equal(child1.getAddress(), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au')
|
||||
assert.equal(child2.getAddress(), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au')
|
||||
})
|
||||
|
||||
it('can recover a BIP32 parent private key from the parent public key, and a derived, non-hardened child private key', function () {
|
||||
function recoverParent (master, child) {
|
||||
assert(!master.keyPair.d, 'You already have the parent private key')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue