deviant/scripts/chipnet-setup-b.mjs
walerikus 518a3ce174 chore: initial project baseline — full Deviant codebase under version control
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>
2026-06-13 20:38:07 +02:00

73 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
/**
* chipnet-setup-b.mjs — generate or load a SECOND chipnet wallet (Wallet B).
*
* Companion to chipnet-setup.mjs (Wallet A, the "founder" wallet that did
* genesis). Used to demonstrate that the open-mint contract is genuinely
* permissionless — any holder of BCH can call mint() on any open-mint
* Deviant token, regardless of who deployed it.
*
* Funded from Wallet A via a one-shot intra-wallet transfer (see
* chipnet-fund-b.mjs). No faucet round-trip needed.
*/
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-b.json');
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 B (independent caller for cross-founder mint test)',
},
null,
2,
),
);
fresh = true;
}
const balance = await wallet.getBalance();
const sats = typeof balance === 'object' ? balance.sat : balance;
divider();
console.log(fresh ? 'Generated Wallet B (fresh).' : 'Loaded Wallet B.');
console.log(`Stored at: ${KEYS_FILE}`);
divider();
console.log(`Receive (BCH): ${wallet.cashaddr}`);
console.log(`Receive (token): ${wallet.tokenaddr}`);
console.log(`Balance: ${sats} sats`);
divider();
if (sats === 0 || sats === 0n) {
console.log('Wallet B is empty. Fund it from Wallet A with:');
console.log(' npm run chipnet:fund-b');
} else {
console.log('Wallet B is funded. Ready to test cross-founder mint.');
}
}
main().catch((err) => {
console.error('FAILED:', err?.message ?? err);
process.exit(1);
});