@btc-vision/transaction 1.0.115 → 1.0.117

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 (69) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/deterministic/AddressMap.d.ts +1 -0
  3. package/browser/deterministic/AddressSet.d.ts +2 -2
  4. package/browser/index.js +1 -1
  5. package/browser/keypair/Address.d.ts +1 -0
  6. package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -2
  7. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -3
  8. package/browser/transaction/builders/TransactionBuilder.d.ts +2 -2
  9. package/browser/transaction/builders/UnwrapTransaction.d.ts +1 -2
  10. package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
  11. package/browser/transaction/interfaces/Tap.d.ts +20 -10
  12. package/browser/transaction/processor/PsbtTransaction.d.ts +1 -2
  13. package/browser/transaction/shared/TweakedTransaction.d.ts +2 -3
  14. package/browser/utils/types.d.ts +1 -0
  15. package/browser/verification/TapscriptVerificator.d.ts +1 -0
  16. package/build/_version.d.ts +1 -1
  17. package/build/_version.js +1 -1
  18. package/build/buffer/BinaryWriter.js +2 -2
  19. package/build/deterministic/AddressMap.d.ts +1 -0
  20. package/build/deterministic/AddressMap.js +5 -0
  21. package/build/deterministic/AddressSet.d.ts +2 -2
  22. package/build/deterministic/AddressSet.js +8 -3
  23. package/build/keypair/Address.d.ts +1 -0
  24. package/build/keypair/Address.js +27 -20
  25. package/build/keypair/AddressVerificator.js +1 -0
  26. package/build/keypair/Wallet.js +1 -1
  27. package/build/transaction/builders/DeploymentTransaction.js +3 -3
  28. package/build/transaction/builders/MultiSignTransaction.d.ts +1 -2
  29. package/build/transaction/builders/MultiSignTransaction.js +1 -1
  30. package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -3
  31. package/build/transaction/builders/SharedInteractionTransaction.js +7 -43
  32. package/build/transaction/builders/TransactionBuilder.d.ts +2 -2
  33. package/build/transaction/builders/TransactionBuilder.js +1 -1
  34. package/build/transaction/builders/UnwrapTransaction.d.ts +1 -2
  35. package/build/transaction/builders/UnwrapTransaction.js +1 -1
  36. package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
  37. package/build/transaction/interfaces/Tap.d.ts +20 -10
  38. package/build/transaction/processor/PsbtTransaction.d.ts +1 -2
  39. package/build/transaction/processor/PsbtTransaction.js +1 -1
  40. package/build/transaction/shared/TweakedTransaction.d.ts +2 -3
  41. package/build/transaction/shared/TweakedTransaction.js +1 -1
  42. package/build/utils/types.d.ts +1 -0
  43. package/build/verification/TapscriptVerificator.d.ts +1 -0
  44. package/build/verification/TapscriptVerificator.js +31 -0
  45. package/eslint.config.js +1 -0
  46. package/package.json +1 -1
  47. package/src/_version.ts +1 -1
  48. package/src/buffer/BinaryWriter.ts +2 -2
  49. package/src/deterministic/AddressMap.ts +6 -0
  50. package/src/deterministic/AddressSet.ts +10 -5
  51. package/src/keypair/Address.ts +37 -17
  52. package/src/keypair/AddressVerificator.ts +1 -0
  53. package/src/keypair/Wallet.ts +1 -1
  54. package/src/transaction/browser/extensions/UnisatSigner.ts +1 -2
  55. package/src/transaction/builders/CustomScriptTransaction.ts +1 -2
  56. package/src/transaction/builders/DeploymentTransaction.ts +4 -6
  57. package/src/transaction/builders/InteractionTransaction.ts +1 -1
  58. package/src/transaction/builders/MultiSignTransaction.ts +12 -3
  59. package/src/transaction/builders/SharedInteractionTransaction.ts +11 -68
  60. package/src/transaction/builders/TransactionBuilder.ts +12 -2
  61. package/src/transaction/builders/UnwrapSegwitTransaction.ts +2 -2
  62. package/src/transaction/builders/UnwrapTransaction.ts +9 -3
  63. package/src/transaction/builders/WrapTransaction.ts +2 -2
  64. package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
  65. package/src/transaction/interfaces/Tap.ts +31 -12
  66. package/src/transaction/processor/PsbtTransaction.ts +9 -2
  67. package/src/transaction/shared/TweakedTransaction.ts +11 -3
  68. package/src/utils/types.ts +1 -0
  69. package/src/verification/TapscriptVerificator.ts +48 -0
