@waku/rln 0.1.1-fa49e29 → 0.1.2-86d4f56
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/README.md +26 -2
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/bundle/index.js +28541 -4914
- package/dist/.tsbuildinfo +1 -1
- package/dist/byte_utils.d.ts +7 -0
- package/dist/byte_utils.js +13 -0
- package/dist/byte_utils.js.map +1 -1
- package/dist/codec.d.ts +5 -3
- package/dist/codec.js +8 -4
- package/dist/codec.js.map +1 -1
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/dist/keystore/index.d.ts +2 -0
- package/dist/keystore/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +11 -11
- package/dist/keystore/keystore.js +12 -3
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +25 -5
- package/dist/message.d.ts +1 -1
- package/dist/message.js +1 -1
- package/dist/metamask.d.ts +2 -0
- package/dist/metamask.js +11 -0
- package/dist/metamask.js.map +1 -0
- package/dist/rln.d.ts +51 -0
- package/dist/rln.js +132 -2
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +12 -11
- package/dist/rln_contract.js +32 -21
- package/dist/rln_contract.js.map +1 -1
- package/package.json +6 -6
- package/src/byte_utils.ts +14 -0
- package/src/codec.ts +10 -5
- package/src/create.ts +9 -0
- package/src/index.ts +4 -9
- package/src/message.ts +1 -1
- package/src/metamask.ts +16 -0
- package/src/rln.ts +237 -2
- package/src/rln_contract.ts +37 -33
- package/bundle/assets/rln_wasm_bg-6f96f821.wasm +0 -0
package/src/rln_contract.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
import { hexToBytes } from "@waku/utils/bytes";
|
1
2
|
import { ethers } from "ethers";
|
2
3
|
|
4
|
+
import { zeroPadLE } from "./byte_utils.js";
|
3
5
|
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
4
|
-
import {
|
6
|
+
import type { DecryptedCredentials } from "./keystore/index.js";
|
7
|
+
import { type IdentityCredential, RLNInstance } from "./rln.js";
|
5
8
|
import { MerkleRootTracker } from "./root_tracker.js";
|
6
9
|
|
7
10
|
type Member = {
|
@@ -9,10 +12,10 @@ type Member = {
|
|
9
12
|
index: ethers.BigNumber;
|
10
13
|
};
|
11
14
|
|
12
|
-
type
|
15
|
+
type Signer = ethers.Signer;
|
13
16
|
|
14
17
|
type RLNContractOptions = {
|
15
|
-
|
18
|
+
signer: Signer;
|
16
19
|
registryAddress: string;
|
17
20
|
};
|
18
21
|
|
@@ -45,7 +48,7 @@ export class RLNContract {
|
|
45
48
|
): Promise<RLNContract> {
|
46
49
|
const rlnContract = new RLNContract(rlnInstance, options);
|
47
50
|
|
48
|
-
await rlnContract.initStorageContract(options.
|
51
|
+
await rlnContract.initStorageContract(options.signer);
|
49
52
|
await rlnContract.fetchMembers(rlnInstance);
|
50
53
|
rlnContract.subscribeToMembers(rlnInstance);
|
51
54
|
|
@@ -54,20 +57,20 @@ export class RLNContract {
|
|
54
57
|
|
55
58
|
constructor(
|
56
59
|
rlnInstance: RLNInstance,
|
57
|
-
{ registryAddress,
|
60
|
+
{ registryAddress, signer }: RLNContractOptions
|
58
61
|
) {
|
59
62
|
const initialRoot = rlnInstance.getMerkleRoot();
|
60
63
|
|
61
64
|
this.registryContract = new ethers.Contract(
|
62
65
|
registryAddress,
|
63
66
|
RLN_REGISTRY_ABI,
|
64
|
-
|
67
|
+
signer
|
65
68
|
);
|
66
69
|
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
67
70
|
}
|
68
71
|
|
69
72
|
private async initStorageContract(
|
70
|
-
|
73
|
+
signer: Signer,
|
71
74
|
options: RLNStorageOptions = {}
|
72
75
|
): Promise<void> {
|
73
76
|
const storageIndex = options?.storageIndex
|
@@ -83,13 +86,20 @@ export class RLNContract {
|
|
83
86
|
this.storageContract = new ethers.Contract(
|
84
87
|
storageAddress,
|
85
88
|
RLN_STORAGE_ABI,
|
86
|
-
|
89
|
+
signer
|
87
90
|
);
|
88
91
|
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
89
92
|
|
90
93
|
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
91
94
|
}
|
92
95
|
|
96
|
+
public get registry(): ethers.Contract {
|
97
|
+
if (!this.registryContract) {
|
98
|
+
throw Error("Registry contract was not initialized");
|
99
|
+
}
|
100
|
+
return this.registryContract as ethers.Contract;
|
101
|
+
}
|
102
|
+
|
93
103
|
public get contract(): ethers.Contract {
|
94
104
|
if (!this.storageContract) {
|
95
105
|
throw Error("Storage contract was not initialized");
|
@@ -150,10 +160,10 @@ export class RLNContract {
|
|
150
160
|
eventsPerBlock.push(evt);
|
151
161
|
toInsertTable.set(evt.blockNumber, eventsPerBlock);
|
152
162
|
}
|
153
|
-
|
154
|
-
this.removeMembers(rlnInstance, toRemoveTable);
|
155
|
-
this.insertMembers(rlnInstance, toInsertTable);
|
156
163
|
});
|
164
|
+
|
165
|
+
this.removeMembers(rlnInstance, toRemoveTable);
|
166
|
+
this.insertMembers(rlnInstance, toInsertTable);
|
157
167
|
}
|
158
168
|
|
159
169
|
private insertMembers(
|
@@ -169,15 +179,11 @@ export class RLNContract {
|
|
169
179
|
return;
|
170
180
|
}
|
171
181
|
|
172
|
-
const idCommitment =
|
173
|
-
ethers.utils.arrayify(_idCommitment),
|
174
|
-
32
|
175
|
-
);
|
182
|
+
const idCommitment = zeroPadLE(hexToBytes(_idCommitment?._hex), 32);
|
176
183
|
rlnInstance.insertMember(idCommitment);
|
177
184
|
this._members.set(index.toNumber(), {
|
178
185
|
index,
|
179
|
-
idCommitment:
|
180
|
-
_idCommitment?._hex || ethers.utils.hexlify(idCommitment),
|
186
|
+
idCommitment: _idCommitment?._hex,
|
181
187
|
});
|
182
188
|
});
|
183
189
|
|
@@ -209,19 +215,9 @@ export class RLNContract {
|
|
209
215
|
);
|
210
216
|
}
|
211
217
|
|
212
|
-
public async
|
213
|
-
|
214
|
-
|
215
|
-
): Promise<Member | undefined> {
|
216
|
-
const identityCredential =
|
217
|
-
await rlnInstance.generateSeededIdentityCredential(signature);
|
218
|
-
|
219
|
-
return this.registerWithKey(identityCredential);
|
220
|
-
}
|
221
|
-
|
222
|
-
public async registerWithKey(
|
223
|
-
credential: IdentityCredential
|
224
|
-
): Promise<Member | undefined> {
|
218
|
+
public async registerWithIdentity(
|
219
|
+
identity: IdentityCredential
|
220
|
+
): Promise<DecryptedCredentials | undefined> {
|
225
221
|
if (this.storageIndex === undefined) {
|
226
222
|
throw Error(
|
227
223
|
"Cannot register credential, no storage contract index found."
|
@@ -230,7 +226,7 @@ export class RLNContract {
|
|
230
226
|
const txRegisterResponse: ethers.ContractTransaction =
|
231
227
|
await this.registryContract["register(uint16,uint256)"](
|
232
228
|
this.storageIndex,
|
233
|
-
|
229
|
+
identity.IDCommitmentBigInt,
|
234
230
|
{ gasLimit: 100000 }
|
235
231
|
);
|
236
232
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
@@ -247,9 +243,17 @@ export class RLNContract {
|
|
247
243
|
memberRegistered.data
|
248
244
|
);
|
249
245
|
|
246
|
+
const network = await this.registryContract.provider.getNetwork();
|
247
|
+
const address = this.registryContract.address;
|
248
|
+
const membershipId = decodedData.index.toNumber();
|
249
|
+
|
250
250
|
return {
|
251
|
-
|
252
|
-
|
251
|
+
identity,
|
252
|
+
membership: {
|
253
|
+
address,
|
254
|
+
treeIndex: membershipId,
|
255
|
+
chainId: network.chainId,
|
256
|
+
},
|
253
257
|
};
|
254
258
|
}
|
255
259
|
|
Binary file
|