File size: 1,333 Bytes
0427fad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import { TrustDeed } from "./trustDeed.js";
import { Syscall } from "./syscall.js";
export type GateDecision = {
syscall: Syscall;
status: "ALLOW" | "REJECT" | "APPROVAL_REQUIRED";
reason: string;
requiresReceipt: boolean;
};
export function checkSyscall(
deed: TrustDeed,
syscall: Syscall
): GateDecision {
const policy = deed.allowed_syscalls[syscall];
if (!policy) {
return {
syscall,
status: "REJECT",
reason: "Syscall is not defined in trust deed.",
requiresReceipt: true
};
}
if (!policy.enabled) {
return {
syscall,
status: policy.requires_approval ? "APPROVAL_REQUIRED" : "REJECT",
reason: "Syscall is disabled by trust deed.",
requiresReceipt: policy.requires_receipt
};
}
if (policy.requires_approval) {
return {
syscall,
status: "APPROVAL_REQUIRED",
reason: "Syscall requires explicit approval.",
requiresReceipt: policy.requires_receipt
};
}
return {
syscall,
status: "ALLOW",
reason: "Syscall allowed by trust deed.",
requiresReceipt: policy.requires_receipt
};
}
export function checkAllSyscalls(
deed: TrustDeed,
syscalls: Syscall[]
): GateDecision[] {
return syscalls.map((s) => checkSyscall(deed, s));
}
|