@waku/rln 0.1.6-006cd41.0 → 0.1.6-a7f52e4.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 (98) hide show
  1. package/bundle/_virtual/index2.js +1 -1
  2. package/bundle/_virtual/utils.js +2 -2
  3. package/bundle/_virtual/utils2.js +2 -2
  4. package/bundle/index.js +2 -1
  5. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
  6. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
  7. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
  8. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
  9. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
  10. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
  11. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
  12. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  13. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
  14. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
  15. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_assert.js +1 -1
  16. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_sha2.js +3 -3
  17. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_u64.js +1 -1
  18. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  19. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/hmac.js +3 -3
  20. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/pbkdf2.js +4 -4
  21. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/scrypt.js +5 -5
  22. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha256.js +3 -3
  23. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha512.js +4 -4
  24. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/utils.js +2 -2
  25. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
  26. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
  27. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
  28. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
  29. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
  30. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
  31. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
  32. package/bundle/node_modules/@noble/hashes/esm/_assert.js +6 -32
  33. package/bundle/node_modules/@noble/hashes/esm/_md.js +22 -11
  34. package/bundle/node_modules/@noble/hashes/esm/_u64.js +4 -3
  35. package/bundle/{packages/rln/node_modules → node_modules}/@noble/hashes/esm/hmac.js +19 -10
  36. package/bundle/{packages/rln/node_modules/@noble/hashes/esm/sha256.js → node_modules/@noble/hashes/esm/sha2.js} +36 -50
  37. package/bundle/node_modules/@noble/hashes/esm/sha256.js +5 -102
  38. package/bundle/node_modules/@noble/hashes/esm/sha3.js +30 -24
  39. package/bundle/node_modules/@noble/hashes/esm/utils.js +69 -18
  40. package/bundle/node_modules/bn.js/lib/bn.js +1 -0
  41. package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +1 -1
  42. package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
  43. package/bundle/packages/rln/dist/contract/constants.js +1 -0
  44. package/bundle/packages/rln/dist/contract/rln_base_contract.js +127 -71
  45. package/bundle/packages/rln/dist/credentials_manager.js +3 -3
  46. package/bundle/packages/rln/dist/identity.js +1 -1
  47. package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
  48. package/bundle/packages/rln/dist/keystore/keystore.js +1 -1
  49. package/bundle/packages/rln/dist/utils/bytes.js +6 -3
  50. package/dist/.tsbuildinfo +1 -1
  51. package/dist/contract/index.d.ts +1 -0
  52. package/dist/contract/index.js +1 -0
  53. package/dist/contract/index.js.map +1 -1
  54. package/dist/contract/rln_base_contract.d.ts +32 -22
  55. package/dist/contract/rln_base_contract.js +127 -71
  56. package/dist/contract/rln_base_contract.js.map +1 -1
  57. package/dist/contract/types.d.ts +5 -0
  58. package/dist/contract/types.js.map +1 -1
  59. package/dist/credentials_manager.js +1 -1
  60. package/dist/credentials_manager.js.map +1 -1
  61. package/dist/identity.js +1 -1
  62. package/dist/identity.js.map +1 -1
  63. package/dist/index.d.ts +2 -1
  64. package/dist/index.js +1 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/keystore/keystore.js.map +1 -1
  67. package/dist/keystore/types.d.ts +2 -2
  68. package/dist/utils/bytes.d.ts +1 -1
  69. package/dist/utils/bytes.js +6 -3
  70. package/dist/utils/bytes.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/contract/index.ts +1 -0
  73. package/src/contract/rln_base_contract.ts +166 -102
  74. package/src/contract/types.ts +5 -0
  75. package/src/credentials_manager.ts +1 -1
  76. package/src/identity.ts +2 -1
  77. package/src/index.ts +3 -1
  78. package/src/keystore/keystore.ts +4 -2
  79. package/src/keystore/types.ts +2 -2
  80. package/src/utils/bytes.ts +6 -6
  81. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
  82. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
  83. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
  84. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
  85. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
  86. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
  87. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
  88. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
  89. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
  90. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
  91. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
  92. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
  93. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
  94. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
  95. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
  96. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
  97. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
  98. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,14 +1,19 @@
