@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.
- package/LICENSE +201 -0
- package/README.md +63 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/serviceModules/events.d.ts +1 -0
- package/dist/serviceModules/events.js +1 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
- package/dist/serviceModules/exposedApiRegistry.js +1 -0
- package/dist/serviceModules/identityRegistry.d.ts +1 -0
- package/dist/serviceModules/identityRegistry.js +1 -0
- package/dist/serviceModules/interception.d.ts +1 -0
- package/dist/serviceModules/interception.js +1 -0
- package/dist/serviceModules/parser.d.ts +1 -0
- package/dist/serviceModules/parser.js +1 -0
- package/dist/serviceModules/router.d.ts +1 -0
- package/dist/serviceModules/router.js +1 -0
- package/dist/serviceModules/wasmCage.d.ts +1 -0
- package/dist/serviceModules/wasmCage.js +1 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
- package/dist/services/Events/contracts/IEventsService.js +1 -0
- package/dist/services/Events/contracts/errors.d.ts +31 -0
- package/dist/services/Events/contracts/errors.js +40 -0
- package/dist/services/Events/contracts/index.d.ts +3 -0
- package/dist/services/Events/contracts/index.js +3 -0
- package/dist/services/Events/contracts/tokens.d.ts +2 -0
- package/dist/services/Events/contracts/tokens.js +2 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
- package/dist/services/Events/descriptor/tokens.d.ts +1 -0
- package/dist/services/Events/descriptor/tokens.js +1 -0
- package/dist/services/Events/index.d.ts +4 -0
- package/dist/services/Events/index.js +4 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
- package/dist/services/Events/orchestrator/EventsService.js +339 -0
- package/dist/services/Events/orchestrator/index.d.ts +2 -0
- package/dist/services/Events/orchestrator/index.js +2 -0
- package/dist/services/Events/orchestrator/limits.d.ts +22 -0
- package/dist/services/Events/orchestrator/limits.js +33 -0
- package/dist/services/Events/serviceModule.d.ts +2 -0
- package/dist/services/Events/serviceModule.js +5 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
- package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +112 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
- package/dist/services/ExposedApiRegistry/index.js +5 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +61 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
- package/dist/services/IdentityRegistry/contracts/index.js +3 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
- package/dist/services/IdentityRegistry/contracts/types.js +18 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
- package/dist/services/IdentityRegistry/index.d.ts +11 -0
- package/dist/services/IdentityRegistry/index.js +6 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
- package/dist/services/IdentityRegistry/serviceModule.js +24 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +65 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +1 -0
- package/dist/services/Interception/contracts/errors.d.ts +26 -0
- package/dist/services/Interception/contracts/errors.js +35 -0
- package/dist/services/Interception/contracts/index.d.ts +3 -0
- package/dist/services/Interception/contracts/index.js +3 -0
- package/dist/services/Interception/contracts/tokens.d.ts +2 -0
- package/dist/services/Interception/contracts/tokens.js +2 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +49 -0
- package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
- package/dist/services/Interception/descriptor/tokens.js +1 -0
- package/dist/services/Interception/index.d.ts +4 -0
- package/dist/services/Interception/index.js +4 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +32 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +180 -0
- package/dist/services/Interception/orchestrator/index.d.ts +1 -0
- package/dist/services/Interception/orchestrator/index.js +1 -0
- package/dist/services/Interception/serviceModule.d.ts +2 -0
- package/dist/services/Interception/serviceModule.js +5 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
- package/dist/services/Parser/contracts/IParserService.js +1 -0
- package/dist/services/Parser/contracts/errors.d.ts +25 -0
- package/dist/services/Parser/contracts/errors.js +33 -0
- package/dist/services/Parser/contracts/index.d.ts +4 -0
- package/dist/services/Parser/contracts/index.js +1 -0
- package/dist/services/Parser/contracts/types.d.ts +42 -0
- package/dist/services/Parser/contracts/types.js +1 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
- package/dist/services/Parser/descriptor/tokens.js +8 -0
- package/dist/services/Parser/index.d.ts +8 -0
- package/dist/services/Parser/index.js +8 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
- package/dist/services/Parser/orchestrator/ParserService.js +105 -0
- package/dist/services/Parser/orchestrator/index.d.ts +1 -0
- package/dist/services/Parser/orchestrator/index.js +1 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
- package/dist/services/Parser/parser/indexSynthesis.js +13 -0
- package/dist/services/Parser/parser/parameters.d.ts +14 -0
- package/dist/services/Parser/parser/parameters.js +89 -0
- package/dist/services/Parser/parser/scanner.d.ts +48 -0
- package/dist/services/Parser/parser/scanner.js +156 -0
- package/dist/services/Parser/parser/syntax.d.ts +30 -0
- package/dist/services/Parser/parser/syntax.js +34 -0
- package/dist/services/Parser/serviceModule.d.ts +2 -0
- package/dist/services/Parser/serviceModule.js +5 -0
- package/dist/services/Router/bootOptions.d.ts +2 -0
- package/dist/services/Router/bootOptions.js +2 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
- package/dist/services/Router/contracts/IRouterService.js +1 -0
- package/dist/services/Router/contracts/caller.d.ts +6 -0
- package/dist/services/Router/contracts/caller.js +6 -0
- package/dist/services/Router/contracts/errors.d.ts +56 -0
- package/dist/services/Router/contracts/errors.js +75 -0
- package/dist/services/Router/contracts/index.d.ts +8 -0
- package/dist/services/Router/contracts/index.js +4 -0
- package/dist/services/Router/contracts/kind.d.ts +7 -0
- package/dist/services/Router/contracts/kind.js +10 -0
- package/dist/services/Router/contracts/registrant.d.ts +23 -0
- package/dist/services/Router/contracts/registrant.js +13 -0
- package/dist/services/Router/contracts/types.d.ts +90 -0
- package/dist/services/Router/contracts/types.js +1 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
- package/dist/services/Router/descriptor/tokens.d.ts +9 -0
- package/dist/services/Router/descriptor/tokens.js +9 -0
- package/dist/services/Router/index.d.ts +4 -0
- package/dist/services/Router/index.js +4 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +74 -0
- package/dist/services/Router/orchestrator/RouterService.js +332 -0
- package/dist/services/Router/orchestrator/index.d.ts +2 -0
- package/dist/services/Router/orchestrator/index.js +1 -0
- package/dist/services/Router/serviceModule.d.ts +4 -0
- package/dist/services/Router/serviceModule.js +22 -0
- package/dist/services/WasmCage/index.d.ts +7 -0
- package/dist/services/WasmCage/index.js +4 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
- package/dist/services/WasmCage/scripts/prepin.js +38 -0
- package/dist/services/WasmCage/serviceModule.d.ts +12 -0
- package/dist/services/WasmCage/serviceModule.js +18 -0
- package/dist/services/WasmCage/src/caged.d.ts +104 -0
- package/dist/services/WasmCage/src/caged.js +381 -0
- package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
- package/dist/services/WasmCage/src/descriptor.js +56 -0
- package/dist/services/WasmCage/src/native.d.ts +29 -0
- package/dist/services/WasmCage/src/native.js +66 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
- package/dist/services/WasmCage/src/nativeDigests.js +15 -0
- package/dist/services/WasmCage/src/package.d.ts +36 -0
- package/dist/services/WasmCage/src/package.js +122 -0
- package/dist/services/shared/canonicalJson.d.ts +29 -0
- package/dist/services/shared/canonicalJson.js +93 -0
- package/dist/services/shared/documentStore.d.ts +16 -0
- package/dist/services/shared/documentStore.js +98 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +18 -0
- package/dist/src/bootstrap/bootKernelInternal.js +420 -0
- package/dist/src/bootstrap/bootTypes.d.ts +89 -0
- package/dist/src/bootstrap/bootTypes.js +1 -0
- package/dist/src/bootstrap/config/index.d.ts +3 -0
- package/dist/src/bootstrap/config/index.js +2 -0
- package/dist/src/bootstrap/config/integrity.d.ts +34 -0
- package/dist/src/bootstrap/config/integrity.js +79 -0
- package/dist/src/bootstrap/config/parse.d.ts +15 -0
- package/dist/src/bootstrap/config/parse.js +81 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
- package/dist/src/bootstrap/config/types.d.ts +41 -0
- package/dist/src/bootstrap/config/types.js +15 -0
- package/dist/src/bootstrap/hardcore.d.ts +212 -0
- package/dist/src/bootstrap/hardcore.js +312 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
- package/dist/src/bootstrap/hardcoreServices.js +258 -0
- package/dist/src/bootstrap/index.d.ts +8 -0
- package/dist/src/bootstrap/index.js +5 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/contracts/accessBroker.d.ts +53 -0
- package/dist/src/contracts/accessBroker.js +1 -0
- package/dist/src/contracts/brudOperation.d.ts +20 -0
- package/dist/src/contracts/brudOperation.js +20 -0
- package/dist/src/contracts/callChain.d.ts +161 -0
- package/dist/src/contracts/callChain.js +19 -0
- package/dist/src/contracts/capability.d.ts +26 -0
- package/dist/src/contracts/capability.js +26 -0
- package/dist/src/contracts/container.d.ts +17 -0
- package/dist/src/contracts/container.js +8 -0
- package/dist/src/contracts/context.d.ts +19 -0
- package/dist/src/contracts/context.js +1 -0
- package/dist/src/contracts/contextContract.d.ts +129 -0
- package/dist/src/contracts/contextContract.js +285 -0
- package/dist/src/contracts/dispatchView.d.ts +21 -0
- package/dist/src/contracts/dispatchView.js +1 -0
- package/dist/src/contracts/handler.d.ts +28 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +25 -0
- package/dist/src/contracts/index.js +8 -0
- package/dist/src/contracts/kernel.d.ts +60 -0
- package/dist/src/contracts/kernel.js +1 -0
- package/dist/src/contracts/lifecycle.d.ts +59 -0
- package/dist/src/contracts/lifecycle.js +1 -0
- package/dist/src/contracts/manifest.d.ts +145 -0
- package/dist/src/contracts/manifest.js +295 -0
- package/dist/src/contracts/pipeline.d.ts +8 -0
- package/dist/src/contracts/pipeline.js +1 -0
- package/dist/src/contracts/policy.d.ts +75 -0
- package/dist/src/contracts/policy.js +77 -0
- package/dist/src/contracts/registry.d.ts +7 -0
- package/dist/src/contracts/registry.js +1 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
- package/dist/src/contracts/serviceDescriptor.js +1 -0
- package/dist/src/contracts/serviceToken.d.ts +36 -0
- package/dist/src/contracts/serviceToken.js +16 -0
- package/dist/src/engine/BrudKernel.d.ts +118 -0
- package/dist/src/engine/BrudKernel.js +366 -0
- package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
- package/dist/src/engine/ExecutionPipeline.js +62 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
- package/dist/src/engine/KernelAccessBroker.js +107 -0
- package/dist/src/engine/KernelRegistry.d.ts +14 -0
- package/dist/src/engine/KernelRegistry.js +33 -0
- package/dist/src/engine/OperationRegistry.d.ts +9 -0
- package/dist/src/engine/OperationRegistry.js +18 -0
- package/dist/src/engine/ServiceContainer.d.ts +13 -0
- package/dist/src/engine/ServiceContainer.js +53 -0
- package/dist/src/engine/callChain.d.ts +68 -0
- package/dist/src/engine/callChain.js +180 -0
- package/dist/src/engine/dag.d.ts +2 -0
- package/dist/src/engine/dag.js +34 -0
- package/dist/src/engine/errors.d.ts +26 -0
- package/dist/src/engine/errors.js +52 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.js +8 -0
- package/dist/src/engine/state.d.ts +1 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
- package/dist/src/validation/jsonSchema/compile.js +386 -0
- package/dist/src/validation/jsonSchema/index.d.ts +3 -0
- package/dist/src/validation/jsonSchema/index.js +2 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
- package/dist/src/validation/jsonSchema/pattern.js +155 -0
- package/dist/src/validation/jsonSchema/types.d.ts +71 -0
- package/dist/src/validation/jsonSchema/types.js +15 -0
- package/package.json +59 -4
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { IdentityRegistryCorruptError, IdentityRegistryMissingError, IdentityRegistryPathError, IdentityRegistryStorageExistsError, IdentityRegistryWriteError, } from '../contracts/errors.js';
|
|
4
|
+
import { isIdentityState, } from '../contracts/types.js';
|
|
5
|
+
import { JsonValueError, canonicalJson, cloneJsonRecord, isPlainRecord, } from '../../shared/canonicalJson.js';
|
|
6
|
+
import { assertExactKeys, canonicalDigest, digestsEqual, resolveAbsoluteStoragePath, writeAtomically, } from '../../shared/documentStore.js';
|
|
7
|
+
/** Stable format marker for the registry document. */
|
|
8
|
+
export const IDENTITY_REGISTRY_FORMAT = 'brud.identity-registry';
|
|
9
|
+
/** Format version the service understands. */
|
|
10
|
+
export const IDENTITY_REGISTRY_VERSION = 1;
|
|
11
|
+
/** Maximum accepted length for an opaque publisher or content hash. */
|
|
12
|
+
export const IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH = 8_192;
|
|
13
|
+
/** Maximum accepted canonical metadata size in bytes. */
|
|
14
|
+
export const IDENTITY_REGISTRY_MAX_METADATA_BYTES = 65_536;
|
|
15
|
+
const DIGEST_ALGORITHM = 'sha256';
|
|
16
|
+
const TOKEN_PATTERN = /^idt_[A-Za-z0-9_-]{43}$/u;
|
|
17
|
+
const DIGEST_PATTERN = /^[0-9a-f]{64}$/u;
|
|
18
|
+
const ROOT_KEYS = new Set(['format', 'version', 'registryId', 'records', 'integrity']);
|
|
19
|
+
const INTEGRITY_KEYS = new Set(['algorithm', 'digest']);
|
|
20
|
+
const RECORD_KEYS = new Set(['token', 'publisher', 'contentHash', 'metadata', 'state']);
|
|
21
|
+
/** Reports whether a value is a non-empty string. */
|
|
22
|
+
function isNonEmptyString(value) {
|
|
23
|
+
return typeof value === 'string' && value.length > 0;
|
|
24
|
+
}
|
|
25
|
+
/** Raises a corrupt-storage failure. */
|
|
26
|
+
function corrupt(storagePath, reason) {
|
|
27
|
+
throw new IdentityRegistryCorruptError(storagePath, reason);
|
|
28
|
+
}
|
|
29
|
+
/** Rejects a storage path that is not an absolute file path. */
|
|
30
|
+
export function assertIdentityRegistryStoragePath(storagePath) {
|
|
31
|
+
return resolveAbsoluteStoragePath(storagePath, (path) => {
|
|
32
|
+
throw new IdentityRegistryPathError(path);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Builds the deterministic lookup key for one binding. */
|
|
36
|
+
export function identityBindingKey(publisher, contentHash) {
|
|
37
|
+
return canonicalJson([publisher, contentHash]);
|
|
38
|
+
}
|
|
39
|
+
/** Validates one record and returns a frozen copy. */
|
|
40
|
+
function parseRecord(value, index, storagePath) {
|
|
41
|
+
if (!isPlainRecord(value)) {
|
|
42
|
+
corrupt(storagePath, `records[${String(index)}] is not an object`);
|
|
43
|
+
}
|
|
44
|
+
assertExactKeys(value, RECORD_KEYS, storagePath, `records[${String(index)}]`, corrupt);
|
|
45
|
+
const token = value.token;
|
|
46
|
+
if (!isNonEmptyString(token) || !TOKEN_PATTERN.test(token)) {
|
|
47
|
+
corrupt(storagePath, `records[${String(index)}].token is not a registry token`);
|
|
48
|
+
}
|
|
49
|
+
const publisher = value.publisher;
|
|
50
|
+
if (!isNonEmptyString(publisher)
|
|
51
|
+
|| publisher.length > IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH) {
|
|
52
|
+
corrupt(storagePath, `records[${String(index)}].publisher is invalid`);
|
|
53
|
+
}
|
|
54
|
+
const contentHash = value.contentHash;
|
|
55
|
+
if (!isNonEmptyString(contentHash)
|
|
56
|
+
|| contentHash.length > IDENTITY_REGISTRY_MAX_OPAQUE_LENGTH) {
|
|
57
|
+
corrupt(storagePath, `records[${String(index)}].contentHash is invalid`);
|
|
58
|
+
}
|
|
59
|
+
const state = value.state;
|
|
60
|
+
if (!isIdentityState(state)) {
|
|
61
|
+
corrupt(storagePath, `records[${String(index)}].state is not a supported state`);
|
|
62
|
+
}
|
|
63
|
+
let metadata;
|
|
64
|
+
try {
|
|
65
|
+
metadata = cloneJsonRecord(value.metadata);
|
|
66
|
+
if (Buffer.byteLength(canonicalJson(metadata), 'utf8') > IDENTITY_REGISTRY_MAX_METADATA_BYTES) {
|
|
67
|
+
corrupt(storagePath, `records[${String(index)}].metadata exceeds the size limit`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error instanceof IdentityRegistryCorruptError) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
const reason = error instanceof JsonValueError
|
|
75
|
+
? error.message
|
|
76
|
+
: 'metadata is not JSON';
|
|
77
|
+
corrupt(storagePath, `records[${String(index)}].metadata is invalid: ${reason}`);
|
|
78
|
+
}
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
token,
|
|
81
|
+
publisher,
|
|
82
|
+
contentHash,
|
|
83
|
+
metadata,
|
|
84
|
+
state: state,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parses and integrity-checks a registry document.
|
|
89
|
+
*
|
|
90
|
+
* @param raw - Exact file contents.
|
|
91
|
+
* @param storagePath - Absolute path used in diagnostics.
|
|
92
|
+
*/
|
|
93
|
+
export function parseIdentityRegistryDocument(raw, storagePath) {
|
|
94
|
+
let document;
|
|
95
|
+
try {
|
|
96
|
+
document = JSON.parse(raw);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
corrupt(storagePath, 'document is not valid JSON');
|
|
100
|
+
}
|
|
101
|
+
if (!isPlainRecord(document)) {
|
|
102
|
+
corrupt(storagePath, 'document root is not an object');
|
|
103
|
+
}
|
|
104
|
+
assertExactKeys(document, ROOT_KEYS, storagePath, 'document', corrupt);
|
|
105
|
+
if (document.format !== IDENTITY_REGISTRY_FORMAT) {
|
|
106
|
+
corrupt(storagePath, 'document format marker is not supported');
|
|
107
|
+
}
|
|
108
|
+
if (document.version !== IDENTITY_REGISTRY_VERSION) {
|
|
109
|
+
corrupt(storagePath, 'document version is not supported');
|
|
110
|
+
}
|
|
111
|
+
const registryId = document.registryId;
|
|
112
|
+
if (!isNonEmptyString(registryId)) {
|
|
113
|
+
corrupt(storagePath, 'registryId is invalid');
|
|
114
|
+
}
|
|
115
|
+
if (!Array.isArray(document.records)) {
|
|
116
|
+
corrupt(storagePath, 'records is not an array');
|
|
117
|
+
}
|
|
118
|
+
const records = [];
|
|
119
|
+
const tokens = new Set();
|
|
120
|
+
const bindings = new Set();
|
|
121
|
+
for (let index = 0; index < document.records.length; index += 1) {
|
|
122
|
+
const record = parseRecord(document.records[index], index, storagePath);
|
|
123
|
+
if (tokens.has(record.token)) {
|
|
124
|
+
corrupt(storagePath, `duplicate token at records[${String(index)}]`);
|
|
125
|
+
}
|
|
126
|
+
const bindingKey = identityBindingKey(record.publisher, record.contentHash);
|
|
127
|
+
if (bindings.has(bindingKey)) {
|
|
128
|
+
corrupt(storagePath, `duplicate binding at records[${String(index)}]`);
|
|
129
|
+
}
|
|
130
|
+
tokens.add(record.token);
|
|
131
|
+
bindings.add(bindingKey);
|
|
132
|
+
records.push(record);
|
|
133
|
+
}
|
|
134
|
+
const integrity = document.integrity;
|
|
135
|
+
if (!isPlainRecord(integrity)) {
|
|
136
|
+
corrupt(storagePath, 'integrity is not an object');
|
|
137
|
+
}
|
|
138
|
+
assertExactKeys(integrity, INTEGRITY_KEYS, storagePath, 'integrity', corrupt);
|
|
139
|
+
if (integrity.algorithm !== DIGEST_ALGORITHM) {
|
|
140
|
+
corrupt(storagePath, 'integrity algorithm is not supported');
|
|
141
|
+
}
|
|
142
|
+
const digest = integrity.digest;
|
|
143
|
+
if (!isNonEmptyString(digest) || !DIGEST_PATTERN.test(digest)) {
|
|
144
|
+
corrupt(storagePath, 'integrity digest is invalid');
|
|
145
|
+
}
|
|
146
|
+
const body = {
|
|
147
|
+
format: IDENTITY_REGISTRY_FORMAT,
|
|
148
|
+
version: IDENTITY_REGISTRY_VERSION,
|
|
149
|
+
registryId,
|
|
150
|
+
records,
|
|
151
|
+
};
|
|
152
|
+
if (!digestsEqual(canonicalDigest(body), digest)) {
|
|
153
|
+
corrupt(storagePath, 'integrity digest mismatch');
|
|
154
|
+
}
|
|
155
|
+
return Object.freeze({
|
|
156
|
+
registryId,
|
|
157
|
+
records: Object.freeze(records),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Serializes a registry document with a fresh integrity digest.
|
|
162
|
+
*
|
|
163
|
+
* @param registryId - Registry instance identifier.
|
|
164
|
+
* @param records - Current records.
|
|
165
|
+
*/
|
|
166
|
+
export function serializeIdentityRegistryDocument(registryId, records) {
|
|
167
|
+
const ordered = [...records].sort((left, right) => left.token.localeCompare(right.token));
|
|
168
|
+
const body = {
|
|
169
|
+
format: IDENTITY_REGISTRY_FORMAT,
|
|
170
|
+
version: IDENTITY_REGISTRY_VERSION,
|
|
171
|
+
registryId,
|
|
172
|
+
records: ordered,
|
|
173
|
+
};
|
|
174
|
+
const document = {
|
|
175
|
+
...body,
|
|
176
|
+
integrity: {
|
|
177
|
+
algorithm: DIGEST_ALGORITHM,
|
|
178
|
+
digest: canonicalDigest(body),
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
return `${JSON.stringify(document, null, 2)}\n`;
|
|
182
|
+
}
|
|
183
|
+
/** Writes a registry document through the shared atomic writer. */
|
|
184
|
+
function writeRegistryAtomically(storagePath, raw) {
|
|
185
|
+
writeAtomically(storagePath, raw, (path, reason) => new IdentityRegistryWriteError(path, reason));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Loads and validates a registry file.
|
|
189
|
+
*
|
|
190
|
+
* @param storagePath - Absolute registry file path.
|
|
191
|
+
*/
|
|
192
|
+
export function loadIdentityRegistryStorage(storagePath) {
|
|
193
|
+
const resolvedPath = assertIdentityRegistryStoragePath(storagePath);
|
|
194
|
+
let raw;
|
|
195
|
+
try {
|
|
196
|
+
raw = readFileSync(resolvedPath, 'utf8');
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
const code = error.code;
|
|
200
|
+
if (code === 'ENOENT') {
|
|
201
|
+
throw new IdentityRegistryMissingError(resolvedPath);
|
|
202
|
+
}
|
|
203
|
+
throw new IdentityRegistryCorruptError(resolvedPath, `storage cannot be read${code === undefined ? '' : ` (${code})`}`);
|
|
204
|
+
}
|
|
205
|
+
return parseIdentityRegistryDocument(raw, resolvedPath);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Persists a registry file atomically.
|
|
209
|
+
*
|
|
210
|
+
* @param storagePath - Absolute registry file path.
|
|
211
|
+
* @param registryId - Registry instance identifier.
|
|
212
|
+
* @param records - Current records.
|
|
213
|
+
*/
|
|
214
|
+
export function persistIdentityRegistryStorage(storagePath, registryId, records) {
|
|
215
|
+
const resolvedPath = assertIdentityRegistryStoragePath(storagePath);
|
|
216
|
+
const raw = serializeIdentityRegistryDocument(registryId, records);
|
|
217
|
+
writeRegistryAtomically(resolvedPath, raw);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Operator provisioning: creates a valid empty registry while the kernel is
|
|
221
|
+
* stopped. Refuses to overwrite an existing registry.
|
|
222
|
+
*
|
|
223
|
+
* @param storagePath - Absolute registry file path.
|
|
224
|
+
*/
|
|
225
|
+
export function provisionIdentityRegistryStorage(storagePath) {
|
|
226
|
+
const resolvedPath = assertIdentityRegistryStoragePath(storagePath);
|
|
227
|
+
if (existsSync(resolvedPath)) {
|
|
228
|
+
throw new IdentityRegistryStorageExistsError(resolvedPath);
|
|
229
|
+
}
|
|
230
|
+
const raw = serializeIdentityRegistryDocument(randomUUID(), []);
|
|
231
|
+
writeRegistryAtomically(resolvedPath, raw);
|
|
232
|
+
// Read the file back so a provisioning write that produced an unreadable
|
|
233
|
+
// document fails here, while the operator is still present.
|
|
234
|
+
loadIdentityRegistryStorage(resolvedPath);
|
|
235
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ExposedApiCaller } from '../../ExposedApiRegistry/contracts/types.js';
|
|
2
|
+
/** The plain caller view an interceptor sees. */
|
|
3
|
+
export interface InterceptedCaller {
|
|
4
|
+
readonly identity: string | null;
|
|
5
|
+
readonly callerClass: string;
|
|
6
|
+
readonly official: boolean;
|
|
7
|
+
readonly capabilities: readonly string[];
|
|
8
|
+
readonly origin: string;
|
|
9
|
+
}
|
|
10
|
+
/** The plain, frozen record of one intercepted call. */
|
|
11
|
+
export interface InterceptedCall {
|
|
12
|
+
/** The interception point, `name@major`. */
|
|
13
|
+
readonly target: string;
|
|
14
|
+
/** The method of the target exposure being called. */
|
|
15
|
+
readonly method: string;
|
|
16
|
+
/** The call's arguments (plain JSON values). */
|
|
17
|
+
readonly args: readonly unknown[];
|
|
18
|
+
/** The original caller of the giver's exposure. */
|
|
19
|
+
readonly caller: InterceptedCaller;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An interceptor's verdict. `modify` replaces the call's arguments (same method,
|
|
23
|
+
* same target); it cannot re-route the call.
|
|
24
|
+
*/
|
|
25
|
+
export type InterceptionVerdict = {
|
|
26
|
+
readonly verdict: 'allow';
|
|
27
|
+
} | {
|
|
28
|
+
readonly verdict: 'block';
|
|
29
|
+
readonly reason: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly verdict: 'modify';
|
|
32
|
+
readonly args: readonly unknown[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* What a giver implements on its instance to be called by the interception
|
|
36
|
+
* hardcore. A non-enumerable method, like `provideExposure`: it is reached only
|
|
37
|
+
* through the hardcore (`instanceOf` + `runAs`), never through `resolve`.
|
|
38
|
+
*/
|
|
39
|
+
export interface IInterceptor {
|
|
40
|
+
intercept(call: InterceptedCall): InterceptionVerdict;
|
|
41
|
+
}
|
|
42
|
+
/** Options the giver passes to `evaluate`. */
|
|
43
|
+
export interface InterceptionEvaluateOptions {
|
|
44
|
+
/** The caller view the giver's projection received (delegation by the owner). */
|
|
45
|
+
readonly caller?: ExposedApiCaller;
|
|
46
|
+
}
|
|
47
|
+
/** The combined outcome the giver enforces. */
|
|
48
|
+
export type InterceptionOutcome = {
|
|
49
|
+
readonly allowed: true;
|
|
50
|
+
readonly args: readonly unknown[];
|
|
51
|
+
readonly modifiedBy: readonly string[];
|
|
52
|
+
} | {
|
|
53
|
+
readonly allowed: false;
|
|
54
|
+
readonly reason: string;
|
|
55
|
+
readonly interceptor?: string;
|
|
56
|
+
};
|
|
57
|
+
export interface IInterceptionService {
|
|
58
|
+
/**
|
|
59
|
+
* Runs the admitted interceptors of the giver's interception point, in the
|
|
60
|
+
* giver's order. Only the point's owner may evaluate it.
|
|
61
|
+
*/
|
|
62
|
+
evaluate(target: string, method: string, args: readonly unknown[], options?: InterceptionEvaluateOptions): InterceptionOutcome;
|
|
63
|
+
/** The interception points in this composition, as `name@major`. */
|
|
64
|
+
list(): readonly string[];
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Stable, machine-readable codes for interception failures. */
|
|
2
|
+
export type InterceptionErrorCode = 'INTERCEPTION_DECLARATION_INVALID' | 'INTERCEPTION_BLOCKED';
|
|
3
|
+
/** Base class for every interception domain failure. */
|
|
4
|
+
export declare abstract class InterceptionError extends Error {
|
|
5
|
+
/** Stable, machine-readable error code. */
|
|
6
|
+
abstract readonly code: InterceptionErrorCode;
|
|
7
|
+
protected constructor(message: string, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
/** Raised at boot when an interception or an interception point is not admissible. */
|
|
10
|
+
export declare class InterceptionDeclarationError extends InterceptionError {
|
|
11
|
+
readonly code: "INTERCEPTION_DECLARATION_INVALID";
|
|
12
|
+
/** Service token of the declaring participant. */
|
|
13
|
+
readonly participant: string;
|
|
14
|
+
constructor(participant: string, reason: string);
|
|
15
|
+
}
|
|
16
|
+
/** Thrown by a giver when the interception outcome blocks the call. */
|
|
17
|
+
export declare class InterceptionBlockedError extends InterceptionError {
|
|
18
|
+
readonly code: "INTERCEPTION_BLOCKED";
|
|
19
|
+
/** The interception point, `name@major`. */
|
|
20
|
+
readonly target: string;
|
|
21
|
+
/** The blocking reason. */
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
/** Service token of the blocking interceptor, when one blocked. */
|
|
24
|
+
readonly interceptor: string | undefined;
|
|
25
|
+
constructor(target: string, reason: string, interceptor?: string);
|
|
26
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Base class for every interception domain failure. */
|
|
2
|
+
export class InterceptionError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'InterceptionError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Raised at boot when an interception or an interception point is not admissible. */
|
|
9
|
+
export class InterceptionDeclarationError extends InterceptionError {
|
|
10
|
+
code = 'INTERCEPTION_DECLARATION_INVALID';
|
|
11
|
+
/** Service token of the declaring participant. */
|
|
12
|
+
participant;
|
|
13
|
+
constructor(participant, reason) {
|
|
14
|
+
super(`Participant "${participant}": ${reason}`);
|
|
15
|
+
this.name = 'InterceptionDeclarationError';
|
|
16
|
+
this.participant = participant;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Thrown by a giver when the interception outcome blocks the call. */
|
|
20
|
+
export class InterceptionBlockedError extends InterceptionError {
|
|
21
|
+
code = 'INTERCEPTION_BLOCKED';
|
|
22
|
+
/** The interception point, `name@major`. */
|
|
23
|
+
target;
|
|
24
|
+
/** The blocking reason. */
|
|
25
|
+
reason;
|
|
26
|
+
/** Service token of the blocking interceptor, when one blocked. */
|
|
27
|
+
interceptor;
|
|
28
|
+
constructor(target, reason, interceptor) {
|
|
29
|
+
super(`Call to "${target}" was blocked by interception: ${reason}`);
|
|
30
|
+
this.name = 'InterceptionBlockedError';
|
|
31
|
+
this.target = target;
|
|
32
|
+
this.reason = reason;
|
|
33
|
+
this.interceptor = interceptor;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ServiceTier } from '../../../src/contracts/lifecycle.js';
|
|
2
|
+
import type { ServiceDescriptor } from '../../../src/contracts/serviceDescriptor.js';
|
|
3
|
+
import type { IInterceptionService } from '../contracts/IInterceptionService.js';
|
|
4
|
+
import { InterceptionService } from '../orchestrator/index.js';
|
|
5
|
+
export declare const INTERCEPTION_SERVICE_TIER: ServiceTier;
|
|
6
|
+
export declare const INTERCEPTION_CONTRACT_VERSION = "1.0.0";
|
|
7
|
+
export declare const INTERCEPTION_CONTRACT_METHODS: readonly ["evaluate", "list"];
|
|
8
|
+
export declare function createInterceptionDescriptor(): ServiceDescriptor<IInterceptionService, InterceptionService>;
|
|
9
|
+
export declare const InterceptionDescriptor: ServiceDescriptor<IInterceptionService, InterceptionService>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { withExposureBindings } from '../../ExposedApiRegistry/contracts/registrant.js';
|
|
2
|
+
import { InterceptionService } from '../orchestrator/index.js';
|
|
3
|
+
import { InterceptionToken } from './tokens.js';
|
|
4
|
+
export const INTERCEPTION_SERVICE_TIER = 'core';
|
|
5
|
+
export const INTERCEPTION_CONTRACT_VERSION = '1.0.0';
|
|
6
|
+
export const INTERCEPTION_CONTRACT_METHODS = ['evaluate', 'list'];
|
|
7
|
+
/**
|
|
8
|
+
* Per-exposure projection bindings. Each projection captures the resolver's
|
|
9
|
+
* caller view at resolve time (the registry runs projection calls as the
|
|
10
|
+
* owner), so `evaluate` knows which giver is asking.
|
|
11
|
+
*/
|
|
12
|
+
function interceptionExposureBindings(instance) {
|
|
13
|
+
return {
|
|
14
|
+
'interception.evaluate@1': {
|
|
15
|
+
projection: (_service, caller) => ({
|
|
16
|
+
evaluate: (target, method, args, options) => instance.evaluateAs(caller, target, method, args, options),
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
'interception.list@1': { projection: () => ({ list: () => instance.list() }) },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function createInterceptionDescriptor() {
|
|
23
|
+
return {
|
|
24
|
+
token: InterceptionToken,
|
|
25
|
+
tier: INTERCEPTION_SERVICE_TIER,
|
|
26
|
+
dependencies: [],
|
|
27
|
+
contract: {
|
|
28
|
+
version: INTERCEPTION_CONTRACT_VERSION,
|
|
29
|
+
methods: INTERCEPTION_CONTRACT_METHODS,
|
|
30
|
+
},
|
|
31
|
+
accessPolicy: {
|
|
32
|
+
allowedCallers: ['kernel'],
|
|
33
|
+
},
|
|
34
|
+
manifest: {
|
|
35
|
+
exposures: [
|
|
36
|
+
// `any`: a giver's exposure may be called from any origin, and its
|
|
37
|
+
// binding evaluates in that caller's chain. `evaluate` itself admits
|
|
38
|
+
// only the point's owner.
|
|
39
|
+
{ name: 'interception.evaluate', version: 1, scope: 'any' },
|
|
40
|
+
{ name: 'interception.list', version: 1, scope: 'runtime' },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
factory: () => {
|
|
44
|
+
const instance = new InterceptionService();
|
|
45
|
+
return withExposureBindings(instance, interceptionExposureBindings(instance));
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export const InterceptionDescriptor = createInterceptionDescriptor();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InterceptionToken } from '../contracts/tokens.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InterceptionToken } from '../contracts/tokens.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AdmittedManifest, KernelCallAuthority } from '../../../src/contracts/index.js';
|
|
2
|
+
import type { ExposedApiCaller } from '../../ExposedApiRegistry/contracts/types.js';
|
|
3
|
+
import type { IInterceptionService, InterceptionEvaluateOptions, InterceptionOutcome } from '../contracts/IInterceptionService.js';
|
|
4
|
+
/** One participant of the composition, as the boot hook hands it over. */
|
|
5
|
+
export interface InterceptionParticipant {
|
|
6
|
+
readonly token: string;
|
|
7
|
+
readonly identity: string | undefined;
|
|
8
|
+
readonly manifest: AdmittedManifest;
|
|
9
|
+
}
|
|
10
|
+
export declare class InterceptionService implements IInterceptionService {
|
|
11
|
+
#private;
|
|
12
|
+
private authority;
|
|
13
|
+
bindAuthority(value: KernelCallAuthority): void;
|
|
14
|
+
/**
|
|
15
|
+
* Builds the interception-point table from the composition's manifests.
|
|
16
|
+
*
|
|
17
|
+
* A point must sit on an exposure its giver declares; every admitted token
|
|
18
|
+
* must be a participant that declares an interception of that point; every
|
|
19
|
+
* declared interception must be admitted by a point. Anything else refuses
|
|
20
|
+
* the boot.
|
|
21
|
+
*/
|
|
22
|
+
registerComposition(participants: readonly InterceptionParticipant[]): void;
|
|
23
|
+
evaluate(target: string, method: string, args: readonly unknown[], options?: InterceptionEvaluateOptions): InterceptionOutcome;
|
|
24
|
+
list(): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates the point for `resolver`, which must be the point's owner. The
|
|
27
|
+
* interceptors run in the giver's admitted order, each as itself: the first
|
|
28
|
+
* `block` wins; `modify` chains; a throw or an invalid verdict blocks
|
|
29
|
+
* (fail closed).
|
|
30
|
+
*/
|
|
31
|
+
evaluateAs(resolver: ExposedApiCaller | undefined, target: string, method: string, args: readonly unknown[], options?: InterceptionEvaluateOptions): InterceptionOutcome;
|
|
32
|
+
}
|