@agent-custody/receipts 0.5.5 → 0.5.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.
- package/README.md +8 -3
- package/dist/cli.js +16 -1
- package/dist/config.d.ts +18 -0
- package/dist/config.js +4 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/log-admin.js +5 -0
- package/dist/log-export.d.ts +28 -0
- package/dist/log-export.js +84 -0
- package/dist/log-sink.d.ts +11 -0
- package/dist/log-sink.js +30 -2
- package/dist/log-store.d.ts +3 -0
- package/dist/log-store.js +7 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +4 -0
- package/dist/otel.d.ts +3 -1
- package/dist/otel.js +17 -2
- package/dist/signer.js +3 -3
- package/dist/splunk.d.ts +26 -0
- package/dist/splunk.js +59 -0
- package/dist/witness.js +1 -1
- package/docs/compliance.md +64 -0
- package/docs/sdk.md +1 -1
- package/docs/tutorials.md +1 -0
- package/docs/usage.md +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
|
|
|
14
14
|
- [The interceptor SDK](docs/sdk.md): Claude Code hooks, the Claude Agent SDK, adapters for the OpenAI Agents SDK, Vercel AI SDK and LangChain, and wrapping tool functions in anything else
|
|
15
15
|
- [Writing policies](docs/policies.md): how a tool call becomes a Cedar request, with tested examples
|
|
16
16
|
- [Verifying a receipt](docs/verification.md): what each check means and what a verified receipt does and does not prove
|
|
17
|
+
- [What the evidence satisfies](docs/compliance.md): the receipts, packs, and certificates mapped to SOC 2, ISO 27001, the EU AI Act, and UK GDPR, with what none of them claims
|
|
17
18
|
|
|
18
19
|
## Getting started
|
|
19
20
|
|
|
@@ -58,7 +59,7 @@ flowchart LR
|
|
|
58
59
|
R[("receipt bundles<br/>receipts/*.json")]
|
|
59
60
|
L[("Merkle log<br/>local file, or a remote log<br/>run by someone else")]
|
|
60
61
|
V["Verifier<br/>auditor, counterparty, CI job"]
|
|
61
|
-
O["Observability<br/>OTel, LangSmith, Arize"]
|
|
62
|
+
O["Observability<br/>OTel, Splunk, LangSmith, Arize"]
|
|
62
63
|
|
|
63
64
|
P -- "signed delegation grant" --> G
|
|
64
65
|
A -- "MCP tools/call" --> G
|
|
@@ -105,7 +106,7 @@ Every receipt names its issuer, and the verifier prints what that issuer kind is
|
|
|
105
106
|
| Vercel AI SDK | SDK | `wrapTools` | | a real `generateText` loop over the SDK's mock model |
|
|
106
107
|
| LangChain / LangGraph (JS) | SDK | `tool(issuer.wrap(fn))` | `ReceiptCallbackHandler` | real `StructuredTool` invocations |
|
|
107
108
|
| anything else | SDK | `issuer.wrap(name, fn)` | `issuer.record` | plain functions |
|
|
108
|
-
| Python: LangChain, OpenAI Agents SDK, Claude Agent SDK | sidecar + [Python package](../python/README.md) | `wrap_tools
|
|
109
|
+
| Python: LangChain, OpenAI Agents SDK, CrewAI, Claude Agent SDK | sidecar + [Python package](../python/README.md) | `wrap_tools` (OpenAI Agents, CrewAI), `claude_hook` PreToolUse deny, `client.wrap` | `ReceiptCallbackHandler` | the real Python packages, receipts checked by this verifier |
|
|
109
110
|
| Go, Java, Rust, any language with HTTP | sidecar | decide then record | record | [examples/languages](examples/languages), each run against a live sidecar |
|
|
110
111
|
| any MCP host in any language: Claude Agent SDK Python, OpenAI Agents Python | gateway | yes | | the gateway is an MCP server; [usage.md](docs/usage.md#python-hosts) |
|
|
111
112
|
| any REST API, as tools the agent reaches through the gateway | gateway, `rest` upstream | yes | | a stand-in HTTP API; [usage.md](docs/usage.md#setup-step-by-step) |
|
|
@@ -226,6 +227,7 @@ src/config.ts gateway and SDK config schemas, path resolution
|
|
|
226
227
|
src/crypto.ts canonical JSON, sha256, Ed25519 keys, DSSE sign/verify
|
|
227
228
|
src/log.ts Merkle log: append, root, inclusion and consistency proofs, verify, JSONL persistence
|
|
228
229
|
src/log-check.ts the outside monitor: verifies the head, checkpoints, and witness of a running log
|
|
230
|
+
src/log-export.ts a tenant's export of their own log, self-checked, as a log file the verifier reads
|
|
229
231
|
src/witness.ts the witness: countersigns the log's checkpoints from another operator's machine, or refuses with an alarm
|
|
230
232
|
src/signer.ts the signer: the log's key in its own process, the key document verifiers fetch
|
|
231
233
|
src/checkpoints.ts signed heads published on a schedule, to files and to Postgres
|
|
@@ -241,6 +243,7 @@ src/sdk/claude.ts Claude Code command hook and Claude Agent SDK in-process hook
|
|
|
241
243
|
src/sdk/openai-agents.ts, vercel-ai.ts, langchain.ts framework adapters, tested against the real packages
|
|
242
244
|
src/sidecar.ts the SDK issuer behind a local HTTP API, for agents in other languages
|
|
243
245
|
src/otel.ts OpenTelemetry export: one OTLP/HTTP span per receipt, after the receipt, no SDK dependency
|
|
246
|
+
src/splunk.ts Splunk export: one HTTP Event Collector event per receipt, token from the environment, beside or instead of otel
|
|
244
247
|
src/rest.ts the REST connector: an HTTP API described as tools, standing where an MCP upstream stands
|
|
245
248
|
src/upstream.ts attested execution: an upstream signs its result for the receipt; the verifier checks it with the upstream key
|
|
246
249
|
vectors/ conformance vectors: receipts, keys, logs, proofs, and expected verdicts; `bun run vectors` regenerates them
|
|
@@ -268,7 +271,7 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
268
271
|
- Claude Code command hook for PreToolUse, PostToolUse, and PostToolUseFailure, with blocking on deny.
|
|
269
272
|
- Claude Agent SDK in-process hooks over the same handler.
|
|
270
273
|
- Provider-native deliveries: an upstream wrapping Stripe or GitHub attaches the signed webhook or delivery for the call; a verifier with the shared secret checks the HMAC, the timestamp, and the binding to the result, and reports the execution as attested by shared secret.
|
|
271
|
-
- Logarithmic appends: the Merkle log caches complete subtrees, so issuing a receipt costs the same at the millionth leaf as at the first; measured at 0.15 ms per receipt and about half a millisecond per gateway call including policy, a fact lookup, and the upstream signature.
|
|
274
|
+
- Logarithmic appends: the Merkle log caches complete subtrees, so issuing a receipt costs the same at the millionth leaf as at the first; measured at 0.15 ms per receipt and about half a millisecond per gateway call including policy, a fact lookup, and the upstream signature. A remote log adds one network round trip plus about five milliseconds of server work per call, two for a pre-committed call; the [deployment guide](https://agent-custody.dev/guide/deployment) has the measurements against the live log.
|
|
272
275
|
- Retention on the log: `prune` replaces leaves older than a cutoff with their hashes and removes their bundles, so proofs still verify and the content is gone.
|
|
273
276
|
- Several upstreams under one gateway and one grant, each tool owned by exactly one, with the receipt naming which served the call; consumed facts flow across them.
|
|
274
277
|
- Attested execution: an upstream that holds a key signs its result for the receipt, the gateway embeds it, and a verifier given the upstream key reports the execution as attested rather than observed. The memory server and the demo upstream sign.
|
|
@@ -282,12 +285,14 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
282
285
|
- Remote log: the issuer can append to a log run by someone else over HTTP, whose key then signs the tree heads, so a verifier learns the receipt was in a log the operator could not rewrite. Includes the reference log server, bearer-token auth, and a root endpoint for auditors.
|
|
283
286
|
- Framework adapters, each tested against the real package with a scripted model and no network: OpenAI Agents SDK (`wrapTools` enforces, `observeRunner` records from lifecycle events), Vercel AI SDK (`wrapTools` over a real `generateText` loop), LangChain (`ReceiptCallbackHandler` records, `issuer.wrap` enforces).
|
|
284
287
|
|
|
288
|
+
- A tenant's export: `log-export` takes, with the tenant's own token, every leaf hash, the signed head, the published keys, the checkpoints, and their usage, checks that they add up, and writes a log copy the verifier reads offline; the evidence never depends on the operator staying in business.
|
|
285
289
|
- Monitoring and metering: `log-check`, the outside probe that verifies the head, the checkpoints, and the witness and exits 1 on trouble, run every ten minutes by the `monitor` workflow; `GET /health`; and usage per tenant per month on the admin page and as CSV.
|
|
286
290
|
- The witness: a second signer on a machine the log's operator does not control countersigns each checkpoint after proving it extends the last one it signed, refuses a rewritten or forked history with an alarm, and publishes its key; `audit --witness-url` requires it. Phase 6 of [issue #6](https://github.com/ch4r10t33r/agent-custody/issues/6).
|
|
287
291
|
- The signer, keys, and checkpoints: the key in its own process (`signer`, `--signer-url`), the key document at `/.well-known/agent-custody-log.json` fetched and pinned by `verify --log-url` and `audit --log-url`, and signed checkpoints per log published to a directory and a table for a verifier who was not watching. Phase 3 of [issue #6](https://github.com/ch4r10t33r/agent-custody/issues/6).
|
|
288
292
|
- The log over Postgres: `log --db-env`, leaves as hashes in one table keyed by tenant, one writer per tenant by advisory lock, tenants and hashed tokens in tables managed by `log-admin`, rate limits and a body cap, retries in the sink, and `import` for an existing file log. Phase 2 of [issue #6](https://github.com/ch4r10t33r/agent-custody/issues/6).
|
|
289
293
|
- A log for someone else: `hashOnly` sends leaf hashes so the log never holds a receipt; the reference server runs several tenant logs at `/t/<tenant>/` with their own tokens and ids; tree heads name their log and the verifier checks it with `--log-id`. Phase 1 of the hosted log, [issue #6](https://github.com/ch4r10t33r/agent-custody/issues/6).
|
|
290
294
|
- OpenTelemetry export: with `otel` in either config, every receipt is also one span at the collector the team already runs, trace id equal to the receipt id, attributes for tool, agent, principal, status, decision, and log position; after the receipt, best effort, never on the evidence path.
|
|
295
|
+
- Splunk export: with `splunk` in either config, every receipt is also one event at the HTTP Event Collector, with the receipt id, tool, agent, principal, status, decision, and log position as searchable fields and the token from the environment; the same best-effort rule.
|
|
291
296
|
- The REST connector: a plain HTTP API described as tools in the gateway config, credentials from the environment, so an agent's direct API calls become receipted, policy-checked tool calls through the gateway.
|
|
292
297
|
- Pre-commit authorization for consequential tools: named in `precommit`, a call is signed and logged before it is forwarded, withheld if the log will not take it, and its receipt carries the committed authorization with proof that it precedes the execution.
|
|
293
298
|
|
package/dist/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import { bothCheckpoints, dirCheckpoints, postgresCheckpoints } from "./checkpoi
|
|
|
12
12
|
import { connectSigner, fetchLogKeys, localSigner, serveSigner } from "./signer.js";
|
|
13
13
|
import { fetchWitnessKeys, Witness } from "./witness.js";
|
|
14
14
|
import { checkLog, formatLogCheck } from "./log-check.js";
|
|
15
|
+
import { exportLog, formatExport } from "./log-export.js";
|
|
15
16
|
import { CheckpointPublisher, fileResolver } from "./log-sink.js";
|
|
16
17
|
import { createRequire } from "node:module";
|
|
17
18
|
import { pruneLog } from "./retention.js";
|
|
@@ -50,6 +51,9 @@ const USAGE = `agent-custody <command>
|
|
|
50
51
|
the operator's admin page at /admin and its API, behind the admin token: tenants, tokens shown once,
|
|
51
52
|
the welcome sheet; the public URLs fill the sheet in
|
|
52
53
|
log-check --log-url <url> [--checkpoints-url <url>] [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>] [--json]
|
|
54
|
+
log-export --log-url <url> [--tenant <name>] --token-env NAME --out <dir> [--month YYYY-MM]... [--json]
|
|
55
|
+
a tenant's own log, with their token: every leaf hash as a log file the verifier
|
|
56
|
+
reads, the signed head, the published keys, the checkpoints, and their usage
|
|
53
57
|
the outside monitor: verifies the head against the published keys, that checkpoints keep up
|
|
54
58
|
with the head and the head extends them, and that the witness countersigns and raises no
|
|
55
59
|
alarm; exits 1 on any failure. Run it from cron or a scheduled workflow elsewhere.
|
|
@@ -177,6 +181,17 @@ async function main(argv) {
|
|
|
177
181
|
console.log(values.json ? JSON.stringify(r, null, 2) : formatLogCheck(r));
|
|
178
182
|
return r.ok ? 0 : 1;
|
|
179
183
|
}
|
|
184
|
+
case "log-export": {
|
|
185
|
+
const { values } = parseArgs({ args: rest, options: { "log-url": { type: "string" }, tenant: { type: "string" }, "token-env": { type: "string" }, out: { type: "string" }, month: { type: "string", multiple: true }, json: { type: "boolean", default: false } } });
|
|
186
|
+
if (!values["log-url"] || !values["token-env"] || !values.out)
|
|
187
|
+
throw new Error("log-export needs --log-url, --token-env, and --out");
|
|
188
|
+
const token = process.env[values["token-env"]];
|
|
189
|
+
if (!token)
|
|
190
|
+
throw new Error(`environment variable ${values["token-env"]} is not set`);
|
|
191
|
+
const r = await exportLog({ logUrl: values["log-url"], ...(values.tenant ? { tenant: values.tenant } : {}), token, outDir: values.out, ...(values.month?.length ? { months: values.month } : {}) });
|
|
192
|
+
console.log(values.json ? JSON.stringify(r, null, 2) : formatExport(r));
|
|
193
|
+
return r.problems.length ? 1 : 0;
|
|
194
|
+
}
|
|
180
195
|
case "witness": {
|
|
181
196
|
const { values } = parseArgs({ args: rest, options: { key: { type: "string" }, "log-url": { type: "string" }, "checkpoints-url": { type: "string" }, out: { type: "string" }, tenant: { type: "string", multiple: true }, every: { type: "string", default: "300" }, once: { type: "boolean", default: false } } });
|
|
182
197
|
if (!values.key || !values["log-url"] || !values["checkpoints-url"] || !values.out)
|
|
@@ -410,7 +425,7 @@ async function main(argv) {
|
|
|
410
425
|
if (values.log)
|
|
411
426
|
proof = new MerkleLog(values.log).consistencyProof(Math.min(m, n), Math.max(m, n));
|
|
412
427
|
else {
|
|
413
|
-
const res = await fetch(new URL(`consistency?old=${Math.min(m, n)}&new=${Math.max(m, n)}`, values["log-url"].endsWith("/") ? values["log-url"] : `${values["log-url"]}/`));
|
|
428
|
+
const res = await fetch(new URL(`consistency?old=${Math.min(m, n)}&new=${Math.max(m, n)}`, values["log-url"].endsWith("/") ? values["log-url"] : `${values["log-url"]}/`), { signal: AbortSignal.timeout(10_000) });
|
|
414
429
|
if (!res.ok)
|
|
415
430
|
throw new Error(`log refused the consistency query: ${res.status}`);
|
|
416
431
|
proof = (await res.json()).hashes;
|
package/dist/config.d.ts
CHANGED
|
@@ -175,12 +175,21 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
175
175
|
url: z.ZodString;
|
|
176
176
|
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
177
177
|
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
178
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
178
179
|
}, z.core.$strip>>;
|
|
179
180
|
otel: z.ZodOptional<z.ZodObject<{
|
|
180
181
|
url: z.ZodString;
|
|
181
182
|
headersEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
182
183
|
serviceName: z.ZodOptional<z.ZodString>;
|
|
183
184
|
}, z.core.$strip>>;
|
|
185
|
+
splunk: z.ZodOptional<z.ZodObject<{
|
|
186
|
+
url: z.ZodString;
|
|
187
|
+
tokenEnv: z.ZodString;
|
|
188
|
+
index: z.ZodOptional<z.ZodString>;
|
|
189
|
+
source: z.ZodOptional<z.ZodString>;
|
|
190
|
+
sourcetype: z.ZodOptional<z.ZodString>;
|
|
191
|
+
host: z.ZodOptional<z.ZodString>;
|
|
192
|
+
}, z.core.$strip>>;
|
|
184
193
|
}, z.core.$strip>;
|
|
185
194
|
export type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
|
|
186
195
|
export type FactConfig = z.infer<typeof FactSchema>;
|
|
@@ -199,12 +208,21 @@ export declare const SdkConfigSchema: z.ZodObject<{
|
|
|
199
208
|
url: z.ZodString;
|
|
200
209
|
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
201
210
|
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
211
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
202
212
|
}, z.core.$strip>>;
|
|
203
213
|
otel: z.ZodOptional<z.ZodObject<{
|
|
204
214
|
url: z.ZodString;
|
|
205
215
|
headersEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
206
216
|
serviceName: z.ZodOptional<z.ZodString>;
|
|
207
217
|
}, z.core.$strip>>;
|
|
218
|
+
splunk: z.ZodOptional<z.ZodObject<{
|
|
219
|
+
url: z.ZodString;
|
|
220
|
+
tokenEnv: z.ZodString;
|
|
221
|
+
index: z.ZodOptional<z.ZodString>;
|
|
222
|
+
source: z.ZodOptional<z.ZodString>;
|
|
223
|
+
sourcetype: z.ZodOptional<z.ZodString>;
|
|
224
|
+
host: z.ZodOptional<z.ZodString>;
|
|
225
|
+
}, z.core.$strip>>;
|
|
208
226
|
framework: z.ZodOptional<z.ZodString>;
|
|
209
227
|
}, z.core.$strip>;
|
|
210
228
|
export type SdkConfig = z.infer<typeof SdkConfigSchema>;
|
package/dist/config.js
CHANGED
|
@@ -2,10 +2,11 @@ import { z } from "zod";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { dirname, resolve } from "node:path";
|
|
4
4
|
/** Where receipts are logged: a local file, or a log reached over HTTP whose bearer token comes from an environment variable. */
|
|
5
|
-
const LogSchema = z.object({ url: z.string().url(), tokenEnv: z.string().min(1).optional(), /** send leaf hashes only; the log never holds the receipt. Use it for any log run by someone else */ hashOnly: z.boolean().optional() });
|
|
5
|
+
const LogSchema = z.object({ url: z.string().url(), tokenEnv: z.string().min(1).optional(), /** send leaf hashes only; the log never holds the receipt. Use it for any log run by someone else */ hashOnly: z.boolean().optional(), /** milliseconds one append may take before the log counts as unreachable; default 10000 */ timeoutMs: z.number().int().positive().optional() });
|
|
6
6
|
const oneLog = { message: "exactly one of logFile or log is required" };
|
|
7
7
|
/** Optional OpenTelemetry export: every receipt also becomes a span at this OTLP/HTTP collector, after it is issued. Never on the evidence path. */
|
|
8
8
|
const OtelSchema = z.object({ url: z.string().url(), headersEnv: z.record(z.string(), z.string().min(1)).optional(), serviceName: z.string().min(1).optional() });
|
|
9
|
+
const SplunkSchema = z.object({ url: z.string().url(), tokenEnv: z.string().min(1), index: z.string().min(1).optional(), source: z.string().min(1).optional(), sourcetype: z.string().min(1).optional(), host: z.string().min(1).optional() });
|
|
9
10
|
const hasOneLog = (c) => (c.logFile ? 1 : 0) + (c.log ? 1 : 0) === 1;
|
|
10
11
|
/** One REST endpoint offered to the agent as a tool. `{name}` segments in the path come from the call's arguments; the rest go to the query on GET and DELETE, or to a JSON body otherwise. */
|
|
11
12
|
const RestToolSchema = z.object({
|
|
@@ -65,6 +66,7 @@ export const GatewayConfigSchema = z.object({
|
|
|
65
66
|
logFile: z.string().optional(),
|
|
66
67
|
log: LogSchema.optional(),
|
|
67
68
|
otel: OtelSchema.optional(),
|
|
69
|
+
splunk: SplunkSchema.optional(),
|
|
68
70
|
}).refine(hasOneLog, oneLog).refine((c) => (c.upstream ? 1 : 0) + (c.upstreams ? 1 : 0) === 1, { message: "exactly one of upstream or upstreams is required" });
|
|
69
71
|
/** Loads a config file and resolves every path relative to the file's directory. */
|
|
70
72
|
export function loadConfig(path) {
|
|
@@ -92,6 +94,7 @@ export const SdkConfigSchema = z.object({
|
|
|
92
94
|
logFile: z.string().optional(),
|
|
93
95
|
log: LogSchema.optional(),
|
|
94
96
|
otel: OtelSchema.optional(),
|
|
97
|
+
splunk: SplunkSchema.optional(),
|
|
95
98
|
/** free-text label of the host framework, e.g. "claude-code", "openai-agents" */
|
|
96
99
|
framework: z.string().optional(),
|
|
97
100
|
}).refine(hasOneLog, oneLog);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export type { AuthorizationBundle, AuthorizationPredicate, AuthorizationStatemen
|
|
|
3
3
|
export type { GatewayOptions } from "./gateway.ts";
|
|
4
4
|
export { buildRequest, restUpstream } from "./rest.ts";
|
|
5
5
|
export { openExporter, otlpExporter, spanFor } from "./otel.ts";
|
|
6
|
+
export { hecEvent, splunkExporter } from "./splunk.ts";
|
|
7
|
+
export { exportLog, formatExport } from "./log-export.ts";
|
|
8
|
+
export type { ExportOptions, ExportResult } from "./log-export.ts";
|
|
6
9
|
export { fileBackend, importLogFile, PostgresLog, PostgresTenancy, RateLimiter } from "./log-store.ts";
|
|
7
10
|
export { connectSigner, fetchLogKeys, localSigner, serveSigner, signerHandler } from "./signer.ts";
|
|
8
11
|
export type { KeyDocument, RemoteSignerOptions, RetiredKey, RunningSigner, Signer, SignerServerOptions } from "./signer.ts";
|
|
@@ -17,6 +20,7 @@ export type { AdminOptions } from "./log-admin.ts";
|
|
|
17
20
|
export type { Checkpoint, CheckpointStore } from "./checkpoints.ts";
|
|
18
21
|
export type { AppendResult, LogBackend, PostgresLike, PostgresLogOptions, RateLimitOptions, Tenant, TokenRecord } from "./log-store.ts";
|
|
19
22
|
export type { OtelConfig, OtlpOptions, ReceiptExporter } from "./otel.ts";
|
|
23
|
+
export type { SplunkConfig, SplunkOptions } from "./splunk.ts";
|
|
20
24
|
export type { IssuerOptions } from "./issue.ts";
|
|
21
25
|
export type { RestOptions, UpstreamClient } from "./rest.ts";
|
|
22
26
|
export * from "./config.ts";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export { AUTHORIZATION_PREDICATE_TYPE, buildAuthorizationStatement } from "./receipt.js";
|
|
3
3
|
export { buildRequest, restUpstream } from "./rest.js";
|
|
4
4
|
export { openExporter, otlpExporter, spanFor } from "./otel.js";
|
|
5
|
+
export { hecEvent, splunkExporter } from "./splunk.js";
|
|
6
|
+
export { exportLog, formatExport } from "./log-export.js";
|
|
5
7
|
export { fileBackend, importLogFile, PostgresLog, PostgresTenancy, RateLimiter } from "./log-store.js";
|
|
6
8
|
export { connectSigner, fetchLogKeys, localSigner, serveSigner, signerHandler } from "./signer.js";
|
|
7
9
|
export { bothCheckpoints, dirCheckpoints, postgresCheckpoints } from "./checkpoints.js";
|
package/dist/log-admin.js
CHANGED
|
@@ -35,6 +35,11 @@ export function welcomeSheet(o) {
|
|
|
35
35
|
` npx agent-custody audit --older receipts/<earlier>.json --newer receipts/<later>.json --log-url ${url} --log-id ${o.logId}`,
|
|
36
36
|
"--log-url fetches this log's published keys and pins them; --log-id makes sure the tree heads are this log's.",
|
|
37
37
|
"",
|
|
38
|
+
"Your log is yours to take, any time, with your token:",
|
|
39
|
+
` npx agent-custody log-export --log-url ${url} --tenant ${o.tenant} --token-env AGENT_CUSTODY_LOG_TOKEN --out custody-export/`,
|
|
40
|
+
"It fetches every leaf hash, the signed head, the keys, the checkpoints, and your usage, checks they add up, and writes",
|
|
41
|
+
"a log copy that verify --log and audit --log read with no server.",
|
|
42
|
+
"",
|
|
38
43
|
"What this log does not do: hold receipt contents, forge a receipt (your gateway key signs those), or, today,",
|
|
39
44
|
"countersign with a second independent witness. The proof table: https://agent-custody.dev/receipts/#what-a-receipt-proves-and-what-it-does-not",
|
|
40
45
|
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ExportOptions {
|
|
2
|
+
logUrl: string;
|
|
3
|
+
/** the tenant whose log to export; omitted, the log at the root paths */
|
|
4
|
+
tenant?: string | undefined;
|
|
5
|
+
token: string;
|
|
6
|
+
outDir: string;
|
|
7
|
+
/** months of usage to include, YYYY-MM; default the current and the previous month */
|
|
8
|
+
months?: string[] | undefined;
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
}
|
|
11
|
+
export interface ExportResult {
|
|
12
|
+
outDir: string;
|
|
13
|
+
logId: string | null;
|
|
14
|
+
treeSize: number;
|
|
15
|
+
rootHash: string;
|
|
16
|
+
keyid: string;
|
|
17
|
+
checkpoints: number;
|
|
18
|
+
usage: {
|
|
19
|
+
month: string;
|
|
20
|
+
appends: number;
|
|
21
|
+
totalLeaves: number;
|
|
22
|
+
liveTokens: number;
|
|
23
|
+
}[];
|
|
24
|
+
/** what did not add up; an export with problems is still written, and says so */
|
|
25
|
+
problems: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function exportLog(o: ExportOptions): Promise<ExportResult>;
|
|
28
|
+
export declare function formatExport(r: ExportResult): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// A tenant's export of their own log: every leaf hash, the signed head, the published keys, the signed checkpoints,
|
|
2
|
+
// and their metering, fetched with their own token and written as files they can keep. The leaves go into a log
|
|
3
|
+
// file in the format the verifier already reads, so `verify --log` and `audit --log` work against the export with
|
|
4
|
+
// no server at all. The export checks itself before it is written: the head must verify against the published keys
|
|
5
|
+
// and its root must be the root of the leaves fetched, and the same for every checkpoint. A tenant who leaves takes
|
|
6
|
+
// this with them; a tenant who stays runs it on a schedule so the evidence never depends on one operator.
|
|
7
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { dsseVerify } from "./crypto.js";
|
|
10
|
+
import { rootOf } from "./log.js";
|
|
11
|
+
import { TREEHEAD_TYPE } from "./receipt.js";
|
|
12
|
+
import { fetchLogKeys } from "./signer.js";
|
|
13
|
+
const monthOf = (d) => d.toISOString().slice(0, 7);
|
|
14
|
+
const previousMonth = (d) => monthOf(new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() - 1, 1)));
|
|
15
|
+
export async function exportLog(o) {
|
|
16
|
+
const f = o.fetch ?? fetch;
|
|
17
|
+
const base = o.logUrl.endsWith("/") ? o.logUrl : `${o.logUrl}/`;
|
|
18
|
+
const path = (op) => new URL(o.tenant ? `t/${o.tenant}/${op}` : op, base);
|
|
19
|
+
const headers = { authorization: `Bearer ${o.token}` };
|
|
20
|
+
const get = async (url, auth) => {
|
|
21
|
+
const res = await f(url, { signal: AbortSignal.timeout(30_000), ...(auth ? { headers } : {}) });
|
|
22
|
+
if (res.status === 401)
|
|
23
|
+
throw new Error(`the log refused the token for ${url.pathname}`);
|
|
24
|
+
if (!res.ok)
|
|
25
|
+
throw new Error(`${res.status} from ${url.pathname}`);
|
|
26
|
+
return res.json();
|
|
27
|
+
};
|
|
28
|
+
const problems = [];
|
|
29
|
+
const { doc, keys } = await fetchLogKeys(base, f);
|
|
30
|
+
const { treeHead } = (await get(path("head"), false));
|
|
31
|
+
const v = dsseVerify(treeHead, keys);
|
|
32
|
+
if (!v.ok || treeHead.payloadType !== TREEHEAD_TYPE)
|
|
33
|
+
throw new Error(`the head does not verify against the published keys: ${v.ok ? "not a tree head" : v.error}`);
|
|
34
|
+
const head = v.payload;
|
|
35
|
+
// every leaf, in pages, as of the head's size; leaves appended meanwhile are the next export's
|
|
36
|
+
const leaves = [];
|
|
37
|
+
while (leaves.length < head.treeSize) {
|
|
38
|
+
const page = (await get(new URL(`?since=${leaves.length}&limit=10000`, path("leaves")), true));
|
|
39
|
+
if (page.leaves.length === 0)
|
|
40
|
+
throw new Error(`the log returned no leaves past ${leaves.length} of ${head.treeSize}`);
|
|
41
|
+
leaves.push(...page.leaves.slice(0, head.treeSize - leaves.length));
|
|
42
|
+
}
|
|
43
|
+
const hashes = leaves.map((h) => Buffer.from(h, "hex"));
|
|
44
|
+
const root = rootOf(hashes);
|
|
45
|
+
if (root !== head.rootHash)
|
|
46
|
+
problems.push(`the root of the ${leaves.length} leaves fetched (${root.slice(0, 12)}) is not the head's (${head.rootHash.slice(0, 12)})`);
|
|
47
|
+
const cps = (await get(path("checkpoints"), false));
|
|
48
|
+
for (const c of cps.checkpoints) {
|
|
49
|
+
const cv = dsseVerify(c.treeHead, keys);
|
|
50
|
+
if (!cv.ok)
|
|
51
|
+
problems.push(`checkpoint at ${c.treeSize} does not verify: ${cv.error}`);
|
|
52
|
+
else if (c.treeSize <= head.treeSize && rootOf(hashes, c.treeSize) !== c.rootHash)
|
|
53
|
+
problems.push(`checkpoint at ${c.treeSize} has root ${c.rootHash.slice(0, 12)}, the leaves give ${rootOf(hashes, c.treeSize).slice(0, 12)}`);
|
|
54
|
+
}
|
|
55
|
+
const usage = [];
|
|
56
|
+
for (const month of o.months ?? [monthOf(new Date()), previousMonth(new Date())]) {
|
|
57
|
+
try {
|
|
58
|
+
usage.push((await get(new URL(`?month=${month}`, path("usage")), true)));
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
problems.push(`usage for ${month}: ${e instanceof Error ? e.message : String(e)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
mkdirSync(o.outDir, { recursive: true });
|
|
65
|
+
writeFileSync(join(o.outDir, "log.jsonl"), leaves.map((h) => JSON.stringify({ hash: h })).join("\n") + (leaves.length ? "\n" : ""));
|
|
66
|
+
writeFileSync(join(o.outDir, "head.json"), JSON.stringify({ treeHead, ...head }, null, 2));
|
|
67
|
+
writeFileSync(join(o.outDir, "keys.json"), JSON.stringify(doc, null, 2));
|
|
68
|
+
writeFileSync(join(o.outDir, "checkpoints.json"), JSON.stringify(cps.checkpoints, null, 2));
|
|
69
|
+
writeFileSync(join(o.outDir, "usage.json"), JSON.stringify(usage, null, 2));
|
|
70
|
+
const result = { outDir: o.outDir, logId: head.log ?? null, treeSize: head.treeSize, rootHash: head.rootHash, keyid: v.keyid, checkpoints: cps.checkpoints.length, usage, problems };
|
|
71
|
+
writeFileSync(join(o.outDir, "export.json"), JSON.stringify({ exportedAt: new Date().toISOString(), logUrl: base, tenant: o.tenant ?? null, ...result }, null, 2));
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
export function formatExport(r) {
|
|
75
|
+
const lines = [
|
|
76
|
+
`exported ${r.treeSize} leaf hash(es) of log ${r.logId ?? "(unnamed)"} to ${r.outDir}`,
|
|
77
|
+
`head root ${r.rootHash.slice(0, 16)}, signed by ${r.keyid.slice(0, 12)}, ${r.checkpoints} checkpoint(s)`,
|
|
78
|
+
...r.usage.map((u) => `usage ${u.month}: ${u.appends} append(s), ${u.totalLeaves} leaves in total, ${u.liveTokens} live token(s)`),
|
|
79
|
+
"",
|
|
80
|
+
"log.jsonl is a log copy the verifier reads: agent-custody verify <receipt> --log <outDir>/log.jsonl --issuer-key ...",
|
|
81
|
+
...(r.problems.length ? ["", ...r.problems.map((p) => `PROBLEM: ${p}`), "", "RESULT: EXPORT DOES NOT ADD UP"] : ["", "RESULT: EXPORT VERIFIED"]),
|
|
82
|
+
];
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
package/dist/log-sink.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface HttpLogOptions {
|
|
|
25
25
|
hashOnly?: boolean;
|
|
26
26
|
/** attempts on 429 and 5xx; default 3 */
|
|
27
27
|
retries?: number;
|
|
28
|
+
/** how long one append may take before it counts as unreachable; default 10000. A log that accepts and never answers must not hold a call forever. */
|
|
29
|
+
timeoutMs?: number;
|
|
28
30
|
fetch?: typeof fetch;
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
@@ -38,6 +40,7 @@ export interface LogConfig {
|
|
|
38
40
|
url: string;
|
|
39
41
|
tokenEnv?: string | undefined;
|
|
40
42
|
hashOnly?: boolean | undefined;
|
|
43
|
+
timeoutMs?: number | undefined;
|
|
41
44
|
} | undefined;
|
|
42
45
|
}
|
|
43
46
|
/** The sink a config asks for: a remote log when `log` is set, otherwise the local file. */
|
|
@@ -75,10 +78,18 @@ export interface LogServerOptions {
|
|
|
75
78
|
/** The address a limit is keyed by: the socket's, or the proxy's forwarded one when the proxy is trusted. */
|
|
76
79
|
export declare function clientAddress(req: IncomingMessage, trustProxy?: boolean): string;
|
|
77
80
|
/** One log as the handler sees it, whatever stands behind it. */
|
|
81
|
+
export interface TenantUsage {
|
|
82
|
+
month: string;
|
|
83
|
+
appends: number;
|
|
84
|
+
totalLeaves: number;
|
|
85
|
+
liveTokens: number;
|
|
86
|
+
}
|
|
78
87
|
export interface ResolvedLog {
|
|
79
88
|
backend: LogBackend;
|
|
80
89
|
logId: string | undefined;
|
|
81
90
|
authorize(token: string | null): Promise<boolean>;
|
|
91
|
+
/** this log's own metering for a month, where the store keeps it */
|
|
92
|
+
usage?(month: string): Promise<TenantUsage>;
|
|
82
93
|
}
|
|
83
94
|
/** Turns the tenant in a path, or null for the root paths, into a log. */
|
|
84
95
|
export interface LogResolver {
|
package/dist/log-sink.js
CHANGED
|
@@ -44,6 +44,7 @@ export function httpLog(url, opts = {}) {
|
|
|
44
44
|
const f = opts.fetch ?? fetch;
|
|
45
45
|
const base = url.endsWith("/") ? url : `${url}/`;
|
|
46
46
|
const attempts = opts.retries ?? 3;
|
|
47
|
+
const timeoutMs = opts.timeoutMs ?? 10_000;
|
|
47
48
|
return {
|
|
48
49
|
kind: "http",
|
|
49
50
|
where: url,
|
|
@@ -56,6 +57,7 @@ export function httpLog(url, opts = {}) {
|
|
|
56
57
|
method: "POST",
|
|
57
58
|
headers: { "content-type": "application/json", ...(opts.token ? { authorization: `Bearer ${opts.token}` } : {}) },
|
|
58
59
|
body: JSON.stringify(opts.hashOnly ? { leafHash: leafHash(leaf).toString("hex") } : { leaf }),
|
|
60
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
59
61
|
});
|
|
60
62
|
}
|
|
61
63
|
catch (e) {
|
|
@@ -88,7 +90,7 @@ export function openLog(cfg, key) {
|
|
|
88
90
|
const token = cfg.log.tokenEnv ? process.env[cfg.log.tokenEnv] : undefined;
|
|
89
91
|
if (cfg.log.tokenEnv && !token)
|
|
90
92
|
throw new Error(`log token: environment variable ${cfg.log.tokenEnv} is not set`);
|
|
91
|
-
return httpLog(cfg.log.url, { ...(token === undefined ? {} : { token }), ...(cfg.log.hashOnly ? { hashOnly: true } : {}) });
|
|
93
|
+
return httpLog(cfg.log.url, { ...(token === undefined ? {} : { token }), ...(cfg.log.hashOnly ? { hashOnly: true } : {}), ...(cfg.log.timeoutMs ? { timeoutMs: cfg.log.timeoutMs } : {}) });
|
|
92
94
|
}
|
|
93
95
|
if (!cfg.logFile)
|
|
94
96
|
throw new Error("config needs logFile or log.url");
|
|
@@ -147,6 +149,11 @@ export function postgresResolver(tenancy, opts = {}) {
|
|
|
147
149
|
backend,
|
|
148
150
|
logId: t.logId,
|
|
149
151
|
authorize: async (tok) => (tenant === null && (opts.staticTokens?.length ?? 0) > 0 && tokenMatches(opts.staticTokens, tok)) || (await tenancy.authorize(id, tok)),
|
|
152
|
+
usage: async (month) => {
|
|
153
|
+
const u = await tenancy.usage(month);
|
|
154
|
+
const row = u.tenants.find((t) => t.id === id);
|
|
155
|
+
return { month, appends: row?.appends ?? 0, totalLeaves: row?.totalLeaves ?? 0, liveTokens: row?.liveTokens ?? 0 };
|
|
156
|
+
},
|
|
150
157
|
};
|
|
151
158
|
},
|
|
152
159
|
async tenants() {
|
|
@@ -259,7 +266,7 @@ export function logHandler(source, keyOrSigner, opts = {}) {
|
|
|
259
266
|
}
|
|
260
267
|
}
|
|
261
268
|
// /t/<tenant>/<op> reaches that tenant's log; anything else is the default log.
|
|
262
|
-
const m = /^\/t\/([A-Za-z0-9_.-]+)\/(append|root|consistency|head|checkpoints)$/.exec(url.pathname);
|
|
269
|
+
const m = /^\/t\/([A-Za-z0-9_.-]+)\/(append|root|consistency|head|checkpoints|leaves|usage)$/.exec(url.pathname);
|
|
263
270
|
let which;
|
|
264
271
|
try {
|
|
265
272
|
which = await resolver.resolve(m ? m[1] : null);
|
|
@@ -301,6 +308,27 @@ export function logHandler(source, keyOrSigner, opts = {}) {
|
|
|
301
308
|
return json(200, await appendSigned(log, signer, { leaf: parsed.leaf }, logId));
|
|
302
309
|
}
|
|
303
310
|
const current = await log.size();
|
|
311
|
+
// A tenant's own data, with their token: every leaf hash, in pages, and their metering. The export command
|
|
312
|
+
// pages through these and rebuilds a log file the verifier reads directly.
|
|
313
|
+
if (req.method === "GET" && (url.pathname.endsWith("/leaves") || url.pathname.endsWith("/usage"))) {
|
|
314
|
+
if (!(await which.authorize(bearer(req))))
|
|
315
|
+
return json(401, { error: "unauthorized" });
|
|
316
|
+
if (url.pathname.endsWith("/usage")) {
|
|
317
|
+
if (!which.usage)
|
|
318
|
+
return json(404, { error: "this log keeps no usage" });
|
|
319
|
+
const month = url.searchParams.get("month") ?? new Date().toISOString().slice(0, 7);
|
|
320
|
+
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month))
|
|
321
|
+
return json(400, { error: "month must be YYYY-MM" });
|
|
322
|
+
return json(200, await which.usage(month), { "cache-control": "no-store" });
|
|
323
|
+
}
|
|
324
|
+
const since = url.searchParams.has("since") ? Number(url.searchParams.get("since")) : 0;
|
|
325
|
+
const limit = url.searchParams.has("limit") ? Number(url.searchParams.get("limit")) : 10_000;
|
|
326
|
+
if (!Number.isInteger(since) || since < 0 || since > current)
|
|
327
|
+
return json(400, { error: `since must be an integer in 0..${current}` });
|
|
328
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 10_000)
|
|
329
|
+
return json(400, { error: "limit must be an integer in 1..10000" });
|
|
330
|
+
return json(200, { since, size: current, leaves: await log.leafHashes(since, since + limit) }, { "cache-control": "no-store" });
|
|
331
|
+
}
|
|
304
332
|
if (req.method === "GET" && url.pathname.endsWith("/root")) {
|
|
305
333
|
const size = url.searchParams.has("size") ? Number(url.searchParams.get("size")) : current;
|
|
306
334
|
if (!Number.isInteger(size) || size < 0 || size > current)
|
package/dist/log-store.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface LogBackend {
|
|
|
9
9
|
appendHash(leafHashHex: string): Promise<AppendResult>;
|
|
10
10
|
root(size?: number): Promise<string>;
|
|
11
11
|
consistencyProof(oldSize: number, newSize?: number): Promise<string[]>;
|
|
12
|
+
/** leaf hashes from (inclusive) to (exclusive), hex */
|
|
13
|
+
leafHashes(from: number, to: number): Promise<string[]>;
|
|
12
14
|
}
|
|
13
15
|
/** The JSONL file log behind the asynchronous interface. */
|
|
14
16
|
export declare function fileBackend(file: string): LogBackend;
|
|
@@ -51,6 +53,7 @@ export declare class PostgresLog implements LogBackend {
|
|
|
51
53
|
private commit;
|
|
52
54
|
append(leaf: string): Promise<AppendResult>;
|
|
53
55
|
appendHash(leafHashHex: string): Promise<AppendResult>;
|
|
56
|
+
leafHashes(from: number, to: number): Promise<string[]>;
|
|
54
57
|
root(size?: number): Promise<string>;
|
|
55
58
|
consistencyProof(oldSize: number, newSize?: number): Promise<string[]>;
|
|
56
59
|
}
|
package/dist/log-store.js
CHANGED
|
@@ -22,6 +22,9 @@ export function fileBackend(file) {
|
|
|
22
22
|
async root(size) {
|
|
23
23
|
return log.root(size);
|
|
24
24
|
},
|
|
25
|
+
async leafHashes(from, to) {
|
|
26
|
+
return log.leafHashes(from, to);
|
|
27
|
+
},
|
|
25
28
|
async consistencyProof(oldSize, newSize) {
|
|
26
29
|
return log.consistencyProof(oldSize, newSize);
|
|
27
30
|
},
|
|
@@ -146,6 +149,10 @@ export class PostgresLog {
|
|
|
146
149
|
throw new Error("leafHash must be 64 lowercase hex characters");
|
|
147
150
|
return this.commit(Buffer.from(leafHashHex, "hex"));
|
|
148
151
|
}
|
|
152
|
+
async leafHashes(from, to) {
|
|
153
|
+
const n = await this.size();
|
|
154
|
+
return this.hashes.slice(Math.max(0, from), Math.min(to, n)).map((h) => h.toString("hex"));
|
|
155
|
+
}
|
|
149
156
|
async root(size) {
|
|
150
157
|
await this.sync();
|
|
151
158
|
const n = size ?? this.hashes.length;
|
package/dist/log.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export declare class MerkleLog {
|
|
|
31
31
|
private readonly file;
|
|
32
32
|
constructor(file: string);
|
|
33
33
|
get size(): number;
|
|
34
|
+
/** Leaf hashes `from` (inclusive) to `to` (exclusive), as hex: what an export carries and what a copy is rebuilt from. */
|
|
35
|
+
leafHashes(from: number, to?: number): string[];
|
|
34
36
|
/** Appends a leaf (an opaque string, typically a canonical JSON envelope). Returns its proof against the new root. */
|
|
35
37
|
append(leaf: string): InclusionProof & {
|
|
36
38
|
rootHash: string;
|
package/dist/log.js
CHANGED
|
@@ -177,6 +177,10 @@ export class MerkleLog {
|
|
|
177
177
|
get size() {
|
|
178
178
|
return this.hashes.length;
|
|
179
179
|
}
|
|
180
|
+
/** Leaf hashes `from` (inclusive) to `to` (exclusive), as hex: what an export carries and what a copy is rebuilt from. */
|
|
181
|
+
leafHashes(from, to = this.hashes.length) {
|
|
182
|
+
return this.hashes.slice(Math.max(0, from), Math.min(to, this.hashes.length)).map((h) => h.toString("hex"));
|
|
183
|
+
}
|
|
180
184
|
/** Appends a leaf (an opaque string, typically a canonical JSON envelope). Returns its proof against the new root. */
|
|
181
185
|
append(leaf) {
|
|
182
186
|
appendFileSync(this.file, JSON.stringify(leaf) + "\n");
|
package/dist/otel.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReceiptBundle, ReceiptPredicate } from "./receipt.ts";
|
|
2
|
+
import { type SplunkConfig } from "./splunk.ts";
|
|
2
3
|
export interface OtelConfig {
|
|
3
4
|
/** the collector's OTLP/HTTP base, e.g. http://localhost:4318; spans go to <url>/v1/traces */
|
|
4
5
|
url: string;
|
|
@@ -22,7 +23,8 @@ export interface OtlpOptions {
|
|
|
22
23
|
}
|
|
23
24
|
/** An exporter that posts each receipt's span to an OTLP/HTTP collector. Failures are reported, never thrown. */
|
|
24
25
|
export declare function otlpExporter(cfg: OtelConfig, opts?: OtlpOptions): ReceiptExporter;
|
|
25
|
-
/** The
|
|
26
|
+
/** The exporters a config asks for, as one; undefined when it asks for none. Each is told independently, so one failing never silences another. */
|
|
26
27
|
export declare function openExporter(cfg: {
|
|
27
28
|
otel?: OtelConfig | undefined;
|
|
29
|
+
splunk?: SplunkConfig | undefined;
|
|
28
30
|
}): ReceiptExporter | undefined;
|
package/dist/otel.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { splunkExporter } from "./splunk.js";
|
|
1
2
|
const str = (key, v) => (v === null || v === undefined ? [] : [{ key, value: { stringValue: v } }]);
|
|
2
3
|
const int = (key, v) => [{ key, value: { intValue: String(v) } }];
|
|
3
4
|
/** The span for one receipt, as the OTLP JSON a collector accepts on /v1/traces. Exported so a test or another transport can reuse it. */
|
|
@@ -81,7 +82,21 @@ export function otlpExporter(cfg, opts = {}) {
|
|
|
81
82
|
},
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
|
-
/** The
|
|
85
|
+
/** The exporters a config asks for, as one; undefined when it asks for none. Each is told independently, so one failing never silences another. */
|
|
85
86
|
export function openExporter(cfg) {
|
|
86
|
-
|
|
87
|
+
const all = [];
|
|
88
|
+
if (cfg.otel)
|
|
89
|
+
all.push(otlpExporter(cfg.otel));
|
|
90
|
+
if (cfg.splunk)
|
|
91
|
+
all.push(splunkExporter(cfg.splunk));
|
|
92
|
+
if (all.length === 0)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (all.length === 1)
|
|
95
|
+
return all[0];
|
|
96
|
+
return {
|
|
97
|
+
where: all.map((e) => e.where).join(", "),
|
|
98
|
+
async exported(p, bundle) {
|
|
99
|
+
await Promise.all(all.map((e) => e.exported(p, bundle)));
|
|
100
|
+
},
|
|
101
|
+
};
|
|
87
102
|
}
|
package/dist/signer.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function connectSigner(url, opts = {}) {
|
|
|
30
30
|
const f = opts.fetch ?? fetch;
|
|
31
31
|
const base = url.endsWith("/") ? url : `${url}/`;
|
|
32
32
|
const headers = { "content-type": "application/json", ...(opts.token ? { authorization: `Bearer ${opts.token}` } : {}) };
|
|
33
|
-
const res = await f(new URL("keys", base), { headers });
|
|
33
|
+
const res = await f(new URL("keys", base), { headers, signal: AbortSignal.timeout(10_000) });
|
|
34
34
|
if (!res.ok)
|
|
35
35
|
throw new Error(`signer ${url} refused the key request: ${res.status}`);
|
|
36
36
|
const doc = (await res.json());
|
|
@@ -49,7 +49,7 @@ export async function connectSigner(url, opts = {}) {
|
|
|
49
49
|
return env;
|
|
50
50
|
},
|
|
51
51
|
async keys() {
|
|
52
|
-
const k = await f(new URL("keys", base), { headers });
|
|
52
|
+
const k = await f(new URL("keys", base), { headers, signal: AbortSignal.timeout(10_000) });
|
|
53
53
|
if (!k.ok)
|
|
54
54
|
throw new Error(`signer ${url} refused the key request: ${k.status}`);
|
|
55
55
|
return (await k.json());
|
|
@@ -120,7 +120,7 @@ export function serveSigner(kp, opts) {
|
|
|
120
120
|
}
|
|
121
121
|
/** For verifiers: the keys a log publishes, fetched from its origin and returned as key references pinned by keyid. */
|
|
122
122
|
export async function fetchLogKeys(logUrl, f = fetch) {
|
|
123
|
-
const res = await f(new URL("/.well-known/agent-custody-log.json", logUrl));
|
|
123
|
+
const res = await f(new URL("/.well-known/agent-custody-log.json", logUrl), { signal: AbortSignal.timeout(10_000) });
|
|
124
124
|
if (!res.ok)
|
|
125
125
|
throw new Error(`log ${logUrl} serves no key document: ${res.status}`);
|
|
126
126
|
const doc = (await res.json());
|
package/dist/splunk.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReceiptBundle, ReceiptPredicate } from "./receipt.ts";
|
|
2
|
+
import type { ReceiptExporter } from "./otel.ts";
|
|
3
|
+
export interface SplunkConfig {
|
|
4
|
+
/** the collector's base, e.g. https://splunk.example.com:8088; events go to <url>/services/collector/event */
|
|
5
|
+
url: string;
|
|
6
|
+
/** environment variable holding the HEC token; a missing variable fails at startup */
|
|
7
|
+
tokenEnv: string;
|
|
8
|
+
/** index to write to; omitted, the token's default index */
|
|
9
|
+
index?: string | undefined;
|
|
10
|
+
/** the event's source field; default agent-custody */
|
|
11
|
+
source?: string | undefined;
|
|
12
|
+
/** the event's sourcetype; default agent-custody:receipt */
|
|
13
|
+
sourcetype?: string | undefined;
|
|
14
|
+
/** the event's host field; omitted, the collector fills it in */
|
|
15
|
+
host?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The HEC event for one receipt: flat fields Splunk can search without a props stanza. Exported for tests and other transports. */
|
|
18
|
+
export declare function hecEvent(p: ReceiptPredicate, bundle: ReceiptBundle, cfg: SplunkConfig): Record<string, unknown>;
|
|
19
|
+
export interface SplunkOptions {
|
|
20
|
+
fetch?: typeof fetch;
|
|
21
|
+
env?: Record<string, string | undefined>;
|
|
22
|
+
/** where export failures are reported; default stderr */
|
|
23
|
+
warn?: (message: string) => void;
|
|
24
|
+
}
|
|
25
|
+
/** An exporter that posts each receipt as one event to a Splunk HTTP Event Collector. Failures are reported, never thrown. */
|
|
26
|
+
export declare function splunkExporter(cfg: SplunkConfig, opts?: SplunkOptions): ReceiptExporter;
|
package/dist/splunk.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The HEC event for one receipt: flat fields Splunk can search without a props stanza. Exported for tests and other transports. */
|
|
2
|
+
export function hecEvent(p, bundle, cfg) {
|
|
3
|
+
const auth = p.authorization;
|
|
4
|
+
const exec = p.execution;
|
|
5
|
+
return {
|
|
6
|
+
time: Date.parse(p.timestamp) / 1000,
|
|
7
|
+
source: cfg.source ?? "agent-custody",
|
|
8
|
+
sourcetype: cfg.sourcetype ?? "agent-custody:receipt",
|
|
9
|
+
...(cfg.index ? { index: cfg.index } : {}),
|
|
10
|
+
...(cfg.host ? { host: cfg.host } : {}),
|
|
11
|
+
event: {
|
|
12
|
+
receipt_id: p.receiptId,
|
|
13
|
+
issuer_kind: p.issuer.kind,
|
|
14
|
+
issuer_keyid: p.issuer.keyid,
|
|
15
|
+
tool: p.tool.name,
|
|
16
|
+
upstream: p.tool.upstream ?? null,
|
|
17
|
+
agent: p.agent.id,
|
|
18
|
+
agent_provenance: p.agent.provenance,
|
|
19
|
+
principal: p.principal.id,
|
|
20
|
+
status: exec.status,
|
|
21
|
+
reason: exec.reason ?? exec.error ?? null,
|
|
22
|
+
policy_decision: p.policy?.decision ?? null,
|
|
23
|
+
policy_digest: p.policy?.policyDigest ?? null,
|
|
24
|
+
policy_reasons: p.policy?.reasons ?? [],
|
|
25
|
+
args_digest: p.request.argsDigest,
|
|
26
|
+
log_leaf_index: bundle.inclusion.leafIndex,
|
|
27
|
+
log_tree_size: bundle.inclusion.treeSize,
|
|
28
|
+
authorization_leaf_index: auth ? auth.inclusion.leafIndex : null,
|
|
29
|
+
consumed_count: p.consumed?.factIds.length ?? 0,
|
|
30
|
+
model: p.model.id,
|
|
31
|
+
session: p.session.id,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** An exporter that posts each receipt as one event to a Splunk HTTP Event Collector. Failures are reported, never thrown. */
|
|
36
|
+
export function splunkExporter(cfg, opts = {}) {
|
|
37
|
+
const f = opts.fetch ?? fetch;
|
|
38
|
+
const env = opts.env ?? process.env;
|
|
39
|
+
const warn = opts.warn ?? ((m) => console.error(m));
|
|
40
|
+
const token = env[cfg.tokenEnv];
|
|
41
|
+
if (!token)
|
|
42
|
+
throw new Error(`splunk: environment variable ${cfg.tokenEnv} is not set`);
|
|
43
|
+
const headers = { "content-type": "application/json", authorization: `Splunk ${token}` };
|
|
44
|
+
const base = cfg.url.endsWith("/") ? cfg.url : `${cfg.url}/`;
|
|
45
|
+
const url = new URL("services/collector/event", base);
|
|
46
|
+
return {
|
|
47
|
+
where: cfg.url,
|
|
48
|
+
async exported(p, bundle) {
|
|
49
|
+
try {
|
|
50
|
+
const res = await f(url, { method: "POST", headers, body: JSON.stringify(hecEvent(p, bundle, cfg)), signal: AbortSignal.timeout(5000) });
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
warn(`agent-custody: splunk export of receipt ${p.receiptId} refused by ${cfg.url}: ${res.status}`);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
warn(`agent-custody: splunk export of receipt ${p.receiptId} failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/witness.js
CHANGED
|
@@ -145,7 +145,7 @@ export class Witness {
|
|
|
145
145
|
}
|
|
146
146
|
/** For verifiers: the witness's published keys, fetched from its host and pinned by keyid. */
|
|
147
147
|
export async function fetchWitnessKeys(witnessUrl, f = fetch) {
|
|
148
|
-
const res = await f(new URL("/.well-known/agent-custody-witness.json", witnessUrl));
|
|
148
|
+
const res = await f(new URL("/.well-known/agent-custody-witness.json", witnessUrl), { signal: AbortSignal.timeout(10_000) });
|
|
149
149
|
if (!res.ok)
|
|
150
150
|
throw new Error(`witness ${witnessUrl} serves no key document: ${res.status}`);
|
|
151
151
|
const doc = (await res.json());
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# What the evidence satisfies
|
|
2
|
+
|
|
3
|
+
Auditors ask for controls by their names. This page maps the requirements they cite most to the artefacts agent-custody produces, so a security questionnaire can be answered with a file rather than a paragraph. It is a map, not a certificate: the artefacts are evidence that a control operated, and the control itself, the policy, the grant, the retention window, the person who reviews an alarm, is yours.
|
|
4
|
+
|
|
5
|
+
Two rules keep the answers honest. First, say which producer made the receipt: a gateway receipt was enforced outside the agent's process, an SDK receipt is the agent's own report, and the receipt's `issuer.kind` says which. Second, say where the log runs: with the default local log the operator can rewrite history, with a log run by someone else they cannot, and with a witness neither operator can. The [proof table](../README.md#what-a-receipt-proves-and-what-it-does-not) has the full list of claims and against whom each holds.
|
|
6
|
+
|
|
7
|
+
## The artefacts
|
|
8
|
+
|
|
9
|
+
| artefact | what it is | how to produce it |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| receipt | one signed record per tool call: who authorized it, what the agent saw, what it did, the policy decision, its position in the log | issued by the gateway or the SDK; `receipts/<id>.json` |
|
|
12
|
+
| authorization | the same, committed to the log before a consequential call was forwarded | `precommit` in the gateway config |
|
|
13
|
+
| verification report | the check list a third party gets from the receipt and public keys alone | `agent-custody verify` |
|
|
14
|
+
| audit | proof that the log at a later size extends its earlier state | `agent-custody audit` between any two tree heads or checkpoints |
|
|
15
|
+
| checkpoint | a signed tree head published on a schedule, countersigned by a witness where one runs | the log's checkpoints host, the witness's host |
|
|
16
|
+
| action pack | one receipt explained and packed with every downstream receipt, signed | `agent-custody-memory explain --out --sign` |
|
|
17
|
+
| custody pack | one fact's history, receipts, blast radius, holds, and forget certificate, signed | `agent-custody-memory pack` |
|
|
18
|
+
| forget certificate | the receipt of the call that erased a value from the ledger and the stores, with each store's answer | `memory.forget` through the gateway |
|
|
19
|
+
| eval report | scores for stale reads, contradictions, and blast radius after retraction, signed | `agent-custody-memory eval --sign` |
|
|
20
|
+
| usage | appends per tenant per month on the hosted log | `/admin/usage.csv` |
|
|
21
|
+
|
|
22
|
+
## SOC 2, Trust Services Criteria
|
|
23
|
+
|
|
24
|
+
| criterion | what it asks | what answers it |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| CC6.1, logical access | access to systems is restricted to authorized users | the delegation grant: a human-signed statement of which agent may call which tools, for how long, embedded in every gateway receipt and re-checked by the verifier |
|
|
27
|
+
| CC6.3, authorization changes | access is granted, modified, and removed by authorized parties | grants have validity windows and are signed by a principal key the gateway is configured to trust; a new grant is a new signed file, a revoked one expires |
|
|
28
|
+
| CC7.2, monitoring for anomalies | the entity monitors system components for anomalies | every call has a receipt, allowed or denied, and `explain` answers who, why, and what depended on it; the OpenTelemetry and Splunk exports carry each receipt into the existing SIEM |
|
|
29
|
+
| CC7.3, evaluation of security events | events are evaluated to determine whether they are incidents | the action pack: one receipt with every downstream receipt, verifiable by the evaluator without access to the system |
|
|
30
|
+
| CC7.4, incident response | incidents are contained and remediated | blast radius names every action and belief that depended on a wrong fact; retract and forget are receipted calls, so the remediation has its own evidence |
|
|
31
|
+
| CC8.1, change management | changes are authorized and tracked | the policy digest in every receipt identifies the exact policy that decided the call, so a policy change is visible in the receipts on either side of it |
|
|
32
|
+
|
|
33
|
+
## ISO/IEC 27001:2022, Annex A
|
|
34
|
+
|
|
35
|
+
| control | what it asks | what answers it |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| A.5.15, access control | rules for access based on business requirements | the grant and the Cedar policy, with the policy decision on facts the gateway fetched itself |
|
|
38
|
+
| A.5.28, collection of evidence | evidence is collected in a form that stands up | receipts are signed, hashed into a Merkle log, and verifiable offline; the audit proves nothing was rewritten between two points; the packs are single signed artefacts for a case file |
|
|
39
|
+
| A.8.10, information deletion | information is deleted when no longer required | forget erases a value from the ledger and the adapted stores and the receipt is the certificate, with each store's own answer; retention sweeps run as receipted calls; a legal hold refuses both |
|
|
40
|
+
| A.8.15, logging | logs are produced, stored, protected, and analysed | the transparency log, append-only and hashed, with a log run by someone else where the operator must not be trusted |
|
|
41
|
+
| A.8.16, monitoring activities | networks, systems, and applications are monitored | `log-check` from a machine that is not the log's, and the per-receipt spans in the SIEM |
|
|
42
|
+
| A.8.32, change management | changes are subject to change management | the policy digest, the grant's window, and the receipts either side of a change |
|
|
43
|
+
|
|
44
|
+
## EU AI Act, obligations on high-risk systems and their deployers
|
|
45
|
+
|
|
46
|
+
| article | what it asks | what answers it |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| Article 12, record-keeping | automatic recording of events over the system's lifetime, enabling traceability | one receipt per tool call, in a tamper-evident log, with the facts the agent was shown and the beliefs it wrote; `explain` traces any action to its causes and consequences |
|
|
49
|
+
| Article 14, human oversight | humans can understand, oversee, and intervene | the grant is a human's signature over what the agent may do; the policy decides on facts the agent did not supply; retract and forget are the intervention, receipted |
|
|
50
|
+
| Article 19, retention of logs | logs are kept for a period appropriate to the purpose | retention windows per space in the memory server; `prune` on the receipt log keeps every proof valid while the content is gone; a legal hold overrides both |
|
|
51
|
+
| Article 26, deployer obligations | deployers keep logs and monitor operation | the same receipts and the same monitor; a tenant on the hosted log has its own log id and checkpoints an auditor can fetch |
|
|
52
|
+
|
|
53
|
+
## UK GDPR
|
|
54
|
+
|
|
55
|
+
| provision | what it asks | what answers it |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| Article 5(2), accountability | the controller demonstrates compliance | signed receipts and packs demonstrate what was done and why, to a party who has no access to the controller's systems |
|
|
58
|
+
| Article 17, right to erasure | personal data is erased on request | the forget certificate, including `stillIndexed` when a store has not caught up, which is what an honest response to a data subject says |
|
|
59
|
+
| Article 30, records of processing | records of processing activities are kept | the receipts, and the memory ledger's history of every fact with its source receipt |
|
|
60
|
+
| Article 32, security of processing | appropriate technical measures | the hosted log holds hashes only, and receipts stay with the controller |
|
|
61
|
+
|
|
62
|
+
## What no artefact here claims
|
|
63
|
+
|
|
64
|
+
That the agent's arguments were correct, that the model named in a receipt produced the call, that the upstream executed the action unless it signed the result or a provider delivery is embedded, or that an SDK receipt was enforced outside the agent. The [proof table](../README.md#what-a-receipt-proves-and-what-it-does-not) says so, and a questionnaire answer that repeats it will survive the reviewer who checks.
|
package/docs/sdk.md
CHANGED
|
@@ -30,7 +30,7 @@ Use the SDK for reach. Use the gateway for anything that moves money, touches pr
|
|
|
30
30
|
|
|
31
31
|
`policyFile` and `principalId` are optional. Without a policy the SDK records and never denies. Paths resolve relative to the config file. Instead of `logFile`, `"log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }` sends every leaf to a log run by someone else, whose key then signs the tree heads; see [usage.md](usage.md) for what that changes and [verification.md](verification.md) for what it proves. Generate the key with `node src/cli.ts keygen --dir keys --name app`.
|
|
32
32
|
|
|
33
|
-
`"otel": { "url": "http://localhost:4318" }` additionally exports every receipt as one span to that OTLP/HTTP collector, after the receipt is written, with the receipt id as the trace id; see the [usage guide](usage.md#setup-step-by-step) for the fields. Export never blocks or fails a receipt.
|
|
33
|
+
`"otel": { "url": "http://localhost:4318" }` additionally exports every receipt as one span to that OTLP/HTTP collector, after the receipt is written, with the receipt id as the trace id; see the [usage guide](usage.md#setup-step-by-step) for the fields. Export never blocks or fails a receipt. `"splunk": { "url": ..., "tokenEnv": "HEC_TOKEN" }` does the same to a Splunk HTTP Event Collector, one event per receipt with the receipt id and log position as fields; both blocks may be set together.
|
|
34
34
|
|
|
35
35
|
Policies see `context.args` and an empty `context.facts`. A policy that reads `context.facts` or `context.grant` errors, which is a deny. That is intended: an SDK policy cannot pretend it checked something outside the agent's process.
|
|
36
36
|
|
package/docs/tutorials.md
CHANGED
|
@@ -28,6 +28,7 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
28
28
|
| 16 | consequential tools, committed first | [16-precommit.ts](../examples/16-precommit.ts) | a refund named in `precommit`: the authorization leaf before the receipt leaf, the five authorization checks in the report, and the same call withheld when the log refuses | `src/gateway.ts`, `src/issue.ts`, `src/verify.ts` |
|
|
29
29
|
| 17 | a REST API as an upstream | [17-rest-upstream.ts](../examples/17-rest-upstream.ts) | a stand-in payments API described as two tools, the token from the environment, a refund allowed on the gateway's own lookup and one denied before reaching the API, the receipt verified | `src/rest.ts`, `src/gateway.ts` |
|
|
30
30
|
| 18 | OpenTelemetry export | [18-opentelemetry.ts](../examples/18-opentelemetry.ts) | a stand-in OTLP collector, `otel` in the config, one span per receipt with the receipt id as trace id, the collector going away and the next receipt still issued | `src/otel.ts`, `src/issue.ts` |
|
|
31
|
+
| 19 | Splunk export | [19-splunk.ts](../examples/19-splunk.ts) | a stand-in HTTP Event Collector, `splunk` in the config with the token from the environment, one event per receipt with the receipt id and log position as fields, the collector going away and the next receipt still issued | `src/splunk.ts`, `src/otel.ts` |
|
|
31
32
|
|
|
32
33
|
## How policies are defined, in one paragraph
|
|
33
34
|
|
package/docs/usage.md
CHANGED
|
@@ -105,10 +105,12 @@ An upstream need not be an MCP server. A plain HTTP API is described as tools:
|
|
|
105
105
|
"log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. If the log refuses a leaf, the receipt is not issued and the call returns an error to the agent. For an ordinary call the upstream action has already happened by then, and the error says so; a receipt that was never logged must not be handed out. For a tool named in `precommit` the order is reversed, below, and the action never happens. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]`, `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Nothing is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
|
|
108
|
+
Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log refuses a leaf, the receipt is not issued and the call returns an error to the agent. For an ordinary call the upstream action has already happened by then, and the error says so; a receipt that was never logged must not be handed out. For a tool named in `precommit` the order is reversed, below, and the action never happens. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]`, `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Nothing is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, and their own usage (`GET /t/<name>/usage?month=`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
|
|
109
109
|
|
|
110
110
|
`otel`, optional in both the gateway and SDK configs, sends every receipt to the collector you already run as one span over OTLP/HTTP, after the receipt is issued: `"otel": { "url": "http://localhost:4318", "headersEnv": { "x-api-key": "OTEL_KEY" }, "serviceName": "support-agents" }`. The span's trace id is the receipt id, its attributes carry the tool, agent, principal, execution status, policy decision, and log position, and its status is an error only when the upstream failed or errored, since a denial is the policy working. Export is best effort: a collector that is down or refuses costs a line on stderr, never a receipt. Tutorial 18 shows it against a stand-in collector.
|
|
111
111
|
|
|
112
|
+
`splunk`, optional in both configs and usable beside `otel`, sends every receipt to a Splunk HTTP Event Collector as one event: `"splunk": { "url": "https://splunk.example.com:8088", "tokenEnv": "HEC_TOKEN", "index": "agents" }`, with optional `source` (default `agent-custody`), `sourcetype` (default `agent-custody:receipt`), and `host`. The token is read from the named environment variable at startup and never appears in the config. Each event carries `receipt_id`, `tool`, `agent`, `principal`, `status`, `reason`, `policy_decision`, `policy_digest`, `args_digest`, `log_leaf_index`, `log_tree_size`, and `authorization_leaf_index` as plain fields, so a search like `sourcetype="agent-custody:receipt" status=denied` needs no field extraction and every alert leads to the receipt by id. The same rule holds: the event is a copy, the receipt is the evidence, and a collector outage costs a warning. Tutorial 19 shows it.
|
|
113
|
+
|
|
112
114
|
`facts` tells the gateway which upstream tool to call before evaluating policy for a given tool. `$args.<key>` copies a value from the intercepted call. The result appears in Cedar as `context.facts.<name>` and in the receipt with its own digest, labelled `observed`. If a fact lookup fails, the call is denied and the receipt says why. A lookup with `"optional": true` is skipped when a `$args.<key>` it needs is absent from the call, and the fact is then simply not present, which a policy tests with `context.facts has <name>`; this is how a policy sees the fact a `memory.write` is about to supersede without denying every write that supersedes nothing.
|
|
113
115
|
|
|
114
116
|
`precommit` names the consequential tools, or `["*"]` for all of them. For every other tool the gateway forwards the call and then records it, so if the log is unreachable at that moment the side effect exists before its evidence does. For a tool in `precommit` the gateway first signs an authorization statement, everything the receipt will say except the outcome, and appends it to the log. Only if the log took it does the call go upstream. The receipt then embeds that authorization with its own inclusion proof, and a verifier checks that it names this call and sits in the log before the receipt does. If the log will not take it, the call is not forwarded, the agent is told `Not executed`, and the receipt records `execution.status: "withheld"` with the policy's `allow` beside it. The authorization is also written on its own as `receipts/<receiptId>.authorization.json`, which is the evidence that survives if the gateway dies between forwarding and the receipt. Use it for money, for anything irreversible, and for anything a counterparty could later dispute; the cost is one extra log append per call.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/receipts",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Chain of custody for AI agents: signed, independently verifiable receipts for tool calls. MCP gateway + Cedar policy + Merkle transparency log",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|