@tpsdev-ai/agent 0.5.4 → 0.7.0
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/dist/bin.js +47 -2
- package/dist/bin.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/io/flair.d.ts +53 -0
- package/dist/io/flair.d.ts.map +1 -0
- package/dist/io/flair.js +157 -0
- package/dist/io/flair.js.map +1 -0
- package/dist/io/mail.d.ts +39 -2
- package/dist/io/mail.d.ts.map +1 -1
- package/dist/io/mail.js +303 -15
- package/dist/io/mail.js.map +1 -1
- package/dist/lib/signEnvelope.d.ts +67 -0
- package/dist/lib/signEnvelope.d.ts.map +1 -0
- package/dist/lib/signEnvelope.js +244 -0
- package/dist/lib/signEnvelope.js.map +1 -0
- package/dist/llm/provider.d.ts +19 -1
- package/dist/llm/provider.d.ts.map +1 -1
- package/dist/llm/provider.js +362 -18
- package/dist/llm/provider.js.map +1 -1
- package/dist/runtime/agent.d.ts +2 -0
- package/dist/runtime/agent.d.ts.map +1 -1
- package/dist/runtime/agent.js +53 -3
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/event-loop.d.ts +36 -5
- package/dist/runtime/event-loop.d.ts.map +1 -1
- package/dist/runtime/event-loop.js +235 -32
- package/dist/runtime/event-loop.js.map +1 -1
- package/dist/runtime/types.d.ts +16 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/telemetry/events.d.ts +57 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/events.js +37 -0
- package/dist/telemetry/events.js.map +1 -0
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +94 -16
- package/dist/tools/edit.js.map +1 -1
- package/package.json +10 -2
- package/src/bin.ts +56 -3
- package/src/config.ts +10 -1
- package/src/index.ts +8 -0
- package/src/io/flair.ts +197 -0
- package/src/io/mail.ts +341 -19
- package/src/lib/signEnvelope.ts +332 -0
- package/src/llm/provider.ts +391 -17
- package/src/runtime/agent.ts +58 -3
- package/src/runtime/event-loop.ts +233 -15
- package/src/runtime/types.ts +20 -1
- package/src/telemetry/events.ts +101 -0
- package/src/tools/edit.ts +108 -17
- package/test/bin-launch-id.test.ts +104 -0
- package/test/core-loop.test.ts +240 -0
- package/test/events.test.ts +33 -0
- package/test/flair-context.test.ts +102 -0
- package/test/governance.test.ts +103 -2
- package/test/io.test.ts +13 -14
- package/test/mail-promote-guard.test.ts +325 -0
- package/test/provider.test.ts +43 -0
package/dist/io/mail.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, renameSync, readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, renameSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { sanitizeError } from "../telemetry/events.js";
|
|
4
|
+
import { verifyEnvelope } from "../lib/signEnvelope.js";
|
|
5
|
+
/**
|
|
6
|
+
* The stable reason string `verifyEnvelope` returns when an agent-kind chain
|
|
7
|
+
* entry or `envelope.from` cannot be resolved from the LOCAL Flair. An ABSENT
|
|
8
|
+
* principal is a topology condition, not a forgery verdict, so it is labelled
|
|
9
|
+
* `unresolvable-principal` rather than `invalid`. Duplicated from the shared
|
|
10
|
+
* promotion boundary because `@tpsdev-ai/agent` cannot import `packages/cli`
|
|
11
|
+
* (the dependency runs the other way: cli → agent).
|
|
12
|
+
*/
|
|
13
|
+
const UNRESOLVABLE_PRINCIPAL_REASON_RE = /^agent (.+) not found in Flair$/;
|
|
14
|
+
/**
|
|
15
|
+
* Write the dlq sidecar for a TERMINAL rejection.
|
|
16
|
+
*
|
|
17
|
+
* It mirrors the shared mail convention's FORMAT — file name `<record>.reason`
|
|
18
|
+
* and a first line `class: <class>`, the shape the shared re-drive's
|
|
19
|
+
* `readReasonSidecar` parses — and reuses the shared class NAMES. It does NOT
|
|
20
|
+
* reproduce the shared reject boundary: only the terminal classes above are
|
|
21
|
+
* emitted, and a retryable outcome (Flair unreachable) writes NO sidecar at all
|
|
22
|
+
* (the record is left in `new/`). So it is "format + the terminal class names
|
|
23
|
+
* this path emits", not the full boundary. (This path previously wrote
|
|
24
|
+
* `${file}.reject` with a bare reason, which no shared reader scans.)
|
|
25
|
+
*/
|
|
26
|
+
function writeRejectSidecar(dlqDir, filename, cls, reason) {
|
|
27
|
+
writeFileSync(join(dlqDir, `${filename}.reason`), `class: ${cls}\nPromote rejected at ${new Date().toISOString()}\nReason: ${reason}\n`, "utf-8");
|
|
28
|
+
}
|
|
3
29
|
/**
|
|
4
30
|
* Maildir-compatible mail client.
|
|
5
31
|
* Reads from mailDir/inbox/new and moves processed messages to mailDir/inbox/cur.
|
|
@@ -7,39 +33,301 @@ import { join } from "node:path";
|
|
|
7
33
|
*/
|
|
8
34
|
export class MailClient {
|
|
9
35
|
mailDir;
|
|
36
|
+
events;
|
|
37
|
+
agentId;
|
|
38
|
+
flairClient;
|
|
10
39
|
inboxNew;
|
|
11
40
|
inboxCur;
|
|
41
|
+
inboxDlq;
|
|
12
42
|
outboxNew;
|
|
13
|
-
|
|
43
|
+
/** One-shot guard so a misconfigured (verifier-less) mailbox warns once, not per poll. */
|
|
44
|
+
warnedNoVerifier = false;
|
|
45
|
+
constructor(mailDir, events, agentId = "unknown", flairClient) {
|
|
14
46
|
this.mailDir = mailDir;
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
this.events = events;
|
|
48
|
+
this.agentId = agentId;
|
|
49
|
+
this.flairClient = flairClient;
|
|
50
|
+
this.inboxNew = join(mailDir, agentId, "new");
|
|
51
|
+
this.inboxCur = join(mailDir, agentId, "cur");
|
|
52
|
+
this.inboxDlq = join(mailDir, agentId, "dlq");
|
|
53
|
+
this.outboxNew = join(mailDir, agentId, "outbox");
|
|
54
|
+
for (const dir of [this.inboxNew, this.inboxCur, this.inboxDlq, this.outboxNew]) {
|
|
20
55
|
mkdirSync(dir, { recursive: true });
|
|
21
56
|
}
|
|
22
57
|
}
|
|
23
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Return all messages in inbox/new and move them to inbox/cur/.
|
|
60
|
+
*
|
|
61
|
+
* Verification is MANDATORY — a record is promoted ONLY after its signed
|
|
62
|
+
* envelope verifies against the local Flair. There is no unverified path:
|
|
63
|
+
* - NO verifier configured → refuse; the record stays in new/ (an absent
|
|
64
|
+
* client must never mean "promote without verifying");
|
|
65
|
+
* - the verifier THROWS (Flair unreachable) → refuse; the record stays in
|
|
66
|
+
* new/ for a later check (a throw must never mean "pass");
|
|
67
|
+
* - the verifier REJECTS → dead-letter to dlq/ with a `.reason` sidecar.
|
|
68
|
+
* Unverified input must never reach the tool-holding model.
|
|
69
|
+
*/
|
|
24
70
|
async checkNewMail() {
|
|
25
71
|
if (!existsSync(this.inboxNew))
|
|
26
72
|
return [];
|
|
27
73
|
const files = readdirSync(this.inboxNew).filter((f) => !f.startsWith(".") && !f.includes("/") && !f.includes("\\"));
|
|
28
74
|
const messages = [];
|
|
75
|
+
// No verifier → NOTHING is promotable. Refuse (never rename into cur/) and
|
|
76
|
+
// leave the records in new/ so a later check with a verifier — or the
|
|
77
|
+
// shared promote() path — can process them.
|
|
78
|
+
if (!this.flairClient) {
|
|
79
|
+
if (files.length === 0)
|
|
80
|
+
return [];
|
|
81
|
+
this.events?.emit({
|
|
82
|
+
type: "mail.receive",
|
|
83
|
+
agent: this.agentId,
|
|
84
|
+
status: "rejected",
|
|
85
|
+
from: "unknown",
|
|
86
|
+
durationMs: 0,
|
|
87
|
+
error: "no verifier configured — refusing to promote unverified mail",
|
|
88
|
+
});
|
|
89
|
+
if (!this.warnedNoVerifier) {
|
|
90
|
+
this.warnedNoVerifier = true;
|
|
91
|
+
console.error(`[MailClient] no Flair verifier configured for "${this.agentId}": refusing to promote ` +
|
|
92
|
+
`${files.length} unverified message(s) from new/. Unverified input must never reach the ` +
|
|
93
|
+
`model — configure flair (url + key) or promote through the shared promote() lifecycle.`);
|
|
94
|
+
}
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
29
97
|
for (const file of files) {
|
|
98
|
+
const started = Date.now();
|
|
30
99
|
const srcPath = join(this.inboxNew, file);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
100
|
+
let body;
|
|
101
|
+
try {
|
|
102
|
+
body = readFileSync(srcPath, "utf-8");
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
this.events?.emit({
|
|
106
|
+
type: "mail.receive",
|
|
107
|
+
agent: this.agentId,
|
|
108
|
+
status: "error",
|
|
109
|
+
from: "unknown",
|
|
110
|
+
durationMs: Date.now() - started,
|
|
111
|
+
error: sanitizeError(err),
|
|
112
|
+
});
|
|
113
|
+
continue; // leave in new/ — a later check retries
|
|
114
|
+
}
|
|
115
|
+
// Verify. A THROW is a refusal, not a pass: leave the record in new/ for a
|
|
116
|
+
// later check (a Flair outage self-heals) and never promote it.
|
|
117
|
+
let verifyResult;
|
|
118
|
+
try {
|
|
119
|
+
verifyResult = await this.verifyMailBody(body);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const detail = sanitizeError(err);
|
|
123
|
+
this.events?.emit({
|
|
124
|
+
type: "mail.receive",
|
|
125
|
+
agent: this.agentId,
|
|
126
|
+
status: "error",
|
|
127
|
+
from: "unknown",
|
|
128
|
+
durationMs: Date.now() - started,
|
|
129
|
+
error: detail,
|
|
130
|
+
});
|
|
131
|
+
console.error(`[MailClient] verification could not run for ${file} — NOT promoting: ${detail}`);
|
|
132
|
+
continue; // leave in new/
|
|
133
|
+
}
|
|
134
|
+
if (!verifyResult.pass) {
|
|
135
|
+
const dlqPath = join(this.inboxDlq, file);
|
|
136
|
+
try {
|
|
137
|
+
if (srcPath !== dlqPath)
|
|
138
|
+
renameSync(srcPath, dlqPath);
|
|
139
|
+
writeRejectSidecar(this.inboxDlq, file, verifyResult.class, verifyResult.reason);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
console.error(`[MailClient] failed to dead-letter ${file}: ${sanitizeError(err)}`);
|
|
143
|
+
}
|
|
144
|
+
this.events?.emit({
|
|
145
|
+
type: "mail.receive",
|
|
146
|
+
agent: this.agentId,
|
|
147
|
+
status: "rejected",
|
|
148
|
+
from: verifyResult.from ?? "unknown",
|
|
149
|
+
durationMs: Date.now() - started,
|
|
150
|
+
error: verifyResult.reason,
|
|
151
|
+
});
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
// Promote to cur/ — verified, and addressed to this mailbox.
|
|
155
|
+
try {
|
|
156
|
+
const dstPath = join(this.inboxCur, file);
|
|
157
|
+
renameSync(srcPath, dstPath);
|
|
158
|
+
let headers = {};
|
|
159
|
+
let from = "unknown";
|
|
160
|
+
try {
|
|
161
|
+
const parsed = JSON.parse(body);
|
|
162
|
+
headers = parsed.headers ?? {};
|
|
163
|
+
from = parsed.from ?? "unknown";
|
|
164
|
+
}
|
|
165
|
+
catch { }
|
|
166
|
+
messages.push({ filename: file, body, receivedAt: new Date(), headers, from });
|
|
167
|
+
this.events?.emit({
|
|
168
|
+
type: "mail.receive",
|
|
169
|
+
agent: this.agentId,
|
|
170
|
+
status: "ok",
|
|
171
|
+
from,
|
|
172
|
+
durationMs: Date.now() - started,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
this.events?.emit({
|
|
177
|
+
type: "mail.receive",
|
|
178
|
+
agent: this.agentId,
|
|
179
|
+
status: "error",
|
|
180
|
+
from: "unknown",
|
|
181
|
+
durationMs: Date.now() - started,
|
|
182
|
+
error: sanitizeError(err),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
35
185
|
}
|
|
36
186
|
return messages;
|
|
37
187
|
}
|
|
38
188
|
/** Write a message to outbox/new for relay delivery. */
|
|
39
189
|
async sendMail(to, body) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
190
|
+
const started = Date.now();
|
|
191
|
+
try {
|
|
192
|
+
const { writeFileSync } = await import("node:fs");
|
|
193
|
+
const filename = `${Date.now()}-${Math.random().toString(36).slice(2)}.json`;
|
|
194
|
+
writeFileSync(join(this.outboxNew, filename), JSON.stringify({ to, body, sentAt: new Date().toISOString() }, null, 2), "utf-8");
|
|
195
|
+
this.events?.emit({
|
|
196
|
+
type: "mail.send",
|
|
197
|
+
agent: this.agentId,
|
|
198
|
+
to,
|
|
199
|
+
status: "ok",
|
|
200
|
+
durationMs: Date.now() - started,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
this.events?.emit({
|
|
205
|
+
type: "mail.send",
|
|
206
|
+
agent: this.agentId,
|
|
207
|
+
to,
|
|
208
|
+
status: "error",
|
|
209
|
+
durationMs: Date.now() - started,
|
|
210
|
+
error: sanitizeError(err),
|
|
211
|
+
});
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Deliver all messages in outbox to recipient inboxes (local relay). */
|
|
216
|
+
deliverOutbox() {
|
|
217
|
+
if (!existsSync(this.outboxNew))
|
|
218
|
+
return;
|
|
219
|
+
const files = readdirSync(this.outboxNew).filter(f => !f.startsWith("."));
|
|
220
|
+
for (const file of files) {
|
|
221
|
+
const srcPath = join(this.outboxNew, file);
|
|
222
|
+
try {
|
|
223
|
+
const raw = readFileSync(srcPath, "utf-8");
|
|
224
|
+
const msg = JSON.parse(raw);
|
|
225
|
+
if (!msg.to || !/^[a-zA-Z0-9_-]{1,64}$/.test(msg.to)) {
|
|
226
|
+
continue; // skip invalid recipients
|
|
227
|
+
}
|
|
228
|
+
const recipientInbox = join(this.mailDir, msg.to, "new");
|
|
229
|
+
mkdirSync(recipientInbox, { recursive: true });
|
|
230
|
+
const destFile = `${msg.sentAt.replace(/[:.]/g, "-")}-${file}`;
|
|
231
|
+
renameSync(srcPath, join(recipientInbox, destFile));
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// Leave in outbox on error
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Verify a mail body against the v1 signed envelope spec AND this mailbox's
|
|
240
|
+
* policy: signature, wrapper→envelope `from` binding, recipient binding
|
|
241
|
+
* (`envelope.to` must be this mailbox's agent), and `messageId`/`timestamp`
|
|
242
|
+
* shape. These are the checks the shared `promote()` applies, so this path
|
|
243
|
+
* cannot present mail the shared path would reject.
|
|
244
|
+
*
|
|
245
|
+
* Returns a terminal `{ pass: false, class, reason }` on a deterministic
|
|
246
|
+
* rejection. Called ONLY when a verifier is configured; a THROW (Flair
|
|
247
|
+
* unreachable) is a refusal the caller acts on, never a pass.
|
|
248
|
+
*/
|
|
249
|
+
async verifyMailBody(body) {
|
|
250
|
+
const client = this.flairClient;
|
|
251
|
+
// 1. Parse the mail file as JSON
|
|
252
|
+
let mailMsg;
|
|
253
|
+
try {
|
|
254
|
+
mailMsg = JSON.parse(body);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return { pass: false, class: "invalid", reason: "json parse error: invalid JSON" };
|
|
258
|
+
}
|
|
259
|
+
if (!mailMsg.body || typeof mailMsg.body !== "string") {
|
|
260
|
+
return { pass: false, class: "invalid", reason: "json parse error: missing body field" };
|
|
261
|
+
}
|
|
262
|
+
// 2. Parse the body field as an envelope
|
|
263
|
+
let envelope;
|
|
264
|
+
try {
|
|
265
|
+
envelope = JSON.parse(mailMsg.body);
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return { pass: false, class: "invalid", reason: "json parse error: invalid envelope body", from: mailMsg.from };
|
|
269
|
+
}
|
|
270
|
+
if (envelope == null || typeof envelope !== "object" || Array.isArray(envelope)) {
|
|
271
|
+
return { pass: false, class: "invalid", reason: "unsigned envelope (v1 required)", from: mailMsg.from };
|
|
272
|
+
}
|
|
273
|
+
const env = envelope;
|
|
274
|
+
if (typeof env.v !== "number" ||
|
|
275
|
+
!Array.isArray(env.delegationChain) ||
|
|
276
|
+
typeof env.signature !== "string") {
|
|
277
|
+
return { pass: false, class: "invalid", reason: "unsigned envelope (v1 required)", from: mailMsg.from };
|
|
278
|
+
}
|
|
279
|
+
// 3. Verify the signature. A THROW here (Flair unreachable) is NOT a pass —
|
|
280
|
+
// it propagates to checkNewMail(), which refuses to promote and leaves
|
|
281
|
+
// the record in new/ for a later check. The verifier adapter throws on an
|
|
282
|
+
// outage, so an outage is RETRYABLE rather than a terminal "not found".
|
|
283
|
+
const vr = await verifyEnvelope(env, client);
|
|
284
|
+
if (!vr.ok) {
|
|
285
|
+
const cls = UNRESOLVABLE_PRINCIPAL_REASON_RE.test(vr.reason)
|
|
286
|
+
? "unresolvable-principal"
|
|
287
|
+
: "invalid";
|
|
288
|
+
return { pass: false, class: cls, reason: vr.reason, from: mailMsg.from };
|
|
289
|
+
}
|
|
290
|
+
// 4. The wrapper `from` is what consumers route by, and it is unverified; a
|
|
291
|
+
// wrapper/envelope mismatch is itself a reject.
|
|
292
|
+
if (mailMsg.from !== env.from) {
|
|
293
|
+
return {
|
|
294
|
+
pass: false,
|
|
295
|
+
class: "invalid",
|
|
296
|
+
reason: `wrapper/envelope from mismatch (wrapper.from=${String(mailMsg.from)}, envelope.from=${String(env.from)})`,
|
|
297
|
+
from: mailMsg.from,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// 5. Recipient binding. A signature is NOT recipient-bound, so a correctly
|
|
301
|
+
// signed envelope addressed to another principal must not be presented
|
|
302
|
+
// here (deliverOutbox writes into any recipient's new/).
|
|
303
|
+
if (env.to !== this.agentId) {
|
|
304
|
+
return {
|
|
305
|
+
pass: false,
|
|
306
|
+
class: "wrong-recipient",
|
|
307
|
+
reason: `wrong-recipient (envelope.to=${String(env.to)}, mailbox=${this.agentId})`,
|
|
308
|
+
from: mailMsg.from,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// 6. `messageId` shape.
|
|
312
|
+
if (typeof env.messageId !== "string" || env.messageId.trim() === "") {
|
|
313
|
+
return {
|
|
314
|
+
pass: false,
|
|
315
|
+
class: "invalid",
|
|
316
|
+
reason: `invalid messageId (must be a non-empty string, got ${JSON.stringify(env.messageId)})`,
|
|
317
|
+
from: mailMsg.from,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// 7. `timestamp` shape — a malformed/absent timestamp must not be silently
|
|
321
|
+
// accepted (the shared path rejects it too).
|
|
322
|
+
if (typeof env.timestamp !== "string" || Number.isNaN(Date.parse(env.timestamp))) {
|
|
323
|
+
return {
|
|
324
|
+
pass: false,
|
|
325
|
+
class: "invalid",
|
|
326
|
+
reason: `invalid timestamp (must be an ISO-8601 string, got ${JSON.stringify(env.timestamp)})`,
|
|
327
|
+
from: mailMsg.from,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return { pass: true };
|
|
43
331
|
}
|
|
44
332
|
}
|
|
45
333
|
//# sourceMappingURL=mail.js.map
|
package/dist/io/mail.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail.js","sourceRoot":"","sources":["../../src/io/mail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"mail.js","sourceRoot":"","sources":["../../src/io/mail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,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C,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACjF,OAAO;gBACL,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,SAAS;gBAChB,MAAM,EAAE,sDAAsD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG;gBAC9F,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* signEnvelope — Ed25519 signature over TPS mail envelope + delegation chain.
|
|
3
|
+
*
|
|
4
|
+
* Signs every agent-kind entry in the delegation chain whose signature is
|
|
5
|
+
* null/missing, then signs the outer envelope. Uses JCS (RFC 8785)
|
|
6
|
+
* canonicalization for deterministic byte-level signing input.
|
|
7
|
+
*/
|
|
8
|
+
export interface ChainEntry {
|
|
9
|
+
agent: string;
|
|
10
|
+
kind: "human" | "agent";
|
|
11
|
+
timestamp: string;
|
|
12
|
+
rationale: string;
|
|
13
|
+
signature: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface Envelope {
|
|
16
|
+
v: number;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
subject?: string;
|
|
20
|
+
body: string;
|
|
21
|
+
messageId: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
delegationChain: ChainEntry[];
|
|
24
|
+
signature?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sign an envelope:
|
|
28
|
+
* - For each agent-kind chain entry whose signature is null/missing, generate
|
|
29
|
+
* sig over jcs({ prior: chain[0..i], entry: { ...entry, signature: undefined } })
|
|
30
|
+
* using the agent's privkey.
|
|
31
|
+
* - Then compute outer sig over jcs({ ...envelope, signature: undefined })
|
|
32
|
+
* using the LAST chain entry's privkey (which must equal envelope.from).
|
|
33
|
+
*
|
|
34
|
+
* Caller passes privkeys by agent name. For PR-1 simplicity, accept a map:
|
|
35
|
+
* keysByAgent: { [agentName: string]: Buffer (32-byte Ed25519 seed) }
|
|
36
|
+
*
|
|
37
|
+
* Returns envelope with chain entry sigs and outer sig populated.
|
|
38
|
+
* Mutates a copy, does not mutate input.
|
|
39
|
+
*/
|
|
40
|
+
export declare function signEnvelope(envelope: Envelope, keysByAgent: Record<string, Buffer>): Envelope;
|
|
41
|
+
export interface FlairClient {
|
|
42
|
+
getAgent(name: string): Promise<{
|
|
43
|
+
publicKey: Buffer;
|
|
44
|
+
} | null>;
|
|
45
|
+
}
|
|
46
|
+
export interface VerifyOk {
|
|
47
|
+
ok: true;
|
|
48
|
+
}
|
|
49
|
+
export interface VerifyReject {
|
|
50
|
+
ok: false;
|
|
51
|
+
reason: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Verify a signed envelope:
|
|
55
|
+
* - v must be 1
|
|
56
|
+
* - delegationChain must be non-empty and length <= 16
|
|
57
|
+
* - last chain entry's agent must equal envelope.from
|
|
58
|
+
* - outer signature must verify against envelope.from's pubkey over
|
|
59
|
+
* jcs({ ...envelope, signature: undefined })
|
|
60
|
+
* - each agent-kind chain entry's signature must verify against that
|
|
61
|
+
* agent's pubkey over jcs({ prior: chain[0..i], entry: { ...entry, signature: undefined } })
|
|
62
|
+
* - each human-kind entry must have signature === null
|
|
63
|
+
*
|
|
64
|
+
* Pure function with DI'd flairClient — no Flair HTTP coupling.
|
|
65
|
+
*/
|
|
66
|
+
export declare function verifyEnvelope(envelope: Envelope, flairClient: FlairClient): Promise<VerifyOk | VerifyReject>;
|
|
67
|
+
//# sourceMappingURL=signEnvelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signEnvelope.d.ts","sourceRoot":"","sources":["../../src/lib/signEnvelope.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAA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