andkom / php-bitcoin-address
一个简单的P2PK、P2PKH、P2SH、P2WPKH、P2WSH输出脚本/地址生成器。
2.0.1
2023-11-16 14:34 UTC
Requires
- php: >=7.1
- ext-gmp: *
- brooksyang/bech32m: ^1.0
- btccom/cashaddress: ^0.0.3
- shanecurran/phpecc: ^0.0.1
- stephenhill/base58: ^1.1
Requires (Dev)
- phpunit/phpunit: >=5.7
This package is auto-updated.
Last update: 2024-09-16 19:22:25 UTC
README
一个简单的P2PK、P2PKH、P2SH、P2WPKH、P2WSH、P2TR输出脚本/地址解析器/生成器/验证器。
支持类型
- 支付给公钥 (P2PK)
- 支付给公钥哈希 (P2PKH)
- 支付给多重签名 (P2MS)
- 支付给脚本哈希 (P2SH)
- 支付给见证公钥哈希 (P2WPKH)
- 支付给见证脚本哈希 (P2WSH)
- 支付给Taproot (P2TR)
- P2WPKH-over-P2SH
- P2WSH-over-P2SH
- 任何组合
支持的网络
- 比特币
- 比特币测试网
- 比特币黄金
- 比特币现金
- 莱特币
- 莱特币测试网
- 狗狗币
- 狗狗币测试网
- 维币
- 维币测试网
- 达世币
- 达世币测试网
- 零币
安装
composer require andkom/php-bitcoin-address
示例
生成P2PK/P2PKH地址
$address = OutputFactory::p2pk($pubKey)->address(); $address = OutputFactory::p2pkh($pubKeyHash)->address();
生成P2MS地址
$address = OutputFactory::p2ms(2, [$pubKey1, $pubKey2, $pubKey3])->address();
生成P2SH地址
$factory = new OutputFactory(); $p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); $address = $factory->p2sh($p2ms)->address();
生成P2WPKH地址
$address = OutputFactory::p2wpkh($pubKeyHash)->address();
生成P2WSH地址
$factory = new OutputFactory(); $p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); $address = $factory->p2wsh($p2ms)->address();
生成P2WPKH-over-P2SH地址
$factory = new OutputFactory(); $p2wpkh = $factory->p2wpkh($pubKeyHash); $address = $factory->p2sh($p2wpkh)->address();
生成P2WSH-over-P2SH地址
$factory = new OutputFactory(); $p2ms = $factory->p2ms(2, [$pubKey1, $pubKey2, $pubKey3]); $p2wsh = $factory->p2wsh($p2ms); $address = $factory->p2sh($p2wsh)->address();
生成P2TR地址
$taprootPubKey = Taproot::construct($pubKey); $address = OutputFactory::p2tr($taprootPubKey)->address();
从输出脚本生成地址
$address = OutputFactory::fromScript($script)->address();
解码比特币地址
$output = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
获取比特币地址类型
$type = NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')->type(); // p2pkh
验证比特币地址
NetworkFactory::bitcoin()->validateAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'); // true