@bsv/expo-wallet-toolbox 0.10.0 → 0.11.2

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.
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Point lookups the external-wallet guard (core/services/vault/guard.ts) runs
3
+ * before it lets a connected app name an existing output or release a held
4
+ * transaction.
5
+ *
6
+ * Each query touches only the rows the caller named, reads basket names,
7
+ * labels and tags, and stops at the first hit. None of them select a locking script,
8
+ * so a Vault output's ~45 KB R1C script never leaves the database.
9
+ *
10
+ * No `userId` filter: a StorageExpoSQLite file belongs to one identity. If a
11
+ * file ever held more than one user, a hit on another user's row would refuse
12
+ * the call, which is the safe direction.
13
+ */
14
+
15
+ /** BRC-100 reserves every basket and label that starts with this for the
16
+ * wallet itself (WalletPermissionsManager's `isAdminBasket`/`isAdminLabel`). */
17
+ export const ADMIN_PREFIX = 'admin'
18
+
19
+ /** The label every Vault deposit, withdrawal and re-lock carries. */
20
+ export const VAULT_ACTION_LABEL = 'vault'
21
+
22
+ /** The tag every Vault output carries, from a deposit, re-lock or chain
23
+ * recovery alike. Chain recovery internalizes without a `vault` label. */
24
+ export const VAULT_OUTPUT_TAG = 'vault'
25
+
26
+ /** Placeholders per statement, kept under the lowest SQLITE_MAX_VARIABLE_NUMBER
27
+ * a shipped SQLite still enforces (999). */
28
+ const MAX_BOUND_VARIABLES = 998
29
+
30
+ const IS_ADMIN_BASKET = `substr("b"."name", 1, ${ADMIN_PREFIX.length}) = '${ADMIN_PREFIX}'`
31
+
32
+ /** The transaction whose id is `transactionIdSql` carries the `vault` label or
33
+ * an `admin*` label. */
34
+ function hasAdminLabel(transactionIdSql: string): string {
35
+ return (
36
+ 'EXISTS (SELECT 1 FROM "tx_labels_map" "m" JOIN "tx_labels" "l" ON "l"."txLabelId" = "m"."txLabelId" ' +
37
+ `WHERE "m"."transactionId" = ${transactionIdSql} AND ("l"."label" = '${VAULT_ACTION_LABEL}' ` +
38
+ `OR substr("l"."label", 1, ${ADMIN_PREFIX.length}) = '${ADMIN_PREFIX}'))`
39
+ )
40
+ }
41
+
42
+ /** The output `o` carries the Vault output tag. */
43
+ const HAS_VAULT_TAG =
44
+ 'EXISTS (SELECT 1 FROM "output_tags_map" "tm" JOIN "output_tags" "tg" ON "tg"."outputTagId" = "tm"."outputTagId" ' +
45
+ `WHERE "tm"."outputId" = "o"."outputId" AND "tg"."tag" = '${VAULT_OUTPUT_TAG}')`
46
+
47
+ /**
48
+ * An output row `o` (with its basket LEFT JOINed as `b`) is admin state when it
49
+ * sits in an `admin`-prefixed basket, or when it has no basket (relinquished,
50
+ * e.g. by "forget unreachable deposits") and is still recognisably a Vault or
51
+ * admin output: tagged `vault`, or created by a `vault`/`admin*`-labelled
52
+ * transaction. The label and tag count only for an unbasketed row, so an
53
+ * app's own basketed outputs never collide with them.
54
+ *
55
+ * `default` is deliberately not included: an app retrying internalizeAction
56
+ * for a payment the wallet already holds as change names a `default` output,
57
+ * and the toolbox treats that retry as a no-op.
58
+ */
59
+ const IS_ADMIN_OUTPUT =
60
+ `((${IS_ADMIN_BASKET}) OR ` +
61
+ `("o"."basketId" IS NULL AND (${HAS_VAULT_TAG} OR ${hasAdminLabel('"o"."transactionId"')})))`
62
+
63
+ const OUTPUT_WITH_BASKET = 'FROM "outputs" "o" LEFT JOIN "output_baskets" "b" ON "b"."basketId" = "o"."basketId" '
64
+
65
+ /**
66
+ * Hit when any named outpoint is admin state (see IS_ADMIN_OUTPUT).
67
+ *
68
+ * One OR-group per outpoint rather than a row-value IN, so the query works on
69
+ * any SQLite build (same shape as `spendingReferencesSql`).
70
+ */
71
+ export function adminOutpointsSql(pairCount: number): string {
72
+ const groups = Array.from({ length: pairCount }, () => '("o"."txid" = ? AND "o"."vout" = ?)').join(' OR ')
73
+ return `SELECT 1 AS hit ${OUTPUT_WITH_BASKET}WHERE (${groups}) AND ${IS_ADMIN_OUTPUT} LIMIT 1`
74
+ }
75
+
76
+ /** Hit when the output with this `outputId` is admin state. */
77
+ export const ADMIN_OUTPUT_BY_ID_SQL = `SELECT 1 AS hit ${OUTPUT_WITH_BASKET}WHERE "o"."outputId" = ? AND ${IS_ADMIN_OUTPUT} LIMIT 1`
78
+
79
+ /**
80
+ * Hit when any named txid is a Vault or admin transaction: labelled `vault` or
81
+ * `admin*`, or creating or spending an output in an admin-prefixed basket.
82
+ *
83
+ * Spending is matched through `outputs.spentBy`, which the toolbox sets when
84
+ * an action reserves its inputs, so a signed-but-held withdrawal is caught
85
+ * before it is broadcast.
86
+ */
87
+ export function adminTransactionsSql(txidCount: number): string {
88
+ const placeholders = Array.from({ length: txidCount }, () => '?').join(', ')
89
+ return (
90
+ 'SELECT 1 AS hit FROM "transactions" "t" ' +
91
+ `WHERE "t"."txid" IN (${placeholders}) AND (` +
92
+ `${hasAdminLabel('"t"."transactionId"')} ` +
93
+ 'OR EXISTS (SELECT 1 FROM "outputs" "o" JOIN "output_baskets" "b" ON "b"."basketId" = "o"."basketId" ' +
94
+ `WHERE "o"."transactionId" = "t"."transactionId" AND ${IS_ADMIN_BASKET}) ` +
95
+ 'OR EXISTS (SELECT 1 FROM "outputs" "o" JOIN "output_baskets" "b" ON "b"."basketId" = "o"."basketId" ' +
96
+ `WHERE "o"."spentBy" = "t"."transactionId" AND ${IS_ADMIN_BASKET})` +
97
+ ') LIMIT 1'
98
+ )
99
+ }
100
+
101
+ /** The slice of an expo-sqlite handle these lookups use. */
102
+ export interface GuardSqlDb {
103
+ getFirstAsync(sql: string, params: (string | number)[]): Promise<unknown>
104
+ }
105
+
106
+ /** `txid.vout` pairs, as the guard canonicalizes them (lowercase txid). */
107
+ export async function anyAdminOutpoint(db: GuardSqlDb, outpoints: string[]): Promise<boolean> {
108
+ const pairs = outpoints.map(outpoint => {
109
+ const dot = outpoint.lastIndexOf('.')
110
+ const txid = outpoint.slice(0, dot).toLowerCase()
111
+ const vout = Number(outpoint.slice(dot + 1))
112
+ if (!/^[0-9a-f]{64}$/.test(txid) || !Number.isSafeInteger(vout) || vout < 0) {
113
+ throw new Error(`Invalid outpoint ${outpoint}`)
114
+ }
115
+ return [txid, vout] as const
116
+ })
117
+ const perStatement = Math.floor(MAX_BOUND_VARIABLES / 2)
118
+ for (let i = 0; i < pairs.length; i += perStatement) {
119
+ const chunk = pairs.slice(i, i + perStatement)
120
+ if (await db.getFirstAsync(adminOutpointsSql(chunk.length), chunk.flat())) return true
121
+ }
122
+ return false
123
+ }
124
+
125
+ export async function anyAdminTransaction(db: GuardSqlDb, txids: string[]): Promise<boolean> {
126
+ const normalized = txids.map(txid => {
127
+ const lower = txid.toLowerCase()
128
+ if (!/^[0-9a-f]{64}$/.test(lower)) throw new Error(`Invalid txid ${txid}`)
129
+ return lower
130
+ })
131
+ for (let i = 0; i < normalized.length; i += MAX_BOUND_VARIABLES) {
132
+ const chunk = normalized.slice(i, i + MAX_BOUND_VARIABLES)
133
+ if (await db.getFirstAsync(adminTransactionsSql(chunk.length), chunk)) return true
134
+ }
135
+ return false
136
+ }
137
+
138
+ export async function isAdminOutput(db: GuardSqlDb, outputId: number): Promise<boolean> {
139
+ return !!(await db.getFirstAsync(ADMIN_OUTPUT_BY_ID_SQL, [outputId]))
140
+ }
@@ -27,7 +27,10 @@ export function bytesForColumn(column: string, value: unknown): Uint8Array | und
27
27
  /** Map an update field to a SQL bind, or omit it from the SET clause. */
