@brud/kernel 0.0.0-stage → 0.0.2

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.
Files changed (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +63 -2
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +13 -0
  5. package/dist/serviceModules/events.d.ts +1 -0
  6. package/dist/serviceModules/events.js +1 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +1 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +1 -0
  10. package/dist/serviceModules/identityRegistry.js +1 -0
  11. package/dist/serviceModules/interception.d.ts +1 -0
  12. package/dist/serviceModules/interception.js +1 -0
  13. package/dist/serviceModules/parser.d.ts +1 -0
  14. package/dist/serviceModules/parser.js +1 -0
  15. package/dist/serviceModules/router.d.ts +1 -0
  16. package/dist/serviceModules/router.js +1 -0
  17. package/dist/serviceModules/wasmCage.d.ts +1 -0
  18. package/dist/serviceModules/wasmCage.js +1 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
  20. package/dist/services/Events/contracts/IEventsService.js +1 -0
  21. package/dist/services/Events/contracts/errors.d.ts +31 -0
  22. package/dist/services/Events/contracts/errors.js +40 -0
  23. package/dist/services/Events/contracts/index.d.ts +3 -0
  24. package/dist/services/Events/contracts/index.js +3 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +2 -0
  26. package/dist/services/Events/contracts/tokens.js +2 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +1 -0
  30. package/dist/services/Events/descriptor/tokens.js +1 -0
  31. package/dist/services/Events/index.d.ts +4 -0
  32. package/dist/services/Events/index.js +4 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +339 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +2 -0
  36. package/dist/services/Events/orchestrator/index.js +2 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +22 -0
  38. package/dist/services/Events/orchestrator/limits.js +33 -0
  39. package/dist/services/Events/serviceModule.d.ts +2 -0
  40. package/dist/services/Events/serviceModule.js +5 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
  58. package/dist/services/ExposedApiRegistry/index.js +5 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +3 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +18 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +11 -0
  80. package/dist/services/IdentityRegistry/index.js +6 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +24 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
  89. package/dist/services/Interception/contracts/errors.d.ts +26 -0
  90. package/dist/services/Interception/contracts/errors.js +35 -0
  91. package/dist/services/Interception/contracts/index.d.ts +3 -0
  92. package/dist/services/Interception/contracts/index.js +3 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +2 -0
  94. package/dist/services/Interception/contracts/tokens.js +2 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
  97. package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
  98. package/dist/services/Interception/descriptor/tokens.js +1 -0
  99. package/dist/services/Interception/index.d.ts +4 -0
  100. package/dist/services/Interception/index.js +4 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
  103. package/dist/services/Interception/orchestrator/index.d.ts +1 -0
  104. package/dist/services/Interception/orchestrator/index.js +1 -0
  105. package/dist/services/Interception/serviceModule.d.ts +2 -0
  106. package/dist/services/Interception/serviceModule.js +5 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
  108. package/dist/services/Parser/contracts/IParserService.js +1 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +25 -0
  110. package/dist/services/Parser/contracts/errors.js +33 -0
  111. package/dist/services/Parser/contracts/index.d.ts +4 -0
  112. package/dist/services/Parser/contracts/index.js +1 -0
  113. package/dist/services/Parser/contracts/types.d.ts +42 -0
  114. package/dist/services/Parser/contracts/types.js +1 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
  118. package/dist/services/Parser/descriptor/tokens.js +8 -0
  119. package/dist/services/Parser/index.d.ts +8 -0
  120. package/dist/services/Parser/index.js +8 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +105 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +1 -0
  124. package/dist/services/Parser/orchestrator/index.js +1 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +13 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +14 -0
  128. package/dist/services/Parser/parser/parameters.js +89 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +48 -0
  130. package/dist/services/Parser/parser/scanner.js +156 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +30 -0
  132. package/dist/services/Parser/parser/syntax.js +34 -0
  133. package/dist/services/Parser/serviceModule.d.ts +2 -0
  134. package/dist/services/Parser/serviceModule.js +5 -0
  135. package/dist/services/Router/bootOptions.d.ts +2 -0
  136. package/dist/services/Router/bootOptions.js +2 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
  138. package/dist/services/Router/contracts/IRouterService.js +1 -0
  139. package/dist/services/Router/contracts/caller.d.ts +6 -0
  140. package/dist/services/Router/contracts/caller.js +6 -0
  141. package/dist/services/Router/contracts/errors.d.ts +67 -0
  142. package/dist/services/Router/contracts/errors.js +90 -0
  143. package/dist/services/Router/contracts/index.d.ts +8 -0
  144. package/dist/services/Router/contracts/index.js +4 -0
  145. package/dist/services/Router/contracts/kind.d.ts +7 -0
  146. package/dist/services/Router/contracts/kind.js +10 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +23 -0
  148. package/dist/services/Router/contracts/registrant.js +13 -0
  149. package/dist/services/Router/contracts/types.d.ts +110 -0
  150. package/dist/services/Router/contracts/types.js +1 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
  153. package/dist/services/Router/descriptor/tokens.d.ts +9 -0
  154. package/dist/services/Router/descriptor/tokens.js +9 -0
  155. package/dist/services/Router/index.d.ts +4 -0
  156. package/dist/services/Router/index.js +4 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +457 -0
  159. package/dist/services/Router/orchestrator/index.d.ts +2 -0
  160. package/dist/services/Router/orchestrator/index.js +1 -0
  161. package/dist/services/Router/serviceModule.d.ts +4 -0
  162. package/dist/services/Router/serviceModule.js +22 -0
  163. package/dist/services/WasmCage/index.d.ts +7 -0
  164. package/dist/services/WasmCage/index.js +4 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +38 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +12 -0
  168. package/dist/services/WasmCage/serviceModule.js +18 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +121 -0
  170. package/dist/services/WasmCage/src/caged.js +460 -0
  171. package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
  172. package/dist/services/WasmCage/src/descriptor.js +56 -0
  173. package/dist/services/WasmCage/src/native.d.ts +29 -0
  174. package/dist/services/WasmCage/src/native.js +66 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +15 -0
  177. package/dist/services/WasmCage/src/package.d.ts +36 -0
  178. package/dist/services/WasmCage/src/package.js +122 -0
  179. package/dist/services/shared/canonicalJson.d.ts +29 -0
  180. package/dist/services/shared/canonicalJson.js +93 -0
  181. package/dist/services/shared/documentStore.d.ts +16 -0
  182. package/dist/services/shared/documentStore.js +98 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +633 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +113 -0
  186. package/dist/src/bootstrap/bootTypes.js +1 -0
  187. package/dist/src/bootstrap/config/index.d.ts +3 -0
  188. package/dist/src/bootstrap/config/index.js +2 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +45 -0
  190. package/dist/src/bootstrap/config/integrity.js +92 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +15 -0
  192. package/dist/src/bootstrap/config/parse.js +81 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
  195. package/dist/src/bootstrap/config/types.d.ts +41 -0
  196. package/dist/src/bootstrap/config/types.js +15 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +212 -0
  198. package/dist/src/bootstrap/hardcore.js +312 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +258 -0
  201. package/dist/src/bootstrap/index.d.ts +13 -0
  202. package/dist/src/bootstrap/index.js +7 -0
  203. package/dist/src/bootstrap/loaded.d.ts +30 -0
  204. package/dist/src/bootstrap/loaded.js +45 -0
  205. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  206. package/dist/src/bootstrap/packageRequirements.js +52 -0
  207. package/dist/src/bootstrap/reload.d.ts +44 -0
  208. package/dist/src/bootstrap/reload.js +45 -0
  209. package/dist/src/bootstrap/seal.d.ts +32 -0
  210. package/dist/src/bootstrap/seal.js +101 -0
  211. package/dist/src/contracts/accessBroker.d.ts +53 -0
  212. package/dist/src/contracts/accessBroker.js +1 -0
  213. package/dist/src/contracts/brudOperation.d.ts +20 -0
  214. package/dist/src/contracts/brudOperation.js +20 -0
  215. package/dist/src/contracts/callChain.d.ts +161 -0
  216. package/dist/src/contracts/callChain.js +19 -0
  217. package/dist/src/contracts/capability.d.ts +26 -0
  218. package/dist/src/contracts/capability.js +26 -0
  219. package/dist/src/contracts/capabilitySet.d.ts +23 -0
  220. package/dist/src/contracts/capabilitySet.js +72 -0
  221. package/dist/src/contracts/container.d.ts +17 -0
  222. package/dist/src/contracts/container.js +8 -0
  223. package/dist/src/contracts/context.d.ts +19 -0
  224. package/dist/src/contracts/context.js +1 -0
  225. package/dist/src/contracts/contextContract.d.ts +132 -0
  226. package/dist/src/contracts/contextContract.js +274 -0
  227. package/dist/src/contracts/dispatchView.d.ts +21 -0
  228. package/dist/src/contracts/dispatchView.js +1 -0
  229. package/dist/src/contracts/handler.d.ts +21 -0
  230. package/dist/src/contracts/handler.js +1 -0
  231. package/dist/src/contracts/index.d.ts +26 -0
  232. package/dist/src/contracts/index.js +9 -0
  233. package/dist/src/contracts/kernel.d.ts +60 -0
  234. package/dist/src/contracts/kernel.js +1 -0
  235. package/dist/src/contracts/lifecycle.d.ts +59 -0
  236. package/dist/src/contracts/lifecycle.js +1 -0
  237. package/dist/src/contracts/manifest.d.ts +180 -0
  238. package/dist/src/contracts/manifest.js +334 -0
  239. package/dist/src/contracts/pipeline.d.ts +8 -0
  240. package/dist/src/contracts/pipeline.js +1 -0
  241. package/dist/src/contracts/policy.d.ts +75 -0
  242. package/dist/src/contracts/policy.js +77 -0
  243. package/dist/src/contracts/registry.d.ts +7 -0
  244. package/dist/src/contracts/registry.js +1 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  246. package/dist/src/contracts/serviceDescriptor.js +1 -0
  247. package/dist/src/contracts/serviceToken.d.ts +36 -0
  248. package/dist/src/contracts/serviceToken.js +16 -0
  249. package/dist/src/engine/BrudKernel.d.ts +120 -0
  250. package/dist/src/engine/BrudKernel.js +395 -0
  251. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  252. package/dist/src/engine/ExecutionPipeline.js +62 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  254. package/dist/src/engine/KernelAccessBroker.js +107 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  256. package/dist/src/engine/KernelRegistry.js +33 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  258. package/dist/src/engine/OperationRegistry.js +18 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  260. package/dist/src/engine/ServiceContainer.js +53 -0
  261. package/dist/src/engine/callChain.d.ts +68 -0
  262. package/dist/src/engine/callChain.js +175 -0
  263. package/dist/src/engine/dag.d.ts +2 -0
  264. package/dist/src/engine/dag.js +34 -0
  265. package/dist/src/engine/errors.d.ts +26 -0
  266. package/dist/src/engine/errors.js +52 -0
  267. package/dist/src/engine/index.d.ts +11 -0
  268. package/dist/src/engine/index.js +8 -0
  269. package/dist/src/engine/state.d.ts +1 -0
  270. package/dist/src/engine/state.js +1 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  272. package/dist/src/validation/jsonSchema/compile.js +386 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  274. package/dist/src/validation/jsonSchema/index.js +2 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  280. package/dist/src/validation/jsonSchema/types.js +15 -0
  281. package/package.json +59 -4
  282. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  283. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  284. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  285. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  286. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,121 @@
1
+ import type { ParticipantManifest, ServiceDescriptor } from '../../../src/contracts/index.js';
2
+ /**
3
+ * Caged participants: code running inside the WASM cage with full participant
4
+ * parity (Architect ruling I-07). The kernel already treats a caged participant
5
+ * like any other; this module is the host side of the cage's call *in*.
6
+ *
7
+ * ## Guest ABI
8
+ *
9
+ * A caged participant's module exports:
10
+ * - `memory` — its linear memory;
11
+ * - `brud_alloc(len: i32) -> i32` — returns a pointer to `len` writable bytes;
12
+ * - `brud_invoke(ptr: i32, len: i32) -> i64` — a call on one of its exposures;
13
+ * - `brud_intercept(ptr: i32, len: i32) -> i64` — an interception verdict
14
+ * (only when the manifest declares an `interceptions` entry with the input
15
+ * stage, which is the default);
16
+ * - `brud_intercept_result(ptr: i32, len: i32) -> i64` — an output-stage verdict
17
+ * (only when an `interceptions` entry declares the output stage);
18
+ * - optionally `brud_start(ptr: i32, len: i32) -> i64` — called once when the
19
+ * participant starts running, with `{ kind: 'start', token }`; it answers
20
+ * `{ ok: true }` or `{ ok: false, error }` (a failure fails the start).
21
+ *
22
+ * It may import `brud.call(ptr: i32, len: i32) -> i64`, the routed call (its
23
+ * only call out): the request is `{ name, version?, method, args }`; the host
24
+ * resolves the exposure through the exposed-API registry as this participant,
25
+ * exactly as a native participant resolves, calls `method` with `args`, and
26
+ * answers `{ ok: true, value }` or `{ ok: false, error: { code, message } }`.
27
+ * A routed call is only possible while the host is calling the guest; a routed
28
+ * call back into the same instance is refused (re-entrancy fails closed).
29
+ *
30
+ * Routed calls may be async. The guest is suspended on a Wasmtime fiber while
31
+ * the host awaits, inside the original caller's call chain, then resumed with
32
+ * the result; the guest code stays synchronous. A caged exposure is sync when
33
+ * every routed call it made answered synchronously, and returns a Promise when
34
+ * one was awaited — exactly like native code. Interceptors stay synchronous:
35
+ * an awaited routed call from `brud_intercept` is answered with an error.
36
+ *
37
+ * The host writes a UTF-8 JSON request at the pointer `brud_alloc` returned and
38
+ * calls the export with `(ptr, len)`. The export returns `(ptr << 32) | len` of
39
+ * a UTF-8 JSON response in its memory.
40
+ *
41
+ * - `brud_invoke` request: `{ kind: 'invoke', exposure, method, args, caller }`
42
+ * where `caller` is `{ identity, callerClass, official, capabilities[], origin }`.
43
+ * Response: `{ ok: true, value }` or `{ ok: false, error: { code, message } }`.
44
+ * - `brud_intercept` request: the {@link InterceptedCall} as JSON. Response:
45
+ * an {@link InterceptionVerdict}.
46
+ * - `brud_intercept_result` request: the {@link InterceptedResult} as JSON.
47
+ * Response: `{ verdict: 'none' }` or `{ verdict: 'append', content }`; a guest
48
+ * can only add content, never change or remove the result.
49
+ *
50
+ * ## Security properties
51
+ *
52
+ * Plain values only (JSON in, JSON out; arguments are validated as JSON before
53
+ * they cross). Every call runs under a fresh fuel budget (its deadline); the
54
+ * memory limit is enforced at instantiation and on every growth; responses
55
+ * over 1 MiB are refused. A trap, an exhausted budget, a malformed response, or
56
+ * an invalid verdict fails closed: the call throws.
57
+ *
58
+ * The cage's outward surface is unchanged: `resolve` (through `brud.call`)
59
+ * stays a caged participant's only call out (W-09). Plain values only: a
60
+ * routed result that is not plain JSON (functions, handles, class instances,
61
+ * non-finite numbers) is refused. Each call into the guest has a wall-clock
62
+ * deadline (`deadlineMs`): once it passes, every routed call is answered with
63
+ * `WASM_CAGE_ROUTED_TIMEOUT`, and fuel bounds the guest's remaining work. A
64
+ * routed call may opt in to cancellation with `"abortable": true`: its last
65
+ * argument must be a plain options object, and the host adds the call's
66
+ * `AbortSignal` to it as `signal`, aborted when the deadline passes.
67
+ *
68
+ * Calls into a busy instance wait their turn (FIFO, at most 64 queued; the
69
+ * deadline counts from the moment a call is queued). A guest calling back into
70
+ * its own instance is refused, since waiting for itself would deadlock;
71
+ * interceptors cannot wait, so a busy instance fails them closed.
72
+ */
73
+ /** Resource limits for one caged participant. */
74
+ export interface CagedParticipantLimits {
75
+ /** Fuel per call: the call's deadline. */
76
+ readonly fuel: number;
77
+ /** Maximum linear-memory size in bytes. */
78
+ readonly maxMemoryBytes: number;
79
+ /** Wall-clock deadline per call into the guest, in milliseconds (default 30 s). */
80
+ readonly deadlineMs?: number;
81
+ }
82
+ /** Options for {@link createCagedParticipant}. */
83
+ export interface CagedParticipantOptions {
84
+ /** The participant's service token id. */
85
+ readonly token: string;
86
+ /** The participant's manifest, declared exactly as a native participant's. */
87
+ readonly manifest: ParticipantManifest;
88
+ /** The guest module: WASM binary or WAT text bytes. */
89
+ readonly wasm: Uint8Array;
90
+ /** Resource limits. */
91
+ readonly limits?: CagedParticipantLimits;
92
+ }
93
+ /** Default caged-participant limits. */
94
+ export declare const DEFAULT_CAGED_LIMITS: CagedParticipantLimits;
95
+ /** A caged guest failed: a trap, an exhausted budget, or a refused response. */
96
+ export declare class CagedGuestError extends Error {
97
+ readonly code: "WASM_CAGE_GUEST_FAILED";
98
+ /** The guest-reported error code, when the guest reported one. */
99
+ readonly guestCode: string | undefined;
100
+ /** A stable reason when the cage itself stopped the guest at a limit; `undefined` for any other failure. */
101
+ readonly reason: CagedLimitReason | undefined;
102
+ /** The engine's full text, backtrace included. Never part of `message`. */
103
+ readonly detail: string | undefined;
104
+ constructor(message: string, guestCode?: string, options?: ErrorOptions & {
105
+ reason?: CagedLimitReason;
106
+ detail?: string;
107
+ });
108
+ }
109
+ /** Why the cage stopped a guest at one of its limits. */
110
+ export type CagedLimitReason = 'CAGE_FUEL_LIMIT' | 'CAGE_MEMORY_LIMIT';
111
+ /** Names the limit the engine's text reports, or `undefined` when it reports none. */
112
+ export declare function limitReason(text: string): CagedLimitReason | undefined;
113
+ /**
114
+ * Builds the descriptor of a caged participant: a participant whose code runs
115
+ * inside the WASM cage and which may be a giver (exposures and interception
116
+ * points) and an interceptor, exactly like a native participant.
117
+ *
118
+ * @param options - Token, manifest, guest module, and limits.
119
+ * @returns The participant's descriptor.
120
+ */
121
+ export declare function createCagedParticipant(options: CagedParticipantOptions): ServiceDescriptor<object>;
@@ -0,0 +1,460 @@
1
+ import { withPlainCapabilities } from '../../../src/contracts/capabilitySet.js';
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { createServiceToken } from '../../../src/contracts/index.js';
4
+ import { compileJsonSchema } from '../../../src/validation/jsonSchema/index.js';
5
+ import { ExposedApiRegistryToken, withExposureBindings } from '../../ExposedApiRegistry/index.js';
6
+ import { InterceptionBlockedError } from '../../Interception/index.js';
7
+ import { loadVerifiedNative } from './native.js';
8
+ /** Default caged-participant limits. */
9
+ export const DEFAULT_CAGED_LIMITS = Object.freeze({
10
+ fuel: 10_000_000,
11
+ maxMemoryBytes: 16 * 1024 * 1024,
12
+ deadlineMs: 30_000,
13
+ });
14
+ /** A caged guest failed: a trap, an exhausted budget, or a refused response. */
15
+ export class CagedGuestError extends Error {
16
+ code = 'WASM_CAGE_GUEST_FAILED';
17
+ /** The guest-reported error code, when the guest reported one. */
18
+ guestCode;
19
+ /** A stable reason when the cage itself stopped the guest at a limit; `undefined` for any other failure. */
20
+ reason;
21
+ /** The engine's full text, backtrace included. Never part of `message`. */
22
+ detail;
23
+ constructor(message, guestCode, options) {
24
+ super(message, options);
25
+ this.name = 'CagedGuestError';
26
+ this.guestCode = guestCode;
27
+ this.reason = options?.reason;
28
+ this.detail = options?.detail;
29
+ }
30
+ }
31
+ let engine;
32
+ function loadNative() {
33
+ const cage = loadVerifiedNative();
34
+ engine ??= new cage.CageEngine();
35
+ return { cage, engine };
36
+ }
37
+ const argsSchema = (() => {
38
+ const compiled = compileJsonSchema({ type: 'array' });
39
+ if (!compiled.ok) {
40
+ throw new Error('caged participant: argument schema failed to compile');
41
+ }
42
+ return compiled.schema;
43
+ })();
44
+ function deepFreeze(value) {
45
+ if (value !== null && typeof value === 'object') {
46
+ for (const child of Object.values(value)) {
47
+ deepFreeze(child);
48
+ }
49
+ Object.freeze(value);
50
+ }
51
+ return value;
52
+ }
53
+ const BACKTRACE_HEADER = /^\s*error while executing at wasm backtrace:\s*$/u;
54
+ /** One backtrace frame. The engine appends the cause to the last frame, so it is captured. */
55
+ const BACKTRACE_FRAME = /^\s*\d+:\s+0x[0-9a-f]+\s+-\s.*?<wasm function \d+>(?::\s*(.*))?$/u;
56
+ /** Names the limit the engine's text reports, or `undefined` when it reports none. */
57
+ export function limitReason(text) {
58
+ if (/all fuel consumed/iu.test(text)) {
59
+ return 'CAGE_FUEL_LIMIT';
60
+ }
61
+ return /growing memory|failed to grow memory|out of memory|memory (?:limit|minimum size|maximum size)|exceeds? .*memory/iu.test(text) ? 'CAGE_MEMORY_LIMIT' : undefined;
62
+ }
63
+ /** The engine's text without its backtrace frames: the part a caller can act on. */
64
+ function withoutBacktrace(text) {
65
+ return text.split('\n').flatMap((line) => {
66
+ if (BACKTRACE_HEADER.test(line)) {
67
+ return [];
68
+ }
69
+ const frame = BACKTRACE_FRAME.exec(line);
70
+ return frame === null ? [line] : (frame[1] === undefined || frame[1] === '' ? [] : [frame[1]]);
71
+ }).join('\n').trim();
72
+ }
73
+ const LIMIT_TEXT = {
74
+ CAGE_FUEL_LIMIT: 'used all of its fuel (limits.fuel)',
75
+ CAGE_MEMORY_LIMIT: 'passed its memory limit (limits.maxMemoryBytes)',
76
+ };
77
+ function guestFailure(exportName, error) {
78
+ if (error instanceof CagedGuestError) {
79
+ return error;
80
+ }
81
+ const detail = error.message;
82
+ const reason = limitReason(detail);
83
+ const summary = reason === undefined ? withoutBacktrace(detail) : LIMIT_TEXT[reason];
84
+ const message = reason === undefined
85
+ ? `caged guest "${exportName}" failed${summary === '' ? '' : `: ${summary}`}`
86
+ : `caged guest "${exportName}" ${summary}`;
87
+ return new CagedGuestError(message, undefined, { cause: error, detail, ...(reason === undefined ? {} : { reason }) });
88
+ }
89
+ function step(exportName, run) {
90
+ try {
91
+ return run();
92
+ }
93
+ catch (error) {
94
+ throw guestFailure(exportName, error);
95
+ }
96
+ }
97
+ function finish(exportName, final) {
98
+ try {
99
+ return JSON.parse(final.response ?? '');
100
+ }
101
+ catch (error) {
102
+ throw new CagedGuestError(`caged guest "${exportName}" returned malformed JSON`, undefined, { cause: error });
103
+ }
104
+ }
105
+ const timeoutResponse = () => routedError('WASM_CAGE_ROUTED_TIMEOUT', 'the call into the cage passed its deadline');
106
+ /** Resolves with the routed answer, or with a timeout answer at the deadline. */
107
+ async function withDeadline(pending, deadline, controller) {
108
+ let timer;
109
+ const expired = new Promise((resolve) => {
110
+ timer = setTimeout(() => {
111
+ controller.abort(new CagedGuestError('the call into the cage passed its deadline', 'WASM_CAGE_ROUTED_TIMEOUT'));
112
+ resolve(timeoutResponse());
113
+ }, Math.max(0, deadline - Date.now()));
114
+ });
115
+ try {
116
+ return await Promise.race([pending, expired]);
117
+ }
118
+ finally {
119
+ clearTimeout(timer);
120
+ }
121
+ }
122
+ /**
123
+ * Drives one call into the guest. Routed requests answered synchronously are
124
+ * resumed at once, so a guest that awaits nothing completes synchronously;
125
+ * the first awaited answer switches the rest of the call to async.
126
+ */
127
+ function callGuest(instance, exportName, request, routed, deadline, allowAsync) {
128
+ const controller = new AbortController();
129
+ let current = step(exportName, () => instance.callJson(exportName, JSON.stringify(request)));
130
+ while (!current.done) {
131
+ const answer = Date.now() >= deadline ? timeoutResponse() : routed(current.request ?? '', controller.signal);
132
+ if (typeof answer !== 'string') {
133
+ if (!allowAsync) {
134
+ answer.catch(() => undefined);
135
+ current = step(exportName, () => instance.resume(routedError('WASM_CAGE_ROUTED_ASYNC', 'this guest entry cannot await a routed call')));
136
+ continue;
137
+ }
138
+ return (async () => {
139
+ let next = answer;
140
+ for (;;) {
141
+ const resolved = typeof next === 'string' ? next : await withDeadline(next, deadline, controller);
142
+ current = step(exportName, () => instance.resume(resolved));
143
+ if (current.done) {
144
+ return finish(exportName, current);
145
+ }
146
+ next = Date.now() >= deadline ? timeoutResponse() : routed(current.request ?? '', controller.signal);
147
+ }
148
+ })();
149
+ }
150
+ current = step(exportName, () => instance.resume(answer));
151
+ }
152
+ return finish(exportName, current);
153
+ }
154
+ const MAX_PLAIN_DEPTH = 64;
155
+ /** Plain JSON only: null, booleans, finite numbers, strings, arrays and plain objects. */
156
+ function isPlainJson(value, depth = 0) {
157
+ if (depth > MAX_PLAIN_DEPTH) {
158
+ return false;
159
+ }
160
+ if (value === null || typeof value === 'boolean' || typeof value === 'string') {
161
+ return true;
162
+ }
163
+ if (typeof value === 'number') {
164
+ return Number.isFinite(value);
165
+ }
166
+ if (Array.isArray(value)) {
167
+ return value.every((item) => isPlainJson(item, depth + 1));
168
+ }
169
+ if (typeof value === 'object') {
170
+ const prototype = Object.getPrototypeOf(value);
171
+ return (prototype === Object.prototype || prototype === null)
172
+ && Object.values(value).every((item) => isPlainJson(item, depth + 1));
173
+ }
174
+ return false;
175
+ }
176
+ function plainCaller(caller) {
177
+ return {
178
+ identity: caller.identity,
179
+ callerClass: caller.callerClass,
180
+ official: caller.official,
181
+ capabilities: [...caller.capabilities].sort(),
182
+ origin: caller.origin,
183
+ };
184
+ }
185
+ function isOutputVerdict(value) {
186
+ if (value === null || typeof value !== 'object') {
187
+ return false;
188
+ }
189
+ const verdict = value;
190
+ return verdict.verdict === 'none' || (verdict.verdict === 'append' && verdict.content !== undefined);
191
+ }
192
+ function isVerdict(value) {
193
+ if (value === null || typeof value !== 'object') {
194
+ return false;
195
+ }
196
+ const verdict = value;
197
+ return verdict.verdict === 'allow'
198
+ || (verdict.verdict === 'block' && typeof verdict.reason === 'string')
199
+ || (verdict.verdict === 'modify' && Array.isArray(verdict.args));
200
+ }
201
+ /** A routed-call failure, as plain values. */
202
+ function routedError(code, message) {
203
+ return JSON.stringify({ ok: false, error: { code, message } });
204
+ }
205
+ /** A routed result as a plain response. */
206
+ function plainResponse(value) {
207
+ const plain = value === undefined ? null : value;
208
+ return isPlainJson(plain)
209
+ ? JSON.stringify({ ok: true, value: plain })
210
+ : routedError('WASM_CAGE_ROUTED_NOT_PLAIN', 'the routed result is not plain JSON');
211
+ }
212
+ function failureResponse(error) {
213
+ const code = error?.code;
214
+ return routedError(typeof code === 'string' ? code : 'WASM_CAGE_ROUTED_FAILED', String(error?.message ?? error));
215
+ }
216
+ /**
217
+ * Serves one routed call: resolve as the caged participant, call the method,
218
+ * answer with plain values. Never throws; every failure is a plain error
219
+ * response. Returns a Promise when the called method returned one.
220
+ */
221
+ function serveRoutedCall(registry, raw, signal) {
222
+ try {
223
+ const request = JSON.parse(raw);
224
+ if (typeof request.name !== 'string' || typeof request.method !== 'string' || !Array.isArray(request.args)
225
+ || (request.version !== undefined && typeof request.version !== 'number' && typeof request.version !== 'string')) {
226
+ return routedError('WASM_CAGE_ROUTED_INVALID', 'a routed call needs a string name, a string method and an args array');
227
+ }
228
+ const options = request.version === undefined ? undefined : { version: request.version };
229
+ const handle = registry().resolve(request.name, options);
230
+ if (handle === null) {
231
+ return routedError('WASM_CAGE_ROUTED_NOT_FOUND', `exposure "${request.name}" did not resolve`);
232
+ }
233
+ const method = handle[request.method];
234
+ if (typeof method !== 'function') {
235
+ return routedError('WASM_CAGE_ROUTED_NOT_FOUND', `exposure "${request.name}" has no method "${request.method}"`);
236
+ }
237
+ let args = request.args;
238
+ if (request.abortable === true) {
239
+ const last = args[args.length - 1];
240
+ if (last === null || typeof last !== 'object' || Array.isArray(last)) {
241
+ return routedError('WASM_CAGE_ROUTED_INVALID', 'an abortable routed call needs a plain options object as its last argument');
242
+ }
243
+ args = [...args.slice(0, -1), { ...last, signal }];
244
+ }
245
+ const value = method.apply(handle, args);
246
+ if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
247
+ return Promise.resolve(value).then(plainResponse, failureResponse);
248
+ }
249
+ return plainResponse(value);
250
+ }
251
+ catch (error) {
252
+ return failureResponse(error);
253
+ }
254
+ }
255
+ /** The instances whose guest call the current async context is inside. */
256
+ const activeInstances = new AsyncLocalStorage();
257
+ const MAX_QUEUED_CALLS = 64;
258
+ /**
259
+ * Serializes calls into one guest instance: one runs at a time, later ones
260
+ * wait (FIFO). A call made from inside this instance's own call is refused.
261
+ */
262
+ function createScheduler(instance, routed, deadlineMs) {
263
+ const self = {};
264
+ const waiting = [];
265
+ let running = false;
266
+ const release = () => {
267
+ running = false;
268
+ waiting.shift()?.();
269
+ };
270
+ const start = (exportName, request, deadline, allowAsync) => {
271
+ if (Date.now() >= deadline) {
272
+ throw new CagedGuestError(`caged guest "${exportName}" waited past its deadline`, 'WASM_CAGE_QUEUE_TIMEOUT');
273
+ }
274
+ running = true;
275
+ const inside = new Set(activeInstances.getStore() ?? []).add(self);
276
+ let outcome;
277
+ try {
278
+ outcome = activeInstances.run(inside, () => callGuest(instance, exportName, request, routed, deadline, allowAsync));
279
+ }
280
+ catch (error) {
281
+ release();
282
+ throw error;
283
+ }
284
+ if (outcome instanceof Promise) {
285
+ return outcome.finally(release);
286
+ }
287
+ release();
288
+ return outcome;
289
+ };
290
+ return (exportName, request, allowAsync) => {
291
+ if (activeInstances.getStore()?.has(self) === true) {
292
+ throw new CagedGuestError(`caged guest "${exportName}" failed: re-entrant call into a busy cage instance`);
293
+ }
294
+ const deadline = Date.now() + deadlineMs;
295
+ if (!running && waiting.length === 0) {
296
+ return start(exportName, request, deadline, allowAsync);
297
+ }
298
+ if (!allowAsync || waiting.length >= MAX_QUEUED_CALLS) {
299
+ throw new CagedGuestError(`caged guest "${exportName}" failed: the cage instance is busy`);
300
+ }
301
+ return new Promise((resolve, reject) => {
302
+ waiting.push(() => {
303
+ try {
304
+ Promise.resolve(start(exportName, request, deadline, allowAsync)).then(resolve, reject);
305
+ }
306
+ catch (error) {
307
+ reject(error);
308
+ }
309
+ });
310
+ });
311
+ };
312
+ }
313
+ function majorOf(version) {
314
+ return version === undefined ? 1 : Number(String(version).split('.')[0]);
315
+ }
316
+ /**
317
+ * Builds the descriptor of a caged participant: a participant whose code runs
318
+ * inside the WASM cage and which may be a giver (exposures and interception
319
+ * points) and an interceptor, exactly like a native participant.
320
+ *
321
+ * @param options - Token, manifest, guest module, and limits.
322
+ * @returns The participant's descriptor.
323
+ */
324
+ export function createCagedParticipant(options) {
325
+ const token = createServiceToken(options.token, `Caged participant "${options.token}"`);
326
+ const limits = options.limits ?? DEFAULT_CAGED_LIMITS;
327
+ const deadlineMs = limits.deadlineMs ?? DEFAULT_CAGED_LIMITS.deadlineMs ?? 30_000;
328
+ const manifest = options.manifest;
329
+ const points = new Set((manifest.interceptionPoints ?? []).map((point) => point.exposure));
330
+ return {
331
+ token,
332
+ tier: 'userland',
333
+ dependencies: [],
334
+ manifest,
335
+ factory: (_context, broker) => {
336
+ const { cage, engine: cageEngine } = loadNative();
337
+ const module = cage.CageModule.compile(cageEngine, Buffer.from(options.wasm));
338
+ const guest = cage.CageInstance.instantiate(module, [{ module: 'brud', name: 'call', kind: 'RoutedCall' }], {
339
+ fuel: limits.fuel,
340
+ maxMemoryBytes: limits.maxMemoryBytes,
341
+ timeoutMs: 0,
342
+ });
343
+ let evaluator = null;
344
+ let registryAccess;
345
+ const registry = () => {
346
+ registryAccess ??= broker.requestAccess({ callerId: token.id, tier: 'userland', options: {} }, ExposedApiRegistryToken);
347
+ return registryAccess;
348
+ };
349
+ const routed = (request, signal) => serveRoutedCall(registry, request, signal);
350
+ const run = createScheduler(guest, routed, deadlineMs);
351
+ const invoke = (exposure, method, rawArgs, caller) => {
352
+ // Capability views are carried as sorted arrays: the guest sees plain JSON.
353
+ const args = withPlainCapabilities(rawArgs);
354
+ const validation = argsSchema.validate(args);
355
+ if (!validation.valid) {
356
+ throw new CagedGuestError(`caged call "${exposure}.${method}": arguments are not plain values`);
357
+ }
358
+ let callArgs = args;
359
+ const name = exposure.slice(0, exposure.lastIndexOf('@'));
360
+ if (points.has(name)) {
361
+ if (evaluator === null) {
362
+ throw new InterceptionBlockedError(exposure, 'interception unavailable');
363
+ }
364
+ const outcome = evaluator.evaluate(exposure, method, callArgs, { caller });
365
+ if (!outcome.allowed) {
366
+ throw new InterceptionBlockedError(exposure, outcome.reason, outcome.interceptor);
367
+ }
368
+ callArgs = outcome.args;
369
+ }
370
+ const settle = (raw) => {
371
+ const response = raw;
372
+ if (response?.ok === true) {
373
+ return deepFreeze(response.value);
374
+ }
375
+ const code = typeof response?.error?.code === 'string' ? response.error.code : undefined;
376
+ const message = typeof response?.error?.message === 'string' ? response.error.message : 'guest refused the call';
377
+ throw new CagedGuestError(`caged call "${exposure}.${method}" failed: ${message}`, code);
378
+ };
379
+ // The output stage, for a point this participant owns: interceptors may append to the
380
+ // result; the caller then receives the envelope. Without one the result is as it was.
381
+ const finish = (raw) => {
382
+ const value = settle(raw);
383
+ if (!points.has(name)) {
384
+ return value;
385
+ }
386
+ if (evaluator === null) {
387
+ throw new InterceptionBlockedError(exposure, 'interception unavailable');
388
+ }
389
+ const staged = evaluator.evaluateResult(exposure, method, callArgs, value, { caller });
390
+ if (!staged.applied) {
391
+ return value;
392
+ }
393
+ if (!staged.allowed) {
394
+ throw new InterceptionBlockedError(exposure, staged.reason);
395
+ }
396
+ return staged.envelope;
397
+ };
398
+ const outcome = run('brud_invoke', {
399
+ kind: 'invoke',
400
+ exposure,
401
+ method,
402
+ args: callArgs,
403
+ caller: plainCaller(caller),
404
+ }, true);
405
+ return outcome instanceof Promise ? outcome.then(finish) : finish(outcome);
406
+ };
407
+ const bindings = {};
408
+ for (const declaration of manifest.exposures ?? []) {
409
+ const exposure = `${declaration.name}@${String(majorOf(declaration.version))}`;
410
+ bindings[exposure] = {
411
+ projection: (_service, caller) => new Proxy(Object.freeze({}), {
412
+ get: (_target, method) => (typeof method !== 'string' || method === 'then' || method === 'toJSON'
413
+ ? undefined
414
+ : (...args) => invoke(exposure, method, args, caller)),
415
+ }),
416
+ };
417
+ }
418
+ const instance = {
419
+ async onRunning() {
420
+ if (points.size > 0) {
421
+ evaluator = registry().resolve('interception.evaluate');
422
+ }
423
+ if (guest.hasExport('brud_start')) {
424
+ const started = await run('brud_start', { kind: 'start', token: token.id }, true);
425
+ if (started?.ok !== true) {
426
+ const message = typeof started?.error?.message === 'string' ? started.error.message : 'guest refused to start';
427
+ throw new CagedGuestError(`caged participant "${token.id}" failed to start: ${message}`);
428
+ }
429
+ }
430
+ },
431
+ };
432
+ const declaresStage = (stage) => (manifest.interceptions ?? []).some((entry) => (entry.stages ?? ['input']).includes(stage));
433
+ if (declaresStage('output')) {
434
+ Object.defineProperty(instance, 'interceptResult', {
435
+ value: (call) => {
436
+ const verdict = run('brud_intercept_result', call, false);
437
+ if (!isOutputVerdict(verdict)) {
438
+ throw new CagedGuestError('invalid output verdict');
439
+ }
440
+ return deepFreeze(verdict);
441
+ },
442
+ enumerable: false,
443
+ });
444
+ }
445
+ if (declaresStage('input')) {
446
+ Object.defineProperty(instance, 'intercept', {
447
+ value: (call) => {
448
+ const verdict = run('brud_intercept', call, false);
449
+ if (!isVerdict(verdict)) {
450
+ throw new CagedGuestError('invalid verdict');
451
+ }
452
+ return deepFreeze(verdict);
453
+ },
454
+ enumerable: false,
455
+ });
456
+ }
457
+ return withExposureBindings(instance, bindings);
458
+ },
459
+ };
460
+ }
@@ -0,0 +1,47 @@
1
+ import type { KernelCallAuthority, ServiceDescriptor, ServiceTier } from '../../../src/contracts/index.js';
2
+ /** Tier assigned to the cage's descriptor. */
3
+ export declare const WASM_CAGE_SERVICE_TIER: ServiceTier;
4
+ /** Contract version declared for the cage's interface. */
5
+ export declare const WASM_CAGE_CONTRACT_VERSION = "1.0.0";
6
+ /**
7
+ * Methods declared for the cage's interface.
8
+ *
9
+ * The cage's only participant-facing surface is the exposed-API registry's
10
+ * `resolve` (design record W-02, W-09). The cage is not a second giver; it is
11
+ * the mechanism that carries a caged participant's call to the registry.
12
+ */
13
+ export declare const WASM_CAGE_CONTRACT_METHODS: readonly ["resolve"];
14
+ /** Public interface the cage promises to the kernel. */
15
+ export interface IWasmCage {
16
+ /**
17
+ * Binds the kernel's call authority.
18
+ *
19
+ * Called once from the cage's hardcore boot hook, with the authority the
20
+ * kernel hands that hook. Before it is called, `resolve` returns `null`
21
+ * rather than running without a chain.
22
+ *
23
+ * @param value - The kernel's call authority.
24
+ */
25
+ bindAuthority(value: KernelCallAuthority): void;
26
+ /**
27
+ * Runs one caged participant's `resolve` against the exposed-API registry.
28
+ *
29
+ * The cage starts a `runtime`-origin chain with the caged participant's
30
+ * recorded caller (W-06), so the frame carries the participant's
31
+ * kernel-issued identity and its parent relation (W-07). The cage does not
32
+ * decide policy: the registry evaluates the giver's Layer 1 policy. The cage
33
+ * is the door, and `resolve` is the only method on its surface (W-02, W-09).
34
+ *
35
+ * @param participantIdentity - The caged participant's kernel-issued token.
36
+ * @param name - The exposure to resolve.
37
+ * @param options - Version and expected owner identity.
38
+ * @returns The resolved handle, or `null`.
39
+ */
40
+ resolve<T = unknown>(participantIdentity: string, name: string, options?: {
41
+ readonly version?: number | string;
42
+ readonly expectedOwner?: string;
43
+ }): T | null;
44
+ }
45
+ /** Token identifying the cage. */
46
+ export declare const WasmCageToken: import("../../../src/contracts/serviceToken.js").ServiceToken<IWasmCage>;
47
+ export declare function createWasmCageDescriptor(): ServiceDescriptor<IWasmCage>;