@btc-vision/transaction 1.5.2 → 1.5.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 (32) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/ABICoder.d.ts +1 -0
  3. package/browser/buffer/BinaryWriter.d.ts +1 -1
  4. package/browser/index.js +1 -1
  5. package/browser/transaction/browser/types/Unisat.d.ts +1 -1
  6. package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -0
  7. package/browser/transaction/shared/TweakedTransaction.d.ts +5 -1
  8. package/build/_version.d.ts +1 -1
  9. package/build/_version.js +1 -1
  10. package/build/abi/ABICoder.d.ts +1 -0
  11. package/build/abi/ABICoder.js +4 -0
  12. package/build/buffer/BinaryWriter.d.ts +1 -1
  13. package/build/buffer/BinaryWriter.js +11 -9
  14. package/build/keypair/AddressVerificator.js +3 -1
  15. package/build/keypair/EcKeyPair.js +5 -5
  16. package/build/transaction/browser/types/Unisat.d.ts +1 -1
  17. package/build/transaction/builders/DeploymentTransaction.js +4 -4
  18. package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
  19. package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
  20. package/build/transaction/shared/TweakedTransaction.d.ts +5 -1
  21. package/build/transaction/shared/TweakedTransaction.js +24 -19
  22. package/package.json +10 -10
  23. package/src/_version.ts +1 -1
  24. package/src/abi/ABICoder.ts +4 -0
  25. package/src/buffer/BinaryWriter.ts +13 -11
  26. package/src/keypair/AddressVerificator.ts +5 -1
  27. package/src/keypair/EcKeyPair.ts +5 -5
  28. package/src/transaction/browser/types/Unisat.ts +1 -1
  29. package/src/transaction/builders/DeploymentTransaction.ts +4 -4
  30. package/src/transaction/builders/SharedInteractionTransaction.ts +4 -4
  31. package/src/transaction/interfaces/ITransactionParameters.ts +1 -0
  32. package/src/transaction/shared/TweakedTransaction.ts +37 -19
@@ -10,6 +10,7 @@ import {
10
10
  isP2TR,
11
11
  isP2WPKH,
12
12
  isP2WSHScript,
13
+ isUnknownSegwitVersion,
13
14
  Network,
14
15
  opcodes,
15
16
  P2TRPayment,
@@ -43,6 +44,8 @@ export interface ITweakedTransactionData {
43
44
  readonly network: Network;
44
45
  readonly chainId?: ChainId;
45
46
  readonly nonWitnessUtxo?: Buffer;
47
+ readonly noSignatures?: boolean;
48
+ readonly unlockScript?: Buffer[];
46
49
  }
47
50
 
48
51
  /**
@@ -126,6 +129,8 @@ export abstract class TweakedTransaction extends Logger {
126
129
 
127
130
  protected regenerated: boolean = false;
128
131
  protected ignoreSignatureErrors: boolean = false;
132
+ protected noSignatures: boolean = false;
133
+ protected unlockScript: Buffer[] | undefined;
129
134
 
130
135
  protected constructor(data: ITweakedTransactionData) {
131
136
  super();
@@ -133,7 +138,9 @@ export abstract class TweakedTransaction extends Logger {
133
138
  this.signer = data.signer;
134
139
  this.network = data.network;
135
140
 
141
+ this.noSignatures = data.noSignatures || false;
136
142
  this.nonWitnessUtxo = data.nonWitnessUtxo;
143
+ this.unlockScript = data.unlockScript;
137
144
 
138
145
  this.isBrowser = typeof window !== 'undefined';
139
146
  }
@@ -476,27 +483,29 @@ export abstract class TweakedTransaction extends Logger {
476
483
  const batchSize: number = 20;
477
484
  const batches = this.splitArray(txs, batchSize);
478
485
 
479
- for (let i = 0; i < batches.length; i++) {
480
- const batch = batches[i];
481
- const promises: Promise<void>[] = [];
482
- const offset = i * batchSize;
486
+ if (!this.noSignatures) {
487
+ for (let i = 0; i < batches.length; i++) {
488
+ const batch = batches[i];
489
+ const promises: Promise<void>[] = [];
490
+ const offset = i * batchSize;
483
491
 
484
- for (let j = 0; j < batch.length; j++) {
485
- const index = offset + j;
486
- const input = batch[j];
492
+ for (let j = 0; j < batch.length; j++) {
493
+ const index = offset + j;
494
+ const input = batch[j];
487
495
 
488
- try {
489
- promises.push(this.signInput(transaction, input, index, this.signer));
490
- } catch (e) {
491
- this.log(`Failed to sign input ${index}: ${(e as Error).stack}`);
496
+ try {
497
+ promises.push(this.signInput(transaction, input, index, this.signer));
498
+ } catch (e) {
499
+ this.log(`Failed to sign input ${index}: ${(e as Error).stack}`);
500
+ }
492
501
  }
493
- }
494
502
 
495
- await Promise.all(promises);
503
+ await Promise.all(promises);
504
+ }
496
505
  }
497
506
 
498
507
  for (let i = 0; i < transaction.data.inputs.length; i++) {
499
- transaction.finalizeInput(i, this.customFinalizerP2SH);
508
+ transaction.finalizeInput(i, this.customFinalizerP2SH.bind(this));
500
509
  }
501
510
 
502
511
  this.finalized = true;
@@ -654,14 +663,14 @@ export abstract class TweakedTransaction extends Logger {
654
663
  * Generate the PSBT input extended, supporting various script types
655
664
  * @param {UTXO} utxo The UTXO
656
665
  * @param {number} i The index of the input
657
- * @param {UTXO} extra Extra UTXO
666
+ * @param {UTXO} _extra Extra UTXO
658
667
  * @protected
659
668
  * @returns {PsbtInputExtended} The PSBT input extended
660
669
  */
661
670
  protected generatePsbtInputExtended(
662
671
  utxo: UTXO,
663
672
  i: number,
664
- extra: boolean = false,
673
+ _extra: boolean = false,
665
674
  ): PsbtInputExtended {
666
675
  const script = Buffer.from(utxo.scriptPubKey.hex, 'hex');
667
676
 
@@ -689,7 +698,7 @@ export abstract class TweakedTransaction extends Logger {
689
698
  }
690
699
 
691
700
  // Handle P2WPKH (SegWit)
692
- else if (isP2WPKH(script)) {
701
+ else if (isP2WPKH(script) || isUnknownSegwitVersion(script)) {
693
702
  // No redeemScript required for pure P2WPKH
694
703
  // witnessUtxo is enough, no nonWitnessUtxo needed.
695
704
  }
@@ -849,7 +858,16 @@ export abstract class TweakedTransaction extends Logger {
849
858
  };
850
859
  }
851
860
 
852
- return getFinalScripts(inputIndex, input, scriptA, isSegwit, isP2SH, isP2WSH);
861
+ return getFinalScripts(
862
+ inputIndex,
863
+ input,
864
+ scriptA,
865
+ isSegwit,
866
+ isP2SH,
867
+ isP2WSH,
868
+ true,
869
+ this.unlockScript,
870
+ );
853
871
  };
854
872
 
855
873
  protected async signInputsWalletBased(transaction: Psbt): Promise<void> {
@@ -860,7 +878,7 @@ export abstract class TweakedTransaction extends Logger {
860
878
 
861
879
  // Then, we finalize every input.
862
880
  for (let i = 0; i < transaction.data.inputs.length; i++) {
863
- transaction.finalizeInput(i, this.customFinalizerP2SH);
881
+ transaction.finalizeInput(i, this.customFinalizerP2SH.bind(this));
864
882
  }
865
883
 
866
884
  this.finalized = true;