I'm trying to play around with ECDSA, but for some reason it's not returning the correct address to me. Here is how I'm trying to return the signing address.
const signer = new ethers.Wallet(PRIVATE_KEY)
const hashedHello = await contract.rndHash('hello')
const ethSignedHash = await contract.ethSignedHash(hashedHello);
const signedMessageHash = await signer.signMessage(hashedHello);
const recoveredSig = await contract.recover(ethSignedHash, signedMessageHash);
console.log('should be my public key => ', recoveredSig)
Here is my contract code:
contract Greeter {
using ECDSA for bytes32;
string private greeting;
function rndHash(string memory data) public pure returns(bytes32) {
return keccak256(abi.encodePacked(data));
}
function ethSignedHash(bytes32 messageHash) public pure returns(bytes32) {
return messageHash.toEthSignedMessageHash();
}
function recover(bytes32 hash, bytes memory signature) public pure returns(address) {
return hash.recover(signature);
}
}