@btc-vision/transaction 1.0.105 → 1.0.107
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/EcKeyPair.d.ts +4 -4
- package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -1
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +4 -2
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +1 -1
- package/browser/transaction/builders/UnwrapTransaction.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +9 -8
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts +11 -1
- package/browser/utxo/interfaces/IUTXO.d.ts +3 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/keypair/EcKeyPair.d.ts +4 -4
- package/build/transaction/TransactionFactory.js +2 -1
- package/build/transaction/builders/CustomScriptTransaction.js +1 -4
- package/build/transaction/builders/MultiSignTransaction.d.ts +1 -1
- package/build/transaction/builders/MultiSignTransaction.js +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +43 -31
- package/build/transaction/builders/TransactionBuilder.d.ts +4 -2
- package/build/transaction/builders/TransactionBuilder.js +17 -5
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +1 -1
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -3
- package/build/transaction/builders/UnwrapTransaction.d.ts +1 -1
- package/build/transaction/builders/UnwrapTransaction.js +2 -2
- package/build/transaction/interfaces/ITransactionParameters.d.ts +9 -8
- package/build/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/build/transaction/processor/PsbtTransaction.js +2 -2
- package/build/transaction/shared/TweakedTransaction.d.ts +2 -1
- package/build/transaction/shared/TweakedTransaction.js +30 -10
- package/build/utxo/OPNetLimitedProvider.d.ts +11 -1
- package/build/utxo/OPNetLimitedProvider.js +49 -2
- package/build/utxo/interfaces/IUTXO.d.ts +3 -1
- package/eslint.config.js +0 -1
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/keypair/EcKeyPair.ts +4 -4
- package/src/transaction/TransactionFactory.ts +3 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +3 -7
- package/src/transaction/builders/MultiSignTransaction.ts +3 -2
- package/src/transaction/builders/SharedInteractionTransaction.ts +61 -34
- package/src/transaction/builders/TransactionBuilder.ts +38 -11
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +5 -5
- package/src/transaction/builders/UnwrapTransaction.ts +6 -2
- package/src/transaction/interfaces/ITransactionParameters.ts +11 -9
- package/src/transaction/processor/PsbtTransaction.ts +2 -2
- package/src/transaction/shared/TweakedTransaction.ts +38 -10
- package/src/utxo/OPNetLimitedProvider.ts +86 -4
- package/src/utxo/interfaces/IUTXO.ts +3 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
-
import { BIP32Interface } from 'bip32';
|
|
2
|
+
import { BIP32API, BIP32Interface } from 'bip32';
|
|
3
3
|
import { Network } from 'bitcoinjs-lib';
|
|
4
|
-
import { ECPairInterface } from 'ecpair';
|
|
4
|
+
import { ECPairAPI, ECPairInterface } from 'ecpair';
|
|
5
5
|
import { IWallet } from './interfaces/IWallet.js';
|
|
6
6
|
export declare class EcKeyPair {
|
|
7
|
-
static BIP32:
|
|
8
|
-
static ECPair:
|
|
7
|
+
static BIP32: BIP32API;
|
|
8
|
+
static ECPair: ECPairAPI;
|
|
9
9
|
static fromWIF(wif: string, network?: Network): ECPairInterface;
|
|
10
10
|
static fromPrivateKey(privateKey: Buffer, network?: Network): ECPairInterface;
|
|
11
11
|
static fromPublicKey(publicKey: Buffer, network?: Network): ECPairInterface;
|
|
@@ -49,7 +49,7 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
|
|
|
49
49
|
finalizeTransactionInputs(): boolean;
|
|
50
50
|
signPSBT(): Promise<Psbt>;
|
|
51
51
|
protected buildTransaction(): Promise<void>;
|
|
52
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
52
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
53
53
|
protected signInputs(_transaction: Psbt): Promise<void>;
|
|
54
54
|
protected generateScriptAddress(): Payment;
|
|
55
55
|
protected generateTapData(): Payment;
|
|
@@ -32,6 +32,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
32
32
|
protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
|
|
33
33
|
finalScriptWitness: Buffer;
|
|
34
34
|
};
|
|
35
|
+
private signIndividualInputs;
|
|
35
36
|
private getPubKeys;
|
|
36
37
|
private generateRedeemScripts;
|
|
37
38
|
}
|
|
@@ -14,6 +14,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
14
14
|
overflowFees: bigint;
|
|
15
15
|
transactionFee: bigint;
|
|
16
16
|
estimatedFees: bigint;
|
|
17
|
+
optionalOutputs: PsbtOutputExtended[] | undefined;
|
|
17
18
|
protected transaction: Psbt;
|
|
18
19
|
protected readonly updateInputs: UpdateInput[];
|
|
19
20
|
protected readonly outputs: PsbtOutputExtended[];
|
|
@@ -34,7 +35,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
34
35
|
setDestinationAddress(address: Address): void;
|
|
35
36
|
setMaximumFeeRate(feeRate: number): void;
|
|
36
37
|
signTransaction(): Promise<Transaction>;
|
|
37
|
-
generateTransactionMinimalSignatures(): Promise<void>;
|
|
38
|
+
generateTransactionMinimalSignatures(checkPartialSigs?: boolean): Promise<void>;
|
|
38
39
|
signPSBT(): Promise<Psbt>;
|
|
39
40
|
addInput(input: PsbtInputExtended): void;
|
|
40
41
|
addOutput(output: PsbtOutputExtended): void;
|
|
@@ -50,6 +51,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
50
51
|
protected getTransactionOPNetFee(): bigint;
|
|
51
52
|
protected calculateTotalUTXOAmount(): bigint;
|
|
52
53
|
protected calculateTotalVOutAmount(): bigint;
|
|
54
|
+
protected addOptionalOutputsAndGetAmount(): bigint;
|
|
53
55
|
protected addInputsFromUTXO(): void;
|
|
54
56
|
protected internalInit(): void;
|
|
55
57
|
protected abstract buildTransaction(): Promise<void>;
|
|
@@ -58,5 +60,5 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
58
60
|
protected getTapOutput(): Buffer;
|
|
59
61
|
protected verifyUTXOValidity(): void;
|
|
60
62
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
61
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
63
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
62
64
|
}
|
|
@@ -19,7 +19,7 @@ export declare class UnwrapSegwitTransaction extends SharedInteractionTransactio
|
|
|
19
19
|
static generateBurnCalldata(amount: bigint): Buffer;
|
|
20
20
|
signPSBT(): Promise<Psbt>;
|
|
21
21
|
mergeVaults(input: VaultUTXOs[]): Promise<void>;
|
|
22
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
22
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
23
23
|
protected generateMultiSignRedeemScript(publicKeys: string[], minimum: number): {
|
|
24
24
|
witnessUtxo: Buffer;
|
|
25
25
|
redeemScript: Buffer;
|
|
@@ -34,7 +34,7 @@ export declare class UnwrapTransaction extends SharedInteractionTransaction<Tran
|
|
|
34
34
|
redeem: Payment;
|
|
35
35
|
};
|
|
36
36
|
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
37
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
37
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
38
38
|
private addVaultUTXO;
|
|
39
39
|
private addVaultInputs;
|
|
40
40
|
private calculateOutputLeftAmountFromVaults;
|
|
@@ -4,12 +4,14 @@ import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
|
4
4
|
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
5
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
|
+
import { PsbtOutputExtended } from './Tap.js';
|
|
7
8
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
8
9
|
readonly from?: Address;
|
|
9
|
-
readonly to?: Address
|
|
10
|
+
readonly to?: Address;
|
|
10
11
|
utxos: UTXO[];
|
|
11
|
-
nonWitnessUtxo?: Buffer
|
|
12
|
+
nonWitnessUtxo?: Buffer;
|
|
12
13
|
estimatedFees?: bigint;
|
|
14
|
+
optionalOutputs?: PsbtOutputExtended[];
|
|
13
15
|
chainId?: ChainId;
|
|
14
16
|
readonly feeRate: number;
|
|
15
17
|
readonly priorityFee: bigint;
|
|
@@ -19,27 +21,26 @@ export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
|
19
21
|
splitInputsInto?: number;
|
|
20
22
|
}
|
|
21
23
|
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
22
|
-
calldata?: Buffer
|
|
24
|
+
calldata?: Buffer;
|
|
23
25
|
disableAutoRefund?: boolean;
|
|
24
26
|
readonly randomBytes?: Buffer;
|
|
25
27
|
}
|
|
26
|
-
export interface IInteractionParameters extends SharedInteractionParameters {
|
|
28
|
+
export interface IInteractionParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
27
29
|
readonly calldata: Buffer;
|
|
28
30
|
readonly to: Address;
|
|
29
31
|
}
|
|
30
|
-
export interface IWrapParameters extends SharedInteractionParameters {
|
|
32
|
+
export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
31
33
|
readonly to?: Address;
|
|
32
34
|
readonly from: Address;
|
|
33
35
|
readonly amount: bigint;
|
|
34
36
|
readonly receiver?: Address;
|
|
35
37
|
readonly generationParameters: WrappedGeneration;
|
|
36
38
|
}
|
|
37
|
-
export interface IUnwrapParameters extends SharedInteractionParameters {
|
|
39
|
+
export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
38
40
|
readonly unwrapUTXOs: VaultUTXOs[];
|
|
39
41
|
readonly amount: bigint;
|
|
40
42
|
}
|
|
41
|
-
export interface IDeploymentParameters extends ITransactionParameters {
|
|
43
|
+
export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
|
|
42
44
|
readonly bytecode: Buffer;
|
|
43
|
-
readonly to?: undefined;
|
|
44
45
|
readonly randomBytes?: Buffer;
|
|
45
46
|
}
|
|
@@ -34,7 +34,7 @@ export declare class PsbtTransaction extends TweakedTransaction {
|
|
|
34
34
|
extractTransaction(): Transaction;
|
|
35
35
|
final(): string;
|
|
36
36
|
toHex(): string;
|
|
37
|
-
addInput(input: PsbtInputExtended): void;
|
|
37
|
+
addInput(input: PsbtInputExtended, checkPartialSigs?: boolean): void;
|
|
38
38
|
addOutput(output: PsbtOutputExtended): void;
|
|
39
39
|
attemptFinalizeInputs(n?: number): boolean;
|
|
40
40
|
getPSBT(): Psbt;
|
|
@@ -33,7 +33,7 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
33
33
|
protected regenerated: boolean;
|
|
34
34
|
protected ignoreSignatureErrors: boolean;
|
|
35
35
|
protected constructor(data: ITweakedTransactionData);
|
|
36
|
-
static readScriptWitnessToWitnessStack(
|
|
36
|
+
static readScriptWitnessToWitnessStack(Buffer: Buffer): Buffer[];
|
|
37
37
|
static preEstimateTaprootTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numWitnessElements: bigint, witnessElementSize: bigint, emptyWitness: bigint, taprootControlWitnessSize?: bigint, taprootScriptSize?: bigint): bigint;
|
|
38
38
|
protected static signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer, sighashTypes: number[]): void;
|
|
39
39
|
protected static calculateSignHash(sighashTypes: number[]): number;
|
|
@@ -48,6 +48,7 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
48
48
|
protected generateScriptAddress(): Payment;
|
|
49
49
|
protected getSignerKey(): Signer;
|
|
50
50
|
protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer?: Signer): Promise<void>;
|
|
51
|
+
protected splitArray<T>(arr: T[], chunkSize: number): T[][];
|
|
51
52
|
protected signInputs(transaction: Psbt): Promise<void>;
|
|
52
53
|
protected internalPubKeyToXOnly(): Buffer;
|
|
53
54
|
protected internalInit(): void;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { Network } from 'bitcoinjs-lib';
|
|
3
|
+
import { Wallet } from '../opnet.js';
|
|
2
4
|
import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
|
|
3
5
|
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
4
6
|
import { BroadcastResponse } from './interfaces/BroadcastResponse.js';
|
|
5
|
-
import { FetchUTXOParams, FetchUTXOParamsMultiAddress, UTXO } from './interfaces/IUTXO.js';
|
|
7
|
+
import { FetchUTXOParams, FetchUTXOParamsMultiAddress, RawUTXOResponse, UTXO } from './interfaces/IUTXO.js';
|
|
8
|
+
export interface WalletUTXOs {
|
|
9
|
+
readonly confirmed: RawUTXOResponse[];
|
|
10
|
+
readonly pending: RawUTXOResponse[];
|
|
11
|
+
readonly spentTransactions: RawUTXOResponse[];
|
|
12
|
+
}
|
|
6
13
|
export declare class OPNetLimitedProvider {
|
|
7
14
|
private readonly opnetAPIUrl;
|
|
8
15
|
private readonly utxoPath;
|
|
@@ -11,6 +18,9 @@ export declare class OPNetLimitedProvider {
|
|
|
11
18
|
fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
|
|
12
19
|
fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
|
|
13
20
|
broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
|
|
21
|
+
splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
|
|
22
|
+
error: string;
|
|
23
|
+
}>;
|
|
14
24
|
rpcMethod(method: string, paramsMethod: unknown[]): Promise<unknown>;
|
|
15
25
|
fetchWrapParameters(amount: bigint): Promise<WrappedGeneration | undefined>;
|
|
16
26
|
fetchUnWrapParameters(amount: bigint, receiver: Address): Promise<UnwrapGeneration | undefined>;
|
|
@@ -9,13 +9,15 @@ export interface FetchUTXOParams {
|
|
|
9
9
|
readonly address: string;
|
|
10
10
|
readonly minAmount: bigint;
|
|
11
11
|
readonly requestedAmount: bigint;
|
|
12
|
-
|
|
12
|
+
optimized?: boolean;
|
|
13
|
+
usePendingUTXO?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export interface FetchUTXOParamsMultiAddress {
|
|
15
16
|
readonly addresses: string[];
|
|
16
17
|
readonly minAmount: bigint;
|
|
17
18
|
readonly requestedAmount: bigint;
|
|
18
19
|
readonly optimized?: boolean;
|
|
20
|
+
readonly usePendingUTXO?: boolean;
|
|
19
21
|
}
|
|
20
22
|
export interface RawUTXOResponse {
|
|
21
23
|
readonly transactionId: string;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.107";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.107';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
-
import { BIP32Interface } from 'bip32';
|
|
2
|
+
import { BIP32API, BIP32Interface } from 'bip32';
|
|
3
3
|
import { Network } from 'bitcoinjs-lib';
|
|
4
|
-
import { ECPairInterface } from 'ecpair';
|
|
4
|
+
import { ECPairAPI, ECPairInterface } from 'ecpair';
|
|
5
5
|
import { IWallet } from './interfaces/IWallet.js';
|
|
6
6
|
export declare class EcKeyPair {
|
|
7
|
-
static BIP32:
|
|
8
|
-
static ECPair:
|
|
7
|
+
static BIP32: BIP32API;
|
|
8
|
+
static ECPair: ECPairAPI;
|
|
9
9
|
static fromWIF(wif: string, network?: Network): ECPairInterface;
|
|
10
10
|
static fromPrivateKey(privateKey: Buffer, network?: Network): ECPairInterface;
|
|
11
11
|
static fromPublicKey(publicKey: Buffer, network?: Network): ECPairInterface;
|
|
@@ -115,6 +115,7 @@ export class TransactionFactory {
|
|
|
115
115
|
utxos: [newUtxo],
|
|
116
116
|
randomBytes: preTransaction.getRndBytes(),
|
|
117
117
|
nonWitnessUtxo: signedTransaction.toBuffer(),
|
|
118
|
+
optionalOutputs: []
|
|
118
119
|
};
|
|
119
120
|
const finalTransaction = new DeploymentTransaction(newParams);
|
|
120
121
|
const outTx = await finalTransaction.signTransaction();
|
|
@@ -141,7 +142,7 @@ export class TransactionFactory {
|
|
|
141
142
|
}
|
|
142
143
|
const childTransactionRequiredValue = wrapParameters.amount +
|
|
143
144
|
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT +
|
|
144
|
-
(wrapParameters.priorityFee ||
|
|
145
|
+
(wrapParameters.priorityFee || 330n);
|
|
145
146
|
const wbtc = new wBTC(wrapParameters.network, wrapParameters.chainId);
|
|
146
147
|
const to = wbtc.getAddress();
|
|
147
148
|
const fundingParameters = {
|
|
@@ -13,13 +13,10 @@ export class CustomScriptTransaction extends TransactionBuilder {
|
|
|
13
13
|
this.tapLeafScript = null;
|
|
14
14
|
this.targetScriptRedeem = null;
|
|
15
15
|
this.leftOverFundsScriptRedeem = null;
|
|
16
|
-
this.customFinalizer = (_inputIndex,
|
|
16
|
+
this.customFinalizer = (_inputIndex, _input) => {
|
|
17
17
|
if (!this.tapLeafScript) {
|
|
18
18
|
throw new Error('Tap leaf script is required');
|
|
19
19
|
}
|
|
20
|
-
if (!input.tapScriptSig) {
|
|
21
|
-
throw new Error('Tap script signature is required');
|
|
22
|
-
}
|
|
23
20
|
const scriptSolution = this.witnesses;
|
|
24
21
|
const witness = scriptSolution
|
|
25
22
|
.concat(this.tapLeafScript.script)
|
|
@@ -49,7 +49,7 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
|
|
|
49
49
|
finalizeTransactionInputs(): boolean;
|
|
50
50
|
signPSBT(): Promise<Psbt>;
|
|
51
51
|
protected buildTransaction(): Promise<void>;
|
|
52
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
52
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
53
53
|
protected signInputs(_transaction: Psbt): Promise<void>;
|
|
54
54
|
protected generateScriptAddress(): Payment;
|
|
55
55
|
protected generateTapData(): Payment;
|
|
@@ -231,11 +231,11 @@ export class MultiSignTransaction extends TransactionBuilder {
|
|
|
231
231
|
value: Number(this.requestedAmount),
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
|
-
async internalBuildTransaction(transaction) {
|
|
234
|
+
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
235
235
|
const inputs = this.getInputs();
|
|
236
236
|
const outputs = this.getOutputs();
|
|
237
237
|
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
238
|
-
transaction.addInputs(inputs);
|
|
238
|
+
transaction.addInputs(inputs, checkPartialSigs);
|
|
239
239
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
240
240
|
transaction.updateInput(i, this.updateInputs[i]);
|
|
241
241
|
}
|
|
@@ -32,6 +32,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
32
32
|
protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
|
|
33
33
|
finalScriptWitness: Buffer;
|
|
34
34
|
};
|
|
35
|
+
private signIndividualInputs;
|
|
35
36
|
private getPubKeys;
|
|
36
37
|
private generateRedeemScripts;
|
|
37
38
|
}
|
|
@@ -14,9 +14,6 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
14
14
|
if (!this.tapLeafScript) {
|
|
15
15
|
throw new Error('Tap leaf script is required');
|
|
16
16
|
}
|
|
17
|
-
if (!input.tapScriptSig) {
|
|
18
|
-
throw new Error('Tap script signature is required');
|
|
19
|
-
}
|
|
20
17
|
if (!this.contractSecret) {
|
|
21
18
|
throw new Error('Contract secret is required');
|
|
22
19
|
}
|
|
@@ -91,38 +88,32 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
91
88
|
await super.signInputs(transaction);
|
|
92
89
|
return;
|
|
93
90
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
const txs = transaction.data.inputs;
|
|
92
|
+
for (let i = 0; i < txs.length; i += 20) {
|
|
93
|
+
const batch = txs.slice(i, i + 20);
|
|
94
|
+
const promises = [];
|
|
95
|
+
for (let y = 0; y < batch.length; y++) {
|
|
96
|
+
const offset = i * 20 + y;
|
|
97
|
+
const input = batch[y];
|
|
98
|
+
promises.push(this.signIndividualInputs(transaction, input, offset));
|
|
101
99
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
100
|
+
await Promise.all(promises).catch((e) => {
|
|
101
|
+
throw e;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
transaction.finalizeInput(0, this.customFinalizer);
|
|
106
|
+
this.log(`Finalized input 0!`);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.log(`Failed to finalize input 0: ${e.stack}`);
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0; i < txs.length; i++) {
|
|
113
112
|
try {
|
|
114
113
|
transaction.finalizeInput(i);
|
|
115
|
-
|
|
114
|
+
this.log(`Finalized input ${i}!`);
|
|
116
115
|
}
|
|
117
|
-
catch
|
|
118
|
-
if (signed || finalized) {
|
|
119
|
-
this.log(`Signed input or finalized input #${i} out of ${transaction.data.inputs.length}! {Signed: ${signed}, Finalized: ${finalized}}`);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (this.regenerated || this.ignoreSignatureErrors) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
throw new Error('Failed to sign input');
|
|
116
|
+
catch { }
|
|
126
117
|
}
|
|
127
118
|
}
|
|
128
119
|
generateScriptAddress() {
|
|
@@ -176,6 +167,27 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
176
167
|
},
|
|
177
168
|
];
|
|
178
169
|
}
|
|
170
|
+
async signIndividualInputs(transaction, input, i) {
|
|
171
|
+
let signed = false;
|
|
172
|
+
try {
|
|
173
|
+
await this.signInput(transaction, input, i, this.scriptSigner);
|
|
174
|
+
signed = true;
|
|
175
|
+
}
|
|
176
|
+
catch { }
|
|
177
|
+
try {
|
|
178
|
+
await this.signInput(transaction, input, i);
|
|
179
|
+
signed = true;
|
|
180
|
+
}
|
|
181
|
+
catch { }
|
|
182
|
+
if (signed) {
|
|
183
|
+
this.log(`Signed input #${i} out of ${transaction.data.inputs.length}! {Signed: ${signed}}`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (this.regenerated || this.ignoreSignatureErrors) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
throw new Error('Failed to sign input');
|
|
190
|
+
}
|
|
179
191
|
getPubKeys() {
|
|
180
192
|
const pubkeys = [this.signer.publicKey];
|
|
181
193
|
if (this.scriptSigner) {
|
|
@@ -14,6 +14,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
14
14
|
overflowFees: bigint;
|
|
15
15
|
transactionFee: bigint;
|
|
16
16
|
estimatedFees: bigint;
|
|
17
|
+
optionalOutputs: PsbtOutputExtended[] | undefined;
|
|
17
18
|
protected transaction: Psbt;
|
|
18
19
|
protected readonly updateInputs: UpdateInput[];
|
|
19
20
|
protected readonly outputs: PsbtOutputExtended[];
|
|
@@ -34,7 +35,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
34
35
|
setDestinationAddress(address: Address): void;
|
|
35
36
|
setMaximumFeeRate(feeRate: number): void;
|
|
36
37
|
signTransaction(): Promise<Transaction>;
|
|
37
|
-
generateTransactionMinimalSignatures(): Promise<void>;
|
|
38
|
+
generateTransactionMinimalSignatures(checkPartialSigs?: boolean): Promise<void>;
|
|
38
39
|
signPSBT(): Promise<Psbt>;
|
|
39
40
|
addInput(input: PsbtInputExtended): void;
|
|
40
41
|
addOutput(output: PsbtOutputExtended): void;
|
|
@@ -50,6 +51,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
50
51
|
protected getTransactionOPNetFee(): bigint;
|
|
51
52
|
protected calculateTotalUTXOAmount(): bigint;
|
|
52
53
|
protected calculateTotalVOutAmount(): bigint;
|
|
54
|
+
protected addOptionalOutputsAndGetAmount(): bigint;
|
|
53
55
|
protected addInputsFromUTXO(): void;
|
|
54
56
|
protected internalInit(): void;
|
|
55
57
|
protected abstract buildTransaction(): Promise<void>;
|
|
@@ -58,5 +60,5 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
58
60
|
protected getTapOutput(): Buffer;
|
|
59
61
|
protected verifyUTXOValidity(): void;
|
|
60
62
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
61
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
63
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
62
64
|
}
|
|
@@ -25,6 +25,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
25
25
|
this.priorityFee = parameters.priorityFee ?? 0n;
|
|
26
26
|
this.utxos = parameters.utxos;
|
|
27
27
|
this.to = parameters.to || undefined;
|
|
28
|
+
this.optionalOutputs = parameters.optionalOutputs;
|
|
28
29
|
this.from = TransactionBuilder.getFrom(parameters.from, this.signer, this.network);
|
|
29
30
|
this.totalInputAmount = this.calculateTotalUTXOAmount();
|
|
30
31
|
const totalVOut = this.calculateTotalVOutAmount();
|
|
@@ -73,6 +74,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
73
74
|
priorityFee: this.priorityFee ?? 0n,
|
|
74
75
|
from: this.from,
|
|
75
76
|
amount: this.estimatedFees,
|
|
77
|
+
optionalOutputs: this.optionalOutputs,
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
setDestinationAddress(address) {
|
|
@@ -101,7 +103,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
101
103
|
}
|
|
102
104
|
throw new Error('Could not sign transaction');
|
|
103
105
|
}
|
|
104
|
-
async generateTransactionMinimalSignatures() {
|
|
106
|
+
async generateTransactionMinimalSignatures(checkPartialSigs = false) {
|
|
105
107
|
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
106
108
|
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
107
109
|
}
|
|
@@ -110,7 +112,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
110
112
|
const inputs = this.getInputs();
|
|
111
113
|
const outputs = this.getOutputs();
|
|
112
114
|
this.transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
113
|
-
this.transaction.addInputs(inputs);
|
|
115
|
+
this.transaction.addInputs(inputs, checkPartialSigs);
|
|
114
116
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
115
117
|
this.transaction.updateInput(i, this.updateInputs[i]);
|
|
116
118
|
}
|
|
@@ -180,7 +182,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
180
182
|
return outputs;
|
|
181
183
|
}
|
|
182
184
|
async addRefundOutput(amountSpent) {
|
|
183
|
-
const sendBackAmount = this.totalInputAmount - amountSpent;
|
|
185
|
+
const sendBackAmount = this.totalInputAmount - amountSpent - this.addOptionalOutputsAndGetAmount();
|
|
184
186
|
if (sendBackAmount >= TransactionBuilder.MINIMUM_DUST) {
|
|
185
187
|
if (AddressVerificator.isValidP2TRAddress(this.from, this.network)) {
|
|
186
188
|
await this.setFeeOutput({
|
|
@@ -231,6 +233,16 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
231
233
|
}
|
|
232
234
|
return total;
|
|
233
235
|
}
|
|
236
|
+
addOptionalOutputsAndGetAmount() {
|
|
237
|
+
if (!this.optionalOutputs)
|
|
238
|
+
return 0n;
|
|
239
|
+
let refundedFromOptionalOutputs = 0n;
|
|
240
|
+
for (let i = 0; i < this.optionalOutputs.length; i++) {
|
|
241
|
+
this.addOutput(this.optionalOutputs[i]);
|
|
242
|
+
refundedFromOptionalOutputs += BigInt(this.optionalOutputs[i].value);
|
|
243
|
+
}
|
|
244
|
+
return refundedFromOptionalOutputs;
|
|
245
|
+
}
|
|
234
246
|
addInputsFromUTXO() {
|
|
235
247
|
if (this.utxos.length) {
|
|
236
248
|
if (this.totalInputAmount < TransactionBuilder.MINIMUM_DUST) {
|
|
@@ -298,12 +310,12 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
298
310
|
this.overflowFees = BigInt(valueLeft);
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
|
-
async internalBuildTransaction(transaction) {
|
|
313
|
+
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
302
314
|
if (transaction.data.inputs.length === 0) {
|
|
303
315
|
const inputs = this.getInputs();
|
|
304
316
|
const outputs = this.getOutputs();
|
|
305
317
|
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
306
|
-
transaction.addInputs(inputs);
|
|
318
|
+
transaction.addInputs(inputs, checkPartialSigs);
|
|
307
319
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
308
320
|
transaction.updateInput(i, this.updateInputs[i]);
|
|
309
321
|
}
|
|
@@ -19,7 +19,7 @@ export declare class UnwrapSegwitTransaction extends SharedInteractionTransactio
|
|
|
19
19
|
static generateBurnCalldata(amount: bigint): Buffer;
|
|
20
20
|
signPSBT(): Promise<Psbt>;
|
|
21
21
|
mergeVaults(input: VaultUTXOs[]): Promise<void>;
|
|
22
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
22
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
23
23
|
protected generateMultiSignRedeemScript(publicKeys: string[], minimum: number): {
|
|
24
24
|
witnessUtxo: Buffer;
|
|
25
25
|
redeemScript: Buffer;
|
|
@@ -81,12 +81,12 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
81
81
|
await this.addVaultInputs(vault);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
async internalBuildTransaction(transaction) {
|
|
84
|
+
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
85
85
|
if (transaction.data.inputs.length === 0) {
|
|
86
86
|
const inputs = this.getInputs();
|
|
87
87
|
const outputs = this.getOutputs();
|
|
88
88
|
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
89
|
-
transaction.addInputs(inputs);
|
|
89
|
+
transaction.addInputs(inputs, checkPartialSigs);
|
|
90
90
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
91
91
|
transaction.updateInput(i, this.updateInputs[i]);
|
|
92
92
|
}
|
|
@@ -149,7 +149,6 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
149
149
|
const inputIndex = this.transaction.inputCount;
|
|
150
150
|
this.addVaultUTXO(utxo, p2wshOutput);
|
|
151
151
|
if (firstSigner) {
|
|
152
|
-
this.log(`Signing input ${inputIndex} with ${firstSigner.publicKey.toString('hex')}`);
|
|
153
152
|
try {
|
|
154
153
|
await this.signInput(this.transaction, this.transaction.data.inputs[inputIndex], inputIndex, this.signer);
|
|
155
154
|
this.log(`Signed input ${inputIndex} with ${firstSigner.publicKey.toString('hex')}`);
|
|
@@ -34,7 +34,7 @@ export declare class UnwrapTransaction extends SharedInteractionTransaction<Tran
|
|
|
34
34
|
redeem: Payment;
|
|
35
35
|
};
|
|
36
36
|
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
37
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
37
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
38
38
|
private addVaultUTXO;
|
|
39
39
|
private addVaultInputs;
|
|
40
40
|
private calculateOutputLeftAmountFromVaults;
|
|
@@ -178,12 +178,12 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
178
178
|
input.tapScriptSig[1].signature,
|
|
179
179
|
];
|
|
180
180
|
}
|
|
181
|
-
async internalBuildTransaction(transaction) {
|
|
181
|
+
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
182
182
|
if (transaction.data.inputs.length === 0) {
|
|
183
183
|
const inputs = this.getInputs();
|
|
184
184
|
const outputs = this.getOutputs();
|
|
185
185
|
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
186
|
-
transaction.addInputs(inputs);
|
|
186
|
+
transaction.addInputs(inputs, checkPartialSigs);
|
|
187
187
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
188
188
|
transaction.updateInput(i, this.updateInputs[i]);
|
|
189
189
|
}
|
|
@@ -4,12 +4,14 @@ import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
|
4
4
|
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
5
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
|
+
import { PsbtOutputExtended } from './Tap.js';
|
|
7
8
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
8
9
|
readonly from?: Address;
|
|
9
|
-
readonly to?: Address
|
|
10
|
+
readonly to?: Address;
|
|
10
11
|
utxos: UTXO[];
|
|
11
|
-
nonWitnessUtxo?: Buffer
|
|
12
|
+
nonWitnessUtxo?: Buffer;
|
|
12
13
|
estimatedFees?: bigint;
|
|
14
|
+
optionalOutputs?: PsbtOutputExtended[];
|
|
13
15
|
chainId?: ChainId;
|
|
14
16
|
readonly feeRate: number;
|
|
15
17
|
readonly priorityFee: bigint;
|
|
@@ -19,27 +21,26 @@ export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
|
19
21
|
splitInputsInto?: number;
|
|
20
22
|
}
|
|
21
23
|
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
22
|
-
calldata?: Buffer
|
|
24
|
+
calldata?: Buffer;
|
|
23
25
|
disableAutoRefund?: boolean;
|
|
24
26
|
readonly randomBytes?: Buffer;
|
|
25
27
|
}
|
|
26
|
-
export interface IInteractionParameters extends SharedInteractionParameters {
|
|
28
|
+
export interface IInteractionParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
27
29
|
readonly calldata: Buffer;
|
|
28
30
|
readonly to: Address;
|
|
29
31
|
}
|
|
30
|
-
export interface IWrapParameters extends SharedInteractionParameters {
|
|
32
|
+
export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
31
33
|
readonly to?: Address;
|
|
32
34
|
readonly from: Address;
|
|
33
35
|
readonly amount: bigint;
|
|
34
36
|
readonly receiver?: Address;
|
|
35
37
|
readonly generationParameters: WrappedGeneration;
|
|
36
38
|
}
|
|
37
|
-
export interface IUnwrapParameters extends SharedInteractionParameters {
|
|
39
|
+
export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
38
40
|
readonly unwrapUTXOs: VaultUTXOs[];
|
|
39
41
|
readonly amount: bigint;
|
|
40
42
|
}
|
|
41
|
-
export interface IDeploymentParameters extends ITransactionParameters {
|
|
43
|
+
export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
|
|
42
44
|
readonly bytecode: Buffer;
|
|
43
|
-
readonly to?: undefined;
|
|
44
45
|
readonly randomBytes?: Buffer;
|
|
45
46
|
}
|
|
@@ -34,7 +34,7 @@ export declare class PsbtTransaction extends TweakedTransaction {
|
|
|
34
34
|
extractTransaction(): Transaction;
|
|
35
35
|
final(): string;
|
|
36
36
|
toHex(): string;
|
|
37
|
-
addInput(input: PsbtInputExtended): void;
|
|
37
|
+
addInput(input: PsbtInputExtended, checkPartialSigs?: boolean): void;
|
|
38
38
|
addOutput(output: PsbtOutputExtended): void;
|
|
39
39
|
attemptFinalizeInputs(n?: number): boolean;
|
|
40
40
|
getPSBT(): Psbt;
|
|
@@ -47,8 +47,8 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
47
47
|
toHex() {
|
|
48
48
|
return this.transaction.toHex();
|
|
49
49
|
}
|
|
50
|
-
addInput(input) {
|
|
51
|
-
this.transaction.addInput(input);
|
|
50
|
+
addInput(input, checkPartialSigs = false) {
|
|
51
|
+
this.transaction.addInput(input, checkPartialSigs);
|
|
52
52
|
}
|
|
53
53
|
addOutput(output) {
|
|
54
54
|
if (!output.value)
|