mnemonicToEntropy

suspend fun mnemonicToEntropy(mnemonic: String, language: MnemonicLanguage = MnemonicLanguage.ENGLISH): ByteArray

Converts a BIP-39 mnemonic phrase back to its original entropy.

This function validates the mnemonic by:

  1. Checking word count (must be 12, 15, 18, 21, or 24)

  2. Verifying all words exist in the word list

  3. Validating the checksum

Algorithm:

  1. Split mnemonic into words

  2. Look up each word's index in word list (O(1) HashMap lookup)

  3. Convert indices to 11-bit binary strings

  4. Concatenate all bits

  5. Split into entropy bits and checksum bits

  6. Verify checksum using constant-time comparison

  7. Return entropy bytes

This function is suspend because JavaScript requires async initialization of the cryptographic library for SHA-256 checksum validation. On JVM and Native platforms, the suspend keyword has zero overhead.

Return

Original entropy bytes

Parameters

mnemonic

Space-separated mnemonic phrase

language

Word list language (default: English)

Throws

if word count is invalid

if a word is not in the word list

if checksum validation fails

Example:

val mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
val entropy = MnemonicUtils.mnemonicToEntropy(mnemonic)
// entropy is 16 bytes of zeros