@atomicfinance/bitcoin-dlc-provider 4.0.2 → 4.1.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.
@@ -1,7 +1,5 @@
1
- /// <reference types="node" />
2
1
  import Provider from '@atomicfinance/provider';
3
- import { AddSignaturesToRefundTxRequest, AddSignaturesToRefundTxResponse, AddSignatureToFundTransactionRequest, AddSignatureToFundTransactionResponse, CreateBatchDlcTransactionsRequest, CreateBatchDlcTransactionsResponse, CreateBatchFundTransactionRequest, CreateBatchFundTransactionResponse, CreateCetAdaptorSignatureRequest, CreateCetAdaptorSignatureResponse, CreateCetAdaptorSignaturesRequest, CreateCetAdaptorSignaturesResponse, CreateCetRequest, CreateCetResponse, CreateDlcTransactionsRequest, CreateDlcTransactionsResponse, CreateFundTransactionRequest, CreateFundTransactionResponse, CreateRefundTransactionRequest, CreateRefundTransactionResponse, CreateSplicedDlcTransactionsRequest, CreateSplicedDlcTransactionsResponse, DlcInputInfoRequest, DlcProvider, GetRawDlcFundingInputSignatureRequest, GetRawDlcFundingInputSignatureResponse, GetRawFundTxSignatureRequest, GetRawFundTxSignatureResponse, GetRawRefundTxSignatureRequest, GetRawRefundTxSignatureResponse, Input, Messages, PayoutRequest, SignCetRequest, SignCetResponse, SignDlcFundingInputRequest, SignDlcFundingInputResponse, SignFundTransactionRequest, SignFundTransactionResponse, VerifyCetAdaptorSignatureRequest, VerifyCetAdaptorSignatureResponse, VerifyCetAdaptorSignaturesRequest, VerifyCetAdaptorSignaturesResponse, VerifyDlcFundingInputSignatureRequest, VerifyDlcFundingInputSignatureResponse, VerifyFundTxSignatureRequest, VerifyFundTxSignatureResponse, VerifyRefundTxSignatureRequest, VerifyRefundTxSignatureResponse } from '@atomicfinance/types';
4
- import { InputSupplementationMode } from '@atomicfinance/types/lib/models/Input';
2
+ import { AddSignaturesToRefundTxRequest, AddSignaturesToRefundTxResponse, AddSignatureToFundTransactionRequest, AddSignatureToFundTransactionResponse, CreateBatchDlcTransactionsRequest, CreateBatchDlcTransactionsResponse, CreateBatchFundTransactionRequest, CreateBatchFundTransactionResponse, CreateCetAdaptorSignatureRequest, CreateCetAdaptorSignatureResponse, CreateCetAdaptorSignaturesRequest, CreateCetAdaptorSignaturesResponse, CreateCetRequest, CreateCetResponse, CreateDlcTransactionsRequest, CreateDlcTransactionsResponse, CreateFundTransactionRequest, CreateFundTransactionResponse, CreateRefundTransactionRequest, CreateRefundTransactionResponse, CreateSplicedDlcTransactionsRequest, CreateSplicedDlcTransactionsResponse, DlcInputInfoRequest, DlcProvider, GetRawDlcFundingInputSignatureRequest, GetRawDlcFundingInputSignatureResponse, GetRawFundTxSignatureRequest, GetRawFundTxSignatureResponse, GetRawRefundTxSignatureRequest, GetRawRefundTxSignatureResponse, Input, InputSupplementationMode, Messages, PayoutRequest, SignCetRequest, SignCetResponse, SignDlcFundingInputRequest, SignDlcFundingInputResponse, SignFundTransactionRequest, SignFundTransactionResponse, VerifyCetAdaptorSignatureRequest, VerifyCetAdaptorSignatureResponse, VerifyCetAdaptorSignaturesRequest, VerifyCetAdaptorSignaturesResponse, VerifyDlcFundingInputSignatureRequest, VerifyDlcFundingInputSignatureResponse, VerifyFundTxSignatureRequest, VerifyFundTxSignatureResponse, VerifyRefundTxSignatureRequest, VerifyRefundTxSignatureResponse } from '@atomicfinance/types';
5
3
  import { Tx } from '@node-dlc/bitcoin';
