@nextera.one/axis-server-sdk 2.2.7 → 2.2.9

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
@@ -253,7 +253,7 @@ function AxisRateLimit(config) {
253
253
  return descriptor;
254
254
  };
255
255
  }
256
- var import_reflect_metadata3, AXIS_META_KEY, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
256
+ var import_reflect_metadata3, AXIS_META_KEY, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_AUTHORIZED_KEY, AXIS_RATE_LIMIT_KEY;
257
257
  var init_intent_policy_decorator = __esm({
258
258
  "src/decorators/intent-policy.decorator.ts"() {
259
259
  import_reflect_metadata3 = require("reflect-metadata");
@@ -263,6 +263,7 @@ var init_intent_policy_decorator = __esm({
263
263
  REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
264
264
  AXIS_PUBLIC_KEY = "axis:public";
265
265
  AXIS_ANONYMOUS_KEY = "axis:anonymous";
266
+ AXIS_AUTHORIZED_KEY = "axis:authorized";
266
267
  AXIS_RATE_LIMIT_KEY = "axis:rateLimit";
267
268
  }
268
269
  });
@@ -1396,6 +1397,271 @@ var init_axis_chain_executor = __esm({
1396
1397
  }
1397
1398
  });
1398
1399
 
1400
+ // src/security/scopes.ts
1401
+ function hasScope(scopes, required) {
1402
+ if (!Array.isArray(scopes) || scopes.length === 0) {
1403
+ return false;
1404
+ }
1405
+ if (scopes.includes(required)) {
1406
+ return true;
1407
+ }
1408
+ const [resource, id] = required.split(":");
1409
+ if (resource && id) {
1410
+ const wildcard = `${resource}:*`;
1411
+ if (scopes.includes(wildcard)) {
1412
+ return true;
1413
+ }
1414
+ }
1415
+ return false;
1416
+ }
1417
+ function parseScope(scope) {
1418
+ const parts = scope.split(":");
1419
+ if (parts.length !== 2) return null;
1420
+ return { resource: parts[0], id: parts[1] };
1421
+ }
1422
+ function canAccessResource(scopes, resourceType, resourceId) {
1423
+ const required = `${resourceType}:${resourceId}`;
1424
+ return hasScope(scopes, required);
1425
+ }
1426
+ var init_scopes = __esm({
1427
+ "src/security/scopes.ts"() {
1428
+ }
1429
+ });
1430
+
1431
+ // src/security/inline-capsule.ts
1432
+ function normalizeInlineCapsule(input) {
1433
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
1434
+ return null;
1435
+ }
1436
+ const raw = input;
1437
+ const scopes = normalizeStringList(raw.scopes ?? raw.scope);
1438
+ return {
1439
+ id: normalizeScalar(raw.id),
1440
+ actorId: normalizeScalar(raw.actorId),
1441
+ intents: normalizeStringList(raw.intents),
1442
+ issuedAt: normalizeTimestamp(raw.issuedAt ?? raw.iat),
1443
+ expiresAt: normalizeTimestamp(raw.expiresAt ?? raw.exp),
1444
+ realm: normalizeScalar(raw.realm),
1445
+ node: normalizeScalar(raw.node),
1446
+ scopes,
1447
+ raw
1448
+ };
1449
+ }
1450
+ function inlineCapsuleAllowsIntent(capsule, intent) {
1451
+ if (!capsule.intents || capsule.intents.length === 0) {
1452
+ return false;
1453
+ }
1454
+ for (const pattern of capsule.intents) {
1455
+ if (pattern === "*" || pattern === intent) {
1456
+ return true;
1457
+ }
1458
+ if (pattern.endsWith(".*")) {
1459
+ const prefix = pattern.slice(0, -1);
1460
+ if (intent.startsWith(prefix)) {
1461
+ return true;
1462
+ }
1463
+ }
1464
+ }
1465
+ return false;
1466
+ }
1467
+ function isInlineCapsuleExpired(capsule, clockSkewMs = 3e4) {
1468
+ if (capsule.expiresAt === void 0) {
1469
+ return false;
1470
+ }
1471
+ return BigInt(Date.now()) > capsule.expiresAt + BigInt(clockSkewMs);
1472
+ }
1473
+ function resolvePolicyScopes(scopes, context) {
1474
+ return scopes.map(
1475
+ (scope) => scope.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
1476
+ const resolved = resolveTemplateExpression(expression.trim(), context);
1477
+ if (resolved === void 0 || resolved === null || resolved === "") {
1478
+ throw new Error(`CAPSULE_SCOPE_TEMPLATE_UNRESOLVED:${expression}`);
1479
+ }
1480
+ return String(resolved);
1481
+ })
1482
+ );
1483
+ }
1484
+ function inlineCapsuleSatisfiesScopes(capsule, requiredScopes, mode = "all") {
1485
+ if (!capsule.scopes || capsule.scopes.length === 0) {
1486
+ return false;
1487
+ }
1488
+ if (mode === "any") {
1489
+ return requiredScopes.some((scope) => hasScope(capsule.scopes, scope));
1490
+ }
1491
+ return requiredScopes.every((scope) => hasScope(capsule.scopes, scope));
1492
+ }
1493
+ function resolveTemplateExpression(expression, context) {
1494
+ if (expression === "intent") {
1495
+ return context.intent;
1496
+ }
1497
+ if (expression === "actorId") {
1498
+ return context.actorId;
1499
+ }
1500
+ if (expression === "chainId") {
1501
+ return context.chainId;
1502
+ }
1503
+ if (expression === "stepId") {
1504
+ return context.stepId;
1505
+ }
1506
+ if (expression.startsWith("body.")) {
1507
+ return getNestedValue(context.body, expression.slice(5));
1508
+ }
1509
+ return void 0;
1510
+ }
1511
+ function getNestedValue(value, path2) {
1512
+ if (!value || typeof value !== "object") {
1513
+ return void 0;
1514
+ }
1515
+ return path2.split(".").reduce((current, segment) => {
1516
+ if (!current || typeof current !== "object") {
1517
+ return void 0;
1518
+ }
1519
+ return current[segment];
1520
+ }, value);
1521
+ }
1522
+ function normalizeScalar(value) {
1523
+ if (typeof value === "string") {
1524
+ return value;
1525
+ }
1526
+ if (value instanceof Uint8Array) {
1527
+ return Buffer.from(value).toString("hex");
1528
+ }
1529
+ return void 0;
1530
+ }
1531
+ function normalizeStringList(value) {
1532
+ if (!value) {
1533
+ return void 0;
1534
+ }
1535
+ const list = Array.isArray(value) ? value : [value];
1536
+ const normalized = list.map((entry) => typeof entry === "string" ? entry : void 0).filter((entry) => !!entry && entry.trim().length > 0);
1537
+ return normalized.length > 0 ? Array.from(new Set(normalized)) : void 0;
1538
+ }
1539
+ function normalizeTimestamp(value) {
1540
+ if (typeof value === "bigint") {
1541
+ return value;
1542
+ }
1543
+ if (typeof value === "number" && Number.isFinite(value)) {
1544
+ return BigInt(Math.trunc(value));
1545
+ }
1546
+ if (typeof value === "string" && value.trim().length > 0) {
1547
+ try {
1548
+ return BigInt(value);
1549
+ } catch {
1550
+ return void 0;
1551
+ }
1552
+ }
1553
+ return void 0;
1554
+ }
1555
+ var init_inline_capsule = __esm({
1556
+ "src/security/inline-capsule.ts"() {
1557
+ init_scopes();
1558
+ }
1559
+ });
1560
+
1561
+ // src/sensor/axis-sensor.ts
1562
+ function normalizeSensorDecision(sensorDecision) {
1563
+ if ("action" in sensorDecision) {
1564
+ switch (sensorDecision.action) {
1565
+ case "ALLOW":
1566
+ return {
1567
+ allow: true,
1568
+ riskScore: 0,
1569
+ reasons: [],
1570
+ meta: sensorDecision.meta
1571
+ };
1572
+ case "DENY":
1573
+ return {
1574
+ allow: false,
1575
+ riskScore: 100,
1576
+ reasons: [sensorDecision.code, sensorDecision.reason].filter(
1577
+ Boolean
1578
+ ),
1579
+ meta: sensorDecision.meta,
1580
+ retryAfterMs: sensorDecision.retryAfterMs
1581
+ };
1582
+ case "THROTTLE":
1583
+ return {
1584
+ allow: false,
1585
+ riskScore: 50,
1586
+ reasons: ["RATE_LIMIT"],
1587
+ retryAfterMs: sensorDecision.retryAfterMs,
1588
+ meta: sensorDecision.meta
1589
+ };
1590
+ case "FLAG":
1591
+ return {
1592
+ allow: true,
1593
+ riskScore: sensorDecision.scoreDelta,
1594
+ reasons: sensorDecision.reasons,
1595
+ meta: sensorDecision.meta
1596
+ };
1597
+ }
1598
+ }
1599
+ return {
1600
+ allow: sensorDecision.allow,
1601
+ riskScore: sensorDecision.riskScore,
1602
+ reasons: sensorDecision.reasons,
1603
+ tags: sensorDecision.tags,
1604
+ meta: sensorDecision.meta,
1605
+ tighten: sensorDecision.tighten,
1606
+ retryAfterMs: sensorDecision.retryAfterMs
1607
+ };
1608
+ }
1609
+ var Decision, SensorDecisions;
1610
+ var init_axis_sensor = __esm({
1611
+ "src/sensor/axis-sensor.ts"() {
1612
+ Decision = /* @__PURE__ */ ((Decision2) => {
1613
+ Decision2["ALLOW"] = "ALLOW";
1614
+ Decision2["DENY"] = "DENY";
1615
+ Decision2["THROTTLE"] = "THROTTLE";
1616
+ Decision2["FLAG"] = "FLAG";
1617
+ return Decision2;
1618
+ })(Decision || {});
1619
+ SensorDecisions = {
1620
+ allow(meta, tags) {
1621
+ return {
1622
+ decision: "ALLOW" /* ALLOW */,
1623
+ allow: true,
1624
+ riskScore: 0,
1625
+ reasons: [],
1626
+ tags,
1627
+ meta
1628
+ };
1629
+ },
1630
+ deny(code, reason, meta) {
1631
+ return {
1632
+ decision: "DENY" /* DENY */,
1633
+ allow: false,
1634
+ riskScore: 100,
1635
+ code,
1636
+ reasons: [code, reason].filter(Boolean),
1637
+ meta
1638
+ };
1639
+ },
1640
+ throttle(retryAfterMs, meta) {
1641
+ return {
1642
+ decision: "THROTTLE" /* THROTTLE */,
1643
+ allow: false,
1644
+ riskScore: 50,
1645
+ retryAfterMs,
1646
+ code: "RATE_LIMIT",
1647
+ reasons: ["RATE_LIMIT"],
1648
+ meta
1649
+ };
1650
+ },
1651
+ flag(scoreDelta, reasons, meta) {
1652
+ return {
1653
+ decision: "FLAG" /* FLAG */,
1654
+ allow: true,
1655
+ riskScore: scoreDelta,
1656
+ scoreDelta,
1657
+ reasons,
1658
+ meta
1659
+ };
1660
+ }
1661
+ };
1662
+ }
1663
+ });
1664
+
1399
1665
  // src/cce/cce.types.ts
