@brud/kernel 0.0.0-stage → 0.0.1

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 (278) 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 +44 -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 +112 -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 +61 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -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 +65 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +1 -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 +49 -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 +32 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +180 -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 +56 -0
  142. package/dist/services/Router/contracts/errors.js +75 -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 +90 -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 +74 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +332 -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 +104 -0
  170. package/dist/services/WasmCage/src/caged.js +381 -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 +18 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +420 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +89 -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 +34 -0
  190. package/dist/src/bootstrap/config/integrity.js +79 -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 +8 -0
  202. package/dist/src/bootstrap/index.js +5 -0
  203. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  204. package/dist/src/bootstrap/packageRequirements.js +52 -0
  205. package/dist/src/contracts/accessBroker.d.ts +53 -0
  206. package/dist/src/contracts/accessBroker.js +1 -0
  207. package/dist/src/contracts/brudOperation.d.ts +20 -0
  208. package/dist/src/contracts/brudOperation.js +20 -0
  209. package/dist/src/contracts/callChain.d.ts +161 -0
  210. package/dist/src/contracts/callChain.js +19 -0
  211. package/dist/src/contracts/capability.d.ts +26 -0
  212. package/dist/src/contracts/capability.js +26 -0
  213. package/dist/src/contracts/container.d.ts +17 -0
  214. package/dist/src/contracts/container.js +8 -0
  215. package/dist/src/contracts/context.d.ts +19 -0
  216. package/dist/src/contracts/context.js +1 -0
  217. package/dist/src/contracts/contextContract.d.ts +129 -0
  218. package/dist/src/contracts/contextContract.js +285 -0
  219. package/dist/src/contracts/dispatchView.d.ts +21 -0
  220. package/dist/src/contracts/dispatchView.js +1 -0
  221. package/dist/src/contracts/handler.d.ts +28 -0
  222. package/dist/src/contracts/handler.js +1 -0
  223. package/dist/src/contracts/index.d.ts +25 -0
  224. package/dist/src/contracts/index.js +8 -0
  225. package/dist/src/contracts/kernel.d.ts +60 -0
  226. package/dist/src/contracts/kernel.js +1 -0
  227. package/dist/src/contracts/lifecycle.d.ts +59 -0
  228. package/dist/src/contracts/lifecycle.js +1 -0
  229. package/dist/src/contracts/manifest.d.ts +145 -0
  230. package/dist/src/contracts/manifest.js +295 -0
  231. package/dist/src/contracts/pipeline.d.ts +8 -0
  232. package/dist/src/contracts/pipeline.js +1 -0
  233. package/dist/src/contracts/policy.d.ts +75 -0
  234. package/dist/src/contracts/policy.js +77 -0
  235. package/dist/src/contracts/registry.d.ts +7 -0
  236. package/dist/src/contracts/registry.js +1 -0
  237. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  238. package/dist/src/contracts/serviceDescriptor.js +1 -0
  239. package/dist/src/contracts/serviceToken.d.ts +36 -0
  240. package/dist/src/contracts/serviceToken.js +16 -0
  241. package/dist/src/engine/BrudKernel.d.ts +118 -0
  242. package/dist/src/engine/BrudKernel.js +366 -0
  243. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  244. package/dist/src/engine/ExecutionPipeline.js +62 -0
  245. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  246. package/dist/src/engine/KernelAccessBroker.js +107 -0
  247. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  248. package/dist/src/engine/KernelRegistry.js +33 -0
  249. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  250. package/dist/src/engine/OperationRegistry.js +18 -0
  251. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  252. package/dist/src/engine/ServiceContainer.js +53 -0
  253. package/dist/src/engine/callChain.d.ts +68 -0
  254. package/dist/src/engine/callChain.js +180 -0
  255. package/dist/src/engine/dag.d.ts +2 -0
  256. package/dist/src/engine/dag.js +34 -0
  257. package/dist/src/engine/errors.d.ts +26 -0
  258. package/dist/src/engine/errors.js +52 -0
  259. package/dist/src/engine/index.d.ts +11 -0
  260. package/dist/src/engine/index.js +8 -0
  261. package/dist/src/engine/state.d.ts +1 -0
  262. package/dist/src/engine/state.js +1 -0
  263. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  264. package/dist/src/validation/jsonSchema/compile.js +386 -0
  265. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  266. package/dist/src/validation/jsonSchema/index.js +2 -0
  267. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  268. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  269. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  270. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  271. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  272. package/dist/src/validation/jsonSchema/types.js +15 -0
  273. package/package.json +59 -4
  274. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  275. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  276. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  277. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  278. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,36 @@
