Replying to Avatar Dr. Hax

Yeah, here's my proof of work.

Library:

https://pypi.org/project/bitcoinlib/

Test vectors from: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

Python code to repro the error:

from bitcoinlib.keys import HDKey

m = HDKey.from_seed('000102030405060708090a0b0c0d0e0f')

assert m.wif_public() == 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'

assert m.wif_private() == 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'

c1 = m.subkey_for_path("m/0")

assert c1.wif_public() == 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'

# fails here ^

assert c1.wif_private() == 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'

what if

# m/0'

c1 = m.subkey_for_path("m/0'")

Reply to this note

Please Login to reply.

Discussion

I think I tried it with and without the single ticks and they seemed to be ignored. I believe the index is an integer type in the code, which is why I decided to experiment with the prime marker.

I saw the public_bytes has the prefix on it, making it a 33 byte string instead of 32 bytes. However, changing that didn't fix it. So if that is a problem, it's not the only problem.

I'll make sure my code matches however it is written in BIP32 before I post my code again though, just to reduce confusion.

OK, accroding gto BIP32 the ser(P) function *does* include the prefix byte, so that part of the code appears correct after all.