43 lines
1.1 KiB
JavaScript

import { unknownLocalAuthority } from "../fixtures/tls.js";
import { TrustRunner } from "../src/index.js";
const villagePlugin = {
manifest: {
id: "community.village.trust",
name: "Village community trust",
role: "decision-authority",
},
collectEvidence({ facts }) {
if (facts.hostname !== "library.village") return;
return {
entries: [
{
kind: "evidence",
code: "known-community-key",
message: "The community has previously observed this certificate.",
},
],
};
},
decide({ facts, journal }) {
const known = journal.entries.some(
(entry) => entry.code === "known-community-key",
);
if (!known) return;
return {
trusted: true,
scope: { hostname: facts.hostname, port: facts.port },
reasonEntryIds: journal.entries
.filter((entry) => entry.code === "known-community-key")
.map((entry) => entry.id),
};
},
};
const result = await new TrustRunner({ plugins: [villagePlugin] }).evaluate(
unknownLocalAuthority,
);
console.log(JSON.stringify(result, null, 2));