Skip to content

Error in verify signature: Cannot initialize #29

Description

@VingoYang

I am trying to verify the signature, but I got the error: Cannot initialize.
Here is my code:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions