protect-mcp 0.7.6 → 0.9.2

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.
@@ -0,0 +1,568 @@
1
+ import {
2
+ Hash,
3
+ abytes,
4
+ aexists,
5
+ aoutput,
6
+ clean,
7
+ createHasher,
8
+ createView,
9
+ rotr,
10
+ toBytes
11
+ } from "./chunk-D733KAPG.mjs";
12
+
13
+ // node_modules/@noble/hashes/esm/_md.js
14
+ function setBigUint64(view, byteOffset, value, isLE) {
15
+ if (typeof view.setBigUint64 === "function")
16
+ return view.setBigUint64(byteOffset, value, isLE);
17
+ const _32n2 = BigInt(32);
18
+ const _u32_max = BigInt(4294967295);
19
+ const wh = Number(value >> _32n2 & _u32_max);
20
+ const wl = Number(value & _u32_max);
21
+ const h = isLE ? 4 : 0;
22
+ const l = isLE ? 0 : 4;
23
+ view.setUint32(byteOffset + h, wh, isLE);
24
+ view.setUint32(byteOffset + l, wl, isLE);
25
+ }
26
+ function Chi(a, b, c) {
27
+ return a & b ^ ~a & c;
28
+ }
29
+ function Maj(a, b, c) {
30
+ return a & b ^ a & c ^ b & c;
31
+ }
32
+ var HashMD = class extends Hash {
33
+ constructor(blockLen, outputLen, padOffset, isLE) {
34
+ super();
35
+ this.finished = false;
36
+ this.length = 0;
37
+ this.pos = 0;
38
+ this.destroyed = false;
39
+ this.blockLen = blockLen;
40
+ this.outputLen = outputLen;
41
+ this.padOffset = padOffset;
42
+ this.isLE = isLE;
43
+ this.buffer = new Uint8Array(blockLen);
44
+ this.view = createView(this.buffer);
45
+ }
46
+ update(data) {
47
+ aexists(this);
48
+ data = toBytes(data);
49
+ abytes(data);
50
+ const { view, buffer, blockLen } = this;
51
+ const len = data.length;
52
+ for (let pos = 0; pos < len; ) {
53
+ const take = Math.min(blockLen - this.pos, len - pos);
54
+ if (take === blockLen) {
55
+ const dataView = createView(data);
56
+ for (; blockLen <= len - pos; pos += blockLen)
57
+ this.process(dataView, pos);
58
+ continue;
59
+ }
60
+ buffer.set(data.subarray(pos, pos + take), this.pos);
61
+ this.pos += take;
62
+ pos += take;
63
+ if (this.pos === blockLen) {
64
+ this.process(view, 0);
65
+ this.pos = 0;
66
+ }
67
+ }
68
+ this.length += data.length;
69
+ this.roundClean();
70
+ return this;
71
+ }
72
+ digestInto(out) {
73
+ aexists(this);
74
+ aoutput(out, this);
75
+ this.finished = true;
76
+ const { buffer, view, blockLen, isLE } = this;
77
+ let { pos } = this;
78
+ buffer[pos++] = 128;
79
+ clean(this.buffer.subarray(pos));
80
+ if (this.padOffset > blockLen - pos) {
81
+ this.process(view, 0);
82
+ pos = 0;
83
+ }
84
+ for (let i = pos; i < blockLen; i++)
85
+ buffer[i] = 0;
86
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
87
+ this.process(view, 0);
88
+ const oview = createView(out);
89
+ const len = this.outputLen;
90
+ if (len % 4)
91
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
92
+ const outLen = len / 4;
93
+ const state = this.get();
94
+ if (outLen > state.length)
95
+ throw new Error("_sha2: outputLen bigger than state");
96
+ for (let i = 0; i < outLen; i++)
97
+ oview.setUint32(4 * i, state[i], isLE);
98
+ }
99
+ digest() {
100
+ const { buffer, outputLen } = this;
101
+ this.digestInto(buffer);
102
+ const res = buffer.slice(0, outputLen);
103
+ this.destroy();
104
+ return res;
105
+ }
106
+ _cloneInto(to) {
107
+ to || (to = new this.constructor());
108
+ to.set(...this.get());
109
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
110
+ to.destroyed = destroyed;
111
+ to.finished = finished;
112
+ to.length = length;
113
+ to.pos = pos;
114
+ if (length % blockLen)
115
+ to.buffer.set(buffer);
116
+ return to;
117
+ }
118
+ clone() {
119
+ return this._cloneInto();
120
+ }
121
+ };
122
+ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
123
+ 1779033703,
124
+ 3144134277,
125
+ 1013904242,
126
+ 2773480762,
127
+ 1359893119,
128
+ 2600822924,
129
+ 528734635,
130
+ 1541459225
131
+ ]);
132
+ var SHA384_IV = /* @__PURE__ */ Uint32Array.from([
133
+ 3418070365,
134
+ 3238371032,
135
+ 1654270250,
136
+ 914150663,
137
+ 2438529370,
138
+ 812702999,
139
+ 355462360,
140
+ 4144912697,
141
+ 1731405415,
142
+ 4290775857,
143
+ 2394180231,
144
+ 1750603025,
145
+ 3675008525,
146
+ 1694076839,
147
+ 1203062813,
148
+ 3204075428
149
+ ]);
150
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
151
+ 1779033703,
152
+ 4089235720,
153
+ 3144134277,
154
+ 2227873595,
155
+ 1013904242,
156
+ 4271175723,
157
+ 2773480762,
158
+ 1595750129,
159
+ 1359893119,
160
+ 2917565137,
161
+ 2600822924,
162
+ 725511199,
163
+ 528734635,
164
+ 4215389547,
165
+ 1541459225,
166
+ 327033209
167
+ ]);
168
+
169
+ // node_modules/@noble/hashes/esm/_u64.js
170
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
171
+ var _32n = /* @__PURE__ */ BigInt(32);
172
+ function fromBig(n, le = false) {
173
+ if (le)
174
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
175
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
176
+ }
177
+ function split(lst, le = false) {
178
+ const len = lst.length;
179
+ let Ah = new Uint32Array(len);
180
+ let Al = new Uint32Array(len);
181
+ for (let i = 0; i < len; i++) {
182
+ const { h, l } = fromBig(lst[i], le);
183
+ [Ah[i], Al[i]] = [h, l];
184
+ }
185
+ return [Ah, Al];
186
+ }
187
+ var shrSH = (h, _l, s) => h >>> s;
188
+ var shrSL = (h, l, s) => h << 32 - s | l >>> s;
189
+ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
190
+ var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
191
+ var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
192
+ var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
193
+ function add(Ah, Al, Bh, Bl) {
194
+ const l = (Al >>> 0) + (Bl >>> 0);
195
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
196
+ }
197
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
198
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
199
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
200
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
201
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
202
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
203
+
204
+ // node_modules/@noble/hashes/esm/sha2.js
205
+ var SHA256_K = /* @__PURE__ */ Uint32Array.from([
206
+ 1116352408,
207
+ 1899447441,
208
+ 3049323471,
209
+ 3921009573,
210
+ 961987163,
211
+ 1508970993,
212
+ 2453635748,
213
+ 2870763221,
214
+ 3624381080,
215
+ 310598401,
216
+ 607225278,
217
+ 1426881987,
218
+ 1925078388,
219
+ 2162078206,
220
+ 2614888103,
221
+ 3248222580,
222
+ 3835390401,
223
+ 4022224774,
224
+ 264347078,
225
+ 604807628,
226
+ 770255983,
227
+ 1249150122,
228
+ 1555081692,
229
+ 1996064986,
230
+ 2554220882,
231
+ 2821834349,
232
+ 2952996808,
233
+ 3210313671,
234
+ 3336571891,
235
+ 3584528711,
236
+ 113926993,
237
+ 338241895,
238
+ 666307205,
239
+ 773529912,
240
+ 1294757372,
241
+ 1396182291,
242
+ 1695183700,
243
+ 1986661051,
244
+ 2177026350,
245
+ 2456956037,
246
+ 2730485921,
247
+ 2820302411,
248
+ 3259730800,
249
+ 3345764771,
250
+ 3516065817,
251
+ 3600352804,
252
+ 4094571909,
253
+ 275423344,
254
+ 430227734,
255
+ 506948616,
256
+ 659060556,
257
+ 883997877,
258
+ 958139571,
259
+ 1322822218,
260
+ 1537002063,
261
+ 1747873779,
262
+ 1955562222,
263
+ 2024104815,
264
+ 2227730452,
265
+ 2361852424,
266
+ 2428436474,
267
+ 2756734187,
268
+ 3204031479,
269
+ 3329325298
270
+ ]);
271
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
272
+ var SHA256 = class extends HashMD {
273
+ constructor(outputLen = 32) {
274
+ super(64, outputLen, 8, false);
275
+ this.A = SHA256_IV[0] | 0;
276
+ this.B = SHA256_IV[1] | 0;
277
+ this.C = SHA256_IV[2] | 0;
278
+ this.D = SHA256_IV[3] | 0;
279
+ this.E = SHA256_IV[4] | 0;
280
+ this.F = SHA256_IV[5] | 0;
281
+ this.G = SHA256_IV[6] | 0;
282
+ this.H = SHA256_IV[7] | 0;
283
+ }
284
+ get() {
285
+ const { A, B, C, D, E, F, G, H } = this;
286
+ return [A, B, C, D, E, F, G, H];
287
+ }
288
+ // prettier-ignore
289
+ set(A, B, C, D, E, F, G, H) {
290
+ this.A = A | 0;
291
+ this.B = B | 0;
292
+ this.C = C | 0;
293
+ this.D = D | 0;
294
+ this.E = E | 0;
295
+ this.F = F | 0;
296
+ this.G = G | 0;
297
+ this.H = H | 0;
298
+ }
299
+ process(view, offset) {
300
+ for (let i = 0; i < 16; i++, offset += 4)
301
+ SHA256_W[i] = view.getUint32(offset, false);
302
+ for (let i = 16; i < 64; i++) {
303
+ const W15 = SHA256_W[i - 15];
304
+ const W2 = SHA256_W[i - 2];
305
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
306
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
307
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
308
+ }
309
+ let { A, B, C, D, E, F, G, H } = this;
310
+ for (let i = 0; i < 64; i++) {
311
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
312
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
313
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
314
+ const T2 = sigma0 + Maj(A, B, C) | 0;
315
+ H = G;
316
+ G = F;
317
+ F = E;
318
+ E = D + T1 | 0;
319
+ D = C;
320
+ C = B;
321
+ B = A;
322
+ A = T1 + T2 | 0;
323
+ }
324
+ A = A + this.A | 0;
325
+ B = B + this.B | 0;
326
+ C = C + this.C | 0;
327
+ D = D + this.D | 0;
328
+ E = E + this.E | 0;
329
+ F = F + this.F | 0;
330
+ G = G + this.G | 0;
331
+ H = H + this.H | 0;
332
+ this.set(A, B, C, D, E, F, G, H);
333
+ }
334
+ roundClean() {
335
+ clean(SHA256_W);
336
+ }
337
+ destroy() {
338
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
339
+ clean(this.buffer);
340
+ }
341
+ };
342
+ var K512 = /* @__PURE__ */ (() => split([
343
+ "0x428a2f98d728ae22",
344
+ "0x7137449123ef65cd",
345
+ "0xb5c0fbcfec4d3b2f",
346
+ "0xe9b5dba58189dbbc",
347
+ "0x3956c25bf348b538",
348
+ "0x59f111f1b605d019",
349
+ "0x923f82a4af194f9b",
350
+ "0xab1c5ed5da6d8118",
351
+ "0xd807aa98a3030242",
352
+ "0x12835b0145706fbe",
353
+ "0x243185be4ee4b28c",
354
+ "0x550c7dc3d5ffb4e2",
355
+ "0x72be5d74f27b896f",
356
+ "0x80deb1fe3b1696b1",
357
+ "0x9bdc06a725c71235",
358
+ "0xc19bf174cf692694",
359
+ "0xe49b69c19ef14ad2",
360
+ "0xefbe4786384f25e3",
361
+ "0x0fc19dc68b8cd5b5",
362
+ "0x240ca1cc77ac9c65",
363
+ "0x2de92c6f592b0275",
364
+ "0x4a7484aa6ea6e483",
365
+ "0x5cb0a9dcbd41fbd4",
366
+ "0x76f988da831153b5",
367
+ "0x983e5152ee66dfab",
368
+ "0xa831c66d2db43210",
369
+ "0xb00327c898fb213f",
370
+ "0xbf597fc7beef0ee4",
371
+ "0xc6e00bf33da88fc2",
372
+ "0xd5a79147930aa725",
373
+ "0x06ca6351e003826f",
374
+ "0x142929670a0e6e70",
375
+ "0x27b70a8546d22ffc",
376
+ "0x2e1b21385c26c926",
377
+ "0x4d2c6dfc5ac42aed",
378
+ "0x53380d139d95b3df",
379
+ "0x650a73548baf63de",
380
+ "0x766a0abb3c77b2a8",
381
+ "0x81c2c92e47edaee6",
382
+ "0x92722c851482353b",
383
+ "0xa2bfe8a14cf10364",
384
+ "0xa81a664bbc423001",
385
+ "0xc24b8b70d0f89791",
386
+ "0xc76c51a30654be30",
387
+ "0xd192e819d6ef5218",
388
+ "0xd69906245565a910",
389
+ "0xf40e35855771202a",
390
+ "0x106aa07032bbd1b8",
391
+ "0x19a4c116b8d2d0c8",
392
+ "0x1e376c085141ab53",
393
+ "0x2748774cdf8eeb99",
394
+ "0x34b0bcb5e19b48a8",
395
+ "0x391c0cb3c5c95a63",
396
+ "0x4ed8aa4ae3418acb",
397
+ "0x5b9cca4f7763e373",
398
+ "0x682e6ff3d6b2b8a3",
399
+ "0x748f82ee5defb2fc",
400
+ "0x78a5636f43172f60",
401
+ "0x84c87814a1f0ab72",
402
+ "0x8cc702081a6439ec",
403
+ "0x90befffa23631e28",
404
+ "0xa4506cebde82bde9",
405
+ "0xbef9a3f7b2c67915",
406
+ "0xc67178f2e372532b",
407
+ "0xca273eceea26619c",
408
+ "0xd186b8c721c0c207",
409
+ "0xeada7dd6cde0eb1e",
410
+ "0xf57d4f7fee6ed178",
411
+ "0x06f067aa72176fba",
412
+ "0x0a637dc5a2c898a6",
413
+ "0x113f9804bef90dae",
414
+ "0x1b710b35131c471b",
415
+ "0x28db77f523047d84",
416
+ "0x32caab7b40c72493",
417
+ "0x3c9ebe0a15c9bebc",
418
+ "0x431d67c49c100d4c",
419
+ "0x4cc5d4becb3e42b6",
420
+ "0x597f299cfc657e2a",
421
+ "0x5fcb6fab3ad6faec",
422
+ "0x6c44198c4a475817"
423
+ ].map((n) => BigInt(n))))();
424
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
425
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
426
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
427
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
428
+ var SHA512 = class extends HashMD {
429
+ constructor(outputLen = 64) {
430
+ super(128, outputLen, 16, false);
431
+ this.Ah = SHA512_IV[0] | 0;
432
+ this.Al = SHA512_IV[1] | 0;
433
+ this.Bh = SHA512_IV[2] | 0;
434
+ this.Bl = SHA512_IV[3] | 0;
435
+ this.Ch = SHA512_IV[4] | 0;
436
+ this.Cl = SHA512_IV[5] | 0;
437
+ this.Dh = SHA512_IV[6] | 0;
438
+ this.Dl = SHA512_IV[7] | 0;
439
+ this.Eh = SHA512_IV[8] | 0;
440
+ this.El = SHA512_IV[9] | 0;
441
+ this.Fh = SHA512_IV[10] | 0;
442
+ this.Fl = SHA512_IV[11] | 0;
443
+ this.Gh = SHA512_IV[12] | 0;
444
+ this.Gl = SHA512_IV[13] | 0;
445
+ this.Hh = SHA512_IV[14] | 0;
446
+ this.Hl = SHA512_IV[15] | 0;
447
+ }
448
+ // prettier-ignore
449
+ get() {
450
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
451
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
452
+ }
453
+ // prettier-ignore
454
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
455
+ this.Ah = Ah | 0;
456
+ this.Al = Al | 0;
457
+ this.Bh = Bh | 0;
458
+ this.Bl = Bl | 0;
459
+ this.Ch = Ch | 0;
460
+ this.Cl = Cl | 0;
461
+ this.Dh = Dh | 0;
462
+ this.Dl = Dl | 0;
463
+ this.Eh = Eh | 0;
464
+ this.El = El | 0;
465
+ this.Fh = Fh | 0;
466
+ this.Fl = Fl | 0;
467
+ this.Gh = Gh | 0;
468
+ this.Gl = Gl | 0;
469
+ this.Hh = Hh | 0;
470
+ this.Hl = Hl | 0;
471
+ }
472
+ process(view, offset) {
473
+ for (let i = 0; i < 16; i++, offset += 4) {
474
+ SHA512_W_H[i] = view.getUint32(offset);
475
+ SHA512_W_L[i] = view.getUint32(offset += 4);
476
+ }
477
+ for (let i = 16; i < 80; i++) {
478
+ const W15h = SHA512_W_H[i - 15] | 0;
479
+ const W15l = SHA512_W_L[i - 15] | 0;
480
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
481
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
482
+ const W2h = SHA512_W_H[i - 2] | 0;
483
+ const W2l = SHA512_W_L[i - 2] | 0;
484
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
485
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
486
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
487
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
488
+ SHA512_W_H[i] = SUMh | 0;
489
+ SHA512_W_L[i] = SUMl | 0;
490
+ }
491
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
492
+ for (let i = 0; i < 80; i++) {
493
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
494
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
495
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
496
+ const CHIl = El & Fl ^ ~El & Gl;
497
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
498
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
499
+ const T1l = T1ll | 0;
500
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
501
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
502
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
503
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
504
+ Hh = Gh | 0;
505
+ Hl = Gl | 0;
506
+ Gh = Fh | 0;
507
+ Gl = Fl | 0;
508
+ Fh = Eh | 0;
509
+ Fl = El | 0;
510
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
511
+ Dh = Ch | 0;
512
+ Dl = Cl | 0;
513
+ Ch = Bh | 0;
514
+ Cl = Bl | 0;
515
+ Bh = Ah | 0;
516
+ Bl = Al | 0;
517
+ const All = add3L(T1l, sigma0l, MAJl);
518
+ Ah = add3H(All, T1h, sigma0h, MAJh);
519
+ Al = All | 0;
520
+ }
521
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
522
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
523
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
524
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
525
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
526
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
527
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
528
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
529
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
530
+ }
531
+ roundClean() {
532
+ clean(SHA512_W_H, SHA512_W_L);
533
+ }
534
+ destroy() {
535
+ clean(this.buffer);
536
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
537
+ }
538
+ };
539
+ var SHA384 = class extends SHA512 {
540
+ constructor() {
541
+ super(48);
542
+ this.Ah = SHA384_IV[0] | 0;
543
+ this.Al = SHA384_IV[1] | 0;
544
+ this.Bh = SHA384_IV[2] | 0;
545
+ this.Bl = SHA384_IV[3] | 0;
546
+ this.Ch = SHA384_IV[4] | 0;
547
+ this.Cl = SHA384_IV[5] | 0;
548
+ this.Dh = SHA384_IV[6] | 0;
549
+ this.Dl = SHA384_IV[7] | 0;
550
+ this.Eh = SHA384_IV[8] | 0;
551
+ this.El = SHA384_IV[9] | 0;
552
+ this.Fh = SHA384_IV[10] | 0;
553
+ this.Fl = SHA384_IV[11] | 0;
554
+ this.Gh = SHA384_IV[12] | 0;
555
+ this.Gl = SHA384_IV[13] | 0;
556
+ this.Hh = SHA384_IV[14] | 0;
557
+ this.Hl = SHA384_IV[15] | 0;
558
+ }
559
+ };
560
+ var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
561
+ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
562
+ var sha384 = /* @__PURE__ */ createHasher(() => new SHA384());
563
+
564
+ export {
565
+ sha256,
566
+ sha512,
567
+ sha384
568
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ sha256
3
+ } from "./chunk-AYNQIEN7.mjs";
4
+ import {
5
+ bytesToHex
6
+ } from "./chunk-D733KAPG.mjs";
7
+
8
+ // src/receipt-enrichment.ts
9
+ var ENRICHMENT_VERSION = 1;
10
+ function canonicalJson(value) {
11
+ const seen = /* @__PURE__ */ new WeakSet();
12
+ const enc = (v) => {
13
+ if (v === null || v === void 0) return "null";
14
+ const t = typeof v;
15
+ if (t === "number") return Number.isFinite(v) ? JSON.stringify(v) : "null";
16
+ if (t === "boolean" || t === "string") return JSON.stringify(v);
17
+ if (t === "bigint") return JSON.stringify(v.toString());
18
+ if (t === "function" || t === "symbol") return "null";
19
+ if (Array.isArray(v)) return "[" + v.map(enc).join(",") + "]";
20
+ if (t === "object") {
21
+ const o = v;
22
+ if (seen.has(o)) return '"[circular]"';
23
+ seen.add(o);
24
+ const body = Object.keys(o).sort().map((k) => JSON.stringify(k) + ":" + enc(o[k])).join(",");
25
+ seen.delete(o);
26
+ return "{" + body + "}";
27
+ }
28
+ return "null";
29
+ };
30
+ return enc(value);
31
+ }
32
+ function sha256Hex(s) {
33
+ return bytesToHex(sha256(new TextEncoder().encode(s)));
34
+ }
35
+ var RULES = [
36
+ { cap: "exec.shell", tool: /bash|shell|exec|terminal|run_command|command/ },
37
+ { cap: "fs.read", tool: /(^|[_.])(read|cat|glob|grep|search|ls|view|list_files|open)/ },
38
+ { cap: "fs.write", tool: /write|create_file|save|append|edit|patch|replace|update_file|multiedit|notebook/ },
39
+ { cap: "fs.delete", tool: /delete|remove|unlink|trash|(^|[_.])rm/ },
40
+ { cap: "net.egress", tool: /fetch|http|curl|wget|request|download|browse|navigate|webfetch|web_search|scrape/ },
41
+ { cap: "vcs", tool: /(^|[_.])git/, text: /\bgit\s+(commit|push|pull|clone|reset|checkout|branch|rebase|merge|tag)\b/ },
42
+ { cap: "package.install", text: /\b(npm|pnpm|yarn)\s+(i|install|add)\b|\bpip3?\s+install\b|\bgo\s+get\b|\bcargo\s+add\b|\bbrew\s+install\b|\bapt(-get)?\s+install\b|\bgem\s+install\b/ },
43
+ { cap: "secret.adjacent", text: /\.env\b|secret|credential|passwd|password|api[_-]?key|private[_-]?key|\.pem\b|\.key\b|id_rsa|bearer\s|aws_(access|secret)|authorization/ },
44
+ { cap: "destructive", text: /rm\s+-[a-z]*[rf]|\brmdir\b|drop\s+table|truncate\s+table|delete\s+from|reset\s+--hard|--force\b|\bmkfs\b|\bdd\s+if=|shutdown|reboot|kill\s+-9|>\s*\/dev\/sd/ },
45
+ { cap: "financial", text: /\b(order|trade|buy|sell|transfer|wire|payment|withdraw|deposit|swap|invoice|charge|refund|settle)\b/ },
46
+ { cap: "data.query", text: /\bselect\s+[\s\S]+\bfrom\b|\binsert\s+into\b|\bupdate\s+[\s\S]+\bset\b|\bdelete\s+from\b/ }
47
+ ];
48
+ function deriveCapabilities(tool, input) {
49
+ const t = String(tool || "").toLowerCase();
50
+ let text = "";
51
+ try {
52
+ text = canonicalJson(input).toLowerCase();
53
+ } catch {
54
+ }
55
+ const caps = /* @__PURE__ */ new Set();
56
+ for (const r of RULES) {
57
+ if (r.tool && r.tool.test(t)) caps.add(r.cap);
58
+ if (r.text && r.text.test(text)) caps.add(r.cap);
59
+ }
60
+ return Array.from(caps).sort();
61
+ }
62
+ function deriveResource(input) {
63
+ const o = input && typeof input === "object" ? input : {};
64
+ const path = o.file_path ?? o.path ?? o.filePath ?? o.notebook_path ?? o.filename;
65
+ if (typeof path === "string" && path.trim()) return { kind: "path", digest: sha256Hex(path.replace(/\\/g, "/")) };
66
+ const url = o.url ?? o.uri ?? o.endpoint ?? o.href;
67
+ if (typeof url === "string" && url.trim()) {
68
+ try {
69
+ return { kind: "host", digest: sha256Hex(new URL(url).host.toLowerCase()) };
70
+ } catch {
71
+ }
72
+ }
73
+ const cmd = o.command ?? o.cmd ?? o.script;
74
+ if (typeof cmd === "string" && cmd.trim()) {
75
+ const first = cmd.trim().split(/\s+/)[0];
76
+ if (first) return { kind: "command", digest: sha256Hex(first) };
77
+ }
78
+ return void 0;
79
+ }
80
+ function buildEnrichment(tool, input) {
81
+ const e = {
82
+ v: ENRICHMENT_VERSION,
83
+ input_digest: sha256Hex(canonicalJson(input ?? {})),
84
+ capabilities: deriveCapabilities(tool, input)
85
+ };
86
+ const resource = deriveResource(input);
87
+ if (resource) e.resource = resource;
88
+ return e;
89
+ }
90
+
91
+ export {
92
+ canonicalJson,
93
+ buildEnrichment
94
+ };