@waku/rln 0.1.6-d3a80d8.0 → 0.1.6-ef2a162.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 (66) 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/rln/dist/contract/constants.js +7 -1
  14. package/bundle/packages/rln/dist/contract/rln_base_contract.js +5 -2
  15. package/bundle/packages/rln/dist/contract/rln_contract.js +2 -2
  16. package/bundle/packages/rln/dist/credentials_manager.js +24 -16
  17. package/bundle/packages/rln/dist/identity.js +8 -6
  18. package/bundle/packages/rln/dist/keystore/keystore.js +38 -11
  19. package/bundle/packages/rln/dist/proof.js +2 -2
  20. package/bundle/packages/rln/dist/utils/bytes.js +103 -58
  21. package/bundle/packages/rln/dist/utils/hash.js +3 -3
  22. package/bundle/packages/rln/dist/zerokit.js +17 -17
  23. package/dist/.tsbuildinfo +1 -1
  24. package/dist/contract/constants.d.ts +6 -0
  25. package/dist/contract/constants.js +6 -0
  26. package/dist/contract/constants.js.map +1 -1
  27. package/dist/contract/rln_base_contract.js +5 -2
  28. package/dist/contract/rln_base_contract.js.map +1 -1
  29. package/dist/contract/rln_contract.js +2 -2
  30. package/dist/contract/rln_contract.js.map +1 -1
  31. package/dist/credentials_manager.d.ts +4 -0
  32. package/dist/credentials_manager.js +25 -16
  33. package/dist/credentials_manager.js.map +1 -1
  34. package/dist/identity.d.ts +5 -2
  35. package/dist/identity.js +8 -5
  36. package/dist/identity.js.map +1 -1
  37. package/dist/keystore/keystore.js +38 -11
  38. package/dist/keystore/keystore.js.map +1 -1
  39. package/dist/proof.js +2 -2
  40. package/dist/proof.js.map +1 -1
  41. package/dist/utils/bytes.d.ts +42 -20
  42. package/dist/utils/bytes.js +102 -57
  43. package/dist/utils/bytes.js.map +1 -1
  44. package/dist/utils/hash.js +5 -5
  45. package/dist/utils/hash.js.map +1 -1
  46. package/dist/utils/index.d.ts +1 -1
  47. package/dist/utils/index.js +1 -1
  48. package/dist/utils/index.js.map +1 -1
  49. package/dist/zerokit.js +17 -17
  50. package/dist/zerokit.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/contract/constants.ts +9 -0
  53. package/src/contract/rln_base_contract.ts +5 -3
  54. package/src/contract/rln_contract.ts +5 -2
  55. package/src/credentials_manager.ts +46 -24
  56. package/src/identity.ts +11 -7
  57. package/src/keystore/keystore.ts +52 -23
  58. package/src/proof.ts +2 -2
  59. package/src/utils/bytes.ts +118 -72
  60. package/src/utils/hash.ts +15 -5
  61. package/src/utils/index.ts +1 -6
  62. package/src/zerokit.ts +30 -22
  63. package/dist/contract/test-utils.d.ts +0 -39
  64. package/dist/contract/test-utils.js +0 -118
  65. package/dist/contract/test-utils.js.map +0 -1
  66. package/src/contract/test-utils.ts +0 -179
@@ -2,7 +2,7 @@ import { generateExtendedMembershipKey, generateSeededExtendedMembershipKey, ins
2
2
  import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './contract/constants.js';
3
3
  import { IdentityCredential } from './identity.js';
4
4
  import { Proof, proofToBytes } from './proof.js';
5
- import { writeUIntLE, concatenate } from './utils/bytes.js';
5
+ import { BytesUtils } from './utils/bytes.js';
6
6
  import { epochIntToBytes, dateToEpoch } from './utils/epoch.js';
7
7
 
8
8
  class Zerokit {
@@ -40,8 +40,8 @@ class Zerokit {
40
40
  insertMembers(index, ...idCommitments) {
41
41
  // serializes a seq of IDCommitments to a byte seq
42
42
  // the order of serialization is |id_commitment_len<8>|id_commitment<var>|
43
- const idCommitmentLen = writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
44
- const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
43
+ const idCommitmentLen = BytesUtils.writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
44
+ const idCommitmentBytes = BytesUtils.concatenate(idCommitmentLen, ...idCommitments);
45
45
  setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
46
46
  }
47
47
  deleteMember(index) {
@@ -52,11 +52,11 @@ class Zerokit {
52
52
  }
53
53
  serializeMessage(uint8Msg, memIndex, epoch, idKey, rateLimit) {
54
54
  // calculate message length
55
- const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
56
- const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
57
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
55
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
56
+ const memIndexBytes = BytesUtils.writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
57
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
58
58
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
59
- return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
59
+ return BytesUtils.concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
60
60
  }
61
61
  async generateRLNProof(msg, index, epoch, idSecretHash, rateLimit) {
62
62
  if (epoch === undefined) {
@@ -92,9 +92,9 @@ class Zerokit {
92
92
  pBytes = proofToBytes(proof);
93
93
  }
94
94
  // calculate message length
95
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
96
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
97
- return verifyRLNProof(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes));
95
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
96
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
97
+ return verifyRLNProof(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes));
98
98
  }
99
99
  verifyWithRoots(proof, msg, roots, rateLimit) {
100
100
  let pBytes;
@@ -105,10 +105,10 @@ class Zerokit {
105
105
  pBytes = proofToBytes(proof);
106
106
  }
107
107
  // calculate message length
108
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
109
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
110
- const rootsBytes = concatenate(...roots);
111
- return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
108
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
109
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
110
+ const rootsBytes = BytesUtils.concatenate(...roots);
111
+ return verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
112
112
  }
113
113
  verifyWithNoRoot(proof, msg, rateLimit) {
114
114
  let pBytes;
@@ -119,9 +119,9 @@ class Zerokit {
119
119
  pBytes = proofToBytes(proof);
120
120
  }
121
121
  // calculate message length
122
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
123
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
124
- return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
122
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
123
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
124
+ return verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
125
125
  }
126
126
  }
127
127