0

I'm trying to go from seed phrase/mnemonic to payable address using BIP 44. Here is a simplified version of the code I'm using. However, when I compare with https://iancoleman.io/bip39/ the private, public, and address don't match up.

var mnemonic = require('bitcore-mnemonic')
var bitcore = require('bitcore-lib')

var code = new mnemonic("width bicycle axis tell burst outdoor tray episode where they forest meadow enhance twin focus");

var xpriv = code.toHDPrivateKey(bitcore.Networks.livenet);
var derived = xpriv.derive("m/44'/0'/0'/0/0")

var privateKey = derived.privateKey
var publicKey = derived.publicKey
var address = new bitcore.Address(publicKey)

console.log(`address: ${address}`)
console.log(`privateKey: ${privateKey}`)
console.log(`publicKey: ${publicKey}`)

This code outputs:

address: 14TomZRSGPtoPGy9HZA8WfX2veMbDXyAAJ
privateKey: 34fb6aee170bb41fe47f97ab601fea589620cf182ecf031688c25e5491c2c06f
publicKey: 027869eb83bbb44621c868fbd2a31daed4a0f8dbaa73d3fd79a597cdb1afcc9d1d

However when I go to https://iancoleman.io/bip39/ it give as the first address with this seed phrase to be:

path: m/44'/0'/0'/0/0
address: 1BogrbApan5Q9xEFEzwPioRu3ogYkzAQZU
public: 0236f0bf97fa766301e1137bef8377e6f6063b8a576bda57220c7ab6cf531cc992
private: L46hcht5ue2tsSKmPEV2v41CrGU8DEJAP1w7XYPbvJ72v5NBPsPF
1

When you say simplified code it's hard to tell where you are going wrong.

Here's an example of how you can derive a bip44 key pair from a mnemonic using bitcoinjs-lib v3.3.2

let mnemonicInput = 'width bicycle axis tell burst outdoor tray episode where they forest meadow enhance twin focus';
let seedHex = bip39.mnemonicToSeedSync(mnemonicInput).toString('hex');

//"14a3235efb14b096e8cc3082b89e0b629ec5c7b2c6621343b2657cb61853b0830623e97b8aeac416d3377b4da90a4838d9aea4d83e0117fd833049305af46f10"

let root = bitcoin.HDNode.fromSeedHex(seedHex);
let deriv = 44;
let account = 0;
let change = 0;
let index = 0;

let acct = root.derivePath("m/"+deriv+"'/0'/"+account+"'");
let xpub = acct.neutered().toBase58();
let pair = acct.derivePath(change+"/"+index).keyPair;

let wifkey = pair.toWIF();
let address = pair.getAddress();

//"address":"1BogrbApan5Q9xEFEzwPioRu3ogYkzAQZU"
//"wifkey":"L46hcht5ue2tsSKmPEV2v41CrGU8DEJAP1w7XYPbvJ72v5NBPsPF"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.