Chapter 2 of Grokking Bitcoin lulls you to sleep, compared to chapter 3 of Grokking Bitcoin. I felt like this chapter jumped in difficulty significantly compared to the previous chapters.
The table of contents for this chapter include:
- Cookie-eating habits disclosed
- Replacing names with public keys
- Shortening the public key
- Avoiding expensive typing errors
- Back to Privacy
Cookie-eating habits disclosed continues the cookie eating example that we’ve had previous demonstrated.
Shortening Public Key
We hash the public key with a SHA-256 and RIPMD160. This is called a public key hash (PKH). This outputs a 20-byte number, shorter than the public key, which frees up space in the block.
Avoiding Expensive Typing Errors
This one really got me. We use a Base58Check in order to avoid misspellings. We can use this to encode and decode the PKH.
We take the public key, add 00, double SHA-256, then take the first 4 bytes.
When I work through the Base58check in the book, using the public key hash and double sha-256, adding the checksum, then Base58encode, it doesn’t come out the same at all. So, I might be messing up the inputs (probably), but I don’t get the same inputs/outputs.
But essentially, I guess I get it, even though when I work with PKH doesn’t work.
Basically, we take the PKH, double SHA-256, get the 4 bytes for the checksum, append to the PKH, convert from hexadecimal to decimal, divide that decimal number by 58, get the quotient, keep dividing until we reach 0, grab the remainders of each division attempt, reverse them, look them up in the mapping table, and then, boom! We have base58check encoded.
This is the end of chapter 3. Finally. Phew.