@brud/kernel 0.0.1 → 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 +0 -0
  2. package/README.md +0 -0
  3. package/dist/index.d.ts +0 -0
  4. package/dist/index.js +0 -0
  5. package/dist/serviceModules/events.d.ts +0 -0
  6. package/dist/serviceModules/events.js +0 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +0 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +0 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +0 -0
  10. package/dist/serviceModules/identityRegistry.js +0 -0
  11. package/dist/serviceModules/interception.d.ts +0 -0
  12. package/dist/serviceModules/interception.js +0 -0
  13. package/dist/serviceModules/parser.d.ts +0 -0
  14. package/dist/serviceModules/parser.js +0 -0
  15. package/dist/serviceModules/router.d.ts +0 -0
  16. package/dist/serviceModules/router.js +0 -0
  17. package/dist/serviceModules/wasmCage.d.ts +0 -0
  18. package/dist/serviceModules/wasmCage.js +0 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +0 -0
  20. package/dist/services/Events/contracts/IEventsService.js +0 -0
  21. package/dist/services/Events/contracts/errors.d.ts +0 -0
  22. package/dist/services/Events/contracts/errors.js +0 -0
  23. package/dist/services/Events/contracts/index.d.ts +0 -0
  24. package/dist/services/Events/contracts/index.js +0 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +0 -0
  26. package/dist/services/Events/contracts/tokens.js +0 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +0 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +0 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +0 -0
  30. package/dist/services/Events/descriptor/tokens.js +0 -0
  31. package/dist/services/Events/index.d.ts +0 -0
  32. package/dist/services/Events/index.js +0 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +0 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +0 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +0 -0
  36. package/dist/services/Events/orchestrator/index.js +0 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +0 -0
  38. package/dist/services/Events/orchestrator/limits.js +0 -0
  39. package/dist/services/Events/serviceModule.d.ts +0 -0
  40. package/dist/services/Events/serviceModule.js +0 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +13 -1
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +0 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +0 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +0 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +1 -1
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +0 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +0 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +0 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +0 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +0 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +21 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +0 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +2 -2
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +2 -2
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +0 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +0 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +0 -0
  58. package/dist/services/ExposedApiRegistry/index.js +0 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +9 -2
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +50 -5
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +0 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +0 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +0 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +0 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +0 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +0 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +0 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +0 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +0 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +0 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +0 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +0 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +0 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +0 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +0 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +0 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +0 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +0 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +0 -0
  80. package/dist/services/IdentityRegistry/index.js +0 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +0 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +0 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +0 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +0 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +0 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +0 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +91 -1
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -1
  89. package/dist/services/Interception/contracts/errors.d.ts +0 -0
  90. package/dist/services/Interception/contracts/errors.js +0 -0
  91. package/dist/services/Interception/contracts/index.d.ts +0 -0
  92. package/dist/services/Interception/contracts/index.js +0 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +0 -0
  94. package/dist/services/Interception/contracts/tokens.js +0 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +1 -1
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +2 -1
  97. package/dist/services/Interception/descriptor/tokens.d.ts +0 -0
  98. package/dist/services/Interception/descriptor/tokens.js +0 -0
  99. package/dist/services/Interception/index.d.ts +0 -0
  100. package/dist/services/Interception/index.js +0 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +9 -1
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +167 -4
  103. package/dist/services/Interception/orchestrator/index.d.ts +0 -0
  104. package/dist/services/Interception/orchestrator/index.js +0 -0
  105. package/dist/services/Interception/serviceModule.d.ts +0 -0
  106. package/dist/services/Interception/serviceModule.js +0 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +0 -0
  108. package/dist/services/Parser/contracts/IParserService.js +0 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +0 -0
  110. package/dist/services/Parser/contracts/errors.js +0 -0
  111. package/dist/services/Parser/contracts/index.d.ts +0 -0
  112. package/dist/services/Parser/contracts/index.js +0 -0
  113. package/dist/services/Parser/contracts/types.d.ts +0 -0
  114. package/dist/services/Parser/contracts/types.js +0 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +0 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +0 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +0 -0
  118. package/dist/services/Parser/descriptor/tokens.js +0 -0
  119. package/dist/services/Parser/index.d.ts +0 -0
  120. package/dist/services/Parser/index.js +0 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +0 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +0 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +0 -0
  124. package/dist/services/Parser/orchestrator/index.js +0 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +0 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +0 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +0 -0
  128. package/dist/services/Parser/parser/parameters.js +0 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +0 -0
  130. package/dist/services/Parser/parser/scanner.js +0 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +0 -0
  132. package/dist/services/Parser/parser/syntax.js +0 -0
  133. package/dist/services/Parser/serviceModule.d.ts +0 -0
  134. package/dist/services/Parser/serviceModule.js +0 -0
  135. package/dist/services/Router/bootOptions.d.ts +0 -0
  136. package/dist/services/Router/bootOptions.js +0 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +1 -1
  138. package/dist/services/Router/contracts/IRouterService.js +0 -0
  139. package/dist/services/Router/contracts/caller.d.ts +0 -0
  140. package/dist/services/Router/contracts/caller.js +0 -0
  141. package/dist/services/Router/contracts/errors.d.ts +12 -1
  142. package/dist/services/Router/contracts/errors.js +15 -0
  143. package/dist/services/Router/contracts/index.d.ts +2 -2
  144. package/dist/services/Router/contracts/index.js +1 -1
  145. package/dist/services/Router/contracts/kind.d.ts +0 -0
  146. package/dist/services/Router/contracts/kind.js +0 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +0 -0
  148. package/dist/services/Router/contracts/registrant.js +0 -0
  149. package/dist/services/Router/contracts/types.d.ts +28 -8
  150. package/dist/services/Router/contracts/types.js +0 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +0 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +1 -1
  153. package/dist/services/Router/descriptor/tokens.d.ts +0 -0
  154. package/dist/services/Router/descriptor/tokens.js +0 -0
  155. package/dist/services/Router/index.d.ts +0 -0
  156. package/dist/services/Router/index.js +0 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +22 -3
  158. package/dist/services/Router/orchestrator/RouterService.js +131 -6
  159. package/dist/services/Router/orchestrator/index.d.ts +0 -0
  160. package/dist/services/Router/orchestrator/index.js +0 -0
  161. package/dist/services/Router/serviceModule.d.ts +0 -0
  162. package/dist/services/Router/serviceModule.js +0 -0
  163. package/dist/services/WasmCage/index.d.ts +0 -0
  164. package/dist/services/WasmCage/index.js +0 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +0 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +0 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +0 -0
  168. package/dist/services/WasmCage/serviceModule.js +0 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +19 -2
  170. package/dist/services/WasmCage/src/caged.js +85 -6
  171. package/dist/services/WasmCage/src/descriptor.d.ts +0 -0
  172. package/dist/services/WasmCage/src/descriptor.js +0 -0
  173. package/dist/services/WasmCage/src/native.d.ts +0 -0
  174. package/dist/services/WasmCage/src/native.js +0 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +0 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +5 -5
  177. package/dist/services/WasmCage/src/package.d.ts +0 -0
  178. package/dist/services/WasmCage/src/package.js +0 -0
  179. package/dist/services/shared/canonicalJson.d.ts +0 -0
  180. package/dist/services/shared/canonicalJson.js +0 -0
  181. package/dist/services/shared/documentStore.d.ts +0 -0
  182. package/dist/services/shared/documentStore.js +0 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +4 -3
  184. package/dist/src/bootstrap/bootKernelInternal.js +284 -71
  185. package/dist/src/bootstrap/bootTypes.d.ts +25 -1
  186. package/dist/src/bootstrap/bootTypes.js +0 -0
  187. package/dist/src/bootstrap/config/index.d.ts +0 -0
  188. package/dist/src/bootstrap/config/index.js +0 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +11 -0
  190. package/dist/src/bootstrap/config/integrity.js +13 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +0 -0
  192. package/dist/src/bootstrap/config/parse.js +0 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +0 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +0 -0
  195. package/dist/src/bootstrap/config/types.d.ts +1 -1
  196. package/dist/src/bootstrap/config/types.js +0 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +0 -0
  198. package/dist/src/bootstrap/hardcore.js +0 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +0 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +14 -14
  201. package/dist/src/bootstrap/index.d.ts +6 -1
  202. package/dist/src/bootstrap/index.js +2 -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 +0 -0
  206. package/dist/src/bootstrap/packageRequirements.js +0 -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 +0 -0
  212. package/dist/src/contracts/accessBroker.js +0 -0
  213. package/dist/src/contracts/brudOperation.d.ts +0 -0
  214. package/dist/src/contracts/brudOperation.js +0 -0
  215. package/dist/src/contracts/callChain.d.ts +0 -0
  216. package/dist/src/contracts/callChain.js +0 -0
  217. package/dist/src/contracts/capability.d.ts +0 -0
  218. package/dist/src/contracts/capability.js +0 -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 +0 -0
  222. package/dist/src/contracts/container.js +0 -0
  223. package/dist/src/contracts/context.d.ts +0 -0
  224. package/dist/src/contracts/context.js +0 -0
  225. package/dist/src/contracts/contextContract.d.ts +11 -8
  226. package/dist/src/contracts/contextContract.js +21 -32
  227. package/dist/src/contracts/dispatchView.d.ts +3 -3
  228. package/dist/src/contracts/dispatchView.js +0 -0
  229. package/dist/src/contracts/handler.d.ts +0 -7
  230. package/dist/src/contracts/handler.js +0 -0
  231. package/dist/src/contracts/index.d.ts +2 -1
  232. package/dist/src/contracts/index.js +1 -0
  233. package/dist/src/contracts/kernel.d.ts +0 -0
  234. package/dist/src/contracts/kernel.js +0 -0
  235. package/dist/src/contracts/lifecycle.d.ts +0 -0
  236. package/dist/src/contracts/lifecycle.js +0 -0
  237. package/dist/src/contracts/manifest.d.ts +35 -0
  238. package/dist/src/contracts/manifest.js +62 -23
  239. package/dist/src/contracts/pipeline.d.ts +0 -0
  240. package/dist/src/contracts/pipeline.js +0 -0
  241. package/dist/src/contracts/policy.d.ts +0 -0
  242. package/dist/src/contracts/policy.js +0 -0
  243. package/dist/src/contracts/registry.d.ts +0 -0
  244. package/dist/src/contracts/registry.js +0 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +0 -0
  246. package/dist/src/contracts/serviceDescriptor.js +0 -0
  247. package/dist/src/contracts/serviceToken.d.ts +0 -0
  248. package/dist/src/contracts/serviceToken.js +0 -0
  249. package/dist/src/engine/BrudKernel.d.ts +2 -0
  250. package/dist/src/engine/BrudKernel.js +35 -6
  251. package/dist/src/engine/ExecutionPipeline.d.ts +0 -0
  252. package/dist/src/engine/ExecutionPipeline.js +0 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +0 -0
  254. package/dist/src/engine/KernelAccessBroker.js +0 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +0 -0
  256. package/dist/src/engine/KernelRegistry.js +0 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +0 -0
  258. package/dist/src/engine/OperationRegistry.js +0 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +0 -0
  260. package/dist/src/engine/ServiceContainer.js +0 -0
  261. package/dist/src/engine/callChain.d.ts +0 -0
  262. package/dist/src/engine/callChain.js +5 -10
  263. package/dist/src/engine/dag.d.ts +0 -0
  264. package/dist/src/engine/dag.js +0 -0
  265. package/dist/src/engine/errors.d.ts +0 -0
  266. package/dist/src/engine/errors.js +0 -0
  267. package/dist/src/engine/index.d.ts +0 -0
  268. package/dist/src/engine/index.js +0 -0
  269. package/dist/src/engine/state.d.ts +0 -0
  270. package/dist/src/engine/state.js +0 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +0 -0
  272. package/dist/src/validation/jsonSchema/compile.js +0 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +0 -0
  274. package/dist/src/validation/jsonSchema/index.js +0 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +0 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +0 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +0 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +0 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +0 -0
  280. package/dist/src/validation/jsonSchema/types.js +0 -0
  281. package/package.json +1 -1
  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
