-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERC721LazyMintWith712SignatureChecker.sol
49 lines (41 loc) · 1.67 KB
/
ERC721LazyMintWith712SignatureChecker.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
47
48
49
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
contract ERC721LazyMintWith712SignatureChecker is ERC721, EIP712, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
constructor(string memory name, string memory symbol)
ERC721(name, symbol)
EIP712(name, "1.0.0")
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
function redeem(address account, uint256 tokenId, address signer, bytes calldata signature)
external
{
require(_verify(signer, _hash(account, tokenId), signature), "Invalid signature");
_safeMint(account, tokenId);
}
function _hash(address account, uint256 tokenId)
internal view returns (bytes32)
{
return _hashTypedDataV4(keccak256(abi.encode(
keccak256("NFT(uint256 tokenId,address account)"),
tokenId,
account
)));
}
function _verify(address signer, bytes32 digest, bytes memory signature)
internal view returns (bool)
{
return hasRole(MINTER_ROLE, signer) && SignatureChecker.isValidSignatureNow(signer, digest, signature);
}
function _baseURI() internal view virtual override returns (string memory) {
return "ipfs://your_cid/";
}
}