@agent-custody/receipts 0.7.0 → 0.8.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.
@@ -0,0 +1,107 @@
1
+ # Payload-bound human approvals
2
+
3
+ A delegation lets an agent use a tool. A human approval authorizes one exact call: this principal, this agent, this tool, and every argument, until a short expiry. The gateway requires the signed approval before forwarding a protected call. A flag such as `approved: true` in the arguments has no authority.
4
+
5
+ The approval is a DSSE envelope signed with an approver's Ed25519 key. Its payload carries `approvalId`, `principal`, `agent`, `tool`, a SHA-256 digest of the complete arguments, `issuedAt`, `expiresAt`, and the action's `amount`, `currency`, and `beneficiary` when those fields exist. Money is an integer in minor units: `2500` means £25.00 for `GBP`, never `25.00`. Extra arguments are covered by the digest too; changing a note or adding a field invalidates the approval.
6
+
7
+ ## Configure the gateway
8
+
9
+ Generate approver keys with `agent-custody keygen --dir keys --name approver`, keep their private halves with the people approving actions, and add their public halves to the gateway:
10
+
11
+ ```json
12
+ {
13
+ "approvals": {
14
+ "trustedKeys": ["keys/approver.pub", "keys/second-approver.pub"],
15
+ "usedDir": "approvals-used",
16
+ "maxLifetimeSeconds": 900,
17
+ "tools": [
18
+ { "tool": "stripe.refund", "minApprovers": 2 }
19
+ ]
20
+ }
21
+ }
22
+ ```
23
+
24
+ This is an addition to the [gateway config](usage.md#setup-step-by-step), with paths relative to that file. `maxLifetimeSeconds` caps the approval lifetime, `expiresAt` minus `issuedAt`. The default is `3600`. The signer chooses the expiry, so the gateway refuses an approval with a longer lifetime, in every mode. This keeps an unused approval, which the agent holds, from staying usable for years. `minApprovers` is `1` by default, or `2` for two distinct trusted signing keys. A repeated signature or the same key listed twice counts once. The operator must assign those keys to distinct people; signatures establish possession of keys, not independent human identities.
25
+
26
+ `tool: "*"` protects every agent call, with an exact tool rule taking precedence. Wildcard rules do not require approvals for the gateway's internal fact lookups. A named fact-lookup tool cannot also have an exact approval rule: startup rejects that configuration. The gateway does not start with an empty trust list, an empty tools list, or duplicate tool rules.
27
+
28
+ The default action argument names are `amount`, `currency`, and `beneficiary`. For a refund whose recipient is `customer_id`, map it explicitly:
29
+
30
+ ```json
31
+ { "tool": "stripe.refund", "minApprovers": 1, "fields": { "beneficiary": "customer_id" } }
32
+ ```
33
+
34
+ Pass the same `fields` when creating the approval. These are top-level argument names, not dot paths. Each present amount must be a safe integer; a present currency or beneficiary must be a nonempty string. An omitted action field is still covered by the complete argument digest, but the approval cannot establish a business meaning for a differently named field unless it is mapped.
35
+
36
+ ## Sign the exact action and send it
37
+
38
+ Use the TypeScript API from the process where the human reviews the action. Show the complete arguments before signing, including any fields beyond the displayed amount and recipient.
39
+
40
+ ```ts
41
+ import {
42
+ APPROVAL_META_KEY, createApproval, dsseCountersign, loadPrivateKey,
43
+ } from "@agent-custody/receipts";
44
+
45
+ const args = { customer_id: "cust_123", amount: 2500, currency: "GBP" };
46
+ const fields = { beneficiary: "customer_id" };
47
+ const first = createApproval(loadPrivateKey("keys/approver.key"), {
48
+ principal: "user_456",
49
+ agent: "support-agent",
50
+ tool: "stripe.refund",
51
+ args,
52
+ fields,
53
+ expiresAt: new Date(Date.now() + 5 * 60_000).toISOString(),
54
+ });
55
+ // For a two-person rule, the second person reviews and signs the same payload.
56
+ const approved = dsseCountersign(first, loadPrivateKey("keys/second-approver.key"));
57
+ const result = await agent.callTool({
58
+ name: "stripe.refund",
59
+ arguments: args,
60
+ _meta: { [APPROVAL_META_KEY]: approved },
61
+ });
62
+ ```
63
+
64
+ `createApproval` supplies a UUID `approvalId` and the current `issuedAt` unless given explicitly. `expiresAt` is required and must follow `issuedAt`. The window is half open: the approval is valid at issuance and invalid at expiry. `dsseCountersign` preserves the payload and adds a signature; it does not issue a different approval.
65
+
66
+ The gateway reads `agent-custody/approval` from the call's `_meta` and removes that key before forwarding. It checks the trusted signatures, threshold, lifetime cap, validity window, principal, agent, tool, complete argument digest, and action fields before fact lookups and Cedar evaluation. Missing, malformed, expired, or mismatched approval denies the call even in observe mode. A valid approval still needs a valid grant and an allowing policy.
67
+
68
+ After facts and any pre-commit authorization have completed, the gateway checks the approval again and atomically consumes its id immediately before forwarding. An approval that expired during those waits, or lost a concurrent race to use the same id, leaves the call `withheld`. Every refusal gets a signed receipt with its reason.
69
+
70
+ ## Consumption and failure recovery
71
+
72
+ `usedDir` is part of the enforcement boundary. Keep it persistent across restarts and share the same directory between all gateway processes that accept the same approvals. The filesystem must support exclusive file creation consistently across those processes, and durable file and directory synchronization. A synchronization failure withholds the call. Separate directories let each gateway consume the same approval once.
73
+
74
+ Consumption is conservative: the id is burned before forwarding. A crash, a log error, or an unknown upstream outcome after consumption does not release it. Obtain a fresh approval after checking the upstream's actual state; retry and exactly-once outcome handling are separate work. Do not delete consumption records while their approvals can still be valid. There is no automatic pruning.
75
+
76
+ An offline receipt verifier checks the signed action and the gateway's recorded consumption time. It cannot prove that another gateway never used that approval: single use depends on this shared persistent store and the gateway enforcing it.
77
+
78
+ ## Verify the evidence
79
+
80
+ The receipt's optional `approval` record embeds the envelope, the required threshold, checked time, status, observed signer keyids, configured field mapping when any, and consumption time when consumed. A missing, malformed, or untrusted approval envelope on a refused call is omitted. Only signature entries that verify against trusted approval keys are retained in an embedded envelope. Under a private capture rule the envelope and the reason are withheld as commitments; see [Privacy](#privacy-limits). Its provenance is `observed`: the gateway records what it checked; the embedded envelope supplies the independent approver signatures.
81
+
82
+ ```bash
83
+ agent-custody verify receipts/<id>.json \
84
+ --issuer-key keys/gateway.pub --principal-key keys/principal.pub \
85
+ --approval-key keys/approver.pub --approval-key keys/second-approver.pub
86
+ ```
87
+
88
+ In code, give `verifyBundle` an `approvalKeys` array of `PublicKeyRef`s, separate from `issuerKeys` and `principalKeys`. Those other keys never implicitly authorize an approval. For a forwarded call carrying an approval record, verification requires trusted approval signatures, the exact action binding, validity at the recorded check and consumption times, and an approved, consumed record. A call that the gateway did not forward needs none of these, and so needs no approval key. This covers a call that Cedar denied, a call outside the grant, and a call withheld after consumption, even when the approval was valid. The record of such a call is an authentic refusal. Verification does not turn its approval into an authorization.
89
+
90
+ `verifyApproval(envelope, trustedKeys, binding, { at?, minApprovers?, maxLifetimeSeconds? })` checks an envelope directly and returns either `{ ok: true, approval, approverKeyids }` or `{ ok: false, error }`. It does not consume it. `consumeApproval(usedDir, approvalId, receiptId, at)` creates the exclusive consumption marker and throws if the id has already been used. The gateway combines these steps; callers building another enforcement boundary must preserve their order.
91
+
92
+ ## Privacy limits
93
+
94
+ The approval envelope arrives in the agent's `_meta`. It carries the amount, currency, beneficiary, and an **unsalted digest of the full arguments**. Under a private capture rule the receipt withholds the whole envelope as one commitment at `approval.envelope`. It is salted, and encrypted in mode `encrypted`. The precommit authorization carries the same commitment. A refusal `reason` can quote the statement, so it is withheld too. Without this, the receipt would publish the action fields, and the digest would confirm a guess of the arguments (issue #126).
95
+
96
+ The record keeps the gateway's own observations in clear: the status, the required threshold, the check and consumption times, the signer key ids, and the configured field mapping. A reviewer sees that an approval was checked and when. To check the signatures and the binding, the reviewer restores the envelope and the arguments with the capture key or a disclosure (`approval.envelope` and `request.args.$rest` in the disclosure file). Without them, the verifier passes the approval checks as committed, as it does for `request args digest`, and says so. A tool with a private rule and an approval therefore proves the approval only to a reviewer who holds the key or a disclosure. The browser verifier cannot restore them.
97
+
98
+ When the issuer withholds nothing under `request.args`, an approved envelope stays in clear. This happens when `args` is in mode `clear` with a private `result`. It also happens when a private `args` rule lists every argument of the call in `clear`, or the call has no arguments. The envelope payload then equals the public call, and the gateway checked that. A denied envelope is still withheld, because it can carry another call's fields. So is the envelope of a call whose tool name is masked. The verifiers use the same test: a forwarded, approved call whose note withholds the envelope, but withholds nothing under `request.args`, fails `approval signatures (human keys)`. Otherwise an issuer could skip the binding check whenever the arguments are public.
99
+
100
+ ### What the receipt can prove about the approval
101
+
102
+ - The receipt proves the signatures, the binding, and the window only to a reviewer who has the envelope. Under a private rule that is the capture key (mode `encrypted`) or a disclosure of `approval.envelope`.
103
+ - In mode `digest` the gateway keeps no copy of the envelope. The salts file holds only salts. A disclosure can then come only from whoever kept the approval: the agent or the approver. If nobody kept it, the human approval cannot be proven afterwards. Use mode `encrypted` when you must prove it later.
104
+ - The receipt does not record `maxLifetimeSeconds`. The offline verifier cannot check the lifetime cap. Only the gateway enforces it, when it admits the approval.
105
+ - Single use is also not provable offline. See above.
106
+
107
+ [Tutorial 30](../examples/30-payload-bound-approvals.ts) runs a real gateway with two approvers, refuses changed arguments, an expired approval and an insufficient threshold, forwards the exact approved call, refuses its replay, and verifies every receipt.
@@ -0,0 +1,99 @@
1
+ # Safe financial operations
2
+
3
+ An API response is evidence of an API call. Settlement is a separate outcome. Configure `operations` on the gateway to give each payment a durable identity, reserve its amount before forwarding, and close uncertain outcomes with a signed provider reconciliation receipt. [Example 29](../examples/29-financial-operations.ts) runs a payments stand-in, drops a response after acceptance, restarts the gateway, and verifies the reconciliation.
4
+
5
+ ## Configuration
6
+
7
+ Add this to a gateway config whose upstream advertises `stripe.refund` and the read-only `refund.lookup`:
8
+
9
+ ```json
10
+ {
11
+ "operations": {
12
+ "database": "operations/operations.sqlite",
13
+ "budgets": [{ "id": "refunds", "currency": "GBP", "limit": 100000 }],
14
+ "tools": [{
15
+ "tool": "stripe.refund",
16
+ "budget": "refunds",
17
+ "amountField": "amount",
18
+ "currencyField": "currency",
19
+ "idempotencyHeader": "Idempotency-Key",
20
+ "reconcile": {
21
+ "tool": "refund.lookup",
22
+ "args": { "key": "$operation.idempotencyKey" },
23
+ "statusPath": "status",
24
+ "identityPath": "idempotencyKey",
25
+ "confirmed": ["succeeded"],
26
+ "failed": ["failed"],
27
+ "pending": ["pending"]
28
+ }
29
+ }]
30
+ }
31
+ }
32
+ ```
33
+
34
+ Amounts and limits are safe integers in minor units; an amount must be positive. Currency must match the budget's three-letter uppercase code. The amount and currency field defaults are `amount` and `currency`. The default REST header is `Idempotency-Key`; `identityPath` defaults to `idempotencyKey`, and `pending` defaults to an empty list. Other fields above are required. Tool names and budget ids must be unique, and reconciliation status lists must be disjoint.
35
+
36
+ The database path resolves relative to the config. Its parent directory must be owner-only (`0700`); the gateway creates a missing directory and creates/tightens the database to `0600`. The database contains recovery data, provider responses, and private commitment salts. Keep it private and durable alongside the signing key. Never delete operation records to implement retention or reset a budget: those records prevent old calls from being forwarded again. Financial operations load `node:sqlite` lazily and need Node 22 with that module available.
37
+
38
+ All sessions and gateway processes sharing a budget must use the same SQLite database on the same machine, with the same budget configuration. Use a remote log for multiple gateway processes; a local receipt log has one writer. Budgets cover UTC calendar days. Unknown, submitted, pending, and confirmed operations continue to count in their original day; a retry never moves a reservation into a new day. A new day gets its own daily limit.
39
+
40
+ ## Provider contract
41
+
42
+ The provider must honor the supplied idempotency key. REST financial tools receive it in the configured header, overriding any static header of that name. MCP financial tools receive `_meta["agent-custody/operation"] = { id, idempotencyKey }` and must pass the key to their payment provider. A2A financial upstreams are refused because they have no payment idempotency contract.
43
+
44
+ Reconciliation is a read from the provider's authoritative operation record. A REST reconciliation tool must use GET. Its arguments may substitute only `$operation.idempotencyKey`, beside configured constants. The template cannot copy `$operation.id`: the agent chose that UUID, and it must not reach a receipt. The result must contain JSON in its first text item. `statusPath` and `identityPath` traverse own properties using dot-separated names. The identity must equal the operation's idempotency key; a missing or unrelated record cannot close a reservation. The configured `failed` states must mean a terminal provider failure that cannot later settle. An absent record, a transport failure, and an HTTP error are uncertain outcomes and must never be mapped to terminal failure.
45
+
46
+ The write upstream, read upstream, and reconciliation configuration are bound into the durable operation. Reconciliation refuses a changed provider configuration. Its lookup arguments, identity path, and terminal mappings are also committed in the original signed authorization. The gateway observes the provider read; this is not an independent provider signature.
47
+
48
+ ## Calling and retrying
49
+
50
+ Generate and persist one lowercase UUID before a consequential call, then retain it across transport failures and restarts:
51
+
52
+ ```ts
53
+ import { randomUUID } from "node:crypto";
54
+ import { OPERATION_META_KEY } from "@agent-custody/receipts";
55
+
56
+ const operationId = randomUUID(); // persist with the business operation before sending
57
+ const call = {
58
+ name: "stripe.refund",
59
+ arguments: { amount: 2500, currency: "GBP", customer_id: "cust_123" },
60
+ _meta: { [OPERATION_META_KEY]: operationId },
61
+ };
62
+ const result = await client.callTool(call);
63
+ ```
64
+
65
+ The first use atomically binds the UUID to the principal, agent, tool, destination, full argument digest, and budget, and reserves the amount before the authorization or forward. Reusing it for different arguments or identity is refused. Identical calls with distinct UUIDs are separate business operations, so generating a fresh UUID after a timeout defeats retry protection.
66
+
67
+ A retry still checks the current grant and policy. It returns the existing logical operation's result, receipt id, and current operation metadata; it never forwards again or reserves again. A retry that policy allows gets a receipt of its own: `execution.status` is `withheld` (the call was not forwarded again), and `operation.originalReceiptId` names the receipt of the first call. The answer carries its id at `_meta["agent-custody/retry-receipt"]`, and `_meta["agent-custody/receipt"]` stays the receipt that holds the outcome. If the gateway died after authorization but before its outcome receipt, the retry reports `unknown` and returns the original signed authorization under `_meta["agent-custody/authorization"]`. There may be no `<originalReceiptId>.json` in that case; the authorization is sufficient for reconciliation.
68
+
69
+ The signed receipt's `execution.status` describes the API call. Its separate `operation.status` records the financial lifecycle:
70
+
71
+ | outcome | meaning | budget |
72
+ | --- | --- | --- |
73
+ | `submitted` | durable reservation exists; forwarding may still be in progress | held |
74
+ | `pending` | API answered; settlement awaits an authoritative read | held |
75
+ | `unknown` | provider acceptance or settlement is uncertain | held |
76
+ | `confirmed` | reconciliation read confirms final success | consumed in the original day |
77
+ | `failed` | reconciliation read confirms terminal failure, or the gateway proves it withheld the forward | released |
78
+
79
+ An initial success response remains `pending` until reconciliation. An HTTP error or thrown call becomes financially `unknown`, even if API execution is `failed` or `error`. Financial authorization logging fails closed in observe mode too; observe suspends Cedar enforcement, never idempotency, budget enforcement, or the required authorization append.
80
+
81
+ ## Reconciling
82
+
83
+ An operator holding the config and signing key runs:
84
+
85
+ ```bash
86
+ agent-custody reconcile --config gateway.json --operation <uuid>
87
+ ```
88
+
89
+ The command prints JSON with `operation`, terminal `status`, and the receipt file path. A pending/unknown record causes a nonzero exit and keeps the reservation; run the command again after the provider record changes. Repeated completed reconciliations return the same bundle. The operator can reconcile after the original agent's grant expires or is revoked, because this reads an existing operation and sends no new payment.
90
+
91
+ In code, `await host.reconcile(operationId)` returns the bundle. This method is on `GatewayHost` and is never advertised as an agent tool. To recover operation ids after a crash, open the configured `OperationStore` and inspect `store.list()`; close the connection when finished. A submitted operation owned by a live process is refused until that forward returns. After a killed process, its submitted authorization can be reconciled. The gateway stores the creator's PID with its kernel start time (`/proc/<pid>/stat`, or `/bin/ps` with the time zone pinned to UTC where there is no `/proc`, because `ps` prints local time). A live process with the same PID and another start time is not the creator, so a gateway that is PID 1 in a restarted container does not block recovery. When the gateway cannot read a start time, it treats the PID as the creator and recovery waits: it never releases the budget of a live forward. The check needs the creator and the operator to share one PID namespace, such as `docker exec` into the gateway container. A second container on the same volume sees other PIDs and must not run `reconcile` while a gateway can still be forwarding.
92
+
93
+ The gateway saves the signed authorization before it forwards. A submitted operation with a dead creator and no saved authorization therefore proves that the call was never sent. `reconcile` closes it with a receipt, with `execution.status: "withheld"` and `operation.status: "failed"`, and then releases the reservation. It makes no provider read. A wrong liveness answer cannot cause a double forward: the creator saves its authorization with a compare-and-set, and it refuses to forward once recovery has closed the operation. Recovery in turn refuses to close the call when an authorization was saved meanwhile. A retry of a closed call is told that the call was not sent and that a new operation id is needed. The recovery store keeps the call's request values until then, so keep the database private.
94
+
95
+ The reconciliation embeds the original receipt or pre-forward authorization, preserves operation identity, and records the configured provider read as `execution.result`. It commits the exact signed/captured receipt and private salts in the recovery store before appending it. Only after the log accepts that receipt does a terminal failure release budget. A log outage or process crash retains the amount; retry uses the same signed bytes and salts. Concurrent recovery can append identical evidence more than once, but cannot choose conflicting terminal outcomes or duplicate a payment.
96
+
97
+ Verify it with the usual `agent-custody verify` command and the gateway/principal public keys. Both verifiers check the original signature and inclusion proof, operation linkage, precommitted lookup, provider record identity and final status, result digest, and log order. Capture rules apply to the reconciliation result too: withheld provider details verify as committed until disclosed or decrypted. The operation metadata never copies the payment amount into clear fields. Under a private capture rule, `operation.id` is withheld too, as one commitment, because the agent chose it. Receipts link by the gateway-derived `idempotencyKey`, which stays in clear.
98
+
99
+ A reconciliation receipt records a provider read. The gateway evaluated no policy for it, and it did not run the payment tool again. Its `policy.reasons` say so. The OpenTelemetry span and the Splunk event mark it: the span has `agent_custody.reconciliation` and `agent_custody.operation.status`, no policy decision, and the status `reconciled`. The span status is an error when the provider reports the operation as failed. A dashboard therefore never counts it as a second allowed call. `explain` and `review` also show it as a provider read (`reconciled`), not as an allowed execution of the tool.
package/docs/policies.md CHANGED
@@ -199,3 +199,25 @@ const d = evaluate(policy, {
199
199
  ```
200
200
 
201
201
  Write one case per branch of every `when` clause, plus one for the missing-attribute path.
202
+
203
+ ## Simulating a policy against recorded history
204
+
205
+ Use `policy simulate` before enforcing a tighter policy. It verifies local receipt bundles with your public keys, then evaluates the proposed Cedar text against the arguments and fact values each receipt recorded at call time. Gateway receipts also supply the principal and scopes from their signed delegation as `context.grant`; SDK receipts keep their original context of `args` and `facts: {}`. Replay runs offline, without fetching new facts or executing tools.
206
+
207
+ ```bash
208
+ agent-custody policy simulate --policy proposed.cedar --receipts receipts \
209
+ --issuer-key keys/gateway.pub --principal-key keys/principal.pub \
210
+ --out simulation.json
211
+ ```
212
+
213
+ For SDK receipts, use the application's public key as `--issuer-key`; no principal key is needed. Add `--log-key keys/log.pub` when another key signed the log's tree heads. Add `--approval-key keys/approver.pub` when the history holds calls that a human approved: `verify` needs those keys for a forwarded call that carries an approval, and the command fails without them. Each key flag may be repeated when the history spans several keys. The directory is read in filename order, without recursion, one bundle at a time, so it never holds the tool results of the whole history in memory. A malformed or unverifiable bundle, or invalid Cedar syntax in the proposed policy, fails the command.
214
+
215
+ A gateway that dies after it forwards a `precommit` call leaves `<id>.authorization.json` and no `<id>.json`. The command verifies each such file as an authorization statement (the issuer key, the tree head, and the inclusion proof) and lists the call under `skipped`, so the report is `INCOMPLETE`. An authorization that does not verify fails the command. An authorization that sits beside its receipt is not read twice.
216
+
217
+ A receipt under a capture rule needs its withheld arguments and fact values to replay. Give `--capture-key-env NAME` to decrypt the values that mode `encrypted` withheld, as `verify` does. Give `--disclose <file>`, which you can repeat, for the values that mode `digest` withheld. Each file is a disclosure as `reveal` writes it, and it applies only to the receipt that its `receiptId` names. A key or a disclosure that does not match a commitment skips that receipt as malformed. The key comes from the environment, never from a flag value.
218
+
219
+ The report lists every call whose `allow` or `deny` decision changes, grouped by tool and the proposed decision's policy ids or evaluation errors, with the receipt ids and both decisions. A call executed in observe mode may already have a recorded deny: replay compares that recorded decision, not whether the tool ran. Calls with the same decision stay unchanged even when different policy ids match. Cedar evaluation errors remain denials.
220
+
221
+ Every run records a `runId`, `timestamp`, the proposed text's sha256 as `policyDigest`, and the original digests as `previousPolicyDigests`. `--out` saves the full JSON report, and `--json` prints it to stdout. Changes alone exit 0. A report that cannot replay every call says `INCOMPLETE` and exits 1: `skipped` names each receipt and why. This includes record-only receipts with no policy baseline, withheld arguments or fact values, calls whose receipt is missing, and calls stopped before Cedar could evaluate. Grant failures cannot become permits through a policy change, and neither can an approval refusal: the gateway checks the approval before Cedar runs, so the call is skipped as a non-policy gate. The approval record says so even under a private rule. Withheld results alone do not prevent replay.
222
+
223
+ The report is an analysis of the supplied receipt directory; it does not prove that the directory contains the whole history. Keep the report beside the proposed policy and review the changed receipt ids before switching from observe mode to enforcement. [Tutorial 28](../examples/28-policy-simulation.ts) records three refunds, stops the gateway, and replays them against a lower limit.
package/docs/tutorials.md CHANGED
@@ -37,6 +37,9 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
37
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
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
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`) |
40
+ | 28 | policy simulation | [28-policy-simulation.ts](../examples/28-policy-simulation.ts) | three refunds recorded in observe mode, then the gateway stopped and their receipts replayed against a lower limit: only one changes decision, grouped by tool and reason with its receipt id, the proposed policy digest saved with the run | `src/simulate.ts`, `src/cli.ts` |
41
+ | 29 | financial operations | [29-financial-operations.ts](../examples/29-financial-operations.ts) | a refund accepted before its response is dropped, a restart and retry producing no second request, the unknown reservation blocking an over-budget refund, and a provider reconciliation receipt that verifies | `src/operations.ts`, `src/gateway.ts`, `src/verify.ts` |
42
+ | 30 | payload-bound human approvals | [30-payload-bound-approvals.ts](../examples/30-payload-bound-approvals.ts) | two people sign the exact refund; missing approval, one signer, changed amount or beneficiary, extra arguments, and expiry are refused; the approved call executes once, its replay is refused, and every receipt verifies with separately trusted approval keys | `src/approval.ts`, `src/gateway.ts`, `src/verify.ts` |
40
43
 
41
44
  ## How policies are defined, in one paragraph
42
45
 
@@ -45,6 +48,8 @@ A policy is a Cedar file. The gateway turns each tool call into a Cedar request:
45
48
  ## Where each guide goes deeper
46
49
 
47
50
  - [usage.md](usage.md): gateway setup and wiring into hosts
51
+ - [approvals.md](approvals.md): exact-action signatures, two-person thresholds, consumption, and privacy limits
52
+ - [financial-operations.md](financial-operations.md): payment retries, budget reservations, provider contract, and operator reconciliation
48
53
  - [sdk.md](sdk.md): the interceptor and every adapter
49
54
  - [policies.md](policies.md): the Cedar mapping, evaluation rules, tested examples, gotchas
50
55
  - [verification.md](verification.md): every check and what a verified receipt does and does not prove
package/docs/usage.md CHANGED
@@ -131,6 +131,8 @@ Exactly one of the two. The bearer token comes from the named environment variab
131
131
 
132
132
  `mode` is `"enforce"` by default. Set it to `"observe"` to run a new policy against real traffic before turning it on: every call the grant allows is forwarded, the decision the policy would have made is recorded on the receipt with `enforced: false`, and nothing is withheld. Observe mode suspends the policy and nothing else: a tool outside the grant's scopes, or a call after the grant expired or was revoked, is denied and never forwarded in either mode. The verifier accepts such a receipt and names the mode; strip the flag and the same receipt fails. Switch to `"enforce"` when the receipts stop saying "would have been denied" for calls you meant to allow.
133
133
 
134
+ To test a different policy against the history already collected, run `agent-custody policy simulate --policy proposed.cedar --receipts receipts --issuer-key keys/gateway.pub --principal-key keys/principal.pub --out simulation.json`. It replays recorded arguments and fact values without calling upstreams, lists changed decisions by tool and reason with the receipt ids, and records the proposed policy digest. Missing replay inputs make the report incomplete. See [the policy simulation guide](policies.md#simulating-a-policy-against-recorded-history).
135
+
134
136
  The grant is checked on every call, not only when the session opens: a call after `expiresAt` is denied with a receipt that says so, the check is repeated just before the forward (a grant that ran out while the facts were gathered leaves the call `withheld`), and over HTTP a session whose grant has expired or been revoked is closed on its next request with `403`. `"revokedGrants": "revoked.json"` names a file of grant digests the gateway re-reads whenever it changes. The digest is sha256 over the grant's signed payload, so extra signatures or fields on the envelope do not change it, and revoking a grant also revokes every grant delegated from it. A file that cannot be read denies every call until it can be read; `agent-custody revoke --config gateway.json --grant grant.json` appends a grant's digest to it, after which every session under that grant refuses its next call and no new session opens for it, with no key rotation. `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, or answers with a head or proof that does not verify, 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.
135
137
 
136
138
  **5. Run the gateway.** It speaks MCP on stdin/stdout and logs to stderr only.
@@ -141,6 +143,30 @@ node src/cli.ts gateway --config ./gateway.json
141
143
 
142
144
  You will not normally run this by hand. The agent host spawns it, as below.
143
145
 
146
+ ## Require a human approval
147
+
148
+ A grant can permit a tool while a human must still approve each exact action. Add `approvals` to the gateway config:
149
+
150
+ ```json
151
+ {
152
+ "approvals": {
153
+ "trustedKeys": ["keys/approver.pub", "keys/second-approver.pub"],
154
+ "usedDir": "approvals-used",
155
+ "tools": [{ "tool": "stripe.refund", "minApprovers": 2, "fields": { "beneficiary": "customer_id" } }]
156
+ }
157
+ }
158
+ ```
159
+
160
+ The caller puts an approver-signed DSSE envelope in `_meta["agent-custody/approval"]`. It binds the principal, agent, tool, complete argument digest, amount in integer minor units, currency, beneficiary, and expiry. The gateway refuses an approval whose lifetime exceeds `approvals.maxLifetimeSeconds` (default `3600`). A second approver countersigns the same envelope for a two-key rule. Missing, expired, mismatched, or insufficiently signed approvals deny the call even in observe mode. A valid approval still needs a valid grant and an allowing policy.
161
+
162
+ The gateway checks again and consumes the approval id immediately before forwarding. Keep `usedDir` persistent and shared by every gateway that accepts the same approvals; a restart, crash, or unknown upstream outcome never releases a consumed id. The receipt embeds the approval evidence; `verify --approval-key` uses separate human public keys to check it. Single use is enforced by the store, not proved globally by one offline receipt.
163
+
164
+ Under a private capture rule the receipt withholds the approval envelope as a commitment, because it carries the action fields and an unsalted digest of all arguments. The status, the times, and the signer key ids stay in clear. Full approval verification then requires the capture key or a disclosure. [The approval guide](approvals.md) covers signing, field mappings, failure recovery, and these privacy limits; [tutorial 30](../examples/30-payload-bound-approvals.ts) runs it end to end.
165
+
166
+ ## Financial operations
167
+
168
+ For payments, configure `operations` to bind a caller-retained operation UUID to the full call, reserve its amount atomically, and pass an idempotency key to the provider. Existing operations are never forwarded again on retry, and an allowed retry gets a `withheld` receipt of its own. API execution and financial settlement have separate statuses; uncertain outcomes hold their reservations until an operator's provider read commits a reconciliation receipt. The [financial operations guide](financial-operations.md) has the config, provider contract, and `agent-custody reconcile` command. [Tutorial 29](../examples/29-financial-operations.ts) runs the lost-response/restart scenario offline.
169
+
144
170
  ## Private evidence
145
171
 
146
172
  A receipt carries the call as it happened: the arguments, the result, and the facts the policy decided on. Some of that a reviewer has no business seeing: the note on a refund with the caller's phone number, the customer record the policy read, the provider's full answer. `capture` in the config says, per tool, what the receipt file carries of each part:
@@ -179,7 +205,7 @@ A reviewer verifies such a receipt three ways:
179
205
 
180
206
  The salts file, `receipts/salts/<id>.json`, is written for the owner alone (mode 0600 in a 0700 directory) and is as sensitive as the values: with it a guess can be confirmed. In mode `digest` it is also the only copy of each salt: lose it, and nobody can disclose those values again, not even the party that holds them, since a value alone cannot be checked against its commitment; the receipt then verifies only as committed. Back the directory up with the receipts, under the same access control as the values themselves. Mode `encrypted` carries each salt inside the ciphertext and nowhere else (the salts file holds only the digest-only ones), so the key alone recovers everything; choose it when a key is easier to keep safe than a directory of files. The key must be 32 random bytes: a reviewer sees its sha256 as `keyid` in every encrypted commitment, which is harmless for a random key and an offline oracle for a key derived from a passphrase. `agent-custody prune` removes the salts and the pre-committed authorization with the receipt.
181
207
 
182
- The limits. A commitment covers a top-level field, so a field is withheld whole, not in part; put what a reviewer may see in fields of its own. An upstream's own signature covers `contentDigest`, an unsalted sha256 over `{ content, isError }` that the upstream computes, so a reviewer holding the upstream's key and a guess of the whole result can confirm the guess; the gateway cannot salt what the upstream signs. A `digest`-only value can be recomputed only by whoever holds it. A result's top-level `_meta` is withheld whatever the rule says, but a `content` item listed in `clear` is kept whole, its own item-level `_meta` or annotations included; list `content` in `clear` only when every item is fit for a reviewer. The verifier cannot tell a redacted receipt from a complete one beyond the capture note; what it establishes is that whatever is shown, disclosed, or decrypted is the value the signed digest was made over. Nothing here changes what the log receives: a remote log run with `hashOnly` gets leaf hashes, as before, and the exporters are handed the same view as the file and carry digests only. The browser verifier at agent-custody.dev/verify reports the committed case and takes no key or disclosure; use the command-line verifier for those. Tutorial 26 runs the refund above end to end.
208
+ The limits. A signed human approval carries its action fields and an unsalted full-argument digest, so a private rule withholds its envelope; see [approval privacy limits](approvals.md#privacy-limits). A commitment covers a top-level field, so a field is withheld whole, not in part; put what a reviewer may see in fields of its own. An upstream's own signature covers `contentDigest`, an unsalted sha256 over `{ content, isError }` that the upstream computes, so a reviewer holding the upstream's key and a guess of the whole result can confirm the guess; the gateway cannot salt what the upstream signs. A `digest`-only value can be recomputed only by whoever holds it. A result's top-level `_meta` is withheld whatever the rule says, but a `content` item listed in `clear` is kept whole, its own item-level `_meta` or annotations included; list `content` in `clear` only when every item is fit for a reviewer. The verifier cannot tell a redacted receipt from a complete one beyond the capture note; what it establishes is that whatever is shown, disclosed, or decrypted is the value the signed digest was made over. Nothing here changes what the log receives: a remote log run with `hashOnly` gets leaf hashes, as before, and the exporters are handed the same view as the file and carry digests only. The browser verifier at agent-custody.dev/verify reports the committed case and takes no key or disclosure; use the command-line verifier for those. Tutorial 26 runs the refund above end to end.
183
209
 
184
210
  ## One gateway for many agents, over HTTP
185
211
 
@@ -284,7 +310,7 @@ Any other MCP client works the same way: Python's `mcp` package, LangGraph's MCP
284
310
  | --- | --- | --- | --- |
285
311
  | executed | as returned by upstream | upstream's content, untouched | `_meta["agent-custody/receipt"]` |
286
312
  | upstream returned an error | `true` | upstream's content | same |
287
- | denied by scope or policy | `true` | `Denied by policy: <reason> (receipt <id>)` | same |
313
+ | denied by scope, approval, or policy | `true` | `Denied by policy: <reason> (receipt <id>)` | same |
288
314
  | upstream unreachable | `true` | `Upstream error: <message> (receipt <id>)` | same |
289
315
 
290
316
  The receipt id is the file name under `receiptsDir`.
@@ -6,7 +6,9 @@ A verifier needs three things and no network access:
6
6
  2. the issuer's public key: the gateway key, or the application key for SDK receipts
7
7
  3. the principal's public key, for gateway receipts, which carry a signed delegation
8
8
 
9
- A fourth is optional: a copy of the log file, which lets the verifier confirm the receipt sits in a log whose root the verifier recomputed, not one the issuer merely asserted.
9
+ A receipt carrying approval evidence for a forwarded call also needs the human approvers' public keys, trusted separately from issuer and principal keys.
10
+
11
+ A copy of the log file is optional. It lets the verifier confirm the receipt sits in a log whose root the verifier recomputed, not one the issuer merely asserted.
10
12
 
11
13
  When the issuer logs to a remote log, the tree head is signed by the log's key rather than the issuer's. The verifier then needs that public key too, and the report says which key signed the tree head. That is the point of a remote log: a tree head signed by a party that is not the operator says the receipt was in a log the operator could not rewrite. A tree head signed by the issuer's own key says only that the issuer has not changed its story since.
12
14
 
@@ -16,14 +18,17 @@ When the issuer logs to a remote log, the tree head is signed by the log's key r
16
18
  node src/cli.ts verify receipts/<id>.json \
17
19
  --issuer-key keys/gateway.pub \
18
20
  --principal-key keys/principal.pub \
19
- --log-key keys/log.pub \ # only for receipts logged to a remote log
20
- --upstream-key keys/upstream.pub \ # only when the upstream signed its result
21
- --log log.jsonl # optional
21
+ --approval-key keys/approver.pub \
22
+ --log-key keys/log.pub \
23
+ --upstream-key keys/upstream.pub \
24
+ --log log.jsonl
22
25
  ```
23
26
 
24
- Exit code 0 when every check passes, 1 otherwise. Add `--json` for machine-readable output. `--issuer-key` and `--principal-key` can be repeated to accept rotated keys; signatures are matched by keyid. `--gateway-key` is an alias for `--issuer-key`. `--principal-key` may be omitted for SDK receipts, which carry no delegation.
27
+ `--approval-key` is needed for forwarded calls carrying human approvals (not for a refusal), `--log-key` for a remote log, and `--upstream-key` when checking a signed upstream result. `--log` is optional.
28
+
29
+ Exit code 0 when every check passes, 1 otherwise. Add `--json` for machine-readable output. `--issuer-key`, `--principal-key`, and `--approval-key` can be repeated to accept rotated keys; signatures are matched by keyid. `--gateway-key` is an alias for `--issuer-key`. `--principal-key` may be omitted for SDK receipts, which carry no delegation.
25
30
 
26
- When a receipt was issued under a capture rule ([private evidence](usage.md#private-evidence)), some of its arguments, result, or facts are commitments rather than values. `--capture-key-env NAME` names the environment variable holding the customer's capture key: the verifier decrypts every encrypted field, checks it against its commitment, and recomputes the digests from the real values. `--disclose disclosure.json` does the same from a file holding the withheld values, `{ "receiptId", "args"?, "result"? }`, as `agent-custody reveal` writes it or as the party that holds them hands it over. Without either, the withheld parts pass as committed and the report says so.
31
+ When a receipt was issued under a capture rule ([private evidence](usage.md#private-evidence)), some of its arguments, result, or facts are commitments rather than values. `--capture-key-env NAME` names the environment variable holding the customer's capture key: the verifier decrypts every encrypted field, checks it against its commitment, and recomputes the digests from the real values. `--disclose disclosure.json` does the same from a file holding the withheld values, `{ "receiptId", "args"?, "result"? }`, as `agent-custody reveal` writes it or as the party that holds them hands it over. Without either, the receipt digest checks pass as committed and the report says so. For a forwarded call carrying approval evidence, the separate approval payload binding check fails while any argument remains withheld.
27
32
 
28
33
  A real report, produced by `node scripts/demo.ts`:
29
34
 
@@ -62,6 +67,8 @@ policy observed allow [policy1] policy ba4e4461ffc4
62
67
  execution observed executed
63
68
  ```
64
69
 
70
+ A refused call's `execution` row carries the reason the receipt records, for example `denied: delegation grant has been revoked`, and so does a `withheld` one. Under a capture rule the reason is a commitment, and the row says `(reason withheld under the capture rule)` rather than printing it.
71
+
65
72
  ## What each check means
66
73
 
67
74
  | check | what it establishes | what a failure usually means |
@@ -78,6 +85,10 @@ execution observed executed
78
85
  | delegation valid at receipt time | the receipt's timestamp is inside the grant's window; a call the gateway refused after the grant ran out passes with a note, since only an executed call must sit inside the window | expired or not-yet-valid authority behind an executed call |
79
86
  | executed tool within delegated scope | if the tool ran, the grant covered it. Denied calls pass this check by construction | a gateway that forwarded out of scope |
80
87
  | principal is claimed, not attested | SDK receipts only: there is no delegation, so the principal is a config string and is labelled as such | an SDK receipt pretending to an attested principal |
88
+ | approval signatures (human keys) | for a forwarded call carrying an approval record, enough distinct human approval keys signed the embedded envelope; issuer and principal keys never substitute. Under a private rule the envelope is a commitment: the check passes as committed until it is disclosed or decrypted. It fails when the envelope is withheld beside arguments in clear | missing approval keys, untrusted signer, or insufficient threshold |
89
+ | approval payload binding | the signed approval names the same principal, agent, tool, complete arguments, and configured amount/currency/beneficiary | changed arguments or a spliced approval. Arguments that are still withheld pass as committed, as `request args digest` does; disclose them or provide the capture key to check the full binding |
90
+ | approval valid at forward time | the approval was valid at the recorded check and consumption times (forwarded calls only) | expiry or a future issuance time behind a forwarded call |
91
+ | approval consistent with execution | forwarded calls with approval evidence have an approved, consumed record with matching signer observations; denied or withheld calls verify as evidence of refusal without endorsing the rejected approval | an execution without the recorded approval consumption, or inconsistent observed signer ids |
81
92
  | request args digest | the args in the predicate hash to the digest in the subject. Recomputed when the arguments are in clear, disclosed with `--disclose`, or decrypted with `--capture-key-env`; when fields are withheld and neither is given, it passes as committed, the detail saying "committed, not recomputed" and how many fields are withheld | edited arguments, or a disclosure that contradicts a commitment |
82
93
  | execution result digest | executed and failed calls: the result in the predicate hashes to `execution.resultDigest`, under the same rules as the arguments; a provider delivery withheld with the result is restored first, since the digest covered it | an edited result, or a disclosure or key that does not match the commitment, or a capture note naming a field that is not a commitment |
83
94
  | fact `<name>` value, fact `<name>` args | only for a captured fact: its commitments hold against the disclosed or decrypted value, or pass as committed when neither is given | a disclosure that lies about a fact the policy decided on |
@@ -86,6 +97,8 @@ execution observed executed
86
97
  | no policy errors on an allow | an allow was not produced while Cedar reported errors | broken fail-closed behaviour |
87
98
  | authorization signature (issuer key) | pre-commit receipts only: the embedded authorization statement was signed by the same issuer key as the receipt | an authorization from another gateway, or none the issuer signed |
88
99
  | authorization names this call | the committed authorization names this receipt id, tool, argument digest, agent, and principal, and recorded an allow | an authorization spliced in from a different call |
100
+ | authorization carries this approval | when present, the human approval envelope, signature threshold, and field mapping match the final receipt | a different approval substituted after the precommit |
101
+ | authorization approval was valid | for a forwarded call, the precommit recorded an approved statement, distinct trusted signer observations, and a check inside the signed window. Under a private rule only the status, the times, and the signer count are checked until the envelope is restored | an invalid initial approval hidden by a valid final receipt |
89
102
  | authorization tree head signature | the authorization's own tree head is signed by a trusted log or issuer key | a fabricated log position for the authorization |
90
103
  | authorization log inclusion proof | the authorization statement is a leaf of that tree | an authorization that was never logged |
91
104
  | authorization logged before execution | the authorization's leaf precedes the receipt's leaf, at a tree size no larger than the receipt's | evidence written after the side effect, dressed up as before |
@@ -95,7 +108,9 @@ execution observed executed
95
108
  | log inclusion proof | this exact envelope is a leaf of the tree with that root | receipt never logged, or logged then changed |
96
109
  | log file root matches tree head | recomputing the root from your copy of the log at that size gives the same value | your log copy and the issuer's history diverge: deletion, reordering, or edit |
97
110
 
98
- Gateway receipts run seventeen checks, eighteen with a log file, one more (`execution result digest`) when the call was executed or failed, and five more when the tool was committed before it ran (`precommit` in the gateway config). SDK receipts run fewer, because there is no delegation to check, and the report says so on the `principal is claimed` line. A receipt issued to a sub-agent under a delegation chain runs one more, `delegation chain to the principal`.
111
+ Approval-bearing forwarded calls add four approval checks. A refused call runs only `approval consistent with execution`, so it verifies without approval keys, with a valid approval or with the invalid approval that caused its refusal. Gateway receipts otherwise run seventeen checks, eighteen with a log file, one more (`execution result digest`) when the call was executed or failed, and five more when the tool was committed before it ran (`precommit` in the gateway config). SDK receipts run fewer, because there is no delegation to check, and the report says so on the `principal is claimed` line. A receipt issued to a sub-agent under a delegation chain runs one more, `delegation chain to the principal`.
112
+
113
+ Financial receipts add `operation …` checks and `authorization names this operation` for the durable id (absent under a private capture rule; the provider key then links the receipts), provider key, precommitted lookup, and budget. Reconciliation receipts embed their original receipt or authorization and run its checks under `reconciliation original …`, reject nested reconciliation evidence, preserve identity at `reconciliation links the original operation`, and check the configured mapping and provider record at `reconciliation lookup matches authorization`, `reconciliation lookup args match request`, and `reconciliation provider status`. The provider's terminal state must agree with the financial outcome and its record must echo the idempotency key. `reconciliation logged after original` checks ordering. These observations do not independently prove settlement without trusting the gateway and provider; private provider results verify as committed until disclosed or decrypted. See [financial operations](financial-operations.md).
99
114
 
100
115
  ## What a verified receipt lets you conclude
101
116
 
@@ -108,9 +123,11 @@ For an SDK receipt the statement is shorter: a process holding the application k
108
123
  A gateway receipt does **not** support:
109
124
 
110
125
  - that Stripe really executed the refund. The upstream result is `observed`, not signed by Stripe. That is the first roadmap item.
111
- - that the side effect exists because the receipt does, unless the receipt carries an authorization. Without one, the call was forwarded first and logged second. With one, the five `authorization` checks establish that the gateway had committed the call to the log before it went out, and a `withheld` execution establishes that it never went out.
126
+ - that the side effect exists because the receipt does, unless the receipt carries an authorization. Without one, the call was forwarded first and logged second. With one, the `authorization` checks establish that the gateway had committed the call to the log before it went out, including the human approval when required, and a `withheld` execution establishes that it never went out.
112
127
  - that the arguments were correct. They are `claimed`: they are what the agent asked for, which is what a receipt should record.
113
128
  - that a receipt issued under a capture rule shows everything the call carried. The `capture` note says which fields are withheld; the verifier establishes that every value shown, disclosed, or decrypted is the one the signed digest was made over, and nothing about the ones it was not shown.
129
+ - that a human approval was not used by another gateway. The signature establishes the exact action and window; single use depends on the gateway's persistent consumption store shared across every process that accepts the approval.
130
+ - that a human approval is valid, for a reviewer who holds neither the capture key nor a disclosure: under a private rule the receipt withholds the approval envelope, because it carries the action fields and an unsalted digest of all arguments. The approval checks then pass as committed. See [approval privacy limits](approvals.md#privacy-limits).
114
131
  - that the model named in `model` produced the call. No hosted provider signs model identity.
115
132
  - that the gateway operator is honest. The operator holds the gateway key. Against a dishonest operator you need a log copy taken out of their control, or a signer they do not control. See the threat model table in the README.
116
133
 
@@ -129,6 +146,7 @@ const bundle = JSON.parse(readFileSync("receipts/<id>.json", "utf8"));
129
146
  const result = verifyBundle(bundle, {
130
147
  issuerKeys: [loadPublicKey("keys/gateway.pub")], // gateway keys and SDK application keys
131
148
  principalKeys: [loadPublicKey("keys/principal.pub")],
149
+ approvalKeys: [loadPublicKey("keys/approver.pub")], // separately trusted human keys; repeat for a two-key rule
132
150
  logKeys: [loadPublicKey("keys/log.pub")], // only for receipts logged to a remote log
133
151
  upstreamKeys: [loadPublicKey("keys/upstream.pub")], // only when the upstream signed its result
134
152
  logFile: "log.jsonl", // optional
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/receipts",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "mcpName": "io.github.svayatta/agent-custody",
5
5
  "description": "Chain of custody for AI agents: signed, independently verifiable receipts for tool calls. MCP gateway + Cedar policy + Merkle transparency log",
6
6
  "license": "Apache-2.0",
@@ -7,26 +7,26 @@
7
7
  "description": "The tree head from the first remote receipt and the log's later head, with the proof the log served.",
8
8
  "older": {
9
9
  "payloadType": "application/vnd.agent-custody.treehead+json",
10
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiNzdjN2EwY2Y5ZDEyMDgwMjRhYjNiMTQxMDEyMmRlZjlmOGRhOTIyNmRjYTQwMTZjNThmM2Q4NzZhYzRkMzBjNyIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODc1WiIsInRyZWVTaXplIjoxfQ==",
10
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMGI5NTIzZmNkZTBhZjVkOWY3YmEwNjBiN2FjNmJkZDhiMGQ5NWMyYThmNjQ2YWE3M2RkNjRkOWU1ZmY5YjA0NSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuMzk1WiIsInRyZWVTaXplIjoxfQ==",
11
11
  "signatures": [
12
12
  {
13
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
14
- "sig": "9XqRx/eFTPQjZ/6W/AKuR+Epc9MonrHj2mVuVy3lm36uUPpACqquwkwE/aALm5dip2YDKZmUnvAc/725nd4nCg=="
13
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
14
+ "sig": "nnKYCsy34ZDyS7Cnt3phxIzBfmchs+Ref/0NdgCX4td6rDkuPilOxVNaDfverl20m0FPCKrBT4Q0lk4BF02jBg=="
15
15
  }
16
16
  ]
17
17
  },
18
18
  "newer": {
19
19
  "payloadType": "application/vnd.agent-custody.treehead+json",
20
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiYzlmNmQ0ZmE0OWMxZjJlMTk2YmNiYzQ3OTlkMDgyM2I4MGRkODQyYWNkMzkyZjljYjdmN2ZmNmFmMjI5MTEwNSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODgwWiIsInRyZWVTaXplIjoyfQ==",
20
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMmRhOGE5MWUyZTVmZjNkYmQ4Y2U2YmQ4MWJmN2MzZDBkZmNlMjUwMzI1OGU1Y2M2YWRiNmNiZDVhOThlOGQ5YiIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuNDAzWiIsInRyZWVTaXplIjoyfQ==",
21
21
  "signatures": [
22
22
  {
23
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
24
- "sig": "6QGCyD4s5SikhHjkd9Gj6zTQOte5kwVtFMJAKyY5+4lp/3OacFmLTLCNOZaX8jGjDneLUeSBSXwk+O16HaxaDg=="
23
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
24
+ "sig": "SgzzdIYTvzGe0YJwaar5BIoQsypXrqaqPMEUJ8dk+rHbxVMMoHhwEcpvw21irNpAuKOEwbEHJ+q6pVygJD4hDA=="
25
25
  }
26
26
  ]
27
27
  },
28
28
  "proof": [
29
- "17f730b5e2ca1e353cfbb98df022d32ef43abaefe7942675a2595de51ae37b55"
29
+ "2a06b62fb52f6ff6b0c0e80166cb7624270ea69b0482f503f69aacb08b03131a"
30
30
  ],
31
31
  "keys": [
32
32
  "log"
@@ -41,26 +41,26 @@
41
41
  "description": "The same heads the wrong way round.",
42
42
  "older": {
43
43
  "payloadType": "application/vnd.agent-custody.treehead+json",
44
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiYzlmNmQ0ZmE0OWMxZjJlMTk2YmNiYzQ3OTlkMDgyM2I4MGRkODQyYWNkMzkyZjljYjdmN2ZmNmFmMjI5MTEwNSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODgwWiIsInRyZWVTaXplIjoyfQ==",
44
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMmRhOGE5MWUyZTVmZjNkYmQ4Y2U2YmQ4MWJmN2MzZDBkZmNlMjUwMzI1OGU1Y2M2YWRiNmNiZDVhOThlOGQ5YiIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuNDAzWiIsInRyZWVTaXplIjoyfQ==",
45
45
  "signatures": [
46
46
  {
47
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
48
- "sig": "6QGCyD4s5SikhHjkd9Gj6zTQOte5kwVtFMJAKyY5+4lp/3OacFmLTLCNOZaX8jGjDneLUeSBSXwk+O16HaxaDg=="
47
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
48
+ "sig": "SgzzdIYTvzGe0YJwaar5BIoQsypXrqaqPMEUJ8dk+rHbxVMMoHhwEcpvw21irNpAuKOEwbEHJ+q6pVygJD4hDA=="
49
49
  }
50
50
  ]
51
51
  },
52
52
  "newer": {
53
53
  "payloadType": "application/vnd.agent-custody.treehead+json",
54
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiNzdjN2EwY2Y5ZDEyMDgwMjRhYjNiMTQxMDEyMmRlZjlmOGRhOTIyNmRjYTQwMTZjNThmM2Q4NzZhYzRkMzBjNyIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODc1WiIsInRyZWVTaXplIjoxfQ==",
54
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMGI5NTIzZmNkZTBhZjVkOWY3YmEwNjBiN2FjNmJkZDhiMGQ5NWMyYThmNjQ2YWE3M2RkNjRkOWU1ZmY5YjA0NSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuMzk1WiIsInRyZWVTaXplIjoxfQ==",
55
55
  "signatures": [
56
56
  {
57
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
58
- "sig": "9XqRx/eFTPQjZ/6W/AKuR+Epc9MonrHj2mVuVy3lm36uUPpACqquwkwE/aALm5dip2YDKZmUnvAc/725nd4nCg=="
57
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
58
+ "sig": "nnKYCsy34ZDyS7Cnt3phxIzBfmchs+Ref/0NdgCX4td6rDkuPilOxVNaDfverl20m0FPCKrBT4Q0lk4BF02jBg=="
59
59
  }
60
60
  ]
61
61
  },
62
62
  "proof": [
63
- "17f730b5e2ca1e353cfbb98df022d32ef43abaefe7942675a2595de51ae37b55"
63
+ "2a06b62fb52f6ff6b0c0e80166cb7624270ea69b0482f503f69aacb08b03131a"
64
64
  ],
65
65
  "keys": [
66
66
  "log"
@@ -77,26 +77,26 @@
77
77
  "description": "Tree heads checked against the app key, which did not sign them.",
78
78
  "older": {
79
79
  "payloadType": "application/vnd.agent-custody.treehead+json",
80
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiNzdjN2EwY2Y5ZDEyMDgwMjRhYjNiMTQxMDEyMmRlZjlmOGRhOTIyNmRjYTQwMTZjNThmM2Q4NzZhYzRkMzBjNyIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODc1WiIsInRyZWVTaXplIjoxfQ==",
80
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMGI5NTIzZmNkZTBhZjVkOWY3YmEwNjBiN2FjNmJkZDhiMGQ5NWMyYThmNjQ2YWE3M2RkNjRkOWU1ZmY5YjA0NSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuMzk1WiIsInRyZWVTaXplIjoxfQ==",
81
81
  "signatures": [
82
82
  {
83
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
84
- "sig": "9XqRx/eFTPQjZ/6W/AKuR+Epc9MonrHj2mVuVy3lm36uUPpACqquwkwE/aALm5dip2YDKZmUnvAc/725nd4nCg=="
83
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
84
+ "sig": "nnKYCsy34ZDyS7Cnt3phxIzBfmchs+Ref/0NdgCX4td6rDkuPilOxVNaDfverl20m0FPCKrBT4Q0lk4BF02jBg=="
85
85
  }
86
86
  ]
87
87
  },
88
88
  "newer": {
89
89
  "payloadType": "application/vnd.agent-custody.treehead+json",
90
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiYzlmNmQ0ZmE0OWMxZjJlMTk2YmNiYzQ3OTlkMDgyM2I4MGRkODQyYWNkMzkyZjljYjdmN2ZmNmFmMjI5MTEwNSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODgwWiIsInRyZWVTaXplIjoyfQ==",
90
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMmRhOGE5MWUyZTVmZjNkYmQ4Y2U2YmQ4MWJmN2MzZDBkZmNlMjUwMzI1OGU1Y2M2YWRiNmNiZDVhOThlOGQ5YiIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuNDAzWiIsInRyZWVTaXplIjoyfQ==",
91
91
  "signatures": [
92
92
  {
93
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
94
- "sig": "6QGCyD4s5SikhHjkd9Gj6zTQOte5kwVtFMJAKyY5+4lp/3OacFmLTLCNOZaX8jGjDneLUeSBSXwk+O16HaxaDg=="
93
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
94
+ "sig": "SgzzdIYTvzGe0YJwaar5BIoQsypXrqaqPMEUJ8dk+rHbxVMMoHhwEcpvw21irNpAuKOEwbEHJ+q6pVygJD4hDA=="
95
95
  }
96
96
  ]
97
97
  },
98
98
  "proof": [
99
- "17f730b5e2ca1e353cfbb98df022d32ef43abaefe7942675a2595de51ae37b55"
99
+ "2a06b62fb52f6ff6b0c0e80166cb7624270ea69b0482f503f69aacb08b03131a"
100
100
  ],
101
101
  "keys": [
102
102
  "app"
@@ -114,21 +114,21 @@
114
114
  "description": "A proof with a hash removed.",
115
115
  "older": {
116
116
  "payloadType": "application/vnd.agent-custody.treehead+json",
117
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiNzdjN2EwY2Y5ZDEyMDgwMjRhYjNiMTQxMDEyMmRlZjlmOGRhOTIyNmRjYTQwMTZjNThmM2Q4NzZhYzRkMzBjNyIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODc1WiIsInRyZWVTaXplIjoxfQ==",
117
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMGI5NTIzZmNkZTBhZjVkOWY3YmEwNjBiN2FjNmJkZDhiMGQ5NWMyYThmNjQ2YWE3M2RkNjRkOWU1ZmY5YjA0NSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuMzk1WiIsInRyZWVTaXplIjoxfQ==",
118
118
  "signatures": [
119
119
  {
120
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
121
- "sig": "9XqRx/eFTPQjZ/6W/AKuR+Epc9MonrHj2mVuVy3lm36uUPpACqquwkwE/aALm5dip2YDKZmUnvAc/725nd4nCg=="
120
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
121
+ "sig": "nnKYCsy34ZDyS7Cnt3phxIzBfmchs+Ref/0NdgCX4td6rDkuPilOxVNaDfverl20m0FPCKrBT4Q0lk4BF02jBg=="
122
122
  }
123
123
  ]
124
124
  },
125
125
  "newer": {
126
126
  "payloadType": "application/vnd.agent-custody.treehead+json",
127
- "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiYzlmNmQ0ZmE0OWMxZjJlMTk2YmNiYzQ3OTlkMDgyM2I4MGRkODQyYWNkMzkyZjljYjdmN2ZmNmFmMjI5MTEwNSIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTE6MDQ6MzkuODgwWiIsInRyZWVTaXplIjoyfQ==",
127
+ "payload": "eyJsb2ciOiJ2ZWN0b3JzLWxvZyIsInJvb3RIYXNoIjoiMmRhOGE5MWUyZTVmZjNkYmQ4Y2U2YmQ4MWJmN2MzZDBkZmNlMjUwMzI1OGU1Y2M2YWRiNmNiZDVhOThlOGQ5YiIsInRpbWVzdGFtcCI6IjIwMjYtMTAtMThUMTg6MTU6MTkuNDAzWiIsInRyZWVTaXplIjoyfQ==",
128
128
  "signatures": [
129
129
  {
130
- "keyid": "a41979e61e630632f122dfa2aab6b31d54f99b5c3947833e7e9d5b866ce50686",
131
- "sig": "6QGCyD4s5SikhHjkd9Gj6zTQOte5kwVtFMJAKyY5+4lp/3OacFmLTLCNOZaX8jGjDneLUeSBSXwk+O16HaxaDg=="
130
+ "keyid": "158f241c3f03fef38c33231e2b8047f7b47dbb2486c1ac5a3e438168ecb4a258",
131
+ "sig": "SgzzdIYTvzGe0YJwaar5BIoQsypXrqaqPMEUJ8dk+rHbxVMMoHhwEcpvw21irNpAuKOEwbEHJ+q6pVygJD4hDA=="
132
132
  }
133
133
  ]
134
134
  },