@waku/rln 0.1.6-ace7ca2.0 → 0.1.6-b0a2e39.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/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +1 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +2 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +12 -9
- package/bundle/packages/core/dist/lib/light_push/light_push_v3.js +30 -0
- package/bundle/packages/core/dist/lib/light_push/utils.js +18 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +2 -0
- package/bundle/packages/core/dist/lib/store/store.js +2 -0
- package/bundle/packages/interfaces/dist/light_push_v3.js +29 -0
- package/bundle/packages/interfaces/dist/protocols.js +10 -0
- package/bundle/packages/proto/dist/generated/light_push.js +3 -3
- package/bundle/packages/proto/dist/generated/light_push_v3.js +348 -0
- package/bundle/packages/rln/dist/codec.js +1 -0
- package/bundle/packages/rln/dist/contract/constants.js +1 -7
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +8 -34
- package/bundle/packages/rln/dist/contract/rln_contract.js +1 -0
- package/bundle/packages/rln/dist/credentials_manager.js +15 -16
- package/bundle/packages/rln/dist/identity.js +8 -5
- package/bundle/packages/rln/dist/keystore/keystore.js +12 -15
- package/bundle/packages/rln/dist/message.js +2 -0
- package/bundle/packages/rln/dist/rln.js +2 -0
- package/bundle/packages/rln/dist/utils/bytes.js +16 -14
- package/bundle/packages/rln/dist/utils/epoch.js +1 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +1 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +0 -6
- package/dist/contract/constants.js +0 -6
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +0 -6
- package/dist/contract/rln_base_contract.js +7 -34
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/test-utils.d.ts +39 -0
- package/dist/contract/test-utils.js +118 -0
- package/dist/contract/test-utils.js.map +1 -0
- package/dist/credentials_manager.js +14 -16
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +2 -4
- package/dist/identity.js +6 -5
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.js +11 -15
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/utils/bytes.d.ts +6 -2
- package/dist/utils/bytes.js +15 -13
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +0 -9
- package/src/contract/rln_base_contract.ts +14 -49
- package/src/contract/test-utils.ts +179 -0
- package/src/credentials_manager.ts +21 -27
- package/src/identity.ts +7 -5
- package/src/keystore/keystore.ts +24 -28
- package/src/utils/bytes.ts +25 -21
- package/src/utils/index.ts +1 -1
package/src/keystore/keystore.ts
CHANGED
@@ -14,6 +14,8 @@ import {
|
|
14
14
|
import _ from "lodash";
|
15
15
|
import { v4 as uuidV4 } from "uuid";
|
16
16
|
|
17
|
+
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
18
|
+
|
17
19
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
18
20
|
import { isCredentialValid, isKeystoreValid } from "./schema_validator.js";
|
19
21
|
import type {
|
@@ -248,25 +250,26 @@ export class Keystore {
|
|
248
250
|
const str = bytesToUtf8(bytes);
|
249
251
|
const obj = JSON.parse(str);
|
250
252
|
|
251
|
-
|
252
|
-
_.get(obj, "identityCredential.idCommitment", [])
|
253
|
-
);
|
254
|
-
const idTrapdoorLE = Keystore.fromArraylikeToBytes(
|
255
|
-
_.get(obj, "identityCredential.idTrapdoor", [])
|
256
|
-
);
|
257
|
-
const idNullifierLE = Keystore.fromArraylikeToBytes(
|
258
|
-
_.get(obj, "identityCredential.idNullifier", [])
|
259
|
-
);
|
260
|
-
const idSecretHashLE = Keystore.fromArraylikeToBytes(
|
261
|
-
_.get(obj, "identityCredential.idSecretHash", [])
|
262
|
-
);
|
263
|
-
|
253
|
+
// TODO: add runtime validation of nwaku credentials
|
264
254
|
return {
|
265
255
|
identity: {
|
266
|
-
IDCommitment:
|
267
|
-
|
268
|
-
|
269
|
-
|
256
|
+
IDCommitment: Keystore.fromArraylikeToBytes(
|
257
|
+
_.get(obj, "identityCredential.idCommitment", [])
|
258
|
+
),
|
259
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(
|
260
|
+
_.get(obj, "identityCredential.idTrapdoor", [])
|
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
|
+
)
|
270
273
|
},
|
271
274
|
membership: {
|
272
275
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -318,21 +321,14 @@ export class Keystore {
|
|
318
321
|
// follows nwaku implementation
|
319
322
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
320
323
|
private static fromIdentityToBytes(options: KeystoreEntity): Uint8Array {
|
321
|
-
function toLittleEndian(bytes: Uint8Array): Uint8Array {
|
322
|
-
return new Uint8Array(bytes).reverse();
|
323
|
-
}
|
324
324
|
return utf8ToBytes(
|
325
325
|
JSON.stringify({
|
326
326
|
treeIndex: options.membership.treeIndex,
|
327
327
|
identityCredential: {
|
328
|
-
idCommitment: Array.from(
|
329
|
-
|
330
|
-
),
|
331
|
-
|
332
|
-
idSecretHash: Array.from(
|
333
|
-
toLittleEndian(options.identity.IDSecretHash)
|
334
|
-
),
|
335
|
-
idTrapdoor: Array.from(toLittleEndian(options.identity.IDTrapdoor))
|
328
|
+
idCommitment: Array.from(options.identity.IDCommitment),
|
329
|
+
idNullifier: Array.from(options.identity.IDNullifier),
|
330
|
+
idSecretHash: Array.from(options.identity.IDSecretHash),
|
331
|
+
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
336
332
|
},
|
337
333
|
membershipContract: {
|
338
334
|
chainId: options.membership.chainId,
|
package/src/utils/bytes.ts
CHANGED
@@ -17,13 +17,18 @@ export function concatenate(...input: Uint8Array[]): Uint8Array {
|
|
17
17
|
return result;
|
18
18
|
}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
// Adapted from https://github.com/feross/buffer
|
21
|
+
function checkInt(
|
22
|
+
buf: Uint8Array,
|
23
|
+
value: number,
|
24
|
+
offset: number,
|
25
|
+
ext: number,
|
26
|
+
max: number,
|
27
|
+
min: number
|
28
|
+
): void {
|
29
|
+
if (value > max || value < min)
|
30
|
+
throw new RangeError('"value" argument is out of bounds');
|
31
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
27
32
|
}
|
28
33
|
|
29
34
|
export function writeUIntLE(
|
@@ -51,6 +56,19 @@ export function writeUIntLE(
|
|
51
56
|
return buf;
|
52
57
|
}
|
53
58
|
|
59
|
+
/**
|
60
|
+
* Transforms Uint8Array into BigInt
|
61
|
+
* @param array: Uint8Array
|
62
|
+
* @returns BigInt
|
63
|
+
*/
|
64
|
+
export function buildBigIntFromUint8Array(
|
65
|
+
array: Uint8Array,
|
66
|
+
byteOffset: number = 0
|
67
|
+
): bigint {
|
68
|
+
const dataView = new DataView(array.buffer);
|
69
|
+
return dataView.getBigUint64(byteOffset, true);
|
70
|
+
}
|
71
|
+
|
54
72
|
/**
|
55
73
|
* Fills with zeros to set length
|
56
74
|
* @param array little endian Uint8Array
|
@@ -64,17 +82,3 @@ export function zeroPadLE(array: Uint8Array, length: number): Uint8Array {
|
|
64
82
|
}
|
65
83
|
return result;
|
66
84
|
}
|
67
|
-
|
68
|
-
// Adapted from https://github.com/feross/buffer
|
69
|
-
function checkInt(
|
70
|
-
buf: Uint8Array,
|
71
|
-
value: number,
|
72
|
-
offset: number,
|
73
|
-
ext: number,
|
74
|
-
max: number,
|
75
|
-
min: number
|
76
|
-
): void {
|
77
|
-
if (value > max || value < min)
|
78
|
-
throw new RangeError('"value" argument is out of bounds');
|
79
|
-
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
80
|
-
}
|