import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); async function generateKey() { const keyPair = await crypto.subtle.generateKey( { name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"], ); const publicKey = await crypto.subtle.exportKey("raw", keyPair.publicKey); const pubBytes = new Uint8Array(publicKey); const pubHex = Array.from(pubBytes).map((b) => b.toString(16).padStart(2, "0")).join(""); console.log(`Public key (raw hex): ${pubHex}`); console.log(`\nNOTE: The proper multibase encoding requires a conversion tool.`); console.log(`For production setup, use:\n npx @atproto/dev gen-key\n`); return { keyPair, pubHex }; } function main() { const domain = process.env.DOMAIN || "porchfest.at"; const tmpl = path.resolve(__dirname, "..", "public", ".well-known", "did.json.template"); const out = path.resolve(__dirname, "..", "public", ".well-known", "did.json"); let content = fs.readFileSync(tmpl, "utf-8"); content = content.replace(/porchfest\.at/g, domain); console.log(`Writing ${out} for did:web:${domain}…`); console.log(`\nNEXT STEPS:`); console.log(` 1. Generate a key pair:`); console.log(` npx --yes @atproto/dev gen-key`); console.log(` 2. Copy the publicKeyMultibase into ${out}`); console.log(` 3. Set DNS TXT _atproto.${domain} = "did=did:web:${domain}"`); console.log(` 4. Deploy the site so ${domain}/.well-known/did.json is served`); console.log(` 5. Run a PDS or use a hosted PDS to host the event records`); console.log(`\n OR the simpler route:`); console.log(` 1. Create a Bluesky account with handle ${domain}`); console.log(` 2. Run: BSKY_HANDLE=${domain} BSKY_APP_PASSWORD=... node scripts/publish-atproto-events.mjs`); fs.writeFileSync(out, content); } main();