@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 CHANGED
@@ -155,6 +155,7 @@ Every receipt names its issuer, and the verifier prints what that issuer kind is
155
155
  | a site any agent arrives at, built on Express or Connect | door, in-process | `app.use(door("door.json"))` | | Express 5.2.1 with `express.json()`, `express.urlencoded()`, and a raw stream read after the door; [guide](docs/door-middleware.md) |
156
156
  | a site any agent arrives at, built on Go `net/http`, Rails (Rack), Django (or WSGI), or Spring | door, authz mode, asked by a middleware | `Door(url, timeout)(handler)`, `AgentCustody::Door`, `DoorMiddleware` / `DoorWSGI`, `CustodyDoor` with a filter | | each example against a live door: Go through `ServeHTTP`, Rack with a Rack env, WSGI under `wsgiref`, Django with a stand-in request and `HttpResponse`, the JDK `HttpServer` filter; the Spring filter is a doc snippet, not compiled; [guide](docs/door-languages.md) |
157
157
  | a site any agent arrives at, served through Cloudflare | door, as a Worker at the edge | `deploy/door/cloudflare-worker`, `wrangler deploy` | | the Worker bundle `wrangler deploy` builds, run in workerd (Miniflare) with stand-ins for the origin, the log, and a key directory; `wrangler deploy --dry-run` by hand; not yet a deployment to Cloudflare itself; [guide](docs/door-worker.md) |
158
+ | a WordPress site: its comments, login, registration, and other forms | door, as a plugin in PHP | `deploy/door/wordpress`, a zip uploaded in the WordPress admin | | the door class under the PHP command line, its receipts through `verifyBundle` and its presets against Cedar; by hand, `smoke.sh` on a stock WordPress 7.1.5 container; it checks no grant, signature, or passport; [guide](docs/door-wordpress.md) |
158
159
  | a site any agent arrives at, built on Next.js (App Router) | door, in-process | `guard.route(handler)` on each route handler | | fetch `Request` and `Response` objects in the tests; by hand, a fresh `create-next-app` (Next.js 16.4.6) under `next dev` and `next start`; [guide](docs/door-middleware.md) |
159
160
 
160
161
  The framework packages, `pg`, and `@node-saml/node-saml` (for SAML sign-in to the portal) are optional peer dependencies. Each adapter imports only from its own package.
@@ -359,6 +360,10 @@ The design is several producers feeding one verifier. The SDK is the top of the
359
360
 
360
361
  **Done**
361
362
 
