@bsv/expo-wallet-toolbox 0.5.0 → 0.9.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.
Files changed (200) hide show
  1. package/CHANGELOG.md +2000 -0
  2. package/README.md +66 -1
  3. package/core/amountFormatHelpers.ts +258 -36
  4. package/core/backup/RemoteSyncReader.ts +133 -24
  5. package/core/backup/appData.ts +157 -0
  6. package/core/backup/client.ts +15 -1
  7. package/core/backup/codec.ts +149 -11
  8. package/core/backup/constants.ts +30 -1
  9. package/core/backup/cursor.ts +31 -2
  10. package/core/backup/push.ts +71 -5
  11. package/core/backup/restore.ts +104 -16
  12. package/core/backup/restoreOnImport.ts +94 -30
  13. package/core/backup/status.ts +13 -8
  14. package/core/config.tsx +12 -5
  15. package/core/constants.ts +14 -1
  16. package/core/contacts/contactActivity.ts +153 -0
  17. package/core/contacts/contactCache.ts +41 -0
  18. package/core/contacts/contactsStore.ts +183 -0
  19. package/core/context/ExchangeRateContext.tsx +34 -27
  20. package/core/context/LocalStorageProvider.tsx +43 -40
  21. package/core/context/UserContext.tsx +18 -7
  22. package/core/context/VaultContext.tsx +49 -2
  23. package/core/context/WalletConnectionContext.tsx +203 -11
  24. package/core/context/WalletContext.tsx +685 -171
  25. package/core/demo/demoAssets.ts +60 -0
  26. package/core/demo/demoLedger.ts +240 -0
  27. package/core/demo/demoMandalaRuntime.ts +96 -0
  28. package/core/demo/demoMode.ts +38 -0
  29. package/core/demo/demoWallet.ts +25 -0
  30. package/core/demo/index.ts +26 -0
  31. package/core/demo/useDemo.ts +59 -0
  32. package/core/headers/OfflineFirstChaintracks.ts +99 -17
  33. package/core/headers/headerStore.ts +33 -14
  34. package/core/headers/syncHeaders.ts +12 -1
  35. package/core/i18n/translations.tsx +2186 -98
  36. package/core/identity/contactLink.ts +36 -0
  37. package/core/identity/handleRegistry/client.ts +314 -0
  38. package/core/identity/handleRegistry/keyPinStore.ts +70 -0
  39. package/core/identity/handleRegistry/profileCert.ts +254 -0
  40. package/core/identity/handleRegistry/registration.ts +559 -0
  41. package/core/identity/handleRegistry/resolver.ts +315 -0
  42. package/core/identity/handleRegistry/rules.ts +104 -0
  43. package/core/index.ts +53 -5
  44. package/core/localpay/build.ts +225 -24
  45. package/core/localpay/pending.ts +110 -7
  46. package/core/localpay/pendingAbortAuthority.ts +95 -0
  47. package/core/localpay/pendingAborts.ts +266 -26
  48. package/core/localpay/session.ts +42 -17
  49. package/core/localpay/settlementAck.ts +10 -1
  50. package/core/localpay/transport/socket.ts +52 -3
  51. package/core/localpay/verify.ts +100 -10
  52. package/core/mandala/abortGuard.ts +96 -20
  53. package/core/mandala/createRuntime.ts +206 -33
  54. package/core/mandala/drain.ts +89 -11
  55. package/core/mandala/inboxPrehold.ts +186 -0
  56. package/core/mandala/permissionModule.ts +202 -20
  57. package/core/mandala/settlementStore.ts +24 -2
  58. package/core/mandala/types.ts +40 -5
  59. package/core/monitor/MonitorSupervisor.ts +121 -0
  60. package/core/monitor/TaskBackupPush.ts +15 -1
  61. package/core/monitor/TaskCreditInbox.ts +1 -1
  62. package/core/monitor/TaskDrainOutbox.ts +15 -1
  63. package/core/monitor/TaskSendOffline.ts +15 -1
  64. package/core/net/online.ts +49 -0
  65. package/core/net/publicDestination.ts +91 -0
  66. package/core/net/validateArcUrl.ts +22 -0
  67. package/core/numberFormat.ts +19 -0
  68. package/core/offline/cancelParked.ts +134 -13
  69. package/core/offline/payerHold.ts +100 -24
  70. package/core/offline/plan.ts +37 -8
  71. package/core/pay/beefRepair.ts +6 -2
  72. package/core/pay/damagedInbox.ts +24 -0
  73. package/core/pay/rails/address.ts +107 -12
  74. package/core/pay/rails/handle.ts +117 -22
  75. package/core/pay/rails/index.ts +45 -7
  76. package/core/pay/rails/nativeIntent.ts +61 -0
  77. package/core/pay/receiveHistory.ts +93 -0
  78. package/core/pay/recordProof.ts +21 -7
  79. package/core/pay/refreshProofGuard.ts +42 -1
  80. package/core/pay/watchlist.ts +5 -2
  81. package/core/peerpay/control.ts +17 -18
  82. package/core/peerpay/handleResendRequests.ts +58 -4
  83. package/core/peerpay/outbox.ts +3 -1
  84. package/core/recovery/backupMaterial.ts +61 -0
  85. package/core/recovery/createWallet.ts +95 -0
  86. package/core/recovery/recoverWallet.ts +120 -0
  87. package/core/recovery/restoreWallet.ts +170 -0
  88. package/core/recovery/secret.ts +92 -0
  89. package/core/recovery/shareCollector.ts +71 -0
  90. package/core/recovery/shareParsing.ts +87 -0
  91. package/core/recovery/shares.ts +116 -0
  92. package/core/recovery/useRecoveryDeps.ts +70 -0
  93. package/core/services/arcTokenStorage.ts +52 -0
  94. package/core/services/arcadeBroadcastProvider.ts +233 -52
  95. package/core/services/autoApprovePolicy.ts +105 -0
  96. package/core/services/callbackToken.ts +19 -0
  97. package/core/services/capWalletArgs.ts +14 -2
  98. package/core/services/connectionAuthority.ts +98 -0
  99. package/core/services/exchangeRate.ts +36 -13
  100. package/core/services/externalOrigin.ts +16 -2
  101. package/core/services/secrets/kek.ts +126 -29
  102. package/core/services/secrets/migration.ts +16 -4
  103. package/core/services/secrets/store.ts +42 -14
  104. package/core/services/vault/VaultKeyService.ts +228 -45
  105. package/core/services/vault/chainRecovery.ts +483 -0
  106. package/core/services/vault/driver.ts +9 -1
  107. package/core/services/vault/enrolledSerialRegistry.ts +150 -0
  108. package/core/services/vault/guard.ts +218 -32
  109. package/core/services/vault/hardwareLease.ts +19 -0
  110. package/core/services/vault/metaAuthority.ts +210 -0
  111. package/core/services/vault/pivReset.ts +64 -23
  112. package/core/services/vault/r1comb.ts +139 -3
  113. package/core/services/vault/session.ts +25 -4
  114. package/core/services/vault/transfers.ts +868 -172
  115. package/core/services/vault/types.ts +19 -4
  116. package/core/services/vault/vaultStore.ts +256 -29
  117. package/core/services/walletArgLimits.ts +45 -2
  118. package/core/services/walletConnectionValidation.ts +76 -6
  119. package/core/services/walletServiceConfig.ts +40 -27
  120. package/core/storage/StorageExpoSQLite.ts +88 -47
  121. package/core/storage/methods/findSql.ts +24 -2
  122. package/core/storage/methods/listActionsSql.ts +8 -5
  123. package/core/storage/methods/listOutputsSql.ts +2 -2
  124. package/core/storage/methods/offlineActions.ts +10 -1
  125. package/core/storage/methods/processOfflineActions.ts +117 -25
  126. package/core/storage/methods/reviewStatusSql.ts +7 -2
  127. package/core/storage/schema/createTables.ts +155 -2
  128. package/core/stores/ConnectionStore.ts +34 -0
  129. package/core/toolboxConfig.ts +104 -0
  130. package/core/toolboxTypes.ts +40 -0
  131. package/core/userAvatar.ts +79 -0
  132. package/core/walletDbRegistry.ts +63 -0
  133. package/core/walletMonitor.ts +25 -4
  134. package/core/walletRepair/releaseStuckReservations.ts +72 -0
  135. package/core/walletRepair/shouldMarkUnspendable.ts +20 -0
  136. package/core/walletRepair/spenderConsumesOutpoint.ts +29 -0
  137. package/package.json +7 -7
  138. package/ui/activityFilter.ts +115 -0
  139. package/ui/backupShares.ts +26 -169
  140. package/ui/components/pay/AddressReceive.tsx +13 -6
  141. package/ui/components/pay/AssetPicker.tsx +30 -9
  142. package/ui/components/pay/MessageBoxConfig.tsx +16 -0
  143. package/ui/components/pay/NearbyFlow.tsx +480 -243
  144. package/ui/components/pay/PaymentSuccessOverlay.tsx +85 -10
  145. package/ui/components/pay/RecipientField.tsx +84 -70
  146. package/ui/components/pay/StepBar.tsx +32 -0
  147. package/ui/components/pay/UniversalSend.tsx +827 -205
  148. package/ui/components/ui/AlertCard.tsx +38 -5
  149. package/ui/components/ui/PencilEditField.tsx +109 -0
  150. package/ui/components/ui/PermissionSheet.tsx +197 -66
  151. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  152. package/ui/components/vault/EnrollWizard.tsx +61 -13
  153. package/ui/components/vault/vaultErrorCopy.ts +3 -1
  154. package/ui/components/wallet/ActivityRow.tsx +227 -123
  155. package/ui/components/wallet/AmountInput.tsx +26 -8
  156. package/ui/components/wallet/AssetSwitcherDropdown.tsx +22 -2
  157. package/ui/components/wallet/Balance.tsx +42 -23
  158. package/ui/components/wallet/BiometricAdvisoryModal.tsx +16 -3
  159. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  160. package/ui/components/wallet/ContactSigil.tsx +49 -0
  161. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  162. package/ui/components/wallet/FitAmount.tsx +148 -0
  163. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  164. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  165. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  166. package/ui/components/wallet/ProfileButton.tsx +62 -0
  167. package/ui/components/wallet/UserAvatar.tsx +85 -0
  168. package/ui/components/wallet/avatarIcons.ts +122 -0
  169. package/ui/exportTransactions.ts +36 -4
  170. package/ui/hooks/useContactsStore.ts +10 -0
  171. package/ui/hooks/useExportWalletData.ts +25 -2
  172. package/ui/hooks/useMandala.ts +18 -1
  173. package/ui/hooks/useOnline.ts +65 -20
  174. package/ui/importDatabases.ts +339 -24
  175. package/ui/index.ts +33 -2
  176. package/ui/isImageUrl.ts +6 -0
  177. package/ui/printRecoveryShares.ts +9 -10
  178. package/ui/recoveryPrompts.ts +91 -0
  179. package/ui/resolveIdentity.ts +31 -9
  180. package/ui/screens/ConnectionsScreen.tsx +86 -19
  181. package/ui/screens/ContactScreen.tsx +289 -0
  182. package/ui/screens/ContactsScreen.tsx +373 -0
  183. package/ui/screens/IdentifierScreen.tsx +256 -0
  184. package/ui/screens/NewContactScreen.tsx +362 -0
  185. package/ui/screens/PairScreen.tsx +74 -2
  186. package/ui/screens/PayScreen.tsx +20 -7
  187. package/ui/screens/ProfileScreen.tsx +783 -0
  188. package/ui/screens/SettingsScreen.tsx +10 -4
  189. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  190. package/ui/screens/TrustScreen.tsx +100 -5
  191. package/ui/screens/VaultScreen.tsx +410 -61
  192. package/ui/screens/VaultTransferScreen.tsx +59 -7
  193. package/ui/screens/WalletCheckScreen.tsx +17 -6
  194. package/ui/screens/WalletConfigScreen.tsx +124 -28
  195. package/ui/screens/WalletHomeScreen.tsx +640 -104
  196. package/ui/screens/detailActionKeys.ts +55 -0
  197. package/ui/tokenFormat.ts +44 -4
  198. package/ui/tokenStatus.ts +21 -0
  199. package/ui/txStatus.ts +48 -5
  200. package/core/storage/LocalStorageAdapter.ts +0 -58
