@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.
- package/CHANGELOG.md +311 -0
- package/README.md +52 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/config.tsx +21 -18
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +413 -23
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +3368 -952
- package/core/index.ts +107 -14
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/externalOrigin.ts +39 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +19 -24
- package/core/storage/StorageExpoSQLite.ts +382 -56
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +0 -54
- package/core/storage/methods/listOutputsSql.ts +7 -3
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +263 -6
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +123 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +240 -0
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +25 -24
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
- package/ui/components/pay/RecipientField.tsx +49 -4
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/UniversalSend.tsx +534 -30
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +101 -17
- package/ui/components/wallet/AmountInput.tsx +77 -25
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +303 -0
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +50 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +130 -10
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +42 -20
- package/ui/screens/WalletHomeScreen.tsx +417 -86
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +79 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Which key will you tap?" — a radio list of the vault's enrolled keys, used
|
|
3
|
+
* before a withdrawal (spec §4.2 step 1) and before a re-lock (§4.3). Keys are
|
|
4
|
+
* shown everywhere as `nickname · …serialTail4` (§3.3), which is what
|
|
5
|
+
* `vaultKeyLabel` produces; the wizard, the vault screen and the transfer
|
|
6
|
+
* screen all import it from here so the format is written once.
|
|
7
|
+
*
|
|
8
|
+
* Controlled: `selected` is the caller's state, and the default (the key used
|
|
9
|
+
* last, `meta.lastUsedSerial`) is the caller's decision.
|
|
10
|
+
*/
|
|
11
|
+
import React from 'react'
|
|
12
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
13
|
+
import PressableScale from '../ui/PressableScale'
|
|
14
|
+
import { useTheme, spacing, radii, typography, type VaultKeyRecord } from '@bsv/expo-wallet-toolbox'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
18
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
19
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
20
|
+
* Loaded lazily, only when actually rendering, same pattern as this
|
|
21
|
+
* package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
22
|
+
*/
|
|
23
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
24
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
25
|
+
function loadIonicons(): IoniconsComponent {
|
|
26
|
+
if (!ioniconsComponent) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
28
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
29
|
+
}
|
|
30
|
+
return ioniconsComponent
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The one display form of a vault key: `nickname · …serialTail4`. */
|
|
34
|
+
export function vaultKeyLabel(k: { nickname: string; serial: string }): string {
|
|
35
|
+
return `${k.nickname} · …${k.serial.slice(-4)}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A serial grouped in threes from the right, e.g. `24939299` → `24 939 299`
|
|
39
|
+
* — the vault screen's key row shows the FULL serial this way rather than
|
|
40
|
+
* `vaultKeyLabel`'s truncated tail4 (that form stays for copy that names a
|
|
41
|
+
* key in passing — alerts, the ceremony sheet). */
|
|
42
|
+
export function formatVaultSerial(serial: string): string {
|
|
43
|
+
return serial.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const KeyChooser: React.FC<{ keys: VaultKeyRecord[]; selected?: string; onSelect: (serial: string) => void }> = ({
|
|
47
|
+
keys,
|
|
48
|
+
selected,
|
|
49
|
+
onSelect
|
|
50
|
+
}) => {
|
|
51
|
+
const { colors } = useTheme()
|
|
52
|
+
const Ionicons = loadIonicons()
|
|
53
|
+
return (
|
|
54
|
+
<View style={[styles.list, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}>
|
|
55
|
+
{keys.map((k, i) => {
|
|
56
|
+
const on = k.serial === selected
|
|
57
|
+
return (
|
|
58
|
+
<PressableScale
|
|
59
|
+
key={k.serial}
|
|
60
|
+
haptic="tap"
|
|
61
|
+
scaleTo={0.98}
|
|
62
|
+
accessibilityRole="radio"
|
|
63
|
+
accessibilityState={{ selected: on }}
|
|
64
|
+
onPress={() => onSelect(k.serial)}
|
|
65
|
+
style={[
|
|
66
|
+
styles.row,
|
|
67
|
+
i < keys.length - 1 && { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.separator }
|
|
68
|
+
]}
|
|
69
|
+
>
|
|
70
|
+
<Ionicons
|
|
71
|
+
name={on ? 'radio-button-on' : 'radio-button-off'}
|
|
72
|
+
size={22}
|
|
73
|
+
color={on ? colors.accent : colors.textTertiary}
|
|
74
|
+
/>
|
|
75
|
+
<Text style={[styles.label, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
76
|
+
{vaultKeyLabel(k)}
|
|
77
|
+
</Text>
|
|
78
|
+
</PressableScale>
|
|
79
|
+
)
|
|
80
|
+
})}
|
|
81
|
+
</View>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const styles = StyleSheet.create({
|
|
86
|
+
list: { borderRadius: radii.lg, borderWidth: StyleSheet.hairlineWidth, overflow: 'hidden' },
|
|
87
|
+
row: {
|
|
88
|
+
flexDirection: 'row',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
gap: spacing.md,
|
|
91
|
+
minHeight: 44,
|
|
92
|
+
paddingVertical: spacing.md,
|
|
93
|
+
paddingHorizontal: spacing.lg
|
|
94
|
+
},
|
|
95
|
+
label: { ...typography.body, flex: 1 }
|
|
96
|
+
})
|
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* VaultContext, which mirrors the ceremony singleton.
|
|
5
5
|
*
|
|
6
6
|
* Every phase says three things: WHY (the reason string / transfer summary),
|
|
7
|
-
* WHAT to do now (the phase copy + illustration), and how
|
|
8
|
-
* (countdown on awaiting-touch and
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* WHAT to do now (the phase copy + illustration), and how far along it is
|
|
8
|
+
* (countdown on awaiting-touch; `Signed k of n` and the batch number while a
|
|
9
|
+
* multi-input withdrawal is being signed — spec §4.2 step 8). Motion is
|
|
10
|
+
* scale/opacity of the sheet's own subviews only — never a fractional-opacity
|
|
11
|
+
* animation over glass (the UIVisualEffectView freeze guardrail).
|
|
12
|
+
*
|
|
13
|
+
* Error copy comes from vaultErrorCopy. CeremonyState carries no serial, so a
|
|
14
|
+
* serial-mismatch here can only list the vault's keys (read from meta); the
|
|
15
|
+
* "That's X — you chose Y" wording is the transfer screen's, which knows both.
|
|
11
16
|
*/
|
|
12
17
|
import React, { useEffect, useRef, useState } from 'react'
|
|
13
18
|
import { View, Text, StyleSheet, TextInput, ActivityIndicator, Platform } from 'react-native'
|
|
@@ -23,12 +28,16 @@ import Animated, {
|
|
|
23
28
|
} from 'react-native-reanimated'
|
|
24
29
|
import Sheet from '../ui/Sheet'
|
|
25
30
|
import PressableScale from '../ui/PressableScale'
|
|
31
|
+
import { vaultErrorCopy, RETRYABLE_VAULT_ERRORS } from './vaultErrorCopy'
|
|
32
|
+
import { vaultKeyLabel } from './KeyChooser'
|
|
26
33
|
import {
|
|
27
34
|
useTheme,
|
|
28
35
|
spacing,
|
|
29
36
|
radii,
|
|
30
37
|
typography,
|
|
31
38
|
useVault,
|
|
39
|
+
vaultStore,
|
|
40
|
+
VAULT_INPUTS_PER_TAP,
|
|
32
41
|
haptics,
|
|
33
42
|
i18n,
|
|
34
43
|
type CeremonyPhase,
|
|
@@ -54,32 +63,6 @@ function loadIonicons(): IoniconsComponent {
|
|
|
54
63
|
return ioniconsComponent
|
|
55
64
|
}
|
|
56
65
|
|
|
57
|
-
const ERROR_COPY: Record<string, string> = {
|
|
58
|
-
'serial-mismatch': 'vault_err_wrong_key',
|
|
59
|
-
'wrong-key': 'vault_err_wrong_key',
|
|
60
|
-
'touch-timeout': 'vault_err_touch_timeout',
|
|
61
|
-
'pin-locked': 'vault_err_pin_locked',
|
|
62
|
-
'pin-invalid': 'vault_err_pin_invalid',
|
|
63
|
-
'key-removed-mid-op': 'vault_err_removed',
|
|
64
|
-
'no-key': 'vault_err_no_key',
|
|
65
|
-
'driver-unavailable': 'vault_err_unavailable',
|
|
66
|
-
'not-enrolled': 'vault_err_unavailable',
|
|
67
|
-
'mgmt-key-custom': 'vault_err_mgmt_key',
|
|
68
|
-
'user-cancelled': 'vault_err_generic',
|
|
69
|
-
'unsupported-platform': 'vault_err_unavailable',
|
|
70
|
-
'slot-occupied': 'vault_err_generic',
|
|
71
|
-
'pin-required': 'vault_enter_pin',
|
|
72
|
-
'nfc-lost': 'vault_err_nfc_lost'
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Errors where the fix is simply "do the tap again" — worth a Retry button
|
|
76
|
-
* instead of only Dismiss. Must stay a SUBSET of `CeremonyController`'s own
|
|
77
|
-
* retryable set (services/vault/ceremony.ts) or the button renders but does
|
|
78
|
-
* nothing — 'key-removed-mid-op' is deliberately excluded even though the
|
|
79
|
-
* ceremony loop can produce it, because it can ALSO arrive from a moment the
|
|
80
|
-
* loop doesn't cover (waiting-for-key), where retry would be a dead button. */
|
|
81
|
-
const RETRYABLE_ERRORS = new Set<string>(['touch-timeout', 'nfc-lost'])
|
|
82
|
-
|
|
83
66
|
/** Swallows the sheet's dismiss while work is in flight — `Sheet` requires an
|
|
84
67
|
* onClose, and cancelling mid-operation is the thing we are preventing. */
|
|
85
68
|
const noop = (): void => {}
|
|
@@ -101,12 +84,12 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
101
84
|
const { state, submitPin, cancel, retry } = useVault()
|
|
102
85
|
const reducedMotion = useReducedMotion()
|
|
103
86
|
const [pin, setPin] = useState('')
|
|
87
|
+
const [keyNames, setKeyNames] = useState('')
|
|
104
88
|
const Ionicons = loadIonicons()
|
|
105
89
|
|
|
106
90
|
const phase = state.phase
|
|
107
91
|
// 'armed' stays hidden: it persists for the whole retention window, so
|
|
108
|
-
// showing it would leave the sheet up for minutes after a transfer is done
|
|
109
|
-
// — deposit and withdrawal both arm the same way and are treated alike here.
|
|
92
|
+
// showing it would leave the sheet up for minutes after a transfer is done.
|
|
110
93
|
const visible = phase !== 'idle' && phase !== 'armed'
|
|
111
94
|
|
|
112
95
|
/**
|
|
@@ -145,13 +128,59 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
145
128
|
}, [phase, reducedMotion, pulse])
|
|
146
129
|
const pulseStyle = useAnimatedStyle(() => ({ transform: [{ scale: pulse.value }] }))
|
|
147
130
|
|
|
148
|
-
// Reset the PIN field whenever we (re)enter pin-entry.
|
|
131
|
+
// Reset the PIN field whenever we (re)enter pin-entry. Usually the sheet is
|
|
132
|
+
// already open by then (pin-entry follows waiting-for-key/connecting), so
|
|
133
|
+
// focus can happen right away; but if pin-entry is reached while the sheet
|
|
134
|
+
// is still sliding in, wait for the open spring to settle first (below) —
|
|
135
|
+
// `autoFocus` or a fixed delay both risk focusing mid-slide, which drops
|
|
136
|
+
// the first keystroke (it lands while the native field is still wiring up).
|
|
137
|
+
const pinInputRef = useRef<TextInput>(null)
|
|
138
|
+
const sheetSettled = useRef(false)
|
|
139
|
+
const wantsPinFocus = useRef(false)
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!visible) sheetSettled.current = false
|
|
142
|
+
}, [visible])
|
|
149
143
|
useEffect(() => {
|
|
150
|
-
if (phase
|
|
144
|
+
if (phase !== 'pin-entry') return
|
|
145
|
+
setPin('')
|
|
146
|
+
if (sheetSettled.current) {
|
|
147
|
+
pinInputRef.current?.focus()
|
|
148
|
+
} else {
|
|
149
|
+
wantsPinFocus.current = true
|
|
150
|
+
}
|
|
151
151
|
}, [phase])
|
|
152
152
|
|
|
153
|
+
// The vault's key labels, for serial-mismatch copy. Read once per ceremony
|
|
154
|
+
// (when the sheet becomes visible), never during idle: this component is
|
|
155
|
+
// mounted for the app's whole life.
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (!visible) return
|
|
158
|
+
let alive = true
|
|
159
|
+
void vaultStore
|
|
160
|
+
.getMeta()
|
|
161
|
+
.then(m => {
|
|
162
|
+
if (alive) setKeyNames(m ? m.keys.map(vaultKeyLabel).join(', ') : '')
|
|
163
|
+
})
|
|
164
|
+
.catch(() => {
|
|
165
|
+
if (alive) setKeyNames('')
|
|
166
|
+
})
|
|
167
|
+
return () => {
|
|
168
|
+
alive = false
|
|
169
|
+
}
|
|
170
|
+
}, [visible])
|
|
171
|
+
|
|
153
172
|
const reason = state.reason
|
|
154
173
|
const errCode = state.error?.code as VaultErrorCode | undefined
|
|
174
|
+
const progress = state.progress
|
|
175
|
+
|
|
176
|
+
// Batch arithmetic (spec §4.2 step 6): at most VAULT_INPUTS_PER_TAP digests
|
|
177
|
+
// per tap. `signed > 0` while waiting for a key means "between batches".
|
|
178
|
+
const batches = progress ? Math.max(1, Math.ceil(progress.total / VAULT_INPUTS_PER_TAP)) : 0
|
|
179
|
+
const batchIndex = progress ? Math.min(batches, Math.floor(progress.signed / VAULT_INPUTS_PER_TAP) + 1) : 0
|
|
180
|
+
const betweenBatches =
|
|
181
|
+
!!progress &&
|
|
182
|
+
progress.signed > 0 &&
|
|
183
|
+
(phase === 'waiting-for-key' || phase === 'awaiting-touch' || phase === 'connecting')
|
|
155
184
|
|
|
156
185
|
// iOS talks to the key over NFC (a tap), Android over USB (insert + touch).
|
|
157
186
|
const nfc = Platform.OS === 'ios'
|
|
@@ -171,7 +200,7 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
171
200
|
case 'broadcasting':
|
|
172
201
|
return t('vault_sending_to_network')
|
|
173
202
|
case 'error':
|
|
174
|
-
return
|
|
203
|
+
return vaultErrorCopy(errCode, { names: keyNames || undefined })
|
|
175
204
|
default:
|
|
176
205
|
return ''
|
|
177
206
|
}
|
|
@@ -180,7 +209,19 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
180
209
|
const iconColor = phase === 'error' ? colors.error : colors.accent
|
|
181
210
|
|
|
182
211
|
return (
|
|
183
|
-
<Sheet
|
|
212
|
+
<Sheet
|
|
213
|
+
visible={visible}
|
|
214
|
+
onClose={busy ? noop : cancel}
|
|
215
|
+
title={t('vault_title')}
|
|
216
|
+
fitContent
|
|
217
|
+
onOpenComplete={() => {
|
|
218
|
+
sheetSettled.current = true
|
|
219
|
+
if (wantsPinFocus.current) {
|
|
220
|
+
wantsPinFocus.current = false
|
|
221
|
+
pinInputRef.current?.focus()
|
|
222
|
+
}
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
184
225
|
<View style={styles.body}>
|
|
185
226
|
{reason ? <Text style={[styles.reason, { color: colors.textSecondary }]}>{reason}</Text> : null}
|
|
186
227
|
|
|
@@ -194,12 +235,29 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
194
235
|
|
|
195
236
|
<Text style={[styles.title, { color: colors.textPrimary }]}>{title}</Text>
|
|
196
237
|
|
|
238
|
+
{/* Between taps of a multi-batch signing: which batch this is, and how
|
|
239
|
+
far along. The iOS system NFC sheet covers this while it is up, so
|
|
240
|
+
this is what the user sees as it dismisses and before the next tap. */}
|
|
241
|
+
{betweenBatches && progress && (
|
|
242
|
+
<>
|
|
243
|
+
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
|
|
244
|
+
{t('vault_nfc_sign_batch', { b: batchIndex, n: batches })}
|
|
245
|
+
</Text>
|
|
246
|
+
<Text style={[styles.hint, { color: colors.textSecondary }]}>
|
|
247
|
+
{t('vault_sign_progress', { signed: progress.signed, total: progress.total })}
|
|
248
|
+
</Text>
|
|
249
|
+
</>
|
|
250
|
+
)}
|
|
251
|
+
|
|
197
252
|
{/* The whole point of the busy phases: say the work is real and say
|
|
198
|
-
not to leave
|
|
199
|
-
progress rather than a hang. */}
|
|
253
|
+
not to leave. While signatures are being gathered, say how many. */}
|
|
200
254
|
{busy && (
|
|
201
255
|
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
|
|
202
|
-
{phase === 'broadcasting'
|
|
256
|
+
{phase === 'broadcasting'
|
|
257
|
+
? t('vault_sending_sub')
|
|
258
|
+
: progress
|
|
259
|
+
? t('vault_sign_progress', { signed: progress.signed, total: progress.total })
|
|
260
|
+
: t('vault_unlocking_sub')}
|
|
203
261
|
</Text>
|
|
204
262
|
)}
|
|
205
263
|
|
|
@@ -211,6 +269,7 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
211
269
|
{nfc ? t('vault_pin_sub_nfc') : t('vault_pin_sub_usb')}
|
|
212
270
|
</Text>
|
|
213
271
|
<TextInput
|
|
272
|
+
ref={pinInputRef}
|
|
214
273
|
style={[styles.pin, { color: colors.textPrimary, backgroundColor: colors.backgroundSecondary }]}
|
|
215
274
|
value={pin}
|
|
216
275
|
onChangeText={setPin}
|
|
@@ -219,7 +278,6 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
219
278
|
keyboardType="number-pad"
|
|
220
279
|
secureTextEntry
|
|
221
280
|
maxLength={8}
|
|
222
|
-
autoFocus
|
|
223
281
|
/>
|
|
224
282
|
{state.error?.code === 'pin-invalid' && typeof state.error.retriesLeft === 'number' && (
|
|
225
283
|
<Text style={[styles.hint, { color: colors.warning }]}>
|
|
@@ -229,9 +287,15 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
229
287
|
<PressableScale
|
|
230
288
|
haptic="confirm"
|
|
231
289
|
onPress={() => {
|
|
232
|
-
if (pin
|
|
290
|
+
if (!/^[0-9]{6,8}$/.test(pin)) return
|
|
291
|
+
submitPin(pin)
|
|
292
|
+
// Drop it from component state the moment it is handed over:
|
|
293
|
+
// this sheet is mounted for the app's whole life, and the
|
|
294
|
+
// phase effect above only clears on RE-ENTERING pin-entry.
|
|
295
|
+
setPin('')
|
|
233
296
|
}}
|
|
234
|
-
|
|
297
|
+
accessibilityState={{ disabled: !/^[0-9]{6,8}$/.test(pin) }}
|
|
298
|
+
style={[styles.primaryBtn, { backgroundColor: colors.accent, opacity: /^[0-9]{6,8}$/.test(pin) ? 1 : 0.4 }]}
|
|
235
299
|
>
|
|
236
300
|
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_unlock_cta')}</Text>
|
|
237
301
|
</PressableScale>
|
|
@@ -248,7 +312,7 @@ export const VaultCeremonySheet: React.FC = () => {
|
|
|
248
312
|
|
|
249
313
|
{phase === 'error' && (
|
|
250
314
|
<View style={styles.errorActions}>
|
|
251
|
-
{errCode &&
|
|
315
|
+
{errCode && RETRYABLE_VAULT_ERRORS.has(errCode) && (
|
|
252
316
|
<PressableScale
|
|
253
317
|
haptic="confirm"
|
|
254
318
|
onPress={retry}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One table from VaultErrorCode to user copy.
|
|
3
|
+
*
|
|
4
|
+
* Replaces two tables that disagreed with each other: VaultCeremonySheet's
|
|
5
|
+
* ERROR_COPY (a hand-written code → key map with alias keys) and
|
|
6
|
+
* VaultTransferScreen's translateVaultError (a `vault_err_${code}` naming
|
|
7
|
+
* convention with a generic fallback). Every code in the union is listed, so
|
|
8
|
+
* adding a code without copy is a type error rather than a raw key on screen.
|
|
9
|
+
*
|
|
10
|
+
* Copy that names keys or amounts takes them from `params`. When a caller has
|
|
11
|
+
* nothing to name, the code degrades to the closest copy that needs no
|
|
12
|
+
* parameters (see the switch) — never to a string with `{{placeholders}}`
|
|
13
|
+
* left in it.
|
|
14
|
+
*
|
|
15
|
+
* Contract note: `VaultError` carries a code, an optional message and
|
|
16
|
+
* `retriesLeft`, plus an optional structured `details` object services may
|
|
17
|
+
* attach (the DECISION: `serial-mismatch` → `{ tapped, chosen }`,
|
|
18
|
+
* `key-already-enrolled` → `{ serial }`, `key-cannot-cover` → `{ reachable,
|
|
19
|
+
* total }`). Callers derive `tappedName`/`chosenName` from `error.details`
|
|
20
|
+
* (Plan 2's `requestSigner` / `enrollKey`), and `reachable`/`total` likewise
|
|
21
|
+
* from `error.details` (see VaultTransferScreen's readErrorDetails). None of
|
|
22
|
+
* this is required: the fallbacks below are what the user sees when a
|
|
23
|
+
* service omits `details`.
|
|
24
|
+
*/
|
|
25
|
+
import { i18n, type VaultErrorCode } from '@bsv/expo-wallet-toolbox'
|
|
26
|
+
|
|
27
|
+
const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
|
|
28
|
+
|
|
29
|
+
export interface VaultErrorParams {
|
|
30
|
+
/** The key the copy is about, as `nickname · …tail4` (KeyChooser's vaultKeyLabel) or a bare nickname. */
|
|
31
|
+
nickname?: string
|
|
32
|
+
/** Every enrolled key, joined with ', '. */
|
|
33
|
+
names?: string
|
|
34
|
+
/** The other enrolled keys (all but `nickname`), joined with ', '. */
|
|
35
|
+
otherNames?: string
|
|
36
|
+
/** serial-mismatch: the tapped card, when it is itself an enrolled key. */
|
|
37
|
+
tappedName?: string
|
|
38
|
+
/** serial-mismatch: the key the user chose in-app. */
|
|
39
|
+
chosenName?: string
|
|
40
|
+
/** key-cannot-cover: formatted amounts (formatAmount output), not raw sats. */
|
|
41
|
+
reachable?: string
|
|
42
|
+
total?: string
|
|
43
|
+
/** pin-invalid: attempts left, appended as a second sentence. */
|
|
44
|
+
count?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Exhaustive over the union: TypeScript rejects a missing or extra entry the
|
|
49
|
+
* moment `VaultErrorCode` changes.
|
|
50
|
+
*/
|
|
51
|
+
const KEY: Record<VaultErrorCode, string> = {
|
|
52
|
+
'unsupported-platform': 'vault_err_unsupported_platform',
|
|
53
|
+
'no-key': 'vault_err_no_key',
|
|
54
|
+
'wrong-key': 'vault_err_wrong_key',
|
|
55
|
+
'pin-required': 'vault_err_pin_required',
|
|
56
|
+
'pin-invalid': 'vault_err_pin_invalid',
|
|
57
|
+
'pin-locked': 'vault_err_pin_locked',
|
|
58
|
+
'puk-invalid': 'vault_err_puk_invalid',
|
|
59
|
+
'puk-locked': 'vault_err_puk_locked',
|
|
60
|
+
'touch-timeout': 'vault_err_touch_timeout',
|
|
61
|
+
'key-removed-mid-op': 'vault_err_key_removed_mid_op',
|
|
62
|
+
'ceremony-active': 'vault_err_ceremony_active',
|
|
63
|
+
'scope-changed': 'vault_err_scope_changed',
|
|
64
|
+
'mgmt-key-custom': 'vault_err_mgmt_key_custom',
|
|
65
|
+
'attestation-invalid': 'vault_err_attestation_invalid',
|
|
66
|
+
'slot-occupied': 'vault_err_slot_occupied',
|
|
67
|
+
'enrollment-partial': 'vault_err_enrollment_partial',
|
|
68
|
+
'template-invalid': 'vault_err_template_invalid',
|
|
69
|
+
'serial-mismatch': 'vault_err_serial_mismatch',
|
|
70
|
+
'user-cancelled': 'vault_err_user_cancelled',
|
|
71
|
+
'not-enrolled': 'vault_err_not_enrolled',
|
|
72
|
+
'driver-unavailable': 'vault_err_driver_unavailable',
|
|
73
|
+
'vault-empty': 'vault_err_vault_empty',
|
|
74
|
+
'amount-exceeds-balance': 'vault_err_amount_exceeds_balance',
|
|
75
|
+
'below-dust': 'vault_err_below_dust',
|
|
76
|
+
'no-transaction': 'vault_err_no_transaction',
|
|
77
|
+
'nfc-lost': 'vault_err_nfc_lost',
|
|
78
|
+
'too-many-inputs': 'vault_err_too_many_inputs',
|
|
79
|
+
'requires-online': 'vault_err_requires_online',
|
|
80
|
+
'not-released': 'vault_err_not_released',
|
|
81
|
+
'not-on-mainnet': 'vault_err_not_on_mainnet',
|
|
82
|
+
'backup-off': 'vault_err_backup_off',
|
|
83
|
+
'not-enough-keys': 'vault_err_not_enough_keys',
|
|
84
|
+
'key-already-enrolled': 'vault_err_key_already_enrolled',
|
|
85
|
+
'key-not-adopted': 'vault_err_key_not_adopted',
|
|
86
|
+
'too-many-keys': 'vault_err_too_many_keys',
|
|
87
|
+
'last-keys': 'vault_err_last_keys',
|
|
88
|
+
'relock-required': 'vault_err_relock_required',
|
|
89
|
+
'action-pending': 'vault_err_action_pending',
|
|
90
|
+
'key-not-committed': 'vault_err_key_not_committed',
|
|
91
|
+
'key-cannot-cover': 'vault_err_key_cannot_cover',
|
|
92
|
+
'too-small-to-relock': 'vault_err_too_small_to_relock',
|
|
93
|
+
'bad-version': 'vault_err_bad_version'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Errors where the fix is simply "do the tap again" — worth a Retry button
|
|
98
|
+
* instead of only Dismiss. Must stay a SUBSET of `CeremonyController`'s own
|
|
99
|
+
* retryable set (core/services/vault/ceremony.ts, `RETRYABLE_TAP_ERRORS`) or
|
|
100
|
+
* the button renders but does nothing. 'key-removed-mid-op' is deliberately
|
|
101
|
+
* excluded even though the signing loop can produce it, because it can ALSO
|
|
102
|
+
* arrive from a moment the loop does not cover (waiting-for-key), where retry
|
|
103
|
+
* would be a dead button.
|
|
104
|
+
*/
|
|
105
|
+
export const RETRYABLE_VAULT_ERRORS: ReadonlySet<VaultErrorCode> = new Set<VaultErrorCode>([
|
|
106
|
+
'touch-timeout',
|
|
107
|
+
'nfc-lost'
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
export function vaultErrorCopy(code: VaultErrorCode | undefined, params: VaultErrorParams = {}): string {
|
|
111
|
+
// `code in KEY` guards a code the natives might emit that the union does not
|
|
112
|
+
// know (vaultErrorFromNative casts freely); it must land on the generic line,
|
|
113
|
+
// not on the raw `vault_err_<code>` key.
|
|
114
|
+
if (!code || !(code in KEY)) return t('vault_err_generic')
|
|
115
|
+
switch (code) {
|
|
116
|
+
case 'serial-mismatch':
|
|
117
|
+
if (params.tappedName && params.chosenName) {
|
|
118
|
+
return t('vault_err_serial_mismatch_chosen', {
|
|
119
|
+
tappedName: params.tappedName,
|
|
120
|
+
chosenName: params.chosenName
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
if (params.names) return t('vault_err_serial_mismatch', { names: params.names })
|
|
124
|
+
return t('vault_err_wrong_key')
|
|
125
|
+
case 'key-already-enrolled':
|
|
126
|
+
case 'key-not-committed':
|
|
127
|
+
return params.nickname ? t(KEY[code], { nickname: params.nickname }) : t('vault_err_generic')
|
|
128
|
+
case 'key-cannot-cover':
|
|
129
|
+
return params.nickname && params.reachable && params.total && params.otherNames
|
|
130
|
+
? t(KEY[code], {
|
|
131
|
+
nickname: params.nickname,
|
|
132
|
+
reachable: params.reachable,
|
|
133
|
+
total: params.total,
|
|
134
|
+
otherNames: params.otherNames
|
|
135
|
+
})
|
|
136
|
+
: t('vault_err_amount_exceeds_balance')
|
|
137
|
+
case 'pin-invalid':
|
|
138
|
+
case 'puk-invalid':
|
|
139
|
+
return typeof params.count === 'number'
|
|
140
|
+
? `${t(KEY[code])} ${t('vault_pin_retries', { count: params.count })}`
|
|
141
|
+
: t(KEY[code])
|
|
142
|
+
default:
|
|
143
|
+
return t(KEY[code])
|
|
144
|
+
}
|
|
145
|
+
}
|