@qntx/wallet-engine 0.9.0 → 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,6 +1,6 @@
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
5
  import { decodeEvm } from "@qntx/wallet-chains/evm";
6
6
  import "@scure/btc-signer";
@@ -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;
@@ -42,10 +42,6 @@ type EventBus<E> = {
42
42
  on: <K extends keyof E>(type: K, listener: (payload: E[K]) => void) => () => void;
43
43
  };
44
44
  declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
45
- type GatewayConfig = {
46
- readonly url: string;
47
- readonly installId: string;
48
- };
49
45
  /**
50
46
  * Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
51
47
  * the same collection object backs every call, so guards (closed) live on the store.
@@ -69,302 +65,6 @@ type PublicStore = {
69
65
  readonly get: (key: string) => Promise<Uint8Array | undefined>;
70
66
  readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
71
67
  };
72
- /**
73
- * `blocked`: on the list. `trusted`: on the list, but the user trusts that origin. `clear`: not on
74
- * the list, or not a web page. `unchecked`: no list has been loaded yet.
75
- */
76
- type PhishingStatus = "blocked" | "trusted" | "clear" | "unchecked";
77
- declare const PHISHING_REFRESH_MS = 3600000;
78
- type PhishingState = {
79
- readonly version: number | null;
80
- /** Last successful sync in this process, or the stored list's time after a restart. */
81
- readonly updatedAt: number | null;
82
- readonly trusted: ReadonlyArray<string>;
83
- };
84
- type PhishingControllerOptions = {
85
- readonly publicStore: PublicStore;
86
- readonly gateway?: GatewayConfig | undefined;
87
- readonly fetch: typeof globalThis.fetch;
88
- readonly now: () => number;
89
- readonly setTimer: (ms: number, fn: () => void) => () => void;
90
- readonly logger: EngineLogger;
91
- };
92
- declare class PhishingController extends Controller<PhishingState> {
93
- private readonly options;
94
- private readonly fetchGateway;
95
- private deny;
96
- private allow;
97
- private inflight;
98
- private abort;
99
- private cancelTimer;
100
- private epoch;
101
- private destroyed;
102
- constructor(options: PhishingControllerOptions);
103
- init(): Promise<void>;
104
- destroy(): Promise<void>;
105
- check(url: string): PhishingStatus;
106
- /** Fetches a snapshot or diff from the gateway; one request at a time, never throws. */
107
- sync(): Promise<void>;
108
- trust(origin: string): Promise<void>;
109
- untrust(origin: string): Promise<void>;
110
- private assertOrigin;
111
- private saveTrusted;
112
- private arm;
113
- private refresh;
114
- private load;
115
- private restoreList;
116
- private fetchAndApply;
117
- private apply;
118
- private persist;
119
- }
120
- type ConnectionOrigin = {
121
- readonly kind: "browser";
122
- readonly origin: string;
123
- };
124
- type ConnectionScope = {
125
- /** CAIP-10 */
126
- readonly accounts: ReadonlyArray<string>;
127
- readonly methods: ReadonlyArray<string>;
128
- readonly notifications: ReadonlyArray<string>;
129
- };
130
- type ConnectionSession = {
131
- readonly id: string;
132
- readonly origin: ConnectionOrigin;
133
- /** Keyed by CAIP-2. */
134
- readonly scopes: Readonly<Record<string, ConnectionScope>>;
135
- /** The session's current EVM network; only dApp sessions have one. */
136
- readonly currentNetwork: string;
137
- /** The origin's Nostr policy — set when the host approves a `nostr` connection. */
138
- readonly nostrPolicy?: NostrPolicy;
139
- /** The origin's Lightning policy — set when the host approves a `lightning` connection. */
140
- readonly lightningPolicy?: LightningPolicy;
141
- readonly createdAt: number;
142
- readonly lastUsedAt: number;
143
- };
144
- /**
145
- * How much a `nostr` session may do without per-call approval: `signing` is `"ask"` (every
146
- * `signEvent` goes through the pipeline), `"always"` (any kind signs directly), or a kind list (`{
147
- * kinds }` — only those kinds sign directly, the rest ask); `decrypt` gates `nip04/nip44 .decrypt`.
148
- * The four forced-confirm kinds `{0,3,5,10002}` always ask regardless.
149
- */
150
- type NostrPolicy = {
151
- readonly signing: "ask" | "always" | {
152
- readonly kinds: ReadonlyArray<number>;
153
- };
154
- readonly decrypt: boolean;
155
- };
156
- /**
157
- * How much a `lightning` session may do without per-call approval: `balance` gates `getBalance`
158
- * (WebLN). Sending and invoicing always go through their own approvals.
159
- */
160
- type LightningPolicy = {
161
- readonly balance: boolean;
162
- };
163
- /** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
164
- type PendingConnection = {
165
- readonly id: string;
166
- readonly origin: ConnectionOrigin;
167
- readonly kind: "connect" | "network";
168
- /**
169
- * Which namespace the connection is for — `eip155` (EVM), `nostr` (NIP-07) or `lightning`
170
- * (WebLN).
171
- */
172
- readonly namespace: "eip155" | "nostr" | "lightning" | "solana";
173
- readonly network?: string;
174
- /** `false` for a `network` request that adds the network without making it current. */
175
- readonly activate?: boolean;
176
- readonly createdAt: number;
177
- };
178
- /** What a connection request asks for; `namespace` defaults to `eip155`, `activate` to `true`. */
179
- type ConnectionRequest = {
180
- readonly kind: PendingConnection["kind"];
181
- readonly namespace?: PendingConnection["namespace"];
182
- readonly network?: string;
183
- readonly activate?: boolean;
184
- };
185
- type AccountGroup = {
186
- readonly walletId: string;
187
- readonly groupIndex: number;
188
- };
189
- type ConnectionState = {
190
- readonly sessions: Readonly<Record<string, ConnectionSession>>;
191
- readonly pending: Readonly<Record<string, PendingConnection>>;
192
- };
193
- type ConnectionControllerOptions = {
194
- readonly openStore: () => Promise<EngineStore>;
195
- readonly random: (n: number) => Uint8Array;
196
- readonly now: () => number;
197
- readonly logger: EngineLogger;
198
- /** Development builds also accept `http://localhost`. */
199
- readonly allowLocalhost: boolean;
200
- /** The group the app currently shows; sessions are bound to it. */
201
- readonly selectedGroup: () => AccountGroup | undefined;
202
- /** The group's EVM address on `network`. */
203
- readonly evmAddress: (group: AccountGroup, network: string) => Promise<string>;
204
- /** The group's Solana address on `network` (a CAIP-2 `solana:<genesis>` chain). */
205
- readonly solanaAddress: (group: AccountGroup, network: string) => Promise<string>;
206
- readonly enabledNetworks: () => ReadonlyArray<string>;
207
- /** A Nostr identity's public key — `nostr(wallet).signer(ref).getPublicKey()`. */
208
- readonly nostrPubkey: (ref: NostrKeyRef) => Promise<string>;
209
- /** Voids a page's unfinished requests (revoked, or its network changed). */
210
- readonly invalidate: (origin: string) => void;
211
- readonly phishing: Pick<PhishingController, "check">;
212
- readonly setTimer: (ms: number, fn: () => unknown) => () => void;
213
- };
214
- declare class ConnectionController extends Controller<ConnectionState> {
215
- private readonly options;
216
- private engineStore;
217
- private readonly waiters;
218
- private readonly expiries;
219
- private group;
220
- private identity;
221
- constructor(options: ConnectionControllerOptions);
222
- init(): Promise<void>;
223
- destroy(): Promise<void>;
224
- /** Locking is not consent: every pending connection is rejected. */
225
- lock(): void;
226
- /**
227
- * A page navigated away (or the bridge is being disposed): the origin's pending connection
228
- * requests are rejected and its unfinished pipeline requests voided — the live session survives
229
- * (a refresh is not a revocation).
230
- */
231
- invalidateOrigin(origin: string): void;
232
- /**
233
- * Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development) and not on
234
- * the phishing list.
235
- */
236
- checkOrigin(origin: string): ConnectionOrigin;
237
- session(origin: string): ConnectionSession | undefined;
238
- pending(): ReadonlyArray<PendingConnection>;
239
- /** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
240
- activeGroup(): AccountGroup | undefined;
241
- /** Whether `network` is an EVM network the wallet has enabled. */
242
- isEnabled(network: string): boolean;
243
- /** The origin's authorized addresses on its current network; empty when not connected. */
244
- accounts(origin: string): ReadonlyArray<string>;
245
- /** Throws `4100` unless the origin's session covers `method` on `network`. */
246
- authorize(origin: string, network: string, method: string): ConnectionSession;
247
- /** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
248
- request(origin: string, { kind, namespace, network, activate }: ConnectionRequest): Promise<ConnectionSession>;
249
- /**
250
- * The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
251
- * network.
252
- */
253
- approveConnection(id: string, grant: {
254
- readonly accounts: ReadonlyArray<string>;
255
- readonly network: string;
256
- /** The `nostr` namespace's grant: the identity's pubkey and the origin's policy. */
257
- readonly nostr?: {
258
- readonly pubkey: string;
259
- readonly policy: NostrPolicy;
260
- };
261
- /** The `lightning` namespace's grant: the origin's policy. */
262
- readonly lightning?: {
263
- readonly policy: LightningPolicy;
264
- };
265
- }): Promise<ConnectionSession>;
266
- rejectConnection(id: string): void;
267
- /** Ends the origin's session; its pending connection and unfinished requests are void. */
268
- revoke(origin: string): Promise<void>;
269
- /** Switches within the session's scope; the origin's unfinished requests are void. */
270
- setCurrentNetwork(origin: string, network: string): Promise<void>;
271
- touch(origin: string): Promise<void>;
272
- /**
273
- * The host switched account group: every session's accounts become the new group's addresses. A
274
- * session that cannot get one (no address derivable) is left with an empty list and has to be
275
- * authorized again.
276
- */
277
- setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
278
- /** The active Nostr identity — `undefined` until the host picks one. */
279
- activeIdentity(): NostrKeyRef | undefined;
280
- /** The origin's persisted Nostr policy — `undefined` until it is nostr-authorized. */
281
- nostrPolicy(origin: string): NostrPolicy | undefined;
282
- /** The origin's `nostr` namespace scope's pubkey, or `undefined` when not nostr-authorized. */
283
- nostrAccount(origin: string): string | undefined;
284
- /** The origin's persisted Lightning policy — `undefined` until it is lightning-authorized. */
285
- lightningPolicy(origin: string): LightningPolicy | undefined;
286
- /** The origin's `solana` scope's address on `network`, or `undefined` when not authorized. */
287
- solanaAccount(origin: string, network: string): string | undefined;
288
- /**
289
- * The host's Nostr identity selection: every authorized `nostr` session's account becomes the new
290
- * identity's pubkey (or empties when the identity is cleared). No event — NIP-07 has none.
291
- */
292
- setActiveIdentity(ref: NostrKeyRef | undefined): Promise<void>;
293
- private dropPending;
294
- private persist;
295
- private requireStore;
296
- }
297
- type SetTimer = (ms: number, fn: () => unknown) => () => void;
298
- type Esplora = {
299
- readonly get: (path: string) => Promise<unknown>;
300
- readonly post: (path: string, body: string) => Promise<unknown>;
301
- };
302
- type SolanaRpc = {
303
- readonly call: (method: string, params: unknown[]) => Promise<unknown>;
304
- };
305
- /**
306
- * A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
307
- * not this network's first endpoint, so the primary reads already come from the host.
308
- * `unavailable`: a cross-check is needed but the network has no host endpoint.
309
- */
310
- type Independent<T> = {
311
- readonly kind: "not-needed";
312
- } | {
313
- readonly kind: "unavailable";
314
- } | {
315
- readonly kind: "available";
316
- readonly client: T;
317
- };
318
- type NetworkControllerState = {
319
- readonly customRpc: Record<string, ReadonlyArray<string>>;
320
- };
321
- type Options$2 = {
322
- readonly fetch: typeof globalThis.fetch;
323
- readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
324
- readonly openStore: () => Promise<EngineStore>;
325
- readonly logger: EngineLogger;
326
- readonly gateway?: GatewayConfig | undefined;
327
- readonly setTimer: SetTimer;
328
- readonly random: (length: number) => Uint8Array;
329
- };
330
- declare class NetworkController extends Controller<NetworkControllerState> {
331
- private readonly options;
332
- private engineStore?;
333
- private readonly clients;
334
- private readonly gatewayBase;
335
- private readonly gatewayFetch;
336
- /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
337
- private gatewayServed;
338
- constructor(options: Options$2);
339
- init(): Promise<void>;
340
- private loadCustomRpc;
341
- /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
342
- private loadGatewayNetworks;
343
- destroy(): Promise<void>;
344
- lock(): void;
345
- /**
346
- * Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
347
- * otherwise a gateway-served network uses gateway → host; else host only.
348
- */
349
- endpoints(network: string): ReadonlyArray<string>;
350
- info(network: string): NetworkInfo;
351
- client(network: string): PublicClient;
352
- /** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
353
- private gatewayFirst;
354
- private independent;
355
- /** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
356
- independentClient(network: string): Independent<PublicClient>;
357
- independentSolanaRpc(network: string): Independent<SolanaRpc>;
358
- independentEsplora(network: string): Independent<Esplora>;
359
- /** Networks with at least one configured endpoint or served by the gateway, by family. */
360
- enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
361
- /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
362
- solanaRpc(network: string): SolanaRpc;
363
- /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
364
- esplora(network: string): Esplora;
365
- /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
366
- addRpc(network: string, url: string): Promise<void>;
367
- }
368
68
  type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