6
4
  import { CetAdaptorSignatures, ContractInfo, DlcAccept, DlcClose, DlcCloseMetadata, DlcOffer, DlcSign, DlcTransactions, FundingInput, HyperbolaPayoutCurvePiece, NumericalDescriptor, OracleAttestation, PolynomialPayoutCurvePiece } from '@node-dlc/messaging';
7
5
  import { BitcoinNetwork } from 'bitcoin-networks';
@@ -15,20 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  const provider_1 = __importDefault(require("@atomicfinance/provider"));
30
40
  const types_1 = require("@atomicfinance/types");
31
- const Input_1 = require("@atomicfinance/types/lib/models/Input");
32
41
  const utils_1 = require("@atomicfinance/utils");
33
42
  const bitcoin_1 = require("@node-dlc/bitcoin");
34
43
  const bufio_1 = require("@node-dlc/bufio");
@@ -72,7 +81,7 @@ class BitcoinDlcProvider extends provider_1.default {
72
81
  return Buffer.from(keyPair.privateKey).toString('hex');
73
82
  }
74
83
  }
75
- catch (error) {
84
+ catch {
76
85
  continue;
77
86
  }
78
87
  }
@@ -98,7 +107,7 @@ class BitcoinDlcProvider extends provider_1.default {
98
107
  }
99
108
  }
100
109
  }
101
- catch (error) {
110
+ catch {
102
111
  continue;
103
112
  }
104
113
  }
