@waku/rln 0.1.5-5e19700.0 → 0.1.5-ea6daae.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 (125) hide show
  1. package/README.md +0 -5
  2. package/bundle/_virtual/index2.js +1 -1
  3. package/bundle/_virtual/utils.js +2 -2
  4. package/bundle/_virtual/utils2.js +2 -2
  5. package/bundle/index.js +1 -3
  6. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
  7. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
  8. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
  9. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
  10. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
  11. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
  12. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
  13. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  14. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
  15. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
  16. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_assert.js +1 -1
  17. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_sha2.js +3 -3
  18. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_u64.js +1 -1
  19. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  20. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/hmac.js +3 -3
  21. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/pbkdf2.js +4 -4
  22. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/scrypt.js +5 -5
  23. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha256.js +3 -3
  24. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha512.js +4 -4
  25. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/utils.js +2 -2
  26. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
  27. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
  28. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
  29. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
  30. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
  31. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
  32. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
  33. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
  34. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
  35. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
  36. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
  37. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
  38. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
  39. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
  40. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
  41. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
  42. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +19 -1
  43. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
  44. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
  45. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
  46. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +58 -10
  47. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
  48. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
  49. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
  50. package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
  51. package/bundle/packages/rln/dist/contract/abi.js +248 -502
  52. package/bundle/packages/rln/dist/contract/constants.js +4 -4
  53. package/bundle/packages/rln/dist/contract/rln_contract.js +36 -120
  54. package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
  55. package/bundle/packages/rln/dist/keystore/keystore.js +2 -3
  56. package/bundle/packages/rln/dist/rln.js +6 -6
  57. package/dist/.tsbuildinfo +1 -1
  58. package/dist/contract/abi.d.ts +17 -21
  59. package/dist/contract/abi.js +248 -502
  60. package/dist/contract/abi.js.map +1 -1
  61. package/dist/contract/constants.d.ts +18 -22
  62. package/dist/contract/constants.js +3 -3
  63. package/dist/contract/constants.js.map +1 -1
  64. package/dist/contract/rln_contract.d.ts +3 -10
  65. package/dist/contract/rln_contract.js +36 -120
  66. package/dist/contract/rln_contract.js.map +1 -1
  67. package/dist/index.d.ts +2 -5
  68. package/dist/index.js +2 -4
  69. package/dist/index.js.map +1 -1
  70. package/dist/keystore/keystore.js +1 -2
  71. package/dist/keystore/keystore.js.map +1 -1
  72. package/dist/keystore/types.d.ts +0 -1
  73. package/dist/rln.d.ts +1 -1
  74. package/dist/rln.js +6 -6
  75. package/dist/rln.js.map +1 -1
  76. package/package.json +1 -1
  77. package/src/contract/abi.ts +248 -502
  78. package/src/contract/constants.ts +3 -3
  79. package/src/contract/rln_contract.ts +46 -158
  80. package/src/index.ts +2 -17
  81. package/src/keystore/keystore.ts +1 -2
  82. package/src/keystore/types.ts +0 -1
  83. package/src/rln.ts +7 -7
  84. package/bundle/packages/rln/dist/contract/rln_light_contract.js +0 -473
  85. package/bundle/packages/rln/dist/rln_light.js +0 -149
  86. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
  87. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
  88. package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
  89. package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
  90. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
  91. package/dist/codec.test-utils.d.ts +0 -36
  92. package/dist/codec.test-utils.js +0 -56
  93. package/dist/codec.test-utils.js.map +0 -1
  94. package/dist/contract/rln_light_contract.d.ts +0 -124
  95. package/dist/contract/rln_light_contract.js +0 -456
  96. package/dist/contract/rln_light_contract.js.map +0 -1
  97. package/dist/contract/test-setup.d.ts +0 -26
  98. package/dist/contract/test-setup.js +0 -56
  99. package/dist/contract/test-setup.js.map +0 -1
  100. package/dist/contract/test-utils.d.ts +0 -39
  101. package/dist/contract/test-utils.js +0 -118
  102. package/dist/contract/test-utils.js.map +0 -1
  103. package/dist/rln_light.d.ts +0 -64
  104. package/dist/rln_light.js +0 -144
  105. package/dist/rln_light.js.map +0 -1
  106. package/src/codec.test-utils.ts +0 -80
  107. package/src/contract/rln_light_contract.ts +0 -718
  108. package/src/contract/test-setup.ts +0 -86
  109. package/src/contract/test-utils.ts +0 -179
  110. package/src/rln_light.ts +0 -235
  111. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
  112. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
  113. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
  114. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
  115. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
  116. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
  117. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
  118. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
  119. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
  120. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
  121. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
  122. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
  123. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
  124. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
  125. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,116 +0,0 @@
