Hi there,
It's been a few days since I try to do this but it seems I can't get the 3 infos I want :
From a mnemonic, I try to get these informations from a specific derived path, but I can't get the WIF key.
Here is my code :
const seed = bip39.mnemonicToSeed( "muscle skate dawn remember pumpkin foil vacuum such brass grass bullet shoulder" ).toString( 'hex' );
const root = HDKey.fromMasterSeed(new Buffer(seed, 'hex'));
const path = "m/44'/0'/0'/0/0";
const publicKey = root.derive(path).publicKey.toString('hex');
const { address } = bitcoin.payments.p2pkh({ pubkey: root.derive(path).publicKey });
const privKey = root.derive(path).privateKey.toString('hex');
Any help about the WIF syntax from this private key? I've read that I need to use SHA-256 twice then base58 encode but it doesn't seem to work.
And from a random keyPair, I get an undefined address with this code :
const bitcoinNetwork = bitcoin.networks.bitcoin;
const keyPair = bitcoin.ECPair.makeRandom(bitcoinNetwork, new Buffer(seed, 'hex'));
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
const publicKey = keyPair.publicKey.toString('hex');
const privKey = keyPair.toWIF();
Any help would be appreciated, thanks !
Read the examples please.
For the HD stuff
const bitcoin = require('bitcoinjs-lib');
const bip39 = require('bip39');
const HDKey = require('bip32');
const seed = bip39.mnemonicToSeed( "muscle skate dawn remember pumpkin foil vacuum such brass grass bullet shoulder" ).toString( 'hex' );
const root = HDKey.fromSeed(new Buffer(seed, 'hex'));
const path = "m/44'/0'/0'/0/0";
const derived = root.derivePath(path);
const publicKey = derived.publicKey.toString('hex');
const { address } = bitcoin.payments.p2pkh({ pubkey: derived.publicKey });
const privKey = bitcoin.ECPair.fromPrivateKey(derived.privateKey).toWIF();
For the single key stuff.
const bitcoin = require('bitcoinjs-lib');
// the default is bitcoin... so this is useless though.
const bitcoinNetwork = bitcoin.networks.bitcoin;
const keyPair = bitcoin.ECPair.makeRandom({ network: bitcoinNetwork });
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
const publicKey = keyPair.publicKey.toString('hex');
const privKey = keyPair.toWIF();
Most helpful comment
Read the examples please.
For the HD stuff
For the single key stuff.