@nextera.one/axis-server-sdk 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codec/axis1.encode.d.mts +10 -0
- package/dist/codec/axis1.encode.d.ts +10 -0
- package/dist/codec/axis1.encode.js +65 -0
- package/dist/codec/axis1.encode.js.map +1 -0
- package/dist/codec/axis1.encode.mjs +41 -0
- package/dist/codec/axis1.encode.mjs.map +1 -0
- package/dist/codec/axis1.signing.d.mts +8 -0
- package/dist/codec/axis1.signing.d.ts +8 -0
- package/dist/codec/axis1.signing.js +61 -0
- package/dist/codec/axis1.signing.js.map +1 -0
- package/dist/codec/axis1.signing.mjs +37 -0
- package/dist/codec/axis1.signing.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +6 -244
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +8 -238
- package/dist/core/index.mjs.map +1 -1
- package/dist/index-VxXqZPuH.d.mts +51 -0
- package/dist/index-VxXqZPuH.d.ts +51 -0
- package/dist/index.d.mts +1295 -429
- package/dist/index.d.ts +1295 -429
- package/dist/index.js +2985 -376
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2991 -368
- package/dist/index.mjs.map +1 -1
- package/dist/types/frame.d.mts +11 -0
- package/dist/types/frame.d.ts +11 -0
- package/dist/types/frame.js +78 -0
- package/dist/types/frame.js.map +1 -0
- package/dist/types/frame.mjs +54 -0
- package/dist/types/frame.mjs.map +1 -0
- package/package.json +2 -1
- package/dist/index-1uEwnW-w.d.mts +0 -122
- package/dist/index-1uEwnW-w.d.ts +0 -122
package/dist/index.mjs
CHANGED
|
@@ -172,76 +172,90 @@ var init_sensor_decorator = __esm({
|
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
// src/decorators/tlv-field.decorator.ts
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
existing
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return (target, propertyKey) => {
|
|
200
|
-
const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
201
|
-
const prop = String(propertyKey);
|
|
202
|
-
let entry = existing.find((e) => e.property === prop);
|
|
203
|
-
if (!entry) {
|
|
204
|
-
entry = { property: prop, tag: 0, validators: [] };
|
|
205
|
-
existing.push(entry);
|
|
175
|
+
var require_tlv_field_decorator = __commonJS({
|
|
176
|
+
"src/decorators/tlv-field.decorator.ts"(exports) {
|
|
177
|
+
"use strict";
|
|
178
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
179
|
+
exports.TLV_VALIDATORS_KEY = exports.TLV_FIELDS_KEY = void 0;
|
|
180
|
+
exports.TlvField = TlvField2;
|
|
181
|
+
exports.TlvValidate = TlvValidate2;
|
|
182
|
+
exports.TlvUtf8Pattern = TlvUtf8Pattern2;
|
|
183
|
+
exports.TlvMinLen = TlvMinLen2;
|
|
184
|
+
exports.TlvEnum = TlvEnum2;
|
|
185
|
+
exports.TlvRange = TlvRange2;
|
|
186
|
+
__require("reflect-metadata");
|
|
187
|
+
exports.TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
188
|
+
exports.TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
189
|
+
var textDecoder = new TextDecoder();
|
|
190
|
+
function assertUniqueFieldMetadata(existing, property, tag) {
|
|
191
|
+
const duplicateProperty = existing.find((item) => item.property === property);
|
|
192
|
+
if (duplicateProperty) {
|
|
193
|
+
throw new Error(`Duplicate @TlvField for property ${property}`);
|
|
194
|
+
}
|
|
195
|
+
const duplicateTag = existing.find((item) => item.tag === tag);
|
|
196
|
+
if (duplicateTag) {
|
|
197
|
+
throw new Error(`Duplicate @TlvField tag ${tag} for ${property}; already used by ${duplicateTag.property}`);
|
|
198
|
+
}
|
|
206
199
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return
|
|
200
|
+
function TlvField2(tag, options) {
|
|
201
|
+
return (target, propertyKey) => {
|
|
202
|
+
const existing = Reflect.getOwnMetadata(exports.TLV_FIELDS_KEY, target.constructor) || [];
|
|
203
|
+
const property = String(propertyKey);
|
|
204
|
+
assertUniqueFieldMetadata(existing, property, tag);
|
|
205
|
+
existing.push({
|
|
206
|
+
property,
|
|
207
|
+
tag,
|
|
208
|
+
options
|
|
209
|
+
});
|
|
210
|
+
Reflect.defineMetadata(exports.TLV_FIELDS_KEY, existing, target.constructor);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function TlvValidate2(validator) {
|
|
214
|
+
return (target, propertyKey) => {
|
|
215
|
+
const existing = Reflect.getOwnMetadata(exports.TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
216
|
+
const prop = String(propertyKey);
|
|
217
|
+
let entry = existing.find((e) => e.property === prop);
|
|
218
|
+
if (!entry) {
|
|
219
|
+
entry = { property: prop, tag: 0, validators: [] };
|
|
220
|
+
existing.push(entry);
|
|
221
|
+
}
|
|
222
|
+
entry.validators.push(validator);
|
|
223
|
+
Reflect.defineMetadata(exports.TLV_VALIDATORS_KEY, existing, target.constructor);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function TlvUtf8Pattern2(pattern, message) {
|
|
227
|
+
const matcher = new RegExp(pattern.source, pattern.flags);
|
|
228
|
+
return TlvValidate2((val, prop) => {
|
|
229
|
+
const str = textDecoder.decode(val);
|
|
230
|
+
matcher.lastIndex = 0;
|
|
231
|
+
return matcher.test(str) ? null : message || `${prop}: failed pattern check`;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function TlvMinLen2(min, message) {
|
|
235
|
+
return TlvValidate2((val, prop) => {
|
|
236
|
+
return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function TlvEnum2(allowed, message) {
|
|
240
|
+
const set = new Set(allowed);
|
|
241
|
+
return TlvValidate2((val, prop) => {
|
|
242
|
+
const str = textDecoder.decode(val);
|
|
243
|
+
return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function TlvRange2(min, max, message) {
|
|
247
|
+
return TlvValidate2((val, prop) => {
|
|
248
|
+
if (val.length !== 8)
|
|
249
|
+
return `${prop}: u64 must be 8 bytes`;
|
|
250
|
+
let n = 0n;
|
|
251
|
+
for (const b of val)
|
|
252
|
+
n = n << 8n | BigInt(b);
|
|
253
|
+
if (n < min || n > max) {
|
|
254
|
+
return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
});
|
|
236
258
|
}
|
|
237
|
-
return null;
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
var TLV_FIELDS_KEY, TLV_VALIDATORS_KEY;
|
|
241
|
-
var init_tlv_field_decorator = __esm({
|
|
242
|
-
"src/decorators/tlv-field.decorator.ts"() {
|
|
243
|
-
TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
244
|
-
TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
245
259
|
}
|
|
246
260
|
});
|
|
247
261
|
|
|
@@ -276,7 +290,7 @@ var require_dto_schema_util = __commonJS({
|
|
|
276
290
|
exports.extractDtoSchema = extractDtoSchema2;
|
|
277
291
|
exports.buildDtoDecoder = buildDtoDecoder2;
|
|
278
292
|
__require("reflect-metadata");
|
|
279
|
-
var tlv_field_decorator_1 = (
|
|
293
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
280
294
|
var tlv_1 = (init_tlv(), __toCommonJS(tlv_exports));
|
|
281
295
|
function extractDtoSchema2(dto) {
|
|
282
296
|
const fieldMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_FIELDS_KEY, dto) || [];
|
|
@@ -385,7 +399,7 @@ var require_axis_id_dto = __commonJS({
|
|
|
385
399
|
};
|
|
386
400
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
387
401
|
exports.AxisIdDto = void 0;
|
|
388
|
-
var tlv_field_decorator_1 = (
|
|
402
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
389
403
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
390
404
|
var AxisIdDto2 = class extends axis_tlv_dto_1.AxisTlvDto {
|
|
391
405
|
};
|
|
@@ -403,25 +417,26 @@ import "reflect-metadata";
|
|
|
403
417
|
function AxisPartialType(BaseDto) {
|
|
404
418
|
class PartialDto extends BaseDto {
|
|
405
419
|
}
|
|
406
|
-
const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
|
|
420
|
+
const fields = Reflect.getOwnMetadata(import_tlv_field.TLV_FIELDS_KEY, BaseDto) || [];
|
|
407
421
|
const partialFields = fields.map((f) => ({
|
|
408
422
|
property: f.property,
|
|
409
423
|
tag: f.tag,
|
|
410
424
|
options: { ...f.options, required: false }
|
|
411
425
|
}));
|
|
412
|
-
Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
413
|
-
const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
426
|
+
Reflect.defineMetadata(import_tlv_field.TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
427
|
+
const validators = Reflect.getOwnMetadata(import_tlv_field.TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
414
428
|
if (validators.length > 0) {
|
|
415
|
-
Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
429
|
+
Reflect.defineMetadata(import_tlv_field.TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
416
430
|
}
|
|
417
431
|
Object.defineProperty(PartialDto, "name", {
|
|
418
432
|
value: `Partial${BaseDto.name}`
|
|
419
433
|
});
|
|
420
434
|
return PartialDto;
|
|
421
435
|
}
|
|
436
|
+
var import_tlv_field;
|
|
422
437
|
var init_axis_partial_type = __esm({
|
|
423
438
|
"src/base/axis-partial-type.ts"() {
|
|
424
|
-
|
|
439
|
+
import_tlv_field = __toESM(require_tlv_field_decorator());
|
|
425
440
|
}
|
|
426
441
|
});
|
|
427
442
|
|
|
@@ -440,7 +455,7 @@ var require_axis_response_dto = __commonJS({
|
|
|
440
455
|
};
|
|
441
456
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
442
457
|
exports.AxisResponseDto = exports.RESPONSE_TAG_UPDATED_BY = exports.RESPONSE_TAG_CREATED_BY = exports.RESPONSE_TAG_UPDATED_AT = exports.RESPONSE_TAG_CREATED_AT = exports.RESPONSE_TAG_ID = void 0;
|
|
443
|
-
var tlv_field_decorator_1 = (
|
|
458
|
+
var tlv_field_decorator_1 = require_tlv_field_decorator();
|
|
444
459
|
var axis_tlv_dto_1 = (init_axis_tlv_dto(), __toCommonJS(axis_tlv_dto_exports));
|
|
445
460
|
exports.RESPONSE_TAG_ID = 1;
|
|
446
461
|
exports.RESPONSE_TAG_CREATED_AT = 2;
|
|
@@ -1333,6 +1348,7 @@ var require_intent_router = __commonJS({
|
|
|
1333
1348
|
this.intentKinds = /* @__PURE__ */ new Map();
|
|
1334
1349
|
this.cceHandlers = /* @__PURE__ */ new Map();
|
|
1335
1350
|
this.ccePipelineConfig = null;
|
|
1351
|
+
this.idelCompiler = null;
|
|
1336
1352
|
}
|
|
1337
1353
|
getSchema(intent) {
|
|
1338
1354
|
return this.intentSchemas.get(intent);
|
|
@@ -1346,6 +1362,34 @@ var require_intent_router = __commonJS({
|
|
|
1346
1362
|
getRegisteredIntents() {
|
|
1347
1363
|
return [...IntentRouter_1.BUILTIN_INTENTS, ...this.handlers.keys()];
|
|
1348
1364
|
}
|
|
1365
|
+
configureIdel(compiler) {
|
|
1366
|
+
this.idelCompiler = compiler;
|
|
1367
|
+
this.logger.log("IDEL compiler configured");
|
|
1368
|
+
}
|
|
1369
|
+
resolveIntent(proposal) {
|
|
1370
|
+
if (!this.idelCompiler) {
|
|
1371
|
+
throw new Error("IDEL compiler not configured. Call configureIdel() first.");
|
|
1372
|
+
}
|
|
1373
|
+
const result = this.idelCompiler.compile(proposal);
|
|
1374
|
+
if (!result.ok || !result.compiled) {
|
|
1375
|
+
const msg = result.errors?.map((e) => e.message).join("; ") ?? "Unknown compilation error";
|
|
1376
|
+
throw new Error(`IDEL compilation failed: ${msg}`);
|
|
1377
|
+
}
|
|
1378
|
+
return result.compiled;
|
|
1379
|
+
}
|
|
1380
|
+
async routeIdel(proposal, frame) {
|
|
1381
|
+
const compiled = this.resolveIntent(proposal);
|
|
1382
|
+
const resolvedFrame = {
|
|
1383
|
+
...frame,
|
|
1384
|
+
headers: new Map(frame.headers)
|
|
1385
|
+
};
|
|
1386
|
+
resolvedFrame.headers.set(3, new TextEncoder().encode(compiled.intent));
|
|
1387
|
+
if (compiled.params && Object.keys(compiled.params).length > 0) {
|
|
1388
|
+
resolvedFrame.body = new TextEncoder().encode(JSON.stringify(compiled.params));
|
|
1389
|
+
}
|
|
1390
|
+
const effect = await this.route(resolvedFrame);
|
|
1391
|
+
return { ...effect, compiled };
|
|
1392
|
+
}
|
|
1349
1393
|
getIntentEntry(intent) {
|
|
1350
1394
|
if (!this.has(intent))
|
|
1351
1395
|
return null;
|
|
@@ -1841,6 +1885,213 @@ var init_observation_hash = __esm({
|
|
|
1841
1885
|
}
|
|
1842
1886
|
});
|
|
1843
1887
|
|
|
1888
|
+
// src/engine/observation/truth-scoring.ts
|
|
1889
|
+
function scoreTruth(obs, expected) {
|
|
1890
|
+
const anomalies = [];
|
|
1891
|
+
let passedChecks = 0;
|
|
1892
|
+
let totalChecks = 0;
|
|
1893
|
+
totalChecks++;
|
|
1894
|
+
if (obs.endMs && obs.decision) {
|
|
1895
|
+
passedChecks++;
|
|
1896
|
+
} else {
|
|
1897
|
+
anomalies.push({
|
|
1898
|
+
code: "OBS_NOT_FINALIZED",
|
|
1899
|
+
level: "critical",
|
|
1900
|
+
message: "Observation was not finalized"
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
totalChecks++;
|
|
1904
|
+
if (obs.stages.length > 0) {
|
|
1905
|
+
passedChecks++;
|
|
1906
|
+
} else {
|
|
1907
|
+
anomalies.push({
|
|
1908
|
+
code: "OBS_NO_STAGES",
|
|
1909
|
+
level: "warning",
|
|
1910
|
+
message: "Observation has no execution stages"
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
totalChecks++;
|
|
1914
|
+
const failedStages = obs.stages.filter((s) => s.status === "fail");
|
|
1915
|
+
if (failedStages.length === 0 || obs.decision === "DENY") {
|
|
1916
|
+
passedChecks++;
|
|
1917
|
+
} else {
|
|
1918
|
+
for (const stage of failedStages) {
|
|
1919
|
+
anomalies.push({
|
|
1920
|
+
code: "STAGE_FAILED",
|
|
1921
|
+
level: "warning",
|
|
1922
|
+
message: `Stage '${stage.name}' failed: ${stage.reason ?? "unknown"}`,
|
|
1923
|
+
field: `stages.${stage.name}`
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
totalChecks++;
|
|
1928
|
+
const invalidSensors = obs.sensors.filter((s) => s.durationMs < 0);
|
|
1929
|
+
if (invalidSensors.length === 0) {
|
|
1930
|
+
passedChecks++;
|
|
1931
|
+
} else {
|
|
1932
|
+
anomalies.push({
|
|
1933
|
+
code: "SENSOR_INVALID_TIMING",
|
|
1934
|
+
level: "warning",
|
|
1935
|
+
message: `${invalidSensors.length} sensor(s) have negative duration`
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
totalChecks++;
|
|
1939
|
+
if (obs.durationMs !== void 0 && obs.durationMs >= 0 && obs.durationMs < 3e5) {
|
|
1940
|
+
passedChecks++;
|
|
1941
|
+
} else {
|
|
1942
|
+
anomalies.push({
|
|
1943
|
+
code: "OBS_DURATION_ANOMALY",
|
|
1944
|
+
level: "warning",
|
|
1945
|
+
message: `Observation duration ${obs.durationMs}ms is suspicious`,
|
|
1946
|
+
actual: obs.durationMs
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
if (expected) {
|
|
1950
|
+
if (expected.decision !== void 0) {
|
|
1951
|
+
totalChecks++;
|
|
1952
|
+
if (obs.decision === expected.decision) {
|
|
1953
|
+
passedChecks++;
|
|
1954
|
+
} else {
|
|
1955
|
+
anomalies.push({
|
|
1956
|
+
code: "DECISION_MISMATCH",
|
|
1957
|
+
level: "critical",
|
|
1958
|
+
message: `Expected decision '${expected.decision}', got '${obs.decision}'`,
|
|
1959
|
+
field: "decision",
|
|
1960
|
+
expected: expected.decision,
|
|
1961
|
+
actual: obs.decision
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
if (expected.statusCode !== void 0) {
|
|
1966
|
+
totalChecks++;
|
|
1967
|
+
if (obs.statusCode === expected.statusCode) {
|
|
1968
|
+
passedChecks++;
|
|
1969
|
+
} else {
|
|
1970
|
+
anomalies.push({
|
|
1971
|
+
code: "STATUS_MISMATCH",
|
|
1972
|
+
level: "warning",
|
|
1973
|
+
message: `Expected status ${expected.statusCode}, got ${obs.statusCode}`,
|
|
1974
|
+
field: "statusCode",
|
|
1975
|
+
expected: expected.statusCode,
|
|
1976
|
+
actual: obs.statusCode
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
if (expected.effect !== void 0) {
|
|
1981
|
+
totalChecks++;
|
|
1982
|
+
if (obs.resultCode === expected.effect || obs.facts?.effect === expected.effect) {
|
|
1983
|
+
passedChecks++;
|
|
1984
|
+
} else {
|
|
1985
|
+
anomalies.push({
|
|
1986
|
+
code: "EFFECT_MISMATCH",
|
|
1987
|
+
level: "warning",
|
|
1988
|
+
message: `Expected effect '${expected.effect}', got '${obs.resultCode}'`,
|
|
1989
|
+
field: "resultCode",
|
|
1990
|
+
expected: expected.effect,
|
|
1991
|
+
actual: obs.resultCode
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
if (expected.maxDurationMs !== void 0) {
|
|
1996
|
+
totalChecks++;
|
|
1997
|
+
if (obs.durationMs !== void 0 && obs.durationMs <= expected.maxDurationMs) {
|
|
1998
|
+
passedChecks++;
|
|
1999
|
+
} else {
|
|
2000
|
+
anomalies.push({
|
|
2001
|
+
code: "DURATION_EXCEEDED",
|
|
2002
|
+
level: "warning",
|
|
2003
|
+
message: `Execution took ${obs.durationMs}ms, max allowed ${expected.maxDurationMs}ms`,
|
|
2004
|
+
field: "durationMs",
|
|
2005
|
+
expected: expected.maxDurationMs,
|
|
2006
|
+
actual: obs.durationMs
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
if (expected.minSensorsPassed !== void 0) {
|
|
2011
|
+
totalChecks++;
|
|
2012
|
+
const passed = obs.sensors.filter((s) => s.allowed).length;
|
|
2013
|
+
if (passed >= expected.minSensorsPassed) {
|
|
2014
|
+
passedChecks++;
|
|
2015
|
+
} else {
|
|
2016
|
+
anomalies.push({
|
|
2017
|
+
code: "INSUFFICIENT_SENSORS",
|
|
2018
|
+
level: "warning",
|
|
2019
|
+
message: `Only ${passed} sensors passed, minimum required ${expected.minSensorsPassed}`,
|
|
2020
|
+
field: "sensors",
|
|
2021
|
+
expected: expected.minSensorsPassed,
|
|
2022
|
+
actual: passed
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
if (expected.assertions) {
|
|
2027
|
+
for (const [key, expectedValue] of Object.entries(expected.assertions)) {
|
|
2028
|
+
totalChecks++;
|
|
2029
|
+
const actualValue = obs.facts[key];
|
|
2030
|
+
if (deepEqual(actualValue, expectedValue)) {
|
|
2031
|
+
passedChecks++;
|
|
2032
|
+
} else {
|
|
2033
|
+
anomalies.push({
|
|
2034
|
+
code: "ASSERTION_FAILED",
|
|
2035
|
+
level: "warning",
|
|
2036
|
+
message: `Assertion failed for facts.${key}`,
|
|
2037
|
+
field: `facts.${key}`,
|
|
2038
|
+
expected: expectedValue,
|
|
2039
|
+
actual: actualValue
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
const confidence = totalChecks > 0 ? passedChecks / totalChecks : 0;
|
|
2046
|
+
const hasCritical = anomalies.some((a) => a.level === "critical");
|
|
2047
|
+
const status = computeTruthStatus(confidence, hasCritical, anomalies.length);
|
|
2048
|
+
const isDeed = status === "confirmed" || status === "partial" && !hasCritical;
|
|
2049
|
+
return {
|
|
2050
|
+
status,
|
|
2051
|
+
confidence,
|
|
2052
|
+
anomalies,
|
|
2053
|
+
passedChecks,
|
|
2054
|
+
totalChecks,
|
|
2055
|
+
verifiedAt: Date.now(),
|
|
2056
|
+
isDeed
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
function computeTruthStatus(confidence, hasCritical, anomalyCount) {
|
|
2060
|
+
if (hasCritical) return "failed";
|
|
2061
|
+
if (confidence === 1) return "confirmed";
|
|
2062
|
+
if (confidence >= 0.8) return "partial";
|
|
2063
|
+
if (confidence >= 0.5) return "uncertain";
|
|
2064
|
+
return "disputed";
|
|
2065
|
+
}
|
|
2066
|
+
function verifyObservation(obs, expected) {
|
|
2067
|
+
const verdict = scoreTruth(obs, expected);
|
|
2068
|
+
return { observation: obs, verdict };
|
|
2069
|
+
}
|
|
2070
|
+
function deepEqual(a, b) {
|
|
2071
|
+
if (a === b) return true;
|
|
2072
|
+
if (a === null || b === null) return false;
|
|
2073
|
+
if (typeof a !== typeof b) return false;
|
|
2074
|
+
if (typeof a !== "object") return String(a) === String(b);
|
|
2075
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2076
|
+
if (a.length !== b.length) return false;
|
|
2077
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
2078
|
+
}
|
|
2079
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
2080
|
+
const aKeys = Object.keys(a);
|
|
2081
|
+
const bKeys = Object.keys(b);
|
|
2082
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
2083
|
+
return aKeys.every(
|
|
2084
|
+
(key) => deepEqual(
|
|
2085
|
+
a[key],
|
|
2086
|
+
b[key]
|
|
2087
|
+
)
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
var init_truth_scoring = __esm({
|
|
2091
|
+
"src/engine/observation/truth-scoring.ts"() {
|
|
2092
|
+
}
|
|
2093
|
+
});
|
|
2094
|
+
|
|
1844
2095
|
// src/core/constants.ts
|
|
1845
2096
|
var constants_exports = {};
|
|
1846
2097
|
__export(constants_exports, {
|
|
@@ -2050,92 +2301,14 @@ __export(axis_bin_exports, {
|
|
|
2050
2301
|
getSignTarget: () => getSignTarget
|
|
2051
2302
|
});
|
|
2052
2303
|
import * as z from "zod";
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
}))
|
|
2059
|
-
);
|
|
2060
|
-
if (hdrBytes.length > MAX_HDR_LEN) throw new Error("Header too large");
|
|
2061
|
-
if (frame.body.length > MAX_BODY_LEN) throw new Error("Body too large");
|
|
2062
|
-
if (frame.sig.length > MAX_SIG_LEN) throw new Error("Signature too large");
|
|
2063
|
-
const hdrLenBytes = encodeVarint(hdrBytes.length);
|
|
2064
|
-
const bodyLenBytes = encodeVarint(frame.body.length);
|
|
2065
|
-
const sigLenBytes = encodeVarint(frame.sig.length);
|
|
2066
|
-
const totalLen = 5 + // Magic (AXIS1)
|
|
2067
|
-
1 + // Version
|
|
2068
|
-
1 + // Flags
|
|
2069
|
-
hdrLenBytes.length + bodyLenBytes.length + sigLenBytes.length + hdrBytes.length + frame.body.length + frame.sig.length;
|
|
2070
|
-
if (totalLen > MAX_FRAME_LEN) throw new Error("Total frame too large");
|
|
2071
|
-
const buf = new Uint8Array(totalLen);
|
|
2072
|
-
let offset = 0;
|
|
2073
|
-
buf.set(AXIS_MAGIC, offset);
|
|
2074
|
-
offset += 5;
|
|
2075
|
-
buf[offset++] = AXIS_VERSION;
|
|
2076
|
-
buf[offset++] = frame.flags;
|
|
2077
|
-
buf.set(hdrLenBytes, offset);
|
|
2078
|
-
offset += hdrLenBytes.length;
|
|
2079
|
-
buf.set(bodyLenBytes, offset);
|
|
2080
|
-
offset += bodyLenBytes.length;
|
|
2081
|
-
buf.set(sigLenBytes, offset);
|
|
2082
|
-
offset += sigLenBytes.length;
|
|
2083
|
-
buf.set(hdrBytes, offset);
|
|
2084
|
-
offset += hdrBytes.length;
|
|
2085
|
-
buf.set(frame.body, offset);
|
|
2086
|
-
offset += frame.body.length;
|
|
2087
|
-
buf.set(frame.sig, offset);
|
|
2088
|
-
offset += frame.sig.length;
|
|
2089
|
-
return buf;
|
|
2090
|
-
}
|
|
2091
|
-
function decodeFrame(buf) {
|
|
2092
|
-
let offset = 0;
|
|
2093
|
-
if (offset + 5 > buf.length) throw new Error("Packet too short");
|
|
2094
|
-
for (let i = 0; i < 5; i++) {
|
|
2095
|
-
if (buf[offset + i] !== AXIS_MAGIC[i]) throw new Error("Invalid Magic");
|
|
2096
|
-
}
|
|
2097
|
-
offset += 5;
|
|
2098
|
-
const ver = buf[offset++];
|
|
2099
|
-
if (ver !== AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);
|
|
2100
|
-
const flags = buf[offset++];
|
|
2101
|
-
const { value: hdrLen, length: hlLen } = decodeVarint(buf, offset);
|
|
2102
|
-
offset += hlLen;
|
|
2103
|
-
if (hdrLen > MAX_HDR_LEN) throw new Error("Header limit exceeded");
|
|
2104
|
-
const { value: bodyLen, length: blLen } = decodeVarint(buf, offset);
|
|
2105
|
-
offset += blLen;
|
|
2106
|
-
if (bodyLen > MAX_BODY_LEN) throw new Error("Body limit exceeded");
|
|
2107
|
-
const { value: sigLen, length: slLen } = decodeVarint(buf, offset);
|
|
2108
|
-
offset += slLen;
|
|
2109
|
-
if (sigLen > MAX_SIG_LEN) throw new Error("Signature limit exceeded");
|
|
2110
|
-
if (offset + hdrLen + bodyLen + sigLen > buf.length) {
|
|
2111
|
-
throw new Error("Frame truncated");
|
|
2112
|
-
}
|
|
2113
|
-
const hdrBytes = buf.slice(offset, offset + hdrLen);
|
|
2114
|
-
offset += hdrLen;
|
|
2115
|
-
const bodyBytes = buf.slice(offset, offset + bodyLen);
|
|
2116
|
-
offset += bodyLen;
|
|
2117
|
-
const sigBytes = buf.slice(offset, offset + sigLen);
|
|
2118
|
-
offset += sigLen;
|
|
2119
|
-
const headers = decodeTLVs(hdrBytes);
|
|
2120
|
-
return {
|
|
2121
|
-
flags,
|
|
2122
|
-
headers,
|
|
2123
|
-
body: bodyBytes,
|
|
2124
|
-
sig: sigBytes
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
function getSignTarget(frame) {
|
|
2128
|
-
return encodeFrame({
|
|
2129
|
-
...frame,
|
|
2130
|
-
sig: new Uint8Array(0)
|
|
2131
|
-
});
|
|
2132
|
-
}
|
|
2304
|
+
import {
|
|
2305
|
+
decodeFrame,
|
|
2306
|
+
encodeFrame,
|
|
2307
|
+
getSignTarget
|
|
2308
|
+
} from "@nextera.one/axis-protocol";
|
|
2133
2309
|
var AxisFrameZ;
|
|
2134
2310
|
var init_axis_bin = __esm({
|
|
2135
2311
|
"src/core/axis-bin.ts"() {
|
|
2136
|
-
init_constants();
|
|
2137
|
-
init_tlv();
|
|
2138
|
-
init_varint();
|
|
2139
2312
|
AxisFrameZ = z.object({
|
|
2140
2313
|
/** Flag bits for protocol control (e.g., encryption, compression) */
|
|
2141
2314
|
flags: z.number().int().nonnegative(),
|
|
@@ -2155,12 +2328,7 @@ var init_axis_bin = __esm({
|
|
|
2155
2328
|
// src/core/signature.ts
|
|
2156
2329
|
import * as crypto2 from "crypto";
|
|
2157
2330
|
function computeSignaturePayload(frame) {
|
|
2158
|
-
|
|
2159
|
-
...frame,
|
|
2160
|
-
sig: new Uint8Array(0)
|
|
2161
|
-
};
|
|
2162
|
-
const encoded = encodeFrame(frameWithoutSig);
|
|
2163
|
-
return Buffer.from(encoded);
|
|
2331
|
+
return Buffer.from(getSignTarget(frame));
|
|
2164
2332
|
}
|
|
2165
2333
|
function signFrame(frame, privateKey) {
|
|
2166
2334
|
const payload = computeSignaturePayload(frame);
|
|
@@ -3041,11 +3209,12 @@ var init_tlv_encode = __esm({
|
|
|
3041
3209
|
});
|
|
3042
3210
|
|
|
3043
3211
|
// src/codec/axis1.encode.ts
|
|
3212
|
+
import { AXIS_MAGIC as AXIS_MAGIC2, AXIS_VERSION as AXIS_VERSION2 } from "@nextera.one/axis-protocol";
|
|
3044
3213
|
function encodeAxis1Frame(f) {
|
|
3045
3214
|
if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
|
|
3046
3215
|
throw new Error("AXIS1_BAD_BUFFERS");
|
|
3047
3216
|
}
|
|
3048
|
-
if (f.ver !==
|
|
3217
|
+
if (f.ver !== AXIS_VERSION2) throw new Error("AXIS1_BAD_VER");
|
|
3049
3218
|
const hdrLen = encVarint(BigInt(f.hdr.length));
|
|
3050
3219
|
const bodyLen = encVarint(BigInt(f.body.length));
|
|
3051
3220
|
const sigLen = encVarint(BigInt(f.sig.length));
|
|
@@ -3065,13 +3234,14 @@ var MAGIC;
|
|
|
3065
3234
|
var init_axis1_encode = __esm({
|
|
3066
3235
|
"src/codec/axis1.encode.ts"() {
|
|
3067
3236
|
init_tlv_encode();
|
|
3068
|
-
MAGIC = Buffer.from(
|
|
3237
|
+
MAGIC = Buffer.from(AXIS_MAGIC2);
|
|
3069
3238
|
}
|
|
3070
3239
|
});
|
|
3071
3240
|
|
|
3072
3241
|
// src/codec/axis1.signing.ts
|
|
3242
|
+
import { AXIS_MAGIC as AXIS_MAGIC3, AXIS_VERSION as AXIS_VERSION3 } from "@nextera.one/axis-protocol";
|
|
3073
3243
|
function axis1SigningBytes(params) {
|
|
3074
|
-
if (params.ver !==
|
|
3244
|
+
if (params.ver !== AXIS_VERSION3) throw new Error("AXIS1_BAD_VER");
|
|
3075
3245
|
const hdrLen = encVarint(BigInt(params.hdr.length));
|
|
3076
3246
|
const bodyLen = encVarint(BigInt(params.body.length));
|
|
3077
3247
|
const sigLenZero = encVarint(0n);
|
|
@@ -3090,7 +3260,7 @@ var MAGIC2;
|
|
|
3090
3260
|
var init_axis1_signing = __esm({
|
|
3091
3261
|
"src/codec/axis1.signing.ts"() {
|
|
3092
3262
|
init_tlv_encode();
|
|
3093
|
-
MAGIC2 = Buffer.from(
|
|
3263
|
+
MAGIC2 = Buffer.from(AXIS_MAGIC3);
|
|
3094
3264
|
}
|
|
3095
3265
|
});
|
|
3096
3266
|
|
|
@@ -3390,6 +3560,7 @@ var init_tlv2 = __esm({
|
|
|
3390
3560
|
});
|
|
3391
3561
|
|
|
3392
3562
|
// src/types/frame.ts
|
|
3563
|
+
import { AXIS_MAGIC as AXIS_MAGIC4 } from "@nextera.one/axis-protocol";
|
|
3393
3564
|
function decodeAxis1Frame(buf) {
|
|
3394
3565
|
let off = 0;
|
|
3395
3566
|
const magic = buf.subarray(off, off + 5);
|
|
@@ -3424,7 +3595,7 @@ var MAGIC3;
|
|
|
3424
3595
|
var init_frame = __esm({
|
|
3425
3596
|
"src/types/frame.ts"() {
|
|
3426
3597
|
init_tlv2();
|
|
3427
|
-
MAGIC3 = Buffer.from(
|
|
3598
|
+
MAGIC3 = Buffer.from(AXIS_MAGIC4);
|
|
3428
3599
|
}
|
|
3429
3600
|
});
|
|
3430
3601
|
|
|
@@ -3578,7 +3749,52 @@ var init_capabilities = __esm({
|
|
|
3578
3749
|
}
|
|
3579
3750
|
});
|
|
3580
3751
|
|
|
3752
|
+
// src/law/law.types.ts
|
|
3753
|
+
function buildAxisLawEvaluationContext(input) {
|
|
3754
|
+
const metadata = input.metadata ?? {};
|
|
3755
|
+
const packet = input.packet;
|
|
3756
|
+
const packetBody = input.frameBody ?? packet?.body ?? packet?.args ?? void 0;
|
|
3757
|
+
const capsuleId = metadata.capsule_id ?? metadata.capsuleId ?? packet?.capsuleId ?? input.clientId;
|
|
3758
|
+
const audience = input.aud ?? metadata.audience ?? packet?.aud;
|
|
3759
|
+
const tps = metadata.tps ?? packet?.tps ?? packet?.tickTps;
|
|
3760
|
+
return {
|
|
3761
|
+
actorId: input.actorId,
|
|
3762
|
+
intent: input.intent,
|
|
3763
|
+
audience,
|
|
3764
|
+
tps,
|
|
3765
|
+
country: input.country,
|
|
3766
|
+
ip: input.ip,
|
|
3767
|
+
path: input.path,
|
|
3768
|
+
clientId: input.clientId,
|
|
3769
|
+
deviceId: input.deviceId,
|
|
3770
|
+
sessionId: input.sessionId,
|
|
3771
|
+
capsuleId,
|
|
3772
|
+
metadata,
|
|
3773
|
+
packet,
|
|
3774
|
+
frameBody: packetBody
|
|
3775
|
+
};
|
|
3776
|
+
}
|
|
3777
|
+
var init_law_types = __esm({
|
|
3778
|
+
"src/law/law.types.ts"() {
|
|
3779
|
+
}
|
|
3780
|
+
});
|
|
3781
|
+
|
|
3782
|
+
// src/law/index.ts
|
|
3783
|
+
var law_exports = {};
|
|
3784
|
+
__export(law_exports, {
|
|
3785
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext
|
|
3786
|
+
});
|
|
3787
|
+
var init_law = __esm({
|
|
3788
|
+
"src/law/index.ts"() {
|
|
3789
|
+
init_law_types();
|
|
3790
|
+
}
|
|
3791
|
+
});
|
|
3792
|
+
|
|
3581
3793
|
// src/risk/index.ts
|
|
3794
|
+
var risk_exports = {};
|
|
3795
|
+
__export(risk_exports, {
|
|
3796
|
+
RiskDecision: () => RiskDecision
|
|
3797
|
+
});
|
|
3582
3798
|
var RiskDecision;
|
|
3583
3799
|
var init_risk = __esm({
|
|
3584
3800
|
"src/risk/index.ts"() {
|
|
@@ -4630,6 +4846,374 @@ var require_axis_sensor_chain_service = __commonJS({
|
|
|
4630
4846
|
}
|
|
4631
4847
|
});
|
|
4632
4848
|
|
|
4849
|
+
// src/timeline/timeline.engine.ts
|
|
4850
|
+
import { createHash as createHash5, randomBytes as randomBytes6 } from "crypto";
|
|
4851
|
+
function generateId(prefix) {
|
|
4852
|
+
return `${prefix}_${randomBytes6(16).toString("hex")}`;
|
|
4853
|
+
}
|
|
4854
|
+
function sha2566(data) {
|
|
4855
|
+
return createHash5("sha256").update(data).digest("hex");
|
|
4856
|
+
}
|
|
4857
|
+
function hashPayload2(payload) {
|
|
4858
|
+
return sha2566(JSON.stringify(payload));
|
|
4859
|
+
}
|
|
4860
|
+
function diffObjects(a, b) {
|
|
4861
|
+
const diffs = [];
|
|
4862
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
4863
|
+
for (const key of allKeys) {
|
|
4864
|
+
const va = a[key];
|
|
4865
|
+
const vb = b[key];
|
|
4866
|
+
if (JSON.stringify(va) !== JSON.stringify(vb)) {
|
|
4867
|
+
diffs.push({ field: key, original: va, replayed: vb });
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4870
|
+
return diffs;
|
|
4871
|
+
}
|
|
4872
|
+
var TimelineEngine;
|
|
4873
|
+
var init_timeline_engine = __esm({
|
|
4874
|
+
"src/timeline/timeline.engine.ts"() {
|
|
4875
|
+
TimelineEngine = class {
|
|
4876
|
+
constructor(store) {
|
|
4877
|
+
this.store = store;
|
|
4878
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
4879
|
+
}
|
|
4880
|
+
/** Register an intent handler for timeline execution */
|
|
4881
|
+
registerHandler(handler) {
|
|
4882
|
+
this.handlers.set(handler.intent, handler);
|
|
4883
|
+
}
|
|
4884
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4885
|
+
// Record (store a real execution as a timeline event)
|
|
4886
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4887
|
+
async recordEvent(intent, actorId, payload, result, options = {}) {
|
|
4888
|
+
const event = {
|
|
4889
|
+
event_id: generateId("evt"),
|
|
4890
|
+
timeline_id: options.timelineId ?? "prime",
|
|
4891
|
+
branch_id: options.branchId ?? "main",
|
|
4892
|
+
parent_event_id: options.parentEventId ?? null,
|
|
4893
|
+
intent,
|
|
4894
|
+
actor_id: actorId,
|
|
4895
|
+
capsule_id: options.capsuleId,
|
|
4896
|
+
tps_coordinate: options.tpsCoordinate,
|
|
4897
|
+
payload_hash: hashPayload2(payload),
|
|
4898
|
+
result_hash: hashPayload2(result),
|
|
4899
|
+
status: "executed",
|
|
4900
|
+
domain: "prime",
|
|
4901
|
+
determinism: options.determinism ?? "deterministic",
|
|
4902
|
+
witness_id: options.witnessId,
|
|
4903
|
+
created_at: Date.now(),
|
|
4904
|
+
metadata: { payload, result }
|
|
4905
|
+
};
|
|
4906
|
+
await this.store.saveEvent(event);
|
|
4907
|
+
return event;
|
|
4908
|
+
}
|
|
4909
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4910
|
+
// Replay
|
|
4911
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4912
|
+
async replay(request) {
|
|
4913
|
+
const originalEvent = await this.store.getEvent(request.source_event_id);
|
|
4914
|
+
if (!originalEvent) {
|
|
4915
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
4916
|
+
}
|
|
4917
|
+
const handler = this.handlers.get(originalEvent.intent);
|
|
4918
|
+
if (!handler) {
|
|
4919
|
+
throw new Error(`No handler registered for intent '${originalEvent.intent}'`);
|
|
4920
|
+
}
|
|
4921
|
+
const originalPayload = originalEvent.metadata?.payload ?? {};
|
|
4922
|
+
const replayPayload = request.mode === "analytical" && request.override_payload ? request.override_payload : originalPayload;
|
|
4923
|
+
const snapshot = await this.store.getSnapshotByEvent(originalEvent.event_id);
|
|
4924
|
+
const context = {
|
|
4925
|
+
event_id: generateId("evt"),
|
|
4926
|
+
timeline_id: originalEvent.timeline_id,
|
|
4927
|
+
branch_id: `replay_${originalEvent.branch_id}`,
|
|
4928
|
+
domain: "audit",
|
|
4929
|
+
actor_id: originalEvent.actor_id,
|
|
4930
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
4931
|
+
snapshot: snapshot ?? void 0,
|
|
4932
|
+
is_replay: true,
|
|
4933
|
+
is_simulation: false
|
|
4934
|
+
};
|
|
4935
|
+
const startMs = Date.now();
|
|
4936
|
+
const handlerResult = await handler.execute(replayPayload, context);
|
|
4937
|
+
const durationMs = Date.now() - startMs;
|
|
4938
|
+
const replayedEvent = {
|
|
4939
|
+
event_id: context.event_id,
|
|
4940
|
+
timeline_id: originalEvent.timeline_id,
|
|
4941
|
+
branch_id: context.branch_id,
|
|
4942
|
+
parent_event_id: originalEvent.event_id,
|
|
4943
|
+
intent: originalEvent.intent,
|
|
4944
|
+
actor_id: originalEvent.actor_id,
|
|
4945
|
+
capsule_id: originalEvent.capsule_id,
|
|
4946
|
+
tps_coordinate: originalEvent.tps_coordinate,
|
|
4947
|
+
payload_hash: hashPayload2(replayPayload),
|
|
4948
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
4949
|
+
status: "replayed",
|
|
4950
|
+
domain: "audit",
|
|
4951
|
+
determinism: originalEvent.determinism,
|
|
4952
|
+
created_at: Date.now(),
|
|
4953
|
+
metadata: { payload: replayPayload, result: handlerResult.result_data }
|
|
4954
|
+
};
|
|
4955
|
+
await this.store.saveEvent(replayedEvent);
|
|
4956
|
+
const originalResult = originalEvent.metadata?.result ?? {};
|
|
4957
|
+
const differences = diffObjects(originalResult, handlerResult.result_data);
|
|
4958
|
+
const deterministicMatch = originalEvent.result_hash === replayedEvent.result_hash;
|
|
4959
|
+
return {
|
|
4960
|
+
original_event: originalEvent,
|
|
4961
|
+
replayed_event: replayedEvent,
|
|
4962
|
+
mode: request.mode,
|
|
4963
|
+
deterministic_match: deterministicMatch,
|
|
4964
|
+
differences,
|
|
4965
|
+
duration_ms: durationMs
|
|
4966
|
+
};
|
|
4967
|
+
}
|
|
4968
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4969
|
+
// Fork
|
|
4970
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
4971
|
+
async fork(request) {
|
|
4972
|
+
const sourceEvent = await this.store.getEvent(request.source_event_id);
|
|
4973
|
+
if (!sourceEvent) {
|
|
4974
|
+
throw new Error(`Event ${request.source_event_id} not found`);
|
|
4975
|
+
}
|
|
4976
|
+
const handler = this.handlers.get(sourceEvent.intent);
|
|
4977
|
+
if (!handler) {
|
|
4978
|
+
throw new Error(`No handler registered for intent '${sourceEvent.intent}'`);
|
|
4979
|
+
}
|
|
4980
|
+
const branch = {
|
|
4981
|
+
branch_id: generateId("branch"),
|
|
4982
|
+
timeline_id: generateId("timeline"),
|
|
4983
|
+
origin_timeline_id: sourceEvent.timeline_id,
|
|
4984
|
+
origin_event_id: sourceEvent.event_id,
|
|
4985
|
+
branch_type: "fork",
|
|
4986
|
+
creator_subject_id: request.actor_id,
|
|
4987
|
+
purpose: request.purpose,
|
|
4988
|
+
status: "active"
|
|
4989
|
+
};
|
|
4990
|
+
await this.store.saveBranch(branch);
|
|
4991
|
+
const snapshot = {
|
|
4992
|
+
snapshot_id: generateId("snap"),
|
|
4993
|
+
timeline_id: sourceEvent.timeline_id,
|
|
4994
|
+
event_id: sourceEvent.event_id,
|
|
4995
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
4996
|
+
state_hash: hashPayload2(
|
|
4997
|
+
sourceEvent.metadata?.result ?? {}
|
|
4998
|
+
),
|
|
4999
|
+
state_data: sourceEvent.metadata?.result ?? {},
|
|
5000
|
+
created_at: Date.now()
|
|
5001
|
+
};
|
|
5002
|
+
await this.store.saveSnapshot(snapshot);
|
|
5003
|
+
const context = {
|
|
5004
|
+
event_id: generateId("evt"),
|
|
5005
|
+
timeline_id: branch.timeline_id,
|
|
5006
|
+
branch_id: branch.branch_id,
|
|
5007
|
+
domain: "fork",
|
|
5008
|
+
actor_id: request.actor_id,
|
|
5009
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
5010
|
+
snapshot,
|
|
5011
|
+
is_replay: false,
|
|
5012
|
+
is_simulation: false
|
|
5013
|
+
};
|
|
5014
|
+
const handlerResult = await handler.execute(request.new_payload, context);
|
|
5015
|
+
const forkedEvent = {
|
|
5016
|
+
event_id: context.event_id,
|
|
5017
|
+
timeline_id: branch.timeline_id,
|
|
5018
|
+
branch_id: branch.branch_id,
|
|
5019
|
+
parent_event_id: sourceEvent.event_id,
|
|
5020
|
+
intent: sourceEvent.intent,
|
|
5021
|
+
actor_id: request.actor_id,
|
|
5022
|
+
tps_coordinate: sourceEvent.tps_coordinate,
|
|
5023
|
+
payload_hash: hashPayload2(request.new_payload),
|
|
5024
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
5025
|
+
status: "forked",
|
|
5026
|
+
domain: "fork",
|
|
5027
|
+
determinism: sourceEvent.determinism,
|
|
5028
|
+
created_at: Date.now(),
|
|
5029
|
+
metadata: {
|
|
5030
|
+
payload: request.new_payload,
|
|
5031
|
+
result: handlerResult.result_data
|
|
5032
|
+
}
|
|
5033
|
+
};
|
|
5034
|
+
await this.store.saveEvent(forkedEvent);
|
|
5035
|
+
return { branch, forked_event: forkedEvent, snapshot };
|
|
5036
|
+
}
|
|
5037
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5038
|
+
// Simulate
|
|
5039
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5040
|
+
async simulate(request) {
|
|
5041
|
+
const handler = this.handlers.get(request.intent);
|
|
5042
|
+
if (!handler) {
|
|
5043
|
+
throw new Error(`No handler registered for intent '${request.intent}'`);
|
|
5044
|
+
}
|
|
5045
|
+
let snapshot;
|
|
5046
|
+
if (request.from_snapshot_id) {
|
|
5047
|
+
const loaded = await this.store.getSnapshot(request.from_snapshot_id);
|
|
5048
|
+
if (!loaded) {
|
|
5049
|
+
throw new Error(`Snapshot ${request.from_snapshot_id} not found`);
|
|
5050
|
+
}
|
|
5051
|
+
snapshot = loaded;
|
|
5052
|
+
}
|
|
5053
|
+
const branch = {
|
|
5054
|
+
branch_id: generateId("branch"),
|
|
5055
|
+
timeline_id: generateId("timeline"),
|
|
5056
|
+
origin_timeline_id: "prime",
|
|
5057
|
+
origin_event_id: "simulation_origin",
|
|
5058
|
+
branch_type: "simulation",
|
|
5059
|
+
created_at_tps: request.at_tps,
|
|
5060
|
+
creator_subject_id: request.actor_id,
|
|
5061
|
+
purpose: request.purpose,
|
|
5062
|
+
status: "active"
|
|
5063
|
+
};
|
|
5064
|
+
await this.store.saveBranch(branch);
|
|
5065
|
+
const context = {
|
|
5066
|
+
event_id: generateId("evt"),
|
|
5067
|
+
timeline_id: branch.timeline_id,
|
|
5068
|
+
branch_id: branch.branch_id,
|
|
5069
|
+
domain: "shadow",
|
|
5070
|
+
actor_id: request.actor_id,
|
|
5071
|
+
tps_coordinate: request.at_tps,
|
|
5072
|
+
snapshot,
|
|
5073
|
+
is_replay: false,
|
|
5074
|
+
is_simulation: true
|
|
5075
|
+
};
|
|
5076
|
+
const startMs = Date.now();
|
|
5077
|
+
const handlerResult = await handler.execute(request.payload, context);
|
|
5078
|
+
const durationMs = Date.now() - startMs;
|
|
5079
|
+
const simulatedEvent = {
|
|
5080
|
+
event_id: context.event_id,
|
|
5081
|
+
timeline_id: branch.timeline_id,
|
|
5082
|
+
branch_id: branch.branch_id,
|
|
5083
|
+
parent_event_id: null,
|
|
5084
|
+
intent: request.intent,
|
|
5085
|
+
actor_id: request.actor_id,
|
|
5086
|
+
tps_coordinate: request.at_tps,
|
|
5087
|
+
payload_hash: hashPayload2(request.payload),
|
|
5088
|
+
result_hash: hashPayload2(handlerResult.result_data),
|
|
5089
|
+
status: "simulated",
|
|
5090
|
+
domain: "shadow",
|
|
5091
|
+
determinism: "bounded_nondeterministic",
|
|
5092
|
+
created_at: Date.now(),
|
|
5093
|
+
metadata: { payload: request.payload, result: handlerResult.result_data }
|
|
5094
|
+
};
|
|
5095
|
+
await this.store.saveEvent(simulatedEvent);
|
|
5096
|
+
branch.status = "completed";
|
|
5097
|
+
await this.store.saveBranch(branch);
|
|
5098
|
+
return {
|
|
5099
|
+
branch,
|
|
5100
|
+
simulated_event: simulatedEvent,
|
|
5101
|
+
predicted_outcome: handlerResult.result_data,
|
|
5102
|
+
side_effects: handlerResult.side_effects ?? [],
|
|
5103
|
+
duration_ms: durationMs
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5107
|
+
// Compare timelines
|
|
5108
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5109
|
+
async compare(timelineIdA, timelineIdB) {
|
|
5110
|
+
const eventsA = await this.store.getEventsByTimeline(timelineIdA);
|
|
5111
|
+
const eventsB = await this.store.getEventsByTimeline(timelineIdB);
|
|
5112
|
+
eventsA.sort((a, b) => a.created_at - b.created_at);
|
|
5113
|
+
eventsB.sort((a, b) => a.created_at - b.created_at);
|
|
5114
|
+
const maxLen = Math.max(eventsA.length, eventsB.length);
|
|
5115
|
+
const eventPairs = [];
|
|
5116
|
+
let divergencePoint;
|
|
5117
|
+
for (let i = 0; i < maxLen; i++) {
|
|
5118
|
+
const a = eventsA[i];
|
|
5119
|
+
const b = eventsB[i];
|
|
5120
|
+
if (!a || !b) {
|
|
5121
|
+
if (!divergencePoint) {
|
|
5122
|
+
divergencePoint = a?.event_id ?? b?.event_id;
|
|
5123
|
+
}
|
|
5124
|
+
continue;
|
|
5125
|
+
}
|
|
5126
|
+
const match = a.result_hash === b.result_hash;
|
|
5127
|
+
const resultA = a.metadata?.result ?? {};
|
|
5128
|
+
const resultB = b.metadata?.result ?? {};
|
|
5129
|
+
const differences = match ? [] : diffObjects(resultA, resultB);
|
|
5130
|
+
if (!match && !divergencePoint) {
|
|
5131
|
+
divergencePoint = a.event_id;
|
|
5132
|
+
}
|
|
5133
|
+
eventPairs.push({ event_a: a, event_b: b, match, differences });
|
|
5134
|
+
}
|
|
5135
|
+
return {
|
|
5136
|
+
timeline_a: timelineIdA,
|
|
5137
|
+
timeline_b: timelineIdB,
|
|
5138
|
+
event_pairs: eventPairs,
|
|
5139
|
+
divergence_point: divergencePoint
|
|
5140
|
+
};
|
|
5141
|
+
}
|
|
5142
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5143
|
+
// State snapshot management
|
|
5144
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
5145
|
+
async createSnapshot(eventId, stateData) {
|
|
5146
|
+
const event = await this.store.getEvent(eventId);
|
|
5147
|
+
if (!event) {
|
|
5148
|
+
throw new Error(`Event ${eventId} not found`);
|
|
5149
|
+
}
|
|
5150
|
+
const snapshot = {
|
|
5151
|
+
snapshot_id: generateId("snap"),
|
|
5152
|
+
timeline_id: event.timeline_id,
|
|
5153
|
+
event_id: eventId,
|
|
5154
|
+
tps_coordinate: event.tps_coordinate,
|
|
5155
|
+
state_hash: hashPayload2(stateData),
|
|
5156
|
+
state_data: stateData,
|
|
5157
|
+
created_at: Date.now()
|
|
5158
|
+
};
|
|
5159
|
+
await this.store.saveSnapshot(snapshot);
|
|
5160
|
+
return snapshot;
|
|
5161
|
+
}
|
|
5162
|
+
async restoreSnapshot(snapshotId) {
|
|
5163
|
+
const snapshot = await this.store.getSnapshot(snapshotId);
|
|
5164
|
+
if (!snapshot) {
|
|
5165
|
+
throw new Error(`Snapshot ${snapshotId} not found`);
|
|
5166
|
+
}
|
|
5167
|
+
return snapshot;
|
|
5168
|
+
}
|
|
5169
|
+
};
|
|
5170
|
+
}
|
|
5171
|
+
});
|
|
5172
|
+
|
|
5173
|
+
// src/timeline/timeline.store.ts
|
|
5174
|
+
var InMemoryTimelineStore;
|
|
5175
|
+
var init_timeline_store = __esm({
|
|
5176
|
+
"src/timeline/timeline.store.ts"() {
|
|
5177
|
+
InMemoryTimelineStore = class {
|
|
5178
|
+
constructor() {
|
|
5179
|
+
this.events = /* @__PURE__ */ new Map();
|
|
5180
|
+
this.branches = /* @__PURE__ */ new Map();
|
|
5181
|
+
this.snapshots = /* @__PURE__ */ new Map();
|
|
5182
|
+
}
|
|
5183
|
+
async saveEvent(event) {
|
|
5184
|
+
this.events.set(event.event_id, event);
|
|
5185
|
+
}
|
|
5186
|
+
async getEvent(eventId) {
|
|
5187
|
+
return this.events.get(eventId) ?? null;
|
|
5188
|
+
}
|
|
5189
|
+
async getEventsByTimeline(timelineId) {
|
|
5190
|
+
return [...this.events.values()].filter((e) => e.timeline_id === timelineId);
|
|
5191
|
+
}
|
|
5192
|
+
async getEventsByBranch(branchId) {
|
|
5193
|
+
return [...this.events.values()].filter((e) => e.branch_id === branchId);
|
|
5194
|
+
}
|
|
5195
|
+
async saveBranch(branch) {
|
|
5196
|
+
this.branches.set(branch.branch_id, branch);
|
|
5197
|
+
}
|
|
5198
|
+
async getBranch(branchId) {
|
|
5199
|
+
return this.branches.get(branchId) ?? null;
|
|
5200
|
+
}
|
|
5201
|
+
async getBranchesByTimeline(timelineId) {
|
|
5202
|
+
return [...this.branches.values()].filter((b) => b.timeline_id === timelineId);
|
|
5203
|
+
}
|
|
5204
|
+
async saveSnapshot(snapshot) {
|
|
5205
|
+
this.snapshots.set(snapshot.snapshot_id, snapshot);
|
|
5206
|
+
}
|
|
5207
|
+
async getSnapshot(snapshotId) {
|
|
5208
|
+
return this.snapshots.get(snapshotId) ?? null;
|
|
5209
|
+
}
|
|
5210
|
+
async getSnapshotByEvent(eventId) {
|
|
5211
|
+
return [...this.snapshots.values()].find((s) => s.event_id === eventId) ?? null;
|
|
5212
|
+
}
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5215
|
+
});
|
|
5216
|
+
|
|
4633
5217
|
// src/utils/axis-tlv-codec.ts
|
|
4634
5218
|
function encodeAxisTlvDto(dtoClass, data) {
|
|
4635
5219
|
const schema = (0, import_dto_schema.extractDtoSchema)(dtoClass);
|
|
@@ -4722,96 +5306,1808 @@ var init_loom_types = __esm({
|
|
|
4722
5306
|
}
|
|
4723
5307
|
});
|
|
4724
5308
|
|
|
4725
|
-
// src/
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
5309
|
+
// src/loom/loom.engine.ts
|
|
5310
|
+
import { createHash as createHash6, randomBytes as randomBytes7 } from "crypto";
|
|
5311
|
+
import { sign as sign2 } from "tweetnacl";
|
|
5312
|
+
function sha2567(data) {
|
|
5313
|
+
return createHash6("sha256").update(data).digest("hex");
|
|
5314
|
+
}
|
|
5315
|
+
function hexToUint8(hex) {
|
|
5316
|
+
const bytes2 = new Uint8Array(hex.length / 2);
|
|
5317
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
5318
|
+
bytes2[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
5319
|
+
}
|
|
5320
|
+
return bytes2;
|
|
5321
|
+
}
|
|
5322
|
+
function uint8ToHex(bytes2) {
|
|
5323
|
+
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
5324
|
+
}
|
|
5325
|
+
function b64ToUint8(b64) {
|
|
5326
|
+
const bin = Buffer.from(b64, "base64");
|
|
5327
|
+
return new Uint8Array(bin.buffer, bin.byteOffset, bin.byteLength);
|
|
5328
|
+
}
|
|
5329
|
+
function uint8ToB64(bytes2) {
|
|
5330
|
+
return Buffer.from(bytes2).toString("base64");
|
|
5331
|
+
}
|
|
5332
|
+
function createPresenceChallenge(declaration, ttlMs = DEFAULT_PRESENCE_TTL_MS) {
|
|
5333
|
+
const now = Date.now();
|
|
5334
|
+
const nonce = randomBytes7(32).toString("hex");
|
|
5335
|
+
const challengeId = sha2567(`${declaration.softid}:${nonce}:${now}`);
|
|
5336
|
+
return {
|
|
5337
|
+
challenge_id: challengeId,
|
|
5338
|
+
nonce,
|
|
5339
|
+
temporal_anchor: now,
|
|
5340
|
+
ttl_ms: ttlMs,
|
|
5341
|
+
expires_at: now + ttlMs
|
|
5342
|
+
};
|
|
5343
|
+
}
|
|
5344
|
+
function presenceSigningData(challenge, deviceMeta) {
|
|
5345
|
+
return JSON.stringify({
|
|
5346
|
+
nonce: challenge.nonce,
|
|
5347
|
+
temporal_anchor: challenge.temporal_anchor,
|
|
5348
|
+
device_meta: deviceMeta ?? null
|
|
5349
|
+
});
|
|
5350
|
+
}
|
|
5351
|
+
function signPresenceChallenge(challenge, privateKeyHex, publicKeyHex, declaration, kid) {
|
|
5352
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
5353
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
5354
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5355
|
+
const signature = sign2.detached(msgBytes, secretKey);
|
|
5356
|
+
return {
|
|
5357
|
+
challenge_id: challenge.challenge_id,
|
|
5358
|
+
signature: uint8ToHex(signature),
|
|
5359
|
+
public_key: publicKeyHex,
|
|
5360
|
+
kid
|
|
5361
|
+
};
|
|
5362
|
+
}
|
|
5363
|
+
function verifyPresenceProof(challenge, proof, declaration, durationMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
5364
|
+
if (Date.now() > challenge.expires_at) {
|
|
5365
|
+
return { valid: false, error: "Challenge expired", code: "CHALLENGE_EXPIRED" };
|
|
5366
|
+
}
|
|
5367
|
+
if (proof.challenge_id !== challenge.challenge_id) {
|
|
5368
|
+
return { valid: false, error: "Challenge ID mismatch", code: "CHALLENGE_MISMATCH" };
|
|
5369
|
+
}
|
|
5370
|
+
const data = presenceSigningData(challenge, declaration.device_meta);
|
|
5371
|
+
const msgBytes = new TextEncoder().encode(data);
|
|
5372
|
+
const sigBytes = hexToUint8(proof.signature);
|
|
5373
|
+
const pubBytes = hexToUint8(proof.public_key);
|
|
5374
|
+
let isValid;
|
|
5375
|
+
try {
|
|
5376
|
+
isValid = sign2.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5377
|
+
} catch {
|
|
5378
|
+
return { valid: false, error: "Signature verification failed", code: "SIG_INVALID" };
|
|
5379
|
+
}
|
|
5380
|
+
if (!isValid) {
|
|
5381
|
+
return { valid: false, error: "Invalid signature", code: "SIG_INVALID" };
|
|
5382
|
+
}
|
|
5383
|
+
const now = Date.now();
|
|
5384
|
+
const presenceId = sha2567(
|
|
5385
|
+
`${proof.public_key}:${challenge.nonce}:${challenge.temporal_anchor}`
|
|
5386
|
+
);
|
|
5387
|
+
const anchorReflection = sha2567(
|
|
5388
|
+
`ar:openlogs:loom:${proof.public_key}`
|
|
5389
|
+
);
|
|
5390
|
+
const receipt = {
|
|
5391
|
+
presence_id: presenceId,
|
|
5392
|
+
softid: declaration.softid,
|
|
5393
|
+
anchor_reflection: anchorReflection,
|
|
5394
|
+
scope: {
|
|
5395
|
+
device_fingerprint: declaration.device_meta?.fingerprint
|
|
5396
|
+
},
|
|
5397
|
+
issued_at: now,
|
|
5398
|
+
expires_at: now + durationMs
|
|
5399
|
+
};
|
|
5400
|
+
return { valid: true, presence: receipt };
|
|
5401
|
+
}
|
|
5402
|
+
function getPresenceStatus(receipt) {
|
|
5403
|
+
const now = Date.now();
|
|
5404
|
+
if (now > receipt.expires_at) return "expired";
|
|
5405
|
+
return "active";
|
|
5406
|
+
}
|
|
5407
|
+
function renewPresence(receipt, extensionMs = DEFAULT_PRESENCE_DURATION_MS) {
|
|
5408
|
+
const now = Date.now();
|
|
5409
|
+
return {
|
|
5410
|
+
...receipt,
|
|
5411
|
+
renewed_at: now,
|
|
5412
|
+
expires_at: now + extensionMs
|
|
5413
|
+
};
|
|
5414
|
+
}
|
|
5415
|
+
function createWrit(body, meta, thread, privateKeyHex, kid) {
|
|
5416
|
+
const head = { tid: thread.tid, seq: thread.seq };
|
|
5417
|
+
const writMeta = { ...meta, prev: thread.prevHash };
|
|
5418
|
+
const unsigned = { head, body, meta: writMeta };
|
|
5419
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
5420
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5421
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5422
|
+
const signature = sign2.detached(msgBytes, secretKey);
|
|
5423
|
+
const sig = {
|
|
5424
|
+
alg: "ed25519",
|
|
5425
|
+
value: uint8ToB64(signature),
|
|
5426
|
+
kid
|
|
5427
|
+
};
|
|
5428
|
+
return { head, body, meta: writMeta, sig };
|
|
5429
|
+
}
|
|
5430
|
+
function validateWrit(writ, publicKeyHex, threadState, grants) {
|
|
5431
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
5432
|
+
if (now < writ.meta.iat) {
|
|
5433
|
+
return {
|
|
5434
|
+
valid: false,
|
|
5435
|
+
error: "Writ not yet valid (iat in future)",
|
|
5436
|
+
code: "TEMPORAL_NOT_YET",
|
|
5437
|
+
gate_failed: "temporal"
|
|
5438
|
+
};
|
|
5439
|
+
}
|
|
5440
|
+
if (now > writ.meta.exp) {
|
|
5441
|
+
return {
|
|
5442
|
+
valid: false,
|
|
5443
|
+
error: "Writ expired",
|
|
5444
|
+
code: "TEMPORAL_EXPIRED",
|
|
5445
|
+
gate_failed: "temporal"
|
|
5446
|
+
};
|
|
5447
|
+
}
|
|
5448
|
+
if (threadState) {
|
|
5449
|
+
if (writ.head.tid !== threadState.thread_id) {
|
|
5450
|
+
return {
|
|
5451
|
+
valid: false,
|
|
5452
|
+
error: "Thread ID mismatch",
|
|
5453
|
+
code: "CAUSAL_TID",
|
|
5454
|
+
gate_failed: "causal"
|
|
5455
|
+
};
|
|
5456
|
+
}
|
|
5457
|
+
if (writ.head.seq !== threadState.sequence + 1) {
|
|
5458
|
+
return {
|
|
5459
|
+
valid: false,
|
|
5460
|
+
error: `Expected seq ${threadState.sequence + 1}, got ${writ.head.seq}`,
|
|
5461
|
+
code: "CAUSAL_SEQ",
|
|
5462
|
+
gate_failed: "causal"
|
|
5463
|
+
};
|
|
5464
|
+
}
|
|
5465
|
+
if (writ.meta.prev !== threadState.last_receipt_hash) {
|
|
5466
|
+
return {
|
|
5467
|
+
valid: false,
|
|
5468
|
+
error: "Previous receipt hash mismatch",
|
|
5469
|
+
code: "CAUSAL_PREV",
|
|
5470
|
+
gate_failed: "causal"
|
|
5471
|
+
};
|
|
5472
|
+
}
|
|
5473
|
+
} else {
|
|
5474
|
+
if (writ.head.seq !== 1) {
|
|
5475
|
+
return {
|
|
5476
|
+
valid: false,
|
|
5477
|
+
error: "First writ in thread must have seq=1",
|
|
5478
|
+
code: "CAUSAL_FIRST_SEQ",
|
|
5479
|
+
gate_failed: "causal"
|
|
5480
|
+
};
|
|
5481
|
+
}
|
|
5482
|
+
if (writ.meta.prev !== "") {
|
|
5483
|
+
return {
|
|
5484
|
+
valid: false,
|
|
5485
|
+
error: "First writ must have empty prev hash",
|
|
5486
|
+
code: "CAUSAL_FIRST_PREV",
|
|
5487
|
+
gate_failed: "causal"
|
|
5488
|
+
};
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
if (writ.body.law !== "self") {
|
|
5492
|
+
const matchingGrant = grants.find(
|
|
5493
|
+
(g) => g.grant_id === writ.body.law && g.subject === writ.body.who && grantCoversAction(g, writ.body.act, writ.body.res, now)
|
|
5494
|
+
);
|
|
5495
|
+
if (!matchingGrant) {
|
|
5496
|
+
return {
|
|
5497
|
+
valid: false,
|
|
5498
|
+
error: `No valid grant found for law=${writ.body.law}`,
|
|
5499
|
+
code: "LEGAL_NO_GRANT",
|
|
5500
|
+
gate_failed: "legal"
|
|
5501
|
+
};
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
const unsigned = {
|
|
5505
|
+
head: writ.head,
|
|
5506
|
+
body: writ.body,
|
|
5507
|
+
meta: writ.meta
|
|
5508
|
+
};
|
|
5509
|
+
const canonical = canonicalizeWrit(unsigned);
|
|
5510
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5511
|
+
const sigBytes = b64ToUint8(writ.sig.value);
|
|
5512
|
+
const pubBytes = hexToUint8(publicKeyHex);
|
|
5513
|
+
let sigValid;
|
|
5514
|
+
try {
|
|
5515
|
+
sigValid = sign2.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5516
|
+
} catch {
|
|
5517
|
+
return {
|
|
5518
|
+
valid: false,
|
|
5519
|
+
error: "Signature verification failed",
|
|
5520
|
+
code: "AUTH_SIG_FAIL",
|
|
5521
|
+
gate_failed: "authentic"
|
|
5522
|
+
};
|
|
5523
|
+
}
|
|
5524
|
+
if (!sigValid) {
|
|
5525
|
+
return {
|
|
5526
|
+
valid: false,
|
|
5527
|
+
error: "Invalid signature",
|
|
5528
|
+
code: "AUTH_SIG_INVALID",
|
|
5529
|
+
gate_failed: "authentic"
|
|
5530
|
+
};
|
|
5531
|
+
}
|
|
5532
|
+
return { valid: true, writ };
|
|
5533
|
+
}
|
|
5534
|
+
function grantCoversAction(grant, action, resource, nowUnix) {
|
|
5535
|
+
if (nowUnix < grant.meta.iat || nowUnix > grant.meta.exp) {
|
|
5536
|
+
return false;
|
|
5537
|
+
}
|
|
5538
|
+
return grant.caps.some(
|
|
5539
|
+
(cap) => matchOec(cap.oec, action) && matchScope(cap.scope, resource)
|
|
5540
|
+
);
|
|
5541
|
+
}
|
|
5542
|
+
function matchOec(pattern, action) {
|
|
5543
|
+
if (pattern === "*") return true;
|
|
5544
|
+
if (pattern === action) return true;
|
|
5545
|
+
if (pattern.endsWith(".*")) {
|
|
5546
|
+
const prefix = pattern.slice(0, -2);
|
|
5547
|
+
return action.startsWith(prefix + ".");
|
|
5548
|
+
}
|
|
5549
|
+
return false;
|
|
5550
|
+
}
|
|
5551
|
+
function matchScope(pattern, resource) {
|
|
5552
|
+
if (pattern === "*") return true;
|
|
5553
|
+
if (pattern === resource) return true;
|
|
5554
|
+
if (pattern.includes("*")) {
|
|
5555
|
+
const regex = new RegExp(
|
|
5556
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*/g, "[^:]*") + "$"
|
|
5557
|
+
);
|
|
5558
|
+
return regex.test(resource);
|
|
5559
|
+
}
|
|
5560
|
+
return false;
|
|
5561
|
+
}
|
|
5562
|
+
function getGrantStatus(grant, revocations) {
|
|
5563
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
5564
|
+
const revoked = revocations.find(
|
|
5565
|
+
(r) => r.target_type === "grant" && r.target_id === grant.grant_id
|
|
5566
|
+
);
|
|
5567
|
+
if (revoked && revoked.effective_at <= now * 1e3) {
|
|
5568
|
+
return "revoked";
|
|
5569
|
+
}
|
|
5570
|
+
if (now > grant.meta.exp) return "expired";
|
|
5571
|
+
return "active";
|
|
5572
|
+
}
|
|
5573
|
+
function validateGrant(grant, issuerPublicKeyHex) {
|
|
5574
|
+
const unsigned = {
|
|
5575
|
+
grant_id: grant.grant_id,
|
|
5576
|
+
issuer: grant.issuer,
|
|
5577
|
+
subject: grant.subject,
|
|
5578
|
+
grant_type: grant.grant_type,
|
|
5579
|
+
caps: grant.caps,
|
|
5580
|
+
meta: grant.meta
|
|
5581
|
+
};
|
|
5582
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
5583
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5584
|
+
const sigBytes = b64ToUint8(grant.sig.value);
|
|
5585
|
+
const pubBytes = hexToUint8(issuerPublicKeyHex);
|
|
5586
|
+
let valid;
|
|
5587
|
+
try {
|
|
5588
|
+
valid = sign2.detached.verify(msgBytes, sigBytes, pubBytes);
|
|
5589
|
+
} catch {
|
|
5590
|
+
return { valid: false, error: "Grant signature verification failed", code: "GRANT_SIG_FAIL" };
|
|
5591
|
+
}
|
|
5592
|
+
if (!valid) {
|
|
5593
|
+
return { valid: false, error: "Invalid grant signature", code: "GRANT_SIG_INVALID" };
|
|
5594
|
+
}
|
|
5595
|
+
return { valid: true, grant };
|
|
5596
|
+
}
|
|
5597
|
+
function createGrant(grantId, issuer, subject, grantType, caps, meta, privateKeyHex, kid) {
|
|
5598
|
+
const unsigned = {
|
|
5599
|
+
grant_id: grantId,
|
|
5600
|
+
issuer,
|
|
5601
|
+
subject,
|
|
5602
|
+
grant_type: grantType,
|
|
5603
|
+
caps,
|
|
5604
|
+
meta
|
|
5605
|
+
};
|
|
5606
|
+
const canonical = canonicalizeGrant(unsigned);
|
|
5607
|
+
const msgBytes = new TextEncoder().encode(canonical);
|
|
5608
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5609
|
+
const signature = sign2.detached(msgBytes, secretKey);
|
|
5610
|
+
return {
|
|
5611
|
+
...unsigned,
|
|
5612
|
+
sig: {
|
|
5613
|
+
alg: "ed25519",
|
|
5614
|
+
value: uint8ToB64(signature),
|
|
5615
|
+
kid
|
|
5616
|
+
}
|
|
5617
|
+
};
|
|
5618
|
+
}
|
|
5619
|
+
function createReceipt(writ, effect, prevReceipt, metadata) {
|
|
5620
|
+
const now = Date.now();
|
|
5621
|
+
const sequence = prevReceipt ? prevReceipt.sequence + 1 : 1;
|
|
5622
|
+
const prevHash = prevReceipt?.hash ?? null;
|
|
5623
|
+
const writHash = sha2567(canonicalizeWrit({
|
|
5624
|
+
head: writ.head,
|
|
5625
|
+
body: writ.body,
|
|
5626
|
+
meta: writ.meta
|
|
5627
|
+
}));
|
|
5628
|
+
const hashInput = [
|
|
5629
|
+
prevHash ?? "",
|
|
5630
|
+
writHash,
|
|
5631
|
+
writ.head.tid,
|
|
5632
|
+
String(sequence),
|
|
5633
|
+
effect,
|
|
5634
|
+
String(now)
|
|
5635
|
+
].join(":");
|
|
5636
|
+
const receiptHash = sha2567(hashInput);
|
|
5637
|
+
const receiptId = sha2567(`receipt:${receiptHash}:${now}`);
|
|
5638
|
+
return {
|
|
5639
|
+
receipt_id: receiptId,
|
|
5640
|
+
writ_hash: writHash,
|
|
5641
|
+
thread_id: writ.head.tid,
|
|
5642
|
+
sequence,
|
|
5643
|
+
effect,
|
|
5644
|
+
hash: receiptHash,
|
|
5645
|
+
prev_hash: prevHash,
|
|
5646
|
+
executed_at: now,
|
|
5647
|
+
metadata
|
|
5648
|
+
};
|
|
5649
|
+
}
|
|
5650
|
+
function verifyReceiptChain(receipts) {
|
|
5651
|
+
if (receipts.length === 0) return { valid: true };
|
|
5652
|
+
const sorted = [...receipts].sort((a, b) => a.sequence - b.sequence);
|
|
5653
|
+
if (sorted[0].prev_hash !== null) {
|
|
5654
|
+
return {
|
|
5655
|
+
valid: false,
|
|
5656
|
+
brokenAt: 0,
|
|
5657
|
+
error: "First receipt must have null prev_hash"
|
|
5658
|
+
};
|
|
5659
|
+
}
|
|
5660
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
5661
|
+
if (sorted[i].prev_hash !== sorted[i - 1].hash) {
|
|
5662
|
+
return {
|
|
5663
|
+
valid: false,
|
|
5664
|
+
brokenAt: i,
|
|
5665
|
+
error: `Receipt ${i} prev_hash does not match receipt ${i - 1} hash`
|
|
5666
|
+
};
|
|
5667
|
+
}
|
|
5668
|
+
}
|
|
5669
|
+
return { valid: true };
|
|
5670
|
+
}
|
|
5671
|
+
function updateThreadState(receipt, softid) {
|
|
5672
|
+
return {
|
|
5673
|
+
thread_id: receipt.thread_id,
|
|
5674
|
+
softid,
|
|
5675
|
+
last_receipt_hash: receipt.hash,
|
|
5676
|
+
sequence: receipt.sequence,
|
|
5677
|
+
updated_at: receipt.executed_at
|
|
5678
|
+
};
|
|
5679
|
+
}
|
|
5680
|
+
function createRevocation(targetType, targetId, issuerSoftid, privateKeyHex, reason) {
|
|
5681
|
+
const now = Date.now();
|
|
5682
|
+
const revocationId = sha2567(`revoke:${targetType}:${targetId}:${now}`);
|
|
5683
|
+
const payload = JSON.stringify({
|
|
5684
|
+
revocation_id: revocationId,
|
|
5685
|
+
target_type: targetType,
|
|
5686
|
+
target_id: targetId,
|
|
5687
|
+
issuer_softid: issuerSoftid,
|
|
5688
|
+
effective_at: now,
|
|
5689
|
+
reason: reason ?? null
|
|
5690
|
+
});
|
|
5691
|
+
const msgBytes = new TextEncoder().encode(payload);
|
|
5692
|
+
const secretKey = hexToUint8(privateKeyHex);
|
|
5693
|
+
const signature = sign2.detached(msgBytes, secretKey);
|
|
5694
|
+
return {
|
|
5695
|
+
revocation_id: revocationId,
|
|
5696
|
+
target_type: targetType,
|
|
5697
|
+
target_id: targetId,
|
|
5698
|
+
issuer_softid: issuerSoftid,
|
|
5699
|
+
reason,
|
|
5700
|
+
effective_at: now,
|
|
5701
|
+
sig_value: uint8ToHex(signature)
|
|
5702
|
+
};
|
|
5703
|
+
}
|
|
5704
|
+
function isRevoked(targetType, targetId, revocations) {
|
|
5705
|
+
const now = Date.now();
|
|
5706
|
+
return revocations.some(
|
|
5707
|
+
(r) => r.target_type === targetType && r.target_id === targetId && r.effective_at <= now
|
|
5708
|
+
);
|
|
5709
|
+
}
|
|
5710
|
+
function executeLoomPipeline(writ, publicKeyHex, presence, threadState, grants, revocations, prevReceipt) {
|
|
5711
|
+
const presenceStatus = getPresenceStatus(presence);
|
|
5712
|
+
if (presenceStatus !== "active") {
|
|
5713
|
+
return { valid: false, error: "Presence not active", code: "PRESENCE_INACTIVE" };
|
|
5714
|
+
}
|
|
5715
|
+
if (isRevoked("presence", presence.presence_id, revocations)) {
|
|
5716
|
+
return { valid: false, error: "Presence revoked", code: "PRESENCE_REVOKED" };
|
|
5717
|
+
}
|
|
5718
|
+
const activeGrants = grants.filter(
|
|
5719
|
+
(g) => getGrantStatus(g, revocations) === "active"
|
|
5720
|
+
);
|
|
5721
|
+
const writResult = validateWrit(writ, publicKeyHex, threadState, activeGrants);
|
|
5722
|
+
if (!writResult.valid) {
|
|
5723
|
+
return { valid: false, error: writResult.error, code: writResult.code };
|
|
5724
|
+
}
|
|
5725
|
+
const receipt = createReceipt(writ, "ALLOW", prevReceipt);
|
|
5726
|
+
const newThreadState = updateThreadState(receipt, writ.body.who);
|
|
5727
|
+
return {
|
|
5728
|
+
receipt,
|
|
5729
|
+
threadState: newThreadState,
|
|
5730
|
+
writValidation: writResult
|
|
5731
|
+
};
|
|
5732
|
+
}
|
|
5733
|
+
var DEFAULT_PRESENCE_TTL_MS, DEFAULT_PRESENCE_DURATION_MS;
|
|
5734
|
+
var init_loom_engine = __esm({
|
|
5735
|
+
"src/loom/loom.engine.ts"() {
|
|
5736
|
+
init_loom_types();
|
|
5737
|
+
DEFAULT_PRESENCE_TTL_MS = 5e3;
|
|
5738
|
+
DEFAULT_PRESENCE_DURATION_MS = 30 * 60 * 1e3;
|
|
5739
|
+
}
|
|
5740
|
+
});
|
|
5741
|
+
|
|
5742
|
+
// src/idel/idel.compiler.ts
|
|
5743
|
+
function validateType(value, expectedType) {
|
|
5744
|
+
switch (expectedType) {
|
|
5745
|
+
case "string":
|
|
5746
|
+
return typeof value === "string";
|
|
5747
|
+
case "number":
|
|
5748
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
5749
|
+
case "boolean":
|
|
5750
|
+
return typeof value === "boolean";
|
|
5751
|
+
case "object":
|
|
5752
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5753
|
+
case "array":
|
|
5754
|
+
return Array.isArray(value);
|
|
5755
|
+
default:
|
|
5756
|
+
return true;
|
|
5757
|
+
}
|
|
5758
|
+
}
|
|
5759
|
+
function assessRisk(schema, proposal, constraints) {
|
|
5760
|
+
const factors = [];
|
|
5761
|
+
let score = 0;
|
|
5762
|
+
const baseRiskMap = {
|
|
5763
|
+
none: 0,
|
|
5764
|
+
low: 0.1,
|
|
5765
|
+
medium: 0.3,
|
|
5766
|
+
high: 0.6,
|
|
5767
|
+
critical: 0.9
|
|
5768
|
+
};
|
|
5769
|
+
score = baseRiskMap[schema.risk_level] ?? 0;
|
|
5770
|
+
if (schema.risk_level !== "none") {
|
|
5771
|
+
factors.push(`Base risk: ${schema.risk_level}`);
|
|
5772
|
+
}
|
|
5773
|
+
if (schema.has_side_effects) {
|
|
5774
|
+
score += 0.1;
|
|
5775
|
+
factors.push("Has side effects");
|
|
5776
|
+
}
|
|
5777
|
+
if (!schema.reversible) {
|
|
5778
|
+
score += 0.1;
|
|
5779
|
+
factors.push("Not reversible");
|
|
5780
|
+
}
|
|
5781
|
+
const failed = constraints.filter((c) => !c.satisfied);
|
|
5782
|
+
if (failed.length > 0) {
|
|
5783
|
+
score += 0.05 * failed.length;
|
|
5784
|
+
factors.push(`${failed.length} unsatisfied constraint(s)`);
|
|
5785
|
+
}
|
|
5786
|
+
score = Math.min(score, 1);
|
|
5787
|
+
let level;
|
|
5788
|
+
if (score <= 0) level = "none";
|
|
5789
|
+
else if (score <= 0.2) level = "low";
|
|
5790
|
+
else if (score <= 0.5) level = "medium";
|
|
5791
|
+
else if (score <= 0.8) level = "high";
|
|
5792
|
+
else level = "critical";
|
|
5793
|
+
return { level, score, factors };
|
|
5794
|
+
}
|
|
5795
|
+
var IdelSchemaRegistry, IdelCompiler;
|
|
5796
|
+
var init_idel_compiler = __esm({
|
|
5797
|
+
"src/idel/idel.compiler.ts"() {
|
|
5798
|
+
IdelSchemaRegistry = class {
|
|
5799
|
+
constructor() {
|
|
5800
|
+
this.schemas = /* @__PURE__ */ new Map();
|
|
5801
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
5802
|
+
}
|
|
5803
|
+
register(schema) {
|
|
5804
|
+
this.schemas.set(schema.intent, schema);
|
|
5805
|
+
}
|
|
5806
|
+
registerAlias(alias, intent) {
|
|
5807
|
+
this.aliases.set(alias.toLowerCase(), intent);
|
|
5808
|
+
}
|
|
5809
|
+
get(intent) {
|
|
5810
|
+
return this.schemas.get(intent);
|
|
5811
|
+
}
|
|
5812
|
+
resolve(raw) {
|
|
5813
|
+
const exact = this.schemas.get(raw);
|
|
5814
|
+
if (exact) return exact;
|
|
5815
|
+
const aliased = this.aliases.get(raw.toLowerCase());
|
|
5816
|
+
if (aliased) return this.schemas.get(aliased);
|
|
5817
|
+
const candidates = [...this.schemas.keys()].filter(
|
|
5818
|
+
(k) => k.startsWith(raw + ".") || k.toLowerCase().includes(raw.toLowerCase())
|
|
5819
|
+
);
|
|
5820
|
+
if (candidates.length === 1) {
|
|
5821
|
+
return this.schemas.get(candidates[0]);
|
|
5822
|
+
}
|
|
5823
|
+
return void 0;
|
|
5824
|
+
}
|
|
5825
|
+
/**
|
|
5826
|
+
* Find all schemas that partially match the raw input.
|
|
5827
|
+
* Returns scored candidates for ambiguity resolution.
|
|
5828
|
+
*/
|
|
5829
|
+
findCandidates(raw) {
|
|
5830
|
+
const normalized = raw.toLowerCase().trim();
|
|
5831
|
+
const results = [];
|
|
5832
|
+
for (const [key, schema] of this.schemas) {
|
|
5833
|
+
let score = 0;
|
|
5834
|
+
if (key === raw) {
|
|
5835
|
+
score = 1;
|
|
5836
|
+
} else if (key.toLowerCase() === normalized) {
|
|
5837
|
+
score = 0.95;
|
|
5838
|
+
} else if (this.aliases.get(normalized) === key) {
|
|
5839
|
+
score = 0.9;
|
|
5840
|
+
} else if (key.toLowerCase().startsWith(normalized)) {
|
|
5841
|
+
score = 0.7;
|
|
5842
|
+
} else if (key.toLowerCase().includes(normalized)) {
|
|
5843
|
+
score = 0.5;
|
|
5844
|
+
} else if (schema.tags?.some((t) => t.toLowerCase().includes(normalized))) {
|
|
5845
|
+
score = 0.4;
|
|
5846
|
+
} else if (schema.description.toLowerCase().includes(normalized)) {
|
|
5847
|
+
score = 0.3;
|
|
5848
|
+
}
|
|
5849
|
+
if (score > 0) {
|
|
5850
|
+
results.push({ schema, score });
|
|
5851
|
+
}
|
|
5852
|
+
}
|
|
5853
|
+
return results.sort((a, b) => b.score - a.score);
|
|
5854
|
+
}
|
|
5855
|
+
list() {
|
|
5856
|
+
return [...this.schemas.values()];
|
|
5857
|
+
}
|
|
5858
|
+
};
|
|
5859
|
+
IdelCompiler = class {
|
|
5860
|
+
constructor(registry) {
|
|
5861
|
+
this.registry = registry;
|
|
5862
|
+
}
|
|
5863
|
+
/**
|
|
5864
|
+
* Compile a raw intent proposal into a validated, executable structure.
|
|
5865
|
+
*/
|
|
5866
|
+
compile(proposal) {
|
|
5867
|
+
const errors = [];
|
|
5868
|
+
const candidates = this.registry.findCandidates(proposal.raw);
|
|
5869
|
+
if (candidates.length === 0) {
|
|
5870
|
+
return {
|
|
5871
|
+
ok: false,
|
|
5872
|
+
errors: [{
|
|
5873
|
+
code: "IDEL_UNKNOWN_INTENT",
|
|
5874
|
+
message: `No intent found matching '${proposal.raw}'`
|
|
5875
|
+
}]
|
|
5876
|
+
};
|
|
5877
|
+
}
|
|
5878
|
+
const best = candidates[0];
|
|
5879
|
+
const schema = best.schema;
|
|
5880
|
+
const alternatives = candidates.slice(1, 4).filter((c) => c.score >= 0.3).map((c) => ({
|
|
5881
|
+
intent: c.schema.intent,
|
|
5882
|
+
confidence: c.score,
|
|
5883
|
+
reason: c.schema.description
|
|
5884
|
+
}));
|
|
5885
|
+
const constraints = [];
|
|
5886
|
+
const clarifications = [];
|
|
5887
|
+
const params = { ...proposal.params };
|
|
5888
|
+
for (const paramSchema of schema.params) {
|
|
5889
|
+
const value = params[paramSchema.name];
|
|
5890
|
+
if (paramSchema.required && value === void 0) {
|
|
5891
|
+
if (paramSchema.default !== void 0) {
|
|
5892
|
+
params[paramSchema.name] = paramSchema.default;
|
|
5893
|
+
constraints.push({
|
|
5894
|
+
kind: "required_param",
|
|
5895
|
+
field: paramSchema.name,
|
|
5896
|
+
description: `Defaulted to ${JSON.stringify(paramSchema.default)}`,
|
|
5897
|
+
satisfied: true,
|
|
5898
|
+
value: paramSchema.default
|
|
5899
|
+
});
|
|
5900
|
+
} else {
|
|
5901
|
+
constraints.push({
|
|
5902
|
+
kind: "required_param",
|
|
5903
|
+
field: paramSchema.name,
|
|
5904
|
+
description: `Required parameter '${paramSchema.name}' is missing`,
|
|
5905
|
+
satisfied: false
|
|
5906
|
+
});
|
|
5907
|
+
clarifications.push({
|
|
5908
|
+
id: `clarify_${paramSchema.name}`,
|
|
5909
|
+
question: paramSchema.description ?? `What is the ${paramSchema.name}?`,
|
|
5910
|
+
field: paramSchema.name,
|
|
5911
|
+
options: paramSchema.enum?.map(String),
|
|
5912
|
+
required: true
|
|
5913
|
+
});
|
|
5914
|
+
}
|
|
5915
|
+
continue;
|
|
5916
|
+
}
|
|
5917
|
+
if (value === void 0) continue;
|
|
5918
|
+
const typeValid = validateType(value, paramSchema.type);
|
|
5919
|
+
constraints.push({
|
|
5920
|
+
kind: "type_check",
|
|
5921
|
+
field: paramSchema.name,
|
|
5922
|
+
description: `Must be ${paramSchema.type}`,
|
|
5923
|
+
satisfied: typeValid,
|
|
5924
|
+
value,
|
|
5925
|
+
expected: paramSchema.type
|
|
5926
|
+
});
|
|
5927
|
+
if (!typeValid) {
|
|
5928
|
+
errors.push({
|
|
5929
|
+
code: "IDEL_TYPE_ERROR",
|
|
5930
|
+
message: `Parameter '${paramSchema.name}' must be ${paramSchema.type}, got ${typeof value}`,
|
|
5931
|
+
field: paramSchema.name
|
|
5932
|
+
});
|
|
5933
|
+
}
|
|
5934
|
+
if (paramSchema.min !== void 0 || paramSchema.max !== void 0) {
|
|
5935
|
+
const numVal = typeof value === "number" ? value : Number(value);
|
|
5936
|
+
const inRange = (paramSchema.min === void 0 || numVal >= paramSchema.min) && (paramSchema.max === void 0 || numVal <= paramSchema.max);
|
|
5937
|
+
constraints.push({
|
|
5938
|
+
kind: "range",
|
|
5939
|
+
field: paramSchema.name,
|
|
5940
|
+
description: `Must be between ${paramSchema.min ?? "-\u221E"} and ${paramSchema.max ?? "\u221E"}`,
|
|
5941
|
+
satisfied: inRange,
|
|
5942
|
+
value: numVal
|
|
5943
|
+
});
|
|
5944
|
+
}
|
|
5945
|
+
if (paramSchema.pattern) {
|
|
5946
|
+
const matches = new RegExp(paramSchema.pattern).test(String(value));
|
|
5947
|
+
constraints.push({
|
|
5948
|
+
kind: "pattern",
|
|
5949
|
+
field: paramSchema.name,
|
|
5950
|
+
description: `Must match ${paramSchema.pattern}`,
|
|
5951
|
+
satisfied: matches,
|
|
5952
|
+
value,
|
|
5953
|
+
expected: paramSchema.pattern
|
|
5954
|
+
});
|
|
5955
|
+
}
|
|
5956
|
+
if (paramSchema.enum) {
|
|
5957
|
+
const inEnum = paramSchema.enum.some(
|
|
5958
|
+
(e) => JSON.stringify(e) === JSON.stringify(value)
|
|
5959
|
+
);
|
|
5960
|
+
constraints.push({
|
|
5961
|
+
kind: "custom",
|
|
5962
|
+
field: paramSchema.name,
|
|
5963
|
+
description: `Must be one of: ${paramSchema.enum.join(", ")}`,
|
|
5964
|
+
satisfied: inEnum,
|
|
5965
|
+
value,
|
|
5966
|
+
expected: paramSchema.enum
|
|
5967
|
+
});
|
|
5968
|
+
}
|
|
5969
|
+
}
|
|
5970
|
+
const risk = assessRisk(schema, proposal, constraints);
|
|
5971
|
+
const unsatisfied = constraints.filter((c) => !c.satisfied);
|
|
5972
|
+
const needsClarification = clarifications.length > 0;
|
|
5973
|
+
let confidence = best.score;
|
|
5974
|
+
if (unsatisfied.length > 0) {
|
|
5975
|
+
confidence *= 1 - unsatisfied.length / Math.max(constraints.length, 1) * 0.5;
|
|
5976
|
+
}
|
|
5977
|
+
if (errors.length > 0) {
|
|
5978
|
+
confidence *= 0.5;
|
|
5979
|
+
}
|
|
5980
|
+
const compiled = {
|
|
5981
|
+
intent: schema.intent,
|
|
5982
|
+
actor_id: proposal.actor_id,
|
|
5983
|
+
target: proposal.target,
|
|
5984
|
+
params,
|
|
5985
|
+
constraints,
|
|
5986
|
+
confidence,
|
|
5987
|
+
alternatives,
|
|
5988
|
+
needs_clarification: needsClarification,
|
|
5989
|
+
clarifications,
|
|
5990
|
+
expected_outcome: schema.description,
|
|
5991
|
+
fallback: schema.related?.[0],
|
|
5992
|
+
risk,
|
|
5993
|
+
metadata: {
|
|
5994
|
+
schema_intent: schema.intent,
|
|
5995
|
+
resolved_from: proposal.raw,
|
|
5996
|
+
has_side_effects: schema.has_side_effects,
|
|
5997
|
+
reversible: schema.reversible
|
|
5998
|
+
}
|
|
5999
|
+
};
|
|
6000
|
+
return {
|
|
6001
|
+
ok: errors.length === 0 && !needsClarification,
|
|
6002
|
+
compiled,
|
|
6003
|
+
errors
|
|
6004
|
+
};
|
|
6005
|
+
}
|
|
6006
|
+
/**
|
|
6007
|
+
* Apply clarification answers and re-compile.
|
|
6008
|
+
*/
|
|
6009
|
+
applyClarifications(compiled, answers) {
|
|
6010
|
+
const proposal = {
|
|
6011
|
+
raw: compiled.intent,
|
|
6012
|
+
actor_id: compiled.actor_id,
|
|
6013
|
+
target: compiled.target,
|
|
6014
|
+
params: { ...compiled.params, ...answers }
|
|
6015
|
+
};
|
|
6016
|
+
return this.compile(proposal);
|
|
6017
|
+
}
|
|
6018
|
+
};
|
|
6019
|
+
}
|
|
6020
|
+
});
|
|
6021
|
+
|
|
6022
|
+
// src/needle/needle.engine.ts
|
|
6023
|
+
import { randomBytes as randomBytes8 } from "crypto";
|
|
6024
|
+
function assembleNeedle(params) {
|
|
6025
|
+
return {
|
|
6026
|
+
needle_id: randomBytes8(16).toString("hex"),
|
|
6027
|
+
phase: "created",
|
|
6028
|
+
tps_coordinate: params.tps_coordinate,
|
|
6029
|
+
intent: params.intent,
|
|
6030
|
+
presence: params.presence,
|
|
6031
|
+
writ: params.writ,
|
|
6032
|
+
grants: params.grants,
|
|
6033
|
+
created_at: Date.now()
|
|
6034
|
+
};
|
|
6035
|
+
}
|
|
6036
|
+
function classifyStitch(observation, verdict) {
|
|
6037
|
+
if (verdict.status === "failed" || verdict.status === "disputed") {
|
|
6038
|
+
return "torn";
|
|
6039
|
+
}
|
|
6040
|
+
if (observation.decision === "DENY") {
|
|
6041
|
+
return "silent";
|
|
6042
|
+
}
|
|
6043
|
+
if (verdict.isDeed) {
|
|
6044
|
+
return "deed";
|
|
6045
|
+
}
|
|
6046
|
+
return "silent";
|
|
6047
|
+
}
|
|
6048
|
+
function formStitch(needle, observation, verdict, receipt) {
|
|
6049
|
+
return {
|
|
6050
|
+
stitch_id: needle.needle_id,
|
|
6051
|
+
kind: classifyStitch(observation, verdict),
|
|
6052
|
+
intent: needle.intent.intent,
|
|
6053
|
+
actor_id: needle.intent.actor_id,
|
|
6054
|
+
tps_coordinate: needle.tps_coordinate,
|
|
6055
|
+
observation,
|
|
6056
|
+
verdict,
|
|
6057
|
+
receipt,
|
|
6058
|
+
thread_id: receipt.thread_id,
|
|
6059
|
+
sequence: receipt.sequence,
|
|
6060
|
+
stitched_at: Date.now()
|
|
6061
|
+
};
|
|
6062
|
+
}
|
|
6063
|
+
async function runNeedlePipeline(needle, config, threadState, prevReceipt, expectedOutcome) {
|
|
6064
|
+
const obs = createObservation("http");
|
|
6065
|
+
obs.intent = needle.intent.intent;
|
|
6066
|
+
obs.actorId = needle.intent.actor_id;
|
|
6067
|
+
needle.phase = "validated";
|
|
6068
|
+
let stage = startStage(obs, "loom.validate");
|
|
6069
|
+
const validation = validateWrit(
|
|
6070
|
+
needle.writ,
|
|
6071
|
+
config.public_key,
|
|
6072
|
+
threadState,
|
|
6073
|
+
needle.grants
|
|
6074
|
+
);
|
|
6075
|
+
if (!validation.valid) {
|
|
6076
|
+
endStage(stage, "fail", validation.error);
|
|
6077
|
+
return failNeedle(needle, obs, "validated", "LOOM_VALIDATION_FAILED", validation.error ?? "Writ validation failed");
|
|
6078
|
+
}
|
|
6079
|
+
endStage(stage, "ok");
|
|
6080
|
+
if (config.sensors && config.sensors.length > 0) {
|
|
6081
|
+
stage = startStage(obs, "sensors.evaluate");
|
|
6082
|
+
const sensorInput = {
|
|
6083
|
+
intent: needle.intent.intent,
|
|
6084
|
+
actorId: needle.intent.actor_id,
|
|
6085
|
+
metadata: {
|
|
6086
|
+
observation: obs,
|
|
6087
|
+
needle_id: needle.needle_id,
|
|
6088
|
+
tps_coordinate: needle.tps_coordinate,
|
|
6089
|
+
writ: needle.writ,
|
|
6090
|
+
grants: needle.grants,
|
|
6091
|
+
params: needle.intent.params
|
|
6092
|
+
}
|
|
6093
|
+
};
|
|
6094
|
+
for (const sensor of config.sensors) {
|
|
6095
|
+
if (sensor.supports && !sensor.supports(sensorInput)) continue;
|
|
6096
|
+
const t0 = Date.now();
|
|
6097
|
+
let decision;
|
|
6098
|
+
try {
|
|
6099
|
+
const rawDecision = await sensor.run(sensorInput);
|
|
6100
|
+
decision = normalizeSensorDecision(rawDecision);
|
|
6101
|
+
} catch (err) {
|
|
6102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6103
|
+
recordSensor(obs, sensor.name, false, 100, Date.now() - t0, [`sensor_error:${msg}`]);
|
|
6104
|
+
endStage(stage, "fail", `Sensor ${sensor.name} threw: ${msg}`);
|
|
6105
|
+
return failNeedle(needle, obs, "validated", "SENSOR_ERROR", `Sensor ${sensor.name} failed: ${msg}`);
|
|
6106
|
+
}
|
|
6107
|
+
recordSensor(obs, sensor.name, decision.allow, decision.riskScore, Date.now() - t0, decision.reasons);
|
|
6108
|
+
if (!decision.allow) {
|
|
6109
|
+
endStage(stage, "fail", `Sensor ${sensor.name} denied`);
|
|
6110
|
+
return failNeedle(needle, obs, "validated", "SENSOR_DENY", decision.reasons[0] ?? `Denied by ${sensor.name}`);
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
endStage(stage, "ok");
|
|
6114
|
+
}
|
|
6115
|
+
needle.phase = "executing";
|
|
6116
|
+
stage = startStage(obs, "handler.execute");
|
|
6117
|
+
const handler = config.handlers.get(needle.intent.intent);
|
|
6118
|
+
if (!handler) {
|
|
6119
|
+
endStage(stage, "fail", `No handler for intent '${needle.intent.intent}'`);
|
|
6120
|
+
return failNeedle(needle, obs, "executing", "NO_HANDLER", `No handler registered for intent '${needle.intent.intent}'`);
|
|
6121
|
+
}
|
|
6122
|
+
const handlerCtx = {
|
|
6123
|
+
needle_id: needle.needle_id,
|
|
6124
|
+
actor_id: needle.intent.actor_id,
|
|
6125
|
+
presence_id: needle.presence.presence_id,
|
|
6126
|
+
writ: needle.writ,
|
|
6127
|
+
grants: needle.grants,
|
|
6128
|
+
tps_coordinate: needle.tps_coordinate
|
|
6129
|
+
};
|
|
6130
|
+
let handlerResult;
|
|
6131
|
+
try {
|
|
6132
|
+
handlerResult = await handler(needle.intent, handlerCtx);
|
|
6133
|
+
} catch (err) {
|
|
6134
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6135
|
+
endStage(stage, "fail", msg);
|
|
6136
|
+
return failNeedle(needle, obs, "executing", "HANDLER_ERROR", msg);
|
|
6137
|
+
}
|
|
6138
|
+
if (!handlerResult.ok) {
|
|
6139
|
+
endStage(stage, "fail", handlerResult.effect);
|
|
6140
|
+
obs.decision = "DENY";
|
|
6141
|
+
obs.resultCode = handlerResult.effect;
|
|
6142
|
+
obs.statusCode = handlerResult.status_code ?? 400;
|
|
6143
|
+
} else {
|
|
6144
|
+
endStage(stage, "ok");
|
|
6145
|
+
obs.decision = "ALLOW";
|
|
6146
|
+
obs.resultCode = handlerResult.effect;
|
|
6147
|
+
obs.statusCode = handlerResult.status_code ?? 200;
|
|
6148
|
+
}
|
|
6149
|
+
if (handlerResult.data) {
|
|
6150
|
+
obs.facts = { ...obs.facts, ...handlerResult.data };
|
|
6151
|
+
}
|
|
6152
|
+
needle.phase = "observed";
|
|
6153
|
+
finalizeObservation(obs, obs.decision ?? "DENY", obs.statusCode ?? 500, obs.resultCode);
|
|
6154
|
+
needle.observation = obs;
|
|
6155
|
+
const verdict = scoreTruth(obs, expectedOutcome);
|
|
6156
|
+
needle.verdict = verdict;
|
|
6157
|
+
needle.phase = "stitched";
|
|
6158
|
+
stage = startStage(obs, "stitch.form");
|
|
6159
|
+
const receipt = createReceipt(
|
|
6160
|
+
needle.writ,
|
|
6161
|
+
obs.decision ?? "DENY",
|
|
6162
|
+
prevReceipt
|
|
6163
|
+
);
|
|
6164
|
+
needle.receipt = receipt;
|
|
6165
|
+
const newThreadState = updateThreadState(
|
|
6166
|
+
receipt,
|
|
6167
|
+
needle.intent.actor_id
|
|
6168
|
+
);
|
|
6169
|
+
const stitch = formStitch(needle, obs, verdict, receipt);
|
|
6170
|
+
needle.completed_at = Date.now();
|
|
6171
|
+
endStage(stage, "ok");
|
|
6172
|
+
return {
|
|
6173
|
+
ok: handlerResult.ok,
|
|
6174
|
+
needle,
|
|
6175
|
+
stitch,
|
|
6176
|
+
thread_state: newThreadState
|
|
6177
|
+
};
|
|
6178
|
+
}
|
|
6179
|
+
function failNeedle(needle, obs, phase, code, message) {
|
|
6180
|
+
needle.phase = "failed";
|
|
6181
|
+
needle.error = { phase, code, message };
|
|
6182
|
+
needle.completed_at = Date.now();
|
|
6183
|
+
obs.decision = obs.decision ?? "DENY";
|
|
6184
|
+
obs.statusCode = obs.statusCode ?? 500;
|
|
6185
|
+
finalizeObservation(obs, obs.decision, obs.statusCode, obs.resultCode);
|
|
6186
|
+
needle.observation = obs;
|
|
6187
|
+
const verdict = scoreTruth(obs);
|
|
6188
|
+
needle.verdict = verdict;
|
|
6189
|
+
return {
|
|
6190
|
+
ok: false,
|
|
6191
|
+
needle
|
|
6192
|
+
};
|
|
6193
|
+
}
|
|
6194
|
+
var init_needle_engine = __esm({
|
|
6195
|
+
"src/needle/needle.engine.ts"() {
|
|
6196
|
+
init_axis_observation();
|
|
6197
|
+
init_truth_scoring();
|
|
6198
|
+
init_loom_engine();
|
|
6199
|
+
init_axis_sensor();
|
|
6200
|
+
}
|
|
6201
|
+
});
|
|
6202
|
+
|
|
6203
|
+
// src/needle/knot.engine.ts
|
|
6204
|
+
import { createHash as createHash8, randomBytes as randomBytes9 } from "crypto";
|
|
6205
|
+
function openKnot(params) {
|
|
6206
|
+
const isIrreversible = params.type === "irreversible";
|
|
6207
|
+
return {
|
|
6208
|
+
knot_id: `knot_${randomBytes9(16).toString("hex")}`,
|
|
6209
|
+
type: params.type,
|
|
6210
|
+
status: "open",
|
|
6211
|
+
stitch_ids: [],
|
|
6212
|
+
thread_id: params.thread_id,
|
|
6213
|
+
tps_anchor: params.tps_anchor,
|
|
6214
|
+
irreversible: isIrreversible,
|
|
6215
|
+
capsule_id: params.capsule_id,
|
|
6216
|
+
law_ref: params.law_ref,
|
|
6217
|
+
branch_ids: [],
|
|
6218
|
+
required_count: params.required_count,
|
|
6219
|
+
all_or_nothing: params.all_or_nothing ?? (params.type === "authority" || isIrreversible),
|
|
6220
|
+
actor_id: params.actor_id,
|
|
6221
|
+
created_at: Date.now()
|
|
6222
|
+
};
|
|
6223
|
+
}
|
|
6224
|
+
function addStitchToKnot(knot, stitch) {
|
|
6225
|
+
if (knot.status !== "open") {
|
|
6226
|
+
return `Knot ${knot.knot_id} is ${knot.status}, cannot add stitches`;
|
|
6227
|
+
}
|
|
6228
|
+
if (stitch.thread_id !== knot.thread_id) {
|
|
6229
|
+
return `Stitch thread ${stitch.thread_id} does not match knot thread ${knot.thread_id}`;
|
|
6230
|
+
}
|
|
6231
|
+
if (knot.stitch_ids.includes(stitch.stitch_id)) {
|
|
6232
|
+
return `Stitch ${stitch.stitch_id} already in knot`;
|
|
6233
|
+
}
|
|
6234
|
+
if (knot.type === "authority" && knot.capsule_id) {
|
|
6235
|
+
if (stitch.observation.capsuleId && stitch.observation.capsuleId !== knot.capsule_id) {
|
|
6236
|
+
return `Stitch capsule ${stitch.observation.capsuleId} does not match knot capsule ${knot.capsule_id}`;
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
knot.stitch_ids.push(stitch.stitch_id);
|
|
6240
|
+
return null;
|
|
6241
|
+
}
|
|
6242
|
+
function validateKnot(knot, stitches) {
|
|
6243
|
+
const errors = [];
|
|
6244
|
+
const passedIds = [];
|
|
6245
|
+
const failedIds = [];
|
|
6246
|
+
const stitchMap = new Map(stitches.map((s) => [s.stitch_id, s]));
|
|
6247
|
+
for (const sid of knot.stitch_ids) {
|
|
6248
|
+
const stitch = stitchMap.get(sid);
|
|
6249
|
+
if (!stitch) {
|
|
6250
|
+
failedIds.push(sid);
|
|
6251
|
+
errors.push({
|
|
6252
|
+
code: "KNOT_MISSING_STITCH",
|
|
6253
|
+
message: `Stitch ${sid} not found`,
|
|
6254
|
+
stitch_id: sid
|
|
6255
|
+
});
|
|
6256
|
+
continue;
|
|
6257
|
+
}
|
|
6258
|
+
if (stitch.kind === "torn") {
|
|
6259
|
+
failedIds.push(sid);
|
|
6260
|
+
errors.push({
|
|
6261
|
+
code: "KNOT_TORN_STITCH",
|
|
6262
|
+
message: `Stitch ${sid} is torn (failed/disputed)`,
|
|
6263
|
+
stitch_id: sid
|
|
6264
|
+
});
|
|
6265
|
+
continue;
|
|
6266
|
+
}
|
|
6267
|
+
if (knot.type === "irreversible" && stitch.kind !== "deed") {
|
|
6268
|
+
failedIds.push(sid);
|
|
6269
|
+
errors.push({
|
|
6270
|
+
code: "KNOT_REQUIRES_DEED",
|
|
6271
|
+
message: `Irreversible knot requires deed stitch, got '${stitch.kind}'`,
|
|
6272
|
+
stitch_id: sid
|
|
6273
|
+
});
|
|
6274
|
+
continue;
|
|
6275
|
+
}
|
|
6276
|
+
passedIds.push(sid);
|
|
6277
|
+
}
|
|
6278
|
+
if (knot.required_count !== void 0 && knot.stitch_ids.length < knot.required_count) {
|
|
6279
|
+
errors.push({
|
|
6280
|
+
code: "KNOT_INSUFFICIENT_STITCHES",
|
|
6281
|
+
message: `Knot requires ${knot.required_count} stitches, has ${knot.stitch_ids.length}`
|
|
6282
|
+
});
|
|
6283
|
+
}
|
|
6284
|
+
const allPassed = failedIds.length === 0;
|
|
6285
|
+
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);
|
|
6286
|
+
return {
|
|
6287
|
+
valid: allPassed && errors.length === 0,
|
|
6288
|
+
passed_stitch_ids: passedIds,
|
|
6289
|
+
failed_stitch_ids: failedIds,
|
|
6290
|
+
can_tie: canTie,
|
|
6291
|
+
errors
|
|
6292
|
+
};
|
|
6293
|
+
}
|
|
6294
|
+
function tieKnot(knot, stitches) {
|
|
6295
|
+
const validation = validateKnot(knot, stitches);
|
|
6296
|
+
if (!validation.can_tie) {
|
|
6297
|
+
return { ...validation, knot };
|
|
6298
|
+
}
|
|
6299
|
+
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);
|
|
6300
|
+
const witnessPayload = receiptHashes.join(":");
|
|
6301
|
+
knot.witness_hash = createHash8("sha256").update(witnessPayload).digest("hex");
|
|
6302
|
+
knot.status = "tied";
|
|
6303
|
+
knot.tied_at = Date.now();
|
|
6304
|
+
return { ...validation, knot };
|
|
6305
|
+
}
|
|
6306
|
+
function breakKnot(knot, request) {
|
|
6307
|
+
if (knot.status === "broken") {
|
|
6308
|
+
return { ok: false, error: "Knot is already broken" };
|
|
6309
|
+
}
|
|
6310
|
+
if (knot.status === "open") {
|
|
6311
|
+
knot.status = "broken";
|
|
6312
|
+
knot.broken_at = Date.now();
|
|
6313
|
+
knot.break_reason = request.reason;
|
|
6314
|
+
return { ok: true };
|
|
6315
|
+
}
|
|
6316
|
+
if (knot.status === "tied") {
|
|
6317
|
+
if (!request.reason) {
|
|
6318
|
+
return { ok: false, error: "Breaking a tied knot requires a reason" };
|
|
6319
|
+
}
|
|
6320
|
+
if ((knot.irreversible || knot.type === "law") && !request.override_grant_id) {
|
|
6321
|
+
return {
|
|
6322
|
+
ok: false,
|
|
6323
|
+
error: `Breaking ${knot.type} knot requires override_grant_id from higher authority`
|
|
6324
|
+
};
|
|
6325
|
+
}
|
|
6326
|
+
knot.status = "broken";
|
|
6327
|
+
knot.broken_at = Date.now();
|
|
6328
|
+
knot.break_reason = request.reason;
|
|
6329
|
+
return { ok: true };
|
|
6330
|
+
}
|
|
6331
|
+
return { ok: false, error: `Cannot break knot in status '${knot.status}'` };
|
|
6332
|
+
}
|
|
6333
|
+
function forkFromKnot(knot, branchId, decisionStitchId) {
|
|
6334
|
+
if (knot.status !== "tied" && knot.status !== "open") {
|
|
6335
|
+
return { ok: false, error: `Cannot fork from knot in status '${knot.status}'` };
|
|
6336
|
+
}
|
|
6337
|
+
if (decisionStitchId) {
|
|
6338
|
+
if (!knot.stitch_ids.includes(decisionStitchId)) {
|
|
6339
|
+
return { ok: false, error: `Decision stitch ${decisionStitchId} is not part of this knot` };
|
|
6340
|
+
}
|
|
6341
|
+
knot.decision_stitch_id = decisionStitchId;
|
|
6342
|
+
}
|
|
6343
|
+
knot.branch_ids.push(branchId);
|
|
6344
|
+
knot.status = "forked";
|
|
6345
|
+
return { ok: true };
|
|
6346
|
+
}
|
|
6347
|
+
function isKnotOpen(knot) {
|
|
6348
|
+
return knot.status === "open";
|
|
6349
|
+
}
|
|
6350
|
+
function isPointOfNoReturn(knot) {
|
|
6351
|
+
return knot.irreversible && knot.status === "tied";
|
|
6352
|
+
}
|
|
6353
|
+
function findKnotsForStitch(stitchId, knots) {
|
|
6354
|
+
return knots.filter((k) => k.stitch_ids.includes(stitchId));
|
|
6355
|
+
}
|
|
6356
|
+
function getIrreversibleKnots(knots) {
|
|
6357
|
+
return knots.filter((k) => k.irreversible && k.status === "tied");
|
|
6358
|
+
}
|
|
6359
|
+
function getDecisionPoints(knots) {
|
|
6360
|
+
return knots.filter((k) => k.type === "decision" || k.status === "forked");
|
|
6361
|
+
}
|
|
6362
|
+
var init_knot_engine = __esm({
|
|
6363
|
+
"src/needle/knot.engine.ts"() {
|
|
6364
|
+
}
|
|
6365
|
+
});
|
|
6366
|
+
|
|
6367
|
+
// src/needle/fabric.engine.ts
|
|
6368
|
+
import { createHash as createHash9, randomBytes as randomBytes10 } from "crypto";
|
|
6369
|
+
function createFabric() {
|
|
6370
|
+
return {
|
|
6371
|
+
fabric_id: `fab_${randomBytes10(16).toString("hex")}`,
|
|
6372
|
+
state_hash: hashState(/* @__PURE__ */ new Map()),
|
|
6373
|
+
cells: /* @__PURE__ */ new Map(),
|
|
6374
|
+
thread_ids: [],
|
|
6375
|
+
stitch_count: 0,
|
|
6376
|
+
knot_count: 0,
|
|
6377
|
+
computed_at: Date.now(),
|
|
6378
|
+
version: 0
|
|
6379
|
+
};
|
|
6380
|
+
}
|
|
6381
|
+
function applyStitch(fabric, stitch, effect) {
|
|
6382
|
+
for (const [key, value] of Object.entries(effect.mutations)) {
|
|
6383
|
+
if (value === null) {
|
|
6384
|
+
fabric.cells.delete(key);
|
|
6385
|
+
} else {
|
|
6386
|
+
const existing = fabric.cells.get(key);
|
|
6387
|
+
if (existing?.locked) {
|
|
6388
|
+
continue;
|
|
6389
|
+
}
|
|
6390
|
+
fabric.cells.set(key, {
|
|
6391
|
+
key,
|
|
6392
|
+
value,
|
|
6393
|
+
last_stitch_id: stitch.stitch_id,
|
|
6394
|
+
last_tps: stitch.tps_coordinate,
|
|
6395
|
+
write_count: (existing?.write_count ?? 0) + 1,
|
|
6396
|
+
locked: false
|
|
6397
|
+
});
|
|
6398
|
+
}
|
|
6399
|
+
}
|
|
6400
|
+
if (!fabric.thread_ids.includes(stitch.thread_id)) {
|
|
6401
|
+
fabric.thread_ids.push(stitch.thread_id);
|
|
6402
|
+
}
|
|
6403
|
+
fabric.stitch_count++;
|
|
6404
|
+
fabric.version++;
|
|
6405
|
+
fabric.projected_at_tps = stitch.tps_coordinate ?? fabric.projected_at_tps;
|
|
6406
|
+
fabric.computed_at = Date.now();
|
|
6407
|
+
fabric.state_hash = hashState(fabric.cells);
|
|
6408
|
+
}
|
|
6409
|
+
function weave(stitches, resolver, knots) {
|
|
6410
|
+
const fabric = createFabric();
|
|
6411
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6412
|
+
for (const stitch of sorted) {
|
|
6413
|
+
if (stitch.kind === "torn") continue;
|
|
6414
|
+
const effect = resolver(stitch);
|
|
6415
|
+
applyStitch(fabric, stitch, effect);
|
|
6416
|
+
}
|
|
6417
|
+
if (knots) {
|
|
6418
|
+
for (const knot of knots) {
|
|
6419
|
+
if (knot.irreversible && knot.status === "tied") {
|
|
6420
|
+
lockCellsByKnot(fabric, knot, stitches, resolver);
|
|
6421
|
+
fabric.knot_count++;
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
}
|
|
6425
|
+
return fabric;
|
|
6426
|
+
}
|
|
6427
|
+
function projectAt(stitches, resolver, tpsFilter, knots) {
|
|
6428
|
+
const filtered = stitches.filter((s) => tpsFilter(s.tps_coordinate));
|
|
6429
|
+
return weave(filtered, resolver, knots);
|
|
6430
|
+
}
|
|
6431
|
+
function lockCellsByKnot(fabric, knot, stitches, resolver) {
|
|
6432
|
+
const knotStitchIds = new Set(knot.stitch_ids);
|
|
6433
|
+
const knotStitches = stitches.filter((s) => knotStitchIds.has(s.stitch_id));
|
|
6434
|
+
for (const stitch of knotStitches) {
|
|
6435
|
+
const effect = resolver(stitch);
|
|
6436
|
+
for (const key of Object.keys(effect.mutations)) {
|
|
6437
|
+
const cell = fabric.cells.get(key);
|
|
6438
|
+
if (cell) {
|
|
6439
|
+
cell.locked = true;
|
|
6440
|
+
cell.locked_by_knot = knot.knot_id;
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
}
|
|
6445
|
+
function lockCells(fabric, keys, knotId) {
|
|
6446
|
+
for (const key of keys) {
|
|
6447
|
+
const cell = fabric.cells.get(key);
|
|
6448
|
+
if (cell) {
|
|
6449
|
+
cell.locked = true;
|
|
6450
|
+
cell.locked_by_knot = knotId;
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
}
|
|
6454
|
+
function queryFabric(fabric, query) {
|
|
6455
|
+
let results = [...fabric.cells.values()];
|
|
6456
|
+
if (query.keys) {
|
|
6457
|
+
const keySet = new Set(query.keys);
|
|
6458
|
+
results = results.filter((c) => keySet.has(c.key));
|
|
6459
|
+
}
|
|
6460
|
+
if (query.prefix) {
|
|
6461
|
+
const prefix = query.prefix;
|
|
6462
|
+
results = results.filter((c) => c.key.startsWith(prefix));
|
|
6463
|
+
}
|
|
6464
|
+
if (query.locked_only) {
|
|
6465
|
+
results = results.filter((c) => c.locked);
|
|
6466
|
+
}
|
|
6467
|
+
return results;
|
|
6468
|
+
}
|
|
6469
|
+
function getFabricValue(fabric, key) {
|
|
6470
|
+
return fabric.cells.get(key)?.value;
|
|
6471
|
+
}
|
|
6472
|
+
function diffFabrics(a, b) {
|
|
6473
|
+
const entries = [];
|
|
6474
|
+
let added = 0;
|
|
6475
|
+
let modified = 0;
|
|
6476
|
+
let deleted = 0;
|
|
6477
|
+
for (const [key, cellB] of b.cells) {
|
|
6478
|
+
const cellA = a.cells.get(key);
|
|
6479
|
+
if (!cellA) {
|
|
6480
|
+
entries.push({
|
|
6481
|
+
key,
|
|
6482
|
+
kind: "added",
|
|
6483
|
+
after: cellB.value,
|
|
6484
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
6485
|
+
});
|
|
6486
|
+
added++;
|
|
6487
|
+
} else if (JSON.stringify(cellA.value) !== JSON.stringify(cellB.value)) {
|
|
6488
|
+
entries.push({
|
|
6489
|
+
key,
|
|
6490
|
+
kind: "modified",
|
|
6491
|
+
before: cellA.value,
|
|
6492
|
+
after: cellB.value,
|
|
6493
|
+
caused_by_stitch: cellB.last_stitch_id
|
|
6494
|
+
});
|
|
6495
|
+
modified++;
|
|
6496
|
+
}
|
|
6497
|
+
}
|
|
6498
|
+
for (const [key, cellA] of a.cells) {
|
|
6499
|
+
if (!b.cells.has(key)) {
|
|
6500
|
+
entries.push({
|
|
6501
|
+
key,
|
|
6502
|
+
kind: "deleted",
|
|
6503
|
+
before: cellA.value
|
|
6504
|
+
});
|
|
6505
|
+
deleted++;
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
return {
|
|
6509
|
+
from_fabric_id: a.fabric_id,
|
|
6510
|
+
to_fabric_id: b.fabric_id,
|
|
6511
|
+
entries,
|
|
6512
|
+
added_count: added,
|
|
6513
|
+
modified_count: modified,
|
|
6514
|
+
deleted_count: deleted
|
|
6515
|
+
};
|
|
6516
|
+
}
|
|
6517
|
+
function hashState(cells) {
|
|
6518
|
+
const keys = [...cells.keys()].sort();
|
|
6519
|
+
const payload = keys.map((k) => `${k}=${JSON.stringify(cells.get(k).value)}`).join("\n");
|
|
6520
|
+
return createHash9("sha256").update(payload).digest("hex");
|
|
6521
|
+
}
|
|
6522
|
+
var init_fabric_engine = __esm({
|
|
6523
|
+
"src/needle/fabric.engine.ts"() {
|
|
6524
|
+
}
|
|
6525
|
+
});
|
|
6526
|
+
|
|
6527
|
+
// src/needle/pattern.engine.ts
|
|
6528
|
+
import { randomBytes as randomBytes11 } from "crypto";
|
|
6529
|
+
function detectSequencePatterns(stitches, windowSize, minOccurrences) {
|
|
6530
|
+
if (stitches.length < windowSize || windowSize < 2) return [];
|
|
6531
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6532
|
+
const sequenceCounts = /* @__PURE__ */ new Map();
|
|
6533
|
+
for (let i = 0; i <= sorted.length - windowSize; i++) {
|
|
6534
|
+
const window = sorted.slice(i, i + windowSize);
|
|
6535
|
+
const key = window.map((s) => s.intent).join("\u2192");
|
|
6536
|
+
const ids = window.map((s) => s.stitch_id);
|
|
6537
|
+
const existing = sequenceCounts.get(key);
|
|
6538
|
+
if (existing) {
|
|
6539
|
+
existing.count++;
|
|
6540
|
+
existing.stitch_ids.push(ids);
|
|
6541
|
+
} else {
|
|
6542
|
+
sequenceCounts.set(key, { count: 1, stitch_ids: [ids] });
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
const patterns = [];
|
|
6546
|
+
const now = Date.now();
|
|
6547
|
+
for (const [key, data] of sequenceCounts) {
|
|
6548
|
+
if (data.count < minOccurrences) continue;
|
|
6549
|
+
const intents = key.split("\u2192");
|
|
6550
|
+
const confidence = Math.min(data.count / (minOccurrences * 2), 1);
|
|
6551
|
+
patterns.push({
|
|
6552
|
+
pattern_id: `pat_seq_${randomBytes11(8).toString("hex")}`,
|
|
6553
|
+
kind: "sequence",
|
|
6554
|
+
name: `Sequence: ${intents.join(" \u2192 ")}`,
|
|
6555
|
+
signature: {
|
|
6556
|
+
intent_sequence: intents,
|
|
6557
|
+
min_length: windowSize,
|
|
6558
|
+
max_length: windowSize
|
|
6559
|
+
},
|
|
6560
|
+
confidence,
|
|
6561
|
+
occurrence_count: data.count,
|
|
6562
|
+
first_seen_at: now,
|
|
6563
|
+
last_seen_at: now,
|
|
6564
|
+
seen_in_threads: [...new Set(
|
|
6565
|
+
data.stitch_ids.flatMap(
|
|
6566
|
+
(ids) => ids.map((id) => sorted.find((s) => s.stitch_id === id)?.thread_id).filter(Boolean)
|
|
6567
|
+
)
|
|
6568
|
+
)],
|
|
6569
|
+
classification: "unclassified"
|
|
6570
|
+
});
|
|
6571
|
+
}
|
|
6572
|
+
return patterns;
|
|
6573
|
+
}
|
|
6574
|
+
function detectKnotPatterns(knots, minOccurrences) {
|
|
6575
|
+
const groups = /* @__PURE__ */ new Map();
|
|
6576
|
+
for (const knot of knots) {
|
|
6577
|
+
if (knot.status !== "tied") continue;
|
|
6578
|
+
const key = `${knot.type}:${knot.stitch_ids.length}`;
|
|
6579
|
+
const group = groups.get(key) ?? [];
|
|
6580
|
+
group.push(knot);
|
|
6581
|
+
groups.set(key, group);
|
|
6582
|
+
}
|
|
6583
|
+
const patterns = [];
|
|
6584
|
+
const now = Date.now();
|
|
6585
|
+
for (const [key, group] of groups) {
|
|
6586
|
+
if (group.length < minOccurrences) continue;
|
|
6587
|
+
const [type, sizeStr] = key.split(":");
|
|
6588
|
+
const size = parseInt(sizeStr, 10);
|
|
6589
|
+
const confidence = Math.min(group.length / (minOccurrences * 2), 1);
|
|
6590
|
+
patterns.push({
|
|
6591
|
+
pattern_id: `pat_knot_${randomBytes11(8).toString("hex")}`,
|
|
6592
|
+
kind: "knot",
|
|
6593
|
+
name: `Knot: ${type} (${size} stitches)`,
|
|
6594
|
+
signature: {
|
|
6595
|
+
knot_type: type,
|
|
6596
|
+
knot_size: size
|
|
6597
|
+
},
|
|
6598
|
+
confidence,
|
|
6599
|
+
occurrence_count: group.length,
|
|
6600
|
+
first_seen_at: now,
|
|
6601
|
+
last_seen_at: now,
|
|
6602
|
+
seen_in_threads: [...new Set(group.map((k) => k.thread_id))],
|
|
6603
|
+
classification: "unclassified"
|
|
6604
|
+
});
|
|
6605
|
+
}
|
|
6606
|
+
return patterns;
|
|
6607
|
+
}
|
|
6608
|
+
function matchPatterns(stitches, patterns) {
|
|
6609
|
+
const sorted = [...stitches].sort((a, b) => a.sequence - b.sequence);
|
|
6610
|
+
const matches = [];
|
|
6611
|
+
const now = Date.now();
|
|
6612
|
+
for (const pattern of patterns) {
|
|
6613
|
+
if (pattern.kind === "sequence" && pattern.signature.intent_sequence) {
|
|
6614
|
+
const seq = pattern.signature.intent_sequence;
|
|
6615
|
+
const seqLen = seq.length;
|
|
6616
|
+
for (let i = 0; i <= sorted.length - seqLen; i++) {
|
|
6617
|
+
const window = sorted.slice(i, i + seqLen);
|
|
6618
|
+
const windowIntents = window.map((s) => s.intent);
|
|
6619
|
+
if (windowIntents.every((intent, idx) => intent === seq[idx])) {
|
|
6620
|
+
matches.push({
|
|
6621
|
+
pattern_id: pattern.pattern_id,
|
|
6622
|
+
matched_stitch_ids: window.map((s) => s.stitch_id),
|
|
6623
|
+
match_score: 1,
|
|
6624
|
+
thread_id: window[0].thread_id,
|
|
6625
|
+
detected_at: now
|
|
6626
|
+
});
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6630
|
+
}
|
|
6631
|
+
return matches;
|
|
6632
|
+
}
|
|
6633
|
+
function recordOccurrence(pattern, threadId) {
|
|
6634
|
+
pattern.occurrence_count++;
|
|
6635
|
+
pattern.last_seen_at = Date.now();
|
|
6636
|
+
pattern.confidence = 1 - 1 / (1 + pattern.occurrence_count * 0.5);
|
|
6637
|
+
if (!pattern.seen_in_threads.includes(threadId)) {
|
|
6638
|
+
pattern.seen_in_threads.push(threadId);
|
|
6639
|
+
}
|
|
6640
|
+
}
|
|
6641
|
+
function detectAnomalies(recentStitches, knownPatterns, threshold = 0.7) {
|
|
6642
|
+
const anomalies = [];
|
|
6643
|
+
const sorted = [...recentStitches].sort((a, b) => a.sequence - b.sequence);
|
|
6644
|
+
const now = Date.now();
|
|
6645
|
+
for (const pattern of knownPatterns) {
|
|
6646
|
+
if (pattern.kind !== "sequence" || !pattern.signature.intent_sequence) continue;
|
|
6647
|
+
if (pattern.confidence < threshold) continue;
|
|
6648
|
+
const seq = pattern.signature.intent_sequence;
|
|
6649
|
+
if (sorted.length >= 1 && sorted.length < seq.length) {
|
|
6650
|
+
const partialMatch = sorted.every(
|
|
6651
|
+
(s, i) => i < seq.length && s.intent === seq[i]
|
|
6652
|
+
);
|
|
6653
|
+
if (partialMatch) {
|
|
6654
|
+
const expectedNext = seq[sorted.length];
|
|
6655
|
+
const lastStitch = sorted[sorted.length - 1];
|
|
6656
|
+
if (pattern.occurrence_count >= 3) {
|
|
6657
|
+
anomalies.push({
|
|
6658
|
+
pattern_id: `pat_anom_${randomBytes11(8).toString("hex")}`,
|
|
6659
|
+
kind: "anomaly",
|
|
6660
|
+
name: `Incomplete: ${pattern.name}`,
|
|
6661
|
+
description: `Expected '${expectedNext}' after '${lastStitch.intent}' based on pattern '${pattern.name}'`,
|
|
6662
|
+
signature: pattern.signature,
|
|
6663
|
+
confidence: pattern.confidence * 0.8,
|
|
6664
|
+
occurrence_count: 1,
|
|
6665
|
+
first_seen_at: now,
|
|
6666
|
+
last_seen_at: now,
|
|
6667
|
+
seen_in_threads: [lastStitch.thread_id],
|
|
6668
|
+
classification: "anomalous"
|
|
6669
|
+
});
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
return anomalies;
|
|
6675
|
+
}
|
|
6676
|
+
var InMemoryPatternStore;
|
|
6677
|
+
var init_pattern_engine = __esm({
|
|
6678
|
+
"src/needle/pattern.engine.ts"() {
|
|
6679
|
+
InMemoryPatternStore = class {
|
|
6680
|
+
constructor() {
|
|
6681
|
+
this.patterns = /* @__PURE__ */ new Map();
|
|
6682
|
+
}
|
|
6683
|
+
save(pattern) {
|
|
6684
|
+
this.patterns.set(pattern.pattern_id, pattern);
|
|
6685
|
+
}
|
|
6686
|
+
get(patternId) {
|
|
6687
|
+
return this.patterns.get(patternId);
|
|
6688
|
+
}
|
|
6689
|
+
findByKind(kind) {
|
|
6690
|
+
return [...this.patterns.values()].filter((p) => p.kind === kind);
|
|
6691
|
+
}
|
|
6692
|
+
findByIntent(intent) {
|
|
6693
|
+
return [...this.patterns.values()].filter(
|
|
6694
|
+
(p) => p.signature.intent_sequence?.includes(intent)
|
|
6695
|
+
);
|
|
6696
|
+
}
|
|
6697
|
+
all() {
|
|
6698
|
+
return [...this.patterns.values()];
|
|
6699
|
+
}
|
|
6700
|
+
};
|
|
6701
|
+
}
|
|
6702
|
+
});
|
|
6703
|
+
|
|
6704
|
+
// src/sensors/tps.sensor.ts
|
|
6705
|
+
var require_tps_sensor = __commonJS({
|
|
6706
|
+
"src/sensors/tps.sensor.ts"(exports) {
|
|
6707
|
+
"use strict";
|
|
6708
|
+
var __decorate = exports && exports.__decorate || function(decorators, target, key, desc) {
|
|
6709
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6710
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6711
|
+
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;
|
|
6712
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6713
|
+
};
|
|
6714
|
+
var __metadata = exports && exports.__metadata || function(k, v) {
|
|
6715
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6716
|
+
};
|
|
6717
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6718
|
+
exports.TpsSensor = void 0;
|
|
6719
|
+
var common_1 = __require("@nestjs/common");
|
|
6720
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6721
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6722
|
+
var TPS_EPOCH_MS = 9343548e5;
|
|
6723
|
+
function parseINotation(tps) {
|
|
6724
|
+
if (!tps.startsWith("i"))
|
|
6725
|
+
return null;
|
|
6726
|
+
const num = Number(tps.slice(1));
|
|
6727
|
+
if (!Number.isFinite(num))
|
|
6728
|
+
return null;
|
|
6729
|
+
return TPS_EPOCH_MS + num;
|
|
6730
|
+
}
|
|
6731
|
+
var TpsSensor2 = class TpsSensor {
|
|
6732
|
+
constructor(options = {}) {
|
|
6733
|
+
this.name = "TpsSensor";
|
|
6734
|
+
this.order = sensor_bands_1.BAND.POLICY + 2;
|
|
6735
|
+
this.maxDriftMs = options.maxDriftMs ?? 3e4;
|
|
6736
|
+
this.resolver = options.resolver ?? parseINotation;
|
|
6737
|
+
}
|
|
6738
|
+
supports(input) {
|
|
6739
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
6740
|
+
return typeof tps === "string" && tps.length > 0;
|
|
6741
|
+
}
|
|
6742
|
+
async run(input) {
|
|
6743
|
+
const tps = input.metadata?.tps_coordinate ?? input.metadata?.tps ?? input.packet?.tps;
|
|
6744
|
+
const resolved = this.resolver(tps);
|
|
6745
|
+
if (resolved === null) {
|
|
6746
|
+
return {
|
|
6747
|
+
allow: false,
|
|
6748
|
+
riskScore: 80,
|
|
6749
|
+
reasons: [`TPS coordinate '${tps}' is structurally invalid`],
|
|
6750
|
+
code: "TPS_INVALID_FORMAT"
|
|
6751
|
+
};
|
|
6752
|
+
}
|
|
6753
|
+
const now = Date.now();
|
|
6754
|
+
const drift = Math.abs(now - resolved);
|
|
6755
|
+
if (drift > this.maxDriftMs) {
|
|
6756
|
+
const direction = resolved > now ? "future" : "past";
|
|
6757
|
+
return {
|
|
6758
|
+
allow: false,
|
|
6759
|
+
riskScore: 70,
|
|
6760
|
+
reasons: [
|
|
6761
|
+
`TPS drift ${drift}ms exceeds max ${this.maxDriftMs}ms (${direction})`
|
|
6762
|
+
],
|
|
6763
|
+
code: "TPS_DRIFT_EXCEEDED",
|
|
6764
|
+
tags: { tpsDriftMs: drift, tpsDirection: direction }
|
|
6765
|
+
};
|
|
6766
|
+
}
|
|
6767
|
+
return {
|
|
6768
|
+
allow: true,
|
|
6769
|
+
riskScore: 0,
|
|
6770
|
+
reasons: [],
|
|
6771
|
+
tags: {
|
|
6772
|
+
tpsResolved: resolved,
|
|
6773
|
+
tpsDriftMs: drift
|
|
6774
|
+
}
|
|
6775
|
+
};
|
|
6776
|
+
}
|
|
6777
|
+
};
|
|
6778
|
+
exports.TpsSensor = TpsSensor2;
|
|
6779
|
+
exports.TpsSensor = TpsSensor2 = __decorate([
|
|
6780
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
6781
|
+
(0, common_1.Injectable)(),
|
|
6782
|
+
__metadata("design:paramtypes", [Object])
|
|
6783
|
+
], TpsSensor2);
|
|
6784
|
+
}
|
|
6785
|
+
});
|
|
6786
|
+
|
|
6787
|
+
// src/sensors/risk-gate.sensor.ts
|
|
6788
|
+
var require_risk_gate_sensor = __commonJS({
|
|
6789
|
+
"src/sensors/risk-gate.sensor.ts"(exports) {
|
|
6790
|
+
"use strict";
|
|
6791
|
+
var __decorate = exports && exports.__decorate || function(decorators, target, key, desc) {
|
|
6792
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6793
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6794
|
+
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;
|
|
6795
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6796
|
+
};
|
|
6797
|
+
var __metadata = exports && exports.__metadata || function(k, v) {
|
|
6798
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6799
|
+
};
|
|
6800
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6801
|
+
exports.RiskGateSensor = void 0;
|
|
6802
|
+
var common_1 = __require("@nestjs/common");
|
|
6803
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6804
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6805
|
+
var risk_1 = (init_risk(), __toCommonJS(risk_exports));
|
|
6806
|
+
var SEVERITY_WEIGHT = {
|
|
6807
|
+
low: 10,
|
|
6808
|
+
medium: 25,
|
|
6809
|
+
high: 50,
|
|
6810
|
+
critical: 100
|
|
6811
|
+
};
|
|
6812
|
+
var RiskGateSensor2 = class RiskGateSensor {
|
|
6813
|
+
constructor(options) {
|
|
6814
|
+
this.name = "RiskGateSensor";
|
|
6815
|
+
this.order = sensor_bands_1.BAND.BUSINESS + 10;
|
|
6816
|
+
this.collectors = options.collectors;
|
|
6817
|
+
this.denyThreshold = options.denyThreshold ?? 75;
|
|
6818
|
+
this.flagThreshold = options.flagThreshold ?? 40;
|
|
6819
|
+
}
|
|
6820
|
+
async run(input) {
|
|
6821
|
+
const results = await Promise.all(this.collectors.map((c) => c(input)));
|
|
6822
|
+
const signals = results.flat();
|
|
6823
|
+
let totalWeight = 0;
|
|
6824
|
+
let weightedSum = 0;
|
|
6825
|
+
for (const signal of signals) {
|
|
6826
|
+
const w = SEVERITY_WEIGHT[signal.severity];
|
|
6827
|
+
totalWeight += 1;
|
|
6828
|
+
weightedSum += w;
|
|
6829
|
+
}
|
|
6830
|
+
const aggregateScore = totalWeight > 0 ? Math.min(100, Math.round(weightedSum / totalWeight)) : 0;
|
|
6831
|
+
const evaluation = this.evaluate(aggregateScore, signals);
|
|
6832
|
+
input.metadata = {
|
|
6833
|
+
...input.metadata ?? {},
|
|
6834
|
+
riskEvaluation: evaluation
|
|
6835
|
+
};
|
|
6836
|
+
if (evaluation.decision === risk_1.RiskDecision.DENY) {
|
|
6837
|
+
return {
|
|
6838
|
+
allow: false,
|
|
6839
|
+
riskScore: aggregateScore,
|
|
6840
|
+
reasons: signals.map((s) => s.message),
|
|
6841
|
+
code: "RISK_GATE_DENY",
|
|
6842
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
6843
|
+
};
|
|
6844
|
+
}
|
|
6845
|
+
if (evaluation.decision === risk_1.RiskDecision.THROTTLE) {
|
|
6846
|
+
return {
|
|
6847
|
+
allow: false,
|
|
6848
|
+
riskScore: aggregateScore,
|
|
6849
|
+
reasons: signals.map((s) => s.message),
|
|
6850
|
+
code: "RISK_GATE_THROTTLE",
|
|
6851
|
+
retryAfterMs: evaluation.retryAfterMs,
|
|
6852
|
+
tags: { riskDecision: evaluation.decision, signalCount: signals.length }
|
|
6853
|
+
};
|
|
6854
|
+
}
|
|
6855
|
+
return {
|
|
6856
|
+
allow: true,
|
|
6857
|
+
riskScore: aggregateScore,
|
|
6858
|
+
reasons: signals.filter((s) => s.severity === "medium" || s.severity === "high").map((s) => s.message),
|
|
6859
|
+
tags: {
|
|
6860
|
+
riskDecision: evaluation.decision,
|
|
6861
|
+
signalCount: signals.length
|
|
6862
|
+
}
|
|
6863
|
+
};
|
|
6864
|
+
}
|
|
6865
|
+
evaluate(score, signals) {
|
|
6866
|
+
const hasCritical = signals.some((s) => s.severity === "critical");
|
|
6867
|
+
if (hasCritical) {
|
|
6868
|
+
return {
|
|
6869
|
+
decision: risk_1.RiskDecision.DENY,
|
|
6870
|
+
reason: "Critical risk signal detected",
|
|
6871
|
+
confidence: 1,
|
|
6872
|
+
signals
|
|
6873
|
+
};
|
|
6874
|
+
}
|
|
6875
|
+
if (score >= this.denyThreshold) {
|
|
6876
|
+
return {
|
|
6877
|
+
decision: risk_1.RiskDecision.DENY,
|
|
6878
|
+
reason: `Aggregate risk score ${score} exceeds deny threshold ${this.denyThreshold}`,
|
|
6879
|
+
confidence: score / 100,
|
|
6880
|
+
signals
|
|
6881
|
+
};
|
|
6882
|
+
}
|
|
6883
|
+
if (score >= this.flagThreshold) {
|
|
6884
|
+
return {
|
|
6885
|
+
decision: risk_1.RiskDecision.STEP_UP,
|
|
6886
|
+
reason: `Aggregate risk score ${score} exceeds flag threshold ${this.flagThreshold}`,
|
|
6887
|
+
confidence: score / 100,
|
|
6888
|
+
signals
|
|
6889
|
+
};
|
|
6890
|
+
}
|
|
6891
|
+
return {
|
|
6892
|
+
decision: risk_1.RiskDecision.ALLOW,
|
|
6893
|
+
confidence: 1 - score / 100,
|
|
6894
|
+
signals
|
|
6895
|
+
};
|
|
6896
|
+
}
|
|
6897
|
+
};
|
|
6898
|
+
exports.RiskGateSensor = RiskGateSensor2;
|
|
6899
|
+
exports.RiskGateSensor = RiskGateSensor2 = __decorate([
|
|
6900
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
6901
|
+
(0, common_1.Injectable)(),
|
|
6902
|
+
__metadata("design:paramtypes", [Object])
|
|
6903
|
+
], RiskGateSensor2);
|
|
6904
|
+
}
|
|
6905
|
+
});
|
|
6906
|
+
|
|
6907
|
+
// src/sensors/tickauth.sensor.ts
|
|
6908
|
+
var require_tickauth_sensor = __commonJS({
|
|
6909
|
+
"src/sensors/tickauth.sensor.ts"(exports) {
|
|
6910
|
+
"use strict";
|
|
6911
|
+
var __decorate = exports && exports.__decorate || function(decorators, target, key, desc) {
|
|
6912
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6913
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6914
|
+
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;
|
|
6915
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6916
|
+
};
|
|
6917
|
+
var __metadata = exports && exports.__metadata || function(k, v) {
|
|
6918
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6919
|
+
};
|
|
6920
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6921
|
+
exports.TickAuthSensor = void 0;
|
|
6922
|
+
var common_1 = __require("@nestjs/common");
|
|
6923
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
6924
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
6925
|
+
var TickAuthSensor2 = class TickAuthSensor {
|
|
6926
|
+
constructor(options = {}) {
|
|
6927
|
+
this.name = "TickAuthSensor";
|
|
6928
|
+
this.order = sensor_bands_1.BAND.IDENTITY + 40;
|
|
6929
|
+
this.verifier = options.verifier;
|
|
6930
|
+
this.matchIntent = options.matchIntent ?? true;
|
|
6931
|
+
this.acceptTypes = options.acceptTypes?.length ? new Set(options.acceptTypes) : null;
|
|
6932
|
+
}
|
|
6933
|
+
supports(input) {
|
|
6934
|
+
return !!(input.metadata?.capsule || input.metadata?.tickauthCapsule || input.metadata?.cceEnvelope?.capsule);
|
|
6935
|
+
}
|
|
6936
|
+
async run(input) {
|
|
6937
|
+
const capsule = input.metadata?.capsule ?? input.metadata?.tickauthCapsule ?? input.metadata?.cceEnvelope?.capsule;
|
|
6938
|
+
if (!capsule) {
|
|
6939
|
+
return {
|
|
6940
|
+
allow: false,
|
|
6941
|
+
riskScore: 90,
|
|
6942
|
+
reasons: ["TickAuth capsule not found"],
|
|
6943
|
+
code: "TICKAUTH_MISSING"
|
|
6944
|
+
};
|
|
6945
|
+
}
|
|
6946
|
+
if (!capsule.capsule_id || typeof capsule.capsule_id !== "string") {
|
|
6947
|
+
return {
|
|
6948
|
+
allow: false,
|
|
6949
|
+
riskScore: 100,
|
|
6950
|
+
reasons: ["TickAuth capsule has no valid capsule_id"],
|
|
6951
|
+
code: "TICKAUTH_INVALID_ID"
|
|
6952
|
+
};
|
|
6953
|
+
}
|
|
6954
|
+
const status = capsule.verification?.status;
|
|
6955
|
+
if (status && status !== "approved") {
|
|
6956
|
+
return {
|
|
6957
|
+
allow: false,
|
|
6958
|
+
riskScore: 100,
|
|
6959
|
+
reasons: [
|
|
6960
|
+
`TickAuth capsule status is '${status}'${capsule.verification?.reason ? `: ${capsule.verification.reason}` : ""}`
|
|
6961
|
+
],
|
|
6962
|
+
code: `TICKAUTH_STATUS_${status.toUpperCase()}`
|
|
6963
|
+
};
|
|
6964
|
+
}
|
|
6965
|
+
if (this.acceptTypes && capsule.capsule_type) {
|
|
6966
|
+
if (!this.acceptTypes.has(capsule.capsule_type)) {
|
|
6967
|
+
return {
|
|
6968
|
+
allow: false,
|
|
6969
|
+
riskScore: 80,
|
|
6970
|
+
reasons: [
|
|
6971
|
+
`TickAuth capsule type '${capsule.capsule_type}' is not in accept list`
|
|
6972
|
+
],
|
|
6973
|
+
code: "TICKAUTH_TYPE_REJECTED"
|
|
6974
|
+
};
|
|
6975
|
+
}
|
|
6976
|
+
}
|
|
6977
|
+
if (this.matchIntent && input.intent && capsule.intent) {
|
|
6978
|
+
if (capsule.intent !== input.intent) {
|
|
6979
|
+
return {
|
|
6980
|
+
allow: false,
|
|
6981
|
+
riskScore: 80,
|
|
6982
|
+
reasons: [
|
|
6983
|
+
`TickAuth capsule intent '${capsule.intent}' does not match AXIS intent '${input.intent}'`
|
|
6984
|
+
],
|
|
6985
|
+
code: "TICKAUTH_INTENT_MISMATCH"
|
|
6986
|
+
};
|
|
6987
|
+
}
|
|
6988
|
+
}
|
|
6989
|
+
if (this.verifier) {
|
|
6990
|
+
const error = await this.verifier(capsule, input);
|
|
6991
|
+
if (error) {
|
|
6992
|
+
return {
|
|
6993
|
+
allow: false,
|
|
6994
|
+
riskScore: 90,
|
|
6995
|
+
reasons: [`TickAuth verification failed: ${error}`],
|
|
6996
|
+
code: "TICKAUTH_VERIFY_FAILED"
|
|
6997
|
+
};
|
|
6998
|
+
}
|
|
6999
|
+
}
|
|
7000
|
+
return {
|
|
7001
|
+
allow: true,
|
|
7002
|
+
riskScore: 0,
|
|
7003
|
+
reasons: [],
|
|
7004
|
+
tags: {
|
|
7005
|
+
tickauthCapsuleId: capsule.capsule_id,
|
|
7006
|
+
tickauthMode: capsule.mode,
|
|
7007
|
+
tickauthSingleUse: capsule.single_use
|
|
7008
|
+
}
|
|
7009
|
+
};
|
|
7010
|
+
}
|
|
7011
|
+
};
|
|
7012
|
+
exports.TickAuthSensor = TickAuthSensor2;
|
|
7013
|
+
exports.TickAuthSensor = TickAuthSensor2 = __decorate([
|
|
7014
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
7015
|
+
(0, common_1.Injectable)(),
|
|
7016
|
+
__metadata("design:paramtypes", [Object])
|
|
7017
|
+
], TickAuthSensor2);
|
|
7018
|
+
}
|
|
7019
|
+
});
|
|
7020
|
+
|
|
7021
|
+
// src/cce/sensors/cce-envelope-validation.sensor.ts
|
|
7022
|
+
var REQUIRED_FIELDS, CceEnvelopeValidationSensor;
|
|
7023
|
+
var init_cce_envelope_validation_sensor = __esm({
|
|
7024
|
+
"src/cce/sensors/cce-envelope-validation.sensor.ts"() {
|
|
7025
|
+
init_axis_sensor();
|
|
7026
|
+
init_cce_types();
|
|
7027
|
+
REQUIRED_FIELDS = [
|
|
7028
|
+
"ver",
|
|
7029
|
+
"request_id",
|
|
7030
|
+
"correlation_id",
|
|
7031
|
+
"client_kid",
|
|
7032
|
+
"capsule",
|
|
7033
|
+
"encrypted_key",
|
|
7034
|
+
"encrypted_payload",
|
|
7035
|
+
"request_nonce",
|
|
7036
|
+
"client_sig",
|
|
7037
|
+
"content_type",
|
|
7038
|
+
"algorithms"
|
|
7039
|
+
];
|
|
7040
|
+
CceEnvelopeValidationSensor = class {
|
|
7041
|
+
constructor() {
|
|
7042
|
+
this.name = "cce.envelope.validation";
|
|
7043
|
+
this.order = 5;
|
|
7044
|
+
this.phase = "PRE_DECODE";
|
|
7045
|
+
}
|
|
7046
|
+
supports(input) {
|
|
7047
|
+
return input.metadata?.cce === true || input.metadata?.contentType === "application/axis-cce";
|
|
7048
|
+
}
|
|
7049
|
+
async run(input) {
|
|
7050
|
+
const envelope = input.metadata?.cceEnvelope;
|
|
7051
|
+
if (!envelope) {
|
|
7052
|
+
return {
|
|
7053
|
+
allow: false,
|
|
7054
|
+
riskScore: 100,
|
|
7055
|
+
reasons: [CCE_ERROR.INVALID_ENVELOPE],
|
|
7056
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7057
|
+
};
|
|
7058
|
+
}
|
|
7059
|
+
for (const field of REQUIRED_FIELDS) {
|
|
7060
|
+
if (envelope[field] === void 0 || envelope[field] === null) {
|
|
7061
|
+
return {
|
|
7062
|
+
allow: false,
|
|
7063
|
+
riskScore: 100,
|
|
7064
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: missing ${field}`],
|
|
7065
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7066
|
+
};
|
|
7067
|
+
}
|
|
7068
|
+
}
|
|
7069
|
+
if (envelope.ver !== CCE_PROTOCOL_VERSION) {
|
|
7070
|
+
return {
|
|
7071
|
+
allow: false,
|
|
7072
|
+
riskScore: 100,
|
|
7073
|
+
reasons: [`${CCE_ERROR.UNSUPPORTED_VERSION}: ${envelope.ver}`],
|
|
7074
|
+
code: CCE_ERROR.UNSUPPORTED_VERSION
|
|
7075
|
+
};
|
|
7076
|
+
}
|
|
7077
|
+
if (!/^[0-9a-f]+$/i.test(envelope.request_nonce)) {
|
|
7078
|
+
return {
|
|
7079
|
+
allow: false,
|
|
7080
|
+
riskScore: 100,
|
|
7081
|
+
reasons: [
|
|
7082
|
+
`${CCE_ERROR.INVALID_ENVELOPE}: invalid request_nonce format`
|
|
7083
|
+
],
|
|
7084
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7085
|
+
};
|
|
7086
|
+
}
|
|
7087
|
+
if (envelope.request_nonce.length !== CCE_NONCE_BYTES * 2) {
|
|
7088
|
+
return {
|
|
7089
|
+
allow: false,
|
|
7090
|
+
riskScore: 100,
|
|
7091
|
+
reasons: [`${CCE_ERROR.INVALID_ENVELOPE}: request_nonce wrong length`],
|
|
7092
|
+
code: CCE_ERROR.INVALID_ENVELOPE
|
|
7093
|
+
};
|
|
7094
|
+
}
|
|
7095
|
+
const capsule = envelope.capsule;
|
|
7096
|
+
if (!capsule.capsule_id || !capsule.ver || !capsule.sub || !capsule.kid || !capsule.intent || !capsule.aud || !capsule.issuer_sig) {
|
|
7097
|
+
return {
|
|
7098
|
+
allow: false,
|
|
7099
|
+
riskScore: 100,
|
|
7100
|
+
reasons: [`${CCE_ERROR.MISSING_CAPSULE}: incomplete capsule claims`],
|
|
7101
|
+
code: CCE_ERROR.MISSING_CAPSULE
|
|
7102
|
+
};
|
|
7103
|
+
}
|
|
7104
|
+
if (!envelope.encrypted_key.ciphertext || !envelope.encrypted_key.alg) {
|
|
7105
|
+
return {
|
|
7106
|
+
allow: false,
|
|
7107
|
+
riskScore: 100,
|
|
7108
|
+
reasons: [
|
|
7109
|
+
`${CCE_ERROR.MISSING_ENCRYPTED_KEY}: incomplete encrypted_key`
|
|
7110
|
+
],
|
|
4815
7111
|
code: CCE_ERROR.MISSING_ENCRYPTED_KEY
|
|
4816
7112
|
};
|
|
4817
7113
|
}
|
|
@@ -5530,94 +7826,19 @@ var init_cce = __esm({
|
|
|
5530
7826
|
// src/core/index.ts
|
|
5531
7827
|
var core_exports = {};
|
|
5532
7828
|
__export(core_exports, {
|
|
5533
|
-
AXIS_MAGIC: () => AXIS_MAGIC,
|
|
5534
|
-
AXIS_VERSION: () => AXIS_VERSION,
|
|
5535
7829
|
AxisError: () => AxisError,
|
|
5536
7830
|
AxisFrameZ: () => AxisFrameZ,
|
|
5537
|
-
BodyProfile: () => BodyProfile,
|
|
5538
|
-
ERR_BAD_SIGNATURE: () => ERR_BAD_SIGNATURE,
|
|
5539
|
-
ERR_CONTRACT_VIOLATION: () => ERR_CONTRACT_VIOLATION,
|
|
5540
|
-
ERR_INVALID_PACKET: () => ERR_INVALID_PACKET,
|
|
5541
|
-
ERR_REPLAY_DETECTED: () => ERR_REPLAY_DETECTED,
|
|
5542
|
-
FLAG_BODY_TLV: () => FLAG_BODY_TLV,
|
|
5543
|
-
FLAG_CHAIN_REQ: () => FLAG_CHAIN_REQ,
|
|
5544
|
-
FLAG_HAS_WITNESS: () => FLAG_HAS_WITNESS,
|
|
5545
|
-
MAX_BODY_LEN: () => MAX_BODY_LEN,
|
|
5546
|
-
MAX_FRAME_LEN: () => MAX_FRAME_LEN,
|
|
5547
|
-
MAX_HDR_LEN: () => MAX_HDR_LEN,
|
|
5548
|
-
MAX_SIG_LEN: () => MAX_SIG_LEN,
|
|
5549
|
-
NCERT_ALG: () => NCERT_ALG,
|
|
5550
|
-
NCERT_EXP: () => NCERT_EXP,
|
|
5551
|
-
NCERT_ISSUER_KID: () => NCERT_ISSUER_KID,
|
|
5552
|
-
NCERT_KID: () => NCERT_KID,
|
|
5553
|
-
NCERT_NBF: () => NCERT_NBF,
|
|
5554
|
-
NCERT_NODE_ID: () => NCERT_NODE_ID,
|
|
5555
|
-
NCERT_PAYLOAD: () => NCERT_PAYLOAD,
|
|
5556
|
-
NCERT_PUB: () => NCERT_PUB,
|
|
5557
|
-
NCERT_SCOPE: () => NCERT_SCOPE,
|
|
5558
|
-
NCERT_SIG: () => NCERT_SIG,
|
|
5559
|
-
PROOF_CAPSULE: () => PROOF_CAPSULE,
|
|
5560
|
-
PROOF_JWT: () => PROOF_JWT,
|
|
5561
|
-
PROOF_LOOM: () => PROOF_LOOM,
|
|
5562
|
-
PROOF_MTLS: () => PROOF_MTLS,
|
|
5563
|
-
PROOF_NONE: () => PROOF_NONE,
|
|
5564
|
-
PROOF_WITNESS: () => PROOF_WITNESS,
|
|
5565
|
-
ProofType: () => ProofType,
|
|
5566
|
-
TLV: () => TLV,
|
|
5567
|
-
TLV_ACTOR_ID: () => TLV_ACTOR_ID,
|
|
5568
|
-
TLV_AUD: () => TLV_AUD,
|
|
5569
|
-
TLV_BODY_ARR: () => TLV_BODY_ARR,
|
|
5570
|
-
TLV_BODY_OBJ: () => TLV_BODY_OBJ,
|
|
5571
|
-
TLV_CAPSULE: () => TLV_CAPSULE,
|
|
5572
|
-
TLV_EFFECT: () => TLV_EFFECT,
|
|
5573
|
-
TLV_ERROR_CODE: () => TLV_ERROR_CODE,
|
|
5574
|
-
TLV_ERROR_MSG: () => TLV_ERROR_MSG,
|
|
5575
|
-
TLV_INDEX: () => TLV_INDEX,
|
|
5576
|
-
TLV_INTENT: () => TLV_INTENT,
|
|
5577
|
-
TLV_KID: () => TLV_KID,
|
|
5578
|
-
TLV_LOOM_PRESENCE_ID: () => TLV_LOOM_PRESENCE_ID,
|
|
5579
|
-
TLV_LOOM_THREAD_HASH: () => TLV_LOOM_THREAD_HASH,
|
|
5580
|
-
TLV_LOOM_WRIT: () => TLV_LOOM_WRIT,
|
|
5581
|
-
TLV_NODE: () => TLV_NODE,
|
|
5582
|
-
TLV_NODE_CERT_HASH: () => TLV_NODE_CERT_HASH,
|
|
5583
|
-
TLV_NODE_KID: () => TLV_NODE_KID,
|
|
5584
|
-
TLV_NONCE: () => TLV_NONCE,
|
|
5585
|
-
TLV_OFFSET: () => TLV_OFFSET,
|
|
5586
|
-
TLV_OK: () => TLV_OK,
|
|
5587
|
-
TLV_PID: () => TLV_PID,
|
|
5588
|
-
TLV_PREV_HASH: () => TLV_PREV_HASH,
|
|
5589
|
-
TLV_PROOF_REF: () => TLV_PROOF_REF,
|
|
5590
|
-
TLV_PROOF_TYPE: () => TLV_PROOF_TYPE,
|
|
5591
|
-
TLV_REALM: () => TLV_REALM,
|
|
5592
|
-
TLV_RECEIPT_HASH: () => TLV_RECEIPT_HASH,
|
|
5593
|
-
TLV_RID: () => TLV_RID,
|
|
5594
|
-
TLV_SHA256_CHUNK: () => TLV_SHA256_CHUNK,
|
|
5595
|
-
TLV_TRACE_ID: () => TLV_TRACE_ID,
|
|
5596
|
-
TLV_TS: () => TLV_TS,
|
|
5597
|
-
TLV_UPLOAD_ID: () => TLV_UPLOAD_ID,
|
|
5598
7831
|
computeReceiptHash: () => computeReceiptHash,
|
|
5599
7832
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
5600
|
-
decodeArray: () => decodeArray,
|
|
5601
|
-
decodeFrame: () => decodeFrame,
|
|
5602
|
-
decodeObject: () => decodeObject,
|
|
5603
|
-
decodeTLVs: () => decodeTLVs,
|
|
5604
|
-
decodeTLVsList: () => decodeTLVsList,
|
|
5605
|
-
decodeVarint: () => decodeVarint,
|
|
5606
|
-
encodeFrame: () => encodeFrame,
|
|
5607
|
-
encodeTLVs: () => encodeTLVs,
|
|
5608
|
-
encodeVarint: () => encodeVarint,
|
|
5609
7833
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
5610
|
-
getSignTarget: () => getSignTarget,
|
|
5611
7834
|
sha256: () => sha2564,
|
|
5612
7835
|
signFrame: () => signFrame,
|
|
5613
|
-
varintLength: () => varintLength,
|
|
5614
7836
|
verifyFrameSignature: () => verifyFrameSignature
|
|
5615
7837
|
});
|
|
7838
|
+
import * as axis_protocol_star from "@nextera.one/axis-protocol";
|
|
5616
7839
|
var init_core = __esm({
|
|
5617
7840
|
"src/core/index.ts"() {
|
|
5618
|
-
|
|
5619
|
-
init_varint();
|
|
5620
|
-
init_tlv();
|
|
7841
|
+
__reExport(core_exports, axis_protocol_star);
|
|
5621
7842
|
init_axis_bin();
|
|
5622
7843
|
init_signature();
|
|
5623
7844
|
init_axis_error();
|
|
@@ -5864,15 +8085,7 @@ __export(decorators_exports, {
|
|
|
5864
8085
|
IntentBody: () => IntentBody,
|
|
5865
8086
|
IntentSensors: () => IntentSensors,
|
|
5866
8087
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
5867
|
-
Sensor: () => Sensor
|
|
5868
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
5869
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
5870
|
-
TlvEnum: () => TlvEnum,
|
|
5871
|
-
TlvField: () => TlvField,
|
|
5872
|
-
TlvMinLen: () => TlvMinLen,
|
|
5873
|
-
TlvRange: () => TlvRange,
|
|
5874
|
-
TlvUtf8Pattern: () => TlvUtf8Pattern,
|
|
5875
|
-
TlvValidate: () => TlvValidate
|
|
8088
|
+
Sensor: () => Sensor
|
|
5876
8089
|
});
|
|
5877
8090
|
var init_decorators = __esm({
|
|
5878
8091
|
"src/decorators/index.ts"() {
|
|
@@ -5883,7 +8096,7 @@ var init_decorators = __esm({
|
|
|
5883
8096
|
init_intent_sensors_decorator();
|
|
5884
8097
|
init_intent_decorator();
|
|
5885
8098
|
init_sensor_decorator();
|
|
5886
|
-
|
|
8099
|
+
__reExport(decorators_exports, __toESM(require_tlv_field_decorator()));
|
|
5887
8100
|
}
|
|
5888
8101
|
});
|
|
5889
8102
|
|
|
@@ -5961,6 +8174,25 @@ var init_engine = __esm({
|
|
|
5961
8174
|
}
|
|
5962
8175
|
});
|
|
5963
8176
|
|
|
8177
|
+
// src/idel/idel.types.ts
|
|
8178
|
+
var init_idel_types = __esm({
|
|
8179
|
+
"src/idel/idel.types.ts"() {
|
|
8180
|
+
}
|
|
8181
|
+
});
|
|
8182
|
+
|
|
8183
|
+
// src/idel/index.ts
|
|
8184
|
+
var idel_exports = {};
|
|
8185
|
+
__export(idel_exports, {
|
|
8186
|
+
IdelCompiler: () => IdelCompiler,
|
|
8187
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry
|
|
8188
|
+
});
|
|
8189
|
+
var init_idel = __esm({
|
|
8190
|
+
"src/idel/index.ts"() {
|
|
8191
|
+
init_idel_types();
|
|
8192
|
+
init_idel_compiler();
|
|
8193
|
+
}
|
|
8194
|
+
});
|
|
8195
|
+
|
|
5964
8196
|
// src/loom/index.ts
|
|
5965
8197
|
var loom_exports = {};
|
|
5966
8198
|
__export(loom_exports, {
|
|
@@ -5970,11 +8202,98 @@ __export(loom_exports, {
|
|
|
5970
8202
|
TLV_WRIT: () => TLV_LOOM_WRIT,
|
|
5971
8203
|
canonicalizeGrant: () => canonicalizeGrant,
|
|
5972
8204
|
canonicalizeWrit: () => canonicalizeWrit,
|
|
5973
|
-
|
|
8205
|
+
createGrant: () => createGrant,
|
|
8206
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
8207
|
+
createReceipt: () => createReceipt,
|
|
8208
|
+
createRevocation: () => createRevocation,
|
|
8209
|
+
createWrit: () => createWrit,
|
|
8210
|
+
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
8211
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
8212
|
+
getGrantStatus: () => getGrantStatus,
|
|
8213
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
8214
|
+
grantCoversAction: () => grantCoversAction,
|
|
8215
|
+
isRevoked: () => isRevoked,
|
|
8216
|
+
renewPresence: () => renewPresence,
|
|
8217
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
8218
|
+
updateThreadState: () => updateThreadState,
|
|
8219
|
+
validateGrant: () => validateGrant,
|
|
8220
|
+
validateWrit: () => validateWrit,
|
|
8221
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
8222
|
+
verifyReceiptChain: () => verifyReceiptChain
|
|
5974
8223
|
});
|
|
5975
8224
|
var init_loom = __esm({
|
|
5976
8225
|
"src/loom/index.ts"() {
|
|
5977
8226
|
init_loom_types();
|
|
8227
|
+
init_loom_engine();
|
|
8228
|
+
}
|
|
8229
|
+
});
|
|
8230
|
+
|
|
8231
|
+
// src/needle/needle.types.ts
|
|
8232
|
+
var init_needle_types = __esm({
|
|
8233
|
+
"src/needle/needle.types.ts"() {
|
|
8234
|
+
}
|
|
8235
|
+
});
|
|
8236
|
+
|
|
8237
|
+
// src/needle/knot.types.ts
|
|
8238
|
+
var init_knot_types = __esm({
|
|
8239
|
+
"src/needle/knot.types.ts"() {
|
|
8240
|
+
}
|
|
8241
|
+
});
|
|
8242
|
+
|
|
8243
|
+
// src/needle/fabric.types.ts
|
|
8244
|
+
var init_fabric_types = __esm({
|
|
8245
|
+
"src/needle/fabric.types.ts"() {
|
|
8246
|
+
}
|
|
8247
|
+
});
|
|
8248
|
+
|
|
8249
|
+
// src/needle/pattern.types.ts
|
|
8250
|
+
var init_pattern_types = __esm({
|
|
8251
|
+
"src/needle/pattern.types.ts"() {
|
|
8252
|
+
}
|
|
8253
|
+
});
|
|
8254
|
+
|
|
8255
|
+
// src/needle/index.ts
|
|
8256
|
+
var needle_exports = {};
|
|
8257
|
+
__export(needle_exports, {
|
|
8258
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
8259
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
8260
|
+
applyStitch: () => applyStitch,
|
|
8261
|
+
assembleNeedle: () => assembleNeedle,
|
|
8262
|
+
breakKnot: () => breakKnot,
|
|
8263
|
+
createFabric: () => createFabric,
|
|
8264
|
+
detectAnomalies: () => detectAnomalies,
|
|
8265
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
8266
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
8267
|
+
diffFabrics: () => diffFabrics,
|
|
8268
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
8269
|
+
forkFromKnot: () => forkFromKnot,
|
|
8270
|
+
formStitch: () => formStitch,
|
|
8271
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
8272
|
+
getFabricValue: () => getFabricValue,
|
|
8273
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
8274
|
+
isKnotOpen: () => isKnotOpen,
|
|
8275
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
8276
|
+
lockCells: () => lockCells,
|
|
8277
|
+
matchPatterns: () => matchPatterns,
|
|
8278
|
+
openKnot: () => openKnot,
|
|
8279
|
+
projectAt: () => projectAt,
|
|
8280
|
+
queryFabric: () => queryFabric,
|
|
8281
|
+
recordOccurrence: () => recordOccurrence,
|
|
8282
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
8283
|
+
tieKnot: () => tieKnot,
|
|
8284
|
+
validateKnot: () => validateKnot,
|
|
8285
|
+
weave: () => weave
|
|
8286
|
+
});
|
|
8287
|
+
var init_needle = __esm({
|
|
8288
|
+
"src/needle/index.ts"() {
|
|
8289
|
+
init_needle_types();
|
|
8290
|
+
init_needle_engine();
|
|
8291
|
+
init_knot_types();
|
|
8292
|
+
init_knot_engine();
|
|
8293
|
+
init_fabric_types();
|
|
8294
|
+
init_fabric_engine();
|
|
8295
|
+
init_pattern_types();
|
|
8296
|
+
init_pattern_engine();
|
|
5978
8297
|
}
|
|
5979
8298
|
});
|
|
5980
8299
|
|
|
@@ -7260,6 +9579,143 @@ var require_intent_registry_sensor = __commonJS({
|
|
|
7260
9579
|
}
|
|
7261
9580
|
});
|
|
7262
9581
|
|
|
9582
|
+
// src/sensors/law-evaluation.sensor.ts
|
|
9583
|
+
var require_law_evaluation_sensor = __commonJS({
|
|
9584
|
+
"src/sensors/law-evaluation.sensor.ts"(exports) {
|
|
9585
|
+
"use strict";
|
|
9586
|
+
var __decorate = exports && exports.__decorate || function(decorators, target, key, desc) {
|
|
9587
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9588
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9589
|
+
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;
|
|
9590
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9591
|
+
};
|
|
9592
|
+
var __metadata = exports && exports.__metadata || function(k, v) {
|
|
9593
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9594
|
+
};
|
|
9595
|
+
var LawEvaluationSensor_1;
|
|
9596
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9597
|
+
exports.LawEvaluationSensor = void 0;
|
|
9598
|
+
var common_1 = __require("@nestjs/common");
|
|
9599
|
+
var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
|
|
9600
|
+
var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
|
|
9601
|
+
var law_1 = (init_law(), __toCommonJS(law_exports));
|
|
9602
|
+
var LawEvaluationSensor = LawEvaluationSensor_1 = class LawEvaluationSensor {
|
|
9603
|
+
constructor(options = {}) {
|
|
9604
|
+
this.options = options;
|
|
9605
|
+
this.logger = new common_1.Logger(LawEvaluationSensor_1.name);
|
|
9606
|
+
this.name = "LawEvaluationSensor";
|
|
9607
|
+
this.order = sensor_bands_1.BAND.POLICY + 5;
|
|
9608
|
+
}
|
|
9609
|
+
supports(input) {
|
|
9610
|
+
return !!this.options.evaluator && !!input.intent;
|
|
9611
|
+
}
|
|
9612
|
+
async run(input) {
|
|
9613
|
+
const evaluator = this.options.evaluator;
|
|
9614
|
+
if (!evaluator) {
|
|
9615
|
+
return { action: "ALLOW" };
|
|
9616
|
+
}
|
|
9617
|
+
const context = (0, law_1.buildAxisLawEvaluationContext)(input);
|
|
9618
|
+
let result;
|
|
9619
|
+
try {
|
|
9620
|
+
result = await evaluator(context);
|
|
9621
|
+
} catch (error) {
|
|
9622
|
+
const message = error instanceof Error ? error.message : "Unknown law evaluation error";
|
|
9623
|
+
this.logger.error(`Law evaluation failed for ${input.intent}: ${message}`);
|
|
9624
|
+
input.metadata = {
|
|
9625
|
+
...input.metadata ?? {},
|
|
9626
|
+
lawEvaluation: {
|
|
9627
|
+
decision: "deny",
|
|
9628
|
+
reason: "Law evaluation failed",
|
|
9629
|
+
explanation: message
|
|
9630
|
+
}
|
|
9631
|
+
};
|
|
9632
|
+
return {
|
|
9633
|
+
action: "DENY",
|
|
9634
|
+
code: "LAW_EVALUATION_ERROR",
|
|
9635
|
+
reason: message,
|
|
9636
|
+
meta: { lawDecision: "deny" }
|
|
9637
|
+
};
|
|
9638
|
+
}
|
|
9639
|
+
input.metadata = {
|
|
9640
|
+
...input.metadata ?? {},
|
|
9641
|
+
lawEvaluation: {
|
|
9642
|
+
...result,
|
|
9643
|
+
context: sanitizeLawContext(context)
|
|
9644
|
+
}
|
|
9645
|
+
};
|
|
9646
|
+
if (result.decision === "allow") {
|
|
9647
|
+
return {
|
|
9648
|
+
allow: true,
|
|
9649
|
+
riskScore: 0,
|
|
9650
|
+
reasons: result.reason ? [result.reason] : [],
|
|
9651
|
+
tags: {
|
|
9652
|
+
lawDecision: "allow",
|
|
9653
|
+
...result.applicable ? { lawApplicableArticles: result.applicable.length } : {}
|
|
9654
|
+
},
|
|
9655
|
+
meta: result
|
|
9656
|
+
};
|
|
9657
|
+
}
|
|
9658
|
+
if (result.decision === "conditional") {
|
|
9659
|
+
const mode = this.options.conditionalDecision ?? "deny";
|
|
9660
|
+
const reasons = [result.reason, result.explanation].filter(Boolean);
|
|
9661
|
+
if (mode === "allow") {
|
|
9662
|
+
return {
|
|
9663
|
+
allow: true,
|
|
9664
|
+
riskScore: 0,
|
|
9665
|
+
reasons,
|
|
9666
|
+
tags: {
|
|
9667
|
+
lawDecision: "conditional"
|
|
9668
|
+
},
|
|
9669
|
+
meta: result
|
|
9670
|
+
};
|
|
9671
|
+
}
|
|
9672
|
+
if (mode === "flag") {
|
|
9673
|
+
return {
|
|
9674
|
+
action: "FLAG",
|
|
9675
|
+
scoreDelta: 25,
|
|
9676
|
+
reasons: reasons.length > 0 ? reasons : ["Execution is conditionally permitted pending additional requirements"],
|
|
9677
|
+
meta: result
|
|
9678
|
+
};
|
|
9679
|
+
}
|
|
9680
|
+
return {
|
|
9681
|
+
action: "DENY",
|
|
9682
|
+
code: "LAW_CONDITIONAL",
|
|
9683
|
+
reason: reasons.join(" | ") || "Execution is conditionally permitted pending additional requirements",
|
|
9684
|
+
meta: { lawDecision: "conditional", evaluation: result }
|
|
9685
|
+
};
|
|
9686
|
+
}
|
|
9687
|
+
return {
|
|
9688
|
+
action: "DENY",
|
|
9689
|
+
code: "LAW_DENIED",
|
|
9690
|
+
reason: [result.reason, result.explanation].filter(Boolean).join(" | ") || "Execution denied by law evaluation",
|
|
9691
|
+
meta: { lawDecision: "deny", evaluation: result }
|
|
9692
|
+
};
|
|
9693
|
+
}
|
|
9694
|
+
};
|
|
9695
|
+
exports.LawEvaluationSensor = LawEvaluationSensor;
|
|
9696
|
+
exports.LawEvaluationSensor = LawEvaluationSensor = LawEvaluationSensor_1 = __decorate([
|
|
9697
|
+
(0, sensor_decorator_1.Sensor)(),
|
|
9698
|
+
(0, common_1.Injectable)(),
|
|
9699
|
+
__metadata("design:paramtypes", [Object])
|
|
9700
|
+
], LawEvaluationSensor);
|
|
9701
|
+
function sanitizeLawContext(context) {
|
|
9702
|
+
return {
|
|
9703
|
+
actorId: context.actorId,
|
|
9704
|
+
intent: context.intent,
|
|
9705
|
+
audience: context.audience,
|
|
9706
|
+
tps: context.tps,
|
|
9707
|
+
country: context.country,
|
|
9708
|
+
ip: context.ip,
|
|
9709
|
+
path: context.path,
|
|
9710
|
+
clientId: context.clientId,
|
|
9711
|
+
deviceId: context.deviceId,
|
|
9712
|
+
sessionId: context.sessionId,
|
|
9713
|
+
capsuleId: context.capsuleId
|
|
9714
|
+
};
|
|
9715
|
+
}
|
|
9716
|
+
}
|
|
9717
|
+
});
|
|
9718
|
+
|
|
7263
9719
|
// src/sensors/proof-presence.sensor.ts
|
|
7264
9720
|
var require_proof_presence_sensor = __commonJS({
|
|
7265
9721
|
"src/sensors/proof-presence.sensor.ts"(exports) {
|
|
@@ -7967,16 +10423,40 @@ var init_sensors2 = __esm({
|
|
|
7967
10423
|
__reExport(sensors_exports, __toESM(require_header_tlv_limit_sensor()));
|
|
7968
10424
|
__reExport(sensors_exports, __toESM(require_intent_allowlist_sensor()));
|
|
7969
10425
|
__reExport(sensors_exports, __toESM(require_intent_registry_sensor()));
|
|
10426
|
+
__reExport(sensors_exports, __toESM(require_law_evaluation_sensor()));
|
|
7970
10427
|
__reExport(sensors_exports, __toESM(require_proof_presence_sensor()));
|
|
7971
10428
|
__reExport(sensors_exports, __toESM(require_protocol_strict_sensor()));
|
|
7972
10429
|
__reExport(sensors_exports, __toESM(require_receipt_policy_sensor()));
|
|
10430
|
+
__reExport(sensors_exports, __toESM(require_risk_gate_sensor()));
|
|
7973
10431
|
__reExport(sensors_exports, __toESM(require_schema_validation_sensor()));
|
|
7974
10432
|
__reExport(sensors_exports, __toESM(require_stream_scope_sensor()));
|
|
10433
|
+
__reExport(sensors_exports, __toESM(require_tickauth_sensor()));
|
|
7975
10434
|
__reExport(sensors_exports, __toESM(require_tlv_parse_sensor()));
|
|
10435
|
+
__reExport(sensors_exports, __toESM(require_tps_sensor()));
|
|
7976
10436
|
__reExport(sensors_exports, __toESM(require_varint_hardening_sensor()));
|
|
7977
10437
|
}
|
|
7978
10438
|
});
|
|
7979
10439
|
|
|
10440
|
+
// src/timeline/timeline.types.ts
|
|
10441
|
+
var init_timeline_types = __esm({
|
|
10442
|
+
"src/timeline/timeline.types.ts"() {
|
|
10443
|
+
}
|
|
10444
|
+
});
|
|
10445
|
+
|
|
10446
|
+
// src/timeline/index.ts
|
|
10447
|
+
var timeline_exports = {};
|
|
10448
|
+
__export(timeline_exports, {
|
|
10449
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
10450
|
+
TimelineEngine: () => TimelineEngine
|
|
10451
|
+
});
|
|
10452
|
+
var init_timeline = __esm({
|
|
10453
|
+
"src/timeline/index.ts"() {
|
|
10454
|
+
init_timeline_types();
|
|
10455
|
+
init_timeline_store();
|
|
10456
|
+
init_timeline_engine();
|
|
10457
|
+
}
|
|
10458
|
+
});
|
|
10459
|
+
|
|
7980
10460
|
// src/utils/index.ts
|
|
7981
10461
|
var utils_exports = {};
|
|
7982
10462
|
__export(utils_exports, {
|
|
@@ -8047,6 +10527,10 @@ __export(index_exports, {
|
|
|
8047
10527
|
INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
|
|
8048
10528
|
INTENT_SENSORS_KEY: () => INTENT_SENSORS_KEY,
|
|
8049
10529
|
INTENT_TIMEOUTS: () => INTENT_TIMEOUTS,
|
|
10530
|
+
IdelCompiler: () => IdelCompiler,
|
|
10531
|
+
IdelSchemaRegistry: () => IdelSchemaRegistry,
|
|
10532
|
+
InMemoryPatternStore: () => InMemoryPatternStore,
|
|
10533
|
+
InMemoryTimelineStore: () => InMemoryTimelineStore,
|
|
8050
10534
|
Intent: () => Intent,
|
|
8051
10535
|
IntentBody: () => IntentBody,
|
|
8052
10536
|
IntentRouter: () => import_intent2.IntentRouter,
|
|
@@ -8082,6 +10566,7 @@ __export(index_exports, {
|
|
|
8082
10566
|
RESPONSE_TAG_UPDATED_BY: () => import_axis_response.RESPONSE_TAG_UPDATED_BY,
|
|
8083
10567
|
ResponseObserver: () => ResponseObserver,
|
|
8084
10568
|
RiskDecision: () => RiskDecision,
|
|
10569
|
+
RiskGateSensor: () => import_risk_gate.RiskGateSensor,
|
|
8085
10570
|
SENSOR_METADATA_KEY: () => SENSOR_METADATA_KEY,
|
|
8086
10571
|
Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
|
|
8087
10572
|
Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -8100,7 +10585,7 @@ __export(index_exports, {
|
|
|
8100
10585
|
TLV_EFFECT: () => TLV_EFFECT,
|
|
8101
10586
|
TLV_ERROR_CODE: () => TLV_ERROR_CODE,
|
|
8102
10587
|
TLV_ERROR_MSG: () => TLV_ERROR_MSG,
|
|
8103
|
-
TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
|
|
10588
|
+
TLV_FIELDS_KEY: () => import_tlv_field2.TLV_FIELDS_KEY,
|
|
8104
10589
|
TLV_INDEX: () => TLV_INDEX,
|
|
8105
10590
|
TLV_INTENT: () => TLV_INTENT,
|
|
8106
10591
|
TLV_KID: () => TLV_KID,
|
|
@@ -8126,20 +10611,28 @@ __export(index_exports, {
|
|
|
8126
10611
|
TLV_TRACE_ID: () => TLV_TRACE_ID,
|
|
8127
10612
|
TLV_TS: () => TLV_TS,
|
|
8128
10613
|
TLV_UPLOAD_ID: () => TLV_UPLOAD_ID,
|
|
8129
|
-
TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
|
|
10614
|
+
TLV_VALIDATORS_KEY: () => import_tlv_field2.TLV_VALIDATORS_KEY,
|
|
8130
10615
|
TLV_WRIT: () => TLV_LOOM_WRIT,
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
10616
|
+
TickAuthSensor: () => import_tickauth.TickAuthSensor,
|
|
10617
|
+
TimelineEngine: () => TimelineEngine,
|
|
10618
|
+
TlvEnum: () => import_tlv_field2.TlvEnum,
|
|
10619
|
+
TlvField: () => import_tlv_field2.TlvField,
|
|
10620
|
+
TlvMinLen: () => import_tlv_field2.TlvMinLen,
|
|
10621
|
+
TlvRange: () => import_tlv_field2.TlvRange,
|
|
10622
|
+
TlvUtf8Pattern: () => import_tlv_field2.TlvUtf8Pattern,
|
|
10623
|
+
TlvValidate: () => import_tlv_field2.TlvValidate,
|
|
10624
|
+
TpsSensor: () => import_tps.TpsSensor,
|
|
10625
|
+
addStitchToKnot: () => addStitchToKnot,
|
|
10626
|
+
applyStitch: () => applyStitch,
|
|
10627
|
+
assembleNeedle: () => assembleNeedle,
|
|
8137
10628
|
axis1SigningBytes: () => axis1SigningBytes,
|
|
8138
10629
|
b64urlDecode: () => b64urlDecode,
|
|
8139
10630
|
b64urlDecodeString: () => b64urlDecodeString,
|
|
8140
10631
|
b64urlEncode: () => b64urlEncode,
|
|
8141
10632
|
b64urlEncodeString: () => b64urlEncodeString,
|
|
10633
|
+
breakKnot: () => breakKnot,
|
|
8142
10634
|
buildAts1Hdr: () => buildAts1Hdr,
|
|
10635
|
+
buildAxisLawEvaluationContext: () => buildAxisLawEvaluationContext,
|
|
8143
10636
|
buildDtoDecoder: () => import_dto_schema.buildDtoDecoder,
|
|
8144
10637
|
buildPacket: () => buildPacket,
|
|
8145
10638
|
buildQueueMessage: () => buildQueueMessage,
|
|
@@ -8158,7 +10651,13 @@ __export(index_exports, {
|
|
|
8158
10651
|
computeReceiptHash: () => computeReceiptHash,
|
|
8159
10652
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
8160
10653
|
core: () => core_exports,
|
|
10654
|
+
createFabric: () => createFabric,
|
|
10655
|
+
createGrant: () => createGrant,
|
|
8161
10656
|
createObservation: () => createObservation,
|
|
10657
|
+
createPresenceChallenge: () => createPresenceChallenge,
|
|
10658
|
+
createReceipt: () => createReceipt,
|
|
10659
|
+
createRevocation: () => createRevocation,
|
|
10660
|
+
createWrit: () => createWrit,
|
|
8162
10661
|
crypto: () => crypto_exports,
|
|
8163
10662
|
decodeArray: () => decodeArray,
|
|
8164
10663
|
decodeAxis1Frame: () => decodeAxis1Frame,
|
|
@@ -8170,6 +10669,10 @@ __export(index_exports, {
|
|
|
8170
10669
|
decodeVarint: () => decodeVarint,
|
|
8171
10670
|
decorators: () => decorators_exports,
|
|
8172
10671
|
deriveAnchorReflection: () => deriveAnchorReflection,
|
|
10672
|
+
detectAnomalies: () => detectAnomalies,
|
|
10673
|
+
detectKnotPatterns: () => detectKnotPatterns,
|
|
10674
|
+
detectSequencePatterns: () => detectSequencePatterns,
|
|
10675
|
+
diffFabrics: () => diffFabrics,
|
|
8173
10676
|
encVarint: () => encVarint,
|
|
8174
10677
|
encodeAxis1Frame: () => encodeAxis1Frame,
|
|
8175
10678
|
encodeAxisTlvDto: () => encodeAxisTlvDto,
|
|
@@ -8180,18 +10683,36 @@ __export(index_exports, {
|
|
|
8180
10683
|
endStage: () => endStage,
|
|
8181
10684
|
engine: () => engine_exports,
|
|
8182
10685
|
executeCcePipeline: () => executeCcePipeline,
|
|
10686
|
+
executeLoomPipeline: () => executeLoomPipeline,
|
|
8183
10687
|
extractDtoSchema: () => import_dto_schema.extractDtoSchema,
|
|
8184
10688
|
finalizeObservation: () => finalizeObservation,
|
|
10689
|
+
findKnotsForStitch: () => findKnotsForStitch,
|
|
10690
|
+
forkFromKnot: () => forkFromKnot,
|
|
10691
|
+
formStitch: () => formStitch,
|
|
8185
10692
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
10693
|
+
getDecisionPoints: () => getDecisionPoints,
|
|
10694
|
+
getFabricValue: () => getFabricValue,
|
|
10695
|
+
getGrantStatus: () => getGrantStatus,
|
|
10696
|
+
getIrreversibleKnots: () => getIrreversibleKnots,
|
|
10697
|
+
getPresenceStatus: () => getPresenceStatus,
|
|
8186
10698
|
getSignTarget: () => getSignTarget,
|
|
10699
|
+
grantCoversAction: () => grantCoversAction,
|
|
8187
10700
|
hasScope: () => hasScope,
|
|
8188
10701
|
hashObservation: () => hashObservation,
|
|
10702
|
+
idel: () => idel_exports,
|
|
8189
10703
|
isAdminOpcode: () => isAdminOpcode,
|
|
10704
|
+
isKnotOpen: () => isKnotOpen,
|
|
8190
10705
|
isKnownOpcode: () => isKnownOpcode,
|
|
10706
|
+
isPointOfNoReturn: () => isPointOfNoReturn,
|
|
10707
|
+
isRevoked: () => isRevoked,
|
|
8191
10708
|
isTimestampValid: () => isTimestampValid,
|
|
10709
|
+
lockCells: () => lockCells,
|
|
8192
10710
|
loom: () => loom_exports,
|
|
10711
|
+
matchPatterns: () => matchPatterns,
|
|
10712
|
+
needle: () => needle_exports,
|
|
8193
10713
|
nonce16: () => nonce16,
|
|
8194
10714
|
normalizeSensorDecision: () => normalizeSensorDecision,
|
|
10715
|
+
openKnot: () => openKnot,
|
|
8195
10716
|
packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
|
|
8196
10717
|
packPasskeyLoginOptionsRes: () => packPasskeyLoginOptionsRes,
|
|
8197
10718
|
packPasskeyLoginVerifyReq: () => packPasskeyLoginVerifyReq,
|
|
@@ -8200,30 +10721,47 @@ __export(index_exports, {
|
|
|
8200
10721
|
parseAutoClaimEntries: () => parseAutoClaimEntries,
|
|
8201
10722
|
parseScope: () => parseScope,
|
|
8202
10723
|
parseStreamEntries: () => parseStreamEntries,
|
|
10724
|
+
projectAt: () => projectAt,
|
|
10725
|
+
queryFabric: () => queryFabric,
|
|
10726
|
+
recordOccurrence: () => recordOccurrence,
|
|
8203
10727
|
recordSensor: () => recordSensor,
|
|
10728
|
+
renewPresence: () => renewPresence,
|
|
8204
10729
|
resolveTimeout: () => resolveTimeout,
|
|
10730
|
+
runNeedlePipeline: () => runNeedlePipeline,
|
|
8205
10731
|
schemas: () => schemas_exports,
|
|
10732
|
+
scoreTruth: () => scoreTruth,
|
|
8206
10733
|
security: () => security_exports,
|
|
8207
10734
|
sensitivityName: () => sensitivityName,
|
|
8208
10735
|
sensors: () => sensors_exports,
|
|
8209
10736
|
sha256: () => sha2564,
|
|
8210
10737
|
signFrame: () => signFrame,
|
|
10738
|
+
signPresenceChallenge: () => signPresenceChallenge,
|
|
8211
10739
|
stableJsonStringify: () => stableJsonStringify,
|
|
8212
10740
|
startStage: () => startStage,
|
|
10741
|
+
tieKnot: () => tieKnot,
|
|
10742
|
+
timeline: () => timeline_exports,
|
|
8213
10743
|
tlv: () => tlv,
|
|
8214
10744
|
u64be: () => u64be,
|
|
8215
10745
|
unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
|
|
8216
10746
|
unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
|
|
8217
10747
|
unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
|
|
10748
|
+
updateThreadState: () => updateThreadState,
|
|
8218
10749
|
utf8: () => utf8,
|
|
8219
10750
|
utils: () => utils_exports,
|
|
8220
10751
|
validateFrameShape: () => validateFrameShape,
|
|
10752
|
+
validateGrant: () => validateGrant,
|
|
10753
|
+
validateKnot: () => validateKnot,
|
|
10754
|
+
validateWrit: () => validateWrit,
|
|
8221
10755
|
varintLength: () => varintLength,
|
|
8222
10756
|
varintU: () => varintU,
|
|
8223
10757
|
verifyFrameSignature: () => verifyFrameSignature,
|
|
8224
|
-
|
|
10758
|
+
verifyObservation: () => verifyObservation,
|
|
10759
|
+
verifyPresenceProof: () => verifyPresenceProof,
|
|
10760
|
+
verifyReceiptChain: () => verifyReceiptChain,
|
|
10761
|
+
verifyResponse: () => verifyResponse,
|
|
10762
|
+
weave: () => weave
|
|
8225
10763
|
});
|
|
8226
|
-
var import_dto_schema, import_axis_id, import_axis_response, import_intent2, import_axis_files, import_axis_request, import_handler_discovery, import_sensor_discovery, import_sensor2, import_axis_sensor_chain;
|
|
10764
|
+
var import_tlv_field2, import_dto_schema, import_axis_id, import_axis_response, import_intent2, import_axis_files, import_axis_request, import_handler_discovery, import_sensor_discovery, import_sensor2, import_axis_sensor_chain, import_tps, import_risk_gate, import_tickauth;
|
|
8227
10765
|
var init_index = __esm({
|
|
8228
10766
|
"src/index.ts"() {
|
|
8229
10767
|
init_handler_decorator();
|
|
@@ -8232,7 +10770,7 @@ var init_index = __esm({
|
|
|
8232
10770
|
init_intent_sensors_decorator();
|
|
8233
10771
|
init_handler_sensors_decorator();
|
|
8234
10772
|
init_sensor_decorator();
|
|
8235
|
-
|
|
10773
|
+
import_tlv_field2 = __toESM(require_tlv_field_decorator());
|
|
8236
10774
|
import_dto_schema = __toESM(require_dto_schema_util());
|
|
8237
10775
|
init_axis_tlv_dto();
|
|
8238
10776
|
import_axis_id = __toESM(require_axis_id_dto());
|
|
@@ -8243,6 +10781,7 @@ var init_index = __esm({
|
|
|
8243
10781
|
init_stable_json();
|
|
8244
10782
|
init_observation_queue_codec();
|
|
8245
10783
|
init_observation_hash();
|
|
10784
|
+
init_truth_scoring();
|
|
8246
10785
|
init_response_observer();
|
|
8247
10786
|
init_constants();
|
|
8248
10787
|
init_varint();
|
|
@@ -8264,6 +10803,7 @@ var init_index = __esm({
|
|
|
8264
10803
|
init_axis_sensor();
|
|
8265
10804
|
init_scopes();
|
|
8266
10805
|
init_capabilities();
|
|
10806
|
+
init_law();
|
|
8267
10807
|
init_risk();
|
|
8268
10808
|
init_opcodes();
|
|
8269
10809
|
init_receipt();
|
|
@@ -8280,19 +10820,33 @@ var init_index = __esm({
|
|
|
8280
10820
|
import_sensor2 = __toESM(require_sensor_registry());
|
|
8281
10821
|
init_axis_observation();
|
|
8282
10822
|
import_axis_sensor_chain = __toESM(require_axis_sensor_chain_service());
|
|
10823
|
+
init_timeline_engine();
|
|
10824
|
+
init_timeline_store();
|
|
8283
10825
|
init_cce_pipeline();
|
|
8284
10826
|
init_cce_types();
|
|
8285
10827
|
init_axis_tlv_codec();
|
|
8286
10828
|
init_loom_types();
|
|
10829
|
+
init_loom_engine();
|
|
10830
|
+
init_idel_compiler();
|
|
10831
|
+
init_needle_engine();
|
|
10832
|
+
init_knot_engine();
|
|
10833
|
+
init_fabric_engine();
|
|
10834
|
+
init_pattern_engine();
|
|
10835
|
+
import_tps = __toESM(require_tps_sensor());
|
|
10836
|
+
import_risk_gate = __toESM(require_risk_gate_sensor());
|
|
10837
|
+
import_tickauth = __toESM(require_tickauth_sensor());
|
|
8287
10838
|
init_cce();
|
|
8288
10839
|
init_core();
|
|
8289
10840
|
init_crypto();
|
|
8290
10841
|
init_decorators();
|
|
8291
10842
|
init_engine();
|
|
10843
|
+
init_idel();
|
|
8292
10844
|
init_loom();
|
|
10845
|
+
init_needle();
|
|
8293
10846
|
init_schemas();
|
|
8294
10847
|
init_security();
|
|
8295
10848
|
init_sensors2();
|
|
10849
|
+
init_timeline();
|
|
8296
10850
|
init_utils();
|
|
8297
10851
|
}
|
|
8298
10852
|
});
|
|
@@ -8314,8 +10868,19 @@ var export_RESPONSE_TAG_CREATED_BY = import_axis_response.RESPONSE_TAG_CREATED_B
|
|
|
8314
10868
|
var export_RESPONSE_TAG_ID = import_axis_response.RESPONSE_TAG_ID;
|
|
8315
10869
|
var export_RESPONSE_TAG_UPDATED_AT = import_axis_response.RESPONSE_TAG_UPDATED_AT;
|
|
8316
10870
|
var export_RESPONSE_TAG_UPDATED_BY = import_axis_response.RESPONSE_TAG_UPDATED_BY;
|
|
10871
|
+
var export_RiskGateSensor = import_risk_gate.RiskGateSensor;
|
|
8317
10872
|
var export_SensorDiscoveryService = import_sensor_discovery.SensorDiscoveryService;
|
|
8318
10873
|
var export_SensorRegistry = import_sensor2.SensorRegistry;
|
|
10874
|
+
var export_TLV_FIELDS_KEY = import_tlv_field2.TLV_FIELDS_KEY;
|
|
10875
|
+
var export_TLV_VALIDATORS_KEY = import_tlv_field2.TLV_VALIDATORS_KEY;
|
|
10876
|
+
var export_TickAuthSensor = import_tickauth.TickAuthSensor;
|
|
10877
|
+
var export_TlvEnum = import_tlv_field2.TlvEnum;
|
|
10878
|
+
var export_TlvField = import_tlv_field2.TlvField;
|
|
10879
|
+
var export_TlvMinLen = import_tlv_field2.TlvMinLen;
|
|
10880
|
+
var export_TlvRange = import_tlv_field2.TlvRange;
|
|
10881
|
+
var export_TlvUtf8Pattern = import_tlv_field2.TlvUtf8Pattern;
|
|
10882
|
+
var export_TlvValidate = import_tlv_field2.TlvValidate;
|
|
10883
|
+
var export_TpsSensor = import_tps.TpsSensor;
|
|
8319
10884
|
var export_buildDtoDecoder = import_dto_schema.buildDtoDecoder;
|
|
8320
10885
|
var export_extractDtoSchema = import_dto_schema.extractDtoSchema;
|
|
8321
10886
|
export {
|
|
@@ -8375,6 +10940,10 @@ export {
|
|
|
8375
10940
|
INTENT_SENSITIVITY_MAP,
|
|
8376
10941
|
INTENT_SENSORS_KEY,
|
|
8377
10942
|
INTENT_TIMEOUTS,
|
|
10943
|
+
IdelCompiler,
|
|
10944
|
+
IdelSchemaRegistry,
|
|
10945
|
+
InMemoryPatternStore,
|
|
10946
|
+
InMemoryTimelineStore,
|
|
8378
10947
|
Intent,
|
|
8379
10948
|
IntentBody,
|
|
8380
10949
|
export_IntentRouter as IntentRouter,
|
|
@@ -8410,6 +10979,7 @@ export {
|
|
|
8410
10979
|
export_RESPONSE_TAG_UPDATED_BY as RESPONSE_TAG_UPDATED_BY,
|
|
8411
10980
|
ResponseObserver,
|
|
8412
10981
|
RiskDecision,
|
|
10982
|
+
export_RiskGateSensor as RiskGateSensor,
|
|
8413
10983
|
SENSOR_METADATA_KEY,
|
|
8414
10984
|
Schema2002_PasskeyLoginOptionsRes,
|
|
8415
10985
|
Schema2011_PasskeyLoginVerifyReq,
|
|
@@ -8428,7 +10998,7 @@ export {
|
|
|
8428
10998
|
TLV_EFFECT,
|
|
8429
10999
|
TLV_ERROR_CODE,
|
|
8430
11000
|
TLV_ERROR_MSG,
|
|
8431
|
-
TLV_FIELDS_KEY,
|
|
11001
|
+
export_TLV_FIELDS_KEY as TLV_FIELDS_KEY,
|
|
8432
11002
|
TLV_INDEX,
|
|
8433
11003
|
TLV_INTENT,
|
|
8434
11004
|
TLV_KID,
|
|
@@ -8454,20 +11024,28 @@ export {
|
|
|
8454
11024
|
TLV_TRACE_ID,
|
|
8455
11025
|
TLV_TS,
|
|
8456
11026
|
TLV_UPLOAD_ID,
|
|
8457
|
-
TLV_VALIDATORS_KEY,
|
|
11027
|
+
export_TLV_VALIDATORS_KEY as TLV_VALIDATORS_KEY,
|
|
8458
11028
|
TLV_LOOM_WRIT as TLV_WRIT,
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
11029
|
+
export_TickAuthSensor as TickAuthSensor,
|
|
11030
|
+
TimelineEngine,
|
|
11031
|
+
export_TlvEnum as TlvEnum,
|
|
11032
|
+
export_TlvField as TlvField,
|
|
11033
|
+
export_TlvMinLen as TlvMinLen,
|
|
11034
|
+
export_TlvRange as TlvRange,
|
|
11035
|
+
export_TlvUtf8Pattern as TlvUtf8Pattern,
|
|
11036
|
+
export_TlvValidate as TlvValidate,
|
|
11037
|
+
export_TpsSensor as TpsSensor,
|
|
11038
|
+
addStitchToKnot,
|
|
11039
|
+
applyStitch,
|
|
11040
|
+
assembleNeedle,
|
|
8465
11041
|
axis1SigningBytes,
|
|
8466
11042
|
b64urlDecode,
|
|
8467
11043
|
b64urlDecodeString,
|
|
8468
11044
|
b64urlEncode,
|
|
8469
11045
|
b64urlEncodeString,
|
|
11046
|
+
breakKnot,
|
|
8470
11047
|
buildAts1Hdr,
|
|
11048
|
+
buildAxisLawEvaluationContext,
|
|
8471
11049
|
export_buildDtoDecoder as buildDtoDecoder,
|
|
8472
11050
|
buildPacket,
|
|
8473
11051
|
buildQueueMessage,
|
|
@@ -8486,7 +11064,13 @@ export {
|
|
|
8486
11064
|
computeReceiptHash,
|
|
8487
11065
|
computeSignaturePayload,
|
|
8488
11066
|
core_exports as core,
|
|
11067
|
+
createFabric,
|
|
11068
|
+
createGrant,
|
|
8489
11069
|
createObservation,
|
|
11070
|
+
createPresenceChallenge,
|
|
11071
|
+
createReceipt,
|
|
11072
|
+
createRevocation,
|
|
11073
|
+
createWrit,
|
|
8490
11074
|
crypto_exports as crypto,
|
|
8491
11075
|
decodeArray,
|
|
8492
11076
|
decodeAxis1Frame,
|
|
@@ -8498,6 +11082,10 @@ export {
|
|
|
8498
11082
|
decodeVarint,
|
|
8499
11083
|
decorators_exports as decorators,
|
|
8500
11084
|
deriveAnchorReflection,
|
|
11085
|
+
detectAnomalies,
|
|
11086
|
+
detectKnotPatterns,
|
|
11087
|
+
detectSequencePatterns,
|
|
11088
|
+
diffFabrics,
|
|
8501
11089
|
encVarint,
|
|
8502
11090
|
encodeAxis1Frame,
|
|
8503
11091
|
encodeAxisTlvDto,
|
|
@@ -8508,18 +11096,36 @@ export {
|
|
|
8508
11096
|
endStage,
|
|
8509
11097
|
engine_exports as engine,
|
|
8510
11098
|
executeCcePipeline,
|
|
11099
|
+
executeLoomPipeline,
|
|
8511
11100
|
export_extractDtoSchema as extractDtoSchema,
|
|
8512
11101
|
finalizeObservation,
|
|
11102
|
+
findKnotsForStitch,
|
|
11103
|
+
forkFromKnot,
|
|
11104
|
+
formStitch,
|
|
8513
11105
|
generateEd25519KeyPair,
|
|
11106
|
+
getDecisionPoints,
|
|
11107
|
+
getFabricValue,
|
|
11108
|
+
getGrantStatus,
|
|
11109
|
+
getIrreversibleKnots,
|
|
11110
|
+
getPresenceStatus,
|
|
8514
11111
|
getSignTarget,
|
|
11112
|
+
grantCoversAction,
|
|
8515
11113
|
hasScope,
|
|
8516
11114
|
hashObservation,
|
|
11115
|
+
idel_exports as idel,
|
|
8517
11116
|
isAdminOpcode,
|
|
11117
|
+
isKnotOpen,
|
|
8518
11118
|
isKnownOpcode,
|
|
11119
|
+
isPointOfNoReturn,
|
|
11120
|
+
isRevoked,
|
|
8519
11121
|
isTimestampValid,
|
|
11122
|
+
lockCells,
|
|
8520
11123
|
loom_exports as loom,
|
|
11124
|
+
matchPatterns,
|
|
11125
|
+
needle_exports as needle,
|
|
8521
11126
|
nonce16,
|
|
8522
11127
|
normalizeSensorDecision,
|
|
11128
|
+
openKnot,
|
|
8523
11129
|
packPasskeyLoginOptionsReq,
|
|
8524
11130
|
packPasskeyLoginOptionsRes,
|
|
8525
11131
|
packPasskeyLoginVerifyReq,
|
|
@@ -8528,27 +11134,44 @@ export {
|
|
|
8528
11134
|
parseAutoClaimEntries,
|
|
8529
11135
|
parseScope,
|
|
8530
11136
|
parseStreamEntries,
|
|
11137
|
+
projectAt,
|
|
11138
|
+
queryFabric,
|
|
11139
|
+
recordOccurrence,
|
|
8531
11140
|
recordSensor,
|
|
11141
|
+
renewPresence,
|
|
8532
11142
|
resolveTimeout,
|
|
11143
|
+
runNeedlePipeline,
|
|
8533
11144
|
schemas_exports as schemas,
|
|
11145
|
+
scoreTruth,
|
|
8534
11146
|
security_exports as security,
|
|
8535
11147
|
sensitivityName,
|
|
8536
11148
|
sensors_exports as sensors,
|
|
8537
11149
|
sha2564 as sha256,
|
|
8538
11150
|
signFrame,
|
|
11151
|
+
signPresenceChallenge,
|
|
8539
11152
|
stableJsonStringify,
|
|
8540
11153
|
startStage,
|
|
11154
|
+
tieKnot,
|
|
11155
|
+
timeline_exports as timeline,
|
|
8541
11156
|
tlv,
|
|
8542
11157
|
u64be,
|
|
8543
11158
|
unpackPasskeyLoginOptionsReq,
|
|
8544
11159
|
unpackPasskeyLoginVerifyReq,
|
|
8545
11160
|
unpackPasskeyRegisterOptionsReq,
|
|
11161
|
+
updateThreadState,
|
|
8546
11162
|
utf8,
|
|
8547
11163
|
utils_exports as utils,
|
|
8548
11164
|
validateFrameShape,
|
|
11165
|
+
validateGrant,
|
|
11166
|
+
validateKnot,
|
|
11167
|
+
validateWrit,
|
|
8549
11168
|
varintLength,
|
|
8550
11169
|
varintU,
|
|
8551
11170
|
verifyFrameSignature,
|
|
8552
|
-
|
|
11171
|
+
verifyObservation,
|
|
11172
|
+
verifyPresenceProof,
|
|
11173
|
+
verifyReceiptChain,
|
|
11174
|
+
verifyResponse,
|
|
11175
|
+
weave
|
|
8553
11176
|
};
|
|
8554
11177
|
//# sourceMappingURL=index.mjs.map
|