What's the magic key version bytes for BIP49

0

I'm implementing BIP49-compatible key derivation for bitcoin-s, but I'm having a hard time finding the magic version bytes to use for the extended keys.

I've been looking at BIP49, but can't find anything there.

Also, is there multiple schemes for deriving P2WPKH-nested-in-P2SH? I've been looking at the Samourai fork of BitcoinJ, Trezor's implementation and the test vectors in BIP49, and I can't get the vectors to pass by using the magic version bytes from Trezor/Samourai.

Maybe I'm confused by which magic bytes from Samourai corresponds to mainnet/testnet P2WPKH-nested-in-P2SH, so any clarification is appreciated here. From my understanding, the mainnet version bytes are 0x049D7CB2 (pub) and 0x049D7878 (priv) and testnet are 0x044a5262 (pub) and 0x044a4e28 (priv).

As a final thing, any pointers to test vectors for BIP49 and BIP84 is appreciated. Currently I've come across the BIPs themselves, as well as SLIP132.

torkel

Posted 2019-04-30T11:39:55.540

Reputation: 122

It's always a good practice to post multiple questions separately, so that people who know one but not the other can help you out. For example, I do not have the document for test vectors handy but I have tried to answer other questions. I'll edit my answer if and when I get the test vectors.Ugam Kamat 2019-04-30T14:32:20.577

Answers

0

I'm implementing BIP49-compatible key derivation for bitcoin-s, but I'm having a hard time finding the magic version bytes to use for the extended keys.

It's prefixes are: YPUB = 0x049D7CB2 and YPRV = 0x049D7878

Is there multiple schemes for deriving P2WPKH-nested-in-P2SH?

You are confusing the two. 77429938 that you have linked in Trezor is used to derive ypub. If you scroll down on Samourai code you will see 0x049D7CB2 for ypub which is same as 77429938 in decimal. xpub stands for extended public key and allows you to generate addresses and scan all the funds associated with them, but not spend them. ypub is exactly like an xpub, except the 'Y' denotes with certainty that this particular extended public key belongs to a wallet that is also following the BIP49 bitcoin standard. This instructs the wallet to definitely scan for P2SH(P2WPKH) addresses. There is also zpub, and that instructs the wallet to only scan for bech32 addresses that starts with bc.

Ugam Kamat

Posted 2019-04-30T11:39:55.540

Reputation: 5 180

I'm aware of what an xpub is. The reason I'm asking if there are multiple schemes is that I can't get the tests from BIP49 to line up with the values found in the Trezor and Samourai code. If I use the magic key version bytes from Trezor and Samourai I end up with xprivs that begin with uprv, whereas the BIP49 test vector says I should get a tprv. (making it look like the BIP author just used normal non-segwit testnet bytes)torkel 2019-04-30T15:40:05.470

@torkel tpriv and upriv are for testnet. In https://github.com/trezor/trezor-firmware/blob/master/common/defs/bitcoin/bitcoin.json#L17 the magic numbers listed are for xpriv_magic, xpub_magic, xpub_magic_segwit_p2sh(same as ypub) and xpub_magic_segwit_native(same as zpub)

Ugam Kamat 2019-04-30T15:48:06.153

@ugam-kamet I'm aware that tprv and uprv are for testnet. The issue here is that the values from Trezor and Samourai produce uprv keys, whereas the BIP produce tprv keys. That's why I'm asking if Trezor and Samourai are not BIP49-compliant, causing multiple schemes for deriving P2WPKH-nested-in-P2SHtorkel 2019-04-30T16:41:34.210

@torkel Now I get your confusion. BIP 49 fails to change the HD seed version bytes and as a result it retains the same prefix as BIP 32 i.e. tpriv. Trezor and Samourai uses the ypub and zpub to clearly distinguish if they have to scan for P2SH(P2WPKH). Whatever may be the prefix, the underlying hex of private/public key is the same. So the addresses generated will also be the same. It's just encoding of the keys that is changing.Ugam Kamat 2019-04-30T16:53:57.710

According to Trezor's blog (https://blog.trezor.io/rolling-out-trezor-wallet-segwit-segregated-witness-5700269debc5), they use BIP-49 for P2SH(P2WPKH) derivation

Ugam Kamat 2019-04-30T16:59:32.373