ebellocchia / py_crypto_hd_wallet

HD wallet for cryptocurrencies based on my bip_utils library
MIT License
52 stars 34 forks source link

How to derive a private key? #2

Closed stdusr closed 4 years ago

ebellocchia commented 4 years ago

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 _rawpriv 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 _wifpriv in the dict, or the extended format, which is _expriv 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 _biputils library for supporting it.

Thanks

ebellocchia commented 4 years ago

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.

ebellocchia commented 4 years ago

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