@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
import * as SQLite from 'expo-sqlite'
|
|
3
|
+
import {
|
|
4
|
+
type StorageExpoSQLite,
|
|
5
|
+
i18n,
|
|
6
|
+
parseDbFilename,
|
|
7
|
+
getRegisteredDbs,
|
|
8
|
+
registerDb,
|
|
9
|
+
selectLatestDb,
|
|
10
|
+
parseTimestampFromFilename
|
|
11
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
12
|
+
import { showAlert } from './components/ui/AlertCard'
|
|
13
|
+
import { showToast } from './components/ui/Toast'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* expo-file-system and expo-document-picker both ship untransformed ESM/raw-TS
|
|
17
|
+
* entry points that Jest cannot parse when eagerly pulled in via the `ui`
|
|
18
|
+
* package barrel, so both are required lazily here rather than imported at
|
|
19
|
+
* module scope — same pattern as this package's other native-module-boundary
|
|
20
|
+
* fixes (expo-router, expo-blur, ui/exportTransactions.ts's expo-file-system
|
|
21
|
+
* use). expo-sqlite stays a static import: it is fully intercepted by this
|
|
22
|
+
* repo's Jest `moduleNameMapper` (`^expo-sqlite$`), so the real ESM entry
|
|
23
|
+
* point is never loaded under test regardless of import style.
|
|
24
|
+
*/
|
|
25
|
+
function loadExpoFileSystem(): typeof import('expo-file-system') {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
27
|
+
return require('expo-file-system') as typeof import('expo-file-system')
|
|
28
|
+
}
|
|
29
|
+
function loadDocumentPicker(): typeof import('expo-document-picker') {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
31
|
+
return require('expo-document-picker') as typeof import('expo-document-picker')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ImportResult {
|
|
35
|
+
imported: boolean
|
|
36
|
+
filename?: string
|
|
37
|
+
keySuffix?: string
|
|
38
|
+
chain?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Let the user pick a wallet `.db` backup file and import it alongside any
|
|
43
|
+
* existing databases. The wallet context will use whichever database has the
|
|
44
|
+
* highest timestamp in its filename.
|
|
45
|
+
*
|
|
46
|
+
* Platform handling:
|
|
47
|
+
* - Cross-platform: reads the picked file as bytes, deserializes into an
|
|
48
|
+
* in-memory SQLite DB, opens a new file-backed DB with the target name,
|
|
49
|
+
* then uses backupDatabaseAsync to copy the data across. This avoids
|
|
50
|
+
* filesystem permission issues on Android.
|
|
51
|
+
*/
|
|
52
|
+
export async function importWalletDatabase(storage: StorageExpoSQLite | null): Promise<ImportResult> {
|
|
53
|
+
const { File } = loadExpoFileSystem()
|
|
54
|
+
const DocumentPicker = loadDocumentPicker()
|
|
55
|
+
|
|
56
|
+
// ── 1. Pick file ──────────────────────────────────────────────────────────
|
|
57
|
+
const result = await DocumentPicker.getDocumentAsync({
|
|
58
|
+
type: '*/*',
|
|
59
|
+
copyToCacheDirectory: true
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (result.canceled || !result.assets?.length) {
|
|
63
|
+
return { imported: false }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const asset = result.assets[0]
|
|
67
|
+
const pickedName = asset.name
|
|
68
|
+
|
|
69
|
+
// ── 2. Validate filename ──────────────────────────────────────────────────
|
|
70
|
+
const parsed = parseDbFilename(pickedName)
|
|
71
|
+
if (!parsed) {
|
|
72
|
+
await showAlert({
|
|
73
|
+
title: i18n.t('import_invalid_file'),
|
|
74
|
+
message: i18n.t('import_invalid_file_detail'),
|
|
75
|
+
buttons: [{ text: i18n.t('done'), key: 'ok' }],
|
|
76
|
+
})
|
|
77
|
+
return { imported: false }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { keySuffix, chain } = parsed
|
|
81
|
+
|
|
82
|
+
// If the imported file has no timestamp (legacy format), assign the current
|
|
83
|
+
// time so it gets a unique filename and participates in timestamp selection.
|
|
84
|
+
let targetFilename: string
|
|
85
|
+
if (parsed.timestamp === 0) {
|
|
86
|
+
const ts = Math.floor(Date.now() / 1000)
|
|
87
|
+
targetFilename = `wallet-${keySuffix}-${chain}net-${ts}.db`
|
|
88
|
+
} else {
|
|
89
|
+
targetFilename = pickedName
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── 3. Check for conflicts ────────────────────────────────────────────────
|
|
93
|
+
const existingDbs = await getRegisteredDbs(keySuffix, chain)
|
|
94
|
+
const importTs = parseTimestampFromFilename(targetFilename)
|
|
95
|
+
|
|
96
|
+
if (existingDbs.length > 0) {
|
|
97
|
+
const currentBest = selectLatestDb(existingDbs)
|
|
98
|
+
const currentBestTs = parseTimestampFromFilename(currentBest)
|
|
99
|
+
|
|
100
|
+
if (currentBestTs >= importTs) {
|
|
101
|
+
// Existing DB has a higher or equal timestamp — imported file will NOT
|
|
102
|
+
// become the active database.
|
|
103
|
+
const choice = await showAlert({
|
|
104
|
+
title: i18n.t('import_conflict_title'),
|
|
105
|
+
message: i18n.t('import_conflict_message'),
|
|
106
|
+
buttons: [
|
|
107
|
+
{ text: i18n.t('cancel'), style: 'cancel', key: 'cancel' },
|
|
108
|
+
{ text: i18n.t('import_anyway'), style: 'destructive', key: 'import' },
|
|
109
|
+
],
|
|
110
|
+
})
|
|
111
|
+
if (choice !== 'import') return { imported: false }
|
|
112
|
+
} else {
|
|
113
|
+
// Imported file will become the active database.
|
|
114
|
+
const choice = await showAlert({
|
|
115
|
+
title: i18n.t('import_confirm_title'),
|
|
116
|
+
message: i18n.t('import_confirm_message'),
|
|
117
|
+
buttons: [
|
|
118
|
+
{ text: i18n.t('cancel'), style: 'cancel', key: 'cancel' },
|
|
119
|
+
{ text: i18n.t('import_wallet_data'), key: 'import' },
|
|
120
|
+
],
|
|
121
|
+
})
|
|
122
|
+
if (choice !== 'import') return { imported: false }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ── 4. Read bytes from picked file ────────────────────────────────────────
|
|
127
|
+
const pickedFile = new File(asset.uri)
|
|
128
|
+
let bytes: Uint8Array
|
|
129
|
+
try {
|
|
130
|
+
bytes = await pickedFile.bytes()
|
|
131
|
+
} catch (e: any) {
|
|
132
|
+
console.error('[importDatabases] Failed to read picked file:', e.message)
|
|
133
|
+
showToast(e.message, { type: 'error' })
|
|
134
|
+
return { imported: false }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── 5. Place the database via deserialize → backup ────────────────────────
|
|
138
|
+
let sourceDb: SQLite.SQLiteDatabase | undefined
|
|
139
|
+
let destDb: SQLite.SQLiteDatabase | undefined
|
|
140
|
+
try {
|
|
141
|
+
// Deserialize the imported bytes into an in-memory database
|
|
142
|
+
sourceDb = await SQLite.deserializeDatabaseAsync(bytes)
|
|
143
|
+
|
|
144
|
+
// Open (or create) a file-backed database with the target filename.
|
|
145
|
+
// This places the file in the default expo-sqlite database directory.
|
|
146
|
+
destDb = await SQLite.openDatabaseAsync(targetFilename)
|
|
147
|
+
|
|
148
|
+
// Copy all data from the in-memory source into the file-backed dest
|
|
149
|
+
await SQLite.backupDatabaseAsync({
|
|
150
|
+
sourceDatabase: sourceDb,
|
|
151
|
+
destDatabase: destDb
|
|
152
|
+
})
|
|
153
|
+
} catch (e: any) {
|
|
154
|
+
console.error('[importDatabases] Failed to place database:', e.message)
|
|
155
|
+
showToast(e.message, { type: 'error' })
|
|
156
|
+
return { imported: false }
|
|
157
|
+
} finally {
|
|
158
|
+
try {
|
|
159
|
+
await sourceDb?.closeAsync()
|
|
160
|
+
} catch {}
|
|
161
|
+
try {
|
|
162
|
+
await destDb?.closeAsync()
|
|
163
|
+
} catch {}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── 6. Register in the wallet DB registry ─────────────────────────────────
|
|
167
|
+
await registerDb(keySuffix, chain, targetFilename)
|
|
168
|
+
|
|
169
|
+
return { imported: true, filename: targetFilename, keySuffix, chain }
|
|
170
|
+
}
|
package/ui/index.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export const CANARY_UI = 'ui'
|
|
2
|
+
|
|
3
|
+
// Shared UI primitives (components/ui)
|
|
4
|
+
export { showAlert, AlertHost } from './components/ui/AlertCard'
|
|
5
|
+
export type { AlertButton, AlertOptions } from './components/ui/AlertCard'
|
|
6
|
+
export { showChoiceSheet, choiceSheetOrder } from './components/ui/ChoiceSheet'
|
|
7
|
+
export { default as AppLogo } from './components/ui/AppLogo'
|
|
8
|
+
export { BlurChrome } from './components/ui/BlurChrome'
|
|
9
|
+
export { default as Celebration } from './components/ui/Celebration'
|
|
10
|
+
export { default as CustomSafeArea } from './components/ui/CustomSafeArea'
|
|
11
|
+
export { ErrorBoundary } from './components/ui/ErrorBoundary'
|
|
12
|
+
export { GroupedList, GroupedSection } from './components/ui/GroupedList'
|
|
13
|
+
export { IconButton } from './components/ui/IconButton'
|
|
14
|
+
export { ListRow } from './components/ui/ListRow'
|
|
15
|
+
export { default as PermissionSheet } from './components/ui/PermissionSheet'
|
|
16
|
+
export { default as PressableScale } from './components/ui/PressableScale'
|
|
17
|
+
export { default as PresenceRow } from './components/ui/PresenceRow'
|
|
18
|
+
export type { PresenceState } from './components/ui/PresenceRow'
|
|
19
|
+
export { default as ScreenGradient } from './components/ui/ScreenGradient'
|
|
20
|
+
export { default as Sheet } from './components/ui/Sheet'
|
|
21
|
+
export { showToast, ToastHost } from './components/ui/Toast'
|
|
22
|
+
export type { ToastType } from './components/ui/Toast'
|
|
23
|
+
|
|
24
|
+
// Security UI (components/security)
|
|
25
|
+
export { default as WalletLockNotice } from './components/security/WalletLockNotice'
|
|
26
|
+
|
|
27
|
+
// Wallet UI (components/wallet) — AmountDisplay pre-moved here (Task 19) as a
|
|
28
|
+
// hard dependency of PermissionSheet; the rest moved in Task 20.
|
|
29
|
+
export { default as AmountDisplay } from './components/wallet/AmountDisplay'
|
|
30
|
+
export { default as ActivityRow, formatRowTime, type ActivityAction } from './components/wallet/ActivityRow'
|
|
31
|
+
export { AmountInput, SatsAmountInput, SEND_MAX_VALUE } from './components/wallet/AmountInput'
|
|
32
|
+
export { default as Balance } from './components/wallet/Balance'
|
|
33
|
+
|
|
34
|
+
// Wallet home screen (Task 20 — extracted from app/index.tsx)
|
|
35
|
+
export { WalletHomeScreen } from './screens/WalletHomeScreen'
|
|
36
|
+
export type { WalletHomeScreenProps } from './screens/WalletHomeScreen'
|
|
37
|
+
|
|
38
|
+
// Wallet-screen support utilities, moved alongside the screen (Task 20)
|
|
39
|
+
export * from './txStatus'
|
|
40
|
+
export { exportTransactionsAsCsv } from './exportTransactions'
|
|
41
|
+
|
|
42
|
+
// Identity resolution and spendable-balance helpers, promoted here (Task 21)
|
|
43
|
+
// as hard dependencies of the pay UI below — same flat-at-root treatment as
|
|
44
|
+
// txStatus.ts/exportTransactions.ts (Task 20).
|
|
45
|
+
export * from './resolveIdentity'
|
|
46
|
+
export { useSpendableBalance } from './hooks/useSpendableBalance'
|
|
47
|
+
|
|
48
|
+
// QR scanner (components/QRScanner) — pulled forward from its originally
|
|
49
|
+
// planned Task 24 move because UniversalSend/NearbyFlow below
|
|
50
|
+
// depend on it directly; see Task 21 report for the full rationale.
|
|
51
|
+
export { default as QRScanner } from './components/QRScanner'
|
|
52
|
+
|
|
53
|
+
// Pay + local-payment UI (components/pay), the P2P payment surfaces (Task 21)
|
|
54
|
+
export { default as AddressReceive } from './components/pay/AddressReceive'
|
|
55
|
+
export { default as AvailableBalance } from './components/pay/AvailableBalance'
|
|
56
|
+
export { default as HandleReceive } from './components/pay/HandleReceive'
|
|
57
|
+
export { useMessageBoxConfig, ConfigPanel } from './components/pay/MessageBoxConfig'
|
|
58
|
+
export { default as NearbyFlow, type NearbyFlowProps } from './components/pay/NearbyFlow'
|
|
59
|
+
export { NearbyAdvisoryModal } from './components/pay/NearbyAdvisoryModal'
|
|
60
|
+
export { default as OfflineNotice, offlineActionDetails, type OfflineNoticeProps } from './components/pay/OfflineNotice'
|
|
61
|
+
export { default as PayCellRow, type PayCellRowProps } from './components/pay/PayCellRow'
|
|
62
|
+
export {
|
|
63
|
+
default as RequestHub,
|
|
64
|
+
requestSatsFrom,
|
|
65
|
+
type RequestHubProps,
|
|
66
|
+
type RequestMethod
|
|
67
|
+
} from './components/pay/RequestHub'
|
|
68
|
+
export { PayField, PayAmountField, ConsequenceNote, PayCta, RecipientSummary } from './components/pay/PayForm'
|
|
69
|
+
export { default as PaymentQrDisplay } from './components/pay/PaymentQrDisplay'
|
|
70
|
+
export { default as PaymentSuccessOverlay, type ReceivedOverlayProps } from './components/pay/PaymentSuccessOverlay'
|
|
71
|
+
export { default as RecipientField } from './components/pay/RecipientField'
|
|
72
|
+
export { default as ResultBanner } from './components/pay/ResultBanner'
|
|
73
|
+
export { default as UniversalSend, type UniversalSendProps } from './components/pay/UniversalSend'
|
|
74
|
+
export {
|
|
75
|
+
peerPayValidationMessage,
|
|
76
|
+
classifyIdentitySearchError,
|
|
77
|
+
useRecipientInput,
|
|
78
|
+
type RecipientTarget,
|
|
79
|
+
type RecipientInlineError,
|
|
80
|
+
type UseRecipientInputOptions
|
|
81
|
+
} from './components/pay/useRecipientInput'
|
|
82
|
+
|
|
83
|
+
// Pay screen (Task 21 — extracted from app/pay.tsx) and the online-status hook
|
|
84
|
+
// it, and several pay cells above, depend on.
|
|
85
|
+
export { PayScreen } from './screens/PayScreen'
|
|
86
|
+
export { useOnline } from './hooks/useOnline'
|
|
87
|
+
|
|
88
|
+
// Settings + wallet-config screens (Task 22 — extracted from app/settings.tsx
|
|
89
|
+
// and app/wallet-config.tsx), plus the recovery/backup utilities they, the
|
|
90
|
+
// share-scanning route (app/auth/scan-shares.tsx) and scripts/generate-pdf.ts
|
|
91
|
+
// depend on. backupShares.ts moved in alongside printRecoveryShares.ts
|
|
92
|
+
// (rather than staying a `@/utils` import reaching outside the package) so
|
|
93
|
+
// printRecoveryShares.ts never imports across the package boundary.
|
|
94
|
+
export { SettingsScreen } from './screens/SettingsScreen'
|
|
95
|
+
export { WalletConfigScreen } from './screens/WalletConfigScreen'
|
|
96
|
+
export { WalletCheckScreen, isReviewActionsError, promptCheckWallet } from './screens/WalletCheckScreen'
|
|
97
|
+
export { exportAllWalletDatabases } from './exportDatabases'
|
|
98
|
+
export { importWalletDatabase, type ImportResult } from './importDatabases'
|
|
99
|
+
export { printRecoveryShares, type PrintSharesSources, type PrintSharesResult } from './printRecoveryShares'
|
|
100
|
+
export {
|
|
101
|
+
parseShare,
|
|
102
|
+
validateShareCompatibility,
|
|
103
|
+
recoverSecretFromShares,
|
|
104
|
+
generatePrintHTML,
|
|
105
|
+
type ParsedShare,
|
|
106
|
+
type RecoveredSecret
|
|
107
|
+
} from './backupShares'
|
|
108
|
+
|
|
109
|
+
// Vault UI (components/vault) + vault screens (Task 23 — extracted from
|
|
110
|
+
// app/vault.tsx, app/vault-recover.tsx, app/vault-transfer.tsx). Also home
|
|
111
|
+
// to VaultCeremonySheet, mounted at the app-shell level (app/_layout.tsx)
|
|
112
|
+
// alongside PermissionSheet/ToastHost above.
|
|
113
|
+
export { EnrollWizard } from './components/vault/EnrollWizard'
|
|
114
|
+
export { PassphraseField, type PassphraseFieldProps } from './components/vault/PassphraseField'
|
|
115
|
+
export { PhraseBackupSheet } from './components/vault/PhraseBackupSheet'
|
|
116
|
+
export { BackupReminderSheet } from './components/wallet/BackupReminderSheet'
|
|
117
|
+
export { BiometricAdvisoryModal } from './components/wallet/BiometricAdvisoryModal'
|
|
118
|
+
export { ImportFromBackupPrompt } from './components/wallet/ImportFromBackupPrompt'
|
|
119
|
+
export { VaultCeremonySheet } from './components/vault/VaultCeremonySheet'
|
|
120
|
+
export { useVaultBalance } from './hooks/useVaultBalance'
|
|
121
|
+
export { VaultScreen } from './screens/VaultScreen'
|
|
122
|
+
export { VaultRecoverScreen } from './screens/VaultRecoverScreen'
|
|
123
|
+
export { VaultTransferScreen } from './screens/VaultTransferScreen'
|
|
124
|
+
|
|
125
|
+
// Connections, pair, trust, and logs screens (Task 24 — extracted from
|
|
126
|
+
// app/connections.tsx, app/pair.tsx, app/trust.tsx, app/logs.tsx).
|
|
127
|
+
// validateTrust.ts/isImageUrl.ts moved alongside TrustScreen as its only
|
|
128
|
+
// dependency in app-root utils/ (deterministicColor.ts/deterministicImage.ts
|
|
129
|
+
// stayed put — nothing moving in this task references them). QRScanner was
|
|
130
|
+
// already pulled forward in Task 21; see the components section above.
|
|
131
|
+
export { ConnectionsScreen } from './screens/ConnectionsScreen'
|
|
132
|
+
export { PairScreen } from './screens/PairScreen'
|
|
133
|
+
export { TrustScreen } from './screens/TrustScreen'
|
|
134
|
+
export { LogsScreen } from './screens/LogsScreen'
|
|
135
|
+
export { default as validateTrust } from './validateTrust'
|
|
136
|
+
export { default as isImageUrl } from './isImageUrl'
|
package/ui/isImageUrl.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-tap "print my recovery shares", shared by Settings, onboarding and vault
|
|
3
|
+
* enrollment.
|
|
4
|
+
*
|
|
5
|
+
* WHAT THESE SHARES COVER
|
|
6
|
+
*
|
|
7
|
+
* For a wallet with a mnemonic, the shares split the mnemonic ENTROPY
|
|
8
|
+
* (BRC-157). Any two rebuild the phrase, and therefore the seed, m/0'/0', the
|
|
9
|
+
* everyday balance AND the vault. The printed sheet is seed-equivalent paper —
|
|
10
|
+
* treat it with the same care as the phrase itself.
|
|
11
|
+
*
|
|
12
|
+
* For a wallet restored from legacy paper there is no mnemonic to frame, so
|
|
13
|
+
* the shares split the raw recovered key, exactly as before. Those restore
|
|
14
|
+
* spending authority only and can never open a vault. That cohort cannot
|
|
15
|
+
* upgrade in place; their remedy is to sweep to a fresh wallet.
|
|
16
|
+
*
|
|
17
|
+
* 24-word phrases are refused: their entropy is 32 bytes, which fills the
|
|
18
|
+
* split secret completely and leaves no room for the tag that tells the two
|
|
19
|
+
* formats apart on recovery.
|
|
20
|
+
*/
|
|
21
|
+
import { Mnemonic, PrivateKey } from '@bsv/sdk'
|
|
22
|
+
import {
|
|
23
|
+
ENTROPY_BYTES,
|
|
24
|
+
generateEntropyShares,
|
|
25
|
+
generateLegacyKeyShares,
|
|
26
|
+
generatePrintHTML
|
|
27
|
+
} from './backupShares'
|
|
28
|
+
import { recoverMnemonicWallet } from '@bsv/expo-wallet-toolbox'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* expo-print ships an untransformed ESM entry point that Jest cannot parse
|
|
32
|
+
* when eagerly pulled in via the `ui` package barrel, so it is required
|
|
33
|
+
* lazily here rather than imported at module scope — same pattern as this
|
|
34
|
+
* package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
35
|
+
*/
|
|
36
|
+
function loadExpoPrint(): typeof import('expo-print') {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
+
return require('expo-print') as typeof import('expo-print')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PrintSharesSources {
|
|
42
|
+
/** The wallet mnemonic, when the wallet has one. */
|
|
43
|
+
mnemonic: string | null
|
|
44
|
+
/** WIF of a share-restored wallet, which has no mnemonic. */
|
|
45
|
+
recoveredKeyWif?: string | null
|
|
46
|
+
/**
|
|
47
|
+
* Display name for the printed recovery instructions (e.g. "In BSV
|
|
48
|
+
* Wallet, go to..."). Host apps should pass their own display name (see
|
|
49
|
+
* UserContext's `appName` for the equivalent pattern) — defaults to a
|
|
50
|
+
* generic placeholder so this package makes no assumption about which
|
|
51
|
+
* app is embedding it.
|
|
52
|
+
*/
|
|
53
|
+
appName?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type PrintSharesResult =
|
|
57
|
+
| { ok: true; format: 'entropy' | 'legacy' }
|
|
58
|
+
| { ok: false; reason: 'no-material' | 'unsupported-word-count' }
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Present the print sheet for a 2-of-3 recovery share set.
|
|
62
|
+
*
|
|
63
|
+
* Never throws for the "cannot print" cases — callers surface the reason as a
|
|
64
|
+
* message. A dismissed print sheet still rejects from expo-print and is the
|
|
65
|
+
* caller's business.
|
|
66
|
+
*/
|
|
67
|
+
export async function printRecoveryShares(
|
|
68
|
+
sources: PrintSharesSources
|
|
69
|
+
): Promise<PrintSharesResult> {
|
|
70
|
+
const Print = loadExpoPrint()
|
|
71
|
+
let shares: string[]
|
|
72
|
+
let identityKey: string
|
|
73
|
+
let format: 'entropy' | 'legacy'
|
|
74
|
+
|
|
75
|
+
if (sources.mnemonic) {
|
|
76
|
+
const entropy = Mnemonic.fromString(sources.mnemonic).toEntropy()
|
|
77
|
+
if (entropy.length !== ENTROPY_BYTES) return { ok: false, reason: 'unsupported-word-count' }
|
|
78
|
+
|
|
79
|
+
shares = generateEntropyShares(entropy)
|
|
80
|
+
identityKey = recoverMnemonicWallet(sources.mnemonic).identityKey
|
|
81
|
+
format = 'entropy'
|
|
82
|
+
} else if (sources.recoveredKeyWif) {
|
|
83
|
+
const priv = PrivateKey.fromWif(sources.recoveredKeyWif)
|
|
84
|
+
shares = generateLegacyKeyShares(Array.from(priv.toArray()))
|
|
85
|
+
identityKey = priv.toPublicKey().toString()
|
|
86
|
+
format = 'legacy'
|
|
87
|
+
} else {
|
|
88
|
+
return { ok: false, reason: 'no-material' }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await Print.printAsync({ html: await generatePrintHTML(shares, identityKey, format, sources.appName) })
|
|
92
|
+
return { ok: true, format }
|
|
93
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity resolution — turning a bare BSV identity key into something a person
|
|
3
|
+
* recognises.
|
|
4
|
+
*
|
|
5
|
+
* Lifted verbatim out of app/payments.tsx so more than one screen can use it.
|
|
6
|
+
* Nothing here is new behaviour; the only change is the file it lives in.
|
|
7
|
+
*
|
|
8
|
+
* Every entry point is NETWORK-DEPENDENT and BEST-EFFORT. `resolveByIdentityKey`
|
|
9
|
+
* reaches an overlay through the wallet, and avatar resolution can add a second
|
|
10
|
+
* hop through UHRP storage. Callers must treat a null result as "not known
|
|
11
|
+
* here, right now" and never as a fact about the peer — and must never make a
|
|
12
|
+
* money decision wait on one. A nearby payment in particular may well be
|
|
13
|
+
* happening precisely because the network is unreachable.
|
|
14
|
+
*/
|
|
15
|
+
import { IdentityClient, StorageDownloader } from '@bsv/sdk'
|
|
16
|
+
import type { DisplayableIdentity, WalletInterface } from '@bsv/sdk'
|
|
17
|
+
|
|
18
|
+
/** Drops repeats by identityKey, keeping the first occurrence. */
|
|
19
|
+
export const uniqueIdentities = (results: DisplayableIdentity[]) => {
|
|
20
|
+
return results.filter((identity, index) => {
|
|
21
|
+
return results.findIndex(i => i.identityKey === identity.identityKey) === index
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Picks a usable avatar URL. An http(s) URL wins outright; anything else is
|
|
27
|
+
* treated as a UHRP hash and resolved through storage, falling back to the raw
|
|
28
|
+
* value so a downloader outage degrades to a broken image rather than a throw.
|
|
29
|
+
*/
|
|
30
|
+
export async function resolveAvatarURL(urls: (string | undefined)[]): Promise<string | undefined> {
|
|
31
|
+
const defined = urls.filter((u): u is string => !!u)
|
|
32
|
+
const httpUrl = defined.find(u => u.startsWith('http'))
|
|
33
|
+
if (httpUrl) return httpUrl
|
|
34
|
+
const nonHttp = defined.find(u => !!u)
|
|
35
|
+
if (!nonHttp) return undefined
|
|
36
|
+
try {
|
|
37
|
+
const downloader = new StorageDownloader()
|
|
38
|
+
const resolved = await downloader.resolve(nonHttp)
|
|
39
|
+
return resolved[0] ?? nonHttp
|
|
40
|
+
} catch {
|
|
41
|
+
return nonHttp
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Folds several certificates into one record, first non-empty value winning. */
|
|
46
|
+
export async function mergeIdentityRecords(
|
|
47
|
+
records: DisplayableIdentity[]
|
|
48
|
+
): Promise<DisplayableIdentity | null> {
|
|
49
|
+
const merged = records.reduce<DisplayableIdentity | null>((acc, cur) => {
|
|
50
|
+
if (!acc) return cur
|
|
51
|
+
return {
|
|
52
|
+
identityKey: acc.identityKey,
|
|
53
|
+
name: acc.name || cur.name,
|
|
54
|
+
avatarURL: acc.avatarURL || cur.avatarURL,
|
|
55
|
+
abbreviatedKey: acc.abbreviatedKey || cur.abbreviatedKey,
|
|
56
|
+
badgeIconURL: acc.badgeIconURL || cur.badgeIconURL,
|
|
57
|
+
badgeLabel: acc.badgeLabel || cur.badgeLabel,
|
|
58
|
+
badgeClickURL: acc.badgeClickURL || cur.badgeClickURL
|
|
59
|
+
}
|
|
60
|
+
}, null)
|
|
61
|
+
if (!merged) return null
|
|
62
|
+
const avatarURL = (await resolveAvatarURL(records.map(r => r.avatarURL))) || ''
|
|
63
|
+
return { ...merged, avatarURL }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolves one identity key. Never rejects — a lookup failure and an unknown
|
|
68
|
+
* peer are indistinguishable to the caller by design, because the UI treatment
|
|
69
|
+
* is the same in both cases.
|
|
70
|
+
*/
|
|
71
|
+
export async function resolveIdentity(
|
|
72
|
+
idClient: IdentityClient,
|
|
73
|
+
sender: string
|
|
74
|
+
): Promise<readonly [string, DisplayableIdentity | null]> {
|
|
75
|
+
try {
|
|
76
|
+
const results = await idClient.resolveByIdentityKey({ identityKey: sender, seekPermission: false })
|
|
77
|
+
return [sender, await mergeIdentityRecords(results)] as const
|
|
78
|
+
} catch {
|
|
79
|
+
return [sender, null] as const
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Attribute search. Unlike resolveIdentity this one DOES throw; callers catch. */
|
|
84
|
+
export async function searchIdentities(
|
|
85
|
+
idClient: IdentityClient,
|
|
86
|
+
text: string
|
|
87
|
+
): Promise<DisplayableIdentity[]> {
|
|
88
|
+
const results = await idClient.resolveByAttributes({
|
|
89
|
+
attributes: { any: text.trim() },
|
|
90
|
+
limit: 5,
|
|
91
|
+
seekPermission: false
|
|
92
|
+
})
|
|
93
|
+
return uniqueIdentities(results)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* An IdentityClient for this wallet, or null if one cannot be constructed.
|
|
98
|
+
*
|
|
99
|
+
* Swallowing the throw is deliberate and matches the original call site: every
|
|
100
|
+
* identity feature is decorative relative to the payment itself, so a client
|
|
101
|
+
* that will not build must leave the screen fully usable.
|
|
102
|
+
*/
|
|
103
|
+
export function makeIdentityClient(
|
|
104
|
+
wallet: WalletInterface | null | undefined,
|
|
105
|
+
adminOriginator: string | undefined
|
|
106
|
+
): IdentityClient | null {
|
|
107
|
+
if (!wallet) return null
|
|
108
|
+
try {
|
|
109
|
+
return new IdentityClient(wallet, undefined, adminOriginator)
|
|
110
|
+
} catch {
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The best short label for a peer: their resolved name, else null.
|
|
117
|
+
*
|
|
118
|
+
* Returns null rather than a placeholder so callers decide how an unknown peer
|
|
119
|
+
* reads in their own context — "Unknown" is wrong in a status line that is
|
|
120
|
+
* otherwise silent about identity.
|
|
121
|
+
*/
|
|
122
|
+
export function identityLabel(identity: DisplayableIdentity | null | undefined): string | null {
|
|
123
|
+
const name = identity?.name?.trim()
|
|
124
|
+
return name ? name : null
|
|
125
|
+
}
|