@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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 +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -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/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- 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 +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- 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/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +100 -0
- package/ui/txStatus.ts +43 -5
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
package/ui/index.ts
CHANGED
|
@@ -78,6 +78,7 @@ export {
|
|
|
78
78
|
useRecipientInput,
|
|
79
79
|
type RecipientTarget,
|
|
80
80
|
type RecipientInlineError,
|
|
81
|
+
type PeerPayRequest,
|
|
81
82
|
type UseRecipientInputOptions
|
|
82
83
|
} from './components/pay/useRecipientInput'
|
|
83
84
|
|
|
@@ -108,20 +109,22 @@ export {
|
|
|
108
109
|
type RecoveredSecret
|
|
109
110
|
} from './backupShares'
|
|
110
111
|
|
|
111
|
-
// Vault UI (components/vault) + vault screens (
|
|
112
|
-
// app/vault
|
|
113
|
-
//
|
|
114
|
-
//
|
|
112
|
+
// Vault UI (components/vault) + vault screens (app/vault.tsx,
|
|
113
|
+
// app/vault-transfer.tsx). Also home to VaultCeremonySheet, mounted at the
|
|
114
|
+
// app-shell level (app/_layout.tsx) alongside PermissionSheet/ToastHost above.
|
|
115
|
+
// The 1-of-N YubiKey vault has no phrase path: PassphraseField,
|
|
116
|
+
// PhraseBackupSheet and VaultRecoverScreen are gone (spec §3.5).
|
|
115
117
|
export { EnrollWizard } from './components/vault/EnrollWizard'
|
|
116
|
-
export {
|
|
117
|
-
export {
|
|
118
|
+
export { KeyChooser, vaultKeyLabel } from './components/vault/KeyChooser'
|
|
119
|
+
export { vaultErrorCopy, RETRYABLE_VAULT_ERRORS, type VaultErrorParams } from './components/vault/vaultErrorCopy'
|
|
118
120
|
export { BackupReminderSheet } from './components/wallet/BackupReminderSheet'
|
|
119
121
|
export { BiometricAdvisoryModal } from './components/wallet/BiometricAdvisoryModal'
|
|
120
122
|
export { ImportFromBackupPrompt } from './components/wallet/ImportFromBackupPrompt'
|
|
121
123
|
export { VaultCeremonySheet } from './components/vault/VaultCeremonySheet'
|
|
122
124
|
export { useVaultBalance } from './hooks/useVaultBalance'
|
|
125
|
+
export { useVaultCoverage } from './hooks/useVaultCoverage'
|
|
126
|
+
export { useExportWalletData } from './hooks/useExportWalletData'
|
|
123
127
|
export { VaultScreen } from './screens/VaultScreen'
|
|
124
|
-
export { VaultRecoverScreen } from './screens/VaultRecoverScreen'
|
|
125
128
|
export { VaultTransferScreen } from './screens/VaultTransferScreen'
|
|
126
129
|
|
|
127
130
|
// Connections, pair, trust, and logs screens (Task 24 — extracted from
|
|
@@ -136,3 +139,68 @@ export { TrustScreen } from './screens/TrustScreen'
|
|
|
136
139
|
export { LogsScreen } from './screens/LogsScreen'
|
|
137
140
|
export { default as validateTrust } from './validateTrust'
|
|
138
141
|
export { default as isImageUrl } from './isImageUrl'
|
|
142
|
+
|
|
143
|
+
// ── Stablecoins ──────────────────────────────────────────────────────
|
|
144
|
+
//
|
|
145
|
+
// Every token surface in this package, and the one hook they all read from.
|
|
146
|
+
// `useMandala()` resolves the runtime from `useWallet().mandala`; a host that
|
|
147
|
+
// builds its own runtime (or a test) can wrap in `MandalaProvider` instead.
|
|
148
|
+
// Nothing here imports `@bsv/mandala`: the runtime is the only door.
|
|
149
|
+
export {
|
|
150
|
+
MandalaProvider,
|
|
151
|
+
useMandala,
|
|
152
|
+
useMandalaRuntime,
|
|
153
|
+
useTokenActivity,
|
|
154
|
+
tokenActivityByTxid,
|
|
155
|
+
type MandalaState,
|
|
156
|
+
type MandalaActivityState
|
|
157
|
+
} from './hooks/useMandala'
|
|
158
|
+
export {
|
|
159
|
+
formatTokenAmount,
|
|
160
|
+
formatTokenAmountWithUnit,
|
|
161
|
+
parseTokenAmount,
|
|
162
|
+
tokenAmountInputText,
|
|
163
|
+
tokenAmountMask,
|
|
164
|
+
tokenAmountParts
|
|
165
|
+
} from './tokenFormat'
|
|
166
|
+
export { tokenStatusKey, tokenRowStatusView, tokenStatusTone, tokenStatusDetailKey, type TokenStatusTone } from './tokenStatus'
|
|
167
|
+
export { SEEN_ASSETS_KEY, SEEN_EVICTIONS_KEY, markSeen, readSeen, useSeenSet, type SeenSet } from './tokenSeen'
|
|
168
|
+
export { default as AssetAmount, type AssetAmountProps } from './components/wallet/AssetAmount'
|
|
169
|
+
export { announceEviction, evictionsFrom, type EvictionNotice } from './components/wallet/tokenEviction'
|
|
170
|
+
export { default as AssetPicker, type AssetPickerProps } from './components/pay/AssetPicker'
|
|
171
|
+
export { default as AdmissionNotice, type AdmissionNoticeProps } from './components/pay/AdmissionNotice'
|
|
172
|
+
export {
|
|
173
|
+
tokenSendCopy,
|
|
174
|
+
tokenRefusalCopy,
|
|
175
|
+
tokenThrowCopy,
|
|
176
|
+
tokenUnavailableCopy,
|
|
177
|
+
type TokenSendCopy,
|
|
178
|
+
type TokenSendContext
|
|
179
|
+
} from './components/pay/tokenSendCopy'
|
|
180
|
+
export type { HandleReceiveProps } from './components/pay/HandleReceive'
|
|
181
|
+
export type { AmountInputAsset } from './components/wallet/AmountInput'
|
|
182
|
+
|
|
183
|
+
// Contacts, profile, and the pencil-edit affordance they share (2026-09-18)
|
|
184
|
+
export { ContactsScreen } from './screens/ContactsScreen'
|
|
185
|
+
export { ContactScreen } from './screens/ContactScreen'
|
|
186
|
+
export { NewContactScreen } from './screens/NewContactScreen'
|
|
187
|
+
export { ProfileScreen } from './screens/ProfileScreen'
|
|
188
|
+
export { IdentifierScreen } from './screens/IdentifierScreen'
|
|
189
|
+
export { default as ProfileButton } from './components/wallet/ProfileButton'
|
|
190
|
+
export { default as ContactSigil } from './components/wallet/ContactSigil'
|
|
191
|
+
export { PencilEditField, type PencilEditFieldProps } from './components/ui/PencilEditField'
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
default as TransactionDetailScreen,
|
|
195
|
+
type TransactionDetailParams,
|
|
196
|
+
type TransactionAction
|
|
197
|
+
} from './screens/TransactionDetailScreen'
|
|
198
|
+
|
|
199
|
+
export { default as SlideOverFromRight } from './components/ui/SlideOverFromRight'
|
|
200
|
+
|
|
201
|
+
export { default as UserAvatar, AvatarGlyph } from './components/wallet/UserAvatar'
|
|
202
|
+
export { AVATAR_ICON_GROUPS, type AvatarIconOption, type AvatarIconGroup } from './components/wallet/avatarIcons'
|
|
203
|
+
|
|
204
|
+
export { default as IconPickerSheet } from './components/wallet/IconPickerSheet'
|
|
205
|
+
export { default as EditPictureSheet, type EditPictureOption } from './components/wallet/EditPictureSheet'
|
|
206
|
+
|
|
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react'
|
|
|
2
2
|
import { View, Text, TouchableOpacity, StyleSheet, Modal, ScrollView } from 'react-native'
|
|
3
3
|
import { observer } from 'mobx-react-lite'
|
|
4
4
|
import { WalletClient } from '@bsv/sdk'
|
|
5
|
-
import type { WalletProtocol } from '@bsv/sdk'
|
|
6
5
|
import * as SecureStore from 'expo-secure-store'
|
|
7
6
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
8
7
|
import { useTranslation } from 'react-i18next'
|
|
@@ -19,11 +18,19 @@ import {
|
|
|
19
18
|
guardVaultAccess,
|
|
20
19
|
capWalletArgs,
|
|
21
20
|
ADMIN_ORIGINATOR,
|
|
21
|
+
parseExternalOrigin,
|
|
22
22
|
connectionStore,
|
|
23
23
|
type Connection,
|
|
24
24
|
useWalletConnection,
|
|
25
25
|
lastSeqKey
|
|
26
26
|
} from '@bsv/expo-wallet-toolbox'
|
|
27
|
+
import {
|
|
28
|
+
buildRelayWebSocketUrl,
|
|
29
|
+
validateMobileIdentityKey,
|
|
30
|
+
validateRelayUrl,
|
|
31
|
+
validateStoredConnectionFields,
|
|
32
|
+
validateStoredConnectionSequence
|
|
33
|
+
} from '../../core/services/walletConnectionValidation'
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
36
|
* expo-clipboard ships an untransformed ESM build (its Clipboard.js imports
|
|
@@ -113,14 +120,10 @@ function parsePairingUri(raw: string): ParseResult {
|
|
|
113
120
|
return { params: null, error: 'This QR code has expired — ask the desktop to generate a new one' }
|
|
114
121
|
}
|
|
115
122
|
|
|
116
|
-
let originUrl: URL
|
|
117
123
|
try {
|
|
118
|
-
|
|
119
|
-
} catch {
|
|
120
|
-
return { params: null, error: 'Origin URL is not valid' }
|
|
121
|
-
}
|
|
122
|
-
if (originUrl.protocol !== 'http:' && originUrl.protocol !== 'https:') {
|
|
123
|
-
return { params: null, error: 'Origin must use http:// or https://' }
|
|
124
|
+
parseExternalOrigin(origin)
|
|
125
|
+
} catch (e) {
|
|
126
|
+
return { params: null, error: e instanceof Error ? e.message : 'Origin URL is not valid' }
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
if (!/^0[23][0-9a-fA-F]{64}$/.test(backendIdentityKey)) {
|
|
@@ -143,12 +146,8 @@ function parsePairingUri(raw: string): ParseResult {
|
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
function
|
|
147
|
-
try {
|
|
148
|
-
return new URL(origin).hostname
|
|
149
|
-
} catch {
|
|
150
|
-
return origin
|
|
151
|
-
}
|
|
149
|
+
function displayDomain(origin: string): string {
|
|
150
|
+
try { return parseExternalOrigin(origin).originator } catch { return 'Invalid origin' }
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
@@ -188,10 +187,13 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
188
187
|
showToast(`${t('wallet_not_ready')}: ${t('please_log_in_first')}`, { type: 'error' })
|
|
189
188
|
return
|
|
190
189
|
}
|
|
191
|
-
const originator = domainFromOrigin(result.params.origin)
|
|
192
|
-
const wallet = new WalletClient(capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)), originator)
|
|
193
190
|
try {
|
|
194
|
-
|
|
191
|
+
const external = parseExternalOrigin(result.params.origin)
|
|
192
|
+
const wallet = new WalletClient(
|
|
193
|
+
capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)),
|
|
194
|
+
external.originator
|
|
195
|
+
)
|
|
196
|
+
await connect({ ...result.params, origin: external.origin }, wallet)
|
|
195
197
|
} catch (err) {
|
|
196
198
|
showToast(`${t('connection_failed')}: ${err instanceof Error ? err.message : t('unknown_error')}`, { type: 'error' })
|
|
197
199
|
}
|
|
@@ -202,14 +204,24 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
202
204
|
|
|
203
205
|
if (!managers.permissionsManager) return
|
|
204
206
|
try {
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const
|
|
207
|
+
const validated = validateStoredConnectionFields(conn)
|
|
208
|
+
const relay = validateRelayUrl(conn.relay)
|
|
209
|
+
const storedSeq = await SecureStore.getItemAsync(lastSeqKey(validated.topic))
|
|
210
|
+
const initialSeq = validateStoredConnectionSequence(storedSeq)
|
|
211
|
+
const wallet = new WalletClient(
|
|
212
|
+
capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)),
|
|
213
|
+
validated.external.originator
|
|
214
|
+
)
|
|
215
|
+
const identityResult = await wallet.getPublicKey({ identityKey: true })
|
|
216
|
+
const currentMobileIdentityKey = validateMobileIdentityKey(identityResult.publicKey)
|
|
217
|
+
if (currentMobileIdentityKey !== validated.mobileIdentityKey) {
|
|
218
|
+
throw new Error('Stored connection belongs to a different wallet identity')
|
|
219
|
+
}
|
|
220
|
+
const ws = new WebSocket(buildRelayWebSocketUrl(relay, validated.topic))
|
|
208
221
|
|
|
209
222
|
ws.onopen = async () => {
|
|
210
223
|
try {
|
|
211
|
-
const
|
|
212
|
-
const seq = storedSeq ? Number(storedSeq) + 1 : 1
|
|
224
|
+
const seq = initialSeq + 1
|
|
213
225
|
const payload = JSON.stringify({
|
|
214
226
|
id: crypto.randomUUID(),
|
|
215
227
|
seq,
|
|
@@ -218,14 +230,14 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
218
230
|
})
|
|
219
231
|
const plaintext = Array.from(new TextEncoder().encode(payload))
|
|
220
232
|
const { ciphertext } = await wallet.encrypt({
|
|
221
|
-
protocolID,
|
|
222
|
-
keyID:
|
|
223
|
-
counterparty:
|
|
233
|
+
protocolID: validated.protocolID,
|
|
234
|
+
keyID: validated.topic,
|
|
235
|
+
counterparty: validated.backendIdentityKey,
|
|
224
236
|
plaintext
|
|
225
237
|
})
|
|
226
238
|
ws.send(
|
|
227
239
|
JSON.stringify({
|
|
228
|
-
topic:
|
|
240
|
+
topic: validated.topic,
|
|
229
241
|
ciphertext: Buffer.from(ciphertext).toString('base64url')
|
|
230
242
|
})
|
|
231
243
|
)
|
|
@@ -241,8 +253,13 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
241
253
|
|
|
242
254
|
async function handleReconnect(conn: Connection) {
|
|
243
255
|
if (!managers.permissionsManager) return
|
|
244
|
-
const wallet = new WalletClient(capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)), domainFromOrigin(conn.origin))
|
|
245
256
|
try {
|
|
257
|
+
const external = parseExternalOrigin(conn.origin)
|
|
258
|
+
const wallet = new WalletClient(
|
|
259
|
+
capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)),
|
|
260
|
+
external.originator
|
|
261
|
+
)
|
|
262
|
+
conn = { ...conn, origin: external.origin }
|
|
246
263
|
await reconnect(conn, wallet)
|
|
247
264
|
} catch (err) {
|
|
248
265
|
showToast(`${t('reconnect_failed')}: ${err instanceof Error ? err.message : t('unknown_error')}`, { type: 'error' })
|
|
@@ -279,7 +296,7 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
279
296
|
{active.map((item, idx) => (
|
|
280
297
|
<ListRow
|
|
281
298
|
key={item.sessionId}
|
|
282
|
-
label={
|
|
299
|
+
label={displayDomain(item.origin)}
|
|
283
300
|
value={new Date(item.connectedAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}
|
|
284
301
|
icon="wifi-outline"
|
|
285
302
|
iconColor={colors.success}
|
|
@@ -303,7 +320,7 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
303
320
|
{inactive.map((item, idx) => (
|
|
304
321
|
<ListRow
|
|
305
322
|
key={item.sessionId}
|
|
306
|
-
label={
|
|
323
|
+
label={displayDomain(item.origin)}
|
|
307
324
|
icon="wifi-outline"
|
|
308
325
|
iconColor={colors.textTertiary}
|
|
309
326
|
showChevron={false}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A contact: their face, name and read-only registered handle up top; your
|
|
3
|
+
* own name for them (editable, pencil → confirm); their Identifier with a
|
|
4
|
+
* copy button; delete; and every interaction with them across every asset
|
|
5
|
+
* (2026-09-17 ruling), drawn with the same rows Home uses.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
8
|
+
import { I18nManager, ScrollView, StyleSheet, Text, View } from 'react-native'
|
|
9
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
10
|
+
import { useTranslation } from 'react-i18next'
|
|
11
|
+
import { useTheme, spacing, typography, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
12
|
+
import { showAlert } from '../components/ui/AlertCard'
|
|
13
|
+
import { GroupedSection } from '../components/ui/GroupedList'
|
|
14
|
+
import { ListRow } from '../components/ui/ListRow'
|
|
15
|
+
import { PencilEditField } from '../components/ui/PencilEditField'
|
|
16
|
+
import PressableScale from '../components/ui/PressableScale'
|
|
17
|
+
import ContactSigil from '../components/wallet/ContactSigil'
|
|
18
|
+
import ContactActivityList from '../components/wallet/ContactActivityList'
|
|
19
|
+
import IdentifierRow from '../components/wallet/IdentifierRow'
|
|
20
|
+
import { useContactsStore } from '../hooks/useContactsStore'
|
|
21
|
+
import { getContactActivity, type ContactActivityItem } from '../../core/contacts/contactActivity'
|
|
22
|
+
import { mergeContactCache } from '../../core/contacts/contactCache'
|
|
23
|
+
import { makeIdentityClient, resolveIdentity } from '../resolveIdentity'
|
|
24
|
+
import { getHandleRegistryConfig } from '../../core/toolboxConfig'
|
|
25
|
+
import { parsePaymail } from '../../core/identity/handleRegistry/rules'
|
|
26
|
+
import { createHandleRegistryClient } from '../../core/identity/handleRegistry/client'
|
|
27
|
+
import type { ContactRow } from '../../core/contacts/contactsStore'
|
|
28
|
+
|
|
29
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
30
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
31
|
+
function loadIonicons(): IoniconsComponent {
|
|
32
|
+
if (!ioniconsComponent) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
35
|
+
}
|
|
36
|
+
return ioniconsComponent
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
40
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
41
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
42
|
+
if (!expoRouterMod) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
45
|
+
}
|
|
46
|
+
return expoRouterMod
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstParam(v: string | string[] | undefined): string | undefined {
|
|
50
|
+
return Array.isArray(v) ? v[0] : v
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function ContactScreen() {
|
|
54
|
+
const { t } = useTranslation()
|
|
55
|
+
const { colors } = useTheme()
|
|
56
|
+
const insets = useSafeAreaInsets()
|
|
57
|
+
const Ionicons = loadIonicons()
|
|
58
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
59
|
+
const { managers, adminOriginator, storage, walletUserId, selectedNetwork } = useWallet()
|
|
60
|
+
const store = useContactsStore()
|
|
61
|
+
const params = useLocalSearchParams<{ identityKey?: string | string[] }>()
|
|
62
|
+
const identityKey = firstParam(params.identityKey) ?? ''
|
|
63
|
+
|
|
64
|
+
const [contact, setContact] = useState<ContactRow | undefined>(undefined)
|
|
65
|
+
const [activity, setActivity] = useState<ContactActivityItem[]>([])
|
|
66
|
+
|
|
67
|
+
const reload = useCallback(async () => {
|
|
68
|
+
if (!store || walletUserId === null || !identityKey) return
|
|
69
|
+
setContact(await store.getContact(walletUserId, identityKey))
|
|
70
|
+
}, [store, walletUserId, identityKey])
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
void reload()
|
|
74
|
+
}, [reload])
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!identityKey) return
|
|
78
|
+
const wallet = managers?.permissionsManager
|
|
79
|
+
void getContactActivity({
|
|
80
|
+
wallet: wallet as never,
|
|
81
|
+
adminOriginator,
|
|
82
|
+
settlementsDb: storage?.sqliteDb as never,
|
|
83
|
+
identityKey
|
|
84
|
+
}).then(setActivity)
|
|
85
|
+
}, [identityKey, managers, adminOriginator, storage])
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Best-effort background cache refresh: the overlay's avatar and the
|
|
89
|
+
* registry's handle, in ONE write. `refreshContactCache` replaces all three
|
|
90
|
+
* cache columns, so two separate calls would each blank what the other just
|
|
91
|
+
* stored. Once per visit — the write feeds `reload`, and re-running on the
|
|
92
|
+
* contact it produced would be a loop.
|
|
93
|
+
*
|
|
94
|
+
* One guard per source, though, not one for the pass. The two clients arrive
|
|
95
|
+
* at different moments: a screen drawn before the wallet finished building
|
|
96
|
+
* has no identity client, while a chain WITH a registry configured has its
|
|
97
|
+
* registry client from the first render — so a single guard would be claimed
|
|
98
|
+
* by the pass that could only do the registry half, and the avatar would
|
|
99
|
+
* never be refreshed for the whole visit even though `managers` is a
|
|
100
|
+
* dependency precisely so that it could be.
|
|
101
|
+
*
|
|
102
|
+
* `name` is never touched: it is the user's own label for this person.
|
|
103
|
+
*/
|
|
104
|
+
const refreshedAvatarKeyRef = useRef('')
|
|
105
|
+
const refreshedHandleKeyRef = useRef('')
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!identityKey || !store || walletUserId === null || !contact) return
|
|
108
|
+
const idClient = makeIdentityClient(managers?.permissionsManager as never, adminOriginator)
|
|
109
|
+
const registry = getHandleRegistryConfig(selectedNetwork)
|
|
110
|
+
const client = registry ? createHandleRegistryClient({ pinned: registry }) : null
|
|
111
|
+
const wantAvatar = !!idClient && refreshedAvatarKeyRef.current !== identityKey
|
|
112
|
+
const wantHandle = !!client && refreshedHandleKeyRef.current !== identityKey
|
|
113
|
+
if (!wantAvatar && !wantHandle) return
|
|
114
|
+
if (wantAvatar) refreshedAvatarKeyRef.current = identityKey
|
|
115
|
+
if (wantHandle) refreshedHandleKeyRef.current = identityKey
|
|
116
|
+
let cancelled = false
|
|
117
|
+
// A pass that never reaches its decision hands the guard back, so a
|
|
118
|
+
// `contact` that changes mid-lookup (a rename, whose `reload` is a new
|
|
119
|
+
// row) is re-checked instead of losing this visit's refresh. It cannot
|
|
120
|
+
// reopen the loop the guard is for: that path is exactly the one this is
|
|
121
|
+
// true on. Set BEFORE the write, not after: a cancellation landing while
|
|
122
|
+
// the UPDATE is in flight would otherwise repeat both lookups to send the
|
|
123
|
+
// same three columns again.
|
|
124
|
+
let decided = false
|
|
125
|
+
void (async () => {
|
|
126
|
+
const [identity, lookup] = await Promise.all([
|
|
127
|
+
wantAvatar && idClient ? resolveIdentity(idClient, identityKey).then(([, found]) => found) : null,
|
|
128
|
+
// A contact whose cached handle names another domain is looked up
|
|
129
|
+
// there; everyone else on the registry this build is configured for.
|
|
130
|
+
wantHandle && client
|
|
131
|
+
? client.lookupProfile(identityKey, parsePaymail(contact.cachedHandle ?? '')?.domain)
|
|
132
|
+
: null
|
|
133
|
+
])
|
|
134
|
+
if (cancelled) return
|
|
135
|
+
// `lookupProfile`, not `lookupIdentityKey`: a `failed` lookup is the
|
|
136
|
+
// registry not having answered, and writing `''` for it would blank a
|
|
137
|
+
// contact's handle every time this screen is opened offline. Only an
|
|
138
|
+
// answer — `found` or `none` — may change the column.
|
|
139
|
+
const learnedHandle = lookup?.kind === 'found' ? lookup.profile.paymail : lookup?.kind === 'none' ? '' : undefined
|
|
140
|
+
const next = mergeContactCache(contact, {
|
|
141
|
+
...(identity?.avatarURL ? { cachedAvatarUrl: identity.avatarURL } : {}),
|
|
142
|
+
...(learnedHandle === undefined ? {} : { cachedHandle: learnedHandle })
|
|
143
|
+
})
|
|
144
|
+
decided = true
|
|
145
|
+
if (!next) return
|
|
146
|
+
await store.refreshContactCache(walletUserId, identityKey, next)
|
|
147
|
+
if (!cancelled) void reload().catch(() => {})
|
|
148
|
+
})().catch(() => {})
|
|
149
|
+
return () => {
|
|
150
|
+
cancelled = true
|
|
151
|
+
if (decided) return
|
|
152
|
+
if (wantAvatar) refreshedAvatarKeyRef.current = ''
|
|
153
|
+
if (wantHandle) refreshedHandleKeyRef.current = ''
|
|
154
|
+
}
|
|
155
|
+
}, [identityKey, store, walletUserId, managers, adminOriginator, selectedNetwork, contact, reload])
|
|
156
|
+
|
|
157
|
+
const onDelete = useCallback(async () => {
|
|
158
|
+
if (!store || walletUserId === null || !contact) return
|
|
159
|
+
const choice = await showAlert({
|
|
160
|
+
title: t('contact_delete'),
|
|
161
|
+
message: t('contact_delete_body', { name: contact.name }),
|
|
162
|
+
buttons: [
|
|
163
|
+
{ text: t('cancel'), style: 'cancel', key: 'cancel' },
|
|
164
|
+
{ text: t('contact_delete'), style: 'destructive', key: 'delete' }
|
|
165
|
+
]
|
|
166
|
+
})
|
|
167
|
+
if (choice !== 'delete') return
|
|
168
|
+
await store.deleteContact(walletUserId, identityKey)
|
|
169
|
+
router.back()
|
|
170
|
+
}, [store, walletUserId, contact, identityKey, t, router])
|
|
171
|
+
|
|
172
|
+
if (!contact) return <View style={[styles.container, { backgroundColor: colors.background }]} />
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
|
|
176
|
+
<View style={[styles.header, { borderBottomColor: colors.separator }]}>
|
|
177
|
+
<PressableScale
|
|
178
|
+
onPress={() => router.back()}
|
|
179
|
+
haptic="tap"
|
|
180
|
+
style={styles.headerBtn}
|
|
181
|
+
accessibilityRole="button"
|
|
182
|
+
accessibilityLabel={t('go_back')}
|
|
183
|
+
>
|
|
184
|
+
<Ionicons
|
|
185
|
+
name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
|
|
186
|
+
size={24}
|
|
187
|
+
color={colors.textSecondary}
|
|
188
|
+
/>
|
|
189
|
+
</PressableScale>
|
|
190
|
+
<Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
191
|
+
{contact.name}
|
|
192
|
+
</Text>
|
|
193
|
+
<View style={styles.headerBtn} />
|
|
194
|
+
</View>
|
|
195
|
+
|
|
196
|
+
<ScrollView
|
|
197
|
+
contentContainerStyle={[styles.content, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]}
|
|
198
|
+
keyboardShouldPersistTaps="handled"
|
|
199
|
+
>
|
|
200
|
+
<View style={styles.hero}>
|
|
201
|
+
<ContactSigil identityKey={identityKey} avatarUrl={contact.cachedAvatarUrl} size={72} radius={24} />
|
|
202
|
+
<Text style={[styles.heroName, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
203
|
+
{contact.name}
|
|
204
|
+
</Text>
|
|
205
|
+
{!!contact.cachedHandle && (
|
|
206
|
+
<>
|
|
207
|
+
<Text style={[styles.handle, { color: colors.textSecondary }]}>{contact.cachedHandle}</Text>
|
|
208
|
+
<View style={styles.captionRow}>
|
|
209
|
+
<Ionicons name="shield-checkmark-outline" size={12} color={colors.textTertiary} />
|
|
210
|
+
<Text style={[styles.handleCaption, { color: colors.textTertiary }]}>
|
|
211
|
+
{t('contact_handle_caption')}
|
|
212
|
+
</Text>
|
|
213
|
+
</View>
|
|
214
|
+
</>
|
|
215
|
+
)}
|
|
216
|
+
</View>
|
|
217
|
+
|
|
218
|
+
<GroupedSection header={t('contact_name_section')} footer={t('contact_name_hint')}>
|
|
219
|
+
<PencilEditField
|
|
220
|
+
value={contact.name}
|
|
221
|
+
placeholder={t('contact_new_title')}
|
|
222
|
+
onSave={async next => {
|
|
223
|
+
if (walletUserId === null) return
|
|
224
|
+
await store?.renameContact(walletUserId, identityKey, next)
|
|
225
|
+
void reload()
|
|
226
|
+
}}
|
|
227
|
+
editAccessibilityLabel={t('contact_edit_name')}
|
|
228
|
+
saveAccessibilityLabel={t('contact_save_name')}
|
|
229
|
+
/>
|
|
230
|
+
</GroupedSection>
|
|
231
|
+
|
|
232
|
+
<GroupedSection header={t('contact_identifier')}>
|
|
233
|
+
<IdentifierRow identityKey={identityKey} />
|
|
234
|
+
</GroupedSection>
|
|
235
|
+
|
|
236
|
+
<GroupedSection>
|
|
237
|
+
<ListRow
|
|
238
|
+
label={t('contact_delete')}
|
|
239
|
+
icon="trash-outline"
|
|
240
|
+
iconColor={colors.error}
|
|
241
|
+
destructive
|
|
242
|
+
showChevron={false}
|
|
243
|
+
onPress={onDelete}
|
|
244
|
+
isLast
|
|
245
|
+
/>
|
|
246
|
+
</GroupedSection>
|
|
247
|
+
|
|
248
|
+
<Text style={[styles.sectionTitle, { color: colors.textTertiary }]}>{t('contact_activity').toUpperCase()}</Text>
|
|
249
|
+
<ContactActivityList items={activity} identityKey={identityKey} />
|
|
250
|
+
</ScrollView>
|
|
251
|
+
</View>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export default ContactScreen
|
|
256
|
+
|
|
257
|
+
const styles = StyleSheet.create({
|
|
258
|
+
container: { flex: 1 },
|
|
259
|
+
header: {
|
|
260
|
+
flexDirection: 'row',
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
justifyContent: 'space-between',
|
|
263
|
+
paddingHorizontal: spacing.sm,
|
|
264
|
+
paddingVertical: spacing.md,
|
|
265
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
266
|
+
},
|
|
267
|
+
headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
268
|
+
headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
|
|
269
|
+
content: { paddingTop: spacing.lg },
|
|
270
|
+
hero: {
|
|
271
|
+
alignItems: 'center',
|
|
272
|
+
gap: spacing.sm,
|
|
273
|
+
paddingHorizontal: spacing.xl,
|
|
274
|
+
paddingTop: spacing.sm,
|
|
275
|
+
paddingBottom: spacing.xl
|
|
276
|
+
},
|
|
277
|
+
heroName: { ...typography.title2, fontWeight: '700', marginTop: spacing.xs },
|
|
278
|
+
handle: { ...typography.body, fontWeight: '500' },
|
|
279
|
+
captionRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs },
|
|
280
|
+
handleCaption: { ...typography.caption1 },
|
|
281
|
+
// Tracked small caps, matching GroupedSection's own header.
|
|
282
|
+
sectionTitle: {
|
|
283
|
+
fontSize: 10.5,
|
|
284
|
+
fontWeight: '700',
|
|
285
|
+
letterSpacing: 1.3,
|
|
286
|
+
paddingHorizontal: spacing.xl,
|
|
287
|
+
paddingBottom: spacing.sm
|
|
288
|
+
}
|
|
289
|
+
})
|