Skip to content

Instantly share code, notes, and snippets.

@BluSyn
Last active January 28, 2021 20:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BluSyn/2025c2f444fa0b9c2c1d to your computer and use it in GitHub Desktop.
Save BluSyn/2025c2f444fa0b9c2c1d to your computer and use it in GitHub Desktop.
Bitcoin BIP39 mnemonic seed to extended MPK (watch-only public key)
/**
* Converts mnemonic recovery seed
* into xpub for watch-only services
*
* Dependencies:
* npm install bitcore bitcore-mnemonic
*/
var bitcore = require('bitcore');
var bitcoreMnemonic = require('bitcore-mnemonic');
var mnemonic = '<ENTER 12-word or 24-word mnemonic seed>';
var seed = new bitcoreMnemonic(mnemonic);
var hdnode = seed.toHDPrivateKey();
// BREAD WALLET and others
// BIP32 (m/0')
var parent = hdnode.derive("m/0'");
console.log(parent.xpubkey);
// TREZOR and others
// BIP44 (m/44'/0'/0')
// var parent = hdnode.derive("m/44'/0'/0'");
// Confirm correct derivation by checking first address
// compare with first receive address generated by your app
var first = parent.derive('m/0/0').publicKey;
console.log(new bitcore.Address(first).toString());
@nixilb
Copy link

nixilb commented Dec 26, 2020

ReferenceError: bitcoreMnemonic is not defined

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