From d2b3b8e0fe3cd1789833177b9dc4e710fa39d3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=9A=E6=95=B2=E4=BB=A3=E7=A0=81=E7=9A=84=E5=96=B5?= Date: Thu, 16 Jun 2022 17:56:13 +0800 Subject: [PATCH] Fix phpEcRecover copy code from nodejs web3 libraty --- src/EcRecover.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EcRecover.php b/src/EcRecover.php index 86720eb..32d0b98 100644 --- a/src/EcRecover.php +++ b/src/EcRecover.php @@ -67,7 +67,8 @@ public static function phpEcRecover(string $message_hash, string $signature) $ec = new EC('secp256k1'); $sign = ["r" => substr($signature, 2, 64), "s" => substr($signature, 66, 64)]; - $recid = ord(hex2bin(substr($signature, 130, 2))) - 27; + $recid = ord(hex2bin(substr($signature, 130, 2))); + $recid = $recid < 2 ? $recid : 1 - ($recid % 2); $pubKey = $ec->recoverPubKey($message_hash, $sign, $recid);