@bsv/expo-wallet-toolbox 0.21.0 → 0.22.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 +114 -0
- package/README.md +78 -13
- package/core/contacts/contactActivity.ts +48 -28
- package/core/contacts/contactsStore.ts +2 -2
- package/core/context/WalletContext.tsx +166 -219
- 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/i18n/translations.tsx +72 -0
- package/core/index.ts +55 -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/vault/guard.ts +5 -4
- package/core/storage/StorageExpoSQLite.ts +93 -229
- package/core/storage/methods/processOfflineActions.ts +86 -136
- package/core/storage/schema/createTables.ts +9 -184
- package/package.json +6 -5
- 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 +94 -160
- package/ui/components/ui/colorPrompt.ts +236 -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/hooks/useMandala.ts +6 -6
- package/ui/hooks/useSpendableBalance.ts +3 -1
- package/ui/importDatabases.ts +1 -1
- package/ui/screens/PayScreen.tsx +14 -20
- package/ui/screens/SettingsScreen.tsx +3 -1
- package/ui/screens/WalletCheckScreen.tsx +7 -2
- 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,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The handle rail's inbox pre-hold pass (offline-settlement spec §4.2/§4.3
|
|
3
|
-
* guard #2; codebase-review mandala-handle-P1-4).
|
|
4
|
-
*
|
|
5
|
-
* `@bsv/mandala`'s own `receiveTokens` (`dist/receive.js` `acceptOne`) calls
|
|
6
|
-
* `wallet.internalizeAction` BEFORE it calls the `settle` hook that finally
|
|
7
|
-
* writes a `token_settlements` row — and `internalizeAction` forces a
|
|
8
|
-
* broadcast attempt of its own via `shareReqsWithWorld`. The only thing
|
|
9
|
-
* standing between that and a real, unmediated broadcast of an unadmitted
|
|
10
|
-
* token transaction is `StorageExpoSQLite.attemptToPostReqsToNetwork`'s
|
|
11
|
-
* lookup of exactly that row. On the FIRST credit of a v2 hand-over message
|
|
12
|
-
* the row does not exist yet, so the guard finds nothing and lets the
|
|
13
|
-
* broadcast through before the issuer's overlay ever got to admit or refuse
|
|
14
|
-
* the transfer. `core/localpay/pending.ts`'s `processPending` closed the same
|
|
15
|
-
* hole for the nearby rail by moving the settlement write ahead of the
|
|
16
|
-
* credit; this file is the handle rail's equivalent, run once per inbox
|
|
17
|
-
* drain, before `createRuntime.ts`'s `receiveFromInbox` ever calls
|
|
18
|
-
* `receiveTokens`.
|
|
19
|
-
*
|
|
20
|
-
* This does NOT reimplement the library's trust logic. The only piece ported
|
|
21
|
-
* here is the mechanical shape of `acceptOne`'s `coverHandover` — parse the
|
|
22
|
-
* AtomicBEEF, merge it into a `Beef`, and hand the linkage/admissions arrays
|
|
23
|
-
* off to `cover` — because `coverHandover` itself is not exported. The
|
|
24
|
-
* verdict is entirely `cover`'s (the same pure, exported COVER walk the real
|
|
25
|
-
* `receiveTokens` runs), and the row it lets through is written by the
|
|
26
|
-
* caller's own `settle` hook, the SAME one `createRuntime.ts` wires as
|
|
27
|
-
* `settleThroughDrain` for the real `receiveTokens` call that follows. Two
|
|
28
|
-
* calls into the same idempotent hook for the same mustSubmit id are exactly
|
|
29
|
-
* the FIX G re-derivation `settlementStore.ts`'s `advanceSettlement` (a CAS)
|
|
30
|
-
* and `upsertSettlement` (never drags `state` backward on conflict) are built
|
|
31
|
-
* to tolerate.
|
|
32
|
-
*
|
|
33
|
-
* A message that will not decode on this side (bad bytes, not a handover, a
|
|
34
|
-
* COVER refusal) is simply left alone: `receiveTokens`'s own `acceptOne` runs
|
|
35
|
-
* the identical pure walk over the identical bytes moments later and, for a
|
|
36
|
-
* hand-over body, reaches `coverHandover` — and therefore any refusal —
|
|
37
|
-
* BEFORE it ever calls `internalizeAction`, so skipping it here costs
|
|
38
|
-
* nothing. Only a message whose evidence WOULD have credited safely, but
|
|
39
|
-
* whose settlement write failed, is dangerous to hand to `receiveTokens`
|
|
40
|
-
* unfiltered — that message is excluded from this pass via the same
|
|
41
|
-
* `processed` dedup set `receiveTokens` already accepts as a message filter
|
|
42
|
-
* (`ReceiveParams.processed`), so it is retried whole on the next drain tick
|
|
43
|
-
* rather than credited on a bare table.
|
|
44
|
-
*
|
|
45
|
-
* One inherent gap: this lists the inbox once, `receiveTokens` lists it
|
|
46
|
-
* again a moment later. A message that arrives in that narrow window is not
|
|
47
|
-
* covered by this pass — it is credited by `receiveTokens` with the
|
|
48
|
-
* library's original ordering, exactly as before this file existed. Closing
|
|
49
|
-
* that would require intercepting inside `acceptOne` itself, which is what
|
|
50
|
-
* the review's alternative (a pre-internalize hook upstream in
|
|
51
|
-
* `@bsv/mandala`) is for.
|
|
52
|
-
*/
|
|
53
|
-
import { Beef, Transaction } from '@bsv/sdk'
|
|
54
|
-
import { MESSAGEBOX } from '@bsv/mandala/constants'
|
|
55
|
-
import type { MessageBoxLike, SettleFn } from '@bsv/mandala'
|
|
56
|
-
import type { CoverResult } from './types'
|
|
57
|
-
import { devLog } from '../logging'
|
|
58
|
-
|
|
59
|
-
/** The v2 hand-over body fields this pass reads (wire contract v2 §8). Untyped past this: everything else is the caller's / the library's concern. */
|
|
60
|
-
interface RawHandoverBody {
|
|
61
|
-
v?: unknown
|
|
62
|
-
kind?: unknown
|
|
63
|
-
assetId?: unknown
|
|
64
|
-
transaction?: unknown
|
|
65
|
-
linkage?: unknown
|
|
66
|
-
admissions?: unknown
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
interface RawInboxMessage {
|
|
70
|
-
messageId: string
|
|
71
|
-
body?: RawHandoverBody
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** What one decoded hand-over needs from `settle` — the exact shape `SettleArgs` wants. */
|
|
75
|
-
interface DecodedHandover {
|
|
76
|
-
tip: Transaction
|
|
77
|
-
assetId: string
|
|
78
|
-
mustSubmit: string[]
|
|
79
|
-
bytesFor: (txid: string) => { beef: number[]; offChainValues: number[] } | undefined
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** The bundle shape this pass's injected `cover` reads — mirrors `libCoverArgs`'s own bundle parameter in `createRuntime.ts`. */
|
|
83
|
-
export interface PreHoldCoverBundle {
|
|
84
|
-
assetId: string
|
|
85
|
-
beef: Map<string, Transaction>
|
|
86
|
-
linkage: Map<string, number[]>
|
|
87
|
-
admissions: Map<string, { outputsToAdmit: number[]; signature: string; signerKey: string }>
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The pure COVER walk, already crossing the app/lib `@bsv/sdk` duplication
|
|
92
|
-
* seam (see `createRuntime.ts`'s `libCoverArgs` — this pass is handed a
|
|
93
|
-
* closure built from that same helper, never the raw library `cover`, so
|
|
94
|
-
* this file needs no cast of its own).
|
|
95
|
-
*/
|
|
96
|
-
export type PreHoldCoverFn = (tip: Transaction, bundle: PreHoldCoverBundle) => CoverResult
|
|
97
|
-
|
|
98
|
-
export interface PreHoldInboxDeps {
|
|
99
|
-
messageBoxClient: MessageBoxLike
|
|
100
|
-
cover: PreHoldCoverFn
|
|
101
|
-
/** The SAME hook `receiveFromInbox` passes to `receiveTokens` as `settle` — `settleThroughDrain`. */
|
|
102
|
-
settle: SettleFn
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Parses one v2 hand-over body into what `settle` needs, or `undefined` if COVER refuses it. Throws on bytes that will not even parse — the caller classifies that as "leave it to the library". */
|
|
106
|
-
function decodeHandover(body: RawHandoverBody, cover: PreHoldCoverFn): DecodedHandover | undefined {
|
|
107
|
-
if (typeof body.assetId !== 'string' || body.assetId === '') return undefined
|
|
108
|
-
if (!Array.isArray(body.transaction)) return undefined
|
|
109
|
-
const tip = Transaction.fromAtomicBEEF(body.transaction as number[])
|
|
110
|
-
|
|
111
|
-
const beef = new Beef()
|
|
112
|
-
beef.mergeTransaction(tip)
|
|
113
|
-
const txs = new Map<string, Transaction>()
|
|
114
|
-
for (const entry of beef.txs) if (entry.tx) txs.set(entry.txid, entry.tx)
|
|
115
|
-
|
|
116
|
-
const linkage = new Map<string, number[]>()
|
|
117
|
-
for (const l of Array.isArray(body.linkage) ? body.linkage : []) {
|
|
118
|
-
if (typeof l?.txid === 'string' && Array.isArray(l.payload)) linkage.set(l.txid, l.payload)
|
|
119
|
-
}
|
|
120
|
-
const admissions = new Map<string, { outputsToAdmit: number[]; signature: string; signerKey: string }>()
|
|
121
|
-
for (const a of Array.isArray(body.admissions) ? body.admissions : []) {
|
|
122
|
-
if (typeof a?.txid === 'string') {
|
|
123
|
-
admissions.set(a.txid, { outputsToAdmit: a.outputsToAdmit, signature: a.signature, signerKey: a.signerKey })
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const result = cover(tip, { assetId: body.assetId, beef: txs, linkage, admissions })
|
|
128
|
-
if (!result.ok) return undefined
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
tip,
|
|
132
|
-
assetId: body.assetId,
|
|
133
|
-
mustSubmit: result.mustSubmit,
|
|
134
|
-
bytesFor: (id: string) => {
|
|
135
|
-
const found = beef.findAtomicTransaction(id)
|
|
136
|
-
if (found == null) return undefined
|
|
137
|
-
return { beef: found.toAtomicBEEF(true), offChainValues: linkage.get(id) ?? [] }
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Runs the pre-hold pass. Returns the ids of messages whose settlement write
|
|
144
|
-
* failed this pass — the caller must keep those out of the `receiveTokens`
|
|
145
|
-
* call that follows (e.g. by adding them to its `processed` set for the
|
|
146
|
-
* duration of that one call, then removing them so the next drain retries).
|
|
147
|
-
*
|
|
148
|
-
* Deliberately best-effort PER MESSAGE and fail-closed PER MESSAGE: one bad
|
|
149
|
-
* or unwritable message never blocks the rest of the inbox, but a message
|
|
150
|
-
* this pass could have safely pre-held is never handed to `receiveTokens`
|
|
151
|
-
* with that write missing.
|
|
152
|
-
*/
|
|
153
|
-
export async function preHoldInboxSettlements(deps: PreHoldInboxDeps): Promise<Set<string>> {
|
|
154
|
-
const exclude = new Set<string>()
|
|
155
|
-
const messages = (await deps.messageBoxClient.listMessages({
|
|
156
|
-
messageBox: MESSAGEBOX,
|
|
157
|
-
acceptPayments: false
|
|
158
|
-
})) as RawInboxMessage[]
|
|
159
|
-
|
|
160
|
-
for (const raw of messages) {
|
|
161
|
-
const body = raw.body
|
|
162
|
-
// v2 + kind:'handover' is the whole version discriminator (receive.js).
|
|
163
|
-
// A v1 body's `covering` is always undefined in `acceptOne`, so its
|
|
164
|
-
// `settle` never runs at all — there is nothing here to pre-hold.
|
|
165
|
-
if (body == null || body.v !== 2 || body.kind !== 'handover') continue
|
|
166
|
-
|
|
167
|
-
let decoded: DecodedHandover | undefined
|
|
168
|
-
try {
|
|
169
|
-
decoded = decodeHandover(body, deps.cover)
|
|
170
|
-
} catch (e) {
|
|
171
|
-
devLog(`[mandala] inbox pre-hold could not decode message ${raw.messageId}; leaving it to the library:`, e)
|
|
172
|
-
continue
|
|
173
|
-
}
|
|
174
|
-
if (!decoded) continue // COVER refused it — acceptOne will reach the same refusal before internalizing
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
await deps.settle({
|
|
178
|
-
txid: decoded.tip.id('hex'),
|
|
179
|
-
mustSubmit: decoded.mustSubmit,
|
|
180
|
-
assetId: decoded.assetId,
|
|
181
|
-
bytesFor: decoded.bytesFor
|
|
182
|
-
})
|
|
183
|
-
} catch (e) {
|
|
184
|
-
devLog(
|
|
185
|
-
`[mandala] inbox pre-hold could not write the settlement row for message ${raw.messageId}; holding it back this pass:`,
|
|
186
|
-
e
|
|
187
|
-
)
|
|
188
|
-
exclude.add(raw.messageId)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return exclude
|
|
193
|
-
}
|