@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/core/index.d.mts +15 -1
- package/dist/core/index.d.ts +15 -1
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +18 -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 +281 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxisFrame } from './core/index.js';
|
|
2
|
-
export { AXIS_MAGIC, AXIS_VERSION, AxisBinaryFrame, AxisFrameZ, TLV as AxisTlvType, ERR_BAD_SIGNATURE, ERR_CONTRACT_VIOLATION, ERR_INVALID_PACKET, ERR_REPLAY_DETECTED, FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS, MAX_BODY_LEN, MAX_FRAME_LEN, MAX_HDR_LEN, MAX_SIG_LEN, NCERT_ALG, NCERT_EXP, NCERT_ISSUER_KID, NCERT_KID, NCERT_NBF, NCERT_NODE_ID, NCERT_PAYLOAD, NCERT_PUB, NCERT_SCOPE, NCERT_SIG, PROOF_CAPSULE, PROOF_JWT, PROOF_LOOM, PROOF_MTLS, PROOF_NONE, PROOF_WITNESS, TLV, TLV_ACTOR_ID, TLV_AUD, TLV_BODY_ARR, TLV_BODY_OBJ, TLV_CAPSULE, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG, TLV_INDEX, TLV_INTENT, TLV_KID, TLV_LOOM_PRESENCE_ID, TLV_LOOM_THREAD_HASH, TLV_LOOM_WRIT, TLV_NODE, TLV_NODE_CERT_HASH, TLV_NODE_KID, TLV_NONCE, TLV_OFFSET, TLV_OK, TLV_PID, TLV_PREV_HASH, TLV_PROOF_REF, TLV_PROOF_TYPE, TLV_REALM, TLV_RECEIPT_HASH, TLV_RID, TLV_SHA256_CHUNK, TLV_TRACE_ID, TLV_TS, TLV_UPLOAD_ID, computeReceiptHash, computeSignaturePayload, decodeArray, decodeFrame, decodeObject, decodeTLVs, decodeTLVsList, decodeVarint, encodeFrame, encodeTLVs, encodeVarint, generateEd25519KeyPair, getSignTarget, sha256, signFrame, varintLength, verifyFrameSignature } from './core/index.js';
|
|
2
|
+
export { AXIS_MAGIC, AXIS_VERSION, AxisBinaryFrame, AxisFrameZ, TLV as AxisTlvType, BodyProfile, ERR_BAD_SIGNATURE, ERR_CONTRACT_VIOLATION, ERR_INVALID_PACKET, ERR_REPLAY_DETECTED, FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS, MAX_BODY_LEN, MAX_FRAME_LEN, MAX_HDR_LEN, MAX_SIG_LEN, NCERT_ALG, NCERT_EXP, NCERT_ISSUER_KID, NCERT_KID, NCERT_NBF, NCERT_NODE_ID, NCERT_PAYLOAD, NCERT_PUB, NCERT_SCOPE, NCERT_SIG, PROOF_CAPSULE, PROOF_JWT, PROOF_LOOM, PROOF_MTLS, PROOF_NONE, PROOF_WITNESS, ProofType, TLV, TLV_ACTOR_ID, TLV_AUD, TLV_BODY_ARR, TLV_BODY_OBJ, TLV_CAPSULE, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG, TLV_INDEX, TLV_INTENT, TLV_KID, TLV_LOOM_PRESENCE_ID, TLV_LOOM_THREAD_HASH, TLV_LOOM_WRIT, TLV_NODE, TLV_NODE_CERT_HASH, TLV_NODE_KID, TLV_NONCE, TLV_OFFSET, TLV_OK, TLV_PID, TLV_PREV_HASH, TLV_PROOF_REF, TLV_PROOF_TYPE, TLV_REALM, TLV_RECEIPT_HASH, TLV_RID, TLV_SHA256_CHUNK, TLV_TRACE_ID, TLV_TS, TLV_UPLOAD_ID, computeReceiptHash, computeSignaturePayload, decodeArray, decodeFrame, decodeObject, decodeTLVs, decodeTLVsList, decodeVarint, encodeFrame, encodeTLVs, encodeVarint, generateEd25519KeyPair, getSignTarget, sha256, signFrame, varintLength, verifyFrameSignature } from './core/index.js';
|
|
3
3
|
import { OnModuleInit } from '@nestjs/common';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
@@ -683,4 +683,60 @@ interface AxisCrudHandler extends AxisHandlerInit {
|
|
|
683
683
|
remove(body: Uint8Array, headers?: Map<number, Uint8Array>): Promise<Uint8Array>;
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
-
|
|
686
|
+
declare function hasScope(scopes: string[], required: string): boolean;
|
|
687
|
+
declare function parseScope(scope: string): {
|
|
688
|
+
resource: string;
|
|
689
|
+
id: string;
|
|
690
|
+
} | null;
|
|
691
|
+
declare function canAccessResource(scopes: string[], resourceType: string, resourceId: string): boolean;
|
|
692
|
+
|
|
693
|
+
declare const CAPABILITIES: {
|
|
694
|
+
readonly read: "read";
|
|
695
|
+
readonly write: "write";
|
|
696
|
+
readonly execute: "execute";
|
|
697
|
+
readonly admin: "admin";
|
|
698
|
+
readonly sign: "sign";
|
|
699
|
+
readonly witness: "witness";
|
|
700
|
+
};
|
|
701
|
+
type Capability = keyof typeof CAPABILITIES;
|
|
702
|
+
declare const PROOF_CAPABILITIES: Record<number, Capability[]>;
|
|
703
|
+
declare const INTENT_REQUIREMENTS: Record<string, Capability[]>;
|
|
704
|
+
|
|
705
|
+
declare function validateFrameShape(frame: any): boolean;
|
|
706
|
+
declare function isTimestampValid(ts: number, skewSeconds?: number): boolean;
|
|
707
|
+
|
|
708
|
+
declare const AXIS_OPCODES: Set<string>;
|
|
709
|
+
declare function isKnownOpcode(op: string): boolean;
|
|
710
|
+
declare function isAdminOpcode(op: string): boolean;
|
|
711
|
+
|
|
712
|
+
type ReceiptEffect = 'ALLOW' | 'DENY' | 'ERROR';
|
|
713
|
+
declare function buildReceiptHash(prevHash: Buffer | null, pid: Buffer, actorId: string, intent: string, effect: ReceiptEffect, ts: bigint): Buffer;
|
|
714
|
+
|
|
715
|
+
declare enum IntentSensitivity {
|
|
716
|
+
LOW = 1,
|
|
717
|
+
MEDIUM = 2,
|
|
718
|
+
HIGH = 3,
|
|
719
|
+
CRITICAL = 4
|
|
720
|
+
}
|
|
721
|
+
declare const INTENT_SENSITIVITY_MAP: Record<string, IntentSensitivity>;
|
|
722
|
+
declare function classifyIntent(intent: string): IntentSensitivity;
|
|
723
|
+
declare function sensitivityName(level: IntentSensitivity): string;
|
|
724
|
+
|
|
725
|
+
declare const INTENT_TIMEOUTS: Record<string, number>;
|
|
726
|
+
declare const DEFAULT_TIMEOUT = 10000;
|
|
727
|
+
declare function resolveTimeout(intent: string): number;
|
|
728
|
+
|
|
729
|
+
interface IntentDefinition {
|
|
730
|
+
intent: string;
|
|
731
|
+
description: string;
|
|
732
|
+
sensitivity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
733
|
+
requiredProof: string[];
|
|
734
|
+
contract: {
|
|
735
|
+
maxDbWrites: number;
|
|
736
|
+
maxTimeMs: number;
|
|
737
|
+
};
|
|
738
|
+
examples?: string[];
|
|
739
|
+
deprecated?: boolean;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export { ATS1_HDR, ATS1_SCHEMA, AXIS_OPCODES, type ActorKeyRecord, ats1 as Ats1Codec, type Axis1DecodedFrame, type Axis1FrameToEncode, type AxisAlg, type AxisPacket as AxisBinaryPacket, type AxisCapsule, type AxisCapsuleConstraints, type AxisCapsulePayload, type AxisCrudHandler, type AxisEffect, type AxisHandler, type AxisHandlerInit, type AxisObservedContext, type AxisPacket$1 as AxisPacket, T as AxisPacketTags, type AxisPostSensor, type AxisPreSensor, type AxisRequestContext, type AxisResponse, type AxisSensor, type AxisSensorInit, type AxisSig, CAPABILITIES, type Capability, type CapsuleBatchBody, type CapsuleBatchResult, type CapsuleIssueBody, type CapsuleIssueResult, type CapsuleMode, type CapsuleRecord, type CapsuleRevokeBody, type CapsuleStatus, ContractViolationError, DEFAULT_CONTRACTS, DEFAULT_TIMEOUT, Decision, type ExecutionContract, ExecutionMeter, type ExecutionMetrics, FALLBACK_CONTRACT, HANDLER_METADATA_KEY, Handler, INTENT_REQUIREMENTS, INTENT_ROUTES_KEY, INTENT_SENSITIVITY_MAP, INTENT_TIMEOUTS, Intent, type IntentDefinition, type IntentExecBody, type IntentOptions, type IntentRoute, IntentRouter, IntentSensitivity, type IssuerKeyRecord, type KeyStatus, PROOF_CAPABILITIES, type ReceiptEffect, Schema2002_PasskeyLoginOptionsRes, Schema2011_PasskeyLoginVerifyReq, Schema2012_PasskeyLoginVerifyRes, Schema2021_PasskeyRegisterOptionsReq, type SensorDecision, SensorDecisions, type SensorInput, type SensorMinifiedDecision, type SensorPhaseMetadata, type TickWindow, axis1SigningBytes, b64urlDecode, b64urlDecodeString, b64urlEncode, b64urlEncodeString, buildAts1Hdr, buildPacket, buildReceiptHash, buildTLVs, bytes, canAccessResource, canonicalJson, canonicalJsonExcluding, classifyIntent, decodeAxis1Frame, encVarint, encodeAxis1Frame, hasScope, isAdminOpcode, isKnownOpcode, isTimestampValid, nonce16, normalizeSensorDecision, packPasskeyLoginOptionsReq, packPasskeyLoginOptionsRes, packPasskeyLoginVerifyReq, packPasskeyLoginVerifyRes, packPasskeyRegisterOptionsReq, parseScope, resolveTimeout, sensitivityName, tlv, u64be, unpackPasskeyLoginOptionsReq, unpackPasskeyLoginVerifyReq, unpackPasskeyRegisterOptionsReq, utf8, validateFrameShape, varintU };
|
package/dist/index.js
CHANGED
|
@@ -40,12 +40,16 @@ __export(index_exports, {
|
|
|
40
40
|
ATS1_HDR: () => ATS1_HDR,
|
|
41
41
|
ATS1_SCHEMA: () => ATS1_SCHEMA,
|
|
42
42
|
AXIS_MAGIC: () => AXIS_MAGIC,
|
|
43
|
+
AXIS_OPCODES: () => AXIS_OPCODES,
|
|
43
44
|
AXIS_VERSION: () => AXIS_VERSION,
|
|
44
45
|
Ats1Codec: () => ats1_exports,
|
|
45
46
|
AxisFrameZ: () => AxisFrameZ,
|
|
46
47
|
AxisPacketTags: () => T,
|
|
48
|
+
BodyProfile: () => BodyProfile,
|
|
49
|
+
CAPABILITIES: () => CAPABILITIES,
|
|
47
50
|
ContractViolationError: () => ContractViolationError,
|
|
48
51
|
DEFAULT_CONTRACTS: () => DEFAULT_CONTRACTS,
|
|
52
|
+
DEFAULT_TIMEOUT: () => DEFAULT_TIMEOUT,
|
|
49
53
|
Decision: () => Decision,
|
|
50
54
|
ERR_BAD_SIGNATURE: () => ERR_BAD_SIGNATURE,
|
|
51
55
|
ERR_CONTRACT_VIOLATION: () => ERR_CONTRACT_VIOLATION,
|
|
@@ -58,9 +62,13 @@ __export(index_exports, {
|
|
|
58
62
|
FLAG_HAS_WITNESS: () => FLAG_HAS_WITNESS,
|
|
59
63
|
HANDLER_METADATA_KEY: () => HANDLER_METADATA_KEY,
|
|
60
64
|
Handler: () => Handler,
|
|
65
|
+
INTENT_REQUIREMENTS: () => INTENT_REQUIREMENTS,
|
|
61
66
|
INTENT_ROUTES_KEY: () => INTENT_ROUTES_KEY,
|
|
67
|
+
INTENT_SENSITIVITY_MAP: () => INTENT_SENSITIVITY_MAP,
|
|
68
|
+
INTENT_TIMEOUTS: () => INTENT_TIMEOUTS,
|
|
62
69
|
Intent: () => Intent,
|
|
63
70
|
IntentRouter: () => IntentRouter,
|
|
71
|
+
IntentSensitivity: () => IntentSensitivity,
|
|
64
72
|
MAX_BODY_LEN: () => MAX_BODY_LEN,
|
|
65
73
|
MAX_FRAME_LEN: () => MAX_FRAME_LEN,
|
|
66
74
|
MAX_HDR_LEN: () => MAX_HDR_LEN,
|
|
@@ -75,12 +83,14 @@ __export(index_exports, {
|
|
|
75
83
|
NCERT_PUB: () => NCERT_PUB,
|
|
76
84
|
NCERT_SCOPE: () => NCERT_SCOPE,
|
|
77
85
|
NCERT_SIG: () => NCERT_SIG,
|
|
86
|
+
PROOF_CAPABILITIES: () => PROOF_CAPABILITIES,
|
|
78
87
|
PROOF_CAPSULE: () => PROOF_CAPSULE,
|
|
79
88
|
PROOF_JWT: () => PROOF_JWT,
|
|
80
89
|
PROOF_LOOM: () => PROOF_LOOM,
|
|
81
90
|
PROOF_MTLS: () => PROOF_MTLS,
|
|
82
91
|
PROOF_NONE: () => PROOF_NONE,
|
|
83
92
|
PROOF_WITNESS: () => PROOF_WITNESS,
|
|
93
|
+
ProofType: () => ProofType,
|
|
84
94
|
Schema2002_PasskeyLoginOptionsRes: () => Schema2002_PasskeyLoginOptionsRes,
|
|
85
95
|
Schema2011_PasskeyLoginVerifyReq: () => Schema2011_PasskeyLoginVerifyReq,
|
|
86
96
|
Schema2012_PasskeyLoginVerifyRes: () => Schema2012_PasskeyLoginVerifyRes,
|
|
@@ -124,10 +134,13 @@ __export(index_exports, {
|
|
|
124
134
|
b64urlEncodeString: () => b64urlEncodeString,
|
|
125
135
|
buildAts1Hdr: () => buildAts1Hdr,
|
|
126
136
|
buildPacket: () => buildPacket,
|
|
137
|
+
buildReceiptHash: () => buildReceiptHash,
|
|
127
138
|
buildTLVs: () => buildTLVs,
|
|
128
139
|
bytes: () => bytes,
|
|
140
|
+
canAccessResource: () => canAccessResource,
|
|
129
141
|
canonicalJson: () => canonicalJson,
|
|
130
142
|
canonicalJsonExcluding: () => canonicalJsonExcluding,
|
|
143
|
+
classifyIntent: () => classifyIntent,
|
|
131
144
|
computeReceiptHash: () => computeReceiptHash,
|
|
132
145
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
133
146
|
decodeArray: () => decodeArray,
|
|
@@ -144,6 +157,10 @@ __export(index_exports, {
|
|
|
144
157
|
encodeVarint: () => encodeVarint,
|
|
145
158
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
146
159
|
getSignTarget: () => getSignTarget,
|
|
160
|
+
hasScope: () => hasScope,
|
|
161
|
+
isAdminOpcode: () => isAdminOpcode,
|
|
162
|
+
isKnownOpcode: () => isKnownOpcode,
|
|
163
|
+
isTimestampValid: () => isTimestampValid,
|
|
147
164
|
nonce16: () => nonce16,
|
|
148
165
|
normalizeSensorDecision: () => normalizeSensorDecision,
|
|
149
166
|
packPasskeyLoginOptionsReq: () => packPasskeyLoginOptionsReq,
|
|
@@ -151,6 +168,9 @@ __export(index_exports, {
|
|
|
151
168
|
packPasskeyLoginVerifyReq: () => packPasskeyLoginVerifyReq,
|
|
152
169
|
packPasskeyLoginVerifyRes: () => packPasskeyLoginVerifyRes,
|
|
153
170
|
packPasskeyRegisterOptionsReq: () => packPasskeyRegisterOptionsReq,
|
|
171
|
+
parseScope: () => parseScope,
|
|
172
|
+
resolveTimeout: () => resolveTimeout,
|
|
173
|
+
sensitivityName: () => sensitivityName,
|
|
154
174
|
sha256: () => sha256,
|
|
155
175
|
signFrame: () => signFrame,
|
|
156
176
|
tlv: () => tlv,
|
|
@@ -159,6 +179,7 @@ __export(index_exports, {
|
|
|
159
179
|
unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
|
|
160
180
|
unpackPasskeyRegisterOptionsReq: () => unpackPasskeyRegisterOptionsReq,
|
|
161
181
|
utf8: () => utf8,
|
|
182
|
+
validateFrameShape: () => validateFrameShape,
|
|
162
183
|
varintLength: () => varintLength,
|
|
163
184
|
varintU: () => varintU,
|
|
164
185
|
verifyFrameSignature: () => verifyFrameSignature
|
|
@@ -410,6 +431,22 @@ var PROOF_JWT = 2;
|
|
|
410
431
|
var PROOF_MTLS = 3;
|
|
411
432
|
var PROOF_LOOM = 4;
|
|
412
433
|
var PROOF_WITNESS = 5;
|
|
434
|
+
var ProofType = /* @__PURE__ */ ((ProofType2) => {
|
|
435
|
+
ProofType2[ProofType2["NONE"] = 0] = "NONE";
|
|
436
|
+
ProofType2[ProofType2["CAPSULE"] = 1] = "CAPSULE";
|
|
437
|
+
ProofType2[ProofType2["JWT"] = 2] = "JWT";
|
|
438
|
+
ProofType2[ProofType2["MTLS"] = 3] = "MTLS";
|
|
439
|
+
ProofType2[ProofType2["LOOM"] = 4] = "LOOM";
|
|
440
|
+
ProofType2[ProofType2["WITNESS"] = 5] = "WITNESS";
|
|
441
|
+
return ProofType2;
|
|
442
|
+
})(ProofType || {});
|
|
443
|
+
var BodyProfile = /* @__PURE__ */ ((BodyProfile2) => {
|
|
444
|
+
BodyProfile2[BodyProfile2["RAW"] = 0] = "RAW";
|
|
445
|
+
BodyProfile2[BodyProfile2["TLV_MAP"] = 1] = "TLV_MAP";
|
|
446
|
+
BodyProfile2[BodyProfile2["OBJ"] = 2] = "OBJ";
|
|
447
|
+
BodyProfile2[BodyProfile2["ARR"] = 3] = "ARR";
|
|
448
|
+
return BodyProfile2;
|
|
449
|
+
})(BodyProfile || {});
|
|
413
450
|
var ERR_INVALID_PACKET = "INVALID_PACKET";
|
|
414
451
|
var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
|
|
415
452
|
var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
|
|
@@ -2013,17 +2050,244 @@ var SensorDecisions = {
|
|
|
2013
2050
|
};
|
|
2014
2051
|
}
|
|
2015
2052
|
};
|
|
2053
|
+
|
|
2054
|
+
// src/security/scopes.ts
|
|
2055
|
+
function hasScope(scopes, required) {
|
|
2056
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
2057
|
+
return false;
|
|
2058
|
+
}
|
|
2059
|
+
if (scopes.includes(required)) {
|
|
2060
|
+
return true;
|
|
2061
|
+
}
|
|
2062
|
+
const [resource, id] = required.split(":");
|
|
2063
|
+
if (resource && id) {
|
|
2064
|
+
const wildcard = `${resource}:*`;
|
|
2065
|
+
if (scopes.includes(wildcard)) {
|
|
2066
|
+
return true;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
return false;
|
|
2070
|
+
}
|
|
2071
|
+
function parseScope(scope) {
|
|
2072
|
+
const parts = scope.split(":");
|
|
2073
|
+
if (parts.length !== 2) return null;
|
|
2074
|
+
return { resource: parts[0], id: parts[1] };
|
|
2075
|
+
}
|
|
2076
|
+
function canAccessResource(scopes, resourceType, resourceId) {
|
|
2077
|
+
const required = `${resourceType}:${resourceId}`;
|
|
2078
|
+
return hasScope(scopes, required);
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
// src/security/capabilities.ts
|
|
2082
|
+
var CAPABILITIES = {
|
|
2083
|
+
read: "read",
|
|
2084
|
+
write: "write",
|
|
2085
|
+
execute: "execute",
|
|
2086
|
+
admin: "admin",
|
|
2087
|
+
sign: "sign",
|
|
2088
|
+
witness: "witness"
|
|
2089
|
+
};
|
|
2090
|
+
var PROOF_CAPABILITIES = {
|
|
2091
|
+
[PROOF_NONE]: [],
|
|
2092
|
+
[PROOF_CAPSULE]: ["read", "write", "execute"],
|
|
2093
|
+
[PROOF_JWT]: ["read"],
|
|
2094
|
+
[PROOF_MTLS]: ["read", "write", "admin"],
|
|
2095
|
+
[PROOF_LOOM]: ["read", "write", "execute"],
|
|
2096
|
+
[PROOF_WITNESS]: ["read", "write", "execute", "witness"]
|
|
2097
|
+
};
|
|
2098
|
+
var INTENT_REQUIREMENTS = {
|
|
2099
|
+
"public.*": [],
|
|
2100
|
+
"schema.*": [],
|
|
2101
|
+
"catalog.*": [],
|
|
2102
|
+
"health.*": [],
|
|
2103
|
+
"system.*": [],
|
|
2104
|
+
"file.upload": ["write"],
|
|
2105
|
+
"file.download": ["read"],
|
|
2106
|
+
"file.delete": ["write", "admin"],
|
|
2107
|
+
"passport.issue": ["write", "execute"],
|
|
2108
|
+
"passport.revoke": ["write", "witness"],
|
|
2109
|
+
"stream.publish": ["write"],
|
|
2110
|
+
"stream.subscribe": ["read"],
|
|
2111
|
+
"admin.*": ["admin"]
|
|
2112
|
+
};
|
|
2113
|
+
|
|
2114
|
+
// src/core/frame-validator.ts
|
|
2115
|
+
function validateFrameShape(frame) {
|
|
2116
|
+
if (!frame || typeof frame !== "object") {
|
|
2117
|
+
return false;
|
|
2118
|
+
}
|
|
2119
|
+
if (frame.v !== 1) {
|
|
2120
|
+
return false;
|
|
2121
|
+
}
|
|
2122
|
+
const requiredStrings = ["pid", "nonce", "actorId", "opcode"];
|
|
2123
|
+
for (const key of requiredStrings) {
|
|
2124
|
+
if (typeof frame[key] !== "string" || frame[key].length < 6) {
|
|
2125
|
+
return false;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
if (typeof frame.ts !== "number" || !Number.isFinite(frame.ts)) {
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
if (frame.aud !== void 0 && (typeof frame.aud !== "string" || frame.aud.length === 0)) {
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
if (!frame.sig || typeof frame.sig !== "object") {
|
|
2135
|
+
return false;
|
|
2136
|
+
}
|
|
2137
|
+
if (frame.sig.alg !== "EdDSA") {
|
|
2138
|
+
return false;
|
|
2139
|
+
}
|
|
2140
|
+
if (typeof frame.sig.kid !== "string" || frame.sig.kid.length < 8) {
|
|
2141
|
+
return false;
|
|
2142
|
+
}
|
|
2143
|
+
if (typeof frame.sig.value !== "string" || frame.sig.value.length < 32) {
|
|
2144
|
+
return false;
|
|
2145
|
+
}
|
|
2146
|
+
if (typeof frame.body !== "object" || frame.body === null) {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
return true;
|
|
2150
|
+
}
|
|
2151
|
+
function isTimestampValid(ts, skewSeconds = 120) {
|
|
2152
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
2153
|
+
const diff = Math.abs(now - ts);
|
|
2154
|
+
return diff <= skewSeconds;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// src/core/opcodes.ts
|
|
2158
|
+
var AXIS_OPCODES = /* @__PURE__ */ new Set([
|
|
2159
|
+
"CAPSULE.ISSUE",
|
|
2160
|
+
"CAPSULE.BATCH",
|
|
2161
|
+
"CAPSULE.REVOKE",
|
|
2162
|
+
"INTENT.EXEC",
|
|
2163
|
+
"ACTOR.KEY.ROTATE",
|
|
2164
|
+
"ACTOR.KEY.REVOKE",
|
|
2165
|
+
"ISSUER.KEY.ROTATE"
|
|
2166
|
+
]);
|
|
2167
|
+
function isKnownOpcode(op) {
|
|
2168
|
+
return AXIS_OPCODES.has(op);
|
|
2169
|
+
}
|
|
2170
|
+
function isAdminOpcode(op) {
|
|
2171
|
+
return op.startsWith("ACTOR.KEY.") || op.startsWith("ISSUER.KEY.");
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
// src/core/receipt.ts
|
|
2175
|
+
var import_crypto3 = require("crypto");
|
|
2176
|
+
function buildReceiptHash(prevHash, pid, actorId, intent, effect, ts) {
|
|
2177
|
+
const h = (0, import_crypto3.createHash)("sha256");
|
|
2178
|
+
if (prevHash) h.update(prevHash);
|
|
2179
|
+
h.update(pid);
|
|
2180
|
+
h.update(Buffer.from(actorId, "utf8"));
|
|
2181
|
+
h.update(Buffer.from(intent, "utf8"));
|
|
2182
|
+
h.update(Buffer.from(effect, "utf8"));
|
|
2183
|
+
h.update(Buffer.from(ts.toString(), "utf8"));
|
|
2184
|
+
return h.digest();
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
// src/core/intent-sensitivity.ts
|
|
2188
|
+
var IntentSensitivity = /* @__PURE__ */ ((IntentSensitivity2) => {
|
|
2189
|
+
IntentSensitivity2[IntentSensitivity2["LOW"] = 1] = "LOW";
|
|
2190
|
+
IntentSensitivity2[IntentSensitivity2["MEDIUM"] = 2] = "MEDIUM";
|
|
2191
|
+
IntentSensitivity2[IntentSensitivity2["HIGH"] = 3] = "HIGH";
|
|
2192
|
+
IntentSensitivity2[IntentSensitivity2["CRITICAL"] = 4] = "CRITICAL";
|
|
2193
|
+
return IntentSensitivity2;
|
|
2194
|
+
})(IntentSensitivity || {});
|
|
2195
|
+
var INTENT_SENSITIVITY_MAP = {
|
|
2196
|
+
// System intents
|
|
2197
|
+
"system.ping": 1 /* LOW */,
|
|
2198
|
+
// Catalog intents
|
|
2199
|
+
"catalog.list": 1 /* LOW */,
|
|
2200
|
+
"catalog.search": 1 /* LOW */,
|
|
2201
|
+
"catalog.intent.describe": 1 /* LOW */,
|
|
2202
|
+
"catalog.intent.complete": 1 /* LOW */,
|
|
2203
|
+
// Stream intents
|
|
2204
|
+
"stream.publish": 2 /* MEDIUM */,
|
|
2205
|
+
"stream.read": 2 /* MEDIUM */,
|
|
2206
|
+
"stream.subscribe": 2 /* MEDIUM */,
|
|
2207
|
+
// File intents
|
|
2208
|
+
"file.init": 2 /* MEDIUM */,
|
|
2209
|
+
"file.chunk": 2 /* MEDIUM */,
|
|
2210
|
+
"file.finalize": 2 /* MEDIUM */,
|
|
2211
|
+
"file.status": 1 /* LOW */,
|
|
2212
|
+
// Passport intents
|
|
2213
|
+
"passport.issue": 3 /* HIGH */,
|
|
2214
|
+
"passport.verify": 2 /* MEDIUM */,
|
|
2215
|
+
"passport.revoke": 4 /* CRITICAL */,
|
|
2216
|
+
// Mail intents
|
|
2217
|
+
"mail.send": 3 /* HIGH */,
|
|
2218
|
+
// Admin intents
|
|
2219
|
+
"admin.create_capsule": 4 /* CRITICAL */,
|
|
2220
|
+
"admin.revoke_capsule": 4 /* CRITICAL */,
|
|
2221
|
+
"admin.issue_node_cert": 4 /* CRITICAL */
|
|
2222
|
+
};
|
|
2223
|
+
function classifyIntent(intent) {
|
|
2224
|
+
if (INTENT_SENSITIVITY_MAP[intent]) {
|
|
2225
|
+
return INTENT_SENSITIVITY_MAP[intent];
|
|
2226
|
+
}
|
|
2227
|
+
const realm = intent.split(".")[0];
|
|
2228
|
+
const wildcardKey = `${realm}.*`;
|
|
2229
|
+
if (INTENT_SENSITIVITY_MAP[wildcardKey]) {
|
|
2230
|
+
return INTENT_SENSITIVITY_MAP[wildcardKey];
|
|
2231
|
+
}
|
|
2232
|
+
return 2 /* MEDIUM */;
|
|
2233
|
+
}
|
|
2234
|
+
function sensitivityName(level) {
|
|
2235
|
+
switch (level) {
|
|
2236
|
+
case 1 /* LOW */:
|
|
2237
|
+
return "LOW";
|
|
2238
|
+
case 2 /* MEDIUM */:
|
|
2239
|
+
return "MEDIUM";
|
|
2240
|
+
case 3 /* HIGH */:
|
|
2241
|
+
return "HIGH";
|
|
2242
|
+
case 4 /* CRITICAL */:
|
|
2243
|
+
return "CRITICAL";
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
// src/core/timeouts.ts
|
|
2248
|
+
var INTENT_TIMEOUTS = {
|
|
2249
|
+
"public.*": 5e3,
|
|
2250
|
+
"schema.*": 5e3,
|
|
2251
|
+
"catalog.*": 5e3,
|
|
2252
|
+
"health.*": 2e3,
|
|
2253
|
+
"file.upload": 6e4,
|
|
2254
|
+
"file.download": 6e4,
|
|
2255
|
+
"file.chunk": 3e4,
|
|
2256
|
+
"file.finalize": 3e4,
|
|
2257
|
+
"stream.*": 3e4,
|
|
2258
|
+
"passport.*": 15e3,
|
|
2259
|
+
"admin.*": 3e4
|
|
2260
|
+
};
|
|
2261
|
+
var DEFAULT_TIMEOUT = 1e4;
|
|
2262
|
+
function resolveTimeout(intent) {
|
|
2263
|
+
if (INTENT_TIMEOUTS[intent]) {
|
|
2264
|
+
return INTENT_TIMEOUTS[intent];
|
|
2265
|
+
}
|
|
2266
|
+
for (const [pattern, timeout] of Object.entries(INTENT_TIMEOUTS)) {
|
|
2267
|
+
if (pattern.endsWith(".*")) {
|
|
2268
|
+
const prefix = pattern.slice(0, -1);
|
|
2269
|
+
if (intent.startsWith(prefix)) {
|
|
2270
|
+
return timeout;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return DEFAULT_TIMEOUT;
|
|
2275
|
+
}
|
|
2016
2276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2017
2277
|
0 && (module.exports = {
|
|
2018
2278
|
ATS1_HDR,
|
|
2019
2279
|
ATS1_SCHEMA,
|
|
2020
2280
|
AXIS_MAGIC,
|
|
2281
|
+
AXIS_OPCODES,
|
|
2021
2282
|
AXIS_VERSION,
|
|
2022
2283
|
Ats1Codec,
|
|
2023
2284
|
AxisFrameZ,
|
|
2024
2285
|
AxisPacketTags,
|
|
2286
|
+
BodyProfile,
|
|
2287
|
+
CAPABILITIES,
|
|
2025
2288
|
ContractViolationError,
|
|
2026
2289
|
DEFAULT_CONTRACTS,
|
|
2290
|
+
DEFAULT_TIMEOUT,
|
|
2027
2291
|
Decision,
|
|
2028
2292
|
ERR_BAD_SIGNATURE,
|
|
2029
2293
|
ERR_CONTRACT_VIOLATION,
|
|
@@ -2036,9 +2300,13 @@ var SensorDecisions = {
|
|
|
2036
2300
|
FLAG_HAS_WITNESS,
|
|
2037
2301
|
HANDLER_METADATA_KEY,
|
|
2038
2302
|
Handler,
|
|
2303
|
+
INTENT_REQUIREMENTS,
|
|
2039
2304
|
INTENT_ROUTES_KEY,
|
|
2305
|
+
INTENT_SENSITIVITY_MAP,
|
|
2306
|
+
INTENT_TIMEOUTS,
|
|
2040
2307
|
Intent,
|
|
2041
2308
|
IntentRouter,
|
|
2309
|
+
IntentSensitivity,
|
|
2042
2310
|
MAX_BODY_LEN,
|
|
2043
2311
|
MAX_FRAME_LEN,
|
|
2044
2312
|
MAX_HDR_LEN,
|
|
@@ -2053,12 +2321,14 @@ var SensorDecisions = {
|
|
|
2053
2321
|
NCERT_PUB,
|
|
2054
2322
|
NCERT_SCOPE,
|
|
2055
2323
|
NCERT_SIG,
|
|
2324
|
+
PROOF_CAPABILITIES,
|
|
2056
2325
|
PROOF_CAPSULE,
|
|
2057
2326
|
PROOF_JWT,
|
|
2058
2327
|
PROOF_LOOM,
|
|
2059
2328
|
PROOF_MTLS,
|
|
2060
2329
|
PROOF_NONE,
|
|
2061
2330
|
PROOF_WITNESS,
|
|
2331
|
+
ProofType,
|
|
2062
2332
|
Schema2002_PasskeyLoginOptionsRes,
|
|
2063
2333
|
Schema2011_PasskeyLoginVerifyReq,
|
|
2064
2334
|
Schema2012_PasskeyLoginVerifyRes,
|
|
@@ -2102,10 +2372,13 @@ var SensorDecisions = {
|
|
|
2102
2372
|
b64urlEncodeString,
|
|
2103
2373
|
buildAts1Hdr,
|
|
2104
2374
|
buildPacket,
|
|
2375
|
+
buildReceiptHash,
|
|
2105
2376
|
buildTLVs,
|
|
2106
2377
|
bytes,
|
|
2378
|
+
canAccessResource,
|
|
2107
2379
|
canonicalJson,
|
|
2108
2380
|
canonicalJsonExcluding,
|
|
2381
|
+
classifyIntent,
|
|
2109
2382
|
computeReceiptHash,
|
|
2110
2383
|
computeSignaturePayload,
|
|
2111
2384
|
decodeArray,
|
|
@@ -2122,6 +2395,10 @@ var SensorDecisions = {
|
|
|
2122
2395
|
encodeVarint,
|
|
2123
2396
|
generateEd25519KeyPair,
|
|
2124
2397
|
getSignTarget,
|
|
2398
|
+
hasScope,
|
|
2399
|
+
isAdminOpcode,
|
|
2400
|
+
isKnownOpcode,
|
|
2401
|
+
isTimestampValid,
|
|
2125
2402
|
nonce16,
|
|
2126
2403
|
normalizeSensorDecision,
|
|
2127
2404
|
packPasskeyLoginOptionsReq,
|
|
@@ -2129,6 +2406,9 @@ var SensorDecisions = {
|
|
|
2129
2406
|
packPasskeyLoginVerifyReq,
|
|
2130
2407
|
packPasskeyLoginVerifyRes,
|
|
2131
2408
|
packPasskeyRegisterOptionsReq,
|
|
2409
|
+
parseScope,
|
|
2410
|
+
resolveTimeout,
|
|
2411
|
+
sensitivityName,
|
|
2132
2412
|
sha256,
|
|
2133
2413
|
signFrame,
|
|
2134
2414
|
tlv,
|
|
@@ -2137,6 +2417,7 @@ var SensorDecisions = {
|
|
|
2137
2417
|
unpackPasskeyLoginVerifyReq,
|
|
2138
2418
|
unpackPasskeyRegisterOptionsReq,
|
|
2139
2419
|
utf8,
|
|
2420
|
+
validateFrameShape,
|
|
2140
2421
|
varintLength,
|
|
2141
2422
|
varintU,
|
|
2142
2423
|
verifyFrameSignature
|