1400
1666
  var CCE_PROTOCOL_VERSION, CCE_DERIVATION, CCE_AES_KEY_BYTES, CCE_IV_BYTES, CCE_NONCE_BYTES, CCE_ERROR, CceError;
1401
1667
  var init_cce_types = __esm({
@@ -1721,168 +1987,64 @@ function buildWitnessRecord(envelope, capsule, verification, execution, options)
1721
1987
  ...options.responsePayload ? { response_payload_hash: hashPayload(options.responsePayload) } : {}
1722
1988
  };
1723
1989
  }
1724
- function extractVerificationState(metadata) {
1725
- return {
1726
- clientSigVerified: metadata.cceClientSigVerified === true,
1727
- capsuleSigVerified: metadata.cceCapsuleVerified === true,
1728
- tpsValid: metadata.cceTpsValid === true,
1729
- audienceMatch: metadata.cceBindingVerified === true,
1730
- intentMatch: metadata.cceBindingVerified === true,
1731
- replayClean: metadata.cceReplayClean === true,
1732
- nonceUnique: metadata.cceReplayClean === true,
1733
- decryptionOk: metadata.cceDecryptionOk === true
1734
- };
1735
- }
1736
- function generateWitnessId(requestId, capsuleId) {
1737
- const input = `witness:${requestId}:${capsuleId}:${Date.now()}`;
1738
- const hash = (0, import_sha23.sha256)(new TextEncoder().encode(input));
1739
- return "wit_" + (0, import_utils4.bytesToHex)(hash).slice(0, 24);
1740
- }
1741
- function computeExecutionContextHash(axisLocalSecret, capsule, requestNonce) {
1742
- const encoder = new TextEncoder();
1743
- const ikm = hexToBytes2(axisLocalSecret);
1744
- const salt = (0, import_sha23.sha256)(
1745
- encoder.encode(
1746
- capsule.capsule_id + "|" + capsule.capsule_nonce + "|" + requestNonce
1747
- )
1748
- );
1749
- const info = encoder.encode(
1750
- [
1751
- CCE_DERIVATION.WITNESS,
1752
- capsule.sub,
1753
- capsule.kid,
1754
- capsule.intent,
1755
- capsule.aud,
1756
- String(capsule.tps_from),
1757
- String(capsule.tps_to),
1758
- capsule.policy_hash ?? "",
1759
- capsule.ver
1760
- ].join("|")
1761
- );
1762
- const witnessKey = (0, import_hkdf2.hkdf)(import_sha23.sha256, ikm, salt, info, 32);
1763
- const hash = (0, import_utils4.bytesToHex)((0, import_sha23.sha256)(witnessKey));
1764
- witnessKey.fill(0);
1765
- return hash;
1766
- }
1767
- function hexToBytes2(hex) {
1768
- const bytes2 = new Uint8Array(hex.length / 2);
1769
- for (let i = 0; i < bytes2.length; i++) {
1770
- bytes2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
1771
- }
1772
- return bytes2;
1773
- }
1774
- var import_utils4, import_hkdf2, import_sha23;
1775
- var init_cce_witness_observer = __esm({
1776
- "src/cce/cce-witness.observer.ts"() {
1777
- import_utils4 = require("@noble/hashes/utils.js");
1778
- import_hkdf2 = require("@noble/hashes/hkdf.js");
1779
- import_sha23 = require("@noble/hashes/sha2.js");
1780
- init_cce_crypto();
1781
- init_cce_types();
1782
- }
1783
- });
1784
-
1785
- // src/sensor/axis-sensor.ts
1786
- function normalizeSensorDecision(sensorDecision) {
1787
- if ("action" in sensorDecision) {
1788
- switch (sensorDecision.action) {
1789
- case "ALLOW":
1790
- return {
1791
- allow: true,
1792
- riskScore: 0,
1793
- reasons: [],
1794
- meta: sensorDecision.meta
1795
- };
1796
- case "DENY":
1797
- return {
1798
- allow: false,
1799
- riskScore: 100,
1800
- reasons: [sensorDecision.code, sensorDecision.reason].filter(
1801
- Boolean
1802
- ),
1803
- meta: sensorDecision.meta,
1804
- retryAfterMs: sensorDecision.retryAfterMs
1805
- };
1806
- case "THROTTLE":
1807
- return {
1808
- allow: false,
1809
- riskScore: 50,
1810
- reasons: ["RATE_LIMIT"],
1811
- retryAfterMs: sensorDecision.retryAfterMs,
1812
- meta: sensorDecision.meta
1813
- };
1814
- case "FLAG":
1815
- return {
1816
- allow: true,
1817
- riskScore: sensorDecision.scoreDelta,
1818
- reasons: sensorDecision.reasons,
1819
- meta: sensorDecision.meta
1820
- };
1821
- }
1822
- }
1823
- return {
1824
- allow: sensorDecision.allow,
1825
- riskScore: sensorDecision.riskScore,
1826
- reasons: sensorDecision.reasons,
1827
- tags: sensorDecision.tags,
1828
- meta: sensorDecision.meta,
1829
- tighten: sensorDecision.tighten,
1830
- retryAfterMs: sensorDecision.retryAfterMs
1831
- };
1832
- }
1833
- var Decision, SensorDecisions;
1834
- var init_axis_sensor = __esm({
1835
- "src/sensor/axis-sensor.ts"() {
1836
- Decision = /* @__PURE__ */ ((Decision2) => {
1837
- Decision2["ALLOW"] = "ALLOW";
1838
- Decision2["DENY"] = "DENY";
1839
- Decision2["THROTTLE"] = "THROTTLE";
1840
- Decision2["FLAG"] = "FLAG";
1841
- return Decision2;
1842
- })(Decision || {});
1843
- SensorDecisions = {
1844
- allow(meta, tags) {
1845
- return {
1846
- decision: "ALLOW" /* ALLOW */,
1847
- allow: true,
1848
- riskScore: 0,
1849
- reasons: [],
1850
- tags,
1851
- meta
1852
- };
1853
- },
1854
- deny(code, reason, meta) {
1855
- return {
1856
- decision: "DENY" /* DENY */,
1857
- allow: false,
1858
- riskScore: 100,
1859
- code,
1860
- reasons: [code, reason].filter(Boolean),
1861
- meta
1862
- };
1863
- },
1864
- throttle(retryAfterMs, meta) {
1865
- return {
1866
- decision: "THROTTLE" /* THROTTLE */,
1867
- allow: false,
1868
- riskScore: 50,
1869
- retryAfterMs,
1870
- code: "RATE_LIMIT",
1871
- reasons: ["RATE_LIMIT"],
1872
- meta
1873
- };
1874
- },
1875
- flag(scoreDelta, reasons, meta) {
1876
- return {
1877
- decision: "FLAG" /* FLAG */,
1878
- allow: true,
1879
- riskScore: scoreDelta,
1880
- scoreDelta,
1881
- reasons,
1882
- meta
1883
- };
1884
- }
1885
- };
1990
+ function extractVerificationState(metadata) {
1991
+ return {
1992
+ clientSigVerified: metadata.cceClientSigVerified === true,
1993
+ capsuleSigVerified: metadata.cceCapsuleVerified === true,
1994
+ tpsValid: metadata.cceTpsValid === true,
1995
+ audienceMatch: metadata.cceBindingVerified === true,
1996
+ intentMatch: metadata.cceBindingVerified === true,
1997
+ replayClean: metadata.cceReplayClean === true,
1998
+ nonceUnique: metadata.cceReplayClean === true,
1999
+ decryptionOk: metadata.cceDecryptionOk === true
2000
+ };
2001
+ }
2002
+ function generateWitnessId(requestId, capsuleId) {
2003
+ const input = `witness:${requestId}:${capsuleId}:${Date.now()}`;
2004
+ const hash = (0, import_sha23.sha256)(new TextEncoder().encode(input));
2005
+ return "wit_" + (0, import_utils4.bytesToHex)(hash).slice(0, 24);
2006
+ }
2007
+ function computeExecutionContextHash(axisLocalSecret, capsule, requestNonce) {
2008
+ const encoder = new TextEncoder();
2009
+ const ikm = hexToBytes2(axisLocalSecret);
2010
+ const salt = (0, import_sha23.sha256)(
2011
+ encoder.encode(
2012
+ capsule.capsule_id + "|" + capsule.capsule_nonce + "|" + requestNonce
2013
+ )
2014
+ );
2015
+ const info = encoder.encode(
2016
+ [
2017
+ CCE_DERIVATION.WITNESS,
2018
+ capsule.sub,
2019
+ capsule.kid,
2020
+ capsule.intent,
2021
+ capsule.aud,
2022
+ String(capsule.tps_from),
2023
+ String(capsule.tps_to),
2024
+ capsule.policy_hash ?? "",
2025
+ capsule.ver
2026
+ ].join("|")
2027
+ );
2028
+ const witnessKey = (0, import_hkdf2.hkdf)(import_sha23.sha256, ikm, salt, info, 32);
2029
+ const hash = (0, import_utils4.bytesToHex)((0, import_sha23.sha256)(witnessKey));
2030
+ witnessKey.fill(0);
2031
+ return hash;
2032
+ }
2033
+ function hexToBytes2(hex) {
2034
+ const bytes2 = new Uint8Array(hex.length / 2);
2035
+ for (let i = 0; i < bytes2.length; i++) {
2036
+ bytes2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
2037
+ }
2038
+ return bytes2;
2039
+ }
2040
+ var import_utils4, import_hkdf2, import_sha23;
2041
+ var init_cce_witness_observer = __esm({
2042
+ "src/cce/cce-witness.observer.ts"() {
2043
+ import_utils4 = require("@noble/hashes/utils.js");
2044
+ import_hkdf2 = require("@noble/hashes/hkdf.js");
2045
+ import_sha23 = require("@noble/hashes/sha2.js");
2046
+ init_cce_crypto();
2047
+ init_cce_types();
1886
2048
  }
1887
2049
  });
1888
2050
 
@@ -2134,167 +2296,6 @@ var init_axis_error = __esm({
2134
2296
  }
2135
2297
  });
2136
2298
 
2137
- // src/security/scopes.ts
2138
- function hasScope(scopes, required) {
2139
- if (!Array.isArray(scopes) || scopes.length === 0) {
2140
- return false;
2141
- }
2142
- if (scopes.includes(required)) {
2143
- return true;
2144
- }
2145
- const [resource, id] = required.split(":");
2146
- if (resource && id) {
2147
- const wildcard = `${resource}:*`;
2148
- if (scopes.includes(wildcard)) {
2149
- return true;
2150
- }
2151
- }
2152
- return false;
2153
- }
2154
- function parseScope(scope) {
2155
- const parts = scope.split(":");
2156
- if (parts.length !== 2) return null;
2157
- return { resource: parts[0], id: parts[1] };
2158
- }
2159
- function canAccessResource(scopes, resourceType, resourceId) {
2160
- const required = `${resourceType}:${resourceId}`;
2161
- return hasScope(scopes, required);
2162
- }
2163
- var init_scopes = __esm({
2164
- "src/security/scopes.ts"() {
2165
- }
2166
- });
2167
-
2168
- // src/security/inline-capsule.ts
2169
- function normalizeInlineCapsule(input) {
2170
- if (!input || typeof input !== "object" || Array.isArray(input)) {
2171
- return null;
2172
- }
2173
- const raw = input;
2174
- const scopes = normalizeStringList(raw.scopes ?? raw.scope);
2175
- return {
2176
- id: normalizeScalar(raw.id),
2177
- actorId: normalizeScalar(raw.actorId),
2178
- intents: normalizeStringList(raw.intents),
2179
- issuedAt: normalizeTimestamp(raw.issuedAt ?? raw.iat),
2180
- expiresAt: normalizeTimestamp(raw.expiresAt ?? raw.exp),
2181
- realm: normalizeScalar(raw.realm),
2182
- node: normalizeScalar(raw.node),
2183
- scopes,
2184
- raw
2185
- };
2186
- }
2187
- function inlineCapsuleAllowsIntent(capsule, intent) {
2188
- if (!capsule.intents || capsule.intents.length === 0) {
2189
- return false;
2190
- }
2191
- for (const pattern of capsule.intents) {
2192
- if (pattern === "*" || pattern === intent) {
2193
- return true;
2194
- }
2195
- if (pattern.endsWith(".*")) {
2196
- const prefix = pattern.slice(0, -1);
2197
- if (intent.startsWith(prefix)) {
2198
- return true;
2199
- }
2200
- }
2201
- }
2202
- return false;
2203
- }
2204
- function isInlineCapsuleExpired(capsule, clockSkewMs = 3e4) {
2205
- if (capsule.expiresAt === void 0) {
2206
- return false;
2207
- }
2208
- return BigInt(Date.now()) > capsule.expiresAt + BigInt(clockSkewMs);
2209
- }
2210
- function resolvePolicyScopes(scopes, context) {
2211
- return scopes.map(
2212
- (scope) => scope.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
2213
- const resolved = resolveTemplateExpression(expression.trim(), context);
2214
- if (resolved === void 0 || resolved === null || resolved === "") {
2215
- throw new Error(`CAPSULE_SCOPE_TEMPLATE_UNRESOLVED:${expression}`);
2216
- }
2217
- return String(resolved);
2218
- })
2219
- );
2220
- }
2221
- function inlineCapsuleSatisfiesScopes(capsule, requiredScopes, mode = "all") {
2222
- if (!capsule.scopes || capsule.scopes.length === 0) {
2223
- return false;
2224
- }
2225
- if (mode === "any") {
2226
- return requiredScopes.some((scope) => hasScope(capsule.scopes, scope));
2227
- }
2228
- return requiredScopes.every((scope) => hasScope(capsule.scopes, scope));
2229
- }
2230
- function resolveTemplateExpression(expression, context) {
2231
- if (expression === "intent") {
2232
- return context.intent;
2233
- }
2234
- if (expression === "actorId") {
2235
- return context.actorId;
2236
- }
2237
- if (expression === "chainId") {
2238
- return context.chainId;
2239
- }
2240
- if (expression === "stepId") {
2241
- return context.stepId;
2242
- }
2243
- if (expression.startsWith("body.")) {
2244
- return getNestedValue(context.body, expression.slice(5));
2245
- }
2246
- return void 0;
2247
- }
2248
- function getNestedValue(value, path2) {
2249
- if (!value || typeof value !== "object") {
2250
- return void 0;
2251
- }
2252
- return path2.split(".").reduce((current, segment) => {
2253
- if (!current || typeof current !== "object") {
2254
- return void 0;
2255
- }
2256
- return current[segment];
2257
- }, value);
2258
- }
2259
- function normalizeScalar(value) {
2260
- if (typeof value === "string") {
2261
- return value;
2262
- }
2263
- if (value instanceof Uint8Array) {
2264
- return Buffer.from(value).toString("hex");
2265
- }
2266
- return void 0;
2267
- }
2268
- function normalizeStringList(value) {
2269
- if (!value) {
2270
- return void 0;
2271
- }
2272
- const list = Array.isArray(value) ? value : [value];
2273
- const normalized = list.map((entry) => typeof entry === "string" ? entry : void 0).filter((entry) => !!entry && entry.trim().length > 0);
2274
- return normalized.length > 0 ? Array.from(new Set(normalized)) : void 0;
2275
- }
2276
- function normalizeTimestamp(value) {
2277
- if (typeof value === "bigint") {
2278
- return value;
2279
- }
2280
- if (typeof value === "number" && Number.isFinite(value)) {
2281
- return BigInt(Math.trunc(value));
2282
- }
2283
- if (typeof value === "string" && value.trim().length > 0) {
2284
- try {
2285
- return BigInt(value);
2286
- } catch {
2287
- return void 0;
2288
- }
2289
- }
2290
- return void 0;
2291
- }
2292
- var init_inline_capsule = __esm({
2293
- "src/security/inline-capsule.ts"() {
2294
- init_scopes();
2295
- }
2296
- });
2297
-
2298
2299
  // src/engine/intent.router.ts
2299
2300
  var intent_router_exports = {};
2300
2301
  __export(intent_router_exports, {
@@ -2368,23 +2369,23 @@ var import_axis_protocol3, import_dto_schema, _IntentRouter, IntentRouter;
2368
2369
  var init_intent_router = __esm({
2369
2370
  "src/engine/intent.router.ts"() {
2370
2371
  import_axis_protocol3 = require("@nextera.one/axis-protocol");
2371
- init_cce_pipeline();
2372
- init_axis_error();
2373
- init_constants();
2374
- init_capsule_policy_decorator();
2375
- init_chain_decorator();
2376
- import_dto_schema = __toESM(require_dto_schema_util());
2377
2372
  init_handler_sensors_decorator();
2378
- init_handler_decorator();
2379
- init_intent_body_decorator();
2380
- init_intent_policy_decorator();
2373
+ init_capsule_policy_decorator();
2381
2374
  init_intent_sensors_decorator();
2382
- init_intent_decorator();
2375
+ init_intent_policy_decorator();
2376
+ init_intent_body_decorator();
2383
2377
  init_observer_decorator();
2378
+ init_handler_decorator();
2379
+ init_intent_decorator();
2380
+ init_chain_decorator();
2381
+ import_dto_schema = __toESM(require_dto_schema_util());
2384
2382
  init_inline_capsule();
2385
- init_axis_sensor();
2386
2383
  init_axis_execution_context();
2384
+ init_axis_sensor();
2387
2385
  init_axis_logger();
2386
+ init_cce_pipeline();
2387
+ init_axis_error();
2388
+ init_constants();
2388
2389
  _IntentRouter = class _IntentRouter {
2389
2390
  constructor(dependencyResolver, observerDispatcher, sensorRegistry) {
2390
2391
  this.logger = createAxisLogger(_IntentRouter.name);
@@ -2420,6 +2421,8 @@ var init_intent_router = __esm({
2420
2421
  this.publicIntents = /* @__PURE__ */ new Set();
2421
2422
  /** Intents flagged as anonymous-session accessible */
2422
2423
  this.anonymousIntents = /* @__PURE__ */ new Set();
2424
+ /** Intents flagged as authorized-session accessible */
2425
+ this.authorizedIntents = /* @__PURE__ */ new Set();
2423
2426
  /** Per-intent rate limit config */
2424
2427
  this.intentRateLimits = /* @__PURE__ */ new Map();
2425
2428
  /** CCE handler registry */
@@ -2846,6 +2849,18 @@ var init_intent_router = __esm({
2846
2849
  if (isAnonMethod || isAnonClass) {
2847
2850
  this.anonymousIntents.add(intent);
2848
2851
  }
2852
+ const isAuthorizedMethod = Reflect.getMetadata(
2853
+ AXIS_AUTHORIZED_KEY,
2854
+ proto,
2855
+ methodName
2856
+ );
2857
+ const isAuthorizedClass = Reflect.getMetadata(
2858
+ AXIS_AUTHORIZED_KEY,
2859
+ proto.constructor
2860
+ );
2861
+ if (isAuthorizedMethod || isAuthorizedClass) {
2862
+ this.authorizedIntents.add(intent);
2863
+ }
2849
2864
  const rateLimit = Reflect.getMetadata(
2850
2865
  AXIS_RATE_LIMIT_KEY,
2851
2866
  proto,
@@ -2871,6 +2886,9 @@ var init_intent_router = __esm({
2871
2886
  isAnonymous(intent) {
2872
2887
  return this.anonymousIntents.has(intent);
2873
2888
  }
2889
+ isAuthorized(intent) {
2890
+ return this.authorizedIntents.has(intent);
2891
+ }
2874
2892
  getRateLimit(intent) {
2875
2893
  return this.intentRateLimits.get(intent);
2876
2894
  }
@@ -10661,15 +10679,52 @@ var require_chunk_hash_sensor = __commonJS({
10661
10679
  var require_entropy_sensor = __commonJS({
10662
10680
  "src/sensors/entropy.sensor.ts"(exports2) {
10663
10681
  "use strict";
10682
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
10683
+ if (k2 === void 0) k2 = k;
10684
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10685
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10686
+ desc = { enumerable: true, get: function() {
10687
+ return m[k];
10688
+ } };
10689
+ }
10690
+ Object.defineProperty(o, k2, desc);
10691
+ }) : (function(o, m, k, k2) {
10692
+ if (k2 === void 0) k2 = k;
10693
+ o[k2] = m[k];
10694
+ }));
10695
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
10696
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
10697
+ }) : function(o, v) {
10698
+ o["default"] = v;
10699
+ });
10664
10700
  var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
10665
10701
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10666
10702
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10667
10703
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10668
10704
  return c > 3 && r && Object.defineProperty(target, key, r), r;
10669
10705
  };
10706
+ var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
10707
+ var ownKeys = function(o) {
10708
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
10709
+ var ar = [];
10710
+ for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
10711
+ return ar;
10712
+ };
10713
+ return ownKeys(o);
10714
+ };
10715
+ return function(mod) {
10716
+ if (mod && mod.__esModule) return mod;
10717
+ var result = {};
10718
+ if (mod != null) {
10719
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
10720
+ }
10721
+ __setModuleDefault(result, mod);
10722
+ return result;
10723
+ };
10724
+ })();
10670
10725
  Object.defineProperty(exports2, "__esModule", { value: true });
10671
10726
  exports2.EntropySensor = void 0;
10672
- var crypto4 = require("crypto");
10727
+ var crypto4 = __importStar(require("crypto"));
10673
10728
  var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
10674
10729
  var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
10675
10730
  var constants_1 = (init_constants(), __toCommonJS(constants_exports));
@@ -11348,10 +11403,15 @@ var init_axis_schemas = __esm({
11348
11403
  ScanBurstDecisionZ = SensorDecisionWithMetadataZ;
11349
11404
  ProofKindZ = z2.enum([
11350
11405
  "NONE",
11351
- "CAPSULE",
11406
+ "ANONYMOUS",
11352
11407
  "PASSPORT",
11408
+ "CAPSULE",
11409
+ "JWT",
11410
+ "CONTRACT",
11411
+ "WITNESS",
11353
11412
  "MTLS",
11354
- "JWT"
11413
+ "DEVICE",
11414
+ "AUTHORIZED"
11355
11415
  ]);
11356
11416
  AccessProfileZ = z2.enum(["PUBLIC", "PARTNER", "INTERNAL", "NODE"]);
11357
11417
  ProofPresenceInputZ = z2.object({
@@ -11473,7 +11533,10 @@ var init_axis_schemas = __esm({
11473
11533
  ip: z2.string().min(1)
11474
11534
  });
11475
11535
  ProtocolStrictInputZ = z2.object({
11476
- rawBytes: z2.union([z2.custom((v) => Buffer.isBuffer(v)), z2.instanceof(Uint8Array)]).optional(),
11536
+ rawBytes: z2.union([
11537
+ z2.custom((v) => Buffer.isBuffer(v)),
11538
+ z2.instanceof(Uint8Array)
11539
+ ]).optional(),
11477
11540
  ip: z2.string().min(1),
11478
11541
  path: z2.string().min(1),
11479
11542
  contentLength: z2.number().int().nonnegative(),