@btc-vision/transaction 1.5.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.
- package/browser/generators/builders/DeploymentGenerator.d.ts +2 -0
- package/browser/index.js +1 -1
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +3 -3
- package/browser/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/browser/transaction/builders/MultiSignTransaction.d.ts +5 -5
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -5
- package/build/generators/builders/DeploymentGenerator.d.ts +2 -0
- package/build/generators/builders/DeploymentGenerator.js +2 -0
- package/build/transaction/builders/CustomScriptTransaction.d.ts +3 -3
- package/build/transaction/builders/CustomScriptTransaction.js +5 -3
- package/build/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/build/transaction/builders/DeploymentTransaction.js +7 -6
- package/build/transaction/builders/MultiSignTransaction.d.ts +5 -5
- package/build/transaction/builders/MultiSignTransaction.js +5 -1
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
- package/build/transaction/builders/SharedInteractionTransaction.js +5 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -5
- package/build/transaction/shared/TweakedTransaction.js +3 -1
- package/build/verification/TapscriptVerificator.js +0 -1
- package/package.json +6 -6
- package/src/generators/builders/DeploymentGenerator.ts +4 -0
- package/src/transaction/builders/CustomScriptTransaction.ts +13 -7
- package/src/transaction/builders/DeploymentTransaction.ts +20 -12
- package/src/transaction/builders/MultiSignTransaction.ts +10 -6
- package/src/transaction/builders/SharedInteractionTransaction.ts +9 -5
- package/src/transaction/shared/TweakedTransaction.ts +8 -4
- package/src/verification/TapscriptVerificator.ts +1 -1
|
@@ -2,7 +2,8 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
2
2
|
import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
3
|
import {
|
|
4
4
|
crypto as bitCrypto,
|
|
5
|
-
|
|
5
|
+
P2TRPayment,
|
|
6
|
+
PaymentType,
|
|
6
7
|
Psbt,
|
|
7
8
|
PsbtInput,
|
|
8
9
|
Signer,
|
|
@@ -15,7 +16,10 @@ import {
|
|
|
15
16
|
TransactionBuilder,
|
|
16
17
|
} from './TransactionBuilder.js';
|
|
17
18
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
18
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
DeploymentGenerator,
|
|
21
|
+
versionBuffer,
|
|
22
|
+
} from '../../generators/builders/DeploymentGenerator.js';
|
|
19
23
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
20
24
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
21
25
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
@@ -25,11 +29,11 @@ import { Address } from '../../keypair/Address.js';
|
|
|
25
29
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
26
30
|
import { ChallengeGenerator, IMineableReward } from '../mineable/ChallengeGenerator.js';
|
|
27
31
|
|
|
28
|
-
const p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
|
|
29
|
-
|
|
30
32
|
export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
31
33
|
public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
34
|
+
|
|
32
35
|
public type: TransactionType.DEPLOYMENT = TransactionType.DEPLOYMENT;
|
|
36
|
+
|
|
33
37
|
protected readonly preimage: Buffer; // ALWAYS 128 bytes for the preimage
|
|
34
38
|
protected readonly rewardChallenge: IMineableReward;
|
|
35
39
|
/**
|
|
@@ -47,12 +51,12 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
47
51
|
* The target script redeem
|
|
48
52
|
* @private
|
|
49
53
|
*/
|
|
50
|
-
private targetScriptRedeem:
|
|
54
|
+
private targetScriptRedeem: P2TRPayment | null = null;
|
|
51
55
|
/**
|
|
52
56
|
* The left over funds script redeem
|
|
53
57
|
* @private
|
|
54
58
|
*/
|
|
55
|
-
private leftOverFundsScriptRedeem:
|
|
59
|
+
private leftOverFundsScriptRedeem: P2TRPayment | null = null;
|
|
56
60
|
/**
|
|
57
61
|
* The compiled target script
|
|
58
62
|
* @private
|
|
@@ -107,10 +111,10 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
107
111
|
private _computedAddress: string | undefined;
|
|
108
112
|
|
|
109
113
|
public constructor(parameters: IDeploymentParameters) {
|
|
110
|
-
// TODO: Add legacy deployment, this is only p2tr.
|
|
111
114
|
super(parameters);
|
|
112
115
|
|
|
113
|
-
this.bytecode = Compressor.compress(parameters.bytecode);
|
|
116
|
+
this.bytecode = Compressor.compress(Buffer.concat([versionBuffer, parameters.bytecode]));
|
|
117
|
+
|
|
114
118
|
this.verifyBytecode();
|
|
115
119
|
|
|
116
120
|
if (parameters.calldata) {
|
|
@@ -337,8 +341,9 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
337
341
|
* Get the tap output
|
|
338
342
|
* @protected
|
|
339
343
|
*/
|
|
340
|
-
protected override generateScriptAddress():
|
|
344
|
+
protected override generateScriptAddress(): P2TRPayment {
|
|
341
345
|
return {
|
|
346
|
+
name: PaymentType.P2TR,
|
|
342
347
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
343
348
|
network: this.network,
|
|
344
349
|
scriptTree: this.scriptTree,
|
|
@@ -349,7 +354,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
349
354
|
* Generate the tap data
|
|
350
355
|
* @protected
|
|
351
356
|
*/
|
|
352
|
-
protected override generateTapData():
|
|
357
|
+
protected override generateTapData(): P2TRPayment {
|
|
353
358
|
const selectedRedeem = this.contractSigner
|
|
354
359
|
? this.targetScriptRedeem
|
|
355
360
|
: this.leftOverFundsScriptRedeem;
|
|
@@ -363,6 +368,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
363
368
|
}
|
|
364
369
|
|
|
365
370
|
return {
|
|
371
|
+
name: PaymentType.P2TR,
|
|
366
372
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
367
373
|
network: this.network,
|
|
368
374
|
scriptTree: this.scriptTree,
|
|
@@ -454,13 +460,15 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
454
460
|
*/
|
|
455
461
|
private generateRedeemScripts(): void {
|
|
456
462
|
this.targetScriptRedeem = {
|
|
457
|
-
|
|
463
|
+
name: PaymentType.P2TR,
|
|
464
|
+
//pubkeys: this.getPubKeys(),
|
|
458
465
|
output: this.compiledTargetScript,
|
|
459
466
|
redeemVersion: 192,
|
|
460
467
|
};
|
|
461
468
|
|
|
462
469
|
this.leftOverFundsScriptRedeem = {
|
|
463
|
-
|
|
470
|
+
name: PaymentType.P2TR,
|
|
471
|
+
//pubkeys: this.getPubKeys(),
|
|
464
472
|
output: this.getLeafScript(),
|
|
465
473
|
redeemVersion: 192,
|
|
466
474
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
crypto as bitcoinCrypto,
|
|
3
3
|
opcodes,
|
|
4
|
-
|
|
4
|
+
P2TRPayment,
|
|
5
|
+
PaymentType,
|
|
5
6
|
Psbt,
|
|
6
7
|
PsbtInput,
|
|
7
8
|
PsbtInputExtended,
|
|
@@ -58,8 +59,8 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
58
59
|
|
|
59
60
|
public type: TransactionType.MULTI_SIG = TransactionType.MULTI_SIG;
|
|
60
61
|
|
|
61
|
-
protected targetScriptRedeem:
|
|
62
|
-
protected leftOverFundsScriptRedeem:
|
|
62
|
+
protected targetScriptRedeem: P2TRPayment | null = null;
|
|
63
|
+
protected leftOverFundsScriptRedeem: P2TRPayment | null = null;
|
|
63
64
|
|
|
64
65
|
protected readonly compiledTargetScript: Buffer;
|
|
65
66
|
protected readonly scriptTree: Taptree;
|
|
@@ -545,16 +546,16 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
545
546
|
*/
|
|
546
547
|
protected override async signInputs(_transaction: Psbt): Promise<void> {}
|
|
547
548
|
|
|
548
|
-
protected override generateScriptAddress():
|
|
549
|
+
protected override generateScriptAddress(): P2TRPayment {
|
|
549
550
|
return {
|
|
550
551
|
internalPubkey: toXOnly(MultiSignTransaction.numsPoint), //this.internalPubKeyToXOnly(),
|
|
551
552
|
network: this.network,
|
|
552
553
|
scriptTree: this.scriptTree,
|
|
553
|
-
|
|
554
|
+
name: PaymentType.P2TR,
|
|
554
555
|
};
|
|
555
556
|
}
|
|
556
557
|
|
|
557
|
-
protected override generateTapData():
|
|
558
|
+
protected override generateTapData(): P2TRPayment {
|
|
558
559
|
const selectedRedeem = this.targetScriptRedeem;
|
|
559
560
|
if (!selectedRedeem) {
|
|
560
561
|
throw new Error('Left over funds script redeem is required');
|
|
@@ -569,6 +570,7 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
569
570
|
network: this.network,
|
|
570
571
|
scriptTree: this.scriptTree,
|
|
571
572
|
redeem: selectedRedeem,
|
|
573
|
+
name: PaymentType.P2TR,
|
|
572
574
|
};
|
|
573
575
|
}
|
|
574
576
|
|
|
@@ -662,11 +664,13 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
662
664
|
*/
|
|
663
665
|
private generateRedeemScripts(): void {
|
|
664
666
|
this.targetScriptRedeem = {
|
|
667
|
+
name: PaymentType.P2TR,
|
|
665
668
|
output: this.compiledTargetScript,
|
|
666
669
|
redeemVersion: 192,
|
|
667
670
|
};
|
|
668
671
|
|
|
669
672
|
this.leftOverFundsScriptRedeem = {
|
|
673
|
+
name: PaymentType.P2TR,
|
|
670
674
|
output: MultiSignTransaction.LOCK_LEAF_SCRIPT,
|
|
671
675
|
redeemVersion: 192,
|
|
672
676
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { address,
|
|
1
|
+
import { address, P2TRPayment, PaymentType, Psbt, PsbtInput, Signer, Taptree, toXOnly } from '@btc-vision/bitcoin';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { MINIMUM_AMOUNT_CA, MINIMUM_AMOUNT_REWARD, TransactionBuilder } from './TransactionBuilder.js';
|
|
4
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -25,8 +25,8 @@ export abstract class SharedInteractionTransaction<
|
|
|
25
25
|
*/
|
|
26
26
|
public readonly randomBytes: Buffer;
|
|
27
27
|
|
|
28
|
-
protected targetScriptRedeem:
|
|
29
|
-
protected leftOverFundsScriptRedeem:
|
|
28
|
+
protected targetScriptRedeem: P2TRPayment | null = null;
|
|
29
|
+
protected leftOverFundsScriptRedeem: P2TRPayment | null = null;
|
|
30
30
|
|
|
31
31
|
protected abstract readonly compiledTargetScript: Buffer;
|
|
32
32
|
protected abstract readonly scriptTree: Taptree;
|
|
@@ -207,15 +207,16 @@ export abstract class SharedInteractionTransaction<
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
protected override generateScriptAddress():
|
|
210
|
+
protected override generateScriptAddress(): P2TRPayment {
|
|
211
211
|
return {
|
|
212
212
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
213
213
|
network: this.network,
|
|
214
214
|
scriptTree: this.scriptTree,
|
|
215
|
+
name: PaymentType.P2TR,
|
|
215
216
|
};
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
protected override generateTapData():
|
|
219
|
+
protected override generateTapData(): P2TRPayment {
|
|
219
220
|
const selectedRedeem = this.scriptSigner
|
|
220
221
|
? this.targetScriptRedeem
|
|
221
222
|
: this.leftOverFundsScriptRedeem;
|
|
@@ -233,6 +234,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
233
234
|
network: this.network,
|
|
234
235
|
scriptTree: this.scriptTree,
|
|
235
236
|
redeem: selectedRedeem,
|
|
237
|
+
name: PaymentType.P2TR,
|
|
236
238
|
};
|
|
237
239
|
}
|
|
238
240
|
|
|
@@ -416,11 +418,13 @@ export abstract class SharedInteractionTransaction<
|
|
|
416
418
|
*/
|
|
417
419
|
private generateRedeemScripts(): void {
|
|
418
420
|
this.targetScriptRedeem = {
|
|
421
|
+
name: PaymentType.P2TR,
|
|
419
422
|
output: this.compiledTargetScript,
|
|
420
423
|
redeemVersion: 192,
|
|
421
424
|
};
|
|
422
425
|
|
|
423
426
|
this.leftOverFundsScriptRedeem = {
|
|
427
|
+
name: PaymentType.P2TR,
|
|
424
428
|
output: SharedInteractionTransaction.LOCK_LEAF_SCRIPT,
|
|
425
429
|
redeemVersion: 192,
|
|
426
430
|
};
|
|
@@ -12,8 +12,10 @@ import {
|
|
|
12
12
|
isP2WSHScript,
|
|
13
13
|
Network,
|
|
14
14
|
opcodes,
|
|
15
|
+
P2TRPayment,
|
|
15
16
|
Payment,
|
|
16
17
|
payments,
|
|
18
|
+
PaymentType,
|
|
17
19
|
Psbt,
|
|
18
20
|
PsbtInput,
|
|
19
21
|
PsbtInputExtended,
|
|
@@ -91,11 +93,11 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
91
93
|
/**
|
|
92
94
|
* @description The script data of the transaction
|
|
93
95
|
*/
|
|
94
|
-
protected scriptData:
|
|
96
|
+
protected scriptData: P2TRPayment | null = null;
|
|
95
97
|
/**
|
|
96
98
|
* @description The tap data of the transaction
|
|
97
99
|
*/
|
|
98
|
-
protected tapData:
|
|
100
|
+
protected tapData: P2TRPayment | null = null;
|
|
99
101
|
/**
|
|
100
102
|
* @description The inputs of the transaction
|
|
101
103
|
*/
|
|
@@ -345,10 +347,11 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
345
347
|
return vSize * feeRate;
|
|
346
348
|
}
|
|
347
349
|
|
|
348
|
-
protected generateTapData():
|
|
350
|
+
protected generateTapData(): P2TRPayment {
|
|
349
351
|
return {
|
|
350
352
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
351
353
|
network: this.network,
|
|
354
|
+
name: PaymentType.P2TR,
|
|
352
355
|
};
|
|
353
356
|
}
|
|
354
357
|
|
|
@@ -357,10 +360,11 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
357
360
|
* @protected
|
|
358
361
|
* @returns {Payment}
|
|
359
362
|
*/
|
|
360
|
-
protected generateScriptAddress():
|
|
363
|
+
protected generateScriptAddress(): P2TRPayment {
|
|
361
364
|
return {
|
|
362
365
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
363
366
|
network: this.network,
|
|
367
|
+
name: PaymentType.P2TR,
|
|
364
368
|
};
|
|
365
369
|
}
|
|
366
370
|
|
|
@@ -91,7 +91,7 @@ export class TapscriptVerificator {
|
|
|
91
91
|
network: network,
|
|
92
92
|
scriptTree: scriptTree,
|
|
93
93
|
redeem: {
|
|
94
|
-
pubkeys: [params.deployerPubKey, params.contractSaltPubKey],
|
|
94
|
+
//pubkeys: [params.deployerPubKey, params.contractSaltPubKey],
|
|
95
95
|
output: compiledTargetScript,
|
|
96
96
|
redeemVersion: TapscriptVerificator.TAP_SCRIPT_VERSION,
|
|
97
97
|
},
|