@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/core/pay/rails/nearby.ts
CHANGED
|
@@ -42,16 +42,126 @@ export {
|
|
|
42
42
|
markSessionSpent,
|
|
43
43
|
processPending,
|
|
44
44
|
savePending,
|
|
45
|
-
type PendingPayment
|
|
45
|
+
type PendingPayment,
|
|
46
|
+
type TokenCreditedHook
|
|
46
47
|
} from '../../localpay/pending'
|
|
47
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The two settlement-durability hooks the rail's callers wire (§4.2, §4.3).
|
|
50
|
+
*
|
|
51
|
+
* `TokenHeldHook` runs BEFORE the receiver's `internalizeAction`, so the
|
|
52
|
+
* `token_settlements` row exists when guard #2 looks for it;
|
|
53
|
+
* `TokenHandedOverHook` runs at the payer's park/hold with the frame still in
|
|
54
|
+
* plaintext, so the payer's own row does not depend on a session key this
|
|
55
|
+
* process only holds in memory. Re-exported here because the rail is the single
|
|
56
|
+
* import site for nearby, and both are implemented by the Mandala runtime and
|
|
57
|
+
* consumed by `processPending` / `holdSentPaymentOffline` respectively.
|
|
58
|
+
*/
|
|
59
|
+
export type {
|
|
60
|
+
AdmissionVerifier,
|
|
61
|
+
EvidenceFrame,
|
|
62
|
+
EvidenceTokenBlock,
|
|
63
|
+
TokenHandedOverHook,
|
|
64
|
+
TokenHandoverState,
|
|
65
|
+
TokenHeldHook
|
|
66
|
+
} from '../../mandala/types'
|
|
67
|
+
export {
|
|
68
|
+
buildPaymentFrame,
|
|
69
|
+
finalizeDelivery,
|
|
70
|
+
selectTokenCoins,
|
|
71
|
+
type BuiltPayment,
|
|
72
|
+
type DeliveryOutcome,
|
|
73
|
+
type LockToPayee,
|
|
74
|
+
type SelectedTokenCoin,
|
|
75
|
+
type TokenBuildDeps
|
|
76
|
+
} from '../../localpay/build'
|
|
48
77
|
export {
|
|
49
78
|
FrameVerifyError,
|
|
79
|
+
declineReasonFor,
|
|
50
80
|
verifyFramePayment,
|
|
51
81
|
type DerivingWallet,
|
|
52
|
-
type FrameVerifyKind
|
|
82
|
+
type FrameVerifyKind,
|
|
83
|
+
type VerifiedPayment
|
|
53
84
|
} from '../../localpay/verify'
|
|
54
|
-
|
|
85
|
+
/**
|
|
86
|
+
* The token half of the rail (offline-settlement spec §9).
|
|
87
|
+
*
|
|
88
|
+
* Same three moves the BSV path makes — build, hand over, hold — with the
|
|
89
|
+
* evidence that makes them safe offline attached to each:
|
|
90
|
+
*
|
|
91
|
+
* · PAYER: `buildPaymentFrame` with `TokenBuildDeps` selects from
|
|
92
|
+
* `MANDALA_BASKET`, builds `noSend`, and attaches the AdmissionBundle
|
|
93
|
+
* `assembleBundle` collected. It submits NOTHING — hand-over comes first,
|
|
94
|
+
* unconditionally, so a face-to-face payment never waits on a network.
|
|
95
|
+
* `finalizeDelivery` then holds and returns `broadcast: 'pending'` for
|
|
96
|
+
* every token payment, online or off (guard #1): the drain is the only
|
|
97
|
+
* path to a real broadcast, and only after admission.
|
|
98
|
+
* · PAYEE: `verifyFramePayment` proves the output is ours and then runs
|
|
99
|
+
* `coverFromFrame` against the injected verifier; a frame that fails COVER
|
|
100
|
+
* is refused at hand-over with `'not_covered'`, exactly like a
|
|
101
|
+
* `not_mine`/`unparseable` decode failure. A frame that passes is credited
|
|
102
|
+
* by `processPending` as a basket insertion, and `onTokenCredited` is where
|
|
103
|
+
* the settlement row and the frame's evidence are persisted.
|
|
104
|
+
* · BOTH: `readSettlementAck` reads σ_I off the confirm channel — verified
|
|
105
|
+
* before it is believed, absent if it does not (FIX H) — and
|
|
106
|
+
* `tokenSendState` turns that into the payer's 'sent-settling' /
|
|
107
|
+
* 'sent-settled' copy.
|
|
108
|
+
*/
|
|
109
|
+
export {
|
|
110
|
+
SETTLEMENT_ACK_PREFIX,
|
|
111
|
+
decodeSettlementAck,
|
|
112
|
+
encodeSettlementAck,
|
|
113
|
+
readSettlementAck,
|
|
114
|
+
tokenSendState,
|
|
115
|
+
type SettlementAck,
|
|
116
|
+
type TokenSendState,
|
|
117
|
+
type VerifyAdmissionFn
|
|
118
|
+
} from '../../localpay/settlementAck'
|
|
119
|
+
export {
|
|
120
|
+
MANDALA_BASKET,
|
|
121
|
+
assembleBundle,
|
|
122
|
+
coverFromFrame,
|
|
123
|
+
tokenParentsOf,
|
|
124
|
+
type AdmissionBundle,
|
|
125
|
+
type BundleStore,
|
|
126
|
+
type CoverBundle,
|
|
127
|
+
type CoverTip,
|
|
128
|
+
type CoverVerifier
|
|
129
|
+
} from '../../mandala/bundle'
|
|
130
|
+
/**
|
|
131
|
+
* The session key the drain cannot hold for itself.
|
|
132
|
+
*
|
|
133
|
+
* A payer's `offline_actions.framePayload` is SEALED with the nearby session's
|
|
134
|
+
* PSK, and the drain deliberately never persists that key — so the flow that
|
|
135
|
+
* mints or scans a session hands it to `rememberSessionPsk` for this process's
|
|
136
|
+
* lifetime, and the drain's decoder tries the keys it was given. See
|
|
137
|
+
* `offline/tokenFrames.ts` for exactly what an unopened row costs (a race the
|
|
138
|
+
* payer is always safe to lose: the RECIPIENT submits).
|
|
139
|
+
*/
|
|
140
|
+
export {
|
|
141
|
+
MAX_REMEMBERED_SESSION_KEYS,
|
|
142
|
+
forgetSessionPsks,
|
|
143
|
+
rememberSessionPsk,
|
|
144
|
+
sealedFramePayloadDecoder
|
|
145
|
+
} from '../../offline/tokenFrames'
|
|
146
|
+
/**
|
|
147
|
+
* The payer's three durability moves, all from one place.
|
|
148
|
+
*
|
|
149
|
+
* `holdSentPaymentOffline` was the only one re-exported here while
|
|
150
|
+
* `parkSentPaymentOffline` and `releaseParkedPayment` were reached through the
|
|
151
|
+
* package root — which is the second implementation path this module exists to
|
|
152
|
+
* prevent. `holdSentPaymentOffline` and `parkSentPaymentOffline` take the same
|
|
153
|
+
* `{ frame, onTokenHandedOver }` deps (they create the settlement row from the
|
|
154
|
+
* plaintext frame); `releaseParkedPayment` takes none — the row already exists
|
|
155
|
+
* from the park, so it only advances it parked → handed_over. All three are the
|
|
156
|
+
* same fork of one decision (confirm now, keep for later, confirm later), so
|
|
157
|
+
* they belong on one import site.
|
|
158
|
+
*/
|
|
159
|
+
export {
|
|
160
|
+
holdSentPaymentOffline,
|
|
161
|
+
parkSentPaymentOffline,
|
|
162
|
+
releaseParkedPayment,
|
|
163
|
+
type TokenHandoverDeps
|
|
164
|
+
} from '../../offline/payerHold'
|
|
55
165
|
export { awdlTransport } from '../../localpay/transport/awdl'
|
|
56
166
|
export { nearbyTransport } from '../../localpay/transport/nearby'
|
|
57
167
|
export { bleTransport } from '../../localpay/transport/ble'
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Argument-size cap for wallets handed to EXTERNAL callers.
|
|
3
3
|
*
|
|
4
|
-
* Composed at each external surface exactly like guardVaultAccess
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* neither a permission prompt nor a storage touch.
|
|
4
|
+
* Composed at each external surface exactly like guardVaultAccess. The current
|
|
5
|
+
* app exposes desktop-pairing and saved-connection WalletClients; an embedding
|
|
6
|
+
* host must wrap any additional bridge it adds. Wrap outside the vault guard so
|
|
7
|
+
* a refusal costs neither a permission prompt nor a storage touch.
|
|
8
8
|
*
|
|
9
9
|
* WHERE THIS MUST NOT GO. Not in guardVaultAccess, not in SimpleWalletManager,
|
|
10
|
-
* not in WalletPermissionsManager, and not in the toolbox.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* any future tightening of these limits on the shared path.
|
|
10
|
+
* not in WalletPermissionsManager, and not in the toolbox. Vault transactions
|
|
11
|
+
* carry roughly 45 KB R1C locks and up to 2.5 KB unlocks per selected input;
|
|
12
|
+
* applying general bridge limits on the internal path could break them. The
|
|
13
|
+
* exemption keeps the vault insulated from future tightening of those limits.
|
|
15
14
|
*
|
|
16
15
|
* The vault is exempt STRUCTURALLY rather than by an originator comparison: it
|
|
17
16
|
* calls managers.permissionsManager directly and never receives a capped wallet.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ADMIN_ORIGINATOR } from '../config'
|
|
2
|
+
|
|
3
|
+
export interface ExternalOrigin {
|
|
4
|
+
/** Canonical HTTPS origin used for relay discovery and persistence. */
|
|
5
|
+
origin: string
|
|
6
|
+
/** Canonical host (and non-default port) used by WalletClient permissions. */
|
|
7
|
+
originator: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse an untrusted pairing origin at the external/internal trust boundary.
|
|
12
|
+
*
|
|
13
|
+
* Pairing relies on TLS for control of the advertised origin, so accepting a
|
|
14
|
+
* fallback string, cleartext URL, credentials, or a URL with path/query data
|
|
15
|
+
* turns an authorization identity into attacker-controlled text. Every fresh
|
|
16
|
+
* pairing and reconnect must pass through this function before constructing a
|
|
17
|
+
* WalletClient or fetching relay metadata.
|
|
18
|
+
*/
|
|
19
|
+
export function parseExternalOrigin(raw: string): ExternalOrigin {
|
|
20
|
+
let url: URL
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(raw)
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error('Origin URL is not valid')
|
|
25
|
+
}
|
|
26
|
+
if (url.protocol !== 'https:') throw new Error('Origin must use https://')
|
|
27
|
+
if (!url.hostname) throw new Error('Origin must include a hostname')
|
|
28
|
+
if (url.username || url.password) throw new Error('Origin must not include credentials')
|
|
29
|
+
if (url.pathname !== '/' || url.search || url.hash) {
|
|
30
|
+
throw new Error('Origin must be a bare HTTPS origin without a path, query, or fragment')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const originator = url.port ? `${url.hostname.toLowerCase()}:${url.port}` : url.hostname.toLowerCase()
|
|
34
|
+
// Defense in depth if the internal label ever changes back to something URL-shaped.
|
|
35
|
+
if (originator === ADMIN_ORIGINATOR.toLowerCase() || url.origin.toLowerCase() === ADMIN_ORIGINATOR.toLowerCase()) {
|
|
36
|
+
throw new Error('Origin is reserved for the wallet')
|
|
37
|
+
}
|
|
38
|
+
return { origin: url.origin, originator }
|
|
39
|
+
}
|