Stellar PHP SDK API Documentation

Mnemonic

BIP-39 compliant mnemonic phrase for hierarchical deterministic key derivation.

This class represents a mnemonic phrase used for generating deterministic wallets following the BIP-39 standard. It can generate secure mnemonics of 12, 15, or 24 words and derive seeds for use with SEP-0005 key derivation paths.

SEP-5 specifies the Stellar derivation path as m/44'/148'/x' where 148 is the Stellar coin type and x is the account index. This enables deterministic wallet generation compatible across the Stellar ecosystem.

Tags
see
https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
BIP39
WordList
HDNode

Table of Contents

Properties

$entropy  : string|null
Hexadecimal entropy string used to generate the mnemonic phrase.
$rawBinaryChunks  : array<string|int, mixed>
Binary chunks representing the combined entropy and checksum.
$words  : array<string|int, mixed>
The actual mnemonic words from the BIP-39 word list.
$wordsCount  : int
Total number of words in the mnemonic phrase.
$wordsIndex  : array<string|int, mixed>
Numeric indices corresponding to each word in the BIP-39 word list.

Methods

__construct()  : mixed
Mnemonic constructor.
bip39SeedHex()  : string
Generates a hexadecimal BIP-39 seed from the mnemonic.
generate()  : Mnemonic
Generates a new mnemonic phrase with the specified word count.
generate12WordsMnemonic()  : Mnemonic
Generates a new 12-word mnemonic phrase.
generate15WordsMnemonic()  : Mnemonic
Generates a new 15-word mnemonic phrase.
generate24WordsMnemonic()  : Mnemonic
Generates a new 24-word mnemonic phrase.
generateSeed()  : string
Generates a binary seed from the mnemonic using PBKDF2.
m44148keyHex()  : string
Derives a Stellar private key following the m/44'/148' derivation path.
mnemonicFromWords()  : Mnemonic
Generates Mnemonic from a space-separated list of words.

Properties

$entropy

Hexadecimal entropy string used to generate the mnemonic phrase.

public string|null $entropy = null

The source entropy (128-256 bits) in hexadecimal format

$rawBinaryChunks

Binary chunks representing the combined entropy and checksum.

public array<string|int, mixed> $rawBinaryChunks

Array of 11-bit binary strings used for word generation

$words

The actual mnemonic words from the BIP-39 word list.

public array<string|int, mixed> $words

Array of strings representing the mnemonic phrase

$wordsCount

Total number of words in the mnemonic phrase.

public int $wordsCount

Valid values are 12, 15, 18, 21, or 24 words

$wordsIndex

Numeric indices corresponding to each word in the BIP-39 word list.

public array<string|int, mixed> $wordsIndex

Array of integers (0-2047) representing word positions

Methods

__construct()

Mnemonic constructor.

public __construct([string|null $entropy = null ]) : mixed
Parameters
$entropy : string|null = null

Hexadecimal entropy string. Optional.

bip39SeedHex()

Generates a hexadecimal BIP-39 seed from the mnemonic.

public bip39SeedHex([string|null $passphrase = "" ]) : string
Parameters
$passphrase : string|null = ""

Optional passphrase for additional security. Default is empty string.

Return values
string —

The generated seed as a hexadecimal string (128 characters).

generate()

Generates a new mnemonic phrase with the specified word count.

public static generate(int $wordCount[, string|null $language = WordList::LANGUAGE_ENGLISH ]) : Mnemonic
Parameters
$wordCount : int

Number of words (12, 15, 18, 21, or 24).

$language : string|null = WordList::LANGUAGE_ENGLISH

Word list language. Default is English.

Tags
throws
Exception

If word count is invalid or generation fails.

Return values
Mnemonic —

A new mnemonic with the specified number of words.

generate12WordsMnemonic()

Generates a new 12-word mnemonic phrase.

public static generate12WordsMnemonic([string|null $language = WordList::LANGUAGE_ENGLISH ]) : Mnemonic
Parameters
$language : string|null = WordList::LANGUAGE_ENGLISH

Word list language. Default is English.

Tags
throws
Exception

If mnemonic generation fails.

Return values
Mnemonic —

A new mnemonic with 12 words.

generate15WordsMnemonic()

Generates a new 15-word mnemonic phrase.

public static generate15WordsMnemonic([string|null $language = WordList::LANGUAGE_ENGLISH ]) : Mnemonic
Parameters
$language : string|null = WordList::LANGUAGE_ENGLISH

Word list language. Default is English.

Tags
throws
Exception

If mnemonic generation fails.

Return values
Mnemonic —

A new mnemonic with 15 words.

generate24WordsMnemonic()

Generates a new 24-word mnemonic phrase.

public static generate24WordsMnemonic([string|null $language = WordList::LANGUAGE_ENGLISH ]) : Mnemonic
Parameters
$language : string|null = WordList::LANGUAGE_ENGLISH

Word list language. Default is English.

Tags
throws
Exception

If mnemonic generation fails.

Return values
Mnemonic —

A new mnemonic with 24 words.

generateSeed()

Generates a binary seed from the mnemonic using PBKDF2.

public generateSeed([string|null $passphrase = "" ][, int|null $bytes = 0 ]) : string
Parameters
$passphrase : string|null = ""

Optional passphrase for additional security. Default is empty string.

$bytes : int|null = 0

Number of bytes to return. Default is 0 (returns full hash).

Tags
security

Passphrases must be handled securely and never logged or stored in plain text. Consider using secure memory handling for sensitive key material.

Return values
string —

The generated binary seed.

m44148keyHex()

Derives a Stellar private key following the m/44'/148' derivation path.

public m44148keyHex([string|null $passphrase = "" ]) : string
Parameters
$passphrase : string|null = ""

Optional passphrase for additional security. Default is empty string.

Return values
string —

The private key as a hexadecimal string (64 characters).

mnemonicFromWords()

Generates Mnemonic from a space-separated list of words.

public static mnemonicFromWords(string $words[, string|null $language = WordList::LANGUAGE_ENGLISH ][, bool|null $verifyChecksum = true ]) : Mnemonic
Parameters
$words : string

Space-separated mnemonic words.

$language : string|null = WordList::LANGUAGE_ENGLISH

Word list language. Default is English.

$verifyChecksum : bool|null = true

Whether to verify entropy checksum. Default is true.

Tags
throws
Exception

If words are invalid or checksum verification fails.

Return values
Mnemonic —

The reconstructed mnemonic.

On this page

Search results