@bsv/expo-wallet-toolbox 0.21.0 → 0.23.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 +222 -0
- package/README.md +82 -13
- package/core/bridge/BrowserBridgeProvider.tsx +273 -0
- package/core/bridge/bindings.ts +459 -0
- package/core/bridge/conformance.ts +222 -0
- package/core/bridge/consent.ts +494 -0
- package/core/bridge/consentSheetSource.ts +98 -0
- package/core/bridge/dispatcher.ts +621 -0
- package/core/bridge/inbox.ts +464 -0
- package/core/bridge/index.ts +48 -0
- package/core/bridge/loopback/cors.ts +57 -0
- package/core/bridge/loopback/endpoints.ts +11 -0
- package/core/bridge/loopback/hostCheck.ts +25 -0
- package/core/bridge/loopback/index.ts +7 -0
- package/core/bridge/loopback/launchProof.ts +166 -0
- package/core/bridge/loopback/router.ts +770 -0
- package/core/bridge/loopback/routerTypes.ts +115 -0
- package/core/bridge/loopback/status.ts +52 -0
- package/core/bridge/memoryInboxStore.ts +222 -0
- package/core/bridge/permissionPolicy.ts +247 -0
- package/core/bridge/policy.ts +72 -0
- package/core/bridge/protocol/base64url.ts +64 -0
- package/core/bridge/protocol/connectionError.ts +79 -0
- package/core/bridge/protocol/constants.ts +21 -0
- package/core/bridge/protocol/continuity.ts +21 -0
- package/core/bridge/protocol/descriptor.ts +395 -0
- package/core/bridge/protocol/envelopes.ts +188 -0
- package/core/bridge/protocol/errorCodec.ts +164 -0
- package/core/bridge/protocol/json.ts +237 -0
- package/core/bridge/protocol/limits.ts +43 -0
- package/core/bridge/protocol/methods.ts +55 -0
- package/core/bridge/protocol/origin.ts +130 -0
- package/core/bridge/runtime.ts +642 -0
- package/core/bridge/runtimeFlags.ts +34 -0
- package/core/bridge/testing/conformanceCases.ts +149 -0
- package/core/bridge/testing/pageClient.ts +44 -0
- package/core/bridge/unverifiedManager.ts +97 -0
- package/core/bridge/unverifiedOriginator.ts +79 -0
- package/core/config.tsx +1 -16
- package/core/contacts/contactActivity.ts +48 -28
- package/core/contacts/contactsStore.ts +2 -2
- package/core/context/WalletConnectionContext.tsx +7 -1
- package/core/context/WalletContext.tsx +420 -348
- package/core/context/sessionTeardown.ts +46 -0
- package/core/demo/demoAssets.ts +8 -10
- package/core/demo/demoLedger.ts +32 -38
- package/core/demo/demoMandalaRuntime.ts +67 -49
- package/core/demo/index.ts +1 -1
- package/core/hooks/usePermissionQueue.ts +89 -34
- package/core/i18n/translations.tsx +983 -12
- package/core/index.ts +70 -37
- package/core/localpay/build.ts +110 -569
- package/core/localpay/codec.ts +190 -93
- package/core/localpay/pending.ts +217 -202
- package/core/localpay/session.ts +99 -25
- package/core/localpay/types.ts +6 -5
- package/core/localpay/verify.ts +118 -173
- package/core/mandala/abortGuard.ts +97 -120
- package/core/mandala/accessPolicy.ts +133 -0
- package/core/mandala/assets.ts +370 -0
- package/core/mandala/colorGuard.ts +178 -0
- package/core/mandala/colorModule.ts +82 -0
- package/core/mandala/createRuntime.ts +483 -2392
- package/core/mandala/handle.ts +694 -0
- package/core/mandala/kvStore.ts +105 -0
- package/core/mandala/nearby.ts +185 -0
- package/core/mandala/receipt.ts +121 -0
- package/core/mandala/runtime.ts +166 -312
- package/core/mandala/settle.ts +540 -0
- package/core/mandala/transferJournal.ts +395 -0
- package/core/mandala/types.ts +61 -311
- package/core/networks.ts +5 -5
- package/core/offline/cancelParked.ts +80 -63
- package/core/offline/payerHold.ts +52 -118
- package/core/parsePeerPayURI.ts +25 -12
- package/core/pay/rails/handle.ts +15 -14
- package/core/pay/rails/index.ts +5 -3
- package/core/pay/rails/nearby.ts +25 -87
- package/core/profiles/assertProfileEmpty.ts +19 -10
- package/core/services/autoApprovePolicy.ts +7 -1
- package/core/services/capWalletArgs.ts +2 -1
- package/core/services/permissionPrompts.ts +132 -0
- package/core/services/signingPermissionPolicy.ts +230 -2
- package/core/services/vault/guard.ts +15 -4
- package/core/services/walletArgLimits.ts +17 -2
- package/core/storage/StorageExpoSQLite.ts +93 -229
- package/core/storage/encryptedDbImage.ts +325 -0
- package/core/storage/methods/processOfflineActions.ts +86 -136
- package/core/storage/schema/createTables.ts +9 -184
- package/core/toolboxConfig.ts +18 -1
- package/package.json +9 -8
- package/ui/bridgeSheet/ContextRelay.tsx +86 -0
- package/ui/bridgeSheet/relayedContexts.ts +21 -0
- package/ui/components/pay/AssetPicker.tsx +2 -2
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/pay/NearbyFlow.tsx +324 -239
- package/ui/components/pay/RequestHub.tsx +10 -0
- package/ui/components/pay/UniversalSend.tsx +31 -28
- package/ui/components/pay/useRecipientInput.ts +2 -2
- package/ui/components/ui/PermissionSheet.tsx +625 -315
- package/ui/components/ui/Sheet.tsx +59 -7
- package/ui/components/ui/colorPrompt.ts +236 -0
- package/ui/components/ui/sheetResumeSignal.ts +19 -0
- package/ui/components/wallet/AmountInput.tsx +9 -6
- package/ui/components/wallet/AssetAmount.tsx +6 -6
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +26 -7
- package/ui/components/wallet/Balance.tsx +3 -1
- package/ui/components/wallet/ContactActivityList.tsx +10 -13
- package/ui/components/wallet/tokenEviction.ts +9 -9
- package/ui/exportDatabases.ts +94 -5
- package/ui/hooks/useExportWalletData.ts +37 -24
- package/ui/hooks/useMandala.ts +6 -6
- package/ui/hooks/useSpendableBalance.ts +3 -1
- package/ui/importDatabases.ts +124 -29
- package/ui/index.ts +4 -0
- package/ui/screens/PayScreen.tsx +14 -20
- package/ui/screens/SettingsScreen.tsx +3 -1
- package/ui/screens/WalletCheckScreen.tsx +7 -2
- package/ui/screens/WalletConfigScreen.tsx +13 -1
- package/ui/screens/WalletHomeScreen.tsx +40 -14
- package/ui/screens/tokenRowTitle.ts +28 -15
- package/ui/tokenFormat.ts +133 -69
- package/ui/tokenStatus.ts +5 -8
- package/core/localpay/settlementAck.ts +0 -155
- package/core/mandala/basketMigration.ts +0 -166
- package/core/mandala/bundle.ts +0 -244
- package/core/mandala/drain.ts +0 -754
- package/core/mandala/inboxPrehold.ts +0 -193
- package/core/mandala/permissionModule.ts +0 -931
- package/core/mandala/resendTransfer.ts +0 -178
- package/core/mandala/settlementStore.ts +0 -434
- package/core/mandala/token.ts +0 -45
- package/core/offline/tokenFrames.ts +0 -197
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Turning the frames this device already holds durably into drain sources.
|
|
3
|
-
*
|
|
4
|
-
* This is the supply side of FIX G and FIX I. `processOfflineActions` calls
|
|
5
|
-
* `token.frames()` at the start of every pass and hands the result to
|
|
6
|
-
* `reconcileSettlements`, which re-derives the evidence cache and any missing
|
|
7
|
-
* `token_settlements` row. The two durable stores have very different shapes,
|
|
8
|
-
* so each gets its own reader:
|
|
9
|
-
*
|
|
10
|
-
* · `localpay_pending` (receiver) holds the frame ALREADY DECODED, so nothing
|
|
11
|
-
* is needed but the queue entries.
|
|
12
|
-
* · `offline_actions.framePayload` (payer) holds the SEALED `bsvpayf1:` QR
|
|
13
|
-
* string. Opening it needs the session pre-shared key, which the drain does
|
|
14
|
-
* not hold and should not — so the decoder is injected by whoever still has
|
|
15
|
-
* the session, and a row that cannot be opened is simply skipped. The payer
|
|
16
|
-
* losing its own settlement row is survivable in a way the recipient's is
|
|
17
|
-
* not: the recipient submits (rule 3), and the payer's optional submit
|
|
18
|
-
* (rule 6) is a race it is always safe to lose.
|
|
19
|
-
*
|
|
20
|
-
* **Deliberately NOT filtered by `MAX_PENDING_ATTEMPTS` (FIX I).** That ceiling
|
|
21
|
-
* governs `localpay_pending`'s own BSV-shaped internalize retry loop and burns
|
|
22
|
-
* an attempt on any failure, including a transient
|
|
23
|
-
* `Block header not found for height N` from a fresh-block BUMP this device has
|
|
24
|
-
* not caught up on. A token payment's state of record is `token_settlements`,
|
|
25
|
-
* not the pending queue — so an exhausted queue entry still contributes its
|
|
26
|
-
* frame here, the settlement row stays alive, and the row is abandoned only by
|
|
27
|
-
* an explicit `refused`/`orphaned` verdict from the overlay.
|
|
28
|
-
*/
|
|
29
|
-
import { Beef, Transaction } from '@bsv/sdk'
|
|
30
|
-
import { MandalaToken } from '../mandala/token'
|
|
31
|
-
import type { EvidenceFrame, TokenFrameSource } from '../mandala/drain'
|
|
32
|
-
import type { OfflineActionRow } from '../storage/methods/offlineActions'
|
|
33
|
-
import { frameBytesFromQr, unsealFrame } from '../localpay/codec'
|
|
34
|
-
|
|
35
|
-
/** Structurally satisfied by `localpay/pending`'s `PendingPayment`. */
|
|
36
|
-
export interface PendingLike {
|
|
37
|
-
frame: EvidenceFrame
|
|
38
|
-
status?: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The subject txid of an AtomicBEEF — the same txid `internalizeAction` used
|
|
43
|
-
* internally, and therefore the one a `token_settlements` row is keyed by.
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* The token figure a frame moves: the amount in the PAYEE output's own script.
|
|
47
|
-
*
|
|
48
|
-
* Read off the atomic transaction rather than trusted from any body, and off
|
|
49
|
-
* `outputIndex` (0 when the frame does not say — the nearby build never
|
|
50
|
-
* randomises outputs) so the payer's own frame answers the payee's figure and
|
|
51
|
-
* never the change. `undefined` for anything that is not a readable token
|
|
52
|
-
* output: the settlement row then has no amount, which the activity list says
|
|
53
|
-
* out loud rather than inventing a number.
|
|
54
|
-
*/
|
|
55
|
-
export function frameTokenAmount(frame: EvidenceFrame): number | undefined {
|
|
56
|
-
try {
|
|
57
|
-
const tx = Transaction.fromAtomicBEEF(Array.from(frame.transaction))
|
|
58
|
-
const script = tx.outputs[frame.outputIndex ?? 0]?.lockingScript
|
|
59
|
-
if (!script) return undefined
|
|
60
|
-
const amount = MandalaToken.decode(script).amount
|
|
61
|
-
return Number.isFinite(amount) && amount >= 0 ? amount : undefined
|
|
62
|
-
} catch {
|
|
63
|
-
return undefined
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function frameTxid(frame: EvidenceFrame): string | undefined {
|
|
68
|
-
try {
|
|
69
|
-
return Beef.fromBinary(frame.transaction).atomicTxid
|
|
70
|
-
} catch {
|
|
71
|
-
return undefined
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Receiver-side sources. Every non-completed entry with a token block, whether
|
|
77
|
-
* or not the pending queue has given up on it.
|
|
78
|
-
*/
|
|
79
|
-
export function tokenFrameSourcesFromPending(entries: readonly PendingLike[]): TokenFrameSource[] {
|
|
80
|
-
const sources: TokenFrameSource[] = []
|
|
81
|
-
for (const entry of entries) {
|
|
82
|
-
if (!entry.frame?.token) continue
|
|
83
|
-
const txid = frameTxid(entry.frame)
|
|
84
|
-
if (!txid) continue
|
|
85
|
-
const amountBaseUnits = frameTokenAmount(entry.frame)
|
|
86
|
-
sources.push({
|
|
87
|
-
txid,
|
|
88
|
-
role: 'received',
|
|
89
|
-
frame: entry.frame,
|
|
90
|
-
...(amountBaseUnits !== undefined ? { amountBaseUnits } : {})
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
return sources
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Payer-side sources, for the rows whose sealed `framePayload` the caller can
|
|
98
|
-
* open. A row this device cannot decode contributes nothing rather than
|
|
99
|
-
* throwing: the drain must reach every other row in the same pass.
|
|
100
|
-
*/
|
|
101
|
-
export function tokenFrameSourcesFromOfflineActions(
|
|
102
|
-
rows: readonly OfflineActionRow[],
|
|
103
|
-
decode: (framePayload: string) => EvidenceFrame | undefined
|
|
104
|
-
): TokenFrameSource[] {
|
|
105
|
-
const sources: TokenFrameSource[] = []
|
|
106
|
-
for (const row of rows) {
|
|
107
|
-
if (!row.framePayload) continue
|
|
108
|
-
let frame: EvidenceFrame | undefined
|
|
109
|
-
try {
|
|
110
|
-
frame = decode(row.framePayload)
|
|
111
|
-
} catch {
|
|
112
|
-
continue
|
|
113
|
-
}
|
|
114
|
-
if (!frame?.token) continue
|
|
115
|
-
const amountBaseUnits = frameTokenAmount(frame)
|
|
116
|
-
sources.push({
|
|
117
|
-
txid: row.txid,
|
|
118
|
-
role: row.role,
|
|
119
|
-
frame,
|
|
120
|
-
// A parked row must keep its own state: it is the user's, not the
|
|
121
|
-
// drain's, and reconciliation may not promote it to a submittable one.
|
|
122
|
-
state: row.status === 'parked' ? 'parked' : undefined,
|
|
123
|
-
...(amountBaseUnits !== undefined ? { amountBaseUnits } : {})
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
return sources
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ───────────────────── the payer's sealed-frame decoder ─────────────────────
|
|
130
|
-
//
|
|
131
|
-
// `offline_actions.framePayload` is the `bsvpayf1:` envelope around a frame
|
|
132
|
-
// SEALED with the nearby session's pre-shared key. The drain holds no session
|
|
133
|
-
// and should not: the PSK is a hand-over secret, not durable wallet state. So
|
|
134
|
-
// the keys of the sessions this process has actually taken part in are kept
|
|
135
|
-
// here, in memory only, and the decoder tries each of them.
|
|
136
|
-
//
|
|
137
|
-
// What "in memory only" costs is bounded and known: a payer that restarts
|
|
138
|
-
// before its own optional submit (rule 6) loses the ability to re-derive its
|
|
139
|
-
// `token_settlements` row from the frame. That is the race it is always safe
|
|
140
|
-
// to lose — the RECIPIENT submits (rule 3), and the payer's submit only makes
|
|
141
|
-
// its own change spendable sooner. What it buys is that a durable copy of the
|
|
142
|
-
// key that opens every stored frame is never written to disk.
|
|
143
|
-
|
|
144
|
-
/** How many session keys are remembered. Well past any plausible number of live hand-overs. */
|
|
145
|
-
export const MAX_REMEMBERED_SESSION_KEYS = 32
|
|
146
|
-
|
|
147
|
-
const sessionKeys: Uint8Array[] = []
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Remember a nearby session's PSK for this process.
|
|
151
|
-
*
|
|
152
|
-
* Called by whoever mints or scans a session (the nearby flow), not by the
|
|
153
|
-
* drain. Idempotent per key, and bounded: the oldest key is dropped once the
|
|
154
|
-
* ring is full, which is correct because a hand-over's frame is reconciled on
|
|
155
|
-
* the very next online tick.
|
|
156
|
-
*/
|
|
157
|
-
export function rememberSessionPsk(psk: Uint8Array): void {
|
|
158
|
-
if (!(psk instanceof Uint8Array) || psk.length !== 32) return
|
|
159
|
-
const already = sessionKeys.some(known => known.length === psk.length && known.every((b, i) => b === psk[i]))
|
|
160
|
-
if (already) return
|
|
161
|
-
sessionKeys.push(new Uint8Array(psk))
|
|
162
|
-
while (sessionKeys.length > MAX_REMEMBERED_SESSION_KEYS) sessionKeys.shift()
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Drop every remembered key. Logout, network switch, and the tests. */
|
|
166
|
-
export function forgetSessionPsks(): void {
|
|
167
|
-
sessionKeys.length = 0
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* A decoder for `tokenFrameSourcesFromOfflineActions`.
|
|
172
|
-
*
|
|
173
|
-
* Tries each remembered session key in turn and returns the first frame that
|
|
174
|
-
* opens. Undefined — never a throw — for a truncated row, a foreign string, or
|
|
175
|
-
* a frame from a session this process no longer holds the key for: the drain
|
|
176
|
-
* must reach every other row in the same pass.
|
|
177
|
-
*/
|
|
178
|
-
export function sealedFramePayloadDecoder(
|
|
179
|
-
keys: () => readonly Uint8Array[] = () => sessionKeys
|
|
180
|
-
): (framePayload: string) => EvidenceFrame | undefined {
|
|
181
|
-
return framePayload => {
|
|
182
|
-
let bytes: Uint8Array
|
|
183
|
-
try {
|
|
184
|
-
bytes = frameBytesFromQr(framePayload)
|
|
185
|
-
} catch {
|
|
186
|
-
return undefined
|
|
187
|
-
}
|
|
188
|
-
for (const psk of keys()) {
|
|
189
|
-
try {
|
|
190
|
-
return unsealFrame(bytes, psk)
|
|
191
|
-
} catch {
|
|
192
|
-
// Wrong key for this frame (a GCM tag mismatch). Try the next.
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return undefined
|
|
196
|
-
}
|
|
197
|
-
}
|