@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.
@@ -516,7 +516,7 @@ function AxisRateLimit(config) {
516
516
  return descriptor;
517
517
  };
518
518
  }
519
- var import_reflect_metadata4, AXIS_META_KEY, SENSITIVITY_METADATA_KEY, CONTRACT_METADATA_KEY, REQUIRED_PROOF_METADATA_KEY, AXIS_PUBLIC_KEY, AXIS_ANONYMOUS_KEY, AXIS_RATE_LIMIT_KEY;
519
+ var import_reflect_metadata4, 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;
520
520
  var init_intent_policy_decorator = __esm({
521
521
  "src/decorators/intent-policy.decorator.ts"() {
522
522
  import_reflect_metadata4 = require("reflect-metadata");
@@ -526,6 +526,7 @@ var init_intent_policy_decorator = __esm({
526
526
  REQUIRED_PROOF_METADATA_KEY = "axis:required_proof";
527
527
  AXIS_PUBLIC_KEY = "axis:public";
528
528
  AXIS_ANONYMOUS_KEY = "axis:anonymous";
529
+ AXIS_AUTHORIZED_KEY = "axis:authorized";
529
530
  AXIS_RATE_LIMIT_KEY = "axis:rateLimit";
530
531
  }
531
532
  });
@@ -1545,6 +1546,271 @@ var init_axis_chain_executor = __esm({
1545
1546
  }
1546
1547
  });
1547
1548
 
1549
+ // src/security/scopes.ts
1550
+ function hasScope(scopes, required) {
1551
+ if (!Array.isArray(scopes) || scopes.length === 0) {
1552
+ return false;
1553
+ }
1554
+ if (scopes.includes(required)) {
1555
+ return true;
1556
+ }
1557
+ const [resource, id] = required.split(":");
1558
+ if (resource && id) {
1559
+ const wildcard = `${resource}:*`;
1560
+ if (scopes.includes(wildcard)) {
1561
+ return true;
1562
+ }
1563
+ }
1564
+ return false;
1565
+ }
1566
+ function parseScope(scope) {
1567
+ const parts = scope.split(":");
1568
+ if (parts.length !== 2) return null;
1569
+ return { resource: parts[0], id: parts[1] };
1570
+ }
1571
+ function canAccessResource(scopes, resourceType, resourceId) {
1572
+ const required = `${resourceType}:${resourceId}`;
1573
+ return hasScope(scopes, required);
1574
+ }
1575
+ var init_scopes = __esm({
1576
+ "src/security/scopes.ts"() {
1577
+ }
1578
+ });
1579
+
1580
+ // src/security/inline-capsule.ts
1581
+ function normalizeInlineCapsule(input) {
1582
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
1583
+ return null;
1584
+ }
1585
+ const raw = input;
1586
+ const scopes = normalizeStringList(raw.scopes ?? raw.scope);
1587
+ return {
1588
+ id: normalizeScalar(raw.id),
1589
+ actorId: normalizeScalar(raw.actorId),
1590
+ intents: normalizeStringList(raw.intents),
1591
+ issuedAt: normalizeTimestamp(raw.issuedAt ?? raw.iat),
1592
+ expiresAt: normalizeTimestamp(raw.expiresAt ?? raw.exp),
1593
+ realm: normalizeScalar(raw.realm),
1594
+ node: normalizeScalar(raw.node),
1595
+ scopes,
1596
+ raw
1597
+ };
1598
+ }
1599
+ function inlineCapsuleAllowsIntent(capsule, intent) {
1600
+ if (!capsule.intents || capsule.intents.length === 0) {
1601
+ return false;
1602
+ }
1603
+ for (const pattern of capsule.intents) {
1604
+ if (pattern === "*" || pattern === intent) {
1605
+ return true;
1606
+ }
1607
+ if (pattern.endsWith(".*")) {
1608
+ const prefix = pattern.slice(0, -1);
1609
+ if (intent.startsWith(prefix)) {
1610
+ return true;
1611
+ }
1612
+ }
1613
+ }
1614
+ return false;
1615
+ }
1616
+ function isInlineCapsuleExpired(capsule, clockSkewMs = 3e4) {
1617
+ if (capsule.expiresAt === void 0) {
1618
+ return false;
1619
+ }
1620
+ return BigInt(Date.now()) > capsule.expiresAt + BigInt(clockSkewMs);
1621
+ }
1622
+ function resolvePolicyScopes(scopes, context) {
1623
+ return scopes.map(
1624
+ (scope) => scope.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
1625
+ const resolved = resolveTemplateExpression(expression.trim(), context);
1626
+ if (resolved === void 0 || resolved === null || resolved === "") {
1627
+ throw new Error(`CAPSULE_SCOPE_TEMPLATE_UNRESOLVED:${expression}`);
1628
+ }
1629
+ return String(resolved);
1630
+ })
1631
+ );
1632
+ }
1633
+ function inlineCapsuleSatisfiesScopes(capsule, requiredScopes, mode = "all") {
1634
+ if (!capsule.scopes || capsule.scopes.length === 0) {
1635
+ return false;
1636
+ }
1637
+ if (mode === "any") {
1638
+ return requiredScopes.some((scope) => hasScope(capsule.scopes, scope));
1639
+ }
1640
+ return requiredScopes.every((scope) => hasScope(capsule.scopes, scope));
1641
+ }
1642
+ function resolveTemplateExpression(expression, context) {
1643
+ if (expression === "intent") {
1644
+ return context.intent;
1645
+ }
1646
+ if (expression === "actorId") {
1647
+ return context.actorId;
1648
+ }
1649
+ if (expression === "chainId") {
1650
+ return context.chainId;
1651
+ }
1652
+ if (expression === "stepId") {
1653
+ return context.stepId;
1654
+ }
1655
+ if (expression.startsWith("body.")) {
1656
+ return getNestedValue(context.body, expression.slice(5));
1657
+ }
1658
+ return void 0;
1659
+ }
1660
+ function getNestedValue(value, path2) {
1661
+ if (!value || typeof value !== "object") {
1662
+ return void 0;
1663
+ }
1664
+ return path2.split(".").reduce((current, segment) => {
1665
+ if (!current || typeof current !== "object") {
1666
+ return void 0;
1667
+ }
1668
+ return current[segment];
1669
+ }, value);
1670
+ }
1671
+ function normalizeScalar(value) {
1672
+ if (typeof value === "string") {
1673
+ return value;
1674
+ }
1675
+ if (value instanceof Uint8Array) {
1676
+ return Buffer.from(value).toString("hex");
1677
+ }
1678
+ return void 0;
1679
+ }
1680
+ function normalizeStringList(value) {
1681
+ if (!value) {
1682
+ return void 0;
1683
+ }
1684
+ const list = Array.isArray(value) ? value : [value];
1685
+ const normalized = list.map((entry) => typeof entry === "string" ? entry : void 0).filter((entry) => !!entry && entry.trim().length > 0);
1686
+ return normalized.length > 0 ? Array.from(new Set(normalized)) : void 0;
1687
+ }
1688
+ function normalizeTimestamp(value) {
1689
+ if (typeof value === "bigint") {
1690
+ return value;
1691
+ }
1692
+ if (typeof value === "number" && Number.isFinite(value)) {
1693
+ return BigInt(Math.trunc(value));
1694
+ }
1695
+ if (typeof value === "string" && value.trim().length > 0) {
1696
+ try {
1697
+ return BigInt(value);
1698
+ } catch {
1699
+ return void 0;
1700
+ }
1701
+ }
1702
+ return void 0;
1703
+ }
1704
+ var init_inline_capsule = __esm({
1705
+ "src/security/inline-capsule.ts"() {
1706
+ init_scopes();
1707
+ }
1708
+ });
1709
+
1710
+ // src/sensor/axis-sensor.ts
1711
+ function normalizeSensorDecision(sensorDecision) {
1712
+ if ("action" in sensorDecision) {
1713
+ switch (sensorDecision.action) {
1714
+ case "ALLOW":
1715
+ return {
1716
+ allow: true,
1717
+ riskScore: 0,
1718
+ reasons: [],
1719
+ meta: sensorDecision.meta
1720
+ };
1721
+ case "DENY":
1722
+ return {
1723
+ allow: false,
1724
+ riskScore: 100,
1725
+ reasons: [sensorDecision.code, sensorDecision.reason].filter(
1726
+ Boolean
1727
+ ),
1728
+ meta: sensorDecision.meta,
1729
+ retryAfterMs: sensorDecision.retryAfterMs
1730
+ };
1731
+ case "THROTTLE":
1732
+ return {
1733
+ allow: false,
1734
+ riskScore: 50,
1735
+ reasons: ["RATE_LIMIT"],
1736
+ retryAfterMs: sensorDecision.retryAfterMs,
1737
+ meta: sensorDecision.meta
1738
+ };
1739
+ case "FLAG":
1740
+ return {
1741
+ allow: true,
1742
+ riskScore: sensorDecision.scoreDelta,
1743
+ reasons: sensorDecision.reasons,
1744
+ meta: sensorDecision.meta
1745
+ };
1746
+ }
1747
+ }
1748
+ return {
1749
+ allow: sensorDecision.allow,
1750
+ riskScore: sensorDecision.riskScore,
1751
+ reasons: sensorDecision.reasons,
1752
+ tags: sensorDecision.tags,
1753
+ meta: sensorDecision.meta,
1754
+ tighten: sensorDecision.tighten,
1755
+ retryAfterMs: sensorDecision.retryAfterMs
1756
+ };
1757
+ }
1758
+ var Decision, SensorDecisions;
1759
+ var init_axis_sensor = __esm({
1760
+ "src/sensor/axis-sensor.ts"() {
1761
+ Decision = /* @__PURE__ */ ((Decision2) => {
1762
+ Decision2["ALLOW"] = "ALLOW";
1763
+ Decision2["DENY"] = "DENY";
1764
+ Decision2["THROTTLE"] = "THROTTLE";
1765
+ Decision2["FLAG"] = "FLAG";
1766
+ return Decision2;
1767
+ })(Decision || {});
1768
+ SensorDecisions = {
1769
+ allow(meta, tags) {
1770
+ return {
1771
+ decision: "ALLOW" /* ALLOW */,
1772
+ allow: true,
1773
+ riskScore: 0,
1774
+ reasons: [],
1775
+ tags,
1776
+ meta
1777
+ };
1778
+ },
1779
+ deny(code, reason, meta) {
1780
+ return {
1781
+ decision: "DENY" /* DENY */,
1782
+ allow: false,
1783
+ riskScore: 100,
1784
+ code,
1785
+ reasons: [code, reason].filter(Boolean),
1786
+ meta
1787
+ };
1788
+ },
1789
+ throttle(retryAfterMs, meta) {
1790
+ return {
1791
+ decision: "THROTTLE" /* THROTTLE */,
1792
+ allow: false,
1793
+ riskScore: 50,
1794
+ retryAfterMs,
1795
+ code: "RATE_LIMIT",
1796
+ reasons: ["RATE_LIMIT"],
1797
+ meta
1798
+ };
1799
+ },
1800
+ flag(scoreDelta, reasons, meta) {
1801
+ return {
1802
+ decision: "FLAG" /* FLAG */,
1803
+ allow: true,
1804
+ riskScore: scoreDelta,
1805
+ scoreDelta,
1806
+ reasons,
1807
+ meta
1808
+ };
1809
+ }
1810
+ };
1811
+ }
1812
+ });
1813
+
1548
1814
  // src/cce/cce.types.ts
