// Step 2 — SUBMIT loser-club's genesis op to plc.directory. ⚠️ IRREVERSIBLE (a permanent append to the
// global PLC op-log). Re-derives the identity deterministically from the saved root mnemonic, verifies the
// DID matches the minted one, validates the op (checkGenesisOp), POSTs, and confirms via GET /:did/data.
// Run under node (global fetch): node scripts/submit-loser-club-plc.mjs
import fs from 'node:fs'
import { createSwarmIdentity } from 'atproto-identity'
import { PlcDirectory } from 'atproto-identity/lib/plc-directory.js'
const SECRETS = process.env.HOME + '/.config/loser-club/secrets.json'
const s = JSON.parse(fs.readFileSync(SECRETS, 'utf8'))
const MEMBRANE = 'https://pds.7rnx.net'
const id = createSwarmIdentity(s.rootMnemonic, { handle: s.handle, pdsUrl: MEMBRANE, feedGenEndpoint: MEMBRANE, labelerEndpoint: MEMBRANE })
if (id.did !== s.did) { console.error('DID mismatch — re-derived', id.did, 'vs saved', s.did, '— REFUSING to submit'); process.exit(1) }
console.log('re-derived DID matches:', id.did)
const plc = new PlcDirectory({}) // uses global fetch (node)
console.log('submitting genesis op to plc.directory …')
try {
const data = await plc.submitGenesis({ did: id.did, signedOp: id.signedOp, confirm: true })
console.log('✓ SUBMITTED + confirmed. PLC data:')
console.log(JSON.stringify(data))
} catch (e) {
console.error('submit FAILED:', e.message)
process.exit(1)
}