@@ -20,7 +20,7 @@
20
20
  * key can sign.
21
21
  */
22
22
  import React, { useCallback, useEffect, useRef, useState } from 'react'
23
- import { View, Text, StyleSheet, ScrollView, TouchableOpacity, ActivityIndicator, TextInput } from 'react-native'
23
+ import { View, Text, StyleSheet, ScrollView, TouchableOpacity, ActivityIndicator, TextInput, AppState } from 'react-native'
24
24
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
25
25
  import { GroupedSection } from '../components/ui/GroupedList'
26
26
  import { ListRow } from '../components/ui/ListRow'
@@ -46,12 +46,18 @@ import {
46
46
  useLocalStorage,
47
47
  relockVault,
48
48
  recoverVaultMetaFromOutputs,
49
+ requireAuthenticatedMeta,
50
+ computeVaultMetaAuthorityTag,
51
+ recoverVaultFromChain,
52
+ wocChainLookup,
53
+ resolveHeldVaultDeposit,
49
54
  adoptVaultKey,
50
55
  beginVaultKeyRemoval,
51
56
  finalizeVaultKeyRemoval,
52
57
  estimateRelockFee,
53
58
  R1C_LOCK_LEN,
54
59
  type VaultWallet,
60
+ type HmacCapableWallet,
55
61
  type VaultSpendResult,
56
62
  vaultStore,
57
63
  type VaultMeta,
@@ -60,6 +66,7 @@ import {
60
66
  type AdoptPhase,
61
67
  VAULT_MIN_KEYS,
62
68
  VAULT_MAX_KEYS,
69
+ VAULT_MAX_ACTIVE_KEYS,
63
70
  getVaultDriver,
64
71
  isVaultEnabled,
65
72
  isVaultAvailable,
@@ -70,13 +77,18 @@ import {
70
77
  getOnline,
71
78
  generateMnemonicWallet,
72
79
  backupAttestation,
80
+ readBackupAttestation,
73
81
  VaultError,
74
82
  haptics,
75
- i18n
83
+ i18n,
84
+ resolveProvisioningPolicy
76
85
  } from '@bsv/expo-wallet-toolbox'
77
86
 
78
87
  const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
79
88
 
89
+ /** How often a removal whose re-lock is not yet accepted is re-checked. */
90
+ const REMOVAL_RECHECK_MS = 30_000
91
+
80
92
  /**
81
93
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
82
94
  * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
@@ -152,12 +164,27 @@ export function VaultScreen() {
152
164
  const [showBiometricAdvisory, setShowBiometricAdvisory] = useState(false)
153
165
  const [creatingWallet, setCreatingWallet] = useState(false)
154
166
  const [walletCreationIntent, setWalletCreationIntent] = useState<'deposit' | 'enroll'>('deposit')
167
+ // XR-114: whether provisioning would actually land on a disclosed
168
+ // (non-biometric) policy for this device/build, so the advisory below
169
+ // never promises Face ID/fingerprint protection it will not deliver.
170
+ const [advisoryDegraded, setAdvisoryDegraded] = useState(false)
155
171
  const [recoveryError, setRecoveryError] = useState<string | null>(null)
156
172
  const [adopting, setAdopting] = useState<{ record: VaultKeyRecord; scopeToken: VaultScopeToken } | null>(null)
157
173
  const [adoptionPin, setAdoptionPin] = useState('')
158
174
  const [adoptionPhase, setAdoptionPhase] = useState<AdoptPhase | null>(null)
159
175
  const [adoptionBusy, setAdoptionBusy] = useState(false)
160
176
  const [adoptionError, setAdoptionError] = useState<string | null>(null)
177
+ // F-04: a signed but unbroadcast deposit left by a crash refuses every
178
+ // vault-mutating call with 'action-pending' forever until it is
179
+ // reconciled. Once any of that surfaces here, offer the one safe manual
180
+ // resolution (resolveHeldVaultDeposit) instead of leaving the vault stuck.
181
+ const [actionPendingNotice, setActionPendingNotice] = useState(false)
182
+ const [resolvingDeposit, setResolvingDeposit] = useState(false)
183
+ // Chain recovery (v7 marker/descriptor, spec v7 §1.2 item 3): offered only
184
+ // while this wallet has no local vault meta at all. Never needs a YubiKey —
185
+ // only the wallet identity — so it is not gated on `supported`.
186
+ const [restoringFromChain, setRestoringFromChain] = useState(false)
187
+ const [restoreNotice, setRestoreNotice] = useState<string | null>(null)
161
188
 
162
189
  // Release flag AND mainnet (task 11). Read from the reactive `selectedNetwork`
163
190
  // so everything this gates collapses on a network switch without a remount —
@@ -174,20 +201,46 @@ export function VaultScreen() {
174
201
  const pm = managers?.permissionsManager
175
202
 
176
203
  const reload = useCallback(async (): Promise<VaultMeta | null> => {
204
+ if (!pm) {
205
+ metaRef.current = null
206
+ setMeta(null)
207
+ setRecoveryError(null)
208
+ return null
209
+ }
210
+ // INT-07 / XR-007: recoverVaultMetaFromOutputs used to run only when the
211
+ // local cache was EMPTY. A stale-but-PRESENT local record (an iOS
212
+ // reinstall Keychain survives, or a revision bump made elsewhere for the
213
+ // same enrollment) then skipped this reconciliation forever — every
214
+ // subsequent spend against the newer on-chain revision failed closed
215
+ // with 'template-invalid', with no in-app way to force it (disableVault
216
+ // refuses on any funded vault). recoverVaultMetaFromOutputs already keeps
217
+ // the cached record whenever the authenticated scan does not supersede it
218
+ // (recoveredSupersedesExisting), so calling it unconditionally only
219
+ // widens WHEN that existing ratchet runs, never what it decides.
220
+ let cached: VaultMeta | null = null
177
221
  try {
178
- if (!pm) {
179
- metaRef.current = null
180
- setMeta(null)
181
- setRecoveryError(null)
182
- return null
183
- }
184
- let m = await vaultStore.getMeta()
185
- if (!m) m = await recoverVaultMetaFromOutputs(pm as unknown as VaultWallet, adminOriginator)
222
+ cached = await vaultStore.getMeta()
223
+ } catch {
224
+ // Nothing to fall back to either; the scan below still gets a chance.
225
+ }
226
+ try {
227
+ const m = await recoverVaultMetaFromOutputs(pm as unknown as VaultWallet, adminOriginator)
186
228
  metaRef.current = m
187
229
  setMeta(m)
188
230
  setRecoveryError(null)
189
231
  return m
190
232
  } catch (error) {
233
+ // A scan that cannot complete (offline, a pending action another call
234
+ // site already surfaces its own notice for, etc.) must not regress an
235
+ // already-correct cached record's instant, offline-safe display into a
236
+ // hard recoveryError screen — only a device with NOTHING cached has
237
+ // nothing safe to fall back to.
238
+ if (cached) {
239
+ metaRef.current = cached
240
+ setMeta(cached)
241
+ setRecoveryError(null)
242
+ return cached
243
+ }
191
244
  metaRef.current = null
192
245
  setRecoveryError(vaultErrorCopy(error instanceof VaultError ? error.code : undefined))
193
246
  throw error
@@ -204,16 +257,127 @@ export function VaultScreen() {
204
257
  void reload().catch(error => console.error('[vault] recovery scan failed:', error))
205
258
  }, [reload])
206
259
 
260
+ /**
261
+ * Restore vault from the blockchain (spec v7 §1.2 item 3 / item 7):
262
+ * scans for chain-published v7 markers and internalizes every confirmed,
263
+ * unspent, authenticated one — no local DB, SecureStore, or backup needed,
264
+ * and no YubiKey either (that is only needed afterward, to spend). Shown
265
+ * only while this wallet has no local vault meta at all.
266
+ */
267
+ const onRestoreFromChain = useCallback(async () => {
268
+ if (!pm || restoringFromChain) return
269
+ setRestoringFromChain(true)
270
+ setRestoreNotice(null)
271
+ try {
272
+ const result = await recoverVaultFromChain(
273
+ pm as unknown as VaultWallet,
274
+ adminOriginator,
275
+ wocChainLookup(selectedNetwork),
276
+ selectedNetwork
277
+ )
278
+ if (result.found > 0) {
279
+ haptics.success()
280
+ setRestoreNotice(t('vault_restore_found', { count: result.found }))
281
+ await reload()
282
+ } else if (result.pendingConfirmation > 0) {
283
+ setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }))
284
+ } else {
285
+ setRestoreNotice(t('vault_restore_none_found'))
286
+ }
287
+ } catch (error) {
288
+ haptics.error()
289
+ setRestoreNotice(vaultErrorCopy(error instanceof VaultError ? error.code : undefined))
290
+ } finally {
291
+ setRestoringFromChain(false)
292
+ }
293
+ }, [pm, restoringFromChain, adminOriginator, selectedNetwork, reload])
294
+
295
+ /** F-04: surface the one recovery action for a signed deposit crash left
296
+ * behind — every other vault call keeps refusing with 'action-pending'
297
+ * until this resolves it, and there was previously no in-app way to. */
298
+ const onResolveHeldDeposit = useCallback(async () => {
299
+ if (!pm || !metaRef.current || resolvingDeposit) return
300
+ setResolvingDeposit(true)
301
+ try {
302
+ const result = await resolveHeldVaultDeposit(pm as unknown as VaultWallet, adminOriginator, metaRef.current)
303
+ if (result.kind === 'failed') {
304
+ console.error('[vault] could not resolve the held deposit:', result.error)
305
+ showToast(vaultErrorCopy('action-pending'), { type: 'error' })
306
+ return
307
+ }
308
+ if (result.kind === 'nothing-held') {
309
+ // XR-006 / INT-03: 'nothing-held' means no held deposit OR
310
+ // withdraw/relock this function knows how to authenticate was
311
+ // found — it does NOT mean the underlying action-pending block is
312
+ // gone. Reporting success here previously cleared the notice while
313
+ // the freeze remained, silently reappearing on the very next vault
314
+ // operation.
315
+ showToast(t('vault_resolve_held_deposit_none'), { type: 'error' })
316
+ return
317
+ }
318
+ setActionPendingNotice(false)
319
+ haptics.success()
320
+ showToast(t('vault_resolve_held_deposit_done'), { type: 'success' })
321
+ await reload()
322
+ } catch (e) {
323
+ console.error('[vault] could not resolve the held deposit:', e)
324
+ showToast(t('vault_resolve_held_deposit_failed'), { type: 'error' })
325
+ } finally {
326
+ setResolvingDeposit(false)
327
+ }
328
+ }, [pm, adminOriginator, resolvingDeposit, reload, t])
329
+
330
+ // A removal whose re-lock is broadcast finishes once the network accepts
331
+ // that re-lock ('unproven'). Usually that is already true when the re-lock
332
+ // returns; when the toolbox is still retrying ('sending'), nothing else
333
+ // reloads this screen when it lands. Re-check while it waits (and on return
334
+ // to the foreground) so the user is not told to leave and come back. A
335
+ // 'prepared' removal is not polled: it needs a re-lock, which reconciles on
336
+ // its own.
337
+ const removalState = meta?.pendingRemoval?.state
207
338
  useEffect(() => {
208
339
  if (!pm || !meta?.pendingRemoval) return
209
340
  let stale = false
210
- void finalizeVaultKeyRemoval(pm as unknown as VaultWallet, adminOriginator)
211
- .then(async complete => {
212
- if (!stale && complete) await reload()
213
- })
214
- .catch(error => console.error('[vault] pending key-removal reconciliation failed:', error))
215
- return () => { stale = true }
216
- }, [pm, meta?.pendingRemoval, adminOriginator, reload])
341
+ let running = false
342
+ const reconcile = () => {
343
+ if (running) return
344
+ running = true
345
+ void finalizeVaultKeyRemoval(pm as unknown as VaultWallet, adminOriginator)
346
+ .then(async complete => {
347
+ if (stale) return
348
+ if (complete) {
349
+ await reload()
350
+ return
351
+ }
352
+ // Reconciliation can itself infer 'broadcast' for a crash-interrupted
353
+ // re-lock; show that without a full rescan.
354
+ const current = await vaultStore.getMeta()
355
+ if (!stale && current?.pendingRemoval?.state !== metaRef.current?.pendingRemoval?.state) {
356
+ metaRef.current = current
357
+ setMeta(current)
358
+ }
359
+ })
360
+ .catch(error => console.error('[vault] pending key-removal reconciliation failed:', error))
361
+ .finally(() => {
362
+ running = false
363
+ })
364
+ }
365
+ reconcile()
366
+ if (removalState !== 'broadcast') {
367
+ return () => {
368
+ stale = true
369
+ }
370
+ }
371
+ const timer = setInterval(reconcile, REMOVAL_RECHECK_MS)
372
+ const foreground = AppState.addEventListener('change', next => {
373
+ if (next === 'active') reconcile()
374
+ })
375
+ return () => {
376
+ stale = true
377
+ clearInterval(timer)
378
+ foreground.remove()
379
+ }
380
+ }, [pm, meta?.pendingRemoval, removalState, adminOriginator, reload])
217
381
 
