@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
package/src/keystore/keystore.ts
CHANGED
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
import _ from "lodash";
|
15
15
|
import { v4 as uuidV4 } from "uuid";
|
16
16
|
|
17
|
+
import { IdentityCredential } from "../identity.js";
|
17
18
|
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
18
19
|
|
19
20
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
@@ -250,27 +251,27 @@ export class Keystore {
|
|
250
251
|
const str = bytesToUtf8(bytes);
|
251
252
|
const obj = JSON.parse(str);
|
252
253
|
|
253
|
-
//
|
254
|
+
// Get identity arrays
|
255
|
+
const [idTrapdoor, idNullifier, idSecretHash, idCommitment] = _.get(
|
256
|
+
obj,
|
257
|
+
"identityCredential",
|
258
|
+
[]
|
259
|
+
);
|
260
|
+
|
261
|
+
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
262
|
+
const idNullifierArray = new Uint8Array(idNullifier || []);
|
263
|
+
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
264
|
+
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
265
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
266
|
+
|
254
267
|
return {
|
255
|
-
identity:
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
IDNullifier: Keystore.fromArraylikeToBytes(
|
263
|
-
_.get(obj, "identityCredential.idNullifier", [])
|
264
|
-
),
|
265
|
-
IDCommitmentBigInt: buildBigIntFromUint8Array(
|
266
|
-
Keystore.fromArraylikeToBytes(
|
267
|
-
_.get(obj, "identityCredential.idCommitment", [])
|
268
|
-
)
|
269
|
-
),
|
270
|
-
IDSecretHash: Keystore.fromArraylikeToBytes(
|
271
|
-
_.get(obj, "identityCredential.idSecretHash", [])
|
272
|
-
)
|
273
|
-
},
|
268
|
+
identity: new IdentityCredential(
|
269
|
+
idTrapdoorArray,
|
270
|
+
idNullifierArray,
|
271
|
+
idSecretHashArray,
|
272
|
+
idCommitmentArray,
|
273
|
+
idCommitmentBigInt
|
274
|
+
),
|
274
275
|
membership: {
|
275
276
|
treeIndex: _.get(obj, "treeIndex"),
|
276
277
|
chainId: _.get(obj, "membershipContract.chainId"),
|
@@ -284,23 +285,6 @@ export class Keystore {
|
|
284
285
|
}
|
285
286
|
}
|
286
287
|
|
287
|
-
private static fromArraylikeToBytes(obj: {
|
288
|
-
[key: number]: number;
|
289
|
-
}): Uint8Array {
|
290
|
-
const bytes = [];
|
291
|
-
|
292
|
-
let index = 0;
|
293
|
-
let lastElement = obj[index];
|
294
|
-
|
295
|
-
while (lastElement !== undefined) {
|
296
|
-
bytes.push(lastElement);
|
297
|
-
index += 1;
|
298
|
-
lastElement = obj[index];
|
299
|
-
}
|
300
|
-
|
301
|
-
return new Uint8Array(bytes);
|
302
|
-
}
|
303
|
-
|
304
288
|
// follows nwaku implementation
|
305
289
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
306
290
|
private static computeMembershipHash(info: MembershipInfo): MembershipHash {
|
@@ -315,12 +299,12 @@ export class Keystore {
|
|
315
299
|
return utf8ToBytes(
|
316
300
|
JSON.stringify({
|
317
301
|
treeIndex: options.membership.treeIndex,
|
318
|
-
identityCredential:
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
302
|
+
identityCredential: [
|
303
|
+
Array.from(options.identity.IDTrapdoor),
|
304
|
+
Array.from(options.identity.IDNullifier),
|
305
|
+
Array.from(options.identity.IDSecretHash),
|
306
|
+
Array.from(options.identity.IDCommitment)
|
307
|
+
],
|
324
308
|
membershipContract: {
|
325
309
|
chainId: options.membership.chainId,
|
326
310
|
address: options.membership.address
|
package/src/keystore/types.ts
CHANGED
@@ -8,7 +8,7 @@ export type Password = string | Uint8Array;
|
|
8
8
|
// see reference
|
9
9
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
10
10
|
export type MembershipInfo = {
|
11
|
-
chainId:
|
11
|
+
chainId: string;
|
12
12
|
address: string;
|
13
13
|
treeIndex: number;
|
14
14
|
rateLimit: number;
|
package/src/rln.ts
CHANGED
@@ -197,7 +197,7 @@ export class RLNInstance {
|
|
197
197
|
}
|
198
198
|
|
199
199
|
const signer = options.signer || (await extractMetaMaskSigner());
|
200
|
-
const currentChainId = await signer.getChainId();
|
200
|
+
const currentChainId = (await signer.getChainId()).toString();
|
201
201
|
|
202
202
|
if (chainId && chainId !== currentChainId) {
|
203
203
|
throw Error(
|
@@ -312,7 +312,7 @@ export class RLNInstance {
|
|
312
312
|
|
313
313
|
const chainId = credentials.membership.chainId;
|
314
314
|
const network = await this._contract.provider.getNetwork();
|
315
|
-
const currentChainId = network.chainId;
|
315
|
+
const currentChainId = network.chainId.toString();
|
316
316
|
if (chainId !== currentChainId) {
|
317
317
|
throw Error(
|
318
318
|
`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
|
package/src/rln_light.ts
CHANGED
@@ -127,7 +127,7 @@ export class RLNLightInstance {
|
|
127
127
|
}
|
128
128
|
|
129
129
|
const signer = options.signer || (await extractMetaMaskSigner());
|
130
|
-
const currentChainId = await signer.getChainId();
|
130
|
+
const currentChainId = (await signer.getChainId()).toString();
|
131
131
|
|
132
132
|
if (chainId && chainId !== currentChainId) {
|
133
133
|
throw Error(
|