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