@atomiqlabs/sdk 8.3.6 → 8.4.3

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 (49) 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/intermediaries/apis/IntermediaryAPI.d.ts +2 -0
  6. package/dist/intermediaries/apis/IntermediaryAPI.js +2 -0
  7. package/dist/swapper/Swapper.d.ts +2 -1
  8. package/dist/swapper/Swapper.js +4 -3
  9. package/dist/swaps/ISwap.d.ts +20 -0
  10. package/dist/swaps/ISwap.js +10 -0
  11. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +12 -0
  12. package/dist/swaps/escrow_swaps/IEscrowSwap.js +18 -0
  13. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +50 -4
  14. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +62 -8
  15. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +4 -1
  16. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +23 -4
  17. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +85 -3
  18. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +109 -5
  19. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +2 -0
  20. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +30 -4
  21. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +44 -3
  22. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +62 -4
  23. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +31 -2
  24. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +59 -2
  25. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +47 -1
  26. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +63 -3
  27. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +20 -2
  28. package/dist/swaps/trusted/ln/LnForGasSwap.js +27 -1
  29. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +20 -3
  30. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +31 -1
  31. package/dist/types/SwapStateInfo.d.ts +5 -0
  32. package/dist/types/SwapStateInfo.js +2 -0
  33. package/package.json +3 -1
  34. package/src/bitcoin/wallet/BitcoinWallet.ts +21 -4
  35. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +60 -5
  36. package/src/intermediaries/apis/IntermediaryAPI.ts +5 -1
  37. package/src/swapper/Swapper.ts +5 -2
  38. package/src/swaps/ISwap.ts +29 -0
  39. package/src/swaps/escrow_swaps/IEscrowSwap.ts +20 -0
  40. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +73 -10
  41. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +28 -3
  42. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +127 -9
  43. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +35 -4
  44. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +75 -6
  45. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +62 -4
  46. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +81 -4
  47. package/src/swaps/trusted/ln/LnForGasSwap.ts +36 -2
  48. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +43 -3
  49. package/src/types/SwapStateInfo.ts +6 -0
@@ -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;
@@ -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
@@ -269,6 +280,15 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
269
280
  * Returns the current state of the swap
270
281
  */
271
282
  getState(): S;
283
+ /**
284
+ * Returns the current state of the swap along with the human-readable description of the state
285
+ */
286
+ getStateInfo(): SwapStateInfo<S>;
287
+ /**
288
+ * Returns a state-dependent set of actions for the user to execute, or empty array if there is currently
289
+ * no action required from the user to execute.
290
+ */
291
+ abstract getCurrentActions(): Promise<SwapExecutionAction<T>[]>;
272
292
  /**
273
293
  * Returns output amount of the swap, user receives this much
274
294
  */
@@ -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
  */
@@ -229,6 +247,18 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
229
247
  required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
230
248
  }>;
231
249
  private isValidSecretPreimage;
250
+ /**
251
+ * Sets the secret preimage for the swap, in case it is not known already
252
+ *
253
+ * @param secret Secret preimage that matches the expected payment hash
254
+ *
255
+ * @throws {Error} If an invalid secret preimage is provided
256
+ */
257
+ setSecretPreimage(secret: string): void;
258
+ /**
259
+ * Returns whether the secret preimage for this swap is known
260
+ */
261
+ hasSecretPreimage(): boolean;
232
262
  /**
233
263
  * Executes the swap with the provided bitcoin lightning network wallet or LNURL
234
264
  *
@@ -239,7 +269,7 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
239
269
  * link, wallet is not required and the LN invoice can be paid externally as well (just pass null or undefined here)
240
270
  * @param callbacks Callbacks to track the progress of the swap
241
271
  * @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
272
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
243
273
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
244
274
  */
245
275
  execute(dstSigner: T["Signer"] | T["NativeSigner"], walletOrLnurlWithdraw?: MinimalLightningNetworkWalletInterface | LNURLWithdraw | string | null | undefined, callbacks?: {
@@ -249,9 +279,10 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
249
279
  onSwapSettled?: (destinationTxId: string) => void;
250
280
  }, options?: {
251
281
  abortSignal?: AbortSignal;
282
+ secret?: string;
252
283
  lightningTxCheckIntervalSeconds?: number;
253
284
  delayBetweenCommitAndClaimSeconds?: number;
254
- }, secret?: string): Promise<void>;
285
+ }): Promise<void>;
255
286
  /**
256
287
  * @inheritDoc
257
288
  *
@@ -259,12 +290,13 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
259
290
  * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
260
291
  * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
261
292
  * can use `skipChecks=true`)
262
- * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
293
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
263
294
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
264
295
  */
265
296
  txsExecute(options?: {
266
297
  skipChecks?: boolean;
267
- }, secret?: string): Promise<{
298
+ secret?: string;
299
+ }): Promise<{
268
300
  name: "Payment";
269
301
  description: string;
270
302
  chain: "LIGHTNING";
@@ -284,6 +316,20 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
284
316
  chain: T["ChainId"];
285
317
  txs: T["TX"][];
286
318
  })[]>;