1549
1815
  var CCE_PROTOCOL_VERSION, CCE_DERIVATION, CCE_AES_KEY_BYTES, CCE_IV_BYTES, CCE_NONCE_BYTES, CCE_ERROR, CceError;
1550
1816
  var init_cce_types = __esm({
@@ -1870,168 +2136,64 @@ function buildWitnessRecord(envelope, capsule, verification, execution, options)
1870
2136
  ...options.responsePayload ? { response_payload_hash: hashPayload(options.responsePayload) } : {}
1871
2137
  };
1872
2138
  }
1873
- function extractVerificationState(metadata) {
1874
- return {
1875
- clientSigVerified: metadata.cceClientSigVerified === true,
1876
- capsuleSigVerified: metadata.cceCapsuleVerified === true,
1877
- tpsValid: metadata.cceTpsValid === true,
1878
- audienceMatch: metadata.cceBindingVerified === true,
1879
- intentMatch: metadata.cceBindingVerified === true,
1880
- replayClean: metadata.cceReplayClean === true,
1881
- nonceUnique: metadata.cceReplayClean === true,
1882
- decryptionOk: metadata.cceDecryptionOk === true
1883
- };
1884
- }
1885
- function generateWitnessId(requestId, capsuleId) {
1886
- const input = `witness:${requestId}:${capsuleId}:${Date.now()}`;
1887
- const hash = (0, import_sha23.sha256)(new TextEncoder().encode(input));
1888
- return "wit_" + (0, import_utils4.bytesToHex)(hash).slice(0, 24);
1889
- }
1890
- function computeExecutionContextHash(axisLocalSecret, capsule, requestNonce) {
1891
- const encoder = new TextEncoder();
1892
- const ikm = hexToBytes2(axisLocalSecret);
1893
- const salt = (0, import_sha23.sha256)(
1894
- encoder.encode(
1895
- capsule.capsule_id + "|" + capsule.capsule_nonce + "|" + requestNonce
1896
- )
1897
- );
1898
- const info = encoder.encode(
1899
- [
1900
- CCE_DERIVATION.WITNESS,
1901
- capsule.sub,
1902
- capsule.kid,
1903
- capsule.intent,
1904
- capsule.aud,
1905
- String(capsule.tps_from),
1906
- String(capsule.tps_to),
1907
- capsule.policy_hash ?? "",
1908
- capsule.ver
1909
- ].join("|")
1910
- );
1911
- const witnessKey = (0, import_hkdf2.hkdf)(import_sha23.sha256, ikm, salt, info, 32);
1912
- const hash = (0, import_utils4.bytesToHex)((0, import_sha23.sha256)(witnessKey));
1913
- witnessKey.fill(0);
1914
- return hash;
1915
- }
1916
- function hexToBytes2(hex) {
1917
- const bytes2 = new Uint8Array(hex.length / 2);
1918
- for (let i = 0; i < bytes2.length; i++) {
1919
- bytes2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
1920
- }
1921
- return bytes2;
1922
- }
1923
- var import_utils4, import_hkdf2, import_sha23;
1924
- var init_cce_witness_observer = __esm({
1925
- "src/cce/cce-witness.observer.ts"() {
1926
- import_utils4 = require("@noble/hashes/utils.js");
1927
- import_hkdf2 = require("@noble/hashes/hkdf.js");
1928
- import_sha23 = require("@noble/hashes/sha2.js");
1929
- init_cce_crypto();
1930
- init_cce_types();
1931
- }
1932
- });
1933
-
1934
- // src/sensor/axis-sensor.ts
1935
- function normalizeSensorDecision(sensorDecision) {
1936
- if ("action" in sensorDecision) {
1937
- switch (sensorDecision.action) {
1938
- case "ALLOW":
1939
- return {
1940
- allow: true,
1941
- riskScore: 0,
1942
- reasons: [],
1943
- meta: sensorDecision.meta
1944
- };
1945
- case "DENY":
1946
- return {
1947
- allow: false,
1948
- riskScore: 100,
1949
- reasons: [sensorDecision.code, sensorDecision.reason].filter(
1950
- Boolean
1951
- ),
1952
- meta: sensorDecision.meta,
1953
- retryAfterMs: sensorDecision.retryAfterMs
1954
- };
1955
- case "THROTTLE":
1956
- return {
1957
- allow: false,
1958
- riskScore: 50,
1959
- reasons: ["RATE_LIMIT"],
1960
- retryAfterMs: sensorDecision.retryAfterMs,
1961
- meta: sensorDecision.meta
1962
- };
1963
- case "FLAG":
1964
- return {
1965
- allow: true,
1966
- riskScore: sensorDecision.scoreDelta,
1967
- reasons: sensorDecision.reasons,
1968
- meta: sensorDecision.meta
1969
- };
1970
- }
1971
- }
1972
- return {
1973
- allow: sensorDecision.allow,
1974
- riskScore: sensorDecision.riskScore,
1975
- reasons: sensorDecision.reasons,
1976
- tags: sensorDecision.tags,
1977
- meta: sensorDecision.meta,
1978
- tighten: sensorDecision.tighten,
1979
- retryAfterMs: sensorDecision.retryAfterMs
1980
- };
1981
- }
1982
- var Decision, SensorDecisions;
1983
- var init_axis_sensor = __esm({
1984
- "src/sensor/axis-sensor.ts"() {
1985
- Decision = /* @__PURE__ */ ((Decision2) => {
1986
- Decision2["ALLOW"] = "ALLOW";
1987
- Decision2["DENY"] = "DENY";
1988
- Decision2["THROTTLE"] = "THROTTLE";
1989
- Decision2["FLAG"] = "FLAG";
1990
- return Decision2;
1991
- })(Decision || {});
1992
- SensorDecisions = {
1993
- allow(meta, tags) {
1994
- return {
1995
- decision: "ALLOW" /* ALLOW */,
1996
- allow: true,
1997
- riskScore: 0,
1998
- reasons: [],
1999
- tags,
2000
- meta
2001
- };
2002
- },
2003
- deny(code, reason, meta) {
2004
- return {
2005
- decision: "DENY" /* DENY */,
2006
- allow: false,
2007
- riskScore: 100,
2008
- code,
2009
- reasons: [code, reason].filter(Boolean),
2010
- meta
2011
- };
2012
- },
2013
- throttle(retryAfterMs, meta) {
2014
- return {
2015
- decision: "THROTTLE" /* THROTTLE */,
2016
- allow: false,
2017
- riskScore: 50,
2018
- retryAfterMs,
2019
- code: "RATE_LIMIT",
2020
- reasons: ["RATE_LIMIT"],
2021
- meta
2022
- };
2023
- },
2024
- flag(scoreDelta, reasons, meta) {
2025
- return {
2026
- decision: "FLAG" /* FLAG */,
2027
- allow: true,
2028
- riskScore: scoreDelta,
2029
- scoreDelta,
2030
- reasons,
2031
- meta
2032
- };
2033
- }
2034
- };
2139
+ function extractVerificationState(metadata) {
2140
+ return {
2141
+ clientSigVerified: metadata.cceClientSigVerified === true,
2142
+ capsuleSigVerified: metadata.cceCapsuleVerified === true,
2143
+ tpsValid: metadata.cceTpsValid === true,
2144
+ audienceMatch: metadata.cceBindingVerified === true,
2145
+ intentMatch: metadata.cceBindingVerified === true,
2146
+ replayClean: metadata.cceReplayClean === true,
2147
+ nonceUnique: metadata.cceReplayClean === true,
2148
+ decryptionOk: metadata.cceDecryptionOk === true
2149
+ };
2150
+ }
2151
+ function generateWitnessId(requestId, capsuleId) {
2152
+ const input = `witness:${requestId}:${capsuleId}:${Date.now()}`;
2153
+ const hash = (0, import_sha23.sha256)(new TextEncoder().encode(input));
2154
+ return "wit_" + (0, import_utils4.bytesToHex)(hash).slice(0, 24);
2155
+ }
2156
+ function computeExecutionContextHash(axisLocalSecret, capsule, requestNonce) {
2157
+ const encoder = new TextEncoder();
2158
+ const ikm = hexToBytes2(axisLocalSecret);
2159
+ const salt = (0, import_sha23.sha256)(
2160
+ encoder.encode(
2161
+ capsule.capsule_id + "|" + capsule.capsule_nonce + "|" + requestNonce
2162
+ )
2163
+ );
2164
+ const info = encoder.encode(
2165
+ [
2166
+ CCE_DERIVATION.WITNESS,
2167
+ capsule.sub,
2168
+ capsule.kid,
2169
+ capsule.intent,
2170
+ capsule.aud,
2171
+ String(capsule.tps_from),
2172
+ String(capsule.tps_to),
2173
+ capsule.policy_hash ?? "",
2174
+ capsule.ver
2175
+ ].join("|")
2176
+ );
2177
+ const witnessKey = (0, import_hkdf2.hkdf)(import_sha23.sha256, ikm, salt, info, 32);
2178
+ const hash = (0, import_utils4.bytesToHex)((0, import_sha23.sha256)(witnessKey));
2179
+ witnessKey.fill(0);
2180
+ return hash;
2181
+ }
2182
+ function hexToBytes2(hex) {
2183
+ const bytes2 = new Uint8Array(hex.length / 2);
2184
+ for (let i = 0; i < bytes2.length; i++) {
2185
+ bytes2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
2186
+ }
2187
+ return bytes2;
2188
+ }
2189
+ var import_utils4, import_hkdf2, import_sha23;
2190
+ var init_cce_witness_observer = __esm({
2191
+ "src/cce/cce-witness.observer.ts"() {
2192
+ import_utils4 = require("@noble/hashes/utils.js");
2193
+ import_hkdf2 = require("@noble/hashes/hkdf.js");
2194
+ import_sha23 = require("@noble/hashes/sha2.js");
2195
+ init_cce_crypto();
2196
+ init_cce_types();
2035
2197
  }
2036
2198
  });
2037
2199
 
@@ -2283,167 +2445,6 @@ var init_axis_error = __esm({
2283
2445
  }
2284
2446
  });
2285
2447
 
2286
- // src/security/scopes.ts
2287
- function hasScope(scopes, required) {
2288
- if (!Array.isArray(scopes) || scopes.length === 0) {
2289
- return false;
2290
- }
2291
- if (scopes.includes(required)) {
2292
- return true;
2293
- }
2294
- const [resource, id] = required.split(":");
2295
- if (resource && id) {
2296
- const wildcard = `${resource}:*`;
2297
- if (scopes.includes(wildcard)) {
2298
- return true;
2299
- }
2300
- }
2301
- return false;
2302
- }
2303
- function parseScope(scope) {
2304
- const parts = scope.split(":");
2305
- if (parts.length !== 2) return null;
2306
- return { resource: parts[0], id: parts[1] };
2307
- }
2308
- function canAccessResource(scopes, resourceType, resourceId) {
2309
- const required = `${resourceType}:${resourceId}`;
2310
- return hasScope(scopes, required);
2311
- }
2312
- var init_scopes = __esm({
2313
- "src/security/scopes.ts"() {
2314
- }
2315
- });
2316
-
2317
- // src/security/inline-capsule.ts
2318
- function normalizeInlineCapsule(input) {
2319
- if (!input || typeof input !== "object" || Array.isArray(input)) {
2320
- return null;
2321
- }
2322
- const raw = input;
2323
- const scopes = normalizeStringList(raw.scopes ?? raw.scope);
2324
- return {
2325
- id: normalizeScalar(raw.id),
2326
- actorId: normalizeScalar(raw.actorId),
2327
- intents: normalizeStringList(raw.intents),
2328
- issuedAt: normalizeTimestamp(raw.issuedAt ?? raw.iat),
2329
- expiresAt: normalizeTimestamp(raw.expiresAt ?? raw.exp),
2330
- realm: normalizeScalar(raw.realm),
2331
- node: normalizeScalar(raw.node),
2332
- scopes,
2333
- raw
2334
- };
2335
- }
2336
- function inlineCapsuleAllowsIntent(capsule, intent) {
2337
- if (!capsule.intents || capsule.intents.length === 0) {
2338
- return false;
2339
- }
2340
- for (const pattern of capsule.intents) {
2341
- if (pattern === "*" || pattern === intent) {
2342
- return true;
2343
- }
2344
- if (pattern.endsWith(".*")) {
2345
- const prefix = pattern.slice(0, -1);
2346
- if (intent.startsWith(prefix)) {
2347
- return true;
2348
- }
2349
- }
2350
- }
2351
- return false;
2352
- }
2353
- function isInlineCapsuleExpired(capsule, clockSkewMs = 3e4) {
2354
- if (capsule.expiresAt === void 0) {
2355
- return false;
2356
- }
2357
- return BigInt(Date.now()) > capsule.expiresAt + BigInt(clockSkewMs);
2358
- }
2359
- function resolvePolicyScopes(scopes, context) {
2360
- return scopes.map(
2361
- (scope) => scope.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
2362
- const resolved = resolveTemplateExpression(expression.trim(), context);
2363
- if (resolved === void 0 || resolved === null || resolved === "") {
2364
- throw new Error(`CAPSULE_SCOPE_TEMPLATE_UNRESOLVED:${expression}`);
2365
- }
2366
- return String(resolved);
2367
- })
2368
- );
2369
- }
2370
- function inlineCapsuleSatisfiesScopes(capsule, requiredScopes, mode = "all") {
2371
- if (!capsule.scopes || capsule.scopes.length === 0) {
2372
- return false;
2373
- }
2374
- if (mode === "any") {
2375
- return requiredScopes.some((scope) => hasScope(capsule.scopes, scope));
2376
- }
2377
- return requiredScopes.every((scope) => hasScope(capsule.scopes, scope));
2378
- }
2379
- function resolveTemplateExpression(expression, context) {
2380
- if (expression === "intent") {
2381
- return context.intent;
2382
- }
2383
- if (expression === "actorId") {
2384
- return context.actorId;
2385
- }
2386
- if (expression === "chainId") {
2387
- return context.chainId;
2388
- }
2389
- if (expression === "stepId") {
2390
- return context.stepId;
2391
- }
2392
- if (expression.startsWith("body.")) {
2393
- return getNestedValue(context.body, expression.slice(5));
2394
- }
2395
- return void 0;
2396
- }
2397
- function getNestedValue(value, path2) {
2398
- if (!value || typeof value !== "object") {
2399
- return void 0;
2400
- }
2401
- return path2.split(".").reduce((current, segment) => {
2402
- if (!current || typeof current !== "object") {
2403
- return void 0;
2404
- }
2405
- return current[segment];
2406
- }, value);
2407
- }
2408
- function normalizeScalar(value) {
2409
- if (typeof value === "string") {
2410
- return value;
2411
- }
2412
- if (value instanceof Uint8Array) {
2413
- return Buffer.from(value).toString("hex");
2414
- }
2415
- return void 0;
2416
- }
2417
- function normalizeStringList(value) {
2418
- if (!value) {
2419
- return void 0;
2420
- }
2421
- const list = Array.isArray(value) ? value : [value];
2422
- const normalized = list.map((entry) => typeof entry === "string" ? entry : void 0).filter((entry) => !!entry && entry.trim().length > 0);
2423
- return normalized.length > 0 ? Array.from(new Set(normalized)) : void 0;
2424
- }
2425
- function normalizeTimestamp(value) {
2426
- if (typeof value === "bigint") {
2427
- return value;
2428
- }
2429
- if (typeof value === "number" && Number.isFinite(value)) {
2430
- return BigInt(Math.trunc(value));
2431
- }
2432
- if (typeof value === "string" && value.trim().length > 0) {
2433
- try {
2434
- return BigInt(value);
2435
- } catch {
2436
- return void 0;
2437
- }
2438
- }
2439
- return void 0;
2440
- }
2441
- var init_inline_capsule = __esm({
2442
- "src/security/inline-capsule.ts"() {
2443
- init_scopes();
2444
- }
2445
- });
2446
-
2447
2448
  // src/engine/intent.router.ts
