0
let bip32 = require('bip32');
let bip39 = require('bip39');
let { bech32, bech32m } = require('bech32')

const seed = bip39.mnemonicToSeedSync('rural catch say tooth tell soul road pilot fee board goose wedding');
// ^randomly generated for this question

const node = bip32.fromSeed(seed, bitcoin.networks.testnet);

//legacy account extended private key
console.log("LEGACY: " + node.derivePath("m/44'/0/0").toBase58()); 
//tprv8giQNMeV5drQbXzAxSaVDj5Q1rAuTDZdGWoSx5oaLfuk9rupqVZXoziLgJSpkuauCToZw7BepygJjJaDBWKx5xQLimyg4KFtKnU2E7b99YH

//segwit account extended private key
//how do I take the same inputs, and get a segwit extended private key / zprv

This is how I'm getting my xprv, I'd like to also test out getting a zprv but I'm having trouble finding the documentation for this. I'm assuming it's going to be something using bech32.

0

Key derivation for P2WPKH using the zpub/zprv version bytes is defined in BIP 84. So you can use bip84 library.

let bip84 = require('bip84');

const root = new bip84.fromSeed('rural catch say tooth tell soul road pilot fee board goose wedding')
const child0 = root.deriveAccount(0) // m/84'/0'/0'
console.log(child0)
// zprvAce8anvk7mGXLFgryEKx2b8tETAKuJRFXM1SRN4wuZDw2cwzxYuJ9PJdecA9MJAuAuchhh3cfLfN3SSL8agTL3tJARw6TmgvAKVgcfVcANm
1
  • Thanks! What if instead of a mnemonic, I had a base58 private key? I thought bip84.fromBase58 might work, but no luck. May 13 at 7:37

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.