Skip to main content

Try it Live

Run BIP39 examples in the interactive playground

Overview

BIP-39 validation ensures mnemonic phrases are correctly formatted, use valid words, and have valid checksums. This prevents typos and ensures wallet recovery success.

Validation Methods

Boolean Validation

Returns true/false without throwing:

Assertion Validation

Throws error with detailed message:

Validation Checks

1. Word Count

Mnemonic must have 12, 15, 18, 21, or 24 words:

2. Wordlist Membership

Each word must exist in BIP-39 English wordlist:

3. Checksum Validation

Last word contains embedded checksum:

Checksum Algorithm

How Checksum Works

12-word mnemonic (128-bit entropy):
  1. Entropy: 128 bits
  2. SHA256 hash: Take first 4 bits
  3. Append: 128 + 4 = 132 bits total
  4. Split: 132 / 11 = 12 words (11 bits each)
  5. Last word: Contains final 4 checksum bits
24-word mnemonic (256-bit entropy):

Checksum Calculation

Validation Error Cases

Wrong Word Count

Invalid Words

Checksum Failures

Whitespace Issues

Case Sensitivity

BIP-39 wordlist is lowercase:

User Input Validation

Sanitize and Validate

Error Messages

Recovery Validation

Verifying Written Backup

Implementation Details

Constant-Time Validation

Checksum validation uses constant-time comparison to prevent timing attacks:

Wordlist Validation

The BIP-39 English wordlist has specific properties:
  • 2048 words (2^11, fits in 11 bits)
  • All lowercase
  • 3-8 characters each
  • First 4 letters unique
  • No similar-looking words

Security Implications

Why Validation Matters

1. Prevent Loss of Funds Invalid mnemonics cannot recover wallets:
2. Detect Transmission Errors Checksum catches single-word changes:
3. Prevent Social Engineering Validate before importing:

Testing

Test Vectors

BIP-39 official test vectors:

Fuzzing

Best Practices

1. Always validate user input
2. Validate immediately after generation
3. Verify backup before clearing original

Examples

References