BIP39
in package
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
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
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
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
Return values
Mnemonic —The generated mnemonic.
generateSecureEntropy()
Generates cryptographically secure entropy.
public
generateSecureEntropy() : BIP39
Tags
Return values
BIP39 —This instance for method chaining.
mnemonic()
Generates the final mnemonic from entropy and word list.
public
mnemonic() : Mnemonic
Tags
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
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
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
Return values
Mnemonic —The reconstructed mnemonic.