@atomiqlabs/sdk 8.8.3 → 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.
Files changed (130) hide show
  1. package/api/index.d.ts +1 -0
  2. package/api/index.js +3 -0
  3. package/dist/ApiList.d.ts +37 -0
  4. package/dist/ApiList.js +30 -0
  5. package/dist/api/ApiEndpoints.d.ts +393 -0
  6. package/dist/api/ApiEndpoints.js +2 -0
  7. package/dist/api/ApiParser.d.ts +10 -0
  8. package/dist/api/ApiParser.js +134 -0
  9. package/dist/api/ApiTypes.d.ts +157 -0
  10. package/dist/api/ApiTypes.js +75 -0
  11. package/dist/api/SerializedAction.d.ts +40 -0
  12. package/dist/api/SerializedAction.js +59 -0
  13. package/dist/api/SwapperApi.d.ts +50 -0
  14. package/dist/api/SwapperApi.js +431 -0
  15. package/dist/api/index.d.ts +5 -0
  16. package/dist/api/index.js +24 -0
  17. package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
  18. package/dist/events/UnifiedSwapEventListener.js +8 -2
  19. package/dist/http/HttpUtils.d.ts +4 -2
  20. package/dist/http/HttpUtils.js +10 -4
  21. package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
  22. package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
  26. package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
  27. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
  28. package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
  29. package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
  30. package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
  31. package/dist/storage/IUnifiedStorage.d.ts +45 -3
  32. package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
  33. package/dist/storage/UnifiedSwapStorage.js +46 -8
  34. package/dist/swapper/Swapper.d.ts +36 -3
  35. package/dist/swapper/Swapper.js +54 -18
  36. package/dist/swapper/SwapperUtils.d.ts +18 -2
  37. package/dist/swapper/SwapperUtils.js +39 -1
  38. package/dist/swaps/ISwap.d.ts +70 -9
  39. package/dist/swaps/ISwap.js +28 -6
  40. package/dist/swaps/ISwapWrapper.d.ts +11 -1
  41. package/dist/swaps/ISwapWrapper.js +23 -3
  42. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
  43. package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
  44. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
  45. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
  46. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
  47. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
  48. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
  49. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
  50. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
  51. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
  52. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
  53. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
  54. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
  55. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
  56. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
  57. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
  58. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
  59. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
  60. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
  61. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
  62. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
  63. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
  64. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
  65. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
  66. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
  67. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
  68. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
  69. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
  70. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
  71. package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
  72. package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
  73. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
  74. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
  75. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
  76. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
  77. package/dist/types/SwapExecutionAction.d.ts +141 -34
  78. package/dist/types/SwapExecutionAction.js +104 -0
  79. package/dist/types/SwapExecutionStep.d.ts +144 -0
  80. package/dist/types/SwapExecutionStep.js +87 -0
  81. package/dist/types/TokenAmount.d.ts +6 -0
  82. package/dist/types/TokenAmount.js +26 -1
  83. package/dist/utils/BitcoinUtils.d.ts +2 -0
  84. package/dist/utils/BitcoinUtils.js +34 -1
  85. package/dist/utils/Utils.d.ts +3 -1
  86. package/dist/utils/Utils.js +7 -1
  87. package/package.json +7 -4
  88. package/src/api/ApiEndpoints.ts +427 -0
  89. package/src/api/ApiParser.ts +138 -0
  90. package/src/api/ApiTypes.ts +229 -0
  91. package/src/api/SerializedAction.ts +97 -0
  92. package/src/api/SwapperApi.ts +545 -0
  93. package/src/api/index.ts +5 -0
  94. package/src/events/UnifiedSwapEventListener.ts +11 -3
  95. package/src/http/HttpUtils.ts +10 -4
  96. package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
  97. package/src/index.ts +1 -0
  98. package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
  99. package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
  100. package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
  101. package/src/storage/IUnifiedStorage.ts +45 -4
  102. package/src/storage/UnifiedSwapStorage.ts +42 -8
  103. package/src/swapper/Swapper.ts +87 -18
  104. package/src/swapper/SwapperUtils.ts +42 -2
  105. package/src/swaps/ISwap.ts +88 -16
  106. package/src/swaps/ISwapWrapper.ts +28 -3
  107. package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
  108. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
  109. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
  110. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
  111. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
  112. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
  113. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
  114. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
  115. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
  116. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
  117. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
  118. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
  119. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
  120. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
  121. package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
  122. package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
  123. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
  124. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
  125. package/src/types/SwapExecutionAction.ts +266 -43
  126. package/src/types/SwapExecutionStep.ts +224 -0
  127. package/src/types/TokenAmount.ts +36 -2
  128. package/src/utils/BitcoinUtils.ts +32 -0
  129. package/src/utils/Utils.ts +10 -1
  130. package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Execution step describing destination-side setup required before the swap can continue.
