@7h3/protocol 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +451 -443
  2. package/package.json +1 -1
  3. package/protocol.d.ts +5 -0
package/index.js CHANGED
@@ -71,6 +71,14 @@ function v() {
71
71
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
72
72
  return crypto.subtle;
73
73
  }
74
+ function y(e = 12) {
75
+ if (typeof crypto > "u" || !crypto.getRandomValues) throw Error("Web Crypto API is not available in this runtime");
76
+ let t = new Uint8Array(e);
77
+ crypto.getRandomValues(t);
78
+ let n = "";
79
+ for (let e of t) n += e.toString(16).padStart(2, "0");
80
+ return n;
81
+ }
74
82
  async function se(e, t) {
75
83
  let n = v(), r = await re(t), i = await n.sign("HMAC", r, l.encode(e));
76
84
  return h(new Uint8Array(i));
@@ -100,13 +108,13 @@ async function pe() {
100
108
  publicKey: h(new Uint8Array(r))
101
109
  };
102
110
  }
103
- async function y(e, t) {
111
+ async function b(e, t) {
104
112
  return le(e, t);
105
113
  }
106
- async function b(e, t, n) {
114
+ async function x(e, t, n) {
107
115
  return ue(e, t, n);
108
116
  }
109
- async function x(e, t, n = "local-dev-key") {
117
+ async function S(e, t, n = "local-dev-key") {
110
118
  let r = await se(_(e), t);
111
119
  return {
112
120
  ...e,
@@ -117,13 +125,13 @@ async function x(e, t, n = "local-dev-key") {
117
125
  }
118
126
  };
119
127
  }
120
- async function me(e, t) {
128
+ async function C(e, t) {
121
129
  return !e.signature || e.signature.alg !== "HS256" ? !1 : ce(_({
122
130
  header: e.header,
123
131
  body: e.body
124
132
  }), e.signature.value, t);
125
133
  }
126
- async function S(e, t, n = "local-ed25519-key") {
134
+ async function w(e, t, n = "local-ed25519-key") {
127
135
  let r = await le(_(e), t);
128
136
  return {
129
137
  ...e,
@@ -134,19 +142,19 @@ async function S(e, t, n = "local-ed25519-key") {
134
142
  }
135
143
  };
136
144
  }
137
- async function C(e, t) {
145
+ async function T(e, t) {
138
146
  return !e.signature || e.signature.alg !== "ED25519" ? !1 : ue(_({
139
147
  header: e.header,
140
148
  body: e.body
141
149
  }), e.signature.value, t);
142
150
  }
143
- async function he(e, t) {
144
- return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? me(e, t.secret) : C(e, t.publicKey);
151
+ async function me(e, t) {
152
+ return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? C(e, t.secret) : T(e, t.publicKey);
145
153
  }
146
- async function ge(e, t, n) {
147
- return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : b(e, t.value, n.publicKey);
154
+ async function he(e, t, n) {
155
+ return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : x(e, t.value, n.publicKey);
148
156
  }
149
- function w(e, t = Date.now()) {
157
+ function E(e, t = Date.now()) {
150
158
  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 : "";
151
159
  return a !== "7h3/0.1" && n.push({
152
160
  level: "error",
@@ -171,17 +179,17 @@ function w(e, t = Date.now()) {
171
179
  message: "Empty content payload"
172
180
  }), n;
173
181
  }
174
- function T(e) {
182
+ function D(e) {
175
183
  let t = e.nowMs ?? Date.now();
176
184
  return {
177
185
  header: {
178
186
  version: "7h3/0.1",
179
- messageId: e.messageId ?? `msg-${t}-${Math.random().toString(36).slice(2, 10)}`,
187
+ messageId: e.messageId ?? `msg-${t}-${y(6)}`,
180
188
  timestampMs: t,
181
189
  ttlMs: e.ttlMs ?? 6e4,
182
190
  sender: e.sender,
183
191
  recipient: e.recipient,
184
- nonce: e.nonce ?? Math.random().toString(36).slice(2, 12)
192
+ nonce: e.nonce ?? y(12)
185
193
  },
186
194
  body: {
187
195
  intent: e.intent,
@@ -193,12 +201,12 @@ function T(e) {
193
201
  }
194
202
  //#endregion
195
203
  //#region src/protocolBinary.ts
196
- var _e = [
204
+ var ge = [
197
205
  65,
198
206
  73,
199
207
  80,
200
208
  66
201
- ], ve = Uint8Array.from(_e), ye = 1, be = 1024 * 1024, xe = 1, Se = 2, Ce = 4, we = 8, Te = new TextEncoder(), Ee = new TextDecoder(), De = new Set([
209
+ ], _e = Uint8Array.from(ge), ve = 1, ye = 1024 * 1024, be = 1, xe = 2, Se = 4, Ce = 8, we = new TextEncoder(), Te = new TextDecoder(), Ee = new Set([
202
210
  "PING",
203
211
  "PONG",
204
212
  "CAPS",
@@ -206,25 +214,25 @@ var _e = [
206
214
  "RESULT",
207
215
  "ERROR"
208
216
  ]);
217
+ function De(e) {
218
+ return we.encode(e);
219
+ }
209
220
  function Oe(e) {
210
- return Te.encode(e);
221
+ return Te.decode(e);
211
222
  }
212
223
  function ke(e) {
213
- return Ee.decode(e);
214
- }
215
- function Ae(e) {
216
224
  return e === "ED25519" ? 2 : 1;
217
225
  }
218
- function je(e) {
226
+ function Ae(e) {
219
227
  return e === 1 ? "HS256" : e === 2 ? "ED25519" : null;
220
228
  }
221
- function E(e) {
222
- return { bytes: Oe(e) };
229
+ function O(e) {
230
+ return { bytes: De(e) };
223
231
  }
224
- function D(e) {
232
+ function k(e) {
225
233
  return e ? 4 + e.bytes.byteLength : 0;
226
234
  }
227
- var Me = class {
235
+ var je = class {
228
236
  bytes;
229
237
  view;
230
238
  offset = 0;
@@ -249,7 +257,7 @@ var Me = class {
249
257
  finish() {
250
258
  return this.bytes;
251
259
  }
252
- }, Ne = class {
260
+ }, Me = class {
253
261
  bytes;
254
262
  offset = 0;
255
263
  constructor(e) {
@@ -280,14 +288,14 @@ var Me = class {
280
288
  }
281
289
  readString() {
282
290
  let e = this.readU32();
283
- return ke(this.readBytes(e));
291
+ return Oe(this.readBytes(e));
284
292
  }
285
293
  };
286
- function Pe(e) {
287
- let t = (e.header.recipient ? xe : 0) | (e.body.capability ? Se : 0) | (e.body.correlationId ? Ce : 0) | (e.signature ? we : 0), n = E(e.header.version), r = E(e.header.messageId), i = E(e.header.sender), a = E(e.header.nonce), o = E(e.body.intent), s = E(e.body.content), c = e.header.recipient ? E(e.header.recipient) : null, l = e.body.capability ? E(e.body.capability) : null, u = e.body.correlationId ? E(e.body.correlationId) : null, d = e.signature ? E(e.signature.keyId) : null, f = e.signature ? E(e.signature.value) : null, p = new Me(ve.byteLength + 1 + 1 + 8 + 4 + D(n) + D(r) + D(i) + D(a) + D(o) + D(s) + D(c) + D(l) + D(u) + +!!e.signature + D(d) + D(f));
288
- 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
+ function Ne(e) {
295
+ let t = (e.header.recipient ? be : 0) | (e.body.capability ? xe : 0) | (e.body.correlationId ? Se : 0) | (e.signature ? Ce : 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 je(_e.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));
296
+ return p.writeBytes(_e), p.writeU8(ve), 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(ke(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
289
297
  }
290
- function Fe(e, t = {}) {
298
+ function Pe(e, t = {}) {
291
299
  try {
292
300
  let n = t.maxFrameBytes ?? 1048576;
293
301
  if (e.byteLength > n) return {
@@ -298,13 +306,13 @@ function Fe(e, t = {}) {
298
306
  }],
299
307
  envelope: null
300
308
  };
301
- let r = new Ne(e);
309
+ let r = new Me(e);
302
310
  if ([
303
311
  r.readU8(),
304
312
  r.readU8(),
305
313
  r.readU8(),
306
314
  r.readU8()
307
- ].some((e, t) => e !== _e[t])) return {
315
+ ].some((e, t) => e !== ge[t])) return {
308
316
  ok: !1,
309
317
  diagnostics: [{
310
318
  level: "error",
@@ -313,7 +321,7 @@ function Fe(e, t = {}) {
313
321
  envelope: null
314
322
  };
315
323
  let i = r.readU8();
316
- if (i !== ye) return {
324
+ if (i !== ve) return {
317
325
  ok: !1,
318
326
  diagnostics: [{
319
327
  level: "error",
@@ -343,7 +351,7 @@ function Fe(e, t = {}) {
343
351
  }],
344
352
  envelope: null
345
353
  };
346
- if (!De.has(c.body.intent)) return {
354
+ if (!Ee.has(c.body.intent)) return {
347
355
  ok: !1,
348
356
  diagnostics: [{
349
357
  level: "error",
@@ -351,8 +359,8 @@ function Fe(e, t = {}) {
351
359
  }],
352
360
  envelope: null
353
361
  };
354
- if (a & xe && (c.header.recipient = r.readString()), a & Se && (c.body.capability = r.readString()), a & Ce && (c.body.correlationId = r.readString()), a & we) {
355
- let e = r.readU8(), t = je(e);
362
+ if (a & be && (c.header.recipient = r.readString()), a & xe && (c.body.capability = r.readString()), a & Se && (c.body.correlationId = r.readString()), a & Ce) {
363
+ let e = r.readU8(), t = Ae(e);
356
364
  if (!t) return {
357
365
  ok: !1,
358
366
  diagnostics: [{
@@ -392,7 +400,7 @@ function Fe(e, t = {}) {
392
400
  }
393
401
  //#endregion
394
402
  //#region src/protocolReplay.ts
395
- var Ie = class {
403
+ var Fe = class {
396
404
  items = [];
397
405
  peek() {
398
406
  return this.items[0];
@@ -425,10 +433,10 @@ var Ie = class {
425
433
  this.items[t] = l, this.items[r] = c, t = r;
426
434
  }
427
435
  }
428
- }, O = class {
436
+ }, A = class {
429
437
  entries = /* @__PURE__ */ new Map();
430
438
  maxEntries;
431
- expiries = new Ie();
439
+ expiries = new Fe();
432
440
  constructor(e = 1e4) {
433
441
  this.maxEntries = e;
434
442
  }
@@ -476,7 +484,7 @@ var Ie = class {
476
484
  consumeMany(e, t = Date.now()) {
477
485
  return e.map((e) => this.consume(e, t));
478
486
  }
479
- }, Le = class {
487
+ }, Ie = class {
480
488
  store;
481
489
  constructor(e) {
482
490
  this.store = e;
@@ -504,7 +512,7 @@ var Ie = class {
504
512
  }
505
513
  return Promise.all(e.map((e) => this.consume(e, t)));
506
514
  }
507
- }, Re = class {
515
+ }, Le = class {
508
516
  entries = /* @__PURE__ */ new Map();
509
517
  maxEntries;
510
518
  constructor(e = 512) {
@@ -534,20 +542,20 @@ var Ie = class {
534
542
  this.entries.delete(e);
535
543
  }
536
544
  };
537
- function ze(e, t) {
545
+ function Re(e, t) {
538
546
  return `${t}|${e.alg}|${e.keyId}`;
539
547
  }
540
- function Be(e) {
548
+ function ze(e) {
541
549
  if (!e || typeof e != "object") return !1;
542
550
  let t = e;
543
551
  return !!(t.header && t.body);
544
552
  }
545
- function Ve(e) {
553
+ function Be(e) {
546
554
  if (!e || typeof e != "object") return !1;
547
555
  let t = e;
548
556
  return t.v === "7h3/0.1" && typeof t.mid == "string" && typeof t.i == "string";
549
557
  }
550
- function He(e) {
558
+ function Ve(e) {
551
559
  return {
552
560
  header: {
553
561
  version: e.v,
@@ -571,7 +579,7 @@ function He(e) {
571
579
  } : void 0
572
580
  };
573
581
  }
574
- function Ue(e) {
582
+ function He(e) {
575
583
  return {
576
584
  v: e.header.version,
577
585
  mid: e.header.messageId,
@@ -591,15 +599,15 @@ function Ue(e) {
591
599
  } : void 0
592
600
  };
593
601
  }
594
- function We(e) {
595
- if (e instanceof Uint8Array) return Fe(e);
602
+ function Ue(e) {
603
+ if (e instanceof Uint8Array) return Pe(e);
596
604
  try {
597
605
  let t = JSON.parse(e);
598
- return Ve(t) ? {
606
+ return Be(t) ? {
599
607
  ok: !0,
600
608
  diagnostics: [],
601
- envelope: He(t)
602
- } : Be(t) ? {
609
+ envelope: Ve(t)
610
+ } : ze(t) ? {
603
611
  ok: !0,
604
612
  diagnostics: [],
605
613
  envelope: t
@@ -622,20 +630,20 @@ function We(e) {
622
630
  };
623
631
  }
624
632
  }
625
- function Ge(e, t = "json") {
626
- return t === "binary" ? Pe(e) : JSON.stringify(t === "compact" ? Ue(e) : e);
633
+ function j(e, t = "json") {
634
+ return t === "binary" ? Ne(e) : JSON.stringify(t === "compact" ? He(e) : e);
627
635
  }
628
- function Ke(e, t = "compact") {
629
- return JSON.stringify(t === "compact" ? e.map(Ue) : e);
636
+ function We(e, t = "compact") {
637
+ return JSON.stringify(t === "compact" ? e.map(He) : e);
630
638
  }
631
- function qe(e) {
639
+ function Ge(e) {
632
640
  try {
633
641
  let t = JSON.parse(e);
634
- return Array.isArray(t) ? t.map((e) => Ve(e) ? {
642
+ return Array.isArray(t) ? t.map((e) => Be(e) ? {
635
643
  ok: !0,
636
644
  diagnostics: [],
637
- envelope: He(e)
638
- } : Be(e) ? {
645
+ envelope: Ve(e)
646
+ } : ze(e) ? {
639
647
  ok: !0,
640
648
  diagnostics: [],
641
649
  envelope: e
@@ -665,7 +673,7 @@ function qe(e) {
665
673
  }];
666
674
  }
667
675
  }
668
- async function k(e, t = {}) {
676
+ async function M(e, t = {}) {
669
677
  let n = t.nowMs ?? Date.now(), r = t.requireSignature ?? !0, i = t.maxClockSkewMs ?? 3e4;
670
678
  async function a(e) {
671
679
  t.telemetry && await t.telemetry({
@@ -673,7 +681,7 @@ async function k(e, t = {}) {
673
681
  ...e
674
682
  });
675
683
  }
676
- let o = typeof e == "string" || e instanceof Uint8Array ? We(e) : {
684
+ let o = typeof e == "string" || e instanceof Uint8Array ? Ue(e) : {
677
685
  ok: !0,
678
686
  diagnostics: [],
679
687
  envelope: e
@@ -699,7 +707,7 @@ async function k(e, t = {}) {
699
707
  envelope: o.envelope
700
708
  };
701
709
  }
702
- let s = [...w(o.envelope, n)];
710
+ let s = [...E(o.envelope, n)];
703
711
  if (s.some((e) => e.level === "error")) return await a({
704
712
  phase: "rejected_validation",
705
713
  sender: o.envelope.header.sender,
@@ -731,7 +739,7 @@ async function k(e, t = {}) {
731
739
  diagnostics: s,
732
740
  envelope: o.envelope
733
741
  });
734
- let c, l = o.envelope.signature, u = ze(l, o.envelope.header.sender);
742
+ let c, l = o.envelope.signature, u = Re(l, o.envelope.header.sender);
735
743
  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) {
736
744
  let e = await t.secretResolver(l.keyId, o.envelope.header.sender);
737
745
  e && (c = {
@@ -756,7 +764,7 @@ async function k(e, t = {}) {
756
764
  diagnostics: s,
757
765
  envelope: o.envelope
758
766
  };
759
- if (!await ge(_({
767
+ if (!await he(_({
760
768
  header: o.envelope.header,
761
769
  body: o.envelope.body
762
770
  }), o.envelope.signature, c)) return s.push({
@@ -798,7 +806,7 @@ async function k(e, t = {}) {
798
806
  envelope: o.envelope
799
807
  };
800
808
  }
801
- async function Je(e, t = {}) {
809
+ async function Ke(e, t = {}) {
802
810
  let n = Math.max(1, Math.floor(t.batchConcurrency ?? Infinity));
803
811
  return (async (e) => {
804
812
  let r = Array(e.length), i = 0, a = Number.isFinite(n) ? Math.min(n, e.length) : e.length;
@@ -807,48 +815,48 @@ async function Je(e, t = {}) {
807
815
  let n = i;
808
816
  i += 1;
809
817
  let a = e[n];
810
- a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await k(a, t);
818
+ a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await M(a, t);
811
819
  }
812
820
  })), await t.telemetry?.({
813
821
  phase: "batch_summary",
814
822
  nowMs: t.nowMs ?? Date.now(),
815
823
  reason: `items=${e.length};accepted=${r.filter((e) => e?.ok).length}`
816
824
  }), r;
817
- })(typeof e == "string" ? qe(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
825
+ })(typeof e == "string" ? Ge(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
818
826
  }
819
- var Ye = class {
827
+ var qe = class {
820
828
  options;
821
829
  constructor(e = {}) {
822
830
  this.options = {
823
831
  ...e,
824
- replayCache: e.replayCache ?? new O(),
825
- verificationMaterialCache: e.verificationMaterialCache ?? new Re()
832
+ replayCache: e.replayCache ?? new A(),
833
+ verificationMaterialCache: e.verificationMaterialCache ?? new Le()
826
834
  };
827
835
  }
828
836
  receive(e, t = Date.now()) {
829
- return k(e, {
837
+ return M(e, {
830
838
  ...this.options,
831
839
  nowMs: t
832
840
  });
833
841
  }
834
842
  receiveBatch(e, t = Date.now()) {
835
- return Je(e, {
843
+ return Ke(e, {
836
844
  ...this.options,
837
845
  nowMs: t
838
846
  });
839
847
  }
840
848
  };
841
- async function Xe(e) {
842
- return x(T(e), e.secret, e.keyId);
849
+ async function Je(e) {
850
+ return S(D(e), e.secret, e.keyId);
843
851
  }
844
852
  //#endregion
845
853
  //#region src/protocolCapabilities.ts
846
- var Ze = [
854
+ var Ye = [
847
855
  "binary",
848
856
  "compact",
849
857
  "json"
850
- ], Qe = ["fast", "receipt"];
851
- function $e(e) {
858
+ ], Xe = ["fast", "receipt"];
859
+ function Ze(e) {
852
860
  return {
853
861
  agent: e.agent,
854
862
  capabilities: e.capabilities ?? [],
@@ -857,10 +865,10 @@ function $e(e) {
857
865
  ackModes: e.ackModes ?? ["receipt"]
858
866
  };
859
867
  }
860
- function et(e) {
868
+ function Qe(e) {
861
869
  return JSON.stringify(e);
862
870
  }
863
- function tt(e) {
871
+ function $e(e) {
864
872
  try {
865
873
  let t = JSON.parse(e);
866
874
  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 : {
@@ -874,8 +882,8 @@ function tt(e) {
874
882
  return null;
875
883
  }
876
884
  }
877
- function nt(e, t) {
878
- let n = Ze.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = Qe.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
885
+ function et(e, t) {
886
+ let n = Ye.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = Xe.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
879
887
  return {
880
888
  wireFormat: n,
881
889
  batchMax: Math.max(1, Math.min(e.batchMax, t.batchMax)),
@@ -884,7 +892,7 @@ function nt(e, t) {
884
892
  }
885
893
  //#endregion
886
894
  //#region src/keyRotation.ts
887
- var rt = class {
895
+ var tt = class {
888
896
  records;
889
897
  constructor(e = []) {
890
898
  this.records = [...e];
@@ -903,12 +911,12 @@ var rt = class {
903
911
  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;
904
912
  }
905
913
  };
906
- function it(e, t = () => Date.now()) {
914
+ function nt(e, t = () => Date.now()) {
907
915
  return async (n, r) => e.resolveVerificationMaterial(n, r, t());
908
916
  }
909
917
  //#endregion
910
918
  //#region src/protocolAgent.ts
911
- var at = class {
919
+ var rt = class {
912
920
  agentId;
913
921
  outboundSecret;
914
922
  keyId;
@@ -922,13 +930,13 @@ var at = class {
922
930
  resolveInboundSecret;
923
931
  onTask;
924
932
  constructor(e) {
925
- 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 O(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
933
+ 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;
926
934
  }
927
935
  async inboundSecretResolver(e, t) {
928
936
  return this.resolveInboundSecret ? this.resolveInboundSecret(e, t) : this.sharedSecrets[t];
929
937
  }
930
938
  async createSignedIntent(e) {
931
- return x(T({
939
+ return S(D({
932
940
  sender: this.agentId,
933
941
  recipient: e.recipient,
934
942
  intent: e.intent,
@@ -942,7 +950,7 @@ var at = class {
942
950
  }), this.outboundSecret, this.keyId);
943
951
  }
944
952
  async receiveAndRespond(e, t = Date.now()) {
945
- let n = await k(e, {
953
+ let n = await M(e, {
946
954
  nowMs: t,
947
955
  requireSignature: this.requireSignature,
948
956
  replayCache: this.replayCache,
@@ -973,7 +981,7 @@ var at = class {
973
981
  if (e.body.intent === "CAPS") return this.createSignedIntent({
974
982
  recipient: e.header.sender,
975
983
  intent: "RESULT",
976
- content: et($e({
984
+ content: Qe(Ze({
977
985
  agent: this.agentId,
978
986
  capabilities: this.capabilities,
979
987
  wireFormats: this.supportedWireFormats,
@@ -1001,14 +1009,14 @@ var at = class {
1001
1009
  }
1002
1010
  return null;
1003
1011
  }
1004
- }, ot = class {
1012
+ }, it = class {
1005
1013
  session;
1006
1014
  wireFormat;
1007
1015
  constructor(e) {
1008
- this.session = new at(e), this.wireFormat = e.wireFormat ?? "compact";
1016
+ this.session = new rt(e), this.wireFormat = e.wireFormat ?? "compact";
1009
1017
  }
1010
1018
  toRaw(e) {
1011
- return Ge(e, this.wireFormat);
1019
+ return j(e, this.wireFormat);
1012
1020
  }
1013
1021
  async createRawIntent(e) {
1014
1022
  let t = await this.session.createSignedIntent(e);
@@ -1022,12 +1030,12 @@ var at = class {
1022
1030
  return r.response && await t(this.toRaw(r.response), r.response), r;
1023
1031
  }
1024
1032
  };
1025
- function st(e) {
1026
- return new ot(e);
1033
+ function at(e) {
1034
+ return new it(e);
1027
1035
  }
1028
1036
  //#endregion
1029
1037
  //#region src/frameworkAdapters.ts
1030
- async function ct(e, t, n = {}) {
1038
+ async function ot(e, t, n = {}) {
1031
1039
  return e.createRawIntent({
1032
1040
  recipient: n.recipient,
1033
1041
  intent: "TASK",
@@ -1036,7 +1044,7 @@ async function ct(e, t, n = {}) {
1036
1044
  correlationId: n.correlationId
1037
1045
  });
1038
1046
  }
1039
- function lt(e) {
1047
+ function st(e) {
1040
1048
  return {
1041
1049
  content: e.body.content,
1042
1050
  name: e.body.intent,
@@ -1050,7 +1058,7 @@ function lt(e) {
1050
1058
  }
1051
1059
  };
1052
1060
  }
1053
- async function ut(e, t, n = {}) {
1061
+ async function ct(e, t, n = {}) {
1054
1062
  return e.createRawIntent({
1055
1063
  recipient: n.recipient,
1056
1064
  intent: "TASK",
@@ -1059,7 +1067,7 @@ async function ut(e, t, n = {}) {
1059
1067
  correlationId: n.correlationId
1060
1068
  });
1061
1069
  }
1062
- function dt(e) {
1070
+ function lt(e) {
1063
1071
  return {
1064
1072
  role: e.body.intent === "TASK" ? "user" : "assistant",
1065
1073
  content: e.body.content,
@@ -1072,15 +1080,15 @@ function dt(e) {
1072
1080
  }
1073
1081
  };
1074
1082
  }
1075
- function ft(e) {
1083
+ function ut(e) {
1076
1084
  return `mcp.${e}`;
1077
1085
  }
1078
- async function pt(e, t, n = {}) {
1086
+ async function dt(e, t, n = {}) {
1079
1087
  async function r(e) {
1080
1088
  n.onPolicyEvent && await n.onPolicyEvent(e);
1081
1089
  }
1082
1090
  if (n.allowedMethods && !n.allowedMethods.includes(t.method)) {
1083
- let e = n.methodToCapability ? n.methodToCapability(t.method) : ft(t.method), i = {
1091
+ let e = n.methodToCapability ? n.methodToCapability(t.method) : ut(t.method), i = {
1084
1092
  intent: "TASK",
1085
1093
  recipient: n.recipient,
1086
1094
  capability: e,
@@ -1095,7 +1103,7 @@ async function pt(e, t, n = {}) {
1095
1103
  reason: "method_not_allowed"
1096
1104
  }), Error(`JSON-RPC method '${t.method}' is not allowed`);
1097
1105
  }
1098
- let i = n.methodToCapability ? n.methodToCapability(t.method) : ft(t.method), a = {
1106
+ let i = n.methodToCapability ? n.methodToCapability(t.method) : ut(t.method), a = {
1099
1107
  intent: "TASK",
1100
1108
  recipient: n.recipient,
1101
1109
  capability: i,
@@ -1149,7 +1157,7 @@ async function pt(e, t, n = {}) {
1149
1157
  })
1150
1158
  });
1151
1159
  }
1152
- function mt(e, t, n = {}) {
1160
+ function ft(e, t, n = {}) {
1153
1161
  if (e.body.intent === "ERROR") return {
1154
1162
  jsonrpc: "2.0",
1155
1163
  id: t,
@@ -1176,16 +1184,16 @@ function mt(e, t, n = {}) {
1176
1184
  }
1177
1185
  //#endregion
1178
1186
  //#region src/runtimePolicy.ts
1179
- function ht(e) {
1187
+ function pt(e) {
1180
1188
  return typeof e == "object" && !!e && !Array.isArray(e);
1181
1189
  }
1182
- function gt(e, t) {
1190
+ function mt(e, t) {
1183
1191
  if (typeof e != "string" || e.trim().length === 0) throw Error(`Invalid runtime policy: '${t}' must be a non-empty string`);
1184
1192
  return e;
1185
1193
  }
1186
- function _t(e) {
1187
- if (!ht(e)) throw Error("Invalid runtime policy: root must be an object");
1188
- let t = gt(e.version, "version"), n = gt(e.name, "name"), r = gt(e.status, "status");
1194
+ function ht(e) {
1195
+ if (!pt(e)) throw Error("Invalid runtime policy: root must be an object");
1196
+ let t = mt(e.version, "version"), n = mt(e.name, "name"), r = mt(e.status, "status");
1189
1197
  return {
1190
1198
  ...e,
1191
1199
  version: t,
@@ -1193,7 +1201,7 @@ function _t(e) {
1193
1201
  status: r
1194
1202
  };
1195
1203
  }
1196
- function vt(e) {
1204
+ function gt(e) {
1197
1205
  let t;
1198
1206
  try {
1199
1207
  t = JSON.parse(e);
@@ -1201,9 +1209,9 @@ function vt(e) {
1201
1209
  let t = e instanceof Error ? e.message : String(e);
1202
1210
  throw Error(`Invalid runtime policy JSON: ${t}`);
1203
1211
  }
1204
- return _t(t);
1212
+ return ht(t);
1205
1213
  }
1206
- async function yt(e) {
1214
+ async function _t(e) {
1207
1215
  if (typeof fetch == "function") {
1208
1216
  let t = await fetch(e);
1209
1217
  if (!t.ok) throw Error(`Failed to fetch runtime policy at '${e}': ${t.status} ${t.statusText}`);
@@ -1211,26 +1219,26 @@ async function yt(e) {
1211
1219
  }
1212
1220
  throw Error("No default runtime file reader available in this environment. Provide 'readTextFile' in loadRuntimePolicy(options).");
1213
1221
  }
1214
- async function bt(e = {}) {
1222
+ async function vt(e = {}) {
1215
1223
  let t = e.path ?? "AI_RUNTIME_POLICY.json";
1216
- return vt(await (e.readTextFile ?? yt)(t));
1224
+ return gt(await (e.readTextFile ?? _t)(t));
1217
1225
  }
1218
1226
  //#endregion
1219
1227
  //#region src/policyEnforcer.ts
1220
- function xt(e, t) {
1228
+ function yt(e, t) {
1221
1229
  if (!Array.isArray(e) || e.length !== 2) throw Error(`Invalid policy tuning range '${t}': expected [min,max]`);
1222
1230
  let n = Number(e[0]), r = Number(e[1]);
1223
1231
  if (!Number.isFinite(n) || !Number.isFinite(r) || n <= 0 || r < n) throw Error(`Invalid policy tuning range '${t}': expected positive ascending numbers`);
1224
1232
  return [Math.floor(n), Math.floor(r)];
1225
1233
  }
1226
- function St(e) {
1234
+ function bt(e) {
1227
1235
  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";
1228
1236
  }
1229
- function Ct(e) {
1237
+ function xt(e) {
1230
1238
  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) => ({
1231
- batchSizeRange: xt(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1232
- inflightCapRange: xt(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1233
- retryBackoffMsRange: xt(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1239
+ batchSizeRange: yt(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1240
+ inflightCapRange: yt(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1241
+ retryBackoffMsRange: yt(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1234
1242
  });
1235
1243
  function u(e) {
1236
1244
  return e.concurrency >= 100 ? "http-binary-batch" : e.latencySensitive ? "ws-batch" : e.compatibilityFirst ? "http" : "ws-batch";
@@ -1267,28 +1275,28 @@ function Ct(e) {
1267
1275
  }
1268
1276
  };
1269
1277
  }
1270
- async function A(e = {}) {
1271
- let t = await bt(e);
1278
+ async function N(e = {}) {
1279
+ let t = await vt(e);
1272
1280
  return {
1273
1281
  policy: t,
1274
- enforcer: Ct(t)
1282
+ enforcer: xt(t)
1275
1283
  };
1276
1284
  }
1277
- function wt(e) {
1278
- return St(e);
1285
+ function St(e) {
1286
+ return bt(e);
1279
1287
  }
1280
1288
  //#endregion
1281
1289
  //#region src/mcpGateway.ts
1282
- var Tt = [
1290
+ var Ct = [
1283
1291
  "tools/call",
1284
1292
  "resources/read",
1285
1293
  "prompts/get"
1286
1294
  ];
1287
- function Et(e) {
1295
+ function wt(e) {
1288
1296
  return JSON.stringify(e);
1289
1297
  }
1290
- function j(e, t, n) {
1291
- return Et({
1298
+ function Tt(e, t, n) {
1299
+ return wt({
1292
1300
  jsonrpc: "2.0",
1293
1301
  id: e,
1294
1302
  error: {
@@ -1297,7 +1305,7 @@ function j(e, t, n) {
1297
1305
  }
1298
1306
  });
1299
1307
  }
1300
- function Dt(e) {
1308
+ function Et(e) {
1301
1309
  let t = JSON.parse(e);
1302
1310
  return t.jsonrpc !== "2.0" || typeof t.method != "string" || t.method.length === 0 || typeof t.id != "string" && typeof t.id != "number" ? null : {
1303
1311
  jsonrpc: "2.0",
@@ -1306,30 +1314,30 @@ function Dt(e) {
1306
1314
  params: t.params
1307
1315
  };
1308
1316
  }
1309
- function Ot(e) {
1317
+ function Dt(e) {
1310
1318
  return e.includes("not allowed") ? -32601 : e.includes("not authorized") ? -32001 : e.includes("rate-limited") ? -32002 : -32603;
1311
1319
  }
1312
- function kt(e) {
1313
- let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Tt, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1320
+ function Ot(e) {
1321
+ let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Ct, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1314
1322
  async function s(t) {
1315
1323
  e.onAuditEvent && await e.onAuditEvent({
1316
1324
  ...t,
1317
1325
  timestampMs: Date.now()
1318
1326
  });
1319
1327
  }
1320
- let c = st({
1328
+ let c = at({
1321
1329
  agentId: t,
1322
1330
  outboundSecret: e.sharedSecret,
1323
1331
  sharedSecrets: { [n]: e.sharedSecret },
1324
1332
  wireFormat: a
1325
- }), l = st({
1333
+ }), l = at({
1326
1334
  agentId: n,
1327
1335
  outboundSecret: e.sharedSecret,
1328
1336
  sharedSecrets: { [t]: e.sharedSecret },
1329
1337
  wireFormat: o,
1330
1338
  onTask: async (e) => ({
1331
1339
  intent: "RESULT",
1332
- content: Et({
1340
+ content: wt({
1333
1341
  ok: !0,
1334
1342
  capability: e.body.capability,
1335
1343
  content: e.body.content
@@ -1342,18 +1350,18 @@ function kt(e) {
1342
1350
  if (!i) return null;
1343
1351
  let a = null;
1344
1352
  try {
1345
- let t = Dt(i);
1353
+ let t = Et(i);
1346
1354
  if (!t) return await s({
1347
1355
  phase: "request_error",
1348
1356
  code: -32600,
1349
1357
  message: "Invalid Request"
1350
- }), j(null, -32600, "Invalid Request");
1358
+ }), Tt(null, -32600, "Invalid Request");
1351
1359
  a = t.id, await s({
1352
1360
  phase: "request_received",
1353
1361
  id: t.id,
1354
1362
  method: t.method
1355
1363
  });
1356
- let o = await pt(c, t, {
1364
+ let o = await dt(c, t, {
1357
1365
  recipient: n,
1358
1366
  allowedMethods: r,
1359
1367
  methodToCapability: e.methodToCapability,
@@ -1377,7 +1385,7 @@ function kt(e) {
1377
1385
  method: t.method,
1378
1386
  code: -32603,
1379
1387
  message: "AIP worker did not produce a response"
1380
- }), j(a, -32603, "AIP worker did not produce a response");
1388
+ }), Tt(a, -32603, "AIP worker did not produce a response");
1381
1389
  let d = await c.receiveRaw(u);
1382
1390
  return !d.ok || !d.received ? (await s({
1383
1391
  phase: "verification_failed",
@@ -1385,25 +1393,25 @@ function kt(e) {
1385
1393
  method: t.method,
1386
1394
  code: -32603,
1387
1395
  message: "AIP verification failed"
1388
- }), j(a, -32603, "AIP verification failed")) : (await s({
1396
+ }), Tt(a, -32603, "AIP verification failed")) : (await s({
1389
1397
  phase: "request_success",
1390
1398
  id: t.id,
1391
1399
  method: t.method
1392
- }), Et(mt(d.received, t.id)));
1400
+ }), wt(ft(d.received, t.id)));
1393
1401
  } catch (e) {
1394
- let t = e instanceof Error ? e.message : "Internal error", n = Ot(t);
1402
+ let t = e instanceof Error ? e.message : "Internal error", n = Dt(t);
1395
1403
  return await s({
1396
1404
  phase: "request_error",
1397
1405
  id: a,
1398
1406
  code: n,
1399
1407
  message: t
1400
- }), j(a, n, t);
1408
+ }), Tt(a, n, t);
1401
1409
  }
1402
1410
  } };
1403
1411
  }
1404
- async function At(e) {
1405
- if (!e.runtimePolicy?.enabled) return kt(e);
1406
- let { enforcer: t } = await A(e.runtimePolicy.options);
1412
+ async function kt(e) {
1413
+ if (!e.runtimePolicy?.enabled) return Ot(e);
1414
+ let { enforcer: t } = await N(e.runtimePolicy.options);
1407
1415
  t.assertInvariant({
1408
1416
  signatureVerification: !0,
1409
1417
  canonicalization: !0,
@@ -1415,7 +1423,7 @@ async function At(e) {
1415
1423
  latencySensitive: e.runtimePolicy.latencySensitive,
1416
1424
  compatibilityFirst: e.runtimePolicy.compatibilityFirst
1417
1425
  }), r = n.includes("binary") ? "binary" : "compact";
1418
- return kt({
1426
+ return Ot({
1419
1427
  ...e,
1420
1428
  gatewayWireFormat: r,
1421
1429
  workerWireFormat: r,
@@ -1431,14 +1439,14 @@ async function At(e) {
1431
1439
  }
1432
1440
  //#endregion
1433
1441
  //#region src/runtimePolicyManager.ts
1434
- var jt = class {
1442
+ var At = class {
1435
1443
  snapshot = null;
1436
1444
  options;
1437
1445
  constructor(e = {}) {
1438
1446
  this.options = e;
1439
1447
  }
1440
1448
  async loadInitial() {
1441
- let e = await A(this.options);
1449
+ let e = await N(this.options);
1442
1450
  return this.snapshot = {
1443
1451
  ...e,
1444
1452
  loadedAtMs: Date.now()
@@ -1451,7 +1459,7 @@ var jt = class {
1451
1459
  async refresh() {
1452
1460
  let e = this.snapshot;
1453
1461
  try {
1454
- let e = await A(this.options);
1462
+ let e = await N(this.options);
1455
1463
  return this.snapshot = {
1456
1464
  ...e,
1457
1465
  loadedAtMs: Date.now()
@@ -1461,7 +1469,7 @@ var jt = class {
1461
1469
  throw t;
1462
1470
  }
1463
1471
  }
1464
- }, Mt = {
1472
+ }, jt = {
1465
1473
  dev: {
1466
1474
  environment: "dev",
1467
1475
  mode: "ws-batch",
@@ -1487,12 +1495,12 @@ var jt = class {
1487
1495
  retryMaxAttempts: 3
1488
1496
  }
1489
1497
  };
1490
- function Nt(e) {
1491
- return Mt[e];
1498
+ function Mt(e) {
1499
+ return jt[e];
1492
1500
  }
1493
1501
  //#endregion
1494
1502
  //#region src/policyTelemetryFeedback.ts
1495
- function Pt(e) {
1503
+ function Nt(e) {
1496
1504
  let t = [], n = "normal";
1497
1505
  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")), {
1498
1506
  severity: n,
@@ -1501,7 +1509,7 @@ function Pt(e) {
1501
1509
  }
1502
1510
  //#endregion
1503
1511
  //#region src/redisClient.ts
1504
- var Ft = class {
1512
+ var Pt = class {
1505
1513
  entries = /* @__PURE__ */ new Map();
1506
1514
  now;
1507
1515
  constructor(e = {}) {
@@ -1547,13 +1555,13 @@ var Ft = class {
1547
1555
  };
1548
1556
  return t;
1549
1557
  }
1550
- }, It = class {
1558
+ }, Ft = class {
1551
1559
  keyPrefix;
1552
1560
  client;
1553
1561
  constructor(e = {}) {
1554
1562
  if (this.keyPrefix = e.keyPrefix ?? "7h3:nonce:", e.client) this.client = e.client;
1555
1563
  else {
1556
- let e = new Ft();
1564
+ let e = new Pt();
1557
1565
  this.client = {
1558
1566
  set: (t, n, r) => e.set(t, n, {
1559
1567
  nx: r?.nx,
@@ -1572,7 +1580,7 @@ var Ft = class {
1572
1580
  px: Math.max(1, t)
1573
1581
  }) === null;
1574
1582
  }
1575
- }, Lt = class {
1583
+ }, It = class {
1576
1584
  nodes;
1577
1585
  constructor(e) {
1578
1586
  this.nodes = e;
@@ -1581,17 +1589,17 @@ var Ft = class {
1581
1589
  return (await Promise.all(this.nodes.map((n) => n.check(e, t)))).some((e) => e);
1582
1590
  }
1583
1591
  };
1584
- function Rt(e, t = {}) {
1585
- return zt(e) ? Vt(e, t) : new It(e);
1592
+ function Lt(e, t = {}) {
1593
+ return Rt(e) ? Bt(e, t) : new Ft(e);
1586
1594
  }
1587
- function zt(e) {
1595
+ function Rt(e) {
1588
1596
  return typeof e == "object" && !!e && typeof e.set == "function" && (typeof e.pipeline == "function" || !("quit" in e));
1589
1597
  }
1590
- function Bt(e) {
1591
- return new Lt(e.map((e) => new It({ redisUrl: e })));
1598
+ function zt(e) {
1599
+ return new It(e.map((e) => new Ft({ redisUrl: e })));
1592
1600
  }
1593
- function Vt(e, t = {}) {
1594
- let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Vt(new Ft(), {
1601
+ function Bt(e, t = {}) {
1602
+ let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Bt(new Pt(), {
1595
1603
  keyPrefix: n,
1596
1604
  errorBehavior: "reject"
1597
1605
  }) : void 0);
@@ -1631,7 +1639,7 @@ function Vt(e, t = {}) {
1631
1639
  }
1632
1640
  //#endregion
1633
1641
  //#region src/revocation.ts
1634
- var Ht = class {
1642
+ var Vt = class {
1635
1643
  revoked = /* @__PURE__ */ new Map();
1636
1644
  now;
1637
1645
  constructor(e = {}) {
@@ -1648,7 +1656,7 @@ var Ht = class {
1648
1656
  this.revoked.set(this.makeKey(e, t), n.untilMs ?? Infinity);
1649
1657
  }
1650
1658
  };
1651
- function Ut(e, t = {}) {
1659
+ function Ht(e, t = {}) {
1652
1660
  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();
1653
1661
  function c(e, t) {
1654
1662
  return `${n}${e}${t}`;
@@ -1680,7 +1688,7 @@ function Ut(e, t = {}) {
1680
1688
  }
1681
1689
  };
1682
1690
  }
1683
- function Wt(e, t, n = {}) {
1691
+ function Ut(e, t, n = {}) {
1684
1692
  let r = n.nowMsProvider ?? (() => Date.now());
1685
1693
  return async (n, i) => {
1686
1694
  if (!await t.isRevoked(i, n.keyId, r())) return e(n, i);
@@ -1688,7 +1696,7 @@ function Wt(e, t, n = {}) {
1688
1696
  }
1689
1697
  //#endregion
1690
1698
  //#region src/mcpWrapper.ts
1691
- function Gt(e, t, n) {
1699
+ function Wt(e, t, n) {
1692
1700
  return {
1693
1701
  jsonrpc: "2.0",
1694
1702
  id: e,
@@ -1698,20 +1706,20 @@ function Gt(e, t, n) {
1698
1706
  }
1699
1707
  };
1700
1708
  }
1701
- function Kt(e, t) {
1709
+ function Gt(e, t) {
1702
1710
  return {
1703
1711
  requireSignature: !0,
1704
1712
  ...e.receive,
1705
1713
  replayCache: t
1706
1714
  };
1707
1715
  }
1708
- function qt(e, t) {
1709
- let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new O());
1716
+ function Kt(e, t) {
1717
+ let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Gt(t, t.receive?.replayCache ?? new A());
1710
1718
  async function a(e) {
1711
- return Ge(await t.sign(e), n);
1719
+ return j(await t.sign(e), n);
1712
1720
  }
1713
1721
  function o(e, n, i, o) {
1714
- return a(T({
1722
+ return a(D({
1715
1723
  sender: t.selfAgentId,
1716
1724
  recipient: e,
1717
1725
  intent: n,
@@ -1721,29 +1729,29 @@ function qt(e, t) {
1721
1729
  }));
1722
1730
  }
1723
1731
  return async (n) => {
1724
- let r = await k(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1725
- if (!r.ok || !r.envelope) return o(a, "ERROR", Gt(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1726
- if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", Gt(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1732
+ let r = await M(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1733
+ if (!r.ok || !r.envelope) return o(a, "ERROR", Wt(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1734
+ if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", Wt(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1727
1735
  let c;
1728
1736
  try {
1729
1737
  c = JSON.parse(r.envelope.body.content);
1730
1738
  } catch {
1731
- return o(a, "ERROR", Gt(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1739
+ return o(a, "ERROR", Wt(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1732
1740
  }
1733
1741
  let l;
1734
1742
  try {
1735
1743
  l = await e(c);
1736
1744
  } catch (e) {
1737
- l = Gt(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1745
+ l = Wt(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1738
1746
  }
1739
1747
  return o(r.envelope.header.sender, "RESULT", l, s);
1740
1748
  };
1741
1749
  }
1742
- function Jt(e) {
1743
- let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new O());
1750
+ function qt(e) {
1751
+ let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Gt(e, e.receive?.replayCache ?? new A());
1744
1752
  return {
1745
1753
  async encodeRequest(r) {
1746
- let i = T({
1754
+ let i = D({
1747
1755
  sender: e.selfAgentId,
1748
1756
  recipient: e.peerAgentId,
1749
1757
  intent: "TASK",
@@ -1751,12 +1759,12 @@ function Jt(e) {
1751
1759
  ttlMs: n
1752
1760
  });
1753
1761
  return {
1754
- raw: Ge(await e.sign(i), t),
1762
+ raw: j(await e.sign(i), t),
1755
1763
  messageId: i.header.messageId
1756
1764
  };
1757
1765
  },
1758
1766
  async decodeResponse(t, n = {}) {
1759
- let i = await k(t, r);
1767
+ let i = await M(t, r);
1760
1768
  if (!i.ok || !i.envelope) {
1761
1769
  let e = i.diagnostics.find((e) => e.level === "error")?.message ?? "unknown";
1762
1770
  throw Error(`AIP response verification failed: ${e}`);
@@ -1768,8 +1776,8 @@ function Jt(e) {
1768
1776
  }
1769
1777
  };
1770
1778
  }
1771
- function Yt(e, t) {
1772
- let n = Jt(t);
1779
+ function Jt(e, t) {
1780
+ let n = qt(t);
1773
1781
  return async (t) => {
1774
1782
  let { raw: r, messageId: i } = await n.encodeRequest(t);
1775
1783
  return n.decodeResponse(await e(r), { expectCorrelationId: i });
@@ -1777,15 +1785,15 @@ function Yt(e, t) {
1777
1785
  }
1778
1786
  //#endregion
1779
1787
  //#region src/mcpTransports.ts
1780
- var M = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
1788
+ var P = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
1781
1789
  t.exports = {};
1782
1790
  })))(), 1);
1783
- function Xt(e) {
1791
+ function Yt(e) {
1784
1792
  if (typeof e != "string") throw Error("stdio adapter supports json/compact (string) wire formats; use the HTTP adapter for binary");
1785
1793
  return e;
1786
1794
  }
1787
- function Zt(e, t = {}) {
1788
- let n = t.input ?? process.stdin, r = t.output ?? process.stdout, i = M.default.createInterface({
1795
+ function Xt(e, t = {}) {
1796
+ let n = t.input ?? process.stdin, r = t.output ?? process.stdout, i = P.default.createInterface({
1789
1797
  input: n,
1790
1798
  crlfDelay: Infinity
1791
1799
  }), a = Promise.resolve(), o = (n) => {
@@ -1793,7 +1801,7 @@ function Zt(e, t = {}) {
1793
1801
  i && (a = a.then(async () => {
1794
1802
  try {
1795
1803
  let t = await e(i);
1796
- r.write(`${Xt(t)}\n`);
1804
+ r.write(`${Yt(t)}\n`);
1797
1805
  } catch (e) {
1798
1806
  t.onError?.(e);
1799
1807
  }
@@ -1803,8 +1811,8 @@ function Zt(e, t = {}) {
1803
1811
  i.off("line", o), i.close();
1804
1812
  } };
1805
1813
  }
1806
- function Qt(e) {
1807
- let t = M.default.createInterface({
1814
+ function Zt(e) {
1815
+ let t = P.default.createInterface({
1808
1816
  input: e.input,
1809
1817
  crlfDelay: Infinity
1810
1818
  }), n = [], r = (e) => {
@@ -1815,7 +1823,7 @@ function Qt(e) {
1815
1823
  };
1816
1824
  return t.on("line", r), {
1817
1825
  send(t) {
1818
- let r = Xt(t);
1826
+ let r = Yt(t);
1819
1827
  return new Promise((t) => {
1820
1828
  n.push(t), e.output.write(`${r}\n`);
1821
1829
  });
@@ -1825,7 +1833,7 @@ function Qt(e) {
1825
1833
  }
1826
1834
  };
1827
1835
  }
1828
- function $t(e, t = {}) {
1836
+ function Qt(e, t = {}) {
1829
1837
  return (n, r) => {
1830
1838
  let i = [];
1831
1839
  n.on("data", (e) => i.push(e)), n.on("error", () => {
@@ -1849,7 +1857,7 @@ function $t(e, t = {}) {
1849
1857
  });
1850
1858
  };
1851
1859
  }
1852
- function en(e) {
1860
+ function $t(e) {
1853
1861
  let t = e.fetchImpl ?? fetch, n = e.binary ? "application/octet-stream" : "application/json";
1854
1862
  return { async send(r) {
1855
1863
  let i = await t(e.url, {
@@ -1865,12 +1873,12 @@ function en(e) {
1865
1873
  }
1866
1874
  //#endregion
1867
1875
  //#region src/keyRegistry.ts
1868
- function tn(e) {
1876
+ function en(e) {
1869
1877
  return { async getPublicKey(t) {
1870
1878
  return e[t] ?? null;
1871
1879
  } };
1872
1880
  }
1873
- function nn(...e) {
1881
+ function tn(...e) {
1874
1882
  return {
1875
1883
  async getPublicKey(t) {
1876
1884
  for (let n of e) {
@@ -1889,7 +1897,7 @@ function nn(...e) {
1889
1897
  }
1890
1898
  };
1891
1899
  }
1892
- function rn(e, t) {
1900
+ function nn(e, t) {
1893
1901
  let n = t?.ttlMs ?? 6e4, r = /* @__PURE__ */ new Map();
1894
1902
  async function i(e, t) {
1895
1903
  let i = Date.now(), a = r.get(e);
@@ -1911,18 +1919,18 @@ function rn(e, t) {
1911
1919
  }
1912
1920
  //#endregion
1913
1921
  //#region src/cborCodec.ts
1914
- var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3, cn = 4, ln = 5, un = 7, dn = 244, fn = 245, pn = 246, mn = 24, hn = 25, gn = 26, _n = 27, vn = 27, yn = class {
1922
+ var F = new TextEncoder(), rn = new TextDecoder(), I = 0, an = 1, on = 2, L = 3, sn = 4, cn = 5, ln = 7, un = 244, dn = 245, fn = 246, pn = 24, mn = 25, hn = 26, gn = 27, _n = 27, vn = class {
1915
1923
  chunks = [];
1916
1924
  encode(e) {
1917
1925
  return this.chunks = [], this._encode(e), this._concat();
1918
1926
  }
1919
1927
  _encode(e) {
1920
1928
  if (e == null) {
1921
- this.chunks.push(new Uint8Array([pn]));
1929
+ this.chunks.push(new Uint8Array([fn]));
1922
1930
  return;
1923
1931
  }
1924
1932
  if (typeof e == "boolean") {
1925
- this.chunks.push(new Uint8Array([e ? fn : dn]));
1933
+ this.chunks.push(new Uint8Array([e ? dn : un]));
1926
1934
  return;
1927
1935
  }
1928
1936
  if (typeof e == "number") {
@@ -1960,28 +1968,28 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
1960
1968
  new DataView(t).setFloat64(0, e, !1), this.chunks.push(new Uint8Array(t));
1961
1969
  return;
1962
1970
  }
1963
- e >= 0 ? this._encodeHead(P, e) : this._encodeHead(on, -1 - e);
1971
+ e >= 0 ? this._encodeHead(I, e) : this._encodeHead(an, -1 - e);
1964
1972
  }
1965
1973
  _float64Header() {
1966
1974
  return new Uint8Array([251]);
1967
1975
  }
1968
1976
  _encodeString(e) {
1969
- let t = N.encode(e);
1970
- this._encodeHead(F, t.length), this.chunks.push(t);
1977
+ let t = F.encode(e);
1978
+ this._encodeHead(L, t.length), this.chunks.push(t);
1971
1979
  }
1972
1980
  _encodeByteString(e) {
1973
- this._encodeHead(sn, e.length), this.chunks.push(e);
1981
+ this._encodeHead(on, e.length), this.chunks.push(e);
1974
1982
  }
1975
1983
  _encodeArray(e) {
1976
- this._encodeHead(cn, e.length);
1984
+ this._encodeHead(sn, e.length);
1977
1985
  for (let t of e) this._encode(t);
1978
1986
  }
1979
1987
  _encodeMapFromAnyEntries(e) {
1980
1988
  let t = e.map(([e, t]) => {
1981
1989
  let n;
1982
- if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(P, e);
1990
+ if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(I, e);
1983
1991
  else {
1984
- let t = N.encode(String(e)), r = this._encodeHeadBytes(F, t.length);
1992
+ let t = F.encode(String(e)), r = this._encodeHeadBytes(L, t.length);
1985
1993
  n = this._concatPair(r, t);
1986
1994
  }
1987
1995
  return {
@@ -1990,27 +1998,27 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
1990
1998
  value: t
1991
1999
  };
1992
2000
  });
1993
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2001
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(cn, t.length);
1994
2002
  for (let { key: e, value: n } of t) {
1995
- if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(P, e);
2003
+ if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(I, e);
1996
2004
  else {
1997
- let t = N.encode(String(e));
1998
- this._encodeHead(F, t.length), this.chunks.push(t);
2005
+ let t = F.encode(String(e));
2006
+ this._encodeHead(L, t.length), this.chunks.push(t);
1999
2007
  }
2000
2008
  this._encode(n);
2001
2009
  }
2002
2010
  }
2003
2011
  _encodeMapFromEntries(e) {
2004
2012
  let t = e.map(([e, t]) => {
2005
- let n = N.encode(e), r = this._encodeHeadBytes(F, n.length);
2013
+ let n = F.encode(e), r = this._encodeHeadBytes(L, n.length);
2006
2014
  return {
2007
2015
  keyBytes: n,
2008
2016
  keyEncoded: this._concatPair(r, n),
2009
2017
  value: t
2010
2018
  };
2011
2019
  });
2012
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2013
- for (let { keyBytes: e, value: n } of t) this._encodeHead(F, e.length), this.chunks.push(e), this._encode(n);
2020
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(cn, t.length);
2021
+ for (let { keyBytes: e, value: n } of t) this._encodeHead(L, e.length), this.chunks.push(e), this._encode(n);
2014
2022
  }
2015
2023
  _compareBytes(e, t) {
2016
2024
  let n = Math.min(e.length, t.length);
@@ -2030,24 +2038,24 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2030
2038
  _encodeHeadBytes(e, t) {
2031
2039
  let n = e << 5;
2032
2040
  if (t <= 23) return new Uint8Array([n | t]);
2033
- if (t <= 255) return new Uint8Array([n | mn, t]);
2041
+ if (t <= 255) return new Uint8Array([n | pn, t]);
2034
2042
  if (t <= 65535) {
2035
2043
  let e = /* @__PURE__ */ new ArrayBuffer(3), r = new DataView(e);
2036
- return r.setUint8(0, n | hn), r.setUint16(1, t, !1), new Uint8Array(e);
2044
+ return r.setUint8(0, n | mn), r.setUint16(1, t, !1), new Uint8Array(e);
2037
2045
  }
2038
2046
  if (t <= 4294967295) {
2039
2047
  let e = /* @__PURE__ */ new ArrayBuffer(5), r = new DataView(e);
2040
- return r.setUint8(0, n | gn), r.setUint32(1, t, !1), new Uint8Array(e);
2048
+ return r.setUint8(0, n | hn), r.setUint32(1, t, !1), new Uint8Array(e);
2041
2049
  }
2042
2050
  let r = /* @__PURE__ */ new ArrayBuffer(9), i = new DataView(r);
2043
- return i.setUint8(0, n | _n), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2051
+ return i.setUint8(0, n | gn), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2044
2052
  }
2045
2053
  _concat() {
2046
2054
  let e = this.chunks.reduce((e, t) => e + t.length, 0), t = new Uint8Array(e), n = 0;
2047
2055
  for (let e of this.chunks) t.set(e, n), n += e.length;
2048
2056
  return t;
2049
2057
  }
2050
- }, bn = class {
2058
+ }, yn = class {
2051
2059
  data;
2052
2060
  offset = 0;
2053
2061
  decode(e) {
@@ -2056,22 +2064,22 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2056
2064
  _decode() {
2057
2065
  let e = this._readByte(), t = e >> 5 & 7, n = e & 31;
2058
2066
  switch (t) {
2059
- case P: return this._decodeUint(n);
2060
- case on: return -1 - this._decodeUint(n);
2061
- case sn: {
2067
+ case I: return this._decodeUint(n);
2068
+ case an: return -1 - this._decodeUint(n);
2069
+ case on: {
2062
2070
  let e = this._decodeUint(n);
2063
2071
  return this._readBytes(e);
2064
2072
  }
2065
- case F: {
2073
+ case L: {
2066
2074
  let e = this._decodeUint(n), t = this._readBytes(e);
2067
- return an.decode(t);
2075
+ return rn.decode(t);
2068
2076
  }
2069
- case cn: {
2077
+ case sn: {
2070
2078
  let e = this._decodeUint(n), t = [];
2071
2079
  for (let n = 0; n < e; n++) t.push(this._decode());
2072
2080
  return t;
2073
2081
  }
2074
- case ln: {
2082
+ case cn: {
2075
2083
  let e = this._decodeUint(n), t = {};
2076
2084
  for (let n = 0; n < e; n++) {
2077
2085
  let e = this._decode();
@@ -2079,11 +2087,11 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2079
2087
  }
2080
2088
  return t;
2081
2089
  }
2082
- case un:
2090
+ case ln:
2083
2091
  if (n === 20) return !1;
2084
2092
  if (n === 21) return !0;
2085
2093
  if (n === 22) return null;
2086
- if (n === vn) {
2094
+ if (n === _n) {
2087
2095
  let e = this._readBytes(8);
2088
2096
  return new DataView(e.buffer, e.byteOffset, 8).getFloat64(0, !1);
2089
2097
  }
@@ -2093,16 +2101,16 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2093
2101
  }
2094
2102
  _decodeUint(e) {
2095
2103
  if (e <= 23) return e;
2096
- if (e === mn) return this._readByte();
2097
- if (e === hn) {
2104
+ if (e === pn) return this._readByte();
2105
+ if (e === mn) {
2098
2106
  let e = this._readBytes(2);
2099
2107
  return new DataView(e.buffer, e.byteOffset, 2).getUint16(0, !1);
2100
2108
  }
2101
- if (e === gn) {
2109
+ if (e === hn) {
2102
2110
  let e = this._readBytes(4);
2103
2111
  return new DataView(e.buffer, e.byteOffset, 4).getUint32(0, !1);
2104
2112
  }
2105
- if (e === _n) {
2113
+ if (e === gn) {
2106
2114
  let e = this._readBytes(8);
2107
2115
  return Number(new DataView(e.buffer, e.byteOffset, 8).getBigUint64(0, !1));
2108
2116
  }
@@ -2118,16 +2126,16 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2118
2126
  return this.offset += e, t;
2119
2127
  }
2120
2128
  };
2121
- function xn(e) {
2122
- return new yn().encode(e);
2129
+ function bn(e) {
2130
+ return new vn().encode(e);
2123
2131
  }
2124
- function Sn(e) {
2125
- return new bn().decode(e);
2132
+ function xn(e) {
2133
+ return new yn().decode(e);
2126
2134
  }
2127
2135
  //#endregion
2128
2136
  //#region src/envelopeCbor.ts
2129
- var Cn = "application/7h3-cbor";
2130
- function wn(e) {
2137
+ var Sn = "application/7h3-cbor";
2138
+ function Cn(e) {
2131
2139
  let t = /* @__PURE__ */ new Map();
2132
2140
  t.set(1, e.header.version), t.set(2, e.header.messageId), t.set(3, e.header.timestampMs), t.set(4, e.header.ttlMs), t.set(5, e.header.sender), e.header.recipient !== void 0 && t.set(6, e.header.recipient), t.set(7, e.header.nonce);
2133
2141
  let n = /* @__PURE__ */ new Map();
@@ -2139,10 +2147,10 @@ function wn(e) {
2139
2147
  let e = /* @__PURE__ */ new Map();
2140
2148
  e.set(1, i.alg), e.set(2, i.keyId), e.set(3, i.value), r.set(3, e);
2141
2149
  }
2142
- return xn(r);
2150
+ return bn(r);
2143
2151
  }
2144
- function Tn(e) {
2145
- let t = Sn(e);
2152
+ function wn(e) {
2153
+ let t = xn(e);
2146
2154
  if (!t || typeof t != "object" || Array.isArray(t)) throw Error("decodeEnvelopeCbor: expected a map at top level");
2147
2155
  let n = t, r = n[1];
2148
2156
  if (!r || typeof r != "object" || Array.isArray(r)) throw Error("decodeEnvelopeCbor: missing header map (key 1)");
@@ -2177,11 +2185,11 @@ function Tn(e) {
2177
2185
  }
2178
2186
  //#endregion
2179
2187
  //#region src/httpBinding.ts
2180
- var En = "x-7h3-envelope";
2181
- async function Dn(e, t, n) {
2188
+ var Tn = "x-7h3-envelope";
2189
+ async function En(e, t, n) {
2182
2190
  let r = t.headerName ?? "x-7h3-envelope", i = (Array.isArray(e["content-type"]) ? e["content-type"][0] : e["content-type"]) ?? "", a;
2183
2191
  if (i.includes("7h3-cbor") && n instanceof Uint8Array) try {
2184
- a = Tn(n);
2192
+ a = wn(n);
2185
2193
  } catch (e) {
2186
2194
  return {
2187
2195
  ok: !1,
@@ -2211,7 +2219,7 @@ async function Dn(e, t, n) {
2211
2219
  detail: "missing required fields"
2212
2220
  };
2213
2221
  if (t.strictTtl ?? !0) {
2214
- let e = w(a).filter((e) => e.level === "error");
2222
+ let e = E(a).filter((e) => e.level === "error");
2215
2223
  if (e.length > 0) return {
2216
2224
  ok: !1,
2217
2225
  reason: "ttl-expired",
@@ -2226,7 +2234,7 @@ async function Dn(e, t, n) {
2226
2234
  reason: "unknown-sender",
2227
2235
  detail: o
2228
2236
  };
2229
- if (!await C(a, e)) return {
2237
+ if (!await T(a, e)) return {
2230
2238
  ok: !1,
2231
2239
  reason: "invalid-signature"
2232
2240
  };
@@ -2237,7 +2245,7 @@ async function Dn(e, t, n) {
2237
2245
  reason: "unknown-sender",
2238
2246
  detail: a.signature.keyId
2239
2247
  };
2240
- if (!await me(a, e)) return {
2248
+ if (!await C(a, e)) return {
2241
2249
  ok: !1,
2242
2250
  reason: "invalid-signature"
2243
2251
  };
@@ -2251,24 +2259,24 @@ async function Dn(e, t, n) {
2251
2259
  envelope: a
2252
2260
  };
2253
2261
  }
2254
- async function On(e, t, n) {
2255
- let r = await S(e, t);
2262
+ async function Dn(e, t, n) {
2263
+ let r = await w(e, t);
2256
2264
  if (n?.format === "cbor") {
2257
- let e = wn(r);
2265
+ let e = Cn(r);
2258
2266
  return {
2259
- headers: { "content-type": Cn },
2267
+ headers: { "content-type": Sn },
2260
2268
  body: e
2261
2269
  };
2262
2270
  }
2263
2271
  return { headers: { [n?.headerName ?? "x-7h3-envelope"]: JSON.stringify(r) } };
2264
2272
  }
2265
- async function kn(e, t, n, r) {
2266
- let i = await x(e, t, n);
2273
+ async function On(e, t, n, r) {
2274
+ let i = await S(e, t, n);
2267
2275
  return { headers: { [r?.headerName ?? "x-7h3-envelope"]: JSON.stringify(i) } };
2268
2276
  }
2269
- function An(e) {
2277
+ function kn(e) {
2270
2278
  return async function(t, n, r) {
2271
- let i = await Dn(t.headers, e);
2279
+ let i = await En(t.headers, e);
2272
2280
  if (!i.ok) {
2273
2281
  n.status(401).json({
2274
2282
  error: "7h3: request verification failed",
@@ -2280,13 +2288,13 @@ function An(e) {
2280
2288
  t["7h3Envelope"] = i.envelope, r();
2281
2289
  };
2282
2290
  }
2283
- async function jn(e, t, n, r) {
2284
- let { headers: i } = await On(t, n, r), a = new Headers(e.headers);
2291
+ async function An(e, t, n, r) {
2292
+ let { headers: i } = await Dn(t, n, r), a = new Headers(e.headers);
2285
2293
  for (let [e, t] of Object.entries(i)) a.set(e, t);
2286
2294
  return new Request(e, { headers: a });
2287
2295
  }
2288
- async function Mn(e, t) {
2289
- return jn(e, T({
2296
+ async function jn(e, t) {
2297
+ return An(e, D({
2290
2298
  sender: t.sender,
2291
2299
  recipient: t.recipient,
2292
2300
  ttlMs: t.ttlMs ?? 6e4,
@@ -2296,49 +2304,49 @@ async function Mn(e, t) {
2296
2304
  }
2297
2305
  //#endregion
2298
2306
  //#region src/webhookBinding.ts
2299
- var I = "x-7h3-sig", L = "x-7h3-ts", Nn = 3e5;
2300
- function R(e, t) {
2307
+ var R = "x-7h3-sig", z = "x-7h3-ts", Mn = 3e5;
2308
+ function B(e, t) {
2301
2309
  return `${e}.${t}`;
2302
2310
  }
2303
- async function Pn(e, t) {
2304
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await y(R(r, n), t.privateKey);
2311
+ async function Nn(e, t) {
2312
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await b(B(r, n), t.privateKey);
2305
2313
  return {
2306
- [I]: i,
2307
- [L]: String(r)
2314
+ [R]: i,
2315
+ [z]: String(r)
2308
2316
  };
2309
2317
  }
2310
- async function Fn(e, t) {
2311
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(R(r, n), t.secret);
2318
+ async function Pn(e, t) {
2319
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(B(r, n), t.secret);
2312
2320
  return {
2313
- [I]: i,
2314
- [L]: String(r)
2321
+ [R]: i,
2322
+ [z]: String(r)
2315
2323
  };
2316
2324
  }
2317
- async function In(e, t, n) {
2318
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2325
+ async function Fn(e, t, n) {
2326
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[R], a = t[z];
2319
2327
  if (!i || !a) return !1;
2320
2328
  let o = Number(a);
2321
2329
  if (!Number.isFinite(o)) return !1;
2322
2330
  let s = n.maxAgeMs ?? 3e5;
2323
- return Date.now() - o > s ? !1 : b(R(o, r), i, n.publicKey);
2331
+ return Date.now() - o > s ? !1 : x(B(o, r), i, n.publicKey);
2324
2332
  }
2325
- async function Ln(e, t, n) {
2326
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2333
+ async function In(e, t, n) {
2334
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[R], a = t[z];
2327
2335
  if (!i || !a) return !1;
2328
2336
  let o = Number(a);
2329
2337
  if (!Number.isFinite(o)) return !1;
2330
2338
  let s = n.maxAgeMs ?? 3e5;
2331
- return Date.now() - o > s ? !1 : fe(R(o, r), i, n.secret);
2339
+ return Date.now() - o > s ? !1 : fe(B(o, r), i, n.secret);
2332
2340
  }
2333
- async function Rn(e, t, n) {
2334
- if (!await In(e, t, n)) throw Error("7h3: webhook signature verification failed");
2341
+ async function Ln(e, t, n) {
2342
+ if (!await Fn(e, t, n)) throw Error("7h3: webhook signature verification failed");
2335
2343
  return JSON.parse(e);
2336
2344
  }
2337
2345
  //#endregion
2338
2346
  //#region src/queueBinding.ts
2339
- async function zn(e, t) {
2347
+ async function Rn(e, t) {
2340
2348
  let n = t.ttlMs ?? 36e5, r = typeof e == "string" ? e : JSON.stringify(e), i = {
2341
- envelope: await S(T({
2349
+ envelope: await w(D({
2342
2350
  sender: t.sender,
2343
2351
  recipient: t.recipient,
2344
2352
  intent: "TASK",
@@ -2349,7 +2357,7 @@ async function zn(e, t) {
2349
2357
  };
2350
2358
  return JSON.stringify(i);
2351
2359
  }
2352
- async function Bn(e, t) {
2360
+ async function zn(e, t) {
2353
2361
  let n;
2354
2362
  try {
2355
2363
  n = JSON.parse(e);
@@ -2357,16 +2365,16 @@ async function Bn(e, t) {
2357
2365
  throw Error("Queue message is not valid JSON");
2358
2366
  }
2359
2367
  if (!n.envelope || typeof n.envelope != "object") throw Error("Queue message missing envelope");
2360
- if (!await C(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2368
+ if (!await T(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2361
2369
  return {
2362
2370
  payload: n.payload,
2363
2371
  envelope: n.envelope
2364
2372
  };
2365
2373
  }
2366
- async function Vn(e, t) {
2374
+ async function Bn(e, t) {
2367
2375
  return Promise.all(e.map(async (e) => {
2368
2376
  try {
2369
- let { payload: n, envelope: r } = await Bn(e, t);
2377
+ let { payload: n, envelope: r } = await zn(e, t);
2370
2378
  return {
2371
2379
  ok: !0,
2372
2380
  payload: n,
@@ -2383,84 +2391,84 @@ async function Vn(e, t) {
2383
2391
  }
2384
2392
  //#endregion
2385
2393
  //#region src/stream.ts
2386
- var Hn = "x-7h3-stream", z = new TextEncoder();
2387
- function B() {
2394
+ var Vn = "x-7h3-stream", V = new TextEncoder();
2395
+ function H() {
2388
2396
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
2389
2397
  return crypto.subtle;
2390
2398
  }
2391
- function V(e) {
2399
+ function U(e) {
2392
2400
  let t = globalThis.Buffer;
2393
2401
  return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
2394
2402
  }
2395
- function H(e) {
2403
+ function W(e) {
2396
2404
  let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = globalThis.Buffer;
2397
2405
  if (n) return new Uint8Array(n.from(t, "base64"));
2398
2406
  let r = atob(t), i = new Uint8Array(r.length);
2399
2407
  for (let e = 0; e < r.length; e++) i[e] = r.charCodeAt(e);
2400
2408
  return i;
2401
2409
  }
2402
- function U(e) {
2410
+ function G(e) {
2403
2411
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
2404
2412
  }
2405
- function Un() {
2413
+ function Hn() {
2406
2414
  let e = new Uint8Array(16);
2407
- return crypto.getRandomValues(e), V(e);
2415
+ return crypto.getRandomValues(e), U(e);
2408
2416
  }
2409
- var W = /* @__PURE__ */ new Map(), Wn = 128;
2410
- function Gn(e, t) {
2411
- let n = `${e}:${t}`, r = W.get(n);
2417
+ var K = /* @__PURE__ */ new Map(), Un = 128;
2418
+ function Wn(e, t) {
2419
+ let n = `${e}:${t}`, r = K.get(n);
2412
2420
  if (r) return r;
2413
- W.size >= Wn && W.clear();
2414
- let i = B(), a = H(e), o = (async () => {
2415
- let e = await i.importKey("raw", U(a), "HKDF", !1, ["deriveBits"]), n = await i.deriveBits({
2421
+ K.size >= Un && K.clear();
2422
+ let i = H(), a = W(e), o = (async () => {
2423
+ let e = await i.importKey("raw", G(a), "HKDF", !1, ["deriveBits"]), n = await i.deriveBits({
2416
2424
  name: "HKDF",
2417
2425
  hash: "SHA-256",
2418
- salt: z.encode(t),
2419
- info: z.encode("7h3-stream/1")
2426
+ salt: V.encode(t),
2427
+ info: V.encode("7h3-stream/1")
2420
2428
  }, e, 256);
2421
2429
  return i.importKey("raw", n, {
2422
2430
  name: "HMAC",
2423
2431
  hash: "SHA-256"
2424
2432
  }, !1, ["sign"]);
2425
2433
  })();
2426
- return o.catch(() => W.delete(n)), W.set(n, o), o;
2434
+ return o.catch(() => K.delete(n)), K.set(n, o), o;
2427
2435
  }
2428
- var G = /* @__PURE__ */ new Map(), Kn = 64;
2429
- function qn(e) {
2430
- let t = G.get(e);
2436
+ var q = /* @__PURE__ */ new Map(), Gn = 64;
2437
+ function Kn(e) {
2438
+ let t = q.get(e);
2431
2439
  if (t) return t;
2432
- G.size >= Kn && G.clear();
2433
- let n = B().importKey("pkcs8", U(H(e)), { name: "Ed25519" }, !1, ["sign"]).catch((t) => {
2434
- throw G.delete(e), t;
2440
+ q.size >= Gn && q.clear();
2441
+ let n = H().importKey("pkcs8", G(W(e)), { name: "Ed25519" }, !1, ["sign"]).catch((t) => {
2442
+ throw q.delete(e), t;
2435
2443
  });
2436
- return G.set(e, n), n;
2444
+ return q.set(e, n), n;
2437
2445
  }
2438
- var K = /* @__PURE__ */ new Map(), Jn = 64;
2439
- function Yn(e) {
2440
- let t = K.get(e);
2446
+ var J = /* @__PURE__ */ new Map(), qn = 64;
2447
+ function Jn(e) {
2448
+ let t = J.get(e);
2441
2449
  if (t) return t;
2442
- K.size >= Jn && K.clear();
2443
- let n = B().importKey("spki", U(H(e)), { name: "Ed25519" }, !1, ["verify"]).catch((t) => {
2444
- throw K.delete(e), t;
2450
+ J.size >= qn && J.clear();
2451
+ let n = H().importKey("spki", G(W(e)), { name: "Ed25519" }, !1, ["verify"]).catch((t) => {
2452
+ throw J.delete(e), t;
2445
2453
  });
2446
- return K.set(e, n), n;
2454
+ return J.set(e, n), n;
2447
2455
  }
2448
- function Xn(e) {
2456
+ function Yn(e) {
2449
2457
  let t = e.map((e) => `${e.i}:${e.d}`);
2450
- return z.encode(t.join("\n"));
2458
+ return V.encode(t.join("\n"));
2451
2459
  }
2452
- async function Zn(e) {
2453
- let t = await B().digest("SHA-256", U(e));
2460
+ async function Xn(e) {
2461
+ let t = await H().digest("SHA-256", G(e));
2454
2462
  return new Uint8Array(t);
2455
2463
  }
2456
- var q = class {
2464
+ var Zn = class {
2457
2465
  opts;
2458
2466
  seq = 0;
2459
2467
  accum = [];
2460
2468
  hmacKeyPromise = null;
2461
2469
  constructor(e) {
2462
2470
  this.opts = {
2463
- nonce: e.nonce ?? Un(),
2471
+ nonce: e.nonce ?? Hn(),
2464
2472
  keyId: e.keyId ?? "stream-key",
2465
2473
  ...e
2466
2474
  };
@@ -2469,11 +2477,11 @@ var q = class {
2469
2477
  return this.opts.nonce;
2470
2478
  }
2471
2479
  getHmacKey() {
2472
- return this.hmacKeyPromise ||= Gn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2480
+ return this.hmacKeyPromise ||= Wn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2473
2481
  }
2474
2482
  async computeChunkHmac(e, t) {
2475
- let n = B(), r = await this.getHmacKey(), i = `${this.opts.nonce}:${e}:${t}`, a = await n.sign("HMAC", r, z.encode(i));
2476
- return V(new Uint8Array(a));
2483
+ let n = H(), r = await this.getHmacKey(), i = `${this.opts.nonce}:${e}:${t}`, a = await n.sign("HMAC", r, V.encode(i));
2484
+ return U(new Uint8Array(a));
2477
2485
  }
2478
2486
  async writeChunk(e) {
2479
2487
  let t = this.seq++, n = await this.computeChunkHmac(t, e);
@@ -2488,11 +2496,11 @@ var q = class {
2488
2496
  };
2489
2497
  }
2490
2498
  async finalize() {
2491
- let e = B(), t = await qn(this.opts.privateKey), n = await Zn(Xn(this.accum)), r = await e.sign("Ed25519", t, U(n)), i = V(new Uint8Array(r)), a = this.seq;
2499
+ let e = H(), t = await Kn(this.opts.privateKey), n = await Xn(Yn(this.accum)), r = await e.sign("Ed25519", t, G(n)), i = U(new Uint8Array(r)), a = this.seq;
2492
2500
  return {
2493
2501
  i: a,
2494
2502
  d: "",
2495
- h: await this.computeChunkHmac(a, V(n)),
2503
+ h: await this.computeChunkHmac(a, U(n)),
2496
2504
  f: !0,
2497
2505
  sig: i,
2498
2506
  kid: this.opts.keyId
@@ -2519,7 +2527,7 @@ var q = class {
2519
2527
  } : e.i === this.expectedSeq ? (this.expectedSeq++, this.accum.push({
2520
2528
  i: e.i,
2521
2529
  d: e.d
2522
- }), this.totalBytes += z.encode(e.d).length, { ok: !0 }) : {
2530
+ }), this.totalBytes += V.encode(e.d).length, { ok: !0 }) : {
2523
2531
  ok: !1,
2524
2532
  reason: `sequence error: expected ${this.expectedSeq}, got ${e.i}`
2525
2533
  };
@@ -2533,17 +2541,17 @@ var q = class {
2533
2541
  ok: !1,
2534
2542
  reason: "missing signature on final chunk"
2535
2543
  };
2536
- let t = B(), n;
2544
+ let t = H(), n;
2537
2545
  try {
2538
- n = await Yn(this.opts.publicKey);
2546
+ n = await Jn(this.opts.publicKey);
2539
2547
  } catch {
2540
2548
  return {
2541
2549
  ok: !1,
2542
2550
  reason: "invalid public key"
2543
2551
  };
2544
2552
  }
2545
- let r = await Zn(Xn(this.accum)), i = H(e.sig);
2546
- return await t.verify("Ed25519", n, U(i), U(r)) ? {
2553
+ let r = await Xn(Yn(this.accum)), i = W(e.sig);
2554
+ return await t.verify("Ed25519", n, G(i), G(r)) ? {
2547
2555
  ok: !0,
2548
2556
  totalBytes: this.totalBytes,
2549
2557
  chunkCount: this.accum.length
@@ -2554,13 +2562,13 @@ var q = class {
2554
2562
  }
2555
2563
  };
2556
2564
  function $n(e) {
2557
- return new q(e);
2565
+ return new Zn(e);
2558
2566
  }
2559
2567
  function er(e) {
2560
2568
  return new Qn(e);
2561
2569
  }
2562
2570
  async function tr(e, t) {
2563
- let n = new q(t), r = [];
2571
+ let n = new Zn(t), r = [];
2564
2572
  if (Array.isArray(e)) for (let t of e) r.push(await n.writeChunk(t));
2565
2573
  else for await (let t of e) r.push(await n.writeChunk(t));
2566
2574
  return r.push(await n.finalize()), r;
@@ -2646,11 +2654,11 @@ function ar(e, t) {
2646
2654
  a(/* @__PURE__ */ Error(`unknown sender: ${o}`), n);
2647
2655
  return;
2648
2656
  }
2649
- if (!await C(i, s).catch(() => !1)) {
2657
+ if (!await T(i, s).catch(() => !1)) {
2650
2658
  a(/* @__PURE__ */ Error("invalid signature"), n);
2651
2659
  return;
2652
2660
  }
2653
- let c = w(i);
2661
+ let c = E(i);
2654
2662
  if (c.some((e) => e.level === "error")) {
2655
2663
  a(/* @__PURE__ */ Error(`envelope invalid: ${c.map((e) => e.message).join("; ")}`), n);
2656
2664
  return;
@@ -2668,7 +2676,7 @@ function ar(e, t) {
2668
2676
  return n;
2669
2677
  },
2670
2678
  async send(r) {
2671
- let i = typeof r == "string" ? r : JSON.stringify(r), a = T({
2679
+ let i = typeof r == "string" ? r : JSON.stringify(r), a = D({
2672
2680
  sender: t.sender,
2673
2681
  recipient: t.recipient,
2674
2682
  ttlMs: t.ttlMs ?? 3e4,
@@ -2676,7 +2684,7 @@ function ar(e, t) {
2676
2684
  content: i
2677
2685
  });
2678
2686
  a.body.correlationId = String(++n);
2679
- let o = await S(a, t.privateKey);
2687
+ let o = await w(a, t.privateKey);
2680
2688
  e.send(JSON.stringify(o));
2681
2689
  },
2682
2690
  onMessage(e) {
@@ -2688,7 +2696,7 @@ function ar(e, t) {
2688
2696
  };
2689
2697
  }
2690
2698
  function or(e, t) {
2691
- let n = new q(t), r = async (t) => {
2699
+ let n = new Zn(t), r = async (t) => {
2692
2700
  let r = typeof t.data == "string" ? t.data : t.data.toString("utf8"), i = await n.writeChunk(r);
2693
2701
  e.send(rr(i));
2694
2702
  }, i = async () => {
@@ -2725,7 +2733,7 @@ function sr(e, t) {
2725
2733
  //#region src/grpcBinding.ts
2726
2734
  var cr = "7h3-envelope-bin";
2727
2735
  async function lr(e) {
2728
- let t = await S(T({
2736
+ let t = await w(D({
2729
2737
  sender: e.sender,
2730
2738
  recipient: e.recipient,
2731
2739
  ttlMs: e.ttlMs ?? 6e4,
@@ -2751,7 +2759,7 @@ async function ur(e, t) {
2751
2759
  message: "7h3: malformed envelope metadata"
2752
2760
  };
2753
2761
  }
2754
- if (t.strictTtl !== !1 && w(i).some((e) => e.level === "error")) return {
2762
+ if (t.strictTtl !== !1 && E(i).some((e) => e.level === "error")) return {
2755
2763
  ok: !1,
2756
2764
  code: 4,
2757
2765
  message: "7h3: envelope expired or invalid"
@@ -2769,7 +2777,7 @@ async function ur(e, t) {
2769
2777
  code: 16,
2770
2778
  message: `7h3: unknown sender ${a}`
2771
2779
  };
2772
- if (!await C(i, e)) return {
2780
+ if (!await T(i, e)) return {
2773
2781
  ok: !1,
2774
2782
  code: 16,
2775
2783
  message: "7h3: invalid signature"
@@ -2781,7 +2789,7 @@ async function ur(e, t) {
2781
2789
  code: 16,
2782
2790
  message: "7h3: unknown key"
2783
2791
  };
2784
- if (!await me(i, e)) return {
2792
+ if (!await C(i, e)) return {
2785
2793
  ok: !1,
2786
2794
  code: 16,
2787
2795
  message: "7h3: invalid signature"
@@ -2864,7 +2872,7 @@ var gr = class {
2864
2872
  if (t && e - t.createdAt < this.maxAgeMs - this.overlapMs) return null;
2865
2873
  t && !t.expiresAt && (t.expiresAt = e + this.overlapMs);
2866
2874
  let { publicKey: n, privateKey: r } = await pe(), i = {
2867
- id: `key-${e}-${Math.random().toString(36).slice(2, 8)}`,
2875
+ id: `key-${e}-${y(4)}`,
2868
2876
  publicKey: n,
2869
2877
  privateKey: r,
2870
2878
  createdAt: e
@@ -2953,7 +2961,7 @@ var gr = class {
2953
2961
  }, yr = new vr();
2954
2962
  //#endregion
2955
2963
  //#region src/routePolicy.ts
2956
- function J(e, t) {
2964
+ function br(e, t) {
2957
2965
  let n = "^", r = 0;
2958
2966
  for (; r < e.length;) {
2959
2967
  let t = e[r];
@@ -2961,18 +2969,18 @@ function J(e, t) {
2961
2969
  }
2962
2970
  return n += "$", new RegExp(n).test(t);
2963
2971
  }
2964
- function br(e, t) {
2965
- for (let n of e) if (J(n.path, t)) return n;
2972
+ function xr(e, t) {
2973
+ for (let n of e) if (br(n.path, t)) return n;
2966
2974
  return null;
2967
2975
  }
2968
- function xr(e, t) {
2976
+ function Sr(e, t) {
2969
2977
  return !e.allowedSenders || e.allowedSenders.length === 0 ? !0 : e.allowedSenders.includes(t);
2970
2978
  }
2971
2979
  //#endregion
2972
2980
  //#region src/signedResponse.ts
2973
- var Sr = "x-7h3-response";
2974
- async function Cr(e, t) {
2975
- let n = await S(T({
2981
+ var Cr = "x-7h3-response";
2982
+ async function wr(e, t) {
2983
+ let n = await w(D({
2976
2984
  sender: t.sender,
2977
2985
  recipient: t.recipient,
2978
2986
  intent: "RESULT",
@@ -2980,10 +2988,10 @@ async function Cr(e, t) {
2980
2988
  correlationId: t.correlationId,
2981
2989
  ttlMs: t.ttlMs ?? 6e4
2982
2990
  }), t.privateKey);
2983
- return { headers: { [Sr]: JSON.stringify(n) } };
2991
+ return { headers: { [Cr]: JSON.stringify(n) } };
2984
2992
  }
2985
- async function wr(e, t, n) {
2986
- let r = t[Sr], i = Array.isArray(r) ? r[0] : r;
2993
+ async function Tr(e, t, n) {
2994
+ let r = t[Cr], i = Array.isArray(r) ? r[0] : r;
2987
2995
  if (!i) return {
2988
2996
  ok: !1,
2989
2997
  reason: "missing-header"
@@ -3002,7 +3010,7 @@ async function wr(e, t, n) {
3002
3010
  ok: !1,
3003
3011
  reason: "ttl-expired",
3004
3012
  envelope: a
3005
- } : await C(a, n.publicKey) ? a.body.content === e ? {
3013
+ } : await T(a, n.publicKey) ? a.body.content === e ? {
3006
3014
  ok: !0,
3007
3015
  envelope: a
3008
3016
  } : {
@@ -3020,7 +3028,7 @@ async function wr(e, t, n) {
3020
3028
  function Y(e) {
3021
3029
  return !e || Object.keys(e).length === 0 ? "__default__" : Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}=${t}`).join(",");
3022
3030
  }
3023
- function Tr(e) {
3031
+ function Er(e) {
3024
3032
  return !e || Object.keys(e).length === 0 ? "" : `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}="${t}"`).join(",")}}`;
3025
3033
  }
3026
3034
  var X = class {
@@ -3041,7 +3049,7 @@ var X = class {
3041
3049
  });
3042
3050
  return e;
3043
3051
  }
3044
- }, Er = class {
3052
+ }, Dr = class {
3045
3053
  bucketBounds;
3046
3054
  states = /* @__PURE__ */ new Map();
3047
3055
  labelSets = /* @__PURE__ */ new Map();
@@ -3097,9 +3105,9 @@ var X = class {
3097
3105
  getBounds() {
3098
3106
  return [...this.bucketBounds];
3099
3107
  }
3100
- }, Dr = class {
3108
+ }, Or = class {
3101
3109
  verifications_total = new X();
3102
- verification_duration_ms = new Er([
3110
+ verification_duration_ms = new Dr([
3103
3111
  .1,
3104
3112
  .5,
3105
3113
  1,
@@ -3113,15 +3121,15 @@ var X = class {
3113
3121
  replay_detections_total = new X();
3114
3122
  audit_entries_total = new X();
3115
3123
  active_connections = new X();
3116
- }, Z = new Dr();
3117
- function Or(e, t = "7h3") {
3124
+ }, Z = new Or();
3125
+ function kr(e, t = "7h3") {
3118
3126
  let n = [];
3119
3127
  function r(e, r, i) {
3120
3128
  let a = `${t}_${e}`;
3121
3129
  n.push(`# HELP ${a} ${r}`), n.push(`# TYPE ${a} counter`);
3122
3130
  let o = i.entries();
3123
3131
  if (o.length === 0) n.push(`${a} 0`);
3124
- else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Tr(e)} ${t}`) : n.push(`${a} ${t}`);
3132
+ else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Er(e)} ${t}`) : n.push(`${a} ${t}`);
3125
3133
  }
3126
3134
  function i(e, r, i) {
3127
3135
  let a = `${t}_${e}`;
@@ -3131,7 +3139,7 @@ function Or(e, t = "7h3") {
3131
3139
  for (let e of i.getBounds()) n.push(`${a}_bucket{le="${e}"} 0`);
3132
3140
  n.push(`${a}_bucket{le="+Inf"} 0`), n.push(`${a}_sum 0`), n.push(`${a}_count 0`);
3133
3141
  } else for (let { labels: e, snapshot: t } of o) {
3134
- let r = e && Object.keys(e).length > 0 ? Tr(e) : "";
3142
+ let r = e && Object.keys(e).length > 0 ? Er(e) : "";
3135
3143
  for (let [e, i] of Object.entries(t.buckets)) {
3136
3144
  if (e === "+Inf") continue;
3137
3145
  let t = r ? r.slice(0, -1) + `,le="${e}"}` : `{le="${e}"}`;
@@ -3143,29 +3151,29 @@ function Or(e, t = "7h3") {
3143
3151
  }
3144
3152
  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";
3145
3153
  }
3146
- function kr(e = "/metrics", t = Z, n = "7h3") {
3154
+ function Ar(e = "/metrics", t = Z, n = "7h3") {
3147
3155
  return (r, i, a) => {
3148
3156
  if (r.url === e && (r.method === "GET" || r.method === void 0)) {
3149
- let e = Or(t, n);
3157
+ let e = kr(t, n);
3150
3158
  i.writeHead(200, { "content-type": "text/plain; version=0.0.4; charset=utf-8" }), i.end(e);
3151
3159
  } else a();
3152
3160
  };
3153
3161
  }
3154
3162
  //#endregion
3155
3163
  //#region src/capability.ts
3156
- var Ar = "x-7h3-capability";
3157
- function jr(e) {
3164
+ var jr = "x-7h3-capability";
3165
+ function Mr(e) {
3158
3166
  let t = [];
3159
3167
  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(",")}}`;
3160
3168
  }
3161
3169
  function Q(e) {
3162
3170
  let t = [];
3163
3171
  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)}`);
3164
- let n = `[${e.scopes.map(jr).join(",")}]`;
3172
+ let n = `[${e.scopes.map(Mr).join(",")}]`;
3165
3173
  return t.push(`"scopes":${n}`), t.push(`"subject":${JSON.stringify(e.subject)}`), t.push(`"version":${JSON.stringify(e.version)}`), `{${t.join(",")}}`;
3166
3174
  }
3167
- async function Mr(e) {
3168
- let t = Date.now(), n = `cap-${t}-${Math.random().toString(36).slice(2, 12)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3175
+ async function Nr(e) {
3176
+ let t = Date.now(), n = `cap-${t}-${y(6)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3169
3177
  id: n,
3170
3178
  version: "7h3-cap/1",
3171
3179
  issuer: e.issuerId,
@@ -3176,35 +3184,35 @@ async function Mr(e) {
3176
3184
  delegationDepth: 0,
3177
3185
  maxDelegations: i,
3178
3186
  keyId: r
3179
- }, o = await y(Q(a), e.issuerPrivateKey);
3187
+ }, o = await b(Q(a), e.issuerPrivateKey);
3180
3188
  return {
3181
3189
  ...a,
3182
3190
  signature: o
3183
3191
  };
3184
3192
  }
3185
- function Nr(e, t) {
3186
- if (!J(t.pathGlob, e.pathGlob)) return !1;
3193
+ function Pr(e, t) {
3194
+ if (!br(t.pathGlob, e.pathGlob)) return !1;
3187
3195
  if (t.methods !== void 0) {
3188
3196
  if (e.methods === void 0) return !1;
3189
3197
  for (let n of e.methods) if (!t.methods.includes(n)) return !1;
3190
3198
  }
3191
3199
  return !0;
3192
3200
  }
3193
- function Pr(e, t) {
3194
- for (let n of e) if (!t.some((e) => Nr(n, e))) return !1;
3201
+ function Fr(e, t) {
3202
+ for (let n of e) if (!t.some((e) => Pr(n, e))) return !1;
3195
3203
  return !0;
3196
3204
  }
3197
- async function Fr(e) {
3205
+ async function Ir(e) {
3198
3206
  let { parentToken: t, delegatorId: n, newSubject: r } = e;
3199
3207
  if (n !== t.subject) throw Error(`delegatorId '${n}' does not match parentToken.subject '${t.subject}'`);
3200
3208
  let i = Date.now();
3201
3209
  if (i >= t.expiresAt) throw Error("Parent token is expired");
3202
3210
  if (t.maxDelegations !== void 0 && t.maxDelegations <= 0) throw Error("Parent token does not allow further delegation (maxDelegations=0)");
3203
3211
  let a = e.scopes ?? t.scopes;
3204
- if (!Pr(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3212
+ if (!Fr(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3205
3213
  let o = t.expiresAt - i;
3206
3214
  if (e.ttlMs > o) throw Error(`Delegated ttlMs (${e.ttlMs}) exceeds parent token remaining TTL (${o})`);
3207
- let s = `cap-${i}-${Math.random().toString(36).slice(2, 12)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3215
+ let s = `cap-${i}-${y(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3208
3216
  id: s,
3209
3217
  version: "7h3-cap/1",
3210
3218
  issuer: n,
@@ -3216,18 +3224,18 @@ async function Fr(e) {
3216
3224
  parentTokenId: t.id,
3217
3225
  maxDelegations: l,
3218
3226
  keyId: c
3219
- }, d = await y(Q(u), e.delegatorPrivateKey);
3227
+ }, d = await b(Q(u), e.delegatorPrivateKey);
3220
3228
  return {
3221
3229
  ...u,
3222
3230
  signature: d
3223
3231
  };
3224
3232
  }
3225
- async function Ir(e, t, n) {
3233
+ async function Lr(e, t, n) {
3226
3234
  if ((n?.now ?? Date.now()) >= e.expiresAt) return !1;
3227
3235
  let { signature: r, ...i } = e;
3228
- return b(Q(i), r, t);
3236
+ return x(Q(i), r, t);
3229
3237
  }
3230
- async function Lr(e, t, n) {
3238
+ async function Rr(e, t, n) {
3231
3239
  if (e.length === 0) return {
3232
3240
  ok: !1,
3233
3241
  reason: "empty-chain"
@@ -3264,13 +3272,13 @@ async function Lr(e, t, n) {
3264
3272
  reason: `no-public-key-for-issuer:${i.issuer}`
3265
3273
  };
3266
3274
  let { signature: o, ...s } = i;
3267
- if (!await b(Q(s), o, a)) return {
3275
+ if (!await x(Q(s), o, a)) return {
3268
3276
  ok: !1,
3269
3277
  reason: `invalid-signature-at-index:${n}`
3270
3278
  };
3271
3279
  }
3272
3280
  let i = e[e.length - 1];
3273
- return n?.requiredPathGlob !== void 0 && !Rr(i, n.requiredPathGlob, n.requiredMethod) ? {
3281
+ return n?.requiredPathGlob !== void 0 && !zr(i, n.requiredPathGlob, n.requiredMethod) ? {
3274
3282
  ok: !1,
3275
3283
  reason: "leaf-token-does-not-cover-required-scope"
3276
3284
  } : {
@@ -3279,26 +3287,26 @@ async function Lr(e, t, n) {
3279
3287
  chain: e
3280
3288
  };
3281
3289
  }
3282
- function Rr(e, t, n) {
3283
- 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;
3290
+ function zr(e, t, n) {
3291
+ for (let r of e.scopes) if (br(r.pathGlob, t) && (r.methods === void 0 || n === void 0 || r.methods.includes(n.toUpperCase()))) return !0;
3284
3292
  return !1;
3285
3293
  }
3286
- function zr(e) {
3294
+ function Br(e) {
3287
3295
  return JSON.stringify(e);
3288
3296
  }
3289
- function Br(e) {
3297
+ function Vr(e) {
3290
3298
  return JSON.parse(e);
3291
3299
  }
3292
3300
  //#endregion
3293
3301
  //#region src/gateway.ts
3294
- var Vr = class {
3302
+ var Hr = class {
3295
3303
  config;
3296
3304
  rateLimiter;
3297
3305
  constructor(e) {
3298
3306
  this.config = e, this.rateLimiter = new vr();
3299
3307
  }
3300
3308
  async verify(e) {
3301
- let t = performance.now(), n = br(this.config.policies ?? [], e.path);
3309
+ let t = performance.now(), n = xr(this.config.policies ?? [], e.path);
3302
3310
  if (n?.require === "none" || !n && (this.config.defaultPolicy ?? "allow") === "allow") {
3303
3311
  let e = performance.now() - t;
3304
3312
  return Z.verifications_total.increment({
@@ -3311,13 +3319,13 @@ var Vr = class {
3311
3319
  };
3312
3320
  }
3313
3321
  if (this.config.capabilityRegistry) {
3314
- let n = e.headers[Ar], r = Array.isArray(n) ? n[0] : n;
3322
+ let n = e.headers[jr], r = Array.isArray(n) ? n[0] : n;
3315
3323
  if (r) try {
3316
- let n = await Lr(Br(r), this.config.capabilityRegistry, {
3324
+ let n = await Rr(Vr(r), this.config.capabilityRegistry, {
3317
3325
  requiredPathGlob: e.path,
3318
3326
  requiredMethod: e.method
3319
3327
  });
3320
- if (n.ok && Rr(n.token, e.path, e.method)) {
3328
+ if (n.ok && zr(n.token, e.path, e.method)) {
3321
3329
  let e = performance.now() - t;
3322
3330
  return Z.verifications_total.increment({
3323
3331
  result: "ok",
@@ -3366,7 +3374,7 @@ var Vr = class {
3366
3374
  reason: "no-matching-policy"
3367
3375
  };
3368
3376
  }
3369
- let r = await Dn(e.headers, {
3377
+ let r = await En(e.headers, {
3370
3378
  keyRegistry: this.config.keyRegistry,
3371
3379
  headerName: this.config.headerName
3372
3380
  });
@@ -3403,7 +3411,7 @@ var Vr = class {
3403
3411
  };
3404
3412
  }
3405
3413
  }
3406
- if (n && !xr(n, a)) {
3414
+ if (n && !Sr(n, a)) {
3407
3415
  let n = performance.now() - t;
3408
3416
  return Z.verifications_total.increment({
3409
3417
  result: "fail",
@@ -3460,7 +3468,7 @@ var Vr = class {
3460
3468
  body: e.body
3461
3469
  }), a = await i.text(), o = { "content-type": i.headers.get("content-type") ?? "application/json" };
3462
3470
  if (this.config.privateKey !== void 0 && (this.config.signResponses ?? !0) && this.config.sender !== void 0) {
3463
- let e = await Cr(a, {
3471
+ let e = await wr(a, {
3464
3472
  privateKey: this.config.privateKey,
3465
3473
  sender: this.config.sender,
3466
3474
  recipient: t.sender || void 0
@@ -3477,12 +3485,12 @@ var Vr = class {
3477
3485
  return this.rateLimiter;
3478
3486
  }
3479
3487
  };
3480
- function Hr(e) {
3481
- return new Vr(e);
3488
+ function Ur(e) {
3489
+ return new Hr(e);
3482
3490
  }
3483
3491
  //#endregion
3484
3492
  //#region src/auditLog.ts
3485
- function Ur(e) {
3493
+ function Wr(e) {
3486
3494
  let t = [
3487
3495
  `"id":${JSON.stringify(e.id)}`,
3488
3496
  `"timestampMs":${e.timestampMs}`,
@@ -3490,7 +3498,7 @@ function Ur(e) {
3490
3498
  ];
3491
3499
  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(",")}}`;
3492
3500
  }
3493
- var Wr = class {
3501
+ var Gr = class {
3494
3502
  entries = [];
3495
3503
  privateKey;
3496
3504
  maxEntries;
@@ -3499,10 +3507,10 @@ var Wr = class {
3499
3507
  }
3500
3508
  async log(e) {
3501
3509
  let t = {
3502
- id: `audit-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
3510
+ id: `audit-${Date.now()}-${y(5)}`,
3503
3511
  timestampMs: Date.now(),
3504
3512
  ...e
3505
- }, n = await y(Ur(t), this.privateKey), r = {
3513
+ }, n = await b(Wr(t), this.privateKey), r = {
3506
3514
  ...t,
3507
3515
  entrySignature: n
3508
3516
  };
@@ -3513,7 +3521,7 @@ var Wr = class {
3513
3521
  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;
3514
3522
  }
3515
3523
  async verify(e, t) {
3516
- return b(Ur({
3524
+ return x(Wr({
3517
3525
  id: e.id,
3518
3526
  timestampMs: e.timestampMs,
3519
3527
  type: e.type,
@@ -3529,7 +3537,7 @@ var Wr = class {
3529
3537
  size() {
3530
3538
  return this.entries.length;
3531
3539
  }
3532
- }, Gr = class {
3540
+ }, Kr = class {
3533
3541
  async log(e) {}
3534
3542
  async query(e) {
3535
3543
  return [];
@@ -3541,25 +3549,25 @@ var Wr = class {
3541
3549
  return 0;
3542
3550
  }
3543
3551
  };
3544
- function Kr(e, t) {
3545
- return new Wr(e, t?.maxEntries);
3552
+ function qr(e, t) {
3553
+ return new Gr(e, t?.maxEntries);
3546
3554
  }
3547
3555
  //#endregion
3548
3556
  //#region src/otel.ts
3549
- var qr = null;
3550
- function Jr(e) {
3551
- qr = e;
3557
+ var Jr = null;
3558
+ function Yr(e) {
3559
+ Jr = e;
3552
3560
  }
3553
- function Yr() {
3554
- if (qr === null) return null;
3561
+ function Xr() {
3562
+ if (Jr === null) return null;
3555
3563
  try {
3556
- return qr.getTracer("7h3/protocol");
3564
+ return Jr.getTracer("7h3/protocol");
3557
3565
  } catch {
3558
3566
  return null;
3559
3567
  }
3560
3568
  }
3561
- async function Xr(e, t) {
3562
- let n = Yr();
3569
+ async function Zr(e, t) {
3570
+ let n = Xr();
3563
3571
  if (n === null) return e(null);
3564
3572
  let r = n.startSpan("7h3.verify", t);
3565
3573
  try {
@@ -3570,8 +3578,8 @@ async function Xr(e, t) {
3570
3578
  r.end();
3571
3579
  }
3572
3580
  }
3573
- async function Zr(e) {
3574
- let t = Yr();
3581
+ async function Qr(e) {
3582
+ let t = Xr();
3575
3583
  if (t === null) return e(null);
3576
3584
  let n = t.startSpan("7h3.audit.write");
3577
3585
  try {
@@ -3584,64 +3592,64 @@ async function Zr(e) {
3584
3592
  }
3585
3593
  //#endregion
3586
3594
  //#region src/encryption.ts
3587
- function Qr(e) {
3595
+ function $r(e) {
3588
3596
  return Buffer.from(e).toString("base64url");
3589
3597
  }
3590
3598
  function $(e) {
3591
3599
  return Buffer.from(e, "base64url");
3592
3600
  }
3593
- var $r = Buffer.from("302e020100300506032b656e04220420", "hex"), ei = Buffer.from("302a300506032b656e032100", "hex");
3594
- function ti(e) {
3601
+ var ei = Buffer.from("302e020100300506032b656e04220420", "hex"), ti = Buffer.from("302a300506032b656e032100", "hex");
3602
+ function ni(e) {
3595
3603
  let t = $(e);
3596
- return (0, M.createPrivateKey)({
3597
- key: Buffer.concat([$r, t]),
3604
+ return (0, P.createPrivateKey)({
3605
+ key: Buffer.concat([ei, t]),
3598
3606
  format: "der",
3599
3607
  type: "pkcs8"
3600
3608
  });
3601
3609
  }
3602
- function ni(e) {
3610
+ function ri(e) {
3603
3611
  let t = $(e);
3604
- return (0, M.createPublicKey)({
3605
- key: Buffer.concat([ei, t]),
3612
+ return (0, P.createPublicKey)({
3613
+ key: Buffer.concat([ti, t]),
3606
3614
  format: "der",
3607
3615
  type: "spki"
3608
3616
  });
3609
3617
  }
3610
- function ri() {
3611
- let { privateKey: e, publicKey: t } = (0, M.generateKeyPairSync)("x25519"), n = e.export({ format: "jwk" });
3618
+ function ii() {
3619
+ let { privateKey: e, publicKey: t } = (0, P.generateKeyPairSync)("x25519"), n = e.export({ format: "jwk" });
3612
3620
  return {
3613
3621
  publicKey: t.export({ format: "jwk" }).x,
3614
3622
  privateKey: n.d
3615
3623
  };
3616
3624
  }
3617
- function ii(e, t, n) {
3618
- let r = (0, M.hkdfSync)("sha256", (0, M.diffieHellman)({
3619
- privateKey: ti(e),
3620
- publicKey: ni(t)
3625
+ function ai(e, t, n) {
3626
+ let r = (0, P.hkdfSync)("sha256", (0, P.diffieHellman)({
3627
+ privateKey: ni(e),
3628
+ publicKey: ri(t)
3621
3629
  }), $(n), Buffer.from("7h3-enc/1", "utf8"), 32);
3622
3630
  return Buffer.from(r);
3623
3631
  }
3624
- function ai(e, t) {
3625
- let n = ri(), r = (0, M.randomBytes)(12), i = Qr(r), a = ii(n.privateKey, t, i), o = Buffer.from(JSON.stringify(e), "utf8"), s = (0, M.createCipheriv)("chacha20-poly1305", a, r, { authTagLength: 16 }), c = Buffer.concat([s.update(o), s.final()]), l = s.getAuthTag(), u = {
3632
+ function oi(e, t) {
3633
+ let n = ii(), r = (0, P.randomBytes)(12), i = $r(r), a = ai(n.privateKey, t, i), o = Buffer.from(JSON.stringify(e), "utf8"), s = (0, P.createCipheriv)("chacha20-poly1305", a, r, { authTagLength: 16 }), c = Buffer.concat([s.update(o), s.final()]), l = s.getAuthTag(), u = {
3626
3634
  ephemeralPublic: n.publicKey,
3627
3635
  nonce: i,
3628
- ciphertext: Qr(c),
3629
- tag: Qr(l)
3636
+ ciphertext: $r(c),
3637
+ tag: $r(l)
3630
3638
  };
3631
3639
  return {
3632
- encryptedContent: Qr(Buffer.from(JSON.stringify(u), "utf8")),
3640
+ encryptedContent: $r(Buffer.from(JSON.stringify(u), "utf8")),
3633
3641
  ephemeralPublic: n.publicKey
3634
3642
  };
3635
3643
  }
3636
- function oi(e, t) {
3637
- let n = $(e).toString("utf8"), { ephemeralPublic: r, nonce: i, ciphertext: a, tag: o } = JSON.parse(n), s = ii(t, r, i), c = $(i), l = $(a), u = $(o), d = (0, M.createDecipheriv)("chacha20-poly1305", s, c, { authTagLength: 16 });
3644
+ function si(e, t) {
3645
+ let n = $(e).toString("utf8"), { ephemeralPublic: r, nonce: i, ciphertext: a, tag: o } = JSON.parse(n), s = ai(t, r, i), c = $(i), l = $(a), u = $(o), d = (0, P.createDecipheriv)("chacha20-poly1305", s, c, { authTagLength: 16 });
3638
3646
  d.setAuthTag(u);
3639
3647
  let f = Buffer.concat([d.update(l), d.final()]);
3640
3648
  return JSON.parse(f.toString("utf8"));
3641
3649
  }
3642
- async function si(e, t) {
3643
- let { encryptedContent: n } = ai(e.body, t.recipientX25519PublicKey);
3644
- return S({
3650
+ async function ci(e, t) {
3651
+ let { encryptedContent: n } = oi(e.body, t.recipientX25519PublicKey);
3652
+ return w({
3645
3653
  header: e.header,
3646
3654
  body: {
3647
3655
  intent: "ENCRYPTED",
@@ -3651,12 +3659,12 @@ async function si(e, t) {
3651
3659
  }
3652
3660
  }, t.senderEd25519PrivateKey);
3653
3661
  }
3654
- async function ci(e, t) {
3655
- if (!await C(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3662
+ async function li(e, t) {
3663
+ if (!await T(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3656
3664
  return {
3657
3665
  envelope: e,
3658
- body: oi(e.body.content, t.recipientX25519PrivateKey)
3666
+ body: si(e.body.content, t.recipientX25519PrivateKey)
3659
3667
  };
3660
3668
  }
3661
3669
  //#endregion
3662
- export { at as AgentSession, ot as AipAgentAdapter, Ar as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Lt as ClusterRedisReplayStore, En as DEFAULT_HEADER, be as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Le as DistributedReplayCache, cr as GRPC_METADATA_KEY, Wr as InMemoryAuditLog, Ft as InMemoryRedisLikeClient, O as InMemoryReplayCache, Ht as InMemoryRevocationStore, Re as InMemoryVerificationMaterialCache, gr as KeyRotationManager, Gr as NoopAuditLog, Vr as Protocol7h3Gateway, Dr as Protocol7h3Metrics, Sr as RESPONSE_HEADER, It as RedisReplayStore, _r as RevocationRegistry, rt as RollingKeyring, jt as RuntimePolicyManager, Hn as STREAM_HEADER, Ye as SessionTransport, Qn as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Er as SimpleHistogram, vr as SlidingWindowRateLimiter, Nn as WEBHOOK_DEFAULT_TTL_MS, I as WEBHOOK_SIG_HEADER, L as WEBHOOK_TS_HEADER, A as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, Rn as consumeWebhook, st as createAipAgentAdapter, $e as createAipCapabilities, kt as createAipMcpGatewayRuntime, At as createAipMcpGatewayRuntimeWithPolicy, Kr as createAuditLog, rn as createCachingKeyRegistry, Bt as createClusterReplayStore, nn as createCompositeKeyRegistry, T as createEnvelope, Hr as createGateway, hr as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, An as createHttpMiddleware, it as createKeyringSignatureResolver, Jt as createMcpClientCodec, kr as createMetricsMiddleware, Ct as createPolicyEnforcer, pt as createRawTaskFromJsonRpc, ct as createRawTaskFromLangChain, ut as createRawTaskFromLlamaIndex, Rt as createRedisReplayStore, Ut as createRedisRevocationStore, Mn as createSignedFetchRequest, Xe as createSignedMessage, $n as createSignedStream, or as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, er as createStreamVerifier, Sn as decodeCbor, We as decodeEnvelope, qe as decodeEnvelopeBatch, Fe as decodeEnvelopeBinary, Tn as decodeEnvelopeCbor, ir as decodeStreamChunk, oi as decryptBody, Fr as delegateCapabilityToken, ii as deriveEncryptionKey, et as encodeAipCapabilities, xn as encodeCbor, Ge as encodeEnvelope, Ke as encodeEnvelopeBatch, Pe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, rr as encodeStreamChunk, ai as encryptBody, mr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, ri as generateX25519KeyPair, Yr as getOtelTracer, Nt as getRuntimeTuningPreset, yr as globalRateLimiter, xr as isAllowedSender, wt as isRuntimeMode, Mr as issueCapabilityToken, bt as loadRuntimePolicy, J as matchGlob, br as matchPolicy, Z as metrics, nt as negotiateAipCapabilities, ci as openEnvelope, tt as parseAipCapabilities, Br as parseCapabilityChain, vt as parseRuntimePolicyJson, pr as parseWellKnownKeys, k as receiveEnvelope, Je as receiveEnvelopeBatch, sr as receiveSignedWebSocketStream, Pt as recommendPolicyAdjustments, Or as renderPrometheusText, si as sealEnvelope, zr as serializeCapabilityChain, Zt as serveMcpOverStdio, fr as serveWellKnownKeys, Jr as setOtelProvider, y as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, S as signEnvelopeEd25519, x as signEnvelopeHmac, jn as signFetchRequest, lr as signGrpcCall, On as signHttpRequest, kn as signHttpRequestHmac, zn as signQueueMessage, Cr as signResponse, tr as signStream, Pn as signWebhook, Fn as signWebhookHmac, mt as toJsonRpcResponse, lt as toLangChainMessage, dt as toLlamaIndexMessage, Rr as tokenMatchesScope, w as validateEnvelope, _t as validateRuntimePolicy, b as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, ge as verifyCanonicalPayloadSignature, Lr as verifyCapabilityChain, Ir as verifyCapabilityToken, C as verifyEnvelopeEd25519, me as verifyEnvelopeHmac, he as verifyEnvelopeSignature, ur as verifyGrpcCall, Dn as verifyHttpEnvelope, Vn as verifyQueueBatch, Bn as verifyQueueMessage, wr as verifyResponse, nr as verifyStream, In as verifyWebhook, Ln as verifyWebhookHmac, Zr as withAuditSpan, dr as withGrpcVerification, Wt as withRevocationCheck, Xr as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, ar as wrapWebSocket };
3670
+ export { rt as AgentSession, it as AipAgentAdapter, jr as CAP_HEADER, Sn as CBOR_CONTENT_TYPE, yn as CborDecoder, vn as CborEncoder, It as ClusterRedisReplayStore, Tn as DEFAULT_HEADER, ye as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Ie as DistributedReplayCache, cr as GRPC_METADATA_KEY, Gr as InMemoryAuditLog, Pt as InMemoryRedisLikeClient, A as InMemoryReplayCache, Vt as InMemoryRevocationStore, Le as InMemoryVerificationMaterialCache, gr as KeyRotationManager, Kr as NoopAuditLog, Hr as Protocol7h3Gateway, Or as Protocol7h3Metrics, Cr as RESPONSE_HEADER, Ft as RedisReplayStore, _r as RevocationRegistry, tt as RollingKeyring, At as RuntimePolicyManager, Vn as STREAM_HEADER, qe as SessionTransport, Qn as SignedStreamReader, Zn as SignedStreamWriter, X as SimpleCounter, Dr as SimpleHistogram, vr as SlidingWindowRateLimiter, Mn as WEBHOOK_DEFAULT_TTL_MS, R as WEBHOOK_SIG_HEADER, z as WEBHOOK_TS_HEADER, N as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, Ln as consumeWebhook, at as createAipAgentAdapter, Ze as createAipCapabilities, Ot as createAipMcpGatewayRuntime, kt as createAipMcpGatewayRuntimeWithPolicy, qr as createAuditLog, nn as createCachingKeyRegistry, zt as createClusterReplayStore, tn as createCompositeKeyRegistry, D as createEnvelope, Ur as createGateway, hr as createHttpKeyRegistry, $t as createHttpMcpClient, Qt as createHttpMcpHandler, kn as createHttpMiddleware, nt as createKeyringSignatureResolver, qt as createMcpClientCodec, Ar as createMetricsMiddleware, xt as createPolicyEnforcer, dt as createRawTaskFromJsonRpc, ot as createRawTaskFromLangChain, ct as createRawTaskFromLlamaIndex, Lt as createRedisReplayStore, Ht as createRedisRevocationStore, jn as createSignedFetchRequest, Je as createSignedMessage, $n as createSignedStream, or as createSignedWebSocketStream, en as createStaticKeyRegistry, Zt as createStdioMcpClient, er as createStreamVerifier, xn as decodeCbor, Ue as decodeEnvelope, Ge as decodeEnvelopeBatch, Pe as decodeEnvelopeBinary, wn as decodeEnvelopeCbor, ir as decodeStreamChunk, si as decryptBody, Ir as delegateCapabilityToken, ai as deriveEncryptionKey, Qe as encodeAipCapabilities, bn as encodeCbor, j as encodeEnvelope, We as encodeEnvelopeBatch, Ne as encodeEnvelopeBinary, Cn as encodeEnvelopeCbor, rr as encodeStreamChunk, oi as encryptBody, mr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, ii as generateX25519KeyPair, Xr as getOtelTracer, Mt as getRuntimeTuningPreset, yr as globalRateLimiter, Sr as isAllowedSender, St as isRuntimeMode, Nr as issueCapabilityToken, vt as loadRuntimePolicy, br as matchGlob, xr as matchPolicy, Z as metrics, et as negotiateAipCapabilities, li as openEnvelope, $e as parseAipCapabilities, Vr as parseCapabilityChain, gt as parseRuntimePolicyJson, pr as parseWellKnownKeys, y as randomHex, M as receiveEnvelope, Ke as receiveEnvelopeBatch, sr as receiveSignedWebSocketStream, Nt as recommendPolicyAdjustments, kr as renderPrometheusText, ci as sealEnvelope, Br as serializeCapabilityChain, Xt as serveMcpOverStdio, fr as serveWellKnownKeys, Yr as setOtelProvider, b as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, w as signEnvelopeEd25519, S as signEnvelopeHmac, An as signFetchRequest, lr as signGrpcCall, Dn as signHttpRequest, On as signHttpRequestHmac, Rn as signQueueMessage, wr as signResponse, tr as signStream, Nn as signWebhook, Pn as signWebhookHmac, ft as toJsonRpcResponse, st as toLangChainMessage, lt as toLlamaIndexMessage, zr as tokenMatchesScope, E as validateEnvelope, ht as validateRuntimePolicy, x as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, he as verifyCanonicalPayloadSignature, Rr as verifyCapabilityChain, Lr as verifyCapabilityToken, T as verifyEnvelopeEd25519, C as verifyEnvelopeHmac, me as verifyEnvelopeSignature, ur as verifyGrpcCall, En as verifyHttpEnvelope, Bn as verifyQueueBatch, zn as verifyQueueMessage, Tr as verifyResponse, nr as verifyStream, Fn as verifyWebhook, In as verifyWebhookHmac, Qr as withAuditSpan, dr as withGrpcVerification, Ut as withRevocationCheck, Zr as withVerificationSpan, Jt as wrapMcpClient, Kt as wrapMcpServer, ar as wrapWebSocket };