1

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?

2 Answers 2

0

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.

0

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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