From 67117913ddd492d5e8a6ccec57d8c5ced238040a Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 19 Apr 2018 13:22:23 -0700 Subject: Add presigned signature type --- .../protocol/Exchange/MixinSignatureValidator.sol | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'packages/contracts') 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) -- cgit v1.2.3