Skip to content

Bitcoin Keys 102: How Wallets Generate Seed Phrases and Private Keys

This article explains how wallets generate seed phrases and derive private keys using standard Bitcoin Propsals (BIP).

  • BIP-32: Hierarchical Deterministic Wallets
  • BIP-39: Mnemonic code for generating deterministic keys
  • BIP-44: Multi-Account Hierarchy for Deterministic Wallets

For more details about a specific wallet, see my articles:

What you need to know first

The article relies on a few cryptographic and Bitcoin notions that it uses without developing them:

  • Private key, public key and address. A Bitcoin private key is a 256-bit secret number; the public key is the point of the secp256k1 elliptic curve obtained by multiplying the curve’s generator by that number, a computation that cannot practically be reversed. The address is then derived from the public key, as detailed in Bitcoin Keys 101 - From seed phrase to address; Overview of ECDSA covers the curve arithmetic.
  • Entropy and brute force. A secret drawn uniformly from \(n\) random bits takes on the order of \(2^n\) guesses to find by exhaustive search. In BIP-39, 12 words encode 128 bits of entropy and 24 words 256 bits, each with a few checksum bits, which is the basis of the 12 versus 24 words discussion.
  • HMAC-SHA512 and PBKDF2. HMAC is a keyed hash construction, used here with SHA-512, and PBKDF2 applies it many times to make guessing slower. BIP-39 turns the mnemonic into the binary seed with PBKDF2-HMAC-SHA512 (2048 iterations), and BIP-32 derives every child key with HMAC-SHA512.
  • Hardened and normal derivation. In a BIP-32 path, an index followed by an apostrophe, such as 44', is hardened: the child can only be computed from the parent’s private key. A normal index, such as the change and address_index levels, can also be derived from the parent’s extended public key, which is how a wallet produces receiving addresses without exposing private keys.
  • Bitcoin script types. The summary table maps each standard to an output type: P2PKH is the legacy pay-to-public-key-hash, P2WPKH its native SegWit version, nested P2WPKH the SegWit version wrapped in a P2SH script for older wallets, and P2TR the Taproot output.

General workflow

As a reminder, the general workflow is the following

1.Generate the seed phrase

2.Create a private key

3.Compute the public key

4.Derive the Bitcoin address from the public key

You can find more details in my article: Bitcoin Keys 101 - From seed phrase to address

Bitcoin-address-bitcoin-address-basic-workflow.drawio


BIP-39: Mnemonic code for generating deterministic keys

Author: Marek Palatinus, Pavol Rusnak, Aaron Voisine, Sean Bowe bip-0039.mediawiki

This BIP describes the implementation of a mnemonic code or mnemonic sentence – a group of easy to remember words – for the generation of deterministic wallets.

It consists of two parts:

  • generating the seed phrase
  • converting it into a binary seed.

This seed can be later used to generate deterministic wallets using BIP-0032 or similar methods.

Schema

Bitcoin-address-BIP-39.drawio

Reference:

Why 24 words instead of 12 ?

24 words, instead of 12, is also used in practice. But is it useful?

Their goal of this greater entropy is to make more difficult to compute the whole seed phase if you know part of the seed phrase

If an attacker knowns:

  • half of a 128-bit code (64 bits), it’s plausible that they’ll be able to brute force the remaining 64 bits.

  • half of a 256-bit code (128 bits), it’s not plausible that they can brute force the other half.

Reference:

The 24 words also help against a keylogger on the Trezor Model One. Its standard recovery has you type the words on the computer, but the device asks for them in a random order and mixes in fake words. A keylogger could therefore learn all the seed words but not their order, and recovering the order is much harder with 24 words than with 12. This applies to the Trezor scrambled recovery, not to every wallet.

Reference:


BIP-32: Hierarchical Deterministic Wallets

See BIP-32

BIP32 defines Hierarchical Deterministic (HD) wallets. This BIP introduces two main concepts

BIP32 introduces two important concepts: key derivation and the hierarchical tree structure.

  • Key Derivation: Keys and addresses are derivedd from a single root key known as the master private key.
    • Child keys are derived from this root in a deterministic way
    • Public keys are generated without revealing the corresponding private keys, which ensures privacy.
  • Hierarchical Tree Structure: Keys can be organized in a multi-level tree structure. A wallet can have and use different child keys, grandchild keys, etc.

Schema from Mastering Bitcoin - ch05_wallets (Andreas M Antonopoulos)

bitcoin-wallet-bip32

See Trezor- What is BIP32?

Summary

Standard Script BIP32 path
BIP44 P2PKH m/44'/0'/0'
BIP49 Nested P2WPKH m/49'/0'/0'
BIP84 P2WPKH m/84'/0'/0'
BIP86 P2TR Single-key m/86'/0'/0'

BIP-44: Multi-Account Hierarchy for Deterministic Wallets

See Bip 0044

This BIP defines a logical hierarchy for deterministic wallets based on an algorithm described in BIP-0032 (BIP32 from now on) and purpose scheme described in BIP-0043.

This BIP defines the following 5 levels in BIP32 path:

m / purpose' / coin_type' / account' / change / address_index

Each level has a specific meaning:

Level Example Description
m   Master node (root of the HD tree)
purpose' 44' Always 44 for BIP-44-compliant wallets
coin_type' 0' Coin type (e.g., 0 = Bitcoin, 2 = Litecoin) — defined in SLIP-44
account' 0' Account index — supports multiple user accounts
change 0 0 = external (receiving), 1 = internal (change)
address_index 0 Address number in the chain

Note:

The value of coin_typeis registed in SLIP-0044 maintained by SatoshiLabs

Blockchain Value
bitcoin 0
Dogecoin 3
Ethereum 60
Solana 501

Annex

Key Terms

Term Definition
BIP A Bitcoin Improvement Proposal, the document format used to specify Bitcoin standards such as BIP-32, BIP-39 and BIP-44.
Private key The 256-bit secret from which the public key and the address are computed, and which signs transactions.
Public key The secp256k1 curve point derived from the private key, from which the Bitcoin address is computed.
Entropy The random bits at the origin of the seed phrase: 128 bits for 12 words and 256 bits for 24 words.
Seed phrase (mnemonic) The group of easy-to-remember words defined by BIP-39 that encodes the wallet’s entropy.
Binary seed The value computed from the mnemonic with PBKDF2-HMAC-SHA512, from which BIP-32 derives the whole tree of keys.
Deterministic wallet A wallet whose keys are all derived from one seed, so that the same seed always regenerates the same keys and addresses.
HD wallet A hierarchical deterministic wallet (BIP-32), whose keys form a multi-level tree of child and grandchild keys below a master key.
Master private key The root key of the BIP-32 tree, written m in derivation paths, from which every child key is derived.
Derivation path The sequence of indexes, such as m/44'/0'/0'/0/0, that locates a key in the BIP-32 tree.
Hardened derivation A derivation step, marked with an apostrophe, whose child can only be computed from the parent’s private key.
Purpose The first level of a BIP-44 path, which names the standard the path follows, such as 44' for BIP-44 or 84' for BIP-84.
Coin type The BIP-44 level that identifies the blockchain, with values registered in SLIP-44, for example 0 for Bitcoin and 60 for Ethereum.
Account The BIP-44 level that lets one seed hold several separate user accounts.
Change The BIP-44 level that separates external (receiving, 0) addresses from internal (change, 1) addresses.
Address index The last BIP-44 level, numbering the successive addresses of an account’s chain.

Reference

You might also enjoy