Last active
January 28, 2021 20:21
-
-
Save BluSyn/2025c2f444fa0b9c2c1d to your computer and use it in GitHub Desktop.
Bitcoin BIP39 mnemonic seed to extended MPK (watch-only public key)
This file contains 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
/** | |
* 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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReferenceError: bitcoreMnemonic is not defined