@@ -149,11 +158,11 @@ class BitcoinDlcProvider extends provider_1.default {
149
158
  /**
150
159
  * Get inputs for amount with explicit supplementation control
151
160
  */
152
- async GetInputsForAmountWithMode(amounts, feeRatePerVb, fixedInputs = [], supplementation = Input_1.InputSupplementationMode.Required) {
161
+ async GetInputsForAmountWithMode(amounts, feeRatePerVb, fixedInputs = [], supplementation = types_1.InputSupplementationMode.Required) {
153
162
  if (amounts.length === 0)
154
163
  return [];
155
164
  // For "none" mode, use exactly the provided inputs
156
- if (supplementation === Input_1.InputSupplementationMode.None) {
165
+ if (supplementation === types_1.InputSupplementationMode.None) {
157
166
  return fixedInputs;
158
167
  }
159
168
  // For "required" and "optional" modes, attempt supplementation
@@ -165,7 +174,7 @@ class BitcoinDlcProvider extends provider_1.default {
165
174
  }
166
175
  catch (e) {
167
176
  const errorMessage = e instanceof Error ? e.message : 'Unknown error';
168
- if (supplementation === Input_1.InputSupplementationMode.Required) {
177
+ if (supplementation === types_1.InputSupplementationMode.Required) {
169
178
  throw Error(`Not enough balance GetInputsForAmountWithMode. Error: ${errorMessage}`);
170
179
  }
171
180
  else {
@@ -195,7 +204,7 @@ class BitcoinDlcProvider extends provider_1.default {
195
204
  }
196
205
  return inputs;
197
206
  }
198
- async Initialize(collateral, feeRatePerVb, fixedInputs, inputSupplementationMode = Input_1.InputSupplementationMode.Required) {
207
+ async Initialize(collateral, feeRatePerVb, fixedInputs, inputSupplementationMode = types_1.InputSupplementationMode.Required) {
199
208
  const network = await this.getConnectedNetwork();
200
209
  const payoutAddress = await this.client.wallet.getUnusedAddress(false);
201
210
  const payoutSPK = bitcoinjs_lib_1.address.toOutputScript(payoutAddress.address, network);
@@ -222,7 +231,7 @@ class BitcoinDlcProvider extends provider_1.default {
222
231
  }
223
232
  async BatchInitialize(collaterals, feeRatePerVb, fixedInputs) {
224
233
  const network = await this.getConnectedNetwork();
225
- const inputs = await this.GetInputsForAmountWithMode(collaterals, feeRatePerVb, fixedInputs, Input_1.InputSupplementationMode.Required);
234
+ const inputs = await this.GetInputsForAmountWithMode(collaterals, feeRatePerVb, fixedInputs, types_1.InputSupplementationMode.Required);
226
235
  const fundingInputs = await Promise.all(inputs.map(async (input) => {
227
236
  return this.inputToFundingInput(input);
228
237
  }));
@@ -1626,7 +1635,7 @@ Payout Group not found even with brute force search');
1626
1635
  }
1627
1636
  else {
1628
1637
  // Handle Input[] through existing Initialize() flow
1629
- const initResult = await this.Initialize(offerCollateralSatoshis, feeRatePerVb, fixedInputs, inputSupplementationMode || Input_1.InputSupplementationMode.Required);
1638
+ const initResult = await this.Initialize(offerCollateralSatoshis, feeRatePerVb, fixedInputs, inputSupplementationMode || types_1.InputSupplementationMode.Required);
1630
1639
  fundingPubKey = initResult.fundingPubKey;
1631
1640
  payoutSPK = initResult.payoutSPK;
1632
1641
  payoutSerialId = initResult.payoutSerialId;
@@ -1792,8 +1801,8 @@ Payout Group not found even with brute force search');
1792
1801
  // Use InputSupplementationMode.None when fixed inputs are provided
1793
1802
  // to avoid wallet lookup issues with unusual addresses
1794
1803
  const supplementationMode = fixedInputs && fixedInputs.length > 0
1795
- ? Input_1.InputSupplementationMode.None
1796
- : Input_1.InputSupplementationMode.Required;
1804
+ ? types_1.InputSupplementationMode.None
1805
+ : types_1.InputSupplementationMode.Required;
1797
1806
  initResult = await this.Initialize(acceptCollateralSatoshis, dlcOffer.feeRatePerVb, fixedInputs, supplementationMode);
1798
1807
  }
1799
1808
  fundingPubKey = initResult.fundingPubKey;
@@ -1812,10 +1821,10 @@ Payout Group not found even with brute force search');
1812
1821
  dlcAccept.acceptCollateral = acceptCollateralSatoshis;
1813
1822
  dlcAccept.fundingPubkey = fundingPubKey;
1814
1823
  dlcAccept.payoutSpk = payoutSPK;
1815
- dlcAccept.payoutSerialId = dlcAccept.payoutSerialId = payoutSerialId;
1824
+ dlcAccept.payoutSerialId = payoutSerialId;
1816
1825
  dlcAccept.fundingInputs = fundingInputs;
1817
1826
  dlcAccept.changeSpk = changeSPK;
1818
- dlcAccept.changeSerialId = dlcAccept.changeSerialId = changeSerialId;
1827
+ dlcAccept.changeSerialId = changeSerialId;
1819
1828
  (0, assert_1.default)(dlcAccept.changeSerialId !== dlcOffer.fundOutputSerialId, 'changeSerialId cannot equal the fundOutputSerialId');
1820
1829
  (0, assert_1.default)(dlcOffer.payoutSerialId !== dlcAccept.payoutSerialId, 'offer.payoutSerialId cannot equal accept.payoutSerialId');
1821
1830
  (0, assert_1.default)((() => {
@@ -2126,7 +2135,7 @@ Payout Group not found even with brute force search');
2126
2135
  // Initiate and build PSBT
2127
2136
  let inputs = _inputs;
2128
2137
  if (!_inputs) {
2129
- const tempInputs = await this.GetInputsForAmountWithMode([BigInt(20000)], dlcOffer.feeRatePerVb, _inputs || [], Input_1.InputSupplementationMode.Required);
2138
+ const tempInputs = await this.GetInputsForAmountWithMode([BigInt(20000)], dlcOffer.feeRatePerVb, _inputs || [], types_1.InputSupplementationMode.Required);
2130
2139
  _inputs = tempInputs;
2131
2140
  }
2132
2141
  // Ensure all inputs have derivation paths by fetching from wallet
@@ -2587,12 +2596,12 @@ Payout Group not found even with brute force search');
2587
2596
  try {
2588
2597
  txRaw = await this.getMethod('getRawTransactionByHash')(input.txid);
2589
2598
  }
2590
- catch (e) {
2599
+ catch {
2591
2600
  try {
2592
2601
  txRaw = (await this.getMethod('jsonrpc')('gettransaction', input.txid))
2593
2602
  .hex;
2594
2603
  }
2595
- catch (e) {
2604
+ catch {
2596
2605
  throw Error(`Cannot find tx ${input.txid} in inputToFundingInput using getrawtransactionbyhash or gettransaction`);
2597
2606
  }
2598
2607
  }