@bsv/expo-wallet-toolbox 0.7.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1790 -0
- package/README.md +54 -1
- package/core/amountFormatHelpers.ts +20 -2
- package/core/backup/RemoteSyncReader.ts +131 -19
- package/core/backup/appData.ts +157 -0
- package/core/backup/client.ts +15 -1
- package/core/backup/codec.ts +147 -9
- package/core/backup/constants.ts +30 -1
- package/core/backup/cursor.ts +31 -2
- package/core/backup/push.ts +70 -4
- package/core/backup/restore.ts +104 -16
- package/core/backup/restoreOnImport.ts +94 -30
- package/core/backup/status.ts +13 -8
- package/core/constants.ts +14 -1
- package/core/context/ExchangeRateContext.tsx +34 -27
- package/core/context/LocalStorageProvider.tsx +43 -40
- package/core/context/UserContext.tsx +18 -7
- package/core/context/VaultContext.tsx +49 -2
- package/core/context/WalletConnectionContext.tsx +203 -11
- package/core/context/WalletContext.tsx +653 -175
- package/core/headers/OfflineFirstChaintracks.ts +48 -4
- package/core/headers/headerStore.ts +26 -4
- package/core/headers/headerSyncTriggers.ts +65 -0
- package/core/headers/syncHeaders.ts +12 -1
- package/core/i18n/translations.tsx +1001 -25
- package/core/identity/handleRegistry/client.ts +31 -2
- package/core/identity/handleRegistry/keyPinStore.ts +70 -0
- package/core/identity/handleRegistry/resolver.ts +71 -3
- package/core/index.ts +33 -3
- package/core/localpay/build.ts +225 -24
- package/core/localpay/pending.ts +110 -7
- package/core/localpay/pendingAbortAuthority.ts +95 -0
- package/core/localpay/pendingAborts.ts +264 -28
- package/core/localpay/session.ts +42 -17
- package/core/localpay/settlementAck.ts +10 -1
- package/core/localpay/transport/socket.ts +52 -3
- package/core/localpay/types.ts +9 -1
- package/core/localpay/verify.ts +143 -16
- package/core/mandala/abortGuard.ts +96 -20
- package/core/mandala/createRuntime.ts +206 -33
- package/core/mandala/drain.ts +89 -11
- package/core/mandala/inboxPrehold.ts +186 -0
- package/core/mandala/permissionModule.ts +202 -20
- package/core/mandala/settlementStore.ts +24 -2
- package/core/mandala/types.ts +40 -5
- package/core/monitor/TaskBackupPush.ts +14 -0
- package/core/monitor/TaskDrainOutbox.ts +14 -0
- package/core/monitor/TaskSendOffline.ts +14 -0
- package/core/net/publicDestination.ts +91 -0
- package/core/net/validateArcUrl.ts +22 -0
- package/core/offline/cancelParked.ts +134 -13
- package/core/offline/payerHold.ts +100 -24
- package/core/offline/plan.ts +36 -7
- package/core/pay/beefRepair.ts +6 -2
- package/core/pay/damagedInbox.ts +24 -0
- package/core/pay/rails/address.ts +107 -12
- package/core/pay/rails/handle.ts +117 -22
- package/core/pay/rails/index.ts +45 -7
- package/core/pay/rails/nativeIntent.ts +61 -0
- package/core/pay/rails/nearby.ts +1 -0
- package/core/pay/receiveHistory.ts +93 -0
- package/core/pay/recordProof.ts +19 -1
- package/core/pay/refreshProofGuard.ts +42 -1
- package/core/pay/watchlist.ts +5 -2
- package/core/peerpay/control.ts +17 -18
- package/core/peerpay/handleResendRequests.ts +58 -4
- package/core/peerpay/outbox.ts +3 -1
- package/core/recovery/backupMaterial.ts +61 -0
- package/core/recovery/createWallet.ts +95 -0
- package/core/recovery/recoverWallet.ts +120 -0
- package/core/recovery/restoreWallet.ts +170 -0
- package/core/recovery/secret.ts +92 -0
- package/core/recovery/shareCollector.ts +71 -0
- package/core/recovery/shareParsing.ts +87 -0
- package/core/recovery/shares.ts +116 -0
- package/core/recovery/useRecoveryDeps.ts +70 -0
- package/core/services/arcTokenStorage.ts +52 -0
- package/core/services/arcadeBroadcastProvider.ts +232 -48
- package/core/services/autoApprovePolicy.ts +105 -0
- package/core/services/callbackToken.ts +19 -0
- package/core/services/capWalletArgs.ts +14 -2
- package/core/services/connectionAuthority.ts +98 -0
- package/core/services/exchangeRate.ts +35 -12
- package/core/services/externalOrigin.ts +11 -0
- package/core/services/secrets/kek.ts +126 -29
- package/core/services/secrets/migration.ts +16 -4
- package/core/services/secrets/store.ts +42 -14
- package/core/services/vault/VaultKeyService.ts +228 -45
- package/core/services/vault/chainRecovery.ts +483 -0
- package/core/services/vault/driver.ts +9 -1
- package/core/services/vault/enrolledSerialRegistry.ts +150 -0
- package/core/services/vault/guard.ts +218 -32
- package/core/services/vault/hardwareLease.ts +19 -0
- package/core/services/vault/metaAuthority.ts +210 -0
- package/core/services/vault/pivReset.ts +64 -23
- package/core/services/vault/r1comb.ts +139 -3
- package/core/services/vault/session.ts +25 -4
- package/core/services/vault/transfers.ts +866 -170
- package/core/services/vault/types.ts +19 -4
- package/core/services/vault/vaultStore.ts +256 -29
- package/core/services/walletArgLimits.ts +45 -2
- package/core/services/walletConnectionValidation.ts +76 -6
- package/core/services/walletServiceConfig.ts +10 -8
- package/core/storage/StorageExpoSQLite.ts +47 -13
- package/core/storage/methods/findSql.ts +21 -2
- package/core/storage/methods/offlineActions.ts +10 -1
- package/core/storage/methods/processOfflineActions.ts +116 -23
- package/core/storage/schema/createTables.ts +126 -2
- package/core/stores/ConnectionStore.ts +34 -0
- package/core/toolboxConfig.ts +45 -11
- package/core/walletDbRegistry.ts +63 -0
- package/core/walletMonitor.ts +17 -1
- package/core/walletRepair/releaseStuckReservations.ts +72 -0
- package/core/walletRepair/shouldMarkUnspendable.ts +20 -0
- package/core/walletRepair/spenderConsumesOutpoint.ts +29 -0
- package/package.json +2 -2
- package/ui/backupShares.ts +26 -169
- package/ui/components/pay/AddressReceive.tsx +13 -6
- package/ui/components/pay/AssetPicker.tsx +30 -9
- package/ui/components/pay/MessageBoxConfig.tsx +16 -0
- package/ui/components/pay/NearbyFlow.tsx +511 -251
- package/ui/components/pay/PaymentSuccessOverlay.tsx +39 -4
- package/ui/components/pay/UniversalSend.tsx +167 -73
- package/ui/components/ui/AlertCard.tsx +38 -5
- package/ui/components/ui/PermissionSheet.tsx +197 -66
- package/ui/components/vault/EnrollWizard.tsx +61 -13
- package/ui/components/vault/vaultErrorCopy.ts +3 -1
- package/ui/components/wallet/ActivityRow.tsx +5 -3
- package/ui/components/wallet/AmountInput.tsx +8 -2
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +22 -2
- package/ui/components/wallet/Balance.tsx +42 -23
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +16 -3
- package/ui/exportTransactions.ts +36 -4
- package/ui/hooks/useExportWalletData.ts +25 -2
- package/ui/importDatabases.ts +339 -24
- package/ui/index.ts +9 -3
- package/ui/isImageUrl.ts +6 -0
- package/ui/printRecoveryShares.ts +9 -10
- package/ui/recoveryPrompts.ts +91 -0
- package/ui/resolveIdentity.ts +31 -9
- package/ui/screens/ConnectionsScreen.tsx +86 -19
- package/ui/screens/IdentifierScreen.tsx +30 -8
- package/ui/screens/PairScreen.tsx +74 -2
- package/ui/screens/SettingsScreen.tsx +10 -4
- package/ui/screens/TrustScreen.tsx +99 -4
- package/ui/screens/VaultScreen.tsx +410 -61
- package/ui/screens/VaultTransferScreen.tsx +59 -7
- package/ui/screens/WalletCheckScreen.tsx +17 -6
- package/ui/screens/WalletConfigScreen.tsx +82 -28
- package/ui/screens/WalletHomeScreen.tsx +179 -88
- package/ui/screens/detailActionKeys.ts +55 -0
- package/ui/tokenFormat.ts +44 -4
- package/ui/txStatus.ts +5 -0
- package/core/storage/LocalStorageAdapter.ts +0 -58
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
isVaultAvailable,
|
|
54
54
|
isBackupPushEnabled,
|
|
55
55
|
getBackupUrl,
|
|
56
|
+
readBackupAttestation,
|
|
56
57
|
type VaultWallet,
|
|
57
58
|
type VaultMeta,
|
|
58
59
|
type VaultSpendResult,
|
|
@@ -176,9 +177,7 @@ export function VaultTransferScreen() {
|
|
|
176
177
|
if (!m || m.keys.length === 0) return
|
|
177
178
|
// Restored records are offered only after this device has proved live
|
|
178
179
|
// possession. Default to the last eligible key, then the first.
|
|
179
|
-
const eligible = m.recovery?.required
|
|
180
|
-
? m.keys.filter(k => m.recovery!.adoptedSerials.includes(k.serial))
|
|
181
|
-
: m.keys
|
|
180
|
+
const eligible = m.recovery?.required ? m.keys.filter(k => m.recovery!.adoptedSerials.includes(k.serial)) : m.keys
|
|
182
181
|
const lastUsed = eligible.find(k => k.serial === m.lastUsedSerial)
|
|
183
182
|
setChosenSerial((lastUsed ?? eligible[0])?.serial)
|
|
184
183
|
})
|
|
@@ -191,9 +190,8 @@ export function VaultTransferScreen() {
|
|
|
191
190
|
// every render would invalidate them all.
|
|
192
191
|
const allKeys = useMemo(() => meta?.keys ?? [], [meta])
|
|
193
192
|
const keys = useMemo(
|
|
194
|
-
() =>
|
|
195
|
-
? allKeys.filter(key => meta.recovery!.adoptedSerials.includes(key.serial))
|
|
196
|
-
: allKeys,
|
|
193
|
+
() =>
|
|
194
|
+
meta?.recovery?.required ? allKeys.filter(key => meta.recovery!.adoptedSerials.includes(key.serial)) : allKeys,
|
|
197
195
|
[meta, allKeys]
|
|
198
196
|
)
|
|
199
197
|
const chosen = keys.find(k => k.serial === chosenSerial)
|
|
@@ -208,10 +206,16 @@ export function VaultTransferScreen() {
|
|
|
208
206
|
? Number.isFinite(sats) && sats >= VAULT_DEPOSIT_MIN
|
|
209
207
|
: isMax || (Number.isFinite(sats) && sats > 0)
|
|
210
208
|
const transfersBlocked = !!meta?.pendingRemoval
|
|
209
|
+
// Six keys is one more than a lock holds (a replacement waiting for the
|
|
210
|
+
// removal of the key it replaces), so nothing that creates a Vault output
|
|
211
|
+
// runs. A deposit always would; a withdrawal only when its remainder is
|
|
212
|
+
// re-vaulted, which run() learns from the preview.
|
|
213
|
+
const overLockLimit = allKeys.length > VAULT_MAX_KEYS
|
|
211
214
|
const canRun =
|
|
212
215
|
validAmount &&
|
|
213
216
|
!busy &&
|
|
214
217
|
!transfersBlocked &&
|
|
218
|
+
!(isDeposit && overLockLimit) &&
|
|
215
219
|
!!pm &&
|
|
216
220
|
balance !== null &&
|
|
217
221
|
(isDeposit ? released : chosen !== undefined)
|
|
@@ -245,6 +249,29 @@ export function VaultTransferScreen() {
|
|
|
245
249
|
if (choice === 'settings') router.push('/wallet-config?section=backup' as never)
|
|
246
250
|
}, [backupConfigured, router])
|
|
247
251
|
|
|
252
|
+
/**
|
|
253
|
+
* XR-003: a distinct, blocking check from `privateBackupEnabled` above —
|
|
254
|
+
* that one gates the encrypted REMOTE backup upload; this one gates the
|
|
255
|
+
* LOCAL mnemonic that alone can recover this vault (I1/I2 — YubiKeys carry
|
|
256
|
+
* no seed) ever having been preserved off-device. VaultScreen's own
|
|
257
|
+
* deposit/enroll entry points already require this before reaching this
|
|
258
|
+
* screen, but a session that reached here some other way (a deep link, or
|
|
259
|
+
* one that skipped the ceremony before this fix shipped) must still be
|
|
260
|
+
* caught at the funding boundary rather than only at first creation.
|
|
261
|
+
*/
|
|
262
|
+
const seedNotPreservedAlert = useCallback(async () => {
|
|
263
|
+
haptics.error()
|
|
264
|
+
const choice = await showAlert({
|
|
265
|
+
title: t('vault_seed_not_preserved_title'),
|
|
266
|
+
message: t('vault_seed_not_preserved_body'),
|
|
267
|
+
buttons: [
|
|
268
|
+
{ text: t('vault_seed_not_preserved_cta'), key: 'backup' },
|
|
269
|
+
{ text: t('vault_cancel'), key: 'cancel', style: 'cancel' }
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
if (choice === 'backup') router.push('/auth/mnemonic?flow=backup' as never)
|
|
273
|
+
}, [router])
|
|
274
|
+
|
|
248
275
|
/** Everything vaultErrorCopy can name for this screen's errors. */
|
|
249
276
|
const errorParams = useCallback(
|
|
250
277
|
(e: unknown): VaultErrorParams => {
|
|
@@ -284,6 +311,15 @@ export function VaultTransferScreen() {
|
|
|
284
311
|
setError(null)
|
|
285
312
|
try {
|
|
286
313
|
if (isDeposit) {
|
|
314
|
+
// XR-003: checked before privateBackupEnabled and before the
|
|
315
|
+
// first-deposit confirmation, for the same reason both of those run
|
|
316
|
+
// early — the user must never be asked to approve a transfer that a
|
|
317
|
+
// missing recovery prerequisite would make catastrophic instead of
|
|
318
|
+
// merely rejected.
|
|
319
|
+
if (!(await readBackupAttestation(pm, adminOriginator))) {
|
|
320
|
+
await seedNotPreservedAlert()
|
|
321
|
+
return
|
|
322
|
+
}
|
|
287
323
|
// Check before first-deposit confirmation so the user is never asked
|
|
288
324
|
// to approve a transfer the service must reject. The service receives
|
|
289
325
|
// the same callback and checks again at the output-creation boundary.
|
|
@@ -340,6 +376,14 @@ export function VaultTransferScreen() {
|
|
|
340
376
|
if (choice !== 'all') return
|
|
341
377
|
withdrawAll = true
|
|
342
378
|
}
|
|
379
|
+
// A remainder that goes back into the vault needs a lock, and six
|
|
380
|
+
// keys is one more than a lock holds. Refuse before any NFC sheet;
|
|
381
|
+
// the service refuses too.
|
|
382
|
+
if (overLockLimit && !withdrawAll && remainder >= VAULT_DEPOSIT_MIN) {
|
|
383
|
+
haptics.error()
|
|
384
|
+
setError(vaultErrorCopy('too-many-active-keys'))
|
|
385
|
+
return
|
|
386
|
+
}
|
|
343
387
|
setBusy(true)
|
|
344
388
|
const result: VaultSpendResult = await withdrawFromVault(
|
|
345
389
|
w,
|
|
@@ -413,6 +457,7 @@ export function VaultTransferScreen() {
|
|
|
413
457
|
balance,
|
|
414
458
|
isDeposit,
|
|
415
459
|
isMax,
|
|
460
|
+
overLockLimit,
|
|
416
461
|
sats,
|
|
417
462
|
keys.length,
|
|
418
463
|
allNames,
|
|
@@ -423,6 +468,7 @@ export function VaultTransferScreen() {
|
|
|
423
468
|
namesFor,
|
|
424
469
|
privateBackupEnabled,
|
|
425
470
|
backupOffAlert,
|
|
471
|
+
seedNotPreservedAlert,
|
|
426
472
|
errorParams,
|
|
427
473
|
refresh,
|
|
428
474
|
router
|
|
@@ -489,7 +535,13 @@ export function VaultTransferScreen() {
|
|
|
489
535
|
)}
|
|
490
536
|
|
|
491
537
|
{transfersBlocked && (
|
|
492
|
-
<Text style={[styles.floor, { color: colors.warning }]}>
|
|
538
|
+
<Text style={[styles.floor, { color: colors.warning }]}>
|
|
539
|
+
{t(meta?.pendingRemoval?.state === 'broadcast' ? 'vault_removal_awaiting_network' : 'vault_err_relock_required')}
|
|
540
|
+
</Text>
|
|
541
|
+
)}
|
|
542
|
+
|
|
543
|
+
{isDeposit && overLockLimit && !transfersBlocked && (
|
|
544
|
+
<Text style={[styles.floor, { color: colors.warning }]}>{t('vault_err_too_many_active_keys')}</Text>
|
|
493
545
|
)}
|
|
494
546
|
|
|
495
547
|
{!isDeposit && meta?.recovery?.required && keys.length === 0 && (
|
|
@@ -29,12 +29,12 @@ import {
|
|
|
29
29
|
} from '../../core/pay/rails/handle'
|
|
30
30
|
import {
|
|
31
31
|
derivationPrefixFor,
|
|
32
|
-
getCurrentDate,
|
|
33
32
|
getPaymentAddress,
|
|
34
|
-
|
|
33
|
+
recoveryDatesToScan,
|
|
35
34
|
sweepAddress,
|
|
36
35
|
wocConfigFor
|
|
37
36
|
} from '../../core/pay/rails/address'
|
|
37
|
+
import { getIssuedDates } from '../../core/pay/receiveHistory'
|
|
38
38
|
import {
|
|
39
39
|
runWalletCheck,
|
|
40
40
|
type WalletCheckPorts,
|
|
@@ -132,6 +132,7 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
132
132
|
adminOriginator,
|
|
133
133
|
storage,
|
|
134
134
|
selectedNetwork,
|
|
135
|
+
getBackupPseudonym,
|
|
135
136
|
checkUtxoSpendability,
|
|
136
137
|
releaseStuckReservations,
|
|
137
138
|
runMonitorTask,
|
|
@@ -143,7 +144,10 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
143
144
|
return useMemo<WalletCheckPorts>(
|
|
144
145
|
() => ({
|
|
145
146
|
checkOnline: async () => ({ online: await getOnline() }),
|
|
146
|
-
|
|
147
|
+
// Scoped to THIS wallet's own identity — see XR-009 / getBackupUploadState. No
|
|
148
|
+
// pseudonym yet (no wallet built for this chain) can never match a real cursor key,
|
|
149
|
+
// so `enabled` still reads the ordinary opt-out preference while `uploaded` is false.
|
|
150
|
+
checkBackup: async () => await getBackupUploadState(selectedNetwork, getBackupPseudonym(selectedNetwork) ?? ''),
|
|
147
151
|
checkPhraseBackup: async () => {
|
|
148
152
|
// Advisory: it records that someone pressed "I have written these
|
|
149
153
|
// down" or completed a print. Nothing verifies the paper exists — but
|
|
@@ -210,9 +214,15 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
210
214
|
if (!wallet) return { imported: 0 }
|
|
211
215
|
const woc = wocConfigFor(selectedNetwork)
|
|
212
216
|
let imported = 0
|
|
213
|
-
|
|
217
|
+
// XR-055: scan every date this device has actually issued a receive address for
|
|
218
|
+
// (pay/receiveHistory.ts), not a fixed 30-day lookback — a payer who sat on a
|
|
219
|
+
// legitimately-displayed address longer than that had no shipped path back to
|
|
220
|
+
// internalizeAction. Falls back to the old fixed-window loop only when there is no
|
|
221
|
+
// recorded history at all (unchanged behaviour for that case).
|
|
222
|
+
const recorded = storage ? await getIssuedDates(storage as never) : []
|
|
223
|
+
for (const date of recoveryDatesToScan(recorded)) {
|
|
214
224
|
try {
|
|
215
|
-
const prefix = derivationPrefixFor(
|
|
225
|
+
const prefix = derivationPrefixFor(date)
|
|
216
226
|
const address = await getPaymentAddress(wallet, adminOriginator, prefix, woc.network)
|
|
217
227
|
const result = await sweepAddress({
|
|
218
228
|
wallet: wallet as never,
|
|
@@ -223,7 +233,7 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
223
233
|
})
|
|
224
234
|
if (result.importedSatoshis > 0) imported++
|
|
225
235
|
} catch {
|
|
226
|
-
// One
|
|
236
|
+
// One date's miss must not skip the rest of the scan.
|
|
227
237
|
}
|
|
228
238
|
}
|
|
229
239
|
return { imported }
|
|
@@ -232,6 +242,7 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
232
242
|
[
|
|
233
243
|
adminOriginator,
|
|
234
244
|
checkUtxoSpendability,
|
|
245
|
+
getBackupPseudonym,
|
|
235
246
|
mandala,
|
|
236
247
|
releaseStuckReservations,
|
|
237
248
|
runMonitorTask,
|
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
KNOWN_ARC_URLS,
|
|
10
10
|
DEFAULT_ARC_URLS,
|
|
11
11
|
arcUrlStorageKey,
|
|
12
|
-
|
|
12
|
+
getArcApiToken,
|
|
13
|
+
setArcApiToken,
|
|
14
|
+
validateArcUrl,
|
|
13
15
|
useTheme,
|
|
14
16
|
spacing,
|
|
15
17
|
typography,
|
|
@@ -176,6 +178,7 @@ export function WalletConfigScreen() {
|
|
|
176
178
|
const [arcUrlInput, setArcUrlInput] = useState('')
|
|
177
179
|
const [arcTokenInput, setArcTokenInput] = useState('')
|
|
178
180
|
const [arcSaving, setArcSaving] = useState(false)
|
|
181
|
+
const [arcUrlError, setArcUrlError] = useState(false)
|
|
179
182
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
180
183
|
|
|
181
184
|
const currentCurrency = settings?.currency || 'BSV'
|
|
@@ -365,15 +368,15 @@ export function WalletConfigScreen() {
|
|
|
365
368
|
}
|
|
366
369
|
}, [storageBusy, storage, managers, adminOriginator, t])
|
|
367
370
|
|
|
368
|
-
// Load persisted ARC URL + token for current network
|
|
371
|
+
// Load persisted ARC URL + token for current network. The token is read
|
|
372
|
+
// via getArcApiToken (XR-106: SecureStore-backed, not plaintext AsyncStorage).
|
|
369
373
|
useEffect(() => {
|
|
370
|
-
Promise.all([
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
})
|
|
374
|
+
Promise.all([AsyncStorage.getItem(arcUrlStorageKey(selectedNetwork)), getArcApiToken(selectedNetwork)]).then(
|
|
375
|
+
([url, token]) => {
|
|
376
|
+
setArcUrlInput(url ?? DEFAULT_ARC_URLS[selectedNetwork] ?? '')
|
|
377
|
+
setArcTokenInput(token ?? '')
|
|
378
|
+
}
|
|
379
|
+
)
|
|
377
380
|
}, [selectedNetwork])
|
|
378
381
|
|
|
379
382
|
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
@@ -405,7 +408,10 @@ export function WalletConfigScreen() {
|
|
|
405
408
|
const result = await importWalletDatabase(storage)
|
|
406
409
|
if (result.imported) {
|
|
407
410
|
showToast(t('import_success'), { type: 'success' })
|
|
408
|
-
|
|
411
|
+
// Not restoreFromBackup: a raw db import already carries a complete
|
|
412
|
+
// local database and must not also replay the encrypted remote
|
|
413
|
+
// backup on top of it — only the same reconciliation pass (XR-079).
|
|
414
|
+
await rebuildWallet({ reviewImportedCoins: true })
|
|
409
415
|
}
|
|
410
416
|
} catch (e) {
|
|
411
417
|
console.warn('[WalletConfig] Import failed:', e)
|
|
@@ -431,20 +437,39 @@ export function WalletConfigScreen() {
|
|
|
431
437
|
|
|
432
438
|
const handleApplyArc = async () => {
|
|
433
439
|
if (arcSaving) return
|
|
440
|
+
const url = arcUrlInput.trim()
|
|
441
|
+
const defaultUrl = DEFAULT_ARC_URLS[selectedNetwork] ?? ''
|
|
442
|
+
// XR-064: a custom endpoint carries the signed transaction (and any
|
|
443
|
+
// configured API token) over the wire — require https, with a narrow
|
|
444
|
+
// loopback exception for local dev.
|
|
445
|
+
if (url && url !== defaultUrl && !validateArcUrl(url)) {
|
|
446
|
+
setArcUrlError(true)
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
setArcUrlError(false)
|
|
434
450
|
setArcSaving(true)
|
|
435
451
|
try {
|
|
436
|
-
const url = arcUrlInput.trim()
|
|
437
452
|
const token = arcTokenInput.trim()
|
|
438
|
-
const
|
|
453
|
+
const previousUrl = (await AsyncStorage.getItem(arcUrlStorageKey(selectedNetwork))) ?? defaultUrl
|
|
454
|
+
const previousToken = (await getArcApiToken(selectedNetwork)) ?? ''
|
|
455
|
+
const nextUrl = url || defaultUrl
|
|
456
|
+
const originChanged = previousUrl !== nextUrl
|
|
457
|
+
// XR-064: a token left exactly as loaded from storage must never
|
|
458
|
+
// silently follow onto a different origin the person just switched
|
|
459
|
+
// to — require it to be re-entered for the new host. A token the
|
|
460
|
+
// person actually typed in this same action (different from what was
|
|
461
|
+
// stored) is an intentional, explicit entry and is still honored.
|
|
462
|
+
const stalePriorToken = originChanged && token === previousToken
|
|
439
463
|
if (url && url !== defaultUrl) {
|
|
440
464
|
await AsyncStorage.setItem(arcUrlStorageKey(selectedNetwork), url)
|
|
441
465
|
} else {
|
|
442
466
|
await AsyncStorage.removeItem(arcUrlStorageKey(selectedNetwork))
|
|
443
467
|
}
|
|
444
|
-
if (token) {
|
|
445
|
-
await
|
|
468
|
+
if (token && !stalePriorToken) {
|
|
469
|
+
await setArcApiToken(selectedNetwork, token)
|
|
446
470
|
} else {
|
|
447
|
-
await
|
|
471
|
+
await setArcApiToken(selectedNetwork, null)
|
|
472
|
+
if (stalePriorToken) setArcTokenInput('')
|
|
448
473
|
}
|
|
449
474
|
setArcExpanded(false)
|
|
450
475
|
await rebuildWallet()
|
|
@@ -458,10 +483,11 @@ export function WalletConfigScreen() {
|
|
|
458
483
|
const handleResetArc = async () => {
|
|
459
484
|
await Promise.all([
|
|
460
485
|
AsyncStorage.removeItem(arcUrlStorageKey(selectedNetwork)),
|
|
461
|
-
|
|
486
|
+
setArcApiToken(selectedNetwork, null)
|
|
462
487
|
])
|
|
463
488
|
setArcUrlInput(DEFAULT_ARC_URLS[selectedNetwork] ?? '')
|
|
464
489
|
setArcTokenInput('')
|
|
490
|
+
setArcUrlError(false)
|
|
465
491
|
setArcExpanded(false)
|
|
466
492
|
await rebuildWallet()
|
|
467
493
|
}
|
|
@@ -660,9 +686,15 @@ export function WalletConfigScreen() {
|
|
|
660
686
|
<View style={localStyles.arcInputRow}>
|
|
661
687
|
<Text style={[localStyles.arcLabel, { color: colors.textSecondary }]}>{t('arc_custom_url')}</Text>
|
|
662
688
|
<TextInput
|
|
663
|
-
style={[
|
|
689
|
+
style={[
|
|
690
|
+
localStyles.arcInput,
|
|
691
|
+
{ color: colors.textPrimary, borderColor: arcUrlError ? colors.error : colors.separator }
|
|
692
|
+
]}
|
|
664
693
|
value={arcUrlInput}
|
|
665
|
-
onChangeText={
|
|
694
|
+
onChangeText={text => {
|
|
695
|
+
setArcUrlInput(text)
|
|
696
|
+
if (arcUrlError) setArcUrlError(false)
|
|
697
|
+
}}
|
|
666
698
|
placeholder="https://..."
|
|
667
699
|
placeholderTextColor={colors.textSecondary}
|
|
668
700
|
autoCapitalize="none"
|
|
@@ -670,6 +702,9 @@ export function WalletConfigScreen() {
|
|
|
670
702
|
keyboardType="url"
|
|
671
703
|
returnKeyType="next"
|
|
672
704
|
/>
|
|
705
|
+
{arcUrlError && (
|
|
706
|
+
<Text style={{ ...typography.caption1, color: colors.error }}>{t('arc_url_https_required')}</Text>
|
|
707
|
+
)}
|
|
673
708
|
</View>
|
|
674
709
|
<View style={localStyles.arcInputRow}>
|
|
675
710
|
<Text style={[localStyles.arcLabel, { color: colors.textSecondary }]}>{t('arc_api_token')}</Text>
|
|
@@ -682,7 +717,9 @@ export function WalletConfigScreen() {
|
|
|
682
717
|
autoCapitalize="none"
|
|
683
718
|
autoCorrect={false}
|
|
684
719
|
returnKeyType="done"
|
|
685
|
-
|
|
720
|
+
// XR-106: this is a live Bearer credential, not display
|
|
721
|
+
// text — mask it like any other secret field.
|
|
722
|
+
secureTextEntry
|
|
686
723
|
/>
|
|
687
724
|
</View>
|
|
688
725
|
<View style={localStyles.arcButtonRow}>
|
|
@@ -955,15 +992,32 @@ export function WalletConfigScreen() {
|
|
|
955
992
|
if (choice !== 'delete') return
|
|
956
993
|
setLoggingOut(true)
|
|
957
994
|
// No artificial yield before this call, unlike the wallet-creation
|
|
958
|
-
// spinner: logout()
|
|
959
|
-
//
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
//
|
|
963
|
-
//
|
|
964
|
-
//
|
|
965
|
-
//
|
|
966
|
-
logout()
|
|
995
|
+
// spinner: logout()'s synchronous prefix (which stops the
|
|
996
|
+
// background monitor's task loop) still runs before its first
|
|
997
|
+
// await, exactly as before — a gap here let the monitor's own
|
|
998
|
+
// pending tick sneak in a fresh task run against storage that
|
|
999
|
+
// was about to be torn down (WERR_UNKNOWN "Database not
|
|
1000
|
+
// initialized" from a task caught mid-flight). Awaiting the
|
|
1001
|
+
// result below only affects what happens AFTER that teardown.
|
|
1002
|
+
//
|
|
1003
|
+
// XR-107: logout() now resolves to whether the secrets layer
|
|
1004
|
+
// verified every legacy plaintext item erased. A persistent
|
|
1005
|
+
// SecureStore delete failure must be reported, not silently
|
|
1006
|
+
// treated as a completed "Delete Wallet" — the user needs to
|
|
1007
|
+
// know and be able to retry, rather than being navigated away
|
|
1008
|
+
// as though nothing were left behind.
|
|
1009
|
+
const erased = await logout()
|
|
1010
|
+
if (!erased) {
|
|
1011
|
+
setLoggingOut(false)
|
|
1012
|
+
await showAlert({
|
|
1013
|
+
title: t('delete_wallet_failed_title'),
|
|
1014
|
+
message: t('delete_wallet_failed_body'),
|
|
1015
|
+
buttons: [{ text: t('vault_ok'), key: 'ok' }],
|
|
1016
|
+
})
|
|
1017
|
+
}
|
|
1018
|
+
// On success logout() has already navigated away — the screen
|
|
1019
|
+
// that owns `loggingOut` is gone, so there is nothing left to
|
|
1020
|
+
// reset here.
|
|
967
1021
|
}}
|
|
968
1022
|
destructive
|
|
969
1023
|
showChevron={false}
|