@agent-custody/receipts 0.6.18 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -11
- package/dist/a2a.d.ts +93 -0
- package/dist/a2a.js +391 -0
- package/dist/capture.d.ts +153 -0
- package/dist/capture.js +559 -0
- package/dist/cli.js +117 -5
- package/dist/config.d.ts +92 -0
- package/dist/config.js +34 -2
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +7 -4
- package/dist/delegation.d.ts +7 -0
- package/dist/delegation.js +15 -1
- package/dist/gateway-http.js +13 -1
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.js +136 -13
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/issue.d.ts +14 -4
- package/dist/issue.js +66 -7
- package/dist/log-sink.d.ts +11 -1
- package/dist/log-sink.js +24 -5
- package/dist/otel.js +5 -4
- package/dist/portal.d.ts +23 -2
- package/dist/portal.js +181 -36
- package/dist/receipt.d.ts +19 -8
- package/dist/retention.d.ts +8 -1
- package/dist/retention.js +21 -2
- package/dist/sdk/index.js +10 -1
- package/dist/splunk.js +6 -4
- package/dist/upstream.d.ts +9 -7
- package/dist/upstream.js +16 -8
- package/dist/verify.d.ts +16 -0
- package/dist/verify.js +171 -13
- package/docs/compliance.md +9 -3
- package/docs/sdk.md +19 -0
- package/docs/tutorials.md +5 -0
- package/docs/usage.md +68 -3
- package/docs/verification.md +11 -4
- package/package.json +4 -3
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1394 -270
package/dist/upstream.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// upstream's key checks it. Provider-native formats, such as Stripe's webhook signatures, are adapters on top of this.
|
|
5
5
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
6
6
|
import { digestOf, dsseSign, dsseVerify } from "./crypto.js";
|
|
7
|
+
import { isCommitment } from "./capture.js";
|
|
7
8
|
export const UPSTREAM_SIG_META_KEY = "agent-custody/upstream-signature";
|
|
8
9
|
export const UPSTREAM_TYPE = "application/vnd.agent-custody.upstream+json";
|
|
9
10
|
export function contentDigest(result) {
|
|
@@ -37,7 +38,8 @@ export function checkUpstream(envelope, keys, expected) {
|
|
|
37
38
|
}
|
|
38
39
|
export function isProviderAttestation(v) {
|
|
39
40
|
const p = v;
|
|
40
|
-
|
|
41
|
+
const stringOrCommitment = (v) => typeof v === "string" || isCommitment(v);
|
|
42
|
+
return !!p && (p.provider === "stripe-webhook" || p.provider === "github-delivery") && stringOrCommitment(p.rawBody) && stringOrCommitment(p.signature) && stringOrCommitment(p.bind);
|
|
41
43
|
}
|
|
42
44
|
/** For upstreams wrapping a provider: attaches the provider's own delivery for this call. */
|
|
43
45
|
export function attachProviderAttestation(result, attestation) {
|
|
@@ -54,13 +56,17 @@ export function upstreamEvidenceOf(result) {
|
|
|
54
56
|
const pathValue = (body, path) => path.split(".").reduce((v, k) => (v && typeof v === "object" ? v[k] : undefined), body);
|
|
55
57
|
/** Stripe: header `t=<unix>,v1=<hex>`, HMAC-SHA256 over `<t>.<rawBody>`; GitHub: header `sha256=<hex>` over rawBody. */
|
|
56
58
|
export function checkProvider(att, secrets, ctx) {
|
|
59
|
+
if (typeof att.rawBody !== "string" || typeof att.signature !== "string" || typeof att.bind !== "string")
|
|
60
|
+
return { ok: false, error: "the delivery body, signature, or bind is withheld; disclose them or give the capture key" };
|
|
61
|
+
const signature = att.signature;
|
|
62
|
+
const bind = att.bind;
|
|
57
63
|
const secret = att.provider === "stripe-webhook" ? secrets.stripe : secrets.github;
|
|
58
64
|
if (!secret)
|
|
59
65
|
return { ok: false, error: `no ${att.provider === "stripe-webhook" ? "Stripe" : "GitHub"} secret given` };
|
|
60
66
|
const hmac = (data) => createHmac("sha256", secret).update(data).digest("hex");
|
|
61
67
|
const equal = (a, b) => a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
62
68
|
if (att.provider === "stripe-webhook") {
|
|
63
|
-
const parts = Object.fromEntries(
|
|
69
|
+
const parts = Object.fromEntries(signature.split(",").map((kv) => kv.split("=")));
|
|
64
70
|
const t = parts.t;
|
|
65
71
|
const v1 = parts.v1;
|
|
66
72
|
if (!t || !v1)
|
|
@@ -72,7 +78,7 @@ export function checkProvider(att, secrets, ctx) {
|
|
|
72
78
|
return { ok: false, error: `Stripe timestamp is ${Math.round(skew)}s from the receipt, beyond tolerance` };
|
|
73
79
|
}
|
|
74
80
|
else {
|
|
75
|
-
const hex =
|
|
81
|
+
const hex = signature.startsWith("sha256=") ? signature.slice(7) : "";
|
|
76
82
|
if (!hex || !equal(hmac(att.rawBody), hex))
|
|
77
83
|
return { ok: false, error: "GitHub signature does not verify with this secret" };
|
|
78
84
|
}
|
|
@@ -83,12 +89,14 @@ export function checkProvider(att, secrets, ctx) {
|
|
|
83
89
|
catch {
|
|
84
90
|
return { ok: false, error: "delivery body is not JSON" };
|
|
85
91
|
}
|
|
86
|
-
const bound = pathValue(body,
|
|
92
|
+
const bound = pathValue(body, bind);
|
|
87
93
|
if (bound === undefined || bound === null || bound === "")
|
|
88
|
-
return { ok: false, error: `delivery has no value at ${
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
return { ok: false, error: `delivery has no value at ${bind}` };
|
|
95
|
+
// what the agent received: the content and the flag, never _meta, which carries the delivery itself and so always contains the bound value
|
|
96
|
+
const received = ctx.result;
|
|
97
|
+
if (!JSON.stringify({ content: received.content, isError: received.isError, structuredContent: received.structuredContent }).includes(JSON.stringify(bound).replace(/^"|"$/g, "")))
|
|
98
|
+
return { ok: false, error: `delivery's ${bind} (${String(bound)}) does not appear in the receipt's result` };
|
|
99
|
+
return { ok: true, keyid: `shared secret (${att.provider}, bound on ${bind})` };
|
|
92
100
|
}
|
|
93
101
|
/** For fake providers and tests: a Stripe-Signature header for a body at a time. */
|
|
94
102
|
export function stripeSignature(rawBody, secret, unixSeconds) {
|
package/dist/verify.d.ts
CHANGED
|
@@ -20,12 +20,28 @@ export interface VerifyOptions {
|
|
|
20
20
|
logFile?: string;
|
|
21
21
|
/** If given, every tree head in the bundle must name this log, so a head from another tenant's log cannot be presented as this one's. */
|
|
22
22
|
logId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The withheld values, as `agent-custody reveal` writes them or the party that holds them hands them over: a partial
|
|
25
|
+
* predicate with `{ $custody: "disclosed", salt, value }` at each withheld path (`{ receiptId, request: { args: { reason: {...} } }, execution: { result: { content: {...} }, error, upstream: { rawBody } }, policy: { errors }, facts: { <name>: { value, args } } }`).
|
|
26
|
+
* The digests are then recomputed and every disclosed value checked against its commitment under its salt.
|
|
27
|
+
*/
|
|
28
|
+
disclosed?: Record<string, unknown> & {
|
|
29
|
+
receiptId?: string;
|
|
30
|
+
};
|
|
31
|
+
/** the customer's capture key: encrypted fields are revealed and the digests recomputed */
|
|
32
|
+
captureKey?: Buffer;
|
|
23
33
|
}
|
|
24
34
|
export interface VerifyResult {
|
|
25
35
|
ok: boolean;
|
|
26
36
|
checks: Check[];
|
|
27
37
|
statement: ReceiptStatement | null;
|
|
28
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Why a statement cannot be verified at all, or null: the capture note is malformed, names a structural part, or a
|
|
41
|
+
* structural part is not what every check assumes it to be. Checked once, before anything reads the statement, so that
|
|
42
|
+
* a crafted note cannot hide the status, the tool, the decision, or the digests behind a commitment and still verify.
|
|
43
|
+
*/
|
|
44
|
+
export declare function structuralProblem(p: unknown): string | null;
|
|
29
45
|
export declare function verifyBundle(bundle: ReceiptBundle, opts: VerifyOptions): VerifyResult;
|
|
30
46
|
export interface AuditResult {
|
|
31
47
|
ok: boolean;
|
package/dist/verify.js
CHANGED
|
@@ -1,10 +1,63 @@
|
|
|
1
1
|
// Independent verification of a receipt bundle. Needs only public keys, and optionally a copy of the log.
|
|
2
2
|
import { canonicalize, digestOf, dsseVerifiers, dsseVerify } from "./crypto.js";
|
|
3
|
+
import { digestSaltFor, getAt, isCommitment, pathKey, pathText, restorePaths, under } from "./capture.js";
|
|
3
4
|
import { delegationHasParent, delegationValidAt, describeChain, verifyDelegation } from "./delegation.js";
|
|
4
5
|
import { leafHash, MerkleLog, verifyConsistency, verifyInclusion } from "./log.js";
|
|
5
6
|
import { checkProvider, checkUpstream, contentDigest, isProviderAttestation } from "./upstream.js";
|
|
6
7
|
import { AUTHORIZATION_PREDICATE_TYPE, RECEIPT_PREDICATE_TYPE, RECEIPT_TYPE, TREEHEAD_TYPE } from "./receipt.js";
|
|
7
8
|
const short = (s) => s.slice(0, 12);
|
|
9
|
+
const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
10
|
+
/** The parts of a statement a capture note may never name: what a verifier reads to run its checks. A note naming one, or a commitment sitting there, is not a private receipt but a broken one. */
|
|
11
|
+
const STRUCTURAL_TOP = new Set(["receiptId", "timestamp", "issuer", "principal", "agent", "delegation", "tool", "authorization", "capture"]);
|
|
12
|
+
const STRUCTURAL_IN = { request: new Set(["argsDigest", "provenance"]), execution: new Set(["status", "provenance"]), policy: new Set(["decision", "reasons", "policyDigest", "enforced", "provenance"]), consumed: new Set(["provenance"]), session: new Set(["provenance"]), model: new Set(["provenance"]) };
|
|
13
|
+
/**
|
|
14
|
+
* Why a statement cannot be verified at all, or null: the capture note is malformed, names a structural part, or a
|
|
15
|
+
* structural part is not what every check assumes it to be. Checked once, before anything reads the statement, so that
|
|
16
|
+
* a crafted note cannot hide the status, the tool, the decision, or the digests behind a commitment and still verify.
|
|
17
|
+
*/
|
|
18
|
+
export function structuralProblem(p) {
|
|
19
|
+
if (!isObject(p))
|
|
20
|
+
return "the predicate is not an object";
|
|
21
|
+
const note = p.capture;
|
|
22
|
+
if (note !== undefined) {
|
|
23
|
+
if (!isObject(note) || (note.mode !== "digest" && note.mode !== "encrypted") || !Array.isArray(note.withheld))
|
|
24
|
+
return "the capture note is malformed";
|
|
25
|
+
if (new Set(note.withheld.map((w) => JSON.stringify(w))).size !== note.withheld.length)
|
|
26
|
+
return "the capture note names a path twice";
|
|
27
|
+
for (const w of note.withheld) {
|
|
28
|
+
if (!Array.isArray(w) || w.length === 0 || !w.every((s) => typeof s === "string"))
|
|
29
|
+
return "the capture note names a malformed path";
|
|
30
|
+
const path = w;
|
|
31
|
+
const head = path[0];
|
|
32
|
+
const named = STRUCTURAL_TOP.has(head) || (path.length === 1 && Object.hasOwn(STRUCTURAL_IN, head)) || (path.length === 2 && Object.hasOwn(STRUCTURAL_IN, head) && STRUCTURAL_IN[head].has(path[1])) || head === "facts" && (path.length <= 2 || path[2] === "tool" || path[2] === "provenance") || (head === "execution" && path.length === 2 && path[1] === "upstream") || (head === "execution" && path.length === 3 && path[1] === "upstream" && path[2] === "provider") || (head === "execution" && path.length === 3 && path[1] === "result" && path[2] === "isError");
|
|
33
|
+
if (named)
|
|
34
|
+
return `the capture note names a structural part: ${pathText(path)}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (typeof p.receiptId !== "string" || typeof p.timestamp !== "string")
|
|
38
|
+
return "receiptId or timestamp is not a string";
|
|
39
|
+
if (!isObject(p.issuer) || !isObject(p.principal) || !isObject(p.agent) || !isObject(p.session) || !isObject(p.model))
|
|
40
|
+
return "issuer, principal, agent, session, or model is not an object";
|
|
41
|
+
if (!isObject(p.tool) || typeof p.tool.name !== "string")
|
|
42
|
+
return "tool.name is not a string";
|
|
43
|
+
if (!isObject(p.request) || typeof p.request.argsDigest !== "string" || !isObject(p.request.args))
|
|
44
|
+
return "request.args or request.argsDigest is not what it should be";
|
|
45
|
+
if (!isObject(p.execution) || !["executed", "failed", "denied", "error", "withheld"].includes(String(p.execution.status)))
|
|
46
|
+
return "execution.status is not a status";
|
|
47
|
+
if (p.policy !== null && (!isObject(p.policy) || (p.policy.decision !== "allow" && p.policy.decision !== "deny") || !Array.isArray(p.policy.reasons)))
|
|
48
|
+
return "policy is neither null nor a decision";
|
|
49
|
+
if (!isObject(p.facts) || Object.values(p.facts).some((f) => !isObject(f) || typeof f.tool !== "string"))
|
|
50
|
+
return "facts is not a map of facts";
|
|
51
|
+
if (p.consumed !== undefined && !isObject(p.consumed))
|
|
52
|
+
return "consumed is not an object";
|
|
53
|
+
if (p.delegation !== undefined && (!isObject(p.delegation) || !isObject(p.delegation.envelope)))
|
|
54
|
+
return "delegation is not a signed envelope";
|
|
55
|
+
if (p.authorization !== undefined && (!isObject(p.authorization) || !isObject(p.authorization.envelope)))
|
|
56
|
+
return "authorization is not a bundle";
|
|
57
|
+
if (isObject(p.execution.upstream) && typeof p.execution.upstream.provider !== "undefined" && typeof p.execution.upstream.provider !== "string")
|
|
58
|
+
return "execution.upstream.provider is not a string";
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
8
61
|
export function verifyBundle(bundle, opts) {
|
|
9
62
|
const checks = [];
|
|
10
63
|
const add = (name, ok, detail) => {
|
|
@@ -21,6 +74,9 @@ export function verifyBundle(bundle, opts) {
|
|
|
21
74
|
const st = sig.payload;
|
|
22
75
|
if (!add("receipt payload type", bundle.envelope.payloadType === RECEIPT_TYPE && st.predicateType === RECEIPT_PREDICATE_TYPE))
|
|
23
76
|
return done(null);
|
|
77
|
+
const broken = structuralProblem(st.predicate);
|
|
78
|
+
if (!add("structural parts in clear", !broken, broken ?? undefined))
|
|
79
|
+
return done(null);
|
|
24
80
|
const p = st.predicate;
|
|
25
81
|
add("issuer kind is known", p.issuer.kind === "gateway" || p.issuer.kind === "sdk", `${p.issuer.kind}${p.issuer.framework ? ` / ${p.issuer.framework}` : ""}`);
|
|
26
82
|
add("issuer keyid matches signer", p.issuer.keyid === sig.keyid);
|
|
@@ -40,34 +96,135 @@ export function verifyBundle(bundle, opts) {
|
|
|
40
96
|
const d = del.delegation;
|
|
41
97
|
const principalKeyid = p.principal.provenance === "attested" ? p.principal.keyid : null;
|
|
42
98
|
add("delegation binds principal and agent", d.principal === p.principal.id && d.agent === p.agent.id && del.keyid === principalKeyid);
|
|
43
|
-
add("delegation valid at receipt time", delegationValidAt(d, p.timestamp), `${d.issuedAt} .. ${d.expiresAt}`);
|
|
44
99
|
const inScope = d.scopes.includes(p.tool.name);
|
|
45
100
|
const executed = p.execution.status === "executed" || p.execution.status === "failed";
|
|
101
|
+
// a call the gateway refused after the grant ran out is still a true record; only an executed call has to sit inside the window
|
|
102
|
+
const valid = delegationValidAt(d, p.timestamp);
|
|
103
|
+
add("delegation valid at receipt time", valid || !executed, valid ? `${d.issuedAt} .. ${d.expiresAt}` : `${d.issuedAt} .. ${d.expiresAt}; the call was ${p.execution.status}, so the grant need not have been in force`);
|
|
46
104
|
add("executed tool within delegated scope", !executed || inScope, inScope ? p.tool.name : `${p.tool.name} not in [${d.scopes.join(", ")}]`);
|
|
47
105
|
}
|
|
48
106
|
}
|
|
49
107
|
else {
|
|
50
108
|
add("principal is claimed, not attested", p.principal.provenance === "claimed", "no signed delegation in this receipt");
|
|
51
109
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
110
|
+
// Private evidence: the signed capture note names every path whose value is withheld behind a commitment. Each path
|
|
111
|
+
// is put back when the receipt carries the value, when it is disclosed, or when the capture key reveals it; a digest
|
|
112
|
+
// over values that are all back is recomputed (with the salt the statement carries), and otherwise the check passes
|
|
113
|
+
// as a commitment and says so. The note decides, never the shape of the data: a path it names must hold a
|
|
114
|
+
// commitment, and commitment-shaped data it does not name is ordinary data, inside the digest.
|
|
115
|
+
const subjectOk = st.subject[0]?.digest.sha256 === p.request.argsDigest;
|
|
116
|
+
const note = p.capture;
|
|
117
|
+
if (opts.disclosed && typeof opts.disclosed === "object" && "receiptId" in opts.disclosed && opts.disclosed.receiptId !== undefined) {
|
|
118
|
+
add("disclosure names this receipt", opts.disclosed.receiptId === p.receiptId, opts.disclosed.receiptId === p.receiptId ? undefined : `the disclosure is for receipt ${String(opts.disclosed.receiptId)}`);
|
|
119
|
+
}
|
|
120
|
+
const back = restorePaths(p, note, opts.disclosed, opts.captureKey);
|
|
121
|
+
const full = back.predicate;
|
|
122
|
+
const committedNote = (paths) => {
|
|
123
|
+
const encrypted = paths.filter((w) => getAt(p, w)?.$custody === "encrypted").length;
|
|
124
|
+
return `committed, not recomputed: ${paths.length} value(s) withheld${encrypted ? ` (${encrypted} encrypted)` : ""}; ${encrypted ? "give the capture key or " : ""}disclose them to recompute`;
|
|
125
|
+
};
|
|
126
|
+
const claimed = new Set();
|
|
127
|
+
/** the state of the withheld paths under a prefix, and the paths it claims for its check line */
|
|
128
|
+
const region = (prefix) => {
|
|
129
|
+
const paths = (note?.withheld ?? []).filter((w) => under(w, prefix));
|
|
130
|
+
for (const w of paths)
|
|
131
|
+
claimed.add(pathKey(w));
|
|
132
|
+
const problem = back.problems.find((x) => under(x.path, prefix))?.error ?? null;
|
|
133
|
+
const missing = back.missing.filter((w) => under(w, prefix));
|
|
134
|
+
const hows = [...new Set(paths.map((w) => back.restored.get(pathKey(w))).filter((h) => !!h))];
|
|
135
|
+
const how = hows.length === 2 ? "disclosed and decrypted" : hows[0];
|
|
136
|
+
return { paths, problem, missing, how };
|
|
137
|
+
};
|
|
138
|
+
const args = region(["request", "args"]);
|
|
139
|
+
if (args.problem)
|
|
140
|
+
add("request args digest", false, args.problem);
|
|
141
|
+
else if (args.missing.length)
|
|
142
|
+
add("request args digest", subjectOk, committedNote(args.missing));
|
|
143
|
+
else
|
|
144
|
+
add("request args digest", digestOf(full.request.args, digestSaltFor(back, note, ["request", "args"])) === p.request.argsDigest && subjectOk, args.how ? `recomputed from ${args.how} values` : undefined);
|
|
145
|
+
// a captured fact: its commitments are checked against a disclosure or the key; the policy decided on the real value
|
|
146
|
+
for (const name of Object.keys(p.facts)) {
|
|
147
|
+
for (const part of ["value", "args"]) {
|
|
148
|
+
const r = region(["facts", name, part]);
|
|
149
|
+
if (!r.paths.length)
|
|
150
|
+
continue;
|
|
151
|
+
if (r.problem)
|
|
152
|
+
add(`fact ${name} ${part}`, false, r.problem);
|
|
153
|
+
else
|
|
154
|
+
add(`fact ${name} ${part}`, true, r.missing.length ? committedNote(r.missing) : `commitments hold against the ${r.how} value`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const executedOrFailed = p.execution.status === "executed" || p.execution.status === "failed";
|
|
158
|
+
let result = null;
|
|
159
|
+
if (executedOrFailed) {
|
|
160
|
+
const r = region(["execution", "result"]);
|
|
161
|
+
const ex = full.execution;
|
|
162
|
+
if (r.problem)
|
|
163
|
+
add("execution result digest", false, r.problem);
|
|
164
|
+
else if (r.missing.length) {
|
|
165
|
+
add("execution result digest", true, committedNote(r.missing));
|
|
166
|
+
// the upstream checks read the content, isError, and structuredContent, never _meta, which carries what the
|
|
167
|
+
// upstream wrote and is withheld beside a result the rule leaves in clear: with only _meta withheld they still run
|
|
168
|
+
if (r.missing.every((w) => pathKey(w) === pathKey(["execution", "result", "_meta"])))
|
|
169
|
+
result = ex.result;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
add("execution result digest", digestOf(ex.result, digestSaltFor(back, note, ["execution", "result"])) === ex.resultDigest, r.how ? `recomputed from ${r.how} values` : undefined);
|
|
173
|
+
result = ex.result;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// every other withheld path gets its own line: a message, a denial reason, a provider's delivery body, a part added later
|
|
177
|
+
for (const w of note?.withheld ?? []) {
|
|
178
|
+
if (claimed.has(pathKey(w)))
|
|
179
|
+
continue;
|
|
180
|
+
const problem = back.problems.find((x) => pathKey(x.path) === pathKey(w))?.error;
|
|
181
|
+
const how = back.restored.get(pathKey(w));
|
|
182
|
+
add(`withheld ${pathText(w)}`, !problem, problem ?? (how ? `holds against the ${how} value` : committedNote([w])));
|
|
183
|
+
}
|
|
184
|
+
const evidence = executedOrFailed && "upstream" in p.execution ? p.execution.upstream : undefined;
|
|
185
|
+
if (executedOrFailed && evidence) {
|
|
186
|
+
// The evidence as restored: the delivery body or the signed envelope may have been withheld with the result. A
|
|
187
|
+
// check is skipped only for a part the signed note declares withheld and the verifier could not restore; a body
|
|
188
|
+
// or an envelope that is simply not there, or commitment-shaped without the note saying so, fails the check.
|
|
189
|
+
const restoredEvidence = full.execution.upstream;
|
|
190
|
+
const withheldStill = (path) => (note?.withheld ?? []).some((w) => pathKey(w) === pathKey(path)) && back.missing.some((w) => pathKey(w) === pathKey(path));
|
|
191
|
+
if (isProviderAttestation(evidence)) {
|
|
56
192
|
if (opts.providerSecrets) {
|
|
57
|
-
const
|
|
58
|
-
|
|
193
|
+
const re = restoredEvidence;
|
|
194
|
+
const parts = ["rawBody", "signature", "bind"];
|
|
195
|
+
if (!result || parts.some((f) => withheldStill(["execution", "upstream", f])))
|
|
196
|
+
add("upstream signature not checked", true, "the result, the delivery body, its signature, or its bind is withheld; disclose them or give the capture key to check the provider's delivery");
|
|
197
|
+
else if (parts.some((f) => typeof re?.[f] !== "string"))
|
|
198
|
+
add("upstream signature (provider secret)", false, "the receipt carries no delivery body, signature, or bind to check, and the capture note does not say they are withheld");
|
|
199
|
+
else {
|
|
200
|
+
const u = checkProvider({ ...evidence, rawBody: re.rawBody, signature: re.signature, bind: re.bind }, opts.providerSecrets, { timestamp: p.timestamp, result });
|
|
201
|
+
add("upstream signature (provider secret)", u.ok, u.ok ? u.keyid : u.error);
|
|
202
|
+
}
|
|
59
203
|
}
|
|
60
204
|
}
|
|
61
205
|
else if ((opts.upstreamKeys?.length ?? 0) > 0) {
|
|
62
|
-
const
|
|
63
|
-
|
|
206
|
+
const env = restoredEvidence?.envelope;
|
|
207
|
+
const wellFormed = !!env && typeof env === "object" && typeof env.payload === "string" && Array.isArray(env.signatures);
|
|
208
|
+
if (!result)
|
|
209
|
+
add("upstream signature not checked", true, "the result is withheld; disclose it or give the capture key to check the upstream's signature against it");
|
|
210
|
+
// the issuer withholds the envelope beside a result it leaves in clear only when the envelope is anything but the plain attestation for this call (a field, a claim, or an encoding the upstream added); a verifier given the upstream's key is then told, not waved past
|
|
211
|
+
else if (withheldStill(["execution", "upstream", "envelope"]))
|
|
212
|
+
add("upstream signature (upstream key)", false, "the result is in clear but the upstream's signature is withheld; disclose it or give the capture key to check it");
|
|
213
|
+
else if (!wellFormed)
|
|
214
|
+
add("upstream signature (upstream key)", false, "the receipt carries no upstream envelope to check, and the capture note does not say it is withheld");
|
|
215
|
+
else {
|
|
216
|
+
const u = checkUpstream(env, opts.upstreamKeys, { receiptId: p.receiptId, tool: p.tool.name, contentDigest: contentDigest(result) });
|
|
217
|
+
add("upstream signature (upstream key)", u.ok, u.ok ? `keyid ${short(u.keyid)}` : u.error);
|
|
218
|
+
}
|
|
64
219
|
}
|
|
65
220
|
}
|
|
66
221
|
if (p.policy) {
|
|
67
222
|
// a deny that was not enforced (observe mode, enforced: false on the receipt) may sit beside an executed call; an enforced one never does
|
|
68
223
|
const consistent = p.policy.decision === "allow" ? p.execution.status !== "denied" : p.policy.enforced === false ? p.execution.status !== "denied" : p.execution.status === "denied";
|
|
69
224
|
add("policy decision consistent with execution", consistent, `${p.policy.decision}${p.policy.enforced === false ? " (observe mode, not enforced)" : ""} -> ${p.execution.status}`);
|
|
70
|
-
|
|
225
|
+
// a withheld error list is a non-empty one: the issuer leaves an empty list in clear
|
|
226
|
+
const errors = isCommitment(p.policy.errors) || (Array.isArray(p.policy.errors) && p.policy.errors.length > 0);
|
|
227
|
+
add("no policy errors on an allow", !(p.policy.decision === "allow" && errors));
|
|
71
228
|
}
|
|
72
229
|
const logKeys = opts.logKeys ?? [];
|
|
73
230
|
if (p.authorization) {
|
|
@@ -167,9 +324,10 @@ export function formatReport(r) {
|
|
|
167
324
|
const row = (f, prov, v) => lines.push(`${f.padEnd(15)} ${prov.padEnd(11)} ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
168
325
|
row("principal", p.principal.provenance, p.principal.id ?? "(none)");
|
|
169
326
|
row("agent", p.agent.provenance, p.agent.id);
|
|
327
|
+
const idText = (v) => (typeof v === "string" ? v : v === null || v === undefined ? "-" : "(withheld under the capture rule)");
|
|
170
328
|
if (p.session.id || p.session.toolUseId)
|
|
171
|
-
row("session", p.session.provenance, `${p.session.id
|
|
172
|
-
row("model", p.model.provenance, p.model.id
|
|
329
|
+
row("session", p.session.provenance, `${idText(p.session.id)} / ${idText(p.session.toolUseId)}`);
|
|
330
|
+
row("model", p.model.provenance, p.model.id === null ? "(none supplied)" : idText(p.model.id));
|
|
173
331
|
row("tool", p.tool.provenance, p.tool.name);
|
|
174
332
|
row("args", p.request.provenance, p.request.args);
|
|
175
333
|
for (const [k, f] of Object.entries(p.facts))
|
|
@@ -179,7 +337,7 @@ export function formatReport(r) {
|
|
|
179
337
|
else
|
|
180
338
|
row("policy", "-", "(none evaluated)");
|
|
181
339
|
if (p.consumed)
|
|
182
|
-
row("consumed", p.consumed.provenance, p.consumed.factIds.length === 0 ? "(no facts shown before this call)" : p.consumed.factIds);
|
|
340
|
+
row("consumed", p.consumed.provenance, !Array.isArray(p.consumed.factIds) ? "(withheld under the capture rule)" : p.consumed.factIds.length === 0 ? "(no facts shown before this call)" : p.consumed.factIds);
|
|
183
341
|
if (p.authorization) {
|
|
184
342
|
const committed = r.checks.filter((c) => c.name.startsWith("authorization ")).every((c) => c.ok);
|
|
185
343
|
row("authorization", "observed", committed ? `committed to the log as leaf ${p.authorization.inclusion.leafIndex}, before the call was forwarded` : "carried, but its checks FAILED");
|
package/docs/compliance.md
CHANGED
|
@@ -24,11 +24,11 @@ Two rules keep the answers honest. First, say which producer made the receipt: a
|
|
|
24
24
|
| criterion | what it asks | what answers it |
|
|
25
25
|
| --- | --- | --- |
|
|
26
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
|
|
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; `agent-custody revoke` revokes a grant, and every session under it or under a grant delegated from it refuses its next call |
|
|
28
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
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
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 |
|
|
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; for changes made by agents, the merge gate below gives per-change evidence of tier, approval, and authority on either side of it |
|
|
32
32
|
|
|
33
33
|
## ISO/IEC 27001:2022, Annex A
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ Two rules keep the answers honest. First, say which producer made the receipt: a
|
|
|
39
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
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
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 |
|
|
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; for agent-made changes, the merge gate below |
|
|
43
43
|
|
|
44
44
|
## EU AI Act, obligations on high-risk systems and their deployers
|
|
45
45
|
|
|
@@ -59,6 +59,12 @@ Two rules keep the answers honest. First, say which producer made the receipt: a
|
|
|
59
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
60
|
| Article 32, security of processing | appropriate technical measures | the hosted log holds hashes only, and receipts stay with the controller |
|
|
61
61
|
|
|
62
|
+
## Agent-made changes: the merge gate
|
|
63
|
+
|
|
64
|
+
Teams whose agents open pull requests hit two problems at once. Volume: SOC 2 and ISO 27001 ask that changes are authorized, tested, and approved under a defined process, and a human on every PR does not scale. Accountability: a pipeline's own audit trail, including an "evidence store" at the end of it, is written by the pipeline that made the decisions. Risk-tiered review solves the first only if the tier decision itself is evidence.
|
|
65
|
+
|
|
66
|
+
[Example 24](../examples/24-agentic-cicd-merge-gate.ts) is that gate. A release agent merges through the gateway; the risk tier is a Cedar policy over facts the gateway fetches from the git host itself, never from the agent: the diff size, whether sensitive paths are touched, the deterministic gate results, which humans approved. Low risk merges on the agent's own authority, medium needs a CODEOWNER's approval the gateway can see, high has no permit for any agent and goes to two humans in the host, and production promotion is refused. Every merge is pre-committed to the log before it is forwarded. The receipts give, per change: the tier, the decision, the approvers as the gateway saw them, the policy digest, the human whose signed grant authorized the agent, and the log positions showing authorization preceded execution, each line verifiable with public keys and no account with us. That is what the two controls above ask for, produced by a key the agent does not hold, instead of a trail the pipeline wrote about itself.
|
|
67
|
+
|
|
62
68
|
## What no artefact here claims
|
|
63
69
|
|
|
64
70
|
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
|
@@ -130,6 +130,8 @@ const graph = workflow.compile().withConfig({ callbacks: [new ReceiptCallbackHan
|
|
|
130
130
|
const refund = tool(issuer.wrap("stripe.refund", fn), { name: "stripe.refund", schema });
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
[Example 23](../examples/23-langchain-kb-agent.ts) is a whole agent on `createAgent`, a docs agent over a knowledge base with a policy that allows writes under `notes/` only, with every receipt verified at the end; it runs with no API key. A 22-second film of it: [agent-custody.dev/demo-langchain-kb.mp4](https://agent-custody.dev/demo-langchain-kb.mp4).
|
|
134
|
+
|
|
133
135
|
LangChain callbacks cannot block a tool, so the handler evaluates no policy; it records what happened, including the `tool_call_id` when one is present, and unwraps `ToolMessage` outputs. For enforcement wrap the function at construction. Do not do both on one tool or it will be recorded twice.
|
|
134
136
|
|
|
135
137
|
## OpenClaw
|
|
@@ -178,6 +180,22 @@ The harness also ships `@deepseek-ai/dsh-hooks-claude-code`, a bridge that runs
|
|
|
178
180
|
|
|
179
181
|
[packages/python/agent_custody/hermes.py](../../python/agent_custody/hermes.py), through the sidecar like every Python adapter. Hermes runs Python plugins in the agent's process and fires `pre_tool_call(tool_name, args, task_id, **kwargs)`, which may return `{"action": "block", "message": …}`, and `post_tool_call(tool_name, args, result, task_id, duration_ms, **kwargs)`. The plugin is the directory [packages/python/hermes-plugin](../../python/hermes-plugin/): a `plugin.yaml` declaring both hooks and a `sidecar_url` setting, and an `__init__.py` that is one line, `from agent_custody.hermes import register`. Copy it to `~/.hermes/plugins/agent-custody/`, `pip install agent-custody`, start the sidecar, `hermes plugins enable agent-custody`. A denied call is blocked before it runs with the receipt id in the message; an allowed one gets no action, so Hermes's own guardrails and approvals still apply; every completed call is recorded with the Hermes `task_id` as the receipt's session. `hermes_hooks(client)` returns the two callables; `register_hermes(ctx, client)` registers them on a plugin context.
|
|
180
182
|
|
|
183
|
+
## Google ADK
|
|
184
|
+
|
|
185
|
+
[packages/python/agent_custody/adk.py](../../python/agent_custody/adk.py), through the sidecar like every Python adapter. ADK runs `before_tool_callback(tool, args, tool_context)` before every tool call, and a dict returned there skips the tool and becomes its result; `after_tool_callback(tool, args, tool_context, tool_response)` runs after the tool and may replace the response. `adk_callbacks(client)` returns both, keyed by the `LlmAgent` fields they go in:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from google.adk.agents import LlmAgent
|
|
189
|
+
from agent_custody import Client
|
|
190
|
+
from agent_custody.adk import adk_callbacks
|
|
191
|
+
|
|
192
|
+
agent = LlmAgent(name="billing", model="gemini-2.5-flash", tools=[...], **adk_callbacks(Client()))
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`pip install "agent-custody[adk]"` brings in `google-adk[a2a]`. The before callback evaluates the policy: on an enforced deny it records the denial receipt and returns `{"error": "agent-custody: <reason> (receipt <id>)", "agent-custody/receipt": "<id>"}`, so ADK skips the tool and the model sees the receipt as the tool's result; on allow, or with no policy, it returns `None` and the tool runs. If the denial receipt cannot be recorded the call is still skipped. The after callback records the executed call, the result as JSON when it is JSON and as text otherwise, and returns `None`, leaving the response as it was; it recognises the denial dict by its receipt key and does not record it a second time. ADK's `invocation_id` and `function_call_id` are the receipt's session. In observe mode a deny is recorded and the tool runs, as with every adapter. Tested in `tests/test_adk.py` against ADK's own runner with a scripted model and a tool named `stripe.refund`.
|
|
196
|
+
|
|
197
|
+
A delegation an ADK agent makes to another agent over A2A, through `RemoteA2aAgent`, is not a tool call and does not pass through these callbacks. Point the `RemoteA2aAgent` at the gateway's A2A front instead, `agent-custody gateway --a2a`, in [usage.md](usage.md#the-gateway-as-an-a2a-agent): every delegation is then a receipted, policy-checked call, and a refused one never reaches the remote agent. `tests/test_adk_a2a.py` runs that with ADK's own `to_a2a` on the remote side.
|
|
198
|
+
|
|
181
199
|
## Any other framework: wrap the function
|
|
182
200
|
|
|
183
201
|
Every agent framework ends up calling a function. Wrap it.
|
|
@@ -218,6 +236,7 @@ const bundle = await issuer.record({ tool, args, model, session }, { status: "ex
|
|
|
218
236
|
| OpenAI Agents SDK | `wrapTools` | `observeRunner` |
|
|
219
237
|
| Vercel AI SDK | `wrapTools` | wrap with a policy-less issuer |
|
|
220
238
|
| LangChain / LangGraph | `tool(issuer.wrap(...))` | `ReceiptCallbackHandler` |
|
|
239
|
+
| Google ADK (Python) | `adk_callbacks`: `before_tool_callback` skips the tool | `after_tool_callback` |
|
|
221
240
|
| anything else | `issuer.wrap` | `issuer.record` |
|
|
222
241
|
|
|
223
242
|
Record-only adapters evaluate no policy on purpose. A receipt that said "policy: deny" next to "execution: executed" would fail verification, and the verifier would be right: that is not a receipt, that is a finding. Enforce, or observe, but do not pretend.
|
package/docs/tutorials.md
CHANGED
|
@@ -32,6 +32,11 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
32
32
|
| 20 | one gateway for many agents, over HTTP | [20-http-gateway.ts](../examples/20-http-gateway.ts) | a gateway host served over Streamable HTTP, two agents connecting with their own grants and seeing their own tools, receipts naming the right agent, a refusal by grant, and a stranger's grant getting no session | `src/gateway-http.ts`, `src/gateway.ts` |
|
|
33
33
|
| 21 | OpenClaw plugin hooks | [21-openclaw.ts](../examples/21-openclaw.ts) | the two hooks driven with OpenClaw's event shapes: an allowed call gets no result, a denied one is blocked with the receipt id, executed and failed calls are recorded, every receipt verifies | `src/sdk/openclaw.ts` |
|
|
34
34
|
| 22 | DeepSeek Harness plugin | [22-deepseek-harness.ts](../examples/22-deepseek-harness.ts) | the module as a plugin, applied by a stand-in context; pre-execute delegating an allowed call and denying one with the receipt id; post-execute recording executed and failed calls; every receipt verifying with the harness's session and call ids | `src/sdk/deepseek-harness.ts` |
|
|
35
|
+
| 23 | a LangChain agent under custody, end to end | [23-langchain-kb-agent.ts](../examples/23-langchain-kb-agent.ts) | a docs agent on LangChain's `createAgent` reading a runbook, refused when it edits one, writing a note that cites its source; three receipts verified with the public key and the log copy; the auditor's report for the refused write. Scripted model, no API key. [23-langchain-kb-agent.tape](../examples/23-langchain-kb-agent.tape) renders it as a film with vhs | `src/sdk/index.ts`, `src/verify.ts` |
|
|
36
|
+
| 24 | an agentic CI/CD merge gate with evidence | [24-agentic-cicd-merge-gate.ts](../examples/24-agentic-cicd-merge-gate.ts) | a release agent merging pull requests through the gateway against a stand-in git host: the risk tier is a policy on facts the gateway fetched itself (diff size, sensitive paths, gate results, human approvals); low merges alone, medium needs a CODEOWNER, high is refused for any agent, production promotion refused; merges pre-committed to the log; an evidence index from the receipts alone, every line verified | `src/gateway.ts`, `src/rest.ts`, `src/verify.ts` |
|
|
37
|
+
| 25 | an agent delegating to an agent over A2A | [25-a2a-delegation.ts](../examples/25-a2a-delegation.ts) | a stand-in document agent speaking A2A 1.0, the gateway serving A2A in front of it with the document agent's card at its own address, an engagement agent delegating twice as an A2A client: one task allowed and answered with the receipt id in its metadata, one refused as a rejected task because it names a privileged matter, the policy deciding on the card the gateway fetched itself; both receipts verified, the allowed one carrying the card as a fact and the authorization logged before the task went out | `src/a2a.ts`, `src/gateway.ts` |
|
|
38
|
+
| 26 | private evidence | [26-private-evidence.ts](../examples/26-private-evidence.ts) | a capture rule for a refund: the arguments encrypted except the amount and the customer id, the provider's answer and the customer record withheld as digests; the receipt file carrying commitments and none of the phone number, the card, the note, or the record; verified as committed without the key; `reveal` with the key writing the disclosure and `verify --capture-key-env` recomputing every digest; a disclosure that lies failing the commitment | `src/capture.ts`, `src/verify.ts` |
|
|
39
|
+
| 27 | revoking an agent's authority mid-session | [27-revocation.ts](../examples/27-revocation.ts) | a support agent and the sub-agent it delegated to, both mid-session on one gateway, cut off on their next call when the operator runs `agent-custody revoke` from another process: no key rotated, no restart, each refusal a signed receipt that verifies, and a new session, a repacked grant, or a fresh delegation from it all refused | `src/gateway.ts` (`revokedGrants`, re-read on every call), `src/delegation.ts` (`grantDigest`, the chain), `src/cli.ts` (`revoke`) |
|
|
35
40
|
|
|
36
41
|
## How policies are defined, in one paragraph
|
|
37
42
|
|