web3p/secp256k1

Ethereum secp256k1 库的 PHP 实现。

v0.2 2018-03-20 02:37 UTC

This package is auto-updated.

Last update: 2024-09-08 01:07:25 UTC


README

为 Ethereum 实现的 secp256k1,此包依赖于 mdanter/ecc 包。

Build Status codecov Licensed under the MIT License

安装

设置最小稳定性为开发版本

composer require web3p/secp256k1

用法

签名消息

use Web3p\Secp256k1\Secp256k1;
use Web3p\Secp256k1\Serializer\HexSignatureSerializer;

$secp256k1 = new Secp256k1();

// return signature contains r and s.
// message and privateKey are hex string
$signature = $secp256k1->sign($message, $privateKey);

// get r
$r = $signature->getR();

// get s
$s = $signature->getS();

// encode to hex
$serializer = new HexSignatureSerializer();
$signatureString = $serializer->serialize($signature);

// or you can call toHex
$signatureString = $signature->toHex();

验证消息

use Web3p\Secp256k1\Secp256k1;

$secp256k1 = new Secp256k1();

// signature was created from sign method.
// hash and publicKey are hex string
$isVerified = $secp256k1->verify($hash, $signature, $publicKey);

API

待办事项。

许可证

MIT