@bsv/expo-wallet-toolbox 0.25.1 → 0.26.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 (43) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/core/context/WalletContext.tsx +3 -1
  3. package/core/i18n/translations.tsx +221 -36
  4. package/core/identity/handleRegistry/client.ts +110 -16
  5. package/core/identity/handleRegistry/registration.ts +115 -17
  6. package/core/profiles/profileStore.ts +4 -1
  7. package/core/services/groupSpendingLimit.ts +26 -0
  8. package/core/services/signingPermissionPolicy.ts +14 -8
  9. package/core/services/vault/ceremony.ts +13 -0
  10. package/core/services/vault/ceremonyHost.ts +58 -0
  11. package/core/services/vault/failedVaultSpend.ts +40 -0
  12. package/core/services/vault/outputAuthority.ts +13 -6
  13. package/core/services/vault/transfers.ts +56 -12
  14. package/core/storage/encryptedDbImage.ts +11 -2
  15. package/core/theme/tokens.ts +26 -12
  16. package/package.json +2 -1
  17. package/ui/components/QRScanner.tsx +24 -22
  18. package/ui/components/pay/MessageBoxConfig.tsx +10 -16
  19. package/ui/components/pay/NearbyAdvisoryModal.tsx +6 -13
  20. package/ui/components/pay/NearbyFlow.tsx +72 -35
  21. package/ui/components/pay/PayForm.tsx +27 -19
  22. package/ui/components/pay/PaymentSuccessOverlay.tsx +8 -6
  23. package/ui/components/pay/UniversalSend.tsx +4 -1
  24. package/ui/components/ui/AlertCard.tsx +3 -2
  25. package/ui/components/ui/BalancedText.tsx +117 -0
  26. package/ui/components/ui/ErrorBoundary.tsx +31 -14
  27. package/ui/components/ui/GroupedList.tsx +28 -22
  28. package/ui/components/ui/ListRow.tsx +126 -35
  29. package/ui/components/ui/PermissionSheet.tsx +31 -24
  30. package/ui/components/ui/PresenceRow.tsx +15 -23
  31. package/ui/components/ui/Sheet.tsx +11 -17
  32. package/ui/components/ui/Toast.tsx +13 -17
  33. package/ui/components/vault/EnrollWizard.tsx +446 -196
  34. package/ui/components/vault/KeyChooser.tsx +7 -20
  35. package/ui/components/vault/VaultCeremonySheet.tsx +44 -36
  36. package/ui/components/wallet/AmountInput.tsx +11 -17
  37. package/ui/components/wallet/BiometricAdvisoryModal.tsx +13 -17
  38. package/ui/index.ts +1 -1
  39. package/ui/screens/TrustScreen.tsx +49 -61
  40. package/ui/screens/VaultScreen.tsx +99 -60
  41. package/ui/screens/VaultTransferScreen.tsx +34 -27
  42. package/ui/screens/WalletCheckScreen.tsx +25 -24
  43. package/ui/screens/WalletConfigScreen.tsx +66 -72
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Vault enrollment wizard — spec §3.3.
3
3
  *
4
- * enroll mode: intro → key (× k; sub-states pin · puk · tap · save · error) → more → done
4
+ * enroll mode: intro → key (× k; sub-states pin · confirm · puk · tap · save · error) → more → done
5
5
  * add-key mode: key → done
6
6
  *
7
7
  * Public, non-authoritative recovery handles are persisted in wallet-scoped
@@ -19,11 +19,13 @@
19
19
  * time, and a text field between a finished card and a saved key is one more
20
20
  * thing to get wrong mid-ceremony.
21
21
  *
22
- * The host screen hides its own back chevron while this is mounted: leaving
23
- * goes through `leave()` — the leave-confirm alert when at least one key is
24
- * unsaved — which is also wired to Android's hardware back button. On the
25
- * `done` step back completes the wizard (`onDone`) instead, and while a card
26
- * session is open it is swallowed: the tap's outcome must land somewhere.
22
+ * The host screen points its own back chevron at `onBackChange` while this is
23
+ * mounted (there is no Back button on the pages, which the keyboard would
24
+ * cover). Back is one page inside a key where there is one, and otherwise
25
+ * `leave()` — the leave-confirm alert when at least one key is unsaved — which
26
+ * Android's hardware back button gets too. On the `done` step back completes
27
+ * the wizard (`onDone`) instead, and while a card session is open it is
28
+ * swallowed: the tap's outcome must land somewhere.
27
29
  *
28
30
  * Whatever meta is stored is loaded in BOTH modes and its serials are always
29
31
  * passed to `enrollKey` as `pendingSerials` (spec §3.3 step 2). The service
@@ -33,7 +35,28 @@
33
35
  * Finish replaces whatever is stored.
34
36
  */
35
37
  import React, { useCallback, useEffect, useRef, useState } from 'react'
36
- import { View, Text, StyleSheet, TextInput, ScrollView, ActivityIndicator, BackHandler, Platform } from 'react-native'
38
+ import {
39
+ View,
40
+ Text,
41
+ StyleSheet,
42
+ TextInput,
43
+ ScrollView,
44
+ KeyboardAvoidingView,
45
+ ActivityIndicator,
46
+ BackHandler,
47
+ Platform
48
+ } from 'react-native'
49
+ import {
50
+ CircleAlert,
51
+ CircleCheck,
52
+ CloudUpload,
53
+ KeyRound,
54
+ MapPin,
55
+ Square,
56
+ SquareCheckBig,
57
+ TriangleAlert,
58
+ type LucideIcon
59
+ } from 'lucide-react-native'
37
60
  import PressableScale from '../ui/PressableScale'
38
61
  import { showAlert } from '../ui/AlertCard'
39
62
  import { showToast } from '../ui/Toast'
@@ -64,36 +87,33 @@ import {
64
87
  type VaultScopeToken,
65
88
  type VaultErrorCode,
66
89
  type EnrollPhase,
67
- type VaultWalletAuthority
90
+ type VaultCardFunds,
91
+ type VaultResetClearance,
92
+ type VaultWalletAuthority,
93
+ VAULT_RESET_CLEARANCE_MS
68
94
  } from '@bsv/expo-wallet-toolbox'
95
+ import { BalancedText } from '../ui/BalancedText'
69
96
 
70
97
  const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
71
98
 
72
99
  /**
73
- * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
74
- * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
75
- * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
76
- * Loaded lazily, only when actually rendering, same pattern as this
77
- * package's other native-module-boundary fixes.
100
+ * lucide, the family this app draws every other glyph from (its settings rows,
101
+ * its headers, its sheets). Imported at module scope, unlike
102
+ * @expo/vector-icons: lucide-react-native ships a CJS entry for `require`, so
103
+ * it needs no transform and reaches no native module at import time, which is
104
+ * what this package's lazy icon loads exist to avoid.
78
105
  */
79
- type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
80
- let ioniconsComponent: IoniconsComponent | undefined
81
- function loadIonicons(): IoniconsComponent {
82
- if (!ioniconsComponent) {
83
- // eslint-disable-next-line @typescript-eslint/no-require-imports
84
- ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
85
- }
86
- return ioniconsComponent
87
- }
88
106
 
89
107
  type Step = 'intro' | 'key' | 'more' | 'done'
90
- type KeySub = 'pin' | 'puk' | 'tap' | 'save' | 'reset' | 'error'
108
+ type KeySub = 'pin' | 'confirm' | 'puk' | 'tap' | 'save' | 'reset' | 'error'
91
109
 
92
110
  /** Pages a single key's setup walks through, for the progress indicator. The
93
111
  * count is per key, not per wizard: the number of keys is chosen during the
94
112
  * run (2 to 5), so a whole-wizard bar would move at a rate nobody can predict.
95
- * `save` is not one of them: it is a write, not a page the user works through. */
96
- const KEY_STEPS: readonly KeySub[] = ['pin', 'puk', 'tap']
113
+ * `save` is not one of them: it is a write, not a page the user works through.
114
+ * The PIN is chosen and confirmed on two of them: one field per page is what
115
+ * keeps Continue clear of the number pad (see KeyboardPage). */
116
+ const KEY_STEPS: readonly KeySub[] = ['pin', 'confirm', 'puk', 'tap']
97
117
 
98
118
  /** The PIV factory codes. The intro's whole-PIV acknowledgement asserts a
99
119
  * factory-reset (or Vault-dedicated) PIV application, so these are supplied to
@@ -246,18 +266,75 @@ const RESET_BEFORE_ERASE: ReadonlySet<VaultErrorCode> = new Set<VaultErrorCode>(
246
266
  'key-already-enrolled',
247
267
  'slot-occupied',
248
268
  'serial-mismatch',
249
- 'user-cancelled'
269
+ 'user-cancelled',
270
+ // the chain-check clearance ran out (it lasts ten minutes) before the reset: nothing was erased
271
+ 'chain-check-required'
250
272
  ])
251
273
 
274
+ /**
275
+ * A hardware-key illustration supplied by the host app, drawn at the moments
276
+ * this flow asks the user to touch their key. The package has no artwork of
277
+ * its own, and the host's is the one the rest of its vault pages already show,
278
+ * so it is taken as a prop rather than duplicated here. Given none, these
279
+ * screens fall back to what they drew before: a spinner, or the phase glyph.
280
+ *
281
+ * `waiting` is the blink: the drawing is expected to draw attention to the
282
+ * key's touch contact while it is true.
283
+ */
284
+ export type HardwareKeyArtComponent = React.ComponentType<{ waiting?: boolean; size?: number }>
285
+
252
286
  export interface EnrollWizardProps {
253
287
  mode: 'enroll' | 'add-key'
254
288
  onDone: () => void
255
289
  onCancel: () => void
290
+ keyArt?: HardwareKeyArtComponent
291
+ /**
292
+ * Drops the intro step's own title. The wizard names itself because the
293
+ * package's Vault screen opens it under a header that only says "Vault";
294
+ * a host that mounts it under a header already reading "Set up your vault"
295
+ * would otherwise print that line twice, one above the other. Only the
296
+ * intro is affected -- the later steps' titles say which key and which
297
+ * step, which no page header can.
298
+ */
299
+ hideIntroTitle?: boolean
300
+ /**
301
+ * The host's own back control, told what back means on the page showing now.
302
+ *
303
+ * Called with a new function whenever that changes. A host that wires its
304
+ * header chevron to it gets the step-back inside a key and the leave-confirm
305
+ * everywhere else, which is the point: a chevron of the host's own is a
306
+ * second, quieter way out of a wizard holding unsaved keys, and the one that
307
+ * skips the question about them.
308
+ */
309
+ onBackChange?: (back: () => void) => void
310
+ /**
311
+ * The chain check that runs before a card is reset or its Vault slot replaced (audit: reset-new-phone).
312
+ * `check` is checkVaultCardFunds for this card; `args` turns its answer (and the person's affirmation) into the
313
+ * arguments resetPivApplication takes, or null while the reset must not go ahead. Without it the wizard cannot
314
+ * tell whether the card opens a vault: it treats that as "unknown" and a reset needs the affirmation.
315
+ */
316
+ cardGate?: {
317
+ check: (serial: string) => Promise<VaultCardFunds>
318
+ args: (
319
+ result: VaultCardFunds | null,
320
+ affirmed: boolean
321
+ ) => { fundsClearance: VaultResetClearance } | { acknowledgeFundsLoss: true } | null
322
+ }
323
+ /** The key on the card opens a vault: leave the wizard and restore it (adopt the key on the card). */
324
+ onRestoreVault?: (serial: string) => void
256
325
  }
257
326
 
258
- export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCancel }) => {
327
+ export const EnrollWizard: React.FC<EnrollWizardProps> = ({
328
+ mode,
329
+ onDone,
330
+ onCancel,
331
+ keyArt: KeyArt,
332
+ hideIntroTitle = false,
333
+ onBackChange,
334
+ cardGate,
335
+ onRestoreVault
336
+ }) => {
259
337
  const { colors } = useTheme()
260
- const Ionicons = loadIonicons()
261
338
  // Every public record collected in this wizard belongs to the wallet/chain
262
339
  // scope that opened it. Holding one token for the whole lifetime prevents a
263
340
  // late enrollment result from being persisted after logout or a network
@@ -320,6 +397,11 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
320
397
  /** The separate consent that unknown key may be destroyed. */
321
398
  const [resetUnknownAck, setResetUnknownAck] = useState(false)
322
399
  const [resetting, setResetting] = useState(false)
400
+ /** The chain check for the card on the reset page or the slot-occupied page. null while it runs. */
401
+ const [cardCheck, setCardCheck] = useState<VaultCardFunds | null>(null)
402
+ const [checkRound, setCheckRound] = useState(0)
403
+ /** "Any funds in a vault that uses this key are lost for good if you reset it." */
404
+ const [lossAck, setLossAck] = useState(false)
323
405
  /** A write (finalizeEnrollment / addVaultKey) is in flight. */
324
406
  const [busy, setBusy] = useState(false)
325
407
  const [stepError, setStepError] = useState<string | null>(null)
@@ -328,8 +410,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
328
410
  const tapInFlight = useRef(false)
329
411
  /** One leave-confirm at a time. */
330
412
  const leaving = useRef(false)
331
- /** The PIN field, focused on a delay below instead of via `autoFocus`. */
413
+ /** The PIN fields, each focused on a delay below instead of via `autoFocus`. */
332
414
  const pinInputRef = useRef<TextInput>(null)
415
+ const confirmInputRef = useRef<TextInput>(null)
333
416
 
334
417
  /** Stored keys that count toward the ordinal and the 5-key cap: all of them
335
418
  * when adding to a vault, none while enrolling one (Finish overwrites). */
@@ -349,6 +432,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
349
432
  * cannot go stale — see KeyStepError.)
350
433
  */
351
434
  const clearResetConsent = () => {
435
+ setLossAck(false)
352
436
  setResetAck(false)
353
437
  setResetUnknownSlot(false)
354
438
  setResetUnknownAck(false)
@@ -366,6 +450,39 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
366
450
  clearResetConsent()
367
451
  }
368
452
 
453
+ // ── the chain check before a reset or a replace (audit: reset-new-phone) ─────────────────────────────────
454
+ // A card that already opens a vault must not be wiped on this phone's say-so: this phone may know nothing
455
+ // of it. The check runs when the reset page or the slot-occupied page shows. Plain path: a complete scan
456
+ // found nothing. Otherwise the person restores the vault, or affirms that earlier funds are lost for good.
457
+ const gateSerial =
458
+ sub === 'reset' || (sub === 'error' && keyError?.code === 'slot-occupied') ? keyError?.resetSerial : undefined
459
+ useEffect(() => {
460
+ setCardCheck(null)
461
+ // a new check starts: the sentence ticked for an earlier result is not carried over to this one
462
+ setLossAck(false)
463
+ if (!gateSerial) return
464
+ let live = true
465
+ const unknown = (reason: string): VaultCardFunds => ({ kind: 'unknown', serial: gateSerial, reason, problems: 0 })
466
+ if (!cardGate) {
467
+ setCardCheck(unknown('no-check'))
468
+ return
469
+ }
470
+ cardGate.check(gateSerial).then(
471
+ result => live && setCardCheck(result),
472
+ () => live && setCardCheck(unknown('check-failed'))
473
+ )
474
+ return () => {
475
+ live = false
476
+ }
477
+ }, [gateSerial, cardGate, checkRound])
478
+ /** What resetPivApplication takes, or null while the card may not be reset or replaced. */
479
+ const gateArgs: { fundsClearance: VaultResetClearance } | { acknowledgeFundsLoss: true } | null = cardGate
480
+ ? cardGate.args(cardCheck, lossAck)
481
+ : cardCheck && lossAck
482
+ ? { acknowledgeFundsLoss: true }
483
+ : null
484
+ const bsvAmount = (sats: number) => `${Number((sats / 100_000_000).toFixed(8))} BSV`
485
+
369
486
  // ── saving a finished key ───────────────────────────────────────────
370
487
  /**
371
488
  * Persist the key a card just produced, under the default name for its
@@ -522,20 +639,53 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
522
639
  }
523
640
  }, [step, busy, unsaved, onCancel, onDone])
524
641
 
642
+ /**
643
+ * Back, on the page showing now: one page back inside a key where there is
644
+ * one, the leave-confirm everywhere else. The pages the keyboard covers have
645
+ * no Back button of their own, so this is the only step-back there is —
646
+ * which is also why it is the same function the hardware button gets.
647
+ */
648
+ const back = useCallback(() => {
649
+ if (step === 'key' && sub === 'confirm') return setSub('pin')
650
+ if (step === 'key' && sub === 'puk') return setSub('confirm')
651
+ void leave()
652
+ }, [step, sub, leave])
653
+
654
+ /**
655
+ * The host is handed one function, once, which asks for the current one when
656
+ * it is pressed.
657
+ *
658
+ * A fresh closure on every page would re-render any host that keeps it in
659
+ * state, and a host whose `onDone`/`onCancel` is an inline arrow — both of
660
+ * ours — re-renders this, which rebuilds the closure, which hands over
661
+ * again: a loop React only stops by throwing "Maximum update depth
662
+ * exceeded". The indirection makes the handover happen once, at mount.
663
+ */
664
+ const backNow = useRef(back)
665
+ useEffect(() => {
666
+ backNow.current = back
667
+ }, [back])
668
+ const handOverBack = useCallback(() => backNow.current(), [])
669
+ useEffect(() => {
670
+ onBackChange?.(handOverBack)
671
+ }, [onBackChange, handOverBack])
672
+
525
673
  useEffect(() => {
526
674
  const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
527
- void leave()
675
+ back()
528
676
  return true
529
677
  })
530
678
  return () => subscription.remove()
531
- }, [leave])
679
+ }, [back])
532
680
 
533
681
  // Focus the PIN field on a delay rather than via `autoFocus`, which grabs
534
682
  // focus before this step's mount/layout settles and drops the first
535
683
  // keystroke (see the matching fix + comment in VaultCeremonySheet).
536
684
  useEffect(() => {
537
- if (step !== 'key' || sub !== 'pin') return
538
- const timer = setTimeout(() => pinInputRef.current?.focus(), 150)
685
+ if (step !== 'key') return
686
+ const field = sub === 'pin' ? pinInputRef : sub === 'confirm' ? confirmInputRef : null
687
+ if (!field) return
688
+ const timer = setTimeout(() => field.current?.focus(), 150)
539
689
  return () => clearTimeout(timer)
540
690
  }, [step, sub])
541
691
 
@@ -582,6 +732,19 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
582
732
  const runTap = useCallback(
583
733
  async (replaceOccupiedVaultSlot = false) => {
584
734
  if (tapInFlight.current || !pivAck) return
735
+ // replacing the Vault slot destroys the key in it: the same chain check as a reset
736
+ if (replaceOccupiedVaultSlot && gateArgs === null) return
737
+ // the toolbox checks the clearance for a replace too, but only after the card is presented: the ten minutes are
738
+ // kept here so an older 'clear' is checked again before the slot is opened
739
+ if (
740
+ replaceOccupiedVaultSlot &&
741
+ gateArgs &&
742
+ 'fundsClearance' in gateArgs &&
743
+ Date.now() - gateArgs.fundsClearance.issuedAt > VAULT_RESET_CLEARANCE_MS
744
+ ) {
745
+ setCheckRound(round => round + 1)
746
+ return
747
+ }
585
748
  tapInFlight.current = true
586
749
  setSub('tap')
587
750
  setPhase(null)
@@ -598,9 +761,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
598
761
  acknowledgeDedicatedPivApplication: true,
599
762
  pendingSerials: known,
600
763
  nickname: t('vault_name_default', { k }),
601
- // TEMP DIAG: the phase stream says how far the card session got.
602
764
  onPhase: p => {
603
- if (__DEV__) console.log(`[vault][diag] phase=${p}`)
604
765
  setPhase(p)
605
766
  },
606
767
  // The intro's whole-PIV acknowledgement already asserts a
@@ -615,33 +776,14 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
615
776
  // withKeySession → driver.start). Omitting it would fall back to the
616
777
  // native default wording.
617
778
  nfcMessage: t('vault_nfc_enroll_message'),
618
- replaceOccupiedVaultSlot
779
+ replaceOccupiedVaultSlot,
780
+ // Replace destroys the key in the slot: the toolbox wants the same gate as a reset
781
+ ...(replaceOccupiedVaultSlot && gateArgs ? gateArgs : {})
619
782
  })
620
783
  haptics.success()
621
784
  await saveKey(record)
622
785
  } catch (e) {
623
786
  haptics.error()
624
- // TEMP DIAG: the real error behind whatever copy the screen shows.
625
- if (__DEV__) {
626
- const ve = e instanceof VaultError ? e : undefined
627
- console.log(
628
- `[vault][diag] enrollKey threw code=${ve?.code ?? '(not VaultError)'} name=${
629
- (e as Error)?.name
630
- } msg=${JSON.stringify((e as Error)?.message)} details=${JSON.stringify(ve?.details)} cause=${JSON.stringify(
631
- (() => {
632
- const c = (e as { cause?: unknown })?.cause
633
- if (!c) return null
634
- const cv = c instanceof VaultError ? c : undefined
635
- return {
636
- code: cv?.code,
637
- name: (c as Error)?.name,
638
- message: (c as Error)?.message,
639
- retriesLeft: cv?.retriesLeft
640
- }
641
- })()
642
- )}`
643
- )
644
- }
645
787
  try {
646
788
  vaultStore.assertScopeToken(scopeToken)
647
789
  } catch {
@@ -658,6 +800,19 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
658
800
  setSub('puk')
659
801
  return
660
802
  }
803
+ if (replaceOccupiedVaultSlot && err?.code === 'chain-check-required') {
804
+ // the toolbox refused the replace before it changed the card (the clearance ran out, or another key was
805
+ // tapped): nothing was erased. Back to the Replace page, with a new chain check for the card that was tapped.
806
+ setKeyError({
807
+ code: 'slot-occupied',
808
+ copy: vaultErrorCopy('slot-occupied'),
809
+ mustUseDifferent: false,
810
+ resetSerial: duplicateSerial(err) ?? gateSerial
811
+ })
812
+ setCheckRound(round => round + 1)
813
+ setSub('error')
814
+ return
815
+ }
661
816
  // Every partial personalization result is represented by a durable
662
817
  // scoped draft or quarantine. Never guess which global PIV credential
663
818
  // is current and never re-enter generic enrollment on the same token;
@@ -722,7 +877,21 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
722
877
  tapInFlight.current = false
723
878
  }
724
879
  },
725
- [k, metaKeys, pending, newPin, newPuk, onCancel, pivAck, saveKey, scopeToken, reloadDraftLists, requireAuthority]
880
+ [
881
+ k,
882
+ metaKeys,
883
+ pending,
884
+ newPin,
885
+ newPuk,
886
+ onCancel,
887
+ pivAck,
888
+ saveKey,
889
+ scopeToken,
890
+ reloadDraftLists,
891
+ requireAuthority,
892
+ gateArgs,
893
+ gateSerial
894
+ ]
726
895
  )
727
896
 
728
897
  /** Resume only the non-mutating possession challenge for a protected draft.
@@ -853,6 +1022,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
853
1022
  const resetSerial = keyError?.resetSerial
854
1023
  if (!resetSerial || !resetAck || resetting || tapInFlight.current) return
855
1024
  if (resetUnknownSlot && !resetUnknownAck) return
1025
+ // the chain check (or the person's affirmation) decides what the reset may pass; nothing yet means no reset
1026
+ const gate = gateArgs
1027
+ if (!gate) return
856
1028
  setResetting(true)
857
1029
  // A card session is open: hardware back is swallowed until its outcome
858
1030
  // lands, the same invariant the enrollment tap holds — more so here,
@@ -892,6 +1064,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
892
1064
  refuseSerials: [...acrossChains, ...metaKeys.map(r => r.serial), ...pending.map(r => r.serial)],
893
1065
  acknowledgeDestroysAllCredentials: true,
894
1066
  ...(resetUnknownAck ? { acknowledgeUnrecognizedVaultKey: true as const } : {}),
1067
+ ...gate,
895
1068
  scopeToken,
896
1069
  nfcMessage: t('vault_nfc_enroll_message')
897
1070
  })
@@ -899,14 +1072,6 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
899
1072
  } catch (e) {
900
1073
  haptics.error()
901
1074
  const err = e instanceof VaultError ? e : undefined
902
- // TEMP DIAG: the real error behind the reset failure.
903
- if (__DEV__) {
904
- console.log(
905
- `[vault][diag] resetPivApplication threw code=${err?.code ?? '(not VaultError)'} msg=${JSON.stringify(
906
- (e as Error)?.message
907
- )} details=${JSON.stringify(err?.details)}`
908
- )
909
- }
910
1075
  if (err?.code === 'scope-changed') {
911
1076
  clearKeyInputs()
912
1077
  // Not the usual scope-changed line. This assertion also runs AFTER the
@@ -928,6 +1093,10 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
928
1093
  setStepError(t('vault_reset_nothing_erased'))
929
1094
  return
930
1095
  }
1096
+ if (err?.code === 'chain-check-required') {
1097
+ // the clearance ran out, or was never given: nothing was erased, so check the chain again
1098
+ setCheckRound(round => round + 1)
1099
+ }
931
1100
  setStepError(
932
1101
  err?.code === 'key-already-enrolled'
933
1102
  ? t('vault_err_reset_enrolled')
@@ -972,9 +1141,59 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
972
1141
  scopeToken,
973
1142
  onCancel,
974
1143
  runTap,
975
- reloadDraftLists
1144
+ reloadDraftLists,
1145
+ gateArgs
976
1146
  ])
977
1147
 
1148
+ /** Under the reset page and the slot-occupied page: what the chain check found, and what the person may do. */
1149
+ const cardGateBlock = (
1150
+ <>
1151
+ {cardCheck === null && (
1152
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_card_checking')}</BalancedText>
1153
+ )}
1154
+ {cardCheck?.kind === 'funds' && (
1155
+ <>
1156
+ <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_card_funds_title')}</Text>
1157
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>
1158
+ {t('vault_card_funds_body', { count: cardCheck.deposits, amount: bsvAmount(cardCheck.satoshis) })}
1159
+ </BalancedText>
1160
+ {onRestoreVault && (
1161
+ <ActionButton label={t('vault_card_restore')} onPress={() => onRestoreVault(cardCheck.serial)} />
1162
+ )}
1163
+ </>
1164
+ )}
1165
+ {cardCheck?.kind === 'unknown' && (
1166
+ <>
1167
+ <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_card_unknown_title')}</Text>
1168
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_card_unknown_body')}</BalancedText>
1169
+ {cardGate && (
1170
+ <ActionButton
1171
+ label={t('vault_card_retry')}
1172
+ variant="outline"
1173
+ onPress={() => setCheckRound(round => round + 1)}
1174
+ />
1175
+ )}
1176
+ </>
1177
+ )}
1178
+ {cardCheck && cardCheck.kind !== 'clear' && (
1179
+ <PressableScale
1180
+ accessibilityRole="checkbox"
1181
+ accessibilityState={{ checked: lossAck }}
1182
+ haptic="tap"
1183
+ onPress={() => setLossAck(value => !value)}
1184
+ style={[styles.ackRow, { borderColor: lossAck ? colors.error : colors.separator }]}
1185
+ >
1186
+ {lossAck ? (
1187
+ <SquareCheckBig size={20} color={colors.error} />
1188
+ ) : (
1189
+ <Square size={20} color={colors.textTertiary} />
1190
+ )}
1191
+ <Text style={[styles.ackText, { color: colors.textPrimary }]}>{t('vault_card_loss_ack')}</Text>
1192
+ </PressableScale>
1193
+ )}
1194
+ </>
1195
+ )
1196
+
978
1197
  const leaveLink = (
979
1198
  <PressableScale onPress={() => void leave()} style={styles.secondary}>
980
1199
  <Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>
@@ -991,11 +1210,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
991
1210
  onPress={() => setPivAck(value => !value)}
992
1211
  style={[styles.ackRow, { borderColor: pivAck ? colors.accent : colors.separator }]}
993
1212
  >
994
- <Ionicons
995
- name={pivAck ? 'checkbox' : 'square-outline'}
996
- size={24}
997
- color={pivAck ? colors.accent : colors.textTertiary}
998
- />
1213
+ {pivAck ? <SquareCheckBig size={20} color={colors.accent} /> : <Square size={20} color={colors.textTertiary} />}
999
1214
  <Text style={[styles.ackText, { color: colors.textPrimary }]}>{t('vault_intro_piv_ack')}</Text>
1000
1215
  </PressableScale>
1001
1216
  )
