@nextera.one/axis-server-sdk 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -264,6 +264,22 @@ var PROOF_JWT = 2;
264
264
  var PROOF_MTLS = 3;
265
265
  var PROOF_LOOM = 4;
266
266
  var PROOF_WITNESS = 5;
267
+ var ProofType = /* @__PURE__ */ ((ProofType2) => {
268
+ ProofType2[ProofType2["NONE"] = 0] = "NONE";
269
+ ProofType2[ProofType2["CAPSULE"] = 1] = "CAPSULE";
270
+ ProofType2[ProofType2["JWT"] = 2] = "JWT";
271
+ ProofType2[ProofType2["MTLS"] = 3] = "MTLS";
272
+ ProofType2[ProofType2["LOOM"] = 4] = "LOOM";
273
+ ProofType2[ProofType2["WITNESS"] = 5] = "WITNESS";
274
+ return ProofType2;
275
+ })(ProofType || {});
276
+ var BodyProfile = /* @__PURE__ */ ((BodyProfile2) => {
277
+ BodyProfile2[BodyProfile2["RAW"] = 0] = "RAW";
278
+ BodyProfile2[BodyProfile2["TLV_MAP"] = 1] = "TLV_MAP";
279
+ BodyProfile2[BodyProfile2["OBJ"] = 2] = "OBJ";
280
+ BodyProfile2[BodyProfile2["ARR"] = 3] = "ARR";
281
+ return BodyProfile2;
282
+ })(BodyProfile || {});
267
283
  var ERR_INVALID_PACKET = "INVALID_PACKET";
268
284
  var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
269
285
  var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
@@ -1867,16 +1883,243 @@ var SensorDecisions = {
1867
1883
  };
1868
1884
  }
1869
1885
  };
