@btc-vision/transaction 1.0.106 → 1.0.108
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 +3 -3
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +1 -1
- package/browser/transaction/builders/UnwrapTransaction.d.ts +1 -1
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -1
- package/browser/utxo/interfaces/IUTXO.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/keypair/EcKeyPair.d.ts +4 -4
- package/build/transaction/browser/extensions/UnisatSigner.js +4 -3
- 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 +42 -31
- package/build/transaction/builders/TransactionBuilder.d.ts +3 -3
- package/build/transaction/builders/TransactionBuilder.js +4 -4
- 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/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.js +1 -1
- package/build/utxo/interfaces/IUTXO.d.ts +1 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/keypair/EcKeyPair.ts +4 -4
- package/src/transaction/browser/extensions/UnisatSigner.ts +4 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +3 -7
- package/src/transaction/builders/MultiSignTransaction.ts +3 -2
- package/src/transaction/builders/SharedInteractionTransaction.ts +59 -34
- package/src/transaction/builders/TransactionBuilder.ts +17 -11
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +5 -5
- package/src/transaction/builders/UnwrapTransaction.ts +6 -2
- package/src/transaction/processor/PsbtTransaction.ts +2 -2
- package/src/transaction/shared/TweakedTransaction.ts +38 -10
- package/src/utxo/OPNetLimitedProvider.ts +1 -1
- package/src/utxo/interfaces/IUTXO.ts +1 -0
|
@@ -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[];
|
|
@@ -27,7 +28,6 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
27
28
|
protected to: Address | undefined;
|
|
28
29
|
protected from: Address;
|
|
29
30
|
protected _maximumFeeRate: number;
|
|
30
|
-
optionalOutputs: PsbtOutputExtended[] | undefined;
|
|
31
31
|
protected constructor(parameters: ITransactionParameters);
|
|
32
32
|
static getFrom(from: string | undefined, keypair: ECPairInterface, network: Network): Address;
|
|
33
33
|
static witnessStackToScriptWitness(witness: Buffer[]): Buffer;
|
|
@@ -35,7 +35,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
35
35
|
setDestinationAddress(address: Address): void;
|
|
36
36
|
setMaximumFeeRate(feeRate: number): void;
|
|
37
37
|
signTransaction(): Promise<Transaction>;
|
|
38
|
-
generateTransactionMinimalSignatures(): Promise<void>;
|
|
38
|
+
generateTransactionMinimalSignatures(checkPartialSigs?: boolean): Promise<void>;
|
|
39
39
|
signPSBT(): Promise<Psbt>;
|
|
40
40
|
addInput(input: PsbtInputExtended): void;
|
|
41
41
|
addOutput(output: PsbtOutputExtended): void;
|
|
@@ -60,5 +60,5 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
60
60
|
protected getTapOutput(): Buffer;
|
|
61
61
|
protected verifyUTXOValidity(): void;
|
|
62
62
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
63
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
63
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
64
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;
|
|
@@ -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;
|
|
@@ -17,6 +17,7 @@ export interface FetchUTXOParamsMultiAddress {
|
|
|
17
17
|
readonly minAmount: bigint;
|
|
18
18
|
readonly requestedAmount: bigint;
|
|
19
19
|
readonly optimized?: boolean;
|
|
20
|
+
readonly usePendingUTXO?: boolean;
|
|
20
21
|
}
|
|
21
22
|
export interface RawUTXOResponse {
|
|
22
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.108";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.108';
|
|
@@ -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;
|
|
@@ -41,10 +41,11 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
41
41
|
return this._network;
|
|
42
42
|
}
|
|
43
43
|
get unisat() {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const module = window.opnet || window.unisat;
|
|
45
|
+
if (!module) {
|
|
46
|
+
throw new Error('OPWallet extension not found');
|
|
46
47
|
}
|
|
47
|
-
return
|
|
48
|
+
return module;
|
|
48
49
|
}
|
|
49
50
|
async init() {
|
|
50
51
|
if (this.isInitialized) {
|
|
@@ -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,31 @@ 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
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.error(`Failed to finalize input 0: ${e.stack}`);
|
|
109
|
+
}
|
|
110
|
+
for (let i = 0; i < txs.length; i++) {
|
|
113
111
|
try {
|
|
114
112
|
transaction.finalizeInput(i);
|
|
115
|
-
|
|
113
|
+
this.log(`Finalized input ${i}!`);
|
|
116
114
|
}
|
|
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');
|
|
115
|
+
catch { }
|
|
126
116
|
}
|
|
127
117
|
}
|
|
128
118
|
generateScriptAddress() {
|
|
@@ -176,6 +166,27 @@ export class SharedInteractionTransaction extends TransactionBuilder {
|
|
|
176
166
|
},
|
|
177
167
|
];
|
|
178
168
|
}
|
|
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
|
+
}
|
|
179
190
|
getPubKeys() {
|
|
180
191
|
const pubkeys = [this.signer.publicKey];
|
|
181
192
|
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[];
|
|
@@ -27,7 +28,6 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
27
28
|
protected to: Address | undefined;
|
|
28
29
|
protected from: Address;
|
|
29
30
|
protected _maximumFeeRate: number;
|
|
30
|
-
optionalOutputs: PsbtOutputExtended[] | undefined;
|
|
31
31
|
protected constructor(parameters: ITransactionParameters);
|
|
32
32
|
static getFrom(from: string | undefined, keypair: ECPairInterface, network: Network): Address;
|
|
33
33
|
static witnessStackToScriptWitness(witness: Buffer[]): Buffer;
|
|
@@ -35,7 +35,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
35
35
|
setDestinationAddress(address: Address): void;
|
|
36
36
|
setMaximumFeeRate(feeRate: number): void;
|
|
37
37
|
signTransaction(): Promise<Transaction>;
|
|
38
|
-
generateTransactionMinimalSignatures(): Promise<void>;
|
|
38
|
+
generateTransactionMinimalSignatures(checkPartialSigs?: boolean): Promise<void>;
|
|
39
39
|
signPSBT(): Promise<Psbt>;
|
|
40
40
|
addInput(input: PsbtInputExtended): void;
|
|
41
41
|
addOutput(output: PsbtOutputExtended): void;
|
|
@@ -60,5 +60,5 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
60
60
|
protected getTapOutput(): Buffer;
|
|
61
61
|
protected verifyUTXOValidity(): void;
|
|
62
62
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
63
|
-
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
63
|
+
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
64
64
|
}
|
|
@@ -103,7 +103,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
103
103
|
}
|
|
104
104
|
throw new Error('Could not sign transaction');
|
|
105
105
|
}
|
|
106
|
-
async generateTransactionMinimalSignatures() {
|
|
106
|
+
async generateTransactionMinimalSignatures(checkPartialSigs = false) {
|
|
107
107
|
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
108
108
|
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
109
109
|
}
|
|
@@ -112,7 +112,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
112
112
|
const inputs = this.getInputs();
|
|
113
113
|
const outputs = this.getOutputs();
|
|
114
114
|
this.transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
115
|
-
this.transaction.addInputs(inputs);
|
|
115
|
+
this.transaction.addInputs(inputs, checkPartialSigs);
|
|
116
116
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
117
117
|
this.transaction.updateInput(i, this.updateInputs[i]);
|
|
118
118
|
}
|
|
@@ -310,12 +310,12 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
310
310
|
this.overflowFees = BigInt(valueLeft);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
async internalBuildTransaction(transaction) {
|
|
313
|
+
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
314
314
|
if (transaction.data.inputs.length === 0) {
|
|
315
315
|
const inputs = this.getInputs();
|
|
316
316
|
const outputs = this.getOutputs();
|
|
317
317
|
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
318
|
-
transaction.addInputs(inputs);
|
|
318
|
+
transaction.addInputs(inputs, checkPartialSigs);
|
|
319
319
|
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
320
320
|
transaction.updateInput(i, this.updateInputs[i]);
|
|
321
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
|
}
|
|
@@ -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)
|
|
@@ -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;
|
|
@@ -28,15 +28,15 @@ export class TweakedTransaction extends Logger {
|
|
|
28
28
|
this.nonWitnessUtxo = data.nonWitnessUtxo;
|
|
29
29
|
this.isBrowser = typeof window !== 'undefined';
|
|
30
30
|
}
|
|
31
|
-
static readScriptWitnessToWitnessStack(
|
|
31
|
+
static readScriptWitnessToWitnessStack(Buffer) {
|
|
32
32
|
let offset = 0;
|
|
33
33
|
function readSlice(n) {
|
|
34
|
-
const slice =
|
|
34
|
+
const slice = Buffer.subarray(offset, offset + n);
|
|
35
35
|
offset += n;
|
|
36
36
|
return slice;
|
|
37
37
|
}
|
|
38
38
|
function readVarInt() {
|
|
39
|
-
const varint = varuint.decode(
|
|
39
|
+
const varint = varuint.decode(Buffer, offset);
|
|
40
40
|
offset += varuint.decode.bytes;
|
|
41
41
|
return varint;
|
|
42
42
|
}
|
|
@@ -193,15 +193,35 @@ export class TweakedTransaction extends Logger {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
splitArray(arr, chunkSize) {
|
|
197
|
+
if (chunkSize <= 0) {
|
|
198
|
+
throw new Error('Chunk size must be greater than 0.');
|
|
199
|
+
}
|
|
200
|
+
const result = [];
|
|
201
|
+
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
202
|
+
result.push(arr.slice(i, i + chunkSize));
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
196
206
|
async signInputs(transaction) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
const txs = transaction.data.inputs;
|
|
208
|
+
const batchSize = 20;
|
|
209
|
+
const batches = this.splitArray(txs, batchSize);
|
|
210
|
+
for (let i = 0; i < batches.length; i++) {
|
|
211
|
+
const batch = batches[i];
|
|
212
|
+
const promises = [];
|
|
213
|
+
const offset = i * batchSize;
|
|
214
|
+
for (let j = 0; j < batch.length; j++) {
|
|
215
|
+
const index = offset + j;
|
|
216
|
+
const input = batch[j];
|
|
217
|
+
try {
|
|
218
|
+
promises.push(this.signInput(transaction, input, index));
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
this.log(`Failed to sign input ${index}: ${e.stack}`);
|
|
222
|
+
}
|
|
204
223
|
}
|
|
224
|
+
await Promise.all(promises);
|
|
205
225
|
}
|
|
206
226
|
try {
|
|
207
227
|
transaction.finalizeAllInputs();
|
|
@@ -76,7 +76,7 @@ export class OPNetLimitedProvider {
|
|
|
76
76
|
minAmount: settings.minAmount,
|
|
77
77
|
requestedAmount: settings.requestedAmount,
|
|
78
78
|
optimized: settings.optimized,
|
|
79
|
-
usePendingUTXO:
|
|
79
|
+
usePendingUTXO: settings.usePendingUTXO,
|
|
80
80
|
};
|
|
81
81
|
const promise = this.fetchUTXO(params).catch(() => {
|
|
82
82
|
return [];
|
|
@@ -17,6 +17,7 @@ export interface FetchUTXOParamsMultiAddress {
|
|
|
17
17
|
readonly minAmount: bigint;
|
|
18
18
|
readonly requestedAmount: bigint;
|
|
19
19
|
readonly optimized?: boolean;
|
|
20
|
+
readonly usePendingUTXO?: boolean;
|
|
20
21
|
}
|
|
21
22
|
export interface RawUTXOResponse {
|
|
22
23
|
readonly transactionId: string;
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.108';
|
package/src/keypair/EcKeyPair.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
2
2
|
import { Address } from '@btc-vision/bsi-binary';
|
|
3
|
-
import bip32, { BIP32Factory, BIP32Interface } from 'bip32';
|
|
3
|
+
import bip32, { BIP32API, BIP32Factory, BIP32Interface } from 'bip32';
|
|
4
4
|
import { address, initEccLib, Network, networks, payments } from 'bitcoinjs-lib';
|
|
5
5
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
6
|
-
import { ECPairFactory, ECPairInterface } from 'ecpair';
|
|
6
|
+
import { ECPairAPI, ECPairFactory, ECPairInterface } from 'ecpair';
|
|
7
7
|
import { IWallet } from './interfaces/IWallet.js';
|
|
8
8
|
|
|
9
9
|
initEccLib(ecc);
|
|
@@ -22,8 +22,8 @@ if (!BIP32factory) {
|
|
|
22
22
|
* @example import { EcKeyPair } from '@btc-vision/transaction';
|
|
23
23
|
*/
|
|
24
24
|
export class EcKeyPair {
|
|
25
|
-
public static BIP32 = BIP32factory(ecc);
|
|
26
|
-
public static ECPair = ECPairFactory(ecc);
|
|
25
|
+
public static BIP32: BIP32API = BIP32factory(ecc);
|
|
26
|
+
public static ECPair: ECPairAPI = ECPairFactory(ecc);
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Generate a keypair from a WIF
|
|
@@ -75,11 +75,12 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
public get unisat(): Unisat {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const module = window.opnet || window.unisat;
|
|
79
|
+
if (!module) {
|
|
80
|
+
throw new Error('OPWallet extension not found');
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
return
|
|
83
|
+
return module;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
public async init(): Promise<void> {
|