Skip to content

Instantly share code, notes, and snippets.

@arshbot
Last active June 13, 2018 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arshbot/95ebc715660e2c6b43ae0e9ae95f3f10 to your computer and use it in GitHub Desktop.
Save arshbot/95ebc715660e2c6b43ae0e9ae95f3f10 to your computer and use it in GitHub Desktop.
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