@nextera.one/axis-server-sdk 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -43,14 +43,19 @@ __export(index_exports, {
43
43
  AXIS_OPCODES: () => AXIS_OPCODES,
44
44
  AXIS_VERSION: () => AXIS_VERSION,
45
45
  Ats1Codec: () => ats1_exports,
46
+ AuthLevel: () => AuthLevel,
46
47
  AxisFrameZ: () => AxisFrameZ,
47
48
  AxisPacketTags: () => T,
48
49
  BodyProfile: () => BodyProfile,
49
50
  CAPABILITIES: () => CAPABILITIES,
51
+ CapsuleStatus: () => CapsuleStatus,
50
52
  ContractViolationError: () => ContractViolationError,
51
53
  DEFAULT_CONTRACTS: () => DEFAULT_CONTRACTS,
52
54
  DEFAULT_TIMEOUT: () => DEFAULT_TIMEOUT,
53
55
  Decision: () => Decision,
56
+ DeviceStatus: () => DeviceStatus,
57
+ DeviceTrustLevel: () => DeviceTrustLevel,
58
+ DeviceType: () => DeviceType,
54
59
  ERR_BAD_SIGNATURE: () => ERR_BAD_SIGNATURE,
55
60
  ERR_CONTRACT_VIOLATION: () => ERR_CONTRACT_VIOLATION,
56
61
  ERR_INVALID_PACKET: () => ERR_INVALID_PACKET,
@@ -69,6 +74,7 @@ __export(index_exports, {
69
74
  Intent: () => Intent,
70
75
  IntentRouter: () => IntentRouter,
71
76
  IntentSensitivity: () => IntentSensitivity,
77
+ LoginChallengeStatus: () => LoginChallengeStatus,
72
78
  MAX_BODY_LEN: () => MAX_BODY_LEN,
73
79
  MAX_FRAME_LEN: () => MAX_FRAME_LEN,
74
80
  MAX_HDR_LEN: () => MAX_HDR_LEN,
@@ -83,6 +89,10 @@ __export(index_exports, {
83
89
  NCERT_PUB: () => NCERT_PUB,
84
90
  NCERT_SCOPE: () => NCERT_SCOPE,
85
91
  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,
86
96
  PROOF_CAPABILITIES: () => PROOF_CAPABILITIES,
87
97
  PROOF_CAPSULE: () => PROOF_CAPSULE,
88
98
  PROOF_JWT: () => PROOF_JWT,
@@ -97,6 +107,7 @@ __export(index_exports, {
97
107
  Schema2012_PasskeyLoginVerifyRes: () => Schema2012_PasskeyLoginVerifyRes,
98
108
  Schema2021_PasskeyRegisterOptionsReq: () => Schema2021_PasskeyRegisterOptionsReq,
99
109
  SensorDecisions: () => SensorDecisions,
110
+ SessionStatus: () => SessionStatus,
100
111
  TLV_ACTOR_ID: () => TLV_ACTOR_ID,
101
112
  TLV_AUD: () => TLV_AUD,
102
113
  TLV_BODY_ARR: () => TLV_BODY_ARR,
@@ -128,6 +139,9 @@ __export(index_exports, {
128
139
  TLV_TRACE_ID: () => TLV_TRACE_ID,
129
140
  TLV_TS: () => TLV_TS,
130
141
  TLV_UPLOAD_ID: () => TLV_UPLOAD_ID,
142
+ TickAuthChallengeStatus: () => TickAuthChallengeStatus,
143
+ TrustLinkStatus: () => TrustLinkStatus,
144
+ TrustLinkType: () => TrustLinkType,
131
145
  axis1SigningBytes: () => axis1SigningBytes,
132
146
  b64urlDecode: () => b64urlDecode,
133
147
  b64urlDecodeString: () => b64urlDecodeString,
@@ -141,6 +155,14 @@ __export(index_exports, {
141
155
  canAccessResource: () => canAccessResource,
142
156
  canonicalJson: () => canonicalJson,
143
157
  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,
144
166
  classifyIntent: () => classifyIntent,
145
167
  computeReceiptHash: () => computeReceiptHash,
146
168
  computeSignaturePayload: () => computeSignaturePayload,
@@ -157,10 +179,17 @@ __export(index_exports, {
157
179
  encodeTLVs: () => encodeTLVs,
158
180
  encodeVarint: () => encodeVarint,
159
181
  generateEd25519KeyPair: () => generateEd25519KeyPair,
182
+ getRequiredAuthLevel: () => getRequiredAuthLevel,
160
183
  getSignTarget: () => getSignTarget,
161
184
  hasScope: () => hasScope,
162
185
  isAdminOpcode: () => isAdminOpcode,
186
+ isCapsuleTerminal: () => isCapsuleTerminal,
187
+ isDeviceTerminal: () => isDeviceTerminal,
163
188
  isKnownOpcode: () => isKnownOpcode,
189
+ isLoginChallengeTerminal: () => isLoginChallengeTerminal,
190
+ isNestFlowIntent: () => isNestFlowIntent,
191
+ isSessionTerminal: () => isSessionTerminal,
192
+ isTickAuthTerminal: () => isTickAuthTerminal,
164
193
  isTimestampValid: () => isTimestampValid,
165
194
  nonce16: () => nonce16,
166
195
  normalizeSensorDecision: () => normalizeSensorDecision,
@@ -171,6 +200,7 @@ __export(index_exports, {
171
200
  packPasskeyRegisterOptionsReq: () => packPasskeyRegisterOptionsReq,
172
201
  parseScope: () => parseScope,
173
202
  resolveTimeout: () => resolveTimeout,
203
+ satisfiesAuthLevel: () => satisfiesAuthLevel,
174
204
  sensitivityName: () => sensitivityName,
175
205
  sha256: () => sha256,
176
206
  signFrame: () => signFrame,
@@ -180,7 +210,13 @@ __export(index_exports, {
180
210
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
181
211
  unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
182
212
  utf8: () => utf8,
213
+ validateCapsuleTransition: () => validateCapsuleTransition,
214
+ validateDeviceTransition: () => validateDeviceTransition,
183
215
  validateFrameShape: () => validateFrameShape,
216
+ validateLoginChallengeTransition: () => validateLoginChallengeTransition,
217
+ validateSessionTransition: () => validateSessionTransition,
218
+ validateTickAuthTransition: () => validateTickAuthTransition,
219
+ validateTrustLinkTransition: () => validateTrustLinkTransition,
184
220
  varintLength: () => varintLength,
185
221
  varintU: () => varintU,
186
222
  verifyFrameSignature: () => verifyFrameSignature
@@ -1536,10 +1572,10 @@ function tlv(type, value) {
1536
1572
  ]);
1537
1573
  }
1538
1574
  function buildTLVs(items, opts) {
1539
- const allow = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1575
+ const allow2 = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1540
1576
  const sorted = [...items].sort((a, b) => a.type - b.type);
1541
1577
  for (let i = 1; i < sorted.length; i++) {
1542
- if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {
1578
+ if (sorted[i].type === sorted[i - 1].type && !allow2.has(sorted[i].type)) {
1543
1579
  throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);
1544
1580
  }
1545
1581
  }
@@ -2109,6 +2145,20 @@ var INTENT_REQUIREMENTS = {
2109
2145
  "passport.revoke": ["write", "witness"],
2110
2146
  "stream.publish": ["write"],
2111
2147
  "stream.subscribe": ["read"],
2148
+ // NestFlow intents
2149
+ "auth.web.login.*": ["execute"],
2150
+ "tickauth.challenge.*": ["execute"],
2151
+ "capsule.issue.*": ["write", "execute"],
2152
+ "session.*": ["execute"],
2153
+ "device.list": ["read"],
2154
+ "device.rename": ["write"],
2155
+ "device.trust.*": ["write", "execute"],
2156
+ "device.revoke": ["write", "execute"],
2157
+ "identity.*": ["admin", "execute"],
2158
+ "primary.device.*": ["admin", "execute"],
2159
+ "secret.rotate": ["admin"],
2160
+ "org.security.*": ["admin"],
2161
+ "production.execution.*": ["admin", "execute"],
2112
2162
  "admin.*": ["admin"]
2113
2163
  };
2114
2164
 
@@ -2130,13 +2180,29 @@ var AXIS_OPCODES = /* @__PURE__ */ new Set([
2130
2180
  "INTENT.EXEC",
2131
2181
  "ACTOR.KEY.ROTATE",
2132
2182
  "ACTOR.KEY.REVOKE",
2133
- "ISSUER.KEY.ROTATE"
2183
+ "ISSUER.KEY.ROTATE",
2184
+ // NestFlow opcodes
2185
+ "AUTH.WEB.LOGIN",
2186
+ "AUTH.WEB.SCAN",
2187
+ "TICKAUTH.CREATE",
2188
+ "TICKAUTH.FULFILL",
2189
+ "TICKAUTH.REJECT",
2190
+ "SESSION.ACTIVATE",
2191
+ "SESSION.REFRESH",
2192
+ "SESSION.LOGOUT",
2193
+ "DEVICE.TRUST",
2194
+ "DEVICE.PROMOTE",
2195
+ "DEVICE.REVOKE",
2196
+ "DEVICE.LIST",
2197
+ "DEVICE.RENAME",
2198
+ "IDENTITY.RECOVERY",
2199
+ "IDENTITY.LOCK"
2134
2200
  ]);
2135
2201
  function isKnownOpcode(op) {
2136
2202
  return AXIS_OPCODES.has(op);
2137
2203
  }
2138
2204
  function isAdminOpcode(op) {
2139
- return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.");
2205
+ return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.") || op.startsWith("IDENTITY.");
2140
2206
  }
2141
2207
 
2142
2208
  // src/core/receipt.ts
@@ -2186,7 +2252,42 @@ var INTENT_SENSITIVITY_MAP = {
2186
2252
  // Admin intents
2187
2253
  "admin.create_capsule": 4 /* CRITICAL */,
2188
2254
  "admin.revoke_capsule": 4 /* CRITICAL */,
2189
- "admin.issue_node_cert": 4 /* CRITICAL */
2255
+ "admin.issue_node_cert": 4 /* CRITICAL */,
2256
+ // NestFlow: Auth
2257
+ "auth.web.login.request": 2 /* MEDIUM */,
2258
+ "auth.web.login.scan": 3 /* HIGH */,
2259
+ // NestFlow: TickAuth
2260
+ "tickauth.challenge.create": 2 /* MEDIUM */,
2261
+ "tickauth.challenge.fulfill": 3 /* HIGH */,
2262
+ "tickauth.challenge.reject": 2 /* MEDIUM */,
2263
+ // NestFlow: Capsule issuance
2264
+ "capsule.issue.login": 3 /* HIGH */,
2265
+ "capsule.issue.device_registration": 3 /* HIGH */,
2266
+ "capsule.issue.step_up": 3 /* HIGH */,
2267
+ "capsule.issue.recovery": 4 /* CRITICAL */,
2268
+ // NestFlow: Session
2269
+ "session.activate": 3 /* HIGH */,
2270
+ "session.refresh": 2 /* MEDIUM */,
2271
+ "session.logout": 1 /* LOW */,
2272
+ // NestFlow: Device trust
2273
+ "device.trust.request": 3 /* HIGH */,
2274
+ "device.trust.promote": 4 /* CRITICAL */,
2275
+ "device.revoke": 4 /* CRITICAL */,
2276
+ "device.list": 1 /* LOW */,
2277
+ "device.rename": 1 /* LOW */,
2278
+ // NestFlow: Protected operations
2279
+ "flow.publish": 2 /* MEDIUM */,
2280
+ "flow.delete": 3 /* HIGH */,
2281
+ "node.delete": 4 /* CRITICAL */,
2282
+ "secret.rotate": 4 /* CRITICAL */,
2283
+ "org.security.update": 4 /* CRITICAL */,
2284
+ "production.execution.approve": 4 /* CRITICAL */,
2285
+ // NestFlow: Recovery
2286
+ "identity.recovery.start": 4 /* CRITICAL */,
2287
+ "identity.recovery.complete": 4 /* CRITICAL */,
2288
+ "primary.device.rotate": 4 /* CRITICAL */,
2289
+ "identity.lock": 4 /* CRITICAL */,
2290
+ "identity.unlock": 4 /* CRITICAL */
2190
2291
  };
2191
2292
  function classifyIntent(intent) {
2192
2293
  if (INTENT_SENSITIVITY_MAP[intent]) {
@@ -2284,6 +2385,425 @@ function isTimestampValid(ts, skewSeconds = 120) {
2284
2385
  const diff = Math.abs(now - ts);
2285
2386
  return diff <= skewSeconds;
2286
2387
  }
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
+ }
2287
2807
  // Annotate the CommonJS export names for ESM import in node:
2288
2808
  0 && (module.exports = {
2289
2809
  ATS1_HDR,
@@ -2292,14 +2812,19 @@ function isTimestampValid(ts, skewSeconds = 120) {
2292
2812
  AXIS_OPCODES,
2293
2813
  AXIS_VERSION,
2294
2814
  Ats1Codec,
2815
+ AuthLevel,
2295
2816
  AxisFrameZ,
2296
2817
  AxisPacketTags,
2297
2818
  BodyProfile,
2298
2819
  CAPABILITIES,
2820
+ CapsuleStatus,
2299
2821
  ContractViolationError,
2300
2822
  DEFAULT_CONTRACTS,
2301
2823
  DEFAULT_TIMEOUT,
2302
2824
  Decision,
2825
+ DeviceStatus,
2826
+ DeviceTrustLevel,
2827
+ DeviceType,
2303
2828
  ERR_BAD_SIGNATURE,
2304
2829
  ERR_CONTRACT_VIOLATION,
2305
2830
  ERR_INVALID_PACKET,
@@ -2318,6 +2843,7 @@ function isTimestampValid(ts, skewSeconds = 120) {
2318
2843
  Intent,
2319
2844
  IntentRouter,
2320
2845
  IntentSensitivity,
2846
+ LoginChallengeStatus,
2321
2847
  MAX_BODY_LEN,
2322
2848
  MAX_FRAME_LEN,
2323
2849
  MAX_HDR_LEN,
@@ -2332,6 +2858,10 @@ function isTimestampValid(ts, skewSeconds = 120) {
2332
2858
  NCERT_PUB,
2333
2859
  NCERT_SCOPE,
2334
2860
  NCERT_SIG,
2861
+ NESTFLOW_INTENTS,
2862
+ NESTFLOW_INTENT_SET,
2863
+ NESTFLOW_POLICY_MAP,
2864
+ NestFlowCapsuleType,
2335
2865
  PROOF_CAPABILITIES,
2336
2866
  PROOF_CAPSULE,
2337
2867
  PROOF_JWT,
@@ -2346,6 +2876,7 @@ function isTimestampValid(ts, skewSeconds = 120) {
2346
2876
  Schema2012_PasskeyLoginVerifyRes,
2347
2877
  Schema2021_PasskeyRegisterOptionsReq,
2348
2878
  SensorDecisions,
2879
+ SessionStatus,
2349
2880
  TLV_ACTOR_ID,
2350
2881
  TLV_AUD,
2351
2882
  TLV_BODY_ARR,
@@ -2377,6 +2908,9 @@ function isTimestampValid(ts, skewSeconds = 120) {
2377
2908
  TLV_TRACE_ID,
2378
2909
  TLV_TS,
2379
2910
  TLV_UPLOAD_ID,
2911
+ TickAuthChallengeStatus,
2912
+ TrustLinkStatus,
2913
+ TrustLinkType,
2380
2914
  axis1SigningBytes,
2381
2915
  b64urlDecode,
2382
2916
  b64urlDecodeString,
@@ -2390,6 +2924,14 @@ function isTimestampValid(ts, skewSeconds = 120) {
2390
2924
  canAccessResource,
2391
2925
  canonicalJson,
2392
2926
  canonicalJsonExcluding,
2927
+ checkBrowserProof,
2928
+ checkCapsule,
2929
+ checkDeviceTrust,
2930
+ checkIntentPolicy,
2931
+ checkLoginChallenge,
2932
+ checkReplayProtection,
2933
+ checkSession,
2934
+ checkTickAuth,
2393
2935
  classifyIntent,
2394
2936
  computeReceiptHash,
2395
2937
  computeSignaturePayload,
@@ -2406,10 +2948,17 @@ function isTimestampValid(ts, skewSeconds = 120) {
2406
2948
  encodeTLVs,
2407
2949
  encodeVarint,
2408
2950
  generateEd25519KeyPair,
2951
+ getRequiredAuthLevel,
2409
2952
  getSignTarget,
2410
2953
  hasScope,
2411
2954
  isAdminOpcode,
2955
+ isCapsuleTerminal,
2956
+ isDeviceTerminal,
2412
2957
  isKnownOpcode,
2958
+ isLoginChallengeTerminal,
2959
+ isNestFlowIntent,
2960
+ isSessionTerminal,
2961
+ isTickAuthTerminal,
2413
2962
  isTimestampValid,
2414
2963
  nonce16,
2415
2964
  normalizeSensorDecision,
@@ -2420,6 +2969,7 @@ function isTimestampValid(ts, skewSeconds = 120) {
2420
2969
  packPasskeyRegisterOptionsReq,
2421
2970
  parseScope,
2422
2971
  resolveTimeout,
2972
+ satisfiesAuthLevel,
2423
2973
  sensitivityName,
2424
2974
  sha256,
2425
2975
  signFrame,
@@ -2429,7 +2979,13 @@ function isTimestampValid(ts, skewSeconds = 120) {
2429
2979
  unpackPasskeyLoginVerifyReq,
2430
2980
  unpackPasskeyRegisterOptionsReq,
2431
2981
  utf8,
2982
+ validateCapsuleTransition,
2983
+ validateDeviceTransition,
2432
2984
  validateFrameShape,
2985
+ validateLoginChallengeTransition,
2986
+ validateSessionTransition,
2987
+ validateTickAuthTransition,
2988
+ validateTrustLinkTransition,
2433
2989
  varintLength,
2434
2990
  varintU,
2435
2991
  verifyFrameSignature