PHP code example of xiongchao / secp256k1

1. Go to this page and download the library: Download xiongchao/secp256k1 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xiongchao / secp256k1 example snippets




use Xiongchao\Secp256k1\Secp256k1;

$secp256k=app(Secp256k1::class);

$priKey=$secp256k->generatePrivateKey();

$pubKey=$secp256k->generatePublicKey($priKey);

$content="This is a message!";

$contentHash=$secp256k->getContentHash($content);

$msg32 = $secp256k->_toBinary32($contentHash);

$rSign=$secp256k->getRecoverableSign($priKey,$msg32);

$sign=$secp256k->getSign($priKey,$secp256k->_toBinary32($contentHash));

var_dump($secp256k->verifyRecoverableSign($pubKey,$rSign,$msg32));

var_dump($secp256k->verifySign($pubKey,$sign,$secp256k->_toBinary32($contentHash)));