369
69
  type AddressBookEntry = {
370
70
  readonly id: string;
@@ -464,6 +164,90 @@ type SimulationOutcome = {
464
164
  readonly error: string;
465
165
  };
466
166
  type EvmFeeTier = "slow" | "normal" | "fast";
167
+ type SetTimer = (ms: number, fn: () => unknown) => () => void;
168
+ type Esplora = {
169
+ readonly get: (path: string) => Promise<unknown>;
170
+ readonly post: (path: string, body: string) => Promise<unknown>;
171
+ };
172
+ type GatewayConfig = {
173
+ readonly url: string;
174
+ readonly installId: string;
175
+ };
176
+ type SolanaRpc = {
177
+ readonly call: (method: string, params: unknown[]) => Promise<unknown>;
178
+ };
179
+ /**
180
+ * A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
181
+ * not this network's first endpoint, so the primary reads already come from the host.
182
+ * `unavailable`: a cross-check is needed but the network has no host endpoint.
183
+ */
184
+ type Independent<T> = {
185
+ readonly kind: "not-needed";
186
+ } | {
187
+ readonly kind: "unavailable";
188
+ } | {
189
+ readonly kind: "available";
190
+ readonly client: T;
191
+ };
192
+ type NetworkControllerState = {
193
+ readonly customRpc: Record<string, ReadonlyArray<string>>;
194
+ };
195
+ type Options$3 = {
196
+ readonly fetch: typeof globalThis.fetch;
197
+ readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
198
+ readonly openStore: () => Promise<EngineStore>;
199
+ readonly logger: EngineLogger;
200
+ readonly gateway?: GatewayConfig | undefined;
201
+ readonly setTimer: SetTimer;
202
+ readonly random: (length: number) => Uint8Array;
203
+ };
204
+ declare class NetworkController extends Controller<NetworkControllerState> {
205
+ private readonly options;
206
+ private engineStore?;
207
+ private readonly clients;
208
+ private readonly ensClients;
209
+ private readonly gatewayBase;
210
+ private readonly gatewayFetch;
211
+ /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
212
+ private gatewayServed;
213
+ constructor(options: Options$3);
214
+ init(): Promise<void>;
215
+ private loadCustomRpc;
216
+ /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
217
+ private loadGatewayNetworks;
218
+ destroy(): Promise<void>;
219
+ lock(): void;
220
+ /**
221
+ * Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
222
+ * otherwise a gateway-served network uses gateway → host; else host only.
223
+ */
224
+ endpoints(network: string): ReadonlyArray<string>;
225
+ info(network: string): NetworkInfo;
226
+ client(network: string): PublicClient;
227
+ /** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
228
+ private gatewayFirst;
229
+ private independent;
230
+ /** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
231
+ independentClient(network: string): Independent<PublicClient>;
232
+ /**
233
+ * The client's sibling for ENS resolution: same ordered endpoints, CCIP-Read enabled over the
234
+ * plain injected fetch — gateway URLs come from contracts, not the host, so they never get the
235
+ * install id.
236
+ */
237
+ ensClient(network: string): PublicClient;
238
+ /** Host-endpoint ENS client for cross-checking resolutions. */
239
+ independentEnsClient(network: string): Independent<PublicClient>;
240
+ independentSolanaRpc(network: string): Independent<SolanaRpc>;
241
+ independentEsplora(network: string): Independent<Esplora>;
242
+ /** Networks with at least one configured endpoint or served by the gateway, by family. */
243
+ enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
244
+ /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
245
+ solanaRpc(network: string): SolanaRpc;
246
+ /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
247
+ esplora(network: string): Esplora;
248
+ /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
249
+ addRpc(network: string, url: string): Promise<void>;
250
+ }
467
251
  type SolanaFeeTier = "slow" | "normal" | "fast";
468
252
  type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount" | "simulation-unavailable";
469
253
  /**
@@ -522,6 +306,7 @@ type SparkControllerOptions = {
522
306
  readonly random: (length: number) => Uint8Array;
523
307
  readonly now: () => number;
524
308
  readonly logger: EngineLogger;
309
+ readonly setTimer: (ms: number, fn: () => void) => () => void;
525
310
  readonly createClient: SparkClientFactory;
526
311
  };
527
312
  declare class SparkController extends Controller<SparkControllerState> {
@@ -793,6 +578,54 @@ type PreparedZap = {
793
578
  };
794
579
  /** Everything up to payment: resolve LNURL, sign the 9734, request the invoice. */
795
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
+ }
796
629
  type ChainApis = ReturnType<typeof chains>;
