@nextera.one/axis-server-sdk 0.8.0 → 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,
@@ -91,11 +101,13 @@ __export(index_exports, {
91
101
  PROOF_NONE: () => PROOF_NONE,
92
102
  PROOF_WITNESS: () => PROOF_WITNESS,
93
103
  ProofType: () => ProofType,
104
+ RiskDecision: () => RiskDecision,
94
105
  Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
95
106
  Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
96
107
  Schema2012_PasskeyLoginVerifyRes: () => Schema2012_PasskeyLoginVerifyRes,
97
108
  Schema2021_PasskeyRegisterOptionsReq: () => Schema2021_PasskeyRegisterOptionsReq,
98
109
  SensorDecisions: () => SensorDecisions,
110
+ SessionStatus: () => SessionStatus,
99
111
  TLV_ACTOR_ID: () => TLV_ACTOR_ID,
100
112
  TLV_AUD: () => TLV_AUD,
101
113
  TLV_BODY_ARR: () => TLV_BODY_ARR,
@@ -127,6 +139,9 @@ __export(index_exports, {
127
139
  TLV_TRACE_ID: () => TLV_TRACE_ID,
128
140
  TLV_TS: () => TLV_TS,
129
141
  TLV_UPLOAD_ID: () => TLV_UPLOAD_ID,
142
+ TickAuthChallengeStatus: () => TickAuthChallengeStatus,
143
+ TrustLinkStatus: () => TrustLinkStatus,
144
+ TrustLinkType: () => TrustLinkType,
130
145
  axis1SigningBytes: () => axis1SigningBytes,
131
146
  b64urlDecode: () => b64urlDecode,
132
147
  b64urlDecodeString: () => b64urlDecodeString,
@@ -140,6 +155,14 @@ __export(index_exports, {
140
155
  canAccessResource: () => canAccessResource,
141
156
  canonicalJson: () => canonicalJson,
142
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,
143
166
  classifyIntent: () => classifyIntent,
144
167
  computeReceiptHash: () => computeReceiptHash,
145
168
  computeSignaturePayload: () => computeSignaturePayload,
@@ -156,10 +179,18 @@ __export(index_exports, {
156
179
  encodeTLVs: () => encodeTLVs,
157
180
  encodeVarint: () => encodeVarint,
158
181
  generateEd25519KeyPair: () => generateEd25519KeyPair,
182
+ getRequiredAuthLevel: () => getRequiredAuthLevel,
159
183
  getSignTarget: () => getSignTarget,
160
184
  hasScope: () => hasScope,
161
185
  isAdminOpcode: () => isAdminOpcode,
186
+ isCapsuleTerminal: () => isCapsuleTerminal,
187
+ isDeviceTerminal: () => isDeviceTerminal,
162
188
  isKnownOpcode: () => isKnownOpcode,
189
+ isLoginChallengeTerminal: () => isLoginChallengeTerminal,
190
+ isNestFlowIntent: () => isNestFlowIntent,
191
+ isSessionTerminal: () => isSessionTerminal,
192
+ isTickAuthTerminal: () => isTickAuthTerminal,
193
+ isTimestampValid: () => isTimestampValid,
163
194
  nonce16: () => nonce16,
164
195
  normalizeSensorDecision: () => normalizeSensorDecision,
165
196
  packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
@@ -169,6 +200,7 @@ __export(index_exports, {
169
200
  packPasskeyRegisterOptionsReq: () => packPasskeyRegisterOptionsReq,
170
201
  parseScope: () => parseScope,
171
202
  resolveTimeout: () => resolveTimeout,
203
+ satisfiesAuthLevel: () => satisfiesAuthLevel,
172
204
  sensitivityName: () => sensitivityName,
173
205
  sha256: () => sha256,
174
206
  signFrame: () => signFrame,
@@ -178,6 +210,13 @@ __export(index_exports, {
178
210
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
179
211
  unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
180
212
  utf8: () => utf8,
213
+ validateCapsuleTransition: () => validateCapsuleTransition,
214
+ validateDeviceTransition: () => validateDeviceTransition,
215
+ validateFrameShape: () => validateFrameShape,
216
+ validateLoginChallengeTransition: () => validateLoginChallengeTransition,
217
+ validateSessionTransition: () => validateSessionTransition,
218
+ validateTickAuthTransition: () => validateTickAuthTransition,
219
+ validateTrustLinkTransition: () => validateTrustLinkTransition,
181
220
  varintLength: () => varintLength,
182
221
  varintU: () => varintU,
183
222
  verifyFrameSignature: () => verifyFrameSignature
@@ -1533,10 +1572,10 @@ function tlv(type, value) {
1533
1572
  ]);
1534
1573
  }
1535
1574
  function buildTLVs(items, opts) {
1536
- const allow = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1575
+ const allow2 = opts?.allowDupTypes ?? /* @__PURE__ */ new Set();
1537
1576
  const sorted = [...items].sort((a, b) => a.type - b.type);
1538
1577
  for (let i = 1; i < sorted.length; i++) {
1539
- 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)) {
1540
1579
  throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);
1541
1580
  }
1542
1581
  }
@@ -2106,9 +2145,33 @@ var INTENT_REQUIREMENTS = {
2106
2145
  "passport.revoke": ["write", "witness"],
2107
2146
  "stream.publish": ["write"],
2108
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"],
2109
2162
  "admin.*": ["admin"]
2110
2163
  };
2111
2164
 
2165
+ // src/risk/index.ts
2166
+ var RiskDecision = /* @__PURE__ */ ((RiskDecision2) => {
2167
+ RiskDecision2["ALLOW"] = "ALLOW";
2168
+ RiskDecision2["THROTTLE"] = "THROTTLE";
2169
+ RiskDecision2["STEP_UP"] = "STEP_UP";
2170
+ RiskDecision2["WITNESS"] = "WITNESS";
2171
+ RiskDecision2["DENY"] = "DENY";
2172
+ return RiskDecision2;
2173
+ })(RiskDecision || {});
2174
+
2112
2175
  // src/core/opcodes.ts
2113
2176
  var AXIS_OPCODES = /* @__PURE__ */ new Set([
2114
2177
  "CAPSULE.ISSUE",
@@ -2117,13 +2180,29 @@ var AXIS_OPCODES = /* @__PURE__ */ new Set([
2117
2180
  "INTENT.EXEC",
2118
2181
  "ACTOR.KEY.ROTATE",
2119
2182
  "ACTOR.KEY.REVOKE",
2120
- "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"
2121
2200
  ]);
2122
2201
  function isKnownOpcode(op) {
2123
2202
  return AXIS_OPCODES.has(op);
2124
2203
  }
2125
2204
  function isAdminOpcode(op) {
2126
- return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.");
2205
+ return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.") || op.startsWith("IDENTITY.");
2127
2206
  }
2128
2207
 
2129
2208
  // src/core/receipt.ts
@@ -2173,7 +2252,42 @@ var INTENT_SENSITIVITY_MAP = {
2173
2252
  // Admin intents
2174
2253
  "admin.create_capsule": 4 /* CRITICAL */,
2175
2254
  "admin.revoke_capsule": 4 /* CRITICAL */,
2176
- "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 */
2177
2291
  };
2178
2292
  function classifyIntent(intent) {
2179
2293
  if (INTENT_SENSITIVITY_MAP[intent]) {
@@ -2228,6 +2342,468 @@ function resolveTimeout(intent) {
2228
2342
  }
2229
2343
  return DEFAULT_TIMEOUT;
2230
2344
  }
2345
+
2346
+ // src/core/frame-validator.ts
2347
+ function validateFrameShape(frame) {
2348
+ if (!frame || typeof frame !== "object") {
2349
+ return false;
2350
+ }
2351
+ if (frame.v !== 1) {
2352
+ return false;
2353
+ }
2354
+ const requiredStrings = ["pid", "nonce", "actorId", "opcode"];
2355
+ for (const key of requiredStrings) {
2356
+ if (typeof frame[key] !== "string" || frame[key].length < 6) {
2357
+ return false;
2358
+ }
2359
+ }
2360
+ if (typeof frame.ts !== "number" || !Number.isFinite(frame.ts)) {
2361
+ return false;
2362
+ }
2363
+ if (frame.aud !== void 0 && (typeof frame.aud !== "string" || frame.aud.length === 0)) {
2364
+ return false;
2365
+ }
2366
+ if (!frame.sig || typeof frame.sig !== "object") {
2367
+ return false;
2368
+ }
2369
+ if (frame.sig.alg !== "EdDSA") {
2370
+ return false;
2371
+ }
2372
+ if (typeof frame.sig.kid !== "string" || frame.sig.kid.length < 8) {
2373
+ return false;
2374
+ }
2375
+ if (typeof frame.sig.value !== "string" || frame.sig.value.length < 32) {
2376
+ return false;
2377
+ }
2378
+ if (typeof frame.body !== "object" || frame.body === null) {
2379
+ return false;
2380
+ }
2381
+ return true;
2382
+ }
2383
+ function isTimestampValid(ts, skewSeconds = 120) {
2384
+ const now = Math.floor(Date.now() / 1e3);
2385
+ const diff = Math.abs(now - ts);
2386
+ return diff <= skewSeconds;
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
+ }
2231
2807
  // Annotate the CommonJS export names for ESM import in node:
2232
2808
  0 && (module.exports = {
2233
2809
  ATS1_HDR,
@@ -2236,14 +2812,19 @@ function resolveTimeout(intent) {
2236
2812
  AXIS_OPCODES,
2237
2813
  AXIS_VERSION,
2238
2814
  Ats1Codec,
2815
+ AuthLevel,
2239
2816
  AxisFrameZ,
2240
2817
  AxisPacketTags,
2241
2818
  BodyProfile,
2242
2819
  CAPABILITIES,
2820
+ CapsuleStatus,
2243
2821
  ContractViolationError,
2244
2822
  DEFAULT_CONTRACTS,
2245
2823
  DEFAULT_TIMEOUT,
2246
2824
  Decision,
2825
+ DeviceStatus,
2826
+ DeviceTrustLevel,
2827
+ DeviceType,
2247
2828
  ERR_BAD_SIGNATURE,
2248
2829
  ERR_CONTRACT_VIOLATION,
2249
2830
  ERR_INVALID_PACKET,
@@ -2262,6 +2843,7 @@ function resolveTimeout(intent) {
2262
2843
  Intent,
2263
2844
  IntentRouter,
2264
2845
  IntentSensitivity,
2846
+ LoginChallengeStatus,
2265
2847
  MAX_BODY_LEN,
2266
2848
  MAX_FRAME_LEN,
2267
2849
  MAX_HDR_LEN,
@@ -2276,6 +2858,10 @@ function resolveTimeout(intent) {
2276
2858
  NCERT_PUB,
2277
2859
  NCERT_SCOPE,
2278
2860
  NCERT_SIG,
2861
+ NESTFLOW_INTENTS,
2862
+ NESTFLOW_INTENT_SET,
2863
+ NESTFLOW_POLICY_MAP,
2864
+ NestFlowCapsuleType,
2279
2865
  PROOF_CAPABILITIES,
2280
2866
  PROOF_CAPSULE,
2281
2867
  PROOF_JWT,
@@ -2284,11 +2870,13 @@ function resolveTimeout(intent) {
2284
2870
  PROOF_NONE,
2285
2871
  PROOF_WITNESS,
2286
2872
  ProofType,
2873
+ RiskDecision,
2287
2874
  Schema2002_PasskeyLoginOptionsRes,
2288
2875
  Schema2011_PasskeyLoginVerifyReq,
2289
2876
  Schema2012_PasskeyLoginVerifyRes,
2290
2877
  Schema2021_PasskeyRegisterOptionsReq,
2291
2878
  SensorDecisions,
2879
+ SessionStatus,
2292
2880
  TLV_ACTOR_ID,
2293
2881
  TLV_AUD,
2294
2882
  TLV_BODY_ARR,
@@ -2320,6 +2908,9 @@ function resolveTimeout(intent) {
2320
2908
  TLV_TRACE_ID,
2321
2909
  TLV_TS,
2322
2910
  TLV_UPLOAD_ID,
2911
+ TickAuthChallengeStatus,
2912
+ TrustLinkStatus,
2913
+ TrustLinkType,
2323
2914
  axis1SigningBytes,
2324
2915
  b64urlDecode,
2325
2916
  b64urlDecodeString,
@@ -2333,6 +2924,14 @@ function resolveTimeout(intent) {
2333
2924
  canAccessResource,
2334
2925
  canonicalJson,
2335
2926
  canonicalJsonExcluding,
2927
+ checkBrowserProof,
2928
+ checkCapsule,
2929
+ checkDeviceTrust,
2930
+ checkIntentPolicy,
2931
+ checkLoginChallenge,
2932
+ checkReplayProtection,
2933
+ checkSession,
2934
+ checkTickAuth,
2336
2935
  classifyIntent,
2337
2936
  computeReceiptHash,
2338
2937
  computeSignaturePayload,
@@ -2349,10 +2948,18 @@ function resolveTimeout(intent) {
2349
2948
  encodeTLVs,
2350
2949
  encodeVarint,
2351
2950
  generateEd25519KeyPair,
2951
+ getRequiredAuthLevel,
2352
2952
  getSignTarget,
2353
2953
  hasScope,
2354
2954
  isAdminOpcode,
2955
+ isCapsuleTerminal,
2956
+ isDeviceTerminal,
2355
2957
  isKnownOpcode,
2958
+ isLoginChallengeTerminal,
2959
+ isNestFlowIntent,
2960
+ isSessionTerminal,
2961
+ isTickAuthTerminal,
2962
+ isTimestampValid,
2356
2963
  nonce16,
2357
2964
  normalizeSensorDecision,
2358
2965
  packPasskeyLoginOptionsReq,
@@ -2362,6 +2969,7 @@ function resolveTimeout(intent) {
2362
2969
  packPasskeyRegisterOptionsReq,
2363
2970
  parseScope,
2364
2971
  resolveTimeout,
2972
+ satisfiesAuthLevel,
2365
2973
  sensitivityName,
2366
2974
  sha256,
2367
2975
  signFrame,
@@ -2371,6 +2979,13 @@ function resolveTimeout(intent) {
2371
2979
  unpackPasskeyLoginVerifyReq,
2372
2980
  unpackPasskeyRegisterOptionsReq,
2373
2981
  utf8,
2982
+ validateCapsuleTransition,
2983
+ validateDeviceTransition,
2984
+ validateFrameShape,
2985
+ validateLoginChallengeTransition,
2986
+ validateSessionTransition,
2987
+ validateTickAuthTransition,
2988
+ validateTrustLinkTransition,
2374
2989
  varintLength,
2375
2990
  varintU,
2376
2991
  verifyFrameSignature