BIP39
Convenience object for BIP-39 mnemonic operations.
This is a facade that delegates to a MnemonicService implementation. Uses BitcoinJ implementation which is BIP-39 compliant and battle-tested.
Reference: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
Usage:
// Generate 24-word mnemonic
val mnemonic = BIP39.generateMnemonic()
// Convert to seed (CRITICAL: wipe seed after use!)
val seed = BIP39.mnemonicToSeed(mnemonic)
try {
// Use seed...
} finally {
Arrays.fill(seed, 0.toByte())
}
// Validate mnemonic
val isValid = BIP39.validateMnemonic(mnemonic)Thread Safety: All methods are thread-safe. The service implementation is immutable.
Testing: For testing with custom implementations, use constructor injection in your components rather than relying on this global object.
Functions
Reconstructs a mnemonic phrase from raw entropy. Inverse of mnemonicToEntropy. See MnemonicService.entropyToMnemonic.
Generates a random BIP-39 mnemonic phrase.
Extracts raw entropy from a mnemonic phrase. Inverse of generateMnemonic. See MnemonicService.mnemonicToEntropy.
Derives a seed from a mnemonic phrase and optional passphrase.
Validates a mnemonic phrase.