@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.
- package/browser/buffer/BinaryReader.d.ts +1 -1
- package/browser/generators/builders/DeploymentGenerator.d.ts +2 -0
- package/browser/index.js +1 -1
- package/browser/index.js.LICENSE.txt +1 -3
- package/browser/keypair/Address.d.ts +1 -0
- package/browser/keypair/AddressVerificator.d.ts +1 -0
- package/browser/keypair/EcKeyPair.d.ts +4 -1
- package/browser/transaction/TransactionFactory.d.ts +0 -1
- package/browser/transaction/browser/Web3Provider.d.ts +2 -0
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +9 -6
- package/browser/transaction/builders/DeploymentTransaction.d.ts +6 -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/buffer/BinaryReader.d.ts +1 -1
- package/build/buffer/BinaryReader.js +1 -1
- package/build/buffer/BinaryWriter.js +2 -2
- package/build/generators/builders/DeploymentGenerator.d.ts +2 -0
- package/build/generators/builders/DeploymentGenerator.js +2 -0
- package/build/keypair/Address.d.ts +1 -0
- package/build/keypair/Address.js +15 -2
- package/build/keypair/AddressVerificator.d.ts +1 -0
- package/build/keypair/AddressVerificator.js +4 -0
- package/build/keypair/EcKeyPair.d.ts +4 -1
- package/build/keypair/EcKeyPair.js +48 -21
- package/build/transaction/TransactionFactory.d.ts +0 -1
- package/build/transaction/TransactionFactory.js +18 -4
- package/build/transaction/browser/Web3Provider.d.ts +2 -0
- package/build/transaction/builders/CustomScriptTransaction.d.ts +9 -6
- package/build/transaction/builders/CustomScriptTransaction.js +29 -6
- package/build/transaction/builders/DeploymentTransaction.d.ts +6 -3
- package/build/transaction/builders/DeploymentTransaction.js +16 -7
- 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/builders/TransactionBuilder.js +3 -2
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -5
- package/build/transaction/shared/TweakedTransaction.js +5 -3
- package/build/verification/TapscriptVerificator.js +0 -1
- package/package.json +18 -18
- package/src/buffer/BinaryReader.ts +2 -2
- package/src/buffer/BinaryWriter.ts +2 -2
- package/src/generators/builders/DeploymentGenerator.ts +4 -0
- package/src/keypair/Address.ts +21 -0
- package/src/keypair/AddressVerificator.ts +6 -1
- package/src/keypair/EcKeyPair.ts +91 -34
- package/src/transaction/TransactionFactory.ts +21 -7
- package/src/transaction/browser/Web3Provider.ts +6 -0
- package/src/transaction/builders/CustomScriptTransaction.ts +51 -14
- package/src/transaction/builders/DeploymentTransaction.ts +36 -14
- package/src/transaction/builders/MultiSignTransaction.ts +10 -6
- package/src/transaction/builders/SharedInteractionTransaction.ts +9 -5
- package/src/transaction/builders/TransactionBuilder.ts +4 -3
- package/src/transaction/shared/TweakedTransaction.ts +10 -6
- package/src/verification/TapscriptVerificator.ts +1 -1
|
@@ -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
|
};
|
|
@@ -27,7 +27,7 @@ import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
|
27
27
|
initEccLib(ecc);
|
|
28
28
|
|
|
29
29
|
export const MINIMUM_AMOUNT_REWARD: bigint = 540n;
|
|
30
|
-
export const MINIMUM_AMOUNT_CA: bigint =
|
|
30
|
+
export const MINIMUM_AMOUNT_CA: bigint = 297n;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Allows to build a transaction like you would on Ethereum.
|
|
@@ -36,9 +36,10 @@ export const MINIMUM_AMOUNT_CA: bigint = 330n;
|
|
|
36
36
|
* @class TransactionBuilder
|
|
37
37
|
*/
|
|
38
38
|
export abstract class TransactionBuilder<T extends TransactionType> extends TweakedTransaction {
|
|
39
|
+
// Cancel script
|
|
39
40
|
public static readonly LOCK_LEAF_SCRIPT: Buffer = script.compile([
|
|
40
|
-
opcodes.
|
|
41
|
-
|
|
41
|
+
opcodes.OP_FALSE,
|
|
42
|
+
opcodes.OP_VERIFY,
|
|
42
43
|
]);
|
|
43
44
|
|
|
44
45
|
public static readonly MINIMUM_DUST: bigint = 50n;
|
|
@@ -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
|
*/
|
|
@@ -151,8 +153,8 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
151
153
|
|
|
152
154
|
function readVarInt(): number {
|
|
153
155
|
const varint = varuint.decode(Buffer, offset);
|
|
154
|
-
offset +=
|
|
155
|
-
return varint;
|
|
156
|
+
offset += varint.bytes;
|
|
157
|
+
return varint.numberValue || 0;
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
function readVarSlice(): Buffer {
|
|
@@ -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
|
},
|