28
28
  export function sqlBindValue(table: string, column: string, value: unknown): SqlBindResult {
29
29
  if (value === undefined) {
30
- if (table === 'outputs' && column === 'spentBy') {
30
+ // Both mean "cleared" to their writers: spentBy on a released reservation,
31
+ // basketId on relinquishOutput and on a synced relinquish arriving through
32
+ // EntityOutput.mergeExisting. Skipping either left the old value in place.
33
+ if (table === 'outputs' && (column === 'spentBy' || column === 'basketId')) {
31
34
  return { omit: false, value: null }
32
35
  }
33
36
  return { omit: true }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.10.0",
3
+ "version": "0.11.2",
4
4
  "private": false,
5
5
  "description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -83,6 +83,7 @@ const KEY: Record<VaultErrorCode, string> = {
83
83
  'not-enough-keys': 'vault_err_not_enough_keys',
84
84
  'key-already-enrolled': 'vault_err_key_already_enrolled',
85
85
  'key-not-adopted': 'vault_err_key_not_adopted',
86
+ 'key-opens-nothing': 'vault_err_key_opens_nothing',
86
87
  'too-many-keys': 'vault_err_too_many_keys',
87
88
  'too-many-active-keys': 'vault_err_too_many_active_keys',
88
89
  'last-keys': 'vault_err_last_keys',
@@ -13,19 +13,15 @@
13
13
  * XR-086: exportAllWalletDatabases() writes the raw, unencrypted SQLite image
14
14
  * straight to the OS share sheet — identity keys, certificate fields,
15
15
  * transaction/derivation metadata and contacts, with no passphrase or
16
- * authenticated-encryption step. Wrapping it in one would need a product
17
- * decision this hook cannot make alone (how the *importing* device gets the
18
- * key/passphrase back — see importDatabases.ts, which has no decrypt step
19
- * either); that is recorded as a design delta on XR-086, not silently
20
- * skipped. What actually ships here is the part that needs no such decision:
21
- * an explicit warning naming what the file contains and that it is not
22
- * encrypted, with a real chance to back out, shared by both call sites since
23
- * they both go through this one hook.
16
+ * authenticated-encryption step. Encrypting it needs a product decision on how
17
+ * the importing device gets the key back (importDatabases.ts has no decrypt
18
+ * step either). The confirmation alert that used to precede the share sheet
19
+ * was removed by product decision: the tap goes straight to the native save
20
+ * prompt.
24
21
  */
25
22
  import { useCallback, useRef, useState } from 'react'
26
- import { i18n, useWallet } from '@bsv/expo-wallet-toolbox'
23
+ import { useWallet } from '@bsv/expo-wallet-toolbox'
27
24
  import { exportAllWalletDatabases } from '../exportDatabases'
28
- import { showAlert } from '../components/ui/AlertCard'
29
25
 
30
26
  export function useExportWalletData(): { exportData: () => Promise<void>; exporting: boolean } {
31
27
  const { storage } = useWallet()
@@ -37,18 +33,8 @@ export function useExportWalletData(): { exportData: () => Promise<void>; export
37
33
  const exportData = useCallback(async () => {
38
34
  if (inFlightRef.current) return
39
35
  inFlightRef.current = true
36
+ setExporting(true)
40
37
  try {
41
- const choice = await showAlert({
42
- title: i18n.t('export_unencrypted_title'),
43
- message: i18n.t('export_unencrypted_message'),
44
- buttons: [
45
- { text: i18n.t('cancel'), style: 'cancel', key: 'cancel' },
46
- { text: i18n.t('export_wallet_data'), style: 'destructive', key: 'export' }
47
- ]
48
- })
49
- if (choice !== 'export') return
50
- // The spinner means "exporting", not "waiting for you to answer".
51
- setExporting(true)
52
38
  await exportAllWalletDatabases(storage)
53
39
  } catch (e) {
54
40
  console.warn('[exportWalletData] Export failed:', e)
@@ -49,6 +49,8 @@ import {
49
49
  requireAuthenticatedMeta,
50
50
  computeVaultMetaAuthorityTag,
51
51
  recoverVaultFromChain,
52
+ recoverVaultWithKey,
53
+ proveHeldVaultKey,
52
54
  wocChainLookup,
53
55
  resolveHeldVaultDeposit,
54
56
  adoptVaultKey,
@@ -74,6 +76,7 @@ import {
74
76
  getBackupUrl,
75
77
  disableVault,
76
78
  disableVaultWhenSafe,
79
+ forgetUnreachableVaultOutputs,
77
80
  getOnline,
78
81
  generateMnemonicWallet,
79
82
  backupAttestation,
@@ -275,14 +278,17 @@ export function VaultScreen() {
275
278
  wocChainLookup(selectedNetwork),
276
279
  selectedNetwork
277
280
  )
281
+ // An earlier setup's deposits authenticate but no key held now opens
282
+ // them; say so, or they read as "nothing found" and look lost.
283
+ const skipped = result.unreachable > 0 ? ` ${t('vault_restore_unreachable', { count: result.unreachable })}` : ''
278
284
  if (result.found > 0) {
279
285
  haptics.success()
280
- setRestoreNotice(t('vault_restore_found', { count: result.found }))
286
+ setRestoreNotice(t('vault_restore_found', { count: result.found }) + skipped)
281
287
  await reload()
282
288
  } else if (result.pendingConfirmation > 0) {
283
- setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }))
289
+ setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }) + skipped)
284
290
  } else {
285
- setRestoreNotice(t('vault_restore_none_found'))
291
+ setRestoreNotice((skipped ? '' : t('vault_restore_none_found')) + skipped.trim())
286
292
  }
287
293
  } catch (error) {
288
294
  haptics.error()
@@ -292,6 +298,67 @@ export function VaultScreen() {
292
298
  }
293
299
  }, [pm, restoringFromChain, adminOriginator, selectedNetwork, reload])
294
300
 
301
+ // Restore with one tapped YubiKey: its signature picks (and proves) the
302
+ // setup whose deposits it can open, so nothing is guessed from setup dates.
303
+ const [keyRestoreOpen, setKeyRestoreOpen] = useState(false)
304
+ const [keyRestorePin, setKeyRestorePin] = useState('')
305
+ const [keyRestoreBusy, setKeyRestoreBusy] = useState(false)
306
+ const [keyRestorePhase, setKeyRestorePhase] = useState<'scanning' | AdoptPhase | null>(null)
307
+ const [keyRestoreError, setKeyRestoreError] = useState<string | null>(null)
308
+
309
+ const closeKeyRestore = useCallback(() => {
310
+ if (keyRestoreBusy) return
311
+ setKeyRestoreOpen(false)
312
+ setKeyRestorePin('')
313
+ setKeyRestorePhase(null)
314
+ setKeyRestoreError(null)
315
+ }, [keyRestoreBusy])
316
+
317
+ const runKeyRestore = useCallback(async () => {
318
+ if (!pm || keyRestoreBusy || !/^[0-9]{6,8}$/.test(keyRestorePin)) return
319
+ setKeyRestoreBusy(true)
320
+ setKeyRestoreError(null)
321
+ setKeyRestorePhase('scanning')
322
+ setRestoreNotice(null)
323
+ try {
324
+ const result = await recoverVaultWithKey(
325
+ pm as unknown as VaultWallet,
326
+ adminOriginator,
327
+ wocChainLookup(selectedNetwork),
328
+ selectedNetwork,
329
+ records =>
330
+ proveHeldVaultKey({
331
+ records,
332
+ getPin: async () => keyRestorePin,
333
+ onPhase: setKeyRestorePhase,
334
+ nfcMessage: t('vault_nfc_adopt_message')
335
+ })
336
+ )
337
+ if (result.found === 0 && result.pendingConfirmation === 0) {
338
+ haptics.error()
339
+ setKeyRestoreError(t('vault_restore_none_found'))
340
+ return
341
+ }
342
+ setKeyRestoreOpen(false)
343
+ setKeyRestorePin('')
344
+ if (result.found > 0) {
345
+ haptics.success()
346
+ showToast(t('vault_restore_found', { count: result.found }), { type: 'success' })
347
+ await reload()
348
+ } else {
349
+ setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }))
350
+ }
351
+ } catch (error) {
352
+ haptics.error()
353
+ const vaultError = error instanceof VaultError ? error : undefined
354
+ if (vaultError?.code === 'pin-invalid') setKeyRestorePin('')
355
+ setKeyRestoreError(vaultErrorCopy(vaultError?.code, { count: vaultError?.retriesLeft }))
356
+ } finally {
357
+ setKeyRestoreBusy(false)
358
+ setKeyRestorePhase(null)
359
+ }
360
+ }, [pm, keyRestoreBusy, keyRestorePin, adminOriginator, selectedNetwork, reload])
361
+
295
362
  /** F-04: surface the one recovery action for a signed deposit crash left
296
363
  * behind — every other vault call keeps refusing with 'action-pending'
297
364
  * until this resolves it, and there was previously no in-app way to. */
