Skip to content

Instantly share code, notes, and snippets.

@you21979
Last active June 25, 2018 04:36
Show Gist options
  • Save you21979/a69f8c8ae3d30748ea7eba7f983ef4db to your computer and use it in GitHub Desktop.
Save you21979/a69f8c8ae3d30748ea7eba7f983ef4db to your computer and use it in GitHub Desktop.
bitcoinjs-lib hdnode snipet

mnemonic generate

12 word

const mnemonic = bip39.generateMnemonic();

24 word

const mnemonic = bip39.generateMnemonic(256);

mnemonic to masternode

const mnemonicToM = (mnemonic, password, network) => {
    const seed = bip39.mnemonicToSeed(mnemonic, password || "")
    const m = bitcoin.HDNode.fromSeedBuffer(seed, bitcoin.networks[network || "bitcoin"])
    return m
}

extended private key

m.deriveHardened(44).deriveHardened(0).deriveHardened(0).toBase58()
m.derivePath("m/44'/0'/0'").toBase58()

extended public key

m.deriveHardened(44).deriveHardened(0).deriveHardened(0).neutered().toBase58()
m.derivePath("m/44'/0'/0'").neutered().toBase58()

bitcoin address

address

m.derivePath("m/44'/0'/0'/0/0").getAddress()

private key

m.derivePath("m/44'/0'/0'/0/0").keyPair.toWIF()
@sagar2agrawal
Copy link

hello there,
I am new to blockchain development and I want to learn about the above code, could you please help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment