@btc-vision/transaction 1.1.0 → 1.1.1

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.
@@ -47,7 +47,7 @@ export declare abstract class TweakedTransaction extends Logger {
47
47
  protected generateTapData(): Payment;
48
48
  protected generateScriptAddress(): Payment;
49
49
  protected getSignerKey(): Signer | ECPairInterface;
50
- protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer?: Signer | ECPairInterface): Promise<void>;
50
+ protected signInput(transaction: Psbt, _input: PsbtInput, i: number, signer: Signer | ECPairInterface): Promise<void>;
51
51
  protected splitArray<T>(arr: T[], chunkSize: number): T[][];
52
52
  protected signInputs(transaction: Psbt): Promise<void>;
53
53
  protected internalPubKeyToXOnly(): Buffer;
@@ -1 +1 @@
1
- export declare const version = "1.1.0";
1
+ export declare const version = "1.1.1";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.1.0';
1
+ export const version = '1.1.1';
@@ -47,7 +47,7 @@ export declare abstract class TweakedTransaction extends Logger {
47
47
  protected generateTapData(): Payment;
48
48
  protected generateScriptAddress(): Payment;
49
49
  protected getSignerKey(): Signer | ECPairInterface;
50
- protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer?: Signer | ECPairInterface): Promise<void>;
50
+ protected signInput(transaction: Psbt, _input: PsbtInput, i: number, signer: Signer | ECPairInterface): Promise<void>;
51
51
  protected splitArray<T>(arr: T[], chunkSize: number): T[][];
52
52
  protected signInputs(transaction: Psbt): Promise<void>;
53
53
  protected internalPubKeyToXOnly(): Buffer;
@@ -156,55 +156,22 @@ export class TweakedTransaction extends Logger {
156
156
  getSignerKey() {
157
157
  return this.signer;
158
158
  }
159
- async signInput(transaction, input, i, signer) {
160
- const signHash = this.sighashTypes && this.sighashTypes.length
161
- ? [TweakedTransaction.calculateSignHash(this.sighashTypes)]
162
- : undefined;
163
- signer = signer || this.getSignerKey();
164
- let testedTap = false;
165
- if (input.tapInternalKey) {
166
- if (!this.tweakedSigner)
167
- this.tweakSigner();
168
- let tweakedSigner;
169
- if (signer !== this.signer) {
170
- tweakedSigner = this.getTweakedSigner(true, signer);
171
- }
172
- else {
173
- tweakedSigner = this.tweakedSigner;
174
- }
175
- if (tweakedSigner) {
176
- testedTap = true;
177
- try {
178
- if ('signTaprootInput' in signer) {
179
- return await signer.signTaprootInput(transaction, i, signHash);
180
- }
181
- else {
182
- transaction.signTaprootInput(i, tweakedSigner, undefined, signHash);
183
- }
184
- return;
185
- }
186
- catch { }
187
- }
188
- }
159
+ async signInput(transaction, _input, i, signer) {
189
160
  try {
190
161
  if ('signInput' in signer) {
191
- return await signer.signInput(transaction, i, signHash);
192
- }
193
- else {
194
- transaction.signInput(i, signer, signHash);
162
+ return await signer.signInput(transaction, i);
195
163
  }
164
+ transaction.signInput(i, signer);
196
165
  }
197
- catch (e) {
198
- if (!testedTap) {
166
+ catch {
167
+ try {
199
168
  if ('signTaprootInput' in signer) {
200
- return await signer.signTaprootInput(transaction, i, signHash);
201
- }
202
- else if (this.tweakedSigner) {
203
- transaction.signTaprootInput(i, this.tweakedSigner, undefined, signHash);
204
- }
205
- else {
206
- throw e;
169
+ return await signer.signTaprootInput(transaction, i);
207
170
  }
171
+ transaction.signTaprootInput(i, signer);
172
+ }
173
+ catch {
174
+ throw new Error('Failed to sign input');
208
175
  }
209
176
  }
210
177
  }
@@ -230,7 +197,7 @@ export class TweakedTransaction extends Logger {
230
197
  const index = offset + j;
231
198
  const input = batch[j];
232
199
  try {
233
- promises.push(this.signInput(transaction, input, index));
200
+ promises.push(this.signInput(transaction, input, index, this.signer));
234
201
  }
235
202
  catch (e) {
236
203
  this.log(`Failed to sign input ${index}: ${e.stack}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.1.0';
1
+ export const version = '1.1.1';
@@ -358,18 +358,38 @@ export abstract class TweakedTransaction extends Logger {
358
358
  /**
359
359
  * Signs an input of the transaction.
360
360
  * @param {Psbt} transaction - The transaction to sign
361
- * @param {PsbtInput} input - The input to sign
361
+ * @param {PsbtInput} _input - The input to sign
362
362
  * @param {number} i - The index of the input
363
- * @param {Signer} [signer] - The signer to use
363
+ * @param {Signer} signer - The signer to use
364
364
  * @protected
365
365
  */
366
366
  protected async signInput(
367
367
  transaction: Psbt,
368
- input: PsbtInput,
368
+ _input: PsbtInput,
369
369
  i: number,
370
- signer?: Signer | ECPairInterface,
370
+ signer: Signer | ECPairInterface,
371
371
  ): Promise<void> {
372
- const signHash =
372
+ try {
373
+ if ('signInput' in signer) {
374
+ // @ts-expect-error - we know it's a signer
375
+ return await (signer.signInput(transaction, i) as Promise<void>);
376
+ }
377
+
378
+ transaction.signInput(i, signer);
379
+ } catch {
380
+ try {
381
+ if ('signTaprootInput' in signer) {
382
+ // @ts-expect-error - we know it's a taproot signer
383
+ return await (signer.signTaprootInput(transaction, i) as Promise<void>);
384
+ }
385
+
386
+ transaction.signTaprootInput(i, signer);
387
+ } catch {
388
+ throw new Error('Failed to sign input');
389
+ }
390
+ }
391
+
392
+ /*const signHash =
373
393
  this.sighashTypes && this.sighashTypes.length
374
394
  ? [TweakedTransaction.calculateSignHash(this.sighashTypes)]
375
395
  : undefined;
@@ -431,7 +451,7 @@ export abstract class TweakedTransaction extends Logger {
431
451
  throw e;
432
452
  }
433
453
  }
434
- }
454
+ }*/
435
455
  }
436
456
 
437
457
  protected splitArray<T>(arr: T[], chunkSize: number): T[][] {
@@ -470,7 +490,7 @@ export abstract class TweakedTransaction extends Logger {
470
490
  const input = batch[j];
471
491
 
472
492
  try {
473
- promises.push(this.signInput(transaction, input, index));
493
+ promises.push(this.signInput(transaction, input, index, this.signer));
474
494
  } catch (e) {
475
495
  this.log(`Failed to sign input ${index}: ${(e as Error).stack}`);
476
496
  }