3
+ *
4
+ * @category Swap Steps
5
+ */
6
+ export type SwapExecutionStepSetup<Chain extends string = string> = {
7
+ type: "Setup";
8
+ side: "destination";
9
+ chain: Chain;
10
+ title: string;
11
+ description: string;
12
+ /**
13
+ * Current status of the setup step.
14
+ *
15
+ * - `awaiting`: The setup transaction or action still needs to be performed.
16
+ * - `completed`: The setup was already completed successfully.
17
+ * - `soft_expired`: The setup should be treated as expired by the user, but it may still progress because of in-flight or background processing.
18
+ * - `expired`: The setup can no longer be performed because the swap expired.
19
+ */
20
+ status: "awaiting" | "completed" | "soft_expired" | "expired";
21
+ setupTxId?: string;
22
+ };
23
+ /**
24
+ * Type guard for {@link SwapExecutionStepSetup}
25
+ *
26
+ * @category Swap Steps
27
+ */
28
+ export declare function isSwapExecutionStepSetup<Chain extends string = string>(obj: any, chain?: Chain): obj is SwapExecutionStepSetup<Chain>;
29
+ /**
30
+ * Execution step describing the user payment that initiates or funds the swap.
31
+ *
32
+ * @category Swap Steps
33
+ */
34
+ export type SwapExecutionStepPayment<Chain extends string = string> = {
35
+ type: "Payment";
36
+ side: "source";
37
+ chain: Chain;
38
+ title: string;
39
+ description: string;
40
+ /**
41
+ * Current status of the payment step.
42
+ *
43
+ * - `inactive`: The payment step is not yet active because a previous step must complete first.
44
+ * - `awaiting`: The payment is expected, but no payment transaction is known yet.
45
+ * - `received`: A payment transaction is known, but it is not yet fully confirmed.
46
+ * - `confirmed`: The payment was confirmed and fully satisfies the swap requirements.
47
+ * - `soft_expired`: The payment should be treated as expired by the user, but it may still progress because of in-flight or background processing.
48
+ * - `expired`: The payment step can no longer be completed because the swap expired.
49
+ */
50
+ status: "inactive" | "awaiting" | "received" | "confirmed" | "soft_expired" | "expired";
51
+ /**
52
+ * Optional confirmation progress for Bitcoin on-chain payments.
53
+ */
54
+ confirmations?: {
55
+ /**
56
+ * Number of confirmations currently observed for the payment.
57
+ */
58
+ current: number;
59
+ /**
60
+ * Number of confirmations required before the payment is considered final.
61
+ */
62
+ target: number;
63
+ /**
64
+ * Estimated remaining time in seconds until the target confirmation count is reached.
65
+ *
66
+ * Can be `-1` if the estimate is not available.
67
+ */
68
+ etaSeconds: number;
69
+ };
70
+ initTxId?: string;
71
+ settleTxId?: string;
72
+ };
73
+ /**
74
+ * Type guard for {@link SwapExecutionStepPayment}
75
+ *
76
+ * @category Swap Steps
77
+ */
78
+ export declare function isSwapExecutionStepPayment<Chain extends string = string>(obj: any, chain?: Chain): obj is SwapExecutionStepPayment<Chain>;
79
+ /**
80
+ * Execution step describing payout or settlement on the destination side of the swap.
81
+ *
82
+ * @category Swap Steps
83
+ */
84
+ export type SwapExecutionStepSettlement<Chain extends string = string, AdditionalStatuses extends "awaiting_automatic" | "awaiting_manual" | "soft_settled" = "awaiting_automatic" | "awaiting_manual" | "soft_settled"> = {
85
+ type: "Settlement";
86
+ side: "destination";
87
+ chain: Chain;
88
+ title: string;
89
+ description: string;
90
+ /**
91
+ * Current status of the settlement step.
92
+ *
93
+ * - `inactive`: The settlement step is not yet active because a previous step must complete first.
94
+ * - `waiting_lp`: The swap is waiting for the intermediary (LP) to create or process the destination-side payout.
95
+ * - `awaiting_automatic`: The swap is waiting for automatic settlement by watchtowers.
96
+ * - `awaiting_manual`: The swap is ready for manual destination-side settlement by the user.
97
+ * - `soft_settled`: The user already received the payout, but the swap is not yet fully finalized on the source side.
98
+ * - `soft_expired`: The settlement should be treated as expired by the user, but it may still progress because of in-flight or background processing.
99
+ * - `settled`: The settlement completed successfully.
100
+ * - `expired`: Settlement is no longer possible because the swap expired or failed.
101
+ */
102
+ status: "inactive" | "waiting_lp" | "soft_expired" | "settled" | "expired" | AdditionalStatuses;
103
+ initTxId?: string;
104
+ settleTxId?: string;
105
+ };
106
+ /**
107
+ * Type guard for {@link SwapExecutionStepSettlement}
108
+ *
109
+ * @category Swap Steps
110
+ */
111
+ export declare function isSwapExecutionStepSettlement<Chain extends string = string>(obj: any, chain?: Chain): obj is SwapExecutionStepSettlement<Chain>;
112
+ /**
113
+ * Execution step describing a source-side refund path after a failed swap.
114
+ *
115
+ * @category Swap Steps
116
+ */
117
+ export type SwapExecutionStepRefund<Chain extends string = string> = {
118
+ type: "Refund";
119
+ side: "source";
120
+ chain: Chain;
121
+ title: string;
122
+ description: string;
123
+ /**
124
+ * Current status of the refund step.
125
+ *
126
+ * - `inactive`: The refund path is not currently available.
127
+ * - `awaiting`: The swap can be refunded and the user may perform the refund action.
128
+ * - `refunded`: The refund was completed successfully.
129
+ */
130
+ status: "inactive" | "awaiting" | "refunded";
131
+ refundTxId?: string;
132
+ };
133
+ /**
134
+ * Type guard for {@link SwapExecutionStepRefund}
135
+ *
136
+ * @category Swap Steps
137
+ */
138
+ export declare function isSwapExecutionStepRefund<Chain extends string = string>(obj: any, chain?: Chain): obj is SwapExecutionStepRefund<Chain>;
139
+ /**
140
+ * Union of all supported swap execution step variants.
141
+ *
142
+ * @category Swap Steps
143
+ */
144
+ export type SwapExecutionStep = SwapExecutionStepSetup | SwapExecutionStepPayment | SwapExecutionStepSettlement | SwapExecutionStepRefund;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSwapExecutionStepRefund = exports.isSwapExecutionStepSettlement = exports.isSwapExecutionStepPayment = exports.isSwapExecutionStepSetup = void 0;
4
+ /**
5
+ * Type guard for {@link SwapExecutionStepSetup}
6
+ *
7
+ * @category Swap Steps
8
+ */
9
+ function isSwapExecutionStepSetup(obj, chain) {
10
+ return typeof (obj) === "object" &&
11
+ obj.type === "Setup" &&
12
+ obj.side === "destination" &&
13
+ typeof (obj.chain) === "string" &&
14
+ (chain == null || obj.chain === chain) &&
15
+ typeof (obj.title) === "string" &&
16
+ typeof (obj.description) === "string" &&
17
+ (obj.status === "awaiting" ||
18
+ obj.status === "completed" ||
19
+ obj.status === "soft_expired" ||
20
+ obj.status === "expired");
21
+ }
22
+ exports.isSwapExecutionStepSetup = isSwapExecutionStepSetup;
23
+ /**
24
+ * Type guard for {@link SwapExecutionStepPayment}
25
+ *
26
+ * @category Swap Steps
27
+ */
28
+ function isSwapExecutionStepPayment(obj, chain) {
29
+ return typeof (obj) === "object" &&
30
+ obj.type === "Payment" &&
31
+ obj.side === "source" &&
32
+ typeof (obj.chain) === "string" &&
33
+ (chain == null || obj.chain === chain) &&
34
+ typeof (obj.title) === "string" &&
35
+ typeof (obj.description) === "string" &&
36
+ (obj.status === "inactive" ||
37
+ obj.status === "awaiting" ||
38
+ obj.status === "received" ||
39
+ obj.status === "confirmed" ||
40
+ obj.status === "soft_expired" ||
41
+ obj.status === "expired") &&
42
+ (obj.confirmations == null ||
43
+ (typeof (obj.confirmations) === "object" &&
44
+ typeof (obj.confirmations.current) === "number" &&
45
+ typeof (obj.confirmations.target) === "number" &&
46
+ typeof (obj.confirmations.etaSeconds) === "number"));
47
+ }
48
+ exports.isSwapExecutionStepPayment = isSwapExecutionStepPayment;
49
+ /**
50
+ * Type guard for {@link SwapExecutionStepSettlement}
51
+ *
52
+ * @category Swap Steps
53
+ */
54
+ function isSwapExecutionStepSettlement(obj, chain) {
55
+ return typeof (obj) === "object" &&
56
+ obj.type === "Settlement" &&
57
+ obj.side === "destination" &&
58
+ typeof (obj.chain) === "string" &&
59
+ (chain == null || obj.chain === chain) &&
60
+ typeof (obj.title) === "string" &&
61
+ typeof (obj.description) === "string" &&
62
+ (obj.status === "inactive" ||
63
+ obj.status === "waiting_lp" ||
64
+ obj.status === "awaiting_automatic" ||
65
+ obj.status === "awaiting_manual" ||
66
+ obj.status === "soft_settled" ||
67
+ obj.status === "soft_expired" ||
68
+ obj.status === "settled" ||
69
+ obj.status === "expired");
70
+ }
71
+ exports.isSwapExecutionStepSettlement = isSwapExecutionStepSettlement;
72
+ /**
73
+ * Type guard for {@link SwapExecutionStepRefund}
74
+ *
75
+ * @category Swap Steps
76
+ */
77
+ function isSwapExecutionStepRefund(obj, chain) {
78
+ return typeof (obj) === "object" &&
79
+ obj.type === "Refund" &&
80
+ obj.side === "source" &&
81
+ typeof (obj.chain) === "string" &&
82
+ (chain == null || obj.chain === chain) &&
83
+ typeof (obj.title) === "string" &&
84
+ typeof (obj.description) === "string" &&
85
+ (obj.status === "inactive" || obj.status === "awaiting" || obj.status === "refunded");
86
+ }
87
+ exports.isSwapExecutionStepRefund = isSwapExecutionStepRefund;
@@ -60,6 +60,12 @@ export type TokenAmount<T extends Token = Token, Known extends boolean = boolean
60
60
  */
