BIP39

object 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

Link copied to clipboard

Reconstructs a mnemonic phrase from raw entropy. Inverse of mnemonicToEntropy. See MnemonicService.entropyToMnemonic.

Link copied to clipboard
fun generateMnemonic(wordCount: Int = 24): String

Generates a random BIP-39 mnemonic phrase.

Link copied to clipboard

Extracts raw entropy from a mnemonic phrase. Inverse of generateMnemonic. See MnemonicService.mnemonicToEntropy.

Link copied to clipboard
fun mnemonicToSeed(mnemonic: String, passphrase: String = ""): ByteArray

Derives a seed from a mnemonic phrase and optional passphrase.

Link copied to clipboard

Validates a mnemonic phrase.