@bsv/expo-wallet-toolbox 0.4.0 → 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 +292 -0
- package/README.md +0 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/config.tsx +9 -1
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +409 -20
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +3368 -952
- package/core/index.ts +97 -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/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 +112 -1
- 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 +38 -16
- 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
|
@@ -2,19 +2,27 @@
|
|
|
2
2
|
* Run a block of token operations against a live key connection, hiding the
|
|
3
3
|
* transport difference:
|
|
4
4
|
*
|
|
5
|
-
* - **session-based
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - **persistent
|
|
11
|
-
*
|
|
12
|
-
* (WalletContext owns it for relock-on-unplug).
|
|
5
|
+
* - **session-based native drivers:** callers gather all user input before
|
|
6
|
+
* entering, then this starts discovery, waits for USB insertion or an NFC
|
|
7
|
+
* tap, runs every token operation against that selected device, and always
|
|
8
|
+
* tears discovery down before releasing the process-wide lease. On iOS the
|
|
9
|
+
* system NFC sheet covers the app; Android listens for USB and NFC together.
|
|
10
|
+
* - **persistent test readers:** the key is already available, so `work` runs
|
|
11
|
+
* immediately and the reader lifecycle is left untouched.
|
|
13
12
|
*
|
|
14
13
|
* `onWaiting` fires when we begin waiting for the tap, so the UI can prompt
|
|
15
|
-
* "hold your key to the top of your phone".
|
|
14
|
+
* "hold your key to the top of your phone". `opts.nfcMessage` is the localised
|
|
15
|
+
* text the iOS scan sheet itself shows; Android accepts and ignores it.
|
|
16
|
+
*
|
|
17
|
+
* This REJECTS instead of waiting forever (spec §3.3 step 2): the system sheet
|
|
18
|
+
* being cancelled → user-cancelled; the session dying with no key → no-key; the
|
|
19
|
+
* key leaving mid-`work` → key-removed-mid-op; and nothing at all arriving by
|
|
20
|
+
* the watchdog deadline → no-key (CoreNFC caps a session at 60 s; YubiKit
|
|
21
|
+
* swallows several failure paths, so no delegate fix makes this redundant).
|
|
16
22
|
*/
|
|
17
23
|
import { VaultDriver } from './driver'
|
|
24
|
+
import { acquireVaultHardwareLease } from './hardwareLease'
|
|
25
|
+
import { VaultError } from './types'
|
|
18
26
|
|
|
19
27
|
interface Deferred<T> {
|
|
20
28
|
promise: Promise<T>
|
|
@@ -31,29 +39,88 @@ function defer<T>(): Deferred<T> {
|
|
|
31
39
|
return { promise, resolve, reject }
|
|
32
40
|
}
|
|
33
41
|
|
|
42
|
+
const DEFAULT_ATTACH_TIMEOUT_MS = 65_000
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Ceiling on the card work itself, once a key HAS connected.
|
|
46
|
+
*
|
|
47
|
+
* The attach watchdog only guards the wait for a tap. Past that, `work()` was
|
|
48
|
+
* unbounded — and a native call that never settles holds the process-wide
|
|
49
|
+
* hardware lease forever, so every later Vault operation fails `ceremony-active`
|
|
50
|
+
* until the app is restarted. That is not hypothetical: YubiKit's `blockPuk`
|
|
51
|
+
* drops its completion for a status word outside the range it expects, which is
|
|
52
|
+
* why the Swift reset carries its own 30s watchdog.
|
|
53
|
+
*
|
|
54
|
+
* Generous, because real work is slow: a withdrawal signs up to
|
|
55
|
+
* VAULT_INPUTS_PER_TAP digests, each touch-gated with a 15s cache. This is a
|
|
56
|
+
* backstop against a lost completion, not a performance bound.
|
|
57
|
+
*/
|
|
58
|
+
const DEFAULT_WORK_TIMEOUT_MS = 180_000
|
|
59
|
+
|
|
34
60
|
export async function withKeySession<T>(
|
|
35
61
|
driver: VaultDriver,
|
|
36
62
|
work: () => Promise<T>,
|
|
37
|
-
onWaiting?: () => void
|
|
63
|
+
onWaiting?: () => void,
|
|
64
|
+
opts?: { nfcMessage?: string; attachTimeoutMs?: number; workTimeoutMs?: number }
|
|
38
65
|
): Promise<T> {
|
|
39
|
-
|
|
40
|
-
return work()
|
|
41
|
-
}
|
|
42
|
-
const connected = defer<void>()
|
|
43
|
-
const off = driver.onKeyEvent(e => {
|
|
44
|
-
if (e.type === 'attached') connected.resolve()
|
|
45
|
-
})
|
|
46
|
-
onWaiting?.()
|
|
47
|
-
driver.start()
|
|
66
|
+
const releaseLease = acquireVaultHardwareLease()
|
|
48
67
|
try {
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
if (!driver.sessionBased) return await work()
|
|
69
|
+
|
|
70
|
+
const connected = defer<void>()
|
|
71
|
+
// Rejects when the key leaves before `work` has resolved; raced against it.
|
|
72
|
+
const detached = defer<never>()
|
|
73
|
+
detached.promise.catch(() => {}) // never unhandled — it only matters inside the race
|
|
74
|
+
let connectedYet = false
|
|
75
|
+
const off = driver.onKeyEvent(e => {
|
|
76
|
+
if (e.type === 'attached') {
|
|
77
|
+
connectedYet = true
|
|
78
|
+
connected.resolve()
|
|
79
|
+
} else if (e.type === 'session-failed') {
|
|
80
|
+
connected.reject(new VaultError(e.code === 'user-cancelled' ? 'user-cancelled' : 'no-key'))
|
|
81
|
+
} else if (e.type === 'detached') {
|
|
82
|
+
const err = new VaultError('key-removed-mid-op', 'YubiKey removed during the operation')
|
|
83
|
+
if (!connectedYet) connected.reject(err)
|
|
84
|
+
detached.reject(err)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
const watchdog = setTimeout(
|
|
88
|
+
() => connected.reject(new VaultError('no-key', 'No key connected before the NFC session deadline')),
|
|
89
|
+
opts?.attachTimeoutMs ?? DEFAULT_ATTACH_TIMEOUT_MS
|
|
90
|
+
)
|
|
91
|
+
;(watchdog as { unref?: () => void }).unref?.()
|
|
53
92
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
93
|
+
onWaiting?.()
|
|
94
|
+
driver.start(opts?.nfcMessage)
|
|
95
|
+
await connected.promise
|
|
96
|
+
clearTimeout(watchdog)
|
|
97
|
+
// Bound the work as well as the wait. `stalled` is only ever a rejection,
|
|
98
|
+
// so a slow-but-live operation is unaffected; what it prevents is a native
|
|
99
|
+
// promise that never settles pinning the lease for the life of the process.
|
|
100
|
+
const stalled = defer<never>()
|
|
101
|
+
stalled.promise.catch(() => {})
|
|
102
|
+
const workWatchdog = setTimeout(
|
|
103
|
+
() => stalled.reject(new VaultError('nfc-lost', 'The YubiKey stopped responding')),
|
|
104
|
+
opts?.workTimeoutMs ?? DEFAULT_WORK_TIMEOUT_MS
|
|
105
|
+
)
|
|
106
|
+
;(workWatchdog as { unref?: () => void }).unref?.()
|
|
107
|
+
try {
|
|
108
|
+
return await Promise.race([work(), detached.promise, stalled.promise])
|
|
109
|
+
} finally {
|
|
110
|
+
clearTimeout(workWatchdog)
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
clearTimeout(watchdog)
|
|
114
|
+
off()
|
|
115
|
+
try {
|
|
116
|
+
driver.stop()
|
|
117
|
+
} catch {
|
|
118
|
+
/* stop is best-effort — dismissing the sheet must never throw */
|
|
119
|
+
}
|
|
57
120
|
}
|
|
121
|
+
} finally {
|
|
122
|
+
// Release only after all native listeners and discovery state are torn
|
|
123
|
+
// down, so a successor cannot be stopped by this operation's finally.
|
|
124
|
+
releaseLease()
|
|
58
125
|
}
|
|
59
126
|
}
|