@agent-custody/receipts 0.16.13 → 0.16.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/admission.d.ts +13 -0
- package/dist/admission.js +48 -13
- package/dist/check.js +19 -2
- package/dist/config.d.ts +9 -1
- package/dist/config.js +5 -3
- package/dist/door-core.d.ts +15 -1
- package/dist/door-core.js +21 -6
- package/dist/door-worker.d.ts +10 -0
- package/dist/door-worker.js +30 -2
- package/dist/door.d.ts +1 -1
- package/dist/door.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/passport.d.ts +13 -0
- package/dist/passport.js +40 -0
- package/dist/portal.js +12 -5
- package/dist/registry.d.ts +26 -1
- package/dist/registry.js +45 -8
- package/docs/admission-lists.md +7 -5
- package/docs/agent-registry.md +21 -3
- package/docs/door-quickstart.md +2 -2
- package/docs/door-wordpress.md +128 -0
- package/docs/door.md +3 -3
- package/docs/github-action.md +2 -2
- package/docs/tutorials.md +1 -0
- package/package.json +2 -1
package/dist/portal.js
CHANGED
|
@@ -996,8 +996,8 @@ export function portalHandler(o) {
|
|
|
996
996
|
return json(400, { error: "limit is 1 to 100" });
|
|
997
997
|
try {
|
|
998
998
|
const page = await agents.search({ ...(q("capability") !== undefined ? { capability: q("capability") } : {}), ...(q("owner") !== undefined ? { owner: q("owner") } : {}), ...(q("after") !== undefined ? { after: q("after") } : {}), ...(limit !== undefined ? { limit: Number(limit) } : {}) });
|
|
999
|
-
// a search finds agents; it is not a directory of contacts, which each agent's own entry
|
|
1000
|
-
return json(200, { registry: portalBase, agents: page.agents.map((e) => { const { contact: _contact, ...listed } = publicEntry(e); return listed; }), next: page.next });
|
|
999
|
+
// a search finds agents; it is not a directory of contacts, nor of each agent's history, which each agent's own entry carries
|
|
1000
|
+
return json(200, { registry: portalBase, agents: page.agents.map((e) => { const { contact: _contact, history: _history, ...listed } = publicEntry(e); return listed; }), next: page.next });
|
|
1001
1001
|
}
|
|
1002
1002
|
catch (e) {
|
|
1003
1003
|
if (e instanceof RegistryInputError)
|
|
@@ -1014,7 +1014,14 @@ export function portalHandler(o) {
|
|
|
1014
1014
|
const status = agentStatus(entry);
|
|
1015
1015
|
if (status !== "active")
|
|
1016
1016
|
return json(410, { error: `the agent is ${status}; the registry issues it no passport`, status });
|
|
1017
|
-
|
|
1017
|
+
try {
|
|
1018
|
+
return json(200, await passportFor(entry));
|
|
1019
|
+
}
|
|
1020
|
+
catch (e) {
|
|
1021
|
+
if (e instanceof RegistryInputError)
|
|
1022
|
+
return json(400, { error: e.message });
|
|
1023
|
+
throw e;
|
|
1024
|
+
}
|
|
1018
1025
|
}
|
|
1019
1026
|
if (req.method === "GET" && url.pathname === "/") {
|
|
1020
1027
|
res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", "x-frame-options": "DENY", "content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'" });
|
|
@@ -1669,7 +1676,7 @@ document.getElementById("f").onsubmit = async (e) => {
|
|
|
1669
1676
|
return json(200, { agents: (await agents.list(tenantId)).map((e) => publicEntry(e)) });
|
|
1670
1677
|
if (req.method === "POST" && !id) {
|
|
1671
1678
|
const entry = await agents.register(tenantId, await jsonBody(), Date.now(), checker);
|
|
1672
|
-
await o.tenancy.record(actor, "agent.register", tenantId, { agent: entry.id, key: entry.agent, capabilities: entry.capabilities, expiresAt: entry.expiresAt, ...(entry.erc8004 ? { erc8004: `${entry.erc8004.agentRegistry}:${entry.erc8004.agentId}` } : {}) });
|
|
1679
|
+
await o.tenancy.record(actor, "agent.register", tenantId, { agent: entry.id, key: entry.agent, capabilities: entry.capabilities, expiresAt: entry.expiresAt, ...(entry.version ? { version: entry.version } : {}), ...(entry.erc8004 ? { erc8004: `${entry.erc8004.agentRegistry}:${entry.erc8004.agentId}` } : {}) });
|
|
1673
1680
|
return json(200, { agent: publicEntry(entry), passport: await passportFor(entry) });
|
|
1674
1681
|
}
|
|
1675
1682
|
if (req.method === "POST" && id && revokeAgent) {
|
|
@@ -1684,7 +1691,7 @@ document.getElementById("f").onsubmit = async (e) => {
|
|
|
1684
1691
|
const entry = await agents.update(tenantId, id, b, Date.now(), checker);
|
|
1685
1692
|
if (!entry)
|
|
1686
1693
|
return json(404, { error: "no active agent with this id belongs to this tenant" });
|
|
1687
|
-
await o.tenancy.record(actor, "agent.update", tenantId, { agent: entry.id, changed: Object.keys(b).sort(), key: entry.agent, capabilities: entry.capabilities, expiresAt: entry.expiresAt, erc8004: entry.erc8004 ? `${entry.erc8004.agentRegistry}:${entry.erc8004.agentId}` : null });
|
|
1694
|
+
await o.tenancy.record(actor, "agent.update", tenantId, { agent: entry.id, changed: Object.keys(b).sort(), key: entry.agent, capabilities: entry.capabilities, ...(entry.version ? { version: entry.version } : {}), expiresAt: entry.expiresAt, erc8004: entry.erc8004 ? `${entry.erc8004.agentRegistry}:${entry.erc8004.agentId}` : null });
|
|
1688
1695
|
return json(200, { agent: publicEntry(entry), ...(agentStatus(entry) === "active" ? { passport: await passportFor(entry) } : {}) });
|
|
1689
1696
|
}
|
|
1690
1697
|
}
|
package/dist/registry.d.ts
CHANGED
|
@@ -29,12 +29,29 @@ export interface AgentEntry {
|
|
|
29
29
|
createdAt: string;
|
|
30
30
|
expiresAt: string;
|
|
31
31
|
revokedAt: string | null;
|
|
32
|
+
/** the version its owner registered, MAJOR.MINOR.PATCH; null or absent when none */
|
|
33
|
+
version?: string | null;
|
|
34
|
+
/** since when this version and key have been in force; the registration's time when absent */
|
|
35
|
+
versionSince?: string;
|
|
36
|
+
/** the tool endpoints its owner says it calls: a claim */
|
|
37
|
+
endpoints?: string[];
|
|
38
|
+
/** the versions and keys it had before, newest first, each with when it was in force */
|
|
39
|
+
history?: AgentVersionRecord[];
|
|
32
40
|
/** the linked ERC-8004 identity as last checked, with the error of the last check when it failed */
|
|
33
41
|
erc8004?: (Erc8004Checked & {
|
|
34
42
|
error?: string;
|
|
35
43
|
errorAt?: string;
|
|
36
44
|
}) | null;
|
|
37
45
|
}
|
|
46
|
+
/** A version and key an agent had, and when they were in force. */
|
|
47
|
+
export interface AgentVersionRecord {
|
|
48
|
+
version: string | null;
|
|
49
|
+
agent: string;
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
}
|
|
53
|
+
/** how many past versions an entry keeps; the oldest go first */
|
|
54
|
+
export declare const MAX_AGENT_HISTORY = 100;
|
|
38
55
|
/** The ERC-8004 link a passport may carry: one whose last check succeeded within `recheckSeconds`. */
|
|
39
56
|
export declare function freshErc8004(e: AgentEntry, recheckSeconds: number, now?: number): Erc8004Checked | null;
|
|
40
57
|
export type AgentStatus = "active" | "revoked" | "expired";
|
|
@@ -57,6 +74,12 @@ export declare function publicEntry(e: AgentEntry, now?: number): {
|
|
|
57
74
|
createdAt: string;
|
|
58
75
|
expiresAt: string;
|
|
59
76
|
status: AgentStatus;
|
|
77
|
+
version: string | null;
|
|
78
|
+
versionSince: string;
|
|
79
|
+
/** the version this one replaced, when it replaced one */
|
|
80
|
+
replaces: string | null;
|
|
81
|
+
endpoints: string[];
|
|
82
|
+
history: AgentVersionRecord[];
|
|
60
83
|
erc8004: (Erc8004Checked & {
|
|
61
84
|
error?: string;
|
|
62
85
|
errorAt?: string;
|
|
@@ -70,6 +93,8 @@ export declare const AgentInputSchema: z.ZodObject<{
|
|
|
70
93
|
agent: z.ZodString;
|
|
71
94
|
proof: z.ZodOptional<z.ZodString>;
|
|
72
95
|
expiresAt: z.ZodISODateTime;
|
|
96
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
97
|
+
endpoints: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
73
98
|
erc8004: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
74
99
|
agentRegistry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
75
100
|
agentId: z.ZodString;
|
|
@@ -93,7 +118,7 @@ export declare class RegistryStore {
|
|
|
93
118
|
register(owner: string, raw: unknown, now?: number, erc8004?: Erc8004Checker): Promise<AgentEntry>;
|
|
94
119
|
get(id: string): Promise<AgentEntry | null>;
|
|
95
120
|
list(owner: string): Promise<AgentEntry[]>;
|
|
96
|
-
/** Changes an active agent of this owner: any of name, contact, capabilities, key, expiry. Null when the owner has no such active agent. */
|
|
121
|
+
/** Changes an active agent of this owner: any of name, contact, capabilities, key, expiry, version, endpoints, ERC-8004 link. Null when the owner has no such active agent. */
|
|
97
122
|
update(owner: string, id: string, raw: unknown, now?: number, erc8004?: Erc8004Checker): Promise<AgentEntry | null>;
|
|
98
123
|
/**
|
|
99
124
|
* Active agents, by id, that hold `capability` (and belong to `owner`) when given: at most `limit` of them, after the
|
package/dist/registry.js
CHANGED
|
@@ -11,7 +11,7 @@ import { randomBytes, sign as edSign, verify as edVerify } from "node:crypto";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { DID_KEY_PREFIX, didKeyOf, publicKeyFromDidKey } from "./did-key.js";
|
|
13
13
|
import { transaction } from "./log-store.js";
|
|
14
|
-
import { AGENT_ID, CAPABILITY, DEFAULT_PASSPORT_SECONDS, DID_KEY, PASSPORT_HEADER, PASSPORT_TYPE, PassportSchema, text } from "./passport.js";
|
|
14
|
+
import { AGENT_ID, AGENT_VERSION, CAPABILITY, DEFAULT_PASSPORT_SECONDS, DID_KEY, EndpointSchema, MAX_ENDPOINT_CHARS, MAX_PASSPORT_HEADER, PASSPORT_HEADER, PASSPORT_TYPE, passportHeader, PassportSchema, text } from "./passport.js";
|
|
15
15
|
import { Erc8004LinkSchema } from "./erc8004-link.js";
|
|
16
16
|
export * from "./passport.js";
|
|
17
17
|
const didKeyOfKey = (k) => didKeyOf(k.publicKey);
|
|
@@ -30,6 +30,8 @@ export function registrationProof(agentKey, registryUrl, owner) {
|
|
|
30
30
|
const agent = didKeyOfKey(agentKey);
|
|
31
31
|
return { agent, proof: edSign(null, registrationMessage(registryUrl, owner, agent), agentKey.privateKey).toString("base64url") };
|
|
32
32
|
}
|
|
33
|
+
/** how many past versions an entry keeps; the oldest go first */
|
|
34
|
+
export const MAX_AGENT_HISTORY = 100;
|
|
33
35
|
/** The ERC-8004 link a passport may carry: one whose last check succeeded within `recheckSeconds`. */
|
|
34
36
|
export function freshErc8004(e, recheckSeconds, now = Date.now()) {
|
|
35
37
|
const l = e.erc8004;
|
|
@@ -50,6 +52,12 @@ export function publicEntry(e, now = Date.now()) {
|
|
|
50
52
|
createdAt: e.createdAt,
|
|
51
53
|
expiresAt: e.expiresAt,
|
|
52
54
|
status: agentStatus(e, now),
|
|
55
|
+
version: e.version ?? null,
|
|
56
|
+
versionSince: e.versionSince ?? e.createdAt,
|
|
57
|
+
/** the version this one replaced, when it replaced one */
|
|
58
|
+
replaces: e.history?.[0]?.version ?? null,
|
|
59
|
+
endpoints: e.endpoints ?? [],
|
|
60
|
+
history: e.history ?? [],
|
|
53
61
|
erc8004: e.erc8004 ?? null,
|
|
54
62
|
};
|
|
55
63
|
}
|
|
@@ -62,6 +70,10 @@ export const AgentInputSchema = z.object({
|
|
|
62
70
|
/** the agent key's signature over `registrationMessage`, base64url: needed to register a key, and to change to a new one */
|
|
63
71
|
proof: z.string().regex(/^[A-Za-z0-9_-]{86}$/, { message: "proof is the agent key's Ed25519 signature over the registration message, base64url" }).optional(),
|
|
64
72
|
expiresAt: z.iso.datetime({ offset: true }),
|
|
73
|
+
/** the agent's version, MAJOR.MINOR.PATCH, or null for none; a change is recorded in the entry's history */
|
|
74
|
+
version: z.string().regex(AGENT_VERSION, { message: "version is MAJOR.MINOR.PATCH, numbers only" }).nullable().optional(),
|
|
75
|
+
/** the tool endpoints the agent says it calls: host names or https/wss URLs, shown to sites as a claim */
|
|
76
|
+
endpoints: z.array(EndpointSchema).max(32).refine((l) => l.reduce((n, e) => n + e.length, 0) <= MAX_ENDPOINT_CHARS, { message: `the endpoints take at most ${MAX_ENDPOINT_CHARS} characters together, so that a door can read the passport` }).optional(),
|
|
65
77
|
/** link an ERC-8004 identity (checked against the chain before it is stored), or null to unlink */
|
|
66
78
|
erc8004: Erc8004LinkSchema.nullable().optional(),
|
|
67
79
|
});
|
|
@@ -131,12 +143,19 @@ export class RegistryStore {
|
|
|
131
143
|
await this.client.query(`CREATE UNIQUE INDEX IF NOT EXISTS ${this.t}_live_key ON ${this.t} (agent) WHERE revoked_at IS NULL`);
|
|
132
144
|
await this.client.query(`ALTER TABLE ${this.t} ADD COLUMN IF NOT EXISTS erc8004 TEXT`);
|
|
133
145
|
await this.client.query(`CREATE INDEX IF NOT EXISTS ${this.t}_capabilities ON ${this.t} USING GIN (capabilities)`);
|
|
146
|
+
await this.client.query(`ALTER TABLE ${this.t} ADD COLUMN IF NOT EXISTS agent_version TEXT`);
|
|
147
|
+
await this.client.query(`ALTER TABLE ${this.t} ADD COLUMN IF NOT EXISTS version_since TIMESTAMPTZ`);
|
|
148
|
+
await this.client.query(`ALTER TABLE ${this.t} ADD COLUMN IF NOT EXISTS endpoints TEXT[] NOT NULL DEFAULT '{}'`);
|
|
149
|
+
await this.client.query(`ALTER TABLE ${this.t} ADD COLUMN IF NOT EXISTS history TEXT`);
|
|
150
|
+
// a row from before these columns starts its first stretch at its registration, to the millisecond, as the entry
|
|
151
|
+
// reads it: the guard in update compares the stored value with the one it read, and NULL would never match
|
|
152
|
+
await this.client.query(`UPDATE ${this.t} SET version_since = date_trunc('milliseconds', created_at) WHERE version_since IS NULL`);
|
|
134
153
|
})();
|
|
135
154
|
return this.ready;
|
|
136
155
|
}
|
|
137
156
|
static row(r) {
|
|
138
157
|
const iso = (v) => (v instanceof Date ? v.toISOString() : new Date(String(v)).toISOString());
|
|
139
|
-
return { id: String(r.id), owner: String(r.owner), name: String(r.name), contact: String(r.contact), capabilities: r.capabilities ?? [], agent: String(r.agent), createdAt: iso(r.created_at), expiresAt: iso(r.expires_at), revokedAt: r.revoked_at ? iso(r.revoked_at) : null, erc8004: r.erc8004 ? JSON.parse(String(r.erc8004)) : null };
|
|
158
|
+
return { id: String(r.id), owner: String(r.owner), name: String(r.name), contact: String(r.contact), capabilities: r.capabilities ?? [], agent: String(r.agent), createdAt: iso(r.created_at), expiresAt: iso(r.expires_at), revokedAt: r.revoked_at ? iso(r.revoked_at) : null, version: r.agent_version ? String(r.agent_version) : null, versionSince: iso(r.version_since ?? r.created_at), endpoints: r.endpoints ?? [], history: r.history ? JSON.parse(String(r.history)) : [], erc8004: r.erc8004 ? JSON.parse(String(r.erc8004)) : null };
|
|
140
159
|
}
|
|
141
160
|
async register(owner, raw, now = Date.now(), erc8004) {
|
|
142
161
|
await this.init();
|
|
@@ -152,7 +171,7 @@ export class RegistryStore {
|
|
|
152
171
|
const { rows: count } = await q(`SELECT count(*)::int AS n FROM ${this.t} WHERE owner = $1 AND revoked_at IS NULL`, [owner]);
|
|
153
172
|
if (Number(count[0].n) >= MAX_AGENTS_PER_OWNER)
|
|
154
173
|
throw new RegistryInputError(`an owner registers at most ${MAX_AGENTS_PER_OWNER} agents; revoke one first`);
|
|
155
|
-
const { rows } = await q(`INSERT INTO ${this.t} (id, owner, name, contact, capabilities, agent, created_at, expires_at, erc8004) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *`, [id, owner, v.name, v.contact, capabilities, v.agent, new Date(now).toISOString(), v.expiresAt, link ? JSON.stringify(link) : null]);
|
|
174
|
+
const { rows } = await q(`INSERT INTO ${this.t} (id, owner, name, contact, capabilities, agent, created_at, expires_at, erc8004, agent_version, version_since, endpoints, history) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $7, $11, '[]') RETURNING *`, [id, owner, v.name, v.contact, capabilities, v.agent, new Date(now).toISOString(), v.expiresAt, link ? JSON.stringify(link) : null, v.version ?? null, v.endpoints ?? []]);
|
|
156
175
|
return RegistryStore.row(rows[0]);
|
|
157
176
|
});
|
|
158
177
|
}
|
|
@@ -174,12 +193,12 @@ export class RegistryStore {
|
|
|
174
193
|
const { rows } = await this.client.query(`SELECT * FROM ${this.t} WHERE owner = $1 ORDER BY created_at, id`, [owner]);
|
|
175
194
|
return rows.map((r) => RegistryStore.row(r));
|
|
176
195
|
}
|
|
177
|
-
/** Changes an active agent of this owner: any of name, contact, capabilities, key, expiry. Null when the owner has no such active agent. */
|
|
196
|
+
/** Changes an active agent of this owner: any of name, contact, capabilities, key, expiry, version, endpoints, ERC-8004 link. Null when the owner has no such active agent. */
|
|
178
197
|
async update(owner, id, raw, now = Date.now(), erc8004) {
|
|
179
198
|
await this.init();
|
|
180
199
|
const v = checkInput(raw, true, now);
|
|
181
200
|
if (Object.keys(v).filter((k) => k !== "proof").length === 0)
|
|
182
|
-
throw new RegistryInputError("nothing to change: give name, contact, capabilities, agent, expiresAt, or erc8004");
|
|
201
|
+
throw new RegistryInputError("nothing to change: give name, contact, capabilities, agent, expiresAt, version, endpoints, or erc8004");
|
|
183
202
|
const current = await this.get(id);
|
|
184
203
|
if (!current || current.owner !== owner || agentStatus(current, now) === "revoked")
|
|
185
204
|
return null;
|
|
@@ -187,12 +206,24 @@ export class RegistryStore {
|
|
|
187
206
|
checkProof(this.registryUrl, owner, v.agent, v.proof);
|
|
188
207
|
const { proof: _proof, erc8004: wanted, ...fields } = v;
|
|
189
208
|
const next = { ...current, ...fields };
|
|
209
|
+
// a new version or a new key starts a new stretch of the entry's history; the one it replaces is kept, with its dates
|
|
210
|
+
const moved = (v.version !== undefined && v.version !== current.version) || next.agent !== current.agent;
|
|
211
|
+
const past = current.history ?? [];
|
|
212
|
+
const history = moved ? [{ version: current.version ?? null, agent: current.agent, from: current.versionSince ?? current.createdAt, to: new Date(now).toISOString() }, ...past].slice(0, MAX_AGENT_HISTORY) : past;
|
|
213
|
+
const since = moved ? new Date(now).toISOString() : (current.versionSince ?? current.createdAt);
|
|
190
214
|
// a link stays only while the registration file lists the agent's key: a new key checks the standing link again
|
|
191
215
|
const target = wanted === undefined ? (current.erc8004 && next.agent !== current.agent ? current.erc8004 : undefined) : wanted;
|
|
192
216
|
const link = target === undefined ? current.erc8004 : target === null ? null : await checkedLink(erc8004, target, next.agent);
|
|
193
217
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
218
|
+
// the version and key read above must still be the row's, so two changes at once cannot both write one stretch of history
|
|
219
|
+
const { rows } = await this.client.query(`UPDATE ${this.t} SET name = $3, contact = $4, capabilities = $5, agent = $6, expires_at = $7, erc8004 = $8, agent_version = $9, version_since = $10, endpoints = $11, history = $12 WHERE id = $1 AND owner = $2 AND revoked_at IS NULL AND agent = $13 AND agent_version IS NOT DISTINCT FROM $14 AND version_since IS NOT DISTINCT FROM $15 RETURNING *`, [id, owner, next.name, next.contact, next.capabilities, next.agent, next.expiresAt, link ? JSON.stringify(link) : null, next.version ?? null, since, next.endpoints ?? [], JSON.stringify(history), current.agent, current.version ?? null, current.versionSince ?? null]);
|
|
220
|
+
if (rows[0])
|
|
221
|
+
return RegistryStore.row(rows[0]);
|
|
222
|
+
// the row was there when read: if it still is, another change moved its version or key in between, and this one, which read the old ones, is not written
|
|
223
|
+
const after = await this.get(id);
|
|
224
|
+
if (after && after.owner === owner && agentStatus(after, now) !== "revoked")
|
|
225
|
+
throw new RegistryInputError("the agent's version or key changed while this change was made; read the entry again and retry");
|
|
226
|
+
return null;
|
|
196
227
|
}
|
|
197
228
|
catch (e) {
|
|
198
229
|
if (keyTaken(e))
|
|
@@ -273,11 +304,17 @@ export async function issuePassport(signer, registryUrl, e, passportSeconds = DE
|
|
|
273
304
|
owner: e.owner,
|
|
274
305
|
contact: e.contact,
|
|
275
306
|
capabilities: e.capabilities,
|
|
307
|
+
...(e.version ? { agentVersion: e.version } : {}),
|
|
308
|
+
...(e.endpoints?.length ? { endpoints: e.endpoints } : {}),
|
|
276
309
|
...(erc8004 ? { erc8004: { agentRegistry: erc8004.agentRegistry, agentId: erc8004.agentId, owner: erc8004.owner, block: erc8004.block } } : {}),
|
|
277
310
|
issuedAt: new Date(now).toISOString(),
|
|
278
311
|
expiresAt: new Date(expires).toISOString(),
|
|
279
312
|
});
|
|
280
|
-
|
|
313
|
+
const env = await signer.sign(PASSPORT_TYPE, passport);
|
|
314
|
+
const size = passportHeader(env).length;
|
|
315
|
+
if (size > MAX_PASSPORT_HEADER)
|
|
316
|
+
throw new RegistryInputError(`the passport would be ${size} characters, more than the ${MAX_PASSPORT_HEADER} a door reads; declare fewer or shorter endpoints or capabilities`);
|
|
317
|
+
return env;
|
|
281
318
|
}
|
|
282
319
|
/** The registry's key document, served at REGISTRY_DOCUMENT_PATH. */
|
|
283
320
|
export async function registryDocument(signer, registryUrl, passportSeconds, erc8004Chains = []) {
|
package/docs/admission-lists.md
CHANGED
|
@@ -13,7 +13,7 @@ curl 'https://app.agent-custody.dev/registry/agents?capability=refunds&limit=50'
|
|
|
13
13
|
# { "registry": "https://app.agent-custody.dev/", "agents": [ <entry>, … ], "next": "agt_…" | null }
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
It lists active agents only, never a revoked or expired one, ordered by id. `capability` filters by one capability and `owner` by one tenant. `limit` is 1 to 100 (50 by default); any other value is a `400`. To get the next page, send `after=<next>`. `registry` is the registry's URL as its passports name it: copy it into a list entry. Each entry is the one `GET /registry/agents/<id>` publishes, without `contact`: id, name, owner, capabilities, its key as a did:key and a JWK, and its ERC-8004 link when it has one. A search finds agents; it is not a directory of contacts. An agent's contact is on its own entry and in its passport, which reaches every site the agent visits.
|
|
16
|
+
It lists active agents only, never a revoked or expired one, ordered by id. `capability` filters by one capability and `owner` by one tenant. `limit` is 1 to 100 (50 by default); any other value is a `400`. To get the next page, send `after=<next>`. `registry` is the registry's URL as its passports name it: copy it into a list entry. Each entry is the one `GET /registry/agents/<id>` publishes, without `contact` or `history`: id, name, owner, capabilities, its key as a did:key and a JWK, and its ERC-8004 link when it has one. A search finds agents; it is not a directory of contacts. An agent's contact is on its own entry and in its passport, which reaches every site the agent visits.
|
|
17
17
|
|
|
18
18
|
The registry's public reads (the search, an agent's entry, and its passport) allow each address a burst of 120 and then one every 2 seconds; past that they answer `429` with `Retry-After`.
|
|
19
19
|
|
|
@@ -28,7 +28,7 @@ The lists are a JSON file beside the door config:
|
|
|
28
28
|
"lists": {
|
|
29
29
|
"partners": [
|
|
30
30
|
{ "registry": "https://app.agent-custody.dev/", "agentId": "agt_d0cdd11e729cf856" },
|
|
31
|
-
{ "erc8004": { "agentRegistry": "eip155:8453:0x…", "agentId": "7" } }
|
|
31
|
+
{ "erc8004": { "agentRegistry": "eip155:8453:0x…", "agentId": "7" }, "registry": "https://app.agent-custody.dev/" }
|
|
32
32
|
],
|
|
33
33
|
"crawlers": [{ "agent": "https://crawler.example" }],
|
|
34
34
|
"blocked": [{ "agent": "did:key:z6Mk…" }]
|
|
@@ -44,13 +44,15 @@ A list name is lowercase letters, digits, and `. _ -`, at most 64 characters. Th
|
|
|
44
44
|
|
|
45
45
|
| entry | matches a `verified` arrival | survives a key rotation |
|
|
46
46
|
| --- | --- | --- |
|
|
47
|
-
| `{ "registry", "agentId" }` | whose [passport](agent-registry.md#admit-registered-agents-at-a-door) is `verified`, from that registry, for that agent id | yes |
|
|
48
|
-
| `{ "erc8004": { "agentRegistry", "agentId" } }` | whose `verified` passport carries that [ERC-8004 link](agent-registry.md#link-an-erc-8004-identity), which the registry checked on chain | yes, while the token's file names the new key |
|
|
47
|
+
| `{ "registry", "agentId", "version"? \| "versions"? }` | whose [passport](agent-registry.md#admit-registered-agents-at-a-door) is `verified`, from that registry, for that agent id | yes |
|
|
48
|
+
| `{ "erc8004": { "agentRegistry", "agentId" }, "registry"? }` | whose `verified` passport carries that [ERC-8004 link](agent-registry.md#link-an-erc-8004-identity), which the registry checked on chain, and, with `registry`, names that registry | yes, while the token's file names the new key |
|
|
49
49
|
| `{ "agent" }` | whose `subject` is that value: a did:key, a Web Bot Auth signature agent's origin, or the agent a trusted grant names | no, for a did:key |
|
|
50
50
|
|
|
51
|
+
A registry entry may also name the agent's versions: `"version": "1.4.0"` for one, or `"versions": { "from": "1.2.0", "below": "2.0.0" }` for a range (`from` included, `below` not, either may be left out). Versions compare as numbers, so 1.10.0 is above 1.2.0. An entry with a version matches only a `verified` passport that carries a version in it; an agent whose owner registered no version is not on the list by that entry. When the agent arrives at a version the list does not name, the receipt shows `passport.agentVersion` and lists without that name, so the site sees the change before it admits it.
|
|
52
|
+
|
|
51
53
|
The registry's URL is part of a registry entry because an agent id is unique only within one registry. A URL or origin is compared in one spelling, so `https://APP.example.test:443` and `https://app.example.test/` name the same registry, and `https://Crawler.Example/` the agent `https://crawler.example`; a did:key is compared exactly.
|
|
52
54
|
|
|
53
|
-
**
|
|
55
|
+
**Bind each registry key to its registry.** A passport's `registry` is written by the registry that signs it. A door that trusts the keys of two registries, each as a bare path, lets either one issue a passport that names the other's URL and an agent id from it, and so put its own agent on a list entry meant for the other's agent. Give each key the one registry it speaks for, `{ "key": "keys/registry.pub", "registry": "https://app.agent-custody.dev/" }` ([the agent registry](agent-registry.md#admit-registered-agents-at-a-door)), and a passport that names any other registry is `invalid`. `agent-custody check` warns when more than one registry key is trusted and any is bound to no URL. The binding protects `{ registry, agentId }` entries, and `{ erc8004 }` entries that name a registry. An `{ erc8004 }` entry trusts the on-chain check of the registry that signed the passport, so without `registry` any registry whose key the door trusts can sign a passport that carries another registry's agent's ERC-8004 identity, and put its own agent on the list by that entry. Add `"registry"` beside `"erc8004"`, the URL of the registry that must vouch for the link, and only a passport that names it matches. An entry without `registry` matches whichever trusted registry vouches, which is safe only when the door trusts one. Prefer registry entries for registered agents, because they survive a key rotation. Use `agent` for an agent with no registry, or to block one key whatever registry vouches for it.
|
|
54
56
|
|
|
55
57
|
The door reads the file when it starts, and refuses to start if the file is not valid. It reads the file again whenever it changes. A changed file that cannot be read, or is not valid, leaves the lists in force and prints `ADMISSION LISTS NOT RELOADED`. Emptying the lists instead would also empty a block list. `agent-custody check --config door.json` checks the file. In a Worker, the lists are the `ADMISSION_LISTS` variable, and a change is a deploy.
|
|
56
58
|
|
package/docs/agent-registry.md
CHANGED
|
@@ -16,6 +16,8 @@ A passport is a DSSE envelope of type `application/vnd.agent-custody.passport+js
|
|
|
16
16
|
"owner": "carted",
|
|
17
17
|
"contact": "agents@carted.example",
|
|
18
18
|
"capabilities": ["refunds"],
|
|
19
|
+
"agentVersion": "1.4.0",
|
|
20
|
+
"endpoints": ["api.stripe.com", "https://mcp.carted.example/mcp"],
|
|
19
21
|
"issuedAt": "2026-11-23T09:00:00.000Z",
|
|
20
22
|
"expiresAt": "2026-11-24T09:00:00.000Z"
|
|
21
23
|
}
|
|
@@ -24,6 +26,8 @@ A passport is a DSSE envelope of type `application/vnd.agent-custody.passport+js
|
|
|
24
26
|
- `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
27
|
- `owner` is the portal tenant that registered the agent. `contact` is how a site reaches the agent's operator.
|
|
26
28
|
- `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.
|
|
29
|
+
- `agentVersion`, when the owner registered one: the agent's version, `MAJOR.MINOR.PATCH`, numbers only. `version` is the passport format's own.
|
|
30
|
+
- `endpoints`, when the owner declared any: the tool endpoints the agent says it calls, host names or https or wss URLs (an MCP server), at most 32. They are a claim: the registry does not check them, and only an [egress witness](egress.md) on the agent's own host can show what it really calls.
|
|
27
31
|
- 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
32
|
- `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
33
|
|
|
@@ -58,6 +62,17 @@ The answer has the registry entry and a first passport. Every key belongs to one
|
|
|
58
62
|
|
|
59
63
|
In code, `didKeyOf(publicKey)` gives a key's did:key.
|
|
60
64
|
|
|
65
|
+
### Versions and declared endpoints
|
|
66
|
+
|
|
67
|
+
A registration, and a change to one, may carry `version` (`MAJOR.MINOR.PATCH`, or `null` for none) and `endpoints` (the tool endpoints the agent says it calls: at most 32, and at most 1,024 characters together, so that a passport with the largest of every other field still fits the 8,192 characters a door reads; a URL is stored as its `href`, and white space and control characters are refused). The entry keeps the agent's history: each change of version, and each key rotation, closes the stretch the agent was in, and the entry records it, newest first, as `{ version, agent, from, to }`. `replaces` is the version the current one replaced. A change of name, contact, capabilities, or expiry leaves the history alone. The entry keeps the last 100 stretches. Two changes made at once to one agent do not both land: the one that reads a version or key that another has just replaced is refused with "read the entry again and retry".
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
curl -b session.txt -H 'content-type: application/json' https://app.example/api/agents/agt_5325ae63b111bdcb -d '{ "version": "1.5.0" }'
|
|
71
|
+
# { "agent": { …, "version": "1.5.0", "replaces": "1.4.0", "history": [ { "version": "1.4.0", "agent": "did:key:z6Mk…", "from": "…", "to": "…" } ] }, "passport": … }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A site that admits one version of an agent names it in its [admission list](admission-lists.md#write-the-lists) with `version` or `versions`. When the agent arrives at a later version, its receipt records `passport.agentVersion` and that no list named it.
|
|
75
|
+
|
|
61
76
|
## Link an ERC-8004 identity
|
|
62
77
|
|
|
63
78
|
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.
|
|
@@ -109,16 +124,18 @@ The agent fetches a fresh passport before the one it holds expires. It needs no
|
|
|
109
124
|
|
|
110
125
|
## Admit registered agents at a door
|
|
111
126
|
|
|
112
|
-
Put the registry's public key in a file, list it in `trustedRegistryKeys
|
|
127
|
+
Put the registry's public key in a file, list it in `trustedRegistryKeys` with the registry's URL (the `registry` of its key document), 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
128
|
|
|
114
129
|
```json
|
|
115
130
|
{
|
|
116
|
-
"trustedRegistryKeys": ["keys/registry.pub"],
|
|
131
|
+
"trustedRegistryKeys": [{ "key": "keys/registry.pub", "registry": "https://app.agent-custody.dev/" }],
|
|
117
132
|
"webBotAuth": { "authorities": ["shop.example"] }
|
|
118
133
|
}
|
|
119
134
|
```
|
|
120
135
|
|
|
121
|
-
|
|
136
|
+
A key bound to a registry admits only passports that name that registry, in any spelling of its URL; a passport it signed that names another registry is `invalid`. A registry writes its own URL into its passports, so without the binding a door that trusts two registries lets either one vouch for the other's agents. A bare path, `"keys/registry.pub"`, is still accepted and trusts the key for any registry; `agent-custody check` warns when more than one registry key is trusted and any is bare.
|
|
137
|
+
|
|
138
|
+
The door refuses to start with `trustedRegistryKeys` and no `webBotAuth`. In a Worker the keys are the `TRUSTED_REGISTRY_KEYS` variable: SPKI PEM keys, each trusted for any registry, or a JSON list of `{ "publicKeyPem", "registry" }`, the `keys` of the key document with the registry's URL added to each. In the list, `registry` is required, and a JSON object, such as the whole key document, is refused: its key would otherwise be read bare. One key listed twice, for two registries or bound and also bare, stops the door at start.
|
|
122
139
|
|
|
123
140
|
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
141
|
|
|
@@ -168,6 +185,7 @@ The receipt names the agent as `observed`, never `attested`: `agent: { id: "did:
|
|
|
168
185
|
|
|
169
186
|
- **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
187
|
- **A key rotation is the same.** A passport for the old key works until it expires.
|
|
188
|
+
- **Declared endpoints are the owner's claim, and so is the version.** The registry records them and signs that the owner said so. An [egress witness](egress.md) on the agent's own host is what shows the endpoints it really calls.
|
|
171
189
|
- **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
190
|
- **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
191
|
- **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).
|
package/docs/door-quickstart.md
CHANGED
|
@@ -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.
|
|
11
|
+
IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.14
|
|
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.
|
|
220
|
+
- **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.14 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 &`.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# The door as a WordPress plugin
|
|
2
|
+
|
|
3
|
+
> For a small business with a WordPress site. How the door works is in [the door](door.md). The plugin, its build script, and its smoke test are in [deploy/door/wordpress](../../../deploy/door/wordpress/README.md).
|
|
4
|
+
|
|
5
|
+
A WordPress site on ordinary hosting cannot run the Node door, and it has no proxy to put the door in. So the plugin is a door written in PHP. It decides each comment and each form submission inside WordPress, before WordPress acts on it. It signs a receipt for each decision with a key that stays on the site, and it appends the hash of each receipt to a log. The receipt is a door receipt: issuer kind `door`, framework `wordpress`. `agent-custody verify` checks it with the plugin's public key and the log, as it checks a receipt from any door.
|
|
6
|
+
|
|
7
|
+
The owner does three things: install the zip, connect the plugin to a log, and choose a policy preset.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
No release publishes the plugin, and a merge to `main` installs it on no site. You build the zip from the repository and upload it.
|
|
12
|
+
|
|
13
|
+
1. Build the zip: `deploy/door/wordpress/build.sh` writes `agent-custody-door.zip`.
|
|
14
|
+
2. In WordPress, go to **Plugins > Add New > Upload Plugin**. Upload the zip and activate the plugin.
|
|
15
|
+
3. Go to **Settings > Agent Custody Door**.
|
|
16
|
+
|
|
17
|
+
On activation the plugin makes its signing key and a table for its receipts. It protects nothing until it is connected to a log, and it shows a notice until then.
|
|
18
|
+
|
|
19
|
+
The plugin needs WordPress 6.0 or later and PHP 7.4 or later. It has no other dependency: WordPress supplies the Ed25519 functions where PHP does not.
|
|
20
|
+
|
|
21
|
+
## Connect to the log
|
|
22
|
+
|
|
23
|
+
| setting | value |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| Log URL | the URL of your tenant on the hosted log, `https://log.agent-custody.dev/t/YOUR-TENANT/`, or the URL of any agent-custody log |
|
|
26
|
+
| Log token | the token of the tenant. To keep it out of the database, put `define( 'AGENT_CUSTODY_DOOR_LOG_TOKEN', '...' );` in `wp-config.php` |
|
|
27
|
+
|
|
28
|
+
When you save, the plugin reads the log's key document (`/.well-known/agent-custody-log.json`) and pins the keys. The page then shows `Connected` and the first 12 characters of each pinned key id. Compare them with the key ids that the log's operator publishes. A log at a new URL is a new log: the plugin reads and pins its keys again.
|
|
29
|
+
|
|
30
|
+
The log gets the hash of each receipt, never the receipt. The receipts stay in the site's database.
|
|
31
|
+
|
|
32
|
+
## Choose a preset
|
|
33
|
+
|
|
34
|
+
A preset is a Cedar policy text that the plugin ships. PHP has no Cedar engine, so the plugin decides each text in PHP, and the test suite checks each PHP decision against Cedar. The receipt records the digest of the policy text.
|
|
35
|
+
|
|
36
|
+
| preset | who may send a protected form | refuses |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| **Watch** | all. The plugin records what Humans decides | nothing. Start here, and read the decisions |
|
|
39
|
+
| **Humans** | a visitor who passed the challenge, and a signed-in user on a comment or on one of the more protected paths | a submission without a passed challenge from a visitor who is not signed in; a login, a registration, or a lost password without a passed challenge from anyone |
|
|
40
|
+
| **Strict** | a visitor or a signed-in user who passed the challenge | each submission without a passed challenge |
|
|
41
|
+
|
|
42
|
+
Humans and Strict need a challenge. Make a widget at Cloudflare Turnstile or hCaptcha and enter its site key and its secret. To keep the secret out of the database, put `define( 'AGENT_CUSTODY_DOOR_CHALLENGE_SECRET', '...' );` in `wp-config.php`. Without a site key and a secret, no submission can pass a challenge and nobody can sign in, so the settings form does not take Humans or Strict without them: it keeps Watch and says why.
|
|
43
|
+
|
|
44
|
+
A signed-in user is exempt in Humans for comments and the more protected paths only. `wp-login.php` takes a login, a registration, or a lost password from a sender who is signed in already, so those forms always need the challenge. On a REST path (`/wp-json/...`), a sender is signed in only with the REST nonce, as for WordPress itself.
|
|
45
|
+
|
|
46
|
+
**Challenge hostnames** are the hostnames of the pages that show the widget. Empty means the hostname of the site, with and without `www.`. A token from a page on another hostname fails.
|
|
47
|
+
|
|
48
|
+
## Put it on a live site
|
|
49
|
+
|
|
50
|
+
Do the first install on a test site, not on the live one.
|
|
51
|
+
|
|
52
|
+
1. Install the plugin, connect it to the log, and keep Watch. Watch refuses nothing, so a wrong setting stops nobody.
|
|
53
|
+
2. Send a comment while you are signed in, then sign out and sign in. Look at **The last 20 decisions** on the settings page. The comment has the decision `allow` and must show `logged` in the Log column at once: the site reaches the log, and the token is good. The login has the decision `deny`, because no challenge is set yet, and shows `pending` until the hourly run sends it.
|
|
54
|
+
3. Download a receipt that shows `logged` from that table and verify it ([Verify a receipt](#verify-a-receipt)).
|
|
55
|
+
4. Enter the challenge keys and change the preset to Humans.
|
|
56
|
+
5. In a browser window that is not signed in, sign in and send a comment. Each form must show the widget, and each submission must pass.
|
|
57
|
+
6. Do the same steps on the live site. Leave Watch on for some days before you change to Humans, and read what Humans would refuse.
|
|
58
|
+
|
|
59
|
+
If step 5 fails and you cannot sign in, see "When the door locks you out".
|
|
60
|
+
|
|
61
|
+
## What it protects
|
|
62
|
+
|
|
63
|
+
| form | the request | route in the receipt |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| Comments | `POST /wp-comments-post.php`, a trackback (`/wp-trackback.php`), and the REST route that makes a comment (`/wp-json/wp/v2/comments`) | `comment` |
|
|
66
|
+
| Login | `POST /wp-login.php`, with no `action` or with an `action` that WordPress does not know: WordPress signs in on each of them | `login` |
|
|
67
|
+
| Registration | `POST /wp-login.php?action=register`, and `/wp-signup.php` on a network | `register` |
|
|
68
|
+
| Lost password | `POST /wp-login.php?action=lostpassword` | `lostpassword` |
|
|
69
|
+
| More protected paths | a request to a path in the list, exact or with `/*` at the end | `form` |
|
|
70
|
+
|
|
71
|
+
Each stock form has a checkbox. The plugin puts the challenge widget in each protected stock form. **More protected paths** is for the forms of other plugins, for example `/wp-json/contact-form-7/*`. With a path in the list, the plugin also puts the widget in each form on a page that posts to the site, so the token goes with the form's fields. A client that is not a browser sends the token in the `X-Agent-Custody-Challenge` header.
|
|
72
|
+
|
|
73
|
+
The door decides each request that is not a `GET`, a `HEAD`, or an `OPTIONS`, and each request that asks the REST API for another method (`_method`, `X-HTTP-Method-Override`). A path in the list starts after the site's address: on a site at `https://example.com/blog/`, write `/wp-json/contact-form-7/*`. The door compares paths as WordPress and the web server read them, so these all match that entry: `//WP-JSON/Contact-Form-7/...`, `/index.php/wp-json/contact-form-7/...`, and `/?rest_route=/contact-form-7/...`. An exact entry also matches with a `/` at the end, and an entry for a script matches the script with a path after it.
|
|
74
|
+
|
|
75
|
+
## What happens to a submission
|
|
76
|
+
|
|
77
|
+
1. The plugin reads the challenge token and asks the provider if it is good. The outcome is `passed`, `failed`, `unavailable`, or `absent`.
|
|
78
|
+
2. It records the arrival fact: the class (`unknown`, or `claimed` when the request names an agent or presents a grant, a signature, or a passport), the address, the method, the path, the route, and the challenge outcome. It records a second fact, `wordpress`, with `loggedIn`.
|
|
79
|
+
3. The preset decides. In Watch, a submission that Humans does not allow goes on to WordPress. Like a refused submission, it makes no request to the log and gets no authorization, and its receipt waits for the flush.
|
|
80
|
+
4. **Refused:** the visitor gets a 403 page with the receipt id. The plugin signs the receipt (`denied`) and stores it as `pending`. It makes no request to the log for a refused submission: the hourly flush appends the receipt.
|
|
81
|
+
5. **Allowed:** the plugin signs an authorization and commits it to the log. Only then does WordPress get the request. When WordPress has answered, the plugin signs the receipt, with the authorization and the status that WordPress answered (`executed`, or `failed` for a 5xx), and appends it to the log.
|
|
82
|
+
|
|
83
|
+
Each answer has `X-Agent-Custody-Receipt` and `X-Agent-Custody-Class`.
|
|
84
|
+
|
|
85
|
+
**When the log does not answer.** A submission that the preset allows is not passed to WordPress: the visitor gets a 503, and the receipt says `withheld`. The evidence must exist before the effect. In Watch, the submission goes on without the authorization, and the PHP error log says so. A receipt that the log did not take stays in the database as `pending`. WordPress cron appends pending receipts each hour: 50 in one run (filter `agent_custody_door_flush_batch`), the receipts of allowed submissions first, then the oldest first.
|
|
86
|
+
|
|
87
|
+
**When refused submissions flood the site.** A refused submission costs its sender nothing, so the plugin puts a bound on what it costs the site. It makes no request to the log, so refused submissions use at most 50 appends of the log's quota in an hour, and they cannot use up the quota that allowed submissions need. When 500 such receipts are `pending` (filter `agent_custody_door_max_pending`), the door still refuses each submission, and it signs no receipt for it until the flush makes room. Those refusals have no evidence.
|
|
88
|
+
|
|
89
|
+
**When the log has a new key.** The plugin pins the log's keys when it connects, and it refuses an answer that another key signed. To read the keys again, empty the log URL, save, enter the URL and the token, and save.
|
|
90
|
+
|
|
91
|
+
**When the door locks you out.** A wrong challenge key or a log that is down also stops your own login under Humans or Strict. Put `define( 'AGENT_CUSTODY_DOOR_OFF', true );` in `wp-config.php`. The plugin then decides nothing. Correct the settings and remove the line.
|
|
92
|
+
|
|
93
|
+
## Verify a receipt
|
|
94
|
+
|
|
95
|
+
The settings page lists the last 20 decisions. Each receipt id is a link to its bundle. The page also shows the door's public key: save it as `door.pub`.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx agent-custody verify RECEIPT.json --issuer-key door.pub --log-url https://log.agent-custody.dev/t/YOUR-TENANT/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## What a receipt records
|
|
102
|
+
|
|
103
|
+
- `request.args`: the method, the path, and the `User-Agent`, `Content-Type`, `Accept`, and `Host` headers. No query, no body, and no digest of the body.
|
|
104
|
+
- `facts.arrival`: as above. The address is `REMOTE_ADDR`. Behind a proxy or a CDN it is the proxy's address.
|
|
105
|
+
- `facts.wordpress`: `{ "loggedIn": true | false }`. It does not name the user.
|
|
106
|
+
- `policy`: the decision, the rules that permitted it, and the digest of the preset's policy text. In Watch, `enforced` is `false`.
|
|
107
|
+
- `execution`: `denied`, `withheld`, or `executed` / `failed` with the HTTP status that WordPress answered.
|
|
108
|
+
|
|
109
|
+
The receipts hold the address and the `User-Agent` of each arrival. They are in the site's database, in the table `wp_agent_custody_receipts`. The receipts that are in the log have two bounds. Such a receipt is deleted after 90 days (filter `agent_custody_door_retention_days`), and the hourly run keeps the newest 10,000 of them (filter `agent_custody_door_max_receipts`). A receipt that is not in the log yet is never deleted: the database has the only evidence of it. The receipt records at most 1,024 characters of the path and of each header. The log has only the hash of a receipt, so download a receipt that you must keep before it is deleted. The plugin keeps its key and its receipts when it is deactivated or deleted: they are the evidence.
|
|
110
|
+
|
|
111
|
+
## What it does not do
|
|
112
|
+
|
|
113
|
+
- **Admit an agent.** The plugin checks no grant, no Web Bot Auth signature, and no registry passport. An arrival that presents one is `claimed`, never `verified`, and the presets admit it only if it passes the challenge. A site that must admit registered agents runs the Node door in front of WordPress ([the door](door.md)).
|
|
114
|
+
- **Run your own Cedar policy.** The three presets are the policies.
|
|
115
|
+
- **Record the rate, behaviour, or fingerprint signals** of the Node door.
|
|
116
|
+
- **Protect a path it does not see.** XML-RPC (`xmlrpc.php`) signs in, makes comments, and takes pingbacks without the forms, and application passwords sign in without the login form. Put `/xmlrpc.php` in the path list to refuse them. A plugin that moves the login form to another address, or that reads a form before the WordPress `init` action, is not seen.
|
|
117
|
+
- **Put a bound on the challenge checks.** Each submission with a token is one request to the provider, and the visitor waits for it, 5 seconds at most. The Node door has a bound on the checks in flight; the plugin has none.
|
|
118
|
+
- **Give one token to two requests.** A provider accepts a token once. A form of another plugin that sends twice (a validation error, then a second try) needs a new token for the second try, and the widget makes one only when the page resets it.
|
|
119
|
+
- **Sign a receipt for each refusal in a flood.** See "When refused submissions flood the site". Each refused submission is still one request to the challenge provider when it has a token, and one database row until the queue is full.
|
|
120
|
+
- **Protect a post password.** The door does not decide `wp-login.php?action=postpass`.
|
|
121
|
+
- **Work across a multisite network.** Activate it on each site.
|
|
122
|
+
|
|
123
|
+
## What was checked, and how
|
|
124
|
+
|
|
125
|
+
- `test/door-wordpress.test.ts` runs the plugin's door class with the PHP command line: canonical JSON and digests equal to `crypto.ts`; the key id equal to the verifier's; each preset against Cedar for each challenge outcome and each route, signed in and not; an allowed comment with its authorization and a refused one, each through a real log and through `verifyBundle` with no failed check; nine log answers that must be refused; the challenge outcomes; the routes, with the spellings of a path that must match. It makes no network request. A machine without `php` skips it.
|
|
126
|
+
- `deploy/door/wordpress/smoke.sh` runs a stock WordPress container with MariaDB, Contact Form 7, and a hash-only log. It installs the plugin from its zip, connects it through the settings form, and checks that the comment form, the login form, and the contact page show the widget; that a comment, a login, and a contact form without a token get 403 and pass with a token (Turnstile's public test keys); that a login with an action that WordPress does not know gets 403; that a comment through the REST API without a token gets 403; that three other ways to the contact form (a second spelling of the path, `rest_route` in the query, a `GET` with `_method=POST`) get 403; that a login from a signed-in user without a token gets 403; that a login in Watch goes on and its receipt waits; that a refused submission makes no request to the log; that a comment gets 503 while the log is down; that a refused comment gets no receipt while the queue is full; and that all fourteen receipts are in the log and verify with `agent-custody verify`. The `gateway-image` workflow runs it on each pull request that touches `deploy/door`. Last run on WordPress 7.1.5 with PHP 8.3.
|
|
127
|
+
- By hand, in a browser, on the smoke test's site: the Turnstile widget (test keys) shows in the comment form and in the Contact Form 7 form and makes a token, and a comment and a contact form that are sent from the page pass the door.
|
|
128
|
+
- Not checked: the hosted log at `log.agent-custody.dev` (the smoke test's log is the same server in one-tenant mode over plain HTTP), hCaptcha against its real service, a widget with real keys, the registration form and the lost-password form on a site, and WordPress on PHP 7.4 (the door class passes its tests on PHP 7.4).
|
package/docs/door.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The gateway stands between an agent and the tools it uses. The door stands between the world and your own HTTP surface: a website, an API, a form. Every arrival, a browser, an API client, a crawler, or an agent acting for someone, is classified by what it presented, decided by a Cedar policy for the route it hit, relayed to your origin or refused, and receipted either way. The receipt is the same signed, logged, independently verifiable receipt the gateway issues, with `issuer.kind: "door"`.
|
|
6
6
|
|
|
7
|
-
New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md). A site already on Cloudflare can run the door at the edge, as a Worker: [the door as a Cloudflare Worker](door-worker.md).
|
|
7
|
+
New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md). A site already on Cloudflare can run the door at the edge, as a Worker: [the door as a Cloudflare Worker](door-worker.md). A WordPress site installs a plugin that protects its comments and forms: [the door as a WordPress plugin](door-wordpress.md).
|
|
8
8
|
|
|
9
9
|
This is the first piece of the agent front door. It answers "what may this arrival do here" and "what did it do, provably". It does not yet answer "is this an agent" for web traffic: that is detection, and the door records only what it can check. An agent that wants to be known can say so in a way the door checks: a grant, or a [Web Bot Auth signature](#web-bot-auth-signatures). Read [what the door knows](#what-the-door-knows-about-an-arrival) before writing a policy.
|
|
10
10
|
|
|
@@ -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 trusted registry keys (an error for one that does not load, or for `trustedRegistryKeys` without `webBotAuth
|
|
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`, and a warning when more than one is trusted and any is bound to no registry URL), 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
|
|
|
@@ -53,7 +53,7 @@ The door records one fact for every arrival, `arrival`, observed by the door its
|
|
|
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) |
|
|
56
|
+
| `passport` | `{ outcome, error?, registry?, registryKeyid?, agentId?, agent?, name?, owner?, capabilities?, agentVersion?, endpoints?, 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
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 |
|
|
58
58
|
| `remote` | string | the arrival's address |
|
|
59
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 |
|
package/docs/github-action.md
CHANGED
|
@@ -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.
|
|
23
|
+
- uses: svayatta/agent-custody@<commit sha of the release> # 0.16.14
|
|
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.
|
|
40
|
+
| `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.14` |
|
|
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
|
@@ -73,6 +73,7 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
73
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
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
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 |
|
|
76
|
+
| 65 | Demo 3, agent admitted: an agent-commerce company registers its agent and is admitted by a marketplace that had been blocking it | [65-agent-admitted-demo.ts](../examples/65-agent-admitted-demo.ts) | the marketplace's door admits only its partners; Carted's agent, with only a signature, is `claimed` and blocked; Carted registers it and gets a passport; with the passport it is `verified`, named, and owned, and still blocked; the marketplace searches the registry for `orders`, lists the agent by its registry entry, and the door reads the list on the next request; the order is placed once; the merchant verifies all three receipts with the door's key and reads who, whose, and what |
|
|
76
77
|
|
|
77
78
|
## How policies are defined, in one paragraph
|
|
78
79
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/receipts",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.14",
|
|
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",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"coverage": "vitest run --coverage.enabled",
|
|
72
72
|
"demo": "tsx scripts/demo.ts",
|
|
73
73
|
"demo:refund": "node examples/59-refund-demo.ts",
|
|
74
|
+
"demo:admitted": "node examples/65-agent-admitted-demo.ts",
|
|
74
75
|
"vectors": "tsx scripts/vectors.ts",
|
|
75
76
|
"bench": "node scripts/hot-path-bench.ts"
|
|
76
77
|
},
|