ebellocchia/py_crypto_hd_wallet

How to derive a private key?

stdusr opened this issue · 3 comments

How to derive a private key?

Hello,
the private key is only one and it is correct, otherwise all addresses and public keys will be wrong. The bytes of the private key are in the raw_priv key of the dictionary. However, to make the key easier to read, various formats are used, but they always refer to the same private key.
Usually, wallets support WIF encoding, which is wif_priv in the dict, or the extended format, which is ex_priv in the dict.
As far as I know, for Bitcoin, the WIF encoding starts with 5 (for main net) or 9 (for test net). However, I noticed now the following sentence in the WIF documentation:

Drop the first byte (it should be 0x80). If the private key corresponded to a compressed public key, also drop the last byte (it should be 0x01). If it corresponded to a compressed public key, the WIF string will have started with K or L instead of 5 (or c instead of 9 on testnet). This is the private key.

That's the reason why the WIF computed by my library is different from the one you find in the website (I'm not adding the 0x01 at the end). I can update the bip_utils library for supporting it.

Thanks

Thank you very much.
I updated both the wallet and the bip_utils library to generate the correct WIF encoding, I also took advantage of this for adding Bitcoin Cash and BitcoinSV to supported coins.

You're welcome.
Ethereum doesn't support WIF format, you can simply use the raw bytes of the private key for it (raw_priv in the dict, just add 0x in front of it and you'll get the same value of the website).