1234567891011121314151617181920 |
- pragma solidity ^0.8.0;
- import "../contracts/utils/cryptography/ECDSA.sol";
- contract Validator {
- event LogSigner(address signer);
- function recoverAddress(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public pure returns(address) {
- bytes memory prefix = "\x19Ethereum Signed Message:\n32";
- bytes32 prefixedHash = keccak256(abi.encode(prefix, msgHash));
- return ecrecover(prefixedHash, v, r, s);
- }
- function verify(address claimer ,bytes calldata data, bytes calldata signature) public returns(bool) {
- bytes32 hashed = keccak256(data);
- address signer = ECDSA.recover(hashed, signature);
- emit LogSigner(signer);
- return signer == claimer;
- }
- }
|