@7h3/protocol 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/bin/7h3.js +663 -0
- package/gateway.d.ts +17 -1
- package/index.js +338 -330
- package/keyRegistry.d.ts +1 -1
- package/package.json +88 -6
- package/protocol.d.ts +1 -0
- package/queueBinding.d.ts +12 -0
- package/rateLimiter.d.ts +11 -0
package/index.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
enumerable: !(s = n(i, d)) || s.enumerable
|
|
6
|
-
});
|
|
7
|
-
return e;
|
|
8
|
-
}, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
|
|
9
|
-
value: n,
|
|
10
|
-
enumerable: !0
|
|
11
|
-
}) : a, n)), l = new TextEncoder(), u = 256, d = /* @__PURE__ */ new Map(), f = 256, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
|
|
1
|
+
import e from "node:readline";
|
|
2
|
+
import { createCipheriv as t, createDecipheriv as n, createPrivateKey as r, createPublicKey as i, diffieHellman as a, generateKeyPairSync as o, hkdfSync as s, randomBytes as c } from "node:crypto";
|
|
3
|
+
//#region src/protocol.ts
|
|
4
|
+
var l = new TextEncoder(), u = 256, d = /* @__PURE__ */ new Map(), f = 256, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
|
|
12
5
|
function ee() {
|
|
13
6
|
return globalThis.Buffer ?? null;
|
|
14
7
|
}
|
|
@@ -24,7 +17,7 @@ function re(e) {
|
|
|
24
17
|
let t = `hs256:${e}`, n = d.get(t);
|
|
25
18
|
if (n) return n;
|
|
26
19
|
d.size >= u && d.clear();
|
|
27
|
-
let r =
|
|
20
|
+
let r = v().importKey("raw", l.encode(e), {
|
|
28
21
|
name: "HMAC",
|
|
29
22
|
hash: "SHA-256"
|
|
30
23
|
}, !1, ["sign", "verify"]).catch((e) => {
|
|
@@ -36,7 +29,7 @@ function ie(e) {
|
|
|
36
29
|
let t = `ed25519:pkcs8:${e}`, n = p.get(t);
|
|
37
30
|
if (n) return n;
|
|
38
31
|
p.size >= f && p.clear();
|
|
39
|
-
let r =
|
|
32
|
+
let r = v().importKey("pkcs8", oe(g(e)), { name: "Ed25519" }, !1, ["sign"]).catch((e) => {
|
|
40
33
|
throw p.delete(t), e;
|
|
41
34
|
});
|
|
42
35
|
return p.set(t, r), r;
|
|
@@ -45,33 +38,33 @@ function ae(e) {
|
|
|
45
38
|
let t = `ed25519:spki:${e}`, n = m.get(t);
|
|
46
39
|
if (n) return n;
|
|
47
40
|
m.size >= f && m.clear();
|
|
48
|
-
let r =
|
|
41
|
+
let r = v().importKey("spki", oe(g(e)), { name: "Ed25519" }, !1, ["verify"]).catch((e) => {
|
|
49
42
|
throw m.delete(t), e;
|
|
50
43
|
});
|
|
51
44
|
return m.set(t, r), r;
|
|
52
45
|
}
|
|
53
|
-
function
|
|
46
|
+
function h(e) {
|
|
54
47
|
let t = ee();
|
|
55
48
|
return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
56
49
|
}
|
|
57
|
-
function
|
|
50
|
+
function g(e) {
|
|
58
51
|
let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = ee();
|
|
59
52
|
if (n) return new Uint8Array(n.from(t, "base64"));
|
|
60
53
|
let r = atob(t), i = new Uint8Array(r.length);
|
|
61
54
|
for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
|
|
62
55
|
return i;
|
|
63
56
|
}
|
|
64
|
-
function
|
|
57
|
+
function oe(e) {
|
|
65
58
|
return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
66
59
|
}
|
|
67
|
-
function
|
|
60
|
+
function _(e) {
|
|
68
61
|
return `{"body":${ne(e.body)},"header":${te(e.header)}}`;
|
|
69
62
|
}
|
|
70
|
-
function
|
|
63
|
+
function v() {
|
|
71
64
|
if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
|
|
72
65
|
return crypto.subtle;
|
|
73
66
|
}
|
|
74
|
-
function
|
|
67
|
+
function y(e = 12) {
|
|
75
68
|
if (typeof crypto > "u" || !crypto.getRandomValues) throw Error("Web Crypto API is not available in this runtime");
|
|
76
69
|
let t = new Uint8Array(e);
|
|
77
70
|
crypto.getRandomValues(t);
|
|
@@ -79,43 +72,43 @@ function v(e = 12) {
|
|
|
79
72
|
for (let e of t) n += e.toString(16).padStart(2, "0");
|
|
80
73
|
return n;
|
|
81
74
|
}
|
|
82
|
-
async function
|
|
83
|
-
let n =
|
|
84
|
-
return
|
|
75
|
+
async function se(e, t) {
|
|
76
|
+
let n = v(), r = await re(t), i = await n.sign("HMAC", r, l.encode(e));
|
|
77
|
+
return h(new Uint8Array(i));
|
|
85
78
|
}
|
|
86
|
-
async function
|
|
87
|
-
let r =
|
|
79
|
+
async function ce(e, t, n) {
|
|
80
|
+
let r = v(), i = await re(n), a = g(t);
|
|
88
81
|
return r.verify("HMAC", i, a.buffer, l.encode(e));
|
|
89
82
|
}
|
|
90
|
-
async function
|
|
91
|
-
let n =
|
|
92
|
-
return
|
|
83
|
+
async function le(e, t) {
|
|
84
|
+
let n = v(), r = await ie(t), i = await n.sign("Ed25519", r, l.encode(e));
|
|
85
|
+
return h(new Uint8Array(i));
|
|
93
86
|
}
|
|
94
|
-
async function
|
|
95
|
-
let r =
|
|
87
|
+
async function ue(e, t, n) {
|
|
88
|
+
let r = v(), i = await ae(n), a = g(t);
|
|
96
89
|
return r.verify("Ed25519", i, a.buffer, l.encode(e));
|
|
97
90
|
}
|
|
98
|
-
async function
|
|
99
|
-
return
|
|
91
|
+
async function de(e, t) {
|
|
92
|
+
return se(e, t);
|
|
100
93
|
}
|
|
101
|
-
async function
|
|
102
|
-
return
|
|
94
|
+
async function fe(e, t, n) {
|
|
95
|
+
return ce(e, t, n);
|
|
103
96
|
}
|
|
104
|
-
async function
|
|
105
|
-
let e =
|
|
97
|
+
async function pe() {
|
|
98
|
+
let e = v(), t = await e.generateKey({ name: "Ed25519" }, !0, ["sign", "verify"]), n = await e.exportKey("pkcs8", t.privateKey), r = await e.exportKey("spki", t.publicKey);
|
|
106
99
|
return {
|
|
107
|
-
privateKey:
|
|
108
|
-
publicKey:
|
|
100
|
+
privateKey: h(new Uint8Array(n)),
|
|
101
|
+
publicKey: h(new Uint8Array(r))
|
|
109
102
|
};
|
|
110
103
|
}
|
|
111
|
-
async function
|
|
112
|
-
return
|
|
104
|
+
async function b(e, t) {
|
|
105
|
+
return le(e, t);
|
|
113
106
|
}
|
|
114
|
-
async function
|
|
115
|
-
return
|
|
107
|
+
async function x(e, t, n) {
|
|
108
|
+
return ue(e, t, n);
|
|
116
109
|
}
|
|
117
|
-
async function
|
|
118
|
-
let r = await
|
|
110
|
+
async function me(e, t, n = "local-dev-key") {
|
|
111
|
+
let r = await se(_(e), t);
|
|
119
112
|
return {
|
|
120
113
|
...e,
|
|
121
114
|
signature: {
|
|
@@ -125,14 +118,14 @@ async function x(e, t, n = "local-dev-key") {
|
|
|
125
118
|
}
|
|
126
119
|
};
|
|
127
120
|
}
|
|
128
|
-
async function
|
|
129
|
-
return !e.signature || e.signature.alg !== "HS256" ? !1 :
|
|
121
|
+
async function S(e, t) {
|
|
122
|
+
return !e.signature || e.signature.alg !== "HS256" ? !1 : ce(_({
|
|
130
123
|
header: e.header,
|
|
131
124
|
body: e.body
|
|
132
125
|
}), e.signature.value, t);
|
|
133
126
|
}
|
|
134
|
-
async function
|
|
135
|
-
let r = await
|
|
127
|
+
async function C(e, t, n = "local-ed25519-key") {
|
|
128
|
+
let r = await le(_(e), t);
|
|
136
129
|
return {
|
|
137
130
|
...e,
|
|
138
131
|
signature: {
|
|
@@ -142,19 +135,20 @@ async function S(e, t, n = "local-ed25519-key") {
|
|
|
142
135
|
}
|
|
143
136
|
};
|
|
144
137
|
}
|
|
145
|
-
async function
|
|
146
|
-
return !e.signature || e.signature.alg !== "ED25519" ? !1 :
|
|
138
|
+
async function w(e, t) {
|
|
139
|
+
return !e.signature || e.signature.alg !== "ED25519" ? !1 : ue(_({
|
|
147
140
|
header: e.header,
|
|
148
141
|
body: e.body
|
|
149
142
|
}), e.signature.value, t);
|
|
150
143
|
}
|
|
151
|
-
async function
|
|
152
|
-
return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ?
|
|
144
|
+
async function he(e, t) {
|
|
145
|
+
return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? S(e, t.secret) : w(e, t.publicKey);
|
|
153
146
|
}
|
|
154
|
-
async function
|
|
155
|
-
return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ?
|
|
147
|
+
async function ge(e, t, n) {
|
|
148
|
+
return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : x(e, t.value, n.publicKey);
|
|
156
149
|
}
|
|
157
|
-
|
|
150
|
+
var _e = 864e5;
|
|
151
|
+
function T(e, t = Date.now()) {
|
|
158
152
|
let n = [], r = e.header ?? {}, i = e.body ?? {}, a = typeof r.version == "string" ? r.version : "", o = typeof r.messageId == "string" ? r.messageId : "", s = typeof r.sender == "string" ? r.sender : "", c = typeof r.nonce == "string" ? r.nonce : "", l = typeof r.timestampMs == "number" ? r.timestampMs : 0, u = typeof r.ttlMs == "number" ? r.ttlMs : 0, d = typeof i.content == "string" ? i.content : "";
|
|
159
153
|
return a !== "7h3/0.1" && n.push({
|
|
160
154
|
level: "error",
|
|
@@ -171,6 +165,9 @@ function w(e, t = Date.now()) {
|
|
|
171
165
|
}), u <= 0 && n.push({
|
|
172
166
|
level: "error",
|
|
173
167
|
message: "ttlMs must be greater than zero"
|
|
168
|
+
}), u > 864e5 && n.push({
|
|
169
|
+
level: "error",
|
|
170
|
+
message: `ttlMs exceeds maximum allowed ${_e} ms`
|
|
174
171
|
}), l + u < t && n.push({
|
|
175
172
|
level: "error",
|
|
176
173
|
message: "Message TTL expired"
|
|
@@ -179,17 +176,17 @@ function w(e, t = Date.now()) {
|
|
|
179
176
|
message: "Empty content payload"
|
|
180
177
|
}), n;
|
|
181
178
|
}
|
|
182
|
-
function
|
|
179
|
+
function E(e) {
|
|
183
180
|
let t = e.nowMs ?? Date.now();
|
|
184
181
|
return {
|
|
185
182
|
header: {
|
|
186
183
|
version: "7h3/0.1",
|
|
187
|
-
messageId: e.messageId ?? `msg-${t}-${
|
|
184
|
+
messageId: e.messageId ?? `msg-${t}-${y(6)}`,
|
|
188
185
|
timestampMs: t,
|
|
189
186
|
ttlMs: e.ttlMs ?? 6e4,
|
|
190
187
|
sender: e.sender,
|
|
191
188
|
recipient: e.recipient,
|
|
192
|
-
nonce: e.nonce ??
|
|
189
|
+
nonce: e.nonce ?? y(12)
|
|
193
190
|
},
|
|
194
191
|
body: {
|
|
195
192
|
intent: e.intent,
|
|
@@ -206,7 +203,7 @@ var ve = [
|
|
|
206
203
|
73,
|
|
207
204
|
80,
|
|
208
205
|
66
|
|
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([
|
|
206
|
+
], ye = Uint8Array.from(ve), be = 1, xe = 1024 * 1024, Se = 1, Ce = 2, we = 4, Te = 8, Ee = new TextEncoder(), De = new TextDecoder(), Oe = /* @__PURE__ */ new Set([
|
|
210
207
|
"PING",
|
|
211
208
|
"PONG",
|
|
212
209
|
"CAPS",
|
|
@@ -226,10 +223,10 @@ function je(e) {
|
|
|
226
223
|
function Me(e) {
|
|
227
224
|
return e === 1 ? "HS256" : e === 2 ? "ED25519" : null;
|
|
228
225
|
}
|
|
229
|
-
function
|
|
226
|
+
function D(e) {
|
|
230
227
|
return { bytes: ke(e) };
|
|
231
228
|
}
|
|
232
|
-
function
|
|
229
|
+
function O(e) {
|
|
233
230
|
return e ? 4 + e.bytes.byteLength : 0;
|
|
234
231
|
}
|
|
235
232
|
var Ne = class {
|
|
@@ -292,7 +289,7 @@ var Ne = class {
|
|
|
292
289
|
}
|
|
293
290
|
};
|
|
294
291
|
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 =
|
|
292
|
+
let t = (e.header.recipient ? Se : 0) | (e.body.capability ? Ce : 0) | (e.body.correlationId ? we : 0) | (e.signature ? Te : 0), n = D(e.header.version), r = D(e.header.messageId), i = D(e.header.sender), a = D(e.header.nonce), o = D(e.body.intent), s = D(e.body.content), c = e.header.recipient ? D(e.header.recipient) : null, l = e.body.capability ? D(e.body.capability) : null, u = e.body.correlationId ? D(e.body.correlationId) : null, d = e.signature ? D(e.signature.keyId) : null, f = e.signature ? D(e.signature.value) : null, p = new Ne(ye.byteLength + 1 + 1 + 8 + 4 + O(n) + O(r) + O(i) + O(a) + O(o) + O(s) + O(c) + O(l) + O(u) + +!!e.signature + O(d) + O(f));
|
|
296
293
|
return p.writeBytes(ye), p.writeU8(be), p.writeU8(t), p.writeU64(e.header.timestampMs), p.writeU32(e.header.ttlMs), p.writeString(n), p.writeString(r), p.writeString(i), p.writeString(a), p.writeString(o), p.writeString(s), c && p.writeString(c), l && p.writeString(l), u && p.writeString(u), e.signature && d && f && (p.writeU8(je(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
|
|
297
294
|
}
|
|
298
295
|
function Ie(e, t = {}) {
|
|
@@ -433,7 +430,7 @@ var Le = class {
|
|
|
433
430
|
this.items[t] = l, this.items[r] = c, t = r;
|
|
434
431
|
}
|
|
435
432
|
}
|
|
436
|
-
},
|
|
433
|
+
}, k = class {
|
|
437
434
|
entries = /* @__PURE__ */ new Map();
|
|
438
435
|
maxEntries;
|
|
439
436
|
expiries = new Le();
|
|
@@ -673,7 +670,7 @@ function Je(e) {
|
|
|
673
670
|
}];
|
|
674
671
|
}
|
|
675
672
|
}
|
|
676
|
-
async function
|
|
673
|
+
async function A(e, t = {}) {
|
|
677
674
|
let n = t.nowMs ?? Date.now(), r = t.requireSignature ?? !0, i = t.maxClockSkewMs ?? 3e4;
|
|
678
675
|
async function a(e) {
|
|
679
676
|
t.telemetry && await t.telemetry({
|
|
@@ -707,7 +704,7 @@ async function k(e, t = {}) {
|
|
|
707
704
|
envelope: o.envelope
|
|
708
705
|
};
|
|
709
706
|
}
|
|
710
|
-
let s = [...
|
|
707
|
+
let s = [...T(o.envelope, n)];
|
|
711
708
|
if (s.some((e) => e.level === "error")) return await a({
|
|
712
709
|
phase: "rejected_validation",
|
|
713
710
|
sender: o.envelope.header.sender,
|
|
@@ -764,7 +761,7 @@ async function k(e, t = {}) {
|
|
|
764
761
|
diagnostics: s,
|
|
765
762
|
envelope: o.envelope
|
|
766
763
|
};
|
|
767
|
-
if (!await
|
|
764
|
+
if (!await ge(_({
|
|
768
765
|
header: o.envelope.header,
|
|
769
766
|
body: o.envelope.body
|
|
770
767
|
}), o.envelope.signature, c)) return s.push({
|
|
@@ -815,7 +812,7 @@ async function Ye(e, t = {}) {
|
|
|
815
812
|
let n = i;
|
|
816
813
|
i += 1;
|
|
817
814
|
let a = e[n];
|
|
818
|
-
a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await
|
|
815
|
+
a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await A(a, t);
|
|
819
816
|
}
|
|
820
817
|
})), await t.telemetry?.({
|
|
821
818
|
phase: "batch_summary",
|
|
@@ -829,12 +826,12 @@ var Xe = class {
|
|
|
829
826
|
constructor(e = {}) {
|
|
830
827
|
this.options = {
|
|
831
828
|
...e,
|
|
832
|
-
replayCache: e.replayCache ?? new
|
|
829
|
+
replayCache: e.replayCache ?? new k(),
|
|
833
830
|
verificationMaterialCache: e.verificationMaterialCache ?? new ze()
|
|
834
831
|
};
|
|
835
832
|
}
|
|
836
833
|
receive(e, t = Date.now()) {
|
|
837
|
-
return
|
|
834
|
+
return A(e, {
|
|
838
835
|
...this.options,
|
|
839
836
|
nowMs: t
|
|
840
837
|
});
|
|
@@ -847,7 +844,7 @@ var Xe = class {
|
|
|
847
844
|
}
|
|
848
845
|
};
|
|
849
846
|
async function Ze(e) {
|
|
850
|
-
return
|
|
847
|
+
return me(E(e), e.secret, e.keyId);
|
|
851
848
|
}
|
|
852
849
|
//#endregion
|
|
853
850
|
//#region src/protocolCapabilities.ts
|
|
@@ -930,13 +927,13 @@ var ot = class {
|
|
|
930
927
|
resolveInboundSecret;
|
|
931
928
|
onTask;
|
|
932
929
|
constructor(e) {
|
|
933
|
-
this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new
|
|
930
|
+
this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new k(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
|
|
934
931
|
}
|
|
935
932
|
async inboundSecretResolver(e, t) {
|
|
936
933
|
return this.resolveInboundSecret ? this.resolveInboundSecret(e, t) : this.sharedSecrets[t];
|
|
937
934
|
}
|
|
938
935
|
async createSignedIntent(e) {
|
|
939
|
-
return
|
|
936
|
+
return me(E({
|
|
940
937
|
sender: this.agentId,
|
|
941
938
|
recipient: e.recipient,
|
|
942
939
|
intent: e.intent,
|
|
@@ -950,7 +947,7 @@ var ot = class {
|
|
|
950
947
|
}), this.outboundSecret, this.keyId);
|
|
951
948
|
}
|
|
952
949
|
async receiveAndRespond(e, t = Date.now()) {
|
|
953
|
-
let n = await
|
|
950
|
+
let n = await A(e, {
|
|
954
951
|
nowMs: t,
|
|
955
952
|
requireSignature: this.requireSignature,
|
|
956
953
|
replayCache: this.replayCache,
|
|
@@ -1275,28 +1272,28 @@ function wt(e) {
|
|
|
1275
1272
|
}
|
|
1276
1273
|
};
|
|
1277
1274
|
}
|
|
1278
|
-
async function
|
|
1275
|
+
async function j(e = {}) {
|
|
1279
1276
|
let t = await xt(e);
|
|
1280
1277
|
return {
|
|
1281
1278
|
policy: t,
|
|
1282
1279
|
enforcer: wt(t)
|
|
1283
1280
|
};
|
|
1284
1281
|
}
|
|
1285
|
-
function
|
|
1282
|
+
function Tt(e) {
|
|
1286
1283
|
return Ct(e);
|
|
1287
1284
|
}
|
|
1288
1285
|
//#endregion
|
|
1289
1286
|
//#region src/mcpGateway.ts
|
|
1290
|
-
var
|
|
1287
|
+
var Et = [
|
|
1291
1288
|
"tools/call",
|
|
1292
1289
|
"resources/read",
|
|
1293
1290
|
"prompts/get"
|
|
1294
1291
|
];
|
|
1295
|
-
function
|
|
1292
|
+
function Dt(e) {
|
|
1296
1293
|
return JSON.stringify(e);
|
|
1297
1294
|
}
|
|
1298
|
-
function
|
|
1299
|
-
return
|
|
1295
|
+
function M(e, t, n) {
|
|
1296
|
+
return Dt({
|
|
1300
1297
|
jsonrpc: "2.0",
|
|
1301
1298
|
id: e,
|
|
1302
1299
|
error: {
|
|
@@ -1305,7 +1302,7 @@ function A(e, t, n) {
|
|
|
1305
1302
|
}
|
|
1306
1303
|
});
|
|
1307
1304
|
}
|
|
1308
|
-
function
|
|
1305
|
+
function Ot(e) {
|
|
1309
1306
|
let t = JSON.parse(e);
|
|
1310
1307
|
return t.jsonrpc !== "2.0" || typeof t.method != "string" || t.method.length === 0 || typeof t.id != "string" && typeof t.id != "number" ? null : {
|
|
1311
1308
|
jsonrpc: "2.0",
|
|
@@ -1314,11 +1311,11 @@ function kt(e) {
|
|
|
1314
1311
|
params: t.params
|
|
1315
1312
|
};
|
|
1316
1313
|
}
|
|
1317
|
-
function
|
|
1314
|
+
function kt(e) {
|
|
1318
1315
|
return e.includes("not allowed") ? -32601 : e.includes("not authorized") ? -32001 : e.includes("rate-limited") ? -32002 : -32603;
|
|
1319
1316
|
}
|
|
1320
|
-
function
|
|
1321
|
-
let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ??
|
|
1317
|
+
function At(e) {
|
|
1318
|
+
let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Et, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
|
|
1322
1319
|
async function s(t) {
|
|
1323
1320
|
e.onAuditEvent && await e.onAuditEvent({
|
|
1324
1321
|
...t,
|
|
@@ -1337,7 +1334,7 @@ function jt(e) {
|
|
|
1337
1334
|
wireFormat: o,
|
|
1338
1335
|
onTask: async (e) => ({
|
|
1339
1336
|
intent: "RESULT",
|
|
1340
|
-
content:
|
|
1337
|
+
content: Dt({
|
|
1341
1338
|
ok: !0,
|
|
1342
1339
|
capability: e.body.capability,
|
|
1343
1340
|
content: e.body.content
|
|
@@ -1350,18 +1347,18 @@ function jt(e) {
|
|
|
1350
1347
|
if (!i) return null;
|
|
1351
1348
|
let a = null;
|
|
1352
1349
|
try {
|
|
1353
|
-
let t =
|
|
1350
|
+
let t = Ot(i);
|
|
1354
1351
|
if (!t) return await s({
|
|
1355
1352
|
phase: "request_error",
|
|
1356
1353
|
code: -32600,
|
|
1357
1354
|
message: "Invalid Request"
|
|
1358
|
-
}),
|
|
1355
|
+
}), M(null, -32600, "Invalid Request");
|
|
1359
1356
|
a = t.id, await s({
|
|
1360
1357
|
phase: "request_received",
|
|
1361
1358
|
id: t.id,
|
|
1362
1359
|
method: t.method
|
|
1363
1360
|
});
|
|
1364
|
-
let o =
|
|
1361
|
+
let o = {
|
|
1365
1362
|
recipient: n,
|
|
1366
1363
|
allowedMethods: r,
|
|
1367
1364
|
methodToCapability: e.methodToCapability,
|
|
@@ -1376,42 +1373,42 @@ function jt(e) {
|
|
|
1376
1373
|
policy: e
|
|
1377
1374
|
});
|
|
1378
1375
|
}
|
|
1379
|
-
}
|
|
1380
|
-
if (await l.handleRaw(
|
|
1381
|
-
|
|
1382
|
-
}), !
|
|
1376
|
+
}, u = await mt(c, t, o), d = null;
|
|
1377
|
+
if (await l.handleRaw(u, async (e) => {
|
|
1378
|
+
d = e;
|
|
1379
|
+
}), !d) return await s({
|
|
1383
1380
|
phase: "verification_failed",
|
|
1384
1381
|
id: t.id,
|
|
1385
1382
|
method: t.method,
|
|
1386
1383
|
code: -32603,
|
|
1387
1384
|
message: "AIP worker did not produce a response"
|
|
1388
|
-
}),
|
|
1389
|
-
let
|
|
1390
|
-
return !
|
|
1385
|
+
}), M(a, -32603, "AIP worker did not produce a response");
|
|
1386
|
+
let f = await c.receiveRaw(d);
|
|
1387
|
+
return !f.ok || !f.received ? (await s({
|
|
1391
1388
|
phase: "verification_failed",
|
|
1392
1389
|
id: t.id,
|
|
1393
1390
|
method: t.method,
|
|
1394
1391
|
code: -32603,
|
|
1395
1392
|
message: "AIP verification failed"
|
|
1396
|
-
}),
|
|
1393
|
+
}), M(a, -32603, "AIP verification failed")) : (await s({
|
|
1397
1394
|
phase: "request_success",
|
|
1398
1395
|
id: t.id,
|
|
1399
1396
|
method: t.method
|
|
1400
|
-
}),
|
|
1397
|
+
}), Dt(ht(f.received, t.id)));
|
|
1401
1398
|
} catch (e) {
|
|
1402
|
-
let t = e instanceof Error ? e.message : "Internal error", n =
|
|
1399
|
+
let t = e instanceof Error ? e.message : "Internal error", n = kt(t);
|
|
1403
1400
|
return await s({
|
|
1404
1401
|
phase: "request_error",
|
|
1405
1402
|
id: a,
|
|
1406
1403
|
code: n,
|
|
1407
1404
|
message: t
|
|
1408
|
-
}),
|
|
1405
|
+
}), M(a, n, t);
|
|
1409
1406
|
}
|
|
1410
1407
|
} };
|
|
1411
1408
|
}
|
|
1412
|
-
async function
|
|
1413
|
-
if (!e.runtimePolicy?.enabled) return
|
|
1414
|
-
let { enforcer: t } = await
|
|
1409
|
+
async function jt(e) {
|
|
1410
|
+
if (!e.runtimePolicy?.enabled) return At(e);
|
|
1411
|
+
let { enforcer: t } = await j(e.runtimePolicy.options);
|
|
1415
1412
|
t.assertInvariant({
|
|
1416
1413
|
signatureVerification: !0,
|
|
1417
1414
|
canonicalization: !0,
|
|
@@ -1423,7 +1420,7 @@ async function Mt(e) {
|
|
|
1423
1420
|
latencySensitive: e.runtimePolicy.latencySensitive,
|
|
1424
1421
|
compatibilityFirst: e.runtimePolicy.compatibilityFirst
|
|
1425
1422
|
}), r = n.includes("binary") ? "binary" : "compact";
|
|
1426
|
-
return
|
|
1423
|
+
return At({
|
|
1427
1424
|
...e,
|
|
1428
1425
|
gatewayWireFormat: r,
|
|
1429
1426
|
workerWireFormat: r,
|
|
@@ -1439,14 +1436,14 @@ async function Mt(e) {
|
|
|
1439
1436
|
}
|
|
1440
1437
|
//#endregion
|
|
1441
1438
|
//#region src/runtimePolicyManager.ts
|
|
1442
|
-
var
|
|
1439
|
+
var Mt = class {
|
|
1443
1440
|
snapshot = null;
|
|
1444
1441
|
options;
|
|
1445
1442
|
constructor(e = {}) {
|
|
1446
1443
|
this.options = e;
|
|
1447
1444
|
}
|
|
1448
1445
|
async loadInitial() {
|
|
1449
|
-
let e = await
|
|
1446
|
+
let e = await j(this.options);
|
|
1450
1447
|
return this.snapshot = {
|
|
1451
1448
|
...e,
|
|
1452
1449
|
loadedAtMs: Date.now()
|
|
@@ -1459,7 +1456,7 @@ var Nt = class {
|
|
|
1459
1456
|
async refresh() {
|
|
1460
1457
|
let e = this.snapshot;
|
|
1461
1458
|
try {
|
|
1462
|
-
let e = await
|
|
1459
|
+
let e = await j(this.options);
|
|
1463
1460
|
return this.snapshot = {
|
|
1464
1461
|
...e,
|
|
1465
1462
|
loadedAtMs: Date.now()
|
|
@@ -1469,7 +1466,7 @@ var Nt = class {
|
|
|
1469
1466
|
throw t;
|
|
1470
1467
|
}
|
|
1471
1468
|
}
|
|
1472
|
-
},
|
|
1469
|
+
}, Nt = {
|
|
1473
1470
|
dev: {
|
|
1474
1471
|
environment: "dev",
|
|
1475
1472
|
mode: "ws-batch",
|
|
@@ -1495,12 +1492,12 @@ var Nt = class {
|
|
|
1495
1492
|
retryMaxAttempts: 3
|
|
1496
1493
|
}
|
|
1497
1494
|
};
|
|
1498
|
-
function
|
|
1499
|
-
return
|
|
1495
|
+
function Pt(e) {
|
|
1496
|
+
return Nt[e];
|
|
1500
1497
|
}
|
|
1501
1498
|
//#endregion
|
|
1502
1499
|
//#region src/policyTelemetryFeedback.ts
|
|
1503
|
-
function
|
|
1500
|
+
function Ft(e) {
|
|
1504
1501
|
let t = [], n = "normal";
|
|
1505
1502
|
return e.dropPct > .1 && (t.push("reduce inflight cap"), t.push("reduce batch size"), t.push("increase retry backoff"), e.mode === "http" && e.concurrency >= 100 && t.push("switch to http-binary-batch"), n = e.dropPct > 2 ? "critical" : "warn"), e.p99Ms > 20 && (t.push("reduce batch size"), t.push("run adaptive benchmark and re-baseline"), n === "normal" && (n = "warn"), e.p99Ms > 100 && (n = "critical")), {
|
|
1506
1503
|
severity: n,
|
|
@@ -1509,7 +1506,7 @@ function It(e) {
|
|
|
1509
1506
|
}
|
|
1510
1507
|
//#endregion
|
|
1511
1508
|
//#region src/redisClient.ts
|
|
1512
|
-
var
|
|
1509
|
+
var It = class {
|
|
1513
1510
|
entries = /* @__PURE__ */ new Map();
|
|
1514
1511
|
now;
|
|
1515
1512
|
constructor(e = {}) {
|
|
@@ -1555,13 +1552,13 @@ var Lt = class {
|
|
|
1555
1552
|
};
|
|
1556
1553
|
return t;
|
|
1557
1554
|
}
|
|
1558
|
-
},
|
|
1555
|
+
}, Lt = class {
|
|
1559
1556
|
keyPrefix;
|
|
1560
1557
|
client;
|
|
1561
1558
|
constructor(e = {}) {
|
|
1562
1559
|
if (this.keyPrefix = e.keyPrefix ?? "7h3:nonce:", e.client) this.client = e.client;
|
|
1563
1560
|
else {
|
|
1564
|
-
let e = new
|
|
1561
|
+
let e = new It();
|
|
1565
1562
|
this.client = {
|
|
1566
1563
|
set: (t, n, r) => e.set(t, n, {
|
|
1567
1564
|
nx: r?.nx,
|
|
@@ -1580,7 +1577,7 @@ var Lt = class {
|
|
|
1580
1577
|
px: Math.max(1, t)
|
|
1581
1578
|
}) === null;
|
|
1582
1579
|
}
|
|
1583
|
-
},
|
|
1580
|
+
}, Rt = class {
|
|
1584
1581
|
nodes;
|
|
1585
1582
|
constructor(e) {
|
|
1586
1583
|
this.nodes = e;
|
|
@@ -1589,17 +1586,17 @@ var Lt = class {
|
|
|
1589
1586
|
return (await Promise.all(this.nodes.map((n) => n.check(e, t)))).some((e) => e);
|
|
1590
1587
|
}
|
|
1591
1588
|
};
|
|
1592
|
-
function
|
|
1593
|
-
return
|
|
1589
|
+
function zt(e, t = {}) {
|
|
1590
|
+
return Bt(e) ? Ht(e, t) : new Lt(e);
|
|
1594
1591
|
}
|
|
1595
|
-
function
|
|
1592
|
+
function Bt(e) {
|
|
1596
1593
|
return typeof e == "object" && !!e && typeof e.set == "function" && (typeof e.pipeline == "function" || !("quit" in e));
|
|
1597
1594
|
}
|
|
1598
|
-
function
|
|
1599
|
-
return new
|
|
1595
|
+
function Vt(e) {
|
|
1596
|
+
return new Rt(e.map((e) => new Lt({ redisUrl: e })));
|
|
1600
1597
|
}
|
|
1601
|
-
function
|
|
1602
|
-
let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ?
|
|
1598
|
+
function Ht(e, t = {}) {
|
|
1599
|
+
let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Ht(new It(), {
|
|
1603
1600
|
keyPrefix: n,
|
|
1604
1601
|
errorBehavior: "reject"
|
|
1605
1602
|
}) : void 0);
|
|
@@ -1639,7 +1636,7 @@ function Ut(e, t = {}) {
|
|
|
1639
1636
|
}
|
|
1640
1637
|
//#endregion
|
|
1641
1638
|
//#region src/revocation.ts
|
|
1642
|
-
var
|
|
1639
|
+
var Ut = class {
|
|
1643
1640
|
revoked = /* @__PURE__ */ new Map();
|
|
1644
1641
|
now;
|
|
1645
1642
|
constructor(e = {}) {
|
|
@@ -1656,7 +1653,7 @@ var Wt = class {
|
|
|
1656
1653
|
this.revoked.set(this.makeKey(e, t), n.untilMs ?? Infinity);
|
|
1657
1654
|
}
|
|
1658
1655
|
};
|
|
1659
|
-
function
|
|
1656
|
+
function Wt(e, t = {}) {
|
|
1660
1657
|
let n = t.keyPrefix ?? "aip:revoked:", r = t.errorBehavior ?? "reject", i = t.cacheTtlMs ?? 5e3, a = t.onDegraded, o = t.now ?? (() => Date.now()), s = /* @__PURE__ */ new Map();
|
|
1661
1658
|
function c(e, t) {
|
|
1662
1659
|
return `${n}${e}${t}`;
|
|
@@ -1688,7 +1685,7 @@ function Gt(e, t = {}) {
|
|
|
1688
1685
|
}
|
|
1689
1686
|
};
|
|
1690
1687
|
}
|
|
1691
|
-
function
|
|
1688
|
+
function Gt(e, t, n = {}) {
|
|
1692
1689
|
let r = n.nowMsProvider ?? (() => Date.now());
|
|
1693
1690
|
return async (n, i) => {
|
|
1694
1691
|
if (!await t.isRevoked(i, n.keyId, r())) return e(n, i);
|
|
@@ -1696,7 +1693,7 @@ function Kt(e, t, n = {}) {
|
|
|
1696
1693
|
}
|
|
1697
1694
|
//#endregion
|
|
1698
1695
|
//#region src/mcpWrapper.ts
|
|
1699
|
-
function
|
|
1696
|
+
function N(e, t, n) {
|
|
1700
1697
|
return {
|
|
1701
1698
|
jsonrpc: "2.0",
|
|
1702
1699
|
id: e,
|
|
@@ -1706,20 +1703,20 @@ function j(e, t, n) {
|
|
|
1706
1703
|
}
|
|
1707
1704
|
};
|
|
1708
1705
|
}
|
|
1709
|
-
function
|
|
1706
|
+
function Kt(e, t) {
|
|
1710
1707
|
return {
|
|
1711
1708
|
requireSignature: !0,
|
|
1712
1709
|
...e.receive,
|
|
1713
1710
|
replayCache: t
|
|
1714
1711
|
};
|
|
1715
1712
|
}
|
|
1716
|
-
function
|
|
1717
|
-
let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i =
|
|
1713
|
+
function qt(e, t) {
|
|
1714
|
+
let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new k());
|
|
1718
1715
|
async function a(e) {
|
|
1719
1716
|
return Ke(await t.sign(e), n);
|
|
1720
1717
|
}
|
|
1721
1718
|
function o(e, n, i, o) {
|
|
1722
|
-
return a(
|
|
1719
|
+
return a(E({
|
|
1723
1720
|
sender: t.selfAgentId,
|
|
1724
1721
|
recipient: e,
|
|
1725
1722
|
intent: n,
|
|
@@ -1729,29 +1726,29 @@ function Jt(e, t) {
|
|
|
1729
1726
|
}));
|
|
1730
1727
|
}
|
|
1731
1728
|
return async (n) => {
|
|
1732
|
-
let r = await
|
|
1733
|
-
if (!r.ok || !r.envelope) return o(a, "ERROR",
|
|
1734
|
-
if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR",
|
|
1729
|
+
let r = await A(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
|
|
1730
|
+
if (!r.ok || !r.envelope) return o(a, "ERROR", N(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
|
|
1731
|
+
if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", N(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
|
|
1735
1732
|
let c;
|
|
1736
1733
|
try {
|
|
1737
1734
|
c = JSON.parse(r.envelope.body.content);
|
|
1738
1735
|
} catch {
|
|
1739
|
-
return o(a, "ERROR",
|
|
1736
|
+
return o(a, "ERROR", N(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
|
|
1740
1737
|
}
|
|
1741
1738
|
let l;
|
|
1742
1739
|
try {
|
|
1743
1740
|
l = await e(c);
|
|
1744
1741
|
} catch (e) {
|
|
1745
|
-
l =
|
|
1742
|
+
l = N(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
|
|
1746
1743
|
}
|
|
1747
1744
|
return o(r.envelope.header.sender, "RESULT", l, s);
|
|
1748
1745
|
};
|
|
1749
1746
|
}
|
|
1750
|
-
function
|
|
1751
|
-
let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r =
|
|
1747
|
+
function Jt(e) {
|
|
1748
|
+
let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new k());
|
|
1752
1749
|
return {
|
|
1753
1750
|
async encodeRequest(r) {
|
|
1754
|
-
let i =
|
|
1751
|
+
let i = E({
|
|
1755
1752
|
sender: e.selfAgentId,
|
|
1756
1753
|
recipient: e.peerAgentId,
|
|
1757
1754
|
intent: "TASK",
|
|
@@ -1764,7 +1761,7 @@ function Yt(e) {
|
|
|
1764
1761
|
};
|
|
1765
1762
|
},
|
|
1766
1763
|
async decodeResponse(t, n = {}) {
|
|
1767
|
-
let i = await
|
|
1764
|
+
let i = await A(t, r);
|
|
1768
1765
|
if (!i.ok || !i.envelope) {
|
|
1769
1766
|
let e = i.diagnostics.find((e) => e.level === "error")?.message ?? "unknown";
|
|
1770
1767
|
throw Error(`AIP response verification failed: ${e}`);
|
|
@@ -1776,8 +1773,8 @@ function Yt(e) {
|
|
|
1776
1773
|
}
|
|
1777
1774
|
};
|
|
1778
1775
|
}
|
|
1779
|
-
function
|
|
1780
|
-
let n =
|
|
1776
|
+
function Yt(e, t) {
|
|
1777
|
+
let n = Jt(t);
|
|
1781
1778
|
return async (t) => {
|
|
1782
1779
|
let { raw: r, messageId: i } = await n.encodeRequest(t);
|
|
1783
1780
|
return n.decodeResponse(await e(r), { expectCorrelationId: i });
|
|
@@ -1785,55 +1782,52 @@ function Xt(e, t) {
|
|
|
1785
1782
|
}
|
|
1786
1783
|
//#endregion
|
|
1787
1784
|
//#region src/mcpTransports.ts
|
|
1788
|
-
|
|
1789
|
-
t.exports = {};
|
|
1790
|
-
})))(), 1);
|
|
1791
|
-
function Zt(e) {
|
|
1785
|
+
function Xt(e) {
|
|
1792
1786
|
if (typeof e != "string") throw Error("stdio adapter supports json/compact (string) wire formats; use the HTTP adapter for binary");
|
|
1793
1787
|
return e;
|
|
1794
1788
|
}
|
|
1795
|
-
function
|
|
1796
|
-
let
|
|
1797
|
-
input:
|
|
1789
|
+
function Zt(t, n = {}) {
|
|
1790
|
+
let r = n.input ?? process.stdin, i = n.output ?? process.stdout, a = e.createInterface({
|
|
1791
|
+
input: r,
|
|
1798
1792
|
crlfDelay: Infinity
|
|
1799
|
-
}),
|
|
1800
|
-
let
|
|
1801
|
-
|
|
1793
|
+
}), o = Promise.resolve(), s = (e) => {
|
|
1794
|
+
let r = e.trim();
|
|
1795
|
+
r && (o = o.then(async () => {
|
|
1802
1796
|
try {
|
|
1803
|
-
let
|
|
1804
|
-
|
|
1797
|
+
let e = await t(r);
|
|
1798
|
+
i.write(`${Xt(e)}\n`);
|
|
1805
1799
|
} catch (e) {
|
|
1806
|
-
|
|
1800
|
+
n.onError?.(e);
|
|
1807
1801
|
}
|
|
1808
1802
|
}));
|
|
1809
1803
|
};
|
|
1810
|
-
return
|
|
1811
|
-
|
|
1804
|
+
return a.on("line", s), { close() {
|
|
1805
|
+
a.off("line", s), a.close();
|
|
1812
1806
|
} };
|
|
1813
1807
|
}
|
|
1814
|
-
function
|
|
1815
|
-
let
|
|
1816
|
-
input:
|
|
1808
|
+
function Qt(t) {
|
|
1809
|
+
let n = e.createInterface({
|
|
1810
|
+
input: t.input,
|
|
1817
1811
|
crlfDelay: Infinity
|
|
1818
|
-
}),
|
|
1812
|
+
}), r = [], i = (e) => {
|
|
1819
1813
|
let t = e.trim();
|
|
1820
1814
|
if (!t) return;
|
|
1821
|
-
let
|
|
1822
|
-
|
|
1823
|
-
};
|
|
1824
|
-
return
|
|
1825
|
-
send(
|
|
1826
|
-
let
|
|
1827
|
-
return new Promise((
|
|
1828
|
-
|
|
1815
|
+
let n = r.shift();
|
|
1816
|
+
n && n(t);
|
|
1817
|
+
};
|
|
1818
|
+
return n.on("line", i), {
|
|
1819
|
+
send(e) {
|
|
1820
|
+
let n = Xt(e);
|
|
1821
|
+
return new Promise((e) => {
|
|
1822
|
+
r.push(e), t.output.write(`${n}\n`);
|
|
1829
1823
|
});
|
|
1830
1824
|
},
|
|
1831
1825
|
close() {
|
|
1832
|
-
|
|
1826
|
+
n.off("line", i), n.close();
|
|
1833
1827
|
}
|
|
1834
1828
|
};
|
|
1835
1829
|
}
|
|
1836
|
-
function
|
|
1830
|
+
function $t(e, t = {}) {
|
|
1837
1831
|
return (n, r) => {
|
|
1838
1832
|
let i = [];
|
|
1839
1833
|
n.on("data", (e) => i.push(e)), n.on("error", () => {
|
|
@@ -1857,7 +1851,7 @@ function en(e, t = {}) {
|
|
|
1857
1851
|
});
|
|
1858
1852
|
};
|
|
1859
1853
|
}
|
|
1860
|
-
function
|
|
1854
|
+
function en(e) {
|
|
1861
1855
|
let t = e.fetchImpl ?? fetch, n = e.binary ? "application/octet-stream" : "application/json";
|
|
1862
1856
|
return { async send(r) {
|
|
1863
1857
|
let i = await t(e.url, {
|
|
@@ -1873,12 +1867,12 @@ function tn(e) {
|
|
|
1873
1867
|
}
|
|
1874
1868
|
//#endregion
|
|
1875
1869
|
//#region src/keyRegistry.ts
|
|
1876
|
-
function
|
|
1870
|
+
function tn(e) {
|
|
1877
1871
|
return { async getPublicKey(t) {
|
|
1878
1872
|
return e[t] ?? null;
|
|
1879
1873
|
} };
|
|
1880
1874
|
}
|
|
1881
|
-
function
|
|
1875
|
+
function nn(...e) {
|
|
1882
1876
|
return {
|
|
1883
1877
|
async getPublicKey(t) {
|
|
1884
1878
|
for (let n of e) {
|
|
@@ -1887,17 +1881,17 @@ function rn(...e) {
|
|
|
1887
1881
|
}
|
|
1888
1882
|
return null;
|
|
1889
1883
|
},
|
|
1890
|
-
async getSharedSecret(t) {
|
|
1891
|
-
for (let
|
|
1892
|
-
if (!
|
|
1893
|
-
let e = await
|
|
1884
|
+
async getSharedSecret(t, n) {
|
|
1885
|
+
for (let r of e) {
|
|
1886
|
+
if (!r.getSharedSecret) continue;
|
|
1887
|
+
let e = await r.getSharedSecret(t, n);
|
|
1894
1888
|
if (e !== null) return e;
|
|
1895
1889
|
}
|
|
1896
1890
|
return null;
|
|
1897
1891
|
}
|
|
1898
1892
|
};
|
|
1899
1893
|
}
|
|
1900
|
-
function
|
|
1894
|
+
function rn(e, t) {
|
|
1901
1895
|
let n = t?.ttlMs ?? 6e4, r = /* @__PURE__ */ new Map();
|
|
1902
1896
|
async function i(e, t) {
|
|
1903
1897
|
let i = Date.now(), a = r.get(e);
|
|
@@ -1912,25 +1906,25 @@ function an(e, t) {
|
|
|
1912
1906
|
async getPublicKey(t) {
|
|
1913
1907
|
return i(`pk:${t}`, () => e.getPublicKey(t));
|
|
1914
1908
|
},
|
|
1915
|
-
async getSharedSecret(t) {
|
|
1916
|
-
return e.getSharedSecret ? i(`ss:${t}`, () => e.getSharedSecret(t)) : null;
|
|
1909
|
+
async getSharedSecret(t, n) {
|
|
1910
|
+
return e.getSharedSecret ? i(`ss:${n}:${t}`, () => e.getSharedSecret(t, n)) : null;
|
|
1917
1911
|
}
|
|
1918
1912
|
};
|
|
1919
1913
|
}
|
|
1920
1914
|
//#endregion
|
|
1921
1915
|
//#region src/cborCodec.ts
|
|
1922
|
-
var
|
|
1916
|
+
var P = new TextEncoder(), an = new TextDecoder(), F = 0, on = 1, sn = 2, I = 3, cn = 4, ln = 5, un = 7, dn = 244, fn = 245, pn = 246, mn = 24, hn = 25, gn = 26, _n = 27, vn = 27, yn = class {
|
|
1923
1917
|
chunks = [];
|
|
1924
1918
|
encode(e) {
|
|
1925
1919
|
return this.chunks = [], this._encode(e), this._concat();
|
|
1926
1920
|
}
|
|
1927
1921
|
_encode(e) {
|
|
1928
1922
|
if (e == null) {
|
|
1929
|
-
this.chunks.push(new Uint8Array([
|
|
1923
|
+
this.chunks.push(new Uint8Array([pn]));
|
|
1930
1924
|
return;
|
|
1931
1925
|
}
|
|
1932
1926
|
if (typeof e == "boolean") {
|
|
1933
|
-
this.chunks.push(new Uint8Array([e ?
|
|
1927
|
+
this.chunks.push(new Uint8Array([e ? fn : dn]));
|
|
1934
1928
|
return;
|
|
1935
1929
|
}
|
|
1936
1930
|
if (typeof e == "number") {
|
|
@@ -1968,28 +1962,28 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
1968
1962
|
new DataView(t).setFloat64(0, e, !1), this.chunks.push(new Uint8Array(t));
|
|
1969
1963
|
return;
|
|
1970
1964
|
}
|
|
1971
|
-
e >= 0 ? this._encodeHead(
|
|
1965
|
+
e >= 0 ? this._encodeHead(F, e) : this._encodeHead(on, -1 - e);
|
|
1972
1966
|
}
|
|
1973
1967
|
_float64Header() {
|
|
1974
1968
|
return new Uint8Array([251]);
|
|
1975
1969
|
}
|
|
1976
1970
|
_encodeString(e) {
|
|
1977
|
-
let t =
|
|
1978
|
-
this._encodeHead(
|
|
1971
|
+
let t = P.encode(e);
|
|
1972
|
+
this._encodeHead(I, t.length), this.chunks.push(t);
|
|
1979
1973
|
}
|
|
1980
1974
|
_encodeByteString(e) {
|
|
1981
|
-
this._encodeHead(
|
|
1975
|
+
this._encodeHead(sn, e.length), this.chunks.push(e);
|
|
1982
1976
|
}
|
|
1983
1977
|
_encodeArray(e) {
|
|
1984
|
-
this._encodeHead(
|
|
1978
|
+
this._encodeHead(cn, e.length);
|
|
1985
1979
|
for (let t of e) this._encode(t);
|
|
1986
1980
|
}
|
|
1987
1981
|
_encodeMapFromAnyEntries(e) {
|
|
1988
1982
|
let t = e.map(([e, t]) => {
|
|
1989
1983
|
let n;
|
|
1990
|
-
if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(
|
|
1984
|
+
if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(F, e);
|
|
1991
1985
|
else {
|
|
1992
|
-
let t =
|
|
1986
|
+
let t = P.encode(String(e)), r = this._encodeHeadBytes(I, t.length);
|
|
1993
1987
|
n = this._concatPair(r, t);
|
|
1994
1988
|
}
|
|
1995
1989
|
return {
|
|
@@ -1998,27 +1992,27 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
1998
1992
|
value: t
|
|
1999
1993
|
};
|
|
2000
1994
|
});
|
|
2001
|
-
t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(
|
|
1995
|
+
t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
|
|
2002
1996
|
for (let { key: e, value: n } of t) {
|
|
2003
|
-
if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(
|
|
1997
|
+
if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(F, e);
|
|
2004
1998
|
else {
|
|
2005
|
-
let t =
|
|
2006
|
-
this._encodeHead(
|
|
1999
|
+
let t = P.encode(String(e));
|
|
2000
|
+
this._encodeHead(I, t.length), this.chunks.push(t);
|
|
2007
2001
|
}
|
|
2008
2002
|
this._encode(n);
|
|
2009
2003
|
}
|
|
2010
2004
|
}
|
|
2011
2005
|
_encodeMapFromEntries(e) {
|
|
2012
2006
|
let t = e.map(([e, t]) => {
|
|
2013
|
-
let n =
|
|
2007
|
+
let n = P.encode(e), r = this._encodeHeadBytes(I, n.length);
|
|
2014
2008
|
return {
|
|
2015
2009
|
keyBytes: n,
|
|
2016
2010
|
keyEncoded: this._concatPair(r, n),
|
|
2017
2011
|
value: t
|
|
2018
2012
|
};
|
|
2019
2013
|
});
|
|
2020
|
-
t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(
|
|
2021
|
-
for (let { keyBytes: e, value: n } of t) this._encodeHead(
|
|
2014
|
+
t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
|
|
2015
|
+
for (let { keyBytes: e, value: n } of t) this._encodeHead(I, e.length), this.chunks.push(e), this._encode(n);
|
|
2022
2016
|
}
|
|
2023
2017
|
_compareBytes(e, t) {
|
|
2024
2018
|
let n = Math.min(e.length, t.length);
|
|
@@ -2038,24 +2032,24 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
2038
2032
|
_encodeHeadBytes(e, t) {
|
|
2039
2033
|
let n = e << 5;
|
|
2040
2034
|
if (t <= 23) return new Uint8Array([n | t]);
|
|
2041
|
-
if (t <= 255) return new Uint8Array([n |
|
|
2035
|
+
if (t <= 255) return new Uint8Array([n | mn, t]);
|
|
2042
2036
|
if (t <= 65535) {
|
|
2043
2037
|
let e = /* @__PURE__ */ new ArrayBuffer(3), r = new DataView(e);
|
|
2044
|
-
return r.setUint8(0, n |
|
|
2038
|
+
return r.setUint8(0, n | hn), r.setUint16(1, t, !1), new Uint8Array(e);
|
|
2045
2039
|
}
|
|
2046
2040
|
if (t <= 4294967295) {
|
|
2047
2041
|
let e = /* @__PURE__ */ new ArrayBuffer(5), r = new DataView(e);
|
|
2048
|
-
return r.setUint8(0, n |
|
|
2042
|
+
return r.setUint8(0, n | gn), r.setUint32(1, t, !1), new Uint8Array(e);
|
|
2049
2043
|
}
|
|
2050
2044
|
let r = /* @__PURE__ */ new ArrayBuffer(9), i = new DataView(r);
|
|
2051
|
-
return i.setUint8(0, n |
|
|
2045
|
+
return i.setUint8(0, n | _n), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
|
|
2052
2046
|
}
|
|
2053
2047
|
_concat() {
|
|
2054
2048
|
let e = this.chunks.reduce((e, t) => e + t.length, 0), t = new Uint8Array(e), n = 0;
|
|
2055
2049
|
for (let e of this.chunks) t.set(e, n), n += e.length;
|
|
2056
2050
|
return t;
|
|
2057
2051
|
}
|
|
2058
|
-
},
|
|
2052
|
+
}, bn = class {
|
|
2059
2053
|
data;
|
|
2060
2054
|
offset = 0;
|
|
2061
2055
|
decode(e) {
|
|
@@ -2064,22 +2058,22 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
2064
2058
|
_decode() {
|
|
2065
2059
|
let e = this._readByte(), t = e >> 5 & 7, n = e & 31;
|
|
2066
2060
|
switch (t) {
|
|
2067
|
-
case
|
|
2068
|
-
case
|
|
2069
|
-
case
|
|
2061
|
+
case F: return this._decodeUint(n);
|
|
2062
|
+
case on: return -1 - this._decodeUint(n);
|
|
2063
|
+
case sn: {
|
|
2070
2064
|
let e = this._decodeUint(n);
|
|
2071
2065
|
return this._readBytes(e);
|
|
2072
2066
|
}
|
|
2073
|
-
case
|
|
2067
|
+
case I: {
|
|
2074
2068
|
let e = this._decodeUint(n), t = this._readBytes(e);
|
|
2075
|
-
return
|
|
2069
|
+
return an.decode(t);
|
|
2076
2070
|
}
|
|
2077
|
-
case
|
|
2071
|
+
case cn: {
|
|
2078
2072
|
let e = this._decodeUint(n), t = [];
|
|
2079
2073
|
for (let n = 0; n < e; n++) t.push(this._decode());
|
|
2080
2074
|
return t;
|
|
2081
2075
|
}
|
|
2082
|
-
case
|
|
2076
|
+
case ln: {
|
|
2083
2077
|
let e = this._decodeUint(n), t = {};
|
|
2084
2078
|
for (let n = 0; n < e; n++) {
|
|
2085
2079
|
let e = this._decode();
|
|
@@ -2087,11 +2081,11 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
2087
2081
|
}
|
|
2088
2082
|
return t;
|
|
2089
2083
|
}
|
|
2090
|
-
case
|
|
2084
|
+
case un:
|
|
2091
2085
|
if (n === 20) return !1;
|
|
2092
2086
|
if (n === 21) return !0;
|
|
2093
2087
|
if (n === 22) return null;
|
|
2094
|
-
if (n ===
|
|
2088
|
+
if (n === vn) {
|
|
2095
2089
|
let e = this._readBytes(8);
|
|
2096
2090
|
return new DataView(e.buffer, e.byteOffset, 8).getFloat64(0, !1);
|
|
2097
2091
|
}
|
|
@@ -2101,16 +2095,16 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
2101
2095
|
}
|
|
2102
2096
|
_decodeUint(e) {
|
|
2103
2097
|
if (e <= 23) return e;
|
|
2104
|
-
if (e ===
|
|
2105
|
-
if (e ===
|
|
2098
|
+
if (e === mn) return this._readByte();
|
|
2099
|
+
if (e === hn) {
|
|
2106
2100
|
let e = this._readBytes(2);
|
|
2107
2101
|
return new DataView(e.buffer, e.byteOffset, 2).getUint16(0, !1);
|
|
2108
2102
|
}
|
|
2109
|
-
if (e ===
|
|
2103
|
+
if (e === gn) {
|
|
2110
2104
|
let e = this._readBytes(4);
|
|
2111
2105
|
return new DataView(e.buffer, e.byteOffset, 4).getUint32(0, !1);
|
|
2112
2106
|
}
|
|
2113
|
-
if (e ===
|
|
2107
|
+
if (e === _n) {
|
|
2114
2108
|
let e = this._readBytes(8);
|
|
2115
2109
|
return Number(new DataView(e.buffer, e.byteOffset, 8).getBigUint64(0, !1));
|
|
2116
2110
|
}
|
|
@@ -2126,16 +2120,16 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
|
|
|
2126
2120
|
return this.offset += e, t;
|
|
2127
2121
|
}
|
|
2128
2122
|
};
|
|
2129
|
-
function
|
|
2130
|
-
return new
|
|
2123
|
+
function xn(e) {
|
|
2124
|
+
return new yn().encode(e);
|
|
2131
2125
|
}
|
|
2132
|
-
function
|
|
2133
|
-
return new
|
|
2126
|
+
function Sn(e) {
|
|
2127
|
+
return new bn().decode(e);
|
|
2134
2128
|
}
|
|
2135
2129
|
//#endregion
|
|
2136
2130
|
//#region src/envelopeCbor.ts
|
|
2137
|
-
var
|
|
2138
|
-
function
|
|
2131
|
+
var Cn = "application/7h3-cbor";
|
|
2132
|
+
function wn(e) {
|
|
2139
2133
|
let t = /* @__PURE__ */ new Map();
|
|
2140
2134
|
t.set(1, e.header.version), t.set(2, e.header.messageId), t.set(3, e.header.timestampMs), t.set(4, e.header.ttlMs), t.set(5, e.header.sender), e.header.recipient !== void 0 && t.set(6, e.header.recipient), t.set(7, e.header.nonce);
|
|
2141
2135
|
let n = /* @__PURE__ */ new Map();
|
|
@@ -2147,10 +2141,10 @@ function Tn(e) {
|
|
|
2147
2141
|
let e = /* @__PURE__ */ new Map();
|
|
2148
2142
|
e.set(1, i.alg), e.set(2, i.keyId), e.set(3, i.value), r.set(3, e);
|
|
2149
2143
|
}
|
|
2150
|
-
return
|
|
2144
|
+
return xn(r);
|
|
2151
2145
|
}
|
|
2152
|
-
function
|
|
2153
|
-
let t =
|
|
2146
|
+
function Tn(e) {
|
|
2147
|
+
let t = Sn(e);
|
|
2154
2148
|
if (!t || typeof t != "object" || Array.isArray(t)) throw Error("decodeEnvelopeCbor: expected a map at top level");
|
|
2155
2149
|
let n = t, r = n[1];
|
|
2156
2150
|
if (!r || typeof r != "object" || Array.isArray(r)) throw Error("decodeEnvelopeCbor: missing header map (key 1)");
|
|
@@ -2185,11 +2179,11 @@ function En(e) {
|
|
|
2185
2179
|
}
|
|
2186
2180
|
//#endregion
|
|
2187
2181
|
//#region src/httpBinding.ts
|
|
2188
|
-
var
|
|
2189
|
-
async function
|
|
2182
|
+
var En = "x-7h3-envelope";
|
|
2183
|
+
async function Dn(e, t, n) {
|
|
2190
2184
|
let r = t.headerName ?? "x-7h3-envelope", i = (Array.isArray(e["content-type"]) ? e["content-type"][0] : e["content-type"]) ?? "", a;
|
|
2191
2185
|
if (i.includes("7h3-cbor") && n instanceof Uint8Array) try {
|
|
2192
|
-
a =
|
|
2186
|
+
a = Tn(n);
|
|
2193
2187
|
} catch (e) {
|
|
2194
2188
|
return {
|
|
2195
2189
|
ok: !1,
|
|
@@ -2219,7 +2213,7 @@ async function On(e, t, n) {
|
|
|
2219
2213
|
detail: "missing required fields"
|
|
2220
2214
|
};
|
|
2221
2215
|
if (t.strictTtl ?? !0) {
|
|
2222
|
-
let e =
|
|
2216
|
+
let e = T(a).filter((e) => e.level === "error");
|
|
2223
2217
|
if (e.length > 0) return {
|
|
2224
2218
|
ok: !1,
|
|
2225
2219
|
reason: "ttl-expired",
|
|
@@ -2234,18 +2228,18 @@ async function On(e, t, n) {
|
|
|
2234
2228
|
reason: "unknown-sender",
|
|
2235
2229
|
detail: o
|
|
2236
2230
|
};
|
|
2237
|
-
if (!await
|
|
2231
|
+
if (!await w(a, e)) return {
|
|
2238
2232
|
ok: !1,
|
|
2239
2233
|
reason: "invalid-signature"
|
|
2240
2234
|
};
|
|
2241
2235
|
} else if (s === "HS256") {
|
|
2242
|
-
let e = await t.keyRegistry.getSharedSecret?.(a.signature.keyId);
|
|
2236
|
+
let e = await t.keyRegistry.getSharedSecret?.(a.signature.keyId, o);
|
|
2243
2237
|
if (!e) return {
|
|
2244
2238
|
ok: !1,
|
|
2245
2239
|
reason: "unknown-sender",
|
|
2246
2240
|
detail: a.signature.keyId
|
|
2247
2241
|
};
|
|
2248
|
-
if (!await
|
|
2242
|
+
if (!await S(a, e)) return {
|
|
2249
2243
|
ok: !1,
|
|
2250
2244
|
reason: "invalid-signature"
|
|
2251
2245
|
};
|
|
@@ -2259,24 +2253,24 @@ async function On(e, t, n) {
|
|
|
2259
2253
|
envelope: a
|
|
2260
2254
|
};
|
|
2261
2255
|
}
|
|
2262
|
-
async function
|
|
2263
|
-
let r = await
|
|
2256
|
+
async function On(e, t, n) {
|
|
2257
|
+
let r = await C(e, t);
|
|
2264
2258
|
if (n?.format === "cbor") {
|
|
2265
|
-
let e =
|
|
2259
|
+
let e = wn(r);
|
|
2266
2260
|
return {
|
|
2267
|
-
headers: { "content-type":
|
|
2261
|
+
headers: { "content-type": Cn },
|
|
2268
2262
|
body: e
|
|
2269
2263
|
};
|
|
2270
2264
|
}
|
|
2271
2265
|
return { headers: { [n?.headerName ?? "x-7h3-envelope"]: JSON.stringify(r) } };
|
|
2272
2266
|
}
|
|
2273
|
-
async function
|
|
2274
|
-
let i = await
|
|
2267
|
+
async function kn(e, t, n, r) {
|
|
2268
|
+
let i = await me(e, t, n);
|
|
2275
2269
|
return { headers: { [r?.headerName ?? "x-7h3-envelope"]: JSON.stringify(i) } };
|
|
2276
2270
|
}
|
|
2277
|
-
function
|
|
2271
|
+
function An(e) {
|
|
2278
2272
|
return async function(t, n, r) {
|
|
2279
|
-
let i = await
|
|
2273
|
+
let i = await Dn(t.headers, e);
|
|
2280
2274
|
if (!i.ok) {
|
|
2281
2275
|
n.status(401).json({
|
|
2282
2276
|
error: "7h3: request verification failed",
|
|
@@ -2288,13 +2282,13 @@ function jn(e) {
|
|
|
2288
2282
|
t["7h3Envelope"] = i.envelope, r();
|
|
2289
2283
|
};
|
|
2290
2284
|
}
|
|
2291
|
-
async function
|
|
2292
|
-
let { headers: i } = await
|
|
2285
|
+
async function jn(e, t, n, r) {
|
|
2286
|
+
let { headers: i } = await On(t, n, r), a = new Headers(e.headers);
|
|
2293
2287
|
for (let [e, t] of Object.entries(i)) a.set(e, t);
|
|
2294
2288
|
return new Request(e, { headers: a });
|
|
2295
2289
|
}
|
|
2296
|
-
async function
|
|
2297
|
-
return
|
|
2290
|
+
async function Mn(e, t) {
|
|
2291
|
+
return jn(e, E({
|
|
2298
2292
|
sender: t.sender,
|
|
2299
2293
|
recipient: t.recipient,
|
|
2300
2294
|
ttlMs: t.ttlMs ?? 6e4,
|
|
@@ -2304,39 +2298,39 @@ async function Nn(e, t) {
|
|
|
2304
2298
|
}
|
|
2305
2299
|
//#endregion
|
|
2306
2300
|
//#region src/webhookBinding.ts
|
|
2307
|
-
var
|
|
2308
|
-
function
|
|
2301
|
+
var L = "x-7h3-sig", R = "x-7h3-ts", Nn = 3e5;
|
|
2302
|
+
function Pn(e, t) {
|
|
2309
2303
|
return `${e}.${t}`;
|
|
2310
2304
|
}
|
|
2311
2305
|
async function Fn(e, t) {
|
|
2312
|
-
let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await
|
|
2306
|
+
let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await b(Pn(r, n), t.privateKey);
|
|
2313
2307
|
return {
|
|
2314
|
-
[
|
|
2315
|
-
[
|
|
2308
|
+
[L]: i,
|
|
2309
|
+
[R]: String(r)
|
|
2316
2310
|
};
|
|
2317
2311
|
}
|
|
2318
2312
|
async function In(e, t) {
|
|
2319
|
-
let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await
|
|
2313
|
+
let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(Pn(r, n), t.secret);
|
|
2320
2314
|
return {
|
|
2321
|
-
[
|
|
2322
|
-
[
|
|
2315
|
+
[L]: i,
|
|
2316
|
+
[R]: String(r)
|
|
2323
2317
|
};
|
|
2324
2318
|
}
|
|
2325
2319
|
async function Ln(e, t, n) {
|
|
2326
|
-
let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[
|
|
2320
|
+
let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
|
|
2327
2321
|
if (!i || !a) return !1;
|
|
2328
2322
|
let o = Number(a);
|
|
2329
2323
|
if (!Number.isFinite(o)) return !1;
|
|
2330
2324
|
let s = n.maxAgeMs ?? 3e5;
|
|
2331
|
-
return Date.now() - o > s ? !1 :
|
|
2325
|
+
return Date.now() - o > s ? !1 : x(Pn(o, r), i, n.publicKey);
|
|
2332
2326
|
}
|
|
2333
2327
|
async function Rn(e, t, n) {
|
|
2334
|
-
let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[
|
|
2328
|
+
let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
|
|
2335
2329
|
if (!i || !a) return !1;
|
|
2336
2330
|
let o = Number(a);
|
|
2337
2331
|
if (!Number.isFinite(o)) return !1;
|
|
2338
2332
|
let s = n.maxAgeMs ?? 3e5;
|
|
2339
|
-
return Date.now() - o > s ? !1 :
|
|
2333
|
+
return Date.now() - o > s ? !1 : fe(Pn(o, r), i, n.secret);
|
|
2340
2334
|
}
|
|
2341
2335
|
async function zn(e, t, n) {
|
|
2342
2336
|
if (!await Ln(e, t, n)) throw Error("7h3: webhook signature verification failed");
|
|
@@ -2346,7 +2340,7 @@ async function zn(e, t, n) {
|
|
|
2346
2340
|
//#region src/queueBinding.ts
|
|
2347
2341
|
async function Bn(e, t) {
|
|
2348
2342
|
let n = t.ttlMs ?? 36e5, r = typeof e == "string" ? e : JSON.stringify(e), i = {
|
|
2349
|
-
envelope: await
|
|
2343
|
+
envelope: await C(E({
|
|
2350
2344
|
sender: t.sender,
|
|
2351
2345
|
recipient: t.recipient,
|
|
2352
2346
|
intent: "TASK",
|
|
@@ -2365,7 +2359,16 @@ async function Vn(e, t) {
|
|
|
2365
2359
|
throw Error("Queue message is not valid JSON");
|
|
2366
2360
|
}
|
|
2367
2361
|
if (!n.envelope || typeof n.envelope != "object") throw Error("Queue message missing envelope");
|
|
2368
|
-
|
|
2362
|
+
let r = t.nowMs ?? Date.now();
|
|
2363
|
+
if (t.strictTtl ?? !0) {
|
|
2364
|
+
let e = T(n.envelope, r).filter((e) => e.level === "error");
|
|
2365
|
+
if (e.length > 0) throw Error(`Queue message failed validation: ${e.map((e) => e.message).join("; ")}`);
|
|
2366
|
+
}
|
|
2367
|
+
if (!await w(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
|
|
2368
|
+
if (t.replayCache) {
|
|
2369
|
+
let e = await t.replayCache.consume(n.envelope, r);
|
|
2370
|
+
if (!e.ok) throw Error(e.reason ?? "Queue message replay detected");
|
|
2371
|
+
}
|
|
2369
2372
|
return {
|
|
2370
2373
|
payload: n.payload,
|
|
2371
2374
|
envelope: n.envelope
|
|
@@ -2414,7 +2417,7 @@ function U(e) {
|
|
|
2414
2417
|
return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
2415
2418
|
}
|
|
2416
2419
|
function Gn() {
|
|
2417
|
-
let e = new Uint8Array(16);
|
|
2420
|
+
let e = /* @__PURE__ */ new Uint8Array(16);
|
|
2418
2421
|
return crypto.getRandomValues(e), V(e);
|
|
2419
2422
|
}
|
|
2420
2423
|
var W = /* @__PURE__ */ new Map(), Kn = 128;
|
|
@@ -2657,11 +2660,11 @@ function sr(e, t) {
|
|
|
2657
2660
|
a(/* @__PURE__ */ Error(`unknown sender: ${o}`), n);
|
|
2658
2661
|
return;
|
|
2659
2662
|
}
|
|
2660
|
-
if (!await
|
|
2663
|
+
if (!await w(i, s).catch(() => !1)) {
|
|
2661
2664
|
a(/* @__PURE__ */ Error("invalid signature"), n);
|
|
2662
2665
|
return;
|
|
2663
2666
|
}
|
|
2664
|
-
let c =
|
|
2667
|
+
let c = T(i);
|
|
2665
2668
|
if (c.some((e) => e.level === "error")) {
|
|
2666
2669
|
a(/* @__PURE__ */ Error(`envelope invalid: ${c.map((e) => e.message).join("; ")}`), n);
|
|
2667
2670
|
return;
|
|
@@ -2679,7 +2682,7 @@ function sr(e, t) {
|
|
|
2679
2682
|
return n;
|
|
2680
2683
|
},
|
|
2681
2684
|
async send(r) {
|
|
2682
|
-
let i = typeof r == "string" ? r : JSON.stringify(r), a = await
|
|
2685
|
+
let i = typeof r == "string" ? r : JSON.stringify(r), a = await C(E({
|
|
2683
2686
|
sender: t.sender,
|
|
2684
2687
|
recipient: t.recipient,
|
|
2685
2688
|
ttlMs: t.ttlMs ?? 3e4,
|
|
@@ -2735,7 +2738,7 @@ function lr(e, t) {
|
|
|
2735
2738
|
//#region src/grpcBinding.ts
|
|
2736
2739
|
var ur = "7h3-envelope-bin";
|
|
2737
2740
|
async function dr(e) {
|
|
2738
|
-
let t = await
|
|
2741
|
+
let t = await C(E({
|
|
2739
2742
|
sender: e.sender,
|
|
2740
2743
|
recipient: e.recipient,
|
|
2741
2744
|
ttlMs: e.ttlMs ?? 6e4,
|
|
@@ -2761,7 +2764,7 @@ async function fr(e, t) {
|
|
|
2761
2764
|
message: "7h3: malformed envelope metadata"
|
|
2762
2765
|
};
|
|
2763
2766
|
}
|
|
2764
|
-
if (t.strictTtl !== !1 &&
|
|
2767
|
+
if (t.strictTtl !== !1 && T(i).some((e) => e.level === "error")) return {
|
|
2765
2768
|
ok: !1,
|
|
2766
2769
|
code: 4,
|
|
2767
2770
|
message: "7h3: envelope expired or invalid"
|
|
@@ -2779,19 +2782,19 @@ async function fr(e, t) {
|
|
|
2779
2782
|
code: 16,
|
|
2780
2783
|
message: `7h3: unknown sender ${a}`
|
|
2781
2784
|
};
|
|
2782
|
-
if (!await
|
|
2785
|
+
if (!await w(i, e)) return {
|
|
2783
2786
|
ok: !1,
|
|
2784
2787
|
code: 16,
|
|
2785
2788
|
message: "7h3: invalid signature"
|
|
2786
2789
|
};
|
|
2787
2790
|
} else if (o === "HS256") {
|
|
2788
|
-
let e = await t.keyRegistry.getSharedSecret?.(i.signature.keyId);
|
|
2791
|
+
let e = await t.keyRegistry.getSharedSecret?.(i.signature.keyId, a);
|
|
2789
2792
|
if (!e) return {
|
|
2790
2793
|
ok: !1,
|
|
2791
2794
|
code: 16,
|
|
2792
2795
|
message: "7h3: unknown key"
|
|
2793
2796
|
};
|
|
2794
|
-
if (!await
|
|
2797
|
+
if (!await S(i, e)) return {
|
|
2795
2798
|
ok: !1,
|
|
2796
2799
|
code: 16,
|
|
2797
2800
|
message: "7h3: invalid signature"
|
|
@@ -2873,8 +2876,8 @@ var vr = class {
|
|
|
2873
2876
|
let e = Date.now(), t = this.getCurrentKey();
|
|
2874
2877
|
if (t && e - t.createdAt < this.maxAgeMs - this.overlapMs) return null;
|
|
2875
2878
|
t && !t.expiresAt && (t.expiresAt = e + this.overlapMs);
|
|
2876
|
-
let { publicKey: n, privateKey: r } = await
|
|
2877
|
-
id: `key-${e}-${
|
|
2879
|
+
let { publicKey: n, privateKey: r } = await pe(), i = {
|
|
2880
|
+
id: `key-${e}-${y(4)}`,
|
|
2878
2881
|
publicKey: n,
|
|
2879
2882
|
privateKey: r,
|
|
2880
2883
|
createdAt: e
|
|
@@ -2973,13 +2976,13 @@ function Sr(e, t) {
|
|
|
2973
2976
|
return null;
|
|
2974
2977
|
}
|
|
2975
2978
|
function Cr(e, t) {
|
|
2976
|
-
return !e.allowedSenders || e.allowedSenders.length === 0
|
|
2979
|
+
return !e.allowedSenders || e.allowedSenders.length === 0 || e.allowedSenders.includes(t);
|
|
2977
2980
|
}
|
|
2978
2981
|
//#endregion
|
|
2979
2982
|
//#region src/signedResponse.ts
|
|
2980
2983
|
var wr = "x-7h3-response";
|
|
2981
2984
|
async function Tr(e, t) {
|
|
2982
|
-
let n = await
|
|
2985
|
+
let n = await C(E({
|
|
2983
2986
|
sender: t.sender,
|
|
2984
2987
|
recipient: t.recipient,
|
|
2985
2988
|
intent: "RESULT",
|
|
@@ -3009,7 +3012,7 @@ async function Er(e, t, n) {
|
|
|
3009
3012
|
ok: !1,
|
|
3010
3013
|
reason: "ttl-expired",
|
|
3011
3014
|
envelope: a
|
|
3012
|
-
} : await
|
|
3015
|
+
} : await w(a, n.publicKey) ? a.body.content === e ? {
|
|
3013
3016
|
ok: !0,
|
|
3014
3017
|
envelope: a
|
|
3015
3018
|
} : {
|
|
@@ -3172,7 +3175,7 @@ function Q(e) {
|
|
|
3172
3175
|
return t.push(`"scopes":${n}`), t.push(`"subject":${JSON.stringify(e.subject)}`), t.push(`"version":${JSON.stringify(e.version)}`), `{${t.join(",")}}`;
|
|
3173
3176
|
}
|
|
3174
3177
|
async function Pr(e) {
|
|
3175
|
-
let t = Date.now(), n = `cap-${t}-${
|
|
3178
|
+
let t = Date.now(), n = `cap-${t}-${y(6)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
|
|
3176
3179
|
id: n,
|
|
3177
3180
|
version: "7h3-cap/1",
|
|
3178
3181
|
issuer: e.issuerId,
|
|
@@ -3183,7 +3186,7 @@ async function Pr(e) {
|
|
|
3183
3186
|
delegationDepth: 0,
|
|
3184
3187
|
maxDelegations: i,
|
|
3185
3188
|
keyId: r
|
|
3186
|
-
}, o = await
|
|
3189
|
+
}, o = await b(Q(a), e.issuerPrivateKey);
|
|
3187
3190
|
return {
|
|
3188
3191
|
...a,
|
|
3189
3192
|
signature: o
|
|
@@ -3211,7 +3214,7 @@ async function Lr(e) {
|
|
|
3211
3214
|
if (!Ir(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
|
|
3212
3215
|
let o = t.expiresAt - i;
|
|
3213
3216
|
if (e.ttlMs > o) throw Error(`Delegated ttlMs (${e.ttlMs}) exceeds parent token remaining TTL (${o})`);
|
|
3214
|
-
let s = `cap-${i}-${
|
|
3217
|
+
let s = `cap-${i}-${y(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
|
|
3215
3218
|
id: s,
|
|
3216
3219
|
version: "7h3-cap/1",
|
|
3217
3220
|
issuer: n,
|
|
@@ -3223,7 +3226,7 @@ async function Lr(e) {
|
|
|
3223
3226
|
parentTokenId: t.id,
|
|
3224
3227
|
maxDelegations: l,
|
|
3225
3228
|
keyId: c
|
|
3226
|
-
}, d = await
|
|
3229
|
+
}, d = await b(Q(u), e.delegatorPrivateKey);
|
|
3227
3230
|
return {
|
|
3228
3231
|
...u,
|
|
3229
3232
|
signature: d
|
|
@@ -3232,7 +3235,7 @@ async function Lr(e) {
|
|
|
3232
3235
|
async function Rr(e, t, n) {
|
|
3233
3236
|
if ((n?.now ?? Date.now()) >= e.expiresAt) return !1;
|
|
3234
3237
|
let { signature: r, ...i } = e;
|
|
3235
|
-
return
|
|
3238
|
+
return x(Q(i), r, t);
|
|
3236
3239
|
}
|
|
3237
3240
|
async function zr(e, t, n) {
|
|
3238
3241
|
if (e.length === 0) return {
|
|
@@ -3271,7 +3274,7 @@ async function zr(e, t, n) {
|
|
|
3271
3274
|
reason: `no-public-key-for-issuer:${i.issuer}`
|
|
3272
3275
|
};
|
|
3273
3276
|
let { signature: o, ...s } = i;
|
|
3274
|
-
if (!await
|
|
3277
|
+
if (!await x(Q(s), o, a)) return {
|
|
3275
3278
|
ok: !1,
|
|
3276
3279
|
reason: `invalid-signature-at-index:${n}`
|
|
3277
3280
|
};
|
|
@@ -3302,7 +3305,7 @@ var Ur = class {
|
|
|
3302
3305
|
config;
|
|
3303
3306
|
rateLimiter;
|
|
3304
3307
|
constructor(e) {
|
|
3305
|
-
this.config = e, this.rateLimiter = new br();
|
|
3308
|
+
this.config = e, this.rateLimiter = new br(), !e.replayStore && (e.policies ?? []).some((e) => e.require !== "none") && console.warn("[7h3-protocol] createGateway(): no replayStore configured with signature-requiring policies. Nonce/replay protection will not survive multiple gateway instances or restarts. See docs/GATEWAY.md#production-safety.");
|
|
3306
3309
|
}
|
|
3307
3310
|
async verify(e) {
|
|
3308
3311
|
let t = performance.now(), n = Sr(this.config.policies ?? [], e.path);
|
|
@@ -3373,7 +3376,7 @@ var Ur = class {
|
|
|
3373
3376
|
reason: "no-matching-policy"
|
|
3374
3377
|
};
|
|
3375
3378
|
}
|
|
3376
|
-
let r = await
|
|
3379
|
+
let r = await Dn(e.headers, {
|
|
3377
3380
|
keyRegistry: this.config.keyRegistry,
|
|
3378
3381
|
headerName: this.config.headerName
|
|
3379
3382
|
});
|
|
@@ -3425,7 +3428,7 @@ var Ur = class {
|
|
|
3425
3428
|
reason: "sender-denied"
|
|
3426
3429
|
};
|
|
3427
3430
|
}
|
|
3428
|
-
if (n?.rateLimit && !this.rateLimiter.consume(a, n.rateLimit).allowed) {
|
|
3431
|
+
if (n?.rateLimit && !(this.config.rateLimitStore ? await this.config.rateLimitStore.consume(a, n.rateLimit) : this.rateLimiter.consume(a, n.rateLimit)).allowed) {
|
|
3429
3432
|
let n = performance.now() - t;
|
|
3430
3433
|
return Z.verifications_total.increment({
|
|
3431
3434
|
result: "fail",
|
|
@@ -3487,9 +3490,14 @@ var Ur = class {
|
|
|
3487
3490
|
function Wr(e) {
|
|
3488
3491
|
return new Ur(e);
|
|
3489
3492
|
}
|
|
3493
|
+
function Gr(e) {
|
|
3494
|
+
if (e.defaultPolicy !== "deny") throw Error("createProductionGateway(): defaultPolicy must be explicitly 'deny'. Unmatched routes must never be forwarded unverified in production.");
|
|
3495
|
+
if (!e.replayStore) throw Error("createProductionGateway(): replayStore is required. Use a shared store (Redis/KV/Durable Object) so nonce replay protection survives multiple instances and restarts.");
|
|
3496
|
+
return new Ur(e);
|
|
3497
|
+
}
|
|
3490
3498
|
//#endregion
|
|
3491
3499
|
//#region src/auditLog.ts
|
|
3492
|
-
function
|
|
3500
|
+
function Kr(e) {
|
|
3493
3501
|
let t = [
|
|
3494
3502
|
`"id":${JSON.stringify(e.id)}`,
|
|
3495
3503
|
`"timestampMs":${e.timestampMs}`,
|
|
@@ -3497,7 +3505,7 @@ function Gr(e) {
|
|
|
3497
3505
|
];
|
|
3498
3506
|
return e.sender !== void 0 && t.push(`"sender":${JSON.stringify(e.sender)}`), e.path !== void 0 && t.push(`"path":${JSON.stringify(e.path)}`), e.method !== void 0 && t.push(`"method":${JSON.stringify(e.method)}`), e.envelopeId !== void 0 && t.push(`"envelopeId":${JSON.stringify(e.envelopeId)}`), e.failReason !== void 0 && t.push(`"failReason":${JSON.stringify(e.failReason)}`), e.upstream !== void 0 && t.push(`"upstream":${JSON.stringify(e.upstream)}`), e.responseStatus !== void 0 && t.push(`"responseStatus":${e.responseStatus}`), `{${t.join(",")}}`;
|
|
3499
3507
|
}
|
|
3500
|
-
var
|
|
3508
|
+
var qr = class {
|
|
3501
3509
|
entries = [];
|
|
3502
3510
|
privateKey;
|
|
3503
3511
|
maxEntries;
|
|
@@ -3506,10 +3514,10 @@ var Kr = class {
|
|
|
3506
3514
|
}
|
|
3507
3515
|
async log(e) {
|
|
3508
3516
|
let t = {
|
|
3509
|
-
id: `audit-${Date.now()}-${
|
|
3517
|
+
id: `audit-${Date.now()}-${y(5)}`,
|
|
3510
3518
|
timestampMs: Date.now(),
|
|
3511
3519
|
...e
|
|
3512
|
-
}, n = await
|
|
3520
|
+
}, n = await b(Kr(t), this.privateKey), r = {
|
|
3513
3521
|
...t,
|
|
3514
3522
|
entrySignature: n
|
|
3515
3523
|
};
|
|
@@ -3520,7 +3528,7 @@ var Kr = class {
|
|
|
3520
3528
|
return e?.type !== void 0 && (t = t.filter((t) => t.type === e.type)), e?.sender !== void 0 && (t = t.filter((t) => t.sender === e.sender)), e?.since !== void 0 && (t = t.filter((t) => t.timestampMs >= e.since)), e?.limit !== void 0 && (t = t.slice(-e.limit)), t;
|
|
3521
3529
|
}
|
|
3522
3530
|
async verify(e, t) {
|
|
3523
|
-
return
|
|
3531
|
+
return x(Kr({
|
|
3524
3532
|
id: e.id,
|
|
3525
3533
|
timestampMs: e.timestampMs,
|
|
3526
3534
|
type: e.type,
|
|
@@ -3536,7 +3544,7 @@ var Kr = class {
|
|
|
3536
3544
|
size() {
|
|
3537
3545
|
return this.entries.length;
|
|
3538
3546
|
}
|
|
3539
|
-
},
|
|
3547
|
+
}, Jr = class {
|
|
3540
3548
|
async log(e) {}
|
|
3541
3549
|
async query(e) {
|
|
3542
3550
|
return [];
|
|
@@ -3548,25 +3556,25 @@ var Kr = class {
|
|
|
3548
3556
|
return 0;
|
|
3549
3557
|
}
|
|
3550
3558
|
};
|
|
3551
|
-
function
|
|
3552
|
-
return new
|
|
3559
|
+
function Yr(e, t) {
|
|
3560
|
+
return new qr(e, t?.maxEntries);
|
|
3553
3561
|
}
|
|
3554
3562
|
//#endregion
|
|
3555
3563
|
//#region src/otel.ts
|
|
3556
|
-
var
|
|
3557
|
-
function
|
|
3558
|
-
|
|
3564
|
+
var Xr = null;
|
|
3565
|
+
function Zr(e) {
|
|
3566
|
+
Xr = e;
|
|
3559
3567
|
}
|
|
3560
|
-
function
|
|
3561
|
-
if (
|
|
3568
|
+
function Qr() {
|
|
3569
|
+
if (Xr === null) return null;
|
|
3562
3570
|
try {
|
|
3563
|
-
return
|
|
3571
|
+
return Xr.getTracer("7h3/protocol");
|
|
3564
3572
|
} catch {
|
|
3565
3573
|
return null;
|
|
3566
3574
|
}
|
|
3567
3575
|
}
|
|
3568
|
-
async function
|
|
3569
|
-
let n =
|
|
3576
|
+
async function $r(e, t) {
|
|
3577
|
+
let n = Qr();
|
|
3570
3578
|
if (n === null) return e(null);
|
|
3571
3579
|
let r = n.startSpan("7h3.verify", t);
|
|
3572
3580
|
try {
|
|
@@ -3577,8 +3585,8 @@ async function Qr(e, t) {
|
|
|
3577
3585
|
r.end();
|
|
3578
3586
|
}
|
|
3579
3587
|
}
|
|
3580
|
-
async function
|
|
3581
|
-
let t =
|
|
3588
|
+
async function ei(e) {
|
|
3589
|
+
let t = Qr();
|
|
3582
3590
|
if (t === null) return e(null);
|
|
3583
3591
|
let n = t.startSpan("7h3.audit.write");
|
|
3584
3592
|
try {
|
|
@@ -3591,64 +3599,64 @@ async function $r(e) {
|
|
|
3591
3599
|
}
|
|
3592
3600
|
//#endregion
|
|
3593
3601
|
//#region src/encryption.ts
|
|
3594
|
-
function
|
|
3602
|
+
function ti(e) {
|
|
3595
3603
|
return Buffer.from(e).toString("base64url");
|
|
3596
3604
|
}
|
|
3597
3605
|
function $(e) {
|
|
3598
3606
|
return Buffer.from(e, "base64url");
|
|
3599
3607
|
}
|
|
3600
|
-
var
|
|
3601
|
-
function
|
|
3608
|
+
var ni = Buffer.from("302e020100300506032b656e04220420", "hex"), ri = Buffer.from("302a300506032b656e032100", "hex");
|
|
3609
|
+
function ii(e) {
|
|
3602
3610
|
let t = $(e);
|
|
3603
|
-
return (
|
|
3604
|
-
key: Buffer.concat([
|
|
3611
|
+
return r({
|
|
3612
|
+
key: Buffer.concat([ni, t]),
|
|
3605
3613
|
format: "der",
|
|
3606
3614
|
type: "pkcs8"
|
|
3607
3615
|
});
|
|
3608
3616
|
}
|
|
3609
|
-
function
|
|
3617
|
+
function ai(e) {
|
|
3610
3618
|
let t = $(e);
|
|
3611
|
-
return (
|
|
3612
|
-
key: Buffer.concat([
|
|
3619
|
+
return i({
|
|
3620
|
+
key: Buffer.concat([ri, t]),
|
|
3613
3621
|
format: "der",
|
|
3614
3622
|
type: "spki"
|
|
3615
3623
|
});
|
|
3616
3624
|
}
|
|
3617
|
-
function
|
|
3618
|
-
let { privateKey: e, publicKey: t } = (
|
|
3625
|
+
function oi() {
|
|
3626
|
+
let { privateKey: e, publicKey: t } = o("x25519"), n = e.export({ format: "jwk" });
|
|
3619
3627
|
return {
|
|
3620
3628
|
publicKey: t.export({ format: "jwk" }).x,
|
|
3621
3629
|
privateKey: n.d
|
|
3622
3630
|
};
|
|
3623
3631
|
}
|
|
3624
|
-
function
|
|
3625
|
-
let r = (
|
|
3626
|
-
privateKey:
|
|
3627
|
-
publicKey:
|
|
3632
|
+
function si(e, t, n) {
|
|
3633
|
+
let r = s("sha256", a({
|
|
3634
|
+
privateKey: ii(e),
|
|
3635
|
+
publicKey: ai(t)
|
|
3628
3636
|
}), $(n), Buffer.from("7h3-enc/1", "utf8"), 32);
|
|
3629
3637
|
return Buffer.from(r);
|
|
3630
3638
|
}
|
|
3631
|
-
function
|
|
3632
|
-
let
|
|
3633
|
-
ephemeralPublic:
|
|
3634
|
-
nonce:
|
|
3635
|
-
ciphertext:
|
|
3636
|
-
tag:
|
|
3639
|
+
function ci(e, n) {
|
|
3640
|
+
let r = oi(), i = c(12), a = ti(i), o = si(r.privateKey, n, a), s = Buffer.from(JSON.stringify(e), "utf8"), l = t("chacha20-poly1305", o, i, { authTagLength: 16 }), u = Buffer.concat([l.update(s), l.final()]), d = l.getAuthTag(), f = {
|
|
3641
|
+
ephemeralPublic: r.publicKey,
|
|
3642
|
+
nonce: a,
|
|
3643
|
+
ciphertext: ti(u),
|
|
3644
|
+
tag: ti(d)
|
|
3637
3645
|
};
|
|
3638
3646
|
return {
|
|
3639
|
-
encryptedContent:
|
|
3640
|
-
ephemeralPublic:
|
|
3647
|
+
encryptedContent: ti(Buffer.from(JSON.stringify(f), "utf8")),
|
|
3648
|
+
ephemeralPublic: r.publicKey
|
|
3641
3649
|
};
|
|
3642
3650
|
}
|
|
3643
|
-
function
|
|
3644
|
-
let
|
|
3645
|
-
|
|
3646
|
-
let
|
|
3647
|
-
return JSON.parse(
|
|
3651
|
+
function li(e, t) {
|
|
3652
|
+
let r = $(e).toString("utf8"), { ephemeralPublic: i, nonce: a, ciphertext: o, tag: s } = JSON.parse(r), c = si(t, i, a), l = $(a), u = $(o), d = $(s), f = n("chacha20-poly1305", c, l, { authTagLength: 16 });
|
|
3653
|
+
f.setAuthTag(d);
|
|
3654
|
+
let p = Buffer.concat([f.update(u), f.final()]);
|
|
3655
|
+
return JSON.parse(p.toString("utf8"));
|
|
3648
3656
|
}
|
|
3649
|
-
async function
|
|
3650
|
-
let { encryptedContent: n } =
|
|
3651
|
-
return
|
|
3657
|
+
async function ui(e, t) {
|
|
3658
|
+
let { encryptedContent: n } = ci(e.body, t.recipientX25519PublicKey);
|
|
3659
|
+
return C({
|
|
3652
3660
|
header: e.header,
|
|
3653
3661
|
body: {
|
|
3654
3662
|
intent: "ENCRYPTED",
|
|
@@ -3658,12 +3666,12 @@ async function li(e, t) {
|
|
|
3658
3666
|
}
|
|
3659
3667
|
}, t.senderEd25519PrivateKey);
|
|
3660
3668
|
}
|
|
3661
|
-
async function
|
|
3662
|
-
if (!await
|
|
3669
|
+
async function di(e, t) {
|
|
3670
|
+
if (!await w(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
|
|
3663
3671
|
return {
|
|
3664
3672
|
envelope: e,
|
|
3665
|
-
body:
|
|
3673
|
+
body: li(e.body.content, t.recipientX25519PrivateKey)
|
|
3666
3674
|
};
|
|
3667
3675
|
}
|
|
3668
3676
|
//#endregion
|
|
3669
|
-
export { ot as AgentSession, st as AipAgentAdapter, Mr as CAP_HEADER,
|
|
3677
|
+
export { ot as AgentSession, st as AipAgentAdapter, Mr as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Rt as ClusterRedisReplayStore, En as DEFAULT_HEADER, xe as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Re as DistributedReplayCache, ur as GRPC_METADATA_KEY, qr as InMemoryAuditLog, It as InMemoryRedisLikeClient, k as InMemoryReplayCache, Ut as InMemoryRevocationStore, ze as InMemoryVerificationMaterialCache, vr as KeyRotationManager, _e as MAX_TTL_MS, Jr as NoopAuditLog, Ur as Protocol7h3Gateway, kr as Protocol7h3Metrics, wr as RESPONSE_HEADER, Lt as RedisReplayStore, yr as RevocationRegistry, it as RollingKeyring, Mt as RuntimePolicyManager, Un as STREAM_HEADER, Xe as SessionTransport, er as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Or as SimpleHistogram, br as SlidingWindowRateLimiter, Nn as WEBHOOK_DEFAULT_TTL_MS, L as WEBHOOK_SIG_HEADER, R as WEBHOOK_TS_HEADER, j as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, zn as consumeWebhook, ct as createAipAgentAdapter, et as createAipCapabilities, At as createAipMcpGatewayRuntime, jt as createAipMcpGatewayRuntimeWithPolicy, Yr as createAuditLog, rn as createCachingKeyRegistry, Vt as createClusterReplayStore, nn as createCompositeKeyRegistry, E as createEnvelope, Wr as createGateway, _r as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, An as createHttpMiddleware, at as createKeyringSignatureResolver, Jt as createMcpClientCodec, jr as createMetricsMiddleware, wt as createPolicyEnforcer, Gr as createProductionGateway, mt as createRawTaskFromJsonRpc, lt as createRawTaskFromLangChain, dt as createRawTaskFromLlamaIndex, zt as createRedisReplayStore, Wt as createRedisRevocationStore, Mn as createSignedFetchRequest, Ze as createSignedMessage, tr as createSignedStream, cr as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, nr as createStreamVerifier, Sn as decodeCbor, Ge as decodeEnvelope, Je as decodeEnvelopeBatch, Ie as decodeEnvelopeBinary, Tn as decodeEnvelopeCbor, or as decodeStreamChunk, li as decryptBody, Lr as delegateCapabilityToken, si as deriveEncryptionKey, tt as encodeAipCapabilities, xn as encodeCbor, Ke as encodeEnvelope, qe as encodeEnvelopeBatch, Fe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, ar as encodeStreamChunk, ci as encryptBody, gr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, oi as generateX25519KeyPair, Qr as getOtelTracer, Pt as getRuntimeTuningPreset, xr as globalRateLimiter, Cr as isAllowedSender, Tt as isRuntimeMode, Pr as issueCapabilityToken, xt as loadRuntimePolicy, J as matchGlob, Sr as matchPolicy, Z as metrics, rt as negotiateAipCapabilities, di as openEnvelope, nt as parseAipCapabilities, Hr as parseCapabilityChain, yt as parseRuntimePolicyJson, hr as parseWellKnownKeys, y as randomHex, A as receiveEnvelope, Ye as receiveEnvelopeBatch, lr as receiveSignedWebSocketStream, Ft as recommendPolicyAdjustments, Ar as renderPrometheusText, ui as sealEnvelope, Vr as serializeCapabilityChain, Zt as serveMcpOverStdio, mr as serveWellKnownKeys, Zr as setOtelProvider, b as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, C as signEnvelopeEd25519, me as signEnvelopeHmac, jn as signFetchRequest, dr as signGrpcCall, On as signHttpRequest, kn as signHttpRequestHmac, Bn as signQueueMessage, Tr as signResponse, rr as signStream, Fn as signWebhook, In as signWebhookHmac, ht as toJsonRpcResponse, ut as toLangChainMessage, ft as toLlamaIndexMessage, Br as tokenMatchesScope, T as validateEnvelope, vt as validateRuntimePolicy, x as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, ge as verifyCanonicalPayloadSignature, zr as verifyCapabilityChain, Rr as verifyCapabilityToken, w as verifyEnvelopeEd25519, S as verifyEnvelopeHmac, he as verifyEnvelopeSignature, fr as verifyGrpcCall, Dn as verifyHttpEnvelope, Hn as verifyQueueBatch, Vn as verifyQueueMessage, Er as verifyResponse, ir as verifyStream, Ln as verifyWebhook, Rn as verifyWebhookHmac, ei as withAuditSpan, pr as withGrpcVerification, Gt as withRevocationCheck, $r as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, sr as wrapWebSocket };
|