Mnemonic Utils
BIP-39 mnemonic utility functions for generating, validating, and converting mnemonic phrases.
This object provides the core operations for BIP-39 mnemonic handling as specified by the BIP-39 specification and SEP-5.
Security Considerations
CSPRNG: Uses cryptographically secure random number generation for entropy
O(1) Word Lookup: Word list lookups use HashMap for constant-time access to mitigate timing attacks
Constant-Time Comparison: Checksum validation uses constant-time comparison to prevent timing attacks
NFKD Normalization: Both mnemonic and passphrase are NFKD-normalized before use per BIP-39 specification
Memory Cleanup: Generated entropy is zeroed after use for defense in depth
Usage Example
// Generate a 24-word mnemonic (256 bits of entropy)
val mnemonic = MnemonicUtils.generateMnemonic(MnemonicStrength.BITS_256)
// Validate a mnemonic
if (MnemonicUtils.validateMnemonic(mnemonic)) {
println("Mnemonic is valid")
}
// Convert mnemonic to BIP-39 seed
val seed = MnemonicUtils.mnemonicToSeed(mnemonic, passphrase = "optional passphrase")See also
for entropy strength options
for supported word list languages
Functions
Detects the language of a mnemonic phrase.
Converts entropy bytes to a BIP-39 mnemonic phrase.
Generates a BIP-39 mnemonic phrase with the specified strength.
Gets the strength level of a mnemonic phrase based on its word count.
Converts a BIP-39 mnemonic phrase back to its original entropy.
Converts a BIP-39 mnemonic phrase to a 64-byte seed.
Converts a BIP-39 mnemonic phrase to a hex-encoded 64-byte seed.
Validates a BIP-39 mnemonic phrase.