WalletUtils

public final class WalletUtils : Sendable

Implements SEP-0005 - Key Derivation Methods for Stellar Accounts.

This class provides BIP-39 mnemonic generation and BIP-44 hierarchical deterministic key derivation for Stellar accounts. It allows creating multiple accounts from a single seed phrase, enabling secure wallet backups and account management.

Typical Usage

// Generate a 12-word mnemonic
let mnemonic = WalletUtils.generate12WordMnemonic()

// Derive first account (index 0)
let keyPair0 = try WalletUtils.createKeyPair(
    mnemonic: mnemonic,
    passphrase: nil,
    index: 0
)

// Derive second account (index 1)
let keyPair1 = try WalletUtils.createKeyPair(
    mnemonic: mnemonic,
    passphrase: nil,
    index: 1
)

See also:

  • Generates a 12 word Mnemonic.

    Declaration

    Swift

    public static func generate12WordMnemonic(language: WordList = .english) -> String
  • Generates a 24 word Mnemonic.

    Declaration

    Swift

    public static func generate24WordMnemonic(language: WordList = .english) -> String
  • Creates a new KeyPair from the given mnemonic and index.

    Throws

    StellarSDKError.invalidArgument for an index outside 0 to 2147483647.

    Declaration

    Swift

    public static func createKeyPair(mnemonic: String, passphrase: String?, index: Int) throws -> KeyPair

    Parameters

    mnemonic

    The mnemonic string.

    passphrase

    The passphrase.

    index

    The index of the wallet to generate, from 0 to 2147483647 (2^31-1), the range of hardened BIP-32 account indexes.