entropyToMnemonic

suspend fun entropyToMnemonic(entropy: ByteArray, language: MnemonicLanguage = MnemonicLanguage.ENGLISH): String

Converts entropy bytes to a BIP-39 mnemonic phrase.

The entropy is validated, SHA-256 checksum bits are appended, and the result is encoded as a sequence of words from the specified word list.

Algorithm:

  1. Validate entropy size (must be 16, 20, 24, 28, or 32 bytes)

  2. Convert entropy to binary string

  3. Calculate SHA-256 hash, take first N bits as checksum (N = entropy_bits / 32)

  4. Append checksum bits to entropy bits

  5. Split into 11-bit chunks

  6. Map each chunk to corresponding word in word list

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

Return

Space-separated mnemonic phrase

Parameters

entropy

Random entropy bytes (16, 20, 24, 28, or 32 bytes)

language

Word list language (default: English)

Throws

if entropy size is invalid

Example:

// Convert 16 bytes of entropy to a 12-word mnemonic
val entropy = HexCodec.decode("00000000000000000000000000000000")
val mnemonic = MnemonicUtils.entropyToMnemonic(entropy)
// Result: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"