@waku/rln 0.1.6-f7778a9.0 → 0.1.6-f7c290d.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 (61) hide show
  1. package/bundle/_virtual/utils.js +2 -2
  2. package/bundle/_virtual/utils2.js +2 -2
  3. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
  4. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
  5. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
  6. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
  7. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
  8. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
  9. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
  10. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
  11. package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
  12. package/bundle/packages/rln/dist/contract/rln_base_contract.js +8 -12
  13. package/bundle/packages/rln/dist/contract/rln_contract.js +2 -2
  14. package/bundle/packages/rln/dist/credentials_manager.js +21 -18
  15. package/bundle/packages/rln/dist/identity.js +8 -6
  16. package/bundle/packages/rln/dist/keystore/keystore.js +21 -10
  17. package/bundle/packages/rln/dist/proof.js +2 -2
  18. package/bundle/packages/rln/dist/utils/bytes.js +103 -58
  19. package/bundle/packages/rln/dist/utils/hash.js +3 -3
  20. package/bundle/packages/rln/dist/zerokit.js +17 -17
  21. package/dist/.tsbuildinfo +1 -1
  22. package/dist/contract/rln_base_contract.d.ts +0 -5
  23. package/dist/contract/rln_base_contract.js +8 -12
  24. package/dist/contract/rln_base_contract.js.map +1 -1
  25. package/dist/contract/rln_contract.js +2 -2
  26. package/dist/contract/rln_contract.js.map +1 -1
  27. package/dist/credentials_manager.d.ts +4 -0
  28. package/dist/credentials_manager.js +22 -18
  29. package/dist/credentials_manager.js.map +1 -1
  30. package/dist/identity.d.ts +5 -2
  31. package/dist/identity.js +8 -5
  32. package/dist/identity.js.map +1 -1
  33. package/dist/keystore/keystore.js +21 -10
  34. package/dist/keystore/keystore.js.map +1 -1
  35. package/dist/proof.js +2 -2
  36. package/dist/proof.js.map +1 -1
  37. package/dist/utils/bytes.d.ts +42 -20
  38. package/dist/utils/bytes.js +102 -57
  39. package/dist/utils/bytes.js.map +1 -1
  40. package/dist/utils/hash.js +5 -5
  41. package/dist/utils/hash.js.map +1 -1
  42. package/dist/utils/index.d.ts +1 -1
  43. package/dist/utils/index.js +1 -1
  44. package/dist/utils/index.js.map +1 -1
  45. package/dist/zerokit.js +17 -17
  46. package/dist/zerokit.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/contract/rln_base_contract.ts +8 -20
  49. package/src/contract/rln_contract.ts +5 -2
  50. package/src/credentials_manager.ts +36 -27
  51. package/src/identity.ts +11 -7
  52. package/src/keystore/keystore.ts +38 -22
  53. package/src/proof.ts +2 -2
  54. package/src/utils/bytes.ts +118 -72
  55. package/src/utils/hash.ts +15 -5
  56. package/src/utils/index.ts +1 -6
  57. package/src/zerokit.ts +30 -22
  58. package/dist/contract/test-utils.d.ts +0 -39
  59. package/dist/contract/test-utils.js +0 -118
  60. package/dist/contract/test-utils.js.map +0 -1
  61. package/src/contract/test-utils.ts +0 -179
