@agent-custody/receipts 0.16.5 → 0.16.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +29 -13
  2. package/dist/capture.d.ts +2 -0
  3. package/dist/capture.js +13 -2
  4. package/dist/check.d.ts +1 -1
  5. package/dist/check.js +34 -10
  6. package/dist/cli.js +54 -9
  7. package/dist/config.d.ts +27 -2
  8. package/dist/config.js +66 -2
  9. package/dist/console-page.js +144 -50
  10. package/dist/deny-report.d.ts +7 -0
  11. package/dist/deny-report.js +8 -3
  12. package/dist/design.d.ts +11 -0
  13. package/dist/design.js +91 -0
  14. package/dist/door-app.d.ts +28 -0
  15. package/dist/door-app.js +244 -0
  16. package/dist/door-partner.d.ts +66 -0
  17. package/dist/door-partner.js +94 -0
  18. package/dist/door.d.ts +139 -10
  19. package/dist/door.js +297 -137
  20. package/dist/gateway-http.d.ts +1 -1
  21. package/dist/index.d.ts +8 -2
  22. package/dist/index.js +5 -1
  23. package/dist/log-admin.js +100 -59
  24. package/dist/log-store.d.ts +8 -2
  25. package/dist/log-store.js +22 -12
  26. package/dist/perathos.d.ts +50 -0
  27. package/dist/perathos.js +188 -0
  28. package/dist/portal.d.ts +66 -5
  29. package/dist/portal.js +895 -242
  30. package/dist/receipt.d.ts +4 -1
  31. package/dist/session-audit.d.ts +46 -0
  32. package/dist/session-audit.js +150 -0
  33. package/dist/site-links.d.ts +23 -0
  34. package/dist/site-links.js +29 -0
  35. package/dist/verify.js +44 -4
  36. package/dist/web-bot-auth.d.ts +105 -0
  37. package/dist/web-bot-auth.js +508 -0
  38. package/docs/acs.md +2 -0
  39. package/docs/approvals.md +1 -1
  40. package/docs/completeness.md +1 -1
  41. package/docs/configuration.md +2 -0
  42. package/docs/console.md +11 -2
  43. package/docs/door-languages.md +168 -0
  44. package/docs/door-middleware.md +216 -0
  45. package/docs/door-quickstart.md +1 -1
  46. package/docs/door-signals.md +43 -6
  47. package/docs/door.md +129 -32
  48. package/docs/egress.md +3 -1
  49. package/docs/github-action.md +2 -2
  50. package/docs/mandates.md +1 -1
  51. package/docs/perathos.md +100 -0
  52. package/docs/sdk.md +32 -1
  53. package/docs/threat-model.md +2 -1
  54. package/docs/tutorials.md +6 -0
  55. package/docs/usage.md +3 -1
  56. package/docs/verification.md +3 -1
  57. package/package.json +7 -1
  58. package/vectors/audit.json +27 -27
  59. package/vectors/canonical.json +5 -5
  60. package/vectors/interop/perathos/LICENSE +21 -0
  61. package/vectors/interop/perathos/README.md +17 -0
  62. package/vectors/interop/perathos/pocketos-replay/session.head.json +11 -0
  63. package/vectors/interop/perathos/pocketos-replay/session.jsonl +8 -0
  64. package/vectors/interop/perathos/pocketos-replay/verification.json +65 -0
  65. package/vectors/receipts.json +1701 -1210
package/dist/receipt.d.ts CHANGED
@@ -36,7 +36,10 @@ export interface FactRecord {
36
36
  value: unknown;
37
37
  /** the digest of the lookup's full result; under a capture rule a commitment to that result (the receipt shows only the selected value, the rest is private), named in the `capture` note */
38
38
  resultDigest: string | Commitment;
39
- provenance: "observed";
39
+ /** `attested` only when `attestation` carries its source's signature over `value` for this receipt and tool, checked by the issuer; a verifier checks it again under the source's key */
40
+ provenance: "observed" | "attested";
41
+ /** the source's attestation envelope (upstream.ts format, over the digest of `value`); the door's partner verdict carries one. Withheld unless it is exactly that plain attestation beside a value in clear */
42
+ attestation?: Envelope | Commitment;
40
43
  }
