@qntx/wallet-engine 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +1057 -20
  2. package/dist/apps-fiat24.d.mts +202 -0
  3. package/dist/apps-fiat24.mjs +1378 -0
  4. package/dist/apps-fiat24.mjs.map +1 -0
  5. package/dist/apps-hyperliquid.d.mts +549 -0
  6. package/dist/apps-hyperliquid.mjs +2742 -0
  7. package/dist/apps-hyperliquid.mjs.map +1 -0
  8. package/dist/apps-polymarket.d.mts +729 -0
  9. package/dist/apps-polymarket.mjs +3786 -0
  10. package/dist/apps-polymarket.mjs.map +1 -0
  11. package/dist/apps.d.mts +136 -0
  12. package/dist/apps.mjs +535 -0
  13. package/dist/apps.mjs.map +1 -0
  14. package/dist/connect-BY1C5ZRI.mjs +210 -0
  15. package/dist/connect-BY1C5ZRI.mjs.map +1 -0
  16. package/dist/connect.d.mts +17 -9
  17. package/dist/connect.mjs +3 -185
  18. package/dist/controller-DpNVHVsj.d.mts +2295 -0
  19. package/dist/controller-rMnaxKAH.mjs +46 -0
  20. package/dist/controller-rMnaxKAH.mjs.map +1 -0
  21. package/dist/decimal-COJ4g8qy.mjs +38 -0
  22. package/dist/decimal-COJ4g8qy.mjs.map +1 -0
  23. package/dist/eligibility-BfM9ybYZ.mjs +48 -0
  24. package/dist/eligibility-BfM9ybYZ.mjs.map +1 -0
  25. package/dist/engine-Dic_kkEr.d.mts +1829 -0
  26. package/dist/errors-B8W-hoYW.d.mts +7 -0
  27. package/dist/errors-horUy5k1.mjs +24 -0
  28. package/dist/errors-horUy5k1.mjs.map +1 -0
  29. package/dist/gateway-contract.d.mts +3 -362
  30. package/dist/gateway-contract.mjs +1531 -81
  31. package/dist/gateway-contract.mjs.map +1 -1
  32. package/dist/idb.d.mts +5 -0
  33. package/dist/idb.mjs +122 -46
  34. package/dist/idb.mjs.map +1 -1
  35. package/dist/index-vBgfOFIh.d.mts +2227 -0
  36. package/dist/index.d.mts +58 -515
  37. package/dist/index.mjs +22314 -4901
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/json-BDwV38cj.mjs +15 -0
  40. package/dist/json-BDwV38cj.mjs.map +1 -0
  41. package/dist/link-Ceq8Dggp.mjs +139 -0
  42. package/dist/link-Ceq8Dggp.mjs.map +1 -0
  43. package/dist/primitives-DbSHLZKq.mjs +31 -0
  44. package/dist/primitives-DbSHLZKq.mjs.map +1 -0
  45. package/dist/push-message-AQuzoNFY.d.mts +84 -0
  46. package/dist/push-message-kbnH1A5w.mjs +142 -0
  47. package/dist/push-message-kbnH1A5w.mjs.map +1 -0
  48. package/dist/push.d.mts +13 -0
  49. package/dist/push.mjs +70 -0
  50. package/dist/push.mjs.map +1 -0
  51. package/dist/qr.d.mts +292 -0
  52. package/dist/qr.mjs +1725 -0
  53. package/dist/qr.mjs.map +1 -0
  54. package/dist/registry-CbtwcxkX.mjs +374 -0
  55. package/dist/registry-CbtwcxkX.mjs.map +1 -0
  56. package/dist/risk-DyABgg4W.mjs +757 -0
  57. package/dist/risk-DyABgg4W.mjs.map +1 -0
  58. package/dist/session-CNJFLarP.mjs +18 -0
  59. package/dist/session-CNJFLarP.mjs.map +1 -0
  60. package/dist/socket-ChG9JRT_.mjs +110 -0
  61. package/dist/socket-ChG9JRT_.mjs.map +1 -0
  62. package/dist/spi-BrTw5s98.d.mts +3 -0
  63. package/dist/timer-Cdk5rGM2.mjs +43 -0
  64. package/dist/timer-Cdk5rGM2.mjs.map +1 -0
  65. package/dist/types-BpvioFGo.d.mts +258 -0
  66. package/dist/types-DbftVZ3I.mjs +90 -0
  67. package/dist/types-DbftVZ3I.mjs.map +1 -0
  68. package/dist/walletconnect.d.mts +86 -0
  69. package/dist/walletconnect.mjs +1507 -0
  70. package/dist/walletconnect.mjs.map +1 -0
  71. package/dist/webln-BgrtPXpG.mjs +2593 -0
  72. package/dist/webln-BgrtPXpG.mjs.map +1 -0
  73. package/dist/webln-Bllk_xJ2.d.mts +666 -0
  74. package/package.json +94 -19
  75. package/dist/connect.mjs.map +0 -1
  76. package/dist/errors-DpkJneDe.d.mts +0 -1696
  77. package/dist/registry-Deo5WQe1.d.mts +0 -25
  78. package/dist/registry-wYrcuFNc.mjs +0 -99
  79. package/dist/registry-wYrcuFNc.mjs.map +0 -1
  80. package/dist/webln-DzsI7jVb.mjs +0 -3629
  81. package/dist/webln-DzsI7jVb.mjs.map +0 -1
