<p>Key derivation for P2WPKH using the zpub/zprv version bytes is defined in BIP 84. So you can use <a href="https://github.com/Anderson-Juhasc/bip84" rel="nofollow noreferrer">bip84</a> library.</p>
<pre><code>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
</code></pre>

CC BY-SA 4.0
2021-05-13T07:37:01.243Z
Thanks!

What if instead of a mnemonic, I had a base58 private key? I thought bip84.fromBase58 might work, but no luck.
Not My Real Name
CC BY-SA 4.0
2021-05-13T06:31:25.457Z
2021-05-13T06:31:25.457Z
Shigeyuki Azuchi
<pre><code>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(&quot;LEGACY: &quot; + node.derivePath(&quot;m/44'/0/0&quot;).toBase58()); 
//tprv8giQNMeV5drQbXzAxSaVDj5Q1rAuTDZdGWoSx5oaLfuk9rupqVZXoziLgJSpkuauCToZw7BepygJjJaDBWKx5xQLimyg4KFtKnU2E7b99YH

//segwit account extended private key
//how do I take the same inputs, and get a segwit extended private key / zprv
</code></pre>
<p>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.</p>

<segregated-witness><javascript>
Using Javascript, I want to generate a segwit private key (zprv) similarly to how I am generating my legacy base58 extended private key. How?
Not My Real Name
# Using Javascript, I want to generate a segwit private key (zprv) similarly to how I am generating my legacy base58 extended private key. How?

(Asked by: username_0 on 2021-05-13)

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.

**Tags:** segregated-witness, javascript


---

## 1 answers

### Answer by username_1 on 2021-05-13. Score: 0 | Accepted answer

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

> **Comments:**
> **username_0**: Thanks!  What if instead of a mnemonic, I had a base58 private key? I thought bip84.fromBase58 might work, but no luck.  

---

