@tokenoftrust/storefront-runner 7.6.2 → 7.6.3

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.
@@ -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({ ...(tenant ? { tenant } : {}), ...(delegation ?? {}) })
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.2",
3
+ "version": "7.6.3",
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",