// Run after changing any plugin: pins each file's SHA-256 in registry.json and // writes registry.json.sig. Exbyte Depot refuses a catalog with a bad signature. // Usage: node tools/sign-registry.mjs import { createHash, createPrivateKey, sign } from "node:crypto"; import { readFileSync, writeFileSync } from "node:fs"; const root = new URL("../", import.meta.url); const keyPath = process.argv[2]; if (!keyPath) { console.error("Usage: node tools/sign-registry.mjs "); process.exit(1); } const reg = JSON.parse(readFileSync(new URL("registry.json", root), "utf8")); for (const p of reg.plugins) { p.sha256 = {}; for (const f of p.files) { p.sha256[f] = createHash("sha256").update(readFileSync(new URL(`plugins/${p.id}/${f}`, root))).digest("hex"); } } reg.updated = new Date().toISOString().replace(/\.\d+Z$/, "Z"); const text = JSON.stringify(reg, null, 2) + "\n"; writeFileSync(new URL("registry.json", root), text); const signature = sign(null, Buffer.from(text, "utf8"), createPrivateKey(readFileSync(keyPath))); writeFileSync(new URL("registry.json.sig", root), signature.toString("base64") + "\n"); console.log(`Signed ${reg.plugins.length} plugin(s).`);