verify signature failed on elliptic-php, error is "cannot initialize"

Viewed 49

I am trying to verify the signature by using elliptic-php library, but I got the error: Cannot initialize. Here is my code:

<?php
    public static function verifySignature($hash, $signature, $address) {
        try {
            $sign = [
                "r" => substr($signature, 0, 64),
                "s" => substr($signature, 64, 64),
            ];
            $reCid = ord(hex2bin(substr($signature, 128, 2)));
            if ($reCid != ($reCid & 1)) {
                return false;
            }
            $ec = new EC('secp256k1');
            $publicKey = $ec->recoverPubKey($hash, $sign, $reCid);
            return $address = self::pubKeyToAddress($publicKey);
        }catch (\Exception $exception) {
            throw new HashException($exception->getCode(),$exception->getMessage());
        }
    }
    verifySignature("c230e229e1e7edd299b4c142ac105a84df7c114ef1d6c538ee9e8461f70b2ad3",""W6AdiMNBTRb/a9oa43CFnL+UjpdhJ4QuxfnVQuTY8EB0RQQ2pvWEeIF9c5oMrokVrCmtBiXe4vW3Fvu+mIZ2bwA=","0x38737be4bb9bdB44Fa4367935E087Dad925CE172");
?>

I traced the error and found it threw out when executed to

$ec->recoverPubKey($hash, $sign, $reCid);

Could you tell me if anyone knows the reason?

0 Answers
Related