BC2: Keys and digital signatures

Lesson 1 of 5 ยท reading 15โ€“25 minutes; practice and project time is on the module page

Public and private keys, and addresses

๐ŸŽฏYou'll be able to

Explain a key pair and how an Ethereum address is made from a public key.

๐Ÿ The everyday picture

A letterbox with a slot: anyone can find it by its address and post into it, but only the person with the key can open it.

๐Ÿ“˜What it really is

๐Ÿ“A worked example

Input: the practice network's first test account, printed by npm run chain.

Steps:

  1. The private key is 64 hexadecimal characters. It's public knowledge for this practice network, so it must not hold anything of value.
  2. ethers.js computes the public key from it, hashes it with Keccak-256 and keeps the last 20 bytes: the address.
  3. Typing the address with one wrong letter fails the EIP-55 checksum, and ethers refuses it.

Expected output: an address you can share and a key you don't.

๐ŸŒWhere it's used

๐Ÿ“Case scenario

A developer generated a key with a simple random function seeded with the time, for a "quick test". The key was later used for real funds. Someone who guessed the approximate time searched the possible seeds and found it. A cryptographically secure generator would have made that search hopeless.

๐Ÿ–ฑ๏ธTry it

Run node -e "const {Wallet}=require('ethers');const w=Wallet.createRandom();console.log(w.address)" in the kit folder twice. Success: two different addresses, and you didn't print or save the keys.

โš ๏ธCommon mistakes

๐Ÿ› ๏ธFor your project

Project 2's owners are five addresses; the vault knows nothing about the people except which addresses may approve.

โœ…Quick check

How is an Ethereum address made?

Show the answer

From the last 20 bytes of the Keccak-256 hash of the public key.

Why must a private key come from a strong random source?

Show the answer

A predictable key can be found by searching the possible values.

โ† BackBC2
ProLearners Assist