@btc-vision/transaction 1.0.116 → 1.0.118
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/deterministic/Map.d.ts +1 -0
- 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/deterministic/Map.d.ts +1 -0
- package/build/deterministic/Map.js +7 -0
- package/build/keypair/Address.d.ts +1 -0
- package/build/keypair/Address.js +27 -20
- package/build/keypair/AddressVerificator.js +3 -6
- 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/deterministic/Map.ts +8 -0
- package/src/keypair/Address.ts +37 -17
- package/src/keypair/AddressVerificator.ts +3 -9
- 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
|
@@ -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.118';
|
|
@@ -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 {
|
package/src/deterministic/Map.ts
CHANGED
|
@@ -15,6 +15,14 @@ export class Map<K, V> {
|
|
|
15
15
|
public values(): V[] {
|
|
16
16
|
return this._values;
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
public entires(): [K, V][] {
|
|
20
|
+
const result: [K, V][] = [];
|
|
21
|
+
for (let i: i32 = 0; i < this._keys.length; i++) {
|
|
22
|
+
result.push([this._keys[i], this._values[i]]);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
18
26
|
|
|
19
27
|
public set(key: K, value: V): void {
|
|
20
28
|
const index: i32 = this.indexOf(key);
|
package/src/keypair/Address.ts
CHANGED
|
@@ -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
|
-
|
|
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 <
|
|
78
|
-
if (
|
|
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 =
|
|
94
|
-
const aByte =
|
|
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 =
|
|
114
|
-
const aByte =
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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;
|
|
@@ -118,8 +118,7 @@ export class AddressVerificator {
|
|
|
118
118
|
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
|
-
} catch
|
|
122
|
-
// If any error occurs (invalid public key, etc.), return false
|
|
121
|
+
} catch {
|
|
123
122
|
return false;
|
|
124
123
|
}
|
|
125
124
|
|
|
@@ -156,9 +155,7 @@ export class AddressVerificator {
|
|
|
156
155
|
// P2SH: Could be P2SH (general) or P2SH-P2WPKH (wrapped SegWit)
|
|
157
156
|
return AddressTypes.P2SH_OR_P2SH_P2WPKH;
|
|
158
157
|
}
|
|
159
|
-
} catch
|
|
160
|
-
// Ignore errors from Base58 decoding, it could be a Bech32 address
|
|
161
|
-
}
|
|
158
|
+
} catch {}
|
|
162
159
|
|
|
163
160
|
try {
|
|
164
161
|
// Try to decode as a Bech32 or Bech32m address (P2WPKH or P2TR)
|
|
@@ -174,10 +171,7 @@ export class AddressVerificator {
|
|
|
174
171
|
return AddressTypes.P2TR;
|
|
175
172
|
}
|
|
176
173
|
}
|
|
177
|
-
} catch
|
|
178
|
-
console.log(error);
|
|
179
|
-
// Ignore errors from Bech32/Bech32m decoding
|
|
180
|
-
}
|
|
174
|
+
} catch {}
|
|
181
175
|
|
|
182
176
|
return null; // Not a valid or recognized Bitcoin address type
|
|
183
177
|
}
|
package/src/keypair/Wallet.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TapScriptSig } from '
|
|
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.
|
|
125
|
-
this._contractAddress = new Address(this.
|
|
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.
|
|
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);
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 '
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
2
|
-
|
|
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
|
|
25
|
+
export interface PsbtInput extends _PsbtInput {}
|
|
15
26
|
|
|
16
|
-
export interface
|
|
17
|
-
address: string;
|
|
18
|
-
value: number;
|
|
19
|
-
}
|
|
27
|
+
export interface PsbtOutput extends _PsbtOutput {}
|
|
20
28
|
|
|
21
|
-
export interface
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
45
|
+
export interface PsbtInputUpdate extends _PsbtInputUpdate {}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Network,
|
|
3
|
+
Psbt,
|
|
4
|
+
PsbtInputExtended,
|
|
5
|
+
PsbtOutputExtended,
|
|
6
|
+
Signer,
|
|
7
|
+
Transaction,
|
|
8
|
+
} from 'bitcoinjs-lib';
|
|
3
9
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
4
10
|
|
|
5
11
|
export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
@@ -117,6 +123,7 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
117
123
|
/**
|
|
118
124
|
* @description Add an input to the transaction
|
|
119
125
|
* @param input
|
|
126
|
+
* @param checkPartialSigs
|
|
120
127
|
*/
|
|
121
128
|
public addInput(input: PsbtInputExtended, checkPartialSigs: boolean = false): void {
|
|
122
129
|
this.transaction.addInput(input, checkPartialSigs);
|