Validator.sol 687 B

1234567891011121314151617181920
  1. pragma solidity ^0.8.0;
  2. import "../contracts/utils/cryptography/ECDSA.sol";
  3. contract Validator {
  4. event LogSigner(address signer);
  5. function recoverAddress(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public pure returns(address) {
  6. bytes memory prefix = "\x19Ethereum Signed Message:\n32";
  7. bytes32 prefixedHash = keccak256(abi.encode(prefix, msgHash));
  8. return ecrecover(prefixedHash, v, r, s);
  9. }
  10. function verify(address claimer ,bytes calldata data, bytes calldata signature) public returns(bool) {
  11. bytes32 hashed = keccak256(data);
  12. address signer = ECDSA.recover(hashed, signature);
  13. emit LogSigner(signer);
  14. return signer == claimer;
  15. }
  16. }