Created
March 22, 2022 22:28
-
-
Save wrightkhlebisol/f1d65478841c0215ab1d31219c50c8d7 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.17+commit.d19bba13.js&optimize=true&runs=100000&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract Verify { | |
address public importantAddress; | |
constructor (address _importantAddress) public { | |
importantAddress = _importantAddress; | |
} | |
function splitSignature(bytes memory sig) | |
public | |
pure | |
returns(uint8, bytes32, bytes32) | |
{ | |
require(sig.length == 65); | |
bytes32 r; | |
bytes32 s; | |
uint8 v; | |
assembly { | |
// first 32 bytes, after the length prefix | |
r := mload(add(sig, 32)) | |
// second 32 bytes | |
s := mload(add(sig, 64)) | |
// final byte (first byte of the next 32 bytes) | |
v := byte(0, mload(add(sig, 96))) | |
} | |
return (v, r, s); | |
} | |
function recoverSigner(bytes32 message, bytes memory sig) | |
public | |
pure | |
returns (address) | |
{ | |
uint8 v; | |
bytes32 r; | |
bytes32 s; | |
(v,r,s) = splitSignature(sig); | |
return ecrecover(message, v,r,s); | |
} | |
function isValidData( | |
uint256 _number, | |
string memory _word, | |
bytes memory sig | |
) | |
public | |
view | |
returns (bool) | |
{ | |
bytes32 message = keccak256(abi.encodePacked(_number, _word)); | |
return (recoverSigner(message, sig) == importantAddress); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment