@nextera.one/axis-server-sdk 0.9.3 → 1.1.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/index.js CHANGED
@@ -43,19 +43,18 @@ __export(index_exports, {
43
43
  AXIS_OPCODES: () => AXIS_OPCODES,
44
44
  AXIS_VERSION: () => AXIS_VERSION,
45
45
  Ats1Codec: () => ats1_exports,
46
- AuthLevel: () => AuthLevel,
47
46
  AxisFrameZ: () => AxisFrameZ,
47
+ AxisIdDto: () => AxisIdDto,
48
48
  AxisPacketTags: () => T,
49
+ AxisPartialType: () => AxisPartialType,
50
+ AxisResponseDto: () => AxisResponseDto,
51
+ AxisTlvDto: () => AxisTlvDto,
49
52
  BodyProfile: () => BodyProfile,
50
53
  CAPABILITIES: () => CAPABILITIES,
51
- CapsuleStatus: () => CapsuleStatus,
52
54
  ContractViolationError: () => ContractViolationError,
53
55
  DEFAULT_CONTRACTS: () => DEFAULT_CONTRACTS,
54
56
  DEFAULT_TIMEOUT: () => DEFAULT_TIMEOUT,
55
57
  Decision: () => Decision,
56
- DeviceStatus: () => DeviceStatus,
57
- DeviceTrustLevel: () => DeviceTrustLevel,
58
- DeviceType: () => DeviceType,
59
58
  ERR_BAD_SIGNATURE: () => ERR_BAD_SIGNATURE,
60
59
  ERR_CONTRACT_VIOLATION: () => ERR_CONTRACT_VIOLATION,
61
60
  ERR_INVALID_PACKET: () => ERR_INVALID_PACKET,
@@ -67,6 +66,7 @@ __export(index_exports, {
67
66
  FLAG_HAS_WITNESS: () => FLAG_HAS_WITNESS,
68
67
  HANDLER_METADATA_KEY: () => HANDLER_METADATA_KEY,
69
68
  Handler: () => Handler,
69
+ INTENT_METADATA_KEY: () => INTENT_METADATA_KEY,
70
70
  INTENT_REQUIREMENTS: () => INTENT_REQUIREMENTS,
71
71
  INTENT_ROUTES_KEY: () => INTENT_ROUTES_KEY,
72
72
  INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
@@ -74,7 +74,6 @@ __export(index_exports, {
74
74
  Intent: () => Intent,
75
75
  IntentRouter: () => IntentRouter,
76
76
  IntentSensitivity: () => IntentSensitivity,
77
- LoginChallengeStatus: () => LoginChallengeStatus,
78
77
  MAX_BODY_LEN: () => MAX_BODY_LEN,
79
78
  MAX_FRAME_LEN: () => MAX_FRAME_LEN,
80
79
  MAX_HDR_LEN: () => MAX_HDR_LEN,
@@ -89,10 +88,6 @@ __export(index_exports, {
89
88
  NCERT_PUB: () => NCERT_PUB,
90
89
  NCERT_SCOPE: () => NCERT_SCOPE,
91
90
  NCERT_SIG: () => NCERT_SIG,
92
- NESTFLOW_INTENTS: () => NESTFLOW_INTENTS,
93
- NESTFLOW_INTENT_SET: () => NESTFLOW_INTENT_SET,
94
- NESTFLOW_POLICY_MAP: () => NESTFLOW_POLICY_MAP,
95
- NestFlowCapsuleType: () => NestFlowCapsuleType,
96
91
  PROOF_CAPABILITIES: () => PROOF_CAPABILITIES,
97
92
  PROOF_CAPSULE: () => PROOF_CAPSULE,
98
93
  PROOF_JWT: () => PROOF_JWT,
@@ -101,13 +96,17 @@ __export(index_exports, {
101
96
  PROOF_NONE: () => PROOF_NONE,
102
97
  PROOF_WITNESS: () => PROOF_WITNESS,
103
98
  ProofType: () => ProofType,
99
+ RESPONSE_TAG_CREATED_AT: () => RESPONSE_TAG_CREATED_AT,
100
+ RESPONSE_TAG_CREATED_BY: () => RESPONSE_TAG_CREATED_BY,
101
+ RESPONSE_TAG_ID: () => RESPONSE_TAG_ID,
102
+ RESPONSE_TAG_UPDATED_AT: () => RESPONSE_TAG_UPDATED_AT,
103
+ RESPONSE_TAG_UPDATED_BY: () => RESPONSE_TAG_UPDATED_BY,
104
104
  RiskDecision: () => RiskDecision,
105
105
  Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
106
106
  Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
107
107
  Schema2012_PasskeyLoginVerifyRes: () => Schema2012_PasskeyLoginVerifyRes,
108
108
  Schema2021_PasskeyRegisterOptionsReq: () => Schema2021_PasskeyRegisterOptionsReq,
109
109
  SensorDecisions: () => SensorDecisions,
110
- SessionStatus: () => SessionStatus,
111
110
  TLV_ACTOR_ID: () => TLV_ACTOR_ID,
112
111
  TLV_AUD: () => TLV_AUD,
113
112
  TLV_BODY_ARR: () => TLV_BODY_ARR,
@@ -116,6 +115,7 @@ __export(index_exports, {
116
115
  TLV_EFFECT: () => TLV_EFFECT,
117
116
  TLV_ERROR_CODE: () => TLV_ERROR_CODE,
118
117
  TLV_ERROR_MSG: () => TLV_ERROR_MSG,
118
+ TLV_FIELDS_KEY: () => TLV_FIELDS_KEY,
119
119
  TLV_INDEX: () => TLV_INDEX,
120
120
  TLV_INTENT: () => TLV_INTENT,
121
121
  TLV_KID: () => TLV_KID,
@@ -139,15 +139,20 @@ __export(index_exports, {
139
139
  TLV_TRACE_ID: () => TLV_TRACE_ID,
140
140
  TLV_TS: () => TLV_TS,
141
141
  TLV_UPLOAD_ID: () => TLV_UPLOAD_ID,
142
- TickAuthChallengeStatus: () => TickAuthChallengeStatus,
143
- TrustLinkStatus: () => TrustLinkStatus,
144
- TrustLinkType: () => TrustLinkType,
142
+ TLV_VALIDATORS_KEY: () => TLV_VALIDATORS_KEY,
143
+ TlvEnum: () => TlvEnum,
144
+ TlvField: () => TlvField,
145
+ TlvMinLen: () => TlvMinLen,
146
+ TlvRange: () => TlvRange,
147
+ TlvUtf8Pattern: () => TlvUtf8Pattern,
148
+ TlvValidate: () => TlvValidate,
145
149
  axis1SigningBytes: () => axis1SigningBytes,
146
150
  b64urlDecode: () => b64urlDecode,
147
151
  b64urlDecodeString: () => b64urlDecodeString,
148
152
  b64urlEncode: () => b64urlEncode,
149
153
  b64urlEncodeString: () => b64urlEncodeString,
150
154
  buildAts1Hdr: () => buildAts1Hdr,
155
+ buildDtoDecoder: () => buildDtoDecoder,
151
156
  buildPacket: () => buildPacket,
152
157
  buildReceiptHash: () => buildReceiptHash,
153
158
  buildTLVs: () => buildTLVs,
@@ -155,14 +160,6 @@ __export(index_exports, {
155
160
  canAccessResource: () => canAccessResource,
156
161
  canonicalJson: () => canonicalJson,
157
162
  canonicalJsonExcluding: () => canonicalJsonExcluding,
158
- checkBrowserProof: () => checkBrowserProof,
159
- checkCapsule: () => checkCapsule,
160
- checkDeviceTrust: () => checkDeviceTrust,
161
- checkIntentPolicy: () => checkIntentPolicy,
162
- checkLoginChallenge: () => checkLoginChallenge,
163
- checkReplayProtection: () => checkReplayProtection,
164
- checkSession: () => checkSession,
165
- checkTickAuth: () => checkTickAuth,
166
163
  classifyIntent: () => classifyIntent,
167
164
  computeReceiptHash: () => computeReceiptHash,
168
165
  computeSignaturePayload: () => computeSignaturePayload,
@@ -178,18 +175,12 @@ __export(index_exports, {
178
175
  encodeFrame: () => encodeFrame,
179
176
  encodeTLVs: () => encodeTLVs,
180
177
  encodeVarint: () => encodeVarint,
178
+ extractDtoSchema: () => extractDtoSchema,
181
179
  generateEd25519KeyPair: () => generateEd25519KeyPair,
182
- getRequiredAuthLevel: () => getRequiredAuthLevel,
183
180
  getSignTarget: () => getSignTarget,
184
181
  hasScope: () => hasScope,
185
182
  isAdminOpcode: () => isAdminOpcode,
186
- isCapsuleTerminal: () => isCapsuleTerminal,
187
- isDeviceTerminal: () => isDeviceTerminal,
188
183
  isKnownOpcode: () => isKnownOpcode,
189
- isLoginChallengeTerminal: () => isLoginChallengeTerminal,
190
- isNestFlowIntent: () => isNestFlowIntent,
191
- isSessionTerminal: () => isSessionTerminal,
192
- isTickAuthTerminal: () => isTickAuthTerminal,
193
184
  isTimestampValid: () => isTimestampValid,
194
185
  nonce16: () => nonce16,
195
186
  normalizeSensorDecision: () => normalizeSensorDecision,
@@ -200,7 +191,6 @@ __export(index_exports, {
200
191
  packPasskeyRegisterOptionsReq: () => packPasskeyRegisterOptionsReq,
201
192
  parseScope: () => parseScope,
202
193
  resolveTimeout: () => resolveTimeout,
203
- satisfiesAuthLevel: () => satisfiesAuthLevel,
204
194
  sensitivityName: () => sensitivityName,
205
195
  sha256: () => sha256,
206
196
  signFrame: () => signFrame,
@@ -210,13 +200,7 @@ __export(index_exports, {
210
200
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
211
201
  unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
212
202
  utf8: () => utf8,
213
- validateCapsuleTransition: () => validateCapsuleTransition,
214
- validateDeviceTransition: () => validateDeviceTransition,
215
203
  validateFrameShape: () => validateFrameShape,
216
- validateLoginChallengeTransition: () => validateLoginChallengeTransition,
217
- validateSessionTransition: () => validateSessionTransition,
218
- validateTickAuthTransition: () => validateTickAuthTransition,
219
- validateTrustLinkTransition: () => validateTrustLinkTransition,
220
204
  varintLength: () => varintLength,
221
205
  varintU: () => varintU,
222
206
  verifyFrameSignature: () => verifyFrameSignature
@@ -235,20 +219,366 @@ function Handler(intent) {
235
219
 
236
220
  // src/decorators/intent.decorator.ts
237
221
  var import_reflect_metadata = require("reflect-metadata");
222
+ var INTENT_METADATA_KEY = "axis:intent";
238
223
  var INTENT_ROUTES_KEY = "axis:intent_routes";
239
224
  function Intent(action, options) {
240
225
  return (target, propertyKey) => {
226
+ Reflect.defineMetadata(
227
+ INTENT_METADATA_KEY,
228
+ { intent: action, ...options },
229
+ target,
230
+ propertyKey
231
+ );
241
232
  const routes = Reflect.getMetadata(INTENT_ROUTES_KEY, target.constructor) || [];
242
233
  routes.push({
243
234
  action,
244
235
  methodName: propertyKey,
245
236
  absolute: options?.absolute,
246
- frame: options?.frame
237
+ frame: options?.frame,
238
+ kind: options?.kind,
239
+ bodyProfile: options?.bodyProfile,
240
+ tlv: options?.tlv,
241
+ dto: options?.dto
247
242
  });
248
243
  Reflect.defineMetadata(INTENT_ROUTES_KEY, routes, target.constructor);
249
244
  };
250
245
  }
251
246
 
247
+ // src/decorators/tlv-field.decorator.ts
248
+ var import_reflect_metadata2 = require("reflect-metadata");
249
+ var TLV_FIELDS_KEY = "axis:tlv:fields";
250
+ var TLV_VALIDATORS_KEY = "axis:tlv:validators";
251
+ function TlvField(tag, options) {
252
+ return (target, propertyKey) => {
253
+ const existing = Reflect.getOwnMetadata(TLV_FIELDS_KEY, target.constructor) || [];
254
+ existing.push({
255
+ property: String(propertyKey),
256
+ tag,
257
+ options
258
+ });
259
+ Reflect.defineMetadata(TLV_FIELDS_KEY, existing, target.constructor);
260
+ };
261
+ }
262
+ function TlvValidate(validator) {
263
+ return (target, propertyKey) => {
264
+ const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
265
+ const prop = String(propertyKey);
266
+ let entry = existing.find((e) => e.property === prop);
267
+ if (!entry) {
268
+ entry = { property: prop, tag: 0, validators: [] };
269
+ existing.push(entry);
270
+ }
271
+ entry.validators.push(validator);
272
+ Reflect.defineMetadata(TLV_VALIDATORS_KEY, existing, target.constructor);
273
+ };
274
+ }
275
+ function TlvUtf8Pattern(pattern, message) {
276
+ return TlvValidate((val, prop) => {
277
+ const str = new TextDecoder().decode(val);
278
+ return pattern.test(str) ? null : message || `${prop}: failed pattern check`;
279
+ });
280
+ }
281
+ function TlvMinLen(min, message) {
282
+ return TlvValidate((val, prop) => {
283
+ return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
284
+ });
285
+ }
286
+ function TlvEnum(allowed, message) {
287
+ const set = new Set(allowed);
288
+ return TlvValidate((val, prop) => {
289
+ const str = new TextDecoder().decode(val);
290
+ return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
291
+ });
292
+ }
293
+ function TlvRange(min, max, message) {
294
+ return TlvValidate((val, prop) => {
295
+ if (val.length !== 8) return `${prop}: u64 must be 8 bytes`;
296
+ let n = 0n;
297
+ for (const b of val) n = n << 8n | BigInt(b);
298
+ if (n < min || n > max) {
299
+ return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
300
+ }
301
+ return null;
302
+ });
303
+ }
304
+
305
+ // src/decorators/dto-schema.util.ts
306
+ var import_reflect_metadata3 = require("reflect-metadata");
307
+
308
+ // src/core/varint.ts
309
+ function encodeVarint(value) {
310
+ if (value < 0) throw new Error("Varint must be unsigned");
311
+ const bytes2 = [];
312
+ while (true) {
313
+ const byte = value & 127;
314
+ value >>>= 7;
315
+ if (value === 0) {
316
+ bytes2.push(byte);
317
+ break;
318
+ }
319
+ bytes2.push(byte | 128);
320
+ }
321
+ return new Uint8Array(bytes2);
322
+ }
323
+ function decodeVarint(buf, offset = 0) {
324
+ let value = 0;
325
+ let shift = 0;
326
+ let length = 0;
327
+ while (true) {
328
+ if (offset + length >= buf.length) {
329
+ throw new Error("Varint decode out of bounds");
330
+ }
331
+ const byte = buf[offset + length];
332
+ value += (byte & 127) * Math.pow(2, shift);
333
+ length++;
334
+ shift += 7;
335
+ if ((byte & 128) === 0) {
336
+ break;
337
+ }
338
+ if (length > 8) throw new Error("Varint too large");
339
+ }
340
+ return { value, length };
341
+ }
342
+ function varintLength(value) {
343
+ if (value < 0) throw new Error("Varint must be unsigned");
344
+ let len = 0;
345
+ do {
346
+ value >>>= 7;
347
+ len++;
348
+ } while (value !== 0);
349
+ return len;
350
+ }
351
+
352
+ // src/core/tlv.ts
353
+ function encodeTLVs(tlvs) {
354
+ const sorted = [...tlvs].sort((a, b) => a.type - b.type);
355
+ for (let i = 0; i < sorted.length - 1; i++) {
356
+ if (sorted[i].type === sorted[i + 1].type) {
357
+ throw new Error(`Duplicate TLV type: ${sorted[i].type}`);
358
+ }
359
+ }
360
+ let totalSize = 0;
361
+ for (const t of sorted) {
362
+ totalSize += varintLength(t.type);
363
+ totalSize += varintLength(t.value.length);
364
+ totalSize += t.value.length;
365
+ }
366
+ const buf = new Uint8Array(totalSize);
367
+ let offset = 0;
368
+ for (const t of sorted) {
369
+ const typeBytes = encodeVarint(t.type);
370
+ buf.set(typeBytes, offset);
371
+ offset += typeBytes.length;
372
+ const lenBytes = encodeVarint(t.value.length);
373
+ buf.set(lenBytes, offset);
374
+ offset += lenBytes.length;
375
+ buf.set(t.value, offset);
376
+ offset += t.value.length;
377
+ }
378
+ return buf;
379
+ }
380
+ function decodeTLVsList(buf, maxItems = 1024) {
381
+ const list = [];
382
+ let offset = 0;
383
+ while (offset < buf.length) {
384
+ if (list.length >= maxItems) throw new Error("TLV_LIMIT");
385
+ const { value: type, length: typeLen } = decodeVarint(buf, offset);
386
+ offset += typeLen;
387
+ const { value: len, length: lenLen } = decodeVarint(buf, offset);
388
+ offset += lenLen;
389
+ if (offset + len > buf.length) {
390
+ throw new Error(`TLV violation: Length ${len} exceeds buffer`);
391
+ }
392
+ const value = buf.slice(offset, offset + len);
393
+ list.push({ type, value });
394
+ offset += len;
395
+ }
396
+ return list;
397
+ }
398
+ function decodeTLVs(buf) {
399
+ const map2 = /* @__PURE__ */ new Map();
400
+ let offset = 0;
401
+ let lastType = -1;
402
+ while (offset < buf.length) {
403
+ const { value: type, length: typeLen } = decodeVarint(buf, offset);
404
+ offset += typeLen;
405
+ if (type <= lastType) {
406
+ throw new Error(
407
+ `TLV violation: Unsorted or duplicate type ${type} after ${lastType}`
408
+ );
409
+ }
410
+ lastType = type;
411
+ const { value: len, length: lenLen } = decodeVarint(buf, offset);
412
+ offset += lenLen;
413
+ if (offset + len > buf.length) {
414
+ throw new Error(`TLV violation: Length ${len} exceeds buffer`);
415
+ }
416
+ const value = buf.slice(offset, offset + len);
417
+ map2.set(type, value);
418
+ offset += len;
419
+ }
420
+ return map2;
421
+ }
422
+ function decodeObject(bytes2, depth = 0, limits = { maxDepth: 8, maxItems: 128 }) {
423
+ if (depth > limits.maxDepth) {
424
+ throw new Error("OBJECT_DEPTH_EXCEEDED");
425
+ }
426
+ const map2 = decodeTLVs(bytes2);
427
+ return map2;
428
+ }
429
+ function decodeArray(bytes2, itemType, maxItems = 256) {
430
+ const list = decodeTLVsList(bytes2, maxItems);
431
+ const items = [];
432
+ for (const tlv2 of list) {
433
+ if (tlv2.type !== itemType) {
434
+ throw new Error(`INVALID_ARRAY_ITEM:${tlv2.type}`);
435
+ }
436
+ items.push(tlv2.value);
437
+ }
438
+ return items;
439
+ }
440
+
441
+ // src/decorators/dto-schema.util.ts
442
+ function extractDtoSchema(dto) {
443
+ const fieldMetas = Reflect.getOwnMetadata(TLV_FIELDS_KEY, dto) || [];
444
+ if (fieldMetas.length === 0) {
445
+ throw new Error(
446
+ `DTO class ${dto.name} has no @TlvField decorators \u2014 nothing to validate`
447
+ );
448
+ }
449
+ const tagByProp = /* @__PURE__ */ new Map();
450
+ const fields = fieldMetas.map((m) => {
451
+ tagByProp.set(m.property, m.tag);
452
+ return {
453
+ name: m.property,
454
+ tag: m.tag,
455
+ kind: m.options.kind,
456
+ required: m.options.required,
457
+ maxLen: m.options.maxLen,
458
+ max: m.options.max,
459
+ scope: m.options.scope
460
+ };
461
+ });
462
+ const validatorMetas = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, dto) || [];
463
+ const validators = /* @__PURE__ */ new Map();
464
+ for (const vm of validatorMetas) {
465
+ const tag = tagByProp.get(vm.property);
466
+ if (tag === void 0) {
467
+ throw new Error(
468
+ `@TlvValidate on ${dto.name}.${vm.property} but no @TlvField found for that property`
469
+ );
470
+ }
471
+ vm.tag = tag;
472
+ validators.set(tag, vm.validators);
473
+ }
474
+ return { fields, validators };
475
+ }
476
+ function buildDtoDecoder(dto) {
477
+ const fieldMetas = Reflect.getOwnMetadata(TLV_FIELDS_KEY, dto) || [];
478
+ if (fieldMetas.length === 0) {
479
+ throw new Error(
480
+ `DTO class ${dto.name} has no @TlvField decorators \u2014 cannot build decoder`
481
+ );
482
+ }
483
+ const tagMap = /* @__PURE__ */ new Map();
484
+ for (const m of fieldMetas) {
485
+ tagMap.set(m.tag, { property: m.property, kind: m.options.kind });
486
+ }
487
+ return (bodyBytes) => {
488
+ const tlvMap2 = decodeTLVs(new Uint8Array(bodyBytes));
489
+ const result = {};
490
+ for (const [tag, raw] of tlvMap2) {
491
+ const meta = tagMap.get(tag);
492
+ if (!meta) continue;
493
+ switch (meta.kind) {
494
+ case "utf8":
495
+ result[meta.property] = new TextDecoder().decode(raw);
496
+ break;
497
+ case "u64": {
498
+ let n = 0n;
499
+ for (let i = 0; i < raw.length; i++) {
500
+ n = n << 8n | BigInt(raw[i]);
501
+ }
502
+ result[meta.property] = n;
503
+ break;
504
+ }
505
+ case "bytes":
506
+ case "bytes16":
507
+ result[meta.property] = raw;
508
+ break;
509
+ case "bool":
510
+ result[meta.property] = raw.length > 0 && raw[0] !== 0;
511
+ break;
512
+ case "obj":
513
+ case "arr":
514
+ result[meta.property] = JSON.parse(new TextDecoder().decode(raw));
515
+ break;
516
+ default:
517
+ result[meta.property] = raw;
518
+ }
519
+ }
520
+ return result;
521
+ };
522
+ }
523
+
524
+ // src/base/axis-tlv.dto.ts
525
+ var AxisTlvDto = class {
526
+ };
527
+
528
+ // src/base/axis-id.dto.ts
529
+ var AxisIdDto = class extends AxisTlvDto {
530
+ };
531
+ __decorateClass([
532
+ TlvField(1, { kind: "utf8", required: true, maxLen: 128 }),
533
+ TlvMinLen(1, "id must not be empty")
534
+ ], AxisIdDto.prototype, "id", 2);
535
+
536
+ // src/base/axis-partial-type.ts
537
+ var import_reflect_metadata4 = require("reflect-metadata");
538
+ function AxisPartialType(BaseDto) {
539
+ class PartialDto extends BaseDto {
540
+ }
541
+ const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
542
+ const partialFields = fields.map((f) => ({
543
+ property: f.property,
544
+ tag: f.tag,
545
+ options: { ...f.options, required: false }
546
+ }));
547
+ Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
548
+ const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
549
+ if (validators.length > 0) {
550
+ Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
551
+ }
552
+ Object.defineProperty(PartialDto, "name", {
553
+ value: `Partial${BaseDto.name}`
554
+ });
555
+ return PartialDto;
556
+ }
557
+
558
+ // src/base/axis-response.dto.ts
559
+ var RESPONSE_TAG_ID = 1;
560
+ var RESPONSE_TAG_CREATED_AT = 2;
561
+ var RESPONSE_TAG_UPDATED_AT = 3;
562
+ var RESPONSE_TAG_CREATED_BY = 4;
563
+ var RESPONSE_TAG_UPDATED_BY = 5;
564
+ var AxisResponseDto = class extends AxisTlvDto {
565
+ };
566
+ __decorateClass([
567
+ TlvField(RESPONSE_TAG_ID, { kind: "utf8" })
568
+ ], AxisResponseDto.prototype, "id", 2);
569
+ __decorateClass([
570
+ TlvField(RESPONSE_TAG_CREATED_AT, { kind: "u64" })
571
+ ], AxisResponseDto.prototype, "created_at", 2);
572
+ __decorateClass([
573
+ TlvField(RESPONSE_TAG_UPDATED_AT, { kind: "u64" })
574
+ ], AxisResponseDto.prototype, "updated_at", 2);
575
+ __decorateClass([
576
+ TlvField(RESPONSE_TAG_CREATED_BY, { kind: "utf8" })
577
+ ], AxisResponseDto.prototype, "created_by", 2);
578
+ __decorateClass([
579
+ TlvField(RESPONSE_TAG_UPDATED_BY, { kind: "utf8" })
580
+ ], AxisResponseDto.prototype, "updated_by", 2);
581
+
252
582
  // src/engine/intent.router.ts
253
583
  var import_common2 = require("@nestjs/common");
254
584
  var IntentRouter = class {
@@ -489,139 +819,6 @@ var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
489
819
  var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
490
820
  var ERR_CONTRACT_VIOLATION = "CONTRACT_VIOLATION";
491
821
 
492
- // src/core/varint.ts
493
- function encodeVarint(value) {
494
- if (value < 0) throw new Error("Varint must be unsigned");
495
- const bytes2 = [];
496
- while (true) {
497
- const byte = value & 127;
498
- value >>>= 7;
499
- if (value === 0) {
500
- bytes2.push(byte);
501
- break;
502
- }
503
- bytes2.push(byte | 128);
504
- }
505
- return new Uint8Array(bytes2);
506
- }
507
- function decodeVarint(buf, offset = 0) {
508
- let value = 0;
509
- let shift = 0;
510
- let length = 0;
511
- while (true) {
512
- if (offset + length >= buf.length) {
513
- throw new Error("Varint decode out of bounds");
514
- }
515
- const byte = buf[offset + length];
516
- value += (byte & 127) * Math.pow(2, shift);
517
- length++;
518
- shift += 7;
519
- if ((byte & 128) === 0) {
520
- break;
521
- }
522
- if (length > 8) throw new Error("Varint too large");
523
- }
524
- return { value, length };
525
- }
526
- function varintLength(value) {
527
- if (value < 0) throw new Error("Varint must be unsigned");
528
- let len = 0;
529
- do {
530
- value >>>= 7;
531
- len++;
532
- } while (value !== 0);
533
- return len;
534
- }
535
-
536
- // src/core/tlv.ts
537
- function encodeTLVs(tlvs) {
538
- const sorted = [...tlvs].sort((a, b) => a.type - b.type);
539
- for (let i = 0; i < sorted.length - 1; i++) {
540
- if (sorted[i].type === sorted[i + 1].type) {
541
- throw new Error(`Duplicate TLV type: ${sorted[i].type}`);
542
- }
543
- }
544
- let totalSize = 0;
545
- for (const t of sorted) {
546
- totalSize += varintLength(t.type);
547
- totalSize += varintLength(t.value.length);
548
- totalSize += t.value.length;
549
- }
550
- const buf = new Uint8Array(totalSize);
551
- let offset = 0;
552
- for (const t of sorted) {
553
- const typeBytes = encodeVarint(t.type);
554
- buf.set(typeBytes, offset);
555
- offset += typeBytes.length;
556
- const lenBytes = encodeVarint(t.value.length);
557
- buf.set(lenBytes, offset);
558
- offset += lenBytes.length;
559
- buf.set(t.value, offset);
560
- offset += t.value.length;
561
- }
562
- return buf;
563
- }
564
- function decodeTLVsList(buf, maxItems = 1024) {
565
- const list = [];
566
- let offset = 0;
567
- while (offset < buf.length) {
568
- if (list.length >= maxItems) throw new Error("TLV_LIMIT");
569
- const { value: type, length: typeLen } = decodeVarint(buf, offset);
570
- offset += typeLen;
571
- const { value: len, length: lenLen } = decodeVarint(buf, offset);
572
- offset += lenLen;
573
- if (offset + len > buf.length) {
574
- throw new Error(`TLV violation: Length ${len} exceeds buffer`);
575
- }
576
- const value = buf.slice(offset, offset + len);
577
- list.push({ type, value });
578
- offset += len;
579
- }
580
- return list;
581
- }
582
- function decodeTLVs(buf) {
583
- const map2 = /* @__PURE__ */ new Map();
584
- let offset = 0;
585
- let lastType = -1;
586
- while (offset < buf.length) {
587
- const { value: type, length: typeLen } = decodeVarint(buf, offset);
588
- offset += typeLen;
589
- if (type <= lastType) {
590
- throw new Error(
591
- `TLV violation: Unsorted or duplicate type ${type} after ${lastType}`
592
- );
593
- }
594
- lastType = type;
595
- const { value: len, length: lenLen } = decodeVarint(buf, offset);
596
- offset += lenLen;
597
- if (offset + len > buf.length) {
598
- throw new Error(`TLV violation: Length ${len} exceeds buffer`);
599
- }
600
- const value = buf.slice(offset, offset + len);
601
- map2.set(type, value);
602
- offset += len;
603
- }
604
- return map2;
605
- }
606
- function decodeObject(bytes2, depth = 0, limits = { maxDepth: 8, maxItems: 128 }) {
607
- if (depth > limits.maxDepth) {
608
- throw new Error("OBJECT_DEPTH_EXCEEDED");
609
- }
610
- const map2 = decodeTLVs(bytes2);
611
- return map2;
612
- }
613
- function decodeArray(bytes2, itemType, maxItems = 256) {
614
- const list = decodeTLVsList(bytes2, maxItems);
615
- const items = [];
616
- for (const tlv2 of list) {
617
- if (tlv2.type !== itemType) {
618
- throw new Error(`INVALID_ARRAY_ITEM:${tlv2.type}`);
619
- }
620
- items.push(tlv2.value);
621
- }
622
- return items;
623
- }
624
-
625
822
  // src/core/signature.ts
626
823
  var crypto = __toESM(require("crypto"));
627
824
 
@@ -1572,10 +1769,10 @@ function tlv(type, value) {
1572
1769
  ]);
1573
1770
  }
1574
1771
  function buildTLVs(items, opts) {
1575
- const allow2 = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1772
+ const allow = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1576
1773
  const sorted = [...items].sort((a, b) => a.type - b.type);
1577
1774
  for (let i = 1; i < sorted.length; i++) {
1578
- if (sorted[i].type === sorted[i - 1].type && !allow2.has(sorted[i].type)) {
1775
+ if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {
1579
1776
  throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);
1580
1777
  }
1581
1778
  }
@@ -2385,425 +2582,6 @@ function isTimestampValid(ts, skewSeconds = 120) {
2385
2582
  const diff = Math.abs(now - ts);
2386
2583
  return diff <= skewSeconds;
2387
2584
  }
2388
-
2389
- // src/nestflow/types.ts
2390
- var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
2391
- DeviceType2["MOBILE"] = "mobile";
2392
- DeviceType2["BROWSER"] = "browser";
2393
- DeviceType2["CLI"] = "cli";
2394
- DeviceType2["SERVICE"] = "service";
2395
- return DeviceType2;
2396
- })(DeviceType || {});
2397
- var DeviceTrustLevel = /* @__PURE__ */ ((DeviceTrustLevel2) => {
2398
- DeviceTrustLevel2["PRIMARY"] = "primary";
2399
- DeviceTrustLevel2["TRUSTED"] = "trusted";
2400
- DeviceTrustLevel2["EPHEMERAL"] = "ephemeral";
2401
- return DeviceTrustLevel2;
2402
- })(DeviceTrustLevel || {});
2403
- var DeviceStatus = /* @__PURE__ */ ((DeviceStatus2) => {
2404
- DeviceStatus2["ACTIVE"] = "active";
2405
- DeviceStatus2["REVOKED"] = "revoked";
2406
- DeviceStatus2["SUSPENDED"] = "suspended";
2407
- return DeviceStatus2;
2408
- })(DeviceStatus || {});
2409
- var LoginChallengeStatus = /* @__PURE__ */ ((LoginChallengeStatus3) => {
2410
- LoginChallengeStatus3["PENDING"] = "pending";
2411
- LoginChallengeStatus3["SCANNED"] = "scanned";
2412
- LoginChallengeStatus3["APPROVED"] = "approved";
2413
- LoginChallengeStatus3["REJECTED"] = "rejected";
2414
- LoginChallengeStatus3["EXPIRED"] = "expired";
2415
- return LoginChallengeStatus3;
2416
- })(LoginChallengeStatus || {});
2417
- var TickAuthChallengeStatus = /* @__PURE__ */ ((TickAuthChallengeStatus2) => {
2418
- TickAuthChallengeStatus2["PENDING"] = "pending";
2419
- TickAuthChallengeStatus2["FULFILLED"] = "fulfilled";
2420
- TickAuthChallengeStatus2["REJECTED"] = "rejected";
2421
- TickAuthChallengeStatus2["EXPIRED"] = "expired";
2422
- return TickAuthChallengeStatus2;
2423
- })(TickAuthChallengeStatus || {});
2424
- var NestFlowCapsuleType = /* @__PURE__ */ ((NestFlowCapsuleType2) => {
2425
- NestFlowCapsuleType2["LOGIN"] = "login";
2426
- NestFlowCapsuleType2["DEVICE_REGISTRATION"] = "device_registration";
2427
- NestFlowCapsuleType2["STEP_UP"] = "step_up";
2428
- NestFlowCapsuleType2["RECOVERY"] = "recovery";
2429
- return NestFlowCapsuleType2;
2430
- })(NestFlowCapsuleType || {});
2431
- var CapsuleStatus = /* @__PURE__ */ ((CapsuleStatus2) => {
2432
- CapsuleStatus2["ACTIVE"] = "active";
2433
- CapsuleStatus2["CONSUMED"] = "consumed";
2434
- CapsuleStatus2["REVOKED"] = "revoked";
2435
- CapsuleStatus2["EXPIRED"] = "expired";
2436
- return CapsuleStatus2;
2437
- })(CapsuleStatus || {});
2438
- var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
2439
- SessionStatus2["ACTIVE"] = "active";
2440
- SessionStatus2["EXPIRED"] = "expired";
2441
- SessionStatus2["REVOKED"] = "revoked";
2442
- return SessionStatus2;
2443
- })(SessionStatus || {});
2444
- var TrustLinkType = /* @__PURE__ */ ((TrustLinkType2) => {
2445
- TrustLinkType2["LOGIN"] = "login";
2446
- TrustLinkType2["PROMOTION"] = "promotion";
2447
- TrustLinkType2["RECOVERY"] = "recovery";
2448
- return TrustLinkType2;
2449
- })(TrustLinkType || {});
2450
- var TrustLinkStatus = /* @__PURE__ */ ((TrustLinkStatus2) => {
2451
- TrustLinkStatus2["ACTIVE"] = "active";
2452
- TrustLinkStatus2["REVOKED"] = "revoked";
2453
- return TrustLinkStatus2;
2454
- })(TrustLinkStatus || {});
2455
- var AuthLevel = /* @__PURE__ */ ((AuthLevel2) => {
2456
- AuthLevel2["SESSION"] = "session";
2457
- AuthLevel2["SESSION_BROWSER"] = "session_browser";
2458
- AuthLevel2["STEP_UP"] = "step_up";
2459
- AuthLevel2["PRIMARY_DEVICE"] = "primary_device";
2460
- return AuthLevel2;
2461
- })(AuthLevel || {});
2462
-
2463
- // src/nestflow/intents.ts
2464
- var NESTFLOW_INTENTS = {
2465
- // Auth
2466
- AUTH_WEB_LOGIN_REQUEST: "auth.web.login.request",
2467
- AUTH_WEB_LOGIN_SCAN: "auth.web.login.scan",
2468
- // TickAuth
2469
- TICKAUTH_CHALLENGE_CREATE: "tickauth.challenge.create",
2470
- TICKAUTH_CHALLENGE_FULFILL: "tickauth.challenge.fulfill",
2471
- TICKAUTH_CHALLENGE_REJECT: "tickauth.challenge.reject",
2472
- // Capsule
2473
- CAPSULE_ISSUE_LOGIN: "capsule.issue.login",
2474
- CAPSULE_ISSUE_DEVICE_REGISTRATION: "capsule.issue.device_registration",
2475
- CAPSULE_ISSUE_STEP_UP: "capsule.issue.step_up",
2476
- CAPSULE_ISSUE_RECOVERY: "capsule.issue.recovery",
2477
- // Session
2478
- SESSION_ACTIVATE: "session.activate",
2479
- SESSION_REFRESH: "session.refresh",
2480
- SESSION_LOGOUT: "session.logout",
2481
- // Device Trust
2482
- DEVICE_TRUST_REQUEST: "device.trust.request",
2483
- DEVICE_TRUST_PROMOTE: "device.trust.promote",
2484
- DEVICE_REVOKE: "device.revoke",
2485
- DEVICE_LIST: "device.list",
2486
- DEVICE_RENAME: "device.rename",
2487
- // Protected Operations
2488
- FLOW_PUBLISH: "flow.publish",
2489
- FLOW_DELETE: "flow.delete",
2490
- NODE_DELETE: "node.delete",
2491
- SECRET_ROTATE: "secret.rotate",
2492
- ORG_SECURITY_UPDATE: "org.security.update",
2493
- PRODUCTION_EXECUTION_APPROVE: "production.execution.approve",
2494
- // Recovery
2495
- IDENTITY_RECOVERY_START: "identity.recovery.start",
2496
- IDENTITY_RECOVERY_COMPLETE: "identity.recovery.complete",
2497
- PRIMARY_DEVICE_ROTATE: "primary.device.rotate",
2498
- IDENTITY_LOCK: "identity.lock",
2499
- IDENTITY_UNLOCK: "identity.unlock"
2500
- };
2501
- var NESTFLOW_INTENT_SET = new Set(
2502
- Object.values(NESTFLOW_INTENTS)
2503
- );
2504
- function isNestFlowIntent(intent) {
2505
- return NESTFLOW_INTENT_SET.has(intent);
2506
- }
2507
-
2508
- // src/nestflow/policy-map.ts
2509
- var NESTFLOW_POLICY_MAP = {
2510
- // Auth — unauthenticated initiator (session issued after)
2511
- [NESTFLOW_INTENTS.AUTH_WEB_LOGIN_REQUEST]: "session" /* SESSION */,
2512
- [NESTFLOW_INTENTS.AUTH_WEB_LOGIN_SCAN]: "primary_device" /* PRIMARY_DEVICE */,
2513
- // TickAuth — primary device handles challenges
2514
- [NESTFLOW_INTENTS.TICKAUTH_CHALLENGE_CREATE]: "session" /* SESSION */,
2515
- [NESTFLOW_INTENTS.TICKAUTH_CHALLENGE_FULFILL]: "primary_device" /* PRIMARY_DEVICE */,
2516
- [NESTFLOW_INTENTS.TICKAUTH_CHALLENGE_REJECT]: "primary_device" /* PRIMARY_DEVICE */,
2517
- // Capsule issuance — varies per type
2518
- [NESTFLOW_INTENTS.CAPSULE_ISSUE_LOGIN]: "primary_device" /* PRIMARY_DEVICE */,
2519
- [NESTFLOW_INTENTS.CAPSULE_ISSUE_DEVICE_REGISTRATION]: "primary_device" /* PRIMARY_DEVICE */,
2520
- [NESTFLOW_INTENTS.CAPSULE_ISSUE_STEP_UP]: "primary_device" /* PRIMARY_DEVICE */,
2521
- [NESTFLOW_INTENTS.CAPSULE_ISSUE_RECOVERY]: "primary_device" /* PRIMARY_DEVICE */,
2522
- // Session management
2523
- [NESTFLOW_INTENTS.SESSION_ACTIVATE]: "session" /* SESSION */,
2524
- [NESTFLOW_INTENTS.SESSION_REFRESH]: "session_browser" /* SESSION_BROWSER */,
2525
- [NESTFLOW_INTENTS.SESSION_LOGOUT]: "session" /* SESSION */,
2526
- // Device trust management
2527
- [NESTFLOW_INTENTS.DEVICE_TRUST_REQUEST]: "session_browser" /* SESSION_BROWSER */,
2528
- [NESTFLOW_INTENTS.DEVICE_TRUST_PROMOTE]: "step_up" /* STEP_UP */,
2529
- [NESTFLOW_INTENTS.DEVICE_REVOKE]: "step_up" /* STEP_UP */,
2530
- [NESTFLOW_INTENTS.DEVICE_LIST]: "session" /* SESSION */,
2531
- [NESTFLOW_INTENTS.DEVICE_RENAME]: "session_browser" /* SESSION_BROWSER */,
2532
- // Protected operations — require step-up auth
2533
- [NESTFLOW_INTENTS.FLOW_PUBLISH]: "session_browser" /* SESSION_BROWSER */,
2534
- [NESTFLOW_INTENTS.FLOW_DELETE]: "step_up" /* STEP_UP */,
2535
- [NESTFLOW_INTENTS.NODE_DELETE]: "step_up" /* STEP_UP */,
2536
- [NESTFLOW_INTENTS.SECRET_ROTATE]: "step_up" /* STEP_UP */,
2537
- [NESTFLOW_INTENTS.ORG_SECURITY_UPDATE]: "step_up" /* STEP_UP */,
2538
- [NESTFLOW_INTENTS.PRODUCTION_EXECUTION_APPROVE]: "step_up" /* STEP_UP */,
2539
- // Recovery — highest privilege
2540
- [NESTFLOW_INTENTS.IDENTITY_RECOVERY_START]: "primary_device" /* PRIMARY_DEVICE */,
2541
- [NESTFLOW_INTENTS.IDENTITY_RECOVERY_COMPLETE]: "primary_device" /* PRIMARY_DEVICE */,
2542
- [NESTFLOW_INTENTS.PRIMARY_DEVICE_ROTATE]: "primary_device" /* PRIMARY_DEVICE */,
2543
- [NESTFLOW_INTENTS.IDENTITY_LOCK]: "primary_device" /* PRIMARY_DEVICE */,
2544
- [NESTFLOW_INTENTS.IDENTITY_UNLOCK]: "primary_device" /* PRIMARY_DEVICE */
2545
- };
2546
- function getRequiredAuthLevel(intent) {
2547
- return NESTFLOW_POLICY_MAP[intent];
2548
- }
2549
- var AUTH_LEVEL_ORDER = [
2550
- "session" /* SESSION */,
2551
- "session_browser" /* SESSION_BROWSER */,
2552
- "step_up" /* STEP_UP */,
2553
- "primary_device" /* PRIMARY_DEVICE */
2554
- ];
2555
- function satisfiesAuthLevel(provided, required) {
2556
- const providedIdx = AUTH_LEVEL_ORDER.indexOf(provided);
2557
- const requiredIdx = AUTH_LEVEL_ORDER.indexOf(required);
2558
- return providedIdx >= requiredIdx;
2559
- }
2560
-
2561
- // src/nestflow/guards.ts
2562
- var allow = () => ({ allowed: true });
2563
- var deny = (reason) => ({ allowed: false, reason });
2564
- function checkIntentPolicy(intent, currentAuthLevel) {
2565
- const required = getRequiredAuthLevel(intent);
2566
- if (!required) {
2567
- return allow();
2568
- }
2569
- if (satisfiesAuthLevel(currentAuthLevel, required)) {
2570
- return allow();
2571
- }
2572
- return {
2573
- allowed: false,
2574
- reason: `Intent '${intent}' requires auth level '${required}', got '${currentAuthLevel}'`,
2575
- step_up_intent: required === "step_up" /* STEP_UP */ ? intent : void 0
2576
- };
2577
- }
2578
- function checkSession(session) {
2579
- if (!session) {
2580
- return deny("No session found");
2581
- }
2582
- if (session.status !== "active" /* ACTIVE */) {
2583
- return deny(`Session status is '${session.status}', expected 'active'`);
2584
- }
2585
- if (new Date(session.expires_at).getTime() < Date.now()) {
2586
- return deny("Session has expired");
2587
- }
2588
- return allow();
2589
- }
2590
- function checkBrowserProof(proof, expectedNonce) {
2591
- if (!proof) {
2592
- return deny("Browser proof-of-possession required but not provided");
2593
- }
2594
- if (!proof.server_nonce || !proof.signature || !proof.signature_algorithm) {
2595
- return deny("Browser proof is missing required fields");
2596
- }
2597
- if (proof.server_nonce !== expectedNonce) {
2598
- return deny("Browser proof nonce does not match expected server nonce");
2599
- }
2600
- return allow();
2601
- }
2602
- var TRUST_ORDER = [
2603
- "ephemeral" /* EPHEMERAL */,
2604
- "trusted" /* TRUSTED */,
2605
- "primary" /* PRIMARY */
2606
- ];
2607
- function checkDeviceTrust(device, minimumTrust) {
2608
- if (!device) {
2609
- return deny("Device not found");
2610
- }
2611
- if (device.status !== "active" /* ACTIVE */) {
2612
- return deny(`Device status is '${device.status}', expected 'active'`);
2613
- }
2614
- const deviceIdx = TRUST_ORDER.indexOf(device.trust_level);
2615
- const requiredIdx = TRUST_ORDER.indexOf(minimumTrust);
2616
- if (deviceIdx < requiredIdx) {
2617
- return deny(
2618
- `Device trust level '${device.trust_level}' does not meet minimum '${minimumTrust}'`
2619
- );
2620
- }
2621
- return allow();
2622
- }
2623
- function checkCapsule(capsule, intent, requestingDeviceUid) {
2624
- if (!capsule) {
2625
- return deny("Capsule not found");
2626
- }
2627
- if (capsule.status !== "active" /* ACTIVE */) {
2628
- return deny(`Capsule status is '${capsule.status}', expected 'active'`);
2629
- }
2630
- if (new Date(capsule.expires_at).getTime() < Date.now()) {
2631
- return deny("Capsule has expired");
2632
- }
2633
- const intentAllowed = capsule.intents.some((pattern) => {
2634
- if (pattern === "*") return true;
2635
- if (pattern === intent) return true;
2636
- if (pattern.endsWith(".*")) {
2637
- return intent.startsWith(pattern.slice(0, -1));
2638
- }
2639
- return false;
2640
- });
2641
- if (!intentAllowed) {
2642
- return deny(`Capsule does not authorize intent '${intent}'`);
2643
- }
2644
- if (capsule.device_uid && requestingDeviceUid && capsule.device_uid !== requestingDeviceUid) {
2645
- return deny("Capsule is bound to a different device");
2646
- }
2647
- return allow();
2648
- }
2649
- function checkLoginChallenge(challenge, expectedStatus) {
2650
- if (!challenge) {
2651
- return deny("Login challenge not found");
2652
- }
2653
- if (new Date(challenge.expires_at).getTime() < Date.now()) {
2654
- return deny("Login challenge has expired");
2655
- }
2656
- if (challenge.status !== expectedStatus) {
2657
- return deny(
2658
- `Login challenge status is '${challenge.status}', expected '${expectedStatus}'`
2659
- );
2660
- }
2661
- return allow();
2662
- }
2663
- function checkTickAuth(challenge) {
2664
- if (!challenge) {
2665
- return deny("TickAuth challenge not found");
2666
- }
2667
- if (challenge.status !== "pending" /* PENDING */) {
2668
- return deny(
2669
- `TickAuth challenge status is '${challenge.status}', expected 'pending'`
2670
- );
2671
- }
2672
- const now = Date.now();
2673
- const start = new Date(challenge.tick_window.start).getTime();
2674
- const end = new Date(challenge.tick_window.end).getTime();
2675
- if (now < start || now > end) {
2676
- return deny("TickAuth challenge is outside its tick window");
2677
- }
2678
- return allow();
2679
- }
2680
- async function checkReplayProtection(nonce, store, windowMs = 5 * 60 * 1e3) {
2681
- if (!nonce) {
2682
- return deny("Nonce is required for replay protection");
2683
- }
2684
- const seen = await store.has(nonce);
2685
- if (seen) {
2686
- return deny("Nonce has already been used (replay detected)");
2687
- }
2688
- await store.add(nonce, new Date(Date.now() + windowMs));
2689
- return allow();
2690
- }
2691
-
2692
- // src/nestflow/invariants.ts
2693
- var LOGIN_CHALLENGE_TRANSITIONS = {
2694
- ["pending" /* PENDING */]: [
2695
- "scanned" /* SCANNED */,
2696
- "expired" /* EXPIRED */
2697
- ],
2698
- ["scanned" /* SCANNED */]: [
2699
- "approved" /* APPROVED */,
2700
- "rejected" /* REJECTED */,
2701
- "expired" /* EXPIRED */
2702
- ],
2703
- ["approved" /* APPROVED */]: [],
2704
- ["rejected" /* REJECTED */]: [],
2705
- ["expired" /* EXPIRED */]: []
2706
- };
2707
- var TICKAUTH_TRANSITIONS = {
2708
- ["pending" /* PENDING */]: [
2709
- "fulfilled" /* FULFILLED */,
2710
- "rejected" /* REJECTED */,
2711
- "expired" /* EXPIRED */
2712
- ],
2713
- ["fulfilled" /* FULFILLED */]: [],
2714
- ["rejected" /* REJECTED */]: [],
2715
- ["expired" /* EXPIRED */]: []
2716
- };
2717
- var CAPSULE_TRANSITIONS = {
2718
- ["active" /* ACTIVE */]: [
2719
- "consumed" /* CONSUMED */,
2720
- "revoked" /* REVOKED */,
2721
- "expired" /* EXPIRED */
2722
- ],
2723
- ["consumed" /* CONSUMED */]: [],
2724
- ["revoked" /* REVOKED */]: [],
2725
- ["expired" /* EXPIRED */]: []
2726
- };
2727
- var SESSION_TRANSITIONS = {
2728
- ["active" /* ACTIVE */]: ["expired" /* EXPIRED */, "revoked" /* REVOKED */],
2729
- ["expired" /* EXPIRED */]: [],
2730
- ["revoked" /* REVOKED */]: []
2731
- };
2732
- var DEVICE_TRANSITIONS = {
2733
- ["active" /* ACTIVE */]: ["suspended" /* SUSPENDED */, "revoked" /* REVOKED */],
2734
- ["suspended" /* SUSPENDED */]: ["active" /* ACTIVE */, "revoked" /* REVOKED */],
2735
- ["revoked" /* REVOKED */]: []
2736
- };
2737
- var TRUST_LINK_TRANSITIONS = {
2738
- ["active" /* ACTIVE */]: ["revoked" /* REVOKED */],
2739
- ["revoked" /* REVOKED */]: []
2740
- };
2741
- function checkTransition(entity, transitions, from, to) {
2742
- const allowed = transitions[from];
2743
- if (!allowed) {
2744
- return {
2745
- valid: false,
2746
- reason: `${entity}: unknown current state '${from}'`
2747
- };
2748
- }
2749
- if (!allowed.includes(to)) {
2750
- return {
2751
- valid: false,
2752
- reason: `${entity}: invalid transition '${from}' \u2192 '${to}'. Allowed: [${allowed.join(", ")}]`
2753
- };
2754
- }
2755
- return { valid: true };
2756
- }
2757
- function validateLoginChallengeTransition(from, to) {
2758
- return checkTransition(
2759
- "LoginChallenge",
2760
- LOGIN_CHALLENGE_TRANSITIONS,
2761
- from,
2762
- to
2763
- );
2764
- }
2765
- function validateTickAuthTransition(from, to) {
2766
- return checkTransition("TickAuthChallenge", TICKAUTH_TRANSITIONS, from, to);
2767
- }
2768
- function validateCapsuleTransition(from, to) {
2769
- return checkTransition("Capsule", CAPSULE_TRANSITIONS, from, to);
2770
- }
2771
- function validateSessionTransition(from, to) {
2772
- return checkTransition("Session", SESSION_TRANSITIONS, from, to);
2773
- }
2774
- function validateDeviceTransition(from, to) {
2775
- return checkTransition("Device", DEVICE_TRANSITIONS, from, to);
2776
- }
2777
- function validateTrustLinkTransition(from, to) {
2778
- return checkTransition("TrustLink", TRUST_LINK_TRANSITIONS, from, to);
2779
- }
2780
- function isLoginChallengeTerminal(status) {
2781
- return [
2782
- "approved" /* APPROVED */,
2783
- "rejected" /* REJECTED */,
2784
- "expired" /* EXPIRED */
2785
- ].includes(status);
2786
- }
2787
- function isTickAuthTerminal(status) {
2788
- return [
2789
- "fulfilled" /* FULFILLED */,
2790
- "rejected" /* REJECTED */,
2791
- "expired" /* EXPIRED */
2792
- ].includes(status);
2793
- }
2794
- function isCapsuleTerminal(status) {
2795
- return [
2796
- "consumed" /* CONSUMED */,
2797
- "revoked" /* REVOKED */,
2798
- "expired" /* EXPIRED */
2799
- ].includes(status);
2800
- }
2801
- function isSessionTerminal(status) {
2802
- return ["expired" /* EXPIRED */, "revoked" /* REVOKED */].includes(status);
2803
- }
2804
- function isDeviceTerminal(status) {
2805
- return status === "revoked" /* REVOKED */;
2806
- }
2807
2585
  // Annotate the CommonJS export names for ESM import in node:
2808
2586
  0 && (module.exports = {
2809
2587
  ATS1_HDR,
@@ -2812,19 +2590,18 @@ function isDeviceTerminal(status) {
2812
2590
  AXIS_OPCODES,
2813
2591
  AXIS_VERSION,
2814
2592
  Ats1Codec,
2815
- AuthLevel,
2816
2593
  AxisFrameZ,
2594
+ AxisIdDto,
2817
2595
  AxisPacketTags,
2596
+ AxisPartialType,
2597
+ AxisResponseDto,
2598
+ AxisTlvDto,
2818
2599
  BodyProfile,
2819
2600
  CAPABILITIES,
2820
- CapsuleStatus,
2821
2601
  ContractViolationError,
2822
2602
  DEFAULT_CONTRACTS,
2823
2603
  DEFAULT_TIMEOUT,
2824
2604
  Decision,
2825
- DeviceStatus,
2826
- DeviceTrustLevel,
2827
- DeviceType,
2828
2605
  ERR_BAD_SIGNATURE,
2829
2606
  ERR_CONTRACT_VIOLATION,
2830
2607
  ERR_INVALID_PACKET,
@@ -2836,6 +2613,7 @@ function isDeviceTerminal(status) {
2836
2613
  FLAG_HAS_WITNESS,
2837
2614
  HANDLER_METADATA_KEY,
2838
2615
  Handler,
2616
+ INTENT_METADATA_KEY,
2839
2617
  INTENT_REQUIREMENTS,
2840
2618
  INTENT_ROUTES_KEY,
2841
2619
  INTENT_SENSITIVITY_MAP,
@@ -2843,7 +2621,6 @@ function isDeviceTerminal(status) {
2843
2621
  Intent,
2844
2622
  IntentRouter,
2845
2623
  IntentSensitivity,
2846
- LoginChallengeStatus,
2847
2624
  MAX_BODY_LEN,
2848
2625
  MAX_FRAME_LEN,
2849
2626
  MAX_HDR_LEN,
@@ -2858,10 +2635,6 @@ function isDeviceTerminal(status) {
2858
2635
  NCERT_PUB,
2859
2636
  NCERT_SCOPE,
2860
2637
  NCERT_SIG,
2861
- NESTFLOW_INTENTS,
2862
- NESTFLOW_INTENT_SET,
2863
- NESTFLOW_POLICY_MAP,
2864
- NestFlowCapsuleType,
2865
2638
  PROOF_CAPABILITIES,
2866
2639
  PROOF_CAPSULE,
2867
2640
  PROOF_JWT,
@@ -2870,13 +2643,17 @@ function isDeviceTerminal(status) {
2870
2643
  PROOF_NONE,
2871
2644
  PROOF_WITNESS,
2872
2645
  ProofType,
2646
+ RESPONSE_TAG_CREATED_AT,
2647
+ RESPONSE_TAG_CREATED_BY,
2648
+ RESPONSE_TAG_ID,
2649
+ RESPONSE_TAG_UPDATED_AT,
2650
+ RESPONSE_TAG_UPDATED_BY,
2873
2651
  RiskDecision,
2874
2652
  Schema2002_PasskeyLoginOptionsRes,
2875
2653
  Schema2011_PasskeyLoginVerifyReq,
2876
2654
  Schema2012_PasskeyLoginVerifyRes,
2877
2655
  Schema2021_PasskeyRegisterOptionsReq,
2878
2656
  SensorDecisions,
2879
- SessionStatus,
2880
2657
  TLV_ACTOR_ID,
2881
2658
  TLV_AUD,
2882
2659
  TLV_BODY_ARR,
@@ -2885,6 +2662,7 @@ function isDeviceTerminal(status) {
2885
2662
  TLV_EFFECT,
2886
2663
  TLV_ERROR_CODE,
2887
2664
  TLV_ERROR_MSG,
2665
+ TLV_FIELDS_KEY,
2888
2666
  TLV_INDEX,
2889
2667
  TLV_INTENT,
2890
2668
  TLV_KID,
@@ -2908,15 +2686,20 @@ function isDeviceTerminal(status) {
2908
2686
  TLV_TRACE_ID,
2909
2687
  TLV_TS,
2910
2688
  TLV_UPLOAD_ID,
2911
- TickAuthChallengeStatus,
2912
- TrustLinkStatus,
2913
- TrustLinkType,
2689
+ TLV_VALIDATORS_KEY,
2690
+ TlvEnum,
2691
+ TlvField,
2692
+ TlvMinLen,
2693
+ TlvRange,
2694
+ TlvUtf8Pattern,
2695
+ TlvValidate,
2914
2696
  axis1SigningBytes,
2915
2697
  b64urlDecode,
2916
2698
  b64urlDecodeString,
2917
2699
  b64urlEncode,
2918
2700
  b64urlEncodeString,
2919
2701
  buildAts1Hdr,
2702
+ buildDtoDecoder,
2920
2703
  buildPacket,
2921
2704
  buildReceiptHash,
2922
2705
  buildTLVs,
@@ -2924,14 +2707,6 @@ function isDeviceTerminal(status) {
2924
2707
  canAccessResource,
2925
2708
  canonicalJson,
2926
2709
  canonicalJsonExcluding,
2927
- checkBrowserProof,
2928
- checkCapsule,
2929
- checkDeviceTrust,
2930
- checkIntentPolicy,
2931
- checkLoginChallenge,
2932
- checkReplayProtection,
2933
- checkSession,
2934
- checkTickAuth,
2935
2710
  classifyIntent,
2936
2711
  computeReceiptHash,
2937
2712
  computeSignaturePayload,
@@ -2947,18 +2722,12 @@ function isDeviceTerminal(status) {
2947
2722
  encodeFrame,
2948
2723
  encodeTLVs,
2949
2724
  encodeVarint,
2725
+ extractDtoSchema,
2950
2726
  generateEd25519KeyPair,
2951
- getRequiredAuthLevel,
2952
2727
  getSignTarget,
2953
2728
  hasScope,
2954
2729
  isAdminOpcode,
2955
- isCapsuleTerminal,
2956
- isDeviceTerminal,
2957
2730
  isKnownOpcode,
2958
- isLoginChallengeTerminal,
2959
- isNestFlowIntent,
2960
- isSessionTerminal,
2961
- isTickAuthTerminal,
2962
2731
  isTimestampValid,
2963
2732
  nonce16,
2964
2733
  normalizeSensorDecision,
@@ -2969,7 +2738,6 @@ function isDeviceTerminal(status) {
2969
2738
  packPasskeyRegisterOptionsReq,
2970
2739
  parseScope,
2971
2740
  resolveTimeout,
2972
- satisfiesAuthLevel,
2973
2741
  sensitivityName,
2974
2742
  sha256,
2975
2743
  signFrame,
@@ -2979,13 +2747,7 @@ function isDeviceTerminal(status) {
2979
2747
  unpackPasskeyLoginVerifyReq,
2980
2748
  unpackPasskeyRegisterOptionsReq,
2981
2749
  utf8,
2982
- validateCapsuleTransition,
2983
- validateDeviceTransition,
2984
2750
  validateFrameShape,
2985
- validateLoginChallengeTransition,
2986
- validateSessionTransition,
2987
- validateTickAuthTransition,
2988
- validateTrustLinkTransition,
2989
2751
  varintLength,
2990
2752
  varintU,
2991
2753
  verifyFrameSignature