Post
Topic
Board Development & Technical Discussion
Merits 2 from 1 user
Re: Need help understanding a transaction
by
DannyHamilton
on 29/12/2014, 22:43:30 UTC
⭐ Merited by ABCbits (2)
What I'm wondering is how do I take the 33 byte 'compressed' form into account?

Note that in the tranaction, there isn't a bitcoin address.  The transaction was not "sent to a bitcoin address", it was sent to a compressed public key.

If you still feel like you want to create a bitcoin address representation for that public key for some reason, then you simply hash the 33 byte public key, instead of hashing the 65 byte public key.

Something like this:

Code:
bool bitcoinCompressedPublicKeyToAddress(const uint8_t input[33], // The 33 bytes long ECDSA public key; first byte will always be either 0x02 or 0x03 followed by a 32 byte components
   uint8_t output[25]) // A bitcoin address (in binary is always 25 bytes long).
{
bool ret = false;

if ( ( input[0] == 0x02 ) || ( ( input[0] == 0x03 ) )
{
uint8_t hash1[32]; // holds the intermediate SHA256 hash computations
SHA256::computeSHA256(input,33,hash1); // Compute the SHA256 hash of the input public ECSDA signature
output[0] = 0; // Store a network byte of 0 (i.e. 'main' network)
RIPEMD160::computeRIPEMD160(hash1,32,&output[1]); // Compute the RIPEMD160 (20 byte) hash of the SHA256 hash
SHA256::computeSHA256(output,21,hash1); // Compute the SHA256 hash of the RIPEMD16 hash + the one byte header (for a checksum)
SHA256::computeSHA256(hash1,32,hash1); // now compute the SHA256 hash of the previously computed SHA256 hash (for a checksum)
output[21] = hash1[0]; // Store the checksum in the last 4 bytes of the public key hash
output[22] = hash1[1];
output[23] = hash1[2];
output[24] = hash1[3];
ret = true;
}
return ret;
}