41
44
  /** A gateway's durable financial operation identity; execution still describes only the tool/API call. */
42
45
  export interface OperationEvidence {
@@ -0,0 +1,46 @@
1
+ export interface AuditedCall {
2
+ session: string;
3
+ /** the last part of the working directory the session ran in */
4
+ project: string;
5
+ timestamp: string;
6
+ tool: string;
7
+ target: string;
8
+ policyIds: string[];
9
+ reasons: string[];
10
+ rules: string[];
11
+ }
12
+ export interface SessionAudit {
13
+ dir: string;
14
+ since: string | null;
15
+ policy: string;
16
+ policyDigest: string;
17
+ transcripts: number;
18
+ sessions: number;
19
+ calls: number;
20
+ denied: AuditedCall[];
21
+ /** calls that no forbid matched but on which a rule errored (a value Cedar cannot hold, an attribute the call lacks); the hook denies these, and they are listed apart because no rule decided them. A call a forbid matched is in `denied` even when another rule errored on it */
22
+ unevaluated: {
23
+ tool: string;
24
+ target: string;
25
+ errors: string[];
26
+ }[];
27
+ /** lines that were not JSON; a transcript being written can end in a partial line */
28
+ unreadable: number;
29
+ }
30
+ export interface SessionAuditOptions {
31
+ /** the directory of Claude Code's per-project transcripts */
32
+ dir: string;
33
+ policyText: string;
34
+ /** shown in the result; the policy file's path, or "the init claude-code template" */
35
+ policyName: string;
36
+ since?: Date;
37
+ }
38
+ /** Claude Code's transcripts: `$CLAUDE_CONFIG_DIR/projects` when that is set, else `~/.claude/projects`. */
39
+ export declare function defaultTranscriptDir(env?: NodeJS.ProcessEnv): string;
40
+ /** `7d`, `24h`, `30m`, or a date or date-time that Date can read. */
41
+ export declare function parseSince(text: string, now?: Date): Date;
42
+ export declare function auditSessions(o: SessionAuditOptions): SessionAudit;
43
+ /** The audit as text. `counts` leaves out every command, path, session, and project, so the output can be shared. */
44
+ export declare function formatSessionAudit(a: SessionAudit, opts?: {
45
+ counts?: boolean;
46
+ }): string;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * `agent-custody audit-sessions`: which of a developer's past Claude Code tool calls a Cedar policy would have denied,
3
+ * read from the session transcripts Claude Code keeps on the machine. It installs nothing, writes nothing, and makes no
4
+ * network request, so it can run before anyone decides to install the hooks.
5
+ *
6
+ * A transcript is the agent host's own account and anyone with the files can edit it: the result is a preview of what
7
+ * the policy would catch, not evidence. Receipts come from the hooks that `init claude-code` installs.
8
+ */
9
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
10
+ import { homedir } from "node:os";
11
+ import { basename, join } from "node:path";
12
+ import { ruleTexts, targetOf } from "./deny-report.js";
13
+ import { evaluate, policyDigest, policyParseErrors, policyReasons, policyRules } from "./policy.js";
14
+ /** Claude Code's transcripts: `$CLAUDE_CONFIG_DIR/projects` when that is set, else `~/.claude/projects`. */
15
+ export function defaultTranscriptDir(env = process.env) {
16
+ return env.CLAUDE_CONFIG_DIR ? join(env.CLAUDE_CONFIG_DIR, "projects") : join(homedir(), ".claude", "projects");
17
+ }
18
+ /** `7d`, `24h`, `30m`, or a date or date-time that Date can read. */
19
+ export function parseSince(text, now = new Date()) {
20
+ const rel = /^(\d+)([dhm])$/.exec(text.trim());
21
+ if (rel)
22
+ return new Date(now.getTime() - Number(rel[1]) * { d: 86_400_000, h: 3_600_000, m: 60_000 }[rel[2]]);
23
+ const t = Date.parse(text);
24
+ if (Number.isNaN(t))
25
+ throw new Error(`--since takes 7d, 24h, 30m, or a date; got "${text}"`);
26
+ return new Date(t);
27
+ }
28
+ function transcriptsUnder(dir) {
29
+ const out = [];
30
+ const walk = (d) => {
31
+ for (const e of readdirSync(d, { withFileTypes: true })) {
32
+ const p = join(d, e.name);
33
+ if (e.isDirectory())
34
+ walk(p);
35
+ else if (e.isFile() && e.name.endsWith(".jsonl"))
36
+ out.push(p);
37
+ }
38
+ };
39
+ walk(dir);
40
+ return out.sort();
41
+ }
42
+ export function auditSessions(o) {
43
+ if (!existsSync(o.dir))
44
+ throw new Error(`no Claude Code transcripts at ${o.dir}; give another directory with --dir`);
45
+ // a policy that does not parse denies every call with the parse error, which would read as "it catches nothing"
46
+ const parseErrors = policyParseErrors(o.policyText);
47
+ if (parseErrors.length)
48
+ throw new Error(`${o.policyName} does not parse: ${parseErrors.join("; ")}`);
49
+ const rules = policyRules(o.policyText);
50
+ const reasons = policyReasons(o.policyText);
51
+ const since = o.since?.getTime();
52
+ const result = { dir: o.dir, since: o.since?.toISOString() ?? null, policy: o.policyName, policyDigest: policyDigest(o.policyText), transcripts: 0, sessions: 0, calls: 0, denied: [], unevaluated: [], unreadable: 0 };
53
+ const sessions = new Set();
54
+ const seen = new Set();
55
+ for (const file of transcriptsUnder(o.dir)) {
56
+ // a transcript last written before the window holds nothing inside it
57
+ if (since !== undefined && statSync(file).mtimeMs < since)
58
+ continue;
59
+ result.transcripts++;
60
+ for (const line of readFileSync(file, "utf8").split("\n")) {
61
+ if (!line.trim())
62
+ continue;
63
+ let entry;
64
+ try {
65
+ entry = JSON.parse(line);
66
+ }
67
+ catch {
68
+ result.unreadable++;
69
+ continue;
70
+ }
71
+ if (entry.type !== "assistant")
72
+ continue;
73
+ const timestamp = typeof entry.timestamp === "string" ? entry.timestamp : "";
74
+ if (since !== undefined && !(Date.parse(timestamp) >= since))
75
+ continue;
76
+ const content = entry.message?.content;
77
+ if (!Array.isArray(content))
78
+ continue;
79
+ for (const c of content) {
80
+ if (c?.type !== "tool_use" || typeof c.name !== "string")
81
+ continue;
82
+ const id = typeof c.id === "string" ? c.id : `${file}:${timestamp}:${c.name}`;
83
+ if (seen.has(id))
84
+ continue;
85
+ seen.add(id);
86
+ const session = typeof entry.sessionId === "string" ? entry.sessionId : basename(file, ".jsonl");
87
+ sessions.add(session);
88
+ result.calls++;
89
+ const args = c.input && typeof c.input === "object" ? c.input : {};
90
+ const d = evaluate(o.policyText, { agentId: "claude-code", tool: c.name, context: { args, facts: {} } });
91
+ // A rule error turns the decision into deny but keeps Cedar's own reasons, which for an allowed call are permits.
92
+ // So a call is a rule's denial when a forbid matched it, whatever else errored, and unevaluated otherwise.
93
+ const forbids = d.reasons.filter((id) => ruleTexts([id], rules, reasons).rules[0]?.startsWith("forbid"));
94
+ if (d.errors.length && !forbids.length) {
95
+ result.unevaluated.push({ tool: c.name, target: targetOf(args), errors: d.errors });
96
+ continue;
97
+ }
98
+ if (d.decision !== "deny")
99
+ continue;
100
+ const ids = d.errors.length ? forbids : d.reasons;
101
+ result.denied.push({ session, project: typeof entry.cwd === "string" ? basename(entry.cwd) : "", timestamp, tool: c.name, target: targetOf(args), policyIds: ids, ...ruleTexts(ids, rules, reasons) });
102
+ }
103
+ }
104
+ }
105
+ result.sessions = sessions.size;
106
+ result.denied.sort((a, b) => (a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0));
107
+ return result;
108
+ }
109
+ const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
110
+ const clip = (s, n = 160) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
111
+ const NO_PERMIT = "no permit matched (default deny)";
112
+ const PREVIEW = "PREVIEW: these are the agent host's own transcripts, not receipts. Nothing here is signed or logged, and a transcript can be edited. For a receipt of each call, signed and logged, run: agent-custody init claude-code";
113
+ /** The audit as text. `counts` leaves out every command, path, session, and project, so the output can be shared. */
114
+ export function formatSessionAudit(a, opts = {}) {
115
+ const window = a.since ? ` since ${a.since}` : "";
116
+ // --counts is the output people share: the policy's file name, not the path to it
117
+ const policy = opts.counts && a.policy.includes("/") ? basename(a.policy) : a.policy;
118
+ const lines = [`Read ${plural(a.calls, "tool call")} in ${plural(a.sessions, "session")}${window}.`, `Policy: ${policy}.`, ""];
119
+ lines.push(`The policy would have denied ${plural(a.denied.length, "call")}${a.denied.length ? ":" : "."}`);
120
+ if (opts.counts) {
121
+ const byRule = new Map();
122
+ for (const c of a.denied) {
123
+ const key = c.policyIds.join(", ");
124
+ const r = byRule.get(key) ?? { n: 0, reason: c.reasons.join("; ") };
125
+ r.n++;
126
+ byRule.set(key, r);
127
+ }
128
+ for (const [ids, r] of [...byRule].sort((x, y) => y[1].n - x[1].n))
129
+ lines.push(` ${String(r.n).padStart(4)} ${ids || NO_PERMIT}${r.reason ? ` ${r.reason}` : ""}`);
130
+ }
131
+ else {
132
+ for (const c of a.denied) {
133
+ lines.push("", ` ${c.tool}: ${clip(c.target)}`);
134
+ if (c.reasons.length)
135
+ lines.push(` reason: ${c.reasons.join("; ")}`);
136
+ lines.push(` rule: ${!c.policyIds.length ? NO_PERMIT : c.rules.length ? `${clip(c.rules.join(" | "))} [${c.policyIds.join(", ")}]` : c.policyIds.join(", ")}`);
137
+ lines.push(` when: ${c.timestamp} session ${c.session.slice(0, 8)}${c.project ? ` in ${c.project}` : ""}`);
138
+ }
139
+ }
140
+ if (a.unevaluated.length) {
141
+ lines.push("", `${plural(a.unevaluated.length, "more call")} matched no forbid rule, but a rule errored on ${a.unevaluated.length === 1 ? "it" : "them"}, for example on a value Cedar cannot hold (a float) or an attribute the call does not have. The hook denies a call like this; no rule decided it, so it is listed apart:`);
142
+ if (!opts.counts)
143
+ for (const u of a.unevaluated)
144
+ lines.push(` ${u.tool}: ${clip(u.target, 80)} (${clip(u.errors[0] ?? "", 80)})`);
145
+ }
146
+ if (a.unreadable)
147
+ lines.push(`${plural(a.unreadable, "transcript line")} could not be read.`);
148
+ lines.push("", PREVIEW);
149
+ return lines.join("\n");
150
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The website's top nav and footer, in one place. The landing page, the docs pages (site/.vitepress), and the
3
+ * dashboard (portal.ts) all read these lists, so a page cannot carry a menu of its own. Links are site paths; the
4
+ * dashboard runs on another host and prefixes them with SITE_URL. Labels follow site/guide/glossary.md.
5
+ */
6
+ export declare const SITE_URL = "https://agent-custody.dev";
7
+ export declare const DASHBOARD_URL = "https://app.agent-custody.dev/";
8
+ export interface SiteLink {
9
+ text: string;
10
+ link: string;
11
+ /** a regular expression over the path: the nav item is highlighted on every page it matches */
12
+ activeMatch?: string;
13
+ }
14
+ export declare const SITE_NAV: SiteLink[];
15
+ export declare const SIGN_IN: SiteLink;
16
+ export declare const GET_STARTED: SiteLink;
17
+ export declare const SITE_FOOTER: {
18
+ title: string;
19
+ links: SiteLink[];
20
+ }[];
21
+ export declare const SITE_LEGAL_LINKS: SiteLink[];
22
+ /** A site path as an absolute URL, for pages on another host. External links pass through. */
23
+ export declare const siteUrl: (link: string) => string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The website's top nav and footer, in one place. The landing page, the docs pages (site/.vitepress), and the
3
+ * dashboard (portal.ts) all read these lists, so a page cannot carry a menu of its own. Links are site paths; the
4
+ * dashboard runs on another host and prefixes them with SITE_URL. Labels follow site/guide/glossary.md.
5
+ */
6
+ export const SITE_URL = "https://agent-custody.dev";
7
+ export const DASHBOARD_URL = "https://app.agent-custody.dev/";
8
+ export const SITE_NAV = [
9
+ { text: "Product", link: "/" },
10
+ { text: "Docs", link: "/guide/getting-started", activeMatch: "^/(guide|receipts|state|python|reference|receipt)/" },
11
+ { text: "Pricing", link: "/pricing" },
12
+ { text: "Blog", link: "/blog/", activeMatch: "^/blog/" },
13
+ { text: "Verify a receipt", link: "/verify" },
14
+ ];
15
+ export const SIGN_IN = { text: "Sign in", link: DASHBOARD_URL };
16
+ export const GET_STARTED = { text: "Get started", link: "/guide/getting-started" };
17
+ export const SITE_FOOTER = [
18
+ { title: "Product", links: [{ text: "How it works", link: "/how-it-works" }, { text: "Use cases", link: "/use-cases" }, { text: "Pricing", link: "/pricing" }, { text: "Hosted log", link: "/hosted-log" }, { text: "Verify a receipt", link: "/verify" }] },
19
+ { title: "Docs", links: [{ text: "Getting started", link: "/guide/getting-started" }, { text: "Incident replay", link: "/guide/incident-replay" }, { text: "Reference", link: "/reference/" }, { text: "Receipt specification", link: "/receipt/v0.2" }, { text: "Glossary", link: "/guide/glossary" }, { text: "Roadmap", link: "/roadmap" }, { text: "Changelog", link: "/changelog" }] },
20
+ { title: "Trust", links: [{ text: "Status and limits", link: "/status" }, { text: "Security", link: "/security" }, { text: "Where data goes", link: "/faq" }, { text: "Threat model", link: "/receipts/threat-model" }, { text: "This repository", link: "/custody" }] },
21
+ { title: "Company", links: [{ text: "Blog", link: "/blog/" }, { text: "Contact", link: "/contact" }, { text: "Privacy", link: "/privacy" }, { text: "Terms", link: "/terms" }] },
22
+ ];
23
+ export const SITE_LEGAL_LINKS = [
24
+ { text: "GitHub", link: "https://github.com/svayatta/agent-custody" },
25
+ { text: "npm", link: "https://www.npmjs.com/org/agent-custody" },
26
+ { text: "PyPI", link: "https://pypi.org/project/agent-custody/" },
27
+ ];
28
+ /** A site path as an absolute URL, for pages on another host. External links pass through. */
29
+ export const siteUrl = (link) => (/^https?:/.test(link) ? link : SITE_URL + link);
package/dist/verify.js CHANGED
@@ -211,6 +211,11 @@ export function verifyBundle(bundle, opts) {
211
211
  // A door decides every arrival by policy; an arrival carries a grant only when it chose to present one.
212
212
  if (p.issuer.kind === "door")
213
213
  add("door receipt carries a policy decision", p.policy !== null);
214
+ // In authz mode the door answers a proxy's check and relays nothing: the receipt is a decision, never a result.
215
+ if (p.issuer.kind === "door" && p.issuer.framework === "authz") {
216
+ const decided = p.execution.status === "withheld" || (p.execution.status === "denied" && p.policy?.decision === "deny");
217
+ add("door authz decided, relayed nothing", decided, decided ? `${p.policy?.decision}; a decision for the proxy, which relays: the door saw neither the body nor the origin's answer` : `the receipt says ${p.execution.status} with a policy ${p.policy?.decision ?? "absent"}`);
218
+ }
214
219
  // An egress witness saw a connection that went around the gateway: where it went and how much, never what was sent.
215
220
  // Its destination is its own observation; its agent is only as good as the proxy credential it checked.
216
221
  if (p.issuer.kind === "egress") {
@@ -373,6 +378,32 @@ export function verifyBundle(bundle, opts) {
373
378
  const how = back.restored.get(pathKey(w));
374
379
  add(`withheld ${pathText(w)}`, !problem, problem ?? (how ? `holds against the ${how} value` : committedNote([w])));
375
380
  }
381
+ // A fact its source signed (the door's partner verdict): the issuer marks it attested after checking the signature
382
+ // under its configured key, and the reader checks it again under the key it trusts for that source. The signature
383
+ // binds this receipt and route, so a verdict moved from another arrival fails here.
384
+ for (const [name, f] of Object.entries(p.facts)) {
385
+ if (f.provenance !== "attested")
386
+ continue;
387
+ const label = `fact ${name} signature (upstream key)`;
388
+ const value = region(["facts", name, "value"]);
389
+ const envPath = ["facts", name, "attestation"];
390
+ const stillWithheld = (note?.withheld ?? []).some((w) => pathKey(w) === pathKey(envPath)) && back.missing.some((w) => pathKey(w) === pathKey(envPath));
391
+ const restored = full.facts[name];
392
+ const env = restored?.attestation;
393
+ const wellFormed = !!env && typeof env === "object" && typeof env.payload === "string" && Array.isArray(env.signatures);
394
+ if (value.problem || value.missing.length)
395
+ add(`fact ${name} signature not checked`, true, "the value is withheld; disclose it or give the capture key to check its signature");
396
+ else if (stillWithheld)
397
+ add(label, false, "the value is in clear but its signature is withheld; disclose it or give the capture key to check it");
398
+ else if (!wellFormed)
399
+ add(label, false, "the fact is marked attested and carries no signature, and the capture note does not say it is withheld");
400
+ else if (!opts.upstreamKeys?.length)
401
+ add(label, false, "the fact is marked attested; give the signer's public key (--upstream-key) to check it");
402
+ else {
403
+ const u = checkUpstream(env, opts.upstreamKeys, { receiptId: p.receiptId, tool: p.tool.name, contentDigest: digestOf(restored.value) });
404
+ add(label, u.ok, u.ok ? `keyid ${short(u.keyid)}` : u.error);
405
+ }
406
+ }
376
407
  const evidence = executedOrFailed && "upstream" in p.execution ? p.execution.upstream : undefined;
377
408
  if (executedOrFailed && evidence) {
378
409
  // The evidence as restored: the delivery body or the signed envelope may have been withheld with the result. A
@@ -567,10 +598,13 @@ export function auditExtends(older, newer, proof, keys, logId, opts = {}) {
567
598
  }
568
599
  return { ok: checks.every((c) => c.ok), checks, older: a, newer: b };
569
600
  }
601
+ /** What kind of evidence the issuer gives; a door answering a proxy's authz check gives a decision only. */
602
+ const issuerNote = (issuer) => (issuer.kind === "door" && issuer.framework === "authz" ? ISSUER_NOTE["door/authz"] : ISSUER_NOTE[issuer.kind] ?? "unknown issuer kind");
570
603
  const ISSUER_NOTE = {
571
604
  gateway: "enforced outside the agent's process; the agent could neither skip nor forge this receipt",
572
605
  sdk: "self-reported by the agent's own process; tamper-evident after issue, but nothing here was enforced outside the agent",
573
606
  door: "enforced in front of the business's own HTTP surface; the arriving party could not forge this receipt and is attested only when it presented a grant, and a request that reached the origin some other way leaves no receipt",
607
+ "door/authz": "decided by the door for a proxy in front of the business's own HTTP surface (nginx auth_request or Envoy ext_authz): the receipt records the decision, not the result, since the proxy relayed an allowed request and the door saw neither its body nor the origin's answer; the arriving party could not forge this receipt and is attested only when it presented a grant",
574
608
  guardian: "decided by an ACS Guardian outside the agent's process and signed with its own key, so the decision is attributable to it; the call is the agent's own report, and the agent could skip the Guardian or ignore its answer",
575
609
  egress: "observed by a forward proxy in the agent's network path, for a connection that went around the gateway: where it went and how much, never what was sent; the agent is known only by the proxy credential the witness checked, and a connection that skipped the proxy (no lockdown) leaves no receipt at all",
576
610
  };
@@ -585,7 +619,7 @@ export function formatReport(r) {
585
619
  return lines.join("\n");
586
620
  const p = r.statement.predicate;
587
621
  lines.push("");
588
- lines.push(`ISSUER: ${p.issuer.kind}${p.issuer.framework ? ` (${p.issuer.framework})` : ""}${p.issuer.strict ? ", strict mode" : ""}, ${ISSUER_NOTE[p.issuer.kind] ?? "unknown issuer kind"}`);
622
+ lines.push(`ISSUER: ${p.issuer.kind}${p.issuer.framework ? ` (${p.issuer.framework})` : ""}${p.issuer.strict ? ", strict mode" : ""}, ${issuerNote(p.issuer)}`);
589
623
  lines.push("");
590
624
  lines.push("field provenance value");
591
625
  const row = (f, prov, v) => lines.push(`${f.padEnd(15)} ${prov.padEnd(11)} ${typeof v === "string" ? v : JSON.stringify(v)}`);
@@ -597,8 +631,14 @@ export function formatReport(r) {
597
631
  row("model", p.model.provenance, p.model.id === null ? "(none supplied)" : idText(p.model.id));
598
632
  row("tool", p.tool.provenance, p.tool.name);
599
633
  row("args", p.request.provenance, p.request.args);
600
- for (const [k, f] of Object.entries(p.facts))
601
- row(`fact.${k}`, f.provenance, f.value);
634
+ for (const [k, f] of Object.entries(p.facts)) {
635
+ if (f.provenance !== "attested") {
636
+ row(`fact.${k}`, f.provenance, f.value);
637
+ continue;
638
+ }
639
+ const signed = r.checks.find((c) => c.name === `fact ${k} signature (upstream key)`);
640
+ row(`fact.${k}`, f.provenance, `${JSON.stringify(f.value)}${signed ? (signed.ok ? ` (signed by ${signed.detail})` : " (signature FAILED)") : " (signature not checked)"}`);
641
+ }
602
642
  if (p.reconciliation)
603
643
  row("policy", "-", "(none evaluated: a provider read, not a call)");
604
644
  else if (p.policy)
@@ -611,7 +651,7 @@ export function formatReport(r) {
611
651
  const committed = r.checks.filter((c) => c.name.startsWith("authorization ")).every((c) => c.ok);
612
652
  row("authorization", "observed", committed ? `committed to the log as leaf ${p.authorization.inclusion.leafIndex}, before the call was forwarded` : "carried, but its checks FAILED");
613
653
  }
614
- else if (p.execution.status === "withheld" && p.issuer.kind !== "guardian")
654
+ else if (p.execution.status === "withheld" && p.issuer.kind !== "guardian" && !(p.issuer.kind === "door" && p.issuer.framework === "authz"))
615
655
  row("authorization", "observed", "the log would not commit it; the call was not forwarded");
616
656
  if (p.approval)
617
657
  row("approval", p.approval.provenance, `${p.approval.status}; ${p.approval.requiredApprovers} approver(s) required${p.approval.consumedAt ? `; consumed ${p.approval.consumedAt}` : ""}${typeof p.approval.reason === "string" ? `; ${p.approval.reason}` : ""}`);
@@ -0,0 +1,105 @@
1
+ export declare const DIRECTORY_PATH = "/.well-known/http-message-signatures-directory";
2
+ export declare const DIRECTORY_MEDIA_TYPE = "application/http-message-signatures-directory+json";
3
+ export declare const WEB_BOT_AUTH_TAG = "web-bot-auth";
4
+ export type BareItem = {
5
+ t: "string";
6
+ v: string;
7
+ } | {
8
+ t: "token";
9
+ v: string;
10
+ } | {
11
+ t: "integer";
12
+ v: number;
13
+ } | {
14
+ t: "decimal";
15
+ v: number;
16
+ } | {
17
+ t: "bytes";
18
+ v: Buffer;
19
+ } | {
20
+ t: "boolean";
21
+ v: boolean;
22
+ };
23
+ export type Params = [string, BareItem][];
24
+ export interface SfItem {
25
+ item: BareItem;
26
+ params: Params;
27
+ }
28
+ export interface SfInnerList {
29
+ list: SfItem[];
30
+ params: Params;
31
+ }
32
+ export type SfMember = SfItem | SfInnerList;
33
+ /** An RFC 8941 dictionary. A later member of the same name replaces an earlier one, as the RFC says. */
34
+ export declare function parseDictionary(text: string): Map<string, SfMember>;
35
+ /** An RFC 8941 item on its own, such as a legacy `Signature-Agent: "https://..."`. */
36
+ export declare function parseItem(text: string): SfItem;
37
+ export declare const serializeMember: (m: SfMember) => string;
38
+ /** What a signature base is built from: the request as the door received it. */
39
+ export interface SignedRequest {
40
+ method: string;
41
+ /** the request target as received, path and query, never decoded */
42
+ target: string;
43
+ /** the authority the request was sent to, normalised (`normalizeAuthority`) */
44
+ authority: string;
45
+ /** every value of a header field, lowercase name; undefined when the field is absent */
46
+ header(name: string): string[] | undefined;
47
+ }
48
+ /** A host as RFC 9421 compares it: lowercase, without the default port of https or http. */
49
+ export declare function normalizeAuthority(host: string): string;
50
+ /**
51
+ * The RFC 9421 signature base (section 2.5) for the covered components and their parameters. Supports `@method`,
52
+ * `@authority`, `@path`, `@query`, and header fields, whole or one dictionary member (`;key`). Any other derived
53
+ * component or component parameter is refused rather than guessed at.
54
+ */
55
+ export declare function signatureBase(req: SignedRequest, input: SfInnerList): string;
56
+ /** The RFC 7638 thumbprint of an Ed25519 JWK (RFC 8037 appendix A.3): the base64url SHA-256 of `{"crv","kty","x"}`. */
57
+ export declare function jwkThumbprint(x: string): string;
58
+ export interface WebBotAuthOptions {
59
+ /** the signature agents, as https origins, whose directories the door may fetch; any other is refused unfetched */
60
+ agents: string[];
61
+ /** the authorities this door serves; a signature covering any other `@authority` is refused */
62
+ authorities: string[];
63
+ requireNonce: boolean;
64
+ maxAgeSeconds: number;
65
+ clockSkewSeconds: number;
66
+ timeoutMs: number;
67
+ maxDirectoryBytes: number;
68
+ cacheSeconds: number;
69
+ maxNonces: number;
70
+ }
71
+ /**
72
+ * What the door made of a request's signature. `verified`: a signature tagged `web-bot-auth` checked against a key
73
+ * that `agent`'s directory publishes. `invalid`: the signature, its parameters, its agent, or the directory was wrong.
74
+ * `unavailable`: the directory could not be fetched, or the door could not record the nonce. `unchecked`: a signature
75
+ * arrived and the door has no `webBotAuth` config. `absent`: no `Signature-Input`.
76
+ */
77
+ export type SignatureCheck = {
78
+ outcome: "verified";
79
+ agent: string;
80
+ keyid: string;
81
+ label: string;
82
+ } | {
83
+ outcome: "invalid" | "unavailable";
84
+ error: string;
85
+ agent?: string;
86
+ keyid?: string;
87
+ } | {
88
+ outcome: "unchecked" | "absent";
89
+ };
90
+ export interface WebBotAuthVerifier {
91
+ verify(req: SignedRequest): Promise<SignatureCheck>;
92
+ /** nonces held now */
93
+ nonces(): number;
94
+ }
95
+ /** A response body up to `max` bytes; null when it passes that, and the rest is not read. */
96
+ export declare function readCapped(res: Response, max: number): Promise<Buffer | null>;
97
+ /** An https origin with nothing after it, as the config holds it; throws on anything else. */
98
+ export declare function agentOrigin(uri: string): string;
99
+ /**
100
+ * Checks Web Bot Auth signatures. The directory of each configured agent is fetched from
101
+ * `<origin>/.well-known/http-message-signatures-directory` over https, never following a redirect, within `timeoutMs`
102
+ * and `maxDirectoryBytes`, and kept for `cacheSeconds` (a failure for 30 seconds). A nonce is remembered until the
103
+ * signature it came with could no longer be accepted, so a signature serves one request. `now` is for tests.
104
+ */
105
+ export declare function createWebBotAuthVerifier(opts: WebBotAuthOptions, f: typeof fetch, now?: () => number): WebBotAuthVerifier;