1
- import { SHA2 } from './_sha2.js';
2
- import { wrapConstructor, rotr } from './utils.js';
1
+ import { HashMD, SHA256_IV, Chi, Maj } from './_md.js';
2
+ import { createHasher, clean, rotr } from './utils.js';
3
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)
4
+ /**
5
+ * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
6
+ * SHA256 is the fastest hash implementable in JS, even faster than Blake3.
7
+ * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
8
+ * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
9
+ * @module
10
+ */
11
+ /**
12
+ * Round constants:
13
+ * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
14
+ */
10
15
  // prettier-ignore
11
- const SHA256_K = new Uint32Array([
16
+ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
12
17
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
13
18
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
14
19
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -18,27 +23,21 @@ const SHA256_K = new Uint32Array([
18
23
  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
19
24
  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
20
25
  ]);
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);
26
+ /** Reusable temporary buffer. "W" comes straight from spec. */
27
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
28
+ class SHA256 extends HashMD {
29
+ constructor(outputLen = 32) {
30
+ super(64, outputLen, 8, false);
32
31
  // We cannot use array here since array allows indexing by variable
33
32
  // 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;
33
+ this.A = SHA256_IV[0] | 0;
34
+ this.B = SHA256_IV[1] | 0;
35
+ this.C = SHA256_IV[2] | 0;
36
+ this.D = SHA256_IV[3] | 0;
37
+ this.E = SHA256_IV[4] | 0;
38
+ this.F = SHA256_IV[5] | 0;
39
+ this.G = SHA256_IV[6] | 0;
40
+ this.H = SHA256_IV[7] | 0;
42
41
  }
43
42
  get() {
44
43
  const { A, B, C, D, E, F, G, H } = this;
@@ -94,33 +93,20 @@ class SHA256 extends SHA2 {
94
93
  this.set(A, B, C, D, E, F, G, H);
95
94
  }
96
95
  roundClean() {
97
- SHA256_W.fill(0);
96
+ clean(SHA256_W);
98
97
  }
99
98
  destroy() {
100
99
  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;
100
+ clean(this.buffer);
117
101
  }
118
102
  }
119
103
  /**
120
- * SHA2-256 hash function
121
- * @param message - data that would be hashed
104
+ * SHA2-256 hash function from RFC 4634.
105
+ *
106
+ * It is the fastest JS hash, even faster than Blake3.
107
+ * To break sha256 using birthday attack, attackers need to try 2^128 hashes.
108
+ * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
122
109
  */
123
- const sha256 = wrapConstructor(() => new SHA256());
124
- wrapConstructor(() => new SHA224());
110
+ const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
125
111
 
126
- export { sha256 };
112
+ export { SHA256, sha256 };
@@ -1,5 +1,4 @@
1
- import { HashMD, Chi, Maj } from './_md.js';
2
- import { wrapConstructor, rotr } from './utils.js';
1
+ import { sha256 as sha256$1 } from './sha2.js';
3
2
 
4
3
  /**
5
4
  * SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
@@ -9,105 +8,9 @@ import { wrapConstructor, rotr } from './utils.js';
9
8
  *
10
9
  * Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
11
10
  * @module
11
+ * @deprecated
12
12
  */
13
- /** Round constants: first 32 bits of fractional parts of the cube roots of the first 64 primes 2..311). */
14
- // prettier-ignore
15
- const SHA256_K = /* @__PURE__ */ new Uint32Array([
16
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
17
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
18
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
19
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
20
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
21
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
22
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
23
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
24
- ]);
25
- /** Initial state: first 32 bits of fractional parts of the square roots of the first 8 primes 2..19. */
26
- // prettier-ignore
27
- const SHA256_IV = /* @__PURE__ */ new Uint32Array([
28
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
29
- ]);
30
- /**
31
- * Temporary buffer, not used to store anything between runs.
32
- * Named this way because it matches specification.
33
- */
34
- const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
35
- class SHA256 extends HashMD {
36
- constructor() {
37
- super(64, 32, 8, false);
38
- // We cannot use array here since array allows indexing by variable
39
- // which means optimizer/compiler cannot use registers.
40
- this.A = SHA256_IV[0] | 0;
41
- this.B = SHA256_IV[1] | 0;
42
- this.C = SHA256_IV[2] | 0;
43
- this.D = SHA256_IV[3] | 0;
44
- this.E = SHA256_IV[4] | 0;
45
- this.F = SHA256_IV[5] | 0;
46
- this.G = SHA256_IV[6] | 0;
47
- this.H = SHA256_IV[7] | 0;
48
- }
49
- get() {
50
- const { A, B, C, D, E, F, G, H } = this;
51
- return [A, B, C, D, E, F, G, H];
52
- }
53
- // prettier-ignore
54
- set(A, B, C, D, E, F, G, H) {
55
- this.A = A | 0;
56
- this.B = B | 0;
57
- this.C = C | 0;
58
- this.D = D | 0;
59
- this.E = E | 0;
60
- this.F = F | 0;
61
- this.G = G | 0;
62
- this.H = H | 0;
63
- }
64
- process(view, offset) {
65
- // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
66
- for (let i = 0; i < 16; i++, offset += 4)
67
- SHA256_W[i] = view.getUint32(offset, false);
68
- for (let i = 16; i < 64; i++) {
69
- const W15 = SHA256_W[i - 15];
70
- const W2 = SHA256_W[i - 2];
71
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
72
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
73
- SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
74
- }
75
- // Compression function main loop, 64 rounds
76
- let { A, B, C, D, E, F, G, H } = this;
77
- for (let i = 0; i < 64; i++) {
78
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
79
- const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
80
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
81
- const T2 = (sigma0 + Maj(A, B, C)) | 0;
82
- H = G;
83
- G = F;
84
- F = E;
85
- E = (D + T1) | 0;
86
- D = C;
87
- C = B;
88
- B = A;
89
- A = (T1 + T2) | 0;
90
- }
91
- // Add the compressed chunk to the current hash value
92
- A = (A + this.A) | 0;
93
- B = (B + this.B) | 0;
94
- C = (C + this.C) | 0;
95
- D = (D + this.D) | 0;
96
- E = (E + this.E) | 0;
97
- F = (F + this.F) | 0;
98
- G = (G + this.G) | 0;
99
- H = (H + this.H) | 0;
100
- this.set(A, B, C, D, E, F, G, H);
101
- }
102
- roundClean() {
103
- SHA256_W.fill(0);
104
- }
105
- destroy() {
106
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
107
- this.buffer.fill(0);
108
- }
109
- }
110
- /** SHA2-256 hash function */
111
- const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
13
+ /** @deprecated Use import from `noble/hashes/sha2` module */
14
+ const sha256 = sha256$1;
112
15
 
113
- export { SHA256, sha256 };
16
+ export { sha256 };
@@ -1,6 +1,5 @@
1
- import { anumber, aexists, abytes, aoutput } from './_assert.js';
2
1
  import { rotlSH, rotlSL, rotlBH, rotlBL, split } from './_u64.js';
3
- import { wrapConstructor, Hash, u32, isLE, byteSwap32, toBytes } from './utils.js';
2
+ import { createHasher, Hash, anumber, u32, swap32IfBE, aexists, toBytes, abytes, aoutput, clean } from './utils.js';
4
3
 
5
4
  /**
6
5
  * SHA3 (keccak) hash function, based on a new "Sponge function" design.
@@ -13,16 +12,18 @@ import { wrapConstructor, Hash, u32, isLE, byteSwap32, toBytes } from './utils.j
13
12
  * Check out `sha3-addons` module for cSHAKE, k12, and others.
14
13
  * @module
15
14
  */
15
+ // No __PURE__ annotations in sha3 header:
16
+ // EVERYTHING is in fact used on every export.
16
17
  // Various per round constants calculations
18
+ const _0n = BigInt(0);
19
+ const _1n = BigInt(1);
20
+ const _2n = BigInt(2);
21
+ const _7n = BigInt(7);
22
+ const _256n = BigInt(256);
23
+ const _0x71n = BigInt(0x71);
17
24
  const SHA3_PI = [];
18
25
  const SHA3_ROTL = [];
19
26
  const _SHA3_IOTA = [];
20
- const _0n = /* @__PURE__ */ BigInt(0);
21
- const _1n = /* @__PURE__ */ BigInt(1);
22
- const _2n = /* @__PURE__ */ BigInt(2);
23
- const _7n = /* @__PURE__ */ BigInt(7);
24
- const _256n = /* @__PURE__ */ BigInt(256);
25
- const _0x71n = /* @__PURE__ */ BigInt(0x71);
26
27
  for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
27
28
  // Pi
28
29
  [x, y] = [y, (2 * x + 3 * y) % 5];
@@ -38,7 +39,9 @@ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
38
39
  }
39
40
  _SHA3_IOTA.push(t);
40
41
  }
