@nextera.one/axis-server-sdk 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +1340 -480
- package/dist/index.d.ts +1340 -480
- package/dist/index.js +2952 -372
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2958 -364
- 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
|
@@ -334,76 +334,90 @@ var init_sensor_decorator = __esm({
|
|
|
334
334
|
});
|
|
335
335
|
|
|
336
336
|
// src/decorators/tlv-field.decorator.ts
|
|
337
|
-
var
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
362
|
-
const prop = String(propertyKey);
|
|
363
|
-
let entry = existing.find((e) => e.property === prop);
|
|
364
|
-
if (!entry) {
|
|
365
|
-
entry = { property: prop, tag: 0, validators: [] };
|
|
366
|
-
existing.push(entry);
|
|
337
|
+
var require_tlv_field_decorator = __commonJS({
|
|
338
|
+
"src/decorators/tlv-field.decorator.ts"(exports2) {
|
|
339
|
+
"use strict";
|
|
340
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
341
|
+
exports2.TLV_VALIDATORS_KEY = exports2.TLV_FIELDS_KEY = void 0;
|
|
342
|
+
exports2.TlvField = TlvField2;
|
|
343
|
+
exports2.TlvValidate = TlvValidate2;
|
|
344
|
+
exports2.TlvUtf8Pattern = TlvUtf8Pattern2;
|
|
345
|
+
exports2.TlvMinLen = TlvMinLen2;
|
|
346
|
+
exports2.TlvEnum = TlvEnum2;
|
|
347
|
+
exports2.TlvRange = TlvRange2;
|
|
348
|
+
require("reflect-metadata");
|
|
349
|
+
exports2.TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
350
|
+
exports2.TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
351
|
+
var textDecoder = new TextDecoder();
|
|
352
|
+
function assertUniqueFieldMetadata(existing, property, tag) {
|
|
353
|
+
const duplicateProperty = existing.find((item) => item.property === property);
|
|
354
|
+
if (duplicateProperty) {
|
|
355
|
+
throw new Error(`Duplicate @TlvField for property ${property}`);
|
|
356
|
+
}
|
|
357
|
+
const duplicateTag = existing.find((item) => item.tag === tag);
|
|
358
|
+
if (duplicateTag) {
|
|
359
|
+
throw new Error(`Duplicate @TlvField tag ${tag} for ${property}; already used by ${duplicateTag.property}`);
|
|
360
|
+
}
|
|
367
361
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return
|
|
362
|
+
function TlvField2(tag, options) {
|
|
363
|
+
return (target, propertyKey) => {
|
|
364
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_FIELDS_KEY, target.constructor) || [];
|
|
365
|
+
const property = String(propertyKey);
|
|
366
|
+
assertUniqueFieldMetadata(existing, property, tag);
|
|
367
|
+
existing.push({
|
|
368
|
+
property,
|
|
369
|
+
tag,
|
|
370
|
+
options
|
|
371
|
+
});
|
|
372
|
+
Reflect.defineMetadata(exports2.TLV_FIELDS_KEY, existing, target.constructor);
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function TlvValidate2(validator) {
|
|
376
|
+
return (target, propertyKey) => {
|
|
377
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
378
|
+
const prop = String(propertyKey);
|
|
379
|
+
let entry = existing.find((e) => e.property === prop);
|
|
380
|
+
if (!entry) {
|
|
381
|
+
entry = { property: prop, tag: 0, validators: [] };
|
|
382
|
+
existing.push(entry);
|
|
383
|
+
}
|
|
384
|
+
entry.validators.push(validator);
|
|
385
|
+
Reflect.defineMetadata(exports2.TLV_VALIDATORS_KEY, existing, target.constructor);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function TlvUtf8Pattern2(pattern, message) {
|
|
389
|
+
const matcher = new RegExp(pattern.source, pattern.flags);
|
|
390
|
+
return TlvValidate2((val, prop) => {
|
|
391
|
+
const str = textDecoder.decode(val);
|
|
392
|
+
matcher.lastIndex = 0;
|
|
393
|
+
return matcher.test(str) ? null : message || `${prop}: failed pattern check`;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function TlvMinLen2(min, message) {
|
|
397
|
+
return TlvValidate2((val, prop) => {
|
|
398
|
+
return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function TlvEnum2(allowed, message) {
|
|
402
|
+
const set = new Set(allowed);
|
|
403
|
+
return TlvValidate2((val, prop) => {
|
|
404
|
+
const str = textDecoder.decode(val);
|
|
405
|
+
return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function TlvRange2(min, max, message) {
|
|
409
|
+
return TlvValidate2((val, prop) => {
|
|
410
|
+
if (val.length !== 8)
|
|
411
|
+
return `${prop}: u64 must be 8 bytes`;
|
|
412
|
+
let n = 0n;
|
|
413
|
+
for (const b of val)
|
|
414
|
+
n = n << 8n | BigInt(b);
|
|
415
|
+
if (n < min || n > max) {
|
|
416
|
+
return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
});
|
|
397
420
|
}
|
|
398
|
-
return null;
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
var import_reflect_metadata8, TLV_FIELDS_KEY, TLV_VALIDATORS_KEY;
|
|
402
|
-
var init_tlv_field_decorator = __esm({
|
|
403
|
-
"src/decorators/tlv-field.decorator.ts"() {
|
|
404
|
-
import_reflect_metadata8 = require("reflect-metadata");
|
|
405
|
-
TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
406
|
-
TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
407
421
|
}
|
|
408
422
|
});
|
|
409
423
|
|
|
@@ -432,7 +446,7 @@ var require_dto_schema_util = __commonJS({
|
|
|
432
446
|
exports2.extractDtoSchema = extractDtoSchema2;
|
|
433
447
|
exports2.buildDtoDecoder = buildDtoDecoder2;
|
|
434
448
|
require("reflect-metadata");
|
|
435
|
-
var tlv_field_decorator_1 = (
|
|
449
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
436
450
|
var tlv_1 = (init_tlv(), __toCommonJS(tlv_exports));
|
|
437
451
|
function extractDtoSchema2(dto) {
|
|
438
452
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
@@ -541,7 +555,7 @@ var require_axis_id_dto = __commonJS({
|
|
|
541
555
|
};
|
|
542
556
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
543
557
|
exports2.AxisIdDto = void 0;
|
|
544
|
-
var tlv_field_decorator_1 = (
|
|
558
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
545
559
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
546
560
|
var AxisIdDto2 = class extends axis_tlv_dto_1.AxisTlvDto {
|
|
547
561
|
};
|
|
@@ -558,27 +572,27 @@ var require_axis_id_dto = __commonJS({
|
|
|
558
572
|
function AxisPartialType(BaseDto) {
|
|
559
573
|
class PartialDto extends BaseDto {
|
|
560
574
|
}
|
|
561
|
-
const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
|
|
575
|
+
const fields = Reflect.getOwnMetadata(import_tlv_field.TLV_FIELDS_KEY, BaseDto) || [];
|
|
562
576
|
const partialFields = fields.map((f) => ({
|
|
563
577
|
property: f.property,
|
|
564
578
|
tag: f.tag,
|
|
565
579
|
options: { ...f.options, required: false }
|
|
566
580
|
}));
|
|
567
|
-
Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
568
|
-
const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
581
|
+
Reflect.defineMetadata(import_tlv_field.TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
582
|
+
const validators = Reflect.getOwnMetadata(import_tlv_field.TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
569
583
|
if (validators.length > 0) {
|
|
570
|
-
Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
584
|
+
Reflect.defineMetadata(import_tlv_field.TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
571
585
|
}
|
|
572
586
|
Object.defineProperty(PartialDto, "name", {
|
|
573
587
|
value: `Partial${BaseDto.name}`
|
|
574
588
|
});
|
|
575
589
|
return PartialDto;
|
|
576
590
|
}
|
|
577
|
-
var
|
|
591
|
+
var import_reflect_metadata8, import_tlv_field;
|
|
578
592
|
var init_axis_partial_type = __esm({
|
|
579
593
|
"src/base/axis-partial-type.ts"() {
|
|
580
|
-
|
|
581
|
-
|
|
594
|
+
import_reflect_metadata8 = require("reflect-metadata");
|
|
595
|
+
import_tlv_field = __toESM(require_tlv_field_decorator());
|
|
582
596
|
}
|
|
583
597
|
});
|
|
584
598
|
|
|
@@ -597,7 +611,7 @@ var require_axis_response_dto = __commonJS({
|
|
|
597
611
|
};
|
|
598
612
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
599
613
|
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;
|
|
600
|
-
var tlv_field_decorator_1 = (
|
|
614
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
601
615
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
602
616
|
exports2.RESPONSE_TAG_ID = 1;
|
|
603
617
|
exports2.RESPONSE_TAG_CREATED_AT = 2;
|
|
@@ -3252,6 +3266,213 @@ var init_observation_hash = __esm({
|
|
|
3252
3266
|
}
|
|
3253
3267
|
});
|
|
3254
3268
|
|
|
3269
|
+
// src/engine/observation/truth-scoring.ts
|
|
3270
|
+
function scoreTruth(obs, expected) {
|
|
3271
|
+
const anomalies = [];
|
|
3272
|
+
let passedChecks = 0;
|
|
3273
|
+
let totalChecks = 0;
|
|
3274
|
+
totalChecks++;
|
|
3275
|
+
if (obs.endMs && obs.decision) {
|
|
3276
|
+
passedChecks++;
|
|
3277
|
+
} else {
|
|
3278
|
+
anomalies.push({
|
|
3279
|
+
code: "OBS_NOT_FINALIZED",
|
|
3280
|
+
level: "critical",
|
|
3281
|
+
message: "Observation was not finalized"
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
totalChecks++;
|
|
3285
|
+
if (obs.stages.length > 0) {
|
|
3286
|
+
passedChecks++;
|
|
3287
|
+
} else {
|
|
3288
|
+
anomalies.push({
|
|
3289
|
+
code: "OBS_NO_STAGES",
|
|
3290
|
+
level: "warning",
|
|
3291
|
+
message: "Observation has no execution stages"
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
totalChecks++;
|
|
3295
|
+
const failedStages = obs.stages.filter((s) => s.status === "fail");
|
|
3296
|
+
if (failedStages.length === 0 || obs.decision === "DENY") {
|
|
3297
|
+
passedChecks++;
|
|
3298
|
+
} else {
|
|
3299
|
+
for (const stage of failedStages) {
|
|
3300
|
+
anomalies.push({
|
|
3301
|
+
code: "STAGE_FAILED",
|
|
3302
|
+
level: "warning",
|
|
3303
|
+
message: `Stage '${stage.name}' failed: ${stage.reason ?? "unknown"}`,
|
|
3304
|
+
field: `stages.${stage.name}`
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
totalChecks++;
|
|
3309
|
+
const invalidSensors = obs.sensors.filter((s) => s.durationMs < 0);
|
|
3310
|
+
if (invalidSensors.length === 0) {
|
|
3311
|
+
passedChecks++;
|
|
3312
|
+
} else {
|
|
3313
|
+
anomalies.push({
|
|
3314
|
+
code: "SENSOR_INVALID_TIMING",
|
|
3315
|
+
level: "warning",
|
|
3316
|
+
message: `${invalidSensors.length} sensor(s) have negative duration`
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
totalChecks++;
|
|
3320
|
+
if (obs.durationMs !== void 0 && obs.durationMs >= 0 && obs.durationMs < 3e5) {
|
|
3321
|
+
passedChecks++;
|
|
3322
|
+
} else {
|
|
3323
|
+
anomalies.push({
|
|
3324
|
+
code: "OBS_DURATION_ANOMALY",
|
|
3325
|
+
level: "warning",
|
|
3326
|
+
message: `Observation duration ${obs.durationMs}ms is suspicious`,
|
|
3327
|
+
actual: obs.durationMs
|
|
3328
|
+
});
|
|
3329
|
+
}
|
|
3330
|
+
if (expected) {
|
|
3331
|
+
if (expected.decision !== void 0) {
|
|
3332
|
+
totalChecks++;
|
|
3333
|
+
if (obs.decision === expected.decision) {
|
|
3334
|
+
passedChecks++;
|
|
3335
|
+
} else {
|
|
3336
|
+
anomalies.push({
|
|
3337
|
+
code: "DECISION_MISMATCH",
|
|
3338
|
+
level: "critical",
|
|
3339
|
+
message: `Expected decision '${expected.decision}', got '${obs.decision}'`,
|
|
3340
|
+
field: "decision",
|
|
3341
|
+
expected: expected.decision,
|
|
3342
|
+
actual: obs.decision
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
if (expected.statusCode !== void 0) {
|
|
3347
|
+
totalChecks++;
|
|
3348
|
+
if (obs.statusCode === expected.statusCode) {
|
|
3349
|
+
passedChecks++;
|
|
3350
|
+
} else {
|
|
3351
|
+
anomalies.push({
|
|
3352
|
+
code: "STATUS_MISMATCH",
|
|
3353
|
+
level: "warning",
|
|
3354
|
+
message: `Expected status ${expected.statusCode}, got ${obs.statusCode}`,
|
|
3355
|
+
field: "statusCode",
|
|
3356
|
+
expected: expected.statusCode,
|
|
3357
|
+
actual: obs.statusCode
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
if (expected.effect !== void 0) {
|
|
3362
|
+
totalChecks++;
|
|
3363
|
+
if (obs.resultCode === expected.effect || obs.facts?.effect === expected.effect) {
|
|
3364
|
+
passedChecks++;
|
|
3365
|
+
} else {
|
|
3366
|
+
anomalies.push({
|
|
3367
|
+
code: "EFFECT_MISMATCH",
|
|
3368
|
+
level: "warning",
|
|
3369
|
+
message: `Expected effect '${expected.effect}', got '${obs.resultCode}'`,
|
|
3370
|
+
field: "resultCode",
|
|
3371
|
+
expected: expected.effect,
|
|
3372
|
+
actual: obs.resultCode
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
if (expected.maxDurationMs !== void 0) {
|
|
3377
|
+
totalChecks++;
|
|
3378
|
+
if (obs.durationMs !== void 0 && obs.durationMs <= expected.maxDurationMs) {
|
|
3379
|
+
passedChecks++;
|
|
3380
|
+
} else {
|
|
3381
|
+
anomalies.push({
|
|
3382
|
+
code: "DURATION_EXCEEDED",
|
|
3383
|
+
level: "warning",
|
|
3384
|
+
message: `Execution took ${obs.durationMs}ms, max allowed ${expected.maxDurationMs}ms`,
|
|
3385
|
+
field: "durationMs",
|
|
3386
|
+
expected: expected.maxDurationMs,
|
|
3387
|
+
actual: obs.durationMs
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
if (expected.minSensorsPassed !== void 0) {
|
|
3392
|
+
totalChecks++;
|
|
3393
|
+
const passed = obs.sensors.filter((s) => s.allowed).length;
|
|
3394
|
+
if (passed >= expected.minSensorsPassed) {
|
|
3395
|
+
passedChecks++;
|
|
3396
|
+
} else {
|
|
3397
|
+
anomalies.push({
|
|
3398
|
+
code: "INSUFFICIENT_SENSORS",
|
|
3399
|
+
level: "warning",
|
|
3400
|
+
message: `Only ${passed} sensors passed, minimum required ${expected.minSensorsPassed}`,
|
|
3401
|
+
field: "sensors",
|
|
3402
|
+
expected: expected.minSensorsPassed,
|
|
3403
|
+
actual: passed
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
if (expected.assertions) {
|
|
3408
|
+
for (const [key, expectedValue] of Object.entries(expected.assertions)) {
|
|
3409
|
+
totalChecks++;
|
|
3410
|
+
const actualValue = obs.facts[key];
|
|
3411
|
+
if (deepEqual(actualValue, expectedValue)) {
|
|
3412
|
+
passedChecks++;
|
|
3413
|
+
} else {
|
|
3414
|
+
anomalies.push({
|
|
3415
|
+
code: "ASSERTION_FAILED",
|
|
3416
|
+
level: "warning",
|
|
3417
|
+
message: `Assertion failed for facts.${key}`,
|
|
3418
|
+
field: `facts.${key}`,
|
|
3419
|
+
expected: expectedValue,
|
|
3420
|
+
actual: actualValue
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
const confidence = totalChecks > 0 ? passedChecks / totalChecks : 0;
|
|
3427
|
+
const hasCritical = anomalies.some((a) => a.level === "critical");
|
|
3428
|
+
const status = computeTruthStatus(confidence, hasCritical, anomalies.length);
|
|
3429
|
+
const isDeed = status === "confirmed" || status === "partial" && !hasCritical;
|
|
3430
|
+
return {
|
|
3431
|
+
status,
|
|
3432
|
+
confidence,
|
|
3433
|
+
anomalies,
|
|
3434
|
+
passedChecks,
|
|
3435
|
+
totalChecks,
|
|
3436
|
+
verifiedAt: Date.now(),
|
|
3437
|
+
isDeed
|
|
3438
|
+
};
|
|
3439
|
+
}
|
|
3440
|
+
function computeTruthStatus(confidence, hasCritical, anomalyCount) {
|
|
3441
|
+
if (hasCritical) return "failed";
|
|
3442
|
+
if (confidence === 1) return "confirmed";
|
|
3443
|
+
if (confidence >= 0.8) return "partial";
|
|
3444
|
+
if (confidence >= 0.5) return "uncertain";
|
|
3445
|
+
return "disputed";
|
|
3446
|
+
}
|
|
3447
|
+
function verifyObservation(obs, expected) {
|
|
3448
|
+
const verdict = scoreTruth(obs, expected);
|
|
3449
|
+
return { observation: obs, verdict };
|
|
3450
|
+
}
|
|
3451
|
+
function deepEqual(a, b) {
|
|
3452
|
+
if (a === b) return true;
|
|
3453
|
+
if (a === null || b === null) return false;
|
|
3454
|
+
if (typeof a !== typeof b) return false;
|
|
3455
|
+
if (typeof a !== "object") return String(a) === String(b);
|
|
3456
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
3457
|
+
if (a.length !== b.length) return false;
|
|
3458
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
3459
|
+
}
|
|
3460
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
3461
|
+
const aKeys = Object.keys(a);
|
|
3462
|
+
const bKeys = Object.keys(b);
|
|
3463
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
3464
|
+
return aKeys.every(
|
|
3465
|
+
(key) => deepEqual(
|
|
3466
|
+
a[key],
|
|
3467
|
+
b[key]
|
|
3468
|
+
)
|
|
3469
|
+
);
|
|
3470
|
+
}
|
|
3471
|
+
var init_truth_scoring = __esm({
|
|
3472
|
+
"src/engine/observation/truth-scoring.ts"() {
|
|
3473
|
+
}
|
|
3474
|
+
});
|
|
3475
|
+
|
|
3255
3476
|
// src/engine/observation/response-observer.ts
|
|
3256
3477
|
function verifyResponse(ctx, response) {
|
|
3257
3478
|
if (!response.effect || typeof response.effect !== "string") {
|
|
@@ -3322,97 +3543,15 @@ var init_varint = __esm({
|
|
|
3322
3543
|
var axis_bin_exports = {};
|
|
3323
3544
|
__export(axis_bin_exports, {
|
|
3324
3545
|
AxisFrameZ: () => AxisFrameZ,
|
|
3325
|
-
decodeFrame: () => decodeFrame,
|
|
3326
|
-
encodeFrame: () => encodeFrame,
|
|
3327
|
-
getSignTarget: () => getSignTarget
|
|
3328
|
-
});
|
|
3329
|
-
|
|
3330
|
-
const hdrBytes = (0, import_axis_protocol.encodeTLVs)(
|
|
3331
|
-
Array.from(frame.headers.entries()).map(([t, v]) => ({
|
|
3332
|
-
type: t,
|
|
3333
|
-
value: v
|
|
3334
|
-
}))
|
|
3335
|
-
);
|
|
3336
|
-
if (hdrBytes.length > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header too large");
|
|
3337
|
-
if (frame.body.length > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body too large");
|
|
3338
|
-
if (frame.sig.length > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature too large");
|
|
3339
|
-
const hdrLenBytes = (0, import_axis_protocol3.encodeVarint)(hdrBytes.length);
|
|
3340
|
-
const bodyLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.body.length);
|
|
3341
|
-
const sigLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.sig.length);
|
|
3342
|
-
const totalLen = 5 + // Magic (AXIS1)
|
|
3343
|
-
1 + // Version
|
|
3344
|
-
1 + // Flags
|
|
3345
|
-
hdrLenBytes.length + bodyLenBytes.length + sigLenBytes.length + hdrBytes.length + frame.body.length + frame.sig.length;
|
|
3346
|
-
if (totalLen > import_axis_protocol2.MAX_FRAME_LEN) throw new Error("Total frame too large");
|
|
3347
|
-
const buf = new Uint8Array(totalLen);
|
|
3348
|
-
let offset = 0;
|
|
3349
|
-
buf.set(import_axis_protocol2.AXIS_MAGIC, offset);
|
|
3350
|
-
offset += 5;
|
|
3351
|
-
buf[offset++] = import_axis_protocol2.AXIS_VERSION;
|
|
3352
|
-
buf[offset++] = frame.flags;
|
|
3353
|
-
buf.set(hdrLenBytes, offset);
|
|
3354
|
-
offset += hdrLenBytes.length;
|
|
3355
|
-
buf.set(bodyLenBytes, offset);
|
|
3356
|
-
offset += bodyLenBytes.length;
|
|
3357
|
-
buf.set(sigLenBytes, offset);
|
|
3358
|
-
offset += sigLenBytes.length;
|
|
3359
|
-
buf.set(hdrBytes, offset);
|
|
3360
|
-
offset += hdrBytes.length;
|
|
3361
|
-
buf.set(frame.body, offset);
|
|
3362
|
-
offset += frame.body.length;
|
|
3363
|
-
buf.set(frame.sig, offset);
|
|
3364
|
-
offset += frame.sig.length;
|
|
3365
|
-
return buf;
|
|
3366
|
-
}
|
|
3367
|
-
function decodeFrame(buf) {
|
|
3368
|
-
let offset = 0;
|
|
3369
|
-
if (offset + 5 > buf.length) throw new Error("Packet too short");
|
|
3370
|
-
for (let i = 0; i < 5; i++) {
|
|
3371
|
-
if (buf[offset + i] !== import_axis_protocol2.AXIS_MAGIC[i]) throw new Error("Invalid Magic");
|
|
3372
|
-
}
|
|
3373
|
-
offset += 5;
|
|
3374
|
-
const ver = buf[offset++];
|
|
3375
|
-
if (ver !== import_axis_protocol2.AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);
|
|
3376
|
-
const flags = buf[offset++];
|
|
3377
|
-
const { value: hdrLen, length: hlLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3378
|
-
offset += hlLen;
|
|
3379
|
-
if (hdrLen > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header limit exceeded");
|
|
3380
|
-
const { value: bodyLen, length: blLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3381
|
-
offset += blLen;
|
|
3382
|
-
if (bodyLen > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body limit exceeded");
|
|
3383
|
-
const { value: sigLen, length: slLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3384
|
-
offset += slLen;
|
|
3385
|
-
if (sigLen > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature limit exceeded");
|
|
3386
|
-
if (offset + hdrLen + bodyLen + sigLen > buf.length) {
|
|
3387
|
-
throw new Error("Frame truncated");
|
|
3388
|
-
}
|
|
3389
|
-
const hdrBytes = buf.slice(offset, offset + hdrLen);
|
|
3390
|
-
offset += hdrLen;
|
|
3391
|
-
const bodyBytes = buf.slice(offset, offset + bodyLen);
|
|
3392
|
-
offset += bodyLen;
|
|
3393
|
-
const sigBytes = buf.slice(offset, offset + sigLen);
|
|
3394
|
-
offset += sigLen;
|
|
3395
|
-
const headers = (0, import_axis_protocol.decodeTLVs)(hdrBytes);
|
|
3396
|
-
return {
|
|
3397
|
-
flags,
|
|
3398
|
-
headers,
|
|
3399
|
-
body: bodyBytes,
|
|
3400
|
-
sig: sigBytes
|
|
3401
|
-
};
|
|
3402
|
-
}
|
|
3403
|
-
function getSignTarget(frame) {
|
|
3404
|
-
return encodeFrame({
|
|
3405
|
-
...frame,
|
|
3406
|
-
sig: new Uint8Array(0)
|
|
3407
|
-
});
|
|
3408
|
-
}
|
|
3409
|
-
var z, AxisFrameZ;
|
|
3546
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
3547
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
3548
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget
|
|
3549
|
+
});
|
|
3550
|
+
var z, import_axis_protocol4, AxisFrameZ;
|
|
3410
3551
|
var init_axis_bin = __esm({
|
|
3411
3552
|
"src/core/axis-bin.ts"() {
|
|
3412
3553
|
z = __toESM(require("zod"));
|
|
3413
|
-
|
|
3414
|
-
init_tlv();
|
|
3415
|
-
init_varint();
|
|
3554
|
+
import_axis_protocol4 = require("@nextera.one/axis-protocol");
|
|
3416
3555
|
AxisFrameZ = z.object({
|
|
3417
3556
|
/** Flag bits for protocol control (e.g., encryption, compression) */
|
|
3418
3557
|
flags: z.number().int().nonnegative(),
|
|
@@ -3431,12 +3570,7 @@ var init_axis_bin = __esm({
|
|
|
3431
3570
|
|
|
3432
3571
|
// src/core/signature.ts
|
|
3433
3572
|
function computeSignaturePayload(frame) {
|
|
3434
|
-
|
|
3435
|
-
...frame,
|
|
3436
|
-
sig: new Uint8Array(0)
|
|
3437
|
-
};
|
|
3438
|
-
const encoded = encodeFrame(frameWithoutSig);
|
|
3439
|
-
return Buffer.from(encoded);
|
|
3573
|
+
return Buffer.from((0, import_axis_protocol4.getSignTarget)(frame));
|
|
3440
3574
|
}
|
|
3441
3575
|
function signFrame(frame, privateKey) {
|
|
3442
3576
|
const payload = computeSignaturePayload(frame);
|
|
@@ -4324,7 +4458,7 @@ function encodeAxis1Frame(f) {
|
|
|
4324
4458
|
if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
|
|
4325
4459
|
throw new Error("AXIS1_BAD_BUFFERS");
|
|
4326
4460
|
}
|
|
4327
|
-
if (f.ver !==
|
|
4461
|
+
if (f.ver !== import_axis_protocol5.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
4328
4462
|
const hdrLen = encVarint(BigInt(f.hdr.length));
|
|
4329
4463
|
const bodyLen = encVarint(BigInt(f.body.length));
|
|
4330
4464
|
const sigLen = encVarint(BigInt(f.sig.length));
|
|
@@ -4340,17 +4474,18 @@ function encodeAxis1Frame(f) {
|
|
|
4340
4474
|
f.sig
|
|
4341
4475
|
]);
|
|
4342
4476
|
}
|
|
4343
|
-
var MAGIC;
|
|
4477
|
+
var import_axis_protocol5, MAGIC;
|
|
4344
4478
|
var init_axis1_encode = __esm({
|
|
4345
4479
|
"src/codec/axis1.encode.ts"() {
|
|
4480
|
+
import_axis_protocol5 = require("@nextera.one/axis-protocol");
|
|
4346
4481
|
init_tlv_encode();
|
|
4347
|
-
MAGIC = Buffer.from(
|
|
4482
|
+
MAGIC = Buffer.from(import_axis_protocol5.AXIS_MAGIC);
|
|
4348
4483
|
}
|
|
4349
4484
|
});
|
|
4350
4485
|
|
|
4351
4486
|
// src/codec/axis1.signing.ts
|
|
4352
4487
|
function axis1SigningBytes(params) {
|
|
4353
|
-
if (params.ver !==
|
|
4488
|
+
if (params.ver !== import_axis_protocol6.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
4354
4489
|
const hdrLen = encVarint(BigInt(params.hdr.length));
|
|
4355
4490
|
const bodyLen = encVarint(BigInt(params.body.length));
|
|
4356
4491
|
const sigLenZero = encVarint(0n);
|
|
@@ -4365,11 +4500,12 @@ function axis1SigningBytes(params) {
|
|
|
4365
4500
|
params.body
|
|
4366
4501
|
]);
|
|
4367
4502
|
}
|
|
4368
|
-
var MAGIC2;
|
|
4503
|
+
var import_axis_protocol6, MAGIC2;
|
|
4369
4504
|
var init_axis1_signing = __esm({
|
|
4370
4505
|
"src/codec/axis1.signing.ts"() {
|
|
4506
|
+
import_axis_protocol6 = require("@nextera.one/axis-protocol");
|
|
4371
4507
|
init_tlv_encode();
|
|
4372
|
-
MAGIC2 = Buffer.from(
|
|
4508
|
+
MAGIC2 = Buffer.from(import_axis_protocol6.AXIS_MAGIC);
|
|
4373
4509
|
}
|
|
4374
4510
|
});
|
|
4375
4511
|
|
|
@@ -4699,11 +4835,12 @@ function decodeAxis1Frame(buf) {
|
|
|
4699
4835
|
if (off !== buf.length) throw new Error("AXIS1_TRAILING_BYTES");
|
|
4700
4836
|
return { ver, flags, hdr, body, sig, frameSize: buf.length };
|
|
4701
4837
|
}
|
|
4702
|
-
var MAGIC3;
|
|
4838
|
+
var import_axis_protocol7, MAGIC3;
|
|
4703
4839
|
var init_frame = __esm({
|
|
4704
4840
|
"src/types/frame.ts"() {
|
|
4841
|
+
import_axis_protocol7 = require("@nextera.one/axis-protocol");
|
|
4705
4842
|
init_tlv2();
|
|
4706
|
-
MAGIC3 = Buffer.from(
|
|
4843
|
+
MAGIC3 = Buffer.from(import_axis_protocol7.AXIS_MAGIC);
|
|
4707
4844
|
}
|
|
4708
4845
|
});
|
|
4709
4846
|
|
|
@@ -4826,7 +4963,52 @@ var init_capabilities = __esm({
|
|
|
4826
4963
|
}
|
|
4827
4964
|
});
|
|
4828
4965
|
|
|
4966
|
+
// src/law/law.types.ts
|
|
4967
|
+
function buildAxisLawEvaluationContext(input) {
|
|
4968
|
+
const metadata = input.metadata ?? {};
|
|
4969
|
+
const packet = input.packet;
|
|
4970
|
+
const packetBody = input.frameBody ?? packet?.body ?? packet?.args ?? void 0;
|
|
4971
|
+
const capsuleId = metadata.capsule_id ?? metadata.capsuleId ?? packet?.capsuleId ?? input.clientId;
|
|
4972
|
+
const audience = input.aud ?? metadata.audience ?? packet?.aud;
|
|
4973
|
+
const tps = metadata.tps ?? packet?.tps ?? packet?.tickTps;
|
|
4974
|
+
return {
|
|
4975
|
+
actorId: input.actorId,
|
|
4976
|
+
intent: input.intent,
|
|
4977
|
+
audience,
|
|
4978
|
+
tps,
|
|
4979
|
+
country: input.country,
|
|
4980
|
+
ip: input.ip,
|
|
4981
|
+
path: input.path,
|
|
4982
|
+
clientId: input.clientId,
|
|
4983
|
+
deviceId: input.deviceId,
|
|
4984
|
+
sessionId: input.sessionId,
|
|
4985
|
+
capsuleId,
|
|
4986
|
+
metadata,
|
|
4987
|
+
packet,
|
|
4988
|
+
frameBody: packetBody
|
|
4989
|
+
};
|
|
4990
|
+
}
|
|
4991
|
+
var init_law_types = __esm({
|
|
4992
|
+
"src/law/law.types.ts"() {
|
|
4993
|
+
}
|
|
4994
|
+
});
|
|
4995
|
+
|
|
4996
|
+
// src/law/index.ts
|
|
4997
|
+
var law_exports = {};
|
|
4998
|
+
__export(law_exports, {
|
|
4999
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext
|
|
5000
|
+
});
|
|
5001
|
+
var init_law = __esm({
|
|
5002
|
+
"src/law/index.ts"() {
|
|
5003
|
+
init_law_types();
|
|
5004
|
+
}
|
|
5005
|
+
});
|
|
5006
|
+
|
|
4829
5007
|
// src/risk/index.ts
|
|
5008
|
+
var risk_exports = {};
|
|
5009
|
+
__export(risk_exports, {
|
|
5010
|
+
RiskDecision: () => RiskDecision
|
|
5011
|
+
});
|
|
4830
5012
|
var RiskDecision;
|
|
4831
5013
|
var init_risk = __esm({
|
|
4832
5014
|
"src/risk/index.ts"() {
|
|
@@ -5936,6 +6118,374 @@ var require_axis_sensor_chain_service = __commonJS({
|
|
|
5936
6118
|
}
|
|
5937
6119
|
});
|
|
5938
6120
|
|
|
6121
|
+
// src/timeline/timeline.engine.ts
|
|
6122
|
+
function generateId(prefix) {
|
|
6123
|
+
return `${prefix}_${(0, import_crypto8.randomBytes)(16).toString("hex")}`;
|
|
6124
|
+
}
|
|
6125
|
+
function sha2566(data) {
|
|
6126
|
+
return (0, import_crypto8.createHash)("sha256").update(data).digest("hex");
|
|
6127
|
+
}
|
|
6128
|
+
function hashPayload2(payload) {
|
|
6129
|
+
return sha2566(JSON.stringify(payload));
|
|
6130
|
+
}
|
|
6131
|
+
function diffObjects(a, b) {
|
|
6132
|
+
const diffs = [];
|
|
6133
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
6134
|
+
for (const key of allKeys) {
|
|
6135
|
+
const va = a[key];
|
|
6136
|
+
const vb = b[key];
|
|
6137
|
+
if (JSON.stringify(va) !== JSON.stringify(vb)) {
|
|
6138
|
+
diffs.push({ field: key, original: va, replayed: vb });
|
|
6139
|
+
}
|
|
6140
|
+
}
|
|
6141
|
+
return diffs;
|
|
6142
|
+
}
|
|
6143
|
+
var import_crypto8, TimelineEngine;
|
|
6144
|
+
var init_timeline_engine = __esm({
|
|
6145
|
+
"src/timeline/timeline.engine.ts"() {
|
|
6146
|
+
import_crypto8 = require("crypto");
|
|
6147
|
+
TimelineEngine = class {
|
|
6148
|
+
constructor(store) {
|
|
6149
|
+
this.store = store;
|
|
6150
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
6151
|
+
}
|
|
6152
|
+
/** Register an intent handler for timeline execution */
|
|
6153
|
+
registerHandler(handler) {
|
|
6154
|
+
this.handlers.set(handler.intent, handler);
|
|
6155
|
+
}
|
|
6156
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6157
|
+
// Record (store a real execution as a timeline event)
|
|
6158
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6159
|
+
async recordEvent(intent, actorId, payload, result, options = {}) {
|
|
6160
|
+
const event = {
|
|
6161
|
+
event_id: generateId("evt"),
|
|
6162
|
+
timeline_id: options.timelineId ?? "prime",
|
|
6163
|
+
branch_id: options.branchId ?? "main",
|
|
6164
|
+
parent_event_id: options.parentEventId ?? null,
|
|
6165
|
+
intent,
|
|
6166
|
+
actor_id: actorId,
|
|
6167
|
+
capsule_id: options.capsuleId,
|
|
6168
|
+
tps_coordinate: options.tpsCoordinate,
|
|
6169
|
+
payload_hash: hashPayload2(payload),
|
|
6170
|
+
result_hash: hashPayload2(result),
|
|
6171
|
+
status: "executed",
|
|
6172
|
+
domain: "prime",
|
|
6173
|
+
determinism: options.determinism ?? "deterministic",
|
|
6174
|
+
witness_id: options.witnessId,
|
|
6175
|
+
created_at: Date.now(),
|
|
6176
|
+
metadata: { payload, result }
|
|
6177
|
+
};
|
|
6178
|
+
await this.store.saveEvent(event);
|
|
6179
|
+
return event;
|
|
6180
|
+
}
|
|
6181
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6182
|
+
// Replay
|
|
6183
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6184
|
+
async replay(request) {
|
|
6185
|
+
const originalEvent = await this.store.getEvent(request.source_event_id);
|
|
6186
|
+
if (!originalEvent) {
|
|
6187
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
6188
|
+
}
|
|
6189
|
+
const handler = this.handlers.get(originalEvent.intent);
|
|
6190
|
+
if (!handler) {
|
|
6191
|
+
throw new Error(`No handler registered for intent '${originalEvent.intent}'`);
|
|
6192
|
+
}
|
|
6193
|
+
const originalPayload = originalEvent.metadata?.payload ?? {};
|
|
6194
|
+
const replayPayload = request.mode === "analytical" && request.override_payload ? request.override_payload : originalPayload;
|
|
6195
|
+
const snapshot = await this.store.getSnapshotByEvent(originalEvent.event_id);
|
|
6196
|
+
const context = {
|
|
6197
|
+
event_id: generateId("evt"),
|
|
6198
|
+
timeline_id: originalEvent.timeline_id,
|
|
6199
|
+
branch_id: `replay_${originalEvent.branch_id}`,
|
|
6200
|
+
domain: "audit",
|
|
6201
|
+
actor_id: originalEvent.actor_id,
|
|
6202
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
6203
|
+
snapshot: snapshot ?? void 0,
|
|
6204
|
+
is_replay: true,
|
|
6205
|
+
is_simulation: false
|
|
6206
|
+
};
|
|
6207
|
+
const startMs = Date.now();
|
|
6208
|
+
const handlerResult = await handler.execute(replayPayload, context);
|
|
6209
|
+
const durationMs = Date.now() - startMs;
|
|
6210
|
+
const replayedEvent = {
|
|
6211
|
+
event_id: context.event_id,
|
|
6212
|
+
timeline_id: originalEvent.timeline_id,
|
|
6213
|
+
branch_id: context.branch_id,
|
|
6214
|
+
parent_event_id: originalEvent.event_id,
|
|
6215
|
+
intent: originalEvent.intent,
|
|
6216
|
+
actor_id: originalEvent.actor_id,
|
|
6217
|
+
capsule_id: originalEvent.capsule_id,
|
|
6218
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
6219
|
+
payload_hash: hashPayload2(replayPayload),
|
|
6220
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6221
|
+
status: "replayed",
|
|
6222
|
+
domain: "audit",
|
|
6223
|
+
determinism: originalEvent.determinism,
|
|
6224
|
+
created_at: Date.now(),
|
|
6225
|
+
metadata: { payload: replayPayload, result: handlerResult.result_data }
|
|
6226
|
+
};
|
|
6227
|
+
await this.store.saveEvent(replayedEvent);
|
|
6228
|
+
const originalResult = originalEvent.metadata?.result ?? {};
|
|
6229
|
+
const differences = diffObjects(originalResult, handlerResult.result_data);
|
|
6230
|
+
const deterministicMatch = originalEvent.result_hash === replayedEvent.result_hash;
|
|
6231
|
+
return {
|
|
6232
|
+
original_event: originalEvent,
|
|
6233
|
+
replayed_event: replayedEvent,
|
|
6234
|
+
mode: request.mode,
|
|
6235
|
+
deterministic_match: deterministicMatch,
|
|
6236
|
+
differences,
|
|
6237
|
+
duration_ms: durationMs
|
|
6238
|
+
};
|
|
6239
|
+
}
|
|
6240
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6241
|
+
// Fork
|
|
6242
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6243
|
+
async fork(request) {
|
|
6244
|
+
const sourceEvent = await this.store.getEvent(request.source_event_id);
|
|
6245
|
+
if (!sourceEvent) {
|
|
6246
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
6247
|
+
}
|
|
6248
|
+
const handler = this.handlers.get(sourceEvent.intent);
|
|
6249
|
+
if (!handler) {
|
|
6250
|
+
throw new Error(`No handler registered for intent '${sourceEvent.intent}'`);
|
|
6251
|
+
}
|
|
6252
|
+
const branch = {
|
|
6253
|
+
branch_id: generateId("branch"),
|
|
6254
|
+
timeline_id: generateId("timeline"),
|
|
6255
|
+
origin_timeline_id: sourceEvent.timeline_id,
|
|
6256
|
+
origin_event_id: sourceEvent.event_id,
|
|
6257
|
+
branch_type: "fork",
|
|
6258
|
+
creator_subject_id: request.actor_id,
|
|
6259
|
+
purpose: request.purpose,
|
|
6260
|
+
status: "active"
|
|
6261
|
+
};
|
|
6262
|
+
await this.store.saveBranch(branch);
|
|
6263
|
+
const snapshot = {
|
|
6264
|
+
snapshot_id: generateId("snap"),
|
|
6265
|
+
timeline_id: sourceEvent.timeline_id,
|
|
6266
|
+
event_id: sourceEvent.event_id,
|
|
6267
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6268
|
+
state_hash: hashPayload2(
|
|
6269
|
+
sourceEvent.metadata?.result ?? {}
|
|
6270
|
+
),
|
|
6271
|
+
state_data: sourceEvent.metadata?.result ?? {},
|
|
6272
|
+
created_at: Date.now()
|
|
6273
|
+
};
|
|
6274
|
+
await this.store.saveSnapshot(snapshot);
|
|
6275
|
+
const context = {
|
|
6276
|
+
event_id: generateId("evt"),
|
|
6277
|
+
timeline_id: branch.timeline_id,
|
|
6278
|
+
branch_id: branch.branch_id,
|
|
6279
|
+
domain: "fork",
|
|
6280
|
+
actor_id: request.actor_id,
|
|
6281
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6282
|
+
snapshot,
|
|
6283
|
+
is_replay: false,
|
|
6284
|
+
is_simulation: false
|
|
6285
|
+
};
|
|
6286
|
+
const handlerResult = await handler.execute(request.new_payload, context);
|
|
6287
|
+
const forkedEvent = {
|
|
6288
|
+
event_id: context.event_id,
|
|
6289
|
+
timeline_id: branch.timeline_id,
|
|
6290
|
+
branch_id: branch.branch_id,
|
|
6291
|
+
parent_event_id: sourceEvent.event_id,
|
|
6292
|
+
intent: sourceEvent.intent,
|
|
6293
|
+
actor_id: request.actor_id,
|
|
6294
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6295
|
+
payload_hash: hashPayload2(request.new_payload),
|
|
6296
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6297
|
+
status: "forked",
|
|
6298
|
+
domain: "fork",
|
|
6299
|
+
determinism: sourceEvent.determinism,
|
|
6300
|
+
created_at: Date.now(),
|
|
6301
|
+
metadata: {
|
|
6302
|
+
payload: request.new_payload,
|
|
6303
|
+
result: handlerResult.result_data
|
|
6304
|
+
}
|
|
6305
|
+
};
|
|
6306
|
+
await this.store.saveEvent(forkedEvent);
|
|
6307
|
+
return { branch, forked_event: forkedEvent, snapshot };
|
|
6308
|
+
}
|
|
6309
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6310
|
+
// Simulate
|
|
6311
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6312
|
+
async simulate(request) {
|
|
6313
|
+
const handler = this.handlers.get(request.intent);
|
|
6314
|
+
if (!handler) {
|
|
6315
|
+
throw new Error(`No handler registered for intent '${request.intent}'`);
|
|
6316
|
+
}
|
|
6317
|
+
let snapshot;
|
|
6318
|
+
if (request.from_snapshot_id) {
|
|
6319
|
+
const loaded = await this.store.getSnapshot(request.from_snapshot_id);
|
|
6320
|
+
if (!loaded) {
|
|
6321
|
+
throw new Error(`Snapshot ${request.from_snapshot_id} not found`);
|
|
6322
|
+
}
|
|
6323
|
+
snapshot = loaded;
|
|
6324
|
+
}
|
|
6325
|
+
const branch = {
|
|
6326
|
+
branch_id: generateId("branch"),
|
|
6327
|
+
timeline_id: generateId("timeline"),
|
|
6328
|
+
origin_timeline_id: "prime",
|
|
6329
|
+
origin_event_id: "simulation_origin",
|
|
6330
|
+
branch_type: "simulation",
|
|
6331
|
+
created_at_tps: request.at_tps,
|
|
6332
|
+
creator_subject_id: request.actor_id,
|
|
6333
|
+
purpose: request.purpose,
|
|
6334
|
+
status: "active"
|
|
6335
|
+
};
|
|
6336
|
+
await this.store.saveBranch(branch);
|
|
6337
|
+
const context = {
|
|
6338
|
+
event_id: generateId("evt"),
|
|
6339
|
+
timeline_id: branch.timeline_id,
|
|
6340
|
+
branch_id: branch.branch_id,
|
|
6341
|
+
domain: "shadow",
|
|
6342
|
+
actor_id: request.actor_id,
|
|
6343
|
+
tps_coordinate: request.at_tps,
|
|
6344
|
+
snapshot,
|
|
6345
|
+
is_replay: false,
|
|
6346
|
+
is_simulation: true
|
|
6347
|
+
};
|
|
6348
|
+
const startMs = Date.now();
|
|
6349
|
+
const handlerResult = await handler.execute(request.payload, context);
|
|
6350
|
+
const durationMs = Date.now() - startMs;
|
|
6351
|
+
const simulatedEvent = {
|
|
6352
|
+
event_id: context.event_id,
|
|
6353
|
+
timeline_id: branch.timeline_id,
|
|
6354
|
+
branch_id: branch.branch_id,
|
|
6355
|
+
parent_event_id: null,
|
|
6356
|
+
intent: request.intent,
|
|
6357
|
+
actor_id: request.actor_id,
|
|
6358
|
+
tps_coordinate: request.at_tps,
|
|
6359
|
+
payload_hash: hashPayload2(request.payload),
|
|
6360
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6361
|
+
status: "simulated",
|
|
6362
|
+
domain: "shadow",
|
|
6363
|
+
determinism: "bounded_nondeterministic",
|
|
6364
|
+
created_at: Date.now(),
|
|
6365
|
+
metadata: { payload: request.payload, result: handlerResult.result_data }
|
|
6366
|
+
};
|
|
6367
|
+
await this.store.saveEvent(simulatedEvent);
|
|
6368
|
+
branch.status = "completed";
|
|
6369
|
+
await this.store.saveBranch(branch);
|
|
6370
|
+
return {
|
|
6371
|
+
branch,
|
|
6372
|
+
simulated_event: simulatedEvent,
|
|
6373
|
+
predicted_outcome: handlerResult.result_data,
|
|
6374
|
+
side_effects: handlerResult.side_effects ?? [],
|
|
6375
|
+
duration_ms: durationMs
|
|
6376
|
+
};
|
|
6377
|
+
}
|
|
6378
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6379
|
+
// Compare timelines
|
|
6380
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6381
|
+
async compare(timelineIdA, timelineIdB) {
|
|
6382
|
+
const eventsA = await this.store.getEventsByTimeline(timelineIdA);
|
|
6383
|
+
const eventsB = await this.store.getEventsByTimeline(timelineIdB);
|
|
6384
|
+
eventsA.sort((a, b) => a.created_at - b.created_at);
|
|
6385
|
+
eventsB.sort((a, b) => a.created_at - b.created_at);
|
|
6386
|
+
const maxLen = Math.max(eventsA.length, eventsB.length);
|
|
6387
|
+
const eventPairs = [];
|
|
6388
|
+
let divergencePoint;
|
|
6389
|
+
for (let i = 0; i < maxLen; i++) {
|
|
6390
|
+
const a = eventsA[i];
|
|
6391
|
+
const b = eventsB[i];
|
|
6392
|
+
if (!a || !b) {
|
|
6393
|
+
if (!divergencePoint) {
|
|
6394
|
+
divergencePoint = a?.event_id ?? b?.event_id;
|
|
6395
|
+
}
|
|
6396
|
+
continue;
|
|
6397
|
+
}
|
|
6398
|
+
const match = a.result_hash === b.result_hash;
|
|
6399
|
+
const resultA = a.metadata?.result ?? {};
|
|
6400
|
+
const resultB = b.metadata?.result ?? {};
|
|
6401
|
+
const differences = match ? [] : diffObjects(resultA, resultB);
|
|
6402
|
+
if (!match && !divergencePoint) {
|
|
6403
|
+
divergencePoint = a.event_id;
|
|
6404
|
+
}
|
|
6405
|
+
eventPairs.push({ event_a: a, event_b: b, match, differences });
|
|
6406
|
+
}
|
|
6407
|
+
return {
|
|
6408
|
+
timeline_a: timelineIdA,
|
|
6409
|
+
timeline_b: timelineIdB,
|
|
6410
|
+
event_pairs: eventPairs,
|
|
6411
|
+
divergence_point: divergencePoint
|
|
6412
|
+
};
|
|
6413
|
+
}
|
|
6414
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6415
|
+
// State snapshot management
|
|
6416
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6417
|
+
async createSnapshot(eventId, stateData) {
|
|
6418
|
+
const event = await this.store.getEvent(eventId);
|
|
6419
|
+
if (!event) {
|
|
6420
|
+
throw new Error(`Event ${eventId} not found`);
|
|
6421
|
+
}
|
|
6422
|
+
const snapshot = {
|
|
6423
|
+
snapshot_id: generateId("snap"),
|
|
6424
|
+
timeline_id: event.timeline_id,
|
|
6425
|
+
event_id: eventId,
|
|
6426
|
+
tps_coordinate: event.tps_coordinate,
|
|
6427
|
+
state_hash: hashPayload2(stateData),
|
|
6428
|
+
state_data: stateData,
|
|
6429
|
+
created_at: Date.now()
|
|
6430
|
+
};
|
|
6431
|
+
await this.store.saveSnapshot(snapshot);
|
|
6432
|
+
return snapshot;
|
|
6433
|
+
}
|
|
6434
|
+
async restoreSnapshot(snapshotId) {
|
|
6435
|
+
const snapshot = await this.store.getSnapshot(snapshotId);
|
|
6436
|
+
if (!snapshot) {
|
|
6437
|
+
throw new Error(`Snapshot ${snapshotId} not found`);
|
|
6438
|
+
}
|
|
6439
|
+
return snapshot;
|
|
6440
|
+
}
|
|
6441
|
+
};
|
|
6442
|
+
}
|
|
6443
|
+
});
|
|
6444
|
+
|
|
6445
|
+
// src/timeline/timeline.store.ts
|
|
6446
|
+
var InMemoryTimelineStore;
|
|
6447
|
+
var init_timeline_store = __esm({
|
|
6448
|
+
"src/timeline/timeline.store.ts"() {
|
|
6449
|
+
InMemoryTimelineStore = class {
|
|
6450
|
+
constructor() {
|
|
6451
|
+
this.events = /* @__PURE__ */ new Map();
|
|
6452
|
+
this.branches = /* @__PURE__ */ new Map();
|
|
6453
|
+
this.snapshots = /* @__PURE__ */ new Map();
|
|
6454
|
+
}
|
|
6455
|
+
async saveEvent(event) {
|
|
6456
|
+
this.events.set(event.event_id, event);
|
|
6457
|
+
}
|
|
6458
|
+
async getEvent(eventId) {
|
|
6459
|
+
return this.events.get(eventId) ?? null;
|
|
6460
|
+
}
|
|
6461
|
+
async getEventsByTimeline(timelineId) {
|
|
6462
|
+
return [...this.events.values()].filter((e) => e.timeline_id === timelineId);
|
|
6463
|
+
}
|
|
6464
|
+
async getEventsByBranch(branchId) {
|
|
6465
|
+
return [...this.events.values()].filter((e) => e.branch_id === branchId);
|
|
6466
|
+
}
|
|
6467
|
+
async saveBranch(branch) {
|
|
6468
|
+
this.branches.set(branch.branch_id, branch);
|
|
6469
|
+
}
|
|
6470
|
+
async getBranch(branchId) {
|
|
6471
|
+
return this.branches.get(branchId) ?? null;
|
|
6472
|
+
}
|
|
6473
|
+
async getBranchesByTimeline(timelineId) {
|
|
6474
|
+
return [...this.branches.values()].filter((b) => b.timeline_id === timelineId);
|
|
6475
|
+
}
|
|
6476
|
+
async saveSnapshot(snapshot) {
|
|
6477
|
+
this.snapshots.set(snapshot.snapshot_id, snapshot);
|
|
6478
|
+
}
|
|
6479
|
+
async getSnapshot(snapshotId) {
|
|
6480
|
+
return this.snapshots.get(snapshotId) ?? null;
|
|
6481
|
+
}
|
|
6482
|
+
async getSnapshotByEvent(eventId) {
|
|
6483
|
+
return [...this.snapshots.values()].find((s) => s.event_id === eventId) ?? null;
|
|
6484
|
+
}
|
|
6485
|
+
};
|
|
6486
|
+
}
|
|
6487
|
+
});
|
|
6488
|
+
|
|
5939
6489
|
// src/utils/axis-tlv-codec.ts
|
|
5940
6490
|
function encodeAxisTlvDto(dtoClass, data) {
|
|
5941
6491
|
const schema = (0, import_dto_schema.extractDtoSchema)(dtoClass);
|
|
@@ -6028,98 +6578,1813 @@ var init_loom_types = __esm({
|
|
|
6028
6578
|
}
|
|
6029
6579
|
});
|
|
6030
6580
|
|
|
6031
|
-
// src/
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6581
|
+
// src/loom/loom.engine.ts
|
|
6582
|
+
function sha2567(data) {
|
|
6583
|
+
return (0, import_crypto9.createHash)("sha256").update(data).digest("hex");
|
|
6584
|
+
}
|
|
6585
|
+
function hexToUint8(hex) {
|
|
6586
|
+
const bytes2 = new Uint8Array(hex.length / 2);
|
|
6587
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
6588
|
+
bytes2[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
6589
|
+
}
|
|
6590
|
+
return bytes2;
|
|
6591
|
+
}
|
|
6592
|
+
function uint8ToHex(bytes2) {
|
|
6593
|
+
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6594
|
+
}
|
|
6595
|
+
function b64ToUint8(b64) {
|
|
6596
|
+
const bin = Buffer.from(b64, "base64");
|
|
6597
|
+
return new Uint8Array(bin.buffer, bin.byteOffset, bin.byteLength);
|
|
6598
|
+
}
|
|
6599
|
+
function uint8ToB64(bytes2) {
|
|
6600
|
+
return Buffer.from(bytes2).toString("base64");
|
|
6601
|
+
}
|
|
6602
|
+
function createPresenceChallenge(declaration, ttlMs = DEFAULT_PRESENCE_TTL_MS) {
|
|
6603
|
+
const now = Date.now();
|
|
6604
|
+
const nonce = (0, import_crypto9.randomBytes)(32).toString("hex");
|
|
6605
|
+
const challengeId = sha2567(`${declaration.softid}:${nonce}:${now}`);
|
|
6606
|
+
return {
|
|
6607
|
+
challenge_id: challengeId,
|
|
6608
|
+
nonce,
|
|
6609
|
+
temporal_anchor: now,
|
|
6610
|
+
ttl_ms: ttlMs,
|
|
6611
|
+
expires_at: now + ttlMs
|
|
6612
|
+
};
|
|
6613
|
+
}
|
|
6614
|
+
function presenceSigningData(challenge, deviceMeta) {
|
|
6615
|
+
return JSON.stringify({
|
|
6616
|
+
nonce: challenge.nonce,
|
|
6617
|
+
temporal_anchor: challenge.temporal_anchor,
|
|
6618
|
+
device_meta: deviceMeta ?? null
|
|
6619
|
+
});
|
|
6620
|
+
}
|
|
6621
|
+
function signPresenceChallenge(challenge, privateKeyHex, publicKeyHex, declaration, kid) {
|
|
6622
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
6623
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
6624
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6625
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6626
|
+
return {
|
|
6627
|
+
challenge_id: challenge.challenge_id,
|
|
6628
|
+
signature: uint8ToHex(signature),
|
|
6629
|
+
public_key: publicKeyHex,
|
|
6630
|
+
kid
|
|
6631
|
+
};
|
|
6632
|
+
}
|
|
6633
|
+
function verifyPresenceProof(challenge, proof, declaration, durationMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
6634
|
+
if (Date.now() > challenge.expires_at) {
|
|
6635
|
+
return { valid: false, error: "Challenge expired", code: "CHALLENGE_EXPIRED" };
|
|
6636
|
+
}
|
|
6637
|
+
if (proof.challenge_id !== challenge.challenge_id) {
|
|
6638
|
+
return { valid: false, error: "Challenge ID mismatch", code: "CHALLENGE_MISMATCH" };
|
|
6639
|
+
}
|
|
6640
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
6641
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
6642
|
+
const sigBytes = hexToUint8(proof.signature);
|
|
6643
|
+
const pubBytes = hexToUint8(proof.public_key);
|
|
6644
|
+
let isValid;
|
|
6645
|
+
try {
|
|
6646
|
+
isValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
6647
|
+
} catch {
|
|
6648
|
+
return { valid: false, error: "Signature verification failed", code: "SIG_INVALID" };
|
|
6649
|
+
}
|
|
6650
|
+
if (!isValid) {
|
|
6651
|
+
return { valid: false, error: "Invalid signature", code: "SIG_INVALID" };
|
|
6652
|
+
}
|
|
6653
|
+
const now = Date.now();
|
|
6654
|
+
const presenceId = sha2567(
|
|
6655
|
+
`${proof.public_key}:${challenge.nonce}:${challenge.temporal_anchor}`
|
|
6656
|
+
);
|
|
6657
|
+
const anchorReflection = sha2567(
|
|
6658
|
+
`ar:openlogs:loom:${proof.public_key}`
|
|
6659
|
+
);
|
|
6660
|
+
const receipt = {
|
|
6661
|
+
presence_id: presenceId,
|
|
6662
|
+
softid: declaration.softid,
|
|
6663
|
+
anchor_reflection: anchorReflection,
|
|
6664
|
+
scope: {
|
|
6665
|
+
device_fingerprint: declaration.device_meta?.fingerprint
|
|
6666
|
+
},
|
|
6667
|
+
issued_at: now,
|
|
6668
|
+
expires_at: now + durationMs
|
|
6669
|
+
};
|
|
6670
|
+
return { valid: true, presence: receipt };
|
|
6671
|
+
}
|
|
6672
|
+
function getPresenceStatus(receipt) {
|
|
6673
|
+
const now = Date.now();
|
|
6674
|
+
if (now > receipt.expires_at) return "expired";
|
|
6675
|
+
return "active";
|
|
6676
|
+
}
|
|
6677
|
+
function renewPresence(receipt, extensionMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
6678
|
+
const now = Date.now();
|
|
6679
|
+
return {
|
|
6680
|
+
...receipt,
|
|
6681
|
+
renewed_at: now,
|
|
6682
|
+
expires_at: now + extensionMs
|
|
6683
|
+
};
|
|
6684
|
+
}
|
|
6685
|
+
function createWrit(body, meta, thread, privateKeyHex, kid) {
|
|
6686
|
+
const head = { tid: thread.tid, seq: thread.seq };
|
|
6687
|
+
const writMeta = { ...meta, prev: thread.prevHash };
|
|
6688
|
+
const unsigned = { head, body, meta: writMeta };
|
|
6689
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
6690
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
6691
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6692
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6693
|
+
const sig = {
|
|
6694
|
+
alg: "ed25519",
|
|
6695
|
+
value: uint8ToB64(signature),
|
|
6696
|
+
kid
|
|
6697
|
+
};
|
|
6698
|
+
return { head, body, meta: writMeta, sig };
|
|
6699
|
+
}
|
|
6700
|
+
function validateWrit(writ, publicKeyHex, threadState, grants) {
|
|
6701
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
6702
|
+
if (now < writ.meta.iat) {
|
|
6703
|
+
return {
|
|
6704
|
+
valid: false,
|
|
6705
|
+
error: "Writ not yet valid (iat in future)",
|
|
6706
|
+
code: "TEMPORAL_NOT_YET",
|
|
6707
|
+
gate_failed: "temporal"
|
|
6708
|
+
};
|
|
6709
|
+
}
|
|
6710
|
+
if (now > writ.meta.exp) {
|
|
6711
|
+
return {
|
|
6712
|
+
valid: false,
|
|
6713
|
+
error: "Writ expired",
|
|
6714
|
+
code: "TEMPORAL_EXPIRED",
|
|
6715
|
+
gate_failed: "temporal"
|
|
6716
|
+
};
|
|
6717
|
+
}
|
|
6718
|
+
if (threadState) {
|
|
6719
|
+
if (writ.head.tid !== threadState.thread_id) {
|
|
6720
|
+
return {
|
|
6721
|
+
valid: false,
|
|
6722
|
+
error: "Thread ID mismatch",
|
|
6723
|
+
code: "CAUSAL_TID",
|
|
6724
|
+
gate_failed: "causal"
|
|
6725
|
+
};
|
|
6726
|
+
}
|
|
6727
|
+
if (writ.head.seq !== threadState.sequence + 1) {
|
|
6728
|
+
return {
|
|
6729
|
+
valid: false,
|
|
6730
|
+
error: `Expected seq ${threadState.sequence + 1}, got ${writ.head.seq}`,
|
|
6731
|
+
code: "CAUSAL_SEQ",
|
|
6732
|
+
gate_failed: "causal"
|
|
6733
|
+
};
|
|
6734
|
+
}
|
|
6735
|
+
if (writ.meta.prev !== threadState.last_receipt_hash) {
|
|
6736
|
+
return {
|
|
6737
|
+
valid: false,
|
|
6738
|
+
error: "Previous receipt hash mismatch",
|
|
6739
|
+
code: "CAUSAL_PREV",
|
|
6740
|
+
gate_failed: "causal"
|
|
6741
|
+
};
|
|
6742
|
+
}
|
|
6743
|
+
} else {
|
|
6744
|
+
if (writ.head.seq !== 1) {
|
|
6745
|
+
return {
|
|
6746
|
+
valid: false,
|
|
6747
|
+
error: "First writ in thread must have seq=1",
|
|
6748
|
+
code: "CAUSAL_FIRST_SEQ",
|
|
6749
|
+
gate_failed: "causal"
|
|
6750
|
+
};
|
|
6751
|
+
}
|
|
6752
|
+
if (writ.meta.prev !== "") {
|
|
6753
|
+
return {
|
|
6754
|
+
valid: false,
|
|
6755
|
+
error: "First writ must have empty prev hash",
|
|
6756
|
+
code: "CAUSAL_FIRST_PREV",
|
|
6757
|
+
gate_failed: "causal"
|
|
6758
|
+
};
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
if (writ.body.law !== "self") {
|
|
6762
|
+
const matchingGrant = grants.find(
|
|
6763
|
+
(g) => g.grant_id === writ.body.law && g.subject === writ.body.who && grantCoversAction(g, writ.body.act, writ.body.res, now)
|
|
6764
|
+
);
|
|
6765
|
+
if (!matchingGrant) {
|
|
6766
|
+
return {
|
|
6767
|
+
valid: false,
|
|
6768
|
+
error: `No valid grant found for law=${writ.body.law}`,
|
|
6769
|
+
code: "LEGAL_NO_GRANT",
|
|
6770
|
+
gate_failed: "legal"
|
|
6771
|
+
};
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6774
|
+
const unsigned = {
|
|
6775
|
+
head: writ.head,
|
|
6776
|
+
body: writ.body,
|
|
6777
|
+
meta: writ.meta
|
|
6778
|
+
};
|
|
6779
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
6780
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
6781
|
+
const sigBytes = b64ToUint8(writ.sig.value);
|
|
6782
|
+
const pubBytes = hexToUint8(publicKeyHex);
|
|
6783
|
+
let sigValid;
|
|
6784
|
+
try {
|
|
6785
|
+
sigValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
6786
|
+
} catch {
|
|
6787
|
+
return {
|
|
6788
|
+
valid: false,
|
|
6789
|
+
error: "Signature verification failed",
|
|
6790
|
+
code: "AUTH_SIG_FAIL",
|
|
6791
|
+
gate_failed: "authentic"
|
|
6792
|
+
};
|
|
6793
|
+
}
|
|
6794
|
+
if (!sigValid) {
|
|
6795
|
+
return {
|
|
6796
|
+
valid: false,
|
|
6797
|
+
error: "Invalid signature",
|
|
6798
|
+
code: "AUTH_SIG_INVALID",
|
|
6799
|
+
gate_failed: "authentic"
|
|
6800
|
+
};
|
|
6801
|
+
}
|
|
6802
|
+
return { valid: true, writ };
|
|
6803
|
+
}
|
|
6804
|
+
function grantCoversAction(grant, action, resource, nowUnix) {
|
|
6805
|
+
if (nowUnix < grant.meta.iat || nowUnix > grant.meta.exp) {
|
|
6806
|
+
return false;
|
|
6807
|
+
}
|
|
6808
|
+
return grant.caps.some(
|
|
6809
|
+
(cap) => matchOec(cap.oec, action) && matchScope(cap.scope, resource)
|
|
6810
|
+
);
|
|
6811
|
+
}
|
|
6812
|
+
function matchOec(pattern, action) {
|
|
6813
|
+
if (pattern === "*") return true;
|
|
6814
|
+
if (pattern === action) return true;
|
|
6815
|
+
if (pattern.endsWith(".*")) {
|
|
6816
|
+
const prefix = pattern.slice(0, -2);
|
|
6817
|
+
return action.startsWith(prefix + ".");
|
|
6818
|
+
}
|
|
6819
|
+
return false;
|
|
6820
|
+
}
|
|
6821
|
+
function matchScope(pattern, resource) {
|
|
6822
|
+
if (pattern === "*") return true;
|
|
6823
|
+
if (pattern === resource) return true;
|
|
6824
|
+
if (pattern.includes("*")) {
|
|
6825
|
+
const regex = new RegExp(
|
|
6826
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*/g, "[^:]*") + "$"
|
|
6827
|
+
);
|
|
6828
|
+
return regex.test(resource);
|
|
6829
|
+
}
|
|
6830
|
+
return false;
|
|
6831
|
+
}
|
|
6832
|
+
function getGrantStatus(grant, revocations) {
|
|
6833
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
6834
|
+
const revoked = revocations.find(
|
|
6835
|
+
(r) => r.target_type === "grant" && r.target_id === grant.grant_id
|
|
6836
|
+
);
|
|
6837
|
+
if (revoked && revoked.effective_at <= now * 1e3) {
|
|
6838
|
+
return "revoked";
|
|
6839
|
+
}
|
|
6840
|
+
if (now > grant.meta.exp) return "expired";
|
|
6841
|
+
return "active";
|
|
6842
|
+
}
|
|
6843
|
+
function validateGrant(grant, issuerPublicKeyHex) {
|
|
6844
|
+
const unsigned = {
|
|
6845
|
+
grant_id: grant.grant_id,
|
|
6846
|
+
issuer: grant.issuer,
|
|
6847
|
+
subject: grant.subject,
|
|
6848
|
+
grant_type: grant.grant_type,
|
|
6849
|
+
caps: grant.caps,
|
|
6850
|
+
meta: grant.meta
|
|
6851
|
+
};
|
|
6852
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
6853
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
6854
|
+
const sigBytes = b64ToUint8(grant.sig.value);
|
|
6855
|
+
const pubBytes = hexToUint8(issuerPublicKeyHex);
|
|
6856
|
+
let valid;
|
|
6857
|
+
try {
|
|
6858
|
+
valid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
6859
|
+
} catch {
|
|
6860
|
+
return { valid: false, error: "Grant signature verification failed", code: "GRANT_SIG_FAIL" };
|
|
6861
|
+
}
|
|
6862
|
+
if (!valid) {
|
|
6863
|
+
return { valid: false, error: "Invalid grant signature", code: "GRANT_SIG_INVALID" };
|
|
6864
|
+
}
|
|
6865
|
+
return { valid: true, grant };
|
|
6866
|
+
}
|
|
6867
|
+
function createGrant(grantId, issuer, subject, grantType, caps, meta, privateKeyHex, kid) {
|
|
6868
|
+
const unsigned = {
|
|
6869
|
+
grant_id: grantId,
|
|
6870
|
+
issuer,
|
|
6871
|
+
subject,
|
|
6872
|
+
grant_type: grantType,
|
|
6873
|
+
caps,
|
|
6874
|
+
meta
|
|
6875
|
+
};
|
|
6876
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
6877
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
6878
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6879
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6880
|
+
return {
|
|
6881
|
+
...unsigned,
|
|
6882
|
+
sig: {
|
|
6883
|
+
alg: "ed25519",
|
|
6884
|
+
value: uint8ToB64(signature),
|
|
6885
|
+
kid
|
|
6886
|
+
}
|
|
6887
|
+
};
|
|
6888
|
+
}
|
|
6889
|
+
function createReceipt(writ, effect, prevReceipt, metadata) {
|
|
6890
|
+
const now = Date.now();
|
|
6891
|
+
const sequence = prevReceipt ? prevReceipt.sequence + 1 : 1;
|
|
6892
|
+
const prevHash = prevReceipt?.hash ?? null;
|
|
6893
|
+
const writHash = sha2567(canonicalizeWrit({
|
|
6894
|
+
head: writ.head,
|
|
6895
|
+
body: writ.body,
|
|
6896
|
+
meta: writ.meta
|
|
6897
|
+
}));
|
|
6898
|
+
const hashInput = [
|
|
6899
|
+
prevHash ?? "",
|
|
6900
|
+
writHash,
|
|
6901
|
+
writ.head.tid,
|
|
6902
|
+
String(sequence),
|
|
6903
|
+
effect,
|
|
6904
|
+
String(now)
|
|
6905
|
+
].join(":");
|
|
6906
|
+
const receiptHash = sha2567(hashInput);
|
|
6907
|
+
const receiptId = sha2567(`receipt:${receiptHash}:${now}`);
|
|
6908
|
+
return {
|
|
6909
|
+
receipt_id: receiptId,
|
|
6910
|
+
writ_hash: writHash,
|
|
6911
|
+
thread_id: writ.head.tid,
|
|
6912
|
+
sequence,
|
|
6913
|
+
effect,
|
|
6914
|
+
hash: receiptHash,
|
|
6915
|
+
prev_hash: prevHash,
|
|
6916
|
+
executed_at: now,
|
|
6917
|
+
metadata
|
|
6918
|
+
};
|
|
6919
|
+
}
|
|
6920
|
+
function verifyReceiptChain(receipts) {
|
|
6921
|
+
if (receipts.length === 0) return { valid: true };
|
|
6922
|
+
const sorted = [...receipts].sort((a, b) => a.sequence - b.sequence);
|
|
6923
|
+
if (sorted[0].prev_hash !== null) {
|
|
6924
|
+
return {
|
|
6925
|
+
valid: false,
|
|
6926
|
+
brokenAt: 0,
|
|
6927
|
+
error: "First receipt must have null prev_hash"
|
|
6928
|
+
};
|
|
6929
|
+
}
|
|
6930
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
6931
|
+
if (sorted[i].prev_hash !== sorted[i - 1].hash) {
|
|
6932
|
+
return {
|
|
6933
|
+
valid: false,
|
|
6934
|
+
brokenAt: i,
|
|
6935
|
+
error: `Receipt ${i} prev_hash does not match receipt ${i - 1} hash`
|
|
6936
|
+
};
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
return { valid: true };
|
|
6940
|
+
}
|
|
6941
|
+
function updateThreadState(receipt, softid) {
|
|
6942
|
+
return {
|
|
6943
|
+
thread_id: receipt.thread_id,
|
|
6944
|
+
softid,
|
|
6945
|
+
last_receipt_hash: receipt.hash,
|
|
6946
|
+
sequence: receipt.sequence,
|
|
6947
|
+
updated_at: receipt.executed_at
|
|
6948
|
+
};
|
|
6949
|
+
}
|
|
6950
|
+
function createRevocation(targetType, targetId, issuerSoftid, privateKeyHex, reason) {
|
|
6951
|
+
const now = Date.now();
|
|
6952
|
+
const revocationId = sha2567(`revoke:${targetType}:${targetId}:${now}`);
|
|
6953
|
+
const payload = JSON.stringify({
|
|
6954
|
+
revocation_id: revocationId,
|
|
6955
|
+
target_type: targetType,
|
|
6956
|
+
target_id: targetId,
|
|
6957
|
+
issuer_softid: issuerSoftid,
|
|
6958
|
+
effective_at: now,
|
|
6959
|
+
reason: reason ?? null
|
|
6960
|
+
});
|
|
6961
|
+
const msgBytes = new TextEncoder().encode(payload);
|
|
6962
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6963
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6964
|
+
return {
|
|
6965
|
+
revocation_id: revocationId,
|
|
6966
|
+
target_type: targetType,
|
|
6967
|
+
target_id: targetId,
|
|
6968
|
+
issuer_softid: issuerSoftid,
|
|
6969
|
+
reason,
|
|
6970
|
+
effective_at: now,
|
|
6971
|
+
sig_value: uint8ToHex(signature)
|
|
6972
|
+
};
|
|
6973
|
+
}
|
|
6974
|
+
function isRevoked(targetType, targetId, revocations) {
|
|
6975
|
+
const now = Date.now();
|
|
6976
|
+
return revocations.some(
|
|
6977
|
+
(r) => r.target_type === targetType && r.target_id === targetId && r.effective_at <= now
|
|
6978
|
+
);
|
|
6979
|
+
}
|
|
6980
|
+
function executeLoomPipeline(writ, publicKeyHex, presence, threadState, grants, revocations, prevReceipt) {
|
|
6981
|
+
const presenceStatus = getPresenceStatus(presence);
|
|
6982
|
+
if (presenceStatus !== "active") {
|
|
6983
|
+
return { valid: false, error: "Presence not active", code: "PRESENCE_INACTIVE" };
|
|
6984
|
+
}
|
|
6985
|
+
if (isRevoked("presence", presence.presence_id, revocations)) {
|
|
6986
|
+
return { valid: false, error: "Presence revoked", code: "PRESENCE_REVOKED" };
|
|
6987
|
+
}
|
|
6988
|
+
const activeGrants = grants.filter(
|
|
6989
|
+
(g) => getGrantStatus(g, revocations) === "active"
|
|
6990
|
+
);
|
|
6991
|
+
const writResult = validateWrit(writ, publicKeyHex, threadState, activeGrants);
|
|
6992
|
+
if (!writResult.valid) {
|
|
6993
|
+
return { valid: false, error: writResult.error, code: writResult.code };
|
|
6994
|
+
}
|
|
6995
|
+
const receipt = createReceipt(writ, "ALLOW", prevReceipt);
|
|
6996
|
+
const newThreadState = updateThreadState(receipt, writ.body.who);
|
|
6997
|
+
return {
|
|
6998
|
+
receipt,
|
|
6999
|
+
threadState: newThreadState,
|
|
7000
|
+
writValidation: writResult
|
|
7001
|
+
};
|
|
7002
|
+
}
|
|
7003
|
+
var import_crypto9, import_tweetnacl, DEFAULT_PRESENCE_TTL_MS, DEFAULT_PRESENCE_DURATION_MS;
|
|
7004
|
+
var init_loom_engine = __esm({
|
|
7005
|
+
"src/loom/loom.engine.ts"() {
|
|
7006
|
+
import_crypto9 = require("crypto");
|
|
7007
|
+
import_tweetnacl = require("tweetnacl");
|
|
7008
|
+
init_loom_types();
|
|
7009
|
+
DEFAULT_PRESENCE_TTL_MS = 5e3;
|
|
7010
|
+
DEFAULT_PRESENCE_DURATION_MS = 30 * 60 * 1e3;
|
|
7011
|
+
}
|
|
7012
|
+
});
|
|
7013
|
+
|
|
7014
|
+
// src/idel/idel.compiler.ts
|
|
7015
|
+
function validateType(value, expectedType) {
|
|
7016
|
+
switch (expectedType) {
|
|
7017
|
+
case "string":
|
|
7018
|
+
return typeof value === "string";
|
|
7019
|
+
case "number":
|
|
7020
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
7021
|
+
case "boolean":
|
|
7022
|
+
return typeof value === "boolean";
|
|
7023
|
+
case "object":
|
|
7024
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7025
|
+
case "array":
|
|
7026
|
+
return Array.isArray(value);
|
|
7027
|
+
default:
|
|
7028
|
+
return true;
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
function assessRisk(schema, proposal, constraints) {
|
|
7032
|
+
const factors = [];
|
|
7033
|
+
let score = 0;
|
|
7034
|
+
const baseRiskMap = {
|
|
7035
|
+
none: 0,
|
|
7036
|
+
low: 0.1,
|
|
7037
|
+
medium: 0.3,
|
|
7038
|
+
high: 0.6,
|
|
7039
|
+
critical: 0.9
|
|
7040
|
+
};
|
|
7041
|
+
score = baseRiskMap[schema.risk_level] ?? 0;
|
|
7042
|
+
if (schema.risk_level !== "none") {
|
|
7043
|
+
factors.push(`Base risk: ${schema.risk_level}`);
|
|
7044
|
+
}
|
|
7045
|
+
if (schema.has_side_effects) {
|
|
7046
|
+
score += 0.1;
|
|
7047
|
+
factors.push("Has side effects");
|
|
7048
|
+
}
|
|
7049
|
+
if (!schema.reversible) {
|
|
7050
|
+
score += 0.1;
|
|
7051
|
+
factors.push("Not reversible");
|
|
7052
|
+
}
|
|
7053
|
+
const failed = constraints.filter((c) => !c.satisfied);
|
|
7054
|
+
if (failed.length > 0) {
|
|
7055
|
+
score += 0.05 * failed.length;
|
|
7056
|
+
factors.push(`${failed.length} unsatisfied constraint(s)`);
|
|
7057
|
+
}
|
|
7058
|
+
score = Math.min(score, 1);
|
|
7059
|
+
let level;
|
|
7060
|
+
if (score <= 0) level = "none";
|
|
7061
|
+
else if (score <= 0.2) level = "low";
|
|
7062
|
+
else if (score <= 0.5) level = "medium";
|
|
7063
|
+
else if (score <= 0.8) level = "high";
|
|
7064
|
+
else level = "critical";
|
|
7065
|
+
return { level, score, factors };
|
|
7066
|
+
}
|
|
7067
|
+
var IdelSchemaRegistry, IdelCompiler;
|
|
7068
|
+
var init_idel_compiler = __esm({
|
|
7069
|
+
"src/idel/idel.compiler.ts"() {
|
|
7070
|
+
IdelSchemaRegistry = class {
|
|
7071
|
+
constructor() {
|
|
7072
|
+
this.schemas = /* @__PURE__ */ new Map();
|
|
7073
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
7074
|
+
}
|
|
7075
|
+
register(schema) {
|
|
7076
|
+
this.schemas.set(schema.intent, schema);
|
|
7077
|
+
}
|
|
7078
|
+
registerAlias(alias, intent) {
|
|
7079
|
+
this.aliases.set(alias.toLowerCase(), intent);
|
|
7080
|
+
}
|
|
7081
|
+
get(intent) {
|
|
7082
|
+
return this.schemas.get(intent);
|
|
7083
|
+
}
|
|
7084
|
+
resolve(raw) {
|
|
7085
|
+
const exact = this.schemas.get(raw);
|
|
7086
|
+
if (exact) return exact;
|
|
7087
|
+
const aliased = this.aliases.get(raw.toLowerCase());
|
|
7088
|
+
if (aliased) return this.schemas.get(aliased);
|
|
7089
|
+
const candidates = [...this.schemas.keys()].filter(
|
|
7090
|
+
(k) => k.startsWith(raw + ".") || k.toLowerCase().includes(raw.toLowerCase())
|
|
7091
|
+
);
|
|
7092
|
+
if (candidates.length === 1) {
|
|
7093
|
+
return this.schemas.get(candidates[0]);
|
|
7094
|
+
}
|
|
7095
|
+
return void 0;
|
|
7096
|
+
}
|
|
7097
|
+
/**
|
|
7098
|
+
* Find all schemas that partially match the raw input.
|
|
7099
|
+
* Returns scored candidates for ambiguity resolution.
|
|
7100
|
+
*/
|
|
7101
|
+
findCandidates(raw) {
|
|
7102
|
+
const normalized = raw.toLowerCase().trim();
|
|
7103
|
+
const results = [];
|
|
7104
|
+
for (const [key, schema] of this.schemas) {
|
|
7105
|
+
let score = 0;
|
|
7106
|
+
if (key === raw) {
|
|
7107
|
+
score = 1;
|
|
7108
|
+
} else if (key.toLowerCase() === normalized) {
|
|
7109
|
+
score = 0.95;
|
|
7110
|
+
} else if (this.aliases.get(normalized) === key) {
|
|
7111
|
+
score = 0.9;
|
|
7112
|
+
} else if (key.toLowerCase().startsWith(normalized)) {
|
|
7113
|
+
score = 0.7;
|
|
7114
|
+
} else if (key.toLowerCase().includes(normalized)) {
|
|
7115
|
+
score = 0.5;
|
|
7116
|
+
} else if (schema.tags?.some((t) => t.toLowerCase().includes(normalized))) {
|
|
7117
|
+
score = 0.4;
|
|
7118
|
+
} else if (schema.description.toLowerCase().includes(normalized)) {
|
|
7119
|
+
score = 0.3;
|
|
7120
|
+
}
|
|
7121
|
+
if (score > 0) {
|
|
7122
|
+
results.push({ schema, score });
|
|
7123
|
+
}
|
|
7124
|
+
}
|
|
7125
|
+
return results.sort((a, b) => b.score - a.score);
|
|
7126
|
+
}
|
|
7127
|
+
list() {
|
|
7128
|
+
return [...this.schemas.values()];
|
|
7129
|
+
}
|
|
7130
|
+
};
|
|
7131
|
+
IdelCompiler = class {
|
|
7132
|
+
constructor(registry) {
|
|
7133
|
+
this.registry = registry;
|
|
7134
|
+
}
|
|
7135
|
+
/**
|
|
7136
|
+
* Compile a raw intent proposal into a validated, executable structure.
|
|
7137
|
+
*/
|
|
7138
|
+
compile(proposal) {
|
|
7139
|
+
const errors = [];
|
|
7140
|
+
const candidates = this.registry.findCandidates(proposal.raw);
|
|
7141
|
+
if (candidates.length === 0) {
|
|
7142
|
+
return {
|
|
7143
|
+
ok: false,
|
|
7144
|
+
errors: [{
|
|
7145
|
+
code: "IDEL_UNKNOWN_INTENT",
|
|
7146
|
+
message: `No intent found matching '${proposal.raw}'`
|
|
7147
|
+
}]
|
|
7148
|
+
};
|
|
7149
|
+
}
|
|
7150
|
+
const best = candidates[0];
|
|
7151
|
+
const schema = best.schema;
|
|
7152
|
+
const alternatives = candidates.slice(1, 4).filter((c) => c.score >= 0.3).map((c) => ({
|
|
7153
|
+
intent: c.schema.intent,
|
|
7154
|
+
confidence: c.score,
|
|
7155
|
+
reason: c.schema.description
|
|
7156
|
+
}));
|
|
7157
|
+
const constraints = [];
|
|
7158
|
+
const clarifications = [];
|
|
7159
|
+
const params = { ...proposal.params };
|
|
7160
|
+
for (const paramSchema of schema.params) {
|
|
7161
|
+
const value = params[paramSchema.name];
|
|
7162
|
+
if (paramSchema.required && value === void 0) {
|
|
7163
|
+
if (paramSchema.default !== void 0) {
|
|
7164
|
+
params[paramSchema.name] = paramSchema.default;
|
|
7165
|
+
constraints.push({
|
|
7166
|
+
kind: "required_param",
|
|
7167
|
+
field: paramSchema.name,
|
|
7168
|
+
description: `Defaulted to ${JSON.stringify(paramSchema.default)}`,
|
|
7169
|
+
satisfied: true,
|
|
7170
|
+
value: paramSchema.default
|
|
7171
|
+
});
|
|
7172
|
+
} else {
|
|
7173
|
+
constraints.push({
|
|
7174
|
+
kind: "required_param",
|
|
7175
|
+
field: paramSchema.name,
|
|
7176
|
+
description: `Required parameter '${paramSchema.name}' is missing`,
|
|
7177
|
+
satisfied: false
|
|
7178
|
+
});
|
|
7179
|
+
clarifications.push({
|
|
7180
|
+
id: `clarify_${paramSchema.name}`,
|
|
7181
|
+
question: paramSchema.description ?? `What is the ${paramSchema.name}?`,
|
|
7182
|
+
field: paramSchema.name,
|
|
7183
|
+
options: paramSchema.enum?.map(String),
|
|
7184
|
+
required: true
|
|
7185
|
+
});
|
|
7186
|
+
}
|
|
7187
|
+
continue;
|
|
7188
|
+
}
|
|
7189
|
+
if (value === void 0) continue;
|
|
7190
|
+
const typeValid = validateType(value, paramSchema.type);
|
|
7191
|
+
constraints.push({
|
|
7192
|
+
kind: "type_check",
|
|
7193
|
+
field: paramSchema.name,
|
|
7194
|
+
description: `Must be ${paramSchema.type}`,
|
|
7195
|
+
satisfied: typeValid,
|
|
7196
|
+
value,
|
|
7197
|
+
expected: paramSchema.type
|
|
7198
|
+
});
|
|
7199
|
+
if (!typeValid) {
|
|
7200
|
+
errors.push({
|
|
7201
|
+
code: "IDEL_TYPE_ERROR",
|
|
7202
|
+
message: `Parameter '${paramSchema.name}' must be ${paramSchema.type}, got ${typeof value}`,
|
|
7203
|
+
field: paramSchema.name
|
|
7204
|
+
});
|
|
7205
|
+
}
|
|
7206
|
+
if (paramSchema.min !== void 0 || paramSchema.max !== void 0) {
|
|
7207
|
+
const numVal = typeof value === "number" ? value : Number(value);
|
|
7208
|
+
const inRange = (paramSchema.min === void 0 || numVal >= paramSchema.min) && (paramSchema.max === void 0 || numVal <= paramSchema.max);
|
|
7209
|
+
constraints.push({
|
|
7210
|
+
kind: "range",
|
|
7211
|
+
field: paramSchema.name,
|
|
7212
|
+
description: `Must be between ${paramSchema.min ?? "-\u221E"} and ${paramSchema.max ?? "\u221E"}`,
|
|
7213
|
+
satisfied: inRange,
|
|
7214
|
+
value: numVal
|
|
7215
|
+
});
|
|
7216
|
+
}
|
|
7217
|
+
if (paramSchema.pattern) {
|
|
7218
|
+
const matches = new RegExp(paramSchema.pattern).test(String(value));
|
|
7219
|
+
constraints.push({
|
|
7220
|
+
kind: "pattern",
|
|
7221
|
+
field: paramSchema.name,
|
|
7222
|
+
description: `Must match ${paramSchema.pattern}`,
|
|
7223
|
+
satisfied: matches,
|
|
7224
|
+
value,
|
|
7225
|
+
expected: paramSchema.pattern
|
|
7226
|
+
});
|
|
7227
|
+
}
|
|
7228
|
+
if (paramSchema.enum) {
|
|
7229
|
+
const inEnum = paramSchema.enum.some(
|
|
7230
|
+
(e) => JSON.stringify(e) === JSON.stringify(value)
|
|
7231
|
+
);
|
|
7232
|
+
constraints.push({
|
|
7233
|
+
kind: "custom",
|
|
7234
|
+
field: paramSchema.name,
|
|
7235
|
+
description: `Must be one of: ${paramSchema.enum.join(", ")}`,
|
|
7236
|
+
satisfied: inEnum,
|
|
7237
|
+
value,
|
|
7238
|
+
expected: paramSchema.enum
|
|
7239
|
+
});
|
|
7240
|
+
}
|
|
7241
|
+
}
|
|
7242
|
+
const risk = assessRisk(schema, proposal, constraints);
|
|
7243
|
+
const unsatisfied = constraints.filter((c) => !c.satisfied);
|
|
7244
|
+
const needsClarification = clarifications.length > 0;
|
|
7245
|
+
let confidence = best.score;
|
|
7246
|
+
if (unsatisfied.length > 0) {
|
|
7247
|
+
confidence *= 1 - unsatisfied.length / Math.max(constraints.length, 1) * 0.5;
|
|
7248
|
+
}
|
|
7249
|
+
if (errors.length > 0) {
|
|
7250
|
+
confidence *= 0.5;
|
|
7251
|
+
}
|
|
7252
|
+
const compiled = {
|
|
7253
|
+
intent: schema.intent,
|
|
7254
|
+
actor_id: proposal.actor_id,
|
|
7255
|
+
target: proposal.target,
|
|
7256
|
+
params,
|
|
7257
|
+
constraints,
|
|
7258
|
+
confidence,
|
|
7259
|
+
alternatives,
|
|
7260
|
+
needs_clarification: needsClarification,
|
|
7261
|
+
clarifications,
|
|
7262
|
+
expected_outcome: schema.description,
|
|
7263
|
+
fallback: schema.related?.[0],
|
|
7264
|
+
risk,
|
|
7265
|
+
metadata: {
|
|
7266
|
+
schema_intent: schema.intent,
|
|
7267
|
+
resolved_from: proposal.raw,
|
|
7268
|
+
has_side_effects: schema.has_side_effects,
|
|
7269
|
+
reversible: schema.reversible
|
|
7270
|
+
}
|
|
7271
|
+
};
|
|
7272
|
+
return {
|
|
7273
|
+
ok: errors.length === 0 && !needsClarification,
|
|
7274
|
+
compiled,
|
|
7275
|
+
errors
|
|
7276
|
+
};
|
|
7277
|
+
}
|
|
7278
|
+
/**
|
|
7279
|
+
* Apply clarification answers and re-compile.
|
|
7280
|
+
*/
|
|
7281
|
+
applyClarifications(compiled, answers) {
|
|
7282
|
+
const proposal = {
|
|
7283
|
+
raw: compiled.intent,
|
|
7284
|
+
actor_id: compiled.actor_id,
|
|
7285
|
+
target: compiled.target,
|
|
7286
|
+
params: { ...compiled.params, ...answers }
|
|
7287
|
+
};
|
|
7288
|
+
return this.compile(proposal);
|
|
7289
|
+
}
|
|
7290
|
+
};
|
|
7291
|
+
}
|
|
7292
|
+
});
|
|
7293
|
+
|
|
7294
|
+
// src/needle/needle.engine.ts
|
|
7295
|
+
function assembleNeedle(params) {
|
|
7296
|
+
return {
|
|
7297
|
+
needle_id: (0, import_crypto10.randomBytes)(16).toString("hex"),
|
|
7298
|
+
phase: "created",
|
|
7299
|
+
tps_coordinate: params.tps_coordinate,
|
|
7300
|
+
intent: params.intent,
|
|
7301
|
+
presence: params.presence,
|
|
7302
|
+
writ: params.writ,
|
|
7303
|
+
grants: params.grants,
|
|
7304
|
+
created_at: Date.now()
|
|
7305
|
+
};
|
|
7306
|
+
}
|
|
7307
|
+
function classifyStitch(observation, verdict) {
|
|
7308
|
+
if (verdict.status === "failed" || verdict.status === "disputed") {
|
|
7309
|
+
return "torn";
|
|
7310
|
+
}
|
|
7311
|
+
if (observation.decision === "DENY") {
|
|
7312
|
+
return "silent";
|
|
7313
|
+
}
|
|
7314
|
+
if (verdict.isDeed) {
|
|
7315
|
+
return "deed";
|
|
7316
|
+
}
|
|
7317
|
+
return "silent";
|
|
7318
|
+
}
|
|
7319
|
+
function formStitch(needle, observation, verdict, receipt) {
|
|
7320
|
+
return {
|
|
7321
|
+
stitch_id: needle.needle_id,
|
|
7322
|
+
kind: classifyStitch(observation, verdict),
|
|
7323
|
+
intent: needle.intent.intent,
|
|
7324
|
+
actor_id: needle.intent.actor_id,
|
|
7325
|
+
tps_coordinate: needle.tps_coordinate,
|
|
7326
|
+
observation,
|
|
7327
|
+
verdict,
|
|
7328
|
+
receipt,
|
|
7329
|
+
thread_id: receipt.thread_id,
|
|
7330
|
+
sequence: receipt.sequence,
|
|
7331
|
+
stitched_at: Date.now()
|
|
7332
|
+
};
|
|
7333
|
+
}
|
|
7334
|
+
async function runNeedlePipeline(needle, config, threadState, prevReceipt, expectedOutcome) {
|
|
7335
|
+
const obs = createObservation("http");
|
|
7336
|
+
obs.intent = needle.intent.intent;
|
|
7337
|
+
obs.actorId = needle.intent.actor_id;
|
|
7338
|
+
needle.phase = "validated";
|
|
7339
|
+
let stage = startStage(obs, "loom.validate");
|
|
7340
|
+
const validation = validateWrit(
|
|
7341
|
+
needle.writ,
|
|
7342
|
+
config.public_key,
|
|
7343
|
+
threadState,
|
|
7344
|
+
needle.grants
|
|
7345
|
+
);
|
|
7346
|
+
if (!validation.valid) {
|
|
7347
|
+
endStage(stage, "fail", validation.error);
|
|
7348
|
+
return failNeedle(needle, obs, "validated", "LOOM_VALIDATION_FAILED", validation.error ?? "Writ validation failed");
|
|
7349
|
+
}
|
|
7350
|
+
endStage(stage, "ok");
|
|
7351
|
+
if (config.sensors && config.sensors.length > 0) {
|
|
7352
|
+
stage = startStage(obs, "sensors.evaluate");
|
|
7353
|
+
const sensorInput = {
|
|
7354
|
+
intent: needle.intent.intent,
|
|
7355
|
+
actorId: needle.intent.actor_id,
|
|
7356
|
+
metadata: {
|
|
7357
|
+
observation: obs,
|
|
7358
|
+
needle_id: needle.needle_id,
|
|
7359
|
+
tps_coordinate: needle.tps_coordinate,
|
|
7360
|
+
writ: needle.writ,
|
|
7361
|
+
grants: needle.grants,
|
|
7362
|
+
params: needle.intent.params
|
|
7363
|
+
}
|
|
7364
|
+
};
|
|
7365
|
+
for (const sensor of config.sensors) {
|
|
7366
|
+
if (sensor.supports && !sensor.supports(sensorInput)) continue;
|
|
7367
|
+
const t0 = Date.now();
|
|
7368
|
+
let decision;
|
|
7369
|
+
try {
|
|
7370
|
+
const rawDecision = await sensor.run(sensorInput);
|
|
7371
|
+
decision = normalizeSensorDecision(rawDecision);
|
|
7372
|
+
} catch (err) {
|
|
7373
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7374
|
+
recordSensor(obs, sensor.name, false, 100, Date.now() - t0, [`sensor_error:${msg}`]);
|
|
7375
|
+
endStage(stage, "fail", `Sensor ${sensor.name} threw: ${msg}`);
|
|
7376
|
+
return failNeedle(needle, obs, "validated", "SENSOR_ERROR", `Sensor ${sensor.name} failed: ${msg}`);
|
|
7377
|
+
}
|
|
7378
|
+
recordSensor(obs, sensor.name, decision.allow, decision.riskScore, Date.now() - t0, decision.reasons);
|
|
7379
|
+
if (!decision.allow) {
|
|
7380
|
+
endStage(stage, "fail", `Sensor ${sensor.name} denied`);
|
|
7381
|
+
return failNeedle(needle, obs, "validated", "SENSOR_DENY", decision.reasons[0] ?? `Denied by ${sensor.name}`);
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
endStage(stage, "ok");
|
|
7385
|
+
}
|
|
7386
|
+
needle.phase = "executing";
|
|
7387
|
+
stage = startStage(obs, "handler.execute");
|
|
7388
|
+
const handler = config.handlers.get(needle.intent.intent);
|
|
7389
|
+
if (!handler) {
|
|
7390
|
+
endStage(stage, "fail", `No handler for intent '${needle.intent.intent}'`);
|
|
7391
|
+
return failNeedle(needle, obs, "executing", "NO_HANDLER", `No handler registered for intent '${needle.intent.intent}'`);
|
|
7392
|
+
}
|
|
7393
|
+
const handlerCtx = {
|
|
7394
|
+
needle_id: needle.needle_id,
|
|
7395
|
+
actor_id: needle.intent.actor_id,
|
|
7396
|
+
presence_id: needle.presence.presence_id,
|
|
7397
|
+
writ: needle.writ,
|
|
7398
|
+
grants: needle.grants,
|
|
7399
|
+
tps_coordinate: needle.tps_coordinate
|
|
7400
|
+
};
|
|
7401
|
+
let handlerResult;
|
|
7402
|
+
try {
|
|
7403
|
+
handlerResult = await handler(needle.intent, handlerCtx);
|
|
7404
|
+
} catch (err) {
|
|
7405
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7406
|
+
endStage(stage, "fail", msg);
|
|
7407
|
+
return failNeedle(needle, obs, "executing", "HANDLER_ERROR", msg);
|
|
7408
|
+
}
|
|
7409
|
+
if (!handlerResult.ok) {
|
|
7410
|
+
endStage(stage, "fail", handlerResult.effect);
|
|
7411
|
+
obs.decision = "DENY";
|
|
7412
|
+
obs.resultCode = handlerResult.effect;
|
|
7413
|
+
obs.statusCode = handlerResult.status_code ?? 400;
|
|
7414
|
+
} else {
|
|
7415
|
+
endStage(stage, "ok");
|
|
7416
|
+
obs.decision = "ALLOW";
|
|
7417
|
+
obs.resultCode = handlerResult.effect;
|
|
7418
|
+
obs.statusCode = handlerResult.status_code ?? 200;
|
|
7419
|
+
}
|
|
7420
|
+
if (handlerResult.data) {
|
|
7421
|
+
obs.facts = { ...obs.facts, ...handlerResult.data };
|
|
7422
|
+
}
|
|
7423
|
+
needle.phase = "observed";
|
|
7424
|
+
finalizeObservation(obs, obs.decision ?? "DENY", obs.statusCode ?? 500, obs.resultCode);
|
|
7425
|
+
needle.observation = obs;
|
|
7426
|
+
const verdict = scoreTruth(obs, expectedOutcome);
|
|
7427
|
+
needle.verdict = verdict;
|
|
7428
|
+
needle.phase = "stitched";
|
|
7429
|
+
stage = startStage(obs, "stitch.form");
|
|
7430
|
+
const receipt = createReceipt(
|
|
7431
|
+
needle.writ,
|
|
7432
|
+
obs.decision ?? "DENY",
|
|
7433
|
+
prevReceipt
|
|
7434
|
+
);
|
|
7435
|
+
needle.receipt = receipt;
|
|
7436
|
+
const newThreadState = updateThreadState(
|
|
7437
|
+
receipt,
|
|
7438
|
+
needle.intent.actor_id
|
|
7439
|
+
);
|
|
7440
|
+
const stitch = formStitch(needle, obs, verdict, receipt);
|
|
7441
|
+
needle.completed_at = Date.now();
|
|
7442
|
+
endStage(stage, "ok");
|
|
7443
|
+
return {
|
|
7444
|
+
ok: handlerResult.ok,
|
|
7445
|
+
needle,
|
|
7446
|
+
stitch,
|
|
7447
|
+
thread_state: newThreadState
|
|
7448
|
+
};
|
|
7449
|
+
}
|
|
7450
|
+
function failNeedle(needle, obs, phase, code, message) {
|
|
7451
|
+
needle.phase = "failed";
|
|
7452
|
+
needle.error = { phase, code, message };
|
|
7453
|
+
needle.completed_at = Date.now();
|
|
7454
|
+
obs.decision = obs.decision ?? "DENY";
|
|
7455
|
+
obs.statusCode = obs.statusCode ?? 500;
|
|
7456
|
+
finalizeObservation(obs, obs.decision, obs.statusCode, obs.resultCode);
|
|
7457
|
+
needle.observation = obs;
|
|
7458
|
+
const verdict = scoreTruth(obs);
|
|
7459
|
+
needle.verdict = verdict;
|
|
7460
|
+
return {
|
|
7461
|
+
ok: false,
|
|
7462
|
+
needle
|
|
7463
|
+
};
|
|
7464
|
+
}
|
|
7465
|
+
var import_crypto10;
|
|
7466
|
+
var init_needle_engine = __esm({
|
|
7467
|
+
"src/needle/needle.engine.ts"() {
|
|
7468
|
+
import_crypto10 = require("crypto");
|
|
7469
|
+
init_axis_observation();
|
|
7470
|
+
init_truth_scoring();
|
|
7471
|
+
init_loom_engine();
|
|
7472
|
+
init_axis_sensor();
|
|
7473
|
+
}
|
|
7474
|
+
});
|
|
7475
|
+
|
|
7476
|
+
// src/needle/knot.engine.ts
|
|
7477
|
+
function openKnot(params) {
|
|
7478
|
+
const isIrreversible = params.type === "irreversible";
|
|
7479
|
+
return {
|
|
7480
|
+
knot_id: `knot_${(0, import_crypto11.randomBytes)(16).toString("hex")}`,
|
|
7481
|
+
type: params.type,
|
|
7482
|
+
status: "open",
|
|
7483
|
+
stitch_ids: [],
|
|
7484
|
+
thread_id: params.thread_id,
|
|
7485
|
+
tps_anchor: params.tps_anchor,
|
|
7486
|
+
irreversible: isIrreversible,
|
|
7487
|
+
capsule_id: params.capsule_id,
|
|
7488
|
+
law_ref: params.law_ref,
|
|
7489
|
+
branch_ids: [],
|
|
7490
|
+
required_count: params.required_count,
|
|
7491
|
+
all_or_nothing: params.all_or_nothing ?? (params.type === "authority" || isIrreversible),
|
|
7492
|
+
actor_id: params.actor_id,
|
|
7493
|
+
created_at: Date.now()
|
|
7494
|
+
};
|
|
7495
|
+
}
|
|
7496
|
+
function addStitchToKnot(knot, stitch) {
|
|
7497
|
+
if (knot.status !== "open") {
|
|
7498
|
+
return `Knot ${knot.knot_id} is ${knot.status}, cannot add stitches`;
|
|
7499
|
+
}
|
|
7500
|
+
if (stitch.thread_id !== knot.thread_id) {
|
|
7501
|
+
return `Stitch thread ${stitch.thread_id} does not match knot thread ${knot.thread_id}`;
|
|
7502
|
+
}
|
|
7503
|
+
if (knot.stitch_ids.includes(stitch.stitch_id)) {
|
|
7504
|
+
return `Stitch ${stitch.stitch_id} already in knot`;
|
|
7505
|
+
}
|
|
7506
|
+
if (knot.type === "authority" && knot.capsule_id) {
|
|
7507
|
+
if (stitch.observation.capsuleId && stitch.observation.capsuleId !== knot.capsule_id) {
|
|
7508
|
+
return `Stitch capsule ${stitch.observation.capsuleId} does not match knot capsule ${knot.capsule_id}`;
|
|
7509
|
+
}
|
|
7510
|
+
}
|
|
7511
|
+
knot.stitch_ids.push(stitch.stitch_id);
|
|
7512
|
+
return null;
|
|
7513
|
+
}
|
|
7514
|
+
function validateKnot(knot, stitches) {
|
|
7515
|
+
const errors = [];
|
|
7516
|
+
const passedIds = [];
|
|
7517
|
+
const failedIds = [];
|
|
7518
|
+
const stitchMap = new Map(stitches.map((s) => [s.stitch_id, s]));
|
|
7519
|
+
for (const sid of knot.stitch_ids) {
|
|
7520
|
+
const stitch = stitchMap.get(sid);
|
|
7521
|
+
if (!stitch) {
|
|
7522
|
+
failedIds.push(sid);
|
|
7523
|
+
errors.push({
|
|
7524
|
+
code: "KNOT_MISSING_STITCH",
|
|
7525
|
+
message: `Stitch ${sid} not found`,
|
|
7526
|
+
stitch_id: sid
|
|
7527
|
+
});
|
|
7528
|
+
continue;
|
|
7529
|
+
}
|
|
7530
|
+
if (stitch.kind === "torn") {
|
|
7531
|
+
failedIds.push(sid);
|
|
7532
|
+
errors.push({
|
|
7533
|
+
code: "KNOT_TORN_STITCH",
|
|
7534
|
+
message: `Stitch ${sid} is torn (failed/disputed)`,
|
|
7535
|
+
stitch_id: sid
|
|
7536
|
+
});
|
|
7537
|
+
continue;
|
|
7538
|
+
}
|
|
7539
|
+
if (knot.type === "irreversible" && stitch.kind !== "deed") {
|
|
7540
|
+
failedIds.push(sid);
|
|
7541
|
+
errors.push({
|
|
7542
|
+
code: "KNOT_REQUIRES_DEED",
|
|
7543
|
+
message: `Irreversible knot requires deed stitch, got '${stitch.kind}'`,
|
|
7544
|
+
stitch_id: sid
|
|
7545
|
+
});
|
|
7546
|
+
continue;
|
|
7547
|
+
}
|
|
7548
|
+
passedIds.push(sid);
|
|
7549
|
+
}
|
|
7550
|
+
if (knot.required_count !== void 0 && knot.stitch_ids.length < knot.required_count) {
|
|
7551
|
+
errors.push({
|
|
7552
|
+
code: "KNOT_INSUFFICIENT_STITCHES",
|
|
7553
|
+
message: `Knot requires ${knot.required_count} stitches, has ${knot.stitch_ids.length}`
|
|
7554
|
+
});
|
|
7555
|
+
}
|
|
7556
|
+
const allPassed = failedIds.length === 0;
|
|
7557
|
+
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);
|
|
7558
|
+
return {
|
|
7559
|
+
valid: allPassed && errors.length === 0,
|
|
7560
|
+
passed_stitch_ids: passedIds,
|
|
7561
|
+
failed_stitch_ids: failedIds,
|
|
7562
|
+
can_tie: canTie,
|
|
7563
|
+
errors
|
|
7564
|
+
};
|
|
7565
|
+
}
|
|
7566
|
+
function tieKnot(knot, stitches) {
|
|
7567
|
+
const validation = validateKnot(knot, stitches);
|
|
7568
|
+
if (!validation.can_tie) {
|
|
7569
|
+
return { ...validation, knot };
|
|
7570
|
+
}
|
|
7571
|
+
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);
|
|
7572
|
+
const witnessPayload = receiptHashes.join(":");
|
|
7573
|
+
knot.witness_hash = (0, import_crypto11.createHash)("sha256").update(witnessPayload).digest("hex");
|
|
7574
|
+
knot.status = "tied";
|
|
7575
|
+
knot.tied_at = Date.now();
|
|
7576
|
+
return { ...validation, knot };
|
|
7577
|
+
}
|
|
7578
|
+
function breakKnot(knot, request) {
|
|
7579
|
+
if (knot.status === "broken") {
|
|
7580
|
+
return { ok: false, error: "Knot is already broken" };
|
|
7581
|
+
}
|
|
7582
|
+
if (knot.status === "open") {
|
|
7583
|
+
knot.status = "broken";
|
|
7584
|
+
knot.broken_at = Date.now();
|
|
7585
|
+
knot.break_reason = request.reason;
|
|
7586
|
+
return { ok: true };
|
|
7587
|
+
}
|
|
7588
|
+
if (knot.status === "tied") {
|
|
7589
|
+
if (!request.reason) {
|
|
7590
|
+
return { ok: false, error: "Breaking a tied knot requires a reason" };
|
|
7591
|
+
}
|
|
7592
|
+
if ((knot.irreversible || knot.type === "law") && !request.override_grant_id) {
|
|
7593
|
+
return {
|
|
7594
|
+
ok: false,
|
|
7595
|
+
error: `Breaking ${knot.type} knot requires override_grant_id from higher authority`
|
|
7596
|
+
};
|
|
7597
|
+
}
|
|
7598
|
+
knot.status = "broken";
|
|
7599
|
+
knot.broken_at = Date.now();
|
|
7600
|
+
knot.break_reason = request.reason;
|
|
7601
|
+
return { ok: true };
|
|
7602
|
+
}
|
|
7603
|
+
return { ok: false, error: `Cannot break knot in status '${knot.status}'` };
|
|
7604
|
+
}
|
|
7605
|
+
function forkFromKnot(knot, branchId, decisionStitchId) {
|
|
7606
|
+
if (knot.status !== "tied" && knot.status !== "open") {
|
|
7607
|
+
return { ok: false, error: `Cannot fork from knot in status '${knot.status}'` };
|
|
7608
|
+
}
|
|
7609
|
+
if (decisionStitchId) {
|
|
7610
|
+
if (!knot.stitch_ids.includes(decisionStitchId)) {
|
|
7611
|
+
return { ok: false, error: `Decision stitch ${decisionStitchId} is not part of this knot` };
|
|
7612
|
+
}
|
|
7613
|
+
knot.decision_stitch_id = decisionStitchId;
|
|
7614
|
+
}
|
|
7615
|
+
knot.branch_ids.push(branchId);
|
|
7616
|
+
knot.status = "forked";
|
|
7617
|
+
return { ok: true };
|
|
7618
|
+
}
|
|
7619
|
+
function isKnotOpen(knot) {
|
|
7620
|
+
return knot.status === "open";
|
|
7621
|
+
}
|
|
7622
|
+
function isPointOfNoReturn(knot) {
|
|
7623
|
+
return knot.irreversible && knot.status === "tied";
|
|
7624
|
+
}
|
|
7625
|
+
function findKnotsForStitch(stitchId, knots) {
|
|
7626
|
+
return knots.filter((k) => k.stitch_ids.includes(stitchId));
|
|
7627
|
+
}
|
|
7628
|
+
function getIrreversibleKnots(knots) {
|
|
7629
|
+
return knots.filter((k) => k.irreversible && k.status === "tied");
|
|
7630
|
+
}
|
|
7631
|
+
function getDecisionPoints(knots) {
|
|
7632
|
+
return knots.filter((k) => k.type === "decision" || k.status === "forked");
|
|
7633
|
+
}
|
|
7634
|
+
var import_crypto11;
|
|
7635
|
+
var init_knot_engine = __esm({
|
|
7636
|
+
"src/needle/knot.engine.ts"() {
|
|
7637
|
+
import_crypto11 = require("crypto");
|
|
7638
|
+
}
|
|
7639
|
+
});
|
|
7640
|
+
|
|
7641
|
+
// src/needle/fabric.engine.ts
|
|
7642
|
+
function createFabric() {
|
|
7643
|
+
return {
|
|
7644
|
+
fabric_id: `fab_${(0, import_crypto12.randomBytes)(16).toString("hex")}`,
|
|
7645
|
+
state_hash: hashState(/* @__PURE__ */ new Map()),
|
|
7646
|
+
cells: /* @__PURE__ */ new Map(),
|
|
7647
|
+
thread_ids: [],
|
|
7648
|
+
stitch_count: 0,
|
|
7649
|
+
knot_count: 0,
|
|
7650
|
+
computed_at: Date.now(),
|
|
7651
|
+
version: 0
|
|
7652
|
+
};
|
|
7653
|
+
}
|
|
7654
|
+
function applyStitch(fabric, stitch, effect) {
|
|
7655
|
+
for (const [key, value] of Object.entries(effect.mutations)) {
|
|
7656
|
+
if (value === null) {
|
|
7657
|
+
fabric.cells.delete(key);
|
|
7658
|
+
} else {
|
|
7659
|
+
const existing = fabric.cells.get(key);
|
|
7660
|
+
if (existing?.locked) {
|
|
7661
|
+
continue;
|
|
7662
|
+
}
|
|
7663
|
+
fabric.cells.set(key, {
|
|
7664
|
+
key,
|
|
7665
|
+
value,
|
|
7666
|
+
last_stitch_id: stitch.stitch_id,
|
|
7667
|
+
last_tps: stitch.tps_coordinate,
|
|
7668
|
+
write_count: (existing?.write_count ?? 0) + 1,
|
|
7669
|
+
locked: false
|
|
7670
|
+
});
|
|
7671
|
+
}
|
|
7672
|
+
}
|
|
7673
|
+
if (!fabric.thread_ids.includes(stitch.thread_id)) {
|
|
7674
|
+
fabric.thread_ids.push(stitch.thread_id);
|
|
7675
|
+
}
|
|
7676
|
+
fabric.stitch_count++;
|
|
7677
|
+
fabric.version++;
|
|
7678
|
+
fabric.projected_at_tps = stitch.tps_coordinate ?? fabric.projected_at_tps;
|
|
7679
|
+
fabric.computed_at = Date.now();
|
|
7680
|
+
fabric.state_hash = hashState(fabric.cells);
|
|
7681
|
+
}
|
|
7682
|
+
function weave(stitches, resolver, knots) {
|
|
7683
|
+
const fabric = createFabric();
|
|
7684
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
7685
|
+
for (const stitch of sorted) {
|
|
7686
|
+
if (stitch.kind === "torn") continue;
|
|
7687
|
+
const effect = resolver(stitch);
|
|
7688
|
+
applyStitch(fabric, stitch, effect);
|
|
7689
|
+
}
|
|
7690
|
+
if (knots) {
|
|
7691
|
+
for (const knot of knots) {
|
|
7692
|
+
if (knot.irreversible && knot.status === "tied") {
|
|
7693
|
+
lockCellsByKnot(fabric, knot, stitches, resolver);
|
|
7694
|
+
fabric.knot_count++;
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
}
|
|
7698
|
+
return fabric;
|
|
7699
|
+
}
|
|
7700
|
+
function projectAt(stitches, resolver, tpsFilter, knots) {
|
|
7701
|
+
const filtered = stitches.filter((s) => tpsFilter(s.tps_coordinate));
|
|
7702
|
+
return weave(filtered, resolver, knots);
|
|
7703
|
+
}
|
|
7704
|
+
function lockCellsByKnot(fabric, knot, stitches, resolver) {
|
|
7705
|
+
const knotStitchIds = new Set(knot.stitch_ids);
|
|
7706
|
+
const knotStitches = stitches.filter((s) => knotStitchIds.has(s.stitch_id));
|
|
7707
|
+
for (const stitch of knotStitches) {
|
|
7708
|
+
const effect = resolver(stitch);
|
|
7709
|
+
for (const key of Object.keys(effect.mutations)) {
|
|
7710
|
+
const cell = fabric.cells.get(key);
|
|
7711
|
+
if (cell) {
|
|
7712
|
+
cell.locked = true;
|
|
7713
|
+
cell.locked_by_knot = knot.knot_id;
|
|
7714
|
+
}
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
}
|
|
7718
|
+
function lockCells(fabric, keys, knotId) {
|
|
7719
|
+
for (const key of keys) {
|
|
7720
|
+
const cell = fabric.cells.get(key);
|
|
7721
|
+
if (cell) {
|
|
7722
|
+
cell.locked = true;
|
|
7723
|
+
cell.locked_by_knot = knotId;
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
7726
|
+
}
|
|
7727
|
+
function queryFabric(fabric, query) {
|
|
7728
|
+
let results = [...fabric.cells.values()];
|
|
7729
|
+
if (query.keys) {
|
|
7730
|
+
const keySet = new Set(query.keys);
|
|
7731
|
+
results = results.filter((c) => keySet.has(c.key));
|
|
7732
|
+
}
|
|
7733
|
+
if (query.prefix) {
|
|
7734
|
+
const prefix = query.prefix;
|
|
7735
|
+
results = results.filter((c) => c.key.startsWith(prefix));
|
|
7736
|
+
}
|
|
7737
|
+
if (query.locked_only) {
|
|
7738
|
+
results = results.filter((c) => c.locked);
|
|
7739
|
+
}
|
|
7740
|
+
return results;
|
|
7741
|
+
}
|
|
7742
|
+
function getFabricValue(fabric, key) {
|
|
7743
|
+
return fabric.cells.get(key)?.value;
|
|
7744
|
+
}
|
|
7745
|
+
function diffFabrics(a, b) {
|
|
7746
|
+
const entries = [];
|
|
7747
|
+
let added = 0;
|
|
7748
|
+
let modified = 0;
|
|
7749
|
+
let deleted = 0;
|
|
7750
|
+
for (const [key, cellB] of b.cells) {
|
|
7751
|
+
const cellA = a.cells.get(key);
|
|
7752
|
+
if (!cellA) {
|
|
7753
|
+
entries.push({
|
|
7754
|
+
key,
|
|
7755
|
+
kind: "added",
|
|
7756
|
+
after: cellB.value,
|
|
7757
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
7758
|
+
});
|
|
7759
|
+
added++;
|
|
7760
|
+
} else if (JSON.stringify(cellA.value) !== JSON.stringify(cellB.value)) {
|
|
7761
|
+
entries.push({
|
|
7762
|
+
key,
|
|
7763
|
+
kind: "modified",
|
|
7764
|
+
before: cellA.value,
|
|
7765
|
+
after: cellB.value,
|
|
7766
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
7767
|
+
});
|
|
7768
|
+
modified++;
|
|
7769
|
+
}
|
|
7770
|
+
}
|
|
7771
|
+
for (const [key, cellA] of a.cells) {
|
|
7772
|
+
if (!b.cells.has(key)) {
|
|
7773
|
+
entries.push({
|
|
7774
|
+
key,
|
|
7775
|
+
kind: "deleted",
|
|
7776
|
+
before: cellA.value
|
|
7777
|
+
});
|
|
7778
|
+
deleted++;
|
|
7779
|
+
}
|
|
7780
|
+
}
|
|
7781
|
+
return {
|
|
7782
|
+
from_fabric_id: a.fabric_id,
|
|
7783
|
+
to_fabric_id: b.fabric_id,
|
|
7784
|
+
entries,
|
|
7785
|
+
added_count: added,
|
|
7786
|
+
modified_count: modified,
|
|
7787
|
+
deleted_count: deleted
|
|
7788
|
+
};
|
|
7789
|
+
}
|
|
7790
|
+
function hashState(cells) {
|
|
7791
|
+
const keys = [...cells.keys()].sort();
|
|
7792
|
+
const payload = keys.map((k) => `${k}=${JSON.stringify(cells.get(k).value)}`).join("\n");
|
|
7793
|
+
return (0, import_crypto12.createHash)("sha256").update(payload).digest("hex");
|
|
7794
|
+
}
|
|
7795
|
+
var import_crypto12;
|
|
7796
|
+
var init_fabric_engine = __esm({
|
|
7797
|
+
"src/needle/fabric.engine.ts"() {
|
|
7798
|
+
import_crypto12 = require("crypto");
|
|
7799
|
+
}
|
|
7800
|
+
});
|
|
7801
|
+
|
|
7802
|
+
// src/needle/pattern.engine.ts
|
|
7803
|
+
function detectSequencePatterns(stitches, windowSize, minOccurrences) {
|
|
7804
|
+
if (stitches.length < windowSize || windowSize < 2) return [];
|
|
7805
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
7806
|
+
const sequenceCounts = /* @__PURE__ */ new Map();
|
|
7807
|
+
for (let i = 0; i <= sorted.length - windowSize; i++) {
|
|
7808
|
+
const window = sorted.slice(i, i + windowSize);
|
|
7809
|
+
const key = window.map((s) => s.intent).join("\u2192");
|
|
7810
|
+
const ids = window.map((s) => s.stitch_id);
|
|
7811
|
+
const existing = sequenceCounts.get(key);
|
|
7812
|
+
if (existing) {
|
|
7813
|
+
existing.count++;
|
|
7814
|
+
existing.stitch_ids.push(ids);
|
|
7815
|
+
} else {
|
|
7816
|
+
sequenceCounts.set(key, { count: 1, stitch_ids: [ids] });
|
|
7817
|
+
}
|
|
7818
|
+
}
|
|
7819
|
+
const patterns = [];
|
|
7820
|
+
const now = Date.now();
|
|
7821
|
+
for (const [key, data] of sequenceCounts) {
|
|
7822
|
+
if (data.count < minOccurrences) continue;
|
|
7823
|
+
const intents = key.split("\u2192");
|
|
7824
|
+
const confidence = Math.min(data.count / (minOccurrences * 2), 1);
|
|
7825
|
+
patterns.push({
|
|
7826
|
+
pattern_id: `pat_seq_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
7827
|
+
kind: "sequence",
|
|
7828
|
+
name: `Sequence: ${intents.join(" \u2192 ")}`,
|
|
7829
|
+
signature: {
|
|
7830
|
+
intent_sequence: intents,
|
|
7831
|
+
min_length: windowSize,
|
|
7832
|
+
max_length: windowSize
|
|
7833
|
+
},
|
|
7834
|
+
confidence,
|
|
7835
|
+
occurrence_count: data.count,
|
|
7836
|
+
first_seen_at: now,
|
|
7837
|
+
last_seen_at: now,
|
|
7838
|
+
seen_in_threads: [...new Set(
|
|
7839
|
+
data.stitch_ids.flatMap(
|
|
7840
|
+
(ids) => ids.map((id) => sorted.find((s) => s.stitch_id === id)?.thread_id).filter(Boolean)
|
|
7841
|
+
)
|
|
7842
|
+
)],
|
|
7843
|
+
classification: "unclassified"
|
|
7844
|
+
});
|
|
7845
|
+
}
|
|
7846
|
+
return patterns;
|
|
7847
|
+
}
|
|
7848
|
+
function detectKnotPatterns(knots, minOccurrences) {
|
|
7849
|
+
const groups = /* @__PURE__ */ new Map();
|
|
7850
|
+
for (const knot of knots) {
|
|
7851
|
+
if (knot.status !== "tied") continue;
|
|
7852
|
+
const key = `${knot.type}:${knot.stitch_ids.length}`;
|
|
7853
|
+
const group = groups.get(key) ?? [];
|
|
7854
|
+
group.push(knot);
|
|
7855
|
+
groups.set(key, group);
|
|
7856
|
+
}
|
|
7857
|
+
const patterns = [];
|
|
7858
|
+
const now = Date.now();
|
|
7859
|
+
for (const [key, group] of groups) {
|
|
7860
|
+
if (group.length < minOccurrences) continue;
|
|
7861
|
+
const [type, sizeStr] = key.split(":");
|
|
7862
|
+
const size = parseInt(sizeStr, 10);
|
|
7863
|
+
const confidence = Math.min(group.length / (minOccurrences * 2), 1);
|
|
7864
|
+
patterns.push({
|
|
7865
|
+
pattern_id: `pat_knot_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
7866
|
+
kind: "knot",
|
|
7867
|
+
name: `Knot: ${type} (${size} stitches)`,
|
|
7868
|
+
signature: {
|
|
7869
|
+
knot_type: type,
|
|
7870
|
+
knot_size: size
|
|
7871
|
+
},
|
|
7872
|
+
confidence,
|
|
7873
|
+
occurrence_count: group.length,
|
|
7874
|
+
first_seen_at: now,
|
|
7875
|
+
last_seen_at: now,
|
|
7876
|
+
seen_in_threads: [...new Set(group.map((k) => k.thread_id))],
|
|
7877
|
+
classification: "unclassified"
|
|
7878
|
+
});
|
|
7879
|
+
}
|
|
7880
|
+
return patterns;
|
|
7881
|
+
}
|
|
7882
|
+
function matchPatterns(stitches, patterns) {
|
|
7883
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
7884
|
+
const matches = [];
|
|
7885
|
+
const now = Date.now();
|
|
7886
|
+
for (const pattern of patterns) {
|
|
7887
|
+
if (pattern.kind === "sequence" && pattern.signature.intent_sequence) {
|
|
7888
|
+
const seq = pattern.signature.intent_sequence;
|
|
7889
|
+
const seqLen = seq.length;
|
|
7890
|
+
for (let i = 0; i <= sorted.length - seqLen; i++) {
|
|
7891
|
+
const window = sorted.slice(i, i + seqLen);
|
|
7892
|
+
const windowIntents = window.map((s) => s.intent);
|
|
7893
|
+
if (windowIntents.every((intent, idx) => intent === seq[idx])) {
|
|
7894
|
+
matches.push({
|
|
7895
|
+
pattern_id: pattern.pattern_id,
|
|
7896
|
+
matched_stitch_ids: window.map((s) => s.stitch_id),
|
|
7897
|
+
match_score: 1,
|
|
7898
|
+
thread_id: window[0].thread_id,
|
|
7899
|
+
detected_at: now
|
|
7900
|
+
});
|
|
7901
|
+
}
|
|
7902
|
+
}
|
|
7903
|
+
}
|
|
7904
|
+
}
|
|
7905
|
+
return matches;
|
|
7906
|
+
}
|
|
7907
|
+
function recordOccurrence(pattern, threadId) {
|
|
7908
|
+
pattern.occurrence_count++;
|
|
7909
|
+
pattern.last_seen_at = Date.now();
|
|
7910
|
+
pattern.confidence = 1 - 1 / (1 + pattern.occurrence_count * 0.5);
|
|
7911
|
+
if (!pattern.seen_in_threads.includes(threadId)) {
|
|
7912
|
+
pattern.seen_in_threads.push(threadId);
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
function detectAnomalies(recentStitches, knownPatterns, threshold = 0.7) {
|
|
7916
|
+
const anomalies = [];
|
|
7917
|
+
const sorted = [...recentStitches].sort((a, b) => a.sequence - b.sequence);
|
|
7918
|
+
const now = Date.now();
|
|
7919
|
+
for (const pattern of knownPatterns) {
|
|
7920
|
+
if (pattern.kind !== "sequence" || !pattern.signature.intent_sequence) continue;
|
|
7921
|
+
if (pattern.confidence < threshold) continue;
|
|
7922
|
+
const seq = pattern.signature.intent_sequence;
|
|
7923
|
+
if (sorted.length >= 1 && sorted.length < seq.length) {
|
|
7924
|
+
const partialMatch = sorted.every(
|
|
7925
|
+
(s, i) => i < seq.length && s.intent === seq[i]
|
|
7926
|
+
);
|
|
7927
|
+
if (partialMatch) {
|
|
7928
|
+
const expectedNext = seq[sorted.length];
|
|
7929
|
+
const lastStitch = sorted[sorted.length - 1];
|
|
7930
|
+
if (pattern.occurrence_count >= 3) {
|
|
7931
|
+
anomalies.push({
|
|
7932
|
+
pattern_id: `pat_anom_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
7933
|
+
kind: "anomaly",
|
|
7934
|
+
name: `Incomplete: ${pattern.name}`,
|
|
7935
|
+
description: `Expected '${expectedNext}' after '${lastStitch.intent}' based on pattern '${pattern.name}'`,
|
|
7936
|
+
signature: pattern.signature,
|
|
7937
|
+
confidence: pattern.confidence * 0.8,
|
|
7938
|
+
occurrence_count: 1,
|
|
7939
|
+
first_seen_at: now,
|
|
7940
|
+
last_seen_at: now,
|
|
7941
|
+
seen_in_threads: [lastStitch.thread_id],
|
|
7942
|
+
classification: "anomalous"
|
|
7943
|
+
});
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
return anomalies;
|
|
7949
|
+
}
|
|
7950
|
+
var import_crypto13, InMemoryPatternStore;
|
|
7951
|
+
var init_pattern_engine = __esm({
|
|
7952
|
+
"src/needle/pattern.engine.ts"() {
|
|
7953
|
+
import_crypto13 = require("crypto");
|
|
7954
|
+
InMemoryPatternStore = class {
|
|
7955
|
+
constructor() {
|
|
7956
|
+
this.patterns = /* @__PURE__ */ new Map();
|
|
7957
|
+
}
|
|
7958
|
+
save(pattern) {
|
|
7959
|
+
this.patterns.set(pattern.pattern_id, pattern);
|
|
7960
|
+
}
|
|
7961
|
+
get(patternId) {
|
|
7962
|
+
return this.patterns.get(patternId);
|
|
7963
|
+
}
|
|
7964
|
+
findByKind(kind) {
|
|
7965
|
+
return [...this.patterns.values()].filter((p) => p.kind === kind);
|
|
7966
|
+
}
|
|
7967
|
+
findByIntent(intent) {
|
|
7968
|
+
return [...this.patterns.values()].filter(
|
|
7969
|
+
(p) => p.signature.intent_sequence?.includes(intent)
|
|
7970
|
+
);
|
|
7971
|
+
}
|
|
7972
|
+
all() {
|
|
7973
|
+
return [...this.patterns.values()];
|
|
7974
|
+
}
|
|
7975
|
+
};
|
|
7976
|
+
}
|
|
7977
|
+
});
|
|
7978
|
+
|
|
7979
|
+
// src/sensors/tps.sensor.ts
|
|
7980
|
+
var require_tps_sensor = __commonJS({
|
|
7981
|
+
"src/sensors/tps.sensor.ts"(exports2) {
|
|
7982
|
+
"use strict";
|
|
7983
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
7984
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7985
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7986
|
+
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;
|
|
7987
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7988
|
+
};
|
|
7989
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
7990
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7991
|
+
};
|
|
7992
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7993
|
+
exports2.TpsSensor = void 0;
|
|
7994
|
+
var common_1 = require("@nestjs/common");
|
|
7995
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
7996
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
7997
|
+
var TPS_EPOCH_MS = 9343548e5;
|
|
7998
|
+
function parseINotation(tps) {
|
|
7999
|
+
if (!tps.startsWith("i"))
|
|
8000
|
+
return null;
|
|
8001
|
+
const num = Number(tps.slice(1));
|
|
8002
|
+
if (!Number.isFinite(num))
|
|
8003
|
+
return null;
|
|
8004
|
+
return TPS_EPOCH_MS + num;
|
|
8005
|
+
}
|
|
8006
|
+
var TpsSensor2 = class TpsSensor {
|
|
8007
|
+
constructor(options = {}) {
|
|
8008
|
+
this.name = "TpsSensor";
|
|
8009
|
+
this.order = sensor_bands_1.BAND.POLICY + 2;
|
|
8010
|
+
this.maxDriftMs = options.maxDriftMs ?? 3e4;
|
|
8011
|
+
this.resolver = options.resolver ?? parseINotation;
|
|
8012
|
+
}
|
|
8013
|
+
supports(input) {
|
|
8014
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
8015
|
+
return typeof tps === "string" && tps.length > 0;
|
|
8016
|
+
}
|
|
8017
|
+
async run(input) {
|
|
8018
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
8019
|
+
const resolved = this.resolver(tps);
|
|
8020
|
+
if (resolved === null) {
|
|
8021
|
+
return {
|
|
8022
|
+
allow: false,
|
|
8023
|
+
riskScore: 80,
|
|
8024
|
+
reasons: [`TPS coordinate '${tps}' is structurally invalid`],
|
|
8025
|
+
code: "TPS_INVALID_FORMAT"
|
|
8026
|
+
};
|
|
8027
|
+
}
|
|
8028
|
+
const now = Date.now();
|
|
8029
|
+
const drift = Math.abs(now - resolved);
|
|
8030
|
+
if (drift > this.maxDriftMs) {
|
|
8031
|
+
const direction = resolved > now ? "future" : "past";
|
|
8032
|
+
return {
|
|
8033
|
+
allow: false,
|
|
8034
|
+
riskScore: 70,
|
|
8035
|
+
reasons: [
|
|
8036
|
+
`TPS drift ${drift}ms exceeds max ${this.maxDriftMs}ms (${direction})`
|
|
8037
|
+
],
|
|
8038
|
+
code: "TPS_DRIFT_EXCEEDED",
|
|
8039
|
+
tags: { tpsDriftMs: drift, tpsDirection: direction }
|
|
8040
|
+
};
|
|
8041
|
+
}
|
|
8042
|
+
return {
|
|
8043
|
+
allow: true,
|
|
8044
|
+
riskScore: 0,
|
|
8045
|
+
reasons: [],
|
|
8046
|
+
tags: {
|
|
8047
|
+
tpsResolved: resolved,
|
|
8048
|
+
tpsDriftMs: drift
|
|
8049
|
+
}
|
|
8050
|
+
};
|
|
8051
|
+
}
|
|
8052
|
+
};
|
|
8053
|
+
exports2.TpsSensor = TpsSensor2;
|
|
8054
|
+
exports2.TpsSensor = TpsSensor2 = __decorate([
|
|
8055
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8056
|
+
(0, common_1.Injectable)(),
|
|
8057
|
+
__metadata("design:paramtypes", [Object])
|
|
8058
|
+
], TpsSensor2);
|
|
8059
|
+
}
|
|
8060
|
+
});
|
|
8061
|
+
|
|
8062
|
+
// src/sensors/risk-gate.sensor.ts
|
|
8063
|
+
var require_risk_gate_sensor = __commonJS({
|
|
8064
|
+
"src/sensors/risk-gate.sensor.ts"(exports2) {
|
|
8065
|
+
"use strict";
|
|
8066
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
8067
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8068
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8069
|
+
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;
|
|
8070
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8071
|
+
};
|
|
8072
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
8073
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8074
|
+
};
|
|
8075
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8076
|
+
exports2.RiskGateSensor = void 0;
|
|
8077
|
+
var common_1 = require("@nestjs/common");
|
|
8078
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
8079
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
8080
|
+
var risk_1 = (init_risk(), __toCommonJS(risk_exports));
|
|
8081
|
+
var SEVERITY_WEIGHT = {
|
|
8082
|
+
low: 10,
|
|
8083
|
+
medium: 25,
|
|
8084
|
+
high: 50,
|
|
8085
|
+
critical: 100
|
|
8086
|
+
};
|
|
8087
|
+
var RiskGateSensor2 = class RiskGateSensor {
|
|
8088
|
+
constructor(options) {
|
|
8089
|
+
this.name = "RiskGateSensor";
|
|
8090
|
+
this.order = sensor_bands_1.BAND.BUSINESS + 10;
|
|
8091
|
+
this.collectors = options.collectors;
|
|
8092
|
+
this.denyThreshold = options.denyThreshold ?? 75;
|
|
8093
|
+
this.flagThreshold = options.flagThreshold ?? 40;
|
|
8094
|
+
}
|
|
8095
|
+
async run(input) {
|
|
8096
|
+
const results = await Promise.all(this.collectors.map((c) => c(input)));
|
|
8097
|
+
const signals = results.flat();
|
|
8098
|
+
let totalWeight = 0;
|
|
8099
|
+
let weightedSum = 0;
|
|
8100
|
+
for (const signal of signals) {
|
|
8101
|
+
const w = SEVERITY_WEIGHT[signal.severity];
|
|
8102
|
+
totalWeight += 1;
|
|
8103
|
+
weightedSum += w;
|
|
8104
|
+
}
|
|
8105
|
+
const aggregateScore = totalWeight > 0 ? Math.min(100, Math.round(weightedSum / totalWeight)) : 0;
|
|
8106
|
+
const evaluation = this.evaluate(aggregateScore, signals);
|
|
8107
|
+
input.metadata = {
|
|
8108
|
+
...input.metadata ?? {},
|
|
8109
|
+
riskEvaluation: evaluation
|
|
8110
|
+
};
|
|
8111
|
+
if (evaluation.decision === risk_1.RiskDecision.DENY) {
|
|
8112
|
+
return {
|
|
8113
|
+
allow: false,
|
|
8114
|
+
riskScore: aggregateScore,
|
|
8115
|
+
reasons: signals.map((s) => s.message),
|
|
8116
|
+
code: "RISK_GATE_DENY",
|
|
8117
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
8118
|
+
};
|
|
8119
|
+
}
|
|
8120
|
+
if (evaluation.decision === risk_1.RiskDecision.THROTTLE) {
|
|
8121
|
+
return {
|
|
8122
|
+
allow: false,
|
|
8123
|
+
riskScore: aggregateScore,
|
|
8124
|
+
reasons: signals.map((s) => s.message),
|
|
8125
|
+
code: "RISK_GATE_THROTTLE",
|
|
8126
|
+
retryAfterMs: evaluation.retryAfterMs,
|
|
8127
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
8128
|
+
};
|
|
8129
|
+
}
|
|
8130
|
+
return {
|
|
8131
|
+
allow: true,
|
|
8132
|
+
riskScore: aggregateScore,
|
|
8133
|
+
reasons: signals.filter((s) => s.severity === "medium" || s.severity === "high").map((s) => s.message),
|
|
8134
|
+
tags: {
|
|
8135
|
+
riskDecision: evaluation.decision,
|
|
8136
|
+
signalCount: signals.length
|
|
8137
|
+
}
|
|
8138
|
+
};
|
|
8139
|
+
}
|
|
8140
|
+
evaluate(score, signals) {
|
|
8141
|
+
const hasCritical = signals.some((s) => s.severity === "critical");
|
|
8142
|
+
if (hasCritical) {
|
|
8143
|
+
return {
|
|
8144
|
+
decision: risk_1.RiskDecision.DENY,
|
|
8145
|
+
reason: "Critical risk signal detected",
|
|
8146
|
+
confidence: 1,
|
|
8147
|
+
signals
|
|
8148
|
+
};
|
|
8149
|
+
}
|
|
8150
|
+
if (score >= this.denyThreshold) {
|
|
8151
|
+
return {
|
|
8152
|
+
decision: risk_1.RiskDecision.DENY,
|
|
8153
|
+
reason: `Aggregate risk score ${score} exceeds deny threshold ${this.denyThreshold}`,
|
|
8154
|
+
confidence: score / 100,
|
|
8155
|
+
signals
|
|
8156
|
+
};
|
|
8157
|
+
}
|
|
8158
|
+
if (score >= this.flagThreshold) {
|
|
8159
|
+
return {
|
|
8160
|
+
decision: risk_1.RiskDecision.STEP_UP,
|
|
8161
|
+
reason: `Aggregate risk score ${score} exceeds flag threshold ${this.flagThreshold}`,
|
|
8162
|
+
confidence: score / 100,
|
|
8163
|
+
signals
|
|
8164
|
+
};
|
|
8165
|
+
}
|
|
8166
|
+
return {
|
|
8167
|
+
decision: risk_1.RiskDecision.ALLOW,
|
|
8168
|
+
confidence: 1 - score / 100,
|
|
8169
|
+
signals
|
|
8170
|
+
};
|
|
8171
|
+
}
|
|
8172
|
+
};
|
|
8173
|
+
exports2.RiskGateSensor = RiskGateSensor2;
|
|
8174
|
+
exports2.RiskGateSensor = RiskGateSensor2 = __decorate([
|
|
8175
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8176
|
+
(0, common_1.Injectable)(),
|
|
8177
|
+
__metadata("design:paramtypes", [Object])
|
|
8178
|
+
], RiskGateSensor2);
|
|
8179
|
+
}
|
|
8180
|
+
});
|
|
8181
|
+
|
|
8182
|
+
// src/sensors/tickauth.sensor.ts
|
|
8183
|
+
var require_tickauth_sensor = __commonJS({
|
|
8184
|
+
"src/sensors/tickauth.sensor.ts"(exports2) {
|
|
8185
|
+
"use strict";
|
|
8186
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
8187
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8188
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8189
|
+
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;
|
|
8190
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8191
|
+
};
|
|
8192
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
8193
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8194
|
+
};
|
|
8195
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8196
|
+
exports2.TickAuthSensor = void 0;
|
|
8197
|
+
var common_1 = require("@nestjs/common");
|
|
8198
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
8199
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
8200
|
+
var TickAuthSensor2 = class TickAuthSensor {
|
|
8201
|
+
constructor(options = {}) {
|
|
8202
|
+
this.name = "TickAuthSensor";
|
|
8203
|
+
this.order = sensor_bands_1.BAND.IDENTITY + 40;
|
|
8204
|
+
this.verifier = options.verifier;
|
|
8205
|
+
this.matchIntent = options.matchIntent ?? true;
|
|
8206
|
+
this.acceptTypes = options.acceptTypes?.length ? new Set(options.acceptTypes) : null;
|
|
8207
|
+
}
|
|
8208
|
+
supports(input) {
|
|
8209
|
+
return !!(input.metadata?.capsule || input.metadata?.tickauthCapsule || input.metadata?.cceEnvelope?.capsule);
|
|
8210
|
+
}
|
|
8211
|
+
async run(input) {
|
|
8212
|
+
const capsule = input.metadata?.capsule ?? input.metadata?.tickauthCapsule ?? input.metadata?.cceEnvelope?.capsule;
|
|
8213
|
+
if (!capsule) {
|
|
8214
|
+
return {
|
|
8215
|
+
allow: false,
|
|
8216
|
+
riskScore: 90,
|
|
8217
|
+
reasons: ["TickAuth capsule not found"],
|
|
8218
|
+
code: "TICKAUTH_MISSING"
|
|
8219
|
+
};
|
|
8220
|
+
}
|
|
8221
|
+
if (!capsule.capsule_id || typeof capsule.capsule_id !== "string") {
|
|
8222
|
+
return {
|
|
8223
|
+
allow: false,
|
|
8224
|
+
riskScore: 100,
|
|
8225
|
+
reasons: ["TickAuth capsule has no valid capsule_id"],
|
|
8226
|
+
code: "TICKAUTH_INVALID_ID"
|
|
8227
|
+
};
|
|
8228
|
+
}
|
|
8229
|
+
const status = capsule.verification?.status;
|
|
8230
|
+
if (status && status !== "approved") {
|
|
8231
|
+
return {
|
|
8232
|
+
allow: false,
|
|
8233
|
+
riskScore: 100,
|
|
8234
|
+
reasons: [
|
|
8235
|
+
`TickAuth capsule status is '${status}'${capsule.verification?.reason ? `: ${capsule.verification.reason}` : ""}`
|
|
8236
|
+
],
|
|
8237
|
+
code: `TICKAUTH_STATUS_${status.toUpperCase()}`
|
|
8238
|
+
};
|
|
8239
|
+
}
|
|
8240
|
+
if (this.acceptTypes && capsule.capsule_type) {
|
|
8241
|
+
if (!this.acceptTypes.has(capsule.capsule_type)) {
|
|
8242
|
+
return {
|
|
8243
|
+
allow: false,
|
|
8244
|
+
riskScore: 80,
|
|
8245
|
+
reasons: [
|
|
8246
|
+
`TickAuth capsule type '${capsule.capsule_type}' is not in accept list`
|
|
8247
|
+
],
|
|
8248
|
+
code: "TICKAUTH_TYPE_REJECTED"
|
|
8249
|
+
};
|
|
8250
|
+
}
|
|
8251
|
+
}
|
|
8252
|
+
if (this.matchIntent && input.intent && capsule.intent) {
|
|
8253
|
+
if (capsule.intent !== input.intent) {
|
|
8254
|
+
return {
|
|
8255
|
+
allow: false,
|
|
8256
|
+
riskScore: 80,
|
|
8257
|
+
reasons: [
|
|
8258
|
+
`TickAuth capsule intent '${capsule.intent}' does not match AXIS intent '${input.intent}'`
|
|
8259
|
+
],
|
|
8260
|
+
code: "TICKAUTH_INTENT_MISMATCH"
|
|
8261
|
+
};
|
|
8262
|
+
}
|
|
8263
|
+
}
|
|
8264
|
+
if (this.verifier) {
|
|
8265
|
+
const error = await this.verifier(capsule, input);
|
|
8266
|
+
if (error) {
|
|
8267
|
+
return {
|
|
8268
|
+
allow: false,
|
|
8269
|
+
riskScore: 90,
|
|
8270
|
+
reasons: [`TickAuth verification failed: ${error}`],
|
|
8271
|
+
code: "TICKAUTH_VERIFY_FAILED"
|
|
8272
|
+
};
|
|
8273
|
+
}
|
|
8274
|
+
}
|
|
8275
|
+
return {
|
|
8276
|
+
allow: true,
|
|
8277
|
+
riskScore: 0,
|
|
8278
|
+
reasons: [],
|
|
8279
|
+
tags: {
|
|
8280
|
+
tickauthCapsuleId: capsule.capsule_id,
|
|
8281
|
+
tickauthMode: capsule.mode,
|
|
8282
|
+
tickauthSingleUse: capsule.single_use
|
|
8283
|
+
}
|
|
8284
|
+
};
|
|
8285
|
+
}
|
|
8286
|
+
};
|
|
8287
|
+
exports2.TickAuthSensor = TickAuthSensor2;
|
|
8288
|
+
exports2.TickAuthSensor = TickAuthSensor2 = __decorate([
|
|
8289
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8290
|
+
(0, common_1.Injectable)(),
|
|
8291
|
+
__metadata("design:paramtypes", [Object])
|
|
8292
|
+
], TickAuthSensor2);
|
|
8293
|
+
}
|
|
8294
|
+
});
|
|
8295
|
+
|
|
8296
|
+
// src/cce/sensors/cce-envelope-validation.sensor.ts
|
|
8297
|
+
var REQUIRED_FIELDS, CceEnvelopeValidationSensor;
|
|
8298
|
+
var init_cce_envelope_validation_sensor = __esm({
|
|
8299
|
+
"src/cce/sensors/cce-envelope-validation.sensor.ts"() {
|
|
8300
|
+
init_axis_sensor();
|
|
8301
|
+
init_cce_types();
|
|
8302
|
+
REQUIRED_FIELDS = [
|
|
8303
|
+
"ver",
|
|
8304
|
+
"request_id",
|
|
8305
|
+
"correlation_id",
|
|
8306
|
+
"client_kid",
|
|
8307
|
+
"capsule",
|
|
8308
|
+
"encrypted_key",
|
|
8309
|
+
"encrypted_payload",
|
|
8310
|
+
"request_nonce",
|
|
8311
|
+
"client_sig",
|
|
8312
|
+
"content_type",
|
|
8313
|
+
"algorithms"
|
|
8314
|
+
];
|
|
8315
|
+
CceEnvelopeValidationSensor = class {
|
|
8316
|
+
constructor() {
|
|
8317
|
+
this.name = "cce.envelope.validation";
|
|
8318
|
+
this.order = 5;
|
|
8319
|
+
this.phase = "PRE_DECODE";
|
|
8320
|
+
}
|
|
8321
|
+
supports(input) {
|
|
8322
|
+
return input.metadata?.cce === true || input.metadata?.contentType === "application/axis-cce";
|
|
8323
|
+
}
|
|
8324
|
+
async run(input) {
|
|
8325
|
+
const envelope = input.metadata?.cceEnvelope;
|
|
8326
|
+
if (!envelope) {
|
|
8327
|
+
return {
|
|
8328
|
+
allow: false,
|
|
8329
|
+
riskScore: 100,
|
|
8330
|
+
reasons: [CCE_ERROR.INVALID_ENVELOPE],
|
|
8331
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
8332
|
+
};
|
|
8333
|
+
}
|
|
8334
|
+
for (const field of REQUIRED_FIELDS) {
|
|
8335
|
+
if (envelope[field] === void 0 || envelope[field] === null) {
|
|
8336
|
+
return {
|
|
8337
|
+
allow: false,
|
|
8338
|
+
riskScore: 100,
|
|
8339
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: missing ${field}`],
|
|
8340
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
8341
|
+
};
|
|
8342
|
+
}
|
|
8343
|
+
}
|
|
8344
|
+
if (envelope.ver !== CCE_PROTOCOL_VERSION) {
|
|
8345
|
+
return {
|
|
8346
|
+
allow: false,
|
|
8347
|
+
riskScore: 100,
|
|
8348
|
+
reasons: [`${CCE_ERROR.UNSUPPORTED_VERSION}: ${envelope.ver}`],
|
|
8349
|
+
code: CCE_ERROR.UNSUPPORTED_VERSION
|
|
8350
|
+
};
|
|
8351
|
+
}
|
|
8352
|
+
if (!/^[0-9a-f]+$/i.test(envelope.request_nonce)) {
|
|
8353
|
+
return {
|
|
8354
|
+
allow: false,
|
|
8355
|
+
riskScore: 100,
|
|
8356
|
+
reasons: [
|
|
8357
|
+
`${CCE_ERROR.INVALID_ENVELOPE}: invalid request_nonce format`
|
|
8358
|
+
],
|
|
8359
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
8360
|
+
};
|
|
8361
|
+
}
|
|
8362
|
+
if (envelope.request_nonce.length !== CCE_NONCE_BYTES * 2) {
|
|
8363
|
+
return {
|
|
8364
|
+
allow: false,
|
|
8365
|
+
riskScore: 100,
|
|
8366
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: request_nonce wrong length`],
|
|
8367
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
8368
|
+
};
|
|
8369
|
+
}
|
|
8370
|
+
const capsule = envelope.capsule;
|
|
8371
|
+
if (!capsule.capsule_id || !capsule.ver || !capsule.sub || !capsule.kid || !capsule.intent || !capsule.aud || !capsule.issuer_sig) {
|
|
8372
|
+
return {
|
|
8373
|
+
allow: false,
|
|
8374
|
+
riskScore: 100,
|
|
8375
|
+
reasons: [`${CCE_ERROR.MISSING_CAPSULE}: incomplete capsule claims`],
|
|
8376
|
+
code: CCE_ERROR.MISSING_CAPSULE
|
|
8377
|
+
};
|
|
8378
|
+
}
|
|
8379
|
+
if (!envelope.encrypted_key.ciphertext || !envelope.encrypted_key.alg) {
|
|
8380
|
+
return {
|
|
8381
|
+
allow: false,
|
|
8382
|
+
riskScore: 100,
|
|
8383
|
+
reasons: [
|
|
8384
|
+
`${CCE_ERROR.MISSING_ENCRYPTED_KEY}: incomplete encrypted_key`
|
|
8385
|
+
],
|
|
8386
|
+
code: CCE_ERROR.MISSING_ENCRYPTED_KEY
|
|
8387
|
+
};
|
|
6123
8388
|
}
|
|
6124
8389
|
input.metadata = input.metadata ?? {};
|
|
6125
8390
|
input.metadata.cceEnvelopeValid = true;
|
|
@@ -6836,94 +9101,18 @@ var init_cce = __esm({
|
|
|
6836
9101
|
// src/core/index.ts
|
|
6837
9102
|
var core_exports = {};
|
|
6838
9103
|
__export(core_exports, {
|
|
6839
|
-
AXIS_MAGIC: () => import_axis_protocol2.AXIS_MAGIC,
|
|
6840
|
-
AXIS_VERSION: () => import_axis_protocol2.AXIS_VERSION,
|
|
6841
9104
|
AxisError: () => AxisError,
|
|
6842
9105
|
AxisFrameZ: () => AxisFrameZ,
|
|
6843
|
-
BodyProfile: () => import_axis_protocol2.BodyProfile,
|
|
6844
|
-
ERR_BAD_SIGNATURE: () => import_axis_protocol2.ERR_BAD_SIGNATURE,
|
|
6845
|
-
ERR_CONTRACT_VIOLATION: () => import_axis_protocol2.ERR_CONTRACT_VIOLATION,
|
|
6846
|
-
ERR_INVALID_PACKET: () => import_axis_protocol2.ERR_INVALID_PACKET,
|
|
6847
|
-
ERR_REPLAY_DETECTED: () => import_axis_protocol2.ERR_REPLAY_DETECTED,
|
|
6848
|
-
FLAG_BODY_TLV: () => import_axis_protocol2.FLAG_BODY_TLV,
|
|
6849
|
-
FLAG_CHAIN_REQ: () => import_axis_protocol2.FLAG_CHAIN_REQ,
|
|
6850
|
-
FLAG_HAS_WITNESS: () => import_axis_protocol2.FLAG_HAS_WITNESS,
|
|
6851
|
-
MAX_BODY_LEN: () => import_axis_protocol2.MAX_BODY_LEN,
|
|
6852
|
-
MAX_FRAME_LEN: () => import_axis_protocol2.MAX_FRAME_LEN,
|
|
6853
|
-
MAX_HDR_LEN: () => import_axis_protocol2.MAX_HDR_LEN,
|
|
6854
|
-
MAX_SIG_LEN: () => import_axis_protocol2.MAX_SIG_LEN,
|
|
6855
|
-
NCERT_ALG: () => import_axis_protocol2.NCERT_ALG,
|
|
6856
|
-
NCERT_EXP: () => import_axis_protocol2.NCERT_EXP,
|
|
6857
|
-
NCERT_ISSUER_KID: () => import_axis_protocol2.NCERT_ISSUER_KID,
|
|
6858
|
-
NCERT_KID: () => import_axis_protocol2.NCERT_KID,
|
|
6859
|
-
NCERT_NBF: () => import_axis_protocol2.NCERT_NBF,
|
|
6860
|
-
NCERT_NODE_ID: () => import_axis_protocol2.NCERT_NODE_ID,
|
|
6861
|
-
NCERT_PAYLOAD: () => import_axis_protocol2.NCERT_PAYLOAD,
|
|
6862
|
-
NCERT_PUB: () => import_axis_protocol2.NCERT_PUB,
|
|
6863
|
-
NCERT_SCOPE: () => import_axis_protocol2.NCERT_SCOPE,
|
|
6864
|
-
NCERT_SIG: () => import_axis_protocol2.NCERT_SIG,
|
|
6865
|
-
PROOF_CAPSULE: () => import_axis_protocol2.PROOF_CAPSULE,
|
|
6866
|
-
PROOF_JWT: () => import_axis_protocol2.PROOF_JWT,
|
|
6867
|
-
PROOF_LOOM: () => import_axis_protocol2.PROOF_LOOM,
|
|
6868
|
-
PROOF_MTLS: () => import_axis_protocol2.PROOF_MTLS,
|
|
6869
|
-
PROOF_NONE: () => import_axis_protocol2.PROOF_NONE,
|
|
6870
|
-
PROOF_WITNESS: () => import_axis_protocol2.PROOF_WITNESS,
|
|
6871
|
-
ProofType: () => import_axis_protocol2.ProofType,
|
|
6872
|
-
TLV: () => import_axis_protocol.TLV,
|
|
6873
|
-
TLV_ACTOR_ID: () => import_axis_protocol2.TLV_ACTOR_ID,
|
|
6874
|
-
TLV_AUD: () => import_axis_protocol2.TLV_AUD,
|
|
6875
|
-
TLV_BODY_ARR: () => import_axis_protocol2.TLV_BODY_ARR,
|
|
6876
|
-
TLV_BODY_OBJ: () => import_axis_protocol2.TLV_BODY_OBJ,
|
|
6877
|
-
TLV_CAPSULE: () => import_axis_protocol2.TLV_CAPSULE,
|
|
6878
|
-
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
6879
|
-
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
6880
|
-
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
6881
|
-
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
6882
|
-
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
6883
|
-
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
6884
|
-
TLV_LOOM_PRESENCE_ID: () => import_axis_protocol2.TLV_LOOM_PRESENCE_ID,
|
|
6885
|
-
TLV_LOOM_THREAD_HASH: () => import_axis_protocol2.TLV_LOOM_THREAD_HASH,
|
|
6886
|
-
TLV_LOOM_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
6887
|
-
TLV_NODE: () => import_axis_protocol2.TLV_NODE,
|
|
6888
|
-
TLV_NODE_CERT_HASH: () => import_axis_protocol2.TLV_NODE_CERT_HASH,
|
|
6889
|
-
TLV_NODE_KID: () => import_axis_protocol2.TLV_NODE_KID,
|
|
6890
|
-
TLV_NONCE: () => import_axis_protocol2.TLV_NONCE,
|
|
6891
|
-
TLV_OFFSET: () => import_axis_protocol2.TLV_OFFSET,
|
|
6892
|
-
TLV_OK: () => import_axis_protocol2.TLV_OK,
|
|
6893
|
-
TLV_PID: () => import_axis_protocol2.TLV_PID,
|
|
6894
|
-
TLV_PREV_HASH: () => import_axis_protocol2.TLV_PREV_HASH,
|
|
6895
|
-
TLV_PROOF_REF: () => import_axis_protocol2.TLV_PROOF_REF,
|
|
6896
|
-
TLV_PROOF_TYPE: () => import_axis_protocol2.TLV_PROOF_TYPE,
|
|
6897
|
-
TLV_REALM: () => import_axis_protocol2.TLV_REALM,
|
|
6898
|
-
TLV_RECEIPT_HASH: () => import_axis_protocol2.TLV_RECEIPT_HASH,
|
|
6899
|
-
TLV_RID: () => import_axis_protocol2.TLV_RID,
|
|
6900
|
-
TLV_SHA256_CHUNK: () => import_axis_protocol2.TLV_SHA256_CHUNK,
|
|
6901
|
-
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
6902
|
-
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
6903
|
-
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
6904
9106
|
computeReceiptHash: () => computeReceiptHash,
|
|
6905
9107
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
6906
|
-
decodeArray: () => import_axis_protocol.decodeArray,
|
|
6907
|
-
decodeFrame: () => decodeFrame,
|
|
6908
|
-
decodeObject: () => import_axis_protocol.decodeObject,
|
|
6909
|
-
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
6910
|
-
decodeTLVsList: () => import_axis_protocol.decodeTLVsList,
|
|
6911
|
-
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
6912
|
-
encodeFrame: () => encodeFrame,
|
|
6913
|
-
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
6914
|
-
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
6915
9108
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
6916
|
-
getSignTarget: () => getSignTarget,
|
|
6917
9109
|
sha256: () => sha2564,
|
|
6918
9110
|
signFrame: () => signFrame,
|
|
6919
|
-
varintLength: () => import_axis_protocol3.varintLength,
|
|
6920
9111
|
verifyFrameSignature: () => verifyFrameSignature
|
|
6921
9112
|
});
|
|
6922
9113
|
var init_core = __esm({
|
|
6923
9114
|
"src/core/index.ts"() {
|
|
6924
|
-
|
|
6925
|
-
init_varint();
|
|
6926
|
-
init_tlv();
|
|
9115
|
+
__reExport(core_exports, require("@nextera.one/axis-protocol"));
|
|
6927
9116
|
init_axis_bin();
|
|
6928
9117
|
init_signature();
|
|
6929
9118
|
init_axis_error();
|
|
@@ -7178,14 +9367,6 @@ __export(decorators_exports, {
|
|
|
7178
9367
|
Observer: () => Observer,
|
|
7179
9368
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
7180
9369
|
Sensor: () => Sensor,
|
|
7181
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
7182
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
7183
|
-
TlvEnum: () => TlvEnum,
|
|
7184
|
-
TlvField: () => TlvField,
|
|
7185
|
-
TlvMinLen: () => TlvMinLen,
|
|
7186
|
-
TlvRange: () => TlvRange,
|
|
7187
|
-
TlvUtf8Pattern: () => TlvUtf8Pattern,
|
|
7188
|
-
TlvValidate: () => TlvValidate,
|
|
7189
9370
|
mergeCapsulePolicyOptions: () => mergeCapsulePolicyOptions,
|
|
7190
9371
|
normalizeCapsulePolicyOptions: () => normalizeCapsulePolicyOptions
|
|
7191
9372
|
});
|
|
@@ -7201,7 +9382,7 @@ var init_decorators = __esm({
|
|
|
7201
9382
|
init_intent_decorator();
|
|
7202
9383
|
init_observer_decorator();
|
|
7203
9384
|
init_sensor_decorator();
|
|
7204
|
-
|
|
9385
|
+
__reExport(decorators_exports, __toESM(require_tlv_field_decorator()));
|
|
7205
9386
|
}
|
|
7206
9387
|
});
|
|
7207
9388
|
|
|
@@ -7302,6 +9483,25 @@ var init_engine = __esm({
|
|
|
7302
9483
|
}
|
|
7303
9484
|
});
|
|
7304
9485
|
|
|
9486
|
+
// src/idel/idel.types.ts
|
|
9487
|
+
var init_idel_types = __esm({
|
|
9488
|
+
"src/idel/idel.types.ts"() {
|
|
9489
|
+
}
|
|
9490
|
+
});
|
|
9491
|
+
|
|
9492
|
+
// src/idel/index.ts
|
|
9493
|
+
var idel_exports = {};
|
|
9494
|
+
__export(idel_exports, {
|
|
9495
|
+
IdelCompiler: () => IdelCompiler,
|
|
9496
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry
|
|
9497
|
+
});
|
|
9498
|
+
var init_idel = __esm({
|
|
9499
|
+
"src/idel/index.ts"() {
|
|
9500
|
+
init_idel_types();
|
|
9501
|
+
init_idel_compiler();
|
|
9502
|
+
}
|
|
9503
|
+
});
|
|
9504
|
+
|
|
7305
9505
|
// src/loom/index.ts
|
|
7306
9506
|
var loom_exports = {};
|
|
7307
9507
|
__export(loom_exports, {
|
|
@@ -7311,11 +9511,98 @@ __export(loom_exports, {
|
|
|
7311
9511
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
7312
9512
|
canonicalizeGrant: () => canonicalizeGrant,
|
|
7313
9513
|
canonicalizeWrit: () => canonicalizeWrit,
|
|
7314
|
-
|
|
9514
|
+
createGrant: () => createGrant,
|
|
9515
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
9516
|
+
createReceipt: () => createReceipt,
|
|
9517
|
+
createRevocation: () => createRevocation,
|
|
9518
|
+
createWrit: () => createWrit,
|
|
9519
|
+
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
9520
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
9521
|
+
getGrantStatus: () => getGrantStatus,
|
|
9522
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
9523
|
+
grantCoversAction: () => grantCoversAction,
|
|
9524
|
+
isRevoked: () => isRevoked,
|
|
9525
|
+
renewPresence: () => renewPresence,
|
|
9526
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
9527
|
+
updateThreadState: () => updateThreadState,
|
|
9528
|
+
validateGrant: () => validateGrant,
|
|
9529
|
+
validateWrit: () => validateWrit,
|
|
9530
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
9531
|
+
verifyReceiptChain: () => verifyReceiptChain
|
|
7315
9532
|
});
|
|
7316
9533
|
var init_loom = __esm({
|
|
7317
9534
|
"src/loom/index.ts"() {
|
|
7318
9535
|
init_loom_types();
|
|
9536
|
+
init_loom_engine();
|
|
9537
|
+
}
|
|
9538
|
+
});
|
|
9539
|
+
|
|
9540
|
+
// src/needle/needle.types.ts
|
|
9541
|
+
var init_needle_types = __esm({
|
|
9542
|
+
"src/needle/needle.types.ts"() {
|
|
9543
|
+
}
|
|
9544
|
+
});
|
|
9545
|
+
|
|
9546
|
+
// src/needle/knot.types.ts
|
|
9547
|
+
var init_knot_types = __esm({
|
|
9548
|
+
"src/needle/knot.types.ts"() {
|
|
9549
|
+
}
|
|
9550
|
+
});
|
|
9551
|
+
|
|
9552
|
+
// src/needle/fabric.types.ts
|
|
9553
|
+
var init_fabric_types = __esm({
|
|
9554
|
+
"src/needle/fabric.types.ts"() {
|
|
9555
|
+
}
|
|
9556
|
+
});
|
|
9557
|
+
|
|
9558
|
+
// src/needle/pattern.types.ts
|
|
9559
|
+
var init_pattern_types = __esm({
|
|
9560
|
+
"src/needle/pattern.types.ts"() {
|
|
9561
|
+
}
|
|
9562
|
+
});
|
|
9563
|
+
|
|
9564
|
+
// src/needle/index.ts
|
|
9565
|
+
var needle_exports = {};
|
|
9566
|
+
__export(needle_exports, {
|
|
9567
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
9568
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
9569
|
+
applyStitch: () => applyStitch,
|
|
9570
|
+
assembleNeedle: () => assembleNeedle,
|
|
9571
|
+
breakKnot: () => breakKnot,
|
|
9572
|
+
createFabric: () => createFabric,
|
|
9573
|
+
detectAnomalies: () => detectAnomalies,
|
|
9574
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
9575
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
9576
|
+
diffFabrics: () => diffFabrics,
|
|
9577
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
9578
|
+
forkFromKnot: () => forkFromKnot,
|
|
9579
|
+
formStitch: () => formStitch,
|
|
9580
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
9581
|
+
getFabricValue: () => getFabricValue,
|
|
9582
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
9583
|
+
isKnotOpen: () => isKnotOpen,
|
|
9584
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
9585
|
+
lockCells: () => lockCells,
|
|
9586
|
+
matchPatterns: () => matchPatterns,
|
|
9587
|
+
openKnot: () => openKnot,
|
|
9588
|
+
projectAt: () => projectAt,
|
|
9589
|
+
queryFabric: () => queryFabric,
|
|
9590
|
+
recordOccurrence: () => recordOccurrence,
|
|
9591
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
9592
|
+
tieKnot: () => tieKnot,
|
|
9593
|
+
validateKnot: () => validateKnot,
|
|
9594
|
+
weave: () => weave
|
|
9595
|
+
});
|
|
9596
|
+
var init_needle = __esm({
|
|
9597
|
+
"src/needle/index.ts"() {
|
|
9598
|
+
init_needle_types();
|
|
9599
|
+
init_needle_engine();
|
|
9600
|
+
init_knot_types();
|
|
9601
|
+
init_knot_engine();
|
|
9602
|
+
init_fabric_types();
|
|
9603
|
+
init_fabric_engine();
|
|
9604
|
+
init_pattern_types();
|
|
9605
|
+
init_pattern_engine();
|
|
7319
9606
|
}
|
|
7320
9607
|
});
|
|
7321
9608
|
|
|
@@ -8601,6 +10888,143 @@ var require_intent_registry_sensor = __commonJS({
|
|
|
8601
10888
|
}
|
|
8602
10889
|
});
|
|
8603
10890
|
|
|
10891
|
+
// src/sensors/law-evaluation.sensor.ts
|
|
10892
|
+
var require_law_evaluation_sensor = __commonJS({
|
|
10893
|
+
"src/sensors/law-evaluation.sensor.ts"(exports2) {
|
|
10894
|
+
"use strict";
|
|
10895
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
10896
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10897
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10898
|
+
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;
|
|
10899
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10900
|
+
};
|
|
10901
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
10902
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10903
|
+
};
|
|
10904
|
+
var LawEvaluationSensor_1;
|
|
10905
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
10906
|
+
exports2.LawEvaluationSensor = void 0;
|
|
10907
|
+
var common_1 = require("@nestjs/common");
|
|
10908
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
10909
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
10910
|
+
var law_1 = (init_law(), __toCommonJS(law_exports));
|
|
10911
|
+
var LawEvaluationSensor = LawEvaluationSensor_1 = class LawEvaluationSensor {
|
|
10912
|
+
constructor(options = {}) {
|
|
10913
|
+
this.options = options;
|
|
10914
|
+
this.logger = new common_1.Logger(LawEvaluationSensor_1.name);
|
|
10915
|
+
this.name = "LawEvaluationSensor";
|
|
10916
|
+
this.order = sensor_bands_1.BAND.POLICY + 5;
|
|
10917
|
+
}
|
|
10918
|
+
supports(input) {
|
|
10919
|
+
return !!this.options.evaluator && !!input.intent;
|
|
10920
|
+
}
|
|
10921
|
+
async run(input) {
|
|
10922
|
+
const evaluator = this.options.evaluator;
|
|
10923
|
+
if (!evaluator) {
|
|
10924
|
+
return { action: "ALLOW" };
|
|
10925
|
+
}
|
|
10926
|
+
const context = (0, law_1.buildAxisLawEvaluationContext)(input);
|
|
10927
|
+
let result;
|
|
10928
|
+
try {
|
|
10929
|
+
result = await evaluator(context);
|
|
10930
|
+
} catch (error) {
|
|
10931
|
+
const message = error instanceof Error ? error.message : "Unknown law evaluation error";
|
|
10932
|
+
this.logger.error(`Law evaluation failed for ${input.intent}: ${message}`);
|
|
10933
|
+
input.metadata = {
|
|
10934
|
+
...input.metadata ?? {},
|
|
10935
|
+
lawEvaluation: {
|
|
10936
|
+
decision: "deny",
|
|
10937
|
+
reason: "Law evaluation failed",
|
|
10938
|
+
explanation: message
|
|
10939
|
+
}
|
|
10940
|
+
};
|
|
10941
|
+
return {
|
|
10942
|
+
action: "DENY",
|
|
10943
|
+
code: "LAW_EVALUATION_ERROR",
|
|
10944
|
+
reason: message,
|
|
10945
|
+
meta: { lawDecision: "deny" }
|
|
10946
|
+
};
|
|
10947
|
+
}
|
|
10948
|
+
input.metadata = {
|
|
10949
|
+
...input.metadata ?? {},
|
|
10950
|
+
lawEvaluation: {
|
|
10951
|
+
...result,
|
|
10952
|
+
context: sanitizeLawContext(context)
|
|
10953
|
+
}
|
|
10954
|
+
};
|
|
10955
|
+
if (result.decision === "allow") {
|
|
10956
|
+
return {
|
|
10957
|
+
allow: true,
|
|
10958
|
+
riskScore: 0,
|
|
10959
|
+
reasons: result.reason ? [result.reason] : [],
|
|
10960
|
+
tags: {
|
|
10961
|
+
lawDecision: "allow",
|
|
10962
|
+
...result.applicable ? { lawApplicableArticles: result.applicable.length } : {}
|
|
10963
|
+
},
|
|
10964
|
+
meta: result
|
|
10965
|
+
};
|
|
10966
|
+
}
|
|
10967
|
+
if (result.decision === "conditional") {
|
|
10968
|
+
const mode = this.options.conditionalDecision ?? "deny";
|
|
10969
|
+
const reasons = [result.reason, result.explanation].filter(Boolean);
|
|
10970
|
+
if (mode === "allow") {
|
|
10971
|
+
return {
|
|
10972
|
+
allow: true,
|
|
10973
|
+
riskScore: 0,
|
|
10974
|
+
reasons,
|
|
10975
|
+
tags: {
|
|
10976
|
+
lawDecision: "conditional"
|
|
10977
|
+
},
|
|
10978
|
+
meta: result
|
|
10979
|
+
};
|
|
10980
|
+
}
|
|
10981
|
+
if (mode === "flag") {
|
|
10982
|
+
return {
|
|
10983
|
+
action: "FLAG",
|
|
10984
|
+
scoreDelta: 25,
|
|
10985
|
+
reasons: reasons.length > 0 ? reasons : ["Execution is conditionally permitted pending additional requirements"],
|
|
10986
|
+
meta: result
|
|
10987
|
+
};
|
|
10988
|
+
}
|
|
10989
|
+
return {
|
|
10990
|
+
action: "DENY",
|
|
10991
|
+
code: "LAW_CONDITIONAL",
|
|
10992
|
+
reason: reasons.join(" | ") || "Execution is conditionally permitted pending additional requirements",
|
|
10993
|
+
meta: { lawDecision: "conditional", evaluation: result }
|
|
10994
|
+
};
|
|
10995
|
+
}
|
|
10996
|
+
return {
|
|
10997
|
+
action: "DENY",
|
|
10998
|
+
code: "LAW_DENIED",
|
|
10999
|
+
reason: [result.reason, result.explanation].filter(Boolean).join(" | ") || "Execution denied by law evaluation",
|
|
11000
|
+
meta: { lawDecision: "deny", evaluation: result }
|
|
11001
|
+
};
|
|
11002
|
+
}
|
|
11003
|
+
};
|
|
11004
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor;
|
|
11005
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor = LawEvaluationSensor_1 = __decorate([
|
|
11006
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
11007
|
+
(0, common_1.Injectable)(),
|
|
11008
|
+
__metadata("design:paramtypes", [Object])
|
|
11009
|
+
], LawEvaluationSensor);
|
|
11010
|
+
function sanitizeLawContext(context) {
|
|
11011
|
+
return {
|
|
11012
|
+
actorId: context.actorId,
|
|
11013
|
+
intent: context.intent,
|
|
11014
|
+
audience: context.audience,
|
|
11015
|
+
tps: context.tps,
|
|
11016
|
+
country: context.country,
|
|
11017
|
+
ip: context.ip,
|
|
11018
|
+
path: context.path,
|
|
11019
|
+
clientId: context.clientId,
|
|
11020
|
+
deviceId: context.deviceId,
|
|
11021
|
+
sessionId: context.sessionId,
|
|
11022
|
+
capsuleId: context.capsuleId
|
|
11023
|
+
};
|
|
11024
|
+
}
|
|
11025
|
+
}
|
|
11026
|
+
});
|
|
11027
|
+
|
|
8604
11028
|
// src/sensors/proof-presence.sensor.ts
|
|
8605
11029
|
var require_proof_presence_sensor = __commonJS({
|
|
8606
11030
|
"src/sensors/proof-presence.sensor.ts"(exports2) {
|
|
@@ -9308,16 +11732,40 @@ var init_sensors2 = __esm({
|
|
|
9308
11732
|
__reExport(sensors_exports, __toESM(require_header_tlv_limit_sensor()));
|
|
9309
11733
|
__reExport(sensors_exports, __toESM(require_intent_allowlist_sensor()));
|
|
9310
11734
|
__reExport(sensors_exports, __toESM(require_intent_registry_sensor()));
|
|
11735
|
+
__reExport(sensors_exports, __toESM(require_law_evaluation_sensor()));
|
|
9311
11736
|
__reExport(sensors_exports, __toESM(require_proof_presence_sensor()));
|
|
9312
11737
|
__reExport(sensors_exports, __toESM(require_protocol_strict_sensor()));
|
|
9313
11738
|
__reExport(sensors_exports, __toESM(require_receipt_policy_sensor()));
|
|
11739
|
+
__reExport(sensors_exports, __toESM(require_risk_gate_sensor()));
|
|
9314
11740
|
__reExport(sensors_exports, __toESM(require_schema_validation_sensor()));
|
|
9315
11741
|
__reExport(sensors_exports, __toESM(require_stream_scope_sensor()));
|
|
11742
|
+
__reExport(sensors_exports, __toESM(require_tickauth_sensor()));
|
|
9316
11743
|
__reExport(sensors_exports, __toESM(require_tlv_parse_sensor()));
|
|
11744
|
+
__reExport(sensors_exports, __toESM(require_tps_sensor()));
|
|
9317
11745
|
__reExport(sensors_exports, __toESM(require_varint_hardening_sensor()));
|
|
9318
11746
|
}
|
|
9319
11747
|
});
|
|
9320
11748
|
|
|
11749
|
+
// src/timeline/timeline.types.ts
|
|
11750
|
+
var init_timeline_types = __esm({
|
|
11751
|
+
"src/timeline/timeline.types.ts"() {
|
|
11752
|
+
}
|
|
11753
|
+
});
|
|
11754
|
+
|
|
11755
|
+
// src/timeline/index.ts
|
|
11756
|
+
var timeline_exports = {};
|
|
11757
|
+
__export(timeline_exports, {
|
|
11758
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
11759
|
+
TimelineEngine: () => TimelineEngine
|
|
11760
|
+
});
|
|
11761
|
+
var init_timeline = __esm({
|
|
11762
|
+
"src/timeline/index.ts"() {
|
|
11763
|
+
init_timeline_types();
|
|
11764
|
+
init_timeline_store();
|
|
11765
|
+
init_timeline_engine();
|
|
11766
|
+
}
|
|
11767
|
+
});
|
|
11768
|
+
|
|
9321
11769
|
// src/utils/index.ts
|
|
9322
11770
|
var utils_exports = {};
|
|
9323
11771
|
__export(utils_exports, {
|
|
@@ -9394,6 +11842,10 @@ __export(index_exports, {
|
|
|
9394
11842
|
INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
|
|
9395
11843
|
INTENT_SENSORS_KEY: () => INTENT_SENSORS_KEY,
|
|
9396
11844
|
INTENT_TIMEOUTS: () => INTENT_TIMEOUTS,
|
|
11845
|
+
IdelCompiler: () => IdelCompiler,
|
|
11846
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry,
|
|
11847
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
11848
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
9397
11849
|
Intent: () => Intent,
|
|
9398
11850
|
IntentBody: () => IntentBody,
|
|
9399
11851
|
IntentRouter: () => import_intent2.IntentRouter,
|
|
@@ -9435,6 +11887,7 @@ __export(index_exports, {
|
|
|
9435
11887
|
RESPONSE_TAG_UPDATED_BY: () => import_axis_response.RESPONSE_TAG_UPDATED_BY,
|
|
9436
11888
|
ResponseObserver: () => ResponseObserver,
|
|
9437
11889
|
RiskDecision: () => RiskDecision,
|
|
11890
|
+
RiskGateSensor: () => import_risk_gate.RiskGateSensor,
|
|
9438
11891
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
9439
11892
|
Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
|
|
9440
11893
|
Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -9453,7 +11906,7 @@ __export(index_exports, {
|
|
|
9453
11906
|
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
9454
11907
|
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
9455
11908
|
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
9456
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
11909
|
+
TLV_FIELDS_KEY: () => import_tlv_field2.TLV_FIELDS_KEY,
|
|
9457
11910
|
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
9458
11911
|
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
9459
11912
|
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
@@ -9479,20 +11932,28 @@ __export(index_exports, {
|
|
|
9479
11932
|
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
9480
11933
|
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
9481
11934
|
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
9482
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
11935
|
+
TLV_VALIDATORS_KEY: () => import_tlv_field2.TLV_VALIDATORS_KEY,
|
|
9483
11936
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
11937
|
+
TickAuthSensor: () => import_tickauth.TickAuthSensor,
|
|
11938
|
+
TimelineEngine: () => TimelineEngine,
|
|
11939
|
+
TlvEnum: () => import_tlv_field2.TlvEnum,
|
|
11940
|
+
TlvField: () => import_tlv_field2.TlvField,
|
|
11941
|
+
TlvMinLen: () => import_tlv_field2.TlvMinLen,
|
|
11942
|
+
TlvRange: () => import_tlv_field2.TlvRange,
|
|
11943
|
+
TlvUtf8Pattern: () => import_tlv_field2.TlvUtf8Pattern,
|
|
11944
|
+
TlvValidate: () => import_tlv_field2.TlvValidate,
|
|
11945
|
+
TpsSensor: () => import_tps.TpsSensor,
|
|
11946
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
11947
|
+
applyStitch: () => applyStitch,
|
|
11948
|
+
assembleNeedle: () => assembleNeedle,
|
|
9490
11949
|
axis1SigningBytes: () => axis1SigningBytes,
|
|
9491
11950
|
b64urlDecode: () => b64urlDecode,
|
|
9492
11951
|
b64urlDecodeString: () => b64urlDecodeString,
|
|
9493
11952
|
b64urlEncode: () => b64urlEncode,
|
|
9494
11953
|
b64urlEncodeString: () => b64urlEncodeString,
|
|
11954
|
+
breakKnot: () => breakKnot,
|
|
9495
11955
|
buildAts1Hdr: () => buildAts1Hdr,
|
|
11956
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext,
|
|
9496
11957
|
buildDtoDecoder: () => import_dto_schema.buildDtoDecoder,
|
|
9497
11958
|
buildPacket: () => buildPacket,
|
|
9498
11959
|
buildQueueMessage: () => buildQueueMessage,
|
|
@@ -9511,11 +11972,17 @@ __export(index_exports, {
|
|
|
9511
11972
|
computeReceiptHash: () => computeReceiptHash,
|
|
9512
11973
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
9513
11974
|
core: () => core_exports,
|
|
11975
|
+
createFabric: () => createFabric,
|
|
11976
|
+
createGrant: () => createGrant,
|
|
9514
11977
|
createObservation: () => createObservation,
|
|
11978
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
11979
|
+
createReceipt: () => createReceipt,
|
|
11980
|
+
createRevocation: () => createRevocation,
|
|
11981
|
+
createWrit: () => createWrit,
|
|
9515
11982
|
crypto: () => crypto_exports,
|
|
9516
11983
|
decodeArray: () => import_axis_protocol.decodeArray,
|
|
9517
11984
|
decodeAxis1Frame: () => decodeAxis1Frame,
|
|
9518
|
-
decodeFrame: () => decodeFrame,
|
|
11985
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
9519
11986
|
decodeObject: () => import_axis_protocol.decodeObject,
|
|
9520
11987
|
decodeQueueMessage: () => decodeQueueMessage,
|
|
9521
11988
|
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
@@ -9523,30 +11990,52 @@ __export(index_exports, {
|
|
|
9523
11990
|
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
9524
11991
|
decorators: () => decorators_exports,
|
|
9525
11992
|
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
11993
|
+
detectAnomalies: () => detectAnomalies,
|
|
11994
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
11995
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
11996
|
+
diffFabrics: () => diffFabrics,
|
|
9526
11997
|
encVarint: () => encVarint,
|
|
9527
11998
|
encodeAxis1Frame: () => encodeAxis1Frame,
|
|
9528
11999
|
encodeAxisTlvDto: () => encodeAxisTlvDto,
|
|
9529
|
-
encodeFrame: () => encodeFrame,
|
|
12000
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
9530
12001
|
encodeQueueMessage: () => encodeQueueMessage,
|
|
9531
12002
|
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
9532
12003
|
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
9533
12004
|
endStage: () => endStage,
|
|
9534
12005
|
engine: () => engine_exports,
|
|
9535
12006
|
executeCcePipeline: () => executeCcePipeline,
|
|
12007
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
9536
12008
|
extractDtoSchema: () => import_dto_schema.extractDtoSchema,
|
|
9537
12009
|
finalizeObservation: () => finalizeObservation,
|
|
12010
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
12011
|
+
forkFromKnot: () => forkFromKnot,
|
|
12012
|
+
formStitch: () => formStitch,
|
|
9538
12013
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
9539
12014
|
getAxisExecutionContext: () => getAxisExecutionContext,
|
|
9540
|
-
|
|
12015
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
12016
|
+
getFabricValue: () => getFabricValue,
|
|
12017
|
+
getGrantStatus: () => getGrantStatus,
|
|
12018
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
12019
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
12020
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget,
|
|
12021
|
+
grantCoversAction: () => grantCoversAction,
|
|
9541
12022
|
hasScope: () => hasScope,
|
|
9542
12023
|
hashObservation: () => hashObservation,
|
|
12024
|
+
idel: () => idel_exports,
|
|
9543
12025
|
isAdminOpcode: () => isAdminOpcode,
|
|
12026
|
+
isKnotOpen: () => isKnotOpen,
|
|
9544
12027
|
isKnownOpcode: () => isKnownOpcode,
|
|
12028
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
12029
|
+
isRevoked: () => isRevoked,
|
|
9545
12030
|
isTimestampValid: () => isTimestampValid,
|
|
12031
|
+
lockCells: () => lockCells,
|
|
9546
12032
|
loom: () => loom_exports,
|
|
12033
|
+
matchPatterns: () => matchPatterns,
|
|
9547
12034
|
mergeAxisExecutionContext: () => mergeAxisExecutionContext,
|
|
12035
|
+
needle: () => needle_exports,
|
|
9548
12036
|
nonce16: () => nonce16,
|
|
9549
12037
|
normalizeSensorDecision: () => normalizeSensorDecision,
|
|
12038
|
+
openKnot: () => openKnot,
|
|
9550
12039
|
packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
|
|
9551
12040
|
packPasskeyLoginOptionsRes: () => packPasskeyLoginOptionsRes,
|
|
9552
12041
|
packPasskeyLoginVerifyReq: () => packPasskeyLoginVerifyReq,
|
|
@@ -9555,32 +12044,49 @@ __export(index_exports, {
|
|
|
9555
12044
|
parseAutoClaimEntries: () => parseAutoClaimEntries,
|
|
9556
12045
|
parseScope: () => parseScope,
|
|
9557
12046
|
parseStreamEntries: () => parseStreamEntries,
|
|
12047
|
+
projectAt: () => projectAt,
|
|
12048
|
+
queryFabric: () => queryFabric,
|
|
12049
|
+
recordOccurrence: () => recordOccurrence,
|
|
9558
12050
|
recordSensor: () => recordSensor,
|
|
12051
|
+
renewPresence: () => renewPresence,
|
|
9559
12052
|
resolveTimeout: () => resolveTimeout,
|
|
12053
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
9560
12054
|
schemas: () => schemas_exports,
|
|
12055
|
+
scoreTruth: () => scoreTruth,
|
|
9561
12056
|
security: () => security_exports,
|
|
9562
12057
|
sensitivityName: () => sensitivityName,
|
|
9563
12058
|
sensors: () => sensors_exports,
|
|
9564
12059
|
sha256: () => sha2564,
|
|
9565
12060
|
signFrame: () => signFrame,
|
|
12061
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
9566
12062
|
stableJsonStringify: () => stableJsonStringify,
|
|
9567
12063
|
startStage: () => startStage,
|
|
12064
|
+
tieKnot: () => tieKnot,
|
|
12065
|
+
timeline: () => timeline_exports,
|
|
9568
12066
|
tlv: () => tlv,
|
|
9569
12067
|
u64be: () => u64be,
|
|
9570
12068
|
unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
|
|
9571
12069
|
unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
|
|
9572
12070
|
unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
|
|
12071
|
+
updateThreadState: () => updateThreadState,
|
|
9573
12072
|
utf8: () => utf8,
|
|
9574
12073
|
utils: () => utils_exports,
|
|
9575
12074
|
validateFrameShape: () => validateFrameShape,
|
|
12075
|
+
validateGrant: () => validateGrant,
|
|
12076
|
+
validateKnot: () => validateKnot,
|
|
12077
|
+
validateWrit: () => validateWrit,
|
|
9576
12078
|
varintLength: () => import_axis_protocol3.varintLength,
|
|
9577
12079
|
varintU: () => varintU,
|
|
9578
12080
|
verifyFrameSignature: () => verifyFrameSignature,
|
|
12081
|
+
verifyObservation: () => verifyObservation,
|
|
12082
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
12083
|
+
verifyReceiptChain: () => verifyReceiptChain,
|
|
9579
12084
|
verifyResponse: () => verifyResponse,
|
|
12085
|
+
weave: () => weave,
|
|
9580
12086
|
withAxisExecutionContext: () => withAxisExecutionContext
|
|
9581
12087
|
});
|
|
9582
12088
|
module.exports = __toCommonJS(index_exports);
|
|
9583
|
-
var import_dto_schema, import_axis_id, import_axis_response, import_axis_chain, import_intent2, import_axis_files, import_axis_request, import_observer_discovery, import_observer_dispatcher, import_handler_discovery, import_sensor_discovery, import_observer2, import_sensor2, import_axis_sensor_chain;
|
|
12089
|
+
var import_tlv_field2, import_dto_schema, import_axis_id, import_axis_response, import_axis_chain, import_intent2, import_axis_files, import_axis_request, import_observer_discovery, import_observer_dispatcher, import_handler_discovery, import_sensor_discovery, import_observer2, import_sensor2, import_axis_sensor_chain, import_tps, import_risk_gate, import_tickauth;
|
|
9584
12090
|
var init_index = __esm({
|
|
9585
12091
|
"src/index.ts"() {
|
|
9586
12092
|
init_chain_decorator();
|
|
@@ -9592,7 +12098,7 @@ var init_index = __esm({
|
|
|
9592
12098
|
init_observer_decorator();
|
|
9593
12099
|
init_handler_sensors_decorator();
|
|
9594
12100
|
init_sensor_decorator();
|
|
9595
|
-
|
|
12101
|
+
import_tlv_field2 = __toESM(require_tlv_field_decorator());
|
|
9596
12102
|
import_dto_schema = __toESM(require_dto_schema_util());
|
|
9597
12103
|
init_axis_tlv_dto();
|
|
9598
12104
|
import_axis_id = __toESM(require_axis_id_dto());
|
|
@@ -9605,6 +12111,7 @@ var init_index = __esm({
|
|
|
9605
12111
|
init_stable_json();
|
|
9606
12112
|
init_observation_queue_codec();
|
|
9607
12113
|
init_observation_hash();
|
|
12114
|
+
init_truth_scoring();
|
|
9608
12115
|
init_response_observer();
|
|
9609
12116
|
init_constants();
|
|
9610
12117
|
init_varint();
|
|
@@ -9626,6 +12133,7 @@ var init_index = __esm({
|
|
|
9626
12133
|
init_axis_sensor();
|
|
9627
12134
|
init_scopes();
|
|
9628
12135
|
init_capabilities();
|
|
12136
|
+
init_law();
|
|
9629
12137
|
init_risk();
|
|
9630
12138
|
init_opcodes();
|
|
9631
12139
|
init_receipt();
|
|
@@ -9645,19 +12153,33 @@ var init_index = __esm({
|
|
|
9645
12153
|
import_sensor2 = __toESM(require_sensor_registry());
|
|
9646
12154
|
init_axis_observation();
|
|
9647
12155
|
import_axis_sensor_chain = __toESM(require_axis_sensor_chain_service());
|
|
12156
|
+
init_timeline_engine();
|
|
12157
|
+
init_timeline_store();
|
|
9648
12158
|
init_cce_pipeline();
|
|
9649
12159
|
init_cce_types();
|
|
9650
12160
|
init_axis_tlv_codec();
|
|
9651
12161
|
init_loom_types();
|
|
12162
|
+
init_loom_engine();
|
|
12163
|
+
init_idel_compiler();
|
|
12164
|
+
init_needle_engine();
|
|
12165
|
+
init_knot_engine();
|
|
12166
|
+
init_fabric_engine();
|
|
12167
|
+
init_pattern_engine();
|
|
12168
|
+
import_tps = __toESM(require_tps_sensor());
|
|
12169
|
+
import_risk_gate = __toESM(require_risk_gate_sensor());
|
|
12170
|
+
import_tickauth = __toESM(require_tickauth_sensor());
|
|
9652
12171
|
init_cce();
|
|
9653
12172
|
init_core();
|
|
9654
12173
|
init_crypto();
|
|
9655
12174
|
init_decorators();
|
|
9656
12175
|
init_engine();
|
|
12176
|
+
init_idel();
|
|
9657
12177
|
init_loom();
|
|
12178
|
+
init_needle();
|
|
9658
12179
|
init_schemas();
|
|
9659
12180
|
init_security();
|
|
9660
12181
|
init_sensors2();
|
|
12182
|
+
init_timeline();
|
|
9661
12183
|
init_utils();
|
|
9662
12184
|
}
|
|
9663
12185
|
});
|
|
@@ -9726,6 +12248,10 @@ init_index();
|
|
|
9726
12248
|
INTENT_SENSITIVITY_MAP,
|
|
9727
12249
|
INTENT_SENSORS_KEY,
|
|
9728
12250
|
INTENT_TIMEOUTS,
|
|
12251
|
+
IdelCompiler,
|
|
12252
|
+
IdelSchemaRegistry,
|
|
12253
|
+
InMemoryPatternStore,
|
|
12254
|
+
InMemoryTimelineStore,
|
|
9729
12255
|
Intent,
|
|
9730
12256
|
IntentBody,
|
|
9731
12257
|
IntentRouter,
|
|
@@ -9767,6 +12293,7 @@ init_index();
|
|
|
9767
12293
|
RESPONSE_TAG_UPDATED_BY,
|
|
9768
12294
|
ResponseObserver,
|
|
9769
12295
|
RiskDecision,
|
|
12296
|
+
RiskGateSensor,
|
|
9770
12297
|
SENSOR_METADATA_KEY,
|
|
9771
12298
|
Schema2002_PasskeyLoginOptionsRes,
|
|
9772
12299
|
Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -9813,18 +12340,26 @@ init_index();
|
|
|
9813
12340
|
TLV_UPLOAD_ID,
|
|
9814
12341
|
TLV_VALIDATORS_KEY,
|
|
9815
12342
|
TLV_WRIT,
|
|
12343
|
+
TickAuthSensor,
|
|
12344
|
+
TimelineEngine,
|
|
9816
12345
|
TlvEnum,
|
|
9817
12346
|
TlvField,
|
|
9818
12347
|
TlvMinLen,
|
|
9819
12348
|
TlvRange,
|
|
9820
12349
|
TlvUtf8Pattern,
|
|
9821
12350
|
TlvValidate,
|
|
12351
|
+
TpsSensor,
|
|
12352
|
+
addStitchToKnot,
|
|
12353
|
+
applyStitch,
|
|
12354
|
+
assembleNeedle,
|
|
9822
12355
|
axis1SigningBytes,
|
|
9823
12356
|
b64urlDecode,
|
|
9824
12357
|
b64urlDecodeString,
|
|
9825
12358
|
b64urlEncode,
|
|
9826
12359
|
b64urlEncodeString,
|
|
12360
|
+
breakKnot,
|
|
9827
12361
|
buildAts1Hdr,
|
|
12362
|
+
buildAxisLawEvaluationContext,
|
|
9828
12363
|
buildDtoDecoder,
|
|
9829
12364
|
buildPacket,
|
|
9830
12365
|
buildQueueMessage,
|
|
@@ -9843,7 +12378,13 @@ init_index();
|
|
|
9843
12378
|
computeReceiptHash,
|
|
9844
12379
|
computeSignaturePayload,
|
|
9845
12380
|
core,
|
|
12381
|
+
createFabric,
|
|
12382
|
+
createGrant,
|
|
9846
12383
|
createObservation,
|
|
12384
|
+
createPresenceChallenge,
|
|
12385
|
+
createReceipt,
|
|
12386
|
+
createRevocation,
|
|
12387
|
+
createWrit,
|
|
9847
12388
|
crypto,
|
|
9848
12389
|
decodeArray,
|
|
9849
12390
|
decodeAxis1Frame,
|
|
@@ -9855,6 +12396,10 @@ init_index();
|
|
|
9855
12396
|
decodeVarint,
|
|
9856
12397
|
decorators,
|
|
9857
12398
|
deriveAnchorReflection,
|
|
12399
|
+
detectAnomalies,
|
|
12400
|
+
detectKnotPatterns,
|
|
12401
|
+
detectSequencePatterns,
|
|
12402
|
+
diffFabrics,
|
|
9858
12403
|
encVarint,
|
|
9859
12404
|
encodeAxis1Frame,
|
|
9860
12405
|
encodeAxisTlvDto,
|
|
@@ -9865,20 +12410,38 @@ init_index();
|
|
|
9865
12410
|
endStage,
|
|
9866
12411
|
engine,
|
|
9867
12412
|
executeCcePipeline,
|
|
12413
|
+
executeLoomPipeline,
|
|
9868
12414
|
extractDtoSchema,
|
|
9869
12415
|
finalizeObservation,
|
|
12416
|
+
findKnotsForStitch,
|
|
12417
|
+
forkFromKnot,
|
|
12418
|
+
formStitch,
|
|
9870
12419
|
generateEd25519KeyPair,
|
|
9871
12420
|
getAxisExecutionContext,
|
|
12421
|
+
getDecisionPoints,
|
|
12422
|
+
getFabricValue,
|
|
12423
|
+
getGrantStatus,
|
|
12424
|
+
getIrreversibleKnots,
|
|
12425
|
+
getPresenceStatus,
|
|
9872
12426
|
getSignTarget,
|
|
12427
|
+
grantCoversAction,
|
|
9873
12428
|
hasScope,
|
|
9874
12429
|
hashObservation,
|
|
12430
|
+
idel,
|
|
9875
12431
|
isAdminOpcode,
|
|
12432
|
+
isKnotOpen,
|
|
9876
12433
|
isKnownOpcode,
|
|
12434
|
+
isPointOfNoReturn,
|
|
12435
|
+
isRevoked,
|
|
9877
12436
|
isTimestampValid,
|
|
12437
|
+
lockCells,
|
|
9878
12438
|
loom,
|
|
12439
|
+
matchPatterns,
|
|
9879
12440
|
mergeAxisExecutionContext,
|
|
12441
|
+
needle,
|
|
9880
12442
|
nonce16,
|
|
9881
12443
|
normalizeSensorDecision,
|
|
12444
|
+
openKnot,
|
|
9882
12445
|
packPasskeyLoginOptionsReq,
|
|
9883
12446
|
packPasskeyLoginOptionsRes,
|
|
9884
12447
|
packPasskeyLoginVerifyReq,
|
|
@@ -9887,28 +12450,45 @@ init_index();
|
|
|
9887
12450
|
parseAutoClaimEntries,
|
|
9888
12451
|
parseScope,
|
|
9889
12452
|
parseStreamEntries,
|
|
12453
|
+
projectAt,
|
|
12454
|
+
queryFabric,
|
|
12455
|
+
recordOccurrence,
|
|
9890
12456
|
recordSensor,
|
|
12457
|
+
renewPresence,
|
|
9891
12458
|
resolveTimeout,
|
|
12459
|
+
runNeedlePipeline,
|
|
9892
12460
|
schemas,
|
|
12461
|
+
scoreTruth,
|
|
9893
12462
|
security,
|
|
9894
12463
|
sensitivityName,
|
|
9895
12464
|
sensors,
|
|
9896
12465
|
sha256,
|
|
9897
12466
|
signFrame,
|
|
12467
|
+
signPresenceChallenge,
|
|
9898
12468
|
stableJsonStringify,
|
|
9899
12469
|
startStage,
|
|
12470
|
+
tieKnot,
|
|
12471
|
+
timeline,
|
|
9900
12472
|
tlv,
|
|
9901
12473
|
u64be,
|
|
9902
12474
|
unpackPasskeyLoginOptionsReq,
|
|
9903
12475
|
unpackPasskeyLoginVerifyReq,
|
|
9904
12476
|
unpackPasskeyRegisterOptionsReq,
|
|
12477
|
+
updateThreadState,
|
|
9905
12478
|
utf8,
|
|
9906
12479
|
utils,
|
|
9907
12480
|
validateFrameShape,
|
|
12481
|
+
validateGrant,
|
|
12482
|
+
validateKnot,
|
|
12483
|
+
validateWrit,
|
|
9908
12484
|
varintLength,
|
|
9909
12485
|
varintU,
|
|
9910
12486
|
verifyFrameSignature,
|
|
12487
|
+
verifyObservation,
|
|
12488
|
+
verifyPresenceProof,
|
|
12489
|
+
verifyReceiptChain,
|
|
9911
12490
|
verifyResponse,
|
|
12491
|
+
weave,
|
|
9912
12492
|
withAxisExecutionContext
|
|
9913
12493
|
});
|
|
9914
12494
|
//# sourceMappingURL=index.js.map
|