@atomiqlabs/sdk 8.3.6 → 8.4.4

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.
Files changed (58) hide show
  1. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +3 -2
  2. package/dist/bitcoin/wallet/BitcoinWallet.js +15 -1
  3. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +25 -3
  4. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +51 -2
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +2 -0
  8. package/dist/intermediaries/apis/IntermediaryAPI.js +2 -0
  9. package/dist/swapper/Swapper.d.ts +2 -1
  10. package/dist/swapper/Swapper.js +4 -3
  11. package/dist/swaps/ISwap.d.ts +34 -0
  12. package/dist/swaps/ISwap.js +10 -0
  13. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +12 -0
  14. package/dist/swaps/escrow_swaps/IEscrowSwap.js +18 -0
  15. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +54 -4
  16. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +72 -8
  17. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +4 -1
  18. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +23 -4
  19. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +89 -3
  20. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +118 -5
  21. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +2 -0
  22. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +30 -4
  23. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +48 -3
  24. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +69 -4
  25. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +40 -2
  26. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +72 -2
  27. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +51 -1
  28. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +71 -3
  29. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +28 -2
  30. package/dist/swaps/trusted/ln/LnForGasSwap.js +39 -1
  31. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +28 -3
  32. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +44 -1
  33. package/dist/types/SwapStateInfo.d.ts +5 -0
  34. package/dist/types/SwapStateInfo.js +2 -0
  35. package/dist/types/lnurl/LNURLPay.d.ts +0 -1
  36. package/dist/types/lnurl/LNURLPay.js +0 -1
  37. package/dist/types/lnurl/LNURLWithdraw.d.ts +0 -1
  38. package/dist/types/lnurl/LNURLWithdraw.js +0 -1
  39. package/package.json +3 -1
  40. package/src/bitcoin/wallet/BitcoinWallet.ts +21 -4
  41. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +60 -5
  42. package/src/index.ts +1 -0
  43. package/src/intermediaries/apis/IntermediaryAPI.ts +5 -1
  44. package/src/swapper/Swapper.ts +5 -2
  45. package/src/swaps/ISwap.ts +45 -0
  46. package/src/swaps/escrow_swaps/IEscrowSwap.ts +20 -0
  47. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +86 -11
  48. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +28 -3
  49. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +137 -9
  50. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +35 -4
  51. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +83 -6
  52. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +77 -4
  53. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +90 -4
  54. package/src/swaps/trusted/ln/LnForGasSwap.ts +51 -3
  55. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +58 -3
  56. package/src/types/SwapStateInfo.ts +6 -0
  57. package/src/types/lnurl/LNURLPay.ts +0 -1
  58. package/src/types/lnurl/LNURLWithdraw.ts +0 -1
@@ -5,7 +5,7 @@ import { BTC_NETWORK } from "@scure/btc-signer/utils";
5
5
  import { Transaction } from "@scure/btc-signer";
6
6
  import { IBitcoinWallet } from "./IBitcoinWallet";
7
7
  import { Buffer } from "buffer";
