OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-proto-peer / gen-loser-config.mjs

33 lines · javascript ref:
// Derive the loser-club hpp SWARM config from its saved secrets (bundle from secrets, NOT provisionDevice —
// the endpoints are genesis-bound; see the memory). Writes ~/.config/loser-club/peer-config.json for a
// `PEER_CONFIG=… bare index.js` serve pointed at the recovered repo. Run from hyper-proto-peer with bare.
import './lib/bare-globals.js'
import process from 'bare-process'
import { readFileSync, writeFileSync } from 'bare-fs'
import b4a from 'b4a'
import { deviceKeetKeyPair, attestDeviceChain, rootIdentityPublicKey } from 'atproto-room/lib/membership.js'

const HOME = process.env.HOME
const s = JSON.parse(readFileSync(HOME + '/.config/loser-club/secrets.json'))
const MEMBRANE = 'https://pds.7rnx.net'

const founderKp = await deviceKeetKeyPair(s.founderDeviceMnemonic)
const deviceProof = b4a.toString(b4a.from(await attestDeviceChain({ rootMnemonic: s.rootMnemonic, devicePublicKey: founderKp.publicKey })), 'hex')
const rootIdentityKey = b4a.toString(await rootIdentityPublicKey(s.rootMnemonic), 'hex')

const cfg = {
  swarm: true,
  storage: HOME + '/.config/loser-club/repo-recovered',
  did: s.did,
  handle: s.handle,
  pdsUrl: MEMBRANE,
  signingKey: s.signingKey,
  deviceMnemonic: s.founderDeviceMnemonic,
  deviceProof,
  rootIdentityKey
}
const out = HOME + '/.config/loser-club/peer-config.json'
writeFileSync(out, JSON.stringify(cfg, null, 2))
console.log('wrote', out, '— did', cfg.did, 'storage', cfg.storage)
process.exit(0)