797
630
  type SignParams = Parameters<ChainApis["sign"]>[0];
798
631
  type AccountRef = SignParams["request"]["account"];
@@ -822,6 +655,12 @@ type TrackedTransaction = {
822
655
  readonly parentId?: string;
823
656
  /** Set on a Spark deposit; `claimed` flips once the deposit is credited on Spark. */
824
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
+ };
825
664
  /** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
826
665
  readonly btc?: {
827
666
  readonly inputs: ReadonlyArray<{
@@ -882,6 +721,8 @@ type PreparedRequest = {
882
721
  readonly checks: ReadonlyArray<RequestCheckCode>;
883
722
  /** Absent when the request is not simulated (replacements, Bitcoin). */
884
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>;
885
726
  /** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
886
727
  readonly staleReason: () => string | undefined | Promise<string | undefined>;
887
728
  /** Signs, finalizes, broadcasts and hands the transaction to tracking. */
@@ -895,9 +736,11 @@ type SignatureResult = {
895
736
  };
896
737
  /** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
897
738
  type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
739
+ /** The address that will sign. */
740
+ readonly signer: string;
898
741
  readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
899
742
  };
900
- type Options$1 = {
743
+ type Options$2 = {
901
744
  readonly wallet: Wallet;
902
745
  readonly networks: NetworkController;
903
746
  readonly openStore: () => Promise<EngineStore>;
@@ -919,7 +762,7 @@ declare class TransactionController extends Controller<TransactionControllerStat
919
762
  private evmRoute;
920
763
  private bitcoinRoute;
921
764
  private locked;
922
- constructor(options: Options$1);
765
+ constructor(options: Options$2);
923
766
  init(): Promise<void>;
924
767
  destroy(): Promise<void>;
925
768
  lock(): void;
@@ -958,7 +801,7 @@ declare class TransactionController extends Controller<TransactionControllerStat
958
801
  * despite the phishing list is a `danger`; one that could not be checked is a `warning`.
959
802
  */
960
803
  type RiskFinding = {
961
- readonly code: "first-recipient" | "address-poisoning" | "phishing-origin" | "phishing-unchecked" | "token-impersonation" | "token-symbol-unicode" | "simulation-reverted" | "simulation-mismatch";
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";
962
805
  readonly level: "warning" | "danger";
963
806
  };
964
807
  /** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
@@ -969,20 +812,54 @@ type BrowserOrigin = {
969
812
  type RequestOrigin = {
970
813
  readonly kind: "internal";
971
814
  } | BrowserOrigin;
972
- type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "nostr-sign" | "webln-invoice" | "watch-asset" | "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";
973
816
  /** A Solana chain account the `solana-sign` request signs for. */
974
817
  type SolanaAccount = {
975
818
  readonly walletId: string;
976
819
  readonly groupIndex: number;
977
820
  readonly address: string;
978
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
+ };
979
856
  type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
980
857
  type SignLogEntry = {
981
858
  readonly id: string;
982
859
  readonly at: number;
983
860
  readonly origin: RequestOrigin;
984
861
  readonly method: RequestMethod;
985
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount;
862
+ readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount;
986
863
  readonly network: string;
987
864
  readonly summary: string;
988
865
  readonly verification: "verified" | "unverifiable";
@@ -1088,7 +965,25 @@ type SolanaSignInput = {
1088
965
  readonly signIn?: SignInFields;
1089
966
  };
1090
967
  };
1091
- type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | SparkDepositInput | SparkExitInput;
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;
984
+ };
985
+ };
986
+ type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | BitcoinSignInput | SparkDepositInput | SparkExitInput;
1092
987
  /** `approve` of a `nostr-sign` request: the signed event. */
