entropy To Mnemonic
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:
Validate entropy size (must be 16, 20, 24, 28, or 32 bytes)
Convert entropy to binary string
Calculate SHA-256 hash, take first N bits as checksum (N = entropy_bits / 32)
Append checksum bits to entropy bits
Split into 11-bit chunks
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
Random entropy bytes (16, 20, 24, 28, or 32 bytes)
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"