Skip to content

Instantly share code, notes, and snippets.

@wmh
Created March 14, 2018 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmh/dcf988314d0ca5e325a1bb504e7e3323 to your computer and use it in GitHub Desktop.
Save wmh/dcf988314d0ca5e325a1bb504e7e3323 to your computer and use it in GitHub Desktop.
Solidity Verify Signature
pragma solidity ^0.4.21;
contract VerifySign {
function verify(bytes _msgHex, uint8 _v, bytes32 _r, bytes32 _s) public pure returns (address) {
bytes32 prefixedHash = keccak256("\x19Ethereum Signed Message:\n", uint2str(_msgHex.length), _msgHex);
address signer = ecrecover(prefixedHash, _v, _r, _s);
return signer;
}
function uint2str(uint i) internal pure returns (string){
if (i == 0) return "0";
uint j = i;
uint length;
while (j != 0){
length++;
j /= 10;
}
bytes memory bstr = new bytes(length);
uint k = length - 1;
while (i != 0){
bstr[k--] = byte(48 + i % 10);
i /= 10;
}
return string(bstr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment