@tokenoftrust/storefront-runner 7.6.2 → 7.6.4
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/apps/storefront/src/lib/access/auth/agentRoles.ts +9 -9
- package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +1 -67
- package/apps/storefront/src/lib/access/auth/session.ts +17 -0
- package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +3 -4
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* role through these constants, never as a string literal (`agentRoles.test.ts` scans
|
|
5
|
-
* the tree for one).
|
|
2
|
+
* Capability names used by the sponsored-agent routes and store entry. A grant can
|
|
3
|
+
* satisfy a role check only when the generated catalog marks that role as holdable.
|
|
6
4
|
*
|
|
7
5
|
* The roles an agent session carries (`actor.roles`) only NARROW what it may reach; they
|
|
8
6
|
* never unlock anything locally. Customer PII in particular stays projected away for an
|
|
9
7
|
* agent whatever its roles say, and `orders:fulfil-by-id` still asks tot20 per operation.
|
|
10
8
|
*/
|
|
11
|
-
import {
|
|
9
|
+
import { isAgentRoleId, type AgentRoleId, type CatalogCapabilityId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
|
|
12
10
|
|
|
13
11
|
export type { AgentRoleId };
|
|
14
12
|
|
|
15
|
-
export const
|
|
13
|
+
export const PREVIEW_VIEW_ROLE = "preview:view" as const satisfies AgentRoleId;
|
|
14
|
+
export const ADMIN_READ_ROLE = "admin:read" as const satisfies AgentRoleId;
|
|
15
|
+
export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies AgentRoleId;
|
|
16
16
|
|
|
17
|
-
/** True when
|
|
18
|
-
export function agentHoldsRole(roles: readonly string[] | null | undefined, role:
|
|
19
|
-
return Array.isArray(roles) && roles.includes(role);
|
|
17
|
+
/** True when the catalog permits the role and the grant names it exactly. */
|
|
18
|
+
export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
|
|
19
|
+
return isAgentRoleId(role) && Array.isArray(roles) && roles.includes(role);
|
|
20
20
|
}
|
|
@@ -24,8 +24,6 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { SignJWT, importPKCS8, type CryptoKey } from "jose";
|
|
26
26
|
import { readEnv } from "@/lib/publication/shared/env";
|
|
27
|
-
import { AGENT_SUBJECT_RE } from "@/lib/access/auth/session";
|
|
28
|
-
import { isCatalogCapabilityId, type CatalogCapabilityId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
|
|
29
27
|
|
|
30
28
|
/** The audience tot20's broker verifier pins. */
|
|
31
29
|
export const BROKER_AUDIENCE = "tot20-broker";
|
|
@@ -153,73 +151,9 @@ export async function mintBrokerAssertion(
|
|
|
153
151
|
return mintBrokerAssertionSubject(sub, overrides);
|
|
154
152
|
}
|
|
155
153
|
|
|
156
|
-
export { AGENT_SUBJECT_RE };
|
|
157
|
-
|
|
158
|
-
/** A delegated (sponsored-agent) assertion's subject and delegation claims. */
|
|
159
|
-
export interface DelegatedBrokerAssertionInput {
|
|
160
|
-
/** The agent subject, `agent:<id>`. Never the sponsor. */
|
|
161
|
-
sub: string;
|
|
162
|
-
/** RFC 8693 actor: the SAME agent subject. Required together with `grantId`. */
|
|
163
|
-
act?: { sub: string };
|
|
164
|
-
/** The agent-sponsorship grant this entry rides on. Required together with `act`. */
|
|
165
|
-
grantId?: string;
|
|
166
|
-
/** The ONE tenant (appDomain) this assertion may act on, signed. Required. */
|
|
167
|
-
tenant: string;
|
|
168
|
-
/**
|
|
169
|
-
* The ONE catalog capability this assertion asks tot20's authority route to decide,
|
|
170
|
-
* signed as `cap`. tot20 refuses an authority answer whose signed `cap` is not the
|
|
171
|
-
* row it was asked about. Omit for a store entry (no authority row is decided).
|
|
172
|
-
*/
|
|
173
|
-
cap?: CatalogCapabilityId;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Mint a DELEGATED broker assertion for a sponsored agent's store entry: `sub` and
|
|
178
|
-
* `act.sub` are both the agent (`agent:<id>`), and `grantId` names the grant tot20 checks
|
|
179
|
-
* against the tot-mcp grant attestation that travels beside it. The sponsor is never
|
|
180
|
-
* the subject: tot20 resolves it only from that attestation.
|
|
181
|
-
*
|
|
182
|
-
* Fails closed with {@link BrokerAssertionError}: `act` and `grantId` are both-or-neither
|
|
183
|
-
* and a delegated assertion needs both; `sub` must match {@link AGENT_SUBJECT_RE};
|
|
184
|
-
* `act.sub` must equal `sub`; the tenant is required. One per call (the `jti` burns).
|
|
185
|
-
*/
|
|
186
|
-
export async function mintDelegatedBrokerAssertion(
|
|
187
|
-
input: DelegatedBrokerAssertionInput,
|
|
188
|
-
overrides: Omit<MintBrokerAssertionOverrides, "tenant"> = {},
|
|
189
|
-
): Promise<string> {
|
|
190
|
-
const sub = (input.sub ?? "").trim();
|
|
191
|
-
const hasAct = !!input.act && typeof input.act.sub === "string" && input.act.sub.length > 0;
|
|
192
|
-
const grantId = typeof input.grantId === "string" ? input.grantId.trim() : "";
|
|
193
|
-
if (hasAct !== !!grantId) {
|
|
194
|
-
throw new BrokerAssertionError("broker assertion: act and grantId must be sent together");
|
|
195
|
-
}
|
|
196
|
-
if (!hasAct) {
|
|
197
|
-
throw new BrokerAssertionError("broker assertion: a delegated assertion requires act and grantId");
|
|
198
|
-
}
|
|
199
|
-
if (!AGENT_SUBJECT_RE.test(sub)) {
|
|
200
|
-
throw new BrokerAssertionError("broker assertion: a delegated subject must be an agent subject");
|
|
201
|
-
}
|
|
202
|
-
if (input.act!.sub !== sub) {
|
|
203
|
-
throw new BrokerAssertionError("broker assertion: act.sub must name the same agent as sub");
|
|
204
|
-
}
|
|
205
|
-
const tenant = (input.tenant ?? "").trim();
|
|
206
|
-
if (!tenant) {
|
|
207
|
-
throw new BrokerAssertionError("broker assertion: a delegated assertion must name its tenant");
|
|
208
|
-
}
|
|
209
|
-
if (input.cap !== undefined && !isCatalogCapabilityId(input.cap)) {
|
|
210
|
-
throw new BrokerAssertionError("broker assertion: cap must be a catalog capability id");
|
|
211
|
-
}
|
|
212
|
-
return mintBrokerAssertionSubject(sub, { ...overrides, tenant }, {
|
|
213
|
-
act: { sub },
|
|
214
|
-
grantId,
|
|
215
|
-
...(input.cap !== undefined ? { cap: input.cap } : {}),
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
154
|
async function mintBrokerAssertionSubject(
|
|
220
155
|
sub: string,
|
|
221
156
|
overrides: MintBrokerAssertionOverrides,
|
|
222
|
-
delegation?: { act: { sub: string }; grantId: string; cap?: CatalogCapabilityId },
|
|
223
157
|
): Promise<string> {
|
|
224
158
|
const privateKeyB64 = overrides.privateKeyB64 ?? (await readEnv(BROKER_PRIVATE_KEY_ENV));
|
|
225
159
|
if (!privateKeyB64) {
|
|
@@ -234,7 +168,7 @@ async function mintBrokerAssertionSubject(
|
|
|
234
168
|
|
|
235
169
|
const key = await loadSigningKey(privateKeyB64);
|
|
236
170
|
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
237
|
-
return new SignJWT(
|
|
171
|
+
return new SignJWT(tenant ? { tenant } : {})
|
|
238
172
|
.setProtectedHeader({ alg: BROKER_ALG, kid, typ: "JWT" })
|
|
239
173
|
.setIssuer(issuer)
|
|
240
174
|
.setSubject(sub)
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* host↔resource check.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import type { CatalogCapabilityId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
|
|
19
|
+
|
|
18
20
|
/** The cookie the browser carries; value is an opaque session id (not the record). */
|
|
19
21
|
export const SESSION_COOKIE = "tot_session";
|
|
20
22
|
|
|
@@ -71,6 +73,21 @@ export interface AgentActor {
|
|
|
71
73
|
mcpOrigin: string;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
/** In-flight proof for one session-bound operation. The session never persists it. */
|
|
77
|
+
export type AgentGrantPairResult = { assertion: string; attestation: string } | null | "fault";
|
|
78
|
+
|
|
79
|
+
export interface AgentGrantPairRequest {
|
|
80
|
+
grantId: string;
|
|
81
|
+
/** The agent subject, `agent:<id>`. */
|
|
82
|
+
agentId: string;
|
|
83
|
+
/** The trusted MCP origin that introspected the agent's token. */
|
|
84
|
+
mcpOrigin: string;
|
|
85
|
+
tenant: string;
|
|
86
|
+
cap: CatalogCapabilityId;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type AgentGrantPairFetcher = (request: AgentGrantPairRequest) => Promise<AgentGrantPairResult>;
|
|
90
|
+
|
|
74
91
|
/** An agent session's lifetime ceiling (the grant's own expiry may cut it shorter). */
|
|
75
92
|
export const AGENT_SESSION_MAX_TTL_SECONDS = 3600;
|
|
76
93
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/** The vendored artifact's schema and the digest tot20 stamped on it. */
|
|
7
7
|
export const CAPABILITY_CATALOG_SCHEMA = "tot.capability-catalog/v1" as const;
|
|
8
|
-
export const CAPABILITY_CATALOG_DIGEST = "sha256:
|
|
8
|
+
export const CAPABILITY_CATALOG_DIGEST = "sha256:0683a9f2312c22c53fd995e5b8f90929b8887251d5fc47300f82776801203a39" as const;
|
|
9
9
|
|
|
10
10
|
/** Every capability row id the catalog names. */
|
|
11
11
|
export const CATALOG_CAPABILITY_IDS = [
|
|
@@ -110,12 +110,11 @@ export const CATALOG_BUNDLE_NAMES = [
|
|
|
110
110
|
] as const;
|
|
111
111
|
export type CatalogBundleName = (typeof CATALOG_BUNDLE_NAMES)[number];
|
|
112
112
|
|
|
113
|
-
/**
|
|
113
|
+
/** Capability rows marked holdable by sponsored agents in the catalog. */
|
|
114
114
|
export const AGENT_ROLE_IDS = [
|
|
115
|
-
"preview:view",
|
|
116
115
|
"admin:read",
|
|
117
116
|
"orders:fulfil-by-id",
|
|
118
|
-
"
|
|
117
|
+
"preview:view",
|
|
119
118
|
] as const satisfies readonly CatalogCapabilityId[];
|
|
120
119
|
export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
|
|
121
120
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.4",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|