8
- import { BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
8
+ import { BitcoinNetwork, BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
9
9
  /**
10
10
  * UTXO data structure for Bitcoin wallets
11
11
  *
@@ -41,7 +41,7 @@ export declare abstract class BitcoinWallet implements IBitcoinWallet {
41
41
  protected readonly network: BTC_NETWORK;
42
42
  protected feeMultiplier: number;
43
43
  protected feeOverride?: number;
44
- constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BTC_NETWORK, feeMultiplier?: number, feeOverride?: number);
44
+ constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BitcoinNetwork | BTC_NETWORK, feeMultiplier?: number, feeOverride?: number);
45
45
  /**
46
46
  * @inheritDoc
47
47
  */
@@ -126,4 +126,5 @@ export declare abstract class BitcoinWallet implements IBitcoinWallet {
126
126
  feeRate: number;
127
127
  totalFee: number;
128
128
  }>;
129
+ static bitcoinNetworkToObject(network: BitcoinNetwork): BTC_NETWORK;
129
130
  }
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BitcoinWallet = exports.identifyAddressType = void 0;
4
4
  const coinselect2_1 = require("../coinselect2");
5
+ const utils_1 = require("@scure/btc-signer/utils");
5
6
  const btc_signer_1 = require("@scure/btc-signer");
6
7
  const buffer_1 = require("buffer");
7
8
  const Utils_1 = require("../../utils/Utils");
8
9
  const BitcoinUtils_1 = require("../../utils/BitcoinUtils");
9
10
  const Logger_1 = require("../../utils/Logger");
11
+ const base_1 = require("@atomiqlabs/base");
10
12
  /**
11
13
  * Identifies the address type of a Bitcoin address
12
14
  *
@@ -29,6 +31,15 @@ function identifyAddressType(address, network) {
29
31
  }
30
32
  }
31
33
  exports.identifyAddressType = identifyAddressType;
34
+ const btcNetworkMapping = {
35
+ [base_1.BitcoinNetwork.MAINNET]: utils_1.NETWORK,
36
+ [base_1.BitcoinNetwork.TESTNET]: utils_1.TEST_NETWORK,
37
+ [base_1.BitcoinNetwork.TESTNET4]: utils_1.TEST_NETWORK,
38
+ [base_1.BitcoinNetwork.REGTEST]: {
39
+ ...utils_1.TEST_NETWORK,
40
+ bech32: "bcrt"
41
+ }
42
+ };
32
43
  const logger = (0, Logger_1.getLogger)("BitcoinWallet: ");
33
44
  /**
34
45
  * Abstract base class for Bitcoin wallet implementations, using bitcoin rpc with address index
@@ -39,7 +50,7 @@ const logger = (0, Logger_1.getLogger)("BitcoinWallet: ");
39
50
  class BitcoinWallet {
40
51
  constructor(mempoolApi, network, feeMultiplier = 1.25, feeOverride) {
41
52
  this.rpc = mempoolApi;
42
- this.network = network;
53
+ this.network = typeof (network) === "object" ? network : BitcoinWallet.bitcoinNetworkToObject(network);
43
54
  this.feeMultiplier = feeMultiplier;
44
55
  this.feeOverride = feeOverride;
45
56
  }
@@ -304,5 +315,8 @@ class BitcoinWallet {
304
315
  totalFee: coinselectResult.fee
305
316
  };
306
317
  }
318
+ static bitcoinNetworkToObject(network) {
319
+ return btcNetworkMapping[network];
320
+ }
307
321
  }
308
322
  exports.BitcoinWallet = BitcoinWallet;
@@ -1,8 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { CoinselectAddressTypes } from "../coinselect2";
2
4
  import { BTC_NETWORK } from "@scure/btc-signer/utils";
3
5
  import { Transaction } from "@scure/btc-signer";
6
+ import { Buffer } from "buffer";
4
7
  import { BitcoinWallet } from "./BitcoinWallet";
5
- import { BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
8
+ import { BitcoinNetwork, BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
6
9
  /**
7
10
  * Bitcoin wallet implementation deriving a single address from a WIF encoded private key
8
11
  *
@@ -13,7 +16,7 @@ export declare class SingleAddressBitcoinWallet extends BitcoinWallet {
13
16
  protected readonly pubkey: Uint8Array;
14
17
  protected readonly address: string;
15
18
  protected readonly addressType: CoinselectAddressTypes;
16
- constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BTC_NETWORK, addressDataOrWIF: string | {
19
+ constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, _network: BitcoinNetwork | BTC_NETWORK, addressDataOrWIF: string | {
17
20
  address: string;
18
21
  publicKey: string;
19
22
  }, feeMultiplier?: number, feeOverride?: number);
@@ -75,5 +78,24 @@ export declare class SingleAddressBitcoinWallet extends BitcoinWallet {
75
78
  *
76
79
  * @returns A WIF encoded bitcoin private key
77
80
  */
78
- static generateRandomPrivateKey(network?: BTC_NETWORK): string;
81
+ static generateRandomPrivateKey(network?: BitcoinNetwork | BTC_NETWORK): string;
82
+ /**
83
+ * Generates a 12-word long mnemonic from any entropy source with 128-bits or more, the entropy is first hashed
84
+ * using sha256, and the first 16 bytes of the hash are used to generate the mnemonic
85
+ *
86
+ * @param entropy Entropy to use for generating the mnemonic
87
+ */
88
+ static mnemonicFromEntropy(entropy: Buffer): string;
89
+ /**
90
+ * Generates a random 12-word long mnemonic
91
+ */
92
+ static generateRandomMnemonic(): string;
93
+ /**
94
+ * Generates a WIF private key from mnemonic phrase
95
+ *
96
+ * @param mnemonic Mnemonic to generate the WIF key from
97
+ * @param network Optional bitcoin network to generate the WIF for
98
+ * @param derivationPath Optional custom derivation path to use for deriving the wallet
99
+ */
100
+ static mnemonicToPrivateKey(mnemonic: string, network?: BitcoinNetwork | BTC_NETWORK, derivationPath?: string): Promise<string>;
79
101
  }
