@bsv/expo-wallet-toolbox 0.3.1 → 0.5.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 (119) hide show
  1. package/CHANGELOG.md +311 -0
  2. package/README.md +52 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/config.tsx +21 -18
  6. package/core/context/VaultContext.tsx +8 -11
  7. package/core/context/WalletConnectionContext.tsx +137 -52
  8. package/core/context/WalletContext.tsx +413 -23
  9. package/core/hooks/useConfirmationSound.ts +14 -8
  10. package/core/i18n/translations.tsx +3368 -952
  11. package/core/index.ts +107 -14
  12. package/core/localpay/build.ts +674 -37
  13. package/core/localpay/codec.ts +68 -5
  14. package/core/localpay/pending.ts +240 -22
  15. package/core/localpay/settlementAck.ts +149 -0
  16. package/core/localpay/types.ts +14 -1
  17. package/core/localpay/verify.ts +118 -69
  18. package/core/mandala/abortGuard.ts +134 -0
  19. package/core/mandala/basketMigration.ts +166 -0
  20. package/core/mandala/bundle.ts +244 -0
  21. package/core/mandala/createRuntime.ts +2437 -0
  22. package/core/mandala/drain.ts +670 -0
  23. package/core/mandala/permissionModule.ts +642 -0
  24. package/core/mandala/resendTransfer.ts +175 -0
  25. package/core/mandala/runtime.ts +357 -0
  26. package/core/mandala/settlementStore.ts +412 -0
  27. package/core/mandala/types.ts +290 -0
  28. package/core/offline/cancelParked.ts +94 -1
  29. package/core/offline/payerHold.ts +152 -12
  30. package/core/offline/tokenFrames.ts +197 -0
  31. package/core/parsePeerPayURI.ts +70 -17
  32. package/core/pay/rails/address.ts +51 -3
  33. package/core/pay/rails/handle.ts +88 -9
  34. package/core/pay/rails/index.ts +16 -6
  35. package/core/pay/rails/nearby.ts +114 -4
  36. package/core/services/capWalletArgs.ts +8 -9
  37. package/core/services/externalOrigin.ts +39 -0
  38. package/core/services/vault/VaultKeyService.ts +912 -251
  39. package/core/services/vault/ceremony.ts +435 -367
  40. package/core/services/vault/ceremonyHost.ts +27 -21
  41. package/core/services/vault/devMock.ts +30 -7
  42. package/core/services/vault/driver.ts +95 -41
  43. package/core/services/vault/guard.ts +514 -56
  44. package/core/services/vault/hardwareLease.ts +22 -0
  45. package/core/services/vault/mockYubiKey.ts +258 -90
  46. package/core/services/vault/pivReset.ts +145 -0
  47. package/core/services/vault/r1comb.ts +976 -0
  48. package/core/services/vault/session.ts +93 -26
  49. package/core/services/vault/transfers.ts +2617 -747
  50. package/core/services/vault/types.ts +100 -43
  51. package/core/services/vault/vaultStore.ts +991 -74
  52. package/core/services/walletConnectionValidation.ts +293 -0
  53. package/core/services/walletServiceConfig.ts +19 -24
  54. package/core/storage/StorageExpoSQLite.ts +382 -56
  55. package/core/storage/dbImage.ts +48 -0
  56. package/core/storage/methods/findSql.ts +0 -54
  57. package/core/storage/methods/listOutputsSql.ts +7 -3
  58. package/core/storage/methods/offlineActions.ts +15 -0
  59. package/core/storage/methods/processOfflineActions.ts +263 -6
  60. package/core/storage/methods/walletBalanceSql.ts +16 -4
  61. package/core/storage/schema/createTables.ts +123 -0
  62. package/core/storage/sqlUpdateValue.ts +24 -0
  63. package/core/toolboxConfig.ts +240 -0
  64. package/core/walletRepair/runWalletCheck.ts +19 -2
  65. package/package.json +25 -24
  66. package/ui/components/QRScanner.tsx +1 -1
  67. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  68. package/ui/components/pay/AssetPicker.tsx +184 -0
  69. package/ui/components/pay/AvailableBalance.tsx +33 -2
  70. package/ui/components/pay/HandleReceive.tsx +213 -50
  71. package/ui/components/pay/NearbyFlow.tsx +616 -69
  72. package/ui/components/pay/PayForm.tsx +73 -8
  73. package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
  74. package/ui/components/pay/RecipientField.tsx +49 -4
  75. package/ui/components/pay/RequestHub.tsx +68 -8
  76. package/ui/components/pay/ResultBanner.tsx +41 -4
  77. package/ui/components/pay/UniversalSend.tsx +534 -30
  78. package/ui/components/pay/tokenSendCopy.ts +116 -0
  79. package/ui/components/pay/useRecipientInput.ts +36 -7
  80. package/ui/components/ui/PermissionSheet.tsx +65 -4
  81. package/ui/components/ui/Sheet.tsx +9 -2
  82. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  83. package/ui/components/vault/KeyChooser.tsx +96 -0
  84. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  85. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  86. package/ui/components/wallet/ActivityRow.tsx +101 -17
  87. package/ui/components/wallet/AmountInput.tsx +77 -25
  88. package/ui/components/wallet/AssetAmount.tsx +95 -0
  89. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  90. package/ui/components/wallet/tokenEviction.ts +65 -0
  91. package/ui/hooks/useExportWalletData.ts +39 -0
  92. package/ui/hooks/useMandala.ts +303 -0
  93. package/ui/hooks/useVaultBalance.ts +105 -7
  94. package/ui/hooks/useVaultCoverage.ts +52 -0
  95. package/ui/importDatabases.ts +7 -3
  96. package/ui/index.ts +50 -7
  97. package/ui/screens/ConnectionsScreen.tsx +46 -29
  98. package/ui/screens/PairScreen.tsx +12 -12
  99. package/ui/screens/PayScreen.tsx +130 -10
  100. package/ui/screens/SettingsScreen.tsx +18 -9
  101. package/ui/screens/VaultScreen.tsx +925 -171
  102. package/ui/screens/VaultTransferScreen.tsx +376 -123
  103. package/ui/screens/WalletCheckScreen.tsx +10 -1
  104. package/ui/screens/WalletConfigScreen.tsx +42 -20
  105. package/ui/screens/WalletHomeScreen.tsx +417 -86
  106. package/ui/screens/homeBadges.ts +9 -1
  107. package/ui/screens/tokenRowTitle.ts +68 -0
  108. package/ui/tokenFormat.ts +108 -0
  109. package/ui/tokenSeen.ts +75 -0
  110. package/ui/tokenStatus.ts +79 -0
  111. package/assets/sounds/vault-close.wav +0 -0
  112. package/assets/sounds/vault-open.wav +0 -0
  113. package/core/services/vault/k1.ts +0 -75
  114. package/core/services/vault/sealing.ts +0 -84
  115. package/core/services/vault/vaultDerivation.ts +0 -152
  116. package/core/services/vault/vaultPassphrase.ts +0 -287
  117. package/ui/components/vault/PassphraseField.tsx +0 -306
  118. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  119. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -30,9 +30,11 @@ import {
30
30
  eraseRemoteBackup,
31
31
  recoverMnemonicWallet,
32
32
  TaskBackupPush,
33
- DEFAULT_BACKUP_URL,
34
33
  setMockDriverEnabled,
35
- NO_MESSAGE_BOX
34
+ setMockPresentKey,
35
+ getMockPresentKey,
36
+ NO_MESSAGE_BOX,
37
+ getBackupUrl
36
38
  } from '@bsv/expo-wallet-toolbox'
