@agent-custody/receipts 0.16.11 → 0.16.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/dist/admission.d.ts +62 -0
- package/dist/admission.js +101 -0
- package/dist/check.js +42 -3
- package/dist/cli.js +179 -7
- package/dist/config.d.ts +6 -1
- package/dist/config.js +21 -2
- package/dist/door-app.js +1 -1
- package/dist/door-core.d.ts +81 -3
- package/dist/door-core.js +113 -13
- package/dist/door-error-rates.d.ts +102 -0
- package/dist/door-error-rates.js +178 -0
- package/dist/door-form.d.ts +7 -2
- package/dist/door-form.js +52 -4
- package/dist/door-measure.d.ts +153 -0
- package/dist/door-measure.js +325 -0
- package/dist/door-signals.d.ts +414 -0
- package/dist/door-signals.js +555 -0
- package/dist/door-test-set.d.ts +43 -0
- package/dist/door-test-set.js +117 -0
- package/dist/door-worker.d.ts +20 -1
- package/dist/door-worker.js +30 -2
- package/dist/door.js +18 -2
- package/dist/erc8004-link.d.ts +24 -0
- package/dist/erc8004-link.js +11 -0
- package/dist/erc8004.d.ts +26 -0
- package/dist/erc8004.js +208 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.js +9 -2
- package/dist/lock.d.ts +5 -0
- package/dist/lock.js +1 -1
- package/dist/log-store.d.ts +3 -1
- package/dist/log-store.js +2 -2
- package/dist/passport.d.ts +53 -0
- package/dist/passport.js +87 -0
- package/dist/portal.d.ts +14 -0
- package/dist/portal.js +102 -0
- package/dist/registry.d.ts +145 -0
- package/dist/registry.js +294 -0
- package/dist/web-bot-auth.d.ts +9 -3
- package/dist/web-bot-auth.js +31 -4
- package/docs/admission-lists.md +89 -0
- package/docs/agent-registry.md +173 -0
- package/docs/door-error-rates.md +490 -0
- package/docs/door-languages.md +3 -1
- package/docs/door-middleware.md +6 -1
- package/docs/door-quickstart.md +2 -2
- package/docs/door-signals.md +112 -2
- package/docs/door-worker.md +14 -1
- package/docs/door.md +37 -6
- package/docs/github-action.md +2 -2
- package/docs/tutorials.md +7 -0
- package/docs/usage.md +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// A labelled test set for the door: arrivals built to be one known kind each, decided by the real door core, with no
|
|
2
|
+
// network. The origin and the signature agent's directory are stand-ins in memory. The labels are true by construction,
|
|
3
|
+
// so the error rates measured on it say what the door's checks do with each kind, not how common each kind is.
|
|
4
|
+
import { generateKeyPairSync, randomUUID, sign } from "node:crypto";
|
|
5
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { DoorConfigSchema } from "./config.js";
|
|
8
|
+
import { generateKeyPair } from "./crypto.js";
|
|
9
|
+
import { createDelegation } from "./delegation.js";
|
|
10
|
+
import { createDoorCoreWith, relayToOrigin } from "./door-core.js";
|
|
11
|
+
import { grantHeader } from "./grant-header.js";
|
|
12
|
+
import { createIssuer } from "./issue.js";
|
|
13
|
+
import { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, jwkThumbprint, parseDictionary, signatureBase } from "./web-bot-auth.js";
|
|
14
|
+
const SITE = "shop.test";
|
|
15
|
+
const AGENT_ORIGIN = "https://crawler.test";
|
|
16
|
+
const BROWSER_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
17
|
+
const POLICY = `permit(principal, action == Action::"api", resource) when { context.facts.arrival.class == "verified" };
|
|
18
|
+
permit(principal, action == Action::"account", resource) when { context.facts.arrival.class == "verified" };`;
|
|
19
|
+
const grant = (k, agent, scopes, fromMs, toMs) => grantHeader(createDelegation(k, { version: "0.1", principal: "shop-owner", agent, scopes, issuedAt: new Date(Date.now() + fromMs).toISOString(), expiresAt: new Date(Date.now() + toMs).toISOString() }));
|
|
20
|
+
function signed(key, x, nonce, path) {
|
|
21
|
+
const created = Math.floor(Date.now() / 1000);
|
|
22
|
+
const headers = { "signature-agent": `crawler="${AGENT_ORIGIN}"` };
|
|
23
|
+
headers["signature-input"] = `sig1=("@authority" "signature-agent";key="crawler");created=${created};expires=${created + 60};keyid="${jwkThumbprint(x)}";alg="ed25519";nonce="${nonce}";tag="web-bot-auth"`;
|
|
24
|
+
const base = signatureBase({ method: "GET", target: path, authority: SITE, header: (h) => (Object.hasOwn(headers, h) ? [headers[h]] : undefined) }, parseDictionary(headers["signature-input"]).get("sig1"));
|
|
25
|
+
headers.signature = `sig1=:${sign(null, Buffer.from(base), key).toString("base64")}:`;
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
const PATH = "/api/orders";
|
|
29
|
+
/** The kinds in the published test set, in the order the page lists them. */
|
|
30
|
+
export const DOOR_TEST_KINDS = [
|
|
31
|
+
{ kind: "browser", automated: false, genuine: null, describes: "a person's browser: a current Chrome user agent and an HTML accept header, nothing else", build: () => ({ headers: { "user-agent": BROWSER_UA, accept: "text/html" } }) },
|
|
32
|
+
{ kind: "script", automated: true, genuine: null, describes: "a program that presents nothing: a curl user agent", build: () => ({ headers: { "user-agent": "curl/8.7.1", accept: "*/*" } }) },
|
|
33
|
+
{ kind: "script-as-browser", automated: true, genuine: null, describes: "a program that sends the browser's headers, byte for byte", build: () => ({ headers: { "user-agent": BROWSER_UA, accept: "text/html" } }) },
|
|
34
|
+
{ kind: "granted-agent", automated: true, genuine: true, describes: "an agent with a grant from a trusted principal, in its window, for this route", build: (k) => ({ headers: { "x-agent-custody-grant": grant(k.principal, "buyer-bot", ["api"], -1000, 3600_000) } }) },
|
|
35
|
+
{ kind: "signed-agent", automated: true, genuine: true, describes: "an agent with a Web Bot Auth signature its listed directory's key verifies, with a fresh nonce", build: (k, n) => ({ headers: signed(k.agent.privateKey, k.agent.x, `signed-${n}`, PATH) }) },
|
|
36
|
+
{ kind: "declared-name", automated: true, genuine: false, describes: "a program that names an agent in `x-agent-custody-agent` and presents nothing else", build: () => ({ headers: { "x-agent-custody-agent": "buyer-bot" } }) },
|
|
37
|
+
{ kind: "forged-signature", automated: true, genuine: false, describes: "a Web Bot Auth signature in the agent's name and keyid, made with another key", build: (k, n) => ({ headers: signed(k.impostor, k.agent.x, `forged-${n}`, PATH) }) },
|
|
38
|
+
{ kind: "replayed-signature", automated: true, genuine: false, describes: "the agent's own valid signature, sent a second time by someone who saw it", build: (k, n) => { const h = signed(k.agent.privateKey, k.agent.x, `replayed-${n}`, PATH); return { headers: h, prime: h }; } },
|
|
39
|
+
{ kind: "untrusted-grant", automated: true, genuine: false, describes: "a well-formed grant signed by a principal key the door does not trust", build: (k) => ({ headers: { "x-agent-custody-grant": grant(k.stranger, "buyer-bot", ["api"], -1000, 3600_000) } }) },
|
|
40
|
+
{ kind: "expired-grant", automated: true, genuine: false, describes: "a trusted principal's grant whose window ended a minute ago", build: (k) => ({ headers: { "x-agent-custody-grant": grant(k.principal, "buyer-bot", ["api"], -3600_000, -60_000) } }) },
|
|
41
|
+
{ kind: "out-of-scope-grant", automated: true, genuine: false, describes: "a trusted principal's grant for another route", build: (k) => ({ headers: { "x-agent-custody-grant": grant(k.principal, "buyer-bot", ["account"], -1000, 3600_000) } }) },
|
|
42
|
+
{ kind: "grant-under-other-signature", automated: true, genuine: false, describes: "a valid grant for one agent, sent under another agent's verified signature", build: (k, n) => ({ headers: { ...signed(k.agent.privateKey, k.agent.x, `wrong-sender-${n}`, PATH), "x-agent-custody-grant": grant(k.principal, "buyer-bot", ["api"], -1000, 3600_000) } }) },
|
|
43
|
+
];
|
|
44
|
+
/** Builds the test set in `dir`: `perKind` labelled arrivals of each kind, their receipts and log, and `labels.jsonl`. */
|
|
45
|
+
export async function buildDoorTestSet(dir, opts) {
|
|
46
|
+
const receiptsDir = join(dir, "receipts");
|
|
47
|
+
const logFile = join(dir, "log.jsonl");
|
|
48
|
+
mkdirSync(receiptsDir, { recursive: true });
|
|
49
|
+
const doorKey = generateKeyPair();
|
|
50
|
+
const agent = generateKeyPairSync("ed25519");
|
|
51
|
+
const keys = {
|
|
52
|
+
principal: generateKeyPair(),
|
|
53
|
+
stranger: generateKeyPair(),
|
|
54
|
+
agent: { privateKey: agent.privateKey, x: agent.publicKey.export({ format: "jwk" }).x },
|
|
55
|
+
impostor: generateKeyPairSync("ed25519").privateKey,
|
|
56
|
+
};
|
|
57
|
+
const directory = JSON.stringify({ keys: [{ kty: "OKP", crv: "Ed25519", x: keys.agent.x }] });
|
|
58
|
+
const cfg = DoorConfigSchema.parse({
|
|
59
|
+
identity: { keyFile: "unread" },
|
|
60
|
+
policyFile: "unread",
|
|
61
|
+
receiptsDir,
|
|
62
|
+
logFile,
|
|
63
|
+
routes: [{ name: "api", path: "/api/*", methods: ["GET"] }, { name: "account", path: "/account/*", methods: ["GET"] }],
|
|
64
|
+
webBotAuth: { agents: [AGENT_ORIGIN], authorities: [SITE] },
|
|
65
|
+
});
|
|
66
|
+
const stand = async (input) => {
|
|
67
|
+
const u = new URL(input instanceof Request ? input.url : String(input));
|
|
68
|
+
if (u.origin === AGENT_ORIGIN && u.pathname === DIRECTORY_PATH)
|
|
69
|
+
return new Response(directory, { headers: { "content-type": DIRECTORY_MEDIA_TYPE } });
|
|
70
|
+
return new Response(JSON.stringify({ ok: true }), { status: 200, headers: { "content-type": "application/json" } });
|
|
71
|
+
};
|
|
72
|
+
const io = {
|
|
73
|
+
key: doorKey,
|
|
74
|
+
trustedPrincipalKeys: [keys.principal],
|
|
75
|
+
readPolicy: () => ({ text: POLICY, key: "test-set" }),
|
|
76
|
+
policySource: "the test set's policy",
|
|
77
|
+
revoked: () => null,
|
|
78
|
+
secret: () => undefined,
|
|
79
|
+
issuer: (capture) => createIssuer(doorKey, receiptsDir, logFile, { capture }),
|
|
80
|
+
fetch: stand,
|
|
81
|
+
timers: false,
|
|
82
|
+
};
|
|
83
|
+
const core = createDoorCoreWith(cfg, io, "test-set");
|
|
84
|
+
const target = { url: new URL("https://origin.test"), headers: {}, timeoutMs: 5000, proto: "https" };
|
|
85
|
+
const send = async (headers, remote) => {
|
|
86
|
+
const req = { method: "GET", url: PATH, headers: { host: SITE, ...headers }, socket: { remoteAddress: remote } };
|
|
87
|
+
const d = await core.decide(req, randomUUID(), async () => ({ body: Buffer.alloc(0) }));
|
|
88
|
+
const relayed = await relayToOrigin(core, cfg, d, req, target, stand);
|
|
89
|
+
await core.record(d, relayed.execution);
|
|
90
|
+
return d.receiptId;
|
|
91
|
+
};
|
|
92
|
+
const labels = [];
|
|
93
|
+
try {
|
|
94
|
+
let i = 0;
|
|
95
|
+
for (const t of opts.kinds ?? DOOR_TEST_KINDS) {
|
|
96
|
+
for (let n = 0; n < opts.perKind; n++, i++) {
|
|
97
|
+
const built = t.build(keys, n);
|
|
98
|
+
// a documentation address per arrival, so the rate counter never ties one kind to another
|
|
99
|
+
const remote = `198.51.100.${i % 250}`;
|
|
100
|
+
if (built.prime)
|
|
101
|
+
await send(built.prime, remote);
|
|
102
|
+
labels.push({ receiptId: await send(built.headers, remote), kind: t.kind, automated: t.automated, genuine: t.genuine, source: "test-set" });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
core.close();
|
|
108
|
+
}
|
|
109
|
+
const labelsFile = join(dir, "labels.jsonl");
|
|
110
|
+
writeFileSync(labelsFile, labels.map((l) => JSON.stringify(l)).join("\n") + "\n");
|
|
111
|
+
return { receiptsDir, logFile, labelsFile, labels, doorKey, principalKey: keys.principal };
|
|
112
|
+
}
|
|
113
|
+
/** The kinds as a Markdown table: what each arrival is, and what the labels say it is. */
|
|
114
|
+
export function formatTestKinds(kinds = DOOR_TEST_KINDS) {
|
|
115
|
+
const yes = (b) => (b === null ? "names no agent" : b ? "yes" : "no");
|
|
116
|
+
return ["| kind | what arrives | a program | genuine |", "| --- | --- | --- | --- |", ...kinds.map((k) => `| \`${k.kind}\` | ${k.describes} | ${k.automated ? "yes" : "no"} | ${yes(k.genuine)} |`), ""].join("\n");
|
|
117
|
+
}
|
package/dist/door-worker.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DoorConfig } from "./config.ts";
|
|
2
2
|
import { type PublicKeyRef } from "./crypto.ts";
|
|
3
3
|
import { type DoorIO, type DoorRequest, type ObservedFact } from "./door-core.ts";
|
|
4
|
+
import type { TlsObservation } from "./door-signals.ts";
|
|
4
5
|
import { type ObjectStore } from "./object-issuer.ts";
|
|
5
6
|
import type { NonceStore } from "./web-bot-auth.ts";
|
|
6
7
|
/** What the Worker needs of an R2 bucket binding. */
|
|
@@ -56,6 +57,10 @@ export interface DoorWorkerEnv {
|
|
|
56
57
|
LOG_HASH_ONLY?: string;
|
|
57
58
|
/** principal keys whose grants are a passport, SPKI PEM */
|
|
58
59
|
TRUSTED_PRINCIPAL_KEYS?: string;
|
|
60
|
+
/** agent registry keys whose passports admit an agent, SPKI PEM */
|
|
61
|
+
TRUSTED_REGISTRY_KEYS?: string;
|
|
62
|
+
/** the site's admission lists, the JSON of a door's `admissionLists` file */
|
|
63
|
+
ADMISSION_LISTS?: string;
|
|
59
64
|
/** a JSON array of revoked grant digests, as in a gateway's or door's `revokedGrants` file */
|
|
60
65
|
REVOKED_GRANTS?: string;
|
|
61
66
|
/** secret: the door's signing key, PKCS8 PEM (`agent-custody keygen`) */
|
|
@@ -68,12 +73,20 @@ export interface DoorWorkerEnv {
|
|
|
68
73
|
NONCES?: DurableObjectNamespaceLike;
|
|
69
74
|
[binding: string]: unknown;
|
|
70
75
|
}
|
|
71
|
-
/** What a request's `cf` object may carry
|
|
76
|
+
/** What a request's `cf` object may carry: Bot Management, only where the zone has it, and what Cloudflare saw of the TLS handshake. */
|
|
72
77
|
interface CfProperties {
|
|
73
78
|
botManagement?: {
|
|
74
79
|
score?: unknown;
|
|
75
80
|
verifiedBot?: unknown;
|
|
81
|
+
ja4?: unknown;
|
|
76
82
|
};
|
|
83
|
+
tlsVersion?: unknown;
|
|
84
|
+
tlsCipher?: unknown;
|
|
85
|
+
tlsClientExtensionsSha1?: unknown;
|
|
86
|
+
tlsClientHelloLength?: unknown;
|
|
87
|
+
httpProtocol?: unknown;
|
|
88
|
+
asn?: unknown;
|
|
89
|
+
asOrganization?: unknown;
|
|
77
90
|
}
|
|
78
91
|
/** the fact the Worker records when Cloudflare Bot Management scored the request */
|
|
79
92
|
export declare const CLOUDFLARE_FACT = "cloudflare";
|
|
@@ -112,6 +125,12 @@ export declare function workerDoorIO(env: DoorWorkerEnv, f: typeof fetch): DoorI
|
|
|
112
125
|
* relayed, and `cdn-loop` sent on to a subrequest would count as a loop.
|
|
113
126
|
*/
|
|
114
127
|
export declare function doorRequestOf(request: Request): DoorRequest;
|
|
128
|
+
/**
|
|
129
|
+
* What Cloudflare saw of the client's TLS handshake, for the door's TLS fingerprint: the JA4 where the zone has Bot
|
|
130
|
+
* Management, and the version, the cipher, the extensions hash, and the ClientHello length that every zone gets. Only
|
|
131
|
+
* strings of a bounded length are taken; the door's signal code checks their shape.
|
|
132
|
+
*/
|
|
133
|
+
export declare function cloudflareTls(cf: CfProperties | undefined): TlsObservation | undefined;
|
|
115
134
|
/** Cloudflare Bot Management's score and verified-bot flag, when the zone has it and they are what Cloudflare documents; nothing otherwise. Cloudflare does not sign them: they enter as observed. */
|
|
116
135
|
export declare function cloudflareFacts(cf: CfProperties | undefined): Record<string, ObservedFact>;
|
|
117
136
|
export interface DoorWorkerOptions {
|
package/dist/door-worker.js
CHANGED
|
@@ -19,6 +19,8 @@ const NOT_IN_A_WORKER = {
|
|
|
19
19
|
logFile: "the log is LOG_URL",
|
|
20
20
|
log: "the log is LOG_URL, LOG_KEYS, LOG_ID, LOG_TOKEN",
|
|
21
21
|
trustedPrincipalKeys: "trusted principal keys are the TRUSTED_PRINCIPAL_KEYS variable",
|
|
22
|
+
trustedRegistryKeys: "trusted registry keys are the TRUSTED_REGISTRY_KEYS variable",
|
|
23
|
+
admissionLists: "admission lists are the ADMISSION_LISTS variable",
|
|
22
24
|
revokedGrants: "revoked grants are the REVOKED_GRANTS variable",
|
|
23
25
|
authz: "a Worker relays; nginx and Envoy ask a Node door",
|
|
24
26
|
trustProxy: "the Worker reads the client's address from Cloudflare (CF-Connecting-IP)",
|
|
@@ -49,6 +51,8 @@ export function workerDoorConfig(env) {
|
|
|
49
51
|
const origin = (raw.origin ?? {});
|
|
50
52
|
if (Object.hasOwn(origin, "url"))
|
|
51
53
|
throw new Error("DOOR_CONFIG has origin.url: the origin is the ORIGIN_URL variable");
|
|
54
|
+
if (raw.behaviour && typeof raw.behaviour === "object" && Object.hasOwn(raw.behaviour, "tlsHeader"))
|
|
55
|
+
throw new Error("DOOR_CONFIG has behaviour.tlsHeader, which a Worker does not take: the Worker reads the TLS fingerprint from Cloudflare (request.cf)");
|
|
52
56
|
if (raw.webBotAuth && !env.NONCES)
|
|
53
57
|
throw new Error("DOOR_CONFIG has webBotAuth, which needs the NONCES Durable Object binding: one isolate's memory cannot refuse a signature replayed to another");
|
|
54
58
|
return DoorConfigSchema.parse({
|
|
@@ -147,8 +151,10 @@ export function workerDoorIO(env, f) {
|
|
|
147
151
|
return {
|
|
148
152
|
key,
|
|
149
153
|
trustedPrincipalKeys: pemKeys(env.TRUSTED_PRINCIPAL_KEYS),
|
|
154
|
+
trustedRegistryKeys: pemKeys(env.TRUSTED_REGISTRY_KEYS),
|
|
150
155
|
readPolicy: () => ({ text: env.DOOR_POLICY, key: "DOOR_POLICY" }),
|
|
151
156
|
policySource: "the DOOR_POLICY variable",
|
|
157
|
+
...(env.ADMISSION_LISTS ? { readAdmission: () => ({ text: env.ADMISSION_LISTS, key: "ADMISSION_LISTS" }), admissionSource: "the ADMISSION_LISTS variable" } : {}),
|
|
152
158
|
revoked: (digests) => (!digests.some((d) => revoked.has(d)) ? null : revoked.has(digests[0]) ? "the grant has been revoked" : "a grant above it in its chain has been revoked"),
|
|
153
159
|
secret: (name) => (typeof env[name] === "string" ? env[name] : undefined),
|
|
154
160
|
issuer: (capture) => createObjectIssuer(key, store, sink, { capture }),
|
|
@@ -169,7 +175,29 @@ export function doorRequestOf(request) {
|
|
|
169
175
|
request.headers.forEach((v, k) => { if (!k.startsWith("cf-") && k !== "cdn-loop")
|
|
170
176
|
headers[k] = v; });
|
|
171
177
|
headers.host = url.host;
|
|
172
|
-
|
|
178
|
+
const cf = request.cf;
|
|
179
|
+
const tls = cloudflareTls(cf);
|
|
180
|
+
// what every zone gets of the connection and of the address's network; the door's signal code checks their shape
|
|
181
|
+
const http = typeof cf?.httpProtocol === "string" && cf.httpProtocol.length <= 16 ? cf.httpProtocol : undefined;
|
|
182
|
+
const network = { ...(typeof cf?.asn === "number" ? { asn: cf.asn } : {}), ...(typeof cf?.asOrganization === "string" ? { organization: cf.asOrganization.slice(0, 256) } : {}) };
|
|
183
|
+
return { method: request.method, url: url.pathname + url.search, headers, transport: { secure: url.protocol === "https:", ...(tls ? { tls } : {}), ...(http ? { http } : {}), ...(Object.keys(network).length ? { network } : {}) }, socket: { remoteAddress: request.headers.get("cf-connecting-ip") ?? undefined } };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* What Cloudflare saw of the client's TLS handshake, for the door's TLS fingerprint: the JA4 where the zone has Bot
|
|
187
|
+
* Management, and the version, the cipher, the extensions hash, and the ClientHello length that every zone gets. Only
|
|
188
|
+
* strings of a bounded length are taken; the door's signal code checks their shape.
|
|
189
|
+
*/
|
|
190
|
+
export function cloudflareTls(cf) {
|
|
191
|
+
if (!cf || typeof cf !== "object")
|
|
192
|
+
return undefined;
|
|
193
|
+
const text = (v) => (typeof v === "string" && v !== "" && v.length <= 64 ? v : undefined);
|
|
194
|
+
const ja4 = text(cf.botManagement?.ja4);
|
|
195
|
+
const negotiated = text(cf.tlsVersion);
|
|
196
|
+
const cipher = text(cf.tlsCipher);
|
|
197
|
+
const extensionsSha1 = text(cf.tlsClientExtensionsSha1);
|
|
198
|
+
const length = typeof cf.tlsClientHelloLength === "number" ? cf.tlsClientHelloLength : /^\d{1,5}$/.test(text(cf.tlsClientHelloLength) ?? "") ? Number(cf.tlsClientHelloLength) : undefined;
|
|
199
|
+
const out = { ...(ja4 ? { ja4 } : {}), ...(negotiated ? { negotiated } : {}), ...(cipher ? { cipher } : {}), ...(extensionsSha1 ? { extensionsSha1 } : {}), ...(length !== undefined ? { helloLength: length } : {}) };
|
|
200
|
+
return Object.keys(out).length ? out : undefined;
|
|
173
201
|
}
|
|
174
202
|
/** Cloudflare Bot Management's score and verified-bot flag, when the zone has it and they are what Cloudflare documents; nothing otherwise. Cloudflare does not sign them: they enter as observed. */
|
|
175
203
|
export function cloudflareFacts(cf) {
|
|
@@ -228,7 +256,7 @@ export function createDoorWorker(options = {}) {
|
|
|
228
256
|
if (request.method === "GET" && url.pathname === FORM_SCRIPT_PATH) {
|
|
229
257
|
if (!cfg.challenge)
|
|
230
258
|
return answer(jsonAnswer(404, {}, { error: "this door has no challenge configured, so it has no form protector" }));
|
|
231
|
-
return new Response(formScript(cfg.challenge), { headers: { "content-type": "text/javascript; charset=utf-8", "cache-control": "public, max-age=300", "x-content-type-options": "nosniff" } });
|
|
259
|
+
return new Response(formScript(cfg.challenge, !!cfg.behaviour), { headers: { "content-type": "text/javascript; charset=utf-8", "cache-control": "public, max-age=300", "x-content-type-options": "nosniff" } });
|
|
232
260
|
}
|
|
233
261
|
if (!core.admit())
|
|
234
262
|
return answer(core.busy());
|
package/dist/door.js
CHANGED
|
@@ -48,6 +48,7 @@ export function nodeDoorIO(cfg, options = {}) {
|
|
|
48
48
|
return {
|
|
49
49
|
key,
|
|
50
50
|
trustedPrincipalKeys: cfg.trustedPrincipalKeys.map(loadPublicKey),
|
|
51
|
+
trustedRegistryKeys: cfg.trustedRegistryKeys.map(loadPublicKey),
|
|
51
52
|
// the bytes and the metadata come from one open file
|
|
52
53
|
readPolicy() {
|
|
53
54
|
const fd = openSync(cfg.policyFile, "r");
|
|
@@ -60,6 +61,21 @@ export function nodeDoorIO(cfg, options = {}) {
|
|
|
60
61
|
}
|
|
61
62
|
},
|
|
62
63
|
policySource: cfg.policyFile,
|
|
64
|
+
...(cfg.admissionLists ? {
|
|
65
|
+
readAdmission(known) {
|
|
66
|
+
const fd = openSync(cfg.admissionLists, "r");
|
|
67
|
+
try {
|
|
68
|
+
const st = fstatSync(fd);
|
|
69
|
+
const key = `${st.ino}:${st.mtimeMs}:${st.ctimeMs}:${st.size}`;
|
|
70
|
+
// a file of 64 full lists is tens of megabytes: it is read only when it has changed
|
|
71
|
+
return key === known ? { key } : { text: readFileSync(fd, "utf8"), key };
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
closeSync(fd);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
admissionSource: cfg.admissionLists,
|
|
78
|
+
} : {}),
|
|
63
79
|
revoked(chainDigests) {
|
|
64
80
|
try {
|
|
65
81
|
revocations.reload();
|
|
@@ -133,7 +149,7 @@ export async function createDoorHost(cfg, options = {}) {
|
|
|
133
149
|
handle,
|
|
134
150
|
flushOutbox: core.flushOutbox,
|
|
135
151
|
pendingReceipts: core.pendingReceipts,
|
|
136
|
-
formScript: () => (cfg.challenge ? formScript(cfg.challenge) : null),
|
|
152
|
+
formScript: () => (cfg.challenge ? formScript(cfg.challenge, !!cfg.behaviour) : null),
|
|
137
153
|
async close() {
|
|
138
154
|
core.close();
|
|
139
155
|
},
|
|
@@ -178,7 +194,7 @@ function createAuthzHost(cfg, options) {
|
|
|
178
194
|
handle,
|
|
179
195
|
flushOutbox: core.flushOutbox,
|
|
180
196
|
pendingReceipts: core.pendingReceipts,
|
|
181
|
-
formScript: () => (cfg.challenge ? formScript(cfg.challenge) : null),
|
|
197
|
+
formScript: () => (cfg.challenge ? formScript(cfg.challenge, !!cfg.behaviour) : null),
|
|
182
198
|
async close() {
|
|
183
199
|
core.close();
|
|
184
200
|
},
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ERC8004_REGISTRATION_TYPE = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
|
|
3
|
+
/** `eip155:<chainId>:<Identity Registry address>`, as ERC-8004 names a registry */
|
|
4
|
+
export declare const ERC8004_REGISTRY: RegExp;
|
|
5
|
+
export declare const Erc8004LinkSchema: z.ZodObject<{
|
|
6
|
+
agentRegistry: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
7
|
+
agentId: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type Erc8004Link = z.infer<typeof Erc8004LinkSchema>;
|
|
10
|
+
/** A link as the registry checked it: the token's owner and the block it read, and when. */
|
|
11
|
+
export interface Erc8004Checked extends Erc8004Link {
|
|
12
|
+
owner: string;
|
|
13
|
+
block: number;
|
|
14
|
+
/** sha256 of the registration file's bytes */
|
|
15
|
+
fileDigest: string;
|
|
16
|
+
checkedAt: string;
|
|
17
|
+
}
|
|
18
|
+
export type Erc8004Check = {
|
|
19
|
+
ok: true;
|
|
20
|
+
link: Erc8004Checked;
|
|
21
|
+
} | {
|
|
22
|
+
ok: false;
|
|
23
|
+
error: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The ERC-8004 link as the registry stores it and a passport carries it: the names and shapes only, so that the
|
|
2
|
+
// registry, and a door that reads a passport, need nothing that reads a chain.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
export const ERC8004_REGISTRATION_TYPE = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
|
|
5
|
+
/** `eip155:<chainId>:<Identity Registry address>`, as ERC-8004 names a registry */
|
|
6
|
+
export const ERC8004_REGISTRY = /^eip155:([1-9][0-9]{0,11}):(0x[0-9a-fA-F]{40})$/;
|
|
7
|
+
export const Erc8004LinkSchema = z.object({
|
|
8
|
+
agentRegistry: z.string().regex(ERC8004_REGISTRY, { message: "agentRegistry is eip155:<chain id>:<registry address>" }).transform((r) => r.toLowerCase()),
|
|
9
|
+
/** the token id, in decimal: a uint256 does not fit in a JSON number */
|
|
10
|
+
agentId: z.string().regex(/^(0|[1-9][0-9]{0,77})$/, { message: "agentId is the token id in decimal" }).refine((v) => !/^[0-9]+$/.test(v) || BigInt(v) < 2n ** 256n, { message: "agentId is not a uint256" }),
|
|
11
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { ERC8004_REGISTRATION_TYPE, ERC8004_REGISTRY, Erc8004LinkSchema, type Erc8004Check, type Erc8004Checked, type Erc8004Link } from "./erc8004-link.ts";
|
|
2
|
+
import { type Erc8004Check, type Erc8004Link } from "./erc8004-link.ts";
|
|
3
|
+
export interface Erc8004ResolverOptions {
|
|
4
|
+
/** a JSON-RPC URL for each chain id the registry reads; from the environment, since a provider's URL often carries its key */
|
|
5
|
+
rpc: Record<string, string>;
|
|
6
|
+
/** an https IPFS gateway (`https://ipfs.io`); without one an `ipfs://` registration file is refused */
|
|
7
|
+
ipfsGateway?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
maxFileBytes?: number;
|
|
10
|
+
/** for the JSON-RPC calls; the global fetch by default */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
/** fetches an https registration file; by default over node:https, refusing internal addresses and redirects. For tests */
|
|
13
|
+
fetchFile?: (url: string, o: {
|
|
14
|
+
timeoutMs: number;
|
|
15
|
+
maxBytes: number;
|
|
16
|
+
signal: AbortSignal;
|
|
17
|
+
}) => Promise<Buffer>;
|
|
18
|
+
}
|
|
19
|
+
export interface Erc8004Resolver {
|
|
20
|
+
/** the chain ids it has an RPC URL for */
|
|
21
|
+
chains: string[];
|
|
22
|
+
check(link: Erc8004Link, didKey: string, now?: Date): Promise<Erc8004Check>;
|
|
23
|
+
}
|
|
24
|
+
/** The string an ABI-encoded `string` return value holds; throws when the encoding does not hold together. */
|
|
25
|
+
export declare function decodeAbiString(hex: string, maxBytes: number): string;
|
|
26
|
+
export declare function createErc8004Resolver(o: Erc8004ResolverOptions): Erc8004Resolver;
|
package/dist/erc8004.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// An ERC-8004 identity for a registered agent. The registry links an agent to its token in an ERC-8004 Identity
|
|
2
|
+
// Registry only when the chain and the token's registration file agree with the registry's own entry: the token
|
|
3
|
+
// exists, its registration file is a v1 file that is active, names that very token among its registrations, and lists
|
|
4
|
+
// the agent's did:key as a DID service. The check runs on the registry, never at the door: a door reads the link from
|
|
5
|
+
// the passport the registry signed. The chain is read through JSON-RPC (eth_call at one block), and the file is
|
|
6
|
+
// fetched once, over https or through a configured IPFS gateway, with a timeout and a size cap, never from an internal
|
|
7
|
+
// address. ERC-8004 is a draft, so only the registration-v1 file type is accepted.
|
|
8
|
+
import { request as httpsRequest } from "node:https";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { sha256Hex } from "./crypto.js";
|
|
11
|
+
import { internalAddress, isAddressLiteral } from "./addresses.js";
|
|
12
|
+
import { publicOnlyLookup } from "./egress.js";
|
|
13
|
+
export { ERC8004_REGISTRATION_TYPE, ERC8004_REGISTRY, Erc8004LinkSchema } from "./erc8004-link.js";
|
|
14
|
+
import { ERC8004_REGISTRATION_TYPE, ERC8004_REGISTRY } from "./erc8004-link.js";
|
|
15
|
+
const OWNER_OF = "0x6352211e";
|
|
16
|
+
const TOKEN_URI = "0xc87b56dd";
|
|
17
|
+
const word = (n) => n.toString(16).padStart(64, "0");
|
|
18
|
+
class ChainError extends Error {
|
|
19
|
+
}
|
|
20
|
+
/** The string an ABI-encoded `string` return value holds; throws when the encoding does not hold together. */
|
|
21
|
+
export function decodeAbiString(hex, maxBytes) {
|
|
22
|
+
const h = hex.replace(/^0x/, "");
|
|
23
|
+
if (!/^[0-9a-f]*$/i.test(h) || h.length < 128)
|
|
24
|
+
throw new ChainError("the answer is not an ABI-encoded string");
|
|
25
|
+
const offset = Number.parseInt(h.slice(0, 64), 16) * 2;
|
|
26
|
+
const length = Number.parseInt(h.slice(offset, offset + 64), 16);
|
|
27
|
+
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset + 64 > h.length)
|
|
28
|
+
throw new ChainError("the answer is not an ABI-encoded string");
|
|
29
|
+
if (length > maxBytes)
|
|
30
|
+
throw new ChainError(`the token URI is longer than ${maxBytes} bytes`);
|
|
31
|
+
const data = h.slice(offset + 64, offset + 64 + length * 2);
|
|
32
|
+
if (data.length !== length * 2)
|
|
33
|
+
throw new ChainError("the answer is shorter than the string it encodes");
|
|
34
|
+
return Buffer.from(data, "hex").toString("utf8");
|
|
35
|
+
}
|
|
36
|
+
/** An https GET that never dials an internal address for a host name, follows no redirect, and stops at the size cap. */
|
|
37
|
+
function httpsFile(url, o) {
|
|
38
|
+
// an address literal is never looked up, so the lookup's filter does not see it
|
|
39
|
+
const host = new URL(url).hostname.replace(/^\[|\]$/g, "");
|
|
40
|
+
if (isAddressLiteral(host) && internalAddress(host))
|
|
41
|
+
return Promise.reject(new Error(`${host} is an internal address; the registry does not fetch from it`));
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const req = httpsRequest(url, { method: "GET", headers: { accept: "application/json" }, lookup: publicOnlyLookup(), timeout: o.timeoutMs, signal: o.signal }, (res) => {
|
|
44
|
+
if ((res.statusCode ?? 0) >= 300) {
|
|
45
|
+
res.resume();
|
|
46
|
+
return reject(new Error(`${url} answered ${res.statusCode}${res.headers.location ? `, a redirect, which the registry does not follow` : ""}`));
|
|
47
|
+
}
|
|
48
|
+
const chunks = [];
|
|
49
|
+
let size = 0;
|
|
50
|
+
res.on("data", (c) => {
|
|
51
|
+
size += c.length;
|
|
52
|
+
if (size > o.maxBytes) {
|
|
53
|
+
req.destroy();
|
|
54
|
+
reject(new Error(`${url} is larger than ${o.maxBytes} bytes`));
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
chunks.push(c);
|
|
58
|
+
});
|
|
59
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
60
|
+
res.on("error", reject);
|
|
61
|
+
});
|
|
62
|
+
req.on("timeout", () => req.destroy(new Error(`${url} did not answer within ${o.timeoutMs} ms`)));
|
|
63
|
+
req.on("error", reject);
|
|
64
|
+
req.end();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const RegistrationSchema = z.object({
|
|
68
|
+
type: z.literal(ERC8004_REGISTRATION_TYPE),
|
|
69
|
+
active: z.boolean(),
|
|
70
|
+
services: z.array(z.object({ name: z.string(), endpoint: z.string() }).passthrough()).max(256),
|
|
71
|
+
registrations: z.array(z.object({ agentId: z.union([z.string(), z.number()]), agentRegistry: z.string() }).passthrough()).max(256),
|
|
72
|
+
}).passthrough();
|
|
73
|
+
export function createErc8004Resolver(o) {
|
|
74
|
+
const timeoutMs = o.timeoutMs ?? 5_000;
|
|
75
|
+
const maxFileBytes = o.maxFileBytes ?? 64 * 1024;
|
|
76
|
+
const f = o.fetch ?? fetch;
|
|
77
|
+
const fetchFile = o.fetchFile ?? httpsFile;
|
|
78
|
+
// `timeout` on node:https is the socket's idle time, so a host that sends a byte now and then would never trip it;
|
|
79
|
+
// the whole fetch ends at the deadline, whatever the fetcher does with the signal
|
|
80
|
+
const fileWithin = (url) => {
|
|
81
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
82
|
+
const late = new Promise((_, reject) => {
|
|
83
|
+
const stop = () => reject(new Error(`${url} did not finish within ${timeoutMs} ms`));
|
|
84
|
+
if (signal.aborted)
|
|
85
|
+
stop();
|
|
86
|
+
else
|
|
87
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
88
|
+
});
|
|
89
|
+
return Promise.race([fetchFile(url, { timeoutMs, maxBytes: maxFileBytes, signal }), late]);
|
|
90
|
+
};
|
|
91
|
+
for (const [chain, url] of Object.entries(o.rpc)) {
|
|
92
|
+
if (!/^[1-9][0-9]{0,11}$/.test(chain))
|
|
93
|
+
throw new Error(`ERC-8004: "${chain}" is not a chain id`);
|
|
94
|
+
if (!/^https?:\/\//.test(url))
|
|
95
|
+
throw new Error(`ERC-8004: the RPC URL for chain ${chain} is not http(s)`);
|
|
96
|
+
}
|
|
97
|
+
if (o.ipfsGateway && !o.ipfsGateway.startsWith("https://"))
|
|
98
|
+
throw new Error("ERC-8004: the IPFS gateway must be https");
|
|
99
|
+
const gateway = o.ipfsGateway?.replace(/\/+$/, "");
|
|
100
|
+
const rpc = async (url, method, params) => {
|
|
101
|
+
let res;
|
|
102
|
+
try {
|
|
103
|
+
res = await f(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }), signal: AbortSignal.timeout(timeoutMs) });
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
throw new ChainError(`the chain's RPC could not be reached: ${e instanceof Error ? e.message : String(e)}`);
|
|
107
|
+
}
|
|
108
|
+
if (!res.ok)
|
|
109
|
+
throw new ChainError(`the chain's RPC answered ${res.status}`);
|
|
110
|
+
const body = (await res.json().catch(() => null));
|
|
111
|
+
if (body?.error)
|
|
112
|
+
throw new ChainError(`the chain refused ${method}: ${String(body.error.message ?? "no message").slice(0, 200)}`);
|
|
113
|
+
if (typeof body?.result !== "string")
|
|
114
|
+
throw new ChainError(`the chain's answer to ${method} is not a hex string`);
|
|
115
|
+
return body.result;
|
|
116
|
+
};
|
|
117
|
+
/** The registration file's bytes for a token URI: inline, over https, or through the IPFS gateway. */
|
|
118
|
+
const fileOf = async (uri) => {
|
|
119
|
+
const inline = /^data:application\/json(;charset=utf-8)?(;base64)?,(.*)$/is.exec(uri);
|
|
120
|
+
if (inline) {
|
|
121
|
+
const bytes = inline[2] ? Buffer.from(inline[3], "base64") : Buffer.from(decodeURIComponent(inline[3]), "utf8");
|
|
122
|
+
if (bytes.length > maxFileBytes)
|
|
123
|
+
throw new Error(`the inline registration file is larger than ${maxFileBytes} bytes`);
|
|
124
|
+
return bytes;
|
|
125
|
+
}
|
|
126
|
+
if (uri.startsWith("ipfs://")) {
|
|
127
|
+
if (!gateway)
|
|
128
|
+
throw new Error("the registration file is on IPFS, and this registry has no IPFS gateway configured");
|
|
129
|
+
const path = uri.slice("ipfs://".length).replace(/^ipfs\//, "");
|
|
130
|
+
const [cid, ...segments] = path.split("/");
|
|
131
|
+
// the token's owner writes this path: a "." or ".." segment would climb out of /ipfs/ to any path on the gateway
|
|
132
|
+
if (!cid || !/^[A-Za-z0-9]+$/.test(cid) || segments.some((p) => !/^[A-Za-z0-9._~-]+$/.test(p) || p === "." || p === ".."))
|
|
133
|
+
throw new Error("the IPFS URI is not a CID and a path of plain segments");
|
|
134
|
+
const prefix = `${new URL(gateway).pathname.replace(/\/+$/, "")}/ipfs/${cid}`;
|
|
135
|
+
const url = new URL(`${gateway}/ipfs/${path}`);
|
|
136
|
+
if (url.origin !== new URL(gateway).origin || (url.pathname !== prefix && !url.pathname.startsWith(`${prefix}/`)))
|
|
137
|
+
throw new Error("the IPFS URI leaves the gateway's /ipfs/ path");
|
|
138
|
+
return fileWithin(url.toString());
|
|
139
|
+
}
|
|
140
|
+
if (uri.startsWith("https://")) {
|
|
141
|
+
const u = new URL(uri);
|
|
142
|
+
if (u.username || u.password)
|
|
143
|
+
throw new Error("the registration file's URL carries credentials");
|
|
144
|
+
return fileWithin(u.toString());
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`the token URI is not https, ipfs, or an inline JSON data URI: ${uri.slice(0, 60)}`);
|
|
147
|
+
};
|
|
148
|
+
async function check(link, didKey, now = new Date()) {
|
|
149
|
+
const m = ERC8004_REGISTRY.exec(link.agentRegistry);
|
|
150
|
+
if (!m)
|
|
151
|
+
return { ok: false, error: "agentRegistry is not eip155:<chain id>:<registry address>" };
|
|
152
|
+
const [, chain, registry] = m;
|
|
153
|
+
const url = o.rpc[chain];
|
|
154
|
+
if (!url)
|
|
155
|
+
return { ok: false, error: `this registry reads no ERC-8004 registry on chain ${chain}; it reads chains ${Object.keys(o.rpc).join(", ") || "none"}` };
|
|
156
|
+
const token = word(BigInt(link.agentId));
|
|
157
|
+
try {
|
|
158
|
+
const blockHex = await rpc(url, "eth_blockNumber", []);
|
|
159
|
+
const block = Number.parseInt(blockHex, 16);
|
|
160
|
+
if (!Number.isSafeInteger(block))
|
|
161
|
+
throw new ChainError("the chain's block number is not a number");
|
|
162
|
+
let ownerWord;
|
|
163
|
+
try {
|
|
164
|
+
ownerWord = await rpc(url, "eth_call", [{ to: registry, data: `${OWNER_OF}${token}` }, blockHex]);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
if (e instanceof ChainError && e.message.startsWith("the chain refused"))
|
|
168
|
+
return { ok: false, error: `token ${link.agentId} does not exist in ${link.agentRegistry} (${e.message})` };
|
|
169
|
+
throw e;
|
|
170
|
+
}
|
|
171
|
+
const owner = `0x${ownerWord.replace(/^0x/, "").slice(-40)}`.toLowerCase();
|
|
172
|
+
if (!/^0x[0-9a-f]{40}$/.test(owner) || /^0x0{40}$/.test(owner))
|
|
173
|
+
return { ok: false, error: `token ${link.agentId} in ${link.agentRegistry} has no owner` };
|
|
174
|
+
const uri = decodeAbiString(await rpc(url, "eth_call", [{ to: registry, data: `${TOKEN_URI}${token}` }, blockHex]), Math.ceil(maxFileBytes * 1.4) + 64);
|
|
175
|
+
let bytes;
|
|
176
|
+
try {
|
|
177
|
+
bytes = await fileOf(uri.trim());
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
return { ok: false, error: `the registration file could not be read: ${e instanceof Error ? e.message : String(e)}` };
|
|
181
|
+
}
|
|
182
|
+
let raw;
|
|
183
|
+
try {
|
|
184
|
+
raw = JSON.parse(bytes.toString("utf8"));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return { ok: false, error: "the registration file is not JSON" };
|
|
188
|
+
}
|
|
189
|
+
const parsed = RegistrationSchema.safeParse(raw);
|
|
190
|
+
if (!parsed.success)
|
|
191
|
+
return { ok: false, error: `the registration file is not an ERC-8004 registration-v1 file: ${parsed.error.issues.slice(0, 3).map((i) => `${i.path.join(".") || "file"} ${i.message}`).join("; ")}` };
|
|
192
|
+
const file = parsed.data;
|
|
193
|
+
if (!file.active)
|
|
194
|
+
return { ok: false, error: "the registration file says the agent is not active" };
|
|
195
|
+
if (!file.registrations.some((r) => String(r.agentId) === link.agentId && r.agentRegistry.toLowerCase() === link.agentRegistry))
|
|
196
|
+
return { ok: false, error: `the registration file does not list token ${link.agentId} of ${link.agentRegistry} among its registrations` };
|
|
197
|
+
if (!file.services.some((s) => s.name === "DID" && s.endpoint === didKey))
|
|
198
|
+
return { ok: false, error: `the registration file lists no DID service with the agent's key ${didKey}` };
|
|
199
|
+
return { ok: true, link: { agentRegistry: link.agentRegistry, agentId: link.agentId, owner, block, fileDigest: sha256Hex(bytes), checkedAt: now.toISOString() } };
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
if (e instanceof ChainError)
|
|
203
|
+
return { ok: false, error: e.message };
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { chains: Object.keys(o.rpc), check };
|
|
208
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export { hecEvent, splunkExporter } from "./splunk.ts";
|
|
|
7
7
|
export { serveConsole, type ConsoleOptions, type RunningConsole } from "./console.ts";
|
|
8
8
|
export { checkConfig, formatFindings, type CheckFinding, type CheckOptions } from "./check.ts";
|
|
9
9
|
export { GRANT_HEADER, grantHeader, parseGrantHeader, serveHttp } from "./gateway-http.ts";
|
|
10
|
-
export { AGENT_HEADER, ARRIVAL_FACT, CLASS_HEADER, DOOR_DEFAULT_CAPTURE, DOOR_VERSION, MAX_CHALLENGE_TOKEN, RECEIPT_HEADER, RATE_BURST_MS, RATE_MINUTE_MS, cedarArgs, classifyArrival, createDoorHost, createRateTracker, matchRoute, normalizePath, remoteOf, serveDoor, signedRequestOf, verifyChallengeToken } from "./door.ts";
|
|
11
|
-
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, createMemoryNonceStore, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.ts";
|
|
10
|
+
export { AGENT_HEADER, ARRIVAL_FACT, CLASS_HEADER, DOOR_DEFAULT_CAPTURE, DOOR_VERSION, MAX_CHALLENGE_TOKEN, RECEIPT_HEADER, RATE_BURST_MS, RATE_MINUTE_MS, PASSPORT_COVERED, cedarArgs, classifyArrival, createDoorHost, createRateTracker, matchRoute, normalizePath, remoteOf, serveDoor, signedRequestOf, verifyChallengeToken } from "./door.ts";
|
|
11
|
+
export { DIRECTORY_MEDIA_TYPE, DIRECTORY_PATH, WEB_BOT_AUTH_TAG, agentOrigin, contentDigestMatches, createMemoryNonceStore, createWebBotAuthVerifier, jwkThumbprint, normalizeAuthority, parseDictionary, signatureBase } from "./web-bot-auth.ts";
|
|
12
12
|
export { DESTINATION_FACT, EGRESS_VERSION, PROXY_REALM, checkProxyCredential, createEgressHost, destinationName, normalizeHost, parseAuthority, publicOnlyLookup, serveEgress } from "./egress.ts";
|
|
13
13
|
export { internalAddress } from "./addresses.ts";
|
|
14
14
|
export { DRAFT_WARNING, draftEgressPolicy } from "./egress-draft.ts";
|
|
@@ -21,7 +21,15 @@ export type { PerathosCheck, PerathosOptions, PerathosReport } from "./perathos.
|
|
|
21
21
|
export { loadAcsGuardianConfig } from "./config.ts";
|
|
22
22
|
export type { AcsGuardianConfig } from "./config.ts";
|
|
23
23
|
export { FORM_SCRIPT_PATH, formScript } from "./door-form.ts";
|
|
24
|
-
export
|
|
24
|
+
export { FLAG_SIGNALS, FORM_REPORT_HEADER, createHistoryTracker, flagOf, observationOf, signalsOf } from "./door-signals.ts";
|
|
25
|
+
export type { ArrivalBehaviour, ArrivalFingerprint, FlagSignal, FormSignals, HeaderFingerprint, HistoryTracker, NavigationSignals, Observation, Signals, SourceHistory, TimingSignals, TlsFingerprint, TlsObservation } from "./door-signals.ts";
|
|
26
|
+
export { LABELS, LABEL_QUESTIONS, LABEL_USES, createMeasure, flagValues, formatMeasure, formatRate, intervalText, isName, labelsFromReceipts, measure, parseLabelledRecord, percent, rateOf, ratePercent, thresholds } from "./door-measure.ts";
|
|
27
|
+
export type { FlagMeasure, FlagValues, Label, LabelExport, LabelQuestion, LabelUse, LabelledRecord, Measure, MeasureResult, Rate, SetMeasure, SideMeasure } from "./door-measure.ts";
|
|
28
|
+
export { challengeLabels, DOOR_QUESTIONS, DoorLabelSchema, doorErrorRates, formatErrorRates, LABEL_SOURCES, parseLabels, readDoorArrivals, wilson } from "./door-error-rates.ts";
|
|
29
|
+
export type { DoorArrivals, DoorLabel, DoorQuestion, ErrorRateRow, LabelSource } from "./door-error-rates.ts";
|
|
30
|
+
export { buildDoorTestSet, DOOR_TEST_KINDS, formatTestKinds } from "./door-test-set.ts";
|
|
31
|
+
export type { DoorTestSet, TestKind } from "./door-test-set.ts";
|
|
32
|
+
export type { Arrival, ArrivalChallenge, ArrivalAdmission, ArrivalClass, ArrivalPassport, ArrivalRate, ChallengeCheck, Classified, DoorHost, DoorOptions, DoorRequest, DoorServerOptions, RateTracker, RateTrackerLimits, RunningDoor } from "./door.ts";
|
|
25
33
|
export type { NonceState, NonceStore, SignatureCheck, SignedRequest, WebBotAuthOptions, WebBotAuthVerifier } from "./web-bot-auth.ts";
|
|
26
34
|
export * from "./capture.ts";
|
|
27
35
|
export { A2A_CARD_PATH, A2A_RECEIPT_METADATA_KEY, A2A_STREAM_META_KEY, a2aUpstream, fetchAgentCard, serveA2a, textOf } from "./a2a.ts";
|
|
@@ -63,6 +71,12 @@ export * from "./operations.ts";
|
|
|
63
71
|
export * from "./crypto.ts";
|
|
64
72
|
export * from "./delegation.ts";
|
|
65
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";
|
|
75
|
+
export type { AgentEntry, Passport, PassportVerifyResult } from "./registry.ts";
|
|
76
|
+
export { AdmissionListsSchema, canonicalAgent, canonicalRegistry, compileAdmissionLists, LIST_NAME, MAX_LIST_ENTRIES, MAX_LISTS } from "./admission.ts";
|
|
77
|
+
export type { AdmissionEntry, AdmissionLists, ArrivalIdentity } from "./admission.ts";
|
|
78
|
+
export { createErc8004Resolver, decodeAbiString, ERC8004_REGISTRATION_TYPE, ERC8004_REGISTRY, Erc8004LinkSchema } from "./erc8004.ts";
|
|
79
|
+
export type { Erc8004Check, Erc8004Checked, Erc8004Link, Erc8004Resolver, Erc8004ResolverOptions } from "./erc8004.ts";
|
|
66
80
|
export * from "./approval.ts";
|
|
67
81
|
export * from "./approval-requests.ts";
|
|
68
82
|
export * from "./gateway.ts";
|