@@ -4,6 +4,7 @@ export type MemorySlotPointer = bigint;
4
4
  export type BufferLike = Uint8Array | Buffer;
5
5
  export type MemorySlotData<T> = T;
6
6
  export type PointerStorage = DeterministicMap<MemorySlotPointer, MemorySlotData<bigint>>;
7
+ export type BlockchainStorage = DeterministicMap<string, PointerStorage>;
7
8
  export type i32 = number;
8
9
  export type u8 = number;
9
10
  export type u16 = number;
@@ -11,6 +11,7 @@ export interface ContractAddressVerificationParams {
11
11
  export declare class TapscriptVerificator {
12
12
  private static readonly TAP_SCRIPT_VERSION;
13
13
  static getContractAddress(params: ContractAddressVerificationParams): string | undefined;
14
+ static verifyControlBlock(params: ContractAddressVerificationParams, controlBlock: Buffer): boolean;
14
15
  static getContractSeed(deployerPubKey: Buffer, bytecode: Buffer, saltHash: Buffer): Buffer;
15
16
  static generateContractVirtualAddress(deployerPubKey: Buffer, bytecode: Buffer, saltHash: Buffer, network?: Network): string;
16
17
  static generateAddressFromScript(params: ContractAddressVerificationParams, scriptTree: Taptree): string | undefined;
@@ -20,6 +20,37 @@ export class TapscriptVerificator {
20
20
  ];
21
21
  return TapscriptVerificator.generateAddressFromScript(params, scriptTree);
22
22
  }
23
+ static verifyControlBlock(params, controlBlock) {
24
+ const network = params.network || networks.bitcoin;
25
+ const scriptBuilder = new DeploymentGenerator(params.deployerPubKey, toXOnly(params.contractSaltPubKey), network);
26
+ const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.calldata);
27
+ const scriptTree = [
28
+ {
29
+ output: compiledTargetScript,
30
+ version: TapscriptVerificator.TAP_SCRIPT_VERSION,
31
+ },
32
+ {
33
+ output: TransactionBuilder.LOCK_LEAF_SCRIPT,
34
+ version: TapscriptVerificator.TAP_SCRIPT_VERSION,
35
+ },
36
+ ];
37
+ const tapData = payments.p2tr({
38
+ internalPubkey: toXOnly(params.deployerPubKey),
39
+ network: network,
40
+ scriptTree: scriptTree,
41
+ redeem: {
42
+ pubkeys: [params.deployerPubKey, params.contractSaltPubKey],
43
+ output: compiledTargetScript,
44
+ redeemVersion: TapscriptVerificator.TAP_SCRIPT_VERSION,
45
+ },
46
+ });
47
+ const witness = tapData.witness;
48
+ if (!witness || witness.length === 0) {
49
+ return false;
50
+ }
51
+ const requiredControlBlock = witness[witness.length - 1];
52
+ return requiredControlBlock.equals(controlBlock);
53
+ }
23
54
  static getContractSeed(deployerPubKey, bytecode, saltHash) {
24
55
  const sha256OfBytecode = bitCrypto.hash256(bytecode);
25
56
  const buf = Buffer.concat([deployerPubKey, saltHash, sha256OfBytecode]);
package/eslint.config.js CHANGED
@@ -28,6 +28,7 @@ export default tseslint.config(
28
28
  '@typescript-eslint/no-unnecessary-type-parameters': 'off',
29
29
  '@typescript-eslint/no-duplicate-enum-values': 'off',
30
30
  'prefer-spread': 'off',
31
+ '@typescript-eslint/no-empty-object-type': 'off',
31
32
  },
32
33
  },
