Created
March 14, 2018 02:48
-
-
Save wmh/dcf988314d0ca5e325a1bb504e7e3323 to your computer and use it in GitHub Desktop.
Solidity Verify Signature
This file contains 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.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