@waku/rln 0.0.2-09108d9.0 → 0.0.2-8a6571f.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,67 @@
1
- export declare const RLN_REGISTRY_ABI: string[];
2
- export declare const RLN_STORAGE_ABI: string[];
3
1
  export declare const SEPOLIA_CONTRACT: {
4
2
  chainId: number;
5
3
  address: string;
6
- abi: string[];
4
+ abi: ({
5
+ inputs: never[];
6
+ stateMutability: string;
7
+ type: string;
8
+ name?: undefined;
9
+ anonymous?: undefined;
10
+ outputs?: undefined;
11
+ } | {
12
+ inputs: {
13
+ internalType: string;
14
+ name: string;
15
+ type: string;
16
+ }[];
17
+ name: string;
18
+ type: string;
19
+ stateMutability?: undefined;
20
+ anonymous?: undefined;
21
+ outputs?: undefined;
22
+ } | {
23
+ anonymous: boolean;
24
+ inputs: {
25
+ indexed: boolean;
26
+ internalType: string;
27
+ name: string;
28
+ type: string;
29
+ }[];
30
+ name: string;
31
+ type: string;
32
+ stateMutability?: undefined;
33
+ outputs?: undefined;
34
+ } | {
35
+ inputs: {
36
+ internalType: string;
37
+ name: string;
38
+ type: string;
39
+ }[];
40
+ name: string;
41
+ outputs: {
42
+ internalType: string;
43
+ name: string;
44
+ type: string;
45
+ }[];
46
+ stateMutability: string;
47
+ type: string;
48
+ anonymous?: undefined;
49
+ })[];
7
50
  };
51
+ /**
52
+ * Rate limit tiers (messages per epoch)
53
+ * Each membership can specify a rate limit within these bounds.
54
+ * @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
55
+ */
56
+ export declare const RATE_LIMIT_TIERS: {
57
+ readonly LOW: 20;
58
+ readonly MEDIUM: 200;
59
+ readonly HIGH: 600;
60
+ };
61
+ export declare const RATE_LIMIT_PARAMS: {
62
+ readonly MIN_RATE: 20;
63
+ readonly MAX_RATE: 600;
64
+ readonly MAX_TOTAL_RATE: 160000;
65
+ readonly EPOCH_LENGTH: 600;
66
+ };
67
+ export declare const DEFAULT_RATE_LIMIT: 600;
@@ -1,67 +1,26 @@
1
- // ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnRegistry_Implementation.json#L3
2
- export const RLN_REGISTRY_ABI = [
3
- "error IncompatibleStorage()",
4
- "error IncompatibleStorageIndex()",
5
- "error NoStorageContractAvailable()",
6
- "error StorageAlreadyExists(address storageAddress)",
7
- "event AdminChanged(address previousAdmin, address newAdmin)",
8
- "event BeaconUpgraded(address indexed beacon)",
9
- "event Initialized(uint8 version)",
10
- "event NewStorageContract(uint16 index, address storageAddress)",
11
- "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
12
- "event Upgraded(address indexed implementation)",
13
- "function forceProgress()",
14
- "function initialize(address _poseidonHasher)",
15
- "function newStorage()",
16
- "function nextStorageIndex() view returns (uint16)",
17
- "function owner() view returns (address)",
18
- "function poseidonHasher() view returns (address)",
19
- "function proxiableUUID() view returns (bytes32)",
20
- "function register(uint16 storageIndex, uint256 commitment)",
21
- "function register(uint256[] commitments)",
22
- "function register(uint16 storageIndex, uint256[] commitments)",
23
- "function registerStorage(address storageAddress)",
24
- "function renounceOwnership()",
25
- "function storages(uint16) view returns (address)",
26
- "function transferOwnership(address newOwner)",
27
- "function upgradeTo(address newImplementation)",
28
- "function upgradeToAndCall(address newImplementation, bytes data) payable",
29
- "function usingStorageIndex() view returns (uint16)"
30
- ];
31
- // ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnStorage_0.json#L3
32
- export const RLN_STORAGE_ABI = [
33
- "constructor(address _poseidonHasher, uint16 _contractIndex)",
34
- "error DuplicateIdCommitment()",
35
- "error FullTree()",
36
- "error InvalidIdCommitment(uint256 idCommitment)",
37
- "error NotImplemented()",
38
- "event MemberRegistered(uint256 idCommitment, uint256 index)",
39
- "event MemberWithdrawn(uint256 idCommitment, uint256 index)",
40
- "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
41
- "function DEPTH() view returns (uint256)",
42
- "function MEMBERSHIP_DEPOSIT() view returns (uint256)",
43
- "function SET_SIZE() view returns (uint256)",
44
- "function contractIndex() view returns (uint16)",
45
- "function deployedBlockNumber() view returns (uint32)",
46
- "function idCommitmentIndex() view returns (uint256)",
47
- "function isValidCommitment(uint256 idCommitment) view returns (bool)",
48
- "function memberExists(uint256) view returns (bool)",
49
- "function members(uint256) view returns (uint256)",
50
- "function owner() view returns (address)",
51
- "function poseidonHasher() view returns (address)",
52
- "function register(uint256[] idCommitments)",
53
- "function register(uint256 idCommitment) payable",
54
- "function renounceOwnership()",
55
- "function slash(uint256 idCommitment, address receiver, uint256[8] proof) pure",
56
- "function stakedAmounts(uint256) view returns (uint256)",
57
- "function transferOwnership(address newOwner)",
58
- "function verifier() view returns (address)",
59
- "function withdraw() pure",
60
- "function withdrawalBalance(address) view returns (uint256)"
61
- ];
1
+ import { RLN_ABI } from "./abi.js";
62
2
  export const SEPOLIA_CONTRACT = {
63
- chainId: 11155111,
64
- address: "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
65
- abi: RLN_REGISTRY_ABI
3
+ chainId: 59141,
4
+ // Implementation contract: 0xde2260ca49300357d5af4153cda0d18f7b3ea9b3
5
+ address: "0xb9cd878c90e49f797b4431fbf4fb333108cb90e6",
6
+ abi: RLN_ABI
66
7
  };
