定制 fenguoz/bip39-mnemonic-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fenguoz/bip39-mnemonic-php

最新稳定版本:1.2.0

Composer 安装命令:

composer require fenguoz/bip39-mnemonic-php

包简介

BIP39 Mnemonics implementation in PHP

README 文档

README

Mnemonic BIP39 implementation in PHP

Installation

Prerequisite

  • PHP ^8.1
  • ext-mbstring (MultiByte string PHP ext. for non-english wordlist)

Composer

composer require fenguoz/bip39-mnemonic-php

Mnemonic Object

This lib will create this Mnemonic object as a result:

Prop Data Description
entropy string Hexadecimal representation of binary Entropy bits
wordsCount int Number of words (12, 15,18, 21 or 24)
wordsIndex array Indexed array (of integers) indexes from wordlist
words array Indexed array of mnemonic codes
rawBinaryChunks array Indexed array of binary bits (1s and 0s) each containing 11 bits according to BIP39 Spec

Generate Mnemonic Codes (12, 15, 18, 21 or 24 words)

Generate mnemonic of 12, 15, 18, 21 or 24 words using an entropy driven from cryptographically secure pseudo-random bytes.

<?php
declare(strict_types=1);

use \FurqanSiddiqui\BIP39\BIP39;

$mnemonic = BIP39::Generate(12);
var_dump($mnemonic->words);
# array(12) { [0]=> string(6) "barrel" [1]=> string(6) "viable" [2]=> string(6) "become" [3]=> string(4) "kiss" [4]=> string(6) "spider" [5]=> string(8) "business" [6]=> string(4) "wool" [7]=> string(6) "amused" [8]=> string(7) "satoshi" [9]=> string(4) "duty" [10]=> string(4) "girl" [11]=> string(5) "april" }
var_dump($mnemonic->entropy);
# string(32) "12de684fbd6d1a3e3f5041bf68918905" 

Generate Mnemonic using specified Entropy

Specify your own entropy to generate mnemonic codes:

<?php
declare(strict_types=1);

use \FurqanSiddiqui\BIP39\BIP39;

$mnemonic = BIP39::Entropy("f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b");
var_dump($mnemonic->wordsCount); # int(24) 
var_dump($mnemonic->words); # array(24) { [0]=> string(7) "virtual" [1]=> string(4) "wear" [2]=> stri...
var_dump($mnemonic->binaryChunks); # array(24) { [0]=> string(11) "11110100011" [1]=> string(11) "11111000011" [2]=> string(11) "10010...
var_dump($mnemonic->entropy); # string(64) "f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b"

Reverse (Mnemonic to Entropy)

Use mnemonic codes to find entropy. By default, lib will cross-check checksum therefore not using valid mnemonic codes will throw an exception.

<?php
declare(strict_types=1);

use \FurqanSiddiqui\BIP39\BIP39;

$mnemonic = BIP39::Words("virtual wear number paddle spike usage degree august buffalo layer high pelican basic duty gate uphold offer reopen favorite please acoustic version clay leader");
var_dump($mnemonic->entropy); # string(64) "f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b"

Generate non-english mnemonic codes

Mnemonic codes may be generated in ALL languages supported in BIP39 spec. This example generates 12 mnemonic codes in Spanish language as an example, and it may be replaced with other any other language with wordlists in BIP39 spec, check here.

<?php
declare(strict_types=1);

use \FurqanSiddiqui\BIP39\BIP39;
use \FurqanSiddiqui\BIP39\Wordlist;

$mnemonic = (new BIP39(12, Wordlist::Spanish())) // 12 words, Spanish language
    ->generateSecureMnemonic(); // Generate mnemonic
    
print implode(" ", $mnemonic->words); # bastón tímido turismo pez pez fideo pellejo persona brinco yoga rasgo diluir
print $mnemonic->entropy; # 1c9cfbc5d93b26b12bcd8c229fdb07a2

Test Vectors

  • [29-01-2023]: Test vectors mentioned in official BIP-0039 specification are tested and included in package. Execute tests/test_a.php to re-run following tests.

统计信息

  • 总下载量: 15.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固