@qntx/wallet-engine 0.4.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 QuantX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @qntx/wallet-engine
2
+
3
+ App-side controllers over a [`@qntx/wallet`](https://www.npmjs.com/package/@qntx/wallet) `Wallet`:
4
+ the account tree, Spark payments, zaps, encrypted metadata sync and cloud backup. Controllers
5
+ expose Zustand stores; every I/O dependency (`fetch`, randomness, clock, storage, relays, cloud)
6
+ is injected. The engine never holds signing keys — every wallet-owned outflow goes through the
7
+ enclave's per-operation approval.
8
+
9
+ Peer dependencies: the exact `@qntx/wallet` release, `@qntx/spark` `^0.5.0` and
10
+ `@qntx/nostr` `^0.15.0`.
11
+
12
+ ```bash
13
+ npm install @qntx/wallet-engine @qntx/wallet @qntx/wallet-worker @qntx/spark @qntx/nostr
14
+ ```
15
+
16
+ ```ts
17
+ import { createWalletEngine } from "@qntx/wallet-engine";
18
+ import { openIndexedDbEngineStore } from "@qntx/wallet-engine/idb";
19
+
20
+ const random = (n: number) => crypto.getRandomValues(new Uint8Array(n));
21
+ const engine = createWalletEngine({
22
+ wallet, // from createWebWallet / createNodeWallet / createNativeWallet
23
+ sparkNetwork: "mainnet",
24
+ fetch: globalThis.fetch.bind(globalThis),
25
+ random,
26
+ now: () => Date.now(),
27
+ logger: { warn: (message, error) => console.warn(message, error) },
28
+ openStore: async () =>
29
+ openIndexedDbEngineStore({
30
+ name: "app-engine",
31
+ dataKey: await wallet.dataKeys.get("wallet-db"),
32
+ random,
33
+ }),
34
+ });
35
+ ```
36
+
37
+ The engine follows the wallet's lock state: unlocking opens the encrypted `EngineStore` and starts
38
+ the selected account group; locking flushes pending writes, closes every Spark client and clears
39
+ in-memory state.
40
+
41
+ ## Surface
42
+
43
+ - `engine.accounts` — `AccountTreeController`: wallets and account groups, selection, names,
44
+ hidden groups, Spark group discovery and social identity bindings.
45
+ - `engine.spark` — `SparkController`: balances, history, sends, Lightning receives and
46
+ cooperative exits for the selected group.
47
+ - `engine.payments` — `parse` (pure, never throws), `resolve` (LNURL lookups) and `pay`, which
48
+ routes a parsed option to Spark, Lightning or a Bitcoin withdrawal after validation and before
49
+ approval. Typed `PayResult` per payment kind.
50
+ - `engine.zaps` — `prepare` signs the NIP-57 request with any `NostrSigner` and fetches the
51
+ invoice; `pay` pays it from the built-in Spark wallet. External wallets may pay
52
+ `prepared.invoice` themselves and validate the receipt against `receiptPubkey`.
53
+ - `engine.metaSync` — NIP-78 (kind 30078) metadata documents, NIP-44 encrypted to the wallet's
54
+ group-0 Nostr identity; pull before publish, per-entry last-writer-wins.
55
+ - `engine.backup` — `BackupController` over an injected `CloudStore`.
56
+
57
+ ## License
58
+
59
+ MIT OR Apache-2.0
package/dist/index.d.mts CHANGED
@@ -2,10 +2,17 @@ import { StoreApi } from "zustand/vanilla";
2
2
  import { CooperativeExitResult, LightningInvoice, LightningPayment, SparkClient, SparkExitChain, SparkNetwork, SparkPayment, SparkStore, SparkTransfer } from "@qntx/spark";
3
3
  import { NostrKeyRef, WalletSigner } from "@qntx/wallet/nostr";
4
4
  import { SparkSigner } from "@qntx/wallet/spark";
5
+ import { PublicClient } from "viem";
6
+ import { chains } from "@qntx/wallet/chains";
7
+ import "@scure/btc-signer";
8
+ import { decodeEvm } from "@qntx/wallet-chains/evm";
5
9
  import { BackupHeader, BackupInfo, InitialFactor, UnlockFactor, Wallet, WalletInfo } from "@qntx/wallet";
6
10
  import { Event, Filter, NostrSigner } from "@qntx/nostr";
7
11
  import { LnurlPayRequest, LnurlWithdrawRequest } from "@qntx/spark/lnurl";
12
+ import "@solana/kit";
8
13
  import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
14
+ import "@scure/btc-signer/psbt.js";
15
+ import "@qntx/wallet-chains";
9
16
  //#region src/controller.d.ts
10
17
  type ControllerOptions<S> = {
11
18
  readonly name: string;
@@ -69,6 +76,12 @@ export declare function createMemoryEngineStore(backing?: {
69
76
  readonly collections?: Map<string, Map<string, Uint8Array>>;
70
77
  }): EngineStore;
71
78
  //#endregion
79
+ //#region src/chains/bitcoin.d.ts
80
+ type Esplora = {
81
+ readonly get: (path: string) => Promise<unknown>;
82
+ readonly post: (path: string, body: string) => Promise<unknown>;
83
+ };
84
+ //#endregion
72
85
  //#region src/meta/doc.d.ts
73
86
  /**
74
87
  * Wallet metadata document — the plaintext exchanged over kind-30078 events between this wallet's
@@ -266,6 +279,9 @@ export declare class SparkController extends Controller<SparkControllerState> {
266
279
  type AccountGroup = {
267
280
  readonly walletId: string;
268
281
  readonly index: number;
282
+ /** `discoverGroups` result — family key → used; a family error lives under `errors`. */
283
+ readonly used?: Readonly<Record<string, boolean>>;
284
+ readonly errors?: Readonly<Record<string, string>>;
269
285
  readonly name?: string;
270
286
  readonly hidden: boolean;
271
287
  /** A social identity (64 lowercase hex) bound to this group; one identity binds one group. */
@@ -287,21 +303,41 @@ type AccountTreeState = {
287
303
  } | null;
288
304
  readonly totals: Readonly<Record<string, number>>;
289
305
  };
306
+ type DiscoveryNetworks = {
307
+ readonly client: (network: string) => {
308
+ readonly getTransactionCount: (p: {
309
+ readonly address: `0x${string}`;
310
+ readonly blockTag: "latest";
311
+ }) => Promise<number>;
312
+ readonly getBalance: (p: {
313
+ readonly address: `0x${string}`;
314
+ }) => Promise<bigint>;
315
+ };
316
+ readonly solanaRpc: (network: string) => {
317
+ readonly call: (method: string, params: unknown[]) => Promise<unknown>;
318
+ };
319
+ readonly esplora: (network: string) => Esplora;
320
+ readonly enabled: (family: "evm" | "solana" | "bitcoin") => ReadonlyArray<string>;
321
+ };
290
322
  type AccountTreeControllerOptions = {
291
323
  readonly wallet: Wallet;
292
324
  readonly spark: SparkController;
293
325
  readonly sparkNetwork: SparkNetwork;
326
+ readonly networks?: DiscoveryNetworks;
327
+ readonly chains?: {
328
+ readonly account: (params: {
329
+ readonly walletId: string;
330
+ readonly groupIndex: number;
331
+ readonly template: string;
332
+ readonly network: string;
333
+ }) => Promise<{
334
+ readonly address?: string;
335
+ readonly xpub?: string;
336
+ }>;
337
+ };
294
338
  readonly logger: EngineLogger;
295
339
  readonly now: () => number;
296
340
  };
297
- /**
298
- * Declarative account tree: wallets come from the Wallet snapshot (reconciled on unlock and on
299
- * every snapshot change while unlocked), groups/names/hidden/selected/totals persist to the engine
300
- * store under `accounts/tree`. The controller drives `spark.setAccounts` with the selected group
301
- * only — an unselected group needs no live client (incoming transfers are claimed whenever it is
302
- * selected again). The active account's `balanceSats` feeds `totals`, debounced 1 s before
303
- * persist.
304
- */
305
341
  export declare class AccountTreeController extends Controller<AccountTreeState> {
306
342
  private readonly options;
307
343
  private col;
@@ -351,6 +387,12 @@ export declare class AccountTreeController extends Controller<AccountTreeState>
351
387
  };
352
388
  /** Sequential inspect from 0 upward; index 0 always included; stop after 2 consecutive unused. */
353
389
  discoverSpark(walletId: string): Promise<number[]>;
390
+ /**
391
+ * Per-group chain-family discovery — same stop rule as `discoverSpark`: group 0 always, stop
392
+ * after two consecutive fully-unused groups. A family error is reported on the group and does NOT
393
+ * count as unused (the group stays in `found` — it can't be proven empty).
394
+ */
395
+ discoverGroups(walletId: string): Promise<number[]>;
354
396
  /** Refresh `totals` for every other visible group; per-group failures are logged and skipped. */
355
397
  refreshTotals(): Promise<void>;
356
398
  private onSparkState;
@@ -370,6 +412,115 @@ export declare class AccountTreeController extends Controller<AccountTreeState>
370
412
  private flushTotals;
371
413
  }
