@bsv/expo-wallet-toolbox 0.15.2 → 0.16.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 +158 -0
- package/core/backup/appData.ts +5 -1
- package/core/backup/codec.ts +9 -3
- package/core/backup/contactsBackup.ts +145 -0
- package/core/backup/push.ts +14 -0
- package/core/backup/restoreOnImport.ts +15 -0
- package/core/contacts/contactsStore.ts +47 -3
- package/core/context/LocalStorageProvider.tsx +3 -1
- package/core/context/WalletContext.tsx +5 -2
- package/core/context/startupPrewarm.ts +54 -0
- package/core/hooks/useConfirmationSound.ts +7 -0
- package/core/identity/handleRegistry/client.ts +2 -1
- package/core/identity/handleRegistry/profileKeys.ts +16 -0
- package/core/identity/handleRegistry/resolver.ts +2 -1
- package/core/identity/handleRegistry/rules.ts +7 -3
- package/core/index.ts +2 -1
- package/core/localpay/build.ts +4 -3
- package/core/localpay/session.ts +6 -0
- package/core/localpay/transport/select.ts +64 -3
- package/core/localpay/verify.ts +2 -1
- package/core/net/trimTrailingSlashes.ts +13 -0
- package/core/parsePeerPayURI.ts +25 -2
- package/core/pay/creditInbox.ts +31 -1
- package/core/pay/rails/address.ts +3 -2
- package/core/pay/rails/handle.ts +8 -2
- package/core/pay/rails/index.ts +6 -4
- package/core/pos/protocol.ts +172 -0
- package/core/profiles/removalProblems.ts +41 -0
- package/core/push/registration.ts +2 -1
- package/core/services/revokeConnection.ts +98 -0
- package/core/storage/schema/createTables.ts +24 -0
- package/core/toolboxConfig.ts +22 -4
- package/package.json +1 -1
- package/ui/components/pay/MessageBoxConfig.tsx +2 -1
- package/ui/components/pay/NearbyFlow.tsx +410 -7
- package/ui/exportTransactions.ts +26 -13
- package/ui/index.ts +2 -2
- package/ui/screens/ConnectionsScreen.tsx +8 -63
- package/ui/screens/ProfileScreen.tsx +2 -40
- package/ui/screens/WalletConfigScreen.tsx +57 -51
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to tell someone whose profile removal was refused or failed: the i18n
|
|
3
|
+
* keys of one paragraph per kind of reason (core/i18n/translations.tsx,
|
|
4
|
+
* profile_remove_*). Shared by every app's Profile screen so the copy can't
|
|
5
|
+
* drift from what core/profiles/removeProfile actually checks.
|
|
6
|
+
*/
|
|
7
|
+
import type { RemovalBlocker } from './assertProfileEmpty'
|
|
8
|
+
import type { ProfileRemovalCheck, RemoveProfileResult } from './removeProfile'
|
|
9
|
+
|
|
10
|
+
/** What can stand in the way of removing a profile, grouped the way the user is told about it. */
|
|
11
|
+
const FUNDS_BLOCKERS: RemovalBlocker[] = ['spendable-outputs', 'token-balance']
|
|
12
|
+
const PENDING_BLOCKERS: RemovalBlocker[] = [
|
|
13
|
+
'pending-transactions',
|
|
14
|
+
'offline-queue',
|
|
15
|
+
'token-settlements',
|
|
16
|
+
'localpay-pending',
|
|
17
|
+
'peerpay-outbox',
|
|
18
|
+
'inbox-pending'
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
export type RemovalProblem = Exclude<ProfileRemovalCheck, { kind: 'ok' }> | Exclude<RemoveProfileResult, { kind: 'removed' }>
|
|
22
|
+
|
|
23
|
+
/** The i18n keys that explain a refusal or failure, one paragraph per kind of reason. */
|
|
24
|
+
export function removalProblemKeys(problem: RemovalProblem): string[] {
|
|
25
|
+
if (problem.kind === 'refused')
|
|
26
|
+
return [problem.reason === 'offline' ? 'profile_remove_offline' : 'profile_remove_failed']
|
|
27
|
+
if (problem.kind === 'handle-failed') return ['profile_remove_failed_handle']
|
|
28
|
+
if (problem.kind === 'blocked') {
|
|
29
|
+
const keys: string[] = []
|
|
30
|
+
const has = (group: RemovalBlocker[]) => problem.reasons.some(r => group.includes(r))
|
|
31
|
+
if (has(FUNDS_BLOCKERS)) keys.push('profile_remove_blocked_funds')
|
|
32
|
+
if (has(PENDING_BLOCKERS)) keys.push('profile_remove_blocked_pending')
|
|
33
|
+
// Funds or pending activity in the databases of its other networks, which the open one never shows.
|
|
34
|
+
if (problem.reasons.includes('other-network')) keys.push('profile_remove_blocked_network')
|
|
35
|
+
// An unfinished handle write is the same thing to the user as a handle that would not release.
|
|
36
|
+
if (problem.reasons.includes('handle-journal')) keys.push('profile_remove_failed_handle')
|
|
37
|
+
if (problem.reasons.includes('check-failed')) keys.push('profile_remove_blocked_check')
|
|
38
|
+
if (keys.length > 0) return keys
|
|
39
|
+
}
|
|
40
|
+
return ['profile_remove_failed']
|
|
41
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
2
|
import type { PushAdapter } from './types'
|
|
3
|
+
import { trimTrailingSlashes } from '../net/trimTrailingSlashes'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* What this device has registered, per identity: a JSON map from identity key to
|
|
@@ -260,7 +261,7 @@ function unregisterUrl(host: string): string {
|
|
|
260
261
|
throw new TypeError('MessageBox host requires HTTPS except on localhost')
|
|
261
262
|
}
|
|
262
263
|
if (url.username || url.password || url.search || url.hash) throw new TypeError('MessageBox host is not a plain URL')
|
|
263
|
-
return `${url.origin}${url.pathname
|
|
264
|
+
return `${url.origin}${trimTrailingSlashes(url.pathname)}/unregisterDevice`
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
/**
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Signing a paired site out (Connections in the existing app, Settings →
|
|
2
|
+
// Sign-ins in the BitcoinSV app): this phone stops serving it at once, then
|
|
3
|
+
// tells it so over the relay (session_revoke), best effort. Moved out of
|
|
4
|
+
// ui/screens/ConnectionsScreen.tsx unchanged, so both screens revoke alike.
|
|
5
|
+
import { WalletClient } from '@bsv/sdk'
|
|
6
|
+
import * as SecureStore from 'expo-secure-store'
|
|
7
|
+
import { ADMIN_ORIGINATOR } from '../config'
|
|
8
|
+
import { capWalletArgs } from './capWalletArgs'
|
|
9
|
+
import { guardVaultAccess } from './vault/guard'
|
|
10
|
+
import { lastSeqKey } from '../context/WalletConnectionContext'
|
|
11
|
+
import connectionStore, { type Connection } from '../stores/ConnectionStore'
|
|
12
|
+
import {
|
|
13
|
+
buildRelayWebSocketUrl,
|
|
14
|
+
validateMobileIdentityKey,
|
|
15
|
+
validateRelayUrl,
|
|
16
|
+
validateStoredConnectionFields,
|
|
17
|
+
validateStoredConnectionSequence
|
|
18
|
+
} from './walletConnectionValidation'
|
|
19
|
+
|
|
20
|
+
/** What a caller may hand in instead (its own imports, so its tests' mocks apply). */
|
|
21
|
+
export interface RevokeDeps {
|
|
22
|
+
store: Pick<typeof connectionStore, 'setStatus'>
|
|
23
|
+
guard: typeof guardVaultAccess
|
|
24
|
+
cap: typeof capWalletArgs
|
|
25
|
+
adminOriginator: string
|
|
26
|
+
seqKey: typeof lastSeqKey
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULTS: RevokeDeps = {
|
|
30
|
+
store: connectionStore,
|
|
31
|
+
guard: guardVaultAccess,
|
|
32
|
+
cap: capWalletArgs,
|
|
33
|
+
adminOriginator: ADMIN_ORIGINATOR,
|
|
34
|
+
seqKey: lastSeqKey
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function revokeConnection(
|
|
38
|
+
conn: Connection,
|
|
39
|
+
permissionsManager: unknown,
|
|
40
|
+
live: { liveTopic?: string; disconnect: () => void },
|
|
41
|
+
deps: RevokeDeps = DEFAULTS
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
// XR-018: local revocation must not depend on the peer's cooperation, or
|
|
44
|
+
// on the best-effort session_revoke send below succeeding. If this is
|
|
45
|
+
// the provider's own live socket for this session, tear it down FIRST —
|
|
46
|
+
// that's the only thing that actually stops wireSocket's onmessage from
|
|
47
|
+
// continuing to dispatch privileged RPC methods to it.
|
|
48
|
+
if (live.liveTopic === conn.sessionId) live.disconnect()
|
|
49
|
+
deps.store.setStatus(conn.sessionId, 'disconnected')
|
|
50
|
+
|
|
51
|
+
if (!permissionsManager) return
|
|
52
|
+
try {
|
|
53
|
+
const validated = validateStoredConnectionFields(conn)
|
|
54
|
+
const relay = validateRelayUrl(conn.relay)
|
|
55
|
+
const storedSeq = await SecureStore.getItemAsync(deps.seqKey(validated.topic))
|
|
56
|
+
const initialSeq = validateStoredConnectionSequence(storedSeq)
|
|
57
|
+
const wallet = new WalletClient(
|
|
58
|
+
deps.cap(deps.guard(permissionsManager as any, deps.adminOriginator)),
|
|
59
|
+
validated.external.originator
|
|
60
|
+
)
|
|
61
|
+
const identityResult = await wallet.getPublicKey({ identityKey: true })
|
|
62
|
+
const currentMobileIdentityKey = validateMobileIdentityKey(identityResult.publicKey)
|
|
63
|
+
if (currentMobileIdentityKey !== validated.mobileIdentityKey) {
|
|
64
|
+
throw new Error('Stored connection belongs to a different wallet identity')
|
|
65
|
+
}
|
|
66
|
+
const ws = new WebSocket(buildRelayWebSocketUrl(relay, validated.topic))
|
|
67
|
+
|
|
68
|
+
ws.onopen = async () => {
|
|
69
|
+
try {
|
|
70
|
+
const seq = initialSeq + 1
|
|
71
|
+
const payload = JSON.stringify({
|
|
72
|
+
id: crypto.randomUUID(),
|
|
73
|
+
seq,
|
|
74
|
+
method: 'session_revoke',
|
|
75
|
+
params: {}
|
|
76
|
+
})
|
|
77
|
+
const plaintext = Array.from(new TextEncoder().encode(payload))
|
|
78
|
+
const { ciphertext } = await wallet.encrypt({
|
|
79
|
+
protocolID: validated.protocolID,
|
|
80
|
+
keyID: validated.topic,
|
|
81
|
+
counterparty: validated.backendIdentityKey,
|
|
82
|
+
plaintext
|
|
83
|
+
})
|
|
84
|
+
ws.send(
|
|
85
|
+
JSON.stringify({
|
|
86
|
+
topic: validated.topic,
|
|
87
|
+
ciphertext: Buffer.from(ciphertext).toString('base64url')
|
|
88
|
+
})
|
|
89
|
+
)
|
|
90
|
+
} finally {
|
|
91
|
+
ws.close()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
ws.onerror = () => ws.close()
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.warn('[connections] session_revoke failed:', e)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -394,6 +394,9 @@ export async function createTables(db: SQLiteDatabase): Promise<void> {
|
|
|
394
394
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_contacts_unique ON contacts(userId, identityKey);
|
|
395
395
|
CREATE INDEX IF NOT EXISTS idx_contacts_userId ON contacts(userId);
|
|
396
396
|
`)
|
|
397
|
+
// Favourites and soft remove (Bitcoin SV Wallet, decision 10): additive,
|
|
398
|
+
// with defaults, so an existing row reads back not-favourite and present.
|
|
399
|
+
await ensureContactsColumns(db)
|
|
397
400
|
|
|
398
401
|
await createMandalaSettlementTables(db)
|
|
399
402
|
}
|
|
@@ -570,6 +573,27 @@ const TRANSACTIONS_COLUMNS: { name: string; ddl: string }[] = [
|
|
|
570
573
|
}
|
|
571
574
|
]
|
|
572
575
|
|
|
576
|
+
/**
|
|
577
|
+
* The same doctrine for `contacts`: columns added after it shipped, each
|
|
578
|
+
* with a default that means "as before" (not a favourite, not removed), so
|
|
579
|
+
* the existing app, which never sets them, sees its address book unchanged.
|
|
580
|
+
*/
|
|
581
|
+
const CONTACTS_COLUMNS: { name: string; ddl: string }[] = [
|
|
582
|
+
{ name: 'favourite', ddl: 'ALTER TABLE contacts ADD COLUMN favourite INTEGER NOT NULL DEFAULT 0' },
|
|
583
|
+
{ name: 'removedAt', ddl: 'ALTER TABLE contacts ADD COLUMN removedAt TEXT' }
|
|
584
|
+
]
|
|
585
|
+
|
|
586
|
+
export async function ensureContactsColumns(db: {
|
|
587
|
+
getAllAsync(sql: string, params: BindValue[]): Promise<unknown[]>
|
|
588
|
+
execAsync(sql: string): Promise<unknown>
|
|
589
|
+
}): Promise<void> {
|
|
590
|
+
const info = (await db.getAllAsync('PRAGMA table_info(contacts)', [])) as { name: string }[]
|
|
591
|
+
const have = new Set(info.map(c => c.name))
|
|
592
|
+
for (const col of CONTACTS_COLUMNS) {
|
|
593
|
+
if (!have.has(col.name)) await db.execAsync(col.ddl)
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
573
597
|
export async function ensureTransactionsColumns(db: {
|
|
574
598
|
getAllAsync(sql: string, params: BindValue[]): Promise<unknown[]>
|
|
575
599
|
execAsync(sql: string): Promise<unknown>
|
package/core/toolboxConfig.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AppChain } from './config'
|
|
2
2
|
import type { PushAdapter } from './push/types'
|
|
3
|
+
import { trimTrailingSlashes } from './net/trimTrailingSlashes'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Service endpoints and API keys for one chain.
|
|
@@ -101,6 +102,13 @@ export interface ToolboxConfig {
|
|
|
101
102
|
* to Pay's recipient search.
|
|
102
103
|
*/
|
|
103
104
|
handleRegistry?: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
105
|
+
/**
|
|
106
|
+
* The shortest handle this host lets people register: 1, 2 or 3 characters
|
|
107
|
+
* (default 3). The rest of the format is fixed (a-z 0-9 . _ -, at most 32,
|
|
108
|
+
* starting and ending with a letter or digit). A host that lowers it must
|
|
109
|
+
* use a registry that accepts the shorter handles.
|
|
110
|
+
*/
|
|
111
|
+
handleMinLength?: 1 | 2 | 3
|
|
104
112
|
/**
|
|
105
113
|
* Release gate for the YubiKey vault (spec §0, D15). Default false: the home
|
|
106
114
|
* button and Settings row are hidden, the vault route shows "Not available
|
|
@@ -124,6 +132,7 @@ interface ResolvedConfig {
|
|
|
124
132
|
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
125
133
|
mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
126
134
|
handleRegistry: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
135
|
+
handleMinLength: 1 | 2 | 3
|
|
127
136
|
vaultEnabled: boolean
|
|
128
137
|
push: PushAdapter | undefined
|
|
129
138
|
}
|
|
@@ -163,7 +172,7 @@ export function isAllowedServiceOrigin(parsed: URL): boolean {
|
|
|
163
172
|
}
|
|
164
173
|
|
|
165
174
|
function normalizeBackupUrl(raw: string): string {
|
|
166
|
-
const trimmed = raw.trim()
|
|
175
|
+
const trimmed = trimTrailingSlashes(raw.trim())
|
|
167
176
|
if (trimmed === '') return ''
|
|
168
177
|
let parsed: URL
|
|
169
178
|
try {
|
|
@@ -203,11 +212,20 @@ export function configureToolbox(config: ToolboxConfig): void {
|
|
|
203
212
|
services: config.services ?? {},
|
|
204
213
|
mandala: config.mandala ?? {},
|
|
205
214
|
handleRegistry: config.handleRegistry ?? {},
|
|
215
|
+
handleMinLength: config.handleMinLength === 1 || config.handleMinLength === 2 ? config.handleMinLength : 3,
|
|
206
216
|
vaultEnabled: config.vaultEnabled === true,
|
|
207
217
|
push: config.push
|
|
208
218
|
}
|
|
209
219
|
}
|
|
210
220
|
|
|
221
|
+
/**
|
|
222
|
+
* The shortest registrable handle (3 unless the host lowered it). Readable
|
|
223
|
+
* before configuration, so pure format checks work in tests and early code.
|
|
224
|
+
*/
|
|
225
|
+
export function getHandleMinLength(): 1 | 2 | 3 {
|
|
226
|
+
return current?.handleMinLength ?? 3
|
|
227
|
+
}
|
|
228
|
+
|
|
211
229
|
/** True once `configureToolbox` has run. For hosts that want to assert their own ordering. */
|
|
212
230
|
export function isToolboxConfigured(): boolean {
|
|
213
231
|
return current !== null
|
|
@@ -246,9 +264,9 @@ const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
|
|
|
246
264
|
export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | undefined {
|
|
247
265
|
const entry = current?.mandala[chain]
|
|
248
266
|
if (!entry) return undefined
|
|
249
|
-
const overlayUrl = entry.overlayUrl?.trim()
|
|
267
|
+
const overlayUrl = trimTrailingSlashes(entry.overlayUrl?.trim() ?? '')
|
|
250
268
|
const overlayIdentityKey = entry.overlayIdentityKey?.trim() ?? ''
|
|
251
|
-
const messageBoxUrl = entry.messageBoxUrl?.trim()
|
|
269
|
+
const messageBoxUrl = trimTrailingSlashes(entry.messageBoxUrl?.trim() ?? '')
|
|
252
270
|
if (overlayUrl === '' || messageBoxUrl === '') return undefined
|
|
253
271
|
if (!COMPRESSED_KEY.test(overlayIdentityKey)) return undefined
|
|
254
272
|
// XR-065 (SEC2-074): neither URL had a scheme policy at all before this --
|
|
@@ -292,7 +310,7 @@ export function getHandleRegistryConfig(chain: AppChain): HandleRegistryConfig |
|
|
|
292
310
|
const entry = current?.handleRegistry[chain]
|
|
293
311
|
if (!entry) return undefined
|
|
294
312
|
const domain = entry.domain?.trim().toLowerCase() ?? ''
|
|
295
|
-
const url = entry.url?.trim()
|
|
313
|
+
const url = trimTrailingSlashes(entry.url?.trim() ?? '')
|
|
296
314
|
if (!REGISTRY_DOMAIN.test(domain) || url === '') return undefined
|
|
297
315
|
let parsed: URL
|
|
298
316
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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",
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
NO_MESSAGE_BOX
|
|
23
23
|
} from '@bsv/expo-wallet-toolbox'
|
|
24
24
|
import { profileScopedKey } from '../../../core/profiles/profileStore'
|
|
25
|
+
import { trimTrailingSlashes } from '../../../core/net/trimTrailingSlashes'
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
@@ -64,7 +65,7 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
|
|
|
64
65
|
|
|
65
66
|
const handleSave = useCallback(
|
|
66
67
|
async (input: string) => {
|
|
67
|
-
const trimmed = input.trim()
|
|
68
|
+
const trimmed = trimTrailingSlashes(input.trim())
|
|
68
69
|
if (!trimmed) {
|
|
69
70
|
showToast(t('enter_valid_url'), { type: 'error' })
|
|
70
71
|
return
|