contracts 1.3.0: agent jobs, reports, stats, join/poll, env templates, church export

Jobs of fixed types with strict argument schemas, signed by the Hub with
Ed25519 over canonical JSON. Agent requests signed with the server's
Ed25519 key. Config sealed to the server's X25519 key (X25519 + HKDF +
AES-256-GCM; Node has no XSalsa20). Exports encrypted with a key that
only travels in the download link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 12:02:24 +02:00
co-authored by Claude Opus 5.5
parent 53e15fdd69
commit 90a98a4306
22 changed files with 3645 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* Canonical JSON for signatures: object keys sorted (by UTF-16 code units, as JavaScript sorts),
* no whitespace, `undefined` properties left out. Arrays keep their order. Only plain JSON values
* (no Dates, Maps or functions: convert them first).
*/
export function canonicalJson(value: unknown): string {
if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
if (typeof value === "number") {
if (!Number.isFinite(value)) throw new Error("canonicalJson: numbers must be finite");
return JSON.stringify(value);
}
if (Array.isArray(value)) return `[${value.map((v) => (v === undefined ? "null" : canonicalJson(v))).join(",")}]`;
if (typeof value === "object") {
const proto = Object.getPrototypeOf(value) as unknown;
if (proto !== Object.prototype && proto !== null) throw new Error("canonicalJson: only plain objects");
const obj = value as Record<string, unknown>;
const entries = Object.keys(obj)
.filter((k) => obj[k] !== undefined)
.sort()
.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`);
return `{${entries.join(",")}}`;
}
throw new Error(`canonicalJson: can't encode a ${typeof value}`);
}