1import { describe, expect, test, vi } from "vitest";2import { runSelfTest } from "./self-test";34describe("Peach crypto KAT (self-test)", () => {5 test("passes with the correct crypto stack", async () => {6 const result = await runSelfTest();7 expect(result.ok).toBe(true);8 expect(result.error).toBeUndefined();9 });1011 12 13 14 test("fails when the produced ciphertext diverges from the pinned vector", async () => {15 const realEncrypt = crypto.subtle.encrypt.bind(crypto.subtle);16 const spy = vi17 .spyOn(crypto.subtle, "encrypt")18 .mockImplementation(async (...args: Parameters<typeof realEncrypt>) => {19 const ct = new Uint8Array(await realEncrypt(...args));20 ct[0] ^= 0xff; 21 return ct.buffer;22 });2324 const result = await runSelfTest();25 expect(result.ok).toBe(false);26 expect(result.error).toContain("does not match the pinned test vector");2728 spy.mockRestore();29 });30});