33
34
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.0.115",
4
+ "version": "1.0.117",
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.0.115';
1
+ export const version = '1.0.117';
@@ -306,13 +306,13 @@ export class BinaryWriter {
306
306
  }
307
307
 
308
308
  private fromAddress(pubKey: Address): Uint8Array {
309
- if (pubKey.byteLength > ADDRESS_BYTE_LENGTH) {
309
+ if (pubKey.tweakedBytes.byteLength > ADDRESS_BYTE_LENGTH) {
310
310
  throw new Error(
311
311
  `Address is too long ${pubKey.byteLength} > ${ADDRESS_BYTE_LENGTH} bytes`,
312
312
  );
313
313
  }
314
314
 
315
- return pubKey;
315
+ return pubKey.tweakedBytes;
316
316
  }
317
317
 
318
318
  private resize(size: u32): void {
@@ -54,4 +54,10 @@ export class AddressMap<V> extends Map<Address, V> {
54
54
 
55
55
  return true;
56
56
  }
57
+
58
+ *[Symbol.iterator](): IterableIterator<[Address, V]> {
59
+ for (const key of this._keys) {
60
+ yield [key, this.get(key) as V];
61
+ }
62
+ }
57
63
  }
@@ -1,4 +1,3 @@
1
- import { i32 } from '../utils/types.js';
2
1
  import { Address } from '../keypair/Address.js';
3
2
 
4
3
  export class AddressSet {
@@ -8,6 +7,10 @@ export class AddressSet {
8
7
  this.keys = keys;
9
8
  }
10
9
 
10
+ public get size(): number {
11
+ return this.keys.length;
12
+ }
13
+
11
14
  public add(address: Address): void {
12
15
  if (!this.has(address)) {
13
16
  this.keys.push(address);
@@ -32,10 +35,6 @@ export class AddressSet {
32
35
  }
33
36
  }
34
37
 
35
- public size(): i32 {
36
- return this.keys.length;
37
- }
38
-
39
38
  public clone(): AddressSet {
40
39
  const clone = new AddressSet();
41
40
 
@@ -59,4 +58,10 @@ export class AddressSet {
59
58
 
60
59
  return clone;
61
60
  }
61
+
62
+ *[Symbol.iterator]() {
63
+ for (let i = 0; i < this.keys.length; i++) {
64
+ yield this.keys[i];
65
+ }
66
+ }
62
67
  }
@@ -9,9 +9,10 @@ export class Address extends Uint8Array {
9
9
  private isP2TROnly: boolean = false;
10
10
  #p2tr: string | undefined;
11
11
  #network: Network | undefined;
12
+ #tweakedBytes: Uint8Array | undefined;
12
13
 
13
14
  public constructor(bytes?: ArrayLike<number>) {
14
- super(ADDRESS_BYTE_LENGTH);
15
+ super(bytes?.length || ADDRESS_BYTE_LENGTH);
15
16
 
16
17
  if (!bytes) {
17
18
  return;
@@ -33,6 +34,14 @@ export class Address extends Uint8Array {
33
34
  return this._keyPair;
34
35
  }
35
36
 
37
+ /**
38
+ * Get the tweaked bytes
39
+ * @returns {Uint8Array} The tweaked bytes
40
+ */
41
+ public get tweakedBytes(): Uint8Array {
42
+ return this.#tweakedBytes || this;
43
+ }
44
+
36
45
  public static dead(): Address {
37
46
  return Address.fromString(
38
47
  '0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f',
@@ -45,6 +54,10 @@ export class Address extends Uint8Array {
45
54
  * @returns {Address} The address
46
55
  */
47
56
  public static fromString(pubKey: string): Address {
57
+ if (!pubKey) {
58
+ throw new Error('Invalid public key');
59
+ }
60
+
48
61
  if (pubKey.startsWith('0x')) {
49
62
  pubKey = pubKey.slice(2);
50
63
  }
@@ -70,12 +83,15 @@ export class Address extends Uint8Array {
70
83
  }
71
84
 
72
85
  public equals(a: Address): boolean {
73
- if (a.length !== this.length) {
86
+ const b = this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array);
87
+ const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
88
+
89
+ if (c.length !== b.length) {
74
90
  return false;
75
91
  }
76
92
 
77
- for (let i = 0; i < this.length; i++) {
78
- if (this[i] !== a[i]) {
93
+ for (let i = 0; i < b.length; i++) {
94
+ if (b[i] !== c[i]) {
79
95
  return false;
80
96
  }
81
97
  }
@@ -89,9 +105,12 @@ export class Address extends Uint8Array {
89
105
  */
90
106
  public lessThan(a: Address): boolean {
91
107
  // Compare the two addresses byte-by-byte, treating them as big-endian uint256
108
+ const b = this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array);
109
+ const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
110
+
92
111
  for (let i = 0; i < 32; i++) {
93
- const thisByte = this[i];
94
- const aByte = a[i];
112
+ const thisByte = b[i];
113
+ const aByte = c[i];
95
114
 
96
115
  if (thisByte < aByte) {
97
116
  return true; // this is less than a
@@ -109,9 +128,12 @@ export class Address extends Uint8Array {
109
128
  */
110
129
  public greaterThan(a: Address): boolean {
111
130
  // Compare the two addresses byte-by-byte, treating them as big-endian uint256
131
+ const b = this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array);
132
+ const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
133
+
112
134
  for (let i = 0; i < 32; i++) {
113
- const thisByte = this[i];
114
- const aByte = a[i];
135
+ const thisByte = b[i];
136
+ const aByte = c[i];
115
137
 
116
138
  if (thisByte > aByte) {
117
139
  return true; // this is greater than a
@@ -130,7 +152,7 @@ export class Address extends Uint8Array {
130
152
  */
131
153
  public override set(publicKey: ArrayLike<number>): void {
132
154
  if (publicKey.length !== 33 && publicKey.length !== 32 && publicKey.length !== 65) {
133
- throw new Error('Invalid public key length');
155
+ throw new Error(`Invalid public key length ${publicKey.length}`);
134
156
  }
135
157
 
136
158
  if (publicKey.length === 32) {
@@ -143,14 +165,14 @@ export class Address extends Uint8Array {
143
165
  } else {
144
166
  this._keyPair = EcKeyPair.fromPublicKey(Uint8Array.from(publicKey));
145
167
 
146
- const tweaked = toXOnly(
168
+ this.#tweakedBytes = toXOnly(
147
169
  Buffer.from(
148
170
  EcKeyPair.tweakPublicKey(this._keyPair.publicKey.toString('hex')),
149
171
  'hex',
150
172
  ),
151
173
  );
152
174
 
153
- super.set(Uint8Array.from(tweaked));
175
+ super.set(publicKey);
154
176
  }
155
177
  }
156
178
 
@@ -207,12 +229,10 @@ export class Address extends Uint8Array {
207
229
  return this.#p2tr;
208
230
  }
209
231
 
210
- let p2trAddy: string | undefined;
211
- if (this._keyPair) {
212
- p2trAddy = EcKeyPair.getTaprootAddress(this.keyPair, network);
213
- } else if (this.isP2TROnly) {
214
- p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this, network);
215
- }
232
+ const p2trAddy: string | undefined = EcKeyPair.tweakedPubKeyBufferToAddress(
233
+ this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array),
234
+ network,
235
+ );
216
236
 
217
237
  if (p2trAddy) {
218
238
  this.#network = network;
@@ -175,6 +175,7 @@ export class AddressVerificator {
175
175
  }
176
176
  }
177
177
  } catch (error) {
178
+ console.log(error);
178
179
  // Ignore errors from Bech32/Bech32m decoding
179
180
  }
180
181
 
@@ -73,7 +73,7 @@ export class Wallet {
73
73
  'hex',
74
74
  );
75
75
 
76
- this._bufferPubKey = Buffer.from(wallet.publicKey, 'hex');
76
+ this._bufferPubKey = this._keypair.publicKey;
77
77
  this._address = new Address(this._keypair.publicKey);
78
78
  }
79
79
 
@@ -1,5 +1,4 @@
1
- import { TapScriptSig } from 'bip174/src/lib/interfaces.js';
2
- import { Network, networks, Psbt } from 'bitcoinjs-lib';
1
+ import { Network, networks, Psbt, TapScriptSig } from 'bitcoinjs-lib';
3
2
  import { ECPairInterface } from 'ecpair';
4
3
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
5
4
  import { CustomKeypair } from '../BrowserSignerBase.js';
@@ -2,14 +2,13 @@ import { Taptree } from 'bitcoinjs-lib/src/types.js';
2
2
  import { TransactionType } from '../enums/TransactionType.js';
3
3
  import { TapLeafScript } from '../interfaces/Tap.js';
4
4
  import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
5
- import { crypto as bitCrypto, Payment, Psbt, Signer, Stack } from 'bitcoinjs-lib';
5
+ import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer, Stack } from 'bitcoinjs-lib';
6
6
  import { TransactionBuilder } from './TransactionBuilder.js';
7
7
  import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
8
8
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
9
9
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
10
10
  import { AddressGenerator } from '../../generators/AddressGenerator.js';
11
11
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
12
- import { PsbtInput } from 'bip174/src/lib/interfaces.js';
13
12
  import { ECPairInterface } from 'ecpair';
14
13
 
15
14
  export interface ICustomTransactionParameters extends SharedInteractionParameters {
@@ -1,6 +1,6 @@
1
1
  import { TransactionType } from '../enums/TransactionType.js';
2
2
  import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
3
- import { crypto as bitCrypto, Payment, Psbt, Signer } from 'bitcoinjs-lib';
3
+ import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer } from 'bitcoinjs-lib';
4
4
  import { TransactionBuilder } from './TransactionBuilder.js';
5
5
  import { Taptree } from 'bitcoinjs-lib/src/types.js';
6
6
  import { TapLeafScript } from '../interfaces/Tap.js';
@@ -8,7 +8,6 @@ import { DeploymentGenerator } from '../../generators/builders/DeploymentGenerat
8
8
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
9
9
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
10
10
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
11
- import { PsbtInput } from 'bip174/src/lib/interfaces.js';
12
11
  import { Compressor } from '../../bytecode/Compressor.js';
13
12
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
14
13
  import { ECPairInterface } from 'ecpair';
@@ -121,8 +120,8 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
121
120
 
122
121
  this.internalInit();
123
122
 
124
- this._contractPubKey = '0x' + this.contractSigner.publicKey.toString('hex');
125
- this._contractAddress = new Address(this.contractSigner.publicKey); //AddressGenerator.generatePKSH(this.contractSeed, this.network);
123
+ this._contractPubKey = '0x' + this.contractSeed.toString('hex');
124
+ this._contractAddress = new Address(this.contractSeed);
126
125
  }
127
126
 
128
127
  /**
@@ -198,7 +197,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
198
197
  const amountSpent: bigint = this.getTransactionOPNetFee();
199
198
  this.addOutput({
200
199
  value: Number(amountSpent),
201
- address: this.to,
200
+ address: this.contractAddress.p2tr(this.network),
202
201
  });
203
202
 
204
203
  await this.addRefundOutput(amountSpent);
@@ -296,7 +295,6 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
296
295
  const deployerPubKey: Buffer = this.internalPubKeyToXOnly();
297
296
  const salt: Buffer = bitCrypto.hash256(this.randomBytes);
298
297
  const sha256OfBytecode: Buffer = bitCrypto.hash256(this.bytecode);
299
-
300
298
  const buf: Buffer = Buffer.concat([deployerPubKey, salt, sha256OfBytecode]);
301
299
 
302
300
  return bitCrypto.hash256(buf);
@@ -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
  }
@@ -1,11 +1,20 @@
1
- import { PsbtInput, TapScriptSig } from 'bip174/src/lib/interfaces.js';
2
- import { crypto as bitcoinCrypto, opcodes, Payment, Psbt, script, Signer } from 'bitcoinjs-lib';
1
+ import {
2
+ crypto as bitcoinCrypto,
3
+ opcodes,
4
+ Payment,
5
+ Psbt,
6
+ PsbtInput,
7
+ PsbtInputExtended,
8
+ PsbtOutputExtended,
9
+ script,
10
+ Signer,
11
+ TapScriptSig,
12
+ } from 'bitcoinjs-lib';
3
13
  import { Taptree } from 'bitcoinjs-lib/src/types.js';
4
14
  import { TransactionBuilder } from './TransactionBuilder.js';
5
15
  import { TransactionType } from '../enums/TransactionType.js';
6
16
  import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
7
17
  import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
8
- import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
9
18
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
10
19
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
11
20
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
@@ -1,5 +1,4 @@
1
- import { PsbtInput } from 'bip174/src/lib/interfaces.js';
2
- import { address, Payment, Psbt, Signer } from 'bitcoinjs-lib';
1
+ import { address, Payment, Psbt, PsbtInput, Signer } from 'bitcoinjs-lib';
3
2
  import { Taptree } from 'bitcoinjs-lib/src/types.js';
4
3
  import { ECPairInterface } from 'ecpair';
5
4
  import { TransactionBuilder } from './TransactionBuilder.js';
@@ -187,35 +186,17 @@ export abstract class SharedInteractionTransaction<
187
186
  return;
188
187
  }
189
188
 
190
- const txs: PsbtInput[] = transaction.data.inputs;
191
- for (let i = 0; i < txs.length; i += 20) {
192
- const batch = txs.slice(i, i + 20);
189
+ for (let i = 0; i < transaction.data.inputs.length; i++) {
190
+ if (i === 0) {
191
+ // multi sig input
192
+ transaction.signInput(0, this.scriptSigner);
193
+ transaction.signInput(0, this.getSignerKey());
193
194
 
194
- const promises: Promise<void>[] = [];
195
- for (let y = 0; y < batch.length; y++) {
196
- const offset = i * 20 + y;
197
- const input = batch[y];
198
-
199
- promises.push(this.signIndividualInputs(transaction, input, offset));
200
- }
201
-
202
- await Promise.all(promises).catch((e: unknown) => {
203
- throw e;
204
- });
205
- }
206
-
207
- try {
208
- transaction.finalizeInput(0, this.customFinalizer);
209
- } catch (e) {
210
- this.error(`Failed to finalize input 0: ${(e as Error).stack}`);
211
- }
212
-
213
- for (let i = 0; i < txs.length; i++) {
214
- try {
195
+ transaction.finalizeInput(0, this.customFinalizer);
196
+ } else {
197
+ transaction.signInput(i, this.getSignerKey());
215
198
  transaction.finalizeInput(i);
216
-
217
- this.log(`Finalized input ${i}!`);
218
- } catch {}
199
+ }
219
200
  }
220
201
  }
221
202
 
@@ -265,7 +246,7 @@ export abstract class SharedInteractionTransaction<
265
246
  this.internalPubKeyToXOnly(),
266
247
  input.tapScriptSig[0].signature,
267
248
  input.tapScriptSig[1].signature,
268
- ];
249
+ ] as Buffer[];
269
250
  }
270
251
 
271
252
  /**
@@ -303,12 +284,6 @@ export abstract class SharedInteractionTransaction<
303
284
  throw new Error('Tap leaf script is required');
304
285
  }
305
286
 
306
- //console.log('finalizing input', input);
307
-
308
- //if (!input.tapLeafScript) {
309
- // throw new Error('Tap script signature is required');
310
- //}
311
-
312
287
  if (!this.contractSecret) {
313
288
  throw new Error('Contract secret is required');
314
289
  }
@@ -323,38 +298,6 @@ export abstract class SharedInteractionTransaction<
323
298
  };
324
299
  };
325
300
 
326
- private async signIndividualInputs(
327
- transaction: Psbt,
328
- input: PsbtInput,
329
- i: number,
330
- ): Promise<void> {
331
- let signed: boolean = false;
332
-
333
- try {
334
- await this.signInput(transaction, input, i, this.scriptSigner);
335
- signed = true;
336
- } catch {}
337
-
338
- try {
339
- await this.signInput(transaction, input, i);
340
- signed = true;
341
- } catch {}
342
-
343
- if (signed) {
344
- this.log(
345
- `Signed input #${i} out of ${transaction.data.inputs.length}! {Signed: ${signed}}`,
346
- );
347
-
348
- return;
349
- }
350
-
351
- if (this.regenerated || this.ignoreSignatureErrors) {
352
- return;
353
- }
354
-
355
- throw new Error('Failed to sign input');
356
- }
357
-
358
301
  /**
359
302
  * Get the public keys
360
303
  * @private
@@ -1,7 +1,17 @@
1
- import { initEccLib, Network, opcodes, Psbt, script, Signer, Transaction } from 'bitcoinjs-lib';
1
+ import {
2
+ initEccLib,
3
+ Network,
4
+ opcodes,
5
+ Psbt,
6
+ PsbtInputExtended,
7
+ PsbtOutputExtended,
8
+ script,
9
+ Signer,
10
+ Transaction,
11
+ } from 'bitcoinjs-lib';
2
12
  import { varuint } from 'bitcoinjs-lib/src/bufferutils.js';
3
13
  import * as ecc from '@bitcoinerlab/secp256k1';
4
- import { PsbtInputExtended, PsbtOutputExtended, UpdateInput } from '../interfaces/Tap.js';
14
+ import { UpdateInput } from '../interfaces/Tap.js';
5
15
  import { TransactionType } from '../enums/TransactionType.js';
6
16
  import {
7
17
  IFundingTransactionParameters,
@@ -4,10 +4,9 @@ import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
4
4
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
5
5
  import { TransactionBuilder } from './TransactionBuilder.js';
6
6
  import { wBTC } from '../../metadata/contracts/wBTC.js';
7
- import { payments, Psbt, Signer } from 'bitcoinjs-lib';
7
+ import { payments, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer } from 'bitcoinjs-lib';
8
8
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
9
9
  import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/PsbtTransaction.js';
10
- import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
11
10
  import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
12
11
  import { ECPairInterface } from 'ecpair';
13
12
  import { Selector } from '../../utils/types.js';
@@ -195,6 +194,7 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction<Transa
195
194
  /**
196
195
  * Builds the transaction.
197
196
  * @param {Psbt} transaction - The transaction to build
197
+ * @param checkPartialSigs
198
198
  * @protected
199
199
  * @returns {Promise<boolean>}
200
200
  * @throws {Error} - If something went wrong while building the transaction
@@ -4,15 +4,21 @@ import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
4
4
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
5
5
  import { TransactionBuilder } from './TransactionBuilder.js';
6
6
  import { wBTC } from '../../metadata/contracts/wBTC.js';
7
- import { Network, Payment, payments, Psbt } from 'bitcoinjs-lib';
7
+ import {
8
+ Network,
9
+ Payment,
10
+ payments,
11
+ Psbt,
12
+ PsbtInput,
13
+ PsbtInputExtended,
14
+ PsbtOutputExtended,
15
+ } from 'bitcoinjs-lib';
8
16
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
9
17
  import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/PsbtTransaction.js';
10
- import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
11
18
  import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
12
19
  import { MultiSignTransaction } from './MultiSignTransaction.js';
13
20
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
14
21
  import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
15
- import { PsbtInput } from 'bip174/src/lib/interfaces.js';
16
22
  import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
17
23
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
18
24
  import { Features } from '../../generators/Features.js';
@@ -1,12 +1,12 @@
1
1
  import { Taptree } from 'bitcoinjs-lib/src/types.js';
2
2
  import { TransactionType } from '../enums/TransactionType.js';
3
- import { PsbtOutputExtendedAddress, TapLeafScript } from '../interfaces/Tap.js';
3
+ import { TapLeafScript } from '../interfaces/Tap.js';
4
4
  import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
5
5
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
6
6
  import { wBTC } from '../../metadata/contracts/wBTC.js';
7
7
  import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
8
8
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
9
- import { Network } from 'bitcoinjs-lib';
9
+ import { Network, PsbtOutputExtendedAddress } from 'bitcoinjs-lib';
10
10
  import { P2TR_MS } from '../shared/P2TR_MS.js';
11
11
  import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
12
12
  import { Selector } from '../../utils/types.js';
@@ -3,8 +3,8 @@ import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
3
3
  import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
4
4
  import { VaultUTXOs } from '../processor/PsbtTransaction.js';
5
5
  import { ChainId } from '../../network/ChainId.js';
6
- import { PsbtOutputExtended } from './Tap.js';
7
6
  import { Address } from '../../keypair/Address.js';
7
+ import { PsbtOutputExtended } from 'bitcoinjs-lib';
8
8
 
9
9
  export interface ITransactionParameters extends ITweakedTransactionData {
10
10
  readonly from?: string;
@@ -1,5 +1,16 @@
1
- import { PsbtInput, PsbtOutput } from 'bip174/src/lib/interfaces.js';
2
- import { TransactionInput } from 'bitcoinjs-lib/src/psbt.js';
1
+ import {
2
+ PsbtInput as _PsbtInput,
3
+ PsbtInputUpdate as _PsbtInputUpdate,
4
+ PsbtOutput as _PsbtOutput,
5
+ TapBip32Derivation as _TapBip32Derivation,
6
+ TapInternalKey as _TapInternalKey,
7
+ TapKeySig as _TapKeySig,
8
+ TapLeaf as _TapLeaf,
9
+ TapLeafScript as _TapLeafScript,
10
+ TapMerkleRoot as _TapMerkleRoot,
11
+ TapScriptSig as _TapScriptSig,
12
+ TapTree as _TapTree,
13
+ } from 'bitcoinjs-lib';
3
14
 
4
15
  export interface TapLeafScript {
5
16
  readonly leafVersion: number;
@@ -11,16 +22,24 @@ export interface UpdateInput {
11
22
  tapLeafScript: TapLeafScript[];
12
23
  }
13
24
 
14
- export interface PsbtInputExtended extends PsbtInput, TransactionInput {}
25
+ export interface PsbtInput extends _PsbtInput {}
15
26
 
16
- export interface PsbtOutputExtendedAddress extends PsbtOutput {
17
- address: string;
18
- value: number;
19
- }
27
+ export interface PsbtOutput extends _PsbtOutput {}
20
28
 
21
- export interface PsbtOutputExtendedScript extends PsbtOutput {
22
- script: Buffer;
23
- value: number;
24
- }
29
+ export interface TapInternalKey extends _TapInternalKey {}
30
+
31
+ export interface TapLeaf extends _TapLeaf {}
32
+
33
+ export interface TapScriptSig extends _TapScriptSig {}
34
+
35
+ export interface TapKeySig extends _TapKeySig {}
36
+
37
+ export interface TapTree extends _TapTree {}
38
+
39
+ export interface TapMerkleRoot extends _TapMerkleRoot {}
40
+
41
+ export interface TapLeafScript extends _TapLeafScript {}
42
+
43
+ export interface TapBip32Derivation extends _TapBip32Derivation {}
25
44
 
26
- export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
45
+ export interface PsbtInputUpdate extends _PsbtInputUpdate {}