@substrat-run/control-plane-api 0.186.0 → 0.188.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.
@@ -39,7 +39,12 @@ export interface PlatformScopeStores {
39
39
  binding: string;
40
40
  erased: number;
41
41
  }[]>;
42
- wipeStores(input: {
42
+ /**
43
+ * Fence each store and wipe it, for a scope that is being deleted (`substrat.fence`, D-71). The
44
+ * object refuses a caller from then on, whenever the call was signed, and refuses a platform call
45
+ * that would write. It is one call to the object, so a retry runs the whole of it again.
46
+ */
47
+ fenceStores(input: {
43
48
  tenantId: string;
44
49
  scopeId: string;
45
50
  vertical: string;
@@ -1 +1 @@
1
- {"version":3,"file":"platform-scope-stores.d.ts","sourceRoot":"","sources":["../src/platform-scope-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAiBL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAA6C,KAAK,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzH;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,Q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oldScopeStores, scopeStoresDeclaredIn, STORE_DRIVERS, issueScopeStoreEnvelope, SCOPE_STORE_ENVELOPE_HEADER, SCOPE_STORE_SIGNATURE_HEADER, ScopeStoreKeyError, STORE_CALL_MAX_BYTES, scopeStoreBodyBytes, scopeStoreObjectName, scopeStoreScriptName, storeEraseResult, storeDriverDumpPageBytes, storeSizeResult, StoreError, } from '@substrat-run/contracts';
1
+ import { LIST_PAGE_MAX, mayHoldScopeStores, scopeStoresDeclaredIn, STORE_DRIVERS, issueScopeStoreEnvelope, SCOPE_STORE_ENVELOPE_HEADER, SCOPE_STORE_SIGNATURE_HEADER, ScopeStoreKeyError, STORE_CALL_MAX_BYTES, scopeStoreBodyBytes, scopeStoreObjectName, scopeStoreScriptName, storeEraseResult, storeDriverDumpPageBytes, STORE_FENCE_OPERATION, storeRequest, storeResponse, storeSizeResult, storeWipeResult, StoreError, } from '@substrat-run/contracts';
2
2
  import { callReservedStoreOperation, readStoreDump } from '@substrat-run/kernel';
3
3
  import { ControlPlaneError } from '@substrat-run/control-plane-client';
4
4
  import { storedDeployManifest } from './deploy.js';
@@ -167,52 +167,81 @@ export async function callPlatformScopeStore(dispatch, target, operation, input)
167
167
  * (vertical, scope) names. Its answer is parsed as every reserved answer is.
168
168
  */
169
169
  export async function callPlatformScopeStoreAt(dispatch, target, operation, input) {
170
- if (!dispatch.platformKey) {
171
- throw new ControlPlaneError(503, 'this control plane holds no scope-store key');
172
- }
173
- const { scriptName, objectName } = target;
174
170
  try {
175
- return await callReservedStoreOperation(async (request) => {
176
- const body = JSON.stringify({ ...request, objectName });
177
- // The store entry refuses a body over the limit (#2811), so it is refused here, before it is signed.
178
- const bytes = scopeStoreBodyBytes(body);
179
- if (bytes > STORE_CALL_MAX_BYTES) {
180
- throw new ControlPlaneError(413, `scope store call '${request.operation}' carries a body of ${bytes} bytes, over the limit of ${STORE_CALL_MAX_BYTES}. Nothing was sent.`);
181
- }
182
- let issued;
183
- try {
184
- issued = await issueScopeStoreEnvelope({
185
- privateKey: dispatch.platformKey,
186
- aud: 'platform',
187
- script: scriptName,
188
- name: objectName,
189
- op: request.operation,
190
- body,
191
- });
192
- }
193
- catch (error) {
194
- if (!(error instanceof ScopeStoreKeyError))
195
- throw error;
196
- // Set but unusable, e.g. a raw key where PKCS8 belongs. The message never carries the key.
197
- console.warn(`scope store call refused: STORE_PLATFORM_KEY is set but unusable (${error.message})`);
198
- throw new ControlPlaneError(503, 'this control plane holds no usable scope-store key');
199
- }
200
- const response = await dispatch.fetch(scriptName, new Request('https://scope-store/invoke', {
201
- method: 'POST',
202
- headers: {
203
- 'content-type': 'application/json',
204
- [SCOPE_STORE_ENVELOPE_HEADER]: issued.header,
205
- [SCOPE_STORE_SIGNATURE_HEADER]: issued.signature,
206
- },
171
+ return await callReservedStoreOperation(signedStoreSend(dispatch, target), operation, input);
172
+ }
173
+ catch (error) {
174
+ asControlPlane(error);
175
+ }
176
+ }
177
+ /** Sign one request, audience `platform`, POST it at the script, and answer the store's JSON, or null for none. */
178
+ function signedStoreSend(dispatch, { scriptName, objectName }) {
179
+ return async (request) => {
180
+ if (!dispatch.platformKey) {
181
+ throw new ControlPlaneError(503, 'this control plane holds no scope-store key');
182
+ }
183
+ const body = JSON.stringify({ ...request, objectName });
184
+ // The store entry refuses a body over the limit (#2811), so it is refused here, before it is signed.
185
+ const bytes = scopeStoreBodyBytes(body);
186
+ if (bytes > STORE_CALL_MAX_BYTES) {
187
+ throw new ControlPlaneError(413, `scope store call '${request.operation}' carries a body of ${bytes} bytes, over the limit of ${STORE_CALL_MAX_BYTES}. Nothing was sent.`);
188
+ }
189
+ let issued;
190
+ try {
191
+ issued = await issueScopeStoreEnvelope({
192
+ privateKey: dispatch.platformKey,
193
+ aud: 'platform',
194
+ script: scriptName,
195
+ name: objectName,
196
+ op: request.operation,
207
197
  body,
208
- }));
209
- try {
210
- return await response.json();
211
- }
212
- catch {
213
- return null;
214
- }
215
- }, operation, input);
198
+ });
199
+ }
200
+ catch (error) {
201
+ if (!(error instanceof ScopeStoreKeyError))
202
+ throw error;
203
+ // Set but unusable, e.g. a raw key where PKCS8 belongs. The message never carries the key.
204
+ console.warn(`scope store call refused: STORE_PLATFORM_KEY is set but unusable (${error.message})`);
205
+ throw new ControlPlaneError(503, 'this control plane holds no usable scope-store key');
206
+ }
207
+ const response = await dispatch.fetch(scriptName, new Request('https://scope-store/invoke', {
208
+ method: 'POST',
209
+ headers: {
210
+ 'content-type': 'application/json',
211
+ [SCOPE_STORE_ENVELOPE_HEADER]: issued.header,
212
+ [SCOPE_STORE_SIGNATURE_HEADER]: issued.signature,
213
+ },
214
+ body,
215
+ }));
216
+ try {
217
+ return await response.json();
218
+ }
219
+ catch {
220
+ return null;
221
+ }
222
+ };
223
+ }
224
+ /**
225
+ * `substrat.fence` on one store object (D-71): the entry fences it and the driver wipes it. The entry
226
+ * answers with the driver's wipe, held to what a wipe answers. An entry older than the fence refuses
227
+ * the call outside the envelope, which reads as `bad_envelope` (502): the reap stops there, and no
228
+ * store is taken for fenced that was not. A fence whose drain outlasts its wait answers 503
229
+ * (`store_fence_draining`), and the reap stays retryable: the next try runs the whole fence again.
230
+ */
231
+ async function callPlatformStoreFence(dispatch, target) {
232
+ const send = signedStoreSend(dispatch, {
233
+ scriptName: scopeStoreScriptName(target.vertical, target.driver),
234
+ objectName: scopeStoreObjectName(target.tenantId, target.vertical, target.scopeId, target.binding),
235
+ });
236
+ try {
237
+ const parsed = storeResponse.safeParse(await send(storeRequest.parse({ operation: STORE_FENCE_OPERATION })));
238
+ if (!parsed.success)
239
+ throw new StoreError({ code: 'bad_envelope', status: 502, body: parsed.error.issues });
240
+ if ('error' in parsed.data)
241
+ throw new StoreError(parsed.data.error);
242
+ const wiped = storeWipeResult.safeParse(parsed.data.result);
243
+ if (!wiped.success)
244
+ throw new StoreError({ code: 'bad_envelope', status: 502, body: wiped.error.issues });
216
245
  }
217
246
  catch (error) {
218
247
  asControlPlane(error);
@@ -231,9 +260,9 @@ export function platformScopeStoresFor(dispatch) {
231
260
  }
232
261
  return erased;
233
262
  },
234
- async wipeStores({ tenantId, scopeId, vertical, stores }) {
263
+ async fenceStores({ tenantId, scopeId, vertical, stores }) {
235
264
  for (const store of stores) {
236
- await call({ ...store, tenantId, scopeId, vertical }, 'substrat.wipe');
265
+ await callPlatformStoreFence(dispatch, { ...store, tenantId, scopeId, vertical });
237
266
  }
238
267
  },
239
268
  async sizeStores({ tenantId, scopeId, vertical, stores }) {
@@ -255,7 +284,7 @@ export function unreachablePlatformScopeStores() {
255
284
  const refuse = async () => {
256
285
  throw new ControlPlaneError(503, 'this control plane cannot reach scope stores');
257
286
  };
258
- return { callStore: () => refuse, eraseSubject: refuse, wipeStores: refuse, sizeStores: refuse };
287
+ return { callStore: () => refuse, eraseSubject: refuse, fenceStores: refuse, sizeStores: refuse };
259
288
  }
260
289
  /**
261
290
  * Each store's whole dump, read a page at a time and joined (D-69): for a pull or a tenant export,
@@ -1 +1 @@
1
- {"version":3,"file":"platform-scope-stores.js","sourceRoot":"","sources":["../src/platform-scope-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,eAAe,EACf,UAAU,GAMX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAA0C,MAAM,sBAAsB,CAAC;AACzH,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAuDnD,gGAAgG;AAChG,MAAM,UAAU,gBAAgB,CAAC,YAA2B;IAC1D,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAC7B,IAAI,GAAY,CAAC;IACjB,I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,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B;IAC5C,MAAM,MAAM,GAAG,KAAK,IAAoB,EAAE;QACxC,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,8CAA8C,CAAC,CAAC;IACnF,CAAC,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AACpG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA2B,EAC3B,KAA8D,EAC9D,MAAqC;IAErC,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACrH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -17,6 +17,12 @@ export declare const STORE_ENTRY_MODULE = "substrat-store-entry.js";
17
17
  * is Python. Reserved.
18
18
  */
19
19
  export declare const STORE_ENTRY_PYTHON_MODULE = "substrat_store_entry.py";
20
+ /**
21
+ * The storage key of a fenced object's tombstone (D-71), the entry's and never a driver's. It is
22
+ * the store's counterpart of the scope object's `_substrat_reaped`: written after the wipe as well
23
+ * as before, since a driver's wipe may `deleteAll()`, and never cleared.
24
+ */
25
+ export declare const STORE_FENCE_KEY = "_substrat_store_fence";
20
26
  /** The binding the entry uses to address that class. */
21
27
  export declare const STORE_OBJECT_BINDING = "SUBSTRAT_STORE";
22
28
  /** The object class the entry addresses, and the SQLite class the upload migrates. Reserved. */
@@ -44,7 +50,7 @@ export declare const STORE_SCRIPT_VAR = "SUBSTRAT_STORE_SCRIPT";
44
50
  * it, so both entries run one verifier. Reserved.
45
51
  */
46
52
  export declare const STORE_VERIFIER_MODULE = "substrat-store-verify.js";
47
- /** The entry itself — 13911 bytes of ESM. */
53
+ /** The entry itself — 18339 bytes of ESM. */
48
54
  export declare const STORE_ENTRY_SOURCE: string;
49
55
  /**
50
56
  * The Python entry (#2290), uploaded as `substrat_store_entry.py`. The driver module's
@@ -54,7 +60,7 @@ export declare const STORE_ENTRY_SOURCE: string;
54
60
  export declare const STORE_ENTRY_PYTHON_SOURCE: string;
55
61
  /**
56
62
  * The verifier the Python entry imports, uploaded beside it as `substrat-store-verify.js`
57
- * (an ES module). It is `packages/control-plane-api/store-entry/verify.ts`, the check the JavaScript entry runs — 11756 bytes.
63
+ * (an ES module). It is `packages/control-plane-api/store-entry/verify.ts`, the check the JavaScript entry runs — 15249 bytes.
58
64
  */
59
65
  export declare const STORE_ENTRY_PYTHON_VERIFIER_SOURCE: string;
60
66
  //# sourceMappingURL=store-entry.generated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-entry.generated.d.ts","sourceRoot":"","sources":["../src/store-entry.generated.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,+BAA+B,CAAC;AAElE,2FAA2F;AAC3F,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AAEpE,4GAA4G;AAC5G,eAAO,MAAM,kBAAkB,4BAA4B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,yBAAyB,4BA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wBAAwB,CAAC;AAExD,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,+BAA+B,eAAe,CAAC;AAE5D,6GAA6G;AAC7G,eAAO,MAAM,gCAAgC,UAAqB,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,mBAAmB,CAAC;AAE9D,mGAAmG;AACnG,eAAO,MAAM,sBAAsB,UAAmF,CAAC;AAEvH,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAEhE,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,EAAE,MAAqolB,CAAC;AAEvqlB;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAA27R,CAAC;AAEp+R;;;GAGG;AACH,eAAO,MAAM,kCAAkC,EAAE,MAA8gf,CAAC"}
@@ -19,6 +19,12 @@ export const STORE_ENTRY_MODULE = "substrat-store-entry.js";
19
19
  * is Python. Reserved.
20
20
  */
21
21
  export const STORE_ENTRY_PYTHON_MODULE = "substrat_store_entry.py";
22
+ /**
23
+ * The storage key of a fenced object's tombstone (D-71), the entry's and never a driver's. It is
24
+ * the store's counterpart of the scope object's `_substrat_reaped`: written after the wipe as well
25
+ * as before, since a driver's wipe may `deleteAll()`, and never cleared.
26
+ */
27
+ export const STORE_FENCE_KEY = "_substrat_store_fence";
22
28
  /** The binding the entry uses to address that class. */
23
29
  export const STORE_OBJECT_BINDING = "SUBSTRAT_STORE";
24
30
  /** The object class the entry addresses, and the SQLite class the upload migrates. Reserved. */
@@ -46,17 +52,17 @@ export const STORE_SCRIPT_VAR = "SUBSTRAT_STORE_SCRIPT";
46
52
  * it, so both entries run one verifier. Reserved.
47
53
  */
48
54
  export const STORE_VERIFIER_MODULE = "substrat-store-verify.js";
49
- /** The entry itself — 13911 bytes of ESM. */
50
- export const STORE_ENTRY_SOURCE = "// packages/control-plane-api/store-entry/entry.ts\nimport { DurableObject } from \"cloudflare:workers\";\nimport * as driverModule from \"__SUBSTRAT_STORE_DRIVER__\";\n\n// packages/control-plane-api/store-entry/names.ts\nvar STORE_OBJECT_BINDING = \"SUBSTRAT_STORE\";\nvar STORE_SCRIPT_VAR = \"SUBSTRAT_STORE_SCRIPT\";\nvar STORE_CALLER_KEYS_VAR = \"SUBSTRAT_STORE_CALLER_KEYS\";\nvar STORE_PLATFORM_KEYS_VAR = \"SUBSTRAT_STORE_PLATFORM_KEYS\";\nvar STORE_RESERVED_BINDING_PREFIX = \"SUBSTRAT_STORE\";\n\n// packages/contracts/dist/scope-store-envelope.js\nvar SCOPE_STORE_ENVELOPE_WINDOW_SECONDS = 60;\nvar SCOPE_STORE_ENVELOPE_HEADER = \"x-substrat-store-envelope\";\nvar SCOPE_STORE_SIGNATURE_HEADER = \"x-substrat-store-signature\";\nvar RESERVED_STORE_OPERATIONS = [\n \"substrat.export-page\",\n \"substrat.stage-page\",\n \"substrat.commit-stage\",\n \"substrat.discard-stage\",\n \"substrat.size\",\n \"substrat.wipe\",\n \"substrat.erase\",\n \"substrat.selfcheck\"\n];\nvar STORE_STAGE_MAX_AGE_MS = 6 * 36e5 + 3 * 30 * 6e4;\nvar STORE_CALL_MAX_BYTES = 4 * 1024 * 1024;\nvar STORE_DUMP_PAGE_MAX_BYTES = 3 * 1024 * 1024;\nvar ADMITTED = {\n \"1\": {\n platform: (op) => RESERVED_STORE_OPERATIONS.includes(op),\n caller: (op) => !op.startsWith(\"substrat.\")\n }\n};\nfunction scopeStoreEnvelopeAdmits(v, aud, op) {\n const byAudience = Object.hasOwn(ADMITTED, String(v)) ? ADMITTED[String(v)] : void 0;\n if (!byAudience || !Object.hasOwn(byAudience, aud))\n return false;\n return byAudience[aud](op);\n}\nfunction bytesToBase64Url(bytes) {\n let binary = \"\";\n for (const byte of bytes)\n binary += String.fromCharCode(byte);\n return btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\nfunction base64UrlToBytes(value) {\n if (!/^[A-Za-z0-9_-]+$/.test(value))\n return void 0;\n const padded = value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + \"=\".repeat((4 - value.length % 4) % 4);\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++)\n bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return void 0;\n }\n}\nfunction copyBytes(bytes) {\n const copy = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(copy).set(bytes);\n return copy;\n}\nfunction isCanonicalBase64Url(text, length) {\n const bytes = base64UrlToBytes(text);\n return bytes?.length === length && bytesToBase64Url(bytes) === text;\n}\nvar NONCE = /^[A-Za-z0-9_-]{22}$/;\nvar KID = /^[A-Za-z0-9_-]{11}$/;\nvar DIGEST = /^[0-9a-f]{64}$/;\nvar IAT = /^(0|[1-9]\\d{0,14})$/;\nfunction parseScopeStoreEnvelope(canonical) {\n const lines = canonical.split(\"\\n\");\n if (lines.length !== 9)\n return void 0;\n const [version, aud, kid, script, name, op, digest, iatText, nonce] = lines;\n if (version !== \"1\" || aud !== \"caller\" && aud !== \"platform\")\n return void 0;\n if (!script || !name || !op)\n return void 0;\n if (!KID.test(kid) || !DIGEST.test(digest) || !IAT.test(iatText) || !NONCE.test(nonce))\n return void 0;\n if (!isCanonicalBase64Url(kid, 8) || !isCanonicalBase64Url(nonce, 16))\n return void 0;\n return { v: 1, aud, kid, script, name, op, digest, iat: Number(iatText), nonce };\n}\nasync function scopeStoreBodyDigest(body) {\n const hash = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(body));\n return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\nfunction scopeStoreEnvelopeFresh(iat, nowSeconds, windowSeconds = SCOPE_STORE_ENVELOPE_WINDOW_SECONDS) {\n return Math.abs(nowSeconds - iat) <= windowSeconds;\n}\nvar SMALL_ORDER_KEYS = [\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n // y = 0, order 4\n \"0100000000000000000000000000000000000000000000000000000000000000\",\n // the identity, order 1\n \"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05\",\n // order 8\n \"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a\",\n // order 8\n \"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p - 1, order 2\n \"edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p, a non-canonical 0\n \"eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\"\n // y = p + 1, a non-canonical identity\n];\nfunction isSmallOrderKey(bytes) {\n const unsigned = Uint8Array.from(bytes);\n unsigned[31] = unsigned[31] & 127;\n const hex = [...unsigned].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n return SMALL_ORDER_KEYS.includes(hex);\n}\nasync function scopeStoreKeyId(publicKey) {\n const bytes = base64UrlToBytes(publicKey);\n if (!bytes || bytes.length !== 32)\n throw new Error(\"a store public key is not 32 bytes of base64url\");\n if (isSmallOrderKey(bytes))\n throw new Error(\"a store public key is a small-order point\");\n const hash = await crypto.subtle.digest(\"SHA-256\", copyBytes(bytes));\n return bytesToBase64Url(new Uint8Array(hash).slice(0, 8));\n}\nfunction scopeStorePublicKeyProblem(key) {\n if (key.length === 0)\n return \"empty\";\n const bytes = base64UrlToBytes(key);\n if (bytes?.length !== 32)\n return \"length\";\n if (isSmallOrderKey(bytes))\n return \"small-order\";\n if (bytesToBase64Url(bytes) !== key)\n return \"non-canonical\";\n return void 0;\n}\nvar PUBLIC_KEY_PROBLEM = {\n empty: \"a store public key list is empty or has an empty entry\",\n length: \"a store public key is not 32 bytes of base64url\",\n \"small-order\": \"a store public key is a small-order point\",\n \"non-canonical\": \"a store public key is not canonical base64url\"\n};\nfunction parseScopeStorePublicKeys(text) {\n const keys = text.split(\",\").map((key) => key.trim());\n if (keys.some((key) => key.length === 0))\n throw new Error(PUBLIC_KEY_PROBLEM.empty);\n const seen = /* @__PURE__ */ new Set();\n for (const key of keys) {\n const problem = scopeStorePublicKeyProblem(key);\n if (problem)\n throw new Error(PUBLIC_KEY_PROBLEM[problem]);\n if (seen.has(key))\n throw new Error(\"a store public key is listed twice\");\n seen.add(key);\n }\n return keys;\n}\nfunction scopeStorePublicKeysFrom(config) {\n const caller = parseScopeStorePublicKeys(config.caller);\n const platform = parseScopeStorePublicKeys(config.platform);\n if (caller.some((key) => platform.includes(key))) {\n throw new Error(\"a store public key is listed for both audiences\");\n }\n return { caller, platform };\n}\nasync function verifyScopeStoreEnvelope(publicKey, canonical, signature) {\n const keyBytes = base64UrlToBytes(publicKey);\n const sigBytes = base64UrlToBytes(signature);\n if (!keyBytes || !sigBytes || sigBytes.length !== 64)\n return false;\n try {\n const key = await crypto.subtle.importKey(\"raw\", copyBytes(keyBytes), { name: \"Ed25519\" }, false, [\"verify\"]);\n return await crypto.subtle.verify(\"Ed25519\", key, copyBytes(sigBytes), new TextEncoder().encode(canonical));\n } catch {\n return false;\n }\n}\nasync function verifyScopeStoreCall(input) {\n const refuse = (refusal2) => ({ ok: false, refusal: refusal2 });\n if (!input.envelope || !input.signature)\n return refuse(\"missing\");\n const bytes = base64UrlToBytes(input.envelope);\n if (!bytes)\n return refuse(\"malformed\");\n let canonical;\n try {\n canonical = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch {\n return refuse(\"malformed\");\n }\n const envelope = parseScopeStoreEnvelope(canonical);\n if (!envelope)\n return refuse(\"malformed\");\n if (!scopeStoreEnvelopeAdmits(envelope.v, envelope.aud, envelope.op))\n return refuse(\"audience\");\n const kidsOf = async (keys) => {\n const kids = /* @__PURE__ */ new Map();\n for (const key of keys) {\n try {\n kids.set(await scopeStoreKeyId(key), key);\n } catch {\n }\n }\n return kids;\n };\n const own = await kidsOf(input.keys[envelope.aud]);\n const other = await kidsOf(input.keys[envelope.aud === \"caller\" ? \"platform\" : \"caller\"]);\n if ([...own.keys()].some((kid) => other.has(kid)))\n return refuse(\"keys\");\n const publicKey = own.get(envelope.kid);\n if (!publicKey)\n return refuse(\"kid\");\n if (!await verifyScopeStoreEnvelope(publicKey, canonical, input.signature))\n return refuse(\"signature\");\n if (envelope.digest !== await scopeStoreBodyDigest(input.body))\n return refuse(\"digest\");\n if (!scopeStoreEnvelopeFresh(envelope.iat, input.nowSeconds, input.windowSeconds))\n return refuse(\"stale\");\n if (envelope.script !== input.script)\n return refuse(\"script\");\n let parsed;\n try {\n parsed = JSON.parse(input.body);\n } catch {\n return refuse(\"body\");\n }\n const field = (key) => typeof parsed === \"object\" && parsed !== null ? Reflect.get(parsed, key) : void 0;\n if (field(\"operation\") !== envelope.op || field(\"objectName\") !== envelope.name)\n return refuse(\"body\");\n return { ok: true, envelope };\n}\n\n// packages/control-plane-api/store-entry/verify.ts\nvar tooLarge = { ok: false, status: 413, message: `payload too large: at most ${STORE_CALL_MAX_BYTES} bytes` };\nfunction storeCallDeclaredRefusal(headers) {\n const declared = headers.get(\"content-length\");\n return declared !== null && /^\\d+$/.test(declared.trim()) && Number(declared) > STORE_CALL_MAX_BYTES ? tooLarge : void 0;\n}\nasync function boundedBody(body) {\n if (!body) return new Uint8Array(0);\n const reader = body.getReader();\n const chunks = [];\n let total = 0;\n for (; ; ) {\n const { done, value } = await reader.read();\n if (done || !value) break;\n total += value.byteLength;\n if (total > STORE_CALL_MAX_BYTES) {\n await reader.cancel().catch(() => void 0);\n return tooLarge;\n }\n chunks.push(value);\n }\n const bytes = new Uint8Array(total);\n let at = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, at);\n at += chunk.byteLength;\n }\n return bytes;\n}\nasync function verifiedStoreCall(request, env) {\n const declared = storeCallDeclaredRefusal(request.headers);\n if (declared) return declared;\n const bytes = await boundedBody(request.body);\n if (!(bytes instanceof Uint8Array)) return bytes;\n let text;\n try {\n text = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n } catch {\n return { ok: false, status: 401, message: \"unauthorized: digest\" };\n }\n const verdict = await storeCallVerdict(request.headers, text, env);\n return verdict.ok ? { ok: true, envelope: verdict.envelope, body: bytes.buffer } : verdict;\n}\nvar STORE_NONCE_KEY_PREFIX = \"substrat.store-nonce/\";\nvar STORE_NONCE_PRUNE_BATCH = 64;\nvar nonceKey = (iat) => `${STORE_NONCE_KEY_PREFIX}${String(iat).padStart(15, \"0\")}/`;\nfunction spendStoreNonce(storage, envelope, nowSeconds) {\n const { kv } = storage;\n const expired = nonceKey(nowSeconds - SCOPE_STORE_ENVELOPE_WINDOW_SECONDS);\n for (const [key2] of kv.list({ prefix: STORE_NONCE_KEY_PREFIX, end: expired, limit: STORE_NONCE_PRUNE_BATCH })) kv.delete(key2);\n if (!scopeStoreEnvelopeFresh(envelope.iat, nowSeconds)) return false;\n const key = `${nonceKey(envelope.iat)}${envelope.nonce}`;\n if (kv.get(key) !== void 0) return false;\n kv.put(key, 1);\n return true;\n}\nvar spentNonce = { ok: false, status: 401, message: \"unauthorized: nonce\" };\nasync function storeCallVerdict(headers, body, env) {\n const script = env[STORE_SCRIPT_VAR];\n let keys;\n try {\n if (typeof script !== \"string\" || script.length === 0) throw new Error(\"no script name\");\n keys = scopeStorePublicKeysFrom({\n caller: String(env[STORE_CALLER_KEYS_VAR] ?? \"\"),\n platform: String(env[STORE_PLATFORM_KEYS_VAR] ?? \"\")\n });\n } catch {\n return { ok: false, status: 503, message: \"this store script is not configured\" };\n }\n const verdict = await verifyScopeStoreCall({\n envelope: headers.get(SCOPE_STORE_ENVELOPE_HEADER),\n signature: headers.get(SCOPE_STORE_SIGNATURE_HEADER),\n body,\n keys,\n script,\n nowSeconds: Math.floor(Date.now() / 1e3)\n });\n return verdict.ok ? verdict : { ok: false, status: 401, message: `unauthorized: ${verdict.refusal}` };\n}\n\n// packages/control-plane-api/store-entry/entry.ts\nvar Driver = driverModule[\"__SUBSTRAT_STORE_CLASS__\"];\nvar refusal = ({ status, message }) => new Response(message, { status });\nfunction driverEnvOf(env) {\n return Object.fromEntries(Object.entries(env).filter(([name]) => !name.startsWith(STORE_RESERVED_BINDING_PREFIX)));\n}\nasync function verified(request, env) {\n const call = await verifiedStoreCall(request, env);\n return call.ok ? call : refusal(call);\n}\nvar SubstratStoreObject = class extends DurableObject {\n #driver;\n /** Constructed once per object instance, on first use, so the driver keeps its in-memory state. */\n #driverObject() {\n this.#driver ??= new Driver(this.ctx, driverEnvOf(this.env));\n return this.#driver;\n }\n async fetch(request) {\n const call = await verified(request, this.env);\n if (call instanceof Response) return call;\n const ns = this.env[STORE_OBJECT_BINDING];\n if (!this.ctx.id.equals(ns.idFromName(call.envelope.name))) return new Response(\"unauthorized: object\", { status: 401 });\n if (!spendStoreNonce(this.ctx.storage, call.envelope, Math.floor(Date.now() / 1e3))) return refusal(spentNonce);\n return this.#driverObject().fetch(\n new Request(request.url, { method: \"POST\", headers: { \"content-type\": \"application/json\" }, body: call.body })\n );\n }\n /** An alarm is the object's own timer, which only the driver sets. It goes to the driver. */\n async alarm(alarmInfo) {\n const driver = this.#driverObject();\n if (typeof driver.alarm === \"function\") await driver.alarm(alarmInfo);\n }\n};\nvar entry_default = {\n async fetch(request, env) {\n const call = await verified(request, env);\n if (call instanceof Response) return call;\n const ns = env[STORE_OBJECT_BINDING];\n return ns.get(ns.idFromName(call.envelope.name)).fetch(\n new Request(request.url, { method: \"POST\", headers: request.headers, body: call.body })\n );\n }\n};\nexport {\n SubstratStoreObject,\n entry_default as default\n};\n";
55
+ /** The entry itself — 18339 bytes of ESM. */
56
+ export const STORE_ENTRY_SOURCE = "// packages/control-plane-api/store-entry/entry.ts\nimport { DurableObject } from \"cloudflare:workers\";\nimport * as driverModule from \"__SUBSTRAT_STORE_DRIVER__\";\n\n// packages/contracts/dist/scope-store-envelope.js\nvar SCOPE_STORE_ENVELOPE_WINDOW_SECONDS = 60;\nvar SCOPE_STORE_ENVELOPE_HEADER = \"x-substrat-store-envelope\";\nvar SCOPE_STORE_SIGNATURE_HEADER = \"x-substrat-store-signature\";\nvar RESERVED_STORE_OPERATIONS = [\n \"substrat.export-page\",\n \"substrat.stage-page\",\n \"substrat.commit-stage\",\n \"substrat.discard-stage\",\n \"substrat.size\",\n \"substrat.wipe\",\n \"substrat.erase\",\n \"substrat.selfcheck\"\n];\nvar STORE_FENCE_OPERATION = \"substrat.fence\";\nvar STORE_FENCED_CODE = \"store_fenced\";\nvar STORE_FENCE_DRAINING_CODE = \"store_fence_draining\";\nvar STORE_STAGE_MAX_AGE_MS = 6 * 36e5 + 3 * 30 * 6e4;\nvar STORE_CALL_MAX_BYTES = 4 * 1024 * 1024;\nvar STORE_DUMP_PAGE_MAX_BYTES = 3 * 1024 * 1024;\nvar ADMITTED = {\n \"1\": {\n platform: (op) => op === STORE_FENCE_OPERATION || RESERVED_STORE_OPERATIONS.includes(op),\n caller: (op) => !op.startsWith(\"substrat.\")\n }\n};\nfunction scopeStoreEnvelopeAdmits(v, aud, op) {\n const byAudience = Object.hasOwn(ADMITTED, String(v)) ? ADMITTED[String(v)] : void 0;\n if (!byAudience || !Object.hasOwn(byAudience, aud))\n return false;\n return byAudience[aud](op);\n}\nfunction bytesToBase64Url(bytes) {\n let binary = \"\";\n for (const byte of bytes)\n binary += String.fromCharCode(byte);\n return btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\nfunction base64UrlToBytes(value) {\n if (!/^[A-Za-z0-9_-]+$/.test(value))\n return void 0;\n const padded = value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + \"=\".repeat((4 - value.length % 4) % 4);\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++)\n bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return void 0;\n }\n}\nfunction copyBytes(bytes) {\n const copy = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(copy).set(bytes);\n return copy;\n}\nfunction isCanonicalBase64Url(text, length) {\n const bytes = base64UrlToBytes(text);\n return bytes?.length === length && bytesToBase64Url(bytes) === text;\n}\nvar NONCE = /^[A-Za-z0-9_-]{22}$/;\nvar KID = /^[A-Za-z0-9_-]{11}$/;\nvar DIGEST = /^[0-9a-f]{64}$/;\nvar IAT = /^(0|[1-9]\\d{0,14})$/;\nfunction parseScopeStoreEnvelope(canonical) {\n const lines = canonical.split(\"\\n\");\n if (lines.length !== 9)\n return void 0;\n const [version, aud, kid, script, name, op, digest, iatText, nonce] = lines;\n if (version !== \"1\" || aud !== \"caller\" && aud !== \"platform\")\n return void 0;\n if (!script || !name || !op)\n return void 0;\n if (!KID.test(kid) || !DIGEST.test(digest) || !IAT.test(iatText) || !NONCE.test(nonce))\n return void 0;\n if (!isCanonicalBase64Url(kid, 8) || !isCanonicalBase64Url(nonce, 16))\n return void 0;\n return { v: 1, aud, kid, script, name, op, digest, iat: Number(iatText), nonce };\n}\nasync function scopeStoreBodyDigest(body) {\n const hash = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(body));\n return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\nfunction scopeStoreEnvelopeFresh(iat, nowSeconds, windowSeconds = SCOPE_STORE_ENVELOPE_WINDOW_SECONDS) {\n return Math.abs(nowSeconds - iat) <= windowSeconds;\n}\nvar SMALL_ORDER_KEYS = [\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n // y = 0, order 4\n \"0100000000000000000000000000000000000000000000000000000000000000\",\n // the identity, order 1\n \"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05\",\n // order 8\n \"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a\",\n // order 8\n \"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p - 1, order 2\n \"edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p, a non-canonical 0\n \"eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\"\n // y = p + 1, a non-canonical identity\n];\nfunction isSmallOrderKey(bytes) {\n const unsigned = Uint8Array.from(bytes);\n unsigned[31] = unsigned[31] & 127;\n const hex = [...unsigned].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n return SMALL_ORDER_KEYS.includes(hex);\n}\nasync function scopeStoreKeyId(publicKey) {\n const bytes = base64UrlToBytes(publicKey);\n if (!bytes || bytes.length !== 32)\n throw new Error(\"a store public key is not 32 bytes of base64url\");\n if (isSmallOrderKey(bytes))\n throw new Error(\"a store public key is a small-order point\");\n const hash = await crypto.subtle.digest(\"SHA-256\", copyBytes(bytes));\n return bytesToBase64Url(new Uint8Array(hash).slice(0, 8));\n}\nfunction scopeStorePublicKeyProblem(key) {\n if (key.length === 0)\n return \"empty\";\n const bytes = base64UrlToBytes(key);\n if (bytes?.length !== 32)\n return \"length\";\n if (isSmallOrderKey(bytes))\n return \"small-order\";\n if (bytesToBase64Url(bytes) !== key)\n return \"non-canonical\";\n return void 0;\n}\nvar PUBLIC_KEY_PROBLEM = {\n empty: \"a store public key list is empty or has an empty entry\",\n length: \"a store public key is not 32 bytes of base64url\",\n \"small-order\": \"a store public key is a small-order point\",\n \"non-canonical\": \"a store public key is not canonical base64url\"\n};\nfunction parseScopeStorePublicKeys(text) {\n const keys = text.split(\",\").map((key) => key.trim());\n if (keys.some((key) => key.length === 0))\n throw new Error(PUBLIC_KEY_PROBLEM.empty);\n const seen = /* @__PURE__ */ new Set();\n for (const key of keys) {\n const problem = scopeStorePublicKeyProblem(key);\n if (problem)\n throw new Error(PUBLIC_KEY_PROBLEM[problem]);\n if (seen.has(key))\n throw new Error(\"a store public key is listed twice\");\n seen.add(key);\n }\n return keys;\n}\nfunction scopeStorePublicKeysFrom(config) {\n const caller = parseScopeStorePublicKeys(config.caller);\n const platform = parseScopeStorePublicKeys(config.platform);\n if (caller.some((key) => platform.includes(key))) {\n throw new Error(\"a store public key is listed for both audiences\");\n }\n return { caller, platform };\n}\nasync function verifyScopeStoreEnvelope(publicKey, canonical, signature) {\n const keyBytes = base64UrlToBytes(publicKey);\n const sigBytes = base64UrlToBytes(signature);\n if (!keyBytes || !sigBytes || sigBytes.length !== 64)\n return false;\n try {\n const key = await crypto.subtle.importKey(\"raw\", copyBytes(keyBytes), { name: \"Ed25519\" }, false, [\"verify\"]);\n return await crypto.subtle.verify(\"Ed25519\", key, copyBytes(sigBytes), new TextEncoder().encode(canonical));\n } catch {\n return false;\n }\n}\nasync function verifyScopeStoreCall(input) {\n const refuse = (refusal2) => ({ ok: false, refusal: refusal2 });\n if (!input.envelope || !input.signature)\n return refuse(\"missing\");\n const bytes = base64UrlToBytes(input.envelope);\n if (!bytes)\n return refuse(\"malformed\");\n let canonical;\n try {\n canonical = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch {\n return refuse(\"malformed\");\n }\n const envelope = parseScopeStoreEnvelope(canonical);\n if (!envelope)\n return refuse(\"malformed\");\n if (!scopeStoreEnvelopeAdmits(envelope.v, envelope.aud, envelope.op))\n return refuse(\"audience\");\n const kidsOf = async (keys) => {\n const kids = /* @__PURE__ */ new Map();\n for (const key of keys) {\n try {\n kids.set(await scopeStoreKeyId(key), key);\n } catch {\n }\n }\n return kids;\n };\n const own = await kidsOf(input.keys[envelope.aud]);\n const other = await kidsOf(input.keys[envelope.aud === \"caller\" ? \"platform\" : \"caller\"]);\n if ([...own.keys()].some((kid) => other.has(kid)))\n return refuse(\"keys\");\n const publicKey = own.get(envelope.kid);\n if (!publicKey)\n return refuse(\"kid\");\n if (!await verifyScopeStoreEnvelope(publicKey, canonical, input.signature))\n return refuse(\"signature\");\n if (envelope.digest !== await scopeStoreBodyDigest(input.body))\n return refuse(\"digest\");\n if (!scopeStoreEnvelopeFresh(envelope.iat, input.nowSeconds, input.windowSeconds))\n return refuse(\"stale\");\n if (envelope.script !== input.script)\n return refuse(\"script\");\n let parsed;\n try {\n parsed = JSON.parse(input.body);\n } catch {\n return refuse(\"body\");\n }\n const field = (key) => typeof parsed === \"object\" && parsed !== null ? Reflect.get(parsed, key) : void 0;\n if (field(\"operation\") !== envelope.op || field(\"objectName\") !== envelope.name)\n return refuse(\"body\");\n return { ok: true, envelope };\n}\n\n// packages/control-plane-api/store-entry/names.ts\nvar STORE_FENCE_KEY = \"_substrat_store_fence\";\nvar STORE_OBJECT_BINDING = \"SUBSTRAT_STORE\";\nvar STORE_SCRIPT_VAR = \"SUBSTRAT_STORE_SCRIPT\";\nvar STORE_CALLER_KEYS_VAR = \"SUBSTRAT_STORE_CALLER_KEYS\";\nvar STORE_PLATFORM_KEYS_VAR = \"SUBSTRAT_STORE_PLATFORM_KEYS\";\nvar STORE_RESERVED_BINDING_PREFIX = \"SUBSTRAT_STORE\";\n\n// packages/control-plane-api/store-entry/fence.ts\nvar STORE_FENCE_DRAIN_MS = 3e4;\nvar WRITES = /* @__PURE__ */ new Set([\"substrat.stage-page\", \"substrat.commit-stage\"]);\nvar FENCED = {\n ok: false,\n status: 410,\n message: JSON.stringify({\n error: { code: STORE_FENCED_CODE, status: 410, body: { message: \"the scope this store belongs to is being deleted\" } }\n }),\n contentType: \"application/json\"\n};\nvar DRAINING = {\n ok: false,\n status: 503,\n message: JSON.stringify({ error: { code: STORE_FENCE_DRAINING_CODE, status: 503 } }),\n contentType: \"application/json\"\n};\nvar PASSED = { ok: true };\nvar StoreObjectFence = class {\n #storage;\n #drainMs;\n /** One instance per object, and every write of the mark goes through it, so once read this is the truth. */\n #fenced;\n #inside = 0;\n #waiting = /* @__PURE__ */ new Set();\n constructor(storage, drainMs) {\n this.#storage = storage;\n this.#drainMs = drainMs;\n }\n async #load() {\n if (this.#fenced !== void 0) return;\n const stored = await this.#storage.get(STORE_FENCE_KEY);\n this.#fenced = this.#fenced === true || stored !== void 0;\n }\n /**\n * Whether a call may go to the driver. Admitted, it counts as inside until `leave`. Nothing awaits\n * between the check and the count, or a `close` could find the object empty with this call on its way in.\n */\n async admit(envelope) {\n await this.#load();\n if (this.#fenced === true && (envelope.aud !== \"platform\" || WRITES.has(envelope.op))) return FENCED;\n this.#inside += 1;\n return PASSED;\n }\n /** Whether the driver's alarm may run: never on a fenced object. Admitted, it counts as inside until `leave`. */\n async admitAlarm() {\n await this.#load();\n if (this.#fenced === true) return false;\n this.#inside += 1;\n return true;\n }\n /** An admitted call is done. On a fenced object the mark is written again, whatever that call's driver did. */\n async leave() {\n this.#inside -= 1;\n if (this.#inside === 0) {\n for (const drained of this.#waiting) drained();\n this.#waiting.clear();\n }\n if (this.#fenced === true) await this.reassert();\n }\n /** Mark the object, durably, then wait out what is inside it. Past the wait it answers 503, and the mark stays. */\n async close() {\n this.#fenced = true;\n await this.reassert();\n return await this.#drained() ? PASSED : DRAINING;\n }\n /** Write the mark, after a step that may have taken it with everything else. */\n async reassert() {\n await this.#storage.put(STORE_FENCE_KEY, true);\n }\n #drained() {\n if (this.#inside === 0) return Promise.resolve(true);\n return new Promise((resolve) => {\n const drained = () => {\n clearTimeout(timer);\n resolve(true);\n };\n const timer = setTimeout(() => {\n this.#waiting.delete(drained);\n resolve(false);\n }, this.#drainMs);\n this.#waiting.add(drained);\n });\n }\n};\nfunction storeObjectFence(storage, drainMs = STORE_FENCE_DRAIN_MS) {\n return new StoreObjectFence(storage, drainMs);\n}\nfunction storeFenceWipeBody(body) {\n const call = JSON.parse(new TextDecoder().decode(body));\n return new TextEncoder().encode(JSON.stringify({ ...call, operation: \"substrat.wipe\" })).buffer;\n}\nasync function callThroughFence(fence, call, forward) {\n if (call.envelope.op === STORE_FENCE_OPERATION) {\n const closed = await fence.close();\n if (!closed.ok) return closed;\n try {\n return await forward(storeFenceWipeBody(call.body));\n } finally {\n await fence.reassert();\n }\n }\n const admitted = await fence.admit(call.envelope);\n if (!admitted.ok) return admitted;\n try {\n return await forward(call.body);\n } finally {\n await fence.leave();\n }\n}\n\n// packages/control-plane-api/store-entry/verify.ts\nvar tooLarge = { ok: false, status: 413, message: `payload too large: at most ${STORE_CALL_MAX_BYTES} bytes` };\nfunction storeCallDeclaredRefusal(headers) {\n const declared = headers.get(\"content-length\");\n return declared !== null && /^\\d+$/.test(declared.trim()) && Number(declared) > STORE_CALL_MAX_BYTES ? tooLarge : void 0;\n}\nasync function boundedBody(body) {\n if (!body) return new Uint8Array(0);\n const reader = body.getReader();\n const chunks = [];\n let total = 0;\n for (; ; ) {\n const { done, value } = await reader.read();\n if (done || !value) break;\n total += value.byteLength;\n if (total > STORE_CALL_MAX_BYTES) {\n await reader.cancel().catch(() => void 0);\n return tooLarge;\n }\n chunks.push(value);\n }\n const bytes = new Uint8Array(total);\n let at = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, at);\n at += chunk.byteLength;\n }\n return bytes;\n}\nasync function verifiedStoreCall(request, env) {\n const declared = storeCallDeclaredRefusal(request.headers);\n if (declared) return declared;\n const bytes = await boundedBody(request.body);\n if (!(bytes instanceof Uint8Array)) return bytes;\n let text;\n try {\n text = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n } catch {\n return { ok: false, status: 401, message: \"unauthorized: digest\" };\n }\n const verdict = await storeCallVerdict(request.headers, text, env);\n return verdict.ok ? { ok: true, envelope: verdict.envelope, body: bytes.buffer } : verdict;\n}\nvar STORE_NONCE_KEY_PREFIX = \"substrat.store-nonce/\";\nvar STORE_NONCE_PRUNE_BATCH = 64;\nvar nonceKey = (iat) => `${STORE_NONCE_KEY_PREFIX}${String(iat).padStart(15, \"0\")}/`;\nfunction spendStoreNonce(storage, envelope, nowSeconds) {\n const { kv } = storage;\n const expired = nonceKey(nowSeconds - SCOPE_STORE_ENVELOPE_WINDOW_SECONDS);\n for (const [key2] of kv.list({ prefix: STORE_NONCE_KEY_PREFIX, end: expired, limit: STORE_NONCE_PRUNE_BATCH })) kv.delete(key2);\n if (!scopeStoreEnvelopeFresh(envelope.iat, nowSeconds)) return false;\n const key = `${nonceKey(envelope.iat)}${envelope.nonce}`;\n if (kv.get(key) !== void 0) return false;\n kv.put(key, 1);\n return true;\n}\nvar spentNonce = { ok: false, status: 401, message: \"unauthorized: nonce\" };\nasync function storeCallVerdict(headers, body, env) {\n const script = env[STORE_SCRIPT_VAR];\n let keys;\n try {\n if (typeof script !== \"string\" || script.length === 0) throw new Error(\"no script name\");\n keys = scopeStorePublicKeysFrom({\n caller: String(env[STORE_CALLER_KEYS_VAR] ?? \"\"),\n platform: String(env[STORE_PLATFORM_KEYS_VAR] ?? \"\")\n });\n } catch {\n return { ok: false, status: 503, message: \"this store script is not configured\" };\n }\n const verdict = await verifyScopeStoreCall({\n envelope: headers.get(SCOPE_STORE_ENVELOPE_HEADER),\n signature: headers.get(SCOPE_STORE_SIGNATURE_HEADER),\n body,\n keys,\n script,\n nowSeconds: Math.floor(Date.now() / 1e3)\n });\n return verdict.ok ? verdict : { ok: false, status: 401, message: `unauthorized: ${verdict.refusal}` };\n}\n\n// packages/control-plane-api/store-entry/entry.ts\nvar Driver = driverModule[\"__SUBSTRAT_STORE_CLASS__\"];\nvar refusal = ({ status, message, contentType }) => new Response(message, { status, headers: contentType ? { \"content-type\": contentType } : void 0 });\nfunction driverEnvOf(env) {\n return Object.fromEntries(Object.entries(env).filter(([name]) => !name.startsWith(STORE_RESERVED_BINDING_PREFIX)));\n}\nasync function verified(request, env) {\n const call = await verifiedStoreCall(request, env);\n return call.ok ? call : refusal(call);\n}\nvar SubstratStoreObject = class extends DurableObject {\n #driver;\n #fence;\n #fenceOf() {\n this.#fence ??= storeObjectFence(this.ctx.storage);\n return this.#fence;\n }\n /** Constructed once per object instance, on first use, so the driver keeps its in-memory state. */\n #driverObject() {\n this.#driver ??= new Driver(this.ctx, driverEnvOf(this.env));\n return this.#driver;\n }\n async fetch(request) {\n const call = await verified(request, this.env);\n if (call instanceof Response) return call;\n const ns = this.env[STORE_OBJECT_BINDING];\n if (!this.ctx.id.equals(ns.idFromName(call.envelope.name))) return new Response(\"unauthorized: object\", { status: 401 });\n if (!spendStoreNonce(this.ctx.storage, call.envelope, Math.floor(Date.now() / 1e3))) return refusal(spentNonce);\n const answer = await callThroughFence(\n this.#fenceOf(),\n call,\n (body) => this.#driverObject().fetch(new Request(request.url, { method: \"POST\", headers: { \"content-type\": \"application/json\" }, body }))\n );\n return answer instanceof Response ? answer : refusal(answer);\n }\n /** An alarm is the object's own timer, which only the driver sets. It goes to the driver, unless the object is fenced. */\n async alarm(alarmInfo) {\n const fence = this.#fenceOf();\n if (!await fence.admitAlarm()) return;\n try {\n const driver = this.#driverObject();\n if (typeof driver.alarm === \"function\") await driver.alarm(alarmInfo);\n } finally {\n await fence.leave();\n }\n }\n};\nvar entry_default = {\n async fetch(request, env) {\n const call = await verified(request, env);\n if (call instanceof Response) return call;\n const ns = env[STORE_OBJECT_BINDING];\n return ns.get(ns.idFromName(call.envelope.name)).fetch(\n new Request(request.url, { method: \"POST\", headers: request.headers, body: call.body })\n );\n }\n};\nexport {\n SubstratStoreObject,\n entry_default as default\n};\n";
51
57
  /**
52
58
  * The Python entry (#2290), uploaded as `substrat_store_entry.py`. The driver module's
53
59
  * name (a Python module name, no `.py`) replaces `__SUBSTRAT_STORE_DRIVER__` and its class
54
60
  * name replaces `__SUBSTRAT_STORE_CLASS__`, as in the JavaScript entry.
55
61
  */
56
- export const STORE_ENTRY_PYTHON_SOURCE = "\"\"\"The platform's Python store entry (#2290), the twin of store-entry/entry.ts.\n\nUploaded as the store script's main module when the driver is Python. The driver's class is\nimported through the two placeholders below, which the upload replaces with the driver's module\nname and class name, as it does for the JavaScript entry. The driver is reached only through\nthis module, after the call is verified.\n\nThere is one verifier. Every call is checked by store-entry/verify.ts, bundled as an ES module\nthe upload ships beside this one and imported through the runtime's JavaScript bridge. It runs\ncontracts' verifyScopeStoreCall (RFC scope-stores section 10.3, checks 1-4) against the script\nname and both audiences' public keys this upload was given. This module parses no envelope, so\nit cannot disagree with the JavaScript entry about one. The default entrypoint addresses\nSubstratStoreObject by idFromName of the signed name. The object checks the call again, and\nrefuses unless its own id is the id of that name (check 5), before the driver is constructed: an\nobject is bound to one name by construction, with nothing stored that the driver could rewrite. It\nthen spends the envelope's nonce through the verifier's spendStoreNonce (K-59), so one envelope is\nadmitted once.\n\nThe body stays in JavaScript (#2811). The verifier module reads it once, bounded by STORE_CALL_MAX_BYTES\n(a declared Content-Length over the limit is refused with 413 before the body is read, and a stream\nthat goes past it is refused at the limit), verifies it as the text those bytes decode to, and hands\nback the bytes as an ArrayBuffer. That buffer is what the default entrypoint forwards to the object\nand what the driver's Request is built over, so this module makes no Python string of the body: the\ndriver reads it as text only if it asks for text. The body used to be read twice and copied to Python\neach time, which failed with exceededMemory from about 6 MB.\nThe driver is constructed once per object instance with the object's ctx and an env with none of\nthe entry's SUBSTRAT_STORE* bindings. The upload sets disallow_importable_env and\ndisable_ctx_exports, and both apply to a Python script: `from workers import env` then reads an\nempty env, and ctx.exports is absent.\n\nWhat this is not: a boundary against a hostile driver, and it is weaker here than in JavaScript.\nPython has no private fields. The driver's module is imported by this one, before this module's\nbody has finished, and runs in the same interpreter: it can reach this module through\nsys.modules and replace its functions, and it can reach the entry's object, its full env and the\nstore namespace in it, through the garbage collector. The env strip and the cached driver keep a\ncareless driver away from the entry's bindings, not a hostile one. A driver written to interfere is\nstopped by the review of its release (D-63), not by this module.\n\"\"\"\n\nfrom workers import DurableObject, Request, Response, WorkerEntrypoint, import_from_javascript\nfrom js import Date, Object\n\nfrom __SUBSTRAT_STORE_DRIVER__ import __SUBSTRAT_STORE_CLASS__ as StoreDriver\n\n# Each of these is a name in store-entry/names.ts; test/python-entry.test.ts holds them equal.\nVERIFIER_MODULE = \"./substrat-store-verify.js\"\nOBJECT_BINDING = \"SUBSTRAT_STORE\"\nRESERVED_BINDING_PREFIX = \"SUBSTRAT_STORE\"\n\n\ndef _unwrapped(value, attribute):\n \"\"\"The JavaScript object under the SDK's wrapper, or the value itself when nothing wraps it.\n\n The SDK pywrangler installs wraps env and ctx, with no public unwrap. An upload does not ship that\n SDK, and the runtime's own may hand either over unwrapped, so the private attribute can be absent\n on a deployed object (a deployed ctx has no `_ctx`). Every unwrap in this module goes through here.\n \"\"\"\n return getattr(value, attribute, value)\n\n\ndef _raw_env(env):\n \"\"\"The JavaScript env the runtime handed over.\"\"\"\n return _unwrapped(env, \"_env\")\n\n\ndef _raw_storage(ctx):\n \"\"\"The object's JavaScript storage.\"\"\"\n return _unwrapped(ctx, \"_ctx\").storage\n\n\ndef _driver_env(env):\n \"\"\"The env the driver is constructed with: everything but the entry's own bindings.\"\"\"\n entries = [entry for entry in Object.entries(_raw_env(env)) if not str(entry[0]).startswith(RESERVED_BINDING_PREFIX)]\n return Object.fromEntries(entries)\n\n\ndef _refusal(verified):\n \"\"\"The response for a refused call: its status and its plain-text message.\"\"\"\n return Response(verified.message, status=verified.status)\n\n\nasync def _verified(request, env):\n \"\"\"The call read once and verified (its envelope and its body as a JavaScript ArrayBuffer), or the refusal.\"\"\"\n verifier = import_from_javascript(VERIFIER_MODULE)\n verified = await verifier.verifiedStoreCall(request.js_object, _raw_env(env))\n return verified if verified.ok else _refusal(verified)\n\n\ndef _driver_request(url, body):\n return Request(url, method=\"POST\", headers={\"content-type\": \"application/json\"}, body=body)\n\n\nclass SubstratStoreObject(DurableObject):\n def __init__(self, ctx, env):\n super().__init__(ctx, env)\n self._driver = None\n\n def _driver_object(self):\n \"\"\"Constructed once per object instance, on first use, so the driver keeps its in-memory state.\"\"\"\n if self._driver is None:\n self._driver = StoreDriver(self.ctx, _driver_env(self.env))\n return self._driver\n\n async def fetch(self, request):\n call = await _verified(request, self.env)\n if isinstance(call, Response):\n return call\n namespace = getattr(self.env, OBJECT_BINDING)\n if not self.ctx.id.equals(namespace.idFromName(call.envelope.name)):\n return Response(\"unauthorized: object\", status=401)\n verifier = import_from_javascript(VERIFIER_MODULE)\n if not verifier.spendStoreNonce(_raw_storage(self.ctx), call.envelope, int(Date.now() // 1000)):\n return _refusal(verifier.spentNonce)\n return await self._driver_object().fetch(_driver_request(request.url, call.body))\n\n async def alarm(self, alarm_info=None):\n \"\"\"An alarm is the object's own timer, which only the driver sets. It goes to the driver.\"\"\"\n driver = self._driver_object()\n if hasattr(driver, \"alarm\"):\n await driver.alarm(alarm_info)\n\n\nclass Default(WorkerEntrypoint):\n async def fetch(self, request):\n call = await _verified(request, self.env)\n if isinstance(call, Response):\n return call\n namespace = getattr(self.env, OBJECT_BINDING)\n stub = namespace.get(namespace.idFromName(call.envelope.name))\n return await stub.fetch(request.url, method=\"POST\", headers=request.js_object.headers, body=call.body)\n";
62
+ export const STORE_ENTRY_PYTHON_SOURCE = "\"\"\"The platform's Python store entry (#2290), the twin of store-entry/entry.ts.\n\nUploaded as the store script's main module when the driver is Python. The driver's class is\nimported through the two placeholders below, which the upload replaces with the driver's module\nname and class name, as it does for the JavaScript entry. The driver is reached only through\nthis module, after the call is verified.\n\nThere is one verifier. Every call is checked by store-entry/verify.ts, bundled as an ES module\nthe upload ships beside this one and imported through the runtime's JavaScript bridge. It runs\ncontracts' verifyScopeStoreCall (RFC scope-stores section 10.3, checks 1-4) against the script\nname and both audiences' public keys this upload was given. This module parses no envelope, so\nit cannot disagree with the JavaScript entry about one. The default entrypoint addresses\nSubstratStoreObject by idFromName of the signed name. The object checks the call again, and\nrefuses unless its own id is the id of that name (check 5), before the driver is constructed: an\nobject is bound to one name by construction, with nothing stored that the driver could rewrite. It\nthen spends the envelope's nonce through the verifier's spendStoreNonce (K-59), so one envelope is\nadmitted once.\n\nInside the object, a call passes the fence (store-entry/fence.ts, D-71) before it reaches the\ndriver, the same fence the JavaScript entry runs, from the same module. An object a deletion path\nhas fenced refuses it, whenever it was signed.\n\nThe body stays in JavaScript (#2811). The verifier module reads it once, bounded by STORE_CALL_MAX_BYTES\n(a declared Content-Length over the limit is refused with 413 before the body is read, and a stream\nthat goes past it is refused at the limit), verifies it as the text those bytes decode to, and hands\nback the bytes as an ArrayBuffer. That buffer is what the default entrypoint forwards to the object\nand what the driver's Request is built over, so this module makes no Python string of the body: the\ndriver reads it as text only if it asks for text. The body used to be read twice and copied to Python\neach time, which failed with exceededMemory from about 6 MB.\nThe driver is constructed once per object instance with the object's ctx and an env with none of\nthe entry's SUBSTRAT_STORE* bindings. The upload sets disallow_importable_env and\ndisable_ctx_exports, and both apply to a Python script: `from workers import env` then reads an\nempty env, and ctx.exports is absent.\n\nWhat this is not: a boundary against a hostile driver, and it is weaker here than in JavaScript.\nPython has no private fields. The driver's module is imported by this one, before this module's\nbody has finished, and runs in the same interpreter: it can reach this module through\nsys.modules and replace its functions, and it can reach the entry's object, its full env and the\nstore namespace in it, through the garbage collector. The env strip and the cached driver keep a\ncareless driver away from the entry's bindings, not a hostile one. A driver written to interfere is\nstopped by the review of its release (D-63), not by this module.\n\"\"\"\n\nfrom workers import DurableObject, Request, Response, WorkerEntrypoint, import_from_javascript\nfrom js import Date, Object\n\nfrom __SUBSTRAT_STORE_DRIVER__ import __SUBSTRAT_STORE_CLASS__ as StoreDriver\n\n# Each of these is a name in store-entry/names.ts; test/python-entry.test.ts holds them equal.\nVERIFIER_MODULE = \"./substrat-store-verify.js\"\nOBJECT_BINDING = \"SUBSTRAT_STORE\"\nFENCE_OPERATION = \"substrat.fence\"\nRESERVED_BINDING_PREFIX = \"SUBSTRAT_STORE\"\n\n\ndef _unwrapped(value, attribute):\n \"\"\"The JavaScript object under the SDK's wrapper, or the value itself when nothing wraps it.\n\n The SDK pywrangler installs wraps env and ctx, with no public unwrap. An upload does not ship that\n SDK, and the runtime's own may hand either over unwrapped, so the private attribute can be absent\n on a deployed object (a deployed ctx has no `_ctx`). Every unwrap in this module goes through here.\n \"\"\"\n return getattr(value, attribute, value)\n\n\ndef _raw_env(env):\n \"\"\"The JavaScript env the runtime handed over.\"\"\"\n return _unwrapped(env, \"_env\")\n\n\ndef _raw_storage(ctx):\n \"\"\"The object's JavaScript storage.\"\"\"\n return _unwrapped(ctx, \"_ctx\").storage\n\n\ndef _driver_env(env):\n \"\"\"The env the driver is constructed with: everything but the entry's own bindings.\"\"\"\n entries = [entry for entry in Object.entries(_raw_env(env)) if not str(entry[0]).startswith(RESERVED_BINDING_PREFIX)]\n return Object.fromEntries(entries)\n\n\ndef _refusal(verified):\n \"\"\"The response for a refused call: its status and its message. The entry's own refusals are plain\n text; the fence's 410 and 503 are the store envelope's error, which names its content type.\"\"\"\n content_type = getattr(verified, \"contentType\", None)\n headers = {\"content-type\": content_type} if content_type else None\n return Response(verified.message, status=verified.status, headers=headers)\n\n\nasync def _verified(request, env):\n \"\"\"The call read once and verified (its envelope and its body as a JavaScript ArrayBuffer), or the refusal.\"\"\"\n verifier = import_from_javascript(VERIFIER_MODULE)\n verified = await verifier.verifiedStoreCall(request.js_object, _raw_env(env))\n return verified if verified.ok else _refusal(verified)\n\n\ndef _driver_request(url, body):\n return Request(url, method=\"POST\", headers={\"content-type\": \"application/json\"}, body=body)\n\n\nclass SubstratStoreObject(DurableObject):\n def __init__(self, ctx, env):\n super().__init__(ctx, env)\n self._driver = None\n self._fence = None\n\n def _driver_object(self):\n \"\"\"Constructed once per object instance, on first use, so the driver keeps its in-memory state.\"\"\"\n if self._driver is None:\n self._driver = StoreDriver(self.ctx, _driver_env(self.env))\n return self._driver\n\n def _fence_of(self):\n \"\"\"One fence per object instance, as in the JavaScript entry. The verifier module holds it.\n\n The fence is JavaScript and calls this storage after this function has returned, so it is\n handed the JavaScript object. Under workers-runtime-sdk's DurableObjectContext, ctx.storage is\n a Python wrapper that reaches JavaScript as a borrowed proxy, destroyed when the call returns,\n and every call would then fail. create_proxy is not the answer: a proxy's .get may be Python's\n __getitem__, so the mark would read as absent and the fence would fail open.\n \"\"\"\n if self._fence is None:\n self._fence = import_from_javascript(VERIFIER_MODULE).storeObjectFence(_raw_storage(self.ctx))\n return self._fence\n\n async def fetch(self, request):\n call = await _verified(request, self.env)\n if isinstance(call, Response):\n return call\n namespace = getattr(self.env, OBJECT_BINDING)\n if not self.ctx.id.equals(namespace.idFromName(call.envelope.name)):\n return Response(\"unauthorized: object\", status=401)\n verifier = import_from_javascript(VERIFIER_MODULE)\n if not verifier.spendStoreNonce(_raw_storage(self.ctx), call.envelope, int(Date.now() // 1000)):\n return _refusal(verifier.spentNonce)\n fence = self._fence_of()\n if call.envelope.op == FENCE_OPERATION:\n closed = await fence.close()\n if not closed.ok:\n return _refusal(closed)\n body = verifier.storeFenceWipeBody(call.body)\n try:\n return await self._driver_object().fetch(_driver_request(request.url, body))\n finally:\n await fence.reassert()\n admitted = await fence.admit(call.envelope)\n if not admitted.ok:\n return _refusal(admitted)\n try:\n return await self._driver_object().fetch(_driver_request(request.url, call.body))\n finally:\n await fence.leave()\n\n async def alarm(self, alarm_info=None):\n \"\"\"An alarm is the object's own timer, which only the driver sets. It goes to the driver, unless the object is fenced.\"\"\"\n fence = self._fence_of()\n if not await fence.admitAlarm():\n return\n try:\n driver = self._driver_object()\n if hasattr(driver, \"alarm\"):\n await driver.alarm(alarm_info)\n finally:\n await fence.leave()\n\n\nclass Default(WorkerEntrypoint):\n async def fetch(self, request):\n call = await _verified(request, self.env)\n if isinstance(call, Response):\n return call\n namespace = getattr(self.env, OBJECT_BINDING)\n stub = namespace.get(namespace.idFromName(call.envelope.name))\n return await stub.fetch(request.url, method=\"POST\", headers=request.js_object.headers, body=call.body)\n";
57
63
  /**
58
64
  * The verifier the Python entry imports, uploaded beside it as `substrat-store-verify.js`
59
- * (an ES module). It is `packages/control-plane-api/store-entry/verify.ts`, the check the JavaScript entry runs — 11756 bytes.
65
+ * (an ES module). It is `packages/control-plane-api/store-entry/verify.ts`, the check the JavaScript entry runs — 15249 bytes.
60
66
  */
61
- export const STORE_ENTRY_PYTHON_VERIFIER_SOURCE = "// packages/contracts/dist/scope-store-envelope.js\nvar SCOPE_STORE_ENVELOPE_WINDOW_SECONDS = 60;\nvar SCOPE_STORE_ENVELOPE_HEADER = \"x-substrat-store-envelope\";\nvar SCOPE_STORE_SIGNATURE_HEADER = \"x-substrat-store-signature\";\nvar RESERVED_STORE_OPERATIONS = [\n \"substrat.export-page\",\n \"substrat.stage-page\",\n \"substrat.commit-stage\",\n \"substrat.discard-stage\",\n \"substrat.size\",\n \"substrat.wipe\",\n \"substrat.erase\",\n \"substrat.selfcheck\"\n];\nvar STORE_STAGE_MAX_AGE_MS = 6 * 36e5 + 3 * 30 * 6e4;\nvar STORE_CALL_MAX_BYTES = 4 * 1024 * 1024;\nvar STORE_DUMP_PAGE_MAX_BYTES = 3 * 1024 * 1024;\nvar ADMITTED = {\n \"1\": {\n platform: (op) => RESERVED_STORE_OPERATIONS.includes(op),\n caller: (op) => !op.startsWith(\"substrat.\")\n }\n};\nfunction scopeStoreEnvelopeAdmits(v, aud, op) {\n const byAudience = Object.hasOwn(ADMITTED, String(v)) ? ADMITTED[String(v)] : void 0;\n if (!byAudience || !Object.hasOwn(byAudience, aud))\n return false;\n return byAudience[aud](op);\n}\nfunction bytesToBase64Url(bytes) {\n let binary = \"\";\n for (const byte of bytes)\n binary += String.fromCharCode(byte);\n return btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\nfunction base64UrlToBytes(value) {\n if (!/^[A-Za-z0-9_-]+$/.test(value))\n return void 0;\n const padded = value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + \"=\".repeat((4 - value.length % 4) % 4);\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++)\n bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return void 0;\n }\n}\nfunction copyBytes(bytes) {\n const copy = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(copy).set(bytes);\n return copy;\n}\nfunction isCanonicalBase64Url(text, length) {\n const bytes = base64UrlToBytes(text);\n return bytes?.length === length && bytesToBase64Url(bytes) === text;\n}\nvar NONCE = /^[A-Za-z0-9_-]{22}$/;\nvar KID = /^[A-Za-z0-9_-]{11}$/;\nvar DIGEST = /^[0-9a-f]{64}$/;\nvar IAT = /^(0|[1-9]\\d{0,14})$/;\nfunction parseScopeStoreEnvelope(canonical) {\n const lines = canonical.split(\"\\n\");\n if (lines.length !== 9)\n return void 0;\n const [version, aud, kid, script, name, op, digest, iatText, nonce] = lines;\n if (version !== \"1\" || aud !== \"caller\" && aud !== \"platform\")\n return void 0;\n if (!script || !name || !op)\n return void 0;\n if (!KID.test(kid) || !DIGEST.test(digest) || !IAT.test(iatText) || !NONCE.test(nonce))\n return void 0;\n if (!isCanonicalBase64Url(kid, 8) || !isCanonicalBase64Url(nonce, 16))\n return void 0;\n return { v: 1, aud, kid, script, name, op, digest, iat: Number(iatText), nonce };\n}\nasync function scopeStoreBodyDigest(body) {\n const hash = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(body));\n return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\nfunction scopeStoreEnvelopeFresh(iat, nowSeconds, windowSeconds = SCOPE_STORE_ENVELOPE_WINDOW_SECONDS) {\n return Math.abs(nowSeconds - iat) <= windowSeconds;\n}\nvar SMALL_ORDER_KEYS = [\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n // y = 0, order 4\n \"0100000000000000000000000000000000000000000000000000000000000000\",\n // the identity, order 1\n \"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05\",\n // order 8\n \"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a\",\n // order 8\n \"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p - 1, order 2\n \"edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p, a non-canonical 0\n \"eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\"\n // y = p + 1, a non-canonical identity\n];\nfunction isSmallOrderKey(bytes) {\n const unsigned = Uint8Array.from(bytes);\n unsigned[31] = unsigned[31] & 127;\n const hex = [...unsigned].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n return SMALL_ORDER_KEYS.includes(hex);\n}\nasync function scopeStoreKeyId(publicKey) {\n const bytes = base64UrlToBytes(publicKey);\n if (!bytes || bytes.length !== 32)\n throw new Error(\"a store public key is not 32 bytes of base64url\");\n if (isSmallOrderKey(bytes))\n throw new Error(\"a store public key is a small-order point\");\n const hash = await crypto.subtle.digest(\"SHA-256\", copyBytes(bytes));\n return bytesToBase64Url(new Uint8Array(hash).slice(0, 8));\n}\nfunction scopeStorePublicKeyProblem(key) {\n if (key.length === 0)\n return \"empty\";\n const bytes = base64UrlToBytes(key);\n if (bytes?.length !== 32)\n return \"length\";\n if (isSmallOrderKey(bytes))\n return \"small-order\";\n if (bytesToBase64Url(bytes) !== key)\n return \"non-canonical\";\n return void 0;\n}\nvar PUBLIC_KEY_PROBLEM = {\n empty: \"a store public key list is empty or has an empty entry\",\n length: \"a store public key is not 32 bytes of base64url\",\n \"small-order\": \"a store public key is a small-order point\",\n \"non-canonical\": \"a store public key is not canonical base64url\"\n};\nfunction parseScopeStorePublicKeys(text) {\n const keys = text.split(\",\").map((key) => key.trim());\n if (keys.some((key) => key.length === 0))\n throw new Error(PUBLIC_KEY_PROBLEM.empty);\n const seen = /* @__PURE__ */ new Set();\n for (const key of keys) {\n const problem = scopeStorePublicKeyProblem(key);\n if (problem)\n throw new Error(PUBLIC_KEY_PROBLEM[problem]);\n if (seen.has(key))\n throw new Error(\"a store public key is listed twice\");\n seen.add(key);\n }\n return keys;\n}\nfunction scopeStorePublicKeysFrom(config) {\n const caller = parseScopeStorePublicKeys(config.caller);\n const platform = parseScopeStorePublicKeys(config.platform);\n if (caller.some((key) => platform.includes(key))) {\n throw new Error(\"a store public key is listed for both audiences\");\n }\n return { caller, platform };\n}\nasync function verifyScopeStoreEnvelope(publicKey, canonical, signature) {\n const keyBytes = base64UrlToBytes(publicKey);\n const sigBytes = base64UrlToBytes(signature);\n if (!keyBytes || !sigBytes || sigBytes.length !== 64)\n return false;\n try {\n const key = await crypto.subtle.importKey(\"raw\", copyBytes(keyBytes), { name: \"Ed25519\" }, false, [\"verify\"]);\n return await crypto.subtle.verify(\"Ed25519\", key, copyBytes(sigBytes), new TextEncoder().encode(canonical));\n } catch {\n return false;\n }\n}\nasync function verifyScopeStoreCall(input) {\n const refuse = (refusal) => ({ ok: false, refusal });\n if (!input.envelope || !input.signature)\n return refuse(\"missing\");\n const bytes = base64UrlToBytes(input.envelope);\n if (!bytes)\n return refuse(\"malformed\");\n let canonical;\n try {\n canonical = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch {\n return refuse(\"malformed\");\n }\n const envelope = parseScopeStoreEnvelope(canonical);\n if (!envelope)\n return refuse(\"malformed\");\n if (!scopeStoreEnvelopeAdmits(envelope.v, envelope.aud, envelope.op))\n return refuse(\"audience\");\n const kidsOf = async (keys) => {\n const kids = /* @__PURE__ */ new Map();\n for (const key of keys) {\n try {\n kids.set(await scopeStoreKeyId(key), key);\n } catch {\n }\n }\n return kids;\n };\n const own = await kidsOf(input.keys[envelope.aud]);\n const other = await kidsOf(input.keys[envelope.aud === \"caller\" ? \"platform\" : \"caller\"]);\n if ([...own.keys()].some((kid) => other.has(kid)))\n return refuse(\"keys\");\n const publicKey = own.get(envelope.kid);\n if (!publicKey)\n return refuse(\"kid\");\n if (!await verifyScopeStoreEnvelope(publicKey, canonical, input.signature))\n return refuse(\"signature\");\n if (envelope.digest !== await scopeStoreBodyDigest(input.body))\n return refuse(\"digest\");\n if (!scopeStoreEnvelopeFresh(envelope.iat, input.nowSeconds, input.windowSeconds))\n return refuse(\"stale\");\n if (envelope.script !== input.script)\n return refuse(\"script\");\n let parsed;\n try {\n parsed = JSON.parse(input.body);\n } catch {\n return refuse(\"body\");\n }\n const field = (key) => typeof parsed === \"object\" && parsed !== null ? Reflect.get(parsed, key) : void 0;\n if (field(\"operation\") !== envelope.op || field(\"objectName\") !== envelope.name)\n return refuse(\"body\");\n return { ok: true, envelope };\n}\n\n// packages/control-plane-api/store-entry/names.ts\nvar STORE_SCRIPT_VAR = \"SUBSTRAT_STORE_SCRIPT\";\nvar STORE_CALLER_KEYS_VAR = \"SUBSTRAT_STORE_CALLER_KEYS\";\nvar STORE_PLATFORM_KEYS_VAR = \"SUBSTRAT_STORE_PLATFORM_KEYS\";\n\n// packages/control-plane-api/store-entry/verify.ts\nvar tooLarge = { ok: false, status: 413, message: `payload too large: at most ${STORE_CALL_MAX_BYTES} bytes` };\nfunction storeCallDeclaredRefusal(headers) {\n const declared = headers.get(\"content-length\");\n return declared !== null && /^\\d+$/.test(declared.trim()) && Number(declared) > STORE_CALL_MAX_BYTES ? tooLarge : void 0;\n}\nasync function boundedBody(body) {\n if (!body) return new Uint8Array(0);\n const reader = body.getReader();\n const chunks = [];\n let total = 0;\n for (; ; ) {\n const { done, value } = await reader.read();\n if (done || !value) break;\n total += value.byteLength;\n if (total > STORE_CALL_MAX_BYTES) {\n await reader.cancel().catch(() => void 0);\n return tooLarge;\n }\n chunks.push(value);\n }\n const bytes = new Uint8Array(total);\n let at = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, at);\n at += chunk.byteLength;\n }\n return bytes;\n}\nasync function verifiedStoreCall(request, env) {\n const declared = storeCallDeclaredRefusal(request.headers);\n if (declared) return declared;\n const bytes = await boundedBody(request.body);\n if (!(bytes instanceof Uint8Array)) return bytes;\n let text;\n try {\n text = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n } catch {\n return { ok: false, status: 401, message: \"unauthorized: digest\" };\n }\n const verdict = await storeCallVerdict(request.headers, text, env);\n return verdict.ok ? { ok: true, envelope: verdict.envelope, body: bytes.buffer } : verdict;\n}\nvar STORE_NONCE_KEY_PREFIX = \"substrat.store-nonce/\";\nvar STORE_NONCE_PRUNE_BATCH = 64;\nvar nonceKey = (iat) => `${STORE_NONCE_KEY_PREFIX}${String(iat).padStart(15, \"0\")}/`;\nfunction spendStoreNonce(storage, envelope, nowSeconds) {\n const { kv } = storage;\n const expired = nonceKey(nowSeconds - SCOPE_STORE_ENVELOPE_WINDOW_SECONDS);\n for (const [key2] of kv.list({ prefix: STORE_NONCE_KEY_PREFIX, end: expired, limit: STORE_NONCE_PRUNE_BATCH })) kv.delete(key2);\n if (!scopeStoreEnvelopeFresh(envelope.iat, nowSeconds)) return false;\n const key = `${nonceKey(envelope.iat)}${envelope.nonce}`;\n if (kv.get(key) !== void 0) return false;\n kv.put(key, 1);\n return true;\n}\nvar spentNonce = { ok: false, status: 401, message: \"unauthorized: nonce\" };\nasync function storeCallVerdict(headers, body, env) {\n const script = env[STORE_SCRIPT_VAR];\n let keys;\n try {\n if (typeof script !== \"string\" || script.length === 0) throw new Error(\"no script name\");\n keys = scopeStorePublicKeysFrom({\n caller: String(env[STORE_CALLER_KEYS_VAR] ?? \"\"),\n platform: String(env[STORE_PLATFORM_KEYS_VAR] ?? \"\")\n });\n } catch {\n return { ok: false, status: 503, message: \"this store script is not configured\" };\n }\n const verdict = await verifyScopeStoreCall({\n envelope: headers.get(SCOPE_STORE_ENVELOPE_HEADER),\n signature: headers.get(SCOPE_STORE_SIGNATURE_HEADER),\n body,\n keys,\n script,\n nowSeconds: Math.floor(Date.now() / 1e3)\n });\n return verdict.ok ? verdict : { ok: false, status: 401, message: `unauthorized: ${verdict.refusal}` };\n}\nexport {\n spendStoreNonce,\n spentNonce,\n storeCallDeclaredRefusal,\n storeCallVerdict,\n verifiedStoreCall\n};\n";
67
+ export const STORE_ENTRY_PYTHON_VERIFIER_SOURCE = "// packages/contracts/dist/scope-store-envelope.js\nvar SCOPE_STORE_ENVELOPE_WINDOW_SECONDS = 60;\nvar SCOPE_STORE_ENVELOPE_HEADER = \"x-substrat-store-envelope\";\nvar SCOPE_STORE_SIGNATURE_HEADER = \"x-substrat-store-signature\";\nvar RESERVED_STORE_OPERATIONS = [\n \"substrat.export-page\",\n \"substrat.stage-page\",\n \"substrat.commit-stage\",\n \"substrat.discard-stage\",\n \"substrat.size\",\n \"substrat.wipe\",\n \"substrat.erase\",\n \"substrat.selfcheck\"\n];\nvar STORE_FENCE_OPERATION = \"substrat.fence\";\nvar STORE_FENCED_CODE = \"store_fenced\";\nvar STORE_FENCE_DRAINING_CODE = \"store_fence_draining\";\nvar STORE_STAGE_MAX_AGE_MS = 6 * 36e5 + 3 * 30 * 6e4;\nvar STORE_CALL_MAX_BYTES = 4 * 1024 * 1024;\nvar STORE_DUMP_PAGE_MAX_BYTES = 3 * 1024 * 1024;\nvar ADMITTED = {\n \"1\": {\n platform: (op) => op === STORE_FENCE_OPERATION || RESERVED_STORE_OPERATIONS.includes(op),\n caller: (op) => !op.startsWith(\"substrat.\")\n }\n};\nfunction scopeStoreEnvelopeAdmits(v, aud, op) {\n const byAudience = Object.hasOwn(ADMITTED, String(v)) ? ADMITTED[String(v)] : void 0;\n if (!byAudience || !Object.hasOwn(byAudience, aud))\n return false;\n return byAudience[aud](op);\n}\nfunction bytesToBase64Url(bytes) {\n let binary = \"\";\n for (const byte of bytes)\n binary += String.fromCharCode(byte);\n return btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\nfunction base64UrlToBytes(value) {\n if (!/^[A-Za-z0-9_-]+$/.test(value))\n return void 0;\n const padded = value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + \"=\".repeat((4 - value.length % 4) % 4);\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++)\n bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return void 0;\n }\n}\nfunction copyBytes(bytes) {\n const copy = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(copy).set(bytes);\n return copy;\n}\nfunction isCanonicalBase64Url(text, length) {\n const bytes = base64UrlToBytes(text);\n return bytes?.length === length && bytesToBase64Url(bytes) === text;\n}\nvar NONCE = /^[A-Za-z0-9_-]{22}$/;\nvar KID = /^[A-Za-z0-9_-]{11}$/;\nvar DIGEST = /^[0-9a-f]{64}$/;\nvar IAT = /^(0|[1-9]\\d{0,14})$/;\nfunction parseScopeStoreEnvelope(canonical) {\n const lines = canonical.split(\"\\n\");\n if (lines.length !== 9)\n return void 0;\n const [version, aud, kid, script, name, op, digest, iatText, nonce] = lines;\n if (version !== \"1\" || aud !== \"caller\" && aud !== \"platform\")\n return void 0;\n if (!script || !name || !op)\n return void 0;\n if (!KID.test(kid) || !DIGEST.test(digest) || !IAT.test(iatText) || !NONCE.test(nonce))\n return void 0;\n if (!isCanonicalBase64Url(kid, 8) || !isCanonicalBase64Url(nonce, 16))\n return void 0;\n return { v: 1, aud, kid, script, name, op, digest, iat: Number(iatText), nonce };\n}\nasync function scopeStoreBodyDigest(body) {\n const hash = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(body));\n return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\nfunction scopeStoreEnvelopeFresh(iat, nowSeconds, windowSeconds = SCOPE_STORE_ENVELOPE_WINDOW_SECONDS) {\n return Math.abs(nowSeconds - iat) <= windowSeconds;\n}\nvar SMALL_ORDER_KEYS = [\n \"0000000000000000000000000000000000000000000000000000000000000000\",\n // y = 0, order 4\n \"0100000000000000000000000000000000000000000000000000000000000000\",\n // the identity, order 1\n \"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05\",\n // order 8\n \"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a\",\n // order 8\n \"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p - 1, order 2\n \"edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\",\n // y = p, a non-canonical 0\n \"eeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f\"\n // y = p + 1, a non-canonical identity\n];\nfunction isSmallOrderKey(bytes) {\n const unsigned = Uint8Array.from(bytes);\n unsigned[31] = unsigned[31] & 127;\n const hex = [...unsigned].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n return SMALL_ORDER_KEYS.includes(hex);\n}\nasync function scopeStoreKeyId(publicKey) {\n const bytes = base64UrlToBytes(publicKey);\n if (!bytes || bytes.length !== 32)\n throw new Error(\"a store public key is not 32 bytes of base64url\");\n if (isSmallOrderKey(bytes))\n throw new Error(\"a store public key is a small-order point\");\n const hash = await crypto.subtle.digest(\"SHA-256\", copyBytes(bytes));\n return bytesToBase64Url(new Uint8Array(hash).slice(0, 8));\n}\nfunction scopeStorePublicKeyProblem(key) {\n if (key.length === 0)\n return \"empty\";\n const bytes = base64UrlToBytes(key);\n if (bytes?.length !== 32)\n return \"length\";\n if (isSmallOrderKey(bytes))\n return \"small-order\";\n if (bytesToBase64Url(bytes) !== key)\n return \"non-canonical\";\n return void 0;\n}\nvar PUBLIC_KEY_PROBLEM = {\n empty: \"a store public key list is empty or has an empty entry\",\n length: \"a store public key is not 32 bytes of base64url\",\n \"small-order\": \"a store public key is a small-order point\",\n \"non-canonical\": \"a store public key is not canonical base64url\"\n};\nfunction parseScopeStorePublicKeys(text) {\n const keys = text.split(\",\").map((key) => key.trim());\n if (keys.some((key) => key.length === 0))\n throw new Error(PUBLIC_KEY_PROBLEM.empty);\n const seen = /* @__PURE__ */ new Set();\n for (const key of keys) {\n const problem = scopeStorePublicKeyProblem(key);\n if (problem)\n throw new Error(PUBLIC_KEY_PROBLEM[problem]);\n if (seen.has(key))\n throw new Error(\"a store public key is listed twice\");\n seen.add(key);\n }\n return keys;\n}\nfunction scopeStorePublicKeysFrom(config) {\n const caller = parseScopeStorePublicKeys(config.caller);\n const platform = parseScopeStorePublicKeys(config.platform);\n if (caller.some((key) => platform.includes(key))) {\n throw new Error(\"a store public key is listed for both audiences\");\n }\n return { caller, platform };\n}\nasync function verifyScopeStoreEnvelope(publicKey, canonical, signature) {\n const keyBytes = base64UrlToBytes(publicKey);\n const sigBytes = base64UrlToBytes(signature);\n if (!keyBytes || !sigBytes || sigBytes.length !== 64)\n return false;\n try {\n const key = await crypto.subtle.importKey(\"raw\", copyBytes(keyBytes), { name: \"Ed25519\" }, false, [\"verify\"]);\n return await crypto.subtle.verify(\"Ed25519\", key, copyBytes(sigBytes), new TextEncoder().encode(canonical));\n } catch {\n return false;\n }\n}\nasync function verifyScopeStoreCall(input) {\n const refuse = (refusal) => ({ ok: false, refusal });\n if (!input.envelope || !input.signature)\n return refuse(\"missing\");\n const bytes = base64UrlToBytes(input.envelope);\n if (!bytes)\n return refuse(\"malformed\");\n let canonical;\n try {\n canonical = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n } catch {\n return refuse(\"malformed\");\n }\n const envelope = parseScopeStoreEnvelope(canonical);\n if (!envelope)\n return refuse(\"malformed\");\n if (!scopeStoreEnvelopeAdmits(envelope.v, envelope.aud, envelope.op))\n return refuse(\"audience\");\n const kidsOf = async (keys) => {\n const kids = /* @__PURE__ */ new Map();\n for (const key of keys) {\n try {\n kids.set(await scopeStoreKeyId(key), key);\n } catch {\n }\n }\n return kids;\n };\n const own = await kidsOf(input.keys[envelope.aud]);\n const other = await kidsOf(input.keys[envelope.aud === \"caller\" ? \"platform\" : \"caller\"]);\n if ([...own.keys()].some((kid) => other.has(kid)))\n return refuse(\"keys\");\n const publicKey = own.get(envelope.kid);\n if (!publicKey)\n return refuse(\"kid\");\n if (!await verifyScopeStoreEnvelope(publicKey, canonical, input.signature))\n return refuse(\"signature\");\n if (envelope.digest !== await scopeStoreBodyDigest(input.body))\n return refuse(\"digest\");\n if (!scopeStoreEnvelopeFresh(envelope.iat, input.nowSeconds, input.windowSeconds))\n return refuse(\"stale\");\n if (envelope.script !== input.script)\n return refuse(\"script\");\n let parsed;\n try {\n parsed = JSON.parse(input.body);\n } catch {\n return refuse(\"body\");\n }\n const field = (key) => typeof parsed === \"object\" && parsed !== null ? Reflect.get(parsed, key) : void 0;\n if (field(\"operation\") !== envelope.op || field(\"objectName\") !== envelope.name)\n return refuse(\"body\");\n return { ok: true, envelope };\n}\n\n// packages/control-plane-api/store-entry/names.ts\nvar STORE_FENCE_KEY = \"_substrat_store_fence\";\nvar STORE_SCRIPT_VAR = \"SUBSTRAT_STORE_SCRIPT\";\nvar STORE_CALLER_KEYS_VAR = \"SUBSTRAT_STORE_CALLER_KEYS\";\nvar STORE_PLATFORM_KEYS_VAR = \"SUBSTRAT_STORE_PLATFORM_KEYS\";\n\n// packages/control-plane-api/store-entry/fence.ts\nvar STORE_FENCE_DRAIN_MS = 3e4;\nvar WRITES = /* @__PURE__ */ new Set([\"substrat.stage-page\", \"substrat.commit-stage\"]);\nvar FENCED = {\n ok: false,\n status: 410,\n message: JSON.stringify({\n error: { code: STORE_FENCED_CODE, status: 410, body: { message: \"the scope this store belongs to is being deleted\" } }\n }),\n contentType: \"application/json\"\n};\nvar DRAINING = {\n ok: false,\n status: 503,\n message: JSON.stringify({ error: { code: STORE_FENCE_DRAINING_CODE, status: 503 } }),\n contentType: \"application/json\"\n};\nvar PASSED = { ok: true };\nvar StoreObjectFence = class {\n #storage;\n #drainMs;\n /** One instance per object, and every write of the mark goes through it, so once read this is the truth. */\n #fenced;\n #inside = 0;\n #waiting = /* @__PURE__ */ new Set();\n constructor(storage, drainMs) {\n this.#storage = storage;\n this.#drainMs = drainMs;\n }\n async #load() {\n if (this.#fenced !== void 0) return;\n const stored = await this.#storage.get(STORE_FENCE_KEY);\n this.#fenced = this.#fenced === true || stored !== void 0;\n }\n /**\n * Whether a call may go to the driver. Admitted, it counts as inside until `leave`. Nothing awaits\n * between the check and the count, or a `close` could find the object empty with this call on its way in.\n */\n async admit(envelope) {\n await this.#load();\n if (this.#fenced === true && (envelope.aud !== \"platform\" || WRITES.has(envelope.op))) return FENCED;\n this.#inside += 1;\n return PASSED;\n }\n /** Whether the driver's alarm may run: never on a fenced object. Admitted, it counts as inside until `leave`. */\n async admitAlarm() {\n await this.#load();\n if (this.#fenced === true) return false;\n this.#inside += 1;\n return true;\n }\n /** An admitted call is done. On a fenced object the mark is written again, whatever that call's driver did. */\n async leave() {\n this.#inside -= 1;\n if (this.#inside === 0) {\n for (const drained of this.#waiting) drained();\n this.#waiting.clear();\n }\n if (this.#fenced === true) await this.reassert();\n }\n /** Mark the object, durably, then wait out what is inside it. Past the wait it answers 503, and the mark stays. */\n async close() {\n this.#fenced = true;\n await this.reassert();\n return await this.#drained() ? PASSED : DRAINING;\n }\n /** Write the mark, after a step that may have taken it with everything else. */\n async reassert() {\n await this.#storage.put(STORE_FENCE_KEY, true);\n }\n #drained() {\n if (this.#inside === 0) return Promise.resolve(true);\n return new Promise((resolve) => {\n const drained = () => {\n clearTimeout(timer);\n resolve(true);\n };\n const timer = setTimeout(() => {\n this.#waiting.delete(drained);\n resolve(false);\n }, this.#drainMs);\n this.#waiting.add(drained);\n });\n }\n};\nfunction storeObjectFence(storage, drainMs = STORE_FENCE_DRAIN_MS) {\n return new StoreObjectFence(storage, drainMs);\n}\nfunction storeFenceWipeBody(body) {\n const call = JSON.parse(new TextDecoder().decode(body));\n return new TextEncoder().encode(JSON.stringify({ ...call, operation: \"substrat.wipe\" })).buffer;\n}\n\n// packages/control-plane-api/store-entry/verify.ts\nvar tooLarge = { ok: false, status: 413, message: `payload too large: at most ${STORE_CALL_MAX_BYTES} bytes` };\nfunction storeCallDeclaredRefusal(headers) {\n const declared = headers.get(\"content-length\");\n return declared !== null && /^\\d+$/.test(declared.trim()) && Number(declared) > STORE_CALL_MAX_BYTES ? tooLarge : void 0;\n}\nasync function boundedBody(body) {\n if (!body) return new Uint8Array(0);\n const reader = body.getReader();\n const chunks = [];\n let total = 0;\n for (; ; ) {\n const { done, value } = await reader.read();\n if (done || !value) break;\n total += value.byteLength;\n if (total > STORE_CALL_MAX_BYTES) {\n await reader.cancel().catch(() => void 0);\n return tooLarge;\n }\n chunks.push(value);\n }\n const bytes = new Uint8Array(total);\n let at = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, at);\n at += chunk.byteLength;\n }\n return bytes;\n}\nasync function verifiedStoreCall(request, env) {\n const declared = storeCallDeclaredRefusal(request.headers);\n if (declared) return declared;\n const bytes = await boundedBody(request.body);\n if (!(bytes instanceof Uint8Array)) return bytes;\n let text;\n try {\n text = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n } catch {\n return { ok: false, status: 401, message: \"unauthorized: digest\" };\n }\n const verdict = await storeCallVerdict(request.headers, text, env);\n return verdict.ok ? { ok: true, envelope: verdict.envelope, body: bytes.buffer } : verdict;\n}\nvar STORE_NONCE_KEY_PREFIX = \"substrat.store-nonce/\";\nvar STORE_NONCE_PRUNE_BATCH = 64;\nvar nonceKey = (iat) => `${STORE_NONCE_KEY_PREFIX}${String(iat).padStart(15, \"0\")}/`;\nfunction spendStoreNonce(storage, envelope, nowSeconds) {\n const { kv } = storage;\n const expired = nonceKey(nowSeconds - SCOPE_STORE_ENVELOPE_WINDOW_SECONDS);\n for (const [key2] of kv.list({ prefix: STORE_NONCE_KEY_PREFIX, end: expired, limit: STORE_NONCE_PRUNE_BATCH })) kv.delete(key2);\n if (!scopeStoreEnvelopeFresh(envelope.iat, nowSeconds)) return false;\n const key = `${nonceKey(envelope.iat)}${envelope.nonce}`;\n if (kv.get(key) !== void 0) return false;\n kv.put(key, 1);\n return true;\n}\nvar spentNonce = { ok: false, status: 401, message: \"unauthorized: nonce\" };\nasync function storeCallVerdict(headers, body, env) {\n const script = env[STORE_SCRIPT_VAR];\n let keys;\n try {\n if (typeof script !== \"string\" || script.length === 0) throw new Error(\"no script name\");\n keys = scopeStorePublicKeysFrom({\n caller: String(env[STORE_CALLER_KEYS_VAR] ?? \"\"),\n platform: String(env[STORE_PLATFORM_KEYS_VAR] ?? \"\")\n });\n } catch {\n return { ok: false, status: 503, message: \"this store script is not configured\" };\n }\n const verdict = await verifyScopeStoreCall({\n envelope: headers.get(SCOPE_STORE_ENVELOPE_HEADER),\n signature: headers.get(SCOPE_STORE_SIGNATURE_HEADER),\n body,\n keys,\n script,\n nowSeconds: Math.floor(Date.now() / 1e3)\n });\n return verdict.ok ? verdict : { ok: false, status: 401, message: `unauthorized: ${verdict.refusal}` };\n}\nexport {\n spendStoreNonce,\n spentNonce,\n storeCallDeclaredRefusal,\n storeCallVerdict,\n storeFenceWipeBody,\n storeObjectFence,\n verifiedStoreCall\n};\n";
62
68
  //# sourceMappingURL=store-entry.generated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-entry.generated.js","sourceRoot":"","sources":["../src/store-entry.generated.ts"],"names":[],"mappings":"AAAA,oOAAoO;AACpO,mEAAmE;AAEnE;;;;;GAKG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAElE,2FAA2F;AAC3F,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC;AAElE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAG,2BAA2B,CAAC;AAEpE,4GAA4G;AAC5G,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AAEnE,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAExD,+DAA+D;AAC/D,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAEtE;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,YAAY,CAAC;AAE5D,6GAA6G;AAC7G,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,gBAAgB,CAAC;AAE9D,mGAAmG;AACnG,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,yBAAyB,EAAC,yBAAyB,EAAC,0BAA0B,CAAC,CAAC;AAEvH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD;;;GAGG;AACH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,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,yBAAyB,EAAC,yBAAyB,EAAC,0BAA0B,CAAC,CAAC;AAEvH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEhE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAW,4nlBAA4nlB,CAAC;AAEvqlB;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAW,k7RAAk7R,CAAC;AAEp+R;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAW,qgfAAqgf,CAAC"}
@@ -37,12 +37,14 @@ export declare const restoreEnds: (caller: PlatformScopeStores, to: StorePlace,
37
37
  * A store's landing that failed once a commit was attempted: which bindings were committed, and
38
38
  * which were not. The commit of `failed` may have run with its answer lost, so the store under it is
39
39
  * either. The route replays erasures even so, since a store replaced by an old copy holds subjects
40
- * erased since, and running the restore again converges: every commit is a whole replace.
40
+ * erased since, and running the restore again converges: every commit is a whole replace. Except
41
+ * after a 410: a store a deletion has fenced refuses for good (D-71), so the answer names the way
42
+ * out instead of a retry.
41
43
  */
42
44
  export declare class StoreLandFailure extends ControlPlaneError {
43
45
  readonly committed: readonly string[];
44
46
  readonly uncommitted: readonly string[];
45
- constructor(cause: unknown, committed: readonly string[], uncommitted: readonly string[]);
47
+ constructor(cause: unknown, scopeId: string, committed: readonly string[], uncommitted: readonly string[]);
46
48
  }
47
49
  /**
48
50
  * Commit each moved store's stage, comparing each count with what was sent. The contract makes a
@@ -1 +1 @@
1
- {"version":3,"file":"store-move-ends.d.ts","sourceRoot":"","sources":["../src/store-move-ends.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CA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AM,EAAE,mBAAmB,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAchI"}
@@ -1,5 +1,5 @@
1
1
  import { storeDriverDumpPageBytes } from '@substrat-run/contracts';
2
- import { storeDumpPages } from '@substrat-run/kernel';
2
+ import { storeDumpPages, storesFencedRefusal } from '@substrat-run/kernel';
3
3
  import { ControlPlaneError } from '@substrat-run/control-plane-client';
4
4
  import { STORE_MOVE_MAX_PAGES } from './store-move.js';
5
5
  const callAt = (caller, place, store) => caller.callStore({ ...place, ...store });
@@ -50,15 +50,19 @@ export const restoreEnds = (caller, to, sourceOf) => (store) => {
50
50
  * A store's landing that failed once a commit was attempted: which bindings were committed, and
51
51
  * which were not. The commit of `failed` may have run with its answer lost, so the store under it is
52
52
  * either. The route replays erasures even so, since a store replaced by an old copy holds subjects
53
- * erased since, and running the restore again converges: every commit is a whole replace.
53
+ * erased since, and running the restore again converges: every commit is a whole replace. Except
54
+ * after a 410: a store a deletion has fenced refuses for good (D-71), so the answer names the way
55
+ * out instead of a retry.
54
56
  */
55
57
  export class StoreLandFailure extends ControlPlaneError {
56
58
  committed;
57
59
  uncommitted;
58
- constructor(cause, committed, uncommitted) {
60
+ constructor(cause, scopeId, committed, uncommitted) {
59
61
  const message = cause instanceof Error ? cause.message : String(cause);
60
- super(cause instanceof ControlPlaneError ? cause.status : 502, `${message}. The scope's stores were committed in part: ${committed.length ? committed.join(', ') : 'none'} committed, ` +
61
- `${uncommitted.join(', ')} not known to be; restore again to finish`);
62
+ const status = cause instanceof ControlPlaneError ? cause.status : 502;
63
+ super(status, `${message}. The scope's stores were committed in part: ${committed.length ? committed.join(', ') : 'none'} committed, ` +
64
+ `${uncommitted.join(', ')} not known to be; ` +
65
+ (status === 410 ? storesFencedRefusal(scopeId) : 'restore again to finish'));
62
66
  this.committed = committed;
63
67
  this.uncommitted = uncommitted;
64
68
  }
@@ -82,7 +86,7 @@ export async function commitStages(caller, place, moved, retry) {
82
86
  const rest = moved.slice(at);
83
87
  for (const left of rest.slice(1))
84
88
  await callAt(caller, place, left)('substrat.discard-stage', { stageId: left.moveId }).catch(() => undefined);
85
- throw new StoreLandFailure(e, committed, rest.map((s) => s.binding));
89
+ throw new StoreLandFailure(e, place.scopeId, committed, rest.map((s) => s.binding));
86
90
  }
87
91
  committed.push(store.binding);
88
92
  }