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