218
382
  // ── helpers ─────────────────────────────────────────────────────────
219
383
  /** `nickname · …tail4` for each referenced key; a key no longer in meta shows its pubkey tail. */
@@ -222,8 +386,9 @@ export function VaultScreen() {
222
386
  refs
223
387
  .map(r => {
224
388
  const current = metaRef.current
225
- const rec = [...(current?.keys ?? []), ...(current?.pendingRemoval ? [current.pendingRemoval.key] : [])]
226
- .find(k => (r.serial !== undefined && k.serial === r.serial) || k.pubkey === r.pubkey)
389
+ const rec = [...(current?.keys ?? []), ...(current?.pendingRemoval ? [current.pendingRemoval.key] : [])].find(
390
+ k => (r.serial !== undefined && k.serial === r.serial) || k.pubkey === r.pubkey
391
+ )
227
392
  return rec ? vaultKeyLabel(rec) : `…${r.pubkey.slice(-4)}`
228
393
  })
229
394
  .join(', '),
@@ -302,10 +467,12 @@ export function VaultScreen() {
302
467
  return
303
468
  }
304
469
  if (vaultError?.code === 'pin-invalid') setAdoptionPin('')
305
- setAdoptionError(vaultErrorCopy(vaultError?.code, {
306
- count: vaultError?.retriesLeft,
307
- names: metaRef.current?.keys.map(vaultKeyLabel).join(', ') || undefined
308
- }))
470
+ setAdoptionError(
471
+ vaultErrorCopy(vaultError?.code, {
472
+ count: vaultError?.retriesLeft,
473
+ names: metaRef.current?.keys.map(vaultKeyLabel).join(', ') || undefined
474
+ })
475
+ )
309
476
  } finally {
310
477
  setAdoptionBusy(false)
311
478
  }
