@waku/rln 0.1.5-6198efb.0 → 0.1.5-861a776.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/packages/rln/dist/contract/constants.js +1 -1
- package/bundle/packages/rln/dist/contract/rln_contract.js +6 -6
- package/bundle/packages/rln/dist/contract/rln_light_contract.js +6 -6
- package/bundle/packages/rln/dist/identity.js +9 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +15 -25
- package/bundle/packages/rln/dist/rln.js +2 -2
- package/bundle/packages/rln/dist/rln_light.js +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +1 -1
- package/dist/contract/constants.js +1 -1
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.js +6 -6
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/rln_light_contract.js +6 -6
- package/dist/contract/rln_light_contract.js.map +1 -1
- package/dist/contract/test-utils.js +1 -1
- package/dist/contract/test-utils.js.map +1 -1
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +9 -0
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.d.ts +0 -1
- package/dist/keystore/keystore.js +15 -25
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +1 -1
- package/dist/rln.js +2 -2
- package/dist/rln.js.map +1 -1
- package/dist/rln_light.js +1 -1
- package/dist/rln_light.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +1 -1
- package/src/contract/rln_contract.ts +6 -6
- package/src/contract/rln_light_contract.ts +6 -6
- package/src/contract/test-utils.ts +1 -1
- package/src/identity.ts +10 -0
- package/src/keystore/keystore.ts +27 -43
- package/src/keystore/types.ts +1 -1
- package/src/rln.ts +2 -2
- package/src/rln_light.ts +1 -1
@@ -300,13 +300,13 @@ class RLNContract {
|
|
300
300
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
301
301
|
const network = await this.contract.provider.getNetwork();
|
302
302
|
const address = this.contract.address;
|
303
|
-
const membershipId =
|
303
|
+
const membershipId = decodedData.index.toString();
|
304
304
|
return {
|
305
305
|
identity,
|
306
306
|
membership: {
|
307
307
|
address,
|
308
|
-
treeIndex: membershipId,
|
309
|
-
chainId: network.chainId,
|
308
|
+
treeIndex: parseInt(membershipId),
|
309
|
+
chainId: network.chainId.toString(),
|
310
310
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
311
311
|
}
|
312
312
|
};
|
@@ -380,13 +380,13 @@ class RLNContract {
|
|
380
380
|
`Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
381
381
|
const network = await this.contract.provider.getNetwork();
|
382
382
|
const address = this.contract.address;
|
383
|
-
const membershipId =
|
383
|
+
const membershipId = decodedData.index.toString();
|
384
384
|
return {
|
385
385
|
identity,
|
386
386
|
membership: {
|
387
387
|
address,
|
388
|
-
treeIndex: membershipId,
|
389
|
-
chainId: network.chainId,
|
388
|
+
treeIndex: parseInt(membershipId),
|
389
|
+
chainId: network.chainId.toString(),
|
390
390
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
391
391
|
}
|
392
392
|
};
|
@@ -253,13 +253,13 @@ class RLNLightContract {
|
|
253
253
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
254
254
|
const network = await this.contract.provider.getNetwork();
|
255
255
|
const address = this.contract.address;
|
256
|
-
const membershipId =
|
256
|
+
const membershipId = decodedData.index.toString();
|
257
257
|
return {
|
258
258
|
identity,
|
259
259
|
membership: {
|
260
260
|
address,
|
261
|
-
treeIndex: membershipId,
|
262
|
-
chainId: network.chainId,
|
261
|
+
treeIndex: parseInt(membershipId),
|
262
|
+
chainId: network.chainId.toString(),
|
263
263
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
264
264
|
}
|
265
265
|
};
|
@@ -335,13 +335,13 @@ class RLNLightContract {
|
|
335
335
|
`Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
336
336
|
const network = await this.contract.provider.getNetwork();
|
337
337
|
const address = this.contract.address;
|
338
|
-
const membershipId =
|
338
|
+
const membershipId = decodedData.index.toString();
|
339
339
|
return {
|
340
340
|
identity,
|
341
341
|
membership: {
|
342
342
|
address,
|
343
|
-
treeIndex: membershipId,
|
344
|
-
chainId: network.chainId,
|
343
|
+
treeIndex: parseInt(membershipId),
|
344
|
+
chainId: network.chainId.toString(),
|
345
345
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
346
346
|
}
|
347
347
|
};
|
@@ -25,6 +25,15 @@ class IdentityCredential {
|
|
25
25
|
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
26
26
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
27
27
|
}
|
28
|
+
toJSON() {
|
29
|
+
return [
|
30
|
+
Array.from(this.IDTrapdoor),
|
31
|
+
Array.from(this.IDNullifier),
|
32
|
+
Array.from(this.IDSecretHash),
|
33
|
+
Array.from(this.IDCommitment),
|
34
|
+
this.IDCommitmentBigInt.toString()
|
35
|
+
];
|
36
|
+
}
|
28
37
|
}
|
29
38
|
|
30
39
|
export { IdentityCredential };
|
@@ -17,6 +17,7 @@ import { Logger } from '../../../utils/dist/logger/index.js';
|
|
17
17
|
import { sha256 } from '../../../../node_modules/ethereum-cryptography/esm/sha256.js';
|
18
18
|
import { bytesToUtf8 } from '../../../../node_modules/ethereum-cryptography/esm/utils.js';
|
19
19
|
import _ from '../../../../node_modules/lodash/lodash.js';
|
20
|
+
import { IdentityCredential } from '../identity.js';
|
20
21
|
import { buildBigIntFromUint8Array } from '../utils/bytes.js';
|
21
22
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
22
23
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
@@ -164,15 +165,15 @@ class Keystore {
|
|
164
165
|
try {
|
165
166
|
const str = bytesToUtf8(bytes);
|
166
167
|
const obj = JSON.parse(str);
|
167
|
-
//
|
168
|
+
// Get identity arrays
|
169
|
+
const [idTrapdoor, idNullifier, idSecretHash, idCommitment] = _.get(obj, "identityCredential", []);
|
170
|
+
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
171
|
+
const idNullifierArray = new Uint8Array(idNullifier || []);
|
172
|
+
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
173
|
+
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
174
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
168
175
|
return {
|
169
|
-
identity:
|
170
|
-
IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
|
171
|
-
IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
|
172
|
-
IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
|
173
|
-
IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
|
174
|
-
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
|
175
|
-
},
|
176
|
+
identity: new IdentityCredential(idTrapdoorArray, idNullifierArray, idSecretHashArray, idCommitmentArray, idCommitmentBigInt),
|
176
177
|
membership: {
|
177
178
|
treeIndex: _.get(obj, "treeIndex"),
|
178
179
|
chainId: _.get(obj, "membershipContract.chainId"),
|
@@ -186,17 +187,6 @@ class Keystore {
|
|
186
187
|
return;
|
187
188
|
}
|
188
189
|
}
|
189
|
-
static fromArraylikeToBytes(obj) {
|
190
|
-
const bytes = [];
|
191
|
-
let index = 0;
|
192
|
-
let lastElement = obj[index];
|
193
|
-
while (lastElement !== undefined) {
|
194
|
-
bytes.push(lastElement);
|
195
|
-
index += 1;
|
196
|
-
lastElement = obj[index];
|
197
|
-
}
|
198
|
-
return new Uint8Array(bytes);
|
199
|
-
}
|
200
190
|
// follows nwaku implementation
|
201
191
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
202
192
|
static computeMembershipHash(info) {
|
@@ -207,12 +197,12 @@ class Keystore {
|
|
207
197
|
static fromIdentityToBytes(options) {
|
208
198
|
return utf8ToBytes(JSON.stringify({
|
209
199
|
treeIndex: options.membership.treeIndex,
|
210
|
-
identityCredential:
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
200
|
+
identityCredential: [
|
201
|
+
Array.from(options.identity.IDTrapdoor),
|
202
|
+
Array.from(options.identity.IDNullifier),
|
203
|
+
Array.from(options.identity.IDSecretHash),
|
204
|
+
Array.from(options.identity.IDCommitment)
|
205
|
+
],
|
216
206
|
membershipContract: {
|
217
207
|
chainId: options.membership.chainId,
|
218
208
|
address: options.membership.address
|
@@ -132,7 +132,7 @@ class RLNInstance {
|
|
132
132
|
chainId = LINEA_CONTRACT.chainId;
|
133
133
|
}
|
134
134
|
const signer = options.signer || (await extractMetaMaskSigner());
|
135
|
-
const currentChainId = await signer.getChainId();
|
135
|
+
const currentChainId = (await signer.getChainId()).toString();
|
136
136
|
if (chainId && chainId !== currentChainId) {
|
137
137
|
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
138
138
|
}
|
@@ -204,7 +204,7 @@ class RLNInstance {
|
|
204
204
|
}
|
205
205
|
const chainId = credentials.membership.chainId;
|
206
206
|
const network = await this._contract.provider.getNetwork();
|
207
|
-
const currentChainId = network.chainId;
|
207
|
+
const currentChainId = network.chainId.toString();
|
208
208
|
if (chainId !== currentChainId) {
|
209
209
|
throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
|
210
210
|
}
|
@@ -74,7 +74,7 @@ class RLNLightInstance {
|
|
74
74
|
chainId = LINEA_CONTRACT.chainId;
|
75
75
|
}
|
76
76
|
const signer = options.signer || (await extractMetaMaskSigner());
|
77
|
-
const currentChainId = await signer.getChainId();
|
77
|
+
const currentChainId = (await signer.getChainId()).toString();
|
78
78
|
if (chainId && chainId !== currentChainId) {
|
79
79
|
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
80
80
|
}
|