@@ -1,1696 +0,0 @@
1
- import { r as NetworkInfo } from "./registry-Deo5WQe1.mjs";
2
- import { StoreApi } from "zustand/vanilla";
3
- import { MessageContent, SignRequest } from "@qntx/wallet-chains";
4
- import { NostrKeyRef, UnlockFactor, Wallet } from "@qntx/wallet";
5
- import { decodeEvm } from "@qntx/wallet-chains/evm";
6
- import "@scure/btc-signer";
7
- import { CooperativeExitResult, LightningInvoice, LightningPayment, LightningSendStatus, SparkClient, SparkNetwork, SparkPayment, SparkStore, SparkTransfer } from "@qntx/spark";
8
- import { LnurlPayRequest, LnurlWithdrawRequest } from "@qntx/spark/lnurl";
9
- import { Event, NostrSigner, UnsignedEvent } from "@qntx/nostr";
10
- import { chains } from "@qntx/wallet/chains";
11
- import { WalletSigner } from "@qntx/wallet/nostr";
12
- import { SparkSigner } from "@qntx/wallet/spark";
13
- import { PublicClient } from "viem";
14
- import "@solana/kit";
15
- import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
16
- import "@scure/btc-signer/psbt.js";
17
- type ControllerOptions<S> = {
18
- readonly name: string;
19
- readonly defaultState: () => S;
20
- };
21
- /**
22
- * Controller base: a zustand vanilla store plus lifecycle. `update` applies a recipe that must
23
- * return a NEW state object; returning the same reference is a no-op (no set, no notification).
24
- * Persistence and migrations layer on later — this package carries only what its first user needs.
25
- */
26
- declare abstract class Controller<S extends Record<string, unknown>> {
27
- readonly name: string;
28
- readonly store: StoreApi<S>;
29
- protected constructor(options: ControllerOptions<S>);
30
- getState(): S;
31
- protected update(recipe: (state: S) => S): void;
32
- abstract init(): Promise<void>;
33
- abstract destroy(): Promise<void>;
34
- }
35
- /** Log port: listener failures are reported here and never reach the emitter or peers. */
36
- type EngineLogger = {
37
- readonly warn: (message: string, error?: unknown) => void;
38
- };
39
- type EventBus<E> = {
40
- /** Synchronous dispatch to every current listener in registration order. */
41
- emit: <K extends keyof E>(type: K, payload: E[K]) => void;
42
- on: <K extends keyof E>(type: K, listener: (payload: E[K]) => void) => () => void;
43
- };
44
- declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
45
- /**
46
- * Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
47
- * the same collection object backs every call, so guards (closed) live on the store.
48
- */
49
- type EngineCollection = {
50
- readonly get: (key: string) => Promise<Uint8Array | undefined>;
51
- readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
52
- readonly delete: (key: string) => Promise<void>;
53
- /** Every key in the collection, in an unspecified order. */
54
- readonly list: () => Promise<ReadonlyArray<string>>;
55
- };
56
- type EngineStore = {
57
- readonly collection: (name: string) => EngineCollection;
58
- readonly close: () => Promise<void>;
59
- };
60
- /**
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.
63
- */
64
- type PublicStore = {
65
- readonly get: (key: string) => Promise<Uint8Array | undefined>;
66
- readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
67
- };
68
- type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
69
- type AddressBookEntry = {
70
- readonly id: string;
71
- readonly name: string;
72
- readonly family: AddressFamily;
73
- readonly address: string;
74
- readonly note?: string;
75
- readonly createdAt: number;
76
- readonly updatedAt: number;
77
- };
78
- type AddressBookTombstone = {
79
- readonly id: string;
80
- readonly deleted: true;
81
- readonly updatedAt: number;
82
- };
83
- type AddressBookRecord = AddressBookEntry | AddressBookTombstone;
84
- type AddressBookState = {
85
- /** Live entries only; tombstones stay internal. */
86
- readonly entries: Record<string, AddressBookEntry>;
87
- };
88
- type AddressBookOptions = {
89
- readonly openStore: () => Promise<EngineStore>;
90
- readonly random: (n: number) => Uint8Array;
91
- readonly now: () => number;
92
- readonly logger: EngineLogger;
93
- };
94
- declare class AddressBookController extends Controller<AddressBookState> {
95
- private readonly options;
96
- private engineStore;
97
- /** Every record, tombstones included, by id. */
98
- private records;
99
- constructor(options: AddressBookOptions);
100
- init(): Promise<void>;
101
- destroy(): Promise<void>;
102
- lock(): void;
103
- /** Entries and tombstones, for the metadata document. */
104
- syncEntries(): ReadonlyArray<AddressBookRecord>;
105
- /**
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.
109
- */
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;
127
- private persist;
128
- private requireStore;
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;
168
- type Esplora = {
169
- readonly get: (path: string) => Promise<unknown>;
170
- readonly post: (path: string, body: string) => Promise<unknown>;
171
- };
172
- type GatewayConfig = {
173
- readonly url: string;
174
- readonly installId: string;
175
- };
176
- type SolanaRpc = {
177
- readonly call: (method: string, params: unknown[]) => Promise<unknown>;
178
- };
179
- /**
180
- * A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
181
- * not this network's first endpoint, so the primary reads already come from the host.
182
- * `unavailable`: a cross-check is needed but the network has no host endpoint.
183
- */
184
- type Independent<T> = {
185
- readonly kind: "not-needed";
186
- } | {
187
- readonly kind: "unavailable";
188
- } | {
189
- readonly kind: "available";
190
- readonly client: T;
191
- };
192
- type NetworkControllerState = {
193
- readonly customRpc: Record<string, ReadonlyArray<string>>;
194
- };
195
- type Options$3 = {
196
- readonly fetch: typeof globalThis.fetch;
197
- readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
198
- readonly openStore: () => Promise<EngineStore>;
199
- readonly logger: EngineLogger;
200
- readonly gateway?: GatewayConfig | undefined;
201
- readonly setTimer: SetTimer;
202
- readonly random: (length: number) => Uint8Array;
203
- };
204
- declare class NetworkController extends Controller<NetworkControllerState> {
205
- private readonly options;
206
- private engineStore?;
207
- private readonly clients;
208
- private readonly ensClients;
209
- private readonly gatewayBase;
210
- private readonly gatewayFetch;
211
- /** Networks the gateway reported at unlock; empty while locked or when the read failed. */
212
- private gatewayServed;
213
- constructor(options: Options$3);
214
- init(): Promise<void>;
215
- private loadCustomRpc;
216
- /** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
217
- private loadGatewayNetworks;
218
- destroy(): Promise<void>;
219
- lock(): void;
220
- /**
221
- * Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
222
- * otherwise a gateway-served network uses gateway → host; else host only.
223
- */
224
- endpoints(network: string): ReadonlyArray<string>;
225
- info(network: string): NetworkInfo;
226
- client(network: string): PublicClient;
227
- /** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
228
- private gatewayFirst;
229
- private independent;
230
- /** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
231
- independentClient(network: string): Independent<PublicClient>;
232
- /**
233
- * The client's sibling for ENS resolution: same ordered endpoints, CCIP-Read enabled over the
234
- * plain injected fetch — gateway URLs come from contracts, not the host, so they never get the
235
- * install id.
236
- */
237
- ensClient(network: string): PublicClient;
238
- /** Host-endpoint ENS client for cross-checking resolutions. */
239
- independentEnsClient(network: string): Independent<PublicClient>;
240
- independentSolanaRpc(network: string): Independent<SolanaRpc>;
241
- independentEsplora(network: string): Independent<Esplora>;
242
- /** Networks with at least one configured endpoint or served by the gateway, by family. */
243
- enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
244
- /** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
245
- solanaRpc(network: string): SolanaRpc;
246
- /** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
247
- esplora(network: string): Esplora;
248
- /** Validate a custom endpoint's reported chain id, then persist it first in the list. */
249
- addRpc(network: string, url: string): Promise<void>;
250
- }
251
- type SolanaFeeTier = "slow" | "normal" | "fast";
252
- type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount" | "simulation-unavailable";
253
- /**
254
- * Local, engine-side metadata pinned to a history entry by transfer id. Written after the payment
255
- * it annotates has already succeeded — a missing or malformed note must never affect the payment
256
- * itself.
257
- */
258
- type PaymentNote = {
259
- readonly kind: "zap";
260
- /** 64 lowercase hex. */
261
- readonly recipientPubkey: string;
262
- /** 64 lowercase hex — event zaps carry the zapped event's id. */
263
- readonly eventId?: string;
264
- /** At most 2000 characters. */
265
- readonly comment?: string;
266
- /** The lud16 or LNURL the zap resolved. */
267
- readonly lightning: string;
268
- };
269
- type SparkActivity = SparkPayment & {
270
- readonly note?: PaymentNote;
271
- };
272
- /**
273
- * SparkStore over one EngineCollection: chains keyed by leafId, plus an index record listing them
274
- * (`exitChains` is a full listing — the port has no secondary index).
275
- */
276
- declare function sparkStore(col: EngineCollection): SparkStore;
277
- type SparkAccountState = {
278
- readonly status: "locked" | "connecting" | "ready" | "error";
279
- readonly balanceSats?: number;
280
- readonly identityPublicKey?: string;
281
- readonly sparkAddress?: string;
282
- readonly errorCategory?: string;
283
- /** First history page (20 entries, newest first), refreshed alongside the balance. */
284
- readonly recent?: ReadonlyArray<SparkActivity>;
285
- };
286
- type SparkControllerState = {
287
- readonly accounts: Readonly<Record<string, SparkAccountState>>;
288
- };
289
- type SparkApis = {
290
- readonly signer: (ref: SparkAccountRef) => SparkSigner;
291
- readonly approve: (params: {
292
- account: SparkAccountRef;
293
- intent: SparkApproveIntent;
294
- verify: UnlockFactor;
295
- }) => Promise<unknown>;
296
- };
297
- type SparkClientFactory = (options: {
298
- readonly ref: SparkAccountRef;
299
- readonly store: ReturnType<typeof sparkStore>;
300
- readonly signer: SparkSigner;
301
- readonly fetch: typeof globalThis.fetch;
302
- }) => SparkClient;
303
- type SparkControllerOptions = {
304
- readonly spark: SparkApis;
305
- readonly fetch: typeof globalThis.fetch;
306
- readonly random: (length: number) => Uint8Array;
307
- readonly now: () => number;
308
- readonly logger: EngineLogger;
309
- readonly setTimer: (ms: number, fn: () => void) => () => void;
310
- readonly createClient: SparkClientFactory;
311
- };
312
- declare class SparkController extends Controller<SparkControllerState> {
313
- private readonly options;
314
- private engineStore;
315
- private readonly accounts;
316
- private readonly clients;
317
- private readonly recentSeq;
318
- private readonly aborts;
319
- constructor(options: SparkControllerOptions);
320
- /** Engine calls this with the open store on unlock; `undefined` on lock. */
321
- setStore(store: EngineStore | undefined): void;
322
- /**
323
- * Declarative account set: refs not yet tracked are patched `locked` and started when the store
324
- * is open; tracked refs no longer listed are stopped and dropped; running refs stay untouched.
325
- */
326
- setAccounts(refs: ReadonlyArray<SparkAccountRef>): void;
327
- init(): Promise<void>;
328
- destroy(): Promise<void>;
329
- private stopAccount;
330
- /** Lock: abort every event loop, close every client, reset state. */
331
- lockAll(): Promise<void>;
332
- private startAccount;
333
- private runEvents;
334
- private handleTransfer;
335
- private notesCollection;
336
- /** Attach locally written notes to a history page; malformed records warn and drop. */
337
- private withNotes;
338
- /**
339
- * Refill `recent` from the first history page. A failure keeps the previous page — it never
340
- * touches `status`/`errorCategory`. A per-account sequence keeps a slower older refresh from
341
- * overwriting a newer one.
342
- */
343
- private refreshRecent;
344
- private patch;
345
- private clientFor;
346
- private guarded;
347
- /**
348
- * One-off balance + activity probe for an account that may not be running: builds a temporary
349
- * client through the same factory on the account's own exit-chain collection (nothing diverges —
350
- * `balance()`/`transfers.history` never write it), reads, and closes it in `finally`.
351
- */
352
- inspect(ref: SparkAccountRef): Promise<{
353
- balanceSats: number;
354
- used: boolean;
355
- }>;
356
- /** History for one account: a client page merged with locally written notes by id. */
357
- history(ref: SparkAccountRef, options?: {
358
- readonly limit?: number;
359
- readonly offset?: number;
360
- }): Promise<{
361
- readonly items: ReadonlyArray<SparkActivity>;
362
- readonly nextOffset: number | undefined;
363
- }>;
364
- send(ref: SparkAccountRef, params: {
365
- receiver: string;
366
- amountSats: number;
367
- verify: UnlockFactor;
368
- }): Promise<SparkTransfer>;
369
- registerLightningAddress(ref: SparkAccountRef, params: {
370
- serverUrl: string;
371
- domain: string;
372
- username: string;
373
- description: string;
374
- }): Promise<{
375
- lnurl: string;
376
- lightningAddress: string;
377
- }>;
378
- unregisterLightningAddress(ref: SparkAccountRef, params: {
379
- serverUrl: string;
380
- domain: string;
381
- username: string;
382
- }): Promise<void>;
383
- payInvoice(ref: SparkAccountRef, params: {
384
- invoice: string;
385
- amountSats?: number;
386
- maxFeeSats: number;
387
- verify: UnlockFactor;
388
- /** Local annotation written under the payment's transfer id after it succeeds. */
389
- note?: PaymentNote;
390
- }): Promise<LightningPayment>;
391
- /**
392
- * Pays a Spark invoice address. The approval intent mirrors `send`: receiver identity and amount
393
- * come from the parsed invoice (the supplied `amountSats` fills an open invoice). Then
394
- * `client.invoices.pay` executes it.
395
- */
396
- paySparkInvoice(ref: SparkAccountRef, params: {
397
- invoice: string;
398
- amountSats?: number;
399
- verify: UnlockFactor;
400
- }): Promise<SparkTransfer>;
401
- createInvoice(ref: SparkAccountRef, params: {
402
- amountSats: number;
403
- memo?: string;
404
- }): Promise<LightningInvoice>;
405
- /** A fresh single-use L1 deposit address (with the SO's proof of possession). */
406
- newDepositAddress(ref: SparkAccountRef): Promise<string>;
407
- /** Claims a confirmed L1 deposit paying one of the account's unused deposit addresses. */
408
- claimDeposit(ref: SparkAccountRef, transaction: Uint8Array): Promise<void>;
409
- /** The account's last-synced balance — a cached snapshot, not a fresh query. */
410
- accountBalance(ref: SparkAccountRef): number | undefined;
411
- /** A payment's settle status — `payInvoice` resolves the send; `sendStatus` reports its preimage. */
412
- paymentStatus(ref: SparkAccountRef, request: {
413
- readonly requestId: string;
414
- readonly paymentHash: Uint8Array;
415
- }): Promise<LightningSendStatus>;
416
- receiveAddress(ref: SparkAccountRef): Promise<string | undefined>;
417
- /**
418
- * Cooperative exit to an L1 address. The client exits `amountSats` of leaves and the payout is
419
- * `amountSats - fee`, so the approval intent carries the PAYOUT: `amountSats: exit - fee` and
420
- * `maxFeeSats: fee` — the kernel matches the exit output against the intent, not the leaf total.
421
- */
422
- withdraw(ref: SparkAccountRef, params: {
423
- address: string;
424
- amountSats?: number;
425
- speed: "FAST" | "MEDIUM" | "SLOW";
426
- maxFeeSats?: number;
427
- verify: UnlockFactor;
428
- }): Promise<CooperativeExitResult>;
429
- }
430
- /**
431
- * What the host shows for a Spark, Lightning or exit request; `family` tells it apart from a chain
432
- * intent.
433
- */
434
- type SparkDisplay = {
435
- readonly family: "spark";
436
- readonly network: SparkNetwork;
437
- readonly kind: "transfer" | "lightning" | "exit";
438
- readonly amountSats: number;
439
- readonly maxFeeSats?: number;
440
- /** Spark address, Lightning payee public key (hex) or bitcoin address. */
441
- readonly receiver: string;
442
- /** Invoice description or the LNURL metadata text. */
443
- readonly description?: string;
444
- };
445
- type SparkResult = {
446
- readonly kind: "spark";
447
- readonly transfer: SparkTransfer;
448
- } | {
449
- readonly kind: "lightning";
450
- readonly payment: LightningPayment;
451
- } | {
452
- readonly kind: "withdraw";
453
- readonly exit: CooperativeExitResult;
454
- };
455
- /**
456
- * A validated, fixed Spark payment: everything that does not need the user's verification has
457
- * happened (including any LNURL invoice fetch), so approval only re-checks expiry and executes.
458
- */
459
- type PreparedSparkAction = {
460
- readonly display: SparkDisplay;
461
- readonly checks: ReadonlyArray<RequestCheckCode>;
462
- /** Why the action can no longer be paid at `now` (an expiring invoice), if so. */
463
- readonly staleReason: (now: number) => string | undefined;
464
- /** Runs the controller's approve-first payment call. */
465
- readonly execute: (spark: SparkController, verify: UnlockFactor) => Promise<SparkResult>;
466
- };
467
- type PaymentOption = {
468
- readonly kind: "spark";
469
- readonly address: string;
470
- } | {
471
- readonly kind: "spark-invoice";
472
- readonly invoice: string;
473
- readonly amountSats?: number;
474
- readonly memo?: string;
475
- readonly expiresAt?: number;
476
- } | {
477
- readonly kind: "lightning";
478
- readonly invoice: string;
479
- readonly amountSats?: number;
480
- readonly paymentHash: string;
481
- readonly description?: string;
482
- readonly expiresAt: number;
483
- } | {
484
- readonly kind: "lnurl-pay";
485
- readonly request: LnurlPayRequest;
486
- readonly address?: string;
487
- } | {
488
- readonly kind: "lnurl-withdraw";
489
- readonly request: LnurlWithdrawRequest;
490
- } | {
491
- readonly kind: "bitcoin";
492
- readonly address: string;
493
- };
494
- type PaymentRequest = {
495
- readonly options: ReadonlyArray<PaymentOption>;
496
- readonly amountSats?: number;
497
- readonly label?: string;
498
- readonly message?: string;
499
- };
500
- type PaymentParse = {
501
- readonly kind: "request";
502
- readonly request: PaymentRequest;
503
- } | {
504
- readonly kind: "lnurl";
505
- readonly url: string;
506
- readonly address?: string;
507
- } | {
508
- readonly kind: "unsupported";
509
- readonly format: "bolt12" | "silent-payment" | "lnurl-auth" | "spark-token-invoice" | "nostr-wallet-connect";
510
- } | {
511
- readonly kind: "invalid";
512
- readonly reason: "network" | "expired" | "amount-mismatch" | "malformed";
513
- } | {
514
- readonly kind: "unrecognized";
515
- };
516
- type ParseOptions = {
517
- readonly network: SparkNetwork;
518
- readonly now: number;
519
- };
520
- /** `input` → PaymentParse. Never throws: every failure is a structured result. */
521
- declare function parsePayment(input: string, options: ParseOptions): PaymentParse;
522
- type PayParams = {
523
- readonly account: SparkAccountRef;
524
- readonly option: PaymentOption;
525
- /** Caller-supplied amount — required by open invoices, the `spark` option, and LNURL flows. */
526
- readonly amountSats?: number;
527
- readonly comment?: string;
528
- readonly maxFeeSats?: number;
529
- readonly speed?: "FAST" | "MEDIUM" | "SLOW";
530
- /** `amountSats` came from the service's minimum (WebLN `lnurl`), not an explicit amount. */
531
- readonly amountFromServiceMinimum?: boolean;
532
- };
533
- type WithdrawLnurlParams = {
534
- readonly account: SparkAccountRef;
535
- readonly option: Extract<PaymentOption, {
536
- kind: "lnurl-withdraw";
537
- }>;
538
- readonly amountSats: number;
539
- };
540
- /** A profile zap names the recipient pubkey; an event zap carries the event it zaps. */
541
- type ZapRecipient = {
542
- readonly pubkey: string;
543
- readonly lightning: string;
544
- } | {
545
- readonly event: Event;
546
- readonly lightning: string;
547
- };
548
- type PrepareZapParams = {
549
- /** Any `NostrSigner` — wallet key, external key, NIP-07/46 — signs the 9734. */
550
- readonly signer: NostrSigner;
551
- readonly recipient: ZapRecipient;
552
- readonly amountSats: number;
553
- readonly comment?: string | undefined;
554
- readonly relays: ReadonlyArray<string>;
555
- readonly network: SparkNetwork;
556
- };
557
- type PrepareZapContext = {
558
- readonly verifyEvent: (event: Event) => boolean;
559
- readonly fetch: typeof globalThis.fetch;
560
- readonly now: () => number;
561
- };
562
- /** Everything a payer needs: the signed 9734, the invoice, and the note fields. */
563
- type PreparedZap = {
564
- readonly zapRequest: Event;
565
- readonly invoice: string;
566
- /** Hex payment hash decoded from the invoice. */
567
- readonly paymentHash: string;
568
- /** Millisecond expiry decoded from the invoice. */
569
- readonly expiresAt: number;
570
- readonly amountSats: number;
571
- /** The LNURL service's 9735 signing pubkey. */
572
- readonly receiptPubkey: string;
573
- readonly recipientPubkey: string;
574
- readonly eventId?: string;
575
- readonly comment?: string;
576
- /** The lud16 or LNURL as given. */
577
- readonly lightning: string;
578
- };
579
- /** Everything up to payment: resolve LNURL, sign the 9734, request the invoice. */
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
- }
629
- type ChainApis = ReturnType<typeof chains>;
630
- type SignParams = Parameters<ChainApis["sign"]>[0];
631
- type AccountRef = Exclude<SignParams["request"], {
632
- kind: "bitcoin.psbt";
633
- }>["account"];
634
- type DisplayIntent = ReturnType<typeof decodeEvm>;
635
- type TxState = "draft" | "signed" | "submitted" | "pending" | "confirmed" | "failed" | "rejected" | "dropped" | "replaced";
636
- /** A bitcoin transaction that funds the wallet's own Spark account; it is claimed once confirmed. */
637
- type SparkDepositTag = {
638
- readonly walletId: string;
639
- readonly groupIndex: number;
640
- readonly network: SparkNetwork;
641
- readonly claimed?: boolean;
642
- };
643
- type TrackedTransaction = {
644
- readonly id: string;
645
- readonly family: "evm" | "solana" | "bitcoin";
646
- readonly network: string;
647
- readonly account: string;
648
- readonly hash: string | undefined;
649
- readonly state: TxState;
650
- readonly intent: DisplayIntent | undefined;
651
- readonly nonce: number;
652
- /** Solana only — the blockhash expiry that turns an unconfirmed tx `dropped`. */
653
- readonly lastValidBlockHeight?: number;
654
- /** EVM replacement — the earlier transaction this one bumps or cancels. */
655
- readonly replaces?: string;
656
- /** CPFP — the unconfirmed parent this child pushes. */
657
- readonly parentId?: string;
658
- /** Set on a Spark deposit; `claimed` flips once the deposit is credited on Spark. */
659
- readonly sparkDeposit?: SparkDepositTag;
660
- /** EVM build record persisted at broadcast for rebroadcast, drop detection and replacement. */
661
- readonly evm?: {
662
- readonly from: string;
663
- readonly groupIndex: number;
664
- readonly raw: string;
665
- };
666
- /** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
667
- readonly btc?: {
668
- readonly inputs: ReadonlyArray<{
669
- readonly txid: string;
670
- readonly vout: number;
671
- readonly value: number;
672
- readonly address: string;
673
- }>;
674
- readonly outputs: ReadonlyArray<{
675
- readonly address: string;
676
- readonly value: number;
677
- readonly own: boolean;
678
- }>;
679
- readonly vsize: number;
680
- readonly fee: number;
681
- readonly feeRate: number;
682
- };
683
- readonly submittedAt: number;
684
- readonly error: string | undefined;
685
- };
686
- type SendParams = {
687
- readonly account: AccountRef;
688
- readonly network: string;
689
- readonly to: string;
690
- readonly amount: bigint;
691
- /** ERC-20 contract — when set, `to`/`amount` are the transfer recipient/units and value is 0. */
692
- readonly token?: string;
693
- readonly fee: EvmFeeTier | SolanaFeeTier;
694
- /** SPL mint decimals — required when `token` is a Solana mint. */
695
- readonly decimals?: number;
696
- readonly verify: SignParams["verify"];
697
- };
698
- type PrepareParams = Omit<SendParams, "verify">;
699
- type ChainRequestMethod = "send" | "speed-up" | "cancel" | "cpfp";
700
- /** What a request asks for; replacements and CPFP name the original transaction. */
701
- type ChainRequestInput = ({
702
- readonly method: "send";
703
- } & PrepareParams) | {
704
- readonly method: "speed-up" | "cancel";
705
- readonly txId: string;
706
- } | {
707
- readonly method: "cpfp";
708
- readonly txId: string;
709
- readonly feeRate: number;
710
- };
711
- /**
712
- * A fully built, estimated and cross-checked send that has not been signed. The unsigned content
713
- * lives in the closures and cannot change after `prepare` returns.
714
- */
715
- type PreparedRequest = {
716
- /** Id of the tracked transaction `submit` creates. */
717
- readonly txId: string;
718
- readonly account: AccountRef;
719
- readonly network: string;
720
- /** The transaction being replaced or accelerated; absent for a plain send. */
721
- readonly target?: string;
722
- readonly intent: DisplayIntent;
723
- readonly checks: ReadonlyArray<RequestCheckCode>;
724
- /** Absent when the request is not simulated (replacements, Bitcoin). */
725
- readonly simulation?: SimulationOutcome;
726
- /** Re-runs the same simulated call at approval; absent when there is nothing to re-run. */
727
- readonly resimulate?: () => Promise<SimulationOutcome>;
728
- /** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
729
- readonly staleReason: () => string | undefined | Promise<string | undefined>;
730
- /** Signs, finalizes, broadcasts and hands the transaction to tracking. */
731
- readonly submit: (verify: SendParams["verify"]) => Promise<TrackedTransaction>;
732
- /** Frees what `prepare` reserved; safe to call more than once. */
733
- readonly release: () => void;
734
- };
735
- type SignatureResult = {
736
- readonly kind: "evm.personal-message" | "evm.typed-data";
737
- readonly signature: Uint8Array;
738
- };
739
- /** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
740
- type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
741
- /** The address that will sign. */
742
- readonly signer: string;
743
- readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
744
- };
745
- type Options$2 = {
746
- readonly wallet: Wallet;
747
- readonly networks: NetworkController;
748
- readonly openStore: () => Promise<EngineStore>;
749
- readonly random: (n: number) => Uint8Array;
750
- readonly setTimer: (ms: number, fn: () => unknown) => () => void;
751
- readonly now: () => number;
752
- readonly logger: EngineLogger;
753
- readonly pollMs?: number;
754
- /** Test seam — defaults to the wallet's real chains proxy. */
755
- readonly chains?: ReturnType<typeof chains>;
756
- };
757
- type TransactionControllerState = {
758
- readonly txs: Record<string, TrackedTransaction>;
759
- };
760
- declare class TransactionController extends Controller<TransactionControllerState> {
761
- private readonly options;
762
- private engineStore?;
763
- private readonly timers;
764
- private evmRoute;
765
- private bitcoinRoute;
766
- private locked;
767
- constructor(options: Options$2);
768
- init(): Promise<void>;
769
- destroy(): Promise<void>;
770
- lock(): void;
771
- private persist;
772
- private transition;
773
- private routeCtx;
774
- /**
775
- * Internal entry for the request pipeline: builds, estimates and cross-checks a send without
776
- * signing it. Bitcoin outputs it selects stay locked under `requestId` until the returned
777
- * `release` runs or the broadcast moves them to the transaction.
778
- */
779
- prepareSend(params: PrepareParams, requestId: string, sparkDeposit?: SparkDepositTag): Promise<PreparedRequest>;
780
- /** The group's next unused `btc.bip84` receive address on a bitcoin `network`. */
781
- nextReceiveAddress(walletId: string, groupIndex: number, network: string): Promise<string>;
782
- /** Records that a Spark deposit was credited; persisted with the transaction. */
783
- markDepositClaimed(id: string): Promise<void>;
784
- /**
785
- * Internal entry for a dApp's EVM signature request: the request is normalized first, a
786
- * transaction is rebuilt with fresh nonce and fees (the dApp's own are discarded), and a message
787
- * is decoded and signed as is.
788
- */
789
- prepareDapp(account: AccountRef, request: SignRequest): Promise<PreparedRequest | PreparedMessage>;
790
- /**
791
- * Internal entry for replacements and CPFP: builds, cross-checks and reserves what the
792
- * replacement needs without signing it. The original must be `submitted` or `pending`.
793
- */
794
- prepareReplacement(input: Exclude<ChainRequestInput, {
795
- method: "send";
796
- }>, requestId: string): Promise<PreparedRequest>;
797
- private track;
798
- }
799
- /**
800
- * Request risk, pure. A recipient the wallet has never paid or saved is a `warning`; one that looks
801
- * like a known address (same first and last four characters, different address) is a `danger` — the
802
- * shape of an address-poisoning lookalike. Both can apply to one recipient. A page the user trusts
803
- * despite the phishing list is a `danger`; one that could not be checked is a `warning`.
804
- */
805
- type RiskFinding = {
806
- 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";
807
- readonly level: "warning" | "danger";
808
- };
809
- /** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
810
- type BrowserOrigin = {
811
- readonly kind: "browser";
812
- readonly origin: string;
813
- };
814
- type RequestOrigin = {
815
- readonly kind: "internal";
816
- } | BrowserOrigin;
817
- type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "nostr-sign" | "webln-invoice" | "watch-asset" | "solana-sign" | "bitcoin-sign" | "spark-deposit" | "spark-exit";
818
- /** A Solana chain account the `solana-sign` request signs for. */
819
- type SolanaAccount = {
820
- readonly walletId: string;
821
- readonly groupIndex: number;
822
- readonly address: string;
823
- };
824
- /** A Bitcoin account the `bitcoin-sign` request signs for: the group's fixed dApp-facing address. */
825
- type BitcoinAccount = {
826
- readonly walletId: string;
827
- readonly groupIndex: number;
828
- readonly address: string;
829
- /** `btc.bip84` for the `payment` purpose, `btc.bip86` for `ordinals`. */
830
- readonly template: "btc.bip84" | "btc.bip86";
831
- };
832
- /**
833
- * The wallet group a `bitcoin-sign` PSBT request signs for: inputs of several dApp-facing templates
834
- * of the same group may mix in one PSBT — each sign entry names its own template.
835
- */
836
- type BitcoinGroup = {
837
- readonly walletId: string;
838
- readonly groupIndex: number;
839
- };
840
- /** The sighash a dApp asks for per input; anything else is refused before it reaches a request. */
841
- type BitcoinSigHash = "ALL" | "SINGLE|ANYONECANPAY";
842
- /** One dApp PSBT and the inputs it asks the wallet to sign. */
843
- type BitcoinPsbtInput = {
844
- readonly psbt: Uint8Array;
845
- readonly sign: ReadonlyArray<{
846
- readonly index: number;
847
- readonly sigHash: BitcoinSigHash;
848
- readonly template: BitcoinAccount["template"];
849
- }>;
850
- };
851
- /**
852
- * A dApp PSBT after the engine enriched the requested inputs with this account's derivation data:
853
- * `request` is what the kernel signs, `ownScripts` the scripts verified as the account's, `inputs`
854
- * the signed inputs' prevout values and sighash (for risk).
855
- */
856
- type PreparedBitcoinPsbt = {
857
- readonly request: Extract<SignRequest, {
858
- kind: "bitcoin.psbt";
859
- }>;
860
- readonly ownScripts: ReadonlySet<string>;
861
- readonly inputs: ReadonlyArray<{
862
- readonly index: number;
863
- readonly value: number;
864
- readonly sigHash: BitcoinSigHash;
865
- readonly template: BitcoinAccount["template"];
866
- }>;
867
- };
868
- type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
869
- type SignLogEntry = {
870
- readonly id: string;
871
- readonly at: number;
872
- readonly origin: RequestOrigin;
873
- readonly method: RequestMethod;
874
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount | BitcoinGroup;
875
- readonly network: string;
876
- readonly summary: string;
877
- readonly verification: "verified" | "unverifiable";
878
- readonly checks: ReadonlyArray<RequestCheckCode>;
879
- readonly risk: ReadonlyArray<RiskFinding>;
880
- readonly outcome: SignLogOutcome;
881
- readonly error?: string;
882
- };
883
- /** A Spark, Lightning (including LNURL-pay and lightning addresses) or cooperative-exit payment. */
884
- type PayInput = {
885
- readonly method: "pay";
886
- readonly origin?: BrowserOrigin;
887
- } & PayParams;
888
- /** A prepared zap; its invoice was fetched by `engine.zaps.prepare` and is paid as-is. */
889
- type ZapInput = {
890
- readonly method: "zap";
891
- readonly account: SparkAccountRef;
892
- readonly zap: PreparedZap;
893
- readonly maxFeeSats: number;
894
- };
895
- /**
896
- * A dApp's EVM request: a transaction (rebuilt here with fresh nonce and fees), a personal message
897
- * or EIP-712 typed data.
898
- */
899
- type EvmSignInput = {
900
- readonly method: "evm-sign";
901
- readonly origin: BrowserOrigin;
902
- readonly account: AccountRef;
903
- readonly network: string;
904
- readonly request: SignRequest;
905
- };
906
- /**
907
- * Funds the wallet's own Spark account from a bitcoin account of the same wallet; the transaction
908
- * is an ordinary bitcoin send to a fresh Spark deposit address and is claimed once confirmed.
909
- */
910
- type SparkDepositInput = {
911
- readonly method: "spark-deposit";
912
- readonly account: SparkAccountRef;
913
- readonly from: AccountRef;
914
- readonly amountSats: number;
915
- readonly fee: PrepareParams["fee"];
916
- };
917
- /** A cooperative exit to the group's own next unused `btc.bip84` receive address. */
918
- type SparkExitInput = {
919
- readonly method: "spark-exit";
920
- readonly account: SparkAccountRef;
921
- readonly amountSats: number;
922
- readonly maxFeeSats: number;
923
- readonly speed?: "FAST" | "MEDIUM" | "SLOW";
924
- };
925
- /**
926
- * A NIP-07 `signEvent` that the policy sends through the pipeline: no factor on approval (Nostr
927
- * events are not per-event verifiable, WD-065); the display is the kind, a short content preview
928
- * and the tag count — the sign log records kind and event id only.
929
- */
930
- type NostrSignInput = {
931
- readonly method: "nostr-sign";
932
- readonly origin: BrowserOrigin;
933
- /** The active identity — the signer the page's pubkey must match. */
934
- readonly ref: NostrKeyRef;
935
- readonly event: UnsignedEvent;
936
- };
937
- /**
938
- * A WebLN `makeInvoice` confirmation: no factor (it only asks the user to confirm generating an
939
- * invoice — WD-065 does not apply; the factor-free rule mirrors `nostr-sign`), `display` carries
940
- * the requested amount and memo.
941
- */
942
- type WeblnInvoiceInput = {
943
- readonly method: "webln-invoice";
944
- readonly origin: BrowserOrigin;
945
- readonly ref: SparkAccountRef;
946
- readonly amountSats: number;
947
- readonly memo?: string;
948
- };
949
- /**
950
- * A dApp's `wallet_watchAsset`: confirm adding an ERC-20 token to the tracked list. No factor;
951
- * `symbol` and `decimals` are read on-chain by the pipeline, never taken from the page.
952
- */
953
- type WatchAssetInput = {
954
- readonly method: "watch-asset";
955
- readonly origin: BrowserOrigin;
956
- readonly account: AccountRef;
957
- readonly network: string;
958
- readonly address: string;
959
- };
960
- /**
961
- * A dApp's Solana request: one `solana-sign` covers a batch of transactions (signed sequentially —
962
- * each prompts) or a `solana.message` raw-message signature.
963
- */
964
- type SolanaSignInput = {
965
- readonly method: "solana-sign";
966
- readonly origin: BrowserOrigin;
967
- readonly account: SolanaAccount;
968
- readonly network: string;
969
- readonly request: {
970
- readonly kind: "transactions";
971
- readonly transactions: ReadonlyArray<Uint8Array>;
972
- readonly send: boolean;
973
- } | {
974
- readonly kind: "message";
975
- readonly message: Uint8Array;
976
- /** Set for a Sign In With Solana request; `message` is its text. */
977
- readonly signIn?: SignInFields;
978
- };
979
- };
980
- /**
981
- * A dApp's Bitcoin request: a BIP-322 simple message signature, or a batch of PSBTs signed one
982
- * after another under one approval (`send` also finalizes and broadcasts each).
983
- */
984
- type BitcoinSignInput = {
985
- readonly method: "bitcoin-sign";
986
- readonly origin: BrowserOrigin;
987
- readonly account: BitcoinAccount;
988
- readonly network: string;
989
- readonly request: {
990
- readonly kind: "message";
991
- readonly message: string;
992
- };
993
- } | {
994
- readonly method: "bitcoin-sign";
995
- readonly origin: BrowserOrigin;
996
- readonly account: BitcoinGroup;
997
- readonly network: string;
998
- readonly request: {
999
- readonly kind: "psbt";
1000
- readonly psbts: ReadonlyArray<BitcoinPsbtInput>;
1001
- readonly send: boolean;
1002
- };
1003
- };
1004
- type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | NostrSignInput | WeblnInvoiceInput | WatchAssetInput | SolanaSignInput | BitcoinSignInput | SparkDepositInput | SparkExitInput;
1005
- /** `approve` of a `nostr-sign` request: the signed event. */
1006
- type NostrSignResult = {
1007
- readonly kind: "nostr.event";
1008
- readonly event: Event;
1009
- };
1010
- /** `nostr-sign` display: the kind, a content preview and the tag count — nothing else is shown. */
1011
- type NostrDisplay = {
1012
- readonly kind: "nostr.event";
1013
- readonly eventKind: number;
1014
- readonly preview: string;
1015
- readonly tagCount: number;
1016
- };
1017
- /** `approve` of a `webln-invoice` request: the created invoice's BOLT11 payment request. */
1018
- type WeblnInvoiceResult = {
1019
- readonly kind: "lightning.invoice";
1020
- readonly paymentRequest: string;
1021
- };
1022
- /** `solana-sign` display: each transaction's decode (fee payer + transfers) or the raw message. */
1023
- type SolanaDisplay = {
1024
- readonly kind: "solana.sign";
1025
- readonly send: boolean;
1026
- readonly count: number;
1027
- readonly transactions: ReadonlyArray<unknown>;
1028
- /** A message request's content — text, or raw bytes when it is not UTF-8. */
1029
- readonly message?: MessageContent;
1030
- readonly signIn?: SignInFields;
1031
- };
1032
- /** `approve` of a `solana-sign` request: the signatures (or signed transactions) per input. */
1033
- type SolanaSignResult = {
1034
- readonly kind: "solana.transactions";
1035
- readonly send: boolean;
1036
- readonly signatures?: ReadonlyArray<string>;
1037
- readonly signedTransactions?: ReadonlyArray<Uint8Array>;
1038
- } | {
1039
- readonly kind: "solana.message";
1040
- readonly signature: Uint8Array;
1041
- };
1042
- /** `bitcoin-sign` display: the message text, or each PSBT's decode. */
1043
- type BitcoinDisplay = {
1044
- readonly kind: "bitcoin.sign";
1045
- readonly message?: MessageContent;
1046
- readonly psbts?: ReadonlyArray<DisplayIntent>;
1047
- readonly send?: boolean;
1048
- };
1049
- /**
1050
- * `approve` of a `bitcoin-sign` request: the BIP-322 simple signature (base64 of the witness), or
1051
- * the signed PSBTs and, when sent, their txids.
1052
- */
1053
- type BitcoinSignResult = {
1054
- readonly kind: "bitcoin.message";
1055
- readonly signature: string;
1056
- } | {
1057
- readonly kind: "bitcoin.psbts";
1058
- readonly signedPsbts: ReadonlyArray<Uint8Array>;
1059
- readonly txids: ReadonlyArray<string>;
1060
- };
1061
- /** `approve` of a `watch-asset` request: the token was added. */
1062
- type TokenWatchResult = {
1063
- readonly kind: "token.watch";
1064
- };
1065
- /** `watch-asset` display: the token as read on-chain; `verified` means it is in the built-in table. */
1066
- type TokenWatchDisplay = {
1067
- readonly kind: "token.watch";
1068
- readonly network: string;
1069
- readonly address: string;
1070
- readonly symbol: string;
1071
- readonly decimals: number;
1072
- readonly verified: boolean;
1073
- };
1074
- /** `webln-invoice` display: the requested amount and memo. */
1075
- type LightningInvoiceDisplay = {
1076
- readonly kind: "lightning.invoice";
1077
- readonly amountSats: number;
1078
- readonly memo?: string;
1079
- };
1080
- type RequestStage = "awaiting-approval" | "signing" | "submitted" | "rejected" | "failed" | "expired" | "invalidated";
1081
- type PendingRequest = {
1082
- readonly id: string;
1083
- readonly origin: RequestOrigin;
1084
- readonly method: RequestMethod;
1085
- readonly account: AccountRef | SparkAccountRef | NostrKeyRef | SolanaAccount | BitcoinAccount | BitcoinGroup;
1086
- readonly network: string;
1087
- readonly stage: RequestStage;
1088
- /** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
1089
- readonly display: DisplayIntent | SparkDisplay | NostrDisplay | LightningInvoiceDisplay | TokenWatchDisplay | SolanaDisplay | BitcoinDisplay;
1090
- /** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
1091
- readonly verification: "verified" | "unverifiable";
1092
- readonly checks: ReadonlyArray<RequestCheckCode>;
1093
- /**
1094
- * Recipient risk; independent of `verification`. A `danger` needs the user's explicit
1095
- * acknowledgement.
1096
- */
1097
- readonly risk: ReadonlyArray<RiskFinding>;
1098
- /** Present for simulated requests: sends and dApp transactions; absent otherwise. */
1099
- readonly simulation?: SimulationOutcome;
1100
- /** When `simulation` was produced (ms); one older than {@link RESIMULATE_AFTER_MS} re-runs. */
1101
- readonly simulatedAt?: number;
1102
- readonly createdAt: number;
1103
- readonly expiresAt: number;
1104
- /** The transaction being replaced or accelerated; absent for a plain send. */
1105
- readonly target?: string;
1106
- /** The tracked transaction once submitted. */
1107
- readonly txId?: string;
1108
- readonly error?: string;
1109
- };
1110
- type RequestControllerState = {
1111
- readonly requests: Record<string, PendingRequest>;
1112
- };
1113
- type RequestControllerOptions = {
1114
- readonly transactions: TransactionController;
1115
- /** The full controller: its payment methods are reachable only through this pipeline. */
1116
- readonly spark: SparkController;
1117
- readonly addressBook: AddressBookController;
1118
- readonly openStore: () => Promise<EngineStore>;
1119
- readonly fetch: typeof globalThis.fetch;
1120
- readonly random: (n: number) => Uint8Array;
1121
- readonly now: () => number;
1122
- readonly setTimer: (ms: number, fn: () => unknown) => () => void;
1123
- readonly logger: EngineLogger;
1124
- /** Signs a Nostr event for `nostr-sign` — `nostr(wallet).signer(ref).signEvent`. */
1125
- readonly nostrSign: (ref: NostrKeyRef, event: UnsignedEvent) => Promise<Event>;
1126
- readonly phishing: Pick<PhishingController, "check">;
1127
- /** Reads a token's metadata and adds it to the tracked list, for `watch-asset`. */
1128
- readonly tokens: {
1129
- readonly metadata: (network: string, address: string) => Promise<{
1130
- readonly symbol: string;
1131
- readonly decimals: number;
1132
- }>;
1133
- readonly add: (network: string, address: string) => Promise<void>;
1134
- };
1135
- /** Whether the account group opted in to signing messages that cannot be shown as text. */
1136
- readonly blindSigning: (walletId: string, groupIndex: number) => boolean;
1137
- /** Simulates one `solana-sign` transaction for display; failures are the caller's `unavailable`. */
1138
- readonly simulateSolana: (account: SolanaAccount, network: string, message: Uint8Array) => Promise<SimulationOutcome>;
1139
- /** Signs/broadcasts a `solana-sign` request — `chains.sign` per tx, then the Solana adapter. */
1140
- readonly solanaSign: (account: {
1141
- readonly walletId: string;
1142
- readonly groupIndex: number;
1143
- readonly address: string;
1144
- }, network: string, request: SolanaSignInput["request"], verify: SendParams["verify"]) => Promise<SolanaSignResult>;
1145
- /** Signs a `bitcoin-sign` message — `chains.sign` with the account's template. */
1146
- readonly bitcoinSign: (account: BitcoinAccount, network: string, request: {
1147
- readonly kind: "message";
1148
- readonly message: string;
1149
- }, verify: SendParams["verify"]) => Promise<BitcoinSignResult>;
1150
- /** Adds the group's derivation data to a dApp's PSBTs; refuses inputs that are not its own. */
1151
- readonly bitcoinPrepare: (account: BitcoinGroup, network: string, psbts: ReadonlyArray<BitcoinPsbtInput>) => Promise<ReadonlyArray<PreparedBitcoinPsbt>>;
1152
- /** Signs (and with `send` broadcasts) the prepared PSBTs. */
1153
- readonly bitcoinSignPsbts: (account: BitcoinGroup, network: string, prepared: ReadonlyArray<PreparedBitcoinPsbt>, send: boolean, verify: SendParams["verify"]) => Promise<BitcoinSignResult>;
1154
- };
1155
- /** Requests expire this long after creation. */
1156
- declare const REQUEST_TTL_MS: number;
1157
- /** A simulation older than this is re-run at approval before any signing. */
1158
- declare const RESIMULATE_AFTER_MS = 60000;
1159
- /** What an approved request resolves with, whichever kind it is. */
1160
- type RequestResult = TrackedTransaction | SparkResult | SignatureResult | NostrSignResult | WeblnInvoiceResult | TokenWatchResult | SolanaSignResult | BitcoinSignResult;
1161
- declare class RequestController extends Controller<RequestControllerState> {
1162
- private readonly options;
1163
- private readonly entries;
1164
- private readonly log;
1165
- private readonly settlers;
1166
- /** Original transaction id → the unfinished request replacing or accelerating it. */
1167
- private readonly targets;
1168
- private locked;
1169
- /** Bumped on every unlock and lock so work that outlives a session never touches the next one. */
1170
- private session;
1171
- constructor(options: RequestControllerOptions);
1172
- init(): Promise<void>;
1173
- destroy(): Promise<void>;
1174
- /** Locking is not consent: every unfinished request becomes `invalidated` and frees its resources. */
1175
- lock(): void;
1176
- /** A page navigated away, was revoked or changed network: its unfinished requests are void. */
1177
- invalidateOrigin(origin: string): void;
1178
- /** The signature record, newest first. */
1179
- signLog(): Promise<ReadonlyArray<SignLogEntry>>;
1180
- clearSignLog(): Promise<void>;
1181
- prepare(input: RequestInput): Promise<PendingRequest>;
1182
- /**
1183
- * Resolves with what `approve` returned, or rejects with `RequestEndedError` when the request
1184
- * ends any other way — how a dApp's pending call learns the outcome.
1185
- */
1186
- outcome(id: string): Promise<RequestResult>;
1187
- private openSettler;
1188
- private settle;
1189
- /** The bitcoin network `account`'s Spark network settles on; any other pairing is refused. */
1190
- private l1Network;
1191
- private sparkBuilt;
1192
- private simulateOne;
1193
- private build;
1194
- /**
1195
- * Signs and submits a request. Anything but a live, unexpired `send` request with this id throws
1196
- * before any signing; a stale build (nonce taken, blockhash expired) fails without signing.
1197
- */
1198
- approve(id: string, method: ChainRequestMethod | "spark-deposit", verify?: SendParams["verify"]): Promise<TrackedTransaction>;
1199
- approve(id: string, method: "pay" | "zap" | "spark-exit", verify?: SendParams["verify"]): Promise<SparkResult>;
1200
- approve(id: string, method: "evm-sign", verify?: SendParams["verify"]): Promise<TrackedTransaction | SignatureResult>;
1201
- approve(id: string, method: "nostr-sign"): Promise<NostrSignResult>;
1202
- approve(id: string, method: "webln-invoice"): Promise<WeblnInvoiceResult>;
1203
- approve(id: string, method: "watch-asset"): Promise<TokenWatchResult>;
1204
- approve(id: string, method: "solana-sign", verify?: SendParams["verify"]): Promise<SolanaSignResult>;
1205
- approve(id: string, method: "bitcoin-sign", verify?: SendParams["verify"]): Promise<BitcoinSignResult>;
1206
- /**
1207
- * A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
1208
- * requests record which step failed on the tracked transaction; for Spark, the approval round is
1209
- * the only source of `WalletError`.
1210
- */
1211
- private failureStage;
1212
- reject(id: string): void;
1213
- /** `approve` for a factor-required run: a missing factor is invalid input. */
1214
- private requireVerify;
1215
- private requireRequest;
1216
- private put;
1217
- private unclaim;
1218
- /** Ends a request in a terminal stage and frees what it reserved. */
1219
- private finish;
1220
- /** Appends the final stage to the signature record; a failed write is a warning, not an error. */
1221
- private record;
1222
- private appendLog;
1223
- /**
1224
- * Addresses the wallet already knows for a family: contacts, plus recipients of tracked chain
1225
- * sends (Spark payments are not tracked).
1226
- */
1227
- private knownAddresses;
1228
- /** A blind-sign request carries one danger; a group that did not opt in refuses it outright. */
1229
- private blindRisk;
1230
- /** Risk of a Sign-In with X message; a message for another domain throws `SignInOriginError`. */
1231
- private signInRisk;
1232
- private chainRisk;
1233
- /** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
1234
- private sparkRisk;
1235
- }
1236
- type ConnectionOrigin = {
1237
- readonly kind: "browser";
1238
- readonly origin: string;
1239
- };
1240
- type ConnectionScope = {
1241
- /** CAIP-10 */
1242
- readonly accounts: ReadonlyArray<string>;
1243
- readonly methods: ReadonlyArray<string>;
1244
- readonly notifications: ReadonlyArray<string>;
1245
- };
1246
- type ConnectionSession = {
1247
- readonly id: string;
1248
- readonly origin: ConnectionOrigin;
1249
- /** Keyed by CAIP-2. */
1250
- readonly scopes: Readonly<Record<string, ConnectionScope>>;
1251
- /** The session's current EVM network; only dApp sessions have one. */
1252
- readonly currentNetwork: string;
1253
- /** The origin's Nostr policy — set when the host approves a `nostr` connection. */
1254
- readonly nostrPolicy?: NostrPolicy;
1255
- /** The origin's Lightning policy — set when the host approves a `lightning` connection. */
1256
- readonly lightningPolicy?: LightningPolicy;
1257
- readonly createdAt: number;
1258
- readonly lastUsedAt: number;
1259
- };
1260
- /**
1261
- * How much a `nostr` session may do without per-call approval: `signing` is `"ask"` (every
1262
- * `signEvent` goes through the pipeline), `"always"` (any kind signs directly), or a kind list (`{
1263
- * kinds }` — only those kinds sign directly, the rest ask); `decrypt` gates `nip04/nip44 .decrypt`.
1264
- * The four forced-confirm kinds `{0,3,5,10002}` always ask regardless.
1265
- */
1266
- type NostrPolicy = {
1267
- readonly signing: "ask" | "always" | {
1268
- readonly kinds: ReadonlyArray<number>;
1269
- };
1270
- readonly decrypt: boolean;
1271
- };
1272
- /**
1273
- * How much a `lightning` session may do without per-call approval: `balance` gates `getBalance`
1274
- * (WebLN). Sending and invoicing always go through their own approvals.
1275
- */
1276
- type LightningPolicy = {
1277
- readonly balance: boolean;
1278
- };
1279
- /** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
1280
- type PendingConnection = {
1281
- readonly id: string;
1282
- readonly origin: ConnectionOrigin;
1283
- readonly kind: "connect" | "network";
1284
- /**
1285
- * Which namespace the connection is for — `eip155` (EVM), `nostr` (NIP-07) or `lightning`
1286
- * (WebLN).
1287
- */
1288
- readonly namespace: "eip155" | "nostr" | "lightning" | "solana" | "bip122";
1289
- readonly network?: string;
1290
- /** `false` for a `network` request that adds the network without making it current. */
1291
- readonly activate?: boolean;
1292
- readonly createdAt: number;
1293
- };
1294
- /** What a connection request asks for; `namespace` defaults to `eip155`, `activate` to `true`. */
1295
- type ConnectionRequest = {
1296
- readonly kind: PendingConnection["kind"];
1297
- readonly namespace?: PendingConnection["namespace"];
1298
- readonly network?: string;
1299
- readonly activate?: boolean;
1300
- };
1301
- type AccountGroup = {
1302
- readonly walletId: string;
1303
- readonly groupIndex: number;
1304
- };
1305
- type ConnectionState = {
1306
- readonly sessions: Readonly<Record<string, ConnectionSession>>;
1307
- readonly pending: Readonly<Record<string, PendingConnection>>;
1308
- };
1309
- type ConnectionControllerOptions = {
1310
- readonly openStore: () => Promise<EngineStore>;
1311
- readonly random: (n: number) => Uint8Array;
1312
- readonly now: () => number;
1313
- readonly logger: EngineLogger;
1314
- /** Development builds also accept `http://localhost`. */
1315
- readonly allowLocalhost: boolean;
1316
- /** The group the app currently shows; sessions are bound to it. */
1317
- readonly selectedGroup: () => AccountGroup | undefined;
1318
- /** The group's EVM address on `network`. */
1319
- readonly evmAddress: (group: AccountGroup, network: string) => Promise<string>;
1320
- /** The group's Solana address on `network` (a CAIP-2 `solana:<genesis>` chain). */
1321
- readonly solanaAddress: (group: AccountGroup, network: string) => Promise<string>;
1322
- /** The group's fixed dApp-facing Bitcoin address of `purpose` on `network` (`bip122:<genesis>`). */
1323
- readonly bitcoinAddress: (group: AccountGroup, network: string, purpose: BitcoinPurpose) => Promise<string>;
1324
- readonly enabledNetworks: () => ReadonlyArray<string>;
1325
- /** A Nostr identity's public key — `nostr(wallet).signer(ref).getPublicKey()`. */
1326
- readonly nostrPubkey: (ref: NostrKeyRef) => Promise<string>;
1327
- /** Voids a page's unfinished requests (revoked, or its network changed). */
1328
- readonly invalidate: (origin: string) => void;
1329
- readonly phishing: Pick<PhishingController, "check">;
1330
- readonly setTimer: (ms: number, fn: () => unknown) => () => void;
1331
- };
1332
- /** `payment` is the group's `btc.bip84` address, `ordinals` its `btc.bip86` one. */
1333
- type BitcoinPurpose = "payment" | "ordinals";
1334
- declare class ConnectionController extends Controller<ConnectionState> {
1335
- private readonly options;
1336
- private engineStore;
1337
- private readonly waiters;
1338
- private readonly expiries;
1339
- private group;
1340
- private identity;
1341
- constructor(options: ConnectionControllerOptions);
1342
- init(): Promise<void>;
1343
- destroy(): Promise<void>;
1344
- /** Locking is not consent: every pending connection is rejected. */
1345
- lock(): void;
1346
- /**
1347
- * A page navigated away (or the bridge is being disposed): the origin's pending connection
1348
- * requests are rejected and its unfinished pipeline requests voided — the live session survives
1349
- * (a refresh is not a revocation).
1350
- */
1351
- invalidateOrigin(origin: string): void;
1352
- /**
1353
- * Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development) and not on
1354
- * the phishing list.
1355
- */
1356
- checkOrigin(origin: string): ConnectionOrigin;
1357
- session(origin: string): ConnectionSession | undefined;
1358
- pending(): ReadonlyArray<PendingConnection>;
1359
- /** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
1360
- activeGroup(): AccountGroup | undefined;
1361
- /** Whether `network` is an EVM network the wallet has enabled. */
1362
- isEnabled(network: string): boolean;
1363
- /** The origin's authorized addresses on its current network; empty when not connected. */
1364
- accounts(origin: string): ReadonlyArray<string>;
1365
- /** Throws `4100` unless the origin's session covers `method` on `network`. */
1366
- authorize(origin: string, network: string, method: string): ConnectionSession;
1367
- /** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
1368
- request(origin: string, { kind, namespace, network, activate }: ConnectionRequest): Promise<ConnectionSession>;
1369
- /**
1370
- * The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
1371
- * network.
1372
- */
1373
- approveConnection(id: string, grant: {
1374
- readonly accounts: ReadonlyArray<string>;
1375
- readonly network: string;
1376
- /** The `nostr` namespace's grant: the identity's pubkey and the origin's policy. */
1377
- readonly nostr?: {
1378
- readonly pubkey: string;
1379
- readonly policy: NostrPolicy;
1380
- };
1381
- /** The `lightning` namespace's grant: the origin's policy. */
1382
- readonly lightning?: {
1383
- readonly policy: LightningPolicy;
1384
- };
1385
- }): Promise<ConnectionSession>;
1386
- rejectConnection(id: string): void;
1387
- /** Ends the origin's session; its pending connection and unfinished requests are void. */
1388
- revoke(origin: string): Promise<void>;
1389
- /** Switches within the session's scope; the origin's unfinished requests are void. */
1390
- setCurrentNetwork(origin: string, network: string): Promise<void>;
1391
- touch(origin: string): Promise<void>;
1392
- /**
1393
- * The host switched account group: every session's accounts become the new group's addresses. A
1394
- * session that cannot get one (no address derivable) is left with an empty list and has to be
1395
- * authorized again.
1396
- */
1397
- setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
1398
- /** The active Nostr identity — `undefined` until the host picks one. */
1399
- activeIdentity(): NostrKeyRef | undefined;
1400
- /** The origin's persisted Nostr policy — `undefined` until it is nostr-authorized. */
1401
- nostrPolicy(origin: string): NostrPolicy | undefined;
1402
- /** The origin's `nostr` namespace scope's pubkey, or `undefined` when not nostr-authorized. */
1403
- nostrAccount(origin: string): string | undefined;
1404
- /** The origin's persisted Lightning policy — `undefined` until it is lightning-authorized. */
1405
- lightningPolicy(origin: string): LightningPolicy | undefined;
1406
- /** The origin's `solana` scope's address on `network`, or `undefined` when not authorized. */
1407
- solanaAccount(origin: string, network: string): string | undefined;
1408
- /**
1409
- * The origin's `bip122` scope accounts on `network`, in `BITCOIN_PURPOSES` order, or `undefined`
1410
- * when not authorized.
1411
- */
1412
- bitcoinAccounts(origin: string, network: string): Record<BitcoinPurpose, string> | undefined;
1413
- private bitcoinScope;
1414
- /**
1415
- * The host's Nostr identity selection: every authorized `nostr` session's account becomes the new
1416
- * identity's pubkey (or empties when the identity is cleared). No event — NIP-07 has none.
1417
- */
1418
- setActiveIdentity(ref: NostrKeyRef | undefined): Promise<void>;
1419
- private dropPending;
1420
- private persist;
1421
- private requireStore;
1422
- }
1423
- /**
1424
- * The Bitcoin Wallet Standard (Exodus' `bitcoin:*` features, registered through
1425
- * `@wallet-standard/wallet` like the Solana wallet) handler — the bridge routes `provider:
1426
- * "bitcoin"` messages here.
1427
- */
1428
- type BitcoinRequest = {
1429
- readonly method: string;
1430
- readonly params?: unknown;
1431
- };
1432
- type BitcoinHandler = {
1433
- readonly handle: (origin: string, request: BitcoinRequest) => Promise<unknown>;
1434
- readonly subscribe: (listener: (event: BitcoinEvent) => void) => () => void;
1435
- };
1436
- /**
1437
- * The Bitcoin Wallet Standard chain ids to the registry's CAIP-2 ids: `bitcoin:testnet` is the
1438
- * registry's default test network (Testnet4 — the registry has no Testnet3).
1439
- */
1440
- declare const BITCOIN_CHAIN_IDS: Readonly<Record<string, string>>;
1441
- /** The Wallet Standard `WalletAccount` shape `bitcoin:connect` returns per account. */
1442
- type BitcoinWalletAccount = {
1443
- readonly address: string;
1444
- /** `payment`: the compressed key (33 bytes); `ordinals`: the x-only internal key (32 bytes). */
1445
- readonly publicKey: Uint8Array;
1446
- readonly chains: ReadonlyArray<string>;
1447
- readonly features: ReadonlyArray<string>;
1448
- };
1449
- type BitcoinEvent = {
1450
- readonly name: "bitcoinAccountsChanged";
1451
- readonly origin: string;
1452
- readonly accounts: ReadonlyArray<BitcoinWalletAccount>;
1453
- };
1454
- type BitcoinConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "bitcoinAccounts" | "request" | "touch" | "revoke" | "getState" | "store">;
1455
- type BitcoinRequests = Pick<RequestController, "prepare" | "outcome">;
1456
- type Options$1 = {
1457
- readonly connections: BitcoinConnections;
1458
- readonly requests: BitcoinRequests;
1459
- /** The group's address and public key for `purpose` on `network` (receive chain, index 0). */
1460
- readonly bitcoinAccount: (group: {
1461
- readonly walletId: string;
1462
- readonly groupIndex: number;
1463
- }, network: string, purpose: BitcoinPurpose) => Promise<{
1464
- readonly address: string;
1465
- readonly publicKey: Uint8Array;
1466
- }>;
1467
- readonly activeGroup: () => {
1468
- readonly walletId: string;
1469
- readonly groupIndex: number;
1470
- } | undefined;
1471
- readonly bitcoinNetwork: () => string;
1472
- };
1473
- /**
1474
- * The Bitcoin Wallet Standard handler: `bitcoin:connect` authorizes the `bip122` scope (both the
1475
- * `payment` and the `ordinals` account) and returns the requested purposes in order;
1476
- * `bitcoin:signMessage` goes through `bitcoin-sign` (BIP-322 simple); `bitcoinAccountsChanged`
1477
- * carries the re-pointed accounts the bridge forwards as `bitcoin:events` `change` on a group
1478
- * switch.
1479
- */
1480
- declare class BitcoinWalletHandler implements BitcoinHandler {
1481
- readonly options: Options$1;
1482
- private readonly events;
1483
- constructor(options: Options$1);
1484
- subscribe(listener: (event: BitcoinEvent) => void): () => void;
1485
- handle(origin: string, request: BitcoinRequest): Promise<unknown>;
1486
- private connect;
1487
- private walletAccount;
1488
- /**
1489
- * Signs `message` (UTF-8 text only — `bitcoin.message` takes text, so there is no blind path) for
1490
- * one of the session's accounts. The signature is the BIP-322 simple witness serialization
1491
- * (witness item count, then each item length-prefixed) — the kernel's `smp` + base64 string
1492
- * decoded to bytes, which is what MetaMask's Bitcoin Wallet Standard wallet hands out.
1493
- */
1494
- private signMessage;
1495
- /**
1496
- * Signs (and with `send` broadcasts) a batch of dApp PSBTs under one approval. Every account
1497
- * named must be a session account — inputs of both purposes may mix in one PSBT, each sign entry
1498
- * carries its account's template — and `chain`, when given, must be the session's network.
1499
- */
1500
- private signTransactions;
1501
- /** The `setActiveGroup` re-point: the bitcoin session's new accounts, `payment` then `ordinals`. */
1502
- bitcoinAccountsChanged(): Promise<BitcoinWalletAccount[]>;
1503
- }
1504
- type Eip1193Request = {
1505
- readonly method: string;
1506
- readonly params?: unknown;
1507
- };
1508
- type Eip1193Event = {
1509
- readonly name: "connect";
1510
- readonly origin: string;
1511
- readonly chainId: string;
1512
- } | {
1513
- readonly name: "accountsChanged";
1514
- readonly origin: string;
1515
- readonly accounts: ReadonlyArray<string>;
1516
- } | {
1517
- readonly name: "chainChanged";
1518
- readonly origin: string;
1519
- readonly chainId: string;
1520
- } | {
1521
- readonly name: "disconnect";
1522
- readonly origin: string;
1523
- };
1524
- type Eip1193HandlerOptions = {
1525
- readonly connections: ConnectionController;
1526
- readonly requests: RequestController;
1527
- readonly networks: NetworkController;
1528
- /** The network an unconnected page sees. */
1529
- readonly defaultNetwork: () => string;
1530
- /** Whether a token is already in the built-in table or the user's custom tokens. */
1531
- readonly isTracked: (network: string, address: string) => boolean;
1532
- };
1533
- declare class Eip1193Handler {
1534
- private readonly options;
1535
- private readonly events;
1536
- constructor(options: Eip1193HandlerOptions);
1537
- /** Events for the host to forward to pages; derived from changes to the sessions. */
1538
- subscribe(listener: (event: Eip1193Event) => void): () => void;
1539
- handle(origin: string, request: Eip1193Request): Promise<unknown>;
1540
- private requestAccounts;
1541
- private permissions;
1542
- private switchChain;
1543
- /**
1544
- * EIP-3085. The chain must already be a network the wallet enables; the page's `rpcUrls` are
1545
- * validated for shape and never read or used — custom endpoints are the user's setting.
1546
- */
1547
- private addChain;
1548
- /** EIP-747 (ERC-20 only): `symbol`, `decimals` and `image` from the page are never used. */
1549
- private watchAsset;
1550
- private authorizedAccount;
1551
- private personalSign;
1552
- private typedData;
1553
- private sendTransaction;
1554
- private signingSession;
1555
- private sign;
1556
- private read;
1557
- }
1558
- /** A NIP-07 method call from the page. */
1559
- type Nip07Request = {
1560
- readonly method: string;
1561
- readonly params?: unknown;
1562
- };
1563
- type Nip07HandlerOptions = {
1564
- readonly connections: Pick<ConnectionController, "checkOrigin" | "authorize" | "session" | "nostrAccount" | "nostrPolicy" | "activeIdentity" | "request" | "touch">;
1565
- readonly requests: Pick<RequestController, "prepare" | "outcome">;
1566
- /** `nostr(wallet).signer(ref)` — the active identity's signer. */
1567
- readonly signerFor: (ref: NostrKeyRef) => WalletSigner;
1568
- };
1569
- declare class Nip07Handler {
1570
- private readonly options;
1571
- constructor(options: Nip07HandlerOptions);
1572
- handle(origin: string, request: Nip07Request): Promise<unknown>;
1573
- private publicKey;
1574
- private signEvent;
1575
- private crypt;
1576
- }
1577
- /**
1578
- * The Wallet Standard (`window.solana` / `registerWallet`) handler — the bridge routes `provider:
1579
- * "solana"` messages here.
1580
- */
1581
- type SolanaRequest = {
1582
- readonly method: string;
1583
- readonly params?: unknown;
1584
- };
1585
- type SolanaHandler = {
1586
- readonly handle: (origin: string, request: SolanaRequest) => Promise<unknown>;
1587
- readonly subscribe: (listener: (event: SolanaEvent) => void) => () => void;
1588
- };
1589
- /**
1590
- * The Wallet Standard short chain ids to the registry's CAIP-2 genesis-hash ids, derived from the
1591
- * solana network registry by name.
1592
- */
1593
- declare const SOLANA_CHAIN_IDS: Readonly<Record<string, string>>;
1594
- /** The Wallet Standard `WalletAccount` shape `standard:connect` returns per account. */
1595
- type SolanaWalletAccount = {
1596
- readonly address: string;
1597
- readonly publicKey: Uint8Array;
1598
- readonly chains: ReadonlyArray<string>;
1599
- readonly features: ReadonlyArray<string>;
1600
- readonly icon?: string;
1601
- readonly label?: string;
1602
- };
1603
- type SolanaEvent = {
1604
- readonly name: "solanaAccountsChanged";
1605
- readonly origin: string;
1606
- readonly accounts: ReadonlyArray<SolanaWalletAccount>;
1607
- };
1608
- type SolanaConnections = Pick<ConnectionController, "checkOrigin" | "session" | "authorize" | "solanaAccount" | "request" | "touch" | "revoke" | "getState" | "store">;
1609
- type SolanaRequests = Pick<RequestController, "prepare" | "outcome">;
1610
- type Options = {
1611
- readonly connections: SolanaConnections;
1612
- readonly requests: SolanaRequests;
1613
- /** The group's Solana address + public key on `network` (the `solana.bip44-change` account). */
1614
- readonly solanaAccount: (group: {
1615
- readonly walletId: string;
1616
- readonly groupIndex: number;
1617
- }, network: string) => Promise<{
1618
- readonly address: string;
1619
- readonly publicKey: Uint8Array;
1620
- }>;
1621
- readonly activeGroup: () => {
1622
- readonly walletId: string;
1623
- readonly groupIndex: number;
1624
- } | undefined;
1625
- readonly solanaNetwork: () => string;
1626
- };
1627
- /**
1628
- * The Wallet Standard handler: `standard:connect` authorizes the `solana` scope, `solana:*` sign
1629
- * requests go through `solana-sign`, `solanaAccountsChanged` returns the re-pointed accounts the
1630
- * bridge forwards as `standard:events` `change` on a group switch.
1631
- */
1632
- declare class SolanaWalletHandler implements SolanaHandler {
1633
- readonly options: Options;
1634
- private readonly events;
1635
- constructor(options: Options);
1636
- /** `standard:events` `change` per origin — derived from changes to the sessions. */
1637
- subscribe(listener: (event: SolanaEvent) => void): () => void;
1638
- handle(origin: string, request: SolanaRequest): Promise<unknown>;
1639
- private connect;
1640
- private walletAccount;
1641
- private signTransactions;
1642
- /**
1643
- * The network a transaction call targets: the wallet's default when no input names a chain,
1644
- * otherwise the one chain every input agrees on (`chain` is required for sign-and-send).
1645
- */
1646
- private networkOf;
1647
- private signMessage;
1648
- /**
1649
- * Sign In With Solana: connects first when needed, binds the message to the page's host and the
1650
- * session's account, and signs the exact text the user is shown.
1651
- */
1652
- private signIn;
1653
- private signMessageRequest;
1654
- /** One `solana-sign` request for the active group, resolved to its outcome. */
1655
- private signRequest;
1656
- /** The `setActiveGroup` re-point: the solana session's new `WalletAccount[]` for `change`. */
1657
- solanaAccountsChanged(_origin: string): Promise<SolanaWalletAccount[]>;
1658
- }
1659
- /** A WebLN method call from the page. */
1660
- type WeblnRequest = {
1661
- readonly method: string;
1662
- readonly params?: unknown;
1663
- };
1664
- type WeblnHandlerOptions = {
1665
- readonly connections: Pick<ConnectionController, "checkOrigin" | "authorize" | "session" | "lightningPolicy" | "request" | "touch">;
1666
- readonly requests: Pick<RequestController, "prepare" | "outcome">;
1667
- readonly spark: Pick<SparkController, "accountBalance" | "paymentStatus">;
1668
- /** The active group's Spark account — `undefined` when no group is selected. */
1669
- readonly sparkAccount: () => SparkAccountRef | undefined;
1670
- readonly now: () => number;
1671
- /** The node's display alias — host-configured, never a pubkey. */
1672
- readonly alias: string;
1673
- /** The host's lightning fee cap — `pay`'s `maxFeeSats` comes from here. */
1674
- readonly lightningMaxFee: (amountSats: number) => number;
1675
- /** The injected wait for the preimage poll. */
1676
- readonly sleep: (ms: number) => Promise<void>;
1677
- };
1678
- declare class WeblnHandler {
1679
- private readonly options;
1680
- constructor(options: WeblnHandlerOptions);
1681
- private ref;
1682
- handle(origin: string, request: WeblnRequest): Promise<unknown>;
1683
- private sendPayment;
1684
- private makeInvoice;
1685
- private lnurl;
1686
- private preimage;
1687
- private lightningOption;
1688
- private getBalance;
1689
- }
1690
- /** EIP-1193 / EIP-1474 / EIP-3326 error: `code` is what the page's promise rejects with. */
1691
- declare class ProviderError extends Error {
1692
- readonly code: number;
1693
- constructor(code: number, message: string);
1694
- }
1695
- 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 };
1696
- //# sourceMappingURL=errors-DpkJneDe.d.mts.map