@bsv/expo-wallet-toolbox 0.19.0 → 0.20.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 (135) hide show
  1. package/CHANGELOG.md +121 -30
  2. package/README.md +79 -79
  3. package/core/backup/RemoteSyncReader.ts +26 -24
  4. package/core/backup/appData.ts +9 -8
  5. package/core/backup/codec.ts +21 -18
  6. package/core/backup/constants.ts +5 -5
  7. package/core/backup/contactsBackup.ts +8 -8
  8. package/core/backup/cursor.ts +12 -7
  9. package/core/backup/derive.ts +3 -3
  10. package/core/backup/deviceId.ts +2 -2
  11. package/core/backup/erase.ts +2 -2
  12. package/core/backup/preference.ts +2 -2
  13. package/core/backup/push.ts +10 -12
  14. package/core/backup/restore.ts +22 -14
  15. package/core/backup/restoreOnImport.ts +3 -2
  16. package/core/config.tsx +17 -13
  17. package/core/constants.ts +34 -11
  18. package/core/contacts/contactsStore.ts +4 -3
  19. package/core/context/WalletConnectionContext.tsx +294 -212
  20. package/core/context/WalletContext.tsx +132 -97
  21. package/core/context/defaultWalletSettings.ts +4 -2
  22. package/core/demo/demoLedger.ts +1 -5
  23. package/core/directpay/DirectPayProvider.tsx +15 -24
  24. package/core/directpay/receive.ts +2 -1
  25. package/core/headers/checkpoints.ts +10 -1
  26. package/core/headers/headerStore.ts +13 -2
  27. package/core/hooks/useConfirmationSound.ts +3 -3
  28. package/core/hooks/useHaptics.ts +23 -6
  29. package/core/i18n/translations.tsx +269 -125
  30. package/core/index.ts +2 -0
  31. package/core/localpay/codec.ts +12 -6
  32. package/core/localpay/deviceCaps.ts +4 -14
  33. package/core/localpay/pending.ts +2 -1
  34. package/core/localpay/qr.ts +1 -1
  35. package/core/localpay/settlementAck.ts +1 -4
  36. package/core/localpay/transport/ble.ts +2 -2
  37. package/core/localpay/transport/socket.ts +1 -1
  38. package/core/mandala/abortGuard.ts +1 -1
  39. package/core/mandala/drain.ts +3 -0
  40. package/core/mandala/permissionModule.ts +3 -2
  41. package/core/mandala/resendTransfer.ts +4 -1
  42. package/core/mandala/runtime.ts +4 -4
  43. package/core/monitor/TaskBackupPush.ts +10 -13
  44. package/core/net/chainMatch.ts +8 -5
  45. package/core/networks.ts +145 -0
  46. package/core/parsePeerPayURI.ts +4 -1
  47. package/core/pay/beefRepair.ts +6 -3
  48. package/core/pay/creditErrors.ts +37 -1
  49. package/core/pay/rails/address.ts +10 -6
  50. package/core/pay/rails/handle.ts +84 -11
  51. package/core/pay/rails/index.ts +18 -2
  52. package/core/pay/receiveHistory.ts +8 -8
  53. package/core/peerpay/handleResendRequests.ts +11 -18
  54. package/core/peerpay/inboxAttempts.ts +1 -4
  55. package/core/peerpay/rebuildToken.ts +12 -9
  56. package/core/profiles/profileStore.ts +2 -1
  57. package/core/profiles/removalProblems.ts +3 -1
  58. package/core/services/arcTokenStorage.ts +2 -1
  59. package/core/services/arcadeBroadcastProvider.ts +7 -17
  60. package/core/services/secrets/envelope.ts +1 -6
  61. package/core/services/secrets/hkdf.ts +1 -6
  62. package/core/services/secrets/index.ts +3 -22
  63. package/core/services/usdFxRates.ts +1 -4
  64. package/core/services/vault/VaultKeyService.ts +2 -1
  65. package/core/services/vault/chainRecovery.ts +48 -21
  66. package/core/services/vault/metaAuthority.ts +4 -1
  67. package/core/services/vault/r1comb.ts +113 -51
  68. package/core/services/vault/session.ts +5 -1
  69. package/core/services/vault/transfers.ts +699 -576
  70. package/core/services/vault/vaultStore.ts +12 -10
  71. package/core/services/walletArgLimits.ts +1 -2
  72. package/core/services/walletConnectionValidation.ts +44 -28
  73. package/core/services/walletServiceConfig.ts +9 -40
  74. package/core/storage/StorageExpoSQLite.ts +7 -21
  75. package/core/storage/methods/listActionsSql.ts +81 -67
  76. package/core/storage/methods/listOutputsSql.ts +21 -16
  77. package/core/storage/methods/reviewStatusSql.ts +1 -4
  78. package/core/stores/ConnectionStore.ts +1 -1
  79. package/core/theme/ThemeContext.tsx +12 -16
  80. package/core/theme/motion.ts +3 -3
  81. package/core/theme/tokens.ts +6 -6
  82. package/core/toolboxConfig.ts +23 -0
  83. package/core/walletDbRegistry.ts +7 -5
  84. package/core/walletRepair/runWalletCheck.ts +1 -4
  85. package/package.json +2 -2
  86. package/ui/components/pay/AddressReceive.tsx +3 -3
  87. package/ui/components/pay/HandleReceive.tsx +15 -15
  88. package/ui/components/pay/MessageBoxConfig.tsx +46 -20
  89. package/ui/components/pay/NearbyFlow.tsx +575 -507
  90. package/ui/components/pay/OfflineNotice.tsx +1 -3
  91. package/ui/components/pay/PayCellRow.tsx +1 -4
  92. package/ui/components/pay/PayForm.tsx +1 -3
  93. package/ui/components/pay/RequestHub.tsx +14 -6
  94. package/ui/components/pay/UniversalSend.tsx +79 -27
  95. package/ui/components/pay/tokenSendCopy.ts +1 -2
  96. package/ui/components/pay/useRecipientInput.ts +2 -2
  97. package/ui/components/security/WalletLockNotice.tsx +1 -3
  98. package/ui/components/ui/AlertCard.tsx +44 -45
  99. package/ui/components/ui/BlurChrome.tsx +4 -15
  100. package/ui/components/ui/Celebration.tsx +3 -3
  101. package/ui/components/ui/ChoiceSheet.ts +1 -3
  102. package/ui/components/ui/ErrorBoundary.tsx +2 -6
  103. package/ui/components/ui/GroupedList.tsx +13 -31
  104. package/ui/components/ui/IconButton.tsx +6 -9
  105. package/ui/components/ui/ListRow.tsx +19 -25
  106. package/ui/components/ui/PresenceRow.tsx +4 -4
  107. package/ui/components/ui/PressableScale.tsx +24 -20
  108. package/ui/components/ui/Toast.tsx +23 -16
  109. package/ui/components/vault/KeyChooser.tsx +9 -6
  110. package/ui/components/vault/VaultBackdrop.tsx +1 -8
  111. package/ui/components/vault/VaultCeremonySheet.tsx +5 -5
  112. package/ui/components/wallet/ActivityRow.tsx +3 -2
  113. package/ui/components/wallet/BackupReminderSheet.tsx +1 -5
  114. package/ui/components/wallet/Balance.tsx +4 -1
  115. package/ui/components/wallet/ContactActivityList.tsx +7 -7
  116. package/ui/components/wallet/IconPickerSheet.tsx +1 -5
  117. package/ui/components/wallet/ProfileSwitcherPopover.tsx +6 -1
  118. package/ui/components/wallet/tokenEviction.ts +4 -1
  119. package/ui/hooks/useMandala.ts +1 -7
  120. package/ui/hooks/useOfflineNoticeActions.ts +21 -27
  121. package/ui/hooks/useSpendableBalance.ts +2 -2
  122. package/ui/hooks/useVaultCoverage.ts +7 -1
  123. package/ui/index.ts +9 -1
  124. package/ui/resolveIdentity.ts +20 -8
  125. package/ui/screens/ConnectionsScreen.tsx +44 -18
  126. package/ui/screens/LogsScreen.tsx +24 -22
  127. package/ui/screens/PairScreen.tsx +85 -54
  128. package/ui/screens/PayScreen.tsx +5 -1
  129. package/ui/screens/ProfileScreen.tsx +0 -3
  130. package/ui/screens/TrustScreen.tsx +125 -80
  131. package/ui/screens/VaultScreen.tsx +19 -7
  132. package/ui/screens/VaultTransferScreen.tsx +5 -1
  133. package/ui/screens/WalletCheckScreen.tsx +14 -17
  134. package/ui/screens/WalletConfigScreen.tsx +414 -376
  135. package/ui/screens/WalletHomeScreen.tsx +47 -42
