@btc-vision/transaction 1.0.116 → 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.
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +1 -0
- package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -2
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -3
- package/browser/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/browser/transaction/builders/UnwrapTransaction.d.ts +1 -2
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/browser/transaction/interfaces/Tap.d.ts +20 -10
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -2
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -3
- package/browser/verification/TapscriptVerificator.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryWriter.js +2 -2
- package/build/keypair/Address.d.ts +1 -0
- package/build/keypair/Address.js +27 -20
- package/build/keypair/Wallet.js +1 -1
- package/build/transaction/builders/DeploymentTransaction.js +3 -3
- package/build/transaction/builders/MultiSignTransaction.d.ts +1 -2
- package/build/transaction/builders/MultiSignTransaction.js +1 -1
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -3
- package/build/transaction/builders/SharedInteractionTransaction.js +7 -43
- package/build/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/transaction/builders/TransactionBuilder.js +1 -1
- package/build/transaction/builders/UnwrapTransaction.d.ts +1 -2
- package/build/transaction/builders/UnwrapTransaction.js +1 -1
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/transaction/interfaces/Tap.d.ts +20 -10
- package/build/transaction/processor/PsbtTransaction.d.ts +1 -2
- package/build/transaction/processor/PsbtTransaction.js +1 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +2 -3
- package/build/transaction/shared/TweakedTransaction.js +1 -1
- package/build/verification/TapscriptVerificator.d.ts +1 -0
- package/build/verification/TapscriptVerificator.js +31 -0
- package/eslint.config.js +1 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryWriter.ts +2 -2
- package/src/keypair/Address.ts +37 -17
- package/src/keypair/Wallet.ts +1 -1
- package/src/transaction/browser/extensions/UnisatSigner.ts +1 -2
- package/src/transaction/builders/CustomScriptTransaction.ts +1 -2
- package/src/transaction/builders/DeploymentTransaction.ts +4 -6
- package/src/transaction/builders/InteractionTransaction.ts +1 -1
- package/src/transaction/builders/MultiSignTransaction.ts +12 -3
- package/src/transaction/builders/SharedInteractionTransaction.ts +11 -68
- package/src/transaction/builders/TransactionBuilder.ts +12 -2
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +2 -2
- package/src/transaction/builders/UnwrapTransaction.ts +9 -3
- package/src/transaction/builders/WrapTransaction.ts +2 -2
- package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
- package/src/transaction/interfaces/Tap.ts +31 -12
- package/src/transaction/processor/PsbtTransaction.ts +9 -2
- package/src/transaction/shared/TweakedTransaction.ts +11 -3
- package/src/verification/TapscriptVerificator.ts +48 -0
|
@@ -6,6 +6,7 @@ export declare class Address extends Uint8Array {
|
|
|
6
6
|
constructor(bytes?: ArrayLike<number>);
|
|
7
7
|
private _keyPair;
|
|
8
8
|
get keyPair(): ECPairInterface;
|
|
9
|
+
get tweakedBytes(): Uint8Array;
|
|
9
10
|
static dead(): Address;
|
|
10
11
|
static fromString(pubKey: string): Address;
|
|
11
12
|
static wrap(bytes: ArrayLike<number>): Address;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput, TapScriptSig } from '
|
|
2
|
-
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
1
|
+
import { Payment, Psbt, PsbtInput, Signer, TapScriptSig } from 'bitcoinjs-lib';
|
|
3
2
|
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
4
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput } from '
|
|
2
|
-
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
1
|
+
import { 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';
|
|
@@ -33,7 +32,6 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
33
32
|
protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
|
|
34
33
|
finalScriptWitness: Buffer;
|
|
35
34
|
};
|
|
36
|
-
private signIndividualInputs;
|
|
37
35
|
private getPubKeys;
|
|
38
36
|
private generateRedeemScripts;
|
|
39
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
-
import {
|
|
1
|
+
import { Network, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
+
import { UpdateInput } from '../interfaces/Tap.js';
|
|
3
3
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
4
|
import { IFundingTransactionParameters, ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
5
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
@@ -2,9 +2,8 @@ import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
4
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Network, Payment, Psbt } from 'bitcoinjs-lib';
|
|
5
|
+
import { Network, Payment, Psbt, PsbtInput } from 'bitcoinjs-lib';
|
|
6
6
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
8
7
|
export declare class UnwrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
9
8
|
private static readonly UNWRAP_SELECTOR;
|
|
10
9
|
type: TransactionType.WBTC_UNWRAP;
|
|
@@ -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
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
9
9
|
readonly from?: string;
|
|
10
10
|
readonly to?: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput, PsbtOutput } from '
|
|
2
|
-
import { TransactionInput } from 'bitcoinjs-lib/src/psbt.js';
|
|
1
|
+
import { PsbtInput as _PsbtInput, PsbtInputUpdate as _PsbtInputUpdate, PsbtOutput as _PsbtOutput, TapBip32Derivation as _TapBip32Derivation, TapInternalKey as _TapInternalKey, TapKeySig as _TapKeySig, TapLeaf as _TapLeaf, TapLeafScript as _TapLeafScript, TapMerkleRoot as _TapMerkleRoot, TapScriptSig as _TapScriptSig, TapTree as _TapTree } from 'bitcoinjs-lib';
|
|
3
2
|
export interface TapLeafScript {
|
|
4
3
|
readonly leafVersion: number;
|
|
5
4
|
readonly controlBlock: Buffer;
|
|
@@ -8,14 +7,25 @@ export interface TapLeafScript {
|
|
|
8
7
|
export interface UpdateInput {
|
|
9
8
|
tapLeafScript: TapLeafScript[];
|
|
10
9
|
}
|
|
11
|
-
export interface
|
|
10
|
+
export interface PsbtInput extends _PsbtInput {
|
|
12
11
|
}
|
|
13
|
-
export interface
|
|
14
|
-
address: string;
|
|
15
|
-
value: number;
|
|
12
|
+
export interface PsbtOutput extends _PsbtOutput {
|
|
16
13
|
}
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export interface TapInternalKey extends _TapInternalKey {
|
|
15
|
+
}
|
|
16
|
+
export interface TapLeaf extends _TapLeaf {
|
|
17
|
+
}
|
|
18
|
+
export interface TapScriptSig extends _TapScriptSig {
|
|
19
|
+
}
|
|
20
|
+
export interface TapKeySig extends _TapKeySig {
|
|
21
|
+
}
|
|
22
|
+
export interface TapTree extends _TapTree {
|
|
23
|
+
}
|
|
24
|
+
export interface TapMerkleRoot extends _TapMerkleRoot {
|
|
25
|
+
}
|
|
26
|
+
export interface TapLeafScript extends _TapLeafScript {
|
|
27
|
+
}
|
|
28
|
+
export interface TapBip32Derivation extends _TapBip32Derivation {
|
|
29
|
+
}
|
|
30
|
+
export interface PsbtInputUpdate extends _PsbtInputUpdate {
|
|
20
31
|
}
|
|
21
|
-
export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
-
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
1
|
+
import { Network, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
2
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
4
3
|
export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
5
4
|
readonly psbt: Psbt;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Logger } from '@btc-vision/logger';
|
|
2
|
-
import { Network, Payment, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
+
import { Network, Payment, Psbt, PsbtInput, PsbtInputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
3
|
import { ECPairInterface } from 'ecpair';
|
|
4
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
5
4
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
6
|
-
import {
|
|
5
|
+
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
7
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
8
7
|
export interface ITweakedTransactionData {
|
|
9
8
|
readonly signer: Signer | ECPairInterface;
|
|
@@ -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;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.117";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.117';
|
|
@@ -240,10 +240,10 @@ export class BinaryWriter {
|
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
fromAddress(pubKey) {
|
|
243
|
-
if (pubKey.byteLength > ADDRESS_BYTE_LENGTH) {
|
|
243
|
+
if (pubKey.tweakedBytes.byteLength > ADDRESS_BYTE_LENGTH) {
|
|
244
244
|
throw new Error(`Address is too long ${pubKey.byteLength} > ${ADDRESS_BYTE_LENGTH} bytes`);
|
|
245
245
|
}
|
|
246
|
-
return pubKey;
|
|
246
|
+
return pubKey.tweakedBytes;
|
|
247
247
|
}
|
|
248
248
|
resize(size) {
|
|
249
249
|
const buf = new Uint8Array(this.buffer.byteLength + size);
|
|
@@ -6,6 +6,7 @@ export declare class Address extends Uint8Array {
|
|
|
6
6
|
constructor(bytes?: ArrayLike<number>);
|
|
7
7
|
private _keyPair;
|
|
8
8
|
get keyPair(): ECPairInterface;
|
|
9
|
+
get tweakedBytes(): Uint8Array;
|
|
9
10
|
static dead(): Address;
|
|
10
11
|
static fromString(pubKey: string): Address;
|
|
11
12
|
static wrap(bytes: ArrayLike<number>): Address;
|
package/build/keypair/Address.js
CHANGED
|
@@ -9,17 +9,18 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _Address_p2tr, _Address_network;
|
|
12
|
+
var _Address_p2tr, _Address_network, _Address_tweakedBytes;
|
|
13
13
|
import { EcKeyPair } from './EcKeyPair.js';
|
|
14
14
|
import { ADDRESS_BYTE_LENGTH } from '../utils/types.js';
|
|
15
15
|
import { AddressVerificator } from './AddressVerificator.js';
|
|
16
16
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
17
17
|
export class Address extends Uint8Array {
|
|
18
18
|
constructor(bytes) {
|
|
19
|
-
super(ADDRESS_BYTE_LENGTH);
|
|
19
|
+
super(bytes?.length || ADDRESS_BYTE_LENGTH);
|
|
20
20
|
this.isP2TROnly = false;
|
|
21
21
|
_Address_p2tr.set(this, void 0);
|
|
22
22
|
_Address_network.set(this, void 0);
|
|
23
|
+
_Address_tweakedBytes.set(this, void 0);
|
|
23
24
|
if (!bytes) {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
@@ -31,10 +32,16 @@ export class Address extends Uint8Array {
|
|
|
31
32
|
}
|
|
32
33
|
return this._keyPair;
|
|
33
34
|
}
|
|
35
|
+
get tweakedBytes() {
|
|
36
|
+
return __classPrivateFieldGet(this, _Address_tweakedBytes, "f") || this;
|
|
37
|
+
}
|
|
34
38
|
static dead() {
|
|
35
39
|
return Address.fromString('0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f');
|
|
36
40
|
}
|
|
37
41
|
static fromString(pubKey) {
|
|
42
|
+
if (!pubKey) {
|
|
43
|
+
throw new Error('Invalid public key');
|
|
44
|
+
}
|
|
38
45
|
if (pubKey.startsWith('0x')) {
|
|
39
46
|
pubKey = pubKey.slice(2);
|
|
40
47
|
}
|
|
@@ -47,20 +54,24 @@ export class Address extends Uint8Array {
|
|
|
47
54
|
return '0x' + Buffer.from(this).toString('hex');
|
|
48
55
|
}
|
|
49
56
|
equals(a) {
|
|
50
|
-
|
|
57
|
+
const b = this.isP2TROnly ? this : __classPrivateFieldGet(this, _Address_tweakedBytes, "f");
|
|
58
|
+
const c = a.isP2TROnly ? a : __classPrivateFieldGet(a, _Address_tweakedBytes, "f");
|
|
59
|
+
if (c.length !== b.length) {
|
|
51
60
|
return false;
|
|
52
61
|
}
|
|
53
|
-
for (let i = 0; i <
|
|
54
|
-
if (
|
|
62
|
+
for (let i = 0; i < b.length; i++) {
|
|
63
|
+
if (b[i] !== c[i]) {
|
|
55
64
|
return false;
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
return true;
|
|
59
68
|
}
|
|
60
69
|
lessThan(a) {
|
|
70
|
+
const b = this.isP2TROnly ? this : __classPrivateFieldGet(this, _Address_tweakedBytes, "f");
|
|
71
|
+
const c = a.isP2TROnly ? a : __classPrivateFieldGet(a, _Address_tweakedBytes, "f");
|
|
61
72
|
for (let i = 0; i < 32; i++) {
|
|
62
|
-
const thisByte =
|
|
63
|
-
const aByte =
|
|
73
|
+
const thisByte = b[i];
|
|
74
|
+
const aByte = c[i];
|
|
64
75
|
if (thisByte < aByte) {
|
|
65
76
|
return true;
|
|
66
77
|
}
|
|
@@ -71,9 +82,11 @@ export class Address extends Uint8Array {
|
|
|
71
82
|
return false;
|
|
72
83
|
}
|
|
73
84
|
greaterThan(a) {
|
|
85
|
+
const b = this.isP2TROnly ? this : __classPrivateFieldGet(this, _Address_tweakedBytes, "f");
|
|
86
|
+
const c = a.isP2TROnly ? a : __classPrivateFieldGet(a, _Address_tweakedBytes, "f");
|
|
74
87
|
for (let i = 0; i < 32; i++) {
|
|
75
|
-
const thisByte =
|
|
76
|
-
const aByte =
|
|
88
|
+
const thisByte = b[i];
|
|
89
|
+
const aByte = c[i];
|
|
77
90
|
if (thisByte > aByte) {
|
|
78
91
|
return true;
|
|
79
92
|
}
|
|
@@ -85,7 +98,7 @@ export class Address extends Uint8Array {
|
|
|
85
98
|
}
|
|
86
99
|
set(publicKey) {
|
|
87
100
|
if (publicKey.length !== 33 && publicKey.length !== 32 && publicKey.length !== 65) {
|
|
88
|
-
throw new Error(
|
|
101
|
+
throw new Error(`Invalid public key length ${publicKey.length}`);
|
|
89
102
|
}
|
|
90
103
|
if (publicKey.length === 32) {
|
|
91
104
|
this.isP2TROnly = true;
|
|
@@ -95,8 +108,8 @@ export class Address extends Uint8Array {
|
|
|
95
108
|
}
|
|
96
109
|
else {
|
|
97
110
|
this._keyPair = EcKeyPair.fromPublicKey(Uint8Array.from(publicKey));
|
|
98
|
-
|
|
99
|
-
super.set(
|
|
111
|
+
__classPrivateFieldSet(this, _Address_tweakedBytes, toXOnly(Buffer.from(EcKeyPair.tweakPublicKey(this._keyPair.publicKey.toString('hex')), 'hex')), "f");
|
|
112
|
+
super.set(publicKey);
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
isValid(network) {
|
|
@@ -121,13 +134,7 @@ export class Address extends Uint8Array {
|
|
|
121
134
|
if (__classPrivateFieldGet(this, _Address_p2tr, "f") && __classPrivateFieldGet(this, _Address_network, "f") === network) {
|
|
122
135
|
return __classPrivateFieldGet(this, _Address_p2tr, "f");
|
|
123
136
|
}
|
|
124
|
-
|
|
125
|
-
if (this._keyPair) {
|
|
126
|
-
p2trAddy = EcKeyPair.getTaprootAddress(this.keyPair, network);
|
|
127
|
-
}
|
|
128
|
-
else if (this.isP2TROnly) {
|
|
129
|
-
p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this, network);
|
|
130
|
-
}
|
|
137
|
+
const p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this.isP2TROnly ? this : __classPrivateFieldGet(this, _Address_tweakedBytes, "f"), network);
|
|
131
138
|
if (p2trAddy) {
|
|
132
139
|
__classPrivateFieldSet(this, _Address_network, network, "f");
|
|
133
140
|
__classPrivateFieldSet(this, _Address_p2tr, p2trAddy, "f");
|
|
@@ -136,4 +143,4 @@ export class Address extends Uint8Array {
|
|
|
136
143
|
throw new Error('Public key not set');
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
|
-
_Address_p2tr = new WeakMap(), _Address_network = new WeakMap();
|
|
146
|
+
_Address_p2tr = new WeakMap(), _Address_network = new WeakMap(), _Address_tweakedBytes = new WeakMap();
|
package/build/keypair/Wallet.js
CHANGED
|
@@ -11,7 +11,7 @@ export class Wallet {
|
|
|
11
11
|
this._legacy = EcKeyPair.getLegacyAddress(this._keypair, this.network);
|
|
12
12
|
this._segwitLegacy = EcKeyPair.getLegacySegwitAddress(this._keypair, this.network);
|
|
13
13
|
this._tweakedKey = Buffer.from(EcKeyPair.tweakPublicKey(this._keypair.publicKey.toString('hex')), 'hex');
|
|
14
|
-
this._bufferPubKey =
|
|
14
|
+
this._bufferPubKey = this._keypair.publicKey;
|
|
15
15
|
this._address = new Address(this._keypair.publicKey);
|
|
16
16
|
}
|
|
17
17
|
get address() {
|
|
@@ -48,8 +48,8 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
48
48
|
this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.calldata);
|
|
49
49
|
this.scriptTree = this.getScriptTree();
|
|
50
50
|
this.internalInit();
|
|
51
|
-
this._contractPubKey = '0x' + this.
|
|
52
|
-
this._contractAddress = new Address(this.
|
|
51
|
+
this._contractPubKey = '0x' + this.contractSeed.toString('hex');
|
|
52
|
+
this._contractAddress = new Address(this.contractSeed);
|
|
53
53
|
}
|
|
54
54
|
get contractPubKey() {
|
|
55
55
|
return this._contractPubKey;
|
|
@@ -91,7 +91,7 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
91
91
|
const amountSpent = this.getTransactionOPNetFee();
|
|
92
92
|
this.addOutput({
|
|
93
93
|
value: Number(amountSpent),
|
|
94
|
-
address: this.
|
|
94
|
+
address: this.contractAddress.p2tr(this.network),
|
|
95
95
|
});
|
|
96
96
|
await this.addRefundOutput(amountSpent);
|
|
97
97
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput, TapScriptSig } from '
|
|
2
|
-
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
1
|
+
import { Payment, Psbt, PsbtInput, Signer, TapScriptSig } from 'bitcoinjs-lib';
|
|
3
2
|
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
4
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { crypto as bitcoinCrypto, opcodes, Psbt, script } from 'bitcoinjs-lib';
|
|
1
|
+
import { crypto as bitcoinCrypto, opcodes, Psbt, script, } from 'bitcoinjs-lib';
|
|
2
2
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
3
3
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
4
|
import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput } from '
|
|
2
|
-
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
1
|
+
import { 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';
|
|
@@ -33,7 +32,6 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
33
32
|
protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
|
|
34
33
|
finalScriptWitness: Buffer;
|
|
35
34
|
};
|
|
36
|
-
private signIndividualInputs;
|
|
37
35
|
private getPubKeys;
|
|
38
36
|
private generateRedeemScripts;
|
|
39
37
|
}
|
|
@@ -88,31 +88,16 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
88
88
|
await super.signInputs(transaction);
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const offset = i * 20 + y;
|
|
97
|
-
const input = batch[y];
|
|
98
|
-
promises.push(this.signIndividualInputs(transaction, input, offset));
|
|
91
|
+
for (let i = 0; i < transaction.data.inputs.length; i++) {
|
|
92
|
+
if (i === 0) {
|
|
93
|
+
transaction.signInput(0, this.scriptSigner);
|
|
94
|
+
transaction.signInput(0, this.getSignerKey());
|
|
95
|
+
transaction.finalizeInput(0, this.customFinalizer);
|
|
99
96
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
transaction.finalizeInput(0, this.customFinalizer);
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
this.error(`Failed to finalize input 0: ${e.stack}`);
|
|
109
|
-
}
|
|
110
|
-
for (let i = 0; i < txs.length; i++) {
|
|
111
|
-
try {
|
|
97
|
+
else {
|
|
98
|
+
transaction.signInput(i, this.getSignerKey());
|
|
112
99
|
transaction.finalizeInput(i);
|
|
113
|
-
this.log(`Finalized input ${i}!`);
|
|
114
100
|
}
|
|
115
|
-
catch { }
|
|
116
101
|
}
|
|
117
102
|
}
|
|
118
103
|
generateScriptAddress() {
|
|
@@ -166,27 +151,6 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
166
151
|
},
|
|
167
152
|
];
|
|
168
153
|
}
|
|
169
|
-
async signIndividualInputs(transaction, input, i) {
|
|
170
|
-
let signed = false;
|
|
171
|
-
try {
|
|
172
|
-
await this.signInput(transaction, input, i, this.scriptSigner);
|
|
173
|
-
signed = true;
|
|
174
|
-
}
|
|
175
|
-
catch { }
|
|
176
|
-
try {
|
|
177
|
-
await this.signInput(transaction, input, i);
|
|
178
|
-
signed = true;
|
|
179
|
-
}
|
|
180
|
-
catch { }
|
|
181
|
-
if (signed) {
|
|
182
|
-
this.log(`Signed input #${i} out of ${transaction.data.inputs.length}! {Signed: ${signed}}`);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (this.regenerated || this.ignoreSignatureErrors) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
throw new Error('Failed to sign input');
|
|
189
|
-
}
|
|
190
154
|
getPubKeys() {
|
|
191
155
|
const pubkeys = [Buffer.from(this.signer.publicKey)];
|
|
192
156
|
if (this.scriptSigner) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
-
import {
|
|
1
|
+
import { Network, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
+
import { UpdateInput } from '../interfaces/Tap.js';
|
|
3
3
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
4
|
import { IFundingTransactionParameters, ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
5
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { initEccLib, opcodes, Psbt, script, Transaction } from 'bitcoinjs-lib';
|
|
1
|
+
import { initEccLib, opcodes, Psbt, script, Transaction, } from 'bitcoinjs-lib';
|
|
2
2
|
import { varuint } from 'bitcoinjs-lib/src/bufferutils.js';
|
|
3
3
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
4
4
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
@@ -2,9 +2,8 @@ import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
4
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Network, Payment, Psbt } from 'bitcoinjs-lib';
|
|
5
|
+
import { Network, Payment, Psbt, PsbtInput } from 'bitcoinjs-lib';
|
|
6
6
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
8
7
|
export declare class UnwrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
9
8
|
private static readonly UNWRAP_SELECTOR;
|
|
10
9
|
type: TransactionType.WBTC_UNWRAP;
|
|
@@ -2,7 +2,7 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
2
2
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
3
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
4
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
5
|
-
import { payments } from 'bitcoinjs-lib';
|
|
5
|
+
import { payments, } from 'bitcoinjs-lib';
|
|
6
6
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
7
7
|
import { PsbtTransaction } from '../processor/PsbtTransaction.js';
|
|
8
8
|
import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.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
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
9
9
|
readonly from?: string;
|
|
10
10
|
readonly to?: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PsbtInput, PsbtOutput } from '
|
|
2
|
-
import { TransactionInput } from 'bitcoinjs-lib/src/psbt.js';
|
|
1
|
+
import { PsbtInput as _PsbtInput, PsbtInputUpdate as _PsbtInputUpdate, PsbtOutput as _PsbtOutput, TapBip32Derivation as _TapBip32Derivation, TapInternalKey as _TapInternalKey, TapKeySig as _TapKeySig, TapLeaf as _TapLeaf, TapLeafScript as _TapLeafScript, TapMerkleRoot as _TapMerkleRoot, TapScriptSig as _TapScriptSig, TapTree as _TapTree } from 'bitcoinjs-lib';
|
|
3
2
|
export interface TapLeafScript {
|
|
4
3
|
readonly leafVersion: number;
|
|
5
4
|
readonly controlBlock: Buffer;
|
|
@@ -8,14 +7,25 @@ export interface TapLeafScript {
|
|
|
8
7
|
export interface UpdateInput {
|
|
9
8
|
tapLeafScript: TapLeafScript[];
|
|
10
9
|
}
|
|
11
|
-
export interface
|
|
10
|
+
export interface PsbtInput extends _PsbtInput {
|
|
12
11
|
}
|
|
13
|
-
export interface
|
|
14
|
-
address: string;
|
|
15
|
-
value: number;
|
|
12
|
+
export interface PsbtOutput extends _PsbtOutput {
|
|
16
13
|
}
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export interface TapInternalKey extends _TapInternalKey {
|
|
15
|
+
}
|
|
16
|
+
export interface TapLeaf extends _TapLeaf {
|
|
17
|
+
}
|
|
18
|
+
export interface TapScriptSig extends _TapScriptSig {
|
|
19
|
+
}
|
|
20
|
+
export interface TapKeySig extends _TapKeySig {
|
|
21
|
+
}
|
|
22
|
+
export interface TapTree extends _TapTree {
|
|
23
|
+
}
|
|
24
|
+
export interface TapMerkleRoot extends _TapMerkleRoot {
|
|
25
|
+
}
|
|
26
|
+
export interface TapLeafScript extends _TapLeafScript {
|
|
27
|
+
}
|
|
28
|
+
export interface TapBip32Derivation extends _TapBip32Derivation {
|
|
29
|
+
}
|
|
30
|
+
export interface PsbtInputUpdate extends _PsbtInputUpdate {
|
|
20
31
|
}
|
|
21
|
-
export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
-
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
1
|
+
import { Network, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
2
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
4
3
|
export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
5
4
|
readonly psbt: Psbt;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Logger } from '@btc-vision/logger';
|
|
2
|
-
import { Network, Payment, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
+
import { Network, Payment, Psbt, PsbtInput, PsbtInputExtended, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
3
|
import { ECPairInterface } from 'ecpair';
|
|
4
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
5
4
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
6
|
-
import {
|
|
5
|
+
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
7
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
8
7
|
export interface ITweakedTransactionData {
|
|
9
8
|
readonly signer: Signer | ECPairInterface;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@btc-vision/logger';
|
|
2
|
-
import { payments } from 'bitcoinjs-lib';
|
|
2
|
+
import { payments, } from 'bitcoinjs-lib';
|
|
3
3
|
import { TweakedSigner } from '../../signer/TweakedSigner.js';
|
|
4
4
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
5
5
|
import { AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
@@ -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
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.117';
|