@btc-vision/transaction 1.0.44 → 1.0.45

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 (31) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/index.js +1 -1
  3. package/browser/transaction/TransactionFactory.d.ts +6 -2
  4. package/browser/transaction/builders/TransactionBuilder.d.ts +1 -0
  5. package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
  6. package/build/_version.d.ts +1 -1
  7. package/build/_version.js +1 -1
  8. package/build/tests/Regtest.js +1 -1
  9. package/build/tests/btc/send.d.ts +1 -0
  10. package/build/tests/btc/send.js +36 -0
  11. package/build/tests/moto/airdropToken.js +3 -3
  12. package/build/tests/test.js +1 -1
  13. package/build/tests/wbtc/transferReg.js +2 -2
  14. package/build/tests/wbtc/unwrapReg.js +1 -1
  15. package/build/tests/wbtc/withdrawalRequestReg.js +1 -1
  16. package/build/tests/wbtc/wrapReg.js +2 -3
  17. package/build/transaction/TransactionFactory.d.ts +6 -2
  18. package/build/transaction/TransactionFactory.js +37 -32
  19. package/build/transaction/builders/FundingTransaction.js +1 -1
  20. package/build/transaction/builders/TransactionBuilder.d.ts +1 -0
  21. package/build/transaction/builders/TransactionBuilder.js +21 -5
  22. package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
  23. package/build/transaction/shared/TweakedTransaction.js +0 -1
  24. package/package.json +2 -2
  25. package/src/_version.ts +1 -1
  26. package/src/transaction/TransactionFactory.ts +61 -51
  27. package/src/transaction/builders/FundingTransaction.ts +40 -40
  28. package/src/transaction/builders/InteractionTransaction.ts +1 -1
  29. package/src/transaction/builders/TransactionBuilder.ts +33 -5
  30. package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
  31. package/src/transaction/shared/TweakedTransaction.ts +0 -1
@@ -1,40 +1,40 @@
1
- import { TransactionType } from '../enums/TransactionType.js';
2
- import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
3
- import { Signer } from 'bitcoinjs-lib';
4
- import { TransactionBuilder } from './TransactionBuilder.js';
5
-
6
- export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
7
- public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
8
-
9
- protected childTransactionRequiredFees: bigint;
10
-
11
- constructor(parameters: IFundingTransactionParameters) {
12
- super(parameters);
13
-
14
- this.childTransactionRequiredFees = parameters.childTransactionRequiredValue;
15
-
16
- this.internalInit();
17
- }
18
-
19
- protected override async buildTransaction(): Promise<void> {
20
- if (!this.to) {
21
- throw new Error('Recipient address is required');
22
- }
23
-
24
- this.addInputsFromUTXO();
25
-
26
- const amountSpent: bigint =
27
- this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
28
-
29
- this.addOutput({
30
- value: Number(amountSpent),
31
- address: this.to,
32
- });
33
-
34
- await this.addRefundOutput(amountSpent);
35
- }
36
-
37
- protected override getSignerKey(): Signer {
38
- return this.signer;
39
- }
40
- }
1
+ import { TransactionType } from '../enums/TransactionType.js';
2
+ import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
3
+ import { Signer } from 'bitcoinjs-lib';
4
+ import { TransactionBuilder } from './TransactionBuilder.js';
5
+
6
+ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
7
+ public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
8
+
9
+ protected childTransactionRequiredFees: bigint;
10
+
11
+ constructor(parameters: IFundingTransactionParameters) {
12
+ super(parameters);
13
+
14
+ this.childTransactionRequiredFees = parameters.amount;
15
+
16
+ this.internalInit();
17
+ }
18
+
19
+ protected override async buildTransaction(): Promise<void> {
20
+ if (!this.to) {
21
+ throw new Error('Recipient address is required');
22
+ }
23
+
24
+ this.addInputsFromUTXO();
25
+
26
+ const amountSpent: bigint =
27
+ this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
28
+
29
+ this.addOutput({
30
+ value: Number(amountSpent),
31
+ address: this.to,
32
+ });
33
+
34
+ await this.addRefundOutput(amountSpent);
35
+ }
36
+
37
+ protected override getSignerKey(): Signer {
38
+ return this.signer;
39
+ }
40
+ }
@@ -31,7 +31,7 @@ export class InteractionTransaction extends SharedInteractionTransaction<Transac
31
31
  this.calldata,
