Bitcoinjs-lib: Different bip32 prefixes for various output scripts

Created on 24 Nov 2017  路  8Comments  路  Source: bitcoinjs/bitcoinjs-lib

When we added segwit accounts at trezor wallet, we realized people are exporting/importing XPUBs wrong - meaning, XPUBs from P2WPKH-in-P2SH HD nodes to "traditional" P2PKH wallets, and that caused confusion.

Both us and Electrum added different xpub version magics for P2WPKH-in-P2SH XPUBs - the segwit xpubs now start at "Ypub".

So instead of network.bip32.public_key, there should be an array? Or something similar (also see https://github.com/trezor/trezor-common/blob/master/coins.json#L14 )

We also added special magic to litecoin p2wpkh-in-p2sh xpubs for this reason ( https://github.com/trezor/trezor-common/blob/master/coins.json#L173 ) - we did, however, just made the p2wpkh-in-p2sh litecoin up and we didn't add all the other 8 magics, since we don't need those in trezor web wallet.

I am not sure how to do this elegantly, and if it's worth breaking compatibility.

how to / question / docs

Most helpful comment

... I鈥檇 reeeeeeally like a BIP first...

But I see where the problem would lie.

Extended keys should use bech32 and just write the script in the hrp, imo.

All 8 comments

The change would need to be somewhere here

https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/networks.js#L10

I am not sure if it's better to add new fields, like private_p2wpkk-in-p2sh, or keep it as private and make that an object.

Also there would need to be changes in hdnode.tobase58...

How we do it in web walet is that we, when importing/exporting xpubs, temporarily clone the network object and replace the network.bip32.public for the cloned object just for the import/export. It is, however, just a quick hack.

@runn1ng what happens when you adding P2WPKH (not in P2SH)? Another version of xpub?

Is there a BIP for it?

Sorry for late follow-up

Nope, there is no BIP for it, but there is no BIP for XPUBs in the first place.(not even in BIP49)

We use what's used in Electrum.

The linked PR (#927) is possibly solving this (haven't tested it)

... I鈥檇 reeeeeeally like a BIP first...

But I see where the problem would lie.

Extended keys should use bech32 and just write the script in the hrp, imo.

@dabura667 write a BIP!
And include the path somewhere

Yea.. reading around, I found only a ML post by ThomasV and a page on electrum.org with the versions, but without reviewing source code it's hard to know what others are actually implementing.

I noticed that two of the prefixes can have multiple scripts, P2SH, or P2PKH. I'd love to know if this is part of the "spec" or if maybe some wallets are just abusing it..

Closing in favour of https://github.com/bitcoinjs/bitcoinjs-lib/pull/927 (and move discussion there)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

panpan2 picture panpan2  路  3Comments

coingeek picture coingeek  路  4Comments

Beardcoding picture Beardcoding  路  3Comments

thrastarson picture thrastarson  路  3Comments

hoshsadiq picture hoshsadiq  路  3Comments