Files
WT-Offline/scripts/sign-launcher-release.ts
T
N0VAN0M4LY 746b74c564 feat(updates): verify and install launcher releases
Check the versioned release channel, verify the signed manifest and installer digest, and open the installer only after confirmation.

Verified type checks, the Windows package, and an upgrade handoff from a local release fixture, including tampering and interrupted downloads.
2026-11-30 11:12:44 +08:00

35 lines
1.7 KiB
TypeScript

import { readFile, writeFile } from 'node:fs/promises';
import { dirname, join, resolve } from 'node:path';
import { packSigningPublicKey, signEd25519, verifyEd25519 } from '@wto/patcher';
import { installerDigest, launcherSignaturePayload } from '../apps/launcher/src/main/services/app-update/installer-integrity.ts';
import { launcherReleaseFiles, LauncherReleaseManifest } from '../apps/launcher/src/shared/schemas/app-update.ts';
const repository = resolve(import.meta.dirname, '..');
async function main(): Promise<void> {
const { version } = JSON.parse(await readFile(join(repository, 'apps', 'launcher', 'package.json'), 'utf8')) as { version: string };
const files = launcherReleaseFiles(version);
const installer = join(repository, 'build', 'windows-installer', files.installer);
const privateKey = process.env['PATCH_SIGNING_KEY'];
const publicKey = packSigningPublicKey();
if (!privateKey || !publicKey) throw new Error('The project signing key pair is required.');
const manifest = LauncherReleaseManifest.parse({
kind: 'wto-launcher-release',
format: 1,
platform: 'win32-x64',
version,
...await installerDigest(installer),
});
const bytes = Buffer.from(JSON.stringify(manifest, null, 2) + '\n', 'utf8');
const payload = launcherSignaturePayload(bytes);
const signature = signEd25519(payload, privateKey);
if (!verifyEd25519(payload, signature, publicKey)) throw new Error('The release key does not match the bundled public key.');
const folder = dirname(installer);
await writeFile(join(folder, files.manifest), bytes);
await writeFile(join(folder, files.signature), signature, 'utf8');
for (const file of Object.values(files)) console.info(join(folder, file));
}
await main();