@qntx/wallet-engine 0.6.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.d.mts +1 -13
- package/dist/gateway-contract.mjs +183 -1
- package/dist/gateway-contract.mjs.map +1 -0
- package/dist/idb.d.mts +0 -4
- package/dist/idb.mjs +3 -6
- package/dist/idb.mjs.map +1 -1
- package/dist/index.d.mts +32 -867
- package/dist/index.mjs +2297 -1821
- package/dist/index.mjs.map +1 -1
- package/dist/registry-CHiAn88k.mjs +98 -0
- package/dist/registry-CHiAn88k.mjs.map +1 -0
- package/dist/{registry-9oeWs_yZ.d.mts → registry-LcFSPrE1.d.mts} +1 -3
- package/dist/webln-CHjBMRcv.mjs +1247 -0
- package/dist/webln-CHjBMRcv.mjs.map +1 -0
- package/package.json +28 -17
- package/dist/contract-D5pguqiZ.mjs +0 -284
- package/dist/contract-D5pguqiZ.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,842 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StoreApi } from "zustand/vanilla";
|
|
3
|
-
import "@scure/btc-signer";
|
|
4
|
-
import { CooperativeExitResult, LightningInvoice, LightningPayment, SparkClient, SparkExitChain, SparkNetwork, SparkPayment, SparkStore, SparkTransfer } from "@qntx/spark";
|
|
5
|
-
import { decodeEvm } from "@qntx/wallet-chains/evm";
|
|
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";
|
|
6
2
|
import { BackupHeader, BackupInfo, InitialFactor, UnlockFactor, Wallet, WalletInfo } from "@qntx/wallet";
|
|
7
|
-
import {
|
|
8
|
-
import { Event, Filter
|
|
9
|
-
import {
|
|
10
|
-
import { SparkSigner } from "@qntx/wallet/spark";
|
|
11
|
-
import { PublicClient } from "viem";
|
|
12
|
-
import { chains } from "@qntx/wallet/chains";
|
|
13
|
-
import "@solana/kit";
|
|
14
|
-
import { SparkAccountRef, SparkApproveIntent } from "@qntx/wallet/protocol";
|
|
15
|
-
import "@qntx/wallet-chains";
|
|
16
|
-
import "@scure/btc-signer/psbt.js";
|
|
17
|
-
//#region src/controller.d.ts
|
|
18
|
-
type ControllerOptions<S> = {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly defaultState: () => S;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Controller base: a zustand vanilla store plus lifecycle. `update` applies a recipe that must
|
|
24
|
-
* return a NEW state object; returning the same reference is a no-op (no set, no notification).
|
|
25
|
-
* Persistence and migrations layer on later — this package carries only what its first user needs.
|
|
26
|
-
*/
|
|
27
|
-
export declare abstract class Controller<S extends Record<string, unknown>> {
|
|
28
|
-
readonly name: string;
|
|
29
|
-
readonly store: StoreApi<S>;
|
|
30
|
-
protected constructor(options: ControllerOptions<S>);
|
|
31
|
-
getState(): S;
|
|
32
|
-
protected update(recipe: (state: S) => S): void;
|
|
33
|
-
abstract init(): Promise<void>;
|
|
34
|
-
abstract destroy(): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/events.d.ts
|
|
38
|
-
/** Log port: listener failures are reported here and never reach the emitter or peers. */
|
|
39
|
-
type EngineLogger = {
|
|
40
|
-
readonly warn: (message: string, error?: unknown) => void;
|
|
41
|
-
};
|
|
42
|
-
type EventBus<E> = {
|
|
43
|
-
/** Synchronous dispatch to every current listener in registration order. */
|
|
44
|
-
emit: <K extends keyof E>(type: K, payload: E[K]) => void;
|
|
45
|
-
on: <K extends keyof E>(type: K, listener: (payload: E[K]) => void) => () => void;
|
|
46
|
-
};
|
|
47
|
-
export declare function createEventBus<E>(logger: EngineLogger): EventBus<E>;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/errors.d.ts
|
|
3
|
+
import { LightningInvoice, SparkExitChain, SparkNetwork } from "@qntx/spark";
|
|
4
|
+
import { Event, Filter } from "@qntx/nostr";
|
|
5
|
+
import { WalletSyncSigner } from "@qntx/wallet/nostr";
|
|
50
6
|
type EngineErrorCode = "closed" | "integrity" | "invalid-input";
|
|
51
7
|
/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */
|
|
52
8
|
export declare class EngineStoreError extends Error {
|
|
53
9
|
readonly code: EngineErrorCode;
|
|
54
10
|
constructor(code: EngineErrorCode, message: string);
|
|
55
11
|
}
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/store/port.d.ts
|
|
58
|
-
/**
|
|
59
|
-
* Engine storage port: named collections of byte values. `collection` is synchronous and cheap —
|
|
60
|
-
* the same collection object backs every call, so guards (closed) live on the store.
|
|
61
|
-
*/
|
|
62
|
-
type EngineCollection = {
|
|
63
|
-
readonly get: (key: string) => Promise<Uint8Array | undefined>;
|
|
64
|
-
readonly put: (key: string, bytes: Uint8Array) => Promise<void>;
|
|
65
|
-
readonly delete: (key: string) => Promise<void>;
|
|
66
|
-
/** Every key in the collection, in an unspecified order. */
|
|
67
|
-
readonly list: () => Promise<ReadonlyArray<string>>;
|
|
68
|
-
};
|
|
69
|
-
type EngineStore = {
|
|
70
|
-
readonly collection: (name: string) => EngineCollection;
|
|
71
|
-
readonly close: () => Promise<void>;
|
|
72
|
-
};
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/store/memory.d.ts
|
|
75
12
|
/** In-memory EngineStore: the Node/test implementation — same contract, no durability. */
|
|
76
13
|
export declare function createMemoryEngineStore(backing?: {
|
|
77
14
|
readonly collections?: Map<string, Map<string, Uint8Array>>;
|
|
78
15
|
}): EngineStore;
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/addresses/normalize.d.ts
|
|
81
|
-
type AddressFamily = "evm" | "solana" | "bitcoin" | "spark";
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/addresses/record.d.ts
|
|
84
|
-
type AddressBookEntry = {
|
|
85
|
-
readonly id: string;
|
|
86
|
-
readonly name: string;
|
|
87
|
-
readonly family: AddressFamily;
|
|
88
|
-
readonly address: string;
|
|
89
|
-
readonly note?: string;
|
|
90
|
-
readonly createdAt: number;
|
|
91
|
-
readonly updatedAt: number;
|
|
92
|
-
};
|
|
93
|
-
type AddressBookTombstone = {
|
|
94
|
-
readonly id: string;
|
|
95
|
-
readonly deleted: true;
|
|
96
|
-
readonly updatedAt: number;
|
|
97
|
-
};
|
|
98
|
-
type AddressBookRecord = AddressBookEntry | AddressBookTombstone;
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/addresses/controller.d.ts
|
|
101
|
-
type AddressBookState = {
|
|
102
|
-
/** Live entries only; tombstones stay internal. */
|
|
103
|
-
readonly entries: Record<string, AddressBookEntry>;
|
|
104
|
-
};
|
|
105
|
-
type AddressBookOptions = {
|
|
106
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
107
|
-
readonly random: (n: number) => Uint8Array;
|
|
108
|
-
readonly now: () => number;
|
|
109
|
-
readonly logger: EngineLogger;
|
|
110
|
-
};
|
|
111
|
-
export declare class AddressBookController extends Controller<AddressBookState> {
|
|
112
|
-
private readonly options;
|
|
113
|
-
private engineStore;
|
|
114
|
-
/** Every record, tombstones included, by id. */
|
|
115
|
-
private records;
|
|
116
|
-
constructor(options: AddressBookOptions);
|
|
117
|
-
init(): Promise<void>;
|
|
118
|
-
destroy(): Promise<void>;
|
|
119
|
-
lock(): void;
|
|
120
|
-
/** Entries and tombstones, for the metadata document. */
|
|
121
|
-
syncEntries(): ReadonlyArray<AddressBookRecord>;
|
|
122
|
-
/**
|
|
123
|
-
* Merges records from another device (last writer wins, tombstones win over older entries).
|
|
124
|
-
* Returns whether anything local changed and whether the merged set holds something `remote`
|
|
125
|
-
* lacks, i.e. whether the remote copy needs a newer publish.
|
|
126
|
-
*/
|
|
127
|
-
merge(remote: ReadonlyArray<AddressBookRecord>): Promise<{
|
|
128
|
-
readonly changed: boolean;
|
|
129
|
-
readonly localNewer: boolean;
|
|
130
|
-
}>;
|
|
131
|
-
add(params: {
|
|
132
|
-
readonly name: string;
|
|
133
|
-
readonly family: AddressFamily;
|
|
134
|
-
readonly address: string;
|
|
135
|
-
readonly note?: string;
|
|
136
|
-
}): Promise<AddressBookEntry>;
|
|
137
|
-
rename(id: string, name: string): Promise<AddressBookEntry>;
|
|
138
|
-
/** Sets or clears (empty or `undefined`) the note. */
|
|
139
|
-
setNote(id: string, note: string | undefined): Promise<AddressBookEntry>;
|
|
140
|
-
/** Removes the entry, leaving a tombstone so other devices drop it too. */
|
|
141
|
-
remove(id: string): Promise<void>;
|
|
142
|
-
private checkedNote;
|
|
143
|
-
private requireEntry;
|
|
144
|
-
private persist;
|
|
145
|
-
private requireStore;
|
|
146
|
-
}
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/addresses/errors.d.ts
|
|
149
16
|
type AddressBookErrorCategory = "invalid-input" | "duplicate" | "not-found" | "locked" | "limit";
|
|
150
17
|
export declare class AddressBookError extends Error {
|
|
151
18
|
readonly category: AddressBookErrorCategory;
|
|
152
19
|
constructor(category: AddressBookErrorCategory, message: string);
|
|
153
20
|
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/chains/evm.d.ts
|
|
156
|
-
type EvmFeeTier = "slow" | "normal" | "fast";
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/chains/bitcoin.d.ts
|
|
159
|
-
type Esplora = {
|
|
160
|
-
readonly get: (path: string) => Promise<unknown>;
|
|
161
|
-
readonly post: (path: string, body: string) => Promise<unknown>;
|
|
162
|
-
};
|
|
163
|
-
//#endregion
|
|
164
|
-
//#region src/networks/controller.d.ts
|
|
165
|
-
type SolanaRpc = {
|
|
166
|
-
readonly call: (method: string, params: unknown[]) => Promise<unknown>;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* A host-endpoint-only client for cross-checking pre-signing reads. `not-needed`: the gateway is
|
|
170
|
-
* not this network's first endpoint, so the primary reads already come from the host.
|
|
171
|
-
* `unavailable`: a cross-check is needed but the network has no host endpoint.
|
|
172
|
-
*/
|
|
173
|
-
type Independent<T> = {
|
|
174
|
-
readonly kind: "not-needed";
|
|
175
|
-
} | {
|
|
176
|
-
readonly kind: "unavailable";
|
|
177
|
-
} | {
|
|
178
|
-
readonly kind: "available";
|
|
179
|
-
readonly client: T;
|
|
180
|
-
};
|
|
181
|
-
type NetworkControllerState = {
|
|
182
|
-
readonly customRpc: Record<string, ReadonlyArray<string>>;
|
|
183
|
-
};
|
|
184
|
-
type Options$2 = {
|
|
185
|
-
readonly fetch: typeof globalThis.fetch;
|
|
186
|
-
readonly rpc: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
187
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
188
|
-
readonly logger: EngineLogger;
|
|
189
|
-
readonly gateway?: {
|
|
190
|
-
readonly url: string;
|
|
191
|
-
readonly installId: string;
|
|
192
|
-
} | undefined;
|
|
193
|
-
};
|
|
194
|
-
declare class NetworkController extends Controller<NetworkControllerState> {
|
|
195
|
-
private readonly options;
|
|
196
|
-
private engineStore?;
|
|
197
|
-
private readonly clients;
|
|
198
|
-
private readonly gatewayBase;
|
|
199
|
-
private readonly gatewayOrigin;
|
|
200
|
-
/** Networks the gateway reported at unlock; empty while locked or when the read failed. */
|
|
201
|
-
private gatewayServed;
|
|
202
|
-
constructor(options: Options$2);
|
|
203
|
-
init(): Promise<void>;
|
|
204
|
-
private loadCustomRpc;
|
|
205
|
-
/** Reads the gateway's served networks; any failure leaves the gateway unused until next unlock. */
|
|
206
|
-
private loadGatewayNetworks;
|
|
207
|
-
/** `fetch` that adds the install id to requests bound for the gateway's origin only. */
|
|
208
|
-
private readonly gatewayFetch;
|
|
209
|
-
destroy(): Promise<void>;
|
|
210
|
-
lock(): void;
|
|
211
|
-
/**
|
|
212
|
-
* Ordered endpoints: a network with custom endpoints uses custom → host and never the gateway;
|
|
213
|
-
* otherwise a gateway-served network uses gateway → host; else host only.
|
|
214
|
-
*/
|
|
215
|
-
endpoints(network: string): ReadonlyArray<string>;
|
|
216
|
-
info(network: string): NetworkInfo;
|
|
217
|
-
client(network: string): PublicClient;
|
|
218
|
-
/** True when the gateway heads this network's endpoint list (no custom endpoints, gateway-served). */
|
|
219
|
-
private gatewayFirst;
|
|
220
|
-
private independent;
|
|
221
|
-
/** Host-endpoint EVM client for cross-checking reads; never sends the install id. */
|
|
222
|
-
independentClient(network: string): Independent<PublicClient>;
|
|
223
|
-
independentSolanaRpc(network: string): Independent<SolanaRpc>;
|
|
224
|
-
independentEsplora(network: string): Independent<Esplora>;
|
|
225
|
-
/** Networks with at least one configured endpoint or served by the gateway, by family. */
|
|
226
|
-
enabled(family: "evm" | "solana" | "bitcoin"): ReadonlyArray<string>;
|
|
227
|
-
/** Solana JSON-RPC over the ordered endpoint list — kit's transport is single-endpoint. */
|
|
228
|
-
solanaRpc(network: string): SolanaRpc;
|
|
229
|
-
/** Bounded-concurrency + 429-aware ordered-failover Esplora client. */
|
|
230
|
-
esplora(network: string): Esplora;
|
|
231
|
-
/** Validate a custom endpoint's reported chain id, then persist it first in the list. */
|
|
232
|
-
addRpc(network: string, url: string): Promise<void>;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/chains/solana.d.ts
|
|
236
|
-
type SolanaFeeTier = "slow" | "normal" | "fast";
|
|
237
|
-
//#endregion
|
|
238
|
-
//#region src/requests/checks.d.ts
|
|
239
|
-
type RequestCheckCode = "decode-partial" | "nonce-mismatch" | "fee-mismatch" | "reads-unverified" | "fee-above-network" | "fee-exceeds-amount";
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/spark/notes.d.ts
|
|
242
|
-
/**
|
|
243
|
-
* Local, engine-side metadata pinned to a history entry by transfer id. Written after the payment
|
|
244
|
-
* it annotates has already succeeded — a missing or malformed note must never affect the payment
|
|
245
|
-
* itself.
|
|
246
|
-
*/
|
|
247
|
-
type PaymentNote = {
|
|
248
|
-
readonly kind: "zap";
|
|
249
|
-
/** 64 lowercase hex. */
|
|
250
|
-
readonly recipientPubkey: string;
|
|
251
|
-
/** 64 lowercase hex — event zaps carry the zapped event's id. */
|
|
252
|
-
readonly eventId?: string;
|
|
253
|
-
/** At most 2000 characters. */
|
|
254
|
-
readonly comment?: string;
|
|
255
|
-
/** The lud16 or LNURL the zap resolved. */
|
|
256
|
-
readonly lightning: string;
|
|
257
|
-
};
|
|
258
|
-
type SparkActivity = SparkPayment & {
|
|
259
|
-
readonly note?: PaymentNote;
|
|
260
|
-
};
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/spark/store.d.ts
|
|
263
|
-
/**
|
|
264
|
-
* SparkStore over one EngineCollection: chains keyed by leafId, plus an index record listing them
|
|
265
|
-
* (`exitChains` is a full listing — the port has no secondary index).
|
|
266
|
-
*/
|
|
267
|
-
export declare function sparkStore(col: EngineCollection): SparkStore;
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region src/spark/controller.d.ts
|
|
270
|
-
type SparkAccountState = {
|
|
271
|
-
readonly status: "locked" | "connecting" | "ready" | "error";
|
|
272
|
-
readonly balanceSats?: number;
|
|
273
|
-
readonly identityPublicKey?: string;
|
|
274
|
-
readonly sparkAddress?: string;
|
|
275
|
-
readonly errorCategory?: string;
|
|
276
|
-
/** First history page (20 entries, newest first), refreshed alongside the balance. */
|
|
277
|
-
readonly recent?: ReadonlyArray<SparkActivity>;
|
|
278
|
-
};
|
|
279
|
-
type SparkControllerState = {
|
|
280
|
-
readonly accounts: Readonly<Record<string, SparkAccountState>>;
|
|
281
|
-
};
|
|
282
|
-
type SparkApis = {
|
|
283
|
-
readonly signer: (ref: SparkAccountRef) => SparkSigner;
|
|
284
|
-
readonly approve: (params: {
|
|
285
|
-
account: SparkAccountRef;
|
|
286
|
-
intent: SparkApproveIntent;
|
|
287
|
-
verify: UnlockFactor;
|
|
288
|
-
}) => Promise<unknown>;
|
|
289
|
-
};
|
|
290
|
-
type SparkClientFactory = (options: {
|
|
291
|
-
readonly ref: SparkAccountRef;
|
|
292
|
-
readonly store: ReturnType<typeof sparkStore>;
|
|
293
|
-
readonly signer: SparkSigner;
|
|
294
|
-
readonly fetch: typeof globalThis.fetch;
|
|
295
|
-
}) => SparkClient;
|
|
296
|
-
type SparkControllerOptions = {
|
|
297
|
-
readonly spark: SparkApis;
|
|
298
|
-
readonly fetch: typeof globalThis.fetch;
|
|
299
|
-
readonly random: (length: number) => Uint8Array;
|
|
300
|
-
readonly now: () => number;
|
|
301
|
-
readonly logger: EngineLogger;
|
|
302
|
-
readonly createClient: SparkClientFactory;
|
|
303
|
-
};
|
|
304
|
-
export declare class SparkController extends Controller<SparkControllerState> {
|
|
305
|
-
private readonly options;
|
|
306
|
-
private engineStore;
|
|
307
|
-
private readonly accounts;
|
|
308
|
-
private readonly clients;
|
|
309
|
-
private readonly recentSeq;
|
|
310
|
-
private readonly aborts;
|
|
311
|
-
constructor(options: SparkControllerOptions);
|
|
312
|
-
/** Engine calls this with the open store on unlock; `undefined` on lock. */
|
|
313
|
-
setStore(store: EngineStore | undefined): void;
|
|
314
|
-
/**
|
|
315
|
-
* Declarative account set: refs not yet tracked are patched `locked` and started when the store
|
|
316
|
-
* is open; tracked refs no longer listed are stopped and dropped; running refs stay untouched.
|
|
317
|
-
*/
|
|
318
|
-
setAccounts(refs: ReadonlyArray<SparkAccountRef>): void;
|
|
319
|
-
init(): Promise<void>;
|
|
320
|
-
destroy(): Promise<void>;
|
|
321
|
-
private stopAccount;
|
|
322
|
-
/** Lock: abort every event loop, close every client, reset state. */
|
|
323
|
-
lockAll(): Promise<void>;
|
|
324
|
-
private startAccount;
|
|
325
|
-
private runEvents;
|
|
326
|
-
private handleTransfer;
|
|
327
|
-
private notesCollection;
|
|
328
|
-
/** Attach locally written notes to a history page; malformed records warn and drop. */
|
|
329
|
-
private withNotes;
|
|
330
|
-
/**
|
|
331
|
-
* Refill `recent` from the first history page. A failure keeps the previous page — it never
|
|
332
|
-
* touches `status`/`errorCategory`. A per-account sequence keeps a slower older refresh from
|
|
333
|
-
* overwriting a newer one.
|
|
334
|
-
*/
|
|
335
|
-
private refreshRecent;
|
|
336
|
-
private patch;
|
|
337
|
-
private clientFor;
|
|
338
|
-
private guarded;
|
|
339
|
-
/**
|
|
340
|
-
* One-off balance + activity probe for an account that may not be running: builds a temporary
|
|
341
|
-
* client through the same factory on the account's own exit-chain collection (nothing diverges —
|
|
342
|
-
* `balance()`/`transfers.history` never write it), reads, and closes it in `finally`.
|
|
343
|
-
*/
|
|
344
|
-
inspect(ref: SparkAccountRef): Promise<{
|
|
345
|
-
balanceSats: number;
|
|
346
|
-
used: boolean;
|
|
347
|
-
}>;
|
|
348
|
-
/** History for one account: a client page merged with locally written notes by id. */
|
|
349
|
-
history(ref: SparkAccountRef, options?: {
|
|
350
|
-
readonly limit?: number;
|
|
351
|
-
readonly offset?: number;
|
|
352
|
-
}): Promise<{
|
|
353
|
-
readonly items: ReadonlyArray<SparkActivity>;
|
|
354
|
-
readonly nextOffset: number | undefined;
|
|
355
|
-
}>;
|
|
356
|
-
send(ref: SparkAccountRef, params: {
|
|
357
|
-
receiver: string;
|
|
358
|
-
amountSats: number;
|
|
359
|
-
verify: UnlockFactor;
|
|
360
|
-
}): Promise<SparkTransfer>;
|
|
361
|
-
registerLightningAddress(ref: SparkAccountRef, params: {
|
|
362
|
-
serverUrl: string;
|
|
363
|
-
domain: string;
|
|
364
|
-
username: string;
|
|
365
|
-
description: string;
|
|
366
|
-
}): Promise<{
|
|
367
|
-
lnurl: string;
|
|
368
|
-
lightningAddress: string;
|
|
369
|
-
}>;
|
|
370
|
-
unregisterLightningAddress(ref: SparkAccountRef, params: {
|
|
371
|
-
serverUrl: string;
|
|
372
|
-
domain: string;
|
|
373
|
-
username: string;
|
|
374
|
-
}): Promise<void>;
|
|
375
|
-
payInvoice(ref: SparkAccountRef, params: {
|
|
376
|
-
invoice: string;
|
|
377
|
-
amountSats?: number;
|
|
378
|
-
maxFeeSats: number;
|
|
379
|
-
verify: UnlockFactor;
|
|
380
|
-
/** Local annotation written under the payment's transfer id after it succeeds. */
|
|
381
|
-
note?: PaymentNote;
|
|
382
|
-
}): Promise<LightningPayment>;
|
|
383
|
-
/**
|
|
384
|
-
* Pays a Spark invoice address. The approval intent mirrors `send`: receiver identity and amount
|
|
385
|
-
* come from the parsed invoice (the supplied `amountSats` fills an open invoice). Then
|
|
386
|
-
* `client.invoices.pay` executes it.
|
|
387
|
-
*/
|
|
388
|
-
paySparkInvoice(ref: SparkAccountRef, params: {
|
|
389
|
-
invoice: string;
|
|
390
|
-
amountSats?: number;
|
|
391
|
-
verify: UnlockFactor;
|
|
392
|
-
}): Promise<SparkTransfer>;
|
|
393
|
-
createInvoice(ref: SparkAccountRef, params: {
|
|
394
|
-
amountSats: number;
|
|
395
|
-
memo?: string;
|
|
396
|
-
}): Promise<LightningInvoice>;
|
|
397
|
-
receiveAddress(ref: SparkAccountRef): Promise<string | undefined>;
|
|
398
|
-
/**
|
|
399
|
-
* Cooperative exit to an L1 address. The client exits `amountSats` of leaves and the payout is
|
|
400
|
-
* `amountSats - fee`, so the approval intent carries the PAYOUT: `amountSats: exit - fee` and
|
|
401
|
-
* `maxFeeSats: fee` — the kernel matches the exit output against the intent, not the leaf total.
|
|
402
|
-
*/
|
|
403
|
-
withdraw(ref: SparkAccountRef, params: {
|
|
404
|
-
address: string;
|
|
405
|
-
amountSats?: number;
|
|
406
|
-
speed: "FAST" | "MEDIUM" | "SLOW";
|
|
407
|
-
maxFeeSats?: number;
|
|
408
|
-
verify: UnlockFactor;
|
|
409
|
-
}): Promise<CooperativeExitResult>;
|
|
410
|
-
}
|
|
411
|
-
//#endregion
|
|
412
|
-
//#region src/payments/action.d.ts
|
|
413
|
-
/**
|
|
414
|
-
* What the host shows for a Spark, Lightning or exit request; `family` tells it apart from a chain
|
|
415
|
-
* intent.
|
|
416
|
-
*/
|
|
417
|
-
type SparkDisplay = {
|
|
418
|
-
readonly family: "spark";
|
|
419
|
-
readonly network: SparkNetwork;
|
|
420
|
-
readonly kind: "transfer" | "lightning" | "exit";
|
|
421
|
-
readonly amountSats: number;
|
|
422
|
-
readonly maxFeeSats?: number;
|
|
423
|
-
/** Spark address, Lightning payee public key (hex) or bitcoin address. */
|
|
424
|
-
readonly receiver: string;
|
|
425
|
-
/** Invoice description or the LNURL metadata text. */
|
|
426
|
-
readonly description?: string;
|
|
427
|
-
};
|
|
428
|
-
type SparkResult = {
|
|
429
|
-
readonly kind: "spark";
|
|
430
|
-
readonly transfer: SparkTransfer;
|
|
431
|
-
} | {
|
|
432
|
-
readonly kind: "lightning";
|
|
433
|
-
readonly payment: LightningPayment;
|
|
434
|
-
} | {
|
|
435
|
-
readonly kind: "withdraw";
|
|
436
|
-
readonly exit: CooperativeExitResult;
|
|
437
|
-
};
|
|
438
|
-
/**
|
|
439
|
-
* A validated, fixed Spark payment: everything that does not need the user's verification has
|
|
440
|
-
* happened (including any LNURL invoice fetch), so approval only re-checks expiry and executes.
|
|
441
|
-
*/
|
|
442
|
-
type PreparedSparkAction = {
|
|
443
|
-
readonly display: SparkDisplay;
|
|
444
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
445
|
-
/** Why the action can no longer be paid at `now` (an expiring invoice), if so. */
|
|
446
|
-
readonly staleReason: (now: number) => string | undefined;
|
|
447
|
-
/** Runs the controller's approve-first payment call. */
|
|
448
|
-
readonly execute: (spark: SparkController, verify: UnlockFactor) => Promise<SparkResult>;
|
|
449
|
-
};
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region src/payments/parse.d.ts
|
|
452
|
-
type PaymentOption = {
|
|
453
|
-
readonly kind: "spark";
|
|
454
|
-
readonly address: string;
|
|
455
|
-
} | {
|
|
456
|
-
readonly kind: "spark-invoice";
|
|
457
|
-
readonly invoice: string;
|
|
458
|
-
readonly amountSats?: number;
|
|
459
|
-
readonly memo?: string;
|
|
460
|
-
readonly expiresAt?: number;
|
|
461
|
-
} | {
|
|
462
|
-
readonly kind: "lightning";
|
|
463
|
-
readonly invoice: string;
|
|
464
|
-
readonly amountSats?: number;
|
|
465
|
-
readonly paymentHash: string;
|
|
466
|
-
readonly description?: string;
|
|
467
|
-
readonly expiresAt: number;
|
|
468
|
-
} | {
|
|
469
|
-
readonly kind: "lnurl-pay";
|
|
470
|
-
readonly request: LnurlPayRequest;
|
|
471
|
-
readonly address?: string;
|
|
472
|
-
} | {
|
|
473
|
-
readonly kind: "lnurl-withdraw";
|
|
474
|
-
readonly request: LnurlWithdrawRequest;
|
|
475
|
-
} | {
|
|
476
|
-
readonly kind: "bitcoin";
|
|
477
|
-
readonly address: string;
|
|
478
|
-
};
|
|
479
|
-
type PaymentRequest = {
|
|
480
|
-
readonly options: ReadonlyArray<PaymentOption>;
|
|
481
|
-
readonly amountSats?: number;
|
|
482
|
-
readonly label?: string;
|
|
483
|
-
readonly message?: string;
|
|
484
|
-
};
|
|
485
|
-
type PaymentParse = {
|
|
486
|
-
readonly kind: "request";
|
|
487
|
-
readonly request: PaymentRequest;
|
|
488
|
-
} | {
|
|
489
|
-
readonly kind: "lnurl";
|
|
490
|
-
readonly url: string;
|
|
491
|
-
readonly address?: string;
|
|
492
|
-
} | {
|
|
493
|
-
readonly kind: "unsupported";
|
|
494
|
-
readonly format: "bolt12" | "silent-payment" | "lnurl-auth" | "spark-token-invoice" | "nostr-wallet-connect";
|
|
495
|
-
} | {
|
|
496
|
-
readonly kind: "invalid";
|
|
497
|
-
readonly reason: "network" | "expired" | "amount-mismatch" | "malformed";
|
|
498
|
-
} | {
|
|
499
|
-
readonly kind: "unrecognized";
|
|
500
|
-
};
|
|
501
|
-
type ParseOptions = {
|
|
502
|
-
readonly network: SparkNetwork;
|
|
503
|
-
readonly now: number;
|
|
504
|
-
};
|
|
505
|
-
/** `input` → PaymentParse. Never throws: every failure is a structured result. */
|
|
506
|
-
export declare function parsePayment(input: string, options: ParseOptions): PaymentParse;
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/payments/pay.d.ts
|
|
509
|
-
type PayParams = {
|
|
510
|
-
readonly account: SparkAccountRef;
|
|
511
|
-
readonly option: PaymentOption;
|
|
512
|
-
/** Caller-supplied amount — required by open invoices, the `spark` option, and LNURL flows. */
|
|
513
|
-
readonly amountSats?: number;
|
|
514
|
-
readonly comment?: string;
|
|
515
|
-
readonly maxFeeSats?: number;
|
|
516
|
-
readonly speed?: "FAST" | "MEDIUM" | "SLOW";
|
|
517
|
-
};
|
|
518
|
-
type WithdrawLnurlParams = {
|
|
519
|
-
readonly account: SparkAccountRef;
|
|
520
|
-
readonly option: Extract<PaymentOption, {
|
|
521
|
-
kind: "lnurl-withdraw";
|
|
522
|
-
}>;
|
|
523
|
-
readonly amountSats: number;
|
|
524
|
-
};
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region src/payments/zap.d.ts
|
|
527
|
-
/** A profile zap names the recipient pubkey; an event zap carries the event it zaps. */
|
|
528
|
-
type ZapRecipient = {
|
|
529
|
-
readonly pubkey: string;
|
|
530
|
-
readonly lightning: string;
|
|
531
|
-
} | {
|
|
532
|
-
readonly event: Event;
|
|
533
|
-
readonly lightning: string;
|
|
534
|
-
};
|
|
535
|
-
type PrepareZapParams = {
|
|
536
|
-
/** Any `NostrSigner` — wallet key, external key, NIP-07/46 — signs the 9734. */
|
|
537
|
-
readonly signer: NostrSigner;
|
|
538
|
-
readonly recipient: ZapRecipient;
|
|
539
|
-
readonly amountSats: number;
|
|
540
|
-
readonly comment?: string | undefined;
|
|
541
|
-
readonly relays: ReadonlyArray<string>;
|
|
542
|
-
readonly network: SparkNetwork;
|
|
543
|
-
};
|
|
544
|
-
type PrepareZapContext = {
|
|
545
|
-
readonly fetch: typeof globalThis.fetch;
|
|
546
|
-
readonly now: () => number;
|
|
547
|
-
};
|
|
548
|
-
/** Everything a payer needs: the signed 9734, the invoice, and the note fields. */
|
|
549
|
-
type PreparedZap = {
|
|
550
|
-
readonly zapRequest: Event;
|
|
551
|
-
readonly invoice: string;
|
|
552
|
-
/** Hex payment hash decoded from the invoice. */
|
|
553
|
-
readonly paymentHash: string;
|
|
554
|
-
/** Millisecond expiry decoded from the invoice. */
|
|
555
|
-
readonly expiresAt: number;
|
|
556
|
-
readonly amountSats: number;
|
|
557
|
-
/** The LNURL service's 9735 signing pubkey. */
|
|
558
|
-
readonly receiptPubkey: string;
|
|
559
|
-
readonly recipientPubkey: string;
|
|
560
|
-
readonly eventId?: string;
|
|
561
|
-
readonly comment?: string;
|
|
562
|
-
/** The lud16 or LNURL as given. */
|
|
563
|
-
readonly lightning: string;
|
|
564
|
-
};
|
|
565
|
-
/** Everything up to payment: resolve LNURL, sign the 9734, request the invoice. */
|
|
566
|
-
export declare function prepareZap(params: PrepareZapParams, context: PrepareZapContext): Promise<PreparedZap>;
|
|
567
|
-
//#endregion
|
|
568
|
-
//#region src/transactions/route.d.ts
|
|
569
|
-
type SignParams = Parameters<ReturnType<typeof chains>["sign"]>[0];
|
|
570
|
-
type AccountRef = SignParams["request"]["account"];
|
|
571
|
-
type DisplayIntent = ReturnType<typeof decodeEvm>;
|
|
572
|
-
type TxState = "draft" | "signed" | "submitted" | "pending" | "confirmed" | "failed" | "rejected" | "dropped" | "replaced";
|
|
573
|
-
type TrackedTransaction = {
|
|
574
|
-
readonly id: string;
|
|
575
|
-
readonly family: "evm" | "solana" | "bitcoin";
|
|
576
|
-
readonly network: string;
|
|
577
|
-
readonly account: string;
|
|
578
|
-
readonly hash: string | undefined;
|
|
579
|
-
readonly state: TxState;
|
|
580
|
-
readonly intent: DisplayIntent | undefined;
|
|
581
|
-
readonly nonce: number;
|
|
582
|
-
/** Solana only — the blockhash expiry that turns an unconfirmed tx `dropped`. */
|
|
583
|
-
readonly lastValidBlockHeight?: number;
|
|
584
|
-
/** EVM replacement — the earlier transaction this one bumps or cancels. */
|
|
585
|
-
readonly replaces?: string;
|
|
586
|
-
/** CPFP — the unconfirmed parent this child pushes. */
|
|
587
|
-
readonly parentId?: string;
|
|
588
|
-
/** Bitcoin build record persisted at send for RBF/CPFP rebuilds. */
|
|
589
|
-
readonly btc?: {
|
|
590
|
-
readonly inputs: ReadonlyArray<{
|
|
591
|
-
readonly txid: string;
|
|
592
|
-
readonly vout: number;
|
|
593
|
-
readonly value: number;
|
|
594
|
-
readonly address: string;
|
|
595
|
-
}>;
|
|
596
|
-
readonly outputs: ReadonlyArray<{
|
|
597
|
-
readonly address: string;
|
|
598
|
-
readonly value: number;
|
|
599
|
-
readonly own: boolean;
|
|
600
|
-
}>;
|
|
601
|
-
readonly vsize: number;
|
|
602
|
-
readonly fee: number;
|
|
603
|
-
readonly feeRate: number;
|
|
604
|
-
};
|
|
605
|
-
readonly submittedAt: number;
|
|
606
|
-
readonly error: string | undefined;
|
|
607
|
-
};
|
|
608
|
-
type SendParams = {
|
|
609
|
-
readonly account: AccountRef;
|
|
610
|
-
readonly network: string;
|
|
611
|
-
readonly to: string;
|
|
612
|
-
readonly amount: bigint;
|
|
613
|
-
/** ERC-20 contract — when set, `to`/`amount` are the transfer recipient/units and value is 0. */
|
|
614
|
-
readonly token?: string;
|
|
615
|
-
readonly fee: EvmFeeTier | SolanaFeeTier;
|
|
616
|
-
/** SPL mint decimals — required when `token` is a Solana mint. */
|
|
617
|
-
readonly decimals?: number;
|
|
618
|
-
readonly verify: SignParams["verify"];
|
|
619
|
-
};
|
|
620
|
-
type PrepareParams = Omit<SendParams, "verify">;
|
|
621
|
-
type ChainRequestMethod = "send" | "speed-up" | "cancel" | "cpfp";
|
|
622
|
-
/** What a request asks for; replacements and CPFP name the original transaction. */
|
|
623
|
-
type ChainRequestInput = ({
|
|
624
|
-
readonly method: "send";
|
|
625
|
-
} & PrepareParams) | {
|
|
626
|
-
readonly method: "speed-up" | "cancel";
|
|
627
|
-
readonly txId: string;
|
|
628
|
-
} | {
|
|
629
|
-
readonly method: "cpfp";
|
|
630
|
-
readonly txId: string;
|
|
631
|
-
readonly feeRate: number;
|
|
632
|
-
};
|
|
633
|
-
/**
|
|
634
|
-
* A fully built, estimated and cross-checked send that has not been signed. The unsigned content
|
|
635
|
-
* lives in the closures and cannot change after `prepare` returns.
|
|
636
|
-
*/
|
|
637
|
-
type PreparedRequest = {
|
|
638
|
-
/** Id of the tracked transaction `submit` creates. */
|
|
639
|
-
readonly txId: string;
|
|
640
|
-
readonly account: AccountRef;
|
|
641
|
-
readonly network: string;
|
|
642
|
-
/** The transaction being replaced or accelerated; absent for a plain send. */
|
|
643
|
-
readonly target?: string;
|
|
644
|
-
readonly intent: DisplayIntent;
|
|
645
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
646
|
-
/** Why the build can no longer be signed (nonce taken, blockhash expired), if so. */
|
|
647
|
-
readonly staleReason: () => string | undefined | Promise<string | undefined>;
|
|
648
|
-
/** Signs, finalizes, broadcasts and hands the transaction to tracking. */
|
|
649
|
-
readonly submit: (verify: SendParams["verify"]) => Promise<TrackedTransaction>;
|
|
650
|
-
/** Frees what `prepare` reserved; safe to call more than once. */
|
|
651
|
-
readonly release: () => void;
|
|
652
|
-
};
|
|
653
|
-
type Options$1 = {
|
|
654
|
-
readonly wallet: Wallet;
|
|
655
|
-
readonly networks: NetworkController;
|
|
656
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
657
|
-
readonly random: (n: number) => Uint8Array;
|
|
658
|
-
readonly setTimer: (ms: number, fn: () => unknown) => () => void;
|
|
659
|
-
readonly now: () => number;
|
|
660
|
-
readonly logger: EngineLogger;
|
|
661
|
-
readonly pollMs?: number;
|
|
662
|
-
/** Test seam — defaults to the wallet's real chains proxy. */
|
|
663
|
-
readonly chains?: ReturnType<typeof chains>;
|
|
664
|
-
};
|
|
665
|
-
//#endregion
|
|
666
|
-
//#region src/transactions/controller.d.ts
|
|
667
|
-
type TransactionControllerState = {
|
|
668
|
-
readonly txs: Record<string, TrackedTransaction>;
|
|
669
|
-
};
|
|
670
|
-
declare class TransactionController extends Controller<TransactionControllerState> {
|
|
671
|
-
private readonly options;
|
|
672
|
-
private engineStore?;
|
|
673
|
-
private readonly timers;
|
|
674
|
-
private evmRoute;
|
|
675
|
-
private bitcoinRoute;
|
|
676
|
-
private locked;
|
|
677
|
-
constructor(options: Options$1);
|
|
678
|
-
init(): Promise<void>;
|
|
679
|
-
destroy(): Promise<void>;
|
|
680
|
-
lock(): void;
|
|
681
|
-
private persist;
|
|
682
|
-
private transition;
|
|
683
|
-
private routeCtx;
|
|
684
|
-
/**
|
|
685
|
-
* Internal entry for the request pipeline: builds, estimates and cross-checks a send without
|
|
686
|
-
* signing it. Bitcoin outputs it selects stay locked under `requestId` until the returned
|
|
687
|
-
* `release` runs or the broadcast moves them to the transaction.
|
|
688
|
-
*/
|
|
689
|
-
prepareSend(params: PrepareParams, requestId: string): Promise<PreparedRequest>;
|
|
690
|
-
/**
|
|
691
|
-
* Internal entry for replacements and CPFP: builds, cross-checks and reserves what the
|
|
692
|
-
* replacement needs without signing it. The original must be `submitted` or `pending`.
|
|
693
|
-
*/
|
|
694
|
-
prepareReplacement(input: Exclude<ChainRequestInput, {
|
|
695
|
-
method: "send";
|
|
696
|
-
}>, requestId: string): Promise<PreparedRequest>;
|
|
697
|
-
private track;
|
|
698
|
-
}
|
|
699
|
-
//#endregion
|
|
700
|
-
//#region src/requests/risk.d.ts
|
|
701
|
-
/**
|
|
702
|
-
* Recipient risk, pure: a recipient the wallet has never paid or saved is a `warning`; one that
|
|
703
|
-
* looks like a known address (same first and last four characters, different address) is a `danger`
|
|
704
|
-
* — the shape of an address-poisoning lookalike. Both can apply to one recipient.
|
|
705
|
-
*/
|
|
706
|
-
type RiskFinding = {
|
|
707
|
-
readonly code: "first-recipient" | "address-poisoning";
|
|
708
|
-
readonly level: "warning" | "danger";
|
|
709
|
-
};
|
|
710
|
-
//#endregion
|
|
711
|
-
//#region src/requests/sign-log.d.ts
|
|
712
|
-
type SignLogOutcome = "submitted" | "rejected" | "failed" | "expired" | "invalidated";
|
|
713
|
-
type SignLogEntry = {
|
|
714
|
-
readonly id: string;
|
|
715
|
-
readonly at: number;
|
|
716
|
-
readonly origin: {
|
|
717
|
-
readonly kind: "internal";
|
|
718
|
-
};
|
|
719
|
-
readonly method: RequestMethod;
|
|
720
|
-
readonly account: AccountRef | SparkAccountRef;
|
|
721
|
-
readonly network: string;
|
|
722
|
-
readonly summary: string;
|
|
723
|
-
readonly verification: "verified" | "unverifiable";
|
|
724
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
725
|
-
readonly risk: ReadonlyArray<RiskFinding>;
|
|
726
|
-
readonly outcome: SignLogOutcome;
|
|
727
|
-
readonly error?: string;
|
|
728
|
-
};
|
|
729
|
-
//#endregion
|
|
730
|
-
//#region src/requests/controller.d.ts
|
|
731
|
-
/** A Spark, Lightning (including LNURL-pay and lightning addresses) or cooperative-exit payment. */
|
|
732
|
-
type PayInput = {
|
|
733
|
-
readonly method: "pay";
|
|
734
|
-
} & PayParams;
|
|
735
|
-
/** A prepared zap; its invoice was fetched by `engine.zaps.prepare` and is paid as-is. */
|
|
736
|
-
type ZapInput = {
|
|
737
|
-
readonly method: "zap";
|
|
738
|
-
readonly account: SparkAccountRef;
|
|
739
|
-
readonly zap: PreparedZap;
|
|
740
|
-
readonly maxFeeSats: number;
|
|
741
|
-
};
|
|
742
|
-
type RequestMethod = ChainRequestMethod | "pay" | "zap";
|
|
743
|
-
type RequestInput = ChainRequestInput | PayInput | ZapInput;
|
|
744
|
-
type RequestStage = "awaiting-approval" | "signing" | "submitted" | "rejected" | "failed" | "expired" | "invalidated";
|
|
745
|
-
type PendingRequest = {
|
|
746
|
-
readonly id: string;
|
|
747
|
-
readonly origin: {
|
|
748
|
-
readonly kind: "internal";
|
|
749
|
-
};
|
|
750
|
-
readonly method: RequestMethod;
|
|
751
|
-
readonly account: AccountRef | SparkAccountRef;
|
|
752
|
-
readonly network: string;
|
|
753
|
-
readonly stage: RequestStage;
|
|
754
|
-
/** Decoded locally from the exact content that will be signed; `family` tells the shapes apart. */
|
|
755
|
-
readonly display: DisplayIntent | SparkDisplay;
|
|
756
|
-
/** `unverifiable` as soon as any check is recorded; the host must ask for explicit confirmation. */
|
|
757
|
-
readonly verification: "verified" | "unverifiable";
|
|
758
|
-
readonly checks: ReadonlyArray<RequestCheckCode>;
|
|
759
|
-
/**
|
|
760
|
-
* Recipient risk; independent of `verification`. A `danger` needs the user's explicit
|
|
761
|
-
* acknowledgement.
|
|
762
|
-
*/
|
|
763
|
-
readonly risk: ReadonlyArray<RiskFinding>;
|
|
764
|
-
readonly createdAt: number;
|
|
765
|
-
readonly expiresAt: number;
|
|
766
|
-
/** The transaction being replaced or accelerated; absent for a plain send. */
|
|
767
|
-
readonly target?: string;
|
|
768
|
-
/** The tracked transaction once submitted. */
|
|
769
|
-
readonly txId?: string;
|
|
770
|
-
readonly error?: string;
|
|
771
|
-
};
|
|
772
|
-
type RequestControllerState = {
|
|
773
|
-
readonly requests: Record<string, PendingRequest>;
|
|
774
|
-
};
|
|
775
|
-
type RequestControllerOptions = {
|
|
776
|
-
readonly transactions: TransactionController;
|
|
777
|
-
/** The full controller: its payment methods are reachable only through this pipeline. */
|
|
778
|
-
readonly spark: SparkController;
|
|
779
|
-
readonly addressBook: AddressBookController;
|
|
780
|
-
readonly openStore: () => Promise<EngineStore>;
|
|
781
|
-
readonly fetch: typeof globalThis.fetch;
|
|
782
|
-
readonly random: (n: number) => Uint8Array;
|
|
783
|
-
readonly now: () => number;
|
|
784
|
-
readonly setTimer: (ms: number, fn: () => unknown) => () => void;
|
|
785
|
-
readonly logger: EngineLogger;
|
|
786
|
-
};
|
|
787
|
-
/** Requests expire this long after creation. */
|
|
788
|
-
export declare const REQUEST_TTL_MS: number;
|
|
789
|
-
export declare class RequestController extends Controller<RequestControllerState> {
|
|
790
|
-
private readonly options;
|
|
791
|
-
private readonly entries;
|
|
792
|
-
private readonly log;
|
|
793
|
-
/** Original transaction id → the unfinished request replacing or accelerating it. */
|
|
794
|
-
private readonly targets;
|
|
795
|
-
private locked;
|
|
796
|
-
/** Bumped on every unlock and lock so work that outlives a session never touches the next one. */
|
|
797
|
-
private session;
|
|
798
|
-
constructor(options: RequestControllerOptions);
|
|
799
|
-
init(): Promise<void>;
|
|
800
|
-
destroy(): Promise<void>;
|
|
801
|
-
/** Locking is not consent: every unfinished request becomes `invalidated` and frees its resources. */
|
|
802
|
-
lock(): void;
|
|
803
|
-
/** The signature record, newest first. */
|
|
804
|
-
signLog(): Promise<ReadonlyArray<SignLogEntry>>;
|
|
805
|
-
clearSignLog(): Promise<void>;
|
|
806
|
-
prepare(input: RequestInput): Promise<PendingRequest>;
|
|
807
|
-
private build;
|
|
808
|
-
/**
|
|
809
|
-
* Signs and submits a request. Anything but a live, unexpired `send` request with this id throws
|
|
810
|
-
* before any signing; a stale build (nonce taken, blockhash expired) fails without signing.
|
|
811
|
-
*/
|
|
812
|
-
approve(id: string, method: ChainRequestMethod, verify: SendParams["verify"]): Promise<TrackedTransaction>;
|
|
813
|
-
approve(id: string, method: "pay" | "zap", verify: SendParams["verify"]): Promise<SparkResult>;
|
|
814
|
-
/**
|
|
815
|
-
* A cancelled or refused verification is `rejected`; anything after it is `failed`. Chain
|
|
816
|
-
* requests record which step failed on the tracked transaction; for Spark, the approval round is
|
|
817
|
-
* the only source of `WalletError`.
|
|
818
|
-
*/
|
|
819
|
-
private failureStage;
|
|
820
|
-
reject(id: string): void;
|
|
821
|
-
private requireRequest;
|
|
822
|
-
private put;
|
|
823
|
-
private unclaim;
|
|
824
|
-
/** Ends a request in a terminal stage and frees what it reserved. */
|
|
825
|
-
private finish;
|
|
826
|
-
/** Appends the final stage to the signature record; a failed write is a warning, not an error. */
|
|
827
|
-
private record;
|
|
828
|
-
private appendLog;
|
|
829
|
-
/**
|
|
830
|
-
* Addresses the wallet already knows for a family: contacts, plus recipients of tracked chain
|
|
831
|
-
* sends (Spark payments are not tracked).
|
|
832
|
-
*/
|
|
833
|
-
private knownAddresses;
|
|
834
|
-
private chainRisk;
|
|
835
|
-
/** Only a Spark transfer has a recipient to check; Lightning and exits are not assessed. */
|
|
836
|
-
private sparkRisk;
|
|
837
|
-
}
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region src/meta/doc.d.ts
|
|
840
21
|
/**
|
|
841
22
|
* Wallet metadata document — the plaintext exchanged over kind-30078 events between this wallet's
|
|
842
23
|
* own devices. One document per wallet; entry-level last-writer-wins on `updatedAt`.
|
|
@@ -862,8 +43,6 @@ type MetaDoc = MetaDocTree & {
|
|
|
862
43
|
readonly v: 2;
|
|
863
44
|
readonly contacts: ReadonlyArray<AddressBookRecord>;
|
|
864
45
|
};
|
|
865
|
-
//#endregion
|
|
866
|
-
//#region src/accounts/controller.d.ts
|
|
867
46
|
type AccountGroup = {
|
|
868
47
|
readonly walletId: string;
|
|
869
48
|
readonly index: number;
|
|
@@ -999,8 +178,6 @@ export declare class AccountTreeController extends Controller<AccountTreeState>
|
|
|
999
178
|
private scheduleTotalsPersist;
|
|
1000
179
|
private flushTotals;
|
|
1001
180
|
}
|
|
1002
|
-
//#endregion
|
|
1003
|
-
//#region src/assets/controller.d.ts
|
|
1004
181
|
type TokenBalance = {
|
|
1005
182
|
readonly address: string;
|
|
1006
183
|
readonly symbol: string;
|
|
@@ -1045,26 +222,19 @@ declare class AssetsController extends Controller<AssetsControllerState> {
|
|
|
1045
222
|
private readTokens;
|
|
1046
223
|
private balanceOfBatch;
|
|
1047
224
|
private balanceOf;
|
|
1048
|
-
private
|
|
1049
|
-
private callNumber;
|
|
225
|
+
private callToken;
|
|
1050
226
|
/** Reads symbol/decimals on-chain, marks unverified, persists; throws when the calls fail. */
|
|
1051
227
|
addToken(network: string, address: string): Promise<void>;
|
|
1052
228
|
private persistToken;
|
|
1053
|
-
private rpc;
|
|
1054
|
-
private rpcHex;
|
|
1055
229
|
/** BTC balance = confirmed spendable + own unconfirmed change; frozen 546/330 shown separately. */
|
|
1056
230
|
refreshBitcoin(xpub: string, network: string): Promise<void>;
|
|
1057
231
|
}
|
|
1058
|
-
//#endregion
|
|
1059
|
-
//#region src/backup/errors.d.ts
|
|
1060
232
|
/** BackupController error categories — never carry file contents, digests or secrets. */
|
|
1061
233
|
type BackupErrorCategory = "cloud" | "conflict" | "unavailable";
|
|
1062
234
|
export declare class BackupControllerError extends Error {
|
|
1063
235
|
readonly category: BackupErrorCategory;
|
|
1064
236
|
constructor(category: BackupErrorCategory, message: string);
|
|
1065
237
|
}
|
|
1066
|
-
//#endregion
|
|
1067
|
-
//#region src/backup/port.d.ts
|
|
1068
238
|
/**
|
|
1069
239
|
* Cloud-file storage port (design/backup.mdx "存储"): the cloud is an opaque key-value namespace —
|
|
1070
240
|
* names are file names (`qntx-wallet-backup-<id>.json`), contents are envelope texts. The kernel
|
|
@@ -1082,8 +252,6 @@ type CloudStore = {
|
|
|
1082
252
|
/** Deleting a missing file succeeds. */
|
|
1083
253
|
readonly delete: (name: string) => Promise<void>;
|
|
1084
254
|
};
|
|
1085
|
-
//#endregion
|
|
1086
|
-
//#region src/backup/controller.d.ts
|
|
1087
255
|
type BackupControllerState = {
|
|
1088
256
|
readonly status: "locked" | "unavailable" | "off" | "syncing" | "synced" | "conflict" | "error";
|
|
1089
257
|
/** The retained backup key's public summary from the wallet snapshot. */
|
|
@@ -1091,7 +259,6 @@ type BackupControllerState = {
|
|
|
1091
259
|
readonly uploadedAt: number | undefined;
|
|
1092
260
|
readonly unprotected: {
|
|
1093
261
|
readonly walletIds: ReadonlyArray<string>;
|
|
1094
|
-
readonly nostrKeyIds: ReadonlyArray<string>;
|
|
1095
262
|
};
|
|
1096
263
|
readonly error: BackupErrorCategory | undefined;
|
|
1097
264
|
};
|
|
@@ -1153,16 +320,12 @@ export declare class BackupController extends Controller<BackupControllerState>
|
|
|
1153
320
|
private reconcile;
|
|
1154
321
|
private pass;
|
|
1155
322
|
}
|
|
1156
|
-
//#endregion
|
|
1157
|
-
//#region src/meta/errors.d.ts
|
|
1158
323
|
/** Meta-sync error categories — messages never carry event or document content. */
|
|
1159
324
|
type MetaSyncErrorCategory = "network" | "internal" | "unsupported" | "corrupt";
|
|
1160
325
|
export declare class MetaSyncError extends Error {
|
|
1161
326
|
readonly category: MetaSyncErrorCategory;
|
|
1162
327
|
constructor(category: MetaSyncErrorCategory, message: string, cause?: unknown);
|
|
1163
328
|
}
|
|
1164
|
-
//#endregion
|
|
1165
|
-
//#region src/meta/controller.d.ts
|
|
1166
329
|
type MetaSyncRelayPort = {
|
|
1167
330
|
readonly fetch: (filter: Filter) => Promise<ReadonlyArray<Event>>;
|
|
1168
331
|
readonly publish: (event: Event) => Promise<void>;
|
|
@@ -1173,7 +336,7 @@ type MetaSyncConfig = {
|
|
|
1173
336
|
readonly relays: MetaSyncRelayPort;
|
|
1174
337
|
};
|
|
1175
338
|
type MetaSyncWalletStatus = {
|
|
1176
|
-
readonly status: "
|
|
339
|
+
readonly status: "syncing" | "synced" | "error";
|
|
1177
340
|
readonly error?: MetaSyncErrorCategory;
|
|
1178
341
|
};
|
|
1179
342
|
type MetaSyncState = {
|
|
@@ -1194,19 +357,21 @@ type MetaSyncControllerOptions = {
|
|
|
1194
357
|
readonly wallet: Wallet;
|
|
1195
358
|
readonly accounts: AccountTreeController;
|
|
1196
359
|
readonly addressBook: AddressBookSync;
|
|
1197
|
-
/** `nostr(wallet)` —
|
|
360
|
+
/** `nostr(wallet).syncSigner` — each wallet signs metadata with its dedicated sync key. */
|
|
1198
361
|
readonly nostr: {
|
|
1199
|
-
readonly
|
|
362
|
+
readonly syncSigner: (walletId: string) => WalletSyncSigner;
|
|
1200
363
|
};
|
|
1201
364
|
readonly metaSync: MetaSyncConfig | undefined;
|
|
1202
365
|
readonly logger: EngineLogger;
|
|
1203
366
|
readonly now: () => number;
|
|
367
|
+
readonly verifyEvent: (event: Event) => boolean;
|
|
1204
368
|
};
|
|
1205
369
|
/**
|
|
1206
370
|
* Wallet-metadata sync over kind-30078 addressable events: one NIP-44-encrypted document per
|
|
1207
|
-
* wallet, authored by its
|
|
1208
|
-
* replaceable events would otherwise let a stale local tree overwrite a newer remote
|
|
1209
|
-
* Debounced publishes are per wallet; a generation counter cancels in-flight write-backs
|
|
371
|
+
* wallet, authored by its dedicated sync key (WD-070). Pull always precedes publish in an unlock
|
|
372
|
+
* session — replaceable events would otherwise let a stale local tree overwrite a newer remote
|
|
373
|
+
* document. Debounced publishes are per wallet; a generation counter cancels in-flight write-backs
|
|
374
|
+
* on lock.
|
|
1210
375
|
*/
|
|
1211
376
|
export declare class MetaSyncController extends Controller<MetaSyncState> {
|
|
1212
377
|
private readonly options;
|
|
@@ -1229,8 +394,6 @@ export declare class MetaSyncController extends Controller<MetaSyncState> {
|
|
|
1229
394
|
/** Manual re-pull of every wallet that can sync. */
|
|
1230
395
|
sync(): Promise<void>;
|
|
1231
396
|
private pullAll;
|
|
1232
|
-
private pubkeyFor;
|
|
1233
|
-
private signerFor;
|
|
1234
397
|
private setStatus;
|
|
1235
398
|
private pullOne;
|
|
1236
399
|
/** The wallet's tree plus the shared address book — every wallet's document carries both. */
|
|
@@ -1242,15 +405,23 @@ export declare class MetaSyncController extends Controller<MetaSyncState> {
|
|
|
1242
405
|
private onTreeChange;
|
|
1243
406
|
private publishNow;
|
|
1244
407
|
}
|
|
1245
|
-
//#endregion
|
|
1246
|
-
//#region src/engine.d.ts
|
|
1247
408
|
type EngineOptions = {
|
|
1248
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;
|
|
1249
416
|
/** Every Spark account the engine touches lives on this network. */
|
|
1250
417
|
readonly sparkNetwork: SparkNetwork;
|
|
1251
418
|
readonly fetch: typeof globalThis.fetch;
|
|
1252
419
|
readonly random: (length: number) => Uint8Array;
|
|
1253
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;
|
|
1254
425
|
readonly logger: EngineLogger;
|
|
1255
426
|
readonly openStore: () => Promise<EngineStore>;
|
|
1256
427
|
/** Cloud file transport for the backup controller; absent → `unavailable`. */
|
|
@@ -1269,8 +440,10 @@ type EngineOptions = {
|
|
|
1269
440
|
readonly installId: string;
|
|
1270
441
|
};
|
|
1271
442
|
/** Injected timer for transaction polling; defaults to setTimeout. */
|
|
443
|
+
/** Development builds: also accept `http://localhost` as a dApp origin. */
|
|
444
|
+
readonly allowLocalhostOrigins?: boolean;
|
|
1272
445
|
readonly setTimer?: (ms: number, fn: () => void) => () => void;
|
|
1273
|
-
/** Kind-30078 wallet-metadata sync; absent →
|
|
446
|
+
/** Kind-30078 wallet-metadata sync; absent → no wallet metadata is synced. */
|
|
1274
447
|
readonly metaSync?: MetaSyncConfig;
|
|
1275
448
|
/** Test seam — defaults to the wallet's real spark proxy. */
|
|
1276
449
|
readonly sparkApis?: SparkControllerOptions["spark"];
|
|
@@ -1281,6 +454,11 @@ type WalletEngine = {
|
|
|
1281
454
|
readonly transactions: TransactionController;
|
|
1282
455
|
readonly requests: RequestController;
|
|
1283
456
|
readonly addressBook: AddressBookController;
|
|
457
|
+
readonly connections: ConnectionController;
|
|
458
|
+
readonly eip1193: Eip1193Handler;
|
|
459
|
+
readonly nip07: Nip07Handler;
|
|
460
|
+
readonly webln: WeblnHandler;
|
|
461
|
+
readonly solanaWallet: SolanaWalletHandler;
|
|
1284
462
|
/** Read and receive surface; every payment goes through `requests`. */
|
|
1285
463
|
readonly spark: Omit<SparkController, "send" | "payInvoice" | "paySparkInvoice" | "withdraw">;
|
|
1286
464
|
readonly accounts: AccountTreeController;
|
|
@@ -1301,36 +479,26 @@ type WalletEngine = {
|
|
|
1301
479
|
readonly unsubscribe: () => void;
|
|
1302
480
|
};
|
|
1303
481
|
export declare function createWalletEngine(options: EngineOptions): WalletEngine;
|
|
1304
|
-
//#endregion
|
|
1305
|
-
//#region src/backup/memory.d.ts
|
|
1306
482
|
/** In-memory CloudStore for tests and the playground; swap the Map for cross-engine sharing. */
|
|
1307
483
|
export declare function createMemoryCloudStore(backing?: Map<string, string>): CloudStore;
|
|
1308
|
-
//#endregion
|
|
1309
|
-
//#region src/spark/errors.d.ts
|
|
1310
484
|
/** SparkController error categories — never carry request bytes or secrets. */
|
|
1311
485
|
type SparkErrorCategory = "network" | "approval-required" | "insufficient-funds" | "rejected" | "internal";
|
|
1312
486
|
export declare class SparkControllerError extends Error {
|
|
1313
487
|
readonly category: SparkErrorCategory;
|
|
1314
488
|
constructor(category: SparkErrorCategory, message: string, cause?: unknown);
|
|
1315
489
|
}
|
|
1316
|
-
//#endregion
|
|
1317
|
-
//#region src/accounts/errors.d.ts
|
|
1318
490
|
/** Account-tree error categories — messages never carry secrets. */
|
|
1319
491
|
type AccountTreeErrorCategory = "invalid-input" | "rejected" | "not-found" | "locked";
|
|
1320
492
|
export declare class AccountTreeError extends Error {
|
|
1321
493
|
readonly category: AccountTreeErrorCategory;
|
|
1322
494
|
constructor(category: AccountTreeErrorCategory, message: string, cause?: unknown);
|
|
1323
495
|
}
|
|
1324
|
-
//#endregion
|
|
1325
|
-
//#region src/payments/errors.d.ts
|
|
1326
496
|
/** Payment layer error categories — messages never carry remote or secret content. */
|
|
1327
497
|
type PaymentErrorCategory = "invalid-input" | "network" | "rejected";
|
|
1328
498
|
export declare class PaymentError extends Error {
|
|
1329
499
|
readonly category: PaymentErrorCategory;
|
|
1330
500
|
constructor(category: PaymentErrorCategory, message: string, cause?: unknown);
|
|
1331
501
|
}
|
|
1332
|
-
//#endregion
|
|
1333
|
-
//#region src/payments/resolve.d.ts
|
|
1334
502
|
type ResolveOptions = ParseOptions & {
|
|
1335
503
|
readonly fetch: typeof globalThis.fetch;
|
|
1336
504
|
};
|
|
@@ -1340,10 +508,7 @@ type ResolveOptions = ParseOptions & {
|
|
|
1340
508
|
* failures throw `PaymentError("network")` — remote error bodies never enter the message.
|
|
1341
509
|
*/
|
|
1342
510
|
export declare function resolvePayment(input: string, options: ResolveOptions): Promise<PaymentParse>;
|
|
1343
|
-
//#endregion
|
|
1344
|
-
//#region src/spark/exit-chain-codec.d.ts
|
|
1345
511
|
export declare function encodeExitChain(chain: SparkExitChain): Uint8Array;
|
|
1346
512
|
export declare function decodeExitChain(bytes: Uint8Array): SparkExitChain;
|
|
1347
|
-
|
|
1348
|
-
export type { AccountGroup, AccountTreeState, AddressBookEntry, AddressBookErrorCategory, AddressBookState, AddressFamily, BackupControllerState, BackupErrorCategory, CloudStore, ControllerOptions, EngineCollection, EngineErrorCode, EngineLogger, EngineOptions, EngineStore, EventBus, MetaDoc, MetaDocGroup, MetaDocTree, MetaDocWallet, MetaSyncConfig, MetaSyncRelayPort, MetaSyncState, MetaSyncWalletStatus, PayInput, PayParams, PaymentNote, PaymentOption, PaymentParse, PaymentRequest, PendingRequest, PrepareZapContext, PrepareZapParams, PreparedSparkAction, PreparedZap, RequestCheckCode, RequestControllerState, RequestInput, RequestMethod, RequestStage, RiskFinding, SignLogEntry, SignLogOutcome, SparkAccountState, SparkActivity, SparkClientFactory, SparkControllerOptions, SparkControllerState, SparkDisplay, SparkErrorCategory, SparkResult, WalletEngine, WithdrawLnurlParams, ZapRecipient };
|
|
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 };
|
|
1349
514
|
//# sourceMappingURL=index.d.mts.map
|