From 10f9ebc0d047f1599f4665fda0b073c449bb8f64 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 27 Jun 2026 08:41:08 -0700 Subject: Add Boltz submarine + reverse swaps (Lightning <-> on-chain) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Non-custodial swaps via Boltz, fully client-side: hal holds the swap key + preimage and claims (reverse) / refunds (submarine) on-chain via the taproot script path, so Boltz can never strand funds. - src/swap.js: tapleaf/tree construction (byte-exact vs boltz-core vectors), swap P2TR address derivation (MuSig2 internal key + taptweak), script-path claim/refund tx builder, bolt11 decode, Boltz api-v2 client, and a polling SwapManager (reverse auto-claim; submarine fund + status + refund). - wallet.js: deterministic swap-key derivation (dedicated chain) + persistence. - api.js: configurable Boltz REST/WS endpoints. - app.js: ⚡ Swap tab — Receive over LN (reverse) + Pay an invoice (submarine). - tools/swap-*.test.js: vectors, live-address, and end-to-end regtest tests. Verified end-to-end on regtest against a local Boltz wired to coinos's bc + a dedicated CLN/hold node. Co-Authored-By: Claude Opus 4.8 --- src/api.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/api.js') diff --git a/src/api.js b/src/api.js index d135218..d6fa2ee 100644 --- a/src/api.js +++ b/src/api.js @@ -57,6 +57,21 @@ export function setRegtestEsplora(url) { try { localStorage.setItem(REGTEST_ESPLORA_KEY, (url || '').trim()); } catch {} } +// Boltz swap backend endpoints (regtest defaults; the api-v2 REST + the +// sidecar swap-status WebSocket). Overridable in Settings for staging/mainnet. +const BOLTZ_API_KEY = 'btc-wallet-boltz-api'; +const BOLTZ_WS_KEY = 'btc-wallet-boltz-ws'; +export function getBoltzApi() { + try { return (localStorage.getItem(BOLTZ_API_KEY) || '').trim() || 'http://localhost:9001'; } + catch { return 'http://localhost:9001'; } +} +export function getBoltzWs() { + try { return (localStorage.getItem(BOLTZ_WS_KEY) || '').trim() || 'ws://localhost:9004/v2/ws'; } + catch { return 'ws://localhost:9004/v2/ws'; } +} +export function setBoltzApi(url) { try { localStorage.setItem(BOLTZ_API_KEY, (url || '').trim()); } catch {} } +export function setBoltzWs(url) { try { localStorage.setItem(BOLTZ_WS_KEY, (url || '').trim()); } catch {} } + // Resolve the configured explorer to the host list the Api tries in order. function resolveHosts(net) { if (net === 'regtest') { -- cgit v1.2.3