@crubal/host 0.0.0-stage → 0.4.0

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,29 @@
1
+ import type { Caller } from "./host.ts";
2
+ export type Jwk = {
3
+ kty: string;
4
+ kid?: string;
5
+ alg?: string;
6
+ [k: string]: unknown;
7
+ };
8
+ export type OidcOptions = {
9
+ /** The token's `iss`. */
10
+ issuer: string;
11
+ /** The token's `aud`, when the provider sets one (Supabase: `authenticated`). */
12
+ audience?: string;
13
+ /** The issuer's JWKS, or how to fetch it; `${issuer}/.well-known/jwks.json` otherwise. */
14
+ jwks?: Jwk[] | (() => Promise<Jwk[]>);
15
+ /** A shared secret for HS256 tokens (a legacy Supabase project). */
16
+ secret?: string;
17
+ /** The provider's name in the host's identity links. */
18
+ provider: string;
19
+ /** The clock, for `exp`. */
20
+ now?: () => number;
21
+ /** The subject → caller link; the host's identities table. */
22
+ identity: (provider: string, subject: string) => Promise<Caller | null>;
23
+ };
24
+ /** Verify a compact JWS and return its claims, or null. */
25
+ export declare function verifyJwt(token: string, o: Omit<OidcOptions, "provider" | "identity">): Promise<{
26
+ [claim: string]: unknown;
27
+ } | null>;
28
+ /** A verifier for `HostOptions.verifiers`: a valid token's subject becomes the caller its link names. */
29
+ export declare function oidcVerifier(o: OidcOptions): (token: string) => Promise<Caller | null>;
@@ -0,0 +1,74 @@
1
+ // oidc.ts: a verifier for bearer tokens an identity provider issued (docs/design/host.md, "Inbound"). A JWT
2
+ // is checked against the issuer's keys (its JWKS, or a shared secret for HS256), its issuer, audience and
3
+ // expiry; the subject is then looked up in the host's identity links, and the store sees only the caller.
4
+ // Supabase Auth is one such issuer; so is any OIDC provider.
5
+ import { createHmac, createPublicKey, timingSafeEqual, verify as cryptoVerify } from "node:crypto";
6
+ const b64 = (s) => Buffer.from(s.replace(/-/g, "+").replace(/_/g, "/"), "base64");
7
+ /** Verify a compact JWS and return its claims, or null. */
8
+ export async function verifyJwt(token, o) {
9
+ const parts = token.split(".");
10
+ if (parts.length !== 3)
11
+ return null;
12
+ const [h, p, s] = parts;
13
+ let header;
14
+ let claims;
15
+ try {
16
+ header = JSON.parse(b64(h).toString("utf8"));
17
+ claims = JSON.parse(b64(p).toString("utf8"));
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ const signed = Buffer.from(`${h}.${p}`);
23
+ const sig = b64(s);
24
+ let ok = false;
25
+ if (header.alg === "HS256") {
26
+ if (!o.secret)
27
+ return null;
28
+ const mac = createHmac("sha256", o.secret).update(signed).digest();
29
+ ok = mac.length === sig.length && timingSafeEqual(mac, sig);
30
+ }
31
+ else {
32
+ const keys = typeof o.jwks === "function" ? await o.jwks() : o.jwks ?? (await (await fetch(`${o.issuer.replace(/\/$/, "")}/.well-known/jwks.json`)).json()).keys;
33
+ const candidates = keys.filter((k) => !header.kid || k.kid === header.kid);
34
+ for (const jwk of candidates) {
35
+ try {
36
+ const key = createPublicKey({ key: jwk, format: "jwk" });
37
+ const algo = header.alg === "EdDSA" ? null : header.alg === "ES256" || header.alg === "RS256" ? "sha256" : header.alg === "ES384" || header.alg === "RS384" ? "sha384" : "sha512";
38
+ ok = cryptoVerify(algo, signed, header.alg?.startsWith("ES") ? { key, dsaEncoding: "ieee-p1363" } : key, sig);
39
+ }
40
+ catch {
41
+ ok = false;
42
+ }
43
+ if (ok)
44
+ break;
45
+ }
46
+ }
47
+ if (!ok)
48
+ return null;
49
+ const now = (o.now ?? (() => Math.floor(Date.now() / 1000)))();
50
+ if (typeof claims.exp === "number" && claims.exp <= now)
51
+ return null;
52
+ if (typeof claims.nbf === "number" && claims.nbf > now)
53
+ return null;
54
+ if (claims.iss !== o.issuer)
55
+ return null;
56
+ if (o.audience) {
57
+ const aud = claims.aud;
58
+ if (!(aud === o.audience || (Array.isArray(aud) && aud.includes(o.audience))))
59
+ return null;
60
+ }
61
+ return claims;
62
+ }
63
+ /** A verifier for `HostOptions.verifiers`: a valid token's subject becomes the caller its link names. */
64
+ export function oidcVerifier(o) {
65
+ return async (token) => {
66
+ if (token.split(".").length !== 3)
67
+ return null;
68
+ const claims = await verifyJwt(token, o);
69
+ if (!claims || typeof claims.sub !== "string")
70
+ return null;
71
+ return o.identity(o.provider, claims.sub);
72
+ };
73
+ }
74
+ //# sourceMappingURL=oidc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc.js","sourceRoot":"","sources":["../../src/oidc.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,0GAA0G;AAC1G,0GAA0G;AAC1G,6DAA6D;AAE7D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAqBnG,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE1F,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAa,EAAE,CAA6C;IAC1F,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAiC,CAAC;IACpD,IAAI,MAAsC,CAAC;IAC3C,IAAI,MAAoC,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAmC,CAAC;QAC/E,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAiC,CAAC;IAC/E,CAA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AQ,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;IAC7F,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,YAAY,CAAC,CAAc;IACzC,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAC/C,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC3D,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,148 @@
1
+ -- The host's own schema (docs/design/host.md): owners and their keys, identities and API keys. Nothing of
2
+ -- an owner's data lives here; that is the store's. Private keys are here only in the reference host's
3
+ -- simplest form; a platform keeps them in a key store or a KMS and leaves `private` empty.
4
+
5
+ create table if not exists host_owners (
6
+ owner text primary key,
7
+ public text not null,
8
+ private text,
9
+ created text not null
10
+ );
11
+
12
+ create table if not exists host_api_keys (
13
+ key_hash text primary key,
14
+ owner text not null,
15
+ caller text not null,
16
+ label text,
17
+ created text not null
18
+ );
19
+
20
+ -- The reference index (docs/design/index-and-forms.md): the current rows per view and audience, applied from
21
+ -- the projection stream, and where it is in each stream. Searchable over the row's text slots.
22
+ create table if not exists index_rows (
23
+ owner text not null,
24
+ view text not null,
25
+ version text not null,
26
+ audience text not null,
27
+ record text not null,
28
+ row jsonb not null,
29
+ buckets jsonb not null default '{}',
30
+ marks jsonb,
31
+ ancestors text[] not null default '{}',
32
+ sort jsonb not null default '[]',
33
+ pin integer,
34
+ seq bigint not null,
35
+ search tsvector,
36
+ -- Whom the record's link facet names, in a `linked <facet>` partition (12.2): the caller's bound.
37
+ linked text,
38
+ primary key (owner, view, version, audience, record)
39
+ );
40
+ create index if not exists index_rows_search on index_rows using gin (search);
41
+ -- Picks are containments on the buckets document; the first pages of a view in its stored order come off this index.
42
+ create index if not exists index_rows_buckets on index_rows using gin (buckets);
43
+ create index if not exists index_rows_order on index_rows (owner, view, version, audience, pin, (sort ->> 0), (sort ->> 1), (sort ->> 2), record);
44
+ -- The platform index (14.8, 14.10): rows reached by an edge on an ancestor, across owners.
45
+ create index if not exists index_rows_ancestors on index_rows using gin (ancestors);
46
+ create index if not exists index_rows_record on index_rows (record);
47
+ -- A store from before the column (0.3.40): the host's migration adds it and its index; a request never builds the index.
48
+ alter table index_rows add column if not exists linked text;
49
+ create index if not exists index_rows_linked on index_rows (owner, view, version, audience, linked) where linked is not null;
50
+
51
+ -- The counts, sums and nested counts of a view under its picks at one index head (the filter tally): one pass
52
+ -- over the view's rows, kept here so every process answers the same question from the table until the index
53
+ -- moves (3.1 s per pass on a 347,000-row view, paid by every function instance and every pick, 2026-10-23).
54
+ create table if not exists index_tallies (
55
+ key text primary key,
56
+ owner text not null,
57
+ view text not null,
58
+ version text not null,
59
+ audience text not null,
60
+ seq bigint not null,
61
+ json jsonb not null,
62
+ at timestamptz not null default now()
63
+ );
64
+ create index if not exists index_tallies_view on index_tallies (owner, view, version, audience, seq);
65
+
66
+ create table if not exists index_cursors (
67
+ owner text not null,
68
+ view text not null,
69
+ version text not null,
70
+ audience text not null,
71
+ seq bigint not null default 0,
72
+ primary key (owner, view, version, audience)
73
+ );
74
+
75
+ -- Credentials behind a contract's name (docs/design/host.md, "Outbound"). The reference host keeps the
76
+ -- material here; a platform keeps it in a vault behind the same interface and leaves `material` empty.
77
+ create table if not exists host_credentials (
78
+ owner text not null,
79
+ name text not null,
80
+ scheme text not null,
81
+ material jsonb not null,
82
+ scopes text[] not null default '{}',
83
+ expires text,
84
+ connected text not null,
85
+ primary key (owner, name)
86
+ );
87
+
88
+ create table if not exists host_identities (
89
+ provider text not null,
90
+ subject text not null,
91
+ owner text not null,
92
+ caller text not null,
93
+ primary key (provider, subject)
94
+ );
95
+
96
+ -- Link offers (7.8 `to: link`): one unguessable token per offer; unpublishing revokes, republishing keeps it.
97
+ create table if not exists host_offer_links (
98
+ owner text not null,
99
+ contract text not null,
100
+ token text not null,
101
+ revoked boolean not null default false,
102
+ primary key (owner, contract)
103
+ );
104
+
105
+ -- Retired signing keys (11.7): each with the span it signed in, so a rotated key still verifies.
106
+ create table if not exists host_keys (
107
+ owner text not null,
108
+ public text not null,
109
+ "from" text,
110
+ until text not null,
111
+ primary key (owner, public)
112
+ );
113
+
114
+ -- A system acting for a hosted person (14.9): what the person allowed, narrowed to items, until when, gated
115
+ -- until they lift it. Revoking keeps the row with when. Identity-adjacent, so the host's, like API keys.
116
+ create table if not exists host_acting_for (
117
+ id bigint generated always as identity primary key,
118
+ system_owner text not null,
119
+ system text not null,
120
+ person text not null,
121
+ items text[] not null default '{}',
122
+ until text,
123
+ gated boolean not null default true,
124
+ created text not null,
125
+ revoked text
126
+ );
127
+ create index if not exists host_acting_for_person on host_acting_for (person);
128
+
129
+ -- Packages an owner publishes from this host (11.5, 11.7): each version's signed bundle and its text, listed in
130
+ -- the well-known file and served at /packages/<owner>/<name>/<version>/. A published version never changes.
131
+ create table if not exists host_published (
132
+ owner text not null,
133
+ package text not null,
134
+ version text not null,
135
+ hash text not null,
136
+ json jsonb not null,
137
+ text text not null,
138
+ published text not null,
139
+ primary key (owner, package, version)
140
+ );
141
+
142
+ -- When each view with a delay (12.6 fresh: 5m) was last published by the loop.
143
+ create table if not exists host_publish (
144
+ owner text not null,
145
+ view text not null,
146
+ at text not null,
147
+ primary key (owner, view)
148
+ );
@@ -0,0 +1,21 @@
1
+ export type SecretStore = {
2
+ get(owner: string, name: string): Promise<string | undefined>;
3
+ /** Optional: a store that can be written to (the table can; the environment can't). */
4
+ set?(owner: string, name: string, value: string): Promise<void>;
5
+ };
6
+ /** Secrets from the environment: `CRUBAL_SECRET_<OWNER>_<NAME>`. */
7
+ export declare class EnvSecrets implements SecretStore {
8
+ get(owner: string, name: string): Promise<string | undefined>;
9
+ }
10
+ /** Secrets from a function the host was configured with (a vault client, a file). */
11
+ export declare class FunctionSecrets implements SecretStore {
12
+ private readonly fn;
13
+ constructor(fn: (owner: string, name: string) => string | undefined | Promise<string | undefined>);
14
+ get(owner: string, name: string): Promise<string | undefined>;
15
+ }
16
+ /** Several stores asked in order; the first answer wins. */
17
+ export declare class ChainedSecrets implements SecretStore {
18
+ private readonly stores;
19
+ constructor(stores: SecretStore[]);
20
+ get(owner: string, name: string): Promise<string | undefined>;
21
+ }
@@ -0,0 +1,36 @@
1
+ // secrets.ts: where credentials' secrets live (docs/design/host.md "What is kept where"). The host asks a
2
+ // SecretStore by (owner, name); the environment serves one owner, the credentials table serves many, and a
3
+ // vault is another implementation of the same two calls. Adapters never see names, only the material.
4
+ const envName = (s) => s.replace(/[^A-Za-z0-9]/g, "_").toUpperCase();
5
+ /** Secrets from the environment: `CRUBAL_SECRET_<OWNER>_<NAME>`. */
6
+ export class EnvSecrets {
7
+ async get(owner, name) {
8
+ return process.env[`CRUBAL_SECRET_${envName(owner)}_${envName(name)}`];
9
+ }
10
+ }
11
+ /** Secrets from a function the host was configured with (a vault client, a file). */
12
+ export class FunctionSecrets {
13
+ fn;
14
+ constructor(fn) {
15
+ this.fn = fn;
16
+ }
17
+ async get(owner, name) {
18
+ return this.fn(owner, name);
19
+ }
20
+ }
21
+ /** Several stores asked in order; the first answer wins. */
22
+ export class ChainedSecrets {
23
+ stores;
24
+ constructor(stores) {
25
+ this.stores = stores;
26
+ }
27
+ async get(owner, name) {
28
+ for (const s of this.stores) {
29
+ const v = await s.get(owner, name);
30
+ if (v !== undefined)
31
+ return v;
32
+ }
33
+ return undefined;
34
+ }
35
+ }
36
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/secrets.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,2GAA2G;AAC3G,sGAAsG;AAQtG,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAE7E,oEAAoE;AACpE,MAAM,OAAO,UAAU;IACrB,KAAK,CAAC,GAAG,CAAC,KAAa,EAAE,IAAY;QACnC,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;CACF;AAED,qFAAqF;AACrF,MAAM,OAAO,eAAe;IACT,EAAE,CAAoF;IACvG,YAAY,EAAqF;QAC/F,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,KAAa,EAAE,IAAY;QACnC,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,4DAA4D;AAC5D,MAAM,OAAO,cAAc;IACR,MAAM,CAAgB;IACvC,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,KAAa,EAAE,IAAY;QACnC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,KAAK,SAAS;gBAAE,OAAO,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ import { type Server } from "node:http";
2
+ import type { Host } from "./host.ts";
3
+ /**
4
+ * A request as the host sees it, whatever carried it: the node server below, or a route in an app that runs
5
+ * the host in process. `url` is the path and query as node gives it; the origin a signature covers comes
6
+ * from the `host` and `x-forwarded-proto` headers; the body is already read, once, so a digest can cover it.
7
+ */
8
+ export type HostRequest = {
9
+ method: string;
10
+ url: string;
11
+ headers: {
12
+ [h: string]: string | string[] | undefined;
13
+ };
14
+ body: string;
15
+ };
16
+ /** What a request's log line and CORS need, set as the request is understood. */
17
+ export type Seen = {
18
+ owner?: string;
19
+ caller?: string;
20
+ route?: string;
21
+ };
22
+ export type HostReply = {
23
+ status: number;
24
+ headers: {
25
+ [h: string]: string;
26
+ };
27
+ body: string;
28
+ seen: Seen;
29
+ };
30
+ /**
31
+ * Answer one request. Every route is here, owner-scoped, the same for every owner; errors become a JSON
32
+ * body with their status. Transports call this: `serve` for node, an app's route for in-process hosting.
33
+ */
34
+ export declare function handle(host: Host, req: HostRequest): Promise<HostReply>;
35
+ /** One structured line per request, when it has been answered. */
36
+ export declare function logLine(host: Host, req: {
37
+ method: string;
38
+ url: string;
39
+ }, reply: HostReply, started: number): void;
40
+ /** The node server: reads each request, hands it to `handle`, writes the reply, logs the line. */
41
+ export declare function serve(host: Host): Server;