mail-address-semantics/impl/js/test/signing.test.mjs
tegwick a841ceec73 MAS-WP-0009 T01: independent JS implementation (impl/js), differential test, SCP-9
impl/js (Node, zero deps, written from the specs): parser, v0.2
statute-aware rules, signing, outside master. Passes addresses.json,
statute-aware.json and auth.json unchanged; its master passes the 11
slave-setup mode flows against the Python email side (ExternalMaster).
Differential testing vs mas_core found two unstated stand-in rules, now
SCP-9 in the v0.2 draft with fixtures si-011..013, dt-109; ABNF comments
no longer say v0.1. Runner: external masters, step errors fail the flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 5787@bnt-lap001
Assistant-Session: 5db26b82-138b-40cc-9856-4d5eb0f752fd
2026-10-19 13:22:22 +02:00

27 lines
1,016 B
JavaScript

// mas-modes-v0.1-spec/conformance/auth.json, consumed unchanged (CONTRACT.md section 7).
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { signature, verify, AuthError } from "../src/signing.mjs";
const fx = JSON.parse(readFileSync(new URL("../../../mas-modes-v0.1-spec/conformance/auth.json", import.meta.url)));
for (const v of fx.vectors) {
test(`${v.id} signature`, () => {
assert.equal(signature(Buffer.from(v.key_hex, "hex"), v.timestamp, Buffer.from(v.body, "utf8")), v.signature);
});
}
for (const c of fx.verify) {
test(`${c.id} ${c.why}`, () => {
const keys = Object.fromEntries(Object.entries(c.keys).map(([p, k]) => [p, Buffer.from(k, "hex")]));
let got;
try {
got = verify(c.headers, Buffer.from(c.body, "utf8"), keys, c.now);
} catch (e) {
assert.ok(e instanceof AuthError);
got = "error:" + e.code;
}
assert.equal(got, "peer" in c ? c.peer : "error:" + c.error);
});
}