Mnemonic

public final class Mnemonic : Sendable

Implements BIP-39 mnemonic code for generating deterministic keys.

This class provides functionality for generating and working with mnemonic phrases (also known as seed phrases or recovery phrases) according to the BIP-39 standard. Mnemonics are human-readable representations of cryptographic seeds that can be used to derive hierarchical deterministic wallets.

The mnemonic consists of 12 or 24 words selected from a standardized word list. These words encode entropy that can be used to generate a seed for wallet derivation.

See also:

  • The strength of the mnemonic, determining the number of words generated.

    • normal: 128 bits of entropy, generates a 12-word mnemonic
    • high: 256 bits of entropy, generates a 24-word mnemonic
    See more

    Declaration

    Swift

    public enum Strength : Int, Sendable
  • Creates a new random mnemonic phrase.

    Generates a cryptographically secure random mnemonic using the specified strength and language word list. The mnemonic can be used to derive deterministic wallets.

    Example:

    let mnemonic = Mnemonic.create(strength: .normal)
    // Returns: "abandon ability able about above absent absorb abstract absurd abuse access accident"
    

    Declaration

    Swift

    public static func create(strength: Strength = .normal, language: WordList = .english) -> String

    Parameters

    strength

    The entropy strength (default: .normal for 12 words)

    language

    The word list language (default: .english)

    Return Value

    A space-separated mnemonic phrase

  • Creates a mnemonic phrase from provided entropy.

    Converts raw entropy bytes into a BIP-39 compliant mnemonic phrase by adding a checksum and encoding the result as words from the specified language word list.

    Declaration

    Swift

    public static func create(entropy: Data, language: WordList = .english) -> String

    Parameters

    entropy

    The entropy bytes (must be 128 or 256 bits)

    language

    The word list language (default: .english)

    Return Value

    A space-separated mnemonic phrase

  • Creates a binary seed from a mnemonic phrase for use in key derivation.

    Generates a 512-bit seed from a mnemonic phrase using PBKDF2-HMAC-SHA512 with 2048 iterations. This seed can be used with BIP-32 hierarchical deterministic key derivation.

    The passphrase provides an additional security factor. Two different passphrases will produce completely different seeds from the same mnemonic, effectively creating plausible deniability.

    Security considerations:

    • The passphrase is optional but recommended for enhanced security
    • Different passphrases generate different seeds from the same mnemonic
    • Store the passphrase securely if used; it cannot be recovered

    Declaration

    Swift

    public static func createSeed(mnemonic: String, withPassphrase passphrase: String = "") -> Data

    Parameters

    mnemonic

    The BIP-39 mnemonic phrase

    passphrase

    Optional passphrase for additional security (default: empty string)

    Return Value

    A 512-bit (64-byte) seed suitable for key derivation