8
+ /**
9
+ * Rate limit tiers (messages per epoch)
10
+ * Each membership can specify a rate limit within these bounds.
11
+ * @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
12
+ */
13
+ export const RATE_LIMIT_TIERS = {
14
+ LOW: 20, // Suggested minimum rate - 20 messages per epoch
15
+ MEDIUM: 200,
16
+ HIGH: 600 // Suggested maximum rate - 600 messages per epoch
17
+ };
18
+ // Global rate limit parameters
19
+ export const RATE_LIMIT_PARAMS = {
20
+ MIN_RATE: RATE_LIMIT_TIERS.LOW,
21
+ MAX_RATE: RATE_LIMIT_TIERS.HIGH,
22
+ MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
23
+ EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
24
+ };
25
+ export const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
67
26
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/contract/constants.ts"],"names":[],"mappings":"AAAA,6JAA6J;AAC7J,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,6BAA6B;IAC7B,kCAAkC;IAClC,oCAAoC;IACpC,oDAAoD;IACpD,6DAA6D;IAC7D,8CAA8C;IAC9C,kCAAkC;IAClC,gEAAgE;IAChE,qFAAqF;IACrF,gDAAgD;IAChD,0BAA0B;IAC1B,8CAA8C;IAC9C,uBAAuB;IACvB,mDAAmD;IACnD,yCAAyC;IACzC,kDAAkD;IAClD,iDAAiD;IACjD,4DAA4D;IAC5D,0CAA0C;IAC1C,+DAA+D;IAC/D,kDAAkD;IAClD,8BAA8B;IAC9B,kDAAkD;IAClD,8CAA8C;IAC9C,+CAA+C;IAC/C,0EAA0E;IAC1E,oDAAoD;CACrD,CAAC;AAEF,+IAA+I;AAC/I,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,6DAA6D;IAC7D,+BAA+B;IAC/B,kBAAkB;IAClB,iDAAiD;IACjD,wBAAwB;IACxB,6DAA6D;IAC7D,4DAA4D;IAC5D,qFAAqF;IACrF,yCAAyC;IACzC,sDAAsD;IACtD,4CAA4C;IAC5C,gDAAgD;IAChD,sDAAsD;IACtD,qDAAqD;IACrD,sEAAsE;IACtE,oDAAoD;IACpD,kDAAkD;IAClD,yCAAyC;IACzC,kDAAkD;IAClD,4CAA4C;IAC5C,iDAAiD;IACjD,8BAA8B;IAC9B,+EAA+E;IAC/E,wDAAwD;IACxD,8CAA8C;IAC9C,4CAA4C;IAC5C,0BAA0B;IAC1B,4DAA4D;CAC7D,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,4CAA4C;IACrD,GAAG,EAAE,gBAAgB;CACtB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/contract/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,KAAK;IACd,sEAAsE;IACtE,OAAO,EAAE,4CAA4C;IACrD,GAAG,EAAE,OAAO;CACb,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,GAAG,EAAE,EAAE,EAAE,iDAAiD;IAC1D,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG,CAAC,kDAAkD;CACpD,CAAC;AAEX,+BAA+B;AAC/B,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,gBAAgB,CAAC,GAAG;IAC9B,QAAQ,EAAE,gBAAgB,CAAC,IAAI;IAC/B,cAAc,EAAE,OAAO,EAAE,kDAAkD;IAC3E,YAAY,EAAE,GAAG,CAAC,uCAAuC;CACjD,CAAC;AAEX,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,QAAQ,CAAC"}
@@ -6,41 +6,122 @@ type Member = {
6
6
  idCommitment: string;
7
7
  index: ethers.BigNumber;
8
8
  };