41
- const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
42
+ const IOTAS = split(_SHA3_IOTA, true);
43
+ const SHA3_IOTA_H = IOTAS[0];
44
+ const SHA3_IOTA_L = IOTAS[1];
42
45
  // Left rotation (without 0, 32, 64)
43
46
  const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
44
47
  const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
@@ -86,44 +89,47 @@ function keccakP(s, rounds = 24) {
86
89
  s[0] ^= SHA3_IOTA_H[round];
87
90
  s[1] ^= SHA3_IOTA_L[round];
88
91
  }
89
- B.fill(0);
92
+ clean(B);
90
93
  }
91
94
  /** Keccak sponge function. */
92
95
  class Keccak extends Hash {
93
96
  // NOTE: we accept arguments in bytes instead of bits here.
94
97
  constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
95
98
  super();
99
+ this.pos = 0;
100
+ this.posOut = 0;
101
+ this.finished = false;
102
+ this.destroyed = false;
103
+ this.enableXOF = false;
96
104
  this.blockLen = blockLen;
97
105
  this.suffix = suffix;
98
106
  this.outputLen = outputLen;
99
107
  this.enableXOF = enableXOF;
100
108
  this.rounds = rounds;
101
- this.pos = 0;
102
- this.posOut = 0;
103
- this.finished = false;
104
- this.destroyed = false;
105
109
  // Can be passed from user as dkLen
106
110
  anumber(outputLen);
107
111
  // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
108
112
  // 0 < blockLen < 200
109
- if (0 >= this.blockLen || this.blockLen >= 200)
110
- throw new Error('Sha3 supports only keccak-f1600 function');
113
+ if (!(0 < blockLen && blockLen < 200))
114
+ throw new Error('only keccak-f1600 function is supported');
111
115
  this.state = new Uint8Array(200);
112
116
  this.state32 = u32(this.state);
113
117
  }