@@ -5,13 +5,20 @@ const utils_1 = require("@scure/btc-signer/utils");
5
5
  const btc_signer_1 = require("@scure/btc-signer");
6
6
  const buffer_1 = require("buffer");
7
7
  const BitcoinWallet_1 = require("./BitcoinWallet");
8
+ const bip32_1 = require("@scure/bip32");
9
+ const bip39_1 = require("@scure/bip39");
10
+ const english_js_1 = require("@scure/bip39/wordlists/english.js");
11
+ const sha2_1 = require("@noble/hashes/sha2");
8
12
  /**
9
13
  * Bitcoin wallet implementation deriving a single address from a WIF encoded private key
10
14
  *
11
15
  * @category Bitcoin
12
16
  */
13
17
  class SingleAddressBitcoinWallet extends BitcoinWallet_1.BitcoinWallet {
14
- constructor(mempoolApi, network, addressDataOrWIF, feeMultiplier = 1.25, feeOverride) {
18
+ constructor(mempoolApi, _network, addressDataOrWIF, feeMultiplier = 1.25, feeOverride) {
19
+ const network = typeof (_network) === "object"
20
+ ? _network
21
+ : BitcoinWallet_1.BitcoinWallet.bitcoinNetworkToObject(_network);
15
22
  super(mempoolApi, network, feeMultiplier, feeOverride);
16
23
  if (typeof (addressDataOrWIF) === "string") {
17
24
  try {
@@ -121,7 +128,49 @@ class SingleAddressBitcoinWallet extends BitcoinWallet_1.BitcoinWallet {
121
128
  * @returns A WIF encoded bitcoin private key
122
129
  */
123
130
  static generateRandomPrivateKey(network) {
124
- return (0, btc_signer_1.WIF)(network).encode((0, utils_1.randomPrivateKeyBytes)());
131
+ const networkObject = network == null || typeof (network) === "object"
132
+ ? network
133
+ : BitcoinWallet_1.BitcoinWallet.bitcoinNetworkToObject(network);
134
+ return (0, btc_signer_1.WIF)(networkObject).encode((0, utils_1.randomPrivateKeyBytes)());
135
+ }
136
+ /**
137
+ * Generates a 12-word long mnemonic from any entropy source with 128-bits or more, the entropy is first hashed
138
+ * using sha256, and the first 16 bytes of the hash are used to generate the mnemonic
139
+ *
140
+ * @param entropy Entropy to use for generating the mnemonic
141
+ */
142
+ static mnemonicFromEntropy(entropy) {
143
+ if (entropy.length < 16)
144
+ throw new Error("Requires at least 128-bit entropy (16 bytes)");
145
+ const entropyHash = buffer_1.Buffer.from((0, sha2_1.sha256)(entropy)).subarray(0, 16);
146
+ return (0, bip39_1.entropyToMnemonic)(entropyHash, english_js_1.wordlist);
147
+ }
148
+ /**
149
+ * Generates a random 12-word long mnemonic
150
+ */
151
+ static generateRandomMnemonic() {
152
+ return (0, bip39_1.generateMnemonic)(english_js_1.wordlist, 128);
153
+ }
154
+ /**
155
+ * Generates a WIF private key from mnemonic phrase
156
+ *
157
+ * @param mnemonic Mnemonic to generate the WIF key from
158
+ * @param network Optional bitcoin network to generate the WIF for
159
+ * @param derivationPath Optional custom derivation path to use for deriving the wallet
160
+ */
161
+ static async mnemonicToPrivateKey(mnemonic, network, derivationPath) {
162
+ const networkObject = network == null || typeof (network) === "object"
163
+ ? network
164
+ : BitcoinWallet_1.BitcoinWallet.bitcoinNetworkToObject(network);
165
+ derivationPath = networkObject == null || networkObject.bech32 === utils_1.NETWORK.bech32
166
+ ? "m/84'/0'/0'/0/0" //Mainnet
167
+ : "m/84'/1'/0'/0/0"; //Testnet
168
+ const seed = await (0, bip39_1.mnemonicToSeed)(mnemonic);
169
+ const hdKey = bip32_1.HDKey.fromMasterSeed(seed);
170
+ const privateKey = hdKey.derive(derivationPath).privateKey;
171
+ if (privateKey == null)
172
+ throw new Error("Cannot derive private key from the mnemonic!");
173
+ return (0, btc_signer_1.WIF)(networkObject).encode(privateKey);
125
174
  }
126
175
  }
127
176
  exports.SingleAddressBitcoinWallet = SingleAddressBitcoinWallet;
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ export * from "./types/lnurl/LNURLWithdraw";
73
73
  export * from "./types/wallets/MinimalBitcoinWalletInterface";
74
74
  export * from "./types/wallets/MinimalLightningNetworkWalletInterface";
75
75
  export * from "./types/wallets/LightningInvoiceCreateService";
76
+ export * from "./types/SwapStateInfo";
76
77
  export * from "./types/AmountData";
77
78
  export * from "./types/CustomPriceFunction";
78
79
  export * from "./types/SwapExecutionAction";
package/dist/index.js CHANGED
@@ -146,6 +146,7 @@ __exportStar(require("./types/lnurl/LNURLWithdraw"), exports);
146
146
  __exportStar(require("./types/wallets/MinimalBitcoinWalletInterface"), exports);
147
147
  __exportStar(require("./types/wallets/MinimalLightningNetworkWalletInterface"), exports);
148
148
  __exportStar(require("./types/wallets/LightningInvoiceCreateService"), exports);
149
+ __exportStar(require("./types/SwapStateInfo"), exports);
149
150
  __exportStar(require("./types/AmountData"), exports);
150
151
  __exportStar(require("./types/CustomPriceFunction"), exports);
151
152
  __exportStar(require("./types/SwapExecutionAction"), exports);
@@ -185,6 +185,7 @@ declare const FromBTCLNResponseSchema: {
185
185
  export type FromBTCLNResponseType = RequestSchemaResult<typeof FromBTCLNResponseSchema>;
186
186
  export type FromBTCLNInit = BaseFromBTCSwapInit & {
187
187
  paymentHash: Buffer;
188
+ description?: string;
188
189
  descriptionHash?: Buffer;
189
190
  };
190
191
  declare const FromBTCLNAutoResponseSchema: {
@@ -205,6 +206,7 @@ export type FromBTCLNAutoResponseType = RequestSchemaResult<typeof FromBTCLNAuto
205
206
  export type FromBTCLNAutoInit = Omit<BaseFromBTCSwapInit, "feeRate"> & {
206
207
  paymentHash: Buffer;
207
208
  gasToken: string;
209
+ description?: string;
208
210
  descriptionHash?: Buffer;
209
211
  gasAmount?: bigint;
210
212
  claimerBounty?: Promise<bigint>;
@@ -321,6 +321,7 @@ class IntermediaryAPI {
321
321
  amount: init.amount.toString(),
322
322
  address: init.claimer,
323
323
  token: init.token,
324
+ description: init.description ?? null,
324
325
  descriptionHash: init.descriptionHash == null ? null : init.descriptionHash.toString("hex"),
325
326
  exactOut: init.exactOut,
326
327
  feeRate: init.feeRate
@@ -366,6 +367,7 @@ class IntermediaryAPI {
366
367
  amount: init.amount.toString(),
367
368
  address: init.claimer,
368
369
  token: init.token,
370
+ description: init.description ?? null,
369
371
  descriptionHash: init.descriptionHash == null ? null : init.descriptionHash.toString("hex"),
370
372
  exactOut: init.exactOut,
371
373
  gasToken: init.gasToken,
@@ -371,8 +371,9 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
371
371
  * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
372
372
  * @param exactOut Whether to use a exact out instead of exact in
373
373
  * @param additionalParams Additional parameters sent to the LP when creating the swap
374
+ * @param options Additional options for the swap
374
375
  */
375
- createFromBTCLNSwapViaLNURL<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, lnurl: string | LNURLWithdraw, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined): Promise<FromBTCLNSwap<T[ChainIdentifier]>>;
376
+ createFromBTCLNSwapViaLNURL<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, lnurl: string | LNURLWithdraw, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCLNOptions): Promise<FromBTCLNSwap<T[ChainIdentifier]>>;
376
377
  /**
377
378
  * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap
378
379
  *
@@ -660,8 +660,9 @@ class Swapper extends events_1.EventEmitter {
660
660
  * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
661
661
  * @param exactOut Whether to use a exact out instead of exact in
662
662
  * @param additionalParams Additional parameters sent to the LP when creating the swap
663
+ * @param options Additional options for the swap
663
664
  */
664
- async createFromBTCLNSwapViaLNURL(chainIdentifier, recipient, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters) {
665
+ async createFromBTCLNSwapViaLNURL(chainIdentifier, recipient, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
665
666
  if (this._chains[chainIdentifier] == null)
666
667
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
667
668
  if (typeof (lnurl) === "string" && !this.Utils.isValidLNURL(lnurl))
@@ -674,7 +675,7 @@ class Swapper extends events_1.EventEmitter {
674
675
  token: tokenAddress,
675
676
  exactIn: !exactOut
676
677
  };
677
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].createViaLNURL(recipient, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN);
678
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].createViaLNURL(recipient, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN);
678
679
  }
679
680
  /**
680
681
  * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap
@@ -821,7 +822,7 @@ class Swapper extends events_1.EventEmitter {
821
822
  throw new Error("LNURL must be a string or LNURLWithdraw object!");
822
823
  return this.supportsSwapType(dstToken.chainId, SwapType_1.SwapType.FROM_BTCLN_AUTO) ?
823
824
  this.createFromBTCLNSwapNewViaLNURL(dstToken.chainId, dst, dstToken.address, src, amount, !exactIn, undefined, options) :
824
- this.createFromBTCLNSwapViaLNURL(dstToken.chainId, dst, dstToken.address, src, amount, !exactIn);
825
+ this.createFromBTCLNSwapViaLNURL(dstToken.chainId, dst, dstToken.address, src, amount, !exactIn, undefined, options);
825
826
  }
826
827
  else {
827
828
  return this.supportsSwapType(dstToken.chainId, SwapType_1.SwapType.FROM_BTCLN_AUTO) ?
@@ -12,6 +12,7 @@ import { Token } from "../types/Token";
12
12
  import { SwapExecutionAction } from "../types/SwapExecutionAction";
13
13
  import { LoggerType } from "../utils/Logger";
14
14
  import { PriceInfoType } from "../types/PriceInfoType";
15
+ import { SwapStateInfo } from "../types/SwapStateInfo";
15
16
  /**
16
17
  * Initialization data for creating a swap
17
18
  *
@@ -41,6 +42,16 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
41
42
  * Swap type
42
43
  */
43
44
  protected readonly abstract TYPE: SwapType;
45
+ /**
46
+ * Description for the states
47
+ * @internal
48
+ */
49
+ protected readonly abstract swapStateDescription: Record<S, string>;
50
+ /**
51
+ * Name of the states
52
+ * @internal
53
+ */
54
+ protected readonly abstract swapStateName: (state: number) => string;
44
55
  /**
45
56
  * Swap logger
46
57
  * @internal
@@ -145,6 +156,16 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
145
156
  * @param options Additional options for executing the swap
146
157
  */
147
158
  abstract txsExecute(options?: any): Promise<SwapExecutionAction<T>[]>;
159
+ /**
160
+ * Executes the swap with the provided wallet, the exact arguments for this functions differ for various swap
161
+ * types. Check the `execute()` function signature in the respective swap class to see the required arguments.
162
+ *
163
+ * @param args Execution arguments, usually contains a source wallet object, callbacks and options, for exact
164
+ * syntax check the respective swap class.
165
+ *
166
+ * @returns Whether a swap was successfully executed or not, if it wasn't the user can refund or claim manually
167
+ */
168
+ abstract execute(...args: any[]): Promise<boolean>;
148
169
  /**
149
170
  * This attempts to populate missing fields in the pricing info based on the swap amounts
150
171
  *
@@ -246,6 +267,10 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
246
267
  * Returns whether the swap failed (e.g. was refunded)
247
268
  */
248
269
  abstract isFailed(): boolean;
270
+ /**
271
+ * Returns whether the swap is currently being processed
272
+ */
273
+ abstract isInProgress(): boolean;
249
274
  /**
250
275
  * Whether a swap was initialized, a swap is considered initialized on first interaction with it, i.e.
251
276
  * calling commit() on a Smart chain -> Bitcoin swaps, calling waitForPayment() or similar on the other
@@ -269,6 +294,15 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
269
294
  * Returns the current state of the swap
270
295
  */
271
296
  getState(): S;
297
+ /**
298
+ * Returns the current state of the swap along with the human-readable description of the state
299
+ */
300
+ getStateInfo(): SwapStateInfo<S>;
301
+ /**
302
+ * Returns a state-dependent set of actions for the user to execute, or empty array if there is currently
303
+ * no action required from the user to execute.
304
+ */
305
+ abstract getCurrentActions(): Promise<SwapExecutionAction<T>[]>;
272
306
  /**
273
307
  * Returns output amount of the swap, user receives this much
274
308
  */
@@ -248,6 +248,16 @@ class ISwap {
248
248
  getState() {
249
249
  return this._state;
250
250
  }
251
+ /**
252
+ * Returns the current state of the swap along with the human-readable description of the state
253
+ */
254
+ getStateInfo() {
255
+ return {
256
+ state: this._state,
257
+ name: this.swapStateName(this._state),
258
+ description: this.swapStateDescription[this._state]
259
+ };
260
+ }
251
261
  //////////////////////////////
252
262
  //// Storage
253
263
  /**
@@ -70,6 +70,18 @@ export declare abstract class IEscrowSwap<T extends ChainType = ChainType, D ext
70
70
  * @inheritDoc
71
71
  */
72
72
  getId(): string;
73
+ /**
74
+ * Returns the smart chain transaction ID of the tx that initiated the escrow
75
+ */
76
+ getEscrowInitTxId(): string | undefined;
77
+ /**
78
+ * Returns the smart chain transaction ID of the tx that claimed (settled) the escrow
79
+ */
80
+ getEscrowClaimTxId(): string | undefined;
81
+ /**
82
+ * Returns the smart chain transaction ID of the tx that refunded the escrow
83
+ */
84
+ getEscrowRefundTxId(): string | undefined;
73
85
  /**
74
86
  * Periodically checks the chain to see whether the swap is committed
75
87
  *
@@ -79,6 +79,24 @@ class IEscrowSwap extends ISwap_1.ISwap {
79
79
  getId() {
80
80
  return this.getIdentifierHashString();
81
81
  }
82
+ /**
83
+ * Returns the smart chain transaction ID of the tx that initiated the escrow
84
+ */
85
+ getEscrowInitTxId() {
86
+ return this._commitTxId;
87
+ }
88
+ /**
89
+ * Returns the smart chain transaction ID of the tx that claimed (settled) the escrow
90
+ */
91
+ getEscrowClaimTxId() {
92
+ return this._claimTxId;
93
+ }
94
+ /**
95
+ * Returns the smart chain transaction ID of the tx that refunded the escrow
96
+ */
97
+ getEscrowRefundTxId() {
98
+ return this._refundTxId;
99
+ }
82
100
  //////////////////////////////
83
101
  //// Watchdogs
84
102
  /**
@@ -13,6 +13,7 @@ import { TokenAmount } from "../../../../types/TokenAmount";
13
13
  import { BtcToken, SCToken } from "../../../../types/Token";
14
14
  import { LoggerType } from "../../../../utils/Logger";
15
15
  import { LNURLWithdraw } from "../../../../types/lnurl/LNURLWithdraw";
16
+ import { SwapExecutionAction } from "../../../../types/SwapExecutionAction";
16
17
  /**
17
18
  * State enum for legacy Lightning -> Smart chain swaps
18
19
  * @category Swaps/Legacy/Lightning → Smart chain
@@ -77,6 +78,23 @@ export declare function isFromBTCLNSwapInit<T extends SwapData>(obj: any): obj i
77
78
  */
78
79
  export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFromBTCSelfInitSwap<T, FromBTCLNDefinition<T>, FromBTCLNSwapState> implements IAddressSwap, IClaimableSwap<T, FromBTCLNDefinition<T>, FromBTCLNSwapState> {
79
80
  protected readonly TYPE = SwapType.FROM_BTCLN;
81
+ /**
82
+ * @internal
83
+ */
84
+ protected readonly swapStateName: (state: number) => string;
85
+ /**
86
+ * @internal
87
+ */
88
+ protected readonly swapStateDescription: {
89
+ [-4]: string;
90
+ [-3]: string;
91
+ [-2]: string;
92
+ [-1]: string;
93
+ 0: string;
94
+ 1: string;
95
+ 2: string;
96
+ 3: string;
97
+ };
80
98
  /**
81
99
  * @internal
82
100
  */
@@ -190,6 +208,10 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
190
208
  * @inheritDoc
191
209
  */
192
210
  isFailed(): boolean;
211
+ /**
212
+ * @inheritDoc
213
+ */
214
+ isInProgress(): boolean;
193
215
  /**
194
216
  * @inheritDoc
195
217
  */
@@ -229,6 +251,18 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
229
251
  required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
230
252
  }>;
231
253
  private isValidSecretPreimage;
254
+ /**
255
+ * Sets the secret preimage for the swap, in case it is not known already
256
+ *
257
+ * @param secret Secret preimage that matches the expected payment hash
258
+ *
259
+ * @throws {Error} If an invalid secret preimage is provided
260
+ */
261
+ setSecretPreimage(secret: string): void;
262
+ /**
263
+ * Returns whether the secret preimage for this swap is known
264
+ */
265
+ hasSecretPreimage(): boolean;
232
266
  /**
233
267
  * Executes the swap with the provided bitcoin lightning network wallet or LNURL
234
268
  *
@@ -239,7 +273,7 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
239
273
  * link, wallet is not required and the LN invoice can be paid externally as well (just pass null or undefined here)
240
274
  * @param callbacks Callbacks to track the progress of the swap
241
275
  * @param options Optional options for the swap like feeRate, AbortSignal, and timeouts/intervals
242
- * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
276
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
243
277
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
244
278
  */
245
279
  execute(dstSigner: T["Signer"] | T["NativeSigner"], walletOrLnurlWithdraw?: MinimalLightningNetworkWalletInterface | LNURLWithdraw | string | null | undefined, callbacks?: {
@@ -249,9 +283,10 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
249
283
  onSwapSettled?: (destinationTxId: string) => void;
250
284
  }, options?: {
251
285
  abortSignal?: AbortSignal;
286
+ secret?: string;
252
287
  lightningTxCheckIntervalSeconds?: number;
253
288
  delayBetweenCommitAndClaimSeconds?: number;
254
- }, secret?: string): Promise<void>;
289
+ }): Promise<boolean>;
255
290
  /**
256
291
  * @inheritDoc
257
292
  *
@@ -259,12 +294,13 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
259
294
  * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
260
295
  * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
261
296
  * can use `skipChecks=true`)
262
- * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
297
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
263
298
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
264
299
  */
265
300
  txsExecute(options?: {
266
301
  skipChecks?: boolean;
267
- }, secret?: string): Promise<{
302
+ secret?: string;
303
+ }): Promise<{
268
304
  name: "Payment";
269
305
  description: string;
270
306
  chain: "LIGHTNING";
@@ -284,6 +320,20 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
284
320
  chain: T["ChainId"];
285
321
  txs: T["TX"][];
286
322
  })[]>;
323
+ /**
324
+ * @inheritDoc
325
+ *
326
+ * @param options
327
+ * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
328
+ * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
329
+ * can use `skipChecks=true`)
330
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
331
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
332
+ */
333
+ getCurrentActions(options?: {
334
+ skipChecks?: boolean;
335
+ secret?: string;
336
+ }): Promise<SwapExecutionAction<T>[]>;
287
337
  /**
288
338
  * Checks whether the LP received the LN payment and we can continue by committing & claiming the HTLC on-chain
289
339
  *