zattera-js 0.1.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +694 -0
  3. package/dist/browser/index.js +2466 -0
  4. package/dist/browser/index.js.map +1 -0
  5. package/dist/node/auth/index.js +188 -0
  6. package/dist/node/auth/index.js.map +1 -0
  7. package/dist/node/auth/keys.js +264 -0
  8. package/dist/node/auth/keys.js.map +1 -0
  9. package/dist/node/auth/memo.js +79 -0
  10. package/dist/node/auth/memo.js.map +1 -0
  11. package/dist/node/auth/serializer.js +162 -0
  12. package/dist/node/auth/serializer.js.map +1 -0
  13. package/dist/node/client/index.js +838 -0
  14. package/dist/node/client/index.js.map +1 -0
  15. package/dist/node/index.js +30 -0
  16. package/dist/node/index.js.map +1 -0
  17. package/dist/node/node_modules/@noble/ciphers/aes.js +254 -0
  18. package/dist/node/node_modules/@noble/ciphers/aes.js.map +1 -0
  19. package/dist/node/node_modules/@noble/ciphers/utils.js +113 -0
  20. package/dist/node/node_modules/@noble/ciphers/utils.js.map +1 -0
  21. package/dist/node/node_modules/@noble/hashes/esm/_md.js +146 -0
  22. package/dist/node/node_modules/@noble/hashes/esm/_md.js.map +1 -0
  23. package/dist/node/node_modules/@noble/hashes/esm/_u64.js +51 -0
  24. package/dist/node/node_modules/@noble/hashes/esm/_u64.js.map +1 -0
  25. package/dist/node/node_modules/@noble/hashes/esm/legacy.js +123 -0
  26. package/dist/node/node_modules/@noble/hashes/esm/legacy.js.map +1 -0
  27. package/dist/node/node_modules/@noble/hashes/esm/sha2.js +346 -0
  28. package/dist/node/node_modules/@noble/hashes/esm/sha2.js.map +1 -0
  29. package/dist/node/node_modules/@noble/hashes/esm/utils.js +73 -0
  30. package/dist/node/node_modules/@noble/hashes/esm/utils.js.map +1 -0
  31. package/dist/node/node_modules/@noble/secp256k1/index.js +578 -0
  32. package/dist/node/node_modules/@noble/secp256k1/index.js.map +1 -0
  33. package/dist/node/node_modules/bs58/node_modules/base-x/src/esm/index.js +132 -0
  34. package/dist/node/node_modules/bs58/node_modules/base-x/src/esm/index.js.map +1 -0
  35. package/dist/node/node_modules/bs58/src/esm/index.js +7 -0
  36. package/dist/node/node_modules/bs58/src/esm/index.js.map +1 -0
  37. package/dist/node/types/index.js +48 -0
  38. package/dist/node/types/index.js.map +1 -0
  39. package/dist/node/utils/chain-id.js +9 -0
  40. package/dist/node/utils/chain-id.js.map +1 -0
  41. package/dist/types/auth/index.d.ts +134 -0
  42. package/dist/types/auth/index.d.ts.map +1 -0
  43. package/dist/types/auth/keys.d.ts +112 -0
  44. package/dist/types/auth/keys.d.ts.map +1 -0
  45. package/dist/types/auth/memo.d.ts +51 -0
  46. package/dist/types/auth/memo.d.ts.map +1 -0
  47. package/dist/types/auth/serializer.d.ts +57 -0
  48. package/dist/types/auth/serializer.d.ts.map +1 -0
  49. package/dist/types/client/index.d.ts +360 -0
  50. package/dist/types/client/index.d.ts.map +1 -0
  51. package/dist/types/index.d.ts +16 -0
  52. package/dist/types/index.d.ts.map +1 -0
  53. package/dist/types/types/index.d.ts +593 -0
  54. package/dist/types/types/index.d.ts.map +1 -0
  55. package/dist/types/utils/chain-id.d.ts +10 -0
  56. package/dist/types/utils/chain-id.d.ts.map +1 -0
  57. package/package.json +63 -0
