@qntx/wallet-engine 0.13.0 → 0.14.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.
Files changed (80) hide show
  1. package/README.md +1057 -20
  2. package/dist/apps-fiat24.d.mts +202 -0
  3. package/dist/apps-fiat24.mjs +1378 -0
  4. package/dist/apps-fiat24.mjs.map +1 -0
  5. package/dist/apps-hyperliquid.d.mts +549 -0
  6. package/dist/apps-hyperliquid.mjs +2742 -0
  7. package/dist/apps-hyperliquid.mjs.map +1 -0
  8. package/dist/apps-polymarket.d.mts +729 -0
  9. package/dist/apps-polymarket.mjs +3786 -0
  10. package/dist/apps-polymarket.mjs.map +1 -0
  11. package/dist/apps.d.mts +136 -0
  12. package/dist/apps.mjs +535 -0
  13. package/dist/apps.mjs.map +1 -0
  14. package/dist/connect-BY1C5ZRI.mjs +210 -0
  15. package/dist/connect-BY1C5ZRI.mjs.map +1 -0
  16. package/dist/connect.d.mts +17 -9
  17. package/dist/connect.mjs +3 -185
  18. package/dist/{errors-CQnlTc1i.d.mts → controller-DpNVHVsj.d.mts} +1093 -758
  19. package/dist/controller-rMnaxKAH.mjs +46 -0
  20. package/dist/controller-rMnaxKAH.mjs.map +1 -0
  21. package/dist/decimal-COJ4g8qy.mjs +38 -0
  22. package/dist/decimal-COJ4g8qy.mjs.map +1 -0
  23. package/dist/eligibility-BfM9ybYZ.mjs +48 -0
  24. package/dist/eligibility-BfM9ybYZ.mjs.map +1 -0
  25. package/dist/engine-Dic_kkEr.d.mts +1829 -0
  26. package/dist/errors-B8W-hoYW.d.mts +7 -0
  27. package/dist/errors-horUy5k1.mjs +24 -0
  28. package/dist/errors-horUy5k1.mjs.map +1 -0
  29. package/dist/gateway-contract.d.mts +3 -608
  30. package/dist/gateway-contract.mjs +1467 -161
  31. package/dist/gateway-contract.mjs.map +1 -1
  32. package/dist/idb.d.mts +5 -0
  33. package/dist/idb.mjs +122 -46
  34. package/dist/idb.mjs.map +1 -1
  35. package/dist/index-vBgfOFIh.d.mts +2227 -0
  36. package/dist/index.d.mts +58 -618
  37. package/dist/index.mjs +21963 -6836
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/json-BDwV38cj.mjs +15 -0
  40. package/dist/json-BDwV38cj.mjs.map +1 -0
  41. package/dist/link-Ceq8Dggp.mjs +139 -0
  42. package/dist/link-Ceq8Dggp.mjs.map +1 -0
  43. package/dist/primitives-DbSHLZKq.mjs +31 -0
  44. package/dist/primitives-DbSHLZKq.mjs.map +1 -0
  45. package/dist/push-message-AQuzoNFY.d.mts +84 -0
  46. package/dist/push-message-kbnH1A5w.mjs +142 -0
  47. package/dist/push-message-kbnH1A5w.mjs.map +1 -0
  48. package/dist/push.d.mts +13 -0
  49. package/dist/push.mjs +70 -0
  50. package/dist/push.mjs.map +1 -0
  51. package/dist/qr.d.mts +292 -0
  52. package/dist/qr.mjs +1725 -0
  53. package/dist/qr.mjs.map +1 -0
  54. package/dist/registry-CbtwcxkX.mjs +374 -0
  55. package/dist/registry-CbtwcxkX.mjs.map +1 -0
  56. package/dist/risk-DyABgg4W.mjs +757 -0
  57. package/dist/risk-DyABgg4W.mjs.map +1 -0
  58. package/dist/session-CNJFLarP.mjs +18 -0
  59. package/dist/session-CNJFLarP.mjs.map +1 -0
  60. package/dist/socket-ChG9JRT_.mjs +110 -0
  61. package/dist/socket-ChG9JRT_.mjs.map +1 -0
  62. package/dist/spi-BrTw5s98.d.mts +3 -0
  63. package/dist/timer-Cdk5rGM2.mjs +43 -0
  64. package/dist/timer-Cdk5rGM2.mjs.map +1 -0
  65. package/dist/types-BpvioFGo.d.mts +258 -0
  66. package/dist/types-DbftVZ3I.mjs +90 -0
  67. package/dist/types-DbftVZ3I.mjs.map +1 -0
  68. package/dist/walletconnect.d.mts +86 -0
  69. package/dist/walletconnect.mjs +1507 -0
  70. package/dist/walletconnect.mjs.map +1 -0
  71. package/dist/webln-BgrtPXpG.mjs +2593 -0
  72. package/dist/webln-BgrtPXpG.mjs.map +1 -0
  73. package/dist/webln-Bllk_xJ2.d.mts +666 -0
  74. package/package.json +92 -19
  75. package/dist/connect.mjs.map +0 -1
  76. package/dist/registry-DwguKWvt.d.mts +0 -27
  77. package/dist/registry-oorLoGtz.mjs +0 -120
  78. package/dist/registry-oorLoGtz.mjs.map +0 -1
  79. package/dist/webln-DKqCnqx1.mjs +0 -3677
  80. package/dist/webln-DKqCnqx1.mjs.map +0 -1
@@ -1,27 +1,107 @@
1
- import { r as NetworkInfo } from "./registry-DwguKWvt.mjs";
1
+ import { Gr as TronNodePath, Lr as TronIndexerPath, dr as NetworkInfo } from "./index-vBgfOFIh.mjs";
2
2
  import { StoreApi } from "zustand/vanilla";
3
- import { MessageContent, SignRequest } from "@qntx/wallet-chains";
4
- import { NostrKeyRef, UnlockFactor, Wallet } from "@qntx/wallet";
3
+ import { BitcoinTemplate, ChainError, DisplayIntent, MessageContent, SignRequest } from "@qntx/wallet-chains";
4
+ import { PublicClient } from "viem";
5
+ import "@solana/kit";
5
6
  import { decodeEvm } from "@qntx/wallet-chains/evm";
6
7
  import "@scure/btc-signer";
8
+ import { BitcoinAccountTemplate, BitcoinOwn } from "@qntx/wallet-chains/bitcoin";
7
9
  import { CooperativeExitResult, LightningInvoice, LightningPayment, LightningSendStatus, SparkClient, SparkNetwork, SparkPayment, SparkStore, SparkTransfer } from "@qntx/spark";
10
+ import { NostrKeyRef, VerifyFactor, Wallet } from "@qntx/wallet";
8
11
  import { LnurlPayRequest, LnurlWithdrawRequest } from "@qntx/spark/lnurl";
9
12
  import { Event, NostrSigner, UnsignedEvent } from "@qntx/nostr";
10
- import { chains } from "@qntx/wallet/chains";
11
- import { PublicClient } from "viem";
12
- import { WalletSigner } from "@qntx/wallet/nostr";
13
13
  import { SparkSigner } from "@qntx/wallet/spark";
14
- import "@solana/kit";
15
- import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
14
+ import { ChainsApi, chains } from "@qntx/wallet/chains";
16
15
  import "@scure/btc-signer/psbt.js";
16
+ import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
17
+ /** Log port: listener failures are reported here and never reach the emitter or peers. */
18
+ type EngineLogger = {
19
+ readonly warn: (message: string, error?: unknown) => void;
20
+ };
21
+ type EventBus<E> = {
22
+ /** Synchronous dispatch to every current listener in registration order. */
23
+ emit: <K extends keyof E>(type: K, payload: E[K]) => void;
24
+ on: <K extends keyof E>(type: K, listener: (payload: E[K]) => void) => () => void;
25
+ };
26
+ declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
27
+ /**
28
+ * A one-shot timer, `setTimeout` semantics: `fn` runs at most once, `ms` after the call, unless the
29
+ * returned function cancels it first. Every host passes exactly this; loops re-arm through
30
+ * {@link repeat}.
31
+ */
32
+ type SetTimer = (ms: number, fn: () => unknown) => () => void;
33
+ /**
34
+ * An `AbortSignal` that fires after `ms` on the injected timer — the platform timeout signal is not
35
+ * available in every runtime this package runs in. Call `cancel` once the work is done, or `abort`
36
+ * to stop it early.
37
+ */
38
+ declare function timeoutSignal(ms: number, setTimer: SetTimer): {
39
+ readonly signal: AbortSignal;
40
+ readonly cancel: () => void;
41
+ readonly abort: () => void;
42
+ };
43
+ type Esplora = {
44
+ readonly get: (path: string) => Promise<unknown>;
45
+ readonly post: (path: string, body: string) => Promise<unknown>;
46
+ };
47
+ /** TRON HTTP client: POSTs an allow-listed path to each endpoint in order. */
48
+ type TronApi = {
49
+ readonly post: (path: TronNodePath | TronIndexerPath, body: unknown) => Promise<unknown>;
50
+ };
51
+ /** A `pinnedTronCaller` client plus the endpoint it committed to after its first answer. */
52
+ type PinnedTronApi = TronApi & {
53
+ /** The URL every later read goes to; `undefined` until the first call answers. */
54
+ readonly pinnedUrl: () => string | undefined;
55
+ };
56
+ /**
57
+ * The TRON node API is throttling and the transaction's validity window does not leave time to wait
58
+ * the requested backoff out — retry the request later.
59
+ */
60
+ declare class TronThrottledError extends Error {
61
+ readonly retryAfterMs: number;
62
+ constructor(retryAfterMs: number);
63
+ }
64
+ type TronFeeQuote = {
65
+ /** Sun the transaction is expected to burn: bandwidth + activation + expected energy. */
66
+ readonly expected: string;
67
+ /** Sun the transaction could burn at most: bandwidth max + activation + `fee_limit`. */
68
+ readonly max: string;
69
+ readonly bandwidth: {
70
+ readonly bytes: number;
71
+ readonly source: "staked" | "free" | "burn" | "activation-staked" | "activation-fee";
72
+ readonly stakedAvailable: bigint;
73
+ readonly freeAvailable: bigint;
74
+ /** Sun the bandwidth is expected to burn. */
75
+ readonly burn: string;
76
+ };
77
+ /** Sun the system contract charges for activating the recipient (absent when not activating). */
78
+ readonly activation?: string;
79
+ readonly energy?: {
80
+ /** `energy_used` — the total estimate, penalty included. */
81
+ readonly used: number;
82
+ /** The dynamic-energy penalty inside `used`. */
83
+ readonly penalty: number;
84
+ /** Staked energy available to the caller. */
85
+ readonly available: bigint;
86
+ /** Sun the caller is expected to burn — the deployer's share only lowers it. */
87
+ readonly burn: string;
88
+ /** Sun the transaction's `fee_limit` is set to. */
89
+ readonly feeLimit: string;
90
+ };
91
+ /** Sun the memo costs (`getMemoFee`); present when `memo` was set. */
92
+ readonly memo?: string;
93
+ readonly warnings: ReadonlyArray<"recipient-not-activated" | "token-recipient-empty" | "fee-limit-below-estimate">;
94
+ };
17
95
  type ControllerOptions<S> = {
18
96
  readonly name: string;
19
97
  readonly defaultState: () => S;
20
98
  };
21
99
  /**
22
100
  * Controller base: a zustand vanilla store plus lifecycle. `update` applies a recipe that must
23
- * return a NEW state object; returning the same reference is a no-op (no set, no notification).
24
- * Persistence and migrations layer on later — this package carries only what its first user needs.
101
+ * return a NEW state object — it replaces the store's state wholesale — and every stored state is
102
+ * deeply frozen once, at this boundary: what `getState` hands a host can only be read. Returning
103
+ * the same reference is a no-op (no set, no notification). Persistence and migrations layer on
104
+ * later — this package carries only what its first user needs.
25
105
  */
