@qntx/wallet-engine 0.8.1 → 0.10.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.
@@ -1,10 +1,10 @@
1
- import { r as NetworkInfo } from "./registry-LcFSPrE1.mjs";
1
+ import { r as NetworkInfo } from "./registry-Deo5WQe1.mjs";
2
2
  import { StoreApi } from "zustand/vanilla";
3
- import { SignRequest } from "@qntx/wallet-chains";
3
+ import { MessageContent, SignRequest } from "@qntx/wallet-chains";
4
4
  import { NostrKeyRef, UnlockFactor, Wallet } from "@qntx/wallet";
5
+ import { decodeEvm } from "@qntx/wallet-chains/evm";
5
6
  import "@scure/btc-signer";
6
7
  import { CooperativeExitResult, LightningInvoice, LightningPayment, LightningSendStatus, SparkClient, SparkNetwork, SparkPayment, SparkStore, SparkTransfer } from "@qntx/spark";
7
- import { decodeEvm } from "@qntx/wallet-chains/evm";
8
8
  import { LnurlPayRequest, LnurlWithdrawRequest } from "@qntx/spark/lnurl";
9
9
  import { Event, NostrSigner, UnsignedEvent } from "@qntx/nostr";
10
10
  import { chains } from "@qntx/wallet/chains";
@@ -12,8 +12,8 @@ import { WalletSigner } from "@qntx/wallet/nostr";
12
12
  import { SparkSigner } from "@qntx/wallet/spark";
13
13
  import { PublicClient } from "viem";
14
14
  import "@solana/kit";
15
- import "@scure/btc-signer/psbt.js";
16
15
  import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
