@agent-custody/receipts 0.16.12 → 0.16.13

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,173 @@
1
+ # The agent registry
2
+
3
+ An organisation that runs agents registers each one on the portal, and the portal signs it a **passport**. A site whose [door](door.md) trusts the registry's key admits that agent as `verified`. The site needs nothing per agent, and the door asks the registry nothing when a request arrives.
4
+
5
+ ## What a passport is
6
+
7
+ A passport is a DSSE envelope of type `application/vnd.agent-custody.passport+json`, signed by the registry's key:
8
+
9
+ ```json
10
+ {
11
+ "version": "0.1",
12
+ "registry": "https://app.agent-custody.dev/",
13
+ "agentId": "agt_5325ae63b111bdcb",
14
+ "agent": "did:key:z6Mkn6Tz2tjzcb8f…",
15
+ "name": "Carted shopper",
16
+ "owner": "carted",
17
+ "contact": "agents@carted.example",
18
+ "capabilities": ["refunds"],
19
+ "issuedAt": "2026-11-23T09:00:00.000Z",
20
+ "expiresAt": "2026-11-24T09:00:00.000Z"
21
+ }
22
+ ```
23
+
24
+ - `agent` is the agent's own Ed25519 key, written as a [did:key](https://w3c-ccg.github.io/did-key-spec/). The agent holds the private key; the registry never sees it.
25
+ - `owner` is the portal tenant that registered the agent. `contact` is how a site reaches the agent's operator.
26
+ - `capabilities` are the organisation's own words for what the agent does: lowercase letters, digits, and `. _ : -`, at most 32. The registry does not check them. A site's policy decides what they are worth.
27
+ - A passport lives for a day by default (`--passport-seconds`, from 60 seconds to 7 days), and never past the registration's own expiry.
28
+ - `erc8004`, when the agent is [linked to an ERC-8004 identity](#link-an-erc-8004-identity): `{ agentRegistry, agentId, owner, block }`, as the registry last checked it on chain.
29
+
30
+ **A passport is public.** It proves nothing without a signature by the agent's key on the same request, so the registry serves one to anyone who asks, like a certificate.
31
+
32
+ ## Register an agent
33
+
34
+ The portal runs the registry when it starts with a registry key, and `--portal-url`, which names the registry in every passport:
35
+
36
+ ```bash
37
+ agent-custody keygen --dir keys --name registry
38
+ export REGISTRY_KEY="$(cat keys/registry.key)"
39
+ agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url https://log.example/ \
40
+ --portal-url https://app.example/ --registry-key-env REGISTRY_KEY
41
+ ```
42
+
43
+ The registry key is its own, never the log's. To keep it out of the process that faces the internet, hold it in a signer, `agent-custody signer --key keys/registry.key --port 8791 --token-env REGISTRY_SIGNER_TOKEN`, and start the portal with `--registry-signer-url http://signer:8791/ --registry-signer-token-env REGISTRY_SIGNER_TOKEN` instead.
44
+
45
+ An admin of a tenant registers an agent with the agent's did:key, a proof that whoever registers it holds that key, a contact, its capabilities, and an expiry at most 366 days out. The agent's operator makes the proof with the agent's private key:
46
+
47
+ ```bash
48
+ agent-custody registry proof --key agent.key --registry https://app.example/ --tenant carted
49
+ # {"agent":"did:key:z6Mk…","proof":"…"}
50
+ curl -b session.txt -H 'content-type: application/json' https://app.example/api/agents \
51
+ -d '{ "name": "Carted shopper", "contact": "agents@carted.example", "capabilities": ["refunds"],
52
+ "agent": "did:key:z6Mk…", "proof": "…", "expiresAt": "2027-02-21T00:00:00Z" }'
53
+ ```
54
+
55
+ The proof is the key's Ed25519 signature over the registry's URL, the tenant, and the did:key (`registrationProof` in code), so it registers that key with that tenant at that registry only. Without it, a tenant could register a did:key it saw in a grant or a signature and choose that agent's capabilities. A key rotation needs the new key's proof.
56
+
57
+ The answer has the registry entry and a first passport. Every key belongs to one live agent, which the database enforces, and a tenant has at most 100 agents that are not revoked. An expired agent counts until it is revoked. `POST /api/agents/<id>` changes the name, contact, capabilities, key, or expiry, and `POST /api/agents/<id>/revoke` revokes the agent for good. Each is in the tenant's audit trail. The [hosted reference](../../../site/reference/hosted.md) lists every route.
58
+
59
+ In code, `didKeyOf(publicKey)` gives a key's did:key.
60
+
61
+ ## Link an ERC-8004 identity
62
+
63
+ An agent that already has a token in an [ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) Identity Registry can carry it in its passport. The registry vouches for the agent, as before; the link adds the agent's portable on-chain identity, so a site can require one. ERC-8004 is still a draft, and only its `registration-v1` file is read.
64
+
65
+ The portal reads a chain only with an RPC URL for it, from the environment:
66
+
67
+ ```bash
68
+ export BASE_RPC="https://…" # a provider's URL often carries its key
69
+ agent-custody portal … --registry-key-env REGISTRY_KEY --erc8004-rpc-env 8453=BASE_RPC [--ipfs-gateway https://ipfs.io]
70
+ ```
71
+
72
+ The owner adds `"erc8004": { "agentRegistry": "eip155:8453:0x…", "agentId": "7" }` to `POST /api/agents` or `POST /api/agents/<id>`. `agentId` is the token id in decimal. Before it stores the link, the registry reads, at one block:
73
+
74
+ 1. `ownerOf(agentId)`: the token exists and has an owner.
75
+ 2. `tokenURI(agentId)`: where the registration file is. It fetches the file: an inline `data:application/json` URI, `https://` (never from an internal address, following no redirect, within 5 seconds and 64 KiB), or `ipfs://` through `--ipfs-gateway`, as a CID and plain path segments that stay under the gateway's `/ipfs/<cid>/`; a `.` or `..` segment is refused.
76
+ 3. The file: its `type` is `registration-v1`, `active` is true, `registrations` lists this `agentRegistry` and `agentId`, and `services` has `{ "name": "DID", "endpoint": "<the agent's did:key>" }`.
77
+
78
+ So the agent's owner publishes its did:key in the token's registration file first. Anything that does not agree is refused with the reason. The entry records the owner address, the block, the file's sha256, and when it was checked. A new key while a link stands is checked against the file again, so rotate the key in the file first. `"erc8004": null` unlinks.
79
+
80
+ A link is checked again before a passport carries it, when the last check is older than `--erc8004-recheck-seconds` (an hour by default, 60 to 86400), at most once a minute per agent. When that check fails, for example because the owner marked the agent inactive or moved the token to a file that no longer lists the key, passports carry no link until a check succeeds, and the entry shows the error. A check that finishes after the owner changed the link or rotated the key is not stored: it was for a link the agent no longer has.
81
+
82
+ The door reads no chain. It records the link from the passport in `arrival.passport.erc8004`, only when the passport is `verified`, bound to the request by the agent's signature; a passport under another key carries no link into the policy. A policy can require it, testing the outcome too:
83
+
84
+ ```cedar
85
+ permit(principal, action == Action::"refund", resource)
86
+ when {
87
+ context.facts.arrival.class == "verified" &&
88
+ context.facts.arrival has passport &&
89
+ context.facts.arrival.passport.outcome == "verified" &&
90
+ context.facts.arrival.passport has erc8004 &&
91
+ context.facts.arrival.passport.erc8004.agentRegistry == "eip155:8453:0x…"
92
+ };
93
+ ```
94
+
95
+ What the link does not do: it reads the ERC-8004 Identity Registry only, not its Reputation or Validation registries; it does not make anyone's token trustworthy (anyone can register one for gas, which is why the registry still vouches); and a door that trusts ERC-8004 registries directly, with no portal, is not built.
96
+
97
+ ## What the registry publishes
98
+
99
+ | path | what |
100
+ | --- | --- |
101
+ | `GET /.well-known/agent-custody-registry.json` | the registry's key document: its URL, the passport type and header, how long a passport lives, the chain ids whose ERC-8004 registries it reads (`erc8004Chains`), and its keys (`keyid`, `alg`, `publicKeyPem`, `validFrom`) |
102
+ | `GET /registry/agents/<id>` | the agent's entry: name, owner, contact, capabilities, its key as a did:key and as an Ed25519 JWK (`kid` is the did:key, `exp` the registration's expiry), `status` (`active`, `revoked`, or `expired`), and `erc8004`, the linked identity as last checked (with `error` when the last check failed) or null |
103
+ | `GET /registry/agents?capability=&owner=&limit=&after=` | the active agents that hold a capability (or belong to an owner), by id, a page of up to 100 at a time; see [admission lists](admission-lists.md#find-agents-in-the-registry) |
104
+ | `GET /registry/agents/<id>/passport` | a fresh passport for an active agent; `410` for a revoked or expired one |
105
+
106
+ These reads need no session. Each address gets a burst of 120 of them (search, entries, and passports together) and then one every 2 seconds; past that the registry answers `429` with `Retry-After`.
107
+
108
+ The agent fetches a fresh passport before the one it holds expires. It needs no session for that.
109
+
110
+ ## Admit registered agents at a door
111
+
112
+ Put the registry's public key in a file, list it in `trustedRegistryKeys`, and configure `webBotAuth`, which checks the agent's signature. Its `agents` may be empty, because a did:key carries its own key and the door fetches nothing:
113
+
114
+ ```json
115
+ {
116
+ "trustedRegistryKeys": ["keys/registry.pub"],
117
+ "webBotAuth": { "authorities": ["shop.example"] }
118
+ }
119
+ ```
120
+
121
+ The door refuses to start with `trustedRegistryKeys` and no `webBotAuth`. In a Worker the keys are the `TRUSTED_REGISTRY_KEYS` variable.
122
+
123
+ The agent sends the passport as base64url JSON in `X-Agent-Custody-Passport`, and signs the request as for [Web Bot Auth](door.md#a-did-key-signature): RFC 9421, Ed25519, `tag="web-bot-auth"`, a nonce, and `keyid` set to its did:key. For the passport to count, the signature also covers what binds it to this one request:
124
+
125
+ - `@authority`, `@method`, `@path`, `@query` (the query string, or `?` when there is none), and `x-agent-custody-passport`;
126
+ - on any method but GET, HEAD, and OPTIONS, `content-digest`: a `Content-Digest` field (RFC 9530, `sha-256` or `sha-512`) that the door checks against the body it read.
127
+
128
+ ```
129
+ Signature-Input: sig1=("@authority" "@method" "@path" "@query" "x-agent-custody-passport" "content-digest");created=…;expires=…;keyid="did:key:z6Mk…";alg="ed25519";nonce="…";tag="web-bot-auth"
130
+ ```
131
+
132
+ A passport is public, so without that a signature the agent made for one request, or before it held a passport the door would take, could be sent again with the passport attached. A door in authz mode does not see the body, so it admits a passport on a safe method only. With no grant in the request, the door then records:
133
+
134
+ - `class: "verified"`, and `subject` the agent's did:key, which is the Cedar `principal`;
135
+ - `arrival.passport`, with `outcome: "verified"`, the registry, the registry's keyid, the agent's id, did:key, name, owner, capabilities, expiry, the passport's digest, and the passport itself (`envelope`).
136
+
137
+ Only a `verified` passport puts the registry's entry in the fact. Any other outcome records the outcome, the error, and at most the registry and the did:key the passport names, so a passport the signer is not bound to cannot carry another agent's capabilities into the policy, even on an arrival that a grant or a signature verified.
138
+
139
+ A policy reads the registry's word as a fact. Test that the field is there and that the passport was verified, since an arrival without a passport has none:
140
+
141
+ ```cedar
142
+ permit(principal, action == Action::"refund", resource)
143
+ when {
144
+ context.facts.arrival.class == "verified" &&
145
+ context.facts.arrival has passport &&
146
+ context.facts.arrival.passport.outcome == "verified" &&
147
+ context.facts.arrival.passport.capabilities.contains("refunds") &&
148
+ context.args.body.amount <= 5000
149
+ };
150
+ ```
151
+
152
+ | what arrived | `passport.outcome` | `class` |
153
+ | --- | --- | --- |
154
+ | a passport from a trusted registry, in its window, under a signature by its did:key that covers all of the above | `verified` | `verified` |
155
+ | the same, with a signature that leaves out a component above, or a `Content-Digest` that is not of the body | `unbound` | `claimed` |
156
+ | the same passport under another key's signature, or with no signature | `wrong-sender` | `claimed` |
157
+ | a passport from another registry, edited, expired, or a header that is not a passport | `invalid` | `claimed` |
158
+ | a passport at a door with no `trustedRegistryKeys` | `unchecked` | `claimed` |
159
+ | a grant and a passport | recorded | decided by the grant alone |
160
+
161
+ A replayed request is refused as any Web Bot Auth signature is: the nonce is kept for the passport's did:key, whatever grant the request also carries, so the second use is `invalid`, and the arrival is `claimed`. The nonce is kept too for a passport that is not yet valid at the door, because the registry's clock is ahead, so the request cannot be sent again once its window opens. The signature covers `@query`, so the request cannot be sent again with another query either.
162
+
163
+ ## What the receipt shows
164
+
165
+ The receipt names the agent as `observed`, never `attested`: `agent: { id: "did:key:z6Mk…", provenance: "observed" }`, and the principal is `claimed`, as for any arrival admitted by its signature alone. A reader can check the recorded passport again under the registry's key (`verifyPassport(envelope, [registryKey], timestamp)`), but cannot repeat the check of the request's signature, which the receipt does not carry.
166
+
167
+ ## What it does not do
168
+
169
+ - **Revocation reaches the door when the passport expires.** Revoking an agent stops new passports. The passport the agent already holds works until its `expiresAt`, because the door asks the registry nothing. `--passport-seconds` is that delay; shorten it if a day is too long.
170
+ - **A key rotation is the same.** A passport for the old key works until it expires.
171
+ - **Capabilities are the owner's claim.** The registry records what the organisation says the agent does, and signs that it said so. It does not check it.
172
+ - **A passport says who, not on whose behalf.** It does not name a principal or a route. For that, the agent presents a [grant](door.md#presenting-a-passport) from a principal the site trusts, and the door decides by the grant.
173
+ - **Who a site admits is the site's own list.** The registry answers a search by capability (`GET /registry/agents?capability=`), and a site lists the agents it admits or blocks in its door's [admission lists](admission-lists.md).
@@ -8,7 +8,7 @@ The door runs from the gateway's container image. The same image runs every othe
8
8
 
9
9
  ```bash
10
10
  mkdir door-quickstart && cd door-quickstart
11
- IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.12
11
+ IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.13
12
12
  alias agent-custody='docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/work -w /work -e TURNSTILE_SECRET $IMAGE'
13
13
  ```
14
14
 
@@ -217,7 +217,7 @@ docker rm -f door site && docker network rm door-quickstart
217
217
 
218
218
  With Node 22 or later, the same page runs the CLI from npm. Four steps change, and every other command stays as it is:
219
219
 
220
- - **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.12 agent-custody'`, and there is no `IMAGE`.
220
+ - **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.13 agent-custody'`, and there is no `IMAGE`.
221
221
  - **Step 2.** Start the stand-in site with `node -e 'require("http").createServer((q,s)=>{s.setHeader("content-type","text/plain");s.end(q.method==="GET"?"the sign-up page\n":"thanks, you are signed up\n")}).listen(3000,"127.0.0.1")' &`.
222
222
  - **Step 4.** In `door.json`, the origin is `"http://127.0.0.1:3000"`. The check then gives one warning, not two.
223
223
  - **Step 5.** Start the door with `agent-custody door --config door.json --port 8780 &`.
@@ -14,7 +14,7 @@ It is the same code as the reverse proxy, the in-process door, and authz mode, w
14
14
  | receipts | the receipts directory | the `RECEIPTS` R2 bucket, same names: `<id>.json`, `<id>.authorization.json`, `salts/<id>.json`, `outbox/<id>.json` |
15
15
  | log | `logFile` or `log.url` | `LOG_URL`, its keys pinned in `LOG_KEYS`, token in the `LOG_TOKEN` secret |
16
16
  | receipts whose log append failed | the outbox, flushed every 30 seconds | the bucket's outbox, flushed by a cron trigger every minute |
17
- | trusted principal keys, revoked grants | files, re-read | the `TRUSTED_PRINCIPAL_KEYS` and `REVOKED_GRANTS` variables; a change is a deploy |
17
+ | trusted principal keys, trusted registry keys, revoked grants, admission lists | files, re-read | the `TRUSTED_PRINCIPAL_KEYS`, `TRUSTED_REGISTRY_KEYS`, `REVOKED_GRANTS`, and `ADMISSION_LISTS` variables; a change is a deploy |
18
18
  | the arrival's address | the socket, or `X-Forwarded-For` with `trustProxy` | `CF-Connecting-IP`, which Cloudflare sets |
19
19
  | Web Bot Auth nonces | one process's memory | a Durable Object per nonce, which every isolate reaches (the `NONCES` binding) |
20
20
  | arrival rates | one process's memory | one isolate's memory |
package/docs/door.md CHANGED
@@ -39,7 +39,7 @@ To run it as a service, the gateway image has a `door` mode (`docker run ... ghc
39
39
 
40
40
  Every field of the config, with its type and default, is in [the door reference](../../../site/reference/door.md#config).
41
41
 
42
- `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the `behaviour` signals (with a warning that the proxy must overwrite `behaviour.tlsHeader`), the revocation file, the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
42
+ `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the `behaviour` signals (with a warning that the proxy must overwrite `behaviour.tlsHeader`), the revocation file, the trusted registry keys (an error for one that does not load, or for `trustedRegistryKeys` without `webBotAuth`), the admission lists file (an error for one that cannot be read or is not valid), the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
43
43
 
44
44
  ## What the door knows about an arrival
45
45
 
@@ -47,12 +47,14 @@ The door records one fact for every arrival, `arrival`, observed by the door its
47
47
 
48
48
  | field | values | meaning |
49
49
  | --- | --- | --- |
50
- | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
50
+ | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes, or a [registry passport](#a-registry-passport) under a signature by the did:key it names. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
51
51
  | `subject` | string | the agent named in a verified grant; else the signature agent of a verified signature (its https origin); else the declared name or the agent a rejected grant named; else `unknown`. Only a verified subject reaches the Cedar `principal` |
52
52
  | `grant` | `verified`, `out-of-scope`, `invalid`, `revoked`, `wrong-sender`, `absent` | what became of the grant header, with `grantError` when it was not accepted. `revoked`: the grant verified, and it or a grant above it in its chain is in `revokedGrants` (see [revoking a grant](#revoking-a-grant)). `wrong-sender`: the grant verified, and the request is signed by a signature agent, or by a did:key, that the grant does not name |
53
53
  | `signature` | `verified`, `invalid`, `unavailable`, `unchecked`, `absent` | what became of an RFC 9421 signature tagged `web-bot-auth`, with `signatureError` when it was not verified. `unchecked`: a `Signature-Input` arrived and the config has no `webBotAuth`, so it is a claim. See [Web Bot Auth signatures](#web-bot-auth-signatures) |
54
54
  | `signatureAgent`, `signatureKeyid` | strings | the `Signature-Agent` origin and the keyid the signature named. For a signature by a did:key's key, both are the did:key. Checked only when `signature` is `verified` |
55
55
  | `declared` | string | the `x-agent-custody-agent` header, when sent. A claim |
56
+ | `passport` | `{ outcome, error?, registry?, registryKeyid?, agentId?, agent?, name?, owner?, capabilities?, erc8004?, expiresAt?, digest?, envelope? }` | only when the arrival sent `x-agent-custody-passport`. `verified`: a key in `trustedRegistryKeys` signed it, it is in its window, and the request is signed by the did:key it names, with a signature that covers `@method`, `@path`, `@query`, the passport header, and on a write a `Content-Digest` that matches the body. `unbound`: it verified and the request is signed by its key, without that coverage. `wrong-sender`: it verified, and the request is not signed by that key. `invalid`: it did not verify. `unchecked`: the door trusts no registry key. Only a `verified` passport puts the registry's entry (`agentId`, `name`, `owner`, `capabilities`, `erc8004` when the registry linked an ERC-8004 identity, `expiresAt`, `digest`) and the passport itself (`envelope`) in the fact; another outcome records at most `registry` and `agent`. See [a registry passport](#a-registry-passport) |
57
+ | `admission` | `{ lists, digest }` | only when the config has `admissionLists`. The names of the site's [admission lists](admission-lists.md) the arrival's agent is on, sorted (empty when none), and the sha256 of the lists file in force. Only a `verified` arrival is on a list: by its subject, or by the registry entry or ERC-8004 identity of its `verified` passport |
56
58
  | `remote` | string | the arrival's address |
57
59
  | `challenge` | `{ provider, outcome, error? }` | only when `challenge` is configured. `passed`: the provider confirmed the token the arrival sent. `failed`: the provider refused the token (`invalid-input-response`, `timeout-or-duplicate`, `expired-input-response`, `already-seen-response`, `missing-input-response`, with the codes in `error`), it confirmed a token issued on another hostname or for another action, or the token was longer than 4096 characters, which is refused without calling the provider. `unavailable`: the provider did not answer in time, answered a non-200, a redirect, or something that is not JSON, answered a code that is its own or the operator's fault (`internal-error`, `bad-request`, `missing-input-secret`, `invalid-input-secret`, `sitekey-secret-mismatch`, `invalid-sitekey`, `missing-sitekey`, `invalid-remoteip`: a rotated secret gives every person one of these), or `maxInFlight` checks were already waiting. `absent`: no token. A passed challenge leaves `class` as it was: it says a provider's test was passed in front of this arrival, not who the arrival is |
58
60
  | `partner` | `{ engine, outcome, error? }` | only when `partner` is configured and the route is in `partner.routes`. `verified`: the engine's verdict was signed for this arrival under `partner.keyFile`, and is the `partner` fact. `rejected`: the engine answered with anything else. `unavailable`: it did not answer in time or at all. See [a partner engine's verdict](#a-partner-engines-verdict) |
@@ -73,6 +75,8 @@ There is no `human` class. The door cannot tell a person from a program that pre
73
75
 
74
76
  **A did:key grant under a signature by its own key is bound to its sender.** <a id="a-did-key-signature"></a>With `webBotAuth` configured, the agent signs the request as for [Web Bot Auth](#web-bot-auth-signatures) (RFC 9421, Ed25519, `tag="web-bot-auth"`, `@authority` covered, `created`, `expires`, and a nonce), and sets `keyid` to its did:key. It sends no `Signature-Agent`, and the door fetches no directory, because the did:key carries the key. The door applies the same checks of the window, the authority, the covered components, and the nonce, and verifies the signature with the key that the did:key names. When the grant verifies and names that did:key, the arrival is `verified` with `signature: "verified"`, and `signatureAgent` and `signatureKeyid` are the did:key. The policy condition for a bound grant, `context.facts.arrival.grant == "verified" && context.facts.arrival.signature == "verified"`, holds for it. A did:key grant under a signature by another did:key's key, or under a Web Bot Auth signature from an https origin, is `wrong-sender`, and the arrival is `claimed`. Anyone can make a key and its did:key, so a did:key signature counts only with a verified grant that names it. With no grant, with a grant that is not verified, or with a grant for another agent, the door records `signature: "invalid"` and the reason in `signatureError`, and the arrival is never `verified` by that signature. `agents` does not list a did:key: the grant of a trusted principal is what admits it. The door keeps the nonce of a did:key signature only when a trusted principal signed the request's grant for that did:key, so signatures by keys that no principal granted cannot fill the nonce store. A door without `webBotAuth` records the signature as `unchecked`, and the grant stays bearer-grade.
75
77
 
78
+ **A registry passport.** <a id="a-registry-passport"></a>An agent registered in an [agent registry](agent-registry.md) holds a passport: a statement, signed by the registry, of the agent's did:key, its owner, a contact, and its capabilities, valid for a day by default. List the registry's key in `trustedRegistryKeys` (the key document is at the registry's `/.well-known/agent-custody-registry.json`) and configure `webBotAuth` (its `agents` may be empty). The agent sends the passport as base64url JSON in `X-Agent-Custody-Passport` and signs the request with its did:key, as [above](#a-did-key-signature), covering `@method`, `@path`, `@query`, the passport header, and on a write `content-digest` ([the agent registry](agent-registry.md#admit-registered-agents-at-a-door) has the full list). With no grant, that arrival is `verified`, its `subject` is the did:key, and `arrival.passport` carries the registry's entry, so a policy can read `context.facts.arrival.passport.capabilities` or `.owner` (test `context.facts.arrival has passport` and `context.facts.arrival.passport.outcome == "verified"` first). The door needs no setup per agent and asks the registry nothing at request time. A passport is public, so on its own it is worth nothing: under another key's signature it is `wrong-sender`, and with no signature it is a claim, and the arrival is `claimed`. A request that presents a grant is judged by its grant; its passport is only recorded. The receipt names the agent as `observed`, as for any signature: a reader can check the recorded passport again under the registry's key, but not the request's signature. Revoking an agent in the registry stops new passports; the one the agent holds works until it expires, so `passportSeconds` on the registry is how long a revocation can take to reach the door.
79
+
76
80
  **Revoking a grant.** <a id="revoking-a-grant"></a>With `revokedGrants` in the config, a grant can be withdrawn before it expires: the file is the gateway's, a JSON array of grant digests, and `agent-custody revoke --config door.json --grant grant.json` appends one. The door re-reads the file when it changes and checks every grant against it after the signature and before the window and the scope, so a running door classifies the next arrival that carries the grant as `claimed` with `grant: "revoked"`, and the Cedar principal is not the agent. Revoking a grant revokes every grant delegated from it (`grantError` says "a grant above it in its chain has been revoked"). A file that is there and cannot be read stops the door from starting; one that becomes unreadable while it runs makes every grant `revoked` until it can be read, so a broken list never lets a grant through. A missing file is an empty list. Without `revokedGrants`, a grant stands until it expires, and `check` warns when the door trusts principals.
77
81
 
78
82
  <a id="challenging-a-human"></a>**Challenging a human.** The door builds no CAPTCHA. With `challenge` configured, a page in front of a protected route renders the provider's widget (Cloudflare Turnstile or hCaptcha) with `siteKey`, and sends the token the widget produced in the `challenge.header` header of its request. The door posts the token and the secret from `secretEnv` to the provider's `siteverify` endpoint, with a timeout, and records the answer as `challenge.outcome`. It adds the arrival's address as `remoteip` only with `trustProxy`, where that address is the client's; without it the socket's address may be a proxy's, and the provider would refuse a token the client solved. It never follows a redirect, which would resend the secret and the token elsewhere. To hCaptcha it also sends `siteKey` as `sitekey`: an hCaptcha secret belongs to the account, and without it a token solved on the account's easiest widget would pass on the hardest. A Turnstile secret belongs to one widget already. `success` alone does not pass: the token must have been issued on one of `hostnames`, and for `action` when one is set, or a token solved on another site that uses this site key, or for another widget, would count. At most `maxInFlight` checks wait on the provider at once; an arrival past that is `unavailable`. The token is stripped before the request is relayed, and neither the token nor the secret is recorded. A policy admits a person on a form route with
@@ -20,7 +20,7 @@ jobs:
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
22
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
- - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.12
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.13
24
24
  with:
25
25
  path: .custody/receipts
26
26
  issuer-key: .custody/keys/agent.pub
@@ -37,7 +37,7 @@ Pin the action to the commit of a release, as you pin every other action. A movi
37
37
  | `principal-key` | the public key files of the principals whose grants a gateway receipt carries, one path on each line; SDK and Claude Code hook receipts need none | |
38
38
  | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
39
39
  | `log-id` | the id that every tree head must name (`verify --log-id`) | |
40
- | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.12` |
40
+ | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.13` |
41
41
  | `github-token` | a token that can write pull request comments; an empty value writes the job summary only | `github.token` |
42
42
  | `comment-author` | the login of the account that `github-token` posts as; the action edits only a comment from this account | `github-actions[bot]` |
43
43
 
package/docs/tutorials.md CHANGED
@@ -70,6 +70,9 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
70
70
  | 59 | Demo 1, the refund (API leg): the door and the gateway together | [59-refund-demo.ts](../examples/59-refund-demo.ts) | a shop with the door in front of its refund API and two payment lanes through the gateway; a shopping agent with a passport is paid £25 once, even on retry; £80, and a forged passport, are refused at the door and never reach the shop; an agent with no passport goes to a person, who approves the exact refund with `agent-custody approvals approve`, and is then paid once; an auditor with public keys and a read-only view of Stripe verifies all ten receipts and finds the £10 refund made in Stripe directly; `bun run demo:refund` |
71
71
  | 60 | the door's behaviour and fingerprint signals, read by a policy as reasons to ask for a challenge | [60-door-behaviour-signals.ts](../examples/60-door-behaviour-signals.ts) | a door with `behaviour` and a challenge in front of a contact form; a browser's page load and form post carry no flag and pass; a tool's direct post is `directWrite`, and a script that states a browser has four flags, and each is refused with the rule's id and how to pass the challenge; a person whose address changed, and whose form page is on another host of the site, is flagged too, and passes with a challenge token; the site never receives the form report header; every receipt verified, with its flags |
72
72
  | 61 | the false-positive rate of each door flag, measured on a labelled set | [61-door-measure.ts](../examples/61-door-measure.ts) | the labelled set recorded from real clients is replayed through the door's signal functions; each flag's false-positive rate and detection rate are printed per session and per arrival with the 95% interval; no real browser is flagged, and the interval is still wide because the set is small |
73
+ | 62 | the agent registry: an organisation registers its agent, receives a passport, and a door that holds only the registry's key admits it | [62-agent-registry.ts](../examples/62-agent-registry.ts) | the portal runs the registry and publishes its key document; a company registers its shopping agent by the agent's own did:key with the capability `refunds`, and gets a passport; a shop's door trusts the registry's key and nothing else; the agent's refund, with its passport and signed by its key, is `verified` and the policy reads the capability; the same passport under another key's signature is `wrong-sender` and refused; after the company revokes the agent the registry issues it no passport; every receipt verified |
74
+ | 63 | linking a registered agent to its ERC-8004 identity, checked on chain by the registry and carried in its passport | [63-agent-registry-erc8004.ts](../examples/63-agent-registry-erc8004.ts) | a stand-in Base node and file host; the registry links the agent to token 7 because its registration file lists the agent's did:key, and records the owner and the block; the passport carries the link; a link to token 8, whose file names another key, is refused |
75
+ | 64 | admission lists: a site finds agents in the registry by capability, lists a partner by its registry entry and blocks another by its key, and its policy reads the lists | [64-admission-lists.ts](../examples/64-admission-lists.ts) | two companies register shopping agents with `refunds`; the shop's search finds both; its door trusts the registry's key and reads `admission.json`; Carted's agent is on `partners` and its refund is allowed; Grabby's agent is verified and on `blocked`, and its refund is refused; each receipt records the lists and their digest, and verifies |
73
76
 
74
77
  ## How policies are defined, in one paragraph
75
78
 
package/docs/usage.md CHANGED
@@ -125,7 +125,7 @@ At startup the gateway fetches the agent's card from `<url>/.well-known/agent-ca
125
125
  "log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
126
126
  ```
127
127
 
128
- Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
128
+ Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. With `--registry-key-env NAME` (or `--registry-signer-url`) and `--portal-url`, the portal also runs the [agent registry](agent-registry.md): a tenant registers its agents by their did:keys, and the portal signs their passports. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
129
129
 
130
130
  `otel`, optional in both the gateway and SDK configs, sends every receipt to the collector you already run as one span over OTLP/HTTP, after the receipt is issued: `"otel": { "url": "http://localhost:4318", "headersEnv": { "x-api-key": "OTEL_KEY" }, "serviceName": "support-agents" }`. The span's trace id is the receipt id, its attributes carry the tool, agent, principal, execution status, policy decision, and log position, and its status is an error only when the upstream failed or errored, since a denial is the policy working. A door receipt records an inbound request, so its span kind is `SERVER`; every other issuer's span is `CLIENT`. Export is best effort: a collector that is down or refuses costs a line on stderr, never a receipt. Tutorial 18 shows it against a stand-in collector.
131
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/receipts",
3
- "version": "0.16.12",
3
+ "version": "0.16.13",
4
4
  "mcpName": "io.github.svayatta/agent-custody",
5
5
  "description": "Proof of what your AI agents did. Give your agents real power, without losing control of them: signed, verifiable receipts for tool calls, an MCP gateway with Cedar or Rego policy, and a Merkle transparency log.",
6
6
  "license": "Apache-2.0",