Stellar PHP SDK API Documentation

BIP39

BIP-39 implementation for mnemonic phrase generation and validation.

This class implements the BIP-39 standard for generating mnemonic phrases from entropy and reconstructing entropy from mnemonic phrases. It handles entropy generation, checksum calculation, and word list operations for creating deterministic wallet seeds.

Tags
see
https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
see
https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
see
Mnemonic
see
WordList

Table of Contents

Methods

__construct()  : mixed
BIP39 constructor.
Entropy()  : Mnemonic
Creates a mnemonic from the provided hexadecimal entropy.
Generate()  : Mnemonic
Generates a new mnemonic with cryptographically secure entropy.
generateSecureEntropy()  : BIP39
Generates cryptographically secure entropy.
mnemonic()  : Mnemonic
Generates the final mnemonic from entropy and word list.
reverse()  : Mnemonic
Reconstructs a mnemonic from an array of words.
useEntropy()  : BIP39
Uses the provided entropy for mnemonic generation.
wordList()  : BIP39
Sets the word list to use for mnemonic generation.
Words()  : Mnemonic
Reconstructs a mnemonic from words.

Methods

__construct()

BIP39 constructor.

public __construct([int $wordCount = 12 ]) : mixed
Parameters
$wordCount : int = 12

Number of words (must be between 12-24 and divisible by 3). Default is 12.

Tags
throws
Exception

If word count is invalid.

Entropy()

Creates a mnemonic from the provided hexadecimal entropy.

public static Entropy(string $entropy) : Mnemonic
Parameters
$entropy : string

Hexadecimal entropy string (128-256 bits).

Tags
throws
Exception

If entropy is invalid.

security

Minimum entropy requirement is 128 bits (32 hex characters). SEP-5 recommends 256 bits (64 hex characters) for maximum security.

Return values
Mnemonic

The generated mnemonic.

Generate()

Generates a new mnemonic with cryptographically secure entropy.

public static Generate([int $wordCount = 12 ]) : Mnemonic
Parameters
$wordCount : int = 12

Number of words in the mnemonic (12, 15, 18, 21, or 24). Default is 12.

Tags
throws
Exception

If word count is invalid.

security

Uses cryptographically secure random_bytes() for entropy generation. SEP-5 recommends 24-word mnemonics (256 bits) for production use.

Return values
Mnemonic

The generated mnemonic.

generateSecureEntropy()

Generates cryptographically secure entropy.

public generateSecureEntropy() : BIP39
Tags
throws
Exception

If entropy generation fails.

Return values
BIP39

This instance for method chaining.

mnemonic()

Generates the final mnemonic from entropy and word list.

public mnemonic() : Mnemonic
Tags
throws
Exception

If entropy or word list is not defined.

Return values
Mnemonic

The generated mnemonic.

reverse()

Reconstructs a mnemonic from an array of words.

public reverse(array<string|int, string> $words[, bool $verifyChecksum = true ]) : Mnemonic
Parameters
$words : array<string|int, string>

Array of mnemonic words.

$verifyChecksum : bool = true

Whether to verify the entropy checksum. Default is true.

Tags
throws
Exception

If words are invalid or checksum verification fails.

Return values
Mnemonic

The reconstructed mnemonic.

useEntropy()

Uses the provided entropy for mnemonic generation.

public useEntropy(string $entropy) : BIP39
Parameters
$entropy : string

Hexadecimal entropy string.

Tags
throws
Exception

If entropy is invalid.

Return values
BIP39

This instance for method chaining.

wordList()

Sets the word list to use for mnemonic generation.

public wordList(WordList $wordList) : BIP39
Parameters
$wordList : WordList

The word list to use.

Return values
BIP39

This instance for method chaining.

Words()

Reconstructs a mnemonic from words.

public static Words(string|array<string|int, string> $words[, WordList|null $wordList = null ][, bool $verifyChecksum = true ]) : Mnemonic
Parameters
$words : string|array<string|int, string>

Mnemonic words as string or array.

$wordList : WordList|null = null

Word list to use. Default is English.

$verifyChecksum : bool = 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