@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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 (182) hide show
  1. package/CHANGELOG.md +547 -0
  2. package/README.md +19 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/amountFormatHelpers.ts +238 -34
  6. package/core/backup/RemoteSyncReader.ts +2 -5
  7. package/core/backup/codec.ts +2 -2
  8. package/core/backup/push.ts +1 -1
  9. package/core/config.tsx +16 -1
  10. package/core/contacts/contactActivity.ts +153 -0
  11. package/core/contacts/contactCache.ts +41 -0
  12. package/core/contacts/contactsStore.ts +183 -0
  13. package/core/context/VaultContext.tsx +8 -11
  14. package/core/context/WalletConnectionContext.tsx +137 -52
  15. package/core/context/WalletContext.tsx +464 -30
  16. package/core/demo/demoAssets.ts +60 -0
  17. package/core/demo/demoLedger.ts +240 -0
  18. package/core/demo/demoMandalaRuntime.ts +96 -0
  19. package/core/demo/demoMode.ts +38 -0
  20. package/core/demo/demoWallet.ts +25 -0
  21. package/core/demo/index.ts +26 -0
  22. package/core/demo/useDemo.ts +59 -0
  23. package/core/headers/OfflineFirstChaintracks.ts +52 -14
  24. package/core/headers/headerStore.ts +7 -10
  25. package/core/hooks/useConfirmationSound.ts +14 -8
  26. package/core/i18n/translations.tsx +4562 -986
  27. package/core/identity/contactLink.ts +36 -0
  28. package/core/identity/handleRegistry/client.ts +285 -0
  29. package/core/identity/handleRegistry/profileCert.ts +254 -0
  30. package/core/identity/handleRegistry/registration.ts +559 -0
  31. package/core/identity/handleRegistry/resolver.ts +247 -0
  32. package/core/identity/handleRegistry/rules.ts +104 -0
  33. package/core/index.ts +116 -15
  34. package/core/localpay/build.ts +674 -37
  35. package/core/localpay/codec.ts +68 -5
  36. package/core/localpay/pending.ts +240 -22
  37. package/core/localpay/pendingAborts.ts +5 -1
  38. package/core/localpay/settlementAck.ts +149 -0
  39. package/core/localpay/types.ts +14 -1
  40. package/core/localpay/verify.ts +118 -69
  41. package/core/mandala/abortGuard.ts +134 -0
  42. package/core/mandala/basketMigration.ts +166 -0
  43. package/core/mandala/bundle.ts +244 -0
  44. package/core/mandala/createRuntime.ts +2437 -0
  45. package/core/mandala/drain.ts +670 -0
  46. package/core/mandala/permissionModule.ts +642 -0
  47. package/core/mandala/resendTransfer.ts +175 -0
  48. package/core/mandala/runtime.ts +357 -0
  49. package/core/mandala/settlementStore.ts +412 -0
  50. package/core/mandala/types.ts +290 -0
  51. package/core/monitor/MonitorSupervisor.ts +121 -0
  52. package/core/monitor/TaskBackupPush.ts +1 -1
  53. package/core/monitor/TaskCreditInbox.ts +1 -1
  54. package/core/monitor/TaskDrainOutbox.ts +1 -1
  55. package/core/monitor/TaskSendOffline.ts +1 -1
  56. package/core/net/online.ts +49 -0
  57. package/core/numberFormat.ts +19 -0
  58. package/core/offline/cancelParked.ts +94 -1
  59. package/core/offline/payerHold.ts +152 -12
  60. package/core/offline/plan.ts +1 -1
  61. package/core/offline/tokenFrames.ts +197 -0
  62. package/core/parsePeerPayURI.ts +70 -17
  63. package/core/pay/rails/address.ts +51 -3
  64. package/core/pay/rails/handle.ts +88 -9
  65. package/core/pay/rails/index.ts +16 -6
  66. package/core/pay/rails/nearby.ts +114 -4
  67. package/core/pay/recordProof.ts +2 -6
  68. package/core/services/arcadeBroadcastProvider.ts +1 -4
  69. package/core/services/capWalletArgs.ts +8 -9
  70. package/core/services/exchangeRate.ts +1 -1
  71. package/core/services/externalOrigin.ts +42 -0
  72. package/core/services/vault/VaultKeyService.ts +912 -251
  73. package/core/services/vault/ceremony.ts +435 -367
  74. package/core/services/vault/ceremonyHost.ts +27 -21
  75. package/core/services/vault/devMock.ts +30 -7
  76. package/core/services/vault/driver.ts +95 -41
  77. package/core/services/vault/guard.ts +514 -56
  78. package/core/services/vault/hardwareLease.ts +22 -0
  79. package/core/services/vault/mockYubiKey.ts +258 -90
  80. package/core/services/vault/pivReset.ts +145 -0
  81. package/core/services/vault/r1comb.ts +976 -0
  82. package/core/services/vault/session.ts +93 -26
  83. package/core/services/vault/transfers.ts +2617 -747
  84. package/core/services/vault/types.ts +100 -43
  85. package/core/services/vault/vaultStore.ts +991 -74
  86. package/core/services/walletConnectionValidation.ts +293 -0
  87. package/core/services/walletServiceConfig.ts +31 -20
  88. package/core/storage/StorageExpoSQLite.ts +420 -87
  89. package/core/storage/dbImage.ts +48 -0
  90. package/core/storage/methods/findSql.ts +3 -54
  91. package/core/storage/methods/listActionsSql.ts +8 -5
  92. package/core/storage/methods/listOutputsSql.ts +9 -5
  93. package/core/storage/methods/offlineActions.ts +15 -0
  94. package/core/storage/methods/processOfflineActions.ts +265 -9
  95. package/core/storage/methods/reviewStatusSql.ts +7 -2
  96. package/core/storage/methods/walletBalanceSql.ts +16 -4
  97. package/core/storage/schema/createTables.ts +152 -0
  98. package/core/storage/sqlUpdateValue.ts +24 -0
  99. package/core/toolboxConfig.ts +182 -1
  100. package/core/toolboxTypes.ts +40 -0
  101. package/core/userAvatar.ts +79 -0
  102. package/core/walletMonitor.ts +8 -3
  103. package/core/walletRepair/runWalletCheck.ts +19 -2
  104. package/package.json +31 -30
  105. package/ui/activityFilter.ts +115 -0
  106. package/ui/components/QRScanner.tsx +1 -1
  107. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  108. package/ui/components/pay/AssetPicker.tsx +184 -0
  109. package/ui/components/pay/AvailableBalance.tsx +33 -2
  110. package/ui/components/pay/HandleReceive.tsx +213 -50
  111. package/ui/components/pay/NearbyFlow.tsx +616 -69
  112. package/ui/components/pay/PayForm.tsx +73 -8
  113. package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
  114. package/ui/components/pay/RecipientField.tsx +132 -73
  115. package/ui/components/pay/RequestHub.tsx +68 -8
  116. package/ui/components/pay/ResultBanner.tsx +41 -4
  117. package/ui/components/pay/StepBar.tsx +32 -0
  118. package/ui/components/pay/UniversalSend.tsx +1118 -86
  119. package/ui/components/pay/tokenSendCopy.ts +116 -0
  120. package/ui/components/pay/useRecipientInput.ts +36 -7
  121. package/ui/components/ui/PencilEditField.tsx +109 -0
  122. package/ui/components/ui/PermissionSheet.tsx +65 -4
  123. package/ui/components/ui/Sheet.tsx +9 -2
  124. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  125. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  126. package/ui/components/vault/KeyChooser.tsx +96 -0
  127. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  128. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  129. package/ui/components/wallet/ActivityRow.tsx +283 -97
  130. package/ui/components/wallet/AmountInput.tsx +92 -28
  131. package/ui/components/wallet/AssetAmount.tsx +95 -0
  132. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  133. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  134. package/ui/components/wallet/ContactSigil.tsx +49 -0
  135. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  136. package/ui/components/wallet/FitAmount.tsx +148 -0
  137. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  138. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  139. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  140. package/ui/components/wallet/ProfileButton.tsx +62 -0
  141. package/ui/components/wallet/UserAvatar.tsx +85 -0
  142. package/ui/components/wallet/avatarIcons.ts +122 -0
  143. package/ui/components/wallet/tokenEviction.ts +65 -0
  144. package/ui/hooks/useContactsStore.ts +10 -0
  145. package/ui/hooks/useExportWalletData.ts +39 -0
  146. package/ui/hooks/useMandala.ts +320 -0
  147. package/ui/hooks/useOnline.ts +65 -20
  148. package/ui/hooks/useVaultBalance.ts +105 -7
  149. package/ui/hooks/useVaultCoverage.ts +52 -0
  150. package/ui/importDatabases.ts +7 -3
  151. package/ui/index.ts +75 -7
  152. package/ui/screens/ConnectionsScreen.tsx +46 -29
  153. package/ui/screens/ContactScreen.tsx +289 -0
  154. package/ui/screens/ContactsScreen.tsx +373 -0
  155. package/ui/screens/IdentifierScreen.tsx +234 -0
  156. package/ui/screens/NewContactScreen.tsx +362 -0
  157. package/ui/screens/PairScreen.tsx +12 -12
  158. package/ui/screens/PayScreen.tsx +145 -12
  159. package/ui/screens/ProfileScreen.tsx +783 -0
  160. package/ui/screens/SettingsScreen.tsx +18 -9
  161. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  162. package/ui/screens/TrustScreen.tsx +1 -1
  163. package/ui/screens/VaultScreen.tsx +925 -171
  164. package/ui/screens/VaultTransferScreen.tsx +376 -123
  165. package/ui/screens/WalletCheckScreen.tsx +10 -1
  166. package/ui/screens/WalletConfigScreen.tsx +80 -16
  167. package/ui/screens/WalletHomeScreen.tsx +915 -139
  168. package/ui/screens/homeBadges.ts +9 -1
  169. package/ui/screens/tokenRowTitle.ts +68 -0
  170. package/ui/tokenFormat.ts +108 -0
  171. package/ui/tokenSeen.ts +75 -0
  172. package/ui/tokenStatus.ts +100 -0
  173. package/ui/txStatus.ts +43 -5
  174. package/assets/sounds/vault-close.wav +0 -0
  175. package/assets/sounds/vault-open.wav +0 -0
  176. package/core/services/vault/k1.ts +0 -75
  177. package/core/services/vault/sealing.ts +0 -84
  178. package/core/services/vault/vaultDerivation.ts +0 -152
  179. package/core/services/vault/vaultPassphrase.ts +0 -287
  180. package/ui/components/vault/PassphraseField.tsx +0 -306
  181. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  182. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -31,6 +31,8 @@ import {
31
31
  recoverMnemonicWallet,
32
32
  TaskBackupPush,
33
33
  setMockDriverEnabled,
34
+ setMockPresentKey,
35
+ getMockPresentKey,
34
36
  NO_MESSAGE_BOX,
35
37
  getBackupUrl
36
38
  } from '@bsv/expo-wallet-toolbox'
