@btc-vision/transaction 1.1.16 → 1.2.0
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/crypto/crypto-browser.d.ts +2 -2
- package/browser/index.js +1 -1
- package/browser/index.js.LICENSE.txt +2 -0
- package/browser/keypair/Address.d.ts +10 -0
- package/browser/keypair/Secp256k1PointDeriver.d.ts +16 -0
- package/browser/opnet.d.ts +2 -0
- package/browser/signer/SignerUtils.d.ts +5 -0
- package/browser/transaction/ContractAddress.d.ts +6 -0
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +3 -4
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -6
- package/browser/utxo/interfaces/IUTXO.d.ts +1 -0
- package/browser/verification/TapscriptVerificator.d.ts +1 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryReader.js +2 -2
- package/build/buffer/BinaryWriter.js +1 -1
- package/build/generators/AddressGenerator.js +1 -2
- package/build/generators/Generator.js +1 -2
- package/build/generators/builders/CalldataGenerator.js +1 -1
- package/build/generators/builders/LegacyCalldataGenerator.js +1 -1
- package/build/generators/builders/MultiSignGenerator.js +1 -2
- package/build/keypair/Address.d.ts +10 -0
- package/build/keypair/Address.js +76 -7
- package/build/keypair/AddressVerificator.js +5 -2
- package/build/keypair/EcKeyPair.js +3 -4
- package/build/keypair/MessageSigner.js +1 -2
- package/build/keypair/Secp256k1PointDeriver.d.ts +16 -0
- package/build/keypair/Secp256k1PointDeriver.js +80 -0
- package/build/keypair/Wallet.js +1 -2
- package/build/opnet.d.ts +2 -0
- package/build/opnet.js +2 -0
- package/build/signer/SignerUtils.d.ts +5 -0
- package/build/signer/SignerUtils.js +40 -0
- package/build/signer/TweakedSigner.js +1 -3
- package/build/transaction/ContractAddress.d.ts +6 -0
- package/build/transaction/ContractAddress.js +12 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +5 -33
- package/build/transaction/browser/extensions/XverseSigner.js +5 -49
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/build/transaction/builders/CustomScriptTransaction.js +1 -2
- package/build/transaction/builders/DeploymentTransaction.js +2 -2
- package/build/transaction/builders/FundingTransaction.js +6 -1
- package/build/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +3 -4
- package/build/transaction/builders/MultiSignTransaction.js +1 -2
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
- package/build/transaction/builders/SharedInteractionTransaction.js +1 -2
- package/build/transaction/builders/TransactionBuilder.js +14 -3
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -6
- package/build/transaction/shared/TweakedTransaction.js +121 -94
- package/build/utils/BitcoinUtils.js +4 -4
- package/build/utils/BufferHelper.js +1 -1
- package/build/utxo/OPNetLimitedProvider.js +1 -0
- package/build/utxo/interfaces/IUTXO.d.ts +1 -0
- package/build/verification/TapscriptVerificator.d.ts +1 -2
- package/build/verification/TapscriptVerificator.js +1 -2
- package/package.json +9 -12
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryReader.ts +2 -2
- package/src/buffer/BinaryWriter.ts +1 -1
- package/src/generators/AddressGenerator.ts +1 -2
- package/src/generators/Generator.ts +1 -2
- package/src/generators/builders/CalldataGenerator.ts +5 -1
- package/src/generators/builders/LegacyCalldataGenerator.ts +5 -1
- package/src/generators/builders/MultiSignGenerator.ts +1 -2
- package/src/keypair/Address.ts +106 -10
- package/src/keypair/AddressVerificator.ts +6 -2
- package/src/keypair/EcKeyPair.ts +14 -5
- package/src/keypair/MessageSigner.ts +1 -2
- package/src/keypair/Secp256k1PointDeriver.ts +170 -0
- package/src/keypair/Wallet.ts +1 -2
- package/src/opnet.ts +2 -0
- package/src/signer/SignerUtils.ts +66 -0
- package/src/signer/TweakedSigner.ts +1 -3
- package/src/transaction/ContractAddress.ts +13 -0
- package/src/transaction/TransactionFactory.ts +4 -258
- package/src/transaction/browser/extensions/UnisatSigner.ts +5 -41
- package/src/transaction/browser/extensions/XverseSigner.ts +9 -69
- package/src/transaction/builders/CustomScriptTransaction.ts +10 -3
- package/src/transaction/builders/DeploymentTransaction.ts +13 -3
- package/src/transaction/builders/FundingTransaction.ts +7 -2
- package/src/transaction/builders/InteractionTransaction.ts +1 -1
- package/src/transaction/builders/MultiSignTransaction.ts +2 -2
- package/src/transaction/builders/SharedInteractionTransaction.ts +1 -3
- package/src/transaction/builders/TransactionBuilder.ts +14 -2
- package/src/transaction/shared/TweakedTransaction.ts +186 -123
- package/src/utils/BitcoinUtils.ts +4 -4
- package/src/utils/BufferHelper.ts +1 -1
- package/src/utxo/OPNetLimitedProvider.ts +1 -0
- package/src/utxo/interfaces/IUTXO.ts +2 -0
- package/src/verification/TapscriptVerificator.ts +9 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isP2TR, pubkeyPositionInScript } from '@btc-vision/bitcoin';
|
|
2
|
+
export function isTaprootInput(input) {
|
|
3
|
+
return (input &&
|
|
4
|
+
!!(input.tapInternalKey ||
|
|
5
|
+
input.tapMerkleRoot ||
|
|
6
|
+
(input.tapLeafScript && input.tapLeafScript.length) ||
|
|
7
|
+
(input.tapBip32Derivation && input.tapBip32Derivation.length) ||
|
|
8
|
+
(input.witnessUtxo && isP2TR(input.witnessUtxo.script))));
|
|
9
|
+
}
|
|
10
|
+
export function getInputRelevantScript(input) {
|
|
11
|
+
if (input.redeemScript) {
|
|
12
|
+
return input.redeemScript;
|
|
13
|
+
}
|
|
14
|
+
if (input.witnessScript) {
|
|
15
|
+
return input.witnessScript;
|
|
16
|
+
}
|
|
17
|
+
if (input.witnessUtxo) {
|
|
18
|
+
return input.witnessUtxo.script;
|
|
19
|
+
}
|
|
20
|
+
if (input.nonWitnessUtxo) {
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export function canSignNonTaprootInput(input, publicKey) {
|
|
25
|
+
if ((input.nonWitnessUtxo &&
|
|
26
|
+
!input.redeemScript &&
|
|
27
|
+
!input.witnessScript &&
|
|
28
|
+
!input.witnessUtxo) ||
|
|
29
|
+
input.redeemScript) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const script = getInputRelevantScript(input);
|
|
33
|
+
if (script) {
|
|
34
|
+
return pubkeyInScript(publicKey, script);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
export function pubkeyInScript(pubkey, script) {
|
|
39
|
+
return pubkeyPositionInScript(pubkey, script) !== -1;
|
|
40
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
2
|
-
import { initEccLib } from '@btc-vision/bitcoin';
|
|
3
|
-
import { tapTweakHash } from '@btc-vision/bitcoin/src/payments/bip341.js';
|
|
4
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
2
|
+
import { initEccLib, tapTweakHash, toXOnly } from '@btc-vision/bitcoin';
|
|
5
3
|
import { EcKeyPair } from '../keypair/EcKeyPair.js';
|
|
6
4
|
initEccLib(ecc);
|
|
7
5
|
export class TweakedSigner {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Secp256k1PointDeriver } from '../keypair/Secp256k1PointDeriver.js';
|
|
2
|
+
class ContractAddressBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.deriver = new Secp256k1PointDeriver();
|
|
5
|
+
}
|
|
6
|
+
generateHybridKeyFromHash(input) {
|
|
7
|
+
const p = this.deriver.findOrDeriveValidPoint(input, false);
|
|
8
|
+
const y = this.deriver.getCanonicalY(p.y1, p.y2);
|
|
9
|
+
return Buffer.from(this.deriver.getHybridPublicKey(p.x, y));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const ContractAddress = new ContractAddressBase();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { crypto as bitCrypto, networks,
|
|
1
|
+
import { crypto as bitCrypto, networks, Psbt, script as bitScript, toXOnly, } from '@btc-vision/bitcoin';
|
|
2
2
|
import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
|
|
3
3
|
import { CustomKeypair } from '../BrowserSignerBase.js';
|
|
4
4
|
import { UnisatNetwork } from '../types/Unisat.js';
|
|
5
|
-
import {
|
|
5
|
+
import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
|
|
6
6
|
export class UnisatSigner extends CustomKeypair {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
@@ -147,12 +147,9 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
else {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
needsToSign = true;
|
|
154
|
-
viaTaproot = false;
|
|
155
|
-
}
|
|
150
|
+
else if (canSignNonTaprootInput(input, this.publicKey)) {
|
|
151
|
+
needsToSign = true;
|
|
152
|
+
viaTaproot = false;
|
|
156
153
|
}
|
|
157
154
|
if (needsToSign) {
|
|
158
155
|
return {
|
|
@@ -248,31 +245,6 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
248
245
|
return nonDuplicate;
|
|
249
246
|
}
|
|
250
247
|
}
|
|
251
|
-
function isTaprootInput(input) {
|
|
252
|
-
if (input.tapInternalKey || input.tapKeySig || input.tapScriptSig || input.tapLeafScript) {
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
if (input.witnessUtxo) {
|
|
256
|
-
const script = input.witnessUtxo.script;
|
|
257
|
-
return script.length === 34 && script[0] === opcodes.OP_1 && script[1] === 0x20;
|
|
258
|
-
}
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
function getInputRelevantScript(input) {
|
|
262
|
-
if (input.redeemScript) {
|
|
263
|
-
return input.redeemScript;
|
|
264
|
-
}
|
|
265
|
-
if (input.witnessScript) {
|
|
266
|
-
return input.witnessScript;
|
|
267
|
-
}
|
|
268
|
-
if (input.witnessUtxo) {
|
|
269
|
-
return input.witnessUtxo.script;
|
|
270
|
-
}
|
|
271
|
-
if (input.nonWitnessUtxo) {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
248
|
function pubkeyInScript(pubkey, script) {
|
|
277
249
|
return pubkeyPositionInScript(pubkey, script) !== -1;
|
|
278
250
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
1
|
+
import { networks, Psbt, toXOnly } from '@btc-vision/bitcoin';
|
|
3
2
|
import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
|
|
4
3
|
import { CustomKeypair } from '../BrowserSignerBase.js';
|
|
4
|
+
import { canSignNonTaprootInput, isTaprootInput, pubkeyInScript, } from '../../../signer/SignerUtils.js';
|
|
5
5
|
export class XverseSigner extends CustomKeypair {
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
@@ -145,12 +145,9 @@ export class XverseSigner extends CustomKeypair {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
else {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
needsToSign = true;
|
|
152
|
-
viaTaproot = false;
|
|
153
|
-
}
|
|
148
|
+
else if (canSignNonTaprootInput(input, this.publicKey)) {
|
|
149
|
+
needsToSign = true;
|
|
150
|
+
viaTaproot = false;
|
|
154
151
|
}
|
|
155
152
|
if (needsToSign) {
|
|
156
153
|
return {
|
|
@@ -256,44 +253,3 @@ export class XverseSigner extends CustomKeypair {
|
|
|
256
253
|
return nonDuplicate;
|
|
257
254
|
}
|
|
258
255
|
}
|
|
259
|
-
function isTaprootInput(input) {
|
|
260
|
-
if (input.tapInternalKey || input.tapKeySig || input.tapScriptSig || input.tapLeafScript) {
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
if (input.witnessUtxo) {
|
|
264
|
-
const script = input.witnessUtxo.script;
|
|
265
|
-
return script.length === 34 && script[0] === opcodes.OP_1 && script[1] === 0x20;
|
|
266
|
-
}
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
function getInputRelevantScript(input) {
|
|
270
|
-
if (input.redeemScript) {
|
|
271
|
-
return input.redeemScript;
|
|
272
|
-
}
|
|
273
|
-
if (input.witnessScript) {
|
|
274
|
-
return input.witnessScript;
|
|
275
|
-
}
|
|
276
|
-
if (input.witnessUtxo) {
|
|
277
|
-
return input.witnessUtxo.script;
|
|
278
|
-
}
|
|
279
|
-
if (input.nonWitnessUtxo) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
function pubkeyInScript(pubkey, script) {
|
|
285
|
-
return pubkeyPositionInScript(pubkey, script) !== -1;
|
|
286
|
-
}
|
|
287
|
-
function pubkeyPositionInScript(pubkey, script) {
|
|
288
|
-
const pubkeyHash = bitCrypto.hash160(pubkey);
|
|
289
|
-
const pubkeyXOnly = toXOnly(pubkey);
|
|
290
|
-
const decompiled = bitScript.decompile(script);
|
|
291
|
-
if (decompiled === null)
|
|
292
|
-
throw new Error('Unknown script error');
|
|
293
|
-
return decompiled.findIndex((element) => {
|
|
294
|
-
if (typeof element === 'number')
|
|
295
|
-
return false;
|
|
296
|
-
return (Buffer.isBuffer(element) &&
|
|
297
|
-
(element.equals(pubkey) || element.equals(pubkeyHash) || element.equals(pubkeyXOnly)));
|
|
298
|
-
});
|
|
299
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Payment, Psbt, Stack } from '@btc-vision/bitcoin';
|
|
1
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
3
4
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
-
import { Payment, Psbt, Stack } from '@btc-vision/bitcoin';
|
|
5
5
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
6
6
|
export interface ICustomTransactionParameters extends SharedInteractionParameters {
|
|
7
7
|
readonly script: (Buffer | Stack)[];
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { crypto as bitCrypto, toXOnly, } from '@btc-vision/bitcoin';
|
|
1
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
-
import { crypto as bitCrypto } from '@btc-vision/bitcoin';
|
|
3
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
4
|
import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
|
|
5
5
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
6
6
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
7
7
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
8
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
9
8
|
export class CustomScriptTransaction extends TransactionBuilder {
|
|
10
9
|
constructor(parameters) {
|
|
11
10
|
super(parameters);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
-
import { crypto as bitCrypto } from '@btc-vision/bitcoin';
|
|
2
|
+
import { crypto as bitCrypto, toXOnly, } from '@btc-vision/bitcoin';
|
|
3
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
4
|
import { DeploymentGenerator } from '../../generators/builders/DeploymentGenerator.js';
|
|
5
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
6
5
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
7
6
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
8
7
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
9
8
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
10
9
|
import { Address } from '../../keypair/Address.js';
|
|
10
|
+
const p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
|
|
11
11
|
export class DeploymentTransaction extends TransactionBuilder {
|
|
12
12
|
constructor(parameters) {
|
|
13
13
|
super(parameters);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
+
import { opcodes, script } from '@btc-vision/bitcoin';
|
|
2
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
3
4
|
export class FundingTransaction extends TransactionBuilder {
|
|
4
5
|
constructor(parameters) {
|
|
@@ -17,9 +18,13 @@ export class FundingTransaction extends TransactionBuilder {
|
|
|
17
18
|
this.splitInputs(this.amount);
|
|
18
19
|
}
|
|
19
20
|
else if (this.isPubKeyDestination) {
|
|
21
|
+
const pubKeyScript = script.compile([
|
|
22
|
+
Buffer.from(this.to.replace('0x', ''), 'hex'),
|
|
23
|
+
opcodes.OP_CHECKSIG,
|
|
24
|
+
]);
|
|
20
25
|
this.addOutput({
|
|
21
26
|
value: Number(this.amount),
|
|
22
|
-
script:
|
|
27
|
+
script: pubKeyScript,
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
30
|
else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
4
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Payment, Psbt, PsbtInput, Signer, TapScriptSig } from '@btc-vision/bitcoin';
|
|
2
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
1
|
+
import { Payment, Psbt, PsbtInput, Signer, TapScriptSig, Taptree } from '@btc-vision/bitcoin';
|
|
3
2
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
3
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
5
4
|
import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
@@ -20,7 +19,7 @@ export interface MultiSignFromBase64Params extends Omit<MultiSignParameters, 'ps
|
|
|
20
19
|
export declare class MultiSignTransaction extends TransactionBuilder<TransactionType.MULTI_SIG> {
|
|
21
20
|
static readonly LOCK_LEAF_SCRIPT: Buffer;
|
|
22
21
|
static readonly signHashTypesArray: number[];
|
|
23
|
-
static readonly numsPoint: Buffer
|
|
22
|
+
static readonly numsPoint: Buffer<ArrayBuffer>;
|
|
24
23
|
type: TransactionType.MULTI_SIG;
|
|
25
24
|
protected targetScriptRedeem: Payment | null;
|
|
26
25
|
protected leftOverFundsScriptRedeem: Payment | null;
|
|
@@ -41,7 +40,7 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
|
|
|
41
40
|
signed: boolean;
|
|
42
41
|
};
|
|
43
42
|
static partialFinalizer: (inputIndex: number, input: PsbtInput, partialSignatures: Buffer[], orderedPubKeys: Buffer[], isFinal: boolean) => {
|
|
44
|
-
finalScriptWitness: Buffer
|
|
43
|
+
finalScriptWitness: Buffer<ArrayBufferLike>;
|
|
45
44
|
};
|
|
46
45
|
static dedupeSignatures(original: TapScriptSig[], partial: TapScriptSig[]): TapScriptSig[];
|
|
47
46
|
static attemptFinalizeInputs(psbt: Psbt, startIndex: number, orderedPubKeys: Buffer[][], isFinal: boolean): boolean;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { crypto as bitcoinCrypto, opcodes, Psbt, script, } from '@btc-vision/bitcoin';
|
|
1
|
+
import { crypto as bitcoinCrypto, opcodes, 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';
|
|
5
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
6
5
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
7
6
|
export class MultiSignTransaction extends TransactionBuilder {
|
|
8
7
|
constructor(parameters) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Payment, Psbt, PsbtInput, Signer } from '@btc-vision/bitcoin';
|
|
2
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
1
|
+
import { Payment, Psbt, PsbtInput, Signer, Taptree } from '@btc-vision/bitcoin';
|
|
3
2
|
import { ECPairInterface } from 'ecpair';
|
|
4
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -30,7 +29,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
30
29
|
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
31
30
|
protected getScriptTree(): Taptree;
|
|
32
31
|
protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
|
|
33
|
-
finalScriptWitness: Buffer
|
|
32
|
+
finalScriptWitness: Buffer<ArrayBufferLike>;
|
|
34
33
|
};
|
|
35
34
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
36
35
|
private signInputsNonWalletBased;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { address } from '@btc-vision/bitcoin';
|
|
1
|
+
import { address, toXOnly } from '@btc-vision/bitcoin';
|
|
2
2
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
3
3
|
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
4
4
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
5
5
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
6
6
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
7
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
8
7
|
export class SharedInteractionTransaction extends TransactionBuilder {
|
|
9
8
|
constructor(parameters) {
|
|
10
9
|
super(parameters);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { initEccLib, opcodes, Psbt, script, Transaction, } from '@btc-vision/bitcoin';
|
|
2
|
-
import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
|
|
1
|
+
import { initEccLib, opcodes, Psbt, script, Transaction, varuint, } from '@btc-vision/bitcoin';
|
|
3
2
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
4
3
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
5
4
|
import { AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
@@ -25,7 +24,9 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
25
24
|
this.priorityFee = parameters.priorityFee ?? 0n;
|
|
26
25
|
this.utxos = parameters.utxos;
|
|
27
26
|
this.to = parameters.to || undefined;
|
|
28
|
-
this.isPubKeyDestination = this.to
|
|
27
|
+
this.isPubKeyDestination = this.to
|
|
28
|
+
? AddressVerificator.isValidPublicKey(this.to, this.network)
|
|
29
|
+
: false;
|
|
29
30
|
this.optionalOutputs = parameters.optionalOutputs;
|
|
30
31
|
this.from = TransactionBuilder.getFrom(parameters.from, this.signer, this.network);
|
|
31
32
|
this.totalInputAmount = this.calculateTotalUTXOAmount();
|
|
@@ -205,6 +206,16 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
205
206
|
tapInternalKey: this.internalPubKeyToXOnly(),
|
|
206
207
|
});
|
|
207
208
|
}
|
|
209
|
+
else if (AddressVerificator.isValidPublicKey(this.from, this.network)) {
|
|
210
|
+
const pubKeyScript = script.compile([
|
|
211
|
+
Buffer.from(this.from.replace('0x', ''), 'hex'),
|
|
212
|
+
opcodes.OP_CHECKSIG,
|
|
213
|
+
]);
|
|
214
|
+
await this.setFeeOutput({
|
|
215
|
+
value: Number(sendBackAmount),
|
|
216
|
+
script: pubKeyScript,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
208
219
|
else {
|
|
209
220
|
await this.setFeeOutput({
|
|
210
221
|
value: Number(sendBackAmount),
|
|
@@ -48,7 +48,7 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
48
48
|
protected generateTapData(): Payment;
|
|
49
49
|
protected generateScriptAddress(): Payment;
|
|
50
50
|
protected getSignerKey(): Signer | ECPairInterface;
|
|
51
|
-
protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer | ECPairInterface, reverse?: boolean): Promise<void>;
|
|
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[][];
|
|
53
53
|
protected signInputs(transaction: Psbt): Promise<void>;
|
|
54
54
|
protected internalPubKeyToXOnly(): Buffer;
|
|
@@ -60,6 +60,10 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
60
60
|
redeemScript: Buffer;
|
|
61
61
|
outputScript: Buffer;
|
|
62
62
|
} | undefined;
|
|
63
|
+
protected generateP2SHP2PKHRedeemScript(inputAddr: string): {
|
|
64
|
+
redeemScript: Buffer;
|
|
65
|
+
outputScript: Buffer;
|
|
66
|
+
} | undefined;
|
|
63
67
|
protected generatePsbtInputExtended(utxo: UTXO, i: number): PsbtInputExtended;
|
|
64
68
|
protected customFinalizerP2SH: (inputIndex: number, input: PsbtInput, scriptA: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean) => {
|
|
65
69
|
finalScriptSig: Buffer | undefined;
|
|
@@ -68,11 +72,6 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
68
72
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
69
73
|
private attemptSignTaproot;
|
|
70
74
|
private isTaprootScriptSpend;
|
|
71
|
-
private isTaprootInput;
|
|
72
|
-
private canSignNonTaprootInput;
|
|
73
|
-
private getInputRelevantScript;
|
|
74
|
-
private pubkeyInScript;
|
|
75
|
-
private pubkeyPositionInScript;
|
|
76
75
|
private signTaprootInput;
|
|
77
76
|
private signNonTaprootInput;
|
|
78
77
|
}
|