all files / contracts/mocks/ MockERC1271.sol

100% Statements 2/2
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                               
// SPDX-License-Identifier: GPL-3.0-or-later
// code borrowed from @uniswap/v3-periphery
pragma solidity 0.8.6;
 
import "./../interfaces/utils/IERC1271.sol";
 
 
/// @title Interface for verifying contract-based account signatures
/// @notice Interface that verifies provided signature for the data
/// @dev Interface defined by EIP-1271
contract MockERC1271 is IERC1271 {
 
    // hash => signature => valid or not
    mapping(bytes32 => mapping(bytes => bool)) private _validSignatures;
 
    /// @notice Returns whether the provided signature is valid for the provided data
    /// @dev MUST return the bytes4 magic value 0x1626ba7e when function passes.
    /// MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5).
    /// MUST allow external calls.
    /// @param hash Hash of the data to be signed
    /// @param signature Signature byte array associated with _data
    /// @return magicValue The bytes4 magic value 0x1626ba7e
    function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4 magicValue) {
        return ((_validSignatures[hash][signature])
          ? bytes4(0x1626ba7e)
          : bytes4(0xffffffff));
    }
 
    // adds or removes a signature
    function setSignature(bytes32 hash, bytes memory signature, bool valid) external {
        _validSignatures[hash][signature] = valid;
    }
}