1093
988
  type NostrSignResult = {
1094
989
  readonly kind: "nostr.event";
@@ -1112,10 +1007,8 @@ type SolanaDisplay = {
1112
1007
  readonly send: boolean;
1113
1008
  readonly count: number;
1114
1009
  readonly transactions: ReadonlyArray<unknown>;
1115
- /** A message request's text (always valid UTF-8). */
1116
- readonly message?: {
1117
- readonly text: string;
1118
- };
1010
+ /** A message request's content — text, or raw bytes when it is not UTF-8. */
1011
+ readonly message?: MessageContent;
1119
1012
  readonly signIn?: SignInFields;
1120
1013
  };
1121
1014
  /** `approve` of a `solana-sign` request: the signatures (or signed transactions) per input. */
@@ -1128,6 +1021,25 @@ type SolanaSignResult = {
1128
1021
  readonly kind: "solana.message";
1129
1022
  readonly signature: Uint8Array;
1130
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
+ };
1131
1043
  /** `approve` of a `watch-asset` request: the token was added. */
1132
1044
  type TokenWatchResult = {
1133
1045
  readonly kind: "token.watch";
@@ -1152,11 +1064,11 @@ type PendingRequest = {
1152
1064
  readonly id: string;
1153
1065
  readonly origin: RequestOrigin;
1154
1066
  readonly method: RequestMethod;
1155
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount;
1067
+ readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount;
1156
1068
  readonly network: string;
1157
1069
  readonly stage: RequestStage;
1158
1070
  /** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
1159
- readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay;
1071
+ readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay | BitcoinDisplay;
1160
1072
  /** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
1161
1073
  readonly verification: "verified" | "unverifiable";
1162
1074
  readonly checks: ReadonlyArray<RequestCheckCode>;
@@ -1167,6 +1079,8 @@ type PendingRequest = {
1167
1079
  readonly risk: ReadonlyArray<RiskFinding>;
1168
1080
  /** Present for simulated requests: sends and dApp transactions; absent otherwise. */
1169
1081
  readonly simulation?: SimulationOutcome;
1082
+ /** When `simulation` was produced (ms); one older than {@link RESIMULATE_AFTER_MS} re-runs. */
1083
+ readonly simulatedAt?: number;
1170
1084
  readonly createdAt: number;
1171
1085
  readonly expiresAt: number;
1172
1086
  /** The transaction being replaced or accelerated; absent for a plain send. */
@@ -1200,6 +1114,8 @@ type RequestControllerOptions = {
1200
1114
  }>;
1201
1115
  readonly add: (network: string, address: string) => Promise<void>;
1202
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;
1203
1119
  /** Simulates one `solana-sign` transaction for display; failures are the caller's `unavailable`. */
1204
1120
  readonly simulateSolana: (account: SolanaAccount, network: string, message: Uint8Array) => Promise<SimulationOutcome>;
1205
1121
  /** Signs/broadcasts a `solana-sign` request — `chains.sign` per tx, then the Solana adapter. */
@@ -1208,11 +1124,22 @@ type RequestControllerOptions = {
1208
1124
  readonly groupIndex: number;
1209
1125
  readonly address: string;
1210
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>;
1211
1136
  };
1212
1137
  /** Requests expire this long after creation. */
1213
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;
1214
1141
  /** What an approved request resolves with, whichever kind it is. */
1215
- type RequestResult = TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult;
1142
+ type RequestResult = TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult | BitcoinSignResult;
1216
1143
  declare class RequestController extends Controller<RequestControllerState> {
1217
1144
  private readonly options;
1218
1145
  private readonly entries;
@@ -1257,6 +1184,7 @@ declare class RequestController extends Controller<RequestControllerState> {
1257
1184
  approve(id: string, method: "webln-invoice"): Promise<WeblnInvoiceResult>;
1258
1185
  approve(id: string, method: "watch-asset"): Promise<TokenWatchResult>;
1259
1186
  approve(id: string, method: "solana-sign", verify?: SendParams["verify"]): Promise<SolanaSignResult>;
1187
+ approve(id: string, method: "bitcoin-sign", verify?: SendParams["verify"]): Promise<BitcoinSignResult>;
1260
1188
  /**
1261
1189
  * A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
1262
1190
  * requests record which step failed on the tracked transaction; for Spark, the approval round is
@@ -1279,10 +1207,282 @@ declare class RequestController extends Controller<RequestControllerState> {
1279
1207
  * sends (Spark payments are not tracked).
1280
1208
  */
1281
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;
1282
1214
  private chainRisk;
1283
1215
  /** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
1284
1216
  private sparkRisk;
1285
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
+ }
1286
1486
  type Eip1193Request = {
1287
1487
  readonly method: string;
1288
1488
  readonly params?: unknown;
@@ -1474,5 +1674,5 @@ declare class ProviderError extends Error {
1474
1674
  readonly code: number;
1475
1675
  constructor(code: number, message: string);
1476
1676
  }
1477
- export { sparkStore as $, RiskFinding as A, ControllerOptions as At, ParseOptions as B, SparkDepositInput as C, EngineCollection as Ct, BrowserOrigin as D, EventBus as Dt, SignLogOutcome as E, EngineLogger as Et, 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, createEventBus as Ot, PrepareZapParams as P, SparkControllerState as Q, PayParams as R, RequestStage as S, PhishingStatus as St, SignLogEntry as T, PublicStore as Tt, 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, PhishingControllerOptions 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, Controller as kt, 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, PHISHING_REFRESH_MS as vt, SparkExitInput as w, EngineStore as wt, RequestInput as x, PhishingState as xt, RequestController as y, PhishingController as yt, WithdrawLnurlParams as z };
1478
- //# sourceMappingURL=errors-CP1G6KCc.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