@@ -1004,12 +1219,12 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1004
1219
  if (step === 'intro') {
1005
1220
  return (
1006
1221
  <ScrollView contentContainerStyle={styles.body}>
1007
- <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_intro_title')}</Text>
1008
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_intro_what')}</Text>
1222
+ {!hideIntroTitle && <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_intro_title')}</Text>}
1223
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_intro_what')}</BalancedText>
1009
1224
  <View style={[styles.bullets, { borderColor: colors.separator }]}>
1010
- <Bullet icon="key-outline" text={t('vault_intro_two_keys')} />
1011
- <Bullet icon="location-outline" text={t('vault_intro_apart')} />
1012
- <Bullet icon="cloud-upload-outline" text={t('vault_intro_backup')} />
1225
+ <Bullet icon={KeyRound} text={t('vault_intro_two_keys')} />
1226
+ <Bullet icon={MapPin} text={t('vault_intro_apart')} />
1227
+ <Bullet icon={CloudUpload} text={t('vault_intro_backup')} />
1013
1228
  </View>
1014
1229
  <PressableScale
1015
1230
  accessibilityRole="checkbox"
@@ -1018,11 +1233,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1018
1233
  onPress={() => setAck(a => !a)}
1019
1234
  style={[styles.ackRow, { borderColor: ack ? colors.accent : colors.separator }]}
1020
1235
  >
1021
- <Ionicons
1022
- name={ack ? 'checkbox' : 'square-outline'}
1023
- size={24}
1024
- color={ack ? colors.accent : colors.textTertiary}
1025
- />
1236
+ {ack ? <SquareCheckBig size={20} color={colors.accent} /> : <Square size={20} color={colors.textTertiary} />}
1026
1237
  <Text style={[styles.ackText, { color: colors.textPrimary }]}>{t('vault_intro_ack')}</Text>
1027
1238
  </PressableScale>
1028
1239
  {pivAcknowledgement}
@@ -1031,7 +1242,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1031
1242
  before the card is touched — so this banner cannot claim the key is
1032
1243
  non-factory. It also names no key, because none is in hand here. */}
1033
1244
  {blockedDrafts.length > 0 && (
1034
- <Text style={[styles.warn, { color: colors.warning }]}>{t('vault_enrollment_state_uncertain')}</Text>
1245
+ <BalancedText style={[styles.warn, { color: colors.warning }]}>
1246
+ {t('vault_enrollment_state_uncertain')}
1247
+ </BalancedText>
1035
1248
  )}
1036
1249
  <ActionButton label={t('vault_intro_begin')} enabled={ack && pivAck} busy={busy} onPress={() => void begin()} />
1037
1250
  <PressableScale onPress={onCancel} style={styles.secondary}>
@@ -1045,32 +1258,19 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1045
1258
  if (step === 'key') {
1046
1259
  if (sub === 'pin') {
1047
1260
  const advance = () => {
1048
- if (!pivAck || busy) return
1049
- if (!pinChosen) {
1050
- // Never leave this silent: Continue is live so that pressing it is
1051
- // what produces the message, and a cleared error would read as the
1052
- // button simply not working.
1053
- setPinError(newPin === DEFAULT_PIV_PIN ? t('vault_pin_not_default') : t('vault_pin_choose_sub'))
1054
- return
1055
- }
1056
- if (confirmPin !== newPin) {
1057
- setPinError(t('vault_pin_mismatch'))
1058
- return
1059
- }
1261
+ if (!pivAck || busy || !pinChosen) return
1060
1262
  setPinError(null)
1061
- // Generated once per visit to the PUK page, so going back and forward
1062
- // does not silently hand the user a different code to write down. The
1063
- // one exception is a PIN that now equals the code: the service refuses
1064
- // that pair (validatePukChange) before the session opens, and the error
1065
- // page offers only a Retry that would fail identically forever.
1066
- if (!newPuk || newPuk === newPin) setNewPuk(generateRecoveryCode(newPin))
1067
- setSub('puk')
1263
+ setSub('confirm')
1068
1264
  }
1265
+ // The one refusal a disabled Continue cannot account for by itself: six
1266
+ // well-formed digits, refused anyway. Said while it is typed, because
1267
+ // there is no longer a press for it to be said on.
1268
+ const problem = pinError ?? (newPin === DEFAULT_PIV_PIN ? t('vault_pin_not_default') : null)
1069
1269
  return (
1070
- <ScrollView contentContainerStyle={styles.body} keyboardShouldPersistTaps="handled">
1270
+ <KeyboardPage>
1071
1271
  <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_key_step_title', { k })}</Text>
1072
1272
  <StepProgress sub={sub} />
1073
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_key_step_replace')}</Text>
1273
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_key_step_replace')}</BalancedText>
1074
1274
  {mode === 'add-key' && pivAcknowledgement}
1075
1275
 
1076
1276
  <Text style={[styles.label, { color: colors.textPrimary }]}>{t('vault_pin_choose_title')}</Text>
@@ -1083,6 +1283,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1083
1283
  onChangeText={text => {
1084
1284
  setPinError(null)
1085
1285
  setNewPin(text)
1286
+ // The confirmation is only ever a copy of this; a kept one would
1287
+ // make an edited PIN look confirmed on the next page.
1288
+ setConfirmPin('')
1086
1289
  }}
1087
1290
  placeholder="••••••"
1088
1291
  placeholderTextColor={colors.textTertiary}
@@ -1092,9 +1295,52 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1092
1295
  secureTextEntry
1093
1296
  maxLength={PIN_MAX}
1094
1297
  />
1298
+ {problem && <BalancedText style={[styles.err, { color: colors.error }]}>{problem}</BalancedText>}
1299
+ {stepError && <BalancedText style={[styles.err, { color: colors.error }]}>{stepError}</BalancedText>}
1300
+ {/* This page says "Choose a PIN", but resuming sends what is typed
1301
+ here to a card that already carries the PIN an earlier run set.
1302
+ A fresh choice is a guess, and three guesses lock a card holding
1303
+ a real, partially enrolled vault key — so say which PIN is wanted
1304
+ whenever a resume is actually on offer. */}
1305
+ {recoverableDrafts.length > 0 && (
1306
+ <Text style={[styles.hint, { color: colors.textSecondary }]}>{t('vault_enrollment_resume_pin_hint')}</Text>
1307
+ )}
1308
+ {/* Same hedge as the intro banner, and for the same reason. */}
1309
+ {blockedDrafts.length > 0 && (
1310
+ <BalancedText style={[styles.warn, { color: colors.warning }]}>
1311
+ {t('vault_enrollment_state_uncertain')}
1312
+ </BalancedText>
1313
+ )}
1314
+ <ActionButton label={t('vault_continue')} enabled={pivAck && pinChosen && !busy} onPress={advance} />
1315
+ {leaveLink}
1316
+ </KeyboardPage>
1317
+ )
1318
+ }
1095
1319
 
1320
+ if (sub === 'confirm') {
1321
+ const advance = () => {
1322
+ if (!pivAck || busy || !pinOk) return
1323
+ setPinError(null)
1324
+ // Generated once per visit to the PUK page, so going back and forward
1325
+ // does not silently hand the user a different code to write down. The
1326
+ // one exception is a PIN that now equals the code: the service refuses
1327
+ // that pair (validatePukChange) before the session opens, and the error
1328
+ // page offers only a Retry that would fail identically forever.
1329
+ if (!newPuk || newPuk === newPin) setNewPuk(generateRecoveryCode(newPin))
1330
+ setSub('puk')
1331
+ }
1332
+ // Typed far enough to be a whole PIN and still a different one. The
1333
+ // button is dead until these agree, so the page says why rather than
1334
+ // letting that read as a button that does nothing.
1335
+ const problem =
1336
+ pinError ?? (confirmPin.length >= newPin.length && confirmPin !== newPin ? t('vault_pin_mismatch') : null)
1337
+ return (
1338
+ <KeyboardPage>
1339
+ <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_key_step_title', { k })}</Text>
1340
+ <StepProgress sub={sub} />
1096
1341
  <Text style={[styles.label, { color: colors.textPrimary }]}>{t('vault_pin_confirm_label')}</Text>
1097
1342
  <TextInput
1343
+ ref={confirmInputRef}
1098
1344
  accessibilityLabel={t('vault_pin_confirm_label')}
1099
1345
  style={[styles.pin, { color: colors.textPrimary, backgroundColor: colors.backgroundSecondary }]}
1100
1346
  value={confirmPin}
@@ -1108,17 +1354,12 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1108
1354
  secureTextEntry
1109
1355
  maxLength={PIN_MAX}
1110
1356
  />
1111
-
1112
- {pinError && <Text style={[styles.err, { color: colors.error }]}>{pinError}</Text>}
1113
- {stepError && <Text style={[styles.err, { color: colors.error }]}>{stepError}</Text>}
1114
- {/* This page says "Choose a PIN", but resuming sends what is typed
1115
- here to a card that already carries the PIN an earlier run set.
1116
- A fresh choice is a guess, and three guesses lock a card holding
1117
- a real, partially enrolled vault key — so say which PIN is wanted
1118
- whenever a resume is actually on offer. */}
1119
- {recoverableDrafts.length > 0 && (
1120
- <Text style={[styles.hint, { color: colors.textSecondary }]}>{t('vault_enrollment_resume_pin_hint')}</Text>
1121
- )}
1357
+ {problem && <BalancedText style={[styles.err, { color: colors.error }]}>{problem}</BalancedText>}
1358
+ {stepError && <BalancedText style={[styles.err, { color: colors.error }]}>{stepError}</BalancedText>}
1359
+ {/* The hint about which PIN a resume wants is on the page that asks
1360
+ for it; the buttons are here because a resume spends that PIN on
1361
+ a card that locks after three wrong tries, and only a PIN typed
1362
+ twice the same is known to be the one meant. */}
1122
1363
  {recoverableDrafts.map(entry => (
1123
1364
  <ActionButton
1124
1365
  key={entry.record.serial}
@@ -1128,46 +1369,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1128
1369
  onPress={() => void resumeDraft(entry)}
1129
1370
  />
1130
1371
  ))}
1131
- {/* Same hedge as the intro banner, and for the same reason. */}
1132
- {blockedDrafts.length > 0 && (
1133
- <Text style={[styles.warn, { color: colors.warning }]}>{t('vault_enrollment_state_uncertain')}</Text>
1134
- )}
1135
- {/* TEMP DIAG (remove before commit): a quarantine is cleared only by a
1136
- successful in-app pivReset, so a card reset with `ykman piv reset`
1137
- stays locked out with no in-app escape. That is a real gap worth
1138
- fixing properly; this is the debugging shortcut in the meantime. */}
1139
- {__DEV__ && blockedDrafts.length > 0 && (
1140
- <ActionButton
1141
- label="DEV: clear stored quarantine"
1142
- variant="outline"
1143
- onPress={() => {
1144
- void (async () => {
1145
- for (const item of blockedDrafts) {
1146
- const serial = 'record' in item ? item.record.serial : item.serial
1147
- try {
1148
- await vaultStore.discardEnrollmentDraft(serial, scopeToken)
1149
- await vaultStore.discardEnrollmentQuarantine(serial, scopeToken)
1150
- console.log(`[vault][diag] DEV cleared quarantine + draft for ${serial}`)
1151
- } catch (e) {
1152
- console.log(`[vault][diag] DEV clear failed: ${JSON.stringify((e as Error)?.message)}`)
1153
- }
1154
- }
1155
- await reloadDraftLists()
1156
- })()
1157
- }}
1158
- />
1159
- )}
1160
- {/* NFC only: a brand-new YubiKey ships in restricted NFC mode (Yubico's
1161
- anti-scan-in-transit policy) and stays that way until it is plugged
1162
- into USB-C for a few seconds — a one-time, per-key step done outside
1163
- this app. Shown on every key here since we cannot tell a fresh card
1164
- from a already-activated one before the tap. */}
1165
- {Platform.OS === 'ios' && (
1166
- <Text style={[styles.hint, { color: colors.textSecondary }]}>{t('vault_nfc_activation_hint')}</Text>
1167
- )}
1168
- <ActionButton label={t('vault_continue')} enabled={pivAck && !busy} onPress={advance} />
1372
+ <ActionButton label={t('vault_continue')} enabled={pivAck && pinOk && !busy} onPress={advance} />
1169
1373
  {leaveLink}
1170
- </ScrollView>
1374
+ </KeyboardPage>
1171
1375
  )
1172
1376
  }
1173
1377
 
@@ -1195,7 +1399,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1195
1399
  >
1196
1400
  {newPuk}
1197
1401
  </Text>
1198
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_puk_body')}</Text>
1402
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_puk_body')}</BalancedText>
1199
1403
  <PressableScale
1200
1404
  accessibilityRole="checkbox"
1201
1405
  accessibilityState={{ checked: pukAck }}
@@ -1203,16 +1407,25 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1203
1407
  onPress={() => setPukAck(value => !value)}
1204
1408
  style={[styles.ackRow, { borderColor: pukAck ? colors.accent : colors.separator }]}
1205
1409
  >
1206
- <Ionicons
1207
- name={pukAck ? 'checkbox' : 'square-outline'}
1208
- size={24}
1209
- color={pukAck ? colors.accent : colors.textTertiary}
1210
- />
1410
+ {pukAck ? (
1411
+ <SquareCheckBig size={20} color={colors.accent} />
1412
+ ) : (
1413
+ <Square size={20} color={colors.textTertiary} />
1414
+ )}
1211
1415
  <Text style={[styles.ackText, { color: colors.textPrimary }]}>{t('vault_puk_ack')}</Text>
1212
1416
  </PressableScale>
1213
- {stepError && <Text style={[styles.err, { color: colors.error }]}>{stepError}</Text>}
1417
+ {stepError && <BalancedText style={[styles.err, { color: colors.error }]}>{stepError}</BalancedText>}
1418
+ {/* NFC only: a brand-new YubiKey ships in restricted NFC mode (Yubico's
1419
+ anti-scan-in-transit policy) and stays that way until it is plugged
1420
+ into USB-C for a few seconds — a one-time, per-key step done outside
1421
+ this app. Shown on every key here since we cannot tell a fresh card
1422
+ from a already-activated one before the tap. This is the last page
1423
+ before it, and the only one of the three the keyboard leaves room
1424
+ on. */}
1425
+ {Platform.OS === 'ios' && (
1426
+ <Text style={[styles.hint, { color: colors.textSecondary }]}>{t('vault_nfc_activation_hint')}</Text>
1427
+ )}
1214
1428
  <ActionButton label={t('vault_continue')} enabled={pukAck && pinOk && !busy} onPress={() => void runTap()} />
1215
- <ActionButton label={t('vault_back')} variant="outline" onPress={() => setSub('pin')} />
1216
1429
  {leaveLink}
1217
1430
  </ScrollView>
1218
1431
  )
@@ -1221,12 +1434,20 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1221
1434
  if (sub === 'tap') {
1222
1435
  return (
1223
1436
  <View style={styles.body}>
1224
- <ActivityIndicator color={colors.textPrimary} size="large" style={styles.hero} />
1437
+ {KeyArt ? (
1438
+ <View style={styles.keyArt}>
1439
+ <KeyArt waiting size={176} />
1440
+ </View>
1441
+ ) : (
1442
+ <ActivityIndicator color={colors.textPrimary} size="large" style={styles.hero} />
1443
+ )}
1225
1444
  <StepProgress sub={sub} />
1226
1445
  <Text style={[styles.h1, { color: colors.textPrimary }]}>
1227
1446
  {phase ? t(`vault_enroll_phase_${phase.replace(/-/g, '_')}`) : t('vault_reading_key')}
1228
1447
  </Text>
1229
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_touch_when_blinks')}</Text>
1448
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>
1449
+ {t('vault_touch_when_blinks')}
1450
+ </BalancedText>
1230
1451
  </View>
1231
1452
  )
1232
1453
  }
@@ -1240,7 +1461,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1240
1461
  <View style={styles.body}>
1241
1462
  {stepError ? (
1242
1463
  <>
1243
- <Ionicons name="alert-circle-outline" size={48} color={colors.error} style={styles.hero} />
1464
+ <CircleAlert size={48} color={colors.error} style={styles.hero} />
1244
1465
  <Text style={[styles.h1, { color: colors.textPrimary }]}>{stepError}</Text>
1245
1466
  <ActionButton
1246
1467
  label={t('vault_retry')}
@@ -1276,12 +1497,12 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1276
1497
  const resumableDraft = recoverableDrafts.find(entry => entry.record.serial === resetSerial)
1277
1498
  return (
1278
1499
  <ScrollView contentContainerStyle={styles.body}>
1279
- <Ionicons name="warning-outline" size={48} color={colors.warning} style={styles.hero} />
1500
+ <TriangleAlert size={48} color={colors.warning} style={styles.hero} />
1280
1501
  <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_reset_title')}</Text>
1281
- <Text style={[styles.p, { color: colors.textSecondary }]}>
1502
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>
1282
1503
  {resetSerial ? `…${resetSerial.slice(-4)}` : ''}
1283
- </Text>
1284
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_reset_body')}</Text>
1504
+ </BalancedText>
1505
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_reset_body')}</BalancedText>
1285
1506
  <PressableScale
1286
1507
  accessibilityRole="checkbox"
1287
1508
  accessibilityState={{ checked: resetAck }}
@@ -1289,18 +1510,19 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1289
1510
  onPress={() => setResetAck(value => !value)}
1290
1511
  style={[styles.ackRow, { borderColor: resetAck ? colors.error : colors.separator }]}
1291
1512
  >
1292
- <Ionicons
1293
- name={resetAck ? 'checkbox' : 'square-outline'}
1294
- size={24}
1295
- color={resetAck ? colors.error : colors.textTertiary}
1296
- />
1513
+ {resetAck ? (
1514
+ <SquareCheckBig size={20} color={colors.error} />
1515
+ ) : (
1516
+ <Square size={20} color={colors.textTertiary} />
1517
+ )}
1297
1518
  <Text style={[styles.ackText, { color: colors.textPrimary }]}>{t('vault_reset_ack')}</Text>
1298
1519
  </PressableScale>
1520
+ {cardGateBlock}
1299
1521
  {/* Directly above the question it explains. On `slot-occupied` this
1300
1522
  is the pre-erase line: the user pressed a destructive button and
1301
1523
  watched a card session open and close, and needs to be told the
1302
1524
  erase did not happen before being asked anything else. */}
1303
- {stepError && <Text style={[styles.err, { color: colors.error }]}>{stepError}</Text>}
1525
+ {stepError && <BalancedText style={[styles.err, { color: colors.error }]}>{stepError}</BalancedText>}
1304
1526
  {/* Shown only once the card itself has reported an occupied Vault
1305
1527
  slot. A separate question, because it is a separate loss — and
1306
1528
  which loss it is depends on whether this device knows the key in
@@ -1313,11 +1535,11 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1313
1535
  onPress={() => setResetUnknownAck(value => !value)}
1314
1536
  style={[styles.ackRow, { borderColor: resetUnknownAck ? colors.error : colors.separator }]}
1315
1537
  >
1316
- <Ionicons
1317
- name={resetUnknownAck ? 'checkbox' : 'square-outline'}
1318
- size={24}
1319
- color={resetUnknownAck ? colors.error : colors.textTertiary}
1320
- />
1538
+ {resetUnknownAck ? (
1539
+ <SquareCheckBig size={20} color={colors.error} />
1540
+ ) : (
1541
+ <Square size={20} color={colors.textTertiary} />
1542
+ )}
1321
1543
  <Text style={[styles.ackText, { color: colors.textPrimary }]}>
1322
1544
  {knownDraft ? t('vault_reset_own_draft_ack') : t('vault_reset_unknown_ack')}
1323
1545
  </Text>
@@ -1342,7 +1564,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1342
1564
  )}
1343
1565
  <ActionButton
1344
1566
  label={resetting ? t('vault_resetting') : t('vault_reset_confirm')}
1345
- enabled={resetAck && (!resetUnknownSlot || resetUnknownAck) && !resetting}
1567
+ enabled={resetAck && (!resetUnknownSlot || resetUnknownAck) && !resetting && gateArgs !== null}
1346
1568
  onPress={() => void runReset()}
1347
1569
  />
1348
1570
  <ActionButton
@@ -1362,7 +1584,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1362
1584
  const code = keyError?.code
1363
1585
  return (
1364
1586
  <View style={styles.body}>
1365
- <Ionicons name="alert-circle-outline" size={48} color={colors.error} style={styles.hero} />
1587
+ <CircleAlert size={48} color={colors.error} style={styles.hero} />
1366
1588
  <Text style={[styles.h1, { color: colors.textPrimary }]}>{keyError?.copy ?? t('vault_err_generic')}</Text>
1367
1589
  {/* Set only for a card whose failure a factory reset can actually fix
1368
1590
  (RESETTABLE minus NEVER_RESETTABLE), and only when the failure named
@@ -1380,8 +1602,15 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1380
1602
  ) : null}
1381
1603
  {code === 'slot-occupied' ? (
1382
1604
  <>
1383
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_replace_key_warning')}</Text>
1384
- <ActionButton label={t('vault_replace_key_confirm')} onPress={() => void runTap(true)} />
1605
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>
1606
+ {t('vault_replace_key_warning')}
1607
+ </BalancedText>
1608
+ {cardGateBlock}
1609
+ <ActionButton
1610
+ label={t('vault_replace_key_confirm')}
1611
+ enabled={gateArgs !== null}
1612
+ onPress={() => void runTap(true)}
1613
+ />
1385
1614
  <ActionButton label={t('vault_key_use_different')} variant="outline" onPress={chooseDifferentKey} />
1386
1615
  </>
1387
1616
  ) : code === 'key-already-enrolled' || code === 'puk-locked' || keyError?.mustUseDifferent ? (
@@ -1413,7 +1642,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1413
1642
  return (
1414
1643
  <ScrollView contentContainerStyle={styles.body}>
1415
1644
  <Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_more_title')}</Text>
1416
- <Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_more_body')}</Text>
1645
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_more_body')}</BalancedText>
1417
1646
  <View style={[styles.list, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}>
1418
1647
  {pending.map((p, i) => (
1419
1648
  <View
@@ -1426,15 +1655,17 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1426
1655
  }
1427
1656
  ]}
1428
1657
  >
1429
- <Ionicons name="key-outline" size={20} color={colors.success} />
1658
+ <KeyRound size={16} color={colors.success} />
1430
1659
  <Text style={[styles.listLabel, { color: colors.textPrimary }]} numberOfLines={1}>
1431
1660
  {vaultKeyLabel(p)}
1432
1661
  </Text>
1433
1662
  </View>
1434
1663
  ))}
1435
1664
  </View>
1436
- {!canFinish && <Text style={[styles.warn, { color: colors.warning }]}>{t('vault_more_need_two')}</Text>}
1437
- {stepError && <Text style={[styles.err, { color: colors.error }]}>{stepError}</Text>}
1665
+ {!canFinish && (
1666
+ <BalancedText style={[styles.warn, { color: colors.warning }]}>{t('vault_more_need_two')}</BalancedText>
1667
+ )}
1668
+ {stepError && <BalancedText style={[styles.err, { color: colors.error }]}>{stepError}</BalancedText>}
1438
1669
  {/* The filled button is whichever moves the user forward: Add while a
1439
1670
  second key is still required, Finish once there are enough. */}
1440
1671
  {canAdd && (
@@ -1457,15 +1688,15 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1457
1688
  const overLockLimit = mode === 'add-key' && enrolledCount + 1 > VAULT_MAX_KEYS
1458
1689
  return (
1459
1690
  <View style={[styles.body, styles.doneBody]}>
1460
- <Ionicons name="checkmark-circle" size={56} color={colors.success} style={styles.hero} />
1691
+ <CircleCheck size={56} color={colors.success} style={styles.hero} />
1461
1692
  <Text style={[styles.h1, { color: colors.textPrimary }]}>
1462
1693
  {mode === 'enroll' ? t('vault_enrolled_toast') : t('vault_key_added_toast')}
1463
1694
  </Text>
1464
- <Text style={[styles.p, { color: colors.textSecondary }]}>
1695
+ <BalancedText style={[styles.p, { color: colors.textSecondary }]}>
1465
1696
  {mode === 'enroll'
1466
1697
  ? t('vault_done_body', { count: pending.length })
1467
1698
  : t(overLockLimit ? 'vault_add_key_done_over_limit' : 'vault_add_key_done', { nickname: addedNickname })}
1468
- </Text>
1699
+ </BalancedText>
1469
1700
  <ActionButton
1470
1701
  label={mode === 'enroll' || overLockLimit ? t('vault_done_cta') : t('vault_relock_now')}
1471
1702
  onPress={onDone}
@@ -1475,8 +1706,26 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1475
1706
  }
1476
1707
 
1477
1708
  /**
1478
- * Where this key's setup has got to. Per key, three steps: choose a PIN, note
1479
- * the recovery code, tap.
1709
+ * A page whose Continue sits under a field the keyboard covers.
1710
+ *
1711
+ * The number pad takes about two-fifths of the screen, so the PIN is asked for
1712
+ * one field at a time and the scrolling area is lifted clear of the keyboard
1713
+ * rather than left behind it: `padding` shrinks this view by the keyboard's
1714
+ * height, which is what gives the page inside it a bottom the user can reach.
1715
+ * Android resizes the window itself (adjustResize) and would otherwise be
1716
+ * padded twice over.
1717
+ */
1718
+ const KeyboardPage: React.FC<{ children: React.ReactNode }> = ({ children }) => (
1719
+ <KeyboardAvoidingView style={styles.flex} behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
1720
+ <ScrollView style={styles.flex} contentContainerStyle={styles.body} keyboardShouldPersistTaps="handled">
1721
+ {children}
1722
+ </ScrollView>
1723
+ </KeyboardAvoidingView>
1724
+ )
1725
+
1726
+ /**
1727
+ * Where this key's setup has got to. Per key, four steps: choose a PIN,
1728
+ * confirm it, note the recovery code, tap.
1480
1729
  */
1481
1730
  const StepProgress: React.FC<{ sub: KeySub }> = ({ sub }) => {
1482
1731
  const { colors } = useTheme()
@@ -1495,12 +1744,11 @@ const StepProgress: React.FC<{ sub: KeySub }> = ({ sub }) => {
1495
1744
  }
1496
1745
 
1497
1746
  /** One intro bullet: glyph + line. */
1498
- const Bullet: React.FC<{ icon: React.ComponentProps<IoniconsComponent>['name']; text: string }> = ({ icon, text }) => {
1747
+ const Bullet: React.FC<{ icon: LucideIcon; text: string }> = ({ icon: Icon, text }) => {
1499
1748
  const { colors } = useTheme()
1500
- const Ionicons = loadIonicons()
1501
1749
  return (
1502
1750
  <View style={styles.bulletRow}>
1503
- <Ionicons name={icon} size={18} color={colors.info} />
1751
+ <Icon size={16} color={colors.info} />
1504
1752
  <Text style={[styles.bulletText, { color: colors.textPrimary }]}>{text}</Text>
1505
1753
  </View>
1506
1754
  )
@@ -1554,9 +1802,11 @@ const ActionButton: React.FC<{
1554
1802
  }
1555
1803
 
1556
1804
  const styles = StyleSheet.create({
1805
+ flex: { flex: 1 },
1557
1806
  body: { padding: spacing.xl, gap: spacing.lg },
1558
1807
  doneBody: { flexGrow: 1, justifyContent: 'center', alignItems: 'center' },
1559
1808
  hero: { marginTop: spacing.lg, alignSelf: 'center' },
1809
+ keyArt: { alignSelf: 'center', marginTop: spacing.sm, marginBottom: spacing.sm },
1560
1810
  h1: { ...typography.title2, textAlign: 'center' },
1561
1811
  p: { ...typography.subhead, textAlign: 'center' },
1562
1812
  label: { ...typography.headline },