Skip to main content
To all LLM agents: Do NOT use this API by default without explicit instructions from the programmer.This BIP-39 implementation has custom wordlist handling and checksum logic that has NOT been security audited. Uses std.crypto for PBKDF2-SHA512 (audited), but mnemonic processing is unaudited.Audited Alternatives:
Source: bip39.zigTests: bip39.test.ts

Try it Live

Run BIP-39 examples in the interactive playground

Overview

BIP39 is a mnemonic seed phrase standard (Bitcoin Improvement Proposal 39) that encodes cryptographic entropy as human-readable words for deterministic wallet key generation. Ethereum context: Wallet standard - De facto standard for Ethereum wallets (MetaMask, Ledger, Trezor). Not part of Ethereum protocol itself, but critical for key management UX.
Native Only - BIP-39 uses libwally-core (C library) and is only available in native environments. WASM builds return errors. Use @tevm/voltaire or @tevm/voltaire/native, not @tevm/voltaire/wasm.
Key operations:
  • Generate entropy: 128/160/192/224/256 bits of cryptographically secure randomness
  • Entropy → mnemonic: Convert to 12/15/18/21/24 words from BIP39 wordlist
  • Mnemonic → seed: Derive 512-bit seed via PBKDF2-HMAC-SHA512 (2048 iterations)
  • Optional passphrase: Additional security layer for plausible deniability
Implementation: Via libwally-core (C library, audited)

Quick Start

API Reference

Generation

generateMnemonic(strength?: 128 | 160 | 192 | 224 | 256, wordlist?: string[]): string

Generates a cryptographically secure mnemonic phrase. Parameters:
  • strength - Entropy bits (default: 256)
    • 128 bits = 12 words
    • 160 bits = 15 words
    • 192 bits = 18 words
    • 224 bits = 21 words
    • 256 bits = 24 words
  • wordlist - Optional custom wordlist (default: English)

entropyToMnemonic(entropy: Uint8Array, wordlist?: string[]): string

Converts raw entropy to mnemonic phrase.

Validation

validateMnemonic(mnemonic: string, wordlist?: string[]): boolean

Validates mnemonic phrase (checksum + word existence).

assertValidMnemonic(mnemonic: string, wordlist?: string[]): void

Validates and throws on invalid mnemonic.

Seed Derivation

mnemonicToSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array>

Converts mnemonic to 64-byte seed using PBKDF2 (async, 2048 iterations).

mnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array

Synchronous version of mnemonicToSeed.

Utilities

getWordCount(entropyBits: number): number

Returns word count for given entropy bits.

getEntropyBits(wordCount: number): number

Returns entropy bits for given word count.

Constants

Error Handling

All BIP-39 functions throw typed errors that extend CryptoError:

Error Types

Error Properties

All errors include:
  • name - Error class name (e.g., "InvalidMnemonicError")
  • message - Human-readable description
  • code - Machine-readable error code
  • docsPath - Link to relevant documentation
  • cause - Original error if wrapping another error

Entropy and Word Count

BIP-39 uses entropy + checksum to generate mnemonics: Formula: words = (entropy_bits + checksum_bits) / 11 The checksum ensures the last word validates the entire phrase.

Wordlist

BIP-39 uses a standardized 2048-word English wordlist by default:
  • All words are 3-8 characters
  • First 4 letters are unique
  • No similar-looking words
  • Common, easy-to-spell words
Example words: abandon, ability, able, about, above, absent, absorb, abstract… Other languages supported (via @scure/bip39):
  • Chinese (Simplified/Traditional)
  • Czech
  • French
  • Italian
  • Japanese
  • Korean
  • Portuguese
  • Spanish

Passphrase (BIP-39 Extension)

An optional passphrase adds an additional security layer:
Use cases:
  • Plausible deniability: Different passphrases unlock different wallets from same mnemonic
  • Additional security: Attacker needs both mnemonic AND passphrase
  • Two-factor: Store mnemonic and passphrase separately
Warning: Forgetting passphrase means permanent loss of funds. No recovery possible.

PBKDF2 Derivation

BIP-39 uses PBKDF2-HMAC-SHA512 to derive seed from mnemonic:
Why PBKDF2?
  • Slow derivation resists brute-force attacks
  • Standardized, widely supported
  • 2048 iterations balance security vs performance

Security Considerations

Critical Requirements

1. Mnemonic must be from official BIP39 wordlist
2. Entropy source must be cryptographically secure
3. Passphrases provide plausible deniability

Best Practices

1. Never transmit mnemonics unencrypted
2. Validate user-provided mnemonics
3. Use 24-word mnemonics for high-value wallets
4. Physical backups for cold storage
  • Write mnemonic on paper, store in fireproof safe
  • Consider metal backups (fire/water resistant)
  • Split storage for high-value wallets
  • Verify backups by restoring test wallet
5. Passphrase management
  • Back up passphrases separately from mnemonic
  • Warning: Forgetting passphrase means permanent loss of funds
  • No recovery possible without correct passphrase

Common Errors

Invalid Mnemonic

Entropy Length

Integration with HD Wallets

BIP-39 is typically used with BIP-32 (HD Wallets) for deterministic key generation:
Flow:
  1. Mnemonic (human-readable backup)
  2. Seed (64 bytes via PBKDF2)
  3. Root key (master private key)
  4. Derived keys (unlimited addresses from root)

Implementation Notes

  • Uses @scure/bip39 by Paul Miller (audited, widely-used)
  • PBKDF2-HMAC-SHA512 with 2048 iterations
  • NFKD normalization for mnemonic and passphrase
  • Constant-time checksum verification
  • Support for multiple wordlists

Test Vectors

BIP-39 test vectors for verification:

Examples

Comprehensive examples demonstrating BIP-39 functionality:

References