61
61
  isUnknown: Known extends true ? false : true;
62
62
  };
63
+ /**
64
+ * Type guard for {@link TokenAmount}
65
+ *
66
+ * @category Tokens
67
+ */
68
+ export declare function isTokenAmount<T extends Token = Token, Known extends boolean = boolean>(obj: any, token?: T, known?: Known): obj is TokenAmount<T, Known>;
63
69
  /**
64
70
  * Factory function to create a TokenAmount
65
71
  *
@@ -1,7 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toTokenAmount = void 0;
3
+ exports.toTokenAmount = exports.isTokenAmount = void 0;
4
+ const Token_1 = require("./Token");
4
5
  const Utils_1 = require("../utils/Utils");
6
+ /**
7
+ * Type guard for {@link TokenAmount}
8
+ *
9
+ * @category Tokens
10
+ */
11
+ function isTokenAmount(obj, token, known) {
12
+ const hasExpectedKnownState = known == null
13
+ ? ((typeof (obj?.rawAmount) === "bigint" && obj?.isUnknown === false) ||
14
+ (obj?.rawAmount === undefined && obj?.isUnknown === true))
15
+ : known
16
+ ? typeof (obj?.rawAmount) === "bigint" && obj?.isUnknown === false
17
+ : obj?.rawAmount === undefined && obj?.isUnknown === true;
18
+ return obj != null &&
19
+ typeof (obj) === "object" &&
20
+ typeof (obj.amount) === "string" &&
21
+ typeof (obj._amount) === "number" &&
22
+ (token == null ? (0, Token_1.isToken)(obj.token) : token.equals(obj.token)) &&
23
+ typeof (obj.currentUsdValue) === "function" &&
24
+ typeof (obj.usdValue) === "function" &&
25
+ (obj.pastUsdValue == null || typeof (obj.pastUsdValue) === "number") &&
26
+ typeof (obj.toString) === "function" &&
27
+ hasExpectedKnownState;
28
+ }
29
+ exports.isTokenAmount = isTokenAmount;
5
30
  /**
6
31
  * Factory function to create a TokenAmount
7
32
  *
@@ -14,3 +14,5 @@ export declare function getDummyAddress(network: BTC_NETWORK, type: CoinselectAd
14
14
  * @param _psbt
15
15
  */
