I was implementing a small application that computes the bitcoin address starting from a private key (256-bit number). I am surprised about the lack of a single trustworthy reference to this, unlike the case of the BIPs.
The book of Antonopoulos and the bitcoin wiki indicate that the public key (pubK) must go through sha256 and ripemd160 hashes before base58check encoding that results in the final bitcoin address; there are also details about the version byte. But the pubK could be serialized in at least two forms, either the full 65-bytes 0x04<xcoord><ycoord>
or the compressed 33-bytes 0x02/0x03 <xcoord>
representation. Both lead to different bitcoin addresses. The wiki explains step by step how to obtain an address from the compressed pubK, but the image in the page shows a diagram that uses the full pubK representation instead. The http://gobittest.appspot.com/ website, referenced in the bitcoin wiki for testing the WIF format, computes the addresses using the full pubK.
Alright, I know that the private key WIF serialization format has a byte to indicate whether the pubK addresses are computed using the the compressed or full representation (see https://en.bitcoin.it/wiki/Wallet_import_format).
Also add a 0x01 byte at the end if the private key will correspond to a compressed public key.
However,
- it is not mentioned anywhere what is the value of that byte when the full pubK is used.
- ultimately a private key is just a 256-bit number, there should be a unique way to derive an address from there.
Are there actually two addresses for each private key in the bitcoin-core implementation? Isn’t there like a standard way of getting the address?
I was implementing a small application that computes the bitcoin address starting from a private key (256-bit number). I am surprised about the lack of a single trustworthy reference to this, unlike the case of the BIPs.
The book of Antonopoulos and the bitcoin wiki indicate that the public key (pubK) must go through sha256 and ripemd160 hashes before base58check encoding that results in the final bitcoin address; there are also details about the version byte. But the pubK could be serialized in at least two forms, either the full 65-bytes 0x04<xcoord><ycoord>
or the compressed 33-bytes 0x02/0x03 <xcoord>
representation. Both lead to different bitcoin addresses. The wiki explains step by step how to obtain an address from the compressed pubK, but the image in the page shows a diagram that uses the full pubK representation instead. The http://gobittest.appspot.com/ website, referenced in the bitcoin wiki for testing the WIF format, computes the addresses using the full pubK.
Alright, I know that the private key WIF serialization format has a byte to indicate whether the pubK addresses are computed using the the compressed or full representation (see https://en.bitcoin.it/wiki/Wallet_import_format).
Also add a 0x01 byte at the end if the private key will correspond to a compressed public key.
However,
- it is not mentioned anywhere what is the value of that byte when the full pubK is used.
- ultimately a private key is just a 256-bit number, there should be a unique way to derive an address from there.
Are there actually two addresses for each private key in the bitcoin-core implementation? Isn’t there like a standard way of getting the address?