@capxul/cli 4.20.0-beta.3 → 4.20.0-beta.31
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.
- package/README.md +1159 -21
- package/dist/browser/GeistVF.woff +0 -0
- package/dist/browser/signer.js +85954 -0
- package/dist/browser/signer.js.map +1 -0
- package/dist/entry-CmnyAyYp.mjs +46446 -0
- package/dist/entry-CmnyAyYp.mjs.map +1 -0
- package/dist/fast-Dvf2EM7j.mjs +57 -0
- package/dist/fast-Dvf2EM7j.mjs.map +1 -0
- package/dist/{lib-BOge5QZP.mjs → lib-5nM6ORJd.mjs} +5 -4
- package/dist/{lib-BOge5QZP.mjs.map → lib-5nM6ORJd.mjs.map} +1 -1
- package/dist/{lib-DH_xJGSE.mjs → lib-BJgR4mWJ.mjs} +6 -5
- package/dist/{lib-DH_xJGSE.mjs.map → lib-BJgR4mWJ.mjs.map} +1 -1
- package/dist/lib-BlUleR2B.mjs +3 -0
- package/dist/{lib-C8ENT9j6.mjs → lib-BspI667y.mjs} +7 -6
- package/dist/{lib-C8ENT9j6.mjs.map → lib-BspI667y.mjs.map} +1 -1
- package/dist/{lib-C4fpnzyy.mjs → lib-Buegx0dz.mjs} +6 -5
- package/dist/{lib-C4fpnzyy.mjs.map → lib-Buegx0dz.mjs.map} +1 -1
- package/dist/{lib-DVGoRCJN.mjs → lib-CJw8te9L.mjs} +38 -38
- package/dist/{lib-DVGoRCJN.mjs.map → lib-CJw8te9L.mjs.map} +1 -1
- package/dist/lib-C_-etuHZ.mjs +3 -0
- package/dist/lib-CoGPQsbr.mjs +655 -0
- package/dist/lib-CoGPQsbr.mjs.map +1 -0
- package/dist/lib-Dd_fsz7h.mjs +3 -0
- package/dist/lib-DnmstTkB.mjs +578 -0
- package/dist/lib-DnmstTkB.mjs.map +1 -0
- package/dist/lib-IlYdzOHo.mjs +3 -0
- package/dist/main.mjs +22 -51062
- package/dist/main.mjs.map +1 -1
- package/dist/organizations-CbmvwYH7.mjs +37607 -0
- package/dist/organizations-CbmvwYH7.mjs.map +1 -0
- package/dist/permission-approvals-CKzN6tEO.mjs +139 -0
- package/dist/permission-approvals-CKzN6tEO.mjs.map +1 -0
- package/dist/record-U7Yu4KQP.mjs +1295 -0
- package/dist/record-U7Yu4KQP.mjs.map +1 -0
- package/dist/{secp256k1-Cc9JhcTQ.mjs → secp256k1-D8L212-Z.mjs} +5 -298
- package/dist/secp256k1-D8L212-Z.mjs.map +1 -0
- package/dist/sha2-CR2DnMEk.mjs +298 -0
- package/dist/sha2-CR2DnMEk.mjs.map +1 -0
- package/dist/utils-DmKXBQjM.mjs +130 -0
- package/dist/utils-DmKXBQjM.mjs.map +1 -0
- package/dist/where-view-DuGbrSLp.mjs +1420 -0
- package/dist/where-view-DuGbrSLp.mjs.map +1 -0
- package/package.json +18 -10
- package/dist/secp256k1-Cc9JhcTQ.mjs.map +0 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { f as rotr, l as createHasher, m as toBytes, n as abytes, o as aoutput, r as aexists, s as clean, t as Hash, u as createView } from "./utils-DmKXBQjM.mjs";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
|
|
3
|
+
/**
|
|
4
|
+
* Internal Merkle-Damgard hash utils.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
|
8
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
9
|
+
if (typeof view.setBigUint64 === "function") return view.setBigUint64(byteOffset, value, isLE);
|
|
10
|
+
const _32n = BigInt(32);
|
|
11
|
+
const _u32_max = BigInt(4294967295);
|
|
12
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
13
|
+
const wl = Number(value & _u32_max);
|
|
14
|
+
const h = isLE ? 4 : 0;
|
|
15
|
+
const l = isLE ? 0 : 4;
|
|
16
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
17
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
18
|
+
}
|
|
19
|
+
/** Choice: a ? b : c */
|
|
20
|
+
function Chi(a, b, c) {
|
|
21
|
+
return a & b ^ ~a & c;
|
|
22
|
+
}
|
|
23
|
+
/** Majority function, true if any two inputs is true. */
|
|
24
|
+
function Maj(a, b, c) {
|
|
25
|
+
return a & b ^ a & c ^ b & c;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Merkle-Damgard hash construction base class.
|
|
29
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
30
|
+
*/
|
|
31
|
+
var HashMD = class extends Hash {
|
|
32
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
33
|
+
super();
|
|
34
|
+
this.finished = false;
|
|
35
|
+
this.length = 0;
|
|
36
|
+
this.pos = 0;
|
|
37
|
+
this.destroyed = false;
|
|
38
|
+
this.blockLen = blockLen;
|
|
39
|
+
this.outputLen = outputLen;
|
|
40
|
+
this.padOffset = padOffset;
|
|
41
|
+
this.isLE = isLE;
|
|
42
|
+
this.buffer = new Uint8Array(blockLen);
|
|
43
|
+
this.view = createView(this.buffer);
|
|
44
|
+
}
|
|
45
|
+
update(data) {
|
|
46
|
+
aexists(this);
|
|
47
|
+
data = toBytes(data);
|
|
48
|
+
abytes(data);
|
|
49
|
+
const { view, buffer, blockLen } = this;
|
|
50
|
+
const len = data.length;
|
|
51
|
+
for (let pos = 0; pos < len;) {
|
|
52
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
53
|
+
if (take === blockLen) {
|
|
54
|
+
const dataView = createView(data);
|
|
55
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
59
|
+
this.pos += take;
|
|
60
|
+
pos += take;
|
|
61
|
+
if (this.pos === blockLen) {
|
|
62
|
+
this.process(view, 0);
|
|
63
|
+
this.pos = 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.length += data.length;
|
|
67
|
+
this.roundClean();
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
digestInto(out) {
|
|
71
|
+
aexists(this);
|
|
72
|
+
aoutput(out, this);
|
|
73
|
+
this.finished = true;
|
|
74
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
75
|
+
let { pos } = this;
|
|
76
|
+
buffer[pos++] = 128;
|
|
77
|
+
clean(this.buffer.subarray(pos));
|
|
78
|
+
if (this.padOffset > blockLen - pos) {
|
|
79
|
+
this.process(view, 0);
|
|
80
|
+
pos = 0;
|
|
81
|
+
}
|
|
82
|
+
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
83
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
84
|
+
this.process(view, 0);
|
|
85
|
+
const oview = createView(out);
|
|
86
|
+
const len = this.outputLen;
|
|
87
|
+
if (len % 4) 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) throw new Error("_sha2: outputLen bigger than state");
|
|
91
|
+
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
92
|
+
}
|
|
93
|
+
digest() {
|
|
94
|
+
const { buffer, outputLen } = this;
|
|
95
|
+
this.digestInto(buffer);
|
|
96
|
+
const res = buffer.slice(0, outputLen);
|
|
97
|
+
this.destroy();
|
|
98
|
+
return res;
|
|
99
|
+
}
|
|
100
|
+
_cloneInto(to) {
|
|
101
|
+
to || (to = new this.constructor());
|
|
102
|
+
to.set(...this.get());
|
|
103
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
104
|
+
to.destroyed = destroyed;
|
|
105
|
+
to.finished = finished;
|
|
106
|
+
to.length = length;
|
|
107
|
+
to.pos = pos;
|
|
108
|
+
if (length % blockLen) to.buffer.set(buffer);
|
|
109
|
+
return to;
|
|
110
|
+
}
|
|
111
|
+
clone() {
|
|
112
|
+
return this._cloneInto();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
117
|
+
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
118
|
+
*/
|
|
119
|
+
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
120
|
+
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
121
|
+
1779033703,
|
|
122
|
+
3144134277,
|
|
123
|
+
1013904242,
|
|
124
|
+
2773480762,
|
|
125
|
+
1359893119,
|
|
126
|
+
2600822924,
|
|
127
|
+
528734635,
|
|
128
|
+
1541459225
|
|
129
|
+
]);
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
|
|
132
|
+
/**
|
|
133
|
+
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
134
|
+
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
135
|
+
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
136
|
+
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
137
|
+
* @module
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* Round constants:
|
|
141
|
+
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
|
|
142
|
+
*/
|
|
143
|
+
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
144
|
+
1116352408,
|
|
145
|
+
1899447441,
|
|
146
|
+
3049323471,
|
|
147
|
+
3921009573,
|
|
148
|
+
961987163,
|
|
149
|
+
1508970993,
|
|
150
|
+
2453635748,
|
|
151
|
+
2870763221,
|
|
152
|
+
3624381080,
|
|
153
|
+
310598401,
|
|
154
|
+
607225278,
|
|
155
|
+
1426881987,
|
|
156
|
+
1925078388,
|
|
157
|
+
2162078206,
|
|
158
|
+
2614888103,
|
|
159
|
+
3248222580,
|
|
160
|
+
3835390401,
|
|
161
|
+
4022224774,
|
|
162
|
+
264347078,
|
|
163
|
+
604807628,
|
|
164
|
+
770255983,
|
|
165
|
+
1249150122,
|
|
166
|
+
1555081692,
|
|
167
|
+
1996064986,
|
|
168
|
+
2554220882,
|
|
169
|
+
2821834349,
|
|
170
|
+
2952996808,
|
|
171
|
+
3210313671,
|
|
172
|
+
3336571891,
|
|
173
|
+
3584528711,
|
|
174
|
+
113926993,
|
|
175
|
+
338241895,
|
|
176
|
+
666307205,
|
|
177
|
+
773529912,
|
|
178
|
+
1294757372,
|
|
179
|
+
1396182291,
|
|
180
|
+
1695183700,
|
|
181
|
+
1986661051,
|
|
182
|
+
2177026350,
|
|
183
|
+
2456956037,
|
|
184
|
+
2730485921,
|
|
185
|
+
2820302411,
|
|
186
|
+
3259730800,
|
|
187
|
+
3345764771,
|
|
188
|
+
3516065817,
|
|
189
|
+
3600352804,
|
|
190
|
+
4094571909,
|
|
191
|
+
275423344,
|
|
192
|
+
430227734,
|
|
193
|
+
506948616,
|
|
194
|
+
659060556,
|
|
195
|
+
883997877,
|
|
196
|
+
958139571,
|
|
197
|
+
1322822218,
|
|
198
|
+
1537002063,
|
|
199
|
+
1747873779,
|
|
200
|
+
1955562222,
|
|
201
|
+
2024104815,
|
|
202
|
+
2227730452,
|
|
203
|
+
2361852424,
|
|
204
|
+
2428436474,
|
|
205
|
+
2756734187,
|
|
206
|
+
3204031479,
|
|
207
|
+
3329325298
|
|
208
|
+
]);
|
|
209
|
+
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
210
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
211
|
+
var SHA256 = class extends HashMD {
|
|
212
|
+
constructor(outputLen = 32) {
|
|
213
|
+
super(64, outputLen, 8, false);
|
|
214
|
+
this.A = SHA256_IV[0] | 0;
|
|
215
|
+
this.B = SHA256_IV[1] | 0;
|
|
216
|
+
this.C = SHA256_IV[2] | 0;
|
|
217
|
+
this.D = SHA256_IV[3] | 0;
|
|
218
|
+
this.E = SHA256_IV[4] | 0;
|
|
219
|
+
this.F = SHA256_IV[5] | 0;
|
|
220
|
+
this.G = SHA256_IV[6] | 0;
|
|
221
|
+
this.H = SHA256_IV[7] | 0;
|
|
222
|
+
}
|
|
223
|
+
get() {
|
|
224
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
225
|
+
return [
|
|
226
|
+
A,
|
|
227
|
+
B,
|
|
228
|
+
C,
|
|
229
|
+
D,
|
|
230
|
+
E,
|
|
231
|
+
F,
|
|
232
|
+
G,
|
|
233
|
+
H
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
set(A, B, C, D, E, F, G, H) {
|
|
237
|
+
this.A = A | 0;
|
|
238
|
+
this.B = B | 0;
|
|
239
|
+
this.C = C | 0;
|
|
240
|
+
this.D = D | 0;
|
|
241
|
+
this.E = E | 0;
|
|
242
|
+
this.F = F | 0;
|
|
243
|
+
this.G = G | 0;
|
|
244
|
+
this.H = H | 0;
|
|
245
|
+
}
|
|
246
|
+
process(view, offset) {
|
|
247
|
+
for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
|
|
248
|
+
for (let i = 16; i < 64; i++) {
|
|
249
|
+
const W15 = SHA256_W[i - 15];
|
|
250
|
+
const W2 = SHA256_W[i - 2];
|
|
251
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
252
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
253
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
254
|
+
}
|
|
255
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
256
|
+
for (let i = 0; i < 64; i++) {
|
|
257
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
258
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
259
|
+
const T2 = (rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22)) + Maj(A, B, C) | 0;
|
|
260
|
+
H = G;
|
|
261
|
+
G = F;
|
|
262
|
+
F = E;
|
|
263
|
+
E = D + T1 | 0;
|
|
264
|
+
D = C;
|
|
265
|
+
C = B;
|
|
266
|
+
B = A;
|
|
267
|
+
A = T1 + T2 | 0;
|
|
268
|
+
}
|
|
269
|
+
A = A + this.A | 0;
|
|
270
|
+
B = B + this.B | 0;
|
|
271
|
+
C = C + this.C | 0;
|
|
272
|
+
D = D + this.D | 0;
|
|
273
|
+
E = E + this.E | 0;
|
|
274
|
+
F = F + this.F | 0;
|
|
275
|
+
G = G + this.G | 0;
|
|
276
|
+
H = H + this.H | 0;
|
|
277
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
278
|
+
}
|
|
279
|
+
roundClean() {
|
|
280
|
+
clean(SHA256_W);
|
|
281
|
+
}
|
|
282
|
+
destroy() {
|
|
283
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
284
|
+
clean(this.buffer);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* SHA2-256 hash function from RFC 4634.
|
|
289
|
+
*
|
|
290
|
+
* It is the fastest JS hash, even faster than Blake3.
|
|
291
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
292
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
293
|
+
*/
|
|
294
|
+
const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
295
|
+
//#endregion
|
|
296
|
+
export { sha256 as t };
|
|
297
|
+
|
|
298
|
+
//# sourceMappingURL=sha2-CR2DnMEk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha2-CR2DnMEk.mjs","names":[],"sources":["../../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js","../../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js"],"sourcesContent":["/**\n * Internal Merkle-Damgard hash utils.\n * @module\n */\nimport { Hash, abytes, aexists, aoutput, clean, createView, toBytes } from \"./utils.js\";\n/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */\nexport function setBigUint64(view, byteOffset, value, isLE) {\n if (typeof view.setBigUint64 === 'function')\n return view.setBigUint64(byteOffset, value, isLE);\n const _32n = BigInt(32);\n const _u32_max = BigInt(0xffffffff);\n const wh = Number((value >> _32n) & _u32_max);\n const wl = Number(value & _u32_max);\n const h = isLE ? 4 : 0;\n const l = isLE ? 0 : 4;\n view.setUint32(byteOffset + h, wh, isLE);\n view.setUint32(byteOffset + l, wl, isLE);\n}\n/** Choice: a ? b : c */\nexport function Chi(a, b, c) {\n return (a & b) ^ (~a & c);\n}\n/** Majority function, true if any two inputs is true. */\nexport function Maj(a, b, c) {\n return (a & b) ^ (a & c) ^ (b & c);\n}\n/**\n * Merkle-Damgard hash construction base class.\n * Could be used to create MD5, RIPEMD, SHA1, SHA2.\n */\nexport class HashMD extends Hash {\n constructor(blockLen, outputLen, padOffset, isLE) {\n super();\n this.finished = false;\n this.length = 0;\n this.pos = 0;\n this.destroyed = false;\n this.blockLen = blockLen;\n this.outputLen = outputLen;\n this.padOffset = padOffset;\n this.isLE = isLE;\n this.buffer = new Uint8Array(blockLen);\n this.view = createView(this.buffer);\n }\n update(data) {\n aexists(this);\n data = toBytes(data);\n abytes(data);\n const { view, buffer, blockLen } = this;\n const len = data.length;\n for (let pos = 0; pos < len;) {\n const take = Math.min(blockLen - this.pos, len - pos);\n // Fast path: we have at least one block in input, cast it to view and process\n if (take === blockLen) {\n const dataView = createView(data);\n for (; blockLen <= len - pos; pos += blockLen)\n this.process(dataView, pos);\n continue;\n }\n buffer.set(data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n pos += take;\n if (this.pos === blockLen) {\n this.process(view, 0);\n this.pos = 0;\n }\n }\n this.length += data.length;\n this.roundClean();\n return this;\n }\n digestInto(out) {\n aexists(this);\n aoutput(out, this);\n this.finished = true;\n // Padding\n // We can avoid allocation of buffer for padding completely if it\n // was previously not allocated here. But it won't change performance.\n const { buffer, view, blockLen, isLE } = this;\n let { pos } = this;\n // append the bit '1' to the message\n buffer[pos++] = 0b10000000;\n clean(this.buffer.subarray(pos));\n // we have less than padOffset left in buffer, so we cannot put length in\n // current block, need process it and pad again\n if (this.padOffset > blockLen - pos) {\n this.process(view, 0);\n pos = 0;\n }\n // Pad until full block byte with zeros\n for (let i = pos; i < blockLen; i++)\n buffer[i] = 0;\n // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that\n // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.\n // So we just write lowest 64 bits of that value.\n setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);\n this.process(view, 0);\n const oview = createView(out);\n const len = this.outputLen;\n // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT\n if (len % 4)\n throw new Error('_sha2: outputLen should be aligned to 32bit');\n const outLen = len / 4;\n const state = this.get();\n if (outLen > state.length)\n throw new Error('_sha2: outputLen bigger than state');\n for (let i = 0; i < outLen; i++)\n oview.setUint32(4 * i, state[i], isLE);\n }\n digest() {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneInto(to) {\n to || (to = new this.constructor());\n to.set(...this.get());\n const { blockLen, buffer, length, finished, destroyed, pos } = this;\n to.destroyed = destroyed;\n to.finished = finished;\n to.length = length;\n to.pos = pos;\n if (length % blockLen)\n to.buffer.set(buffer);\n return to;\n }\n clone() {\n return this._cloneInto();\n }\n}\n/**\n * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.\n * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.\n */\n/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */\nexport const SHA256_IV = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n]);\n/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */\nexport const SHA224_IV = /* @__PURE__ */ Uint32Array.from([\n 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,\n]);\n/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */\nexport const SHA384_IV = /* @__PURE__ */ Uint32Array.from([\n 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,\n 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,\n]);\n/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */\nexport const SHA512_IV = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,\n 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,\n]);\n//# sourceMappingURL=_md.js.map","/**\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"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;AAMA,SAAgB,aAAa,MAAM,YAAY,OAAO,MAAM;CACxD,IAAI,OAAO,KAAK,iBAAiB,YAC7B,OAAO,KAAK,aAAa,YAAY,OAAO,IAAI;CACpD,MAAM,OAAO,OAAO,EAAE;CACtB,MAAM,WAAW,OAAO,UAAU;CAClC,MAAM,KAAK,OAAQ,SAAS,OAAQ,QAAQ;CAC5C,MAAM,KAAK,OAAO,QAAQ,QAAQ;CAClC,MAAM,IAAI,OAAO,IAAI;CACrB,MAAM,IAAI,OAAO,IAAI;CACrB,KAAK,UAAU,aAAa,GAAG,IAAI,IAAI;CACvC,KAAK,UAAU,aAAa,GAAG,IAAI,IAAI;AAC3C;;AAEA,SAAgB,IAAI,GAAG,GAAG,GAAG;CACzB,OAAQ,IAAI,IAAM,CAAC,IAAI;AAC3B;;AAEA,SAAgB,IAAI,GAAG,GAAG,GAAG;CACzB,OAAQ,IAAI,IAAM,IAAI,IAAM,IAAI;AACpC;;;;;AAKA,IAAa,SAAb,cAA4B,KAAK;CAC7B,YAAY,UAAU,WAAW,WAAW,MAAM;EAC9C,MAAM;EACN,KAAK,WAAW;EAChB,KAAK,SAAS;EACd,KAAK,MAAM;EACX,KAAK,YAAY;EACjB,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,KAAK,YAAY;EACjB,KAAK,OAAO;E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
|
+
* Internal webcrypto alias.
|
|
5
|
+
* We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+.
|
|
6
|
+
* Falls back to Node.js built-in crypto for Node.js <=v14.
|
|
7
|
+
* See utils.ts for details.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
const crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
|
|
13
|
+
/**
|
|
14
|
+
* Utilities for hex, bytes, CSPRNG.
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
18
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
19
|
+
function isBytes(a) {
|
|
20
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
21
|
+
}
|
|
22
|
+
/** Asserts something is positive integer. */
|
|
23
|
+
function anumber(n) {
|
|
24
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error("positive integer expected, got " + n);
|
|
25
|
+
}
|
|
26
|
+
/** Asserts something is Uint8Array. */
|
|
27
|
+
function abytes(b, ...lengths) {
|
|
28
|
+
if (!isBytes(b)) throw new Error("Uint8Array expected");
|
|
29
|
+
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
30
|
+
}
|
|
31
|
+
/** Asserts something is hash */
|
|
32
|
+
function ahash(h) {
|
|
33
|
+
if (typeof h !== "function" || typeof h.create !== "function") throw new Error("Hash should be wrapped by utils.createHasher");
|
|
34
|
+
anumber(h.outputLen);
|
|
35
|
+
anumber(h.blockLen);
|
|
36
|
+
}
|
|
37
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
|
38
|
+
function aexists(instance, checkFinished = true) {
|
|
39
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
40
|
+
if (checkFinished && instance.finished) 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) throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
47
|
+
}
|
|
48
|
+
/** Cast u8 / u16 / u32 to u32. */
|
|
49
|
+
function u32(arr) {
|
|
50
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
51
|
+
}
|
|
52
|
+
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
53
|
+
function clean(...arrays) {
|
|
54
|
+
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
55
|
+
}
|
|
56
|
+
/** Create DataView of an array for easy byte-level manipulation. */
|
|
57
|
+
function createView(arr) {
|
|
58
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
59
|
+
}
|
|
60
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
|
61
|
+
function rotr(word, shift) {
|
|
62
|
+
return word << 32 - shift | word >>> shift;
|
|
63
|
+
}
|
|
64
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
65
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
66
|
+
/** The byte swap operation for uint32 */
|
|
67
|
+
function byteSwap(word) {
|
|
68
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
69
|
+
}
|
|
70
|
+
/** In place byte swap for Uint32Array */
|
|
71
|
+
function byteSwap32(arr) {
|
|
72
|
+
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
73
|
+
return arr;
|
|
74
|
+
}
|
|
75
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
76
|
+
/**
|
|
77
|
+
* Converts string to bytes using UTF8 encoding.
|
|
78
|
+
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
79
|
+
*/
|
|
80
|
+
function utf8ToBytes(str) {
|
|
81
|
+
if (typeof str !== "string") throw new Error("string expected");
|
|
82
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
86
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
87
|
+
* Keep in mind for future mutable operations.
|
|
88
|
+
*/
|
|
89
|
+
function toBytes(data) {
|
|
90
|
+
if (typeof data === "string") data = utf8ToBytes(data);
|
|
91
|
+
abytes(data);
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
/** Copies several Uint8Arrays into one. */
|
|
95
|
+
function concatBytes(...arrays) {
|
|
96
|
+
let sum = 0;
|
|
97
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
98
|
+
const a = arrays[i];
|
|
99
|
+
abytes(a);
|
|
100
|
+
sum += a.length;
|
|
101
|
+
}
|
|
102
|
+
const res = new Uint8Array(sum);
|
|
103
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
104
|
+
const a = arrays[i];
|
|
105
|
+
res.set(a, pad);
|
|
106
|
+
pad += a.length;
|
|
107
|
+
}
|
|
108
|
+
return res;
|
|
109
|
+
}
|
|
110
|
+
/** For runtime check if class implements interface */
|
|
111
|
+
var Hash = class {};
|
|
112
|
+
/** Wraps hash function, creating an interface on top of it */
|
|
113
|
+
function createHasher(hashCons) {
|
|
114
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
115
|
+
const tmp = hashCons();
|
|
116
|
+
hashC.outputLen = tmp.outputLen;
|
|
117
|
+
hashC.blockLen = tmp.blockLen;
|
|
118
|
+
hashC.create = () => hashCons();
|
|
119
|
+
return hashC;
|
|
120
|
+
}
|
|
121
|
+
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
122
|
+
function randomBytes$1(bytesLength = 32) {
|
|
123
|
+
if (crypto && typeof crypto.getRandomValues === "function") return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
124
|
+
if (crypto && typeof crypto.randomBytes === "function") return Uint8Array.from(crypto.randomBytes(bytesLength));
|
|
125
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { anumber as a, concatBytes as c, randomBytes$1 as d, rotr as f, u32 as h, ahash as i, createHasher as l, toBytes as m, abytes as n, aoutput as o, swap32IfBE as p, aexists as r, clean as s, Hash as t, createView as u };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=utils-DmKXBQjM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DmKXBQjM.mjs","names":["randomBytes"],"sources":["../../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/cryptoNode.js","../../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js"],"sourcesContent":["/**\n * Internal webcrypto alias.\n * We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+.\n * Falls back to Node.js built-in crypto for Node.js <=v14.\n * See utils.ts for details.\n * @module\n */\n// @ts-ignore\nimport * as nc from 'node:crypto';\nexport const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc\n ? nc.webcrypto\n : nc && typeof nc === 'object' && 'randomBytes' in nc\n ? nc\n : undefined;\n//# sourceMappingURL=cryptoNode.js.map","/**\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"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;;AASA,MAAa,SAAS,MAAM,OAAO,OAAO,YAAY,eAAe,KAC/D,GAAG,YACH,MAAM,OAAO,OAAO,YAAY,iBAAiB,KAC7C,KACA,KAAA;;;;;;;;;ACAV,SAAgB,QAAQ,GAAG;CACvB,OAAO,aAAa,cAAe,YAAY,OAAO,CAAC,KAAK,EAAE,YAAY,SAAS;AACvF;;AAEA,SAAgB,QAAQ,GAAG;CACvB,IAAI,CAAC,OAAO,cAAc,CAAC,KAAK,IAAI,GAChC,MAAM,IAAI,MAAM,oCAAoC,CAAC;AAC7D;;AAEA,SAAgB,OAAO,GAAG,GAAG,SAAS;CAClC,IAAI,CAAC,QAAQ,CAAC,GACV,MAAM,IAAI,MAAM,qBAAqB;CACzC,IAAI,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAAS,EAAE,MAAM,GAChD,MAAM,IAAI,MAAM,mCAAmC,UAAU,kBAAkB,EAAE,MAAM;AAC/F;;AAEA,SA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