16
16
  export declare function parsePsbtTransaction(_psbt: Transaction | string): Transaction;
17
+ export declare function getVoutIndex(psbt: Transaction, network: BTC_NETWORK, address: string, amount: bigint): number | undefined;
18
+ export declare function getSenderAddress(psbt: Transaction, network: BTC_NETWORK, inputIndex?: number): string | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePsbtTransaction = exports.getDummyAddress = exports.getDummyOutputScript = exports.toCoinselectAddressType = exports.toOutputScript = exports.fromOutputScript = void 0;
3
+ exports.getSenderAddress = exports.getVoutIndex = exports.parsePsbtTransaction = exports.getDummyAddress = exports.getDummyOutputScript = exports.toCoinselectAddressType = exports.toOutputScript = exports.fromOutputScript = void 0;
4
4
  const utils_1 = require("@scure/btc-signer/utils");
5
5
  const buffer_1 = require("buffer");
6
6
  const btc_signer_1 = require("@scure/btc-signer");
@@ -139,3 +139,36 @@ function parsePsbtTransaction(_psbt) {
139
139
  }
140
140
  }
141
141
  exports.parsePsbtTransaction = parsePsbtTransaction;
142
+ function getVoutIndex(psbt, network, address, amount) {
143
+ const script = toOutputScript(network, address);
144
+ for (let i = 0; i < psbt.outputsLength; i++) {
145
+ const output = psbt.getOutput(i);
146
+ if (output.amount === amount &&
147
+ output.script != null &&
148
+ script.equals(buffer_1.Buffer.from(output.script))) {
149
+ return i;
150
+ }
151
+ }
152
+ }
153
+ exports.getVoutIndex = getVoutIndex;
154
+ function getSenderAddress(psbt, network, inputIndex = 0) {
155
+ if (psbt.inputsLength <= inputIndex)
156
+ return undefined;
157
+ const input = psbt.getInput(inputIndex);
158
+ let script;
159
+ if (input.witnessUtxo?.script != null) {
160
+ script = input.witnessUtxo.script;
161
+ }
162
+ else if (input.nonWitnessUtxo != null && input.index != null) {
163
+ script = input.nonWitnessUtxo.outputs[input.index]?.script;
164
+ }
165
+ if (script == null)
166
+ return undefined;
167
+ try {
168
+ return (0, btc_signer_1.Address)(network).encode(btc_signer_1.OutScript.decode(script));
169
+ }
170
+ catch (e) {
171
+ return buffer_1.Buffer.from(script).toString("hex");
172
+ }
173
+ }
174
+ exports.getSenderAddress = getSenderAddress;
@@ -51,8 +51,10 @@ export declare function mapToArray<K, V, Output>(map: Map<K, V>, translator: (ke
51
51
  * Creates a new abort controller that will abort if the passed abort signal aborts
52
52
  *
53
53
  * @param abortSignal
54
+ * @param timeoutSeconds
55
+ * @param timeoutMessage
54
56
  */
55
- export declare function extendAbortController(abortSignal?: AbortSignal): AbortController;
57
+ export declare function extendAbortController(abortSignal?: AbortSignal, timeoutSeconds?: number, timeoutMessage?: string): AbortController;
56
58
  export declare function bigIntMin(a: bigint, b: bigint): bigint;
57
59
  export declare function bigIntMin(a?: bigint, b?: bigint): bigint | undefined;
58
60
  export declare function bigIntMax(a: bigint, b: bigint): bigint;
@@ -96,13 +96,19 @@ exports.mapToArray = mapToArray;
96
96
  * Creates a new abort controller that will abort if the passed abort signal aborts
97
97
  *
98
98
  * @param abortSignal
99
+ * @param timeoutSeconds
100
+ * @param timeoutMessage
99
101
  */
100
- function extendAbortController(abortSignal) {
102
+ function extendAbortController(abortSignal, timeoutSeconds, timeoutMessage) {
101
103
  const _abortController = new AbortController();
102
104
  if (abortSignal != null) {
103
105
  abortSignal.throwIfAborted();
104
106
  abortSignal.onabort = () => _abortController.abort(abortSignal.reason);
105
107
  }
108
+ if (timeoutSeconds != null) {
109
+ const timeout = setTimeout(() => _abortController.abort(new Error(timeoutMessage ?? "Timed out")), timeoutSeconds * 1000);
110
+ _abortController.signal.addEventListener("abort", () => clearTimeout(timeout));
111
+ }
106
112
  return _abortController;
107
113
  }
108
114
  exports.extendAbortController = extendAbortController;
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@atomiqlabs/sdk",
3
- "version": "8.8.3",
3
+ "version": "8.9.0",
4
4
  "description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build:ts4": "npx -p typescript@4.9 tsc --noEmit",
10
- "build:ts5": "npx -p typescript@5.9 tsc --noEmit"
9
+ "build": "npx -y -p typescript@4.9 tsc",
10
+ "build:ts4": "npx -y -p typescript@4.9 tsc --noEmit",
11
+ "build:ts5": "npx -y -p typescript@5.9 tsc --noEmit"
11
12
  },
12
13
  "files": [
13
14
  "/dist",
14
- "/src"
15
+ "/src",
16
+ "/api"
15
17
  ],
16
18
  "keywords": [
17
19
  "Bitcoin",
@@ -28,6 +30,7 @@
28
30
  "@atomiqlabs/btc-mempool": "^1.0.4",
29
31
  "@atomiqlabs/messenger-nostr": "^2.0.0",
30
32
  "@noble/ciphers": "^1.2.1",
33
+ "@noble/curves": "^1.9.7",
31
34
  "@noble/hashes": "^1.7.1",
32
35
  "@scure/base": "^1.2.4",
33
36
  "@scure/bip32": "^2.0.1",