Skip to content

Commit bc3aef5

Browse files
Ian Colemandcousens
authored andcommitted
add testnet bip49 example
1 parent e7eaf77 commit bc3aef5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/integration/bip32.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ describe('bitcoinjs-lib (BIP32)', function () {
4949
assert.equal(child2.getAddress(), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au')
5050
})
5151

52+
it('can create a BIP49, bitcoin testnet, account 0, external address', function () {
53+
var mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
54+
var seed = bip39.mnemonicToSeed(mnemonic)
55+
var root = bitcoin.HDNode.fromSeedBuffer(seed)
56+
57+
var path = "m/49'/1'/0'/0/0"
58+
var child = root.derivePath(path)
59+
60+
var keyhash = bitcoin.crypto.hash160(child.getPublicKeyBuffer())
61+
var scriptSig = bitcoin.script.witnessPubKeyHash.output.encode(keyhash)
62+
var addressBytes = bitcoin.crypto.hash160(scriptSig)
63+
var outputScript = bitcoin.script.scriptHash.output.encode(addressBytes)
64+
var address = bitcoin.address.fromOutputScript(outputScript, bitcoin.networks.testnet)
65+
66+
assert.equal(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')
67+
})
68+
5269
it('can recover a BIP32 parent private key from the parent public key, and a derived, non-hardened child private key', function () {
5370
function recoverParent (master, child) {
5471
assert(!master.keyPair.d, 'You already have the parent private key')

0 commit comments

Comments
 (0)