16
+ import "@scure/btc-signer/psbt.js";
17
17
  type ControllerOptions<S> = {
18
18
  readonly name: string;
19
19
  readonly defaultState: () => S;
@@ -57,172 +57,122 @@ type EngineStore = {
57
57
  readonly collection: (name: string) => EngineCollection;
58
58
  readonly close: () => Promise<void>;
59
59
  };
60
- type ConnectionOrigin = {
61
- readonly kind: "browser";
62
- readonly origin: string;
63
- };
64
- type ConnectionScope = {
65
- /** CAIP-10 */
66
- readonly accounts: ReadonlyArray<string>;
67
- readonly methods: ReadonlyArray<string>;
68
- readonly notifications: ReadonlyArray<string>;
69
- };
70
- type ConnectionSession = {
71
- readonly id: string;
72
- readonly origin: ConnectionOrigin;
73
- /** Keyed by CAIP-2. */
74
- readonly scopes: Readonly<Record<string, ConnectionScope>>;
75
- /** The session's current EVM network; only dApp sessions have one. */
76
- readonly currentNetwork: string;
77
- /** The origin's Nostr policy — set when the host approves a `nostr` connection. */
78
- readonly nostrPolicy?: NostrPolicy;
79
- /** The origin's Lightning policy — set when the host approves a `lightning` connection. */
80
- readonly lightningPolicy?: LightningPolicy;
81
- readonly createdAt: number;
82
- readonly lastUsedAt: number;
83
- };
84
60
  /**
85
- * How much a `nostr` session may do without per-call approval: `signing` is `"ask"` (every
86
- * `signEvent` goes through the pipeline), `"always"` (any kind signs directly), or a kind list (`{
87
- * kinds }` — only those kinds sign directly, the rest ask); `decrypt` gates `nip04/nip44 .decrypt`.
88
- * The four forced-confirm kinds `{0,3,5,10002}` always ask regardless.
61
+ * Non-secret device data (the phishing list, the origins the user trusts): available while the
62
+ * wallet is locked, and the host may keep it unencrypted. Never put anything secret in it.
89
63
  */
90
- type NostrPolicy = {
91
- readonly signing: "ask" | "always" | {
92
- readonly kinds: ReadonlyArray<number>;
93
- };
94
- readonly decrypt: boolean;
95
- };
96
- /**
97
- * How much a `lightning` session may do without per-call approval: `balance` gates `getBalance`
98
- * (WebLN). Sending and invoicing always go through their own approvals.
99
- */
100
- type LightningPolicy = {
101
- readonly balance: boolean;
64
+ type PublicStore = {
65
+ readonly get: (key: string) => Promise<Uint8Array | undefined>;
66
+ readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
102
67
  };
103
- /** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
104
- type PendingConnection = {
68
+ type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
69
+ type AddressBookEntry = {
105
70
  readonly id: string;
106
- readonly origin: ConnectionOrigin;
107
- readonly kind: "connect" | "network";
108
- /**
109
- * Which namespace the connection is for — `eip155` (EVM), `nostr` (NIP-07) or `lightning`
110
- * (WebLN).
111
- */
112
- readonly namespace: "eip155" | "nostr" | "lightning" | "solana";
113
- readonly network?: string;
71
+ readonly name: string;
72
+ readonly family: AddressFamily;
73
+ readonly address: string;
74
+ readonly note?: string;
114
75
  readonly createdAt: number;
76
+ readonly updatedAt: number;
115
77
  };
116
- type AccountGroup = {
117
- readonly walletId: string;
118
- readonly groupIndex: number;
78
+ type AddressBookTombstone = {
79
+ readonly id: string;
80
+ readonly deleted: true;
81
+ readonly updatedAt: number;
119
82
  };
120
- type ConnectionState = {
121
- readonly sessions: Readonly<Record<string, ConnectionSession>>;
122
- readonly pending: Readonly<Record<string, PendingConnection>>;
83
+ type AddressBookRecord = AddressBookEntry | AddressBookTombstone;
84
+ type AddressBookState = {
85
+ /** Live entries only; tombstones stay internal. */
86
+ readonly entries: Record<string, AddressBookEntry>;
123
87
  };
124
- type ConnectionControllerOptions = {
88
+ type AddressBookOptions = {
125
89
  readonly openStore: () => Promise<EngineStore>;
126
90
  readonly random: (n: number) => Uint8Array;
127
91
  readonly now: () => number;
128
92
  readonly logger: EngineLogger;
129
- /** Development builds also accept `http://localhost`. */
130
- readonly allowLocalhost: boolean;
131
- /** The group the app currently shows; sessions are bound to it. */
132
- readonly selectedGroup: () => AccountGroup | undefined;
133
- /** The group's EVM address on `network`. */
134
- readonly evmAddress: (group: AccountGroup, network: string) => Promise<string>;
135
- /** The group's Solana address on `network` (a CAIP-2 `solana:<genesis>` chain). */
136
- readonly solanaAddress: (group: AccountGroup, network: string) => Promise<string>;
137
- readonly enabledNetworks: () => ReadonlyArray<string>;
138
- /** A Nostr identity's public key — `nostr(wallet).signer(ref).getPublicKey()`. */
139
- readonly nostrPubkey: (ref: NostrKeyRef) => Promise<string>;
140
- /** Voids a page's unfinished requests (revoked, or its network changed). */
141
- readonly invalidate: (origin: string) => void;
142
93
  };
143
- declare class ConnectionController extends Controller<ConnectionState> {
94
+ declare class AddressBookController extends Controller<AddressBookState> {
144
95
  private readonly options;
145
96
  private engineStore;
146
- private readonly waiters;
147
- private group;
148
- private identity;
149
- constructor(options: ConnectionControllerOptions);
97
+ /** Every record, tombstones included, by id. */
98
+ private records;
99
+ constructor(options: AddressBookOptions);
150
100
  init(): Promise<void>;
151
101
  destroy(): Promise<void>;
152
- /** Locking is not consent: every pending connection is rejected. */
153
102
  lock(): void;
103
+ /** Entries and tombstones, for the metadata document. */
104
+ syncEntries(): ReadonlyArray<AddressBookRecord>;
154
105
  /**
155
- * A page navigated away (or the bridge is being disposed): the origin's pending connection
156
- * requests are rejected and its unfinished pipeline requests voided — the live session survives
157
- * (a refresh is not a revocation).
158
- */
159
- invalidateOrigin(origin: string): void;
160
- /** Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development). */
161
- checkOrigin(origin: string): ConnectionOrigin;
162
- session(origin: string): ConnectionSession | undefined;
163
- pending(): ReadonlyArray<PendingConnection>;
164
- /** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
165
- activeGroup(): AccountGroup | undefined;
166
- /** Whether `network` is an EVM network the wallet has enabled. */
167
- isEnabled(network: string): boolean;
168
- /** The origin's authorized addresses on its current network; empty when not connected. */
169
- accounts(origin: string): ReadonlyArray<string>;
170
- /** Throws `4100` unless the origin's session covers `method` on `network`. */
171
- authorize(origin: string, network: string, method: string): ConnectionSession;
172
- /** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
173
- request(origin: string, kind: PendingConnection["kind"], network?: string, namespace?: PendingConnection["namespace"]): Promise<ConnectionSession>;
174
- /**
175
- * The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
176
- * network.
177
- */
178
- approveConnection(id: string, grant: {
179
- readonly accounts: ReadonlyArray<string>;
180
- readonly network: string;
181
- /** The `nostr` namespace's grant: the identity's pubkey and the origin's policy. */
182
- readonly nostr?: {
183
- readonly pubkey: string;
184
- readonly policy: NostrPolicy;
185
- };
186
- /** The `lightning` namespace's grant: the origin's policy. */
187
- readonly lightning?: {
188
- readonly policy: LightningPolicy;
189
- };
190
- }): Promise<ConnectionSession>;
191
- rejectConnection(id: string): void;
192
- /** Ends the origin's session; its pending connection and unfinished requests are void. */
193
- revoke(origin: string): Promise<void>;
194
- /** Switches within the session's scope; the origin's unfinished requests are void. */
195
- setCurrentNetwork(origin: string, network: string): Promise<void>;
196
- touch(origin: string): Promise<void>;
197
- /**
198
- * The host switched account group: every session's accounts become the new group's addresses. A
199
- * session that cannot get one (no address derivable) is left with an empty list and has to be
200
- * authorized again.
201
- */
202
- setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
203
- /** The active Nostr identity — `undefined` until the host picks one. */
204
- activeIdentity(): NostrKeyRef | undefined;
205
- /** The origin's persisted Nostr policy — `undefined` until it is nostr-authorized. */
206
- nostrPolicy(origin: string): NostrPolicy | undefined;
207
- /** The origin's `nostr` namespace scope's pubkey, or `undefined` when not nostr-authorized. */
208
- nostrAccount(origin: string): string | undefined;
209
- /** The origin's persisted Lightning policy — `undefined` until it is lightning-authorized. */
210
- lightningPolicy(origin: string): LightningPolicy | undefined;
211
- /** The origin's `solana` scope's address on `network`, or `undefined` when not authorized. */
212
- solanaAccount(origin: string, network: string): string | undefined;
213
- /**
214
- * The host's Nostr identity selection: every authorized `nostr` session's account becomes the new
215
- * identity's pubkey (or empties when the identity is cleared). No event — NIP-07 has none.
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.
216
109
  */
217
- setActiveIdentity(ref: NostrKeyRef | undefined): Promise<void>;
218
- private dropPending;
110
+ merge(remote: ReadonlyArray<AddressBookRecord>): Promise<{
111
+ readonly changed: boolean;
112
+ readonly localNewer: boolean;
113
+ }>;
114
+ add(params: {
115
+ readonly name: string;
116
+ readonly family: AddressFamily;
117
+ readonly address: string;
118
+ readonly note?: string;
119
+ }): Promise<AddressBookEntry>;
120
+ rename(id: string, name: string): Promise<AddressBookEntry>;
121
+ /** Sets or clears (empty or `undefined`) the note. */
122
+ setNote(id: string, note: string | undefined): Promise<AddressBookEntry>;
123
+ /** Removes the entry, leaving a tombstone so other devices drop it too. */
124
+ remove(id: string): Promise<void>;
125
+ private checkedNote;
126
+ private requireEntry;
219
127
  private persist;
220
128
  private requireStore;
221
129
  }
130
+ /** A Sign In With Solana request after validation: `domain` and `address` are resolved. */
131
+ type SignInFields = {
132
+ readonly domain: string;
133
+ readonly address: string;
134
+ readonly statement?: string;
135
+ readonly uri?: string;
136
+ readonly version?: string;
137
+ readonly chainId?: string;
138
+ readonly nonce?: string;
139
+ readonly issuedAt?: string;
140
+ readonly expirationTime?: string;
141
+ readonly notBefore?: string;
142
+ readonly requestId?: string;
143
+ readonly resources?: ReadonlyArray<string>;
144
+ };
145
+ /** Simulation result shapes, in a leaf module so routes and the request controller share them. */
146
+ type AssetChange = {
147
+ /** Same ids as `DisplayIntent`: EVM `native` or a token address; Solana `lamports` or a mint. */
148
+ readonly asset: string;
149
+ /** Signed decimal in the smallest unit; negative is an outflow. */
150
+ readonly amount: string;
151
+ readonly decimals?: number;
152
+ readonly symbol?: string;
153
+ /** True only when `decimals` and `symbol` come from the built-in token table. */
154
+ readonly verified: boolean;
155
+ };
156
+ type SimulationOutcome = {
157
+ readonly status: "success";
158
+ readonly changes: ReadonlyArray<AssetChange>;
159
+ } | {
160
+ readonly status: "reverted";
161
+ readonly error: string;
162
+ } | {
163
+ readonly status: "unavailable";
164
+ readonly error: string;
165
+ };
166
+ type EvmFeeTier = "slow" | "normal" | "fast";
167
+ type SetTimer = (ms: number, fn: () => unknown) => () => void;
222
168
  type Esplora = {
223
169
  readonly get: (path: string) => Promise<unknown>;
224
170
  readonly post: (path: string, body: string) => Promise<unknown>;
225
171
  };
172
+ type GatewayConfig = {
173
+ readonly url: string;
174
+ readonly installId: string;
175
+ };
226
176
  type SolanaRpc = {
227
177
  readonly call: (method: string, params: unknown[]) => Promise<unknown>;
228
178
  };
@@ -242,31 +192,29 @@ type Independent<T> = {
242
192
  type NetworkControllerState = {
243
193
  readonly customRpc: Record<string, ReadonlyArray<string>>;
244
194
  };
245
- type Options$2 = {
195
+ type Options$3 = {
246
196
  readonly fetch: typeof globalThis.fetch;
247
197
  readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
248
198
  readonly openStore: () => Promise<EngineStore>;
249
199
  readonly logger: EngineLogger;
250
- readonly gateway?: {
251
- readonly url: string;
252
- readonly installId: string;
253
- } | undefined;
200
+ readonly gateway?: GatewayConfig | undefined;
201
+ readonly setTimer: SetTimer;
202
+ readonly random: (length: number) => Uint8Array;
254
203
  };
255
204
  declare class NetworkController extends Controller<NetworkControllerState> {
256
205
  private readonly options;
257
206
  private engineStore?;
258
207
  private readonly clients;
208
+ private readonly ensClients;
259
209
  private readonly gatewayBase;
260
- private readonly gatewayOrigin;
210
+ private readonly gatewayFetch;
261
211
  /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
262
212
  private gatewayServed;
263
- constructor(options: Options$2);
213
+ constructor(options: Options$3);
264
214
  init(): Promise<void>;
265
215
  private loadCustomRpc;
266
216
  /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
267
217
  private loadGatewayNetworks;
268
- /** `fetch` that adds the install id to requests bound for the gateway's origin only. */
269
- private readonly gatewayFetch;
270
218
  destroy(): Promise<void>;
271
219
  lock(): void;
272
220
  /**
@@ -281,6 +229,14 @@ declare class NetworkController extends Controller<NetworkControllerState> {
281
229
  private independent;
282
230
  /** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
283
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>;
284
240
  independentSolanaRpc(network: string): Independent<SolanaRpc>;
285
241
  independentEsplora(network: string): Independent<Esplora>;
286
242
  /** Networks with at least one configured endpoint or served by the gateway, by family. */
@@ -292,71 +248,8 @@ declare class NetworkController extends Controller<NetworkControllerState> {
292
248
  /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
293
249
  addRpc(network: string, url: string): Promise<void>;
294
250
  }
295
- type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
296
- type AddressBookEntry = {
297
- readonly id: string;
298
- readonly name: string;
299
- readonly family: AddressFamily;
300
- readonly address: string;
301
- readonly note?: string;
302
- readonly createdAt: number;
303
- readonly updatedAt: number;
304
- };
305
- type AddressBookTombstone = {
306
- readonly id: string;
307
- readonly deleted: true;
308
- readonly updatedAt: number;
309
- };
310
- type AddressBookRecord = AddressBookEntry | AddressBookTombstone;
311
- type AddressBookState = {
312
- /** Live entries only; tombstones stay internal. */
313
- readonly entries: Record<string, AddressBookEntry>;
314
- };
315
- type AddressBookOptions = {
316
- readonly openStore: () => Promise<EngineStore>;
317
- readonly random: (n: number) => Uint8Array;
318
- readonly now: () => number;
319
- readonly logger: EngineLogger;
320
- };
321
- declare class AddressBookController extends Controller<AddressBookState> {
322
- private readonly options;
323
- private engineStore;
324
- /** Every record, tombstones included, by id. */
325
- private records;
326
- constructor(options: AddressBookOptions);
327
- init(): Promise<void>;
328
- destroy(): Promise<void>;
329
- lock(): void;
330
- /** Entries and tombstones, for the metadata document. */
331
- syncEntries(): ReadonlyArray<AddressBookRecord>;
332
- /**
333
- * Merges records from another device (last writer wins, tombstones win over older entries).
334
- * Returns whether anything local changed and whether the merged set holds something `remote`
335
- * lacks, i.e. whether the remote copy needs a newer publish.
336
- */
337
- merge(remote: ReadonlyArray<AddressBookRecord>): Promise<{
338
- readonly changed: boolean;
339
- readonly localNewer: boolean;
340
- }>;
341
- add(params: {
342
- readonly name: string;
343
- readonly family: AddressFamily;
344
- readonly address: string;
345
- readonly note?: string;
346
- }): Promise<AddressBookEntry>;
347
- rename(id: string, name: string): Promise<AddressBookEntry>;
348
- /** Sets or clears (empty or `undefined`) the note. */
349
- setNote(id: string, note: string | undefined): Promise<AddressBookEntry>;
350
- /** Removes the entry, leaving a tombstone so other devices drop it too. */
351
- remove(id: string): Promise<void>;
352
- private checkedNote;
353
- private requireEntry;
354
- private persist;
355
- private requireStore;
356
- }
357
- type EvmFeeTier = "slow" | "normal" | "fast";
358
251
  type SolanaFeeTier = "slow" | "normal" | "fast";
359
- type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount";
252
+ type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount" | "simulation-unavailable";
360
253
  /**
361
254
  * Local, engine-side metadata pinned to a history entry by transfer id. Written after the payment
362
255
  * it annotates has already succeeded — a missing or malformed note must never affect the payment
@@ -413,6 +306,7 @@ type SparkControllerOptions = {
413
306
  readonly random: (length: number) => Uint8Array;
414
307
  readonly now: () => number;
415
308
  readonly logger: EngineLogger;
309
+ readonly setTimer: (ms: number, fn: () => void) => () => void;
416
310
  readonly createClient: SparkClientFactory;
417
311
  };
418
312
  declare class SparkController extends Controller<SparkControllerState> {
@@ -684,6 +578,54 @@ type PreparedZap = {
684
578
  };
685
579
  /** Everything up to payment: resolve LNURL, sign the 9734, request the invoice. */
686
580
  declare function prepareZap(params: PrepareZapParams, context: PrepareZapContext): Promise<PreparedZap>;
581
+ /**
582
+ * `blocked`: on the list. `trusted`: on the list, but the user trusts that origin. `clear`: not on
583
+ * the list, or not a web page. `unchecked`: no list has been loaded yet.
584
+ */
585
+ type PhishingStatus = "blocked" | "trusted" | "clear" | "unchecked";
586
+ declare const PHISHING_REFRESH_MS = 3600000;
587
+ type PhishingState = {
588
+ readonly version: number | null;
589
+ /** Last successful sync in this process, or the stored list's time after a restart. */
590
+ readonly updatedAt: number | null;
591
+ readonly trusted: ReadonlyArray<string>;
592
+ };
593
+ type PhishingControllerOptions = {
594
+ readonly publicStore: PublicStore;
595
+ readonly gateway?: GatewayConfig | undefined;
596
+ readonly fetch: typeof globalThis.fetch;
597
+ readonly now: () => number;
598
+ readonly setTimer: (ms: number, fn: () => void) => () => void;
599
+ readonly logger: EngineLogger;
600
+ };
601
+ declare class PhishingController extends Controller<PhishingState> {
602
+ private readonly options;
603
+ private readonly fetchGateway;
604
+ private deny;
605
+ private allow;
606
+ private inflight;
607
+ private abort;
608
+ private cancelTimer;
609
+ private epoch;
610
+ private destroyed;
611
+ constructor(options: PhishingControllerOptions);
612
+ init(): Promise<void>;
613
+ destroy(): Promise<void>;
614
+ check(url: string): PhishingStatus;
615
+ /** Fetches a snapshot or diff from the gateway; one request at a time, never throws. */
616
+ sync(): Promise<void>;
617
+ trust(origin: string): Promise<void>;
618
+ untrust(origin: string): Promise<void>;
619
+ private assertOrigin;
620
+ private saveTrusted;
621
+ private arm;
622
+ private refresh;
623
+ private load;
624
+ private restoreList;
625
+ private fetchAndApply;
626
+ private apply;
627
+ private persist;
628
+ }
687
629
  type ChainApis = ReturnType<typeof chains>;
688
630
  type SignParams = Parameters<ChainApis["sign"]>[0];
689
631
  type AccountRef = SignParams["request"]["account"];
@@ -713,6 +655,12 @@ type TrackedTransaction = {
713
655
  readonly parentId?: string;
714
656
  /** Set on a Spark deposit; `claimed` flips once the deposit is credited on Spark. */
715
657
  readonly sparkDeposit?: SparkDepositTag;
658
+ /** EVM build record persisted at broadcast for rebroadcast, drop detection and replacement. */
659
+ readonly evm?: {
660
+ readonly from: string;
661
+ readonly groupIndex: number;
662
+ readonly raw: string;
663
+ };
716
664
  /** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
717
665
  readonly btc?: {
718
666
  readonly inputs: ReadonlyArray<{
@@ -771,6 +719,10 @@ type PreparedRequest = {
771
719
  readonly target?: string;
772
720
  readonly intent: DisplayIntent;
773
721
  readonly checks: ReadonlyArray<RequestCheckCode>;
722
+ /** Absent when the request is not simulated (replacements, Bitcoin). */
723
+ readonly simulation?: SimulationOutcome;
724
+ /** Re-runs the same simulated call at approval; absent when there is nothing to re-run. */
725
+ readonly resimulate?: () => Promise<SimulationOutcome>;
774
726
  /** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
775
727
  readonly staleReason: () => string | undefined | Promise<string | undefined>;
776
728
  /** Signs, finalizes, broadcasts and hands the transaction to tracking. */
@@ -784,9 +736,11 @@ type SignatureResult = {
784
736
  };
785
737
  /** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
786
738
  type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
739
+ /** The address that will sign. */
740
+ readonly signer: string;
787
741
  readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
788
742
  };
789
- type Options$1 = {
743
+ type Options$2 = {
790
744
  readonly wallet: Wallet;
791
745
  readonly networks: NetworkController;
792
746
  readonly openStore: () => Promise<EngineStore>;
@@ -808,7 +762,7 @@ declare class TransactionController extends Controller<TransactionControllerStat
808
762
  private evmRoute;
809
763
  private bitcoinRoute;
810
764
  private locked;
811
- constructor(options: Options$1);
765
+ constructor(options: Options$2);
812
766
  init(): Promise<void>;
813
767
  destroy(): Promise<void>;
814
768
  lock(): void;
@@ -841,12 +795,13 @@ declare class TransactionController extends Controller<TransactionControllerStat
841
795
  private track;
842
796
  }
843
797
  /**
844
- * Recipient risk, pure: a recipient the wallet has never paid or saved is a `warning`; one that
845
- * looks like a known address (same first and last four characters, different address) is a `danger`
846
- * — the shape of an address-poisoning lookalike. Both can apply to one recipient.
798
+ * Request risk, pure. A recipient the wallet has never paid or saved is a `warning`; one that looks
799
+ * like a known address (same first and last four characters, different address) is a `danger` — the
800
+ * shape of an address-poisoning lookalike. Both can apply to one recipient. A page the user trusts
801
+ * despite the phishing list is a `danger`; one that could not be checked is a `warning`.
847
802
  */
848
803
  type RiskFinding = {
849
- readonly code: "first-recipient" | "address-poisoning";
804
+ 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" | "blind-signing";
850
805
  readonly level: "warning" | "danger";
851
806
  };
852
807
  /** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
@@ -857,20 +812,54 @@ type BrowserOrigin = {
857
812
  type RequestOrigin = {
858
813
  readonly kind: "internal";
859
814
  } | BrowserOrigin;
860
- type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "nostr-sign" | "webln-invoice" | "solana-sign" | "spark-deposit" | "spark-exit";
815
+ type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "nostr-sign" | "webln-invoice" | "watch-asset" | "solana-sign" | "bitcoin-sign" | "spark-deposit" | "spark-exit";
861
816
  /** A Solana chain account the `solana-sign` request signs for. */
862
817
  type SolanaAccount = {
863
818
  readonly walletId: string;
864
819
  readonly groupIndex: number;
865
820
  readonly address: string;
866
821
  };
822
+ /** A Bitcoin account the `bitcoin-sign` request signs for: the group's fixed dApp-facing address. */
823
+ type BitcoinAccount = {
824
+ readonly walletId: string;
825
+ readonly groupIndex: number;
826
+ readonly address: string;
827
+ /** `btc.bip84` for the `payment` purpose, `btc.bip86` for `ordinals`. */
828
+ readonly template: "btc.bip84" | "btc.bip86";
829
+ };
830
+ /** The sighash a dApp asks for per input; anything else is refused before it reaches a request. */
831
+ type BitcoinSigHash = "ALL" | "SINGLE|ANYONECANPAY";
832
+ /** One dApp PSBT and the inputs it asks the wallet to sign. */
833
+ type BitcoinPsbtInput = {
834
+ readonly psbt: Uint8Array;
835
+ readonly sign: ReadonlyArray<{
836
+ readonly index: number;
837
+ readonly sigHash: BitcoinSigHash;
838
+ }>;
839
+ };
840
+ /**
841
+ * A dApp PSBT after the engine enriched the requested inputs with this account's derivation data:
842
+ * `request` is what the kernel signs, `ownScripts` the scripts verified as the account's, `inputs`
843
+ * the signed inputs' prevout values and sighash (for risk).
844
+ */
845
+ type PreparedBitcoinPsbt = {
846
+ readonly request: Extract<SignRequest, {
847
+ kind: "bitcoin.psbt";
848
+ }>;
849
+ readonly ownScripts: ReadonlySet<string>;
850
+ readonly inputs: ReadonlyArray<{
851
+ readonly index: number;
852
+ readonly value: number;
853
+ readonly sigHash: BitcoinSigHash;
854
+ }>;
855
+ };
867
856
  type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
868
857
  type SignLogEntry = {
869
858
  readonly id: string;
870
859
  readonly at: number;
871
860
  readonly origin: RequestOrigin;
872
861
  readonly method: RequestMethod;
873
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount;
862
+ readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount;
874
863
  readonly network: string;
875
864
  readonly summary: string;
876
865
  readonly verification: "verified" | "unverifiable";
@@ -945,6 +934,17 @@ type WeblnInvoiceInput = {
945
934
  readonly amountSats: number;
946
935
  readonly memo?: string;
947
936
  };
937
+ /**
938
+ * A dApp's `wallet_watchAsset`: confirm adding an ERC-20 token to the tracked list. No factor;
939
+ * `symbol` and `decimals` are read on-chain by the pipeline, never taken from the page.
940
+ */
941
+ type WatchAssetInput = {
942
+ readonly method: "watch-asset";
943
+ readonly origin: BrowserOrigin;
944
+ readonly account: AccountRef;
945
+ readonly network: string;
946
+ readonly address: string;
947
+ };
948
948
  /**
949
949
  * A dApp's Solana request: one `solana-sign` covers a batch of transactions (signed sequentially —
950
950
  * each prompts) or a `solana.message` raw-message signature.
@@ -961,9 +961,29 @@ type SolanaSignInput = {
961
961
  } | {
962
962
  readonly kind: "message";
963
963
  readonly message: Uint8Array;
964
+ /** Set for a Sign In With Solana request; `message` is its text. */
965
+ readonly signIn?: SignInFields;
966
+ };
967
+ };
968
+ /**
969
+ * A dApp's Bitcoin request: a BIP-322 simple message signature, or a batch of PSBTs signed one
970
+ * after another under one approval (`send` also finalizes and broadcasts each).
971
+ */
972
+ type BitcoinSignInput = {
973
+ readonly method: "bitcoin-sign";
974
+ readonly origin: BrowserOrigin;
975
+ readonly account: BitcoinAccount;
976
+ readonly network: string;
977
+ readonly request: {
978
+ readonly kind: "message";
979
+ readonly message: string;
980
+ } | {
981
+ readonly kind: "psbt";
982
+ readonly psbts: ReadonlyArray<BitcoinPsbtInput>;
983
+ readonly send: boolean;
964
984
  };
965
985
  };
966
- type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | SolanaSignInput | SparkDepositInput | SparkExitInput;
986
+ type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | BitcoinSignInput | SparkDepositInput | SparkExitInput;
967
987
  /** `approve` of a `nostr-sign` request: the signed event. */
968
988
  type NostrSignResult = {
969
989
  readonly kind: "nostr.event";
@@ -987,6 +1007,9 @@ type SolanaDisplay = {
987
1007
  readonly send: boolean;
988
1008
  readonly count: number;
989
1009
  readonly transactions: ReadonlyArray<unknown>;
1010
+ /** A message request's content — text, or raw bytes when it is not UTF-8. */
1011
+ readonly message?: MessageContent;
1012
+ readonly signIn?: SignInFields;
990
1013
  };
991
1014
  /** `approve` of a `solana-sign` request: the signatures (or signed transactions) per input. */
992
1015
  type SolanaSignResult = {
@@ -998,6 +1021,38 @@ type SolanaSignResult = {
998
1021
  readonly kind: "solana.message";
999
1022
  readonly signature: Uint8Array;
1000
1023
  };
1024
+ /** `bitcoin-sign` display: the message text, or each PSBT's decode. */
1025
+ type BitcoinDisplay = {
1026
+ readonly kind: "bitcoin.sign";
1027
+ readonly message?: MessageContent;
1028
+ readonly psbts?: ReadonlyArray<DisplayIntent>;
1029
+ readonly send?: boolean;
1030
+ };
1031
+ /**
1032
+ * `approve` of a `bitcoin-sign` request: the BIP-322 simple signature (base64 of the witness), or
1033
+ * the signed PSBTs and, when sent, their txids.
1034
+ */
1035
+ type BitcoinSignResult = {
1036
+ readonly kind: "bitcoin.message";
1037
+ readonly signature: string;
1038
+ } | {
1039
+ readonly kind: "bitcoin.psbts";
1040
+ readonly signedPsbts: ReadonlyArray<Uint8Array>;
1041
+ readonly txids: ReadonlyArray<string>;
1042
+ };
1043
+ /** `approve` of a `watch-asset` request: the token was added. */
1044
+ type TokenWatchResult = {
1045
+ readonly kind: "token.watch";
1046
+ };
1047
+ /** `watch-asset` display: the token as read on-chain; `verified` means it is in the built-in table. */
1048
+ type TokenWatchDisplay = {
1049
+ readonly kind: "token.watch";
1050
+ readonly network: string;
1051
+ readonly address: string;
1052
+ readonly symbol: string;
1053
+ readonly decimals: number;
1054
+ readonly verified: boolean;
1055
+ };
1001
1056
  /** `webln-invoice` display: the requested amount and memo. */
1002
1057
  type LightningInvoiceDisplay = {
1003
1058
  readonly kind: "lightning.invoice";
@@ -1009,11 +1064,11 @@ type PendingRequest = {
1009
1064
  readonly id: string;
1010
1065
  readonly origin: RequestOrigin;
1011
1066
  readonly method: RequestMethod;
1012
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount;
1067
+ readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount;
1013
1068
  readonly network: string;
1014
1069
  readonly stage: RequestStage;
1015
1070
  /** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
1016
- readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | SolanaDisplay;
1071
+ readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay | BitcoinDisplay;
1017
1072
  /** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
1018
1073
  readonly verification: "verified" | "unverifiable";
1019
1074
  readonly checks: ReadonlyArray<RequestCheckCode>;
@@ -1022,6 +1077,10 @@ type PendingRequest = {
1022
1077
  * acknowledgement.
1023
1078
  */
1024
1079
  readonly risk: ReadonlyArray<RiskFinding>;
1080
+ /** Present for simulated requests: sends and dApp transactions; absent otherwise. */
1081
+ readonly simulation?: SimulationOutcome;
1082
+ /** When `simulation` was produced (ms); one older than {@link RESIMULATE_AFTER_MS} re-runs. */
1083
+ readonly simulatedAt?: number;
1025
1084
  readonly createdAt: number;
1026
1085
  readonly expiresAt: number;
1027
1086
  /** The transaction being replaced or accelerated; absent for a plain send. */
@@ -1046,15 +1105,41 @@ type RequestControllerOptions = {
1046
1105
  readonly logger: EngineLogger;
1047
1106
  /** Signs a Nostr event for `nostr-sign` — `nostr(wallet).signer(ref).signEvent`. */
1048
1107
  readonly nostrSign: (ref: NostrKeyRef, event: UnsignedEvent) => Promise<Event>;
1108
+ readonly phishing: Pick<PhishingController, "check">;
1109
+ /** Reads a token's metadata and adds it to the tracked list, for `watch-asset`. */
1110
+ readonly tokens: {
1111
+ readonly metadata: (network: string, address: string) => Promise<{
1112
+ readonly symbol: string;
1113
+ readonly decimals: number;
1114
+ }>;
1115
+ readonly add: (network: string, address: string) => Promise<void>;
1116
+ };
1117
+ /** Whether the account group opted in to signing messages that cannot be shown as text. */
1118
+ readonly blindSigning: (walletId: string, groupIndex: number) => boolean;
1119
+ /** Simulates one `solana-sign` transaction for display; failures are the caller's `unavailable`. */
1120
+ readonly simulateSolana: (account: SolanaAccount, network: string, message: Uint8Array) => Promise<SimulationOutcome>;
1049
1121
  /** Signs/broadcasts a `solana-sign` request — `chains.sign` per tx, then the Solana adapter. */
1050
1122
  readonly solanaSign: (account: {
1051
1123
  readonly walletId: string;
1052
1124
  readonly groupIndex: number;
1053
1125
  readonly address: string;
1054
1126
  }, network: string, request: SolanaSignInput["request"], verify: SendParams["verify"]) => Promise<SolanaSignResult>;
1127
+ /** Signs a `bitcoin-sign` message — `chains.sign` with the account's template. */
1128
+ readonly bitcoinSign: (account: BitcoinAccount, network: string, request: {
1129
+ readonly kind: "message";
1130
+ readonly message: string;
1131
+ }, verify: SendParams["verify"]) => Promise<BitcoinSignResult>;
1132
+ /** Adds the account's derivation data to a dApp's PSBTs; refuses inputs that are not its own. */
1133
+ readonly bitcoinPrepare: (account: BitcoinAccount, network: string, psbts: ReadonlyArray<BitcoinPsbtInput>) => Promise<ReadonlyArray<PreparedBitcoinPsbt>>;
1134
+ /** Signs (and with `send` broadcasts) the prepared PSBTs. */
1135
+ readonly bitcoinSignPsbts: (account: BitcoinAccount, network: string, prepared: ReadonlyArray<PreparedBitcoinPsbt>, send: boolean, verify: SendParams["verify"]) => Promise<BitcoinSignResult>;
1055
1136
  };
1056
1137
  /** Requests expire this long after creation. */
1057
1138
  declare const REQUEST_TTL_MS: number;
1139
+ /** A simulation older than this is re-run at approval before any signing. */
1140
+ declare const RESIMULATE_AFTER_MS = 60000;
1141
+ /** What an approved request resolves with, whichever kind it is. */
1142
+ type RequestResult = TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult | BitcoinSignResult;
1058
1143
  declare class RequestController extends Controller<RequestControllerState> {
1059
1144
  private readonly options;
1060
1145
  private readonly entries;
@@ -1080,12 +1165,13 @@ declare class RequestController extends Controller<RequestControllerState> {
1080
1165
  * Resolves with what `approve` returned, or rejects with `RequestEndedError` when the request
1081
1166
  * ends any other way — how a dApp's pending call learns the outcome.
1082
1167
  */
1083
- outcome(id: string): Promise<TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | SolanaSignResult>;
1168
+ outcome(id: string): Promise<RequestResult>;
1084
1169
  private openSettler;
1085
1170
  private settle;
1086
1171
  /** The bitcoin network `account`'s Spark network settles on; any other pairing is refused. */
1087
1172
  private l1Network;
1088
1173
  private sparkBuilt;
1174
+ private simulateOne;
1089
1175
  private build;
1090
1176
  /**
1091
1177
  * Signs and submits a request. Anything but a live, unexpired `send` request with this id throws
@@ -1096,7 +1182,9 @@ declare class RequestController extends Controller<RequestControllerState> {
1096
1182
  approve(id: string, method: "evm-sign", verify?: SendParams["verify"]): Promise<TrackedTransaction | SignatureResult>;
1097
1183
  approve(id: string, method: "nostr-sign"): Promise<NostrSignResult>;
1098
1184
  approve(id: string, method: "webln-invoice"): Promise<WeblnInvoiceResult>;
1185
+ approve(id: string, method: "watch-asset"): Promise<TokenWatchResult>;
1099
1186
  approve(id: string, method: "solana-sign", verify?: SendParams["verify"]): Promise<SolanaSignResult>;
1187
+ approve(id: string, method: "bitcoin-sign", verify?: SendParams["verify"]): Promise<BitcoinSignResult>;
1100
1188
  /**
1101
1189
  * A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
1102
1190
  * requests record which step failed on the tracked transaction; for Spark, the approval round is
@@ -1119,10 +1207,282 @@ declare class RequestController extends Controller<RequestControllerState> {
1119
1207
  * sends (Spark payments are not tracked).
1120
1208
  */
1121
1209
  private knownAddresses;
1210
+ /** A blind-sign request carries one danger; a group that did not opt in refuses it outright. */
1211
+ private blindRisk;
1212
+ /** Risk of a Sign-In with X message; a message for another domain throws `SignInOriginError`. */
1213
+ private signInRisk;
1122
1214
  private chainRisk;
1123
1215
  /** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
1124
1216
  private sparkRisk;
1125
1217
  }
1218
+ type ConnectionOrigin = {
1219
+ readonly kind: "browser";
1220
+ readonly origin: string;
1221
+ };
1222
+ type ConnectionScope = {
1223
+ /** CAIP-10 */
1224
+ readonly accounts: ReadonlyArray<string>;
1225
+ readonly methods: ReadonlyArray<string>;
1226
+ readonly notifications: ReadonlyArray<string>;
1227
+ };
1228
+ type ConnectionSession = {
1229
+ readonly id: string;
1230
+ readonly origin: ConnectionOrigin;
1231
+ /** Keyed by CAIP-2. */
1232
+ readonly scopes: Readonly<Record<string, ConnectionScope>>;
1233
+ /** The session's current EVM network; only dApp sessions have one. */
1234
+ readonly currentNetwork: string;
1235
+ /** The origin's Nostr policy — set when the host approves a `nostr` connection. */
1236
+ readonly nostrPolicy?: NostrPolicy;
1237
+ /** The origin's Lightning policy — set when the host approves a `lightning` connection. */
1238
+ readonly lightningPolicy?: LightningPolicy;
1239
+ readonly createdAt: number;
1240
+ readonly lastUsedAt: number;
1241
+ };
1242
+ /**
1243
+ * How much a `nostr` session may do without per-call approval: `signing` is `"ask"` (every
1244
+ * `signEvent` goes through the pipeline), `"always"` (any kind signs directly), or a kind list (`{
1245
+ * kinds }` — only those kinds sign directly, the rest ask); `decrypt` gates `nip04/nip44 .decrypt`.
1246
+ * The four forced-confirm kinds `{0,3,5,10002}` always ask regardless.
1247
+ */
1248
+ type NostrPolicy = {
1249
+ readonly signing: "ask" | "always" | {
1250
+ readonly kinds: ReadonlyArray<number>;
1251
+ };
1252
+ readonly decrypt: boolean;
1253
+ };
1254
+ /**
1255
+ * How much a `lightning` session may do without per-call approval: `balance` gates `getBalance`
1256
+ * (WebLN). Sending and invoicing always go through their own approvals.
1257
+ */
1258
+ type LightningPolicy = {
1259
+ readonly balance: boolean;
1260
+ };
1261
+ /** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
1262
+ type PendingConnection = {
1263
+ readonly id: string;
1264
+ readonly origin: ConnectionOrigin;
1265
+ readonly kind: "connect" | "network";
1266
+ /**
1267
+ * Which namespace the connection is for — `eip155` (EVM), `nostr` (NIP-07) or `lightning`
1268
+ * (WebLN).
1269
+ */
1270
+ readonly namespace: "eip155" | "nostr" | "lightning" | "solana" | "bip122";
1271
+ readonly network?: string;
1272
+ /** `false` for a `network` request that adds the network without making it current. */
1273
+ readonly activate?: boolean;
1274
+ readonly createdAt: number;
1275
+ };
1276
+ /** What a connection request asks for; `namespace` defaults to `eip155`, `activate` to `true`. */
1277
+ type ConnectionRequest = {
1278
+ readonly kind: PendingConnection["kind"];
1279
+ readonly namespace?: PendingConnection["namespace"];
1280
+ readonly network?: string;
1281
+ readonly activate?: boolean;
1282
+ };
1283
+ type AccountGroup = {
1284
+ readonly walletId: string;
1285
+ readonly groupIndex: number;
1286
+ };
1287
+ type ConnectionState = {
1288
+ readonly sessions: Readonly<Record<string, ConnectionSession>>;
1289
+ readonly pending: Readonly<Record<string, PendingConnection>>;
1290
+ };
1291
+ type ConnectionControllerOptions = {
1292
+ readonly openStore: () => Promise<EngineStore>;
1293
+ readonly random: (n: number) => Uint8Array;
1294
+ readonly now: () => number;
1295
+ readonly logger: EngineLogger;
1296
+ /** Development builds also accept `http://localhost`. */
1297
+ readonly allowLocalhost: boolean;
1298
+ /** The group the app currently shows; sessions are bound to it. */
1299
+ readonly selectedGroup: () => AccountGroup | undefined;
1300
+ /** The group's EVM address on `network`. */
1301
+ readonly evmAddress: (group: AccountGroup, network: string) => Promise<string>;
1302
+ /** The group's Solana address on `network` (a CAIP-2 `solana:<genesis>` chain). */
1303
+ readonly solanaAddress: (group: AccountGroup, network: string) => Promise<string>;
1304
+ /** The group's fixed dApp-facing Bitcoin address of `purpose` on `network` (`bip122:<genesis>`). */
1305
+ readonly bitcoinAddress: (group: AccountGroup, network: string, purpose: BitcoinPurpose) => Promise<string>;
1306
+ readonly enabledNetworks: () => ReadonlyArray<string>;
1307
+ /** A Nostr identity's public key — `nostr(wallet).signer(ref).getPublicKey()`. */
1308
+ readonly nostrPubkey: (ref: NostrKeyRef) => Promise<string>;
1309
+ /** Voids a page's unfinished requests (revoked, or its network changed). */
1310
+ readonly invalidate: (origin: string) => void;
1311
+ readonly phishing: Pick<PhishingController, "check">;
1312
+ readonly setTimer: (ms: number, fn: () => unknown) => () => void;
1313
+ };
1314
+ /** `payment` is the group's `btc.bip84` address, `ordinals` its `btc.bip86` one. */
1315
+ type BitcoinPurpose = "payment" | "ordinals";
1316
+ declare class ConnectionController extends Controller<ConnectionState> {
1317
+ private readonly options;
1318
+ private engineStore;
1319
+ private readonly waiters;
1320
+ private readonly expiries;
1321
+ private group;
1322
+ private identity;
1323
+ constructor(options: ConnectionControllerOptions);
1324
+ init(): Promise<void>;
1325
+ destroy(): Promise<void>;
1326
+ /** Locking is not consent: every pending connection is rejected. */
1327
+ lock(): void;
1328
+ /**
1329
+ * A page navigated away (or the bridge is being disposed): the origin's pending connection
1330
+ * requests are rejected and its unfinished pipeline requests voided — the live session survives
1331
+ * (a refresh is not a revocation).
1332
+ */
1333
+ invalidateOrigin(origin: string): void;
1334
+ /**
1335
+ * Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development) and not on
1336
+ * the phishing list.
1337
+ */
1338
+ checkOrigin(origin: string): ConnectionOrigin;
1339
+ session(origin: string): ConnectionSession | undefined;
1340
+ pending(): ReadonlyArray<PendingConnection>;
1341
+ /** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
1342
+ activeGroup(): AccountGroup | undefined;
1343
+ /** Whether `network` is an EVM network the wallet has enabled. */
1344
+ isEnabled(network: string): boolean;
1345
+ /** The origin's authorized addresses on its current network; empty when not connected. */
1346
+ accounts(origin: string): ReadonlyArray<string>;
1347
+ /** Throws `4100` unless the origin's session covers `method` on `network`. */
1348
+ authorize(origin: string, network: string, method: string): ConnectionSession;
1349
+ /** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
1350
+ request(origin: string, { kind, namespace, network, activate }: ConnectionRequest): Promise<ConnectionSession>;
1351
+ /**
1352
+ * The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
1353
+ * network.
1354
+ */
1355
+ approveConnection(id: string, grant: {
1356
+ readonly accounts: ReadonlyArray<string>;
1357
+ readonly network: string;
1358
+ /** The `nostr` namespace's grant: the identity's pubkey and the origin's policy. */
1359
+ readonly nostr?: {
1360
+ readonly pubkey: string;
1361
+ readonly policy: NostrPolicy;
1362
+ };
1363
+ /** The `lightning` namespace's grant: the origin's policy. */
1364
+ readonly lightning?: {
1365
+ readonly policy: LightningPolicy;
1366
+ };
1367
+ }): Promise<ConnectionSession>;
1368
+ rejectConnection(id: string): void;
1369
+ /** Ends the origin's session; its pending connection and unfinished requests are void. */
1370
+ revoke(origin: string): Promise<void>;
1371
+ /** Switches within the session's scope; the origin's unfinished requests are void. */
1372
+ setCurrentNetwork(origin: string, network: string): Promise<void>;
1373
+ touch(origin: string): Promise<void>;
1374
+ /**
1375
+ * The host switched account group: every session's accounts become the new group's addresses. A
1376
+ * session that cannot get one (no address derivable) is left with an empty list and has to be
1377
+ * authorized again.
1378
+ */
1379
+ setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
1380
+ /** The active Nostr identity — `undefined` until the host picks one. */
1381
+ activeIdentity(): NostrKeyRef | undefined;
1382
+ /** The origin's persisted Nostr policy — `undefined` until it is nostr-authorized. */
1383
+ nostrPolicy(origin: string): NostrPolicy | undefined;
1384
+ /** The origin's `nostr` namespace scope's pubkey, or `undefined` when not nostr-authorized. */
1385
+ nostrAccount(origin: string): string | undefined;
1386
+ /** The origin's persisted Lightning policy — `undefined` until it is lightning-authorized. */
1387
+ lightningPolicy(origin: string): LightningPolicy | undefined;
1388
+ /** The origin's `solana` scope's address on `network`, or `undefined` when not authorized. */
1389
+ solanaAccount(origin: string, network: string): string | undefined;
1390
+ /**
1391
+ * The origin's `bip122` scope accounts on `network`, in `BITCOIN_PURPOSES` order, or `undefined`
1392
+ * when not authorized.
1393
+ */
1394
+ bitcoinAccounts(origin: string, network: string): Record<BitcoinPurpose, string> | undefined;
1395
+ private bitcoinScope;
1396
+ /**
1397
+ * The host's Nostr identity selection: every authorized `nostr` session's account becomes the new
1398
+ * identity's pubkey (or empties when the identity is cleared). No event — NIP-07 has none.
1399
+ */
1400
+ setActiveIdentity(ref: NostrKeyRef | undefined): Promise<void>;
1401
+ private dropPending;
1402
+ private persist;
1403
+ private requireStore;
1404
+ }
1405
+ /**
1406
+ * The Bitcoin Wallet Standard (Exodus' `bitcoin:*` features, registered through
1407
+ * `@wallet-standard/wallet` like the Solana wallet) handler — the bridge routes `provider:
1408
+ * "bitcoin"` messages here.
1409
+ */
1410
+ type BitcoinRequest = {
1411
+ readonly method: string;
1412
+ readonly params?: unknown;
1413
+ };
1414
+ type BitcoinHandler = {
1415
+ readonly handle: (origin: string, request: BitcoinRequest) => Promise<unknown>;
1416
+ readonly subscribe: (listener: (event: BitcoinEvent) => void) => () => void;
1417
+ };
1418
+ /**
1419
+ * The Bitcoin Wallet Standard chain ids to the registry's CAIP-2 ids: `bitcoin:testnet` is the
1420
+ * registry's default test network (Testnet4 — the registry has no Testnet3).
1421
+ */
1422
+ declare const BITCOIN_CHAIN_IDS: Readonly<Record<string, string>>;
1423
+ /** The Wallet Standard `WalletAccount` shape `bitcoin:connect` returns per account. */
1424
+ type BitcoinWalletAccount = {
1425
+ readonly address: string;
1426
+ /** `payment`: the compressed key (33 bytes); `ordinals`: the x-only internal key (32 bytes). */
1427
+ readonly publicKey: Uint8Array;
1428
+ readonly chains: ReadonlyArray<string>;
1429
+ readonly features: ReadonlyArray<string>;
1430
+ };
1431
+ type BitcoinEvent = {
1432
+ readonly name: "bitcoinAccountsChanged";
1433
+ readonly origin: string;
1434
+ readonly accounts: ReadonlyArray<BitcoinWalletAccount>;
1435
+ };
1436
+ type BitcoinConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "bitcoinAccounts" | "request" | "touch" | "revoke" | "getState" | "store">;
1437
+ type BitcoinRequests = Pick<RequestController, "prepare" | "outcome">;
1438
+ type Options$1 = {
1439
+ readonly connections: BitcoinConnections;
1440
+ readonly requests: BitcoinRequests;
1441
+ /** The group's address and public key for `purpose` on `network` (receive chain, index 0). */
1442
+ readonly bitcoinAccount: (group: {
1443
+ readonly walletId: string;
1444
+ readonly groupIndex: number;
1445
+ }, network: string, purpose: BitcoinPurpose) => Promise<{
1446
+ readonly address: string;
1447
+ readonly publicKey: Uint8Array;
1448
+ }>;
1449
+ readonly activeGroup: () => {
1450
+ readonly walletId: string;
1451
+ readonly groupIndex: number;
1452
+ } | undefined;
1453
+ readonly bitcoinNetwork: () => string;
1454
+ };
1455
+ /**
1456
+ * The Bitcoin Wallet Standard handler: `bitcoin:connect` authorizes the `bip122` scope (both the
1457
+ * `payment` and the `ordinals` account) and returns the requested purposes in order;
1458
+ * `bitcoin:signMessage` goes through `bitcoin-sign` (BIP-322 simple); `bitcoinAccountsChanged`
1459
+ * carries the re-pointed accounts the bridge forwards as `bitcoin:events` `change` on a group
1460
+ * switch.
1461
+ */
1462
+ declare class BitcoinWalletHandler implements BitcoinHandler {
1463
+ readonly options: Options$1;
1464
+ private readonly events;
1465
+ constructor(options: Options$1);
1466
+ subscribe(listener: (event: BitcoinEvent) => void): () => void;
1467
+ handle(origin: string, request: BitcoinRequest): Promise<unknown>;
1468
+ private connect;
1469
+ private walletAccount;
1470
+ /**
1471
+ * Signs `message` (UTF-8 text only — `bitcoin.message` takes text, so there is no blind path) for
1472
+ * one of the session's accounts. The signature is the BIP-322 simple witness serialization
1473
+ * (witness item count, then each item length-prefixed) — the kernel's `smp` + base64 string
1474
+ * decoded to bytes, which is what MetaMask's Bitcoin Wallet Standard wallet hands out.
1475
+ */
1476
+ private signMessage;
1477
+ /**
1478
+ * Signs (and with `send` broadcasts) a batch of dApp PSBTs under one approval. Every account
1479
+ * named must be a session account of one purpose — a PSBT spending both payment and ordinals
1480
+ * inputs is not supported yet — and `chain`, when given, must be the session's network.
1481
+ */
1482
+ private signTransactions;
1483
+ /** The `setActiveGroup` re-point: the bitcoin session's new accounts, `payment` then `ordinals`. */
1484
+ bitcoinAccountsChanged(): Promise<BitcoinWalletAccount[]>;
1485
+ }
1126
1486
  type Eip1193Request = {
1127
1487
  readonly method: string;
1128
1488
  readonly params?: unknown;
@@ -1149,11 +1509,12 @@ type Eip1193HandlerOptions = {
1149
1509
  readonly networks: NetworkController;
1150
1510
  /** The network an unconnected page sees. */
1151
1511
  readonly defaultNetwork: () => string;
1512
+ /** Whether a token is already in the built-in table or the user's custom tokens. */
1513
+ readonly isTracked: (network: string, address: string) => boolean;
1152
1514
  };
1153
1515
  declare class Eip1193Handler {
1154
1516
  private readonly options;
1155
- private readonly listeners;
1156
- private unsubscribe;
1517
+ private readonly events;
1157
1518
  constructor(options: Eip1193HandlerOptions);
1158
1519
  /** Events for the host to forward to pages; derived from changes to the sessions. */
1159
1520
  subscribe(listener: (event: Eip1193Event) => void): () => void;
@@ -1161,6 +1522,13 @@ declare class Eip1193Handler {
1161
1522
  private requestAccounts;
1162
1523
  private permissions;
1163
1524
  private switchChain;
1525
+ /**
1526
+ * EIP-3085. The chain must already be a network the wallet enables; the page's `rpcUrls` are
1527
+ * validated for shape and never read or used — custom endpoints are the user's setting.
1528
+ */
1529
+ private addChain;
1530
+ /** EIP-747 (ERC-20 only): `symbol`, `decimals` and `image` from the page are never used. */
1531
+ private watchAsset;
1164
1532
  private authorizedAccount;
1165
1533
  private personalSign;
1166
1534
  private typedData;
@@ -1220,9 +1588,10 @@ type SolanaEvent = {
1220
1588
  readonly accounts: ReadonlyArray<SolanaWalletAccount>;
1221
1589
  };
1222
1590
  type SolanaConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "solanaAccount" | "request" | "touch" | "revoke" | "getState" | "store">;
1591
+ type SolanaRequests = Pick<RequestController, "prepare" | "outcome">;
1223
1592
  type Options = {
1224
1593
  readonly connections: SolanaConnections;
1225
- readonly requests: Pick<RequestController, "prepare" | "outcome">;
1594
+ readonly requests: SolanaRequests;
1226
1595
  /** The group's Solana address + public key on `network` (the `solana.bip44-change` account). */
1227
1596
  readonly solanaAccount: (group: {
1228
1597
  readonly walletId: string;
@@ -1244,8 +1613,7 @@ type Options = {
1244
1613
  */
1245
1614
  declare class SolanaWalletHandler implements SolanaHandler {
1246
1615
  readonly options: Options;
1247
- private readonly listeners;
1248
- private unsubscribe;
1616
+ private readonly events;
1249
1617
  constructor(options: Options);
1250
1618
  /** `standard:events` `change` per origin — derived from changes to the sessions. */
1251
1619
  subscribe(listener: (event: SolanaEvent) => void): () => void;
@@ -1253,7 +1621,20 @@ declare class SolanaWalletHandler implements SolanaHandler {
1253
1621
  private connect;
1254
1622
  private walletAccount;
1255
1623
  private signTransactions;
1624
+ /**
1625
+ * The network a transaction call targets: the wallet's default when no input names a chain,
1626
+ * otherwise the one chain every input agrees on (`chain` is required for sign-and-send).
1627
+ */
1628
+ private networkOf;
1256
1629
  private signMessage;
1630
+ /**
1631
+ * Sign In With Solana: connects first when needed, binds the message to the page's host and the
1632
+ * session's account, and signs the exact text the user is shown.
1633
+ */
1634
+ private signIn;
1635
+ private signMessageRequest;
1636
+ /** One `solana-sign` request for the active group, resolved to its outcome. */
1637
+ private signRequest;
1257
1638
  /** The `setActiveGroup` re-point: the solana session's new `WalletAccount[]` for `change`. */
1258
1639
  solanaAccountsChanged(_origin: string): Promise<SolanaWalletAccount[]>;
1259
1640
  }
@@ -1268,6 +1649,7 @@ type WeblnHandlerOptions = {
1268
1649
  readonly spark: Pick<SparkController, "accountBalance" | "paymentStatus">;
1269
1650
  /** The active group's Spark account — `undefined` when no group is selected. */
1270
1651
  readonly sparkAccount: () => SparkAccountRef | undefined;
1652
+ readonly now: () => number;
1271
1653
  /** The node's display alias — host-configured, never a pubkey. */
1272
1654
  readonly alias: string;
1273
1655
  /** The host's lightning fee cap — `pay`'s `maxFeeSats` comes from here. */
@@ -1292,5 +1674,5 @@ declare class ProviderError extends Error {
1292
1674
  readonly code: number;
1293
1675
  constructor(code: number, message: string);
1294
1676
  }
1295
- export { sparkStore as $, RiskFinding as A, ParseOptions as B, SparkDepositInput as C, Controller as Ct, BrowserOrigin as D, SignLogOutcome as E, PreparedZap as F, PreparedSparkAction as G, PaymentParse as H, ZapRecipient as I, SparkAccountState as J, SparkDisplay as K, prepareZap as L, SignatureResult as M, PrepareZapContext as N, RequestMethod as O, PrepareZapParams as P, SparkControllerState as Q, PayParams as R, RequestStage as S, createEventBus as St, SignLogEntry as T, PaymentRequest as U, PaymentOption as V, parsePayment as W, SparkController as X, SparkClientFactory as Y, SparkControllerOptions as Z, PendingRequest as _, PendingConnection as _t, SolanaEvent as a, AddressBookEntry as at, RequestControllerState as b, EngineLogger as bt, SolanaWalletAccount as c, NetworkController as ct, Nip07Request as d, ConnectionController as dt, PaymentNote as et, Eip1193Event as f, ConnectionOrigin as ft, PayInput as g, NostrPolicy as gt, EvmSignInput as h, ConnectionState as ht, SOLANA_CHAIN_IDS as i, AddressBookState as it, TransactionController as j, RequestOrigin as k, SolanaWalletHandler as l, Esplora as lt, Eip1193Request as m, ConnectionSession as mt, WeblnHandler as n, RequestCheckCode as nt, SolanaHandler as o, AddressBookRecord as ot, Eip1193Handler as p, ConnectionScope as pt, SparkResult as q, WeblnRequest as r, AddressBookController as rt, SolanaRequest as s, AddressFamily as st, ProviderError as t, SparkActivity as tt, Nip07Handler as u, AccountGroup as ut, REQUEST_TTL_MS as v, EngineCollection as vt, SparkExitInput as w, ControllerOptions as wt, RequestInput as x, EventBus as xt, RequestController as y, EngineStore as yt, WithdrawLnurlParams as z };
1296
- //# sourceMappingURL=errors-CW_XXGL9.d.mts.map
1677
+ export { PrepareZapContext as $, PayInput as A, EngineCollection as At, SignLogEntry as B, ConnectionOrigin as C, NetworkController as Ct, NostrPolicy as D, AddressBookEntry as Dt, ConnectionState as E, AddressBookState as Et, RequestControllerState as F, createEventBus as Ft, RiskFinding as G, BrowserOrigin as H, RequestInput as I, Controller as It, PHISHING_REFRESH_MS as J, TransactionController as K, RequestStage as L, ControllerOptions as Lt, REQUEST_TTL_MS as M, PublicStore as Mt, RESIMULATE_AFTER_MS as N, EngineLogger as Nt, PendingConnection as O, AddressBookRecord as Ot, RequestController as P, EventBus as Pt, PhishingStatus as Q, SparkDepositInput as R, ConnectionController as S, RequestCheckCode as St, ConnectionSession as T, AddressBookController as Tt, RequestMethod as U, SignLogOutcome as V, RequestOrigin as W, PhishingControllerOptions as X, PhishingController as Y, PhishingState as Z, BitcoinHandler as _, SparkControllerOptions as _t, SolanaEvent as a, WithdrawLnurlParams as at, BitcoinWalletHandler as b, PaymentNote as bt, SolanaWalletAccount as c, PaymentParse as ct, Nip07Request as d, PreparedSparkAction as dt, PrepareZapParams as et, Eip1193Event as f, SparkDisplay as ft, BitcoinEvent as g, SparkController as gt, BITCOIN_CHAIN_IDS as h, SparkClientFactory as ht, SOLANA_CHAIN_IDS as i, PayParams as it, PendingRequest as j, EngineStore as jt, EvmSignInput as k, AddressFamily as kt, SolanaWalletHandler as l, PaymentRequest as lt, Eip1193Request as m, SparkAccountState as mt, WeblnHandler as n, ZapRecipient as nt, SolanaHandler as o, ParseOptions as ot, Eip1193Handler as p, SparkResult as pt, SignatureResult as q, WeblnRequest as r, prepareZap as rt, SolanaRequest as s, PaymentOption as st, ProviderError as t, PreparedZap as tt, Nip07Handler as u, parsePayment as ut, BitcoinRequest as v, SparkControllerState as vt, ConnectionScope as w, Esplora as wt, AccountGroup as x, SparkActivity as xt, BitcoinWalletAccount as y, sparkStore as yt, SparkExitInput as z };
1678
+ //# sourceMappingURL=errors-Bglz0VYn.d.mts.map