@waku/rln 0.0.2-09108d9.0 → 0.0.2-2380dac.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.
- package/bundle/index.js +2 -1
- package/bundle/packages/rln/dist/contract/abi.js +648 -0
- package/bundle/packages/rln/dist/contract/constants.js +25 -65
- package/bundle/packages/rln/dist/contract/rln_contract.js +370 -75
- package/bundle/packages/rln/dist/message.js +1 -1
- package/bundle/packages/rln/dist/rln.js +34 -20
- package/bundle/packages/rln/dist/zerokit.js +34 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/abi.d.ts +46 -0
- package/dist/contract/abi.js +647 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +63 -3
- package/dist/contract/constants.js +23 -64
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +100 -17
- package/dist/contract/rln_contract.js +369 -73
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/message.js +1 -1
- package/dist/message.js.map +1 -1
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +34 -19
- package/dist/rln.js.map +1 -1
- package/dist/zerokit.d.ts +10 -6
- package/dist/zerokit.js +34 -14
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/abi.ts +646 -0
- package/src/contract/constants.ts +26 -65
- package/src/contract/rln_contract.ts +549 -108
- package/src/index.ts +4 -9
- package/src/message.ts +1 -1
- package/src/rln.ts +54 -21
- package/src/zerokit.ts +74 -15
@@ -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:
|
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
|
-
|
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:
|
64
|
-
|
65
|
-
|
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,
|
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,124 @@ type Member = {
|
|
6
6
|
idCommitment: string;
|
7
7
|
index: ethers.BigNumber;
|
8
8
|
};
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
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
|
+
membershipRateLimit: ethers.BigNumber;
|
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
|
-
|
42
|
+
contract: ethers.Contract;
|
25
43
|
private merkleRootTracker;
|
26
44
|
private deployBlock;
|
27
|
-
private
|
28
|
-
private storageContract;
|
29
|
-
private _membersFilter;
|
45
|
+
private rateLimit;
|
30
46
|
private _members;
|
47
|
+
private _membersFilter;
|
48
|
+
private _membershipErasedFilter;
|
49
|
+
private _membersExpiredFilter;
|
50
|
+
/**
|
51
|
+
* Asynchronous initializer for RLNContract.
|
52
|
+
* Allows injecting a mocked contract for testing purposes.
|
53
|
+
*/
|
31
54
|
static init(rlnInstance: RLNInstance, options: RLNContractInitOptions): Promise<RLNContract>;
|
32
|
-
constructor(
|
33
|
-
|
34
|
-
|
35
|
-
|
55
|
+
private constructor();
|
56
|
+
/**
|
57
|
+
* Gets the current rate limit for this contract instance
|
58
|
+
*/
|
59
|
+
getRateLimit(): number;
|
60
|
+
/**
|
61
|
+
* Gets the contract address
|
62
|
+
*/
|
63
|
+
get address(): string;
|
64
|
+
/**
|
65
|
+
* Gets the contract provider
|
66
|
+
*/
|
67
|
+
get provider(): ethers.providers.Provider;
|
68
|
+
/**
|
69
|
+
* Gets the minimum allowed rate limit from the contract
|
70
|
+
* @returns Promise<number> The minimum rate limit in messages per epoch
|
71
|
+
*/
|
72
|
+
getMinRateLimit(): Promise<number>;
|
73
|
+
/**
|
74
|
+
* Gets the maximum allowed rate limit from the contract
|
75
|
+
* @returns Promise<number> The maximum rate limit in messages per epoch
|
76
|
+
*/
|
77
|
+
getMaxRateLimit(): Promise<number>;
|
78
|
+
/**
|
79
|
+
* Gets the maximum total rate limit across all memberships
|
80
|
+
* @returns Promise<number> The maximum total rate limit in messages per epoch
|
81
|
+
*/
|
82
|
+
getMaxTotalRateLimit(): Promise<number>;
|
83
|
+
/**
|
84
|
+
* Gets the current total rate limit usage across all memberships
|
85
|
+
* @returns Promise<number> The current total rate limit usage in messages per epoch
|
86
|
+
*/
|
87
|
+
getCurrentTotalRateLimit(): Promise<number>;
|
88
|
+
/**
|
89
|
+
* Gets the remaining available total rate limit that can be allocated
|
90
|
+
* @returns Promise<number> The remaining rate limit that can be allocated
|
91
|
+
*/
|
92
|
+
getRemainingTotalRateLimit(): Promise<number>;
|
93
|
+
/**
|
94
|
+
* Updates the rate limit for future registrations
|
95
|
+
* @param newRateLimit The new rate limit to use
|
96
|
+
*/
|
97
|
+
setRateLimit(newRateLimit: number): Promise<void>;
|
36
98
|
get members(): Member[];
|
37
99
|
private get membersFilter();
|
100
|
+
private get membershipErasedFilter();
|
101
|
+
private get membersExpiredFilter();
|
38
102
|
fetchMembers(rlnInstance: RLNInstance, options?: FetchMembersOptions): Promise<void>;
|
39
103
|
processEvents(rlnInstance: RLNInstance, events: ethers.Event[]): void;
|
40
104
|
private insertMembers;
|
41
105
|
private removeMembers;
|
42
106
|
subscribeToMembers(rlnInstance: RLNInstance): void;
|
43
107
|
registerWithIdentity(identity: IdentityCredential): Promise<DecryptedCredentials | undefined>;
|
108
|
+
/**
|
109
|
+
* Helper method to get remaining messages in current epoch
|
110
|
+
* @param membershipId The ID of the membership to check
|
111
|
+
* @returns number of remaining messages allowed in current epoch
|
112
|
+
*/
|
113
|
+
getRemainingMessages(membershipId: number): Promise<number>;
|
114
|
+
registerWithPermitAndErase(identity: IdentityCredential, permit: {
|
115
|
+
owner: string;
|
116
|
+
deadline: number;
|
117
|
+
v: number;
|
118
|
+
r: string;
|
119
|
+
s: string;
|
120
|
+
}, idCommitmentsToErase: string[]): Promise<DecryptedCredentials | undefined>;
|
44
121
|
roots(): Uint8Array[];
|
122
|
+
withdraw(token: string, holder: string): Promise<void>;
|
123
|
+
getMembershipInfo(idCommitment: string): Promise<MembershipInfo | undefined>;
|
124
|
+
extendMembership(idCommitment: string): Promise<ethers.ContractTransaction>;
|
125
|
+
eraseMembership(idCommitment: string, eraseFromMembershipSet?: boolean): Promise<ethers.ContractTransaction>;
|
126
|
+
registerMembership(idCommitment: string, rateLimit?: number): Promise<ethers.ContractTransaction>;
|
127
|
+
private getMemberIndex;
|
45
128
|
}
|
46
129
|
export {};
|