1
- import assert from './_assert.js';
2
- import { Hash, createView, toBytes } from './utils.js';
3
-
4
- // Polyfill for Safari 14
5
- function setBigUint64(view, byteOffset, value, isLE) {
6
- if (typeof view.setBigUint64 === 'function')
7
- return view.setBigUint64(byteOffset, value, isLE);
8
- const _32n = BigInt(32);
9
- const _u32_max = BigInt(0xffffffff);
10
- const wh = Number((value >> _32n) & _u32_max);
11
- const wl = Number(value & _u32_max);
12
- const h = isLE ? 4 : 0;
13
- const l = isLE ? 0 : 4;
14
- view.setUint32(byteOffset + h, wh, isLE);
15
- view.setUint32(byteOffset + l, wl, isLE);
16
- }
17
- // Base SHA2 class (RFC 6234)
18
- class SHA2 extends Hash {
19
- constructor(blockLen, outputLen, padOffset, isLE) {
20
- super();
21
- this.blockLen = blockLen;
22
- this.outputLen = outputLen;
23
- this.padOffset = padOffset;
24
- this.isLE = isLE;
25
- this.finished = false;
26
- this.length = 0;
27
- this.pos = 0;
28
- this.destroyed = false;
29
- this.buffer = new Uint8Array(blockLen);
30
- this.view = createView(this.buffer);
31
- }
32
- update(data) {
33
- assert.exists(this);
34
- const { view, buffer, blockLen } = this;
35
- data = toBytes(data);
36
- const len = data.length;
37
- for (let pos = 0; pos < len;) {
38
- const take = Math.min(blockLen - this.pos, len - pos);
39
- // Fast path: we have at least one block in input, cast it to view and process
40
- if (take === blockLen) {
41
- const dataView = createView(data);
42
- for (; blockLen <= len - pos; pos += blockLen)
43
- this.process(dataView, pos);
44
- continue;
45
- }
46
- buffer.set(data.subarray(pos, pos + take), this.pos);
47
- this.pos += take;
48
- pos += take;
49
- if (this.pos === blockLen) {
50
- this.process(view, 0);
51
- this.pos = 0;
52
- }
53
- }
54
- this.length += data.length;
55
- this.roundClean();
56
- return this;
57
- }
58
- digestInto(out) {
59
- assert.exists(this);
60
- assert.output(out, this);
61
- this.finished = true;
62
- // Padding
63
- // We can avoid allocation of buffer for padding completely if it
64
- // was previously not allocated here. But it won't change performance.
65
- const { buffer, view, blockLen, isLE } = this;
66
- let { pos } = this;
67
- // append the bit '1' to the message
68
- buffer[pos++] = 0b10000000;
69
- this.buffer.subarray(pos).fill(0);
70
- // we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
71
- if (this.padOffset > blockLen - pos) {
72
- this.process(view, 0);
73
- pos = 0;
74
- }
75
- // Pad until full block byte with zeros
76
- for (let i = pos; i < blockLen; i++)
77
- buffer[i] = 0;
78
- // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
79
- // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
80
- // So we just write lowest 64 bits of that value.
81
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
82
- this.process(view, 0);
83
- const oview = createView(out);
84
- const len = this.outputLen;
85
- // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
86
- if (len % 4)
87
- throw new Error('_sha2: outputLen should be aligned to 32bit');
88
- const outLen = len / 4;
89
- const state = this.get();
90
- if (outLen > state.length)
91
- throw new Error('_sha2: outputLen bigger than state');
92
- for (let i = 0; i < outLen; i++)
93
- oview.setUint32(4 * i, state[i], isLE);
94
- }
95
- digest() {
96
- const { buffer, outputLen } = this;
97
- this.digestInto(buffer);
98
- const res = buffer.slice(0, outputLen);
99
- this.destroy();
100
- return res;
101
- }
102
- _cloneInto(to) {
103
- to || (to = new this.constructor());
104
- to.set(...this.get());
105
- const { blockLen, buffer, length, finished, destroyed, pos } = this;
106
- to.length = length;
107
- to.pos = pos;
108
- to.finished = finished;
109
- to.destroyed = destroyed;
110
- if (length % blockLen)
111
- to.buffer.set(buffer);
112
- return to;
113
- }
114
- }
115
-
116
- export { SHA2 };
@@ -1,79 +0,0 @@
1
- import assert from './_assert.js';
2
- import { Hash, toBytes } from './utils.js';
3
-
4
- // HMAC (RFC 2104)
5
- class HMAC extends Hash {
6
- constructor(hash, _key) {
7
- super();
8
- this.finished = false;
9
- this.destroyed = false;
10
- assert.hash(hash);
11
- const key = toBytes(_key);
12
- this.iHash = hash.create();
13
- if (typeof this.iHash.update !== 'function')
14
- throw new TypeError('Expected instance of class which extends utils.Hash');
15
- this.blockLen = this.iHash.blockLen;
16
- this.outputLen = this.iHash.outputLen;
17
- const blockLen = this.blockLen;
18
- const pad = new Uint8Array(blockLen);
19
- // blockLen can be bigger than outputLen
20
- pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
21
- for (let i = 0; i < pad.length; i++)
22
- pad[i] ^= 0x36;
23
- this.iHash.update(pad);
24
- // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
25
- this.oHash = hash.create();
26
- // Undo internal XOR && apply outer XOR
27
- for (let i = 0; i < pad.length; i++)
28
- pad[i] ^= 0x36 ^ 0x5c;
29
- this.oHash.update(pad);
30
- pad.fill(0);
31
- }
32
- update(buf) {
33
- assert.exists(this);
34
- this.iHash.update(buf);
35
- return this;
36
- }
37
- digestInto(out) {
38
- assert.exists(this);
39
- assert.bytes(out, this.outputLen);
40
- this.finished = true;
41
- this.iHash.digestInto(out);
42
- this.oHash.update(out);
43
- this.oHash.digestInto(out);
44
- this.destroy();
45
- }
46
- digest() {
47
- const out = new Uint8Array(this.oHash.outputLen);
48
- this.digestInto(out);
49
- return out;
50
- }
51
- _cloneInto(to) {
52
- // Create new instance without calling constructor since key already in state and we don't know it.
53
- to || (to = Object.create(Object.getPrototypeOf(this), {}));
54
- const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
55
- to = to;
56
- to.finished = finished;
57
- to.destroyed = destroyed;
58
- to.blockLen = blockLen;
59
- to.outputLen = outputLen;
60
- to.oHash = oHash._cloneInto(to.oHash);
61
- to.iHash = iHash._cloneInto(to.iHash);
62
- return to;
63
- }
64
- destroy() {
65
- this.destroyed = true;
66
- this.oHash.destroy();
67
- this.iHash.destroy();
68
- }
69
- }
70
- /**
71
- * HMAC: RFC2104 message authentication code.
72
- * @param hash - function that would be used e.g. sha256
73
- * @param key - message key
74
- * @param message - message data
75
- */
76
- const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
77
- hmac.create = (hash, key) => new HMAC(hash, key);
78
-
79
- export { hmac };
@@ -1,126 +0,0 @@
1
- import { SHA2 } from './_sha2.js';
2
- import { wrapConstructor, rotr } from './utils.js';
3
-
4
- // Choice: a ? b : c
5
- const Chi = (a, b, c) => (a & b) ^ (~a & c);
6
- // Majority function, true if any two inpust is true
7
- const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
8
- // Round constants:
9
- // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
10
- // prettier-ignore
11
- const SHA256_K = new Uint32Array([
12
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
13
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
14
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
15
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
16
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
17
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
18
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
19
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
20
- ]);
21
- // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
22
- // prettier-ignore
23
- const IV = new Uint32Array([
24
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
25
- ]);
26
- // Temporary buffer, not used to store anything between runs
27
- // Named this way because it matches specification.
28
- const SHA256_W = new Uint32Array(64);
29
- class SHA256 extends SHA2 {
30
- constructor() {
31
- super(64, 32, 8, false);
32
- // We cannot use array here since array allows indexing by variable
33
- // which means optimizer/compiler cannot use registers.
34
- this.A = IV[0] | 0;
35
- this.B = IV[1] | 0;
36
- this.C = IV[2] | 0;
37
- this.D = IV[3] | 0;
38
- this.E = IV[4] | 0;
39
- this.F = IV[5] | 0;
40
- this.G = IV[6] | 0;
41
- this.H = IV[7] | 0;
42
- }
43
- get() {
44
- const { A, B, C, D, E, F, G, H } = this;
45
- return [A, B, C, D, E, F, G, H];
46
- }
47
- // prettier-ignore
48
- set(A, B, C, D, E, F, G, H) {
49
- this.A = A | 0;
50
- this.B = B | 0;
51
- this.C = C | 0;
52
- this.D = D | 0;
53
- this.E = E | 0;
54
- this.F = F | 0;
55
- this.G = G | 0;
56
- this.H = H | 0;
57
- }
58
- process(view, offset) {
59
- // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
60
- for (let i = 0; i < 16; i++, offset += 4)
61
- SHA256_W[i] = view.getUint32(offset, false);
62
- for (let i = 16; i < 64; i++) {
63
- const W15 = SHA256_W[i - 15];
64
- const W2 = SHA256_W[i - 2];
65
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
66
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
67
- SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
68
- }
69
- // Compression function main loop, 64 rounds
70
- let { A, B, C, D, E, F, G, H } = this;
71
- for (let i = 0; i < 64; i++) {
72
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
73
- const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
74
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
75
- const T2 = (sigma0 + Maj(A, B, C)) | 0;
76
- H = G;
77
- G = F;
78
- F = E;
79
- E = (D + T1) | 0;
80
- D = C;
81
- C = B;
82
- B = A;
83
- A = (T1 + T2) | 0;
84
- }
85
- // Add the compressed chunk to the current hash value
86
- A = (A + this.A) | 0;
87
- B = (B + this.B) | 0;
88
- C = (C + this.C) | 0;
89
- D = (D + this.D) | 0;
90
- E = (E + this.E) | 0;
91
- F = (F + this.F) | 0;
92
- G = (G + this.G) | 0;
93
- H = (H + this.H) | 0;
94
- this.set(A, B, C, D, E, F, G, H);
95
- }
96
- roundClean() {
97
- SHA256_W.fill(0);
98
- }
99
- destroy() {
100
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
101
- this.buffer.fill(0);
102
- }
103
- }
104
- // Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
105
- class SHA224 extends SHA256 {
106
- constructor() {
107
- super();
108
- this.A = 0xc1059ed8 | 0;
109
- this.B = 0x367cd507 | 0;
110
- this.C = 0x3070dd17 | 0;
111
- this.D = 0xf70e5939 | 0;
112
- this.E = 0xffc00b31 | 0;
113
- this.F = 0x68581511 | 0;
114
- this.G = 0x64f98fa7 | 0;
115
- this.H = 0xbefa4fa4 | 0;
116
- this.outputLen = 28;
117
- }
118
- }
119
- /**
120
- * SHA2-256 hash function
121
- * @param message - data that would be hashed
122
- */
123
- const sha256 = wrapConstructor(() => new SHA256());
124
- wrapConstructor(() => new SHA224());
125
-
126
- export { sha256 };
@@ -1,43 +0,0 @@
1
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
- // The import here is via the package name. This is to ensure
3
- // that exports mapping/resolution does fall into place.
4
- // Cast array to view
5
- const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
6
- // The rotate right (circular right shift) operation for uint32
7
- const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
8
- const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
9
- // There is almost no big endian hardware, but js typed arrays uses platform specific endianness.
10
- // So, just to be sure not to corrupt anything.
11
- if (!isLE)
12
- throw new Error('Non little-endian hardware is not supported');
13
- Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
14
- function utf8ToBytes(str) {
15
- if (typeof str !== 'string') {
16
- throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
17
- }
18
- return new TextEncoder().encode(str);
19
- }
20
- function toBytes(data) {
21
- if (typeof data === 'string')
22
- data = utf8ToBytes(data);
23
- if (!(data instanceof Uint8Array))
24
- throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
25
- return data;
26
- }
27
- // For runtime check if class implements interface
28
- class Hash {
29
- // Safe version that clones internal state
30
- clone() {
31
- return this._cloneInto();
32
- }
33
- }
34
- function wrapConstructor(hashConstructor) {
35
- const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
36
- const tmp = hashConstructor();
37
- hashC.outputLen = tmp.outputLen;
38
- hashC.blockLen = tmp.blockLen;
39
- hashC.create = () => hashConstructor();
40
- return hashC;
41
- }
42
-
43
- export { Hash, createView, isLE, rotr, toBytes, utf8ToBytes, wrapConstructor };
@@ -1,36 +0,0 @@
1
- import type { IProtoMessage } from "@waku/interfaces";
2
- import type { IdentityCredential } from "./identity.js";
3
- export interface TestRLNCodecSetup {
4
- rlnInstance: any;
5
- credential: IdentityCredential;
6
- index: number;
7
- payload: Uint8Array;
8
- }
9
- export declare const TEST_CONSTANTS: {
10
- readonly contentTopic: "/test/1/waku-message/utf8";
11
- readonly emptyPubsubTopic: "";
12
- readonly defaultIndex: 0;
13
- readonly defaultPayload: Uint8Array;
14
- };
15
- export declare const EMPTY_PROTO_MESSAGE: {
16
- readonly timestamp: undefined;
17
- readonly contentTopic: "";
18
- readonly ephemeral: undefined;
19
- readonly meta: undefined;
20
- readonly rateLimitProof: undefined;
21
- readonly version: undefined;
22
- };
23
- /**
24
- * Creates a basic RLN setup for codec tests
25
- */
26
- export declare function createTestRLNCodecSetup(): Promise<TestRLNCodecSetup>;
27
- /**
28
- * Creates a meta setter function for testing
29
- */
30
- export declare function createTestMetaSetter(): (msg: IProtoMessage & {
31
- meta: undefined;
32
- }) => Uint8Array;
33
- /**
34
- * Verifies common RLN message properties
35
- */
36
- export declare function verifyRLNMessage(msg: any, payload: Uint8Array, contentTopic: string, version: number, rlnInstance: any): void;
@@ -1,56 +0,0 @@
1
- import { expect } from "chai";
2
- import { createRLN } from "./create.js";
3
- export const TEST_CONSTANTS = {
4
- contentTopic: "/test/1/waku-message/utf8",
5
- emptyPubsubTopic: "",
6
- defaultIndex: 0,
7
- defaultPayload: new Uint8Array([1, 2, 3, 4, 5])
8
- };
9
- export const EMPTY_PROTO_MESSAGE = {
10
- timestamp: undefined,
11
- contentTopic: "",
12
- ephemeral: undefined,
13
- meta: undefined,
14
- rateLimitProof: undefined,
15
- version: undefined
16
- };
17
- /**
18
- * Creates a basic RLN setup for codec tests
19
- */
20
- export async function createTestRLNCodecSetup() {
21
- const rlnInstance = await createRLN();
22
- const credential = rlnInstance.zerokit.generateIdentityCredentials();
23
- rlnInstance.zerokit.insertMember(credential.IDCommitment);
24
- return {
25
- rlnInstance,
26
- credential,
27
- index: TEST_CONSTANTS.defaultIndex,
28
- payload: TEST_CONSTANTS.defaultPayload
29
- };
30
- }
31
- /**
32
- * Creates a meta setter function for testing
33
- */
34
- export function createTestMetaSetter() {
35
- return (msg) => {
36
- const buffer = new ArrayBuffer(4);
37
- const view = new DataView(buffer);
38
- view.setUint32(0, msg.payload.length, false);
39
- return new Uint8Array(buffer);
40
- };
41
- }
42
- /**
43
- * Verifies common RLN message properties
44
- */
45
- export function verifyRLNMessage(msg, payload, contentTopic, version, rlnInstance) {
46
- expect(msg.rateLimitProof).to.not.be.undefined;
47
- expect(msg.verify([rlnInstance.zerokit.getMerkleRoot()])).to.be.true;
48
- expect(msg.verifyNoRoot()).to.be.true;
49
- expect(msg.epoch).to.not.be.undefined;
50
- expect(msg.epoch).to.be.gt(0);
51
- expect(msg.contentTopic).to.eq(contentTopic);
52
- expect(msg.msg.version).to.eq(version);
53
- expect(msg.payload).to.deep.eq(payload);
54
- expect(msg.timestamp).to.not.be.undefined;
55
- }
56
- //# sourceMappingURL=codec.test-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codec.test-utils.js","sourceRoot":"","sources":["../src/codec.test-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAUxC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,2BAA2B;IACzC,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,CAAC;IACf,cAAc,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CACvC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE,EAAE;IAChB,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,SAAS;IACf,cAAc,EAAE,SAAS;IACzB,OAAO,EAAE,SAAS;CACV,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,MAAM,WAAW,GAAG,MAAM,SAAS,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC;IACrE,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAE1D,OAAO;QACL,WAAW;QACX,UAAU;QACV,KAAK,EAAE,cAAc,CAAC,YAAY;QAClC,OAAO,EAAE,cAAc,CAAC,cAAc;KACvC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAGlC,OAAO,CAAC,GAAwC,EAAc,EAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC7C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAQ,EACR,OAAmB,EACnB,YAAoB,EACpB,OAAe,EACf,WAAgB;IAEhB,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;IAC/C,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACrE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACtC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;IACtC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE9B,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;AAC5C,CAAC"}
@@ -1,124 +0,0 @@
1
- import { ethers } from "ethers";
2
- import type { IdentityCredential } from "../identity.js";
3
- import type { DecryptedCredentials } from "../keystore/index.js";
4
- type Member = {
5
- idCommitment: string;
6
- index: ethers.BigNumber;
7
- };
8
- interface RLNContractOptions {
9
- signer: ethers.Signer;
10
- address: string;
11
- rateLimit?: number;
12
- }
13
- interface RLNContractInitOptions extends RLNContractOptions {
14
- contract?: ethers.Contract;
15
- }
16
- export interface MembershipRegisteredEvent {
17
- idCommitment: string;
18
- membershipRateLimit: ethers.BigNumber;
19
- index: ethers.BigNumber;
20
- }
21
- type FetchMembersOptions = {
22
- fromBlock?: number;
23
- fetchRange?: number;
24
- fetchChunks?: number;
25
- };
26
- export interface MembershipInfo {
27
- index: ethers.BigNumber;
28
- idCommitment: string;
29
- rateLimit: number;
30
- startBlock: number;
31
- endBlock: number;
32
- state: MembershipState;
33
- }
34
- export declare enum MembershipState {
35
- Active = "Active",
36
- GracePeriod = "GracePeriod",
37
- Expired = "Expired",
38
- ErasedAwaitsWithdrawal = "ErasedAwaitsWithdrawal"
39
- }
40
- export declare class RLNLightContract {
41
- contract: ethers.Contract;
42
- private deployBlock;
43
- private rateLimit;
44
- private _members;
45
- private _membersFilter;
46
- private _membershipErasedFilter;
47
- private _membersExpiredFilter;
48
- /**
49
- * Asynchronous initializer for RLNContract.
50
- * Allows injecting a mocked contract for testing purposes.
51
- */
52
- static init(options: RLNContractInitOptions): Promise<RLNLightContract>;
53
- private constructor();
54
- /**
55
- * Gets the current rate limit for this contract instance
56
- */
57
- getRateLimit(): number;
58
- /**
59
- * Gets the contract address
60
- */
61
- get address(): string;
62
- /**
63
- * Gets the contract provider
64
- */
65
- get provider(): ethers.providers.Provider;
66
- /**
67
- * Gets the minimum allowed rate limit from the contract
68
- * @returns Promise<number> The minimum rate limit in messages per epoch
69
- */
70
- getMinRateLimit(): Promise<number>;
71
- /**
72
- * Gets the maximum allowed rate limit from the contract
73
- * @returns Promise<number> The maximum rate limit in messages per epoch
74
- */
75
- getMaxRateLimit(): Promise<number>;
76
- /**
77
- * Gets the maximum total rate limit across all memberships
78
- * @returns Promise<number> The maximum total rate limit in messages per epoch
79
- */
80
- getMaxTotalRateLimit(): Promise<number>;
81
- /**
82
- * Gets the current total rate limit usage across all memberships
83
- * @returns Promise<number> The current total rate limit usage in messages per epoch
84
- */
85
- getCurrentTotalRateLimit(): Promise<number>;
86
- /**
87
- * Gets the remaining available total rate limit that can be allocated
88
- * @returns Promise<number> The remaining rate limit that can be allocated
89
- */
90
- getRemainingTotalRateLimit(): Promise<number>;
91
- /**
92
- * Updates the rate limit for future registrations
93
- * @param newRateLimit The new rate limit to use
94
- */
95
- setRateLimit(newRateLimit: number): Promise<void>;
96
- get members(): Member[];
97
- private get membersFilter();
98
- private get membershipErasedFilter();
99
- private get membersExpiredFilter();
100
- fetchMembers(options?: FetchMembersOptions): Promise<void>;
101
- processEvents(events: ethers.Event[]): void;
102
- subscribeToMembers(): void;
103
- registerWithIdentity(identity: IdentityCredential): Promise<DecryptedCredentials | undefined>;
104
- /**
105
- * Helper method to get remaining messages in current epoch
106
- * @param membershipId The ID of the membership to check
107
- * @returns number of remaining messages allowed in current epoch
108
- */
109
- getRemainingMessages(membershipId: number): Promise<number>;
110
- registerWithPermitAndErase(identity: IdentityCredential, permit: {
111
- owner: string;
112
- deadline: number;
113
- v: number;
114
- r: string;
115
- s: string;
116
- }, idCommitmentsToErase: string[]): Promise<DecryptedCredentials | undefined>;
117
- withdraw(token: string, holder: string): Promise<void>;
118
- getMembershipInfo(idCommitment: string): Promise<MembershipInfo | undefined>;
119
- extendMembership(idCommitment: string): Promise<ethers.ContractTransaction>;
120
- eraseMembership(idCommitment: string, eraseFromMembershipSet?: boolean): Promise<ethers.ContractTransaction>;
121
- registerMembership(idCommitment: string, rateLimit?: number): Promise<ethers.ContractTransaction>;
122
- private getMemberIndex;
123
- }
124
- export {};