PHP code example of web3p / secp256k1

1. Go to this page and download the library: Download web3p/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/ */

    

web3p / secp256k1 example snippets


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);