37
39
 
38
40
  /**
@@ -64,7 +66,7 @@ import { ListRow } from '../components/ui/ListRow'
64
66
  import { showAlert } from '../components/ui/AlertCard'
65
67
  import { showToast } from '../components/ui/Toast'
66
68
  import { PrivateKey } from '@bsv/sdk'
67
- import { exportAllWalletDatabases } from '../exportDatabases'
69
+ import { useExportWalletData } from '../hooks/useExportWalletData'
68
70
  import { importWalletDatabase } from '../importDatabases'
69
71
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
70
72
 
@@ -105,6 +107,14 @@ function loadExpoRouter(): ExpoRouterModule {
105
107
  return expoRouterMod
106
108
  }
107
109
 
110
+ /** The three serials the DEV mock can present, cycled by the selector row below. */
111
+ type MockPresentKey = Parameters<typeof setMockPresentKey>[0]
112
+ const NEXT_MOCK_KEY: Record<MockPresentKey, MockPresentKey> = {
113
+ 'MOCK-DEV-1': 'MOCK-DEV-2',
114
+ 'MOCK-DEV-2': 'MOCK-DEV-3',
115
+ 'MOCK-DEV-3': 'MOCK-DEV-1'
116
+ }
117
+
108
118
  export function WalletConfigScreen() {
109
119
  const versionLabel = useMemo(() => appVersionLabel(), [])
110
120
  const { t } = useTranslation()
@@ -129,7 +139,10 @@ export function WalletConfigScreen() {
129
139
 
130
140
  const [switchingNetwork, setSwitchingNetwork] = useState(false)
131
141
  const [networkExpanded, setNetworkExpanded] = useState(false)
132
- const [isExporting, setIsExporting] = useState(false)
142
+ const { exportData, exporting } = useExportWalletData()
143
+ // Not read from getMockPresentKey() at mount: the mock is off by default and
144
+ // the row is hidden until the toggle turns it on, at which point it syncs.
145
+ const [mockPresent, setMockPresent] = useState<MockPresentKey>('MOCK-DEV-1')
133
146
  const [isImporting, setIsImporting] = useState(false)
134
147
  const [vaultMockOn, setVaultMockOn] = useState(false)
135
148
  const [backupPushOn, setBackupPushOn] = useState(true)
@@ -257,7 +270,7 @@ export function WalletConfigScreen() {
257
270
  // chain propagates — a partial erasure must never be reported as done.
258
271
  let deleted = 0
259
272
  for (const chain of BACKUP_CHAINS) {
260
- deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl: DEFAULT_BACKUP_URL })).deleted
273
+ deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl: getBackupUrl() })).deleted
261
274
  }
