@bsv/expo-wallet-toolbox 0.10.0 → 0.11.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.
- package/CHANGELOG.md +111 -0
- package/core/backup/restoreOnImport.ts +10 -3
- package/core/context/WalletContext.tsx +18 -5
- package/core/i18n/translations.tsx +109 -36
- package/core/localpay/pendingAbortAuthority.ts +6 -8
- package/core/localpay/pendingAborts.ts +11 -30
- package/core/mandala/permissionModule.ts +10 -8
- package/core/services/vault/VaultKeyService.ts +58 -1
- package/core/services/vault/chainRecovery.ts +188 -37
- package/core/services/vault/guard.ts +75 -139
- package/core/services/vault/transfers.ts +64 -2
- package/core/services/vault/types.ts +3 -0
- package/core/storage/StorageExpoSQLite.ts +33 -11
- package/core/storage/methods/vaultGuardSql.ts +140 -0
- package/core/storage/sqlUpdateValue.ts +4 -1
- package/package.json +1 -1
- package/ui/components/vault/vaultErrorCopy.ts +1 -0
- package/ui/hooks/useExportWalletData.ts +7 -21
- package/ui/screens/VaultScreen.tsx +192 -7
|
@@ -83,6 +83,7 @@ const KEY: Record<VaultErrorCode, string> = {
|
|
|
83
83
|
'not-enough-keys': 'vault_err_not_enough_keys',
|
|
84
84
|
'key-already-enrolled': 'vault_err_key_already_enrolled',
|
|
85
85
|
'key-not-adopted': 'vault_err_key_not_adopted',
|
|
86
|
+
'key-opens-nothing': 'vault_err_key_opens_nothing',
|
|
86
87
|
'too-many-keys': 'vault_err_too_many_keys',
|
|
87
88
|
'too-many-active-keys': 'vault_err_too_many_active_keys',
|
|
88
89
|
'last-keys': 'vault_err_last_keys',
|
|
@@ -13,19 +13,15 @@
|
|
|
13
13
|
* XR-086: exportAllWalletDatabases() writes the raw, unencrypted SQLite image
|
|
14
14
|
* straight to the OS share sheet — identity keys, certificate fields,
|
|
15
15
|
* transaction/derivation metadata and contacts, with no passphrase or
|
|
16
|
-
* authenticated-encryption step.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* an explicit warning naming what the file contains and that it is not
|
|
22
|
-
* encrypted, with a real chance to back out, shared by both call sites since
|
|
23
|
-
* they both go through this one hook.
|
|
16
|
+
* authenticated-encryption step. Encrypting it needs a product decision on how
|
|
17
|
+
* the importing device gets the key back (importDatabases.ts has no decrypt
|
|
18
|
+
* step either). The confirmation alert that used to precede the share sheet
|
|
19
|
+
* was removed by product decision: the tap goes straight to the native save
|
|
20
|
+
* prompt.
|
|
24
21
|
*/
|
|
25
22
|
import { useCallback, useRef, useState } from 'react'
|
|
26
|
-
import {
|
|
23
|
+
import { useWallet } from '@bsv/expo-wallet-toolbox'
|
|
27
24
|
import { exportAllWalletDatabases } from '../exportDatabases'
|
|
28
|
-
import { showAlert } from '../components/ui/AlertCard'
|
|
29
25
|
|
|
30
26
|
export function useExportWalletData(): { exportData: () => Promise<void>; exporting: boolean } {
|
|
31
27
|
const { storage } = useWallet()
|
|
@@ -37,18 +33,8 @@ export function useExportWalletData(): { exportData: () => Promise<void>; export
|
|
|
37
33
|
const exportData = useCallback(async () => {
|
|
38
34
|
if (inFlightRef.current) return
|
|
39
35
|
inFlightRef.current = true
|
|
36
|
+
setExporting(true)
|
|
40
37
|
try {
|
|
41
|
-
const choice = await showAlert({
|
|
42
|
-
title: i18n.t('export_unencrypted_title'),
|
|
43
|
-
message: i18n.t('export_unencrypted_message'),
|
|
44
|
-
buttons: [
|
|
45
|
-
{ text: i18n.t('cancel'), style: 'cancel', key: 'cancel' },
|
|
46
|
-
{ text: i18n.t('export_wallet_data'), style: 'destructive', key: 'export' }
|
|
47
|
-
]
|
|
48
|
-
})
|
|
49
|
-
if (choice !== 'export') return
|
|
50
|
-
// The spinner means "exporting", not "waiting for you to answer".
|
|
51
|
-
setExporting(true)
|
|
52
38
|
await exportAllWalletDatabases(storage)
|
|
53
39
|
} catch (e) {
|
|
54
40
|
console.warn('[exportWalletData] Export failed:', e)
|
|
@@ -49,6 +49,8 @@ import {
|
|
|
49
49
|
requireAuthenticatedMeta,
|
|
50
50
|
computeVaultMetaAuthorityTag,
|
|
51
51
|
recoverVaultFromChain,
|
|
52
|
+
recoverVaultWithKey,
|
|
53
|
+
proveHeldVaultKey,
|
|
52
54
|
wocChainLookup,
|
|
53
55
|
resolveHeldVaultDeposit,
|
|
54
56
|
adoptVaultKey,
|
|
@@ -74,6 +76,7 @@ import {
|
|
|
74
76
|
getBackupUrl,
|
|
75
77
|
disableVault,
|
|
76
78
|
disableVaultWhenSafe,
|
|
79
|
+
forgetUnreachableVaultOutputs,
|
|
77
80
|
getOnline,
|
|
78
81
|
generateMnemonicWallet,
|
|
79
82
|
backupAttestation,
|
|
@@ -275,14 +278,17 @@ export function VaultScreen() {
|
|
|
275
278
|
wocChainLookup(selectedNetwork),
|
|
276
279
|
selectedNetwork
|
|
277
280
|
)
|
|
281
|
+
// An earlier setup's deposits authenticate but no key held now opens
|
|
282
|
+
// them; say so, or they read as "nothing found" and look lost.
|
|
283
|
+
const skipped = result.unreachable > 0 ? ` ${t('vault_restore_unreachable', { count: result.unreachable })}` : ''
|
|
278
284
|
if (result.found > 0) {
|
|
279
285
|
haptics.success()
|
|
280
|
-
setRestoreNotice(t('vault_restore_found', { count: result.found }))
|
|
286
|
+
setRestoreNotice(t('vault_restore_found', { count: result.found }) + skipped)
|
|
281
287
|
await reload()
|
|
282
288
|
} else if (result.pendingConfirmation > 0) {
|
|
283
|
-
setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }))
|
|
289
|
+
setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }) + skipped)
|
|
284
290
|
} else {
|
|
285
|
-
setRestoreNotice(t('vault_restore_none_found'))
|
|
291
|
+
setRestoreNotice((skipped ? '' : t('vault_restore_none_found')) + skipped.trim())
|
|
286
292
|
}
|
|
287
293
|
} catch (error) {
|
|
288
294
|
haptics.error()
|
|
@@ -292,6 +298,67 @@ export function VaultScreen() {
|
|
|
292
298
|
}
|
|
293
299
|
}, [pm, restoringFromChain, adminOriginator, selectedNetwork, reload])
|
|
294
300
|
|
|
301
|
+
// Restore with one tapped YubiKey: its signature picks (and proves) the
|
|
302
|
+
// setup whose deposits it can open, so nothing is guessed from setup dates.
|
|
303
|
+
const [keyRestoreOpen, setKeyRestoreOpen] = useState(false)
|
|
304
|
+
const [keyRestorePin, setKeyRestorePin] = useState('')
|
|
305
|
+
const [keyRestoreBusy, setKeyRestoreBusy] = useState(false)
|
|
306
|
+
const [keyRestorePhase, setKeyRestorePhase] = useState<'scanning' | AdoptPhase | null>(null)
|
|
307
|
+
const [keyRestoreError, setKeyRestoreError] = useState<string | null>(null)
|
|
308
|
+
|
|
309
|
+
const closeKeyRestore = useCallback(() => {
|
|
310
|
+
if (keyRestoreBusy) return
|
|
311
|
+
setKeyRestoreOpen(false)
|
|
312
|
+
setKeyRestorePin('')
|
|
313
|
+
setKeyRestorePhase(null)
|
|
314
|
+
setKeyRestoreError(null)
|
|
315
|
+
}, [keyRestoreBusy])
|
|
316
|
+
|
|
317
|
+
const runKeyRestore = useCallback(async () => {
|
|
318
|
+
if (!pm || keyRestoreBusy || !/^[0-9]{6,8}$/.test(keyRestorePin)) return
|
|
319
|
+
setKeyRestoreBusy(true)
|
|
320
|
+
setKeyRestoreError(null)
|
|
321
|
+
setKeyRestorePhase('scanning')
|
|
322
|
+
setRestoreNotice(null)
|
|
323
|
+
try {
|
|
324
|
+
const result = await recoverVaultWithKey(
|
|
325
|
+
pm as unknown as VaultWallet,
|
|
326
|
+
adminOriginator,
|
|
327
|
+
wocChainLookup(selectedNetwork),
|
|
328
|
+
selectedNetwork,
|
|
329
|
+
records =>
|
|
330
|
+
proveHeldVaultKey({
|
|
331
|
+
records,
|
|
332
|
+
getPin: async () => keyRestorePin,
|
|
333
|
+
onPhase: setKeyRestorePhase,
|
|
334
|
+
nfcMessage: t('vault_nfc_adopt_message')
|
|
335
|
+
})
|
|
336
|
+
)
|
|
337
|
+
if (result.found === 0 && result.pendingConfirmation === 0) {
|
|
338
|
+
haptics.error()
|
|
339
|
+
setKeyRestoreError(t('vault_restore_none_found'))
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
setKeyRestoreOpen(false)
|
|
343
|
+
setKeyRestorePin('')
|
|
344
|
+
if (result.found > 0) {
|
|
345
|
+
haptics.success()
|
|
346
|
+
showToast(t('vault_restore_found', { count: result.found }), { type: 'success' })
|
|
347
|
+
await reload()
|
|
348
|
+
} else {
|
|
349
|
+
setRestoreNotice(t('vault_restore_pending', { count: result.pendingConfirmation }))
|
|
350
|
+
}
|
|
351
|
+
} catch (error) {
|
|
352
|
+
haptics.error()
|
|
353
|
+
const vaultError = error instanceof VaultError ? error : undefined
|
|
354
|
+
if (vaultError?.code === 'pin-invalid') setKeyRestorePin('')
|
|
355
|
+
setKeyRestoreError(vaultErrorCopy(vaultError?.code, { count: vaultError?.retriesLeft }))
|
|
356
|
+
} finally {
|
|
357
|
+
setKeyRestoreBusy(false)
|
|
358
|
+
setKeyRestorePhase(null)
|
|
359
|
+
}
|
|
360
|
+
}, [pm, keyRestoreBusy, keyRestorePin, adminOriginator, selectedNetwork, reload])
|
|
361
|
+
|
|
295
362
|
/** F-04: surface the one recovery action for a signed deposit crash left
|
|
296
363
|
* behind — every other vault call keeps refusing with 'action-pending'
|
|
297
364
|
* until this resolves it, and there was previously no in-app way to. */
|
|
@@ -773,6 +840,41 @@ export function VaultScreen() {
|
|
|
773
840
|
)
|
|
774
841
|
|
|
775
842
|
// ── disable ─────────────────────────────────────────────────────────
|
|
843
|
+
const [forgetting, setForgetting] = useState(false)
|
|
844
|
+
const confirmForgetUnreachable = useCallback(async () => {
|
|
845
|
+
const count = coverage?.unreachableOutputs ?? 0
|
|
846
|
+
if (!pm || forgetting || count === 0) return
|
|
847
|
+
const choice = await showAlert({
|
|
848
|
+
title: t('vault_forget_unreachable_title'),
|
|
849
|
+
message: t('vault_forget_unreachable_message', { count }),
|
|
850
|
+
buttons: [
|
|
851
|
+
{ text: t('vault_forget_unreachable_confirm'), key: 'confirm', style: 'destructive' },
|
|
852
|
+
{ text: t('vault_cancel'), key: 'cancel', style: 'cancel' }
|
|
853
|
+
]
|
|
854
|
+
})
|
|
855
|
+
if (choice !== 'confirm') return
|
|
856
|
+
setForgetting(true)
|
|
857
|
+
try {
|
|
858
|
+
const { forgotten } = await forgetUnreachableVaultOutputs(pm as unknown as VaultWallet, adminOriginator)
|
|
859
|
+
haptics.success()
|
|
860
|
+
showToast(t('vault_forget_unreachable_done', { count: forgotten }), { type: 'success' })
|
|
861
|
+
} catch (e) {
|
|
862
|
+
console.error('[vault] could not forget unreachable deposits:', e instanceof Error ? e.message : e)
|
|
863
|
+
haptics.error()
|
|
864
|
+
const code = e instanceof VaultError ? e.code : undefined
|
|
865
|
+
if (code === 'action-pending') setActionPendingNotice(true)
|
|
866
|
+
await showAlert({
|
|
867
|
+
title: t('vault_forget_unreachable_title'),
|
|
868
|
+
message: vaultErrorCopy(code),
|
|
869
|
+
buttons: [{ text: t('vault_ok'), key: 'ok' }]
|
|
870
|
+
})
|
|
871
|
+
} finally {
|
|
872
|
+
setForgetting(false)
|
|
873
|
+
refresh()
|
|
874
|
+
refreshCoverage()
|
|
875
|
+
}
|
|
876
|
+
}, [coverage, pm, forgetting, adminOriginator, refresh, refreshCoverage])
|
|
877
|
+
|
|
776
878
|
const confirmDisable = useCallback(async () => {
|
|
777
879
|
// Refuse while funds remain: disabling forgets the key list, and with it
|
|
778
880
|
// the only in-app way to sign for those outputs.
|
|
@@ -1081,6 +1183,18 @@ export function VaultScreen() {
|
|
|
1081
1183
|
YubiKey — that is only needed afterward, to spend. */}
|
|
1082
1184
|
{enabled && !!pm && (
|
|
1083
1185
|
<View style={styles.heroNotice}>
|
|
1186
|
+
{supported && (
|
|
1187
|
+
<PressableScale
|
|
1188
|
+
haptic="tap"
|
|
1189
|
+
onPress={restoringFromChain ? undefined : () => setKeyRestoreOpen(true)}
|
|
1190
|
+
accessibilityState={{ disabled: restoringFromChain }}
|
|
1191
|
+
style={styles.secondary}
|
|
1192
|
+
>
|
|
1193
|
+
<Text style={[styles.secondaryLabel, { color: colors.accent }]}>
|
|
1194
|
+
{t('vault_restore_with_key')}
|
|
1195
|
+
</Text>
|
|
1196
|
+
</PressableScale>
|
|
1197
|
+
)}
|
|
1084
1198
|
<PressableScale
|
|
1085
1199
|
haptic="tap"
|
|
1086
1200
|
onPress={restoringFromChain ? undefined : () => void onRestoreFromChain()}
|
|
@@ -1104,6 +1218,64 @@ export function VaultScreen() {
|
|
|
1104
1218
|
<View style={styles.heroSpacerBottom} />
|
|
1105
1219
|
</ScrollView>
|
|
1106
1220
|
</View>
|
|
1221
|
+
<Sheet
|
|
1222
|
+
visible={keyRestoreOpen}
|
|
1223
|
+
onClose={keyRestoreBusy ? noop : closeKeyRestore}
|
|
1224
|
+
title={t('vault_restore_with_key')}
|
|
1225
|
+
fitContent
|
|
1226
|
+
>
|
|
1227
|
+
<View style={styles.sheetBody}>
|
|
1228
|
+
<Text style={[styles.p, { color: colors.textSecondary }]}>{t('vault_restore_with_key_body')}</Text>
|
|
1229
|
+
<Text style={[styles.sheetLabel, { color: colors.textPrimary }]}>{t('vault_enter_pin')}</Text>
|
|
1230
|
+
<TextInput
|
|
1231
|
+
accessibilityLabel={t('vault_enter_pin')}
|
|
1232
|
+
style={[styles.input, { color: colors.textPrimary, backgroundColor: colors.backgroundSecondary }]}
|
|
1233
|
+
value={keyRestorePin}
|
|
1234
|
+
onChangeText={text => {
|
|
1235
|
+
setKeyRestoreError(null)
|
|
1236
|
+
setKeyRestorePin(text)
|
|
1237
|
+
}}
|
|
1238
|
+
placeholder="••••••"
|
|
1239
|
+
placeholderTextColor={colors.textTertiary}
|
|
1240
|
+
keyboardType="number-pad"
|
|
1241
|
+
secureTextEntry={keyRestorePin.length > 0}
|
|
1242
|
+
maxLength={8}
|
|
1243
|
+
editable={!keyRestoreBusy}
|
|
1244
|
+
autoFocus
|
|
1245
|
+
/>
|
|
1246
|
+
{keyRestoreBusy && (
|
|
1247
|
+
<View style={styles.adoptionProgress}>
|
|
1248
|
+
<ActivityIndicator color={colors.accent} />
|
|
1249
|
+
<Text style={[styles.p, { color: colors.textSecondary }]}>
|
|
1250
|
+
{keyRestorePhase === 'scanning'
|
|
1251
|
+
? t('vault_restore_scanning')
|
|
1252
|
+
: keyRestorePhase === 'challenging'
|
|
1253
|
+
? t('vault_touch_when_blinks')
|
|
1254
|
+
: t('vault_reading_key')}
|
|
1255
|
+
</Text>
|
|
1256
|
+
</View>
|
|
1257
|
+
)}
|
|
1258
|
+
{keyRestoreError && <Text style={[styles.err, { color: colors.error }]}>{keyRestoreError}</Text>}
|
|
1259
|
+
<PressableScale
|
|
1260
|
+
haptic="confirm"
|
|
1261
|
+
onPress={!keyRestoreBusy && /^[0-9]{6,8}$/.test(keyRestorePin) ? () => void runKeyRestore() : undefined}
|
|
1262
|
+
accessibilityState={{ disabled: keyRestoreBusy || !/^[0-9]{6,8}$/.test(keyRestorePin) }}
|
|
1263
|
+
style={[
|
|
1264
|
+
styles.primary,
|
|
1265
|
+
{ backgroundColor: colors.accent, opacity: !keyRestoreBusy && /^[0-9]{6,8}$/.test(keyRestorePin) ? 1 : 0.5 }
|
|
1266
|
+
]}
|
|
1267
|
+
>
|
|
1268
|
+
{keyRestoreBusy ? (
|
|
1269
|
+
<ActivityIndicator color={colors.textOnAccent} />
|
|
1270
|
+
) : (
|
|
1271
|
+
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_continue')}</Text>
|
|
1272
|
+
)}
|
|
1273
|
+
</PressableScale>
|
|
1274
|
+
<PressableScale onPress={keyRestoreBusy ? undefined : closeKeyRestore} style={styles.secondary}>
|
|
1275
|
+
<Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>{t('vault_cancel')}</Text>
|
|
1276
|
+
</PressableScale>
|
|
1277
|
+
</View>
|
|
1278
|
+
</Sheet>
|
|
1107
1279
|
<BiometricAdvisoryModal
|
|
1108
1280
|
visible={showBiometricAdvisory}
|
|
1109
1281
|
loading={creatingWallet}
|
|
@@ -1240,18 +1412,31 @@ export function VaultScreen() {
|
|
|
1240
1412
|
header={keySectionHeader}
|
|
1241
1413
|
footer={t('vault_footnote')}
|
|
1242
1414
|
>
|
|
1243
|
-
{
|
|
1415
|
+
{/* Deposits no key on the list can open (an earlier setup's) are
|
|
1416
|
+
counted once, here: a re-lock cannot reach them, so they are kept
|
|
1417
|
+
out of the two re-lock badges below. */}
|
|
1418
|
+
{coverage && coverage.unreachableOutputs > 0 && (
|
|
1419
|
+
<ListRow
|
|
1420
|
+
label={t('vault_badge_unreachable', { count: coverage.unreachableOutputs })}
|
|
1421
|
+
icon="close-circle-outline"
|
|
1422
|
+
iconColor={colors.error}
|
|
1423
|
+
showChevron={false}
|
|
1424
|
+
onPress={forgetting ? undefined : () => void confirmForgetUnreachable()}
|
|
1425
|
+
trailing={forgetting ? <ActivityIndicator size="small" /> : undefined}
|
|
1426
|
+
/>
|
|
1427
|
+
)}
|
|
1428
|
+
{coverage && coverage.missingKeys.length > 0 && coverage.stale > coverage.unreachableOutputs && (
|
|
1244
1429
|
<ListRow
|
|
1245
|
-
label={t('vault_badge_missing', { count: coverage.stale, nickname: missingNames })}
|
|
1430
|
+
label={t('vault_badge_missing', { count: coverage.stale - coverage.unreachableOutputs, nickname: missingNames })}
|
|
1246
1431
|
icon="alert-circle-outline"
|
|
1247
1432
|
iconColor={colors.warning}
|
|
1248
1433
|
showChevron={false}
|
|
1249
1434
|
onPress={openGenericRelock}
|
|
1250
1435
|
/>
|
|
1251
1436
|
)}
|
|
1252
|
-
{coverage && coverage.removedKeyOutputs >
|
|
1437
|
+
{coverage && coverage.removedKeyOutputs > coverage.unreachableOutputs && (
|
|
1253
1438
|
<ListRow
|
|
1254
|
-
label={t('vault_badge_removed', { count: coverage.removedKeyOutputs })}
|
|
1439
|
+
label={t('vault_badge_removed', { count: coverage.removedKeyOutputs - coverage.unreachableOutputs })}
|
|
1255
1440
|
icon="alert-circle-outline"
|
|
1256
1441
|
iconColor={colors.warning}
|
|
1257
1442
|
showChevron={false}
|