26
106
  declare abstract class Controller<S extends Record<string, unknown>> {
27
107
  readonly name: string;
@@ -32,21 +112,39 @@ declare abstract class Controller<S extends Record<string, unknown>> {
32
112
  abstract init(): Promise<void>;
33
113
  abstract destroy(): Promise<void>;
34
114
  }
35
- /** Log port: listener failures are reported here and never reach the emitter or peers. */
36
- type EngineLogger = {
37
- readonly warn: (message: string, error?: unknown) => void;
38
- };
39
- type EventBus<E> = {
40
- /** Synchronous dispatch to every current listener in registration order. */
41
- emit: <K extends keyof E>(type: K, payload: E[K]) => void;
42
- on: <K extends keyof E>(type: K, listener: (payload: E[K]) => void) => () => void;
115
+ /**
116
+ * Per-session gateway client ids — a fresh unlinkable id per scope. Lives apart from client.ts so
117
+ * entries that need only session ids (the apps eligibility fetch) don't bundle the contract table
118
+ * that `gatewayScope` requires.
119
+ */
120
+ /** A gateway traffic class with its own client id: one per chain family plus the service routes. */
121
+ type GatewayScope = "evm" | "solana" | "bitcoin" | "tron" | "service";
122
+ type GatewayConfig = {
123
+ readonly url: string;
124
+ readonly clientIds: Readonly<Record<GatewayScope, string>>;
43
125
  };
44
- declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
126
+ type EngineErrorCode = "closed" | "invalid-input";
127
+ /** Typed engine errors: store codes are `closed` and `invalid-input`. */
128
+ declare class EngineStoreError extends Error {
129
+ readonly code: EngineErrorCode;
130
+ constructor(code: EngineErrorCode, message: string);
131
+ }
132
+ /** Why an NFT transfer preparation refused, surfaced for callers that branch on it. */
133
+ type NftRefusal = "not-nft" | "not-owned" | "insufficient-balance" | "programmable" | "frozen" | "not-found";
134
+ /** An NFT send refusal: `code` stays `invalid-request`, `reason` names which guard fired. */
135
+ declare class NftTransferError extends ChainError {
136
+ readonly reason: NftRefusal;
137
+ constructor(reason: NftRefusal, message: string);
138
+ }
45
139
  /**
46
140
  * Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
47
141
  * the same collection object backs every call, so guards (closed) live on the store.
48
142
  */
49
143
  type EngineCollection = {
144
+ /**
145
+ * Resolves `undefined` for a missing record AND for one the store cannot authenticate — an
146
+ * unauthenticated record reads exactly like a deleted one.
147
+ */
50
148
  readonly get: (key: string) => Promise<Uint8Array | undefined>;
51
149
  readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
52
150
  readonly delete: (key: string) => Promise<void>;
@@ -65,7 +163,142 @@ type PublicStore = {
65
163
  readonly get: (key: string) => Promise<Uint8Array | undefined>;
66
164
  readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
67
165
  };
68
- type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
166
+ type SolanaRpc = {
167
+ readonly call: (method: string, params: unknown[]) => Promise<unknown>;
168
+ };
169
+ /** A `pinnedSolanaCaller` client plus the endpoint it committed to after its first answer. */
170
+ type PinnedSolanaRpc = SolanaRpc & {
171
+ /** The URL every later read goes to; `undefined` until the first call answers. */
172
+ readonly pinnedUrl: () => string | undefined;
173
+ };
174
+ /**
175
+ * A second-upstream client for cross-checking reads the primary endpoints answered. `not-needed`:
176
+ * the primary already comes from a host endpoint — trusted configuration — so no other upstream is
177
+ * involved. `unavailable`: a cross-check is needed but there is no second upstream to run it on.
178
+ * `available` carries the corroborating client and names which upstream it reads: a `host` endpoint
179
+ * is trusted configuration; `gateway` is the gateway a custom-endpoint list displaced — a different
180
+ * upstream than the primary, but not trusted configuration.
181
+ */
182
+ type Independent<T> = {
183
+ readonly kind: "not-needed";
184
+ } | {
185
+ readonly kind: "unavailable";
186
+ } | {
187
+ readonly kind: "available";
188
+ readonly source: "host" | "gateway";
189
+ readonly client: T;
190
+ };
191
+ type NetworkControllerState = {
192
+ readonly customRpc: Record<string, ReadonlyArray<string>>;
193
+ };
194
+ type Options$1 = {
195
+ readonly fetch: typeof globalThis.fetch;
196
+ readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
197
+ /** The session EngineStore — the engine opens it once per unlock and closes it on lock. */
198
+ readonly openStore: () => Promise<EngineStore>;
199
+ readonly logger: EngineLogger;
200
+ readonly gateway?: GatewayConfig | undefined;
201
+ readonly setTimer: SetTimer;
202
+ readonly random: (length: number) => Uint8Array;
203
+ readonly now: () => number;
204
+ };
205
+ declare class NetworkController extends Controller<NetworkControllerState> {
206
+ private readonly options;
207
+ private engineStore?;
208
+ private readonly clients;
209
+ private readonly ensClients;
210
+ private readonly gatewayBase;
211
+ private readonly gatewayFetch;
212
+ /** The persisted custom endpoints, verified or not — what `addRpc` writes back. */
213
+ private storedRpc;
214
+ /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
215
+ private gatewayServed;
216
+ constructor(options: Options$1);
217
+ init(): Promise<void>;
218
+ /**
219
+ * Loads the persisted custom endpoints and re-verifies each against its network before use: an
220
+ * endpoint that no longer serves the chain (or does not answer) is skipped for this session and
221
+ * stays persisted, so a transient failure costs nothing at the next unlock.
222
+ */
223
+ private loadCustomRpc;
224
+ /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
225
+ private loadGatewayNetworks;
226
+ destroy(): Promise<void>;
227
+ lock(): void;
228
+ /** The gateway URL serving `network`'s family RPC, or `undefined` when the gateway cannot. */
229
+ private gatewayUrl;
230
+ /**
231
+ * Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
232
+ * otherwise a gateway-served network uses gateway → host; else host only.
233
+ */
234
+ endpoints(network: string): ReadonlyArray<string>;
235
+ info(network: string): NetworkInfo;
236
+ client(network: string): PublicClient;
237
+ /** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
238
+ gatewayFirst(network: string): boolean;
239
+ /**
240
+ * The upstream a network's reads corroborate on. A custom-endpoint network is never its own
241
+ * proof: the host endpoints corroborate it when there are any, else the gateway it displaced when
242
+ * the gateway serves the network, else nothing can. A gateway-first network corroborates on the
243
+ * host endpoints as before; a host-only list needs nothing.
244
+ */
245
+ private independent;
246
+ /** Second-upstream EVM client for cross-checking reads; a host never gets the install id. */
247
+ independentClient(network: string): Independent<PublicClient>;
248
+ /**
249
+ * The client's sibling for ENS resolution: same ordered endpoints, CCIP-Read enabled over the
250
+ * plain injected fetch — gateway URLs come from contracts, not the host, so they never get the
251
+ * install id.
252
+ */
253
+ ensClient(network: string): PublicClient;
254
+ /** Second-upstream ENS client for cross-checking resolutions. */
255
+ independentEnsClient(network: string): Independent<PublicClient>;
256
+ independentSolanaRpc(network: string): Independent<SolanaRpc>;
257
+ /**
258
+ * Fresh pinned second-upstream Solana client — for proofs whose reads must all come from one
259
+ * upstream. Only a different upstream than `primaryUrl` corroborates: when the poll's pin already
260
+ * landed on a host endpoint, the host-only continuity rule applies instead of a second read of
261
+ * the same upstream.
262
+ */
263
+ independentPinnedSolanaRpc(network: string, primaryUrl: string | undefined): Independent<SolanaRpc>;
264
+ /** Second-upstream TRON client for cross-checking reads; a host never gets the install id. */
265
+ independentTronApi(network: string): Independent<TronApi>;
266
+ /**
267
+ * Fresh pinned second-upstream TRON client — for proofs whose reads must all come from one
268
+ * upstream. Only a different upstream than `primaryUrl` corroborates: when the poll's pin already
269
+ * landed on a host endpoint, the host-only continuity rule applies instead of a second read of
270
+ * the same upstream.
271
+ */
272
+ independentPinnedTronApi(network: string, primaryUrl: string | undefined): Independent<TronApi>;
273
+ independentEsplora(network: string): Independent<Esplora>;
274
+ /** Networks with at least one configured endpoint or served by the gateway, by family. */
275
+ enabled(family: "evm" | "solana" | "bitcoin" | "tron"): ReadonlyArray<string>;
276
+ /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
277
+ solanaRpc(network: string): SolanaRpc;
278
+ /**
279
+ * Fresh one-upstream Solana client: failover on the first call, then pinned — for a sequence of
280
+ * reads that must agree with each other.
281
+ */
282
+ pinnedSolanaRpc(network: string): PinnedSolanaRpc;
283
+ /** TRON node API over the ordered endpoint list — plain POSTs fail over like Solana's. */
284
+ tronApi(network: string): TronApi;
285
+ /**
286
+ * Fresh one-upstream TRON client: failover on the first call, then pinned — for a sequence of
287
+ * reads that must agree with each other. `until` bounds throttled-read retries to the
288
+ * transaction's validity window; absent, a 429/503 propagates like every other failure.
289
+ */
290
+ pinnedTronApi(network: string, until?: () => number): PinnedTronApi;
291
+ /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
292
+ esplora(network: string): Esplora;
293
+ /**
294
+ * Throws unless `url` serves `info`'s chain: the genesis hash for Bitcoin (Esplora) and Solana,
295
+ * `eth_chainId` for EVM. Bounded like the gateway probe, so a dead endpoint cannot stall unlock.
296
+ */
297
+ private probe;
298
+ /** Validates a custom endpoint against the network's chain, then persists it first in the list. */
299
+ addRpc(network: string, url: string): Promise<void>;
300
+ }
301
+ type AddressFamily = "evm" | "solana" | "bitcoin" | "tron" | "spark";
69
302
  type AddressBookEntry = {
70
303
  readonly id: string;
71
304
  readonly name: string;
@@ -86,6 +319,7 @@ type AddressBookState = {
86
319
  readonly entries: Record<string, AddressBookEntry>;
87
320
  };
88
321
  type AddressBookOptions = {
322
+ /** The session EngineStore — the engine opens it once per unlock and closes it on lock. */
89
323
  readonly openStore: () => Promise<EngineStore>;
90
324
  readonly random: (n: number) => Uint8Array;
91
325
  readonly now: () => number;
@@ -103,9 +337,10 @@ declare class AddressBookController extends Controller<AddressBookState> {
103
337
  /** Entries and tombstones, for the metadata document. */
104
338
  syncEntries(): ReadonlyArray<AddressBookRecord>;
105
339
  /**
106
- * Merges records from another device (last writer wins, tombstones win over older entries).
107
- * Returns whether anything local changed and whether the merged set holds something `remote`
108
- * lacks, i.e. whether the remote copy needs a newer publish.
340
+ * Merges records from another device (last writer wins among records with the same identity,
341
+ * tombstones are terminal, records stamped past the clock bound or rewriting a local identity are
342
+ * refused). Returns whether anything local changed and whether the merged set holds something
343
+ * `remote` lacks, i.e. whether the remote copy needs a newer publish.
109
344
  */
110
345
  merge(remote: ReadonlyArray<AddressBookRecord>): Promise<{
111
346
  readonly changed: boolean;
@@ -122,6 +357,8 @@ declare class AddressBookController extends Controller<AddressBookState> {
122
357
  setNote(id: string, note: string | undefined): Promise<AddressBookEntry>;
123
358
  /** Removes the entry, leaving a tombstone so other devices drop it too. */
124
359
  remove(id: string): Promise<void>;
360
+ /** An edit always stamps above the record it replaces, so it outranks a newer remote copy. */
361
+ private editStamp;
125
362
  private checkedNote;
126
363
  private requireEntry;
127
364
  private persist;
@@ -164,90 +401,6 @@ type SimulationOutcome = {
164
401
  readonly error: string;
165
402
  };
166
403
  type EvmFeeTier = "slow" | "normal" | "fast";
167
- type SetTimer = (ms: number, fn: () => unknown) => () => void;
168
- type Esplora = {
169
- readonly get: (path: string) => Promise<unknown>;
170
- readonly post: (path: string, body: string) => Promise<unknown>;
171
- };
172
- type GatewayConfig = {
173
- readonly url: string;
174
- readonly installId: string;
175
- };
176
- type SolanaRpc = {
177
- readonly call: (method: string, params: unknown[]) => Promise<unknown>;
178
- };
179
- /**
180
- * A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
181
- * not this network's first endpoint, so the primary reads already come from the host.
182
- * `unavailable`: a cross-check is needed but the network has no host endpoint.
183
- */
184
- type Independent<T> = {
185
- readonly kind: "not-needed";
186
- } | {
187
- readonly kind: "unavailable";
188
- } | {
189
- readonly kind: "available";
190
- readonly client: T;
191
- };
192
- type NetworkControllerState = {
193
- readonly customRpc: Record<string, ReadonlyArray<string>>;
194
- };
195
- type Options$3 = {
196
- readonly fetch: typeof globalThis.fetch;
197
- readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
198
- readonly openStore: () => Promise<EngineStore>;
199
- readonly logger: EngineLogger;
200
- readonly gateway?: GatewayConfig | undefined;
201
- readonly setTimer: SetTimer;
202
- readonly random: (length: number) => Uint8Array;
203
- };
204
- declare class NetworkController extends Controller<NetworkControllerState> {
205
- private readonly options;
206
- private engineStore?;
207
- private readonly clients;
208
- private readonly ensClients;
209
- private readonly gatewayBase;
210
- private readonly gatewayFetch;
211
- /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
212
- private gatewayServed;
213
- constructor(options: Options$3);
214
- init(): Promise<void>;
215
- private loadCustomRpc;
216
- /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
217
- private loadGatewayNetworks;
218
- destroy(): Promise<void>;
219
- lock(): void;
220
- /**
221
- * Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
222
- * otherwise a gateway-served network uses gateway → host; else host only.
223
- */
224
- endpoints(network: string): ReadonlyArray<string>;
225
- info(network: string): NetworkInfo;
226
- client(network: string): PublicClient;
227
- /** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
228
- private gatewayFirst;
229
- private independent;
230
- /** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
231
- independentClient(network: string): Independent<PublicClient>;
232
- /**
233
- * The client's sibling for ENS resolution: same ordered endpoints, CCIP-Read enabled over the
234
- * plain injected fetch — gateway URLs come from contracts, not the host, so they never get the
235
- * install id.
236
- */
237
- ensClient(network: string): PublicClient;
238
- /** Host-endpoint ENS client for cross-checking resolutions. */
239
- independentEnsClient(network: string): Independent<PublicClient>;
240
- independentSolanaRpc(network: string): Independent<SolanaRpc>;
241
- independentEsplora(network: string): Independent<Esplora>;
242
- /** Networks with at least one configured endpoint or served by the gateway, by family. */
243
- enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
244
- /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
245
- solanaRpc(network: string): SolanaRpc;
246
- /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
247
- esplora(network: string): Esplora;
248
- /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
249
- addRpc(network: string, url: string): Promise<void>;
250
- }
251
404
  type SolanaFeeTier = "slow" | "normal" | "fast";
252
405
  type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount" | "simulation-unavailable";
253
406
  /**
@@ -269,9 +422,40 @@ type PaymentNote = {
269
422
  type SparkActivity = SparkPayment & {
270
423
  readonly note?: PaymentNote;
271
424
  };
425
+ /** A Spark send or Spark invoice, a Lightning payment, a cooperative exit, or a token send. */
426
+ type SparkPaymentKind = "transfer" | "lightning" | "exit" | "token";
272
427
  /**
273
- * SparkStore over one EngineCollection: chains keyed by leafId, plus an index record listing them
274
- * (`exitChains` is a full listing — the port has no secondary index).
428
+ * `submitted`: persisted before the commit call, and kept after it returned until the operator
429
+ * reports a final status. `unknown`: the commit response was lost — it may have committed.
430
+ * `settled` and `failed` are the operator's final answer. `archived`: the user gave up on an
431
+ * outcome the operator can never answer for — kept, never reconciled, never blocking.
432
+ */
433
+ type SparkPaymentState = "submitted" | "unknown" | "settled" | "failed" | "archived";
434
+ /** One wallet-initiated Spark payment, from just before its commit call to the operator's answer. */
435
+ type SparkPaymentRecord = {
436
+ /** The request's idempotent transfer id — for sats payments, the Spark transfer id. */
437
+ readonly id: string;
438
+ readonly kind: SparkPaymentKind;
439
+ readonly state: SparkPaymentState;
440
+ /** Spark address, Lightning payee public key (hex) or bitcoin address. */
441
+ readonly receiver: string;
442
+ /** Decimal base units: sats, or the token's base units. */
443
+ readonly amount: string;
444
+ /** Token payments: the bech32m token identifier. */
445
+ readonly tokenIdentifier?: string;
446
+ /** Token payments whose broadcast outcome was uncertain: the outputs it spends. */
447
+ readonly inputOutputIds?: ReadonlyArray<string>;
448
+ /** Settled token payments: the final transaction hash. */
449
+ readonly transactionHash?: string;
450
+ /** Milliseconds since the epoch, taken just before the commit call. */
451
+ readonly submittedAt: number;
452
+ /** Why the payment failed, or why its outcome is unknown. */
453
+ readonly error?: string;
454
+ };
455
+ /**
456
+ * SparkStore over one EngineCollection: chains keyed by leafId, enumerated by the port's `list()`.
457
+ * A record that fails to decode — or does not name its own key, like a leftover `__all__` index row
458
+ * from older data — is skipped, not fatal: the next leaves sync rewrites it.
275
459
  */
276
460
  declare function sparkStore(col: EngineCollection): SparkStore;
277
461
  type SparkAccountState = {
@@ -282,6 +466,18 @@ type SparkAccountState = {
282
466
  readonly errorCategory?: string;
283
467
  /** First history page (20 entries, newest first), refreshed alongside the balance. */
284
468
  readonly recent?: ReadonlyArray<SparkActivity>;
469
+ /** Token balances in base units, refreshed alongside `recent`; absent until the first read. */
470
+ readonly tokens?: ReadonlyArray<SparkTokenBalance>;
471
+ /**
472
+ * This session's payment records by id — every open one, plus those that settled or failed since
473
+ * unlock; absent until the account has one.
474
+ */
475
+ readonly payments?: Readonly<Record<string, SparkPaymentRecord>>;
476
+ };
477
+ type SparkTokenBalance = {
478
+ readonly tokenIdentifier: string;
479
+ readonly amount: string;
480
+ readonly outputCount: number;
285
481
  };
286
482
  type SparkControllerState = {
287
483
  readonly accounts: Readonly<Record<string, SparkAccountState>>;
@@ -291,7 +487,7 @@ type SparkApis = {
291
487
  readonly approve: (params: {
292
488
  account: SparkAccountRef;
293
489
  intent: SparkApproveIntent;
294
- verify: UnlockFactor;
490
+ verify: VerifyFactor;
295
491
  }) => Promise<unknown>;
296
492
  };
297
493
  type SparkClientFactory = (options: {
@@ -303,7 +499,6 @@ type SparkClientFactory = (options: {
303
499
  type SparkControllerOptions = {
304
500
  readonly spark: SparkApis;
305
501
  readonly fetch: typeof globalThis.fetch;
306
- readonly random: (length: number) => Uint8Array;
307
502
  readonly now: () => number;
308
503
  readonly logger: EngineLogger;
309
504
  readonly setTimer: (ms: number, fn: () => void) => () => void;
@@ -314,7 +509,9 @@ declare class SparkController extends Controller<SparkControllerState> {
314
509
  private engineStore;
315
510
  private readonly accounts;
316
511
  private readonly clients;
512
+ private readonly ledgers;
317
513
  private readonly recentSeq;
514
+ private readonly tokensSeq;
318
515
  private readonly aborts;
319
516
  constructor(options: SparkControllerOptions);
320
517
  /** Engine calls this with the open store on unlock; `undefined` on lock. */
@@ -341,9 +538,50 @@ declare class SparkController extends Controller<SparkControllerState> {
341
538
  * overwriting a newer one.
342
539
  */
343
540
  private refreshRecent;
541
+ /**
542
+ * Refill `tokens` from the client's balance list. Like `refreshRecent`: a failure warns and keeps
543
+ * the previous list — it never touches `status`/`errorCategory` — and the sequence + client
544
+ * identity guard keeps a stale read from overwriting a newer one.
545
+ */
546
+ private refreshTokens;
344
547
  private patch;
345
548
  private clientFor;
549
+ /** A running account's client and payment ledger — they start and stop together. */
550
+ private connection;
551
+ /**
552
+ * Runs a committing call under a payment record persisted first — a failed write throws before
553
+ * anything is sent. An unknown outcome leaves the record open and throws `unknown` carrying it; a
554
+ * definite error fails it; a call that returns keeps it `submitted` until the operator's history
555
+ * settles it, unless `settled` reads the final state from the result itself.
556
+ */
557
+ private recorded;
558
+ /**
559
+ * A definite pre-commit refusal for sats payments: the operator's balance answers before any
560
+ * record exists — an unreadable balance is `network` (nothing is committed), a shortfall is
561
+ * `insufficient-funds`.
562
+ */
563
+ private requireSats;
346
564
  private guarded;
565
+ /**
566
+ * Runs a committing client call with up to three idempotent retries (1 s, 2 s, 4 s backoff):
567
+ * `retryable` decides which error means the outcome is unknown and the same call may repeat,
568
+ * `call` receives the previous attempt's error so a retry can carry the handle it reported. A
569
+ * definite error on the first attempt propagates; after an uncertain attempt nothing is definite
570
+ * any more — the earlier attempt may have committed — so exhaustion and any later error throw
571
+ * {@link UnknownOutcomeError} with `message`.
572
+ */
573
+ private committing;
574
+ /**
575
+ * A sats payment commits under its transfer id: a network failure leaves the outcome unknown, so
576
+ * the same call retries under the same id — the SO/SSP deduplicates it.
577
+ */
578
+ private committed;
579
+ /**
580
+ * A token transfer commits under its spent output ids: only `SparkTokenBroadcastError` means the
581
+ * broadcast's outcome is uncertain — a plain network error happened before it — so the retry
582
+ * carries `error.inputOutputIds` and the same terms, per the library's contract.
583
+ */
584
+ private committedToken;
347
585
  /**
348
586
  * One-off balance + activity probe for an account that may not be running: builds a temporary
349
587
  * client through the same factory on the account's own exit-chain collection (nothing diverges —
@@ -364,8 +602,31 @@ declare class SparkController extends Controller<SparkControllerState> {
364
602
  send(ref: SparkAccountRef, params: {
365
603
  receiver: string;
366
604
  amountSats: number;
367
- verify: UnlockFactor;
605
+ /** The request's idempotent transfer id — a retry resumes, never double-pays. */
606
+ transferId: string;
607
+ verify: VerifyFactor;
608
+ /** Called immediately before the send; a throw there means nothing may be sent. */
609
+ commit: () => void;
368
610
  }): Promise<SparkTransfer>;
611
+ /**
612
+ * Sends a token amount to a Spark address. The approval intent is the kernel's `token` shape —
613
+ * the raw 32-byte identifier and the receiver's identity key with a canonical decimal amount —
614
+ * and the commit retries only on `SparkTokenBroadcastError`, under the spent output ids it
615
+ * reports; everything else propagates (a plain network failure happened before broadcast).
616
+ */
617
+ sendToken(ref: SparkAccountRef, params: {
618
+ /** Spark address of the receiver. */
619
+ receiver: string;
620
+ /** Bech32m token identifier (`btkn`/`btknrt`). */
621
+ tokenIdentifier: string;
622
+ /** Base units, 1…2^128−1. */
623
+ amount: bigint;
624
+ /** The request's idempotent transfer id — keys the payment record. */
625
+ transferId: string;
626
+ verify: VerifyFactor;
627
+ /** Called immediately before the transfer; a throw there means nothing may be sent. */
628
+ commit: () => void;
629
+ }): Promise<string>;
369
630
  registerLightningAddress(ref: SparkAccountRef, params: {
370
631
  serverUrl: string;
371
632
  domain: string;
@@ -384,7 +645,11 @@ declare class SparkController extends Controller<SparkControllerState> {
384
645
  invoice: string;
385
646
  amountSats?: number;
386
647
  maxFeeSats: number;
387
- verify: UnlockFactor;
648
+ /** The request's idempotent transfer id — a retry resumes, never double-pays. */
649
+ transferId: string;
650
+ verify: VerifyFactor;
651
+ /** Called immediately before the send; a throw there means nothing may be sent. */
652
+ commit: () => void;
388
653
  /** Local annotation written under the payment's transfer id after it succeeds. */
389
654
  note?: PaymentNote;
390
655
  }): Promise<LightningPayment>;
@@ -396,7 +661,11 @@ declare class SparkController extends Controller<SparkControllerState> {
396
661
  paySparkInvoice(ref: SparkAccountRef, params: {
397
662
  invoice: string;
398
663
  amountSats?: number;
399
- verify: UnlockFactor;
664
+ /** The request's idempotent transfer id — a retry resumes, never double-pays. */
665
+ transferId: string;
666
+ verify: VerifyFactor;
667
+ /** Called immediately before the send; a throw there means nothing may be sent. */
668
+ commit: () => void;
400
669
  }): Promise<SparkTransfer>;
401
670
  createInvoice(ref: SparkAccountRef, params: {
402
671
  amountSats: number;
@@ -406,6 +675,13 @@ declare class SparkController extends Controller<SparkControllerState> {
406
675
  newDepositAddress(ref: SparkAccountRef): Promise<string>;
407
676
  /** Claims a confirmed L1 deposit paying one of the account's unused deposit addresses. */
408
677
  claimDeposit(ref: SparkAccountRef, transaction: Uint8Array): Promise<void>;
678
+ /**
679
+ * Archives an open payment record the operator can never answer for — a token send whose
680
+ * broadcast failed before its spent outputs were known. The archived outcome stays genuinely
681
+ * unknown forever: it stops blocking re-sends and `holdsToken`, and history flags it
682
+ * `unresolved`. The host must obtain the user's confirmation first.
683
+ */
684
+ archivePayment(ref: SparkAccountRef, id: string): void;
409
685
  /** The account's last-synced balance — a cached snapshot, not a fresh query. */
410
686
  accountBalance(ref: SparkAccountRef): number | undefined;
411
687
  /** A payment's settle status — `payInvoice` resolves the send; `sendStatus` reports its preimage. */
@@ -415,17 +691,42 @@ declare class SparkController extends Controller<SparkControllerState> {
415
691
  }): Promise<LightningSendStatus>;
416
692
  receiveAddress(ref: SparkAccountRef): Promise<string | undefined>;
417
693
  /**
418
- * Cooperative exit to an L1 address. The client exits `amountSats` of leaves and the payout is
419
- * `amountSats - fee`, so the approval intent carries the PAYOUT: `amountSats: exit - fee` and
420
- * `maxFeeSats: fee` — the kernel matches the exit output against the intent, not the leaf total.
694
+ * The SSP's converged cooperative-exit quote for paying `amountSats` to an L1 address: the fee
695
+ * depends on the gross amount, so the quote is re-taken on `amountSats + fee` until it settles.
696
+ */
697
+ quoteExit(ref: SparkAccountRef, params: {
698
+ address: string;
699
+ /** Sats that arrive at the address — the exit debits amountSats + fee. */
700
+ amountSats: number;
701
+ speed: "FAST" | "MEDIUM" | "SLOW";
702
+ }): Promise<{
703
+ readonly feeSats: number;
704
+ readonly exitSats: number;
705
+ }>;
706
+ /**
707
+ * Cooperative exit to an L1 address: `amountSats` arrives at the address and the exit debits
708
+ * `amountSats + fee` of leaves, where `fee` is the SSP's converged quote for the speed —
709
+ * re-quoted here and bounded by `maxFeeSats` before any approval. The intent carries the payout
710
+ * (`amountSats`) and the fee (`maxFeeSats: fee`); the kernel matches the exit output against it.
421
711
  */
422
712
  withdraw(ref: SparkAccountRef, params: {
423
713
  address: string;
424
- amountSats?: number;
714
+ /** Sats that arrive at the address — the exit debits amountSats + the quoted fee. */
715
+ amountSats: number;
425
716
  speed: "FAST" | "MEDIUM" | "SLOW";
426
- maxFeeSats?: number;
427
- verify: UnlockFactor;
717
+ /** Caller cap on the converged exit fee, in sats. */
718
+ maxFeeSats: number;
719
+ /** The request's idempotent transfer id — a retry resumes, never double-pays. */
720
+ transferId: string;
721
+ verify: VerifyFactor;
722
+ /** Called immediately before the send; a throw there means nothing may be sent. */
723
+ commit: () => void;
428
724
  }): Promise<CooperativeExitResult>;
725
+ /**
726
+ * Converges the SSP exit fee for a payout: the fee is quoted on the gross amount, so re-quote on
727
+ * `amountSats + fee` until the fee stops growing (three re-quotes at most).
728
+ */
729
+ private settleExitFee;
429
730
  }
430
731
  /**
431
732
  * What the host shows for a Spark, Lightning or exit request; `family` tells it apart from a chain
@@ -437,10 +738,22 @@ type SparkDisplay = {
437
738
  readonly kind: "transfer" | "lightning" | "exit";
438
739
  readonly amountSats: number;
439
740
  readonly maxFeeSats?: number;
741
+ /** Exits only: the quoted fee; the debit is `amountSats + feeSats`. */
742
+ readonly feeSats?: number;
440
743
  /** Spark address, Lightning payee public key (hex) or bitcoin address. */
441
744
  readonly receiver: string;
442
745
  /** Invoice description or the LNURL metadata text. */
443
746
  readonly description?: string;
747
+ } | {
748
+ readonly family: "spark";
749
+ readonly network: SparkNetwork;
750
+ readonly kind: "token";
751
+ /** Bech32m token identifier (`btkn`/`btknrt`). */
752
+ readonly tokenIdentifier: string;
753
+ /** Decimal base units. */
754
+ readonly amount: string;
755
+ /** Spark address of the receiver. */
756
+ readonly receiver: string;
444
757
  };
445
758
  type SparkResult = {
446
759
  readonly kind: "spark";
@@ -451,6 +764,18 @@ type SparkResult = {
451
764
  } | {
452
765
  readonly kind: "withdraw";
453
766
  readonly exit: CooperativeExitResult;
767
+ } | {
768
+ readonly kind: "token";
769
+ readonly transactionHash: string;
770
+ } |
771
+ /**
772
+ * The commit response was lost and the payment may have gone out: `payment` is its open record,
773
+ * which `SparkAccountState.payments` and `engine.history` keep following until the Spark operator
774
+ * settles or fails it.
775
+ */
776
+ {
777
+ readonly kind: "pending";
778
+ readonly payment: SparkPaymentRecord;
454
779
  };
455
780
  /**
456
781
  * A validated, fixed Spark payment: everything that does not need the user's verification has
@@ -461,8 +786,12 @@ type PreparedSparkAction = {
461
786
  readonly checks: ReadonlyArray<RequestCheckCode>;
462
787
  /** Why the action can no longer be paid at `now` (an expiring invoice), if so. */
463
788
  readonly staleReason: (now: number) => string | undefined;
464
- /** Runs the controller's approve-first payment call. */
465
- readonly execute: (spark: SparkController, verify: UnlockFactor) => Promise<SparkResult>;
789
+ /**
790
+ * Runs the controller's approve-first payment call. `commit` is the request's point of no return
791
+ * — the controller calls it immediately before the client call that sends, and a throw there
792
+ * means nothing may be sent.
793
+ */
794
+ readonly execute: (spark: SparkController, verify: VerifyFactor, commit: () => void) => Promise<SparkResult>;
466
795
  };
467
796
  type PaymentOption = {
468
797
  readonly kind: "spark";
@@ -498,6 +827,10 @@ type PaymentRequest = {
498
827
  readonly message?: string;
499
828
  };
500
829
  type PaymentParse = {
830
+ /** A WalletConnect pairing URI; the host passes it to the walletconnect entry's `pair`. */
831
+ readonly kind: "walletconnect";
832
+ readonly uri: string;
833
+ } | {
501
834
  readonly kind: "request";
502
835
  readonly request: PaymentRequest;
503
836
  } | {
@@ -529,6 +862,13 @@ type PayParams = {
529
862
  readonly speed?: "FAST" | "MEDIUM" | "SLOW";
530
863
  /** `amountSats` came from the service's minimum (WebLN `lnurl`), not an explicit amount. */
531
864
  readonly amountFromServiceMinimum?: boolean;
865
+ /** Token payment — valid only with the plain `spark` option, and never with `amountSats`. */
866
+ readonly token?: {
867
+ /** Bech32m token identifier (`btkn`/`btknrt`). */
868
+ readonly identifier: string;
869
+ /** Base units. */
870
+ readonly amount: bigint;
871
+ };
532
872
  };
533
873
  type WithdrawLnurlParams = {
534
874
  readonly account: SparkAccountRef;
@@ -626,6 +966,148 @@ declare class PhishingController extends Controller<PhishingState> {
626
966
  private apply;
627
967
  private persist;
628
968
  }
969
+ type ChainRequestMethod = "send" | "speed-up" | "cancel" | "cpfp" | "evm-delegation" | "evm-batch" | "evm-approve" | "evm-revoke" | "evm-cctp" | "evm-swap" | "evm-bridge" | "evm-nft-send" | "solana-nft-send" | "evm-lido" | "solana-stake" | "solana-revoke" | "solana-swap" | "tron-stake" | "tron-approve";
970
+ /** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
971
+ type BrowserOrigin = {
972
+ readonly kind: "browser";
973
+ readonly origin: string;
974
+ };
975
+ type WalletConnectVerify = {
976
+ readonly validation: "VALID" | "INVALID" | "UNKNOWN";
977
+ readonly isScam: boolean;
978
+ };
979
+ /** A WalletConnect peer. `origin` is the session key `walletconnect:<topic>` — never a URL. */
980
+ type WalletConnectOrigin = {
981
+ readonly kind: "walletconnect";
982
+ readonly origin: string;
983
+ readonly topic: string;
984
+ /** The peer's self-declared metadata URL reduced to its origin — display only, never verified. */
985
+ readonly url: string;
986
+ readonly name: string;
987
+ readonly verify: WalletConnectVerify;
988
+ };
989
+ type DappOrigin = BrowserOrigin | WalletConnectOrigin;
990
+ /** A request an in-engine application (Hyperliquid, …) opened — core never enumerates app ids. */
991
+ type AppOrigin = {
992
+ readonly kind: "app";
993
+ readonly id: string;
994
+ };
995
+ /**
996
+ * A scanned QR sign request. `declared` is the counterpart's self-declared origin text — display
997
+ * only, never verified; it is already sanitised and at most 64 characters.
998
+ */
999
+ type QrOrigin = {
1000
+ readonly kind: "qr";
1001
+ readonly declared?: string;
1002
+ };
1003
+ type RequestOrigin = {
1004
+ readonly kind: "internal";
1005
+ } | AppOrigin | DappOrigin | QrOrigin;
1006
+ /** The URL a dApp origin's phishing and sign-in checks run against. */
1007
+ declare const dappUrl: (origin: DappOrigin) => string;
1008
+ declare const walletConnectKey: (topic: string) => string;
1009
+ type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "tron-sign" | "evm-delegation" | "evm-batch" | "nostr-sign" | "webln-invoice" | "watch-asset" | "solana-sign" | "bitcoin-sign" | "spark-deposit" | "spark-exit";
1010
+ /** A Solana chain account the `solana-sign` request signs for. */
1011
+ type SolanaAccount = {
1012
+ readonly walletId: string;
1013
+ readonly groupIndex: number;
1014
+ readonly address: string;
1015
+ };
1016
+ /** A Bitcoin account the `bitcoin-sign` request signs for: the group's fixed dApp-facing address. */
1017
+ type BitcoinAccount = {
1018
+ readonly walletId: string;
1019
+ readonly groupIndex: number;
1020
+ readonly address: string;
1021
+ /** `btc.bip84` for the `payment` purpose, `btc.bip86` for `ordinals`. */
1022
+ readonly template: "btc.bip84" | "btc.bip86";
1023
+ };
1024
+ /**
1025
+ * The wallet group a `bitcoin-sign` PSBT request signs for: inputs of several dApp-facing templates
1026
+ * of the same group may mix in one PSBT — each sign entry names its own template.
1027
+ */
1028
+ type BitcoinGroup = {
1029
+ readonly walletId: string;
1030
+ readonly groupIndex: number;
1031
+ };
1032
+ /** The sighash a dApp asks for per input; anything else is refused before it reaches a request. */
1033
+ type BitcoinSigHash = "ALL" | "SINGLE|ANYONECANPAY";
1034
+ /**
1035
+ * One PSBT and the inputs it asks the wallet to sign — a QR counterpart may request any of the
1036
+ * group's four templates where a dApp only uses the two dApp-facing ones.
1037
+ */
1038
+ type BitcoinPsbtInput = {
1039
+ readonly psbt: Uint8Array;
1040
+ readonly sign: ReadonlyArray<{
1041
+ readonly index: number;
1042
+ readonly sigHash: BitcoinSigHash;
1043
+ readonly template: BitcoinTemplate;
1044
+ }>;
1045
+ };
1046
+ /**
1047
+ * A dApp PSBT after the engine enriched the requested inputs with this account's derivation data:
1048
+ * `request` is what the kernel signs, `own` the verified own-key outputs split into discoverable
1049
+ * change and unusual paths, `inputs` the signed inputs' prevout values and sighash (for risk).
1050
+ */
1051
+ type PreparedBitcoinPsbt = {
1052
+ readonly request: Extract<SignRequest, {
1053
+ kind: "bitcoin.psbt";
1054
+ }>;
1055
+ readonly own: BitcoinOwn;
1056
+ readonly inputs: ReadonlyArray<{
1057
+ readonly index: number;
1058
+ readonly value: number;
1059
+ readonly sigHash: BitcoinSigHash;
1060
+ readonly template: BitcoinTemplate;
1061
+ /** The user froze this outpoint — signing it is a danger finding. */
1062
+ readonly frozen: boolean;
1063
+ }>;
1064
+ };
1065
+ /** A token the page asked to watch whose on-chain metadata cannot be shown; the dApp's bad input. */
1066
+ declare class InvalidTokenError extends Error {
1067
+ constructor(message: string);
1068
+ }
1069
+ /** A Sign-In with X message for another domain than the page that asked for the signature. */
1070
+ declare class SignInOriginError extends Error {
1071
+ constructor(message: string);
1072
+ }
1073
+ /** A request that ended without a result: `stage` says how, `message` is the failure if any. */
1074
+ declare class RequestEndedError extends Error {
1075
+ readonly stage: "rejected" | "failed" | "expired" | "invalidated";
1076
+ /**
1077
+ * Whether the request had reached the `signed` stage when it ended — `false` proves nothing it
1078
+ * produced was broadcast, `true` means a signature may already be out.
1079
+ */
1080
+ readonly signed: boolean;
1081
+ constructor(stage: RequestEndedError["stage"], message: string | undefined, signed: boolean);
1082
+ }
1083
+ /**
1084
+ * An app pinned the nonce its transaction must carry but the sender's next free nonce differs — the
1085
+ * request is refused before anything is shown rather than signed at a nonce that would sit
1086
+ * `unknown` forever.
1087
+ */
1088
+ declare class NonceConflictError extends Error {
1089
+ /** The nonce the caller requires the transaction to carry. */
1090
+ readonly expected: number;
1091
+ /** The sender's next free nonce as the engine sees it. */
1092
+ readonly next: number;
1093
+ constructor(expected: number, next: number);
1094
+ }
1095
+ /** The origin already has a request in flight; a dApp gets one at a time. */
1096
+ declare class OriginBusyError extends Error {
1097
+ constructor(origin: string);
1098
+ }
1099
+ /**
1100
+ * Request risk, pure. A recipient the wallet has never paid or saved is a `warning`; one that looks
1101
+ * like a known address (same first and last four characters, different address) is a `danger` — the
1102
+ * shape of an address-poisoning lookalike. Both can apply to one recipient. A page the user trusts
1103
+ * despite the phishing list is a `danger`; one that could not be checked is a `warning`. A sign-in
1104
+ * over QR carries no verifiable domain at all — a `danger` the user must acknowledge, since a dApp
1105
+ * claiming a domain it does not own is refused outright.
1106
+ */
1107
+ type RiskFinding = {
1108
+ readonly code: "first-recipient" | "address-poisoning" | "phishing-origin" | "phishing-unchecked" | "token-impersonation" | "token-symbol-unicode" | "simulation-reverted" | "simulation-mismatch" | "collection-approval" | "unlimited-approval" | "sign-in-malformed" | "sign-in-domain-mismatch" | "sign-in-port-mismatch" | "sign-in-address-mismatch" | "sign-in-expired" | "sign-in-not-yet-valid" | "permit-approval" | "permit-unlimited" | "permit-long-lived" | "order-receives-nothing" | "order-offerer-mismatch" | "safe-delegatecall" | "safe-gas-refund" | "bitcoin-sighash-single" | "bitcoin-inscription-input" | "bitcoin-frozen-input" | "bitcoin-unusual-output" | "bitcoin-unconfirmed-output" | "stake-authority" | "blind-signing" | "contract-recipient" | "token-contract-recipient" | "token-recipient-empty" | "fee-limit-below-estimate" | "verify-mismatch" | "verify-threat" | "fiat24-internal-account" | "fiat24-card-pull" | "fiat24-unlimited-approval" | "fiat24-exact-out-unbounded" | "fiat24-payee-offchain" | "fiat24-account-move" | "fiat24-account-burn" | "qr-sign-in-unverified";
1109
+ readonly level: "warning" | "danger";
1110
+ };
629
1111
  type AcrossBridgeQuote = {
630
1112
  readonly provider: "across";
631
1113
  readonly inputToken: string;
@@ -710,13 +1192,25 @@ type JupiterSwapQuote = {
710
1192
  readonly lookupTables: ReadonlyArray<string>;
711
1193
  readonly fetchedAt: number;
712
1194
  };
713
- type ChainApis = ReturnType<typeof chains>;
1195
+ type ChainApis = Omit<ReturnType<typeof chains>, "sign"> & {
1196
+ readonly sign: (params: Parameters<ChainsApi["sign"]>[0] & {
1197
+ readonly acknowledgeUnconfirmed?: true;
1198
+ }) => ReturnType<ChainsApi["sign"]>;
1199
+ };
714
1200
  type SignParams = Parameters<ChainApis["sign"]>[0];
1201
+ type SignResult = Awaited<ReturnType<ChainApis["sign"]>>;
715
1202
  type AccountRef = Exclude<SignParams["request"], {
716
1203
  kind: "bitcoin.psbt";
717
1204
  }>["account"];
718
- type DisplayIntent = ReturnType<typeof decodeEvm>;
1205
+ type DisplayIntent$1 = ReturnType<typeof decodeEvm>;
719
1206
  type TxState = "draft" | "signed" | "submitted" | "pending" | "confirmed" | "failed" | "rejected" | "dropped" | "replaced";
1207
+ /** Where an on-chain transaction sits, as its tracker last saw it. */
1208
+ type TxBlock = {
1209
+ /** Block hash; absent on Solana, whose status answer names only the slot. */
1210
+ readonly hash?: string;
1211
+ /** Block number (EVM), height (Bitcoin) or slot (Solana). */
1212
+ readonly height: number;
1213
+ };
720
1214
  /** A bitcoin transaction that funds the wallet's own Spark account; it is claimed once confirmed. */
721
1215
  type SparkDepositTag = {
722
1216
  readonly walletId: string;
@@ -726,27 +1220,75 @@ type SparkDepositTag = {
726
1220
  };
727
1221
  type TrackedTransaction = {
728
1222
  readonly id: string;
729
- readonly family: "evm" | "solana" | "bitcoin";
1223
+ readonly family: "evm" | "solana" | "bitcoin" | "tron";
730
1224
  readonly network: string;
731
1225
  /** The signer's identity label — `walletId` for HD accounts, `keyId` for imported keys. */
732
1226
  readonly account: string;
733
1227
  readonly hash: string | undefined;
734
1228
  readonly state: TxState;
735
- readonly intent: DisplayIntent | undefined;
1229
+ readonly intent: DisplayIntent$1 | undefined;
736
1230
  readonly nonce: number;
1231
+ /**
1232
+ * The block a `confirmed` or on-chain `failed` transaction is in; cleared when a reorg returns it
1233
+ * to `submitted`.
1234
+ */
1235
+ readonly block?: TxBlock | undefined;
1236
+ /**
1237
+ * Past the network's finality rule (EVM `finalized` tag, 6 Bitcoin confirmations, Solana
1238
+ * `finalized`): never changes again, no longer polled.
1239
+ */
1240
+ readonly final?: boolean | undefined;
737
1241
  /** Solana only — the blockhash expiry that turns an unconfirmed tx `dropped`. */
738
1242
  readonly lastValidBlockHeight?: number;
1243
+ /**
1244
+ * Solana only — a durable-nonce transaction has no block-height expiry: `account` is the nonce
1245
+ * account and `value` the nonce its first instruction advances, read back on each poll. `account`
1246
+ * is undefined when the message loads it from a lookup table: nothing to read on it, so the
1247
+ * transaction is never dropped — only resolved by landing.
1248
+ */
1249
+ readonly durableNonce?: {
1250
+ readonly account: string | undefined;
1251
+ readonly value: string;
1252
+ };
1253
+ /**
1254
+ * TRON build record — `raw_data.expiration` bounds drop proofs (past it the network can never
1255
+ * include the transaction); `from` is the sender, for group membership like `evm.from`.
1256
+ * `dappSignature` is set on a dApp-observed entry: the wallet-signed signature (lowercase hex)
1257
+ * `submitDappTron` later matches against the bytes the dApp broadcasts.
1258
+ */
1259
+ readonly tron?: {
1260
+ readonly expiration: number;
1261
+ readonly from: string;
1262
+ readonly dappSignature?: string;
1263
+ };
739
1264
  /** EVM replacement — the earlier transaction this one bumps or cancels. */
740
1265
  readonly replaces?: string;
741
1266
  /** CPFP — the unconfirmed parent this child pushes. */
742
1267
  readonly parentId?: string;
743
1268
  /** Set on a Spark deposit; `claimed` flips once the deposit is credited on Spark. */
744
1269
  readonly sparkDeposit?: SparkDepositTag;
745
- /** EVM build record persisted at broadcast for rebroadcast, drop detection and replacement. */
1270
+ /**
1271
+ * Absent: the tracker may rebroadcast the persisted bytes while the network does not know them.
1272
+ * `false`: recovered from a broadcast whose outcome never settled — it may have been refused — so
1273
+ * the bytes are watched but never resent; a speed-up or cancel is the remedy.
1274
+ */
1275
+ readonly rebroadcast?: false;
1276
+ /**
1277
+ * EVM and Bitcoin: neither endpoint has known this transaction for `STUCK_AFTER_MS`. It stays
1278
+ * `submitted`, still holds its nonce or inputs and is polled at the finality interval; offer
1279
+ * speed-up or cancel.
1280
+ */
1281
+ readonly stuck?: boolean | undefined;
1282
+ /**
1283
+ * The signed transaction exactly as broadcast — EVM and Bitcoin hex, Solana base64 wire —
1284
+ * persisted with `hash` before it leaves, so an unknown outcome is rebroadcast, even after a
1285
+ * restart. Cleared when the node refuses it.
1286
+ */
1287
+ readonly raw?: string | undefined;
1288
+ /** EVM build record persisted with `raw`, for drop detection and replacement. */
746
1289
  readonly evm?: {
747
1290
  readonly from: string;
748
1291
  readonly account: AccountRef;
749
- readonly raw: string;
750
1292
  };
751
1293
  /** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
752
1294
  readonly btc?: {
@@ -764,6 +1306,10 @@ type TrackedTransaction = {
764
1306
  readonly vsize: number;
765
1307
  readonly fee: number;
766
1308
  readonly feeRate: number;
1309
+ /** The account shape the transaction was built from — needed to rebuild it after a restart. */
1310
+ readonly template: BitcoinAccountTemplate;
1311
+ readonly groupIndex: number;
1312
+ readonly tier: "fast" | "normal" | "slow";
767
1313
  };
768
1314
  readonly submittedAt: number;
769
1315
  readonly error: string | undefined;
@@ -778,13 +1324,38 @@ type SendParams = {
778
1324
  readonly fee: EvmFeeTier | SolanaFeeTier;
779
1325
  /** SPL mint decimals — required when `token` is a Solana mint. */
780
1326
  readonly decimals?: number;
1327
+ /**
1328
+ * Bitcoin only — the exact outpoints (`txid:vout`) this send spends; omit for automatic
1329
+ * selection. Naming an inscription-protected output opts into spending it.
1330
+ */
1331
+ readonly inputs?: ReadonlyArray<string>;
1332
+ /** TRON only — the `raw_data.data` memo; refused on every other family. */
1333
+ readonly memo?: string;
781
1334
  readonly verify: SignParams["verify"];
782
1335
  };
783
1336
  type PrepareParams = Omit<SendParams, "verify">;
784
- type ChainRequestMethod = "send" | "speed-up" | "cancel" | "cpfp" | "evm-delegation" | "evm-batch" | "evm-approve" | "evm-swap" | "evm-bridge" | "evm-nft-send" | "solana-core-send" | "evm-lido" | "solana-stake" | "solana-swap";
1337
+ /** One standing EVM approval to remove. */
1338
+ type EvmRevokeTarget = {
1339
+ readonly kind: "erc20";
1340
+ readonly token: string;
1341
+ readonly spender: string;
1342
+ } | {
1343
+ readonly kind: "permit2";
1344
+ readonly token: string;
1345
+ readonly spender: string;
1346
+ } | {
1347
+ readonly kind: "operator";
1348
+ readonly contract: string;
1349
+ readonly operator: string;
1350
+ } | {
1351
+ readonly kind: "nft";
1352
+ readonly contract: string;
1353
+ readonly tokenId: bigint;
1354
+ };
785
1355
  /** What a request asks for; replacements and CPFP name the original transaction. */
786
1356
  type ChainRequestInput = ({
787
1357
  readonly method: "send";
1358
+ readonly origin?: DappOrigin;
788
1359
  } & PrepareParams) | {
789
1360
  readonly method: "speed-up" | "cancel";
790
1361
  readonly txId: string;
@@ -809,10 +1380,7 @@ type ChainRequestInput = ({
809
1380
  }>;
810
1381
  readonly fee: PrepareParams["fee"];
811
1382
  /** A page asking for the batch (`wallet_sendCalls`); absent means the wallet itself. */
812
- readonly origin?: {
813
- readonly kind: "browser";
814
- readonly origin: string;
815
- };
1383
+ readonly origin?: DappOrigin;
816
1384
  } | {
817
1385
  readonly method: "evm-approve";
818
1386
  readonly account: AccountRef;
@@ -821,6 +1389,26 @@ type ChainRequestInput = ({
821
1389
  readonly spender: string;
822
1390
  readonly amount: bigint;
823
1391
  readonly fee: PrepareParams["fee"];
1392
+ } | {
1393
+ readonly method: "evm-revoke";
1394
+ readonly account: AccountRef;
1395
+ readonly network: string;
1396
+ /**
1397
+ * 1..EVM_BATCH_LIMIT distinct targets; more than one needs the account delegated to the
1398
+ * wallet's delegator.
1399
+ */
1400
+ readonly targets: ReadonlyArray<EvmRevokeTarget>;
1401
+ readonly fee: PrepareParams["fee"];
1402
+ } | {
1403
+ /** The Hyperliquid CCTP deposit — `depositForBurnWithHook` on the route's messenger. */
1404
+ readonly method: "evm-cctp";
1405
+ readonly account: AccountRef;
1406
+ readonly network: string;
1407
+ readonly amount: bigint;
1408
+ readonly dex: "perps" | "spot";
1409
+ /** The Circle forward fee bound — strictly below `amount`. */
1410
+ readonly maxFee: bigint;
1411
+ readonly fee: PrepareParams["fee"];
824
1412
  } | {
825
1413
  readonly method: "evm-swap";
826
1414
  readonly account: AccountRef;
@@ -839,16 +1427,18 @@ type ChainRequestInput = ({
839
1427
  readonly network: string;
840
1428
  /** The ERC-721 or ERC-1155 contract. */
841
1429
  readonly contract: string;
842
- readonly tokenId: bigint;
1430
+ /** The ids sent — one for ERC-721, up to `EVM_BATCH_LIMIT` for ERC-1155. */
1431
+ readonly items: ReadonlyArray<{
1432
+ readonly tokenId: bigint;
1433
+ readonly amount?: bigint;
1434
+ }>;
843
1435
  readonly to: string;
844
- /** ERC-1155 only — the units sent; ERC-721 ignores it. */
845
- readonly amount?: bigint;
846
1436
  readonly fee: PrepareParams["fee"];
847
1437
  } | {
848
- readonly method: "solana-core-send";
1438
+ readonly method: "solana-nft-send";
849
1439
  readonly account: AccountRef;
850
1440
  readonly network: string;
851
- /** The Core asset account. */
1441
+ /** The SPL mint or Core asset account. */
852
1442
  readonly asset: string;
853
1443
  readonly to: string;
854
1444
  readonly fee: PrepareParams["fee"];
@@ -873,6 +1463,13 @@ type ChainRequestInput = ({
873
1463
  readonly requestIds: ReadonlyArray<bigint>;
874
1464
  };
875
1465
  readonly fee: PrepareParams["fee"];
1466
+ } | {
1467
+ readonly method: "solana-revoke";
1468
+ readonly account: AccountRef;
1469
+ readonly network: string;
1470
+ /** 1..10 distinct token accounts the signer owns whose delegate is removed — one Revoke each. */
1471
+ readonly tokenAccounts: ReadonlyArray<string>;
1472
+ readonly fee: PrepareParams["fee"];
876
1473
  } | {
877
1474
  readonly method: "solana-stake";
878
1475
  readonly account: AccountRef;
@@ -890,6 +1487,47 @@ type ChainRequestInput = ({
890
1487
  readonly lamports: bigint;
891
1488
  };
892
1489
  readonly fee: PrepareParams["fee"];
1490
+ } | {
1491
+ readonly method: "tron-stake";
1492
+ readonly account: AccountRef;
1493
+ readonly network: string;
1494
+ readonly action: {
1495
+ readonly kind: "freeze" | "unfreeze";
1496
+ readonly amount: bigint;
1497
+ readonly resource: "bandwidth" | "energy";
1498
+ } | {
1499
+ readonly kind: "withdraw-expired";
1500
+ } | {
1501
+ readonly kind: "cancel-unfreeze";
1502
+ } | {
1503
+ readonly kind: "delegate";
1504
+ readonly receiver: string;
1505
+ readonly amount: bigint;
1506
+ readonly resource: "bandwidth" | "energy";
1507
+ /** Lock the delegation for this many blocks (1..getMaxDelegateLockPeriod). */
1508
+ readonly lockBlocks?: number;
1509
+ } | {
1510
+ readonly kind: "undelegate";
1511
+ readonly receiver: string;
1512
+ readonly amount: bigint;
1513
+ readonly resource: "bandwidth" | "energy";
1514
+ } | {
1515
+ readonly kind: "vote";
1516
+ readonly votes: ReadonlyArray<{
1517
+ readonly witness: string;
1518
+ readonly count: bigint;
1519
+ }>;
1520
+ } | {
1521
+ readonly kind: "claim-rewards";
1522
+ };
1523
+ } | {
1524
+ readonly method: "tron-approve";
1525
+ readonly account: AccountRef;
1526
+ readonly network: string;
1527
+ readonly token: string;
1528
+ readonly spender: string;
1529
+ /** The new allowance in token units; 0 revokes. */
1530
+ readonly amount: bigint;
893
1531
  };
894
1532
  /**
895
1533
  * One `wallet_sendCalls` bundle: the tracked transactions it produced so `wallet_getCallsStatus`
@@ -921,40 +1559,71 @@ type PreparedRequest = {
921
1559
  readonly network: string;
922
1560
  /** The transaction being replaced or accelerated; absent for a plain send. */
923
1561
  readonly target?: string;
924
- readonly intent: DisplayIntent;
1562
+ readonly intent: DisplayIntent$1;
1563
+ /** The address the route resolved for `account` — what recipient risk calls self. */
1564
+ readonly signer?: string;
925
1565
  readonly checks: ReadonlyArray<RequestCheckCode>;
1566
+ /** Findings a route can only see on-chain (contract recipient, empty token balance). */
1567
+ readonly risk?: ReadonlyArray<RiskFinding>;
1568
+ /** The TRON fee quote — the intent's fee field carries only `fee_limit`. */
1569
+ readonly tronFee?: TronFeeQuote;
926
1570
  /** Absent when the request is not simulated (replacements, Bitcoin). */
927
1571
  readonly simulation?: SimulationOutcome;
928
1572
  /** Re-runs the same simulated call at approval; absent when there is nothing to re-run. */
929
1573
  readonly resimulate?: () => Promise<SimulationOutcome>;
930
1574
  /** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
931
1575
  readonly staleReason: () => string | undefined | Promise<string | undefined>;
932
- /** Signs, finalizes, broadcasts and hands the transaction to tracking. */
933
- readonly submit: (verify: SendParams["verify"]) => Promise<TrackedTransaction>;
1576
+ /**
1577
+ * Signs, finalizes, broadcasts and hands the transaction to tracking. `commit` must run
1578
+ * immediately (no await in between) before the network send; a throw there means nothing may be
1579
+ * sent.
1580
+ */
1581
+ readonly submit: (verify: SendParams["verify"], commit: () => void) => Promise<TrackedTransaction>;
934
1582
  /** Frees what `prepare` reserved; safe to call more than once. */
935
1583
  readonly release: () => void;
936
1584
  };
937
1585
  type SignatureResult = {
938
- readonly kind: "evm.personal-message" | "evm.typed-data";
1586
+ readonly kind: "evm.personal-message" | "evm.fiat24-session" | "evm.typed-data" | "tron.message" | "tron.typed-data";
1587
+ readonly signature: Uint8Array;
1588
+ };
1589
+ /** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
1590
+ type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
1591
+ /** The address that will sign. */
1592
+ readonly signer: string;
1593
+ readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
1594
+ };
1595
+ /** A transaction signed for a counterpart that broadcasts it itself — nothing is tracked or sent. */
1596
+ type SignedTransactionResult = {
1597
+ readonly kind: "evm.signed-transaction";
1598
+ readonly signedTransaction: Uint8Array;
1599
+ } | {
1600
+ readonly kind: "tron.signed-transaction";
939
1601
  readonly signature: Uint8Array;
940
1602
  };
941
- /** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
942
- type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
1603
+ /**
1604
+ * A prepared QR transaction signature: all of `PreparedRequest`'s checks without its tracking —
1605
+ * `submit` signs the request's own bytes, `commit()`s before returning, and hands back the signed
1606
+ * material for the counterpart to broadcast.
1607
+ */
1608
+ type PreparedQrSign = Omit<PreparedRequest, "submit" | "txId"> & {
943
1609
  /** The address that will sign. */
944
1610
  readonly signer: string;
945
- readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
1611
+ readonly submit: (verify: SendParams["verify"], commit: () => void) => Promise<SignedTransactionResult>;
946
1612
  };
947
- type Options$2 = {
1613
+ type Options = {
948
1614
  readonly wallet: Wallet;
949
1615
  readonly networks: NetworkController;
1616
+ /** The session EngineStore — the engine opens it once per unlock and closes it on lock. */
950
1617
  readonly openStore: () => Promise<EngineStore>;
951
1618
  readonly random: (n: number) => Uint8Array;
952
1619
  readonly setTimer: (ms: number, fn: () => unknown) => () => void;
953
1620
  readonly now: () => number;
954
1621
  readonly logger: EngineLogger;
955
1622
  readonly pollMs?: number;
956
- /** Test seam — defaults to the wallet's real chains proxy. */
957
- readonly chains?: ReturnType<typeof chains>;
1623
+ /** The engine's signing path — `signers.apis`: custody dispatch lives in the signers module. */
1624
+ readonly chains: ReturnType<typeof chains>;
1625
+ /** A card wallet still waiting on a member card holds no groups — its addresses do not exist. */
1626
+ readonly isWalletIncomplete?: (walletId: string) => boolean;
958
1627
  };
959
1628
  type TransactionControllerState = {
960
1629
  readonly txs: Record<string, TrackedTransaction>;
@@ -966,8 +1635,24 @@ declare class TransactionController extends Controller<TransactionControllerStat
966
1635
  private evmRoute;
967
1636
  private bitcoinRoute;
968
1637
  private locked;
1638
+ /**
1639
+ * Bumped on every `lock`: a `RouteContext` captures it at creation, so an async result that
1640
+ * outlives its session — a broadcast settling after lock→unlock — is recognized as stale and
1641
+ * never writes into the new session's state or store, and never touches its timers.
1642
+ */
1643
+ private generation;
969
1644
  private readonly batches;
970
- constructor(options: Options$2);
1645
+ /**
1646
+ * The latest row whose bookkeeping write has not reached the store — set by a locked vault or a
1647
+ * failed write, replayed at `init` and by the flush loop. Locking keeps it: these rows describe
1648
+ * bytes that may already be out, so losing one means losing a refusal.
1649
+ */
1650
+ private readonly unsaved;
1651
+ /** The running flush loop while `unsaved` is non-empty and the vault is unlocked. */
1652
+ private unsavedFlush;
1653
+ /** In-flight drop/reorg corroboration — poll streaks die with the session. */
1654
+ private dropEvidence;
1655
+ constructor(options: Options);
971
1656
  init(): Promise<void>;
972
1657
  destroy(): Promise<void>;
973
1658
  /** One `wallet_sendCalls` bundle the user approved; retained alongside the transactions it lists. */
@@ -979,6 +1664,11 @@ declare class TransactionController extends Controller<TransactionControllerStat
979
1664
  lock(): void;
980
1665
  private persist;
981
1666
  private transition;
1667
+ /** Arms the bookkeeping retry while the vault is unlocked and a row still needs the store. */
1668
+ private armUnsavedFlush;
1669
+ private stopUnsavedFlush;
1670
+ /** Writes every parked row; a row that lands leaves `unsaved`, an empty `unsaved` stops the loop. */
1671
+ private flushUnsaved;
982
1672
  private routeCtx;
983
1673
  /**
984
1674
  * Internal entry for the request pipeline: builds, estimates and cross-checks a send without
@@ -987,7 +1677,41 @@ declare class TransactionController extends Controller<TransactionControllerStat
987
1677
  */
988
1678
  prepareSend(params: PrepareParams, requestId: string, sparkDeposit?: SparkDepositTag): Promise<PreparedRequest>;
989
1679
  /** The group's next unused `btc.bip84` receive address on a bitcoin `network`. */
990
- nextReceiveAddress(walletId: string, groupIndex: number, network: string): Promise<string>;
1680
+ nextReceiveAddress(walletId: string, groupIndex: number, network: string): Promise<{
1681
+ address: string;
1682
+ confirmed: boolean;
1683
+ }>;
1684
+ /**
1685
+ * Freeze or unfreeze bitcoin outpoints (`txid:vout`) for one account on one `network`. Freezing
1686
+ * is intent, not utxo state — the outpoint need not be unspent — and it never lifts the derived
1687
+ * inscription protection.
1688
+ */
1689
+ setUtxosFrozen(account: {
1690
+ readonly walletId: string;
1691
+ readonly groupIndex: number;
1692
+ }, network: string, outpoints: ReadonlyArray<string>, frozen: boolean): Promise<void>;
1693
+ /** The outpoints the account froze on `network`. */
1694
+ frozenUtxos(account: {
1695
+ readonly walletId: string;
1696
+ readonly groupIndex: number;
1697
+ }, network: string): ReadonlyArray<string>;
1698
+ /**
1699
+ * Internal entry for the dApp `signTransaction` send path: a dApp-built transaction has no build
1700
+ * record; it joins tracking under its signed bytes like a wallet send.
1701
+ */
1702
+ submitDappBitcoin(network: string, walletId: string, prepared: PreparedBitcoinPsbt, result: SignResult): Promise<string>;
1703
+ /**
1704
+ * Internal entry for the dApp `signAndSendTransaction` path: a dApp-built transaction has no
1705
+ * build record; it joins tracking under its signed bytes like a wallet send.
1706
+ */
1707
+ submitDappSolana(network: string, walletId: string, wire: Uint8Array, lastValidBlockHeight: bigint, intent: DisplayIntent$1): Promise<string>;
1708
+ /**
1709
+ * Internal entry for the dApp `solana-sign` path: proves every message's lifetime — recent
1710
+ * blockhash or durable nonce — belongs to the session's cluster before anything is prompted or
1711
+ * signed. Throws `SolanaClusterBindingError` on an unbound message; the returned checks join the
1712
+ * request's when a mainnet build could only be gateway-bound.
1713
+ */
1714
+ bindDappSolana(network: string, messages: ReadonlyArray<Uint8Array>): Promise<ReadonlyArray<RequestCheckCode>>;
991
1715
  /** Records that a Spark deposit was credited; persisted with the transaction. */
992
1716
  markDepositClaimed(id: string): Promise<void>;
993
1717
  /**
@@ -995,7 +1719,28 @@ declare class TransactionController extends Controller<TransactionControllerStat
995
1719
  * transaction is rebuilt with fresh nonce and fees (the dApp's own are discarded), and a message
996
1720
  * is decoded and signed as is.
997
1721
  */
998
- prepareDapp(account: AccountRef, request: SignRequest): Promise<PreparedRequest | PreparedMessage>;
1722
+ prepareDapp(account: AccountRef, request: SignRequest, options?: {
1723
+ readonly nonce?: number;
1724
+ }): Promise<PreparedRequest | PreparedMessage>;
1725
+ /**
1726
+ * Internal entry for a scanned QR EVM transaction: normalized with the same rules, but the
1727
+ * request's own nonce and fees are signed unchanged — a QR counterpart broadcasts the signed
1728
+ * envelope itself, so nothing is tracked or sent here.
1729
+ */
1730
+ prepareQrEvm(account: AccountRef, request: SignRequest): Promise<PreparedQrSign>;
1731
+ /**
1732
+ * Internal entry for a dApp's TRON request: the transaction bytes are validated, proven fresh and
1733
+ * quoted but never re-encoded — the kernel signs exactly the bytes the dApp sent. Messages and
1734
+ * typed data decode and sign like the EVM path.
1735
+ */
1736
+ prepareDappTron(account: AccountRef, request: SignRequest, options?: {
1737
+ readonly broadcast: false;
1738
+ }): Promise<PreparedRequest | PreparedMessage | PreparedQrSign>;
1739
+ /**
1740
+ * Internal entry for the dApp broadcast path (`wallet/sign` then the dApp sends the signed
1741
+ * transaction back): pairs the signature with the observed entry and broadcasts — once.
1742
+ */
1743
+ submitDappTron(network: string, rawData: Uint8Array, signature: Uint8Array): Promise<TrackedTransaction>;
999
1744
  /**
1000
1745
  * Internal entry for replacements and CPFP: builds, cross-checks and reserves what the
1001
1746
  * replacement needs without signing it. The original must be `submitted` or `pending`.
@@ -1008,7 +1753,7 @@ declare class TransactionController extends Controller<TransactionControllerStat
1008
1753
  * builds, estimates and cross-checks the self-transaction without signing it.
1009
1754
  */
1010
1755
  prepareEvmInternal(input: Extract<ChainRequestInput, {
1011
- method: "evm-delegation" | "evm-batch" | "evm-approve" | "evm-swap" | "evm-bridge" | "evm-nft-send" | "evm-lido";
1756
+ method: "evm-delegation" | "evm-batch" | "evm-approve" | "evm-revoke" | "evm-cctp" | "evm-swap" | "evm-bridge" | "evm-nft-send" | "evm-lido";
1012
1757
  }>, _requestId: string): Promise<PreparedRequest>;
1013
1758
  /**
1014
1759
  * Internal `solana-stake` requests: checks the delegation rules, then builds the stake
@@ -1017,85 +1762,60 @@ declare class TransactionController extends Controller<TransactionControllerStat
1017
1762
  prepareSolanaStake(input: Extract<ChainRequestInput, {
1018
1763
  method: "solana-stake";
1019
1764
  }>, _requestId: string): Promise<PreparedRequest>;
1765
+ /**
1766
+ * Internal `solana-revoke` requests: every token account is re-read on both endpoints before a
1767
+ * program-matched `Revoke` goes through the same fee/simulation tail as a send.
1768
+ */
1769
+ prepareSolanaRevoke(input: Extract<ChainRequestInput, {
1770
+ method: "solana-revoke";
1771
+ }>, _requestId: string): Promise<PreparedRequest>;
1772
+ /**
1773
+ * Internal `tron-stake` requests: the java-tron actuator rules are checked against node reads,
1774
+ * then the operation goes through the same build/sign/track tail as a send.
1775
+ */
1776
+ prepareTronStake(input: Extract<ChainRequestInput, {
1777
+ method: "tron-stake";
1778
+ }>, _requestId: string): Promise<PreparedRequest>;
1779
+ /** Internal `tron-approve` requests: TRC-20 `approve` (amount 0 revokes). */
1780
+ prepareTronApprove(input: Extract<ChainRequestInput, {
1781
+ method: "tron-approve";
1782
+ }>, _requestId: string): Promise<PreparedRequest>;
1020
1783
  prepareSolanaSwap(input: Extract<ChainRequestInput, {
1021
1784
  method: "solana-swap";
1022
1785
  }>, _requestId: string): Promise<PreparedRequest>;
1023
- prepareSolanaCoreSend(input: Extract<ChainRequestInput, {
1024
- method: "solana-core-send";
1786
+ prepareSolanaNftSend(input: Extract<ChainRequestInput, {
1787
+ method: "solana-nft-send";
1025
1788
  }>, _requestId: string): Promise<PreparedRequest>;
1026
1789
  /** The account's 7702 delegation state on `network` (primary endpoint only). */
1027
1790
  delegationState(account: AccountRef, network: string): Promise<DelegationStatus>;
1791
+ /**
1792
+ * The address `account` resolves to on `network` — HD through the chains proxy, imported from the
1793
+ * vault's key list; the ref's family must match the network's.
1794
+ */
1795
+ addressOf(account: AccountRef, network: string): Promise<string>;
1028
1796
  private track;
1797
+ /**
1798
+ * Re-arms a transaction's loop — at the finality interval once included, back to `pollMs` after a
1799
+ * reorg.
1800
+ */
1801
+ private retrack;
1802
+ private untrack;
1803
+ /**
1804
+ * One status poll. `included` keeps a non-final row tracked at the finality interval; `reorged`
1805
+ * clears the block and returns the row to the pool as `submitted`; `ended` stops the loop. An
1806
+ * answer describes the snapshot the poll started from — a concurrent transition (a sibling
1807
+ * marking this replaced, a reload) means the row moved on and the next poll decides.
1808
+ */
1809
+ private pollOnce;
1810
+ /** When one of a replace pair is included, its live siblings are `replaced`. */
1811
+ private markReplacedSiblings;
1812
+ /** A reorged transaction revives `replaced` siblings: each is `submitted` and polled again. */
1813
+ private reviveSiblings;
1814
+ /** A reorged transaction re-anchors what it consumed — EVM nonces, Bitcoin inputs. */
1815
+ private reopen;
1816
+ /** A transaction that settled frees what it locked, whichever way it settled. */
1817
+ private settle;
1029
1818
  }
1030
- /**
1031
- * Request risk, pure. A recipient the wallet has never paid or saved is a `warning`; one that looks
1032
- * like a known address (same first and last four characters, different address) is a `danger` — the
1033
- * shape of an address-poisoning lookalike. Both can apply to one recipient. A page the user trusts
1034
- * despite the phishing list is a `danger`; one that could not be checked is a `warning`.
1035
- */
1036
- type RiskFinding = {
1037
- readonly code: "first-recipient" | "address-poisoning" | "phishing-origin" | "phishing-unchecked" | "token-impersonation" | "token-symbol-unicode" | "simulation-reverted" | "simulation-mismatch" | "collection-approval" | "unlimited-approval" | "sign-in-malformed" | "sign-in-domain-mismatch" | "sign-in-port-mismatch" | "sign-in-address-mismatch" | "sign-in-expired" | "sign-in-not-yet-valid" | "permit-approval" | "permit-unlimited" | "permit-long-lived" | "order-receives-nothing" | "order-offerer-mismatch" | "safe-delegatecall" | "safe-gas-refund" | "bitcoin-sighash-single" | "bitcoin-inscription-input" | "stake-authority" | "blind-signing";
1038
- readonly level: "warning" | "danger";
1039
- };
1040
- /** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
1041
- type BrowserOrigin = {
1042
- readonly kind: "browser";
1043
- readonly origin: string;
1044
- };
1045
- type RequestOrigin = {
1046
- readonly kind: "internal";
1047
- } | BrowserOrigin;
1048
- type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "evm-delegation" | "evm-batch" | "nostr-sign" | "webln-invoice" | "watch-asset" | "solana-sign" | "bitcoin-sign" | "spark-deposit" | "spark-exit";
1049
- /** A Solana chain account the `solana-sign` request signs for. */
1050
- type SolanaAccount = {
1051
- readonly walletId: string;
1052
- readonly groupIndex: number;
1053
- readonly address: string;
1054
- };
1055
- /** A Bitcoin account the `bitcoin-sign` request signs for: the group's fixed dApp-facing address. */
1056
- type BitcoinAccount = {
1057
- readonly walletId: string;
1058
- readonly groupIndex: number;
1059
- readonly address: string;
1060
- /** `btc.bip84` for the `payment` purpose, `btc.bip86` for `ordinals`. */
1061
- readonly template: "btc.bip84" | "btc.bip86";
1062
- };
1063
- /**
1064
- * The wallet group a `bitcoin-sign` PSBT request signs for: inputs of several dApp-facing templates
1065
- * of the same group may mix in one PSBT — each sign entry names its own template.
1066
- */
1067
- type BitcoinGroup = {
1068
- readonly walletId: string;
1069
- readonly groupIndex: number;
1070
- };
1071
- /** The sighash a dApp asks for per input; anything else is refused before it reaches a request. */
1072
- type BitcoinSigHash = "ALL" | "SINGLE|ANYONECANPAY";
1073
- /** One dApp PSBT and the inputs it asks the wallet to sign. */
1074
- type BitcoinPsbtInput = {
1075
- readonly psbt: Uint8Array;
1076
- readonly sign: ReadonlyArray<{
1077
- readonly index: number;
1078
- readonly sigHash: BitcoinSigHash;
1079
- readonly template: BitcoinAccount["template"];
1080
- }>;
1081
- };
1082
- /**
1083
- * A dApp PSBT after the engine enriched the requested inputs with this account's derivation data:
1084
- * `request` is what the kernel signs, `ownScripts` the scripts verified as the account's, `inputs`
1085
- * the signed inputs' prevout values and sighash (for risk).
1086
- */
1087
- type PreparedBitcoinPsbt = {
1088
- readonly request: Extract<SignRequest, {
1089
- kind: "bitcoin.psbt";
1090
- }>;
1091
- readonly ownScripts: ReadonlySet<string>;
1092
- readonly inputs: ReadonlyArray<{
1093
- readonly index: number;
1094
- readonly value: number;
1095
- readonly sigHash: BitcoinSigHash;
1096
- readonly template: BitcoinAccount["template"];
1097
- }>;
1098
- };
1099
1819
  type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
1100
1820
  type SignLogEntry = {
1101
1821
  readonly id: string;
@@ -1111,10 +1831,15 @@ type SignLogEntry = {
1111
1831
  readonly outcome: SignLogOutcome;
1112
1832
  readonly error?: string;
1113
1833
  };
1834
+ /**
1835
+ * `signed` is the point of no return: the signature exists and is being returned or broadcast, so
1836
+ * invalidation no longer applies.
1837
+ */
1838
+ type RequestStage = "awaiting-approval" | "signing" | "signed" | "submitted" | "rejected" | "failed" | "expired" | "invalidated";
1114
1839
  /** A Spark, Lightning (including LNURL-pay and lightning addresses) or cooperative-exit payment. */
1115
1840
  type PayInput = {
1116
1841
  readonly method: "pay";
1117
- readonly origin?: BrowserOrigin;
1842
+ readonly origin?: DappOrigin;
1118
1843
  } & PayParams;
1119
1844
  /** A prepared zap; its invoice was fetched by `engine.zaps.prepare` and is paid as-is. */
1120
1845
  type ZapInput = {
@@ -1129,7 +1854,27 @@ type ZapInput = {
1129
1854
  */
1130
1855
  type EvmSignInput = {
1131
1856
  readonly method: "evm-sign";
1132
- readonly origin: BrowserOrigin;
1857
+ /** A page asking for the signature; a QR request carries a QrOrigin; absent means the wallet. */
1858
+ readonly origin?: DappOrigin | QrOrigin;
1859
+ readonly account: AccountRef;
1860
+ readonly network: string;
1861
+ readonly request: SignRequest;
1862
+ /**
1863
+ * App requests with an `evm.transaction` only: the nonce the transaction must carry. `prepare`
1864
+ * refuses with a `NonceConflictError` before anything is shown when the sender's next free nonce
1865
+ * differs, and rejects with a plain validation error when `nonce` is set on any other request
1866
+ * kind, on a request with a dApp or no app origin, or is not a safe non-negative integer.
1867
+ */
1868
+ readonly nonce?: number;
1869
+ };
1870
+ /**
1871
+ * A dApp's TRON request: a transaction whose exact `raw_data` bytes are validated and signed
1872
+ * unchanged, a TIP-191 message or TIP-712 typed data.
1873
+ */
1874
+ type TronSignInput = {
1875
+ readonly method: "tron-sign";
1876
+ /** A page asking for the signature; a QR request carries a QrOrigin; absent means the wallet. */
1877
+ readonly origin?: DappOrigin | QrOrigin;
1133
1878
  readonly account: AccountRef;
1134
1879
  readonly network: string;
1135
1880
  readonly request: SignRequest;
@@ -1160,7 +1905,7 @@ type SparkExitInput = {
1160
1905
  */
1161
1906
  type NostrSignInput = {
1162
1907
  readonly method: "nostr-sign";
1163
- readonly origin: BrowserOrigin;
1908
+ readonly origin: DappOrigin;
1164
1909
  /** The active identity — the signer the page's pubkey must match. */
1165
1910
  readonly ref: NostrKeyRef;
1166
1911
  readonly event: UnsignedEvent;
@@ -1172,7 +1917,7 @@ type NostrSignInput = {
1172
1917
  */
1173
1918
  type WeblnInvoiceInput = {
1174
1919
  readonly method: "webln-invoice";
1175
- readonly origin: BrowserOrigin;
1920
+ readonly origin: DappOrigin;
1176
1921
  readonly ref: SparkAccountRef;
1177
1922
  readonly amountSats: number;
1178
1923
  readonly memo?: string;
@@ -1183,7 +1928,7 @@ type WeblnInvoiceInput = {
1183
1928
  */
1184
1929
  type WatchAssetInput = {
1185
1930
  readonly method: "watch-asset";
1186
- readonly origin: BrowserOrigin;
1931
+ readonly origin: DappOrigin;
1187
1932
  readonly account: AccountRef;
1188
1933
  readonly network: string;
1189
1934
  readonly address: string;
@@ -1194,11 +1939,12 @@ type WatchAssetInput = {
1194
1939
  */
1195
1940
  type SolanaSignInput = {
1196
1941
  readonly method: "solana-sign";
1197
- readonly origin: BrowserOrigin;
1942
+ readonly origin: DappOrigin | QrOrigin;
1198
1943
  readonly account: SolanaAccount;
1199
1944
  readonly network: string;
1200
1945
  readonly request: {
1201
1946
  readonly kind: "transactions";
1947
+ /** Serialized transactions as the Wallet Standard passes them. */
1202
1948
  readonly transactions: ReadonlyArray<Uint8Array>;
1203
1949
  readonly send: boolean;
1204
1950
  } | {
@@ -1214,7 +1960,7 @@ type SolanaSignInput = {
1214
1960
  */
1215
1961
  type BitcoinSignInput = {
1216
1962
  readonly method: "bitcoin-sign";
1217
- readonly origin: BrowserOrigin;
1963
+ readonly origin: DappOrigin;
1218
1964
  readonly account: BitcoinAccount;
1219
1965
  readonly network: string;
1220
1966
  readonly request: {
@@ -1223,7 +1969,7 @@ type BitcoinSignInput = {
1223
1969
  };
1224
1970
  } | {
1225
1971
  readonly method: "bitcoin-sign";
1226
- readonly origin: BrowserOrigin;
1972
+ readonly origin: DappOrigin | QrOrigin;
1227
1973
  readonly account: BitcoinGroup;
1228
1974
  readonly network: string;
1229
1975
  readonly request: {
@@ -1232,7 +1978,7 @@ type BitcoinSignInput = {
1232
1978
  readonly send: boolean;
1233
1979
  };
1234
1980
  };
1235
- type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | BitcoinSignInput | SparkDepositInput | SparkExitInput;
1981
+ type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | TronSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | BitcoinSignInput | SparkDepositInput | SparkExitInput;
1236
1982
  /** `approve` of a `nostr-sign` request: the signed event. */
1237
1983
  type NostrSignResult = {
1238
1984
  readonly kind: "nostr.event";
@@ -1255,7 +2001,7 @@ type SolanaDisplay = {
1255
2001
  readonly kind: "solana.sign";
1256
2002
  readonly send: boolean;
1257
2003
  readonly count: number;
1258
- readonly transactions: ReadonlyArray<unknown>;
2004
+ readonly transactions: ReadonlyArray<DisplayIntent$1>;
1259
2005
  /** A message request's content — text, or raw bytes when it is not UTF-8. */
1260
2006
  readonly message?: MessageContent;
1261
2007
  readonly signIn?: SignInFields;
@@ -1266,6 +2012,12 @@ type SolanaSignResult = {
1266
2012
  readonly send: boolean;
1267
2013
  readonly signatures?: ReadonlyArray<string>;
1268
2014
  readonly signedTransactions?: ReadonlyArray<Uint8Array>;
2015
+ /** Where the batch stopped; `signatures` holds exactly the ids that went out. */
2016
+ readonly stopped?: {
2017
+ readonly index: number;
2018
+ readonly reason: "refused" | "not-sent";
2019
+ readonly error: string;
2020
+ };
1269
2021
  } | {
1270
2022
  readonly kind: "solana.message";
1271
2023
  readonly signature: Uint8Array;
@@ -1274,7 +2026,7 @@ type SolanaSignResult = {
1274
2026
  type BitcoinDisplay = {
1275
2027
  readonly kind: "bitcoin.sign";
1276
2028
  readonly message?: MessageContent;
1277
- readonly psbts?: ReadonlyArray<DisplayIntent>;
2029
+ readonly psbts?: ReadonlyArray<DisplayIntent$1>;
1278
2030
  readonly send?: boolean;
1279
2031
  };
1280
2032
  /**
@@ -1288,6 +2040,12 @@ type BitcoinSignResult = {
1288
2040
  readonly kind: "bitcoin.psbts";
1289
2041
  readonly signedPsbts: ReadonlyArray<Uint8Array>;
1290
2042
  readonly txids: ReadonlyArray<string>;
2043
+ /** Where the batch stopped; `txids` holds exactly the ids that went out. */
2044
+ readonly stopped?: {
2045
+ readonly index: number;
2046
+ readonly reason: "refused" | "not-sent";
2047
+ readonly error: string;
2048
+ };
1291
2049
  };
1292
2050
  /** `approve` of a `watch-asset` request: the token was added. */
1293
2051
  type TokenWatchResult = {
@@ -1308,7 +2066,42 @@ type LightningInvoiceDisplay = {
1308
2066
  readonly amountSats: number;
1309
2067
  readonly memo?: string;
1310
2068
  };
1311
- type RequestStage = "awaiting-approval" | "signing" | "submitted" | "rejected" | "failed" | "expired" | "invalidated";
2069
+ /** `approve` refused a blind request for a vault whose owner has not allowed blind signing. */
2070
+ declare class BlindSigningDisabledError extends Error {
2071
+ constructor();
2072
+ }
2073
+ /**
2074
+ * The approval-time re-simulation differs from the prepared outcome; the request went back to
2075
+ * `awaiting-approval` with the fresh result and stays approvable.
2076
+ */
2077
+ declare class SimulationChangedError extends Error {
2078
+ constructor();
2079
+ }
2080
+ /**
2081
+ * What the user must have confirmed for a request to be approved: its `danger` findings and every
2082
+ * recorded check. The host passes back the codes it showed, so a finding that appeared after the
2083
+ * approval screen was drawn is never confirmed unseen.
2084
+ */
2085
+ type RequestAcknowledgement = {
2086
+ readonly risk: ReadonlyArray<RiskFinding["code"]>;
2087
+ readonly checks: ReadonlyArray<RequestCheckCode>;
2088
+ };
2089
+ type ApproveOptions = {
2090
+ /** The factor for requests that sign with a secret; requests that do not take none. */
2091
+ readonly verify?: SendParams["verify"];
2092
+ /** Required, and exact, whenever {@link requiredAcknowledgement} is not empty. */
2093
+ readonly acknowledged?: RequestAcknowledgement;
2094
+ };
2095
+ /** The acknowledgement `approve` requires for the request as it stands now. */
2096
+ declare const requiredAcknowledgement: (request: Pick<PendingRequest, "risk" | "checks">) => RequestAcknowledgement;
2097
+ /**
2098
+ * `approve` was called without confirming exactly the request's current danger findings and checks.
2099
+ * The request stays `awaiting-approval`; `required` is what to show and pass back.
2100
+ */
2101
+ declare class AcknowledgementRequiredError extends Error {
2102
+ readonly required: RequestAcknowledgement;
2103
+ constructor(required: RequestAcknowledgement);
2104
+ }
1312
2105
  type PendingRequest = {
1313
2106
  readonly id: string;
1314
2107
  readonly origin: RequestOrigin;
@@ -1317,17 +2110,19 @@ type PendingRequest = {
1317
2110
  readonly network: string;
1318
2111
  readonly stage: RequestStage;
1319
2112
  /** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
1320
- readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay | BitcoinDisplay;
1321
- /** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
2113
+ readonly display: DisplayIntent$1 | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay | BitcoinDisplay;
2114
+ /** `unverifiable` as soon as any check is recorded; `approve` requires each to be acknowledged. */
1322
2115
  readonly verification: "verified" | "unverifiable";
1323
2116
  readonly checks: ReadonlyArray<RequestCheckCode>;
1324
2117
  /**
1325
- * Recipient risk; independent of `verification`. A `danger` needs the user's explicit
1326
- * acknowledgement.
2118
+ * Recipient risk; independent of `verification`. `approve` requires each `danger` to be
2119
+ * acknowledged.
1327
2120
  */
1328
2121
  readonly risk: ReadonlyArray<RiskFinding>;
1329
2122
  /** Present for simulated requests: sends and dApp transactions; absent otherwise. */
1330
2123
  readonly simulation?: SimulationOutcome;
2124
+ /** The TRON fee quote a tron send built — bandwidth, activation and energy detail. */
2125
+ readonly tronFee?: TronFeeQuote;
1331
2126
  /** When `simulation` was produced (ms); one older than {@link RESIMULATE_AFTER_MS} re-runs. */
1332
2127
  readonly simulatedAt?: number;
1333
2128
  readonly createdAt: number;
@@ -1346,6 +2141,7 @@ type RequestControllerOptions = {
1346
2141
  /** The full controller: its payment methods are reachable only through this pipeline. */
1347
2142
  readonly spark: SparkController;
1348
2143
  readonly addressBook: AddressBookController;
2144
+ /** The session EngineStore — the engine opens it once per unlock and closes it on lock. */
1349
2145
  readonly openStore: () => Promise<EngineStore>;
1350
2146
  readonly fetch: typeof globalThis.fetch;
1351
2147
  readonly random: (n: number) => Uint8Array;
@@ -1363,8 +2159,11 @@ type RequestControllerOptions = {
1363
2159
  }>;
1364
2160
  readonly add: (network: string, address: string) => Promise<void>;
1365
2161
  };
1366
- /** Whether the account group opted in to signing messages that cannot be shown as text. */
1367
- readonly blindSigning: (walletId: string, groupIndex: number) => boolean;
2162
+ /**
2163
+ * The vault's blind-signing setting (`WalletSnapshot.blindSigning`); `approve` refuses a blind
2164
+ * request while it is off, and the kernel enforces it again.
2165
+ */
2166
+ readonly blindSigning: () => boolean;
1368
2167
  /** Simulates one `solana-sign` transaction for display; failures are the caller's `unavailable`. */
1369
2168
  readonly simulateSolana: (account: SolanaAccount, network: string, message: Uint8Array) => Promise<SimulationOutcome>;
1370
2169
  /** Signs/broadcasts a `solana-sign` request — `chains.sign` per tx, then the Solana adapter. */
@@ -1372,7 +2171,7 @@ type RequestControllerOptions = {
1372
2171
  readonly walletId: string;
1373
2172
  readonly groupIndex: number;
1374
2173
  readonly address: string;
1375
- }, network: string, request: SolanaSignInput["request"], verify: SendParams["verify"]) => Promise<SolanaSignResult>;
2174
+ }, network: string, request: SolanaSignInput["request"], verify: SendParams["verify"], commit: () => void) => Promise<SolanaSignResult>;
1376
2175
  /** Signs a `bitcoin-sign` message — `chains.sign` with the account's template. */
1377
2176
  readonly bitcoinSign: (account: BitcoinAccount, network: string, request: {
1378
2177
  readonly kind: "message";
@@ -1381,14 +2180,14 @@ type RequestControllerOptions = {
1381
2180
  /** Adds the group's derivation data to a dApp's PSBTs; refuses inputs that are not its own. */
1382
2181
  readonly bitcoinPrepare: (account: BitcoinGroup, network: string, psbts: ReadonlyArray<BitcoinPsbtInput>) => Promise<ReadonlyArray<PreparedBitcoinPsbt>>;
1383
2182
  /** Signs (and with `send` broadcasts) the prepared PSBTs. */
1384
- readonly bitcoinSignPsbts: (account: BitcoinGroup, network: string, prepared: ReadonlyArray<PreparedBitcoinPsbt>, send: boolean, verify: SendParams["verify"]) => Promise<BitcoinSignResult>;
2183
+ readonly bitcoinSignPsbts: (account: BitcoinGroup, network: string, prepared: ReadonlyArray<PreparedBitcoinPsbt>, send: boolean, verify: SendParams["verify"], commit: () => void) => Promise<BitcoinSignResult>;
1385
2184
  };
1386
2185
  /** Requests expire this long after creation. */
1387
2186
  declare const REQUEST_TTL_MS: number;
1388
2187
  /** A simulation older than this is re-run at approval before any signing. */
1389
2188
  declare const RESIMULATE_AFTER_MS = 60000;
1390
2189
  /** What an approved request resolves with, whichever kind it is. */
1391
- type RequestResult = TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult | BitcoinSignResult;
2190
+ type RequestResult = TrackedTransaction | SparkResult | SignatureResult | SignedTransactionResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult | BitcoinSignResult;
1392
2191
  declare class RequestController extends Controller<RequestControllerState> {
1393
2192
  private readonly options;
1394
2193
  private readonly entries;
@@ -1396,20 +2195,25 @@ declare class RequestController extends Controller<RequestControllerState> {
1396
2195
  private readonly settlers;
1397
2196
  /** Original transaction id → the unfinished request replacing or accelerating it. */
1398
2197
  private readonly targets;
2198
+ /** Requests still being built, request id → the prepare in flight. */
2199
+ private readonly preparing;
1399
2200
  private locked;
1400
- /** Bumped on every unlock and lock so work that outlives a session never touches the next one. */
1401
- private session;
1402
2201
  constructor(options: RequestControllerOptions);
1403
2202
  init(): Promise<void>;
1404
2203
  destroy(): Promise<void>;
1405
2204
  /** Locking is not consent: every unfinished request becomes `invalidated` and frees its resources. */
1406
2205
  lock(): void;
2206
+ /**
2207
+ * Locking, unlocking and switching account group void every unfinished request (requests.mdx
2208
+ * invariant 1).
2209
+ */
2210
+ invalidateAll(): void;
1407
2211
  /** A page navigated away, was revoked or changed network: its unfinished requests are void. */
1408
2212
  invalidateOrigin(origin: string): void;
1409
2213
  /** The signature record, newest first. */
1410
2214
  signLog(): Promise<ReadonlyArray<SignLogEntry>>;
1411
2215
  clearSignLog(): Promise<void>;
1412
- prepare(input: RequestInput): Promise<PendingRequest>;
2216
+ prepare(input: RequestInput, app?: AppOrigin): Promise<PendingRequest>;
1413
2217
  /**
1414
2218
  * Resolves with what `approve` returned, or rejects with `RequestEndedError` when the request
1415
2219
  * ends any other way — how a dApp's pending call learns the outcome.
@@ -1423,31 +2227,46 @@ declare class RequestController extends Controller<RequestControllerState> {
1423
2227
  private simulateOne;
1424
2228
  private build;
1425
2229
  /**
1426
- * Signs and submits a request. Anything but a live, unexpired `send` request with this id throws
1427
- * before any signing; a stale build (nonce taken, blockhash expired) fails without signing.
2230
+ * Signs and submits a request. Anything but a live, unexpired request of this method throws
2231
+ * before any signing; a stale build (nonce taken, blockhash expired) fails without signing. So
2232
+ * does a request with `danger` findings or checks unless `options.acknowledged` names exactly
2233
+ * those — including the ones a re-simulation at approval adds ({@link requiredAcknowledgement}).
1428
2234
  */
1429
- approve(id: string, method: ChainRequestMethod | "spark-deposit", verify?: SendParams["verify"]): Promise<TrackedTransaction>;
1430
- approve(id: string, method: "pay" | "zap" | "spark-exit", verify?: SendParams["verify"]): Promise<SparkResult>;
1431
- approve(id: string, method: "evm-sign", verify?: SendParams["verify"]): Promise<TrackedTransaction | SignatureResult>;
1432
- approve(id: string, method: "nostr-sign"): Promise<NostrSignResult>;
1433
- approve(id: string, method: "webln-invoice"): Promise<WeblnInvoiceResult>;
1434
- approve(id: string, method: "watch-asset"): Promise<TokenWatchResult>;
1435
- approve(id: string, method: "solana-sign", verify?: SendParams["verify"]): Promise<SolanaSignResult>;
1436
- approve(id: string, method: "bitcoin-sign", verify?: SendParams["verify"]): Promise<BitcoinSignResult>;
2235
+ approve(id: string, method: ChainRequestMethod | "spark-deposit", options?: ApproveOptions): Promise<TrackedTransaction>;
2236
+ approve(id: string, method: "pay" | "zap" | "spark-exit", options?: ApproveOptions): Promise<SparkResult>;
2237
+ approve(id: string, method: "evm-sign" | "tron-sign", options?: ApproveOptions): Promise<TrackedTransaction | SignatureResult | SignedTransactionResult>;
2238
+ approve(id: string, method: "nostr-sign", options?: ApproveOptions): Promise<NostrSignResult>;
2239
+ approve(id: string, method: "webln-invoice", options?: ApproveOptions): Promise<WeblnInvoiceResult>;
2240
+ approve(id: string, method: "watch-asset", options?: ApproveOptions): Promise<TokenWatchResult>;
2241
+ approve(id: string, method: "solana-sign", options?: ApproveOptions): Promise<SolanaSignResult>;
2242
+ approve(id: string, method: "bitcoin-sign", options?: ApproveOptions): Promise<BitcoinSignResult>;
1437
2243
  /**
1438
- * A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
1439
- * requests record which step failed on the tracked transaction; for Spark, the approval round is
1440
- * the only source of `WalletError`.
2244
+ * A cancelled or refused verification is `reject`; anything after it is `fail`. Chain requests
2245
+ * record which step failed on the tracked transaction; for Spark, the approval round is the only
2246
+ * source of `WalletError`.
1441
2247
  */
1442
- private failureStage;
2248
+ private failureEvent;
1443
2249
  reject(id: string): void;
1444
2250
  /** `approve` for a factor-required run: a missing factor is invalid input. */
1445
2251
  private requireVerify;
1446
2252
  private requireRequest;
1447
2253
  private put;
1448
2254
  private unclaim;
1449
- /** Ends a request in a terminal stage and frees what it reserved. */
1450
- private finish;
2255
+ /**
2256
+ * Applies a terminal event: the request ends in the stage `event` maps to and frees what it
2257
+ * reserved. A no-op when the event cannot happen in the current stage, so a terminal stage, its
2258
+ * sign-log record and its settlement each happen exactly once.
2259
+ */
2260
+ private end;
2261
+ /** Applies `event` to `id`'s stage; returns the new stage, `undefined` when it cannot happen. */
2262
+ private transition;
2263
+ /** `approve` resumes after each await here: the request must still be `signing`. */
2264
+ private assertSigning;
2265
+ /**
2266
+ * `signing` → `signed` — the point of no return: the signature exists and is being returned or
2267
+ * broadcast, so invalidation no longer applies. Idempotent while `signed`; throws otherwise.
2268
+ */
2269
+ private commit;
1451
2270
  /** Appends the final stage to the signature record; a failed write is a warning, not an error. */
1452
2271
  private record;
1453
2272
  private appendLog;
@@ -1456,505 +2275,21 @@ declare class RequestController extends Controller<RequestControllerState> {
1456
2275
  * sends (Spark payments are not tracked).
1457
2276
  */
1458
2277
  private knownAddresses;
1459
- /** A blind-sign request carries one danger; a group that did not opt in refuses it outright. */
2278
+ /**
2279
+ * A decoder-marked blind request carries one danger; `approve` refuses it while the setting is
2280
+ * off.
2281
+ */
1460
2282
  private blindRisk;
1461
2283
  /** Risk of a Sign-In with X message; a message for another domain throws `SignInOriginError`. */
1462
2284
  private signInRisk;
2285
+ /** Every recipient the decoded intent names, minus the signer — the one rule for all requests. */
2286
+ private recipientRisk;
1463
2287
  private chainRisk;
1464
- /** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
1465
- private sparkRisk;
1466
- }
1467
- type ConnectionOrigin = {
1468
- readonly kind: "browser";
1469
- readonly origin: string;
1470
- };
1471
- type ConnectionScope = {
1472
- /** CAIP-10 */
1473
- readonly accounts: ReadonlyArray<string>;
1474
- readonly methods: ReadonlyArray<string>;
1475
- readonly notifications: ReadonlyArray<string>;
1476
- };
1477
- type ConnectionSession = {
1478
- readonly id: string;
1479
- readonly origin: ConnectionOrigin;
1480
- /** Keyed by CAIP-2. */
1481
- readonly scopes: Readonly<Record<string, ConnectionScope>>;
1482
- /** The session's current EVM network; only dApp sessions have one. */
1483
- readonly currentNetwork: string;
1484
- /** The origin's Nostr policy — set when the host approves a `nostr` connection. */
1485
- readonly nostrPolicy?: NostrPolicy;
1486
- /** The origin's Lightning policy — set when the host approves a `lightning` connection. */
1487
- readonly lightningPolicy?: LightningPolicy;
1488
- readonly createdAt: number;
1489
- readonly lastUsedAt: number;
1490
- };
1491
- /**
1492
- * How much a `nostr` session may do without per-call approval: `signing` is `"ask"` (every
1493
- * `signEvent` goes through the pipeline), `"always"` (any kind signs directly), or a kind list (`{
1494
- * kinds }` — only those kinds sign directly, the rest ask); `decrypt` gates `nip04/nip44 .decrypt`.
1495
- * The four forced-confirm kinds `{0,3,5,10002}` always ask regardless.
1496
- */
1497
- type NostrPolicy = {
1498
- readonly signing: "ask" | "always" | {
1499
- readonly kinds: ReadonlyArray<number>;
1500
- };
1501
- readonly decrypt: boolean;
1502
- };
1503
- /**
1504
- * How much a `lightning` session may do without per-call approval: `balance` gates `getBalance`
1505
- * (WebLN). Sending and invoicing always go through their own approvals.
1506
- */
1507
- type LightningPolicy = {
1508
- readonly balance: boolean;
1509
- };
1510
- /** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
1511
- type PendingConnection = {
1512
- readonly id: string;
1513
- readonly origin: ConnectionOrigin;
1514
- readonly kind: "connect" | "network";
1515
- /**
1516
- * Which namespace the connection is for — `eip155` (EVM), `nostr` (NIP-07) or `lightning`
1517
- * (WebLN).
1518
- */
1519
- readonly namespace: "eip155" | "nostr" | "lightning" | "solana" | "bip122";
1520
- readonly network?: string;
1521
- /** `false` for a `network` request that adds the network without making it current. */
1522
- readonly activate?: boolean;
1523
- readonly createdAt: number;
1524
- };
1525
- /** What a connection request asks for; `namespace` defaults to `eip155`, `activate` to `true`. */
1526
- type ConnectionRequest = {
1527
- readonly kind: PendingConnection["kind"];
1528
- readonly namespace?: PendingConnection["namespace"];
1529
- readonly network?: string;
1530
- readonly activate?: boolean;
1531
- };
1532
- type AccountGroup = {
1533
- readonly walletId: string;
1534
- readonly groupIndex: number;
1535
- };
1536
- type ConnectionState = {
1537
- readonly sessions: Readonly<Record<string, ConnectionSession>>;
1538
- readonly pending: Readonly<Record<string, PendingConnection>>;
1539
- };
1540
- type ConnectionControllerOptions = {
1541
- readonly openStore: () => Promise<EngineStore>;
1542
- readonly random: (n: number) => Uint8Array;
1543
- readonly now: () => number;
1544
- readonly logger: EngineLogger;
1545
- /** Development builds also accept `http://localhost`. */
1546
- readonly allowLocalhost: boolean;
1547
- /** The group the app currently shows; sessions are bound to it. */
1548
- readonly selectedGroup: () => AccountGroup | undefined;
1549
- /** The group's EVM address on `network`. */
1550
- readonly evmAddress: (group: AccountGroup, network: string) => Promise<string>;
1551
- /** The group's Solana address on `network` (a CAIP-2 `solana:<genesis>` chain). */
1552
- readonly solanaAddress: (group: AccountGroup, network: string) => Promise<string>;
1553
- /** The group's fixed dApp-facing Bitcoin address of `purpose` on `network` (`bip122:<genesis>`). */
1554
- readonly bitcoinAddress: (group: AccountGroup, network: string, purpose: BitcoinPurpose) => Promise<string>;
1555
- readonly enabledNetworks: () => ReadonlyArray<string>;
1556
- /** A Nostr identity's public key — `nostr(wallet).signer(ref).getPublicKey()`. */
1557
- readonly nostrPubkey: (ref: NostrKeyRef) => Promise<string>;
1558
- /** Voids a page's unfinished requests (revoked, or its network changed). */
1559
- readonly invalidate: (origin: string) => void;
1560
- readonly phishing: Pick<PhishingController, "check">;
1561
- readonly setTimer: (ms: number, fn: () => unknown) => () => void;
1562
- };
1563
- /** `payment` is the group's `btc.bip84` address, `ordinals` its `btc.bip86` one. */
1564
- type BitcoinPurpose = "payment" | "ordinals";
1565
- declare class ConnectionController extends Controller<ConnectionState> {
1566
- private readonly options;
1567
- private engineStore;
1568
- private readonly waiters;
1569
- private readonly expiries;
1570
- private group;
1571
- private identity;
1572
- constructor(options: ConnectionControllerOptions);
1573
- init(): Promise<void>;
1574
- destroy(): Promise<void>;
1575
- /** Locking is not consent: every pending connection is rejected. */
1576
- lock(): void;
1577
- /**
1578
- * A page navigated away (or the bridge is being disposed): the origin's pending connection
1579
- * requests are rejected and its unfinished pipeline requests voided — the live session survives
1580
- * (a refresh is not a revocation).
1581
- */
1582
- invalidateOrigin(origin: string): void;
1583
- /**
1584
- * Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development) and not on
1585
- * the phishing list.
1586
- */
1587
- checkOrigin(origin: string): ConnectionOrigin;
1588
- session(origin: string): ConnectionSession | undefined;
1589
- pending(): ReadonlyArray<PendingConnection>;
1590
- /** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
1591
- activeGroup(): AccountGroup | undefined;
1592
- /** Whether `network` is an EVM network the wallet has enabled. */
1593
- isEnabled(network: string): boolean;
1594
- /** The origin's authorized addresses on its current network; empty when not connected. */
1595
- accounts(origin: string): ReadonlyArray<string>;
1596
- /** Throws `4100` unless the origin's session covers `method` on `network`. */
1597
- authorize(origin: string, network: string, method: string): ConnectionSession;
1598
- /** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
1599
- request(origin: string, { kind, namespace, network, activate }: ConnectionRequest): Promise<ConnectionSession>;
1600
- /**
1601
- * The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
1602
- * network.
1603
- */
1604
- approveConnection(id: string, grant: {
1605
- readonly accounts: ReadonlyArray<string>;
1606
- readonly network: string;
1607
- /** The `nostr` namespace's grant: the identity's pubkey and the origin's policy. */
1608
- readonly nostr?: {
1609
- readonly pubkey: string;
1610
- readonly policy: NostrPolicy;
1611
- };
1612
- /** The `lightning` namespace's grant: the origin's policy. */
1613
- readonly lightning?: {
1614
- readonly policy: LightningPolicy;
1615
- };
1616
- }): Promise<ConnectionSession>;
1617
- rejectConnection(id: string): void;
1618
- /** Ends the origin's session; its pending connection and unfinished requests are void. */
1619
- revoke(origin: string): Promise<void>;
1620
- /** Switches within the session's scope; the origin's unfinished requests are void. */
1621
- setCurrentNetwork(origin: string, network: string): Promise<void>;
1622
- touch(origin: string): Promise<void>;
1623
- /**
1624
- * The host switched account group: every session's accounts become the new group's addresses. A
1625
- * session that cannot get one (no address derivable) is left with an empty list and has to be
1626
- * authorized again.
1627
- */
1628
- setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
1629
- /** The active Nostr identity — `undefined` until the host picks one. */
1630
- activeIdentity(): NostrKeyRef | undefined;
1631
- /** The origin's persisted Nostr policy — `undefined` until it is nostr-authorized. */
1632
- nostrPolicy(origin: string): NostrPolicy | undefined;
1633
- /** The origin's `nostr` namespace scope's pubkey, or `undefined` when not nostr-authorized. */
1634
- nostrAccount(origin: string): string | undefined;
1635
- /** The origin's persisted Lightning policy — `undefined` until it is lightning-authorized. */
1636
- lightningPolicy(origin: string): LightningPolicy | undefined;
1637
- /** The origin's `solana` scope's address on `network`, or `undefined` when not authorized. */
1638
- solanaAccount(origin: string, network: string): string | undefined;
1639
- /**
1640
- * The origin's `bip122` scope accounts on `network`, in `BITCOIN_PURPOSES` order, or `undefined`
1641
- * when not authorized.
1642
- */
1643
- bitcoinAccounts(origin: string, network: string): Record<BitcoinPurpose, string> | undefined;
1644
- private bitcoinScope;
1645
- /**
1646
- * The host's Nostr identity selection: every authorized `nostr` session's account becomes the new
1647
- * identity's pubkey (or empties when the identity is cleared). No event — NIP-07 has none.
1648
- */
1649
- setActiveIdentity(ref: NostrKeyRef | undefined): Promise<void>;
1650
- private dropPending;
1651
- private persist;
1652
- private requireStore;
1653
- }
1654
- /**
1655
- * The Bitcoin Wallet Standard (Exodus' `bitcoin:*` features, registered through
1656
- * `@wallet-standard/wallet` like the Solana wallet) handler — the bridge routes `provider:
1657
- * "bitcoin"` messages here.
1658
- */
1659
- type BitcoinRequest = {
1660
- readonly method: string;
1661
- readonly params?: unknown;
1662
- };
1663
- type BitcoinHandler = {
1664
- readonly handle: (origin: string, request: BitcoinRequest) => Promise<unknown>;
1665
- readonly subscribe: (listener: (event: BitcoinEvent) => void) => () => void;
1666
- };
1667
- /**
1668
- * The Bitcoin Wallet Standard chain ids to the registry's CAIP-2 ids: `bitcoin:testnet` is the
1669
- * registry's default test network (Testnet4 — the registry has no Testnet3).
1670
- */
1671
- declare const BITCOIN_CHAIN_IDS: Readonly<Record<string, string>>;
1672
- /** The Wallet Standard `WalletAccount` shape `bitcoin:connect` returns per account. */
1673
- type BitcoinWalletAccount = {
1674
- readonly address: string;
1675
- /** `payment`: the compressed key (33 bytes); `ordinals`: the x-only internal key (32 bytes). */
1676
- readonly publicKey: Uint8Array;
1677
- readonly chains: ReadonlyArray<string>;
1678
- readonly features: ReadonlyArray<string>;
1679
- };
1680
- type BitcoinEvent = {
1681
- readonly name: "bitcoinAccountsChanged";
1682
- readonly origin: string;
1683
- readonly accounts: ReadonlyArray<BitcoinWalletAccount>;
1684
- };
1685
- type BitcoinConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "bitcoinAccounts" | "request" | "touch" | "revoke" | "getState" | "store">;
1686
- type BitcoinRequests = Pick<RequestController, "prepare" | "outcome">;
1687
- type Options$1 = {
1688
- readonly connections: BitcoinConnections;
1689
- readonly requests: BitcoinRequests;
1690
- /** The group's address and public key for `purpose` on `network` (receive chain, index 0). */
1691
- readonly bitcoinAccount: (group: {
1692
- readonly walletId: string;
1693
- readonly groupIndex: number;
1694
- }, network: string, purpose: BitcoinPurpose) => Promise<{
1695
- readonly address: string;
1696
- readonly publicKey: Uint8Array;
1697
- }>;
1698
- readonly activeGroup: () => {
1699
- readonly walletId: string;
1700
- readonly groupIndex: number;
1701
- } | undefined;
1702
- readonly bitcoinNetwork: () => string;
1703
- };
1704
- /**
1705
- * The Bitcoin Wallet Standard handler: `bitcoin:connect` authorizes the `bip122` scope (both the
1706
- * `payment` and the `ordinals` account) and returns the requested purposes in order;
1707
- * `bitcoin:signMessage` goes through `bitcoin-sign` (BIP-322 simple); `bitcoinAccountsChanged`
1708
- * carries the re-pointed accounts the bridge forwards as `bitcoin:events` `change` on a group
1709
- * switch.
1710
- */
1711
- declare class BitcoinWalletHandler implements BitcoinHandler {
1712
- readonly options: Options$1;
1713
- private readonly events;
1714
- constructor(options: Options$1);
1715
- subscribe(listener: (event: BitcoinEvent) => void): () => void;
1716
- handle(origin: string, request: BitcoinRequest): Promise<unknown>;
1717
- private connect;
1718
- private walletAccount;
1719
2288
  /**
1720
- * Signs `message` (UTF-8 text only — `bitcoin.message` takes text, so there is no blind path) for
1721
- * one of the session's accounts. The signature is the BIP-322 simple witness serialization
1722
- * (witness item count, then each item length-prefixed) — the kernel's `smp` + base64 string
1723
- * decoded to bytes, which is what MetaMask's Bitcoin Wallet Standard wallet hands out.
2289
+ * Sats/token transfers name a Spark receiver and exits a bitcoin one — both assessed. Lightning
2290
+ * names a payee public key, which no address book holds, so it is not assessed.
1724
2291
  */
1725
- private signMessage;
1726
- /**
1727
- * Signs (and with `send` broadcasts) a batch of dApp PSBTs under one approval. Every account
1728
- * named must be a session account — inputs of both purposes may mix in one PSBT, each sign entry
1729
- * carries its account's template — and `chain`, when given, must be the session's network.
1730
- */
1731
- private signTransactions;
1732
- /** The `setActiveGroup` re-point: the bitcoin session's new accounts, `payment` then `ordinals`. */
1733
- bitcoinAccountsChanged(): Promise<BitcoinWalletAccount[]>;
1734
- }
1735
- type Eip1193Request = {
1736
- readonly method: string;
1737
- readonly params?: unknown;
1738
- };
1739
- type Eip1193Event = {
1740
- readonly name: "connect";
1741
- readonly origin: string;
1742
- readonly chainId: string;
1743
- } | {
1744
- readonly name: "accountsChanged";
1745
- readonly origin: string;
1746
- readonly accounts: ReadonlyArray<string>;
1747
- } | {
1748
- readonly name: "chainChanged";
1749
- readonly origin: string;
1750
- readonly chainId: string;
1751
- } | {
1752
- readonly name: "disconnect";
1753
- readonly origin: string;
1754
- };
1755
- type Eip1193HandlerOptions = {
1756
- readonly connections: ConnectionController;
1757
- readonly requests: RequestController;
1758
- readonly networks: NetworkController;
1759
- /** The network an unconnected page sees. */
1760
- readonly defaultNetwork: () => string;
1761
- /** Whether a token is already in the built-in table or the user's custom tokens. */
1762
- readonly isTracked: (network: string, address: string) => boolean;
1763
- /** The account's EIP-7702 delegation state on `network`. */
1764
- readonly delegationState: (account: AccountRef, network: string) => Promise<DelegationStatus>;
1765
- /** `wallet_sendCalls` bundles, keyed by their id. */
1766
- readonly batches: {
1767
- readonly record: (record: BatchRecord) => Promise<void>;
1768
- readonly get: (origin: string, id: string) => BatchRecord | undefined;
1769
- };
1770
- /** A tracked transaction by id — `wallet_getCallsStatus` aggregates them. */
1771
- readonly txById: (id: string) => TrackedTransaction | undefined;
1772
- /** The host shows a bundle's status page; `wallet_showCallsStatus` is the trigger. */
1773
- readonly showCallsStatus: (request: {
1774
- readonly origin: string;
1775
- readonly txIds: ReadonlyArray<string>;
1776
- }) => void;
1777
- readonly now: () => number;
1778
- readonly random: (length: number) => Uint8Array;
1779
- };
1780
- declare class Eip1193Handler {
1781
- private readonly options;
1782
- private readonly events;
1783
- constructor(options: Eip1193HandlerOptions);
1784
- /** Events for the host to forward to pages; derived from changes to the sessions. */
1785
- subscribe(listener: (event: Eip1193Event) => void): () => void;
1786
- handle(origin: string, request: Eip1193Request): Promise<unknown>;
1787
- private requestAccounts;
1788
- private permissions;
1789
- private switchChain;
1790
- /**
1791
- * EIP-3085. The chain must already be a network the wallet enables; the page's `rpcUrls` are
1792
- * validated for shape and never read or used — custom endpoints are the user's setting.
1793
- */
1794
- private addChain;
1795
- /** EIP-747 (ERC-20 only): `symbol`, `decimals` and `image` from the page are never used. */
1796
- private watchAsset;
1797
- private authorizedAccount;
1798
- private personalSign;
1799
- private typedData;
1800
- private sendTransaction;
1801
- /** The eip1559 placeholder the pipeline re-fills; only to, value, data and gas survive. */
1802
- private txSkeleton;
1803
- private signingSession;
1804
- private sign;
1805
- private requiredSession;
1806
- private accountFor;
1807
- /**
1808
- * EIP-5792 `wallet_getCapabilities`: `atomic` per chain the page asks about or its session
1809
- * covers.
1810
- */
1811
- private getCapabilities;
1812
- /** `wallet_sendCalls` (EIP-5792 v2.0.0): atomic batch, sequential fallback or 5760. */
1813
- private sendCalls;
1814
- /** One call through the `evm-sign` transaction path — its own approval. */
1815
- private submitCall;
1816
- /** ≥2 calls through `evm-batch` with the page's origin. */
1817
- private submitBatch;
1818
- /** `wallet_getCallsStatus` / `wallet_showCallsStatus`: the record must belong to the origin. */
1819
- private callsStatus;
1820
- private read;
1821
- }
1822
- /** A NIP-07 method call from the page. */
1823
- type Nip07Request = {
1824
- readonly method: string;
1825
- readonly params?: unknown;
1826
- };
1827
- type Nip07HandlerOptions = {
1828
- readonly connections: Pick<ConnectionController, "checkOrigin" | "authorize" | "session" | "nostrAccount" | "nostrPolicy" | "activeIdentity" | "request" | "touch">;
1829
- readonly requests: Pick<RequestController, "prepare" | "outcome">;
1830
- /** `nostr(wallet).signer(ref)` — the active identity's signer. */
1831
- readonly signerFor: (ref: NostrKeyRef) => WalletSigner;
1832
- };
1833
- declare class Nip07Handler {
1834
- private readonly options;
1835
- constructor(options: Nip07HandlerOptions);
1836
- handle(origin: string, request: Nip07Request): Promise<unknown>;
1837
- private publicKey;
1838
- private signEvent;
1839
- private crypt;
1840
- }
1841
- /**
1842
- * The Wallet Standard (`window.solana` / `registerWallet`) handler — the bridge routes `provider:
1843
- * "solana"` messages here.
1844
- */
1845
- type SolanaRequest = {
1846
- readonly method: string;
1847
- readonly params?: unknown;
1848
- };
1849
- type SolanaHandler = {
1850
- readonly handle: (origin: string, request: SolanaRequest) => Promise<unknown>;
1851
- readonly subscribe: (listener: (event: SolanaEvent) => void) => () => void;
1852
- };
1853
- /**
1854
- * The Wallet Standard short chain ids to the registry's CAIP-2 genesis-hash ids, derived from the
1855
- * solana network registry by name.
1856
- */
1857
- declare const SOLANA_CHAIN_IDS: Readonly<Record<string, string>>;
1858
- /** The Wallet Standard `WalletAccount` shape `standard:connect` returns per account. */
1859
- type SolanaWalletAccount = {
1860
- readonly address: string;
1861
- readonly publicKey: Uint8Array;
1862
- readonly chains: ReadonlyArray<string>;
1863
- readonly features: ReadonlyArray<string>;
1864
- readonly icon?: string;
1865
- readonly label?: string;
1866
- };
1867
- type SolanaEvent = {
1868
- readonly name: "solanaAccountsChanged";
1869
- readonly origin: string;
1870
- readonly accounts: ReadonlyArray<SolanaWalletAccount>;
1871
- };
1872
- type SolanaConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "solanaAccount" | "request" | "touch" | "revoke" | "getState" | "store">;
1873
- type SolanaRequests = Pick<RequestController, "prepare" | "outcome">;
1874
- type Options = {
1875
- readonly connections: SolanaConnections;
1876
- readonly requests: SolanaRequests;
1877
- /** The group's Solana address + public key on `network` (the `solana.bip44-change` account). */
1878
- readonly solanaAccount: (group: {
1879
- readonly walletId: string;
1880
- readonly groupIndex: number;
1881
- }, network: string) => Promise<{
1882
- readonly address: string;
1883
- readonly publicKey: Uint8Array;
1884
- }>;
1885
- readonly activeGroup: () => {
1886
- readonly walletId: string;
1887
- readonly groupIndex: number;
1888
- } | undefined;
1889
- readonly solanaNetwork: () => string;
1890
- };
1891
- /**
1892
- * The Wallet Standard handler: `standard:connect` authorizes the `solana` scope, `solana:*` sign
1893
- * requests go through `solana-sign`, `solanaAccountsChanged` returns the re-pointed accounts the
1894
- * bridge forwards as `standard:events` `change` on a group switch.
1895
- */
1896
- declare class SolanaWalletHandler implements SolanaHandler {
1897
- readonly options: Options;
1898
- private readonly events;
1899
- constructor(options: Options);
1900
- /** `standard:events` `change` per origin — derived from changes to the sessions. */
1901
- subscribe(listener: (event: SolanaEvent) => void): () => void;
1902
- handle(origin: string, request: SolanaRequest): Promise<unknown>;
1903
- private connect;
1904
- private walletAccount;
1905
- private signTransactions;
1906
- /**
1907
- * The network a transaction call targets: the wallet's default when no input names a chain,
1908
- * otherwise the one chain every input agrees on (`chain` is required for sign-and-send).
1909
- */
1910
- private networkOf;
1911
- private signMessage;
1912
- /**
1913
- * Sign In With Solana: connects first when needed, binds the message to the page's host and the
1914
- * session's account, and signs the exact text the user is shown.
1915
- */
1916
- private signIn;
1917
- private signMessageRequest;
1918
- /** One `solana-sign` request for the active group, resolved to its outcome. */
1919
- private signRequest;
1920
- /** The `setActiveGroup` re-point: the solana session's new `WalletAccount[]` for `change`. */
1921
- solanaAccountsChanged(_origin: string): Promise<SolanaWalletAccount[]>;
1922
- }
1923
- /** A WebLN method call from the page. */
1924
- type WeblnRequest = {
1925
- readonly method: string;
1926
- readonly params?: unknown;
1927
- };
1928
- type WeblnHandlerOptions = {
1929
- readonly connections: Pick<ConnectionController, "checkOrigin" | "authorize" | "session" | "lightningPolicy" | "request" | "touch">;
1930
- readonly requests: Pick<RequestController, "prepare" | "outcome">;
1931
- readonly spark: Pick<SparkController, "accountBalance" | "paymentStatus">;
1932
- /** The active group's Spark account — `undefined` when no group is selected. */
1933
- readonly sparkAccount: () => SparkAccountRef | undefined;
1934
- readonly now: () => number;
1935
- /** The node's display alias — host-configured, never a pubkey. */
1936
- readonly alias: string;
1937
- /** The host's lightning fee cap — `pay`'s `maxFeeSats` comes from here. */
1938
- readonly lightningMaxFee: (amountSats: number) => number;
1939
- /** The injected wait for the preimage poll. */
1940
- readonly sleep: (ms: number) => Promise<void>;
1941
- };
1942
- declare class WeblnHandler {
1943
- private readonly options;
1944
- constructor(options: WeblnHandlerOptions);
1945
- private ref;
1946
- handle(origin: string, request: WeblnRequest): Promise<unknown>;
1947
- private sendPayment;
1948
- private makeInvoice;
1949
- private lnurl;
1950
- private preimage;
1951
- private lightningOption;
1952
- private getBalance;
1953
- }
1954
- /** EIP-1193 / EIP-1474 / EIP-3326 error: `code` is what the page's promise rejects with. */
1955
- declare class ProviderError extends Error {
1956
- readonly code: number;
1957
- constructor(code: number, message: string);
2292
+ private sparkRisk;
1958
2293
  }
1959
- export { PHISHING_REFRESH_MS as $, PayInput as A, AddressBookController as At, SignLogEntry as B, createEventBus as Bt, ConnectionOrigin as C, SparkControllerState as Ct, NostrPolicy as D, RequestCheckCode as Dt, ConnectionState as E, SparkActivity as Et, RequestControllerState as F, EngineCollection as Ft, RiskFinding as G, BrowserOrigin as H, ControllerOptions as Ht, RequestInput as I, EngineStore as It, DelegationStatus as J, TransactionController as K, RequestStage as L, PublicStore as Lt, REQUEST_TTL_MS as M, AddressBookEntry as Mt, RESIMULATE_AFTER_MS as N, AddressBookRecord as Nt, PendingConnection as O, NetworkController as Ot, RequestController as P, AddressFamily as Pt, AcrossBridgeStatus as Q, SparkDepositInput as R, EngineLogger as Rt, ConnectionController as S, SparkControllerOptions as St, ConnectionSession as T, PaymentNote as Tt, RequestMethod as U, SignLogOutcome as V, Controller as Vt, RequestOrigin as W, SwapQuote as X, SignatureResult as Y, AcrossBridgeQuote as Z, BitcoinHandler as _, SparkDisplay as _t, SolanaEvent as a, PrepareZapParams as at, BitcoinWalletHandler as b, SparkClientFactory as bt, SolanaWalletAccount as c, prepareZap as ct, Nip07Request as d, ParseOptions as dt, PhishingController as et, Eip1193Event as f, PaymentOption as ft, BitcoinEvent as g, PreparedSparkAction as gt, BITCOIN_CHAIN_IDS as h, parsePayment as ht, SOLANA_CHAIN_IDS as i, PrepareZapContext as it, PendingRequest as j, AddressBookState as jt, EvmSignInput as k, Esplora as kt, SolanaWalletHandler as l, PayParams as lt, Eip1193Request as m, PaymentRequest as mt, WeblnHandler as n, PhishingState as nt, SolanaHandler as o, PreparedZap as ot, Eip1193Handler as p, PaymentParse as pt, AccountRef as q, WeblnRequest as r, PhishingStatus as rt, SolanaRequest as s, ZapRecipient as st, ProviderError as t, PhishingControllerOptions as tt, Nip07Handler as u, WithdrawLnurlParams as ut, BitcoinRequest as v, SparkResult as vt, ConnectionScope as w, sparkStore as wt, AccountGroup as x, SparkController as xt, BitcoinWalletAccount as y, SparkAccountState as yt, SparkExitInput as z, EventBus as zt };
1960
- //# sourceMappingURL=errors-CQnlTc1i.d.mts.map
2294
+ export { TxBlock as $, SparkControllerState as $t, WatchAssetInput as A, Controller as An, PhishingController as At, AccountRef as B, createEventBus as Bn, WithdrawLnurlParams as Bt, SolanaSignInput as C, PublicStore as Cn, SignInOriginError as Ct, TokenWatchDisplay as D, NftTransferError as Dn, dappUrl as Dt, SparkExitInput as E, NftRefusal as En, WalletConnectVerify as Et, RequestStage as F, Esplora as Fn, PrepareZapParams as Ft, DisplayIntent$1 as G, parsePayment as Gt, ChainApis as H, PaymentOption as Ht, SignLogEntry as I, SetTimer as In, PreparedZap as It, SendParams as J, SparkResult as Jt, EvmRevokeTarget as K, PreparedSparkAction as Kt, SignLogOutcome as L, timeoutSignal as Ln, ZapRecipient as Lt, WeblnInvoiceResult as M, TronApi as Mn, PhishingState as Mt, ZapInput as N, TronFeeQuote as Nn, PhishingStatus as Nt, TokenWatchResult as O, GatewayConfig as On, walletConnectKey as Ot, requiredAcknowledgement as P, TronThrottledError as Pn, PrepareZapContext as Pt, TrackedTransaction as Q, SparkControllerOptions as Qt, TransactionController as R, EngineLogger as Rn, prepareZap as Rt, SolanaDisplay as S, EngineStore as Sn, RequestOrigin as St, SparkDepositInput as T, EngineStoreError as Tn, WalletConnectOrigin as Tt, ChainRequestInput as U, PaymentParse as Ut, BatchRecord as V, ParseOptions as Vt, DelegationStatus as W, PaymentRequest as Wt, SignedTransactionResult as X, SparkClientFactory as Xt, SignatureResult as Y, SparkAccountState as Yt, SparkDepositTag as Z, SparkController as Zt, RequestController as _, AddressFamily as _n, NonceConflictError as _t, BitcoinSignResult as a, PaymentNote as an, AcrossBridgeQuote as at, RequestResult as b, SolanaRpc as bn, RequestEndedError as bt, LightningInvoiceDisplay as c, SolanaFeeTier as cn, AppOrigin as ct, NostrSignResult as d, SimulationOutcome as dn, BitcoinPsbtInput as dt, SparkTokenBalance as en, TxState as et, PayInput as f, SignInFields as fn, BitcoinSigHash as ft, RequestAcknowledgement as g, AddressBookRecord as gn, InvalidTokenError as gt, RESIMULATE_AFTER_MS as h, AddressBookEntry as hn, DappOrigin as ht, BitcoinSignInput as i, SparkPaymentState as in, ZeroExSwapQuote as it, WeblnInvoiceInput as j, ControllerOptions as jn, PhishingControllerOptions as jt, TronSignInput as k, GatewayScope as kn, PHISHING_REFRESH_MS as kt, NostrDisplay as l, EvmFeeTier as ln, BitcoinAccount as lt, REQUEST_TTL_MS as m, AddressBookState as mn, ChainRequestMethod as mt, ApproveOptions as n, SparkPaymentKind as nn, JupiterSwapQuote as nt, BlindSigningDisabledError as o, SparkActivity as on, AcrossBridgeStatus as ot, PendingRequest as p, AddressBookController as pn, BrowserOrigin as pt, PrepareParams as q, SparkDisplay as qt, BitcoinDisplay as r, SparkPaymentRecord as rn, SwapQuote as rt, EvmSignInput as s, RequestCheckCode as sn, RiskFinding as st, AcknowledgementRequiredError as t, sparkStore as tn, JupiterInstruction as tt, NostrSignInput as u, AssetChange as un, BitcoinGroup as ut, RequestControllerState as v, NetworkController as vn, OriginBusyError as vt, SolanaSignResult as w, EngineErrorCode as wn, SolanaAccount as wt, SimulationChangedError as x, EngineCollection as xn, RequestMethod as xt, RequestInput as y, NetworkControllerState as yn, QrOrigin as yt, TransactionControllerState as z, EventBus as zn, PayParams as zt };
2295
+ //# sourceMappingURL=controller-DpNVHVsj.d.mts.map