// Live demo of the trustless Ark->Lightning bridge against the coinos
// mutinynet ASP. This is the reference run to point upstream at: everything
// here is public infrastructure, no regtest, no local shortcuts.
//
// wallet --HTLC--> arkswap-staging.coinos.io --pays bolt11--> cl-mut
// bridge claims with the preimage
//
// Usage: BRIDGE_TOKEN=... bun tools/ark/live-bridge-demo.js
//
// Runs entirely over public HTTPS. NB the ASP hostname needs a Cloudflare
// managed-WAF skip for POSTs under /bark_server. and /mailbox_server. —
// binary protobuf trips signature rules above ~1.5KB.
import { execSync } from 'node:child_process';
import { generateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { HDKey } from '@scure/bip32';
import { hex } from '@scure/base';
import { sha256 } from '@noble/hashes/sha256';
import { ArkManager } from '../../src/ark/manager.js';
import { getHtlcPreimage } from '../../src/ark/lightning.js';
const ARK = process.env.ARK_URL || 'https://ark-staging.coinos.io';
const ESPLORA = process.env.ESPLORA_URL || 'https://mutinynet.com/api';
const BRIDGE = process.env.BRIDGE_URL || 'https://arkswap-staging.coinos.io';
const TOKEN = process.env.BRIDGE_TOKEN || '';
const sh = (c) => execSync(c, { shell: '/bin/bash' }).toString().trim();
// invoices come from cl-mut, the same node the bridge pays from — on a demo
// network that's the only node we control; the payment is still a real
// bolt11 settlement observable in listinvoices.
const clmut = (c) => {
const out = sh(`ssh cs 'docker exec cl-mut lightning-cli --signet ${c}'`);
return JSON.parse(out.slice(out.indexOf('{')));
};
const mut = (c) => sh(`ssh cs 'docker exec mut bitcoin-cli -signet -rpcwallet=mutiny ${c}'`);
// A board's funding output MUST be vout 0 (captaind rejects it otherwise) and
// sendtoaddress randomizes output order, so funding goes through a helper on
// cs that pins change to position 1.
const fundBoard = (address, btc) => sh(`ssh cs '~/ark/fund-board.sh ${address} ${btc}'`);
const sleep = (ms) => new Promise((r) => setTimeout(r, | 1 | -4/+27 |