/
ERC1271WalletMock.sol
46 lines (40 loc) · 1.4 KB
/
ERC1271WalletMock.sol
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
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: MIT
// solhint-disable one-contract-per-file
pragma solidity ^0.8.0;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
contract ERC1271WalletMock is Ownable, IERC1271, IERC721Receiver {
constructor(address originalOwner) {
transferOwnership(originalOwner);
}
function isValidSignature(
bytes32 hash,
bytes memory signature
) external view override returns (bytes4 magicValue) {
return
ECDSA.recover(hash, signature) == owner() ? this.isValidSignature.selector : bytes4(0);
}
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external pure override returns (bytes4) {
return this.onERC721Received.selector;
}
}
contract ERC1271MaliciousMock is IERC1271, IERC721Receiver {
function isValidSignature(bytes32, bytes memory) external pure override returns (bytes4) {
return 0xffffffff;
}
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external pure override returns (bytes4) {
return this.onERC721Received.selector;
}
}