@@ -365,7 +532,8 @@ export function VaultScreen() {
365
532
  throw new VaultError('template-invalid', 'Vault re-lock made no progress')
366
533
  }
367
534
  previousCapped = result.cappedInputs
368
- if (result.cappedInputs > 0) showToast(t('vault_relock_capped', { count: result.cappedInputs }), { type: 'info' })
535
+ if (result.cappedInputs > 0)
536
+ showToast(t('vault_relock_capped', { count: result.cappedInputs }), { type: 'info' })
369
537
  } while (result.cappedInputs > 0)
370
538
  refresh()
371
539
  refreshCoverage()
@@ -408,6 +576,7 @@ export function VaultScreen() {
408
576
  } catch (e) {
409
577
  console.error('[vault] re-lock failed:', e instanceof Error ? e.message : e, e)
410
578
  const code = e instanceof VaultError ? e.code : undefined
579
+ if (code === 'action-pending') setActionPendingNotice(true)
411
580
  if (code === 'backup-off') {
412
581
  await backupOffAlert()
413
582
  return
@@ -421,7 +590,20 @@ export function VaultScreen() {
421
590
  } finally {
422
591
  setRelocking(false)
423
592
  }
424
- }, [pm, relock, relockSerial, relocking, adminOriginator, transferOpts, closeRelock, refresh, refreshCoverage, namesFor, reload, backupOffAlert])
593
+ }, [
594
+ pm,
595
+ relock,
596
+ relockSerial,
597
+ relocking,
598
+ adminOriginator,
599
+ transferOpts,
600
+ closeRelock,
601
+ refresh,
602
+ refreshCoverage,
603
+ namesFor,
604
+ reload,
605
+ backupOffAlert
606
+ ])
425
607
 
426
608
  // ── wizard hand-offs ────────────────────────────────────────────────
427
609
  /**
@@ -457,7 +639,9 @@ export function VaultScreen() {
457
639
  // The new key can open deposits made from now on; a re-lock makes it open
458
640
  // everything. Pointless on an empty vault, so only offered when it holds
459
641
  // something — the wizard's done step already said so either way.
460
- if (added.length > 0 && (balance ?? 0) > 0) {
642
+ // Not at six keys either: a lock holds five, so the key being replaced has
643
+ // to be removed first, and that removal's re-lock covers both changes.
644
+ if (added.length > 0 && (balance ?? 0) > 0 && m.keys.length <= VAULT_MAX_KEYS) {
461
645
  openRelock({
462
646
  reason: t('vault_relock_reason', { names: others.map(vaultKeyLabel).join(', ') }),
463
647
  exclude: added[0].serial
@@ -471,7 +655,20 @@ export function VaultScreen() {
471
655
  const next = renameText.trim()
472
656
  if (next && next !== renaming.nickname) {
473
657
  try {
474
- await vaultStore.renameKey(renaming.serial, next)
658
+ // XR-002: renameKey only changes a nickname, but its `next` meta
659
+ // still bumps revision — never trust the CURRENT record as the basis
660
+ // for a freshly tagged one without re-verifying it first (the same
661
+ // laundering caveat as vaultStore.addKey).
662
+ if (!pm) throw new VaultError('driver-unavailable', 'Wallet is not ready for a vault operation')
663
+ const currentMeta = metaRef.current
664
+ if (!currentMeta) throw new VaultError('not-enrolled', 'Vault is not set up')
665
+ const scopeToken = vaultStore.captureScopeToken()
666
+ await requireAuthenticatedMeta(pm as unknown as VaultWallet, adminOriginator, scopeToken, currentMeta)
667
+ const scope = vaultStore.getScope()
668
+ if (!scope) throw new VaultError('not-enrolled', 'Wallet vault scope is not configured')
669
+ await vaultStore.renameKey(renaming.serial, next, scopeToken, nextMeta =>
670
+ computeVaultMetaAuthorityTag(pm as unknown as HmacCapableWallet, adminOriginator, nextMeta, scope)
671
+ )
475
672
  await reload()
476
673
  } catch (e) {
477
674
  haptics.error()
@@ -479,7 +676,7 @@ export function VaultScreen() {
479
676
  }
480
677
  }
481
678
  setRenaming(null)
482
- }, [renaming, renameText, reload])
679
+ }, [renaming, renameText, reload, pm, adminOriginator])
483
680
 
484
681
  const removeKey = useCallback(
485
682
  async (rec: VaultKeyRecord) => {
@@ -533,15 +730,20 @@ export function VaultScreen() {
533
730
  // for the re-lock that makes the keys still on it open every deposit.
534
731
  openRelock({
535
732
  reason: t('vault_relock_reason_remaining', {
536
- names: m.keys.filter(k => k.serial !== rec.serial).map(vaultKeyLabel).join(', ')
733
+ names: m.keys
734
+ .filter(k => k.serial !== rec.serial)
735
+ .map(vaultKeyLabel)
736
+ .join(', ')
537
737
  }),
538
738
  revoke: rec
539
739
  })
540
740
  } catch (e) {
541
741
  haptics.error()
742
+ const code = e instanceof VaultError ? e.code : undefined
743
+ if (code === 'action-pending') setActionPendingNotice(true)
542
744
  await showAlert({
543
745
  title,
544
- message: vaultErrorCopy(e instanceof VaultError ? e.code : undefined),
746
+ message: vaultErrorCopy(code),
545
747
  buttons: [{ text: t('vault_ok'), key: 'ok' }]
546
748
  })
547
749
  return
@@ -552,14 +754,14 @@ export function VaultScreen() {
552
754
 
553
755
  const keyActions = useCallback(
554
756
  async (rec: VaultKeyRecord) => {
555
- const choice = await showAlert({
556
- title: vaultKeyLabel(rec),
557
- buttons: [
558
- { text: t('vault_key_action_rename'), key: 'rename' },
559
- { text: t('vault_key_action_remove'), key: 'remove', style: 'destructive' },
560
- { text: t('vault_cancel'), key: 'cancel', style: 'cancel' }
561
- ]
562
- })
757
+ // Remove only when it leaves at least VAULT_MIN_KEYS, and one removal at
758
+ // a time. To replace a key in a two-key vault, add the new one first.
759
+ const current = metaRef.current
760
+ const canRemove = !!current && !current.pendingRemoval && current.keys.length > VAULT_MIN_KEYS
761
+ const buttons: AlertButton[] = [{ text: t('vault_key_action_rename'), key: 'rename' }]
762
+ if (canRemove) buttons.push({ text: t('vault_key_action_remove'), key: 'remove', style: 'destructive' })
763
+ buttons.push({ text: t('vault_cancel'), key: 'cancel', style: 'cancel' })
764
+ const choice = await showAlert({ title: vaultKeyLabel(rec), buttons })
563
765
  if (choice === 'rename') {
564
766
  setRenameText(rec.nickname)
565
767
  setRenaming(rec)
@@ -629,6 +831,13 @@ export function VaultScreen() {
629
831
  * destinationPress → BiometricAdvisoryModal → ensureWalletExists.
630
832
  */
