@bsv/expo-wallet-toolbox 0.3.1 → 0.5.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 +311 -0
- package/README.md +52 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/config.tsx +21 -18
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +413 -23
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +3368 -952
- package/core/index.ts +107 -14
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- 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/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- 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/services/capWalletArgs.ts +8 -9
- package/core/services/externalOrigin.ts +39 -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 +19 -24
- package/core/storage/StorageExpoSQLite.ts +382 -56
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +0 -54
- package/core/storage/methods/listOutputsSql.ts +7 -3
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +263 -6
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +123 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +240 -0
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +25 -24
- 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 +43 -2
- package/ui/components/pay/RecipientField.tsx +49 -4
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/UniversalSend.tsx +534 -30
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- 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 +101 -17
- package/ui/components/wallet/AmountInput.tsx +77 -25
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +303 -0
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +50 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +130 -10
- package/ui/screens/SettingsScreen.tsx +18 -9
- 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 +42 -20
- package/ui/screens/WalletHomeScreen.tsx +417 -86
- 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 +79 -0
- 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/screens/PayScreen.tsx
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
typography,
|
|
34
34
|
useWallet,
|
|
35
35
|
validatePeerPayURI,
|
|
36
|
+
peerPayValidationMessage,
|
|
36
37
|
type Session,
|
|
37
38
|
takeProofNudge,
|
|
38
39
|
findOfflineActions,
|
|
@@ -40,6 +41,8 @@ import {
|
|
|
40
41
|
TaskSendOffline
|
|
41
42
|
} from '@bsv/expo-wallet-toolbox'
|
|
42
43
|
import { getPendingCorruptNotice, readUnprocessedPending } from '../../core/localpay/pending'
|
|
44
|
+
import { useAssetStatus, useMandala } from '../hooks/useMandala'
|
|
45
|
+
import { formatTokenAmountWithUnit } from '../tokenFormat'
|
|
43
46
|
import { nearbyAdvisory } from '../../core/localpay/nearbyAdvisory'
|
|
44
47
|
import { NearbyAdvisoryModal } from '../components/pay/NearbyAdvisoryModal'
|
|
45
48
|
import type { DismissTarget } from '../dismissTarget'
|
|
@@ -139,19 +142,25 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
139
142
|
identityKey?: string | string[]
|
|
140
143
|
sats?: string | string[]
|
|
141
144
|
peerpay?: string | string[]
|
|
145
|
+
asset?: string | string[]
|
|
142
146
|
}>()
|
|
143
147
|
|
|
144
148
|
const peerpay = firstParam(params.peerpay)
|
|
145
149
|
const peerPayValidation = useMemo(() => (peerpay ? validatePeerPayURI(peerpay) : null), [peerpay])
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
const peerPayInvalid = peerPayValidationMessage(peerPayValidation)
|
|
151
|
+
// A link's money and figure are adopted only from a link with no error at
|
|
152
|
+
// all: one that mixes `sats` with a token request must not be read as either.
|
|
153
|
+
const linkSats = peerPayValidation && !peerPayInvalid ? peerPayValidation.sats : undefined
|
|
154
|
+
const linkAsset = peerPayValidation && !peerPayInvalid ? peerPayValidation.asset : undefined
|
|
155
|
+
const linkAmount = peerPayValidation && !peerPayInvalid ? peerPayValidation.amount : undefined
|
|
151
156
|
|
|
152
157
|
const initialIdentityKey = peerPayValidation?.identityKey ?? firstParam(params.identityKey)
|
|
153
|
-
const satsParam =
|
|
158
|
+
const satsParam = linkSats ?? Number(firstParam(params.sats))
|
|
154
159
|
const initialSats = Number.isFinite(satsParam) && satsParam > 0 ? Number(satsParam) : undefined
|
|
160
|
+
const initialTokenAmount = useMemo(
|
|
161
|
+
() => (linkAsset && linkAmount ? { assetId: linkAsset, baseUnits: linkAmount } : undefined),
|
|
162
|
+
[linkAsset, linkAmount]
|
|
163
|
+
)
|
|
155
164
|
// Memoized: useRecipientInput re-adopts initialTarget whenever its identity changes.
|
|
156
165
|
const initialTarget = useMemo(
|
|
157
166
|
() =>
|
|
@@ -182,7 +191,89 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
182
191
|
)
|
|
183
192
|
/** Get side: the hub's raw amount, carried into the method. */
|
|
184
193
|
const [requestSats, setRequestSats] = useState('')
|
|
185
|
-
|
|
194
|
+
|
|
195
|
+
// ── the asset axis ──────────────────────────────────────────────────
|
|
196
|
+
// One piece of state for the whole screen, so the choice survives the hop
|
|
197
|
+
// from the hub into a method and back. `null` is BSV, and a wallet holding no
|
|
198
|
+
// token never leaves that value.
|
|
199
|
+
const mandala = useMandala()
|
|
200
|
+
const balances = mandala.balances ?? []
|
|
201
|
+
// A token request in a peerpay link selects its asset the way `?asset=` does,
|
|
202
|
+
// and a `sats=` link selects BSV. The choice is remembered against the link
|
|
203
|
+
// it was made under, so a second link arriving while this screen is mounted
|
|
204
|
+
// names its own money — the way its figure already does — while a choice
|
|
205
|
+
// made after the link (the picker) stands until the next link.
|
|
206
|
+
// Every term of the request, so two links for the same asset (a new payee,
|
|
207
|
+
// a new figure) are two links, not one.
|
|
208
|
+
const linkKey = `${initialIdentityKey ?? ''}|${linkAsset ?? ''}|${linkAmount ?? ''}|${linkSats ?? ''}`
|
|
209
|
+
const [choice, setChoice] = useState<{ forLink: string; assetId: string | null }>(() => ({
|
|
210
|
+
forLink: linkKey,
|
|
211
|
+
assetId: linkAsset ?? firstParam(params.asset) ?? null
|
|
212
|
+
}))
|
|
213
|
+
const selectedAssetId =
|
|
214
|
+
choice.forLink === linkKey ? choice.assetId : (linkAsset ?? (linkSats !== undefined ? null : choice.assetId))
|
|
215
|
+
const setSelectedAssetId = useCallback((id: string | null) => setChoice({ forLink: linkKey, assetId: id }), [linkKey])
|
|
216
|
+
const holding = balances.find(b => b.asset.assetId === selectedAssetId) ?? null
|
|
217
|
+
const asset = holding?.asset ?? null
|
|
218
|
+
/**
|
|
219
|
+
* The banner over the send form: a malformed link, or a valid token request
|
|
220
|
+
* for an asset this wallet does not hold — which the effect below turns
|
|
221
|
+
* back into BSV, and which must not do so silently: the payer would
|
|
222
|
+
* otherwise pay a different money than the one asked for, with no figure
|
|
223
|
+
* and no idea why.
|
|
224
|
+
*/
|
|
225
|
+
// No runtime on a BUILT wallet is a settled fact — the runtime is published
|
|
226
|
+
// at build, only on a chain with Mandala endpoints — where no runtime on a
|
|
227
|
+
// wallet still building is merely unknown and decides nothing yet.
|
|
228
|
+
const tokensNever = walletBuilt && !mandala.available
|
|
229
|
+
const peerPayNotice = useMemo(() => {
|
|
230
|
+
if (peerPayInvalid) return peerPayInvalid
|
|
231
|
+
if (
|
|
232
|
+
linkAsset &&
|
|
233
|
+
(tokensNever || (mandala.balances && !mandala.balances.some(b => b.asset.assetId === linkAsset)))
|
|
234
|
+
) {
|
|
235
|
+
return t('pay_asset_link_not_held')
|
|
236
|
+
}
|
|
237
|
+
return null
|
|
238
|
+
}, [peerPayInvalid, linkAsset, tokensNever, mandala.balances, t])
|
|
239
|
+
// Regulatory/registry facts for whichever asset is selected — RequestHub
|
|
240
|
+
// stays a plain prop-driven view, so this screen is the one that asks.
|
|
241
|
+
const selectedAssetStatus = useAssetStatus(asset?.assetId ?? null).status
|
|
242
|
+
// A deep link naming an asset this wallet does not hold selects BSV rather
|
|
243
|
+
// than a denomination with no balance behind it.
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (selectedAssetId && (tokensNever || (mandala.balances && !holding))) setSelectedAssetId(null)
|
|
246
|
+
}, [selectedAssetId, tokensNever, mandala.balances, holding, setSelectedAssetId])
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The request, in the unit it was actually typed in.
|
|
250
|
+
*
|
|
251
|
+
* `requestSatsFrom(requestSats)` would read base units as satoshis the moment
|
|
252
|
+
* an asset is selected — a 25.00 USDX request rendering as "2,500 satoshis"
|
|
253
|
+
* on the payee's own screen and binding the payer to that figure. The
|
|
254
|
+
* discriminated shape makes the unit impossible to lose.
|
|
255
|
+
*/
|
|
256
|
+
const request: { kind: 'bsv'; sats?: number } | { kind: 'token'; baseUnits?: number; assetId: string } = asset
|
|
257
|
+
? { kind: 'token', baseUnits: requestSatsFrom(requestSats), assetId: asset.assetId }
|
|
258
|
+
: { kind: 'bsv', sats: requestSatsFrom(requestSats) }
|
|
259
|
+
const initialNearbyRequest = useMemo(
|
|
260
|
+
() => ({
|
|
261
|
+
sats: requestSatsFrom(requestSats),
|
|
262
|
+
...(asset
|
|
263
|
+
? {
|
|
264
|
+
asset: {
|
|
265
|
+
id: asset.assetId,
|
|
266
|
+
label: asset.label,
|
|
267
|
+
ticker: asset.ticker,
|
|
268
|
+
decimals: asset.decimals,
|
|
269
|
+
overlayUrl: asset.overlayUrl,
|
|
270
|
+
overlayIdentityKey: asset.overlayIdentityKey
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
: {})
|
|
274
|
+
}),
|
|
275
|
+
[requestSats, asset]
|
|
276
|
+
)
|
|
186
277
|
// One camera raise per deep link; a cancelled advisory must not re-open it.
|
|
187
278
|
const [scanOnMount, setScanOnMount] = useState(paramCell === 'pay-nearby')
|
|
188
279
|
|
|
@@ -377,22 +468,41 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
377
468
|
<UniversalSend
|
|
378
469
|
initialTarget={initialTarget}
|
|
379
470
|
initialSats={initialSats}
|
|
471
|
+
initialTokenAmount={initialTokenAmount}
|
|
380
472
|
initialNotice={peerPayNotice}
|
|
381
473
|
openScannerOnMount={scanOnMount}
|
|
382
474
|
onNearbySession={onNearbySession}
|
|
475
|
+
selectedAssetId={selectedAssetId}
|
|
476
|
+
onSelectAsset={setSelectedAssetId}
|
|
383
477
|
dismissTo={dismissTo}
|
|
384
478
|
/>
|
|
385
479
|
</>
|
|
386
480
|
)
|
|
387
481
|
}
|
|
388
|
-
|
|
482
|
+
// Satoshis ONLY on the BSV branch. On the token branch the same digits are
|
|
483
|
+
// base units, and every satoshi-shaped prop below must not see them.
|
|
484
|
+
const sats = request.kind === 'bsv' ? request.sats : undefined
|
|
485
|
+
const requestedAmountText =
|
|
486
|
+
asset && request.kind === 'token' && request.baseUnits !== undefined
|
|
487
|
+
? (formatTokenAmountWithUnit(request.baseUnits, asset) ?? undefined)
|
|
488
|
+
: undefined
|
|
389
489
|
switch (method) {
|
|
390
490
|
case 'get-nearby':
|
|
391
491
|
return nearbyAdvisorySeen ? (
|
|
392
492
|
<NearbyFlow role="payee" initialRequest={initialNearbyRequest} onExit={goBack} dismissTo={dismissTo} />
|
|
393
493
|
) : null
|
|
394
494
|
case 'get-handle':
|
|
395
|
-
return
|
|
495
|
+
return (
|
|
496
|
+
<HandleReceive
|
|
497
|
+
initialSats={sats}
|
|
498
|
+
asset={asset ? { assetId: asset.assetId, ticker: asset.ticker, issuerName: asset.issuerName } : null}
|
|
499
|
+
requestedBaseUnits={request.kind === 'token' ? request.baseUnits : undefined}
|
|
500
|
+
requestedAmountText={requestedAmountText}
|
|
501
|
+
assetMessageBoxUrl={selectedAssetStatus?.messageBoxUrl ?? null}
|
|
502
|
+
onBsvInstead={() => setSelectedAssetId(null)}
|
|
503
|
+
dismissTo={dismissTo}
|
|
504
|
+
/>
|
|
505
|
+
)
|
|
396
506
|
case 'get-address':
|
|
397
507
|
return <AddressReceive initialSats={sats} dismissTo={dismissTo} />
|
|
398
508
|
default:
|
|
@@ -404,6 +514,10 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
404
514
|
onChangeRequestSats={setRequestSats}
|
|
405
515
|
onPick={setMethod}
|
|
406
516
|
online={online}
|
|
517
|
+
balances={balances}
|
|
518
|
+
selectedAssetId={selectedAssetId}
|
|
519
|
+
onSelectAsset={setSelectedAssetId}
|
|
520
|
+
assetStatus={selectedAssetStatus}
|
|
407
521
|
/>
|
|
408
522
|
</>
|
|
409
523
|
)
|
|
@@ -429,7 +543,13 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
429
543
|
<Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
430
544
|
{/* The screen names what it is doing: the direction, or the rail/method once one is live. */}
|
|
431
545
|
{direction === 'pay'
|
|
432
|
-
?
|
|
546
|
+
? nearbySession
|
|
547
|
+
? t('pay_cell_nearby_pay')
|
|
548
|
+
: asset
|
|
549
|
+
? // The coin was chosen on Home; this is the one place the
|
|
550
|
+
// Pay screen says which one it is armed with.
|
|
551
|
+
t('pay_direction_pay_asset', { ticker: asset.ticker })
|
|
552
|
+
: t('pay_direction_pay')
|
|
433
553
|
: t(method ? METHOD_TITLE_KEYS[method] : 'local_pay_request')}
|
|
434
554
|
</Text>
|
|
435
555
|
<View style={styles.headerBtn} />
|
|
@@ -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 } from '@bsv/expo-wallet-toolbox'
|
|
4
|
+
import { useTheme, spacing, typography, useWallet, isVaultAvailable } 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'
|
|
@@ -34,6 +34,10 @@ export function SettingsScreen() {
|
|
|
34
34
|
const { router } = loadExpoRouter()
|
|
35
35
|
const { managers, adminOriginator, selectedNetwork, txStatusVersion } = useWallet()
|
|
36
36
|
|
|
37
|
+
// Read during render, from the reactive network, so the row disappears on a
|
|
38
|
+
// switch to testnet without a remount.
|
|
39
|
+
const vaultAvailable = isVaultAvailable(selectedNetwork)
|
|
40
|
+
|
|
37
41
|
const balanceCacheKey = `cached_wallet_balance_${selectedNetwork}`
|
|
38
42
|
const balanceCacheTimestampKey = `cached_wallet_balance_ts_${selectedNetwork}`
|
|
39
43
|
const [accountBalance, setAccountBalance] = useState<number | null>(null)
|
|
@@ -132,15 +136,20 @@ export function SettingsScreen() {
|
|
|
132
136
|
icon="swap-horizontal-outline"
|
|
133
137
|
iconColor={colors.success}
|
|
134
138
|
onPress={() => router.push('/pay')}
|
|
139
|
+
isLast={!vaultAvailable}
|
|
135
140
|
/>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
{/* Same release and network gate as the home screen's Vault
|
|
142
|
+
destination (spec §5.5, task 11). */}
|
|
143
|
+
{vaultAvailable && (
|
|
144
|
+
<ListRow
|
|
145
|
+
label={t('vault_row_title')}
|
|
146
|
+
icon="safe"
|
|
147
|
+
iconFamily="material-community"
|
|
148
|
+
iconColor="#30B0C7"
|
|
149
|
+
onPress={() => router.push('/vault' as any)}
|
|
150
|
+
isLast
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
144
153
|
</GroupedSection>
|
|
145
154
|
|
|
146
155
|
{/* ── Settings drill-down ── */}
|