@@ -1,5 +1,6 @@
1
+ import { evaluateExposedApiPolicy, parseExposedApiPolicy, } from '../../ExposedApiRegistry/contracts/policy.js';
1
2
  import { isValidRouterKind } from '../contracts/kind.js';
2
- import { RouterDisposedError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, } from '../contracts/errors.js';
3
+ import { RouterDisposedError, RouterInvalidDeclarationError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, } from '../contracts/errors.js';
3
4
  /**
4
5
  * Level-1 Brud kind Router.
5
6
  *
@@ -9,11 +10,15 @@ import { RouterDisposedError, RouterInvalidKindError, RouterKindCollisionError,
9
10
  * guard for alternate compositions.
10
11
  *
11
12
  * Dispatch resolves every target through the access broker with the token the
12
- * owning service supplied, so access policies still apply and a plugin can
13
- * never be a routing target.
13
+ * owning service supplied, so access policies still apply and only the
14
+ * owning service can be a routing target.
14
15
  */
15
16
  export class RouterService {
16
17
  registrations = new Map();
18
+ /** The parsed permission of every declared operation, by kind then operation. Frozen at registration. */
19
+ permissions = new Map();
20
+ /** The one permission of every kind whose owner defines its operation names. */
21
+ openKinds = new Map();
17
22
  authority;
18
23
  dependencies;
19
24
  parser;
@@ -40,7 +45,7 @@ export class RouterService {
40
45
  identity: context.caller.identity,
41
46
  callerClass: context.caller.callerClass,
42
47
  official: context.caller.official,
43
- capabilities: Object.freeze([...context.caller.capabilities].sort()),
48
+ capabilities: context.caller.capabilities,
44
49
  origin: context.origin,
45
50
  });
