import { test, expect } from "bun:test"; import { encrypt, decrypt } from "../scripts/operator-crypto"; test("operator envelope authenticates ciphertext and hides plaintext", () => { const password = "operator-only-test-passphrase", secret = { token: "synthetic-token-never-real", shares: ["synthetic-share"], }; const first = encrypt(secret, password), second = encrypt(secret, password); expect(first).not.toBe(second); expect(first.includes(secret.token)).toBe(false); expect(decrypt(first, password)).toEqual(secret); expect(() => decrypt(first, "different-operator-password")).toThrow( "OPERATOR_DECRYPTION_FAILED", ); const envelope = JSON.parse(first); envelope.data = Buffer.from("tampered").toString("base64"); expect(() => decrypt(JSON.stringify(envelope), password)).toThrow( "OPERATOR_DECRYPTION_FAILED", ); }); test("operator envelope requires a sufficiently long passphrase", () => { expect(() => encrypt({}, "short")).toThrow("OPERATOR_PASSWORD_TOO_SHORT"); });