-
Notifications
You must be signed in to change notification settings - Fork 22
/
WordLinesToken.sol
64 lines (53 loc) · 1.86 KB
/
WordLinesToken.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pragma solidity >=0.6.0 <0.9.0;
//SPDX-License-Identifier: MIT
import "hardhat/console.sol";
import "./wordlinesVerifier.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract WordLinesToken is Verifier, ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() public ERC721("WordLinesToken", "WLT") {
_setBaseURI("https://ipfs.io/ipfs/");
}
mapping(bytes32 => string) public inputToTokenURI;
mapping(address => mapping(string => bool)) public claimedTokenURIs;
function getHash(uint[92] memory input) public pure returns (bytes32) {
uint[] memory copy = new uint[](91);
for (uint i = 0;i < 91;i++) copy[i] = input[i];
return keccak256(abi.encodePacked(copy));
}
function mintItem(
address to,
uint[2] memory a,
uint[2][2] memory b,
uint[2] memory c,
uint[92] memory input
) public
returns (uint256)
{
uint256 addr = uint256(to);
bytes32 inputHash = getHash(input);
require(input[91] == addr, "Address does not match zk input address");
string memory tokenURI = inputToTokenURI[inputHash];
require(bytes(tokenURI).length != 0, "Invalid token URI");
require(claimedTokenURIs[to][tokenURI] != true, "Already claimed token URI");
require(verifyProof(a, b, c, input), "Invalid Proof");
_tokenIds.increment();
uint256 id = _tokenIds.current();
_mint(to, id);
_setTokenURI(id, tokenURI);
claimedTokenURIs[to][tokenURI] = true;
return id;
}
function addToken(
string memory tokenURI,
uint[92] memory input
) public onlyOwner
returns (bool)
{
inputToTokenURI[getHash(input)] = tokenURI;
return true;
}
}