319
+ /**
320
+ * @inheritDoc
321
+ *
322
+ * @param options
323
+ * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
324
+ * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
325
+ * can use `skipChecks=true`)
326
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
327
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
328
+ */
329
+ getCurrentActions(options?: {
330
+ skipChecks?: boolean;
331
+ secret?: string;
332
+ }): Promise<SwapExecutionAction<T>[]>;
287
333
  /**
288
334
  * Checks whether the LP received the LN payment and we can continue by committing & claiming the HTLC on-chain
289
335
  *
@@ -66,6 +66,16 @@ var FromBTCLNSwapState;
66
66
  */
67
67
  FromBTCLNSwapState[FromBTCLNSwapState["CLAIM_CLAIMED"] = 3] = "CLAIM_CLAIMED";
68
68
  })(FromBTCLNSwapState = exports.FromBTCLNSwapState || (exports.FromBTCLNSwapState = {}));
69
+ const FromBTCLNSwapStateDescription = {
70
+ [FromBTCLNSwapState.FAILED]: "Swap has failed as the user didn't settle the HTLC on the destination before expiration",
71
+ [FromBTCLNSwapState.QUOTE_EXPIRED]: "Swap has expired for good and there is no way how it can be executed anymore",
72
+ [FromBTCLNSwapState.QUOTE_SOFT_EXPIRED]: "Swap is expired, though there is still a chance that it will be processed",
73
+ [FromBTCLNSwapState.EXPIRED]: "Swap HTLC on the destination chain has expired, it is not safe anymore to settle (claim) the swap on the destination smart chain.",
74
+ [FromBTCLNSwapState.PR_CREATED]: "Swap quote was created, pay the bolt11 lightning network invoice to initiate the swap, then use the wait till the lightning network payment is received by the intermediary (LP)",
75
+ [FromBTCLNSwapState.PR_PAID]: "Lightning network payment has been received by the intermediary (LP), the user can now settle the swap on the destination smart chain side.",
76
+ [FromBTCLNSwapState.CLAIM_COMMITED]: "Swap escrow HTLC has been created on the destination chain. Continue by claiming it.",
77
+ [FromBTCLNSwapState.CLAIM_CLAIMED]: "Swap successfully settled and funds received on the destination chain"
78
+ };
69
79
  function isFromBTCLNSwapInit(obj) {
70
80
  return (obj.pr == null || typeof obj.pr === "string") &&
71
81
  (obj.secret == null || typeof obj.secret === "string") &&
@@ -97,6 +107,14 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
97
107
  initOrObject.url += "/frombtcln";
98
108
  super(wrapper, initOrObject);
99
109
  this.TYPE = SwapType_1.SwapType.FROM_BTCLN;
110
+ /**
111
+ * @internal
112
+ */
113
+ this.swapStateName = (state) => FromBTCLNSwapState[state];
114
+ /**
115
+ * @internal
116
+ */
117
+ this.swapStateDescription = FromBTCLNSwapStateDescription;
100
118
  /**
101
119
  * @internal
102
120
  */
@@ -384,6 +402,24 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
384
402
  const claimHash = this.wrapper._contract.getHashForHtlc(paymentHash).toString("hex");
385
403
  return this.getSwapData().getClaimHash() === claimHash;
386
404
  }
405
+ /**
406
+ * Sets the secret preimage for the swap, in case it is not known already
407
+ *
408
+ * @param secret Secret preimage that matches the expected payment hash
409
+ *
410
+ * @throws {Error} If an invalid secret preimage is provided
411
+ */
412
+ setSecretPreimage(secret) {
413
+ if (!this.isValidSecretPreimage(secret))
414
+ throw new Error("Invalid secret preimage provided, hash doesn't match!");
415
+ this.secret = secret;
416
+ }
417
+ /**
418
+ * Returns whether the secret preimage for this swap is known
419
+ */
420
+ hasSecretPreimage() {
421
+ return this.secret != null;
422
+ }
387
423
  //////////////////////////////
388
424
  //// Execution
389
425
  /**
@@ -396,10 +432,10 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
396
432
  * link, wallet is not required and the LN invoice can be paid externally as well (just pass null or undefined here)
397
433
  * @param callbacks Callbacks to track the progress of the swap
398
434
  * @param options Optional options for the swap like feeRate, AbortSignal, and timeouts/intervals
399
- * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
435
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
400
436
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
401
437
  */
