Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in verify signature: Cannot initialize #29

Open
VingoYang opened this issue Dec 23, 2020 · 0 comments
Open

Error in verify signature: Cannot initialize #29

VingoYang opened this issue Dec 23, 2020 · 0 comments

Comments

@VingoYang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant