bitcoin-php/bitcoin-ecdsa
Composer 安装命令:
composer require bitcoin-php/bitcoin-ecdsa
包简介
PHP library allowing to generate BTC addresses from private keys
README 文档
README
WARNING
This piece of software is provided without warranty of any kind, use it at your own risk.
REQUIREMENTS
php 5.4.0 or newer.
php5-gmp needs to be installed.
If you want to launch the test file you need to be under a unix system with libbitcoin intalled on it.
USAGE
Installation
Best way is to use composer
composer require bitcoin-php/bitcoin-ecdsa
Alternatively add the following snippet to your composer.json
"bitcoin-php/bitcoin-ecdsa" : ">=1.3"
Instantiation
use BitcoinPHP\BitcoinECDSA\BitcoinECDSA; require_once("src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php"); $bitcoinECDSA = new BitcoinECDSA();
Set a private key
$bitcoinECDSA->setPrivateKey($k);
examples of private keys :
4C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D 00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC
Generate a random private key
$bitcoinECDSA->generateRandomPrivateKey($nonce);
The nonce is optional, typically the nonce is a chunk of random data you get from the user. This can be mouse coordinates. Using a nonce adds randomness, which means the generated private key is stronger.
Get the private key
$bitcoinECDSA->getPrivateKey();
Returns the private key.
Get the Wif
$bitcoinECDSA->getWif();
returns the private key under the Wallet Import Format
Get the Public Key
$bitcoinECDSA->getPubKey();
Returns the compressed public key. The compressed PubKey starts with 0x02 if its y coordinate is even and 0x03 if it is odd, the next 32 bytes corresponds to the x coordinates.
Example : 0226c50013603b085fbc26411d5d7e564b252d88964eedc4e01251d2d495e92c29
Get the Uncompressed Public Key
$bitcoinECDSA->getUncompressedPubKey();
Returns the uncompressed PubKey. The uncompressed PubKey starts with 0x04, the next 32 bytes are the x coordinates, the last 32 bytes are the y coordinates.
Example : 04c80e8af3f1b7816a18aa24f242fc0740e9c4027d67c76dacf4ce32d2e5aace241c426fd288a9976ca750f1b192d3acd89dfbeca07ef27f3e5eb5d482354c4249
Get the coordinates of the Public Key
$bitcoinECDSA->getPubKeyPoints();
Returns an array containing the x and y coordinates of the public key
Example : Array ( [x] => a69243f3c4c047aba38d7ac3660317629c957ab1f89ea42343aee186538a34f8 [y] => b6d862f39819060378542a3bb43ff76b5d7bb23fc012f09c3cd2724bebe0b0bd )
Get the Address
$bitcoinECDSA->getAddress();
Returns the compressed Bitcoin Address.
Get the uncompressed Address
$bitcoinECDSA->getUncompressedAddress();
Returns the uncompressed Bitcoin Address.
Validate an address
$bitcoinECDSA->validateAddress($address);
Returns true if the address is valid and false if it isn't
Validate a Wif key
$bitcoinECDSA->validateWifKey($wif);
Returns true if the WIF key is valid and false if it isn't
Signatures
Sign a message
$bitcoinECDSA->signMessage('message');
Returns a satoshi client standard signed message.
verify a message
$bitcoinECDSA->checkSignatureForRawMessage($signedMessage);
Returns true if the signature is matching the address and false if it isn't.
sign a sha256 hash
$bitcoinECDSA->signHash($hash);
Returns a DER encoded hexadecimal signature.
verify a signature
$bitcoinECDSA->checkDerSignature($pubKey, $signature, $hash)
Returns true if the signature is matching the public key and false if it isn't.
Examples
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/
bitcoin-php/bitcoin-ecdsa 适用场景与选型建议
bitcoin-php/bitcoin-ecdsa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.33k 次下载、GitHub Stars 达 229, 最近一次更新时间为 2014 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bitcoin」 「ECDSA」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitcoin-php/bitcoin-ecdsa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitcoin-php/bitcoin-ecdsa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitcoin-php/bitcoin-ecdsa 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
ECDSA signature value object with DER/JWS raw format conversion and curve-order validation. For Cloud KMS/HSM-based JWT signing where OpenSSL/KMS returns DER but JWT (RFC 7518) requires raw format.
secp256k1 elliptic-curve arithmetic + RFC 6979 deterministic ECDSA sign / verify / recover in pure PHP on ext-gmp.
CoinDesk Bitcoin Price Index API for Laravel
Library for PKCS5 v2 key derivation & and message encryption
phinance, binance API PHP client
统计信息
- 总下载量: 66.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 232
- 点击次数: 24
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: unlicense
- 更新时间: 2014-06-01