@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
@@ -1,226 +0,0 @@
1
- /**
2
- * Vault recovery — full screen, not a drawer.
3
- *
4
- * The escape hatch when the hardware key is lost or its PIV applet is bricked.
5
- * It sweeps the vault to the everyday balance WITHOUT the key, then clears the
6
- * vault.
7
- *
8
- * Requires the wallet's own recovery phrase (already on this device) plus the
9
- * vault passphrase chosen at enrollment. BIP39 passphrases have no checksum,
10
- * so a typo silently derives a different, valid, empty vault node rather than
11
- * throwing. v4 vault meta stores no key material to catch that here anymore —
12
- * the sweep itself catches it instead: every vault output mismatches a wrong
13
- * key (transfers.ts's prepareSpends), and the resulting
14
- * VaultError('wrong-key') is mapped below to the passphrase copy the user
15
- * actually needs to see.
16
- */
17
- import React, { useCallback, useState } from 'react'
18
- import { View, Text, StyleSheet, TextInput, ScrollView, ActivityIndicator, TouchableOpacity } from 'react-native'
19
- import { useSafeAreaInsets } from 'react-native-safe-area-context'
20
- import PressableScale from '../components/ui/PressableScale'
21
- import { showToast } from '../components/ui/Toast'
22
- import {
23
- useTheme,
24
- spacing,
25
- radii,
26
- typography,
27
- haptics,
28
- useWallet,
29
- useLocalStorage,
30
- disableVault,
31
- recoverVaultHD,
32
- sweepVaultWithHD,
33
- type VaultWallet,
34
- VaultError,
35
- i18n
36
- } from '@bsv/expo-wallet-toolbox'
37
-
38
- const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
39
-
40
- /**
41
- * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
42
- * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
43
- * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
44
- * Ionicons is loaded lazily, only when actually rendering, same pattern as
45
- * this package's other native-module-boundary fixes (expo-router, expo-blur).
46
- */
47
- type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
48
- let ioniconsComponent: IoniconsComponent | undefined
49
- function loadIonicons(): IoniconsComponent {
50
- if (!ioniconsComponent) {
51
- // eslint-disable-next-line @typescript-eslint/no-require-imports
52
- ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
53
- }
54
- return ioniconsComponent
55
- }
56
-
57
- /**
58
- * expo-router is required lazily rather than imported at module scope: this
59
- * file is barrel-exported from the package's `ui` entry point, and a static
60
- * top-level `import` of expo-router pulls in its own untransformed JSX
61
- * source (Navigator.js etc.), which Jest cannot parse for any consumer of the
62
- * barrel, even one that never navigates. Same pattern as
63
- * core/context/WalletContext.tsx's and WalletHomeScreen.tsx's lazy
64
- * expo-router load.
65
- */
66
- type ExpoRouterModule = typeof import('expo-router')
67
- let expoRouterMod: ExpoRouterModule | undefined
68
- function loadExpoRouter(): ExpoRouterModule {
69
- if (!expoRouterMod) {
70
- // eslint-disable-next-line @typescript-eslint/no-require-imports
71
- expoRouterMod = require('expo-router') as ExpoRouterModule
72
- }
73
- return expoRouterMod
74
- }
75
-
76
- export function VaultRecoverScreen() {
77
- const { colors } = useTheme()
78
- const insets = useSafeAreaInsets()
79
- const { router } = loadExpoRouter()
80
- const Ionicons = loadIonicons()
81
- const { managers, adminOriginator } = useWallet()
82
- const { getMnemonic } = useLocalStorage()
83
-
84
- const [passphrase, setPassphrase] = useState('')
85
- const [busy, setBusy] = useState(false)
86
- const [error, setError] = useState<string | null>(null)
87
-
88
- const run = useCallback(async () => {
89
- const pm = managers?.permissionsManager
90
- if (!pm) return
91
- setBusy(true)
92
- setError(null)
93
- try {
94
- const mnemonic = await getMnemonic()
95
- if (!mnemonic) throw new VaultError('bad-mnemonic', t('vault_requires_mnemonic'))
96
- const hd = await recoverVaultHD(mnemonic, passphrase)
97
-
98
- // sweepVaultWithHD caps at VAULT_MAX_INPUTS per call (see transfers.ts) and
99
- // reports how many vault outputs it left behind. A vault holding more than
100
- // that cap needs several sweeps, so repeat until either call reports
101
- // nothing left to do: `null` means the vault was already empty when that
102
- // sweep ran, and `remainingInputs === 0` means the sweep that just ran
103
- // cleared the last of it. Each successful iteration strictly reduces the
104
- // number of vault outputs still held (it spends min(remaining,
105
- // VAULT_MAX_INPUTS) > 0 of them), so remainingInputs decreases every pass
106
- // and the loop is guaranteed to terminate at 0 or null. A thrown error
107
- // (e.g. 'wrong-key' from a mismatched passphrase) exits the loop and the
108
- // catch below runs instead — disableVault() is never reached, and the
109
- // vault is left exactly as it was before the failed iteration.
110
- let result = await sweepVaultWithHD(pm as unknown as VaultWallet, adminOriginator, hd, t('vault_recover_reason'))
111
- while (result !== null && result.remainingInputs > 0) {
112
- result = await sweepVaultWithHD(pm as unknown as VaultWallet, adminOriginator, hd, t('vault_recover_reason'))
113
- }
114
-
115
- await disableVault()
116
- haptics.success()
117
- showToast(t('vault_recovered_toast'), { type: 'success' })
118
- setPassphrase('')
119
- router.back()
120
- } catch (e) {
121
- const code = e instanceof VaultError ? e.code : undefined
122
- // The sweep's prepareSpends throws 'wrong-key' when every vault output
123
- // mismatches the derived key — on this screen that always means the
124
- // typed passphrase does not match the one this vault was enrolled
125
- // with (there is no YubiKey involved here to be the "wrong" one), so
126
- // show the passphrase-specific copy rather than the sweep's own
127
- // generic wrong-key message.
128
- const msg =
129
- code === 'wrong-key'
130
- ? t('vault_recover_wrong_passphrase')
131
- : e instanceof VaultError
132
- ? e.message || t(`vault_err_${e.code.replace(/-/g, '_')}`)
133
- : t('vault_recover_failed')
134
- setError(msg)
135
- haptics.error()
136
- } finally {
137
- setBusy(false)
138
- }
139
- }, [passphrase, managers?.permissionsManager, adminOriginator, getMnemonic])
140
-
141
- const canRun = passphrase.length > 0
142
-
143
- return (
144
- <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
145
- <View style={[styles.header, { borderBottomColor: colors.separator }]}>
146
- <TouchableOpacity onPress={() => router.back()} style={styles.iconBtn}>
147
- <Ionicons name="chevron-back" size={24} color={colors.textSecondary} />
148
- </TouchableOpacity>
149
- <Text style={[styles.headerTitle, { color: colors.textPrimary }]}>{t('vault_recover_title')}</Text>
150
- <View style={styles.iconBtn} />
151
- </View>
152
-
153
- <ScrollView contentContainerStyle={styles.body} keyboardShouldPersistTaps="handled">
154
- <Text style={[styles.sub, { color: colors.textSecondary }]}>{t('vault_recover_sub')}</Text>
155
-
156
- <Text style={[styles.label, { color: colors.textPrimary }]}>{t('vault_recover_passphrase_label')}</Text>
157
- <Text style={[styles.fine, { color: colors.textSecondary }]}>{t('vault_recover_passphrase_help')}</Text>
158
- <TextInput
159
- style={[styles.input, { color: colors.textPrimary, backgroundColor: colors.backgroundElevated }]}
160
- value={passphrase}
161
- onChangeText={setPassphrase}
162
- placeholder={t('vault_recover_passphrase_placeholder')}
163
- placeholderTextColor={colors.textTertiary}
164
- autoCapitalize="none"
165
- autoCorrect={false}
166
- spellCheck={false}
167
- secureTextEntry
168
- />
169
-
170
- {error && <Text style={[styles.err, { color: colors.error }]}>{error}</Text>}
171
-
172
- <PressableScale
173
- haptic="confirm"
174
- onPress={canRun && !busy ? run : undefined}
175
- style={[
176
- styles.primary,
177
- {
178
- backgroundColor: canRun ? colors.accent : colors.backgroundElevated,
179
- opacity: busy ? 0.6 : 1
180
- }
181
- ]}
182
- >
183
- {busy ? (
184
- <ActivityIndicator color={colors.textOnAccent} />
185
- ) : (
186
- <Text style={[styles.primaryLabel, { color: canRun ? colors.textOnAccent : colors.textTertiary }]}>
187
- {t('vault_recover_cta')}
188
- </Text>
189
- )}
190
- </PressableScale>
191
- </ScrollView>
192
- </View>
193
- )
194
- }
195
-
196
- const styles = StyleSheet.create({
197
- container: { flex: 1 },
198
- header: {
199
- flexDirection: 'row',
200
- alignItems: 'center',
201
- justifyContent: 'space-between',
202
- paddingHorizontal: spacing.sm,
203
- paddingVertical: spacing.md,
204
- borderBottomWidth: StyleSheet.hairlineWidth
205
- },
206
- iconBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
207
- headerTitle: { ...typography.headline },
208
- body: { padding: spacing.xl, gap: spacing.md },
209
- sub: { ...typography.subhead },
210
- label: { ...typography.footnote, fontWeight: '600', textTransform: 'uppercase' },
211
- fine: { ...typography.footnote },
212
- input: {
213
- borderRadius: radii.md,
214
- paddingHorizontal: spacing.lg,
215
- paddingVertical: spacing.md,
216
- ...typography.body
217
- },
218
- err: { ...typography.footnote },
219
- primary: {
220
- borderRadius: radii.md,
221
- paddingVertical: spacing.lg,
222
- alignItems: 'center',
223
- marginTop: spacing.sm
224
- },
225
- primaryLabel: { ...typography.headline }
226
- })