#!/usr/bin/env node

/**
 * Generates an ES256 JWK for OAuth client authentication.
 *
 * Usage:
 *   node scripts/gen-jwk.mjs
 *
 * Output the JWK and set it as PRIVATE_KEY_ES256 in your environment.
 */

import { JoseKey } from "@atproto/oauth-client-node";

async function main() {
  const kid = `sidetrail-${Date.now()}`;
  const key = await JoseKey.generate(["ES256"], kid);
  const jwk = key.privateJwk;

  console.log("Generated ES256 JWK for OAuth client authentication:\n");
  console.log(JSON.stringify(jwk));
  console.log("\n");
  console.log("Add this to your environment as PRIVATE_KEY_ES256:");
  console.log(`PRIVATE_KEY_ES256='${JSON.stringify(jwk)}'`);
}

main().catch(console.error);
