@bsv/expo-wallet-toolbox 0.3.0 → 0.4.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 +251 -0
- package/README.md +60 -8
- package/core/config.tsx +12 -17
- package/core/context/LocalStorageProvider.tsx +29 -4
- package/core/context/WalletContext.tsx +5 -4
- package/core/i18n/translations.tsx +12 -0
- package/core/index.ts +11 -1
- package/core/services/secrets/migration.ts +3 -2
- package/core/services/secrets/store.ts +6 -4
- package/core/services/vault/backupAttestation.ts +17 -2
- package/core/services/walletServiceConfig.ts +19 -24
- package/core/toolboxConfig.ts +129 -0
- package/package.json +3 -2
- package/ui/screens/ConnectionsScreen.tsx +12 -2
- package/ui/screens/WalletConfigScreen.tsx +27 -108
- package/ui/screens/WalletHomeScreen.tsx +38 -19
|
@@ -28,17 +28,19 @@ import { EnvelopeBlob, EnvelopeError, SECRET_NAMES, SecretName } from './types'
|
|
|
28
28
|
* the stale ciphertext. Harmless — it was already unopenable — but don't call
|
|
29
29
|
* it speculatively in a hot path.
|
|
30
30
|
*/
|
|
31
|
-
export async function hasSecret(name: SecretName): Promise<boolean> {
|
|
31
|
+
export async function hasSecret(name: SecretName, options?: { strict?: boolean }): Promise<boolean> {
|
|
32
32
|
try {
|
|
33
33
|
return (await SecureStore.getItemAsync(envKey(name), envOptions)) !== null
|
|
34
|
-
} catch {
|
|
34
|
+
} catch (err) {
|
|
35
|
+
// Creation must distinguish an unreadable keychain from an empty one.
|
|
36
|
+
if (options?.strict) throw err
|
|
35
37
|
return false
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export async function hasAnySecret(): Promise<boolean> {
|
|
41
|
+
export async function hasAnySecret(options?: { strict?: boolean }): Promise<boolean> {
|
|
40
42
|
for (const name of SECRET_NAMES) {
|
|
41
|
-
if (await hasSecret(name)) return true
|
|
43
|
+
if (await hasSecret(name, options)) return true
|
|
42
44
|
}
|
|
43
45
|
return false
|
|
44
46
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
19
19
|
|
|
20
20
|
export const ATTEST_KEY_PREFIX = 'vault_backup_attest_v1_'
|
|
21
|
+
export const PENDING_KEY_PREFIX = 'wallet_backup_pending_v1_'
|
|
21
22
|
|
|
22
23
|
export type BackupMedium = 'phrase' | 'shares'
|
|
23
24
|
|
|
@@ -30,8 +31,21 @@ export interface BackupAttestation {
|
|
|
30
31
|
|
|
31
32
|
/** Last 8 hex chars of the identity key — the app's established scope suffix. */
|
|
32
33
|
const scopeKey = (identityKey: string): string => ATTEST_KEY_PREFIX + identityKey.slice(-8)
|
|
34
|
+
const pendingKey = (identityKey: string): string => PENDING_KEY_PREFIX + identityKey
|
|
33
35
|
|
|
34
36
|
export const backupAttestation = {
|
|
37
|
+
/** Only newly generated wallets are known to need their first backup.
|
|
38
|
+
* A returning wallet with no record predates tracking: its backup status is
|
|
39
|
+
* unknown, not evidence that the owner has never saved their keys. */
|
|
40
|
+
async markPending(identityKey: string): Promise<void> {
|
|
41
|
+
await AsyncStorage.setItem(pendingKey(identityKey), '1')
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async needsReminder(identityKey: string): Promise<boolean> {
|
|
45
|
+
if ((await AsyncStorage.getItem(pendingKey(identityKey))) !== '1') return false
|
|
46
|
+
return (await backupAttestation.get(identityKey)) === null
|
|
47
|
+
},
|
|
48
|
+
|
|
35
49
|
async get(identityKey: string): Promise<BackupAttestation | null> {
|
|
36
50
|
const raw = await AsyncStorage.getItem(scopeKey(identityKey))
|
|
37
51
|
if (!raw) return null
|
|
@@ -46,16 +60,17 @@ export const backupAttestation = {
|
|
|
46
60
|
async set(identityKey: string, medium: BackupMedium): Promise<void> {
|
|
47
61
|
const record: BackupAttestation = { v: 1, medium, at: Date.now() }
|
|
48
62
|
await AsyncStorage.setItem(scopeKey(identityKey), JSON.stringify(record))
|
|
63
|
+
await AsyncStorage.removeItem(pendingKey(identityKey))
|
|
49
64
|
},
|
|
50
65
|
|
|
51
66
|
async clear(identityKey: string): Promise<void> {
|
|
52
|
-
await AsyncStorage.
|
|
67
|
+
await AsyncStorage.multiRemove([scopeKey(identityKey), pendingKey(identityKey)])
|
|
53
68
|
},
|
|
54
69
|
|
|
55
70
|
/** Logout has no identity key to hand, so sweep the prefix. */
|
|
56
71
|
async clearAll(): Promise<void> {
|
|
57
72
|
const keys = await AsyncStorage.getAllKeys()
|
|
58
|
-
const mine = keys.filter(k => k.startsWith(ATTEST_KEY_PREFIX))
|
|
73
|
+
const mine = keys.filter(k => k.startsWith(ATTEST_KEY_PREFIX) || k.startsWith(PENDING_KEY_PREFIX))
|
|
59
74
|
if (mine.length > 0) await AsyncStorage.multiRemove(mine)
|
|
60
75
|
}
|
|
61
76
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AppChain } from '../config'
|
|
2
2
|
import { toWalletChain } from '../config'
|
|
3
|
+
import { getServiceConfig } from '../toolboxConfig'
|
|
3
4
|
import {
|
|
4
5
|
ChaintracksServiceClient,
|
|
5
6
|
Services
|
|
@@ -18,18 +19,11 @@ import type { ChainTracker } from '@bsv/sdk'
|
|
|
18
19
|
* this, rather than each keeping their own copy that could drift.
|
|
19
20
|
*/
|
|
20
21
|
export function chaintracksUrlFor(network: AppChain): string {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (network === 'test')
|
|
25
|
-
|
|
26
|
-
process.env?.EXPO_PUBLIC_TEST_CHAINTRACKS_URL ??
|
|
27
|
-
'https://arcade-v2-testnet-us-1.bsvblockchain.tech/chaintracks/v1'
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
return (
|
|
31
|
-
process.env?.EXPO_PUBLIC_TERATEST_CHAINTRACKS_URL ?? 'https://arcade-v2-ttn-us-1.bsvblockchain.tech/chaintracks/v1'
|
|
32
|
-
)
|
|
22
|
+
const configured = getServiceConfig(network).chaintracksUrl
|
|
23
|
+
if (configured != null && configured !== '') return configured
|
|
24
|
+
if (network === 'main') return 'https://arcade-v2-us-1.bsvblockchain.tech/chaintracks/v1'
|
|
25
|
+
if (network === 'test') return 'https://arcade-v2-testnet-us-1.bsvblockchain.tech/chaintracks/v1'
|
|
26
|
+
return 'https://arcade-v2-ttn-us-1.bsvblockchain.tech/chaintracks/v1'
|
|
33
27
|
}
|
|
34
28
|
|
|
35
29
|
/**
|
|
@@ -75,6 +69,7 @@ export function createServiceOptions(
|
|
|
75
69
|
chaintracksOverride?: ChaintracksClientApi
|
|
76
70
|
): WalletServicesOptions {
|
|
77
71
|
const walletChain = toWalletChain(network)
|
|
72
|
+
const svc = getServiceConfig(network)
|
|
78
73
|
const base = {
|
|
79
74
|
chain: walletChain,
|
|
80
75
|
bsvExchangeRate,
|
|
@@ -88,15 +83,15 @@ export function createServiceOptions(
|
|
|
88
83
|
if (network === 'main') {
|
|
89
84
|
return {
|
|
90
85
|
...base,
|
|
91
|
-
arcUrl: arcUrlOverride ??
|
|
86
|
+
arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-us-1.bsvblockchain.tech',
|
|
92
87
|
arcConfig: {
|
|
93
|
-
apiKey: arcApiKeyOverride ??
|
|
88
|
+
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
94
89
|
callbackToken
|
|
95
90
|
},
|
|
96
91
|
bsvUpdateMsecs: 60 * 60 * 1000,
|
|
97
92
|
fiatUpdateMsecs: 60 * 60 * 1000,
|
|
98
|
-
whatsOnChainApiKey:
|
|
99
|
-
taalApiKey:
|
|
93
|
+
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
94
|
+
taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
|
|
100
95
|
chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
|
|
101
96
|
}
|
|
102
97
|
}
|
|
@@ -104,15 +99,15 @@ export function createServiceOptions(
|
|
|
104
99
|
if (network === 'test') {
|
|
105
100
|
return {
|
|
106
101
|
...base,
|
|
107
|
-
arcUrl: arcUrlOverride ??
|
|
102
|
+
arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-testnet-us-1.bsvblockchain.tech',
|
|
108
103
|
arcConfig: {
|
|
109
|
-
apiKey: arcApiKeyOverride ??
|
|
104
|
+
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
110
105
|
callbackToken
|
|
111
106
|
},
|
|
112
107
|
bsvUpdateMsecs: 60 * 60 * 1000000,
|
|
113
108
|
fiatUpdateMsecs: 60 * 60 * 1000000,
|
|
114
|
-
whatsOnChainApiKey:
|
|
115
|
-
taalApiKey:
|
|
109
|
+
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
110
|
+
taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
|
|
116
111
|
chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
|
|
117
112
|
}
|
|
118
113
|
}
|
|
@@ -120,15 +115,15 @@ export function createServiceOptions(
|
|
|
120
115
|
// teratest
|
|
121
116
|
return {
|
|
122
117
|
...base,
|
|
123
|
-
arcUrl: arcUrlOverride ??
|
|
118
|
+
arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-ttn-us-1.bsvblockchain.tech',
|
|
124
119
|
arcConfig: {
|
|
125
|
-
apiKey: arcApiKeyOverride ??
|
|
120
|
+
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
126
121
|
callbackToken
|
|
127
122
|
},
|
|
128
123
|
bsvUpdateMsecs: 60 * 60 * 1000000,
|
|
129
124
|
fiatUpdateMsecs: 60 * 60 * 1000000,
|
|
130
|
-
whatsOnChainApiKey:
|
|
131
|
-
taalApiKey:
|
|
125
|
+
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
126
|
+
taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
|
|
132
127
|
chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
|
|
133
128
|
}
|
|
134
129
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { AppChain } from './config'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service endpoints and API keys for one chain.
|
|
5
|
+
*
|
|
6
|
+
* Every field is optional: an omitted field falls back to the built-in public
|
|
7
|
+
* default in `walletServiceConfig.ts`. Omitting the whole chain entry is the
|
|
8
|
+
* same as passing `{}`.
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolboxServiceConfig {
|
|
11
|
+
arcUrl?: string
|
|
12
|
+
arcApiKey?: string
|
|
13
|
+
chaintracksUrl?: string
|
|
14
|
+
whatsOnChainApiKey?: string
|
|
15
|
+
taalApiKey?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runtime configuration supplied by the host app.
|
|
20
|
+
*
|
|
21
|
+
* The toolbox reads no `process.env` of its own. Expo's Babel preset refuses to
|
|
22
|
+
* inline `EXPO_PUBLIC_*` for any file whose path contains `node_modules`
|
|
23
|
+
* (`babel-preset-expo/build/common.js` — `!isNodeModule && ...`), so an env read
|
|
24
|
+
* inside this package is `undefined` in every production bundle of a host that
|
|
25
|
+
* installs it from npm, while working fine in dev and in a host that consumes it
|
|
26
|
+
* from source. That asymmetry is what silently disabled backup for three weeks.
|
|
27
|
+
*
|
|
28
|
+
* So the host reads its own env — where inlining works — and states the values
|
|
29
|
+
* here, once, before rendering:
|
|
30
|
+
*
|
|
31
|
+
* configureToolbox({
|
|
32
|
+
* backupUrl: process.env.EXPO_PUBLIC_BACKUP_URL ?? null,
|
|
33
|
+
* services: { main: { arcUrl: process.env.EXPO_PUBLIC_ARC_URL } }
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* There is deliberately no env fallback here. A fallback would restore exactly
|
|
37
|
+
* the silent path this seam exists to close.
|
|
38
|
+
*/
|
|
39
|
+
export interface ToolboxConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Origin of the encrypted wallet-backup service — no trailing slash, no path.
|
|
42
|
+
* The BRC-103/104 handshake is posted to the origin root, so a path prefix
|
|
43
|
+
* makes every request fail authentication.
|
|
44
|
+
*
|
|
45
|
+
* `null` disables backup entirely: no monitor task is registered, nothing is
|
|
46
|
+
* sent, and the backup UI does not render. It is required rather than
|
|
47
|
+
* optional so that every build states its endpoint — including stating that
|
|
48
|
+
* it has none. An upgrading host that passes nothing gets a type error, not
|
|
49
|
+
* another empty string.
|
|
50
|
+
*/
|
|
51
|
+
backupUrl: string | null
|
|
52
|
+
/** Per-chain service endpoints and keys. Omitted chains use built-in defaults. */
|
|
53
|
+
services?: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ResolvedConfig {
|
|
57
|
+
backupUrl: string
|
|
58
|
+
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let current: ResolvedConfig | null = null
|
|
62
|
+
|
|
63
|
+
const NOT_CONFIGURED =
|
|
64
|
+
'expo-wallet-toolbox is not configured. Call configureToolbox({ backupUrl, services }) ' +
|
|
65
|
+
'from the host app entry point, before rendering WalletContextProvider. ' +
|
|
66
|
+
'Pass backupUrl: null to disable backup deliberately.'
|
|
67
|
+
|
|
68
|
+
function normalizeBackupUrl(raw: string): string {
|
|
69
|
+
const trimmed = raw.trim().replace(/\/+$/, '')
|
|
70
|
+
if (trimmed === '') return ''
|
|
71
|
+
let parsed: URL
|
|
72
|
+
try {
|
|
73
|
+
parsed = new URL(trimmed)
|
|
74
|
+
} catch {
|
|
75
|
+
throw new Error(`configureToolbox: backupUrl is not a valid URL: ${raw}`)
|
|
76
|
+
}
|
|
77
|
+
if (parsed.pathname !== '' && parsed.pathname !== '/') {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`configureToolbox: backupUrl must be an origin with no path (got "${parsed.pathname}"). ` +
|
|
80
|
+
'The BRC-103/104 handshake posts to the origin root, so a path prefix fails authentication.'
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
if (parsed.search !== '' || parsed.hash !== '') {
|
|
84
|
+
throw new Error(`configureToolbox: backupUrl must be a bare origin, with no query or fragment: ${raw}`)
|
|
85
|
+
}
|
|
86
|
+
return trimmed
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Install the host's runtime configuration. Call once, at app entry, before
|
|
91
|
+
* anything from this package renders or builds a wallet.
|
|
92
|
+
*
|
|
93
|
+
* Calling it again replaces the configuration wholesale — it is not merged.
|
|
94
|
+
*/
|
|
95
|
+
export function configureToolbox(config: ToolboxConfig): void {
|
|
96
|
+
if (config == null || !('backupUrl' in config)) {
|
|
97
|
+
throw new Error('configureToolbox: backupUrl is required. Pass null to disable backup.')
|
|
98
|
+
}
|
|
99
|
+
current = {
|
|
100
|
+
backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
|
|
101
|
+
services: config.services ?? {}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** True once `configureToolbox` has run. For hosts that want to assert their own ordering. */
|
|
106
|
+
export function isToolboxConfigured(): boolean {
|
|
107
|
+
return current !== null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The configured backup origin, or `''` when the host passed `null`.
|
|
112
|
+
* Throws if the host never configured the toolbox at all — an unconfigured
|
|
113
|
+
* build must fail loudly, not quietly behave like a disabled one.
|
|
114
|
+
*/
|
|
115
|
+
export function getBackupUrl(): string {
|
|
116
|
+
if (current === null) throw new Error(NOT_CONFIGURED)
|
|
117
|
+
return current.backupUrl
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Service endpoints for a chain. Missing fields are the caller's to default. */
|
|
121
|
+
export function getServiceConfig(chain: AppChain): ToolboxServiceConfig {
|
|
122
|
+
if (current === null) throw new Error(NOT_CONFIGURED)
|
|
123
|
+
return current.services[chain] ?? {}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Test-only: drop the installed configuration. */
|
|
127
|
+
export function resetToolboxConfig(): void {
|
|
128
|
+
current = null
|
|
129
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"core",
|
|
27
27
|
"ui",
|
|
28
|
-
"assets"
|
|
28
|
+
"assets",
|
|
29
|
+
"CHANGELOG.md"
|
|
29
30
|
],
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"@bsv/air-gap": "^0.1.1",
|
|
@@ -93,7 +93,9 @@ type ParseResult = { params: PairingParams; error: null } | { params: null; erro
|
|
|
93
93
|
function parsePairingUri(raw: string): ParseResult {
|
|
94
94
|
try {
|
|
95
95
|
const url = new URL(raw)
|
|
96
|
-
if (url.protocol !== 'bsv-wallet:'
|
|
96
|
+
if (url.protocol !== 'bsv-wallet:' && url.protocol !== 'bsv-browser:') {
|
|
97
|
+
return { params: null, error: 'Not a bsv-wallet:// or bsv-browser:// URI' }
|
|
98
|
+
}
|
|
97
99
|
|
|
98
100
|
const g = (k: string) => url.searchParams.get(k) ?? ''
|
|
99
101
|
const topic = g('topic')
|
|
@@ -163,7 +165,15 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
163
165
|
// Auto-connect when navigated here with deep link pairing params
|
|
164
166
|
useEffect(() => {
|
|
165
167
|
if (!deepLinkParams.topic || !managers.permissionsManager) return
|
|
166
|
-
const
|
|
168
|
+
const query = new URLSearchParams({
|
|
169
|
+
topic: deepLinkParams.topic,
|
|
170
|
+
backendIdentityKey: deepLinkParams.backendIdentityKey ?? '',
|
|
171
|
+
protocolID: deepLinkParams.protocolID ?? '',
|
|
172
|
+
origin: deepLinkParams.origin ?? '',
|
|
173
|
+
expiry: deepLinkParams.expiry ?? '',
|
|
174
|
+
sig: deepLinkParams.sig ?? ''
|
|
175
|
+
})
|
|
176
|
+
const uri = `bsv-wallet://pair?${query}`
|
|
167
177
|
handleScan(uri)
|
|
168
178
|
}, [deepLinkParams.topic, managers.permissionsManager]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
169
179
|
|
|
@@ -24,17 +24,15 @@ import {
|
|
|
24
24
|
satoshisPerFiatUnit,
|
|
25
25
|
ExchangeRateContext,
|
|
26
26
|
DISPLAY_CURRENCY_OPTIONS,
|
|
27
|
-
recordBackupAttestation,
|
|
28
27
|
isBackupPushEnabled,
|
|
29
28
|
setBackupPushEnabled,
|
|
30
29
|
BACKUP_CHAINS,
|
|
31
30
|
eraseRemoteBackup,
|
|
32
31
|
recoverMnemonicWallet,
|
|
33
32
|
TaskBackupPush,
|
|
34
|
-
DEFAULT_BACKUP_URL,
|
|
35
33
|
setMockDriverEnabled,
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
NO_MESSAGE_BOX,
|
|
35
|
+
getBackupUrl
|
|
38
36
|
} from '@bsv/expo-wallet-toolbox'
|
|
39
37
|
|
|
40
38
|
/**
|
|
@@ -68,7 +66,6 @@ import { showToast } from '../components/ui/Toast'
|
|
|
68
66
|
import { PrivateKey } from '@bsv/sdk'
|
|
69
67
|
import { exportAllWalletDatabases } from '../exportDatabases'
|
|
70
68
|
import { importWalletDatabase } from '../importDatabases'
|
|
71
|
-
import { printRecoveryShares } from '../printRecoveryShares'
|
|
72
69
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
73
70
|
|
|
74
71
|
/**
|
|
@@ -108,29 +105,13 @@ function loadExpoRouter(): ExpoRouterModule {
|
|
|
108
105
|
return expoRouterMod
|
|
109
106
|
}
|
|
110
107
|
|
|
111
|
-
/**
|
|
112
|
-
* @react-native-clipboard/clipboard reaches for its native TurboModule at
|
|
113
|
-
* import time (`TurboModuleRegistry.getEnforcing`), which throws under Jest
|
|
114
|
-
* (no native binary registered there) even though the module itself
|
|
115
|
-
* transforms fine. Required lazily, only when a handler actually copies
|
|
116
|
-
* something, so importing the `ui` barrel never touches the native module.
|
|
117
|
-
* Same pattern as WalletHomeScreen.tsx's lazy clipboard load.
|
|
118
|
-
*/
|
|
119
|
-
type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
|
|
120
|
-
let clipboardModule: ClipboardModule | undefined
|
|
121
|
-
function loadClipboard(): ClipboardModule {
|
|
122
|
-
if (!clipboardModule) {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
124
|
-
clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
|
|
125
|
-
}
|
|
126
|
-
return clipboardModule
|
|
127
|
-
}
|
|
128
|
-
|
|
129
108
|
export function WalletConfigScreen() {
|
|
130
109
|
const versionLabel = useMemo(() => appVersionLabel(), [])
|
|
131
110
|
const { t } = useTranslation()
|
|
132
111
|
const { colors } = useTheme()
|
|
133
|
-
const { router } = loadExpoRouter()
|
|
112
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
113
|
+
const { section } = useLocalSearchParams<{ section?: string }>()
|
|
114
|
+
const openBackup = section === 'backup'
|
|
134
115
|
const Ionicons = loadIonicons()
|
|
135
116
|
const {
|
|
136
117
|
managers,
|
|
@@ -146,8 +127,6 @@ export function WalletConfigScreen() {
|
|
|
146
127
|
const { getMnemonic, getRecoveredKey } = useLocalStorage()
|
|
147
128
|
const insets = useSafeAreaInsets()
|
|
148
129
|
|
|
149
|
-
const [isPrinting, setIsPrinting] = useState(false)
|
|
150
|
-
const [copiedMnemonic, setCopiedMnemonic] = useState(false)
|
|
151
130
|
const [switchingNetwork, setSwitchingNetwork] = useState(false)
|
|
152
131
|
const [networkExpanded, setNetworkExpanded] = useState(false)
|
|
153
132
|
const [isExporting, setIsExporting] = useState(false)
|
|
@@ -158,7 +137,10 @@ export function WalletConfigScreen() {
|
|
|
158
137
|
const [loggingOut, setLoggingOut] = useState(false)
|
|
159
138
|
const [storageBusy, setStorageBusy] = useState(false)
|
|
160
139
|
const [currencyExpanded, setCurrencyExpanded] = useState(false)
|
|
161
|
-
const [advancedExpanded, setAdvancedExpanded] = useState(
|
|
140
|
+
const [advancedExpanded, setAdvancedExpanded] = useState(openBackup)
|
|
141
|
+
const scrollRef = useRef<ScrollView>(null)
|
|
142
|
+
const [backupSectionY, setBackupSectionY] = useState<number | null>(null)
|
|
143
|
+
const scrolledToBackup = useRef(false)
|
|
162
144
|
const [thresholdExpanded, setThresholdExpanded] = useState(false)
|
|
163
145
|
const [thresholdSats, setThresholdSats] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
|
|
164
146
|
const [thresholdInput, setThresholdInput] = useState('')
|
|
@@ -167,11 +149,21 @@ export function WalletConfigScreen() {
|
|
|
167
149
|
const [arcTokenInput, setArcTokenInput] = useState('')
|
|
168
150
|
const [arcSaving, setArcSaving] = useState(false)
|
|
169
151
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
170
|
-
const { appName } = useContext(UserContext)
|
|
171
152
|
|
|
172
153
|
const currentCurrency = settings?.currency || 'BSV'
|
|
173
154
|
const messageBox = useMessageBoxConfig(t)
|
|
174
155
|
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (openBackup) setAdvancedExpanded(true)
|
|
158
|
+
else scrolledToBackup.current = false
|
|
159
|
+
}, [openBackup])
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!openBackup || backupSectionY === null || scrolledToBackup.current) return
|
|
163
|
+
scrollRef.current?.scrollTo({ y: backupSectionY, animated: false })
|
|
164
|
+
scrolledToBackup.current = true
|
|
165
|
+
}, [openBackup, backupSectionY])
|
|
166
|
+
|
|
175
167
|
// Load persisted auto-approve threshold
|
|
176
168
|
useEffect(() => {
|
|
177
169
|
AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY).then(v => {
|
|
@@ -265,7 +257,7 @@ export function WalletConfigScreen() {
|
|
|
265
257
|
// chain propagates — a partial erasure must never be reported as done.
|
|
266
258
|
let deleted = 0
|
|
267
259
|
for (const chain of BACKUP_CHAINS) {
|
|
268
|
-
deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl:
|
|
260
|
+
deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl: getBackupUrl() })).deleted
|
|
269
261
|
}
|
|
270
262
|
setBackupPushOn(false)
|
|
271
263
|
showToast(t('backup_erase_done', { count: deleted }), { type: 'success' })
|
|
@@ -378,61 +370,6 @@ export function WalletConfigScreen() {
|
|
|
378
370
|
})
|
|
379
371
|
}, [])
|
|
380
372
|
|
|
381
|
-
const handleCopyMnemonic = async () => {
|
|
382
|
-
try {
|
|
383
|
-
// Copy mnemonic if available, otherwise fall back to primary key hex
|
|
384
|
-
const mnemonic = await getMnemonic()
|
|
385
|
-
if (mnemonic) {
|
|
386
|
-
loadClipboard().setString(mnemonic)
|
|
387
|
-
} else {
|
|
388
|
-
const wif = await getRecoveredKey()
|
|
389
|
-
if (!wif) return
|
|
390
|
-
loadClipboard().setString(PrivateKey.fromWif(wif).toHex())
|
|
391
|
-
}
|
|
392
|
-
setCopiedMnemonic(true)
|
|
393
|
-
setTimeout(() => setCopiedMnemonic(false), 2000)
|
|
394
|
-
} catch (error) {
|
|
395
|
-
console.error('Error retrieving recovery key:', error)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const handlePrintRecoveryShares = async () => {
|
|
400
|
-
if (isPrinting) return
|
|
401
|
-
setIsPrinting(true)
|
|
402
|
-
try {
|
|
403
|
-
const result = await printRecoveryShares({
|
|
404
|
-
mnemonic: await getMnemonic(),
|
|
405
|
-
recoveredKeyWif: await getRecoveredKey(),
|
|
406
|
-
appName
|
|
407
|
-
})
|
|
408
|
-
if (result.ok) {
|
|
409
|
-
// A resolved print sheet from Settings is the same genuine backup
|
|
410
|
-
// EnrollWizard records — the other route to satisfying the vault's
|
|
411
|
-
// backup prerequisite — so it records the same attestation, through
|
|
412
|
-
// the same writer.
|
|
413
|
-
//
|
|
414
|
-
// A failure here must be visible. The paper is real and correct; only
|
|
415
|
-
// the record is missing. Staying silent would send the user away
|
|
416
|
-
// believing they are covered, and the vault would refuse every deposit
|
|
417
|
-
// later with nothing on screen connecting the two.
|
|
418
|
-
if (!(await recordBackupAttestation(managers?.permissionsManager, adminOriginator, 'shares'))) {
|
|
419
|
-
showToast(t('vault_backup_attest_failed_printed'), { type: 'error' })
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
showToast(
|
|
423
|
-
result.reason === 'unsupported-word-count'
|
|
424
|
-
? t('vault_shares_word_count')
|
|
425
|
-
: 'Unable to access wallet key. Please authenticate and try again.',
|
|
426
|
-
{ type: 'error' }
|
|
427
|
-
)
|
|
428
|
-
}
|
|
429
|
-
} catch (error: any) {
|
|
430
|
-
console.info('[WalletConfig] Print recovery shares did not complete:', error?.message)
|
|
431
|
-
} finally {
|
|
432
|
-
setIsPrinting(false)
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
373
|
const handleExportData = async () => {
|
|
437
374
|
if (isExporting) return
|
|
438
375
|
setIsExporting(true)
|
|
@@ -545,7 +482,7 @@ export function WalletConfigScreen() {
|
|
|
545
482
|
<Text style={[localStyles.headerTitle, { color: colors.textPrimary }]}>{t('settings')}</Text>
|
|
546
483
|
<View style={localStyles.headerBack} />
|
|
547
484
|
</View>
|
|
548
|
-
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
485
|
+
<ScrollView ref={scrollRef} style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
549
486
|
{/* ── Essentials ──
|
|
550
487
|
The rows a holder reaches for without being told to: what their money
|
|
551
488
|
is denominated in, how to hand an app access, and the two ways out of
|
|
@@ -845,6 +782,7 @@ export function WalletConfigScreen() {
|
|
|
845
782
|
</GroupedSection>
|
|
846
783
|
|
|
847
784
|
{/* ── Data & Security ── */}
|
|
785
|
+
<View onLayout={event => setBackupSectionY(event.nativeEvent.layout.y)}>
|
|
848
786
|
<GroupedSection header={t('data_and_security')}>
|
|
849
787
|
{/* Vault's primary entry lives on the wallet menu (below Payments).
|
|
850
788
|
The DEV mock toggle stays here. */}
|
|
@@ -862,31 +800,11 @@ export function WalletConfigScreen() {
|
|
|
862
800
|
}}
|
|
863
801
|
/>
|
|
864
802
|
)}
|
|
865
|
-
{/* Both are recovery material rather than everyday controls, so
|
|
866
|
-
they sit with the rest of the data-and-security rows. */}
|
|
867
803
|
<ListRow
|
|
868
|
-
label={t('
|
|
804
|
+
label={t('backup_wallet_keys', { defaultValue: 'Backup Wallet Keys' })}
|
|
869
805
|
icon="key-outline"
|
|
870
806
|
iconColor="#CC8400"
|
|
871
|
-
onPress={
|
|
872
|
-
showChevron={false}
|
|
873
|
-
trailing={
|
|
874
|
-
<TouchableOpacity onPress={handleCopyMnemonic} style={{ padding: spacing.xs }}>
|
|
875
|
-
<Ionicons
|
|
876
|
-
name={copiedMnemonic ? 'checkmark' : 'copy-outline'}
|
|
877
|
-
size={18}
|
|
878
|
-
color={copiedMnemonic ? colors.success : colors.textSecondary}
|
|
879
|
-
/>
|
|
880
|
-
</TouchableOpacity>
|
|
881
|
-
}
|
|
882
|
-
/>
|
|
883
|
-
<ListRow
|
|
884
|
-
label={t('print_recovery_keys')}
|
|
885
|
-
icon="print-outline"
|
|
886
|
-
iconColor="#5856D6"
|
|
887
|
-
onPress={handlePrintRecoveryShares}
|
|
888
|
-
showChevron={false}
|
|
889
|
-
trailing={isPrinting ? <ActivityIndicator size="small" /> : undefined}
|
|
807
|
+
onPress={() => router.push('/auth/mnemonic?flow=backup')}
|
|
890
808
|
/>
|
|
891
809
|
<ListRow
|
|
892
810
|
label={t('storage_row')}
|
|
@@ -920,12 +838,13 @@ export function WalletConfigScreen() {
|
|
|
920
838
|
isLast
|
|
921
839
|
/>
|
|
922
840
|
</GroupedSection>
|
|
841
|
+
</View>
|
|
923
842
|
|
|
924
843
|
{/* ── Private backup ──
|
|
925
844
|
Its own section purely so the footer can carry the disclosure: the app sends an
|
|
926
845
|
encrypted copy of the wallet database to a BSVA-operated server by default, and
|
|
927
846
|
that deserves saying out loud rather than burying in a row label. */}
|
|
928
|
-
{
|
|
847
|
+
{getBackupUrl() !== '' && (
|
|
929
848
|
<GroupedSection header={t('backup_push_section')} footer={t('backup_push_disclosure')}>
|
|
930
849
|
<ListRow
|
|
931
850
|
label={t('backup_push_toggle')}
|