@waku/rln 0.1.1-7e93896 → 0.1.1-8928376
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 +22860 -315
- 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 +49 -0
- package/dist/keystore/keystore.js +182 -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/message.d.ts +1 -0
- package/dist/message.js +3 -0
- package/dist/message.js.map +1 -1
- package/dist/rln.js +3 -11
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +9 -3
- package/dist/rln_contract.js +28 -8
- 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/message.ts +4 -0
- package/src/rln.ts +3 -12
- package/src/rln_contract.ts +56 -13
package/dist/rln_contract.d.ts
CHANGED
@@ -4,9 +4,10 @@ declare type Member = {
|
|
4
4
|
pubkey: string;
|
5
5
|
index: number;
|
6
6
|
};
|
7
|
+
declare type Provider = ethers.Signer | ethers.providers.Provider;
|
7
8
|
declare type ContractOptions = {
|
8
9
|
address: string;
|
9
|
-
provider:
|
10
|
+
provider: Provider;
|
10
11
|
};
|
11
12
|
declare type FetchMembersOptions = {
|
12
13
|
fromBlock?: number;
|
@@ -14,14 +15,19 @@ declare type FetchMembersOptions = {
|
|
14
15
|
fetchChunks?: number;
|
15
16
|
};
|
16
17
|
export declare class RLNContract {
|
17
|
-
private
|
18
|
-
private membersFilter;
|
18
|
+
private registryContract;
|
19
19
|
private merkleRootTracker;
|
20
|
+
private deployBlock;
|
21
|
+
private storageIndex;
|
22
|
+
private storageContract;
|
23
|
+
private _membersFilter;
|
20
24
|
private _members;
|
21
25
|
static init(rlnInstance: RLNInstance, options: ContractOptions): Promise<RLNContract>;
|
22
26
|
constructor(rlnInstance: RLNInstance, { address, provider }: ContractOptions);
|
27
|
+
private initStorageContract;
|
23
28
|
get contract(): ethers.Contract;
|
24
29
|
get members(): Member[];
|
30
|
+
private get membersFilter();
|
25
31
|
fetchMembers(rlnInstance: RLNInstance, options?: FetchMembersOptions): Promise<void>;
|
26
32
|
processEvents(rlnInstance: RLNInstance, events: ethers.Event[]): void;
|
27
33
|
private insertMembers;
|
package/dist/rln_contract.js
CHANGED
@@ -1,28 +1,46 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import {
|
3
|
-
import { MerkleRootTracker } from "./root_tracker";
|
2
|
+
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
3
|
+
import { MerkleRootTracker } from "./root_tracker.js";
|
4
4
|
export class RLNContract {
|
5
5
|
constructor(rlnInstance, { address, provider }) {
|
6
6
|
this._members = [];
|
7
7
|
const initialRoot = rlnInstance.getMerkleRoot();
|
8
|
-
this.
|
8
|
+
this.registryContract = new ethers.Contract(address, 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) {
|
19
|
+
const index = await this.registryContract.usingStorageIndex();
|
20
|
+
const address = await this.registryContract.storages(index);
|
21
|
+
this.storageIndex = index;
|
22
|
+
this.storageContract = new ethers.Contract(address, RLN_STORAGE_ABI, provider);
|
23
|
+
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
24
|
+
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
25
|
+
}
|
18
26
|
get contract() {
|
19
|
-
|
27
|
+
if (!this.storageContract) {
|
28
|
+
throw Error("Storage contract was not initialized.");
|
29
|
+
}
|
30
|
+
return this.storageContract;
|
20
31
|
}
|
21
32
|
get members() {
|
22
33
|
return this._members;
|
23
34
|
}
|
35
|
+
get membersFilter() {
|
36
|
+
if (!this._membersFilter) {
|
37
|
+
throw Error("Members filter was not initialized.");
|
38
|
+
}
|
39
|
+
return this._membersFilter;
|
40
|
+
}
|
24
41
|
async fetchMembers(rlnInstance, options = {}) {
|
25
42
|
const registeredMemberEvents = await queryFilter(this.contract, {
|
43
|
+
fromBlock: this.deployBlock,
|
26
44
|
...options,
|
27
45
|
membersFilter: this.membersFilter,
|
28
46
|
});
|
@@ -95,9 +113,11 @@ export class RLNContract {
|
|
95
113
|
return this.registerWithKey(identityCredential);
|
96
114
|
}
|
97
115
|
async registerWithKey(credential) {
|
98
|
-
|
99
|
-
|
100
|
-
|
116
|
+
if (!this.storageIndex) {
|
117
|
+
throw Error("Cannot register credential, no storage contract index found.");
|
118
|
+
}
|
119
|
+
const txRegisterResponse = await this.registryContract.register(this.storageIndex, credential.IDCommitmentBigInt, {
|
120
|
+
gasLimit: 100000,
|
101
121
|
});
|
102
122
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
103
123
|
return txRegisterReceipt?.events?.[0];
|
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;AAoBtD,MAAM,OAAO,WAAW;IAwBtB,YACE,WAAwB,EACxB,EAAE,OAAO,EAAE,QAAQ,EAAmB;QAjBhC,aAAQ,GAAa,EAAE,CAAC;QAmB9B,MAAM,WAAW,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC;QAEhD,IAAI,CAAC,gBAAgB,GAAG,IAAI,MAAM,CAAC,QAAQ,CACzC,OAAO,EACP,gBAAgB,EAChB,QAAQ,CACT,CAAC;QACF,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAzBM,MAAM,CAAC,KAAK,CAAC,IAAI,CACtB,WAAwB,EACxB,OAAwB;QAExB,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAE1D,MAAM,WAAW,CAAC,mBAAmB,CAAC,OAAO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1
|
{
|
2
2
|
"name": "@waku/rln",
|
3
|
-
"version": "0.1.1-
|
3
|
+
"version": "0.1.1-8928376",
|
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.12",
|
87
|
-
"@waku/message-encryption": "^0.0.15",
|
88
|
-
"@waku/core": "^0.0.17",
|
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: "0xF1935b338321013f11068abCafC548A7B0db732C",
|
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/message.ts
CHANGED
@@ -57,6 +57,10 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
57
57
|
return this.msg.ephemeral;
|
58
58
|
}
|
59
59
|
|
60
|
+
get meta(): Uint8Array | undefined {
|
61
|
+
return this.msg.meta;
|
62
|
+
}
|
63
|
+
|
60
64
|
get epoch(): number | undefined {
|
61
65
|
const bytes = this.msg.rateLimitProof?.epoch;
|
62
66
|
if (!bytes) return;
|
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;
|
package/src/rln_contract.ts
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
4
4
|
import { IdentityCredential, RLNInstance } from "./rln.js";
|
5
|
-
import { MerkleRootTracker } from "./root_tracker";
|
5
|
+
import { MerkleRootTracker } from "./root_tracker.js";
|
6
6
|
|
7
7
|
type Member = {
|
8
8
|
pubkey: string;
|
9
9
|
index: number;
|
10
10
|
};
|
11
11
|
|
12
|
+
type Provider = ethers.Signer | ethers.providers.Provider;
|
13
|
+
|
12
14
|
type ContractOptions = {
|
13
15
|
address: string;
|
14
|
-
provider:
|
16
|
+
provider: Provider;
|
15
17
|
};
|
16
18
|
|
17
19
|
type FetchMembersOptions = {
|
@@ -21,10 +23,14 @@ type FetchMembersOptions = {
|
|
21
23
|
};
|
22
24
|
|
23
25
|
export class RLNContract {
|
24
|
-
private
|
25
|
-
private membersFilter: ethers.EventFilter;
|
26
|
+
private registryContract: ethers.Contract;
|
26
27
|
private merkleRootTracker: MerkleRootTracker;
|
27
28
|
|
29
|
+
private deployBlock: undefined | number;
|
30
|
+
private storageIndex: undefined | number;
|
31
|
+
private storageContract: undefined | ethers.Contract;
|
32
|
+
private _membersFilter: undefined | ethers.EventFilter;
|
33
|
+
|
28
34
|
private _members: Member[] = [];
|
29
35
|
|
30
36
|
public static async init(
|
@@ -33,6 +39,7 @@ export class RLNContract {
|
|
33
39
|
): Promise<RLNContract> {
|
34
40
|
const rlnContract = new RLNContract(rlnInstance, options);
|
35
41
|
|
42
|
+
await rlnContract.initStorageContract(options.provider);
|
36
43
|
await rlnContract.fetchMembers(rlnInstance);
|
37
44
|
rlnContract.subscribeToMembers(rlnInstance);
|
38
45
|
|
@@ -45,24 +52,53 @@ export class RLNContract {
|
|
45
52
|
) {
|
46
53
|
const initialRoot = rlnInstance.getMerkleRoot();
|
47
54
|
|
48
|
-
this.
|
55
|
+
this.registryContract = new ethers.Contract(
|
56
|
+
address,
|
57
|
+
RLN_REGISTRY_ABI,
|
58
|
+
provider
|
59
|
+
);
|
49
60
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
50
|
-
|
61
|
+
}
|
62
|
+
|
63
|
+
private async initStorageContract(provider: Provider): Promise<void> {
|
64
|
+
const index = await this.registryContract.usingStorageIndex();
|
65
|
+
const address = await this.registryContract.storages(index);
|
66
|
+
|
67
|
+
this.storageIndex = index;
|
68
|
+
this.storageContract = new ethers.Contract(
|
69
|
+
address,
|
70
|
+
RLN_STORAGE_ABI,
|
71
|
+
provider
|
72
|
+
);
|
73
|
+
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
74
|
+
|
75
|
+
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
51
76
|
}
|
52
77
|
|
53
78
|
public get contract(): ethers.Contract {
|
54
|
-
|
79
|
+
if (!this.storageContract) {
|
80
|
+
throw Error("Storage contract was not initialized.");
|
81
|
+
}
|
82
|
+
return this.storageContract as ethers.Contract;
|
55
83
|
}
|
56
84
|
|
57
85
|
public get members(): Member[] {
|
58
86
|
return this._members;
|
59
87
|
}
|
60
88
|
|
89
|
+
private get membersFilter(): ethers.EventFilter {
|
90
|
+
if (!this._membersFilter) {
|
91
|
+
throw Error("Members filter was not initialized.");
|
92
|
+
}
|
93
|
+
return this._membersFilter as ethers.EventFilter;
|
94
|
+
}
|
95
|
+
|
61
96
|
public async fetchMembers(
|
62
97
|
rlnInstance: RLNInstance,
|
63
98
|
options: FetchMembersOptions = {}
|
64
99
|
): Promise<void> {
|
65
100
|
const registeredMemberEvents = await queryFilter(this.contract, {
|
101
|
+
fromBlock: this.deployBlock,
|
66
102
|
...options,
|
67
103
|
membersFilter: this.membersFilter,
|
68
104
|
});
|
@@ -164,12 +200,19 @@ export class RLNContract {
|
|
164
200
|
public async registerWithKey(
|
165
201
|
credential: IdentityCredential
|
166
202
|
): Promise<ethers.Event | undefined> {
|
167
|
-
|
168
|
-
|
203
|
+
if (!this.storageIndex) {
|
204
|
+
throw Error(
|
205
|
+
"Cannot register credential, no storage contract index found."
|
206
|
+
);
|
207
|
+
}
|
169
208
|
const txRegisterResponse: ethers.ContractTransaction =
|
170
|
-
await this.
|
171
|
-
|
172
|
-
|
209
|
+
await this.registryContract.register(
|
210
|
+
this.storageIndex,
|
211
|
+
credential.IDCommitmentBigInt,
|
212
|
+
{
|
213
|
+
gasLimit: 100000,
|
214
|
+
}
|
215
|
+
);
|
173
216
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
174
217
|
|
175
218
|
return txRegisterReceipt?.events?.[0];
|