@bsv/expo-wallet-toolbox 0.15.2 → 0.17.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 +199 -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/restore.ts +26 -4
- package/core/backup/restoreOnImport.ts +28 -4
- package/core/contacts/contactsStore.ts +47 -3
- package/core/context/LocalStorageProvider.tsx +3 -1
- package/core/context/WalletContext.tsx +256 -76
- package/core/context/startupPrewarm.ts +54 -0
- package/core/directpay/dialFailure.ts +56 -0
- package/core/directpay/index.ts +7 -0
- package/core/directpay/payFlow.ts +117 -0
- package/core/directpay/paymentKey.ts +16 -0
- package/core/directpay/settings.ts +253 -0
- package/core/directpay/status.ts +52 -0
- package/core/directpay/types.ts +128 -0
- package/core/hooks/useConfirmationSound.ts +7 -0
- package/core/i18n/translations.tsx +354 -12
- 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 +14 -2
- 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/discovery.ts +17 -8
- package/core/profiles/profileStore.ts +34 -7
- package/core/profiles/removalProblems.ts +41 -0
- package/core/push/registration.ts +2 -1
- package/core/services/callbackToken.ts +7 -0
- package/core/services/revokeConnection.ts +98 -0
- package/core/storage/schema/createTables.ts +24 -0
- package/core/toolboxConfig.ts +85 -5
- 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
|
/**
|
|
@@ -11,6 +11,13 @@ import { Hash, Utils, type KeyDeriver } from '@bsv/sdk'
|
|
|
11
11
|
* Instead derive a BRC-42 private key under a fixed protocol/keyID for
|
|
12
12
|
* counterparty 'self' and hash it. Deterministic per wallet build, but only
|
|
13
13
|
* this wallet's root key can compute it — unlike the public identity key.
|
|
14
|
+
*
|
|
15
|
+
* This derivation is shared with BSV Desktop (deriveArcadeCallbackToken in
|
|
16
|
+
* bsv-desktop src/lib/services/createServices.ts), so a wallet open in both
|
|
17
|
+
* apps hears one Arcade status stream. Change it in both or neither: the
|
|
18
|
+
* known-answer vectors in __tests__/services/callbackToken.test.ts are the
|
|
19
|
+
* same ones bsv-desktop's test/arcade.test.ts checks. The private key is
|
|
20
|
+
* hashed unpadded, so one with a leading zero byte hashes as 31 bytes.
|
|
14
21
|
*/
|
|
15
22
|
export function deriveCallbackToken(keyDeriver: Pick<KeyDeriver, 'derivePrivateKey'>): string {
|
|
16
23
|
const priv = keyDeriver.derivePrivateKey([2, 'arcade callback token'], '1', 'self')
|
|
@@ -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,7 @@
|
|
|
1
1
|
import type { AppChain } from './config'
|
|
2
2
|
import type { PushAdapter } from './push/types'
|
|
3
|
+
import { trimTrailingSlashes } from './net/trimTrailingSlashes'
|
|
4
|
+
import { isRelayUrl, isStunUrl } from './directpay/settings'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Service endpoints and API keys for one chain.
|
|
@@ -44,6 +46,35 @@ export interface HandleRegistryConfig {
|
|
|
44
46
|
url: string
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
/**
|
|
50
|
+
* What the host states about direct (push) payments, the live WebRTC link tried before the
|
|
51
|
+
* message box. Every field is optional, and the whole entry is: a host that states nothing
|
|
52
|
+
* here keeps today's behaviour. The package never imports a WebRTC implementation itself —
|
|
53
|
+
* the native module would have to be linked by every host that merely installs it — so the
|
|
54
|
+
* host that ships one passes it in.
|
|
55
|
+
*
|
|
56
|
+
* `relayUrl` and `stunUrls` are checked when the toolbox is configured, by the same rules as
|
|
57
|
+
* the user's own settings (`isRelayUrl`, `isStunUrl`). They are this build's defaults: they
|
|
58
|
+
* stand in for the built-in ones, and what the user saves in `DirectPaySettings` wins over both.
|
|
59
|
+
*/
|
|
60
|
+
export interface DirectPayHostConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Whether this build offers direct payments at all, as `vaultEnabled` gates the vault. The
|
|
63
|
+
* user's own receive switch is a separate setting (`DirectPaySettings.receiveEnabled`).
|
|
64
|
+
* Unset means off.
|
|
65
|
+
*/
|
|
66
|
+
enabled?: boolean
|
|
67
|
+
/** This build's signaling relay, `wss://` only, a host with no credentials. Unset means the built-in one. */
|
|
68
|
+
relayUrl?: string
|
|
69
|
+
/** This build's `stun:` / `stuns:` servers, as written (none is trimmed). Unset means the built-in ones. */
|
|
70
|
+
stunUrls?: string[]
|
|
71
|
+
/**
|
|
72
|
+
* The host's `RTCPeerConnection` constructor (e.g. from react-native-webrtc). Typed
|
|
73
|
+
* `unknown` because this package ships no WebRTC types and must not depend on any.
|
|
74
|
+
*/
|
|
75
|
+
RTCPeerConnection?: unknown
|
|
76
|
+
}
|
|
77
|
+
|
|
47
78
|
/**
|
|
48
79
|
* Runtime configuration supplied by the host app.
|
|
49
80
|
*
|
|
@@ -101,6 +132,13 @@ export interface ToolboxConfig {
|
|
|
101
132
|
* to Pay's recipient search.
|
|
102
133
|
*/
|
|
103
134
|
handleRegistry?: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
135
|
+
/**
|
|
136
|
+
* The shortest handle this host lets people register: 1, 2 or 3 characters
|
|
137
|
+
* (default 3). The rest of the format is fixed (a-z 0-9 . _ -, at most 32,
|
|
138
|
+
* starting and ending with a letter or digit). A host that lowers it must
|
|
139
|
+
* use a registry that accepts the shorter handles.
|
|
140
|
+
*/
|
|
141
|
+
handleMinLength?: 1 | 2 | 3
|
|
104
142
|
/**
|
|
105
143
|
* Release gate for the YubiKey vault (spec §0, D15). Default false: the home
|
|
106
144
|
* button and Settings row are hidden, the vault route shows "Not available
|
|
@@ -117,6 +155,11 @@ export interface ToolboxConfig {
|
|
|
117
155
|
* states it here, like the URLs above.
|
|
118
156
|
*/
|
|
119
157
|
push?: PushAdapter
|
|
158
|
+
/**
|
|
159
|
+
* Direct (push) payments. Optional, and unset by default: a host that omits it sees no
|
|
160
|
+
* change.
|
|
161
|
+
*/
|
|
162
|
+
directPay?: DirectPayHostConfig
|
|
120
163
|
}
|
|
121
164
|
|
|
122
165
|
interface ResolvedConfig {
|
|
@@ -124,8 +167,10 @@ interface ResolvedConfig {
|
|
|
124
167
|
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
125
168
|
mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
126
169
|
handleRegistry: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
170
|
+
handleMinLength: 1 | 2 | 3
|
|
127
171
|
vaultEnabled: boolean
|
|
128
172
|
push: PushAdapter | undefined
|
|
173
|
+
directPay: DirectPayHostConfig | undefined
|
|
129
174
|
}
|
|
130
175
|
|
|
131
176
|
let current: ResolvedConfig | null = null
|
|
@@ -163,7 +208,7 @@ export function isAllowedServiceOrigin(parsed: URL): boolean {
|
|
|
163
208
|
}
|
|
164
209
|
|
|
165
210
|
function normalizeBackupUrl(raw: string): string {
|
|
166
|
-
const trimmed = raw.trim()
|
|
211
|
+
const trimmed = trimTrailingSlashes(raw.trim())
|
|
167
212
|
if (trimmed === '') return ''
|
|
168
213
|
let parsed: URL
|
|
169
214
|
try {
|
|
@@ -188,6 +233,20 @@ function normalizeBackupUrl(raw: string): string {
|
|
|
188
233
|
return trimmed
|
|
189
234
|
}
|
|
190
235
|
|
|
236
|
+
/** Throws unless the host's direct pay addresses are acceptable; unset fields are fine. */
|
|
237
|
+
function checkDirectPayHostConfig(directPay: DirectPayHostConfig | undefined): void {
|
|
238
|
+
if (directPay === undefined) return
|
|
239
|
+
const { relayUrl, stunUrls } = directPay
|
|
240
|
+
if (relayUrl !== undefined && !(typeof relayUrl === 'string' && isRelayUrl(relayUrl))) {
|
|
241
|
+
throw new Error(`configureToolbox: directPay.relayUrl must be a wss:// address without credentials: ${relayUrl}`)
|
|
242
|
+
}
|
|
243
|
+
if (stunUrls !== undefined && !(Array.isArray(stunUrls) && stunUrls.every(url => isStunUrl(url)))) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`configureToolbox: directPay.stunUrls must be a list of stun: or stuns: addresses: ${JSON.stringify(stunUrls)}`
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
191
250
|
/**
|
|
192
251
|
* Install the host's runtime configuration. Call once, at app entry, before
|
|
193
252
|
* anything from this package renders or builds a wallet.
|
|
@@ -198,16 +257,27 @@ export function configureToolbox(config: ToolboxConfig): void {
|
|
|
198
257
|
if (config == null || !('backupUrl' in config)) {
|
|
199
258
|
throw new Error('configureToolbox: backupUrl is required. Pass null to disable backup.')
|
|
200
259
|
}
|
|
260
|
+
checkDirectPayHostConfig(config.directPay)
|
|
201
261
|
current = {
|
|
202
262
|
backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
|
|
203
263
|
services: config.services ?? {},
|
|
204
264
|
mandala: config.mandala ?? {},
|
|
205
265
|
handleRegistry: config.handleRegistry ?? {},
|
|
266
|
+
handleMinLength: config.handleMinLength === 1 || config.handleMinLength === 2 ? config.handleMinLength : 3,
|
|
206
267
|
vaultEnabled: config.vaultEnabled === true,
|
|
207
|
-
push: config.push
|
|
268
|
+
push: config.push,
|
|
269
|
+
directPay: config.directPay
|
|
208
270
|
}
|
|
209
271
|
}
|
|
210
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The shortest registrable handle (3 unless the host lowered it). Readable
|
|
275
|
+
* before configuration, so pure format checks work in tests and early code.
|
|
276
|
+
*/
|
|
277
|
+
export function getHandleMinLength(): 1 | 2 | 3 {
|
|
278
|
+
return current?.handleMinLength ?? 3
|
|
279
|
+
}
|
|
280
|
+
|
|
211
281
|
/** True once `configureToolbox` has run. For hosts that want to assert their own ordering. */
|
|
212
282
|
export function isToolboxConfigured(): boolean {
|
|
213
283
|
return current !== null
|
|
@@ -246,9 +316,9 @@ const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
|
|
|
246
316
|
export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | undefined {
|
|
247
317
|
const entry = current?.mandala[chain]
|
|
248
318
|
if (!entry) return undefined
|
|
249
|
-
const overlayUrl = entry.overlayUrl?.trim()
|
|
319
|
+
const overlayUrl = trimTrailingSlashes(entry.overlayUrl?.trim() ?? '')
|
|
250
320
|
const overlayIdentityKey = entry.overlayIdentityKey?.trim() ?? ''
|
|
251
|
-
const messageBoxUrl = entry.messageBoxUrl?.trim()
|
|
321
|
+
const messageBoxUrl = trimTrailingSlashes(entry.messageBoxUrl?.trim() ?? '')
|
|
252
322
|
if (overlayUrl === '' || messageBoxUrl === '') return undefined
|
|
253
323
|
if (!COMPRESSED_KEY.test(overlayIdentityKey)) return undefined
|
|
254
324
|
// XR-065 (SEC2-074): neither URL had a scheme policy at all before this --
|
|
@@ -292,7 +362,7 @@ export function getHandleRegistryConfig(chain: AppChain): HandleRegistryConfig |
|
|
|
292
362
|
const entry = current?.handleRegistry[chain]
|
|
293
363
|
if (!entry) return undefined
|
|
294
364
|
const domain = entry.domain?.trim().toLowerCase() ?? ''
|
|
295
|
-
const url = entry.url?.trim()
|
|
365
|
+
const url = trimTrailingSlashes(entry.url?.trim() ?? '')
|
|
296
366
|
if (!REGISTRY_DOMAIN.test(domain) || url === '') return undefined
|
|
297
367
|
let parsed: URL
|
|
298
368
|
try {
|
|
@@ -341,6 +411,16 @@ export function getPushAdapter(): PushAdapter | undefined {
|
|
|
341
411
|
return current?.push
|
|
342
412
|
}
|
|
343
413
|
|
|
414
|
+
/**
|
|
415
|
+
* What the host stated about direct payments, or undefined when it stated nothing.
|
|
416
|
+
*
|
|
417
|
+
* Deliberately NOT throwing when unconfigured, like `getPushAdapter`: it is read while
|
|
418
|
+
* building the wallet, and "unconfigured" must look like "not stated".
|
|
419
|
+
*/
|
|
420
|
+
export function getDirectPayConfig(): DirectPayHostConfig | undefined {
|
|
421
|
+
return current?.directPay
|
|
422
|
+
}
|
|
423
|
+
|
|
344
424
|
/**
|
|
345
425
|
* Whether the vault may be used on this network.
|
|
346
426
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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
|