@nextera.one/axis-server-sdk 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codec/axis1.encode.d.mts +10 -0
- package/dist/codec/axis1.encode.d.ts +10 -0
- package/dist/codec/axis1.encode.js +65 -0
- package/dist/codec/axis1.encode.js.map +1 -0
- package/dist/codec/axis1.encode.mjs +41 -0
- package/dist/codec/axis1.encode.mjs.map +1 -0
- package/dist/codec/axis1.signing.d.mts +8 -0
- package/dist/codec/axis1.signing.d.ts +8 -0
- package/dist/codec/axis1.signing.js +61 -0
- package/dist/codec/axis1.signing.js.map +1 -0
- package/dist/codec/axis1.signing.mjs +37 -0
- package/dist/codec/axis1.signing.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +6 -244
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +8 -238
- package/dist/core/index.mjs.map +1 -1
- package/dist/index-VxXqZPuH.d.mts +51 -0
- package/dist/index-VxXqZPuH.d.ts +51 -0
- package/dist/index.d.mts +1295 -429
- package/dist/index.d.ts +1295 -429
- package/dist/index.js +2985 -376
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2991 -368
- package/dist/index.mjs.map +1 -1
- package/dist/types/frame.d.mts +11 -0
- package/dist/types/frame.d.ts +11 -0
- package/dist/types/frame.js +78 -0
- package/dist/types/frame.js.map +1 -0
- package/dist/types/frame.mjs +54 -0
- package/dist/types/frame.mjs.map +1 -0
- package/package.json +2 -1
- package/dist/index-1uEwnW-w.d.mts +0 -122
- package/dist/index-1uEwnW-w.d.ts +0 -122
package/dist/index.js
CHANGED
|
@@ -166,76 +166,90 @@ var init_sensor_decorator = __esm({
|
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
// src/decorators/tlv-field.decorator.ts
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
194
|
-
const prop = String(propertyKey);
|
|
195
|
-
let entry = existing.find((e) => e.property === prop);
|
|
196
|
-
if (!entry) {
|
|
197
|
-
entry = { property: prop, tag: 0, validators: [] };
|
|
198
|
-
existing.push(entry);
|
|
169
|
+
var require_tlv_field_decorator = __commonJS({
|
|
170
|
+
"src/decorators/tlv-field.decorator.ts"(exports2) {
|
|
171
|
+
"use strict";
|
|
172
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
173
|
+
exports2.TLV_VALIDATORS_KEY = exports2.TLV_FIELDS_KEY = void 0;
|
|
174
|
+
exports2.TlvField = TlvField2;
|
|
175
|
+
exports2.TlvValidate = TlvValidate2;
|
|
176
|
+
exports2.TlvUtf8Pattern = TlvUtf8Pattern2;
|
|
177
|
+
exports2.TlvMinLen = TlvMinLen2;
|
|
178
|
+
exports2.TlvEnum = TlvEnum2;
|
|
179
|
+
exports2.TlvRange = TlvRange2;
|
|
180
|
+
require("reflect-metadata");
|
|
181
|
+
exports2.TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
182
|
+
exports2.TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
183
|
+
var textDecoder = new TextDecoder();
|
|
184
|
+
function assertUniqueFieldMetadata(existing, property, tag) {
|
|
185
|
+
const duplicateProperty = existing.find((item) => item.property === property);
|
|
186
|
+
if (duplicateProperty) {
|
|
187
|
+
throw new Error(`Duplicate @TlvField for property ${property}`);
|
|
188
|
+
}
|
|
189
|
+
const duplicateTag = existing.find((item) => item.tag === tag);
|
|
190
|
+
if (duplicateTag) {
|
|
191
|
+
throw new Error(`Duplicate @TlvField tag ${tag} for ${property}; already used by ${duplicateTag.property}`);
|
|
192
|
+
}
|
|
199
193
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return
|
|
194
|
+
function TlvField2(tag, options) {
|
|
195
|
+
return (target, propertyKey) => {
|
|
196
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_FIELDS_KEY, target.constructor) || [];
|
|
197
|
+
const property = String(propertyKey);
|
|
198
|
+
assertUniqueFieldMetadata(existing, property, tag);
|
|
199
|
+
existing.push({
|
|
200
|
+
property,
|
|
201
|
+
tag,
|
|
202
|
+
options
|
|
203
|
+
});
|
|
204
|
+
Reflect.defineMetadata(exports2.TLV_FIELDS_KEY, existing, target.constructor);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function TlvValidate2(validator) {
|
|
208
|
+
return (target, propertyKey) => {
|
|
209
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
210
|
+
const prop = String(propertyKey);
|
|
211
|
+
let entry = existing.find((e) => e.property === prop);
|
|
212
|
+
if (!entry) {
|
|
213
|
+
entry = { property: prop, tag: 0, validators: [] };
|
|
214
|
+
existing.push(entry);
|
|
215
|
+
}
|
|
216
|
+
entry.validators.push(validator);
|
|
217
|
+
Reflect.defineMetadata(exports2.TLV_VALIDATORS_KEY, existing, target.constructor);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function TlvUtf8Pattern2(pattern, message) {
|
|
221
|
+
const matcher = new RegExp(pattern.source, pattern.flags);
|
|
222
|
+
return TlvValidate2((val, prop) => {
|
|
223
|
+
const str = textDecoder.decode(val);
|
|
224
|
+
matcher.lastIndex = 0;
|
|
225
|
+
return matcher.test(str) ? null : message || `${prop}: failed pattern check`;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function TlvMinLen2(min, message) {
|
|
229
|
+
return TlvValidate2((val, prop) => {
|
|
230
|
+
return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function TlvEnum2(allowed, message) {
|
|
234
|
+
const set = new Set(allowed);
|
|
235
|
+
return TlvValidate2((val, prop) => {
|
|
236
|
+
const str = textDecoder.decode(val);
|
|
237
|
+
return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function TlvRange2(min, max, message) {
|
|
241
|
+
return TlvValidate2((val, prop) => {
|
|
242
|
+
if (val.length !== 8)
|
|
243
|
+
return `${prop}: u64 must be 8 bytes`;
|
|
244
|
+
let n = 0n;
|
|
245
|
+
for (const b of val)
|
|
246
|
+
n = n << 8n | BigInt(b);
|
|
247
|
+
if (n < min || n > max) {
|
|
248
|
+
return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
});
|
|
229
252
|
}
|
|
230
|
-
return null;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
var import_reflect_metadata5, TLV_FIELDS_KEY, TLV_VALIDATORS_KEY;
|
|
234
|
-
var init_tlv_field_decorator = __esm({
|
|
235
|
-
"src/decorators/tlv-field.decorator.ts"() {
|
|
236
|
-
import_reflect_metadata5 = require("reflect-metadata");
|
|
237
|
-
TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
238
|
-
TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
239
253
|
}
|
|
240
254
|
});
|
|
241
255
|
|
|
@@ -264,7 +278,7 @@ var require_dto_schema_util = __commonJS({
|
|
|
264
278
|
exports2.extractDtoSchema = extractDtoSchema2;
|
|
265
279
|
exports2.buildDtoDecoder = buildDtoDecoder2;
|
|
266
280
|
require("reflect-metadata");
|
|
267
|
-
var tlv_field_decorator_1 = (
|
|
281
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
268
282
|
var tlv_1 = (init_tlv(), __toCommonJS(tlv_exports));
|
|
269
283
|
function extractDtoSchema2(dto) {
|
|
270
284
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
@@ -373,7 +387,7 @@ var require_axis_id_dto = __commonJS({
|
|
|
373
387
|
};
|
|
374
388
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
375
389
|
exports2.AxisIdDto = void 0;
|
|
376
|
-
var tlv_field_decorator_1 = (
|
|
390
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
377
391
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
378
392
|
var AxisIdDto2 = class extends axis_tlv_dto_1.AxisTlvDto {
|
|
379
393
|
};
|
|
@@ -390,27 +404,27 @@ var require_axis_id_dto = __commonJS({
|
|
|
390
404
|
function AxisPartialType(BaseDto) {
|
|
391
405
|
class PartialDto extends BaseDto {
|
|
392
406
|
}
|
|
393
|
-
const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
|
|
407
|
+
const fields = Reflect.getOwnMetadata(import_tlv_field.TLV_FIELDS_KEY, BaseDto) || [];
|
|
394
408
|
const partialFields = fields.map((f) => ({
|
|
395
409
|
property: f.property,
|
|
396
410
|
tag: f.tag,
|
|
397
411
|
options: { ...f.options, required: false }
|
|
398
412
|
}));
|
|
399
|
-
Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
400
|
-
const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
413
|
+
Reflect.defineMetadata(import_tlv_field.TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
414
|
+
const validators = Reflect.getOwnMetadata(import_tlv_field.TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
401
415
|
if (validators.length > 0) {
|
|
402
|
-
Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
416
|
+
Reflect.defineMetadata(import_tlv_field.TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
403
417
|
}
|
|
404
418
|
Object.defineProperty(PartialDto, "name", {
|
|
405
419
|
value: `Partial${BaseDto.name}`
|
|
406
420
|
});
|
|
407
421
|
return PartialDto;
|
|
408
422
|
}
|
|
409
|
-
var
|
|
423
|
+
var import_reflect_metadata5, import_tlv_field;
|
|
410
424
|
var init_axis_partial_type = __esm({
|
|
411
425
|
"src/base/axis-partial-type.ts"() {
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
import_reflect_metadata5 = require("reflect-metadata");
|
|
427
|
+
import_tlv_field = __toESM(require_tlv_field_decorator());
|
|
414
428
|
}
|
|
415
429
|
});
|
|
416
430
|
|
|
@@ -429,7 +443,7 @@ var require_axis_response_dto = __commonJS({
|
|
|
429
443
|
};
|
|
430
444
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
431
445
|
exports2.AxisResponseDto = exports2.RESPONSE_TAG_UPDATED_BY = exports2.RESPONSE_TAG_CREATED_BY = exports2.RESPONSE_TAG_UPDATED_AT = exports2.RESPONSE_TAG_CREATED_AT = exports2.RESPONSE_TAG_ID = void 0;
|
|
432
|
-
var tlv_field_decorator_1 = (
|
|
446
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
433
447
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
434
448
|
exports2.RESPONSE_TAG_ID = 1;
|
|
435
449
|
exports2.RESPONSE_TAG_CREATED_AT = 2;
|
|
@@ -1324,6 +1338,7 @@ var require_intent_router = __commonJS({
|
|
|
1324
1338
|
this.intentKinds = /* @__PURE__ */ new Map();
|
|
1325
1339
|
this.cceHandlers = /* @__PURE__ */ new Map();
|
|
1326
1340
|
this.ccePipelineConfig = null;
|
|
1341
|
+
this.idelCompiler = null;
|
|
1327
1342
|
}
|
|
1328
1343
|
getSchema(intent) {
|
|
1329
1344
|
return this.intentSchemas.get(intent);
|
|
@@ -1337,6 +1352,34 @@ var require_intent_router = __commonJS({
|
|
|
1337
1352
|
getRegisteredIntents() {
|
|
1338
1353
|
return [...IntentRouter_1.BUILTIN_INTENTS, ...this.handlers.keys()];
|
|
1339
1354
|
}
|
|
1355
|
+
configureIdel(compiler) {
|
|
1356
|
+
this.idelCompiler = compiler;
|
|
1357
|
+
this.logger.log("IDEL compiler configured");
|
|
1358
|
+
}
|
|
1359
|
+
resolveIntent(proposal) {
|
|
1360
|
+
if (!this.idelCompiler) {
|
|
1361
|
+
throw new Error("IDEL compiler not configured. Call configureIdel() first.");
|
|
1362
|
+
}
|
|
1363
|
+
const result = this.idelCompiler.compile(proposal);
|
|
1364
|
+
if (!result.ok || !result.compiled) {
|
|
1365
|
+
const msg = result.errors?.map((e) => e.message).join("; ") ?? "Unknown compilation error";
|
|
1366
|
+
throw new Error(`IDEL compilation failed: ${msg}`);
|
|
1367
|
+
}
|
|
1368
|
+
return result.compiled;
|
|
1369
|
+
}
|
|
1370
|
+
async routeIdel(proposal, frame) {
|
|
1371
|
+
const compiled = this.resolveIntent(proposal);
|
|
1372
|
+
const resolvedFrame = {
|
|
1373
|
+
...frame,
|
|
1374
|
+
headers: new Map(frame.headers)
|
|
1375
|
+
};
|
|
1376
|
+
resolvedFrame.headers.set(3, new TextEncoder().encode(compiled.intent));
|
|
1377
|
+
if (compiled.params && Object.keys(compiled.params).length > 0) {
|
|
1378
|
+
resolvedFrame.body = new TextEncoder().encode(JSON.stringify(compiled.params));
|
|
1379
|
+
}
|
|
1380
|
+
const effect = await this.route(resolvedFrame);
|
|
1381
|
+
return { ...effect, compiled };
|
|
1382
|
+
}
|
|
1340
1383
|
getIntentEntry(intent) {
|
|
1341
1384
|
if (!this.has(intent))
|
|
1342
1385
|
return null;
|
|
@@ -1833,6 +1876,213 @@ var init_observation_hash = __esm({
|
|
|
1833
1876
|
}
|
|
1834
1877
|
});
|
|
1835
1878
|
|
|
1879
|
+
// src/engine/observation/truth-scoring.ts
|
|
1880
|
+
function scoreTruth(obs, expected) {
|
|
1881
|
+
const anomalies = [];
|
|
1882
|
+
let passedChecks = 0;
|
|
1883
|
+
let totalChecks = 0;
|
|
1884
|
+
totalChecks++;
|
|
1885
|
+
if (obs.endMs && obs.decision) {
|
|
1886
|
+
passedChecks++;
|
|
1887
|
+
} else {
|
|
1888
|
+
anomalies.push({
|
|
1889
|
+
code: "OBS_NOT_FINALIZED",
|
|
1890
|
+
level: "critical",
|
|
1891
|
+
message: "Observation was not finalized"
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
totalChecks++;
|
|
1895
|
+
if (obs.stages.length > 0) {
|
|
1896
|
+
passedChecks++;
|
|
1897
|
+
} else {
|
|
1898
|
+
anomalies.push({
|
|
1899
|
+
code: "OBS_NO_STAGES",
|
|
1900
|
+
level: "warning",
|
|
1901
|
+
message: "Observation has no execution stages"
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
totalChecks++;
|
|
1905
|
+
const failedStages = obs.stages.filter((s) => s.status === "fail");
|
|
1906
|
+
if (failedStages.length === 0 || obs.decision === "DENY") {
|
|
1907
|
+
passedChecks++;
|
|
1908
|
+
} else {
|
|
1909
|
+
for (const stage of failedStages) {
|
|
1910
|
+
anomalies.push({
|
|
1911
|
+
code: "STAGE_FAILED",
|
|
1912
|
+
level: "warning",
|
|
1913
|
+
message: `Stage '${stage.name}' failed: ${stage.reason ?? "unknown"}`,
|
|
1914
|
+
field: `stages.${stage.name}`
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
totalChecks++;
|
|
1919
|
+
const invalidSensors = obs.sensors.filter((s) => s.durationMs < 0);
|
|
1920
|
+
if (invalidSensors.length === 0) {
|
|
1921
|
+
passedChecks++;
|
|
1922
|
+
} else {
|
|
1923
|
+
anomalies.push({
|
|
1924
|
+
code: "SENSOR_INVALID_TIMING",
|
|
1925
|
+
level: "warning",
|
|
1926
|
+
message: `${invalidSensors.length} sensor(s) have negative duration`
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
totalChecks++;
|
|
1930
|
+
if (obs.durationMs !== void 0 && obs.durationMs >= 0 && obs.durationMs < 3e5) {
|
|
1931
|
+
passedChecks++;
|
|
1932
|
+
} else {
|
|
1933
|
+
anomalies.push({
|
|
1934
|
+
code: "OBS_DURATION_ANOMALY",
|
|
1935
|
+
level: "warning",
|
|
1936
|
+
message: `Observation duration ${obs.durationMs}ms is suspicious`,
|
|
1937
|
+
actual: obs.durationMs
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
if (expected) {
|
|
1941
|
+
if (expected.decision !== void 0) {
|
|
1942
|
+
totalChecks++;
|
|
1943
|
+
if (obs.decision === expected.decision) {
|
|
1944
|
+
passedChecks++;
|
|
1945
|
+
} else {
|
|
1946
|
+
anomalies.push({
|
|
1947
|
+
code: "DECISION_MISMATCH",
|
|
1948
|
+
level: "critical",
|
|
1949
|
+
message: `Expected decision '${expected.decision}', got '${obs.decision}'`,
|
|
1950
|
+
field: "decision",
|
|
1951
|
+
expected: expected.decision,
|
|
1952
|
+
actual: obs.decision
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
if (expected.statusCode !== void 0) {
|
|
1957
|
+
totalChecks++;
|
|
1958
|
+
if (obs.statusCode === expected.statusCode) {
|
|
1959
|
+
passedChecks++;
|
|
1960
|
+
} else {
|
|
1961
|
+
anomalies.push({
|
|
1962
|
+
code: "STATUS_MISMATCH",
|
|
1963
|
+
level: "warning",
|
|
1964
|
+
message: `Expected status ${expected.statusCode}, got ${obs.statusCode}`,
|
|
1965
|
+
field: "statusCode",
|
|
1966
|
+
expected: expected.statusCode,
|
|
1967
|
+
actual: obs.statusCode
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
if (expected.effect !== void 0) {
|
|
1972
|
+
totalChecks++;
|
|
1973
|
+
if (obs.resultCode === expected.effect || obs.facts?.effect === expected.effect) {
|
|
1974
|
+
passedChecks++;
|
|
1975
|
+
} else {
|
|
1976
|
+
anomalies.push({
|
|
1977
|
+
code: "EFFECT_MISMATCH",
|
|
1978
|
+
level: "warning",
|
|
1979
|
+
message: `Expected effect '${expected.effect}', got '${obs.resultCode}'`,
|
|
1980
|
+
field: "resultCode",
|
|
1981
|
+
expected: expected.effect,
|
|
1982
|
+
actual: obs.resultCode
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
if (expected.maxDurationMs !== void 0) {
|
|
1987
|
+
totalChecks++;
|
|
1988
|
+
if (obs.durationMs !== void 0 && obs.durationMs <= expected.maxDurationMs) {
|
|
1989
|
+
passedChecks++;
|
|
1990
|
+
} else {
|
|
1991
|
+
anomalies.push({
|
|
1992
|
+
code: "DURATION_EXCEEDED",
|
|
1993
|
+
level: "warning",
|
|
1994
|
+
message: `Execution took ${obs.durationMs}ms, max allowed ${expected.maxDurationMs}ms`,
|
|
1995
|
+
field: "durationMs",
|
|
1996
|
+
expected: expected.maxDurationMs,
|
|
1997
|
+
actual: obs.durationMs
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (expected.minSensorsPassed !== void 0) {
|
|
2002
|
+
totalChecks++;
|
|
2003
|
+
const passed = obs.sensors.filter((s) => s.allowed).length;
|
|
2004
|
+
if (passed >= expected.minSensorsPassed) {
|
|
2005
|
+
passedChecks++;
|
|
2006
|
+
} else {
|
|
2007
|
+
anomalies.push({
|
|
2008
|
+
code: "INSUFFICIENT_SENSORS",
|
|
2009
|
+
level: "warning",
|
|
2010
|
+
message: `Only ${passed} sensors passed, minimum required ${expected.minSensorsPassed}`,
|
|
2011
|
+
field: "sensors",
|
|
2012
|
+
expected: expected.minSensorsPassed,
|
|
2013
|
+
actual: passed
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
if (expected.assertions) {
|
|
2018
|
+
for (const [key, expectedValue] of Object.entries(expected.assertions)) {
|
|
2019
|
+
totalChecks++;
|
|
2020
|
+
const actualValue = obs.facts[key];
|
|
2021
|
+
if (deepEqual(actualValue, expectedValue)) {
|
|
2022
|
+
passedChecks++;
|
|
2023
|
+
} else {
|
|
2024
|
+
anomalies.push({
|
|
2025
|
+
code: "ASSERTION_FAILED",
|
|
2026
|
+
level: "warning",
|
|
2027
|
+
message: `Assertion failed for facts.${key}`,
|
|
2028
|
+
field: `facts.${key}`,
|
|
2029
|
+
expected: expectedValue,
|
|
2030
|
+
actual: actualValue
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
const confidence = totalChecks > 0 ? passedChecks / totalChecks : 0;
|
|
2037
|
+
const hasCritical = anomalies.some((a) => a.level === "critical");
|
|
2038
|
+
const status = computeTruthStatus(confidence, hasCritical, anomalies.length);
|
|
2039
|
+
const isDeed = status === "confirmed" || status === "partial" && !hasCritical;
|
|
2040
|
+
return {
|
|
2041
|
+
status,
|
|
2042
|
+
confidence,
|
|
2043
|
+
anomalies,
|
|
2044
|
+
passedChecks,
|
|
2045
|
+
totalChecks,
|
|
2046
|
+
verifiedAt: Date.now(),
|
|
2047
|
+
isDeed
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
function computeTruthStatus(confidence, hasCritical, anomalyCount) {
|
|
2051
|
+
if (hasCritical) return "failed";
|
|
2052
|
+
if (confidence === 1) return "confirmed";
|
|
2053
|
+
if (confidence >= 0.8) return "partial";
|
|
2054
|
+
if (confidence >= 0.5) return "uncertain";
|
|
2055
|
+
return "disputed";
|
|
2056
|
+
}
|
|
2057
|
+
function verifyObservation(obs, expected) {
|
|
2058
|
+
const verdict = scoreTruth(obs, expected);
|
|
2059
|
+
return { observation: obs, verdict };
|
|
2060
|
+
}
|
|
2061
|
+
function deepEqual(a, b) {
|
|
2062
|
+
if (a === b) return true;
|
|
2063
|
+
if (a === null || b === null) return false;
|
|
2064
|
+
if (typeof a !== typeof b) return false;
|
|
2065
|
+
if (typeof a !== "object") return String(a) === String(b);
|
|
2066
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2067
|
+
if (a.length !== b.length) return false;
|
|
2068
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
2069
|
+
}
|
|
2070
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
2071
|
+
const aKeys = Object.keys(a);
|
|
2072
|
+
const bKeys = Object.keys(b);
|
|
2073
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
2074
|
+
return aKeys.every(
|
|
2075
|
+
(key) => deepEqual(
|
|
2076
|
+
a[key],
|
|
2077
|
+
b[key]
|
|
2078
|
+
)
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
var init_truth_scoring = __esm({
|
|
2082
|
+
"src/engine/observation/truth-scoring.ts"() {
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
|
|
1836
2086
|
// src/core/constants.ts
|
|
1837
2087
|
var constants_exports = {};
|
|
1838
2088
|
__export(constants_exports, {
|
|
@@ -1976,97 +2226,15 @@ var init_varint = __esm({
|
|
|
1976
2226
|
var axis_bin_exports = {};
|
|
1977
2227
|
__export(axis_bin_exports, {
|
|
1978
2228
|
AxisFrameZ: () => AxisFrameZ,
|
|
1979
|
-
decodeFrame: () => decodeFrame,
|
|
1980
|
-
encodeFrame: () => encodeFrame,
|
|
1981
|
-
getSignTarget: () => getSignTarget
|
|
1982
|
-
});
|
|
1983
|
-
|
|
1984
|
-
const hdrBytes = (0, import_axis_protocol.encodeTLVs)(
|
|
1985
|
-
Array.from(frame.headers.entries()).map(([t, v]) => ({
|
|
1986
|
-
type: t,
|
|
1987
|
-
value: v
|
|
1988
|
-
}))
|
|
1989
|
-
);
|
|
1990
|
-
if (hdrBytes.length > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header too large");
|
|
1991
|
-
if (frame.body.length > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body too large");
|
|
1992
|
-
if (frame.sig.length > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature too large");
|
|
1993
|
-
const hdrLenBytes = (0, import_axis_protocol3.encodeVarint)(hdrBytes.length);
|
|
1994
|
-
const bodyLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.body.length);
|
|
1995
|
-
const sigLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.sig.length);
|
|
1996
|
-
const totalLen = 5 + // Magic (AXIS1)
|
|
1997
|
-
1 + // Version
|
|
1998
|
-
1 + // Flags
|
|
1999
|
-
hdrLenBytes.length + bodyLenBytes.length + sigLenBytes.length + hdrBytes.length + frame.body.length + frame.sig.length;
|
|
2000
|
-
if (totalLen > import_axis_protocol2.MAX_FRAME_LEN) throw new Error("Total frame too large");
|
|
2001
|
-
const buf = new Uint8Array(totalLen);
|
|
2002
|
-
let offset = 0;
|
|
2003
|
-
buf.set(import_axis_protocol2.AXIS_MAGIC, offset);
|
|
2004
|
-
offset += 5;
|
|
2005
|
-
buf[offset++] = import_axis_protocol2.AXIS_VERSION;
|
|
2006
|
-
buf[offset++] = frame.flags;
|
|
2007
|
-
buf.set(hdrLenBytes, offset);
|
|
2008
|
-
offset += hdrLenBytes.length;
|
|
2009
|
-
buf.set(bodyLenBytes, offset);
|
|
2010
|
-
offset += bodyLenBytes.length;
|
|
2011
|
-
buf.set(sigLenBytes, offset);
|
|
2012
|
-
offset += sigLenBytes.length;
|
|
2013
|
-
buf.set(hdrBytes, offset);
|
|
2014
|
-
offset += hdrBytes.length;
|
|
2015
|
-
buf.set(frame.body, offset);
|
|
2016
|
-
offset += frame.body.length;
|
|
2017
|
-
buf.set(frame.sig, offset);
|
|
2018
|
-
offset += frame.sig.length;
|
|
2019
|
-
return buf;
|
|
2020
|
-
}
|
|
2021
|
-
function decodeFrame(buf) {
|
|
2022
|
-
let offset = 0;
|
|
2023
|
-
if (offset + 5 > buf.length) throw new Error("Packet too short");
|
|
2024
|
-
for (let i = 0; i < 5; i++) {
|
|
2025
|
-
if (buf[offset + i] !== import_axis_protocol2.AXIS_MAGIC[i]) throw new Error("Invalid Magic");
|
|
2026
|
-
}
|
|
2027
|
-
offset += 5;
|
|
2028
|
-
const ver = buf[offset++];
|
|
2029
|
-
if (ver !== import_axis_protocol2.AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);
|
|
2030
|
-
const flags = buf[offset++];
|
|
2031
|
-
const { value: hdrLen, length: hlLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
2032
|
-
offset += hlLen;
|
|
2033
|
-
if (hdrLen > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header limit exceeded");
|
|
2034
|
-
const { value: bodyLen, length: blLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
2035
|
-
offset += blLen;
|
|
2036
|
-
if (bodyLen > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body limit exceeded");
|
|
2037
|
-
const { value: sigLen, length: slLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
2038
|
-
offset += slLen;
|
|
2039
|
-
if (sigLen > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature limit exceeded");
|
|
2040
|
-
if (offset + hdrLen + bodyLen + sigLen > buf.length) {
|
|
2041
|
-
throw new Error("Frame truncated");
|
|
2042
|
-
}
|
|
2043
|
-
const hdrBytes = buf.slice(offset, offset + hdrLen);
|
|
2044
|
-
offset += hdrLen;
|
|
2045
|
-
const bodyBytes = buf.slice(offset, offset + bodyLen);
|
|
2046
|
-
offset += bodyLen;
|
|
2047
|
-
const sigBytes = buf.slice(offset, offset + sigLen);
|
|
2048
|
-
offset += sigLen;
|
|
2049
|
-
const headers = (0, import_axis_protocol.decodeTLVs)(hdrBytes);
|
|
2050
|
-
return {
|
|
2051
|
-
flags,
|
|
2052
|
-
headers,
|
|
2053
|
-
body: bodyBytes,
|
|
2054
|
-
sig: sigBytes
|
|
2055
|
-
};
|
|
2056
|
-
}
|
|
2057
|
-
function getSignTarget(frame) {
|
|
2058
|
-
return encodeFrame({
|
|
2059
|
-
...frame,
|
|
2060
|
-
sig: new Uint8Array(0)
|
|
2061
|
-
});
|
|
2062
|
-
}
|
|
2063
|
-
var z, AxisFrameZ;
|
|
2229
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
2230
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
2231
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget
|
|
2232
|
+
});
|
|
2233
|
+
var z, import_axis_protocol4, AxisFrameZ;
|
|
2064
2234
|
var init_axis_bin = __esm({
|
|
2065
2235
|
"src/core/axis-bin.ts"() {
|
|
2066
2236
|
z = __toESM(require("zod"));
|
|
2067
|
-
|
|
2068
|
-
init_tlv();
|
|
2069
|
-
init_varint();
|
|
2237
|
+
import_axis_protocol4 = require("@nextera.one/axis-protocol");
|
|
2070
2238
|
AxisFrameZ = z.object({
|
|
2071
2239
|
/** Flag bits for protocol control (e.g., encryption, compression) */
|
|
2072
2240
|
flags: z.number().int().nonnegative(),
|
|
@@ -2085,12 +2253,7 @@ var init_axis_bin = __esm({
|
|
|
2085
2253
|
|
|
2086
2254
|
// src/core/signature.ts
|
|
2087
2255
|
function computeSignaturePayload(frame) {
|
|
2088
|
-
|
|
2089
|
-
...frame,
|
|
2090
|
-
sig: new Uint8Array(0)
|
|
2091
|
-
};
|
|
2092
|
-
const encoded = encodeFrame(frameWithoutSig);
|
|
2093
|
-
return Buffer.from(encoded);
|
|
2256
|
+
return Buffer.from((0, import_axis_protocol4.getSignTarget)(frame));
|
|
2094
2257
|
}
|
|
2095
2258
|
function signFrame(frame, privateKey) {
|
|
2096
2259
|
const payload = computeSignaturePayload(frame);
|
|
@@ -2978,7 +3141,7 @@ function encodeAxis1Frame(f) {
|
|
|
2978
3141
|
if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
|
|
2979
3142
|
throw new Error("AXIS1_BAD_BUFFERS");
|
|
2980
3143
|
}
|
|
2981
|
-
if (f.ver !==
|
|
3144
|
+
if (f.ver !== import_axis_protocol5.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
2982
3145
|
const hdrLen = encVarint(BigInt(f.hdr.length));
|
|
2983
3146
|
const bodyLen = encVarint(BigInt(f.body.length));
|
|
2984
3147
|
const sigLen = encVarint(BigInt(f.sig.length));
|
|
@@ -2994,17 +3157,18 @@ function encodeAxis1Frame(f) {
|
|
|
2994
3157
|
f.sig
|
|
2995
3158
|
]);
|
|
2996
3159
|
}
|
|
2997
|
-
var MAGIC;
|
|
3160
|
+
var import_axis_protocol5, MAGIC;
|
|
2998
3161
|
var init_axis1_encode = __esm({
|
|
2999
3162
|
"src/codec/axis1.encode.ts"() {
|
|
3163
|
+
import_axis_protocol5 = require("@nextera.one/axis-protocol");
|
|
3000
3164
|
init_tlv_encode();
|
|
3001
|
-
MAGIC = Buffer.from(
|
|
3165
|
+
MAGIC = Buffer.from(import_axis_protocol5.AXIS_MAGIC);
|
|
3002
3166
|
}
|
|
3003
3167
|
});
|
|
3004
3168
|
|
|
3005
3169
|
// src/codec/axis1.signing.ts
|
|
3006
3170
|
function axis1SigningBytes(params) {
|
|
3007
|
-
if (params.ver !==
|
|
3171
|
+
if (params.ver !== import_axis_protocol6.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
3008
3172
|
const hdrLen = encVarint(BigInt(params.hdr.length));
|
|
3009
3173
|
const bodyLen = encVarint(BigInt(params.body.length));
|
|
3010
3174
|
const sigLenZero = encVarint(0n);
|
|
@@ -3019,11 +3183,12 @@ function axis1SigningBytes(params) {
|
|
|
3019
3183
|
params.body
|
|
3020
3184
|
]);
|
|
3021
3185
|
}
|
|
3022
|
-
var MAGIC2;
|
|
3186
|
+
var import_axis_protocol6, MAGIC2;
|
|
3023
3187
|
var init_axis1_signing = __esm({
|
|
3024
3188
|
"src/codec/axis1.signing.ts"() {
|
|
3189
|
+
import_axis_protocol6 = require("@nextera.one/axis-protocol");
|
|
3025
3190
|
init_tlv_encode();
|
|
3026
|
-
MAGIC2 = Buffer.from(
|
|
3191
|
+
MAGIC2 = Buffer.from(import_axis_protocol6.AXIS_MAGIC);
|
|
3027
3192
|
}
|
|
3028
3193
|
});
|
|
3029
3194
|
|
|
@@ -3353,11 +3518,12 @@ function decodeAxis1Frame(buf) {
|
|
|
3353
3518
|
if (off !== buf.length) throw new Error("AXIS1_TRAILING_BYTES");
|
|
3354
3519
|
return { ver, flags, hdr, body, sig, frameSize: buf.length };
|
|
3355
3520
|
}
|
|
3356
|
-
var MAGIC3;
|
|
3521
|
+
var import_axis_protocol7, MAGIC3;
|
|
3357
3522
|
var init_frame = __esm({
|
|
3358
3523
|
"src/types/frame.ts"() {
|
|
3524
|
+
import_axis_protocol7 = require("@nextera.one/axis-protocol");
|
|
3359
3525
|
init_tlv2();
|
|
3360
|
-
MAGIC3 = Buffer.from(
|
|
3526
|
+
MAGIC3 = Buffer.from(import_axis_protocol7.AXIS_MAGIC);
|
|
3361
3527
|
}
|
|
3362
3528
|
});
|
|
3363
3529
|
|
|
@@ -3511,7 +3677,52 @@ var init_capabilities = __esm({
|
|
|
3511
3677
|
}
|
|
3512
3678
|
});
|
|
3513
3679
|
|
|
3680
|
+
// src/law/law.types.ts
|
|
3681
|
+
function buildAxisLawEvaluationContext(input) {
|
|
3682
|
+
const metadata = input.metadata ?? {};
|
|
3683
|
+
const packet = input.packet;
|
|
3684
|
+
const packetBody = input.frameBody ?? packet?.body ?? packet?.args ?? void 0;
|
|
3685
|
+
const capsuleId = metadata.capsule_id ?? metadata.capsuleId ?? packet?.capsuleId ?? input.clientId;
|
|
3686
|
+
const audience = input.aud ?? metadata.audience ?? packet?.aud;
|
|
3687
|
+
const tps = metadata.tps ?? packet?.tps ?? packet?.tickTps;
|
|
3688
|
+
return {
|
|
3689
|
+
actorId: input.actorId,
|
|
3690
|
+
intent: input.intent,
|
|
3691
|
+
audience,
|
|
3692
|
+
tps,
|
|
3693
|
+
country: input.country,
|
|
3694
|
+
ip: input.ip,
|
|
3695
|
+
path: input.path,
|
|
3696
|
+
clientId: input.clientId,
|
|
3697
|
+
deviceId: input.deviceId,
|
|
3698
|
+
sessionId: input.sessionId,
|
|
3699
|
+
capsuleId,
|
|
3700
|
+
metadata,
|
|
3701
|
+
packet,
|
|
3702
|
+
frameBody: packetBody
|
|
3703
|
+
};
|
|
3704
|
+
}
|
|
3705
|
+
var init_law_types = __esm({
|
|
3706
|
+
"src/law/law.types.ts"() {
|
|
3707
|
+
}
|
|
3708
|
+
});
|
|
3709
|
+
|
|
3710
|
+
// src/law/index.ts
|
|
3711
|
+
var law_exports = {};
|
|
3712
|
+
__export(law_exports, {
|
|
3713
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext
|
|
3714
|
+
});
|
|
3715
|
+
var init_law = __esm({
|
|
3716
|
+
"src/law/index.ts"() {
|
|
3717
|
+
init_law_types();
|
|
3718
|
+
}
|
|
3719
|
+
});
|
|
3720
|
+
|
|
3514
3721
|
// src/risk/index.ts
|
|
3722
|
+
var risk_exports = {};
|
|
3723
|
+
__export(risk_exports, {
|
|
3724
|
+
RiskDecision: () => RiskDecision
|
|
3725
|
+
});
|
|
3515
3726
|
var RiskDecision;
|
|
3516
3727
|
var init_risk = __esm({
|
|
3517
3728
|
"src/risk/index.ts"() {
|
|
@@ -4565,6 +4776,374 @@ var require_axis_sensor_chain_service = __commonJS({
|
|
|
4565
4776
|
}
|
|
4566
4777
|
});
|
|
4567
4778
|
|
|
4779
|
+
// src/timeline/timeline.engine.ts
|
|
4780
|
+
function generateId(prefix) {
|
|
4781
|
+
return `${prefix}_${(0, import_crypto8.randomBytes)(16).toString("hex")}`;
|
|
4782
|
+
}
|
|
4783
|
+
function sha2566(data) {
|
|
4784
|
+
return (0, import_crypto8.createHash)("sha256").update(data).digest("hex");
|
|
4785
|
+
}
|
|
4786
|
+
function hashPayload2(payload) {
|
|
4787
|
+
return sha2566(JSON.stringify(payload));
|
|
4788
|
+
}
|
|
4789
|
+
function diffObjects(a, b) {
|
|
4790
|
+
const diffs = [];
|
|
4791
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
4792
|
+
for (const key of allKeys) {
|
|
4793
|
+
const va = a[key];
|
|
4794
|
+
const vb = b[key];
|
|
4795
|
+
if (JSON.stringify(va) !== JSON.stringify(vb)) {
|
|
4796
|
+
diffs.push({ field: key, original: va, replayed: vb });
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
return diffs;
|
|
4800
|
+
}
|
|
4801
|
+
var import_crypto8, TimelineEngine;
|
|
4802
|
+
var init_timeline_engine = __esm({
|
|
4803
|
+
"src/timeline/timeline.engine.ts"() {
|
|
4804
|
+
import_crypto8 = require("crypto");
|
|
4805
|
+
TimelineEngine = class {
|
|
4806
|
+
constructor(store) {
|
|
4807
|
+
this.store = store;
|
|
4808
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
4809
|
+
}
|
|
4810
|
+
/** Register an intent handler for timeline execution */
|
|
4811
|
+
registerHandler(handler) {
|
|
4812
|
+
this.handlers.set(handler.intent, handler);
|
|
4813
|
+
}
|
|
4814
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4815
|
+
// Record (store a real execution as a timeline event)
|
|
4816
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4817
|
+
async recordEvent(intent, actorId, payload, result, options = {}) {
|
|
4818
|
+
const event = {
|
|
4819
|
+
event_id: generateId("evt"),
|
|
4820
|
+
timeline_id: options.timelineId ?? "prime",
|
|
4821
|
+
branch_id: options.branchId ?? "main",
|
|
4822
|
+
parent_event_id: options.parentEventId ?? null,
|
|
4823
|
+
intent,
|
|
4824
|
+
actor_id: actorId,
|
|
4825
|
+
capsule_id: options.capsuleId,
|
|
4826
|
+
tps_coordinate: options.tpsCoordinate,
|
|
4827
|
+
payload_hash: hashPayload2(payload),
|
|
4828
|
+
result_hash: hashPayload2(result),
|
|
4829
|
+
status: "executed",
|
|
4830
|
+
domain: "prime",
|
|
4831
|
+
determinism: options.determinism ?? "deterministic",
|
|
4832
|
+
witness_id: options.witnessId,
|
|
4833
|
+
created_at: Date.now(),
|
|
4834
|
+
metadata: { payload, result }
|
|
4835
|
+
};
|
|
4836
|
+
await this.store.saveEvent(event);
|
|
4837
|
+
return event;
|
|
4838
|
+
}
|
|
4839
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4840
|
+
// Replay
|
|
4841
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4842
|
+
async replay(request) {
|
|
4843
|
+
const originalEvent = await this.store.getEvent(request.source_event_id);
|
|
4844
|
+
if (!originalEvent) {
|
|
4845
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
4846
|
+
}
|
|
4847
|
+
const handler = this.handlers.get(originalEvent.intent);
|
|
4848
|
+
if (!handler) {
|
|
4849
|
+
throw new Error(`No handler registered for intent '${originalEvent.intent}'`);
|
|
4850
|
+
}
|
|
4851
|
+
const originalPayload = originalEvent.metadata?.payload ?? {};
|
|
4852
|
+
const replayPayload = request.mode === "analytical" && request.override_payload ? request.override_payload : originalPayload;
|
|
4853
|
+
const snapshot = await this.store.getSnapshotByEvent(originalEvent.event_id);
|
|
4854
|
+
const context = {
|
|
4855
|
+
event_id: generateId("evt"),
|
|
4856
|
+
timeline_id: originalEvent.timeline_id,
|
|
4857
|
+
branch_id: `replay_${originalEvent.branch_id}`,
|
|
4858
|
+
domain: "audit",
|
|
4859
|
+
actor_id: originalEvent.actor_id,
|
|
4860
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
4861
|
+
snapshot: snapshot ?? void 0,
|
|
4862
|
+
is_replay: true,
|
|
4863
|
+
is_simulation: false
|
|
4864
|
+
};
|
|
4865
|
+
const startMs = Date.now();
|
|
4866
|
+
const handlerResult = await handler.execute(replayPayload, context);
|
|
4867
|
+
const durationMs = Date.now() - startMs;
|
|
4868
|
+
const replayedEvent = {
|
|
4869
|
+
event_id: context.event_id,
|
|
4870
|
+
timeline_id: originalEvent.timeline_id,
|
|
4871
|
+
branch_id: context.branch_id,
|
|
4872
|
+
parent_event_id: originalEvent.event_id,
|
|
4873
|
+
intent: originalEvent.intent,
|
|
4874
|
+
actor_id: originalEvent.actor_id,
|
|
4875
|
+
capsule_id: originalEvent.capsule_id,
|
|
4876
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
4877
|
+
payload_hash: hashPayload2(replayPayload),
|
|
4878
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
4879
|
+
status: "replayed",
|
|
4880
|
+
domain: "audit",
|
|
4881
|
+
determinism: originalEvent.determinism,
|
|
4882
|
+
created_at: Date.now(),
|
|
4883
|
+
metadata: { payload: replayPayload, result: handlerResult.result_data }
|
|
4884
|
+
};
|
|
4885
|
+
await this.store.saveEvent(replayedEvent);
|
|
4886
|
+
const originalResult = originalEvent.metadata?.result ?? {};
|
|
4887
|
+
const differences = diffObjects(originalResult, handlerResult.result_data);
|
|
4888
|
+
const deterministicMatch = originalEvent.result_hash === replayedEvent.result_hash;
|
|
4889
|
+
return {
|
|
4890
|
+
original_event: originalEvent,
|
|
4891
|
+
replayed_event: replayedEvent,
|
|
4892
|
+
mode: request.mode,
|
|
4893
|
+
deterministic_match: deterministicMatch,
|
|
4894
|
+
differences,
|
|
4895
|
+
duration_ms: durationMs
|
|
4896
|
+
};
|
|
4897
|
+
}
|
|
4898
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4899
|
+
// Fork
|
|
4900
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4901
|
+
async fork(request) {
|
|
4902
|
+
const sourceEvent = await this.store.getEvent(request.source_event_id);
|
|
4903
|
+
if (!sourceEvent) {
|
|
4904
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
4905
|
+
}
|
|
4906
|
+
const handler = this.handlers.get(sourceEvent.intent);
|
|
4907
|
+
if (!handler) {
|
|
4908
|
+
throw new Error(`No handler registered for intent '${sourceEvent.intent}'`);
|
|
4909
|
+
}
|
|
4910
|
+
const branch = {
|
|
4911
|
+
branch_id: generateId("branch"),
|
|
4912
|
+
timeline_id: generateId("timeline"),
|
|
4913
|
+
origin_timeline_id: sourceEvent.timeline_id,
|
|
4914
|
+
origin_event_id: sourceEvent.event_id,
|
|
4915
|
+
branch_type: "fork",
|
|
4916
|
+
creator_subject_id: request.actor_id,
|
|
4917
|
+
purpose: request.purpose,
|
|
4918
|
+
status: "active"
|
|
4919
|
+
};
|
|
4920
|
+
await this.store.saveBranch(branch);
|
|
4921
|
+
const snapshot = {
|
|
4922
|
+
snapshot_id: generateId("snap"),
|
|
4923
|
+
timeline_id: sourceEvent.timeline_id,
|
|
4924
|
+
event_id: sourceEvent.event_id,
|
|
4925
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
4926
|
+
state_hash: hashPayload2(
|
|
4927
|
+
sourceEvent.metadata?.result ?? {}
|
|
4928
|
+
),
|
|
4929
|
+
state_data: sourceEvent.metadata?.result ?? {},
|
|
4930
|
+
created_at: Date.now()
|
|
4931
|
+
};
|
|
4932
|
+
await this.store.saveSnapshot(snapshot);
|
|
4933
|
+
const context = {
|
|
4934
|
+
event_id: generateId("evt"),
|
|
4935
|
+
timeline_id: branch.timeline_id,
|
|
4936
|
+
branch_id: branch.branch_id,
|
|
4937
|
+
domain: "fork",
|
|
4938
|
+
actor_id: request.actor_id,
|
|
4939
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
4940
|
+
snapshot,
|
|
4941
|
+
is_replay: false,
|
|
4942
|
+
is_simulation: false
|
|
4943
|
+
};
|
|
4944
|
+
const handlerResult = await handler.execute(request.new_payload, context);
|
|
4945
|
+
const forkedEvent = {
|
|
4946
|
+
event_id: context.event_id,
|
|
4947
|
+
timeline_id: branch.timeline_id,
|
|
4948
|
+
branch_id: branch.branch_id,
|
|
4949
|
+
parent_event_id: sourceEvent.event_id,
|
|
4950
|
+
intent: sourceEvent.intent,
|
|
4951
|
+
actor_id: request.actor_id,
|
|
4952
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
4953
|
+
payload_hash: hashPayload2(request.new_payload),
|
|
4954
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
4955
|
+
status: "forked",
|
|
4956
|
+
domain: "fork",
|
|
4957
|
+
determinism: sourceEvent.determinism,
|
|
4958
|
+
created_at: Date.now(),
|
|
4959
|
+
metadata: {
|
|
4960
|
+
payload: request.new_payload,
|
|
4961
|
+
result: handlerResult.result_data
|
|
4962
|
+
}
|
|
4963
|
+
};
|
|
4964
|
+
await this.store.saveEvent(forkedEvent);
|
|
4965
|
+
return { branch, forked_event: forkedEvent, snapshot };
|
|
4966
|
+
}
|
|
4967
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4968
|
+
// Simulate
|
|
4969
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4970
|
+
async simulate(request) {
|
|
4971
|
+
const handler = this.handlers.get(request.intent);
|
|
4972
|
+
if (!handler) {
|
|
4973
|
+
throw new Error(`No handler registered for intent '${request.intent}'`);
|
|
4974
|
+
}
|
|
4975
|
+
let snapshot;
|
|
4976
|
+
if (request.from_snapshot_id) {
|
|
4977
|
+
const loaded = await this.store.getSnapshot(request.from_snapshot_id);
|
|
4978
|
+
if (!loaded) {
|
|
4979
|
+
throw new Error(`Snapshot ${request.from_snapshot_id} not found`);
|
|
4980
|
+
}
|
|
4981
|
+
snapshot = loaded;
|
|
4982
|
+
}
|
|
4983
|
+
const branch = {
|
|
4984
|
+
branch_id: generateId("branch"),
|
|
4985
|
+
timeline_id: generateId("timeline"),
|
|
4986
|
+
origin_timeline_id: "prime",
|
|
4987
|
+
origin_event_id: "simulation_origin",
|
|
4988
|
+
branch_type: "simulation",
|
|
4989
|
+
created_at_tps: request.at_tps,
|
|
4990
|
+
creator_subject_id: request.actor_id,
|
|
4991
|
+
purpose: request.purpose,
|
|
4992
|
+
status: "active"
|
|
4993
|
+
};
|
|
4994
|
+
await this.store.saveBranch(branch);
|
|
4995
|
+
const context = {
|
|
4996
|
+
event_id: generateId("evt"),
|
|
4997
|
+
timeline_id: branch.timeline_id,
|
|
4998
|
+
branch_id: branch.branch_id,
|
|
4999
|
+
domain: "shadow",
|
|
5000
|
+
actor_id: request.actor_id,
|
|
5001
|
+
tps_coordinate: request.at_tps,
|
|
5002
|
+
snapshot,
|
|
5003
|
+
is_replay: false,
|
|
5004
|
+
is_simulation: true
|
|
5005
|
+
};
|
|
5006
|
+
const startMs = Date.now();
|
|
5007
|
+
const handlerResult = await handler.execute(request.payload, context);
|
|
5008
|
+
const durationMs = Date.now() - startMs;
|
|
5009
|
+
const simulatedEvent = {
|
|
5010
|
+
event_id: context.event_id,
|
|
5011
|
+
timeline_id: branch.timeline_id,
|
|
5012
|
+
branch_id: branch.branch_id,
|
|
5013
|
+
parent_event_id: null,
|
|
5014
|
+
intent: request.intent,
|
|
5015
|
+
actor_id: request.actor_id,
|
|
5016
|
+
tps_coordinate: request.at_tps,
|
|
5017
|
+
payload_hash: hashPayload2(request.payload),
|
|
5018
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
5019
|
+
status: "simulated",
|
|
5020
|
+
domain: "shadow",
|
|
5021
|
+
determinism: "bounded_nondeterministic",
|
|
5022
|
+
created_at: Date.now(),
|
|
5023
|
+
metadata: { payload: request.payload, result: handlerResult.result_data }
|
|
5024
|
+
};
|
|
5025
|
+
await this.store.saveEvent(simulatedEvent);
|
|
5026
|
+
branch.status = "completed";
|
|
5027
|
+
await this.store.saveBranch(branch);
|
|
5028
|
+
return {
|
|
5029
|
+
branch,
|
|
5030
|
+
simulated_event: simulatedEvent,
|
|
5031
|
+
predicted_outcome: handlerResult.result_data,
|
|
5032
|
+
side_effects: handlerResult.side_effects ?? [],
|
|
5033
|
+
duration_ms: durationMs
|
|
5034
|
+
};
|
|
5035
|
+
}
|
|
5036
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5037
|
+
// Compare timelines
|
|
5038
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5039
|
+
async compare(timelineIdA, timelineIdB) {
|
|
5040
|
+
const eventsA = await this.store.getEventsByTimeline(timelineIdA);
|
|
5041
|
+
const eventsB = await this.store.getEventsByTimeline(timelineIdB);
|
|
5042
|
+
eventsA.sort((a, b) => a.created_at - b.created_at);
|
|
5043
|
+
eventsB.sort((a, b) => a.created_at - b.created_at);
|
|
5044
|
+
const maxLen = Math.max(eventsA.length, eventsB.length);
|
|
5045
|
+
const eventPairs = [];
|
|
5046
|
+
let divergencePoint;
|
|
5047
|
+
for (let i = 0; i < maxLen; i++) {
|
|
5048
|
+
const a = eventsA[i];
|
|
5049
|
+
const b = eventsB[i];
|
|
5050
|
+
if (!a || !b) {
|
|
5051
|
+
if (!divergencePoint) {
|
|
5052
|
+
divergencePoint = a?.event_id ?? b?.event_id;
|
|
5053
|
+
}
|
|
5054
|
+
continue;
|
|
5055
|
+
}
|
|
5056
|
+
const match = a.result_hash === b.result_hash;
|
|
5057
|
+
const resultA = a.metadata?.result ?? {};
|
|
5058
|
+
const resultB = b.metadata?.result ?? {};
|
|
5059
|
+
const differences = match ? [] : diffObjects(resultA, resultB);
|
|
5060
|
+
if (!match && !divergencePoint) {
|
|
5061
|
+
divergencePoint = a.event_id;
|
|
5062
|
+
}
|
|
5063
|
+
eventPairs.push({ event_a: a, event_b: b, match, differences });
|
|
5064
|
+
}
|
|
5065
|
+
return {
|
|
5066
|
+
timeline_a: timelineIdA,
|
|
5067
|
+
timeline_b: timelineIdB,
|
|
5068
|
+
event_pairs: eventPairs,
|
|
5069
|
+
divergence_point: divergencePoint
|
|
5070
|
+
};
|
|
5071
|
+
}
|
|
5072
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5073
|
+
// State snapshot management
|
|
5074
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5075
|
+
async createSnapshot(eventId, stateData) {
|
|
5076
|
+
const event = await this.store.getEvent(eventId);
|
|
5077
|
+
if (!event) {
|
|
5078
|
+
throw new Error(`Event ${eventId} not found`);
|
|
5079
|
+
}
|
|
5080
|
+
const snapshot = {
|
|
5081
|
+
snapshot_id: generateId("snap"),
|
|
5082
|
+
timeline_id: event.timeline_id,
|
|
5083
|
+
event_id: eventId,
|
|
5084
|
+
tps_coordinate: event.tps_coordinate,
|
|
5085
|
+
state_hash: hashPayload2(stateData),
|
|
5086
|
+
state_data: stateData,
|
|
5087
|
+
created_at: Date.now()
|
|
5088
|
+
};
|
|
5089
|
+
await this.store.saveSnapshot(snapshot);
|
|
5090
|
+
return snapshot;
|
|
5091
|
+
}
|
|
5092
|
+
async restoreSnapshot(snapshotId) {
|
|
5093
|
+
const snapshot = await this.store.getSnapshot(snapshotId);
|
|
5094
|
+
if (!snapshot) {
|
|
5095
|
+
throw new Error(`Snapshot ${snapshotId} not found`);
|
|
5096
|
+
}
|
|
5097
|
+
return snapshot;
|
|
5098
|
+
}
|
|
5099
|
+
};
|
|
5100
|
+
}
|
|
5101
|
+
});
|
|
5102
|
+
|
|
5103
|
+
// src/timeline/timeline.store.ts
|
|
5104
|
+
var InMemoryTimelineStore;
|
|
5105
|
+
var init_timeline_store = __esm({
|
|
5106
|
+
"src/timeline/timeline.store.ts"() {
|
|
5107
|
+
InMemoryTimelineStore = class {
|
|
5108
|
+
constructor() {
|
|
5109
|
+
this.events = /* @__PURE__ */ new Map();
|
|
5110
|
+
this.branches = /* @__PURE__ */ new Map();
|
|
5111
|
+
this.snapshots = /* @__PURE__ */ new Map();
|
|
5112
|
+
}
|
|
5113
|
+
async saveEvent(event) {
|
|
5114
|
+
this.events.set(event.event_id, event);
|
|
5115
|
+
}
|
|
5116
|
+
async getEvent(eventId) {
|
|
5117
|
+
return this.events.get(eventId) ?? null;
|
|
5118
|
+
}
|
|
5119
|
+
async getEventsByTimeline(timelineId) {
|
|
5120
|
+
return [...this.events.values()].filter((e) => e.timeline_id === timelineId);
|
|
5121
|
+
}
|
|
5122
|
+
async getEventsByBranch(branchId) {
|
|
5123
|
+
return [...this.events.values()].filter((e) => e.branch_id === branchId);
|
|
5124
|
+
}
|
|
5125
|
+
async saveBranch(branch) {
|
|
5126
|
+
this.branches.set(branch.branch_id, branch);
|
|
5127
|
+
}
|
|
5128
|
+
async getBranch(branchId) {
|
|
5129
|
+
return this.branches.get(branchId) ?? null;
|
|
5130
|
+
}
|
|
5131
|
+
async getBranchesByTimeline(timelineId) {
|
|
5132
|
+
return [...this.branches.values()].filter((b) => b.timeline_id === timelineId);
|
|
5133
|
+
}
|
|
5134
|
+
async saveSnapshot(snapshot) {
|
|
5135
|
+
this.snapshots.set(snapshot.snapshot_id, snapshot);
|
|
5136
|
+
}
|
|
5137
|
+
async getSnapshot(snapshotId) {
|
|
5138
|
+
return this.snapshots.get(snapshotId) ?? null;
|
|
5139
|
+
}
|
|
5140
|
+
async getSnapshotByEvent(eventId) {
|
|
5141
|
+
return [...this.snapshots.values()].find((s) => s.event_id === eventId) ?? null;
|
|
5142
|
+
}
|
|
5143
|
+
};
|
|
5144
|
+
}
|
|
5145
|
+
});
|
|
5146
|
+
|
|
4568
5147
|
// src/utils/axis-tlv-codec.ts
|
|
4569
5148
|
function encodeAxisTlvDto(dtoClass, data) {
|
|
4570
5149
|
const schema = (0, import_dto_schema.extractDtoSchema)(dtoClass);
|
|
@@ -4657,99 +5236,1814 @@ var init_loom_types = __esm({
|
|
|
4657
5236
|
}
|
|
4658
5237
|
});
|
|
4659
5238
|
|
|
4660
|
-
// src/
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
5239
|
+
// src/loom/loom.engine.ts
|
|
5240
|
+
function sha2567(data) {
|
|
5241
|
+
return (0, import_crypto9.createHash)("sha256").update(data).digest("hex");
|
|
5242
|
+
}
|
|
5243
|
+
function hexToUint8(hex) {
|
|
5244
|
+
const bytes2 = new Uint8Array(hex.length / 2);
|
|
5245
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
5246
|
+
bytes2[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
5247
|
+
}
|
|
5248
|
+
return bytes2;
|
|
5249
|
+
}
|
|
5250
|
+
function uint8ToHex(bytes2) {
|
|
5251
|
+
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
5252
|
+
}
|
|
5253
|
+
function b64ToUint8(b64) {
|
|
5254
|
+
const bin = Buffer.from(b64, "base64");
|
|
5255
|
+
return new Uint8Array(bin.buffer, bin.byteOffset, bin.byteLength);
|
|
5256
|
+
}
|
|
5257
|
+
function uint8ToB64(bytes2) {
|
|
5258
|
+
return Buffer.from(bytes2).toString("base64");
|
|
5259
|
+
}
|
|
5260
|
+
function createPresenceChallenge(declaration, ttlMs = DEFAULT_PRESENCE_TTL_MS) {
|
|
5261
|
+
const now = Date.now();
|
|
5262
|
+
const nonce = (0, import_crypto9.randomBytes)(32).toString("hex");
|
|
5263
|
+
const challengeId = sha2567(`${declaration.softid}:${nonce}:${now}`);
|
|
5264
|
+
return {
|
|
5265
|
+
challenge_id: challengeId,
|
|
5266
|
+
nonce,
|
|
5267
|
+
temporal_anchor: now,
|
|
5268
|
+
ttl_ms: ttlMs,
|
|
5269
|
+
expires_at: now + ttlMs
|
|
5270
|
+
};
|
|
5271
|
+
}
|
|
5272
|
+
function presenceSigningData(challenge, deviceMeta) {
|
|
5273
|
+
return JSON.stringify({
|
|
5274
|
+
nonce: challenge.nonce,
|
|
5275
|
+
temporal_anchor: challenge.temporal_anchor,
|
|
5276
|
+
device_meta: deviceMeta ?? null
|
|
5277
|
+
});
|
|
5278
|
+
}
|
|
5279
|
+
function signPresenceChallenge(challenge, privateKeyHex, publicKeyHex, declaration, kid) {
|
|
5280
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
5281
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
5282
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5283
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
5284
|
+
return {
|
|
5285
|
+
challenge_id: challenge.challenge_id,
|
|
5286
|
+
signature: uint8ToHex(signature),
|
|
5287
|
+
public_key: publicKeyHex,
|
|
5288
|
+
kid
|
|
5289
|
+
};
|
|
5290
|
+
}
|
|
5291
|
+
function verifyPresenceProof(challenge, proof, declaration, durationMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
5292
|
+
if (Date.now() > challenge.expires_at) {
|
|
5293
|
+
return { valid: false, error: "Challenge expired", code: "CHALLENGE_EXPIRED" };
|
|
5294
|
+
}
|
|
5295
|
+
if (proof.challenge_id !== challenge.challenge_id) {
|
|
5296
|
+
return { valid: false, error: "Challenge ID mismatch", code: "CHALLENGE_MISMATCH" };
|
|
5297
|
+
}
|
|
5298
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
5299
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
5300
|
+
const sigBytes = hexToUint8(proof.signature);
|
|
5301
|
+
const pubBytes = hexToUint8(proof.public_key);
|
|
5302
|
+
let isValid;
|
|
5303
|
+
try {
|
|
5304
|
+
isValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5305
|
+
} catch {
|
|
5306
|
+
return { valid: false, error: "Signature verification failed", code: "SIG_INVALID" };
|
|
5307
|
+
}
|
|
5308
|
+
if (!isValid) {
|
|
5309
|
+
return { valid: false, error: "Invalid signature", code: "SIG_INVALID" };
|
|
5310
|
+
}
|
|
5311
|
+
const now = Date.now();
|
|
5312
|
+
const presenceId = sha2567(
|
|
5313
|
+
`${proof.public_key}:${challenge.nonce}:${challenge.temporal_anchor}`
|
|
5314
|
+
);
|
|
5315
|
+
const anchorReflection = sha2567(
|
|
5316
|
+
`ar:openlogs:loom:${proof.public_key}`
|
|
5317
|
+
);
|
|
5318
|
+
const receipt = {
|
|
5319
|
+
presence_id: presenceId,
|
|
5320
|
+
softid: declaration.softid,
|
|
5321
|
+
anchor_reflection: anchorReflection,
|
|
5322
|
+
scope: {
|
|
5323
|
+
device_fingerprint: declaration.device_meta?.fingerprint
|
|
5324
|
+
},
|
|
5325
|
+
issued_at: now,
|
|
5326
|
+
expires_at: now + durationMs
|
|
5327
|
+
};
|
|
5328
|
+
return { valid: true, presence: receipt };
|
|
5329
|
+
}
|
|
5330
|
+
function getPresenceStatus(receipt) {
|
|
5331
|
+
const now = Date.now();
|
|
5332
|
+
if (now > receipt.expires_at) return "expired";
|
|
5333
|
+
return "active";
|
|
5334
|
+
}
|
|
5335
|
+
function renewPresence(receipt, extensionMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
5336
|
+
const now = Date.now();
|
|
5337
|
+
return {
|
|
5338
|
+
...receipt,
|
|
5339
|
+
renewed_at: now,
|
|
5340
|
+
expires_at: now + extensionMs
|
|
5341
|
+
};
|
|
5342
|
+
}
|
|
5343
|
+
function createWrit(body, meta, thread, privateKeyHex, kid) {
|
|
5344
|
+
const head = { tid: thread.tid, seq: thread.seq };
|
|
5345
|
+
const writMeta = { ...meta, prev: thread.prevHash };
|
|
5346
|
+
const unsigned = { head, body, meta: writMeta };
|
|
5347
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
5348
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5349
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5350
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
5351
|
+
const sig = {
|
|
5352
|
+
alg: "ed25519",
|
|
5353
|
+
value: uint8ToB64(signature),
|
|
5354
|
+
kid
|
|
5355
|
+
};
|
|
5356
|
+
return { head, body, meta: writMeta, sig };
|
|
5357
|
+
}
|
|
5358
|
+
function validateWrit(writ, publicKeyHex, threadState, grants) {
|
|
5359
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
5360
|
+
if (now < writ.meta.iat) {
|
|
5361
|
+
return {
|
|
5362
|
+
valid: false,
|
|
5363
|
+
error: "Writ not yet valid (iat in future)",
|
|
5364
|
+
code: "TEMPORAL_NOT_YET",
|
|
5365
|
+
gate_failed: "temporal"
|
|
5366
|
+
};
|
|
5367
|
+
}
|
|
5368
|
+
if (now > writ.meta.exp) {
|
|
5369
|
+
return {
|
|
5370
|
+
valid: false,
|
|
5371
|
+
error: "Writ expired",
|
|
5372
|
+
code: "TEMPORAL_EXPIRED",
|
|
5373
|
+
gate_failed: "temporal"
|
|
5374
|
+
};
|
|
5375
|
+
}
|
|
5376
|
+
if (threadState) {
|
|
5377
|
+
if (writ.head.tid !== threadState.thread_id) {
|
|
5378
|
+
return {
|
|
5379
|
+
valid: false,
|
|
5380
|
+
error: "Thread ID mismatch",
|
|
5381
|
+
code: "CAUSAL_TID",
|
|
5382
|
+
gate_failed: "causal"
|
|
5383
|
+
};
|
|
5384
|
+
}
|
|
5385
|
+
if (writ.head.seq !== threadState.sequence + 1) {
|
|
5386
|
+
return {
|
|
5387
|
+
valid: false,
|
|
5388
|
+
error: `Expected seq ${threadState.sequence + 1}, got ${writ.head.seq}`,
|
|
5389
|
+
code: "CAUSAL_SEQ",
|
|
5390
|
+
gate_failed: "causal"
|
|
5391
|
+
};
|
|
5392
|
+
}
|
|
5393
|
+
if (writ.meta.prev !== threadState.last_receipt_hash) {
|
|
5394
|
+
return {
|
|
5395
|
+
valid: false,
|
|
5396
|
+
error: "Previous receipt hash mismatch",
|
|
5397
|
+
code: "CAUSAL_PREV",
|
|
5398
|
+
gate_failed: "causal"
|
|
5399
|
+
};
|
|
5400
|
+
}
|
|
5401
|
+
} else {
|
|
5402
|
+
if (writ.head.seq !== 1) {
|
|
5403
|
+
return {
|
|
5404
|
+
valid: false,
|
|
5405
|
+
error: "First writ in thread must have seq=1",
|
|
5406
|
+
code: "CAUSAL_FIRST_SEQ",
|
|
5407
|
+
gate_failed: "causal"
|
|
5408
|
+
};
|
|
5409
|
+
}
|
|
5410
|
+
if (writ.meta.prev !== "") {
|
|
5411
|
+
return {
|
|
5412
|
+
valid: false,
|
|
5413
|
+
error: "First writ must have empty prev hash",
|
|
5414
|
+
code: "CAUSAL_FIRST_PREV",
|
|
5415
|
+
gate_failed: "causal"
|
|
5416
|
+
};
|
|
5417
|
+
}
|
|
5418
|
+
}
|
|
5419
|
+
if (writ.body.law !== "self") {
|
|
5420
|
+
const matchingGrant = grants.find(
|
|
5421
|
+
(g) => g.grant_id === writ.body.law && g.subject === writ.body.who && grantCoversAction(g, writ.body.act, writ.body.res, now)
|
|
5422
|
+
);
|
|
5423
|
+
if (!matchingGrant) {
|
|
5424
|
+
return {
|
|
5425
|
+
valid: false,
|
|
5426
|
+
error: `No valid grant found for law=${writ.body.law}`,
|
|
5427
|
+
code: "LEGAL_NO_GRANT",
|
|
5428
|
+
gate_failed: "legal"
|
|
5429
|
+
};
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
const unsigned = {
|
|
5433
|
+
head: writ.head,
|
|
5434
|
+
body: writ.body,
|
|
5435
|
+
meta: writ.meta
|
|
5436
|
+
};
|
|
5437
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
5438
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5439
|
+
const sigBytes = b64ToUint8(writ.sig.value);
|
|
5440
|
+
const pubBytes = hexToUint8(publicKeyHex);
|
|
5441
|
+
let sigValid;
|
|
5442
|
+
try {
|
|
5443
|
+
sigValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5444
|
+
} catch {
|
|
5445
|
+
return {
|
|
5446
|
+
valid: false,
|
|
5447
|
+
error: "Signature verification failed",
|
|
5448
|
+
code: "AUTH_SIG_FAIL",
|
|
5449
|
+
gate_failed: "authentic"
|
|
5450
|
+
};
|
|
5451
|
+
}
|
|
5452
|
+
if (!sigValid) {
|
|
5453
|
+
return {
|
|
5454
|
+
valid: false,
|
|
5455
|
+
error: "Invalid signature",
|
|
5456
|
+
code: "AUTH_SIG_INVALID",
|
|
5457
|
+
gate_failed: "authentic"
|
|
5458
|
+
};
|
|
5459
|
+
}
|
|
5460
|
+
return { valid: true, writ };
|
|
5461
|
+
}
|
|
5462
|
+
function grantCoversAction(grant, action, resource, nowUnix) {
|
|
5463
|
+
if (nowUnix < grant.meta.iat || nowUnix > grant.meta.exp) {
|
|
5464
|
+
return false;
|
|
5465
|
+
}
|
|
5466
|
+
return grant.caps.some(
|
|
5467
|
+
(cap) => matchOec(cap.oec, action) && matchScope(cap.scope, resource)
|
|
5468
|
+
);
|
|
5469
|
+
}
|
|
5470
|
+
function matchOec(pattern, action) {
|
|
5471
|
+
if (pattern === "*") return true;
|
|
5472
|
+
if (pattern === action) return true;
|
|
5473
|
+
if (pattern.endsWith(".*")) {
|
|
5474
|
+
const prefix = pattern.slice(0, -2);
|
|
5475
|
+
return action.startsWith(prefix + ".");
|
|
5476
|
+
}
|
|
5477
|
+
return false;
|
|
5478
|
+
}
|
|
5479
|
+
function matchScope(pattern, resource) {
|
|
5480
|
+
if (pattern === "*") return true;
|
|
5481
|
+
if (pattern === resource) return true;
|
|
5482
|
+
if (pattern.includes("*")) {
|
|
5483
|
+
const regex = new RegExp(
|
|
5484
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*/g, "[^:]*") + "$"
|
|
5485
|
+
);
|
|
5486
|
+
return regex.test(resource);
|
|
5487
|
+
}
|
|
5488
|
+
return false;
|
|
5489
|
+
}
|
|
5490
|
+
function getGrantStatus(grant, revocations) {
|
|
5491
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
5492
|
+
const revoked = revocations.find(
|
|
5493
|
+
(r) => r.target_type === "grant" && r.target_id === grant.grant_id
|
|
5494
|
+
);
|
|
5495
|
+
if (revoked && revoked.effective_at <= now * 1e3) {
|
|
5496
|
+
return "revoked";
|
|
5497
|
+
}
|
|
5498
|
+
if (now > grant.meta.exp) return "expired";
|
|
5499
|
+
return "active";
|
|
5500
|
+
}
|
|
5501
|
+
function validateGrant(grant, issuerPublicKeyHex) {
|
|
5502
|
+
const unsigned = {
|
|
5503
|
+
grant_id: grant.grant_id,
|
|
5504
|
+
issuer: grant.issuer,
|
|
5505
|
+
subject: grant.subject,
|
|
5506
|
+
grant_type: grant.grant_type,
|
|
5507
|
+
caps: grant.caps,
|
|
5508
|
+
meta: grant.meta
|
|
5509
|
+
};
|
|
5510
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
5511
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5512
|
+
const sigBytes = b64ToUint8(grant.sig.value);
|
|
5513
|
+
const pubBytes = hexToUint8(issuerPublicKeyHex);
|
|
5514
|
+
let valid;
|
|
5515
|
+
try {
|
|
5516
|
+
valid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5517
|
+
} catch {
|
|
5518
|
+
return { valid: false, error: "Grant signature verification failed", code: "GRANT_SIG_FAIL" };
|
|
5519
|
+
}
|
|
5520
|
+
if (!valid) {
|
|
5521
|
+
return { valid: false, error: "Invalid grant signature", code: "GRANT_SIG_INVALID" };
|
|
5522
|
+
}
|
|
5523
|
+
return { valid: true, grant };
|
|
5524
|
+
}
|
|
5525
|
+
function createGrant(grantId, issuer, subject, grantType, caps, meta, privateKeyHex, kid) {
|
|
5526
|
+
const unsigned = {
|
|
5527
|
+
grant_id: grantId,
|
|
5528
|
+
issuer,
|
|
5529
|
+
subject,
|
|
5530
|
+
grant_type: grantType,
|
|
5531
|
+
caps,
|
|
5532
|
+
meta
|
|
5533
|
+
};
|
|
5534
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
5535
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5536
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5537
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
5538
|
+
return {
|
|
5539
|
+
...unsigned,
|
|
5540
|
+
sig: {
|
|
5541
|
+
alg: "ed25519",
|
|
5542
|
+
value: uint8ToB64(signature),
|
|
5543
|
+
kid
|
|
5544
|
+
}
|
|
5545
|
+
};
|
|
5546
|
+
}
|
|
5547
|
+
function createReceipt(writ, effect, prevReceipt, metadata) {
|
|
5548
|
+
const now = Date.now();
|
|
5549
|
+
const sequence = prevReceipt ? prevReceipt.sequence + 1 : 1;
|
|
5550
|
+
const prevHash = prevReceipt?.hash ?? null;
|
|
5551
|
+
const writHash = sha2567(canonicalizeWrit({
|
|
5552
|
+
head: writ.head,
|
|
5553
|
+
body: writ.body,
|
|
5554
|
+
meta: writ.meta
|
|
5555
|
+
}));
|
|
5556
|
+
const hashInput = [
|
|
5557
|
+
prevHash ?? "",
|
|
5558
|
+
writHash,
|
|
5559
|
+
writ.head.tid,
|
|
5560
|
+
String(sequence),
|
|
5561
|
+
effect,
|
|
5562
|
+
String(now)
|
|
5563
|
+
].join(":");
|
|
5564
|
+
const receiptHash = sha2567(hashInput);
|
|
5565
|
+
const receiptId = sha2567(`receipt:${receiptHash}:${now}`);
|
|
5566
|
+
return {
|
|
5567
|
+
receipt_id: receiptId,
|
|
5568
|
+
writ_hash: writHash,
|
|
5569
|
+
thread_id: writ.head.tid,
|
|
5570
|
+
sequence,
|
|
5571
|
+
effect,
|
|
5572
|
+
hash: receiptHash,
|
|
5573
|
+
prev_hash: prevHash,
|
|
5574
|
+
executed_at: now,
|
|
5575
|
+
metadata
|
|
5576
|
+
};
|
|
5577
|
+
}
|
|
5578
|
+
function verifyReceiptChain(receipts) {
|
|
5579
|
+
if (receipts.length === 0) return { valid: true };
|
|
5580
|
+
const sorted = [...receipts].sort((a, b) => a.sequence - b.sequence);
|
|
5581
|
+
if (sorted[0].prev_hash !== null) {
|
|
5582
|
+
return {
|
|
5583
|
+
valid: false,
|
|
5584
|
+
brokenAt: 0,
|
|
5585
|
+
error: "First receipt must have null prev_hash"
|
|
5586
|
+
};
|
|
5587
|
+
}
|
|
5588
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
5589
|
+
if (sorted[i].prev_hash !== sorted[i - 1].hash) {
|
|
5590
|
+
return {
|
|
5591
|
+
valid: false,
|
|
5592
|
+
brokenAt: i,
|
|
5593
|
+
error: `Receipt ${i} prev_hash does not match receipt ${i - 1} hash`
|
|
5594
|
+
};
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5597
|
+
return { valid: true };
|
|
5598
|
+
}
|
|
5599
|
+
function updateThreadState(receipt, softid) {
|
|
5600
|
+
return {
|
|
5601
|
+
thread_id: receipt.thread_id,
|
|
5602
|
+
softid,
|
|
5603
|
+
last_receipt_hash: receipt.hash,
|
|
5604
|
+
sequence: receipt.sequence,
|
|
5605
|
+
updated_at: receipt.executed_at
|
|
5606
|
+
};
|
|
5607
|
+
}
|
|
5608
|
+
function createRevocation(targetType, targetId, issuerSoftid, privateKeyHex, reason) {
|
|
5609
|
+
const now = Date.now();
|
|
5610
|
+
const revocationId = sha2567(`revoke:${targetType}:${targetId}:${now}`);
|
|
5611
|
+
const payload = JSON.stringify({
|
|
5612
|
+
revocation_id: revocationId,
|
|
5613
|
+
target_type: targetType,
|
|
5614
|
+
target_id: targetId,
|
|
5615
|
+
issuer_softid: issuerSoftid,
|
|
5616
|
+
effective_at: now,
|
|
5617
|
+
reason: reason ?? null
|
|
5618
|
+
});
|
|
5619
|
+
const msgBytes = new TextEncoder().encode(payload);
|
|
5620
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5621
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
5622
|
+
return {
|
|
5623
|
+
revocation_id: revocationId,
|
|
5624
|
+
target_type: targetType,
|
|
5625
|
+
target_id: targetId,
|
|
5626
|
+
issuer_softid: issuerSoftid,
|
|
5627
|
+
reason,
|
|
5628
|
+
effective_at: now,
|
|
5629
|
+
sig_value: uint8ToHex(signature)
|
|
5630
|
+
};
|
|
5631
|
+
}
|
|
5632
|
+
function isRevoked(targetType, targetId, revocations) {
|
|
5633
|
+
const now = Date.now();
|
|
5634
|
+
return revocations.some(
|
|
5635
|
+
(r) => r.target_type === targetType && r.target_id === targetId && r.effective_at <= now
|
|
5636
|
+
);
|
|
5637
|
+
}
|
|
5638
|
+
function executeLoomPipeline(writ, publicKeyHex, presence, threadState, grants, revocations, prevReceipt) {
|
|
5639
|
+
const presenceStatus = getPresenceStatus(presence);
|
|
5640
|
+
if (presenceStatus !== "active") {
|
|
5641
|
+
return { valid: false, error: "Presence not active", code: "PRESENCE_INACTIVE" };
|
|
5642
|
+
}
|
|
5643
|
+
if (isRevoked("presence", presence.presence_id, revocations)) {
|
|
5644
|
+
return { valid: false, error: "Presence revoked", code: "PRESENCE_REVOKED" };
|
|
5645
|
+
}
|
|
5646
|
+
const activeGrants = grants.filter(
|
|
5647
|
+
(g) => getGrantStatus(g, revocations) === "active"
|
|
5648
|
+
);
|
|
5649
|
+
const writResult = validateWrit(writ, publicKeyHex, threadState, activeGrants);
|
|
5650
|
+
if (!writResult.valid) {
|
|
5651
|
+
return { valid: false, error: writResult.error, code: writResult.code };
|
|
5652
|
+
}
|
|
5653
|
+
const receipt = createReceipt(writ, "ALLOW", prevReceipt);
|
|
5654
|
+
const newThreadState = updateThreadState(receipt, writ.body.who);
|
|
5655
|
+
return {
|
|
5656
|
+
receipt,
|
|
5657
|
+
threadState: newThreadState,
|
|
5658
|
+
writValidation: writResult
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
var import_crypto9, import_tweetnacl, DEFAULT_PRESENCE_TTL_MS, DEFAULT_PRESENCE_DURATION_MS;
|
|
5662
|
+
var init_loom_engine = __esm({
|
|
5663
|
+
"src/loom/loom.engine.ts"() {
|
|
5664
|
+
import_crypto9 = require("crypto");
|
|
5665
|
+
import_tweetnacl = require("tweetnacl");
|
|
5666
|
+
init_loom_types();
|
|
5667
|
+
DEFAULT_PRESENCE_TTL_MS = 5e3;
|
|
5668
|
+
DEFAULT_PRESENCE_DURATION_MS = 30 * 60 * 1e3;
|
|
5669
|
+
}
|
|
5670
|
+
});
|
|
5671
|
+
|
|
5672
|
+
// src/idel/idel.compiler.ts
|
|
5673
|
+
function validateType(value, expectedType) {
|
|
5674
|
+
switch (expectedType) {
|
|
5675
|
+
case "string":
|
|
5676
|
+
return typeof value === "string";
|
|
5677
|
+
case "number":
|
|
5678
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
5679
|
+
case "boolean":
|
|
5680
|
+
return typeof value === "boolean";
|
|
5681
|
+
case "object":
|
|
5682
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5683
|
+
case "array":
|
|
5684
|
+
return Array.isArray(value);
|
|
5685
|
+
default:
|
|
5686
|
+
return true;
|
|
5687
|
+
}
|
|
5688
|
+
}
|
|
5689
|
+
function assessRisk(schema, proposal, constraints) {
|
|
5690
|
+
const factors = [];
|
|
5691
|
+
let score = 0;
|
|
5692
|
+
const baseRiskMap = {
|
|
5693
|
+
none: 0,
|
|
5694
|
+
low: 0.1,
|
|
5695
|
+
medium: 0.3,
|
|
5696
|
+
high: 0.6,
|
|
5697
|
+
critical: 0.9
|
|
5698
|
+
};
|
|
5699
|
+
score = baseRiskMap[schema.risk_level] ?? 0;
|
|
5700
|
+
if (schema.risk_level !== "none") {
|
|
5701
|
+
factors.push(`Base risk: ${schema.risk_level}`);
|
|
5702
|
+
}
|
|
5703
|
+
if (schema.has_side_effects) {
|
|
5704
|
+
score += 0.1;
|
|
5705
|
+
factors.push("Has side effects");
|
|
5706
|
+
}
|
|
5707
|
+
if (!schema.reversible) {
|
|
5708
|
+
score += 0.1;
|
|
5709
|
+
factors.push("Not reversible");
|
|
5710
|
+
}
|
|
5711
|
+
const failed = constraints.filter((c) => !c.satisfied);
|
|
5712
|
+
if (failed.length > 0) {
|
|
5713
|
+
score += 0.05 * failed.length;
|
|
5714
|
+
factors.push(`${failed.length} unsatisfied constraint(s)`);
|
|
5715
|
+
}
|
|
5716
|
+
score = Math.min(score, 1);
|
|
5717
|
+
let level;
|
|
5718
|
+
if (score <= 0) level = "none";
|
|
5719
|
+
else if (score <= 0.2) level = "low";
|
|
5720
|
+
else if (score <= 0.5) level = "medium";
|
|
5721
|
+
else if (score <= 0.8) level = "high";
|
|
5722
|
+
else level = "critical";
|
|
5723
|
+
return { level, score, factors };
|
|
5724
|
+
}
|
|
5725
|
+
var IdelSchemaRegistry, IdelCompiler;
|
|
5726
|
+
var init_idel_compiler = __esm({
|
|
5727
|
+
"src/idel/idel.compiler.ts"() {
|
|
5728
|
+
IdelSchemaRegistry = class {
|
|
5729
|
+
constructor() {
|
|
5730
|
+
this.schemas = /* @__PURE__ */ new Map();
|
|
5731
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
5732
|
+
}
|
|
5733
|
+
register(schema) {
|
|
5734
|
+
this.schemas.set(schema.intent, schema);
|
|
5735
|
+
}
|
|
5736
|
+
registerAlias(alias, intent) {
|
|
5737
|
+
this.aliases.set(alias.toLowerCase(), intent);
|
|
5738
|
+
}
|
|
5739
|
+
get(intent) {
|
|
5740
|
+
return this.schemas.get(intent);
|
|
5741
|
+
}
|
|
5742
|
+
resolve(raw) {
|
|
5743
|
+
const exact = this.schemas.get(raw);
|
|
5744
|
+
if (exact) return exact;
|
|
5745
|
+
const aliased = this.aliases.get(raw.toLowerCase());
|
|
5746
|
+
if (aliased) return this.schemas.get(aliased);
|
|
5747
|
+
const candidates = [...this.schemas.keys()].filter(
|
|
5748
|
+
(k) => k.startsWith(raw + ".") || k.toLowerCase().includes(raw.toLowerCase())
|
|
5749
|
+
);
|
|
5750
|
+
if (candidates.length === 1) {
|
|
5751
|
+
return this.schemas.get(candidates[0]);
|
|
5752
|
+
}
|
|
5753
|
+
return void 0;
|
|
5754
|
+
}
|
|
5755
|
+
/**
|
|
5756
|
+
* Find all schemas that partially match the raw input.
|
|
5757
|
+
* Returns scored candidates for ambiguity resolution.
|
|
5758
|
+
*/
|
|
5759
|
+
findCandidates(raw) {
|
|
5760
|
+
const normalized = raw.toLowerCase().trim();
|
|
5761
|
+
const results = [];
|
|
5762
|
+
for (const [key, schema] of this.schemas) {
|
|
5763
|
+
let score = 0;
|
|
5764
|
+
if (key === raw) {
|
|
5765
|
+
score = 1;
|
|
5766
|
+
} else if (key.toLowerCase() === normalized) {
|
|
5767
|
+
score = 0.95;
|
|
5768
|
+
} else if (this.aliases.get(normalized) === key) {
|
|
5769
|
+
score = 0.9;
|
|
5770
|
+
} else if (key.toLowerCase().startsWith(normalized)) {
|
|
5771
|
+
score = 0.7;
|
|
5772
|
+
} else if (key.toLowerCase().includes(normalized)) {
|
|
5773
|
+
score = 0.5;
|
|
5774
|
+
} else if (schema.tags?.some((t) => t.toLowerCase().includes(normalized))) {
|
|
5775
|
+
score = 0.4;
|
|
5776
|
+
} else if (schema.description.toLowerCase().includes(normalized)) {
|
|
5777
|
+
score = 0.3;
|
|
5778
|
+
}
|
|
5779
|
+
if (score > 0) {
|
|
5780
|
+
results.push({ schema, score });
|
|
5781
|
+
}
|
|
5782
|
+
}
|
|
5783
|
+
return results.sort((a, b) => b.score - a.score);
|
|
5784
|
+
}
|
|
5785
|
+
list() {
|
|
5786
|
+
return [...this.schemas.values()];
|
|
5787
|
+
}
|
|
5788
|
+
};
|
|
5789
|
+
IdelCompiler = class {
|
|
5790
|
+
constructor(registry) {
|
|
5791
|
+
this.registry = registry;
|
|
5792
|
+
}
|
|
5793
|
+
/**
|
|
5794
|
+
* Compile a raw intent proposal into a validated, executable structure.
|
|
5795
|
+
*/
|
|
5796
|
+
compile(proposal) {
|
|
5797
|
+
const errors = [];
|
|
5798
|
+
const candidates = this.registry.findCandidates(proposal.raw);
|
|
5799
|
+
if (candidates.length === 0) {
|
|
5800
|
+
return {
|
|
5801
|
+
ok: false,
|
|
5802
|
+
errors: [{
|
|
5803
|
+
code: "IDEL_UNKNOWN_INTENT",
|
|
5804
|
+
message: `No intent found matching '${proposal.raw}'`
|
|
5805
|
+
}]
|
|
5806
|
+
};
|
|
5807
|
+
}
|
|
5808
|
+
const best = candidates[0];
|
|
5809
|
+
const schema = best.schema;
|
|
5810
|
+
const alternatives = candidates.slice(1, 4).filter((c) => c.score >= 0.3).map((c) => ({
|
|
5811
|
+
intent: c.schema.intent,
|
|
5812
|
+
confidence: c.score,
|
|
5813
|
+
reason: c.schema.description
|
|
5814
|
+
}));
|
|
5815
|
+
const constraints = [];
|
|
5816
|
+
const clarifications = [];
|
|
5817
|
+
const params = { ...proposal.params };
|
|
5818
|
+
for (const paramSchema of schema.params) {
|
|
5819
|
+
const value = params[paramSchema.name];
|
|
5820
|
+
if (paramSchema.required && value === void 0) {
|
|
5821
|
+
if (paramSchema.default !== void 0) {
|
|
5822
|
+
params[paramSchema.name] = paramSchema.default;
|
|
5823
|
+
constraints.push({
|
|
5824
|
+
kind: "required_param",
|
|
5825
|
+
field: paramSchema.name,
|
|
5826
|
+
description: `Defaulted to ${JSON.stringify(paramSchema.default)}`,
|
|
5827
|
+
satisfied: true,
|
|
5828
|
+
value: paramSchema.default
|
|
5829
|
+
});
|
|
5830
|
+
} else {
|
|
5831
|
+
constraints.push({
|
|
5832
|
+
kind: "required_param",
|
|
5833
|
+
field: paramSchema.name,
|
|
5834
|
+
description: `Required parameter '${paramSchema.name}' is missing`,
|
|
5835
|
+
satisfied: false
|
|
5836
|
+
});
|
|
5837
|
+
clarifications.push({
|
|
5838
|
+
id: `clarify_${paramSchema.name}`,
|
|
5839
|
+
question: paramSchema.description ?? `What is the ${paramSchema.name}?`,
|
|
5840
|
+
field: paramSchema.name,
|
|
5841
|
+
options: paramSchema.enum?.map(String),
|
|
5842
|
+
required: true
|
|
5843
|
+
});
|
|
5844
|
+
}
|
|
5845
|
+
continue;
|
|
5846
|
+
}
|
|
5847
|
+
if (value === void 0) continue;
|
|
5848
|
+
const typeValid = validateType(value, paramSchema.type);
|
|
5849
|
+
constraints.push({
|
|
5850
|
+
kind: "type_check",
|
|
5851
|
+
field: paramSchema.name,
|
|
5852
|
+
description: `Must be ${paramSchema.type}`,
|
|
5853
|
+
satisfied: typeValid,
|
|
5854
|
+
value,
|
|
5855
|
+
expected: paramSchema.type
|
|
5856
|
+
});
|
|
5857
|
+
if (!typeValid) {
|
|
5858
|
+
errors.push({
|
|
5859
|
+
code: "IDEL_TYPE_ERROR",
|
|
5860
|
+
message: `Parameter '${paramSchema.name}' must be ${paramSchema.type}, got ${typeof value}`,
|
|
5861
|
+
field: paramSchema.name
|
|
5862
|
+
});
|
|
5863
|
+
}
|
|
5864
|
+
if (paramSchema.min !== void 0 || paramSchema.max !== void 0) {
|
|
5865
|
+
const numVal = typeof value === "number" ? value : Number(value);
|
|
5866
|
+
const inRange = (paramSchema.min === void 0 || numVal >= paramSchema.min) && (paramSchema.max === void 0 || numVal <= paramSchema.max);
|
|
5867
|
+
constraints.push({
|
|
5868
|
+
kind: "range",
|
|
5869
|
+
field: paramSchema.name,
|
|
5870
|
+
description: `Must be between ${paramSchema.min ?? "-\u221E"} and ${paramSchema.max ?? "\u221E"}`,
|
|
5871
|
+
satisfied: inRange,
|
|
5872
|
+
value: numVal
|
|
5873
|
+
});
|
|
5874
|
+
}
|
|
5875
|
+
if (paramSchema.pattern) {
|
|
5876
|
+
const matches = new RegExp(paramSchema.pattern).test(String(value));
|
|
5877
|
+
constraints.push({
|
|
5878
|
+
kind: "pattern",
|
|
5879
|
+
field: paramSchema.name,
|
|
5880
|
+
description: `Must match ${paramSchema.pattern}`,
|
|
5881
|
+
satisfied: matches,
|
|
5882
|
+
value,
|
|
5883
|
+
expected: paramSchema.pattern
|
|
5884
|
+
});
|
|
5885
|
+
}
|
|
5886
|
+
if (paramSchema.enum) {
|
|
5887
|
+
const inEnum = paramSchema.enum.some(
|
|
5888
|
+
(e) => JSON.stringify(e) === JSON.stringify(value)
|
|
5889
|
+
);
|
|
5890
|
+
constraints.push({
|
|
5891
|
+
kind: "custom",
|
|
5892
|
+
field: paramSchema.name,
|
|
5893
|
+
description: `Must be one of: ${paramSchema.enum.join(", ")}`,
|
|
5894
|
+
satisfied: inEnum,
|
|
5895
|
+
value,
|
|
5896
|
+
expected: paramSchema.enum
|
|
5897
|
+
});
|
|
5898
|
+
}
|
|
5899
|
+
}
|
|
5900
|
+
const risk = assessRisk(schema, proposal, constraints);
|
|
5901
|
+
const unsatisfied = constraints.filter((c) => !c.satisfied);
|
|
5902
|
+
const needsClarification = clarifications.length > 0;
|
|
5903
|
+
let confidence = best.score;
|
|
5904
|
+
if (unsatisfied.length > 0) {
|
|
5905
|
+
confidence *= 1 - unsatisfied.length / Math.max(constraints.length, 1) * 0.5;
|
|
5906
|
+
}
|
|
5907
|
+
if (errors.length > 0) {
|
|
5908
|
+
confidence *= 0.5;
|
|
5909
|
+
}
|
|
5910
|
+
const compiled = {
|
|
5911
|
+
intent: schema.intent,
|
|
5912
|
+
actor_id: proposal.actor_id,
|
|
5913
|
+
target: proposal.target,
|
|
5914
|
+
params,
|
|
5915
|
+
constraints,
|
|
5916
|
+
confidence,
|
|
5917
|
+
alternatives,
|
|
5918
|
+
needs_clarification: needsClarification,
|
|
5919
|
+
clarifications,
|
|
5920
|
+
expected_outcome: schema.description,
|
|
5921
|
+
fallback: schema.related?.[0],
|
|
5922
|
+
risk,
|
|
5923
|
+
metadata: {
|
|
5924
|
+
schema_intent: schema.intent,
|
|
5925
|
+
resolved_from: proposal.raw,
|
|
5926
|
+
has_side_effects: schema.has_side_effects,
|
|
5927
|
+
reversible: schema.reversible
|
|
5928
|
+
}
|
|
5929
|
+
};
|
|
5930
|
+
return {
|
|
5931
|
+
ok: errors.length === 0 && !needsClarification,
|
|
5932
|
+
compiled,
|
|
5933
|
+
errors
|
|
5934
|
+
};
|
|
5935
|
+
}
|
|
5936
|
+
/**
|
|
5937
|
+
* Apply clarification answers and re-compile.
|
|
5938
|
+
*/
|
|
5939
|
+
applyClarifications(compiled, answers) {
|
|
5940
|
+
const proposal = {
|
|
5941
|
+
raw: compiled.intent,
|
|
5942
|
+
actor_id: compiled.actor_id,
|
|
5943
|
+
target: compiled.target,
|
|
5944
|
+
params: { ...compiled.params, ...answers }
|
|
5945
|
+
};
|
|
5946
|
+
return this.compile(proposal);
|
|
5947
|
+
}
|
|
5948
|
+
};
|
|
5949
|
+
}
|
|
5950
|
+
});
|
|
5951
|
+
|
|
5952
|
+
// src/needle/needle.engine.ts
|
|
5953
|
+
function assembleNeedle(params) {
|
|
5954
|
+
return {
|
|
5955
|
+
needle_id: (0, import_crypto10.randomBytes)(16).toString("hex"),
|
|
5956
|
+
phase: "created",
|
|
5957
|
+
tps_coordinate: params.tps_coordinate,
|
|
5958
|
+
intent: params.intent,
|
|
5959
|
+
presence: params.presence,
|
|
5960
|
+
writ: params.writ,
|
|
5961
|
+
grants: params.grants,
|
|
5962
|
+
created_at: Date.now()
|
|
5963
|
+
};
|
|
5964
|
+
}
|
|
5965
|
+
function classifyStitch(observation, verdict) {
|
|
5966
|
+
if (verdict.status === "failed" || verdict.status === "disputed") {
|
|
5967
|
+
return "torn";
|
|
5968
|
+
}
|
|
5969
|
+
if (observation.decision === "DENY") {
|
|
5970
|
+
return "silent";
|
|
5971
|
+
}
|
|
5972
|
+
if (verdict.isDeed) {
|
|
5973
|
+
return "deed";
|
|
5974
|
+
}
|
|
5975
|
+
return "silent";
|
|
5976
|
+
}
|
|
5977
|
+
function formStitch(needle, observation, verdict, receipt) {
|
|
5978
|
+
return {
|
|
5979
|
+
stitch_id: needle.needle_id,
|
|
5980
|
+
kind: classifyStitch(observation, verdict),
|
|
5981
|
+
intent: needle.intent.intent,
|
|
5982
|
+
actor_id: needle.intent.actor_id,
|
|
5983
|
+
tps_coordinate: needle.tps_coordinate,
|
|
5984
|
+
observation,
|
|
5985
|
+
verdict,
|
|
5986
|
+
receipt,
|
|
5987
|
+
thread_id: receipt.thread_id,
|
|
5988
|
+
sequence: receipt.sequence,
|
|
5989
|
+
stitched_at: Date.now()
|
|
5990
|
+
};
|
|
5991
|
+
}
|
|
5992
|
+
async function runNeedlePipeline(needle, config, threadState, prevReceipt, expectedOutcome) {
|
|
5993
|
+
const obs = createObservation("http");
|
|
5994
|
+
obs.intent = needle.intent.intent;
|
|
5995
|
+
obs.actorId = needle.intent.actor_id;
|
|
5996
|
+
needle.phase = "validated";
|
|
5997
|
+
let stage = startStage(obs, "loom.validate");
|
|
5998
|
+
const validation = validateWrit(
|
|
5999
|
+
needle.writ,
|
|
6000
|
+
config.public_key,
|
|
6001
|
+
threadState,
|
|
6002
|
+
needle.grants
|
|
6003
|
+
);
|
|
6004
|
+
if (!validation.valid) {
|
|
6005
|
+
endStage(stage, "fail", validation.error);
|
|
6006
|
+
return failNeedle(needle, obs, "validated", "LOOM_VALIDATION_FAILED", validation.error ?? "Writ validation failed");
|
|
6007
|
+
}
|
|
6008
|
+
endStage(stage, "ok");
|
|
6009
|
+
if (config.sensors && config.sensors.length > 0) {
|
|
6010
|
+
stage = startStage(obs, "sensors.evaluate");
|
|
6011
|
+
const sensorInput = {
|
|
6012
|
+
intent: needle.intent.intent,
|
|
6013
|
+
actorId: needle.intent.actor_id,
|
|
6014
|
+
metadata: {
|
|
6015
|
+
observation: obs,
|
|
6016
|
+
needle_id: needle.needle_id,
|
|
6017
|
+
tps_coordinate: needle.tps_coordinate,
|
|
6018
|
+
writ: needle.writ,
|
|
6019
|
+
grants: needle.grants,
|
|
6020
|
+
params: needle.intent.params
|
|
6021
|
+
}
|
|
6022
|
+
};
|
|
6023
|
+
for (const sensor of config.sensors) {
|
|
6024
|
+
if (sensor.supports && !sensor.supports(sensorInput)) continue;
|
|
6025
|
+
const t0 = Date.now();
|
|
6026
|
+
let decision;
|
|
6027
|
+
try {
|
|
6028
|
+
const rawDecision = await sensor.run(sensorInput);
|
|
6029
|
+
decision = normalizeSensorDecision(rawDecision);
|
|
6030
|
+
} catch (err) {
|
|
6031
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6032
|
+
recordSensor(obs, sensor.name, false, 100, Date.now() - t0, [`sensor_error:${msg}`]);
|
|
6033
|
+
endStage(stage, "fail", `Sensor ${sensor.name} threw: ${msg}`);
|
|
6034
|
+
return failNeedle(needle, obs, "validated", "SENSOR_ERROR", `Sensor ${sensor.name} failed: ${msg}`);
|
|
6035
|
+
}
|
|
6036
|
+
recordSensor(obs, sensor.name, decision.allow, decision.riskScore, Date.now() - t0, decision.reasons);
|
|
6037
|
+
if (!decision.allow) {
|
|
6038
|
+
endStage(stage, "fail", `Sensor ${sensor.name} denied`);
|
|
6039
|
+
return failNeedle(needle, obs, "validated", "SENSOR_DENY", decision.reasons[0] ?? `Denied by ${sensor.name}`);
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
endStage(stage, "ok");
|
|
6043
|
+
}
|
|
6044
|
+
needle.phase = "executing";
|
|
6045
|
+
stage = startStage(obs, "handler.execute");
|
|
6046
|
+
const handler = config.handlers.get(needle.intent.intent);
|
|
6047
|
+
if (!handler) {
|
|
6048
|
+
endStage(stage, "fail", `No handler for intent '${needle.intent.intent}'`);
|
|
6049
|
+
return failNeedle(needle, obs, "executing", "NO_HANDLER", `No handler registered for intent '${needle.intent.intent}'`);
|
|
6050
|
+
}
|
|
6051
|
+
const handlerCtx = {
|
|
6052
|
+
needle_id: needle.needle_id,
|
|
6053
|
+
actor_id: needle.intent.actor_id,
|
|
6054
|
+
presence_id: needle.presence.presence_id,
|
|
6055
|
+
writ: needle.writ,
|
|
6056
|
+
grants: needle.grants,
|
|
6057
|
+
tps_coordinate: needle.tps_coordinate
|
|
6058
|
+
};
|
|
6059
|
+
let handlerResult;
|
|
6060
|
+
try {
|
|
6061
|
+
handlerResult = await handler(needle.intent, handlerCtx);
|
|
6062
|
+
} catch (err) {
|
|
6063
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6064
|
+
endStage(stage, "fail", msg);
|
|
6065
|
+
return failNeedle(needle, obs, "executing", "HANDLER_ERROR", msg);
|
|
6066
|
+
}
|
|
6067
|
+
if (!handlerResult.ok) {
|
|
6068
|
+
endStage(stage, "fail", handlerResult.effect);
|
|
6069
|
+
obs.decision = "DENY";
|
|
6070
|
+
obs.resultCode = handlerResult.effect;
|
|
6071
|
+
obs.statusCode = handlerResult.status_code ?? 400;
|
|
6072
|
+
} else {
|
|
6073
|
+
endStage(stage, "ok");
|
|
6074
|
+
obs.decision = "ALLOW";
|
|
6075
|
+
obs.resultCode = handlerResult.effect;
|
|
6076
|
+
obs.statusCode = handlerResult.status_code ?? 200;
|
|
6077
|
+
}
|
|
6078
|
+
if (handlerResult.data) {
|
|
6079
|
+
obs.facts = { ...obs.facts, ...handlerResult.data };
|
|
6080
|
+
}
|
|
6081
|
+
needle.phase = "observed";
|
|
6082
|
+
finalizeObservation(obs, obs.decision ?? "DENY", obs.statusCode ?? 500, obs.resultCode);
|
|
6083
|
+
needle.observation = obs;
|
|
6084
|
+
const verdict = scoreTruth(obs, expectedOutcome);
|
|
6085
|
+
needle.verdict = verdict;
|
|
6086
|
+
needle.phase = "stitched";
|
|
6087
|
+
stage = startStage(obs, "stitch.form");
|
|
6088
|
+
const receipt = createReceipt(
|
|
6089
|
+
needle.writ,
|
|
6090
|
+
obs.decision ?? "DENY",
|
|
6091
|
+
prevReceipt
|
|
6092
|
+
);
|
|
6093
|
+
needle.receipt = receipt;
|
|
6094
|
+
const newThreadState = updateThreadState(
|
|
6095
|
+
receipt,
|
|
6096
|
+
needle.intent.actor_id
|
|
6097
|
+
);
|
|
6098
|
+
const stitch = formStitch(needle, obs, verdict, receipt);
|
|
6099
|
+
needle.completed_at = Date.now();
|
|
6100
|
+
endStage(stage, "ok");
|
|
6101
|
+
return {
|
|
6102
|
+
ok: handlerResult.ok,
|
|
6103
|
+
needle,
|
|
6104
|
+
stitch,
|
|
6105
|
+
thread_state: newThreadState
|
|
6106
|
+
};
|
|
6107
|
+
}
|
|
6108
|
+
function failNeedle(needle, obs, phase, code, message) {
|
|
6109
|
+
needle.phase = "failed";
|
|
6110
|
+
needle.error = { phase, code, message };
|
|
6111
|
+
needle.completed_at = Date.now();
|
|
6112
|
+
obs.decision = obs.decision ?? "DENY";
|
|
6113
|
+
obs.statusCode = obs.statusCode ?? 500;
|
|
6114
|
+
finalizeObservation(obs, obs.decision, obs.statusCode, obs.resultCode);
|
|
6115
|
+
needle.observation = obs;
|
|
6116
|
+
const verdict = scoreTruth(obs);
|
|
6117
|
+
needle.verdict = verdict;
|
|
6118
|
+
return {
|
|
6119
|
+
ok: false,
|
|
6120
|
+
needle
|
|
6121
|
+
};
|
|
6122
|
+
}
|
|
6123
|
+
var import_crypto10;
|
|
6124
|
+
var init_needle_engine = __esm({
|
|
6125
|
+
"src/needle/needle.engine.ts"() {
|
|
6126
|
+
import_crypto10 = require("crypto");
|
|
6127
|
+
init_axis_observation();
|
|
6128
|
+
init_truth_scoring();
|
|
6129
|
+
init_loom_engine();
|
|
6130
|
+
init_axis_sensor();
|
|
6131
|
+
}
|
|
6132
|
+
});
|
|
6133
|
+
|
|
6134
|
+
// src/needle/knot.engine.ts
|
|
6135
|
+
function openKnot(params) {
|
|
6136
|
+
const isIrreversible = params.type === "irreversible";
|
|
6137
|
+
return {
|
|
6138
|
+
knot_id: `knot_${(0, import_crypto11.randomBytes)(16).toString("hex")}`,
|
|
6139
|
+
type: params.type,
|
|
6140
|
+
status: "open",
|
|
6141
|
+
stitch_ids: [],
|
|
6142
|
+
thread_id: params.thread_id,
|
|
6143
|
+
tps_anchor: params.tps_anchor,
|
|
6144
|
+
irreversible: isIrreversible,
|
|
6145
|
+
capsule_id: params.capsule_id,
|
|
6146
|
+
law_ref: params.law_ref,
|
|
6147
|
+
branch_ids: [],
|
|
6148
|
+
required_count: params.required_count,
|
|
6149
|
+
all_or_nothing: params.all_or_nothing ?? (params.type === "authority" || isIrreversible),
|
|
6150
|
+
actor_id: params.actor_id,
|
|
6151
|
+
created_at: Date.now()
|
|
6152
|
+
};
|
|
6153
|
+
}
|
|
6154
|
+
function addStitchToKnot(knot, stitch) {
|
|
6155
|
+
if (knot.status !== "open") {
|
|
6156
|
+
return `Knot ${knot.knot_id} is ${knot.status}, cannot add stitches`;
|
|
6157
|
+
}
|
|
6158
|
+
if (stitch.thread_id !== knot.thread_id) {
|
|
6159
|
+
return `Stitch thread ${stitch.thread_id} does not match knot thread ${knot.thread_id}`;
|
|
6160
|
+
}
|
|
6161
|
+
if (knot.stitch_ids.includes(stitch.stitch_id)) {
|
|
6162
|
+
return `Stitch ${stitch.stitch_id} already in knot`;
|
|
6163
|
+
}
|
|
6164
|
+
if (knot.type === "authority" && knot.capsule_id) {
|
|
6165
|
+
if (stitch.observation.capsuleId && stitch.observation.capsuleId !== knot.capsule_id) {
|
|
6166
|
+
return `Stitch capsule ${stitch.observation.capsuleId} does not match knot capsule ${knot.capsule_id}`;
|
|
6167
|
+
}
|
|
6168
|
+
}
|
|
6169
|
+
knot.stitch_ids.push(stitch.stitch_id);
|
|
6170
|
+
return null;
|
|
6171
|
+
}
|
|
6172
|
+
function validateKnot(knot, stitches) {
|
|
6173
|
+
const errors = [];
|
|
6174
|
+
const passedIds = [];
|
|
6175
|
+
const failedIds = [];
|
|
6176
|
+
const stitchMap = new Map(stitches.map((s) => [s.stitch_id, s]));
|
|
6177
|
+
for (const sid of knot.stitch_ids) {
|
|
6178
|
+
const stitch = stitchMap.get(sid);
|
|
6179
|
+
if (!stitch) {
|
|
6180
|
+
failedIds.push(sid);
|
|
6181
|
+
errors.push({
|
|
6182
|
+
code: "KNOT_MISSING_STITCH",
|
|
6183
|
+
message: `Stitch ${sid} not found`,
|
|
6184
|
+
stitch_id: sid
|
|
6185
|
+
});
|
|
6186
|
+
continue;
|
|
6187
|
+
}
|
|
6188
|
+
if (stitch.kind === "torn") {
|
|
6189
|
+
failedIds.push(sid);
|
|
6190
|
+
errors.push({
|
|
6191
|
+
code: "KNOT_TORN_STITCH",
|
|
6192
|
+
message: `Stitch ${sid} is torn (failed/disputed)`,
|
|
6193
|
+
stitch_id: sid
|
|
6194
|
+
});
|
|
6195
|
+
continue;
|
|
6196
|
+
}
|
|
6197
|
+
if (knot.type === "irreversible" && stitch.kind !== "deed") {
|
|
6198
|
+
failedIds.push(sid);
|
|
6199
|
+
errors.push({
|
|
6200
|
+
code: "KNOT_REQUIRES_DEED",
|
|
6201
|
+
message: `Irreversible knot requires deed stitch, got '${stitch.kind}'`,
|
|
6202
|
+
stitch_id: sid
|
|
6203
|
+
});
|
|
6204
|
+
continue;
|
|
6205
|
+
}
|
|
6206
|
+
passedIds.push(sid);
|
|
6207
|
+
}
|
|
6208
|
+
if (knot.required_count !== void 0 && knot.stitch_ids.length < knot.required_count) {
|
|
6209
|
+
errors.push({
|
|
6210
|
+
code: "KNOT_INSUFFICIENT_STITCHES",
|
|
6211
|
+
message: `Knot requires ${knot.required_count} stitches, has ${knot.stitch_ids.length}`
|
|
6212
|
+
});
|
|
6213
|
+
}
|
|
6214
|
+
const allPassed = failedIds.length === 0;
|
|
6215
|
+
const canTie = knot.all_or_nothing ? allPassed && (knot.required_count === void 0 || knot.stitch_ids.length >= knot.required_count) : passedIds.length > 0 && (knot.required_count === void 0 || passedIds.length >= knot.required_count);
|
|
6216
|
+
return {
|
|
6217
|
+
valid: allPassed && errors.length === 0,
|
|
6218
|
+
passed_stitch_ids: passedIds,
|
|
6219
|
+
failed_stitch_ids: failedIds,
|
|
6220
|
+
can_tie: canTie,
|
|
6221
|
+
errors
|
|
6222
|
+
};
|
|
6223
|
+
}
|
|
6224
|
+
function tieKnot(knot, stitches) {
|
|
6225
|
+
const validation = validateKnot(knot, stitches);
|
|
6226
|
+
if (!validation.can_tie) {
|
|
6227
|
+
return { ...validation, knot };
|
|
6228
|
+
}
|
|
6229
|
+
const receiptHashes = validation.passed_stitch_ids.map((sid) => stitches.find((s) => s.stitch_id === sid)).sort((a, b) => a.sequence - b.sequence).map((s) => s.receipt.hash);
|
|
6230
|
+
const witnessPayload = receiptHashes.join(":");
|
|
6231
|
+
knot.witness_hash = (0, import_crypto11.createHash)("sha256").update(witnessPayload).digest("hex");
|
|
6232
|
+
knot.status = "tied";
|
|
6233
|
+
knot.tied_at = Date.now();
|
|
6234
|
+
return { ...validation, knot };
|
|
6235
|
+
}
|
|
6236
|
+
function breakKnot(knot, request) {
|
|
6237
|
+
if (knot.status === "broken") {
|
|
6238
|
+
return { ok: false, error: "Knot is already broken" };
|
|
6239
|
+
}
|
|
6240
|
+
if (knot.status === "open") {
|
|
6241
|
+
knot.status = "broken";
|
|
6242
|
+
knot.broken_at = Date.now();
|
|
6243
|
+
knot.break_reason = request.reason;
|
|
6244
|
+
return { ok: true };
|
|
6245
|
+
}
|
|
6246
|
+
if (knot.status === "tied") {
|
|
6247
|
+
if (!request.reason) {
|
|
6248
|
+
return { ok: false, error: "Breaking a tied knot requires a reason" };
|
|
6249
|
+
}
|
|
6250
|
+
if ((knot.irreversible || knot.type === "law") && !request.override_grant_id) {
|
|
6251
|
+
return {
|
|
6252
|
+
ok: false,
|
|
6253
|
+
error: `Breaking ${knot.type} knot requires override_grant_id from higher authority`
|
|
6254
|
+
};
|
|
6255
|
+
}
|
|
6256
|
+
knot.status = "broken";
|
|
6257
|
+
knot.broken_at = Date.now();
|
|
6258
|
+
knot.break_reason = request.reason;
|
|
6259
|
+
return { ok: true };
|
|
6260
|
+
}
|
|
6261
|
+
return { ok: false, error: `Cannot break knot in status '${knot.status}'` };
|
|
6262
|
+
}
|
|
6263
|
+
function forkFromKnot(knot, branchId, decisionStitchId) {
|
|
6264
|
+
if (knot.status !== "tied" && knot.status !== "open") {
|
|
6265
|
+
return { ok: false, error: `Cannot fork from knot in status '${knot.status}'` };
|
|
6266
|
+
}
|
|
6267
|
+
if (decisionStitchId) {
|
|
6268
|
+
if (!knot.stitch_ids.includes(decisionStitchId)) {
|
|
6269
|
+
return { ok: false, error: `Decision stitch ${decisionStitchId} is not part of this knot` };
|
|
6270
|
+
}
|
|
6271
|
+
knot.decision_stitch_id = decisionStitchId;
|
|
6272
|
+
}
|
|
6273
|
+
knot.branch_ids.push(branchId);
|
|
6274
|
+
knot.status = "forked";
|
|
6275
|
+
return { ok: true };
|
|
6276
|
+
}
|
|
6277
|
+
function isKnotOpen(knot) {
|
|
6278
|
+
return knot.status === "open";
|
|
6279
|
+
}
|
|
6280
|
+
function isPointOfNoReturn(knot) {
|
|
6281
|
+
return knot.irreversible && knot.status === "tied";
|
|
6282
|
+
}
|
|
6283
|
+
function findKnotsForStitch(stitchId, knots) {
|
|
6284
|
+
return knots.filter((k) => k.stitch_ids.includes(stitchId));
|
|
6285
|
+
}
|
|
6286
|
+
function getIrreversibleKnots(knots) {
|
|
6287
|
+
return knots.filter((k) => k.irreversible && k.status === "tied");
|
|
6288
|
+
}
|
|
6289
|
+
function getDecisionPoints(knots) {
|
|
6290
|
+
return knots.filter((k) => k.type === "decision" || k.status === "forked");
|
|
6291
|
+
}
|
|
6292
|
+
var import_crypto11;
|
|
6293
|
+
var init_knot_engine = __esm({
|
|
6294
|
+
"src/needle/knot.engine.ts"() {
|
|
6295
|
+
import_crypto11 = require("crypto");
|
|
6296
|
+
}
|
|
6297
|
+
});
|
|
6298
|
+
|
|
6299
|
+
// src/needle/fabric.engine.ts
|
|
6300
|
+
function createFabric() {
|
|
6301
|
+
return {
|
|
6302
|
+
fabric_id: `fab_${(0, import_crypto12.randomBytes)(16).toString("hex")}`,
|
|
6303
|
+
state_hash: hashState(/* @__PURE__ */ new Map()),
|
|
6304
|
+
cells: /* @__PURE__ */ new Map(),
|
|
6305
|
+
thread_ids: [],
|
|
6306
|
+
stitch_count: 0,
|
|
6307
|
+
knot_count: 0,
|
|
6308
|
+
computed_at: Date.now(),
|
|
6309
|
+
version: 0
|
|
6310
|
+
};
|
|
6311
|
+
}
|
|
6312
|
+
function applyStitch(fabric, stitch, effect) {
|
|
6313
|
+
for (const [key, value] of Object.entries(effect.mutations)) {
|
|
6314
|
+
if (value === null) {
|
|
6315
|
+
fabric.cells.delete(key);
|
|
6316
|
+
} else {
|
|
6317
|
+
const existing = fabric.cells.get(key);
|
|
6318
|
+
if (existing?.locked) {
|
|
6319
|
+
continue;
|
|
6320
|
+
}
|
|
6321
|
+
fabric.cells.set(key, {
|
|
6322
|
+
key,
|
|
6323
|
+
value,
|
|
6324
|
+
last_stitch_id: stitch.stitch_id,
|
|
6325
|
+
last_tps: stitch.tps_coordinate,
|
|
6326
|
+
write_count: (existing?.write_count ?? 0) + 1,
|
|
6327
|
+
locked: false
|
|
6328
|
+
});
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6331
|
+
if (!fabric.thread_ids.includes(stitch.thread_id)) {
|
|
6332
|
+
fabric.thread_ids.push(stitch.thread_id);
|
|
6333
|
+
}
|
|
6334
|
+
fabric.stitch_count++;
|
|
6335
|
+
fabric.version++;
|
|
6336
|
+
fabric.projected_at_tps = stitch.tps_coordinate ?? fabric.projected_at_tps;
|
|
6337
|
+
fabric.computed_at = Date.now();
|
|
6338
|
+
fabric.state_hash = hashState(fabric.cells);
|
|
6339
|
+
}
|
|
6340
|
+
function weave(stitches, resolver, knots) {
|
|
6341
|
+
const fabric = createFabric();
|
|
6342
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6343
|
+
for (const stitch of sorted) {
|
|
6344
|
+
if (stitch.kind === "torn") continue;
|
|
6345
|
+
const effect = resolver(stitch);
|
|
6346
|
+
applyStitch(fabric, stitch, effect);
|
|
6347
|
+
}
|
|
6348
|
+
if (knots) {
|
|
6349
|
+
for (const knot of knots) {
|
|
6350
|
+
if (knot.irreversible && knot.status === "tied") {
|
|
6351
|
+
lockCellsByKnot(fabric, knot, stitches, resolver);
|
|
6352
|
+
fabric.knot_count++;
|
|
6353
|
+
}
|
|
6354
|
+
}
|
|
6355
|
+
}
|
|
6356
|
+
return fabric;
|
|
6357
|
+
}
|
|
6358
|
+
function projectAt(stitches, resolver, tpsFilter, knots) {
|
|
6359
|
+
const filtered = stitches.filter((s) => tpsFilter(s.tps_coordinate));
|
|
6360
|
+
return weave(filtered, resolver, knots);
|
|
6361
|
+
}
|
|
6362
|
+
function lockCellsByKnot(fabric, knot, stitches, resolver) {
|
|
6363
|
+
const knotStitchIds = new Set(knot.stitch_ids);
|
|
6364
|
+
const knotStitches = stitches.filter((s) => knotStitchIds.has(s.stitch_id));
|
|
6365
|
+
for (const stitch of knotStitches) {
|
|
6366
|
+
const effect = resolver(stitch);
|
|
6367
|
+
for (const key of Object.keys(effect.mutations)) {
|
|
6368
|
+
const cell = fabric.cells.get(key);
|
|
6369
|
+
if (cell) {
|
|
6370
|
+
cell.locked = true;
|
|
6371
|
+
cell.locked_by_knot = knot.knot_id;
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
function lockCells(fabric, keys, knotId) {
|
|
6377
|
+
for (const key of keys) {
|
|
6378
|
+
const cell = fabric.cells.get(key);
|
|
6379
|
+
if (cell) {
|
|
6380
|
+
cell.locked = true;
|
|
6381
|
+
cell.locked_by_knot = knotId;
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6384
|
+
}
|
|
6385
|
+
function queryFabric(fabric, query) {
|
|
6386
|
+
let results = [...fabric.cells.values()];
|
|
6387
|
+
if (query.keys) {
|
|
6388
|
+
const keySet = new Set(query.keys);
|
|
6389
|
+
results = results.filter((c) => keySet.has(c.key));
|
|
6390
|
+
}
|
|
6391
|
+
if (query.prefix) {
|
|
6392
|
+
const prefix = query.prefix;
|
|
6393
|
+
results = results.filter((c) => c.key.startsWith(prefix));
|
|
6394
|
+
}
|
|
6395
|
+
if (query.locked_only) {
|
|
6396
|
+
results = results.filter((c) => c.locked);
|
|
6397
|
+
}
|
|
6398
|
+
return results;
|
|
6399
|
+
}
|
|
6400
|
+
function getFabricValue(fabric, key) {
|
|
6401
|
+
return fabric.cells.get(key)?.value;
|
|
6402
|
+
}
|
|
6403
|
+
function diffFabrics(a, b) {
|
|
6404
|
+
const entries = [];
|
|
6405
|
+
let added = 0;
|
|
6406
|
+
let modified = 0;
|
|
6407
|
+
let deleted = 0;
|
|
6408
|
+
for (const [key, cellB] of b.cells) {
|
|
6409
|
+
const cellA = a.cells.get(key);
|
|
6410
|
+
if (!cellA) {
|
|
6411
|
+
entries.push({
|
|
6412
|
+
key,
|
|
6413
|
+
kind: "added",
|
|
6414
|
+
after: cellB.value,
|
|
6415
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
6416
|
+
});
|
|
6417
|
+
added++;
|
|
6418
|
+
} else if (JSON.stringify(cellA.value) !== JSON.stringify(cellB.value)) {
|
|
6419
|
+
entries.push({
|
|
6420
|
+
key,
|
|
6421
|
+
kind: "modified",
|
|
6422
|
+
before: cellA.value,
|
|
6423
|
+
after: cellB.value,
|
|
6424
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
6425
|
+
});
|
|
6426
|
+
modified++;
|
|
6427
|
+
}
|
|
6428
|
+
}
|
|
6429
|
+
for (const [key, cellA] of a.cells) {
|
|
6430
|
+
if (!b.cells.has(key)) {
|
|
6431
|
+
entries.push({
|
|
6432
|
+
key,
|
|
6433
|
+
kind: "deleted",
|
|
6434
|
+
before: cellA.value
|
|
6435
|
+
});
|
|
6436
|
+
deleted++;
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
return {
|
|
6440
|
+
from_fabric_id: a.fabric_id,
|
|
6441
|
+
to_fabric_id: b.fabric_id,
|
|
6442
|
+
entries,
|
|
6443
|
+
added_count: added,
|
|
6444
|
+
modified_count: modified,
|
|
6445
|
+
deleted_count: deleted
|
|
6446
|
+
};
|
|
6447
|
+
}
|
|
6448
|
+
function hashState(cells) {
|
|
6449
|
+
const keys = [...cells.keys()].sort();
|
|
6450
|
+
const payload = keys.map((k) => `${k}=${JSON.stringify(cells.get(k).value)}`).join("\n");
|
|
6451
|
+
return (0, import_crypto12.createHash)("sha256").update(payload).digest("hex");
|
|
6452
|
+
}
|
|
6453
|
+
var import_crypto12;
|
|
6454
|
+
var init_fabric_engine = __esm({
|
|
6455
|
+
"src/needle/fabric.engine.ts"() {
|
|
6456
|
+
import_crypto12 = require("crypto");
|
|
6457
|
+
}
|
|
6458
|
+
});
|
|
6459
|
+
|
|
6460
|
+
// src/needle/pattern.engine.ts
|
|
6461
|
+
function detectSequencePatterns(stitches, windowSize, minOccurrences) {
|
|
6462
|
+
if (stitches.length < windowSize || windowSize < 2) return [];
|
|
6463
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6464
|
+
const sequenceCounts = /* @__PURE__ */ new Map();
|
|
6465
|
+
for (let i = 0; i <= sorted.length - windowSize; i++) {
|
|
6466
|
+
const window = sorted.slice(i, i + windowSize);
|
|
6467
|
+
const key = window.map((s) => s.intent).join("\u2192");
|
|
6468
|
+
const ids = window.map((s) => s.stitch_id);
|
|
6469
|
+
const existing = sequenceCounts.get(key);
|
|
6470
|
+
if (existing) {
|
|
6471
|
+
existing.count++;
|
|
6472
|
+
existing.stitch_ids.push(ids);
|
|
6473
|
+
} else {
|
|
6474
|
+
sequenceCounts.set(key, { count: 1, stitch_ids: [ids] });
|
|
6475
|
+
}
|
|
6476
|
+
}
|
|
6477
|
+
const patterns = [];
|
|
6478
|
+
const now = Date.now();
|
|
6479
|
+
for (const [key, data] of sequenceCounts) {
|
|
6480
|
+
if (data.count < minOccurrences) continue;
|
|
6481
|
+
const intents = key.split("\u2192");
|
|
6482
|
+
const confidence = Math.min(data.count / (minOccurrences * 2), 1);
|
|
6483
|
+
patterns.push({
|
|
6484
|
+
pattern_id: `pat_seq_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
6485
|
+
kind: "sequence",
|
|
6486
|
+
name: `Sequence: ${intents.join(" \u2192 ")}`,
|
|
6487
|
+
signature: {
|
|
6488
|
+
intent_sequence: intents,
|
|
6489
|
+
min_length: windowSize,
|
|
6490
|
+
max_length: windowSize
|
|
6491
|
+
},
|
|
6492
|
+
confidence,
|
|
6493
|
+
occurrence_count: data.count,
|
|
6494
|
+
first_seen_at: now,
|
|
6495
|
+
last_seen_at: now,
|
|
6496
|
+
seen_in_threads: [...new Set(
|
|
6497
|
+
data.stitch_ids.flatMap(
|
|
6498
|
+
(ids) => ids.map((id) => sorted.find((s) => s.stitch_id === id)?.thread_id).filter(Boolean)
|
|
6499
|
+
)
|
|
6500
|
+
)],
|
|
6501
|
+
classification: "unclassified"
|
|
6502
|
+
});
|
|
6503
|
+
}
|
|
6504
|
+
return patterns;
|
|
6505
|
+
}
|
|
6506
|
+
function detectKnotPatterns(knots, minOccurrences) {
|
|
6507
|
+
const groups = /* @__PURE__ */ new Map();
|
|
6508
|
+
for (const knot of knots) {
|
|
6509
|
+
if (knot.status !== "tied") continue;
|
|
6510
|
+
const key = `${knot.type}:${knot.stitch_ids.length}`;
|
|
6511
|
+
const group = groups.get(key) ?? [];
|
|
6512
|
+
group.push(knot);
|
|
6513
|
+
groups.set(key, group);
|
|
6514
|
+
}
|
|
6515
|
+
const patterns = [];
|
|
6516
|
+
const now = Date.now();
|
|
6517
|
+
for (const [key, group] of groups) {
|
|
6518
|
+
if (group.length < minOccurrences) continue;
|
|
6519
|
+
const [type, sizeStr] = key.split(":");
|
|
6520
|
+
const size = parseInt(sizeStr, 10);
|
|
6521
|
+
const confidence = Math.min(group.length / (minOccurrences * 2), 1);
|
|
6522
|
+
patterns.push({
|
|
6523
|
+
pattern_id: `pat_knot_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
6524
|
+
kind: "knot",
|
|
6525
|
+
name: `Knot: ${type} (${size} stitches)`,
|
|
6526
|
+
signature: {
|
|
6527
|
+
knot_type: type,
|
|
6528
|
+
knot_size: size
|
|
6529
|
+
},
|
|
6530
|
+
confidence,
|
|
6531
|
+
occurrence_count: group.length,
|
|
6532
|
+
first_seen_at: now,
|
|
6533
|
+
last_seen_at: now,
|
|
6534
|
+
seen_in_threads: [...new Set(group.map((k) => k.thread_id))],
|
|
6535
|
+
classification: "unclassified"
|
|
6536
|
+
});
|
|
6537
|
+
}
|
|
6538
|
+
return patterns;
|
|
6539
|
+
}
|
|
6540
|
+
function matchPatterns(stitches, patterns) {
|
|
6541
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6542
|
+
const matches = [];
|
|
6543
|
+
const now = Date.now();
|
|
6544
|
+
for (const pattern of patterns) {
|
|
6545
|
+
if (pattern.kind === "sequence" && pattern.signature.intent_sequence) {
|
|
6546
|
+
const seq = pattern.signature.intent_sequence;
|
|
6547
|
+
const seqLen = seq.length;
|
|
6548
|
+
for (let i = 0; i <= sorted.length - seqLen; i++) {
|
|
6549
|
+
const window = sorted.slice(i, i + seqLen);
|
|
6550
|
+
const windowIntents = window.map((s) => s.intent);
|
|
6551
|
+
if (windowIntents.every((intent, idx) => intent === seq[idx])) {
|
|
6552
|
+
matches.push({
|
|
6553
|
+
pattern_id: pattern.pattern_id,
|
|
6554
|
+
matched_stitch_ids: window.map((s) => s.stitch_id),
|
|
6555
|
+
match_score: 1,
|
|
6556
|
+
thread_id: window[0].thread_id,
|
|
6557
|
+
detected_at: now
|
|
6558
|
+
});
|
|
6559
|
+
}
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
return matches;
|
|
6564
|
+
}
|
|
6565
|
+
function recordOccurrence(pattern, threadId) {
|
|
6566
|
+
pattern.occurrence_count++;
|
|
6567
|
+
pattern.last_seen_at = Date.now();
|
|
6568
|
+
pattern.confidence = 1 - 1 / (1 + pattern.occurrence_count * 0.5);
|
|
6569
|
+
if (!pattern.seen_in_threads.includes(threadId)) {
|
|
6570
|
+
pattern.seen_in_threads.push(threadId);
|
|
6571
|
+
}
|
|
6572
|
+
}
|
|
6573
|
+
function detectAnomalies(recentStitches, knownPatterns, threshold = 0.7) {
|
|
6574
|
+
const anomalies = [];
|
|
6575
|
+
const sorted = [...recentStitches].sort((a, b) => a.sequence - b.sequence);
|
|
6576
|
+
const now = Date.now();
|
|
6577
|
+
for (const pattern of knownPatterns) {
|
|
6578
|
+
if (pattern.kind !== "sequence" || !pattern.signature.intent_sequence) continue;
|
|
6579
|
+
if (pattern.confidence < threshold) continue;
|
|
6580
|
+
const seq = pattern.signature.intent_sequence;
|
|
6581
|
+
if (sorted.length >= 1 && sorted.length < seq.length) {
|
|
6582
|
+
const partialMatch = sorted.every(
|
|
6583
|
+
(s, i) => i < seq.length && s.intent === seq[i]
|
|
6584
|
+
);
|
|
6585
|
+
if (partialMatch) {
|
|
6586
|
+
const expectedNext = seq[sorted.length];
|
|
6587
|
+
const lastStitch = sorted[sorted.length - 1];
|
|
6588
|
+
if (pattern.occurrence_count >= 3) {
|
|
6589
|
+
anomalies.push({
|
|
6590
|
+
pattern_id: `pat_anom_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
6591
|
+
kind: "anomaly",
|
|
6592
|
+
name: `Incomplete: ${pattern.name}`,
|
|
6593
|
+
description: `Expected '${expectedNext}' after '${lastStitch.intent}' based on pattern '${pattern.name}'`,
|
|
6594
|
+
signature: pattern.signature,
|
|
6595
|
+
confidence: pattern.confidence * 0.8,
|
|
6596
|
+
occurrence_count: 1,
|
|
6597
|
+
first_seen_at: now,
|
|
6598
|
+
last_seen_at: now,
|
|
6599
|
+
seen_in_threads: [lastStitch.thread_id],
|
|
6600
|
+
classification: "anomalous"
|
|
6601
|
+
});
|
|
6602
|
+
}
|
|
6603
|
+
}
|
|
6604
|
+
}
|
|
6605
|
+
}
|
|
6606
|
+
return anomalies;
|
|
6607
|
+
}
|
|
6608
|
+
var import_crypto13, InMemoryPatternStore;
|
|
6609
|
+
var init_pattern_engine = __esm({
|
|
6610
|
+
"src/needle/pattern.engine.ts"() {
|
|
6611
|
+
import_crypto13 = require("crypto");
|
|
6612
|
+
InMemoryPatternStore = class {
|
|
6613
|
+
constructor() {
|
|
6614
|
+
this.patterns = /* @__PURE__ */ new Map();
|
|
6615
|
+
}
|
|
6616
|
+
save(pattern) {
|
|
6617
|
+
this.patterns.set(pattern.pattern_id, pattern);
|
|
6618
|
+
}
|
|
6619
|
+
get(patternId) {
|
|
6620
|
+
return this.patterns.get(patternId);
|
|
6621
|
+
}
|
|
6622
|
+
findByKind(kind) {
|
|
6623
|
+
return [...this.patterns.values()].filter((p) => p.kind === kind);
|
|
6624
|
+
}
|
|
6625
|
+
findByIntent(intent) {
|
|
6626
|
+
return [...this.patterns.values()].filter(
|
|
6627
|
+
(p) => p.signature.intent_sequence?.includes(intent)
|
|
6628
|
+
);
|
|
6629
|
+
}
|
|
6630
|
+
all() {
|
|
6631
|
+
return [...this.patterns.values()];
|
|
6632
|
+
}
|
|
6633
|
+
};
|
|
6634
|
+
}
|
|
6635
|
+
});
|
|
6636
|
+
|
|
6637
|
+
// src/sensors/tps.sensor.ts
|
|
6638
|
+
var require_tps_sensor = __commonJS({
|
|
6639
|
+
"src/sensors/tps.sensor.ts"(exports2) {
|
|
6640
|
+
"use strict";
|
|
6641
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
6642
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6643
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6644
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6645
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6646
|
+
};
|
|
6647
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
6648
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6649
|
+
};
|
|
6650
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6651
|
+
exports2.TpsSensor = void 0;
|
|
6652
|
+
var common_1 = require("@nestjs/common");
|
|
6653
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6654
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6655
|
+
var TPS_EPOCH_MS = 9343548e5;
|
|
6656
|
+
function parseINotation(tps) {
|
|
6657
|
+
if (!tps.startsWith("i"))
|
|
6658
|
+
return null;
|
|
6659
|
+
const num = Number(tps.slice(1));
|
|
6660
|
+
if (!Number.isFinite(num))
|
|
6661
|
+
return null;
|
|
6662
|
+
return TPS_EPOCH_MS + num;
|
|
6663
|
+
}
|
|
6664
|
+
var TpsSensor2 = class TpsSensor {
|
|
6665
|
+
constructor(options = {}) {
|
|
6666
|
+
this.name = "TpsSensor";
|
|
6667
|
+
this.order = sensor_bands_1.BAND.POLICY + 2;
|
|
6668
|
+
this.maxDriftMs = options.maxDriftMs ?? 3e4;
|
|
6669
|
+
this.resolver = options.resolver ?? parseINotation;
|
|
6670
|
+
}
|
|
6671
|
+
supports(input) {
|
|
6672
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
6673
|
+
return typeof tps === "string" && tps.length > 0;
|
|
6674
|
+
}
|
|
6675
|
+
async run(input) {
|
|
6676
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
6677
|
+
const resolved = this.resolver(tps);
|
|
6678
|
+
if (resolved === null) {
|
|
6679
|
+
return {
|
|
6680
|
+
allow: false,
|
|
6681
|
+
riskScore: 80,
|
|
6682
|
+
reasons: [`TPS coordinate '${tps}' is structurally invalid`],
|
|
6683
|
+
code: "TPS_INVALID_FORMAT"
|
|
6684
|
+
};
|
|
6685
|
+
}
|
|
6686
|
+
const now = Date.now();
|
|
6687
|
+
const drift = Math.abs(now - resolved);
|
|
6688
|
+
if (drift > this.maxDriftMs) {
|
|
6689
|
+
const direction = resolved > now ? "future" : "past";
|
|
6690
|
+
return {
|
|
6691
|
+
allow: false,
|
|
6692
|
+
riskScore: 70,
|
|
6693
|
+
reasons: [
|
|
6694
|
+
`TPS drift ${drift}ms exceeds max ${this.maxDriftMs}ms (${direction})`
|
|
6695
|
+
],
|
|
6696
|
+
code: "TPS_DRIFT_EXCEEDED",
|
|
6697
|
+
tags: { tpsDriftMs: drift, tpsDirection: direction }
|
|
6698
|
+
};
|
|
6699
|
+
}
|
|
6700
|
+
return {
|
|
6701
|
+
allow: true,
|
|
6702
|
+
riskScore: 0,
|
|
6703
|
+
reasons: [],
|
|
6704
|
+
tags: {
|
|
6705
|
+
tpsResolved: resolved,
|
|
6706
|
+
tpsDriftMs: drift
|
|
6707
|
+
}
|
|
6708
|
+
};
|
|
6709
|
+
}
|
|
6710
|
+
};
|
|
6711
|
+
exports2.TpsSensor = TpsSensor2;
|
|
6712
|
+
exports2.TpsSensor = TpsSensor2 = __decorate([
|
|
6713
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
6714
|
+
(0, common_1.Injectable)(),
|
|
6715
|
+
__metadata("design:paramtypes", [Object])
|
|
6716
|
+
], TpsSensor2);
|
|
6717
|
+
}
|
|
6718
|
+
});
|
|
6719
|
+
|
|
6720
|
+
// src/sensors/risk-gate.sensor.ts
|
|
6721
|
+
var require_risk_gate_sensor = __commonJS({
|
|
6722
|
+
"src/sensors/risk-gate.sensor.ts"(exports2) {
|
|
6723
|
+
"use strict";
|
|
6724
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
6725
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6726
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6727
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6728
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6729
|
+
};
|
|
6730
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
6731
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6732
|
+
};
|
|
6733
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6734
|
+
exports2.RiskGateSensor = void 0;
|
|
6735
|
+
var common_1 = require("@nestjs/common");
|
|
6736
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6737
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6738
|
+
var risk_1 = (init_risk(), __toCommonJS(risk_exports));
|
|
6739
|
+
var SEVERITY_WEIGHT = {
|
|
6740
|
+
low: 10,
|
|
6741
|
+
medium: 25,
|
|
6742
|
+
high: 50,
|
|
6743
|
+
critical: 100
|
|
6744
|
+
};
|
|
6745
|
+
var RiskGateSensor2 = class RiskGateSensor {
|
|
6746
|
+
constructor(options) {
|
|
6747
|
+
this.name = "RiskGateSensor";
|
|
6748
|
+
this.order = sensor_bands_1.BAND.BUSINESS + 10;
|
|
6749
|
+
this.collectors = options.collectors;
|
|
6750
|
+
this.denyThreshold = options.denyThreshold ?? 75;
|
|
6751
|
+
this.flagThreshold = options.flagThreshold ?? 40;
|
|
6752
|
+
}
|
|
6753
|
+
async run(input) {
|
|
6754
|
+
const results = await Promise.all(this.collectors.map((c) => c(input)));
|
|
6755
|
+
const signals = results.flat();
|
|
6756
|
+
let totalWeight = 0;
|
|
6757
|
+
let weightedSum = 0;
|
|
6758
|
+
for (const signal of signals) {
|
|
6759
|
+
const w = SEVERITY_WEIGHT[signal.severity];
|
|
6760
|
+
totalWeight += 1;
|
|
6761
|
+
weightedSum += w;
|
|
6762
|
+
}
|
|
6763
|
+
const aggregateScore = totalWeight > 0 ? Math.min(100, Math.round(weightedSum / totalWeight)) : 0;
|
|
6764
|
+
const evaluation = this.evaluate(aggregateScore, signals);
|
|
6765
|
+
input.metadata = {
|
|
6766
|
+
...input.metadata ?? {},
|
|
6767
|
+
riskEvaluation: evaluation
|
|
6768
|
+
};
|
|
6769
|
+
if (evaluation.decision === risk_1.RiskDecision.DENY) {
|
|
6770
|
+
return {
|
|
6771
|
+
allow: false,
|
|
6772
|
+
riskScore: aggregateScore,
|
|
6773
|
+
reasons: signals.map((s) => s.message),
|
|
6774
|
+
code: "RISK_GATE_DENY",
|
|
6775
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
6776
|
+
};
|
|
6777
|
+
}
|
|
6778
|
+
if (evaluation.decision === risk_1.RiskDecision.THROTTLE) {
|
|
6779
|
+
return {
|
|
6780
|
+
allow: false,
|
|
6781
|
+
riskScore: aggregateScore,
|
|
6782
|
+
reasons: signals.map((s) => s.message),
|
|
6783
|
+
code: "RISK_GATE_THROTTLE",
|
|
6784
|
+
retryAfterMs: evaluation.retryAfterMs,
|
|
6785
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
6786
|
+
};
|
|
6787
|
+
}
|
|
6788
|
+
return {
|
|
6789
|
+
allow: true,
|
|
6790
|
+
riskScore: aggregateScore,
|
|
6791
|
+
reasons: signals.filter((s) => s.severity === "medium" || s.severity === "high").map((s) => s.message),
|
|
6792
|
+
tags: {
|
|
6793
|
+
riskDecision: evaluation.decision,
|
|
6794
|
+
signalCount: signals.length
|
|
6795
|
+
}
|
|
6796
|
+
};
|
|
6797
|
+
}
|
|
6798
|
+
evaluate(score, signals) {
|
|
6799
|
+
const hasCritical = signals.some((s) => s.severity === "critical");
|
|
6800
|
+
if (hasCritical) {
|
|
6801
|
+
return {
|
|
6802
|
+
decision: risk_1.RiskDecision.DENY,
|
|
6803
|
+
reason: "Critical risk signal detected",
|
|
6804
|
+
confidence: 1,
|
|
6805
|
+
signals
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
if (score >= this.denyThreshold) {
|
|
6809
|
+
return {
|
|
6810
|
+
decision: risk_1.RiskDecision.DENY,
|
|
6811
|
+
reason: `Aggregate risk score ${score} exceeds deny threshold ${this.denyThreshold}`,
|
|
6812
|
+
confidence: score / 100,
|
|
6813
|
+
signals
|
|
6814
|
+
};
|
|
6815
|
+
}
|
|
6816
|
+
if (score >= this.flagThreshold) {
|
|
6817
|
+
return {
|
|
6818
|
+
decision: risk_1.RiskDecision.STEP_UP,
|
|
6819
|
+
reason: `Aggregate risk score ${score} exceeds flag threshold ${this.flagThreshold}`,
|
|
6820
|
+
confidence: score / 100,
|
|
6821
|
+
signals
|
|
6822
|
+
};
|
|
6823
|
+
}
|
|
6824
|
+
return {
|
|
6825
|
+
decision: risk_1.RiskDecision.ALLOW,
|
|
6826
|
+
confidence: 1 - score / 100,
|
|
6827
|
+
signals
|
|
6828
|
+
};
|
|
6829
|
+
}
|
|
6830
|
+
};
|
|
6831
|
+
exports2.RiskGateSensor = RiskGateSensor2;
|
|
6832
|
+
exports2.RiskGateSensor = RiskGateSensor2 = __decorate([
|
|
6833
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
6834
|
+
(0, common_1.Injectable)(),
|
|
6835
|
+
__metadata("design:paramtypes", [Object])
|
|
6836
|
+
], RiskGateSensor2);
|
|
6837
|
+
}
|
|
6838
|
+
});
|
|
6839
|
+
|
|
6840
|
+
// src/sensors/tickauth.sensor.ts
|
|
6841
|
+
var require_tickauth_sensor = __commonJS({
|
|
6842
|
+
"src/sensors/tickauth.sensor.ts"(exports2) {
|
|
6843
|
+
"use strict";
|
|
6844
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
6845
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6846
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6847
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6848
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6849
|
+
};
|
|
6850
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
6851
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6852
|
+
};
|
|
6853
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6854
|
+
exports2.TickAuthSensor = void 0;
|
|
6855
|
+
var common_1 = require("@nestjs/common");
|
|
6856
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6857
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6858
|
+
var TickAuthSensor2 = class TickAuthSensor {
|
|
6859
|
+
constructor(options = {}) {
|
|
6860
|
+
this.name = "TickAuthSensor";
|
|
6861
|
+
this.order = sensor_bands_1.BAND.IDENTITY + 40;
|
|
6862
|
+
this.verifier = options.verifier;
|
|
6863
|
+
this.matchIntent = options.matchIntent ?? true;
|
|
6864
|
+
this.acceptTypes = options.acceptTypes?.length ? new Set(options.acceptTypes) : null;
|
|
6865
|
+
}
|
|
6866
|
+
supports(input) {
|
|
6867
|
+
return !!(input.metadata?.capsule || input.metadata?.tickauthCapsule || input.metadata?.cceEnvelope?.capsule);
|
|
6868
|
+
}
|
|
6869
|
+
async run(input) {
|
|
6870
|
+
const capsule = input.metadata?.capsule ?? input.metadata?.tickauthCapsule ?? input.metadata?.cceEnvelope?.capsule;
|
|
6871
|
+
if (!capsule) {
|
|
6872
|
+
return {
|
|
6873
|
+
allow: false,
|
|
6874
|
+
riskScore: 90,
|
|
6875
|
+
reasons: ["TickAuth capsule not found"],
|
|
6876
|
+
code: "TICKAUTH_MISSING"
|
|
6877
|
+
};
|
|
6878
|
+
}
|
|
6879
|
+
if (!capsule.capsule_id || typeof capsule.capsule_id !== "string") {
|
|
6880
|
+
return {
|
|
6881
|
+
allow: false,
|
|
6882
|
+
riskScore: 100,
|
|
6883
|
+
reasons: ["TickAuth capsule has no valid capsule_id"],
|
|
6884
|
+
code: "TICKAUTH_INVALID_ID"
|
|
6885
|
+
};
|
|
6886
|
+
}
|
|
6887
|
+
const status = capsule.verification?.status;
|
|
6888
|
+
if (status && status !== "approved") {
|
|
6889
|
+
return {
|
|
6890
|
+
allow: false,
|
|
6891
|
+
riskScore: 100,
|
|
6892
|
+
reasons: [
|
|
6893
|
+
`TickAuth capsule status is '${status}'${capsule.verification?.reason ? `: ${capsule.verification.reason}` : ""}`
|
|
6894
|
+
],
|
|
6895
|
+
code: `TICKAUTH_STATUS_${status.toUpperCase()}`
|
|
6896
|
+
};
|
|
6897
|
+
}
|
|
6898
|
+
if (this.acceptTypes && capsule.capsule_type) {
|
|
6899
|
+
if (!this.acceptTypes.has(capsule.capsule_type)) {
|
|
6900
|
+
return {
|
|
6901
|
+
allow: false,
|
|
6902
|
+
riskScore: 80,
|
|
6903
|
+
reasons: [
|
|
6904
|
+
`TickAuth capsule type '${capsule.capsule_type}' is not in accept list`
|
|
6905
|
+
],
|
|
6906
|
+
code: "TICKAUTH_TYPE_REJECTED"
|
|
6907
|
+
};
|
|
6908
|
+
}
|
|
6909
|
+
}
|
|
6910
|
+
if (this.matchIntent && input.intent && capsule.intent) {
|
|
6911
|
+
if (capsule.intent !== input.intent) {
|
|
6912
|
+
return {
|
|
6913
|
+
allow: false,
|
|
6914
|
+
riskScore: 80,
|
|
6915
|
+
reasons: [
|
|
6916
|
+
`TickAuth capsule intent '${capsule.intent}' does not match AXIS intent '${input.intent}'`
|
|
6917
|
+
],
|
|
6918
|
+
code: "TICKAUTH_INTENT_MISMATCH"
|
|
6919
|
+
};
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6922
|
+
if (this.verifier) {
|
|
6923
|
+
const error = await this.verifier(capsule, input);
|
|
6924
|
+
if (error) {
|
|
6925
|
+
return {
|
|
6926
|
+
allow: false,
|
|
6927
|
+
riskScore: 90,
|
|
6928
|
+
reasons: [`TickAuth verification failed: ${error}`],
|
|
6929
|
+
code: "TICKAUTH_VERIFY_FAILED"
|
|
6930
|
+
};
|
|
6931
|
+
}
|
|
6932
|
+
}
|
|
6933
|
+
return {
|
|
6934
|
+
allow: true,
|
|
6935
|
+
riskScore: 0,
|
|
6936
|
+
reasons: [],
|
|
6937
|
+
tags: {
|
|
6938
|
+
tickauthCapsuleId: capsule.capsule_id,
|
|
6939
|
+
tickauthMode: capsule.mode,
|
|
6940
|
+
tickauthSingleUse: capsule.single_use
|
|
6941
|
+
}
|
|
6942
|
+
};
|
|
6943
|
+
}
|
|
6944
|
+
};
|
|
6945
|
+
exports2.TickAuthSensor = TickAuthSensor2;
|
|
6946
|
+
exports2.TickAuthSensor = TickAuthSensor2 = __decorate([
|
|
6947
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
6948
|
+
(0, common_1.Injectable)(),
|
|
6949
|
+
__metadata("design:paramtypes", [Object])
|
|
6950
|
+
], TickAuthSensor2);
|
|
6951
|
+
}
|
|
6952
|
+
});
|
|
6953
|
+
|
|
6954
|
+
// src/cce/sensors/cce-envelope-validation.sensor.ts
|
|
6955
|
+
var REQUIRED_FIELDS, CceEnvelopeValidationSensor;
|
|
6956
|
+
var init_cce_envelope_validation_sensor = __esm({
|
|
6957
|
+
"src/cce/sensors/cce-envelope-validation.sensor.ts"() {
|
|
6958
|
+
init_axis_sensor();
|
|
6959
|
+
init_cce_types();
|
|
6960
|
+
REQUIRED_FIELDS = [
|
|
6961
|
+
"ver",
|
|
6962
|
+
"request_id",
|
|
6963
|
+
"correlation_id",
|
|
6964
|
+
"client_kid",
|
|
6965
|
+
"capsule",
|
|
6966
|
+
"encrypted_key",
|
|
6967
|
+
"encrypted_payload",
|
|
6968
|
+
"request_nonce",
|
|
6969
|
+
"client_sig",
|
|
6970
|
+
"content_type",
|
|
6971
|
+
"algorithms"
|
|
6972
|
+
];
|
|
6973
|
+
CceEnvelopeValidationSensor = class {
|
|
6974
|
+
constructor() {
|
|
6975
|
+
this.name = "cce.envelope.validation";
|
|
6976
|
+
this.order = 5;
|
|
6977
|
+
this.phase = "PRE_DECODE";
|
|
6978
|
+
}
|
|
6979
|
+
supports(input) {
|
|
6980
|
+
return input.metadata?.cce === true || input.metadata?.contentType === "application/axis-cce";
|
|
6981
|
+
}
|
|
6982
|
+
async run(input) {
|
|
6983
|
+
const envelope = input.metadata?.cceEnvelope;
|
|
6984
|
+
if (!envelope) {
|
|
6985
|
+
return {
|
|
6986
|
+
allow: false,
|
|
6987
|
+
riskScore: 100,
|
|
6988
|
+
reasons: [CCE_ERROR.INVALID_ENVELOPE],
|
|
6989
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
6990
|
+
};
|
|
6991
|
+
}
|
|
6992
|
+
for (const field of REQUIRED_FIELDS) {
|
|
6993
|
+
if (envelope[field] === void 0 || envelope[field] === null) {
|
|
6994
|
+
return {
|
|
6995
|
+
allow: false,
|
|
6996
|
+
riskScore: 100,
|
|
6997
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: missing ${field}`],
|
|
6998
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
6999
|
+
};
|
|
7000
|
+
}
|
|
7001
|
+
}
|
|
7002
|
+
if (envelope.ver !== CCE_PROTOCOL_VERSION) {
|
|
7003
|
+
return {
|
|
7004
|
+
allow: false,
|
|
7005
|
+
riskScore: 100,
|
|
7006
|
+
reasons: [`${CCE_ERROR.UNSUPPORTED_VERSION}: ${envelope.ver}`],
|
|
7007
|
+
code: CCE_ERROR.UNSUPPORTED_VERSION
|
|
7008
|
+
};
|
|
7009
|
+
}
|
|
7010
|
+
if (!/^[0-9a-f]+$/i.test(envelope.request_nonce)) {
|
|
7011
|
+
return {
|
|
7012
|
+
allow: false,
|
|
7013
|
+
riskScore: 100,
|
|
7014
|
+
reasons: [
|
|
7015
|
+
`${CCE_ERROR.INVALID_ENVELOPE}: invalid request_nonce format`
|
|
7016
|
+
],
|
|
7017
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7018
|
+
};
|
|
7019
|
+
}
|
|
7020
|
+
if (envelope.request_nonce.length !== CCE_NONCE_BYTES * 2) {
|
|
7021
|
+
return {
|
|
7022
|
+
allow: false,
|
|
7023
|
+
riskScore: 100,
|
|
7024
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: request_nonce wrong length`],
|
|
7025
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7026
|
+
};
|
|
7027
|
+
}
|
|
7028
|
+
const capsule = envelope.capsule;
|
|
7029
|
+
if (!capsule.capsule_id || !capsule.ver || !capsule.sub || !capsule.kid || !capsule.intent || !capsule.aud || !capsule.issuer_sig) {
|
|
7030
|
+
return {
|
|
7031
|
+
allow: false,
|
|
7032
|
+
riskScore: 100,
|
|
7033
|
+
reasons: [`${CCE_ERROR.MISSING_CAPSULE}: incomplete capsule claims`],
|
|
7034
|
+
code: CCE_ERROR.MISSING_CAPSULE
|
|
7035
|
+
};
|
|
7036
|
+
}
|
|
7037
|
+
if (!envelope.encrypted_key.ciphertext || !envelope.encrypted_key.alg) {
|
|
7038
|
+
return {
|
|
7039
|
+
allow: false,
|
|
7040
|
+
riskScore: 100,
|
|
7041
|
+
reasons: [
|
|
7042
|
+
`${CCE_ERROR.MISSING_ENCRYPTED_KEY}: incomplete encrypted_key`
|
|
7043
|
+
],
|
|
7044
|
+
code: CCE_ERROR.MISSING_ENCRYPTED_KEY
|
|
7045
|
+
};
|
|
7046
|
+
}
|
|
4753
7047
|
input.metadata = input.metadata ?? {};
|
|
4754
7048
|
input.metadata.cceEnvelopeValid = true;
|
|
4755
7049
|
return {
|
|
@@ -5465,94 +7759,18 @@ var init_cce = __esm({
|
|
|
5465
7759
|
// src/core/index.ts
|
|
5466
7760
|
var core_exports = {};
|
|
5467
7761
|
__export(core_exports, {
|
|
5468
|
-
AXIS_MAGIC: () => import_axis_protocol2.AXIS_MAGIC,
|
|
5469
|
-
AXIS_VERSION: () => import_axis_protocol2.AXIS_VERSION,
|
|
5470
7762
|
AxisError: () => AxisError,
|
|
5471
7763
|
AxisFrameZ: () => AxisFrameZ,
|
|
5472
|
-
BodyProfile: () => import_axis_protocol2.BodyProfile,
|
|
5473
|
-
ERR_BAD_SIGNATURE: () => import_axis_protocol2.ERR_BAD_SIGNATURE,
|
|
5474
|
-
ERR_CONTRACT_VIOLATION: () => import_axis_protocol2.ERR_CONTRACT_VIOLATION,
|
|
5475
|
-
ERR_INVALID_PACKET: () => import_axis_protocol2.ERR_INVALID_PACKET,
|
|
5476
|
-
ERR_REPLAY_DETECTED: () => import_axis_protocol2.ERR_REPLAY_DETECTED,
|
|
5477
|
-
FLAG_BODY_TLV: () => import_axis_protocol2.FLAG_BODY_TLV,
|
|
5478
|
-
FLAG_CHAIN_REQ: () => import_axis_protocol2.FLAG_CHAIN_REQ,
|
|
5479
|
-
FLAG_HAS_WITNESS: () => import_axis_protocol2.FLAG_HAS_WITNESS,
|
|
5480
|
-
MAX_BODY_LEN: () => import_axis_protocol2.MAX_BODY_LEN,
|
|
5481
|
-
MAX_FRAME_LEN: () => import_axis_protocol2.MAX_FRAME_LEN,
|
|
5482
|
-
MAX_HDR_LEN: () => import_axis_protocol2.MAX_HDR_LEN,
|
|
5483
|
-
MAX_SIG_LEN: () => import_axis_protocol2.MAX_SIG_LEN,
|
|
5484
|
-
NCERT_ALG: () => import_axis_protocol2.NCERT_ALG,
|
|
5485
|
-
NCERT_EXP: () => import_axis_protocol2.NCERT_EXP,
|
|
5486
|
-
NCERT_ISSUER_KID: () => import_axis_protocol2.NCERT_ISSUER_KID,
|
|
5487
|
-
NCERT_KID: () => import_axis_protocol2.NCERT_KID,
|
|
5488
|
-
NCERT_NBF: () => import_axis_protocol2.NCERT_NBF,
|
|
5489
|
-
NCERT_NODE_ID: () => import_axis_protocol2.NCERT_NODE_ID,
|
|
5490
|
-
NCERT_PAYLOAD: () => import_axis_protocol2.NCERT_PAYLOAD,
|
|
5491
|
-
NCERT_PUB: () => import_axis_protocol2.NCERT_PUB,
|
|
5492
|
-
NCERT_SCOPE: () => import_axis_protocol2.NCERT_SCOPE,
|
|
5493
|
-
NCERT_SIG: () => import_axis_protocol2.NCERT_SIG,
|
|
5494
|
-
PROOF_CAPSULE: () => import_axis_protocol2.PROOF_CAPSULE,
|
|
5495
|
-
PROOF_JWT: () => import_axis_protocol2.PROOF_JWT,
|
|
5496
|
-
PROOF_LOOM: () => import_axis_protocol2.PROOF_LOOM,
|
|
5497
|
-
PROOF_MTLS: () => import_axis_protocol2.PROOF_MTLS,
|
|
5498
|
-
PROOF_NONE: () => import_axis_protocol2.PROOF_NONE,
|
|
5499
|
-
PROOF_WITNESS: () => import_axis_protocol2.PROOF_WITNESS,
|
|
5500
|
-
ProofType: () => import_axis_protocol2.ProofType,
|
|
5501
|
-
TLV: () => import_axis_protocol.TLV,
|
|
5502
|
-
TLV_ACTOR_ID: () => import_axis_protocol2.TLV_ACTOR_ID,
|
|
5503
|
-
TLV_AUD: () => import_axis_protocol2.TLV_AUD,
|
|
5504
|
-
TLV_BODY_ARR: () => import_axis_protocol2.TLV_BODY_ARR,
|
|
5505
|
-
TLV_BODY_OBJ: () => import_axis_protocol2.TLV_BODY_OBJ,
|
|
5506
|
-
TLV_CAPSULE: () => import_axis_protocol2.TLV_CAPSULE,
|
|
5507
|
-
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
5508
|
-
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
5509
|
-
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
5510
|
-
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
5511
|
-
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
5512
|
-
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
5513
|
-
TLV_LOOM_PRESENCE_ID: () => import_axis_protocol2.TLV_LOOM_PRESENCE_ID,
|
|
5514
|
-
TLV_LOOM_THREAD_HASH: () => import_axis_protocol2.TLV_LOOM_THREAD_HASH,
|
|
5515
|
-
TLV_LOOM_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
5516
|
-
TLV_NODE: () => import_axis_protocol2.TLV_NODE,
|
|
5517
|
-
TLV_NODE_CERT_HASH: () => import_axis_protocol2.TLV_NODE_CERT_HASH,
|
|
5518
|
-
TLV_NODE_KID: () => import_axis_protocol2.TLV_NODE_KID,
|
|
5519
|
-
TLV_NONCE: () => import_axis_protocol2.TLV_NONCE,
|
|
5520
|
-
TLV_OFFSET: () => import_axis_protocol2.TLV_OFFSET,
|
|
5521
|
-
TLV_OK: () => import_axis_protocol2.TLV_OK,
|
|
5522
|
-
TLV_PID: () => import_axis_protocol2.TLV_PID,
|
|
5523
|
-
TLV_PREV_HASH: () => import_axis_protocol2.TLV_PREV_HASH,
|
|
5524
|
-
TLV_PROOF_REF: () => import_axis_protocol2.TLV_PROOF_REF,
|
|
5525
|
-
TLV_PROOF_TYPE: () => import_axis_protocol2.TLV_PROOF_TYPE,
|
|
5526
|
-
TLV_REALM: () => import_axis_protocol2.TLV_REALM,
|
|
5527
|
-
TLV_RECEIPT_HASH: () => import_axis_protocol2.TLV_RECEIPT_HASH,
|
|
5528
|
-
TLV_RID: () => import_axis_protocol2.TLV_RID,
|
|
5529
|
-
TLV_SHA256_CHUNK: () => import_axis_protocol2.TLV_SHA256_CHUNK,
|
|
5530
|
-
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
5531
|
-
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
5532
|
-
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
5533
7764
|
computeReceiptHash: () => computeReceiptHash,
|
|
5534
7765
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
5535
|
-
decodeArray: () => import_axis_protocol.decodeArray,
|
|
5536
|
-
decodeFrame: () => decodeFrame,
|
|
5537
|
-
decodeObject: () => import_axis_protocol.decodeObject,
|
|
5538
|
-
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
5539
|
-
decodeTLVsList: () => import_axis_protocol.decodeTLVsList,
|
|
5540
|
-
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
5541
|
-
encodeFrame: () => encodeFrame,
|
|
5542
|
-
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
5543
|
-
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
5544
7766
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
5545
|
-
getSignTarget: () => getSignTarget,
|
|
5546
7767
|
sha256: () => sha2564,
|
|
5547
7768
|
signFrame: () => signFrame,
|
|
5548
|
-
varintLength: () => import_axis_protocol3.varintLength,
|
|
5549
7769
|
verifyFrameSignature: () => verifyFrameSignature
|
|
5550
7770
|
});
|
|
5551
7771
|
var init_core = __esm({
|
|
5552
7772
|
"src/core/index.ts"() {
|
|
5553
|
-
|
|
5554
|
-
init_varint();
|
|
5555
|
-
init_tlv();
|
|
7773
|
+
__reExport(core_exports, require("@nextera.one/axis-protocol"));
|
|
5556
7774
|
init_axis_bin();
|
|
5557
7775
|
init_signature();
|
|
5558
7776
|
init_axis_error();
|
|
@@ -5799,15 +8017,7 @@ __export(decorators_exports, {
|
|
|
5799
8017
|
IntentBody: () => IntentBody,
|
|
5800
8018
|
IntentSensors: () => IntentSensors,
|
|
5801
8019
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
5802
|
-
Sensor: () => Sensor
|
|
5803
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
5804
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
5805
|
-
TlvEnum: () => TlvEnum,
|
|
5806
|
-
TlvField: () => TlvField,
|
|
5807
|
-
TlvMinLen: () => TlvMinLen,
|
|
5808
|
-
TlvRange: () => TlvRange,
|
|
5809
|
-
TlvUtf8Pattern: () => TlvUtf8Pattern,
|
|
5810
|
-
TlvValidate: () => TlvValidate
|
|
8020
|
+
Sensor: () => Sensor
|
|
5811
8021
|
});
|
|
5812
8022
|
var init_decorators = __esm({
|
|
5813
8023
|
"src/decorators/index.ts"() {
|
|
@@ -5818,7 +8028,7 @@ var init_decorators = __esm({
|
|
|
5818
8028
|
init_intent_sensors_decorator();
|
|
5819
8029
|
init_intent_decorator();
|
|
5820
8030
|
init_sensor_decorator();
|
|
5821
|
-
|
|
8031
|
+
__reExport(decorators_exports, __toESM(require_tlv_field_decorator()));
|
|
5822
8032
|
}
|
|
5823
8033
|
});
|
|
5824
8034
|
|
|
@@ -5896,6 +8106,25 @@ var init_engine = __esm({
|
|
|
5896
8106
|
}
|
|
5897
8107
|
});
|
|
5898
8108
|
|
|
8109
|
+
// src/idel/idel.types.ts
|
|
8110
|
+
var init_idel_types = __esm({
|
|
8111
|
+
"src/idel/idel.types.ts"() {
|
|
8112
|
+
}
|
|
8113
|
+
});
|
|
8114
|
+
|
|
8115
|
+
// src/idel/index.ts
|
|
8116
|
+
var idel_exports = {};
|
|
8117
|
+
__export(idel_exports, {
|
|
8118
|
+
IdelCompiler: () => IdelCompiler,
|
|
8119
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry
|
|
8120
|
+
});
|
|
8121
|
+
var init_idel = __esm({
|
|
8122
|
+
"src/idel/index.ts"() {
|
|
8123
|
+
init_idel_types();
|
|
8124
|
+
init_idel_compiler();
|
|
8125
|
+
}
|
|
8126
|
+
});
|
|
8127
|
+
|
|
5899
8128
|
// src/loom/index.ts
|
|
5900
8129
|
var loom_exports = {};
|
|
5901
8130
|
__export(loom_exports, {
|
|
@@ -5905,11 +8134,98 @@ __export(loom_exports, {
|
|
|
5905
8134
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
5906
8135
|
canonicalizeGrant: () => canonicalizeGrant,
|
|
5907
8136
|
canonicalizeWrit: () => canonicalizeWrit,
|
|
5908
|
-
|
|
8137
|
+
createGrant: () => createGrant,
|
|
8138
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
8139
|
+
createReceipt: () => createReceipt,
|
|
8140
|
+
createRevocation: () => createRevocation,
|
|
8141
|
+
createWrit: () => createWrit,
|
|
8142
|
+
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
8143
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
8144
|
+
getGrantStatus: () => getGrantStatus,
|
|
8145
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
8146
|
+
grantCoversAction: () => grantCoversAction,
|
|
8147
|
+
isRevoked: () => isRevoked,
|
|
8148
|
+
renewPresence: () => renewPresence,
|
|
8149
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
8150
|
+
updateThreadState: () => updateThreadState,
|
|
8151
|
+
validateGrant: () => validateGrant,
|
|
8152
|
+
validateWrit: () => validateWrit,
|
|
8153
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
8154
|
+
verifyReceiptChain: () => verifyReceiptChain
|
|
5909
8155
|
});
|
|
5910
8156
|
var init_loom = __esm({
|
|
5911
8157
|
"src/loom/index.ts"() {
|
|
5912
8158
|
init_loom_types();
|
|
8159
|
+
init_loom_engine();
|
|
8160
|
+
}
|
|
8161
|
+
});
|
|
8162
|
+
|
|
8163
|
+
// src/needle/needle.types.ts
|
|
8164
|
+
var init_needle_types = __esm({
|
|
8165
|
+
"src/needle/needle.types.ts"() {
|
|
8166
|
+
}
|
|
8167
|
+
});
|
|
8168
|
+
|
|
8169
|
+
// src/needle/knot.types.ts
|
|
8170
|
+
var init_knot_types = __esm({
|
|
8171
|
+
"src/needle/knot.types.ts"() {
|
|
8172
|
+
}
|
|
8173
|
+
});
|
|
8174
|
+
|
|
8175
|
+
// src/needle/fabric.types.ts
|
|
8176
|
+
var init_fabric_types = __esm({
|
|
8177
|
+
"src/needle/fabric.types.ts"() {
|
|
8178
|
+
}
|
|
8179
|
+
});
|
|
8180
|
+
|
|
8181
|
+
// src/needle/pattern.types.ts
|
|
8182
|
+
var init_pattern_types = __esm({
|
|
8183
|
+
"src/needle/pattern.types.ts"() {
|
|
8184
|
+
}
|
|
8185
|
+
});
|
|
8186
|
+
|
|
8187
|
+
// src/needle/index.ts
|
|
8188
|
+
var needle_exports = {};
|
|
8189
|
+
__export(needle_exports, {
|
|
8190
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
8191
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
8192
|
+
applyStitch: () => applyStitch,
|
|
8193
|
+
assembleNeedle: () => assembleNeedle,
|
|
8194
|
+
breakKnot: () => breakKnot,
|
|
8195
|
+
createFabric: () => createFabric,
|
|
8196
|
+
detectAnomalies: () => detectAnomalies,
|
|
8197
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
8198
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
8199
|
+
diffFabrics: () => diffFabrics,
|
|
8200
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
8201
|
+
forkFromKnot: () => forkFromKnot,
|
|
8202
|
+
formStitch: () => formStitch,
|
|
8203
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
8204
|
+
getFabricValue: () => getFabricValue,
|
|
8205
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
8206
|
+
isKnotOpen: () => isKnotOpen,
|
|
8207
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
8208
|
+
lockCells: () => lockCells,
|
|
8209
|
+
matchPatterns: () => matchPatterns,
|
|
8210
|
+
openKnot: () => openKnot,
|
|
8211
|
+
projectAt: () => projectAt,
|
|
8212
|
+
queryFabric: () => queryFabric,
|
|
8213
|
+
recordOccurrence: () => recordOccurrence,
|
|
8214
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
8215
|
+
tieKnot: () => tieKnot,
|
|
8216
|
+
validateKnot: () => validateKnot,
|
|
8217
|
+
weave: () => weave
|
|
8218
|
+
});
|
|
8219
|
+
var init_needle = __esm({
|
|
8220
|
+
"src/needle/index.ts"() {
|
|
8221
|
+
init_needle_types();
|
|
8222
|
+
init_needle_engine();
|
|
8223
|
+
init_knot_types();
|
|
8224
|
+
init_knot_engine();
|
|
8225
|
+
init_fabric_types();
|
|
8226
|
+
init_fabric_engine();
|
|
8227
|
+
init_pattern_types();
|
|
8228
|
+
init_pattern_engine();
|
|
5913
8229
|
}
|
|
5914
8230
|
});
|
|
5915
8231
|
|
|
@@ -7195,6 +9511,143 @@ var require_intent_registry_sensor = __commonJS({
|
|
|
7195
9511
|
}
|
|
7196
9512
|
});
|
|
7197
9513
|
|
|
9514
|
+
// src/sensors/law-evaluation.sensor.ts
|
|
9515
|
+
var require_law_evaluation_sensor = __commonJS({
|
|
9516
|
+
"src/sensors/law-evaluation.sensor.ts"(exports2) {
|
|
9517
|
+
"use strict";
|
|
9518
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
9519
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9520
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9521
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9522
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9523
|
+
};
|
|
9524
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
9525
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9526
|
+
};
|
|
9527
|
+
var LawEvaluationSensor_1;
|
|
9528
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
9529
|
+
exports2.LawEvaluationSensor = void 0;
|
|
9530
|
+
var common_1 = require("@nestjs/common");
|
|
9531
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
9532
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
9533
|
+
var law_1 = (init_law(), __toCommonJS(law_exports));
|
|
9534
|
+
var LawEvaluationSensor = LawEvaluationSensor_1 = class LawEvaluationSensor {
|
|
9535
|
+
constructor(options = {}) {
|
|
9536
|
+
this.options = options;
|
|
9537
|
+
this.logger = new common_1.Logger(LawEvaluationSensor_1.name);
|
|
9538
|
+
this.name = "LawEvaluationSensor";
|
|
9539
|
+
this.order = sensor_bands_1.BAND.POLICY + 5;
|
|
9540
|
+
}
|
|
9541
|
+
supports(input) {
|
|
9542
|
+
return !!this.options.evaluator && !!input.intent;
|
|
9543
|
+
}
|
|
9544
|
+
async run(input) {
|
|
9545
|
+
const evaluator = this.options.evaluator;
|
|
9546
|
+
if (!evaluator) {
|
|
9547
|
+
return { action: "ALLOW" };
|
|
9548
|
+
}
|
|
9549
|
+
const context = (0, law_1.buildAxisLawEvaluationContext)(input);
|
|
9550
|
+
let result;
|
|
9551
|
+
try {
|
|
9552
|
+
result = await evaluator(context);
|
|
9553
|
+
} catch (error) {
|
|
9554
|
+
const message = error instanceof Error ? error.message : "Unknown law evaluation error";
|
|
9555
|
+
this.logger.error(`Law evaluation failed for ${input.intent}: ${message}`);
|
|
9556
|
+
input.metadata = {
|
|
9557
|
+
...input.metadata ?? {},
|
|
9558
|
+
lawEvaluation: {
|
|
9559
|
+
decision: "deny",
|
|
9560
|
+
reason: "Law evaluation failed",
|
|
9561
|
+
explanation: message
|
|
9562
|
+
}
|
|
9563
|
+
};
|
|
9564
|
+
return {
|
|
9565
|
+
action: "DENY",
|
|
9566
|
+
code: "LAW_EVALUATION_ERROR",
|
|
9567
|
+
reason: message,
|
|
9568
|
+
meta: { lawDecision: "deny" }
|
|
9569
|
+
};
|
|
9570
|
+
}
|
|
9571
|
+
input.metadata = {
|
|
9572
|
+
...input.metadata ?? {},
|
|
9573
|
+
lawEvaluation: {
|
|
9574
|
+
...result,
|
|
9575
|
+
context: sanitizeLawContext(context)
|
|
9576
|
+
}
|
|
9577
|
+
};
|
|
9578
|
+
if (result.decision === "allow") {
|
|
9579
|
+
return {
|
|
9580
|
+
allow: true,
|
|
9581
|
+
riskScore: 0,
|
|
9582
|
+
reasons: result.reason ? [result.reason] : [],
|
|
9583
|
+
tags: {
|
|
9584
|
+
lawDecision: "allow",
|
|
9585
|
+
...result.applicable ? { lawApplicableArticles: result.applicable.length } : {}
|
|
9586
|
+
},
|
|
9587
|
+
meta: result
|
|
9588
|
+
};
|
|
9589
|
+
}
|
|
9590
|
+
if (result.decision === "conditional") {
|
|
9591
|
+
const mode = this.options.conditionalDecision ?? "deny";
|
|
9592
|
+
const reasons = [result.reason, result.explanation].filter(Boolean);
|
|
9593
|
+
if (mode === "allow") {
|
|
9594
|
+
return {
|
|
9595
|
+
allow: true,
|
|
9596
|
+
riskScore: 0,
|
|
9597
|
+
reasons,
|
|
9598
|
+
tags: {
|
|
9599
|
+
lawDecision: "conditional"
|
|
9600
|
+
},
|
|
9601
|
+
meta: result
|
|
9602
|
+
};
|
|
9603
|
+
}
|
|
9604
|
+
if (mode === "flag") {
|
|
9605
|
+
return {
|
|
9606
|
+
action: "FLAG",
|
|
9607
|
+
scoreDelta: 25,
|
|
9608
|
+
reasons: reasons.length > 0 ? reasons : ["Execution is conditionally permitted pending additional requirements"],
|
|
9609
|
+
meta: result
|
|
9610
|
+
};
|
|
9611
|
+
}
|
|
9612
|
+
return {
|
|
9613
|
+
action: "DENY",
|
|
9614
|
+
code: "LAW_CONDITIONAL",
|
|
9615
|
+
reason: reasons.join(" | ") || "Execution is conditionally permitted pending additional requirements",
|
|
9616
|
+
meta: { lawDecision: "conditional", evaluation: result }
|
|
9617
|
+
};
|
|
9618
|
+
}
|
|
9619
|
+
return {
|
|
9620
|
+
action: "DENY",
|
|
9621
|
+
code: "LAW_DENIED",
|
|
9622
|
+
reason: [result.reason, result.explanation].filter(Boolean).join(" | ") || "Execution denied by law evaluation",
|
|
9623
|
+
meta: { lawDecision: "deny", evaluation: result }
|
|
9624
|
+
};
|
|
9625
|
+
}
|
|
9626
|
+
};
|
|
9627
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor;
|
|
9628
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor = LawEvaluationSensor_1 = __decorate([
|
|
9629
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
9630
|
+
(0, common_1.Injectable)(),
|
|
9631
|
+
__metadata("design:paramtypes", [Object])
|
|
9632
|
+
], LawEvaluationSensor);
|
|
9633
|
+
function sanitizeLawContext(context) {
|
|
9634
|
+
return {
|
|
9635
|
+
actorId: context.actorId,
|
|
9636
|
+
intent: context.intent,
|
|
9637
|
+
audience: context.audience,
|
|
9638
|
+
tps: context.tps,
|
|
9639
|
+
country: context.country,
|
|
9640
|
+
ip: context.ip,
|
|
9641
|
+
path: context.path,
|
|
9642
|
+
clientId: context.clientId,
|
|
9643
|
+
deviceId: context.deviceId,
|
|
9644
|
+
sessionId: context.sessionId,
|
|
9645
|
+
capsuleId: context.capsuleId
|
|
9646
|
+
};
|
|
9647
|
+
}
|
|
9648
|
+
}
|
|
9649
|
+
});
|
|
9650
|
+
|
|
7198
9651
|
// src/sensors/proof-presence.sensor.ts
|
|
7199
9652
|
var require_proof_presence_sensor = __commonJS({
|
|
7200
9653
|
"src/sensors/proof-presence.sensor.ts"(exports2) {
|
|
@@ -7902,16 +10355,40 @@ var init_sensors2 = __esm({
|
|
|
7902
10355
|
__reExport(sensors_exports, __toESM(require_header_tlv_limit_sensor()));
|
|
7903
10356
|
__reExport(sensors_exports, __toESM(require_intent_allowlist_sensor()));
|
|
7904
10357
|
__reExport(sensors_exports, __toESM(require_intent_registry_sensor()));
|
|
10358
|
+
__reExport(sensors_exports, __toESM(require_law_evaluation_sensor()));
|
|
7905
10359
|
__reExport(sensors_exports, __toESM(require_proof_presence_sensor()));
|
|
7906
10360
|
__reExport(sensors_exports, __toESM(require_protocol_strict_sensor()));
|
|
7907
10361
|
__reExport(sensors_exports, __toESM(require_receipt_policy_sensor()));
|
|
10362
|
+
__reExport(sensors_exports, __toESM(require_risk_gate_sensor()));
|
|
7908
10363
|
__reExport(sensors_exports, __toESM(require_schema_validation_sensor()));
|
|
7909
10364
|
__reExport(sensors_exports, __toESM(require_stream_scope_sensor()));
|
|
10365
|
+
__reExport(sensors_exports, __toESM(require_tickauth_sensor()));
|
|
7910
10366
|
__reExport(sensors_exports, __toESM(require_tlv_parse_sensor()));
|
|
10367
|
+
__reExport(sensors_exports, __toESM(require_tps_sensor()));
|
|
7911
10368
|
__reExport(sensors_exports, __toESM(require_varint_hardening_sensor()));
|
|
7912
10369
|
}
|
|
7913
10370
|
});
|
|
7914
10371
|
|
|
10372
|
+
// src/timeline/timeline.types.ts
|
|
10373
|
+
var init_timeline_types = __esm({
|
|
10374
|
+
"src/timeline/timeline.types.ts"() {
|
|
10375
|
+
}
|
|
10376
|
+
});
|
|
10377
|
+
|
|
10378
|
+
// src/timeline/index.ts
|
|
10379
|
+
var timeline_exports = {};
|
|
10380
|
+
__export(timeline_exports, {
|
|
10381
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
10382
|
+
TimelineEngine: () => TimelineEngine
|
|
10383
|
+
});
|
|
10384
|
+
var init_timeline = __esm({
|
|
10385
|
+
"src/timeline/index.ts"() {
|
|
10386
|
+
init_timeline_types();
|
|
10387
|
+
init_timeline_store();
|
|
10388
|
+
init_timeline_engine();
|
|
10389
|
+
}
|
|
10390
|
+
});
|
|
10391
|
+
|
|
7915
10392
|
// src/utils/index.ts
|
|
7916
10393
|
var utils_exports = {};
|
|
7917
10394
|
__export(utils_exports, {
|
|
@@ -7982,6 +10459,10 @@ __export(index_exports, {
|
|
|
7982
10459
|
INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
|
|
7983
10460
|
INTENT_SENSORS_KEY: () => INTENT_SENSORS_KEY,
|
|
7984
10461
|
INTENT_TIMEOUTS: () => INTENT_TIMEOUTS,
|
|
10462
|
+
IdelCompiler: () => IdelCompiler,
|
|
10463
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry,
|
|
10464
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
10465
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
7985
10466
|
Intent: () => Intent,
|
|
7986
10467
|
IntentBody: () => IntentBody,
|
|
7987
10468
|
IntentRouter: () => import_intent2.IntentRouter,
|
|
@@ -8017,6 +10498,7 @@ __export(index_exports, {
|
|
|
8017
10498
|
RESPONSE_TAG_UPDATED_BY: () => import_axis_response.RESPONSE_TAG_UPDATED_BY,
|
|
8018
10499
|
ResponseObserver: () => ResponseObserver,
|
|
8019
10500
|
RiskDecision: () => RiskDecision,
|
|
10501
|
+
RiskGateSensor: () => import_risk_gate.RiskGateSensor,
|
|
8020
10502
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
8021
10503
|
Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
|
|
8022
10504
|
Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -8035,7 +10517,7 @@ __export(index_exports, {
|
|
|
8035
10517
|
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
8036
10518
|
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
8037
10519
|
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
8038
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
10520
|
+
TLV_FIELDS_KEY: () => import_tlv_field2.TLV_FIELDS_KEY,
|
|
8039
10521
|
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
8040
10522
|
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
8041
10523
|
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
@@ -8061,20 +10543,28 @@ __export(index_exports, {
|
|
|
8061
10543
|
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
8062
10544
|
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
8063
10545
|
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
8064
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
10546
|
+
TLV_VALIDATORS_KEY: () => import_tlv_field2.TLV_VALIDATORS_KEY,
|
|
8065
10547
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
10548
|
+
TickAuthSensor: () => import_tickauth.TickAuthSensor,
|
|
10549
|
+
TimelineEngine: () => TimelineEngine,
|
|
10550
|
+
TlvEnum: () => import_tlv_field2.TlvEnum,
|
|
10551
|
+
TlvField: () => import_tlv_field2.TlvField,
|
|
10552
|
+
TlvMinLen: () => import_tlv_field2.TlvMinLen,
|
|
10553
|
+
TlvRange: () => import_tlv_field2.TlvRange,
|
|
10554
|
+
TlvUtf8Pattern: () => import_tlv_field2.TlvUtf8Pattern,
|
|
10555
|
+
TlvValidate: () => import_tlv_field2.TlvValidate,
|
|
10556
|
+
TpsSensor: () => import_tps.TpsSensor,
|
|
10557
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
10558
|
+
applyStitch: () => applyStitch,
|
|
10559
|
+
assembleNeedle: () => assembleNeedle,
|
|
8072
10560
|
axis1SigningBytes: () => axis1SigningBytes,
|
|
8073
10561
|
b64urlDecode: () => b64urlDecode,
|
|
8074
10562
|
b64urlDecodeString: () => b64urlDecodeString,
|
|
8075
10563
|
b64urlEncode: () => b64urlEncode,
|
|
8076
10564
|
b64urlEncodeString: () => b64urlEncodeString,
|
|
10565
|
+
breakKnot: () => breakKnot,
|
|
8077
10566
|
buildAts1Hdr: () => buildAts1Hdr,
|
|
10567
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext,
|
|
8078
10568
|
buildDtoDecoder: () => import_dto_schema.buildDtoDecoder,
|
|
8079
10569
|
buildPacket: () => buildPacket,
|
|
8080
10570
|
buildQueueMessage: () => buildQueueMessage,
|
|
@@ -8093,11 +10583,17 @@ __export(index_exports, {
|
|
|
8093
10583
|
computeReceiptHash: () => computeReceiptHash,
|
|
8094
10584
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
8095
10585
|
core: () => core_exports,
|
|
10586
|
+
createFabric: () => createFabric,
|
|
10587
|
+
createGrant: () => createGrant,
|
|
8096
10588
|
createObservation: () => createObservation,
|
|
10589
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
10590
|
+
createReceipt: () => createReceipt,
|
|
10591
|
+
createRevocation: () => createRevocation,
|
|
10592
|
+
createWrit: () => createWrit,
|
|
8097
10593
|
crypto: () => crypto_exports,
|
|
8098
10594
|
decodeArray: () => import_axis_protocol.decodeArray,
|
|
8099
10595
|
decodeAxis1Frame: () => decodeAxis1Frame,
|
|
8100
|
-
decodeFrame: () => decodeFrame,
|
|
10596
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
8101
10597
|
decodeObject: () => import_axis_protocol.decodeObject,
|
|
8102
10598
|
decodeQueueMessage: () => decodeQueueMessage,
|
|
8103
10599
|
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
@@ -8105,28 +10601,50 @@ __export(index_exports, {
|
|
|
8105
10601
|
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
8106
10602
|
decorators: () => decorators_exports,
|
|
8107
10603
|
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
10604
|
+
detectAnomalies: () => detectAnomalies,
|
|
10605
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
10606
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
10607
|
+
diffFabrics: () => diffFabrics,
|
|
8108
10608
|
encVarint: () => encVarint,
|
|
8109
10609
|
encodeAxis1Frame: () => encodeAxis1Frame,
|
|
8110
10610
|
encodeAxisTlvDto: () => encodeAxisTlvDto,
|
|
8111
|
-
encodeFrame: () => encodeFrame,
|
|
10611
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
8112
10612
|
encodeQueueMessage: () => encodeQueueMessage,
|
|
8113
10613
|
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
8114
10614
|
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
8115
10615
|
endStage: () => endStage,
|
|
8116
10616
|
engine: () => engine_exports,
|
|
8117
10617
|
executeCcePipeline: () => executeCcePipeline,
|
|
10618
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
8118
10619
|
extractDtoSchema: () => import_dto_schema.extractDtoSchema,
|
|
8119
10620
|
finalizeObservation: () => finalizeObservation,
|
|
10621
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
10622
|
+
forkFromKnot: () => forkFromKnot,
|
|
10623
|
+
formStitch: () => formStitch,
|
|
8120
10624
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
8121
|
-
|
|
10625
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
10626
|
+
getFabricValue: () => getFabricValue,
|
|
10627
|
+
getGrantStatus: () => getGrantStatus,
|
|
10628
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
10629
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
10630
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget,
|
|
10631
|
+
grantCoversAction: () => grantCoversAction,
|
|
8122
10632
|
hasScope: () => hasScope,
|
|
8123
10633
|
hashObservation: () => hashObservation,
|
|
10634
|
+
idel: () => idel_exports,
|
|
8124
10635
|
isAdminOpcode: () => isAdminOpcode,
|
|
10636
|
+
isKnotOpen: () => isKnotOpen,
|
|
8125
10637
|
isKnownOpcode: () => isKnownOpcode,
|
|
10638
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
10639
|
+
isRevoked: () => isRevoked,
|
|
8126
10640
|
isTimestampValid: () => isTimestampValid,
|
|
10641
|
+
lockCells: () => lockCells,
|
|
8127
10642
|
loom: () => loom_exports,
|
|
10643
|
+
matchPatterns: () => matchPatterns,
|
|
10644
|
+
needle: () => needle_exports,
|
|
8128
10645
|
nonce16: () => nonce16,
|
|
8129
10646
|
normalizeSensorDecision: () => normalizeSensorDecision,
|
|
10647
|
+
openKnot: () => openKnot,
|
|
8130
10648
|
packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
|
|
8131
10649
|
packPasskeyLoginOptionsRes: () => packPasskeyLoginOptionsRes,
|
|
8132
10650
|
packPasskeyLoginVerifyReq: () => packPasskeyLoginVerifyReq,
|
|
@@ -8135,31 +10653,48 @@ __export(index_exports, {
|
|
|
8135
10653
|
parseAutoClaimEntries: () => parseAutoClaimEntries,
|
|
8136
10654
|
parseScope: () => parseScope,
|
|
8137
10655
|
parseStreamEntries: () => parseStreamEntries,
|
|
10656
|
+
projectAt: () => projectAt,
|
|
10657
|
+
queryFabric: () => queryFabric,
|
|
10658
|
+
recordOccurrence: () => recordOccurrence,
|
|
8138
10659
|
recordSensor: () => recordSensor,
|
|
10660
|
+
renewPresence: () => renewPresence,
|
|
8139
10661
|
resolveTimeout: () => resolveTimeout,
|
|
10662
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
8140
10663
|
schemas: () => schemas_exports,
|
|
10664
|
+
scoreTruth: () => scoreTruth,
|
|
8141
10665
|
security: () => security_exports,
|
|
8142
10666
|
sensitivityName: () => sensitivityName,
|
|
8143
10667
|
sensors: () => sensors_exports,
|
|
8144
10668
|
sha256: () => sha2564,
|
|
8145
10669
|
signFrame: () => signFrame,
|
|
10670
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
8146
10671
|
stableJsonStringify: () => stableJsonStringify,
|
|
8147
10672
|
startStage: () => startStage,
|
|
10673
|
+
tieKnot: () => tieKnot,
|
|
10674
|
+
timeline: () => timeline_exports,
|
|
8148
10675
|
tlv: () => tlv,
|
|
8149
10676
|
u64be: () => u64be,
|
|
8150
10677
|
unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
|
|
8151
10678
|
unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
|
|
8152
10679
|
unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
|
|
10680
|
+
updateThreadState: () => updateThreadState,
|
|
8153
10681
|
utf8: () => utf8,
|
|
8154
10682
|
utils: () => utils_exports,
|
|
8155
10683
|
validateFrameShape: () => validateFrameShape,
|
|
10684
|
+
validateGrant: () => validateGrant,
|
|
10685
|
+
validateKnot: () => validateKnot,
|
|
10686
|
+
validateWrit: () => validateWrit,
|
|
8156
10687
|
varintLength: () => import_axis_protocol3.varintLength,
|
|
8157
10688
|
varintU: () => varintU,
|
|
8158
10689
|
verifyFrameSignature: () => verifyFrameSignature,
|
|
8159
|
-
|
|
10690
|
+
verifyObservation: () => verifyObservation,
|
|
10691
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
10692
|
+
verifyReceiptChain: () => verifyReceiptChain,
|
|
10693
|
+
verifyResponse: () => verifyResponse,
|
|
10694
|
+
weave: () => weave
|
|
8160
10695
|
});
|
|
8161
10696
|
module.exports = __toCommonJS(index_exports);
|
|
8162
|
-
var import_dto_schema, import_axis_id, import_axis_response, import_intent2, import_axis_files, import_axis_request, import_handler_discovery, import_sensor_discovery, import_sensor2, import_axis_sensor_chain;
|
|
10697
|
+
var import_tlv_field2, import_dto_schema, import_axis_id, import_axis_response, import_intent2, import_axis_files, import_axis_request, import_handler_discovery, import_sensor_discovery, import_sensor2, import_axis_sensor_chain, import_tps, import_risk_gate, import_tickauth;
|
|
8163
10698
|
var init_index = __esm({
|
|
8164
10699
|
"src/index.ts"() {
|
|
8165
10700
|
init_handler_decorator();
|
|
@@ -8168,7 +10703,7 @@ var init_index = __esm({
|
|
|
8168
10703
|
init_intent_sensors_decorator();
|
|
8169
10704
|
init_handler_sensors_decorator();
|
|
8170
10705
|
init_sensor_decorator();
|
|
8171
|
-
|
|
10706
|
+
import_tlv_field2 = __toESM(require_tlv_field_decorator());
|
|
8172
10707
|
import_dto_schema = __toESM(require_dto_schema_util());
|
|
8173
10708
|
init_axis_tlv_dto();
|
|
8174
10709
|
import_axis_id = __toESM(require_axis_id_dto());
|
|
@@ -8179,6 +10714,7 @@ var init_index = __esm({
|
|
|
8179
10714
|
init_stable_json();
|
|
8180
10715
|
init_observation_queue_codec();
|
|
8181
10716
|
init_observation_hash();
|
|
10717
|
+
init_truth_scoring();
|
|
8182
10718
|
init_response_observer();
|
|
8183
10719
|
init_constants();
|
|
8184
10720
|
init_varint();
|
|
@@ -8200,6 +10736,7 @@ var init_index = __esm({
|
|
|
8200
10736
|
init_axis_sensor();
|
|
8201
10737
|
init_scopes();
|
|
8202
10738
|
init_capabilities();
|
|
10739
|
+
init_law();
|
|
8203
10740
|
init_risk();
|
|
8204
10741
|
init_opcodes();
|
|
8205
10742
|
init_receipt();
|
|
@@ -8216,19 +10753,33 @@ var init_index = __esm({
|
|
|
8216
10753
|
import_sensor2 = __toESM(require_sensor_registry());
|
|
8217
10754
|
init_axis_observation();
|
|
8218
10755
|
import_axis_sensor_chain = __toESM(require_axis_sensor_chain_service());
|
|
10756
|
+
init_timeline_engine();
|
|
10757
|
+
init_timeline_store();
|
|
8219
10758
|
init_cce_pipeline();
|
|
8220
10759
|
init_cce_types();
|
|
8221
10760
|
init_axis_tlv_codec();
|
|
8222
10761
|
init_loom_types();
|
|
10762
|
+
init_loom_engine();
|
|
10763
|
+
init_idel_compiler();
|
|
10764
|
+
init_needle_engine();
|
|
10765
|
+
init_knot_engine();
|
|
10766
|
+
init_fabric_engine();
|
|
10767
|
+
init_pattern_engine();
|
|
10768
|
+
import_tps = __toESM(require_tps_sensor());
|
|
10769
|
+
import_risk_gate = __toESM(require_risk_gate_sensor());
|
|
10770
|
+
import_tickauth = __toESM(require_tickauth_sensor());
|
|
8223
10771
|
init_cce();
|
|
8224
10772
|
init_core();
|
|
8225
10773
|
init_crypto();
|
|
8226
10774
|
init_decorators();
|
|
8227
10775
|
init_engine();
|
|
10776
|
+
init_idel();
|
|
8228
10777
|
init_loom();
|
|
10778
|
+
init_needle();
|
|
8229
10779
|
init_schemas();
|
|
8230
10780
|
init_security();
|
|
8231
10781
|
init_sensors2();
|
|
10782
|
+
init_timeline();
|
|
8232
10783
|
init_utils();
|
|
8233
10784
|
}
|
|
8234
10785
|
});
|
|
@@ -8291,6 +10842,10 @@ init_index();
|
|
|
8291
10842
|
INTENT_SENSITIVITY_MAP,
|
|
8292
10843
|
INTENT_SENSORS_KEY,
|
|
8293
10844
|
INTENT_TIMEOUTS,
|
|
10845
|
+
IdelCompiler,
|
|
10846
|
+
IdelSchemaRegistry,
|
|
10847
|
+
InMemoryPatternStore,
|
|
10848
|
+
InMemoryTimelineStore,
|
|
8294
10849
|
Intent,
|
|
8295
10850
|
IntentBody,
|
|
8296
10851
|
IntentRouter,
|
|
@@ -8326,6 +10881,7 @@ init_index();
|
|
|
8326
10881
|
RESPONSE_TAG_UPDATED_BY,
|
|
8327
10882
|
ResponseObserver,
|
|
8328
10883
|
RiskDecision,
|
|
10884
|
+
RiskGateSensor,
|
|
8329
10885
|
SENSOR_METADATA_KEY,
|
|
8330
10886
|
Schema2002_PasskeyLoginOptionsRes,
|
|
8331
10887
|
Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -8372,18 +10928,26 @@ init_index();
|
|
|
8372
10928
|
TLV_UPLOAD_ID,
|
|
8373
10929
|
TLV_VALIDATORS_KEY,
|
|
8374
10930
|
TLV_WRIT,
|
|
10931
|
+
TickAuthSensor,
|
|
10932
|
+
TimelineEngine,
|
|
8375
10933
|
TlvEnum,
|
|
8376
10934
|
TlvField,
|
|
8377
10935
|
TlvMinLen,
|
|
8378
10936
|
TlvRange,
|
|
8379
10937
|
TlvUtf8Pattern,
|
|
8380
10938
|
TlvValidate,
|
|
10939
|
+
TpsSensor,
|
|
10940
|
+
addStitchToKnot,
|
|
10941
|
+
applyStitch,
|
|
10942
|
+
assembleNeedle,
|
|
8381
10943
|
axis1SigningBytes,
|
|
8382
10944
|
b64urlDecode,
|
|
8383
10945
|
b64urlDecodeString,
|
|
8384
10946
|
b64urlEncode,
|
|
8385
10947
|
b64urlEncodeString,
|
|
10948
|
+
breakKnot,
|
|
8386
10949
|
buildAts1Hdr,
|
|
10950
|
+
buildAxisLawEvaluationContext,
|
|
8387
10951
|
buildDtoDecoder,
|
|
8388
10952
|
buildPacket,
|
|
8389
10953
|
buildQueueMessage,
|
|
@@ -8402,7 +10966,13 @@ init_index();
|
|
|
8402
10966
|
computeReceiptHash,
|
|
8403
10967
|
computeSignaturePayload,
|
|
8404
10968
|
core,
|
|
10969
|
+
createFabric,
|
|
10970
|
+
createGrant,
|
|
8405
10971
|
createObservation,
|
|
10972
|
+
createPresenceChallenge,
|
|
10973
|
+
createReceipt,
|
|
10974
|
+
createRevocation,
|
|
10975
|
+
createWrit,
|
|
8406
10976
|
crypto,
|
|
8407
10977
|
decodeArray,
|
|
8408
10978
|
decodeAxis1Frame,
|
|
@@ -8414,6 +10984,10 @@ init_index();
|
|
|
8414
10984
|
decodeVarint,
|
|
8415
10985
|
decorators,
|
|
8416
10986
|
deriveAnchorReflection,
|
|
10987
|
+
detectAnomalies,
|
|
10988
|
+
detectKnotPatterns,
|
|
10989
|
+
detectSequencePatterns,
|
|
10990
|
+
diffFabrics,
|
|
8417
10991
|
encVarint,
|
|
8418
10992
|
encodeAxis1Frame,
|
|
8419
10993
|
encodeAxisTlvDto,
|
|
@@ -8424,18 +10998,36 @@ init_index();
|
|
|
8424
10998
|
endStage,
|
|
8425
10999
|
engine,
|
|
8426
11000
|
executeCcePipeline,
|
|
11001
|
+
executeLoomPipeline,
|
|
8427
11002
|
extractDtoSchema,
|
|
8428
11003
|
finalizeObservation,
|
|
11004
|
+
findKnotsForStitch,
|
|
11005
|
+
forkFromKnot,
|
|
11006
|
+
formStitch,
|
|
8429
11007
|
generateEd25519KeyPair,
|
|
11008
|
+
getDecisionPoints,
|
|
11009
|
+
getFabricValue,
|
|
11010
|
+
getGrantStatus,
|
|
11011
|
+
getIrreversibleKnots,
|
|
11012
|
+
getPresenceStatus,
|
|
8430
11013
|
getSignTarget,
|
|
11014
|
+
grantCoversAction,
|
|
8431
11015
|
hasScope,
|
|
8432
11016
|
hashObservation,
|
|
11017
|
+
idel,
|
|
8433
11018
|
isAdminOpcode,
|
|
11019
|
+
isKnotOpen,
|
|
8434
11020
|
isKnownOpcode,
|
|
11021
|
+
isPointOfNoReturn,
|
|
11022
|
+
isRevoked,
|
|
8435
11023
|
isTimestampValid,
|
|
11024
|
+
lockCells,
|
|
8436
11025
|
loom,
|
|
11026
|
+
matchPatterns,
|
|
11027
|
+
needle,
|
|
8437
11028
|
nonce16,
|
|
8438
11029
|
normalizeSensorDecision,
|
|
11030
|
+
openKnot,
|
|
8439
11031
|
packPasskeyLoginOptionsReq,
|
|
8440
11032
|
packPasskeyLoginOptionsRes,
|
|
8441
11033
|
packPasskeyLoginVerifyReq,
|
|
@@ -8444,27 +11036,44 @@ init_index();
|
|
|
8444
11036
|
parseAutoClaimEntries,
|
|
8445
11037
|
parseScope,
|
|
8446
11038
|
parseStreamEntries,
|
|
11039
|
+
projectAt,
|
|
11040
|
+
queryFabric,
|
|
11041
|
+
recordOccurrence,
|
|
8447
11042
|
recordSensor,
|
|
11043
|
+
renewPresence,
|
|
8448
11044
|
resolveTimeout,
|
|
11045
|
+
runNeedlePipeline,
|
|
8449
11046
|
schemas,
|
|
11047
|
+
scoreTruth,
|
|
8450
11048
|
security,
|
|
8451
11049
|
sensitivityName,
|
|
8452
11050
|
sensors,
|
|
8453
11051
|
sha256,
|
|
8454
11052
|
signFrame,
|
|
11053
|
+
signPresenceChallenge,
|
|
8455
11054
|
stableJsonStringify,
|
|
8456
11055
|
startStage,
|
|
11056
|
+
tieKnot,
|
|
11057
|
+
timeline,
|
|
8457
11058
|
tlv,
|
|
8458
11059
|
u64be,
|
|
8459
11060
|
unpackPasskeyLoginOptionsReq,
|
|
8460
11061
|
unpackPasskeyLoginVerifyReq,
|
|
8461
11062
|
unpackPasskeyRegisterOptionsReq,
|
|
11063
|
+
updateThreadState,
|
|
8462
11064
|
utf8,
|
|
8463
11065
|
utils,
|
|
8464
11066
|
validateFrameShape,
|
|
11067
|
+
validateGrant,
|
|
11068
|
+
validateKnot,
|
|
11069
|
+
validateWrit,
|
|
8465
11070
|
varintLength,
|
|
8466
11071
|
varintU,
|
|
8467
11072
|
verifyFrameSignature,
|
|
8468
|
-
|
|
11073
|
+
verifyObservation,
|
|
11074
|
+
verifyPresenceProof,
|
|
11075
|
+
verifyReceiptChain,
|
|
11076
|
+
verifyResponse,
|
|
11077
|
+
weave
|
|
8469
11078
|
});
|
|
8470
11079
|
//# sourceMappingURL=index.js.map
|