@nextera.one/axis-server-sdk 0.5.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/core/index.d.mts +29 -1
- package/dist/core/index.d.ts +29 -1
- package/dist/core/index.js +62 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +46 -0
- package/dist/core/index.mjs.map +1 -1
- package/dist/index.d.mts +58 -2
- package/dist/index.d.ts +58 -2
- package/dist/index.js +323 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +288 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -246,10 +246,40 @@ var TLV_INDEX = 71;
|
|
|
246
246
|
var TLV_OFFSET = 72;
|
|
247
247
|
var TLV_SHA256_CHUNK = 73;
|
|
248
248
|
var TLV_CAPSULE = 90;
|
|
249
|
+
var TLV_BODY_OBJ = 254;
|
|
250
|
+
var TLV_BODY_ARR = 255;
|
|
251
|
+
var NCERT_NODE_ID = 1;
|
|
252
|
+
var NCERT_KID = 2;
|
|
253
|
+
var NCERT_ALG = 3;
|
|
254
|
+
var NCERT_PUB = 4;
|
|
255
|
+
var NCERT_NBF = 5;
|
|
256
|
+
var NCERT_EXP = 6;
|
|
257
|
+
var NCERT_SCOPE = 7;
|
|
258
|
+
var NCERT_ISSUER_KID = 8;
|
|
259
|
+
var NCERT_PAYLOAD = 50;
|
|
260
|
+
var NCERT_SIG = 51;
|
|
261
|
+
var PROOF_NONE = 0;
|
|
249
262
|
var PROOF_CAPSULE = 1;
|
|
250
263
|
var PROOF_JWT = 2;
|
|
251
264
|
var PROOF_MTLS = 3;
|
|
252
265
|
var PROOF_LOOM = 4;
|
|
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 || {});
|
|
253
283
|
var ERR_INVALID_PACKET = "INVALID_PACKET";
|
|
254
284
|
var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
|
|
255
285
|
var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
|
|
@@ -1853,16 +1883,243 @@ var SensorDecisions = {
|
|
|
1853
1883
|
};
|
|
1854
1884
|
}
|
|
1855
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
|
+
}
|
|
1856
2109
|
export {
|
|
1857
2110
|
ATS1_HDR,
|
|
1858
2111
|
ATS1_SCHEMA,
|
|
1859
2112
|
AXIS_MAGIC,
|
|
2113
|
+
AXIS_OPCODES,
|
|
1860
2114
|
AXIS_VERSION,
|
|
1861
2115
|
ats1_exports as Ats1Codec,
|
|
1862
2116
|
AxisFrameZ,
|
|
1863
2117
|
T as AxisPacketTags,
|
|
2118
|
+
BodyProfile,
|
|
2119
|
+
CAPABILITIES,
|
|
1864
2120
|
ContractViolationError,
|
|
1865
2121
|
DEFAULT_CONTRACTS,
|
|
2122
|
+
DEFAULT_TIMEOUT,
|
|
1866
2123
|
Decision,
|
|
1867
2124
|
ERR_BAD_SIGNATURE,
|
|
1868
2125
|
ERR_CONTRACT_VIOLATION,
|
|
@@ -1875,17 +2132,35 @@ export {
|
|
|
1875
2132
|
FLAG_HAS_WITNESS,
|
|
1876
2133
|
HANDLER_METADATA_KEY,
|
|
1877
2134
|
Handler,
|
|
2135
|
+
INTENT_REQUIREMENTS,
|
|
1878
2136
|
INTENT_ROUTES_KEY,
|
|
2137
|
+
INTENT_SENSITIVITY_MAP,
|
|
2138
|
+
INTENT_TIMEOUTS,
|
|
1879
2139
|
Intent,
|
|
1880
2140
|
IntentRouter,
|
|
2141
|
+
IntentSensitivity,
|
|
1881
2142
|
MAX_BODY_LEN,
|
|
1882
2143
|
MAX_FRAME_LEN,
|
|
1883
2144
|
MAX_HDR_LEN,
|
|
1884
2145
|
MAX_SIG_LEN,
|
|
2146
|
+
NCERT_ALG,
|
|
2147
|
+
NCERT_EXP,
|
|
2148
|
+
NCERT_ISSUER_KID,
|
|
2149
|
+
NCERT_KID,
|
|
2150
|
+
NCERT_NBF,
|
|
2151
|
+
NCERT_NODE_ID,
|
|
2152
|
+
NCERT_PAYLOAD,
|
|
2153
|
+
NCERT_PUB,
|
|
2154
|
+
NCERT_SCOPE,
|
|
2155
|
+
NCERT_SIG,
|
|
2156
|
+
PROOF_CAPABILITIES,
|
|
1885
2157
|
PROOF_CAPSULE,
|
|
1886
2158
|
PROOF_JWT,
|
|
1887
2159
|
PROOF_LOOM,
|
|
1888
2160
|
PROOF_MTLS,
|
|
2161
|
+
PROOF_NONE,
|
|
2162
|
+
PROOF_WITNESS,
|
|
2163
|
+
ProofType,
|
|
1889
2164
|
Schema2002_PasskeyLoginOptionsRes,
|
|
1890
2165
|
Schema2011_PasskeyLoginVerifyReq,
|
|
1891
2166
|
Schema2012_PasskeyLoginVerifyRes,
|
|
@@ -1893,6 +2168,8 @@ export {
|
|
|
1893
2168
|
SensorDecisions,
|
|
1894
2169
|
TLV_ACTOR_ID,
|
|
1895
2170
|
TLV_AUD,
|
|
2171
|
+
TLV_BODY_ARR,
|
|
2172
|
+
TLV_BODY_OBJ,
|
|
1896
2173
|
TLV_CAPSULE,
|
|
1897
2174
|
TLV_EFFECT,
|
|
1898
2175
|
TLV_ERROR_CODE,
|
|
@@ -1927,10 +2204,13 @@ export {
|
|
|
1927
2204
|
b64urlEncodeString,
|
|
1928
2205
|
buildAts1Hdr,
|
|
1929
2206
|
buildPacket,
|
|
2207
|
+
buildReceiptHash,
|
|
1930
2208
|
buildTLVs,
|
|
1931
2209
|
bytes,
|
|
2210
|
+
canAccessResource,
|
|
1932
2211
|
canonicalJson,
|
|
1933
2212
|
canonicalJsonExcluding,
|
|
2213
|
+
classifyIntent,
|
|
1934
2214
|
computeReceiptHash,
|
|
1935
2215
|
computeSignaturePayload,
|
|
1936
2216
|
decodeArray,
|
|
@@ -1947,6 +2227,10 @@ export {
|
|
|
1947
2227
|
encodeVarint,
|
|
1948
2228
|
generateEd25519KeyPair,
|
|
1949
2229
|
getSignTarget,
|
|
2230
|
+
hasScope,
|
|
2231
|
+
isAdminOpcode,
|
|
2232
|
+
isKnownOpcode,
|
|
2233
|
+
isTimestampValid,
|
|
1950
2234
|
nonce16,
|
|
1951
2235
|
normalizeSensorDecision,
|
|
1952
2236
|
packPasskeyLoginOptionsReq,
|
|
@@ -1954,6 +2238,9 @@ export {
|
|
|
1954
2238
|
packPasskeyLoginVerifyReq,
|
|
1955
2239
|
packPasskeyLoginVerifyRes,
|
|
1956
2240
|
packPasskeyRegisterOptionsReq,
|
|
2241
|
+
parseScope,
|
|
2242
|
+
resolveTimeout,
|
|
2243
|
+
sensitivityName,
|
|
1957
2244
|
sha256,
|
|
1958
2245
|
signFrame,
|
|
1959
2246
|
tlv,
|
|
@@ -1962,6 +2249,7 @@ export {
|
|
|
1962
2249
|
unpackPasskeyLoginVerifyReq,
|
|
1963
2250
|
unpackPasskeyRegisterOptionsReq,
|
|
1964
2251
|
utf8,
|
|
2252
|
+
validateFrameShape,
|
|
1965
2253
|
varintLength,
|
|
1966
2254
|
varintU,
|
|
1967
2255
|
verifyFrameSignature
|