Mnemonic
Implements SEP-0005 Key Derivation Methods for Stellar Keys.
Provides hierarchical deterministic key derivation from BIP-39 mnemonic phrases using the Stellar-specific derivation path m/44'/148'/x' where:
44' is the BIP-44 purpose (hardened)
148' is the Stellar coin type from SLIP-0044 (hardened)
x' is the account index (hardened)
The mnemonic supports:
BIP-39 mnemonic generation in 9 languages (English, Chinese Simplified, Chinese Traditional, French, Italian, Japanese, Korean, Spanish, Malay)
All BIP-39 word lengths: 12, 15, 18, 21, and 24 words
Mnemonic validation with checksum verification
SLIP-0010 hierarchical deterministic key derivation for Ed25519
Optional BIP-39 passphrase for additional security
Usage Example
// Generate a 24-word mnemonic (recommended)
val mnemonic = Mnemonic.generate24WordsMnemonic()
// Create Mnemonic instance from phrase
val mnemonic = Mnemonic.from(mnemonic)
// Derive keypairs for multiple accounts
val account0 = mnemonic.getKeyPair(index = 0)
val account1 = mnemonic.getKeyPair(index = 1)
// Get account ID only (more efficient for display)
val accountId = mnemonic.getAccountId(index = 0)
// With passphrase for additional security
val secureMnemonic = Mnemonic.from(mnemonic, passphrase = "my secret passphrase")
// Clean up when done
mnemonic.close()Security Considerations
Store mnemonics securely: Never expose mnemonics in logs, error messages, or insecure storage
Never log sensitive data: Mnemonics, BIP-39 seeds, and private keys must never be logged
Use close(): Call close when the mnemonic instance is no longer needed to zero internal seed data
Passphrase handling: Lost passphrases cannot be recovered; the mnemonic alone cannot restore access to funds if a passphrase was used
Validate mnemonics: Always validate mnemonics before use with validate
Implementation Details
Key derivation follows SLIP-0010 for Ed25519:
Master key:
HMAC-SHA512(key = "ed25519 seed", data = BIP39_seed)Child derivation:
HMAC-SHA512(key = parent_chain_code, data = 0x00 || parent_key || index + 2^31)
All derivation is hardened (indicated by apostrophe in path) as required by Ed25519.
See also
Functions
Gets the Stellar account ID at the specified index.
Gets the 64-byte BIP-39 seed.
Gets the BIP-39 seed as a hex-encoded string.
Derives a Stellar keypair at the specified account index.
Gets the raw 32-byte Ed25519 private key at the specified index.
Gets the raw 32-byte Ed25519 public key at the specified index.