@atomiqlabs/sdk 8.7.7 → 8.9.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/api/index.d.ts +1 -0
- package/api/index.js +3 -0
- package/dist/ApiList.d.ts +37 -0
- package/dist/ApiList.js +30 -0
- package/dist/api/ApiEndpoints.d.ts +393 -0
- package/dist/api/ApiEndpoints.js +2 -0
- package/dist/api/ApiParser.d.ts +10 -0
- package/dist/api/ApiParser.js +134 -0
- package/dist/api/ApiTypes.d.ts +157 -0
- package/dist/api/ApiTypes.js +75 -0
- package/dist/api/SerializedAction.d.ts +40 -0
- package/dist/api/SerializedAction.js +59 -0
- package/dist/api/SwapperApi.d.ts +50 -0
- package/dist/api/SwapperApi.js +431 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +24 -0
- package/dist/bitcoin/coinselect2/accumulative.d.ts +1 -0
- package/dist/bitcoin/coinselect2/accumulative.js +1 -1
- package/dist/bitcoin/coinselect2/blackjack.d.ts +1 -0
- package/dist/bitcoin/coinselect2/blackjack.js +1 -1
- package/dist/bitcoin/coinselect2/index.d.ts +3 -2
- package/dist/bitcoin/coinselect2/index.js +2 -2
- package/dist/bitcoin/coinselect2/utils.d.ts +7 -2
- package/dist/bitcoin/coinselect2/utils.js +45 -10
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +8 -25
- package/dist/bitcoin/wallet/BitcoinWallet.js +31 -18
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +40 -2
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +7 -2
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +10 -4
- package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
- package/dist/events/UnifiedSwapEventListener.js +8 -2
- package/dist/http/HttpUtils.d.ts +4 -2
- package/dist/http/HttpUtils.js +10 -4
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
- package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +182 -15
- package/dist/intermediaries/apis/IntermediaryAPI.js +192 -31
- package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
- package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
- package/dist/storage/IUnifiedStorage.d.ts +45 -3
- package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
- package/dist/storage/UnifiedSwapStorage.js +46 -8
- package/dist/swapper/Swapper.d.ts +77 -4
- package/dist/swapper/Swapper.js +117 -25
- package/dist/swapper/SwapperUtils.d.ts +18 -2
- package/dist/swapper/SwapperUtils.js +39 -1
- package/dist/swaps/ISwap.d.ts +70 -9
- package/dist/swaps/ISwap.js +28 -6
- package/dist/swaps/ISwapWrapper.d.ts +11 -1
- package/dist/swaps/ISwapWrapper.js +23 -3
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +85 -22
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +299 -56
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +41 -7
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +183 -58
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
- package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
- package/dist/types/SwapExecutionAction.d.ts +141 -34
- package/dist/types/SwapExecutionAction.js +104 -0
- package/dist/types/SwapExecutionStep.d.ts +144 -0
- package/dist/types/SwapExecutionStep.js +87 -0
- package/dist/types/TokenAmount.d.ts +6 -0
- package/dist/types/TokenAmount.js +26 -1
- package/dist/utils/BitcoinUtils.d.ts +4 -0
- package/dist/utils/BitcoinUtils.js +73 -1
- package/dist/utils/BitcoinWalletUtils.d.ts +2 -2
- package/dist/utils/Utils.d.ts +3 -1
- package/dist/utils/Utils.js +7 -1
- package/package.json +7 -4
- package/src/api/ApiEndpoints.ts +427 -0
- package/src/api/ApiParser.ts +138 -0
- package/src/api/ApiTypes.ts +229 -0
- package/src/api/SerializedAction.ts +97 -0
- package/src/api/SwapperApi.ts +545 -0
- package/src/api/index.ts +5 -0
- package/src/bitcoin/coinselect2/accumulative.ts +2 -1
- package/src/bitcoin/coinselect2/blackjack.ts +2 -1
- package/src/bitcoin/coinselect2/index.ts +5 -4
- package/src/bitcoin/coinselect2/utils.ts +55 -14
- package/src/bitcoin/wallet/BitcoinWallet.ts +69 -57
- package/src/bitcoin/wallet/IBitcoinWallet.ts +44 -3
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +12 -4
- package/src/events/UnifiedSwapEventListener.ts +11 -3
- package/src/http/HttpUtils.ts +10 -4
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
- package/src/index.ts +1 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
- package/src/intermediaries/apis/IntermediaryAPI.ts +335 -35
- package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
- package/src/storage/IUnifiedStorage.ts +45 -4
- package/src/storage/UnifiedSwapStorage.ts +42 -8
- package/src/swapper/Swapper.ts +165 -24
- package/src/swapper/SwapperUtils.ts +42 -2
- package/src/swaps/ISwap.ts +88 -16
- package/src/swaps/ISwapWrapper.ts +28 -3
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +413 -64
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +239 -61
- package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
- package/src/types/SwapExecutionAction.ts +266 -43
- package/src/types/SwapExecutionStep.ts +224 -0
- package/src/types/TokenAmount.ts +36 -2
- package/src/utils/BitcoinUtils.ts +73 -0
- package/src/utils/BitcoinWalletUtils.ts +2 -2
- package/src/utils/Utils.ts +10 -1
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { FieldTypeEnum, RequestSchemaResult } from "../../http/paramcoders/SchemaVerifier";
|
|
3
|
+
import { FieldTypeEnum, RequestSchema, RequestSchemaResult, RequestSchemaResultPromise } from "../../http/paramcoders/SchemaVerifier";
|
|
4
|
+
import { RequestBody } from "../../http/paramcoders/client/StreamingFetchPromise";
|
|
4
5
|
export type InfoHandlerResponse = {
|
|
5
6
|
envelope: string;
|
|
6
7
|
chains: {
|
|
@@ -234,17 +235,27 @@ declare const SpvFromBTCPrepareResponseSchema: {
|
|
|
234
235
|
readonly callerFeeShare: FieldTypeEnum.BigInt;
|
|
235
236
|
readonly frontingFeeShare: FieldTypeEnum.BigInt;
|
|
236
237
|
readonly executionFeeShare: FieldTypeEnum.BigInt;
|
|
238
|
+
readonly usedUtxoInputCalculation: FieldTypeEnum.BooleanOptional;
|
|
237
239
|
};
|
|
238
240
|
export type SpvFromBTCPrepareResponseType = RequestSchemaResult<typeof SpvFromBTCPrepareResponseSchema>;
|
|
239
241
|
export type SpvFromBTCPrepare = SwapInit & {
|
|
240
242
|
address: string;
|
|
241
|
-
amount: bigint
|
|
243
|
+
amount: Promise<bigint>;
|
|
242
244
|
gasAmount: bigint;
|
|
243
245
|
gasToken: string;
|
|
244
246
|
exactOut: boolean;
|
|
245
247
|
callerFeeRate: Promise<bigint>;
|
|
246
248
|
frontingFeeRate: bigint;
|
|
247
249
|
stickyAddress?: boolean;
|
|
250
|
+
amountUtxos?: Promise<{
|
|
251
|
+
value: number;
|
|
252
|
+
vSize: number;
|
|
253
|
+
cpfp?: {
|
|
254
|
+
effectiveVSize: number;
|
|
255
|
+
effectiveFeeRate: number;
|
|
256
|
+
};
|
|
257
|
+
}[] | undefined>;
|
|
258
|
+
amountFeeRate?: Promise<number | undefined>;
|
|
248
259
|
};
|
|
249
260
|
declare const SpvFromBTCInitResponseSchema: {
|
|
250
261
|
readonly txId: FieldTypeEnum.String;
|
|
@@ -254,7 +265,108 @@ export type SpvFromBTCInit = {
|
|
|
254
265
|
quoteId: string;
|
|
255
266
|
psbtHex: string;
|
|
256
267
|
};
|
|
268
|
+
export declare enum TrustedInvoiceStatusResponseCodes {
|
|
269
|
+
EXPIRED = 10001,
|
|
270
|
+
PAID = 10000,
|
|
271
|
+
AWAIT_PAYMENT = 10010,
|
|
272
|
+
PENDING = 10011,
|
|
273
|
+
TX_SENT = 10012
|
|
274
|
+
}
|
|
275
|
+
export type TrustedInvoiceStatusResponse = {
|
|
276
|
+
code: TrustedInvoiceStatusResponseCodes.TX_SENT | TrustedInvoiceStatusResponseCodes.PAID;
|
|
277
|
+
msg: string;
|
|
278
|
+
data: {
|
|
279
|
+
txId: string;
|
|
280
|
+
};
|
|
281
|
+
} | {
|
|
282
|
+
code: Exclude<TrustedInvoiceStatusResponseCodes, TrustedInvoiceStatusResponseCodes.TX_SENT | TrustedInvoiceStatusResponseCodes.PAID>;
|
|
283
|
+
msg: string;
|
|
284
|
+
};
|
|
285
|
+
export type TrustedFromBTCLNInit = {
|
|
286
|
+
address: string;
|
|
287
|
+
amount: bigint;
|
|
288
|
+
token: string;
|
|
289
|
+
};
|
|
290
|
+
declare const TrustedFromBTCLNResponseSchema: {
|
|
291
|
+
readonly pr: FieldTypeEnum.String;
|
|
292
|
+
readonly swapFee: FieldTypeEnum.BigInt;
|
|
293
|
+
readonly swapFeeSats: FieldTypeEnum.BigInt;
|
|
294
|
+
readonly total: FieldTypeEnum.BigInt;
|
|
295
|
+
};
|
|
296
|
+
export type TrustedFromBTCLNResponseType = RequestSchemaResult<typeof TrustedFromBTCLNResponseSchema>;
|
|
297
|
+
export declare enum TrustedAddressStatusResponseCodes {
|
|
298
|
+
EXPIRED = 10001,
|
|
299
|
+
PAID = 10000,
|
|
300
|
+
AWAIT_PAYMENT = 10010,
|
|
301
|
+
AWAIT_CONFIRMATION = 10011,
|
|
302
|
+
PENDING = 10013,
|
|
303
|
+
TX_SENT = 10012,
|
|
304
|
+
REFUNDED = 10014,
|
|
305
|
+
DOUBLE_SPENT = 10015,
|
|
306
|
+
REFUNDABLE = 10016
|
|
307
|
+
}
|
|
308
|
+
export type TrustedAddressStatusResponse = {
|
|
309
|
+
code: TrustedAddressStatusResponseCodes.TX_SENT | TrustedAddressStatusResponseCodes.PAID;
|
|
310
|
+
msg: string;
|
|
311
|
+
data: {
|
|
312
|
+
adjustedAmount: string;
|
|
313
|
+
adjustedTotal: string;
|
|
314
|
+
adjustedFee?: string;
|
|
315
|
+
adjustedFeeSats?: string;
|
|
316
|
+
txId: string;
|
|
317
|
+
scTxId: string;
|
|
318
|
+
};
|
|
319
|
+
} | {
|
|
320
|
+
code: TrustedAddressStatusResponseCodes.AWAIT_CONFIRMATION | TrustedAddressStatusResponseCodes.PENDING;
|
|
321
|
+
msg: string;
|
|
322
|
+
data: {
|
|
323
|
+
adjustedAmount: string;
|
|
324
|
+
adjustedTotal: string;
|
|
325
|
+
adjustedFee?: string;
|
|
326
|
+
adjustedFeeSats?: string;
|
|
327
|
+
txId: string;
|
|
328
|
+
};
|
|
329
|
+
} | {
|
|
330
|
+
code: TrustedAddressStatusResponseCodes.REFUNDABLE;
|
|
331
|
+
msg: string;
|
|
332
|
+
data: {
|
|
333
|
+
adjustedAmount: string;
|
|
334
|
+
};
|
|
335
|
+
} | {
|
|
336
|
+
code: TrustedAddressStatusResponseCodes.REFUNDED | TrustedAddressStatusResponseCodes.DOUBLE_SPENT;
|
|
337
|
+
msg: string;
|
|
338
|
+
data: {
|
|
339
|
+
txId: string;
|
|
340
|
+
};
|
|
341
|
+
} | {
|
|
342
|
+
code: TrustedAddressStatusResponseCodes.AWAIT_PAYMENT | TrustedAddressStatusResponseCodes.EXPIRED;
|
|
343
|
+
msg: string;
|
|
344
|
+
};
|
|
345
|
+
export type TrustedFromBTCInit = {
|
|
346
|
+
address: string;
|
|
347
|
+
amount: bigint;
|
|
348
|
+
token: string;
|
|
349
|
+
refundAddress?: string;
|
|
350
|
+
};
|
|
351
|
+
declare const TrustedFromBTCResponseSchema: {
|
|
352
|
+
readonly paymentHash: FieldTypeEnum.String;
|
|
353
|
+
readonly sequence: FieldTypeEnum.BigInt;
|
|
354
|
+
readonly btcAddress: FieldTypeEnum.String;
|
|
355
|
+
readonly amountSats: FieldTypeEnum.BigInt;
|
|
356
|
+
readonly swapFeeSats: FieldTypeEnum.BigInt;
|
|
357
|
+
readonly swapFee: FieldTypeEnum.BigInt;
|
|
358
|
+
readonly total: FieldTypeEnum.BigInt;
|
|
359
|
+
readonly intermediaryKey: FieldTypeEnum.String;
|
|
360
|
+
readonly recommendedFee: FieldTypeEnum.Number;
|
|
361
|
+
readonly expiresAt: FieldTypeEnum.Number;
|
|
362
|
+
};
|
|
363
|
+
export type TrustedFromBTCResponseType = RequestSchemaResult<typeof TrustedFromBTCResponseSchema>;
|
|
257
364
|
export declare class IntermediaryAPI {
|
|
365
|
+
requestHeaders?: (type: "GET" | "POST", url: string, body?: any) => Record<string, string>;
|
|
366
|
+
constructor(requestHeaders?: (type: "GET" | "POST", url: string, body?: any) => Record<string, string>);
|
|
367
|
+
httpGet<T>(url: string, timeout?: number, abortSignal?: AbortSignal, allowNon200?: boolean): Promise<T>;
|
|
368
|
+
httpPost<T>(url: string, body: any, timeout?: number, abortSignal?: AbortSignal): Promise<T>;
|
|
369
|
+
streamingFetchPromise<T extends RequestSchema>(url: string, body: RequestBody, schema: T, timeout?: number, signal?: AbortSignal, streamRequest?: boolean): Promise<RequestSchemaResultPromise<T>>;
|
|
258
370
|
/**
|
|
259
371
|
* Returns the information about a specific intermediary
|
|
260
372
|
*
|
|
@@ -265,7 +377,7 @@ export declare class IntermediaryAPI {
|
|
|
265
377
|
* @throws {RequestError} If non-200 http response code is returned
|
|
266
378
|
* @throws {Error} If the supplied nonce doesn't match the response
|
|
267
379
|
*/
|
|
268
|
-
|
|
380
|
+
getIntermediaryInfo(baseUrl: string, timeout?: number, abortSignal?: AbortSignal): Promise<InfoHandlerResponse>;
|
|
269
381
|
/**
|
|
270
382
|
* Returns the information about an outcome of the To BTC swap
|
|
271
383
|
*
|
|
@@ -277,7 +389,7 @@ export declare class IntermediaryAPI {
|
|
|
277
389
|
*
|
|
278
390
|
* @throws {RequestError} If non-200 http response code is returned
|
|
279
391
|
*/
|
|
280
|
-
|
|
392
|
+
getRefundAuthorization(url: string, paymentHash: string, sequence: bigint, timeout?: number, abortSignal?: AbortSignal): Promise<RefundAuthorizationResponse>;
|
|
281
393
|
/**
|
|
282
394
|
* Returns the information about the payment of the From BTCLN swaps
|
|
283
395
|
*
|
|
@@ -288,7 +400,7 @@ export declare class IntermediaryAPI {
|
|
|
288
400
|
*
|
|
289
401
|
* @throws {RequestError} If non-200 http response code is returned
|
|
290
402
|
*/
|
|
291
|
-
|
|
403
|
+
getPaymentAuthorization(url: string, paymentHash: string, timeout?: number, abortSignal?: AbortSignal): Promise<PaymentAuthorizationResponse>;
|
|
292
404
|
/**
|
|
293
405
|
* Returns the status of the payment of the From BTCLN swaps
|
|
294
406
|
*
|
|
@@ -299,7 +411,7 @@ export declare class IntermediaryAPI {
|
|
|
299
411
|
*
|
|
300
412
|
* @throws {RequestError} If non-200 http response code is returned
|
|
301
413
|
*/
|
|
302
|
-
|
|
414
|
+
getInvoiceStatus(url: string, paymentHash: string, timeout?: number, abortSignal?: AbortSignal): Promise<InvoiceStatusResponse>;
|
|
303
415
|
/**
|
|
304
416
|
* Initiate To BTC swap with an intermediary
|
|
305
417
|
*
|
|
@@ -312,7 +424,7 @@ export declare class IntermediaryAPI {
|
|
|
312
424
|
*
|
|
313
425
|
* @throws {RequestError} If non-200 http response code is returned
|
|
314
426
|
*/
|
|
315
|
-
|
|
427
|
+
initToBTC(chainIdentifier: string, baseUrl: string, init: ToBTCInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
316
428
|
signDataPrefetch: Promise<any>;
|
|
317
429
|
response: Promise<ToBTCResponseType>;
|
|
318
430
|
};
|
|
@@ -329,7 +441,7 @@ export declare class IntermediaryAPI {
|
|
|
329
441
|
*
|
|
330
442
|
* @throws {RequestError} If non-200 http response code is returned
|
|
331
443
|
*/
|
|
332
|
-
|
|
444
|
+
initFromBTC(chainIdentifier: string, baseUrl: string, depositToken: string, init: FromBTCInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
333
445
|
signDataPrefetch: Promise<any>;
|
|
334
446
|
response: Promise<FromBTCResponseType>;
|
|
335
447
|
};
|
|
@@ -346,7 +458,7 @@ export declare class IntermediaryAPI {
|
|
|
346
458
|
*
|
|
347
459
|
* @throws {RequestError} If non-200 http response code is returned
|
|
348
460
|
*/
|
|
349
|
-
|
|
461
|
+
initFromBTCLN(chainIdentifier: string, baseUrl: string, depositToken: string, init: FromBTCLNInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
350
462
|
lnPublicKey: Promise<string | null>;
|
|
351
463
|
response: Promise<FromBTCLNResponseType>;
|
|
352
464
|
};
|
|
@@ -362,7 +474,7 @@ export declare class IntermediaryAPI {
|
|
|
362
474
|
*
|
|
363
475
|
* @throws {RequestError} If non-200 http response code is returned
|
|
364
476
|
*/
|
|
365
|
-
|
|
477
|
+
initFromBTCLNAuto(chainIdentifier: string, baseUrl: string, init: FromBTCLNAutoInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
366
478
|
lnPublicKey: Promise<string | null>;
|
|
367
479
|
response: Promise<FromBTCLNAutoResponseType>;
|
|
368
480
|
};
|
|
@@ -378,7 +490,7 @@ export declare class IntermediaryAPI {
|
|
|
378
490
|
*
|
|
379
491
|
* @throws {RequestError} If non-200 http response code is returned
|
|
380
492
|
*/
|
|
381
|
-
|
|
493
|
+
initToBTCLN(chainIdentifier: string, baseUrl: string, init: ToBTCLNInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
382
494
|
signDataPrefetch: Promise<any>;
|
|
383
495
|
response: Promise<ToBTCLNResponseType>;
|
|
384
496
|
};
|
|
@@ -393,7 +505,7 @@ export declare class IntermediaryAPI {
|
|
|
393
505
|
*
|
|
394
506
|
* @throws {RequestError} If non-200 http response code is returned
|
|
395
507
|
*/
|
|
396
|
-
|
|
508
|
+
initToBTCLNExactIn(baseUrl: string, init: ToBTCLNInitExactIn, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): Promise<ToBTCLNResponseType>;
|
|
397
509
|
/**
|
|
398
510
|
* Prepare To BTCLN exact in swap with an intermediary
|
|
399
511
|
*
|
|
@@ -406,7 +518,7 @@ export declare class IntermediaryAPI {
|
|
|
406
518
|
*
|
|
407
519
|
* @throws {RequestError} If non-200 http response code is returned
|
|
408
520
|
*/
|
|
409
|
-
|
|
521
|
+
prepareToBTCLNExactIn(chainIdentifier: string, baseUrl: string, init: ToBTCLNPrepareExactIn, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): {
|
|
410
522
|
signDataPrefetch: Promise<any>;
|
|
411
523
|
response: Promise<ToBTCLNPrepareExactInResponseType>;
|
|
412
524
|
};
|
|
@@ -422,7 +534,7 @@ export declare class IntermediaryAPI {
|
|
|
422
534
|
*
|
|
423
535
|
* @throws {RequestError} If non-200 http response code is returned
|
|
424
536
|
*/
|
|
425
|
-
|
|
537
|
+
prepareSpvFromBTC(chainIdentifier: string, baseUrl: string, init: SpvFromBTCPrepare, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): Promise<SpvFromBTCPrepareResponseType>;
|
|
426
538
|
/**
|
|
427
539
|
* Prepare From BTC swap via new spv vault swaps with an intermediary
|
|
428
540
|
*
|
|
@@ -435,6 +547,61 @@ export declare class IntermediaryAPI {
|
|
|
435
547
|
*
|
|
436
548
|
* @throws {RequestError} If non-200 http response code is returned
|
|
437
549
|
*/
|
|
438
|
-
|
|
550
|
+
initSpvFromBTC(chainIdentifier: string, url: string, init: SpvFromBTCInit, timeout?: number, abortSignal?: AbortSignal, streamRequest?: boolean): Promise<SpvFromBTCInitResponseType>;
|
|
551
|
+
/**
|
|
552
|
+
* Fetches the invoice status from the intermediary node
|
|
553
|
+
*
|
|
554
|
+
* @param url Url of the trusted intermediary
|
|
555
|
+
* @param paymentHash Payment hash of the lightning invoice
|
|
556
|
+
* @param timeout Timeout in milliseconds
|
|
557
|
+
* @param abortSignal
|
|
558
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
559
|
+
*/
|
|
560
|
+
getTrustedInvoiceStatus(url: string, paymentHash: string, timeout?: number, abortSignal?: AbortSignal): Promise<TrustedInvoiceStatusResponse>;
|
|
561
|
+
/**
|
|
562
|
+
* Initiate a trusted swap from BTCLN to SC native currency, retries!
|
|
563
|
+
*
|
|
564
|
+
* @param chainIdentifier
|
|
565
|
+
* @param baseUrl Base url of the trusted swap intermediary
|
|
566
|
+
* @param init Initialization parameters
|
|
567
|
+
* @param timeout Timeout in milliseconds for the request
|
|
568
|
+
* @param abortSignal
|
|
569
|
+
* @throws {RequestError} If the response is non-200
|
|
570
|
+
*/
|
|
571
|
+
initTrustedFromBTCLN(chainIdentifier: string, baseUrl: string, init: TrustedFromBTCLNInit, timeout?: number, abortSignal?: AbortSignal): Promise<TrustedFromBTCLNResponseType>;
|
|
572
|
+
/**
|
|
573
|
+
* Fetches the address status from the intermediary node
|
|
574
|
+
*
|
|
575
|
+
* @param url Url of the trusted intermediary
|
|
576
|
+
* @param paymentHash Payment hash of the swap
|
|
577
|
+
* @param sequence Sequence number of the swap
|
|
578
|
+
* @param timeout Timeout in milliseconds
|
|
579
|
+
* @param abortSignal
|
|
580
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
581
|
+
*/
|
|
582
|
+
getTrustedAddressStatus(url: string, paymentHash: string, sequence: bigint, timeout?: number, abortSignal?: AbortSignal): Promise<TrustedAddressStatusResponse>;
|
|
583
|
+
/**
|
|
584
|
+
* Sets the refund address for an on-chain gas swap
|
|
585
|
+
*
|
|
586
|
+
* @param url Url of the trusted intermediary
|
|
587
|
+
* @param paymentHash Payment hash of the swap
|
|
588
|
+
* @param sequence Sequence number of the swap
|
|
589
|
+
* @param refundAddress Refund address to set for the swap
|
|
590
|
+
* @param timeout Timeout in milliseconds
|
|
591
|
+
* @param abortSignal
|
|
592
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
593
|
+
*/
|
|
594
|
+
setTrustedRefundAddress(url: string, paymentHash: string, sequence: bigint, refundAddress: string, timeout?: number, abortSignal?: AbortSignal): Promise<void>;
|
|
595
|
+
/**
|
|
596
|
+
* Initiate a trusted swap from BTC to SC native currency, retries!
|
|
597
|
+
*
|
|
598
|
+
* @param chainIdentifier
|
|
599
|
+
* @param baseUrl Base url of the trusted swap intermediary
|
|
600
|
+
* @param init Initialization parameters
|
|
601
|
+
* @param timeout Timeout in milliseconds for the request
|
|
602
|
+
* @param abortSignal
|
|
603
|
+
* @throws {RequestError} If the response is non-200
|
|
604
|
+
*/
|
|
605
|
+
initTrustedFromBTC(chainIdentifier: string, baseUrl: string, init: TrustedFromBTCInit, timeout?: number, abortSignal?: AbortSignal): Promise<TrustedFromBTCResponseType>;
|
|
439
606
|
}
|
|
440
607
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IntermediaryAPI = exports.InvoiceStatusResponseCodes = exports.PaymentAuthorizationResponseCodes = exports.RefundAuthorizationResponseCodes = void 0;
|
|
3
|
+
exports.IntermediaryAPI = exports.TrustedAddressStatusResponseCodes = exports.TrustedInvoiceStatusResponseCodes = exports.InvoiceStatusResponseCodes = exports.PaymentAuthorizationResponseCodes = exports.RefundAuthorizationResponseCodes = void 0;
|
|
4
4
|
const RequestError_1 = require("../../errors/RequestError");
|
|
5
5
|
const SchemaVerifier_1 = require("../../http/paramcoders/SchemaVerifier");
|
|
6
6
|
const StreamingFetchPromise_1 = require("../../http/paramcoders/client/StreamingFetchPromise");
|
|
@@ -123,12 +123,70 @@ const SpvFromBTCPrepareResponseSchema = {
|
|
|
123
123
|
gasSwapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
124
124
|
callerFeeShare: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
125
125
|
frontingFeeShare: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
126
|
-
executionFeeShare: SchemaVerifier_1.FieldTypeEnum.BigInt
|
|
126
|
+
executionFeeShare: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
127
|
+
usedUtxoInputCalculation: SchemaVerifier_1.FieldTypeEnum.BooleanOptional
|
|
127
128
|
};
|
|
128
129
|
const SpvFromBTCInitResponseSchema = {
|
|
129
130
|
txId: SchemaVerifier_1.FieldTypeEnum.String
|
|
130
131
|
};
|
|
132
|
+
/////////////////////////
|
|
133
|
+
///// Trusted from BTCLN
|
|
134
|
+
var TrustedInvoiceStatusResponseCodes;
|
|
135
|
+
(function (TrustedInvoiceStatusResponseCodes) {
|
|
136
|
+
TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["EXPIRED"] = 10001] = "EXPIRED";
|
|
137
|
+
TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["PAID"] = 10000] = "PAID";
|
|
138
|
+
TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["AWAIT_PAYMENT"] = 10010] = "AWAIT_PAYMENT";
|
|
139
|
+
TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["PENDING"] = 10011] = "PENDING";
|
|
140
|
+
TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["TX_SENT"] = 10012] = "TX_SENT";
|
|
141
|
+
})(TrustedInvoiceStatusResponseCodes = exports.TrustedInvoiceStatusResponseCodes || (exports.TrustedInvoiceStatusResponseCodes = {}));
|
|
142
|
+
const TrustedFromBTCLNResponseSchema = {
|
|
143
|
+
pr: SchemaVerifier_1.FieldTypeEnum.String,
|
|
144
|
+
swapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
145
|
+
swapFeeSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
146
|
+
total: SchemaVerifier_1.FieldTypeEnum.BigInt
|
|
147
|
+
};
|
|
148
|
+
/////////////////////////
|
|
149
|
+
///// Trusted from BTC
|
|
150
|
+
var TrustedAddressStatusResponseCodes;
|
|
151
|
+
(function (TrustedAddressStatusResponseCodes) {
|
|
152
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["EXPIRED"] = 10001] = "EXPIRED";
|
|
153
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["PAID"] = 10000] = "PAID";
|
|
154
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["AWAIT_PAYMENT"] = 10010] = "AWAIT_PAYMENT";
|
|
155
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["AWAIT_CONFIRMATION"] = 10011] = "AWAIT_CONFIRMATION";
|
|
156
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["PENDING"] = 10013] = "PENDING";
|
|
157
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["TX_SENT"] = 10012] = "TX_SENT";
|
|
158
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["REFUNDED"] = 10014] = "REFUNDED";
|
|
159
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["DOUBLE_SPENT"] = 10015] = "DOUBLE_SPENT";
|
|
160
|
+
TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["REFUNDABLE"] = 10016] = "REFUNDABLE";
|
|
161
|
+
})(TrustedAddressStatusResponseCodes = exports.TrustedAddressStatusResponseCodes || (exports.TrustedAddressStatusResponseCodes = {}));
|
|
162
|
+
const TrustedFromBTCResponseSchema = {
|
|
163
|
+
paymentHash: SchemaVerifier_1.FieldTypeEnum.String,
|
|
164
|
+
sequence: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
165
|
+
btcAddress: SchemaVerifier_1.FieldTypeEnum.String,
|
|
166
|
+
amountSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
167
|
+
swapFeeSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
168
|
+
swapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
169
|
+
total: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
170
|
+
intermediaryKey: SchemaVerifier_1.FieldTypeEnum.String,
|
|
171
|
+
recommendedFee: SchemaVerifier_1.FieldTypeEnum.Number,
|
|
172
|
+
expiresAt: SchemaVerifier_1.FieldTypeEnum.Number
|
|
173
|
+
};
|
|
131
174
|
class IntermediaryAPI {
|
|
175
|
+
constructor(requestHeaders) {
|
|
176
|
+
this.requestHeaders = requestHeaders;
|
|
177
|
+
}
|
|
178
|
+
httpGet(url, timeout, abortSignal, allowNon200 = false) {
|
|
179
|
+
const headers = this.requestHeaders == null ? {} : this.requestHeaders("GET", url);
|
|
180
|
+
return (0, HttpUtils_1.httpGet)(url, timeout, abortSignal, allowNon200, headers);
|
|
181
|
+
}
|
|
182
|
+
httpPost(url, body, timeout, abortSignal) {
|
|
183
|
+
const headers = this.requestHeaders == null ? {} : this.requestHeaders("POST", url, body);
|
|
184
|
+
return (0, HttpUtils_1.httpPost)(url, body, timeout, abortSignal, headers);
|
|
185
|
+
}
|
|
186
|
+
streamingFetchPromise(url, body, schema, timeout, signal, streamRequest) {
|
|
187
|
+
const headers = this.requestHeaders == null ? {} : this.requestHeaders("POST", url);
|
|
188
|
+
return (0, StreamingFetchPromise_1.streamingFetchPromise)(url, body, schema, timeout, signal, streamRequest, headers);
|
|
189
|
+
}
|
|
132
190
|
/**
|
|
133
191
|
* Returns the information about a specific intermediary
|
|
134
192
|
*
|
|
@@ -139,14 +197,14 @@ class IntermediaryAPI {
|
|
|
139
197
|
* @throws {RequestError} If non-200 http response code is returned
|
|
140
198
|
* @throws {Error} If the supplied nonce doesn't match the response
|
|
141
199
|
*/
|
|
142
|
-
|
|
200
|
+
async getIntermediaryInfo(baseUrl, timeout, abortSignal) {
|
|
143
201
|
const nonce = (0, Utils_1.randomBytes)(32).toString("hex");
|
|
144
202
|
const abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
145
203
|
//We don't know whether the node supports only POST or also has GET info support enabled
|
|
146
204
|
// here we try both, and abort when the first one returns (which should be GET)
|
|
147
205
|
const response = await Promise.any([
|
|
148
|
-
|
|
149
|
-
|
|
206
|
+
this.httpGet(baseUrl + "/info?nonce=" + nonce, timeout, abortController.signal),
|
|
207
|
+
this.httpPost(baseUrl + "/info", {
|
|
150
208
|
nonce,
|
|
151
209
|
}, timeout, abortController.signal)
|
|
152
210
|
]);
|
|
@@ -167,8 +225,8 @@ class IntermediaryAPI {
|
|
|
167
225
|
*
|
|
168
226
|
* @throws {RequestError} If non-200 http response code is returned
|
|
169
227
|
*/
|
|
170
|
-
|
|
171
|
-
return (0, RetryUtils_1.tryWithRetries)(() =>
|
|
228
|
+
async getRefundAuthorization(url, paymentHash, sequence, timeout, abortSignal) {
|
|
229
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getRefundAuthorization" +
|
|
172
230
|
"?paymentHash=" + encodeURIComponent(paymentHash) +
|
|
173
231
|
"&sequence=" + encodeURIComponent(sequence.toString(10)), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
174
232
|
}
|
|
@@ -182,8 +240,8 @@ class IntermediaryAPI {
|
|
|
182
240
|
*
|
|
183
241
|
* @throws {RequestError} If non-200 http response code is returned
|
|
184
242
|
*/
|
|
185
|
-
|
|
186
|
-
return (0, RetryUtils_1.tryWithRetries)(() =>
|
|
243
|
+
async getPaymentAuthorization(url, paymentHash, timeout, abortSignal) {
|
|
244
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoicePaymentAuth" +
|
|
187
245
|
"?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
188
246
|
}
|
|
189
247
|
/**
|
|
@@ -196,8 +254,8 @@ class IntermediaryAPI {
|
|
|
196
254
|
*
|
|
197
255
|
* @throws {RequestError} If non-200 http response code is returned
|
|
198
256
|
*/
|
|
199
|
-
|
|
200
|
-
return (0, RetryUtils_1.tryWithRetries)(() =>
|
|
257
|
+
async getInvoiceStatus(url, paymentHash, timeout, abortSignal) {
|
|
258
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoiceStatus" +
|
|
201
259
|
"?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
202
260
|
}
|
|
203
261
|
/**
|
|
@@ -212,8 +270,8 @@ class IntermediaryAPI {
|
|
|
212
270
|
*
|
|
213
271
|
* @throws {RequestError} If non-200 http response code is returned
|
|
214
272
|
*/
|
|
215
|
-
|
|
216
|
-
const responseBodyPromise =
|
|
273
|
+
initToBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
274
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtc/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
|
|
217
275
|
...init.additionalParams,
|
|
218
276
|
address: init.btcAddress,
|
|
219
277
|
amount: init.amount.toString(10),
|
|
@@ -260,8 +318,8 @@ class IntermediaryAPI {
|
|
|
260
318
|
*
|
|
261
319
|
* @throws {RequestError} If non-200 http response code is returned
|
|
262
320
|
*/
|
|
263
|
-
|
|
264
|
-
const responseBodyPromise =
|
|
321
|
+
initFromBTC(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
|
|
322
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtc/getAddress?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
|
|
265
323
|
...init.additionalParams,
|
|
266
324
|
address: init.claimer,
|
|
267
325
|
amount: init.amount.toString(10),
|
|
@@ -314,8 +372,8 @@ class IntermediaryAPI {
|
|
|
314
372
|
*
|
|
315
373
|
* @throws {RequestError} If non-200 http response code is returned
|
|
316
374
|
*/
|
|
317
|
-
|
|
318
|
-
const responseBodyPromise =
|
|
375
|
+
initFromBTCLN(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
|
|
376
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtcln/createInvoice?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
|
|
319
377
|
...init.additionalParams,
|
|
320
378
|
paymentHash: init.paymentHash.toString("hex"),
|
|
321
379
|
amount: init.amount.toString(),
|
|
@@ -360,8 +418,8 @@ class IntermediaryAPI {
|
|
|
360
418
|
*
|
|
361
419
|
* @throws {RequestError} If non-200 http response code is returned
|
|
362
420
|
*/
|
|
363
|
-
|
|
364
|
-
const responseBodyPromise =
|
|
421
|
+
initFromBTCLNAuto(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
422
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtcln_auto/createInvoice?chain=" + encodeURIComponent(chainIdentifier), {
|
|
365
423
|
...init.additionalParams,
|
|
366
424
|
paymentHash: init.paymentHash.toString("hex"),
|
|
367
425
|
amount: init.amount.toString(),
|
|
@@ -408,8 +466,8 @@ class IntermediaryAPI {
|
|
|
408
466
|
*
|
|
409
467
|
* @throws {RequestError} If non-200 http response code is returned
|
|
410
468
|
*/
|
|
411
|
-
|
|
412
|
-
const responseBodyPromise =
|
|
469
|
+
initToBTCLN(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
470
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
|
|
413
471
|
exactIn: false,
|
|
414
472
|
...init.additionalParams,
|
|
415
473
|
pr: init.pr,
|
|
@@ -453,8 +511,8 @@ class IntermediaryAPI {
|
|
|
453
511
|
*
|
|
454
512
|
* @throws {RequestError} If non-200 http response code is returned
|
|
455
513
|
*/
|
|
456
|
-
|
|
457
|
-
const responseBody = await
|
|
514
|
+
async initToBTCLNExactIn(baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
515
|
+
const responseBody = await this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoiceExactIn", {
|
|
458
516
|
...init.additionalParams,
|
|
459
517
|
pr: init.pr,
|
|
460
518
|
reqId: init.reqId,
|
|
@@ -488,8 +546,8 @@ class IntermediaryAPI {
|
|
|
488
546
|
*
|
|
489
547
|
* @throws {RequestError} If non-200 http response code is returned
|
|
490
548
|
*/
|
|
491
|
-
|
|
492
|
-
const responseBodyPromise =
|
|
549
|
+
prepareToBTCLNExactIn(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
550
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
|
|
493
551
|
exactIn: true,
|
|
494
552
|
...init.additionalParams,
|
|
495
553
|
pr: init.pr,
|
|
@@ -533,18 +591,32 @@ class IntermediaryAPI {
|
|
|
533
591
|
*
|
|
534
592
|
* @throws {RequestError} If non-200 http response code is returned
|
|
535
593
|
*/
|
|
536
|
-
|
|
537
|
-
|
|
594
|
+
prepareSpvFromBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
|
|
595
|
+
//We need to make sure we only send the amount parameter after the amountUtxos and amountFeeRate resolve
|
|
596
|
+
// this is needed, because in the LP code to maintain backwards compatibility the amountUtxos and amountFeeRate
|
|
597
|
+
// params are checked immediately after the amount param (and other params) are received, if amount were sent
|
|
598
|
+
// first without the amountUtxos or amountFeeRate populated these fields would've been skipped altogether
|
|
599
|
+
const amountPromise = (async () => {
|
|
600
|
+
if (init.amountUtxos != null)
|
|
601
|
+
await init.amountUtxos;
|
|
602
|
+
if (init.amountFeeRate != null)
|
|
603
|
+
await init.amountFeeRate;
|
|
604
|
+
const amount = await init.amount;
|
|
605
|
+
return amount.toString(10);
|
|
606
|
+
})();
|
|
607
|
+
const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtc_spv/getQuote?chain=" + encodeURIComponent(chainIdentifier), {
|
|
538
608
|
exactOut: init.exactOut,
|
|
539
609
|
...init.additionalParams,
|
|
540
610
|
address: init.address,
|
|
541
|
-
amount:
|
|
611
|
+
amount: amountPromise,
|
|
542
612
|
token: init.token,
|
|
543
613
|
gasAmount: init.gasAmount.toString(10),
|
|
544
614
|
gasToken: init.gasToken,
|
|
545
615
|
frontingFeeRate: init.frontingFeeRate.toString(10),
|
|
546
616
|
callerFeeRate: init.callerFeeRate.then(val => val.toString(10)),
|
|
547
|
-
stickyAddress: init.stickyAddress
|
|
617
|
+
stickyAddress: init.stickyAddress,
|
|
618
|
+
amountUtxos: init.amountUtxos,
|
|
619
|
+
amountFeeRate: init.amountFeeRate
|
|
548
620
|
}, {
|
|
549
621
|
code: SchemaVerifier_1.FieldTypeEnum.Number,
|
|
550
622
|
msg: SchemaVerifier_1.FieldTypeEnum.String,
|
|
@@ -576,8 +648,8 @@ class IntermediaryAPI {
|
|
|
576
648
|
*
|
|
577
649
|
* @throws {RequestError} If non-200 http response code is returned
|
|
578
650
|
*/
|
|
579
|
-
|
|
580
|
-
const responseBodyPromise =
|
|
651
|
+
initSpvFromBTC(chainIdentifier, url, init, timeout, abortSignal, streamRequest) {
|
|
652
|
+
const responseBodyPromise = this.streamingFetchPromise(url + "/postQuote?chain=" + encodeURIComponent(chainIdentifier), {
|
|
581
653
|
quoteId: init.quoteId,
|
|
582
654
|
psbtHex: init.psbtHex
|
|
583
655
|
}, {
|
|
@@ -599,5 +671,94 @@ class IntermediaryAPI {
|
|
|
599
671
|
return result;
|
|
600
672
|
});
|
|
601
673
|
}
|
|
674
|
+
/**
|
|
675
|
+
* Fetches the invoice status from the intermediary node
|
|
676
|
+
*
|
|
677
|
+
* @param url Url of the trusted intermediary
|
|
678
|
+
* @param paymentHash Payment hash of the lightning invoice
|
|
679
|
+
* @param timeout Timeout in milliseconds
|
|
680
|
+
* @param abortSignal
|
|
681
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
682
|
+
*/
|
|
683
|
+
async getTrustedInvoiceStatus(url, paymentHash, timeout, abortSignal) {
|
|
684
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoiceStatus?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Initiate a trusted swap from BTCLN to SC native currency, retries!
|
|
688
|
+
*
|
|
689
|
+
* @param chainIdentifier
|
|
690
|
+
* @param baseUrl Base url of the trusted swap intermediary
|
|
691
|
+
* @param init Initialization parameters
|
|
692
|
+
* @param timeout Timeout in milliseconds for the request
|
|
693
|
+
* @param abortSignal
|
|
694
|
+
* @throws {RequestError} If the response is non-200
|
|
695
|
+
*/
|
|
696
|
+
async initTrustedFromBTCLN(chainIdentifier, baseUrl, init, timeout, abortSignal) {
|
|
697
|
+
const resp = await (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(baseUrl + "/lnforgas/createInvoice" +
|
|
698
|
+
"?address=" + encodeURIComponent(init.address) +
|
|
699
|
+
"&amount=" + encodeURIComponent(init.amount.toString(10)) +
|
|
700
|
+
"&chain=" + encodeURIComponent(chainIdentifier) +
|
|
701
|
+
"&token=" + encodeURIComponent(init.token), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
702
|
+
if (resp.code !== 10000)
|
|
703
|
+
throw RequestError_1.RequestError.parse(JSON.stringify(resp), 400);
|
|
704
|
+
const res = (0, SchemaVerifier_1.verifySchema)(resp.data, TrustedFromBTCLNResponseSchema);
|
|
705
|
+
if (res == null)
|
|
706
|
+
throw new Error("Invalid response returned from LP");
|
|
707
|
+
return res;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Fetches the address status from the intermediary node
|
|
711
|
+
*
|
|
712
|
+
* @param url Url of the trusted intermediary
|
|
713
|
+
* @param paymentHash Payment hash of the swap
|
|
714
|
+
* @param sequence Sequence number of the swap
|
|
715
|
+
* @param timeout Timeout in milliseconds
|
|
716
|
+
* @param abortSignal
|
|
717
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
718
|
+
*/
|
|
719
|
+
async getTrustedAddressStatus(url, paymentHash, sequence, timeout, abortSignal) {
|
|
720
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getAddressStatus?paymentHash=" + encodeURIComponent(paymentHash) + "&sequence=" + encodeURIComponent(sequence.toString(10)), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Sets the refund address for an on-chain gas swap
|
|
724
|
+
*
|
|
725
|
+
* @param url Url of the trusted intermediary
|
|
726
|
+
* @param paymentHash Payment hash of the swap
|
|
727
|
+
* @param sequence Sequence number of the swap
|
|
728
|
+
* @param refundAddress Refund address to set for the swap
|
|
729
|
+
* @param timeout Timeout in milliseconds
|
|
730
|
+
* @param abortSignal
|
|
731
|
+
* @throws {RequestError} if non-200 http response is returned
|
|
732
|
+
*/
|
|
733
|
+
async setTrustedRefundAddress(url, paymentHash, sequence, refundAddress, timeout, abortSignal) {
|
|
734
|
+
return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/setRefundAddress" +
|
|
735
|
+
"?paymentHash=" + encodeURIComponent(paymentHash) +
|
|
736
|
+
"&sequence=" + encodeURIComponent(sequence.toString(10)) +
|
|
737
|
+
"&refundAddress=" + encodeURIComponent(refundAddress), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Initiate a trusted swap from BTC to SC native currency, retries!
|
|
741
|
+
*
|
|
742
|
+
* @param chainIdentifier
|
|
743
|
+
* @param baseUrl Base url of the trusted swap intermediary
|
|
744
|
+
* @param init Initialization parameters
|
|
745
|
+
* @param timeout Timeout in milliseconds for the request
|
|
746
|
+
* @param abortSignal
|
|
747
|
+
* @throws {RequestError} If the response is non-200
|
|
748
|
+
*/
|
|
749
|
+
async initTrustedFromBTC(chainIdentifier, baseUrl, init, timeout, abortSignal) {
|
|
750
|
+
const resp = await (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(baseUrl + "/frombtc_trusted/getAddress?chain=" + encodeURIComponent(chainIdentifier) +
|
|
751
|
+
"&address=" + encodeURIComponent(init.address) +
|
|
752
|
+
"&amount=" + encodeURIComponent(init.amount.toString(10)) +
|
|
753
|
+
(init.refundAddress == null ? "" : "&refundAddress=" + encodeURIComponent(init.refundAddress)) +
|
|
754
|
+
"&exactIn=true" +
|
|
755
|
+
"&token=" + encodeURIComponent(init.token), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
|
|
756
|
+
if (resp.code !== 10000)
|
|
757
|
+
throw RequestError_1.RequestError.parse(JSON.stringify(resp), 400);
|
|
758
|
+
const res = (0, SchemaVerifier_1.verifySchema)(resp.data, TrustedFromBTCResponseSchema);
|
|
759
|
+
if (res == null)
|
|
760
|
+
throw new Error("Invalid response returned from LP");
|
|
761
|
+
return res;
|
|
762
|
+
}
|
|
602
763
|
}
|
|
603
764
|
exports.IntermediaryAPI = IntermediaryAPI;
|