1886
+
1887
+ // src/security/scopes.ts
1888
+ function hasScope(scopes, required) {
1889
+ if (!Array.isArray(scopes) || scopes.length === 0) {
1890
+ return false;
1891
+ }
1892
+ if (scopes.includes(required)) {
1893
+ return true;
1894
+ }
1895
+ const [resource, id] = required.split(":");
1896
+ if (resource && id) {
1897
+ const wildcard = `${resource}:*`;
1898
+ if (scopes.includes(wildcard)) {
1899
+ return true;
1900
+ }
1901
+ }
1902
+ return false;
1903
+ }
1904
+ function parseScope(scope) {
1905
+ const parts = scope.split(":");
1906
+ if (parts.length !== 2) return null;
1907
+ return { resource: parts[0], id: parts[1] };
1908
+ }
1909
+ function canAccessResource(scopes, resourceType, resourceId) {
1910
+ const required = `${resourceType}:${resourceId}`;
1911
+ return hasScope(scopes, required);
1912
+ }
1913
+
1914
+ // src/security/capabilities.ts
1915
+ var CAPABILITIES = {
1916
+ read: "read",
1917
+ write: "write",
1918
+ execute: "execute",
1919
+ admin: "admin",
1920
+ sign: "sign",
1921
+ witness: "witness"
1922
+ };
1923
+ var PROOF_CAPABILITIES = {
1924
+ [PROOF_NONE]: [],
1925
+ [PROOF_CAPSULE]: ["read", "write", "execute"],
1926
+ [PROOF_JWT]: ["read"],
1927
+ [PROOF_MTLS]: ["read", "write", "admin"],
1928
+ [PROOF_LOOM]: ["read", "write", "execute"],
1929
+ [PROOF_WITNESS]: ["read", "write", "execute", "witness"]
1930
+ };
1931
+ var INTENT_REQUIREMENTS = {
1932
+ "public.*": [],
1933
+ "schema.*": [],
1934
+ "catalog.*": [],
1935
+ "health.*": [],
1936
+ "system.*": [],
1937
+ "file.upload": ["write"],
1938
+ "file.download": ["read"],
1939
+ "file.delete": ["write", "admin"],
1940
+ "passport.issue": ["write", "execute"],
1941
+ "passport.revoke": ["write", "witness"],
1942
+ "stream.publish": ["write"],
1943
+ "stream.subscribe": ["read"],
1944
+ "admin.*": ["admin"]
1945
+ };
1946
+
1947
+ // src/core/frame-validator.ts
1948
+ function validateFrameShape(frame) {
1949
+ if (!frame || typeof frame !== "object") {
1950
+ return false;
1951
+ }
1952
+ if (frame.v !== 1) {
1953
+ return false;
1954
+ }
1955
+ const requiredStrings = ["pid", "nonce", "actorId", "opcode"];
1956
+ for (const key of requiredStrings) {
1957
+ if (typeof frame[key] !== "string" || frame[key].length < 6) {
1958
+ return false;
1959
+ }
1960
+ }
1961
+ if (typeof frame.ts !== "number" || !Number.isFinite(frame.ts)) {
1962
+ return false;
1963
+ }
1964
+ if (frame.aud !== void 0 && (typeof frame.aud !== "string" || frame.aud.length === 0)) {
1965
+ return false;
1966
+ }
1967
+ if (!frame.sig || typeof frame.sig !== "object") {
1968
+ return false;
1969
+ }
1970
+ if (frame.sig.alg !== "EdDSA") {
1971
+ return false;
1972
+ }
1973
+ if (typeof frame.sig.kid !== "string" || frame.sig.kid.length < 8) {
1974
+ return false;
1975
+ }
1976
+ if (typeof frame.sig.value !== "string" || frame.sig.value.length < 32) {
1977
+ return false;
1978
+ }
1979
+ if (typeof frame.body !== "object" || frame.body === null) {
1980
+ return false;
1981
+ }
1982
+ return true;
1983
+ }
1984
+ function isTimestampValid(ts, skewSeconds = 120) {
1985
+ const now = Math.floor(Date.now() / 1e3);
1986
+ const diff = Math.abs(now - ts);
1987
+ return diff <= skewSeconds;
1988
+ }
1989
+
1990
+ // src/core/opcodes.ts
1991
+ var AXIS_OPCODES = /* @__PURE__ */ new Set([
1992
+ "CAPSULE.ISSUE",
1993
+ "CAPSULE.BATCH",
1994
+ "CAPSULE.REVOKE",
1995
+ "INTENT.EXEC",
1996
+ "ACTOR.KEY.ROTATE",
1997
+ "ACTOR.KEY.REVOKE",
1998
+ "ISSUER.KEY.ROTATE"
1999
+ ]);
2000
+ function isKnownOpcode(op) {
2001
+ return AXIS_OPCODES.has(op);
2002
+ }
2003
+ function isAdminOpcode(op) {
2004
+ return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.");
2005
+ }
2006
+
2007
+ // src/core/receipt.ts
2008
+ import { createHash as createHash3 } from "crypto";
2009
+ function buildReceiptHash(prevHash, pid, actorId, intent, effect, ts) {
2010
+ const h = createHash3("sha256");
2011
+ if (prevHash) h.update(prevHash);
2012
+ h.update(pid);
2013
+ h.update(Buffer.from(actorId, "utf8"));
2014
+ h.update(Buffer.from(intent, "utf8"));
2015
+ h.update(Buffer.from(effect, "utf8"));
2016
+ h.update(Buffer.from(ts.toString(), "utf8"));
2017
+ return h.digest();
2018
+ }
2019
+
2020
+ // src/core/intent-sensitivity.ts
2021
+ var IntentSensitivity = /* @__PURE__ */ ((IntentSensitivity2) => {
2022
+ IntentSensitivity2[IntentSensitivity2["LOW"] = 1] = "LOW";
2023
+ IntentSensitivity2[IntentSensitivity2["MEDIUM"] = 2] = "MEDIUM";
2024
+ IntentSensitivity2[IntentSensitivity2["HIGH"] = 3] = "HIGH";
2025
+ IntentSensitivity2[IntentSensitivity2["CRITICAL"] = 4] = "CRITICAL";
2026
+ return IntentSensitivity2;
2027
+ })(IntentSensitivity || {});
2028
+ var INTENT_SENSITIVITY_MAP = {
2029
+ // System intents
2030
+ "system.ping": 1 /* LOW */,
2031
+ // Catalog intents
2032
+ "catalog.list": 1 /* LOW */,
2033
+ "catalog.search": 1 /* LOW */,
2034
+ "catalog.intent.describe": 1 /* LOW */,
2035
+ "catalog.intent.complete": 1 /* LOW */,
2036
+ // Stream intents
2037
+ "stream.publish": 2 /* MEDIUM */,
2038
+ "stream.read": 2 /* MEDIUM */,
2039
+ "stream.subscribe": 2 /* MEDIUM */,
2040
+ // File intents
2041
+ "file.init": 2 /* MEDIUM */,
2042
+ "file.chunk": 2 /* MEDIUM */,
2043
+ "file.finalize": 2 /* MEDIUM */,
2044
+ "file.status": 1 /* LOW */,
2045
+ // Passport intents
2046
+ "passport.issue": 3 /* HIGH */,
2047
+ "passport.verify": 2 /* MEDIUM */,
2048
+ "passport.revoke": 4 /* CRITICAL */,
2049
+ // Mail intents
2050
+ "mail.send": 3 /* HIGH */,
2051
+ // Admin intents
2052
+ "admin.create_capsule": 4 /* CRITICAL */,
2053
+ "admin.revoke_capsule": 4 /* CRITICAL */,
2054
+ "admin.issue_node_cert": 4 /* CRITICAL */
2055
+ };
2056
+ function classifyIntent(intent) {
2057
+ if (INTENT_SENSITIVITY_MAP[intent]) {
2058
+ return INTENT_SENSITIVITY_MAP[intent];
2059
+ }
2060
+ const realm = intent.split(".")[0];
2061
+ const wildcardKey = `${realm}.*`;
2062
+ if (INTENT_SENSITIVITY_MAP[wildcardKey]) {
2063
+ return INTENT_SENSITIVITY_MAP[wildcardKey];
2064
+ }
2065
+ return 2 /* MEDIUM */;
2066
+ }
2067
+ function sensitivityName(level) {
2068
+ switch (level) {
2069
+ case 1 /* LOW */:
2070
+ return "LOW";
2071
+ case 2 /* MEDIUM */:
2072
+ return "MEDIUM";
2073
+ case 3 /* HIGH */:
2074
+ return "HIGH";
2075
+ case 4 /* CRITICAL */:
2076
+ return "CRITICAL";
2077
+ }
2078
+ }
2079
+
2080
+ // src/core/timeouts.ts
2081
+ var INTENT_TIMEOUTS = {
2082
+ "public.*": 5e3,
2083
+ "schema.*": 5e3,
2084
+ "catalog.*": 5e3,
2085
+ "health.*": 2e3,
2086
+ "file.upload": 6e4,
2087
+ "file.download": 6e4,
2088
+ "file.chunk": 3e4,
2089
+ "file.finalize": 3e4,
2090
+ "stream.*": 3e4,
2091
+ "passport.*": 15e3,
2092
+ "admin.*": 3e4
2093
+ };
2094
+ var DEFAULT_TIMEOUT = 1e4;
2095
+ function resolveTimeout(intent) {
2096
+ if (INTENT_TIMEOUTS[intent]) {
2097
+ return INTENT_TIMEOUTS[intent];
2098
+ }
2099
+ for (const [pattern, timeout] of Object.entries(INTENT_TIMEOUTS)) {
2100
+ if (pattern.endsWith(".*")) {
2101
+ const prefix = pattern.slice(0, -1);
2102
+ if (intent.startsWith(prefix)) {
2103
+ return timeout;
2104
+ }
2105
+ }
2106
+ }
2107
+ return DEFAULT_TIMEOUT;
2108
+ }
1870
2109
  export {
1871
2110
  ATS1_HDR,
1872
2111
  ATS1_SCHEMA,
1873
2112
  AXIS_MAGIC,
2113
+ AXIS_OPCODES,
1874
2114
  AXIS_VERSION,
1875
2115
  ats1_exports as Ats1Codec,
1876
2116
  AxisFrameZ,
1877
2117
  T as AxisPacketTags,
2118
+ BodyProfile,
2119
+ CAPABILITIES,
1878
2120
  ContractViolationError,
1879
2121
  DEFAULT_CONTRACTS,
2122
+ DEFAULT_TIMEOUT,
1880
2123
  Decision,
1881
2124
  ERR_BAD_SIGNATURE,
1882
2125
  ERR_CONTRACT_VIOLATION,
@@ -1889,9 +2132,13 @@ export {
1889
2132
  FLAG_HAS_WITNESS,
1890
2133
  HANDLER_METADATA_KEY,
1891
2134
  Handler,
2135
+ INTENT_REQUIREMENTS,
1892
2136
  INTENT_ROUTES_KEY,
2137
+ INTENT_SENSITIVITY_MAP,
2138
+ INTENT_TIMEOUTS,
1893
2139
  Intent,
1894
2140
  IntentRouter,
2141
+ IntentSensitivity,
1895
2142
  MAX_BODY_LEN,
1896
2143
  MAX_FRAME_LEN,
1897
2144
  MAX_HDR_LEN,
@@ -1906,12 +2153,14 @@ export {
1906
2153
  NCERT_PUB,
1907
2154
  NCERT_SCOPE,
1908
2155
  NCERT_SIG,
2156
+ PROOF_CAPABILITIES,
1909
2157
  PROOF_CAPSULE,
1910
2158
  PROOF_JWT,
1911
2159
  PROOF_LOOM,
1912
2160
  PROOF_MTLS,
1913
2161
  PROOF_NONE,
1914
2162
  PROOF_WITNESS,
2163
+ ProofType,
1915
2164
  Schema2002_PasskeyLoginOptionsRes,
1916
2165
  Schema2011_PasskeyLoginVerifyReq,
1917
2166
  Schema2012_PasskeyLoginVerifyRes,
@@ -1955,10 +2204,13 @@ export {
1955
2204
  b64urlEncodeString,
1956
2205
  buildAts1Hdr,
1957
2206
  buildPacket,
2207
+ buildReceiptHash,
1958
2208
  buildTLVs,
1959
2209
  bytes,
2210
+ canAccessResource,
1960
2211
  canonicalJson,
1961
2212
  canonicalJsonExcluding,
2213
+ classifyIntent,
1962
2214
  computeReceiptHash,
1963
2215
  computeSignaturePayload,
1964
2216
  decodeArray,
@@ -1975,6 +2227,10 @@ export {
1975
2227
  encodeVarint,
1976
2228
  generateEd25519KeyPair,
1977
2229
  getSignTarget,
2230
+ hasScope,
2231
+ isAdminOpcode,
2232
+ isKnownOpcode,
2233
+ isTimestampValid,
1978
2234
  nonce16,
1979
2235
  normalizeSensorDecision,
1980
2236
  packPasskeyLoginOptionsReq,
@@ -1982,6 +2238,9 @@ export {
1982
2238
  packPasskeyLoginVerifyReq,
1983
2239
  packPasskeyLoginVerifyRes,
1984
2240
  packPasskeyRegisterOptionsReq,
2241
+ parseScope,
2242
+ resolveTimeout,
2243
+ sensitivityName,
1985
2244
  sha256,
1986
2245
  signFrame,
1987
2246
  tlv,
@@ -1990,6 +2249,7 @@ export {
1990
2249
  unpackPasskeyLoginVerifyReq,
1991
2250
  unpackPasskeyRegisterOptionsReq,
1992
2251
  utf8,
2252
+ validateFrameShape,
1993
2253
  varintLength,
1994
2254
  varintU,
1995
2255
  verifyFrameSignature