Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var bip39 = require('bip39');
var hdkey = require('hdkey');
var createHash = require('create-hash');
var btcLib = require('bitcoinjs-lib');
var bs58check = require('bs58check');
//const mnemonic = bip39.generateMnemonic(); //generates string
const mnemonic = "gentle mutual speak consider mandate kingdom cash explain soul exile cabin squeeze";
const seed = bip39.mnemonicToSeed(mnemonic); //creates seed buffer
console.log('Seed: ' + seed);
console.log('mnemonic: ' + mnemonic);
const root = hdkey.fromMasterSeed(seed);
const masterPrivateKey = root.privateKey.toString('hex');
console.log('masterPrivateKey: ' + masterPrivateKey);
const addrnode = root.derive("m/44'/0'/0'/0/0");
console.log('addrnodePublicKey: '+ addrnode._publicKey)
const step1 = addrnode._publicKey;
const step2 = createHash('sha256').update(step1).digest();
const step3 = createHash('rmd160').update(step2).digest();
var step4 = Buffer.allocUnsafe(21);
step4.writeUInt8(0x00, 0);
step3.copy(step4, 1); //step4 now holds the extended RIPMD-160 result
const step9 = bs58check.encode(step4);
console.log('Base58Check: ' + step9);
/*
Mainnet
pubKeyHash: 0x00,
Testnet
pubKeyHash: 0x6f,
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.