From befa01bc9b2c144c020b403429db20bc5278db93 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 4 Dec 2026 13:18:47 -0700 Subject: Spending moves to ark2.coinos.io by itself: coins on the retired server go across through coinos's migrator. ark.coinos.io's server key was stolen in the 2026-12-04 breach, so coinos stood up ark2.coinos.io with a fresh key. The "coinos" preset now points there (same id, so everyone on coinos follows), and the old server stays as a hidden, retiring preset whose successor is "coinos" and whose migrator is migrate.coinos.io. After connecting, a wallet that still holds spendable coins on the old server opens that wallet (same seed, same keys), asks the migrator for a deposit address naming its own ark2 address, and sends everything there in batches of the largest coins (at most 48 per payment, as the old server can't run consolidation rounds). The migrator pays the same amount on ark2; a toast says it arrived. Coins at the exit-depth cap stay behind. arkWanted() also counts coins waiting on a retiring server, so a wallet whose coins are all there still connects. src/ark/migrate.js holds the logic apart from the UI. ArkManager gains freshAddress()/_addressFor(i): an address on a key of its own, mailbox id blinded with that key (what the migrator hands out per migration). Tested end to end on regtest against two captaind 0.8.0-coinos servers and the real migrator (coinosv3-server migrator/e2e-test.js: 19 checks, incl. batching, caps and restart-safety). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar --- src/features/ark.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'src/features') diff --git a/src/features/ark.js b/src/features/ark.js index 2c1a581..b95f8c0 100644 --- a/src/features/ark.js +++ b/src/features/ark.js @@ -9,6 +9,7 @@ import { HDKey } from '@scure/bip32'; import { hex, base32nopad, bech32 } from '@scure/base'; import { sha256 } from '@noble/hashes/sha256'; import { ArkManager, remoteRenewalsInFlight, lnFoldedIds, sameDelivery, renewPolicy, CUSTODY_TIERS } from '../ark/manager.js'; +import { migrateWallet, awaitMigration } from '../ark/migrate.js'; export { remoteRenewalsInFlight }; // Coins this device may offer: spendable, and not held by a renewal another @@ -575,7 +576,15 @@ export function arkFeature(ctx) { const cfg = getArkConfig(); const st = cfg && peekArk(wallet, cfg.ark); return !!(st && ((st.vtxos || []).length || (st.movements || []).length - || (st.actions || []).some((a) => !['done', 'failed'].includes(a.step)))); + || (st.actions || []).some((a) => !['done', 'failed'].includes(a.step)))) + || retiringWithCoins().length > 0; // coins on a retired server: connect so they can move + } + // Retired servers this wallet still holds spendable coins on, whose + // successor is the server it's on now (ark.coinos.io → ark2.coinos.io). + function retiringWithCoins() { + const cur = getArkProviderId(); + return arkPresets(getNetwork()).filter((p) => p.retiring && p.successor === cur && p.migrator && p.ark + && (peekArk(wallet, p.ark)?.vtxos || []).some((v) => v.state === 'spendable')); } function initArk() { @@ -593,7 +602,7 @@ export function arkFeature(ctx) { return; } if (safeBoot()) return; // safe mode: the coins show from the store; nothing dials out unasked - if (arkAvailable() && arkWanted()) { lastAutoInit = Date.now(); connectArk().then(() => rescueOtherServers()).catch(() => {}); } + if (arkAvailable() && arkWanted()) { lastAutoInit = Date.now(); connectArk().then(() => migrateRetiring()).then(() => rescueOtherServers()).catch(() => {}); } } // Automatic re-inits (a synced snapshot arriving) must not restart a @@ -608,6 +617,39 @@ export function arkFeature(ctx) { // every other server this wallet holds state with gets a short visit — its // own manager, a receive rescan, a sync to claim — and a toast says what // arrived and where. The coins stay with that server until a switch back. + // coinos retired its first Ark server (its key was stolen 2026-12-04). A + // wallet still holding coins there moves them to the successor on its + // own: the migrator gives a deposit address on the old server and pays the + // same amount to this wallet's address on the new one. Once per session. + let migratedRetiring = false; + async function migrateRetiring() { + if (migratedRetiring || wallet.watchOnly || !ark) return; + const list = retiringWithCoins(); + if (!list.length) return; + migratedRetiring = true; + for (const p of list) { + try { + const mgr = new ArkManager({ + account: wallet.account(), + storage: { + load: () => wallet.loadArkState(p.ark), + adopt: (serverPubkey) => wallet.adoptArkState(serverPubkey, p.ark), + save: (s) => { wallet.saveArkState(mergeArkStates(s, wallet.loadArkState(p.ark)), p.ark); }, + }, + arkUrl: p.ark, esploraUrl: p.esplora, network: getNetwork(), honorsExpired: !!p.honorsExpired, + }); + await mgr.init(); + await mgr.sync(); + if (!mgr.balance().spendableSat) continue; + const res = await migrateWallet(mgr, { migratorUrl: p.migrator, dest: ark.address(), log: (m) => console.log('ark: ' + m) }); + if (!res.sentSat) continue; + const fin = await awaitMigration(p.migrator, res.id, { timeoutMs: 90000 }); + await ark.sync().catch(() => {}); + toast(t(fin?.status === 'done' ? 'arkMigrated' : 'arkMigratePending', { amount: fmtSats(res.sentSat) }), 9000); + render(); + } catch (e) { console.warn('ark: moving coins off ' + p.ark + ' failed', e); } + } + } let rescuedServers = false; async function rescueOtherServers() { if (rescuedServers || wallet.watchOnly) return; @@ -2846,7 +2888,7 @@ export function arkFeature(ctx) { return parts.join(', '); }; function arkServerCompare(presets) { - const cols = presets.filter((p) => p.ark && p.id !== 'custom'); + const cols = presets.filter((p) => p.ark && p.id !== 'custom' && !p.hidden); if (cols.length < 2) return null; const infos = cols.map((p) => serverInfo(p.ark)); const cell = (i, f) => (i === undefined ? '…' : i === null ? '—' : f(i)); @@ -2904,7 +2946,7 @@ export function arkFeature(ctx) { h('h3', {}, t('arkServerTitle')), h('p', { class: 'small muted', style: 'margin:0' }, t('arkServerDesc')), h('select', { onChange: (e) => pick(e.target.value) }, - ...presets.map((p) => h('option', { value: p.id, selected: p.id === (c || cur) }, p.label))), + ...presets.filter((p) => !p.hidden || p.id === (c || cur)).map((p) => h('option', { value: p.id, selected: p.id === (c || cur) }, p.label))), h('button', { class: 'linklike small', style: 'align-self:flex-start', onClick: () => { ui.arkCmpOpen = !ui.arkCmpOpen; render(); } }, ui.arkCmpOpen ? t('arkCmpHide') : t('arkCmpShow')), ui.arkCmpOpen ? arkServerCompare(presets) : null, (c === 'custom' || cur === 'custom') ? h('div', { class: 'col', style: 'gap:6px' }, -- cgit v1.2.3