is wrong with js and solidity signatures.
I use ethers lib on client side
So i sign message via
const message = "Hello World:;
const signature = await signer.signMessage(message);
and can successfully verify it via
const signerAddr = await ethers.utils.verifyMessage(message, signature);
From Solidity side I have next one but I have some issue with hash. So means that I need to convert "Hello World" to hash
When I'm converting "Hello World" with solidity
function getMessageHash(
string memory _message
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_message));
}
function getEthSignedMessageHash(bytes32 _messageHash)
public
pure
returns (bytes32)
{
return
keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash)
);
}
hash = getMessageHash("Hello World")
ethPrefixedHash = getEthSignedMessageHash(hash);
I can't verify ethPrefixedHash via verify with signature that I got from ethers lib.
function verify(
address _signer,
string memory _message,
bytes memory signature
) public pure returns (bool) {
bytes32 messageHash = getMessageHash(_message);
bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);
return recoverSigner(ethSignedMessageHash, signature) == _signer;
}
I did it before when changed ethers sign logic on js side ,
in order not to sign the string I signed a hash.
But i forgot the solution and spent 5 hours with goggle and a lot of examples.
Can anyone help pls? What is wrong
How I can get the same on client side? return keccak256(abi.encodePacked(_message)); I did something like const messageHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(JSON.stringify(message))); but it's not the same as keccak256(abi.encodePacked(_message)); returns me on solidity Am I missed somethnig?
if i get you right, you want to recover the signer or verify the signer ?
Обсуждают сегодня