49 lines
2.5 KiB
JavaScript
49 lines
2.5 KiB
JavaScript
#!/usr/bin/env node
|
|
// Signs the wayBetter Store catalog with the store's Ed25519 key (detached signature), through the
|
|
// framework CLI (`waybetter store sign|verify`, waybetter/packages/waybetter/cli/store.mjs) with
|
|
// wayBetter for X's defaults.
|
|
//
|
|
// node scripts/sign-store.mjs --init create the store key once (never overwrites)
|
|
// node scripts/sign-store.mjs [catalog.json] sign (default apps/web/public/store/catalog.json)
|
|
// node scripts/sign-store.mjs --verify [file] verify only (signature and catalog rules)
|
|
//
|
|
// Options: --key <path> (private key, default ~/.better-twttr-keys/store.key or $WAYBETTER_STORE_KEY),
|
|
// --pub <path> (public key, default apps/desktop/src-tauri/keys/store.pub, compiled into the app).
|
|
//
|
|
// The signature file `<catalog>.sig` is the base64 of the 64-byte Ed25519 signature over the exact
|
|
// catalog bytes. The public key file is the base64 of the raw 32-byte key. The private key is a
|
|
// PKCS#8 PEM that stays in the key folder: nothing here prints, copies or moves it.
|
|
import { homedir } from 'node:os';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { storeCommand } from '../waybetter/packages/waybetter/cli/store.mjs';
|
|
|
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const DEFAULT_KEY = process.env.WAYBETTER_STORE_KEY || join(homedir(), '.better-twttr-keys', 'store.key');
|
|
const DEFAULT_PUB = join(ROOT, 'apps/desktop/src-tauri/keys/store.pub');
|
|
const DEFAULT_CATALOG = join(ROOT, 'apps/web/public/store/catalog.json');
|
|
|
|
function args(argv) {
|
|
const out = { init: false, verifyOnly: false, key: DEFAULT_KEY, pub: DEFAULT_PUB, file: DEFAULT_CATALOG };
|
|
for (let i = 0; i < argv.length; i += 1) {
|
|
const arg = argv[i];
|
|
if (arg === '--init') out.init = true;
|
|
else if (arg === '--verify') out.verifyOnly = true;
|
|
else if (arg === '--key') out.key = resolve(argv[++i]);
|
|
else if (arg === '--pub') out.pub = resolve(argv[++i]);
|
|
else if (arg.startsWith('--')) throw new Error(`unknown option ${arg}`);
|
|
else out.file = resolve(arg);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
try {
|
|
const o = args(process.argv.slice(2));
|
|
const argv = o.init ? ['sign', '--init', '--key', o.key, '--pub', o.pub]
|
|
: o.verifyOnly ? ['verify', o.file, '--pub', o.pub, '--app', 'x']
|
|
: ['sign', o.file, '--key', o.key, '--pub', o.pub];
|
|
for (const line of await storeCommand(argv)) console.log(line);
|
|
} catch (error) {
|
|
console.error(`sign-store: ${error.message}`);
|
|
process.exit(1);
|
|
}
|