eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

32 lines
1.5 KiB
JavaScript

import { createHash, sign, verify, createPrivateKey, createPublicKey } from 'node:crypto';
export const bodySha256 = value => createHash('sha256').update(value).digest('hex');
export function signPreviewProof(privateKey, payload) {
if (createPrivateKey(privateKey).asymmetricKeyType !== 'ed25519') throw new Error('Ed25519 proof key required');
const encoded = Buffer.from(JSON.stringify(payload)).toString('base64url');
return `${encoded}.${sign(null, Buffer.from(encoded), privateKey).toString('base64url')}`;
}
export function verifyPreviewProof(publicKey, proof, expected, now = Date.now()) {
try {
if (typeof proof !== 'string' || proof.length > 8192 || createPublicKey(publicKey).asymmetricKeyType !== 'ed25519')
return undefined;
const parts = proof.split('.');
if (parts.length !== 2 || !verify(null, Buffer.from(parts[0]), publicKey, Buffer.from(parts[1], 'base64url')))
return undefined;
const value = JSON.parse(Buffer.from(parts[0], 'base64url').toString());
if (
value.schemaVersion !== 1 ||
!Number.isSafeInteger(value.issuedAt) ||
value.issuedAt > now + 5000 ||
now - value.issuedAt > 120000 ||
!Number.isSafeInteger(value.expiresAt) ||
value.expiresAt <= now ||
value.expiresAt - value.issuedAt > 120000
)
return undefined;
for (const [key, wanted] of Object.entries(expected)) if (value[key] !== wanted) return undefined;
return value;
} catch {
return undefined;
}
}