@@ -0,0 +1,346 @@
1
+ import { HashMD, SHA512_IV, SHA256_IV, Chi, Maj } from "./_md.js";
2
+ import { add4L, add4H, add5L, split, add5H, add, add3H, rotrSH, shrSH, rotrSL, shrSL, rotrBH, rotrBL, add3L } from "./_u64.js";
3
+ import { createHasher, clean, rotr } from "./utils.js";
4
+ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
5
+ 1116352408,
6
+ 1899447441,
7
+ 3049323471,
8
+ 3921009573,
9
+ 961987163,
10
+ 1508970993,
11
+ 2453635748,
12
+ 2870763221,
13
+ 3624381080,
14
+ 310598401,
15
+ 607225278,
16
+ 1426881987,
17
+ 1925078388,
18
+ 2162078206,
19
+ 2614888103,
20
+ 3248222580,
21
+ 3835390401,
22
+ 4022224774,
23
+ 264347078,
24
+ 604807628,
25
+ 770255983,
26
+ 1249150122,
27
+ 1555081692,
28
+ 1996064986,
29
+ 2554220882,
30
+ 2821834349,
31
+ 2952996808,
32
+ 3210313671,
33
+ 3336571891,
34
+ 3584528711,
35
+ 113926993,
36
+ 338241895,
37
+ 666307205,
38
+ 773529912,
39
+ 1294757372,
40
+ 1396182291,
41
+ 1695183700,
42
+ 1986661051,
43
+ 2177026350,
44
+ 2456956037,
45
+ 2730485921,
46
+ 2820302411,
47
+ 3259730800,
48
+ 3345764771,
49
+ 3516065817,
50
+ 3600352804,
51
+ 4094571909,
52
+ 275423344,
53
+ 430227734,
54
+ 506948616,
55
+ 659060556,
56
+ 883997877,
57
+ 958139571,
58
+ 1322822218,
59
+ 1537002063,
60
+ 1747873779,
61
+ 1955562222,
62
+ 2024104815,
63
+ 2227730452,
64
+ 2361852424,
65
+ 2428436474,
66
+ 2756734187,
67
+ 3204031479,
68
+ 3329325298
69
+ ]);
70
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
71
+ class SHA256 extends HashMD {
72
+ constructor(outputLen = 32) {
73
+ super(64, outputLen, 8, false);
74
+ this.A = SHA256_IV[0] | 0;
75
+ this.B = SHA256_IV[1] | 0;
76
+ this.C = SHA256_IV[2] | 0;
77
+ this.D = SHA256_IV[3] | 0;
78
+ this.E = SHA256_IV[4] | 0;
79
+ this.F = SHA256_IV[5] | 0;
80
+ this.G = SHA256_IV[6] | 0;
81
+ this.H = SHA256_IV[7] | 0;
82
+ }
83
+ get() {
84
+ const { A, B, C, D, E, F, G, H } = this;
85
+ return [A, B, C, D, E, F, G, H];
86
+ }
87
+ // prettier-ignore
88
+ set(A, B, C, D, E, F, G, H) {
89
+ this.A = A | 0;
90
+ this.B = B | 0;
91
+ this.C = C | 0;
92
+ this.D = D | 0;
93
+ this.E = E | 0;
94
+ this.F = F | 0;
95
+ this.G = G | 0;
96
+ this.H = H | 0;
97
+ }
98
+ process(view, offset) {
99
+ for (let i = 0; i < 16; i++, offset += 4)
100
+ SHA256_W[i] = view.getUint32(offset, false);
101
+ for (let i = 16; i < 64; i++) {
102
+ const W15 = SHA256_W[i - 15];
103
+ const W2 = SHA256_W[i - 2];
104
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
105
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
106
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
107
+ }
108
+ let { A, B, C, D, E, F, G, H } = this;
109
+ for (let i = 0; i < 64; i++) {
110
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
111
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
112
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
113
+ const T2 = sigma0 + Maj(A, B, C) | 0;
114
+ H = G;
115
+ G = F;
116
+ F = E;
117
+ E = D + T1 | 0;
118
+ D = C;
119
+ C = B;
120
+ B = A;
121
+ A = T1 + T2 | 0;
122
+ }
123
+ A = A + this.A | 0;
124
+ B = B + this.B | 0;
125
+ C = C + this.C | 0;
126
+ D = D + this.D | 0;
127
+ E = E + this.E | 0;
128
+ F = F + this.F | 0;
129
+ G = G + this.G | 0;
130
+ H = H + this.H | 0;
131
+ this.set(A, B, C, D, E, F, G, H);
132
+ }
133
+ roundClean() {
134
+ clean(SHA256_W);
135
+ }
136
+ destroy() {
137
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
138
+ clean(this.buffer);
139
+ }
140
+ }
141
+ const K512 = /* @__PURE__ */ (() => split([
142
+ "0x428a2f98d728ae22",
143
+ "0x7137449123ef65cd",
144
+ "0xb5c0fbcfec4d3b2f",
145
+ "0xe9b5dba58189dbbc",
146
+ "0x3956c25bf348b538",
147
+ "0x59f111f1b605d019",
148
+ "0x923f82a4af194f9b",
149
+ "0xab1c5ed5da6d8118",
150
+ "0xd807aa98a3030242",
151
+ "0x12835b0145706fbe",
152
+ "0x243185be4ee4b28c",
153
+ "0x550c7dc3d5ffb4e2",
154
+ "0x72be5d74f27b896f",
155
+ "0x80deb1fe3b1696b1",
156
+ "0x9bdc06a725c71235",
157
+ "0xc19bf174cf692694",
158
+ "0xe49b69c19ef14ad2",
159
+ "0xefbe4786384f25e3",
160
+ "0x0fc19dc68b8cd5b5",
161
+ "0x240ca1cc77ac9c65",
162
+ "0x2de92c6f592b0275",
163
+ "0x4a7484aa6ea6e483",
164
+ "0x5cb0a9dcbd41fbd4",
165
+ "0x76f988da831153b5",
166
+ "0x983e5152ee66dfab",
167
+ "0xa831c66d2db43210",
168
+ "0xb00327c898fb213f",
169
+ "0xbf597fc7beef0ee4",
170
+ "0xc6e00bf33da88fc2",
171
+ "0xd5a79147930aa725",
172
+ "0x06ca6351e003826f",
173
+ "0x142929670a0e6e70",
174
+ "0x27b70a8546d22ffc",
175
+ "0x2e1b21385c26c926",
176
+ "0x4d2c6dfc5ac42aed",
177
+ "0x53380d139d95b3df",
178
+ "0x650a73548baf63de",
179
+ "0x766a0abb3c77b2a8",
180
+ "0x81c2c92e47edaee6",
181
+ "0x92722c851482353b",
182
+ "0xa2bfe8a14cf10364",
183
+ "0xa81a664bbc423001",
184
+ "0xc24b8b70d0f89791",
185
+ "0xc76c51a30654be30",
186
+ "0xd192e819d6ef5218",
187
+ "0xd69906245565a910",
188
+ "0xf40e35855771202a",
189
+ "0x106aa07032bbd1b8",
190
+ "0x19a4c116b8d2d0c8",
191
+ "0x1e376c085141ab53",
192
+ "0x2748774cdf8eeb99",
193
+ "0x34b0bcb5e19b48a8",
194
+ "0x391c0cb3c5c95a63",
195
+ "0x4ed8aa4ae3418acb",
196
+ "0x5b9cca4f7763e373",
197
+ "0x682e6ff3d6b2b8a3",
198
+ "0x748f82ee5defb2fc",
199
+ "0x78a5636f43172f60",
200
+ "0x84c87814a1f0ab72",
201
+ "0x8cc702081a6439ec",
202
+ "0x90befffa23631e28",
203
+ "0xa4506cebde82bde9",
204
+ "0xbef9a3f7b2c67915",
205
+ "0xc67178f2e372532b",
206
+ "0xca273eceea26619c",
207
+ "0xd186b8c721c0c207",
208
+ "0xeada7dd6cde0eb1e",
209
+ "0xf57d4f7fee6ed178",
210
+ "0x06f067aa72176fba",
211
+ "0x0a637dc5a2c898a6",
212
+ "0x113f9804bef90dae",
213
+ "0x1b710b35131c471b",
214
+ "0x28db77f523047d84",
215
+ "0x32caab7b40c72493",
216
+ "0x3c9ebe0a15c9bebc",
217
+ "0x431d67c49c100d4c",
218
+ "0x4cc5d4becb3e42b6",
219
+ "0x597f299cfc657e2a",
220
+ "0x5fcb6fab3ad6faec",
221
+ "0x6c44198c4a475817"
222
+ ].map((n) => BigInt(n))))();
223
+ const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
224
+ const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
225
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
226
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
227
+ class SHA512 extends HashMD {
228
+ constructor(outputLen = 64) {
229
+ super(128, outputLen, 16, false);
230
+ this.Ah = SHA512_IV[0] | 0;
231
+ this.Al = SHA512_IV[1] | 0;
232
+ this.Bh = SHA512_IV[2] | 0;
233
+ this.Bl = SHA512_IV[3] | 0;
234
+ this.Ch = SHA512_IV[4] | 0;
235
+ this.Cl = SHA512_IV[5] | 0;
236
+ this.Dh = SHA512_IV[6] | 0;
237
+ this.Dl = SHA512_IV[7] | 0;
238
+ this.Eh = SHA512_IV[8] | 0;
239
+ this.El = SHA512_IV[9] | 0;
240
+ this.Fh = SHA512_IV[10] | 0;
241
+ this.Fl = SHA512_IV[11] | 0;
242
+ this.Gh = SHA512_IV[12] | 0;
243
+ this.Gl = SHA512_IV[13] | 0;
244
+ this.Hh = SHA512_IV[14] | 0;
245
+ this.Hl = SHA512_IV[15] | 0;
246
+ }
247
+ // prettier-ignore
248
+ get() {
249
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
250
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
251
+ }
252
+ // prettier-ignore
253
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
254
+ this.Ah = Ah | 0;
255
+ this.Al = Al | 0;
256
+ this.Bh = Bh | 0;
257
+ this.Bl = Bl | 0;
258
+ this.Ch = Ch | 0;
259
+ this.Cl = Cl | 0;
260
+ this.Dh = Dh | 0;
261
+ this.Dl = Dl | 0;
262
+ this.Eh = Eh | 0;
263
+ this.El = El | 0;
264
+ this.Fh = Fh | 0;
265
+ this.Fl = Fl | 0;
266
+ this.Gh = Gh | 0;
267
+ this.Gl = Gl | 0;
268
+ this.Hh = Hh | 0;
269
+ this.Hl = Hl | 0;
270
+ }
271
+ process(view, offset) {
272
+ for (let i = 0; i < 16; i++, offset += 4) {
273
+ SHA512_W_H[i] = view.getUint32(offset);
274
+ SHA512_W_L[i] = view.getUint32(offset += 4);
275
+ }
276
+ for (let i = 16; i < 80; i++) {
277
+ const W15h = SHA512_W_H[i - 15] | 0;
278
+ const W15l = SHA512_W_L[i - 15] | 0;
279
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
280
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
281
+ const W2h = SHA512_W_H[i - 2] | 0;
282
+ const W2l = SHA512_W_L[i - 2] | 0;
283
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
284
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
285
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
286
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
287
+ SHA512_W_H[i] = SUMh | 0;
288
+ SHA512_W_L[i] = SUMl | 0;
289
+ }
290
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
291
+ for (let i = 0; i < 80; i++) {
292
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
293
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
294
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
295
+ const CHIl = El & Fl ^ ~El & Gl;
296
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
297
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
298
+ const T1l = T1ll | 0;
299
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
300
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
301
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
302
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
303
+ Hh = Gh | 0;
304
+ Hl = Gl | 0;
305
+ Gh = Fh | 0;
306
+ Gl = Fl | 0;
307
+ Fh = Eh | 0;
308
+ Fl = El | 0;
309
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
310
+ Dh = Ch | 0;
311
+ Dl = Cl | 0;
312
+ Ch = Bh | 0;
313
+ Cl = Bl | 0;
314
+ Bh = Ah | 0;
315
+ Bl = Al | 0;
316
+ const All = add3L(T1l, sigma0l, MAJl);
317
+ Ah = add3H(All, T1h, sigma0h, MAJh);
318
+ Al = All | 0;
319
+ }
320
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
321
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
322
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
323
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
324
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
325
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
326
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
327
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
328
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
329
+ }
330
+ roundClean() {
331
+ clean(SHA512_W_H, SHA512_W_L);
332
+ }
333
+ destroy() {
334
+ clean(this.buffer);
335
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
336
+ }
337
+ }
338
+ const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
339
+ const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
340
+ export {
341
+ SHA256,
342
+ SHA512,
343
+ sha256,
344
+ sha512
345
+ };
346
+ //# sourceMappingURL=sha2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha2.js","sources":["../../../../../../node_modules/@noble/hashes/esm/sha2.js"],"sourcesContent":["/**\n * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.\n * SHA256 is the fastest hash implementable in JS, even faster than Blake3.\n * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and\n * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).\n * @module\n */\nimport { Chi, HashMD, Maj, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from \"./_md.js\";\nimport * as u64 from \"./_u64.js\";\nimport { clean, createHasher, rotr } from \"./utils.js\";\n/**\n * Round constants:\n * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)\n */\n// prettier-ignore\nconst SHA256_K = /* @__PURE__ */ Uint32Array.from([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n]);\n/** Reusable temporary buffer. \"W\" comes straight from spec. */\nconst SHA256_W = /* @__PURE__ */ new Uint32Array(64);\nexport class SHA256 extends HashMD {\n constructor(outputLen = 32) {\n super(64, outputLen, 8, false);\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n this.A = SHA256_IV[0] | 0;\n this.B = SHA256_IV[1] | 0;\n this.C = SHA256_IV[2] | 0;\n this.D = SHA256_IV[3] | 0;\n this.E = SHA256_IV[4] | 0;\n this.F = SHA256_IV[5] | 0;\n this.G = SHA256_IV[6] | 0;\n this.H = SHA256_IV[7] | 0;\n }\n get() {\n const { A, B, C, D, E, F, G, H } = this;\n return [A, B, C, D, E, F, G, H];\n }\n // prettier-ignore\n set(A, B, C, D, E, F, G, H) {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n this.E = E | 0;\n this.F = F | 0;\n this.G = G | 0;\n this.H = H | 0;\n }\n process(view, offset) {\n // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4)\n SHA256_W[i] = view.getUint32(offset, false);\n for (let i = 16; i < 64; i++) {\n const W15 = SHA256_W[i - 15];\n const W2 = SHA256_W[i - 2];\n const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);\n const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);\n SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;\n }\n // Compression function main loop, 64 rounds\n let { A, B, C, D, E, F, G, H } = this;\n for (let i = 0; i < 64; i++) {\n const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);\n const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);\n const T2 = (sigma0 + Maj(A, B, C)) | 0;\n H = G;\n G = F;\n F = E;\n E = (D + T1) | 0;\n D = C;\n C = B;\n B = A;\n A = (T1 + T2) | 0;\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n E = (E + this.E) | 0;\n F = (F + this.F) | 0;\n G = (G + this.G) | 0;\n H = (H + this.H) | 0;\n this.set(A, B, C, D, E, F, G, H);\n }\n roundClean() {\n clean(SHA256_W);\n }\n destroy() {\n this.set(0, 0, 0, 0, 0, 0, 0, 0);\n clean(this.buffer);\n }\n}\nexport class SHA224 extends SHA256 {\n constructor() {\n super(28);\n this.A = SHA224_IV[0] | 0;\n this.B = SHA224_IV[1] | 0;\n this.C = SHA224_IV[2] | 0;\n this.D = SHA224_IV[3] | 0;\n this.E = SHA224_IV[4] | 0;\n this.F = SHA224_IV[5] | 0;\n this.G = SHA224_IV[6] | 0;\n this.H = SHA224_IV[7] | 0;\n }\n}\n// SHA2-512 is slower than sha256 in js because u64 operations are slow.\n// Round contants\n// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409\n// prettier-ignore\nconst K512 = /* @__PURE__ */ (() => u64.split([\n '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',\n '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',\n '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',\n '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',\n '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',\n '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',\n '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',\n '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',\n '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',\n '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',\n '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',\n '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',\n '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',\n '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',\n '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',\n '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',\n '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',\n '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',\n '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',\n '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'\n].map(n => BigInt(n))))();\nconst SHA512_Kh = /* @__PURE__ */ (() => K512[0])();\nconst SHA512_Kl = /* @__PURE__ */ (() => K512[1])();\n// Reusable temporary buffers\nconst SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);\nconst SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);\nexport class SHA512 extends HashMD {\n constructor(outputLen = 64) {\n super(128, outputLen, 16, false);\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n // h -- high 32 bits, l -- low 32 bits\n this.Ah = SHA512_IV[0] | 0;\n this.Al = SHA512_IV[1] | 0;\n this.Bh = SHA512_IV[2] | 0;\n this.Bl = SHA512_IV[3] | 0;\n this.Ch = SHA512_IV[4] | 0;\n this.Cl = SHA512_IV[5] | 0;\n this.Dh = SHA512_IV[6] | 0;\n this.Dl = SHA512_IV[7] | 0;\n this.Eh = SHA512_IV[8] | 0;\n this.El = SHA512_IV[9] | 0;\n this.Fh = SHA512_IV[10] | 0;\n this.Fl = SHA512_IV[11] | 0;\n this.Gh = SHA512_IV[12] | 0;\n this.Gl = SHA512_IV[13] | 0;\n this.Hh = SHA512_IV[14] | 0;\n this.Hl = SHA512_IV[15] | 0;\n }\n // prettier-ignore\n get() {\n const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];\n }\n // prettier-ignore\n set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {\n this.Ah = Ah | 0;\n this.Al = Al | 0;\n this.Bh = Bh | 0;\n this.Bl = Bl | 0;\n this.Ch = Ch | 0;\n this.Cl = Cl | 0;\n this.Dh = Dh | 0;\n this.Dl = Dl | 0;\n this.Eh = Eh | 0;\n this.El = El | 0;\n this.Fh = Fh | 0;\n this.Fl = Fl | 0;\n this.Gh = Gh | 0;\n this.Gl = Gl | 0;\n this.Hh = Hh | 0;\n this.Hl = Hl | 0;\n }\n process(view, offset) {\n // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) {\n SHA512_W_H[i] = view.getUint32(offset);\n SHA512_W_L[i] = view.getUint32((offset += 4));\n }\n for (let i = 16; i < 80; i++) {\n // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)\n const W15h = SHA512_W_H[i - 15] | 0;\n const W15l = SHA512_W_L[i - 15] | 0;\n const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);\n const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);\n // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)\n const W2h = SHA512_W_H[i - 2] | 0;\n const W2l = SHA512_W_L[i - 2] | 0;\n const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);\n const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);\n // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];\n const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);\n const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);\n SHA512_W_H[i] = SUMh | 0;\n SHA512_W_L[i] = SUMl | 0;\n }\n let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n // Compression function main loop, 80 rounds\n for (let i = 0; i < 80; i++) {\n // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)\n const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);\n const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);\n //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const CHIh = (Eh & Fh) ^ (~Eh & Gh);\n const CHIl = (El & Fl) ^ (~El & Gl);\n // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]\n // prettier-ignore\n const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);\n const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);\n const T1l = T1ll | 0;\n // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)\n const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);\n const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);\n const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);\n const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);\n Hh = Gh | 0;\n Hl = Gl | 0;\n Gh = Fh | 0;\n Gl = Fl | 0;\n Fh = Eh | 0;\n Fl = El | 0;\n ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));\n Dh = Ch | 0;\n Dl = Cl | 0;\n Ch = Bh | 0;\n Cl = Bl | 0;\n Bh = Ah | 0;\n Bl = Al | 0;\n const All = u64.add3L(T1l, sigma0l, MAJl);\n Ah = u64.add3H(All, T1h, sigma0h, MAJh);\n Al = All | 0;\n }\n // Add the compressed chunk to the current hash value\n ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));\n ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));\n ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));\n ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));\n ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));\n ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));\n ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));\n ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));\n this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);\n }\n roundClean() {\n clean(SHA512_W_H, SHA512_W_L);\n }\n destroy() {\n clean(this.buffer);\n this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n }\n}\nexport class SHA384 extends SHA512 {\n constructor() {\n super(48);\n this.Ah = SHA384_IV[0] | 0;\n this.Al = SHA384_IV[1] | 0;\n this.Bh = SHA384_IV[2] | 0;\n this.Bl = SHA384_IV[3] | 0;\n this.Ch = SHA384_IV[4] | 0;\n this.Cl = SHA384_IV[5] | 0;\n this.Dh = SHA384_IV[6] | 0;\n this.Dl = SHA384_IV[7] | 0;\n this.Eh = SHA384_IV[8] | 0;\n this.El = SHA384_IV[9] | 0;\n this.Fh = SHA384_IV[10] | 0;\n this.Fl = SHA384_IV[11] | 0;\n this.Gh = SHA384_IV[12] | 0;\n this.Gl = SHA384_IV[13] | 0;\n this.Hh = SHA384_IV[14] | 0;\n this.Hl = SHA384_IV[15] | 0;\n }\n}\n/**\n * Truncated SHA512/256 and SHA512/224.\n * SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as \"intermediary\" IV of SHA512/t.\n * Then t hashes string to produce result IV.\n * See `test/misc/sha2-gen-iv.js`.\n */\n/** SHA512/224 IV */\nconst T224_IV = /* @__PURE__ */ Uint32Array.from([\n 0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,\n 0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,\n]);\n/** SHA512/256 IV */\nconst T256_IV = /* @__PURE__ */ Uint32Array.from([\n 0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,\n 0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,\n]);\nexport class SHA512_224 extends SHA512 {\n constructor() {\n super(28);\n this.Ah = T224_IV[0] | 0;\n this.Al = T224_IV[1] | 0;\n this.Bh = T224_IV[2] | 0;\n this.Bl = T224_IV[3] | 0;\n this.Ch = T224_IV[4] | 0;\n this.Cl = T224_IV[5] | 0;\n this.Dh = T224_IV[6] | 0;\n this.Dl = T224_IV[7] | 0;\n this.Eh = T224_IV[8] | 0;\n this.El = T224_IV[9] | 0;\n this.Fh = T224_IV[10] | 0;\n this.Fl = T224_IV[11] | 0;\n this.Gh = T224_IV[12] | 0;\n this.Gl = T224_IV[13] | 0;\n this.Hh = T224_IV[14] | 0;\n this.Hl = T224_IV[15] | 0;\n }\n}\nexport class SHA512_256 extends SHA512 {\n constructor() {\n super(32);\n this.Ah = T256_IV[0] | 0;\n this.Al = T256_IV[1] | 0;\n this.Bh = T256_IV[2] | 0;\n this.Bl = T256_IV[3] | 0;\n this.Ch = T256_IV[4] | 0;\n this.Cl = T256_IV[5] | 0;\n this.Dh = T256_IV[6] | 0;\n this.Dl = T256_IV[7] | 0;\n this.Eh = T256_IV[8] | 0;\n this.El = T256_IV[9] | 0;\n this.Fh = T256_IV[10] | 0;\n this.Fl = T256_IV[11] | 0;\n this.Gh = T256_IV[12] | 0;\n this.Gl = T256_IV[13] | 0;\n this.Hh = T256_IV[14] | 0;\n this.Hl = T256_IV[15] | 0;\n }\n}\n/**\n * SHA2-256 hash function from RFC 4634.\n *\n * It is the fastest JS hash, even faster than Blake3.\n * To break sha256 using birthday attack, attackers need to try 2^128 hashes.\n * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.\n */\nexport const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());\n/** SHA2-224 hash function from RFC 4634 */\nexport const sha224 = /* @__PURE__ */ createHasher(() => new SHA224());\n/** SHA2-512 hash function from RFC 4634. */\nexport const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());\n/** SHA2-384 hash function from RFC 4634. */\nexport const sha384 = /* @__PURE__ */ createHasher(() => new SHA384());\n/**\n * SHA2-512/256 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_256 = /* @__PURE__ */ createHasher(() => new SHA512_256());\n/**\n * SHA2-512/224 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_224 = /* @__PURE__ */ createHasher(() => new SHA512_224());\n//# sourceMappingURL=sha2.js.map"],"names":["u64.split","u64.rotrSH","u64.shrSH","u64.rotrSL","u64.shrSL","u64.rotrBH","u64.rotrBL","u64.add4L","u64.add4H","u64.add5L","u64.add5H","u64.add","u64.add3L","u64.add3H"],"mappings":";;;AAeA,MAAM,WAA2B,4BAAY,KAAK;AAAA,EAC9C;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EACpF;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EACpF;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EACpF;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EACpF;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EACpF;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;AAAA,EAAY;A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,IAAQ,KAAK,KAAK,GAAG,KAAK,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AACpE,KAAC,EAAE,GAAG,IAAI,GAAG,GAAE,IAAKA,IAAQ,KAAK,KAAK,GAAG,KAAK,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AACpE,SAAK,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;AAAA,EAC3E;AAAA,EACA,aAAa;AACT,UAAM,YAAY,UAAU;AAAA,EAChC;AAAA,EACA,UAAU;AACN,UAAM,KAAK,MAAM;AACjB,SAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAAA,EAC3D;AACJ;AAuFY,MAAC,SAAyB,6BAAa,MAAM,IAAI,OAAM,CAAE;AAIzD,MAAC,SAAyB,6BAAa,MAAM,IAAI,OAAM,CAAE;","x_google_ignoreList":[0]}
@@ -0,0 +1,73 @@
1
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
+ function isBytes(a) {
3
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
4
+ }
5
+ function abytes(b, ...lengths) {
6
+ if (!isBytes(b))
7
+ throw new Error("Uint8Array expected");
8
+ if (lengths.length > 0 && !lengths.includes(b.length))
9
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
10
+ }
11
+ function aexists(instance, checkFinished = true) {
12
+ if (instance.destroyed)
13
+ throw new Error("Hash instance has been destroyed");
14
+ if (checkFinished && instance.finished)
15
+ throw new Error("Hash#digest() has already been called");
16
+ }
17
+ function aoutput(out, instance) {
18
+ abytes(out);
19
+ const min = instance.outputLen;
20
+ if (out.length < min) {
21
+ throw new Error("digestInto() expects output buffer of length at least " + min);
22
+ }
23
+ }
24
+ function clean(...arrays) {
25
+ for (let i = 0; i < arrays.length; i++) {
26
+ arrays[i].fill(0);
27
+ }
28
+ }
29
+ function createView(arr) {
30
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
31
+ }
32
+ function rotr(word, shift) {
33
+ return word << 32 - shift | word >>> shift;
34
+ }
35
+ function rotl(word, shift) {
36
+ return word << shift | word >>> 32 - shift >>> 0;
37
+ }
38
+ function utf8ToBytes(str) {
39
+ if (typeof str !== "string")
40
+ throw new Error("string expected");
41
+ return new Uint8Array(new TextEncoder().encode(str));
42
+ }
43
+ function toBytes(data) {
44
+ if (typeof data === "string")
45
+ data = utf8ToBytes(data);
46
+ abytes(data);
47
+ return data;
48
+ }
49
+ class Hash {
50
+ }
51
+ function createHasher(hashCons) {
52
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
53
+ const tmp = hashCons();
54
+ hashC.outputLen = tmp.outputLen;
55
+ hashC.blockLen = tmp.blockLen;
56
+ hashC.create = () => hashCons();
57
+ return hashC;
58
+ }
59
+ export {
60
+ Hash,
61
+ abytes,
62
+ aexists,
63
+ aoutput,
64
+ clean,
65
+ createHasher,
66
+ createView,
67
+ isBytes,
68
+ rotl,
69
+ rotr,
70
+ toBytes,
71
+ utf8ToBytes
72
+ };
73
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../../../node_modules/@noble/hashes/esm/utils.js"],"sourcesContent":["/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a) {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n/** Asserts something is positive integer. */\nexport function anumber(n) {\n if (!Number.isSafeInteger(n) || n < 0)\n throw new Error('positive integer expected, got ' + n);\n}\n/** Asserts something is Uint8Array. */\nexport function abytes(b, ...lengths) {\n if (!isBytes(b))\n throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n/** Asserts something is hash */\nexport function ahash(h) {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance, checkFinished = true) {\n if (instance.destroyed)\n throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished)\n throw new Error('Hash#digest() has already been called');\n}\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out, instance) {\n abytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('digestInto() expects output buffer of length at least ' + min);\n }\n}\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr) {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr) {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays) {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr) {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word, shift) {\n return (word << (32 - shift)) | (word >>> shift);\n}\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word, shift) {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n/** The byte swap operation for uint32 */\nexport function byteSwap(word) {\n return (((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff));\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE = isLE\n ? (n) => n\n : (n) => byteSwap(n);\n/** @deprecated */\nexport const byteSwapIfBE = swap8IfBE;\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr) {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\nexport const swap32IfBE = isLE\n ? (u) => u\n : byteSwap32;\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin = /* @__PURE__ */ (() => \n// @ts-ignore\ntypeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes) {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin)\n return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };\nfunction asciiToBase16(ch) {\n if (ch >= asciis._0 && ch <= asciis._9)\n return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F)\n return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f)\n return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex) {\n if (typeof hex !== 'string')\n throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin)\n return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2)\n throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async () => { };\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(iters, tick, cb) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick)\n continue;\n await nextTick();\n ts += diff;\n }\n}\n/**\n * Converts string to bytes using UTF8 encoding.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str) {\n if (typeof str !== 'string')\n throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n/**\n * Converts bytes to string using UTF8 encoding.\n * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'\n */\nexport function bytesToUtf8(bytes) {\n return new TextDecoder().decode(bytes);\n}\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data) {\n if (typeof data === 'string')\n data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data) {\n if (typeof data === 'string')\n data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays) {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\nexport function checkOpts(defaults, opts) {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged;\n}\n/** For runtime check if class implements interface */\nexport class Hash {\n}\n/** Wraps hash function, creating an interface on top of it */\nexport function createHasher(hashCons) {\n const hashC = (msg) => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\nexport function createOptHasher(hashCons) {\n const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({});\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts) => hashCons(opts);\n return hashC;\n}\nexport function createXOFer(hashCons) {\n const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({});\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts) => hashCons(opts);\n return hashC;\n}\nexport const wrapConstructor = createHasher;\nexport const wrapConstructorWithOpts = createOptHasher;\nexport const wrapXOFConstructorWithOpts = createXOFer;\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32) {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return Uint8Array.from(crypto.randomBytes(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n//# sourceMappingURL=utils.js.map"],"names":[],"mappings":"AAIA;AASO,SAAS,QAAQ,GAAG;AACvB,SAAO,aAAa,cAAe,YAAY,OAAO,CAAC,KAAK,EAAE,YAAY,SAAS;AACvF;AAOO,SAAS,OAAO,MAAM,SAAS;AAClC,MAAI,CAAC,QAAQ,CAAC;AACV,UAAM,IAAI,MAAM,qBAAqB;AACzC,MAAI,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAAS,EAAE,MAAM;AAChD,UAAM,IAAI,MAAM,mCAAmC,UAAU,kBAAkB,EAAE,MAAM;AAC/F;AASO,SAAS,QAAQ,UAAU,gBAAgB,MAAM;AACpD,MAAI,SAAS;AACT,UAAM,IAAI,MAAM,kCAAkC;AACtD,MAAI,iBAAiB,SAAS;AAC1B,UAAM,IAAI,MAAM,uCAAuC;AAC/D;AAEO,SAAS,QAAQ,KAAK,UAAU;AACnC,SAAO,GAAG;AACV,QAAM,MAAM,SAAS;AACrB,MAAI,IAAI,SAAS,KAAK;AAClB,UAAM,IAAI,MAAM,2DAA2D,GAAG;AAAA,EAClF;AACJ;AAUO,SAAS,SAAS,QAAQ;AAC7B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACpC,WAAO,CAAC,EAAE,KAAK,CAAC;AAAA,EACpB;AACJ;AAEO,SAAS,WAAW,KAAK;A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