@bsv/expo-wallet-toolbox 0.5.0 → 0.9.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 +2000 -0
- package/README.md +66 -1
- package/core/amountFormatHelpers.ts +258 -36
- package/core/backup/RemoteSyncReader.ts +133 -24
- package/core/backup/appData.ts +157 -0
- package/core/backup/client.ts +15 -1
- package/core/backup/codec.ts +149 -11
- package/core/backup/constants.ts +30 -1
- package/core/backup/cursor.ts +31 -2
- package/core/backup/push.ts +71 -5
- package/core/backup/restore.ts +104 -16
- package/core/backup/restoreOnImport.ts +94 -30
- package/core/backup/status.ts +13 -8
- package/core/config.tsx +12 -5
- package/core/constants.ts +14 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/ExchangeRateContext.tsx +34 -27
- package/core/context/LocalStorageProvider.tsx +43 -40
- package/core/context/UserContext.tsx +18 -7
- package/core/context/VaultContext.tsx +49 -2
- package/core/context/WalletConnectionContext.tsx +203 -11
- package/core/context/WalletContext.tsx +685 -171
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +99 -17
- package/core/headers/headerStore.ts +33 -14
- package/core/headers/syncHeaders.ts +12 -1
- package/core/i18n/translations.tsx +2186 -98
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +314 -0
- package/core/identity/handleRegistry/keyPinStore.ts +70 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +315 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +53 -5
- package/core/localpay/build.ts +225 -24
- package/core/localpay/pending.ts +110 -7
- package/core/localpay/pendingAbortAuthority.ts +95 -0
- package/core/localpay/pendingAborts.ts +266 -26
- package/core/localpay/session.ts +42 -17
- package/core/localpay/settlementAck.ts +10 -1
- package/core/localpay/transport/socket.ts +52 -3
- package/core/localpay/verify.ts +100 -10
- package/core/mandala/abortGuard.ts +96 -20
- package/core/mandala/createRuntime.ts +206 -33
- package/core/mandala/drain.ts +89 -11
- package/core/mandala/inboxPrehold.ts +186 -0
- package/core/mandala/permissionModule.ts +202 -20
- package/core/mandala/settlementStore.ts +24 -2
- package/core/mandala/types.ts +40 -5
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +15 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +15 -1
- package/core/monitor/TaskSendOffline.ts +15 -1
- package/core/net/online.ts +49 -0
- package/core/net/publicDestination.ts +91 -0
- package/core/net/validateArcUrl.ts +22 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +134 -13
- package/core/offline/payerHold.ts +100 -24
- package/core/offline/plan.ts +37 -8
- package/core/pay/beefRepair.ts +6 -2
- package/core/pay/damagedInbox.ts +24 -0
- package/core/pay/rails/address.ts +107 -12
- package/core/pay/rails/handle.ts +117 -22
- package/core/pay/rails/index.ts +45 -7
- package/core/pay/rails/nativeIntent.ts +61 -0
- package/core/pay/receiveHistory.ts +93 -0
- package/core/pay/recordProof.ts +21 -7
- package/core/pay/refreshProofGuard.ts +42 -1
- package/core/pay/watchlist.ts +5 -2
- package/core/peerpay/control.ts +17 -18
- package/core/peerpay/handleResendRequests.ts +58 -4
- package/core/peerpay/outbox.ts +3 -1
- package/core/recovery/backupMaterial.ts +61 -0
- package/core/recovery/createWallet.ts +95 -0
- package/core/recovery/recoverWallet.ts +120 -0
- package/core/recovery/restoreWallet.ts +170 -0
- package/core/recovery/secret.ts +92 -0
- package/core/recovery/shareCollector.ts +71 -0
- package/core/recovery/shareParsing.ts +87 -0
- package/core/recovery/shares.ts +116 -0
- package/core/recovery/useRecoveryDeps.ts +70 -0
- package/core/services/arcTokenStorage.ts +52 -0
- package/core/services/arcadeBroadcastProvider.ts +233 -52
- package/core/services/autoApprovePolicy.ts +105 -0
- package/core/services/callbackToken.ts +19 -0
- package/core/services/capWalletArgs.ts +14 -2
- package/core/services/connectionAuthority.ts +98 -0
- package/core/services/exchangeRate.ts +36 -13
- package/core/services/externalOrigin.ts +16 -2
- package/core/services/secrets/kek.ts +126 -29
- package/core/services/secrets/migration.ts +16 -4
- package/core/services/secrets/store.ts +42 -14
- package/core/services/vault/VaultKeyService.ts +228 -45
- package/core/services/vault/chainRecovery.ts +483 -0
- package/core/services/vault/driver.ts +9 -1
- package/core/services/vault/enrolledSerialRegistry.ts +150 -0
- package/core/services/vault/guard.ts +218 -32
- package/core/services/vault/hardwareLease.ts +19 -0
- package/core/services/vault/metaAuthority.ts +210 -0
- package/core/services/vault/pivReset.ts +64 -23
- package/core/services/vault/r1comb.ts +139 -3
- package/core/services/vault/session.ts +25 -4
- package/core/services/vault/transfers.ts +868 -172
- package/core/services/vault/types.ts +19 -4
- package/core/services/vault/vaultStore.ts +256 -29
- package/core/services/walletArgLimits.ts +45 -2
- package/core/services/walletConnectionValidation.ts +76 -6
- package/core/services/walletServiceConfig.ts +40 -27
- package/core/storage/StorageExpoSQLite.ts +88 -47
- package/core/storage/methods/findSql.ts +24 -2
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +2 -2
- package/core/storage/methods/offlineActions.ts +10 -1
- package/core/storage/methods/processOfflineActions.ts +117 -25
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/schema/createTables.ts +155 -2
- package/core/stores/ConnectionStore.ts +34 -0
- package/core/toolboxConfig.ts +104 -0
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletDbRegistry.ts +63 -0
- package/core/walletMonitor.ts +25 -4
- package/core/walletRepair/releaseStuckReservations.ts +72 -0
- package/core/walletRepair/shouldMarkUnspendable.ts +20 -0
- package/core/walletRepair/spenderConsumesOutpoint.ts +29 -0
- package/package.json +7 -7
- package/ui/activityFilter.ts +115 -0
- package/ui/backupShares.ts +26 -169
- package/ui/components/pay/AddressReceive.tsx +13 -6
- package/ui/components/pay/AssetPicker.tsx +30 -9
- package/ui/components/pay/MessageBoxConfig.tsx +16 -0
- package/ui/components/pay/NearbyFlow.tsx +480 -243
- package/ui/components/pay/PaymentSuccessOverlay.tsx +85 -10
- package/ui/components/pay/RecipientField.tsx +84 -70
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +827 -205
- package/ui/components/ui/AlertCard.tsx +38 -5
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +197 -66
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +61 -13
- package/ui/components/vault/vaultErrorCopy.ts +3 -1
- package/ui/components/wallet/ActivityRow.tsx +227 -123
- package/ui/components/wallet/AmountInput.tsx +26 -8
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +22 -2
- package/ui/components/wallet/Balance.tsx +42 -23
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +16 -3
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/exportTransactions.ts +36 -4
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +25 -2
- package/ui/hooks/useMandala.ts +18 -1
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/importDatabases.ts +339 -24
- package/ui/index.ts +33 -2
- package/ui/isImageUrl.ts +6 -0
- package/ui/printRecoveryShares.ts +9 -10
- package/ui/recoveryPrompts.ts +91 -0
- package/ui/resolveIdentity.ts +31 -9
- package/ui/screens/ConnectionsScreen.tsx +86 -19
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +256 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +74 -2
- package/ui/screens/PayScreen.tsx +20 -7
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +10 -4
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +100 -5
- package/ui/screens/VaultScreen.tsx +410 -61
- package/ui/screens/VaultTransferScreen.tsx +59 -7
- package/ui/screens/WalletCheckScreen.tsx +17 -6
- package/ui/screens/WalletConfigScreen.tsx +124 -28
- package/ui/screens/WalletHomeScreen.tsx +640 -104
- package/ui/screens/detailActionKeys.ts +55 -0
- package/ui/tokenFormat.ts +44 -4
- package/ui/tokenStatus.ts +21 -0
- package/ui/txStatus.ts +48 -5
- package/core/storage/LocalStorageAdapter.ts +0 -58
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* New Contact — four ways in: a scanned or deep-linked identity key (QR scan
|
|
3
|
+
* on the Contacts header, or `bsv-wallet://contact/add?identityKey=`), a
|
|
4
|
+
* network search hit on Contacts (`?source=search`), the "Save as a contact"
|
|
5
|
+
* offer on a payment's success screen (`?identityKey=` and `?name=` both
|
|
6
|
+
* prefilled, `?source=pay`), or the plain "New Contact" button at the bottom
|
|
7
|
+
* of the Contacts list (2026-09-18) — the only path with no identity key
|
|
8
|
+
* yet, where the Identifier row itself becomes an editable paste field.
|
|
9
|
+
*
|
|
10
|
+
* Any past activity with the key is shown below the form, so you can see who
|
|
11
|
+
* you are about to save.
|
|
12
|
+
*/
|
|
13
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
14
|
+
import { I18nManager, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native'
|
|
15
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
16
|
+
import { useTranslation } from 'react-i18next'
|
|
17
|
+
import { useTheme, spacing, radii, typography, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
18
|
+
import { GroupedSection } from '../components/ui/GroupedList'
|
|
19
|
+
import PressableScale from '../components/ui/PressableScale'
|
|
20
|
+
import { showToast } from '../components/ui/Toast'
|
|
21
|
+
import ContactSigil from '../components/wallet/ContactSigil'
|
|
22
|
+
import ContactActivityList from '../components/wallet/ContactActivityList'
|
|
23
|
+
import IdentifierRow from '../components/wallet/IdentifierRow'
|
|
24
|
+
import { useContactsStore } from '../hooks/useContactsStore'
|
|
25
|
+
import { abbreviateKey } from '../../core/pay/counterparty'
|
|
26
|
+
import { isCompressedIdentityKey } from '../../core/identity/contactLink'
|
|
27
|
+
import { getHandleRegistryConfig } from '../../core/toolboxConfig'
|
|
28
|
+
import { parsePaymail } from '../../core/identity/handleRegistry/rules'
|
|
29
|
+
import { createHandleRegistryClient } from '../../core/identity/handleRegistry/client'
|
|
30
|
+
import { getContactActivity, type ContactActivityItem } from '../../core/contacts/contactActivity'
|
|
31
|
+
import type { ContactSource } from '../../core/contacts/contactsStore'
|
|
32
|
+
|
|
33
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
34
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
35
|
+
function loadIonicons(): IoniconsComponent {
|
|
36
|
+
if (!ioniconsComponent) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
39
|
+
}
|
|
40
|
+
return ioniconsComponent
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
44
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
45
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
46
|
+
if (!expoRouterMod) {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
48
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
49
|
+
}
|
|
50
|
+
return expoRouterMod
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function firstParam(v: string | string[] | undefined): string | undefined {
|
|
54
|
+
return Array.isArray(v) ? v[0] : v
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const SOURCES: ReadonlySet<string> = new Set<ContactSource>(['manual', 'qr', 'pay', 'search'])
|
|
58
|
+
|
|
59
|
+
export function NewContactScreen() {
|
|
60
|
+
const { t } = useTranslation()
|
|
61
|
+
const { colors } = useTheme()
|
|
62
|
+
const insets = useSafeAreaInsets()
|
|
63
|
+
const Ionicons = loadIonicons()
|
|
64
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
65
|
+
const { walletUserId, managers, adminOriginator, storage, selectedNetwork } = useWallet()
|
|
66
|
+
const store = useContactsStore()
|
|
67
|
+
const params = useLocalSearchParams<{
|
|
68
|
+
identityKey?: string | string[]
|
|
69
|
+
name?: string | string[]
|
|
70
|
+
handle?: string | string[]
|
|
71
|
+
source?: string | string[]
|
|
72
|
+
}>()
|
|
73
|
+
const prefilledIdentityKey = (firstParam(params.identityKey) ?? '').toLowerCase()
|
|
74
|
+
/**
|
|
75
|
+
* The registry's `handle@domain`, when the caller had one: Pay's "Save as a
|
|
76
|
+
* contact" is the only route that knows it today — the Contacts search tier
|
|
77
|
+
* is an overlay result, which carries no paymail — and it is the only way
|
|
78
|
+
* this column is ever populated.
|
|
79
|
+
*
|
|
80
|
+
* Validated, not trusted. `/contact/add` is a deep-linkable expo-router
|
|
81
|
+
* route, so this param is a string from outside the app — and what it becomes
|
|
82
|
+
* is rendered on ContactScreen under a shield and the words "only they can
|
|
83
|
+
* change it". Anything that is not a paymail is not a handle.
|
|
84
|
+
*
|
|
85
|
+
* Passing `parsePaymail` is only the SHAPE, though, and shape says nothing
|
|
86
|
+
* about whose handle it is: a phishing link can assert any well-formed
|
|
87
|
+
* paymail for any identity key. The registry decides that, below.
|
|
88
|
+
*/
|
|
89
|
+
const parsedHandle = parsePaymail(firstParam(params.handle) ?? '')
|
|
90
|
+
const prefilledHandle = parsedHandle ? `${parsedHandle.handle}@${parsedHandle.domain}` : ''
|
|
91
|
+
const handleDomain = parsedHandle?.domain
|
|
92
|
+
const sourceParam = firstParam(params.source)
|
|
93
|
+
const source: ContactSource = sourceParam && SOURCES.has(sourceParam) ? (sourceParam as ContactSource) : 'qr'
|
|
94
|
+
// The only path with no identity key yet: the plain "New Contact" button on
|
|
95
|
+
// the Contacts list. Everywhere else (scan, deep link, search, the payment
|
|
96
|
+
// success screen) arrives with one already known, and the row stays read-only.
|
|
97
|
+
const manualEntry = prefilledIdentityKey === ''
|
|
98
|
+
|
|
99
|
+
const [name, setName] = useState(firstParam(params.name) ?? '')
|
|
100
|
+
const [identifierInput, setIdentifierInput] = useState('')
|
|
101
|
+
const [saving, setSaving] = useState(false)
|
|
102
|
+
const [activity, setActivity] = useState<ContactActivityItem[]>([])
|
|
103
|
+
|
|
104
|
+
const identityKey = manualEntry ? identifierInput.trim().toLowerCase() : prefilledIdentityKey
|
|
105
|
+
const identityKeyValid = isCompressedIdentityKey(identityKey)
|
|
106
|
+
const nameValid = name.trim().length > 0
|
|
107
|
+
|
|
108
|
+
/** Two strings rather than the config object, which is rebuilt every call. */
|
|
109
|
+
const registry = getHandleRegistryConfig(selectedNetwork)
|
|
110
|
+
const registryDomain = registry?.domain
|
|
111
|
+
const registryUrl = registry?.url
|
|
112
|
+
const registryClient = useMemo(
|
|
113
|
+
() =>
|
|
114
|
+
registryDomain && registryUrl
|
|
115
|
+
? createHandleRegistryClient({ pinned: { domain: registryDomain, url: registryUrl } })
|
|
116
|
+
: null,
|
|
117
|
+
[registryDomain, registryUrl]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The handle this key actually holds, as the registry answers for it — the
|
|
122
|
+
* only version of the param worth storing.
|
|
123
|
+
*
|
|
124
|
+
* `cachedHandle` is drawn on ContactScreen under a shield reading "only they
|
|
125
|
+
* can change it", and it is the line Pay's contacts tier offers this person
|
|
126
|
+
* by. An asserted string is neither of those things, so it is checked against
|
|
127
|
+
* the key it claims before it is written, on the domain it names (the same
|
|
128
|
+
* domain ContactScreen's own refresh asks). An unproven one is simply not a
|
|
129
|
+
* handle here: that refresh fills the column in later if it is real, and no
|
|
130
|
+
* screen has to un-say a shield in the meantime.
|
|
131
|
+
*/
|
|
132
|
+
const [provenFor, setProvenFor] = useState<{ identityKey: string; handle: string } | null>(null)
|
|
133
|
+
// Held against the pair it was proven for, rather than reset when either
|
|
134
|
+
// changes: the manual-entry field rewrites `identityKey` on every keystroke,
|
|
135
|
+
// and a proof carried over to the next key would be exactly the claim this
|
|
136
|
+
// is here to refuse.
|
|
137
|
+
const verifiedHandle =
|
|
138
|
+
provenFor?.identityKey === identityKey && provenFor?.handle === prefilledHandle ? prefilledHandle : ''
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!registryClient || !prefilledHandle || !identityKeyValid) return
|
|
141
|
+
let cancelled = false
|
|
142
|
+
void registryClient.lookupProfile(identityKey, handleDomain).then(seen => {
|
|
143
|
+
if (cancelled || seen.kind !== 'found' || seen.profile.paymail !== prefilledHandle) return
|
|
144
|
+
setProvenFor({ identityKey, handle: prefilledHandle })
|
|
145
|
+
})
|
|
146
|
+
return () => {
|
|
147
|
+
cancelled = true
|
|
148
|
+
}
|
|
149
|
+
}, [registryClient, prefilledHandle, handleDomain, identityKey, identityKeyValid])
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (!identityKeyValid) {
|
|
153
|
+
setActivity([])
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
let cancelled = false
|
|
157
|
+
void getContactActivity({
|
|
158
|
+
wallet: managers?.permissionsManager as never,
|
|
159
|
+
adminOriginator,
|
|
160
|
+
settlementsDb: storage?.sqliteDb as never,
|
|
161
|
+
identityKey
|
|
162
|
+
}).then(items => {
|
|
163
|
+
if (!cancelled) setActivity(items)
|
|
164
|
+
})
|
|
165
|
+
return () => {
|
|
166
|
+
cancelled = true
|
|
167
|
+
}
|
|
168
|
+
}, [identityKey, identityKeyValid, managers, adminOriginator, storage])
|
|
169
|
+
|
|
170
|
+
const onSave = useCallback(async () => {
|
|
171
|
+
if (!store || walletUserId === null || !identityKeyValid || !nameValid) return
|
|
172
|
+
setSaving(true)
|
|
173
|
+
try {
|
|
174
|
+
await store.createContact({
|
|
175
|
+
userId: walletUserId,
|
|
176
|
+
identityKey,
|
|
177
|
+
name: name.trim(),
|
|
178
|
+
...(verifiedHandle ? { cachedHandle: verifiedHandle } : {}),
|
|
179
|
+
source: manualEntry ? 'manual' : source
|
|
180
|
+
})
|
|
181
|
+
showToast(t('contact_saved'), { type: 'success' })
|
|
182
|
+
router.replace({ pathname: '/contact', params: { identityKey } } as never)
|
|
183
|
+
} finally {
|
|
184
|
+
setSaving(false)
|
|
185
|
+
}
|
|
186
|
+
}, [
|
|
187
|
+
store,
|
|
188
|
+
walletUserId,
|
|
189
|
+
identityKey,
|
|
190
|
+
identityKeyValid,
|
|
191
|
+
name,
|
|
192
|
+
nameValid,
|
|
193
|
+
verifiedHandle,
|
|
194
|
+
manualEntry,
|
|
195
|
+
source,
|
|
196
|
+
router,
|
|
197
|
+
t
|
|
198
|
+
])
|
|
199
|
+
|
|
200
|
+
const canSave = nameValid && identityKeyValid && !saving
|
|
201
|
+
const showIdentifierError = manualEntry && identifierInput.trim().length > 0 && !identityKeyValid
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
|
|
205
|
+
<View style={[styles.header, { borderBottomColor: colors.separator }]}>
|
|
206
|
+
<PressableScale
|
|
207
|
+
onPress={() => router.back()}
|
|
208
|
+
haptic="tap"
|
|
209
|
+
style={styles.headerBtn}
|
|
210
|
+
accessibilityRole="button"
|
|
211
|
+
accessibilityLabel={t('go_back')}
|
|
212
|
+
>
|
|
213
|
+
<Ionicons
|
|
214
|
+
name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
|
|
215
|
+
size={24}
|
|
216
|
+
color={colors.textSecondary}
|
|
217
|
+
/>
|
|
218
|
+
</PressableScale>
|
|
219
|
+
<Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
220
|
+
{t('contact_new_title')}
|
|
221
|
+
</Text>
|
|
222
|
+
<View style={styles.headerBtn} />
|
|
223
|
+
</View>
|
|
224
|
+
|
|
225
|
+
<ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
|
|
226
|
+
<View style={styles.hero}>
|
|
227
|
+
<ContactSigil identityKey={identityKeyValid ? identityKey : '0'.repeat(66)} size={72} radius={24} />
|
|
228
|
+
<Text style={[styles.heroKey, { color: identityKeyValid ? colors.textPrimary : colors.textTertiary }]}>
|
|
229
|
+
{identityKeyValid ? abbreviateKey(identityKey) : t('contact_identifier')}
|
|
230
|
+
</Text>
|
|
231
|
+
{/* Only once the registry has confirmed it belongs to this key: a
|
|
232
|
+
handle shown here is the same claim the shield makes on the
|
|
233
|
+
screen this route replaces itself with. */}
|
|
234
|
+
<Text style={[styles.heroCaption, { color: colors.textTertiary }]}>
|
|
235
|
+
{verifiedHandle || t('contact_no_handle_registered')}
|
|
236
|
+
</Text>
|
|
237
|
+
</View>
|
|
238
|
+
|
|
239
|
+
<GroupedSection header={t('contact_name_section')} footer={t('contact_new_name_hint')}>
|
|
240
|
+
<View style={styles.nameRow}>
|
|
241
|
+
<View style={styles.nameLeading}>
|
|
242
|
+
<Ionicons name="pencil-outline" size={17} color={colors.textSecondary} />
|
|
243
|
+
</View>
|
|
244
|
+
<TextInput
|
|
245
|
+
value={name}
|
|
246
|
+
onChangeText={setName}
|
|
247
|
+
placeholder={t('contact_new_title')}
|
|
248
|
+
placeholderTextColor={colors.textTertiary}
|
|
249
|
+
autoFocus={!manualEntry}
|
|
250
|
+
returnKeyType="done"
|
|
251
|
+
style={[styles.nameInput, { color: colors.textPrimary }]}
|
|
252
|
+
/>
|
|
253
|
+
</View>
|
|
254
|
+
</GroupedSection>
|
|
255
|
+
|
|
256
|
+
<GroupedSection
|
|
257
|
+
header={t('contact_identifier')}
|
|
258
|
+
footer={showIdentifierError ? t('contact_identifier_invalid') : undefined}
|
|
259
|
+
>
|
|
260
|
+
{manualEntry ? (
|
|
261
|
+
<TextInput
|
|
262
|
+
value={identifierInput}
|
|
263
|
+
onChangeText={setIdentifierInput}
|
|
264
|
+
placeholder={t('contact_identifier_placeholder')}
|
|
265
|
+
placeholderTextColor={colors.textTertiary}
|
|
266
|
+
autoCapitalize="none"
|
|
267
|
+
autoCorrect={false}
|
|
268
|
+
autoFocus
|
|
269
|
+
style={[styles.identifierInput, { color: showIdentifierError ? colors.error : colors.textPrimary }]}
|
|
270
|
+
/>
|
|
271
|
+
) : (
|
|
272
|
+
<IdentifierRow identityKey={identityKey} />
|
|
273
|
+
)}
|
|
274
|
+
</GroupedSection>
|
|
275
|
+
|
|
276
|
+
{activity.length > 0 && (
|
|
277
|
+
<>
|
|
278
|
+
<Text style={[styles.sectionTitle, { color: colors.textTertiary }]}>
|
|
279
|
+
{t('contact_activity').toUpperCase()}
|
|
280
|
+
</Text>
|
|
281
|
+
<ContactActivityList items={activity} identityKey={identityKey} />
|
|
282
|
+
</>
|
|
283
|
+
)}
|
|
284
|
+
</ScrollView>
|
|
285
|
+
|
|
286
|
+
<View style={[styles.footer, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]}>
|
|
287
|
+
<PressableScale
|
|
288
|
+
onPress={onSave}
|
|
289
|
+
disabled={!canSave}
|
|
290
|
+
haptic="confirm"
|
|
291
|
+
style={[styles.cta, { backgroundColor: canSave ? colors.accent : colors.fill }]}
|
|
292
|
+
accessibilityRole="button"
|
|
293
|
+
accessibilityState={{ disabled: !canSave }}
|
|
294
|
+
>
|
|
295
|
+
<Ionicons name="person-add-outline" size={18} color={canSave ? colors.textOnAccent : colors.textTertiary} />
|
|
296
|
+
<Text style={[styles.ctaText, { color: canSave ? colors.textOnAccent : colors.textTertiary }]}>
|
|
297
|
+
{t('contact_save')}
|
|
298
|
+
</Text>
|
|
299
|
+
</PressableScale>
|
|
300
|
+
</View>
|
|
301
|
+
</View>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export default NewContactScreen
|
|
306
|
+
|
|
307
|
+
const styles = StyleSheet.create({
|
|
308
|
+
container: { flex: 1 },
|
|
309
|
+
header: {
|
|
310
|
+
flexDirection: 'row',
|
|
311
|
+
alignItems: 'center',
|
|
312
|
+
justifyContent: 'space-between',
|
|
313
|
+
paddingHorizontal: spacing.sm,
|
|
314
|
+
paddingVertical: spacing.md,
|
|
315
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
316
|
+
},
|
|
317
|
+
headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
318
|
+
headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
|
|
319
|
+
content: { paddingTop: spacing.lg, paddingBottom: spacing.lg },
|
|
320
|
+
hero: {
|
|
321
|
+
alignItems: 'center',
|
|
322
|
+
gap: spacing.sm,
|
|
323
|
+
paddingHorizontal: spacing.xl,
|
|
324
|
+
paddingTop: spacing.sm,
|
|
325
|
+
paddingBottom: spacing.xl
|
|
326
|
+
},
|
|
327
|
+
heroKey: { fontSize: 18, lineHeight: 24, fontWeight: '700', fontFamily: 'monospace', marginTop: spacing.xs },
|
|
328
|
+
heroCaption: { ...typography.footnote },
|
|
329
|
+
nameRow: {
|
|
330
|
+
flexDirection: 'row',
|
|
331
|
+
alignItems: 'center',
|
|
332
|
+
minHeight: 52,
|
|
333
|
+
paddingLeft: spacing.xs,
|
|
334
|
+
paddingRight: spacing.lg
|
|
335
|
+
},
|
|
336
|
+
nameLeading: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
337
|
+
nameInput: { ...typography.body, flex: 1, minWidth: 0, paddingVertical: spacing.md, paddingHorizontal: 0 },
|
|
338
|
+
identifierInput: {
|
|
339
|
+
...typography.subhead,
|
|
340
|
+
fontFamily: 'monospace',
|
|
341
|
+
minHeight: 48,
|
|
342
|
+
paddingHorizontal: spacing.lg,
|
|
343
|
+
paddingVertical: spacing.md
|
|
344
|
+
},
|
|
345
|
+
sectionTitle: {
|
|
346
|
+
fontSize: 10.5,
|
|
347
|
+
fontWeight: '700',
|
|
348
|
+
letterSpacing: 1.3,
|
|
349
|
+
paddingHorizontal: spacing.xl,
|
|
350
|
+
paddingBottom: spacing.sm
|
|
351
|
+
},
|
|
352
|
+
footer: { paddingHorizontal: spacing.lg, paddingTop: spacing.sm },
|
|
353
|
+
cta: {
|
|
354
|
+
flexDirection: 'row',
|
|
355
|
+
alignItems: 'center',
|
|
356
|
+
justifyContent: 'center',
|
|
357
|
+
gap: spacing.sm,
|
|
358
|
+
paddingVertical: spacing.md + 2,
|
|
359
|
+
borderRadius: radii.md
|
|
360
|
+
},
|
|
361
|
+
ctaText: { ...typography.subhead, fontWeight: '600' }
|
|
362
|
+
})
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
SafeAreaView,
|
|
8
8
|
ActivityIndicator,
|
|
9
9
|
} from 'react-native'
|
|
10
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
10
11
|
import { WalletClient } from '@bsv/sdk'
|
|
11
12
|
import {
|
|
12
13
|
useWallet,
|
|
@@ -18,8 +19,13 @@ import {
|
|
|
18
19
|
guardVaultAccess,
|
|
19
20
|
capWalletArgs,
|
|
20
21
|
ADMIN_ORIGINATOR,
|
|
21
|
-
parseExternalOrigin
|
|
22
|
+
parseExternalOrigin,
|
|
23
|
+
connectionStore,
|
|
24
|
+
DEFAULT_AUTO_APPROVE_THRESHOLD,
|
|
25
|
+
AUTO_APPROVE_STORAGE_KEY,
|
|
26
|
+
AUTO_APPROVE_DAILY_CAP_SATS
|
|
22
27
|
} from '@bsv/expo-wallet-toolbox'
|
|
28
|
+
import { computeConnectionAuthorityTag } from '../../core/services/connectionAuthority'
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* expo-router is required lazily rather than imported at module scope: this
|
|
@@ -62,6 +68,21 @@ export function PairScreen() {
|
|
|
62
68
|
// Pre-connection validation error (before connect() is called)
|
|
63
69
|
const [preConnectError, setPreConnectError] = useState<string | null>(null)
|
|
64
70
|
|
|
71
|
+
// XR-023: the ONLY value ever shown to the user pre-approval must be the
|
|
72
|
+
// same validated/canonicalized origin handleApprove authorizes — never the
|
|
73
|
+
// raw, attacker-controlled route param. Set once validation below passes.
|
|
74
|
+
const [canonicalOrigin, setCanonicalOrigin] = useState<string | null>(null)
|
|
75
|
+
|
|
76
|
+
// XR-028: the standing auto-spend authority a paired origin gets was never
|
|
77
|
+
// disclosed at approval time. Read the SAME persisted threshold WalletContext
|
|
78
|
+
// reads for spendingAuthorizationCallback — 0/unset means auto-approve is off.
|
|
79
|
+
const [autoApproveThreshold, setAutoApproveThreshold] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY)
|
|
82
|
+
.then(v => { if (v !== null) setAutoApproveThreshold(Number(v) || 0) })
|
|
83
|
+
.catch(() => {})
|
|
84
|
+
}, [])
|
|
85
|
+
|
|
65
86
|
// Whether this mount is a reconnect (explicitly passed from connections screen)
|
|
66
87
|
const isReconnect = params.reconnect === 'true'
|
|
67
88
|
|
|
@@ -91,6 +112,15 @@ export function PairScreen() {
|
|
|
91
112
|
setPreConnectError('QR code has expired')
|
|
92
113
|
return
|
|
93
114
|
}
|
|
115
|
+
// Canonicalize BEFORE it is ever rendered — the same validator
|
|
116
|
+
// handleApprove uses, run up front instead of only at Approve time, so
|
|
117
|
+
// the displayed value and the authorized value are never different
|
|
118
|
+
// objects. An unparseable origin must never reach the Approve card.
|
|
119
|
+
try {
|
|
120
|
+
setCanonicalOrigin(parseExternalOrigin(origin).originator)
|
|
121
|
+
} catch (err) {
|
|
122
|
+
setPreConnectError(err instanceof Error ? err.message : 'Origin URL is not valid')
|
|
123
|
+
}
|
|
94
124
|
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
|
95
125
|
|
|
96
126
|
// Nav timer — start when leaving this screen, cancel when returning
|
|
@@ -114,6 +144,31 @@ export function PairScreen() {
|
|
|
114
144
|
capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)),
|
|
115
145
|
external.originator
|
|
116
146
|
)
|
|
147
|
+
// XR-027: stage a saved-pairing authority tag for the EXACT tuple the
|
|
148
|
+
// user is approving on this screen, BEFORE connect() ever runs — with
|
|
149
|
+
// an ADMIN-scoped wallet, never `wallet` above (that one is scoped to
|
|
150
|
+
// the peer's own originator and would let the peer mint this tag
|
|
151
|
+
// itself; see connectionAuthority.ts). connectionStore.add() (deep
|
|
152
|
+
// inside connect()'s websocket-open callback, which never sees an
|
|
153
|
+
// admin wallet) consumes the staged tag the moment it creates the
|
|
154
|
+
// record. A failure here must never block a pairing the user just
|
|
155
|
+
// explicitly approved — it only means this record starts out
|
|
156
|
+
// untagged, which reconnect treats as "needs re-approval" later,
|
|
157
|
+
// exactly like a tampered record; it is never a silent downgrade of
|
|
158
|
+
// trust for the live session being approved right now.
|
|
159
|
+
try {
|
|
160
|
+
const adminWallet = capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR))
|
|
161
|
+
const tag = await computeConnectionAuthorityTag(adminWallet, ADMIN_ORIGINATOR, {
|
|
162
|
+
origin: external.origin,
|
|
163
|
+
topic: params.topic,
|
|
164
|
+
protocolID: params.protocolID,
|
|
165
|
+
backendIdentityKey: params.backendIdentityKey,
|
|
166
|
+
})
|
|
167
|
+
connectionStore.stageAuthorityTag(params.topic, tag)
|
|
168
|
+
} catch (err) {
|
|
169
|
+
console.warn('[PairScreen] failed to compute connection authority tag', err)
|
|
170
|
+
connectionStore.discardStagedAuthorityTag(params.topic)
|
|
171
|
+
}
|
|
117
172
|
await connect({
|
|
118
173
|
topic: params.topic,
|
|
119
174
|
backendIdentityKey: params.backendIdentityKey,
|
|
@@ -172,13 +227,30 @@ export function PairScreen() {
|
|
|
172
227
|
<View style={styles.infoBox}>
|
|
173
228
|
<View style={styles.infoRow}>
|
|
174
229
|
<Text style={styles.infoLabel}>Origin</Text>
|
|
175
|
-
|
|
230
|
+
{/* ellipsizeMode="middle" (not RN's tail-truncating default)
|
|
231
|
+
keeps the registrable-domain suffix visible even for a long
|
|
232
|
+
attacker-chosen hostname designed to hide it behind a
|
|
233
|
+
trustworthy-looking prefix. */}
|
|
234
|
+
<Text style={styles.infoValue} numberOfLines={1} ellipsizeMode="middle">
|
|
235
|
+
{canonicalOrigin ?? ''}
|
|
236
|
+
</Text>
|
|
176
237
|
</View>
|
|
177
238
|
<View style={styles.divider} />
|
|
178
239
|
<View style={styles.infoRow}>
|
|
179
240
|
<Text style={styles.infoLabel}>Permissions</Text>
|
|
180
241
|
<Text style={styles.infoValue}>getPublicKey, listOutputs + more</Text>
|
|
181
242
|
</View>
|
|
243
|
+
{autoApproveThreshold > 0 && (
|
|
244
|
+
<>
|
|
245
|
+
<View style={styles.divider} />
|
|
246
|
+
<View style={styles.infoRow}>
|
|
247
|
+
<Text style={styles.infoLabel}>Auto-approve</Text>
|
|
248
|
+
<Text style={styles.infoValue}>
|
|
249
|
+
Up to {autoApproveThreshold.toLocaleString()} sats per request, {AUTO_APPROVE_DAILY_CAP_SATS.toLocaleString()} sats/24h total, without asking
|
|
250
|
+
</Text>
|
|
251
|
+
</View>
|
|
252
|
+
</>
|
|
253
|
+
)}
|
|
182
254
|
</View>
|
|
183
255
|
|
|
184
256
|
<View style={styles.buttonRow}>
|
package/ui/screens/PayScreen.tsx
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* `?cell=` values survive as deep-link aliases: any `pay-*` opens the send form
|
|
12
12
|
* (`pay-nearby` with the scanner up), any `get-*` opens that method directly.
|
|
13
13
|
*/
|
|
14
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
14
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
15
15
|
import { I18nManager, InteractionManager, Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
16
16
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
17
17
|
import { useTranslation } from 'react-i18next'
|
|
@@ -19,7 +19,8 @@ import { useTranslation } from 'react-i18next'
|
|
|
19
19
|
import PressableScale from '../components/ui/PressableScale'
|
|
20
20
|
import { partitionQueueByGrace } from '../../core/offline/queueGrace'
|
|
21
21
|
import PaymentQrDisplay from '../components/pay/PaymentQrDisplay'
|
|
22
|
-
import UniversalSend from '../components/pay/UniversalSend'
|
|
22
|
+
import UniversalSend, { type UniversalSendHandle } from '../components/pay/UniversalSend'
|
|
23
|
+
import type { PayStep } from '../components/pay/StepBar'
|
|
23
24
|
import RequestHub, { requestSatsFrom, type RequestMethod } from '../components/pay/RequestHub'
|
|
24
25
|
import NearbyFlow from '../components/pay/NearbyFlow'
|
|
25
26
|
import HandleReceive from '../components/pay/HandleReceive'
|
|
@@ -423,7 +424,13 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
423
424
|
* trying to leave behind, which puts them one edge-swipe away instead of
|
|
424
425
|
* discarding them.
|
|
425
426
|
*/
|
|
427
|
+
// The three-step send form owns its own step; the header's one back
|
|
428
|
+
// chevron walks it back a step before it leaves the screen (no second back
|
|
429
|
+
// control inside the form — 2026-09-18 design).
|
|
430
|
+
const sendRef = useRef<UniversalSendHandle>(null)
|
|
431
|
+
const [payStep, setPayStep] = useState<PayStep>('who')
|
|
426
432
|
const goBack = useCallback(() => {
|
|
433
|
+
if (sendRef.current?.back()) return
|
|
427
434
|
router.dismissTo(dismissTo)
|
|
428
435
|
}, [dismissTo])
|
|
429
436
|
|
|
@@ -466,6 +473,8 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
466
473
|
<>
|
|
467
474
|
{offlineNotice}
|
|
468
475
|
<UniversalSend
|
|
476
|
+
ref={sendRef}
|
|
477
|
+
onStepChange={setPayStep}
|
|
469
478
|
initialTarget={initialTarget}
|
|
470
479
|
initialSats={initialSats}
|
|
471
480
|
initialTokenAmount={initialTokenAmount}
|
|
@@ -545,11 +554,15 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
545
554
|
{direction === 'pay'
|
|
546
555
|
? nearbySession
|
|
547
556
|
? t('pay_cell_nearby_pay')
|
|
548
|
-
:
|
|
549
|
-
? // The
|
|
550
|
-
//
|
|
551
|
-
t('
|
|
552
|
-
:
|
|
557
|
+
: payStep === 'review'
|
|
558
|
+
? // The last step is named for what it is: a review, before the
|
|
559
|
+
// button that names the exact figure and asset being sent.
|
|
560
|
+
t('pay_review_title')
|
|
561
|
+
: asset
|
|
562
|
+
? // The coin was chosen on Home; this is the one place the
|
|
563
|
+
// Pay screen says which one it is armed with.
|
|
564
|
+
t('pay_direction_pay_asset', { ticker: asset.ticker })
|
|
565
|
+
: t('pay_direction_pay')
|
|
553
566
|
: t(method ? METHOD_TITLE_KEYS[method] : 'local_pay_request')}
|
|
554
567
|
</Text>
|
|
555
568
|
<View style={styles.headerBtn} />
|