@tokenoftrust/storefront-runner 7.6.9 → 7.6.10

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.
@@ -26,6 +26,7 @@
26
26
  * for the outcome.
27
27
  */
28
28
  import { readEnv } from "@/lib/publication/shared/env";
29
+ import { mcpServiceProof, type McpServiceProofSpec } from "./mcpServiceProof";
29
30
 
30
31
  export interface McpServiceResponse {
31
32
  status: number;
@@ -52,6 +53,12 @@ export interface McpServiceRequest {
52
53
  path: string;
53
54
  query?: Record<string, string>;
54
55
  body?: unknown;
56
+ /**
57
+ * A proof over a typed tuple, computed here from the service secret and merged into an object
58
+ * `body` under `proof.field`. The caller supplies labels and values and receives only the proof;
59
+ * the secret never leaves this module.
60
+ */
61
+ proof?: McpServiceProofSpec;
55
62
  /** `"grant"` selects `MCP_GRANT_AUTHORITY_URL`; omitted selects `MCP_APP_BINDING_URL`. */
56
63
  authority?: "grant";
57
64
  transport: McpServiceTransport;
@@ -147,12 +154,15 @@ export async function callMcpService(req: McpServiceRequest): Promise<McpService
147
154
  const headers = { "x-mcp-service-secret": secret };
148
155
  let res: McpServiceResponse;
149
156
  try {
157
+ const body = req.proof
158
+ ? { ...(req.body as Record<string, unknown>), [req.proof.field]: await mcpServiceProof(req.proof, secret) }
159
+ : req.body;
150
160
  if (req.method === "GET") {
151
161
  if (!req.transport.get) throw new Error("transport has no get()");
152
162
  res = await req.transport.get(url, headers);
153
163
  } else {
154
164
  if (!req.transport.post) throw new Error("transport has no post()");
155
- res = await req.transport.post(url, headers, req.body);
165
+ res = await req.transport.post(url, headers, body);
156
166
  }
157
167
  } catch (thrown) {
158
168
  console.error(
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Proof that a request body was produced by a holder of the shared tot-mcp service key. The caller
3
+ * names a field, two labels and the tuple to sign; this module derives a key from the service
4
+ * secret and returns only the hex HMAC. The secret is used here and in `callMcpService`, and never
5
+ * handed to a caller.
6
+ *
7
+ * The proof shows possession of the shared service key over the tuple. It does not establish who
8
+ * the viewer is: the caller's own admin and tenant checks do that before a proof is requested.
9
+ */
10
+
11
+ export interface McpServiceProofSpec {
12
+ /** The body field that carries the proof. */
13
+ field: string;
14
+ /** Derives the signing key from the service secret. */
15
+ keyLabel: string;
16
+ /** Prefixes the signed tuple, so a proof for one purpose verifies for no other. */
17
+ proofLabel: string;
18
+ /** The signed values, in order. */
19
+ tuple: readonly (string | number)[];
20
+ }
21
+
22
+ async function hmac(key: BufferSource, message: string): Promise<ArrayBuffer> {
23
+ const imported = await crypto.subtle.importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
24
+ return crypto.subtle.sign("HMAC", imported, new TextEncoder().encode(message));
25
+ }
26
+
27
+ /** Lowercase hex HMAC-SHA256 of `[proofLabel, ...tuple]` under a key derived from the secret. */
28
+ export async function mcpServiceProof(spec: McpServiceProofSpec, secret: string): Promise<string> {
29
+ const key = await hmac(new TextEncoder().encode(secret), spec.keyLabel);
30
+ const proof = new Uint8Array(await hmac(key, JSON.stringify([spec.proofLabel, ...spec.tuple])));
31
+ return Array.from(proof, (byte) => byte.toString(16).padStart(2, "0")).join("");
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.9",
3
+ "version": "7.6.10",
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",