diff options
Diffstat (limited to 'src/features/ark.js')
| -rw-r--r-- | src/features/ark.js | 50 |
1 files changed, 46 insertions, 4 deletions
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' }, |
