Brings the whole project into git (previously only the on-ramp feature and a few parallel files were tracked). Includes: wallet core (src/), CashScript contracts/, the Capacitor shell (shells/), scripts/, tests, and the docs corpus (wiki/, snapshots/, Parameters/, Archive/, KnowledgeBase text). Excluded via .gitignore: node_modules/, dist/, .env (secrets), testnet WIF key files (.chipnet-*.json, devWallets.ts), KnowledgeBase/RAW media (~9.6 GB), transcripts/ (session logs), and machine-local config (.claude/*.local, *.lock). Secret-scanned before commit — no credentials in the tree. Note: src/swapMath.ts, src/swapBuilder.ts, contracts/OpenMintToken.cash are legacy (OP_RETURN era) but still imported; committed as-is, flagged for a separate removal once de-referenced. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* chipnet-setup-d.mjs — generate or load a FOURTH chipnet wallet (Wallet D).
|
|
*
|
|
* Wallet D is an independent identity for the next round of tests, funded
|
|
* directly from the chipnet faucet (like Wallet C) so its BCH has no
|
|
* provenance link to Wallets A/B. Idempotent: first run generates a fresh
|
|
* WIF and saves it to `.chipnet-keys-d.json` (gitignored); subsequent runs
|
|
* reload that file and just re-check the balance.
|
|
*/
|
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { TestNetWallet } from 'mainnet-js';
|
|
|
|
const ROOT = join(import.meta.dirname, '..');
|
|
const KEYS_FILE = join(ROOT, '.chipnet-keys-d.json');
|
|
|
|
const FAUCETS = [
|
|
'https://tbch.googol.cash/',
|
|
'https://bitcoincash-faucet.com/',
|
|
];
|
|
|
|
function divider() {
|
|
console.log('='.repeat(72));
|
|
}
|
|
|
|
async function main() {
|
|
let wallet;
|
|
let fresh;
|
|
if (existsSync(KEYS_FILE)) {
|
|
const { wif } = JSON.parse(readFileSync(KEYS_FILE, 'utf8'));
|
|
wallet = await TestNetWallet.fromWIF(wif);
|
|
fresh = false;
|
|
} else {
|
|
wallet = await TestNetWallet.newRandom();
|
|
writeFileSync(
|
|
KEYS_FILE,
|
|
JSON.stringify(
|
|
{
|
|
wif: wallet.privateKeyWif,
|
|
cashaddr: wallet.cashaddr,
|
|
tokenaddr: wallet.tokenaddr,
|
|
generated: new Date().toISOString(),
|
|
network: 'chipnet',
|
|
role: 'wallet D (independent, faucet-funded)',
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
fresh = true;
|
|
}
|
|
|
|
let sats;
|
|
try {
|
|
const balance = await wallet.getBalance();
|
|
sats = typeof balance === 'object' ? balance.sat : balance;
|
|
} catch (err) {
|
|
sats = null; // network unreachable from here — address is still valid to fund
|
|
console.error(`(balance check skipped: ${err?.message ?? err})`);
|
|
}
|
|
|
|
divider();
|
|
console.log(fresh ? 'Generated Wallet D (fresh).' : 'Loaded Wallet D.');
|
|
console.log(`Stored at: ${KEYS_FILE}`);
|
|
divider();
|
|
console.log(`Receive (BCH): ${wallet.cashaddr}`);
|
|
console.log(`Receive (token): ${wallet.tokenaddr}`);
|
|
console.log(`Balance: ${sats === null ? 'unknown (offline)' : `${sats} sats`}`);
|
|
divider();
|
|
if (sats === null || sats === 0 || sats === 0n) {
|
|
console.log('Wallet D needs funding. Fund it from a chipnet faucet:');
|
|
for (const url of FAUCETS) console.log(` - ${url}`);
|
|
console.log('');
|
|
console.log('Paste this address into the faucet:');
|
|
console.log(` ${wallet.cashaddr}`);
|
|
console.log('Then re-run this script to confirm the balance.');
|
|
process.exitCode = 2;
|
|
} else {
|
|
console.log('Wallet D is funded. Ready for instructions.');
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('FAILED:', err?.message ?? err);
|
|
process.exit(1);
|
|
});
|