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