-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExampleNPerEpochContract.sol
49 lines (42 loc) · 1.31 KB
/
ExampleNPerEpochContract.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.13;
import {ByteHasher} from "../helpers/ByteHasher.sol";
import {IWorldID} from "../interfaces/IWorldID.sol";
import { NPerEpoch} from "../NPerEpoch.sol";
contract ExampleNPerEpochContract is NPerEpoch {
using ByteHasher for bytes;
error MismatchedMessage();
error InvalidActionId();
event Message(string message);
mapping(uint256 => bool) internal nullifierHashes;
constructor(IWorldID _worldId) NPerEpoch(_worldId) {}
function sendMessage(
uint256 root,
string calldata input,
uint256 nullifierHash,
uint256[8] calldata proof,
RateLimitKey calldata actionId
)
public rateLimit(
root,
abi.encodePacked(input).hashToField(),
nullifierHash,
actionId,
proof
)
{
if (keccak256(abi.encodePacked(actionId.namespace)) != keccak256(abi.encodePacked("send_message"))) revert InvalidNullifier();
if (nullifierHashes[nullifierHash]) revert InvalidNullifier();
nullifierHashes[nullifierHash] = true;
emit Message(input);
}
function settings()
public
pure
virtual
override
returns (NPerEpoch.Settings memory)
{
return Settings(1, 300, 2);
}
}