@lendasat/lendaswap-sdk 0.1.65 → 0.1.68
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 +200 -126
- package/dist/api.d.ts +139 -103
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +236 -137
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -27
- package/dist/index.js.map +1 -1
- package/package.json +14 -15
- package/wasm/lendaswap_wasm_sdk.d.ts +133 -123
- package/wasm/lendaswap_wasm_sdk_bg.js +548 -248
- package/wasm/lendaswap_wasm_sdk_bg.wasm +0 -0
- package/wasm/lendaswap_wasm_sdk_bg.wasm.d.ts +45 -35
- package/dist/price-calculations.test.d.ts +0 -2
- package/dist/price-calculations.test.d.ts.map +0 -1
- package/dist/price-calculations.test.js +0 -173
- package/dist/price-calculations.test.js.map +0 -1
- package/dist/storage/dexieSwapStorage.d.ts +0 -113
- package/dist/storage/dexieSwapStorage.d.ts.map +0 -1
- package/dist/storage/dexieSwapStorage.js +0 -200
- package/dist/storage/dexieSwapStorage.js.map +0 -1
- package/dist/storage/dexieVtxoSwapStorage.d.ts +0 -105
- package/dist/storage/dexieVtxoSwapStorage.d.ts.map +0 -1
- package/dist/storage/dexieVtxoSwapStorage.js +0 -149
- package/dist/storage/dexieVtxoSwapStorage.js.map +0 -1
- package/dist/storage/dexieWalletStorage.d.ts +0 -99
- package/dist/storage/dexieWalletStorage.d.ts.map +0 -1
- package/dist/storage/dexieWalletStorage.js +0 -139
- package/dist/storage/dexieWalletStorage.js.map +0 -1
- package/dist/storage/index.d.ts +0 -19
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -22
- package/dist/storage/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,26 +6,27 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
9
|
+
* import { Client, ClientBuilder, openIdbDatabase } from '@lendasat/lendaswap-sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Open the IndexedDB database
|
|
12
|
+
* const storage = await openIdbDatabase();
|
|
13
|
+
*
|
|
14
|
+
* // Create client using builder (recommended)
|
|
15
|
+
* const client = Client.builder()
|
|
16
|
+
* .url('https://apilendaswap.lendasat.com')
|
|
17
|
+
* .storage(storage)
|
|
18
|
+
* .network('bitcoin')
|
|
19
|
+
* .arkadeUrl('https://arkade.computer')
|
|
20
|
+
* .esploraUrl('https://mempool.space/api')
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // Or use the static create method
|
|
24
|
+
* const client2 = await Client.create(
|
|
23
25
|
* 'https://apilendaswap.lendasat.com',
|
|
24
|
-
*
|
|
25
|
-
* swapStorage,
|
|
26
|
-
* vtxoSwapStorage,
|
|
26
|
+
* storage,
|
|
27
27
|
* 'bitcoin',
|
|
28
|
-
* 'https://arkade.computer'
|
|
28
|
+
* 'https://arkade.computer',
|
|
29
|
+
* 'https://mempool.space/api'
|
|
29
30
|
* );
|
|
30
31
|
*
|
|
31
32
|
* // Initialize wallet (generates mnemonic if needed)
|
|
@@ -38,10 +39,9 @@
|
|
|
38
39
|
* @packageDocumentation
|
|
39
40
|
*/
|
|
40
41
|
export type { NetworkInput } from "./api.js";
|
|
41
|
-
export { type AssetPair, type BtcToArkadeSwapRequest, type BtcToArkadeSwapResponse, type BtcToEvmSwapResponse, type Chain, Client, CreateVtxoSwapResult, EstimateVtxoSwapResponse, type EvmToArkadeSwapRequest, type EvmToBtcSwapResponse, type EvmToLightningSwapRequest, type ExtendedSwapStorageData, type ExtendedSwapStorageDataWasm,
|
|
42
|
+
export { type AssetPair, type BtcToArkadeSwapRequest, type BtcToArkadeSwapResponse, type BtcToEvmSwapResponse, type Chain, Client, ClientBuilder, CreateVtxoSwapResult, EstimateVtxoSwapResponse, type EvmToArkadeSwapRequest, type EvmToBtcSwapResponse, type EvmToLightningSwapRequest, type ExtendedSwapStorageData, type ExtendedSwapStorageDataWasm, ExtendedVtxoSwapStorageData, type GelatoSubmitRequest, type GelatoSubmitResponse, type GetSwapResponse, getLogLevel, type IdbStorageHandle, type LogLevel, type Network, openIdbDatabase, type QuoteRequest, QuoteResponse, type RecoveredSwap, type RecoverSwapsResponse, type SwapRequest, SwapStatus, swapStatusToString, type SwapType, setLogLevel, TokenId, type TokenIdString, type TokenInfo, Version, VhtlcAmounts, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
42
43
|
export { PriceFeedService, type PriceTiers, type PriceUpdateCallback, type PriceUpdateMessage, type TradingPairPrices, } from "./price-feed.js";
|
|
43
44
|
export { calculateSourceAmount, calculateTargetAmount, computeExchangeRate, selectTierRate, } from "./price-calculations.js";
|
|
44
|
-
export { createDexieSwapStorage, createDexieVtxoSwapStorage, createDexieWalletStorage, DexieSwapStorageProvider, DexieVtxoSwapStorageProvider, DexieWalletStorageProvider, STORAGE_KEYS, } from "./storage/index.js";
|
|
45
45
|
export type { SwapData, SwapParams } from "./types.js";
|
|
46
46
|
export { type GetUsdPriceOptions, getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, type UsdPriceResult, } from "./usd-price.js";
|
|
47
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EACL,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,KAAK,EACV,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,eAAe,EACf,KAAK,YAAY,EACjB,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,UAAU,EACV,kBAAkB,EAClB,KAAK,QAAQ,EACb,WAAW,EACX,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,OAAO,EACP,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,KAAK,kBAAkB,EACvB,cAAc,EACd,6BAA6B,EAC7B,WAAW,EACX,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,26 +6,27 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
9
|
+
* import { Client, ClientBuilder, openIdbDatabase } from '@lendasat/lendaswap-sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Open the IndexedDB database
|
|
12
|
+
* const storage = await openIdbDatabase();
|
|
13
|
+
*
|
|
14
|
+
* // Create client using builder (recommended)
|
|
15
|
+
* const client = Client.builder()
|
|
16
|
+
* .url('https://apilendaswap.lendasat.com')
|
|
17
|
+
* .storage(storage)
|
|
18
|
+
* .network('bitcoin')
|
|
19
|
+
* .arkadeUrl('https://arkade.computer')
|
|
20
|
+
* .esploraUrl('https://mempool.space/api')
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // Or use the static create method
|
|
24
|
+
* const client2 = await Client.create(
|
|
23
25
|
* 'https://apilendaswap.lendasat.com',
|
|
24
|
-
*
|
|
25
|
-
* swapStorage,
|
|
26
|
-
* vtxoSwapStorage,
|
|
26
|
+
* storage,
|
|
27
27
|
* 'bitcoin',
|
|
28
|
-
* 'https://arkade.computer'
|
|
28
|
+
* 'https://arkade.computer',
|
|
29
|
+
* 'https://mempool.space/api'
|
|
29
30
|
* );
|
|
30
31
|
*
|
|
31
32
|
* // Initialize wallet (generates mnemonic if needed)
|
|
@@ -37,17 +38,9 @@
|
|
|
37
38
|
*
|
|
38
39
|
* @packageDocumentation
|
|
39
40
|
*/
|
|
40
|
-
// Re-export WASM types that are commonly used
|
|
41
|
-
// Storage provider types for Client.create()
|
|
42
|
-
// API client
|
|
43
41
|
// Re-export WASM types and API types
|
|
44
|
-
export { Client, CreateVtxoSwapResult, EstimateVtxoSwapResponse, ExtendedVtxoSwapStorageData, getLogLevel, QuoteResponse, SwapStatus, swapStatusToString, setLogLevel, TokenId, Version, VhtlcAmounts, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
42
|
+
export { Client, ClientBuilder, CreateVtxoSwapResult, EstimateVtxoSwapResponse, ExtendedVtxoSwapStorageData, getLogLevel, openIdbDatabase, QuoteResponse, SwapStatus, swapStatusToString, setLogLevel, TokenId, Version, VhtlcAmounts, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
45
43
|
export { PriceFeedService, } from "./price-feed.js";
|
|
46
44
|
export { calculateSourceAmount, calculateTargetAmount, computeExchangeRate, selectTierRate, } from "./price-calculations.js";
|
|
47
|
-
// Storage (wallet data)
|
|
48
|
-
// Swap storage (typed swap data using Dexie/IndexedDB)
|
|
49
|
-
// VTXO swap storage (typed VTXO swap data using Dexie/IndexedDB)
|
|
50
|
-
// Wallet storage (typed wallet data using Dexie/IndexedDB)
|
|
51
|
-
export { createDexieSwapStorage, createDexieVtxoSwapStorage, createDexieWalletStorage, DexieSwapStorageProvider, DexieVtxoSwapStorageProvider, DexieWalletStorageProvider, STORAGE_KEYS, } from "./storage/index.js";
|
|
52
45
|
export { getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, } from "./usd-price.js";
|
|
53
46
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,qCAAqC;AACrC,OAAO,EAML,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EAMxB,2BAA2B,EAI3B,WAAW,EAIX,eAAe,EAEf,aAAa,EAIb,UAAU,EACV,kBAAkB,EAElB,WAAW,EACX,OAAO,EAGP,OAAO,EACP,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,GAKjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,cAAc,EACd,6BAA6B,EAC7B,WAAW,EACX,YAAY,GAEb,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lendasat/lendaswap-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"description": "Lendaswap Client SDK for TypeScript/JavaScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,9 +16,19 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"wasm"
|
|
18
18
|
],
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build:wasm": "cd ../wasm-sdk && wasm-pack build --target bundler --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
21
|
+
"build:wasm:release": "cd ../wasm-sdk && wasm-pack build --target bundler --release --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
22
|
+
"build:ts": "tsc",
|
|
23
|
+
"build": "pnpm run build:wasm && pnpm run build:ts",
|
|
24
|
+
"build:release": "pnpm run build:wasm:release && pnpm run build:ts",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"clean": "rm -rf dist wasm",
|
|
27
|
+
"prepublishOnly": "pnpm run build:release",
|
|
28
|
+
"publish:npm": "pnpm run build:release && pnpm publish --access public",
|
|
29
|
+
"publish:npm:dry-run": "pnpm run build:release && pnpm publish --access public --dry-run"
|
|
21
30
|
},
|
|
31
|
+
"dependencies": {},
|
|
22
32
|
"devDependencies": {
|
|
23
33
|
"@biomejs/biome": "2.3.7",
|
|
24
34
|
"@types/node": "^20.0.0",
|
|
@@ -42,16 +52,5 @@
|
|
|
42
52
|
},
|
|
43
53
|
"publishConfig": {
|
|
44
54
|
"access": "public"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build:wasm": "cd ../wasm-sdk && wasm-pack build --target bundler --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
48
|
-
"build:wasm:release": "cd ../wasm-sdk && wasm-pack build --target bundler --release --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
49
|
-
"build:ts": "tsc",
|
|
50
|
-
"build": "pnpm run build:wasm && pnpm run build:ts",
|
|
51
|
-
"build:release": "pnpm run build:wasm:release && pnpm run build:ts",
|
|
52
|
-
"test": "vitest",
|
|
53
|
-
"clean": "rm -rf dist wasm",
|
|
54
|
-
"publish:npm": "pnpm run build:release && pnpm publish --access public",
|
|
55
|
-
"publish:npm:dry-run": "pnpm run build:release && pnpm publish --access public --dry-run"
|
|
56
55
|
}
|
|
57
|
-
}
|
|
56
|
+
}
|
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
* Returns a human-readable string representation of the swap status.
|
|
5
5
|
*/
|
|
6
6
|
export function swapStatusToString(status: SwapStatus): string;
|
|
7
|
+
/**
|
|
8
|
+
* Open the IndexedDB database with migrations.
|
|
9
|
+
*
|
|
10
|
+
* This function opens (or creates) the lendaswap IndexedDB database
|
|
11
|
+
* and runs any necessary migrations. It also migrates wallet data from
|
|
12
|
+
* the old Dexie-based `lendaswap-wallet` database if present.
|
|
13
|
+
*
|
|
14
|
+
* # Arguments
|
|
15
|
+
* * `db_name` - Optional database name (default: "lendaswap-v2")
|
|
16
|
+
*
|
|
17
|
+
* # Returns
|
|
18
|
+
* An `IdbStorageHandle` that can be used to create storage implementations.
|
|
19
|
+
*/
|
|
20
|
+
export function openIdbDatabase(db_name?: string | null): Promise<IdbStorageHandle>;
|
|
7
21
|
/**
|
|
8
22
|
* Initialize the WASM module.
|
|
9
23
|
*
|
|
@@ -162,29 +176,68 @@ export class BtcToEvmSwapResponse {
|
|
|
162
176
|
set evm_htlc_fund_txid(value: string | null | undefined);
|
|
163
177
|
}
|
|
164
178
|
/**
|
|
165
|
-
* Lendaswap client.
|
|
179
|
+
* Lendaswap client using IndexedDB storage.
|
|
180
|
+
*
|
|
181
|
+
* This client uses native Rust IndexedDB storage via the `idb` crate.
|
|
182
|
+
*
|
|
183
|
+
* # Example
|
|
184
|
+
*
|
|
185
|
+
* ```javascript
|
|
186
|
+
* import init, { openIdbDatabase, Client, ClientBuilder } from '@lendasat/lendaswap-sdk';
|
|
187
|
+
*
|
|
188
|
+
* await init();
|
|
189
|
+
*
|
|
190
|
+
* // Open the IndexedDB database
|
|
191
|
+
* const storage = await openIdbDatabase();
|
|
192
|
+
*
|
|
193
|
+
* // Create the client using the builder (recommended)
|
|
194
|
+
* const client = new ClientBuilder()
|
|
195
|
+
* .url('https://api.lendaswap.com')
|
|
196
|
+
* .storage(storage)
|
|
197
|
+
* .network('bitcoin')
|
|
198
|
+
* .arkadeUrl('https://arkade.computer')
|
|
199
|
+
* .esploraUrl('https://mempool.space/api')
|
|
200
|
+
* .build();
|
|
201
|
+
*
|
|
202
|
+
* // Or use the constructor directly
|
|
203
|
+
* const client2 = new Client(
|
|
204
|
+
* 'https://api.lendaswap.com',
|
|
205
|
+
* storage,
|
|
206
|
+
* 'bitcoin',
|
|
207
|
+
* 'https://arkade.computer',
|
|
208
|
+
* 'https://mempool.space/api'
|
|
209
|
+
* );
|
|
210
|
+
*
|
|
211
|
+
* await client.init();
|
|
212
|
+
* ```
|
|
166
213
|
*/
|
|
167
214
|
export class Client {
|
|
168
215
|
free(): void;
|
|
169
216
|
[Symbol.dispose](): void;
|
|
170
217
|
/**
|
|
171
|
-
* Create a new
|
|
218
|
+
* Create a new [`ClientBuilder`] for constructing a client.
|
|
219
|
+
*/
|
|
220
|
+
static builder(): ClientBuilder;
|
|
221
|
+
/**
|
|
222
|
+
* Create a new client with IndexedDB storage.
|
|
172
223
|
*
|
|
173
224
|
* # Arguments
|
|
174
225
|
* * `base_url` - The Lendaswap API URL
|
|
175
|
-
* * `
|
|
176
|
-
* * `swap_storage` - Storage provider for swap data
|
|
177
|
-
* * `vtxo_swap_storage` - Storage provider for VTXO swap data
|
|
226
|
+
* * `storage` - Storage handle from `openIdbDatabase()`
|
|
178
227
|
* * `network` - The Bitcoin network ("bitcoin" or "testnet")
|
|
179
228
|
* * `arkade_url` - The Arkade server URL
|
|
180
229
|
* * `esplora_url` - The Esplora API URL for on-chain Bitcoin operations
|
|
181
230
|
*/
|
|
182
|
-
constructor(base_url: string,
|
|
231
|
+
constructor(base_url: string, storage: IdbStorageHandle, network: string, arkade_url: string, esplora_url: string);
|
|
183
232
|
init(mnemonic?: string | null): Promise<void>;
|
|
184
233
|
/**
|
|
185
234
|
* Create an Arkade to EVM swap.
|
|
186
235
|
*/
|
|
187
|
-
createArkadeToEvmSwap(target_address: string, target_amount: number, target_token: string, target_chain: string, referral_code?: string | null): Promise<BtcToEvmSwapResponse>;
|
|
236
|
+
createArkadeToEvmSwap(target_address: string, source_amount: bigint | null | undefined, target_amount: number | null | undefined, target_token: string, target_chain: string, referral_code?: string | null): Promise<BtcToEvmSwapResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* Create a Lightning to EVM swap.
|
|
239
|
+
*/
|
|
240
|
+
createLightningToEvmSwap(target_address: string, source_amount: bigint | null | undefined, target_amount: number | null | undefined, target_token: string, target_chain: string, referral_code?: string | null): Promise<BtcToEvmSwapResponse>;
|
|
188
241
|
/**
|
|
189
242
|
* Create an EVM to Arkade swap.
|
|
190
243
|
*/
|
|
@@ -247,16 +300,6 @@ export class Client {
|
|
|
247
300
|
* Delete specific swap
|
|
248
301
|
*/
|
|
249
302
|
deleteSwap(id: string): Promise<void>;
|
|
250
|
-
/**
|
|
251
|
-
* Get the list of swap IDs that failed to deserialize during the last listAll() call.
|
|
252
|
-
* These are "corrupted" entries that couldn't be loaded.
|
|
253
|
-
*/
|
|
254
|
-
getCorruptedSwapIds(): string[];
|
|
255
|
-
/**
|
|
256
|
-
* Delete all corrupted swap entries from storage.
|
|
257
|
-
* Returns the number of entries deleted.
|
|
258
|
-
*/
|
|
259
|
-
deleteCorruptedSwaps(): Promise<number>;
|
|
260
303
|
/**
|
|
261
304
|
* Estimate the fee for a VTXO swap.
|
|
262
305
|
*
|
|
@@ -301,6 +344,63 @@ export class Client {
|
|
|
301
344
|
*/
|
|
302
345
|
listAllVtxoSwaps(): Promise<ExtendedVtxoSwapStorageData[]>;
|
|
303
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Builder for constructing a [`Client`] with a fluent API.
|
|
349
|
+
*
|
|
350
|
+
* # Example
|
|
351
|
+
*
|
|
352
|
+
* ```javascript
|
|
353
|
+
* import init, { openIdbDatabase, ClientBuilder } from '@lendasat/lendaswap-sdk';
|
|
354
|
+
*
|
|
355
|
+
* await init();
|
|
356
|
+
*
|
|
357
|
+
* const storage = await openIdbDatabase();
|
|
358
|
+
*
|
|
359
|
+
* const client = await ClientBuilder.new()
|
|
360
|
+
* .url('https://api.lendaswap.com')
|
|
361
|
+
* .storage(storage)
|
|
362
|
+
* .network('bitcoin')
|
|
363
|
+
* .arkadeUrl('https://arkade.computer')
|
|
364
|
+
* .esploraUrl('https://mempool.space/api')
|
|
365
|
+
* .build();
|
|
366
|
+
*
|
|
367
|
+
* await client.init();
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export class ClientBuilder {
|
|
371
|
+
free(): void;
|
|
372
|
+
[Symbol.dispose](): void;
|
|
373
|
+
/**
|
|
374
|
+
* Create a new client builder with all fields unset.
|
|
375
|
+
*/
|
|
376
|
+
constructor();
|
|
377
|
+
/**
|
|
378
|
+
* Set the Lendaswap API URL.
|
|
379
|
+
*/
|
|
380
|
+
url(url: string): ClientBuilder;
|
|
381
|
+
/**
|
|
382
|
+
* Set the storage handle from `openIdbDatabase()`.
|
|
383
|
+
*/
|
|
384
|
+
storage(storage: IdbStorageHandle): ClientBuilder;
|
|
385
|
+
/**
|
|
386
|
+
* Set the Bitcoin network ("bitcoin", "testnet", "regtest", or "mutinynet").
|
|
387
|
+
*/
|
|
388
|
+
network(network: string): ClientBuilder;
|
|
389
|
+
/**
|
|
390
|
+
* Set the Arkade server URL.
|
|
391
|
+
*/
|
|
392
|
+
arkadeUrl(url: string): ClientBuilder;
|
|
393
|
+
/**
|
|
394
|
+
* Set the Esplora API URL for on-chain Bitcoin operations.
|
|
395
|
+
*/
|
|
396
|
+
esploraUrl(url: string): ClientBuilder;
|
|
397
|
+
/**
|
|
398
|
+
* Build the client, consuming the builder.
|
|
399
|
+
*
|
|
400
|
+
* Returns an error if any required field is missing.
|
|
401
|
+
*/
|
|
402
|
+
build(): Client;
|
|
403
|
+
}
|
|
304
404
|
/**
|
|
305
405
|
* Result from creating a VTXO swap.
|
|
306
406
|
*/
|
|
@@ -448,6 +548,22 @@ export class ExtendedVtxoSwapStorageData {
|
|
|
448
548
|
*/
|
|
449
549
|
swap_params: SwapParams;
|
|
450
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Shared database handle for all storage implementations.
|
|
553
|
+
*/
|
|
554
|
+
export class IdbStorageHandle {
|
|
555
|
+
private constructor();
|
|
556
|
+
free(): void;
|
|
557
|
+
[Symbol.dispose](): void;
|
|
558
|
+
/**
|
|
559
|
+
* Close the database connection.
|
|
560
|
+
*/
|
|
561
|
+
close(): void;
|
|
562
|
+
/**
|
|
563
|
+
* Get the database name.
|
|
564
|
+
*/
|
|
565
|
+
readonly name: string;
|
|
566
|
+
}
|
|
451
567
|
export class IntoUnderlyingByteSource {
|
|
452
568
|
private constructor();
|
|
453
569
|
free(): void;
|
|
@@ -473,112 +589,6 @@ export class IntoUnderlyingSource {
|
|
|
473
589
|
pull(controller: ReadableStreamDefaultController): Promise<any>;
|
|
474
590
|
cancel(): void;
|
|
475
591
|
}
|
|
476
|
-
/**
|
|
477
|
-
* JavaScript swap storage provider passed from TypeScript.
|
|
478
|
-
*
|
|
479
|
-
* This struct wraps JavaScript callback functions that implement
|
|
480
|
-
* typed swap storage operations. Each function should return a Promise.
|
|
481
|
-
*
|
|
482
|
-
* # Example (TypeScript with Dexie)
|
|
483
|
-
*
|
|
484
|
-
* ```typescript
|
|
485
|
-
* import Dexie from 'dexie';
|
|
486
|
-
*
|
|
487
|
-
* const db = new Dexie('lendaswap');
|
|
488
|
-
* db.version(1).stores({ swaps: 'id' });
|
|
489
|
-
*
|
|
490
|
-
* const swapStorage = new JsSwapStorageProvider(
|
|
491
|
-
* async (swapId) => await db.swaps.get(swapId) ?? null,
|
|
492
|
-
* async (swapId, data) => { await db.swaps.put({ id: swapId, ...data }); },
|
|
493
|
-
* async (swapId) => { await db.swaps.delete(swapId); },
|
|
494
|
-
* async () => await db.swaps.toCollection().primaryKeys()
|
|
495
|
-
* );
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
export class JsSwapStorageProvider {
|
|
499
|
-
free(): void;
|
|
500
|
-
[Symbol.dispose](): void;
|
|
501
|
-
/**
|
|
502
|
-
* Create a new JsSwapStorageProvider from JavaScript callbacks.
|
|
503
|
-
*
|
|
504
|
-
* # Arguments
|
|
505
|
-
* * `get_fn` - Function: `(swapId: string) => Promise<ExtendedSwapStorageData | null>`
|
|
506
|
-
* * `store_fn` - Function: `(swapId: string, data: ExtendedSwapStorageData) => Promise<void>`
|
|
507
|
-
* * `delete_fn` - Function: `(swapId: string) => Promise<void>`
|
|
508
|
-
* * `list_fn` - Function: `() => Promise<string[]>`
|
|
509
|
-
* * `get_all_fn` - Function: `() => Promise<ExtendedSwapStorageData[]>`
|
|
510
|
-
*/
|
|
511
|
-
constructor(get_fn: Function, store_fn: Function, delete_fn: Function, list_fn: Function, get_all_fn: Function);
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* JavaScript VTXO swap storage provider passed from TypeScript.
|
|
515
|
-
*
|
|
516
|
-
* This struct wraps JavaScript callback functions that implement
|
|
517
|
-
* typed VTXO swap storage operations. Each function should return a Promise.
|
|
518
|
-
*
|
|
519
|
-
* # Example (TypeScript with Dexie)
|
|
520
|
-
*
|
|
521
|
-
* ```typescript
|
|
522
|
-
* import Dexie from 'dexie';
|
|
523
|
-
*
|
|
524
|
-
* const db = new Dexie('lendaswap');
|
|
525
|
-
* db.version(1).stores({ vtxoSwaps: 'id' });
|
|
526
|
-
*
|
|
527
|
-
* const vtxoSwapStorage = new JsVtxoSwapStorageProvider(
|
|
528
|
-
* async (swapId) => await db.vtxoSwaps.get(swapId) ?? null,
|
|
529
|
-
* async (swapId, data) => { await db.vtxoSwaps.put({ id: swapId, ...data }); },
|
|
530
|
-
* async (swapId) => { await db.vtxoSwaps.delete(swapId); },
|
|
531
|
-
* async () => await db.vtxoSwaps.toCollection().primaryKeys(),
|
|
532
|
-
* async () => await db.vtxoSwaps.toArray()
|
|
533
|
-
* );
|
|
534
|
-
* ```
|
|
535
|
-
*/
|
|
536
|
-
export class JsVtxoSwapStorageProvider {
|
|
537
|
-
free(): void;
|
|
538
|
-
[Symbol.dispose](): void;
|
|
539
|
-
/**
|
|
540
|
-
* Create a new JsVtxoSwapStorageProvider from JavaScript callbacks.
|
|
541
|
-
*
|
|
542
|
-
* # Arguments
|
|
543
|
-
* * `get_fn` - Function: `(swapId: string) => Promise<ExtendedVtxoSwapStorageData | null>`
|
|
544
|
-
* * `store_fn` - Function: `(swapId: string, data: ExtendedVtxoSwapStorageData) => Promise<void>`
|
|
545
|
-
* * `delete_fn` - Function: `(swapId: string) => Promise<void>`
|
|
546
|
-
* * `list_fn` - Function: `() => Promise<string[]>`
|
|
547
|
-
* * `get_all_fn` - Function: `() => Promise<ExtendedVtxoSwapStorageData[]>`
|
|
548
|
-
*/
|
|
549
|
-
constructor(get_fn: Function, store_fn: Function, delete_fn: Function, list_fn: Function, get_all_fn: Function);
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* JavaScript wallet storage provider passed from TypeScript.
|
|
553
|
-
*
|
|
554
|
-
* This struct wraps JavaScript callback functions that implement
|
|
555
|
-
* the typed wallet storage operations. Each function should return a Promise.
|
|
556
|
-
*
|
|
557
|
-
* # Example (TypeScript)
|
|
558
|
-
*
|
|
559
|
-
* ```typescript
|
|
560
|
-
* const provider = new JsWalletStorageProvider(
|
|
561
|
-
* async () => localStorage.getItem('mnemonic'), // get_mnemonic
|
|
562
|
-
* async (mnemonic) => localStorage.setItem('mnemonic', mnemonic), // set_mnemonic
|
|
563
|
-
* async () => parseInt(localStorage.getItem('key_index') ?? '0'), // get_key_index
|
|
564
|
-
* async (index) => localStorage.setItem('key_index', index.toString()), // set_key_index
|
|
565
|
-
* );
|
|
566
|
-
* ```
|
|
567
|
-
*/
|
|
568
|
-
export class JsWalletStorageProvider {
|
|
569
|
-
free(): void;
|
|
570
|
-
[Symbol.dispose](): void;
|
|
571
|
-
/**
|
|
572
|
-
* Create a new JsWalletStorageProvider from JavaScript callbacks.
|
|
573
|
-
*
|
|
574
|
-
* # Arguments
|
|
575
|
-
* * `get_mnemonic_fn` - Function: `() => Promise<string | null>`
|
|
576
|
-
* * `set_mnemonic_fn` - Function: `(mnemonic: string) => Promise<void>`
|
|
577
|
-
* * `get_key_index_fn` - Function: `() => Promise<number>`
|
|
578
|
-
* * `set_key_index_fn` - Function: `(index: number) => Promise<void>`
|
|
579
|
-
*/
|
|
580
|
-
constructor(get_mnemonic_fn: Function, set_mnemonic_fn: Function, get_key_index_fn: Function, set_key_index_fn: Function);
|
|
581
|
-
}
|
|
582
592
|
/**
|
|
583
593
|
* Quote response from the API.
|
|
584
594
|
*/
|