@bsv/expo-wallet-toolbox 0.20.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 +147 -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/directpay/DirectPayManager.ts +148 -29
- package/core/directpay/DirectPayProvider.tsx +11 -2
- package/core/directpay/payFlow.ts +10 -1
- package/core/directpay/settings.ts +56 -9
- package/core/directpay/types.ts +11 -2
- package/core/directpay/webrtpay.ts +4 -0
- package/core/i18n/translations.tsx +185 -84
- 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/direct.ts +6 -2
- 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 +10 -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
package/core/mandala/runtime.ts
CHANGED
|
@@ -2,361 +2,215 @@
|
|
|
2
2
|
* MandalaRuntime — the single object the UI layer consumes for stablecoin
|
|
3
3
|
* features. Constructed once in WalletContext (core wiring), exposed via
|
|
4
4
|
* `useMandala()`. Pure types here; the implementation lives in
|
|
5
|
-
* core/mandala/createRuntime.ts
|
|
6
|
-
* core/hooks/useMandala.ts.
|
|
5
|
+
* core/mandala/createRuntime.ts and the hook in ui/hooks/useMandala.ts.
|
|
7
6
|
*
|
|
8
|
-
* Design rule (ux §1): the UI never talks to the overlay
|
|
9
|
-
* everything goes through this surface so failure copy,
|
|
10
|
-
* state live in one place.
|
|
7
|
+
* Design rule (ux §1): the UI never talks to the overlay, the color module or
|
|
8
|
+
* the lib directly; everything goes through this surface so failure copy,
|
|
9
|
+
* journaling and state live in one place.
|
|
10
|
+
*
|
|
11
|
+
* Since 1Color (plan 07) and Amendment B7: the color permission module holds
|
|
12
|
+
* every token; the runtime is the HOST over it. `@bsv/mandala` sends,
|
|
13
|
+
* receives, verifies (online submit or offline COVER) and settles hand-overs
|
|
14
|
+
* with the host ledger, and the module's host-only `markSettled(txid)` clears
|
|
15
|
+
* `color_offline` once a coin is settled. The wallet's own `color_transfers`
|
|
16
|
+
* journal mirrors every transfer. Token amounts are exact `bigint`
|
|
17
|
+
* everywhere on this surface (IC §0).
|
|
11
18
|
*/
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
CoverResult,
|
|
15
|
-
FetchAdmissionFn,
|
|
16
|
-
SettlementStore,
|
|
17
|
-
TokenHandedOverHook,
|
|
18
|
-
TokenHeldHook,
|
|
19
|
-
TokenSettlementRow,
|
|
20
|
-
TokenSettlementState
|
|
21
|
-
} from './types'
|
|
22
|
-
import type { LockToPayee, TokenBuildDeps } from '../localpay/build'
|
|
23
|
-
import type { CoverVerifier } from './bundle'
|
|
24
|
-
import type { VerifyAdmissionFn } from '../localpay/settlementAck'
|
|
25
|
-
import type { TokenCreditedHook } from '../localpay/pending'
|
|
26
|
-
import type { OfflineTokenDeps } from '../storage/methods/processOfflineActions'
|
|
19
|
+
import type { HandoverResult } from '@bsv/mandala'
|
|
20
|
+
import type { PaymentFrame } from '../localpay/codec'
|
|
27
21
|
import type { MandalaEndpointConfig } from '../toolboxConfig'
|
|
28
|
-
import type {
|
|
22
|
+
import type { TransferJournal } from './transferJournal'
|
|
23
|
+
import type { ColorTransferRail, ColorTransferRole, ColorTransferRow, ColorTransferState } from './types'
|
|
24
|
+
|
|
25
|
+
/** Display metadata of one asset, from its deploy tx (W7). Untrusted display data: the full `assetId` is always available. */
|
|
26
|
+
export interface TokenAssetInfo {
|
|
27
|
+
assetId: string
|
|
28
|
+
label: string // e.g. "Acme Dollar"; the short asset id when unresolved
|
|
29
|
+
ticker: string // e.g. "USDX"; '' when unresolved
|
|
30
|
+
decimals: number // 0..18; 0 when unresolved
|
|
31
|
+
issuerName?: string
|
|
32
|
+
/** The deploy was read and names this wallet's overlay. False means every field above is a fallback. */
|
|
33
|
+
resolved: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One held asset's figures (W10).
|
|
38
|
+
*
|
|
39
|
+
* `units` is the exact `p color balance <assetTag>` sum: everything available
|
|
40
|
+
* to spend, INCLUDING offline credits (0207:396-404). `offlineUnits` is the
|
|
41
|
+
* pending part of it, the same view filtered to `color_offline` (B7) —
|
|
42
|
+
* accepted, but not yet settled with the issuer's overlay. It is never more
|
|
43
|
+
* than `units`; the settled part is `units - offlineUnits`. Never sum the two.
|
|
44
|
+
*/
|
|
45
|
+
export interface TokenBalance {
|
|
46
|
+
asset: TokenAssetInfo
|
|
47
|
+
units: bigint
|
|
48
|
+
offlineUnits: bigint
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* How a journal row reads on the activity list. `settling` covers every
|
|
53
|
+
* non-terminal state; `stuck` is a non-terminal row older than STUCK_AFTER_MS.
|
|
54
|
+
* A cancelled send never appears (the money never moved).
|
|
55
|
+
*/
|
|
56
|
+
export type TokenActivityStatus = 'settling' | 'settled' | 'refused' | 'stuck'
|
|
57
|
+
|
|
58
|
+
export interface TokenActivityRow {
|
|
59
|
+
txid: string
|
|
60
|
+
role: ColorTransferRole
|
|
61
|
+
asset: TokenAssetInfo
|
|
62
|
+
units: bigint
|
|
63
|
+
counterpartyKey?: string
|
|
64
|
+
status: TokenActivityStatus
|
|
65
|
+
at: string // ISO
|
|
66
|
+
refusedCode?: string
|
|
67
|
+
rail: ColorTransferRail
|
|
68
|
+
}
|
|
29
69
|
|
|
30
70
|
/**
|
|
31
71
|
* Regulatory/registry facts about one asset, for the UI's remaining copy
|
|
32
72
|
* (paused banners, frozen-balance notices, access-mode refusals, admission
|
|
33
|
-
* status). Everything here is best-effort and short-lived (~10s cache
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
73
|
+
* status). Everything here is best-effort and short-lived (~10s cache): a
|
|
74
|
+
* stale or unreachable overlay reads as the least alarming answer
|
|
75
|
+
* (`false`/`undefined`), never as a thrown error, because this is display
|
|
76
|
+
* copy, not a gate anything transacts against.
|
|
37
77
|
*/
|
|
38
78
|
export interface TokenAssetStatus {
|
|
39
79
|
/** The issuer has paused this asset. */
|
|
40
80
|
paused: boolean
|
|
41
|
-
/**
|
|
42
|
-
|
|
81
|
+
/** Exact sum of amounts across the asset's frozen outpoints, per the overlay's admin state. */
|
|
82
|
+
frozenUnits: bigint
|
|
43
83
|
/** 'allowlist' | 'denylist', when the overlay reports one. */
|
|
44
84
|
accessMode?: string
|
|
45
|
-
/** This wallet's own identity key, admitted under the
|
|
46
|
-
* `undefined` when the registry is inactive (no membership gate in effect) or unknown. */
|
|
85
|
+
/** This wallet's own identity key, admitted under the issuer registry; `undefined` when no gate is live or unknown. */
|
|
47
86
|
selfAdmitted: boolean | undefined
|
|
48
87
|
/** Same question for another identity key — e.g. a recipient before a send. */
|
|
49
88
|
recipientAdmitted(identityKey: string): Promise<boolean | undefined>
|
|
50
|
-
/** Whether the asset's on-chain label/ticker/decimals resolved
|
|
89
|
+
/** Whether the asset's on-chain label/ticker/decimals resolved. */
|
|
51
90
|
metadataResolved: boolean
|
|
52
91
|
/** The MessageBox host this deployment's handle rail uses. */
|
|
53
92
|
messageBoxUrl: string
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
95
|
+
/** Handle (MessageBox) rail results. */
|
|
96
|
+
export type TokenSendResult =
|
|
97
|
+
/**
|
|
98
|
+
* The hand-over is built and journaled. `settled`: the overlay admitted it
|
|
99
|
+
* before the call returned. `notified: false`: the MessageBox delivery did
|
|
100
|
+
* not go through; the tick redelivers it. Neither is ever a reason to send
|
|
101
|
+
* again — a second send is a second payment.
|
|
102
|
+
*/
|
|
103
|
+
| { kind: 'sent'; txid: string; settled: boolean; notified: boolean }
|
|
104
|
+
| { kind: 'refused'; code: string; message: string }
|
|
105
|
+
| { kind: 'unavailable'; message: string }
|
|
65
106
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/** Spendable base units (sum of unspent outputs in the token basket). */
|
|
69
|
-
baseUnits: number
|
|
70
|
-
/** Base units in rows whose settlement is not yet 'broadcast' (received offline). */
|
|
71
|
-
unsettledBaseUnits: number
|
|
72
|
-
}
|
|
107
|
+
/** Where one row stood when `settleNow` let go of it; `'unavailable'` is no row/database/deployment, never a verdict. */
|
|
108
|
+
export type TokenSettleState = ColorTransferState | 'unavailable'
|
|
73
109
|
|
|
74
110
|
export interface TokenHoldingsReview {
|
|
75
111
|
settled: number
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
refused: number
|
|
113
|
+
pending: number
|
|
114
|
+
/** The overlay could not be asked; nothing was decided. */
|
|
78
115
|
unreachable: boolean
|
|
79
116
|
}
|
|
80
117
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
role: 'sent' | 'received'
|
|
86
|
-
asset: TokenAssetInfo
|
|
87
|
-
baseUnits: number
|
|
88
|
-
counterpartyKey?: string
|
|
89
|
-
status: TokenActivityStatus
|
|
90
|
-
at: string // ISO
|
|
91
|
-
refusedCode?: string
|
|
92
|
-
/** `payloadHash` of the linkage bytes this refusal was recorded against (amendment §9.1/§9.3). */
|
|
93
|
-
refusedPayloadHash?: string
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Handle (MessageBox) rail results — mirror the wallet's existing rail result shapes. */
|
|
97
|
-
export type TokenSendResult =
|
|
98
|
-
| {
|
|
99
|
-
kind: 'sent'
|
|
100
|
-
txid: string
|
|
101
|
-
/**
|
|
102
|
-
* The issuer's overlay has this transaction (`admitted`, or `broadcast`
|
|
103
|
-
* on top of it) — because a hand-over that landed while this device had
|
|
104
|
-
* signal is followed straight away by the payer's own submit
|
|
105
|
-
* (`settleNow`). False is not a failure and never a reason to retry the
|
|
106
|
-
* SEND: the money moved at hand-over, and the drain finishes the
|
|
107
|
-
* settlement on its next tick.
|
|
108
|
-
*/
|
|
109
|
-
settled: boolean
|
|
110
|
-
/**
|
|
111
|
-
* False when the transaction committed but the recipient's MessageBox
|
|
112
|
-
* notification did not go out (the lib's `TransferResult.notified`).
|
|
113
|
-
*
|
|
114
|
-
* The money is sent either way — the notify is journaled by the lib and
|
|
115
|
-
* retried by `reconcileNotifications` on the next drain tick — but until
|
|
116
|
-
* it lands the recipient has an output nothing has told them to
|
|
117
|
-
* internalize. The UI says "recipient notification pending" rather than
|
|
118
|
-
* implying either that the payment failed (it did not) or that the payee
|
|
119
|
-
* can already see it (they cannot). NEVER a reason to retry the send: a
|
|
120
|
-
* second send would be a second payment.
|
|
121
|
-
*/
|
|
122
|
-
notified: boolean
|
|
123
|
-
}
|
|
124
|
-
| { kind: 'refused'; code: string; message: string }
|
|
125
|
-
| { kind: 'unavailable'; message: string }
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Where one row stood when `settleNow` let go of it.
|
|
129
|
-
*
|
|
130
|
-
* Every `TokenSettlementState` can come back, because the answer is simply the
|
|
131
|
-
* row's state re-read after the step: `'admitted'`/`'broadcast'` are the two
|
|
132
|
-
* that mean settled, `'refused'`/`'orphaned'` are the overlay's final word, and
|
|
133
|
-
* an unchanged `'handed_over'`/`'held'` means the step stalled and the ordinary
|
|
134
|
-
* drain will try again. `'unavailable'` is the one addition — no such row, no
|
|
135
|
-
* database, or no Mandala deployment on this chain — and is never a verdict
|
|
136
|
-
* about the money.
|
|
137
|
-
*/
|
|
138
|
-
export type TokenSettleState = TokenSettlementState | 'unavailable'
|
|
139
|
-
|
|
140
|
-
export interface MandalaRuntime {
|
|
141
|
-
/** Chain gate: mainnet-only in v1 (ux §2). */
|
|
142
|
-
available: boolean
|
|
143
|
-
/**
|
|
144
|
-
* THIS DEVICE's configured Mandala deployment — the §9.10 trust anchor, in
|
|
145
|
-
* the shape every call site that has to state one wants (`verifyFramePayment`'s
|
|
146
|
-
* `opts.asset`, a session's own `asset` block).
|
|
147
|
-
*
|
|
148
|
-
* Exposed because the alternative is each call site reaching for whatever
|
|
149
|
-
* overlay facts are nearest to hand, and the nearest ones are on the incoming
|
|
150
|
-
* FRAME. A frame's `overlayUrl`/`overlayIdentityKey` are the payer's claim;
|
|
151
|
-
* verifying a payer's σ_I against the payer's own key is not a check at all.
|
|
152
|
-
* Every field is `''` when this chain has no Mandala deployment
|
|
153
|
-
* (`available === false`), which no frame can ever equal.
|
|
154
|
-
*/
|
|
155
|
-
endpoints: MandalaEndpointConfig
|
|
156
|
-
store: SettlementStore
|
|
157
|
-
/** Assets this wallet currently holds or has ever received. */
|
|
158
|
-
listAssets(): Promise<TokenAssetInfo[]>
|
|
159
|
-
balances(): Promise<TokenBalance[]>
|
|
160
|
-
activity(limit?: number): Promise<TokenActivityRow[]>
|
|
161
|
-
/** Non-terminal rows older than STUCK_AFTER_MS (FIX M). */
|
|
162
|
-
stuck(): Promise<TokenSettlementRow[]>
|
|
163
|
-
/** Handle rail: send to an identity key over MessageBox (lib transferTokens). */
|
|
164
|
-
sendToHandle(args: {
|
|
118
|
+
/** What the nearby rail (localpay build, payer hold, payee pending) is handed by the runtime. */
|
|
119
|
+
export interface NearbyTokenDeps {
|
|
120
|
+
/** PAYER: build and sign the module hand-over bound to the session's remittance (Task 15). */
|
|
121
|
+
handover(a: {
|
|
165
122
|
assetId: string
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
123
|
+
units: bigint
|
|
124
|
+
recipientKey: string
|
|
125
|
+
derivationPrefix: string
|
|
126
|
+
derivationSuffix: string
|
|
170
127
|
note?: string
|
|
171
|
-
}): Promise<
|
|
128
|
+
}): Promise<HandoverResult>
|
|
129
|
+
/** PAYER: the frame was handed over (or parked) (Task 15). */
|
|
130
|
+
onHandedOver(txid: string, state: 'parked' | 'handed_over'): Promise<void>
|
|
172
131
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* what
|
|
132
|
+
* PAYEE: run the lib's recipient path on a token frame's v4 body (B7):
|
|
133
|
+
* strict parse, online submit or offline COVER with the S1 hop checks, the
|
|
134
|
+
* host-ledger record, then the plain BRC-207 receipt internalize. Throws
|
|
135
|
+
* what the lib throws; `offline` is true when the credit rests on COVER
|
|
136
|
+
* evidence (pending settlement).
|
|
177
137
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
* their own money to reach the issuer. So this runs exactly what the drain
|
|
194
|
-
* would have run for this txid: COVER, `/submit` parents-first, and a
|
|
195
|
-
* broadcast of the tip only once every ancestor is admitted.
|
|
196
|
-
*
|
|
197
|
-
* **Never a failure path.** It reports where the row ended up; it does not
|
|
198
|
-
* throw, and a caller that cannot reach the overlay simply gets the state it
|
|
199
|
-
* started with back, because the drain still owns the retry. The two states
|
|
200
|
-
* the USER owns (`'built'`, `'parked'`) are returned untouched — FIX F: a
|
|
201
|
-
* payment the payer deliberately withheld is not settled by anybody's
|
|
202
|
-
* optimisation.
|
|
203
|
-
*
|
|
204
|
-
* **Safe to race with the tick drain.** Every advance is a CAS
|
|
205
|
-
* (`advanceSettlement`) and `/submit` is idempotent (FIX C), so the worst a
|
|
206
|
-
* lost race costs is one duplicate submit that returns the same admission.
|
|
207
|
-
* Two overlapping `settleNow` calls for the same txid are coalesced onto one
|
|
208
|
-
* in-flight run and get the same answer.
|
|
209
|
-
*/
|
|
210
|
-
settleNow(txid: string): Promise<TokenSettleState>
|
|
138
|
+
accept(
|
|
139
|
+
frame: PaymentFrame
|
|
140
|
+
): Promise<{ txid: string; assetId: string; units: bigint; outputIndex: number; offline: boolean }>
|
|
141
|
+
/** PAYEE: the receipt settled either way (Task 16). */
|
|
142
|
+
onReceived(
|
|
143
|
+
a: {
|
|
144
|
+
txid: string
|
|
145
|
+
assetId: string
|
|
146
|
+
units: bigint
|
|
147
|
+
counterpartyKey: string
|
|
148
|
+
outputIndex: number
|
|
149
|
+
},
|
|
150
|
+
outcome: { ok: true; offline: boolean } | { ok: false; code: string; final: boolean }
|
|
151
|
+
): Promise<void>
|
|
152
|
+
}
|
|
211
153
|
|
|
154
|
+
export interface MandalaRuntime {
|
|
155
|
+
/** Endpoints, the color module, its provider and a wallet database are all present. */
|
|
156
|
+
available: boolean
|
|
212
157
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* what this device holds (blinding journal or the payee output's marker, the
|
|
216
|
-
* bytes `refetch` finds, any cached σ_I) and is the same body `transferTokens`
|
|
217
|
-
* sends, so the recipient's inbox needs nothing new. Never contacts the
|
|
218
|
-
* overlay and never moves the transaction's own status — a delivery, not a
|
|
219
|
-
* payment. See `core/mandala/resendTransfer.ts`.
|
|
158
|
+
* THIS DEVICE's configured Mandala deployment. Every field is `''` when this
|
|
159
|
+
* chain has none (`available === false`), which no frame can ever equal.
|
|
220
160
|
*/
|
|
221
|
-
|
|
222
|
-
txid: string,
|
|
223
|
-
deps: {
|
|
224
|
-
/** AtomicBEEF for the txid — `makeResendBeef` in the app. */
|
|
225
|
-
refetch: (txid: string) => Promise<number[] | undefined>
|
|
226
|
-
/** Unwraps metadata the permissions manager encrypted on its way to storage. */
|
|
227
|
-
decryptMetadata?: (value: string) => Promise<string>
|
|
228
|
-
}
|
|
229
|
-
): Promise<TokenResendOutcome>
|
|
230
|
-
|
|
161
|
+
endpoints: MandalaEndpointConfig
|
|
231
162
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* row
|
|
235
|
-
* had no retry at all (2026-09-15). Rides the drain tick. Never throws;
|
|
236
|
-
* returns how many rows changed state.
|
|
163
|
+
* The `color_transfers` journal: the one key for the broadcast hold and the
|
|
164
|
+
* abort refusal. Without a database every method rejects; it never reads as
|
|
165
|
+
* "no row".
|
|
237
166
|
*/
|
|
238
|
-
|
|
167
|
+
journal: TransferJournal
|
|
239
168
|
|
|
240
|
-
/**
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
* refusals, overlay-accepted-but-unbroadcast txs, pending aborts, the stuck
|
|
249
|
-
* `nosend` sweep) and `reconcileNotifications` (recipient notifications a
|
|
250
|
-
* crashed or offline send never delivered).
|
|
251
|
-
*
|
|
252
|
-
* Separate from `drainNow`'s settlement pass because it recovers the HANDLE
|
|
253
|
-
* rail's half-finished state, which has no `token_settlements` row of its
|
|
254
|
-
* own to drain — and it rides the same tick because both are "what this
|
|
255
|
-
* device owes after a reconnect". Best-effort in every direction: never
|
|
256
|
-
* throws, and an unreachable overlay or MessageBox simply leaves the entries
|
|
257
|
-
* journaled for the next pass.
|
|
258
|
-
*/
|
|
259
|
-
reconcileJournals(): Promise<void>
|
|
260
|
-
/** Plain reason a recipient string cannot receive tokens, or null (D4 / ux §5.4). */
|
|
261
|
-
recipientRefusal(recipient: string): string | null
|
|
262
|
-
/** Subscribe to changes (balances/activity/settlement state). Returns unsubscribe. */
|
|
263
|
-
subscribe(listener: () => void): () => void
|
|
264
|
-
/**
|
|
265
|
-
* GET /admin/admission/:txid, mapped and FIX-H-verified against this
|
|
266
|
-
* session's overlay identity key (an unverifiable 'admitted' answer counts
|
|
267
|
-
* as absent). Used by `cancelParkedPayment`'s overlay-authoritative cancel
|
|
268
|
-
* (FIX J) and by `recoverStaleAdmissions`' own recovery pass.
|
|
269
|
-
*/
|
|
270
|
-
fetchAdmission: FetchAdmissionFn
|
|
271
|
-
/**
|
|
272
|
-
* FIX C recovery: advances any `handed_over`/`held` row older than one
|
|
273
|
-
* drain interval with no local admission by asking the overlay once per
|
|
274
|
-
* pass. Returns the number of rows advanced. Never throws.
|
|
275
|
-
*/
|
|
276
|
-
recoverStaleAdmissions(): Promise<number>
|
|
277
|
-
/**
|
|
278
|
-
* Repair the wallet's own view of a token transaction it wrongly failed.
|
|
279
|
-
*
|
|
280
|
-
* A `token_settlements` row reading `admitted`/`broadcast` beside a wallet
|
|
281
|
-
* transaction reading `failed` (and a request reading `invalid`) is the
|
|
282
|
-
* 2026-09-15 fingerprint: the overlay admitted — and therefore broadcast —
|
|
283
|
-
* the transaction, and an abort a moment later released its input coin as
|
|
284
|
-
* spendable although it was spent on chain. For every such row where the
|
|
285
|
-
* transaction is independently confirmed to exist (the chain, or an admission
|
|
286
|
-
* the overlay still holds), this puts the transaction back to a live status,
|
|
287
|
-
* re-marks its inputs spent, restores its own outputs to spendable and
|
|
288
|
-
* repairs the request so the monitor proves it.
|
|
289
|
-
*
|
|
290
|
-
* Rides the drain tick, returns the number of transactions repaired, and
|
|
291
|
-
* never throws. Never acts on the settlement row alone.
|
|
292
|
-
*/
|
|
293
|
-
repairAdmittedAborted(): Promise<number>
|
|
294
|
-
/**
|
|
295
|
-
* The Check Wallet pass over token state, on demand rather than on the tick.
|
|
296
|
-
*
|
|
297
|
-
* Every non-terminal settlement row the drain owns takes one `settleNow`
|
|
298
|
-
* step; whatever is still not settled is put to the overlay. Every spendable
|
|
299
|
-
* token coin without a verified σ_I covering its vout is put to the overlay
|
|
300
|
-
* too. Only the overlay's OWN final verdict writes anything: a refused or
|
|
301
|
-
* evicted transaction is failed locally (its row closed, its inputs freed,
|
|
302
|
-
* its outputs made unspendable), and a coin the overlay admitted for other
|
|
303
|
-
* outputs is made unspendable. A row or coin the overlay has never heard of
|
|
304
|
-
* is counted as `unattested` and left exactly as it was — the drain still
|
|
305
|
-
* owns it, and removing it on absence would be removing it on a guess.
|
|
306
|
-
* `unreachable` is true when the overlay could not be asked; nothing was
|
|
307
|
-
* decided in that case. Never throws.
|
|
308
|
-
*/
|
|
309
|
-
reviewTokenHoldings(): Promise<TokenHoldingsReview>
|
|
310
|
-
/**
|
|
311
|
-
* Sweeps abandoned nearby-blinding reservations (a `lockToPayee` call whose
|
|
312
|
-
* payment was never built/committed) older than 24h. Returns the number
|
|
313
|
-
* removed. Never throws.
|
|
314
|
-
*/
|
|
315
|
-
pruneBlindingReservations(): Promise<number>
|
|
169
|
+
/** Assets this wallet holds (any inventory record) or has ever journaled. */
|
|
170
|
+
listAssets(): Promise<TokenAssetInfo[]>
|
|
171
|
+
/** One row per asset with a value record in the inventory. Rejects (never a partial figure) when a read fails. */
|
|
172
|
+
balances(): Promise<TokenBalance[]>
|
|
173
|
+
/** Journal rows, newest first, cancelled sends omitted. */
|
|
174
|
+
activity(limit?: number): Promise<TokenActivityRow[]>
|
|
175
|
+
/** Non-terminal journal rows older than STUCK_AFTER_MS. */
|
|
176
|
+
stuck(): Promise<ColorTransferRow[]>
|
|
316
177
|
/** Regulatory/registry facts about `assetId`, from the ~10s cache. */
|
|
317
178
|
assetStatus(assetId: string): Promise<TokenAssetStatus>
|
|
318
179
|
/** Same as `assetStatus`, forcing a fresh read past the cache. */
|
|
319
180
|
refreshAssetStatus(assetId: string): Promise<TokenAssetStatus>
|
|
181
|
+
/** Caches a deploy tx for offline metadata reads (W7). Never throws. */
|
|
182
|
+
rememberDeploy(declarationTxHex: string): Promise<void>
|
|
183
|
+
/** Plain reason a recipient string cannot receive tokens, or null. Sending to self is allowed. */
|
|
184
|
+
recipientRefusal(recipient: string): string | null
|
|
185
|
+
/** Subscribe to changes (balances/activity/settlement state). Returns unsubscribe. */
|
|
186
|
+
subscribe(listener: () => void): () => void
|
|
320
187
|
|
|
321
|
-
// ── Injection points ──
|
|
322
|
-
//
|
|
323
|
-
// Everything above is something a screen asks the runtime to DO. Everything
|
|
324
|
-
// below is something the runtime hands to machinery that already exists —
|
|
325
|
-
// the release drain, the nearby build, the frame verifier, the pending
|
|
326
|
-
// queue — so that each of those keeps its own single call site instead of
|
|
327
|
-
// growing a second, Mandala-shaped one. They are on this interface rather
|
|
328
|
-
// than on a wider "wallet runtime" type because the UI assembles some of
|
|
329
|
-
// them (NearbyFlow's build deps) and the wallet shell the rest, and both
|
|
330
|
-
// read the same `useWallet().mandala`.
|
|
331
|
-
|
|
332
|
-
/** Token deps for `processOfflineActions`, passed on every drain tick (§4.3). */
|
|
333
|
-
tokenDeps: OfflineTokenDeps
|
|
334
|
-
/** What `buildPaymentFrame` needs for a nearby token payment: `{ store, lockToPayee }`. */
|
|
335
|
-
tokenBuildDeps: TokenBuildDeps
|
|
336
|
-
/** The pure COVER verifier `coverFromFrame` injects when a frame is handed over. */
|
|
337
|
-
coverVerifier: CoverVerifier
|
|
338
|
-
/** FIX H: verifies a counterparty-supplied σ_I (a settlement ack) before it gates anything. */
|
|
339
|
-
verifyAdmissionEntry: VerifyAdmissionFn
|
|
340
|
-
/**
|
|
341
|
-
* The same check, curried onto THIS session's configured overlay identity
|
|
342
|
-
* key — the shape the drain and the frame verifier inject (`AdmissionVerifier`).
|
|
343
|
-
* A caller cannot name the key it wants an entry checked against, which is
|
|
344
|
-
* the point: §9.10's expected signer is configuration, never frame data.
|
|
345
|
-
*/
|
|
346
|
-
verifyAdmission: AdmissionVerifier
|
|
347
|
-
/** `processPending`'s token hook: journal a credited frame's settlement row and evidence. */
|
|
348
|
-
onTokenCredited: TokenCreditedHook
|
|
349
188
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
189
|
+
* One row's settlement (B7): a delivered own hand-over through lib
|
|
190
|
+
* `settleHandover`, a held receipt through `settleReceipts`; built/parked
|
|
191
|
+
* and undelivered rows are returned untouched.
|
|
353
192
|
*/
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
193
|
+
settleNow(txid: string): Promise<TokenSettleState>
|
|
194
|
+
/** Every pending receipt and delivered own hand-over, single-flight; returns how many journal rows changed. */
|
|
195
|
+
settleAll(): Promise<number>
|
|
196
|
+
/** `settleAll` plus a count of where every row stands (Task 12). */
|
|
197
|
+
reviewTokenHoldings(): Promise<TokenHoldingsReview>
|
|
198
|
+
/** Whether the overlay already admitted this hand-over; `undefined` when it cannot be asked (Task 12). */
|
|
199
|
+
isHandoverAdmitted(txid: string): Promise<boolean | undefined>
|
|
200
|
+
/** Journals held 1Color receipts that have no row (held when `color_offline`, else settled) (Task 12). */
|
|
201
|
+
reconcileHeld(txids: readonly string[]): Promise<void>
|
|
202
|
+
/** Handle rail: hand over to an identity key and deliver over MessageBox (Task 13). */
|
|
203
|
+
sendToHandle(a: {
|
|
204
|
+
assetId: string
|
|
205
|
+
recipientIdentityKey: string
|
|
206
|
+
units: bigint
|
|
207
|
+
note?: string
|
|
208
|
+
}): Promise<TokenSendResult>
|
|
209
|
+
/** Handle rail: drain the `mandala-color` box. `incomplete`: the box could not be read (Task 13). */
|
|
210
|
+
receiveFromInbox(): Promise<{ credited: number; failed: number; incomplete?: true }>
|
|
211
|
+
/** Re-deliver a sent hand-over over MessageBox. Never contacts the overlay (Task 13). */
|
|
212
|
+
resendTransfer(txid: string): Promise<'resent' | 'not-found' | 'unavailable'>
|
|
213
|
+
/** One drain pass: redeliver, settle, reconcile held. Never throws (Task 17). */
|
|
214
|
+
tick(): Promise<void>
|
|
215
|
+
nearby: NearbyTokenDeps
|
|
362
216
|
}
|