46
51
  }
@@ -72,7 +77,8 @@ export class RouterService {
72
77
  exposure: declaration.exposure,
73
78
  ...(declaration.version === undefined ? {} : { version: Number(declaration.version) }),
74
79
  ...(declaration.description === undefined ? {} : { description: declaration.description }),
75
- ...(declaration.operations === undefined ? {} : { operations: declaration.operations }),
80
+ operations: declaration.operations,
81
+ ...(declaration.permission === undefined ? {} : { permission: declaration.permission }),
76
82
  }, owner);
77
83
  }
78
84
  register(registration, owner) {
@@ -92,7 +98,60 @@ export class RouterService {
92
98
  if (typeof registration.exposure !== 'string' || registration.exposure.length === 0) {
93
99
  throw new RouterInvalidKindError(registration.kind);
94
100
  }
101
+ const compiled = this.compilePermissions(registration);
95
102
  this.registrations.set(registration.kind, Object.freeze({ ...registration, ...(owner === undefined ? {} : { owner }) }));
103
+ if (compiled instanceof Map) {
104
+ this.permissions.set(registration.kind, compiled);
105
+ }
106
+ else {
107
+ this.openKinds.set(registration.kind, compiled);
108
+ }
109
+ }
110
+ /**
111
+ * Builds the operation registry for one kind: every operation must be
112
+ * declared and carry a valid permission, its own or the kind's. Refuses the
113
+ * declaration, and so the boot, otherwise.
114
+ */
115
+ compilePermissions(registration) {
116
+ const refuse = (reason) => {
117
+ throw new RouterInvalidDeclarationError(registration.kind, reason);
118
+ };
119
+ const operations = registration.operations;
120
+ if (operations === 'open') {
121
+ if (registration.permission === undefined) {
122
+ return refuse('an open operation vocabulary needs a kind-level permission');
123
+ }
124
+ }
125
+ else if (typeof operations !== 'object' || operations === null || Array.isArray(operations) || Object.keys(operations).length === 0) {
126
+ return refuse('it must declare every operation it serves');
127
+ }
128
+ const parse = (value, where) => {
129
+ let policy;
130
+ try {
131
+ policy = parseExposedApiPolicy(value);
132
+ }
133
+ catch (error) {
134
+ return refuse(`${where} permission is invalid (${describe(error)})`);
135
+ }
136
+ if (policy.parentCallerClasses !== undefined) {
137
+ return refuse(`${where} permission cannot use parentCallerClasses: the Router does not know the caller's parent`);
138
+ }
139
+ return policy;
140
+ };
141
+ const fallback = registration.permission === undefined ? undefined : parse(registration.permission, 'the kind');
142
+ if (registration.operations === 'open') {
143
+ return fallback;
144
+ }
145
+ const compiled = new Map();
146
+ for (const [name, operation] of Object.entries(registration.operations)) {
147
+ const own = operation.permission === undefined ? undefined : parse(operation.permission, `operation "${name}"`);
148
+ const effective = own ?? fallback;
149
+ if (effective === undefined) {
150
+ return refuse(`operation "${name}" has no permission and the kind declares none`);
151
+ }
152
+ compiled.set(name, effective);
153
+ }
154
+ return compiled;
96
155
  }
97
156
  closeRegistration() {
98
157
  this.closed = true;
@@ -112,7 +171,13 @@ export class RouterService {
112
171
  return Object.freeze(Array.from(this.registrations.values(), (registration) => Object.freeze({
113
172
  kind: registration.kind,
114
173
  ...(registration.description === undefined ? {} : { description: registration.description }),
115
- ...(registration.operations === undefined ? {} : { operations: registration.operations }),
174
+ ...(registration.operations === 'open' ? { open: true } : { operations: Object.freeze(Object.fromEntries(Object.entries(registration.operations).map(([name, operation]) => [
175
+ name,
176
+ Object.freeze({
177
+ ...(operation.description === undefined ? {} : { description: operation.description }),
178
+ ...(operation.input === undefined ? {} : { input: operation.input }),
179
+ }),
180
+ ]))) }),
116
181
  })));
117
182
  }
118
183
  async route(rawInput, options = {}, caller) {
@@ -169,6 +234,23 @@ export class RouterService {
169
234
  }
170
235
  continue;
171
236
  }
237
+ const refusal = this.refuseBeforeOwner(registration.kind, operation, routeCaller);
238
+ if (refusal !== undefined) {
239
+ failed += 1;
240
+ outcomes.push({
241
+ operationIndex: operation.index,
242
+ sequence,
243
+ kind: operation.kind,
244
+ name: operation.name,
245
+ status: refusal.status,
246
+ error: refusal.error,
247
+ });
248
+ if (stopOnFailure) {
249
+ appendRemaining(outcomes, operations, sequence + 1, 'skipped');
250
+ break;
251
+ }
252
+ continue;
253
+ }
172
254
  let result;
173
255
  try {
174
256
  // The access broker is the only resolution path: the registered token
@@ -239,6 +321,49 @@ export class RouterService {
239
321
  failed,
240
322
  };
241
323
  }
324
+ /**
325
+ * The operation registry check, run before the owner is resolved: the
326
+ * operation must be declared for its kind, and the caller must hold the
327
+ * operation's permission. The reason a permission is denied goes to the
328
+ * observation stream, never to the caller.
329
+ */
330
+ refuseBeforeOwner(kind, operation, caller) {
331
+ const policy = this.openKinds.get(kind) ?? this.permissions.get(kind)?.get(operation.name);
332
+ if (policy === undefined) {
333
+ this.observeRefusal('operation-not-declared', kind, operation.name, caller, undefined);
334
+ return {
335
+ status: 'operation_not_declared',
336
+ error: `OPERATION_NOT_DECLARED: kind "${kind}" does not declare operation "${operation.name}"`,
337
+ };
338
+ }
339
+ const decision = evaluateExposedApiPolicy(policy, 'any', {
340
+ origin: caller.origin,
341
+ caller: {
342
+ callerClass: caller.callerClass,
343
+ identity: caller.identity,
344
+ official: caller.official,
345
+ capabilities: caller.capabilities,
346
+ },
347
+ });
348
+ if (decision.allowed) {
349
+ return undefined;
350
+ }
351
+ this.observeRefusal('permission-denied', kind, operation.name, caller, decision.reason);
352
+ return {
353
+ status: 'permission_denied',
354
+ error: `PERMISSION_DENIED: the caller may not call operation "${operation.name}" of kind "${kind}"`,
355
+ };
356
+ }
357
+ observeRefusal(event, kind, name, caller, reason) {
358
+ this.authority?.observe('router', event, {
359
+ kind,
360
+ operation: name,
361
+ ...(reason === undefined ? {} : { reason }),
362
+ callerIdentity: caller.identity,
363
+ callerClass: caller.callerClass,
364
+ origin: caller.origin,
365
+ });
366
+ }
242
367
  resolveParser() {
243
368
  this.parser ??= this.dependencies.getParser();
244
369
  return this.parser;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -11,7 +11,10 @@ import type { ParticipantManifest, ServiceDescriptor } from '../../../src/contra
11
11
  * - `brud_alloc(len: i32) -> i32` — returns a pointer to `len` writable bytes;
12
12
  * - `brud_invoke(ptr: i32, len: i32) -> i64` — a call on one of its exposures;
13
13
  * - `brud_intercept(ptr: i32, len: i32) -> i64` — an interception verdict
14
- * (only when the manifest declares `interceptions`);
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);
15
18
  * - optionally `brud_start(ptr: i32, len: i32) -> i64` — called once when the
16
19
  * participant starts running, with `{ kind: 'start', token }`; it answers
17
20
  * `{ ok: true }` or `{ ok: false, error }` (a failure fails the start).
@@ -40,6 +43,9 @@ import type { ParticipantManifest, ServiceDescriptor } from '../../../src/contra
40
43
  * Response: `{ ok: true, value }` or `{ ok: false, error: { code, message } }`.
41
44
  * - `brud_intercept` request: the {@link InterceptedCall} as JSON. Response:
42
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.
43
49
  *
44
50
  * ## Security properties
45
51
  *
@@ -91,8 +97,19 @@ export declare class CagedGuestError extends Error {
91
97
  readonly code: "WASM_CAGE_GUEST_FAILED";
92
98
  /** The guest-reported error code, when the guest reported one. */
93
99
  readonly guestCode: string | undefined;
94
- constructor(message: string, guestCode?: string, options?: ErrorOptions);
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
+ });
95
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;
96
113
  /**
97
114
  * Builds the descriptor of a caged participant: a participant whose code runs
98
115
  * inside the WASM cage and which may be a giver (exposures and interception
@@ -1,3 +1,4 @@
1
+ import { withPlainCapabilities } from '../../../src/contracts/capabilitySet.js';
1
2
  import { AsyncLocalStorage } from 'node:async_hooks';
2
3
  import { createServiceToken } from '../../../src/contracts/index.js';
3
4
  import { compileJsonSchema } from '../../../src/validation/jsonSchema/index.js';
@@ -15,10 +16,16 @@ export class CagedGuestError extends Error {
15
16
  code = 'WASM_CAGE_GUEST_FAILED';
16
17
  /** The guest-reported error code, when the guest reported one. */
17
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;
18
23
  constructor(message, guestCode, options) {
19
24
  super(message, options);
20
25
  this.name = 'CagedGuestError';
21
26
  this.guestCode = guestCode;
27
+ this.reason = options?.reason;
28
+ this.detail = options?.detail;
22
29
  }
23
30
  }