402
- async execute(dstSigner, walletOrLnurlWithdraw, callbacks, options, secret) {
438
+ async execute(dstSigner, walletOrLnurlWithdraw, callbacks, options) {
403
439
  if (this._state === FromBTCLNSwapState.FAILED)
404
440
  throw new Error("Swap failed!");
405
441
  if (this._state === FromBTCLNSwapState.EXPIRED)
@@ -431,7 +467,7 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
431
467
  }
432
468
  if (this._state === FromBTCLNSwapState.PR_PAID || this._state === FromBTCLNSwapState.CLAIM_COMMITED) {
433
469
  if (this.canCommitAndClaimInOneShot()) {
434
- await this.commitAndClaim(dstSigner, options?.abortSignal, undefined, callbacks?.onDestinationCommitSent, callbacks?.onDestinationClaimSent, secret);
470
+ await this.commitAndClaim(dstSigner, options?.abortSignal, undefined, callbacks?.onDestinationCommitSent, callbacks?.onDestinationClaimSent, options?.secret);
435
471
  }
436
472
  else {
437
473
  if (this._state === FromBTCLNSwapState.PR_PAID) {
@@ -440,7 +476,7 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
440
476
  await (0, TimeoutUtils_1.timeoutPromise)(options.delayBetweenCommitAndClaimSeconds * 1000, options?.abortSignal);
441
477
  }
442
478
  if (this._state === FromBTCLNSwapState.CLAIM_COMMITED) {
443
- await this.claim(dstSigner, options?.abortSignal, callbacks?.onDestinationClaimSent, secret);
479
+ await this.claim(dstSigner, options?.abortSignal, callbacks?.onDestinationClaimSent, options?.secret);
444
480
  }
445
481
  }
446
482
  }
@@ -457,10 +493,10 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
457
493
  * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
458
494
  * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
459
495
  * can use `skipChecks=true`)
460
- * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
496
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
461
497
  * was recovered from on-chain data, or the pre-image was generated outside the SDK
462
498
  */
463
- async txsExecute(options, secret) {
499
+ async txsExecute(options) {
464
500
  if (this._state === FromBTCLNSwapState.PR_CREATED) {
465
501
  if (!await this._verifyQuoteValid())
466
502
  throw new Error("Quote already expired or close to expiry!");
@@ -483,7 +519,7 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
483
519
  if (!await this._verifyQuoteValid())
484
520
  throw new Error("Quote already expired or close to expiry!");
485
521
  const txsCommit = await this.txsCommit(options?.skipChecks);
486
- const txsClaim = await this._txsClaim(undefined, secret);
522
+ const txsClaim = await this._txsClaim(undefined, options?.secret);
487
523
  return [
488
524
  {
489
525
  name: "Commit",
@@ -500,7 +536,7 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
500
536
  ];
501
537
  }
502
538
  if (this._state === FromBTCLNSwapState.CLAIM_COMMITED) {
503
- const txsClaim = await this.txsClaim(undefined, secret);
539
+ const txsClaim = await this.txsClaim(undefined, options?.secret);
504
540
  return [
505
541
  {
506
542
  name: "Claim",
@@ -512,6 +548,24 @@ class FromBTCLNSwap extends IFromBTCSelfInitSwap_1.IFromBTCSelfInitSwap {
512
548
  }
513
549
  throw new Error("Invalid swap state to obtain execution txns, required PR_CREATED, PR_PAID or CLAIM_COMMITED");
514
550
  }
551
+ /**
552
+ * @inheritDoc
553
+ *
554
+ * @param options
555
+ * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
556
+ * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
557
+ * can use `skipChecks=true`)
558
+ * @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
559
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
560
+ */
561
+ async getCurrentActions(options) {
562
+ try {
563
+ return await this.txsExecute(options);
564
+ }
565
+ catch (e) {
566
+ return [];
567
+ }
568
+ }
515
569
  //////////////////////////////
516
570
  //// Payment
517
571
  /**
@@ -18,6 +18,8 @@ import { AmountData } from "../../../../types/AmountData";
18
18
  import { LNURLWithdrawParamsWithUrl } from "../../../../types/lnurl/LNURLWithdraw";
19
19
  import { AllOptional } from "../../../../utils/TypeUtils";
20
20
  export type FromBTCLNOptions = {
21
+ paymentHash?: Buffer;
22
+ description?: string;
21
23
  descriptionHash?: Buffer;
22
24
  unsafeSkipLnNodeCheck?: boolean;
23
25
  };
@@ -130,10 +132,11 @@ export declare class FromBTCLNWrapper<T extends ChainType> extends IFromBTCLNWra
130
132
  * @param lnurl LNURL-withdraw link to pull the funds from
131
133
  * @param amountData Amount, token and exact input/output data for to swap
132
134
  * @param lps An array of intermediaries (LPs) to get the quotes from
135
+ * @param options Optional additional quote options
133
136
  * @param additionalParams Optional additional parameters sent to the LP when creating the swap
134
137
  * @param abortSignal Abort signal
135
138
  */
136
- createViaLNURL(recipient: string, lnurl: string | LNURLWithdrawParamsWithUrl, amountData: AmountData, lps: Intermediary[], additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
139
+ createViaLNURL(recipient: string, lnurl: string | LNURLWithdrawParamsWithUrl, amountData: AmountData, lps: Intermediary[], options?: FromBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
137
140
  quote: Promise<FromBTCLNSwap<T>>;
138
141
  intermediary: Intermediary;
139
142
  }[]>;