372
414
  //#endregion
415
+ //#region src/networks/registry.d.ts
416
+ /**
417
+ * Built-in EVM network registry: the 8 mainnets from chains.mdx plus their main testnets. Each
418
+ * chain id was checked against the chain's official documentation (source URL per entry).
419
+ * Signing-time chainId always comes from this table, never from an RPC endpoint.
420
+ */
421
+ type NetworkInfo = {
422
+ readonly id: string;
423
+ readonly chainId: number;
424
+ readonly name: string;
425
+ readonly symbol: string;
426
+ readonly multicall3?: string;
427
+ /** CAIP-2 family — `solana:<ref>` networks are validated against genesis-hash, not chainId. */
428
+ readonly family: "evm" | "solana" | "bitcoin";
429
+ readonly genesisHash?: string;
430
+ readonly decimals: number;
431
+ readonly testnet: boolean;
432
+ };
433
+ //#endregion
434
+ //#region src/networks/controller.d.ts
435
+ type SolanaRpc = {
436
+ readonly call: (method: string, params: unknown[]) => Promise<unknown>;
437
+ };
438
+ type NetworkControllerState = {
439
+ readonly customRpc: Record<string, ReadonlyArray<string>>;
440
+ };
441
+ type Options$2 = {
442
+ readonly fetch: typeof globalThis.fetch;
443
+ readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
444
+ readonly openStore: () => Promise<EngineStore>;
445
+ readonly logger: EngineLogger;
446
+ };
447
+ declare class NetworkController extends Controller<NetworkControllerState> {
448
+ private readonly options;
449
+ private engineStore?;
450
+ private readonly clients;
451
+ constructor(options: Options$2);
452
+ init(): Promise<void>;
453
+ destroy(): Promise<void>;
454
+ lock(): void;
455
+ endpoints(network: string): ReadonlyArray<string>;
456
+ info(network: string): NetworkInfo;
457
+ client(network: string): PublicClient;
458
+ /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
459
+ /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
460
+ /** Networks with at least one configured endpoint, filtered by family. */
461
+ enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
462
+ solanaRpc(network: string): SolanaRpc;
463
+ /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
464
+ esplora(network: string): Esplora;
465
+ addRpc(network: string, url: string): Promise<void>;
466
+ }
467
+ //#endregion
468
+ //#region src/assets/controller.d.ts
469
+ type TokenBalance = {
470
+ readonly address: string;
471
+ readonly symbol: string;
472
+ readonly decimals: number;
473
+ readonly balance: string;
474
+ /** False for user-added tokens until they appear in the built-in table. */
475
+ readonly verified: boolean;
476
+ };
477
+ type AccountBalances = {
478
+ readonly native: string;
479
+ readonly tokens: ReadonlyArray<TokenBalance>;
480
+ /** Bitcoin only — confirmed + own unconfirmed change; frozen 546/330-sat UTXOs shown apart. */
481
+ readonly unconfirmed?: string;
482
+ readonly frozen?: string;
483
+ };
484
+ type AssetsControllerState = {
485
+ readonly balances: Record<string, AccountBalances>;
486
+ };
487
+ type Options$1 = {
488
+ readonly networks: NetworkController;
489
+ readonly openStore: () => Promise<EngineStore>;
490
+ readonly setTimer: (ms: number, fn: () => unknown) => () => void;
491
+ readonly logger: EngineLogger;
492
+ };
493
+ declare class AssetsController extends Controller<AssetsControllerState> {
494
+ private readonly options;
495
+ private engineStore;
496
+ private readonly bitcoinUtxos;
497
+ private visible;
498
+ private cancelPoll;
499
+ private readonly customTokens;
500
+ constructor(options: Options$1);
501
+ init(): Promise<void>;
502
+ lock(): void;
503
+ destroy(): Promise<void>;
504
+ setVisible(visible: boolean): void;
505
+ private armPoll;
506
+ private refreshAll;
507
+ refresh(address: string, network: string): Promise<void>;
508
+ /** SOL via getBalance; SPL via getTokenAccountsByOwner (jsonParsed) for known mints. */
509
+ private refreshSolana;
510
+ private readTokens;
511
+ private balanceOfBatch;
512
+ private balanceOf;
513
+ private callString;
514
+ private callNumber;
515
+ /** Reads symbol/decimals on-chain, marks unverified, persists; throws when the calls fail. */
516
+ addToken(network: string, address: string): Promise<void>;
517
+ private persistToken;
518
+ private rpc;
519
+ private rpcHex;
520
+ /** BTC balance = confirmed spendable + own unconfirmed change; frozen 546/330 shown separately. */
521
+ refreshBitcoin(xpub: string, network: string): Promise<void>;
522
+ }
523
+ //#endregion
373
524
  //#region src/backup/errors.d.ts
