Skip to content

Mnemonic Utilities

← Back to Examples Overview

Mnemonic and seed conversion utilities following the Algorand 25-word mnemonic standard.

ExampleDescription
Mnemonic from Seed

This example demonstrates how to use mnemonicFromSeed() to convert a 32-byte seed into a 25-word Algorand mnemonic. The mnemonic uses BIP39-style word encoding where each word represents 11 bits of data.

Key concepts:

  • A 32-byte (256-bit) seed produces 24 data words (256 / 11 = ~23.3, rounded up)
  • A 25th checksum word is computed from the SHA-512/256 hash of the seed
  • The mnemonic is deterministic: same seed always produces same mnemonic
Seed from Mnemonic

This example demonstrates how to use seedFromMnemonic() to convert a 25-word Algorand mnemonic back to its original 32-byte seed. This is the reverse operation of mnemonicFromSeed().

Key concepts:

  • seedFromMnemonic() reverses the mnemonic encoding process
  • The checksum word is verified to ensure mnemonic integrity
  • Round-trip conversion: seed -> mnemonic -> seed produces identical bytes
Secret Key to Mnemonic

This example demonstrates how to use secretKeyToMnemonic() to convert a 64-byte Algorand secret key to a 25-word mnemonic.

Key concepts:

  • Algorand secret keys are 64 bytes: bytes 0-31 are the seed, bytes 32-63 are the public key
  • secretKeyToMnemonic() extracts the first 32 bytes (seed portion) and converts to mnemonic
  • This produces the same result as calling mnemonicFromSeed() on the seed directly
Master Derivation Key Functions

This example demonstrates the master derivation key (MDK) alias functions and shows their equivalence to the core seed/mnemonic functions.

Key concepts:

  • masterDerivationKeyToMnemonic() is an alias for mnemonicFromSeed()
  • mnemonicToMasterDerivationKey() is an alias for seedFromMnemonic()
  • These aliases exist for wallet derivation workflows where the terminology

”master derivation key” is more familiar than “seed”

Error Handling for Mnemonic Functions

This example demonstrates how to properly handle errors when working with mnemonic functions, including invalid words, bad checksums, and wrong seed lengths.

Key concepts:

  • NOT_IN_WORDS_LIST_ERROR_MSG: Thrown when a mnemonic contains an invalid word
  • FAIL_TO_DECODE_MNEMONIC_ERROR_MSG: Thrown when checksum validation fails
  • RangeError: Thrown when seed length is not 32 bytes

Run any example from the repository’s examples directory:

Terminal window
cd examples
npm run example algo25/01-*.ts