@btc-vision/transaction 1.7.17 → 1.7.19

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.
@@ -14,17 +14,20 @@ export interface DeploymentResult {
14
14
  readonly contractPubKey: string;
15
15
  readonly challenge: RawChallenge;
16
16
  readonly utxos: UTXO[];
17
+ readonly inputUtxos: UTXO[];
17
18
  }
18
19
  export interface FundingTransactionResponse {
19
20
  readonly tx: Transaction;
20
21
  readonly original: FundingTransaction;
21
22
  readonly estimatedFees: bigint;
22
23
  readonly nextUTXOs: UTXO[];
24
+ readonly inputUtxos: UTXO[];
23
25
  }
24
26
  export interface BitcoinTransferBase {
25
27
  readonly tx: string;
26
28
  readonly estimatedFees: bigint;
27
29
  readonly nextUTXOs: UTXO[];
30
+ readonly inputUtxos: UTXO[];
28
31
  }
29
32
  export interface InteractionResponse {
30
33
  readonly fundingTransaction: string | null;
@@ -32,6 +35,7 @@ export interface InteractionResponse {
32
35
  readonly estimatedFees: bigint;
33
36
  readonly nextUTXOs: UTXO[];
34
37
  readonly fundingUTXOs: UTXO[];
38
+ readonly fundingInputUtxos: UTXO[];
35
39
  readonly challenge: RawChallenge;
36
40
  readonly interactionAddress: string | null;
37
41
  readonly compiledTargetScript: string | null;
@@ -42,6 +46,7 @@ export interface BitcoinTransferResponse extends BitcoinTransferBase {
42
46
  export interface CancelledTransaction {
43
47
  readonly transaction: string;
44
48
  readonly nextUTXOs: UTXO[];
49
+ readonly inputUtxos: UTXO[];
45
50
  }
46
51
  export declare class TransactionFactory {
47
52
  debug: boolean;
@@ -50,7 +55,7 @@ export declare class TransactionFactory {
50
55
  private readonly INITIAL_FUNDING_ESTIMATE;
51
56
  private readonly MAX_ITERATIONS;
52
57
  createCancellableTransaction(params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner): Promise<CancelledTransaction>;
53
- createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[]]>;
58
+ createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[], UTXO[]]>;
54
59
  signInteraction(interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner): Promise<InteractionResponse>;
55
60
  signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
56
61
  createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
@@ -1 +1 @@
1
- export declare const version = "1.7.17";
1
+ export declare const version = "1.7.18";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.7.17';
1
+ export const version = '1.7.18';
@@ -14,17 +14,20 @@ export interface DeploymentResult {
14
14
  readonly contractPubKey: string;
15
15
  readonly challenge: RawChallenge;
16
16
  readonly utxos: UTXO[];
17
+ readonly inputUtxos: UTXO[];
17
18
  }
18
19
  export interface FundingTransactionResponse {
19
20
  readonly tx: Transaction;
20
21
  readonly original: FundingTransaction;
21
22
  readonly estimatedFees: bigint;
22
23
  readonly nextUTXOs: UTXO[];
24
+ readonly inputUtxos: UTXO[];
23
25
  }
24
26
  export interface BitcoinTransferBase {
25
27
  readonly tx: string;
26
28
  readonly estimatedFees: bigint;
27
29
  readonly nextUTXOs: UTXO[];
30
+ readonly inputUtxos: UTXO[];
28
31
  }
29
32
  export interface InteractionResponse {
30
33
  readonly fundingTransaction: string | null;
@@ -32,6 +35,7 @@ export interface InteractionResponse {
32
35
  readonly estimatedFees: bigint;
33
36
  readonly nextUTXOs: UTXO[];
34
37
  readonly fundingUTXOs: UTXO[];
38
+ readonly fundingInputUtxos: UTXO[];
35
39
  readonly challenge: RawChallenge;
36
40
  readonly interactionAddress: string | null;
37
41
  readonly compiledTargetScript: string | null;
@@ -42,6 +46,7 @@ export interface BitcoinTransferResponse extends BitcoinTransferBase {
42
46
  export interface CancelledTransaction {
43
47
  readonly transaction: string;
44
48
  readonly nextUTXOs: UTXO[];
49
+ readonly inputUtxos: UTXO[];
45
50
  }
46
51
  export declare class TransactionFactory {
47
52
  debug: boolean;
@@ -50,7 +55,7 @@ export declare class TransactionFactory {
50
55
  private readonly INITIAL_FUNDING_ESTIMATE;
51
56
  private readonly MAX_ITERATIONS;
52
57
  createCancellableTransaction(params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner): Promise<CancelledTransaction>;
53
- createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[]]>;
58
+ createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[], UTXO[]]>;
54
59
  signInteraction(interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner): Promise<InteractionResponse>;
55
60
  signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
56
61
  createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
@@ -14,10 +14,7 @@ export class TransactionFactory {
14
14
  constructor() {
15
15
  this.debug = false;
16
16
  this.DUMMY_PUBKEY = Buffer.alloc(32, 1);
17
- this.P2TR_SCRIPT = Buffer.concat([
18
- Buffer.from([0x51, 0x20]),
19
- this.DUMMY_PUBKEY,
20
- ]);
17
+ this.P2TR_SCRIPT = Buffer.concat([Buffer.from([0x51, 0x20]), this.DUMMY_PUBKEY]);
21
18
  this.INITIAL_FUNDING_ESTIMATE = 2000n;
22
19
  this.MAX_ITERATIONS = 10;
23
20
  }
@@ -44,6 +41,7 @@ export class TransactionFactory {
44
41
  return {
45
42
  transaction: rawTx,
46
43
  nextUTXOs: this.getUTXOAsTransaction(signed, params.from, 0),
44
+ inputUtxos: params.utxos,
47
45
  };
48
46
  }
49
47
  async createCustomScriptTransaction(interactionParameters) {
@@ -101,6 +99,7 @@ export class TransactionFactory {
101
99
  signedTransaction.tx.toHex(),
102
100
  outTx.toHex(),
103
101
  this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
102
+ interactionParameters.utxos,
104
103
  ];
105
104
  }
106
105
  async signInteraction(interactionParameters) {
@@ -174,6 +173,7 @@ export class TransactionFactory {
174
173
  nextUTXOs: this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
175
174
  challenge: challenge.toRaw(),
176
175
  fundingUTXOs: fundingUTXO,
176
+ fundingInputUtxos: interactionParameters.utxos,
177
177
  compiledTargetScript: interactionTx.exportCompiledTargetScript().toString('hex'),
178
178
  };
179
179
  }
@@ -254,6 +254,7 @@ export class TransactionFactory {
254
254
  contractPubKey: deploymentTx.contractPubKey,
255
255
  utxos: [refundUTXO],
256
256
  challenge: challenge.toRaw(),
257
+ inputUtxos: deploymentParameters.utxos,
257
258
  };
258
259
  }
259
260
  async createBTCTransfer(parameters) {
@@ -266,6 +267,7 @@ export class TransactionFactory {
266
267
  original: resp.original,
267
268
  tx: resp.tx.toHex(),
268
269
  nextUTXOs: this.getAllNewUTXOs(resp.original, resp.tx, parameters.from),
270
+ inputUtxos: parameters.utxos,
269
271
  };
270
272
  }
271
273
  getAllNewUTXOs(original, tx, to) {
@@ -314,7 +316,10 @@ export class TransactionFactory {
314
316
  if (!interaction) {
315
317
  throw new Error('Could not sign interaction transaction.');
316
318
  }
317
- return interaction;
319
+ return {
320
+ ...interaction,
321
+ inputUtxos: interaction.inputUtxos ?? interactionParameters.utxos,
322
+ };
318
323
  }
319
324
  async detectInteractionOPWallet(interactionParameters) {
320
325
  if (typeof window === 'undefined') {
@@ -332,7 +337,10 @@ export class TransactionFactory {
332
337
  if (!interaction) {
333
338
  throw new Error('Could not sign interaction transaction.');
334
339
  }
335
- return interaction;
340
+ return {
341
+ ...interaction,
342
+ fundingInputUtxos: interaction.fundingInputUtxos ?? interactionParameters.utxos,
343
+ };
336
344
  }
337
345
  async detectDeploymentOPWallet(deploymentParameters) {
338
346
  if (typeof window === 'undefined') {
@@ -350,7 +358,10 @@ export class TransactionFactory {
350
358
  if (!deployment) {
351
359
  throw new Error('Could not sign interaction transaction.');
352
360
  }
353
- return deployment;
361
+ return {
362
+ ...deployment,
363
+ inputUtxos: deployment.inputUtxos ?? deploymentParameters.utxos,
364
+ };
354
365
  }
355
366
  async createFundTransaction(parameters) {
356
367
  if (!parameters.to)
@@ -365,6 +376,7 @@ export class TransactionFactory {
365
376
  original: fundingTransaction,
366
377
  estimatedFees: fundingTransaction.estimatedFees,
367
378
  nextUTXOs: this.getUTXOAsTransaction(signedTransaction, parameters.to, 0),
379
+ inputUtxos: parameters.utxos,
368
380
  };
369
381
  }
370
382
  hasP2WDAInputs(utxos) {
@@ -398,6 +410,7 @@ export class TransactionFactory {
398
410
  estimatedFees: p2wdaTransaction.estimatedFees,
399
411
  nextUTXOs: this.getUTXOAsTransaction(signedTx, interactionParameters.from, signedTx.outs.length - 1),
400
412
  fundingUTXOs: [...interactionParameters.utxos, ...inputs],
413
+ fundingInputUtxos: interactionParameters.utxos,
401
414
  challenge: interactionParameters.challenge.toRaw(),
402
415
  compiledTargetScript: null,
403
416
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.7.17",
4
+ "version": "1.7.19",
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.7.17';
1
+ export const version = '1.7.18';
@@ -34,12 +34,11 @@ import { CancelTransaction, ICancelTransactionParameters } from './builders/Canc
34
34
 
35
35
  export interface DeploymentResult {
36
36
  readonly transaction: [string, string];
37
-
38
37
  readonly contractAddress: string;
39
38
  readonly contractPubKey: string;
40
39
  readonly challenge: RawChallenge;
41
-
42
40
  readonly utxos: UTXO[];
41
+ readonly inputUtxos: UTXO[];
43
42
  }
44
43
 
45
44
  export interface FundingTransactionResponse {
@@ -47,12 +46,14 @@ export interface FundingTransactionResponse {
47
46
  readonly original: FundingTransaction;
48
47
  readonly estimatedFees: bigint;
49
48
  readonly nextUTXOs: UTXO[];
49
+ readonly inputUtxos: UTXO[];
50
50
  }
51
51
 
52
52
  export interface BitcoinTransferBase {
53
53
  readonly tx: string;
54
54
  readonly estimatedFees: bigint;
55
55
  readonly nextUTXOs: UTXO[];
56
+ readonly inputUtxos: UTXO[];
56
57
  }
57
58
 
58
59
  export interface InteractionResponse {
@@ -61,6 +62,7 @@ export interface InteractionResponse {
61
62
  readonly estimatedFees: bigint;
62
63
  readonly nextUTXOs: UTXO[];
63
64
  readonly fundingUTXOs: UTXO[];
65
+ readonly fundingInputUtxos: UTXO[];
64
66
  readonly challenge: RawChallenge;
65
67
  readonly interactionAddress: string | null;
66
68
  readonly compiledTargetScript: string | null;
@@ -73,19 +75,22 @@ export interface BitcoinTransferResponse extends BitcoinTransferBase {
73
75
  export interface CancelledTransaction {
74
76
  readonly transaction: string;
75
77
  readonly nextUTXOs: UTXO[];
78
+ readonly inputUtxos: UTXO[];
76
79
  }
77
80
 
78
81
  export class TransactionFactory {
79
82
  public debug: boolean = false;
80
83
 
81
84
  private readonly DUMMY_PUBKEY = Buffer.alloc(32, 1);
82
- private readonly P2TR_SCRIPT = Buffer.concat([
83
- Buffer.from([0x51, 0x20]), // OP_1 + 32 bytes
84
- this.DUMMY_PUBKEY,
85
- ]);
85
+ private readonly P2TR_SCRIPT = Buffer.concat([Buffer.from([0x51, 0x20]), this.DUMMY_PUBKEY]);
86
86
  private readonly INITIAL_FUNDING_ESTIMATE = 2000n;
87
87
  private readonly MAX_ITERATIONS = 10;
88
88
 
89
+ /**
90
+ * @description Creates a cancellable transaction.
91
+ * @param {ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner} params - The cancel transaction parameters
92
+ * @returns {Promise<CancelledTransaction>} - The cancelled transaction result
93
+ */
89
94
  public async createCancellableTransaction(
90
95
  params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner,
91
96
  ): Promise<CancelledTransaction> {
@@ -115,16 +120,18 @@ export class TransactionFactory {
115
120
  return {
116
121
  transaction: rawTx,
117
122
  nextUTXOs: this.getUTXOAsTransaction(signed, params.from, 0),
123
+ inputUtxos: params.utxos,
118
124
  };
119
125
  }
120
126
 
121
127
  /**
122
128
  * @description Generate a transaction with a custom script.
123
- * @returns {Promise<[string, string]>} - The signed transaction
129
+ * @param {ICustomTransactionParameters | ICustomTransactionWithoutSigner} interactionParameters - The custom transaction parameters
130
+ * @returns {Promise<[string, string, UTXO[], UTXO[]]>} - The signed transaction tuple [fundingTx, customTx, nextUTXOs, inputUtxos]
124
131
  */
125
132
  public async createCustomScriptTransaction(
126
133
  interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner,
127
- ): Promise<[string, string, UTXO[]]> {
134
+ ): Promise<[string, string, UTXO[], UTXO[]]> {
128
135
  if (!interactionParameters.to) {
129
136
  throw new Error('Field "to" not provided.');
130
137
  }
@@ -140,7 +147,6 @@ export class TransactionFactory {
140
147
 
141
148
  const inputs = this.parseOptionalInputs(interactionParameters.optionalInputs);
142
149
 
143
- // Use common iteration logic
144
150
  const { finalTransaction, estimatedAmount, challenge } = await this.iterateFundingAmount(
145
151
  { ...interactionParameters, optionalInputs: inputs },
146
152
  CustomScriptTransaction,
@@ -159,7 +165,6 @@ export class TransactionFactory {
159
165
  parameters.utxos = interactionParameters.utxos;
160
166
  parameters.amount = estimatedAmount;
161
167
 
162
- // Create funding transaction
163
168
  const feeEstimationFunding = await this.createFundTransaction({
164
169
  ...parameters,
165
170
  optionalOutputs: [],
@@ -199,11 +204,13 @@ export class TransactionFactory {
199
204
  signedTransaction.tx.toHex(),
200
205
  outTx.toHex(),
201
206
  this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
207
+ interactionParameters.utxos,
202
208
  ];
203
209
  }
204
210
 
205
211
  /**
206
212
  * @description Generates the required transactions.
213
+ * @param {IInteractionParameters | InteractionParametersWithoutSigner} interactionParameters - The interaction parameters
207
214
  * @returns {Promise<InteractionResponse>} - The signed transaction
208
215
  */
209
216
  public async signInteraction(
@@ -235,7 +242,6 @@ export class TransactionFactory {
235
242
 
236
243
  const inputs = this.parseOptionalInputs(interactionParameters.optionalInputs);
237
244
 
238
- // Use common iteration logic
239
245
  const { finalTransaction, estimatedAmount, challenge } = await this.iterateFundingAmount(
240
246
  { ...interactionParameters, optionalInputs: inputs },
241
247
  InteractionTransaction,
@@ -310,6 +316,7 @@ export class TransactionFactory {
310
316
  ),
311
317
  challenge: challenge.toRaw(),
312
318
  fundingUTXOs: fundingUTXO,
319
+ fundingInputUtxos: interactionParameters.utxos,
313
320
  compiledTargetScript: interactionTx.exportCompiledTargetScript().toString('hex'),
314
321
  };
315
322
  }
@@ -333,7 +340,6 @@ export class TransactionFactory {
333
340
 
334
341
  const inputs = this.parseOptionalInputs(deploymentParameters.optionalInputs);
335
342
 
336
- // Use common iteration logic
337
343
  const { finalTransaction, estimatedAmount, challenge } = await this.iterateFundingAmount(
338
344
  { ...deploymentParameters, optionalInputs: inputs },
339
345
  DeploymentTransaction,
@@ -421,13 +427,14 @@ export class TransactionFactory {
421
427
  contractPubKey: deploymentTx.contractPubKey,
422
428
  utxos: [refundUTXO],
423
429
  challenge: challenge.toRaw(),
430
+ inputUtxos: deploymentParameters.utxos,
424
431
  };
425
432
  }
426
433
 
427
434
  /**
428
435
  * @description Creates a funding transaction.
429
436
  * @param {IFundingTransactionParameters} parameters - The funding transaction parameters
430
- * @returns {Promise<{ estimatedFees: bigint; tx: string }>} - The signed transaction
437
+ * @returns {Promise<BitcoinTransferResponse>} - The signed transaction
431
438
  */
432
439
  public async createBTCTransfer(
433
440
  parameters: IFundingTransactionParameters,
@@ -442,6 +449,7 @@ export class TransactionFactory {
442
449
  original: resp.original,
443
450
  tx: resp.tx.toHex(),
444
451
  nextUTXOs: this.getAllNewUTXOs(resp.original, resp.tx, parameters.from),
452
+ inputUtxos: parameters.utxos,
445
453
  };
446
454
  }
447
455
 
@@ -450,6 +458,7 @@ export class TransactionFactory {
450
458
  * @param {TransactionBuilder<TransactionType>} original - The original transaction
451
459
  * @param {Transaction} tx - The transaction
452
460
  * @param {string} to - The address to filter
461
+ * @returns {UTXO[]} - The new UTXOs belonging to the specified address
453
462
  */
454
463
  public getAllNewUTXOs(
455
464
  original: TransactionBuilder<TransactionType>,
@@ -473,6 +482,11 @@ export class TransactionFactory {
473
482
  return utxos;
474
483
  }
475
484
 
485
+ /**
486
+ * Parse optional inputs and normalize nonWitnessUtxo format.
487
+ * @param {UTXO[]} optionalInputs - The optional inputs to parse
488
+ * @returns {UTXO[]} - The parsed inputs with normalized nonWitnessUtxo
489
+ */
476
490
  private parseOptionalInputs(optionalInputs?: UTXO[]): UTXO[] {
477
491
  return (optionalInputs || []).map((input) => {
478
492
  let nonWitness = input.nonWitnessUtxo;
@@ -495,6 +509,11 @@ export class TransactionFactory {
495
509
  });
496
510
  }
497
511
 
512
+ /**
513
+ * Detect and use OP_WALLET for cancel transactions if available.
514
+ * @param {ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner} interactionParameters - The cancel parameters
515
+ * @returns {Promise<CancelledTransaction | null>} - The cancelled transaction or null if OP_WALLET not available
516
+ */
498
517
  private async detectCancelOPWallet(
499
518
  interactionParameters:
500
519
  | ICancelTransactionParameters
@@ -512,7 +531,6 @@ export class TransactionFactory {
512
531
  const opnet = _window.opnet.web3;
513
532
  const interaction = await opnet.cancelTransaction({
514
533
  ...interactionParameters,
515
-
516
534
  // @ts-expect-error no, this is ok
517
535
  signer: undefined,
518
536
  });
@@ -521,9 +539,17 @@ export class TransactionFactory {
521
539
  throw new Error('Could not sign interaction transaction.');
522
540
  }
523
541
 
524
- return interaction;
542
+ return {
543
+ ...interaction,
544
+ inputUtxos: interaction.inputUtxos ?? interactionParameters.utxos,
545
+ };
525
546
  }
526
547
 
548
+ /**
549
+ * Detect and use OP_WALLET for interaction transactions if available.
550
+ * @param {IInteractionParameters | InteractionParametersWithoutSigner} interactionParameters - The interaction parameters
551
+ * @returns {Promise<InteractionResponse | null>} - The interaction response or null if OP_WALLET not available
552
+ */
527
553
  private async detectInteractionOPWallet(
528
554
  interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner,
529
555
  ): Promise<InteractionResponse | null> {
@@ -539,7 +565,6 @@ export class TransactionFactory {
539
565
  const opnet = _window.opnet.web3;
540
566
  const interaction = await opnet.signInteraction({
541
567
  ...interactionParameters,
542
-
543
568
  // @ts-expect-error no, this is ok
544
569
  signer: undefined,
545
570
  });
@@ -548,9 +573,17 @@ export class TransactionFactory {
548
573
  throw new Error('Could not sign interaction transaction.');
549
574
  }
550
575
 
551
- return interaction;
576
+ return {
577
+ ...interaction,
578
+ fundingInputUtxos: interaction.fundingInputUtxos ?? interactionParameters.utxos,
579
+ };
552
580
  }
553
581
 
582
+ /**
583
+ * Detect and use OP_WALLET for deployment transactions if available.
584
+ * @param {IDeploymentParameters | IDeploymentParametersWithoutSigner} deploymentParameters - The deployment parameters
585
+ * @returns {Promise<DeploymentResult | null>} - The deployment result or null if OP_WALLET not available
586
+ */
554
587
  private async detectDeploymentOPWallet(
555
588
  deploymentParameters: IDeploymentParameters | IDeploymentParametersWithoutSigner,
556
589
  ): Promise<DeploymentResult | null> {
@@ -566,7 +599,6 @@ export class TransactionFactory {
566
599
  const opnet = _window.opnet.web3;
567
600
  const deployment = await opnet.deployContract({
568
601
  ...deploymentParameters,
569
-
570
602
  // @ts-expect-error no, this is ok
571
603
  signer: undefined,
572
604
  });
@@ -575,9 +607,17 @@ export class TransactionFactory {
575
607
  throw new Error('Could not sign interaction transaction.');
576
608
  }
577
609
 
578
- return deployment;
610
+ return {
611
+ ...deployment,
612
+ inputUtxos: deployment.inputUtxos ?? deploymentParameters.utxos,
613
+ };
579
614
  }
580
615
 
616
+ /**
617
+ * Create and sign a funding transaction.
618
+ * @param {IFundingTransactionParameters} parameters - The funding transaction parameters
619
+ * @returns {Promise<FundingTransactionResponse>} - The funding transaction response
620
+ */
581
621
  private async createFundTransaction(
582
622
  parameters: IFundingTransactionParameters,
583
623
  ): Promise<FundingTransactionResponse> {
@@ -594,6 +634,7 @@ export class TransactionFactory {
594
634
  original: fundingTransaction,
595
635
  estimatedFees: fundingTransaction.estimatedFees,
596
636
  nextUTXOs: this.getUTXOAsTransaction(signedTransaction, parameters.to, 0),
637
+ inputUtxos: parameters.utxos,
597
638
  };
598
639
  }
599
640
 
@@ -604,13 +645,19 @@ export class TransactionFactory {
604
645
  * if any of them are P2WDA addresses. P2WDA detection is based on the
605
646
  * witness script pattern: (OP_2DROP * 5) <pubkey> OP_CHECKSIG
606
647
  *
607
- * @param utxos The main UTXOs to check
608
- * @returns true if any UTXO is P2WDA, false otherwise
648
+ * @param {UTXO[]} utxos - The main UTXOs to check
649
+ * @returns {boolean} - true if any UTXO is P2WDA, false otherwise
609
650
  */
610
651
  private hasP2WDAInputs(utxos: UTXO[]): boolean {
611
652
  return utxos.some((utxo) => P2WDADetector.isP2WDAUTXO(utxo));
612
653
  }
613
654
 
655
+ /**
656
+ * Write PSBT header with type and consensus version.
657
+ * @param {PSBTTypes} type - The PSBT type
658
+ * @param {string} psbt - The base64 encoded PSBT
659
+ * @returns {string} - The hex encoded PSBT with header
660
+ */
614
661
  private writePSBTHeader(type: PSBTTypes, psbt: string): string {
615
662
  const buf = Buffer.from(psbt, 'base64');
616
663
 
@@ -635,8 +682,8 @@ export class TransactionFactory {
635
682
  * - 75% cost reduction for data storage
636
683
  * - No separate funding transaction needed
637
684
  *
638
- * @param interactionParameters The interaction parameters
639
- * @returns The signed P2WDA interaction response
685
+ * @param {IInteractionParameters | InteractionParametersWithoutSigner} interactionParameters - The interaction parameters
686
+ * @returns {Promise<InteractionResponse>} - The signed P2WDA interaction response
640
687
  */
641
688
  private async signP2WDAInteraction(
642
689
  interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner,
@@ -645,7 +692,6 @@ export class TransactionFactory {
645
692
  throw new Error('Field "from" not provided.');
646
693
  }
647
694
 
648
- // Ensure we have a signer for P2WDA
649
695
  if (!('signer' in interactionParameters)) {
650
696
  throw new Error(
651
697
  'P2WDA interactions require a signer. OP_WALLET is not supported for P2WDA.',
@@ -669,14 +715,20 @@ export class TransactionFactory {
669
715
  nextUTXOs: this.getUTXOAsTransaction(
670
716
  signedTx,
671
717
  interactionParameters.from,
672
- signedTx.outs.length - 1, // Last output is typically the change
718
+ signedTx.outs.length - 1,
673
719
  ),
674
720
  fundingUTXOs: [...interactionParameters.utxos, ...inputs],
721
+ fundingInputUtxos: interactionParameters.utxos,
675
722
  challenge: interactionParameters.challenge.toRaw(),
676
723
  compiledTargetScript: null,
677
724
  };
678
725
  }
679
726
 
727
+ /**
728
+ * Get the priority fee from transaction parameters.
729
+ * @param {ITransactionParameters} params - The transaction parameters
730
+ * @returns {bigint} - The priority fee, minimum dust if below threshold
731
+ */
680
732
  private getPriorityFee(params: ITransactionParameters): bigint {
681
733
  const totalFee = params.priorityFee + params.gasSatFee;
682
734
  if (totalFee < TransactionBuilder.MINIMUM_DUST) {
@@ -687,7 +739,16 @@ export class TransactionFactory {
687
739
  }
688
740
 
689
741
  /**
690
- * Common iteration logic for finding the correct funding amount
742
+ * Common iteration logic for finding the correct funding amount.
743
+ *
744
+ * This method iteratively estimates the required funding amount by simulating
745
+ * transactions until the amount converges or max iterations is reached.
746
+ *
747
+ * @param {P} params - The transaction parameters
748
+ * @param {new (params: P) => T} TransactionClass - The transaction class constructor
749
+ * @param {(tx: T) => Promise<bigint>} calculateAmount - Function to calculate required amount
750
+ * @param {string} debugPrefix - Prefix for debug logging
751
+ * @returns {Promise<{finalTransaction: T, estimatedAmount: bigint, challenge: ChallengeSolution | null}>} - The final transaction and estimated amount
691
752
  */
692
753
  private async iterateFundingAmount<
693
754
  T extends InteractionTransaction | DeploymentTransaction | CustomScriptTransaction,
@@ -732,14 +793,13 @@ export class TransactionFactory {
732
793
  nonWitnessUtxo: dummyTx.toBuffer(),
733
794
  };
734
795
 
735
- // Build transaction params - TypeScript needs explicit typing here
736
796
  let txParams: P;
737
797
  if ('challenge' in params && params.challenge) {
738
798
  const withChallenge = {
739
799
  ...params,
740
800
  utxos: [simulatedFundedUtxo],
741
801
  randomBytes: randomBytes,
742
- challenge: challenge ?? params.challenge, // Use existing or original
802
+ challenge: challenge ?? params.challenge,
743
803
  };
744
804
  txParams = withChallenge as P;
745
805
  } else {
@@ -776,7 +836,6 @@ export class TransactionFactory {
776
836
 
777
837
  finalPreTransaction = preTransaction;
778
838
 
779
- // Extract challenge with explicit typing
780
839
  if (
781
840
  'getChallenge' in preTransaction &&
782
841
  typeof preTransaction.getChallenge === 'function'
@@ -804,6 +863,13 @@ export class TransactionFactory {
804
863
  };
805
864
  }
806
865
 
866
+ /**
867
+ * Convert a transaction output to a UTXO.
868
+ * @param {Transaction} tx - The transaction
869
+ * @param {string} to - The address
870
+ * @param {number} index - The output index
871
+ * @returns {UTXO[]} - The UTXO array (empty if output doesn't exist)
872
+ */
807
873
  private getUTXOAsTransaction(tx: Transaction, to: string, index: number): UTXO[] {
808
874
  if (!tx.outs[index]) return [];
809
875