Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
881 additions
and
326 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
pragma solidity ^0.4.18; | ||
|
||
|
||
/** | ||
* @title Eliptic curve signature operations | ||
* | ||
* @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d | ||
*/ | ||
|
||
library ECRecovery { | ||
|
||
/** | ||
* @dev Recover signer address from a message by using his signature | ||
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. | ||
* @param sig bytes signature, the signature is generated using web3.eth.sign() | ||
*/ | ||
function recover(bytes32 hash, bytes sig) public pure returns (address) { | ||
bytes32 r; | ||
bytes32 s; | ||
uint8 v; | ||
|
||
//Check the signature length | ||
if (sig.length != 65) { | ||
return (address(0)); | ||
} | ||
|
||
// Divide the signature in r, s and v variables | ||
assembly { | ||
r := mload(add(sig, 32)) | ||
s := mload(add(sig, 64)) | ||
v := byte(0, mload(add(sig, 96))) | ||
} | ||
|
||
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions | ||
if (v < 27) { | ||
v += 27; | ||
} | ||
|
||
// If the version is correct return the signer address | ||
if (v != 27 && v != 28) { | ||
return (address(0)); | ||
} else { | ||
return ecrecover(hash, v, r, s); | ||
} | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.