@@ -773,6 +840,41 @@ export function VaultScreen() {
773
840
  )
774
841
 
775
842
  // ── disable ─────────────────────────────────────────────────────────
843
+ const [forgetting, setForgetting] = useState(false)
844
+ const confirmForgetUnreachable = useCallback(async () => {
845
+ const count = coverage?.unreachableOutputs ?? 0
846
+ if (!pm || forgetting || count === 0) return
847
+ const choice = await showAlert({
848
+ title: t('vault_forget_unreachable_title'),
849
+ message: t('vault_forget_unreachable_message', { count }),
850
+ buttons: [
851
+ { text: t('vault_forget_unreachable_confirm'), key: 'confirm', style: 'destructive' },
852
+ { text: t('vault_cancel'), key: 'cancel', style: 'cancel' }
853
+ ]
854
+ })
855
+ if (choice !== 'confirm') return
856
+ setForgetting(true)
857
+ try {
858
+ const { forgotten } = await forgetUnreachableVaultOutputs(pm as unknown as VaultWallet, adminOriginator)
859
+ haptics.success()
860
+ showToast(t('vault_forget_unreachable_done', { count: forgotten }), { type: 'success' })
861
+ } catch (e) {
862
+ console.error('[vault] could not forget unreachable deposits:', e instanceof Error ? e.message : e)
863
+ haptics.error()
864
+ const code = e instanceof VaultError ? e.code : undefined
865
+ if (code === 'action-pending') setActionPendingNotice(true)
866
+ await showAlert({
867
+ title: t('vault_forget_unreachable_title'),
868
+ message: vaultErrorCopy(code),
869
+ buttons: [{ text: t('vault_ok'), key: 'ok' }]
870
+ })
871
+ } finally {
872
+ setForgetting(false)
873
+ refresh()
874
+ refreshCoverage()
875
+ }
876
+ }, [coverage, pm, forgetting, adminOriginator, refresh, refreshCoverage])
877
+
776
878
  const confirmDisable = useCallback(async () => {
777
879
  // Refuse while funds remain: disabling forgets the key list, and with it
778
880
  // the only in-app way to sign for those outputs.
@@ -1081,6 +1183,18 @@ export function VaultScreen() {
1081
1183
  YubiKey — that is only needed afterward, to spend. */}
1082
1184
  {enabled && !!pm && (
1083
1185
  <View style={styles.heroNotice}>
1186
+ {supported && (
1187
+ <PressableScale
1188
+ haptic="tap"
1189
+ onPress={restoringFromChain ? undefined : () => setKeyRestoreOpen(true)}
1190
+ accessibilityState={{ disabled: restoringFromChain }}
1191
+ style={styles.secondary}
1192
+ >
1193
+ <Text style={[styles.secondaryLabel, { color: colors.accent }]}>
1194
+ {t('vault_restore_with_key')}
1195
+ </Text>
1196
+ </PressableScale>
1197
+ )}
1084
1198
  <PressableScale
1085
1199
  haptic="tap"
1086
1200
  onPress={restoringFromChain ? undefined : () => void onRestoreFromChain()}
@@ -1104,6 +1218,64 @@ export function VaultScreen() {
1104
1218
  <View style={styles.heroSpacerBottom} />
1105
1219
  </ScrollView>
1106
1220
  </View>
1221
+ <Sheet
1222
+ visible={keyRestoreOpen}
1223
+ onClose={keyRestoreBusy ? noop : closeKeyRestore}
1224
+ title={t('vault_restore_with_key')}
1225
+ fitContent
1226
+ >
1227
+ <View style={styles.sheetBody}>
1228
+ <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_restore_with_key_body')}</Text>
1229
+ <Text style={[styles.sheetLabel, { color: colors.textPrimary }]}>{t('vault_enter_pin')}</Text>
1230
+ <TextInput
1231
+ accessibilityLabel={t('vault_enter_pin')}
1232
+ style={[styles.input, { color: colors.textPrimary, backgroundColor: colors.backgroundSecondary }]}
1233
+ value={keyRestorePin}
1234
+ onChangeText={text => {
1235
+ setKeyRestoreError(null)
1236
+ setKeyRestorePin(text)
1237
+ }}
1238
+ placeholder="••••••"
1239
+ placeholderTextColor={colors.textTertiary}
1240
+ keyboardType="number-pad"
1241
+ secureTextEntry={keyRestorePin.length > 0}
1242
+ maxLength={8}
1243
+ editable={!keyRestoreBusy}
1244
+ autoFocus
1245
+ />
1246
+ {keyRestoreBusy && (
1247
+ <View style={styles.adoptionProgress}>
1248
+ <ActivityIndicator color={colors.accent} />
1249
+ <Text style={[styles.p, { color: colors.textSecondary }]}>
1250
+ {keyRestorePhase === 'scanning'
1251
+ ? t('vault_restore_scanning')
1252
+ : keyRestorePhase === 'challenging'
1253
+ ? t('vault_touch_when_blinks')
1254
+ : t('vault_reading_key')}
1255
+ </Text>
1256
+ </View>
1257
+ )}
1258
+ {keyRestoreError && <Text style={[styles.err, { color: colors.error }]}>{keyRestoreError}</Text>}
1259
+ <PressableScale
1260
+ haptic="confirm"
1261
+ onPress={!keyRestoreBusy && /^[0-9]{6,8}$/.test(keyRestorePin) ? () => void runKeyRestore() : undefined}
1262
+ accessibilityState={{ disabled: keyRestoreBusy || !/^[0-9]{6,8}$/.test(keyRestorePin) }}
1263
+ style={[
1264
+ styles.primary,
1265
+ { backgroundColor: colors.accent, opacity: !keyRestoreBusy && /^[0-9]{6,8}$/.test(keyRestorePin) ? 1 : 0.5 }
1266
+ ]}
1267
+ >
1268
+ {keyRestoreBusy ? (
1269
+ <ActivityIndicator color={colors.textOnAccent} />
1270
+ ) : (
1271
+ <Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_continue')}</Text>
1272
+ )}
1273
+ </PressableScale>
1274
+ <PressableScale onPress={keyRestoreBusy ? undefined : closeKeyRestore} style={styles.secondary}>
1275
+ <Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>{t('vault_cancel')}</Text>
1276
+ </PressableScale>
1277
+ </View>
1278
+ </Sheet>
1107
1279
  <BiometricAdvisoryModal
1108
1280
  visible={showBiometricAdvisory}
1109
1281
  loading={creatingWallet}
@@ -1240,18 +1412,31 @@ export function VaultScreen() {
1240
1412
  header={keySectionHeader}
1241
1413
  footer={t('vault_footnote')}
1242
1414
  >
1243
- {coverage && coverage.missingKeys.length > 0 && (
1415
+ {/* Deposits no key on the list can open (an earlier setup's) are
1416
+ counted once, here: a re-lock cannot reach them, so they are kept
1417
+ out of the two re-lock badges below. */}
1418
+ {coverage && coverage.unreachableOutputs > 0 && (
1419
+ <ListRow
1420
+ label={t('vault_badge_unreachable', { count: coverage.unreachableOutputs })}
1421
+ icon="close-circle-outline"
1422
+ iconColor={colors.error}
1423
+ showChevron={false}
1424
+ onPress={forgetting ? undefined : () => void confirmForgetUnreachable()}
1425
+ trailing={forgetting ? <ActivityIndicator size="small" /> : undefined}
1426
+ />
1427
+ )}
1428
+ {coverage && coverage.missingKeys.length > 0 && coverage.stale > coverage.unreachableOutputs && (
1244
1429
  <ListRow
1245
- label={t('vault_badge_missing', { count: coverage.stale, nickname: missingNames })}
1430
+ label={t('vault_badge_missing', { count: coverage.stale - coverage.unreachableOutputs, nickname: missingNames })}
1246
1431
  icon="alert-circle-outline"
1247
1432
  iconColor={colors.warning}
1248
1433
  showChevron={false}
1249
1434
  onPress={openGenericRelock}
1250
1435
  />
1251
1436
  )}
1252
- {coverage && coverage.removedKeyOutputs > 0 && (
1437
+ {coverage && coverage.removedKeyOutputs > coverage.unreachableOutputs && (
1253
1438
  <ListRow
1254
- label={t('vault_badge_removed', { count: coverage.removedKeyOutputs })}
1439
+ label={t('vault_badge_removed', { count: coverage.removedKeyOutputs - coverage.unreachableOutputs })}
1255
1440
  icon="alert-circle-outline"
1256
1441
  iconColor={colors.warning}
1257
1442
  showChevron={false}