118
+ clone() {
119
+ return this._cloneInto();
120
+ }
114
121
  keccak() {
115
- if (!isLE)
116
- byteSwap32(this.state32);
122
+ swap32IfBE(this.state32);
117
123
  keccakP(this.state32, this.rounds);
118
- if (!isLE)
119
- byteSwap32(this.state32);
124
+ swap32IfBE(this.state32);
120
125
  this.posOut = 0;
121
126
  this.pos = 0;
122
127
  }
123
128
  update(data) {
124
129
  aexists(this);
125
- const { blockLen, state } = this;
126
130
  data = toBytes(data);
131
+ abytes(data);
132
+ const { blockLen, state } = this;
127
133
  const len = data.length;
128
134
  for (let pos = 0; pos < len;) {
129
135
  const take = Math.min(blockLen - this.pos, len - pos);
@@ -185,7 +191,7 @@ class Keccak extends Hash {
185
191
  }
186
192
  destroy() {
187
193
  this.destroyed = true;
188
- this.state.fill(0);
194
+ clean(this.state);
189
195
  }
190
196
  _cloneInto(to) {
191
197
  const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
@@ -203,8 +209,8 @@ class Keccak extends Hash {
203
209
  return to;
204
210
  }
205
211
  }
206
- const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
212
+ const gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
207
213
  /** keccak-256 hash function. Different from SHA3-256. */
208
- const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
214
+ const keccak_256 = /* @__PURE__ */ (() => gen(0x01, 136, 256 / 8))();
209
215
 
210
216
  export { Keccak, keccakP, keccak_256 };
@@ -1,5 +1,3 @@
1
- import { abytes } from './_assert.js';
2
-
3
1
  /**
4
2
  * Utilities for hex, bytes, CSPRNG.
5
3
  * @module
@@ -11,10 +9,55 @@ import { abytes } from './_assert.js';
11
9
  // from `crypto` to `cryptoNode`, which imports native module.
12
10
  // Makes the utils un-importable in browsers without a bundler.
13
11
  // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
12
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
13
+ function isBytes(a) {
14
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
15
+ }
16
+ /** Asserts something is positive integer. */
17
+ function anumber(n) {
18
+ if (!Number.isSafeInteger(n) || n < 0)
19
+ throw new Error('positive integer expected, got ' + n);
20
+ }
21
+ /** Asserts something is Uint8Array. */
22
+ function abytes(b, ...lengths) {
23
+ if (!isBytes(b))
24
+ throw new Error('Uint8Array expected');
25
+ if (lengths.length > 0 && !lengths.includes(b.length))
26
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
27
+ }
28
+ /** Asserts something is hash */
29
+ function ahash(h) {
30
+ if (typeof h !== 'function' || typeof h.create !== 'function')
31
+ throw new Error('Hash should be wrapped by utils.createHasher');
32
+ anumber(h.outputLen);
33
+ anumber(h.blockLen);
34
+ }
35
+ /** Asserts a hash instance has not been destroyed / finished */
36
+ function aexists(instance, checkFinished = true) {
37
+ if (instance.destroyed)
38
+ throw new Error('Hash instance has been destroyed');
39
+ if (checkFinished && instance.finished)
40
+ throw new Error('Hash#digest() has already been called');
41
+ }
42
+ /** Asserts output is properly-sized byte array */
43
+ function aoutput(out, instance) {
44
+ abytes(out);
45
+ const min = instance.outputLen;
46
+ if (out.length < min) {
47
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
48
+ }
49
+ }
50
+ /** Cast u8 / u16 / u32 to u32. */
14
51
  function u32(arr) {
15
52
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
16
53
  }
17
- // Cast array to view
54
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
55
+ function clean(...arrays) {
56
+ for (let i = 0; i < arrays.length; i++) {
57
+ arrays[i].fill(0);
58
+ }
59
+ }
60
+ /** Create DataView of an array for easy byte-level manipulation. */
18
61
  function createView(arr) {
19
62
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
20
63
  }
@@ -24,7 +67,7 @@ function rotr(word, shift) {
24
67
  }
25
68
  /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
26
69
  const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
27
- // The byte swap operation for uint32
70
+ /** The byte swap operation for uint32 */
28
71
  function byteSwap(word) {
29
72
  return (((word << 24) & 0xff000000) |
30
73
  ((word << 8) & 0xff0000) |
@@ -36,15 +79,26 @@ function byteSwap32(arr) {
36
79
  for (let i = 0; i < arr.length; i++) {
37
80
  arr[i] = byteSwap(arr[i]);
38
81
  }
82
+ return arr;
39
83
  }
84
+ const swap32IfBE = isLE
85
+ ? (u) => u
86
+ : byteSwap32;
87
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
88
+ const hasHexBuiltin = /* @__PURE__ */ (() =>
89
+ // @ts-ignore
90
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
40
91
  // Array where index 0xf0 (240) is mapped to string 'f0'
41
92
  const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
42
93
  /**
43
- * Convert byte array to hex string.
94
+ * Convert byte array to hex string. Uses built-in function, when available.
44
95
  * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
45
96
  */
46
97
  function bytesToHex(bytes) {
47
98
  abytes(bytes);
99
+ // @ts-ignore
100
+ if (hasHexBuiltin)
101
+ return bytes.toHex();
48
102
  // pre-caching improves the speed 6x
49
103
  let hex = '';
50
104
  for (let i = 0; i < bytes.length; i++) {
@@ -64,12 +118,15 @@ function asciiToBase16(ch) {
64
118
  return;
65
119
  }
66
120
  /**
67
- * Convert hex string to byte array.
121
+ * Convert hex string to byte array. Uses built-in function, when available.
68
122
  * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
69
123
  */
70
124
  function hexToBytes(hex) {
71
125
  if (typeof hex !== 'string')
72
126
  throw new Error('hex string expected, got ' + typeof hex);
127
+ // @ts-ignore
128
+ if (hasHexBuiltin)
129
+ return Uint8Array.fromHex(hex);
73
130
  const hl = hex.length;
74
131
  const al = hl / 2;
75
132
  if (hl % 2)
@@ -87,12 +144,12 @@ function hexToBytes(hex) {
87
144
  return array;
88
145
  }
89
146
  /**
90
- * Convert JS string to byte array.
91
- * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
147
+ * Converts string to bytes using UTF8 encoding.
148
+ * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
92
149
  */
93
150
  function utf8ToBytes(str) {
94
151
  if (typeof str !== 'string')
95
- throw new Error('utf8ToBytes expected string, got ' + typeof str);
152
+ throw new Error('string expected');
96
153
  return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
97
154
  }
98
155
  /**
@@ -106,9 +163,7 @@ function toBytes(data) {
106
163
  abytes(data);
107
164
  return data;
108
165
  }
109
- /**
110
- * Copies several Uint8Arrays into one.
111
- */
166
+ /** Copies several Uint8Arrays into one. */
112
167
  function concatBytes(...arrays) {
113
168
  let sum = 0;
114
169
  for (let i = 0; i < arrays.length; i++) {
@@ -126,13 +181,9 @@ function concatBytes(...arrays) {
126
181
  }
127
182
  /** For runtime check if class implements interface */
128
183
  class Hash {
129
- // Safe version that clones internal state
130
- clone() {
131
- return this._cloneInto();
132
- }
133
184
  }
134
185
  /** Wraps hash function, creating an interface on top of it */
135
- function wrapConstructor(hashCons) {
186
+ function createHasher(hashCons) {
136
187
  const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
137
188
  const tmp = hashCons();
138
189
  hashC.outputLen = tmp.outputLen;
@@ -141,4 +192,4 @@ function wrapConstructor(hashCons) {
141
192
  return hashC;
142
193
  }
143
194
 
144
- export { Hash, byteSwap, byteSwap32, bytesToHex, concatBytes, createView, hexToBytes, isLE, rotr, toBytes, u32, utf8ToBytes, wrapConstructor };
195
+ export { Hash, abytes, aexists, ahash, anumber, aoutput, byteSwap, byteSwap32, bytesToHex, clean, concatBytes, createHasher, createView, hexToBytes, isBytes, isLE, rotr, swap32IfBE, toBytes, u32, utf8ToBytes };
@@ -1818,6 +1818,7 @@ bn.exports;
1818
1818
  this.words[i] = carry;
1819
1819
  this.length++;
1820
1820
  }
1821
+ this.length = num === 0 ? 1 : this.length;
1821
1822
 
1822
1823
  return isNegNum ? this.ineg() : this;
1823
1824
  };
@@ -1,4 +1,4 @@
1
- import { sha256 as sha256$1 } from '../../@noble/hashes/esm/sha256.js';
1
+ import { sha256 as sha256$1 } from '../../@noble/hashes/esm/sha2.js';
2
2
  import { wrapHash } from './utils.js';
3
3
 
4
4
  const sha256 = wrapHash(sha256$1);
@@ -1,5 +1,5 @@
1
- import { getDefaultExportFromCjs, commonjsGlobal } from '../../../../../../_virtual/_commonjsHelpers.js';
2
- import { __module as sha3$1 } from '../../../../../../_virtual/sha3.js';
1
+ import { getDefaultExportFromCjs, commonjsGlobal } from '../../../_virtual/_commonjsHelpers.js';
2
+ import { __module as sha3$1 } from '../../../_virtual/sha3.js';
3
3
 
4
4
  /**
5
5
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
@@ -12,6 +12,7 @@ const LINEA_CONTRACT = {
12
12
  */
13
13
  const RATE_LIMIT_TIERS = {
14
14
  LOW: 20, // Suggested minimum rate - 20 messages per epoch
15
+ MEDIUM: 200,
15
16
  HIGH: 600 // Suggested maximum rate - 600 messages per epoch
16
17
  };
17
18
  // Global rate limit parameters