@@ -1,64 +1,109 @@
1
- /**
2
- * Concatenate Uint8Arrays
3
- * @param input
4
- * @returns concatenation of all Uint8Array received as input
5
- */
6
- export function concatenate(...input) {
7
- let totalLength = 0;
8
- for (const arr of input) {
9
- totalLength += arr.length;
1
+ export class BytesUtils {
2
+ /**
3
+ * Switches endianness of a byte array
4
+ */
5
+ static switchEndianness(bytes) {
6
+ return new Uint8Array(bytes.reverse());
10
7
  }
11
- const result = new Uint8Array(totalLength);
12
- let offset = 0;
13
- for (const arr of input) {
14
- result.set(arr, offset);
15
- offset += arr.length;
8
+ /**
9
+ * Builds a BigInt from a big-endian Uint8Array
10
+ * @param bytes The big-endian bytes to convert
11
+ * @returns The resulting BigInt in big-endian format
12
+ */
13
+ static buildBigIntFromUint8ArrayBE(bytes) {
14
+ let result = 0n;
15
+ for (let i = 0; i < bytes.length; i++) {
16
+ result = (result << 8n) + BigInt(bytes[i]);
17
+ }
18
+ return result;
16
19
  }
17
- return result;
18
- }
19
- // Adapted from https://github.com/feross/buffer
20
- function checkInt(buf, value, offset, ext, max, min) {
21
- if (value > max || value < min)
22
- throw new RangeError('"value" argument is out of bounds');
23
- if (offset + ext > buf.length)
24
- throw new RangeError("Index out of range");
25
- }
26
- export function writeUIntLE(buf, value, offset, byteLength, noAssert) {
27
- value = +value;
28
- offset = offset >>> 0;
29
- byteLength = byteLength >>> 0;
30
- if (!noAssert) {
31
- const maxBytes = Math.pow(2, 8 * byteLength) - 1;
32
- checkInt(buf, value, offset, byteLength, maxBytes, 0);
20
+ /**
21
+ * Switches endianness of a bigint value
22
+ * @param value The bigint value to switch endianness for
23
+ * @returns The bigint value with reversed endianness
24
+ */
25
+ static switchEndiannessBigInt(value) {
26
+ // Convert bigint to byte array
27
+ const bytes = [];
28
+ let tempValue = value;
29
+ while (tempValue > 0n) {
30
+ bytes.push(Number(tempValue & 0xffn));
31
+ tempValue >>= 8n;
32
+ }
33
+ // Reverse bytes and convert back to bigint
34
+ return bytes
35
+ .reverse()
36
+ .reduce((acc, byte) => (acc << 8n) + BigInt(byte), 0n);
33
37
  }
34
- let mul = 1;
35
- let i = 0;
36
- buf[offset] = value & 0xff;
37
- while (++i < byteLength && (mul *= 0x100)) {
38
- buf[offset + i] = (value / mul) & 0xff;
38
+ /**
39
+ * Converts a big-endian bigint to a 32-byte big-endian Uint8Array
40
+ * @param value The big-endian bigint to convert
41
+ * @returns A 32-byte big-endian Uint8Array
42
+ */
43
+ static bigIntToUint8Array32BE(value) {
44
+ const bytes = new Uint8Array(32);
45
+ for (let i = 31; i >= 0; i--) {
46
+ bytes[i] = Number(value & 0xffn);
47
+ value >>= 8n;
48
+ }
49
+ return bytes;
39
50
  }
40
- return buf;
41
- }
42
- /**
43
- * Transforms Uint8Array into BigInt
44
- * @param array: Uint8Array
45
- * @returns BigInt
46
- */
47
- export function buildBigIntFromUint8Array(array, byteOffset = 0) {
48
- const dataView = new DataView(array.buffer);
49
- return dataView.getBigUint64(byteOffset, true);
50
- }
51
- /**
52
- * Fills with zeros to set length
53
- * @param array little endian Uint8Array
54
- * @param length amount to pad
55
- * @returns little endian Uint8Array padded with zeros to set length
56
- */
57
- export function zeroPadLE(array, length) {
58
- const result = new Uint8Array(length);
59
- for (let i = 0; i < length; i++) {
60
- result[i] = array[i] || 0;
51
+ /**
52
+ * Writes an unsigned integer to a buffer in little-endian format
53
+ */
54
+ static writeUIntLE(buf, value, offset, byteLength, noAssert) {
55
+ value = +value;
56
+ offset = offset >>> 0;
57
+ byteLength = byteLength >>> 0;
58
+ if (!noAssert) {
59
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
60
+ BytesUtils.checkInt(buf, value, offset, byteLength, maxBytes, 0);
61
+ }
62
+ let mul = 1;
63
+ let i = 0;
64
+ buf[offset] = value & 0xff;
65
+ while (++i < byteLength && (mul *= 0x100)) {
66
+ buf[offset + i] = (value / mul) & 0xff;
67
+ }
68
+ return buf;
69
+ }
70
+ /**
71
+ * Fills with zeros to set length
72
+ * @param array little endian Uint8Array
73
+ * @param length amount to pad
74
+ * @returns little endian Uint8Array padded with zeros to set length
75
+ */
76
+ static zeroPadLE(array, length) {
77
+ const result = new Uint8Array(length);
78
+ for (let i = 0; i < length; i++) {
79
+ result[i] = array[i] || 0;
80
+ }
81
+ return result;
82
+ }
83
+ // Adapted from https://github.com/feross/buffer
84
+ static checkInt(buf, value, offset, ext, max, min) {
85
+ if (value > max || value < min)
86
+ throw new RangeError('"value" argument is out of bounds');
87
+ if (offset + ext > buf.length)
88
+ throw new RangeError("Index out of range");
89
+ }
90
+ /**
91
+ * Concatenate Uint8Arrays
92
+ * @param input
93
+ * @returns concatenation of all Uint8Array received as input
94
+ */
95
+ static concatenate(...input) {
96
+ let totalLength = 0;
97
+ for (const arr of input) {
98
+ totalLength += arr.length;
99
+ }
100
+ const result = new Uint8Array(totalLength);
101
+ let offset = 0;
102
+ for (const arr of input) {
103
+ result.set(arr, offset);
104
+ offset += arr.length;
105
+ }
106
+ return result;
61
107
  }
62
- return result;
63
108
  }
64
109
  //# sourceMappingURL=bytes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,KAAmB;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC;IAC5B,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACxB,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gDAAgD;AAChD,SAAS,QAAQ,CACf,GAAe,EACf,KAAa,EACb,MAAc,EACd,GAAW,EACX,GAAW,EACX,GAAW;IAEX,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG;QAC5B,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAC;IAC5D,IAAI,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM;Q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-rln-wasm";
2
- import { concatenate, writeUIntLE } from "./bytes.js";
2
+ import { BytesUtils } from "./bytes.js";
3
3
  export function poseidonHash(...input) {
4
- const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
5
- const lenPrefixedData = concatenate(inputLen, ...input);
4
+ const inputLen = BytesUtils.writeUIntLE(new Uint8Array(8), input.length, 0, 8);
5
+ const lenPrefixedData = BytesUtils.concatenate(inputLen, ...input);
6
6
  return zerokitRLN.poseidonHash(lenPrefixedData);
7
7
  }
8
8
  export function sha256(input) {
9
- const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
10
- const lenPrefixedData = concatenate(inputLen, input);
9
+ const inputLen = BytesUtils.writeUIntLE(new Uint8Array(8), input.length, 0, 8);
10
+ const lenPrefixedData = BytesUtils.concatenate(inputLen, input);
11
11
  return zerokitRLN.hash(lenPrefixedData);
12
12
  }
13
13
  //# sourceMappingURL=hash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,UAAU,YAAY,CAAC,GAAG,KAAwB;IACtD,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAiB;IACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC"}
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,UAAU,YAAY,CAAC,GAAG,KAAwB;IACtD,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CACrC,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,KAAK,CAAC,MAAM,EACZ,CAAC,EACD,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAiB;IACtC,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CACrC,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,KAAK,CAAC,MAAM,EACZ,CAAC,EACD,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export { extractMetaMaskSigner } from "./metamask.js";
2
- export { concatenate, writeUIntLE, buildBigIntFromUint8Array, zeroPadLE } from "./bytes.js";
2
+ export { BytesUtils } from "./bytes.js";
3
3
  export { sha256, poseidonHash } from "./hash.js";
4
4
  export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
@@ -1,5 +1,5 @@
1
1
  export { extractMetaMaskSigner } from "./metamask.js";
2
- export { concatenate, writeUIntLE, buildBigIntFromUint8Array, zeroPadLE } from "./bytes.js";
2
+ export { BytesUtils } from "./bytes.js";
3
3
  export { sha256, poseidonHash } from "./hash.js";
4
4
  export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
package/dist/zerokit.js CHANGED
@@ -2,7 +2,7 @@ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
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 { concatenate, dateToEpoch, epochIntToBytes, writeUIntLE } from "./utils/index.js";
5
+ import { BytesUtils, dateToEpoch, epochIntToBytes } from "./utils/index.js";
6
6
  export class Zerokit {
7
7
  zkRLN;
8
8
  witnessCalculator;
@@ -38,8 +38,8 @@ export class Zerokit {
38
38
  insertMembers(index, ...idCommitments) {
39
39
  // serializes a seq of IDCommitments to a byte seq
40
40
  // the order of serialization is |id_commitment_len<8>|id_commitment<var>|
41
- const idCommitmentLen = writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
42
- const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
41
+ const idCommitmentLen = BytesUtils.writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
42
+ const idCommitmentBytes = BytesUtils.concatenate(idCommitmentLen, ...idCommitments);
43
43
  zerokitRLN.setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
44
44
  }
45
45
  deleteMember(index) {
@@ -50,11 +50,11 @@ export class Zerokit {
50
50
  }
51
51
  serializeMessage(uint8Msg, memIndex, epoch, idKey, rateLimit) {
52
52
  // calculate message length
53
- const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
54
- const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
55
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
53
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
54
+ const memIndexBytes = BytesUtils.writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
55
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
56
56
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
57
- return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
57
+ return BytesUtils.concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
58
58
  }
59
59
  async generateRLNProof(msg, index, epoch, idSecretHash, rateLimit) {
60
60
  if (epoch === undefined) {
@@ -90,9 +90,9 @@ export class Zerokit {
90
90
  pBytes = proofToBytes(proof);
91
91
  }
92
92
  // calculate message length
93
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
94
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
95
- return zerokitRLN.verifyRLNProof(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes));
93
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
94
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
95
+ return zerokitRLN.verifyRLNProof(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes));
96
96
  }
97
97
  verifyWithRoots(proof, msg, roots, rateLimit) {
98
98
  let pBytes;
@@ -103,10 +103,10 @@ export class Zerokit {
103
103
  pBytes = proofToBytes(proof);
104
104
  }
105
105
  // calculate message length
106
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
107
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
108
- const rootsBytes = concatenate(...roots);
109
- return zerokitRLN.verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
106
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
107
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
108
+ const rootsBytes = BytesUtils.concatenate(...roots);
109
+ return zerokitRLN.verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
110
110
  }
111
111
  verifyWithNoRoot(proof, msg, rateLimit) {
112
112
  let pBytes;
@@ -117,9 +117,9 @@ export class Zerokit {
117
117
  pBytes = proofToBytes(proof);
118
118
  }
119
119
  // calculate message length
120
- const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
121
- const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
122
- return zerokitRLN.verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
120
+ const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
121
+ const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
122
+ return zerokitRLN.verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
123
123
  }
124
124
  }
125
125
  //# sourceMappingURL=zerokit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zerokit.js","sourceRoot":"","sources":["../src/zerokit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAE1B,MAAM,OAAO,OAAO;IAEC;IACA;IACA;IAHnB,YACmB,KAAa,EACb,iBAAoC,EACpC,aAAqB,kBAAkB;QAFvC,UAAK,GAAL,KAAK,CAAQ;QACb,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,eAAU,GAAV,UAAU,CAA6B;IACvD,CAAC;IAEJ,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEM,2BAA2B;QAChC,MAAM,OAAO,GAAG,UAAU,CAAC,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,iDAA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AC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,MAAM,cAAc,GAAG,UAAU,CAAC,WAAW,CAC3C,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,SAAS,IAAI,IAAI,CAAC,SAAS,EAC3B,CAAC,EACD,CAAC,CACF,CAAC;QAEF,OAAO,UAAU,CAAC,eAAe,CAC/B,IAAI,CAAC,KAAK,EACV,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,EAC3D,IAAI,UAAU,EAAE,CACjB,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@waku/rln","version":"0.1.6-f7778a9.0","description":"RLN (Rate Limiting Nullifier) implementation for Waku","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/rln#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","rln","rate-limiting","privacy","web3"],"scripts":{"build":"run-s build:**","build:copy":"mkdir -p dist/resources && cp -r src/resources/* dist/resources/","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint \"src/!(resources)/**/*.{ts,js}\" *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:browser":"karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^5.0.1","@types/chai-spies":"^1.0.6","@waku/interfaces":"0.0.31-f7778a9.0","@types/deep-equal-in-any-order":"^1.0.4","@types/lodash":"^4.17.15","@types/sinon":"^17.0.3","@waku/build-utils":"^1.0.0","@waku/message-encryption":"0.0.34-f7778a9.0","deep-equal-in-any-order":"^2.0.6","fast-check":"^3.23.2","rollup-plugin-copy":"^3.5.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@chainsafe/bls-keystore":"3.0.0","@waku/core":"0.0.36-f7778a9.0","@waku/utils":"0.0.24-f7778a9.0","@noble/hashes":"^1.2.0","@waku/zerokit-rln-wasm":"^0.0.13","ethereum-cryptography":"^3.1.0","ethers":"^5.7.2","lodash":"^4.17.21","uuid":"^11.0.5","chai":"^5.1.2","chai-as-promised":"^8.0.1","chai-spies":"^1.1.0","chai-subset":"^1.6.0","sinon":"^19.0.2"}}
1
+ {"name":"@waku/rln","version":"0.1.6-f7c290d.0","description":"RLN (Rate Limiting Nullifier) implementation for Waku","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/rln#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","rln","rate-limiting","privacy","web3"],"scripts":{"build":"run-s build:**","build:copy":"mkdir -p dist/resources && cp -r src/resources/* dist/resources/","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint \"src/!(resources)/**/*.{ts,js}\" *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:browser":"karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^5.0.1","@types/chai-spies":"^1.0.6","@waku/interfaces":"0.0.31-f7c290d.0","@types/deep-equal-in-any-order":"^1.0.4","@types/lodash":"^4.17.15","@types/sinon":"^17.0.3","@waku/build-utils":"^1.0.0","@waku/message-encryption":"0.0.34-f7c290d.0","deep-equal-in-any-order":"^2.0.6","fast-check":"^3.23.2","rollup-plugin-copy":"^3.5.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@chainsafe/bls-keystore":"3.0.0","@waku/core":"0.0.36-f7c290d.0","@waku/utils":"0.0.24-f7c290d.0","@noble/hashes":"^1.2.0","@waku/zerokit-rln-wasm":"^0.0.13","ethereum-cryptography":"^3.1.0","ethers":"^5.7.2","lodash":"^4.17.21","uuid":"^11.0.5","chai":"^5.1.2","chai-as-promised":"^8.0.1","chai-spies":"^1.1.0","chai-subset":"^1.6.0","sinon":"^19.0.2"}}
@@ -3,13 +3,10 @@ import { ethers } from "ethers";
3
3
 
4
4
  import { IdentityCredential } from "../identity.js";
5
5
  import { DecryptedCredentials } from "../keystore/types.js";
6
+ import { BytesUtils } from "../utils/bytes.js";
6
7
 
7
8
  import { RLN_ABI } from "./abi.js";
8
- import {
9
- DEFAULT_Q,
10
- DEFAULT_RATE_LIMIT,
11
- RATE_LIMIT_PARAMS
12
- } from "./constants.js";
9
+ import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from "./constants.js";
13
10
  import {
14
11
  CustomQueryOptions,
15
12
  FetchMembersOptions,
@@ -29,12 +26,6 @@ export class RLNBaseContract {
29
26
  private minRateLimit?: number;
30
27
  private maxRateLimit?: number;
31
28
 
32
- /**
33
- * Default Q value for the RLN contract.
34
- * @see https://github.com/waku-org/waku-rlnv2-contract/blob/b7e9a9b1bc69256a2a3076c1f099b50ce84e7eff/src/WakuRlnV2.sol#L25
35
- */
36
- public idCommitmentBigIntLimit = DEFAULT_Q;
37
-
38
29
  protected _members: Map<number, Member> = new Map();
39
30
  private _membersFilter: ethers.EventFilter;
40
31
  private _membershipErasedFilter: ethers.EventFilter;
@@ -87,16 +78,12 @@ export class RLNBaseContract {
87
78
  options: RLNContractInitOptions
88
79
  ): Promise<RLNBaseContract> {
89
80
  const instance = new RLNBaseContract(options);
90
- const [min, max, idCommitmentBigIntLimit] = await Promise.all([
81
+ const [min, max] = await Promise.all([
91
82
  instance.contract.minMembershipRateLimit(),
92
- instance.contract.maxMembershipRateLimit(),
93
- instance.contract.Q()
83
+ instance.contract.maxMembershipRateLimit()
94
84
  ]);
95
85
  instance.minRateLimit = ethers.BigNumber.from(min).toNumber();
96
86
  instance.maxRateLimit = ethers.BigNumber.from(max).toNumber();
97
- instance.idCommitmentBigIntLimit = BigInt(
98
- idCommitmentBigIntLimit.toString()
99
- );
100
87
 
101
88
  instance.validateRateLimit(instance.rateLimit);
102
89
  return instance;
@@ -504,7 +491,6 @@ export class RLNBaseContract {
504
491
  log.error(`Error in withdraw: ${(error as Error).message}`);
505
492
  }
506
493
  }
507
-
508
494
  public async registerWithIdentity(
509
495
  identity: IdentityCredential
510
496
  ): Promise<DecryptedCredentials | undefined> {
@@ -543,7 +529,9 @@ export class RLNBaseContract {
543
529
  identity.IDCommitmentBigInt,
544
530
  this.rateLimit,
545
531
  [],
546
- { gasLimit }
532
+ {
533
+ gasLimit
534
+ }
547
535
  );
548
536
 
549
537
  const txRegisterReceipt = await txRegisterResponse.wait();
@@ -640,7 +628,7 @@ export class RLNBaseContract {
640
628
  permit.v,
641
629
  permit.r,
642
630
  permit.s,
643
- identity.IDCommitmentBigInt,
631
+ BytesUtils.buildBigIntFromUint8ArrayBE(identity.IDCommitment),
644
632
  this.rateLimit,
645
633
  idCommitmentsToErase.map((id) => ethers.BigNumber.from(id))
646
634
  );
@@ -4,7 +4,7 @@ import { ethers } from "ethers";
4
4
 
5
5
  import type { RLNInstance } from "../rln.js";
6
6
  import { MerkleRootTracker } from "../root_tracker.js";
7
- import { zeroPadLE } from "../utils/bytes.js";
7
+ import { BytesUtils } from "../utils/bytes.js";
8
8
 
9
9
  import { RLNBaseContract } from "./rln_base_contract.js";
10
10
  import { RLNContractInitOptions } from "./types.js";
@@ -110,7 +110,10 @@ export class RLNContract extends RLNBaseContract {
110
110
  index = ethers.BigNumber.from(index);
111
111
  }
112
112
 
113
- const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
113
+ const idCommitment = BytesUtils.zeroPadLE(
114
+ hexToBytes(_idCommitment),
115
+ 32
116
+ );
114
117
  rlnInstance.zerokit.insertMember(idCommitment);
115
118
 
116
119
  const numericIndex = index.toNumber();
@@ -1,9 +1,9 @@
1
1
  import { hmac } from "@noble/hashes/hmac";
2
- import { sha256 } from "@noble/hashes/sha256";
2
+ import { sha256 } from "@noble/hashes/sha2";
3
3
  import { Logger } from "@waku/utils";
4
4
  import { ethers } from "ethers";
5
5
 
6
- import { LINEA_CONTRACT } from "./contract/constants.js";
6
+ import { DEFAULT_Q, LINEA_CONTRACT } from "./contract/constants.js";
7
7
  import { RLNBaseContract } from "./contract/rln_base_contract.js";
8
8
  import { IdentityCredential } from "./identity.js";
9
9
  import { Keystore } from "./keystore/index.js";
@@ -13,10 +13,8 @@ import type {
13
13
  } from "./keystore/index.js";
14
14
  import { KeystoreEntity, Password } from "./keystore/types.js";
15
15
  import { RegisterMembershipOptions, StartRLNOptions } from "./types.js";
16
- import {
17
- buildBigIntFromUint8Array,
18
- extractMetaMaskSigner
19
- } from "./utils/index.js";
16
+ import { BytesUtils } from "./utils/bytes.js";
17
+ import { extractMetaMaskSigner } from "./utils/index.js";
20
18
  import { Zerokit } from "./zerokit.js";
21
19
 
22
20
  const log = new Logger("waku:credentials");
@@ -261,35 +259,46 @@ export class RLNCredentialsManager {
261
259
 
262
260
  // Generate deterministic values using HMAC-SHA256
263
261
  // We use different context strings for each component to ensure they're different
264
- const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
265
- const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
262
+ const idTrapdoorBE = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
263
+ const idNullifierBE = hmac(
264
+ sha256,
265
+ seedBytes,
266
+ encoder.encode("IDNullifier")
267
+ );
266
268
 
267
- const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
268
- const idSecretHash = sha256(combinedBytes);
269
+ const combinedBytes = new Uint8Array([...idTrapdoorBE, ...idNullifierBE]);
270
+ const idSecretHashBE = sha256(combinedBytes);
269
271
 
270
- const idCommitment = sha256(idSecretHash);
272
+ const idCommitmentRawBE = sha256(idSecretHashBE);
273
+ const idCommitmentBE = this.reduceIdCommitment(idCommitmentRawBE);
271
274
 
272
- let idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
273
- if (!this.contract) {
274
- throw Error("RLN contract is not initialized");
275
- }
275
+ log.info(
276
+ "Successfully generated identity credential, storing in Big Endian format"
277
+ );
278
+ return new IdentityCredential(
279
+ idTrapdoorBE,
280
+ idNullifierBE,
281
+ idSecretHashBE,
282
+ idCommitmentBE
283
+ );
284
+ }
276
285
 
277
- const idCommitmentBigIntLimit = this.contract.idCommitmentBigIntLimit;
286
+ /**
287
+ * Helper: take 32-byte BE, reduce mod Q, return 32-byte BE
288
+ */
289
+ private reduceIdCommitment(
290
+ bytesBE: Uint8Array,
291
+ limit: bigint = DEFAULT_Q
292
+ ): Uint8Array {
293
+ const nBE = BytesUtils.buildBigIntFromUint8ArrayBE(bytesBE);
278
294
 
279
- if (idCommitmentBigInt >= idCommitmentBigIntLimit) {
295
+ if (nBE >= limit) {
280
296
  log.warn(
281
- `ID commitment is greater than Q, reducing it by Q(idCommitmentBigIntLimit): ${idCommitmentBigInt} % ${idCommitmentBigIntLimit}`
297
+ `ID commitment is greater than Q, reducing it by Q: ${nBE} % ${limit}`
282
298
  );
283
- idCommitmentBigInt = idCommitmentBigInt % idCommitmentBigIntLimit;
299
+ return BytesUtils.bigIntToUint8Array32BE(nBE % limit);
284
300
  }
285
301
 
286
- log.info("Successfully generated identity credential");
287
- return new IdentityCredential(
288
- idTrapdoor,
289
- idNullifier,
290
- idSecretHash,
291
- idCommitment,
292
- idCommitmentBigInt
293
- );
302
+ return bytesBE;
294
303
  }
295
304
  }
package/src/identity.ts CHANGED
@@ -1,13 +1,19 @@
1
- import { buildBigIntFromUint8Array } from "./utils/index.js";
1
+ import { BytesUtils } from "./utils/bytes.js";
2
2
 
3
3
  export class IdentityCredential {
4
+ public IDCommitmentBigInt: bigint;
5
+ /**
6
+ * All variables are in little-endian format
7
+ */
4
8
  public constructor(
5
9
  public readonly IDTrapdoor: Uint8Array,
6
10
  public readonly IDNullifier: Uint8Array,
7
11
  public readonly IDSecretHash: Uint8Array,
8
- public readonly IDCommitment: Uint8Array,
9
- public readonly IDCommitmentBigInt: bigint
10
- ) {}
12
+ public readonly IDCommitment: Uint8Array
13
+ ) {
14
+ this.IDCommitmentBigInt =
15
+ BytesUtils.buildBigIntFromUint8ArrayBE(IDCommitment);
16
+ }
11
17
 
12
18
  public static fromBytes(memKeys: Uint8Array): IdentityCredential {
13
19
  if (memKeys.length < 128) {
@@ -18,14 +24,12 @@ export class IdentityCredential {
18
24
  const idNullifier = memKeys.subarray(32, 64);
19
25
  const idSecretHash = memKeys.subarray(64, 96);
20
26
  const idCommitment = memKeys.subarray(96, 128);
21
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
22
27
 
23
28
  return new IdentityCredential(
24
29
  idTrapdoor,
25
30
  idNullifier,
26
31
  idSecretHash,
27
- idCommitment,
28
- idCommitmentBigInt
32
+ idCommitment
29
33
  );
30
34
  }
31
35
  }