374
525
  /** BackupController error categories — never carry file contents, digests or secrets. */
375
526
  type BackupErrorCategory = "cloud" | "conflict" | "unavailable";
@@ -676,6 +827,109 @@ export declare function prepareZap(params: PrepareZapParams, context: PrepareZap
676
827
  */
677
828
  export declare function payZap(spark: SparkController, account: SparkAccountRef, prepared: PreparedZap, options: PayZapOptions): Promise<LightningPayment>;
678
829
  //#endregion
830
+ //#region src/chains/evm.d.ts
831
+ type EvmFeeTier = "slow" | "normal" | "fast";
832
+ //#endregion
833
+ //#region src/chains/solana.d.ts
834
+ type SolanaFeeTier = "slow" | "normal" | "fast";
835
+ //#endregion
836
+ //#region src/transactions/route.d.ts
837
+ type SignParams = Parameters<ReturnType<typeof chains>["sign"]>[0];
838
+ type AccountRef = SignParams["request"]["account"];
839
+ type DisplayIntent = ReturnType<typeof decodeEvm>;
840
+ type TxState = "draft" | "signed" | "submitted" | "pending" | "confirmed" | "failed" | "rejected" | "dropped" | "replaced";
841
+ type TrackedTransaction = {
842
+ readonly id: string;
843
+ readonly family: "evm" | "solana" | "bitcoin";
844
+ readonly network: string;
845
+ readonly account: string;
846
+ readonly hash: string | undefined;
847
+ readonly state: TxState;
848
+ readonly intent: DisplayIntent | undefined;
849
+ readonly nonce: number;
850
+ /** Solana only — the blockhash expiry that turns an unconfirmed tx `dropped`. */
851
+ readonly lastValidBlockHeight?: number;
852
+ /** EVM replacement — the earlier transaction this one bumps or cancels. */
853
+ readonly replaces?: string;
854
+ /** CPFP — the unconfirmed parent this child pushes. */
855
+ readonly parentId?: string;
856
+ /** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
857
+ readonly btc?: {
858
+ readonly inputs: ReadonlyArray<{
859
+ readonly txid: string;
860
+ readonly vout: number;
861
+ readonly value: number;
862
+ readonly address: string;
863
+ }>;
864
+ readonly outputs: ReadonlyArray<{
865
+ readonly address: string;
866
+ readonly value: number;
867
+ readonly own: boolean;
868
+ }>;
869
+ readonly vsize: number;
870
+ readonly fee: number;
871
+ readonly feeRate: number;
872
+ };
873
+ readonly submittedAt: number;
874
+ readonly error: string | undefined;
875
+ };
876
+ type SendParams = {
877
+ readonly account: AccountRef;
878
+ readonly network: string;
879
+ readonly to: string;
880
+ readonly amount: bigint;
881
+ /** ERC-20 contract — when set, `to`/`amount` are the transfer recipient/units and value is 0. */
882
+ readonly token?: string;
883
+ readonly fee: EvmFeeTier | SolanaFeeTier;
884
+ /** SPL mint decimals — required when `token` is a Solana mint. */
885
+ readonly decimals?: number;
886
+ readonly verify: SignParams["verify"];
887
+ };
888
+ type Options = {
889
+ readonly wallet: Wallet;
890
+ readonly networks: NetworkController;
891
+ readonly openStore: () => Promise<EngineStore>;
892
+ readonly random: (n: number) => Uint8Array;
893
+ readonly setTimer: (ms: number, fn: () => unknown) => () => void;
894
+ readonly now: () => number;
895
+ readonly logger: EngineLogger;
896
+ readonly pollMs?: number;
897
+ /** Test seam — defaults to the wallet's real chains proxy. */
898
+ readonly chains?: ReturnType<typeof chains>;
899
+ };
900
+ //#endregion
901
+ //#region src/transactions/controller.d.ts
902
+ type TransactionControllerState = {
903
+ readonly txs: Record<string, TrackedTransaction>;
904
+ };
905
+ declare class TransactionController extends Controller<TransactionControllerState> {
906
+ private readonly options;
907
+ private engineStore?;
908
+ private readonly timers;
909
+ private evmRoute;
910
+ private readonly bitcoinRoute;
911
+ private locked;
912
+ constructor(options: Options);
913
+ init(): Promise<void>;
914
+ destroy(): Promise<void>;
915
+ lock(): void;
916
+ private persist;
917
+ private transition;
918
+ private routeCtx;
919
+ send(params: SendParams): Promise<TrackedTransaction>;
920
+ /**
921
+ * Speed up or cancel a pending/submitted EVM transaction at the same nonce — a fresh signature is
922
+ * required and a rejection leaves the original untouched.
923
+ */
924
+ replace(id: string, mode: "speed-up" | "cancel", verify: SendParams["verify"]): Promise<TrackedTransaction>;
925
+ /**
926
+ * CPFP — spend an unconfirmed tx's own outputs into a higher-fee child so the package mines.
927
+ * Bitcoin only; the child is linked via `parentId`.
928
+ */
929
+ bumpChild(id: string, targetRate: number, verify: SendParams["verify"]): Promise<TrackedTransaction>;
930
+ private track;
931
+ }
932
+ //#endregion
679
933
  //#region src/engine.d.ts
680
934
  type EngineOptions = {
681
935
  readonly wallet: Wallet;
@@ -688,12 +942,19 @@ type EngineOptions = {
688
942
  readonly openStore: () => Promise<EngineStore>;
689
943
  /** Cloud file transport for the backup controller; absent → `unavailable`. */
690
944
  readonly cloud?: CloudStore;
945
+ /** RPC endpoints per network (CAIP-2), ordered by preference for the viem fallback transport. */
946
+ readonly rpc?: Readonly<Record<string, ReadonlyArray<string>>>;
947
+ /** Injected timer for transaction polling; defaults to setTimeout. */
948
+ readonly setTimer?: (ms: number, fn: () => void) => () => void;
691
949
  /** Kind-30078 wallet-metadata sync; absent → every wallet reports `unavailable`. */
692
950
  readonly metaSync?: MetaSyncConfig;
693
951
  /** Test seam — defaults to the wallet's real spark proxy. */
694
952
  readonly sparkApis?: SparkControllerOptions["spark"];
695
953
  };
696
954
  type WalletEngine = {
955
+ readonly networks: NetworkController;
956
+ readonly assets: AssetsController;
957
+ readonly transactions: TransactionController;
697
958
  readonly spark: SparkController;
698
959
  readonly accounts: AccountTreeController;
699
960
  readonly metaSync: MetaSyncController;
@@ -705,7 +966,7 @@ type WalletEngine = {
705
966
  readonly payments: {
706
967
  readonly parse: (input: string, network: SparkNetwork) => PaymentParse;
707
968
  readonly resolve: (input: string, network: SparkNetwork) => Promise<PaymentParse>;
708
- readonly pay: (params: PayParams) => Promise<unknown>;
969
+ readonly pay: (params: PayParams) => Promise<PayResult>;
709
970
  };
710
971
  readonly unsubscribe: () => void;
711
972
  };
@@ -754,5 +1015,5 @@ export declare function resolvePayment(input: string, options: ResolveOptions):
754
1015
  export declare function encodeExitChain(chain: SparkExitChain): Uint8Array;
755
1016
  export declare function decodeExitChain(bytes: Uint8Array): SparkExitChain;
756
1017
  //#endregion
757
- export type { AccountGroup, AccountTreeState, BackupControllerState, BackupErrorCategory, CloudStore, ControllerOptions, EngineCollection, EngineErrorCode, EngineLogger, EngineOptions, EngineStore, EventBus, MetaDoc, MetaDocGroup, MetaDocWallet, MetaSyncConfig, MetaSyncRelayPort, MetaSyncState, MetaSyncWalletStatus, PayResult, PayZapOptions, PaymentNote, PaymentOption, PaymentParse, PaymentRequest, PrepareZapContext, PrepareZapParams, PreparedZap, SparkAccountState, SparkActivity, SparkClientFactory, SparkControllerOptions, SparkControllerState, SparkErrorCategory, WalletEngine, ZapRecipient };
1018
+ export type { AccountGroup, AccountTreeState, BackupControllerState, BackupErrorCategory, CloudStore, ControllerOptions, EngineCollection, EngineErrorCode, EngineLogger, EngineOptions, EngineStore, EventBus, MetaDoc, MetaDocGroup, MetaDocWallet, MetaSyncConfig, MetaSyncRelayPort, MetaSyncState, MetaSyncWalletStatus, PayParams, PayResult, PayZapOptions, PaymentNote, PaymentOption, PaymentParse, PaymentRequest, PrepareZapContext, PrepareZapParams, PreparedZap, SparkAccountState, SparkActivity, SparkClientFactory, SparkControllerOptions, SparkControllerState, SparkErrorCategory, WalletEngine, ZapRecipient };
758
1019
  //# sourceMappingURL=index.d.mts.map