631
833
  const creatingWalletRef = useRef(false)
834
+ // XR-003: set only on the branch below that generates a BRAND NEW mnemonic.
835
+ // A freshly generated wallet is certainly unattested (markPending was just
836
+ // written for it); onAdvisoryContinue reads this to skip a redundant
837
+ // attestation lookup and go straight to the mandatory seed-preservation
838
+ // screen, rather than risk a stale `managers.permissionsManager` closure
839
+ // read immediately after this same call just built it.
840
+ const justCreatedIdentityRef = useRef<string | null>(null)
632
841
  const ensureWalletExists = useCallback(async (): Promise<boolean> => {
633
842
  if (managers.permissionsManager) return true
634
843
  if (!secretsReady || walletBuilding || creatingWalletRef.current) return false
@@ -646,6 +855,7 @@ export function VaultScreen() {
646
855
  if (!(await hasStoredIdentity())) router.replace('/auth/mnemonic')
647
856
  return false
648
857
  }
858
+ justCreatedIdentityRef.current = wallet.identityKey
649
859
  try {
650
860
  await backupAttestation.markPending(wallet.identityKey)
651
861
  } catch (error) {
@@ -659,10 +869,42 @@ export function VaultScreen() {
659
869
  } finally {
660
870
  creatingWalletRef.current = false
661
871
  }
662
- }, [managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, createMnemonic, buildWalletFromMnemonic, router])
872
+ }, [
873
+ managers.permissionsManager,
874
+ secretsReady,
875
+ walletBuilding,
876
+ hasStoredIdentity,
877
+ createMnemonic,
878
+ buildWalletFromMnemonic,
879
+ router
880
+ ])
881
+
882
+ /**
883
+ * XR-003: neither the enroll wizard nor a deposit may be reached before the
884
+ * mnemonic that alone can recover this vault (I1/I2 — YubiKeys carry no
885
+ * seed) has been durably preserved off-device at least once. Distinct from
886
+ * the ordinary wallet's dismissible backupAttestation reminder (which stays
887
+ * non-blocking): here the same record BLOCKS instead of reminding, because
888
+ * real money is about to depend on it. `knownUnattested` skips the lookup
889
+ * for the one caller (onAdvisoryContinue, immediately after generating a
890
+ * brand new mnemonic) where `managers.permissionsManager` may still be a
891
+ * stale pre-build closure read.
892
+ */
893
+ const requireBackupAttested = useCallback(
894
+ async (knownUnattested = false): Promise<boolean> => {
895
+ const attested = knownUnattested
896
+ ? null
897
+ : await readBackupAttestation(managers.permissionsManager, adminOriginator)
898
+ if (attested) return true
899
+ router.push('/auth/mnemonic?flow=backup')
900
+ return false
901
+ },
902
+ [managers.permissionsManager, adminOriginator, router]
903
+ )
663
904
 
664
905
  const onDeposit = useCallback(async () => {
665
906
  if (managers.permissionsManager) {
907
+ if (!(await requireBackupAttested())) return
666
908
  router.push('/vault-transfer?direction=deposit')
667
909
  return
668
910
  }
@@ -672,12 +914,14 @@ export function VaultScreen() {
672
914
  } catch {
673
915
  return
674
916
  }
917
+ setAdvisoryDegraded((await resolveProvisioningPolicy()).disclose)
675
918
  setWalletCreationIntent('deposit')
676
919
  setShowBiometricAdvisory(true)
677
- }, [managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, router])
920
+ }, [managers.permissionsManager, requireBackupAttested, secretsReady, walletBuilding, hasStoredIdentity, router])
678
921
 
679
922
  const onBeginEnrollment = useCallback(async () => {
680
923
  if (managers.permissionsManager) {
924
+ if (!(await requireBackupAttested())) return
681
925
  setWizard('enroll')
682
926
  return
683
927
  }
@@ -687,9 +931,10 @@ export function VaultScreen() {
687
931
  } catch {
688
932
  return
689
933
  }
934
+ setAdvisoryDegraded((await resolveProvisioningPolicy()).disclose)
690
935
  setWalletCreationIntent('enroll')
691
936
  setShowBiometricAdvisory(true)
692
- }, [managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity])
937
+ }, [managers.permissionsManager, requireBackupAttested, secretsReady, walletBuilding, hasStoredIdentity])
693
938
 
694
939
  const onAdvisoryContinue = useCallback(() => {
695
940
  // Kept up (with a spinner in place of the label) until wallet creation
@@ -702,6 +947,9 @@ export function VaultScreen() {
702
947
  const created = await ensureWalletExists()
703
948
  setShowBiometricAdvisory(false)
704
949
  if (created) {
950
+ const justCreated = justCreatedIdentityRef.current !== null
951
+ justCreatedIdentityRef.current = null
952
+ if (!(await requireBackupAttested(justCreated))) return
705
953
  if (walletCreationIntent === 'enroll') setWizard('enroll')
706
954
  else router.push('/vault-transfer?direction=deposit')
707
955
  }
@@ -709,7 +957,7 @@ export function VaultScreen() {
709
957
  setCreatingWallet(false)
710
958
  }
711
959
  })()
712
- }, [ensureWalletExists, router, walletCreationIntent])
960
+ }, [ensureWalletExists, requireBackupAttested, router, walletCreationIntent])
713
961
 
714
962
  // ── header ──────────────────────────────────────────────────────────
715
963
  // While the wizard is up, back means "leave set-up" and goes through the
@@ -736,7 +984,11 @@ export function VaultScreen() {
736
984
  <View style={styles.centered}>
737
985
  <Ionicons name="alert-circle-outline" size={44} color={colors.error} />
738
986
  <Text style={[styles.p, { color: colors.textPrimary }]}>{recoveryError}</Text>
739
- <PressableScale haptic="tap" onPress={retryRecovery} style={[styles.primary, { backgroundColor: colors.accent }]}>
987
+ <PressableScale
988
+ haptic="tap"
989
+ onPress={retryRecovery}
990
+ style={[styles.primary, { backgroundColor: colors.accent }]}
991
+ >
740
992
  <Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_retry')}</Text>
741
993
  </PressableScale>
742
994
  </View>
@@ -760,7 +1012,11 @@ export function VaultScreen() {
760
1012
  return (
761
1013
  <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
762
1014
  {Header}
763
- <EnrollWizard mode={wizard} onDone={wizard === 'enroll' ? onEnrolled : onKeyAdded} onCancel={() => void closeWizard()} />
1015
+ <EnrollWizard
1016
+ mode={wizard}
1017
+ onDone={wizard === 'enroll' ? onEnrolled : onKeyAdded}
1018
+ onCancel={() => void closeWizard()}
1019
+ />
764
1020
  </View>
765
1021
  )
766
1022
  }
@@ -792,7 +1048,11 @@ export function VaultScreen() {
792
1048
  styles.primary,
793
1049
  canEnroll
794
1050
  ? { backgroundColor: colors.accent }
795
- : { backgroundColor: 'transparent', borderWidth: StyleSheet.hairlineWidth, borderColor: colors.separator }
1051
+ : {
1052
+ backgroundColor: 'transparent',
1053
+ borderWidth: StyleSheet.hairlineWidth,
1054
+ borderColor: colors.separator
1055
+ }
796
1056
  ]}
