<p>I figured it out. You need to store the extended private key, which starts with xpriv. You can get it with bip32.fromSeed(seed).toBase58()</p>

CC BY-SA 4.0
2021-10-10T18:04:53.567Z
2021-10-10T18:04:53.567Z
Infinite Recursion
<p>WIF is an encoding scheme meant for raw private keys, which are usually 32 bytes long.</p>
<p>A seed is not a private key, so encoding it as such is probably not a good idea.</p>
<p>An extended key is 32 bytes for the private key plus 32 bytes for the chain code, and more bytes for the depth and child index. Like a seed, it should not be encoded in WIF format.</p>

CC BY-SA 4.0
2021-10-06T02:09:16.327Z
2021-10-06T02:09:16.327Z
Sachin Meier
<p>I'm using the bitcoinjs collection of libraries, specifically <a href="https://github.com/bitcoinjs/wif" rel="nofollow noreferrer">https://github.com/bitcoinjs/wif</a>, <a href="https://github.com/bitcoinjs/bip32" rel="nofollow noreferrer">https://github.com/bitcoinjs/bip32</a> and <a href="https://github.com/bitcoinjs/bip39" rel="nofollow noreferrer">https://github.com/bitcoinjs/bip39</a> with nodejs.</p>
<p>I have a mnemonic and can get the seed of it using bip39:</p>
<pre><code>&gt; const mnemonic = 'laptop arrest wide slice extend today jelly bachelor interest similar debris behind'
&gt; const seed = bip39.mnemonicToSeedSync(mnemonic)
&gt; seed
&lt;Buffer 11 ae 55 c9 cb c0 c8 5c 09 d2 4e 36 4a 90 a6 64 09 fe 2b 87 47 79 4a 7b 03 39 76 ff 4b e9 28 59 84 74 81 cf 07 a2 7f c6 91 67 ec 04 7c a3 dc d9 23 9b ... 14 more bytes&gt;
</code></pre>
<p>However, encoding it using wif and then decoding it only contains the first 16 bytes of the seed:</p>
<pre><code>&gt; wif.decode(wif.encode(0x80, seed, true)).privateKey
&lt;Buffer 11 ae 55 c9 cb c0 c8 5c 09 d2 4e 36 4a 90 a6 64 09 fe 2b 87 47 79 4a 7b 03 39 76 ff 4b e9 28 59&gt;
</code></pre>
<p>This is a problem because when I use bip32.fromSeed, the derived keys are not the same. Using bip32.fromPrivateKey solves this issue, but only if I have the chaincode, which still needs to be somehow stored separately.</p>
<p>What am I doing wrong? Thanks in advance. When using mnemonics, am I supposed to discard part of the seed so it aligns with the WIF?</p>

<bip32-hd-wallets><mnemonic-seed><bitcoinjs><wallet-import-format>
Storing entire seed from bip39 mnemonic using WIF
Infinite Recursion
# Storing entire seed from bip39 mnemonic using WIF

(Asked by: username_0 on 2021-09-30)

I'm using the bitcoinjs collection of libraries, specifically <https://github.com/bitcoinjs/wif>, <https://github.com/bitcoinjs/bip32> and <https://github.com/bitcoinjs/bip39> with nodejs.

I have a mnemonic and can get the seed of it using bip39:

```
> const mnemonic = 'laptop arrest wide slice extend today jelly bachelor interest similar debris behind'
> const seed = bip39.mnemonicToSeedSync(mnemonic)
> seed
<Buffer 11 ae 55 c9 cb c0 c8 5c 09 d2 4e 36 4a 90 a6 64 09 fe 2b 87 47 79 4a 7b 03 39 76 ff 4b e9 28 59 84 74 81 cf 07 a2 7f c6 91 67 ec 04 7c a3 dc d9 23 9b ... 14 more bytes>

```

However, encoding it using wif and then decoding it only contains the first 16 bytes of the seed:

```
> wif.decode(wif.encode(0x80, seed, true)).privateKey
<Buffer 11 ae 55 c9 cb c0 c8 5c 09 d2 4e 36 4a 90 a6 64 09 fe 2b 87 47 79 4a 7b 03 39 76 ff 4b e9 28 59>

```

This is a problem because when I use bip32.fromSeed, the derived keys are not the same. Using bip32.fromPrivateKey solves this issue, but only if I have the chaincode, which still needs to be somehow stored separately.

What am I doing wrong? Thanks in advance. When using mnemonics, am I supposed to discard part of the seed so it aligns with the WIF?

**Tags:** bip32-hd-wallets, mnemonic-seed, bitcoinjs, wallet-import-format


---

## 2 answers

### Answer by username_0 on 2021-10-10. Score: 1

I figured it out. You need to store the extended private key, which starts with xpriv. You can get it with bip32.fromSeed(seed).toBase58()


---

### Answer by username_1 on 2021-10-06. Score: 1

WIF is an encoding scheme meant for raw private keys, which are usually 32 bytes long.

A seed is not a private key, so encoding it as such is probably not a good idea.

An extended key is 32 bytes for the private key plus 32 bytes for the chain code, and more bytes for the depth and child index. Like a seed, it should not be encoded in WIF format.


---

