@qntx/wallet-engine 0.7.0 → 0.8.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.
- package/README.md +2 -0
- package/dist/connect.d.mts +45 -0
- package/dist/connect.mjs +174 -0
- package/dist/connect.mjs.map +1 -0
- package/dist/errors-CW_XXGL9.d.mts +1296 -0
- package/dist/gateway-contract.mjs +183 -1
- package/dist/gateway-contract.mjs.map +1 -0
- package/dist/index.d.mts +18 -1000
- package/dist/index.mjs +587 -939
- package/dist/index.mjs.map +1 -1
- package/dist/registry-CHiAn88k.mjs +98 -0
- package/dist/registry-CHiAn88k.mjs.map +1 -0
- package/dist/webln-CHjBMRcv.mjs +1247 -0
- package/dist/webln-CHjBMRcv.mjs.map +1 -0
- package/package.json +27 -16
- package/dist/contract-CEsgLme3.mjs +0 -277
- package/dist/contract-CEsgLme3.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,1014 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StoreApi } from "zustand/vanilla";
|
|
3
|
-
import { SignRequest } from "@qntx/wallet-chains";
|
|
1
|
+
import { $ as sparkStore, A as RiskFinding, B as ParseOptions, C as SparkDepositInput, Ct as Controller, D as BrowserOrigin, E as SignLogOutcome, F as PreparedZap, G as PreparedSparkAction, H as PaymentParse, I as ZapRecipient, J as SparkAccountState, K as SparkDisplay, L as prepareZap, M as SignatureResult, N as PrepareZapContext, O as RequestMethod, P as PrepareZapParams, Q as SparkControllerState, R as PayParams, S as RequestStage, St as createEventBus, T as SignLogEntry, U as PaymentRequest, V as PaymentOption, W as parsePayment, X as SparkController, Y as SparkClientFactory, Z as SparkControllerOptions, _ as PendingRequest, _t as PendingConnection, at as AddressBookEntry, b as RequestControllerState, bt as EngineLogger, ct as NetworkController, dt as ConnectionController, et as PaymentNote, f as Eip1193Event, ft as ConnectionOrigin, g as PayInput, h as EvmSignInput, ht as ConnectionState, it as AddressBookState, j as TransactionController, k as RequestOrigin, l as SolanaWalletHandler, lt as Esplora, m as Eip1193Request, mt as ConnectionSession, n as WeblnHandler, nt as RequestCheckCode, ot as AddressBookRecord, p as Eip1193Handler, pt as ConnectionScope, q as SparkResult, rt as AddressBookController, st as AddressFamily, t as ProviderError, tt as SparkActivity, u as Nip07Handler, ut as AccountGroup$1, v as REQUEST_TTL_MS, vt as EngineCollection, w as SparkExitInput, wt as ControllerOptions, x as RequestInput, xt as EventBus, y as RequestController, yt as EngineStore, z as WithdrawLnurlParams } from "./errors-CW_XXGL9.mjs";
|
|
4
2
|
import { BackupHeader, BackupInfo, InitialFactor, UnlockFactor, Wallet, WalletInfo } from "@qntx/wallet";
|
|
5
|
-
import "@
|
|
6
|
-
import {
|
|
7
|
-
import { decodeEvm } from "@qntx/wallet-chains/evm";
|
|
8
|
-
import { LnurlPayRequest, LnurlWithdrawRequest } from "@qntx/spark/lnurl";
|
|
9
|
-
import { Event, Filter, NostrSigner } from "@qntx/nostr";
|
|
10
|
-
import { chains } from "@qntx/wallet/chains";
|
|
3
|
+
import { LightningInvoice, SparkExitChain, SparkNetwork } from "@qntx/spark";
|
|
4
|
+
import { Event, Filter } from "@qntx/nostr";
|
|
11
5
|
import { WalletSyncSigner } from "@qntx/wallet/nostr";
|
|
12
|
-
import { SparkSigner } from "@qntx/wallet/spark";
|
|
13
|
-
import { PublicClient } from "viem";
|
|
14
|
-
import "@solana/kit";
|
|
15
|
-
import "@scure/btc-signer/psbt.js";
|
|
16
|
-
import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
|
|
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
|
-
export 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
|
-
export declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
|
|
45
6
|
type EngineErrorCode = "closed" | "integrity" | "invalid-input";
|
|
46
7
|
/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */
|
|
47
8
|
export declare class EngineStoreError extends Error {
|
|
48
9
|
readonly code: EngineErrorCode;
|
|
49
10
|
constructor(code: EngineErrorCode, message: string);
|
|
50
11
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
|
|
53
|
-
* the same collection object backs every call, so guards (closed) live on the store.
|
|
54
|
-
*/
|
|
55
|
-
type EngineCollection = {
|
|
56
|
-
readonly get: (key: string) => Promise<Uint8Array | undefined>;
|
|
57
|
-
readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
|
|
58
|
-
readonly delete: (key: string) => Promise<void>;
|
|
59
|
-
/** Every key in the collection, in an unspecified order. */
|
|
60
|
-
readonly list: () => Promise<ReadonlyArray<string>>;
|
|
61
|
-
};
|
|
62
|
-
type EngineStore = {
|
|
63
|
-
readonly collection: (name: string) => EngineCollection;
|
|
64
|
-
readonly close: () => Promise<void>;
|
|
65
|
-
};
|
|
66
12
|
/** In-memory EngineStore: the Node/test implementation — same contract, no durability. */
|
|
67
13
|
export declare function createMemoryEngineStore(backing?: {
|
|
68
14
|
readonly collections?: Map<string, Map<string, Uint8Array>>;
|
|
69
15
|
}): EngineStore;
|
|
70
|
-
type ConnectionOrigin = {
|
|
71
|
-
readonly kind: "browser";
|
|
72
|
-
readonly origin: string;
|
|
73
|
-
};
|
|
74
|
-
type ConnectionScope = {
|
|
75
|
-
/** CAIP-10 */
|
|
76
|
-
readonly accounts: ReadonlyArray<string>;
|
|
77
|
-
readonly methods: ReadonlyArray<string>;
|
|
78
|
-
readonly notifications: ReadonlyArray<string>;
|
|
79
|
-
};
|
|
80
|
-
type ConnectionSession = {
|
|
81
|
-
readonly id: string;
|
|
82
|
-
readonly origin: ConnectionOrigin;
|
|
83
|
-
/** Keyed by CAIP-2. */
|
|
84
|
-
readonly scopes: Readonly<Record<string, ConnectionScope>>;
|
|
85
|
-
/** The session's current EVM network; only dApp sessions have one. */
|
|
86
|
-
readonly currentNetwork: string;
|
|
87
|
-
readonly createdAt: number;
|
|
88
|
-
readonly lastUsedAt: number;
|
|
89
|
-
};
|
|
90
|
-
/** `connect` asks for accounts; `network` asks to add a network the session does not cover. */
|
|
91
|
-
type PendingConnection = {
|
|
92
|
-
readonly id: string;
|
|
93
|
-
readonly origin: ConnectionOrigin;
|
|
94
|
-
readonly kind: "connect" | "network";
|
|
95
|
-
readonly network?: string;
|
|
96
|
-
readonly createdAt: number;
|
|
97
|
-
};
|
|
98
|
-
type AccountGroup$1 = {
|
|
99
|
-
readonly walletId: string;
|
|
100
|
-
readonly groupIndex: number;
|
|
101
|
-
};
|
|
102
|
-
type ConnectionState = {
|
|
103
|
-
readonly sessions: Readonly<Record<string, ConnectionSession>>;
|
|
104
|
-
readonly pending: Readonly<Record<string, PendingConnection>>;
|
|
105
|
-
};
|
|
106
|
-
type ConnectionControllerOptions = {
|
|
107
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
108
|
-
readonly random: (n: number) => Uint8Array;
|
|
109
|
-
readonly now: () => number;
|
|
110
|
-
readonly logger: EngineLogger;
|
|
111
|
-
/** Development builds also accept `http://localhost`. */
|
|
112
|
-
readonly allowLocalhost: boolean;
|
|
113
|
-
/** The group the app currently shows; sessions are bound to it. */
|
|
114
|
-
readonly selectedGroup: () => AccountGroup$1 | undefined;
|
|
115
|
-
/** The group's EVM address on `network`. */
|
|
116
|
-
readonly evmAddress: (group: AccountGroup$1, network: string) => Promise<string>;
|
|
117
|
-
readonly enabledNetworks: () => ReadonlyArray<string>;
|
|
118
|
-
/** Voids a page's unfinished requests (revoked, or its network changed). */
|
|
119
|
-
readonly invalidate: (origin: string) => void;
|
|
120
|
-
};
|
|
121
|
-
export declare class ConnectionController extends Controller<ConnectionState> {
|
|
122
|
-
private readonly options;
|
|
123
|
-
private engineStore;
|
|
124
|
-
private readonly waiters;
|
|
125
|
-
private group;
|
|
126
|
-
constructor(options: ConnectionControllerOptions);
|
|
127
|
-
init(): Promise<void>;
|
|
128
|
-
destroy(): Promise<void>;
|
|
129
|
-
/** Locking is not consent: every pending connection is rejected. */
|
|
130
|
-
lock(): void;
|
|
131
|
-
/** Throws `4100` unless `origin` is `https://host[:port]` (or localhost in development). */
|
|
132
|
-
checkOrigin(origin: string): ConnectionOrigin;
|
|
133
|
-
session(origin: string): ConnectionSession | undefined;
|
|
134
|
-
pending(): ReadonlyArray<PendingConnection>;
|
|
135
|
-
/** The group sessions are bound to: the host's last `setActiveGroup`, else the app's selection. */
|
|
136
|
-
activeGroup(): AccountGroup$1 | undefined;
|
|
137
|
-
/** Whether `network` is an EVM network the wallet has enabled. */
|
|
138
|
-
isEnabled(network: string): boolean;
|
|
139
|
-
/** The origin's authorized addresses on its current network; empty when not connected. */
|
|
140
|
-
accounts(origin: string): ReadonlyArray<string>;
|
|
141
|
-
/** Throws `4100` unless the origin's session covers `method` on `network`. */
|
|
142
|
-
authorize(origin: string, network: string, method: string): ConnectionSession;
|
|
143
|
-
/** Resolves with the session once the host approves; rejects with `4001` when it refuses. */
|
|
144
|
-
request(origin: string, kind: PendingConnection["kind"], network?: string): Promise<ConnectionSession>;
|
|
145
|
-
/**
|
|
146
|
-
* The host's approval, by id: the accounts granted (EVM addresses of the active group) and the
|
|
147
|
-
* network.
|
|
148
|
-
*/
|
|
149
|
-
approveConnection(id: string, grant: {
|
|
150
|
-
readonly accounts: ReadonlyArray<string>;
|
|
151
|
-
readonly network: string;
|
|
152
|
-
}): Promise<ConnectionSession>;
|
|
153
|
-
rejectConnection(id: string): void;
|
|
154
|
-
/** Ends the origin's session; its pending connection and unfinished requests are void. */
|
|
155
|
-
revoke(origin: string): Promise<void>;
|
|
156
|
-
/** Switches within the session's scope; the origin's unfinished requests are void. */
|
|
157
|
-
setCurrentNetwork(origin: string, network: string): Promise<void>;
|
|
158
|
-
touch(origin: string): Promise<void>;
|
|
159
|
-
/**
|
|
160
|
-
* The host switched account group: every session's accounts become the new group's addresses. A
|
|
161
|
-
* session that cannot get one (no address derivable) is left with an empty list and has to be
|
|
162
|
-
* authorized again.
|
|
163
|
-
*/
|
|
164
|
-
setActiveGroup(walletId: string, groupIndex: number): Promise<void>;
|
|
165
|
-
private dropPending;
|
|
166
|
-
private persist;
|
|
167
|
-
private requireStore;
|
|
168
|
-
}
|
|
169
|
-
type Esplora = {
|
|
170
|
-
readonly get: (path: string) => Promise<unknown>;
|
|
171
|
-
readonly post: (path: string, body: string) => Promise<unknown>;
|
|
172
|
-
};
|
|
173
|
-
type SolanaRpc = {
|
|
174
|
-
readonly call: (method: string, params: unknown[]) => Promise<unknown>;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
|
|
178
|
-
* not this network's first endpoint, so the primary reads already come from the host.
|
|
179
|
-
* `unavailable`: a cross-check is needed but the network has no host endpoint.
|
|
180
|
-
*/
|
|
181
|
-
type Independent<T> = {
|
|
182
|
-
readonly kind: "not-needed";
|
|
183
|
-
} | {
|
|
184
|
-
readonly kind: "unavailable";
|
|
185
|
-
} | {
|
|
186
|
-
readonly kind: "available";
|
|
187
|
-
readonly client: T;
|
|
188
|
-
};
|
|
189
|
-
type NetworkControllerState = {
|
|
190
|
-
readonly customRpc: Record<string, ReadonlyArray<string>>;
|
|
191
|
-
};
|
|
192
|
-
type Options$2 = {
|
|
193
|
-
readonly fetch: typeof globalThis.fetch;
|
|
194
|
-
readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
195
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
196
|
-
readonly logger: EngineLogger;
|
|
197
|
-
readonly gateway?: {
|
|
198
|
-
readonly url: string;
|
|
199
|
-
readonly installId: string;
|
|
200
|
-
} | undefined;
|
|
201
|
-
};
|
|
202
|
-
declare class NetworkController extends Controller<NetworkControllerState> {
|
|
203
|
-
private readonly options;
|
|
204
|
-
private engineStore?;
|
|
205
|
-
private readonly clients;
|
|
206
|
-
private readonly gatewayBase;
|
|
207
|
-
private readonly gatewayOrigin;
|
|
208
|
-
/** Networks the gateway reported at unlock; empty while locked or when the read failed. */
|
|
209
|
-
private gatewayServed;
|
|
210
|
-
constructor(options: Options$2);
|
|
211
|
-
init(): Promise<void>;
|
|
212
|
-
private loadCustomRpc;
|
|
213
|
-
/** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
|
|
214
|
-
private loadGatewayNetworks;
|
|
215
|
-
/** `fetch` that adds the install id to requests bound for the gateway's origin only. */
|
|
216
|
-
private readonly gatewayFetch;
|
|
217
|
-
destroy(): Promise<void>;
|
|
218
|
-
lock(): void;
|
|
219
|
-
/**
|
|
220
|
-
* Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
|
|
221
|
-
* otherwise a gateway-served network uses gateway → host; else host only.
|
|
222
|
-
*/
|
|
223
|
-
endpoints(network: string): ReadonlyArray<string>;
|
|
224
|
-
info(network: string): NetworkInfo;
|
|
225
|
-
client(network: string): PublicClient;
|
|
226
|
-
/** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
|
|
227
|
-
private gatewayFirst;
|
|
228
|
-
private independent;
|
|
229
|
-
/** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
|
|
230
|
-
independentClient(network: string): Independent<PublicClient>;
|
|
231
|
-
independentSolanaRpc(network: string): Independent<SolanaRpc>;
|
|
232
|
-
independentEsplora(network: string): Independent<Esplora>;
|
|
233
|
-
/** Networks with at least one configured endpoint or served by the gateway, by family. */
|
|
234
|
-
enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
|
|
235
|
-
/** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
|
|
236
|
-
solanaRpc(network: string): SolanaRpc;
|
|
237
|
-
/** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
|
|
238
|
-
esplora(network: string): Esplora;
|
|
239
|
-
/** Validate a custom endpoint's reported chain id, then persist it first in the list. */
|
|
240
|
-
addRpc(network: string, url: string): Promise<void>;
|
|
241
|
-
}
|
|
242
|
-
type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
|
|
243
|
-
type AddressBookEntry = {
|
|
244
|
-
readonly id: string;
|
|
245
|
-
readonly name: string;
|
|
246
|
-
readonly family: AddressFamily;
|
|
247
|
-
readonly address: string;
|
|
248
|
-
readonly note?: string;
|
|
249
|
-
readonly createdAt: number;
|
|
250
|
-
readonly updatedAt: number;
|
|
251
|
-
};
|
|
252
|
-
type AddressBookTombstone = {
|
|
253
|
-
readonly id: string;
|
|
254
|
-
readonly deleted: true;
|
|
255
|
-
readonly updatedAt: number;
|
|
256
|
-
};
|
|
257
|
-
type AddressBookRecord = AddressBookEntry | AddressBookTombstone;
|
|
258
|
-
type AddressBookState = {
|
|
259
|
-
/** Live entries only; tombstones stay internal. */
|
|
260
|
-
readonly entries: Record<string, AddressBookEntry>;
|
|
261
|
-
};
|
|
262
|
-
type AddressBookOptions = {
|
|
263
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
264
|
-
readonly random: (n: number) => Uint8Array;
|
|
265
|
-
readonly now: () => number;
|
|
266
|
-
readonly logger: EngineLogger;
|
|
267
|
-
};
|
|
268
|
-
export declare class AddressBookController extends Controller<AddressBookState> {
|
|
269
|
-
private readonly options;
|
|
270
|
-
private engineStore;
|
|
271
|
-
/** Every record, tombstones included, by id. */
|
|
272
|
-
private records;
|
|
273
|
-
constructor(options: AddressBookOptions);
|
|
274
|
-
init(): Promise<void>;
|
|
275
|
-
destroy(): Promise<void>;
|
|
276
|
-
lock(): void;
|
|
277
|
-
/** Entries and tombstones, for the metadata document. */
|
|
278
|
-
syncEntries(): ReadonlyArray<AddressBookRecord>;
|
|
279
|
-
/**
|
|
280
|
-
* Merges records from another device (last writer wins, tombstones win over older entries).
|
|
281
|
-
* Returns whether anything local changed and whether the merged set holds something `remote`
|
|
282
|
-
* lacks, i.e. whether the remote copy needs a newer publish.
|
|
283
|
-
*/
|
|
284
|
-
merge(remote: ReadonlyArray<AddressBookRecord>): Promise<{
|
|
285
|
-
readonly changed: boolean;
|
|
286
|
-
readonly localNewer: boolean;
|
|
287
|
-
}>;
|
|
288
|
-
add(params: {
|
|
289
|
-
readonly name: string;
|
|
290
|
-
readonly family: AddressFamily;
|
|
291
|
-
readonly address: string;
|
|
292
|
-
readonly note?: string;
|
|
293
|
-
}): Promise<AddressBookEntry>;
|
|
294
|
-
rename(id: string, name: string): Promise<AddressBookEntry>;
|
|
295
|
-
/** Sets or clears (empty or `undefined`) the note. */
|
|
296
|
-
setNote(id: string, note: string | undefined): Promise<AddressBookEntry>;
|
|
297
|
-
/** Removes the entry, leaving a tombstone so other devices drop it too. */
|
|
298
|
-
remove(id: string): Promise<void>;
|
|
299
|
-
private checkedNote;
|
|
300
|
-
private requireEntry;
|
|
301
|
-
private persist;
|
|
302
|
-
private requireStore;
|
|
303
|
-
}
|
|
304
|
-
type EvmFeeTier = "slow" | "normal" | "fast";
|
|
305
|
-
type SolanaFeeTier = "slow" | "normal" | "fast";
|
|
306
|
-
type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount";
|
|
307
|
-
/**
|
|
308
|
-
* Local, engine-side metadata pinned to a history entry by transfer id. Written after the payment
|
|
309
|
-
* it annotates has already succeeded — a missing or malformed note must never affect the payment
|
|
310
|
-
* itself.
|
|
311
|
-
*/
|
|
312
|
-
type PaymentNote = {
|
|
313
|
-
readonly kind: "zap";
|
|
314
|
-
/** 64 lowercase hex. */
|
|
315
|
-
readonly recipientPubkey: string;
|
|
316
|
-
/** 64 lowercase hex — event zaps carry the zapped event's id. */
|
|
317
|
-
readonly eventId?: string;
|
|
318
|
-
/** At most 2000 characters. */
|
|
319
|
-
readonly comment?: string;
|
|
320
|
-
/** The lud16 or LNURL the zap resolved. */
|
|
321
|
-
readonly lightning: string;
|
|
322
|
-
};
|
|
323
|
-
type SparkActivity = SparkPayment & {
|
|
324
|
-
readonly note?: PaymentNote;
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* SparkStore over one EngineCollection: chains keyed by leafId, plus an index record listing them
|
|
328
|
-
* (`exitChains` is a full listing — the port has no secondary index).
|
|
329
|
-
*/
|
|
330
|
-
export declare function sparkStore(col: EngineCollection): SparkStore;
|
|
331
|
-
type SparkAccountState = {
|
|
332
|
-
readonly status: "locked" | "connecting" | "ready" | "error";
|
|
333
|
-
readonly balanceSats?: number;
|
|
334
|
-
readonly identityPublicKey?: string;
|
|
335
|
-
readonly sparkAddress?: string;
|
|
336
|
-
readonly errorCategory?: string;
|
|
337
|
-
/** First history page (20 entries, newest first), refreshed alongside the balance. */
|
|
338
|
-
readonly recent?: ReadonlyArray<SparkActivity>;
|
|
339
|
-
};
|
|
340
|
-
type SparkControllerState = {
|
|
341
|
-
readonly accounts: Readonly<Record<string, SparkAccountState>>;
|
|
342
|
-
};
|
|
343
|
-
type SparkApis = {
|
|
344
|
-
readonly signer: (ref: SparkAccountRef) => SparkSigner;
|
|
345
|
-
readonly approve: (params: {
|
|
346
|
-
account: SparkAccountRef;
|
|
347
|
-
intent: SparkApproveIntent;
|
|
348
|
-
verify: UnlockFactor;
|
|
349
|
-
}) => Promise<unknown>;
|
|
350
|
-
};
|
|
351
|
-
type SparkClientFactory = (options: {
|
|
352
|
-
readonly ref: SparkAccountRef;
|
|
353
|
-
readonly store: ReturnType<typeof sparkStore>;
|
|
354
|
-
readonly signer: SparkSigner;
|
|
355
|
-
readonly fetch: typeof globalThis.fetch;
|
|
356
|
-
}) => SparkClient;
|
|
357
|
-
type SparkControllerOptions = {
|
|
358
|
-
readonly spark: SparkApis;
|
|
359
|
-
readonly fetch: typeof globalThis.fetch;
|
|
360
|
-
readonly random: (length: number) => Uint8Array;
|
|
361
|
-
readonly now: () => number;
|
|
362
|
-
readonly logger: EngineLogger;
|
|
363
|
-
readonly createClient: SparkClientFactory;
|
|
364
|
-
};
|
|
365
|
-
export declare class SparkController extends Controller<SparkControllerState> {
|
|
366
|
-
private readonly options;
|
|
367
|
-
private engineStore;
|
|
368
|
-
private readonly accounts;
|
|
369
|
-
private readonly clients;
|
|
370
|
-
private readonly recentSeq;
|
|
371
|
-
private readonly aborts;
|
|
372
|
-
constructor(options: SparkControllerOptions);
|
|
373
|
-
/** Engine calls this with the open store on unlock; `undefined` on lock. */
|
|
374
|
-
setStore(store: EngineStore | undefined): void;
|
|
375
|
-
/**
|
|
376
|
-
* Declarative account set: refs not yet tracked are patched `locked` and started when the store
|
|
377
|
-
* is open; tracked refs no longer listed are stopped and dropped; running refs stay untouched.
|
|
378
|
-
*/
|
|
379
|
-
setAccounts(refs: ReadonlyArray<SparkAccountRef>): void;
|
|
380
|
-
init(): Promise<void>;
|
|
381
|
-
destroy(): Promise<void>;
|
|
382
|
-
private stopAccount;
|
|
383
|
-
/** Lock: abort every event loop, close every client, reset state. */
|
|
384
|
-
lockAll(): Promise<void>;
|
|
385
|
-
private startAccount;
|
|
386
|
-
private runEvents;
|
|
387
|
-
private handleTransfer;
|
|
388
|
-
private notesCollection;
|
|
389
|
-
/** Attach locally written notes to a history page; malformed records warn and drop. */
|
|
390
|
-
private withNotes;
|
|
391
|
-
/**
|
|
392
|
-
* Refill `recent` from the first history page. A failure keeps the previous page — it never
|
|
393
|
-
* touches `status`/`errorCategory`. A per-account sequence keeps a slower older refresh from
|
|
394
|
-
* overwriting a newer one.
|
|
395
|
-
*/
|
|
396
|
-
private refreshRecent;
|
|
397
|
-
private patch;
|
|
398
|
-
private clientFor;
|
|
399
|
-
private guarded;
|
|
400
|
-
/**
|
|
401
|
-
* One-off balance + activity probe for an account that may not be running: builds a temporary
|
|
402
|
-
* client through the same factory on the account's own exit-chain collection (nothing diverges —
|
|
403
|
-
* `balance()`/`transfers.history` never write it), reads, and closes it in `finally`.
|
|
404
|
-
*/
|
|
405
|
-
inspect(ref: SparkAccountRef): Promise<{
|
|
406
|
-
balanceSats: number;
|
|
407
|
-
used: boolean;
|
|
408
|
-
}>;
|
|
409
|
-
/** History for one account: a client page merged with locally written notes by id. */
|
|
410
|
-
history(ref: SparkAccountRef, options?: {
|
|
411
|
-
readonly limit?: number;
|
|
412
|
-
readonly offset?: number;
|
|
413
|
-
}): Promise<{
|
|
414
|
-
readonly items: ReadonlyArray<SparkActivity>;
|
|
415
|
-
readonly nextOffset: number | undefined;
|
|
416
|
-
}>;
|
|
417
|
-
send(ref: SparkAccountRef, params: {
|
|
418
|
-
receiver: string;
|
|
419
|
-
amountSats: number;
|
|
420
|
-
verify: UnlockFactor;
|
|
421
|
-
}): Promise<SparkTransfer>;
|
|
422
|
-
registerLightningAddress(ref: SparkAccountRef, params: {
|
|
423
|
-
serverUrl: string;
|
|
424
|
-
domain: string;
|
|
425
|
-
username: string;
|
|
426
|
-
description: string;
|
|
427
|
-
}): Promise<{
|
|
428
|
-
lnurl: string;
|
|
429
|
-
lightningAddress: string;
|
|
430
|
-
}>;
|
|
431
|
-
unregisterLightningAddress(ref: SparkAccountRef, params: {
|
|
432
|
-
serverUrl: string;
|
|
433
|
-
domain: string;
|
|
434
|
-
username: string;
|
|
435
|
-
}): Promise<void>;
|
|
436
|
-
payInvoice(ref: SparkAccountRef, params: {
|
|
437
|
-
invoice: string;
|
|
438
|
-
amountSats?: number;
|
|
439
|
-
maxFeeSats: number;
|
|
440
|
-
verify: UnlockFactor;
|
|
441
|
-
/** Local annotation written under the payment's transfer id after it succeeds. */
|
|
442
|
-
note?: PaymentNote;
|
|
443
|
-
}): Promise<LightningPayment>;
|
|
444
|
-
/**
|
|
445
|
-
* Pays a Spark invoice address. The approval intent mirrors `send`: receiver identity and amount
|
|
446
|
-
* come from the parsed invoice (the supplied `amountSats` fills an open invoice). Then
|
|
447
|
-
* `client.invoices.pay` executes it.
|
|
448
|
-
*/
|
|
449
|
-
paySparkInvoice(ref: SparkAccountRef, params: {
|
|
450
|
-
invoice: string;
|
|
451
|
-
amountSats?: number;
|
|
452
|
-
verify: UnlockFactor;
|
|
453
|
-
}): Promise<SparkTransfer>;
|
|
454
|
-
createInvoice(ref: SparkAccountRef, params: {
|
|
455
|
-
amountSats: number;
|
|
456
|
-
memo?: string;
|
|
457
|
-
}): Promise<LightningInvoice>;
|
|
458
|
-
/** A fresh single-use L1 deposit address (with the SO's proof of possession). */
|
|
459
|
-
newDepositAddress(ref: SparkAccountRef): Promise<string>;
|
|
460
|
-
/** Claims a confirmed L1 deposit paying one of the account's unused deposit addresses. */
|
|
461
|
-
claimDeposit(ref: SparkAccountRef, transaction: Uint8Array): Promise<void>;
|
|
462
|
-
receiveAddress(ref: SparkAccountRef): Promise<string | undefined>;
|
|
463
|
-
/**
|
|
464
|
-
* Cooperative exit to an L1 address. The client exits `amountSats` of leaves and the payout is
|
|
465
|
-
* `amountSats - fee`, so the approval intent carries the PAYOUT: `amountSats: exit - fee` and
|
|
466
|
-
* `maxFeeSats: fee` — the kernel matches the exit output against the intent, not the leaf total.
|
|
467
|
-
*/
|
|
468
|
-
withdraw(ref: SparkAccountRef, params: {
|
|
469
|
-
address: string;
|
|
470
|
-
amountSats?: number;
|
|
471
|
-
speed: "FAST" | "MEDIUM" | "SLOW";
|
|
472
|
-
maxFeeSats?: number;
|
|
473
|
-
verify: UnlockFactor;
|
|
474
|
-
}): Promise<CooperativeExitResult>;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* What the host shows for a Spark, Lightning or exit request; `family` tells it apart from a chain
|
|
478
|
-
* intent.
|
|
479
|
-
*/
|
|
480
|
-
type SparkDisplay = {
|
|
481
|
-
readonly family: "spark";
|
|
482
|
-
readonly network: SparkNetwork;
|
|
483
|
-
readonly kind: "transfer" | "lightning" | "exit";
|
|
484
|
-
readonly amountSats: number;
|
|
485
|
-
readonly maxFeeSats?: number;
|
|
486
|
-
/** Spark address, Lightning payee public key (hex) or bitcoin address. */
|
|
487
|
-
readonly receiver: string;
|
|
488
|
-
/** Invoice description or the LNURL metadata text. */
|
|
489
|
-
readonly description?: string;
|
|
490
|
-
};
|
|
491
|
-
type SparkResult = {
|
|
492
|
-
readonly kind: "spark";
|
|
493
|
-
readonly transfer: SparkTransfer;
|
|
494
|
-
} | {
|
|
495
|
-
readonly kind: "lightning";
|
|
496
|
-
readonly payment: LightningPayment;
|
|
497
|
-
} | {
|
|
498
|
-
readonly kind: "withdraw";
|
|
499
|
-
readonly exit: CooperativeExitResult;
|
|
500
|
-
};
|
|
501
|
-
/**
|
|
502
|
-
* A validated, fixed Spark payment: everything that does not need the user's verification has
|
|
503
|
-
* happened (including any LNURL invoice fetch), so approval only re-checks expiry and executes.
|
|
504
|
-
*/
|
|
505
|
-
type PreparedSparkAction = {
|
|
506
|
-
readonly display: SparkDisplay;
|
|
507
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
508
|
-
/** Why the action can no longer be paid at `now` (an expiring invoice), if so. */
|
|
509
|
-
readonly staleReason: (now: number) => string | undefined;
|
|
510
|
-
/** Runs the controller's approve-first payment call. */
|
|
511
|
-
readonly execute: (spark: SparkController, verify: UnlockFactor) => Promise<SparkResult>;
|
|
512
|
-
};
|
|
513
|
-
type PaymentOption = {
|
|
514
|
-
readonly kind: "spark";
|
|
515
|
-
readonly address: string;
|
|
516
|
-
} | {
|
|
517
|
-
readonly kind: "spark-invoice";
|
|
518
|
-
readonly invoice: string;
|
|
519
|
-
readonly amountSats?: number;
|
|
520
|
-
readonly memo?: string;
|
|
521
|
-
readonly expiresAt?: number;
|
|
522
|
-
} | {
|
|
523
|
-
readonly kind: "lightning";
|
|
524
|
-
readonly invoice: string;
|
|
525
|
-
readonly amountSats?: number;
|
|
526
|
-
readonly paymentHash: string;
|
|
527
|
-
readonly description?: string;
|
|
528
|
-
readonly expiresAt: number;
|
|
529
|
-
} | {
|
|
530
|
-
readonly kind: "lnurl-pay";
|
|
531
|
-
readonly request: LnurlPayRequest;
|
|
532
|
-
readonly address?: string;
|
|
533
|
-
} | {
|
|
534
|
-
readonly kind: "lnurl-withdraw";
|
|
535
|
-
readonly request: LnurlWithdrawRequest;
|
|
536
|
-
} | {
|
|
537
|
-
readonly kind: "bitcoin";
|
|
538
|
-
readonly address: string;
|
|
539
|
-
};
|
|
540
|
-
type PaymentRequest = {
|
|
541
|
-
readonly options: ReadonlyArray<PaymentOption>;
|
|
542
|
-
readonly amountSats?: number;
|
|
543
|
-
readonly label?: string;
|
|
544
|
-
readonly message?: string;
|
|
545
|
-
};
|
|
546
|
-
type PaymentParse = {
|
|
547
|
-
readonly kind: "request";
|
|
548
|
-
readonly request: PaymentRequest;
|
|
549
|
-
} | {
|
|
550
|
-
readonly kind: "lnurl";
|
|
551
|
-
readonly url: string;
|
|
552
|
-
readonly address?: string;
|
|
553
|
-
} | {
|
|
554
|
-
readonly kind: "unsupported";
|
|
555
|
-
readonly format: "bolt12" | "silent-payment" | "lnurl-auth" | "spark-token-invoice" | "nostr-wallet-connect";
|
|
556
|
-
} | {
|
|
557
|
-
readonly kind: "invalid";
|
|
558
|
-
readonly reason: "network" | "expired" | "amount-mismatch" | "malformed";
|
|
559
|
-
} | {
|
|
560
|
-
readonly kind: "unrecognized";
|
|
561
|
-
};
|
|
562
|
-
type ParseOptions = {
|
|
563
|
-
readonly network: SparkNetwork;
|
|
564
|
-
readonly now: number;
|
|
565
|
-
};
|
|
566
|
-
/** `input` → PaymentParse. Never throws: every failure is a structured result. */
|
|
567
|
-
export declare function parsePayment(input: string, options: ParseOptions): PaymentParse;
|
|
568
|
-
type PayParams = {
|
|
569
|
-
readonly account: SparkAccountRef;
|
|
570
|
-
readonly option: PaymentOption;
|
|
571
|
-
/** Caller-supplied amount — required by open invoices, the `spark` option, and LNURL flows. */
|
|
572
|
-
readonly amountSats?: number;
|
|
573
|
-
readonly comment?: string;
|
|
574
|
-
readonly maxFeeSats?: number;
|
|
575
|
-
readonly speed?: "FAST" | "MEDIUM" | "SLOW";
|
|
576
|
-
};
|
|
577
|
-
type WithdrawLnurlParams = {
|
|
578
|
-
readonly account: SparkAccountRef;
|
|
579
|
-
readonly option: Extract<PaymentOption, {
|
|
580
|
-
kind: "lnurl-withdraw";
|
|
581
|
-
}>;
|
|
582
|
-
readonly amountSats: number;
|
|
583
|
-
};
|
|
584
|
-
/** A profile zap names the recipient pubkey; an event zap carries the event it zaps. */
|
|
585
|
-
type ZapRecipient = {
|
|
586
|
-
readonly pubkey: string;
|
|
587
|
-
readonly lightning: string;
|
|
588
|
-
} | {
|
|
589
|
-
readonly event: Event;
|
|
590
|
-
readonly lightning: string;
|
|
591
|
-
};
|
|
592
|
-
type PrepareZapParams = {
|
|
593
|
-
/** Any `NostrSigner` — wallet key, external key, NIP-07/46 — signs the 9734. */
|
|
594
|
-
readonly signer: NostrSigner;
|
|
595
|
-
readonly recipient: ZapRecipient;
|
|
596
|
-
readonly amountSats: number;
|
|
597
|
-
readonly comment?: string | undefined;
|
|
598
|
-
readonly relays: ReadonlyArray<string>;
|
|
599
|
-
readonly network: SparkNetwork;
|
|
600
|
-
};
|
|
601
|
-
type PrepareZapContext = {
|
|
602
|
-
readonly fetch: typeof globalThis.fetch;
|
|
603
|
-
readonly now: () => number;
|
|
604
|
-
};
|
|
605
|
-
/** Everything a payer needs: the signed 9734, the invoice, and the note fields. */
|
|
606
|
-
type PreparedZap = {
|
|
607
|
-
readonly zapRequest: Event;
|
|
608
|
-
readonly invoice: string;
|
|
609
|
-
/** Hex payment hash decoded from the invoice. */
|
|
610
|
-
readonly paymentHash: string;
|
|
611
|
-
/** Millisecond expiry decoded from the invoice. */
|
|
612
|
-
readonly expiresAt: number;
|
|
613
|
-
readonly amountSats: number;
|
|
614
|
-
/** The LNURL service's 9735 signing pubkey. */
|
|
615
|
-
readonly receiptPubkey: string;
|
|
616
|
-
readonly recipientPubkey: string;
|
|
617
|
-
readonly eventId?: string;
|
|
618
|
-
readonly comment?: string;
|
|
619
|
-
/** The lud16 or LNURL as given. */
|
|
620
|
-
readonly lightning: string;
|
|
621
|
-
};
|
|
622
|
-
/** Everything up to payment: resolve LNURL, sign the 9734, request the invoice. */
|
|
623
|
-
export declare function prepareZap(params: PrepareZapParams, context: PrepareZapContext): Promise<PreparedZap>;
|
|
624
|
-
type ChainApis = ReturnType<typeof chains>;
|
|
625
|
-
type SignParams = Parameters<ChainApis["sign"]>[0];
|
|
626
|
-
type AccountRef = SignParams["request"]["account"];
|
|
627
|
-
type DisplayIntent = ReturnType<typeof decodeEvm>;
|
|
628
|
-
type TxState = "draft" | "signed" | "submitted" | "pending" | "confirmed" | "failed" | "rejected" | "dropped" | "replaced";
|
|
629
|
-
/** A bitcoin transaction that funds the wallet's own Spark account; it is claimed once confirmed. */
|
|
630
|
-
type SparkDepositTag = {
|
|
631
|
-
readonly walletId: string;
|
|
632
|
-
readonly groupIndex: number;
|
|
633
|
-
readonly network: SparkNetwork;
|
|
634
|
-
readonly claimed?: boolean;
|
|
635
|
-
};
|
|
636
|
-
type TrackedTransaction = {
|
|
637
|
-
readonly id: string;
|
|
638
|
-
readonly family: "evm" | "solana" | "bitcoin";
|
|
639
|
-
readonly network: string;
|
|
640
|
-
readonly account: string;
|
|
641
|
-
readonly hash: string | undefined;
|
|
642
|
-
readonly state: TxState;
|
|
643
|
-
readonly intent: DisplayIntent | undefined;
|
|
644
|
-
readonly nonce: number;
|
|
645
|
-
/** Solana only — the blockhash expiry that turns an unconfirmed tx `dropped`. */
|
|
646
|
-
readonly lastValidBlockHeight?: number;
|
|
647
|
-
/** EVM replacement — the earlier transaction this one bumps or cancels. */
|
|
648
|
-
readonly replaces?: string;
|
|
649
|
-
/** CPFP — the unconfirmed parent this child pushes. */
|
|
650
|
-
readonly parentId?: string;
|
|
651
|
-
/** Set on a Spark deposit; `claimed` flips once the deposit is credited on Spark. */
|
|
652
|
-
readonly sparkDeposit?: SparkDepositTag;
|
|
653
|
-
/** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
|
|
654
|
-
readonly btc?: {
|
|
655
|
-
readonly inputs: ReadonlyArray<{
|
|
656
|
-
readonly txid: string;
|
|
657
|
-
readonly vout: number;
|
|
658
|
-
readonly value: number;
|
|
659
|
-
readonly address: string;
|
|
660
|
-
}>;
|
|
661
|
-
readonly outputs: ReadonlyArray<{
|
|
662
|
-
readonly address: string;
|
|
663
|
-
readonly value: number;
|
|
664
|
-
readonly own: boolean;
|
|
665
|
-
}>;
|
|
666
|
-
readonly vsize: number;
|
|
667
|
-
readonly fee: number;
|
|
668
|
-
readonly feeRate: number;
|
|
669
|
-
};
|
|
670
|
-
readonly submittedAt: number;
|
|
671
|
-
readonly error: string | undefined;
|
|
672
|
-
};
|
|
673
|
-
type SendParams = {
|
|
674
|
-
readonly account: AccountRef;
|
|
675
|
-
readonly network: string;
|
|
676
|
-
readonly to: string;
|
|
677
|
-
readonly amount: bigint;
|
|
678
|
-
/** ERC-20 contract — when set, `to`/`amount` are the transfer recipient/units and value is 0. */
|
|
679
|
-
readonly token?: string;
|
|
680
|
-
readonly fee: EvmFeeTier | SolanaFeeTier;
|
|
681
|
-
/** SPL mint decimals — required when `token` is a Solana mint. */
|
|
682
|
-
readonly decimals?: number;
|
|
683
|
-
readonly verify: SignParams["verify"];
|
|
684
|
-
};
|
|
685
|
-
type PrepareParams = Omit<SendParams, "verify">;
|
|
686
|
-
type ChainRequestMethod = "send" | "speed-up" | "cancel" | "cpfp";
|
|
687
|
-
/** What a request asks for; replacements and CPFP name the original transaction. */
|
|
688
|
-
type ChainRequestInput = ({
|
|
689
|
-
readonly method: "send";
|
|
690
|
-
} & PrepareParams) | {
|
|
691
|
-
readonly method: "speed-up" | "cancel";
|
|
692
|
-
readonly txId: string;
|
|
693
|
-
} | {
|
|
694
|
-
readonly method: "cpfp";
|
|
695
|
-
readonly txId: string;
|
|
696
|
-
readonly feeRate: number;
|
|
697
|
-
};
|
|
698
|
-
/**
|
|
699
|
-
* A fully built, estimated and cross-checked send that has not been signed. The unsigned content
|
|
700
|
-
* lives in the closures and cannot change after `prepare` returns.
|
|
701
|
-
*/
|
|
702
|
-
type PreparedRequest = {
|
|
703
|
-
/** Id of the tracked transaction `submit` creates. */
|
|
704
|
-
readonly txId: string;
|
|
705
|
-
readonly account: AccountRef;
|
|
706
|
-
readonly network: string;
|
|
707
|
-
/** The transaction being replaced or accelerated; absent for a plain send. */
|
|
708
|
-
readonly target?: string;
|
|
709
|
-
readonly intent: DisplayIntent;
|
|
710
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
711
|
-
/** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
|
|
712
|
-
readonly staleReason: () => string | undefined | Promise<string | undefined>;
|
|
713
|
-
/** Signs, finalizes, broadcasts and hands the transaction to tracking. */
|
|
714
|
-
readonly submit: (verify: SendParams["verify"]) => Promise<TrackedTransaction>;
|
|
715
|
-
/** Frees what `prepare` reserved; safe to call more than once. */
|
|
716
|
-
readonly release: () => void;
|
|
717
|
-
};
|
|
718
|
-
type SignatureResult = {
|
|
719
|
-
readonly kind: "evm.personal-message" | "evm.typed-data";
|
|
720
|
-
readonly signature: Uint8Array;
|
|
721
|
-
};
|
|
722
|
-
/** A prepared message signature: nothing is broadcast or tracked, `submit` returns the signature. */
|
|
723
|
-
type PreparedMessage = Omit<PreparedRequest, "submit" | "txId"> & {
|
|
724
|
-
readonly submit: (verify: SendParams["verify"]) => Promise<SignatureResult>;
|
|
725
|
-
};
|
|
726
|
-
type Options$1 = {
|
|
727
|
-
readonly wallet: Wallet;
|
|
728
|
-
readonly networks: NetworkController;
|
|
729
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
730
|
-
readonly random: (n: number) => Uint8Array;
|
|
731
|
-
readonly setTimer: (ms: number, fn: () => unknown) => () => void;
|
|
732
|
-
readonly now: () => number;
|
|
733
|
-
readonly logger: EngineLogger;
|
|
734
|
-
readonly pollMs?: number;
|
|
735
|
-
/** Test seam — defaults to the wallet's real chains proxy. */
|
|
736
|
-
readonly chains?: ReturnType<typeof chains>;
|
|
737
|
-
};
|
|
738
|
-
type TransactionControllerState = {
|
|
739
|
-
readonly txs: Record<string, TrackedTransaction>;
|
|
740
|
-
};
|
|
741
|
-
declare class TransactionController extends Controller<TransactionControllerState> {
|
|
742
|
-
private readonly options;
|
|
743
|
-
private engineStore?;
|
|
744
|
-
private readonly timers;
|
|
745
|
-
private evmRoute;
|
|
746
|
-
private bitcoinRoute;
|
|
747
|
-
private locked;
|
|
748
|
-
constructor(options: Options$1);
|
|
749
|
-
init(): Promise<void>;
|
|
750
|
-
destroy(): Promise<void>;
|
|
751
|
-
lock(): void;
|
|
752
|
-
private persist;
|
|
753
|
-
private transition;
|
|
754
|
-
private routeCtx;
|
|
755
|
-
/**
|
|
756
|
-
* Internal entry for the request pipeline: builds, estimates and cross-checks a send without
|
|
757
|
-
* signing it. Bitcoin outputs it selects stay locked under `requestId` until the returned
|
|
758
|
-
* `release` runs or the broadcast moves them to the transaction.
|
|
759
|
-
*/
|
|
760
|
-
prepareSend(params: PrepareParams, requestId: string, sparkDeposit?: SparkDepositTag): Promise<PreparedRequest>;
|
|
761
|
-
/** The group's next unused `btc.bip84` receive address on a bitcoin `network`. */
|
|
762
|
-
nextReceiveAddress(walletId: string, groupIndex: number, network: string): Promise<string>;
|
|
763
|
-
/** Records that a Spark deposit was credited; persisted with the transaction. */
|
|
764
|
-
markDepositClaimed(id: string): Promise<void>;
|
|
765
|
-
/**
|
|
766
|
-
* Internal entry for a dApp's EVM signature request: the request is normalized first, a
|
|
767
|
-
* transaction is rebuilt with fresh nonce and fees (the dApp's own are discarded), and a message
|
|
768
|
-
* is decoded and signed as is.
|
|
769
|
-
*/
|
|
770
|
-
prepareDapp(account: AccountRef, request: SignRequest): Promise<PreparedRequest | PreparedMessage>;
|
|
771
|
-
/**
|
|
772
|
-
* Internal entry for replacements and CPFP: builds, cross-checks and reserves what the
|
|
773
|
-
* replacement needs without signing it. The original must be `submitted` or `pending`.
|
|
774
|
-
*/
|
|
775
|
-
prepareReplacement(input: Exclude<ChainRequestInput, {
|
|
776
|
-
method: "send";
|
|
777
|
-
}>, requestId: string): Promise<PreparedRequest>;
|
|
778
|
-
private track;
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Recipient risk, pure: a recipient the wallet has never paid or saved is a `warning`; one that
|
|
782
|
-
* looks like a known address (same first and last four characters, different address) is a `danger`
|
|
783
|
-
* — the shape of an address-poisoning lookalike. Both can apply to one recipient.
|
|
784
|
-
*/
|
|
785
|
-
type RiskFinding = {
|
|
786
|
-
readonly code: "first-recipient" | "address-poisoning";
|
|
787
|
-
readonly level: "warning" | "danger";
|
|
788
|
-
};
|
|
789
|
-
/** A web page; `origin` is `scheme://host[:port]`, computed by the host from the top-level URL. */
|
|
790
|
-
type BrowserOrigin = {
|
|
791
|
-
readonly kind: "browser";
|
|
792
|
-
readonly origin: string;
|
|
793
|
-
};
|
|
794
|
-
type RequestOrigin = {
|
|
795
|
-
readonly kind: "internal";
|
|
796
|
-
} | BrowserOrigin;
|
|
797
|
-
type RequestMethod = ChainRequestMethod | "pay" | "zap" | "evm-sign" | "spark-deposit" | "spark-exit";
|
|
798
|
-
type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
|
|
799
|
-
type SignLogEntry = {
|
|
800
|
-
readonly id: string;
|
|
801
|
-
readonly at: number;
|
|
802
|
-
readonly origin: RequestOrigin;
|
|
803
|
-
readonly method: RequestMethod;
|
|
804
|
-
readonly account: AccountRef | SparkAccountRef;
|
|
805
|
-
readonly network: string;
|
|
806
|
-
readonly summary: string;
|
|
807
|
-
readonly verification: "verified" | "unverifiable";
|
|
808
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
809
|
-
readonly risk: ReadonlyArray<RiskFinding>;
|
|
810
|
-
readonly outcome: SignLogOutcome;
|
|
811
|
-
readonly error?: string;
|
|
812
|
-
};
|
|
813
|
-
/** A Spark, Lightning (including LNURL-pay and lightning addresses) or cooperative-exit payment. */
|
|
814
|
-
type PayInput = {
|
|
815
|
-
readonly method: "pay";
|
|
816
|
-
} & PayParams;
|
|
817
|
-
/** A prepared zap; its invoice was fetched by `engine.zaps.prepare` and is paid as-is. */
|
|
818
|
-
type ZapInput = {
|
|
819
|
-
readonly method: "zap";
|
|
820
|
-
readonly account: SparkAccountRef;
|
|
821
|
-
readonly zap: PreparedZap;
|
|
822
|
-
readonly maxFeeSats: number;
|
|
823
|
-
};
|
|
824
|
-
/**
|
|
825
|
-
* A dApp's EVM request: a transaction (rebuilt here with fresh nonce and fees), a personal message
|
|
826
|
-
* or EIP-712 typed data.
|
|
827
|
-
*/
|
|
828
|
-
type EvmSignInput = {
|
|
829
|
-
readonly method: "evm-sign";
|
|
830
|
-
readonly origin: BrowserOrigin;
|
|
831
|
-
readonly account: AccountRef;
|
|
832
|
-
readonly network: string;
|
|
833
|
-
readonly request: SignRequest;
|
|
834
|
-
};
|
|
835
|
-
/**
|
|
836
|
-
* Funds the wallet's own Spark account from a bitcoin account of the same wallet; the transaction
|
|
837
|
-
* is an ordinary bitcoin send to a fresh Spark deposit address and is claimed once confirmed.
|
|
838
|
-
*/
|
|
839
|
-
type SparkDepositInput = {
|
|
840
|
-
readonly method: "spark-deposit";
|
|
841
|
-
readonly account: SparkAccountRef;
|
|
842
|
-
readonly from: AccountRef;
|
|
843
|
-
readonly amountSats: number;
|
|
844
|
-
readonly fee: PrepareParams["fee"];
|
|
845
|
-
};
|
|
846
|
-
/** A cooperative exit to the group's own next unused `btc.bip84` receive address. */
|
|
847
|
-
type SparkExitInput = {
|
|
848
|
-
readonly method: "spark-exit";
|
|
849
|
-
readonly account: SparkAccountRef;
|
|
850
|
-
readonly amountSats: number;
|
|
851
|
-
readonly maxFeeSats: number;
|
|
852
|
-
readonly speed?: "FAST" | "MEDIUM" | "SLOW";
|
|
853
|
-
};
|
|
854
|
-
type RequestInput = ChainRequestInput | PayInput | ZapInput | EvmSignInput | SparkDepositInput | SparkExitInput;
|
|
855
|
-
type RequestStage = "awaiting-approval" | "signing" | "submitted" | "rejected" | "failed" | "expired" | "invalidated";
|
|
856
|
-
type PendingRequest = {
|
|
857
|
-
readonly id: string;
|
|
858
|
-
readonly origin: RequestOrigin;
|
|
859
|
-
readonly method: RequestMethod;
|
|
860
|
-
readonly account: AccountRef | SparkAccountRef;
|
|
861
|
-
readonly network: string;
|
|
862
|
-
readonly stage: RequestStage;
|
|
863
|
-
/** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
|
|
864
|
-
readonly display: DisplayIntent | SparkDisplay;
|
|
865
|
-
/** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
|
|
866
|
-
readonly verification: "verified" | "unverifiable";
|
|
867
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
868
|
-
/**
|
|
869
|
-
* Recipient risk; independent of `verification`. A `danger` needs the user's explicit
|
|
870
|
-
* acknowledgement.
|
|
871
|
-
*/
|
|
872
|
-
readonly risk: ReadonlyArray<RiskFinding>;
|
|
873
|
-
readonly createdAt: number;
|
|
874
|
-
readonly expiresAt: number;
|
|
875
|
-
/** The transaction being replaced or accelerated; absent for a plain send. */
|
|
876
|
-
readonly target?: string;
|
|
877
|
-
/** The tracked transaction once submitted. */
|
|
878
|
-
readonly txId?: string;
|
|
879
|
-
readonly error?: string;
|
|
880
|
-
};
|
|
881
|
-
type RequestControllerState = {
|
|
882
|
-
readonly requests: Record<string, PendingRequest>;
|
|
883
|
-
};
|
|
884
|
-
type RequestControllerOptions = {
|
|
885
|
-
readonly transactions: TransactionController;
|
|
886
|
-
/** The full controller: its payment methods are reachable only through this pipeline. */
|
|
887
|
-
readonly spark: SparkController;
|
|
888
|
-
readonly addressBook: AddressBookController;
|
|
889
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
890
|
-
readonly fetch: typeof globalThis.fetch;
|
|
891
|
-
readonly random: (n: number) => Uint8Array;
|
|
892
|
-
readonly now: () => number;
|
|
893
|
-
readonly setTimer: (ms: number, fn: () => unknown) => () => void;
|
|
894
|
-
readonly logger: EngineLogger;
|
|
895
|
-
};
|
|
896
|
-
/** Requests expire this long after creation. */
|
|
897
|
-
export declare const REQUEST_TTL_MS: number;
|
|
898
|
-
export declare class RequestController extends Controller<RequestControllerState> {
|
|
899
|
-
private readonly options;
|
|
900
|
-
private readonly entries;
|
|
901
|
-
private readonly log;
|
|
902
|
-
private readonly settlers;
|
|
903
|
-
/** Original transaction id → the unfinished request replacing or accelerating it. */
|
|
904
|
-
private readonly targets;
|
|
905
|
-
private locked;
|
|
906
|
-
/** Bumped on every unlock and lock so work that outlives a session never touches the next one. */
|
|
907
|
-
private session;
|
|
908
|
-
constructor(options: RequestControllerOptions);
|
|
909
|
-
init(): Promise<void>;
|
|
910
|
-
destroy(): Promise<void>;
|
|
911
|
-
/** Locking is not consent: every unfinished request becomes `invalidated` and frees its resources. */
|
|
912
|
-
lock(): void;
|
|
913
|
-
/** A page navigated away, was revoked or changed network: its unfinished requests are void. */
|
|
914
|
-
invalidateOrigin(origin: string): void;
|
|
915
|
-
/** The signature record, newest first. */
|
|
916
|
-
signLog(): Promise<ReadonlyArray<SignLogEntry>>;
|
|
917
|
-
clearSignLog(): Promise<void>;
|
|
918
|
-
prepare(input: RequestInput): Promise<PendingRequest>;
|
|
919
|
-
/**
|
|
920
|
-
* Resolves with what `approve` returned, or rejects with `RequestEndedError` when the request
|
|
921
|
-
* ends any other way — how a dApp's pending call learns the outcome.
|
|
922
|
-
*/
|
|
923
|
-
outcome(id: string): Promise<TrackedTransaction | SparkResult | SignatureResult>;
|
|
924
|
-
private openSettler;
|
|
925
|
-
private settle;
|
|
926
|
-
/** The bitcoin network `account`'s Spark network settles on; any other pairing is refused. */
|
|
927
|
-
private l1Network;
|
|
928
|
-
private sparkBuilt;
|
|
929
|
-
private build;
|
|
930
|
-
/**
|
|
931
|
-
* Signs and submits a request. Anything but a live, unexpired `send` request with this id throws
|
|
932
|
-
* before any signing; a stale build (nonce taken, blockhash expired) fails without signing.
|
|
933
|
-
*/
|
|
934
|
-
approve(id: string, method: ChainRequestMethod | "spark-deposit", verify: SendParams["verify"]): Promise<TrackedTransaction>;
|
|
935
|
-
approve(id: string, method: "pay" | "zap" | "spark-exit", verify: SendParams["verify"]): Promise<SparkResult>;
|
|
936
|
-
approve(id: string, method: "evm-sign", verify: SendParams["verify"]): Promise<TrackedTransaction | SignatureResult>;
|
|
937
|
-
/**
|
|
938
|
-
* A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
|
|
939
|
-
* requests record which step failed on the tracked transaction; for Spark, the approval round is
|
|
940
|
-
* the only source of `WalletError`.
|
|
941
|
-
*/
|
|
942
|
-
private failureStage;
|
|
943
|
-
reject(id: string): void;
|
|
944
|
-
private requireRequest;
|
|
945
|
-
private put;
|
|
946
|
-
private unclaim;
|
|
947
|
-
/** Ends a request in a terminal stage and frees what it reserved. */
|
|
948
|
-
private finish;
|
|
949
|
-
/** Appends the final stage to the signature record; a failed write is a warning, not an error. */
|
|
950
|
-
private record;
|
|
951
|
-
private appendLog;
|
|
952
|
-
/**
|
|
953
|
-
* Addresses the wallet already knows for a family: contacts, plus recipients of tracked chain
|
|
954
|
-
* sends (Spark payments are not tracked).
|
|
955
|
-
*/
|
|
956
|
-
private knownAddresses;
|
|
957
|
-
private chainRisk;
|
|
958
|
-
/** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
|
|
959
|
-
private sparkRisk;
|
|
960
|
-
}
|
|
961
|
-
type Eip1193Request = {
|
|
962
|
-
readonly method: string;
|
|
963
|
-
readonly params?: unknown;
|
|
964
|
-
};
|
|
965
|
-
type Eip1193Event = {
|
|
966
|
-
readonly name: "connect";
|
|
967
|
-
readonly origin: string;
|
|
968
|
-
readonly chainId: string;
|
|
969
|
-
} | {
|
|
970
|
-
readonly name: "accountsChanged";
|
|
971
|
-
readonly origin: string;
|
|
972
|
-
readonly accounts: ReadonlyArray<string>;
|
|
973
|
-
} | {
|
|
974
|
-
readonly name: "chainChanged";
|
|
975
|
-
readonly origin: string;
|
|
976
|
-
readonly chainId: string;
|
|
977
|
-
} | {
|
|
978
|
-
readonly name: "disconnect";
|
|
979
|
-
readonly origin: string;
|
|
980
|
-
};
|
|
981
|
-
type Eip1193HandlerOptions = {
|
|
982
|
-
readonly connections: ConnectionController;
|
|
983
|
-
readonly requests: RequestController;
|
|
984
|
-
readonly networks: NetworkController;
|
|
985
|
-
/** The network an unconnected page sees. */
|
|
986
|
-
readonly defaultNetwork: () => string;
|
|
987
|
-
};
|
|
988
|
-
export declare class Eip1193Handler {
|
|
989
|
-
private readonly options;
|
|
990
|
-
private readonly listeners;
|
|
991
|
-
private unsubscribe;
|
|
992
|
-
constructor(options: Eip1193HandlerOptions);
|
|
993
|
-
/** Events for the host to forward to pages; derived from changes to the sessions. */
|
|
994
|
-
subscribe(listener: (event: Eip1193Event) => void): () => void;
|
|
995
|
-
handle(origin: string, request: Eip1193Request): Promise<unknown>;
|
|
996
|
-
private requestAccounts;
|
|
997
|
-
private permissions;
|
|
998
|
-
private switchChain;
|
|
999
|
-
private authorizedAccount;
|
|
1000
|
-
private personalSign;
|
|
1001
|
-
private typedData;
|
|
1002
|
-
private sendTransaction;
|
|
1003
|
-
private signingSession;
|
|
1004
|
-
private sign;
|
|
1005
|
-
private read;
|
|
1006
|
-
}
|
|
1007
|
-
/** EIP-1193 / EIP-1474 / EIP-3326 error: `code` is what the page's promise rejects with. */
|
|
1008
|
-
export declare class ProviderError extends Error {
|
|
1009
|
-
readonly code: number;
|
|
1010
|
-
constructor(code: number, message: string);
|
|
1011
|
-
}
|
|
1012
16
|
type AddressBookErrorCategory = "invalid-input" | "duplicate" | "not-found" | "locked" | "limit";
|
|
1013
17
|
export declare class AddressBookError extends Error {
|
|
1014
18
|
readonly category: AddressBookErrorCategory;
|
|
@@ -1360,6 +364,7 @@ type MetaSyncControllerOptions = {
|
|
|
1360
364
|
readonly metaSync: MetaSyncConfig | undefined;
|
|
1361
365
|
readonly logger: EngineLogger;
|
|
1362
366
|
readonly now: () => number;
|
|
367
|
+
readonly verifyEvent: (event: Event) => boolean;
|
|
1363
368
|
};
|
|
1364
369
|
/**
|
|
1365
370
|
* Wallet-metadata sync over kind-30078 addressable events: one NIP-44-encrypted document per
|
|
@@ -1402,11 +407,21 @@ export declare class MetaSyncController extends Controller<MetaSyncState> {
|
|
|
1402
407
|
}
|
|
1403
408
|
type EngineOptions = {
|
|
1404
409
|
readonly wallet: Wallet;
|
|
410
|
+
/**
|
|
411
|
+
* Verifies events the engine checks itself (external-signer zap requests, relay metadata
|
|
412
|
+
* documents). Required, with no default: `@qntx/nostr`'s own `verifyEvent` is bound to the
|
|
413
|
+
* pure-JS noble backend — pass the host's native verifier, the same one given to the wallet.
|
|
414
|
+
*/
|
|
415
|
+
readonly verifyEvent: (event: Event) => boolean;
|
|
1405
416
|
/** Every Spark account the engine touches lives on this network. */
|
|
1406
417
|
readonly sparkNetwork: SparkNetwork;
|
|
1407
418
|
readonly fetch: typeof globalThis.fetch;
|
|
1408
419
|
readonly random: (length: number) => Uint8Array;
|
|
1409
420
|
readonly now: () => number;
|
|
421
|
+
/** The WebLN node's display alias — `getInfo` never exposes a pubkey. */
|
|
422
|
+
readonly weblnAlias: string;
|
|
423
|
+
/** The host's lightning fee cap for WebLN sends — validated to a non-negative safe integer. */
|
|
424
|
+
readonly lightningMaxFee: (amountSats: number) => number;
|
|
1410
425
|
readonly logger: EngineLogger;
|
|
1411
426
|
readonly openStore: () => Promise<EngineStore>;
|
|
1412
427
|
/** Cloud file transport for the backup controller; absent → `unavailable`. */
|
|
@@ -1441,6 +456,9 @@ type WalletEngine = {
|
|
|
1441
456
|
readonly addressBook: AddressBookController;
|
|
1442
457
|
readonly connections: ConnectionController;
|
|
1443
458
|
readonly eip1193: Eip1193Handler;
|
|
459
|
+
readonly nip07: Nip07Handler;
|
|
460
|
+
readonly webln: WeblnHandler;
|
|
461
|
+
readonly solanaWallet: SolanaWalletHandler;
|
|
1444
462
|
/** Read and receive surface; every payment goes through `requests`. */
|
|
1445
463
|
readonly spark: Omit<SparkController, "send" | "payInvoice" | "paySparkInvoice" | "withdraw">;
|
|
1446
464
|
readonly accounts: AccountTreeController;
|
|
@@ -1492,5 +510,5 @@ type ResolveOptions = ParseOptions & {
|
|
|
1492
510
|
export declare function resolvePayment(input: string, options: ResolveOptions): Promise<PaymentParse>;
|
|
1493
511
|
export declare function encodeExitChain(chain: SparkExitChain): Uint8Array;
|
|
1494
512
|
export declare function decodeExitChain(bytes: Uint8Array): SparkExitChain;
|
|
1495
|
-
export type
|
|
513
|
+
export { type AccountGroup, type AccountTreeState, AddressBookController, type AddressBookEntry, type AddressBookErrorCategory, type AddressBookState, type AddressFamily, type BackupControllerState, type BackupErrorCategory, type BrowserOrigin, type CloudStore, type AccountGroup$1 as ConnectionAccountGroup, ConnectionController, type ConnectionOrigin, type ConnectionScope, type ConnectionSession, type ConnectionState, Controller, type ControllerOptions, type Eip1193Event, Eip1193Handler, type Eip1193Request, type EngineCollection, type EngineErrorCode, type EngineLogger, type EngineOptions, type EngineStore, type EventBus, type EvmSignInput, type MetaDoc, type MetaDocGroup, type MetaDocTree, type MetaDocWallet, type MetaSyncConfig, type MetaSyncRelayPort, type MetaSyncState, type MetaSyncWalletStatus, type PayInput, type PayParams, type PaymentNote, type PaymentOption, type PaymentParse, type PaymentRequest, type PendingConnection, type PendingRequest, type PrepareZapContext, type PrepareZapParams, type PreparedSparkAction, type PreparedZap, ProviderError, REQUEST_TTL_MS, type RequestCheckCode, RequestController, type RequestControllerState, type RequestInput, type RequestMethod, type RequestOrigin, type RequestStage, type RiskFinding, type SignLogEntry, type SignLogOutcome, type SignatureResult, type SparkAccountState, type SparkActivity, type SparkClientFactory, SparkController, type SparkControllerOptions, type SparkControllerState, type SparkDepositInput, type SparkDisplay, type SparkErrorCategory, type SparkExitInput, type SparkResult, type WalletEngine, type WithdrawLnurlParams, type ZapRecipient, createEventBus, parsePayment, prepareZap, sparkStore };
|
|
1496
514
|
//# sourceMappingURL=index.d.mts.map
|