@@ -69,7 +69,7 @@ export interface RestoreResult {
69
69
  }
70
70
 
71
71
  /** What the user can choose between when more than one device has a backup. */
72
- export async function listBackups (deps: {
72
+ export async function listBackups(deps: {
73
73
  primaryKey: number[]
74
74
  chain: BackupChain
75
75
  baseUrl?: string
@@ -89,11 +89,11 @@ export async function listBackups (deps: {
89
89
  * result says which way this restore was chosen; the chunk-count check below still runs
90
90
  * either way as the last line of defence.
91
91
  */
92
- export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResult> {
92
+ export async function restoreFromBackup(deps: RestoreDeps): Promise<RestoreResult> {
93
93
  const client = resolveClient(deps)
94
94
  const wallet = deriveBackupWallet(deps.primaryKey, deps.chain)
95
95
 
96
- const devices = deps.manifest ?? await client.manifest()
96
+ const devices = deps.manifest ?? (await client.manifest())
97
97
  if (devices.length === 0) {
98
98
  throw new Error('No backup found for this wallet')
99
99
  }
@@ -140,14 +140,17 @@ export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResu
140
140
  offsets: []
141
141
  })
142
142
 
143
- const result = await deps.storage.processSyncChunk({
144
- identityKey: deps.identityKey,
145
- fromStorageIdentityKey: chosen.deviceId,
146
- toStorageIdentityKey: settings.storageIdentityKey,
147
- maxRoughSize: 0,
148
- maxItems: 0,
149
- offsets: []
150
- }, chunk)
143
+ const result = await deps.storage.processSyncChunk(
144
+ {
145
+ identityKey: deps.identityKey,
146
+ fromStorageIdentityKey: chosen.deviceId,
147
+ toStorageIdentityKey: settings.storageIdentityKey,
148
+ maxRoughSize: 0,
149
+ maxItems: 0,
150
+ offsets: []
151
+ },
152
+ chunk
153
+ )
151
154
 
152
155
  if (result.done) {
153
156
  if (chunks < reader.length) throw new Error('Backup replay completed before all indexed chunks were applied')
@@ -179,7 +182,7 @@ export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResu
179
182
  * which also reconciles notification IDs and preserves completed transactions.
180
183
  * Run only after the entire log lands, before the wallet/monitor is published.
181
184
  */
182
- async function reconcileRestoredProofs (storage: StorageExpoSQLite, onActivity?: () => void): Promise<void> {
185
+ async function reconcileRestoredProofs(storage: StorageExpoSQLite, onActivity?: () => void): Promise<void> {
183
186
  const limit = 1
184
187
  for (let offset = 0; ; offset += limit) {
185
188
  if (offset > 0) onActivity?.()
@@ -240,7 +243,7 @@ export interface PickedTarget {
240
243
  * newest generation" heuristic, with `verified: false` so the caller can warn rather than
241
244
  * silently claim a verified restore.
242
245
  */
243
- export async function pickTarget (
246
+ export async function pickTarget(
244
247
  devices: DeviceSummary[],
245
248
  client: BackupClient,
246
249
  wallet: CompletedProtoWallet,
@@ -303,7 +306,12 @@ export async function pickTarget (
303
306
  }
304
307
  }
305
308
 
306
- function resolveClient (deps: { primaryKey: number[], chain: BackupChain, baseUrl?: string, client?: BackupClient }): BackupClient {
309
+ function resolveClient(deps: {
310
+ primaryKey: number[]
311
+ chain: BackupChain
312
+ baseUrl?: string
313
+ client?: BackupClient
314
+ }): BackupClient {
307
315
  if (deps.client != null) return deps.client
308
316
  if (deps.baseUrl == null || deps.baseUrl === '') {
309
317
  throw new Error('restore requires either a client or a baseUrl')
@@ -95,8 +95,9 @@ export interface RestoreOnImportResult {
95
95
  verified?: boolean
96
96
  }
97
97
 
98
- export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<RestoreOnImportResult> {
99
- const client = deps.client ?? (hasUrl(deps.baseUrl) ? new BackupClient(deps.baseUrl!, deps.primaryKey, deps.chain) : null)
98
+ export async function restoreOnImport(deps: RestoreOnImportDeps): Promise<RestoreOnImportResult> {
99
+ const client =
100
+ deps.client ?? (hasUrl(deps.baseUrl) ? new BackupClient(deps.baseUrl!, deps.primaryKey, deps.chain) : null)
100
101
  if (client == null) {
101
102
  return { restored: false, chunks: 0, reason: 'not-configured' }
102
103
  }
package/core/config.tsx CHANGED
@@ -1,25 +1,29 @@
1
- export type AppChain = 'main' | 'test' | 'teratest'
1
+ import type { Chain as ToolboxChain } from '@bsv/wallet-toolbox-mobile'
2
+ import { NETWORKS, type AppChain } from './networks'
2
3
 
3
- /**
4
- * The wallet-toolbox `Chain` type used by @bsv/wallet-toolbox-mobile.
5
- * Mirrors `Chain = 'main' | 'test' | 'ttn' | 'mock'` from the toolbox sdk.
6
- */
7
- export type WalletChain = 'main' | 'test' | 'ttn'
4
+ export type { AppChain, WalletChain } from './networks'
8
5
 
9
6
  /**
10
7
  * Map our app-level chain id to the wallet-toolbox `Chain` value.
11
- * The app persists/displays `'teratest'`, but the toolbox (and its default
12
- * wallet-client service paths — e.g. WhatsOnChain `api.woc-ttn.bsvblockchain.tech`)
13
- * identify TeraTestNet as `'ttn'`. Keep `'teratest'` for AsyncStorage keys,
14
- * env var names (`EXPO_PUBLIC_TERATEST_*`) and UI; convert only at toolbox boundaries.
8
+ * The app persists/displays `'teratest'` and `'scaletest'`, but the toolbox
9
+ * identifies them as `'ttn'` and `'regtest'`. Keep the app names for
10
+ * AsyncStorage keys, env var names (`EXPO_PUBLIC_TERATEST_*`) and UI; convert
11
+ * only at toolbox boundaries.
12
+ *
13
+ * The one cast in the chain mapping: `'regtest'` joins the toolbox's `Chain`
14
+ * in @bsv/wallet-toolbox 2.15.0 (bsv-blockchain/ts-stack#819). Only scaletest
15
+ * maps to it, and scaletest is not available (NETWORKS.scaletest.available),
16
+ * so the installed 2.14.x never receives it. Drop the cast when the
17
+ * dependency is bumped.
15
18
  */
16
- export function toWalletChain(chain: AppChain): WalletChain {
17
- return chain === 'teratest' ? 'ttn' : chain
19
+ export function toWalletChain(chain: AppChain): ToolboxChain {
20
+ return NETWORKS[chain].walletChain as ToolboxChain
18
21
  }
19
22
 
20
23
  export const DEFAULT_WAB_URL = 'noWAB'
21
24
  export const DEFAULT_STORAGE_URL = 'local'
22
- export const DEFAULT_MESSAGEBOX_URL = 'https://messagebox.bsvblockchain.tech'
25
+ /** Mainnet's MessageBox server. Each network has its own: see `NETWORKS`. */
26
+ export const DEFAULT_MESSAGEBOX_URL = NETWORKS.main.messageBoxUrl
23
27
  /**
24
28
  * Encrypted wallet-backup log.
25
29
  *
package/core/constants.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { NETWORKS, type AppChain } from './networks'
2
+
1
3
  /** Auto-approve transactions below this satoshi amount without showing the spend modal */
2
4
  export const DEFAULT_AUTO_APPROVE_THRESHOLD = 100_000
3
5
  /** Minimum milliseconds between two auto-approved transactions from the SAME originator */
@@ -33,16 +35,37 @@ export const arcUrlStorageKey = (network: string) => `arc_custom_url_${network}`
33
35
  export const arcApiTokenStorageKey = (network: string) => `arc_custom_api_token_${network}`
34
36
 
35
37
  /** Default ARC URLs per network */
36
- export const DEFAULT_ARC_URLS: Record<string, string> = {
37
- main: 'https://arcade-v2-us-1.bsvblockchain.tech',
38
- test: 'https://arcade-v2-testnet-us-1.bsvblockchain.tech',
39
- teratest: 'https://arcade-v2-ttn-us-1.bsvblockchain.tech'
38
+ export const DEFAULT_ARC_URLS: Record<AppChain, string> = {
39
+ main: NETWORKS.main.arcadeUrl,
40
+ test: NETWORKS.test.arcadeUrl,
41
+ teratest: NETWORKS.teratest.arcadeUrl,
42
+ scaletest: NETWORKS.scaletest.arcadeUrl
43
+ }
44
+
45
+ export interface KnownArcUrl {
46
+ label: string
47
+ url: string
48
+ requiresToken: boolean
40
49
  }
41
50
 
42
- /** Known ARC endpoint presets (mainnet-focused, user edits for other regions) */
43
- export const KNOWN_ARC_URLS = [
44
- { label: 'Arcade v2 (default)', url: 'https://arcade-v2-us-1.bsvblockchain.tech', requiresToken: false },
45
- { label: 'Arcade', url: 'https://arcade-us-1.bsvb.tech', requiresToken: false },
46
- { label: 'TAAL', url: 'https://arc.taal.com', requiresToken: true },
47
- { label: 'GorillaPool', url: 'https://arc.gorillapool.io', requiresToken: false }
48
- ]
51
+ /**
52
+ * Known ARC endpoint presets, per network. Each list names only endpoints that
53
+ * serve that network: picking a mainnet ARC on a test chain posts its
54
+ * transactions to a network that will reject them (or, worse, accept a replay).
55
+ * The scaling and tera test networks have one Arcade each, so they offer no
56
+ * presets beyond their default.
57
+ */
58
+ export const KNOWN_ARC_URLS: Record<AppChain, readonly KnownArcUrl[]> = {
59
+ main: [
60
+ { label: 'Arcade v2 (default)', url: NETWORKS.main.arcadeUrl, requiresToken: false },
61
+ { label: 'Arcade', url: 'https://arcade-us-1.bsvb.tech', requiresToken: false },
62
+ { label: 'TAAL', url: 'https://arc.taal.com', requiresToken: true },
63
+ { label: 'GorillaPool', url: 'https://arc.gorillapool.io', requiresToken: false }
64
+ ],
65
+ test: [
66
+ { label: 'Arcade v2 (default)', url: NETWORKS.test.arcadeUrl, requiresToken: false },
67
+ { label: 'TAAL', url: 'https://arc-test.taal.com', requiresToken: true }
68
+ ],
69
+ teratest: [{ label: 'Arcade v2 (default)', url: NETWORKS.teratest.arcadeUrl, requiresToken: false }],
70
+ scaletest: [{ label: 'Arcade (default)', url: NETWORKS.scaletest.arcadeUrl, requiresToken: false }]
71
+ }
@@ -118,9 +118,10 @@ export interface ContactsStore {
118
118
  export function createContactsStore(db: ContactsDb): ContactsStore {
119
119
  return {
120
120
  async listContacts(userId) {
121
- const rows = (await db.getAllAsync('SELECT * FROM contacts WHERE userId = ? AND removedAt IS NULL ORDER BY name COLLATE NOCASE ASC', [
122
- userId
123
- ])) as ContactDbRow[]
121
+ const rows = (await db.getAllAsync(
122
+ 'SELECT * FROM contacts WHERE userId = ? AND removedAt IS NULL ORDER BY name COLLATE NOCASE ASC',
123
+ [userId]
124
+ )) as ContactDbRow[]
124
125
  return rows.map(toContact)
125
126
  },
126
127