@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
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { AppChain } from './config'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service endpoints and API keys for one chain.
|
|
5
|
+
*
|
|
6
|
+
* Every field is optional: an omitted field falls back to the built-in public
|
|
7
|
+
* default in `walletServiceConfig.ts`. Omitting the whole chain entry is the
|
|
8
|
+
* same as passing `{}`.
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolboxServiceConfig {
|
|
11
|
+
arcUrl?: string
|
|
12
|
+
arcApiKey?: string
|
|
13
|
+
chaintracksUrl?: string
|
|
14
|
+
whatsOnChainApiKey?: string
|
|
15
|
+
taalApiKey?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The three endpoints a Mandala stablecoin deployment is addressed by, for one
|
|
20
|
+
* chain (offline-settlement spec §12: endpoints live in the host's toolbox
|
|
21
|
+
* config, never in an env read inside this package).
|
|
22
|
+
*
|
|
23
|
+
* All three are required together, and that is the point: `overlayUrl` without
|
|
24
|
+
* `overlayIdentityKey` is an overlay whose σ_I nothing can verify, which is
|
|
25
|
+
* indistinguishable from no overlay at all — so a half-stated chain entry is
|
|
26
|
+
* treated as an unstated one (`getMandalaEndpoints` returns undefined) rather
|
|
27
|
+
* than producing a runtime that can submit but never prove.
|
|
28
|
+
*/
|
|
29
|
+
export interface MandalaEndpointConfig {
|
|
30
|
+
/** Origin of the issuer's overlay, no trailing slash — `${overlayUrl}/submit` is posted to. */
|
|
31
|
+
overlayUrl: string
|
|
32
|
+
/** 66-hex compressed key; the ONLY key an admission signature may come from. */
|
|
33
|
+
overlayIdentityKey: string
|
|
34
|
+
/** MessageBox host for the `'mandala-payments'` box (the handle rail). */
|
|
35
|
+
messageBoxUrl: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Runtime configuration supplied by the host app.
|
|
40
|
+
*
|
|
41
|
+
* The toolbox reads no `process.env` of its own. Expo's Babel preset refuses to
|
|
42
|
+
* inline `EXPO_PUBLIC_*` for any file whose path contains `node_modules`
|
|
43
|
+
* (`babel-preset-expo/build/common.js` — `!isNodeModule && ...`), so an env read
|
|
44
|
+
* inside this package is `undefined` in every production bundle of a host that
|
|
45
|
+
* installs it from npm, while working fine in dev and in a host that consumes it
|
|
46
|
+
* from source. That asymmetry is what silently disabled backup for three weeks.
|
|
47
|
+
*
|
|
48
|
+
* So the host reads its own env — where inlining works — and states the values
|
|
49
|
+
* here, once, before rendering:
|
|
50
|
+
*
|
|
51
|
+
* configureToolbox({
|
|
52
|
+
* backupUrl: process.env.EXPO_PUBLIC_BACKUP_URL ?? null,
|
|
53
|
+
* services: { main: { arcUrl: process.env.EXPO_PUBLIC_ARC_URL } }
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* There is deliberately no env fallback here. A fallback would restore exactly
|
|
57
|
+
* the silent path this seam exists to close.
|
|
58
|
+
*/
|
|
59
|
+
export interface ToolboxConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Origin of the encrypted wallet-backup service — no trailing slash, no path.
|
|
62
|
+
* The BRC-103/104 handshake is posted to the origin root, so a path prefix
|
|
63
|
+
* makes every request fail authentication.
|
|
64
|
+
*
|
|
65
|
+
* `null` disables backup entirely: no monitor task is registered, nothing is
|
|
66
|
+
* sent, and the backup UI does not render. It is required rather than
|
|
67
|
+
* optional so that every build states its endpoint — including stating that
|
|
68
|
+
* it has none. An upgrading host that passes nothing gets a type error, not
|
|
69
|
+
* another empty string.
|
|
70
|
+
*/
|
|
71
|
+
backupUrl: string | null
|
|
72
|
+
/** Per-chain service endpoints and keys. Omitted chains use built-in defaults. */
|
|
73
|
+
services?: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
74
|
+
/**
|
|
75
|
+
* Per-chain Mandala stablecoin endpoints. There is deliberately NO default:
|
|
76
|
+
* an issuer's overlay and its identity key are deployment facts this package
|
|
77
|
+
* cannot guess, and guessing one would mean verifying admissions against the
|
|
78
|
+
* wrong key. A chain with no complete entry has no Mandala runtime
|
|
79
|
+
* (`useWallet().mandala` is undefined). Which chains carry an entry is the
|
|
80
|
+
* host's whole policy — e.g. testnet only while the issuer's overlay is a
|
|
81
|
+
* testnet deployment.
|
|
82
|
+
*/
|
|
83
|
+
mandala?: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
84
|
+
/**
|
|
85
|
+
* Release gate for the YubiKey vault (spec §0, D15). Default false: the home
|
|
86
|
+
* button and Settings row are hidden, the vault route shows "Not available
|
|
87
|
+
* yet", and no code path may enrol hardware or create a vault output. Turned
|
|
88
|
+
* on per build profile by the host (EXPO_PUBLIC_VAULT_ENABLED in eas.json),
|
|
89
|
+
* never read from process.env here.
|
|
90
|
+
*/
|
|
91
|
+
vaultEnabled?: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface ResolvedConfig {
|
|
95
|
+
backupUrl: string
|
|
96
|
+
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
97
|
+
mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
98
|
+
vaultEnabled: boolean
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let current: ResolvedConfig | null = null
|
|
102
|
+
|
|
103
|
+
const NOT_CONFIGURED =
|
|
104
|
+
'expo-wallet-toolbox is not configured. Call configureToolbox({ backupUrl, services }) ' +
|
|
105
|
+
'from the host app entry point, before rendering WalletContextProvider. ' +
|
|
106
|
+
'Pass backupUrl: null to disable backup deliberately.'
|
|
107
|
+
|
|
108
|
+
function normalizeBackupUrl(raw: string): string {
|
|
109
|
+
const trimmed = raw.trim().replace(/\/+$/, '')
|
|
110
|
+
if (trimmed === '') return ''
|
|
111
|
+
let parsed: URL
|
|
112
|
+
try {
|
|
113
|
+
parsed = new URL(trimmed)
|
|
114
|
+
} catch {
|
|
115
|
+
throw new Error(`configureToolbox: backupUrl is not a valid URL: ${raw}`)
|
|
116
|
+
}
|
|
117
|
+
if (parsed.pathname !== '' && parsed.pathname !== '/') {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`configureToolbox: backupUrl must be an origin with no path (got "${parsed.pathname}"). ` +
|
|
120
|
+
'The BRC-103/104 handshake posts to the origin root, so a path prefix fails authentication.'
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
if (parsed.search !== '' || parsed.hash !== '') {
|
|
124
|
+
throw new Error(`configureToolbox: backupUrl must be a bare origin, with no query or fragment: ${raw}`)
|
|
125
|
+
}
|
|
126
|
+
return trimmed
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Install the host's runtime configuration. Call once, at app entry, before
|
|
131
|
+
* anything from this package renders or builds a wallet.
|
|
132
|
+
*
|
|
133
|
+
* Calling it again replaces the configuration wholesale — it is not merged.
|
|
134
|
+
*/
|
|
135
|
+
export function configureToolbox(config: ToolboxConfig): void {
|
|
136
|
+
if (config == null || !('backupUrl' in config)) {
|
|
137
|
+
throw new Error('configureToolbox: backupUrl is required. Pass null to disable backup.')
|
|
138
|
+
}
|
|
139
|
+
current = {
|
|
140
|
+
backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
|
|
141
|
+
services: config.services ?? {},
|
|
142
|
+
mandala: config.mandala ?? {},
|
|
143
|
+
vaultEnabled: config.vaultEnabled === true
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** True once `configureToolbox` has run. For hosts that want to assert their own ordering. */
|
|
148
|
+
export function isToolboxConfigured(): boolean {
|
|
149
|
+
return current !== null
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The configured backup origin, or `''` when the host passed `null`.
|
|
154
|
+
* Throws if the host never configured the toolbox at all — an unconfigured
|
|
155
|
+
* build must fail loudly, not quietly behave like a disabled one.
|
|
156
|
+
*/
|
|
157
|
+
export function getBackupUrl(): string {
|
|
158
|
+
if (current === null) throw new Error(NOT_CONFIGURED)
|
|
159
|
+
return current.backupUrl
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Service endpoints for a chain. Missing fields are the caller's to default. */
|
|
163
|
+
export function getServiceConfig(chain: AppChain): ToolboxServiceConfig {
|
|
164
|
+
if (current === null) throw new Error(NOT_CONFIGURED)
|
|
165
|
+
return current.services[chain] ?? {}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The Mandala endpoints for a chain, or undefined when this build has none.
|
|
172
|
+
*
|
|
173
|
+
* Deliberately NOT throwing when the toolbox is unconfigured, for the same
|
|
174
|
+
* reason `isVaultEnabled` does not: this is read while building the wallet and
|
|
175
|
+
* while rendering, and "unconfigured" must look like "Mandala off" rather than
|
|
176
|
+
* crash a wallet that never wanted stablecoins.
|
|
177
|
+
*
|
|
178
|
+
* A partial or malformed entry answers undefined rather than a half-usable
|
|
179
|
+
* object: an overlay URL with no verifiable identity key can submit but can
|
|
180
|
+
* never prove an admission, which is the one shape this feature must not have.
|
|
181
|
+
*/
|
|
182
|
+
export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | undefined {
|
|
183
|
+
const entry = current?.mandala[chain]
|
|
184
|
+
if (!entry) return undefined
|
|
185
|
+
const overlayUrl = entry.overlayUrl?.trim().replace(/\/+$/, '') ?? ''
|
|
186
|
+
const overlayIdentityKey = entry.overlayIdentityKey?.trim() ?? ''
|
|
187
|
+
const messageBoxUrl = entry.messageBoxUrl?.trim().replace(/\/+$/, '') ?? ''
|
|
188
|
+
if (overlayUrl === '' || messageBoxUrl === '') return undefined
|
|
189
|
+
if (!COMPRESSED_KEY.test(overlayIdentityKey)) return undefined
|
|
190
|
+
return { overlayUrl, overlayIdentityKey, messageBoxUrl }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Whether Mandala stablecoins are available on this network.
|
|
195
|
+
*
|
|
196
|
+
* Exactly the chains the host stated complete endpoints for — nothing else
|
|
197
|
+
* gates it. (v1 hardcoded mainnet on top of that, ux §2; since 2026-09-15 the
|
|
198
|
+
* host's `mandala` map is the whole policy, so a testnet-only rollout is a
|
|
199
|
+
* config choice, not a code change.) Chain is a parameter, not a module read,
|
|
200
|
+
* for the same reason `isVaultAvailable`'s is: screens must re-render when the
|
|
201
|
+
* user switches network.
|
|
202
|
+
*/
|
|
203
|
+
export function isMandalaAvailable(chain: AppChain): boolean {
|
|
204
|
+
return getMandalaEndpoints(chain) !== undefined
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether this build may enrol vault hardware or create vault outputs.
|
|
209
|
+
*
|
|
210
|
+
* Deliberately NOT throwing when unconfigured: this is read while rendering
|
|
211
|
+
* the home screen, and "unconfigured" must look like "vault off", not crash.
|
|
212
|
+
*/
|
|
213
|
+
export function isVaultEnabled(): boolean {
|
|
214
|
+
return current?.vaultEnabled ?? false
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Whether the vault may be used on this network.
|
|
219
|
+
*
|
|
220
|
+
* Vault is mainnet-only by product decision (2026-09-12): there is no reason to
|
|
221
|
+
* hold different hardware keys per network, and high-value storage is
|
|
222
|
+
* meaningless on a chain whose coins are worthless. Keeping it off testnet also
|
|
223
|
+
* removes a fund-loss path — the enrollment wizard's reset offer reads enrolled
|
|
224
|
+
* serials from one wallet+chain namespace, but a YubiKey is physical and shared
|
|
225
|
+
* across all of them, so a testnet wizard could offer to factory-reset a live
|
|
226
|
+
* mainnet signer.
|
|
227
|
+
*
|
|
228
|
+
* Chain is a parameter, not a module read: screens must re-render when the user
|
|
229
|
+
* switches network, and `selectedNetwork` from the wallet context is what makes
|
|
230
|
+
* that reactive. Keeping it a parameter also keeps this module a leaf — it must
|
|
231
|
+
* never import `vaultStore`.
|
|
232
|
+
*/
|
|
233
|
+
export function isVaultAvailable(chain: AppChain): boolean {
|
|
234
|
+
return isVaultEnabled() && chain === 'main'
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Test-only: drop the installed configuration. */
|
|
238
|
+
export function resetToolboxConfig(): void {
|
|
239
|
+
current = null
|
|
240
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Ordered Check-my-wallet repair steps.
|
|
3
3
|
*
|
|
4
4
|
* Records first so phantom spendable outputs do not poison later sends.
|
|
5
|
-
* freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs
|
|
5
|
+
* freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs + reviewTokens.removed
|
|
6
6
|
*
|
|
7
7
|
* A port throw marks that step error; later steps still run.
|
|
8
8
|
*/
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export type WalletCheckStepId =
|
|
11
11
|
| 'online'
|
|
12
12
|
| 'records'
|
|
13
|
+
| 'tokens'
|
|
13
14
|
| 'coins'
|
|
14
15
|
| 'proofs'
|
|
15
16
|
| 'missed_payments'
|
|
@@ -48,6 +49,13 @@ export interface WalletCheckPorts {
|
|
|
48
49
|
/** Whether the recovery phrase was written down or the shares printed. */
|
|
49
50
|
checkPhraseBackup: () => Promise<{ backedUp: boolean }>
|
|
50
51
|
reviewSpendable: () => Promise<{ released: number; recovered: number }>
|
|
52
|
+
/**
|
|
53
|
+
* Token settlement rows and held coins, checked against the issuer's overlay.
|
|
54
|
+
* `removed` = transactions the overlay refused, now failed locally; `unattested`
|
|
55
|
+
* = rows/coins the overlay has no record of, reported and left alone. Throws
|
|
56
|
+
* when the overlay cannot be reached.
|
|
57
|
+
*/
|
|
58
|
+
reviewTokens: () => Promise<{ settled: number; removed: number; unattested: number }>
|
|
51
59
|
checkProofs: () => Promise<{ repaired: number }>
|
|
52
60
|
reviewStatus: () => Promise<{ failedTxs: number; restoredInputs: number }>
|
|
53
61
|
releaseStuck: () => Promise<{ released: number }>
|
|
@@ -144,6 +152,14 @@ export async function runWalletCheck(
|
|
|
144
152
|
})
|
|
145
153
|
record('records', records, () => ((records as { ok?: boolean }).ok === true ? 'ok' : 'error'))
|
|
146
154
|
|
|
155
|
+
onStep('tokens')
|
|
156
|
+
const tokens = await guard(skips, 'tokens', { settled: 0, removed: 0, unattested: 0 }, () =>
|
|
157
|
+
settle(() => ports.reviewTokens(), { settled: 0, removed: 0, unattested: 0 })
|
|
158
|
+
)
|
|
159
|
+
record('tokens', tokens, () =>
|
|
160
|
+
!(tokens as { ok?: boolean }).ok ? 'error' : tokens.value.unattested > 0 ? 'attention' : 'ok'
|
|
161
|
+
)
|
|
162
|
+
|
|
147
163
|
onStep('proofs')
|
|
148
164
|
const proofs = await guard(skips, 'proofs', { repaired: 0 }, () =>
|
|
149
165
|
settle(() => ports.checkProofs(), { repaired: 0 })
|
|
@@ -185,7 +201,8 @@ export async function runWalletCheck(
|
|
|
185
201
|
record('coins', spendable, () => ((spendable as { ok?: boolean }).ok === true ? 'ok' : 'error'))
|
|
186
202
|
|
|
187
203
|
return {
|
|
188
|
-
freedCoins:
|
|
204
|
+
freedCoins:
|
|
205
|
+
spendable.value.released + records.value.stuckReleased + records.value.restoredInputs + tokens.value.removed,
|
|
189
206
|
recoveredPayments: missed.value.accepted + missed.value.imported,
|
|
190
207
|
repairedProofs: proofs.value.repaired,
|
|
191
208
|
steps,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@bsv/air-gap": "^0.1.1",
|
|
33
33
|
"@bsv/backup-cache-client": "^0.1.0",
|
|
34
34
|
"@bsv/btms-permission-module": "^1.1.0",
|
|
35
|
+
"@bsv/mandala": "^0.2.0",
|
|
35
36
|
"@bsv/message-box-client": "^2.2.1",
|
|
36
37
|
"@bsv/react-native-localpay-transport": "*",
|
|
37
38
|
"@bsv/sdk": "^2.4.1",
|
|
@@ -41,41 +42,41 @@
|
|
|
41
42
|
"@noble/curves": "^2.3.0",
|
|
42
43
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
43
44
|
"@react-native-clipboard/clipboard": "^1.16.2",
|
|
44
|
-
"@react-native-community/netinfo": "^
|
|
45
|
+
"@react-native-community/netinfo": "^12.0.1",
|
|
45
46
|
"@urbit/sigil-js": "^2.2.0",
|
|
46
47
|
"date-fns": "^4.1.0",
|
|
47
|
-
"expo-audio": "~
|
|
48
|
-
"expo-blur": "~
|
|
49
|
-
"expo-camera": "~
|
|
50
|
-
"expo-clipboard": "~
|
|
51
|
-
"expo-crypto": "~
|
|
52
|
-
"expo-device": "~
|
|
53
|
-
"expo-document-picker": "~
|
|
54
|
-
"expo-file-system": "~
|
|
55
|
-
"expo-haptics": "~
|
|
56
|
-
"expo-image": "~
|
|
57
|
-
"expo-local-authentication": "~
|
|
58
|
-
"expo-localization": "~
|
|
59
|
-
"expo-print": "~
|
|
60
|
-
"expo-router": "~
|
|
61
|
-
"expo-secure-store": "~
|
|
62
|
-
"expo-sharing": "~
|
|
63
|
-
"expo-sqlite": "~
|
|
64
|
-
"expo-status-bar": "~
|
|
48
|
+
"expo-audio": "~57.0.5",
|
|
49
|
+
"expo-blur": "~57.0.3",
|
|
50
|
+
"expo-camera": "~57.0.5",
|
|
51
|
+
"expo-clipboard": "~57.0.2",
|
|
52
|
+
"expo-crypto": "~57.0.3",
|
|
53
|
+
"expo-device": "~57.0.2",
|
|
54
|
+
"expo-document-picker": "~57.0.2",
|
|
55
|
+
"expo-file-system": "~57.0.7",
|
|
56
|
+
"expo-haptics": "~57.0.3",
|
|
57
|
+
"expo-image": "~57.0.5",
|
|
58
|
+
"expo-local-authentication": "~57.0.3",
|
|
59
|
+
"expo-localization": "~57.0.2",
|
|
60
|
+
"expo-print": "~57.0.2",
|
|
61
|
+
"expo-router": "~57.0.21",
|
|
62
|
+
"expo-secure-store": "~57.0.4",
|
|
63
|
+
"expo-sharing": "~57.0.19",
|
|
64
|
+
"expo-sqlite": "~57.0.3",
|
|
65
|
+
"expo-status-bar": "~57.0.1",
|
|
65
66
|
"i18next": "^25.2.1",
|
|
66
67
|
"mobx": "^6.13.7",
|
|
67
68
|
"mobx-react-lite": "^4.1.0",
|
|
68
69
|
"qrcode": "^1.5.4",
|
|
69
70
|
"react": "^19.2.0",
|
|
70
|
-
"react-i18next": "^
|
|
71
|
-
"react-native": "^0.
|
|
71
|
+
"react-i18next": "^16.6.6",
|
|
72
|
+
"react-native": "^0.86.3",
|
|
72
73
|
"react-native-engine-native": "*",
|
|
73
|
-
"react-native-gesture-handler": "~2.
|
|
74
|
+
"react-native-gesture-handler": "~2.32.0",
|
|
74
75
|
"react-native-localize": "^3.4.1",
|
|
75
76
|
"react-native-nitro-modules": "^0.35.2",
|
|
76
77
|
"react-native-qrcode-svg": "^6.3.15",
|
|
77
78
|
"react-native-reanimated": "^4.2.1",
|
|
78
|
-
"react-native-safe-area-context": "~5.
|
|
79
|
+
"react-native-safe-area-context": "~5.7.0",
|
|
79
80
|
"react-native-secp-native": "*",
|
|
80
81
|
"react-native-sse": "^1.2.1",
|
|
81
82
|
"react-native-svg": "^15.15.3",
|
|
@@ -271,7 +271,7 @@ const styles = StyleSheet.create({
|
|
|
271
271
|
|
|
272
272
|
// ── Scanner overlay ────────────────────────────────────────────────────
|
|
273
273
|
overlay: {
|
|
274
|
-
...StyleSheet.
|
|
274
|
+
...StyleSheet.absoluteFill,
|
|
275
275
|
justifyContent: 'space-between'
|
|
276
276
|
},
|
|
277
277
|
overlayTop: {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "You can't be paid in USDX yet" — the screen that replaces a payment code
|
|
3
|
+
* rather than showing one that cannot work.
|
|
4
|
+
*
|
|
5
|
+
* Showing the QR anyway would manufacture a failure inside someone else's app,
|
|
6
|
+
* attributed to nothing: the payer scans, their wallet refuses, and neither
|
|
7
|
+
* party can see why. Withholding the code and naming the party who decides is
|
|
8
|
+
* the whole of error prevention in one screen.
|
|
9
|
+
*
|
|
10
|
+
* It deliberately offers no "How to get registered" affordance. There is no
|
|
11
|
+
* route inside this wallet to become registered — registration is the issuer's
|
|
12
|
+
* chain, gated by whatever the issuer requires — so a button for it would
|
|
13
|
+
* dead-end. What it offers instead is the rail that works right now.
|
|
14
|
+
*/
|
|
15
|
+
import React from 'react'
|
|
16
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
17
|
+
import { useTranslation } from 'react-i18next'
|
|
18
|
+
import { hitTargets, radii, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
|
|
19
|
+
import PressableScale from '../ui/PressableScale'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
23
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
24
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
25
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
26
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
27
|
+
*/
|
|
28
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
29
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
30
|
+
function loadIonicons(): IoniconsComponent {
|
|
31
|
+
if (!ioniconsComponent) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
34
|
+
}
|
|
35
|
+
return ioniconsComponent
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AdmissionNoticeProps {
|
|
39
|
+
ticker: string
|
|
40
|
+
/** Resolved issuer name; falls back to "the issuer" rather than a hex key. */
|
|
41
|
+
issuerName?: string
|
|
42
|
+
/**
|
|
43
|
+
* The runtime's own plain reason, when it has one. It wins over the generic
|
|
44
|
+
* body: a specific true sentence beats a general true sentence.
|
|
45
|
+
*/
|
|
46
|
+
reason?: string | null
|
|
47
|
+
onBsvInstead: () => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default function AdmissionNotice({ ticker, issuerName, reason, onBsvInstead }: AdmissionNoticeProps) {
|
|
51
|
+
const { t } = useTranslation()
|
|
52
|
+
const { colors } = useTheme()
|
|
53
|
+
const Ionicons = loadIonicons()
|
|
54
|
+
const issuer = issuerName || t('token_issuer_fallback')
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
// One region, so the title and the reason are read together before the
|
|
58
|
+
// route row rather than as three unrelated announcements.
|
|
59
|
+
<View style={styles.wrap} accessibilityRole="summary" accessible>
|
|
60
|
+
<Ionicons name="alert-circle-outline" size={48} color={colors.textTertiary} />
|
|
61
|
+
<Text style={[styles.title, { color: colors.textPrimary }]} textBreakStrategy="balanced">
|
|
62
|
+
{t('token_admit_title', { ticker })}
|
|
63
|
+
</Text>
|
|
64
|
+
<Text style={[styles.body, { color: colors.textSecondary }]} textBreakStrategy="balanced">
|
|
65
|
+
{reason || t('token_admit_body', { issuer, ticker })}
|
|
66
|
+
</Text>
|
|
67
|
+
<PressableScale
|
|
68
|
+
onPress={onBsvInstead}
|
|
69
|
+
haptic="tap"
|
|
70
|
+
style={[styles.route, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}
|
|
71
|
+
accessibilityRole="button"
|
|
72
|
+
accessibilityLabel={t('token_admit_bsv_instead')}
|
|
73
|
+
>
|
|
74
|
+
<Ionicons name="arrow-down" size={18} color={colors.textPrimary} />
|
|
75
|
+
<Text style={[styles.routeLabel, { color: colors.textPrimary }]}>{t('token_admit_bsv_instead')}</Text>
|
|
76
|
+
<Ionicons name="chevron-forward" size={18} color={colors.textQuaternary} />
|
|
77
|
+
</PressableScale>
|
|
78
|
+
</View>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const styles = StyleSheet.create({
|
|
83
|
+
wrap: { alignItems: 'center', paddingHorizontal: spacing.xl, paddingVertical: spacing.xxl, gap: spacing.md },
|
|
84
|
+
title: { ...typography.title3, textAlign: 'center' },
|
|
85
|
+
body: { ...typography.subhead, textAlign: 'center', maxWidth: 320 },
|
|
86
|
+
route: {
|
|
87
|
+
flexDirection: 'row',
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
gap: spacing.md,
|
|
90
|
+
alignSelf: 'stretch',
|
|
91
|
+
minHeight: hitTargets.minimum,
|
|
92
|
+
paddingVertical: spacing.md,
|
|
93
|
+
paddingHorizontal: spacing.lg,
|
|
94
|
+
borderRadius: radii.lg,
|
|
95
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
96
|
+
marginTop: spacing.md
|
|
97
|
+
},
|
|
98
|
+
routeLabel: { ...typography.headline, fontWeight: '600', flex: 1 }
|
|
99
|
+
})
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Paying with" / "Getting paid in" — the asset question, asked inside the flow
|
|
3
|
+
* that already asks who and how much.
|
|
4
|
+
*
|
|
5
|
+
* The asset is a property of a payment, not a mode of the wallet: there is no
|
|
6
|
+
* token screen to switch into and no setting to change, because a person who
|
|
7
|
+
* holds two kinds of money does not want a second wallet, they want to choose
|
|
8
|
+
* once, here, at the moment it matters.
|
|
9
|
+
*
|
|
10
|
+
* It sits ABOVE the recipient field on purpose. Choosing an asset changes the
|
|
11
|
+
* unit of the amount, the available figure and which recipient shapes are even
|
|
12
|
+
* legal (a token has no address rail), so asking it second would silently
|
|
13
|
+
* invalidate work the user had already done.
|
|
14
|
+
*
|
|
15
|
+
* The control is the display-currency expander from Settings, verbatim: a row
|
|
16
|
+
* with a down-chevron that opens an inline list with a trailing checkmark. Not
|
|
17
|
+
* a segmented control — that caps out at four options and this list is as long
|
|
18
|
+
* as the user's holdings. It is layout, not animation, so Reduce Motion needs
|
|
19
|
+
* no special case.
|
|
20
|
+
*
|
|
21
|
+
* Renders `null` when the wallet holds no token, which is the whole of "a
|
|
22
|
+
* wallet that has never held one renders today's screen".
|
|
23
|
+
*/
|
|
24
|
+
import React, { useState } from 'react'
|
|
25
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
26
|
+
import { hitTargets, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
|
|
27
|
+
import type { TokenBalance } from '../../../core/mandala/runtime'
|
|
28
|
+
import { ListRow } from '../ui/ListRow'
|
|
29
|
+
import { formatTokenAmountWithUnit } from '../../tokenFormat'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
33
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
34
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
35
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
36
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
37
|
+
*/
|
|
38
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
39
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
40
|
+
function loadIonicons(): IoniconsComponent {
|
|
41
|
+
if (!ioniconsComponent) {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
43
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
44
|
+
}
|
|
45
|
+
return ioniconsComponent
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The BSV row's label is the literal string, like `mainnet`/`testnet` elsewhere
|
|
50
|
+
* in this app: a `pay_asset_bsv` key would be byte-identical in all twelve
|
|
51
|
+
* locales and fail translation parity for being untranslated.
|
|
52
|
+
*/
|
|
53
|
+
const BSV_LABEL = 'BSV'
|
|
54
|
+
|
|
55
|
+
export interface AssetPickerProps {
|
|
56
|
+
/** Held assets. Empty means no picker at all. */
|
|
57
|
+
balances: TokenBalance[]
|
|
58
|
+
/** `null` selects BSV — the default, and what every existing flow assumes. */
|
|
59
|
+
selected: string | null
|
|
60
|
+
onSelect: (assetId: string | null) => void
|
|
61
|
+
/** Shown beside the BSV row; `null` is UNKNOWN and prints nothing. */
|
|
62
|
+
bsvBalanceText?: string | null
|
|
63
|
+
/** Whether the collapsed row shows each asset's figure (Pay does; Get paid doesn't). */
|
|
64
|
+
showFigures?: boolean
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default function AssetPicker({
|
|
68
|
+
balances,
|
|
69
|
+
selected,
|
|
70
|
+
onSelect,
|
|
71
|
+
bsvBalanceText = null,
|
|
72
|
+
showFigures = true
|
|
73
|
+
}: AssetPickerProps) {
|
|
74
|
+
const { colors } = useTheme()
|
|
75
|
+
const [expanded, setExpanded] = useState(false)
|
|
76
|
+
|
|
77
|
+
if (balances.length === 0) return null
|
|
78
|
+
|
|
79
|
+
const current = balances.find(b => b.asset.assetId === selected) ?? null
|
|
80
|
+
const currentLabel = current ? current.asset.label || current.asset.ticker : BSV_LABEL
|
|
81
|
+
const currentFigure = current
|
|
82
|
+
? formatTokenAmountWithUnit(current.baseUnits, current.asset)
|
|
83
|
+
: bsvBalanceText
|
|
84
|
+
|
|
85
|
+
const choose = (assetId: string | null) => {
|
|
86
|
+
onSelect(assetId)
|
|
87
|
+
setExpanded(false)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<View>
|
|
92
|
+
<View
|
|
93
|
+
accessible
|
|
94
|
+
accessibilityRole="button"
|
|
95
|
+
accessibilityState={{ expanded }}
|
|
96
|
+
accessibilityLabel={[currentLabel, showFigures ? currentFigure : null].filter(Boolean).join(', ')}
|
|
97
|
+
>
|
|
98
|
+
<ListRow
|
|
99
|
+
label={currentLabel}
|
|
100
|
+
value={showFigures && currentFigure ? currentFigure : undefined}
|
|
101
|
+
icon="cash-outline"
|
|
102
|
+
isLast={!expanded}
|
|
103
|
+
onPress={() => setExpanded(e => !e)}
|
|
104
|
+
showChevron
|
|
105
|
+
chevronDown
|
|
106
|
+
/>
|
|
107
|
+
</View>
|
|
108
|
+
{expanded && (
|
|
109
|
+
<View style={[styles.options, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}>
|
|
110
|
+
<AssetOption
|
|
111
|
+
label={BSV_LABEL}
|
|
112
|
+
figure={showFigures ? bsvBalanceText : null}
|
|
113
|
+
selected={selected === null}
|
|
114
|
+
onPress={() => choose(null)}
|
|
115
|
+
/>
|
|
116
|
+
{balances.map(b => (
|
|
117
|
+
<AssetOption
|
|
118
|
+
key={b.asset.assetId}
|
|
119
|
+
label={b.asset.label || b.asset.ticker}
|
|
120
|
+
figure={showFigures ? formatTokenAmountWithUnit(b.baseUnits, b.asset) : null}
|
|
121
|
+
selected={selected === b.asset.assetId}
|
|
122
|
+
onPress={() => choose(b.asset.assetId)}
|
|
123
|
+
/>
|
|
124
|
+
))}
|
|
125
|
+
</View>
|
|
126
|
+
)}
|
|
127
|
+
</View>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function AssetOption({
|
|
132
|
+
label,
|
|
133
|
+
figure,
|
|
134
|
+
selected,
|
|
135
|
+
onPress
|
|
136
|
+
}: {
|
|
137
|
+
label: string
|
|
138
|
+
figure?: string | null
|
|
139
|
+
selected: boolean
|
|
140
|
+
onPress: () => void
|
|
141
|
+
}) {
|
|
142
|
+
const { colors } = useTheme()
|
|
143
|
+
const Ionicons = loadIonicons()
|
|
144
|
+
return (
|
|
145
|
+
<TouchableOpacity
|
|
146
|
+
style={styles.option}
|
|
147
|
+
onPress={onPress}
|
|
148
|
+
activeOpacity={0.6}
|
|
149
|
+
accessibilityRole="button"
|
|
150
|
+
// The checkmark is not the only signal: state travels with the element.
|
|
151
|
+
accessibilityState={{ selected }}
|
|
152
|
+
accessibilityLabel={[label, figure].filter(Boolean).join(', ')}
|
|
153
|
+
>
|
|
154
|
+
<Text style={[styles.optionLabel, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
155
|
+
{label}
|
|
156
|
+
</Text>
|
|
157
|
+
{!!figure && (
|
|
158
|
+
<Text style={[styles.optionFigure, { color: colors.textSecondary }]} numberOfLines={1}>
|
|
159
|
+
{figure}
|
|
160
|
+
</Text>
|
|
161
|
+
)}
|
|
162
|
+
{selected && <Ionicons name="checkmark" size={20} color={colors.accent} style={styles.check} />}
|
|
163
|
+
</TouchableOpacity>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const styles = StyleSheet.create({
|
|
168
|
+
options: {
|
|
169
|
+
borderBottomLeftRadius: 12,
|
|
170
|
+
borderBottomRightRadius: 12,
|
|
171
|
+
borderTopWidth: StyleSheet.hairlineWidth
|
|
172
|
+
},
|
|
173
|
+
option: {
|
|
174
|
+
flexDirection: 'row',
|
|
175
|
+
alignItems: 'center',
|
|
176
|
+
gap: spacing.sm,
|
|
177
|
+
minHeight: hitTargets.minimum,
|
|
178
|
+
paddingVertical: spacing.md,
|
|
179
|
+
paddingHorizontal: spacing.lg
|
|
180
|
+
},
|
|
181
|
+
optionLabel: { ...typography.body, flex: 1 },
|
|
182
|
+
optionFigure: { ...typography.footnote, fontVariant: ['tabular-nums'] },
|
|
183
|
+
check: { marginLeft: spacing.xs }
|
|
184
|
+
})
|