|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { readFileSync, readdirSync } from "node:fs"; |
| 3 | +import { fileURLToPath } from "node:url"; |
| 4 | +import { signConcept } from "@verifiable-okf/signer"; |
| 5 | +import { verifyConcept } from "@verifiable-okf/verifier"; |
| 6 | +import { renderReport, type ReportItem } from "../src/index.js"; |
| 7 | + |
| 8 | +// VOKF-9 worked example: the OKF bundle under examples/ must sign → verify cleanly. |
| 9 | +const bundleDir = fileURLToPath(new URL("../../../examples/okf-bundle", import.meta.url)); |
| 10 | +const SEED = Uint8Array.from(Array.from({ length: 32 }, (_, i) => i + 1)); |
| 11 | +const SIGN = { privateKey: SEED, validFrom: "2026-01-01T00:00:00Z", validUntil: "2027-01-01T00:00:00Z" }; |
| 12 | +const NOW = new Date("2026-06-15T00:00:00Z"); |
| 13 | + |
| 14 | +describe("worked example (examples/okf-bundle)", () => { |
| 15 | + const files = readdirSync(bundleDir).filter((f) => f.endsWith(".md")).sort(); |
| 16 | + |
| 17 | + it("contains a multi-concept bundle", () => { |
| 18 | + expect(files.length).toBeGreaterThanOrEqual(3); |
| 19 | + }); |
| 20 | + |
| 21 | + it("every concept signs then verifies as `verified`", async () => { |
| 22 | + const items: ReportItem[] = []; |
| 23 | + for (const f of files) { |
| 24 | + const signed = signConcept(readFileSync(`${bundleDir}/${f}`), SIGN); |
| 25 | + const result = await verifyConcept(signed, { now: NOW }); |
| 26 | + expect(result.status, f).toBe("verified"); |
| 27 | + items.push({ id: f, result }); |
| 28 | + } |
| 29 | + // and the report renders all of them as verified, offline |
| 30 | + const html = renderReport(items); |
| 31 | + expect((html.match(/>verified</g) ?? []).length).toBe(files.length); |
| 32 | + expect(html).not.toMatch(/(?:src|href)\s*=\s*["']https?:\/\//i); |
| 33 | + }); |
| 34 | +}); |
0 commit comments