32
32
  this.contractSecret,
33
33
  );
34
-
34
+
35
35
  this.scriptTree = this.getScriptTree();
36
36
  this.internalInit();
37
37
  }
@@ -182,8 +182,8 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
182
182
  }
183
183
 
184
184
  public async getFundingTransactionParameters(): Promise<IFundingTransactionParameters> {
185
- if (!this.transactionFee) {
186
- this.transactionFee = await this.estimateTransactionFees();
185
+ if (!this.estimatedFees) {
186
+ this.estimatedFees = await this.estimateTransactionFees();
187
187
  }
188
188
 
189
189
  return {
@@ -194,7 +194,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
194
194
  feeRate: this.feeRate,
195
195
  priorityFee: this.priorityFee,
196
196
  from: this.from,
197
- childTransactionRequiredValue: this.transactionFee,
197
+ amount: this.estimatedFees,
198
198
  };
199
199
  }
200
200
 
@@ -245,6 +245,34 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
245
245
  throw new Error('Could not sign transaction');
246
246
  }
247
247
 
248
+ /**
249
+ * @description Generates the transaction minimal signatures
250
+ * @public
251
+ */
252
+ public async generateTransactionMinimalSignatures(): Promise<void> {
253
+ if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
254
+ throw new Error(
255
+ 'Invalid contract address. The contract address must be a taproot address.',
256
+ );
257
+ }
258
+
259
+ await this.buildTransaction();
260
+
261
+ if (this.transaction.data.inputs.length === 0) {
262
+ const inputs: PsbtInputExtended[] = this.getInputs();
263
+ const outputs: PsbtOutputExtended[] = this.getOutputs();
264
+
265
+ this.transaction.setMaximumFeeRate(this._maximumFeeRate);
266
+ this.transaction.addInputs(inputs);
267
+
268
+ for (let i = 0; i < this.updateInputs.length; i++) {
269
+ this.transaction.updateInput(i, this.updateInputs[i]);
270
+ }
271
+
272
+ this.transaction.addOutputs(outputs);
273
+ }
274
+ }
275
+
248
276
  /**
249
277
  * @description Signs the transaction
250
278
  * @public
@@ -317,9 +345,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
317
345
 
318
346
  const builtTx = await this.internalBuildTransaction(fakeTx);
319
347
  if (builtTx) {
320
- const tx = fakeTx.extractTransaction(false);
348
+ const tx = fakeTx.extractTransaction(false, true);
321
349
  const size = tx.virtualSize();
322
- const fee: number = this.feeRate * size + 1;
350
+ const fee: number = this.feeRate * size;
323
351
 
324
352
  this.estimatedFees = BigInt(Math.ceil(fee) + 1);
325
353
 
@@ -17,7 +17,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
17
17
  }
18
18
 
19
19
  export interface IFundingTransactionParameters extends ITransactionParameters {
20
- childTransactionRequiredValue: bigint;
20
+ amount: bigint;
21
21
  }
22
22
 
23
23
  export interface SharedInteractionParameters extends ITransactionParameters {
@@ -424,7 +424,6 @@ export abstract class TweakedTransaction extends Logger {
424
424
  try {
425
425
  await this.signInput(transaction, input, i);
426
426
  } catch (e) {
427
- console.log(e);
428
427
  this.log(`Failed to sign input ${i}: ${(e as Error).stack}`);
429
428
  }
430
429
  }