@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback } from 'react'
|
|
2
2
|
import { View, Text, ScrollView, StyleSheet } from 'react-native'
|
|
3
3
|
import { useTranslation } from 'react-i18next'
|
|
4
|
-
import { useTheme, spacing, typography, useWallet, isVaultAvailable } from '@bsv/expo-wallet-toolbox'
|
|
4
|
+
import { useTheme, spacing, typography, useWallet, isVaultAvailable, useVault } from '@bsv/expo-wallet-toolbox'
|
|
5
5
|
import { GroupedSection } from '../components/ui/GroupedList'
|
|
6
6
|
import { ListRow } from '../components/ui/ListRow'
|
|
7
7
|
import AmountDisplay from '../components/wallet/AmountDisplay'
|
|
@@ -37,6 +37,11 @@ export function SettingsScreen() {
|
|
|
37
37
|
// Read during render, from the reactive network, so the row disappears on a
|
|
38
38
|
// switch to testnet without a remount.
|
|
39
39
|
const vaultAvailable = isVaultAvailable(selectedNetwork)
|
|
40
|
+
// F-07: an existing, already-funded vault stays reachable even when the
|
|
41
|
+
// flag is off or the network switched — see showVaultRow below. VaultScreen
|
|
42
|
+
// itself is never gated on that flag for withdraw.
|
|
43
|
+
const { hasVaultMeta } = useVault()
|
|
44
|
+
const showVaultRow = vaultAvailable || hasVaultMeta
|
|
40
45
|
|
|
41
46
|
const balanceCacheKey = `cached_wallet_balance_${selectedNetwork}`
|
|
42
47
|
const balanceCacheTimestampKey = `cached_wallet_balance_ts_${selectedNetwork}`
|
|
@@ -136,11 +141,12 @@ export function SettingsScreen() {
|
|
|
136
141
|
icon="swap-horizontal-outline"
|
|
137
142
|
iconColor={colors.success}
|
|
138
143
|
onPress={() => router.push('/pay')}
|
|
139
|
-
isLast={!
|
|
144
|
+
isLast={!showVaultRow}
|
|
140
145
|
/>
|
|
141
146
|
{/* Same release and network gate as the home screen's Vault
|
|
142
|
-
destination (spec §5.5, task 11)
|
|
143
|
-
|
|
147
|
+
destination (spec §5.5, task 11), plus the F-07 OR for an
|
|
148
|
+
existing enrollment. */}
|
|
149
|
+
{showVaultRow && (
|
|
144
150
|
<ListRow
|
|
145
151
|
label={t('vault_row_title')}
|
|
146
152
|
icon="safe"
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One transaction, on its own screen.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the expand-in-place row: a tap on an activity row now means exactly
|
|
5
|
+
* one thing, and the utilities that used to unfold underneath it live in the
|
|
6
|
+
* overflow menu here.
|
|
7
|
+
*
|
|
8
|
+
* Presented full-screen by `WalletHomeScreen` rather than as its own route,
|
|
9
|
+
* deliberately: the utilities in the overflow menu are the list's own
|
|
10
|
+
* handlers, entangled with its busy-row state and its storage/permissions
|
|
11
|
+
* managers, and a route could only have reached them by duplicating logic
|
|
12
|
+
* that includes the overlay-authoritative cancel (FIX J). Same appearance,
|
|
13
|
+
* none of that risk.
|
|
14
|
+
*
|
|
15
|
+
* Works for all four combinations the list can produce — money in or out, BSV
|
|
16
|
+
* or a stablecoin — because everything it draws comes from the row that opened
|
|
17
|
+
* it rather than from a second query. The counterparty is drawn as the same
|
|
18
|
+
* generative sigil the list uses, never as a raw identity key: a 66-character
|
|
19
|
+
* hex string is not an answer to "who was this".
|
|
20
|
+
*/
|
|
21
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
22
|
+
import { Modal, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
23
|
+
import { useTranslation } from 'react-i18next'
|
|
24
|
+
import {
|
|
25
|
+
useTheme,
|
|
26
|
+
spacing,
|
|
27
|
+
radii,
|
|
28
|
+
typography,
|
|
29
|
+
useWallet,
|
|
30
|
+
useWalletManagers,
|
|
31
|
+
formatAmount,
|
|
32
|
+
formatSatoshisExact,
|
|
33
|
+
isFiatCurrency,
|
|
34
|
+
ExchangeRateContext
|
|
35
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
36
|
+
import type { ContactRow } from '../../core/contacts/contactsStore'
|
|
37
|
+
import CustomSafeArea from '../components/ui/CustomSafeArea'
|
|
38
|
+
import ContactSigil from '../components/wallet/ContactSigil'
|
|
39
|
+
import { showToast } from '../components/ui/Toast'
|
|
40
|
+
import { useContactsStore } from '../hooks/useContactsStore'
|
|
41
|
+
|
|
42
|
+
type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
|
|
43
|
+
let clipboardModule: ClipboardModule | undefined
|
|
44
|
+
function loadClipboard(): ClipboardModule {
|
|
45
|
+
if (!clipboardModule) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
47
|
+
clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
|
|
48
|
+
}
|
|
49
|
+
return clipboardModule
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
54
|
+
* this package's other native-module-boundary fixes (see AdmissionNotice.tsx):
|
|
55
|
+
* @expo/vector-icons reaches expo-font, untransformed ESM that breaks every
|
|
56
|
+
* Jest suite importing the `ui` barrel. `Icon` is one module-level component
|
|
57
|
+
* rather than `const Ionicons = loadIonicons()` per render site, which
|
|
58
|
+
* react-hooks/static-components reports as a component created during render.
|
|
59
|
+
*/
|
|
60
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
61
|
+
type IoniconsProps = React.ComponentProps<IoniconsComponent>
|
|
62
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
63
|
+
function loadIonicons(): IoniconsComponent {
|
|
64
|
+
if (!ioniconsComponent) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
66
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
67
|
+
}
|
|
68
|
+
return ioniconsComponent
|
|
69
|
+
}
|
|
70
|
+
function Icon(props: IoniconsProps) {
|
|
71
|
+
return React.createElement(loadIonicons(), props)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Everything the screen draws, handed over by the row that opened it.
|
|
76
|
+
*
|
|
77
|
+
* Passed as one JSON route param rather than a dozen loose ones: the shape is
|
|
78
|
+
* the row's own, so a new field on the row never means a new param to thread
|
|
79
|
+
* through expo-router's string-typed `params`.
|
|
80
|
+
*/
|
|
81
|
+
export interface TransactionDetailParams {
|
|
82
|
+
txid: string
|
|
83
|
+
/** Signed satoshis. Ignored for a token row, which carries its own figure. */
|
|
84
|
+
satoshis: number
|
|
85
|
+
status: string
|
|
86
|
+
description?: string
|
|
87
|
+
isOutgoing: boolean
|
|
88
|
+
createdAt?: string
|
|
89
|
+
counterpartyKey?: string
|
|
90
|
+
/** Present only for a stablecoin row. */
|
|
91
|
+
token?: {
|
|
92
|
+
title: string
|
|
93
|
+
amount?: { value: string; unit: string }
|
|
94
|
+
incoming: boolean
|
|
95
|
+
statusText?: string
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** One action in the overflow menu. */
|
|
100
|
+
export interface TransactionAction {
|
|
101
|
+
key: string
|
|
102
|
+
label: string
|
|
103
|
+
icon: string
|
|
104
|
+
danger?: boolean
|
|
105
|
+
onPress: () => void
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function formatFullDate(value?: string): string {
|
|
109
|
+
if (!value) return ''
|
|
110
|
+
const d = new Date(value)
|
|
111
|
+
if (Number.isNaN(d.getTime())) return ''
|
|
112
|
+
try {
|
|
113
|
+
return d.toLocaleString(undefined, {
|
|
114
|
+
year: 'numeric',
|
|
115
|
+
month: 'short',
|
|
116
|
+
day: 'numeric',
|
|
117
|
+
hour: '2-digit',
|
|
118
|
+
minute: '2-digit'
|
|
119
|
+
})
|
|
120
|
+
} catch {
|
|
121
|
+
return d.toISOString()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** `a1b2c3…d4e5f6` — a txid you can eyeball against an explorer without it
|
|
126
|
+
* taking the whole row. */
|
|
127
|
+
function shortTxid(txid: string): string {
|
|
128
|
+
if (txid.length <= 16) return txid
|
|
129
|
+
return `${txid.slice(0, 8)}…${txid.slice(-6)}`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default function TransactionDetailScreen({
|
|
133
|
+
tx,
|
|
134
|
+
getActions,
|
|
135
|
+
onBack
|
|
136
|
+
}: {
|
|
137
|
+
tx: TransactionDetailParams
|
|
138
|
+
/**
|
|
139
|
+
* The overflow menu's contents, built when the menu is OPENED rather than
|
|
140
|
+
* handed over as an array. The list's handlers read refs, and calling them
|
|
141
|
+
* — even indirectly — while this screen renders is a render-phase ref read.
|
|
142
|
+
* Building on press also means the menu reflects the row's state now, not
|
|
143
|
+
* its state when the screen was first drawn.
|
|
144
|
+
*/
|
|
145
|
+
getActions?: () => TransactionAction[]
|
|
146
|
+
onBack: () => void
|
|
147
|
+
}) {
|
|
148
|
+
const { colors } = useTheme()
|
|
149
|
+
const { t } = useTranslation()
|
|
150
|
+
const { settings, walletUserId } = useWallet()
|
|
151
|
+
const contactsStore = useContactsStore()
|
|
152
|
+
const { satoshisPerUSD, usdToFiat } = React.useContext(ExchangeRateContext)
|
|
153
|
+
const currency = settings?.currency || 'BSV'
|
|
154
|
+
const [menuActions, setMenuActions] = useState<TransactionAction[] | null>(null)
|
|
155
|
+
const [contact, setContact] = useState<ContactRow | undefined>(undefined)
|
|
156
|
+
|
|
157
|
+
const { storage } = useWalletManagers()
|
|
158
|
+
/** undefined while looking, null when the transaction is not in a block yet. */
|
|
159
|
+
const [blockHeight, setBlockHeight] = useState<number | null | undefined>(undefined)
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!tx.txid || !storage) return
|
|
162
|
+
let cancelled = false
|
|
163
|
+
storage
|
|
164
|
+
.getProvenTxHeight(tx.txid)
|
|
165
|
+
.then(h => {
|
|
166
|
+
if (!cancelled) setBlockHeight(h)
|
|
167
|
+
})
|
|
168
|
+
.catch(() => {
|
|
169
|
+
if (!cancelled) setBlockHeight(null)
|
|
170
|
+
})
|
|
171
|
+
return () => {
|
|
172
|
+
cancelled = true
|
|
173
|
+
}
|
|
174
|
+
}, [tx.txid, storage])
|
|
175
|
+
|
|
176
|
+
const counterpartyKey = tx.counterpartyKey
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
// No clear on the way out: this screen shows ONE transaction, so the
|
|
179
|
+
// counterparty never changes under it, and `contact` is already undefined
|
|
180
|
+
// until a lookup succeeds.
|
|
181
|
+
if (!counterpartyKey || !contactsStore || walletUserId == null) return
|
|
182
|
+
let cancelled = false
|
|
183
|
+
void contactsStore
|
|
184
|
+
.getContact(walletUserId, counterpartyKey)
|
|
185
|
+
.then(c => {
|
|
186
|
+
if (!cancelled) setContact(c)
|
|
187
|
+
})
|
|
188
|
+
.catch(() => {
|
|
189
|
+
// A failed lookup reads as "not a saved contact", which is what the
|
|
190
|
+
// screen already shows.
|
|
191
|
+
})
|
|
192
|
+
return () => {
|
|
193
|
+
cancelled = true
|
|
194
|
+
}
|
|
195
|
+
}, [counterpartyKey, contactsStore, walletUserId])
|
|
196
|
+
|
|
197
|
+
const incoming = tx.token ? tx.token.incoming : !tx.isOutgoing
|
|
198
|
+
|
|
199
|
+
/** What the transaction actually moved, in exact sats — never BSV or fiat. */
|
|
200
|
+
const hero = useMemo(() => {
|
|
201
|
+
if (tx.token) return tx.token.amount ?? null
|
|
202
|
+
return formatSatoshisExact(tx.satoshis, true)
|
|
203
|
+
}, [tx])
|
|
204
|
+
|
|
205
|
+
const exact = hero ? `${hero.value} ${hero.unit}` : ''
|
|
206
|
+
|
|
207
|
+
/** The same money in the display currency; none when that currency is BSV. */
|
|
208
|
+
const fiat = useMemo(() => {
|
|
209
|
+
if (tx.token || !isFiatCurrency(currency)) return null
|
|
210
|
+
return formatAmount(tx.satoshis, currency, satoshisPerUSD, { showPlus: true, usdToFiat })
|
|
211
|
+
}, [tx, currency, satoshisPerUSD, usdToFiat])
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Who this was with. A saved contact's own label wins, then the handle the
|
|
215
|
+
* registry cached for them, then the direction — never the identity key.
|
|
216
|
+
*/
|
|
217
|
+
const title = tx.token
|
|
218
|
+
? contact?.name || contact?.cachedHandle || tx.token.title
|
|
219
|
+
: contact?.name ||
|
|
220
|
+
contact?.cachedHandle ||
|
|
221
|
+
tx.description ||
|
|
222
|
+
(incoming ? t('tx_received', { defaultValue: 'Received' }) : t('tx_sent', { defaultValue: 'Sent' }))
|
|
223
|
+
|
|
224
|
+
const statusText = tx.token?.statusText || tx.status
|
|
225
|
+
|
|
226
|
+
const copyTxid = useCallback(() => {
|
|
227
|
+
if (!tx.txid) return
|
|
228
|
+
loadClipboard().setString(tx.txid)
|
|
229
|
+
showToast(t('copied', { defaultValue: 'Copied' }), { type: 'success' })
|
|
230
|
+
}, [tx.txid, t])
|
|
231
|
+
|
|
232
|
+
// Same pair the activity row uses, so a figure does not change colour
|
|
233
|
+
// between the list and this screen.
|
|
234
|
+
const amountColor = incoming ? colors.successAmount : colors.textPrimary
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<CustomSafeArea style={[styles.screen, { backgroundColor: colors.background }]}>
|
|
238
|
+
<View style={styles.header}>
|
|
239
|
+
<TouchableOpacity
|
|
240
|
+
onPress={onBack}
|
|
241
|
+
style={styles.headerBtn}
|
|
242
|
+
accessibilityRole="button"
|
|
243
|
+
accessibilityLabel={t('go_back')}
|
|
244
|
+
>
|
|
245
|
+
<Icon name="chevron-back" size={24} color={colors.textPrimary} />
|
|
246
|
+
</TouchableOpacity>
|
|
247
|
+
{getActions ? (
|
|
248
|
+
<TouchableOpacity
|
|
249
|
+
onPress={() => {
|
|
250
|
+
const next = getActions()
|
|
251
|
+
// An empty menu is not a menu; leave the tap inert rather than
|
|
252
|
+
// opening an empty sheet.
|
|
253
|
+
if (next.length > 0) setMenuActions(next)
|
|
254
|
+
}}
|
|
255
|
+
style={styles.headerBtn}
|
|
256
|
+
accessibilityRole="button"
|
|
257
|
+
accessibilityLabel={t('more', { defaultValue: 'More' })}
|
|
258
|
+
>
|
|
259
|
+
<Icon name="ellipsis-horizontal" size={22} color={colors.textPrimary} />
|
|
260
|
+
</TouchableOpacity>
|
|
261
|
+
) : (
|
|
262
|
+
<View style={styles.headerBtn} />
|
|
263
|
+
)}
|
|
264
|
+
</View>
|
|
265
|
+
|
|
266
|
+
<ScrollView contentContainerStyle={styles.body}>
|
|
267
|
+
{/* The face, at portrait size. Falls back to the direction arrow only
|
|
268
|
+
when there is no counterparty key at all — a received token payment
|
|
269
|
+
carries a per-payment blinded key, which still draws a stable face
|
|
270
|
+
for THAT payment. */}
|
|
271
|
+
{counterpartyKey ? (
|
|
272
|
+
<ContactSigil identityKey={counterpartyKey} avatarUrl={contact?.cachedAvatarUrl} size={84} radius={42} />
|
|
273
|
+
) : (
|
|
274
|
+
<View style={[styles.fallbackFace, { backgroundColor: colors.fill }]}>
|
|
275
|
+
<Icon name={incoming ? 'arrow-down' : 'arrow-up'} size={34} color={colors.textSecondary} />
|
|
276
|
+
</View>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
<Text style={[styles.title, { color: colors.textPrimary }]} numberOfLines={2}>
|
|
280
|
+
{title}
|
|
281
|
+
</Text>
|
|
282
|
+
{/* The handle only when it is not already what the title says. */}
|
|
283
|
+
{contact?.cachedHandle && contact.cachedHandle !== title ? (
|
|
284
|
+
<Text style={[styles.handle, { color: colors.textSecondary }]}>{contact.cachedHandle}</Text>
|
|
285
|
+
) : null}
|
|
286
|
+
|
|
287
|
+
{hero ? (
|
|
288
|
+
<Text style={[styles.hero, { color: amountColor }]} numberOfLines={1} adjustsFontSizeToFit>
|
|
289
|
+
{hero.value}
|
|
290
|
+
{hero.unit ? <Text style={[styles.heroUnit, { color: colors.textSecondary }]}> {hero.unit}</Text> : null}
|
|
291
|
+
</Text>
|
|
292
|
+
) : (
|
|
293
|
+
<Text style={[styles.hero, { color: colors.textSecondary }]}>—</Text>
|
|
294
|
+
)}
|
|
295
|
+
{fiat ? <Text style={[styles.fiat, { color: colors.textSecondary }]}>{fiat}</Text> : null}
|
|
296
|
+
|
|
297
|
+
<View style={[styles.divider, { borderColor: colors.hairline }]} />
|
|
298
|
+
|
|
299
|
+
<DetailRow label={t('tx_detail_status', { defaultValue: 'Status' })} value={statusText} />
|
|
300
|
+
<DetailRow label={t('tx_detail_date', { defaultValue: 'Date' })} value={formatFullDate(tx.createdAt) || '—'} />
|
|
301
|
+
<DetailRow label={t('tx_detail_amount', { defaultValue: 'Amount' })} value={exact || '—'} />
|
|
302
|
+
{tx.txid ? (
|
|
303
|
+
<DetailRow
|
|
304
|
+
label={t('tx_detail_block')}
|
|
305
|
+
value={
|
|
306
|
+
blockHeight === undefined
|
|
307
|
+
? '—'
|
|
308
|
+
: blockHeight === null
|
|
309
|
+
? t('tx_detail_block_pending')
|
|
310
|
+
: String(blockHeight)
|
|
311
|
+
}
|
|
312
|
+
/>
|
|
313
|
+
) : null}
|
|
314
|
+
{tx.txid ? (
|
|
315
|
+
<DetailRow
|
|
316
|
+
label={t('tx_detail_txid', { defaultValue: 'Transaction ID' })}
|
|
317
|
+
value={shortTxid(tx.txid)}
|
|
318
|
+
onCopy={copyTxid}
|
|
319
|
+
/>
|
|
320
|
+
) : null}
|
|
321
|
+
</ScrollView>
|
|
322
|
+
|
|
323
|
+
{/* The utilities that used to unfold inside the row. */}
|
|
324
|
+
<Modal
|
|
325
|
+
visible={menuActions !== null}
|
|
326
|
+
transparent
|
|
327
|
+
animationType="fade"
|
|
328
|
+
onRequestClose={() => setMenuActions(null)}
|
|
329
|
+
>
|
|
330
|
+
<Pressable style={styles.backdrop} onPress={() => setMenuActions(null)}>
|
|
331
|
+
<View style={[styles.menu, { backgroundColor: colors.surfaceRaised, borderColor: colors.hairline }]}>
|
|
332
|
+
{(menuActions ?? []).map(a => (
|
|
333
|
+
<TouchableOpacity
|
|
334
|
+
key={a.key}
|
|
335
|
+
style={styles.menuItem}
|
|
336
|
+
onPress={() => {
|
|
337
|
+
setMenuActions(null)
|
|
338
|
+
a.onPress()
|
|
339
|
+
}}
|
|
340
|
+
>
|
|
341
|
+
<Icon
|
|
342
|
+
name={a.icon as never}
|
|
343
|
+
size={18}
|
|
344
|
+
color={a.danger ? colors.error : colors.textSecondary}
|
|
345
|
+
style={styles.menuIcon}
|
|
346
|
+
/>
|
|
347
|
+
<Text style={[styles.menuLabel, { color: a.danger ? colors.error : colors.textPrimary }]}>
|
|
348
|
+
{a.label}
|
|
349
|
+
</Text>
|
|
350
|
+
</TouchableOpacity>
|
|
351
|
+
))}
|
|
352
|
+
</View>
|
|
353
|
+
</Pressable>
|
|
354
|
+
</Modal>
|
|
355
|
+
</CustomSafeArea>
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function DetailRow({ label, value, onCopy }: { label: string; value: string; onCopy?: () => void }) {
|
|
360
|
+
const { colors } = useTheme()
|
|
361
|
+
return (
|
|
362
|
+
<View style={styles.row}>
|
|
363
|
+
<Text style={[styles.rowLabel, { color: colors.textSecondary }]}>{label}</Text>
|
|
364
|
+
<View style={styles.rowValueGroup}>
|
|
365
|
+
<Text style={[styles.rowValue, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
366
|
+
{value}
|
|
367
|
+
</Text>
|
|
368
|
+
{onCopy ? (
|
|
369
|
+
<TouchableOpacity onPress={onCopy} style={styles.copyBtn} accessibilityRole="button">
|
|
370
|
+
<Icon name="copy-outline" size={16} color={colors.textSecondary} />
|
|
371
|
+
</TouchableOpacity>
|
|
372
|
+
) : null}
|
|
373
|
+
</View>
|
|
374
|
+
</View>
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const styles = StyleSheet.create({
|
|
379
|
+
screen: { flex: 1 },
|
|
380
|
+
header: {
|
|
381
|
+
flexDirection: 'row',
|
|
382
|
+
alignItems: 'center',
|
|
383
|
+
justifyContent: 'space-between',
|
|
384
|
+
paddingHorizontal: spacing.md,
|
|
385
|
+
paddingVertical: spacing.sm
|
|
386
|
+
},
|
|
387
|
+
headerBtn: { width: 40, height: 40, alignItems: 'center', justifyContent: 'center' },
|
|
388
|
+
body: { paddingHorizontal: spacing.lg, paddingBottom: spacing.xxxl },
|
|
389
|
+
fallbackFace: { width: 84, height: 84, borderRadius: 42, alignItems: 'center', justifyContent: 'center' },
|
|
390
|
+
title: { ...typography.title1, fontWeight: '700', marginTop: spacing.lg },
|
|
391
|
+
handle: { ...typography.body, marginTop: spacing.xs },
|
|
392
|
+
hero: { ...typography.largeTitle, fontSize: 48, lineHeight: 56, fontWeight: '700', marginTop: spacing.lg },
|
|
393
|
+
heroUnit: { ...typography.title3, fontWeight: '600' },
|
|
394
|
+
fiat: { ...typography.body, marginTop: spacing.xs },
|
|
395
|
+
divider: { borderTopWidth: StyleSheet.hairlineWidth, borderStyle: 'dashed', marginVertical: spacing.xl },
|
|
396
|
+
row: {
|
|
397
|
+
flexDirection: 'row',
|
|
398
|
+
alignItems: 'center',
|
|
399
|
+
justifyContent: 'space-between',
|
|
400
|
+
paddingVertical: spacing.md
|
|
401
|
+
},
|
|
402
|
+
rowLabel: { ...typography.body, flexShrink: 0, marginRight: spacing.md },
|
|
403
|
+
rowValueGroup: { flexDirection: 'row', alignItems: 'center', flexShrink: 1 },
|
|
404
|
+
rowValue: { ...typography.body, fontWeight: '600', flexShrink: 1 },
|
|
405
|
+
copyBtn: { marginLeft: spacing.sm, padding: spacing.xs },
|
|
406
|
+
backdrop: { flex: 1, backgroundColor: 'rgba(0,0,0,0.35)' },
|
|
407
|
+
menu: {
|
|
408
|
+
position: 'absolute',
|
|
409
|
+
top: 56,
|
|
410
|
+
right: spacing.md,
|
|
411
|
+
minWidth: 200,
|
|
412
|
+
borderRadius: radii.lg,
|
|
413
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
414
|
+
paddingVertical: spacing.xs
|
|
415
|
+
},
|
|
416
|
+
menuItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: spacing.md, paddingHorizontal: spacing.md },
|
|
417
|
+
menuIcon: { marginRight: spacing.md },
|
|
418
|
+
menuLabel: { ...typography.body }
|
|
419
|
+
})
|
|
@@ -15,8 +15,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
|
15
15
|
import { useTranslation } from 'react-i18next'
|
|
16
16
|
// Same deep path WalletContext uses: the package root does not re-export the
|
|
17
17
|
// settings types.
|
|
18
|
-
import type { Certifier as WalletCertifier } from '@bsv/wallet-toolbox-mobile
|
|
18
|
+
import type { Certifier as WalletCertifier } from '@bsv/wallet-toolbox-mobile'
|
|
19
19
|
import validateTrust from '../validateTrust'
|
|
20
|
+
import { isPublicHttpsUrl } from '../../core/net/publicDestination'
|
|
20
21
|
import { GroupedSection } from '../components/ui/GroupedList'
|
|
21
22
|
import { showAlert } from '../components/ui/AlertCard'
|
|
22
23
|
import { haptics, useTheme, spacing, radii, typography, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
@@ -156,13 +157,93 @@ const orderChanged = (a: Certifier[], b: Certifier[]): boolean => {
|
|
|
156
157
|
|
|
157
158
|
const fetchWithTimeout = async (url: string, ms: number) => {
|
|
158
159
|
const controller = new AbortController()
|
|
160
|
+
const startedAt = Date.now()
|
|
159
161
|
const id = setTimeout(() => controller.abort(), ms)
|
|
162
|
+
let res: Response
|
|
160
163
|
try {
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
// `redirect: 'error'` so an on-path attacker cannot substitute the origin
|
|
165
|
+
// a trust-provider manifest is fetched from by redirecting the entered
|
|
166
|
+
// HTTPS origin somewhere else (XR-076 / SEC2-011) — a legitimate provider
|
|
167
|
+
// has no reason to redirect its own manifest.json.
|
|
168
|
+
res = await fetch(url, { signal: controller.signal, redirect: 'error' })
|
|
163
169
|
} finally {
|
|
164
170
|
clearTimeout(id)
|
|
165
171
|
}
|
|
172
|
+
// XR-075 (SEC2-090): `id` above bounds only the connection/headers --
|
|
173
|
+
// clearing it as soon as fetch() resolves left body consumption (the
|
|
174
|
+
// caller's later res.json()) completely unbounded: a provider that answers
|
|
175
|
+
// instantly and then stalls or drips its body could hang this screen's
|
|
176
|
+
// loading state forever. Mirrors core/identity/handleRegistry/resolver.ts's
|
|
177
|
+
// fetchWithTimeout: a second timer, scoped to the remaining time budget,
|
|
178
|
+
// keeps the same AbortController live through body consumption too, and
|
|
179
|
+
// the byte cap from readBoundedManifestJson (XR-074) applies here as well.
|
|
180
|
+
const originalJson = res.json.bind(res)
|
|
181
|
+
res.json = () =>
|
|
182
|
+
new Promise((resolve, reject) => {
|
|
183
|
+
const bodyTimer = setTimeout(
|
|
184
|
+
() => {
|
|
185
|
+
controller.abort()
|
|
186
|
+
reject(new Error(`The domain did not respond within ${Math.round(ms / 1000)} seconds`))
|
|
187
|
+
},
|
|
188
|
+
Math.max(0, ms - (Date.now() - startedAt))
|
|
189
|
+
)
|
|
190
|
+
void readBoundedManifestJson(res, originalJson)
|
|
191
|
+
.then(resolve, reject)
|
|
192
|
+
.finally(() => clearTimeout(bodyTimer))
|
|
193
|
+
})
|
|
194
|
+
return res
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* XR-074 (SEC2-012): every other JSON-consuming call site in the handle
|
|
199
|
+
* registry (resolver.ts's readBoundedJson, XR-077) bounds body bytes before
|
|
200
|
+
* parsing — this screen's own manifest fetch never got that treatment. A
|
|
201
|
+
* malicious or compromised trust-provider domain could otherwise answer with
|
|
202
|
+
* an arbitrarily large body and force a full JSON parse/allocation before
|
|
203
|
+
* validateTrust ever runs. A BRC-68 manifest is a few hundred bytes of JSON;
|
|
204
|
+
* this ceiling is comfortably over anything real while still bounding an
|
|
205
|
+
* attacker-controlled response.
|
|
206
|
+
*/
|
|
207
|
+
const MAX_TRUST_MANIFEST_BYTES = 64 * 1024
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Mirrors core/identity/handleRegistry/resolver.ts's readBoundedJson: a
|
|
211
|
+
* declared Content-Length over the cap is refused before anything is read;
|
|
212
|
+
* otherwise, when the runtime exposes the body as a stream, chunks are
|
|
213
|
+
* counted as they arrive and the read is aborted the instant the running
|
|
214
|
+
* total crosses the cap. `fallback` (the runtime's own `response.json`) is
|
|
215
|
+
* used only when no stream is available to count from.
|
|
216
|
+
*/
|
|
217
|
+
async function readBoundedManifestJson(res: Response, fallback: () => Promise<unknown>): Promise<unknown> {
|
|
218
|
+
const declared = res.headers?.get?.('content-length')
|
|
219
|
+
if (declared) {
|
|
220
|
+
const n = Number(declared)
|
|
221
|
+
if (Number.isFinite(n) && n > MAX_TRUST_MANIFEST_BYTES) {
|
|
222
|
+
throw new Error(`Trust manifest declared ${n} bytes, over the ${MAX_TRUST_MANIFEST_BYTES} byte limit`)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const reader = (res as { body?: ReadableStream<Uint8Array> | null }).body?.getReader?.()
|
|
226
|
+
if (!reader) return await fallback()
|
|
227
|
+
const chunks: Uint8Array[] = []
|
|
228
|
+
let total = 0
|
|
229
|
+
for (;;) {
|
|
230
|
+
const { done, value } = await reader.read()
|
|
231
|
+
if (done) break
|
|
232
|
+
if (!value) continue
|
|
233
|
+
total += value.byteLength
|
|
234
|
+
if (total > MAX_TRUST_MANIFEST_BYTES) {
|
|
235
|
+
await reader.cancel().catch(() => {})
|
|
236
|
+
throw new Error(`Trust manifest exceeded the ${MAX_TRUST_MANIFEST_BYTES} byte limit while streaming`)
|
|
237
|
+
}
|
|
238
|
+
chunks.push(value)
|
|
239
|
+
}
|
|
240
|
+
const merged = new Uint8Array(total)
|
|
241
|
+
let offset = 0
|
|
242
|
+
for (const chunk of chunks) {
|
|
243
|
+
merged.set(chunk, offset)
|
|
244
|
+
offset += chunk.byteLength
|
|
245
|
+
}
|
|
246
|
+
return JSON.parse(new TextDecoder().decode(merged))
|
|
166
247
|
}
|
|
167
248
|
|
|
168
249
|
// -------------------- Main Screen --------------------
|
|
@@ -465,7 +546,21 @@ function AddProviderModal({
|
|
|
465
546
|
if (!domain) return
|
|
466
547
|
setLoading(true)
|
|
467
548
|
setDomainError(null)
|
|
468
|
-
|
|
549
|
+
// An explicit http:// origin is a downgrade a passive network attacker
|
|
550
|
+
// can force just by intercepting the connection — refuse it outright
|
|
551
|
+
// rather than fetching it (XR-076 / SEC2-011). A bare domain always
|
|
552
|
+
// resolves to https://; an explicit https:// origin is passed through.
|
|
553
|
+
if (/^http:\/\//i.test(domain)) {
|
|
554
|
+
throw new Error('Trust providers must be imported over https://')
|
|
555
|
+
}
|
|
556
|
+
const url = domain.startsWith('https://') ? `${domain}/manifest.json` : `https://${domain}/manifest.json`
|
|
557
|
+
// A user-typed domain needs no DNS trickery to reach a loopback or
|
|
558
|
+
// private-network service directly (XR-073 / SEC2-057, SEC2-076) —
|
|
559
|
+
// refuse it before making the request, same host-class check the
|
|
560
|
+
// handle registry applies to a foreign domain's own capabilities.
|
|
561
|
+
if (!isPublicHttpsUrl(url)) {
|
|
562
|
+
throw new Error('That domain does not name a public trust provider')
|
|
563
|
+
}
|
|
469
564
|
let res: Response
|
|
470
565
|
try {
|
|
471
566
|
res = await fetchWithTimeout(url, 15000)
|
|
@@ -474,7 +569,7 @@ function AddProviderModal({
|
|
|
474
569
|
throw new Error('Could not fetch the trust data from that domain (it needs to follow the BRC-68 protocol)')
|
|
475
570
|
}
|
|
476
571
|
if (!res.ok) throw new Error('Failed to fetch trust manifest from that domain')
|
|
477
|
-
const json = await res.json()
|
|
572
|
+
const json = (await res.json()) as any
|
|
478
573
|
const trust = json?.babbage?.trust
|
|
479
574
|
if (!json?.babbage || !trust || typeof trust !== 'object') {
|
|
480
575
|
throw new Error('This domain does not support importing a trust relationship (it needs to follow the BRC-68 protocol)')
|