@@ -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,27 @@ function loadExpoRouter(): ExpoRouterModule {
105
107
  return expoRouterMod
106
108
  }
107
109
 
110
+ /**
111
+ * Demo mode, or null in anything but a dev bundle.
112
+ *
113
+ * Required at module scope behind `__DEV__` so a release build inlines the
114
+ * flag as false and folds the require — and the whole demo folder — out.
115
+ * Same pattern as `utils/AgentationGate.tsx`.
116
+ */
117
+ type DemoModule = typeof import('../../core/demo')
118
+ const demoMod: DemoModule | null = __DEV__
119
+ ? // eslint-disable-next-line @typescript-eslint/no-require-imports
120
+ (require('../../core/demo') as DemoModule)
121
+ : null
122
+
123
+ /** The three serials the DEV mock can present, cycled by the selector row below. */
124
+ type MockPresentKey = Parameters<typeof setMockPresentKey>[0]
125
+ const NEXT_MOCK_KEY: Record<MockPresentKey, MockPresentKey> = {
126
+ 'MOCK-DEV-1': 'MOCK-DEV-2',
127
+ 'MOCK-DEV-2': 'MOCK-DEV-3',
128
+ 'MOCK-DEV-3': 'MOCK-DEV-1'
129
+ }
130
+
108
131
  export function WalletConfigScreen() {
109
132
  const versionLabel = useMemo(() => appVersionLabel(), [])
110
133
  const { t } = useTranslation()
@@ -113,6 +136,7 @@ export function WalletConfigScreen() {
113
136
  const { section } = useLocalSearchParams<{ section?: string }>()
114
137
  const openBackup = section === 'backup'
115
138
  const Ionicons = loadIonicons()
139
+
116
140
  const {
117
141
  managers,
118
142
  adminOriginator,
@@ -129,7 +153,11 @@ export function WalletConfigScreen() {
129
153
 
130
154
  const [switchingNetwork, setSwitchingNetwork] = useState(false)
131
155
  const [networkExpanded, setNetworkExpanded] = useState(false)
132
- const [isExporting, setIsExporting] = useState(false)
156
+ const { exportData, exporting } = useExportWalletData()
157
+ // Not read from getMockPresentKey() at mount: the mock is off by default and
158
+ // the row is hidden until the toggle turns it on, at which point it syncs.
159
+ const [mockPresent, setMockPresent] = useState<MockPresentKey>('MOCK-DEV-1')
160
+ const [demoOn, setDemoOn] = useState(() => demoMod?.isDemoModeEnabled() ?? false)
133
161
  const [isImporting, setIsImporting] = useState(false)
134
162
  const [vaultMockOn, setVaultMockOn] = useState(false)
135
163
  const [backupPushOn, setBackupPushOn] = useState(true)
@@ -370,18 +398,6 @@ export function WalletConfigScreen() {
370
398
  })
371
399
  }, [])
372
400
 
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
401
  const handleImportData = async () => {
386
402
  if (isImporting) return
387
403
  setIsImporting(true)
@@ -784,6 +800,33 @@ export function WalletConfigScreen() {
784
800
  {/* ── Data & Security ── */}
785
801
  <View onLayout={event => setBackupSectionY(event.nativeEvent.layout.y)}>
786
802
  <GroupedSection header={t('data_and_security')}>
803
+ {/* Demo mode: a wallet full of obviously-fake BSV and stablecoins,
804
+ for showing the app without an account or a balance. Literal
805
+ copy rather than i18n — this row renders only under `__DEV__`
806
+ and never reaches a release build, so it is not user copy. */}
807
+ {__DEV__ && demoMod && (
808
+ <ListRow
809
+ label="Demo mode (dev)"
810
+ icon="flask-outline"
811
+ iconColor="#8E8E93"
812
+ showChevron={false}
813
+ value={demoOn ? 'On' : 'Off'}
814
+ onPress={() => {
815
+ const next = !demoOn
816
+ setDemoOn(next)
817
+ demoMod.setDemoModeEnabled(next)
818
+ }}
819
+ />
820
+ )}
821
+ {__DEV__ && demoMod && demoOn && (
822
+ <ListRow
823
+ label="Reset demo data (dev)"
824
+ icon="refresh-outline"
825
+ iconColor="#8E8E93"
826
+ showChevron={false}
827
+ onPress={() => demoMod.resetDemoLedger()}
828
+ />
829
+ )}
787
830
  {/* Vault's primary entry lives on the wallet menu (below Payments).
788
831
  The DEV mock toggle stays here. */}
789
832
  {__DEV__ && (
@@ -797,6 +840,27 @@ export function WalletConfigScreen() {
797
840
  const next = !vaultMockOn
798
841
  setVaultMockOn(next)
799
842
  setMockDriverEnabled(next)
843
+ if (next) setMockPresent(getMockPresentKey())
844
+ }}
845
+ />
846
+ )}
847
+ {/* Which of the three mock YubiKeys is "on the phone" right now.
848
+ A 1-of-N vault enrolled with MOCK-DEV-1 and MOCK-DEV-2 is
849
+ exercised by switching the present key between taps. The label
850
+ is a literal rather than user copy because this row renders
851
+ only under the `__DEV__` gate just below — it never reaches a
852
+ release build. */}
853
+ {__DEV__ && vaultMockOn && (
854
+ <ListRow
855
+ label="Mock key present (dev)"
856
+ icon="key-outline"
857
+ iconColor="#8E8E93"
858
+ showChevron={false}
859
+ value={mockPresent}
860
+ onPress={() => {
861
+ const next = NEXT_MOCK_KEY[mockPresent]
862
+ setMockPresent(next)
863
+ setMockPresentKey(next)
800
864
  }}
801
865
  />
802
866
  )}
@@ -818,9 +882,9 @@ export function WalletConfigScreen() {
818
882
  label={t('export_wallet_data')}
819
883
  icon="share-outline"
820
884
  iconColor="#32ADE6"
821
- onPress={handleExportData}
885
+ onPress={() => void exportData()}
822
886
  showChevron={false}
823
- trailing={isExporting ? <ActivityIndicator size="small" /> : undefined}
887
+ trailing={exporting ? <ActivityIndicator size="small" /> : undefined}
824
888
  />
825
889
  <ListRow
826
890
  label={t('import_wallet_data')}