-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
I am trying to verify the signature of a hashed message, and the method used in the description doesn't return the right address :
function verifySignature($message, $signature, $address) {
$msglen = strlen($message);
$hash = Keccak::hash("\x19Ethereum Signed Message:\n{$msglen}{$message}", 256);
$sign = ["r" => substr($signature, 2, 64),
"s" => substr($signature, 66, 64)];
$recid = ord(hex2bin(substr($signature, 130, 2))) - 27;
if ($recid != ($recid & 1))
return false;
$ec = new EC('secp256k1');
$pubkey = $ec->recoverPubKey($hash, $sign, $recid);
return $address == $this->pubKeyToAddress($pubkey);
}
$address = "0xd927a97442c8bce9f18e84de11cac6e54a890ff8";
$message = "0xa880c297e04a9a4e1b8856dd4b48c1f6c0b0b82b1da2907b3d16f6ab1357c8b9";
// signature returned by eth.sign(address, message)
$signature = "0xcd33577b169a3f2a5c835b3ca7dab1d41fa32db4b791c6856319756e7fecc3cb13676706408b019b6dcc3fe28a72f8435390bb0a1572ba241cfd09ae917784511c";
if ($this->verifySignature($message, $signature, $address)) {
Log::error("SUCCSS");
} else {
Log::error("FAIL");
}
the address returned by verifySignature (that we try to compare to the original address) is 0xad21644cb255d77dbf4b1ab716cca9797ce3e5bb
which is different than the original address.
The problem here is that when not signing the hashed message but the original message it works correctly.
the original message is : "It'sMe MArio". (without the quotes) and the hashing is done by sha3 : web3.utils.sha3(message)
Metadata
Metadata
Assignees
Labels
No labels