@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.
Files changed (69) hide show
  1. package/bundle/_virtual/utils.js +2 -2
  2. package/bundle/_virtual/utils2.js +2 -2
  3. package/bundle/index.js +1 -1
  4. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
  5. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
  6. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
  7. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
  8. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
  9. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
  10. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
  11. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
  12. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
  13. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -0
  14. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +1 -0
  15. package/bundle/packages/core/dist/lib/filter/filter.js +2 -0
  16. package/bundle/packages/core/dist/lib/light_push/light_push.js +12 -9
  17. package/bundle/packages/core/dist/lib/light_push/light_push_v3.js +30 -0
  18. package/bundle/packages/core/dist/lib/light_push/utils.js +18 -0
  19. package/bundle/packages/core/dist/lib/message/version_0.js +1 -0
  20. package/bundle/packages/core/dist/lib/metadata/metadata.js +2 -0
  21. package/bundle/packages/core/dist/lib/store/store.js +2 -0
  22. package/bundle/packages/interfaces/dist/light_push_v3.js +29 -0
  23. package/bundle/packages/interfaces/dist/protocols.js +10 -0
  24. package/bundle/packages/proto/dist/generated/light_push.js +3 -3
  25. package/bundle/packages/proto/dist/generated/light_push_v3.js +348 -0
  26. package/bundle/packages/rln/dist/codec.js +1 -0
  27. package/bundle/packages/rln/dist/contract/constants.js +1 -7
  28. package/bundle/packages/rln/dist/contract/rln_base_contract.js +8 -34
  29. package/bundle/packages/rln/dist/contract/rln_contract.js +1 -0
  30. package/bundle/packages/rln/dist/credentials_manager.js +15 -16
  31. package/bundle/packages/rln/dist/identity.js +8 -5
  32. package/bundle/packages/rln/dist/keystore/keystore.js +12 -15
  33. package/bundle/packages/rln/dist/message.js +2 -0
  34. package/bundle/packages/rln/dist/rln.js +2 -0
  35. package/bundle/packages/rln/dist/utils/bytes.js +16 -14
  36. package/bundle/packages/rln/dist/utils/epoch.js +1 -0
  37. package/bundle/packages/utils/dist/common/sharding/index.js +1 -0
  38. package/dist/.tsbuildinfo +1 -1
  39. package/dist/contract/constants.d.ts +0 -6
  40. package/dist/contract/constants.js +0 -6
  41. package/dist/contract/constants.js.map +1 -1
  42. package/dist/contract/rln_base_contract.d.ts +0 -6
  43. package/dist/contract/rln_base_contract.js +7 -34
  44. package/dist/contract/rln_base_contract.js.map +1 -1
  45. package/dist/contract/test-utils.d.ts +39 -0
  46. package/dist/contract/test-utils.js +118 -0
  47. package/dist/contract/test-utils.js.map +1 -0
  48. package/dist/credentials_manager.js +14 -16
  49. package/dist/credentials_manager.js.map +1 -1
  50. package/dist/identity.d.ts +2 -4
  51. package/dist/identity.js +6 -5
  52. package/dist/identity.js.map +1 -1
  53. package/dist/keystore/keystore.js +11 -15
  54. package/dist/keystore/keystore.js.map +1 -1
  55. package/dist/utils/bytes.d.ts +6 -2
  56. package/dist/utils/bytes.js +15 -13
  57. package/dist/utils/bytes.js.map +1 -1
  58. package/dist/utils/index.d.ts +1 -1
  59. package/dist/utils/index.js +1 -1
  60. package/dist/utils/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/contract/constants.ts +0 -9
  63. package/src/contract/rln_base_contract.ts +14 -49
  64. package/src/contract/test-utils.ts +179 -0
  65. package/src/credentials_manager.ts +21 -27
  66. package/src/identity.ts +7 -5
  67. package/src/keystore/keystore.ts +24 -28
  68. package/src/utils/bytes.ts +25 -21
  69. package/src/utils/index.ts +1 -1
@@ -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
- const idCommitmentLE = Keystore.fromArraylikeToBytes(
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: idCommitmentLE,
267
- IDTrapdoor: idTrapdoorLE,
268
- IDNullifier: idNullifierLE,
269
- IDSecretHash: idSecretHashLE
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
- toLittleEndian(options.identity.IDCommitment)
330
- ),
331
- idNullifier: Array.from(toLittleEndian(options.identity.IDNullifier)),
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,
@@ -17,13 +17,18 @@ export function concatenate(...input: Uint8Array[]): Uint8Array {
17
17
  return result;
18
18
  }
19
19
 
20
- export function switchEndianness(bytes: Uint8Array): Uint8Array {
21
- return new Uint8Array(bytes.reverse());
22
- }
23
-
24
- export function buildBigIntFromUint8ArrayBE(bytes: Uint8Array): bigint {
25
- // Interpret bytes as big-endian
26
- return bytes.reduce((acc, byte) => (acc << 8n) + BigInt(byte), 0n);
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
- }
@@ -2,7 +2,7 @@ export { extractMetaMaskSigner } from "./metamask.js";
2
2
  export {
3
3
  concatenate,
4
4
  writeUIntLE,
5
- switchEndianness,
5
+ buildBigIntFromUint8Array,
6
6
  zeroPadLE
7
7
  } from "./bytes.js";
8
8
  export { sha256, poseidonHash } from "./hash.js";