Crypto wallets
Practical, exam-ready notes on crypto wallets: what they store, how deterministic (HD) wallets and mnemonics work, address derivation, wallet types (hot/cold/custodial/hardware), signing and keystore formats, with worked examples and exam guidance.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two sentences: A crypto wallet is the software or device an engineer uses to hold and use cryptographic keys that control blockchain funds and identities. Understanding wallets (how keys are derived, stored, backed up and used to sign transactions) is essential for building secure blockchain clients, smart-contract front-ends, wallets, and integrations.
Key ideas
(Define terms before using.)
Private key — a secret number (usually 256 bits for Bitcoin/Ethereum) used to create signatures that prove control of funds. It must be kept secret. Representations: 32-byte binary, hex string, or encoded in a keystore or mnemonic-derived form.
Public key — the point on an elliptic curve produced by scalar multiplication of the curve generator by the private key. It is derived from the private key and can be shared. For Bitcoin/Ethereum the curve is secp256k1.
Address — a short identifier derived from a public key, used on-chain to receive funds. Example derivations: for Bitcoin take RIPEMD160(SHA256(pubkey)) then Base58Check; for Ethereum take the lower 20 bytes of Keccak-256(uncompressed_pubkey without the 0x04 prefix, i.e., the 64-byte x||y), then prefix 0x (optionally apply EIP-55 mixed-case checksum for display). Note: Ethereum uses Keccak-256 (pre-SHA-3) rather than NIST SHA3-256.
Mnemonic (seed phrase) — a human-readable set of words that encodes entropy and a checksum to allow easy backup. Checksum = first ENT/32 bits of SHA-256(entropy); allowed ENT sizes are 128, 160, 192, 224, or 256 bits. A mnemonic is mapped to a binary seed and then to wallet master keys. Example lengths: 12, 15, 18, 21, 24 words (12 words come from 128 bits entropy + 4-bit checksum = 132 bits = 12×11).
Deterministic wallet (HD wallet) — a wallet that deterministically derives many private/public key pairs from a single root seed. Definition: an HD wallet is a key-generation scheme that, given a single root seed, uses cryptographic key-derivation (with a chain code) to produce a tree of child keys reproducibly (BIP32 defines the algorithm used by many wallets).
Chain code — 32 bytes of extra data in BIP32 that, together with a private or public key, allow deriving child keys without revealing the root secret for non-hardened derivation.
Hardened child key — a child key derived in a way that uses the parent private key (not the parent public key), preventing child public-key derivation from parent public key. Notation: index with apostrophe, e.g., 0' or index >= 2^31.
Derivation path — a human-readable path that names the route in the HD tree, e.g., m/44'/60'/0'/0/0. Standards like BIP44 and BIP84 fix parts of this path for interoperability.
Custodial wallet — a wallet where a third party holds the private keys (exchanges). Non-custodial wallet — user holds keys.
Hot wallet — connected to the internet (mobile/desktop/browser extensions). Cold wallet — offline (hardware wallet, paper wallet, air-gapped computer).
Hardware wallet — a device that isolates private keys and performs signing (many include a secure element or secure MCU); it exposes only signed transactions and public keys to the host.
Keystore file (JSON) — an encrypted JSON file format used by Ethereum clients: it stores an encrypted private key plus KDF and cipher parameters so the user can recover the key with a password.
Signing — producing a digital signature on a transaction or message using the private key; signature allows network validators to accept transactions as authorized by the key owner.
BIP39 (mnemonic to seed): mnemonic -> seed uses PBKDF2 with HMAC-SHA512, salt = "mnemonic" + optional passphrase, 2048 iterations, output 512 bits. Inputs (mnemonic and passphrase) are UTF-8 NFKD-normalized. This seed then feeds BIP32.
BIP32 (HD derivation): master key derived with I = HMAC-SHA512(key = "Bitcoin seed", data = seed). I_L (left 32 bytes) = master private key, I_R (right 32 bytes) = master chain code; I_L must be in [1, n-1] (n = secp256k1 order) or the result is invalid. Child key derivation uses HMAC-SHA512 with data depending on hardened/non-hardened mode and the chain code. Extended keys (xprv/xpub) serialize depth, parent fingerprint, child number, chain code, and key material using Base58Check.
BIP44 standardizes a multi-account hierarchy: path m / purpose' / coin_type' / account' / change / address_index. Draw to explain: a tree with root at top labeled "master seed", branches for purpose', coin_type', account', then split into change (0 external, 1 internal) and address indices.
Diagram to draw (exam): draw a vertical tree. Top node: "mnemonic" -> arrow to "seed" -> arrow to "master private key + chain code (m)". Then draw branches labeled purpose' (e.g., 44'), coin_type', account', then smaller branches for change and address_index. Label hardened apostrophe on the first three levels.
Security principles (laws/assumptions):
- Private keys must be unpredictable (uniform 256-bit) and never reused across contexts when privacy is a concern.
- If only a mnemonic is backed up, the entire wallet can be reconstructed; loss of mnemonic = loss of funds; leakage of mnemonic = compromise.
- Hardware wallets reduce attack surface by keeping keys in secure element and exposing only signatures.
Where derivations are used in software: wallets implement BIP39 -> BIP32 -> BIP44 (or BIP84/BIP49) to provide interoperable account addresses.
Formulas
(Useful syntaxes and formulas to remember.)
mnemonic_length_words = (ENT + ENT/32) / 11 — ENT is entropy length in bits; result is number of 11-bit words. Example: ENT=128 -> (128+4)/11 = 12.
seed = PBKDF2-HMAC-SHA512(password = mnemonic, salt = "mnemonic" + passphrase, iterations = 2048, dkLen = 64) — output 64 bytes (512 bits). Applies in BIP39.
I = HMAC-SHA512(key = "Bitcoin seed", data = seed) — BIP32 master key derivation; I_L (32 bytes) is master private key, I_R is chain code.
derivation path syntax: m / purpose' / coin_type' / account' / change / address_index — example: m/44'/60'/0'/0/0.
Bitcoin address (compressed pubkey flow): pubkey -> SHA-256 -> RIPEMD-160 -> add_version_byte -> checksum = SHA256(SHA256(payload)) first 4 bytes -> Base58Check(payload+checksum).
Ethereum address: address = 0x + last20bytes(Keccak-256(uncompressed_pubkey_without_prefix)); here the uncompressed public key is the 64-byte x||y without the 0x04 prefix; display may use EIP-55 checksum case; note Keccak-256 != NIST SHA3-256.
Private/public key size: private_key_length ≈ 256 bits — the numeric scalar range [1, n-1] where n is curve order. Applies for secp256k1.
Keystore formats (syntax to remember):
- BIP39 mnemonic wordlists of 2048 words; typical mnemonic lengths: 12/15/18/21/24.
- BIP44 path examples:
m/44'/0'/0'/0/0(BTC),m/44'/60'/0'/0/0(ETH older wallets). Also know BIP49 (P2SH-wrapped SegWit, e.g.,m/49'/0'/0'/0/0) and BIP84 (native SegWit/bech32 P2WPKH, e.g.,m/84'/0'/0'/0/0).
Worked examples
(University-exam standard answers, step-by-step.)
Example 1 — Mnemonic length and checksum (numeric step-by-step): Given: ENT = 128 bits.
- Compute checksum length CS = ENT / 32 = 128 / 32 = 4 bits.
- Total bits = ENT + CS = 128 + 4 = 132 bits.
- Each mnemonic word encodes 11 bits, so number of words = 132 / 11 = 12 words. Answer: 12-word mnemonic. (This is the usual exam derivation question.)
Example 2 — From mnemonic to master keys (algorithm trace): Given: mnemonic "legal winner thank year ..." (some 12 words) and an empty passphrase.
- Compute seed = PBKDF2-HMAC-SHA512(password = mnemonic, salt = "mnemonic" + "", iterations = 2048, dkLen = 64). Output: 64 bytes (do not attempt manual HMAC calculation in exam; state algorithm and sizes).
- Compute I = HMAC-SHA512(key = "Bitcoin seed", data = seed). Split I into I_L (first 32 bytes) and I_R (next 32 bytes). I_L is the master private key (m), I_R is the master chain code.
- For child with path m/0'/1: apply hardened derivation where needed (use private-key-based data) and HMAC-SHA512 with parent chain code as key. The exam answer must show the rule, not numeric HMAC values. Final: show that from the seed the wallet deterministically derives all account private keys.
Example 3 — How a hardware wallet signs a transaction (algorithm trace): Task: send from account at path m/44'/60'/0'/0/1.
- Host constructs an unsigned transaction and sends the transaction contents (e.g., PSBT for Bitcoin or full fields/typed data for Ethereum) to the hardware wallet so the device can display and verify details, rather than only a hash.
- Hardware wallet derives private key at the specified path (uses chain code and HMAC steps internally) and computes signature = Sign(private_key, tx_hash) with secp256k1 ECDSA.
- Hardware returns signature to host; host combines signature into serialized transaction and broadcasts. Answer must mention path, local derivation, that the private key never leaves hardware, and signature verification uses public key recovered from signature.
Common mistakes
- Forgetting checksum bits when explaining BIP39 word count; always show ENT/32 calculation.
- Assuming a non-hardened child cannot be compromised if parent public key leaked — actually non-hardened children allow public derivation from parent public key and chain code, so leaking chain code + parent public key allows deriving non-hardened child public keys; moreover, if any one non-hardened child private key is later leaked alongside the parent public key/chain code, the parent private key can be recovered; hardened derivation prevents these attacks.
- Using same address for many payments without explaining privacy implications.
- Saying all keystore JSONs use the same KDF and cipher; different clients may use scrypt or PBKDF2 and different cipher modes.
For your exam
Kinds of questions and what full-marks answers include:
- Definitions: define each bold term precisely (private key, mnemonic, HD wallet, chain code, hardened derivation).
- Short notes: describe BIP39 and BIP32; include exact algorithm names (PBKDF2-HMAC-SHA512, HMAC-SHA512) and parameter sizes.
- Derivations: show ENT->CS->words calculation for BIP39; show derivation path syntax and explain hardened vs non-hardened with index rule (hardened = index >= 2^31 or apostrophe notation).
- Diagrams: draw the mnemonic->seed->master key->child keys tree and label where chain code is used and where hardened edges are.
- Practical/programming: give example derivation path
m/44'/60'/0'/0/0and explain how to import the mnemonic into another wallet (state passphrase behavior). - Security question: list threat model differences between custodial, hot non-custodial, and hardware wallets, and how PSBT or air-gapped signing helps.
A full-marks answer is precise on standards (BIP39/BIP32/BIP44 names and basic parameters), includes sizes (entropy, seed length), and explains trade-offs.
Quick check
- What does a chain code do in BIP32?
- How many checksum bits for 256-bit entropy in BIP39?
- Give the derivation path example for an Ethereum first external address using BIP44.
Answers: The chain code allows child key derivation (it is extra 32 bytes used with HMAC so public-derivation is possible for non-hardened children); CS = ENT/32 = 256/32 = 8 bits; Example path:
m/44'/60'/0'/0/0.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?