Study Notes: Chapter 4 – Wallets

1. Why Do We Need a Wallet?

Q1: What is a wallet in the context of Bitcoin (or cookie tokens)?

A wallet is a software application that generates and stores your private keys, creates addresses, facilitates payments, and keeps track of your funds. It does not store the money itself (that’s in the blockchain or spreadsheet) but holds the keys to spend it.

04 01
Figure 1. Bitcoin (cookie token) wallets

Q2: What common tasks should a wallet handle?

2. First Wallet Version & Key Features

Q3: How does the wallet improve the user experience compared to emailing Lisa manually?

The wallet automates most steps: it handles address creation, digital signatures, and prepares the payment details (amount, recipient address) for the user. It also updates balances automatically by checking the spreadsheet/ledger.

04 02
Figure 2. Buying a cookie with the new wallet app using QR codes

3. Backing Up Private Keys

Q4: Why do we need to back up our private keys?

Because losing your private keys means permanently losing access to your funds. The ledger (spreadsheet/blockchain) won’t care who lost a key; it only checks digital signatures.

04 05
Figure 5. Simple backup of private keys (unencrypted) has potential risks.

Q5: What are some initial (but imperfect) solutions for backing up private keys?

Q6: What are the main drawbacks of password-encrypted backups?

4. Hierarchical Deterministic Wallets

04 07
Figure 7. Backing up a single random seed is enough for all future addresses.

Q7: What is a hierarchical deterministic (HD) wallet?

An HD wallet derives all of its private keys from a single master seed. This seed alone can recreate the entire family (tree) of private keys, enabling a single backup to restore them all.

Q8: Why is this approach so much better for backups?

You only need to back up once (the seed). Any new addresses derived in the future remain backed up as long as you have that seed. No repeated exports, no repeated backups each time a new key is generated.

04 08
Figure 8. A tree of keys under two "accounts": shopping and savings

5. Seeds and Mnemonic Sentences (BIP39)

Q9: Instead of storing a hex seed like 16432a2077…, how can we make it more human-friendly?

We use a mnemonic sentence of 12 or 24 English words. This is easier to write down and verify. The wallet can convert it back into the seed if needed.

04 16
Figure 16. Generating a seed from a mnemonic (12 or 24 words)

Q10: How does the mnemonic system protect against typos?

Each mnemonic includes a short checksum (several bits), so if the user writes down incorrect words, there’s a high chance the wallet will detect it when restoring.

6. Extended Public (XPUB) and Private (XPRV) Keys

Q11: What is an xprv and how does it differ from a normal private key?

An xprv (extended private key) contains two parts:

This setup allows generating child keys (and child chain codes) in a hierarchical fashion.

04 19
Figure 19. An xpub has a public key + a chain code; an xprv has a private key + a chain code

Q12: What about xpub (extended public key)?

Similarly, an xpub is the public key + chain code. With an xpub, you can generate new addresses (child public keys), but cannot spend funds because you don’t have the private keys.

Q13: Why is xpub so useful on insecure servers?

A web server can generate many fresh receiving addresses using the xpub (no private keys needed), so even if the server is hacked, the attacker cannot steal funds—it only exposes public info.

7. Hardened Key Derivation

Q14: What's the risk if someone has a normal child private key and the parent xpub?

They can potentially compute the entire parent xprv (and thus spend all other child keys in that branch). This is because normal derivation uses standard math that can be reversed with these two pieces of info.

04 24
Figure 24. Hardened child derivation uses the parent private key in the hash, preventing someone with the child private key and the parent xpub from calculating the parent private key.

Q15: How does hardened derivation fix that?

Hardened derivation uses the parent private key in the hash instead of the parent public key. That way, the child private key cannot be reversed from the xpub.

8. Public Key Math (Optional Deep Dive)

Q16: What is the elliptic curve used in Bitcoin, and why is it secure?

Bitcoin uses the secp256k1 elliptic curve y^2 = x^3 + 7 (mod p). It's secure because there's no known efficient "inverse" for the multiplication operation that maps a private key to a public key.

04 30
Figure 30. Summarizing how child public keys come from parent xpub using special addition operations.

9. Key Takeaways


End of Study Notes for Chapter 4. These principles—wallet apps, HD wallets, mnemonic sentences, and xpub/xprv—are crucial for convenient and secure management of Bitcoin or cookie tokens!