@btc-vision/transaction 1.4.0 → 1.5.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.
Files changed (56) hide show
  1. package/browser/buffer/BinaryReader.d.ts +1 -1
  2. package/browser/generators/builders/DeploymentGenerator.d.ts +2 -0
  3. package/browser/index.js +1 -1
  4. package/browser/index.js.LICENSE.txt +1 -3
  5. package/browser/keypair/Address.d.ts +1 -0
  6. package/browser/keypair/AddressVerificator.d.ts +1 -0
  7. package/browser/keypair/EcKeyPair.d.ts +4 -1
  8. package/browser/transaction/TransactionFactory.d.ts +0 -1
  9. package/browser/transaction/browser/Web3Provider.d.ts +2 -0
  10. package/browser/transaction/builders/CustomScriptTransaction.d.ts +9 -6
  11. package/browser/transaction/builders/DeploymentTransaction.d.ts +6 -3
  12. package/browser/transaction/builders/MultiSignTransaction.d.ts +5 -5
  13. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
  14. package/browser/transaction/shared/TweakedTransaction.d.ts +5 -5
  15. package/build/buffer/BinaryReader.d.ts +1 -1
  16. package/build/buffer/BinaryReader.js +1 -1
  17. package/build/buffer/BinaryWriter.js +2 -2
  18. package/build/generators/builders/DeploymentGenerator.d.ts +2 -0
  19. package/build/generators/builders/DeploymentGenerator.js +2 -0
  20. package/build/keypair/Address.d.ts +1 -0
  21. package/build/keypair/Address.js +15 -2
  22. package/build/keypair/AddressVerificator.d.ts +1 -0
  23. package/build/keypair/AddressVerificator.js +4 -0
  24. package/build/keypair/EcKeyPair.d.ts +4 -1
  25. package/build/keypair/EcKeyPair.js +48 -21
  26. package/build/transaction/TransactionFactory.d.ts +0 -1
  27. package/build/transaction/TransactionFactory.js +18 -4
  28. package/build/transaction/browser/Web3Provider.d.ts +2 -0
  29. package/build/transaction/builders/CustomScriptTransaction.d.ts +9 -6
  30. package/build/transaction/builders/CustomScriptTransaction.js +29 -6
  31. package/build/transaction/builders/DeploymentTransaction.d.ts +6 -3
  32. package/build/transaction/builders/DeploymentTransaction.js +16 -7
  33. package/build/transaction/builders/MultiSignTransaction.d.ts +5 -5
  34. package/build/transaction/builders/MultiSignTransaction.js +5 -1
  35. package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
  36. package/build/transaction/builders/SharedInteractionTransaction.js +5 -1
  37. package/build/transaction/builders/TransactionBuilder.js +3 -2
  38. package/build/transaction/shared/TweakedTransaction.d.ts +5 -5
  39. package/build/transaction/shared/TweakedTransaction.js +5 -3
  40. package/build/verification/TapscriptVerificator.js +0 -1
  41. package/package.json +18 -18
  42. package/src/buffer/BinaryReader.ts +2 -2
  43. package/src/buffer/BinaryWriter.ts +2 -2
  44. package/src/generators/builders/DeploymentGenerator.ts +4 -0
  45. package/src/keypair/Address.ts +21 -0
  46. package/src/keypair/AddressVerificator.ts +6 -1
  47. package/src/keypair/EcKeyPair.ts +91 -34
  48. package/src/transaction/TransactionFactory.ts +21 -7
  49. package/src/transaction/browser/Web3Provider.ts +6 -0
  50. package/src/transaction/builders/CustomScriptTransaction.ts +51 -14
  51. package/src/transaction/builders/DeploymentTransaction.ts +36 -14
  52. package/src/transaction/builders/MultiSignTransaction.ts +10 -6
  53. package/src/transaction/builders/SharedInteractionTransaction.ts +9 -5
  54. package/src/transaction/builders/TransactionBuilder.ts +4 -3
  55. package/src/transaction/shared/TweakedTransaction.ts +10 -6
  56. package/src/verification/TapscriptVerificator.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { crypto as bitCrypto, toXOnly, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitCrypto, PaymentType, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { TransactionType } from '../enums/TransactionType.js';
3
3
  import { TransactionBuilder } from './TransactionBuilder.js';
4
4
  import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
@@ -12,14 +12,20 @@ export class CustomScriptTransaction extends TransactionBuilder {
12
12
  this.tapLeafScript = null;
13
13
  this.targetScriptRedeem = null;
14
14
  this.leftOverFundsScriptRedeem = null;
15
- this.customFinalizer = (_inputIndex, _input) => {
15
+ this.customFinalizer = (_inputIndex, input) => {
16
16
  if (!this.tapLeafScript) {
17
17
  throw new Error('Tap leaf script is required');
18
18
  }
19
- const scriptSolution = this.witnesses;
19
+ const scriptSolution = this.getScriptSolution(input);
20
20
  const witness = scriptSolution
21
21
  .concat(this.tapLeafScript.script)
22
22
  .concat(this.tapLeafScript.controlBlock);
23
+ if (this.annexData && this.annexData.length > 0) {
24
+ const annex = this.annexData[0] === 0x50
25
+ ? this.annexData
26
+ : Buffer.concat([Buffer.from([0x50]), this.annexData]);
27
+ witness.push(annex);
28
+ }
23
29
  return {
24
30
  finalScriptWitness: TransactionBuilder.witnessStackToScriptWitness(witness),
25
31
  };
@@ -86,7 +92,10 @@ export class CustomScriptTransaction extends TransactionBuilder {
86
92
  }
87
93
  for (let i = 0; i < transaction.data.inputs.length; i++) {
88
94
  if (i === 0) {
89
- transaction.signInput(0, this.contractSigner);
95
+ try {
96
+ transaction.signInput(0, this.contractSigner);
97
+ }
98
+ catch (e) { }
90
99
  transaction.signInput(0, this.getSignerKey());
91
100
  transaction.finalizeInput(0, this.customFinalizer);
92
101
  }
@@ -101,6 +110,7 @@ export class CustomScriptTransaction extends TransactionBuilder {
101
110
  internalPubkey: this.internalPubKeyToXOnly(),
102
111
  network: this.network,
103
112
  scriptTree: this.scriptTree,
113
+ name: PaymentType.P2TR,
104
114
  };
105
115
  }
106
116
  generateTapData() {
@@ -118,8 +128,21 @@ export class CustomScriptTransaction extends TransactionBuilder {
118
128
  network: this.network,
119
129
  scriptTree: this.scriptTree,
120
130
  redeem: selectedRedeem,
131
+ name: PaymentType.P2TR,
121
132
  };
122
133
  }
134
+ getScriptSolution(input) {
135
+ if (!input.tapScriptSig) {
136
+ throw new Error('Tap script signature is required');
137
+ }
138
+ const witnesses = [...this.witnesses];
139
+ if (input.tapScriptSig) {
140
+ for (const sig of input.tapScriptSig) {
141
+ witnesses.push(sig.signature);
142
+ }
143
+ }
144
+ return witnesses;
145
+ }
123
146
  getContractSeed() {
124
147
  return bitCrypto.hash256(this.randomBytes);
125
148
  }
@@ -132,12 +155,12 @@ export class CustomScriptTransaction extends TransactionBuilder {
132
155
  }
133
156
  generateRedeemScripts() {
134
157
  this.targetScriptRedeem = {
135
- pubkeys: this.getPubKeys(),
158
+ name: PaymentType.P2TR,
136
159
  output: this.compiledTargetScript,
137
160
  redeemVersion: 192,
138
161
  };
139
162
  this.leftOverFundsScriptRedeem = {
140
- pubkeys: this.getPubKeys(),
163
+ name: PaymentType.P2TR,
141
164
  output: this.getLeafScript(),
142
165
  redeemVersion: 192,
143
166
  };
@@ -1,6 +1,6 @@
1
1
  import { TransactionType } from '../enums/TransactionType.js';
2
2
  import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
3
- import { Payment, Psbt } from '@btc-vision/bitcoin';
3
+ import { P2TRPayment, Psbt } from '@btc-vision/bitcoin';
4
4
  import { TransactionBuilder } from './TransactionBuilder.js';
5
5
  import { TapLeafScript } from '../interfaces/Tap.js';
6
6
  import { Address } from '../../keypair/Address.js';
@@ -12,6 +12,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
12
12
  protected readonly rewardChallenge: IMineableReward;
13
13
  protected readonly _contractAddress: Address;
14
14
  protected tapLeafScript: TapLeafScript | null;
15
+ private readonly deploymentVersion;
15
16
  private targetScriptRedeem;
16
17
  private leftOverFundsScriptRedeem;
17
18
  private readonly compiledTargetScript;
@@ -23,18 +24,20 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
23
24
  private readonly contractSigner;
24
25
  private readonly _contractPubKey;
25
26
  private readonly randomBytes;
27
+ private _computedAddress;
26
28
  constructor(parameters: IDeploymentParameters);
27
29
  get contractPubKey(): string;
28
30
  get contractAddress(): Address;
29
31
  get p2trAddress(): string;
30
32
  getRndBytes(): Buffer;
31
33
  getPreimage(): Buffer;
34
+ getContractAddress(): string;
32
35
  protected contractSignerXOnlyPubKey(): Buffer;
33
36
  protected buildTransaction(): Promise<void>;
34
37
  protected signInputsWalletBased(transaction: Psbt): Promise<void>;
35
38
  protected signInputs(transaction: Psbt): Promise<void>;
36
- protected generateScriptAddress(): Payment;
37
- protected generateTapData(): Payment;
39
+ protected generateScriptAddress(): P2TRPayment;
40
+ protected generateTapData(): P2TRPayment;
38
41
  private verifyCalldata;
39
42
  private verifyBytecode;
40
43
  private getContractSeed;
@@ -1,19 +1,19 @@
1
1
  import { TransactionType } from '../enums/TransactionType.js';
2
- import { crypto as bitCrypto, toXOnly, } from '@btc-vision/bitcoin';
2
+ import { crypto as bitCrypto, PaymentType, toXOnly, } from '@btc-vision/bitcoin';
3
3
  import { MINIMUM_AMOUNT_CA, MINIMUM_AMOUNT_REWARD, TransactionBuilder, } from './TransactionBuilder.js';
4
- import { DeploymentGenerator } from '../../generators/builders/DeploymentGenerator.js';
4
+ import { DeploymentGenerator, versionBuffer, } from '../../generators/builders/DeploymentGenerator.js';
5
5
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
6
6
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
7
7
  import { Compressor } from '../../bytecode/Compressor.js';
8
8
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
9
9
  import { Address } from '../../keypair/Address.js';
10
10
  import { ChallengeGenerator } from '../mineable/ChallengeGenerator.js';
11
- const p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
12
11
  export class DeploymentTransaction extends TransactionBuilder {
13
12
  constructor(parameters) {
14
13
  super(parameters);
15
14
  this.type = TransactionType.DEPLOYMENT;
16
15
  this.tapLeafScript = null;
16
+ this.deploymentVersion = 0x00;
17
17
  this.targetScriptRedeem = null;
18
18
  this.leftOverFundsScriptRedeem = null;
19
19
  this.customFinalizer = (_inputIndex, input) => {
@@ -35,7 +35,7 @@ export class DeploymentTransaction extends TransactionBuilder {
35
35
  finalScriptWitness: TransactionBuilder.witnessStackToScriptWitness(witness),
36
36
  };
37
37
  };
38
- this.bytecode = Compressor.compress(parameters.bytecode);
38
+ this.bytecode = Compressor.compress(Buffer.concat([versionBuffer, parameters.bytecode]));
39
39
  this.verifyBytecode();
40
40
  if (parameters.calldata) {
41
41
  this.calldata = parameters.calldata;
@@ -70,6 +70,13 @@ export class DeploymentTransaction extends TransactionBuilder {
70
70
  getPreimage() {
71
71
  return this.preimage;
72
72
  }
73
+ getContractAddress() {
74
+ if (this._computedAddress) {
75
+ return this._computedAddress;
76
+ }
77
+ this._computedAddress = EcKeyPair.p2op(this.contractSeed, this.network, this.deploymentVersion);
78
+ return this._computedAddress;
79
+ }
73
80
  contractSignerXOnlyPubKey() {
74
81
  return toXOnly(Buffer.from(this.contractSigner.publicKey));
75
82
  }
@@ -105,7 +112,7 @@ export class DeploymentTransaction extends TransactionBuilder {
105
112
  }
106
113
  this.addOutput({
107
114
  value: Number(amountToCA),
108
- address: this.contractAddress.p2tr(this.network),
115
+ address: this.getContractAddress(),
109
116
  });
110
117
  if (amountToCA === MINIMUM_AMOUNT_CA &&
111
118
  amountSpent - MINIMUM_AMOUNT_CA > MINIMUM_AMOUNT_REWARD) {
@@ -162,6 +169,7 @@ export class DeploymentTransaction extends TransactionBuilder {
162
169
  }
163
170
  generateScriptAddress() {
164
171
  return {
172
+ name: PaymentType.P2TR,
165
173
  internalPubkey: this.internalPubKeyToXOnly(),
166
174
  network: this.network,
167
175
  scriptTree: this.scriptTree,
@@ -178,6 +186,7 @@ export class DeploymentTransaction extends TransactionBuilder {
178
186
  throw new Error('Script tree is required');
179
187
  }
180
188
  return {
189
+ name: PaymentType.P2TR,
181
190
  internalPubkey: this.internalPubKeyToXOnly(),
182
191
  network: this.network,
183
192
  scriptTree: this.scriptTree,
@@ -216,12 +225,12 @@ export class DeploymentTransaction extends TransactionBuilder {
216
225
  }
217
226
  generateRedeemScripts() {
218
227
  this.targetScriptRedeem = {
219
- pubkeys: this.getPubKeys(),
228
+ name: PaymentType.P2TR,
220
229
  output: this.compiledTargetScript,
221
230
  redeemVersion: 192,
222
231
  };
223
232
  this.leftOverFundsScriptRedeem = {
224
- pubkeys: this.getPubKeys(),
233
+ name: PaymentType.P2TR,
225
234
  output: this.getLeafScript(),
226
235
  redeemVersion: 192,
227
236
  };
@@ -1,4 +1,4 @@
1
- import { Payment, Psbt, PsbtInput, Signer, TapScriptSig, Taptree } from '@btc-vision/bitcoin';
1
+ import { P2TRPayment, Psbt, PsbtInput, Signer, TapScriptSig, Taptree } from '@btc-vision/bitcoin';
2
2
  import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { TransactionType } from '../enums/TransactionType.js';
4
4
  import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
@@ -21,8 +21,8 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
21
21
  static readonly signHashTypesArray: number[];
22
22
  static readonly numsPoint: Buffer<ArrayBuffer>;
23
23
  type: TransactionType.MULTI_SIG;
24
- protected targetScriptRedeem: Payment | null;
25
- protected leftOverFundsScriptRedeem: Payment | null;
24
+ protected targetScriptRedeem: P2TRPayment | null;
25
+ protected leftOverFundsScriptRedeem: P2TRPayment | null;
26
26
  protected readonly compiledTargetScript: Buffer;
27
27
  protected readonly scriptTree: Taptree;
28
28
  protected readonly publicKeys: Buffer[];
@@ -49,8 +49,8 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
49
49
  protected buildTransaction(): Promise<void>;
50
50
  protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
51
51
  protected signInputs(_transaction: Psbt): Promise<void>;
52
- protected generateScriptAddress(): Payment;
53
- protected generateTapData(): Payment;
52
+ protected generateScriptAddress(): P2TRPayment;
53
+ protected generateTapData(): P2TRPayment;
54
54
  protected getScriptSolution(input: PsbtInput): Buffer[];
55
55
  protected getScriptTree(): Taptree;
56
56
  private getTotalOutputAmount;
@@ -1,4 +1,4 @@
1
- import { crypto as bitcoinCrypto, opcodes, Psbt, script, toXOnly, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitcoinCrypto, opcodes, PaymentType, Psbt, script, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { TransactionType } from '../enums/TransactionType.js';
4
4
  import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
@@ -256,6 +256,7 @@ export class MultiSignTransaction extends TransactionBuilder {
256
256
  internalPubkey: toXOnly(MultiSignTransaction.numsPoint),
257
257
  network: this.network,
258
258
  scriptTree: this.scriptTree,
259
+ name: PaymentType.P2TR,
259
260
  };
260
261
  }
261
262
  generateTapData() {
@@ -271,6 +272,7 @@ export class MultiSignTransaction extends TransactionBuilder {
271
272
  network: this.network,
272
273
  scriptTree: this.scriptTree,
273
274
  redeem: selectedRedeem,
275
+ name: PaymentType.P2TR,
274
276
  };
275
277
  }
276
278
  getScriptSolution(input) {
@@ -307,10 +309,12 @@ export class MultiSignTransaction extends TransactionBuilder {
307
309
  }
308
310
  generateRedeemScripts() {
309
311
  this.targetScriptRedeem = {
312
+ name: PaymentType.P2TR,
310
313
  output: this.compiledTargetScript,
311
314
  redeemVersion: 192,
312
315
  };
313
316
  this.leftOverFundsScriptRedeem = {
317
+ name: PaymentType.P2TR,
314
318
  output: MultiSignTransaction.LOCK_LEAF_SCRIPT,
315
319
  redeemVersion: 192,
316
320
  };
@@ -1,4 +1,4 @@
1
- import { Payment, Psbt, PsbtInput, Signer, Taptree } from '@btc-vision/bitcoin';
1
+ import { P2TRPayment, Psbt, PsbtInput, Signer, Taptree } from '@btc-vision/bitcoin';
2
2
  import { ECPairInterface } from 'ecpair';
3
3
  import { TransactionBuilder } from './TransactionBuilder.js';
4
4
  import { TransactionType } from '../enums/TransactionType.js';
@@ -8,8 +8,8 @@ import { IMineableReward } from '../mineable/ChallengeGenerator.js';
8
8
  export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
9
9
  static readonly MAXIMUM_CALLDATA_SIZE: number;
10
10
  readonly randomBytes: Buffer;
11
- protected targetScriptRedeem: Payment | null;
12
- protected leftOverFundsScriptRedeem: Payment | null;
11
+ protected targetScriptRedeem: P2TRPayment | null;
12
+ protected leftOverFundsScriptRedeem: P2TRPayment | null;
13
13
  protected abstract readonly compiledTargetScript: Buffer;
14
14
  protected abstract readonly scriptTree: Taptree;
15
15
  protected readonly preimage: Buffer;
@@ -28,8 +28,8 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
28
28
  protected generateKeyPairFromSeed(): ECPairInterface;
29
29
  protected buildTransaction(): Promise<void>;
30
30
  protected signInputs(transaction: Psbt): Promise<void>;
31
- protected generateScriptAddress(): Payment;
32
- protected generateTapData(): Payment;
31
+ protected generateScriptAddress(): P2TRPayment;
32
+ protected generateTapData(): P2TRPayment;
33
33
  protected getScriptSolution(input: PsbtInput): Buffer[];
34
34
  protected getScriptTree(): Taptree;
35
35
  protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
@@ -1,4 +1,4 @@
1
- import { address, toXOnly } from '@btc-vision/bitcoin';
1
+ import { address, PaymentType, toXOnly } from '@btc-vision/bitcoin';
2
2
  import { MINIMUM_AMOUNT_CA, MINIMUM_AMOUNT_REWARD, TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
4
4
  import { Compressor } from '../../bytecode/Compressor.js';
@@ -102,6 +102,7 @@ export class SharedInteractionTransaction extends TransactionBuilder {
102
102
  internalPubkey: this.internalPubKeyToXOnly(),
103
103
  network: this.network,
104
104
  scriptTree: this.scriptTree,
105
+ name: PaymentType.P2TR,
105
106
  };
106
107
  }
107
108
  generateTapData() {
@@ -119,6 +120,7 @@ export class SharedInteractionTransaction extends TransactionBuilder {
119
120
  network: this.network,
120
121
  scriptTree: this.scriptTree,
121
122
  redeem: selectedRedeem,
123
+ name: PaymentType.P2TR,
122
124
  };
123
125
  }
124
126
  getScriptSolution(input) {
@@ -219,10 +221,12 @@ export class SharedInteractionTransaction extends TransactionBuilder {
219
221
  }
220
222
  generateRedeemScripts() {
221
223
  this.targetScriptRedeem = {
224
+ name: PaymentType.P2TR,
222
225
  output: this.compiledTargetScript,
223
226
  redeemVersion: 192,
224
227
  };
225
228
  this.leftOverFundsScriptRedeem = {
229
+ name: PaymentType.P2TR,
226
230
  output: SharedInteractionTransaction.LOCK_LEAF_SCRIPT,
227
231
  redeemVersion: 192,
228
232
  };
@@ -5,7 +5,7 @@ import { AddressVerificator } from '../../keypair/AddressVerificator.js';
5
5
  import { TweakedTransaction } from '../shared/TweakedTransaction.js';
6
6
  initEccLib(ecc);
7
7
  export const MINIMUM_AMOUNT_REWARD = 540n;
8
- export const MINIMUM_AMOUNT_CA = 330n;
8
+ export const MINIMUM_AMOUNT_CA = 297n;
9
9
  export class TransactionBuilder extends TweakedTransaction {
10
10
  constructor(parameters) {
11
11
  super(parameters);
@@ -386,6 +386,7 @@ export class TransactionBuilder extends TweakedTransaction {
386
386
  }
387
387
  }
388
388
  TransactionBuilder.LOCK_LEAF_SCRIPT = script.compile([
389
- opcodes.OP_0,
389
+ opcodes.OP_FALSE,
390
+ opcodes.OP_VERIFY,
390
391
  ]);
391
392
  TransactionBuilder.MINIMUM_DUST = 50n;
@@ -1,5 +1,5 @@
1
1
  import { Logger } from '@btc-vision/logger';
2
- import { Network, Payment, Psbt, PsbtInput, PsbtInputExtended, Signer, Transaction } from '@btc-vision/bitcoin';
2
+ import { Network, P2TRPayment, Psbt, PsbtInput, PsbtInputExtended, Signer, Transaction } from '@btc-vision/bitcoin';
3
3
  import { ECPairInterface } from 'ecpair';
4
4
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
5
5
  import { TapLeafScript } from '../interfaces/Tap.js';
@@ -24,8 +24,8 @@ export declare abstract class TweakedTransaction extends Logger {
24
24
  protected signed: boolean;
25
25
  protected abstract readonly transaction: Psbt;
26
26
  protected sighashTypes: number[] | undefined;
27
- protected scriptData: Payment | null;
28
- protected tapData: Payment | null;
27
+ protected scriptData: P2TRPayment | null;
28
+ protected tapData: P2TRPayment | null;
29
29
  protected readonly inputs: PsbtInputExtended[];
30
30
  protected sequence: number;
31
31
  protected tapLeafScript: TapLeafScript | null;
@@ -45,8 +45,8 @@ export declare abstract class TweakedTransaction extends Logger {
45
45
  disableRBF(): void;
46
46
  getTweakerHash(): Buffer | undefined;
47
47
  preEstimateTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numSignatures: bigint, numPubkeys: bigint): bigint;
48
- protected generateTapData(): Payment;
49
- protected generateScriptAddress(): Payment;
48
+ protected generateTapData(): P2TRPayment;
49
+ protected generateScriptAddress(): P2TRPayment;
50
50
  protected getSignerKey(): Signer | ECPairInterface;
51
51
  protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer | ECPairInterface, reverse?: boolean, errored?: boolean): Promise<void>;
52
52
  protected splitArray<T>(arr: T[], chunkSize: number): T[][];
@@ -1,5 +1,5 @@
1
1
  import { Logger } from '@btc-vision/logger';
2
- import { address as bitAddress, crypto as bitCrypto, getFinalScripts, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, opcodes, payments, script, toXOnly, varuint, } from '@btc-vision/bitcoin';
2
+ import { address as bitAddress, crypto as bitCrypto, getFinalScripts, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, opcodes, payments, PaymentType, script, toXOnly, varuint, } from '@btc-vision/bitcoin';
3
3
  import { TweakedSigner } from '../../signer/TweakedSigner.js';
4
4
  import { canSignNonTaprootInput, isTaprootInput, pubkeyInScript, } from '../../signer/SignerUtils.js';
5
5
  export var TransactionSequence;
@@ -47,8 +47,8 @@ export class TweakedTransaction extends Logger {
47
47
  }
48
48
  function readVarInt() {
49
49
  const varint = varuint.decode(Buffer, offset);
50
- offset += varuint.decode.bytes;
51
- return varint;
50
+ offset += varint.bytes;
51
+ return varint.numberValue || 0;
52
52
  }
53
53
  function readVarSlice() {
54
54
  const len = readVarInt();
@@ -140,12 +140,14 @@ export class TweakedTransaction extends Logger {
140
140
  return {
141
141
  internalPubkey: this.internalPubKeyToXOnly(),
142
142
  network: this.network,
143
+ name: PaymentType.P2TR,
143
144
  };
144
145
  }
145
146
  generateScriptAddress() {
146
147
  return {
147
148
  internalPubkey: this.internalPubKeyToXOnly(),
148
149
  network: this.network,
150
+ name: PaymentType.P2TR,
149
151
  };
150
152
  }
151
153
  getSignerKey() {
@@ -37,7 +37,6 @@ export class TapscriptVerificator {
37
37
  network: network,
38
38
  scriptTree: scriptTree,
39
39
  redeem: {
40
- pubkeys: [params.deployerPubKey, params.contractSaltPubKey],
41
40
  output: compiledTargetScript,
42
41
  redeemVersion: TapscriptVerificator.TAP_SCRIPT_VERSION,
43
42
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.5.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": {
@@ -64,16 +64,16 @@
64
64
  "docs": "typedoc --out docs --exclude 'src/tests/*.ts' --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/tests/test.ts --exclude src/index.ts src"
65
65
  },
66
66
  "devDependencies": {
67
- "@babel/core": "^7.26.9",
67
+ "@babel/core": "^7.27.3",
68
68
  "@babel/plugin-proposal-class-properties": "^7.18.6",
69
- "@babel/plugin-transform-runtime": "^7.26.9",
70
- "@babel/preset-env": "^7.26.9",
71
- "@babel/preset-flow": "^7.25.9",
72
- "@babel/preset-react": "^7.26.3",
73
- "@babel/preset-typescript": "^7.26.0",
74
- "@types/node": "^22.13.10",
69
+ "@babel/plugin-transform-runtime": "^7.27.3",
70
+ "@babel/preset-env": "^7.27.2",
71
+ "@babel/preset-flow": "^7.27.1",
72
+ "@babel/preset-react": "^7.27.1",
73
+ "@babel/preset-typescript": "^7.27.1",
74
+ "@types/node": "^22.15.26",
75
75
  "@types/sha.js": "^2.4.4",
76
- "eslint": "^9.22.0",
76
+ "eslint": "^9.27.0",
77
77
  "gulp": "^5.0.0",
78
78
  "gulp-cached": "^1.1.1",
79
79
  "gulp-typescript": "^6.0.0-alpha.1",
@@ -82,20 +82,20 @@
82
82
  "prettier": "^3.5.3",
83
83
  "stream-browserify": "^3.0.0",
84
84
  "stream-http": "^3.2.0",
85
- "typedoc": "^0.27.9",
86
- "typescript-eslint": "^8.26.0",
85
+ "typedoc": "^0.28.5",
86
+ "typescript-eslint": "^8.33.0",
87
87
  "webpack-cli": "^6.0.1"
88
88
  },
89
89
  "dependencies": {
90
90
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
91
91
  "@bitcoinerlab/secp256k1": "^1.1.1",
92
- "@btc-vision/bitcoin": "^6.3.6",
93
- "@btc-vision/bitcoin-rpc": "^1.0.0",
92
+ "@btc-vision/bitcoin": "^6.4.5",
93
+ "@btc-vision/bitcoin-rpc": "^1.0.1",
94
94
  "@btc-vision/logger": "^1.0.6",
95
- "@eslint/js": "^9.22.0",
96
- "@noble/secp256k1": "^2.1.0",
95
+ "@eslint/js": "^9.27.0",
96
+ "@noble/secp256k1": "^2.2.3",
97
97
  "assert": "^2.1.0",
98
- "babel-loader": "^9.2.1",
98
+ "babel-loader": "^10.0.0",
99
99
  "babel-plugin-transform-import-meta": "^2.3.2",
100
100
  "babel-preset-react": "^6.24.1",
101
101
  "babelify": "^10.0.0",
@@ -112,7 +112,7 @@
112
112
  "sha.js": "^2.4.11",
113
113
  "ts-loader": "^9.5.2",
114
114
  "ts-node": "^10.9.2",
115
- "typescript": "^5.7.3",
116
- "webpack": "^5.98.0"
115
+ "typescript": "^5.8.3",
116
+ "webpack": "^5.99.9"
117
117
  }
118
118
  }
@@ -182,7 +182,7 @@ export class BinaryReader {
182
182
  * Reads a string of the given length in raw bytes. By default, do NOT zero-stop
183
183
  * (matching how we wrote the raw bytes).
184
184
  */
185
- public readString(length: u16): string {
185
+ public readString(length: u32): string {
186
186
  const textDecoder = new TextDecoder();
187
187
  const bytes = this.readBytes(length, false);
188
188
  return textDecoder.decode(bytes);
@@ -192,7 +192,7 @@ export class BinaryReader {
192
192
  * Reads a string that was written as [u16 length][raw bytes].
193
193
  */
194
194
  public readStringWithLength(be: boolean = true): string {
195
- const length = this.readU16(be);
195
+ const length = this.readU32(be);
196
196
  return this.readString(length);
197
197
  }
198
198
 
@@ -160,9 +160,9 @@ export class BinaryWriter {
160
160
  }
161
161
 
162
162
  public writeStringWithLength(value: string): void {
163
- this.allocSafe(U16_BYTE_LENGTH + value.length);
163
+ this.allocSafe(U32_BYTE_LENGTH + value.length);
164
164
 
165
- this.writeU16(value.length);
165
+ this.writeU32(value.length);
166
166
  this.writeString(value);
167
167
  }
168
168
 
@@ -2,6 +2,9 @@ import { crypto, Network, networks, opcodes, script } from '@btc-vision/bitcoin'
2
2
  import { Generator } from '../Generator.js';
3
3
  import { Feature, Features } from '../Features.js';
4
4
 
5
+ export const OPNET_DEPLOYMENT_VERSION = 0x00;
6
+ export const versionBuffer = Buffer.from([OPNET_DEPLOYMENT_VERSION]);
7
+
5
8
  export class DeploymentGenerator extends Generator {
6
9
  constructor(
7
10
  senderPubKey: Buffer,
@@ -52,6 +55,7 @@ export class DeploymentGenerator extends Generator {
52
55
  if (!this.contractSaltPubKey) throw new Error('Contract salt public key not set');
53
56
 
54
57
  const dataChunks: Buffer[][] = this.splitBufferIntoChunks(contractBytecode);
58
+
55
59
  const calldataChunks: Buffer[][] = calldata ? this.splitBufferIntoChunks(calldata) : [];
56
60
 
57
61
  const featuresList: Features[] = [];
@@ -12,6 +12,7 @@ import { BitcoinUtils } from '../utils/BitcoinUtils.js';
12
12
  */
13
13
  export class Address extends Uint8Array {
14
14
  #p2tr: string | undefined;
15
+ #p2op: string | undefined;
15
16
  #network: Network | undefined;
16
17
  #originalPublicKey: Uint8Array | undefined;
17
18
  #keyPair: ECPairInterface | undefined;
@@ -316,6 +317,26 @@ export class Address extends Uint8Array {
316
317
  throw new Error('Public key not set');
317
318
  }
318
319
 
320
+ /**
321
+ * Get an opnet address encoded in bech32m format.
322
+ * @param network
323
+ */
324
+ public p2op(network: Network): string {
325
+ if (this.#p2op && this.#network === network) {
326
+ return this.#p2op;
327
+ }
328
+
329
+ const p2opAddy: string | undefined = EcKeyPair.p2op(this, network);
330
+ if (p2opAddy) {
331
+ this.#network = network;
332
+ this.#p2op = p2opAddy;
333
+
334
+ return p2opAddy;
335
+ }
336
+
337
+ throw new Error('Public key not set');
338
+ }
339
+
319
340
  public toTweakedHybridPublicKeyHex(): string {
320
341
  if (!this.#tweakedUncompressed) {
321
342
  throw new Error('Public key not set');
@@ -7,6 +7,7 @@ initEccLib(ecc);
7
7
 
8
8
  export enum AddressTypes {
9
9
  P2PKH = 'P2PKH',
10
+ P2OP = 'P2OP',
10
11
  P2SH_OR_P2SH_P2WPKH = 'P2SH_OR_P2SH-P2WPKH',
11
12
  P2PK = 'P2PK',
12
13
  P2TR = 'P2TR',
@@ -169,11 +170,11 @@ export class AddressVerificator {
169
170
  try {
170
171
  // First, try to decode as a Base58Check address (P2PKH, P2SH, or P2SH-P2WPKH)
171
172
  const decodedBase58 = address.fromBase58Check(addy);
172
-
173
173
  if (decodedBase58.version === network.pubKeyHash) {
174
174
  // P2PKH: Legacy address (starting with '1' for mainnet, 'm/n' for testnet)
175
175
  return AddressTypes.P2PKH;
176
176
  }
177
+
177
178
  if (decodedBase58.version === network.scriptHash) {
178
179
  // P2SH: Could be P2SH (general) or P2SH-P2WPKH (wrapped SegWit)
179
180
  return AddressTypes.P2SH_OR_P2SH_P2WPKH;
@@ -183,12 +184,16 @@ export class AddressVerificator {
183
184
  try {
184
185
  // Try to decode as a Bech32 or Bech32m address (P2WPKH or P2TR)
185
186
  const decodedBech32 = address.fromBech32(addy);
187
+ if (decodedBech32.prefix === network.bech32Opnet && decodedBech32.version === 16) {
188
+ return AddressTypes.P2OP;
189
+ }
186
190
 
187
191
  if (decodedBech32.prefix === network.bech32) {
188
192
  // P2WPKH: SegWit address (starting with 'bc1q' for mainnet, 'tb1q' for testnet)
189
193
  if (decodedBech32.version === 0 && decodedBech32.data.length === 20) {
190
194
  return AddressTypes.P2WPKH;
191
195
  }
196
+
192
197
  // P2TR: Taproot address (starting with 'bc1p' for mainnet, 'tb1p' for testnet)
193
198
  if (decodedBech32.version === 1 && decodedBech32.data.length === 32) {
194
199
  return AddressTypes.P2TR;