Kirin 0f47bd08df 1 | há 2 anos atrás | |
---|---|---|
.. | ||
src | há 2 anos atrás | |
test | há 2 anos atrás | |
.coveralls.yml | há 2 anos atrás | |
.gitignore | há 2 anos atrás | |
.travis.yml | há 2 anos atrás | |
LICENSE | há 2 anos atrás | |
README.md | há 2 anos atrás | |
composer.json | há 2 anos atrás | |
composer.lock | há 2 anos atrás | |
phpunit.xml.dist | há 2 anos atrás |
$ composer require kornrunner/secp256k1
Sign a message:
<?php
require_once 'vendor/autoload.php';
use kornrunner\Secp256k1;
use kornrunner\Serializer\HexSignatureSerializer;
$secp256k1 = new Secp256k1();
// return signature contains r, s and recovery param (v).
// message and privateKey are hex strings
$signature = $secp256k1->sign($message, $privateKey);
// get r
$r = $signature->getR();
// get s
$s = $signature->getS();
// get recovery param
$v = $signature->getRecoveryParam();
// encode to hex
$serializer = new HexSignatureSerializer();
$signatureString = $serializer->serialize($signature);
// or you can call toHex
$signatureString = $signature->toHex();
Verify a message:
<?php
require_once 'vendor/autoload.php';
use kornrunner\Secp256k1;
$secp256k1 = new Secp256k1();
// signature was created by sign method
// hash and publicKey are hex strings
$isVerified = $secp256k1->verify($hash, $signature, $publicKey);
MIT
ETH 0x9c7b7a00972121fb843af7af74526d7eb585b171