44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* derive-chipnet-addresses.mjs — read every `.chipnet-keys*.json`, derive
|
|
* the cashaddr from each WIF, and write a PUBLIC-only JSON to
|
|
* design/explorer/addresses.json
|
|
*
|
|
* No private keys go in the output — only label + cashaddr. Safe to serve
|
|
* over HTTP and check into design/explorer/ for the browser-based dashboard.
|
|
*
|
|
* Run: rtk node scripts/derive-chipnet-addresses.mjs
|
|
* (re-run whenever you add a new chipnet wallet)
|
|
*/
|
|
import { readFileSync, readdirSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { TestNetWallet } from 'mainnet-js';
|
|
|
|
const ROOT = join(import.meta.dirname, '..');
|
|
const OUT_DIR = join(ROOT, 'design', 'explorer');
|
|
const OUT = join(OUT_DIR, 'addresses.json');
|
|
|
|
const wallets = readdirSync(ROOT)
|
|
.filter((f) => /^\.chipnet-keys(-[a-z0-9]+)?\.json$/.test(f))
|
|
.map((f) => {
|
|
const m = /^\.chipnet-keys(?:-([a-z0-9]+))?\.json$/.exec(f);
|
|
const label = m?.[1] ? m[1].toUpperCase() : 'A';
|
|
return { label, path: join(ROOT, f) };
|
|
})
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
|
|
|
const rows = [];
|
|
for (const { label, path } of wallets) {
|
|
const { wif } = JSON.parse(readFileSync(path, 'utf8'));
|
|
const wallet = await TestNetWallet.fromWIF(wif);
|
|
rows.push({ label, cashaddr: wallet.cashaddr });
|
|
}
|
|
|
|
if (!existsSync(OUT_DIR)) mkdirSync(OUT_DIR, { recursive: true });
|
|
writeFileSync(OUT, JSON.stringify({ network: 'chipnet', generatedAt: new Date().toISOString(), wallets: rows }, null, 2));
|
|
|
|
console.log(`Wrote ${rows.length} chipnet addresses → ${OUT}`);
|
|
for (const r of rows) console.log(` ${r.label} ${r.cashaddr}`);
|
|
|
|
// mainnet-js holds WSS sockets open; exit explicitly so the script ends.
|
|
process.exit(0);
|