定制 php-core/simple-crypto 二次开发

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

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

php-core/simple-crypto

Composer 安装命令:

composer require php-core/simple-crypto

包简介

Simple PHP Cryptocurrency and Blockchain Helper Library

README 文档

README

A simple and efficient PHP library for cryptocurrency wallet generation and management. Generate addresses for Bitcoin, Ethereum, and all EVM-compatible chains (Polygon, BSC, etc.) using standard BIP protocols.

Features

  • Multiple Chain Support:

    • Bitcoin (BTC)
      • Legacy addresses (1...)
      • SegWit addresses (3...)
      • Native SegWit addresses (bc1...)
    • All EVM-compatible chains:
      • Ethereum (ETH)
      • Polygon (MATIC)
      • Binance Smart Chain (BSC)
      • Avalanche (AVAX)
      • And any other EVM chain
  • Standards Compliance:

    • BIP32 (Hierarchical Deterministic Wallets)
    • BIP39 (Mnemonic Phrases)
    • BIP44 (Multi-Account Hierarchy)
    • BIP84 (Native SegWit)
  • Security Features:

    • Message signing and verification
    • Hardened derivation support
    • Secure key generation

Requirements

  • PHP 8.3+
  • GMP extension
  • Sodium extension
  • MBString extension

Installation

composer require php-core/simple-crypto

Quick Start

Generate Multi-Chain Addresses

use PHPCore\SimpleCrypto\Wallet\Mnemonic\BIP39Mnemonic;
use PHPCore\SimpleCrypto\Wallet\KeyPair\BTCKeyPair;
use PHPCore\SimpleCrypto\Wallet\KeyPair\EVMKeyPair;

// Create or import a mnemonic
$mnemonic = new BIP39Mnemonic();
$phrase = $mnemonic->generate(12);
$seed = $mnemonic->toSeed($phrase);

// Create master key pairs
$btcMaster = BTCKeyPair::fromSeed($seed);
$evmMaster = EVMKeyPair::fromSeed($seed);

// Generate Bitcoin addresses
$btcPath = "m/84'/0'/0'/0/0"; // BIP84 for native SegWit
$btcAccount = $btcMaster->derivePath($btcPath);

echo "Bitcoin Legacy: " . $btcAccount->getAddress('legacy') . "\n";
echo "Bitcoin SegWit: " . $btcAccount->getAddress('segwit') . "\n";
echo "Bitcoin Native SegWit: " . $btcAccount->getAddress('native_segwit') . "\n";

// Generate EVM address (works for ETH, MATIC, BSC, etc.)
$evmPath = "m/44'/60'/0'/0/0"; // BIP44 for Ethereum
$evmAccount = $evmMaster->derivePath($evmPath);
echo "EVM Address: " . $evmAccount->getAddress() . "\n";

Generate Multiple Addresses

// Generate multiple Bitcoin addresses
for ($i = 0; $i < 5; $i++) {
    $path = "m/84'/0'/0'/0/{$i}";
    $account = $btcMaster->derivePath($path);
    echo "Address #{$i}: " . $account->getAddress('native_segwit') . "\n";
}

// Generate multiple EVM addresses
for ($i = 0; $i < 5; $i++) {
    $path = "m/44'/60'/0'/0/{$i}";
    $account = $evmMaster->derivePath($path);
    echo "Address #{$i}: " . $account->getAddress() . "\n";
}

Sign and Verify Messages

// Bitcoin message signing
$btcAccount = BTCKeyPair::fromSeed($seed);
$message = "Hello, Bitcoin!";
$signature = $btcAccount->sign($message);
$isValid = $btcAccount->verify($message, $signature);

// EVM message signing
$evmAccount = EVMKeyPair::fromSeed($seed);
$message = "Hello, Ethereum!";
$signature = $evmAccount->sign($message);
$isValid = $evmAccount->verify($message, $signature);

Advanced Usage

Custom Derivation Paths

// Bitcoin paths
$legacyPath = "m/44'/0'/0'/0/0";     // BIP44 legacy
$segwitPath = "m/49'/0'/0'/0/0";      // BIP49 SegWit
$nativePath = "m/84'/0'/0'/0/0";      // BIP84 Native SegWit

// EVM paths
$standardPath = "m/44'/60'/0'/0/0";   // Standard Ethereum
$ledgerPath = "m/44'/60'/0'";         // Ledger Live
$customPath = "m/44'/60'/1'/0/0";     // Custom account

Working with Private Keys

$account = EVMKeyPair::fromSeed($seed);

// Get private key (for import into wallets)
$privateKey = $account->getPrivateKey();

// Get public key
$publicKey = $account->getPublicKey();

// Get compressed public key
$compressedPubKey = $account->getCompressedPublicKey();

Security Considerations

  1. Mnemonic Phrases:

    • Store securely
    • Never share with anyone
    • Enables recovery of all derived addresses
  2. Private Keys:

    • Keep offline when possible
    • Use hardware wallets for large amounts
    • Each address has its own private key
  3. Testing:

    • Use testnet addresses during development
    • Verify addresses before sending real funds

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Run tests: composer test
  4. Submit a pull request

License

MIT License. See LICENSE file for details.

Credits

Developed by PHPCore Team.

php-core/simple-crypto 适用场景与选型建议

php-core/simple-crypto 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 824 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 php-core/simple-crypto 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 php-core/simple-crypto 我们能提供哪些服务?
定制开发 / 二次开发

基于 php-core/simple-crypto 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 824
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-23