24
31
  let engine;
@@ -43,10 +50,41 @@ function deepFreeze(value) {
43
50
  }
44
51
  return value;
45
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
+ };
46
77
  function guestFailure(exportName, error) {
47
- return error instanceof CagedGuestError
48
- ? error
49
- : new CagedGuestError(`caged guest "${exportName}" failed: ${error.message}`, undefined, { cause: 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 }) });
50
88
  }
51
89
  function step(exportName, run) {
52
90
  try {
@@ -144,6 +182,13 @@ function plainCaller(caller) {
144
182
  origin: caller.origin,
145
183
  };
146
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
+ }
147
192
  function isVerdict(value) {
148
193
  if (value === null || typeof value !== 'object') {
149
194
  return false;
@@ -303,7 +348,9 @@ export function createCagedParticipant(options) {
303
348
  };
304
349
  const routed = (request, signal) => serveRoutedCall(registry, request, signal);
305
350
  const run = createScheduler(guest, routed, deadlineMs);
306
- const invoke = (exposure, method, args, caller) => {
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);
307
354
  const validation = argsSchema.validate(args);
308
355
  if (!validation.valid) {
309
356
  throw new CagedGuestError(`caged call "${exposure}.${method}": arguments are not plain values`);
@@ -329,6 +376,25 @@ export function createCagedParticipant(options) {
329
376
  const message = typeof response?.error?.message === 'string' ? response.error.message : 'guest refused the call';
330
377
  throw new CagedGuestError(`caged call "${exposure}.${method}" failed: ${message}`, code);
331
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
+ };
332
398
  const outcome = run('brud_invoke', {
333
399
  kind: 'invoke',
334
400
  exposure,
@@ -336,7 +402,7 @@ export function createCagedParticipant(options) {
336
402
  args: callArgs,
337
403
  caller: plainCaller(caller),
338
404
  }, true);
339
- return outcome instanceof Promise ? outcome.then(settle) : settle(outcome);
405
+ return outcome instanceof Promise ? outcome.then(finish) : finish(outcome);
340
406
  };
341
407
  const bindings = {};
342
408
  for (const declaration of manifest.exposures ?? []) {
@@ -363,7 +429,20 @@ export function createCagedParticipant(options) {
363
429
  }
364
430
  },
365
431
  };
366
- if ((manifest.interceptions ?? []).length > 0) {
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')) {
367
446
  Object.defineProperty(instance, 'intercept', {
368
447
  value: (call) => {
369
448
  const verdict = run('brud_intercept', call, false);
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -7,9 +7,9 @@
7
7
  * binary whose digest is not listed here.
8
8
  */
9
9
  export const WASM_CAGE_NATIVE_DIGESTS = Object.freeze([
10
- ['darwin-arm64', 'aaeb94c102b3299a73914bc2b17a78d695bb8279d74612b07be663cae92c3e39'],
11
- ['darwin-x64', '166123bf656caec62b96c3edff9efc024f4a9e17a866a8c8cba8098d79db2456'],
12
- ['linux-arm64-gnu', 'bc57be8ce648c88cba8e1fa703c8ce74fc65d5bafa2dc70713389f31353fba73'],
13
- ['linux-x64-gnu', '05b3ac5e3e616873419bd805d52ee5fb11746f5b9b681f767e28c47b181313a6'],
14
- ['win32-x64-msvc', 'f3040c1233215f6ccfd2f767c9d1586aff2efe02a4cc1d5971e431277c0e4b10'],
10
+ ['darwin-arm64', '47af7e64c8481e42cd7b73bd89ac3f69da182591b64a1b656a33725cb5e64cad'],
11
+ ['darwin-x64', 'c833ad031943aa522720805a418edb36add03da0f79bf4421aa908d7644f324a'],
12
+ ['linux-arm64-gnu', '5c420e2cf34c26dbd15951d8e9d4c0444f89ac8c3e789637d0a75661699ed25c'],
13
+ ['linux-x64-gnu', '7c7d46dfe4b3c72c2612b9742bb474d97f05670332f175055a33d37e61ef5ffa'],
14
+ ['win32-x64-msvc', '5be0f4f1b82ab17284afa78b0248d300a8a1589ae288dacbfe2f628d9bed85e2'],
15
15
  ]);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import { BrudKernel } from '../engine/BrudKernel.js';
1
+ import { type ReloadableKernel } from './reload.js';
2
2
  import type { BootKernelOptions, ComposeKernelOptions } from './bootTypes.js';
3
3
  /**
4
4
  * Reads, validates, composes, and boots a kernel from `brud.config.json`.
@@ -6,7 +6,7 @@ import type { BootKernelOptions, ComposeKernelOptions } from './bootTypes.js';
6
6
  * @param configPath - Path to the config file.
7
7
  * @param options - Generic options bag and logger.
8
8
  */
9
- export declare function bootKernel(configPath: string, options: BootKernelOptions): Promise<BrudKernel>;
9
+ export declare function bootKernel(configPath: string, options: BootKernelOptions): Promise<ReloadableKernel>;
10
10
  /**
11
11
  * Builds a kernel whose config is composed lazily on the first `boot()`.
12
12
  *
@@ -15,4 +15,5 @@ export declare function bootKernel(configPath: string, options: BootKernelOption
15
15
  * instances in the ESM cache instead of loading a second copy through
16
16
  * `require`.
17
17
  */
18
- export declare function createDeferredKernel(configPath: string, options: ComposeKernelOptions): BrudKernel;
18
+ export declare function createDeferredKernel(configPath: string, options: ComposeKernelOptions): ReloadableKernel;
19
+ export declare function resolveModuleId(declaredPath: string, configPath: string): string;