aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol30
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)