diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-04-20 04:22:23 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:57:18 +0800 |
commit | 67117913ddd492d5e8a6ccec57d8c5ced238040a (patch) | |
tree | 6010eda2a210b6dffa5c20c17391f972f683fe80 | |
parent | e532f2c1650d845aa1186daa8983de18d8affc3c (diff) | |
download | dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar.gz dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar.bz2 dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar.lz dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar.xz dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.tar.zst dexon-sol-tools-67117913ddd492d5e8a6ccec57d8c5ced238040a.zip |
Add presigned signature type
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index d8bb25fca..48e7be424 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -33,9 +33,18 @@ contract MixinSignatureValidator is Ecrecover, EIP712, Trezor, - Contract + Contract, + PreSigned } + // Mapping of hash => signer => signed + mapping(bytes32 => mapping(address => bool)) preSigned; + + /// @dev Verifies that a hash has been signed by the given signer. + /// @param hash Any 32 byte hash. + /// @param signer Address that should have signed the given hash. + /// @param signature Proof that the hash has been signed by signer. + /// @return True if the address recovered from the provided signature matches the input signer address. function isValidSignature( bytes32 hash, address signer, @@ -135,6 +144,11 @@ contract MixinSignatureValidator is } else if (signatureType == SignatureType.Contract) { isValid = ISigner(signer).isValidSignature(hash, signature); return isValid; + + // Signer signed hash previously using the preSign function + } else if (signatureType == SignatureType.PreSigned) { + isValid = preSigned[hash][signer]; + return isValid; } // Anything else is illegal (We do not return false because @@ -145,6 +159,20 @@ contract MixinSignatureValidator is revert(); } + /// @dev Approves a hash on-chain using any valid signature type. + /// After presigning a hash, the preSign signature type will become valid for that hash and signer. + /// @param signer Address that should have signed the given hash. + /// @param signature Proof that the hash has been signed by signer. + function preSign( + bytes32 hash, + address signer, + bytes memory signature) + public + { + require(isValidSignature(hash, signer, signature)); + preSigned[hash][signer] = true; + } + function get32(bytes memory b, uint256 index) private pure returns (bytes32 result) |