@lendasat/lendaswap-sdk 0.1.3 → 0.1.6

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.
@@ -0,0 +1,486 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Initialize the WASM module.
5
+ *
6
+ * This sets up logging and panic hooks for better debugging.
7
+ * Log level can be configured via localStorage key "lendaswap_log_level".
8
+ * Valid values: "trace", "debug", "info", "warn", "error" (case-insensitive).
9
+ * Default is "warn" if not set or invalid.
10
+ */
11
+ export function initialize(): void;
12
+ /**
13
+ * Set the log level at runtime.
14
+ * This updates localStorage and reinitializes the logger.
15
+ *
16
+ * Valid values: "trace", "debug", "info", "warn", "error" (case-insensitive).
17
+ */
18
+ export function setLogLevel(level: string): void;
19
+ /**
20
+ * Get the current log level.
21
+ */
22
+ export function getLogLevel(): string;
23
+ /**
24
+ * Chain type for token information.
25
+ */
26
+ export enum Chain {
27
+ Arkade = 0,
28
+ Lightning = 1,
29
+ Polygon = 2,
30
+ Ethereum = 3,
31
+ }
32
+ /**
33
+ * The `ReadableStreamType` enum.
34
+ *
35
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
36
+ */
37
+ type ReadableStreamType = "bytes";
38
+ /**
39
+ * Token information.
40
+ */
41
+ export class AssetPair {
42
+ private constructor();
43
+ free(): void;
44
+ [Symbol.dispose](): void;
45
+ source: TokenInfo;
46
+ target: TokenInfo;
47
+ }
48
+ /**
49
+ * Lendaswap client.
50
+ */
51
+ export class Client {
52
+ free(): void;
53
+ [Symbol.dispose](): void;
54
+ /**
55
+ * Create a new client with separate wallet and swap storage.
56
+ *
57
+ * # Arguments
58
+ * * `base_url` - The Lendaswap API URL
59
+ * * `wallet_storage` - Storage provider for wallet data (mnemonic, key index)
60
+ * * `swap_storage` - Storage provider for swap data
61
+ * * `network` - The Bitcoin network ("bitcoin" or "testnet")
62
+ * * `arkade_url` - The Arkade server URL
63
+ */
64
+ constructor(base_url: string, wallet_storage: JsWalletStorageProvider, swap_storage: JsSwapStorageProvider, network: string, arkade_url: string);
65
+ init(mnemonic?: string | null): Promise<void>;
66
+ /**
67
+ * Create an Arkade to EVM swap.
68
+ */
69
+ createArkadeToEvmSwap(target_address: string, target_amount: number, target_token: string, target_chain: string, referral_code?: string | null): Promise<any>;
70
+ /**
71
+ * Create an EVM to Arkade swap.
72
+ */
73
+ createEvmToArkadeSwap(target_address: string, user_address: string, source_amount: number, source_token: string, source_chain: string, referral_code?: string | null): Promise<any>;
74
+ /**
75
+ * Create an EVM to Lightning swap.
76
+ */
77
+ createEvmToLightningSwap(bolt11_invoice: string, user_address: string, source_token: string, source_chain: string, referral_code?: string | null): Promise<any>;
78
+ getAssetPairs(): Promise<AssetPair[]>;
79
+ getTokens(): Promise<TokenInfo[]>;
80
+ /**
81
+ * Get a quote.
82
+ */
83
+ getQuote(from: string, to: string, base_amount: bigint): Promise<QuoteResponse>;
84
+ /**
85
+ * Get swap by ID.
86
+ *
87
+ * This function returns `[ExtendedSwapResponse]`. It's too complex for Wasm to handle.
88
+ */
89
+ getSwap(id: string): Promise<any>;
90
+ /**
91
+ * Get all swaps.
92
+ *
93
+ * This function returns `[ExtendedSwapResponse[]]`. It's too complex for Wasm to handle.
94
+ */
95
+ listAll(): Promise<any>;
96
+ claimGelato(swap_id: string, secret?: string | null): Promise<void>;
97
+ amountsForSwap(swap_id: string): Promise<any>;
98
+ claimVhtlc(swap_id: string): Promise<void>;
99
+ refundVhtlc(swap_id: string, refund_address: string): Promise<string>;
100
+ /**
101
+ * Get API version.
102
+ */
103
+ getVersion(): Promise<Version>;
104
+ /**
105
+ * Recover swaps using xpub.
106
+ */
107
+ recoverSwaps(): Promise<any>;
108
+ /**
109
+ * Get mnemonic
110
+ */
111
+ getMnemonic(): Promise<string>;
112
+ /**
113
+ * Get userIdXpub
114
+ */
115
+ getUserIdXpub(): Promise<string>;
116
+ /**
117
+ * Deletes all stored swaps
118
+ */
119
+ clearSwapStorage(): Promise<void>;
120
+ /**
121
+ * Delete specific swap
122
+ */
123
+ deleteSwap(id: string): Promise<void>;
124
+ /**
125
+ * Estimate the fee for a VTXO swap.
126
+ *
127
+ * # Arguments
128
+ * * `vtxos` - List of VTXO outpoints to refresh ("txid:vout" format)
129
+ */
130
+ estimateVtxoSwap(vtxos: string[]): Promise<EstimateVtxoSwapResponse>;
131
+ /**
132
+ * Create a VTXO swap for refreshing VTXOs.
133
+ *
134
+ * Returns the swap response and swap params.
135
+ *
136
+ * # Arguments
137
+ * * `vtxos` - List of VTXO outpoints to refresh ("txid:vout" format)
138
+ */
139
+ createVtxoSwap(vtxos: string[]): Promise<CreateVtxoSwapResult>;
140
+ /**
141
+ * Get VTXO swap details by ID.
142
+ */
143
+ getVtxoSwap(id: string): Promise<VtxoSwapResponse>;
144
+ /**
145
+ * Claim the server's VHTLC in a VTXO swap.
146
+ *
147
+ * # Arguments
148
+ * * `swap` - The VTXO swap response
149
+ * * `swap_params` - The client's swap parameters
150
+ * * `claim_address` - The Arkade address to receive the claimed funds
151
+ */
152
+ claimVtxoSwap(swap: VtxoSwapResponse, swap_params: SwapParams, claim_address: string): Promise<string>;
153
+ /**
154
+ * Refund the client's VHTLC in a VTXO swap.
155
+ *
156
+ * # Arguments
157
+ * * `swap` - The VTXO swap response
158
+ * * `swap_params` - The client's swap parameters
159
+ * * `refund_address` - The Arkade address to receive the refunded funds
160
+ */
161
+ refundVtxoSwap(swap: VtxoSwapResponse, swap_params: SwapParams, refund_address: string): Promise<string>;
162
+ }
163
+ /**
164
+ * Result from creating a VTXO swap.
165
+ */
166
+ export class CreateVtxoSwapResult {
167
+ private constructor();
168
+ free(): void;
169
+ [Symbol.dispose](): void;
170
+ /**
171
+ * The swap response
172
+ */
173
+ response: VtxoSwapResponse;
174
+ /**
175
+ * The swap parameters (needed for claim/refund)
176
+ */
177
+ swapParams: SwapParams;
178
+ }
179
+ /**
180
+ * Estimate response for a VTXO swap.
181
+ */
182
+ export class EstimateVtxoSwapResponse {
183
+ private constructor();
184
+ free(): void;
185
+ [Symbol.dispose](): void;
186
+ /**
187
+ * Total fee in satoshis
188
+ */
189
+ feeSats: bigint;
190
+ /**
191
+ * Total input amount in satoshis
192
+ */
193
+ totalInputSats: bigint;
194
+ /**
195
+ * Amount user will receive (total_input_sats - fee_sats)
196
+ */
197
+ outputSats: bigint;
198
+ /**
199
+ * Number of VTXOs being refreshed
200
+ */
201
+ vtxoCount: number;
202
+ }
203
+ export class IntoUnderlyingByteSource {
204
+ private constructor();
205
+ free(): void;
206
+ [Symbol.dispose](): void;
207
+ start(controller: ReadableByteStreamController): void;
208
+ pull(controller: ReadableByteStreamController): Promise<any>;
209
+ cancel(): void;
210
+ readonly type: ReadableStreamType;
211
+ readonly autoAllocateChunkSize: number;
212
+ }
213
+ export class IntoUnderlyingSink {
214
+ private constructor();
215
+ free(): void;
216
+ [Symbol.dispose](): void;
217
+ write(chunk: any): Promise<any>;
218
+ close(): Promise<any>;
219
+ abort(reason: any): Promise<any>;
220
+ }
221
+ export class IntoUnderlyingSource {
222
+ private constructor();
223
+ free(): void;
224
+ [Symbol.dispose](): void;
225
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
226
+ cancel(): void;
227
+ }
228
+ /**
229
+ * JavaScript swap storage provider passed from TypeScript.
230
+ *
231
+ * This struct wraps JavaScript callback functions that implement
232
+ * typed swap storage operations. Each function should return a Promise.
233
+ *
234
+ * # Example (TypeScript with Dexie)
235
+ *
236
+ * ```typescript
237
+ * import Dexie from 'dexie';
238
+ *
239
+ * const db = new Dexie('lendaswap');
240
+ * db.version(1).stores({ swaps: 'id' });
241
+ *
242
+ * const swapStorage = new JsSwapStorageProvider(
243
+ * async (swapId) => await db.swaps.get(swapId) ?? null,
244
+ * async (swapId, data) => { await db.swaps.put({ id: swapId, ...data }); },
245
+ * async (swapId) => { await db.swaps.delete(swapId); },
246
+ * async () => await db.swaps.toCollection().primaryKeys()
247
+ * );
248
+ * ```
249
+ */
250
+ export class JsSwapStorageProvider {
251
+ free(): void;
252
+ [Symbol.dispose](): void;
253
+ /**
254
+ * Create a new JsSwapStorageProvider from JavaScript callbacks.
255
+ *
256
+ * # Arguments
257
+ * * `get_fn` - Function: `(swapId: string) => Promise<ExtendedSwapStorageData | null>`
258
+ * * `store_fn` - Function: `(swapId: string, data: ExtendedSwapStorageData) => Promise<void>`
259
+ * * `delete_fn` - Function: `(swapId: string) => Promise<void>`
260
+ * * `list_fn` - Function: `() => Promise<string[]>`
261
+ * * `get_all_fn` - Function: `() => Promise<ExtendedSwapStorageData[]>`
262
+ */
263
+ constructor(get_fn: Function, store_fn: Function, delete_fn: Function, list_fn: Function, get_all_fn: Function);
264
+ }
265
+ /**
266
+ * JavaScript wallet storage provider passed from TypeScript.
267
+ *
268
+ * This struct wraps JavaScript callback functions that implement
269
+ * the typed wallet storage operations. Each function should return a Promise.
270
+ *
271
+ * # Example (TypeScript)
272
+ *
273
+ * ```typescript
274
+ * const provider = new JsWalletStorageProvider(
275
+ * async () => localStorage.getItem('mnemonic'), // get_mnemonic
276
+ * async (mnemonic) => localStorage.setItem('mnemonic', mnemonic), // set_mnemonic
277
+ * async () => parseInt(localStorage.getItem('key_index') ?? '0'), // get_key_index
278
+ * async (index) => localStorage.setItem('key_index', index.toString()), // set_key_index
279
+ * );
280
+ * ```
281
+ */
282
+ export class JsWalletStorageProvider {
283
+ free(): void;
284
+ [Symbol.dispose](): void;
285
+ /**
286
+ * Create a new JsWalletStorageProvider from JavaScript callbacks.
287
+ *
288
+ * # Arguments
289
+ * * `get_mnemonic_fn` - Function: `() => Promise<string | null>`
290
+ * * `set_mnemonic_fn` - Function: `(mnemonic: string) => Promise<void>`
291
+ * * `get_key_index_fn` - Function: `() => Promise<number>`
292
+ * * `set_key_index_fn` - Function: `(index: number) => Promise<void>`
293
+ */
294
+ constructor(get_mnemonic_fn: Function, set_mnemonic_fn: Function, get_key_index_fn: Function, set_key_index_fn: Function);
295
+ }
296
+ /**
297
+ * Quote response from the API.
298
+ */
299
+ export class QuoteResponse {
300
+ private constructor();
301
+ free(): void;
302
+ [Symbol.dispose](): void;
303
+ exchangeRate: string;
304
+ networkFee: bigint;
305
+ protocolFee: bigint;
306
+ protocolFeeRate: number;
307
+ minAmount: bigint;
308
+ maxAmount: bigint;
309
+ }
310
+ /**
311
+ * Parameters derived for a swap operation.
312
+ */
313
+ export class SwapParams {
314
+ private constructor();
315
+ free(): void;
316
+ [Symbol.dispose](): void;
317
+ /**
318
+ * Secret key (hex-encoded).
319
+ */
320
+ own_sk: string;
321
+ /**
322
+ * Public key (hex-encoded).
323
+ */
324
+ own_pk: string;
325
+ /**
326
+ * Preimage for HTLC (hex-encoded).
327
+ */
328
+ preimage: string;
329
+ /**
330
+ * Hash of the preimage (hex-encoded).
331
+ */
332
+ preimage_hash: string;
333
+ /**
334
+ * User ID derived from HD wallet (hex-encoded).
335
+ */
336
+ user_id: string;
337
+ /**
338
+ * Key derivation index used.
339
+ */
340
+ key_index: number;
341
+ }
342
+ /**
343
+ * Token identifier.
344
+ */
345
+ export class TokenId {
346
+ private constructor();
347
+ free(): void;
348
+ [Symbol.dispose](): void;
349
+ toString(): string;
350
+ static fromString(s: string): TokenId;
351
+ }
352
+ /**
353
+ * Token information.
354
+ */
355
+ export class TokenInfo {
356
+ private constructor();
357
+ free(): void;
358
+ [Symbol.dispose](): void;
359
+ tokenId: string;
360
+ symbol: string;
361
+ chain: Chain;
362
+ name: string;
363
+ decimals: number;
364
+ }
365
+ /**
366
+ * Version information.
367
+ */
368
+ export class Version {
369
+ private constructor();
370
+ free(): void;
371
+ [Symbol.dispose](): void;
372
+ tag: string;
373
+ commitHash: string;
374
+ }
375
+ /**
376
+ * VHTLC amounts returned from Arkade.
377
+ */
378
+ export class VhtlcAmounts {
379
+ private constructor();
380
+ free(): void;
381
+ [Symbol.dispose](): void;
382
+ /**
383
+ * Amount that can be spent (in satoshis).
384
+ */
385
+ spendable: bigint;
386
+ /**
387
+ * Amount already spent (in satoshis).
388
+ */
389
+ spent: bigint;
390
+ /**
391
+ * Amount that can be recovered via refund (in satoshis).
392
+ */
393
+ recoverable: bigint;
394
+ }
395
+ /**
396
+ * Response from creating/getting a VTXO swap.
397
+ */
398
+ export class VtxoSwapResponse {
399
+ private constructor();
400
+ free(): void;
401
+ [Symbol.dispose](): void;
402
+ /**
403
+ * Swap ID
404
+ */
405
+ id: string;
406
+ /**
407
+ * Swap status
408
+ */
409
+ status: string;
410
+ /**
411
+ * Creation timestamp (RFC3339)
412
+ */
413
+ createdAt: string;
414
+ /**
415
+ * Client's VHTLC address
416
+ */
417
+ clientVhtlcAddress: string;
418
+ /**
419
+ * Amount client should fund in satoshis
420
+ */
421
+ clientFundAmountSats: bigint;
422
+ /**
423
+ * Client's public key
424
+ */
425
+ clientPk: string;
426
+ /**
427
+ * Client VHTLC locktime (Unix timestamp)
428
+ */
429
+ clientLocktime: bigint;
430
+ /**
431
+ * Client claim delay in seconds
432
+ */
433
+ clientUnilateralClaimDelay: bigint;
434
+ /**
435
+ * Client refund delay in seconds
436
+ */
437
+ clientUnilateralRefundDelay: bigint;
438
+ /**
439
+ * Client refund without receiver delay in seconds
440
+ */
441
+ clientUnilateralRefundWithoutReceiverDelay: bigint;
442
+ /**
443
+ * Server's VHTLC address
444
+ */
445
+ serverVhtlcAddress: string;
446
+ /**
447
+ * Amount server will fund in satoshis
448
+ */
449
+ serverFundAmountSats: bigint;
450
+ /**
451
+ * Server's public key
452
+ */
453
+ serverPk: string;
454
+ /**
455
+ * Server VHTLC locktime (Unix timestamp)
456
+ */
457
+ serverLocktime: bigint;
458
+ /**
459
+ * Server claim delay in seconds
460
+ */
461
+ serverUnilateralClaimDelay: bigint;
462
+ /**
463
+ * Server refund delay in seconds
464
+ */
465
+ serverUnilateralRefundDelay: bigint;
466
+ /**
467
+ * Server refund without receiver delay in seconds
468
+ */
469
+ serverUnilateralRefundWithoutReceiverDelay: bigint;
470
+ /**
471
+ * Arkade server's public key
472
+ */
473
+ arkadeServerPk: string;
474
+ /**
475
+ * The preimage hash (SHA256)
476
+ */
477
+ preimageHash: string;
478
+ /**
479
+ * Fee in satoshis
480
+ */
481
+ feeSats: bigint;
482
+ /**
483
+ * Bitcoin network
484
+ */
485
+ network: string;
486
+ }
@@ -0,0 +1,5 @@
1
+ import * as wasm from "./lendaswap_wasm_sdk_bg.wasm";
2
+ export * from "./lendaswap_wasm_sdk_bg.js";
3
+ import { __wbg_set_wasm } from "./lendaswap_wasm_sdk_bg.js";
4
+ __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();