@nextera.one/axis-server-sdk 2.1.5 → 2.1.7
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 -267
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +8 -260
- 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 +1406 -520
- package/dist/index.d.ts +1406 -520
- package/dist/index.js +3091 -433
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3100 -428
- 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-DXHfWxLG.d.mts +0 -133
- package/dist/index-DXHfWxLG.d.ts +0 -133
package/dist/index.js
CHANGED
|
@@ -137,8 +137,10 @@ var init_capsule_policy_decorator = __esm({
|
|
|
137
137
|
var intent_policy_decorator_exports = {};
|
|
138
138
|
__export(intent_policy_decorator_exports, {
|
|
139
139
|
AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
|
|
140
|
+
AXIS_META_KEY: () => AXIS_META_KEY,
|
|
140
141
|
AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
|
|
141
142
|
AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
|
|
143
|
+
Axis: () => Axis,
|
|
142
144
|
AxisAnonymous: () => AxisAnonymous,
|
|
143
145
|
AxisPublic: () => AxisPublic,
|
|
144
146
|
AxisRateLimit: () => AxisRateLimit,
|
|
@@ -251,6 +253,11 @@ function Witness() {
|
|
|
251
253
|
}
|
|
252
254
|
});
|
|
253
255
|
}
|
|
256
|
+
function Axis() {
|
|
257
|
+
return (target) => {
|
|
258
|
+
Reflect.defineMetadata(AXIS_META_KEY, { entry: true }, target);
|
|
259
|
+
};
|
|
260
|
+
}
|
|
254
261
|
function AxisPublic() {
|
|
255
262
|
return (target, propertyKey, descriptor) => {
|
|
256
263
|
if (descriptor) {
|
|
@@ -277,10 +284,11 @@ function AxisRateLimit(config) {
|
|
|
277
284
|
return descriptor;
|
|
278
285
|
};
|
|
279
286
|
}
|
|
280
|
-
var import_reflect_metadata3, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
|
|
287
|
+
var import_reflect_metadata3, AXIS_META_KEY, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
|
|
281
288
|
var init_intent_policy_decorator = __esm({
|
|
282
289
|
"src/decorators/intent-policy.decorator.ts"() {
|
|
283
290
|
import_reflect_metadata3 = require("reflect-metadata");
|
|
291
|
+
AXIS_META_KEY = "axis:axis";
|
|
284
292
|
SENSITIVITY_METADATA_KEY = "axis:sensitivity";
|
|
285
293
|
CONTRACT_METADATA_KEY = "axis:contract";
|
|
286
294
|
REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
|
|
@@ -335,7 +343,8 @@ function Intent(action, options) {
|
|
|
335
343
|
chain: options?.chain,
|
|
336
344
|
bodyProfile: options?.bodyProfile,
|
|
337
345
|
tlv: options?.tlv,
|
|
338
|
-
dto: options?.dto
|
|
346
|
+
dto: options?.dto,
|
|
347
|
+
is: options?.is
|
|
339
348
|
});
|
|
340
349
|
Reflect.defineMetadata(INTENT_ROUTES_KEY, routes, target.constructor);
|
|
341
350
|
};
|
|
@@ -491,76 +500,90 @@ var init_sensor_decorator = __esm({
|
|
|
491
500
|
});
|
|
492
501
|
|
|
493
502
|
// src/decorators/tlv-field.decorator.ts
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
519
|
-
const prop = String(propertyKey);
|
|
520
|
-
let entry = existing.find((e) => e.property === prop);
|
|
521
|
-
if (!entry) {
|
|
522
|
-
entry = { property: prop, tag: 0, validators: [] };
|
|
523
|
-
existing.push(entry);
|
|
503
|
+
var require_tlv_field_decorator = __commonJS({
|
|
504
|
+
"src/decorators/tlv-field.decorator.ts"(exports2) {
|
|
505
|
+
"use strict";
|
|
506
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
507
|
+
exports2.TLV_VALIDATORS_KEY = exports2.TLV_FIELDS_KEY = void 0;
|
|
508
|
+
exports2.TlvField = TlvField2;
|
|
509
|
+
exports2.TlvValidate = TlvValidate2;
|
|
510
|
+
exports2.TlvUtf8Pattern = TlvUtf8Pattern2;
|
|
511
|
+
exports2.TlvMinLen = TlvMinLen2;
|
|
512
|
+
exports2.TlvEnum = TlvEnum2;
|
|
513
|
+
exports2.TlvRange = TlvRange2;
|
|
514
|
+
require("reflect-metadata");
|
|
515
|
+
exports2.TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
516
|
+
exports2.TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
517
|
+
var textDecoder = new TextDecoder();
|
|
518
|
+
function assertUniqueFieldMetadata(existing, property, tag) {
|
|
519
|
+
const duplicateProperty = existing.find((item) => item.property === property);
|
|
520
|
+
if (duplicateProperty) {
|
|
521
|
+
throw new Error(`Duplicate @TlvField for property ${property}`);
|
|
522
|
+
}
|
|
523
|
+
const duplicateTag = existing.find((item) => item.tag === tag);
|
|
524
|
+
if (duplicateTag) {
|
|
525
|
+
throw new Error(`Duplicate @TlvField tag ${tag} for ${property}; already used by ${duplicateTag.property}`);
|
|
526
|
+
}
|
|
524
527
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
return
|
|
528
|
+
function TlvField2(tag, options) {
|
|
529
|
+
return (target, propertyKey) => {
|
|
530
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_FIELDS_KEY, target.constructor) || [];
|
|
531
|
+
const property = String(propertyKey);
|
|
532
|
+
assertUniqueFieldMetadata(existing, property, tag);
|
|
533
|
+
existing.push({
|
|
534
|
+
property,
|
|
535
|
+
tag,
|
|
536
|
+
options
|
|
537
|
+
});
|
|
538
|
+
Reflect.defineMetadata(exports2.TLV_FIELDS_KEY, existing, target.constructor);
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function TlvValidate2(validator) {
|
|
542
|
+
return (target, propertyKey) => {
|
|
543
|
+
const existing = Reflect.getOwnMetadata(exports2.TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
544
|
+
const prop = String(propertyKey);
|
|
545
|
+
let entry = existing.find((e) => e.property === prop);
|
|
546
|
+
if (!entry) {
|
|
547
|
+
entry = { property: prop, tag: 0, validators: [] };
|
|
548
|
+
existing.push(entry);
|
|
549
|
+
}
|
|
550
|
+
entry.validators.push(validator);
|
|
551
|
+
Reflect.defineMetadata(exports2.TLV_VALIDATORS_KEY, existing, target.constructor);
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function TlvUtf8Pattern2(pattern, message) {
|
|
555
|
+
const matcher = new RegExp(pattern.source, pattern.flags);
|
|
556
|
+
return TlvValidate2((val, prop) => {
|
|
557
|
+
const str = textDecoder.decode(val);
|
|
558
|
+
matcher.lastIndex = 0;
|
|
559
|
+
return matcher.test(str) ? null : message || `${prop}: failed pattern check`;
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
function TlvMinLen2(min, message) {
|
|
563
|
+
return TlvValidate2((val, prop) => {
|
|
564
|
+
return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
function TlvEnum2(allowed, message) {
|
|
568
|
+
const set = new Set(allowed);
|
|
569
|
+
return TlvValidate2((val, prop) => {
|
|
570
|
+
const str = textDecoder.decode(val);
|
|
571
|
+
return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function TlvRange2(min, max, message) {
|
|
575
|
+
return TlvValidate2((val, prop) => {
|
|
576
|
+
if (val.length !== 8)
|
|
577
|
+
return `${prop}: u64 must be 8 bytes`;
|
|
578
|
+
let n = 0n;
|
|
579
|
+
for (const b of val)
|
|
580
|
+
n = n << 8n | BigInt(b);
|
|
581
|
+
if (n < min || n > max) {
|
|
582
|
+
return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
});
|
|
554
586
|
}
|
|
555
|
-
return null;
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
var import_reflect_metadata9, TLV_FIELDS_KEY, TLV_VALIDATORS_KEY;
|
|
559
|
-
var init_tlv_field_decorator = __esm({
|
|
560
|
-
"src/decorators/tlv-field.decorator.ts"() {
|
|
561
|
-
import_reflect_metadata9 = require("reflect-metadata");
|
|
562
|
-
TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
563
|
-
TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
564
587
|
}
|
|
565
588
|
});
|
|
566
589
|
|
|
@@ -589,7 +612,7 @@ var require_dto_schema_util = __commonJS({
|
|
|
589
612
|
exports2.extractDtoSchema = extractDtoSchema2;
|
|
590
613
|
exports2.buildDtoDecoder = buildDtoDecoder2;
|
|
591
614
|
require("reflect-metadata");
|
|
592
|
-
var tlv_field_decorator_1 = (
|
|
615
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
593
616
|
var tlv_1 = (init_tlv(), __toCommonJS(tlv_exports));
|
|
594
617
|
function extractDtoSchema2(dto) {
|
|
595
618
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
@@ -698,7 +721,7 @@ var require_axis_id_dto = __commonJS({
|
|
|
698
721
|
};
|
|
699
722
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
700
723
|
exports2.AxisIdDto = void 0;
|
|
701
|
-
var tlv_field_decorator_1 = (
|
|
724
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
702
725
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
703
726
|
var AxisIdDto2 = class extends axis_tlv_dto_1.AxisTlvDto {
|
|
704
727
|
};
|
|
@@ -715,27 +738,27 @@ var require_axis_id_dto = __commonJS({
|
|
|
715
738
|
function AxisPartialType(BaseDto) {
|
|
716
739
|
class PartialDto extends BaseDto {
|
|
717
740
|
}
|
|
718
|
-
const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
|
|
741
|
+
const fields = Reflect.getOwnMetadata(import_tlv_field.TLV_FIELDS_KEY, BaseDto) || [];
|
|
719
742
|
const partialFields = fields.map((f) => ({
|
|
720
743
|
property: f.property,
|
|
721
744
|
tag: f.tag,
|
|
722
745
|
options: { ...f.options, required: false }
|
|
723
746
|
}));
|
|
724
|
-
Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
725
|
-
const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
747
|
+
Reflect.defineMetadata(import_tlv_field.TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
748
|
+
const validators = Reflect.getOwnMetadata(import_tlv_field.TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
726
749
|
if (validators.length > 0) {
|
|
727
|
-
Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
750
|
+
Reflect.defineMetadata(import_tlv_field.TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
728
751
|
}
|
|
729
752
|
Object.defineProperty(PartialDto, "name", {
|
|
730
753
|
value: `Partial${BaseDto.name}`
|
|
731
754
|
});
|
|
732
755
|
return PartialDto;
|
|
733
756
|
}
|
|
734
|
-
var
|
|
757
|
+
var import_reflect_metadata9, import_tlv_field;
|
|
735
758
|
var init_axis_partial_type = __esm({
|
|
736
759
|
"src/base/axis-partial-type.ts"() {
|
|
737
|
-
|
|
738
|
-
|
|
760
|
+
import_reflect_metadata9 = require("reflect-metadata");
|
|
761
|
+
import_tlv_field = __toESM(require_tlv_field_decorator());
|
|
739
762
|
}
|
|
740
763
|
});
|
|
741
764
|
|
|
@@ -754,7 +777,7 @@ var require_axis_response_dto = __commonJS({
|
|
|
754
777
|
};
|
|
755
778
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
756
779
|
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;
|
|
757
|
-
var tlv_field_decorator_1 = (
|
|
780
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
758
781
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
759
782
|
exports2.RESPONSE_TAG_ID = 1;
|
|
760
783
|
exports2.RESPONSE_TAG_CREATED_AT = 2;
|
|
@@ -2059,6 +2082,121 @@ var init_inline_capsule = __esm({
|
|
|
2059
2082
|
}
|
|
2060
2083
|
});
|
|
2061
2084
|
|
|
2085
|
+
// src/engine/registry/sensor.registry.ts
|
|
2086
|
+
var require_sensor_registry = __commonJS({
|
|
2087
|
+
"src/engine/registry/sensor.registry.ts"(exports2) {
|
|
2088
|
+
"use strict";
|
|
2089
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
2090
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2091
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2092
|
+
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;
|
|
2093
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2094
|
+
};
|
|
2095
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
2096
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2097
|
+
};
|
|
2098
|
+
var SensorRegistry_1;
|
|
2099
|
+
var _a;
|
|
2100
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2101
|
+
exports2.SensorRegistry = void 0;
|
|
2102
|
+
var common_1 = require("@nestjs/common");
|
|
2103
|
+
var config_1 = require("@nestjs/config");
|
|
2104
|
+
var SensorRegistry2 = SensorRegistry_1 = class SensorRegistry {
|
|
2105
|
+
constructor(configService) {
|
|
2106
|
+
this.configService = configService;
|
|
2107
|
+
this.sensors = [];
|
|
2108
|
+
this.sensorsByName = /* @__PURE__ */ new Map();
|
|
2109
|
+
this.sensorsByType = /* @__PURE__ */ new Map();
|
|
2110
|
+
this.logger = new common_1.Logger(SensorRegistry_1.name);
|
|
2111
|
+
}
|
|
2112
|
+
register(sensor) {
|
|
2113
|
+
if (!sensor.name) {
|
|
2114
|
+
throw new Error("AxisSensor must have a name");
|
|
2115
|
+
}
|
|
2116
|
+
const enabledSensorsStr = this.configService.get("ENABLED_SENSORS");
|
|
2117
|
+
const disabledSensorsStr = this.configService.get("DISABLED_SENSORS");
|
|
2118
|
+
const enabledSensors = enabledSensorsStr ? enabledSensorsStr.split(",").map((s) => s.trim()) : null;
|
|
2119
|
+
const disabledSensors = disabledSensorsStr ? disabledSensorsStr.split(",").map((s) => s.trim()) : [];
|
|
2120
|
+
if (enabledSensors && !enabledSensors.includes(sensor.name)) {
|
|
2121
|
+
this.logger.log(`Skipping disabled sensor (not in ENABLED_SENSORS): ${sensor.name}`);
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
if (disabledSensors.includes(sensor.name)) {
|
|
2125
|
+
this.logger.log(`Skipping disabled sensor (in DISABLED_SENSORS): ${sensor.name}`);
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
if (sensor.order === void 0) {
|
|
2129
|
+
throw new Error(`AxisSensor "${sensor.name}" must have an order field`);
|
|
2130
|
+
}
|
|
2131
|
+
const isPreDecodeSensor = this.isPreDecodeSensor(sensor);
|
|
2132
|
+
const isPostDecodeSensor = this.isPostDecodeSensor(sensor);
|
|
2133
|
+
if (isPreDecodeSensor && sensor.order >= 40) {
|
|
2134
|
+
this.logger.warn(`AxisSensor "${sensor.name}" is marked as PRE_DECODE but has order ${sensor.order} (should be < 40)`);
|
|
2135
|
+
}
|
|
2136
|
+
if (isPostDecodeSensor && sensor.order < 40) {
|
|
2137
|
+
this.logger.warn(`AxisSensor "${sensor.name}" is marked as POST_DECODE but has order ${sensor.order} (should be >= 40)`);
|
|
2138
|
+
}
|
|
2139
|
+
this.sensors.push(sensor);
|
|
2140
|
+
this.indexSensor(sensor);
|
|
2141
|
+
const phaseLabel = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase || "UNKNOWN";
|
|
2142
|
+
this.logger.debug(`Registered sensor: ${sensor.name} (order: ${sensor.order}, phase: ${phaseLabel})`);
|
|
2143
|
+
}
|
|
2144
|
+
list() {
|
|
2145
|
+
return [...this.sensors].sort((a, b) => (a.order ?? 999) - (b.order ?? 999));
|
|
2146
|
+
}
|
|
2147
|
+
resolve(ref) {
|
|
2148
|
+
if (typeof ref === "string") {
|
|
2149
|
+
return this.sensorsByName.get(ref);
|
|
2150
|
+
}
|
|
2151
|
+
return this.sensorsByType.get(ref) ?? this.sensorsByName.get(ref.name);
|
|
2152
|
+
}
|
|
2153
|
+
getByName(name) {
|
|
2154
|
+
return this.sensorsByName.get(name);
|
|
2155
|
+
}
|
|
2156
|
+
getPreDecodeSensors() {
|
|
2157
|
+
return this.list().filter((s) => (s.order ?? 999) < 40);
|
|
2158
|
+
}
|
|
2159
|
+
getPostDecodeSensors() {
|
|
2160
|
+
return this.list().filter((s) => (s.order ?? 999) >= 40);
|
|
2161
|
+
}
|
|
2162
|
+
isPreDecodeSensor(sensor) {
|
|
2163
|
+
const phase = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase;
|
|
2164
|
+
return phase === "PRE_DECODE" || (sensor.order ?? 999) < 40;
|
|
2165
|
+
}
|
|
2166
|
+
isPostDecodeSensor(sensor) {
|
|
2167
|
+
const phase = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase;
|
|
2168
|
+
return phase === "POST_DECODE" || (sensor.order ?? 999) >= 40;
|
|
2169
|
+
}
|
|
2170
|
+
getSensorCountByPhase() {
|
|
2171
|
+
return {
|
|
2172
|
+
preDecodeCount: this.getPreDecodeSensors().length,
|
|
2173
|
+
postDecodeCount: this.getPostDecodeSensors().length
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
clear() {
|
|
2177
|
+
this.sensors = [];
|
|
2178
|
+
this.sensorsByName.clear();
|
|
2179
|
+
this.sensorsByType.clear();
|
|
2180
|
+
}
|
|
2181
|
+
indexSensor(sensor) {
|
|
2182
|
+
this.sensorsByName.set(sensor.name, sensor);
|
|
2183
|
+
const sensorType = sensor.constructor;
|
|
2184
|
+
if (!sensorType)
|
|
2185
|
+
return;
|
|
2186
|
+
this.sensorsByType.set(sensorType, sensor);
|
|
2187
|
+
if (!this.sensorsByName.has(sensorType.name)) {
|
|
2188
|
+
this.sensorsByName.set(sensorType.name, sensor);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
exports2.SensorRegistry = SensorRegistry2;
|
|
2193
|
+
exports2.SensorRegistry = SensorRegistry2 = SensorRegistry_1 = __decorate([
|
|
2194
|
+
(0, common_1.Injectable)(),
|
|
2195
|
+
__metadata("design:paramtypes", [typeof (_a = typeof config_1.ConfigService !== "undefined" && config_1.ConfigService) === "function" ? _a : Object])
|
|
2196
|
+
], SensorRegistry2);
|
|
2197
|
+
}
|
|
2198
|
+
});
|
|
2199
|
+
|
|
2062
2200
|
// src/engine/intent.router.ts
|
|
2063
2201
|
var require_intent_router = __commonJS({
|
|
2064
2202
|
"src/engine/intent.router.ts"(exports2) {
|
|
@@ -2080,6 +2218,7 @@ var require_intent_router = __commonJS({
|
|
|
2080
2218
|
var IntentRouter_1;
|
|
2081
2219
|
var _a;
|
|
2082
2220
|
var _b;
|
|
2221
|
+
var _c;
|
|
2083
2222
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2084
2223
|
exports2.IntentRouter = void 0;
|
|
2085
2224
|
var common_1 = require("@nestjs/common");
|
|
@@ -2100,11 +2239,33 @@ var require_intent_router = __commonJS({
|
|
|
2100
2239
|
var observer_decorator_1 = (init_observer_decorator(), __toCommonJS(observer_decorator_exports));
|
|
2101
2240
|
var inline_capsule_1 = (init_inline_capsule(), __toCommonJS(inline_capsule_exports));
|
|
2102
2241
|
var axis_sensor_1 = (init_axis_sensor(), __toCommonJS(axis_sensor_exports));
|
|
2242
|
+
var sensor_registry_1 = require_sensor_registry();
|
|
2103
2243
|
var axis_execution_context_1 = (init_axis_execution_context(), __toCommonJS(axis_execution_context_exports));
|
|
2104
2244
|
var observer_dispatcher_service_1 = require_observer_dispatcher_service();
|
|
2105
2245
|
function observerRefKey(ref) {
|
|
2106
2246
|
return typeof ref === "string" ? ref : ref.name;
|
|
2107
2247
|
}
|
|
2248
|
+
function sensorRefKey(ref) {
|
|
2249
|
+
return typeof ref === "string" ? ref : ref.name;
|
|
2250
|
+
}
|
|
2251
|
+
function mergeIntentSensorRefs(...sensorGroups) {
|
|
2252
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2253
|
+
for (const group of sensorGroups) {
|
|
2254
|
+
if (!Array.isArray(group))
|
|
2255
|
+
continue;
|
|
2256
|
+
for (const ref of group) {
|
|
2257
|
+
const key = sensorRefKey(ref);
|
|
2258
|
+
const existing = merged.get(key);
|
|
2259
|
+
if (!existing || typeof existing === "string" && typeof ref !== "string") {
|
|
2260
|
+
merged.set(key, ref);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
return Array.from(merged.values());
|
|
2265
|
+
}
|
|
2266
|
+
function isAxisSensorInstance(value) {
|
|
2267
|
+
return !!value && typeof value.name === "string" && typeof value.run === "function";
|
|
2268
|
+
}
|
|
2108
2269
|
function mergeObserverBindings(bindings) {
|
|
2109
2270
|
const merged = /* @__PURE__ */ new Map();
|
|
2110
2271
|
for (const binding of bindings) {
|
|
@@ -2141,9 +2302,10 @@ var require_intent_router = __commonJS({
|
|
|
2141
2302
|
};
|
|
2142
2303
|
}
|
|
2143
2304
|
var IntentRouter2 = IntentRouter_1 = class IntentRouter {
|
|
2144
|
-
constructor(moduleRef, observerDispatcher) {
|
|
2305
|
+
constructor(moduleRef, observerDispatcher, sensorRegistry) {
|
|
2145
2306
|
this.moduleRef = moduleRef;
|
|
2146
2307
|
this.observerDispatcher = observerDispatcher;
|
|
2308
|
+
this.sensorRegistry = sensorRegistry;
|
|
2147
2309
|
this.logger = new common_1.Logger(IntentRouter_1.name);
|
|
2148
2310
|
this.decoder = new TextDecoder();
|
|
2149
2311
|
this.encoder = new TextEncoder();
|
|
@@ -2311,9 +2473,9 @@ var require_intent_router = __commonJS({
|
|
|
2311
2473
|
if (!handler) {
|
|
2312
2474
|
throw new Error(`Intent not found: ${intent}`);
|
|
2313
2475
|
}
|
|
2314
|
-
const
|
|
2315
|
-
if (
|
|
2316
|
-
await this.runIntentSensors(
|
|
2476
|
+
const sensorRefs = this.intentSensors.get(intent);
|
|
2477
|
+
if (sensorRefs && sensorRefs.length > 0) {
|
|
2478
|
+
await this.runIntentSensors(sensorRefs, intent, frame);
|
|
2317
2479
|
}
|
|
2318
2480
|
const decoder = this.intentDecoders.get(intent);
|
|
2319
2481
|
let decodedBody = frame.body;
|
|
@@ -2384,10 +2546,8 @@ var require_intent_router = __commonJS({
|
|
|
2384
2546
|
this.intentDecoders.set(intent, decoder);
|
|
2385
2547
|
}
|
|
2386
2548
|
const intentSensors = Reflect.getMetadata(intent_sensors_decorator_1.INTENT_SENSORS_KEY, proto, methodName);
|
|
2387
|
-
const
|
|
2388
|
-
|
|
2389
|
-
...Array.isArray(intentSensors) ? intentSensors : []
|
|
2390
|
-
];
|
|
2549
|
+
const meta = Reflect.getMetadata(intent_decorator_1.INTENT_METADATA_KEY, proto, methodName);
|
|
2550
|
+
const combined = mergeIntentSensorRefs(handlerSensors, Array.isArray(intentSensors) ? intentSensors : void 0, Array.isArray(meta?.is) ? meta.is : void 0);
|
|
2391
2551
|
if (combined.length > 0) {
|
|
2392
2552
|
this.intentSensors.set(intent, combined);
|
|
2393
2553
|
}
|
|
@@ -2405,7 +2565,6 @@ var require_intent_router = __commonJS({
|
|
|
2405
2565
|
if (capsulePolicy) {
|
|
2406
2566
|
this.intentCapsulePolicies.set(intent, capsulePolicy);
|
|
2407
2567
|
}
|
|
2408
|
-
const meta = Reflect.getMetadata(intent_decorator_1.INTENT_METADATA_KEY, proto, methodName);
|
|
2409
2568
|
if (meta) {
|
|
2410
2569
|
this.storeSchema({ ...meta, intent });
|
|
2411
2570
|
if (meta.kind) {
|
|
@@ -2473,23 +2632,26 @@ var require_intent_router = __commonJS({
|
|
|
2473
2632
|
return;
|
|
2474
2633
|
await this.observerDispatcher.dispatch(bindings, context);
|
|
2475
2634
|
}
|
|
2476
|
-
async runIntentSensors(
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
} catch {
|
|
2484
|
-
this.logger.warn(`@IntentSensors: could not resolve ${SensorClass.name} for ${intent}`);
|
|
2485
|
-
continue;
|
|
2635
|
+
async runIntentSensors(sensorRefs, intent, frame) {
|
|
2636
|
+
for (const sensorRef of sensorRefs) {
|
|
2637
|
+
const sensor = this.resolveIntentSensor(sensorRef);
|
|
2638
|
+
const sensorName = sensorRefKey(sensorRef);
|
|
2639
|
+
if (!sensor) {
|
|
2640
|
+
this.logger.error(`Intent sensor ${sensorName} is not registered for ${intent}`);
|
|
2641
|
+
throw new Error(`SENSOR_MISSING:${sensorName}`);
|
|
2486
2642
|
}
|
|
2487
2643
|
const sensorInput = {
|
|
2488
2644
|
rawBytes: frame.body,
|
|
2489
2645
|
intent,
|
|
2490
2646
|
body: frame.body,
|
|
2491
2647
|
headerTLVs: frame.headers,
|
|
2492
|
-
|
|
2648
|
+
frameBody: frame.body,
|
|
2649
|
+
metadata: {
|
|
2650
|
+
phase: "intent",
|
|
2651
|
+
intent,
|
|
2652
|
+
schema: this.getSchema(intent),
|
|
2653
|
+
validators: this.getValidators(intent)
|
|
2654
|
+
}
|
|
2493
2655
|
};
|
|
2494
2656
|
if (sensor.supports && !sensor.supports(sensorInput))
|
|
2495
2657
|
continue;
|
|
@@ -2501,6 +2663,21 @@ var require_intent_router = __commonJS({
|
|
|
2501
2663
|
}
|
|
2502
2664
|
}
|
|
2503
2665
|
}
|
|
2666
|
+
resolveIntentSensor(ref) {
|
|
2667
|
+
const registered = this.sensorRegistry?.resolve(ref);
|
|
2668
|
+
if (registered) {
|
|
2669
|
+
return registered;
|
|
2670
|
+
}
|
|
2671
|
+
if (!this.moduleRef || typeof ref === "string") {
|
|
2672
|
+
return void 0;
|
|
2673
|
+
}
|
|
2674
|
+
try {
|
|
2675
|
+
const resolved = this.moduleRef.get(ref, { strict: false });
|
|
2676
|
+
return isAxisSensorInstance(resolved) ? resolved : void 0;
|
|
2677
|
+
} catch {
|
|
2678
|
+
return void 0;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2504
2681
|
getEffectiveCapsulePolicy(intent, frame) {
|
|
2505
2682
|
const registeredPolicy = this.intentCapsulePolicies.get(intent);
|
|
2506
2683
|
const chainConfig = this.intentChains.get(intent);
|
|
@@ -2816,7 +2993,8 @@ var require_intent_router = __commonJS({
|
|
|
2816
2993
|
(0, common_1.Injectable)(),
|
|
2817
2994
|
__param(0, (0, common_1.Optional)()),
|
|
2818
2995
|
__param(1, (0, common_1.Optional)()),
|
|
2819
|
-
|
|
2996
|
+
__param(2, (0, common_1.Optional)()),
|
|
2997
|
+
__metadata("design:paramtypes", [typeof (_a = typeof core_1.ModuleRef !== "undefined" && core_1.ModuleRef) === "function" ? _a : Object, typeof (_b = typeof observer_dispatcher_service_1.ObserverDispatcherService !== "undefined" && observer_dispatcher_service_1.ObserverDispatcherService) === "function" ? _b : Object, typeof (_c = typeof sensor_registry_1.SensorRegistry !== "undefined" && sensor_registry_1.SensorRegistry) === "function" ? _c : Object])
|
|
2820
2998
|
], IntentRouter2);
|
|
2821
2999
|
}
|
|
2822
3000
|
});
|
|
@@ -3455,6 +3633,213 @@ var init_observation_hash = __esm({
|
|
|
3455
3633
|
}
|
|
3456
3634
|
});
|
|
3457
3635
|
|
|
3636
|
+
// src/engine/observation/truth-scoring.ts
|
|
3637
|
+
function scoreTruth(obs, expected) {
|
|
3638
|
+
const anomalies = [];
|
|
3639
|
+
let passedChecks = 0;
|
|
3640
|
+
let totalChecks = 0;
|
|
3641
|
+
totalChecks++;
|
|
3642
|
+
if (obs.endMs && obs.decision) {
|
|
3643
|
+
passedChecks++;
|
|
3644
|
+
} else {
|
|
3645
|
+
anomalies.push({
|
|
3646
|
+
code: "OBS_NOT_FINALIZED",
|
|
3647
|
+
level: "critical",
|
|
3648
|
+
message: "Observation was not finalized"
|
|
3649
|
+
});
|
|
3650
|
+
}
|
|
3651
|
+
totalChecks++;
|
|
3652
|
+
if (obs.stages.length > 0) {
|
|
3653
|
+
passedChecks++;
|
|
3654
|
+
} else {
|
|
3655
|
+
anomalies.push({
|
|
3656
|
+
code: "OBS_NO_STAGES",
|
|
3657
|
+
level: "warning",
|
|
3658
|
+
message: "Observation has no execution stages"
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3661
|
+
totalChecks++;
|
|
3662
|
+
const failedStages = obs.stages.filter((s) => s.status === "fail");
|
|
3663
|
+
if (failedStages.length === 0 || obs.decision === "DENY") {
|
|
3664
|
+
passedChecks++;
|
|
3665
|
+
} else {
|
|
3666
|
+
for (const stage of failedStages) {
|
|
3667
|
+
anomalies.push({
|
|
3668
|
+
code: "STAGE_FAILED",
|
|
3669
|
+
level: "warning",
|
|
3670
|
+
message: `Stage '${stage.name}' failed: ${stage.reason ?? "unknown"}`,
|
|
3671
|
+
field: `stages.${stage.name}`
|
|
3672
|
+
});
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
totalChecks++;
|
|
3676
|
+
const invalidSensors = obs.sensors.filter((s) => s.durationMs < 0);
|
|
3677
|
+
if (invalidSensors.length === 0) {
|
|
3678
|
+
passedChecks++;
|
|
3679
|
+
} else {
|
|
3680
|
+
anomalies.push({
|
|
3681
|
+
code: "SENSOR_INVALID_TIMING",
|
|
3682
|
+
level: "warning",
|
|
3683
|
+
message: `${invalidSensors.length} sensor(s) have negative duration`
|
|
3684
|
+
});
|
|
3685
|
+
}
|
|
3686
|
+
totalChecks++;
|
|
3687
|
+
if (obs.durationMs !== void 0 && obs.durationMs >= 0 && obs.durationMs < 3e5) {
|
|
3688
|
+
passedChecks++;
|
|
3689
|
+
} else {
|
|
3690
|
+
anomalies.push({
|
|
3691
|
+
code: "OBS_DURATION_ANOMALY",
|
|
3692
|
+
level: "warning",
|
|
3693
|
+
message: `Observation duration ${obs.durationMs}ms is suspicious`,
|
|
3694
|
+
actual: obs.durationMs
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3697
|
+
if (expected) {
|
|
3698
|
+
if (expected.decision !== void 0) {
|
|
3699
|
+
totalChecks++;
|
|
3700
|
+
if (obs.decision === expected.decision) {
|
|
3701
|
+
passedChecks++;
|
|
3702
|
+
} else {
|
|
3703
|
+
anomalies.push({
|
|
3704
|
+
code: "DECISION_MISMATCH",
|
|
3705
|
+
level: "critical",
|
|
3706
|
+
message: `Expected decision '${expected.decision}', got '${obs.decision}'`,
|
|
3707
|
+
field: "decision",
|
|
3708
|
+
expected: expected.decision,
|
|
3709
|
+
actual: obs.decision
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
if (expected.statusCode !== void 0) {
|
|
3714
|
+
totalChecks++;
|
|
3715
|
+
if (obs.statusCode === expected.statusCode) {
|
|
3716
|
+
passedChecks++;
|
|
3717
|
+
} else {
|
|
3718
|
+
anomalies.push({
|
|
3719
|
+
code: "STATUS_MISMATCH",
|
|
3720
|
+
level: "warning",
|
|
3721
|
+
message: `Expected status ${expected.statusCode}, got ${obs.statusCode}`,
|
|
3722
|
+
field: "statusCode",
|
|
3723
|
+
expected: expected.statusCode,
|
|
3724
|
+
actual: obs.statusCode
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
if (expected.effect !== void 0) {
|
|
3729
|
+
totalChecks++;
|
|
3730
|
+
if (obs.resultCode === expected.effect || obs.facts?.effect === expected.effect) {
|
|
3731
|
+
passedChecks++;
|
|
3732
|
+
} else {
|
|
3733
|
+
anomalies.push({
|
|
3734
|
+
code: "EFFECT_MISMATCH",
|
|
3735
|
+
level: "warning",
|
|
3736
|
+
message: `Expected effect '${expected.effect}', got '${obs.resultCode}'`,
|
|
3737
|
+
field: "resultCode",
|
|
3738
|
+
expected: expected.effect,
|
|
3739
|
+
actual: obs.resultCode
|
|
3740
|
+
});
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
if (expected.maxDurationMs !== void 0) {
|
|
3744
|
+
totalChecks++;
|
|
3745
|
+
if (obs.durationMs !== void 0 && obs.durationMs <= expected.maxDurationMs) {
|
|
3746
|
+
passedChecks++;
|
|
3747
|
+
} else {
|
|
3748
|
+
anomalies.push({
|
|
3749
|
+
code: "DURATION_EXCEEDED",
|
|
3750
|
+
level: "warning",
|
|
3751
|
+
message: `Execution took ${obs.durationMs}ms, max allowed ${expected.maxDurationMs}ms`,
|
|
3752
|
+
field: "durationMs",
|
|
3753
|
+
expected: expected.maxDurationMs,
|
|
3754
|
+
actual: obs.durationMs
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
if (expected.minSensorsPassed !== void 0) {
|
|
3759
|
+
totalChecks++;
|
|
3760
|
+
const passed = obs.sensors.filter((s) => s.allowed).length;
|
|
3761
|
+
if (passed >= expected.minSensorsPassed) {
|
|
3762
|
+
passedChecks++;
|
|
3763
|
+
} else {
|
|
3764
|
+
anomalies.push({
|
|
3765
|
+
code: "INSUFFICIENT_SENSORS",
|
|
3766
|
+
level: "warning",
|
|
3767
|
+
message: `Only ${passed} sensors passed, minimum required ${expected.minSensorsPassed}`,
|
|
3768
|
+
field: "sensors",
|
|
3769
|
+
expected: expected.minSensorsPassed,
|
|
3770
|
+
actual: passed
|
|
3771
|
+
});
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
if (expected.assertions) {
|
|
3775
|
+
for (const [key, expectedValue] of Object.entries(expected.assertions)) {
|
|
3776
|
+
totalChecks++;
|
|
3777
|
+
const actualValue = obs.facts[key];
|
|
3778
|
+
if (deepEqual(actualValue, expectedValue)) {
|
|
3779
|
+
passedChecks++;
|
|
3780
|
+
} else {
|
|
3781
|
+
anomalies.push({
|
|
3782
|
+
code: "ASSERTION_FAILED",
|
|
3783
|
+
level: "warning",
|
|
3784
|
+
message: `Assertion failed for facts.${key}`,
|
|
3785
|
+
field: `facts.${key}`,
|
|
3786
|
+
expected: expectedValue,
|
|
3787
|
+
actual: actualValue
|
|
3788
|
+
});
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
const confidence = totalChecks > 0 ? passedChecks / totalChecks : 0;
|
|
3794
|
+
const hasCritical = anomalies.some((a) => a.level === "critical");
|
|
3795
|
+
const status = computeTruthStatus(confidence, hasCritical, anomalies.length);
|
|
3796
|
+
const isDeed = status === "confirmed" || status === "partial" && !hasCritical;
|
|
3797
|
+
return {
|
|
3798
|
+
status,
|
|
3799
|
+
confidence,
|
|
3800
|
+
anomalies,
|
|
3801
|
+
passedChecks,
|
|
3802
|
+
totalChecks,
|
|
3803
|
+
verifiedAt: Date.now(),
|
|
3804
|
+
isDeed
|
|
3805
|
+
};
|
|
3806
|
+
}
|
|
3807
|
+
function computeTruthStatus(confidence, hasCritical, anomalyCount) {
|
|
3808
|
+
if (hasCritical) return "failed";
|
|
3809
|
+
if (confidence === 1) return "confirmed";
|
|
3810
|
+
if (confidence >= 0.8) return "partial";
|
|
3811
|
+
if (confidence >= 0.5) return "uncertain";
|
|
3812
|
+
return "disputed";
|
|
3813
|
+
}
|
|
3814
|
+
function verifyObservation(obs, expected) {
|
|
3815
|
+
const verdict = scoreTruth(obs, expected);
|
|
3816
|
+
return { observation: obs, verdict };
|
|
3817
|
+
}
|
|
3818
|
+
function deepEqual(a, b) {
|
|
3819
|
+
if (a === b) return true;
|
|
3820
|
+
if (a === null || b === null) return false;
|
|
3821
|
+
if (typeof a !== typeof b) return false;
|
|
3822
|
+
if (typeof a !== "object") return String(a) === String(b);
|
|
3823
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
3824
|
+
if (a.length !== b.length) return false;
|
|
3825
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
3826
|
+
}
|
|
3827
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
3828
|
+
const aKeys = Object.keys(a);
|
|
3829
|
+
const bKeys = Object.keys(b);
|
|
3830
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
3831
|
+
return aKeys.every(
|
|
3832
|
+
(key) => deepEqual(
|
|
3833
|
+
a[key],
|
|
3834
|
+
b[key]
|
|
3835
|
+
)
|
|
3836
|
+
);
|
|
3837
|
+
}
|
|
3838
|
+
var init_truth_scoring = __esm({
|
|
3839
|
+
"src/engine/observation/truth-scoring.ts"() {
|
|
3840
|
+
}
|
|
3841
|
+
});
|
|
3842
|
+
|
|
3458
3843
|
// src/engine/observation/response-observer.ts
|
|
3459
3844
|
function verifyResponse(ctx, response) {
|
|
3460
3845
|
if (!response.effect || typeof response.effect !== "string") {
|
|
@@ -3525,97 +3910,15 @@ var init_varint = __esm({
|
|
|
3525
3910
|
var axis_bin_exports = {};
|
|
3526
3911
|
__export(axis_bin_exports, {
|
|
3527
3912
|
AxisFrameZ: () => AxisFrameZ,
|
|
3528
|
-
decodeFrame: () => decodeFrame,
|
|
3529
|
-
encodeFrame: () => encodeFrame,
|
|
3530
|
-
getSignTarget: () => getSignTarget
|
|
3531
|
-
});
|
|
3532
|
-
|
|
3533
|
-
const hdrBytes = (0, import_axis_protocol.encodeTLVs)(
|
|
3534
|
-
Array.from(frame.headers.entries()).map(([t, v]) => ({
|
|
3535
|
-
type: t,
|
|
3536
|
-
value: v
|
|
3537
|
-
}))
|
|
3538
|
-
);
|
|
3539
|
-
if (hdrBytes.length > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header too large");
|
|
3540
|
-
if (frame.body.length > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body too large");
|
|
3541
|
-
if (frame.sig.length > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature too large");
|
|
3542
|
-
const hdrLenBytes = (0, import_axis_protocol3.encodeVarint)(hdrBytes.length);
|
|
3543
|
-
const bodyLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.body.length);
|
|
3544
|
-
const sigLenBytes = (0, import_axis_protocol3.encodeVarint)(frame.sig.length);
|
|
3545
|
-
const totalLen = 5 + // Magic (AXIS1)
|
|
3546
|
-
1 + // Version
|
|
3547
|
-
1 + // Flags
|
|
3548
|
-
hdrLenBytes.length + bodyLenBytes.length + sigLenBytes.length + hdrBytes.length + frame.body.length + frame.sig.length;
|
|
3549
|
-
if (totalLen > import_axis_protocol2.MAX_FRAME_LEN) throw new Error("Total frame too large");
|
|
3550
|
-
const buf = new Uint8Array(totalLen);
|
|
3551
|
-
let offset = 0;
|
|
3552
|
-
buf.set(import_axis_protocol2.AXIS_MAGIC, offset);
|
|
3553
|
-
offset += 5;
|
|
3554
|
-
buf[offset++] = import_axis_protocol2.AXIS_VERSION;
|
|
3555
|
-
buf[offset++] = frame.flags;
|
|
3556
|
-
buf.set(hdrLenBytes, offset);
|
|
3557
|
-
offset += hdrLenBytes.length;
|
|
3558
|
-
buf.set(bodyLenBytes, offset);
|
|
3559
|
-
offset += bodyLenBytes.length;
|
|
3560
|
-
buf.set(sigLenBytes, offset);
|
|
3561
|
-
offset += sigLenBytes.length;
|
|
3562
|
-
buf.set(hdrBytes, offset);
|
|
3563
|
-
offset += hdrBytes.length;
|
|
3564
|
-
buf.set(frame.body, offset);
|
|
3565
|
-
offset += frame.body.length;
|
|
3566
|
-
buf.set(frame.sig, offset);
|
|
3567
|
-
offset += frame.sig.length;
|
|
3568
|
-
return buf;
|
|
3569
|
-
}
|
|
3570
|
-
function decodeFrame(buf) {
|
|
3571
|
-
let offset = 0;
|
|
3572
|
-
if (offset + 5 > buf.length) throw new Error("Packet too short");
|
|
3573
|
-
for (let i = 0; i < 5; i++) {
|
|
3574
|
-
if (buf[offset + i] !== import_axis_protocol2.AXIS_MAGIC[i]) throw new Error("Invalid Magic");
|
|
3575
|
-
}
|
|
3576
|
-
offset += 5;
|
|
3577
|
-
const ver = buf[offset++];
|
|
3578
|
-
if (ver !== import_axis_protocol2.AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);
|
|
3579
|
-
const flags = buf[offset++];
|
|
3580
|
-
const { value: hdrLen, length: hlLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3581
|
-
offset += hlLen;
|
|
3582
|
-
if (hdrLen > import_axis_protocol2.MAX_HDR_LEN) throw new Error("Header limit exceeded");
|
|
3583
|
-
const { value: bodyLen, length: blLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3584
|
-
offset += blLen;
|
|
3585
|
-
if (bodyLen > import_axis_protocol2.MAX_BODY_LEN) throw new Error("Body limit exceeded");
|
|
3586
|
-
const { value: sigLen, length: slLen } = (0, import_axis_protocol3.decodeVarint)(buf, offset);
|
|
3587
|
-
offset += slLen;
|
|
3588
|
-
if (sigLen > import_axis_protocol2.MAX_SIG_LEN) throw new Error("Signature limit exceeded");
|
|
3589
|
-
if (offset + hdrLen + bodyLen + sigLen > buf.length) {
|
|
3590
|
-
throw new Error("Frame truncated");
|
|
3591
|
-
}
|
|
3592
|
-
const hdrBytes = buf.slice(offset, offset + hdrLen);
|
|
3593
|
-
offset += hdrLen;
|
|
3594
|
-
const bodyBytes = buf.slice(offset, offset + bodyLen);
|
|
3595
|
-
offset += bodyLen;
|
|
3596
|
-
const sigBytes = buf.slice(offset, offset + sigLen);
|
|
3597
|
-
offset += sigLen;
|
|
3598
|
-
const headers = (0, import_axis_protocol.decodeTLVs)(hdrBytes);
|
|
3599
|
-
return {
|
|
3600
|
-
flags,
|
|
3601
|
-
headers,
|
|
3602
|
-
body: bodyBytes,
|
|
3603
|
-
sig: sigBytes
|
|
3604
|
-
};
|
|
3605
|
-
}
|
|
3606
|
-
function getSignTarget(frame) {
|
|
3607
|
-
return encodeFrame({
|
|
3608
|
-
...frame,
|
|
3609
|
-
sig: new Uint8Array(0)
|
|
3610
|
-
});
|
|
3611
|
-
}
|
|
3612
|
-
var z, AxisFrameZ;
|
|
3913
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
3914
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
3915
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget
|
|
3916
|
+
});
|
|
3917
|
+
var z, import_axis_protocol4, AxisFrameZ;
|
|
3613
3918
|
var init_axis_bin = __esm({
|
|
3614
3919
|
"src/core/axis-bin.ts"() {
|
|
3615
3920
|
z = __toESM(require("zod"));
|
|
3616
|
-
|
|
3617
|
-
init_tlv();
|
|
3618
|
-
init_varint();
|
|
3921
|
+
import_axis_protocol4 = require("@nextera.one/axis-protocol");
|
|
3619
3922
|
AxisFrameZ = z.object({
|
|
3620
3923
|
/** Flag bits for protocol control (e.g., encryption, compression) */
|
|
3621
3924
|
flags: z.number().int().nonnegative(),
|
|
@@ -3634,12 +3937,7 @@ var init_axis_bin = __esm({
|
|
|
3634
3937
|
|
|
3635
3938
|
// src/core/signature.ts
|
|
3636
3939
|
function computeSignaturePayload(frame) {
|
|
3637
|
-
|
|
3638
|
-
...frame,
|
|
3639
|
-
sig: new Uint8Array(0)
|
|
3640
|
-
};
|
|
3641
|
-
const encoded = encodeFrame(frameWithoutSig);
|
|
3642
|
-
return Buffer.from(encoded);
|
|
3940
|
+
return Buffer.from((0, import_axis_protocol4.getSignTarget)(frame));
|
|
3643
3941
|
}
|
|
3644
3942
|
function signFrame(frame, privateKey) {
|
|
3645
3943
|
const payload = computeSignaturePayload(frame);
|
|
@@ -4527,7 +4825,7 @@ function encodeAxis1Frame(f) {
|
|
|
4527
4825
|
if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
|
|
4528
4826
|
throw new Error("AXIS1_BAD_BUFFERS");
|
|
4529
4827
|
}
|
|
4530
|
-
if (f.ver !==
|
|
4828
|
+
if (f.ver !== import_axis_protocol5.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
4531
4829
|
const hdrLen = encVarint(BigInt(f.hdr.length));
|
|
4532
4830
|
const bodyLen = encVarint(BigInt(f.body.length));
|
|
4533
4831
|
const sigLen = encVarint(BigInt(f.sig.length));
|
|
@@ -4543,17 +4841,18 @@ function encodeAxis1Frame(f) {
|
|
|
4543
4841
|
f.sig
|
|
4544
4842
|
]);
|
|
4545
4843
|
}
|
|
4546
|
-
var MAGIC;
|
|
4844
|
+
var import_axis_protocol5, MAGIC;
|
|
4547
4845
|
var init_axis1_encode = __esm({
|
|
4548
4846
|
"src/codec/axis1.encode.ts"() {
|
|
4847
|
+
import_axis_protocol5 = require("@nextera.one/axis-protocol");
|
|
4549
4848
|
init_tlv_encode();
|
|
4550
|
-
MAGIC = Buffer.from(
|
|
4849
|
+
MAGIC = Buffer.from(import_axis_protocol5.AXIS_MAGIC);
|
|
4551
4850
|
}
|
|
4552
4851
|
});
|
|
4553
4852
|
|
|
4554
4853
|
// src/codec/axis1.signing.ts
|
|
4555
4854
|
function axis1SigningBytes(params) {
|
|
4556
|
-
if (params.ver !==
|
|
4855
|
+
if (params.ver !== import_axis_protocol6.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
|
|
4557
4856
|
const hdrLen = encVarint(BigInt(params.hdr.length));
|
|
4558
4857
|
const bodyLen = encVarint(BigInt(params.body.length));
|
|
4559
4858
|
const sigLenZero = encVarint(0n);
|
|
@@ -4568,11 +4867,12 @@ function axis1SigningBytes(params) {
|
|
|
4568
4867
|
params.body
|
|
4569
4868
|
]);
|
|
4570
4869
|
}
|
|
4571
|
-
var MAGIC2;
|
|
4870
|
+
var import_axis_protocol6, MAGIC2;
|
|
4572
4871
|
var init_axis1_signing = __esm({
|
|
4573
4872
|
"src/codec/axis1.signing.ts"() {
|
|
4873
|
+
import_axis_protocol6 = require("@nextera.one/axis-protocol");
|
|
4574
4874
|
init_tlv_encode();
|
|
4575
|
-
MAGIC2 = Buffer.from(
|
|
4875
|
+
MAGIC2 = Buffer.from(import_axis_protocol6.AXIS_MAGIC);
|
|
4576
4876
|
}
|
|
4577
4877
|
});
|
|
4578
4878
|
|
|
@@ -4902,11 +5202,12 @@ function decodeAxis1Frame(buf) {
|
|
|
4902
5202
|
if (off !== buf.length) throw new Error("AXIS1_TRAILING_BYTES");
|
|
4903
5203
|
return { ver, flags, hdr, body, sig, frameSize: buf.length };
|
|
4904
5204
|
}
|
|
4905
|
-
var MAGIC3;
|
|
5205
|
+
var import_axis_protocol7, MAGIC3;
|
|
4906
5206
|
var init_frame = __esm({
|
|
4907
5207
|
"src/types/frame.ts"() {
|
|
5208
|
+
import_axis_protocol7 = require("@nextera.one/axis-protocol");
|
|
4908
5209
|
init_tlv2();
|
|
4909
|
-
MAGIC3 = Buffer.from(
|
|
5210
|
+
MAGIC3 = Buffer.from(import_axis_protocol7.AXIS_MAGIC);
|
|
4910
5211
|
}
|
|
4911
5212
|
});
|
|
4912
5213
|
|
|
@@ -5029,7 +5330,52 @@ var init_capabilities = __esm({
|
|
|
5029
5330
|
}
|
|
5030
5331
|
});
|
|
5031
5332
|
|
|
5333
|
+
// src/law/law.types.ts
|
|
5334
|
+
function buildAxisLawEvaluationContext(input) {
|
|
5335
|
+
const metadata = input.metadata ?? {};
|
|
5336
|
+
const packet = input.packet;
|
|
5337
|
+
const packetBody = input.frameBody ?? packet?.body ?? packet?.args ?? void 0;
|
|
5338
|
+
const capsuleId = metadata.capsule_id ?? metadata.capsuleId ?? packet?.capsuleId ?? input.clientId;
|
|
5339
|
+
const audience = input.aud ?? metadata.audience ?? packet?.aud;
|
|
5340
|
+
const tps = metadata.tps ?? packet?.tps ?? packet?.tickTps;
|
|
5341
|
+
return {
|
|
5342
|
+
actorId: input.actorId,
|
|
5343
|
+
intent: input.intent,
|
|
5344
|
+
audience,
|
|
5345
|
+
tps,
|
|
5346
|
+
country: input.country,
|
|
5347
|
+
ip: input.ip,
|
|
5348
|
+
path: input.path,
|
|
5349
|
+
clientId: input.clientId,
|
|
5350
|
+
deviceId: input.deviceId,
|
|
5351
|
+
sessionId: input.sessionId,
|
|
5352
|
+
capsuleId,
|
|
5353
|
+
metadata,
|
|
5354
|
+
packet,
|
|
5355
|
+
frameBody: packetBody
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5358
|
+
var init_law_types = __esm({
|
|
5359
|
+
"src/law/law.types.ts"() {
|
|
5360
|
+
}
|
|
5361
|
+
});
|
|
5362
|
+
|
|
5363
|
+
// src/law/index.ts
|
|
5364
|
+
var law_exports = {};
|
|
5365
|
+
__export(law_exports, {
|
|
5366
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext
|
|
5367
|
+
});
|
|
5368
|
+
var init_law = __esm({
|
|
5369
|
+
"src/law/index.ts"() {
|
|
5370
|
+
init_law_types();
|
|
5371
|
+
}
|
|
5372
|
+
});
|
|
5373
|
+
|
|
5032
5374
|
// src/risk/index.ts
|
|
5375
|
+
var risk_exports = {};
|
|
5376
|
+
__export(risk_exports, {
|
|
5377
|
+
RiskDecision: () => RiskDecision
|
|
5378
|
+
});
|
|
5033
5379
|
var RiskDecision;
|
|
5034
5380
|
var init_risk = __esm({
|
|
5035
5381
|
"src/risk/index.ts"() {
|
|
@@ -5773,9 +6119,9 @@ var require_handler_discovery_service = __commonJS({
|
|
|
5773
6119
|
}
|
|
5774
6120
|
});
|
|
5775
6121
|
|
|
5776
|
-
// src/engine/
|
|
5777
|
-
var
|
|
5778
|
-
"src/engine/
|
|
6122
|
+
// src/engine/sensor-discovery.service.ts
|
|
6123
|
+
var require_sensor_discovery_service = __commonJS({
|
|
6124
|
+
"src/engine/sensor-discovery.service.ts"(exports2) {
|
|
5779
6125
|
"use strict";
|
|
5780
6126
|
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
5781
6127
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5786,103 +6132,12 @@ var require_sensor_registry = __commonJS({
|
|
|
5786
6132
|
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
5787
6133
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5788
6134
|
};
|
|
5789
|
-
var
|
|
6135
|
+
var SensorDiscoveryService_1;
|
|
5790
6136
|
var _a;
|
|
6137
|
+
var _b;
|
|
6138
|
+
var _c;
|
|
5791
6139
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5792
|
-
exports2.
|
|
5793
|
-
var common_1 = require("@nestjs/common");
|
|
5794
|
-
var config_1 = require("@nestjs/config");
|
|
5795
|
-
var SensorRegistry2 = SensorRegistry_1 = class SensorRegistry {
|
|
5796
|
-
constructor(configService) {
|
|
5797
|
-
this.configService = configService;
|
|
5798
|
-
this.sensors = [];
|
|
5799
|
-
this.logger = new common_1.Logger(SensorRegistry_1.name);
|
|
5800
|
-
}
|
|
5801
|
-
register(sensor) {
|
|
5802
|
-
if (!sensor.name) {
|
|
5803
|
-
throw new Error("AxisSensor must have a name");
|
|
5804
|
-
}
|
|
5805
|
-
const enabledSensorsStr = this.configService.get("ENABLED_SENSORS");
|
|
5806
|
-
const disabledSensorsStr = this.configService.get("DISABLED_SENSORS");
|
|
5807
|
-
const enabledSensors = enabledSensorsStr ? enabledSensorsStr.split(",").map((s) => s.trim()) : null;
|
|
5808
|
-
const disabledSensors = disabledSensorsStr ? disabledSensorsStr.split(",").map((s) => s.trim()) : [];
|
|
5809
|
-
if (enabledSensors && !enabledSensors.includes(sensor.name)) {
|
|
5810
|
-
this.logger.log(`Skipping disabled sensor (not in ENABLED_SENSORS): ${sensor.name}`);
|
|
5811
|
-
return;
|
|
5812
|
-
}
|
|
5813
|
-
if (disabledSensors.includes(sensor.name)) {
|
|
5814
|
-
this.logger.log(`Skipping disabled sensor (in DISABLED_SENSORS): ${sensor.name}`);
|
|
5815
|
-
return;
|
|
5816
|
-
}
|
|
5817
|
-
if (sensor.order === void 0) {
|
|
5818
|
-
throw new Error(`AxisSensor "${sensor.name}" must have an order field`);
|
|
5819
|
-
}
|
|
5820
|
-
const isPreDecodeSensor = this.isPreDecodeSensor(sensor);
|
|
5821
|
-
const isPostDecodeSensor = this.isPostDecodeSensor(sensor);
|
|
5822
|
-
if (isPreDecodeSensor && sensor.order >= 40) {
|
|
5823
|
-
this.logger.warn(`AxisSensor "${sensor.name}" is marked as PRE_DECODE but has order ${sensor.order} (should be < 40)`);
|
|
5824
|
-
}
|
|
5825
|
-
if (isPostDecodeSensor && sensor.order < 40) {
|
|
5826
|
-
this.logger.warn(`AxisSensor "${sensor.name}" is marked as POST_DECODE but has order ${sensor.order} (should be >= 40)`);
|
|
5827
|
-
}
|
|
5828
|
-
this.sensors.push(sensor);
|
|
5829
|
-
const phaseLabel = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase || "UNKNOWN";
|
|
5830
|
-
this.logger.debug(`Registered sensor: ${sensor.name} (order: ${sensor.order}, phase: ${phaseLabel})`);
|
|
5831
|
-
}
|
|
5832
|
-
list() {
|
|
5833
|
-
return [...this.sensors].sort((a, b) => (a.order ?? 999) - (b.order ?? 999));
|
|
5834
|
-
}
|
|
5835
|
-
getPreDecodeSensors() {
|
|
5836
|
-
return this.list().filter((s) => (s.order ?? 999) < 40);
|
|
5837
|
-
}
|
|
5838
|
-
getPostDecodeSensors() {
|
|
5839
|
-
return this.list().filter((s) => (s.order ?? 999) >= 40);
|
|
5840
|
-
}
|
|
5841
|
-
isPreDecodeSensor(sensor) {
|
|
5842
|
-
const phase = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase;
|
|
5843
|
-
return phase === "PRE_DECODE" || (sensor.order ?? 999) < 40;
|
|
5844
|
-
}
|
|
5845
|
-
isPostDecodeSensor(sensor) {
|
|
5846
|
-
const phase = typeof sensor.phase === "string" ? sensor.phase : sensor.phase?.phase;
|
|
5847
|
-
return phase === "POST_DECODE" || (sensor.order ?? 999) >= 40;
|
|
5848
|
-
}
|
|
5849
|
-
getSensorCountByPhase() {
|
|
5850
|
-
return {
|
|
5851
|
-
preDecodeCount: this.getPreDecodeSensors().length,
|
|
5852
|
-
postDecodeCount: this.getPostDecodeSensors().length
|
|
5853
|
-
};
|
|
5854
|
-
}
|
|
5855
|
-
clear() {
|
|
5856
|
-
this.sensors = [];
|
|
5857
|
-
}
|
|
5858
|
-
};
|
|
5859
|
-
exports2.SensorRegistry = SensorRegistry2;
|
|
5860
|
-
exports2.SensorRegistry = SensorRegistry2 = SensorRegistry_1 = __decorate([
|
|
5861
|
-
(0, common_1.Injectable)(),
|
|
5862
|
-
__metadata("design:paramtypes", [typeof (_a = typeof config_1.ConfigService !== "undefined" && config_1.ConfigService) === "function" ? _a : Object])
|
|
5863
|
-
], SensorRegistry2);
|
|
5864
|
-
}
|
|
5865
|
-
});
|
|
5866
|
-
|
|
5867
|
-
// src/engine/sensor-discovery.service.ts
|
|
5868
|
-
var require_sensor_discovery_service = __commonJS({
|
|
5869
|
-
"src/engine/sensor-discovery.service.ts"(exports2) {
|
|
5870
|
-
"use strict";
|
|
5871
|
-
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
5872
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5873
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5874
|
-
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;
|
|
5875
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5876
|
-
};
|
|
5877
|
-
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
5878
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5879
|
-
};
|
|
5880
|
-
var SensorDiscoveryService_1;
|
|
5881
|
-
var _a;
|
|
5882
|
-
var _b;
|
|
5883
|
-
var _c;
|
|
5884
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5885
|
-
exports2.SensorDiscoveryService = void 0;
|
|
6140
|
+
exports2.SensorDiscoveryService = void 0;
|
|
5886
6141
|
var common_1 = require("@nestjs/common");
|
|
5887
6142
|
var core_1 = require("@nestjs/core");
|
|
5888
6143
|
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
@@ -6102,6 +6357,374 @@ var require_axis_sensor_chain_service = __commonJS({
|
|
|
6102
6357
|
}
|
|
6103
6358
|
});
|
|
6104
6359
|
|
|
6360
|
+
// src/timeline/timeline.engine.ts
|
|
6361
|
+
function generateId(prefix) {
|
|
6362
|
+
return `${prefix}_${(0, import_crypto8.randomBytes)(16).toString("hex")}`;
|
|
6363
|
+
}
|
|
6364
|
+
function sha2566(data) {
|
|
6365
|
+
return (0, import_crypto8.createHash)("sha256").update(data).digest("hex");
|
|
6366
|
+
}
|
|
6367
|
+
function hashPayload2(payload) {
|
|
6368
|
+
return sha2566(JSON.stringify(payload));
|
|
6369
|
+
}
|
|
6370
|
+
function diffObjects(a, b) {
|
|
6371
|
+
const diffs = [];
|
|
6372
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
6373
|
+
for (const key of allKeys) {
|
|
6374
|
+
const va = a[key];
|
|
6375
|
+
const vb = b[key];
|
|
6376
|
+
if (JSON.stringify(va) !== JSON.stringify(vb)) {
|
|
6377
|
+
diffs.push({ field: key, original: va, replayed: vb });
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
return diffs;
|
|
6381
|
+
}
|
|
6382
|
+
var import_crypto8, TimelineEngine;
|
|
6383
|
+
var init_timeline_engine = __esm({
|
|
6384
|
+
"src/timeline/timeline.engine.ts"() {
|
|
6385
|
+
import_crypto8 = require("crypto");
|
|
6386
|
+
TimelineEngine = class {
|
|
6387
|
+
constructor(store) {
|
|
6388
|
+
this.store = store;
|
|
6389
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
6390
|
+
}
|
|
6391
|
+
/** Register an intent handler for timeline execution */
|
|
6392
|
+
registerHandler(handler) {
|
|
6393
|
+
this.handlers.set(handler.intent, handler);
|
|
6394
|
+
}
|
|
6395
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6396
|
+
// Record (store a real execution as a timeline event)
|
|
6397
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6398
|
+
async recordEvent(intent, actorId, payload, result, options = {}) {
|
|
6399
|
+
const event = {
|
|
6400
|
+
event_id: generateId("evt"),
|
|
6401
|
+
timeline_id: options.timelineId ?? "prime",
|
|
6402
|
+
branch_id: options.branchId ?? "main",
|
|
6403
|
+
parent_event_id: options.parentEventId ?? null,
|
|
6404
|
+
intent,
|
|
6405
|
+
actor_id: actorId,
|
|
6406
|
+
capsule_id: options.capsuleId,
|
|
6407
|
+
tps_coordinate: options.tpsCoordinate,
|
|
6408
|
+
payload_hash: hashPayload2(payload),
|
|
6409
|
+
result_hash: hashPayload2(result),
|
|
6410
|
+
status: "executed",
|
|
6411
|
+
domain: "prime",
|
|
6412
|
+
determinism: options.determinism ?? "deterministic",
|
|
6413
|
+
witness_id: options.witnessId,
|
|
6414
|
+
created_at: Date.now(),
|
|
6415
|
+
metadata: { payload, result }
|
|
6416
|
+
};
|
|
6417
|
+
await this.store.saveEvent(event);
|
|
6418
|
+
return event;
|
|
6419
|
+
}
|
|
6420
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6421
|
+
// Replay
|
|
6422
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6423
|
+
async replay(request) {
|
|
6424
|
+
const originalEvent = await this.store.getEvent(request.source_event_id);
|
|
6425
|
+
if (!originalEvent) {
|
|
6426
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
6427
|
+
}
|
|
6428
|
+
const handler = this.handlers.get(originalEvent.intent);
|
|
6429
|
+
if (!handler) {
|
|
6430
|
+
throw new Error(`No handler registered for intent '${originalEvent.intent}'`);
|
|
6431
|
+
}
|
|
6432
|
+
const originalPayload = originalEvent.metadata?.payload ?? {};
|
|
6433
|
+
const replayPayload = request.mode === "analytical" && request.override_payload ? request.override_payload : originalPayload;
|
|
6434
|
+
const snapshot = await this.store.getSnapshotByEvent(originalEvent.event_id);
|
|
6435
|
+
const context = {
|
|
6436
|
+
event_id: generateId("evt"),
|
|
6437
|
+
timeline_id: originalEvent.timeline_id,
|
|
6438
|
+
branch_id: `replay_${originalEvent.branch_id}`,
|
|
6439
|
+
domain: "audit",
|
|
6440
|
+
actor_id: originalEvent.actor_id,
|
|
6441
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
6442
|
+
snapshot: snapshot ?? void 0,
|
|
6443
|
+
is_replay: true,
|
|
6444
|
+
is_simulation: false
|
|
6445
|
+
};
|
|
6446
|
+
const startMs = Date.now();
|
|
6447
|
+
const handlerResult = await handler.execute(replayPayload, context);
|
|
6448
|
+
const durationMs = Date.now() - startMs;
|
|
6449
|
+
const replayedEvent = {
|
|
6450
|
+
event_id: context.event_id,
|
|
6451
|
+
timeline_id: originalEvent.timeline_id,
|
|
6452
|
+
branch_id: context.branch_id,
|
|
6453
|
+
parent_event_id: originalEvent.event_id,
|
|
6454
|
+
intent: originalEvent.intent,
|
|
6455
|
+
actor_id: originalEvent.actor_id,
|
|
6456
|
+
capsule_id: originalEvent.capsule_id,
|
|
6457
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
6458
|
+
payload_hash: hashPayload2(replayPayload),
|
|
6459
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6460
|
+
status: "replayed",
|
|
6461
|
+
domain: "audit",
|
|
6462
|
+
determinism: originalEvent.determinism,
|
|
6463
|
+
created_at: Date.now(),
|
|
6464
|
+
metadata: { payload: replayPayload, result: handlerResult.result_data }
|
|
6465
|
+
};
|
|
6466
|
+
await this.store.saveEvent(replayedEvent);
|
|
6467
|
+
const originalResult = originalEvent.metadata?.result ?? {};
|
|
6468
|
+
const differences = diffObjects(originalResult, handlerResult.result_data);
|
|
6469
|
+
const deterministicMatch = originalEvent.result_hash === replayedEvent.result_hash;
|
|
6470
|
+
return {
|
|
6471
|
+
original_event: originalEvent,
|
|
6472
|
+
replayed_event: replayedEvent,
|
|
6473
|
+
mode: request.mode,
|
|
6474
|
+
deterministic_match: deterministicMatch,
|
|
6475
|
+
differences,
|
|
6476
|
+
duration_ms: durationMs
|
|
6477
|
+
};
|
|
6478
|
+
}
|
|
6479
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6480
|
+
// Fork
|
|
6481
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6482
|
+
async fork(request) {
|
|
6483
|
+
const sourceEvent = await this.store.getEvent(request.source_event_id);
|
|
6484
|
+
if (!sourceEvent) {
|
|
6485
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
6486
|
+
}
|
|
6487
|
+
const handler = this.handlers.get(sourceEvent.intent);
|
|
6488
|
+
if (!handler) {
|
|
6489
|
+
throw new Error(`No handler registered for intent '${sourceEvent.intent}'`);
|
|
6490
|
+
}
|
|
6491
|
+
const branch = {
|
|
6492
|
+
branch_id: generateId("branch"),
|
|
6493
|
+
timeline_id: generateId("timeline"),
|
|
6494
|
+
origin_timeline_id: sourceEvent.timeline_id,
|
|
6495
|
+
origin_event_id: sourceEvent.event_id,
|
|
6496
|
+
branch_type: "fork",
|
|
6497
|
+
creator_subject_id: request.actor_id,
|
|
6498
|
+
purpose: request.purpose,
|
|
6499
|
+
status: "active"
|
|
6500
|
+
};
|
|
6501
|
+
await this.store.saveBranch(branch);
|
|
6502
|
+
const snapshot = {
|
|
6503
|
+
snapshot_id: generateId("snap"),
|
|
6504
|
+
timeline_id: sourceEvent.timeline_id,
|
|
6505
|
+
event_id: sourceEvent.event_id,
|
|
6506
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6507
|
+
state_hash: hashPayload2(
|
|
6508
|
+
sourceEvent.metadata?.result ?? {}
|
|
6509
|
+
),
|
|
6510
|
+
state_data: sourceEvent.metadata?.result ?? {},
|
|
6511
|
+
created_at: Date.now()
|
|
6512
|
+
};
|
|
6513
|
+
await this.store.saveSnapshot(snapshot);
|
|
6514
|
+
const context = {
|
|
6515
|
+
event_id: generateId("evt"),
|
|
6516
|
+
timeline_id: branch.timeline_id,
|
|
6517
|
+
branch_id: branch.branch_id,
|
|
6518
|
+
domain: "fork",
|
|
6519
|
+
actor_id: request.actor_id,
|
|
6520
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6521
|
+
snapshot,
|
|
6522
|
+
is_replay: false,
|
|
6523
|
+
is_simulation: false
|
|
6524
|
+
};
|
|
6525
|
+
const handlerResult = await handler.execute(request.new_payload, context);
|
|
6526
|
+
const forkedEvent = {
|
|
6527
|
+
event_id: context.event_id,
|
|
6528
|
+
timeline_id: branch.timeline_id,
|
|
6529
|
+
branch_id: branch.branch_id,
|
|
6530
|
+
parent_event_id: sourceEvent.event_id,
|
|
6531
|
+
intent: sourceEvent.intent,
|
|
6532
|
+
actor_id: request.actor_id,
|
|
6533
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
6534
|
+
payload_hash: hashPayload2(request.new_payload),
|
|
6535
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6536
|
+
status: "forked",
|
|
6537
|
+
domain: "fork",
|
|
6538
|
+
determinism: sourceEvent.determinism,
|
|
6539
|
+
created_at: Date.now(),
|
|
6540
|
+
metadata: {
|
|
6541
|
+
payload: request.new_payload,
|
|
6542
|
+
result: handlerResult.result_data
|
|
6543
|
+
}
|
|
6544
|
+
};
|
|
6545
|
+
await this.store.saveEvent(forkedEvent);
|
|
6546
|
+
return { branch, forked_event: forkedEvent, snapshot };
|
|
6547
|
+
}
|
|
6548
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6549
|
+
// Simulate
|
|
6550
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6551
|
+
async simulate(request) {
|
|
6552
|
+
const handler = this.handlers.get(request.intent);
|
|
6553
|
+
if (!handler) {
|
|
6554
|
+
throw new Error(`No handler registered for intent '${request.intent}'`);
|
|
6555
|
+
}
|
|
6556
|
+
let snapshot;
|
|
6557
|
+
if (request.from_snapshot_id) {
|
|
6558
|
+
const loaded = await this.store.getSnapshot(request.from_snapshot_id);
|
|
6559
|
+
if (!loaded) {
|
|
6560
|
+
throw new Error(`Snapshot ${request.from_snapshot_id} not found`);
|
|
6561
|
+
}
|
|
6562
|
+
snapshot = loaded;
|
|
6563
|
+
}
|
|
6564
|
+
const branch = {
|
|
6565
|
+
branch_id: generateId("branch"),
|
|
6566
|
+
timeline_id: generateId("timeline"),
|
|
6567
|
+
origin_timeline_id: "prime",
|
|
6568
|
+
origin_event_id: "simulation_origin",
|
|
6569
|
+
branch_type: "simulation",
|
|
6570
|
+
created_at_tps: request.at_tps,
|
|
6571
|
+
creator_subject_id: request.actor_id,
|
|
6572
|
+
purpose: request.purpose,
|
|
6573
|
+
status: "active"
|
|
6574
|
+
};
|
|
6575
|
+
await this.store.saveBranch(branch);
|
|
6576
|
+
const context = {
|
|
6577
|
+
event_id: generateId("evt"),
|
|
6578
|
+
timeline_id: branch.timeline_id,
|
|
6579
|
+
branch_id: branch.branch_id,
|
|
6580
|
+
domain: "shadow",
|
|
6581
|
+
actor_id: request.actor_id,
|
|
6582
|
+
tps_coordinate: request.at_tps,
|
|
6583
|
+
snapshot,
|
|
6584
|
+
is_replay: false,
|
|
6585
|
+
is_simulation: true
|
|
6586
|
+
};
|
|
6587
|
+
const startMs = Date.now();
|
|
6588
|
+
const handlerResult = await handler.execute(request.payload, context);
|
|
6589
|
+
const durationMs = Date.now() - startMs;
|
|
6590
|
+
const simulatedEvent = {
|
|
6591
|
+
event_id: context.event_id,
|
|
6592
|
+
timeline_id: branch.timeline_id,
|
|
6593
|
+
branch_id: branch.branch_id,
|
|
6594
|
+
parent_event_id: null,
|
|
6595
|
+
intent: request.intent,
|
|
6596
|
+
actor_id: request.actor_id,
|
|
6597
|
+
tps_coordinate: request.at_tps,
|
|
6598
|
+
payload_hash: hashPayload2(request.payload),
|
|
6599
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
6600
|
+
status: "simulated",
|
|
6601
|
+
domain: "shadow",
|
|
6602
|
+
determinism: "bounded_nondeterministic",
|
|
6603
|
+
created_at: Date.now(),
|
|
6604
|
+
metadata: { payload: request.payload, result: handlerResult.result_data }
|
|
6605
|
+
};
|
|
6606
|
+
await this.store.saveEvent(simulatedEvent);
|
|
6607
|
+
branch.status = "completed";
|
|
6608
|
+
await this.store.saveBranch(branch);
|
|
6609
|
+
return {
|
|
6610
|
+
branch,
|
|
6611
|
+
simulated_event: simulatedEvent,
|
|
6612
|
+
predicted_outcome: handlerResult.result_data,
|
|
6613
|
+
side_effects: handlerResult.side_effects ?? [],
|
|
6614
|
+
duration_ms: durationMs
|
|
6615
|
+
};
|
|
6616
|
+
}
|
|
6617
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6618
|
+
// Compare timelines
|
|
6619
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6620
|
+
async compare(timelineIdA, timelineIdB) {
|
|
6621
|
+
const eventsA = await this.store.getEventsByTimeline(timelineIdA);
|
|
6622
|
+
const eventsB = await this.store.getEventsByTimeline(timelineIdB);
|
|
6623
|
+
eventsA.sort((a, b) => a.created_at - b.created_at);
|
|
6624
|
+
eventsB.sort((a, b) => a.created_at - b.created_at);
|
|
6625
|
+
const maxLen = Math.max(eventsA.length, eventsB.length);
|
|
6626
|
+
const eventPairs = [];
|
|
6627
|
+
let divergencePoint;
|
|
6628
|
+
for (let i = 0; i < maxLen; i++) {
|
|
6629
|
+
const a = eventsA[i];
|
|
6630
|
+
const b = eventsB[i];
|
|
6631
|
+
if (!a || !b) {
|
|
6632
|
+
if (!divergencePoint) {
|
|
6633
|
+
divergencePoint = a?.event_id ?? b?.event_id;
|
|
6634
|
+
}
|
|
6635
|
+
continue;
|
|
6636
|
+
}
|
|
6637
|
+
const match = a.result_hash === b.result_hash;
|
|
6638
|
+
const resultA = a.metadata?.result ?? {};
|
|
6639
|
+
const resultB = b.metadata?.result ?? {};
|
|
6640
|
+
const differences = match ? [] : diffObjects(resultA, resultB);
|
|
6641
|
+
if (!match && !divergencePoint) {
|
|
6642
|
+
divergencePoint = a.event_id;
|
|
6643
|
+
}
|
|
6644
|
+
eventPairs.push({ event_a: a, event_b: b, match, differences });
|
|
6645
|
+
}
|
|
6646
|
+
return {
|
|
6647
|
+
timeline_a: timelineIdA,
|
|
6648
|
+
timeline_b: timelineIdB,
|
|
6649
|
+
event_pairs: eventPairs,
|
|
6650
|
+
divergence_point: divergencePoint
|
|
6651
|
+
};
|
|
6652
|
+
}
|
|
6653
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6654
|
+
// State snapshot management
|
|
6655
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
6656
|
+
async createSnapshot(eventId, stateData) {
|
|
6657
|
+
const event = await this.store.getEvent(eventId);
|
|
6658
|
+
if (!event) {
|
|
6659
|
+
throw new Error(`Event ${eventId} not found`);
|
|
6660
|
+
}
|
|
6661
|
+
const snapshot = {
|
|
6662
|
+
snapshot_id: generateId("snap"),
|
|
6663
|
+
timeline_id: event.timeline_id,
|
|
6664
|
+
event_id: eventId,
|
|
6665
|
+
tps_coordinate: event.tps_coordinate,
|
|
6666
|
+
state_hash: hashPayload2(stateData),
|
|
6667
|
+
state_data: stateData,
|
|
6668
|
+
created_at: Date.now()
|
|
6669
|
+
};
|
|
6670
|
+
await this.store.saveSnapshot(snapshot);
|
|
6671
|
+
return snapshot;
|
|
6672
|
+
}
|
|
6673
|
+
async restoreSnapshot(snapshotId) {
|
|
6674
|
+
const snapshot = await this.store.getSnapshot(snapshotId);
|
|
6675
|
+
if (!snapshot) {
|
|
6676
|
+
throw new Error(`Snapshot ${snapshotId} not found`);
|
|
6677
|
+
}
|
|
6678
|
+
return snapshot;
|
|
6679
|
+
}
|
|
6680
|
+
};
|
|
6681
|
+
}
|
|
6682
|
+
});
|
|
6683
|
+
|
|
6684
|
+
// src/timeline/timeline.store.ts
|
|
6685
|
+
var InMemoryTimelineStore;
|
|
6686
|
+
var init_timeline_store = __esm({
|
|
6687
|
+
"src/timeline/timeline.store.ts"() {
|
|
6688
|
+
InMemoryTimelineStore = class {
|
|
6689
|
+
constructor() {
|
|
6690
|
+
this.events = /* @__PURE__ */ new Map();
|
|
6691
|
+
this.branches = /* @__PURE__ */ new Map();
|
|
6692
|
+
this.snapshots = /* @__PURE__ */ new Map();
|
|
6693
|
+
}
|
|
6694
|
+
async saveEvent(event) {
|
|
6695
|
+
this.events.set(event.event_id, event);
|
|
6696
|
+
}
|
|
6697
|
+
async getEvent(eventId) {
|
|
6698
|
+
return this.events.get(eventId) ?? null;
|
|
6699
|
+
}
|
|
6700
|
+
async getEventsByTimeline(timelineId) {
|
|
6701
|
+
return [...this.events.values()].filter((e) => e.timeline_id === timelineId);
|
|
6702
|
+
}
|
|
6703
|
+
async getEventsByBranch(branchId) {
|
|
6704
|
+
return [...this.events.values()].filter((e) => e.branch_id === branchId);
|
|
6705
|
+
}
|
|
6706
|
+
async saveBranch(branch) {
|
|
6707
|
+
this.branches.set(branch.branch_id, branch);
|
|
6708
|
+
}
|
|
6709
|
+
async getBranch(branchId) {
|
|
6710
|
+
return this.branches.get(branchId) ?? null;
|
|
6711
|
+
}
|
|
6712
|
+
async getBranchesByTimeline(timelineId) {
|
|
6713
|
+
return [...this.branches.values()].filter((b) => b.timeline_id === timelineId);
|
|
6714
|
+
}
|
|
6715
|
+
async saveSnapshot(snapshot) {
|
|
6716
|
+
this.snapshots.set(snapshot.snapshot_id, snapshot);
|
|
6717
|
+
}
|
|
6718
|
+
async getSnapshot(snapshotId) {
|
|
6719
|
+
return this.snapshots.get(snapshotId) ?? null;
|
|
6720
|
+
}
|
|
6721
|
+
async getSnapshotByEvent(eventId) {
|
|
6722
|
+
return [...this.snapshots.values()].find((s) => s.event_id === eventId) ?? null;
|
|
6723
|
+
}
|
|
6724
|
+
};
|
|
6725
|
+
}
|
|
6726
|
+
});
|
|
6727
|
+
|
|
6105
6728
|
// src/utils/axis-tlv-codec.ts
|
|
6106
6729
|
function encodeAxisTlvDto(dtoClass, data) {
|
|
6107
6730
|
const schema = (0, import_dto_schema.extractDtoSchema)(dtoClass);
|
|
@@ -6160,37 +6783,1752 @@ var init_axis_tlv_codec = __esm({
|
|
|
6160
6783
|
}
|
|
6161
6784
|
});
|
|
6162
6785
|
|
|
6163
|
-
// src/loom/loom.types.ts
|
|
6164
|
-
function deriveAnchorReflection(softid, context = "openlogs", scope = "loom") {
|
|
6165
|
-
return `ar:${context}:${scope}:${softid}`;
|
|
6166
|
-
}
|
|
6167
|
-
function canonicalizeWrit(writ) {
|
|
6168
|
-
const ordered = {
|
|
6169
|
-
head: { tid: writ.head.tid, seq: writ.head.seq },
|
|
6170
|
-
body: {
|
|
6171
|
-
who: writ.body.who,
|
|
6172
|
-
act: writ.body.act,
|
|
6173
|
-
res: writ.body.res,
|
|
6174
|
-
law: writ.body.law
|
|
6175
|
-
},
|
|
6176
|
-
meta: { iat: writ.meta.iat, exp: writ.meta.exp, prev: writ.meta.prev }
|
|
6177
|
-
};
|
|
6178
|
-
return JSON.stringify(ordered);
|
|
6179
|
-
}
|
|
6180
|
-
function canonicalizeGrant(grant) {
|
|
6181
|
-
const ordered = {
|
|
6182
|
-
grant_id: grant.grant_id,
|
|
6183
|
-
issuer: grant.issuer,
|
|
6184
|
-
subject: grant.subject,
|
|
6185
|
-
grant_type: grant.grant_type,
|
|
6186
|
-
caps: grant.caps,
|
|
6187
|
-
meta: grant.meta
|
|
6188
|
-
};
|
|
6189
|
-
return JSON.stringify(ordered);
|
|
6190
|
-
}
|
|
6191
|
-
var init_loom_types = __esm({
|
|
6192
|
-
"src/loom/loom.types.ts"() {
|
|
6193
|
-
init_constants();
|
|
6786
|
+
// src/loom/loom.types.ts
|
|
6787
|
+
function deriveAnchorReflection(softid, context = "openlogs", scope = "loom") {
|
|
6788
|
+
return `ar:${context}:${scope}:${softid}`;
|
|
6789
|
+
}
|
|
6790
|
+
function canonicalizeWrit(writ) {
|
|
6791
|
+
const ordered = {
|
|
6792
|
+
head: { tid: writ.head.tid, seq: writ.head.seq },
|
|
6793
|
+
body: {
|
|
6794
|
+
who: writ.body.who,
|
|
6795
|
+
act: writ.body.act,
|
|
6796
|
+
res: writ.body.res,
|
|
6797
|
+
law: writ.body.law
|
|
6798
|
+
},
|
|
6799
|
+
meta: { iat: writ.meta.iat, exp: writ.meta.exp, prev: writ.meta.prev }
|
|
6800
|
+
};
|
|
6801
|
+
return JSON.stringify(ordered);
|
|
6802
|
+
}
|
|
6803
|
+
function canonicalizeGrant(grant) {
|
|
6804
|
+
const ordered = {
|
|
6805
|
+
grant_id: grant.grant_id,
|
|
6806
|
+
issuer: grant.issuer,
|
|
6807
|
+
subject: grant.subject,
|
|
6808
|
+
grant_type: grant.grant_type,
|
|
6809
|
+
caps: grant.caps,
|
|
6810
|
+
meta: grant.meta
|
|
6811
|
+
};
|
|
6812
|
+
return JSON.stringify(ordered);
|
|
6813
|
+
}
|
|
6814
|
+
var init_loom_types = __esm({
|
|
6815
|
+
"src/loom/loom.types.ts"() {
|
|
6816
|
+
init_constants();
|
|
6817
|
+
}
|
|
6818
|
+
});
|
|
6819
|
+
|
|
6820
|
+
// src/loom/loom.engine.ts
|
|
6821
|
+
function sha2567(data) {
|
|
6822
|
+
return (0, import_crypto9.createHash)("sha256").update(data).digest("hex");
|
|
6823
|
+
}
|
|
6824
|
+
function hexToUint8(hex) {
|
|
6825
|
+
const bytes2 = new Uint8Array(hex.length / 2);
|
|
6826
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
6827
|
+
bytes2[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
6828
|
+
}
|
|
6829
|
+
return bytes2;
|
|
6830
|
+
}
|
|
6831
|
+
function uint8ToHex(bytes2) {
|
|
6832
|
+
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6833
|
+
}
|
|
6834
|
+
function b64ToUint8(b64) {
|
|
6835
|
+
const bin = Buffer.from(b64, "base64");
|
|
6836
|
+
return new Uint8Array(bin.buffer, bin.byteOffset, bin.byteLength);
|
|
6837
|
+
}
|
|
6838
|
+
function uint8ToB64(bytes2) {
|
|
6839
|
+
return Buffer.from(bytes2).toString("base64");
|
|
6840
|
+
}
|
|
6841
|
+
function createPresenceChallenge(declaration, ttlMs = DEFAULT_PRESENCE_TTL_MS) {
|
|
6842
|
+
const now = Date.now();
|
|
6843
|
+
const nonce = (0, import_crypto9.randomBytes)(32).toString("hex");
|
|
6844
|
+
const challengeId = sha2567(`${declaration.softid}:${nonce}:${now}`);
|
|
6845
|
+
return {
|
|
6846
|
+
challenge_id: challengeId,
|
|
6847
|
+
nonce,
|
|
6848
|
+
temporal_anchor: now,
|
|
6849
|
+
ttl_ms: ttlMs,
|
|
6850
|
+
expires_at: now + ttlMs
|
|
6851
|
+
};
|
|
6852
|
+
}
|
|
6853
|
+
function presenceSigningData(challenge, deviceMeta) {
|
|
6854
|
+
return JSON.stringify({
|
|
6855
|
+
nonce: challenge.nonce,
|
|
6856
|
+
temporal_anchor: challenge.temporal_anchor,
|
|
6857
|
+
device_meta: deviceMeta ?? null
|
|
6858
|
+
});
|
|
6859
|
+
}
|
|
6860
|
+
function signPresenceChallenge(challenge, privateKeyHex, publicKeyHex, declaration, kid) {
|
|
6861
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
6862
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
6863
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6864
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6865
|
+
return {
|
|
6866
|
+
challenge_id: challenge.challenge_id,
|
|
6867
|
+
signature: uint8ToHex(signature),
|
|
6868
|
+
public_key: publicKeyHex,
|
|
6869
|
+
kid
|
|
6870
|
+
};
|
|
6871
|
+
}
|
|
6872
|
+
function verifyPresenceProof(challenge, proof, declaration, durationMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
6873
|
+
if (Date.now() > challenge.expires_at) {
|
|
6874
|
+
return { valid: false, error: "Challenge expired", code: "CHALLENGE_EXPIRED" };
|
|
6875
|
+
}
|
|
6876
|
+
if (proof.challenge_id !== challenge.challenge_id) {
|
|
6877
|
+
return { valid: false, error: "Challenge ID mismatch", code: "CHALLENGE_MISMATCH" };
|
|
6878
|
+
}
|
|
6879
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
6880
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
6881
|
+
const sigBytes = hexToUint8(proof.signature);
|
|
6882
|
+
const pubBytes = hexToUint8(proof.public_key);
|
|
6883
|
+
let isValid;
|
|
6884
|
+
try {
|
|
6885
|
+
isValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
6886
|
+
} catch {
|
|
6887
|
+
return { valid: false, error: "Signature verification failed", code: "SIG_INVALID" };
|
|
6888
|
+
}
|
|
6889
|
+
if (!isValid) {
|
|
6890
|
+
return { valid: false, error: "Invalid signature", code: "SIG_INVALID" };
|
|
6891
|
+
}
|
|
6892
|
+
const now = Date.now();
|
|
6893
|
+
const presenceId = sha2567(
|
|
6894
|
+
`${proof.public_key}:${challenge.nonce}:${challenge.temporal_anchor}`
|
|
6895
|
+
);
|
|
6896
|
+
const anchorReflection = sha2567(
|
|
6897
|
+
`ar:openlogs:loom:${proof.public_key}`
|
|
6898
|
+
);
|
|
6899
|
+
const receipt = {
|
|
6900
|
+
presence_id: presenceId,
|
|
6901
|
+
softid: declaration.softid,
|
|
6902
|
+
anchor_reflection: anchorReflection,
|
|
6903
|
+
scope: {
|
|
6904
|
+
device_fingerprint: declaration.device_meta?.fingerprint
|
|
6905
|
+
},
|
|
6906
|
+
issued_at: now,
|
|
6907
|
+
expires_at: now + durationMs
|
|
6908
|
+
};
|
|
6909
|
+
return { valid: true, presence: receipt };
|
|
6910
|
+
}
|
|
6911
|
+
function getPresenceStatus(receipt) {
|
|
6912
|
+
const now = Date.now();
|
|
6913
|
+
if (now > receipt.expires_at) return "expired";
|
|
6914
|
+
return "active";
|
|
6915
|
+
}
|
|
6916
|
+
function renewPresence(receipt, extensionMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
6917
|
+
const now = Date.now();
|
|
6918
|
+
return {
|
|
6919
|
+
...receipt,
|
|
6920
|
+
renewed_at: now,
|
|
6921
|
+
expires_at: now + extensionMs
|
|
6922
|
+
};
|
|
6923
|
+
}
|
|
6924
|
+
function createWrit(body, meta, thread, privateKeyHex, kid) {
|
|
6925
|
+
const head = { tid: thread.tid, seq: thread.seq };
|
|
6926
|
+
const writMeta = { ...meta, prev: thread.prevHash };
|
|
6927
|
+
const unsigned = { head, body, meta: writMeta };
|
|
6928
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
6929
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
6930
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
6931
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
6932
|
+
const sig = {
|
|
6933
|
+
alg: "ed25519",
|
|
6934
|
+
value: uint8ToB64(signature),
|
|
6935
|
+
kid
|
|
6936
|
+
};
|
|
6937
|
+
return { head, body, meta: writMeta, sig };
|
|
6938
|
+
}
|
|
6939
|
+
function validateWrit(writ, publicKeyHex, threadState, grants) {
|
|
6940
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
6941
|
+
if (now < writ.meta.iat) {
|
|
6942
|
+
return {
|
|
6943
|
+
valid: false,
|
|
6944
|
+
error: "Writ not yet valid (iat in future)",
|
|
6945
|
+
code: "TEMPORAL_NOT_YET",
|
|
6946
|
+
gate_failed: "temporal"
|
|
6947
|
+
};
|
|
6948
|
+
}
|
|
6949
|
+
if (now > writ.meta.exp) {
|
|
6950
|
+
return {
|
|
6951
|
+
valid: false,
|
|
6952
|
+
error: "Writ expired",
|
|
6953
|
+
code: "TEMPORAL_EXPIRED",
|
|
6954
|
+
gate_failed: "temporal"
|
|
6955
|
+
};
|
|
6956
|
+
}
|
|
6957
|
+
if (threadState) {
|
|
6958
|
+
if (writ.head.tid !== threadState.thread_id) {
|
|
6959
|
+
return {
|
|
6960
|
+
valid: false,
|
|
6961
|
+
error: "Thread ID mismatch",
|
|
6962
|
+
code: "CAUSAL_TID",
|
|
6963
|
+
gate_failed: "causal"
|
|
6964
|
+
};
|
|
6965
|
+
}
|
|
6966
|
+
if (writ.head.seq !== threadState.sequence + 1) {
|
|
6967
|
+
return {
|
|
6968
|
+
valid: false,
|
|
6969
|
+
error: `Expected seq ${threadState.sequence + 1}, got ${writ.head.seq}`,
|
|
6970
|
+
code: "CAUSAL_SEQ",
|
|
6971
|
+
gate_failed: "causal"
|
|
6972
|
+
};
|
|
6973
|
+
}
|
|
6974
|
+
if (writ.meta.prev !== threadState.last_receipt_hash) {
|
|
6975
|
+
return {
|
|
6976
|
+
valid: false,
|
|
6977
|
+
error: "Previous receipt hash mismatch",
|
|
6978
|
+
code: "CAUSAL_PREV",
|
|
6979
|
+
gate_failed: "causal"
|
|
6980
|
+
};
|
|
6981
|
+
}
|
|
6982
|
+
} else {
|
|
6983
|
+
if (writ.head.seq !== 1) {
|
|
6984
|
+
return {
|
|
6985
|
+
valid: false,
|
|
6986
|
+
error: "First writ in thread must have seq=1",
|
|
6987
|
+
code: "CAUSAL_FIRST_SEQ",
|
|
6988
|
+
gate_failed: "causal"
|
|
6989
|
+
};
|
|
6990
|
+
}
|
|
6991
|
+
if (writ.meta.prev !== "") {
|
|
6992
|
+
return {
|
|
6993
|
+
valid: false,
|
|
6994
|
+
error: "First writ must have empty prev hash",
|
|
6995
|
+
code: "CAUSAL_FIRST_PREV",
|
|
6996
|
+
gate_failed: "causal"
|
|
6997
|
+
};
|
|
6998
|
+
}
|
|
6999
|
+
}
|
|
7000
|
+
if (writ.body.law !== "self") {
|
|
7001
|
+
const matchingGrant = grants.find(
|
|
7002
|
+
(g) => g.grant_id === writ.body.law && g.subject === writ.body.who && grantCoversAction(g, writ.body.act, writ.body.res, now)
|
|
7003
|
+
);
|
|
7004
|
+
if (!matchingGrant) {
|
|
7005
|
+
return {
|
|
7006
|
+
valid: false,
|
|
7007
|
+
error: `No valid grant found for law=${writ.body.law}`,
|
|
7008
|
+
code: "LEGAL_NO_GRANT",
|
|
7009
|
+
gate_failed: "legal"
|
|
7010
|
+
};
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
const unsigned = {
|
|
7014
|
+
head: writ.head,
|
|
7015
|
+
body: writ.body,
|
|
7016
|
+
meta: writ.meta
|
|
7017
|
+
};
|
|
7018
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
7019
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
7020
|
+
const sigBytes = b64ToUint8(writ.sig.value);
|
|
7021
|
+
const pubBytes = hexToUint8(publicKeyHex);
|
|
7022
|
+
let sigValid;
|
|
7023
|
+
try {
|
|
7024
|
+
sigValid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
7025
|
+
} catch {
|
|
7026
|
+
return {
|
|
7027
|
+
valid: false,
|
|
7028
|
+
error: "Signature verification failed",
|
|
7029
|
+
code: "AUTH_SIG_FAIL",
|
|
7030
|
+
gate_failed: "authentic"
|
|
7031
|
+
};
|
|
7032
|
+
}
|
|
7033
|
+
if (!sigValid) {
|
|
7034
|
+
return {
|
|
7035
|
+
valid: false,
|
|
7036
|
+
error: "Invalid signature",
|
|
7037
|
+
code: "AUTH_SIG_INVALID",
|
|
7038
|
+
gate_failed: "authentic"
|
|
7039
|
+
};
|
|
7040
|
+
}
|
|
7041
|
+
return { valid: true, writ };
|
|
7042
|
+
}
|
|
7043
|
+
function grantCoversAction(grant, action, resource, nowUnix) {
|
|
7044
|
+
if (nowUnix < grant.meta.iat || nowUnix > grant.meta.exp) {
|
|
7045
|
+
return false;
|
|
7046
|
+
}
|
|
7047
|
+
return grant.caps.some(
|
|
7048
|
+
(cap) => matchOec(cap.oec, action) && matchScope(cap.scope, resource)
|
|
7049
|
+
);
|
|
7050
|
+
}
|
|
7051
|
+
function matchOec(pattern, action) {
|
|
7052
|
+
if (pattern === "*") return true;
|
|
7053
|
+
if (pattern === action) return true;
|
|
7054
|
+
if (pattern.endsWith(".*")) {
|
|
7055
|
+
const prefix = pattern.slice(0, -2);
|
|
7056
|
+
return action.startsWith(prefix + ".");
|
|
7057
|
+
}
|
|
7058
|
+
return false;
|
|
7059
|
+
}
|
|
7060
|
+
function matchScope(pattern, resource) {
|
|
7061
|
+
if (pattern === "*") return true;
|
|
7062
|
+
if (pattern === resource) return true;
|
|
7063
|
+
if (pattern.includes("*")) {
|
|
7064
|
+
const regex = new RegExp(
|
|
7065
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*/g, "[^:]*") + "$"
|
|
7066
|
+
);
|
|
7067
|
+
return regex.test(resource);
|
|
7068
|
+
}
|
|
7069
|
+
return false;
|
|
7070
|
+
}
|
|
7071
|
+
function getGrantStatus(grant, revocations) {
|
|
7072
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
7073
|
+
const revoked = revocations.find(
|
|
7074
|
+
(r) => r.target_type === "grant" && r.target_id === grant.grant_id
|
|
7075
|
+
);
|
|
7076
|
+
if (revoked && revoked.effective_at <= now * 1e3) {
|
|
7077
|
+
return "revoked";
|
|
7078
|
+
}
|
|
7079
|
+
if (now > grant.meta.exp) return "expired";
|
|
7080
|
+
return "active";
|
|
7081
|
+
}
|
|
7082
|
+
function validateGrant(grant, issuerPublicKeyHex) {
|
|
7083
|
+
const unsigned = {
|
|
7084
|
+
grant_id: grant.grant_id,
|
|
7085
|
+
issuer: grant.issuer,
|
|
7086
|
+
subject: grant.subject,
|
|
7087
|
+
grant_type: grant.grant_type,
|
|
7088
|
+
caps: grant.caps,
|
|
7089
|
+
meta: grant.meta
|
|
7090
|
+
};
|
|
7091
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
7092
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
7093
|
+
const sigBytes = b64ToUint8(grant.sig.value);
|
|
7094
|
+
const pubBytes = hexToUint8(issuerPublicKeyHex);
|
|
7095
|
+
let valid;
|
|
7096
|
+
try {
|
|
7097
|
+
valid = import_tweetnacl.sign.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
7098
|
+
} catch {
|
|
7099
|
+
return { valid: false, error: "Grant signature verification failed", code: "GRANT_SIG_FAIL" };
|
|
7100
|
+
}
|
|
7101
|
+
if (!valid) {
|
|
7102
|
+
return { valid: false, error: "Invalid grant signature", code: "GRANT_SIG_INVALID" };
|
|
7103
|
+
}
|
|
7104
|
+
return { valid: true, grant };
|
|
7105
|
+
}
|
|
7106
|
+
function createGrant(grantId, issuer, subject, grantType, caps, meta, privateKeyHex, kid) {
|
|
7107
|
+
const unsigned = {
|
|
7108
|
+
grant_id: grantId,
|
|
7109
|
+
issuer,
|
|
7110
|
+
subject,
|
|
7111
|
+
grant_type: grantType,
|
|
7112
|
+
caps,
|
|
7113
|
+
meta
|
|
7114
|
+
};
|
|
7115
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
7116
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
7117
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
7118
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
7119
|
+
return {
|
|
7120
|
+
...unsigned,
|
|
7121
|
+
sig: {
|
|
7122
|
+
alg: "ed25519",
|
|
7123
|
+
value: uint8ToB64(signature),
|
|
7124
|
+
kid
|
|
7125
|
+
}
|
|
7126
|
+
};
|
|
7127
|
+
}
|
|
7128
|
+
function createReceipt(writ, effect, prevReceipt, metadata) {
|
|
7129
|
+
const now = Date.now();
|
|
7130
|
+
const sequence = prevReceipt ? prevReceipt.sequence + 1 : 1;
|
|
7131
|
+
const prevHash = prevReceipt?.hash ?? null;
|
|
7132
|
+
const writHash = sha2567(canonicalizeWrit({
|
|
7133
|
+
head: writ.head,
|
|
7134
|
+
body: writ.body,
|
|
7135
|
+
meta: writ.meta
|
|
7136
|
+
}));
|
|
7137
|
+
const hashInput = [
|
|
7138
|
+
prevHash ?? "",
|
|
7139
|
+
writHash,
|
|
7140
|
+
writ.head.tid,
|
|
7141
|
+
String(sequence),
|
|
7142
|
+
effect,
|
|
7143
|
+
String(now)
|
|
7144
|
+
].join(":");
|
|
7145
|
+
const receiptHash = sha2567(hashInput);
|
|
7146
|
+
const receiptId = sha2567(`receipt:${receiptHash}:${now}`);
|
|
7147
|
+
return {
|
|
7148
|
+
receipt_id: receiptId,
|
|
7149
|
+
writ_hash: writHash,
|
|
7150
|
+
thread_id: writ.head.tid,
|
|
7151
|
+
sequence,
|
|
7152
|
+
effect,
|
|
7153
|
+
hash: receiptHash,
|
|
7154
|
+
prev_hash: prevHash,
|
|
7155
|
+
executed_at: now,
|
|
7156
|
+
metadata
|
|
7157
|
+
};
|
|
7158
|
+
}
|
|
7159
|
+
function verifyReceiptChain(receipts) {
|
|
7160
|
+
if (receipts.length === 0) return { valid: true };
|
|
7161
|
+
const sorted = [...receipts].sort((a, b) => a.sequence - b.sequence);
|
|
7162
|
+
if (sorted[0].prev_hash !== null) {
|
|
7163
|
+
return {
|
|
7164
|
+
valid: false,
|
|
7165
|
+
brokenAt: 0,
|
|
7166
|
+
error: "First receipt must have null prev_hash"
|
|
7167
|
+
};
|
|
7168
|
+
}
|
|
7169
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
7170
|
+
if (sorted[i].prev_hash !== sorted[i - 1].hash) {
|
|
7171
|
+
return {
|
|
7172
|
+
valid: false,
|
|
7173
|
+
brokenAt: i,
|
|
7174
|
+
error: `Receipt ${i} prev_hash does not match receipt ${i - 1} hash`
|
|
7175
|
+
};
|
|
7176
|
+
}
|
|
7177
|
+
}
|
|
7178
|
+
return { valid: true };
|
|
7179
|
+
}
|
|
7180
|
+
function updateThreadState(receipt, softid) {
|
|
7181
|
+
return {
|
|
7182
|
+
thread_id: receipt.thread_id,
|
|
7183
|
+
softid,
|
|
7184
|
+
last_receipt_hash: receipt.hash,
|
|
7185
|
+
sequence: receipt.sequence,
|
|
7186
|
+
updated_at: receipt.executed_at
|
|
7187
|
+
};
|
|
7188
|
+
}
|
|
7189
|
+
function createRevocation(targetType, targetId, issuerSoftid, privateKeyHex, reason) {
|
|
7190
|
+
const now = Date.now();
|
|
7191
|
+
const revocationId = sha2567(`revoke:${targetType}:${targetId}:${now}`);
|
|
7192
|
+
const payload = JSON.stringify({
|
|
7193
|
+
revocation_id: revocationId,
|
|
7194
|
+
target_type: targetType,
|
|
7195
|
+
target_id: targetId,
|
|
7196
|
+
issuer_softid: issuerSoftid,
|
|
7197
|
+
effective_at: now,
|
|
7198
|
+
reason: reason ?? null
|
|
7199
|
+
});
|
|
7200
|
+
const msgBytes = new TextEncoder().encode(payload);
|
|
7201
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
7202
|
+
const signature = import_tweetnacl.sign.detached(msgBytes, secretKey);
|
|
7203
|
+
return {
|
|
7204
|
+
revocation_id: revocationId,
|
|
7205
|
+
target_type: targetType,
|
|
7206
|
+
target_id: targetId,
|
|
7207
|
+
issuer_softid: issuerSoftid,
|
|
7208
|
+
reason,
|
|
7209
|
+
effective_at: now,
|
|
7210
|
+
sig_value: uint8ToHex(signature)
|
|
7211
|
+
};
|
|
7212
|
+
}
|
|
7213
|
+
function isRevoked(targetType, targetId, revocations) {
|
|
7214
|
+
const now = Date.now();
|
|
7215
|
+
return revocations.some(
|
|
7216
|
+
(r) => r.target_type === targetType && r.target_id === targetId && r.effective_at <= now
|
|
7217
|
+
);
|
|
7218
|
+
}
|
|
7219
|
+
function executeLoomPipeline(writ, publicKeyHex, presence, threadState, grants, revocations, prevReceipt) {
|
|
7220
|
+
const presenceStatus = getPresenceStatus(presence);
|
|
7221
|
+
if (presenceStatus !== "active") {
|
|
7222
|
+
return { valid: false, error: "Presence not active", code: "PRESENCE_INACTIVE" };
|
|
7223
|
+
}
|
|
7224
|
+
if (isRevoked("presence", presence.presence_id, revocations)) {
|
|
7225
|
+
return { valid: false, error: "Presence revoked", code: "PRESENCE_REVOKED" };
|
|
7226
|
+
}
|
|
7227
|
+
const activeGrants = grants.filter(
|
|
7228
|
+
(g) => getGrantStatus(g, revocations) === "active"
|
|
7229
|
+
);
|
|
7230
|
+
const writResult = validateWrit(writ, publicKeyHex, threadState, activeGrants);
|
|
7231
|
+
if (!writResult.valid) {
|
|
7232
|
+
return { valid: false, error: writResult.error, code: writResult.code };
|
|
7233
|
+
}
|
|
7234
|
+
const receipt = createReceipt(writ, "ALLOW", prevReceipt);
|
|
7235
|
+
const newThreadState = updateThreadState(receipt, writ.body.who);
|
|
7236
|
+
return {
|
|
7237
|
+
receipt,
|
|
7238
|
+
threadState: newThreadState,
|
|
7239
|
+
writValidation: writResult
|
|
7240
|
+
};
|
|
7241
|
+
}
|
|
7242
|
+
var import_crypto9, import_tweetnacl, DEFAULT_PRESENCE_TTL_MS, DEFAULT_PRESENCE_DURATION_MS;
|
|
7243
|
+
var init_loom_engine = __esm({
|
|
7244
|
+
"src/loom/loom.engine.ts"() {
|
|
7245
|
+
import_crypto9 = require("crypto");
|
|
7246
|
+
import_tweetnacl = require("tweetnacl");
|
|
7247
|
+
init_loom_types();
|
|
7248
|
+
DEFAULT_PRESENCE_TTL_MS = 5e3;
|
|
7249
|
+
DEFAULT_PRESENCE_DURATION_MS = 30 * 60 * 1e3;
|
|
7250
|
+
}
|
|
7251
|
+
});
|
|
7252
|
+
|
|
7253
|
+
// src/idel/idel.compiler.ts
|
|
7254
|
+
function validateType(value, expectedType) {
|
|
7255
|
+
switch (expectedType) {
|
|
7256
|
+
case "string":
|
|
7257
|
+
return typeof value === "string";
|
|
7258
|
+
case "number":
|
|
7259
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
7260
|
+
case "boolean":
|
|
7261
|
+
return typeof value === "boolean";
|
|
7262
|
+
case "object":
|
|
7263
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7264
|
+
case "array":
|
|
7265
|
+
return Array.isArray(value);
|
|
7266
|
+
default:
|
|
7267
|
+
return true;
|
|
7268
|
+
}
|
|
7269
|
+
}
|
|
7270
|
+
function assessRisk(schema, proposal, constraints) {
|
|
7271
|
+
const factors = [];
|
|
7272
|
+
let score = 0;
|
|
7273
|
+
const baseRiskMap = {
|
|
7274
|
+
none: 0,
|
|
7275
|
+
low: 0.1,
|
|
7276
|
+
medium: 0.3,
|
|
7277
|
+
high: 0.6,
|
|
7278
|
+
critical: 0.9
|
|
7279
|
+
};
|
|
7280
|
+
score = baseRiskMap[schema.risk_level] ?? 0;
|
|
7281
|
+
if (schema.risk_level !== "none") {
|
|
7282
|
+
factors.push(`Base risk: ${schema.risk_level}`);
|
|
7283
|
+
}
|
|
7284
|
+
if (schema.has_side_effects) {
|
|
7285
|
+
score += 0.1;
|
|
7286
|
+
factors.push("Has side effects");
|
|
7287
|
+
}
|
|
7288
|
+
if (!schema.reversible) {
|
|
7289
|
+
score += 0.1;
|
|
7290
|
+
factors.push("Not reversible");
|
|
7291
|
+
}
|
|
7292
|
+
const failed = constraints.filter((c) => !c.satisfied);
|
|
7293
|
+
if (failed.length > 0) {
|
|
7294
|
+
score += 0.05 * failed.length;
|
|
7295
|
+
factors.push(`${failed.length} unsatisfied constraint(s)`);
|
|
7296
|
+
}
|
|
7297
|
+
score = Math.min(score, 1);
|
|
7298
|
+
let level;
|
|
7299
|
+
if (score <= 0) level = "none";
|
|
7300
|
+
else if (score <= 0.2) level = "low";
|
|
7301
|
+
else if (score <= 0.5) level = "medium";
|
|
7302
|
+
else if (score <= 0.8) level = "high";
|
|
7303
|
+
else level = "critical";
|
|
7304
|
+
return { level, score, factors };
|
|
7305
|
+
}
|
|
7306
|
+
var IdelSchemaRegistry, IdelCompiler;
|
|
7307
|
+
var init_idel_compiler = __esm({
|
|
7308
|
+
"src/idel/idel.compiler.ts"() {
|
|
7309
|
+
IdelSchemaRegistry = class {
|
|
7310
|
+
constructor() {
|
|
7311
|
+
this.schemas = /* @__PURE__ */ new Map();
|
|
7312
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
7313
|
+
}
|
|
7314
|
+
register(schema) {
|
|
7315
|
+
this.schemas.set(schema.intent, schema);
|
|
7316
|
+
}
|
|
7317
|
+
registerAlias(alias, intent) {
|
|
7318
|
+
this.aliases.set(alias.toLowerCase(), intent);
|
|
7319
|
+
}
|
|
7320
|
+
get(intent) {
|
|
7321
|
+
return this.schemas.get(intent);
|
|
7322
|
+
}
|
|
7323
|
+
resolve(raw) {
|
|
7324
|
+
const exact = this.schemas.get(raw);
|
|
7325
|
+
if (exact) return exact;
|
|
7326
|
+
const aliased = this.aliases.get(raw.toLowerCase());
|
|
7327
|
+
if (aliased) return this.schemas.get(aliased);
|
|
7328
|
+
const candidates = [...this.schemas.keys()].filter(
|
|
7329
|
+
(k) => k.startsWith(raw + ".") || k.toLowerCase().includes(raw.toLowerCase())
|
|
7330
|
+
);
|
|
7331
|
+
if (candidates.length === 1) {
|
|
7332
|
+
return this.schemas.get(candidates[0]);
|
|
7333
|
+
}
|
|
7334
|
+
return void 0;
|
|
7335
|
+
}
|
|
7336
|
+
/**
|
|
7337
|
+
* Find all schemas that partially match the raw input.
|
|
7338
|
+
* Returns scored candidates for ambiguity resolution.
|
|
7339
|
+
*/
|
|
7340
|
+
findCandidates(raw) {
|
|
7341
|
+
const normalized = raw.toLowerCase().trim();
|
|
7342
|
+
const results = [];
|
|
7343
|
+
for (const [key, schema] of this.schemas) {
|
|
7344
|
+
let score = 0;
|
|
7345
|
+
if (key === raw) {
|
|
7346
|
+
score = 1;
|
|
7347
|
+
} else if (key.toLowerCase() === normalized) {
|
|
7348
|
+
score = 0.95;
|
|
7349
|
+
} else if (this.aliases.get(normalized) === key) {
|
|
7350
|
+
score = 0.9;
|
|
7351
|
+
} else if (key.toLowerCase().startsWith(normalized)) {
|
|
7352
|
+
score = 0.7;
|
|
7353
|
+
} else if (key.toLowerCase().includes(normalized)) {
|
|
7354
|
+
score = 0.5;
|
|
7355
|
+
} else if (schema.tags?.some((t) => t.toLowerCase().includes(normalized))) {
|
|
7356
|
+
score = 0.4;
|
|
7357
|
+
} else if (schema.description.toLowerCase().includes(normalized)) {
|
|
7358
|
+
score = 0.3;
|
|
7359
|
+
}
|
|
7360
|
+
if (score > 0) {
|
|
7361
|
+
results.push({ schema, score });
|
|
7362
|
+
}
|
|
7363
|
+
}
|
|
7364
|
+
return results.sort((a, b) => b.score - a.score);
|
|
7365
|
+
}
|
|
7366
|
+
list() {
|
|
7367
|
+
return [...this.schemas.values()];
|
|
7368
|
+
}
|
|
7369
|
+
};
|
|
7370
|
+
IdelCompiler = class {
|
|
7371
|
+
constructor(registry) {
|
|
7372
|
+
this.registry = registry;
|
|
7373
|
+
}
|
|
7374
|
+
/**
|
|
7375
|
+
* Compile a raw intent proposal into a validated, executable structure.
|
|
7376
|
+
*/
|
|
7377
|
+
compile(proposal) {
|
|
7378
|
+
const errors = [];
|
|
7379
|
+
const candidates = this.registry.findCandidates(proposal.raw);
|
|
7380
|
+
if (candidates.length === 0) {
|
|
7381
|
+
return {
|
|
7382
|
+
ok: false,
|
|
7383
|
+
errors: [{
|
|
7384
|
+
code: "IDEL_UNKNOWN_INTENT",
|
|
7385
|
+
message: `No intent found matching '${proposal.raw}'`
|
|
7386
|
+
}]
|
|
7387
|
+
};
|
|
7388
|
+
}
|
|
7389
|
+
const best = candidates[0];
|
|
7390
|
+
const schema = best.schema;
|
|
7391
|
+
const alternatives = candidates.slice(1, 4).filter((c) => c.score >= 0.3).map((c) => ({
|
|
7392
|
+
intent: c.schema.intent,
|
|
7393
|
+
confidence: c.score,
|
|
7394
|
+
reason: c.schema.description
|
|
7395
|
+
}));
|
|
7396
|
+
const constraints = [];
|
|
7397
|
+
const clarifications = [];
|
|
7398
|
+
const params = { ...proposal.params };
|
|
7399
|
+
for (const paramSchema of schema.params) {
|
|
7400
|
+
const value = params[paramSchema.name];
|
|
7401
|
+
if (paramSchema.required && value === void 0) {
|
|
7402
|
+
if (paramSchema.default !== void 0) {
|
|
7403
|
+
params[paramSchema.name] = paramSchema.default;
|
|
7404
|
+
constraints.push({
|
|
7405
|
+
kind: "required_param",
|
|
7406
|
+
field: paramSchema.name,
|
|
7407
|
+
description: `Defaulted to ${JSON.stringify(paramSchema.default)}`,
|
|
7408
|
+
satisfied: true,
|
|
7409
|
+
value: paramSchema.default
|
|
7410
|
+
});
|
|
7411
|
+
} else {
|
|
7412
|
+
constraints.push({
|
|
7413
|
+
kind: "required_param",
|
|
7414
|
+
field: paramSchema.name,
|
|
7415
|
+
description: `Required parameter '${paramSchema.name}' is missing`,
|
|
7416
|
+
satisfied: false
|
|
7417
|
+
});
|
|
7418
|
+
clarifications.push({
|
|
7419
|
+
id: `clarify_${paramSchema.name}`,
|
|
7420
|
+
question: paramSchema.description ?? `What is the ${paramSchema.name}?`,
|
|
7421
|
+
field: paramSchema.name,
|
|
7422
|
+
options: paramSchema.enum?.map(String),
|
|
7423
|
+
required: true
|
|
7424
|
+
});
|
|
7425
|
+
}
|
|
7426
|
+
continue;
|
|
7427
|
+
}
|
|
7428
|
+
if (value === void 0) continue;
|
|
7429
|
+
const typeValid = validateType(value, paramSchema.type);
|
|
7430
|
+
constraints.push({
|
|
7431
|
+
kind: "type_check",
|
|
7432
|
+
field: paramSchema.name,
|
|
7433
|
+
description: `Must be ${paramSchema.type}`,
|
|
7434
|
+
satisfied: typeValid,
|
|
7435
|
+
value,
|
|
7436
|
+
expected: paramSchema.type
|
|
7437
|
+
});
|
|
7438
|
+
if (!typeValid) {
|
|
7439
|
+
errors.push({
|
|
7440
|
+
code: "IDEL_TYPE_ERROR",
|
|
7441
|
+
message: `Parameter '${paramSchema.name}' must be ${paramSchema.type}, got ${typeof value}`,
|
|
7442
|
+
field: paramSchema.name
|
|
7443
|
+
});
|
|
7444
|
+
}
|
|
7445
|
+
if (paramSchema.min !== void 0 || paramSchema.max !== void 0) {
|
|
7446
|
+
const numVal = typeof value === "number" ? value : Number(value);
|
|
7447
|
+
const inRange = (paramSchema.min === void 0 || numVal >= paramSchema.min) && (paramSchema.max === void 0 || numVal <= paramSchema.max);
|
|
7448
|
+
constraints.push({
|
|
7449
|
+
kind: "range",
|
|
7450
|
+
field: paramSchema.name,
|
|
7451
|
+
description: `Must be between ${paramSchema.min ?? "-\u221E"} and ${paramSchema.max ?? "\u221E"}`,
|
|
7452
|
+
satisfied: inRange,
|
|
7453
|
+
value: numVal
|
|
7454
|
+
});
|
|
7455
|
+
}
|
|
7456
|
+
if (paramSchema.pattern) {
|
|
7457
|
+
const matches = new RegExp(paramSchema.pattern).test(String(value));
|
|
7458
|
+
constraints.push({
|
|
7459
|
+
kind: "pattern",
|
|
7460
|
+
field: paramSchema.name,
|
|
7461
|
+
description: `Must match ${paramSchema.pattern}`,
|
|
7462
|
+
satisfied: matches,
|
|
7463
|
+
value,
|
|
7464
|
+
expected: paramSchema.pattern
|
|
7465
|
+
});
|
|
7466
|
+
}
|
|
7467
|
+
if (paramSchema.enum) {
|
|
7468
|
+
const inEnum = paramSchema.enum.some(
|
|
7469
|
+
(e) => JSON.stringify(e) === JSON.stringify(value)
|
|
7470
|
+
);
|
|
7471
|
+
constraints.push({
|
|
7472
|
+
kind: "custom",
|
|
7473
|
+
field: paramSchema.name,
|
|
7474
|
+
description: `Must be one of: ${paramSchema.enum.join(", ")}`,
|
|
7475
|
+
satisfied: inEnum,
|
|
7476
|
+
value,
|
|
7477
|
+
expected: paramSchema.enum
|
|
7478
|
+
});
|
|
7479
|
+
}
|
|
7480
|
+
}
|
|
7481
|
+
const risk = assessRisk(schema, proposal, constraints);
|
|
7482
|
+
const unsatisfied = constraints.filter((c) => !c.satisfied);
|
|
7483
|
+
const needsClarification = clarifications.length > 0;
|
|
7484
|
+
let confidence = best.score;
|
|
7485
|
+
if (unsatisfied.length > 0) {
|
|
7486
|
+
confidence *= 1 - unsatisfied.length / Math.max(constraints.length, 1) * 0.5;
|
|
7487
|
+
}
|
|
7488
|
+
if (errors.length > 0) {
|
|
7489
|
+
confidence *= 0.5;
|
|
7490
|
+
}
|
|
7491
|
+
const compiled = {
|
|
7492
|
+
intent: schema.intent,
|
|
7493
|
+
actor_id: proposal.actor_id,
|
|
7494
|
+
target: proposal.target,
|
|
7495
|
+
params,
|
|
7496
|
+
constraints,
|
|
7497
|
+
confidence,
|
|
7498
|
+
alternatives,
|
|
7499
|
+
needs_clarification: needsClarification,
|
|
7500
|
+
clarifications,
|
|
7501
|
+
expected_outcome: schema.description,
|
|
7502
|
+
fallback: schema.related?.[0],
|
|
7503
|
+
risk,
|
|
7504
|
+
metadata: {
|
|
7505
|
+
schema_intent: schema.intent,
|
|
7506
|
+
resolved_from: proposal.raw,
|
|
7507
|
+
has_side_effects: schema.has_side_effects,
|
|
7508
|
+
reversible: schema.reversible
|
|
7509
|
+
}
|
|
7510
|
+
};
|
|
7511
|
+
return {
|
|
7512
|
+
ok: errors.length === 0 && !needsClarification,
|
|
7513
|
+
compiled,
|
|
7514
|
+
errors
|
|
7515
|
+
};
|
|
7516
|
+
}
|
|
7517
|
+
/**
|
|
7518
|
+
* Apply clarification answers and re-compile.
|
|
7519
|
+
*/
|
|
7520
|
+
applyClarifications(compiled, answers) {
|
|
7521
|
+
const proposal = {
|
|
7522
|
+
raw: compiled.intent,
|
|
7523
|
+
actor_id: compiled.actor_id,
|
|
7524
|
+
target: compiled.target,
|
|
7525
|
+
params: { ...compiled.params, ...answers }
|
|
7526
|
+
};
|
|
7527
|
+
return this.compile(proposal);
|
|
7528
|
+
}
|
|
7529
|
+
};
|
|
7530
|
+
}
|
|
7531
|
+
});
|
|
7532
|
+
|
|
7533
|
+
// src/needle/needle.engine.ts
|
|
7534
|
+
function assembleNeedle(params) {
|
|
7535
|
+
return {
|
|
7536
|
+
needle_id: (0, import_crypto10.randomBytes)(16).toString("hex"),
|
|
7537
|
+
phase: "created",
|
|
7538
|
+
tps_coordinate: params.tps_coordinate,
|
|
7539
|
+
intent: params.intent,
|
|
7540
|
+
presence: params.presence,
|
|
7541
|
+
writ: params.writ,
|
|
7542
|
+
grants: params.grants,
|
|
7543
|
+
created_at: Date.now()
|
|
7544
|
+
};
|
|
7545
|
+
}
|
|
7546
|
+
function classifyStitch(observation, verdict) {
|
|
7547
|
+
if (verdict.status === "failed" || verdict.status === "disputed") {
|
|
7548
|
+
return "torn";
|
|
7549
|
+
}
|
|
7550
|
+
if (observation.decision === "DENY") {
|
|
7551
|
+
return "silent";
|
|
7552
|
+
}
|
|
7553
|
+
if (verdict.isDeed) {
|
|
7554
|
+
return "deed";
|
|
7555
|
+
}
|
|
7556
|
+
return "silent";
|
|
7557
|
+
}
|
|
7558
|
+
function formStitch(needle, observation, verdict, receipt) {
|
|
7559
|
+
return {
|
|
7560
|
+
stitch_id: needle.needle_id,
|
|
7561
|
+
kind: classifyStitch(observation, verdict),
|
|
7562
|
+
intent: needle.intent.intent,
|
|
7563
|
+
actor_id: needle.intent.actor_id,
|
|
7564
|
+
tps_coordinate: needle.tps_coordinate,
|
|
7565
|
+
observation,
|
|
7566
|
+
verdict,
|
|
7567
|
+
receipt,
|
|
7568
|
+
thread_id: receipt.thread_id,
|
|
7569
|
+
sequence: receipt.sequence,
|
|
7570
|
+
stitched_at: Date.now()
|
|
7571
|
+
};
|
|
7572
|
+
}
|
|
7573
|
+
async function runNeedlePipeline(needle, config, threadState, prevReceipt, expectedOutcome) {
|
|
7574
|
+
const obs = createObservation("http");
|
|
7575
|
+
obs.intent = needle.intent.intent;
|
|
7576
|
+
obs.actorId = needle.intent.actor_id;
|
|
7577
|
+
needle.phase = "validated";
|
|
7578
|
+
let stage = startStage(obs, "loom.validate");
|
|
7579
|
+
const validation = validateWrit(
|
|
7580
|
+
needle.writ,
|
|
7581
|
+
config.public_key,
|
|
7582
|
+
threadState,
|
|
7583
|
+
needle.grants
|
|
7584
|
+
);
|
|
7585
|
+
if (!validation.valid) {
|
|
7586
|
+
endStage(stage, "fail", validation.error);
|
|
7587
|
+
return failNeedle(needle, obs, "validated", "LOOM_VALIDATION_FAILED", validation.error ?? "Writ validation failed");
|
|
7588
|
+
}
|
|
7589
|
+
endStage(stage, "ok");
|
|
7590
|
+
if (config.sensors && config.sensors.length > 0) {
|
|
7591
|
+
stage = startStage(obs, "sensors.evaluate");
|
|
7592
|
+
const sensorInput = {
|
|
7593
|
+
intent: needle.intent.intent,
|
|
7594
|
+
actorId: needle.intent.actor_id,
|
|
7595
|
+
metadata: {
|
|
7596
|
+
observation: obs,
|
|
7597
|
+
needle_id: needle.needle_id,
|
|
7598
|
+
tps_coordinate: needle.tps_coordinate,
|
|
7599
|
+
writ: needle.writ,
|
|
7600
|
+
grants: needle.grants,
|
|
7601
|
+
params: needle.intent.params
|
|
7602
|
+
}
|
|
7603
|
+
};
|
|
7604
|
+
for (const sensor of config.sensors) {
|
|
7605
|
+
if (sensor.supports && !sensor.supports(sensorInput)) continue;
|
|
7606
|
+
const t0 = Date.now();
|
|
7607
|
+
let decision;
|
|
7608
|
+
try {
|
|
7609
|
+
const rawDecision = await sensor.run(sensorInput);
|
|
7610
|
+
decision = normalizeSensorDecision(rawDecision);
|
|
7611
|
+
} catch (err) {
|
|
7612
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7613
|
+
recordSensor(obs, sensor.name, false, 100, Date.now() - t0, [`sensor_error:${msg}`]);
|
|
7614
|
+
endStage(stage, "fail", `Sensor ${sensor.name} threw: ${msg}`);
|
|
7615
|
+
return failNeedle(needle, obs, "validated", "SENSOR_ERROR", `Sensor ${sensor.name} failed: ${msg}`);
|
|
7616
|
+
}
|
|
7617
|
+
recordSensor(obs, sensor.name, decision.allow, decision.riskScore, Date.now() - t0, decision.reasons);
|
|
7618
|
+
if (!decision.allow) {
|
|
7619
|
+
endStage(stage, "fail", `Sensor ${sensor.name} denied`);
|
|
7620
|
+
return failNeedle(needle, obs, "validated", "SENSOR_DENY", decision.reasons[0] ?? `Denied by ${sensor.name}`);
|
|
7621
|
+
}
|
|
7622
|
+
}
|
|
7623
|
+
endStage(stage, "ok");
|
|
7624
|
+
}
|
|
7625
|
+
needle.phase = "executing";
|
|
7626
|
+
stage = startStage(obs, "handler.execute");
|
|
7627
|
+
const handler = config.handlers.get(needle.intent.intent);
|
|
7628
|
+
if (!handler) {
|
|
7629
|
+
endStage(stage, "fail", `No handler for intent '${needle.intent.intent}'`);
|
|
7630
|
+
return failNeedle(needle, obs, "executing", "NO_HANDLER", `No handler registered for intent '${needle.intent.intent}'`);
|
|
7631
|
+
}
|
|
7632
|
+
const handlerCtx = {
|
|
7633
|
+
needle_id: needle.needle_id,
|
|
7634
|
+
actor_id: needle.intent.actor_id,
|
|
7635
|
+
presence_id: needle.presence.presence_id,
|
|
7636
|
+
writ: needle.writ,
|
|
7637
|
+
grants: needle.grants,
|
|
7638
|
+
tps_coordinate: needle.tps_coordinate
|
|
7639
|
+
};
|
|
7640
|
+
let handlerResult;
|
|
7641
|
+
try {
|
|
7642
|
+
handlerResult = await handler(needle.intent, handlerCtx);
|
|
7643
|
+
} catch (err) {
|
|
7644
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7645
|
+
endStage(stage, "fail", msg);
|
|
7646
|
+
return failNeedle(needle, obs, "executing", "HANDLER_ERROR", msg);
|
|
7647
|
+
}
|
|
7648
|
+
if (!handlerResult.ok) {
|
|
7649
|
+
endStage(stage, "fail", handlerResult.effect);
|
|
7650
|
+
obs.decision = "DENY";
|
|
7651
|
+
obs.resultCode = handlerResult.effect;
|
|
7652
|
+
obs.statusCode = handlerResult.status_code ?? 400;
|
|
7653
|
+
} else {
|
|
7654
|
+
endStage(stage, "ok");
|
|
7655
|
+
obs.decision = "ALLOW";
|
|
7656
|
+
obs.resultCode = handlerResult.effect;
|
|
7657
|
+
obs.statusCode = handlerResult.status_code ?? 200;
|
|
7658
|
+
}
|
|
7659
|
+
if (handlerResult.data) {
|
|
7660
|
+
obs.facts = { ...obs.facts, ...handlerResult.data };
|
|
7661
|
+
}
|
|
7662
|
+
needle.phase = "observed";
|
|
7663
|
+
finalizeObservation(obs, obs.decision ?? "DENY", obs.statusCode ?? 500, obs.resultCode);
|
|
7664
|
+
needle.observation = obs;
|
|
7665
|
+
const verdict = scoreTruth(obs, expectedOutcome);
|
|
7666
|
+
needle.verdict = verdict;
|
|
7667
|
+
needle.phase = "stitched";
|
|
7668
|
+
stage = startStage(obs, "stitch.form");
|
|
7669
|
+
const receipt = createReceipt(
|
|
7670
|
+
needle.writ,
|
|
7671
|
+
obs.decision ?? "DENY",
|
|
7672
|
+
prevReceipt
|
|
7673
|
+
);
|
|
7674
|
+
needle.receipt = receipt;
|
|
7675
|
+
const newThreadState = updateThreadState(
|
|
7676
|
+
receipt,
|
|
7677
|
+
needle.intent.actor_id
|
|
7678
|
+
);
|
|
7679
|
+
const stitch = formStitch(needle, obs, verdict, receipt);
|
|
7680
|
+
needle.completed_at = Date.now();
|
|
7681
|
+
endStage(stage, "ok");
|
|
7682
|
+
return {
|
|
7683
|
+
ok: handlerResult.ok,
|
|
7684
|
+
needle,
|
|
7685
|
+
stitch,
|
|
7686
|
+
thread_state: newThreadState
|
|
7687
|
+
};
|
|
7688
|
+
}
|
|
7689
|
+
function failNeedle(needle, obs, phase, code, message) {
|
|
7690
|
+
needle.phase = "failed";
|
|
7691
|
+
needle.error = { phase, code, message };
|
|
7692
|
+
needle.completed_at = Date.now();
|
|
7693
|
+
obs.decision = obs.decision ?? "DENY";
|
|
7694
|
+
obs.statusCode = obs.statusCode ?? 500;
|
|
7695
|
+
finalizeObservation(obs, obs.decision, obs.statusCode, obs.resultCode);
|
|
7696
|
+
needle.observation = obs;
|
|
7697
|
+
const verdict = scoreTruth(obs);
|
|
7698
|
+
needle.verdict = verdict;
|
|
7699
|
+
return {
|
|
7700
|
+
ok: false,
|
|
7701
|
+
needle
|
|
7702
|
+
};
|
|
7703
|
+
}
|
|
7704
|
+
var import_crypto10;
|
|
7705
|
+
var init_needle_engine = __esm({
|
|
7706
|
+
"src/needle/needle.engine.ts"() {
|
|
7707
|
+
import_crypto10 = require("crypto");
|
|
7708
|
+
init_axis_observation();
|
|
7709
|
+
init_truth_scoring();
|
|
7710
|
+
init_loom_engine();
|
|
7711
|
+
init_axis_sensor();
|
|
7712
|
+
}
|
|
7713
|
+
});
|
|
7714
|
+
|
|
7715
|
+
// src/needle/knot.engine.ts
|
|
7716
|
+
function openKnot(params) {
|
|
7717
|
+
const isIrreversible = params.type === "irreversible";
|
|
7718
|
+
return {
|
|
7719
|
+
knot_id: `knot_${(0, import_crypto11.randomBytes)(16).toString("hex")}`,
|
|
7720
|
+
type: params.type,
|
|
7721
|
+
status: "open",
|
|
7722
|
+
stitch_ids: [],
|
|
7723
|
+
thread_id: params.thread_id,
|
|
7724
|
+
tps_anchor: params.tps_anchor,
|
|
7725
|
+
irreversible: isIrreversible,
|
|
7726
|
+
capsule_id: params.capsule_id,
|
|
7727
|
+
law_ref: params.law_ref,
|
|
7728
|
+
branch_ids: [],
|
|
7729
|
+
required_count: params.required_count,
|
|
7730
|
+
all_or_nothing: params.all_or_nothing ?? (params.type === "authority" || isIrreversible),
|
|
7731
|
+
actor_id: params.actor_id,
|
|
7732
|
+
created_at: Date.now()
|
|
7733
|
+
};
|
|
7734
|
+
}
|
|
7735
|
+
function addStitchToKnot(knot, stitch) {
|
|
7736
|
+
if (knot.status !== "open") {
|
|
7737
|
+
return `Knot ${knot.knot_id} is ${knot.status}, cannot add stitches`;
|
|
7738
|
+
}
|
|
7739
|
+
if (stitch.thread_id !== knot.thread_id) {
|
|
7740
|
+
return `Stitch thread ${stitch.thread_id} does not match knot thread ${knot.thread_id}`;
|
|
7741
|
+
}
|
|
7742
|
+
if (knot.stitch_ids.includes(stitch.stitch_id)) {
|
|
7743
|
+
return `Stitch ${stitch.stitch_id} already in knot`;
|
|
7744
|
+
}
|
|
7745
|
+
if (knot.type === "authority" && knot.capsule_id) {
|
|
7746
|
+
if (stitch.observation.capsuleId && stitch.observation.capsuleId !== knot.capsule_id) {
|
|
7747
|
+
return `Stitch capsule ${stitch.observation.capsuleId} does not match knot capsule ${knot.capsule_id}`;
|
|
7748
|
+
}
|
|
7749
|
+
}
|
|
7750
|
+
knot.stitch_ids.push(stitch.stitch_id);
|
|
7751
|
+
return null;
|
|
7752
|
+
}
|
|
7753
|
+
function validateKnot(knot, stitches) {
|
|
7754
|
+
const errors = [];
|
|
7755
|
+
const passedIds = [];
|
|
7756
|
+
const failedIds = [];
|
|
7757
|
+
const stitchMap = new Map(stitches.map((s) => [s.stitch_id, s]));
|
|
7758
|
+
for (const sid of knot.stitch_ids) {
|
|
7759
|
+
const stitch = stitchMap.get(sid);
|
|
7760
|
+
if (!stitch) {
|
|
7761
|
+
failedIds.push(sid);
|
|
7762
|
+
errors.push({
|
|
7763
|
+
code: "KNOT_MISSING_STITCH",
|
|
7764
|
+
message: `Stitch ${sid} not found`,
|
|
7765
|
+
stitch_id: sid
|
|
7766
|
+
});
|
|
7767
|
+
continue;
|
|
7768
|
+
}
|
|
7769
|
+
if (stitch.kind === "torn") {
|
|
7770
|
+
failedIds.push(sid);
|
|
7771
|
+
errors.push({
|
|
7772
|
+
code: "KNOT_TORN_STITCH",
|
|
7773
|
+
message: `Stitch ${sid} is torn (failed/disputed)`,
|
|
7774
|
+
stitch_id: sid
|
|
7775
|
+
});
|
|
7776
|
+
continue;
|
|
7777
|
+
}
|
|
7778
|
+
if (knot.type === "irreversible" && stitch.kind !== "deed") {
|
|
7779
|
+
failedIds.push(sid);
|
|
7780
|
+
errors.push({
|
|
7781
|
+
code: "KNOT_REQUIRES_DEED",
|
|
7782
|
+
message: `Irreversible knot requires deed stitch, got '${stitch.kind}'`,
|
|
7783
|
+
stitch_id: sid
|
|
7784
|
+
});
|
|
7785
|
+
continue;
|
|
7786
|
+
}
|
|
7787
|
+
passedIds.push(sid);
|
|
7788
|
+
}
|
|
7789
|
+
if (knot.required_count !== void 0 && knot.stitch_ids.length < knot.required_count) {
|
|
7790
|
+
errors.push({
|
|
7791
|
+
code: "KNOT_INSUFFICIENT_STITCHES",
|
|
7792
|
+
message: `Knot requires ${knot.required_count} stitches, has ${knot.stitch_ids.length}`
|
|
7793
|
+
});
|
|
7794
|
+
}
|
|
7795
|
+
const allPassed = failedIds.length === 0;
|
|
7796
|
+
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);
|
|
7797
|
+
return {
|
|
7798
|
+
valid: allPassed && errors.length === 0,
|
|
7799
|
+
passed_stitch_ids: passedIds,
|
|
7800
|
+
failed_stitch_ids: failedIds,
|
|
7801
|
+
can_tie: canTie,
|
|
7802
|
+
errors
|
|
7803
|
+
};
|
|
7804
|
+
}
|
|
7805
|
+
function tieKnot(knot, stitches) {
|
|
7806
|
+
const validation = validateKnot(knot, stitches);
|
|
7807
|
+
if (!validation.can_tie) {
|
|
7808
|
+
return { ...validation, knot };
|
|
7809
|
+
}
|
|
7810
|
+
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);
|
|
7811
|
+
const witnessPayload = receiptHashes.join(":");
|
|
7812
|
+
knot.witness_hash = (0, import_crypto11.createHash)("sha256").update(witnessPayload).digest("hex");
|
|
7813
|
+
knot.status = "tied";
|
|
7814
|
+
knot.tied_at = Date.now();
|
|
7815
|
+
return { ...validation, knot };
|
|
7816
|
+
}
|
|
7817
|
+
function breakKnot(knot, request) {
|
|
7818
|
+
if (knot.status === "broken") {
|
|
7819
|
+
return { ok: false, error: "Knot is already broken" };
|
|
7820
|
+
}
|
|
7821
|
+
if (knot.status === "open") {
|
|
7822
|
+
knot.status = "broken";
|
|
7823
|
+
knot.broken_at = Date.now();
|
|
7824
|
+
knot.break_reason = request.reason;
|
|
7825
|
+
return { ok: true };
|
|
7826
|
+
}
|
|
7827
|
+
if (knot.status === "tied") {
|
|
7828
|
+
if (!request.reason) {
|
|
7829
|
+
return { ok: false, error: "Breaking a tied knot requires a reason" };
|
|
7830
|
+
}
|
|
7831
|
+
if ((knot.irreversible || knot.type === "law") && !request.override_grant_id) {
|
|
7832
|
+
return {
|
|
7833
|
+
ok: false,
|
|
7834
|
+
error: `Breaking ${knot.type} knot requires override_grant_id from higher authority`
|
|
7835
|
+
};
|
|
7836
|
+
}
|
|
7837
|
+
knot.status = "broken";
|
|
7838
|
+
knot.broken_at = Date.now();
|
|
7839
|
+
knot.break_reason = request.reason;
|
|
7840
|
+
return { ok: true };
|
|
7841
|
+
}
|
|
7842
|
+
return { ok: false, error: `Cannot break knot in status '${knot.status}'` };
|
|
7843
|
+
}
|
|
7844
|
+
function forkFromKnot(knot, branchId, decisionStitchId) {
|
|
7845
|
+
if (knot.status !== "tied" && knot.status !== "open") {
|
|
7846
|
+
return { ok: false, error: `Cannot fork from knot in status '${knot.status}'` };
|
|
7847
|
+
}
|
|
7848
|
+
if (decisionStitchId) {
|
|
7849
|
+
if (!knot.stitch_ids.includes(decisionStitchId)) {
|
|
7850
|
+
return { ok: false, error: `Decision stitch ${decisionStitchId} is not part of this knot` };
|
|
7851
|
+
}
|
|
7852
|
+
knot.decision_stitch_id = decisionStitchId;
|
|
7853
|
+
}
|
|
7854
|
+
knot.branch_ids.push(branchId);
|
|
7855
|
+
knot.status = "forked";
|
|
7856
|
+
return { ok: true };
|
|
7857
|
+
}
|
|
7858
|
+
function isKnotOpen(knot) {
|
|
7859
|
+
return knot.status === "open";
|
|
7860
|
+
}
|
|
7861
|
+
function isPointOfNoReturn(knot) {
|
|
7862
|
+
return knot.irreversible && knot.status === "tied";
|
|
7863
|
+
}
|
|
7864
|
+
function findKnotsForStitch(stitchId, knots) {
|
|
7865
|
+
return knots.filter((k) => k.stitch_ids.includes(stitchId));
|
|
7866
|
+
}
|
|
7867
|
+
function getIrreversibleKnots(knots) {
|
|
7868
|
+
return knots.filter((k) => k.irreversible && k.status === "tied");
|
|
7869
|
+
}
|
|
7870
|
+
function getDecisionPoints(knots) {
|
|
7871
|
+
return knots.filter((k) => k.type === "decision" || k.status === "forked");
|
|
7872
|
+
}
|
|
7873
|
+
var import_crypto11;
|
|
7874
|
+
var init_knot_engine = __esm({
|
|
7875
|
+
"src/needle/knot.engine.ts"() {
|
|
7876
|
+
import_crypto11 = require("crypto");
|
|
7877
|
+
}
|
|
7878
|
+
});
|
|
7879
|
+
|
|
7880
|
+
// src/needle/fabric.engine.ts
|
|
7881
|
+
function createFabric() {
|
|
7882
|
+
return {
|
|
7883
|
+
fabric_id: `fab_${(0, import_crypto12.randomBytes)(16).toString("hex")}`,
|
|
7884
|
+
state_hash: hashState(/* @__PURE__ */ new Map()),
|
|
7885
|
+
cells: /* @__PURE__ */ new Map(),
|
|
7886
|
+
thread_ids: [],
|
|
7887
|
+
stitch_count: 0,
|
|
7888
|
+
knot_count: 0,
|
|
7889
|
+
computed_at: Date.now(),
|
|
7890
|
+
version: 0
|
|
7891
|
+
};
|
|
7892
|
+
}
|
|
7893
|
+
function applyStitch(fabric, stitch, effect) {
|
|
7894
|
+
for (const [key, value] of Object.entries(effect.mutations)) {
|
|
7895
|
+
if (value === null) {
|
|
7896
|
+
fabric.cells.delete(key);
|
|
7897
|
+
} else {
|
|
7898
|
+
const existing = fabric.cells.get(key);
|
|
7899
|
+
if (existing?.locked) {
|
|
7900
|
+
continue;
|
|
7901
|
+
}
|
|
7902
|
+
fabric.cells.set(key, {
|
|
7903
|
+
key,
|
|
7904
|
+
value,
|
|
7905
|
+
last_stitch_id: stitch.stitch_id,
|
|
7906
|
+
last_tps: stitch.tps_coordinate,
|
|
7907
|
+
write_count: (existing?.write_count ?? 0) + 1,
|
|
7908
|
+
locked: false
|
|
7909
|
+
});
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
if (!fabric.thread_ids.includes(stitch.thread_id)) {
|
|
7913
|
+
fabric.thread_ids.push(stitch.thread_id);
|
|
7914
|
+
}
|
|
7915
|
+
fabric.stitch_count++;
|
|
7916
|
+
fabric.version++;
|
|
7917
|
+
fabric.projected_at_tps = stitch.tps_coordinate ?? fabric.projected_at_tps;
|
|
7918
|
+
fabric.computed_at = Date.now();
|
|
7919
|
+
fabric.state_hash = hashState(fabric.cells);
|
|
7920
|
+
}
|
|
7921
|
+
function weave(stitches, resolver, knots) {
|
|
7922
|
+
const fabric = createFabric();
|
|
7923
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
7924
|
+
for (const stitch of sorted) {
|
|
7925
|
+
if (stitch.kind === "torn") continue;
|
|
7926
|
+
const effect = resolver(stitch);
|
|
7927
|
+
applyStitch(fabric, stitch, effect);
|
|
7928
|
+
}
|
|
7929
|
+
if (knots) {
|
|
7930
|
+
for (const knot of knots) {
|
|
7931
|
+
if (knot.irreversible && knot.status === "tied") {
|
|
7932
|
+
lockCellsByKnot(fabric, knot, stitches, resolver);
|
|
7933
|
+
fabric.knot_count++;
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7937
|
+
return fabric;
|
|
7938
|
+
}
|
|
7939
|
+
function projectAt(stitches, resolver, tpsFilter, knots) {
|
|
7940
|
+
const filtered = stitches.filter((s) => tpsFilter(s.tps_coordinate));
|
|
7941
|
+
return weave(filtered, resolver, knots);
|
|
7942
|
+
}
|
|
7943
|
+
function lockCellsByKnot(fabric, knot, stitches, resolver) {
|
|
7944
|
+
const knotStitchIds = new Set(knot.stitch_ids);
|
|
7945
|
+
const knotStitches = stitches.filter((s) => knotStitchIds.has(s.stitch_id));
|
|
7946
|
+
for (const stitch of knotStitches) {
|
|
7947
|
+
const effect = resolver(stitch);
|
|
7948
|
+
for (const key of Object.keys(effect.mutations)) {
|
|
7949
|
+
const cell = fabric.cells.get(key);
|
|
7950
|
+
if (cell) {
|
|
7951
|
+
cell.locked = true;
|
|
7952
|
+
cell.locked_by_knot = knot.knot_id;
|
|
7953
|
+
}
|
|
7954
|
+
}
|
|
7955
|
+
}
|
|
7956
|
+
}
|
|
7957
|
+
function lockCells(fabric, keys, knotId) {
|
|
7958
|
+
for (const key of keys) {
|
|
7959
|
+
const cell = fabric.cells.get(key);
|
|
7960
|
+
if (cell) {
|
|
7961
|
+
cell.locked = true;
|
|
7962
|
+
cell.locked_by_knot = knotId;
|
|
7963
|
+
}
|
|
7964
|
+
}
|
|
7965
|
+
}
|
|
7966
|
+
function queryFabric(fabric, query) {
|
|
7967
|
+
let results = [...fabric.cells.values()];
|
|
7968
|
+
if (query.keys) {
|
|
7969
|
+
const keySet = new Set(query.keys);
|
|
7970
|
+
results = results.filter((c) => keySet.has(c.key));
|
|
7971
|
+
}
|
|
7972
|
+
if (query.prefix) {
|
|
7973
|
+
const prefix = query.prefix;
|
|
7974
|
+
results = results.filter((c) => c.key.startsWith(prefix));
|
|
7975
|
+
}
|
|
7976
|
+
if (query.locked_only) {
|
|
7977
|
+
results = results.filter((c) => c.locked);
|
|
7978
|
+
}
|
|
7979
|
+
return results;
|
|
7980
|
+
}
|
|
7981
|
+
function getFabricValue(fabric, key) {
|
|
7982
|
+
return fabric.cells.get(key)?.value;
|
|
7983
|
+
}
|
|
7984
|
+
function diffFabrics(a, b) {
|
|
7985
|
+
const entries = [];
|
|
7986
|
+
let added = 0;
|
|
7987
|
+
let modified = 0;
|
|
7988
|
+
let deleted = 0;
|
|
7989
|
+
for (const [key, cellB] of b.cells) {
|
|
7990
|
+
const cellA = a.cells.get(key);
|
|
7991
|
+
if (!cellA) {
|
|
7992
|
+
entries.push({
|
|
7993
|
+
key,
|
|
7994
|
+
kind: "added",
|
|
7995
|
+
after: cellB.value,
|
|
7996
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
7997
|
+
});
|
|
7998
|
+
added++;
|
|
7999
|
+
} else if (JSON.stringify(cellA.value) !== JSON.stringify(cellB.value)) {
|
|
8000
|
+
entries.push({
|
|
8001
|
+
key,
|
|
8002
|
+
kind: "modified",
|
|
8003
|
+
before: cellA.value,
|
|
8004
|
+
after: cellB.value,
|
|
8005
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
8006
|
+
});
|
|
8007
|
+
modified++;
|
|
8008
|
+
}
|
|
8009
|
+
}
|
|
8010
|
+
for (const [key, cellA] of a.cells) {
|
|
8011
|
+
if (!b.cells.has(key)) {
|
|
8012
|
+
entries.push({
|
|
8013
|
+
key,
|
|
8014
|
+
kind: "deleted",
|
|
8015
|
+
before: cellA.value
|
|
8016
|
+
});
|
|
8017
|
+
deleted++;
|
|
8018
|
+
}
|
|
8019
|
+
}
|
|
8020
|
+
return {
|
|
8021
|
+
from_fabric_id: a.fabric_id,
|
|
8022
|
+
to_fabric_id: b.fabric_id,
|
|
8023
|
+
entries,
|
|
8024
|
+
added_count: added,
|
|
8025
|
+
modified_count: modified,
|
|
8026
|
+
deleted_count: deleted
|
|
8027
|
+
};
|
|
8028
|
+
}
|
|
8029
|
+
function hashState(cells) {
|
|
8030
|
+
const keys = [...cells.keys()].sort();
|
|
8031
|
+
const payload = keys.map((k) => `${k}=${JSON.stringify(cells.get(k).value)}`).join("\n");
|
|
8032
|
+
return (0, import_crypto12.createHash)("sha256").update(payload).digest("hex");
|
|
8033
|
+
}
|
|
8034
|
+
var import_crypto12;
|
|
8035
|
+
var init_fabric_engine = __esm({
|
|
8036
|
+
"src/needle/fabric.engine.ts"() {
|
|
8037
|
+
import_crypto12 = require("crypto");
|
|
8038
|
+
}
|
|
8039
|
+
});
|
|
8040
|
+
|
|
8041
|
+
// src/needle/pattern.engine.ts
|
|
8042
|
+
function detectSequencePatterns(stitches, windowSize, minOccurrences) {
|
|
8043
|
+
if (stitches.length < windowSize || windowSize < 2) return [];
|
|
8044
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
8045
|
+
const sequenceCounts = /* @__PURE__ */ new Map();
|
|
8046
|
+
for (let i = 0; i <= sorted.length - windowSize; i++) {
|
|
8047
|
+
const window = sorted.slice(i, i + windowSize);
|
|
8048
|
+
const key = window.map((s) => s.intent).join("\u2192");
|
|
8049
|
+
const ids = window.map((s) => s.stitch_id);
|
|
8050
|
+
const existing = sequenceCounts.get(key);
|
|
8051
|
+
if (existing) {
|
|
8052
|
+
existing.count++;
|
|
8053
|
+
existing.stitch_ids.push(ids);
|
|
8054
|
+
} else {
|
|
8055
|
+
sequenceCounts.set(key, { count: 1, stitch_ids: [ids] });
|
|
8056
|
+
}
|
|
8057
|
+
}
|
|
8058
|
+
const patterns = [];
|
|
8059
|
+
const now = Date.now();
|
|
8060
|
+
for (const [key, data] of sequenceCounts) {
|
|
8061
|
+
if (data.count < minOccurrences) continue;
|
|
8062
|
+
const intents = key.split("\u2192");
|
|
8063
|
+
const confidence = Math.min(data.count / (minOccurrences * 2), 1);
|
|
8064
|
+
patterns.push({
|
|
8065
|
+
pattern_id: `pat_seq_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
8066
|
+
kind: "sequence",
|
|
8067
|
+
name: `Sequence: ${intents.join(" \u2192 ")}`,
|
|
8068
|
+
signature: {
|
|
8069
|
+
intent_sequence: intents,
|
|
8070
|
+
min_length: windowSize,
|
|
8071
|
+
max_length: windowSize
|
|
8072
|
+
},
|
|
8073
|
+
confidence,
|
|
8074
|
+
occurrence_count: data.count,
|
|
8075
|
+
first_seen_at: now,
|
|
8076
|
+
last_seen_at: now,
|
|
8077
|
+
seen_in_threads: [...new Set(
|
|
8078
|
+
data.stitch_ids.flatMap(
|
|
8079
|
+
(ids) => ids.map((id) => sorted.find((s) => s.stitch_id === id)?.thread_id).filter(Boolean)
|
|
8080
|
+
)
|
|
8081
|
+
)],
|
|
8082
|
+
classification: "unclassified"
|
|
8083
|
+
});
|
|
8084
|
+
}
|
|
8085
|
+
return patterns;
|
|
8086
|
+
}
|
|
8087
|
+
function detectKnotPatterns(knots, minOccurrences) {
|
|
8088
|
+
const groups = /* @__PURE__ */ new Map();
|
|
8089
|
+
for (const knot of knots) {
|
|
8090
|
+
if (knot.status !== "tied") continue;
|
|
8091
|
+
const key = `${knot.type}:${knot.stitch_ids.length}`;
|
|
8092
|
+
const group = groups.get(key) ?? [];
|
|
8093
|
+
group.push(knot);
|
|
8094
|
+
groups.set(key, group);
|
|
8095
|
+
}
|
|
8096
|
+
const patterns = [];
|
|
8097
|
+
const now = Date.now();
|
|
8098
|
+
for (const [key, group] of groups) {
|
|
8099
|
+
if (group.length < minOccurrences) continue;
|
|
8100
|
+
const [type, sizeStr] = key.split(":");
|
|
8101
|
+
const size = parseInt(sizeStr, 10);
|
|
8102
|
+
const confidence = Math.min(group.length / (minOccurrences * 2), 1);
|
|
8103
|
+
patterns.push({
|
|
8104
|
+
pattern_id: `pat_knot_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
8105
|
+
kind: "knot",
|
|
8106
|
+
name: `Knot: ${type} (${size} stitches)`,
|
|
8107
|
+
signature: {
|
|
8108
|
+
knot_type: type,
|
|
8109
|
+
knot_size: size
|
|
8110
|
+
},
|
|
8111
|
+
confidence,
|
|
8112
|
+
occurrence_count: group.length,
|
|
8113
|
+
first_seen_at: now,
|
|
8114
|
+
last_seen_at: now,
|
|
8115
|
+
seen_in_threads: [...new Set(group.map((k) => k.thread_id))],
|
|
8116
|
+
classification: "unclassified"
|
|
8117
|
+
});
|
|
8118
|
+
}
|
|
8119
|
+
return patterns;
|
|
8120
|
+
}
|
|
8121
|
+
function matchPatterns(stitches, patterns) {
|
|
8122
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
8123
|
+
const matches = [];
|
|
8124
|
+
const now = Date.now();
|
|
8125
|
+
for (const pattern of patterns) {
|
|
8126
|
+
if (pattern.kind === "sequence" && pattern.signature.intent_sequence) {
|
|
8127
|
+
const seq = pattern.signature.intent_sequence;
|
|
8128
|
+
const seqLen = seq.length;
|
|
8129
|
+
for (let i = 0; i <= sorted.length - seqLen; i++) {
|
|
8130
|
+
const window = sorted.slice(i, i + seqLen);
|
|
8131
|
+
const windowIntents = window.map((s) => s.intent);
|
|
8132
|
+
if (windowIntents.every((intent, idx) => intent === seq[idx])) {
|
|
8133
|
+
matches.push({
|
|
8134
|
+
pattern_id: pattern.pattern_id,
|
|
8135
|
+
matched_stitch_ids: window.map((s) => s.stitch_id),
|
|
8136
|
+
match_score: 1,
|
|
8137
|
+
thread_id: window[0].thread_id,
|
|
8138
|
+
detected_at: now
|
|
8139
|
+
});
|
|
8140
|
+
}
|
|
8141
|
+
}
|
|
8142
|
+
}
|
|
8143
|
+
}
|
|
8144
|
+
return matches;
|
|
8145
|
+
}
|
|
8146
|
+
function recordOccurrence(pattern, threadId) {
|
|
8147
|
+
pattern.occurrence_count++;
|
|
8148
|
+
pattern.last_seen_at = Date.now();
|
|
8149
|
+
pattern.confidence = 1 - 1 / (1 + pattern.occurrence_count * 0.5);
|
|
8150
|
+
if (!pattern.seen_in_threads.includes(threadId)) {
|
|
8151
|
+
pattern.seen_in_threads.push(threadId);
|
|
8152
|
+
}
|
|
8153
|
+
}
|
|
8154
|
+
function detectAnomalies(recentStitches, knownPatterns, threshold = 0.7) {
|
|
8155
|
+
const anomalies = [];
|
|
8156
|
+
const sorted = [...recentStitches].sort((a, b) => a.sequence - b.sequence);
|
|
8157
|
+
const now = Date.now();
|
|
8158
|
+
for (const pattern of knownPatterns) {
|
|
8159
|
+
if (pattern.kind !== "sequence" || !pattern.signature.intent_sequence) continue;
|
|
8160
|
+
if (pattern.confidence < threshold) continue;
|
|
8161
|
+
const seq = pattern.signature.intent_sequence;
|
|
8162
|
+
if (sorted.length >= 1 && sorted.length < seq.length) {
|
|
8163
|
+
const partialMatch = sorted.every(
|
|
8164
|
+
(s, i) => i < seq.length && s.intent === seq[i]
|
|
8165
|
+
);
|
|
8166
|
+
if (partialMatch) {
|
|
8167
|
+
const expectedNext = seq[sorted.length];
|
|
8168
|
+
const lastStitch = sorted[sorted.length - 1];
|
|
8169
|
+
if (pattern.occurrence_count >= 3) {
|
|
8170
|
+
anomalies.push({
|
|
8171
|
+
pattern_id: `pat_anom_${(0, import_crypto13.randomBytes)(8).toString("hex")}`,
|
|
8172
|
+
kind: "anomaly",
|
|
8173
|
+
name: `Incomplete: ${pattern.name}`,
|
|
8174
|
+
description: `Expected '${expectedNext}' after '${lastStitch.intent}' based on pattern '${pattern.name}'`,
|
|
8175
|
+
signature: pattern.signature,
|
|
8176
|
+
confidence: pattern.confidence * 0.8,
|
|
8177
|
+
occurrence_count: 1,
|
|
8178
|
+
first_seen_at: now,
|
|
8179
|
+
last_seen_at: now,
|
|
8180
|
+
seen_in_threads: [lastStitch.thread_id],
|
|
8181
|
+
classification: "anomalous"
|
|
8182
|
+
});
|
|
8183
|
+
}
|
|
8184
|
+
}
|
|
8185
|
+
}
|
|
8186
|
+
}
|
|
8187
|
+
return anomalies;
|
|
8188
|
+
}
|
|
8189
|
+
var import_crypto13, InMemoryPatternStore;
|
|
8190
|
+
var init_pattern_engine = __esm({
|
|
8191
|
+
"src/needle/pattern.engine.ts"() {
|
|
8192
|
+
import_crypto13 = require("crypto");
|
|
8193
|
+
InMemoryPatternStore = class {
|
|
8194
|
+
constructor() {
|
|
8195
|
+
this.patterns = /* @__PURE__ */ new Map();
|
|
8196
|
+
}
|
|
8197
|
+
save(pattern) {
|
|
8198
|
+
this.patterns.set(pattern.pattern_id, pattern);
|
|
8199
|
+
}
|
|
8200
|
+
get(patternId) {
|
|
8201
|
+
return this.patterns.get(patternId);
|
|
8202
|
+
}
|
|
8203
|
+
findByKind(kind) {
|
|
8204
|
+
return [...this.patterns.values()].filter((p) => p.kind === kind);
|
|
8205
|
+
}
|
|
8206
|
+
findByIntent(intent) {
|
|
8207
|
+
return [...this.patterns.values()].filter(
|
|
8208
|
+
(p) => p.signature.intent_sequence?.includes(intent)
|
|
8209
|
+
);
|
|
8210
|
+
}
|
|
8211
|
+
all() {
|
|
8212
|
+
return [...this.patterns.values()];
|
|
8213
|
+
}
|
|
8214
|
+
};
|
|
8215
|
+
}
|
|
8216
|
+
});
|
|
8217
|
+
|
|
8218
|
+
// src/sensors/tps.sensor.ts
|
|
8219
|
+
var require_tps_sensor = __commonJS({
|
|
8220
|
+
"src/sensors/tps.sensor.ts"(exports2) {
|
|
8221
|
+
"use strict";
|
|
8222
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
8223
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8224
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8225
|
+
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;
|
|
8226
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8227
|
+
};
|
|
8228
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
8229
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8230
|
+
};
|
|
8231
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8232
|
+
exports2.TpsSensor = void 0;
|
|
8233
|
+
var common_1 = require("@nestjs/common");
|
|
8234
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
8235
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
8236
|
+
var TPS_EPOCH_MS = 9343548e5;
|
|
8237
|
+
function parseINotation(tps) {
|
|
8238
|
+
if (!tps.startsWith("i"))
|
|
8239
|
+
return null;
|
|
8240
|
+
const num = Number(tps.slice(1));
|
|
8241
|
+
if (!Number.isFinite(num))
|
|
8242
|
+
return null;
|
|
8243
|
+
return TPS_EPOCH_MS + num;
|
|
8244
|
+
}
|
|
8245
|
+
var TpsSensor2 = class TpsSensor {
|
|
8246
|
+
constructor(options = {}) {
|
|
8247
|
+
this.name = "TpsSensor";
|
|
8248
|
+
this.order = sensor_bands_1.BAND.POLICY + 2;
|
|
8249
|
+
this.maxDriftMs = options.maxDriftMs ?? 3e4;
|
|
8250
|
+
this.resolver = options.resolver ?? parseINotation;
|
|
8251
|
+
}
|
|
8252
|
+
supports(input) {
|
|
8253
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
8254
|
+
return typeof tps === "string" && tps.length > 0;
|
|
8255
|
+
}
|
|
8256
|
+
async run(input) {
|
|
8257
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
8258
|
+
const resolved = this.resolver(tps);
|
|
8259
|
+
if (resolved === null) {
|
|
8260
|
+
return {
|
|
8261
|
+
allow: false,
|
|
8262
|
+
riskScore: 80,
|
|
8263
|
+
reasons: [`TPS coordinate '${tps}' is structurally invalid`],
|
|
8264
|
+
code: "TPS_INVALID_FORMAT"
|
|
8265
|
+
};
|
|
8266
|
+
}
|
|
8267
|
+
const now = Date.now();
|
|
8268
|
+
const drift = Math.abs(now - resolved);
|
|
8269
|
+
if (drift > this.maxDriftMs) {
|
|
8270
|
+
const direction = resolved > now ? "future" : "past";
|
|
8271
|
+
return {
|
|
8272
|
+
allow: false,
|
|
8273
|
+
riskScore: 70,
|
|
8274
|
+
reasons: [
|
|
8275
|
+
`TPS drift ${drift}ms exceeds max ${this.maxDriftMs}ms (${direction})`
|
|
8276
|
+
],
|
|
8277
|
+
code: "TPS_DRIFT_EXCEEDED",
|
|
8278
|
+
tags: { tpsDriftMs: drift, tpsDirection: direction }
|
|
8279
|
+
};
|
|
8280
|
+
}
|
|
8281
|
+
return {
|
|
8282
|
+
allow: true,
|
|
8283
|
+
riskScore: 0,
|
|
8284
|
+
reasons: [],
|
|
8285
|
+
tags: {
|
|
8286
|
+
tpsResolved: resolved,
|
|
8287
|
+
tpsDriftMs: drift
|
|
8288
|
+
}
|
|
8289
|
+
};
|
|
8290
|
+
}
|
|
8291
|
+
};
|
|
8292
|
+
exports2.TpsSensor = TpsSensor2;
|
|
8293
|
+
exports2.TpsSensor = TpsSensor2 = __decorate([
|
|
8294
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8295
|
+
(0, common_1.Injectable)(),
|
|
8296
|
+
__metadata("design:paramtypes", [Object])
|
|
8297
|
+
], TpsSensor2);
|
|
8298
|
+
}
|
|
8299
|
+
});
|
|
8300
|
+
|
|
8301
|
+
// src/sensors/risk-gate.sensor.ts
|
|
8302
|
+
var require_risk_gate_sensor = __commonJS({
|
|
8303
|
+
"src/sensors/risk-gate.sensor.ts"(exports2) {
|
|
8304
|
+
"use strict";
|
|
8305
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
8306
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8307
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8308
|
+
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;
|
|
8309
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8310
|
+
};
|
|
8311
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
8312
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8313
|
+
};
|
|
8314
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8315
|
+
exports2.RiskGateSensor = void 0;
|
|
8316
|
+
var common_1 = require("@nestjs/common");
|
|
8317
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
8318
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
8319
|
+
var risk_1 = (init_risk(), __toCommonJS(risk_exports));
|
|
8320
|
+
var SEVERITY_WEIGHT = {
|
|
8321
|
+
low: 10,
|
|
8322
|
+
medium: 25,
|
|
8323
|
+
high: 50,
|
|
8324
|
+
critical: 100
|
|
8325
|
+
};
|
|
8326
|
+
var RiskGateSensor2 = class RiskGateSensor {
|
|
8327
|
+
constructor(options) {
|
|
8328
|
+
this.name = "RiskGateSensor";
|
|
8329
|
+
this.order = sensor_bands_1.BAND.BUSINESS + 10;
|
|
8330
|
+
this.collectors = options.collectors;
|
|
8331
|
+
this.denyThreshold = options.denyThreshold ?? 75;
|
|
8332
|
+
this.flagThreshold = options.flagThreshold ?? 40;
|
|
8333
|
+
}
|
|
8334
|
+
async run(input) {
|
|
8335
|
+
const results = await Promise.all(this.collectors.map((c) => c(input)));
|
|
8336
|
+
const signals = results.flat();
|
|
8337
|
+
let totalWeight = 0;
|
|
8338
|
+
let weightedSum = 0;
|
|
8339
|
+
for (const signal of signals) {
|
|
8340
|
+
const w = SEVERITY_WEIGHT[signal.severity];
|
|
8341
|
+
totalWeight += 1;
|
|
8342
|
+
weightedSum += w;
|
|
8343
|
+
}
|
|
8344
|
+
const aggregateScore = totalWeight > 0 ? Math.min(100, Math.round(weightedSum / totalWeight)) : 0;
|
|
8345
|
+
const evaluation = this.evaluate(aggregateScore, signals);
|
|
8346
|
+
input.metadata = {
|
|
8347
|
+
...input.metadata ?? {},
|
|
8348
|
+
riskEvaluation: evaluation
|
|
8349
|
+
};
|
|
8350
|
+
if (evaluation.decision === risk_1.RiskDecision.DENY) {
|
|
8351
|
+
return {
|
|
8352
|
+
allow: false,
|
|
8353
|
+
riskScore: aggregateScore,
|
|
8354
|
+
reasons: signals.map((s) => s.message),
|
|
8355
|
+
code: "RISK_GATE_DENY",
|
|
8356
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
8357
|
+
};
|
|
8358
|
+
}
|
|
8359
|
+
if (evaluation.decision === risk_1.RiskDecision.THROTTLE) {
|
|
8360
|
+
return {
|
|
8361
|
+
allow: false,
|
|
8362
|
+
riskScore: aggregateScore,
|
|
8363
|
+
reasons: signals.map((s) => s.message),
|
|
8364
|
+
code: "RISK_GATE_THROTTLE",
|
|
8365
|
+
retryAfterMs: evaluation.retryAfterMs,
|
|
8366
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
8367
|
+
};
|
|
8368
|
+
}
|
|
8369
|
+
return {
|
|
8370
|
+
allow: true,
|
|
8371
|
+
riskScore: aggregateScore,
|
|
8372
|
+
reasons: signals.filter((s) => s.severity === "medium" || s.severity === "high").map((s) => s.message),
|
|
8373
|
+
tags: {
|
|
8374
|
+
riskDecision: evaluation.decision,
|
|
8375
|
+
signalCount: signals.length
|
|
8376
|
+
}
|
|
8377
|
+
};
|
|
8378
|
+
}
|
|
8379
|
+
evaluate(score, signals) {
|
|
8380
|
+
const hasCritical = signals.some((s) => s.severity === "critical");
|
|
8381
|
+
if (hasCritical) {
|
|
8382
|
+
return {
|
|
8383
|
+
decision: risk_1.RiskDecision.DENY,
|
|
8384
|
+
reason: "Critical risk signal detected",
|
|
8385
|
+
confidence: 1,
|
|
8386
|
+
signals
|
|
8387
|
+
};
|
|
8388
|
+
}
|
|
8389
|
+
if (score >= this.denyThreshold) {
|
|
8390
|
+
return {
|
|
8391
|
+
decision: risk_1.RiskDecision.DENY,
|
|
8392
|
+
reason: `Aggregate risk score ${score} exceeds deny threshold ${this.denyThreshold}`,
|
|
8393
|
+
confidence: score / 100,
|
|
8394
|
+
signals
|
|
8395
|
+
};
|
|
8396
|
+
}
|
|
8397
|
+
if (score >= this.flagThreshold) {
|
|
8398
|
+
return {
|
|
8399
|
+
decision: risk_1.RiskDecision.STEP_UP,
|
|
8400
|
+
reason: `Aggregate risk score ${score} exceeds flag threshold ${this.flagThreshold}`,
|
|
8401
|
+
confidence: score / 100,
|
|
8402
|
+
signals
|
|
8403
|
+
};
|
|
8404
|
+
}
|
|
8405
|
+
return {
|
|
8406
|
+
decision: risk_1.RiskDecision.ALLOW,
|
|
8407
|
+
confidence: 1 - score / 100,
|
|
8408
|
+
signals
|
|
8409
|
+
};
|
|
8410
|
+
}
|
|
8411
|
+
};
|
|
8412
|
+
exports2.RiskGateSensor = RiskGateSensor2;
|
|
8413
|
+
exports2.RiskGateSensor = RiskGateSensor2 = __decorate([
|
|
8414
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8415
|
+
(0, common_1.Injectable)(),
|
|
8416
|
+
__metadata("design:paramtypes", [Object])
|
|
8417
|
+
], RiskGateSensor2);
|
|
8418
|
+
}
|
|
8419
|
+
});
|
|
8420
|
+
|
|
8421
|
+
// src/sensors/tickauth.sensor.ts
|
|
8422
|
+
var require_tickauth_sensor = __commonJS({
|
|
8423
|
+
"src/sensors/tickauth.sensor.ts"(exports2) {
|
|
8424
|
+
"use strict";
|
|
8425
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
8426
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8427
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8428
|
+
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;
|
|
8429
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8430
|
+
};
|
|
8431
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
8432
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8433
|
+
};
|
|
8434
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8435
|
+
exports2.TickAuthSensor = void 0;
|
|
8436
|
+
var common_1 = require("@nestjs/common");
|
|
8437
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
8438
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
8439
|
+
var TickAuthSensor2 = class TickAuthSensor {
|
|
8440
|
+
constructor(options = {}) {
|
|
8441
|
+
this.name = "TickAuthSensor";
|
|
8442
|
+
this.order = sensor_bands_1.BAND.IDENTITY + 40;
|
|
8443
|
+
this.verifier = options.verifier;
|
|
8444
|
+
this.matchIntent = options.matchIntent ?? true;
|
|
8445
|
+
this.acceptTypes = options.acceptTypes?.length ? new Set(options.acceptTypes) : null;
|
|
8446
|
+
}
|
|
8447
|
+
supports(input) {
|
|
8448
|
+
return !!(input.metadata?.capsule || input.metadata?.tickauthCapsule || input.metadata?.cceEnvelope?.capsule);
|
|
8449
|
+
}
|
|
8450
|
+
async run(input) {
|
|
8451
|
+
const capsule = input.metadata?.capsule ?? input.metadata?.tickauthCapsule ?? input.metadata?.cceEnvelope?.capsule;
|
|
8452
|
+
if (!capsule) {
|
|
8453
|
+
return {
|
|
8454
|
+
allow: false,
|
|
8455
|
+
riskScore: 90,
|
|
8456
|
+
reasons: ["TickAuth capsule not found"],
|
|
8457
|
+
code: "TICKAUTH_MISSING"
|
|
8458
|
+
};
|
|
8459
|
+
}
|
|
8460
|
+
if (!capsule.capsule_id || typeof capsule.capsule_id !== "string") {
|
|
8461
|
+
return {
|
|
8462
|
+
allow: false,
|
|
8463
|
+
riskScore: 100,
|
|
8464
|
+
reasons: ["TickAuth capsule has no valid capsule_id"],
|
|
8465
|
+
code: "TICKAUTH_INVALID_ID"
|
|
8466
|
+
};
|
|
8467
|
+
}
|
|
8468
|
+
const status = capsule.verification?.status;
|
|
8469
|
+
if (status && status !== "approved") {
|
|
8470
|
+
return {
|
|
8471
|
+
allow: false,
|
|
8472
|
+
riskScore: 100,
|
|
8473
|
+
reasons: [
|
|
8474
|
+
`TickAuth capsule status is '${status}'${capsule.verification?.reason ? `: ${capsule.verification.reason}` : ""}`
|
|
8475
|
+
],
|
|
8476
|
+
code: `TICKAUTH_STATUS_${status.toUpperCase()}`
|
|
8477
|
+
};
|
|
8478
|
+
}
|
|
8479
|
+
if (this.acceptTypes && capsule.capsule_type) {
|
|
8480
|
+
if (!this.acceptTypes.has(capsule.capsule_type)) {
|
|
8481
|
+
return {
|
|
8482
|
+
allow: false,
|
|
8483
|
+
riskScore: 80,
|
|
8484
|
+
reasons: [
|
|
8485
|
+
`TickAuth capsule type '${capsule.capsule_type}' is not in accept list`
|
|
8486
|
+
],
|
|
8487
|
+
code: "TICKAUTH_TYPE_REJECTED"
|
|
8488
|
+
};
|
|
8489
|
+
}
|
|
8490
|
+
}
|
|
8491
|
+
if (this.matchIntent && input.intent && capsule.intent) {
|
|
8492
|
+
if (capsule.intent !== input.intent) {
|
|
8493
|
+
return {
|
|
8494
|
+
allow: false,
|
|
8495
|
+
riskScore: 80,
|
|
8496
|
+
reasons: [
|
|
8497
|
+
`TickAuth capsule intent '${capsule.intent}' does not match AXIS intent '${input.intent}'`
|
|
8498
|
+
],
|
|
8499
|
+
code: "TICKAUTH_INTENT_MISMATCH"
|
|
8500
|
+
};
|
|
8501
|
+
}
|
|
8502
|
+
}
|
|
8503
|
+
if (this.verifier) {
|
|
8504
|
+
const error = await this.verifier(capsule, input);
|
|
8505
|
+
if (error) {
|
|
8506
|
+
return {
|
|
8507
|
+
allow: false,
|
|
8508
|
+
riskScore: 90,
|
|
8509
|
+
reasons: [`TickAuth verification failed: ${error}`],
|
|
8510
|
+
code: "TICKAUTH_VERIFY_FAILED"
|
|
8511
|
+
};
|
|
8512
|
+
}
|
|
8513
|
+
}
|
|
8514
|
+
return {
|
|
8515
|
+
allow: true,
|
|
8516
|
+
riskScore: 0,
|
|
8517
|
+
reasons: [],
|
|
8518
|
+
tags: {
|
|
8519
|
+
tickauthCapsuleId: capsule.capsule_id,
|
|
8520
|
+
tickauthMode: capsule.mode,
|
|
8521
|
+
tickauthSingleUse: capsule.single_use
|
|
8522
|
+
}
|
|
8523
|
+
};
|
|
8524
|
+
}
|
|
8525
|
+
};
|
|
8526
|
+
exports2.TickAuthSensor = TickAuthSensor2;
|
|
8527
|
+
exports2.TickAuthSensor = TickAuthSensor2 = __decorate([
|
|
8528
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
8529
|
+
(0, common_1.Injectable)(),
|
|
8530
|
+
__metadata("design:paramtypes", [Object])
|
|
8531
|
+
], TickAuthSensor2);
|
|
6194
8532
|
}
|
|
6195
8533
|
});
|
|
6196
8534
|
|
|
@@ -7002,95 +9340,18 @@ var init_cce = __esm({
|
|
|
7002
9340
|
// src/core/index.ts
|
|
7003
9341
|
var core_exports = {};
|
|
7004
9342
|
__export(core_exports, {
|
|
7005
|
-
AXIS_MAGIC: () => import_axis_protocol2.AXIS_MAGIC,
|
|
7006
|
-
AXIS_VERSION: () => import_axis_protocol2.AXIS_VERSION,
|
|
7007
9343
|
AxisError: () => AxisError,
|
|
7008
9344
|
AxisFrameZ: () => AxisFrameZ,
|
|
7009
|
-
AxisMediaTypes: () => AxisMediaTypes,
|
|
7010
|
-
BodyProfile: () => import_axis_protocol2.BodyProfile,
|
|
7011
|
-
ERR_BAD_SIGNATURE: () => import_axis_protocol2.ERR_BAD_SIGNATURE,
|
|
7012
|
-
ERR_CONTRACT_VIOLATION: () => import_axis_protocol2.ERR_CONTRACT_VIOLATION,
|
|
7013
|
-
ERR_INVALID_PACKET: () => import_axis_protocol2.ERR_INVALID_PACKET,
|
|
7014
|
-
ERR_REPLAY_DETECTED: () => import_axis_protocol2.ERR_REPLAY_DETECTED,
|
|
7015
|
-
FLAG_BODY_TLV: () => import_axis_protocol2.FLAG_BODY_TLV,
|
|
7016
|
-
FLAG_CHAIN_REQ: () => import_axis_protocol2.FLAG_CHAIN_REQ,
|
|
7017
|
-
FLAG_HAS_WITNESS: () => import_axis_protocol2.FLAG_HAS_WITNESS,
|
|
7018
|
-
MAX_BODY_LEN: () => import_axis_protocol2.MAX_BODY_LEN,
|
|
7019
|
-
MAX_FRAME_LEN: () => import_axis_protocol2.MAX_FRAME_LEN,
|
|
7020
|
-
MAX_HDR_LEN: () => import_axis_protocol2.MAX_HDR_LEN,
|
|
7021
|
-
MAX_SIG_LEN: () => import_axis_protocol2.MAX_SIG_LEN,
|
|
7022
|
-
NCERT_ALG: () => import_axis_protocol2.NCERT_ALG,
|
|
7023
|
-
NCERT_EXP: () => import_axis_protocol2.NCERT_EXP,
|
|
7024
|
-
NCERT_ISSUER_KID: () => import_axis_protocol2.NCERT_ISSUER_KID,
|
|
7025
|
-
NCERT_KID: () => import_axis_protocol2.NCERT_KID,
|
|
7026
|
-
NCERT_NBF: () => import_axis_protocol2.NCERT_NBF,
|
|
7027
|
-
NCERT_NODE_ID: () => import_axis_protocol2.NCERT_NODE_ID,
|
|
7028
|
-
NCERT_PAYLOAD: () => import_axis_protocol2.NCERT_PAYLOAD,
|
|
7029
|
-
NCERT_PUB: () => import_axis_protocol2.NCERT_PUB,
|
|
7030
|
-
NCERT_SCOPE: () => import_axis_protocol2.NCERT_SCOPE,
|
|
7031
|
-
NCERT_SIG: () => import_axis_protocol2.NCERT_SIG,
|
|
7032
|
-
PROOF_CAPSULE: () => import_axis_protocol2.PROOF_CAPSULE,
|
|
7033
|
-
PROOF_JWT: () => import_axis_protocol2.PROOF_JWT,
|
|
7034
|
-
PROOF_LOOM: () => import_axis_protocol2.PROOF_LOOM,
|
|
7035
|
-
PROOF_MTLS: () => import_axis_protocol2.PROOF_MTLS,
|
|
7036
|
-
PROOF_NONE: () => import_axis_protocol2.PROOF_NONE,
|
|
7037
|
-
PROOF_WITNESS: () => import_axis_protocol2.PROOF_WITNESS,
|
|
7038
|
-
ProofType: () => import_axis_protocol2.ProofType,
|
|
7039
|
-
TLV: () => import_axis_protocol.TLV,
|
|
7040
|
-
TLV_ACTOR_ID: () => import_axis_protocol2.TLV_ACTOR_ID,
|
|
7041
|
-
TLV_AUD: () => import_axis_protocol2.TLV_AUD,
|
|
7042
|
-
TLV_BODY_ARR: () => import_axis_protocol2.TLV_BODY_ARR,
|
|
7043
|
-
TLV_BODY_OBJ: () => import_axis_protocol2.TLV_BODY_OBJ,
|
|
7044
|
-
TLV_CAPSULE: () => import_axis_protocol2.TLV_CAPSULE,
|
|
7045
|
-
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
7046
|
-
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
7047
|
-
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
7048
|
-
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
7049
|
-
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
7050
|
-
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
7051
|
-
TLV_LOOM_PRESENCE_ID: () => import_axis_protocol2.TLV_LOOM_PRESENCE_ID,
|
|
7052
|
-
TLV_LOOM_THREAD_HASH: () => import_axis_protocol2.TLV_LOOM_THREAD_HASH,
|
|
7053
|
-
TLV_LOOM_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
7054
|
-
TLV_NODE: () => import_axis_protocol2.TLV_NODE,
|
|
7055
|
-
TLV_NODE_CERT_HASH: () => import_axis_protocol2.TLV_NODE_CERT_HASH,
|
|
7056
|
-
TLV_NODE_KID: () => import_axis_protocol2.TLV_NODE_KID,
|
|
7057
|
-
TLV_NONCE: () => import_axis_protocol2.TLV_NONCE,
|
|
7058
|
-
TLV_OFFSET: () => import_axis_protocol2.TLV_OFFSET,
|
|
7059
|
-
TLV_OK: () => import_axis_protocol2.TLV_OK,
|
|
7060
|
-
TLV_PID: () => import_axis_protocol2.TLV_PID,
|
|
7061
|
-
TLV_PREV_HASH: () => import_axis_protocol2.TLV_PREV_HASH,
|
|
7062
|
-
TLV_PROOF_REF: () => import_axis_protocol2.TLV_PROOF_REF,
|
|
7063
|
-
TLV_PROOF_TYPE: () => import_axis_protocol2.TLV_PROOF_TYPE,
|
|
7064
|
-
TLV_REALM: () => import_axis_protocol2.TLV_REALM,
|
|
7065
|
-
TLV_RECEIPT_HASH: () => import_axis_protocol2.TLV_RECEIPT_HASH,
|
|
7066
|
-
TLV_RID: () => import_axis_protocol2.TLV_RID,
|
|
7067
|
-
TLV_SHA256_CHUNK: () => import_axis_protocol2.TLV_SHA256_CHUNK,
|
|
7068
|
-
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
7069
|
-
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
7070
|
-
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
7071
9345
|
computeReceiptHash: () => computeReceiptHash,
|
|
7072
9346
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
7073
|
-
decodeArray: () => import_axis_protocol.decodeArray,
|
|
7074
|
-
decodeFrame: () => decodeFrame,
|
|
7075
|
-
decodeObject: () => import_axis_protocol.decodeObject,
|
|
7076
|
-
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
7077
|
-
decodeTLVsList: () => import_axis_protocol.decodeTLVsList,
|
|
7078
|
-
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
7079
|
-
encodeFrame: () => encodeFrame,
|
|
7080
|
-
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
7081
|
-
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
7082
9347
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
7083
|
-
getSignTarget: () => getSignTarget,
|
|
7084
9348
|
sha256: () => sha2564,
|
|
7085
9349
|
signFrame: () => signFrame,
|
|
7086
|
-
varintLength: () => import_axis_protocol3.varintLength,
|
|
7087
9350
|
verifyFrameSignature: () => verifyFrameSignature
|
|
7088
9351
|
});
|
|
7089
9352
|
var init_core = __esm({
|
|
7090
9353
|
"src/core/index.ts"() {
|
|
7091
|
-
|
|
7092
|
-
init_varint();
|
|
7093
|
-
init_tlv();
|
|
9354
|
+
__reExport(core_exports, require("@nextera.one/axis-protocol"));
|
|
7094
9355
|
init_axis_bin();
|
|
7095
9356
|
init_signature();
|
|
7096
9357
|
init_axis_error();
|
|
@@ -7291,8 +9552,10 @@ var init_crypto = __esm({
|
|
|
7291
9552
|
var decorators_exports = {};
|
|
7292
9553
|
__export(decorators_exports, {
|
|
7293
9554
|
AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
|
|
9555
|
+
AXIS_META_KEY: () => AXIS_META_KEY,
|
|
7294
9556
|
AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
|
|
7295
9557
|
AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
|
|
9558
|
+
Axis: () => Axis,
|
|
7296
9559
|
AxisAnonymous: () => AxisAnonymous,
|
|
7297
9560
|
AxisPublic: () => AxisPublic,
|
|
7298
9561
|
AxisRateLimit: () => AxisRateLimit,
|
|
@@ -7321,14 +9584,6 @@ __export(decorators_exports, {
|
|
|
7321
9584
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
7322
9585
|
Sensitivity: () => Sensitivity,
|
|
7323
9586
|
Sensor: () => Sensor,
|
|
7324
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
7325
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
7326
|
-
TlvEnum: () => TlvEnum,
|
|
7327
|
-
TlvField: () => TlvField,
|
|
7328
|
-
TlvMinLen: () => TlvMinLen,
|
|
7329
|
-
TlvRange: () => TlvRange,
|
|
7330
|
-
TlvUtf8Pattern: () => TlvUtf8Pattern,
|
|
7331
|
-
TlvValidate: () => TlvValidate,
|
|
7332
9587
|
Witness: () => Witness,
|
|
7333
9588
|
mergeCapsulePolicyOptions: () => mergeCapsulePolicyOptions,
|
|
7334
9589
|
normalizeCapsulePolicyOptions: () => normalizeCapsulePolicyOptions
|
|
@@ -7346,7 +9601,7 @@ var init_decorators = __esm({
|
|
|
7346
9601
|
init_intent_decorator();
|
|
7347
9602
|
init_observer_decorator();
|
|
7348
9603
|
init_sensor_decorator();
|
|
7349
|
-
|
|
9604
|
+
__reExport(decorators_exports, __toESM(require_tlv_field_decorator()));
|
|
7350
9605
|
}
|
|
7351
9606
|
});
|
|
7352
9607
|
|
|
@@ -7447,6 +9702,25 @@ var init_engine = __esm({
|
|
|
7447
9702
|
}
|
|
7448
9703
|
});
|
|
7449
9704
|
|
|
9705
|
+
// src/idel/idel.types.ts
|
|
9706
|
+
var init_idel_types = __esm({
|
|
9707
|
+
"src/idel/idel.types.ts"() {
|
|
9708
|
+
}
|
|
9709
|
+
});
|
|
9710
|
+
|
|
9711
|
+
// src/idel/index.ts
|
|
9712
|
+
var idel_exports = {};
|
|
9713
|
+
__export(idel_exports, {
|
|
9714
|
+
IdelCompiler: () => IdelCompiler,
|
|
9715
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry
|
|
9716
|
+
});
|
|
9717
|
+
var init_idel = __esm({
|
|
9718
|
+
"src/idel/index.ts"() {
|
|
9719
|
+
init_idel_types();
|
|
9720
|
+
init_idel_compiler();
|
|
9721
|
+
}
|
|
9722
|
+
});
|
|
9723
|
+
|
|
7450
9724
|
// src/loom/index.ts
|
|
7451
9725
|
var loom_exports = {};
|
|
7452
9726
|
__export(loom_exports, {
|
|
@@ -7456,11 +9730,98 @@ __export(loom_exports, {
|
|
|
7456
9730
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
7457
9731
|
canonicalizeGrant: () => canonicalizeGrant,
|
|
7458
9732
|
canonicalizeWrit: () => canonicalizeWrit,
|
|
7459
|
-
|
|
9733
|
+
createGrant: () => createGrant,
|
|
9734
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
9735
|
+
createReceipt: () => createReceipt,
|
|
9736
|
+
createRevocation: () => createRevocation,
|
|
9737
|
+
createWrit: () => createWrit,
|
|
9738
|
+
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
9739
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
9740
|
+
getGrantStatus: () => getGrantStatus,
|
|
9741
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
9742
|
+
grantCoversAction: () => grantCoversAction,
|
|
9743
|
+
isRevoked: () => isRevoked,
|
|
9744
|
+
renewPresence: () => renewPresence,
|
|
9745
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
9746
|
+
updateThreadState: () => updateThreadState,
|
|
9747
|
+
validateGrant: () => validateGrant,
|
|
9748
|
+
validateWrit: () => validateWrit,
|
|
9749
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
9750
|
+
verifyReceiptChain: () => verifyReceiptChain
|
|
7460
9751
|
});
|
|
7461
9752
|
var init_loom = __esm({
|
|
7462
9753
|
"src/loom/index.ts"() {
|
|
7463
9754
|
init_loom_types();
|
|
9755
|
+
init_loom_engine();
|
|
9756
|
+
}
|
|
9757
|
+
});
|
|
9758
|
+
|
|
9759
|
+
// src/needle/needle.types.ts
|
|
9760
|
+
var init_needle_types = __esm({
|
|
9761
|
+
"src/needle/needle.types.ts"() {
|
|
9762
|
+
}
|
|
9763
|
+
});
|
|
9764
|
+
|
|
9765
|
+
// src/needle/knot.types.ts
|
|
9766
|
+
var init_knot_types = __esm({
|
|
9767
|
+
"src/needle/knot.types.ts"() {
|
|
9768
|
+
}
|
|
9769
|
+
});
|
|
9770
|
+
|
|
9771
|
+
// src/needle/fabric.types.ts
|
|
9772
|
+
var init_fabric_types = __esm({
|
|
9773
|
+
"src/needle/fabric.types.ts"() {
|
|
9774
|
+
}
|
|
9775
|
+
});
|
|
9776
|
+
|
|
9777
|
+
// src/needle/pattern.types.ts
|
|
9778
|
+
var init_pattern_types = __esm({
|
|
9779
|
+
"src/needle/pattern.types.ts"() {
|
|
9780
|
+
}
|
|
9781
|
+
});
|
|
9782
|
+
|
|
9783
|
+
// src/needle/index.ts
|
|
9784
|
+
var needle_exports = {};
|
|
9785
|
+
__export(needle_exports, {
|
|
9786
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
9787
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
9788
|
+
applyStitch: () => applyStitch,
|
|
9789
|
+
assembleNeedle: () => assembleNeedle,
|
|
9790
|
+
breakKnot: () => breakKnot,
|
|
9791
|
+
createFabric: () => createFabric,
|
|
9792
|
+
detectAnomalies: () => detectAnomalies,
|
|
9793
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
9794
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
9795
|
+
diffFabrics: () => diffFabrics,
|
|
9796
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
9797
|
+
forkFromKnot: () => forkFromKnot,
|
|
9798
|
+
formStitch: () => formStitch,
|
|
9799
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
9800
|
+
getFabricValue: () => getFabricValue,
|
|
9801
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
9802
|
+
isKnotOpen: () => isKnotOpen,
|
|
9803
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
9804
|
+
lockCells: () => lockCells,
|
|
9805
|
+
matchPatterns: () => matchPatterns,
|
|
9806
|
+
openKnot: () => openKnot,
|
|
9807
|
+
projectAt: () => projectAt,
|
|
9808
|
+
queryFabric: () => queryFabric,
|
|
9809
|
+
recordOccurrence: () => recordOccurrence,
|
|
9810
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
9811
|
+
tieKnot: () => tieKnot,
|
|
9812
|
+
validateKnot: () => validateKnot,
|
|
9813
|
+
weave: () => weave
|
|
9814
|
+
});
|
|
9815
|
+
var init_needle = __esm({
|
|
9816
|
+
"src/needle/index.ts"() {
|
|
9817
|
+
init_needle_types();
|
|
9818
|
+
init_needle_engine();
|
|
9819
|
+
init_knot_types();
|
|
9820
|
+
init_knot_engine();
|
|
9821
|
+
init_fabric_types();
|
|
9822
|
+
init_fabric_engine();
|
|
9823
|
+
init_pattern_types();
|
|
9824
|
+
init_pattern_engine();
|
|
7464
9825
|
}
|
|
7465
9826
|
});
|
|
7466
9827
|
|
|
@@ -8709,6 +11070,143 @@ var require_intent_registry_sensor = __commonJS({
|
|
|
8709
11070
|
}
|
|
8710
11071
|
});
|
|
8711
11072
|
|
|
11073
|
+
// src/sensors/law-evaluation.sensor.ts
|
|
11074
|
+
var require_law_evaluation_sensor = __commonJS({
|
|
11075
|
+
"src/sensors/law-evaluation.sensor.ts"(exports2) {
|
|
11076
|
+
"use strict";
|
|
11077
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
11078
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11079
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11080
|
+
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;
|
|
11081
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11082
|
+
};
|
|
11083
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
11084
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11085
|
+
};
|
|
11086
|
+
var LawEvaluationSensor_1;
|
|
11087
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
11088
|
+
exports2.LawEvaluationSensor = void 0;
|
|
11089
|
+
var common_1 = require("@nestjs/common");
|
|
11090
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
11091
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
11092
|
+
var law_1 = (init_law(), __toCommonJS(law_exports));
|
|
11093
|
+
var LawEvaluationSensor = LawEvaluationSensor_1 = class LawEvaluationSensor {
|
|
11094
|
+
constructor(options = {}) {
|
|
11095
|
+
this.options = options;
|
|
11096
|
+
this.logger = new common_1.Logger(LawEvaluationSensor_1.name);
|
|
11097
|
+
this.name = "LawEvaluationSensor";
|
|
11098
|
+
this.order = sensor_bands_1.BAND.POLICY + 5;
|
|
11099
|
+
}
|
|
11100
|
+
supports(input) {
|
|
11101
|
+
return !!this.options.evaluator && !!input.intent;
|
|
11102
|
+
}
|
|
11103
|
+
async run(input) {
|
|
11104
|
+
const evaluator = this.options.evaluator;
|
|
11105
|
+
if (!evaluator) {
|
|
11106
|
+
return { action: "ALLOW" };
|
|
11107
|
+
}
|
|
11108
|
+
const context = (0, law_1.buildAxisLawEvaluationContext)(input);
|
|
11109
|
+
let result;
|
|
11110
|
+
try {
|
|
11111
|
+
result = await evaluator(context);
|
|
11112
|
+
} catch (error) {
|
|
11113
|
+
const message = error instanceof Error ? error.message : "Unknown law evaluation error";
|
|
11114
|
+
this.logger.error(`Law evaluation failed for ${input.intent}: ${message}`);
|
|
11115
|
+
input.metadata = {
|
|
11116
|
+
...input.metadata ?? {},
|
|
11117
|
+
lawEvaluation: {
|
|
11118
|
+
decision: "deny",
|
|
11119
|
+
reason: "Law evaluation failed",
|
|
11120
|
+
explanation: message
|
|
11121
|
+
}
|
|
11122
|
+
};
|
|
11123
|
+
return {
|
|
11124
|
+
action: "DENY",
|
|
11125
|
+
code: "LAW_EVALUATION_ERROR",
|
|
11126
|
+
reason: message,
|
|
11127
|
+
meta: { lawDecision: "deny" }
|
|
11128
|
+
};
|
|
11129
|
+
}
|
|
11130
|
+
input.metadata = {
|
|
11131
|
+
...input.metadata ?? {},
|
|
11132
|
+
lawEvaluation: {
|
|
11133
|
+
...result,
|
|
11134
|
+
context: sanitizeLawContext(context)
|
|
11135
|
+
}
|
|
11136
|
+
};
|
|
11137
|
+
if (result.decision === "allow") {
|
|
11138
|
+
return {
|
|
11139
|
+
allow: true,
|
|
11140
|
+
riskScore: 0,
|
|
11141
|
+
reasons: result.reason ? [result.reason] : [],
|
|
11142
|
+
tags: {
|
|
11143
|
+
lawDecision: "allow",
|
|
11144
|
+
...result.applicable ? { lawApplicableArticles: result.applicable.length } : {}
|
|
11145
|
+
},
|
|
11146
|
+
meta: result
|
|
11147
|
+
};
|
|
11148
|
+
}
|
|
11149
|
+
if (result.decision === "conditional") {
|
|
11150
|
+
const mode = this.options.conditionalDecision ?? "deny";
|
|
11151
|
+
const reasons = [result.reason, result.explanation].filter(Boolean);
|
|
11152
|
+
if (mode === "allow") {
|
|
11153
|
+
return {
|
|
11154
|
+
allow: true,
|
|
11155
|
+
riskScore: 0,
|
|
11156
|
+
reasons,
|
|
11157
|
+
tags: {
|
|
11158
|
+
lawDecision: "conditional"
|
|
11159
|
+
},
|
|
11160
|
+
meta: result
|
|
11161
|
+
};
|
|
11162
|
+
}
|
|
11163
|
+
if (mode === "flag") {
|
|
11164
|
+
return {
|
|
11165
|
+
action: "FLAG",
|
|
11166
|
+
scoreDelta: 25,
|
|
11167
|
+
reasons: reasons.length > 0 ? reasons : ["Execution is conditionally permitted pending additional requirements"],
|
|
11168
|
+
meta: result
|
|
11169
|
+
};
|
|
11170
|
+
}
|
|
11171
|
+
return {
|
|
11172
|
+
action: "DENY",
|
|
11173
|
+
code: "LAW_CONDITIONAL",
|
|
11174
|
+
reason: reasons.join(" | ") || "Execution is conditionally permitted pending additional requirements",
|
|
11175
|
+
meta: { lawDecision: "conditional", evaluation: result }
|
|
11176
|
+
};
|
|
11177
|
+
}
|
|
11178
|
+
return {
|
|
11179
|
+
action: "DENY",
|
|
11180
|
+
code: "LAW_DENIED",
|
|
11181
|
+
reason: [result.reason, result.explanation].filter(Boolean).join(" | ") || "Execution denied by law evaluation",
|
|
11182
|
+
meta: { lawDecision: "deny", evaluation: result }
|
|
11183
|
+
};
|
|
11184
|
+
}
|
|
11185
|
+
};
|
|
11186
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor;
|
|
11187
|
+
exports2.LawEvaluationSensor = LawEvaluationSensor = LawEvaluationSensor_1 = __decorate([
|
|
11188
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
11189
|
+
(0, common_1.Injectable)(),
|
|
11190
|
+
__metadata("design:paramtypes", [Object])
|
|
11191
|
+
], LawEvaluationSensor);
|
|
11192
|
+
function sanitizeLawContext(context) {
|
|
11193
|
+
return {
|
|
11194
|
+
actorId: context.actorId,
|
|
11195
|
+
intent: context.intent,
|
|
11196
|
+
audience: context.audience,
|
|
11197
|
+
tps: context.tps,
|
|
11198
|
+
country: context.country,
|
|
11199
|
+
ip: context.ip,
|
|
11200
|
+
path: context.path,
|
|
11201
|
+
clientId: context.clientId,
|
|
11202
|
+
deviceId: context.deviceId,
|
|
11203
|
+
sessionId: context.sessionId,
|
|
11204
|
+
capsuleId: context.capsuleId
|
|
11205
|
+
};
|
|
11206
|
+
}
|
|
11207
|
+
}
|
|
11208
|
+
});
|
|
11209
|
+
|
|
8712
11210
|
// src/sensors/proof-presence.sensor.ts
|
|
8713
11211
|
var require_proof_presence_sensor = __commonJS({
|
|
8714
11212
|
"src/sensors/proof-presence.sensor.ts"(exports2) {
|
|
@@ -9411,16 +11909,40 @@ var init_sensors2 = __esm({
|
|
|
9411
11909
|
__reExport(sensors_exports, __toESM(require_header_tlv_limit_sensor()));
|
|
9412
11910
|
__reExport(sensors_exports, __toESM(require_intent_allowlist_sensor()));
|
|
9413
11911
|
__reExport(sensors_exports, __toESM(require_intent_registry_sensor()));
|
|
11912
|
+
__reExport(sensors_exports, __toESM(require_law_evaluation_sensor()));
|
|
9414
11913
|
__reExport(sensors_exports, __toESM(require_proof_presence_sensor()));
|
|
9415
11914
|
__reExport(sensors_exports, __toESM(require_protocol_strict_sensor()));
|
|
9416
11915
|
__reExport(sensors_exports, __toESM(require_receipt_policy_sensor()));
|
|
11916
|
+
__reExport(sensors_exports, __toESM(require_risk_gate_sensor()));
|
|
9417
11917
|
__reExport(sensors_exports, __toESM(require_schema_validation_sensor()));
|
|
9418
11918
|
__reExport(sensors_exports, __toESM(require_stream_scope_sensor()));
|
|
11919
|
+
__reExport(sensors_exports, __toESM(require_tickauth_sensor()));
|
|
9419
11920
|
__reExport(sensors_exports, __toESM(require_tlv_parse_sensor()));
|
|
11921
|
+
__reExport(sensors_exports, __toESM(require_tps_sensor()));
|
|
9420
11922
|
__reExport(sensors_exports, __toESM(require_varint_hardening_sensor()));
|
|
9421
11923
|
}
|
|
9422
11924
|
});
|
|
9423
11925
|
|
|
11926
|
+
// src/timeline/timeline.types.ts
|
|
11927
|
+
var init_timeline_types = __esm({
|
|
11928
|
+
"src/timeline/timeline.types.ts"() {
|
|
11929
|
+
}
|
|
11930
|
+
});
|
|
11931
|
+
|
|
11932
|
+
// src/timeline/index.ts
|
|
11933
|
+
var timeline_exports = {};
|
|
11934
|
+
__export(timeline_exports, {
|
|
11935
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
11936
|
+
TimelineEngine: () => TimelineEngine
|
|
11937
|
+
});
|
|
11938
|
+
var init_timeline = __esm({
|
|
11939
|
+
"src/timeline/index.ts"() {
|
|
11940
|
+
init_timeline_types();
|
|
11941
|
+
init_timeline_store();
|
|
11942
|
+
init_timeline_engine();
|
|
11943
|
+
}
|
|
11944
|
+
});
|
|
11945
|
+
|
|
9424
11946
|
// src/utils/index.ts
|
|
9425
11947
|
var utils_exports = {};
|
|
9426
11948
|
__export(utils_exports, {
|
|
@@ -9440,6 +11962,7 @@ __export(index_exports, {
|
|
|
9440
11962
|
AXIS_ANONYMOUS_KEY: () => AXIS_ANONYMOUS_KEY,
|
|
9441
11963
|
AXIS_EXECUTION_CONTEXT_KEY: () => AXIS_EXECUTION_CONTEXT_KEY,
|
|
9442
11964
|
AXIS_MAGIC: () => import_axis_protocol2.AXIS_MAGIC,
|
|
11965
|
+
AXIS_META_KEY: () => AXIS_META_KEY,
|
|
9443
11966
|
AXIS_OPCODES: () => AXIS_OPCODES,
|
|
9444
11967
|
AXIS_PUBLIC_KEY: () => AXIS_PUBLIC_KEY,
|
|
9445
11968
|
AXIS_RATE_LIMIT_KEY: () => AXIS_RATE_LIMIT_KEY,
|
|
@@ -9448,6 +11971,7 @@ __export(index_exports, {
|
|
|
9448
11971
|
AXIS_UPLOAD_SESSION_STORE: () => AXIS_UPLOAD_SESSION_STORE,
|
|
9449
11972
|
AXIS_VERSION: () => import_axis_protocol2.AXIS_VERSION,
|
|
9450
11973
|
Ats1Codec: () => ats1_exports,
|
|
11974
|
+
Axis: () => Axis,
|
|
9451
11975
|
AxisAnonymous: () => AxisAnonymous,
|
|
9452
11976
|
AxisChainExecutor: () => import_axis_chain.AxisChainExecutor,
|
|
9453
11977
|
AxisContext: () => import_axis_request.AxisContext,
|
|
@@ -9507,6 +12031,10 @@ __export(index_exports, {
|
|
|
9507
12031
|
INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
|
|
9508
12032
|
INTENT_SENSORS_KEY: () => INTENT_SENSORS_KEY,
|
|
9509
12033
|
INTENT_TIMEOUTS: () => INTENT_TIMEOUTS,
|
|
12034
|
+
IdelCompiler: () => IdelCompiler,
|
|
12035
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry,
|
|
12036
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
12037
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
9510
12038
|
Intent: () => Intent,
|
|
9511
12039
|
IntentBody: () => IntentBody,
|
|
9512
12040
|
IntentRouter: () => import_intent2.IntentRouter,
|
|
@@ -9550,6 +12078,7 @@ __export(index_exports, {
|
|
|
9550
12078
|
RequiredProof: () => RequiredProof,
|
|
9551
12079
|
ResponseObserver: () => ResponseObserver,
|
|
9552
12080
|
RiskDecision: () => RiskDecision,
|
|
12081
|
+
RiskGateSensor: () => import_risk_gate.RiskGateSensor,
|
|
9553
12082
|
SENSITIVITY_METADATA_KEY: () => SENSITIVITY_METADATA_KEY,
|
|
9554
12083
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
9555
12084
|
Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
|
|
@@ -9570,7 +12099,7 @@ __export(index_exports, {
|
|
|
9570
12099
|
TLV_EFFECT: () => import_axis_protocol2.TLV_EFFECT,
|
|
9571
12100
|
TLV_ERROR_CODE: () => import_axis_protocol2.TLV_ERROR_CODE,
|
|
9572
12101
|
TLV_ERROR_MSG: () => import_axis_protocol2.TLV_ERROR_MSG,
|
|
9573
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
12102
|
+
TLV_FIELDS_KEY: () => import_tlv_field2.TLV_FIELDS_KEY,
|
|
9574
12103
|
TLV_INDEX: () => import_axis_protocol2.TLV_INDEX,
|
|
9575
12104
|
TLV_INTENT: () => import_axis_protocol2.TLV_INTENT,
|
|
9576
12105
|
TLV_KID: () => import_axis_protocol2.TLV_KID,
|
|
@@ -9596,21 +12125,29 @@ __export(index_exports, {
|
|
|
9596
12125
|
TLV_TRACE_ID: () => import_axis_protocol2.TLV_TRACE_ID,
|
|
9597
12126
|
TLV_TS: () => import_axis_protocol2.TLV_TS,
|
|
9598
12127
|
TLV_UPLOAD_ID: () => import_axis_protocol2.TLV_UPLOAD_ID,
|
|
9599
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
12128
|
+
TLV_VALIDATORS_KEY: () => import_tlv_field2.TLV_VALIDATORS_KEY,
|
|
9600
12129
|
TLV_WRIT: () => import_axis_protocol2.TLV_LOOM_WRIT,
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
12130
|
+
TickAuthSensor: () => import_tickauth.TickAuthSensor,
|
|
12131
|
+
TimelineEngine: () => TimelineEngine,
|
|
12132
|
+
TlvEnum: () => import_tlv_field2.TlvEnum,
|
|
12133
|
+
TlvField: () => import_tlv_field2.TlvField,
|
|
12134
|
+
TlvMinLen: () => import_tlv_field2.TlvMinLen,
|
|
12135
|
+
TlvRange: () => import_tlv_field2.TlvRange,
|
|
12136
|
+
TlvUtf8Pattern: () => import_tlv_field2.TlvUtf8Pattern,
|
|
12137
|
+
TlvValidate: () => import_tlv_field2.TlvValidate,
|
|
12138
|
+
TpsSensor: () => import_tps.TpsSensor,
|
|
9607
12139
|
Witness: () => Witness,
|
|
12140
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
12141
|
+
applyStitch: () => applyStitch,
|
|
12142
|
+
assembleNeedle: () => assembleNeedle,
|
|
9608
12143
|
axis1SigningBytes: () => axis1SigningBytes,
|
|
9609
12144
|
b64urlDecode: () => b64urlDecode,
|
|
9610
12145
|
b64urlDecodeString: () => b64urlDecodeString,
|
|
9611
12146
|
b64urlEncode: () => b64urlEncode,
|
|
9612
12147
|
b64urlEncodeString: () => b64urlEncodeString,
|
|
12148
|
+
breakKnot: () => breakKnot,
|
|
9613
12149
|
buildAts1Hdr: () => buildAts1Hdr,
|
|
12150
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext,
|
|
9614
12151
|
buildDtoDecoder: () => import_dto_schema.buildDtoDecoder,
|
|
9615
12152
|
buildPacket: () => buildPacket,
|
|
9616
12153
|
buildQueueMessage: () => buildQueueMessage,
|
|
@@ -9629,11 +12166,17 @@ __export(index_exports, {
|
|
|
9629
12166
|
computeReceiptHash: () => computeReceiptHash,
|
|
9630
12167
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
9631
12168
|
core: () => core_exports,
|
|
12169
|
+
createFabric: () => createFabric,
|
|
12170
|
+
createGrant: () => createGrant,
|
|
9632
12171
|
createObservation: () => createObservation,
|
|
12172
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
12173
|
+
createReceipt: () => createReceipt,
|
|
12174
|
+
createRevocation: () => createRevocation,
|
|
12175
|
+
createWrit: () => createWrit,
|
|
9633
12176
|
crypto: () => crypto_exports,
|
|
9634
12177
|
decodeArray: () => import_axis_protocol.decodeArray,
|
|
9635
12178
|
decodeAxis1Frame: () => decodeAxis1Frame,
|
|
9636
|
-
decodeFrame: () => decodeFrame,
|
|
12179
|
+
decodeFrame: () => import_axis_protocol4.decodeFrame,
|
|
9637
12180
|
decodeObject: () => import_axis_protocol.decodeObject,
|
|
9638
12181
|
decodeQueueMessage: () => decodeQueueMessage,
|
|
9639
12182
|
decodeTLVs: () => import_axis_protocol.decodeTLVs,
|
|
@@ -9641,30 +12184,52 @@ __export(index_exports, {
|
|
|
9641
12184
|
decodeVarint: () => import_axis_protocol3.decodeVarint,
|
|
9642
12185
|
decorators: () => decorators_exports,
|
|
9643
12186
|
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
12187
|
+
detectAnomalies: () => detectAnomalies,
|
|
12188
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
12189
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
12190
|
+
diffFabrics: () => diffFabrics,
|
|
9644
12191
|
encVarint: () => encVarint,
|
|
9645
12192
|
encodeAxis1Frame: () => encodeAxis1Frame,
|
|
9646
12193
|
encodeAxisTlvDto: () => encodeAxisTlvDto,
|
|
9647
|
-
encodeFrame: () => encodeFrame,
|
|
12194
|
+
encodeFrame: () => import_axis_protocol4.encodeFrame,
|
|
9648
12195
|
encodeQueueMessage: () => encodeQueueMessage,
|
|
9649
12196
|
encodeTLVs: () => import_axis_protocol.encodeTLVs,
|
|
9650
12197
|
encodeVarint: () => import_axis_protocol3.encodeVarint,
|
|
9651
12198
|
endStage: () => endStage,
|
|
9652
12199
|
engine: () => engine_exports,
|
|
9653
12200
|
executeCcePipeline: () => executeCcePipeline,
|
|
12201
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
9654
12202
|
extractDtoSchema: () => import_dto_schema.extractDtoSchema,
|
|
9655
12203
|
finalizeObservation: () => finalizeObservation,
|
|
12204
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
12205
|
+
forkFromKnot: () => forkFromKnot,
|
|
12206
|
+
formStitch: () => formStitch,
|
|
9656
12207
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
9657
12208
|
getAxisExecutionContext: () => getAxisExecutionContext,
|
|
9658
|
-
|
|
12209
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
12210
|
+
getFabricValue: () => getFabricValue,
|
|
12211
|
+
getGrantStatus: () => getGrantStatus,
|
|
12212
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
12213
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
12214
|
+
getSignTarget: () => import_axis_protocol4.getSignTarget,
|
|
12215
|
+
grantCoversAction: () => grantCoversAction,
|
|
9659
12216
|
hasScope: () => hasScope,
|
|
9660
12217
|
hashObservation: () => hashObservation,
|
|
12218
|
+
idel: () => idel_exports,
|
|
9661
12219
|
isAdminOpcode: () => isAdminOpcode,
|
|
12220
|
+
isKnotOpen: () => isKnotOpen,
|
|
9662
12221
|
isKnownOpcode: () => isKnownOpcode,
|
|
12222
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
12223
|
+
isRevoked: () => isRevoked,
|
|
9663
12224
|
isTimestampValid: () => isTimestampValid,
|
|
12225
|
+
lockCells: () => lockCells,
|
|
9664
12226
|
loom: () => loom_exports,
|
|
12227
|
+
matchPatterns: () => matchPatterns,
|
|
9665
12228
|
mergeAxisExecutionContext: () => mergeAxisExecutionContext,
|
|
12229
|
+
needle: () => needle_exports,
|
|
9666
12230
|
nonce16: () => nonce16,
|
|
9667
12231
|
normalizeSensorDecision: () => normalizeSensorDecision,
|
|
12232
|
+
openKnot: () => openKnot,
|
|
9668
12233
|
packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
|
|
9669
12234
|
packPasskeyLoginOptionsRes: () => packPasskeyLoginOptionsRes,
|
|
9670
12235
|
packPasskeyLoginVerifyReq: () => packPasskeyLoginVerifyReq,
|
|
@@ -9673,32 +12238,49 @@ __export(index_exports, {
|
|
|
9673
12238
|
parseAutoClaimEntries: () => parseAutoClaimEntries,
|
|
9674
12239
|
parseScope: () => parseScope,
|
|
9675
12240
|
parseStreamEntries: () => parseStreamEntries,
|
|
12241
|
+
projectAt: () => projectAt,
|
|
12242
|
+
queryFabric: () => queryFabric,
|
|
12243
|
+
recordOccurrence: () => recordOccurrence,
|
|
9676
12244
|
recordSensor: () => recordSensor,
|
|
12245
|
+
renewPresence: () => renewPresence,
|
|
9677
12246
|
resolveTimeout: () => resolveTimeout,
|
|
12247
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
9678
12248
|
schemas: () => schemas_exports,
|
|
12249
|
+
scoreTruth: () => scoreTruth,
|
|
9679
12250
|
security: () => security_exports,
|
|
9680
12251
|
sensitivityName: () => sensitivityName,
|
|
9681
12252
|
sensors: () => sensors_exports,
|
|
9682
12253
|
sha256: () => sha2564,
|
|
9683
12254
|
signFrame: () => signFrame,
|
|
12255
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
9684
12256
|
stableJsonStringify: () => stableJsonStringify,
|
|
9685
12257
|
startStage: () => startStage,
|
|
12258
|
+
tieKnot: () => tieKnot,
|
|
12259
|
+
timeline: () => timeline_exports,
|
|
9686
12260
|
tlv: () => tlv,
|
|
9687
12261
|
u64be: () => u64be,
|
|
9688
12262
|
unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
|
|
9689
12263
|
unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
|
|
9690
12264
|
unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
|
|
12265
|
+
updateThreadState: () => updateThreadState,
|
|
9691
12266
|
utf8: () => utf8,
|
|
9692
12267
|
utils: () => utils_exports,
|
|
9693
12268
|
validateFrameShape: () => validateFrameShape,
|
|
12269
|
+
validateGrant: () => validateGrant,
|
|
12270
|
+
validateKnot: () => validateKnot,
|
|
12271
|
+
validateWrit: () => validateWrit,
|
|
9694
12272
|
varintLength: () => import_axis_protocol3.varintLength,
|
|
9695
12273
|
varintU: () => varintU,
|
|
9696
12274
|
verifyFrameSignature: () => verifyFrameSignature,
|
|
12275
|
+
verifyObservation: () => verifyObservation,
|
|
12276
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
12277
|
+
verifyReceiptChain: () => verifyReceiptChain,
|
|
9697
12278
|
verifyResponse: () => verifyResponse,
|
|
12279
|
+
weave: () => weave,
|
|
9698
12280
|
withAxisExecutionContext: () => withAxisExecutionContext
|
|
9699
12281
|
});
|
|
9700
12282
|
module.exports = __toCommonJS(index_exports);
|
|
9701
|
-
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;
|
|
12283
|
+
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;
|
|
9702
12284
|
var init_index = __esm({
|
|
9703
12285
|
"src/index.ts"() {
|
|
9704
12286
|
init_chain_decorator();
|
|
@@ -9711,7 +12293,7 @@ var init_index = __esm({
|
|
|
9711
12293
|
init_observer_decorator();
|
|
9712
12294
|
init_handler_sensors_decorator();
|
|
9713
12295
|
init_sensor_decorator();
|
|
9714
|
-
|
|
12296
|
+
import_tlv_field2 = __toESM(require_tlv_field_decorator());
|
|
9715
12297
|
import_dto_schema = __toESM(require_dto_schema_util());
|
|
9716
12298
|
init_axis_tlv_dto();
|
|
9717
12299
|
import_axis_id = __toESM(require_axis_id_dto());
|
|
@@ -9724,6 +12306,7 @@ var init_index = __esm({
|
|
|
9724
12306
|
init_stable_json();
|
|
9725
12307
|
init_observation_queue_codec();
|
|
9726
12308
|
init_observation_hash();
|
|
12309
|
+
init_truth_scoring();
|
|
9727
12310
|
init_response_observer();
|
|
9728
12311
|
init_constants();
|
|
9729
12312
|
init_varint();
|
|
@@ -9745,6 +12328,7 @@ var init_index = __esm({
|
|
|
9745
12328
|
init_axis_sensor();
|
|
9746
12329
|
init_scopes();
|
|
9747
12330
|
init_capabilities();
|
|
12331
|
+
init_law();
|
|
9748
12332
|
init_risk();
|
|
9749
12333
|
init_opcodes();
|
|
9750
12334
|
init_receipt();
|
|
@@ -9764,19 +12348,33 @@ var init_index = __esm({
|
|
|
9764
12348
|
import_sensor2 = __toESM(require_sensor_registry());
|
|
9765
12349
|
init_axis_observation();
|
|
9766
12350
|
import_axis_sensor_chain = __toESM(require_axis_sensor_chain_service());
|
|
12351
|
+
init_timeline_engine();
|
|
12352
|
+
init_timeline_store();
|
|
9767
12353
|
init_cce_pipeline();
|
|
9768
12354
|
init_cce_types();
|
|
9769
12355
|
init_axis_tlv_codec();
|
|
9770
12356
|
init_loom_types();
|
|
12357
|
+
init_loom_engine();
|
|
12358
|
+
init_idel_compiler();
|
|
12359
|
+
init_needle_engine();
|
|
12360
|
+
init_knot_engine();
|
|
12361
|
+
init_fabric_engine();
|
|
12362
|
+
init_pattern_engine();
|
|
12363
|
+
import_tps = __toESM(require_tps_sensor());
|
|
12364
|
+
import_risk_gate = __toESM(require_risk_gate_sensor());
|
|
12365
|
+
import_tickauth = __toESM(require_tickauth_sensor());
|
|
9771
12366
|
init_cce();
|
|
9772
12367
|
init_core();
|
|
9773
12368
|
init_crypto();
|
|
9774
12369
|
init_decorators();
|
|
9775
12370
|
init_engine();
|
|
12371
|
+
init_idel();
|
|
9776
12372
|
init_loom();
|
|
12373
|
+
init_needle();
|
|
9777
12374
|
init_schemas();
|
|
9778
12375
|
init_security();
|
|
9779
12376
|
init_sensors2();
|
|
12377
|
+
init_timeline();
|
|
9780
12378
|
init_utils();
|
|
9781
12379
|
}
|
|
9782
12380
|
});
|
|
@@ -9788,6 +12386,7 @@ init_index();
|
|
|
9788
12386
|
AXIS_ANONYMOUS_KEY,
|
|
9789
12387
|
AXIS_EXECUTION_CONTEXT_KEY,
|
|
9790
12388
|
AXIS_MAGIC,
|
|
12389
|
+
AXIS_META_KEY,
|
|
9791
12390
|
AXIS_OPCODES,
|
|
9792
12391
|
AXIS_PUBLIC_KEY,
|
|
9793
12392
|
AXIS_RATE_LIMIT_KEY,
|
|
@@ -9796,6 +12395,7 @@ init_index();
|
|
|
9796
12395
|
AXIS_UPLOAD_SESSION_STORE,
|
|
9797
12396
|
AXIS_VERSION,
|
|
9798
12397
|
Ats1Codec,
|
|
12398
|
+
Axis,
|
|
9799
12399
|
AxisAnonymous,
|
|
9800
12400
|
AxisChainExecutor,
|
|
9801
12401
|
AxisContext,
|
|
@@ -9855,6 +12455,10 @@ init_index();
|
|
|
9855
12455
|
INTENT_SENSITIVITY_MAP,
|
|
9856
12456
|
INTENT_SENSORS_KEY,
|
|
9857
12457
|
INTENT_TIMEOUTS,
|
|
12458
|
+
IdelCompiler,
|
|
12459
|
+
IdelSchemaRegistry,
|
|
12460
|
+
InMemoryPatternStore,
|
|
12461
|
+
InMemoryTimelineStore,
|
|
9858
12462
|
Intent,
|
|
9859
12463
|
IntentBody,
|
|
9860
12464
|
IntentRouter,
|
|
@@ -9898,6 +12502,7 @@ init_index();
|
|
|
9898
12502
|
RequiredProof,
|
|
9899
12503
|
ResponseObserver,
|
|
9900
12504
|
RiskDecision,
|
|
12505
|
+
RiskGateSensor,
|
|
9901
12506
|
SENSITIVITY_METADATA_KEY,
|
|
9902
12507
|
SENSOR_METADATA_KEY,
|
|
9903
12508
|
Schema2002_PasskeyLoginOptionsRes,
|
|
@@ -9946,19 +12551,27 @@ init_index();
|
|
|
9946
12551
|
TLV_UPLOAD_ID,
|
|
9947
12552
|
TLV_VALIDATORS_KEY,
|
|
9948
12553
|
TLV_WRIT,
|
|
12554
|
+
TickAuthSensor,
|
|
12555
|
+
TimelineEngine,
|
|
9949
12556
|
TlvEnum,
|
|
9950
12557
|
TlvField,
|
|
9951
12558
|
TlvMinLen,
|
|
9952
12559
|
TlvRange,
|
|
9953
12560
|
TlvUtf8Pattern,
|
|
9954
12561
|
TlvValidate,
|
|
12562
|
+
TpsSensor,
|
|
9955
12563
|
Witness,
|
|
12564
|
+
addStitchToKnot,
|
|
12565
|
+
applyStitch,
|
|
12566
|
+
assembleNeedle,
|
|
9956
12567
|
axis1SigningBytes,
|
|
9957
12568
|
b64urlDecode,
|
|
9958
12569
|
b64urlDecodeString,
|
|
9959
12570
|
b64urlEncode,
|
|
9960
12571
|
b64urlEncodeString,
|
|
12572
|
+
breakKnot,
|
|
9961
12573
|
buildAts1Hdr,
|
|
12574
|
+
buildAxisLawEvaluationContext,
|
|
9962
12575
|
buildDtoDecoder,
|
|
9963
12576
|
buildPacket,
|
|
9964
12577
|
buildQueueMessage,
|
|
@@ -9977,7 +12590,13 @@ init_index();
|
|
|
9977
12590
|
computeReceiptHash,
|
|
9978
12591
|
computeSignaturePayload,
|
|
9979
12592
|
core,
|
|
12593
|
+
createFabric,
|
|
12594
|
+
createGrant,
|
|
9980
12595
|
createObservation,
|
|
12596
|
+
createPresenceChallenge,
|
|
12597
|
+
createReceipt,
|
|
12598
|
+
createRevocation,
|
|
12599
|
+
createWrit,
|
|
9981
12600
|
crypto,
|
|
9982
12601
|
decodeArray,
|
|
9983
12602
|
decodeAxis1Frame,
|
|
@@ -9989,6 +12608,10 @@ init_index();
|
|
|
9989
12608
|
decodeVarint,
|
|
9990
12609
|
decorators,
|
|
9991
12610
|
deriveAnchorReflection,
|
|
12611
|
+
detectAnomalies,
|
|
12612
|
+
detectKnotPatterns,
|
|
12613
|
+
detectSequencePatterns,
|
|
12614
|
+
diffFabrics,
|
|
9992
12615
|
encVarint,
|
|
9993
12616
|
encodeAxis1Frame,
|
|
9994
12617
|
encodeAxisTlvDto,
|
|
@@ -9999,20 +12622,38 @@ init_index();
|
|
|
9999
12622
|
endStage,
|
|
10000
12623
|
engine,
|
|
10001
12624
|
executeCcePipeline,
|
|
12625
|
+
executeLoomPipeline,
|
|
10002
12626
|
extractDtoSchema,
|
|
10003
12627
|
finalizeObservation,
|
|
12628
|
+
findKnotsForStitch,
|
|
12629
|
+
forkFromKnot,
|
|
12630
|
+
formStitch,
|
|
10004
12631
|
generateEd25519KeyPair,
|
|
10005
12632
|
getAxisExecutionContext,
|
|
12633
|
+
getDecisionPoints,
|
|
12634
|
+
getFabricValue,
|
|
12635
|
+
getGrantStatus,
|
|
12636
|
+
getIrreversibleKnots,
|
|
12637
|
+
getPresenceStatus,
|
|
10006
12638
|
getSignTarget,
|
|
12639
|
+
grantCoversAction,
|
|
10007
12640
|
hasScope,
|
|
10008
12641
|
hashObservation,
|
|
12642
|
+
idel,
|
|
10009
12643
|
isAdminOpcode,
|
|
12644
|
+
isKnotOpen,
|
|
10010
12645
|
isKnownOpcode,
|
|
12646
|
+
isPointOfNoReturn,
|
|
12647
|
+
isRevoked,
|
|
10011
12648
|
isTimestampValid,
|
|
12649
|
+
lockCells,
|
|
10012
12650
|
loom,
|
|
12651
|
+
matchPatterns,
|
|
10013
12652
|
mergeAxisExecutionContext,
|
|
12653
|
+
needle,
|
|
10014
12654
|
nonce16,
|
|
10015
12655
|
normalizeSensorDecision,
|
|
12656
|
+
openKnot,
|
|
10016
12657
|
packPasskeyLoginOptionsReq,
|
|
10017
12658
|
packPasskeyLoginOptionsRes,
|
|
10018
12659
|
packPasskeyLoginVerifyReq,
|
|
@@ -10021,28 +12662,45 @@ init_index();
|
|
|
10021
12662
|
parseAutoClaimEntries,
|
|
10022
12663
|
parseScope,
|
|
10023
12664
|
parseStreamEntries,
|
|
12665
|
+
projectAt,
|
|
12666
|
+
queryFabric,
|
|
12667
|
+
recordOccurrence,
|
|
10024
12668
|
recordSensor,
|
|
12669
|
+
renewPresence,
|
|
10025
12670
|
resolveTimeout,
|
|
12671
|
+
runNeedlePipeline,
|
|
10026
12672
|
schemas,
|
|
12673
|
+
scoreTruth,
|
|
10027
12674
|
security,
|
|
10028
12675
|
sensitivityName,
|
|
10029
12676
|
sensors,
|
|
10030
12677
|
sha256,
|
|
10031
12678
|
signFrame,
|
|
12679
|
+
signPresenceChallenge,
|
|
10032
12680
|
stableJsonStringify,
|
|
10033
12681
|
startStage,
|
|
12682
|
+
tieKnot,
|
|
12683
|
+
timeline,
|
|
10034
12684
|
tlv,
|
|
10035
12685
|
u64be,
|
|
10036
12686
|
unpackPasskeyLoginOptionsReq,
|
|
10037
12687
|
unpackPasskeyLoginVerifyReq,
|
|
10038
12688
|
unpackPasskeyRegisterOptionsReq,
|
|
12689
|
+
updateThreadState,
|
|
10039
12690
|
utf8,
|
|
10040
12691
|
utils,
|
|
10041
12692
|
validateFrameShape,
|
|
12693
|
+
validateGrant,
|
|
12694
|
+
validateKnot,
|
|
12695
|
+
validateWrit,
|
|
10042
12696
|
varintLength,
|
|
10043
12697
|
varintU,
|
|
10044
12698
|
verifyFrameSignature,
|
|
12699
|
+
verifyObservation,
|
|
12700
|
+
verifyPresenceProof,
|
|
12701
|
+
verifyReceiptChain,
|
|
10045
12702
|
verifyResponse,
|
|
12703
|
+
weave,
|
|
10046
12704
|
withAxisExecutionContext
|
|
10047
12705
|
});
|
|
10048
12706
|
//# sourceMappingURL=index.js.map
|