@waku/rln 0.1.1-b429b05 → 0.1.1-fa49e29
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 +22902 -334
- package/dist/.tsbuildinfo +1 -1
- package/dist/byte_utils.d.ts +6 -0
- package/dist/byte_utils.js +9 -0
- package/dist/byte_utils.js.map +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +62 -9
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +2 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +193 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +9 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/rln.js +3 -11
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +21 -11
- package/dist/rln_contract.js +58 -23
- package/dist/rln_contract.js.map +1 -1
- package/package.json +22 -7
- package/src/byte_utils.ts +10 -0
- package/src/constants.ts +63 -9
- package/src/index.ts +9 -2
- package/src/rln.ts +3 -12
- package/src/rln_contract.ts +113 -35
package/dist/rln_contract.d.ts
CHANGED
@@ -1,34 +1,44 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
2
|
import { IdentityCredential, RLNInstance } from "./rln.js";
|
3
3
|
declare type Member = {
|
4
|
-
|
5
|
-
index:
|
4
|
+
idCommitment: string;
|
5
|
+
index: ethers.BigNumber;
|
6
6
|
};
|
7
|
-
declare type
|
8
|
-
|
9
|
-
provider:
|
7
|
+
declare type Provider = ethers.Signer | ethers.providers.Provider;
|
8
|
+
declare type RLNContractOptions = {
|
9
|
+
provider: Provider;
|
10
|
+
registryAddress: string;
|
10
11
|
};
|
12
|
+
declare type RLNStorageOptions = {
|
13
|
+
storageIndex?: number;
|
14
|
+
};
|
15
|
+
declare type RLNContractInitOptions = RLNContractOptions & RLNStorageOptions;
|
11
16
|
declare type FetchMembersOptions = {
|
12
17
|
fromBlock?: number;
|
13
18
|
fetchRange?: number;
|
14
19
|
fetchChunks?: number;
|
15
20
|
};
|
16
21
|
export declare class RLNContract {
|
17
|
-
private
|
18
|
-
private membersFilter;
|
22
|
+
private registryContract;
|
19
23
|
private merkleRootTracker;
|
24
|
+
private deployBlock;
|
25
|
+
private storageIndex;
|
26
|
+
private storageContract;
|
27
|
+
private _membersFilter;
|
20
28
|
private _members;
|
21
|
-
static init(rlnInstance: RLNInstance, options:
|
22
|
-
constructor(rlnInstance: RLNInstance, {
|
29
|
+
static init(rlnInstance: RLNInstance, options: RLNContractInitOptions): Promise<RLNContract>;
|
30
|
+
constructor(rlnInstance: RLNInstance, { registryAddress, provider }: RLNContractOptions);
|
31
|
+
private initStorageContract;
|
23
32
|
get contract(): ethers.Contract;
|
24
33
|
get members(): Member[];
|
34
|
+
private get membersFilter();
|
25
35
|
fetchMembers(rlnInstance: RLNInstance, options?: FetchMembersOptions): Promise<void>;
|
26
36
|
processEvents(rlnInstance: RLNInstance, events: ethers.Event[]): void;
|
27
37
|
private insertMembers;
|
28
38
|
private removeMembers;
|
29
39
|
subscribeToMembers(rlnInstance: RLNInstance): void;
|
30
|
-
registerWithSignature(rlnInstance: RLNInstance, signature: string): Promise<
|
31
|
-
registerWithKey(credential: IdentityCredential): Promise<
|
40
|
+
registerWithSignature(rlnInstance: RLNInstance, signature: string): Promise<Member | undefined>;
|
41
|
+
registerWithKey(credential: IdentityCredential): Promise<Member | undefined>;
|
32
42
|
roots(): Uint8Array[];
|
33
43
|
}
|
34
44
|
export {};
|
package/dist/rln_contract.js
CHANGED
@@ -1,28 +1,52 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import {
|
2
|
+
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
3
3
|
import { MerkleRootTracker } from "./root_tracker.js";
|
4
4
|
export class RLNContract {
|
5
|
-
constructor(rlnInstance, {
|
6
|
-
this._members =
|
5
|
+
constructor(rlnInstance, { registryAddress, provider }) {
|
6
|
+
this._members = new Map();
|
7
7
|
const initialRoot = rlnInstance.getMerkleRoot();
|
8
|
-
this.
|
8
|
+
this.registryContract = new ethers.Contract(registryAddress, RLN_REGISTRY_ABI, provider);
|
9
9
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
10
|
-
this.membersFilter = this.contract.filters.MemberRegistered();
|
11
10
|
}
|
12
11
|
static async init(rlnInstance, options) {
|
13
12
|
const rlnContract = new RLNContract(rlnInstance, options);
|
13
|
+
await rlnContract.initStorageContract(options.provider);
|
14
14
|
await rlnContract.fetchMembers(rlnInstance);
|
15
15
|
rlnContract.subscribeToMembers(rlnInstance);
|
16
16
|
return rlnContract;
|
17
17
|
}
|
18
|
+
async initStorageContract(provider, options = {}) {
|
19
|
+
const storageIndex = options?.storageIndex
|
20
|
+
? options.storageIndex
|
21
|
+
: await this.registryContract.usingStorageIndex();
|
22
|
+
const storageAddress = await this.registryContract.storages(storageIndex);
|
23
|
+
if (!storageAddress || storageAddress === ethers.constants.AddressZero) {
|
24
|
+
throw Error("No RLN Storage initialized on registry contract.");
|
25
|
+
}
|
26
|
+
this.storageIndex = storageIndex;
|
27
|
+
this.storageContract = new ethers.Contract(storageAddress, RLN_STORAGE_ABI, provider);
|
28
|
+
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
29
|
+
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
30
|
+
}
|
18
31
|
get contract() {
|
19
|
-
|
32
|
+
if (!this.storageContract) {
|
33
|
+
throw Error("Storage contract was not initialized");
|
34
|
+
}
|
35
|
+
return this.storageContract;
|
20
36
|
}
|
21
37
|
get members() {
|
22
|
-
|
38
|
+
const sortedMembers = Array.from(this._members.values()).sort((left, right) => left.index.toNumber() - right.index.toNumber());
|
39
|
+
return sortedMembers;
|
40
|
+
}
|
41
|
+
get membersFilter() {
|
42
|
+
if (!this._membersFilter) {
|
43
|
+
throw Error("Members filter was not initialized.");
|
44
|
+
}
|
45
|
+
return this._membersFilter;
|
23
46
|
}
|
24
47
|
async fetchMembers(rlnInstance, options = {}) {
|
25
48
|
const registeredMemberEvents = await queryFilter(this.contract, {
|
49
|
+
fromBlock: this.deployBlock,
|
26
50
|
...options,
|
27
51
|
membersFilter: this.membersFilter,
|
28
52
|
});
|
@@ -39,11 +63,11 @@ export class RLNContract {
|
|
39
63
|
const index = evt.args.index;
|
40
64
|
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
41
65
|
if (toRemoveVal != undefined) {
|
42
|
-
toRemoveVal.push(index);
|
66
|
+
toRemoveVal.push(index.toNumber());
|
43
67
|
toRemoveTable.set(evt.blockNumber, toRemoveVal);
|
44
68
|
}
|
45
69
|
else {
|
46
|
-
toRemoveTable.set(evt.blockNumber, [index]);
|
70
|
+
toRemoveTable.set(evt.blockNumber, [index.toNumber()]);
|
47
71
|
}
|
48
72
|
}
|
49
73
|
else {
|
@@ -61,14 +85,17 @@ export class RLNContract {
|
|
61
85
|
insertMembers(rlnInstance, toInsert) {
|
62
86
|
toInsert.forEach((events, blockNumber) => {
|
63
87
|
events.forEach((evt) => {
|
64
|
-
|
88
|
+
const _idCommitment = evt?.args?.idCommitment;
|
89
|
+
const index = evt?.args?.index;
|
90
|
+
if (!_idCommitment || !index) {
|
65
91
|
return;
|
66
92
|
}
|
67
|
-
const
|
68
|
-
const index = evt.args.index;
|
69
|
-
const idCommitment = ethers.utils.zeroPad(ethers.utils.arrayify(pubkey), 32);
|
93
|
+
const idCommitment = ethers.utils.zeroPad(ethers.utils.arrayify(_idCommitment), 32);
|
70
94
|
rlnInstance.insertMember(idCommitment);
|
71
|
-
this.
|
95
|
+
this._members.set(index.toNumber(), {
|
96
|
+
index,
|
97
|
+
idCommitment: _idCommitment?._hex || ethers.utils.hexlify(idCommitment),
|
98
|
+
});
|
72
99
|
});
|
73
100
|
const currentRoot = rlnInstance.getMerkleRoot();
|
74
101
|
this.merkleRootTracker.pushRoot(blockNumber, currentRoot);
|
@@ -78,9 +105,8 @@ export class RLNContract {
|
|
78
105
|
const removeDescending = new Map([...toRemove].sort().reverse());
|
79
106
|
removeDescending.forEach((indexes, blockNumber) => {
|
80
107
|
indexes.forEach((index) => {
|
81
|
-
|
82
|
-
|
83
|
-
this.members.splice(idx, 1);
|
108
|
+
if (this._members.has(index)) {
|
109
|
+
this._members.delete(index);
|
84
110
|
}
|
85
111
|
rlnInstance.deleteMember(index);
|
86
112
|
});
|
@@ -88,19 +114,28 @@ export class RLNContract {
|
|
88
114
|
});
|
89
115
|
}
|
90
116
|
subscribeToMembers(rlnInstance) {
|
91
|
-
this.contract.on(this.membersFilter, (_pubkey, _index, event) => this.processEvents(rlnInstance, event));
|
117
|
+
this.contract.on(this.membersFilter, (_pubkey, _index, event) => this.processEvents(rlnInstance, [event]));
|
92
118
|
}
|
93
119
|
async registerWithSignature(rlnInstance, signature) {
|
94
120
|
const identityCredential = await rlnInstance.generateSeededIdentityCredential(signature);
|
95
121
|
return this.registerWithKey(identityCredential);
|
96
122
|
}
|
97
123
|
async registerWithKey(credential) {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
});
|
124
|
+
if (this.storageIndex === undefined) {
|
125
|
+
throw Error("Cannot register credential, no storage contract index found.");
|
126
|
+
}
|
127
|
+
const txRegisterResponse = await this.registryContract["register(uint16,uint256)"](this.storageIndex, credential.IDCommitmentBigInt, { gasLimit: 100000 });
|
102
128
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
103
|
-
|
129
|
+
// assumption: register(uint16,uint256) emits one event
|
130
|
+
const memberRegistered = txRegisterReceipt?.events?.[0];
|
131
|
+
if (!memberRegistered) {
|
132
|
+
return undefined;
|
133
|
+
}
|
134
|
+
const decodedData = this.contract.interface.decodeEventLog("MemberRegistered", memberRegistered.data);
|
135
|
+
return {
|
136
|
+
idCommitment: decodedData.idCommitment,
|
137
|
+
index: decodedData.index,
|
138
|
+
};
|
104
139
|
}
|
105
140
|
roots() {
|
106
141
|
return this.merkleRootTracker.roots();
|
package/dist/rln_contract.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rln_contract.js","sourceRoot":"","sources":["../src/rln_contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"rln_contract.js","sourceRoot":"","sources":["../src/rln_contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AA0BtD,MAAM,OAAO,WAAW;IAwBtB,YACE,WAAwB,EACxB,EAAE,eAAe,EAAE,QAAQ,EAAsB;QAjB3C,aAAQ,GAAwB,IAAI,GAAG,EAAE,CAAC;QAmBhD,MAAM,WAAW,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC;QAEhD,IAAI,CAAC,gBAAgB,GAAG,IAAI,MAAM,CAAC,QAAQ,CACzC,eAAe,EACf,gBAAgB,EAChB,QAAQ,CACT,CAAC;QACF,IAAI,CAAC,iBAAiB,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AClC,CAAC;AAED,SAAS,aAAa,CACpB,IAAY,EACZ,EAAU,EACV,IAAY;IAEZ,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,OAAO,IAAI,GAAG,EAAE,EAAE;QAChB,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAElD,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAqB,CAAC,CAAC;QAE/C,IAAI,GAAG,KAAK,CAAC;KACd;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,QAAQ,CAAC,CAAC,KAAK,CAAI,KAAU,EAAE,IAAY;IACzC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,OAAO,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE;QAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEzC,MAAM,OAAO,CAAC;QAEd,KAAK,GAAG,IAAI,CAAC;QACb,IAAI,IAAI,IAAI,CAAC;KACd;AACH,CAAC;AAED,SAAS,YAAY,CAAI,OAAmB,EAAE,YAAe;IAC3D,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,mCAAmC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/rln",
|
3
|
-
"version": "0.1.1-
|
3
|
+
"version": "0.1.1-fa49e29",
|
4
4
|
"description": "Rate Limit Nullifier for js-waku",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -24,6 +24,7 @@
|
|
24
24
|
"scripts": {
|
25
25
|
"prepare": "husky install",
|
26
26
|
"build": "run-s build:**",
|
27
|
+
"build:codegen": "node ./scripts/schema_validator_codegen.js",
|
27
28
|
"build:tsc": "tsc",
|
28
29
|
"build:bundle": "rollup --config rollup.config.js",
|
29
30
|
"size": "npm run build && size-limit",
|
@@ -45,7 +46,7 @@
|
|
45
46
|
"crypto": false
|
46
47
|
},
|
47
48
|
"engines": {
|
48
|
-
"node": ">=
|
49
|
+
"node": ">=18"
|
49
50
|
},
|
50
51
|
"publishConfig": {
|
51
52
|
"access": "public",
|
@@ -59,19 +60,31 @@
|
|
59
60
|
"@size-limit/preset-big-lib": "^8.0.0",
|
60
61
|
"@types/app-root-path": "^1.2.4",
|
61
62
|
"@types/chai": "^4.2.15",
|
63
|
+
"@types/chai-as-promised": "^7.1.6",
|
62
64
|
"@types/chai-spies": "^1.0.3",
|
65
|
+
"@types/chai-subset": "^1.3.3",
|
63
66
|
"@types/debug": "^4.1.7",
|
67
|
+
"@types/deep-equal-in-any-order": "^1.0.1",
|
68
|
+
"@types/lodash": "^4.14.199",
|
64
69
|
"@types/mocha": "^9.1.0",
|
65
70
|
"@types/node": "^17.0.6",
|
66
71
|
"@types/tail": "^2.0.0",
|
67
72
|
"@types/uuid": "^8.3.0",
|
68
73
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
69
74
|
"@typescript-eslint/parser": "^5.8.1",
|
75
|
+
"@waku/core": "^0.0.18",
|
76
|
+
"@waku/interfaces": "^0.0.13",
|
77
|
+
"@waku/message-encryption": "^0.0.16",
|
70
78
|
"@web/rollup-plugin-import-meta-assets": "^1.0.7",
|
79
|
+
"ajv": "^8.12.0",
|
80
|
+
"ajv-formats": "^2.1.1",
|
71
81
|
"app-root-path": "^3.0.0",
|
72
82
|
"chai": "^4.3.4",
|
83
|
+
"chai-as-promised": "^7.1.1",
|
73
84
|
"chai-spies": "^1.0.0",
|
85
|
+
"chai-subset": "^1.6.0",
|
74
86
|
"cspell": "^5.14.0",
|
87
|
+
"deep-equal-in-any-order": "^2.0.6",
|
75
88
|
"eslint": "^8.6.0",
|
76
89
|
"eslint-config-prettier": "^8.3.0",
|
77
90
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
@@ -83,9 +96,6 @@
|
|
83
96
|
"husky": "^7.0.4",
|
84
97
|
"ignore-loader": "^0.1.2",
|
85
98
|
"isomorphic-fetch": "^3.0.0",
|
86
|
-
"@waku/interfaces": "^0.0.13",
|
87
|
-
"@waku/message-encryption": "^0.0.16",
|
88
|
-
"@waku/core": "^0.0.18",
|
89
99
|
"jsdom": "^19.0.0",
|
90
100
|
"jsdom-global": "^3.0.2",
|
91
101
|
"karma": "^6.3.12",
|
@@ -129,8 +139,13 @@
|
|
129
139
|
]
|
130
140
|
},
|
131
141
|
"dependencies": {
|
132
|
-
"@
|
142
|
+
"@chainsafe/bls-keystore": "^3.0.0",
|
143
|
+
"@waku/utils": "^0.0.11",
|
133
144
|
"@waku/zerokit-rln-wasm": "^0.0.10",
|
134
|
-
"
|
145
|
+
"ethereum-cryptography": "^2.1.2",
|
146
|
+
"ethers": "^5.7.2",
|
147
|
+
"lodash": "^4.17.21",
|
148
|
+
"rlnjs": "^3.2.3",
|
149
|
+
"uuid": "^9.0.1"
|
135
150
|
}
|
136
151
|
}
|
package/src/byte_utils.ts
CHANGED
@@ -37,3 +37,13 @@ export function writeUIntLE(
|
|
37
37
|
|
38
38
|
return buf;
|
39
39
|
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Transforms Uint8Array into BigInt
|
43
|
+
* @param array: Uint8Array
|
44
|
+
* @returns BigInt
|
45
|
+
*/
|
46
|
+
export function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
47
|
+
const dataView = new DataView(array.buffer);
|
48
|
+
return dataView.getBigUint64(0, true);
|
49
|
+
}
|
package/src/constants.ts
CHANGED
@@ -1,14 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
"
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
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
|
+
|
32
|
+
// ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnStorage_0.json#L3
|
33
|
+
export const RLN_STORAGE_ABI = [
|
34
|
+
"constructor(address _poseidonHasher, uint16 _contractIndex)",
|
35
|
+
"error DuplicateIdCommitment()",
|
36
|
+
"error FullTree()",
|
37
|
+
"error InvalidIdCommitment(uint256 idCommitment)",
|
38
|
+
"error NotImplemented()",
|
39
|
+
"event MemberRegistered(uint256 idCommitment, uint256 index)",
|
40
|
+
"event MemberWithdrawn(uint256 idCommitment, uint256 index)",
|
41
|
+
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
|
42
|
+
"function DEPTH() view returns (uint256)",
|
43
|
+
"function MEMBERSHIP_DEPOSIT() view returns (uint256)",
|
44
|
+
"function SET_SIZE() view returns (uint256)",
|
45
|
+
"function contractIndex() view returns (uint16)",
|
46
|
+
"function deployedBlockNumber() view returns (uint32)",
|
47
|
+
"function idCommitmentIndex() view returns (uint256)",
|
48
|
+
"function isValidCommitment(uint256 idCommitment) view returns (bool)",
|
49
|
+
"function memberExists(uint256) view returns (bool)",
|
50
|
+
"function members(uint256) view returns (uint256)",
|
51
|
+
"function owner() view returns (address)",
|
52
|
+
"function poseidonHasher() view returns (address)",
|
53
|
+
"function register(uint256[] idCommitments)",
|
54
|
+
"function register(uint256 idCommitment) payable",
|
55
|
+
"function renounceOwnership()",
|
56
|
+
"function slash(uint256 idCommitment, address receiver, uint256[8] proof) pure",
|
57
|
+
"function stakedAmounts(uint256) view returns (uint256)",
|
58
|
+
"function transferOwnership(address newOwner)",
|
59
|
+
"function verifier() view returns (address)",
|
60
|
+
"function withdraw() pure",
|
61
|
+
"function withdrawalBalance(address) view returns (uint256)",
|
7
62
|
];
|
8
63
|
|
9
64
|
export const SEPOLIA_CONTRACT = {
|
10
65
|
chainId: 11155111,
|
11
|
-
|
12
|
-
|
13
|
-
abi: RLN_ABI,
|
66
|
+
address: "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
|
67
|
+
abi: RLN_REGISTRY_ABI,
|
14
68
|
};
|
package/src/index.ts
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
RLN_REGISTRY_ABI,
|
4
|
+
RLN_STORAGE_ABI,
|
5
|
+
SEPOLIA_CONTRACT,
|
6
|
+
} from "./constants.js";
|
7
|
+
import { Keystore } from "./keystore/index.js";
|
3
8
|
import {
|
4
9
|
IdentityCredential,
|
5
10
|
Proof,
|
@@ -19,6 +24,7 @@ export async function create(): Promise<RLNInstance> {
|
|
19
24
|
}
|
20
25
|
|
21
26
|
export {
|
27
|
+
Keystore,
|
22
28
|
RLNInstance,
|
23
29
|
IdentityCredential,
|
24
30
|
Proof,
|
@@ -27,6 +33,7 @@ export {
|
|
27
33
|
RLNDecoder,
|
28
34
|
MerkleRootTracker,
|
29
35
|
RLNContract,
|
30
|
-
|
36
|
+
RLN_STORAGE_ABI,
|
37
|
+
RLN_REGISTRY_ABI,
|
31
38
|
SEPOLIA_CONTRACT,
|
32
39
|
};
|
package/src/rln.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import type { IRateLimitProof } from "@waku/interfaces";
|
2
|
-
import
|
2
|
+
import { default as init } from "@waku/zerokit-rln-wasm";
|
3
|
+
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
3
4
|
|
4
|
-
import { writeUIntLE } from "./byte_utils.js";
|
5
|
+
import { buildBigIntFromUint8Array, writeUIntLE } from "./byte_utils.js";
|
5
6
|
import { dateToEpoch, epochIntToBytes } from "./epoch.js";
|
6
7
|
import verificationKey from "./resources/verification_key.js";
|
7
8
|
import * as wc from "./witness_calculator.js";
|
@@ -26,16 +27,6 @@ function concatenate(...input: Uint8Array[]): Uint8Array {
|
|
26
27
|
return result;
|
27
28
|
}
|
28
29
|
|
29
|
-
/**
|
30
|
-
* Transforms Uint8Array into BigInt
|
31
|
-
* @param array: Uint8Array
|
32
|
-
* @returns BigInt
|
33
|
-
*/
|
34
|
-
function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
35
|
-
const dataView = new DataView(array.buffer);
|
36
|
-
return dataView.getBigUint64(0, true);
|
37
|
-
}
|
38
|
-
|
39
30
|
const stringEncoder = new TextEncoder();
|
40
31
|
|
41
32
|
const DEPTH = 20;
|