@7h3/protocol 0.5.4 → 0.5.6

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/index.js CHANGED
@@ -107,7 +107,7 @@ async function b(e, t) {
107
107
  async function x(e, t, n) {
108
108
  return ue(e, t, n);
109
109
  }
110
- async function me(e, t, n = "local-dev-key") {
110
+ async function S(e, t, n = "local-dev-key") {
111
111
  let r = await se(_(e), t);
112
112
  return {
113
113
  ...e,
@@ -118,13 +118,13 @@ async function me(e, t, n = "local-dev-key") {
118
118
  }
119
119
  };
120
120
  }
121
- async function S(e, t) {
121
+ async function C(e, t) {
122
122
  return !e.signature || e.signature.alg !== "HS256" ? !1 : ce(_({
123
123
  header: e.header,
124
124
  body: e.body
125
125
  }), e.signature.value, t);
126
126
  }
127
- async function C(e, t, n = "local-ed25519-key") {
127
+ async function w(e, t, n = "local-ed25519-key") {
128
128
  let r = await le(_(e), t);
129
129
  return {
130
130
  ...e,
@@ -135,21 +135,21 @@ async function C(e, t, n = "local-ed25519-key") {
135
135
  }
136
136
  };
137
137
  }
138
- async function w(e, t) {
138
+ async function T(e, t) {
139
139
  return !e.signature || e.signature.alg !== "ED25519" ? !1 : ue(_({
140
140
  header: e.header,
141
141
  body: e.body
142
142
  }), e.signature.value, t);
143
143
  }
144
- async function he(e, t) {
145
- return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? S(e, t.secret) : w(e, t.publicKey);
144
+ async function me(e, t) {
145
+ return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? C(e, t.secret) : T(e, t.publicKey);
146
146
  }
147
- async function ge(e, t, n) {
147
+ async function he(e, t, n) {
148
148
  return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : x(e, t.value, n.publicKey);
149
149
  }
150
- var _e = 864e5;
151
- function T(e, t = Date.now()) {
152
- let n = [], r = e.header ?? {}, i = e.body ?? {}, a = typeof r.version == "string" ? r.version : "", o = typeof r.messageId == "string" ? r.messageId : "", s = typeof r.sender == "string" ? r.sender : "", c = typeof r.nonce == "string" ? r.nonce : "", l = typeof r.timestampMs == "number" ? r.timestampMs : 0, u = typeof r.ttlMs == "number" ? r.ttlMs : 0, d = typeof i.content == "string" ? i.content : "";
150
+ var ge = 864e5;
151
+ function E(e, t = Date.now()) {
152
+ let n = [], r = e.header ?? {}, i = e.body ?? {}, a = typeof r.version == "string" ? r.version : "", o = typeof r.messageId == "string" ? r.messageId : "", s = typeof r.sender == "string" ? r.sender : "", c = typeof r.nonce == "string" ? r.nonce : "", l = typeof r.timestampMs == "number" && Number.isFinite(r.timestampMs) ? r.timestampMs : NaN, u = typeof r.ttlMs == "number" && Number.isFinite(r.ttlMs) ? r.ttlMs : NaN, d = typeof i.content == "string" ? i.content : "";
153
153
  return a !== "7h3/0.1" && n.push({
154
154
  level: "error",
155
155
  message: `Unsupported protocol version '${a}'`
@@ -162,13 +162,19 @@ function T(e, t = Date.now()) {
162
162
  }), c.trim() || n.push({
163
163
  level: "error",
164
164
  message: "Missing nonce — replay protection requires a unique nonce per message"
165
- }), u <= 0 && n.push({
165
+ }), Number.isFinite(l) || n.push({
166
+ level: "error",
167
+ message: "timestampMs must be a finite number"
168
+ }), Number.isFinite(u) ? (u <= 0 && n.push({
166
169
  level: "error",
167
170
  message: "ttlMs must be greater than zero"
168
171
  }), u > 864e5 && n.push({
169
172
  level: "error",
170
- message: `ttlMs exceeds maximum allowed ${_e} ms`
171
- }), l + u < t && n.push({
173
+ message: `ttlMs exceeds maximum allowed ${ge} ms`
174
+ })) : n.push({
175
+ level: "error",
176
+ message: "ttlMs must be a finite number"
177
+ }), Number.isFinite(l) && Number.isFinite(u) && l + u < t && n.push({
172
178
  level: "error",
173
179
  message: "Message TTL expired"
174
180
  }), d.trim() || n.push({
@@ -176,7 +182,7 @@ function T(e, t = Date.now()) {
176
182
  message: "Empty content payload"
177
183
  }), n;
178
184
  }
179
- function E(e) {
185
+ function D(e) {
180
186
  let t = e.nowMs ?? Date.now();
181
187
  return {
182
188
  header: {
@@ -198,12 +204,12 @@ function E(e) {
198
204
  }
199
205
  //#endregion
200
206
  //#region src/protocolBinary.ts
201
- var ve = [
207
+ var _e = [
202
208
  65,
203
209
  73,
204
210
  80,
205
211
  66
206
- ], ye = Uint8Array.from(ve), be = 1, xe = 1024 * 1024, Se = 1, Ce = 2, we = 4, Te = 8, Ee = new TextEncoder(), De = new TextDecoder(), Oe = /* @__PURE__ */ new Set([
212
+ ], ve = Uint8Array.from(_e), ye = 1, be = 1024 * 1024, xe = 1, Se = 2, Ce = 4, we = 8, Te = new TextEncoder(), Ee = new TextDecoder(), De = /* @__PURE__ */ new Set([
207
213
  "PING",
208
214
  "PONG",
209
215
  "CAPS",
@@ -211,25 +217,25 @@ var ve = [
211
217
  "RESULT",
212
218
  "ERROR"
213
219
  ]);
220
+ function Oe(e) {
221
+ return Te.encode(e);
222
+ }
214
223
  function ke(e) {
215
- return Ee.encode(e);
224
+ return Ee.decode(e);
216
225
  }
217
226
  function Ae(e) {
218
- return De.decode(e);
219
- }
220
- function je(e) {
221
227
  return e === "ED25519" ? 2 : 1;
222
228
  }
223
- function Me(e) {
229
+ function je(e) {
224
230
  return e === 1 ? "HS256" : e === 2 ? "ED25519" : null;
225
231
  }
226
- function D(e) {
227
- return { bytes: ke(e) };
228
- }
229
232
  function O(e) {
233
+ return { bytes: Oe(e) };
234
+ }
235
+ function k(e) {
230
236
  return e ? 4 + e.bytes.byteLength : 0;
231
237
  }
232
- var Ne = class {
238
+ var Me = class {
233
239
  bytes;
234
240
  view;
235
241
  offset = 0;
@@ -254,7 +260,7 @@ var Ne = class {
254
260
  finish() {
255
261
  return this.bytes;
256
262
  }
257
- }, Pe = class {
263
+ }, Ne = class {
258
264
  bytes;
259
265
  offset = 0;
260
266
  constructor(e) {
@@ -285,14 +291,14 @@ var Ne = class {
285
291
  }
286
292
  readString() {
287
293
  let e = this.readU32();
288
- return Ae(this.readBytes(e));
294
+ return ke(this.readBytes(e));
289
295
  }
290
296
  };
291
- function Fe(e) {
292
- let t = (e.header.recipient ? Se : 0) | (e.body.capability ? Ce : 0) | (e.body.correlationId ? we : 0) | (e.signature ? Te : 0), n = D(e.header.version), r = D(e.header.messageId), i = D(e.header.sender), a = D(e.header.nonce), o = D(e.body.intent), s = D(e.body.content), c = e.header.recipient ? D(e.header.recipient) : null, l = e.body.capability ? D(e.body.capability) : null, u = e.body.correlationId ? D(e.body.correlationId) : null, d = e.signature ? D(e.signature.keyId) : null, f = e.signature ? D(e.signature.value) : null, p = new Ne(ye.byteLength + 1 + 1 + 8 + 4 + O(n) + O(r) + O(i) + O(a) + O(o) + O(s) + O(c) + O(l) + O(u) + +!!e.signature + O(d) + O(f));
293
- return p.writeBytes(ye), p.writeU8(be), p.writeU8(t), p.writeU64(e.header.timestampMs), p.writeU32(e.header.ttlMs), p.writeString(n), p.writeString(r), p.writeString(i), p.writeString(a), p.writeString(o), p.writeString(s), c && p.writeString(c), l && p.writeString(l), u && p.writeString(u), e.signature && d && f && (p.writeU8(je(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
297
+ function Pe(e) {
298
+ let t = (e.header.recipient ? xe : 0) | (e.body.capability ? Se : 0) | (e.body.correlationId ? Ce : 0) | (e.signature ? we : 0), n = O(e.header.version), r = O(e.header.messageId), i = O(e.header.sender), a = O(e.header.nonce), o = O(e.body.intent), s = O(e.body.content), c = e.header.recipient ? O(e.header.recipient) : null, l = e.body.capability ? O(e.body.capability) : null, u = e.body.correlationId ? O(e.body.correlationId) : null, d = e.signature ? O(e.signature.keyId) : null, f = e.signature ? O(e.signature.value) : null, p = new Me(ve.byteLength + 1 + 1 + 8 + 4 + k(n) + k(r) + k(i) + k(a) + k(o) + k(s) + k(c) + k(l) + k(u) + +!!e.signature + k(d) + k(f));
299
+ return p.writeBytes(ve), p.writeU8(ye), p.writeU8(t), p.writeU64(e.header.timestampMs), p.writeU32(e.header.ttlMs), p.writeString(n), p.writeString(r), p.writeString(i), p.writeString(a), p.writeString(o), p.writeString(s), c && p.writeString(c), l && p.writeString(l), u && p.writeString(u), e.signature && d && f && (p.writeU8(Ae(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
294
300
  }
295
- function Ie(e, t = {}) {
301
+ function Fe(e, t = {}) {
296
302
  try {
297
303
  let n = t.maxFrameBytes ?? 1048576;
298
304
  if (e.byteLength > n) return {
@@ -303,13 +309,13 @@ function Ie(e, t = {}) {
303
309
  }],
304
310
  envelope: null
305
311
  };
306
- let r = new Pe(e);
312
+ let r = new Ne(e);
307
313
  if ([
308
314
  r.readU8(),
309
315
  r.readU8(),
310
316
  r.readU8(),
311
317
  r.readU8()
312
- ].some((e, t) => e !== ve[t])) return {
318
+ ].some((e, t) => e !== _e[t])) return {
313
319
  ok: !1,
314
320
  diagnostics: [{
315
321
  level: "error",
@@ -318,7 +324,7 @@ function Ie(e, t = {}) {
318
324
  envelope: null
319
325
  };
320
326
  let i = r.readU8();
321
- if (i !== be) return {
327
+ if (i !== ye) return {
322
328
  ok: !1,
323
329
  diagnostics: [{
324
330
  level: "error",
@@ -348,7 +354,7 @@ function Ie(e, t = {}) {
348
354
  }],
349
355
  envelope: null
350
356
  };
351
- if (!Oe.has(c.body.intent)) return {
357
+ if (!De.has(c.body.intent)) return {
352
358
  ok: !1,
353
359
  diagnostics: [{
354
360
  level: "error",
@@ -356,8 +362,8 @@ function Ie(e, t = {}) {
356
362
  }],
357
363
  envelope: null
358
364
  };
359
- if (a & Se && (c.header.recipient = r.readString()), a & Ce && (c.body.capability = r.readString()), a & we && (c.body.correlationId = r.readString()), a & Te) {
360
- let e = r.readU8(), t = Me(e);
365
+ if (a & xe && (c.header.recipient = r.readString()), a & Se && (c.body.capability = r.readString()), a & Ce && (c.body.correlationId = r.readString()), a & we) {
366
+ let e = r.readU8(), t = je(e);
361
367
  if (!t) return {
362
368
  ok: !1,
363
369
  diagnostics: [{
@@ -397,7 +403,7 @@ function Ie(e, t = {}) {
397
403
  }
398
404
  //#endregion
399
405
  //#region src/protocolReplay.ts
400
- var Le = class {
406
+ var Ie = class {
401
407
  items = [];
402
408
  peek() {
403
409
  return this.items[0];
@@ -430,10 +436,10 @@ var Le = class {
430
436
  this.items[t] = l, this.items[r] = c, t = r;
431
437
  }
432
438
  }
433
- }, k = class {
439
+ }, A = class {
434
440
  entries = /* @__PURE__ */ new Map();
435
441
  maxEntries;
436
- expiries = new Le();
442
+ expiries = new Ie();
437
443
  constructor(e = 1e4) {
438
444
  this.maxEntries = e;
439
445
  }
@@ -467,21 +473,23 @@ var Le = class {
467
473
  consume(e, t = Date.now()) {
468
474
  this.prune(t);
469
475
  let n = this.makeKey(e), r = this.entries.get(n);
470
- if (r && r > t) return {
476
+ if (r !== void 0 && (!Number.isFinite(r) || r > t)) return {
471
477
  ok: !1,
472
478
  reason: "Replay detected for sender/messageId/nonce"
473
479
  };
474
- this.entries.size >= this.maxEntries && this.evictOne();
475
480
  let i = e.header.timestampMs + e.header.ttlMs;
476
- return this.entries.set(n, i), this.expiries.push({
481
+ return Number.isFinite(i) ? (this.entries.size >= this.maxEntries && this.evictOne(), this.entries.set(n, i), this.expiries.push({
477
482
  key: n,
478
483
  expiresAt: i
479
- }), { ok: !0 };
484
+ }), { ok: !0 }) : {
485
+ ok: !1,
486
+ reason: "Cannot track replay protection for a non-finite timestampMs/ttlMs"
487
+ };
480
488
  }
481
489
  consumeMany(e, t = Date.now()) {
482
490
  return e.map((e) => this.consume(e, t));
483
491
  }
484
- }, Re = class {
492
+ }, Le = class {
485
493
  store;
486
494
  constructor(e) {
487
495
  this.store = e;
@@ -491,9 +499,12 @@ var Le = class {
491
499
  }
492
500
  async consume(e, t = Date.now()) {
493
501
  let n = this.makeKey(e), r = e.header.timestampMs + e.header.ttlMs;
494
- return await this.store.reserve(n, r, t) ? { ok: !0 } : {
502
+ return Number.isFinite(r) ? await this.store.reserve(n, r, t) ? { ok: !0 } : {
495
503
  ok: !1,
496
504
  reason: "Replay detected for sender/messageId/nonce"
505
+ } : {
506
+ ok: !1,
507
+ reason: "Cannot track replay protection for a non-finite timestampMs/ttlMs"
497
508
  };
498
509
  }
499
510
  async consumeMany(e, t = Date.now()) {
@@ -509,7 +520,7 @@ var Le = class {
509
520
  }
510
521
  return Promise.all(e.map((e) => this.consume(e, t)));
511
522
  }
512
- }, ze = class {
523
+ }, Re = class {
513
524
  entries = /* @__PURE__ */ new Map();
514
525
  maxEntries;
515
526
  constructor(e = 512) {
@@ -539,20 +550,20 @@ var Le = class {
539
550
  this.entries.delete(e);
540
551
  }
541
552
  };
542
- function Be(e, t) {
553
+ function ze(e, t) {
543
554
  return `${t}|${e.alg}|${e.keyId}`;
544
555
  }
545
- function Ve(e) {
556
+ function Be(e) {
546
557
  if (!e || typeof e != "object") return !1;
547
558
  let t = e;
548
559
  return !!(t.header && t.body);
549
560
  }
550
- function He(e) {
561
+ function Ve(e) {
551
562
  if (!e || typeof e != "object") return !1;
552
563
  let t = e;
553
564
  return t.v === "7h3/0.1" && typeof t.mid == "string" && typeof t.i == "string";
554
565
  }
555
- function Ue(e) {
566
+ function He(e) {
556
567
  return {
557
568
  header: {
558
569
  version: e.v,
@@ -576,7 +587,7 @@ function Ue(e) {
576
587
  } : void 0
577
588
  };
578
589
  }
579
- function We(e) {
590
+ function Ue(e) {
580
591
  return {
581
592
  v: e.header.version,
582
593
  mid: e.header.messageId,
@@ -596,15 +607,15 @@ function We(e) {
596
607
  } : void 0
597
608
  };
598
609
  }
599
- function Ge(e) {
600
- if (e instanceof Uint8Array) return Ie(e);
610
+ function We(e) {
611
+ if (e instanceof Uint8Array) return Fe(e);
601
612
  try {
602
613
  let t = JSON.parse(e);
603
- return He(t) ? {
614
+ return Ve(t) ? {
604
615
  ok: !0,
605
616
  diagnostics: [],
606
- envelope: Ue(t)
607
- } : Ve(t) ? {
617
+ envelope: He(t)
618
+ } : Be(t) ? {
608
619
  ok: !0,
609
620
  diagnostics: [],
610
621
  envelope: t
@@ -627,20 +638,20 @@ function Ge(e) {
627
638
  };
628
639
  }
629
640
  }
630
- function Ke(e, t = "json") {
631
- return t === "binary" ? Fe(e) : JSON.stringify(t === "compact" ? We(e) : e);
641
+ function j(e, t = "json") {
642
+ return t === "binary" ? Pe(e) : JSON.stringify(t === "compact" ? Ue(e) : e);
632
643
  }
633
- function qe(e, t = "compact") {
634
- return JSON.stringify(t === "compact" ? e.map(We) : e);
644
+ function Ge(e, t = "compact") {
645
+ return JSON.stringify(t === "compact" ? e.map(Ue) : e);
635
646
  }
636
- function Je(e) {
647
+ function Ke(e) {
637
648
  try {
638
649
  let t = JSON.parse(e);
639
- return Array.isArray(t) ? t.map((e) => He(e) ? {
650
+ return Array.isArray(t) ? t.map((e) => Ve(e) ? {
640
651
  ok: !0,
641
652
  diagnostics: [],
642
- envelope: Ue(e)
643
- } : Ve(e) ? {
653
+ envelope: He(e)
654
+ } : Be(e) ? {
644
655
  ok: !0,
645
656
  diagnostics: [],
646
657
  envelope: e
@@ -670,7 +681,7 @@ function Je(e) {
670
681
  }];
671
682
  }
672
683
  }
673
- async function A(e, t = {}) {
684
+ async function M(e, t = {}) {
674
685
  let n = t.nowMs ?? Date.now(), r = t.requireSignature ?? !0, i = t.maxClockSkewMs ?? 3e4;
675
686
  async function a(e) {
676
687
  t.telemetry && await t.telemetry({
@@ -678,7 +689,7 @@ async function A(e, t = {}) {
678
689
  ...e
679
690
  });
680
691
  }
681
- let o = typeof e == "string" || e instanceof Uint8Array ? Ge(e) : {
692
+ let o = typeof e == "string" || e instanceof Uint8Array ? We(e) : {
682
693
  ok: !0,
683
694
  diagnostics: [],
684
695
  envelope: e
@@ -688,7 +699,7 @@ async function A(e, t = {}) {
688
699
  phase: "decoded",
689
700
  sender: o.envelope.header.sender,
690
701
  messageId: o.envelope.header.messageId
691
- }), o.envelope.header.timestampMs > n + i) {
702
+ }), !Number.isFinite(o.envelope.header.timestampMs) || o.envelope.header.timestampMs > n + i) {
692
703
  let e = "Message timestamp exceeds allowed clock skew", t = [{
693
704
  level: "error",
694
705
  message: e
@@ -704,7 +715,7 @@ async function A(e, t = {}) {
704
715
  envelope: o.envelope
705
716
  };
706
717
  }
707
- let s = [...T(o.envelope, n)];
718
+ let s = [...E(o.envelope, n)];
708
719
  if (s.some((e) => e.level === "error")) return await a({
709
720
  phase: "rejected_validation",
710
721
  sender: o.envelope.header.sender,
@@ -736,7 +747,7 @@ async function A(e, t = {}) {
736
747
  diagnostics: s,
737
748
  envelope: o.envelope
738
749
  });
739
- let c, l = o.envelope.signature, u = Be(l, o.envelope.header.sender);
750
+ let c, l = o.envelope.signature, u = ze(l, o.envelope.header.sender);
740
751
  if (t.verificationMaterialCache && (c = t.verificationMaterialCache.get(u, n)), t.signatureResolver && (c ??= await t.signatureResolver(l, o.envelope.header.sender)), !c && l.alg === "HS256" && t.secretResolver) {
741
752
  let e = await t.secretResolver(l.keyId, o.envelope.header.sender);
742
753
  e && (c = {
@@ -761,7 +772,7 @@ async function A(e, t = {}) {
761
772
  diagnostics: s,
762
773
  envelope: o.envelope
763
774
  };
764
- if (!await ge(_({
775
+ if (!await he(_({
765
776
  header: o.envelope.header,
766
777
  body: o.envelope.body
767
778
  }), o.envelope.signature, c)) return s.push({
@@ -803,7 +814,7 @@ async function A(e, t = {}) {
803
814
  envelope: o.envelope
804
815
  };
805
816
  }
806
- async function Ye(e, t = {}) {
817
+ async function qe(e, t = {}) {
807
818
  let n = Math.max(1, Math.floor(t.batchConcurrency ?? Infinity));
808
819
  return (async (e) => {
809
820
  let r = Array(e.length), i = 0, a = Number.isFinite(n) ? Math.min(n, e.length) : e.length;
@@ -812,48 +823,48 @@ async function Ye(e, t = {}) {
812
823
  let n = i;
813
824
  i += 1;
814
825
  let a = e[n];
815
- a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await A(a, t);
826
+ a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await M(a, t);
816
827
  }
817
828
  })), await t.telemetry?.({
818
829
  phase: "batch_summary",
819
830
  nowMs: t.nowMs ?? Date.now(),
820
831
  reason: `items=${e.length};accepted=${r.filter((e) => e?.ok).length}`
821
832
  }), r;
822
- })(typeof e == "string" ? Je(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
833
+ })(typeof e == "string" ? Ke(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
823
834
  }
824
- var Xe = class {
835
+ var Je = class {
825
836
  options;
826
837
  constructor(e = {}) {
827
838
  this.options = {
828
839
  ...e,
829
- replayCache: e.replayCache ?? new k(),
830
- verificationMaterialCache: e.verificationMaterialCache ?? new ze()
840
+ replayCache: e.replayCache ?? new A(),
841
+ verificationMaterialCache: e.verificationMaterialCache ?? new Re()
831
842
  };
832
843
  }
833
844
  receive(e, t = Date.now()) {
834
- return A(e, {
845
+ return M(e, {
835
846
  ...this.options,
836
847
  nowMs: t
837
848
  });
838
849
  }
839
850
  receiveBatch(e, t = Date.now()) {
840
- return Ye(e, {
851
+ return qe(e, {
841
852
  ...this.options,
842
853
  nowMs: t
843
854
  });
844
855
  }
845
856
  };
846
- async function Ze(e) {
847
- return me(E(e), e.secret, e.keyId);
857
+ async function Ye(e) {
858
+ return S(D(e), e.secret, e.keyId);
848
859
  }
849
860
  //#endregion
850
861
  //#region src/protocolCapabilities.ts
851
- var Qe = [
862
+ var Xe = [
852
863
  "binary",
853
864
  "compact",
854
865
  "json"
855
- ], $e = ["fast", "receipt"];
856
- function et(e) {
866
+ ], Ze = ["fast", "receipt"];
867
+ function Qe(e) {
857
868
  return {
858
869
  agent: e.agent,
859
870
  capabilities: e.capabilities ?? [],
@@ -862,10 +873,10 @@ function et(e) {
862
873
  ackModes: e.ackModes ?? ["receipt"]
863
874
  };
864
875
  }
865
- function tt(e) {
876
+ function $e(e) {
866
877
  return JSON.stringify(e);
867
878
  }
868
- function nt(e) {
879
+ function et(e) {
869
880
  try {
870
881
  let t = JSON.parse(e);
871
882
  return typeof t.agent != "string" || !Array.isArray(t.capabilities) || !Array.isArray(t.wireFormats) || !Array.isArray(t.ackModes) || typeof t.batchMax != "number" || t.batchMax < 1 ? null : {
@@ -879,8 +890,8 @@ function nt(e) {
879
890
  return null;
880
891
  }
881
892
  }
882
- function rt(e, t) {
883
- let n = Qe.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = $e.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
893
+ function tt(e, t) {
894
+ let n = Xe.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = Ze.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
884
895
  return {
885
896
  wireFormat: n,
886
897
  batchMax: Math.max(1, Math.min(e.batchMax, t.batchMax)),
@@ -889,7 +900,7 @@ function rt(e, t) {
889
900
  }
890
901
  //#endregion
891
902
  //#region src/keyRotation.ts
892
- var it = class {
903
+ var nt = class {
893
904
  records;
894
905
  constructor(e = []) {
895
906
  this.records = [...e];
@@ -908,12 +919,12 @@ var it = class {
908
919
  return this.records.filter((r) => r.sender === t && r.keyId === e.keyId && r.alg === e.alg && r.status !== "revoked" && r.notBeforeMs <= n && n < r.notAfterMs).sort((e, t) => t.notBeforeMs - e.notBeforeMs)[0]?.material;
909
920
  }
910
921
  };
911
- function at(e, t = () => Date.now()) {
922
+ function rt(e, t = () => Date.now()) {
912
923
  return async (n, r) => e.resolveVerificationMaterial(n, r, t());
913
924
  }
914
925
  //#endregion
915
926
  //#region src/protocolAgent.ts
916
- var ot = class {
927
+ var it = class {
917
928
  agentId;
918
929
  outboundSecret;
919
930
  keyId;
@@ -927,13 +938,13 @@ var ot = class {
927
938
  resolveInboundSecret;
928
939
  onTask;
929
940
  constructor(e) {
930
- this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new k(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
941
+ this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new A(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
931
942
  }
932
943
  async inboundSecretResolver(e, t) {
933
944
  return this.resolveInboundSecret ? this.resolveInboundSecret(e, t) : this.sharedSecrets[t];
934
945
  }
935
946
  async createSignedIntent(e) {
936
- return me(E({
947
+ return S(D({
937
948
  sender: this.agentId,
938
949
  recipient: e.recipient,
939
950
  intent: e.intent,
@@ -947,7 +958,7 @@ var ot = class {
947
958
  }), this.outboundSecret, this.keyId);
948
959
  }
949
960
  async receiveAndRespond(e, t = Date.now()) {
950
- let n = await A(e, {
961
+ let n = await M(e, {
951
962
  nowMs: t,
952
963
  requireSignature: this.requireSignature,
953
964
  replayCache: this.replayCache,
@@ -978,7 +989,7 @@ var ot = class {
978
989
  if (e.body.intent === "CAPS") return this.createSignedIntent({
979
990
  recipient: e.header.sender,
980
991
  intent: "RESULT",
981
- content: tt(et({
992
+ content: $e(Qe({
982
993
  agent: this.agentId,
983
994
  capabilities: this.capabilities,
984
995
  wireFormats: this.supportedWireFormats,
@@ -1006,14 +1017,14 @@ var ot = class {
1006
1017
  }
1007
1018
  return null;
1008
1019
  }
1009
- }, st = class {
1020
+ }, at = class {
1010
1021
  session;
1011
1022
  wireFormat;
1012
1023
  constructor(e) {
1013
- this.session = new ot(e), this.wireFormat = e.wireFormat ?? "compact";
1024
+ this.session = new it(e), this.wireFormat = e.wireFormat ?? "compact";
1014
1025
  }
1015
1026
  toRaw(e) {
1016
- return Ke(e, this.wireFormat);
1027
+ return j(e, this.wireFormat);
1017
1028
  }
1018
1029
  async createRawIntent(e) {
1019
1030
  let t = await this.session.createSignedIntent(e);
@@ -1027,12 +1038,12 @@ var ot = class {
1027
1038
  return r.response && await t(this.toRaw(r.response), r.response), r;
1028
1039
  }
1029
1040
  };
1030
- function ct(e) {
1031
- return new st(e);
1041
+ function ot(e) {
1042
+ return new at(e);
1032
1043
  }
1033
1044
  //#endregion
1034
1045
  //#region src/frameworkAdapters.ts
1035
- async function lt(e, t, n = {}) {
1046
+ async function st(e, t, n = {}) {
1036
1047
  return e.createRawIntent({
1037
1048
  recipient: n.recipient,
1038
1049
  intent: "TASK",
@@ -1041,7 +1052,7 @@ async function lt(e, t, n = {}) {
1041
1052
  correlationId: n.correlationId
1042
1053
  });
1043
1054
  }
1044
- function ut(e) {
1055
+ function ct(e) {
1045
1056
  return {
1046
1057
  content: e.body.content,
1047
1058
  name: e.body.intent,
@@ -1055,7 +1066,7 @@ function ut(e) {
1055
1066
  }
1056
1067
  };
1057
1068
  }
1058
- async function dt(e, t, n = {}) {
1069
+ async function lt(e, t, n = {}) {
1059
1070
  return e.createRawIntent({
1060
1071
  recipient: n.recipient,
1061
1072
  intent: "TASK",
@@ -1064,7 +1075,7 @@ async function dt(e, t, n = {}) {
1064
1075
  correlationId: n.correlationId
1065
1076
  });
1066
1077
  }
1067
- function ft(e) {
1078
+ function ut(e) {
1068
1079
  return {
1069
1080
  role: e.body.intent === "TASK" ? "user" : "assistant",
1070
1081
  content: e.body.content,
@@ -1077,15 +1088,15 @@ function ft(e) {
1077
1088
  }
1078
1089
  };
1079
1090
  }
1080
- function pt(e) {
1091
+ function dt(e) {
1081
1092
  return `mcp.${e}`;
1082
1093
  }
1083
- async function mt(e, t, n = {}) {
1094
+ async function ft(e, t, n = {}) {
1084
1095
  async function r(e) {
1085
1096
  n.onPolicyEvent && await n.onPolicyEvent(e);
1086
1097
  }
1087
1098
  if (n.allowedMethods && !n.allowedMethods.includes(t.method)) {
1088
- let e = n.methodToCapability ? n.methodToCapability(t.method) : pt(t.method), i = {
1099
+ let e = n.methodToCapability ? n.methodToCapability(t.method) : dt(t.method), i = {
1089
1100
  intent: "TASK",
1090
1101
  recipient: n.recipient,
1091
1102
  capability: e,
@@ -1100,7 +1111,7 @@ async function mt(e, t, n = {}) {
1100
1111
  reason: "method_not_allowed"
1101
1112
  }), Error(`JSON-RPC method '${t.method}' is not allowed`);
1102
1113
  }
1103
- let i = n.methodToCapability ? n.methodToCapability(t.method) : pt(t.method), a = {
1114
+ let i = n.methodToCapability ? n.methodToCapability(t.method) : dt(t.method), a = {
1104
1115
  intent: "TASK",
1105
1116
  recipient: n.recipient,
1106
1117
  capability: i,
@@ -1154,7 +1165,7 @@ async function mt(e, t, n = {}) {
1154
1165
  })
1155
1166
  });
1156
1167
  }
1157
- function ht(e, t, n = {}) {
1168
+ function pt(e, t, n = {}) {
1158
1169
  if (e.body.intent === "ERROR") return {
1159
1170
  jsonrpc: "2.0",
1160
1171
  id: t,
@@ -1181,16 +1192,16 @@ function ht(e, t, n = {}) {
1181
1192
  }
1182
1193
  //#endregion
1183
1194
  //#region src/runtimePolicy.ts
1184
- function gt(e) {
1195
+ function mt(e) {
1185
1196
  return typeof e == "object" && !!e && !Array.isArray(e);
1186
1197
  }
1187
- function _t(e, t) {
1198
+ function ht(e, t) {
1188
1199
  if (typeof e != "string" || e.trim().length === 0) throw Error(`Invalid runtime policy: '${t}' must be a non-empty string`);
1189
1200
  return e;
1190
1201
  }
1191
- function vt(e) {
1192
- if (!gt(e)) throw Error("Invalid runtime policy: root must be an object");
1193
- let t = _t(e.version, "version"), n = _t(e.name, "name"), r = _t(e.status, "status");
1202
+ function gt(e) {
1203
+ if (!mt(e)) throw Error("Invalid runtime policy: root must be an object");
1204
+ let t = ht(e.version, "version"), n = ht(e.name, "name"), r = ht(e.status, "status");
1194
1205
  return {
1195
1206
  ...e,
1196
1207
  version: t,
@@ -1198,7 +1209,7 @@ function vt(e) {
1198
1209
  status: r
1199
1210
  };
1200
1211
  }
1201
- function yt(e) {
1212
+ function _t(e) {
1202
1213
  let t;
1203
1214
  try {
1204
1215
  t = JSON.parse(e);
@@ -1206,9 +1217,9 @@ function yt(e) {
1206
1217
  let t = e instanceof Error ? e.message : String(e);
1207
1218
  throw Error(`Invalid runtime policy JSON: ${t}`, { cause: e });
1208
1219
  }
1209
- return vt(t);
1220
+ return gt(t);
1210
1221
  }
1211
- async function bt(e) {
1222
+ async function vt(e) {
1212
1223
  if (typeof fetch == "function") {
1213
1224
  let t = await fetch(e);
1214
1225
  if (!t.ok) throw Error(`Failed to fetch runtime policy at '${e}': ${t.status} ${t.statusText}`);
@@ -1216,26 +1227,26 @@ async function bt(e) {
1216
1227
  }
1217
1228
  throw Error("No default runtime file reader available in this environment. Provide 'readTextFile' in loadRuntimePolicy(options).");
1218
1229
  }
1219
- async function xt(e = {}) {
1230
+ async function yt(e = {}) {
1220
1231
  let t = e.path ?? "AI_RUNTIME_POLICY.json";
1221
- return yt(await (e.readTextFile ?? bt)(t));
1232
+ return _t(await (e.readTextFile ?? vt)(t));
1222
1233
  }
1223
1234
  //#endregion
1224
1235
  //#region src/policyEnforcer.ts
1225
- function St(e, t) {
1236
+ function bt(e, t) {
1226
1237
  if (!Array.isArray(e) || e.length !== 2) throw Error(`Invalid policy tuning range '${t}': expected [min,max]`);
1227
1238
  let n = Number(e[0]), r = Number(e[1]);
1228
1239
  if (!Number.isFinite(n) || !Number.isFinite(r) || n <= 0 || r < n) throw Error(`Invalid policy tuning range '${t}': expected positive ascending numbers`);
1229
1240
  return [Math.floor(n), Math.floor(r)];
1230
1241
  }
1231
- function Ct(e) {
1242
+ function xt(e) {
1232
1243
  return e === "http" || e === "ws" || e === "http-binary" || e === "http-batch" || e === "http-binary-batch" || e === "ws-batch" || e === "ws-binary" || e === "ws-binary-batch";
1233
1244
  }
1234
- function wt(e) {
1245
+ function St(e) {
1235
1246
  let t = Number((e.slo_defaults ?? {}).drop_pct_max ?? .1), n = Number((e.slo_defaults ?? {}).p99_ms_max ?? 20), r = Number((e.tuning ?? {}).max_retry_attempts ?? 3), i = Array.isArray((e.tuning ?? {}).retriable_status_codes) ? (e.tuning ?? {}).retriable_status_codes.map((e) => Number(e)).filter((e) => Number.isFinite(e)) : [503], a = e.tuning ?? {}, o = a.batch_size, s = a.inflight_cap, c = a.retry_backoff_ms, l = (e) => ({
1236
- batchSizeRange: St(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1237
- inflightCapRange: St(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1238
- retryBackoffMsRange: St(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1247
+ batchSizeRange: bt(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1248
+ inflightCapRange: bt(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1249
+ retryBackoffMsRange: bt(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1239
1250
  });
1240
1251
  function u(e) {
1241
1252
  return e.concurrency >= 100 ? "http-binary-batch" : e.latencySensitive ? "ws-batch" : e.compatibilityFirst ? "http" : "ws-batch";
@@ -1272,28 +1283,28 @@ function wt(e) {
1272
1283
  }
1273
1284
  };
1274
1285
  }
1275
- async function j(e = {}) {
1276
- let t = await xt(e);
1286
+ async function N(e = {}) {
1287
+ let t = await yt(e);
1277
1288
  return {
1278
1289
  policy: t,
1279
- enforcer: wt(t)
1290
+ enforcer: St(t)
1280
1291
  };
1281
1292
  }
1282
- function Tt(e) {
1283
- return Ct(e);
1293
+ function Ct(e) {
1294
+ return xt(e);
1284
1295
  }
1285
1296
  //#endregion
1286
1297
  //#region src/mcpGateway.ts
1287
- var Et = [
1298
+ var wt = [
1288
1299
  "tools/call",
1289
1300
  "resources/read",
1290
1301
  "prompts/get"
1291
1302
  ];
1292
- function Dt(e) {
1303
+ function Tt(e) {
1293
1304
  return JSON.stringify(e);
1294
1305
  }
1295
- function M(e, t, n) {
1296
- return Dt({
1306
+ function Et(e, t, n) {
1307
+ return Tt({
1297
1308
  jsonrpc: "2.0",
1298
1309
  id: e,
1299
1310
  error: {
@@ -1302,7 +1313,7 @@ function M(e, t, n) {
1302
1313
  }
1303
1314
  });
1304
1315
  }
1305
- function Ot(e) {
1316
+ function Dt(e) {
1306
1317
  let t = JSON.parse(e);
1307
1318
  return t.jsonrpc !== "2.0" || typeof t.method != "string" || t.method.length === 0 || typeof t.id != "string" && typeof t.id != "number" ? null : {
1308
1319
  jsonrpc: "2.0",
@@ -1311,30 +1322,30 @@ function Ot(e) {
1311
1322
  params: t.params
1312
1323
  };
1313
1324
  }
1314
- function kt(e) {
1325
+ function Ot(e) {
1315
1326
  return e.includes("not allowed") ? -32601 : e.includes("not authorized") ? -32001 : e.includes("rate-limited") ? -32002 : -32603;
1316
1327
  }
1317
- function At(e) {
1318
- let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Et, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1328
+ function kt(e) {
1329
+ let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? wt, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1319
1330
  async function s(t) {
1320
1331
  e.onAuditEvent && await e.onAuditEvent({
1321
1332
  ...t,
1322
1333
  timestampMs: Date.now()
1323
1334
  });
1324
1335
  }
1325
- let c = ct({
1336
+ let c = ot({
1326
1337
  agentId: t,
1327
1338
  outboundSecret: e.sharedSecret,
1328
1339
  sharedSecrets: { [n]: e.sharedSecret },
1329
1340
  wireFormat: a
1330
- }), l = ct({
1341
+ }), l = ot({
1331
1342
  agentId: n,
1332
1343
  outboundSecret: e.sharedSecret,
1333
1344
  sharedSecrets: { [t]: e.sharedSecret },
1334
1345
  wireFormat: o,
1335
1346
  onTask: async (e) => ({
1336
1347
  intent: "RESULT",
1337
- content: Dt({
1348
+ content: Tt({
1338
1349
  ok: !0,
1339
1350
  capability: e.body.capability,
1340
1351
  content: e.body.content
@@ -1347,12 +1358,12 @@ function At(e) {
1347
1358
  if (!i) return null;
1348
1359
  let a = null;
1349
1360
  try {
1350
- let t = Ot(i);
1361
+ let t = Dt(i);
1351
1362
  if (!t) return await s({
1352
1363
  phase: "request_error",
1353
1364
  code: -32600,
1354
1365
  message: "Invalid Request"
1355
- }), M(null, -32600, "Invalid Request");
1366
+ }), Et(null, -32600, "Invalid Request");
1356
1367
  a = t.id, await s({
1357
1368
  phase: "request_received",
1358
1369
  id: t.id,
@@ -1373,7 +1384,7 @@ function At(e) {
1373
1384
  policy: e
1374
1385
  });
1375
1386
  }
1376
- }, u = await mt(c, t, o), d = null;
1387
+ }, u = await ft(c, t, o), d = null;
1377
1388
  if (await l.handleRaw(u, async (e) => {
1378
1389
  d = e;
1379
1390
  }), !d) return await s({
@@ -1382,7 +1393,7 @@ function At(e) {
1382
1393
  method: t.method,
1383
1394
  code: -32603,
1384
1395
  message: "AIP worker did not produce a response"
1385
- }), M(a, -32603, "AIP worker did not produce a response");
1396
+ }), Et(a, -32603, "AIP worker did not produce a response");
1386
1397
  let f = await c.receiveRaw(d);
1387
1398
  return !f.ok || !f.received ? (await s({
1388
1399
  phase: "verification_failed",
@@ -1390,25 +1401,25 @@ function At(e) {
1390
1401
  method: t.method,
1391
1402
  code: -32603,
1392
1403
  message: "AIP verification failed"
1393
- }), M(a, -32603, "AIP verification failed")) : (await s({
1404
+ }), Et(a, -32603, "AIP verification failed")) : (await s({
1394
1405
  phase: "request_success",
1395
1406
  id: t.id,
1396
1407
  method: t.method
1397
- }), Dt(ht(f.received, t.id)));
1408
+ }), Tt(pt(f.received, t.id)));
1398
1409
  } catch (e) {
1399
- let t = e instanceof Error ? e.message : "Internal error", n = kt(t);
1410
+ let t = e instanceof Error ? e.message : "Internal error", n = Ot(t);
1400
1411
  return await s({
1401
1412
  phase: "request_error",
1402
1413
  id: a,
1403
1414
  code: n,
1404
1415
  message: t
1405
- }), M(a, n, t);
1416
+ }), Et(a, n, t);
1406
1417
  }
1407
1418
  } };
1408
1419
  }
1409
- async function jt(e) {
1410
- if (!e.runtimePolicy?.enabled) return At(e);
1411
- let { enforcer: t } = await j(e.runtimePolicy.options);
1420
+ async function At(e) {
1421
+ if (!e.runtimePolicy?.enabled) return kt(e);
1422
+ let { enforcer: t } = await N(e.runtimePolicy.options);
1412
1423
  t.assertInvariant({
1413
1424
  signatureVerification: !0,
1414
1425
  canonicalization: !0,
@@ -1420,7 +1431,7 @@ async function jt(e) {
1420
1431
  latencySensitive: e.runtimePolicy.latencySensitive,
1421
1432
  compatibilityFirst: e.runtimePolicy.compatibilityFirst
1422
1433
  }), r = n.includes("binary") ? "binary" : "compact";
1423
- return At({
1434
+ return kt({
1424
1435
  ...e,
1425
1436
  gatewayWireFormat: r,
1426
1437
  workerWireFormat: r,
@@ -1436,14 +1447,14 @@ async function jt(e) {
1436
1447
  }
1437
1448
  //#endregion
1438
1449
  //#region src/runtimePolicyManager.ts
1439
- var Mt = class {
1450
+ var jt = class {
1440
1451
  snapshot = null;
1441
1452
  options;
1442
1453
  constructor(e = {}) {
1443
1454
  this.options = e;
1444
1455
  }
1445
1456
  async loadInitial() {
1446
- let e = await j(this.options);
1457
+ let e = await N(this.options);
1447
1458
  return this.snapshot = {
1448
1459
  ...e,
1449
1460
  loadedAtMs: Date.now()
@@ -1456,7 +1467,7 @@ var Mt = class {
1456
1467
  async refresh() {
1457
1468
  let e = this.snapshot;
1458
1469
  try {
1459
- let e = await j(this.options);
1470
+ let e = await N(this.options);
1460
1471
  return this.snapshot = {
1461
1472
  ...e,
1462
1473
  loadedAtMs: Date.now()
@@ -1466,7 +1477,7 @@ var Mt = class {
1466
1477
  throw t;
1467
1478
  }
1468
1479
  }
1469
- }, Nt = {
1480
+ }, Mt = {
1470
1481
  dev: {
1471
1482
  environment: "dev",
1472
1483
  mode: "ws-batch",
@@ -1492,12 +1503,12 @@ var Mt = class {
1492
1503
  retryMaxAttempts: 3
1493
1504
  }
1494
1505
  };
1495
- function Pt(e) {
1496
- return Nt[e];
1506
+ function Nt(e) {
1507
+ return Mt[e];
1497
1508
  }
1498
1509
  //#endregion
1499
1510
  //#region src/policyTelemetryFeedback.ts
1500
- function Ft(e) {
1511
+ function Pt(e) {
1501
1512
  let t = [], n = "normal";
1502
1513
  return e.dropPct > .1 && (t.push("reduce inflight cap"), t.push("reduce batch size"), t.push("increase retry backoff"), e.mode === "http" && e.concurrency >= 100 && t.push("switch to http-binary-batch"), n = e.dropPct > 2 ? "critical" : "warn"), e.p99Ms > 20 && (t.push("reduce batch size"), t.push("run adaptive benchmark and re-baseline"), n === "normal" && (n = "warn"), e.p99Ms > 100 && (n = "critical")), {
1503
1514
  severity: n,
@@ -1506,7 +1517,7 @@ function Ft(e) {
1506
1517
  }
1507
1518
  //#endregion
1508
1519
  //#region src/redisClient.ts
1509
- var It = class {
1520
+ var Ft = class {
1510
1521
  entries = /* @__PURE__ */ new Map();
1511
1522
  now;
1512
1523
  constructor(e = {}) {
@@ -1552,13 +1563,13 @@ var It = class {
1552
1563
  };
1553
1564
  return t;
1554
1565
  }
1555
- }, Lt = class {
1566
+ }, It = class {
1556
1567
  keyPrefix;
1557
1568
  client;
1558
1569
  constructor(e = {}) {
1559
1570
  if (this.keyPrefix = e.keyPrefix ?? "7h3:nonce:", e.client) this.client = e.client;
1560
1571
  else {
1561
- let e = new It();
1572
+ let e = new Ft();
1562
1573
  this.client = {
1563
1574
  set: (t, n, r) => e.set(t, n, {
1564
1575
  nx: r?.nx,
@@ -1577,7 +1588,7 @@ var It = class {
1577
1588
  px: Math.max(1, t)
1578
1589
  }) === null;
1579
1590
  }
1580
- }, Rt = class {
1591
+ }, Lt = class {
1581
1592
  nodes;
1582
1593
  constructor(e) {
1583
1594
  this.nodes = e;
@@ -1586,17 +1597,17 @@ var It = class {
1586
1597
  return (await Promise.all(this.nodes.map((n) => n.check(e, t)))).some((e) => e);
1587
1598
  }
1588
1599
  };
1589
- function zt(e, t = {}) {
1590
- return Bt(e) ? Ht(e, t) : new Lt(e);
1600
+ function Rt(e, t = {}) {
1601
+ return zt(e) ? Vt(e, t) : new It(e);
1591
1602
  }
1592
- function Bt(e) {
1603
+ function zt(e) {
1593
1604
  return typeof e == "object" && !!e && typeof e.set == "function" && (typeof e.pipeline == "function" || !("quit" in e));
1594
1605
  }
1595
- function Vt(e) {
1596
- return new Rt(e.map((e) => new Lt({ redisUrl: e })));
1606
+ function Bt(e) {
1607
+ return new Lt(e.map((e) => new It({ redisUrl: e })));
1597
1608
  }
1598
- function Ht(e, t = {}) {
1599
- let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Ht(new It(), {
1609
+ function Vt(e, t = {}) {
1610
+ let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Vt(new Ft(), {
1600
1611
  keyPrefix: n,
1601
1612
  errorBehavior: "reject"
1602
1613
  }) : void 0);
@@ -1636,7 +1647,7 @@ function Ht(e, t = {}) {
1636
1647
  }
1637
1648
  //#endregion
1638
1649
  //#region src/revocation.ts
1639
- var Ut = class {
1650
+ var Ht = class {
1640
1651
  revoked = /* @__PURE__ */ new Map();
1641
1652
  now;
1642
1653
  constructor(e = {}) {
@@ -1653,7 +1664,7 @@ var Ut = class {
1653
1664
  this.revoked.set(this.makeKey(e, t), n.untilMs ?? Infinity);
1654
1665
  }
1655
1666
  };
1656
- function Wt(e, t = {}) {
1667
+ function Ut(e, t = {}) {
1657
1668
  let n = t.keyPrefix ?? "aip:revoked:", r = t.errorBehavior ?? "reject", i = t.cacheTtlMs ?? 5e3, a = t.onDegraded, o = t.now ?? (() => Date.now()), s = /* @__PURE__ */ new Map();
1658
1669
  function c(e, t) {
1659
1670
  return `${n}${e}${t}`;
@@ -1685,7 +1696,7 @@ function Wt(e, t = {}) {
1685
1696
  }
1686
1697
  };
1687
1698
  }
1688
- function Gt(e, t, n = {}) {
1699
+ function Wt(e, t, n = {}) {
1689
1700
  let r = n.nowMsProvider ?? (() => Date.now());
1690
1701
  return async (n, i) => {
1691
1702
  if (!await t.isRevoked(i, n.keyId, r())) return e(n, i);
@@ -1693,7 +1704,7 @@ function Gt(e, t, n = {}) {
1693
1704
  }
1694
1705
  //#endregion
1695
1706
  //#region src/mcpWrapper.ts
1696
- function N(e, t, n) {
1707
+ function Gt(e, t, n) {
1697
1708
  return {
1698
1709
  jsonrpc: "2.0",
1699
1710
  id: e,
@@ -1705,18 +1716,18 @@ function N(e, t, n) {
1705
1716
  }
1706
1717
  function Kt(e, t) {
1707
1718
  return {
1708
- requireSignature: !0,
1709
1719
  ...e.receive,
1720
+ requireSignature: !0,
1710
1721
  replayCache: t
1711
1722
  };
1712
1723
  }
1713
1724
  function qt(e, t) {
1714
- let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new k());
1725
+ let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new A());
1715
1726
  async function a(e) {
1716
- return Ke(await t.sign(e), n);
1727
+ return j(await t.sign(e), n);
1717
1728
  }
1718
1729
  function o(e, n, i, o) {
1719
- return a(E({
1730
+ return a(D({
1720
1731
  sender: t.selfAgentId,
1721
1732
  recipient: e,
1722
1733
  intent: n,
@@ -1726,29 +1737,29 @@ function qt(e, t) {
1726
1737
  }));
1727
1738
  }
1728
1739
  return async (n) => {
1729
- let r = await A(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1730
- if (!r.ok || !r.envelope) return o(a, "ERROR", N(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1731
- if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", N(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1740
+ let r = await M(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1741
+ if (!r.ok || !r.envelope) return o(a, "ERROR", Gt(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1742
+ if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", Gt(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1732
1743
  let c;
1733
1744
  try {
1734
1745
  c = JSON.parse(r.envelope.body.content);
1735
1746
  } catch {
1736
- return o(a, "ERROR", N(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1747
+ return o(a, "ERROR", Gt(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1737
1748
  }
1738
1749
  let l;
1739
1750
  try {
1740
1751
  l = await e(c);
1741
1752
  } catch (e) {
1742
- l = N(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1753
+ l = Gt(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1743
1754
  }
1744
1755
  return o(r.envelope.header.sender, "RESULT", l, s);
1745
1756
  };
1746
1757
  }
1747
1758
  function Jt(e) {
1748
- let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new k());
1759
+ let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new A());
1749
1760
  return {
1750
1761
  async encodeRequest(r) {
1751
- let i = E({
1762
+ let i = D({
1752
1763
  sender: e.selfAgentId,
1753
1764
  recipient: e.peerAgentId,
1754
1765
  intent: "TASK",
@@ -1756,12 +1767,12 @@ function Jt(e) {
1756
1767
  ttlMs: n
1757
1768
  });
1758
1769
  return {
1759
- raw: Ke(await e.sign(i), t),
1770
+ raw: j(await e.sign(i), t),
1760
1771
  messageId: i.header.messageId
1761
1772
  };
1762
1773
  },
1763
1774
  async decodeResponse(t, n = {}) {
1764
- let i = await A(t, r);
1775
+ let i = await M(t, r);
1765
1776
  if (!i.ok || !i.envelope) {
1766
1777
  let e = i.diagnostics.find((e) => e.level === "error")?.message ?? "unknown";
1767
1778
  throw Error(`AIP response verification failed: ${e}`);
@@ -2074,7 +2085,7 @@ var P = new TextEncoder(), an = new TextDecoder(), F = 0, on = 1, sn = 2, I = 3,
2074
2085
  return t;
2075
2086
  }
2076
2087
  case ln: {
2077
- let e = this._decodeUint(n), t = {};
2088
+ let e = this._decodeUint(n), t = Object.create(null);
2078
2089
  for (let n = 0; n < e; n++) {
2079
2090
  let e = this._decode();
2080
2091
  t[String(e)] = this._decode();
@@ -2143,7 +2154,18 @@ function wn(e) {
2143
2154
  }
2144
2155
  return xn(r);
2145
2156
  }
2146
- function Tn(e) {
2157
+ function L(e, t) {
2158
+ if (typeof e != "string") throw Error(`decodeEnvelopeCbor: ${t} must be a string`);
2159
+ return e;
2160
+ }
2161
+ function Tn(e, t) {
2162
+ if (e !== void 0) return L(e, t);
2163
+ }
2164
+ function En(e, t) {
2165
+ if (typeof e != "number" || !Number.isFinite(e)) throw Error(`decodeEnvelopeCbor: ${t} must be a finite number`);
2166
+ return e;
2167
+ }
2168
+ function Dn(e) {
2147
2169
  let t = Sn(e);
2148
2170
  if (!t || typeof t != "object" || Array.isArray(t)) throw Error("decodeEnvelopeCbor: expected a map at top level");
2149
2171
  let n = t, r = n[1];
@@ -2152,38 +2174,42 @@ function Tn(e) {
2152
2174
  if (!a || typeof a != "object" || Array.isArray(a)) throw Error("decodeEnvelopeCbor: missing body map (key 2)");
2153
2175
  let o = a, s = {
2154
2176
  header: {
2155
- version: i[1],
2156
- messageId: i[2],
2157
- timestampMs: i[3],
2158
- ttlMs: i[4],
2159
- sender: i[5],
2160
- nonce: i[7]
2177
+ version: L(i[1], "header.version"),
2178
+ messageId: L(i[2], "header.messageId"),
2179
+ timestampMs: En(i[3], "header.timestampMs"),
2180
+ ttlMs: En(i[4], "header.ttlMs"),
2181
+ sender: L(i[5], "header.sender"),
2182
+ nonce: L(i[7], "header.nonce")
2161
2183
  },
2162
2184
  body: {
2163
- intent: o[1],
2164
- content: o[2]
2165
- }
2166
- };
2167
- i[6] !== void 0 && (s.header.recipient = i[6]), o[3] !== void 0 && (s.body.capability = o[3]), o[4] !== void 0 && (s.body.correlationId = o[4]);
2168
- let c = n[3];
2169
- if (c != null) {
2170
- if (typeof c != "object" || Array.isArray(c)) throw Error("decodeEnvelopeCbor: expected signature map at key 3");
2171
- let e = c;
2185
+ intent: L(o[1], "body.intent"),
2186
+ content: L(o[2], "body.content")
2187
+ }
2188
+ }, c = Tn(i[6], "header.recipient");
2189
+ c !== void 0 && (s.header.recipient = c);
2190
+ let l = Tn(o[3], "body.capability");
2191
+ l !== void 0 && (s.body.capability = l);
2192
+ let u = Tn(o[4], "body.correlationId");
2193
+ u !== void 0 && (s.body.correlationId = u);
2194
+ let d = n[3];
2195
+ if (d != null) {
2196
+ if (typeof d != "object" || Array.isArray(d)) throw Error("decodeEnvelopeCbor: expected signature map at key 3");
2197
+ let e = d;
2172
2198
  s.signature = {
2173
- alg: e[1],
2174
- keyId: e[2],
2175
- value: e[3]
2199
+ alg: L(e[1], "signature.alg"),
2200
+ keyId: L(e[2], "signature.keyId"),
2201
+ value: L(e[3], "signature.value")
2176
2202
  };
2177
2203
  }
2178
2204
  return s;
2179
2205
  }
2180
2206
  //#endregion
2181
2207
  //#region src/httpBinding.ts
2182
- var En = "x-7h3-envelope";
2183
- async function Dn(e, t, n) {
2208
+ var On = "x-7h3-envelope";
2209
+ async function kn(e, t, n) {
2184
2210
  let r = t.headerName ?? "x-7h3-envelope", i = (Array.isArray(e["content-type"]) ? e["content-type"][0] : e["content-type"]) ?? "", a;
2185
2211
  if (i.includes("7h3-cbor") && n instanceof Uint8Array) try {
2186
- a = Tn(n);
2212
+ a = Dn(n);
2187
2213
  } catch (e) {
2188
2214
  return {
2189
2215
  ok: !1,
@@ -2213,7 +2239,7 @@ async function Dn(e, t, n) {
2213
2239
  detail: "missing required fields"
2214
2240
  };
2215
2241
  if (t.strictTtl ?? !0) {
2216
- let e = T(a).filter((e) => e.level === "error");
2242
+ let e = E(a).filter((e) => e.level === "error");
2217
2243
  if (e.length > 0) return {
2218
2244
  ok: !1,
2219
2245
  reason: "ttl-expired",
@@ -2228,7 +2254,7 @@ async function Dn(e, t, n) {
2228
2254
  reason: "unknown-sender",
2229
2255
  detail: o
2230
2256
  };
2231
- if (!await w(a, e)) return {
2257
+ if (!await T(a, e)) return {
2232
2258
  ok: !1,
2233
2259
  reason: "invalid-signature"
2234
2260
  };
@@ -2239,7 +2265,7 @@ async function Dn(e, t, n) {
2239
2265
  reason: "unknown-sender",
2240
2266
  detail: a.signature.keyId
2241
2267
  };
2242
- if (!await S(a, e)) return {
2268
+ if (!await C(a, e)) return {
2243
2269
  ok: !1,
2244
2270
  reason: "invalid-signature"
2245
2271
  };
@@ -2253,8 +2279,8 @@ async function Dn(e, t, n) {
2253
2279
  envelope: a
2254
2280
  };
2255
2281
  }
2256
- async function On(e, t, n) {
2257
- let r = await C(e, t);
2282
+ async function An(e, t, n) {
2283
+ let r = await w(e, t);
2258
2284
  if (n?.format === "cbor") {
2259
2285
  let e = wn(r);
2260
2286
  return {
@@ -2264,13 +2290,13 @@ async function On(e, t, n) {
2264
2290
  }
2265
2291
  return { headers: { [n?.headerName ?? "x-7h3-envelope"]: JSON.stringify(r) } };
2266
2292
  }
2267
- async function kn(e, t, n, r) {
2268
- let i = await me(e, t, n);
2293
+ async function jn(e, t, n, r) {
2294
+ let i = await S(e, t, n);
2269
2295
  return { headers: { [r?.headerName ?? "x-7h3-envelope"]: JSON.stringify(i) } };
2270
2296
  }
2271
- function An(e) {
2297
+ function Mn(e) {
2272
2298
  return async function(t, n, r) {
2273
- let i = await Dn(t.headers, e);
2299
+ let i = await kn(t.headers, e);
2274
2300
  if (!i.ok) {
2275
2301
  n.status(401).json({
2276
2302
  error: "7h3: request verification failed",
@@ -2282,13 +2308,13 @@ function An(e) {
2282
2308
  t["7h3Envelope"] = i.envelope, r();
2283
2309
  };
2284
2310
  }
2285
- async function jn(e, t, n, r) {
2286
- let { headers: i } = await On(t, n, r), a = new Headers(e.headers);
2311
+ async function Nn(e, t, n, r) {
2312
+ let { headers: i } = await An(t, n, r), a = new Headers(e.headers);
2287
2313
  for (let [e, t] of Object.entries(i)) a.set(e, t);
2288
2314
  return new Request(e, { headers: a });
2289
2315
  }
2290
- async function Mn(e, t) {
2291
- return jn(e, E({
2316
+ async function Pn(e, t) {
2317
+ return Nn(e, D({
2292
2318
  sender: t.sender,
2293
2319
  recipient: t.recipient,
2294
2320
  ttlMs: t.ttlMs ?? 6e4,
@@ -2298,49 +2324,68 @@ async function Mn(e, t) {
2298
2324
  }
2299
2325
  //#endregion
2300
2326
  //#region src/webhookBinding.ts
2301
- var L = "x-7h3-sig", R = "x-7h3-ts", Nn = 3e5;
2302
- function Pn(e, t) {
2327
+ var R = "x-7h3-sig", z = "x-7h3-ts", Fn = 3e5, In = class {
2328
+ seen = /* @__PURE__ */ new Map();
2329
+ maxEntries;
2330
+ constructor(e = 1e4) {
2331
+ this.maxEntries = e;
2332
+ }
2333
+ prune(e) {
2334
+ for (let [t, n] of this.seen) n <= e && this.seen.delete(t);
2335
+ }
2336
+ consume(e, t, n) {
2337
+ this.prune(n);
2338
+ let r = this.seen.get(e);
2339
+ if (r !== void 0 && r > n) return !1;
2340
+ if (this.seen.size >= this.maxEntries) {
2341
+ let e = this.seen.keys().next().value;
2342
+ e !== void 0 && this.seen.delete(e);
2343
+ }
2344
+ return this.seen.set(e, t), !0;
2345
+ }
2346
+ };
2347
+ function B(e, t) {
2303
2348
  return `${e}.${t}`;
2304
2349
  }
2305
- async function Fn(e, t) {
2306
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await b(Pn(r, n), t.privateKey);
2350
+ async function Ln(e, t) {
2351
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await b(B(r, n), t.privateKey);
2307
2352
  return {
2308
- [L]: i,
2309
- [R]: String(r)
2353
+ [R]: i,
2354
+ [z]: String(r)
2310
2355
  };
2311
2356
  }
2312
- async function In(e, t) {
2313
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(Pn(r, n), t.secret);
2357
+ async function Rn(e, t) {
2358
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(B(r, n), t.secret);
2314
2359
  return {
2315
- [L]: i,
2316
- [R]: String(r)
2360
+ [R]: i,
2361
+ [z]: String(r)
2317
2362
  };
2318
2363
  }
2319
- async function Ln(e, t, n) {
2320
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
2364
+ async function zn(e, t, n) {
2365
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[R], a = t[z];
2321
2366
  if (!i || !a) return !1;
2322
2367
  let o = Number(a);
2323
2368
  if (!Number.isFinite(o)) return !1;
2324
- let s = n.maxAgeMs ?? 3e5;
2325
- return Date.now() - o > s ? !1 : x(Pn(o, r), i, n.publicKey);
2369
+ let s = n.maxAgeMs ?? 3e5, c = Date.now();
2370
+ return !(c - o > s || !await x(B(o, r), i, n.publicKey) || n.replayCache && !await n.replayCache.consume(i, o + s, c));
2326
2371
  }
2327
- async function Rn(e, t, n) {
2328
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
2372
+ async function Bn(e, t, n) {
2373
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[R], a = t[z];
2329
2374
  if (!i || !a) return !1;
2330
2375
  let o = Number(a);
2331
2376
  if (!Number.isFinite(o)) return !1;
2332
- let s = n.maxAgeMs ?? 3e5;
2333
- return Date.now() - o > s ? !1 : fe(Pn(o, r), i, n.secret);
2377
+ let s = n.maxAgeMs ?? 3e5, c = Date.now();
2378
+ return !(c - o > s || !await fe(B(o, r), i, n.secret) || n.replayCache && !await n.replayCache.consume(i, o + s, c));
2334
2379
  }
2335
- async function zn(e, t, n) {
2336
- if (!await Ln(e, t, n)) throw Error("7h3: webhook signature verification failed");
2380
+ async function Vn(e, t, n) {
2381
+ if (!await zn(e, t, n)) throw Error("7h3: webhook signature verification failed");
2337
2382
  return JSON.parse(e);
2338
2383
  }
2339
2384
  //#endregion
2340
2385
  //#region src/queueBinding.ts
2341
- async function Bn(e, t) {
2386
+ async function Hn(e, t) {
2342
2387
  let n = t.ttlMs ?? 36e5, r = typeof e == "string" ? e : JSON.stringify(e), i = {
2343
- envelope: await C(E({
2388
+ envelope: await w(D({
2344
2389
  sender: t.sender,
2345
2390
  recipient: t.recipient,
2346
2391
  intent: "TASK",
@@ -2351,7 +2396,7 @@ async function Bn(e, t) {
2351
2396
  };
2352
2397
  return JSON.stringify(i);
2353
2398
  }
2354
- async function Vn(e, t) {
2399
+ async function Un(e, t) {
2355
2400
  let n;
2356
2401
  try {
2357
2402
  n = JSON.parse(e);
@@ -2361,10 +2406,10 @@ async function Vn(e, t) {
2361
2406
  if (!n.envelope || typeof n.envelope != "object") throw Error("Queue message missing envelope");
2362
2407
  let r = t.nowMs ?? Date.now();
2363
2408
  if (t.strictTtl ?? !0) {
2364
- let e = T(n.envelope, r).filter((e) => e.level === "error");
2409
+ let e = E(n.envelope, r).filter((e) => e.level === "error");
2365
2410
  if (e.length > 0) throw Error(`Queue message failed validation: ${e.map((e) => e.message).join("; ")}`);
2366
2411
  }
2367
- if (!await w(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2412
+ if (!await T(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2368
2413
  if (t.replayCache) {
2369
2414
  let e = await t.replayCache.consume(n.envelope, r);
2370
2415
  if (!e.ok) throw Error(e.reason ?? "Queue message replay detected");
@@ -2374,10 +2419,10 @@ async function Vn(e, t) {
2374
2419
  envelope: n.envelope
2375
2420
  };
2376
2421
  }
2377
- async function Hn(e, t) {
2422
+ async function Wn(e, t) {
2378
2423
  return Promise.all(e.map(async (e) => {
2379
2424
  try {
2380
- let { payload: n, envelope: r } = await Vn(e, t);
2425
+ let { payload: n, envelope: r } = await Un(e, t);
2381
2426
  return {
2382
2427
  ok: !0,
2383
2428
  payload: n,
@@ -2394,87 +2439,87 @@ async function Hn(e, t) {
2394
2439
  }
2395
2440
  //#endregion
2396
2441
  //#region src/stream.ts
2397
- var Un = "x-7h3-stream", z = new TextEncoder();
2398
- function B() {
2442
+ var Gn = "x-7h3-stream", V = new TextEncoder();
2443
+ function H() {
2399
2444
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
2400
2445
  return crypto.subtle;
2401
2446
  }
2402
- function Wn() {
2447
+ function Kn() {
2403
2448
  return globalThis.Buffer;
2404
2449
  }
2405
- function V(e) {
2406
- let t = Wn();
2450
+ function U(e) {
2451
+ let t = Kn();
2407
2452
  return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
2408
2453
  }
2409
- function H(e) {
2410
- let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = Wn();
2454
+ function W(e) {
2455
+ let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = Kn();
2411
2456
  if (n) return new Uint8Array(n.from(t, "base64"));
2412
2457
  let r = atob(t), i = new Uint8Array(r.length);
2413
2458
  for (let e = 0; e < r.length; e++) i[e] = r.charCodeAt(e);
2414
2459
  return i;
2415
2460
  }
2416
- function U(e) {
2461
+ function G(e) {
2417
2462
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
2418
2463
  }
2419
- function Gn() {
2464
+ function qn() {
2420
2465
  let e = /* @__PURE__ */ new Uint8Array(16);
2421
- return crypto.getRandomValues(e), V(e);
2466
+ return crypto.getRandomValues(e), U(e);
2422
2467
  }
2423
- var W = /* @__PURE__ */ new Map(), Kn = 128;
2424
- function qn(e, t) {
2425
- let n = `${e}:${t}`, r = W.get(n);
2468
+ var K = /* @__PURE__ */ new Map(), Jn = 128;
2469
+ function Yn(e, t) {
2470
+ let n = `${e}:${t}`, r = K.get(n);
2426
2471
  if (r) return r;
2427
- W.size >= Kn && W.clear();
2428
- let i = B(), a = H(e), o = (async () => {
2429
- let e = await i.importKey("raw", U(a), "HKDF", !1, ["deriveBits"]), n = await i.deriveBits({
2472
+ K.size >= Jn && K.clear();
2473
+ let i = H(), a = W(e), o = (async () => {
2474
+ let e = await i.importKey("raw", G(a), "HKDF", !1, ["deriveBits"]), n = await i.deriveBits({
2430
2475
  name: "HKDF",
2431
2476
  hash: "SHA-256",
2432
- salt: z.encode(t),
2433
- info: z.encode("7h3-stream/1")
2477
+ salt: V.encode(t),
2478
+ info: V.encode("7h3-stream/1")
2434
2479
  }, e, 256);
2435
2480
  return i.importKey("raw", n, {
2436
2481
  name: "HMAC",
2437
2482
  hash: "SHA-256"
2438
2483
  }, !1, ["sign"]);
2439
2484
  })();
2440
- return o.catch(() => W.delete(n)), W.set(n, o), o;
2485
+ return o.catch(() => K.delete(n)), K.set(n, o), o;
2441
2486
  }
2442
- var G = /* @__PURE__ */ new Map(), Jn = 64;
2443
- function Yn(e) {
2444
- let t = G.get(e);
2487
+ var q = /* @__PURE__ */ new Map(), Xn = 64;
2488
+ function Zn(e) {
2489
+ let t = q.get(e);
2445
2490
  if (t) return t;
2446
- G.size >= Jn && G.clear();
2447
- let n = B().importKey("pkcs8", U(H(e)), { name: "Ed25519" }, !1, ["sign"]).catch((t) => {
2448
- throw G.delete(e), t;
2491
+ q.size >= Xn && q.clear();
2492
+ let n = H().importKey("pkcs8", G(W(e)), { name: "Ed25519" }, !1, ["sign"]).catch((t) => {
2493
+ throw q.delete(e), t;
2449
2494
  });
2450
- return G.set(e, n), n;
2495
+ return q.set(e, n), n;
2451
2496
  }
2452
- var K = /* @__PURE__ */ new Map(), Xn = 64;
2453
- function Zn(e) {
2454
- let t = K.get(e);
2497
+ var J = /* @__PURE__ */ new Map(), Qn = 64;
2498
+ function $n(e) {
2499
+ let t = J.get(e);
2455
2500
  if (t) return t;
2456
- K.size >= Xn && K.clear();
2457
- let n = B().importKey("spki", U(H(e)), { name: "Ed25519" }, !1, ["verify"]).catch((t) => {
2458
- throw K.delete(e), t;
2501
+ J.size >= Qn && J.clear();
2502
+ let n = H().importKey("spki", G(W(e)), { name: "Ed25519" }, !1, ["verify"]).catch((t) => {
2503
+ throw J.delete(e), t;
2459
2504
  });
2460
- return K.set(e, n), n;
2505
+ return J.set(e, n), n;
2461
2506
  }
2462
- function Qn(e) {
2507
+ function er(e) {
2463
2508
  let t = e.map((e) => `${e.i}:${e.d}`);
2464
- return z.encode(t.join("\n"));
2509
+ return V.encode(t.join("\n"));
2465
2510
  }
2466
- async function $n(e) {
2467
- let t = await B().digest("SHA-256", U(e));
2511
+ async function tr(e) {
2512
+ let t = await H().digest("SHA-256", G(e));
2468
2513
  return new Uint8Array(t);
2469
2514
  }
2470
- var q = class {
2515
+ var nr = class {
2471
2516
  opts;
2472
2517
  seq = 0;
2473
2518
  accum = [];
2474
2519
  hmacKeyPromise = null;
2475
2520
  constructor(e) {
2476
2521
  this.opts = {
2477
- nonce: e.nonce ?? Gn(),
2522
+ nonce: e.nonce ?? qn(),
2478
2523
  keyId: e.keyId ?? "stream-key",
2479
2524
  ...e
2480
2525
  };
@@ -2483,11 +2528,11 @@ var q = class {
2483
2528
  return this.opts.nonce;
2484
2529
  }
2485
2530
  getHmacKey() {
2486
- return this.hmacKeyPromise ||= qn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2531
+ return this.hmacKeyPromise ||= Yn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2487
2532
  }
2488
2533
  async computeChunkHmac(e, t) {
2489
- let n = B(), r = await this.getHmacKey(), i = `${this.opts.nonce}:${e}:${t}`, a = await n.sign("HMAC", r, z.encode(i));
2490
- return V(new Uint8Array(a));
2534
+ let n = H(), r = await this.getHmacKey(), i = `${this.opts.nonce}:${e}:${t}`, a = await n.sign("HMAC", r, V.encode(i));
2535
+ return U(new Uint8Array(a));
2491
2536
  }
2492
2537
  async writeChunk(e) {
2493
2538
  let t = this.seq++, n = await this.computeChunkHmac(t, e);
@@ -2502,17 +2547,17 @@ var q = class {
2502
2547
  };
2503
2548
  }
2504
2549
  async finalize() {
2505
- let e = B(), t = await Yn(this.opts.privateKey), n = await $n(Qn(this.accum)), r = await e.sign("Ed25519", t, U(n)), i = V(new Uint8Array(r)), a = this.seq;
2550
+ let e = H(), t = await Zn(this.opts.privateKey), n = await tr(er(this.accum)), r = await e.sign("Ed25519", t, G(n)), i = U(new Uint8Array(r)), a = this.seq;
2506
2551
  return {
2507
2552
  i: a,
2508
2553
  d: "",
2509
- h: await this.computeChunkHmac(a, V(n)),
2554
+ h: await this.computeChunkHmac(a, U(n)),
2510
2555
  f: !0,
2511
2556
  sig: i,
2512
2557
  kid: this.opts.keyId
2513
2558
  };
2514
2559
  }
2515
- }, er = class {
2560
+ }, rr = class {
2516
2561
  opts;
2517
2562
  expectedSeq = 0;
2518
2563
  accum = [];
@@ -2533,7 +2578,7 @@ var q = class {
2533
2578
  } : e.i === this.expectedSeq ? (this.expectedSeq++, this.accum.push({
2534
2579
  i: e.i,
2535
2580
  d: e.d
2536
- }), this.totalBytes += z.encode(e.d).length, { ok: !0 }) : {
2581
+ }), this.totalBytes += V.encode(e.d).length, { ok: !0 }) : {
2537
2582
  ok: !1,
2538
2583
  reason: `sequence error: expected ${this.expectedSeq}, got ${e.i}`
2539
2584
  };
@@ -2547,17 +2592,17 @@ var q = class {
2547
2592
  ok: !1,
2548
2593
  reason: "missing signature on final chunk"
2549
2594
  };
2550
- let t = B(), n;
2595
+ let t = H(), n;
2551
2596
  try {
2552
- n = await Zn(this.opts.publicKey);
2597
+ n = await $n(this.opts.publicKey);
2553
2598
  } catch {
2554
2599
  return {
2555
2600
  ok: !1,
2556
2601
  reason: "invalid public key"
2557
2602
  };
2558
2603
  }
2559
- let r = await $n(Qn(this.accum)), i = H(e.sig);
2560
- return await t.verify("Ed25519", n, U(i), U(r)) ? {
2604
+ let r = await tr(er(this.accum)), i = W(e.sig);
2605
+ return await t.verify("Ed25519", n, G(i), G(r)) ? {
2561
2606
  ok: !0,
2562
2607
  totalBytes: this.totalBytes,
2563
2608
  chunkCount: this.accum.length
@@ -2567,20 +2612,20 @@ var q = class {
2567
2612
  };
2568
2613
  }
2569
2614
  };
2570
- function tr(e) {
2571
- return new q(e);
2615
+ function ir(e) {
2616
+ return new nr(e);
2572
2617
  }
2573
- function nr(e) {
2574
- return new er(e);
2618
+ function ar(e) {
2619
+ return new rr(e);
2575
2620
  }
2576
- async function rr(e, t) {
2577
- let n = new q(t), r = [];
2621
+ async function or(e, t) {
2622
+ let n = new nr(t), r = [];
2578
2623
  if (Array.isArray(e)) for (let t of e) r.push(await n.writeChunk(t));
2579
2624
  else for await (let t of e) r.push(await n.writeChunk(t));
2580
2625
  return r.push(await n.finalize()), r;
2581
2626
  }
2582
- async function ir(e, t) {
2583
- let n = new er(t), r = e.slice(0, -1), i = e[e.length - 1];
2627
+ async function sr(e, t) {
2628
+ let n = new rr(t), r = e.slice(0, -1), i = e[e.length - 1];
2584
2629
  if (e.length === 0) return {
2585
2630
  ok: !1,
2586
2631
  reason: "empty chunk array — missing final frame"
@@ -2606,10 +2651,10 @@ async function ir(e, t) {
2606
2651
  }
2607
2652
  return n.finalize(i);
2608
2653
  }
2609
- function ar(e) {
2654
+ function cr(e) {
2610
2655
  return JSON.stringify(e);
2611
2656
  }
2612
- function or(e) {
2657
+ function lr(e) {
2613
2658
  let t;
2614
2659
  try {
2615
2660
  t = JSON.parse(e);
@@ -2636,7 +2681,7 @@ function or(e) {
2636
2681
  }
2637
2682
  //#endregion
2638
2683
  //#region src/wsBinding.ts
2639
- function sr(e, t) {
2684
+ function ur(e, t) {
2640
2685
  let n = 0, r = [], i = [];
2641
2686
  function a(e, n) {
2642
2687
  t.onVerifyFail?.(e, n);
@@ -2660,15 +2705,22 @@ function sr(e, t) {
2660
2705
  a(/* @__PURE__ */ Error(`unknown sender: ${o}`), n);
2661
2706
  return;
2662
2707
  }
2663
- if (!await w(i, s).catch(() => !1)) {
2708
+ if (!await T(i, s).catch(() => !1)) {
2664
2709
  a(/* @__PURE__ */ Error("invalid signature"), n);
2665
2710
  return;
2666
2711
  }
2667
- let c = T(i);
2712
+ let c = E(i);
2668
2713
  if (c.some((e) => e.level === "error")) {
2669
2714
  a(/* @__PURE__ */ Error(`envelope invalid: ${c.map((e) => e.message).join("; ")}`), n);
2670
2715
  return;
2671
2716
  }
2717
+ if (t.replayCache) {
2718
+ let e = await t.replayCache.consume(i);
2719
+ if (!e.ok) {
2720
+ a(Error(e.reason ?? "replay detected"), n);
2721
+ return;
2722
+ }
2723
+ }
2672
2724
  let l = i.body.content;
2673
2725
  try {
2674
2726
  l = JSON.parse(i.body.content);
@@ -2682,7 +2734,7 @@ function sr(e, t) {
2682
2734
  return n;
2683
2735
  },
2684
2736
  async send(r) {
2685
- let i = typeof r == "string" ? r : JSON.stringify(r), a = await C(E({
2737
+ let i = typeof r == "string" ? r : JSON.stringify(r), a = await w(D({
2686
2738
  sender: t.sender,
2687
2739
  recipient: t.recipient,
2688
2740
  ttlMs: t.ttlMs ?? 3e4,
@@ -2700,28 +2752,28 @@ function sr(e, t) {
2700
2752
  }
2701
2753
  };
2702
2754
  }
2703
- function cr(e, t) {
2704
- let n = new q(t), r = async (t) => {
2755
+ function dr(e, t) {
2756
+ let n = new nr(t), r = async (t) => {
2705
2757
  let r = typeof t.data == "string" ? t.data : t.data.toString("utf8"), i = await n.writeChunk(r);
2706
- e.send(ar(i));
2758
+ e.send(cr(i));
2707
2759
  }, i = async () => {
2708
2760
  e.removeEventListener("message", r), e.removeEventListener("close", i);
2709
2761
  let t = await n.finalize();
2710
- e.send(ar(t));
2762
+ e.send(cr(t));
2711
2763
  };
2712
2764
  return e.addEventListener("message", r), e.addEventListener("close", i), n;
2713
2765
  }
2714
- function lr(e, t) {
2766
+ function fr(e, t) {
2715
2767
  return new Promise((n, r) => {
2716
2768
  let i = [], a = async (e) => {
2717
2769
  let a = typeof e.data == "string" ? e.data : e.data.toString("utf8"), o;
2718
2770
  try {
2719
- o = or(a);
2771
+ o = lr(a);
2720
2772
  } catch (e) {
2721
2773
  s(), r(e);
2722
2774
  return;
2723
2775
  }
2724
- i.push(o), o.f && (s(), n(await ir(i, t)));
2776
+ i.push(o), o.f && (s(), n(await sr(i, t)));
2725
2777
  }, o = () => {
2726
2778
  s(), n({
2727
2779
  ok: !1,
@@ -2736,9 +2788,9 @@ function lr(e, t) {
2736
2788
  }
2737
2789
  //#endregion
2738
2790
  //#region src/grpcBinding.ts
2739
- var ur = "7h3-envelope-bin";
2740
- async function dr(e) {
2741
- let t = await C(E({
2791
+ var pr = "7h3-envelope-bin";
2792
+ async function mr(e) {
2793
+ let t = await w(D({
2742
2794
  sender: e.sender,
2743
2795
  recipient: e.recipient,
2744
2796
  ttlMs: e.ttlMs ?? 6e4,
@@ -2747,7 +2799,7 @@ async function dr(e) {
2747
2799
  }), e.privateKey);
2748
2800
  return { [e.metadataKey ?? "7h3-envelope-bin"]: JSON.stringify(t) };
2749
2801
  }
2750
- async function fr(e, t) {
2802
+ async function hr(e, t) {
2751
2803
  let n = e[t.metadataKey ?? "7h3-envelope-bin"], r = Array.isArray(n) ? n[0] : n instanceof Uint8Array ? new TextDecoder().decode(n) : n;
2752
2804
  if (!r) return {
2753
2805
  ok: !1,
@@ -2764,7 +2816,7 @@ async function fr(e, t) {
2764
2816
  message: "7h3: malformed envelope metadata"
2765
2817
  };
2766
2818
  }
2767
- if (t.strictTtl !== !1 && T(i).some((e) => e.level === "error")) return {
2819
+ if (t.strictTtl !== !1 && E(i).some((e) => e.level === "error")) return {
2768
2820
  ok: !1,
2769
2821
  code: 4,
2770
2822
  message: "7h3: envelope expired or invalid"
@@ -2782,7 +2834,7 @@ async function fr(e, t) {
2782
2834
  code: 16,
2783
2835
  message: `7h3: unknown sender ${a}`
2784
2836
  };
2785
- if (!await w(i, e)) return {
2837
+ if (!await T(i, e)) return {
2786
2838
  ok: !1,
2787
2839
  code: 16,
2788
2840
  message: "7h3: invalid signature"
@@ -2794,7 +2846,7 @@ async function fr(e, t) {
2794
2846
  code: 16,
2795
2847
  message: "7h3: unknown key"
2796
2848
  };
2797
- if (!await S(i, e)) return {
2849
+ if (!await C(i, e)) return {
2798
2850
  ok: !1,
2799
2851
  code: 16,
2800
2852
  message: "7h3: invalid signature"
@@ -2809,39 +2861,39 @@ async function fr(e, t) {
2809
2861
  envelope: i
2810
2862
  };
2811
2863
  }
2812
- function pr(e, t) {
2864
+ function gr(e, t) {
2813
2865
  return async (n) => {
2814
- let r = await fr(n.metadata, t);
2866
+ let r = await hr(n.metadata, t);
2815
2867
  if (!r.ok) throw Object.assign(Error(r.message), { code: r.code });
2816
2868
  return n["7h3Envelope"] = r.envelope, e(n);
2817
2869
  };
2818
2870
  }
2819
2871
  //#endregion
2820
2872
  //#region src/keyInfra.ts
2821
- function mr(e) {
2873
+ function _r(e) {
2822
2874
  return JSON.stringify(e);
2823
2875
  }
2824
- function hr(e) {
2876
+ function vr(e) {
2825
2877
  let t = JSON.parse(e);
2826
2878
  if (t.version !== "7h3/0.1") throw Error(`unsupported version: ${t.version}`);
2827
2879
  return t;
2828
2880
  }
2829
- async function gr(e, t) {
2881
+ async function yr(e, t) {
2830
2882
  let n = e.replace(/\/$/, "") + "/.well-known/7h3-keys", r = new AbortController(), i = t?.timeout ? setTimeout(() => r.abort(), t.timeout) : void 0;
2831
2883
  try {
2832
2884
  let e = await fetch(n, { signal: r.signal });
2833
2885
  if (!e.ok) throw Error(`HTTP ${e.status} from ${n}`);
2834
- return hr(await e.text());
2886
+ return vr(await e.text());
2835
2887
  } finally {
2836
2888
  i !== void 0 && clearTimeout(i);
2837
2889
  }
2838
2890
  }
2839
- function _r(e) {
2891
+ function br(e) {
2840
2892
  let t = /* @__PURE__ */ new Map(), n = e?.cacheMs ?? 6e4, r = e?.timeout ?? 5e3;
2841
2893
  async function i(e) {
2842
2894
  let i = Date.now(), a = t.get(e);
2843
2895
  if (a && a.expiresAt > i) return a.doc;
2844
- let o = await gr(e, { timeout: r });
2896
+ let o = await yr(e, { timeout: r });
2845
2897
  return t.set(e, {
2846
2898
  doc: o,
2847
2899
  expiresAt: i + n
@@ -2858,7 +2910,7 @@ function _r(e) {
2858
2910
  }
2859
2911
  } };
2860
2912
  }
2861
- var vr = class {
2913
+ var xr = class {
2862
2914
  maxAgeMs;
2863
2915
  overlapMs;
2864
2916
  keys = [];
@@ -2905,10 +2957,10 @@ var vr = class {
2905
2957
  toKeyRegistry() {
2906
2958
  return { getPublicKey: async (e) => {
2907
2959
  let t = Date.now();
2908
- return this.keys.find((n) => n.id === e && (!n.expiresAt || n.expiresAt > t))?.publicKey ?? this.getCurrentKey()?.publicKey ?? null;
2960
+ return this.keys.find((n) => n.id === e && (!n.expiresAt || n.expiresAt > t))?.publicKey ?? null;
2909
2961
  } };
2910
2962
  }
2911
- }, yr = class {
2963
+ }, Sr = class {
2912
2964
  revoked = /* @__PURE__ */ new Map();
2913
2965
  revoke(e, t) {
2914
2966
  this.revoked.set(e, {
@@ -2933,11 +2985,15 @@ var vr = class {
2933
2985
  wrapRegistry(e) {
2934
2986
  return {
2935
2987
  getPublicKey: async (t) => this.isRevoked(t) ? null : e.getPublicKey(t),
2936
- getSharedSecret: e.getSharedSecret?.bind(e)
2988
+ getSharedSecret: e.getSharedSecret ? async (t, n) => this.isRevoked(t) || this.isRevoked(n) ? null : e.getSharedSecret(t, n) : void 0
2937
2989
  };
2938
2990
  }
2939
- }, br = class {
2991
+ }, Cr = class {
2940
2992
  windows = /* @__PURE__ */ new Map();
2993
+ maxKeys;
2994
+ constructor(e = {}) {
2995
+ this.maxKeys = e.maxKeys ?? 5e4;
2996
+ }
2941
2997
  check(e, t, n = Date.now()) {
2942
2998
  let r = n - t.windowMs, i = (this.windows.get(e) ?? []).filter((e) => e > r), a = i.length, o = a < t.requests;
2943
2999
  return {
@@ -2948,7 +3004,13 @@ var vr = class {
2948
3004
  }
2949
3005
  consume(e, t, n = Date.now()) {
2950
3006
  let r = n - t.windowMs, i = (this.windows.get(e) ?? []).filter((e) => e > r), a = i.length < t.requests;
2951
- return a && (i.push(n), this.windows.set(e, i)), {
3007
+ if (a && i.push(n), i.length > 0) for (this.windows.delete(e), this.windows.set(e, i); this.windows.size > this.maxKeys;) {
3008
+ let e = this.windows.keys().next().value;
3009
+ if (e === void 0) break;
3010
+ this.windows.delete(e);
3011
+ }
3012
+ else this.windows.delete(e);
3013
+ return {
2952
3014
  allowed: a,
2953
3015
  remaining: Math.max(0, t.requests - i.length),
2954
3016
  resetMs: i.length > 0 ? Math.max(0, i[0] + t.windowMs - n) : 0
@@ -2960,10 +3022,10 @@ var vr = class {
2960
3022
  clear() {
2961
3023
  this.windows.clear();
2962
3024
  }
2963
- }, xr = new br();
3025
+ }, wr = new Cr();
2964
3026
  //#endregion
2965
3027
  //#region src/routePolicy.ts
2966
- function J(e, t) {
3028
+ function Tr(e, t) {
2967
3029
  let n = "^", r = 0;
2968
3030
  for (; r < e.length;) {
2969
3031
  let t = e[r];
@@ -2971,18 +3033,18 @@ function J(e, t) {
2971
3033
  }
2972
3034
  return n += "$", new RegExp(n).test(t);
2973
3035
  }
2974
- function Sr(e, t) {
2975
- for (let n of e) if (J(n.path, t)) return n;
3036
+ function Er(e, t) {
3037
+ for (let n of e) if (Tr(n.path, t)) return n;
2976
3038
  return null;
2977
3039
  }
2978
- function Cr(e, t) {
3040
+ function Dr(e, t) {
2979
3041
  return !e.allowedSenders || e.allowedSenders.length === 0 || e.allowedSenders.includes(t);
2980
3042
  }
2981
3043
  //#endregion
2982
3044
  //#region src/signedResponse.ts
2983
- var wr = "x-7h3-response";
2984
- async function Tr(e, t) {
2985
- let n = await C(E({
3045
+ var Or = "x-7h3-response";
3046
+ async function kr(e, t) {
3047
+ let n = await w(D({
2986
3048
  sender: t.sender,
2987
3049
  recipient: t.recipient,
2988
3050
  intent: "RESULT",
@@ -2990,10 +3052,10 @@ async function Tr(e, t) {
2990
3052
  correlationId: t.correlationId,
2991
3053
  ttlMs: t.ttlMs ?? 6e4
2992
3054
  }), t.privateKey);
2993
- return { headers: { [wr]: JSON.stringify(n) } };
3055
+ return { headers: { [Or]: JSON.stringify(n) } };
2994
3056
  }
2995
- async function Er(e, t, n) {
2996
- let r = t[wr], i = Array.isArray(r) ? r[0] : r;
3057
+ async function Ar(e, t, n) {
3058
+ let r = t[Or], i = Array.isArray(r) ? r[0] : r;
2997
3059
  if (!i) return {
2998
3060
  ok: !1,
2999
3061
  reason: "missing-header"
@@ -3012,7 +3074,7 @@ async function Er(e, t, n) {
3012
3074
  ok: !1,
3013
3075
  reason: "ttl-expired",
3014
3076
  envelope: a
3015
- } : await w(a, n.publicKey) ? a.body.content === e ? {
3077
+ } : await T(a, n.publicKey) ? a.body.content === e ? {
3016
3078
  ok: !0,
3017
3079
  envelope: a
3018
3080
  } : {
@@ -3027,21 +3089,21 @@ async function Er(e, t, n) {
3027
3089
  }
3028
3090
  //#endregion
3029
3091
  //#region src/telemetry.ts
3030
- function Y(e) {
3092
+ function jr(e) {
3031
3093
  return !e || Object.keys(e).length === 0 ? "__default__" : Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}=${t}`).join(",");
3032
3094
  }
3033
- function Dr(e) {
3095
+ function Mr(e) {
3034
3096
  return !e || Object.keys(e).length === 0 ? "" : `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}="${t}"`).join(",")}}`;
3035
3097
  }
3036
- var X = class {
3098
+ var Y = class {
3037
3099
  counts = /* @__PURE__ */ new Map();
3038
3100
  labelSets = /* @__PURE__ */ new Map();
3039
3101
  increment(e) {
3040
- let t = Y(e);
3102
+ let t = jr(e);
3041
3103
  this.counts.set(t, (this.counts.get(t) ?? 0) + 1), this.labelSets.has(t) || this.labelSets.set(t, e);
3042
3104
  }
3043
3105
  value(e) {
3044
- return this.counts.get(Y(e)) ?? 0;
3106
+ return this.counts.get(jr(e)) ?? 0;
3045
3107
  }
3046
3108
  entries() {
3047
3109
  let e = [];
@@ -3051,7 +3113,7 @@ var X = class {
3051
3113
  });
3052
3114
  return e;
3053
3115
  }
3054
- }, Or = class {
3116
+ }, Nr = class {
3055
3117
  bucketBounds;
3056
3118
  states = /* @__PURE__ */ new Map();
3057
3119
  labelSets = /* @__PURE__ */ new Map();
@@ -3071,7 +3133,7 @@ var X = class {
3071
3133
  this.bucketBounds = [...e].sort((e, t) => e - t);
3072
3134
  }
3073
3135
  observe(e, t) {
3074
- let n = Y(t);
3136
+ let n = jr(t);
3075
3137
  this.states.has(n) || (this.states.set(n, {
3076
3138
  count: 0,
3077
3139
  sum: 0,
@@ -3081,7 +3143,7 @@ var X = class {
3081
3143
  r.count++, r.sum += e, r.observations.push(e);
3082
3144
  }
3083
3145
  snapshot(e) {
3084
- let t = Y(e), n = this.states.get(t) ?? {
3146
+ let t = jr(e), n = this.states.get(t) ?? {
3085
3147
  count: 0,
3086
3148
  sum: 0,
3087
3149
  observations: []
@@ -3107,9 +3169,9 @@ var X = class {
3107
3169
  getBounds() {
3108
3170
  return [...this.bucketBounds];
3109
3171
  }
3110
- }, kr = class {
3111
- verifications_total = new X();
3112
- verification_duration_ms = new Or([
3172
+ }, Pr = class {
3173
+ verifications_total = new Y();
3174
+ verification_duration_ms = new Nr([
3113
3175
  .1,
3114
3176
  .5,
3115
3177
  1,
@@ -3118,20 +3180,20 @@ var X = class {
3118
3180
  50,
3119
3181
  100
3120
3182
  ]);
3121
- rate_limit_hits_total = new X();
3122
- sender_denials_total = new X();
3123
- replay_detections_total = new X();
3124
- audit_entries_total = new X();
3125
- active_connections = new X();
3126
- }, Z = new kr();
3127
- function Ar(e, t = "7h3") {
3183
+ rate_limit_hits_total = new Y();
3184
+ sender_denials_total = new Y();
3185
+ replay_detections_total = new Y();
3186
+ audit_entries_total = new Y();
3187
+ active_connections = new Y();
3188
+ }, X = new Pr();
3189
+ function Fr(e, t = "7h3") {
3128
3190
  let n = [];
3129
3191
  function r(e, r, i) {
3130
3192
  let a = `${t}_${e}`;
3131
3193
  n.push(`# HELP ${a} ${r}`), n.push(`# TYPE ${a} counter`);
3132
3194
  let o = i.entries();
3133
3195
  if (o.length === 0) n.push(`${a} 0`);
3134
- else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Dr(e)} ${t}`) : n.push(`${a} ${t}`);
3196
+ else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Mr(e)} ${t}`) : n.push(`${a} ${t}`);
3135
3197
  }
3136
3198
  function i(e, r, i) {
3137
3199
  let a = `${t}_${e}`;
@@ -3141,7 +3203,7 @@ function Ar(e, t = "7h3") {
3141
3203
  for (let e of i.getBounds()) n.push(`${a}_bucket{le="${e}"} 0`);
3142
3204
  n.push(`${a}_bucket{le="+Inf"} 0`), n.push(`${a}_sum 0`), n.push(`${a}_count 0`);
3143
3205
  } else for (let { labels: e, snapshot: t } of o) {
3144
- let r = e && Object.keys(e).length > 0 ? Dr(e) : "";
3206
+ let r = e && Object.keys(e).length > 0 ? Mr(e) : "";
3145
3207
  for (let [e, i] of Object.entries(t.buckets)) {
3146
3208
  if (e === "+Inf") continue;
3147
3209
  let t = r ? r.slice(0, -1) + `,le="${e}"}` : `{le="${e}"}`;
@@ -3153,28 +3215,28 @@ function Ar(e, t = "7h3") {
3153
3215
  }
3154
3216
  return r("verifications_total", "Total number of AIP envelope verifications, by result, algorithm, and transport", e.verifications_total), i("verification_duration_ms", "Verification latency in milliseconds", e.verification_duration_ms), r("rate_limit_hits_total", "Total number of rate-limit rejections, by sender and path", e.rate_limit_hits_total), r("sender_denials_total", "Total number of sender-denied (403) rejections, by sender and path", e.sender_denials_total), r("replay_detections_total", "Total number of replay-detected events, by transport", e.replay_detections_total), r("audit_entries_total", "Total number of audit log entries written, by type", e.audit_entries_total), r("active_connections", "Current active connections, by transport (WS/gRPC)", e.active_connections), n.join("\n") + "\n";
3155
3217
  }
3156
- function jr(e = "/metrics", t = Z, n = "7h3") {
3218
+ function Ir(e = "/metrics", t = X, n = "7h3") {
3157
3219
  return (r, i, a) => {
3158
3220
  if (r.url === e && (r.method === "GET" || r.method === void 0)) {
3159
- let e = Ar(t, n);
3221
+ let e = Fr(t, n);
3160
3222
  i.writeHead(200, { "content-type": "text/plain; version=0.0.4; charset=utf-8" }), i.end(e);
3161
3223
  } else a();
3162
3224
  };
3163
3225
  }
3164
3226
  //#endregion
3165
3227
  //#region src/capability.ts
3166
- var Mr = "x-7h3-capability";
3167
- function Nr(e) {
3228
+ var Lr = "x-7h3-capability";
3229
+ function Rr(e) {
3168
3230
  let t = [];
3169
3231
  return e.maxDelegations !== void 0 && t.push(`"maxDelegations":${e.maxDelegations}`), e.methods !== void 0 && t.push(`"methods":${JSON.stringify(e.methods)}`), t.push(`"pathGlob":${JSON.stringify(e.pathGlob)}`), `{${t.join(",")}}`;
3170
3232
  }
3171
- function Q(e) {
3233
+ function Z(e) {
3172
3234
  let t = [];
3173
3235
  t.push(`"delegationDepth":${e.delegationDepth}`), t.push(`"expiresAt":${e.expiresAt}`), t.push(`"id":${JSON.stringify(e.id)}`), t.push(`"issuedAt":${e.issuedAt}`), t.push(`"issuer":${JSON.stringify(e.issuer)}`), t.push(`"keyId":${JSON.stringify(e.keyId)}`), e.maxDelegations !== void 0 && t.push(`"maxDelegations":${e.maxDelegations}`), e.parentTokenId !== void 0 && t.push(`"parentTokenId":${JSON.stringify(e.parentTokenId)}`);
3174
- let n = `[${e.scopes.map(Nr).join(",")}]`;
3236
+ let n = `[${e.scopes.map(Rr).join(",")}]`;
3175
3237
  return t.push(`"scopes":${n}`), t.push(`"subject":${JSON.stringify(e.subject)}`), t.push(`"version":${JSON.stringify(e.version)}`), `{${t.join(",")}}`;
3176
3238
  }
3177
- async function Pr(e) {
3239
+ async function zr(e) {
3178
3240
  let t = Date.now(), n = `cap-${t}-${y(6)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3179
3241
  id: n,
3180
3242
  version: "7h3-cap/1",
@@ -3186,32 +3248,46 @@ async function Pr(e) {
3186
3248
  delegationDepth: 0,
3187
3249
  maxDelegations: i,
3188
3250
  keyId: r
3189
- }, o = await b(Q(a), e.issuerPrivateKey);
3251
+ }, o = await b(Z(a), e.issuerPrivateKey);
3190
3252
  return {
3191
3253
  ...a,
3192
3254
  signature: o
3193
3255
  };
3194
3256
  }
3195
- function Fr(e, t) {
3196
- if (!J(t.pathGlob, e.pathGlob)) return !1;
3257
+ function Br(e, t) {
3258
+ return e === t || t === "*" && e !== "**";
3259
+ }
3260
+ function Vr(e, t) {
3261
+ let n = e.split("/"), r = t.split("/"), i = 0;
3262
+ for (let e of r) {
3263
+ if (e === "**") return !0;
3264
+ if (i >= n.length) return !1;
3265
+ let t = n[i];
3266
+ if (t === "**" || !Br(t, e)) return !1;
3267
+ i += 1;
3268
+ }
3269
+ return i === n.length;
3270
+ }
3271
+ function Hr(e, t) {
3272
+ if (!Vr(e.pathGlob, t.pathGlob)) return !1;
3197
3273
  if (t.methods !== void 0) {
3198
3274
  if (e.methods === void 0) return !1;
3199
3275
  for (let n of e.methods) if (!t.methods.includes(n)) return !1;
3200
3276
  }
3201
3277
  return !0;
3202
3278
  }
3203
- function Ir(e, t) {
3204
- for (let n of e) if (!t.some((e) => Fr(n, e))) return !1;
3279
+ function Ur(e, t) {
3280
+ for (let n of e) if (!t.some((e) => Hr(n, e))) return !1;
3205
3281
  return !0;
3206
3282
  }
3207
- async function Lr(e) {
3283
+ async function Wr(e) {
3208
3284
  let { parentToken: t, delegatorId: n, newSubject: r } = e;
3209
3285
  if (n !== t.subject) throw Error(`delegatorId '${n}' does not match parentToken.subject '${t.subject}'`);
3210
3286
  let i = Date.now();
3211
3287
  if (i >= t.expiresAt) throw Error("Parent token is expired");
3212
3288
  if (t.maxDelegations !== void 0 && t.maxDelegations <= 0) throw Error("Parent token does not allow further delegation (maxDelegations=0)");
3213
3289
  let a = e.scopes ?? t.scopes;
3214
- if (!Ir(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3290
+ if (!Ur(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3215
3291
  let o = t.expiresAt - i;
3216
3292
  if (e.ttlMs > o) throw Error(`Delegated ttlMs (${e.ttlMs}) exceeds parent token remaining TTL (${o})`);
3217
3293
  let s = `cap-${i}-${y(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
@@ -3226,18 +3302,18 @@ async function Lr(e) {
3226
3302
  parentTokenId: t.id,
3227
3303
  maxDelegations: l,
3228
3304
  keyId: c
3229
- }, d = await b(Q(u), e.delegatorPrivateKey);
3305
+ }, d = await b(Z(u), e.delegatorPrivateKey);
3230
3306
  return {
3231
3307
  ...u,
3232
3308
  signature: d
3233
3309
  };
3234
3310
  }
3235
- async function Rr(e, t, n) {
3311
+ async function Gr(e, t, n) {
3236
3312
  if ((n?.now ?? Date.now()) >= e.expiresAt) return !1;
3237
3313
  let { signature: r, ...i } = e;
3238
- return x(Q(i), r, t);
3314
+ return x(Z(i), r, t);
3239
3315
  }
3240
- async function zr(e, t, n) {
3316
+ async function Kr(e, t, n) {
3241
3317
  if (e.length === 0) return {
3242
3318
  ok: !1,
3243
3319
  reason: "empty-chain"
@@ -3263,6 +3339,18 @@ async function zr(e, t, n) {
3263
3339
  ok: !1,
3264
3340
  reason: `chain-broken: token[${n}].delegationDepth ${i.delegationDepth} !== ${t.delegationDepth + 1}`
3265
3341
  };
3342
+ if (t.maxDelegations !== void 0 && t.maxDelegations <= 0) return {
3343
+ ok: !1,
3344
+ reason: `chain-broken: token[${n - 1}] does not permit further delegation (maxDelegations=0)`
3345
+ };
3346
+ if (i.expiresAt > t.expiresAt) return {
3347
+ ok: !1,
3348
+ reason: `chain-broken: token[${n}].expiresAt exceeds token[${n - 1}].expiresAt`
3349
+ };
3350
+ if (!Ur(i.scopes, t.scopes)) return {
3351
+ ok: !1,
3352
+ reason: `chain-broken: token[${n}].scopes exceed token[${n - 1}].scopes`
3353
+ };
3266
3354
  }
3267
3355
  if (r >= i.expiresAt) return {
3268
3356
  ok: !1,
@@ -3274,13 +3362,13 @@ async function zr(e, t, n) {
3274
3362
  reason: `no-public-key-for-issuer:${i.issuer}`
3275
3363
  };
3276
3364
  let { signature: o, ...s } = i;
3277
- if (!await x(Q(s), o, a)) return {
3365
+ if (!await x(Z(s), o, a)) return {
3278
3366
  ok: !1,
3279
3367
  reason: `invalid-signature-at-index:${n}`
3280
3368
  };
3281
3369
  }
3282
3370
  let i = e[e.length - 1];
3283
- return n?.requiredPathGlob !== void 0 && !Br(i, n.requiredPathGlob, n.requiredMethod) ? {
3371
+ return n?.requiredPathGlob !== void 0 && !qr(i, n.requiredPathGlob, n.requiredMethod) ? {
3284
3372
  ok: !1,
3285
3373
  reason: "leaf-token-does-not-cover-required-scope"
3286
3374
  } : {
@@ -3289,85 +3377,151 @@ async function zr(e, t, n) {
3289
3377
  chain: e
3290
3378
  };
3291
3379
  }
3292
- function Br(e, t, n) {
3293
- for (let r of e.scopes) if (J(r.pathGlob, t) && (r.methods === void 0 || n === void 0 || r.methods.includes(n.toUpperCase()))) return !0;
3380
+ function qr(e, t, n) {
3381
+ for (let r of e.scopes) if (Tr(r.pathGlob, t) && (r.methods === void 0 || n !== void 0 && r.methods.includes(n.toUpperCase()))) return !0;
3294
3382
  return !1;
3295
3383
  }
3296
- function Vr(e) {
3384
+ function Jr(e) {
3297
3385
  return JSON.stringify(e);
3298
3386
  }
3299
- function Hr(e) {
3387
+ function Yr(e) {
3300
3388
  return JSON.parse(e);
3301
3389
  }
3302
3390
  //#endregion
3303
3391
  //#region src/gateway.ts
3304
- var Ur = class {
3392
+ function Xr(e) {
3393
+ if (!e.startsWith("/")) return null;
3394
+ let t = e;
3395
+ for (let e = 0; e < 5; e++) {
3396
+ let e;
3397
+ try {
3398
+ e = decodeURIComponent(t);
3399
+ } catch {
3400
+ return null;
3401
+ }
3402
+ if (e === t) break;
3403
+ t = e;
3404
+ }
3405
+ if (/%[0-9a-fA-F]{2}/.test(t) || /[\x00-\x1f]/.test(t)) return null;
3406
+ let n = t.split("/"), r = [];
3407
+ for (let e of n) if (!(e === "" || e === ".")) {
3408
+ if (e === "..") {
3409
+ if (r.length === 0) return null;
3410
+ r.pop();
3411
+ continue;
3412
+ }
3413
+ r.push(e);
3414
+ }
3415
+ return "/" + r.join("/");
3416
+ }
3417
+ var Zr = class {
3305
3418
  config;
3306
3419
  rateLimiter;
3307
3420
  constructor(e) {
3308
- this.config = e, this.rateLimiter = new br(), !e.replayStore && (e.policies ?? []).some((e) => e.require !== "none") && console.warn("[7h3-protocol] createGateway(): no replayStore configured with signature-requiring policies. Nonce/replay protection will not survive multiple gateway instances or restarts. See docs/GATEWAY.md#production-safety.");
3421
+ this.config = e, this.rateLimiter = new Cr(), !e.replayStore && (e.policies ?? []).some((e) => e.require !== "none") && console.warn("[7h3-protocol] createGateway(): no replayStore configured with signature-requiring policies. Nonce/replay protection will not survive multiple gateway instances or restarts. See docs/GATEWAY.md#production-safety.");
3422
+ }
3423
+ async checkSenderAndRateLimit(e, t, n, r, i) {
3424
+ if (e && !Dr(e, t)) {
3425
+ let e = performance.now() - i;
3426
+ return X.verifications_total.increment({
3427
+ result: "fail",
3428
+ alg: n,
3429
+ transport: "http"
3430
+ }), X.verification_duration_ms.observe(e), X.sender_denials_total.increment({
3431
+ sender: t,
3432
+ path: r.path
3433
+ }), {
3434
+ ok: !1,
3435
+ status: 403,
3436
+ reason: "sender-denied"
3437
+ };
3438
+ }
3439
+ if (e?.rateLimit && !(this.config.rateLimitStore ? await this.config.rateLimitStore.consume(t, e.rateLimit) : this.rateLimiter.consume(t, e.rateLimit)).allowed) {
3440
+ let e = performance.now() - i;
3441
+ return X.verifications_total.increment({
3442
+ result: "fail",
3443
+ alg: n,
3444
+ transport: "http"
3445
+ }), X.verification_duration_ms.observe(e), X.rate_limit_hits_total.increment({
3446
+ sender: t,
3447
+ path: r.path
3448
+ }), {
3449
+ ok: !1,
3450
+ status: 429,
3451
+ reason: "rate-limited"
3452
+ };
3453
+ }
3454
+ return null;
3309
3455
  }
3310
3456
  async verify(e) {
3311
- let t = performance.now(), n = Sr(this.config.policies ?? [], e.path);
3312
- if (n?.require === "none" || !n && (this.config.defaultPolicy ?? "allow") === "allow") {
3457
+ let t = performance.now(), n = Xr(e.path);
3458
+ if (n === null) return {
3459
+ ok: !1,
3460
+ status: 400,
3461
+ reason: "invalid-path"
3462
+ };
3463
+ let r = Er(this.config.policies ?? [], n);
3464
+ if (r?.require === "none" || !r && (this.config.defaultPolicy ?? "allow") === "allow") {
3313
3465
  let e = performance.now() - t;
3314
- return Z.verifications_total.increment({
3466
+ return X.verifications_total.increment({
3315
3467
  result: "ok",
3316
3468
  alg: "none",
3317
3469
  transport: "http"
3318
- }), Z.verification_duration_ms.observe(e), {
3470
+ }), X.verification_duration_ms.observe(e), {
3319
3471
  ok: !0,
3320
3472
  sender: ""
3321
3473
  };
3322
3474
  }
3323
3475
  if (this.config.capabilityRegistry) {
3324
- let n = e.headers[Mr], r = Array.isArray(n) ? n[0] : n;
3325
- if (r) try {
3326
- let n = await zr(Hr(r), this.config.capabilityRegistry, {
3476
+ let n = e.headers[Lr], i = Array.isArray(n) ? n[0] : n;
3477
+ if (i) try {
3478
+ let n = await Kr(Yr(i), this.config.capabilityRegistry, {
3327
3479
  requiredPathGlob: e.path,
3328
3480
  requiredMethod: e.method
3329
3481
  });
3330
- if (n.ok && Br(n.token, e.path, e.method)) {
3331
- let e = performance.now() - t;
3332
- return Z.verifications_total.increment({
3482
+ if (n.ok && qr(n.token, e.path, e.method)) {
3483
+ let i = n.token.subject, a = await this.checkSenderAndRateLimit(r, i, "ED25519", e, t);
3484
+ if (a) return a;
3485
+ let o = performance.now() - t;
3486
+ return X.verifications_total.increment({
3333
3487
  result: "ok",
3334
3488
  alg: "ED25519",
3335
3489
  transport: "http"
3336
- }), Z.verification_duration_ms.observe(e), {
3490
+ }), X.verification_duration_ms.observe(o), {
3337
3491
  ok: !0,
3338
- sender: n.token.subject
3492
+ sender: i
3339
3493
  };
3340
3494
  }
3341
- let i = performance.now() - t;
3342
- return Z.verifications_total.increment({
3495
+ let a = performance.now() - t;
3496
+ return X.verifications_total.increment({
3343
3497
  result: "fail",
3344
3498
  alg: "none",
3345
3499
  transport: "http"
3346
- }), Z.verification_duration_ms.observe(i), {
3500
+ }), X.verification_duration_ms.observe(a), {
3347
3501
  ok: !1,
3348
3502
  status: 401,
3349
3503
  reason: n.ok ? "capability-scope-mismatch" : n.reason
3350
3504
  };
3351
3505
  } catch {
3352
3506
  let e = performance.now() - t;
3353
- return Z.verifications_total.increment({
3507
+ return X.verifications_total.increment({
3354
3508
  result: "fail",
3355
3509
  alg: "none",
3356
3510
  transport: "http"
3357
- }), Z.verification_duration_ms.observe(e), {
3511
+ }), X.verification_duration_ms.observe(e), {
3358
3512
  ok: !1,
3359
3513
  status: 401,
3360
3514
  reason: "invalid-capability-chain"
3361
3515
  };
3362
3516
  }
3363
3517
  }
3364
- if (!n && (this.config.defaultPolicy ?? "allow") === "deny") {
3518
+ if (!r && (this.config.defaultPolicy ?? "allow") === "deny") {
3365
3519
  let n = performance.now() - t;
3366
- return Z.verifications_total.increment({
3520
+ return X.verifications_total.increment({
3367
3521
  result: "fail",
3368
3522
  alg: "none",
3369
3523
  transport: "http"
3370
- }), Z.verification_duration_ms.observe(n), Z.sender_denials_total.increment({
3524
+ }), X.verification_duration_ms.observe(n), X.sender_denials_total.increment({
3371
3525
  sender: "",
3372
3526
  path: e.path
3373
3527
  }), {
@@ -3376,82 +3530,54 @@ var Ur = class {
3376
3530
  reason: "no-matching-policy"
3377
3531
  };
3378
3532
  }
3379
- let r = await Dn(e.headers, {
3533
+ let i = await kn(e.headers, {
3380
3534
  keyRegistry: this.config.keyRegistry,
3381
3535
  headerName: this.config.headerName
3382
3536
  });
3383
- if (!r.ok) {
3537
+ if (!i.ok) {
3384
3538
  let e = performance.now() - t;
3385
- return Z.verifications_total.increment({
3539
+ return X.verifications_total.increment({
3386
3540
  result: "fail",
3387
3541
  alg: "none",
3388
3542
  transport: "http"
3389
- }), Z.verification_duration_ms.observe(e), {
3543
+ }), X.verification_duration_ms.observe(e), {
3390
3544
  ok: !1,
3391
3545
  status: 401,
3392
- reason: r.reason
3546
+ reason: i.reason
3393
3547
  };
3394
3548
  }
3395
- let i = r.envelope, a = i.header.sender, o = i.header.messageId, s = i.signature?.alg ?? "none";
3396
- if (this.config.replayStore && await this.config.replayStore.check(i.header.nonce, i.header.ttlMs)) return {
3549
+ let a = i.envelope, o = a.header.sender, s = a.header.messageId, c = a.signature?.alg ?? "none";
3550
+ if (this.config.replayStore && await this.config.replayStore.check(a.header.nonce, a.header.ttlMs)) return {
3397
3551
  ok: !1,
3398
3552
  status: 401,
3399
3553
  reason: "replay-detected"
3400
3554
  };
3401
- if (n && n.require !== "any") {
3402
- let e = i.signature?.alg, r = n.require === "ed25519" && e !== "ED25519", a = n.require === "hmac" && e !== "HS256";
3403
- if (r || a) {
3555
+ if (r && r.require !== "any") {
3556
+ let e = a.signature?.alg, n = r.require === "ed25519" && e !== "ED25519", i = r.require === "hmac" && e !== "HS256";
3557
+ if (n || i) {
3404
3558
  let e = performance.now() - t;
3405
- return Z.verifications_total.increment({
3559
+ return X.verifications_total.increment({
3406
3560
  result: "fail",
3407
- alg: s,
3561
+ alg: c,
3408
3562
  transport: "http"
3409
- }), Z.verification_duration_ms.observe(e), {
3563
+ }), X.verification_duration_ms.observe(e), {
3410
3564
  ok: !1,
3411
3565
  status: 401,
3412
3566
  reason: "invalid-signature"
3413
3567
  };
3414
3568
  }
3415
3569
  }
3416
- if (n && !Cr(n, a)) {
3417
- let n = performance.now() - t;
3418
- return Z.verifications_total.increment({
3419
- result: "fail",
3420
- alg: s,
3421
- transport: "http"
3422
- }), Z.verification_duration_ms.observe(n), Z.sender_denials_total.increment({
3423
- sender: a,
3424
- path: e.path
3425
- }), {
3426
- ok: !1,
3427
- status: 403,
3428
- reason: "sender-denied"
3429
- };
3430
- }
3431
- if (n?.rateLimit && !(this.config.rateLimitStore ? await this.config.rateLimitStore.consume(a, n.rateLimit) : this.rateLimiter.consume(a, n.rateLimit)).allowed) {
3432
- let n = performance.now() - t;
3433
- return Z.verifications_total.increment({
3434
- result: "fail",
3435
- alg: s,
3436
- transport: "http"
3437
- }), Z.verification_duration_ms.observe(n), Z.rate_limit_hits_total.increment({
3438
- sender: a,
3439
- path: e.path
3440
- }), {
3441
- ok: !1,
3442
- status: 429,
3443
- reason: "rate-limited"
3444
- };
3445
- }
3446
- let c = performance.now() - t;
3447
- return Z.verifications_total.increment({
3570
+ let l = await this.checkSenderAndRateLimit(r, o, c, e, t);
3571
+ if (l) return l;
3572
+ let u = performance.now() - t;
3573
+ return X.verifications_total.increment({
3448
3574
  result: "ok",
3449
- alg: s,
3575
+ alg: c,
3450
3576
  transport: "http"
3451
- }), Z.verification_duration_ms.observe(c), {
3577
+ }), X.verification_duration_ms.observe(u), {
3452
3578
  ok: !0,
3453
- sender: a,
3454
- envelopeId: o
3579
+ sender: o,
3580
+ envelopeId: s
3455
3581
  };
3456
3582
  }
3457
3583
  async handle(e) {
@@ -3461,43 +3587,43 @@ var Ur = class {
3461
3587
  headers: { "content-type": "application/json" },
3462
3588
  body: JSON.stringify({ error: t.reason })
3463
3589
  };
3464
- let n = this.config.upstream.replace(/\/$/, "") + e.path, r = {};
3465
- for (let [t, n] of Object.entries(e.headers)) r[t] = Array.isArray(n) ? n[0] : n;
3466
- t.sender && (r["x-7h3-sender"] = t.sender), r["x-7h3-verified"] = "true";
3467
- let i = await fetch(n, {
3590
+ let n = Xr(e.path), r = this.config.upstream.replace(/\/$/, "") + n, i = {};
3591
+ for (let [t, n] of Object.entries(e.headers)) i[t] = Array.isArray(n) ? n[0] : n;
3592
+ t.sender && (i["x-7h3-sender"] = t.sender, i["x-7h3-verified"] = "true");
3593
+ let a = await fetch(r, {
3468
3594
  method: e.method,
3469
- headers: r,
3595
+ headers: i,
3470
3596
  body: e.body
3471
- }), a = await i.text(), o = { "content-type": i.headers.get("content-type") ?? "application/json" };
3597
+ }), o = await a.text(), s = { "content-type": a.headers.get("content-type") ?? "application/json" };
3472
3598
  if (this.config.privateKey !== void 0 && (this.config.signResponses ?? !0) && this.config.sender !== void 0) {
3473
- let e = await Tr(a, {
3599
+ let e = await kr(o, {
3474
3600
  privateKey: this.config.privateKey,
3475
3601
  sender: this.config.sender,
3476
3602
  recipient: t.sender || void 0
3477
3603
  });
3478
- Object.assign(o, e.headers);
3604
+ Object.assign(s, e.headers);
3479
3605
  }
3480
3606
  return {
3481
- status: i.status,
3482
- headers: o,
3483
- body: a
3607
+ status: a.status,
3608
+ headers: s,
3609
+ body: o
3484
3610
  };
3485
3611
  }
3486
3612
  getRateLimiter() {
3487
3613
  return this.rateLimiter;
3488
3614
  }
3489
3615
  };
3490
- function Wr(e) {
3491
- return new Ur(e);
3616
+ function Qr(e) {
3617
+ return new Zr(e);
3492
3618
  }
3493
- function Gr(e) {
3619
+ function $r(e) {
3494
3620
  if (e.defaultPolicy !== "deny") throw Error("createProductionGateway(): defaultPolicy must be explicitly 'deny'. Unmatched routes must never be forwarded unverified in production.");
3495
3621
  if (!e.replayStore) throw Error("createProductionGateway(): replayStore is required. Use a shared store (Redis/KV/Durable Object) so nonce replay protection survives multiple instances and restarts.");
3496
- return new Ur(e);
3622
+ return new Zr(e);
3497
3623
  }
3498
3624
  //#endregion
3499
3625
  //#region src/auditLog.ts
3500
- function Kr(e) {
3626
+ function ei(e) {
3501
3627
  let t = [
3502
3628
  `"id":${JSON.stringify(e.id)}`,
3503
3629
  `"timestampMs":${e.timestampMs}`,
@@ -3505,7 +3631,7 @@ function Kr(e) {
3505
3631
  ];
3506
3632
  return e.sender !== void 0 && t.push(`"sender":${JSON.stringify(e.sender)}`), e.path !== void 0 && t.push(`"path":${JSON.stringify(e.path)}`), e.method !== void 0 && t.push(`"method":${JSON.stringify(e.method)}`), e.envelopeId !== void 0 && t.push(`"envelopeId":${JSON.stringify(e.envelopeId)}`), e.failReason !== void 0 && t.push(`"failReason":${JSON.stringify(e.failReason)}`), e.upstream !== void 0 && t.push(`"upstream":${JSON.stringify(e.upstream)}`), e.responseStatus !== void 0 && t.push(`"responseStatus":${e.responseStatus}`), `{${t.join(",")}}`;
3507
3633
  }
3508
- var qr = class {
3634
+ var ti = class {
3509
3635
  entries = [];
3510
3636
  privateKey;
3511
3637
  maxEntries;
@@ -3517,7 +3643,7 @@ var qr = class {
3517
3643
  id: `audit-${Date.now()}-${y(5)}`,
3518
3644
  timestampMs: Date.now(),
3519
3645
  ...e
3520
- }, n = await b(Kr(t), this.privateKey), r = {
3646
+ }, n = await b(ei(t), this.privateKey), r = {
3521
3647
  ...t,
3522
3648
  entrySignature: n
3523
3649
  };
@@ -3528,7 +3654,7 @@ var qr = class {
3528
3654
  return e?.type !== void 0 && (t = t.filter((t) => t.type === e.type)), e?.sender !== void 0 && (t = t.filter((t) => t.sender === e.sender)), e?.since !== void 0 && (t = t.filter((t) => t.timestampMs >= e.since)), e?.limit !== void 0 && (t = t.slice(-e.limit)), t;
3529
3655
  }
3530
3656
  async verify(e, t) {
3531
- return x(Kr({
3657
+ return x(ei({
3532
3658
  id: e.id,
3533
3659
  timestampMs: e.timestampMs,
3534
3660
  type: e.type,
@@ -3544,7 +3670,7 @@ var qr = class {
3544
3670
  size() {
3545
3671
  return this.entries.length;
3546
3672
  }
3547
- }, Jr = class {
3673
+ }, ni = class {
3548
3674
  async log(e) {}
3549
3675
  async query(e) {
3550
3676
  return [];
@@ -3556,25 +3682,25 @@ var qr = class {
3556
3682
  return 0;
3557
3683
  }
3558
3684
  };
3559
- function Yr(e, t) {
3560
- return new qr(e, t?.maxEntries);
3685
+ function ri(e, t) {
3686
+ return new ti(e, t?.maxEntries);
3561
3687
  }
3562
3688
  //#endregion
3563
3689
  //#region src/otel.ts
3564
- var Xr = null;
3565
- function Zr(e) {
3566
- Xr = e;
3690
+ var ii = null;
3691
+ function ai(e) {
3692
+ ii = e;
3567
3693
  }
3568
- function Qr() {
3569
- if (Xr === null) return null;
3694
+ function oi() {
3695
+ if (ii === null) return null;
3570
3696
  try {
3571
- return Xr.getTracer("7h3/protocol");
3697
+ return ii.getTracer("7h3/protocol");
3572
3698
  } catch {
3573
3699
  return null;
3574
3700
  }
3575
3701
  }
3576
- async function $r(e, t) {
3577
- let n = Qr();
3702
+ async function si(e, t) {
3703
+ let n = oi();
3578
3704
  if (n === null) return e(null);
3579
3705
  let r = n.startSpan("7h3.verify", t);
3580
3706
  try {
@@ -3585,8 +3711,8 @@ async function $r(e, t) {
3585
3711
  r.end();
3586
3712
  }
3587
3713
  }
3588
- async function ei(e) {
3589
- let t = Qr();
3714
+ async function ci(e) {
3715
+ let t = oi();
3590
3716
  if (t === null) return e(null);
3591
3717
  let n = t.startSpan("7h3.audit.write");
3592
3718
  try {
@@ -3599,64 +3725,64 @@ async function ei(e) {
3599
3725
  }
3600
3726
  //#endregion
3601
3727
  //#region src/encryption.ts
3602
- function ti(e) {
3728
+ function Q(e) {
3603
3729
  return Buffer.from(e).toString("base64url");
3604
3730
  }
3605
3731
  function $(e) {
3606
3732
  return Buffer.from(e, "base64url");
3607
3733
  }
3608
- var ni = Buffer.from("302e020100300506032b656e04220420", "hex"), ri = Buffer.from("302a300506032b656e032100", "hex");
3609
- function ii(e) {
3734
+ var li = Buffer.from("302e020100300506032b656e04220420", "hex"), ui = Buffer.from("302a300506032b656e032100", "hex");
3735
+ function di(e) {
3610
3736
  let t = $(e);
3611
3737
  return r({
3612
- key: Buffer.concat([ni, t]),
3738
+ key: Buffer.concat([li, t]),
3613
3739
  format: "der",
3614
3740
  type: "pkcs8"
3615
3741
  });
3616
3742
  }
3617
- function ai(e) {
3743
+ function fi(e) {
3618
3744
  let t = $(e);
3619
3745
  return i({
3620
- key: Buffer.concat([ri, t]),
3746
+ key: Buffer.concat([ui, t]),
3621
3747
  format: "der",
3622
3748
  type: "spki"
3623
3749
  });
3624
3750
  }
3625
- function oi() {
3751
+ function pi() {
3626
3752
  let { privateKey: e, publicKey: t } = o("x25519"), n = e.export({ format: "jwk" });
3627
3753
  return {
3628
3754
  publicKey: t.export({ format: "jwk" }).x,
3629
3755
  privateKey: n.d
3630
3756
  };
3631
3757
  }
3632
- function si(e, t, n) {
3758
+ function mi(e, t, n) {
3633
3759
  let r = s("sha256", a({
3634
- privateKey: ii(e),
3635
- publicKey: ai(t)
3760
+ privateKey: di(e),
3761
+ publicKey: fi(t)
3636
3762
  }), $(n), Buffer.from("7h3-enc/1", "utf8"), 32);
3637
3763
  return Buffer.from(r);
3638
3764
  }
3639
- function ci(e, n) {
3640
- let r = oi(), i = c(12), a = ti(i), o = si(r.privateKey, n, a), s = Buffer.from(JSON.stringify(e), "utf8"), l = t("chacha20-poly1305", o, i, { authTagLength: 16 }), u = Buffer.concat([l.update(s), l.final()]), d = l.getAuthTag(), f = {
3765
+ function hi(e, n) {
3766
+ let r = pi(), i = c(12), a = Q(i), o = mi(r.privateKey, n, a), s = Buffer.from(JSON.stringify(e), "utf8"), l = t("chacha20-poly1305", o, i, { authTagLength: 16 }), u = Buffer.concat([l.update(s), l.final()]), d = l.getAuthTag(), f = {
3641
3767
  ephemeralPublic: r.publicKey,
3642
3768
  nonce: a,
3643
- ciphertext: ti(u),
3644
- tag: ti(d)
3769
+ ciphertext: Q(u),
3770
+ tag: Q(d)
3645
3771
  };
3646
3772
  return {
3647
- encryptedContent: ti(Buffer.from(JSON.stringify(f), "utf8")),
3773
+ encryptedContent: Q(Buffer.from(JSON.stringify(f), "utf8")),
3648
3774
  ephemeralPublic: r.publicKey
3649
3775
  };
3650
3776
  }
3651
- function li(e, t) {
3652
- let r = $(e).toString("utf8"), { ephemeralPublic: i, nonce: a, ciphertext: o, tag: s } = JSON.parse(r), c = si(t, i, a), l = $(a), u = $(o), d = $(s), f = n("chacha20-poly1305", c, l, { authTagLength: 16 });
3777
+ function gi(e, t) {
3778
+ let r = $(e).toString("utf8"), { ephemeralPublic: i, nonce: a, ciphertext: o, tag: s } = JSON.parse(r), c = mi(t, i, a), l = $(a), u = $(o), d = $(s), f = n("chacha20-poly1305", c, l, { authTagLength: 16 });
3653
3779
  f.setAuthTag(d);
3654
3780
  let p = Buffer.concat([f.update(u), f.final()]);
3655
3781
  return JSON.parse(p.toString("utf8"));
3656
3782
  }
3657
- async function ui(e, t) {
3658
- let { encryptedContent: n } = ci(e.body, t.recipientX25519PublicKey);
3659
- return C({
3783
+ async function _i(e, t) {
3784
+ let { encryptedContent: n } = hi(e.body, t.recipientX25519PublicKey);
3785
+ return w({
3660
3786
  header: e.header,
3661
3787
  body: {
3662
3788
  intent: "ENCRYPTED",
@@ -3666,12 +3792,12 @@ async function ui(e, t) {
3666
3792
  }
3667
3793
  }, t.senderEd25519PrivateKey);
3668
3794
  }
3669
- async function di(e, t) {
3670
- if (!await w(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3795
+ async function vi(e, t) {
3796
+ if (!await T(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3671
3797
  return {
3672
3798
  envelope: e,
3673
- body: li(e.body.content, t.recipientX25519PrivateKey)
3799
+ body: gi(e.body.content, t.recipientX25519PrivateKey)
3674
3800
  };
3675
3801
  }
3676
3802
  //#endregion
3677
- export { ot as AgentSession, st as AipAgentAdapter, Mr as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Rt as ClusterRedisReplayStore, En as DEFAULT_HEADER, xe as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Re as DistributedReplayCache, ur as GRPC_METADATA_KEY, qr as InMemoryAuditLog, It as InMemoryRedisLikeClient, k as InMemoryReplayCache, Ut as InMemoryRevocationStore, ze as InMemoryVerificationMaterialCache, vr as KeyRotationManager, _e as MAX_TTL_MS, Jr as NoopAuditLog, Ur as Protocol7h3Gateway, kr as Protocol7h3Metrics, wr as RESPONSE_HEADER, Lt as RedisReplayStore, yr as RevocationRegistry, it as RollingKeyring, Mt as RuntimePolicyManager, Un as STREAM_HEADER, Xe as SessionTransport, er as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Or as SimpleHistogram, br as SlidingWindowRateLimiter, Nn as WEBHOOK_DEFAULT_TTL_MS, L as WEBHOOK_SIG_HEADER, R as WEBHOOK_TS_HEADER, j as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, zn as consumeWebhook, ct as createAipAgentAdapter, et as createAipCapabilities, At as createAipMcpGatewayRuntime, jt as createAipMcpGatewayRuntimeWithPolicy, Yr as createAuditLog, rn as createCachingKeyRegistry, Vt as createClusterReplayStore, nn as createCompositeKeyRegistry, E as createEnvelope, Wr as createGateway, _r as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, An as createHttpMiddleware, at as createKeyringSignatureResolver, Jt as createMcpClientCodec, jr as createMetricsMiddleware, wt as createPolicyEnforcer, Gr as createProductionGateway, mt as createRawTaskFromJsonRpc, lt as createRawTaskFromLangChain, dt as createRawTaskFromLlamaIndex, zt as createRedisReplayStore, Wt as createRedisRevocationStore, Mn as createSignedFetchRequest, Ze as createSignedMessage, tr as createSignedStream, cr as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, nr as createStreamVerifier, Sn as decodeCbor, Ge as decodeEnvelope, Je as decodeEnvelopeBatch, Ie as decodeEnvelopeBinary, Tn as decodeEnvelopeCbor, or as decodeStreamChunk, li as decryptBody, Lr as delegateCapabilityToken, si as deriveEncryptionKey, tt as encodeAipCapabilities, xn as encodeCbor, Ke as encodeEnvelope, qe as encodeEnvelopeBatch, Fe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, ar as encodeStreamChunk, ci as encryptBody, gr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, oi as generateX25519KeyPair, Qr as getOtelTracer, Pt as getRuntimeTuningPreset, xr as globalRateLimiter, Cr as isAllowedSender, Tt as isRuntimeMode, Pr as issueCapabilityToken, xt as loadRuntimePolicy, J as matchGlob, Sr as matchPolicy, Z as metrics, rt as negotiateAipCapabilities, di as openEnvelope, nt as parseAipCapabilities, Hr as parseCapabilityChain, yt as parseRuntimePolicyJson, hr as parseWellKnownKeys, y as randomHex, A as receiveEnvelope, Ye as receiveEnvelopeBatch, lr as receiveSignedWebSocketStream, Ft as recommendPolicyAdjustments, Ar as renderPrometheusText, ui as sealEnvelope, Vr as serializeCapabilityChain, Zt as serveMcpOverStdio, mr as serveWellKnownKeys, Zr as setOtelProvider, b as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, C as signEnvelopeEd25519, me as signEnvelopeHmac, jn as signFetchRequest, dr as signGrpcCall, On as signHttpRequest, kn as signHttpRequestHmac, Bn as signQueueMessage, Tr as signResponse, rr as signStream, Fn as signWebhook, In as signWebhookHmac, ht as toJsonRpcResponse, ut as toLangChainMessage, ft as toLlamaIndexMessage, Br as tokenMatchesScope, T as validateEnvelope, vt as validateRuntimePolicy, x as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, ge as verifyCanonicalPayloadSignature, zr as verifyCapabilityChain, Rr as verifyCapabilityToken, w as verifyEnvelopeEd25519, S as verifyEnvelopeHmac, he as verifyEnvelopeSignature, fr as verifyGrpcCall, Dn as verifyHttpEnvelope, Hn as verifyQueueBatch, Vn as verifyQueueMessage, Er as verifyResponse, ir as verifyStream, Ln as verifyWebhook, Rn as verifyWebhookHmac, ei as withAuditSpan, pr as withGrpcVerification, Gt as withRevocationCheck, $r as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, sr as wrapWebSocket };
3803
+ export { it as AgentSession, at as AipAgentAdapter, Lr as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Lt as ClusterRedisReplayStore, On as DEFAULT_HEADER, be as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Le as DistributedReplayCache, pr as GRPC_METADATA_KEY, ti as InMemoryAuditLog, Ft as InMemoryRedisLikeClient, A as InMemoryReplayCache, Ht as InMemoryRevocationStore, Re as InMemoryVerificationMaterialCache, In as InMemoryWebhookReplayCache, xr as KeyRotationManager, ge as MAX_TTL_MS, ni as NoopAuditLog, Zr as Protocol7h3Gateway, Pr as Protocol7h3Metrics, Or as RESPONSE_HEADER, It as RedisReplayStore, Sr as RevocationRegistry, nt as RollingKeyring, jt as RuntimePolicyManager, Gn as STREAM_HEADER, Je as SessionTransport, rr as SignedStreamReader, nr as SignedStreamWriter, Y as SimpleCounter, Nr as SimpleHistogram, Cr as SlidingWindowRateLimiter, Fn as WEBHOOK_DEFAULT_TTL_MS, R as WEBHOOK_SIG_HEADER, z as WEBHOOK_TS_HEADER, N as bootstrapRuntimePolicyEnforcer, Z as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, Vn as consumeWebhook, ot as createAipAgentAdapter, Qe as createAipCapabilities, kt as createAipMcpGatewayRuntime, At as createAipMcpGatewayRuntimeWithPolicy, ri as createAuditLog, rn as createCachingKeyRegistry, Bt as createClusterReplayStore, nn as createCompositeKeyRegistry, D as createEnvelope, Qr as createGateway, br as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, Mn as createHttpMiddleware, rt as createKeyringSignatureResolver, Jt as createMcpClientCodec, Ir as createMetricsMiddleware, St as createPolicyEnforcer, $r as createProductionGateway, ft as createRawTaskFromJsonRpc, st as createRawTaskFromLangChain, lt as createRawTaskFromLlamaIndex, Rt as createRedisReplayStore, Ut as createRedisRevocationStore, Pn as createSignedFetchRequest, Ye as createSignedMessage, ir as createSignedStream, dr as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, ar as createStreamVerifier, Sn as decodeCbor, We as decodeEnvelope, Ke as decodeEnvelopeBatch, Fe as decodeEnvelopeBinary, Dn as decodeEnvelopeCbor, lr as decodeStreamChunk, gi as decryptBody, Wr as delegateCapabilityToken, mi as deriveEncryptionKey, $e as encodeAipCapabilities, xn as encodeCbor, j as encodeEnvelope, Ge as encodeEnvelopeBatch, Pe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, cr as encodeStreamChunk, hi as encryptBody, yr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, pi as generateX25519KeyPair, oi as getOtelTracer, Nt as getRuntimeTuningPreset, wr as globalRateLimiter, Dr as isAllowedSender, Ct as isRuntimeMode, zr as issueCapabilityToken, yt as loadRuntimePolicy, Tr as matchGlob, Er as matchPolicy, X as metrics, tt as negotiateAipCapabilities, Xr as normalizeGatewayPath, vi as openEnvelope, et as parseAipCapabilities, Yr as parseCapabilityChain, _t as parseRuntimePolicyJson, vr as parseWellKnownKeys, y as randomHex, M as receiveEnvelope, qe as receiveEnvelopeBatch, fr as receiveSignedWebSocketStream, Pt as recommendPolicyAdjustments, Fr as renderPrometheusText, _i as sealEnvelope, Jr as serializeCapabilityChain, Zt as serveMcpOverStdio, _r as serveWellKnownKeys, ai as setOtelProvider, b as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, w as signEnvelopeEd25519, S as signEnvelopeHmac, Nn as signFetchRequest, mr as signGrpcCall, An as signHttpRequest, jn as signHttpRequestHmac, Hn as signQueueMessage, kr as signResponse, or as signStream, Ln as signWebhook, Rn as signWebhookHmac, pt as toJsonRpcResponse, ct as toLangChainMessage, ut as toLlamaIndexMessage, qr as tokenMatchesScope, E as validateEnvelope, gt as validateRuntimePolicy, x as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, he as verifyCanonicalPayloadSignature, Kr as verifyCapabilityChain, Gr as verifyCapabilityToken, T as verifyEnvelopeEd25519, C as verifyEnvelopeHmac, me as verifyEnvelopeSignature, hr as verifyGrpcCall, kn as verifyHttpEnvelope, Wn as verifyQueueBatch, Un as verifyQueueMessage, Ar as verifyResponse, sr as verifyStream, zn as verifyWebhook, Bn as verifyWebhookHmac, ci as withAuditSpan, gr as withGrpcVerification, Wt as withRevocationCheck, si as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, ur as wrapWebSocket };