2448
2449
  var intent_router_exports = {};
2449
2450
  __export(intent_router_exports, {
@@ -2517,23 +2518,23 @@ var import_axis_protocol4, import_dto_schema, _IntentRouter, IntentRouter;
2517
2518
  var init_intent_router = __esm({
2518
2519
  "src/engine/intent.router.ts"() {
2519
2520
  import_axis_protocol4 = require("@nextera.one/axis-protocol");
2520
- init_cce_pipeline();
2521
- init_axis_error();
2522
- init_constants();
2523
- init_capsule_policy_decorator();
2524
- init_chain_decorator();
2525
- import_dto_schema = __toESM(require_dto_schema_util());
2526
2521
  init_handler_sensors_decorator();
2527
- init_handler_decorator();
2528
- init_intent_body_decorator();
2529
- init_intent_policy_decorator();
2522
+ init_capsule_policy_decorator();
2530
2523
  init_intent_sensors_decorator();
2531
- init_intent_decorator();
2524
+ init_intent_policy_decorator();
2525
+ init_intent_body_decorator();
2532
2526
  init_observer_decorator();
2527
+ init_handler_decorator();
2528
+ init_intent_decorator();
2529
+ init_chain_decorator();
2530
+ import_dto_schema = __toESM(require_dto_schema_util());
2533
2531
  init_inline_capsule();
2534
- init_axis_sensor();
2535
2532
  init_axis_execution_context();
2533
+ init_axis_sensor();
2536
2534
  init_axis_logger();
2535
+ init_cce_pipeline();
2536
+ init_axis_error();
2537
+ init_constants();
2537
2538
  _IntentRouter = class _IntentRouter {
2538
2539
  constructor(dependencyResolver, observerDispatcher, sensorRegistry) {
2539
2540
  this.logger = createAxisLogger(_IntentRouter.name);
@@ -2569,6 +2570,8 @@ var init_intent_router = __esm({
2569
2570
  this.publicIntents = /* @__PURE__ */ new Set();
2570
2571
  /** Intents flagged as anonymous-session accessible */
2571
2572
  this.anonymousIntents = /* @__PURE__ */ new Set();
2573
+ /** Intents flagged as authorized-session accessible */
2574
+ this.authorizedIntents = /* @__PURE__ */ new Set();
2572
2575
  /** Per-intent rate limit config */
2573
2576
  this.intentRateLimits = /* @__PURE__ */ new Map();
2574
2577
  /** CCE handler registry */
@@ -2995,6 +2998,18 @@ var init_intent_router = __esm({
2995
2998
  if (isAnonMethod || isAnonClass) {
2996
2999
  this.anonymousIntents.add(intent);
2997
3000
  }
3001
+ const isAuthorizedMethod = Reflect.getMetadata(
3002
+ AXIS_AUTHORIZED_KEY,
3003
+ proto,
3004
+ methodName
3005
+ );
3006
+ const isAuthorizedClass = Reflect.getMetadata(
3007
+ AXIS_AUTHORIZED_KEY,
3008
+ proto.constructor
3009
+ );
3010
+ if (isAuthorizedMethod || isAuthorizedClass) {
3011
+ this.authorizedIntents.add(intent);
3012
+ }
2998
3013
  const rateLimit = Reflect.getMetadata(
2999
3014
  AXIS_RATE_LIMIT_KEY,
3000
3015
  proto,
@@ -3020,6 +3035,9 @@ var init_intent_router = __esm({
3020
3035
  isAnonymous(intent) {
3021
3036
  return this.anonymousIntents.has(intent);
3022
3037
  }
3038
+ isAuthorized(intent) {
3039
+ return this.authorizedIntents.has(intent);
3040
+ }
3023
3041
  getRateLimit(intent) {
3024
3042
  return this.intentRateLimits.get(intent);
3025
3043
  }
@@ -11047,15 +11065,52 @@ var require_chunk_hash_sensor = __commonJS({
11047
11065
  var require_entropy_sensor = __commonJS({
11048
11066
  "src/sensors/entropy.sensor.ts"(exports2) {
11049
11067
  "use strict";
11068
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
11069
+ if (k2 === void 0) k2 = k;
11070
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11071
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11072
+ desc = { enumerable: true, get: function() {
11073
+ return m[k];
11074
+ } };
11075
+ }
11076
+ Object.defineProperty(o, k2, desc);
11077
+ }) : (function(o, m, k, k2) {
11078
+ if (k2 === void 0) k2 = k;
11079
+ o[k2] = m[k];
11080
+ }));
11081
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
11082
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11083
+ }) : function(o, v) {
11084
+ o["default"] = v;
11085
+ });
11050
11086
  var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
11051
11087
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11052
11088
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11053
11089
  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;
11054
11090
  return c > 3 && r && Object.defineProperty(target, key, r), r;
11055
11091
  };
11092
+ var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
11093
+ var ownKeys = function(o) {
11094
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
11095
+ var ar = [];
11096
+ for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
11097
+ return ar;
11098
+ };
11099
+ return ownKeys(o);
11100
+ };
11101
+ return function(mod) {
11102
+ if (mod && mod.__esModule) return mod;
11103
+ var result = {};
11104
+ if (mod != null) {
11105
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
11106
+ }
11107
+ __setModuleDefault(result, mod);
11108
+ return result;
11109
+ };
11110
+ })();
11056
11111
  Object.defineProperty(exports2, "__esModule", { value: true });
11057
11112
  exports2.EntropySensor = void 0;
11058
- var crypto4 = require("crypto");
11113
+ var crypto4 = __importStar(require("crypto"));
11059
11114
  var sensor_decorator_1 = (init_sensor_decorator(), __toCommonJS(sensor_decorator_exports));
11060
11115
  var sensor_bands_1 = (init_sensor_bands(), __toCommonJS(sensor_bands_exports));
11061
11116
  var constants_1 = (init_constants(), __toCommonJS(constants_exports));
@@ -11734,10 +11789,15 @@ var init_axis_schemas = __esm({
11734
11789
  ScanBurstDecisionZ = SensorDecisionWithMetadataZ;
11735
11790
  ProofKindZ = z2.enum([
11736
11791
  "NONE",
11737
- "CAPSULE",
11792
+ "ANONYMOUS",
11738
11793
  "PASSPORT",
11794
+ "CAPSULE",
11795
+ "JWT",
11796
+ "CONTRACT",
11797
+ "WITNESS",
11739
11798
  "MTLS",
11740
- "JWT"
11799
+ "DEVICE",
11800
+ "AUTHORIZED"
11741
11801
  ]);
11742
11802
  AccessProfileZ = z2.enum(["PUBLIC", "PARTNER", "INTERNAL", "NODE"]);
11743
11803
  ProofPresenceInputZ = z2.object({
@@ -11859,7 +11919,10 @@ var init_axis_schemas = __esm({
11859
11919
  ip: z2.string().min(1)
11860
11920
  });
11861
11921
  ProtocolStrictInputZ = z2.object({
11862
- rawBytes: z2.union([z2.custom((v) => Buffer.isBuffer(v)), z2.instanceof(Uint8Array)]).optional(),
11922
+ rawBytes: z2.union([
11923
+ z2.custom((v) => Buffer.isBuffer(v)),
11924
+ z2.instanceof(Uint8Array)
11925
+ ]).optional(),
11863
11926
  ip: z2.string().min(1),
11864
11927
  path: z2.string().min(1),
11865
11928
  contentLength: z2.number().int().nonnegative(),