Created
July 6, 2017 13:40
-
-
Save vkobel/c23ac4e6a8a094dcd8759ebabcfc70ab to your computer and use it in GitHub Desktop.
Ethereum Solidity - example contract that shows how to use the ecrecover function to works along with eth_sign
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.4.11; | |
contract EcRecover { | |
function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address) { | |
bytes32 prefixedHash = sha3("\x19Ethereum Signed Message:\n32", hash); | |
return ecrecover(prefixedHash, v, r, s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The trick is that eth_sign is prefixing its hash with the string "\x19Ethereum Signed Message:\n32".
32 is the length of the hash (fixed in this case).