#!/usr/bin/env node /** * generate-shell-dev-wallets.mjs — bundle every `.chipnet-keys-*.json` in the * project root into a TS module the Capacitor shell imports. That module fuels * the in-shell Wallet Picker (Settings → Wallets and the Onboarding shortcut) * so the shell is portable across all your dev wallets with one click — no * WIF copy/paste, no re-seeding. * * Output: shells/app/src/devWallets.ts * * Re-run this script after generating new wallets (scripts/generate-addresses.mjs) * so the picker sees them. * * !!! CHIPNET / DEV ONLY !!! The emitted module carries WIFs in plaintext. It is * gitignored. Never run against mainnet keys. */ import { readFileSync, readdirSync, writeFileSync, mkdirSync } from 'node:fs'; import { join, dirname } from 'node:path'; const ROOT = join(import.meta.dirname, '..'); const OUT = join(ROOT, 'shells', 'app', 'src', 'devWallets.ts'); function discover() { return 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, file: f }; }) .sort((a, b) => a.label.localeCompare(b.label)); } function escapeStringLiteral(s) { return s.replace(/\\/g, '\\\\').replace(/'/g, "\\'"); } function main() { const wallets = discover(); if (wallets.length === 0) { console.error('No .chipnet-keys*.json files found — nothing to bundle.'); process.exit(1); } const records = wallets.map(({ label, file }) => { const { wif, cashaddr, tokenaddr } = JSON.parse(readFileSync(join(ROOT, file), 'utf8')); if (!wif || !cashaddr) throw new Error(`${file} missing wif/cashaddr`); return { label, wif, cashaddr, tokenaddr: tokenaddr ?? '' }; }); const lines = [ '// AUTO-GENERATED by scripts/generate-shell-dev-wallets.mjs — do not edit by hand.', '// CHIPNET / DEV ONLY. WIFs are plaintext; file is gitignored.', '// Re-run the generator after adding wallets via scripts/generate-addresses.mjs.', '', 'export interface DevWallet {', ' readonly label: string;', ' readonly cashaddr: string;', ' readonly tokenaddr: string;', ' readonly wif: string;', '}', '', 'export const DEV_WALLETS: readonly DevWallet[] = [', ...records.map( (r) => ` { label: '${escapeStringLiteral(r.label)}', cashaddr: '${escapeStringLiteral(r.cashaddr)}', tokenaddr: '${escapeStringLiteral(r.tokenaddr)}', wif: '${escapeStringLiteral(r.wif)}' },`, ), '];', '', `export const DEV_WALLETS_BUNDLED_AT = '${new Date().toISOString()}';`, '', ]; mkdirSync(dirname(OUT), { recursive: true }); writeFileSync(OUT, lines.join('\n')); console.log(` wrote ${OUT} (${records.length} wallets: ${records.map((r) => r.label).join(', ')})`); } main();