797
1057
  >
798
1058
  <Text style={[styles.primaryLabel, { color: canEnroll ? colors.textOnAccent : colors.textTertiary }]}>
@@ -810,7 +1070,34 @@ export function VaultScreen() {
810
1070
  {enabled && !supported && (
811
1071
  <View style={styles.heroNotice}>
812
1072
  <Text style={[styles.heroNoticeTitle, { color: colors.error }]}>{t('vault_unsupported_title')}</Text>
813
- <Text style={[styles.heroNoticeBody, { color: colors.textSecondary }]}>{t('vault_unsupported_body')}</Text>
1073
+ <Text style={[styles.heroNoticeBody, { color: colors.textSecondary }]}>
1074
+ {t('vault_unsupported_body')}
1075
+ </Text>
1076
+ </View>
1077
+ )}
1078
+ {/* No local vault meta at all: a wiped device / reinstall with
1079
+ the same wallet identity may still have vault deposits
1080
+ on-chain. Needs the wallet identity (pm) but never a
1081
+ YubiKey — that is only needed afterward, to spend. */}
1082
+ {enabled && !!pm && (
1083
+ <View style={styles.heroNotice}>
1084
+ <PressableScale
1085
+ haptic="tap"
1086
+ onPress={restoringFromChain ? undefined : () => void onRestoreFromChain()}
1087
+ accessibilityState={{ disabled: restoringFromChain }}
1088
+ style={styles.secondary}
1089
+ >
1090
+ {restoringFromChain ? (
1091
+ <ActivityIndicator color={colors.accent} />
1092
+ ) : (
1093
+ <Text style={[styles.secondaryLabel, { color: colors.accent }]}>
1094
+ {t('vault_restore_from_chain')}
1095
+ </Text>
1096
+ )}
1097
+ </PressableScale>
1098
+ {restoreNotice && (
1099
+ <Text style={[styles.heroNoticeBody, { color: colors.textSecondary }]}>{restoreNotice}</Text>
1100
+ )}
814
1101
  </View>
815
1102
  )}
816
1103
  </View>
@@ -820,6 +1107,7 @@ export function VaultScreen() {
820
1107
  <BiometricAdvisoryModal
821
1108
  visible={showBiometricAdvisory}
822
1109
  loading={creatingWallet}
1110
+ degraded={advisoryDegraded}
823
1111
  onCancel={() => setShowBiometricAdvisory(false)}
824
1112
  onContinue={onAdvisoryContinue}
825
1113
  />
@@ -828,14 +1116,20 @@ export function VaultScreen() {
828
1116
  }
829
1117
 
830
1118
  // ── enrolled ─────────────────────────────────────────────────────────
831
- const canAdd = enabled && !meta.pendingRemoval && meta.keys.length < VAULT_MAX_KEYS
1119
+ const canAdd = enabled && !meta.pendingRemoval && meta.keys.length < VAULT_MAX_ACTIVE_KEYS
1120
+ // Six keys: one more than a lock holds, so nothing that creates a Vault
1121
+ // output runs until one is removed. A full withdrawal creates none.
1122
+ const overLockLimit = meta.keys.length > VAULT_MAX_KEYS
832
1123
  const adoptedSerials = new Set(meta.recovery?.adoptedSerials ?? [])
833
1124
  const recoveryRequired = meta.recovery?.required === true
834
1125
  const adoptedKeyCount = meta.keys.filter(key => adoptedSerials.has(key.serial)).length
835
1126
  const hasAdoptedKey = !recoveryRequired || adoptedKeyCount > 0
836
1127
  const hasRecoveryRedundancy = !recoveryRequired || adoptedKeyCount >= VAULT_MIN_KEYS
837
1128
  const transfersBlocked = !!meta.pendingRemoval
838
- const canDeposit = enabled && !transfersBlocked && hasRecoveryRedundancy
1129
+ // Re-lock signed and broadcast: nothing is left to re-lock, only the
1130
+ // network's acceptance to wait for (the effect above re-checks).
1131
+ const removalAwaitingNetwork = meta.pendingRemoval?.state === 'broadcast'
1132
+ const canDeposit = enabled && !transfersBlocked && hasRecoveryRedundancy && !overLockLimit
839
1133
  const canWithdraw = !transfersBlocked && hasAdoptedKey
840
1134
  const missingNames = coverage
841
1135
  ? meta.keys
@@ -844,9 +1138,16 @@ export function VaultScreen() {
844
1138
  .join(', ')
845
1139
  : ''
846
1140
  const relockCandidates = relock?.exclude ? meta.keys.filter(k => k.serial !== relock.exclude) : meta.keys
847
- const openGenericRelock = enabled
848
- ? () => openRelock({ reason: t('vault_relock_reason_generic'), revoke: meta.pendingRemoval?.key })
849
- : undefined
1141
+ const openGenericRelock =
1142
+ enabled && !overLockLimit
1143
+ ? () => openRelock({ reason: t('vault_relock_reason_generic'), revoke: meta.pendingRemoval?.key })
1144
+ : undefined
1145
+ // The header counts the removed key while its removal is pending, but never
1146
+ // reads "6 of 5": over the limit it drops the "of 5".
1147
+ const listedKeys = meta.keys.length + (meta.pendingRemoval ? 1 : 0)
1148
+ const keySectionHeader = overLockLimit
1149
+ ? t('vault_key_section_over_limit', { count: meta.keys.length })
1150
+ : t('vault_key_section', { count: listedKeys > VAULT_MAX_KEYS ? meta.keys.length : listedKeys })
850
1151
 
851
1152
  return (
852
1153
  <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
@@ -891,21 +1192,52 @@ export function VaultScreen() {
891
1192
  accessibilityState={{ disabled: !canWithdraw }}
892
1193
  style={[
893
1194
  styles.actionBtn,
894
- { backgroundColor: colors.backgroundElevated, borderColor: colors.separator, borderWidth: StyleSheet.hairlineWidth }
1195
+ {
1196
+ backgroundColor: colors.backgroundElevated,
1197
+ borderColor: colors.separator,
1198
+ borderWidth: StyleSheet.hairlineWidth
1199
+ }
895
1200
  ]}
896
1201
  >
897
- <Ionicons name="arrow-up" size={18} color={colors.accent} />
898
- <Text style={[styles.actionLabel, { color: colors.accent }]}>{t('vault_withdraw_cta')}</Text>
1202
+ <Ionicons name="arrow-up" size={18} color={canWithdraw ? colors.accent : colors.textTertiary} />
1203
+ <Text style={[styles.actionLabel, { color: canWithdraw ? colors.accent : colors.textTertiary }]}>
1204
+ {t('vault_withdraw_cta')}
1205
+ </Text>
899
1206
  </PressableScale>
900
1207
  </View>
901
1208
  {!enabled && <Text style={[styles.notice, { color: colors.textSecondary }]}>{t(unavailableCopy)}</Text>}
902
- {transfersBlocked && <Text style={[styles.notice, { color: colors.warning }]}>{t('vault_err_relock_required')}</Text>}
1209
+ {transfersBlocked && (
1210
+ <Text style={[styles.notice, { color: colors.warning }]}>
1211
+ {t(removalAwaitingNetwork ? 'vault_removal_awaiting_network' : 'vault_err_relock_required')}
1212
+ </Text>
1213
+ )}
1214
+ {overLockLimit && !transfersBlocked && (
1215
+ <Text style={[styles.notice, { color: colors.warning }]}>{t('vault_err_too_many_active_keys')}</Text>
1216
+ )}
903
1217
  {recoveryRequired && !hasRecoveryRedundancy && (
904
1218
  <Text style={[styles.notice, { color: colors.warning }]}>{t('vault_err_key_not_adopted')}</Text>
905
1219
  )}
1220
+ {actionPendingNotice && (
1221
+ <View style={[styles.notice, styles.actionPendingBlock]}>
1222
+ <Text style={[styles.heroNoticeBody, { color: colors.warning }]}>{vaultErrorCopy('action-pending')}</Text>
1223
+ <PressableScale
1224
+ haptic="confirm"
1225
+ onPress={resolvingDeposit ? undefined : () => void onResolveHeldDeposit()}
1226
+ accessibilityState={{ disabled: resolvingDeposit }}
1227
+ >
1228
+ {resolvingDeposit ? (
1229
+ <ActivityIndicator color={colors.accent} />
1230
+ ) : (
1231
+ <Text style={[typography.footnote, { color: colors.accent, fontWeight: '600', textAlign: 'center' }]}>
1232
+ {t('vault_resolve_held_deposit_action')}
1233
+ </Text>
1234
+ )}
1235
+ </PressableScale>
1236
+ </View>
1237
+ )}
906
1238
 
907
1239
  <GroupedSection
908
- header={t('vault_key_section', { count: meta.keys.length + (meta.pendingRemoval ? 1 : 0) })}
1240
+ header={keySectionHeader}
909
1241
  footer={t('vault_footnote')}
910
1242
  >
911
1243
  {coverage && coverage.missingKeys.length > 0 && (
@@ -945,16 +1277,22 @@ export function VaultScreen() {
945
1277
  <ListRow
946
1278
  key={`pending-${meta.pendingRemoval.key.serial}`}
947
1279
  label={`${meta.pendingRemoval.key.nickname} · ${formatVaultSerial(meta.pendingRemoval.key.serial)}`}
948
- subtitle={t('vault_key_pending_removal')}
1280
+ subtitle={t(removalAwaitingNetwork ? 'vault_key_removal_awaiting_network' : 'vault_key_pending_removal')}
949
1281
  icon="time-outline"
950
1282
  iconColor={colors.warning}
951
1283
  showChevron={false}
952
- onPress={openGenericRelock}
1284
+ onPress={removalAwaitingNetwork ? undefined : openGenericRelock}
953
1285
  isLast={!canAdd}
954
1286
  />
955
1287
  )}
956
1288
  {canAdd && (
957
- <ListRow label={t('vault_add_key_row')} icon="add-circle-outline" iconColor={colors.info} onPress={openAddKey} isLast />
1289
+ <ListRow
1290
+ label={t('vault_add_key_row')}
1291
+ icon="add-circle-outline"
1292
+ iconColor={colors.info}
1293
+ onPress={openAddKey}
1294
+ isLast
1295
+ />
958
1296
  )}
959
1297
  </GroupedSection>
960
1298
 
@@ -1011,7 +1349,11 @@ export function VaultScreen() {
1011
1349
  onSubmitEditing={() => void saveRename()}
1012
1350
  autoFocus
1013
1351
  />
1014
- <PressableScale haptic="confirm" onPress={() => void saveRename()} style={[styles.primary, { backgroundColor: colors.accent }]}>
1352
+ <PressableScale
1353
+ haptic="confirm"
1354
+ onPress={() => void saveRename()}
1355
+ style={[styles.primary, { backgroundColor: colors.accent }]}
1356
+ >
1015
1357
  <Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_rename_save')}</Text>
1016
1358
  </PressableScale>
1017
1359
  <PressableScale onPress={() => setRenaming(null)} style={styles.secondary}>
@@ -1078,7 +1420,12 @@ export function VaultScreen() {
1078
1420
  </Sheet>
1079
1421
 
1080
1422
  {/* Re-lock — choose the key, then one ceremony tap per pass. */}
1081
- <Sheet visible={relock !== null} onClose={relocking ? noop : closeRelock} title={t('vault_relock_row')} fitContent>
1423
+ <Sheet
1424
+ visible={relock !== null}
1425
+ onClose={relocking ? noop : closeRelock}
1426
+ title={t('vault_relock_row')}
1427
+ fitContent
1428
+ >
1082
1429
  <View style={styles.sheetBody}>
1083
1430
  {relock?.reason ? <Text style={[styles.p, { color: colors.textSecondary }]}>{relock.reason}</Text> : null}
1084
1431
  <Text style={[styles.sheetLabel, { color: colors.textPrimary }]}>{t('vault_relock_choose')}</Text>
@@ -1105,6 +1452,7 @@ export function VaultScreen() {
1105
1452
  <BiometricAdvisoryModal
1106
1453
  visible={showBiometricAdvisory}
1107
1454
  loading={creatingWallet}
1455
+ degraded={advisoryDegraded}
1108
1456
  onCancel={() => setShowBiometricAdvisory(false)}
1109
1457
  onContinue={onAdvisoryContinue}
1110
1458
  />
@@ -1142,6 +1490,7 @@ const styles = StyleSheet.create({
1142
1490
  h1: { ...typography.title1, textAlign: 'center' },
1143
1491
  p: { ...typography.subhead, textAlign: 'center' },
1144
1492
  notice: { ...typography.footnote, textAlign: 'center', paddingHorizontal: spacing.xl, marginBottom: spacing.xxl },
1493
+ actionPendingBlock: { gap: spacing.sm },
1145
1494
  primary: { width: '100%', borderRadius: radii.md, paddingVertical: spacing.lg, alignItems: 'center' },
1146
1495
  primaryLabel: { ...typography.headline },
1147
1496
  secondary: { paddingVertical: spacing.md, alignItems: 'center' },