feat(reconstruction): add obligation ledgers
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import type { ReconstructionObligation } from "../domain/reconstructionObligationLedgerSchemas.js";
|
||||
|
||||
type ProofAuthority = ReconstructionObligation["required_fixture_authority"];
|
||||
type OriginalAuthority =
|
||||
ReconstructionObligation["required_original_authority"];
|
||||
|
||||
/** Return whether an actual reconstruction proof is comparable to a requirement. */
|
||||
export const proofAuthoritySatisfies = (
|
||||
actual: ProofAuthority,
|
||||
required: ProofAuthority,
|
||||
): boolean => {
|
||||
const accepted: Readonly<Record<ProofAuthority, readonly ProofAuthority[]>> =
|
||||
{
|
||||
unit: [
|
||||
"unit",
|
||||
"integration",
|
||||
"protocol",
|
||||
"renderer",
|
||||
"packaged-process",
|
||||
"native-abi",
|
||||
"live-observation",
|
||||
"external",
|
||||
],
|
||||
integration: [
|
||||
"integration",
|
||||
"protocol",
|
||||
"renderer",
|
||||
"packaged-process",
|
||||
"native-abi",
|
||||
"live-observation",
|
||||
],
|
||||
protocol: ["protocol", "packaged-process", "live-observation"],
|
||||
renderer: ["renderer", "packaged-process", "live-observation"],
|
||||
"packaged-process": ["packaged-process", "live-observation"],
|
||||
"native-abi": ["native-abi"],
|
||||
"live-observation": ["live-observation"],
|
||||
external: ["external"],
|
||||
};
|
||||
return accepted[required].includes(actual);
|
||||
};
|
||||
|
||||
/** Check that Evidence can authenticate the declared reconstruction authority. */
|
||||
export const evidenceAuthoritySupportsProof = (
|
||||
evidence: Evidence,
|
||||
authority: ProofAuthority,
|
||||
): boolean =>
|
||||
evidence.confidence === "observed" &&
|
||||
(authority === "external"
|
||||
? evidence.authority === "external-service"
|
||||
: ["shipped-artifact", "controlled-replay"].includes(evidence.authority));
|
||||
|
||||
/** Check that Evidence observes the original at the required boundary. */
|
||||
export const evidenceSupportsOriginalAuthority = (
|
||||
evidence: Evidence,
|
||||
authority: OriginalAuthority,
|
||||
): boolean => {
|
||||
if (evidence.confidence !== "observed") return false;
|
||||
if (authority === "static") return evidence.authority === "shipped-artifact";
|
||||
if (authority === "runtime")
|
||||
return ["controlled-replay", "external-service"].includes(
|
||||
evidence.authority,
|
||||
);
|
||||
if (authority === "process")
|
||||
return (
|
||||
evidence.operation === "capture_process_scenario" &&
|
||||
evidence.predicate_type === "rea.process-capture/v4"
|
||||
);
|
||||
return evidence.authority === "external-service";
|
||||
};
|
||||
Reference in New Issue
Block a user