1
+ import type { ServiceTier } from '../../../src/contracts/lifecycle.js';
2
+ import type { ServiceDescriptor } from '../../../src/contracts/serviceDescriptor.js';
3
+ import type { IIdentityRegistry } from '../contracts/types.js';
4
+ import { IdentityRegistryService } from '../orchestrator/IdentityRegistryService.js';
5
+ /** Namespace owned by the identity registry in the context contract. */
6
+ export declare const IDENTITY_REGISTRY_CONTEXT_SCOPE = "identity";
7
+ /** Namespaced context field holding the absolute registry storage file path. */
8
+ export declare const IDENTITY_REGISTRY_PATH_CONTEXT_FIELD = "identity.registry.path";
9
+ /** Tier assigned to the identity registry descriptor. */
10
+ export declare const IDENTITY_REGISTRY_SERVICE_TIER: ServiceTier;
11
+ /** Contract version declared for the identity registry interface. */
12
+ export declare const IDENTITY_REGISTRY_CONTRACT_VERSION = "1.0.0";
13
+ /** Methods declared for the identity registry interface. */
14
+ export declare const IDENTITY_REGISTRY_CONTRACT_METHODS: readonly ["issue", "resolve", "retire", "revoke"];
15
+ /** Configuration for {@link createIdentityRegistryDescriptor}. */
16
+ export interface IdentityRegistryDescriptorOptions {
17
+ /**
18
+ * Absolute storage file path used instead of the context field.
19
+ *
20
+ * Intended for embedding the descriptor without a kernel context contract.
21
+ * The standard composition reads `identity.registry.path`.
22
+ */
23
+ readonly storagePath?: string;
24
+ /** Publishes the constructed instance for other service modules. */
25
+ readonly onConstruct?: (service: IdentityRegistryService) => void;
26
+ }
27
+ /**
28
+ * Builds the identity registry descriptor.
29
+ *
30
+ * The registry has no dependencies. It must be constructible before any
31
+ * boot-time issuer that wants to record a binding, and the boot issuer depends
32
+ * on {@link IdentityRegistryToken} so the registry's `initialize` runs first.
33
+ *
34
+ * @param options - Optional storage override and construction hook.
35
+ */
36
+ export declare function createIdentityRegistryDescriptor(options?: IdentityRegistryDescriptorOptions): ServiceDescriptor<IIdentityRegistry, IdentityRegistryService>;
@@ -0,0 +1,44 @@
1
+ import { requireContextString } from '../../../src/contracts/contextContract.js';
2
+ import { IdentityRegistryService } from '../orchestrator/IdentityRegistryService.js';
3
+ import { IdentityRegistryToken } from './tokens.js';
4
+ /** Namespace owned by the identity registry in the context contract. */
5
+ export const IDENTITY_REGISTRY_CONTEXT_SCOPE = 'identity';
6
+ /** Namespaced context field holding the absolute registry storage file path. */
7
+ export const IDENTITY_REGISTRY_PATH_CONTEXT_FIELD = 'identity.registry.path';
8
+ /** Tier assigned to the identity registry descriptor. */
9
+ export const IDENTITY_REGISTRY_SERVICE_TIER = 'core';
10
+ /** Contract version declared for the identity registry interface. */
11
+ export const IDENTITY_REGISTRY_CONTRACT_VERSION = '1.0.0';
12
+ /** Methods declared for the identity registry interface. */
13
+ export const IDENTITY_REGISTRY_CONTRACT_METHODS = [
14
+ 'issue',
15
+ 'resolve',
16
+ 'retire',
17
+ 'revoke',
18
+ ];
19
+ /**
20
+ * Builds the identity registry descriptor.
21
+ *
22
+ * The registry has no dependencies. It must be constructible before any
23
+ * boot-time issuer that wants to record a binding, and the boot issuer depends
24
+ * on {@link IdentityRegistryToken} so the registry's `initialize` runs first.
25
+ *
26
+ * @param options - Optional storage override and construction hook.
27
+ */
28
+ export function createIdentityRegistryDescriptor(options) {
29
+ return {
30
+ token: IdentityRegistryToken,
31
+ tier: IDENTITY_REGISTRY_SERVICE_TIER,
32
+ dependencies: [],
33
+ contract: {
34
+ version: IDENTITY_REGISTRY_CONTRACT_VERSION,
35
+ methods: IDENTITY_REGISTRY_CONTRACT_METHODS,
36
+ },
37
+ factory: (context) => {
38
+ const storagePath = options?.storagePath ?? requireContextString(context.options, IDENTITY_REGISTRY_PATH_CONTEXT_FIELD, IdentityRegistryToken.id);
39
+ const service = new IdentityRegistryService({ storagePath });
40
+ options?.onConstruct?.(service);
41
+ return service;
42
+ },
43
+ };
44
+ }
@@ -0,0 +1,8 @@
1
+ import type { IIdentityRegistry } from '../contracts/types.js';
2
+ /**
3
+ * Kernel service token for the identity registry.
4
+ *
5
+ * The identifier is stable and namespaced under the kernel's core tier. It is
6
+ * not an identity token; it resolves the registry service itself.
7
+ */
8
+ export declare const IdentityRegistryToken: import("../../../src/contracts/serviceToken.js").ServiceToken<IIdentityRegistry>;
@@ -0,0 +1,8 @@
1
+ import { createServiceToken } from '../../../src/contracts/serviceToken.js';
2
+ /**
3
+ * Kernel service token for the identity registry.
4
+ *
5
+ * The identifier is stable and namespaced under the kernel's core tier. It is
6
+ * not an identity token; it resolves the registry service itself.
7
+ */
8
+ export const IdentityRegistryToken = createServiceToken('brud.core.identityRegistry', 'Kernel-owned registry of issued participant identity tokens');
@@ -0,0 +1,11 @@
1
+ export type { IdentityBinding, IdentityRecord, IdentityState, IdentityToken, IIdentityRegistry, } from './contracts/types.js';
2
+ export { IDENTITY_STATES, isIdentityState } from './contracts/types.js';
3
+ export { IdentityRegistryCorruptError, IdentityRegistryError, IdentityRegistryFrozenError, IdentityRegistryInputError, IdentityRegistryMissingError, IdentityRegistryNotReadyError, IdentityRegistryPathError, IdentityRegistryRevokedError, IdentityRegistryStorageExistsError, IdentityRegistryUnknownTokenError, IdentityRegistryWriteError, } from './contracts/errors.js';
4
+ export type { IdentityRegistryErrorCode } from './contracts/errors.js';
5
+ export { IDENTITY_REGISTRY_CONTEXT_SCOPE, IDENTITY_REGISTRY_CONTRACT_METHODS, IDENTITY_REGISTRY_CONTRACT_VERSION, IDENTITY_REGISTRY_PATH_CONTEXT_FIELD, IDENTITY_REGISTRY_SERVICE_TIER, createIdentityRegistryDescriptor, } from './descriptor/descriptor.js';
6
+ export type { IdentityRegistryDescriptorOptions } from './descriptor/descriptor.js';
7
+ export { IdentityRegistryToken } from './descriptor/tokens.js';
8
+ export { IdentityRegistryService, } from './orchestrator/IdentityRegistryService.js';
9
+ export type { IdentityRegistryServiceOptions } from './orchestrator/IdentityRegistryService.js';
10
+ export { IDENTITY_REGISTRY_FORMAT, IDENTITY_REGISTRY_MAX_METADATA_BYTES, IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH, IDENTITY_REGISTRY_VERSION, loadIdentityRegistryStorage, parseIdentityRegistryDocument, persistIdentityRegistryStorage, provisionIdentityRegistryStorage, serializeIdentityRegistryDocument, } from './storage/registryDocument.js';
11
+ export type { LoadedIdentityRegistry } from './storage/registryDocument.js';
@@ -0,0 +1,6 @@
1
+ export { IDENTITY_STATES, isIdentityState } from './contracts/types.js';
2
+ export { IdentityRegistryCorruptError, IdentityRegistryError, IdentityRegistryFrozenError, IdentityRegistryInputError, IdentityRegistryMissingError, IdentityRegistryNotReadyError, IdentityRegistryPathError, IdentityRegistryRevokedError, IdentityRegistryStorageExistsError, IdentityRegistryUnknownTokenError, IdentityRegistryWriteError, } from './contracts/errors.js';
3
+ export { IDENTITY_REGISTRY_CONTEXT_SCOPE, IDENTITY_REGISTRY_CONTRACT_METHODS, IDENTITY_REGISTRY_CONTRACT_VERSION, IDENTITY_REGISTRY_PATH_CONTEXT_FIELD, IDENTITY_REGISTRY_SERVICE_TIER, createIdentityRegistryDescriptor, } from './descriptor/descriptor.js';
4
+ export { IdentityRegistryToken } from './descriptor/tokens.js';
5
+ export { IdentityRegistryService, } from './orchestrator/IdentityRegistryService.js';
6
+ export { IDENTITY_REGISTRY_FORMAT, IDENTITY_REGISTRY_MAX_METADATA_BYTES, IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH, IDENTITY_REGISTRY_VERSION, loadIdentityRegistryStorage, parseIdentityRegistryDocument, persistIdentityRegistryStorage, provisionIdentityRegistryStorage, serializeIdentityRegistryDocument, } from './storage/registryDocument.js';
@@ -0,0 +1,47 @@
1
+ import type { IServiceLifecycle } from '../../../src/contracts/lifecycle.js';
2
+ import type { IdentityBinding, IdentityRecord, IdentityToken, IIdentityRegistry } from '../contracts/types.js';
3
+ /** Construction options for {@link IdentityRegistryService}. */
4
+ export interface IdentityRegistryServiceOptions {
5
+ /** Absolute path to the operator-provisioned registry file. */
6
+ readonly storagePath: string;
7
+ }
8
+ /**
9
+ * Kernel-owned identity registry service.
10
+ *
11
+ * The registry records opaque bindings, issues one stable token per binding,
12
+ * and is writable only during boot. `initialize` loads and integrity-checks
13
+ * the operator-provisioned document and protects it with the same guard class
14
+ * as the root config. `onRunning` freezes the service first, then persists the
15
+ * final document atomically and re-protects it.
16
+ */
17
+ export declare class IdentityRegistryService implements IIdentityRegistry, IServiceLifecycle {
18
+ #private;
19
+ constructor(options: IdentityRegistryServiceOptions);
20
+ /**
21
+ * Loads and integrity-checks the registry, then protects the file.
22
+ *
23
+ * A missing or corrupt document fails here; the registry never regenerates
24
+ * an existing storage location.
25
+ */
26
+ initialize(): void;
27
+ /** {@inheritDoc IIdentityRegistry.issue} */
28
+ issue(binding: IdentityBinding): IdentityRecord;
29
+ /** {@inheritDoc IIdentityRegistry.resolve} */
30
+ resolve(token: IdentityToken): IdentityRecord | null;
31
+ /** {@inheritDoc IIdentityRegistry.retire} */
32
+ retire(token: IdentityToken): IdentityRecord;
33
+ /** {@inheritDoc IIdentityRegistry.revoke} */
34
+ revoke(token: IdentityToken): IdentityRecord;
35
+ /**
36
+ * Freezes the registry and persists the final document.
37
+ *
38
+ * Freezing happens first so no mutation can occur while the write is in
39
+ * flight. The write releases the protected-path guard only for a synchronous
40
+ * atomic write/verify/re-protect block.
41
+ */
42
+ onRunning(): void;
43
+ /** Releases the protected-path claim held for this kernel. */
44
+ dispose(): void;
45
+ /** Returns the protected storage path. */
46
+ get storagePath(): string;
47
+ }
@@ -0,0 +1,240 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { resolve as resolvePath } from 'node:path';
3
+ import { protectConfigFile, releaseConfigProtection, } from '../../../src/bootstrap/config/integrity.js';
4
+ import { IdentityRegistryFrozenError, IdentityRegistryInputError, IdentityRegistryNotReadyError, IdentityRegistryRevokedError, IdentityRegistryUnknownTokenError, } from '../contracts/errors.js';
5
+ import { JsonValueError, canonicalJson, cloneJsonRecord, isPlainRecord, } from '../../shared/canonicalJson.js';
6
+ import { IDENTITY_REGISTRY_MAX_METADATA_BYTES, IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH, identityBindingKey, loadIdentityRegistryStorage, persistIdentityRegistryStorage, } from '../storage/registryDocument.js';
7
+ /** Validates an opaque string without interpreting it. */
8
+ function requireOpaqueString(value, field) {
9
+ if (typeof value !== 'string' || value.length === 0) {
10
+ throw new IdentityRegistryInputError(field, 'must be a non-empty string');
11
+ }
12
+ if (value.length > IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH) {
13
+ throw new IdentityRegistryInputError(field, `must be at most ${String(IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH)} characters`);
14
+ }
15
+ return value;
16
+ }
17
+ /** Validates and clones opaque JSON metadata. */
18
+ function requireMetadata(value) {
19
+ try {
20
+ const metadata = cloneJsonRecord(value);
21
+ if (Buffer.byteLength(canonicalJson(metadata), 'utf8')
22
+ > IDENTITY_REGISTRY_MAX_METADATA_BYTES) {
23
+ throw new IdentityRegistryInputError('metadata', `must be at most ${String(IDENTITY_REGISTRY_MAX_METADATA_BYTES)} canonical bytes`);
24
+ }
25
+ return metadata;
26
+ }
27
+ catch (error) {
28
+ if (error instanceof IdentityRegistryInputError) {
29
+ throw error;
30
+ }
31
+ const reason = error instanceof JsonValueError
32
+ ? error.message
33
+ : 'must be a JSON object';
34
+ throw new IdentityRegistryInputError('metadata', reason);
35
+ }
36
+ }
37
+ /** Returns an immutable copy of one record. */
38
+ function snapshot(record) {
39
+ return Object.freeze({
40
+ token: record.token,
41
+ publisher: record.publisher,
42
+ contentHash: record.contentHash,
43
+ metadata: record.metadata,
44
+ state: record.state,
45
+ });
46
+ }
47
+ /**
48
+ * Kernel-owned identity registry service.
49
+ *
50
+ * The registry records opaque bindings, issues one stable token per binding,
51
+ * and is writable only during boot. `initialize` loads and integrity-checks
52
+ * the operator-provisioned document and protects it with the same guard class
53
+ * as the root config. `onRunning` freezes the service first, then persists the
54
+ * final document atomically and re-protects it.
55
+ */
56
+ export class IdentityRegistryService {
57
+ #storagePath;
58
+ #byToken = new Map();
59
+ #byBinding = new Map();
60
+ #registryId = '';
61
+ #initialized = false;
62
+ #frozen = false;
63
+ #dirty = false;
64
+ #protected = false;
65
+ constructor(options) {
66
+ this.#storagePath = resolvePath(options.storagePath);
67
+ }
68
+ /**
69
+ * Loads and integrity-checks the registry, then protects the file.
70
+ *
71
+ * A missing or corrupt document fails here; the registry never regenerates
72
+ * an existing storage location.
73
+ */
74
+ initialize() {
75
+ if (this.#initialized) {
76
+ return;
77
+ }
78
+ const loaded = loadIdentityRegistryStorage(this.#storagePath);
79
+ for (const record of loaded.records) {
80
+ const mutable = {
81
+ token: record.token,
82
+ publisher: record.publisher,
83
+ contentHash: record.contentHash,
84
+ metadata: record.metadata,
85
+ state: record.state,
86
+ };
87
+ this.#byToken.set(record.token, mutable);
88
+ this.#byBinding.set(identityBindingKey(record.publisher, record.contentHash), mutable);
89
+ }
90
+ this.#registryId = loaded.registryId;
91
+ protectConfigFile(this.#storagePath);
92
+ this.#protected = true;
93
+ this.#initialized = true;
94
+ }
95
+ /** {@inheritDoc IIdentityRegistry.issue} */
96
+ issue(binding) {
97
+ this.#assertMutable('issue');
98
+ const candidate = binding;
99
+ if (!isPlainRecord(candidate)) {
100
+ throw new IdentityRegistryInputError('binding', 'must be an object');
101
+ }
102
+ const publisher = requireOpaqueString(candidate.publisher, 'publisher');
103
+ const contentHash = requireOpaqueString(candidate.contentHash, 'contentHash');
104
+ const metadata = requireMetadata(candidate.metadata);
105
+ const key = identityBindingKey(publisher, contentHash);
106
+ const existing = this.#byBinding.get(key);
107
+ if (existing !== undefined) {
108
+ if (existing.state === 'revoked') {
109
+ throw new IdentityRegistryRevokedError(existing.token);
110
+ }
111
+ existing.metadata = metadata;
112
+ existing.state = 'active';
113
+ this.#dirty = true;
114
+ return snapshot(existing);
115
+ }
116
+ const record = this.#createRecord(publisher, contentHash, metadata);
117
+ this.#byToken.set(record.token, record);
118
+ this.#byBinding.set(key, record);
119
+ this.#dirty = true;
120
+ return snapshot(record);
121
+ }
122
+ /** {@inheritDoc IIdentityRegistry.resolve} */
123
+ resolve(token) {
124
+ if (typeof token !== 'string') {
125
+ return null;
126
+ }
127
+ const record = this.#byToken.get(token);
128
+ return record === undefined ? null : snapshot(record);
129
+ }
130
+ /** {@inheritDoc IIdentityRegistry.retire} */
131
+ retire(token) {
132
+ this.#assertMutable('retire');
133
+ const record = this.#requireRecord(token);
134
+ if (record.state === 'revoked') {
135
+ throw new IdentityRegistryRevokedError(token);
136
+ }
137
+ if (record.state === 'retired') {
138
+ return snapshot(record);
139
+ }
140
+ record.state = 'retired';
141
+ this.#dirty = true;
142
+ return snapshot(record);
143
+ }
144
+ /** {@inheritDoc IIdentityRegistry.revoke} */
145
+ revoke(token) {
146
+ this.#assertMutable('revoke');
147
+ const record = this.#requireRecord(token);
148
+ if (record.state === 'revoked') {
149
+ return snapshot(record);
150
+ }
151
+ record.state = 'revoked';
152
+ this.#dirty = true;
153
+ return snapshot(record);
154
+ }
155
+ /**
156
+ * Freezes the registry and persists the final document.
157
+ *
158
+ * Freezing happens first so no mutation can occur while the write is in
159
+ * flight. The write releases the protected-path guard only for a synchronous
160
+ * atomic write/verify/re-protect block.
161
+ */
162
+ onRunning() {
163
+ if (!this.#initialized) {
164
+ throw new IdentityRegistryNotReadyError('freeze');
165
+ }
166
+ this.#frozen = true;
167
+ if (!this.#dirty) {
168
+ return;
169
+ }
170
+ this.#persist();
171
+ this.#dirty = false;
172
+ }
173
+ /** Releases the protected-path claim held for this kernel. */
174
+ dispose() {
175
+ if (this.#protected) {
176
+ releaseConfigProtection(this.#storagePath);
177
+ this.#protected = false;
178
+ }
179
+ }
180
+ /** Returns the protected storage path. */
181
+ get storagePath() {
182
+ return this.#storagePath;
183
+ }
184
+ /** Creates a new opaque token that is not already recorded. */
185
+ #createRecord(publisher, contentHash, metadata) {
186
+ for (;;) {
187
+ const token = `idt_${randomBytes(32).toString('base64url')}`;
188
+ if (!this.#byToken.has(token)) {
189
+ return {
190
+ token,
191
+ publisher,
192
+ contentHash,
193
+ metadata,
194
+ state: 'active',
195
+ };
196
+ }
197
+ }
198
+ }
199
+ /** Persists the exact in-memory state and verifies the written file. */
200
+ #persist() {
201
+ const records = [...this.#byToken.values()].map(snapshot);
202
+ const wasProtected = this.#protected;
203
+ if (wasProtected) {
204
+ releaseConfigProtection(this.#storagePath);
205
+ this.#protected = false;
206
+ }
207
+ try {
208
+ persistIdentityRegistryStorage(this.#storagePath, this.#registryId, records);
209
+ // Read the document back so the file that will be trusted on the next
210
+ // boot is the file that was integrity-checked in this one.
211
+ loadIdentityRegistryStorage(this.#storagePath);
212
+ }
213
+ finally {
214
+ if (wasProtected) {
215
+ protectConfigFile(this.#storagePath);
216
+ this.#protected = true;
217
+ }
218
+ }
219
+ }
220
+ /** Refuses mutation before load and after freeze. */
221
+ #assertMutable(operation) {
222
+ if (!this.#initialized) {
223
+ throw new IdentityRegistryNotReadyError(operation);
224
+ }
225
+ if (this.#frozen) {
226
+ throw new IdentityRegistryFrozenError(operation);
227
+ }
228
+ }
229
+ /** Resolves a required record for a mutating operation. */
230
+ #requireRecord(token) {
231
+ if (typeof token !== 'string' || token.length === 0) {
232
+ throw new IdentityRegistryUnknownTokenError(String(token));
233
+ }
234
+ const record = this.#byToken.get(token);
235
+ if (record === undefined) {
236
+ throw new IdentityRegistryUnknownTokenError(token);
237
+ }
238
+ return record;
239
+ }
240
+ }
@@ -0,0 +1,10 @@
1
+ import type { KernelServiceModuleContext } from '../../src/bootstrap/bootTypes.js';
2
+ /** Shared-bag slot where the identity registry publishes its instance. */
3
+ export declare const IDENTITY_REGISTRY_SLOT = "brud.core.identityRegistry.instance";
4
+ /**
5
+ * Composes the identity registry through the standard service-module contract.
6
+ *
7
+ * The module declares its own namespaced storage field and publishes the
8
+ * instance for boot-time issuers. It does not read the kernel config.
9
+ */
10
+ export declare function createService(context: KernelServiceModuleContext): import("../../index.js").ServiceDescriptor<import("./index.js").IIdentityRegistry, import("./index.js").IdentityRegistryService>;
@@ -0,0 +1,24 @@
1
+ import { IDENTITY_REGISTRY_CONTEXT_SCOPE, IDENTITY_REGISTRY_PATH_CONTEXT_FIELD, createIdentityRegistryDescriptor, } from './descriptor/descriptor.js';
2
+ /** Shared-bag slot where the identity registry publishes its instance. */
3
+ export const IDENTITY_REGISTRY_SLOT = 'brud.core.identityRegistry.instance';
4
+ /**
5
+ * Composes the identity registry through the standard service-module contract.
6
+ *
7
+ * The module declares its own namespaced storage field and publishes the
8
+ * instance for boot-time issuers. It does not read the kernel config.
9
+ */
10
+ export function createService(context) {
11
+ context.declareContextFields(IDENTITY_REGISTRY_CONTEXT_SCOPE, [
12
+ {
13
+ name: IDENTITY_REGISTRY_PATH_CONTEXT_FIELD,
14
+ type: 'string',
15
+ required: true,
16
+ description: 'Absolute path to the operator-provisioned identity registry file.',
17
+ },
18
+ ]);
19
+ return createIdentityRegistryDescriptor({
20
+ onConstruct: (service) => {
21
+ context.shared[IDENTITY_REGISTRY_SLOT] = service;
22
+ },
23
+ });
24
+ }
@@ -0,0 +1,55 @@
1
+ import { type IdentityRecord } from '../contracts/types.js';
2
+ /** Stable format marker for the registry document. */
3
+ export declare const IDENTITY_REGISTRY_FORMAT = "brud.identity-registry";
4
+ /** Format version the service understands. */
5
+ export declare const IDENTITY_REGISTRY_VERSION = 1;
6
+ /** Maximum accepted length for an opaque publisher or content hash. */
7
+ export declare const IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH = 8192;
8
+ /** Maximum accepted canonical metadata size in bytes. */
9
+ export declare const IDENTITY_REGISTRY_MAX_METADATA_BYTES = 65536;
10
+ /** Result of loading and validating a registry document. */
11
+ export interface LoadedIdentityRegistry {
12
+ /** Registry instance identifier recorded at provisioning. */
13
+ readonly registryId: string;
14
+ /** Validated records in document order. */
15
+ readonly records: readonly IdentityRecord[];
16
+ }
17
+ /** Rejects a storage path that is not an absolute file path. */
18
+ export declare function assertIdentityRegistryStoragePath(storagePath: string): string;
19
+ /** Builds the deterministic lookup key for one binding. */
20
+ export declare function identityBindingKey(publisher: string, contentHash: string): string;
21
+ /**
22
+ * Parses and integrity-checks a registry document.
23
+ *
24
+ * @param raw - Exact file contents.
25
+ * @param storagePath - Absolute path used in diagnostics.
26
+ */
27
+ export declare function parseIdentityRegistryDocument(raw: string, storagePath: string): LoadedIdentityRegistry;
28
+ /**
29
+ * Serializes a registry document with a fresh integrity digest.
30
+ *
31
+ * @param registryId - Registry instance identifier.
32
+ * @param records - Current records.
33
+ */
34
+ export declare function serializeIdentityRegistryDocument(registryId: string, records: readonly IdentityRecord[]): string;
35
+ /**
36
+ * Loads and validates a registry file.
37
+ *
38
+ * @param storagePath - Absolute registry file path.
39
+ */
40
+ export declare function loadIdentityRegistryStorage(storagePath: string): LoadedIdentityRegistry;
41
+ /**
42
+ * Persists a registry file atomically.
43
+ *
44
+ * @param storagePath - Absolute registry file path.
45
+ * @param registryId - Registry instance identifier.
46
+ * @param records - Current records.
47
+ */
48
+ export declare function persistIdentityRegistryStorage(storagePath: string, registryId: string, records: readonly IdentityRecord[]): void;
49
+ /**
50
+ * Operator provisioning: creates a valid empty registry while the kernel is
51
+ * stopped. Refuses to overwrite an existing registry.
52
+ *
53
+ * @param storagePath - Absolute registry file path.
54
+ */
55
+ export declare function provisionIdentityRegistryStorage(storagePath: string): void;