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):- Entropy: 128 bits
- SHA256 hash: Take first 4 bits
- Append: 128 + 4 = 132 bits total
- Split: 132 / 11 = 12 words (11 bits each)
- Last word: Contains final 4 checksum bits
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:Testing
Test Vectors
BIP-39 official test vectors:Fuzzing
Best Practices
1. Always validate user inputExamples
- Validate Mnemonic - Validate mnemonics and handle errors
- Full Workflow - Complete wallet creation with validation

