Last active
August 30, 2017 15:41
-
-
Save juscamarena/8b3928599f4c9658a39cf30f632eea95 to your computer and use it in GitHub Desktop.
Generating Segwit Addresses bip49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bitcoin = require('bitcoinjs-lib') | |
const assert = require('assert') | |
// example mnemonic: bless slide survey easy fossil river audit excess cry kingdom very valid country coffee addict | |
// acount extended pub key m/49'/0'/0'/0 | |
const XPUB = 'xpub6DSniLEmH3haqnDkeV8vEbCaJeWn3NybeiHajgPY2TktB7DovU1ba6JoDn3JDYZNj8hSAKNCdAMMcrDPYGYa4Rg1ZGtB6p9Yv5EJqLwSPn5'; | |
index = 0 | |
let hdNode = bitcoin.HDNode.fromBase58(XPUB); | |
let pubKey = hdNode.derivePath("0/" + index).keyPair.getPublicKeyBuffer(); | |
let witnessScript = bitcoin.script.witnessPubKeyHash.output.encode(bitcoin.crypto.hash160(pubKey)) | |
let scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(witnessScript)) | |
//console.log(scriptPubKey); | |
let address = bitcoin.address.fromOutputScript(scriptPubKey) | |
console.log(address); | |
assert.strictEqual(address, "3N7vBWpEY2kzUAdUuGFZUtcwGbMn5xzBNk"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Verify using: https://iancoleman.github.io/bip39/#english