Roadmap › Blockchain & Web3 Fundamentals › Module: Blockchain Fundamentals
Lessons in this course (15)
2. Cryptography: hashing, keys, signatures and Merkle trees
Basic★ Must knowLesson 2 of 15
- Hash function (SHA-256 in Bitcoin, Keccak-256 in Ethereum): deterministic, fixed-size output, one-way, tiny input change → completely different output (avalanche), collision-resistant.
- Public-key cryptography (elliptic curve secp256k1): a random private key (256-bit) → public key → address (Ethereum: last 20 bytes of Keccak-256 of the public key, shown as
0x...). - Digital signature (ECDSA): proves the transaction was authorised by the private-key holder without revealing it; anyone can verify with the public key.
- Merkle tree: transactions hashed pairwise up to a single Merkle root in the header — lets light clients prove a transaction is in a block with a small proof (O(log n)).
- Seed phrase (BIP-39 mnemonic, 12/24 words) derives many keys (BIP-32/44 hierarchical deterministic wallets). Whoever has the seed phrase owns the funds — no password reset.
js
// Hashing and signing with ethers.js v6
import { keccak256, toUtf8Bytes, Wallet, verifyMessage } from "ethers";
keccak256(toUtf8Bytes("hello")); // 0x1c8aff95...
const wallet = Wallet.createRandom(); // never log real keys
const sig = await wallet.signMessage("Login nonce 4821");
verifyMessage("Login nonce 4821", sig) === wallet.address; // true → "Sign-In with Ethereum" idea