262
275
  setBackupPushOn(false)
263
276
  showToast(t('backup_erase_done', { count: deleted }), { type: 'success' })
@@ -370,18 +383,6 @@ export function WalletConfigScreen() {
370
383
  })
371
384
  }, [])
372
385
 
373
- const handleExportData = async () => {
374
- if (isExporting) return
375
- setIsExporting(true)
376
- try {
377
- await exportAllWalletDatabases(storage)
378
- } catch (e) {
379
- console.warn('[WalletConfig] Export failed:', e)
380
- } finally {
381
- setIsExporting(false)
382
- }
383
- }
384
-
385
386
  const handleImportData = async () => {
386
387
  if (isImporting) return
387
388
  setIsImporting(true)
@@ -797,6 +798,27 @@ export function WalletConfigScreen() {
797
798
  const next = !vaultMockOn
798
799
  setVaultMockOn(next)
799
800
  setMockDriverEnabled(next)
801
+ if (next) setMockPresent(getMockPresentKey())
802
+ }}
803
+ />
804
+ )}
805
+ {/* Which of the three mock YubiKeys is "on the phone" right now.
806
+ A 1-of-N vault enrolled with MOCK-DEV-1 and MOCK-DEV-2 is
807
+ exercised by switching the present key between taps. The label
808
+ is a literal rather than user copy because this row renders
809
+ only under the `__DEV__` gate just below — it never reaches a
810
+ release build. */}
811
+ {__DEV__ && vaultMockOn && (
812
+ <ListRow
813
+ label="Mock key present (dev)"
814
+ icon="key-outline"
815
+ iconColor="#8E8E93"
816
+ showChevron={false}
817
+ value={mockPresent}
818
+ onPress={() => {
819
+ const next = NEXT_MOCK_KEY[mockPresent]
820
+ setMockPresent(next)
821
+ setMockPresentKey(next)
800
822
  }}
801
823
  />
802
824
  )}
@@ -818,9 +840,9 @@ export function WalletConfigScreen() {
818
840
  label={t('export_wallet_data')}
819
841
  icon="share-outline"
820
842
  iconColor="#32ADE6"
821
- onPress={handleExportData}
843
+ onPress={() => void exportData()}
822
844
  showChevron={false}
823
- trailing={isExporting ? <ActivityIndicator size="small" /> : undefined}
845
+ trailing={exporting ? <ActivityIndicator size="small" /> : undefined}
824
846
  />
825
847
  <ListRow
826
848
  label={t('import_wallet_data')}
@@ -844,7 +866,7 @@ export function WalletConfigScreen() {
844
866
  Its own section purely so the footer can carry the disclosure: the app sends an
845
867
  encrypted copy of the wallet database to a BSVA-operated server by default, and
846
868
  that deserves saying out loud rather than burying in a row label. */}
847
- {DEFAULT_BACKUP_URL !== '' && (
869
+ {getBackupUrl() !== '' && (
848
870
  <GroupedSection header={t('backup_push_section')} footer={t('backup_push_disclosure')}>
849
871
  <ListRow
850
872
  label={t('backup_push_toggle')}