@bitspark/archon-server 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ /** How long a pending enrollment lives, in seconds, when the config names no ttl. */
2
+ export declare const ENROLL_DEFAULT_TTL_SECONDS = 300;
3
+ /** A pending enrollment: written once by `prepare`, persisted by the service, never changed —
4
+ * completion consumes it, it does not edit it. */
5
+ export interface EnrollmentRecord {
6
+ transaction: Uint8Array;
7
+ /** What authorized the enrollment: the session, or the bootstrap credential reserved to this
8
+ * record. An identifier, never a secret — a session's id, not its cookie — since the record
9
+ * is stored. */
10
+ authorization: Uint8Array;
11
+ /** The intended account, opaque to archon. */
12
+ account: Uint8Array;
13
+ purpose: string;
14
+ newKey: Uint8Array;
15
+ nonce: Uint8Array;
16
+ /** SHA-256 of the service's immutable intent bytes. */
17
+ intentDigest: Uint8Array;
18
+ /** Seconds since the epoch. */
19
+ expires: number;
20
+ }
21
+ /** What the client needs to prove: the record's public half and the audience. */
22
+ export interface EnrollmentChallenge {
23
+ transaction: Uint8Array;
24
+ nonce: Uint8Array;
25
+ purpose: string;
26
+ audience: string;
27
+ intentDigest: Uint8Array;
28
+ expires: number;
29
+ }
30
+ /** What the service supplies to `prepare`, after validating the authorizing credential. */
31
+ export interface EnrollmentBegin {
32
+ authorization: Uint8Array;
33
+ account: Uint8Array;
34
+ purpose: string;
35
+ newKey: Uint8Array;
36
+ /** The immutable intent bytes — what the service will record. archon binds their digest and
37
+ * never interprets them. A digest is not confidentiality: keep guessable account data out. */
38
+ intent: Uint8Array;
39
+ }
40
+ export type EnrollmentOutcome = "completed" | "notPending" | "unavailable";
41
+ /** The service's authorizing integration: its persistence of pending records and its atomic
42
+ * completion. */
43
+ export interface EnrollmentIntegration {
44
+ /** The record for `transaction`, or undefined when there is none. A throw means it cannot
45
+ * answer, and the completion fails closed. */
46
+ load(transaction: Uint8Array): EnrollmentRecord | undefined | Promise<EnrollmentRecord | undefined>;
47
+ /**
48
+ * The service's atomic business operation. In one persistence transaction it checks that
49
+ * `record` is still pending and its authorizing context still acceptable under the service's
50
+ * policy, records `record.newKey` as `record.account`'s for `record.purpose`, and consumes the
51
+ * record (and any bootstrap credential reserved to it). Concurrent calls for one record answer
52
+ * "completed" at most once.
53
+ */
54
+ complete(record: EnrollmentRecord): EnrollmentOutcome | Promise<EnrollmentOutcome>;
55
+ }
56
+ export interface EnrollerConfig {
57
+ /** The configured audience every binding is rebuilt from (docs/request.md §2). */
58
+ audience: string;
59
+ /** Required: without it, possession alone would suffice. */
60
+ integration: EnrollmentIntegration;
61
+ /** Seconds; defaults to ENROLL_DEFAULT_TTL_SECONDS. */
62
+ ttl?: number;
63
+ /** Seconds since the epoch; defaults to the system clock. */
64
+ clock?: () => number;
65
+ entropy?: (n: number) => Uint8Array;
66
+ }
67
+ /** Why a completion failed, with the HTTP status a service's route answers: 400 for a malformed
68
+ * completion, 401 for a proof that does not verify, 403 for a completion under another
69
+ * authorization, 404 for an unknown or expired transaction, 409 for one already completed or no
70
+ * longer eligible, 503 when the integration cannot answer. */
71
+ export declare class EnrollmentRefusal extends Error {
72
+ readonly status: number;
73
+ constructor(status: number, message: string);
74
+ }
75
+ /** Prepares and completes enrollments under one configuration. */
76
+ export declare class Enroller {
77
+ #private;
78
+ constructor(config: EnrollerConfig);
79
+ /** The pending record for `begin`, and the challenge to send the client. The service persists
80
+ * the record; nothing here stores it. */
81
+ prepare(begin: EnrollmentBegin): Promise<{
82
+ record: EnrollmentRecord;
83
+ challenge: EnrollmentChallenge;
84
+ }>;
85
+ /** Complete the enrollment `transaction` names, under `authorization`, with `proof`. Returns
86
+ * the completed record; throws an EnrollmentRefusal. */
87
+ complete(transaction: Uint8Array, proof: Uint8Array, authorization: Uint8Array): Promise<EnrollmentRecord>;
88
+ }
@@ -0,0 +1,157 @@
1
+ // The server's half of key enrollment (ADR 0010 §7; docs/request.md §6, version 1, fixed by
2
+ // ADR 0010's status note of 4 October 2026).
3
+ //
4
+ // An enrollment has a new key prove its own possession while a separate authority — the
5
+ // service's session, or a bootstrap credential — says whose key it is. The sdk holds the binding
6
+ // and the proof. This module holds what only a server can, in two halves:
7
+ //
8
+ // - `prepare` builds the PENDING RECORD, the immutable association of authorizing context,
9
+ // intended account, purpose, new key, a fresh nonce, the intent's digest and an expiry. The
10
+ // service calls it only after validating the session or bootstrap credential, persists the
11
+ // record in its own transaction (reserving a bootstrap credential to it atomically, when there
12
+ // is one), and sends the client the challenge.
13
+ // - `complete` takes what a completion request carries — the transaction id and the proof — and
14
+ // the authorization the service extracted from that request. It checks, in order: the record
15
+ // exists and has not expired; the same authorization began it; the proof verifies under the
16
+ // record's new key, over the binding rebuilt from the record and the configured audience. Only
17
+ // then does it call the integration's `complete`, the service's ATOMIC business operation: the
18
+ // key-account association recorded and the record consumed, in one persistence transaction.
19
+ // archon cannot promise that atomicity across a callback and a separate database (ADR 0010
20
+ // §7), so it does not pretend to: the operation is the service's.
21
+ //
22
+ // There is NO "possession alone suffices" mode: the constructor refuses a missing integration.
23
+ // Possession identifies a key; only the service's authority ties it to an account. And a
24
+ // completion cannot substitute anything: it names a record, and the account, key, purpose, nonce
25
+ // and intent all come from that record.
26
+ //
27
+ // archon defines no enrollment route. The service mounts completion wherever it serves its
28
+ // accounts, behind its own session and CSRF protection.
29
+ import { ENROLL_DIGEST_SIZE, ENROLL_MAX_TRANSACTION_SIZE, MIN_NONCE_SIZE, enrollBinding, verifyEnroll } from "@bitspark/archon-sdk";
30
+ /** How long a pending enrollment lives, in seconds, when the config names no ttl. */
31
+ export const ENROLL_DEFAULT_TTL_SECONDS = 300;
32
+ /** The generated transaction id's and nonce's size: the possession scheme's floor, and enough
33
+ * that an id is not guessable. */
34
+ const ID_SIZE = MIN_NONCE_SIZE;
35
+ /** Why a completion failed, with the HTTP status a service's route answers: 400 for a malformed
36
+ * completion, 401 for a proof that does not verify, 403 for a completion under another
37
+ * authorization, 404 for an unknown or expired transaction, 409 for one already completed or no
38
+ * longer eligible, 503 when the integration cannot answer. */
39
+ export class EnrollmentRefusal extends Error {
40
+ status;
41
+ constructor(status, message) {
42
+ super(message);
43
+ this.status = status;
44
+ }
45
+ }
46
+ function equal(a, b) {
47
+ if (a.length !== b.length)
48
+ return false;
49
+ let diff = 0;
50
+ for (let i = 0; i < a.length; i++)
51
+ diff |= a[i] ^ b[i];
52
+ return diff === 0;
53
+ }
54
+ function request(r) {
55
+ return { nonce: r.nonce, transaction: r.transaction, purpose: r.purpose, newKey: r.newKey, intentDigest: r.intentDigest };
56
+ }
57
+ /** Prepares and completes enrollments under one configuration. */
58
+ export class Enroller {
59
+ #audience;
60
+ #integration;
61
+ #ttl;
62
+ #clock;
63
+ #entropy;
64
+ constructor(config) {
65
+ if (config.integration === undefined || config.integration === null) {
66
+ throw new Error("enroll: an integration is required — possession identifies a key; only the service's authority ties it to an account");
67
+ }
68
+ // The binding's audience rules, checked once here rather than failing every completion.
69
+ enrollBinding(config.audience, {
70
+ nonce: new Uint8Array(ID_SIZE),
71
+ transaction: new Uint8Array(1),
72
+ purpose: "add-key",
73
+ newKey: new Uint8Array(32),
74
+ intentDigest: new Uint8Array(ENROLL_DIGEST_SIZE),
75
+ });
76
+ this.#audience = config.audience;
77
+ this.#integration = config.integration;
78
+ this.#ttl = config.ttl ?? ENROLL_DEFAULT_TTL_SECONDS;
79
+ this.#clock = config.clock ?? (() => Math.floor(Date.now() / 1000));
80
+ this.#entropy = config.entropy ?? ((n) => crypto.getRandomValues(new Uint8Array(n)));
81
+ }
82
+ /** The pending record for `begin`, and the challenge to send the client. The service persists
83
+ * the record; nothing here stores it. */
84
+ async prepare(begin) {
85
+ if (begin.authorization.length === 0)
86
+ throw new Error("enroll: an enrollment needs the authorization that began it");
87
+ if (begin.account.length === 0)
88
+ throw new Error("enroll: an enrollment needs the account it is for");
89
+ const intent = new Uint8Array(begin.intent);
90
+ const record = {
91
+ transaction: this.#entropy(ID_SIZE).slice(),
92
+ authorization: begin.authorization.slice(),
93
+ account: begin.account.slice(),
94
+ purpose: begin.purpose,
95
+ newKey: begin.newKey.slice(),
96
+ nonce: this.#entropy(ID_SIZE).slice(),
97
+ intentDigest: new Uint8Array(await crypto.subtle.digest("SHA-256", intent)),
98
+ expires: this.#clock() + this.#ttl,
99
+ };
100
+ // The sdk's binding rules, refused here rather than at completion.
101
+ enrollBinding(this.#audience, request(record));
102
+ return {
103
+ record,
104
+ challenge: {
105
+ transaction: record.transaction,
106
+ nonce: record.nonce,
107
+ purpose: record.purpose,
108
+ audience: this.#audience,
109
+ intentDigest: record.intentDigest,
110
+ expires: record.expires,
111
+ },
112
+ };
113
+ }
114
+ /** Complete the enrollment `transaction` names, under `authorization`, with `proof`. Returns
115
+ * the completed record; throws an EnrollmentRefusal. */
116
+ async complete(transaction, proof, authorization) {
117
+ if (transaction.length === 0 || transaction.length > ENROLL_MAX_TRANSACTION_SIZE) {
118
+ throw new EnrollmentRefusal(400, "enroll: malformed transaction id");
119
+ }
120
+ let record;
121
+ try {
122
+ record = await this.#integration.load(transaction);
123
+ }
124
+ catch {
125
+ throw new EnrollmentRefusal(503, "enroll: the integration cannot load");
126
+ }
127
+ if (record === undefined)
128
+ throw new EnrollmentRefusal(404, "enroll: unknown or expired transaction");
129
+ // A record for another transaction is an integration fault, and is never verified against.
130
+ if (!equal(record.transaction, transaction)) {
131
+ throw new EnrollmentRefusal(503, "enroll: the integration returned another transaction's record");
132
+ }
133
+ if (this.#clock() >= record.expires)
134
+ throw new EnrollmentRefusal(404, "enroll: unknown or expired transaction");
135
+ // The same authorization that began it — checked before the proof, so a stranger's
136
+ // completion learns nothing about it.
137
+ if (authorization.length === 0 || !equal(record.authorization, authorization)) {
138
+ throw new EnrollmentRefusal(403, "enroll: not the authorization that began this enrollment");
139
+ }
140
+ if (!verifyEnroll(this.#audience, request(record), proof)) {
141
+ throw new EnrollmentRefusal(401, "enroll: the proof does not verify");
142
+ }
143
+ let outcome;
144
+ try {
145
+ outcome = await this.#integration.complete(record);
146
+ }
147
+ catch {
148
+ outcome = "unavailable";
149
+ }
150
+ if (outcome === "completed")
151
+ return record;
152
+ if (outcome === "notPending")
153
+ throw new EnrollmentRefusal(409, "enroll: already completed or no longer eligible");
154
+ throw new EnrollmentRefusal(503, "enroll: the integration cannot complete");
155
+ }
156
+ }
157
+ //# sourceMappingURL=enroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enroll.js","sourceRoot":"","sources":["../../src/enroll.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,6CAA6C;AAC7C,EAAE;AACF,wFAAwF;AACxF,iGAAiG;AACjG,0EAA0E;AAC1E,EAAE;AACF,2FAA2F;AAC3F,8FAA8F;AAC9F,6FAA6F;AAC7F,iGAAiG;AACjG,iDAAiD;AACjD,gGAAgG;AAChG,+FAA+F;AAC/F,8FAA8F;AAC9F,iGAAiG;AACjG,iGAAiG;AACjG,8FAA8F;AAC9F,6FAA6F;AAC7F,oEAAoE;AACpE,EAAE;AACF,+FAA+F;AAC/F,yFAAyF;AACzF,iGAAiG;AACjG,wCAAwC;AACxC,EAAE;AACF,2FAA2F;AAC3F,wDAAwD;AACxD,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAsB,MAAM,sBAAsB,CAAC;AAExJ,qFAAqF;AACrF,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAE9C;mCACmC;AACnC,MAAM,OAAO,GAAG,cAAc,CAAC;AAwE/B;;;+DAG+D;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAE/B,MAAM;IADjB,YACW,MAAc,EACvB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;sBAHN,MAAM;IAIjB,CAAC;CACF;AAED,SAAS,KAAK,CAAC,CAAa,EAAE,CAAa;IACzC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IA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,IAAI,iBAAiB,CAAC,GAAG,EAAE,wCAAwC,CAAC,CAAC;QAChH,mFAAmF;QACnF,sCAAsC;QACtC,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,EAAE,CAAC;YAC9E,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,0DAA0D,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,mCAAmC,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,OAA0B,CAAC;QAC/B,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,aAAa,CAAC;QAC1B,CAAC;QACD,IAAI,OAAO,KAAK,WAAW;YAAE,OAAO,MAAM,CAAC;QAC3C,IAAI,OAAO,KAAK,YAAY;YAAE,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,iDAAiD,CAAC,CAAC;QAClH,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,yCAAyC,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -1,2 +1,4 @@
1
1
  export * from "./login.js";
2
+ export * from "./request.js";
3
+ export * from "./enroll.js";
2
4
  export { fromHex, MAX_BODY_BYTES, rfc3339, scanTopLevel, stripMount, toHex } from "./json.js";
package/dist/src/index.js CHANGED
@@ -7,6 +7,13 @@
7
7
  // them. It opens no socket, starts no timer, persists nothing, and interprets no authority:
8
8
  // that is ADR 0007 §B, and it is what makes the tier adoptable by a service that has already
9
9
  // chosen its stack.
10
+ //
11
+ // It also carries the server's half of request authentication (docs/request.md §7, version 1):
12
+ // a `RequestVerifier` in front of a replay store, under the same constraints. And the server's
13
+ // half of key enrollment (docs/request.md §6, version 1): an `Enroller` that cannot be built
14
+ // without the service's authorizing integration.
10
15
  export * from "./login.js";
16
+ export * from "./request.js";
17
+ export * from "./enroll.js";
11
18
  export { fromHex, MAX_BODY_BYTES, rfc3339, scanTopLevel, stripMount, toHex } from "./json.js";
12
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,EAAE;AACF,+FAA+F;AAC/F,qEAAqE;AACrE,uFAAuF;AACvF,0FAA0F;AAC1F,4FAA4F;AAC5F,6FAA6F;AAC7F,oBAAoB;AACpB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,EAAE;AACF,+FAA+F;AAC/F,qEAAqE;AACrE,uFAAuF;AACvF,0FAA0F;AAC1F,4FAA4F;AAC5F,6FAA6F;AAC7F,oBAAoB;AACpB,EAAE;AACF,+FAA+F;AAC/F,+FAA+F;AAC/F,6FAA6F;AAC7F,iDAAiD;AACjD,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,114 @@
1
+ import { type RequestPolicy, type VerifiedRequest } from "@bitspark/archon-sdk";
2
+ /** The largest body a verifier reads to recompute the digest. A larger one is refused, never
3
+ * truncated: a digest over part of a body verifies nothing. */
4
+ export declare const REQUEST_MAX_BODY_BYTES: number;
5
+ export type ReplayOutcome = "inserted" | "alreadyPresent" | "unavailable";
6
+ /** What a replay store remembers. Never the signature bytes: a signature is one spelling of a
7
+ * proof, the identifier is the proof's. */
8
+ export interface ReplayKey {
9
+ /** REQUEST_TAG. */
10
+ profile: string;
11
+ audience: string;
12
+ /** The canonical key text. */
13
+ principal: string;
14
+ /** Hex. */
15
+ nonce: string;
16
+ }
17
+ /** One insertion: the key, and the window in which any verifier could accept the proof — `from`
18
+ * is created − δ, `until` is expires + δ, both in seconds since the epoch. A store retains the
19
+ * key at least until `until`; `from` is what lets a store that lost its memory refuse proofs it
20
+ * might have seen. */
21
+ export interface ReplayEntry {
22
+ key: ReplayKey;
23
+ from: number;
24
+ until: number;
25
+ }
26
+ /**
27
+ * Makes a proof usable at most once. Requirements (ADR 0010 §5): one winner across every
28
+ * verifier in the acceptance scope — concurrent inserts of one key return "inserted" at most
29
+ * once; a key retained at least until its `until`, when no verifier can still accept the proof;
30
+ * and a store that cannot guarantee both answers "unavailable" rather than "inserted".
31
+ */
32
+ export interface ReplayStore {
33
+ insertIfAbsent(entry: ReplayEntry): ReplayOutcome | Promise<ReplayOutcome>;
34
+ }
35
+ /**
36
+ * The reference ReplayStore: one process, in memory. It is correct for exactly one verifier
37
+ * process, and its RESTART POLICY is what makes it correct across a restart at all (ADR 0010 §5:
38
+ * losing accepted identifiers reopens old proofs).
39
+ *
40
+ * A proof is acceptable from `entry.from` (created − δ). A process started at `start` cannot know
41
+ * what an earlier process accepted, so it admits only proofs whose window opened at or after
42
+ * `start`, and answers "unavailable" for anything older — waiting out, rather than guessing about,
43
+ * the proofs a previous incarnation could have seen. A deployment with more than one verifier, or
44
+ * that cannot afford the wait, supplies a shared store with the same contract.
45
+ */
46
+ export declare class MemoryReplayStore implements ReplayStore {
47
+ #private;
48
+ readonly start: number;
49
+ /** `start`: when this incarnation began, in seconds since the epoch. */
50
+ constructor(start: number);
51
+ insertIfAbsent(entry: ReplayEntry): ReplayOutcome;
52
+ /** Forgets every identifier whose `until` is not after `now`, and returns how many. Optional
53
+ * and caller-driven: nothing here starts a timer, and retaining a key longer is always safe. */
54
+ sweep(now: number): number;
55
+ }
56
+ /** ADR 0010 §6's `AuthenticatedRequest`: a request that verified and was admitted by the replay
57
+ * store — the principal, and the request descriptor authentication verified. Authorization
58
+ * evaluates this, not a re-parse. (Go and Rust name it `request.Authenticated`, as the sdk names
59
+ * `VerifiedRequest` `request.Verified` there: the module supplies the noun.) */
60
+ export type AuthenticatedRequest = VerifiedRequest;
61
+ /** Why a request was not authenticated, with the HTTP status to answer: 400 for a request the
62
+ * profile does not accept as transported, 401 for one that does not authenticate, 413 for an
63
+ * oversized body, 503 when the replay store is unavailable. */
64
+ export declare class RequestRefusal extends Error {
65
+ readonly status: number;
66
+ constructor(status: number, message: string);
67
+ }
68
+ /** A request as received: the method, the raw request-target, every header field in order, the
69
+ * body after transfer framing, and the trailer fields (any is refused in v1). */
70
+ export interface RawRequest {
71
+ method: string;
72
+ requestTarget: string;
73
+ headers: ReadonlyArray<readonly [string, string]>;
74
+ body: Uint8Array;
75
+ trailers?: ReadonlyArray<readonly [string, string]>;
76
+ }
77
+ /** The shape of node:http's IncomingMessage that `readNodeRequest` reads — structural, so this
78
+ * package depends on no server. */
79
+ export interface NodeRequestLike extends AsyncIterable<Uint8Array | string> {
80
+ method?: string | undefined;
81
+ url?: string | undefined;
82
+ rawHeaders: string[];
83
+ rawTrailers: string[];
84
+ }
85
+ /** Read a node:http request as received: its raw request-target, its raw header lines, its body
86
+ * (refused, not truncated, past REQUEST_MAX_BODY_BYTES) and its trailers.
87
+ *
88
+ * Past the limit it keeps no more bytes but reads on to the end, as node:http itself drains an
89
+ * unread body: abandoning the stream would destroy the socket, and the client would get a reset
90
+ * instead of the 413. The server's request timeout bounds how long that can take. */
91
+ export declare function readNodeRequest(req: NodeRequestLike): Promise<RawRequest>;
92
+ export interface VerifierConfig {
93
+ policy: RequestPolicy;
94
+ store: ReplayStore;
95
+ /** Seconds since the epoch; defaults to the system clock. */
96
+ clock?: () => number;
97
+ }
98
+ /** Authenticates requests under one policy against one replay store. */
99
+ export declare class RequestVerifier {
100
+ #private;
101
+ constructor(config: VerifierConfig);
102
+ /** Authenticate a request as received. Throws a RequestRefusal. */
103
+ authenticateRaw(raw: RawRequest): Promise<AuthenticatedRequest>;
104
+ /** Authenticate a fetch Request — the normalised request a fetch application routes on — and
105
+ * return the body it read alongside. Throws a RequestRefusal. */
106
+ authenticate(request: Request): Promise<{
107
+ auth: AuthenticatedRequest;
108
+ body: Uint8Array<ArrayBuffer>;
109
+ }>;
110
+ /** The fetch-style middleware: authenticate every request before `next` sees it. A refused
111
+ * request never reaches `next`; it is answered with the refusal's status and a one-line reason.
112
+ * `next` gets a fresh Request carrying the body that was verified. */
113
+ guard(next: (request: Request, auth: AuthenticatedRequest) => Response | Promise<Response>): (request: Request) => Promise<Response>;
114
+ }
@@ -0,0 +1,242 @@
1
+ // The server's half of request authentication (ADR 0010 §5–§6; docs/request.md §7 steps 8–9,
2
+ // version 1, fixed by ADR 0010's status note of 4 October 2026).
3
+ //
4
+ // The sdk's verifyRequest checks a proof: one spelling, the coverage, the audience echo, the
5
+ // digest, freshness and the signature. It does not remember. This module adds what only a
6
+ // server can: the HTTP extraction, the clock, and the REPLAY STORE — the one operation that makes
7
+ // a proof usable at most once:
8
+ //
9
+ // insertIfAbsent({key: (profile, audience, principal, nonce), from, until}) → inserted | alreadyPresent | unavailable
10
+ //
11
+ // A request reaches the application only as an AuthenticatedRequest, and only after a proof verified
12
+ // AND its identifier was inserted. `alreadyPresent` is a replay; `unavailable` FAILS CLOSED — a
13
+ // store that cannot answer, or throws, is never permission to skip the check.
14
+ //
15
+ // Two ways in, because a fetch-style Request has already lost the request line:
16
+ //
17
+ // - `authenticateRaw` takes the request as received. `readNodeRequest` builds one from
18
+ // node:http's IncomingMessage — its raw `url` and `rawHeaders` — so a Node server verifies
19
+ // exactly what arrived, as the Go and Rust lanes do.
20
+ // - `authenticate` (and `guard`) take a fetch Request, and verify against its URL's pathname and
21
+ // search. The WHATWG URL parser has normalised those (dot segments resolved, `\` read as `/`,
22
+ // some characters percent-encoded), and a Headers object has joined repeated fields with ", ".
23
+ // That normalised request is the only one a fetch application ever sees and routes on, so it is
24
+ // the one verified: what authentication checked and what authorization evaluates stay the same
25
+ // request. A proof signed over any other spelling is refused.
26
+ //
27
+ // Like the login handler, nothing here opens a socket, starts a timer or depends on a framework.
28
+ import { REQUEST_TAG, verifyRequest } from "@bitspark/archon-sdk";
29
+ /** The largest body a verifier reads to recompute the digest. A larger one is refused, never
30
+ * truncated: a digest over part of a body verifies nothing. */
31
+ export const REQUEST_MAX_BODY_BYTES = 1 << 20;
32
+ /**
33
+ * The reference ReplayStore: one process, in memory. It is correct for exactly one verifier
34
+ * process, and its RESTART POLICY is what makes it correct across a restart at all (ADR 0010 §5:
35
+ * losing accepted identifiers reopens old proofs).
36
+ *
37
+ * A proof is acceptable from `entry.from` (created − δ). A process started at `start` cannot know
38
+ * what an earlier process accepted, so it admits only proofs whose window opened at or after
39
+ * `start`, and answers "unavailable" for anything older — waiting out, rather than guessing about,
40
+ * the proofs a previous incarnation could have seen. A deployment with more than one verifier, or
41
+ * that cannot afford the wait, supplies a shared store with the same contract.
42
+ */
43
+ export class MemoryReplayStore {
44
+ start;
45
+ #seen = new Map();
46
+ /** `start`: when this incarnation began, in seconds since the epoch. */
47
+ constructor(start) {
48
+ this.start = start;
49
+ }
50
+ insertIfAbsent(entry) {
51
+ if (entry.from < this.start)
52
+ return "unavailable";
53
+ const k = JSON.stringify([entry.key.profile, entry.key.audience, entry.key.principal, entry.key.nonce]);
54
+ if (this.#seen.has(k))
55
+ return "alreadyPresent";
56
+ this.#seen.set(k, entry.until);
57
+ return "inserted";
58
+ }
59
+ /** Forgets every identifier whose `until` is not after `now`, and returns how many. Optional
60
+ * and caller-driven: nothing here starts a timer, and retaining a key longer is always safe. */
61
+ sweep(now) {
62
+ let n = 0;
63
+ for (const [k, until] of this.#seen) {
64
+ if (until <= now) {
65
+ this.#seen.delete(k);
66
+ n++;
67
+ }
68
+ }
69
+ return n;
70
+ }
71
+ }
72
+ /** Why a request was not authenticated, with the HTTP status to answer: 400 for a request the
73
+ * profile does not accept as transported, 401 for one that does not authenticate, 413 for an
74
+ * oversized body, 503 when the replay store is unavailable. */
75
+ export class RequestRefusal extends Error {
76
+ status;
77
+ constructor(status, message) {
78
+ super(message);
79
+ this.status = status;
80
+ }
81
+ }
82
+ function pairs(flat) {
83
+ const out = [];
84
+ for (let i = 0; i + 1 < flat.length; i += 2)
85
+ out.push([flat[i], flat[i + 1]]);
86
+ return out;
87
+ }
88
+ function concat(chunks, total) {
89
+ const out = new Uint8Array(total);
90
+ let at = 0;
91
+ for (const c of chunks) {
92
+ out.set(c, at);
93
+ at += c.length;
94
+ }
95
+ return out;
96
+ }
97
+ function tooLarge() {
98
+ return new RequestRefusal(413, "request: the body is over the verifier's limit");
99
+ }
100
+ /** Read a node:http request as received: its raw request-target, its raw header lines, its body
101
+ * (refused, not truncated, past REQUEST_MAX_BODY_BYTES) and its trailers.
102
+ *
103
+ * Past the limit it keeps no more bytes but reads on to the end, as node:http itself drains an
104
+ * unread body: abandoning the stream would destroy the socket, and the client would get a reset
105
+ * instead of the 413. The server's request timeout bounds how long that can take. */
106
+ export async function readNodeRequest(req) {
107
+ const chunks = [];
108
+ let total = 0;
109
+ for await (const chunk of req) {
110
+ const bytes = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
111
+ total += bytes.length;
112
+ if (total > REQUEST_MAX_BODY_BYTES) {
113
+ chunks.length = 0;
114
+ continue;
115
+ }
116
+ chunks.push(bytes);
117
+ }
118
+ if (total > REQUEST_MAX_BODY_BYTES)
119
+ throw tooLarge();
120
+ return {
121
+ method: req.method ?? "",
122
+ requestTarget: req.url ?? "",
123
+ headers: pairs(req.rawHeaders),
124
+ body: concat(chunks, total),
125
+ trailers: pairs(req.rawTrailers),
126
+ };
127
+ }
128
+ async function readBounded(body) {
129
+ if (body === null)
130
+ return new Uint8Array(0);
131
+ const reader = body.getReader();
132
+ const chunks = [];
133
+ let total = 0;
134
+ for (;;) {
135
+ const { done, value } = await reader.read();
136
+ if (done)
137
+ break;
138
+ total += value.length;
139
+ if (total > REQUEST_MAX_BODY_BYTES) {
140
+ await reader.cancel().catch(() => { });
141
+ throw tooLarge();
142
+ }
143
+ chunks.push(value);
144
+ }
145
+ return concat(chunks, total);
146
+ }
147
+ /** Authenticates requests under one policy against one replay store. */
148
+ export class RequestVerifier {
149
+ #policy;
150
+ #store;
151
+ #clock;
152
+ constructor(config) {
153
+ this.#policy = config.policy;
154
+ this.#store = config.store;
155
+ this.#clock = config.clock ?? (() => Math.floor(Date.now() / 1000));
156
+ }
157
+ /** Authenticate a request as received. Throws a RequestRefusal. */
158
+ async authenticateRaw(raw) {
159
+ if (raw.body.length > REQUEST_MAX_BODY_BYTES)
160
+ throw tooLarge();
161
+ // v1 accepts no content coding and no trailers (ADR 0010 §4): the digest is over the content
162
+ // as received, and a coded body would make "as received" ambiguous.
163
+ if (raw.headers.some(([n]) => n.toLowerCase() === "content-encoding") || (raw.trailers?.length ?? 0) > 0) {
164
+ throw new RequestRefusal(400, "request: content codings and trailers are not accepted in v1");
165
+ }
166
+ let verified;
167
+ try {
168
+ verified = verifyRequest(this.#policy, this.#clock(), {
169
+ method: raw.method,
170
+ requestTarget: raw.requestTarget,
171
+ headers: raw.headers,
172
+ body: raw.body,
173
+ });
174
+ }
175
+ catch (e) {
176
+ throw new RequestRefusal(401, e instanceof Error ? e.message : String(e));
177
+ }
178
+ // Only now, after the proof and its freshness verified (ADR 0010 §5: verify before
179
+ // inserting), is the identifier remembered — until no verifier can still accept it.
180
+ let outcome;
181
+ try {
182
+ outcome = await this.#store.insertIfAbsent({
183
+ key: {
184
+ profile: REQUEST_TAG,
185
+ audience: this.#policy.audience,
186
+ principal: verified.keyText,
187
+ nonce: Array.from(verified.nonce, (b) => b.toString(16).padStart(2, "0")).join(""),
188
+ },
189
+ from: verified.created - this.#policy.skew,
190
+ until: verified.expires + this.#policy.skew,
191
+ });
192
+ }
193
+ catch {
194
+ outcome = "unavailable";
195
+ }
196
+ if (outcome === "inserted")
197
+ return verified;
198
+ if (outcome === "alreadyPresent")
199
+ throw new RequestRefusal(401, "request: replayed");
200
+ throw new RequestRefusal(503, "request: the replay store is unavailable");
201
+ }
202
+ /** Authenticate a fetch Request — the normalised request a fetch application routes on — and
203
+ * return the body it read alongside. Throws a RequestRefusal. */
204
+ async authenticate(request) {
205
+ const body = await readBounded(request.body);
206
+ const url = new URL(request.url);
207
+ const auth = await this.authenticateRaw({
208
+ method: request.method,
209
+ requestTarget: url.pathname + url.search,
210
+ headers: [...request.headers],
211
+ body,
212
+ });
213
+ return { auth, body };
214
+ }
215
+ /** The fetch-style middleware: authenticate every request before `next` sees it. A refused
216
+ * request never reaches `next`; it is answered with the refusal's status and a one-line reason.
217
+ * `next` gets a fresh Request carrying the body that was verified. */
218
+ guard(next) {
219
+ return async (request) => {
220
+ let verified;
221
+ try {
222
+ verified = await this.authenticate(request);
223
+ }
224
+ catch (e) {
225
+ const status = e instanceof RequestRefusal ? e.status : 401;
226
+ return new Response(`${e instanceof Error ? e.message : String(e)}\n`, {
227
+ status,
228
+ headers: { "content-type": "text/plain; charset=utf-8" },
229
+ });
230
+ }
231
+ const bodiless = request.method === "GET" || request.method === "HEAD";
232
+ const forward = new Request(request.url, {
233
+ method: request.method,
234
+ headers: request.headers,
235
+ body: bodiless ? null : verified.body,
236
+ signal: request.signal,
237
+ });
238
+ return next(forward, verified.auth);
239
+ };
240
+ }
241
+ }
242
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,iEAAiE;AACjE,EAAE;AACF,6FAA6F;AAC7F,0FAA0F;AAC1F,kGAAkG;AAClG,+BAA+B;AAC/B,EAAE;AACF,wHAAwH;AACxH,EAAE;AACF,qGAAq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,KAAK,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC;YACvE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE;gBACvC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI;gBACrC,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitspark/archon-server",
3
- "version": "0.9.0",
4
- "description": "archon login: the service-side handler — four routes, law-free, store-minimal. A fetch-style handler that opens no socket.",
3
+ "version": "0.10.1",
4
+ "description": "archon's service side: the login handler (four routes, law-free, store-minimal), the request profile's verifier with its replay store, and key enrollment's server half. Fetch-style; opens no socket.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -22,8 +22,8 @@
22
22
  "test": "tsc -p tsconfig.json && node --test dist/test/*.test.js"
23
23
  },
24
24
  "dependencies": {
25
- "@bitspark/archon": "^0.9.0",
26
- "@bitspark/archon-sdk": "^0.9.0"
25
+ "@bitspark/archon": "^0.10.1",
26
+ "@bitspark/archon-sdk": "^0.10.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^26",