9
- type Signer = ethers.Signer;
10
- type RLNContractOptions = {
11
- signer: Signer;
12
- registryAddress: string;
13
- };
14
- type RLNStorageOptions = {
15
- storageIndex?: number;
16
- };
17
- type RLNContractInitOptions = RLNContractOptions & RLNStorageOptions;
9
+ interface RLNContractOptions {
10
+ signer: ethers.Signer;
11
+ address: string;
12
+ rateLimit?: number;
13
+ }
14
+ interface RLNContractInitOptions extends RLNContractOptions {
15
+ contract?: ethers.Contract;
16
+ }
17
+ export interface MembershipRegisteredEvent {
18
+ idCommitment: string;
19
+ rateLimit: number;
20
+ index: ethers.BigNumber;
21
+ }
18
22
  type FetchMembersOptions = {
19
23
  fromBlock?: number;
20
24
  fetchRange?: number;
21
25
  fetchChunks?: number;
22
26
  };
27
+ export interface MembershipInfo {
28
+ index: ethers.BigNumber;
29
+ idCommitment: string;
30
+ rateLimit: number;
31
+ startBlock: number;
32
+ endBlock: number;
33
+ state: MembershipState;
34
+ }
35
+ export declare enum MembershipState {
36
+ Active = "Active",
37
+ GracePeriod = "GracePeriod",
38
+ Expired = "Expired",
39
+ ErasedAwaitsWithdrawal = "ErasedAwaitsWithdrawal"
40
+ }
23
41
  export declare class RLNContract {
24
- private registryContract;
42
+ contract: ethers.Contract;
25
43
  private merkleRootTracker;
26
44
  private deployBlock;
27
- private storageIndex;
28
- private storageContract;
29
- private _membersFilter;
45
+ private rateLimit;
30
46
  private _members;
47
+ private _membersFilter;
48
+ private _membersRemovedFilter;
49
+ /**
50
+ * Asynchronous initializer for RLNContract.
51
+ * Allows injecting a mocked contract for testing purposes.
52
+ */
31
53
  static init(rlnInstance: RLNInstance, options: RLNContractInitOptions): Promise<RLNContract>;
32
- constructor(rlnInstance: RLNInstance, { registryAddress, signer }: RLNContractOptions);
33
- private initStorageContract;
34
- get registry(): ethers.Contract;
35
- get contract(): ethers.Contract;
54
+ private constructor();
55
+ /**
56
+ * Gets the current rate limit for this contract instance
57
+ */
58
+ getRateLimit(): number;
59
+ /**
60
+ * Gets the contract address
61
+ */
62
+ get address(): string;
63
+ /**
64
+ * Gets the contract provider
65
+ */
66
+ get provider(): ethers.providers.Provider;
67
+ /**
68
+ * Gets the minimum allowed rate limit from the contract
69
+ * @returns Promise<number> The minimum rate limit in messages per epoch
70
+ */
71
+ getMinRateLimit(): Promise<number>;
72
+ /**
73
+ * Gets the maximum allowed rate limit from the contract
74
+ * @returns Promise<number> The maximum rate limit in messages per epoch
75
+ */
76
+ getMaxRateLimit(): Promise<number>;
77
+ /**
78
+ * Gets the maximum total rate limit across all memberships
79
+ * @returns Promise<number> The maximum total rate limit in messages per epoch
80
+ */
81
+ getMaxTotalRateLimit(): Promise<number>;
82
+ /**
83
+ * Gets the current total rate limit usage across all memberships
84
+ * @returns Promise<number> The current total rate limit usage in messages per epoch
85
+ */
86
+ getCurrentTotalRateLimit(): Promise<number>;
87
+ /**
88
+ * Gets the remaining available total rate limit that can be allocated
89
+ * @returns Promise<number> The remaining rate limit that can be allocated
90
+ */
91
+ getRemainingTotalRateLimit(): Promise<number>;
92
+ /**
93
+ * Updates the rate limit for future registrations
94
+ * @param newRateLimit The new rate limit to use
95
+ */
96
+ setRateLimit(newRateLimit: number): Promise<void>;
36
97
  get members(): Member[];
37
98
  private get membersFilter();
99
+ private get membersRemovedFilter();
38
100
  fetchMembers(rlnInstance: RLNInstance, options?: FetchMembersOptions): Promise<void>;
39
101
  processEvents(rlnInstance: RLNInstance, events: ethers.Event[]): void;
40
102
  private insertMembers;
41
103
  private removeMembers;
42
104
  subscribeToMembers(rlnInstance: RLNInstance): void;
43
105
  registerWithIdentity(identity: IdentityCredential): Promise<DecryptedCredentials | undefined>;
106
+ /**
107
+ * Helper method to get remaining messages in current epoch
108
+ * @param membershipId The ID of the membership to check
109
+ * @returns number of remaining messages allowed in current epoch
110
+ */
111
+ getRemainingMessages(membershipId: number): Promise<number>;
112
+ registerWithPermitAndErase(identity: IdentityCredential, permit: {
113
+ owner: string;
114
+ deadline: number;
115
+ v: number;
116
+ r: string;
117
+ s: string;
118
+ }, idCommitmentsToErase: string[]): Promise<DecryptedCredentials | undefined>;
44
119
  roots(): Uint8Array[];
120
+ withdraw(token: string, holder: string): Promise<void>;
121
+ getMembershipInfo(idCommitment: string): Promise<MembershipInfo | undefined>;
122
+ extendMembership(idCommitment: string): Promise<ethers.ContractTransaction>;
123
+ eraseMembership(idCommitment: string, eraseFromMembershipSet?: boolean): Promise<ethers.ContractTransaction>;
124
+ registerMembership(idCommitment: string, rateLimit?: number): Promise<ethers.ContractTransaction>;
125
+ private getMemberIndex;
45
126
  }
46
127
  export {};