363
+ - The door as a WordPress plugin (svayatta/pm#15): `deploy/door/wordpress` is a door in PHP for a stock WordPress site. The owner installs a zip, connects it to the hosted log, and chooses a preset (Watch, Humans, Strict). The plugin decides each comment, login, registration, and lost-password request, commits an allowed one to the log before WordPress acts on it, and signs a door receipt for each with a key that stays on the site. It checks no grant, signature, or passport: such an arrival is `claimed` ([the door as a WordPress plugin](docs/door-wordpress.md)).
364
+ - Demo 3, agent admitted (svayatta/pm#43): `bun run demo:admitted` (tutorial 65) puts the door in front of a marketplace's order API, admitting only its partners. An agent-commerce company's agent is blocked with only its signature, registers and gets a passport, is blocked again as a known agent the marketplace has not listed, and is admitted once the marketplace finds it in the registry by capability and lists it, with no restart of the door. The merchant verifies each receipt with the door's key and reads who the agent was, who owns it, and what it did. `test/admitted-demo.test.ts` runs it cold twice.
365
+ - Agent versions and declared endpoints (svayatta/pm#79): a registry entry carries the agent's `version` and the tool `endpoints` it says it calls, with the history of its versions and keys; passports and the arrival fact carry both, and an admission list entry may name a version or a range, so an arrival at a version the site has not listed is recorded with that version and on no list ([the agent registry](docs/agent-registry.md#versions-and-declared-endpoints)).
366
+ - Registry keys bound to their registry: a `trustedRegistryKeys` entry `{ "key", "registry" }` (in a Worker, a JSON list in `TRUSTED_REGISTRY_KEYS`) admits only passports that name its registry, so a door that trusts two registries does not let one vouch for the other's agents; `check` warns about keys bound to none ([the agent registry](docs/agent-registry.md#admit-registered-agents-at-a-door)).
362
367
  - Capability index and admission lists (svayatta/pm#22): the registry answers `GET /registry/agents?capability=` with its active agents, a page at a time. A door with `admissionLists` reads a site's named lists of agents, each entry a registry entry, an ERC-8004 identity, or a verified subject, and records in `arrival.admission` the lists a verified arrival's agent is on and the digest of the lists in force; the policy decides what each list means, and the decision is a receipt. A claim, or a passport the signer is not bound to, puts no agent on a list. The file is re-read when it changes, and a broken one leaves the lists in force ([admission lists](docs/admission-lists.md), tutorial 64).
363
368
  - The agent registry (svayatta/pm#21): with a registry key, `agent-custody portal` also runs an agent registry. A tenant registers each agent by its own Ed25519 did:key, with the key's proof that it holds it, a contact, capabilities, and an expiry, and the portal signs it a passport that lives a day. The registry publishes its key document at `/.well-known/agent-custody-registry.json`, each agent's entry and key, and fresh passports to anyone. A door with the registry's key in `trustedRegistryKeys` admits an agent that sends its passport and signs the request with that did:key, covering the passport, the method, the path, and a digest of the body, as `verified`, with no setup per agent and no call to the registry; the passport's entry is in the arrival fact for the policy, and under another key it is `wrong-sender`. Revocation stops new passports and reaches the door when the last one expires. With an RPC per chain, the registry also links an agent to its ERC-8004 identity, only when the token's registration file lists the agent's did:key, and the passport carries the link for the door's policy; the door reads no chain ([the agent registry](docs/agent-registry.md), tutorials 62 and 63).
364
369
  - Demo 1, the refund, API leg (svayatta/pm#41): `bun run demo:refund` (tutorial 59) puts the door in front of a shop's refund API and pays through two gateway lanes. A passport holder is paid once; over the limit or with a forged passport it is refused at the door; an agent with no passport waits for a person to approve the exact refund; an auditor verifies every receipt and finds a refund made in Stripe directly. It runs cold twice in a row in the tests. The phone leg waits for the tells service and the Twilio hook.
@@ -13,11 +13,17 @@ export declare const canonicalRegistry: (v: string) => string;
13
13
  declare const EntrySchema: z.ZodUnion<readonly [z.ZodObject<{
14
14
  registry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
15
15
  agentId: z.ZodString;
16
+ version: z.ZodOptional<z.ZodString>;
17
+ versions: z.ZodOptional<z.ZodObject<{
18
+ from: z.ZodOptional<z.ZodString>;
19
+ below: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strict>>;
16
21
  }, z.core.$strict>, z.ZodObject<{
17
22
  erc8004: z.ZodObject<{
18
23
  agentRegistry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
19
24
  agentId: z.ZodString;
20
25
  }, z.core.$strict>;
26
+ registry: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
21
27
  }, z.core.$strict>, z.ZodObject<{
22
28
  agent: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
23
29
  }, z.core.$strict>]>;
@@ -26,11 +32,17 @@ export declare const AdmissionListsSchema: z.ZodObject<{
26
32
  lists: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
27
33
  registry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
28
34
  agentId: z.ZodString;
35
+ version: z.ZodOptional<z.ZodString>;
36
+ versions: z.ZodOptional<z.ZodObject<{
37
+ from: z.ZodOptional<z.ZodString>;
38
+ below: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$strict>>;
29
40
  }, z.core.$strict>, z.ZodObject<{
30
41
  erc8004: z.ZodObject<{
31
42
  agentRegistry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
32
43
  agentId: z.ZodString;
33
44
  }, z.core.$strict>;
45
+ registry: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
34
46
  }, z.core.$strict>, z.ZodObject<{
35
47
  agent: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
36
48
  }, z.core.$strict>]>>>;
@@ -51,6 +63,7 @@ export interface ArrivalIdentity {
51
63
  outcome: string;
52
64
  registry?: string;
53
65
  agentId?: string;
66
+ agentVersion?: string;
54
67
  erc8004?: {
55
68
  agentRegistry: string;
56
69
  agentId: string;
package/dist/admission.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { z } from "zod";
9
9
  import { sha256Hex } from "./crypto.js";
10
10
  import { ERC8004_REGISTRY } from "./erc8004-link.js";
11
- import { AGENT_ID } from "./passport.js";
11
+ import { AGENT_ID, AGENT_VERSION, compareVersions } from "./passport.js";
12
12
  export const LIST_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
13
13
  export const MAX_LISTS = 64;
14
14
  export const MAX_LIST_ENTRIES = 10_000;
@@ -38,10 +38,28 @@ export const canonicalRegistry = (v) => {
38
38
  }
39
39
  };
40
40
  const EntrySchema = z.union([
41
- /** a registry entry: the registry's URL, as its passports name it, and the agent's id there; it survives key rotation */
42
- z.object({ registry: z.string().url().max(200).transform(canonicalRegistry), agentId: z.string().regex(AGENT_ID) }).strict(),
43
- /** an ERC-8004 identity, as a verified passport's registry checked it on chain */
44
- z.object({ erc8004: z.object({ agentRegistry: z.string().regex(ERC8004_REGISTRY).transform((r) => r.toLowerCase()), agentId: z.string().regex(/^(0|[1-9][0-9]{0,77})$/) }).strict() }).strict(),
41
+ /**
42
+ * a registry entry: the registry's URL, as its passports name it, and the agent's id there; it survives key rotation.
43
+ * `version` names one version of the agent, and `versions` a range (`from` inclusive, `below` exclusive); an arrival
44
+ * whose passport carries another version, or none, is not on the list by this entry
45
+ */
46
+ z.object({
47
+ registry: z.string().url().max(200).transform(canonicalRegistry),
48
+ agentId: z.string().regex(AGENT_ID),
49
+ version: z.string().regex(AGENT_VERSION, { message: "version is MAJOR.MINOR.PATCH, numbers only" }).optional(),
50
+ versions: z.object({ from: z.string().regex(AGENT_VERSION).optional(), below: z.string().regex(AGENT_VERSION).optional() }).strict()
51
+ .refine((r) => r.from !== undefined || r.below !== undefined, { message: "versions needs from, below, or both" })
52
+ .refine((r) => r.from === undefined || r.below === undefined || compareVersions(r.from, r.below) < 0, { message: "versions: from must be below below" })
53
+ .optional(),
54
+ }).strict().refine((e) => e.version === undefined || e.versions === undefined, { message: "give version or versions, not both" }),
55
+ /**
56
+ * an ERC-8004 identity, as a verified passport's registry checked it on chain. `registry` names the one registry
57
+ * whose check counts; without it, every registry whose key the door trusts can put an agent on the list by this entry
58
+ */
59
+ z.object({
60
+ erc8004: z.object({ agentRegistry: z.string().regex(ERC8004_REGISTRY).transform((r) => r.toLowerCase()), agentId: z.string().regex(/^(0|[1-9][0-9]{0,77})$/) }).strict(),
61
+ registry: z.string().url().max(200).transform(canonicalRegistry).optional(),
62
+ }).strict(),
45
63
  /** the subject of a verified arrival: a did:key, a Web Bot Auth signature agent's origin, or a grant's agent */
46
64
  z.object({ agent: z.string().min(1).max(200).transform(canonicalAgent) }).strict(),
47
65
  ]);
@@ -55,7 +73,21 @@ export const AdmissionListsSchema = z.object({
55
73
  ctx.addIssue({ code: "custom", path: [name], message: `"${name.slice(0, 40)}": a list name is lowercase letters, digits, and . _ -, at most 64 characters` });
56
74
  }),
57
75
  }).strict();
58
- const keyOf = (e) => ("registry" in e ? `registry ${e.registry} ${e.agentId}` : "erc8004" in e ? `erc8004 ${e.erc8004.agentRegistry} ${e.erc8004.agentId}` : `agent ${e.agent}`);
76
+ const erc8004Key = (link, registry) => `erc8004 ${link.agentRegistry} ${link.agentId}${registry === undefined ? "" : ` from ${registry}`}`;
77
+ const keyOf = (e) => ("erc8004" in e ? erc8004Key(e.erc8004, e.registry) : "registry" in e ? `registry ${e.registry} ${e.agentId}` : `agent ${e.agent}`);
78
+ const rangeOf = (e) => ("agentId" in e ? (e.version !== undefined ? { from: e.version, upTo: e.version } : e.versions) : undefined);
79
+ function inRange(r, version) {
80
+ if (!r)
81
+ return true;
82
+ // a version that is not one is in no range: compareVersions would refuse it, and a list must not admit it
83
+ if (version === undefined || !AGENT_VERSION.test(version))
84
+ return false;
85
+ if (r.from !== undefined && compareVersions(version, r.from) < 0)
86
+ return false;
87
+ if (r.upTo !== undefined && compareVersions(version, r.upTo) > 0)
88
+ return false;
89
+ return r.below === undefined || compareVersions(version, r.below) < 0;
90
+ }
59
91
  /** Parses and compiles a lists file; throws, naming what is wrong, when it is not one. */
60
92
  export function compileAdmissionLists(text) {
61
93
  let raw;
@@ -68,13 +100,12 @@ export function compileAdmissionLists(text) {
68
100
  const parsed = AdmissionListsSchema.safeParse(raw);
69
101
  if (!parsed.success)
70
102
  throw new Error(`the admission lists are not valid: ${parsed.error.issues.slice(0, 5).map((i) => `${i.path.join(".") || "file"} ${i.message}`).join("; ")}`);
103
+ // each key holds the lists that name it, with the versions each entry admits
71
104
  const index = new Map();
72
105
  for (const [name, entries] of Object.entries(parsed.data.lists)) {
73
106
  for (const e of entries) {
74
107
  const k = keyOf(e);
75
- const on = index.get(k) ?? new Set();
76
- on.add(name);
77
- index.set(k, on);
108
+ index.set(k, [...(index.get(k) ?? []), { name, range: rangeOf(e) }]);
78
109
  }
79
110
  }
80
111
  const names = Object.keys(parsed.data.lists).sort();
@@ -88,13 +119,17 @@ export function compileAdmissionLists(text) {
88
119
  const p = a.passport;
89
120
  if (p?.outcome === "verified" && p.registry && p.agentId) {
90
121
  keys.push(`registry ${canonicalRegistry(p.registry)} ${p.agentId}`);
91
- if (p.erc8004)
92
- keys.push(`erc8004 ${p.erc8004.agentRegistry.toLowerCase()} ${p.erc8004.agentId}`);
122
+ if (p.erc8004) {
123
+ const link = { agentRegistry: p.erc8004.agentRegistry.toLowerCase(), agentId: p.erc8004.agentId };
124
+ keys.push(erc8004Key(link), erc8004Key(link, canonicalRegistry(p.registry)));
125
+ }
93
126
  }
94
127
  const on = new Set();
128
+ const version = p?.outcome === "verified" ? p.agentVersion : undefined;
95
129
  for (const k of keys)
96
- for (const name of index.get(k) ?? [])
97
- on.add(name);
130
+ for (const { name, range } of index.get(k) ?? [])
131
+ if (inRange(range, version))
132
+ on.add(name);
98
133
  return [...on].sort();
99
134
  },
100
135
  };
package/dist/check.js CHANGED
@@ -3,11 +3,12 @@
3
3
  // is where tool-name collisions and unreachable servers show up, and compares every tool name the config mentions with
4
4
  // the tools the upstreams actually offer.
5
5
  import { compileAdmissionLists } from "./admission.js";
6
+ import { registryKeysOf } from "./door-core.js";
6
7
  import * as cedar from "@cedar-policy/cedar-wasm/nodejs";
7
8
  import { accessSync, constants, existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
8
9
  import { tmpdir } from "node:os";
9
10
  import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
10
- import { DoorConfigSchema, EgressConfigSchema, GatewayConfigSchema, loadConfig, loadDoorConfig, loadEgressConfig, ONE_LOG, strictRefusals } from "./config.js";
11
+ import { DoorConfigSchema, EgressConfigSchema, GatewayConfigSchema, loadConfig, loadDoorConfig, loadEgressConfig, ONE_LOG, registryKeyEntry, strictRefusals } from "./config.js";
11
12
  import { generateKeyPair, loadPrivateKey, loadPublicKey, writeKeyPair } from "./crypto.js";
12
13
  import { delegationValidAt, verifyDelegation } from "./delegation.js";
13
14
  import { hasPermitRule } from "./policy.js";
@@ -139,7 +140,7 @@ export function checkDoorConfig(configPath) {
139
140
  }
140
141
  }
141
142
  let registries = 0;
142
- for (const f of cfg.trustedRegistryKeys) {
143
+ for (const { key: f } of cfg.trustedRegistryKeys.map(registryKeyEntry)) {
143
144
  try {
144
145
  loadPublicKey(f);
145
146
  registries++;
@@ -158,6 +159,22 @@ export function checkDoorConfig(configPath) {
158
159
  add("error", "registry keys", "trustedRegistryKeys needs webBotAuth: a passport admits an agent only on a request its did:key signed, and webBotAuth checks that signature");
159
160
  else if (registries === cfg.trustedRegistryKeys.length)
160
161
  add("ok", "registry keys", `${registries} trusted registry key${registries === 1 ? "" : "s"} load`);
162
+ try {
163
+ registryKeysOf(cfg.trustedRegistryKeys.map(registryKeyEntry).flatMap((e) => {
164
+ try {
165
+ return [{ ref: loadPublicKey(e.key), ...(e.registry !== undefined ? { registry: e.registry } : {}) }];
166
+ }
167
+ catch {
168
+ return [];
169
+ }
170
+ }));
171
+ }
172
+ catch (e) {
173
+ add("error", "registry keys", e instanceof Error ? e.message : String(e));
174
+ }
175
+ const unbound = cfg.trustedRegistryKeys.map(registryKeyEntry).filter((e) => e.registry === undefined).length;
176
+ if (cfg.trustedRegistryKeys.length > 1 && unbound > 0)
177
+ add("warn", "registry keys", `${unbound} of ${cfg.trustedRegistryKeys.length} registry keys are bound to no registry URL, and such a key can sign passports that name any registry, so one registry can put its agents on another's list entries: give each { "key", "registry" }`);
161
178
  }
162
179
  if (!existsSync(cfg.policyFile))
163
180
  add("error", "policy", `${cfg.policyFile} does not exist`);
package/dist/config.d.ts CHANGED
@@ -418,7 +418,10 @@ export declare const DoorConfigSchema: z.ZodObject<{
418
418
  }, z.core.$strip>>>;
419
419
  unmatchedRoute: z.ZodDefault<z.ZodString>;
420
420
  trustedPrincipalKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
421
- trustedRegistryKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
421
+ trustedRegistryKeys: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
422
+ key: z.ZodString;
423
+ registry: z.ZodString;
424
+ }, z.core.$strict>]>>>;
422
425
  revokedGrants: z.ZodOptional<z.ZodString>;
423
426
  admissionLists: z.ZodOptional<z.ZodString>;
424
427
  policyFile: z.ZodString;
@@ -523,6 +526,11 @@ export declare const DoorConfigSchema: z.ZodObject<{
523
526
  captureKeyEnv: z.ZodOptional<z.ZodString>;
524
527
  }, z.core.$strip>;
525
528
  export type DoorConfig = z.infer<typeof DoorConfigSchema>;
529
+ /** A trusted registry key's file and, when the entry binds it, the one registry URL its passports may name. */
530
+ export declare const registryKeyEntry: (e: DoorConfig["trustedRegistryKeys"][number]) => {
531
+ key: string;
532
+ registry?: string;
533
+ };
526
534
  /**
527
535
  * The egress witness: a forward proxy in the agent's network path for every connection that does not go to the gateway.
528
536
  * Each agent proves who it is with its own proxy credential (`Proxy-Authorization: Basic`, id and secret); the secret
package/dist/config.js CHANGED
@@ -261,10 +261,10 @@ export const DoorConfigSchema = z.object({
261
261
  /** principal keys whose grants the door accepts as a passport: an arrival carrying one of their grants, in scope for its route, is `verified` */
262
262
  trustedPrincipalKeys: z.array(z.string()).default([]),
263
263
  /** agent registry keys (the key document at the registry's /.well-known/agent-custody-registry.json): an arrival that presents a passport one of them signed, and signs the request with the did:key the passport names, is `verified`. Needs `webBotAuth`, which checks the signature */
264
- trustedRegistryKeys: z.array(z.string()).default([]),
264
+ trustedRegistryKeys: z.array(z.union([z.string().min(1), z.object({ key: z.string().min(1), registry: z.string().url().refine((u) => /^https?:\/\//.test(u), { message: "registry is an http(s) URL" }) }).strict()])).default([]),
265
265
  /** a JSON file listing digests of revoked grant envelopes, the same file and format as the gateway's (`agent-custody revoke --config door.json` appends to it); re-read whenever it changes, checked on every arrival. A grant it lists, or one whose chain it lists, is `revoked` */
266
266
  revokedGrants: z.string().min(1).optional(),
267
- /** a JSON file of the site's named admission lists (`{ "lists": { "partners": [ { "registry", "agentId" } | { "erc8004": { "agentRegistry", "agentId" } } | { "agent" } ] } }`); re-read whenever it changes. The names of the lists a verified arrival's agent is on are `arrival.admission.lists` */
267
+ /** a JSON file of the site's named admission lists (`{ "lists": { "partners": [ { "registry", "agentId" } | { "erc8004": { "agentRegistry", "agentId" }, "registry"? } | { "agent" } ] } }`); re-read whenever it changes. The names of the lists a verified arrival's agent is on are `arrival.admission.lists` */
268
268
  admissionLists: z.string().min(1).optional(),
269
269
  policyFile: z.string(),
270
270
  /** "enforce" (default) refuses what the policy denies; "observe" forwards everything and records the decision with `enforced: false` */
@@ -377,6 +377,8 @@ export const DoorConfigSchema = z.object({
377
377
  .refine((c) => !c.partner || c.partner.routes.every((r) => r === "*" || r === c.unmatchedRoute || c.routes.some((x) => x.name === r)), { message: "partner.routes names a route the door does not have" })
378
378
  .refine((c) => !c.authz || c.trustProxy, { message: "authz needs trustProxy: true, since every check comes from the proxy and the arrival's address is the last in its X-Forwarded-For" })
379
379
  .refine((c) => !c.log || !!c.log.keys?.length, { message: "a remote log needs log.keys: the log's public key files, pinned, to check its answer before a request is relayed" });
380
+ /** A trusted registry key's file and, when the entry binds it, the one registry URL its passports may name. */
381
+ export const registryKeyEntry = (e) => (typeof e === "string" ? { key: e } : e);
380
382
  /**
381
383
  * The egress witness: a forward proxy in the agent's network path for every connection that does not go to the gateway.
382
384
  * Each agent proves who it is with its own proxy credential (`Proxy-Authorization: Basic`, id and secret); the secret
@@ -423,7 +425,7 @@ export function loadDoorConfig(path) {
423
425
  ...cfg,
424
426
  identity: { keyFile: r(cfg.identity.keyFile) },
425
427
  trustedPrincipalKeys: cfg.trustedPrincipalKeys.map(r),
426
- trustedRegistryKeys: cfg.trustedRegistryKeys.map(r),
428
+ trustedRegistryKeys: cfg.trustedRegistryKeys.map((e) => (typeof e === "string" ? r(e) : { ...e, key: r(e.key) })),
427
429
  ...(cfg.revokedGrants ? { revokedGrants: r(cfg.revokedGrants) } : {}),
428
430
  ...(cfg.admissionLists ? { admissionLists: r(cfg.admissionLists) } : {}),
429
431
  policyFile: r(cfg.policyFile),
@@ -163,6 +163,10 @@ export interface ArrivalPassport {
163
163
  name?: string;
164
164
  owner?: string;
165
165
  capabilities?: string[];
166
+ /** the agent's version, as its owner registered it */
167
+ agentVersion?: string;
168
+ /** the tool endpoints its owner says it calls: a claim the registry passed on, not a fact the door checked */
169
+ endpoints?: string[];
166
170
  /** the agent's ERC-8004 identity, as the registry checked it against the chain */
167
171
  erc8004?: {
168
172
  agentRegistry: string;
@@ -184,6 +188,14 @@ export interface ArrivalAdmission {
184
188
  lists: string[];
185
189
  digest: string;
186
190
  }
191
+ /** Trusted registry keys for the door's IO: the keys, and the URL that each bound key's passports may name, by keyid. */
192
+ export declare function registryKeysOf(keys: {
193
+ ref: PublicKeyRef;
194
+ registry?: string;
195
+ }[]): {
196
+ trustedRegistryKeys: PublicKeyRef[];
197
+ registryUrls: Record<string, string>;
198
+ };
187
199
  /** The components a signature must cover for the passport it carries to admit its agent. */
188
200
  export declare const PASSPORT_COVERED: readonly ["@method", "@path", "@query", "x-agent-custody-passport"];
189
201
  export interface Classified {
@@ -292,7 +304,7 @@ export declare function signedRequestOf(req: DoorRequest): SignedRequest;
292
304
  * Without `signature`, a `Signature-Input` header is recorded as `unchecked`. `revoked`, when given, says why a grant
293
305
  * that verified is revoked (from its chain's digests, leaf first), or null when it is not; a revoked grant is `claimed`.
294
306
  */
295
- export declare function classifyArrival(req: DoorRequest, trusted: PublicKeyRef[], route: string, trustProxy: boolean, at: string, signature?: SignatureCheck, revoked?: (chainDigests: string[]) => string | null, registry?: PublicKeyRef[], contentDigest?: boolean): Classified;
307
+ export declare function classifyArrival(req: DoorRequest, trusted: PublicKeyRef[], route: string, trustProxy: boolean, at: string, signature?: SignatureCheck, revoked?: (chainDigests: string[]) => string | null, registry?: PublicKeyRef[], contentDigest?: boolean, registryUrls?: Record<string, string>): Classified;
296
308
  /** The body as the door read it: whole, or how many bytes had arrived when it passed the limit. */
297
309
  export type BodyRead = {
298
310
  body: Buffer;
@@ -382,6 +394,8 @@ export interface DoorIO {
382
394
  trustedPrincipalKeys: PublicKeyRef[];
383
395
  /** agent registry keys whose passports admit the did:key they name */
384
396
  trustedRegistryKeys?: PublicKeyRef[];
397
+ /** the one registry URL a registry key's passports may name, by the key's keyid; a key absent here may name any */
398
+ registryUrls?: Record<string, string>;
385
399
  /** the policy text, and a value that changes whenever the text may have; read on every arrival. Throws when it cannot be read: the policy in force stays */
386
400
  readPolicy(): {
387
401
  text: string;
package/dist/door-core.js CHANGED
@@ -4,7 +4,7 @@ import { DID_KEY_PREFIX } from "./did-key.js";
4
4
  import { decodeDelegation, delegationValidAt, grantChainDigests, verifyDelegation } from "./delegation.js";
5
5
  import { parseGrantHeader, GRANT_HEADER } from "./grant-header.js";
6
6
  import { MAX_PASSPORT_HEADER, PASSPORT_HEADER, parsePassportHeader, passportSignedBy, verifyPassport } from "./passport.js";
7
- import { compileAdmissionLists } from "./admission.js";
7
+ import { canonicalRegistry, compileAdmissionLists } from "./admission.js";
8
8
  import { ReceiptPending } from "./receipt-pending.js";
9
9
  import { contentDigestMatches, createWebBotAuthVerifier, normalizeAuthority } from "./web-bot-auth.js";
10
10
  import { createHistoryTracker, createSeenCounter, fingerprintKey, FORM_REPORT_HEADER, historySource, observationOf, signalsOf } from "./door-signals.js";
@@ -131,13 +131,24 @@ export function createRateTracker(now = () => performance.now(), limits = {}) {
131
131
  clearInterval(timer); },
132
132
  };
133
133
  }
134
+ /** Trusted registry keys for the door's IO: the keys, and the URL that each bound key's passports may name, by keyid. */
135
+ export function registryKeysOf(keys) {
136
+ // one key listed twice must say one thing: two registries, or bound and also bare, cannot both hold
137
+ const seen = new Map();
138
+ for (const k of keys) {
139
+ if (seen.has(k.ref.keyid) && seen.get(k.ref.keyid) !== k.registry)
140
+ throw new Error(`the registry key ${k.ref.keyid} is listed twice, for ${seen.get(k.ref.keyid) ?? "any registry"} and for ${k.registry ?? "any registry"}; list it once, bound to its one registry`);
141
+ seen.set(k.ref.keyid, k.registry);
142
+ }
143
+ return { trustedRegistryKeys: keys.map((k) => k.ref), registryUrls: Object.fromEntries(keys.filter((k) => k.registry !== undefined).map((k) => [k.ref.keyid, k.registry])) };
144
+ }
134
145
  /** The components a signature must cover for the passport it carries to admit its agent. */
135
146
  export const PASSPORT_COVERED = ["@method", "@path", "@query", PASSPORT_HEADER];
136
147
  /**
137
148
  * The passport check for an arrival. `signer` is the did:key whose signature on this request the door verified, with
138
149
  * the components it covered; `contentDigest` is true when a `Content-Digest` field matched the body the door read.
139
150
  */
140
- function checkPassport(req, method, registry, at, signer, contentDigest) {
151
+ function checkPassport(req, method, registry, at, signer, contentDigest, registryUrls = {}) {
141
152
  const raw = req.headers[PASSPORT_HEADER];
142
153
  if (raw === undefined)
143
154
  return undefined;
@@ -150,6 +161,10 @@ function checkPassport(req, method, registry, at, signer, contentDigest) {
150
161
  if (!v.ok)
151
162
  return { outcome: "invalid", error: v.error };
152
163
  const p = v.passport;
164
+ // a registry writes its own URL into the passports it signs; a key bound to one URL must not vouch for another registry's agents
165
+ const bound = registryUrls[v.keyid];
166
+ if (bound !== undefined && canonicalRegistry(p.registry) !== canonicalRegistry(bound))
167
+ return { outcome: "invalid", error: `the passport names the registry ${p.registry}, and the key ${v.keyid} that signed it is trusted for ${bound} only` };
153
168
  const named = { registry: p.registry, agent: p.agent };
154
169
  if (signer?.agent !== p.agent)
155
170
  return { outcome: "wrong-sender", error: signer ? `the passport names ${p.agent}, and the request is signed by ${signer.agent}` : `the passport names ${p.agent}, and the request carries no signature by that key that the door verified`, ...named };
@@ -159,7 +174,7 @@ function checkPassport(req, method, registry, at, signer, contentDigest) {
159
174
  return { outcome: "unbound", error: `the signature does not cover ${missing.join(", ")}, which bind the passport to this request`, ...named };
160
175
  if (writes && !contentDigest)
161
176
  return { outcome: "unbound", error: "the Content-Digest the signature covers does not match the body the door read, or the door did not read the body" };
162
- return { outcome: "verified", ...named, registryKeyid: v.keyid, agentId: p.agentId, name: p.name, owner: p.owner, capabilities: p.capabilities, ...(p.erc8004 ? { erc8004: p.erc8004 } : {}), expiresAt: p.expiresAt, digest: v.digest, envelope: env };
177
+ return { outcome: "verified", ...named, registryKeyid: v.keyid, agentId: p.agentId, name: p.name, owner: p.owner, capabilities: p.capabilities, ...(p.agentVersion ? { agentVersion: p.agentVersion } : {}), ...(p.endpoints ? { endpoints: p.endpoints } : {}), ...(p.erc8004 ? { erc8004: p.erc8004 } : {}), expiresAt: p.expiresAt, digest: v.digest, envelope: env };
163
178
  }
164
179
  const HOP_BY_HOP = new Set(["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade", "proxy-connection"]);
165
180
  /** request headers the receipt records in clear; everything else is relayed and not recorded */
@@ -316,7 +331,7 @@ export function signedRequestOf(req) {
316
331
  * Without `signature`, a `Signature-Input` header is recorded as `unchecked`. `revoked`, when given, says why a grant
317
332
  * that verified is revoked (from its chain's digests, leaf first), or null when it is not; a revoked grant is `claimed`.
318
333
  */
319
- export function classifyArrival(req, trusted, route, trustProxy, at, signature, revoked, registry, contentDigest) {
334
+ export function classifyArrival(req, trusted, route, trustProxy, at, signature, revoked, registry, contentDigest, registryUrls) {
320
335
  const url = requestUrl(req);
321
336
  const method = (req.method ?? "GET").toUpperCase();
322
337
  const declaredRaw = req.headers[AGENT_HEADER];
@@ -327,7 +342,7 @@ export function classifyArrival(req, trusted, route, trustProxy, at, signature,
327
342
  // only on the last line, with a verified grant for that did:key. Everywhere else it is invalid, so that no policy
328
343
  // takes it for a checked identity.
329
344
  const didSigner = signer?.agent.startsWith(DID_KEY_PREFIX) ? signer : undefined;
330
- const passport = checkPassport(req, method, registry, at, didSigner ? { agent: didSigner.agent, ...(sig.outcome === "verified" && sig.covered ? { covered: sig.covered } : {}) } : undefined, contentDigest);
345
+ const passport = checkPassport(req, method, registry, at, didSigner ? { agent: didSigner.agent, ...(sig.outcome === "verified" && sig.covered ? { covered: sig.covered } : {}) } : undefined, contentDigest, registryUrls);
331
346
  const admitted = passport?.outcome === "verified";
332
347
  const norm = normalizePath(url.pathname);
333
348
  const baseOf = (s) => ({
@@ -530,7 +545,7 @@ export function createDoorCoreWith(cfg, io, framework, opts = {}) {
530
545
  const body = read === null ? Buffer.alloc(0) : "body" in read ? read.body : null;
531
546
  const digestField = req.headers["content-digest"];
532
547
  const contentDigest = read !== null && body !== null && typeof digestField === "string" && contentDigestMatches(digestField, body);
533
- const { arrival, delegation, signer } = classifyArrival(req, trusted, route, !!cfg.trustProxy, timestamp, signature, revoked, registry, contentDigest);
548
+ const { arrival, delegation, signer } = classifyArrival(req, trusted, route, !!cfg.trustProxy, timestamp, signature, revoked, registry, contentDigest, io.registryUrls);
534
549
  const admission = currentAdmission();
535
550
  if (admission)
536
551
  arrival.admission = { lists: admission.match(arrival), digest: admission.digest };
@@ -92,6 +92,16 @@ interface CfProperties {
92
92
  export declare const CLOUDFLARE_FACT = "cloudflare";
93
93
  /** Every SPKI PEM block in a variable. */
94
94
  export declare function pemKeys(text: string | undefined): PublicKeyRef[];
95
+ /**
96
+ * The trusted registry keys: PEM public keys, each trusted for any registry URL, or a JSON list of
97
+ * `{ publicKeyPem, registry }`, the shape of the `keys` in a registry's key document, that binds each key to the one
98
+ * registry URL its passports may name. A JSON object, such as a whole key document, is refused: its PEM would
99
+ * otherwise be read as a bare key and bound to nothing.
100
+ */
101
+ export declare function registryKeys(text: string | undefined): {
102
+ trustedRegistryKeys: PublicKeyRef[];
103
+ registryUrls: Record<string, string>;
104
+ };
95
105
  /**
96
106
  * The door config from the Worker's bindings, checked by the same schema as a Node door's. The fields that name files
97
107
  * are refused in DOOR_CONFIG, and the placeholders put in their place say where the Worker gets each one; nothing reads them.
@@ -3,9 +3,10 @@
3
3
  // variables; receipts go to an R2 bucket and to the log over HTTP; Web Bot Auth nonces go to a Durable Object. Built for workerd by scripts/build-door-worker.ts,
4
4
  // deployed from deploy/door/cloudflare-worker/.
5
5
  import { createPrivateKey, createPublicKey } from "node:crypto";
6
+ import { z } from "zod";
6
7
  import { DoorConfigSchema } from "./config.js";
7
8
  import { keyidOf, publicKeyFromPem } from "./crypto.js";
8
- import { createDoorCoreWith, DOOR_VERSION, jsonAnswer, readStream, RECEIPT_HEADER, relayedAnswer, relayToOrigin } from "./door-core.js";
9
+ import { createDoorCoreWith, registryKeysOf, DOOR_VERSION, jsonAnswer, readStream, RECEIPT_HEADER, relayedAnswer, relayToOrigin } from "./door-core.js";
9
10
  import { FORM_SCRIPT_PATH, formScript } from "./door-form.js";
10
11
  import { httpLog } from "./log-http.js";
11
12
  import { createObjectIssuer } from "./object-issuer.js";
@@ -32,6 +33,33 @@ const NOT_IN_A_WORKER = {
32
33
  export function pemKeys(text) {
33
34
  return [...(text ?? "").matchAll(/-----BEGIN PUBLIC KEY-----[\s\S]+?-----END PUBLIC KEY-----/g)].map((m) => publicKeyFromPem(m[0]));
34
35
  }
36
+ // `registry` is required: with the key document's other fields allowed through, a misspelt or missing one would
37
+ // otherwise leave the key trusted for any registry, and a Worker has no check to warn of it
38
+ const BoundRegistryKeysSchema = z.array(z.object({ publicKeyPem: z.string().min(1), registry: z.string().url().refine((u) => /^https?:\/\//.test(u), { message: "registry is an http(s) URL" }) }).passthrough()).min(1);
39
+ /**
40
+ * The trusted registry keys: PEM public keys, each trusted for any registry URL, or a JSON list of
41
+ * `{ publicKeyPem, registry }`, the shape of the `keys` in a registry's key document, that binds each key to the one
42
+ * registry URL its passports may name. A JSON object, such as a whole key document, is refused: its PEM would
43
+ * otherwise be read as a bare key and bound to nothing.
44
+ */
45
+ export function registryKeys(text) {
46
+ const t = (text ?? "").trim();
47
+ if (t.startsWith("{"))
48
+ throw new Error("TRUSTED_REGISTRY_KEYS is a JSON object; give PEM keys, or a JSON list of { publicKeyPem, registry } (the key document's keys, each with the registry's URL)");
49
+ if (!t.startsWith("["))
50
+ return registryKeysOf(pemKeys(t).map((ref) => ({ ref })));
51
+ let raw;
52
+ try {
53
+ raw = JSON.parse(t);
54
+ }
55
+ catch (e) {
56
+ throw new Error(`TRUSTED_REGISTRY_KEYS starts with [ and is not JSON: ${e instanceof Error ? e.message : String(e)}`);
57
+ }
58
+ const parsed = BoundRegistryKeysSchema.safeParse(raw);
59
+ if (!parsed.success)
60
+ throw new Error(`TRUSTED_REGISTRY_KEYS is not a list of { publicKeyPem, registry }: ${parsed.error.issues.slice(0, 3).map((i) => `${i.path.join(".")} ${i.message}`).join("; ")}`);
61
+ return registryKeysOf(parsed.data.map((e) => ({ ref: publicKeyFromPem(e.publicKeyPem), registry: e.registry })));
62
+ }
35
63
  /**
36
64
  * The door config from the Worker's bindings, checked by the same schema as a Node door's. The fields that name files
37
65
  * are refused in DOOR_CONFIG, and the placeholders put in their place say where the Worker gets each one; nothing reads them.
@@ -151,7 +179,7 @@ export function workerDoorIO(env, f) {
151
179
  return {
152
180
  key,
153
181
  trustedPrincipalKeys: pemKeys(env.TRUSTED_PRINCIPAL_KEYS),
154
- trustedRegistryKeys: pemKeys(env.TRUSTED_REGISTRY_KEYS),
182
+ ...registryKeys(env.TRUSTED_REGISTRY_KEYS),
155
183
  readPolicy: () => ({ text: env.DOOR_POLICY, key: "DOOR_POLICY" }),
156
184
  policySource: "the DOOR_POLICY variable",
157
185
  ...(env.ADMISSION_LISTS ? { readAdmission: () => ({ text: env.ADMISSION_LISTS, key: "ADMISSION_LISTS" }), admissionSource: "the ADMISSION_LISTS variable" } : {}),
package/dist/door.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type IncomingMessage, type ServerResponse } from "node:http";
2
- import type { DoorConfig } from "./config.ts";
2
+ import { type DoorConfig } from "./config.ts";
3
3
  import { type FlushResult } from "./issue.ts";
4
4
  import { type LogSink } from "./log-sink.ts";
5
5
  import { type ReceiptExporter } from "./otel.ts";
package/dist/door.js CHANGED
@@ -9,13 +9,14 @@
9
9
  import { randomUUID } from "node:crypto";
10
10
  import { closeSync, fstatSync, openSync, readFileSync } from "node:fs";
11
11
  import { createServer } from "node:http";
12
+ import { registryKeyEntry } from "./config.js";
12
13
  import { loadPrivateKey, loadPublicKey } from "./crypto.js";
13
14
  import { createIssuer } from "./issue.js";
14
15
  import { openLog } from "./log-sink.js";
15
16
  import { FORM_SCRIPT_PATH, formScript } from "./door-form.js";
16
17
  import { createRevocationList } from "./revocation.js";
17
18
  import { openExporter } from "./otel.js";
18
- import { AUTHZ_ALLOWED_REASON, DOOR_VERSION, RECEIPT_HEADER, authzTarget, createDoorCoreWith, jsonAnswer as json, relayedAnswer, relayToOrigin } from "./door-core.js";
19
+ import { AUTHZ_ALLOWED_REASON, DOOR_VERSION, RECEIPT_HEADER, authzTarget, createDoorCoreWith, registryKeysOf, jsonAnswer as json, relayedAnswer, relayToOrigin } from "./door-core.js";
19
20
  export * from "./door-core.js";
20
21
  /** The body, or how many bytes had arrived when it passed the limit; the rest is drained and dropped. */
21
22
  export function readBody(req, max) {
@@ -48,7 +49,7 @@ export function nodeDoorIO(cfg, options = {}) {
48
49
  return {
49
50
  key,
50
51
  trustedPrincipalKeys: cfg.trustedPrincipalKeys.map(loadPublicKey),
51
- trustedRegistryKeys: cfg.trustedRegistryKeys.map(loadPublicKey),
52
+ ...registryKeysOf(cfg.trustedRegistryKeys.map(registryKeyEntry).map((e) => ({ ref: loadPublicKey(e.key), ...(e.registry ? { registry: e.registry } : {}) }))),
52
53
  // the bytes and the metadata come from one open file
53
54
  readPolicy() {
54
55
  const fd = openSync(cfg.policyFile, "r");
package/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ export * from "./operations.ts";
71
71
  export * from "./crypto.ts";
72
72
  export * from "./delegation.ts";
73
73
  export { base58btcDecode, base58btcEncode, DID_KEY_PREFIX, didKeyOf, publicKeyFromDidKey } from "./did-key.ts";
74
- export { DEFAULT_PASSPORT_SECONDS, MAX_PASSPORT_HEADER, MAX_PASSPORT_SECONDS, PASSPORT_HEADER, PASSPORT_TYPE, PassportSchema, REGISTRY_DOCUMENT_PATH, issuePassport, parsePassportHeader, passportDigest, passportHeader, registrationMessage, registrationProof, verifyPassport } from "./registry.ts";
74
+ export { AGENT_VERSION, compareVersions, DEFAULT_PASSPORT_SECONDS, EndpointSchema, MAX_AGENT_HISTORY, MAX_ENDPOINT_CHARS, MAX_PASSPORT_HEADER, MAX_PASSPORT_SECONDS, PASSPORT_HEADER, PASSPORT_TYPE, PassportSchema, REGISTRY_DOCUMENT_PATH, issuePassport, parsePassportHeader, passportDigest, passportHeader, registrationMessage, registrationProof, verifyPassport } from "./registry.ts";
75
75
  export type { AgentEntry, Passport, PassportVerifyResult } from "./registry.ts";
76
76
  export { AdmissionListsSchema, canonicalAgent, canonicalRegistry, compileAdmissionLists, LIST_NAME, MAX_LIST_ENTRIES, MAX_LISTS } from "./admission.ts";
77
77
  export type { AdmissionEntry, AdmissionLists, ArrivalIdentity } from "./admission.ts";
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ export * from "./operations.js";
39
39
  export * from "./crypto.js";
40
40
  export * from "./delegation.js";
41
41
  export { base58btcDecode, base58btcEncode, DID_KEY_PREFIX, didKeyOf, publicKeyFromDidKey } from "./did-key.js";
42
- export { DEFAULT_PASSPORT_SECONDS, MAX_PASSPORT_HEADER, MAX_PASSPORT_SECONDS, PASSPORT_HEADER, PASSPORT_TYPE, PassportSchema, REGISTRY_DOCUMENT_PATH, issuePassport, parsePassportHeader, passportDigest, passportHeader, registrationMessage, registrationProof, verifyPassport } from "./registry.js";
42
+ export { AGENT_VERSION, compareVersions, DEFAULT_PASSPORT_SECONDS, EndpointSchema, MAX_AGENT_HISTORY, MAX_ENDPOINT_CHARS, MAX_PASSPORT_HEADER, MAX_PASSPORT_SECONDS, PASSPORT_HEADER, PASSPORT_TYPE, PassportSchema, REGISTRY_DOCUMENT_PATH, issuePassport, parsePassportHeader, passportDigest, passportHeader, registrationMessage, registrationProof, verifyPassport } from "./registry.js";
43
43
  export { AdmissionListsSchema, canonicalAgent, canonicalRegistry, compileAdmissionLists, LIST_NAME, MAX_LIST_ENTRIES, MAX_LISTS } from "./admission.js";
44
44
  export { createErc8004Resolver, decodeAbiString, ERC8004_REGISTRATION_TYPE, ERC8004_REGISTRY, Erc8004LinkSchema } from "./erc8004.js";
45
45
  export * from "./approval.js";
@@ -13,6 +13,17 @@ export declare const MAX_PASSPORT_SECONDS: number;
13
13
  export declare const AGENT_ID: RegExp;
14
14
  export declare const CAPABILITY: RegExp;
15
15
  export declare const DID_KEY: RegExp;
16
+ /** an agent's version: MAJOR.MINOR.PATCH, numbers only, compared as numbers */
17
+ export declare const AGENT_VERSION: RegExp;
18
+ /** Orders two versions that match AGENT_VERSION: negative, zero, or positive. */
19
+ export declare function compareVersions(a: string, b: string): number;
20
+ /** A tool endpoint an agent says it calls: a host name, or an https or wss URL (an MCP server). A claim, never checked by the registry. */
21
+ export declare const EndpointSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
22
+ /**
23
+ * The most characters the declared endpoints of one agent may take, together. With the largest of every other field, a
24
+ * passport stays within MAX_PASSPORT_HEADER, so a door can always read it.
25
+ */
26
+ export declare const MAX_ENDPOINT_CHARS = 1024;
16
27
  export declare const text: (max: number) => z.ZodString;
17
28
  export declare const PassportSchema: z.ZodObject<{
18
29
  version: z.ZodLiteral<"0.1">;
@@ -23,6 +34,8 @@ export declare const PassportSchema: z.ZodObject<{
23
34
  owner: z.ZodString;
24
35
  contact: z.ZodString;
25
36
  capabilities: z.ZodArray<z.ZodString>;
37
+ agentVersion: z.ZodOptional<z.ZodString>;
38
+ endpoints: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
26
39
  erc8004: z.ZodOptional<z.ZodObject<{
27
40
  agentRegistry: z.ZodString;
28
41
  agentId: z.ZodString;
package/dist/passport.js CHANGED
@@ -17,6 +17,42 @@ export const MAX_PASSPORT_SECONDS = 7 * 86_400;
17
17
  export const AGENT_ID = /^agt_[0-9a-f]{16}$/;
18
18
  export const CAPABILITY = /^[a-z0-9][a-z0-9._:-]{0,63}$/;
19
19
  export const DID_KEY = /^did:key:z[1-9A-HJ-NP-Za-km-z]{40,60}$/;
20
+ /** an agent's version: MAJOR.MINOR.PATCH, numbers only, compared as numbers */
21
+ export const AGENT_VERSION = /^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$/;
22
+ /** Orders two versions that match AGENT_VERSION: negative, zero, or positive. */
23
+ export function compareVersions(a, b) {
24
+ // anything else would compare as NaN, which is neither below nor above, and a range check would let it through
25
+ if (!AGENT_VERSION.test(a) || !AGENT_VERSION.test(b))
26
+ throw new Error(`not a version, MAJOR.MINOR.PATCH: ${!AGENT_VERSION.test(a) ? a : b}`.slice(0, 120));
27
+ const x = a.split(".").map(Number);
28
+ const y = b.split(".").map(Number);
29
+ for (let i = 0; i < 3; i++)
30
+ if (x[i] !== y[i])
31
+ return x[i] - y[i];
32
+ return 0;
33
+ }
34
+ const HOSTNAME = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/;
35
+ /** A tool endpoint an agent says it calls: a host name, or an https or wss URL (an MCP server). A claim, never checked by the registry. */
36
+ export const EndpointSchema = z.string().max(200)
37
+ .refine((v) => !/[\s\u0000-\u001f\u007f]/.test(v), { message: "an endpoint has no white space or control characters" })
38
+ .refine((v) => {
39
+ if (HOSTNAME.test(v))
40
+ return true;
41
+ try {
42
+ const u = new URL(v);
43
+ return (u.protocol === "https:" || u.protocol === "wss:") && !u.username && !u.password && HOSTNAME.test(u.hostname);
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }, { message: "an endpoint is a lowercase host name, or an https or wss URL without credentials" })
49
+ // one spelling: a URL is kept as its href, so what the passport carries is what the URL means
50
+ .transform((v) => (HOSTNAME.test(v) ? v : new URL(v).href));
51
+ /**
52
+ * The most characters the declared endpoints of one agent may take, together. With the largest of every other field, a
53
+ * passport stays within MAX_PASSPORT_HEADER, so a door can always read it.
54
+ */
55
+ export const MAX_ENDPOINT_CHARS = 1024;
20
56
  export const text = (max) => z.string().trim().min(1).max(max).refine((s) => !/[\u0000-\u001f\u007f]/.test(s), { message: "control characters are not allowed" });
21
57
  export const PassportSchema = z.object({
22
58
  version: z.literal("0.1"),
@@ -31,6 +67,10 @@ export const PassportSchema = z.object({
31
67
  /** how a site reaches the agent's operator */
32
68
  contact: text(200),
33
69
  capabilities: z.array(z.string().regex(CAPABILITY)).max(32),
70
+ /** the version of the agent its owner registered; absent when none was */
71
+ agentVersion: z.string().regex(AGENT_VERSION).optional(),
72
+ /** the tool endpoints the agent's owner says it calls: a claim, which the registry does not check */
73
+ endpoints: z.array(EndpointSchema).max(32).optional(),
34
74
  /** the agent's ERC-8004 identity, as the registry last checked it against the chain; absent when it has none or the check is stale */
35
75
  erc8004: z.object({ agentRegistry: z.string().regex(ERC8004_REGISTRY), agentId: z.string().regex(/^[0-9]{1,78}$/), owner: z.string().regex(/^0x[0-9a-f]{40}$/), block: z.number().int().nonnegative() }).optional(),
36
76
  issuedAt: z.iso.datetime({ offset: true }),