32 lines · 1.6 KB · TypeScriptRaw
/** * Sealed at arrival (e2e rulings R2): the Worker seals a row to the person's * arrival key byte for byte as the core does (vectors/seal/arrival.json), * and a device holding the data key opens it (the core's test of the same * vector). */import { describe, expect, it } from "vitest";import V from "../../../crates/cotton-conformance/vectors/seal/arrival.json";import { isArrivalRow, keyFromText, sealAtArrival } from "../src/arrival.ts";const hex = (h: string): Uint8Array => Uint8Array.from(h.match(/../g)!.map((b) => parseInt(b, 16)));describe("sealed at arrival", () => { it("seals the vector's row byte for byte as the core does", async () => { const stored = await sealAtArrival(keyFromText(V.arrival_pub)!, V.database, V.table, V.id, { clear: V.clear, blind: [], blind_exact: [] }, V.row, { dek: hex(V.dek_hex), bodyNonce: hex(V.body_nonce_hex), ephemeral: hex(V.ephemeral_hex), wrapNonce: hex(V.wrap_nonce_hex), }); expect(stored).toEqual(V.stored); expect(isArrivalRow(stored)).toBe(true); }); it("keeps no typed word in the clear and refuses a column the sealer writes", async () => { const stored = await sealAtArrival(keyFromText(V.arrival_pub)!, V.database, V.table, V.id, { clear: V.clear, blind: [], blind_exact: [] }, V.row); expect(JSON.stringify(stored)).not.toContain("Lantern"); expect(stored.day).toBe("2026-11-15"); await expect(sealAtArrival(keyFromText(V.arrival_pub)!, V.database, V.table, V.id, { clear: [], blind: [], blind_exact: [] }, { seal_v: 3 })).rejects.toThrow("seal_column_clash"); });});