@agent-custody/receipts 0.16.9 → 0.16.11
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 +24 -9
- package/dist/approval-requests.d.ts +114 -0
- package/dist/approval-requests.js +198 -0
- package/dist/approval.d.ts +8 -0
- package/dist/approval.js +10 -3
- package/dist/check.js +2 -0
- package/dist/cli.js +96 -16
- package/dist/completeness.d.ts +28 -2
- package/dist/completeness.js +102 -9
- package/dist/config.d.ts +3 -0
- package/dist/config.js +6 -1
- package/dist/console-page.js +87 -2
- package/dist/console.js +72 -0
- package/dist/crypto.d.ts +2 -0
- package/dist/crypto.js +2 -1
- package/dist/delegation.d.ts +1 -1
- package/dist/delegation.js +19 -2
- package/dist/did-key.d.ts +11 -0
- package/dist/did-key.js +86 -0
- package/dist/door-app.d.ts +3 -0
- package/dist/door-app.js +10 -0
- package/dist/door-core.d.ts +373 -0
- package/dist/door-core.js +743 -0
- package/dist/door-form.d.ts +6 -0
- package/dist/door-form.js +97 -0
- package/dist/door-worker.d.ts +133 -0
- package/dist/door-worker.js +259 -0
- package/dist/door.d.ts +18 -294
- package/dist/door.js +62 -722
- package/dist/gateway-http.d.ts +1 -6
- package/dist/gateway-http.js +2 -19
- package/dist/gateway.js +24 -3
- package/dist/grant-header.d.ts +8 -0
- package/dist/grant-header.js +19 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -2
- package/dist/issue.d.ts +2 -16
- package/dist/issue.js +2 -12
- package/dist/log-http.d.ts +37 -0
- package/dist/log-http.js +74 -0
- package/dist/log-sink.d.ts +3 -37
- package/dist/log-sink.js +5 -71
- package/dist/log.d.ts +2 -27
- package/dist/log.js +2 -173
- package/dist/merkle.d.ts +27 -0
- package/dist/merkle.js +175 -0
- package/dist/object-issuer.d.ts +29 -0
- package/dist/object-issuer.js +172 -0
- package/dist/receipt-pending.d.ts +16 -0
- package/dist/receipt-pending.js +14 -0
- package/dist/web-bot-auth.d.ts +26 -6
- package/dist/web-bot-auth.js +116 -56
- package/docs/approvals.md +33 -0
- package/docs/completeness.md +82 -12
- package/docs/console.md +11 -4
- package/docs/door-middleware.md +11 -0
- package/docs/door-quickstart.md +53 -17
- package/docs/door-signals.md +5 -5
- package/docs/door-worker.md +81 -0
- package/docs/door.md +38 -8
- package/docs/github-action.md +2 -2
- package/docs/threat-model.md +1 -1
- package/docs/tutorials.md +5 -0
- package/docs/verification.md +1 -1
- package/package.json +3 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1645 -1549
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
import type { CaptureConfig } from "./capture.ts";
|
|
3
|
+
import type { DoorConfig, DoorRouteConfig } from "./config.ts";
|
|
4
|
+
import { type Envelope, type KeyPair, type PublicKeyRef } from "./crypto.ts";
|
|
5
|
+
import { type Delegation } from "./delegation.ts";
|
|
6
|
+
import type { Issuer } from "./issue.ts";
|
|
7
|
+
import { type FlushResult } from "./receipt-pending.ts";
|
|
8
|
+
import { type NonceStore, type SignatureCheck, type SignedRequest } from "./web-bot-auth.ts";
|
|
9
|
+
import { type ArrivalPartner } from "./door-partner.ts";
|
|
10
|
+
import type { AuthorizationBundle, ReceiptPredicate } from "./receipt.ts";
|
|
11
|
+
export declare const DOOR_VERSION = "0.1.0";
|
|
12
|
+
/** on every answer the door gives: the receipt that records the decision */
|
|
13
|
+
export declare const RECEIPT_HEADER = "x-agent-custody-receipt";
|
|
14
|
+
/** on every answer: `verified`, `claimed`, or `unknown`, what the door made of the arrival */
|
|
15
|
+
export declare const CLASS_HEADER = "x-agent-custody-class";
|
|
16
|
+
/** the fact the door records for every arrival, and the policy reads as `context.facts.arrival` */
|
|
17
|
+
export declare const ARRIVAL_FACT = "arrival";
|
|
18
|
+
/** the header an agent may use to name itself without a grant; recorded as claimed, never checked */
|
|
19
|
+
export declare const AGENT_HEADER = "x-agent-custody-agent";
|
|
20
|
+
/** in authz mode: the original request's method and target, as nginx `auth_request` and Envoy `ext_authz` are configured to send them */
|
|
21
|
+
export declare const ORIGINAL_METHOD_HEADER = "x-original-method";
|
|
22
|
+
export declare const ORIGINAL_URI_HEADER = "x-original-uri";
|
|
23
|
+
/** the reason an allowed authz receipt carries: the door decided, and the proxy, not the door, relays */
|
|
24
|
+
export declare const AUTHZ_ALLOWED_REASON = "allowed; the door answered the proxy's authz check and relays nothing: the proxy relays the request, and the door sees neither its body nor the origin's answer";
|
|
25
|
+
export type ArrivalClass = "verified" | "claimed" | "unknown";
|
|
26
|
+
/** What the door observed about one arrival. Every field is the door's own observation; none is the caller's claim about itself except `declared`, which says so. */
|
|
27
|
+
export interface Arrival {
|
|
28
|
+
class: ArrivalClass;
|
|
29
|
+
/** the agent named in a verified grant, else the signature agent of a verified signature, else the name the caller declared, else "unknown" */
|
|
30
|
+
subject: string;
|
|
31
|
+
/**
|
|
32
|
+
* What became of the grant header: a trusted grant in scope for this route, one out of scope, one that did not verify,
|
|
33
|
+
* one revoked (`revoked`: it, or a grant above it in its chain, is in `revokedGrants`, or that file cannot be read),
|
|
34
|
+
* one presented by another agent (`wrong-sender`: the request is signed by a signature agent, or a did:key, the grant does not name),
|
|
35
|
+
* or none.
|
|
36
|
+
*/
|
|
37
|
+
grant: "verified" | "out-of-scope" | "invalid" | "revoked" | "wrong-sender" | "absent";
|
|
38
|
+
grantError?: string;
|
|
39
|
+
/** What became of an RFC 9421 signature tagged `web-bot-auth`: see `SignatureCheck`. `unchecked` when the door has no `webBotAuth` config */
|
|
40
|
+
signature: SignatureCheck["outcome"];
|
|
41
|
+
/** the `Signature-Agent` origin, or the did:key that is the signature's keyid; checked only when `signature` is `verified` */
|
|
42
|
+
signatureAgent?: string;
|
|
43
|
+
/** the signature's keyid, the RFC 7638 thumbprint of the agent's key, or a did:key; checked only when `signature` is `verified` */
|
|
44
|
+
signatureKeyid?: string;
|
|
45
|
+
signatureError?: string;
|
|
46
|
+
/** the agent name from the `x-agent-custody-agent` header, when sent; a claim */
|
|
47
|
+
declared?: string;
|
|
48
|
+
remote: string;
|
|
49
|
+
method: string;
|
|
50
|
+
path: string;
|
|
51
|
+
route: string;
|
|
52
|
+
/** how often this source has arrived lately, counted by this door process; set by the door, absent from `classifyArrival` alone */
|
|
53
|
+
rate?: ArrivalRate;
|
|
54
|
+
/** what became of the challenge token, when the door is configured to challenge; absent otherwise, and from `classifyArrival` alone */
|
|
55
|
+
challenge?: ArrivalChallenge;
|
|
56
|
+
/** what became of the question to the partner engine, when the door asks one about this route; absent otherwise, and from `classifyArrival` alone. The verdict itself is the `partner` fact, present only when `outcome` is `verified` */
|
|
57
|
+
partner?: ArrivalPartner;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The outcome of a human challenge. `passed`: the provider confirmed the token, so the provider judged a person present
|
|
61
|
+
* at the time it was solved. `failed`: the provider refused it, with its error codes. `unavailable`: the provider did
|
|
62
|
+
* not answer in time. `absent`: no token was sent. A passed challenge does not change `class`: it says nothing about who
|
|
63
|
+
* the arrival is, only that a provider's test was passed in front of it.
|
|
64
|
+
*/
|
|
65
|
+
export interface ArrivalChallenge {
|
|
66
|
+
provider: "turnstile" | "hcaptcha";
|
|
67
|
+
outcome: "passed" | "failed" | "unavailable" | "absent";
|
|
68
|
+
error?: string;
|
|
69
|
+
}
|
|
70
|
+
/** a provider token is about 2 KB; a longer value is refused as failed without calling the provider */
|
|
71
|
+
export declare const MAX_CHALLENGE_TOKEN = 4096;
|
|
72
|
+
export interface ChallengeCheck {
|
|
73
|
+
provider: "turnstile" | "hcaptcha";
|
|
74
|
+
secret: string;
|
|
75
|
+
token: string;
|
|
76
|
+
/** the client's address, sent as `remoteip` only when the door knows it is the client's and not a proxy's */
|
|
77
|
+
remoteIp?: string;
|
|
78
|
+
/** the hostnames of the pages that render the widget, lowercase */
|
|
79
|
+
hostnames: string[];
|
|
80
|
+
/** the widget's action, when one is required (Turnstile) */
|
|
81
|
+
action?: string;
|
|
82
|
+
/** the public site key; sent to hCaptcha, whose secret belongs to the account, so a token from another of its site keys is refused */
|
|
83
|
+
siteKey?: string;
|
|
84
|
+
timeoutMs: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Asks the provider whether the token is good. The token and the secret go to the provider only; neither is recorded,
|
|
88
|
+
* and a redirect is never followed, since it would resend both to the Location's host. `success` is not enough: the
|
|
89
|
+
* token must have been issued on one of the site's own hostnames, and for the configured action, or a token solved on
|
|
90
|
+
* another site with this site key, or for another widget, would pass.
|
|
91
|
+
*/
|
|
92
|
+
export declare function verifyChallengeToken(check: ChallengeCheck, f: typeof fetch): Promise<ArrivalChallenge>;
|
|
93
|
+
/**
|
|
94
|
+
* Arrivals from one source in the last 10 seconds (`burst`) and 60 seconds (`minute`), this one included, whatever the
|
|
95
|
+
* policy decided about them. The source is the agent a verified grant names, else the arrival's address. One process's
|
|
96
|
+
* memory: the count starts at one when the door starts, and two doors do not share it.
|
|
97
|
+
*/
|
|
98
|
+
export interface ArrivalRate {
|
|
99
|
+
by: "agent" | "remote";
|
|
100
|
+
burst: number;
|
|
101
|
+
minute: number;
|
|
102
|
+
}
|
|
103
|
+
export declare const RATE_BURST_MS = 10000;
|
|
104
|
+
export declare const RATE_MINUTE_MS = 60000;
|
|
105
|
+
export interface RateTrackerLimits {
|
|
106
|
+
/** sources kept at once; past this the least recently seen is forgotten. Default 10000 */
|
|
107
|
+
maxSources?: number;
|
|
108
|
+
/** a source key longer than this is kept as its sha256. Default 256 */
|
|
109
|
+
maxKeyLength?: number;
|
|
110
|
+
/** false where a process-wide timer cannot run (a Worker): the sweep then runs from `hit`, at most once a minute. Default true */
|
|
111
|
+
sweepTimer?: boolean;
|
|
112
|
+
}
|
|
113
|
+
export interface RateTracker {
|
|
114
|
+
hit(source: string): {
|
|
115
|
+
burst: number;
|
|
116
|
+
minute: number;
|
|
117
|
+
};
|
|
118
|
+
/** sources kept now */
|
|
119
|
+
size(): number;
|
|
120
|
+
/** stops the sweep */
|
|
121
|
+
close(): void;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Counts arrivals per source over the two windows. Each source keeps its arrival times in order with two heads that only
|
|
125
|
+
* move forward, so one arrival costs the same however many came before it in the window; the array is compacted once
|
|
126
|
+
* half of it is behind the minute head. The source key comes from the arrival, and with `trustProxy` the client may
|
|
127
|
+
* choose it, so the map bounds itself: at most `maxSources` keys, none longer than `maxKeyLength`, and a source with no
|
|
128
|
+
* arrival in the last minute is dropped every minute whether or not traffic goes on. A source forgotten early counts
|
|
129
|
+
* again from 1, which only lowers what a pace rule sees for a client that floods the map. The clock is monotonic
|
|
130
|
+
* (`performance.now`), so a step of the wall clock (an NTP correction, a VM resume) neither keeps old arrivals inside
|
|
131
|
+
* the windows nor drops new ones; an injected clock that goes back is held at the last time seen. `now` is for tests.
|
|
132
|
+
*/
|
|
133
|
+
export declare function createRateTracker(now?: () => number, limits?: RateTrackerLimits): RateTracker;
|
|
134
|
+
export interface Classified {
|
|
135
|
+
arrival: Arrival;
|
|
136
|
+
/** set when the arrival is verified by a grant: the grant, as presented */
|
|
137
|
+
delegation?: {
|
|
138
|
+
envelope: Envelope;
|
|
139
|
+
grant: Delegation;
|
|
140
|
+
principalKeyid: string;
|
|
141
|
+
};
|
|
142
|
+
/** set when a verified signature names the arrival's agent: alone, or bound to the grant that names the same agent */
|
|
143
|
+
signer?: {
|
|
144
|
+
agent: string;
|
|
145
|
+
keyid: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The record of the call keeps what arrived; the policy reads a copy Cedar accepts. Cedar has no `null` and no
|
|
150
|
+
* non-integer number, and refuses the whole request on either, so a body with `"coupon": null` or `"price": 9.99` would
|
|
151
|
+
* be denied whatever the policy says. In the copy a `null` is dropped and a number that is not a safe integer becomes its
|
|
152
|
+
* string; a rule that compares `price` as a number then errors, and the call is denied by that rule rather than by Cedar.
|
|
153
|
+
*/
|
|
154
|
+
export declare function cedarArgs(value: unknown): unknown;
|
|
155
|
+
/**
|
|
156
|
+
* What a receipt records of an arrival when the config gives its route no capture rule: the method, the path, the
|
|
157
|
+
* recorded headers, and the body's size in clear; the query and the body withheld, each a salted commitment. A query can
|
|
158
|
+
* carry an API key and a form body a password. Set a rule for the route (or `"*"`) to record more in clear.
|
|
159
|
+
*/
|
|
160
|
+
export declare const DOOR_DEFAULT_CAPTURE: {
|
|
161
|
+
args: {
|
|
162
|
+
mode: "digest";
|
|
163
|
+
clear: string[];
|
|
164
|
+
};
|
|
165
|
+
result: {
|
|
166
|
+
mode: "clear";
|
|
167
|
+
};
|
|
168
|
+
facts: {
|
|
169
|
+
mode: "clear";
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* The path as the origin will read it: each segment percent-decoded once, so that `/%61dmin` falls under `/admin/*`, and
|
|
174
|
+
* empty segments merged, so that `//admin/users` and `/admin//users` fall under it too (nginx, Apache, and many
|
|
175
|
+
* frameworks merge them, and the origin would serve the admin page to an arrival the door matched as something else).
|
|
176
|
+
* A trailing slash is kept. Refused when a segment does not decode, or decodes to a slash, a backslash, or a dot
|
|
177
|
+
* segment: the origin would then read a path the door did not match. `relay` is the merged, decoded path encoded once
|
|
178
|
+
* more, the form the origin is sent, so the door and the origin read one path.
|
|
179
|
+
*/
|
|
180
|
+
export declare function normalizePath(pathname: string): {
|
|
181
|
+
path: string;
|
|
182
|
+
relay: string;
|
|
183
|
+
} | {
|
|
184
|
+
problem: string;
|
|
185
|
+
};
|
|
186
|
+
/** What the door reads of a request: its method, its target, its headers, and the socket's address. A Node `IncomingMessage` is one; the in-process door builds one from a fetch `Request`. */
|
|
187
|
+
export interface DoorRequest {
|
|
188
|
+
method?: string | undefined;
|
|
189
|
+
url?: string | undefined;
|
|
190
|
+
headers: IncomingHttpHeaders;
|
|
191
|
+
/** every value of each field, as Node keeps them; read for an HTTP message signature */
|
|
192
|
+
headersDistinct?: Record<string, string[] | undefined>;
|
|
193
|
+
socket: {
|
|
194
|
+
remoteAddress?: string | undefined;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The original request an authz check asks about, from `X-Original-Method` and `X-Original-URI`, with the check's own
|
|
199
|
+
* headers and address. The check request's own method and path are the proxy's (nginx sends GET to a fixed location),
|
|
200
|
+
* so both headers are required, and a check without them is refused rather than decided on the proxy's request.
|
|
201
|
+
*/
|
|
202
|
+
export declare function authzTarget(req: DoorRequest): DoorRequest | {
|
|
203
|
+
problem: string;
|
|
204
|
+
};
|
|
205
|
+
/** The route an arrival falls under: the first configured route whose methods and decoded path match, else the unmatched name. A trailing slash matches as no trailing slash. */
|
|
206
|
+
export declare function matchRoute(routes: DoorRouteConfig[], unmatched: string, method: string, pathname: string): string;
|
|
207
|
+
/**
|
|
208
|
+
* The arrival's address: the socket's, or with trustProxy the last address in `X-Forwarded-For`, the one the proxy in
|
|
209
|
+
* front of the door appended. Everything before it was sent by the client, which may write what it likes there.
|
|
210
|
+
*/
|
|
211
|
+
export declare function remoteOf(req: DoorRequest, trustProxy: boolean): string;
|
|
212
|
+
/**
|
|
213
|
+
* The request as RFC 9421 reads it: the target as received, the `Host` as the authority, and every value of each field.
|
|
214
|
+
* A request without `headersDistinct` (a fetch request, which joins repeated fields with ", ") gives each field's value as
|
|
215
|
+
* it holds it.
|
|
216
|
+
*/
|
|
217
|
+
export declare function signedRequestOf(req: DoorRequest): SignedRequest;
|
|
218
|
+
/**
|
|
219
|
+
* What the arrival presented, checked where it can be. A grant signed by a trusted principal, in its window, naming this
|
|
220
|
+
* route among its scopes, makes the arrival `verified` and its principal attested. A grant that is out of scope, expired,
|
|
221
|
+
* or signed by a stranger leaves the arrival `claimed`: it asserted an identity the door could not accept for this route.
|
|
222
|
+
* Without a grant, a Web Bot Auth signature the door verified (`signature`, from `createWebBotAuthVerifier`) makes the
|
|
223
|
+
* arrival `verified` as its signature agent. With both, the signature binds the grant to its sender when the grant names
|
|
224
|
+
* that signature agent; a grant presented under another agent's signature is `wrong-sender` and the arrival `claimed`.
|
|
225
|
+
* A signature by a did:key's own key binds a grant that names that did:key in the same way, and counts for nothing else.
|
|
226
|
+
* An `x-agent-custody-agent` header or a signature that did not verify alone is `claimed`. Nothing at all is `unknown`.
|
|
227
|
+
* Without `signature`, a `Signature-Input` header is recorded as `unchecked`. `revoked`, when given, says why a grant
|
|
228
|
+
* that verified is revoked (from its chain's digests, leaf first), or null when it is not; a revoked grant is `claimed`.
|
|
229
|
+
*/
|
|
230
|
+
export declare function classifyArrival(req: DoorRequest, trusted: PublicKeyRef[], route: string, trustProxy: boolean, at: string, signature?: SignatureCheck, revoked?: (chainDigests: string[]) => string | null): Classified;
|
|
231
|
+
/** The body as the door read it: whole, or how many bytes had arrived when it passed the limit. */
|
|
232
|
+
export type BodyRead = {
|
|
233
|
+
body: Buffer;
|
|
234
|
+
} | {
|
|
235
|
+
oversized: true;
|
|
236
|
+
bytes: number;
|
|
237
|
+
};
|
|
238
|
+
/** A fetch body, or how many bytes had arrived when it passed the limit; the rest is not read. */
|
|
239
|
+
export declare function readStream(stream: ReadableStream<Uint8Array> | null, max: number): Promise<BodyRead>;
|
|
240
|
+
/** The query as own properties: a parameter named `constructor` or `__proto__` is a parameter, never an inherited member or the prototype. */
|
|
241
|
+
export declare function queryOf(url: URL): Record<string, string | string[]>;
|
|
242
|
+
export type Execution = ReceiptPredicate["execution"];
|
|
243
|
+
type ReceiptHead = Omit<ReceiptPredicate, "session" | "model" | "execution" | "authorization">;
|
|
244
|
+
/** A fact the runtime observed for itself: the tool the receipt names as its source, and the value. Not signed by anyone: the door's own observation. */
|
|
245
|
+
export interface ObservedFact {
|
|
246
|
+
tool: string;
|
|
247
|
+
value: unknown;
|
|
248
|
+
}
|
|
249
|
+
/** One arrival as the door decided it, before anything was relayed or passed on. */
|
|
250
|
+
export interface DoorDecision {
|
|
251
|
+
receiptId: string;
|
|
252
|
+
arrival: Arrival;
|
|
253
|
+
method: string;
|
|
254
|
+
url: URL;
|
|
255
|
+
route: string;
|
|
256
|
+
/** the path decoded and encoded once, the form the origin is sent; absent when the path did not decode cleanly */
|
|
257
|
+
relay?: string;
|
|
258
|
+
/** the body, or null when it passed `maxBodyBytes` */
|
|
259
|
+
body: Buffer | null;
|
|
260
|
+
/** set when the door refuses the arrival: what the receipt records, and the status the arrival is answered */
|
|
261
|
+
refused?: {
|
|
262
|
+
execution: Execution;
|
|
263
|
+
status: number;
|
|
264
|
+
};
|
|
265
|
+
head: ReceiptHead;
|
|
266
|
+
authorization?: AuthorizationBundle;
|
|
267
|
+
}
|
|
268
|
+
/** An answer the door gives itself, in place of the origin's or the app's. */
|
|
269
|
+
export interface DoorAnswer {
|
|
270
|
+
status: number;
|
|
271
|
+
headers: Record<string, string>;
|
|
272
|
+
body: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The door's decision loop, shared by the proxy and the in-process door: classify the arrival, read its body, run the
|
|
276
|
+
* policy, commit the authorization of a request that can change something, and write the receipt once the outcome is
|
|
277
|
+
* known. What happens between the decision and the receipt, relaying to an origin or passing the request to the app in
|
|
278
|
+
* the same process, is the caller's.
|
|
279
|
+
*/
|
|
280
|
+
export interface DoorCore {
|
|
281
|
+
keyid: string;
|
|
282
|
+
policyDigest(): string;
|
|
283
|
+
/** false when `maxInFlight` arrivals are already being handled: answer `busy()` before the body is read. Every admitted arrival is released */
|
|
284
|
+
admit(): boolean;
|
|
285
|
+
release(): void;
|
|
286
|
+
busy(): DoorAnswer;
|
|
287
|
+
/**
|
|
288
|
+
* `framework`, when given, is the receipt's `issuer.framework` in place of the core's. `read` is null when the door never
|
|
289
|
+
* sees the body (an authz check): the receipt then records none. `observed` are facts the runtime saw for itself (a
|
|
290
|
+
* Worker's Cloudflare Bot Management score), by name: each enters the receipt labelled `observed` and the policy as
|
|
291
|
+
* `context.facts.<name>`. A name the door uses itself (`arrival`, `partner`) is refused.
|
|
292
|
+
*/
|
|
293
|
+
decide(req: DoorRequest, receiptId: string, read: ((max: number) => Promise<BodyRead>) | null, framework?: string, observed?: Record<string, ObservedFact>): Promise<DoorDecision>;
|
|
294
|
+
/** a header the door consumed and never passes on: the grant (and `Authorization` when it carried it), the declared agent, the challenge token */
|
|
295
|
+
consumed(name: string, req: DoorRequest, arrival: Arrival): boolean;
|
|
296
|
+
/** writes the receipt; null when it could not be written, after saying why on stderr */
|
|
297
|
+
record(d: DoorDecision, execution: Execution): Promise<{
|
|
298
|
+
logPending: boolean;
|
|
299
|
+
} | null>;
|
|
300
|
+
/** the door's headers on every answer */
|
|
301
|
+
mark(d: DoorDecision, logPending: boolean): Record<string, string>;
|
|
302
|
+
/** the answer to an arrival the door refused */
|
|
303
|
+
refusal(d: DoorDecision, logPending: boolean): DoorAnswer;
|
|
304
|
+
/** the answer when the receipt could not be written: what happened, so that nobody retries a refund that went through */
|
|
305
|
+
unrecorded(d: DoorDecision, execution: Execution, notSent: boolean): DoorAnswer;
|
|
306
|
+
flushOutbox(): Promise<FlushResult>;
|
|
307
|
+
pendingReceipts(): number;
|
|
308
|
+
close(): void;
|
|
309
|
+
}
|
|
310
|
+
/** A JSON answer the door gives itself, with the headers every such answer carries. */
|
|
311
|
+
export declare const jsonAnswer: (status: number, headers: Record<string, string>, body: unknown) => DoorAnswer;
|
|
312
|
+
/** What the door core needs from where it runs. The Node door reads its files and environment; a Worker reads its bindings. */
|
|
313
|
+
export interface DoorIO {
|
|
314
|
+
/** the key that signs the door's receipts */
|
|
315
|
+
key: KeyPair;
|
|
316
|
+
/** principal keys whose grants are a passport */
|
|
317
|
+
trustedPrincipalKeys: PublicKeyRef[];
|
|
318
|
+
/** 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 */
|
|
319
|
+
readPolicy(): {
|
|
320
|
+
text: string;
|
|
321
|
+
key: string;
|
|
322
|
+
};
|
|
323
|
+
/** names the policy in messages: its file, or the variable it came from */
|
|
324
|
+
policySource: string;
|
|
325
|
+
/** why a grant with these chain digests (leaf first) is revoked, or null when it is not. A list that cannot be read must revoke: return the reason */
|
|
326
|
+
revoked(chainDigests: string[]): string | null;
|
|
327
|
+
/** a secret by the name the config gives it (`captureKeyEnv`, `challenge.secretEnv`), or undefined when it is not set */
|
|
328
|
+
secret(name: string): string | undefined;
|
|
329
|
+
/** the receipt issuer, given the capture rules the core settled and the capture key */
|
|
330
|
+
issuer(capture: {
|
|
331
|
+
rules: CaptureConfig;
|
|
332
|
+
key: Buffer | undefined;
|
|
333
|
+
}): Issuer;
|
|
334
|
+
fetch: typeof fetch;
|
|
335
|
+
/** false where a process-wide timer cannot run (a Worker) */
|
|
336
|
+
timers: boolean;
|
|
337
|
+
/** where Web Bot Auth nonces are kept; this process's memory when absent */
|
|
338
|
+
nonceStore?: NonceStore;
|
|
339
|
+
}
|
|
340
|
+
/** The decision loop for a door config over the given I/O; `framework` is the receipt's `issuer.framework`. Throws when the config cannot be served. */
|
|
341
|
+
export declare function createDoorCoreWith(cfg: DoorConfig, io: DoorIO, framework: string, opts?: {
|
|
342
|
+
autoFlush?: boolean | undefined;
|
|
343
|
+
}): DoorCore;
|
|
344
|
+
/** Where the door relays an allowed arrival: the origin, the headers that are its credentials, and how long it may take. */
|
|
345
|
+
export interface OriginTarget {
|
|
346
|
+
url: URL;
|
|
347
|
+
headers: Record<string, string>;
|
|
348
|
+
timeoutMs: number;
|
|
349
|
+
/** `X-Forwarded-Proto` for an arrival not behind a trusted proxy: the scheme the door itself serves */
|
|
350
|
+
proto: string;
|
|
351
|
+
}
|
|
352
|
+
/** What became of the relay: the execution the receipt records, the origin's answer when it arrived whole, and whether the request never left the door. */
|
|
353
|
+
export interface Relayed {
|
|
354
|
+
execution: Execution;
|
|
355
|
+
answer?: {
|
|
356
|
+
status: number;
|
|
357
|
+
headers: Record<string, string | string[]>;
|
|
358
|
+
body: Buffer;
|
|
359
|
+
};
|
|
360
|
+
notSent: boolean;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Relays a decided arrival to the origin with fetch, unless the door refused it, and says what happened. Each arrival
|
|
364
|
+
* also holds the origin's answer (up to `maxResponseBytes`) in memory until it is answered.
|
|
365
|
+
*/
|
|
366
|
+
export declare function relayToOrigin(core: DoorCore, cfg: DoorConfig, d: DoorDecision, req: DoorRequest, origin: OriginTarget, f: typeof fetch): Promise<Relayed>;
|
|
367
|
+
/** The answer to a relayed arrival once its receipt is written: the refusal, the relay's failure, or the origin's answer with the door's headers. */
|
|
368
|
+
export declare function relayedAnswer(core: DoorCore, cfg: DoorConfig, d: DoorDecision, r: Relayed, logPending: boolean): {
|
|
369
|
+
status: number;
|
|
370
|
+
headers: Record<string, string | string[]>;
|
|
371
|
+
body: Buffer | string;
|
|
372
|
+
};
|
|
373
|
+
export {};
|