sakoora0x/bip39-mnemonic-php
Composer 安装命令:
composer require sakoora0x/bip39-mnemonic-php
包简介
BIP39 Mnemonics implementation in PHP
关键字:
README 文档
README
Mnemonic BIP39 implementation in PHP
Installation
Prerequisite
- PHP ^8.2
- ext-mbstring (MultiByte string PHP ext. for non-english wordlist)
Composer
composer require sakoora0x/bip39-mnemonic-php
Generating a Secure Mnemonic
Generate a mnemonic using a secure PRNG implementation.
BIP39::fromRandom
| Argument | Type | Description |
|---|---|---|
| $wordList | AbstractLanguage |
Langage instance for wordlist |
| $wordCount | int | Number of words (12-24) |
Returns instance of Mnemonic class.
Example:
// Generate entropy using PRNG $mnemonic = \sakoora0x\BIP39\BIP39::fromRandom( \sakoora0x\BIP39\Language\English::getInstance(), wordCount: 12 ); # array(12) { [0]=> string(4) "tape" [1]=> string(8) "solution" ... [10]=> string(6) "border" [11]=> string(6) "sample" } var_dump($mnemonic->words); # string(32) "ddd9dbcd1b07a09c16f080637818675f" var_dump($mnemonic->entropy);
Entropy to Mnemonic
Generate mnemonic codes from given entropy
BIP39::fromEntropy
| Argument | Type | Description |
|---|---|---|
| $entropy | string |
Raw binary entropy bytes |
| $wordList | AbstractLanguage |
Langage instance for wordlist |
Returns instance of Mnemonic class.
Example:
$mnemonic = \sakoora0x\BIP39\BIP39::fromEntropy( hex2bin("ddd9dbcd1b07a09c16f080637818675f"), \sakoora0x\BIP39\Language\English::getInstance() ); # array(12) { [0]=> string(4) "tape" [1]=> string(8) "solution" ... [10]=> string(6) "border" [11]=> string(6) "sample" } var_dump($mnemonic->words);
Mnemonic sentence/Words to Mnemonic
Generate entropy from mnemonic codes
BIP39::fromWords
| Argument | Type | Description |
|---|---|---|
| $words | Array<string> | Array of mnemonic codes |
| $wordList | AbstractLanguage |
Langage instance for wordlist |
| $verifyChecksum | bool | Defaults to TRUE, computes and verifies checksum as per BIP39 spec. |
Returns instance of Mnemonic class.
Example:
$mnemonic = \sakoora0x\BIP39\BIP39::fromWords( ["tape", "solution", "viable", "current", "key", "evoke", "forward", "avoid", "gloom", "school", "border", "sample"], \sakoora0x\BIP39\Language\English::getInstance() ); #string(32) "ddd9dbcd1b07a09c16f080637818675f" var_dump($mnemonic->entropy);
Mnemonic Class
readonly class Mnemonic
This lib will create this Mnemonic object as a result:
| Property | Type | Description |
|---|---|---|
| language | string | Language name (as it was passed to constructor of wordlist class) |
| words | Array<string> | Mnemonic codes |
| wordsIndex | Array<int> | Position/index # of each mnemonic code corresponding to wordlist used |
| wordsCount | int | Number of mnemonic codes (i.e. 12, 15, 18, 21 or 24) |
| entropy | string | Entropy in hexadecimal encoding |
Generating Seed with Passphrase
Mnemonic->generateSeed
Generates seed from a mnemonic as per BIP39 specifications.
| Argument | Type | Description |
|---|---|---|
| $passphrase | string | Defaults to empty string ("") |
| $bytes | int | Number of bytes to return, defaults to 64. |
Returns:
| Type | Description |
|---|---|
| string | Returns computed PBKDF2 hash in RAW BINARY as string |
Generate non-english mnemonic codes
Check AbstractLanguage and AbstractLanguageFile classes. English class has all
2048 words pre-loaded instead of reading from a local file every time. To implement other languages or
custom set of 2048 words, check ChineseWords.php file in tests directory for example of implementation.
class CustomWords extends \sakoora0x\BIP39\Language\AbstractLanguageFile { /** * @return static */ protected static function constructor(): static { return new static( language: "some_language", words: static::wordsFromFile( pathToFile: "/path/to/wordlist.txt", eolChar: PHP_EOL ), mbEncoding: "UTF-8" ); } }
and then use in place of AbstractLanguage where required:
CustomWords::getInstance()
Test Vectors
Include PHPUnit tests for all test vectors mentioned in official BIP-0039 specification.
Running Tests
Install dependencies:
composer install
Run tests:
./vendor/bin/phpunit
Run tests with verbose output:
./vendor/bin/phpunit --testdox
sakoora0x/bip39-mnemonic-php 适用场景与选型建议
sakoora0x/bip39-mnemonic-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mnemonics」 「bip39」 「BIP-0039」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sakoora0x/bip39-mnemonic-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sakoora0x/bip39-mnemonic-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sakoora0x/bip39-mnemonic-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
BIP39 Mnemonics implementation in PHP
PHP mnemonic generation library for TON blockchain
BIP39 Mnemonics implementation in PHP
BIP39 Mnemonics implementation in PHP
Laravel package for EVM compatible network wallet creation with mnemonic seed phrase support
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-23