@btc-vision/transaction 1.0.100 → 1.0.102
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/.vscode/settings.json +10 -0
- package/LICENSE +21 -0
- package/browser/_version.d.ts +1 -1
- package/browser/generators/Features.d.ts +4 -1
- package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/keypair/EcKeyPair.d.ts +2 -2
- package/browser/metadata/contracts/wBTC.d.ts +2 -2
- package/browser/transaction/TransactionFactory.d.ts +4 -5
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +2 -2
- package/browser/transaction/browser/types/Unisat.d.ts +1 -2
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/processor/PsbtTransaction.d.ts +2 -2
- package/browser/utils/BitcoinUtils.d.ts +1 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts +3 -3
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/Features.d.ts +4 -1
- package/build/generators/Features.js +4 -1
- package/build/generators/builders/CalldataGenerator.d.ts +1 -1
- package/build/generators/builders/CalldataGenerator.js +5 -3
- package/build/generators/builders/MultiSignGenerator.js +2 -2
- package/build/keypair/EcKeyPair.d.ts +2 -2
- package/build/keypair/EcKeyPair.js +8 -5
- package/build/metadata/contracts/wBTC.d.ts +2 -2
- package/build/metadata/contracts/wBTC.js +2 -2
- package/build/metadata/tokens.js +2 -2
- package/build/signer/TweakedSigner.js +1 -1
- package/build/transaction/TransactionFactory.d.ts +4 -5
- package/build/transaction/TransactionFactory.js +6 -7
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +2 -2
- package/build/transaction/browser/extensions/UnisatSigner.js +3 -3
- package/build/transaction/browser/types/Unisat.d.ts +1 -2
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/build/transaction/builders/CustomScriptTransaction.js +7 -7
- package/build/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/build/transaction/builders/DeploymentTransaction.js +2 -2
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/FundingTransaction.js +2 -2
- package/build/transaction/builders/MultiSignTransaction.js +7 -7
- package/build/transaction/builders/SharedInteractionTransaction.js +3 -3
- package/build/transaction/builders/TransactionBuilder.js +6 -6
- package/build/transaction/builders/UnwrapTransaction.js +4 -4
- package/build/transaction/builders/WrapTransaction.js +1 -1
- package/build/transaction/processor/PsbtTransaction.d.ts +2 -2
- package/build/transaction/processor/PsbtTransaction.js +2 -2
- package/build/transaction/shared/TweakedTransaction.js +4 -4
- package/build/utils/BitcoinUtils.d.ts +1 -1
- package/build/utils/BitcoinUtils.js +1 -1
- package/build/utxo/OPNetLimitedProvider.d.ts +3 -3
- package/build/utxo/OPNetLimitedProvider.js +7 -7
- package/eslint.config.js +38 -0
- package/gulpfile.js +19 -45
- package/package.json +14 -8
- package/src/_version.ts +1 -1
- package/src/generators/Features.ts +5 -1
- package/src/generators/builders/CalldataGenerator.ts +6 -4
- package/src/generators/builders/MultiSignGenerator.ts +6 -4
- package/src/keypair/EcKeyPair.ts +10 -8
- package/src/metadata/contracts/wBTC.ts +3 -3
- package/src/metadata/tokens.ts +2 -2
- package/src/signer/TweakedSigner.ts +4 -4
- package/src/transaction/TransactionFactory.ts +18 -20
- package/src/transaction/browser/extensions/UnisatSigner.ts +6 -6
- package/src/transaction/browser/types/Unisat.ts +1 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +7 -7
- package/src/transaction/builders/DeploymentTransaction.ts +5 -5
- package/src/transaction/builders/FundingTransaction.ts +2 -2
- package/src/transaction/builders/MultiSignTransaction.ts +8 -7
- package/src/transaction/builders/SharedInteractionTransaction.ts +3 -3
- package/src/transaction/builders/TransactionBuilder.ts +6 -6
- package/src/transaction/builders/UnwrapTransaction.ts +4 -4
- package/src/transaction/builders/WrapTransaction.ts +1 -1
- package/src/transaction/processor/PsbtTransaction.ts +4 -4
- package/src/transaction/shared/TweakedTransaction.ts +19 -11
- package/src/utils/BitcoinUtils.ts +3 -3
- package/src/utxo/OPNetLimitedProvider.ts +19 -10
- package/webpack.config.js +1 -0
- package/LICENSE.md +0 -62
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
1
2
|
import { Psbt, Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
import { Output } from 'bitcoinjs-lib/src/transaction.js';
|
|
4
|
+
import { currentConsensus, currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
5
|
+
import { wBTC } from '../metadata/contracts/wBTC.js';
|
|
6
|
+
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
7
|
+
import {
|
|
8
|
+
CustomScriptTransaction,
|
|
9
|
+
ICustomTransactionParameters,
|
|
10
|
+
} from './builders/CustomScriptTransaction.js';
|
|
11
|
+
import { DeploymentTransaction } from './builders/DeploymentTransaction.js';
|
|
12
|
+
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
13
|
+
import { InteractionTransaction } from './builders/InteractionTransaction.js';
|
|
14
|
+
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
15
|
+
import { UnwrapSegwitTransaction } from './builders/UnwrapSegwitTransaction.js';
|
|
16
|
+
import { UnwrapTransaction } from './builders/UnwrapTransaction.js';
|
|
17
|
+
import { WrapTransaction } from './builders/WrapTransaction.js';
|
|
18
|
+
import { TransactionType } from './enums/TransactionType.js';
|
|
2
19
|
import {
|
|
3
20
|
IDeploymentParameters,
|
|
4
21
|
IFundingTransactionParameters,
|
|
@@ -6,25 +23,8 @@ import {
|
|
|
6
23
|
IUnwrapParameters,
|
|
7
24
|
IWrapParameters,
|
|
8
25
|
} from './interfaces/ITransactionParameters.js';
|
|
9
|
-
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
10
|
-
import { Output } from 'bitcoinjs-lib/src/transaction.js';
|
|
11
|
-
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
12
|
-
import { InteractionTransaction } from './builders/InteractionTransaction.js';
|
|
13
|
-
import { DeploymentTransaction } from './builders/DeploymentTransaction.js';
|
|
14
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
15
|
-
import { wBTC } from '../metadata/contracts/wBTC.js';
|
|
16
|
-
import { WrapTransaction } from './builders/WrapTransaction.js';
|
|
17
|
-
import { PSBTTypes } from './psbt/PSBTTypes.js';
|
|
18
26
|
import { VaultUTXOs } from './processor/PsbtTransaction.js';
|
|
19
|
-
import {
|
|
20
|
-
import { UnwrapTransaction } from './builders/UnwrapTransaction.js';
|
|
21
|
-
import { currentConsensus, currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
22
|
-
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
23
|
-
import { TransactionType } from './enums/TransactionType.js';
|
|
24
|
-
import {
|
|
25
|
-
CustomScriptTransaction,
|
|
26
|
-
ICustomTransactionParameters,
|
|
27
|
-
} from './builders/CustomScriptTransaction';
|
|
27
|
+
import { PSBTTypes } from './psbt/PSBTTypes.js';
|
|
28
28
|
|
|
29
29
|
export interface DeploymentResult {
|
|
30
30
|
readonly transaction: [string, string];
|
|
@@ -73,8 +73,6 @@ export interface UnwrapResult {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export class TransactionFactory {
|
|
76
|
-
constructor() {}
|
|
77
|
-
|
|
78
76
|
/**
|
|
79
77
|
* @description Generate a transaction with a custom script.
|
|
80
78
|
* @returns {Promise<[string, string]>} - The signed transaction
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CustomKeypair } from '../BrowserSignerBase.js';
|
|
2
|
-
import { Network, networks, Psbt } from 'bitcoinjs-lib';
|
|
3
|
-
import { PsbtSignatureOptions, Unisat, UnisatNetwork } from '../types/Unisat.js';
|
|
4
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
5
|
-
import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
|
|
6
|
-
import { ECPairInterface } from 'ecpair';
|
|
7
2
|
import { TapScriptSig } from 'bip174/src/lib/interfaces.js';
|
|
3
|
+
import { Network, networks, Psbt } from 'bitcoinjs-lib';
|
|
4
|
+
import { ECPairInterface } from 'ecpair';
|
|
5
|
+
import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
|
|
6
|
+
import { CustomKeypair } from '../BrowserSignerBase.js';
|
|
7
|
+
import { PsbtSignatureOptions, Unisat, UnisatNetwork } from '../types/Unisat.js';
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
interface Window {
|
|
@@ -139,7 +139,7 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
139
139
|
i: number,
|
|
140
140
|
sighashTypes: number[],
|
|
141
141
|
): Promise<void> {
|
|
142
|
-
|
|
142
|
+
const firstSignature = await this.signTweaked(transaction, i, sighashTypes, false);
|
|
143
143
|
this.combine(transaction, firstSignature, i);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -90,9 +90,7 @@ export interface Unisat {
|
|
|
90
90
|
|
|
91
91
|
on(event: 'accountsChanged', listener: (accounts: string[]) => void): void;
|
|
92
92
|
|
|
93
|
-
on(event: 'networkChanged', listener: (network: UnisatNetwork) => void): void;
|
|
94
|
-
|
|
95
|
-
on(event: 'chainChanged', listener: (network: UnisatNetwork) => void): void;
|
|
93
|
+
on(event: 'chainChanged' | 'networkChanged', listener: (network: UnisatNetwork) => void): void;
|
|
96
94
|
|
|
97
95
|
removeListener(event: 'accountsChanged', listener: (accounts: string[]) => void): void;
|
|
98
96
|
|
|
@@ -4,11 +4,11 @@ import { TapLeafScript } from '../interfaces/Tap.js';
|
|
|
4
4
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
5
|
import { Address } from '@btc-vision/bsi-binary';
|
|
6
6
|
import { crypto as bitCrypto, Payment, Psbt, Signer, Stack } from 'bitcoinjs-lib';
|
|
7
|
-
import { TransactionBuilder } from './TransactionBuilder';
|
|
8
|
-
import { CustomGenerator } from '../../generators/builders/CustomGenerator';
|
|
9
|
-
import { BitcoinUtils } from '../../utils/BitcoinUtils';
|
|
10
|
-
import { EcKeyPair } from '../../keypair/EcKeyPair';
|
|
11
|
-
import { AddressGenerator } from '../../generators/AddressGenerator';
|
|
7
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
8
|
+
import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
|
|
9
|
+
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
10
|
+
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
11
|
+
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
12
12
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
13
13
|
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
14
14
|
|
|
@@ -148,7 +148,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
148
148
|
this.to = this.getScriptAddress();
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
const selectedRedeem =
|
|
151
|
+
const selectedRedeem = this.contractSigner
|
|
152
152
|
? this.targetScriptRedeem
|
|
153
153
|
: this.leftOverFundsScriptRedeem;
|
|
154
154
|
|
|
@@ -224,7 +224,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
224
224
|
* @protected
|
|
225
225
|
*/
|
|
226
226
|
protected override generateTapData(): Payment {
|
|
227
|
-
const selectedRedeem =
|
|
227
|
+
const selectedRedeem = this.contractSigner
|
|
228
228
|
? this.targetScriptRedeem
|
|
229
229
|
: this.leftOverFundsScriptRedeem;
|
|
230
230
|
|
|
@@ -14,9 +14,8 @@ import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
|
14
14
|
import { Address } from '@btc-vision/bsi-binary';
|
|
15
15
|
|
|
16
16
|
export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
17
|
+
public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
17
18
|
public type: TransactionType.DEPLOYMENT = TransactionType.DEPLOYMENT;
|
|
18
|
-
public static readonly MAXIMUM_CONTRACT_SIZE = 128*1024;
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* The contract address
|
|
22
21
|
* @protected
|
|
@@ -83,7 +82,8 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
83
82
|
this.bytecode = Compressor.compress(parameters.bytecode);
|
|
84
83
|
if (!this.bytecode) throw new Error('Bytecode is required');
|
|
85
84
|
|
|
86
|
-
if (this.bytecode.length > DeploymentTransaction.MAXIMUM_CONTRACT_SIZE)
|
|
85
|
+
if (this.bytecode.length > DeploymentTransaction.MAXIMUM_CONTRACT_SIZE)
|
|
86
|
+
throw new Error('Contract size overflow.');
|
|
87
87
|
|
|
88
88
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
89
89
|
|
|
@@ -147,7 +147,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
147
147
|
this.to = this.getScriptAddress();
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
const selectedRedeem =
|
|
150
|
+
const selectedRedeem = this.contractSigner
|
|
151
151
|
? this.targetScriptRedeem
|
|
152
152
|
: this.leftOverFundsScriptRedeem;
|
|
153
153
|
|
|
@@ -223,7 +223,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
223
223
|
* @protected
|
|
224
224
|
*/
|
|
225
225
|
protected override generateTapData(): Payment {
|
|
226
|
-
const selectedRedeem =
|
|
226
|
+
const selectedRedeem = this.contractSigner
|
|
227
227
|
? this.targetScriptRedeem
|
|
228
228
|
: this.leftOverFundsScriptRedeem;
|
|
229
229
|
|
|
@@ -35,7 +35,7 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (this.splitInputsInto > 1) {
|
|
38
|
-
|
|
38
|
+
this.splitInputs(amountSpent);
|
|
39
39
|
} else {
|
|
40
40
|
this.addOutput({
|
|
41
41
|
value: Number(amountSpent),
|
|
@@ -46,7 +46,7 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
46
46
|
await this.addRefundOutput(amountSpent);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
protected
|
|
49
|
+
protected splitInputs(amountSpent: bigint): void {
|
|
50
50
|
if (!this.to) {
|
|
51
51
|
throw new Error('Recipient address is required');
|
|
52
52
|
}
|
|
@@ -139,7 +139,7 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
139
139
|
public static verifyIfSigned(psbt: Psbt, signerPubKey: Buffer): boolean {
|
|
140
140
|
let alreadySigned: boolean = false;
|
|
141
141
|
for (let i = 1; i < psbt.data.inputs.length; i++) {
|
|
142
|
-
|
|
142
|
+
const input: PsbtInput = psbt.data.inputs[i];
|
|
143
143
|
if (!input.finalScriptWitness) {
|
|
144
144
|
continue;
|
|
145
145
|
}
|
|
@@ -183,12 +183,12 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
183
183
|
let final: boolean = true;
|
|
184
184
|
|
|
185
185
|
for (let i = originalInputCount; i < psbt.data.inputs.length; i++) {
|
|
186
|
-
|
|
186
|
+
const input: PsbtInput = psbt.data.inputs[i];
|
|
187
187
|
if (!input.tapInternalKey) {
|
|
188
188
|
input.tapInternalKey = toXOnly(MultiSignTransaction.numsPoint);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
const partialSignatures: TapScriptSig[] = [];
|
|
192
192
|
if (input.finalScriptWitness) {
|
|
193
193
|
const decoded = TransactionBuilder.readScriptWitnessToWitnessStack(
|
|
194
194
|
input.finalScriptWitness,
|
|
@@ -278,9 +278,9 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
278
278
|
.flat();
|
|
279
279
|
} else {
|
|
280
280
|
/** We must order the signatures and the pub keys. */
|
|
281
|
-
for (
|
|
281
|
+
for (const pubKey of orderedPubKeys) {
|
|
282
282
|
let found = false;
|
|
283
|
-
for (
|
|
283
|
+
for (const sig of input.tapScriptSig) {
|
|
284
284
|
if (sig.pubkey.equals(toXOnly(pubKey))) {
|
|
285
285
|
scriptSolution.push(sig.signature);
|
|
286
286
|
found = true;
|
|
@@ -349,13 +349,13 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
349
349
|
let finalizedInputs = 0;
|
|
350
350
|
for (let i = startIndex; i < psbt.data.inputs.length; i++) {
|
|
351
351
|
try {
|
|
352
|
-
|
|
352
|
+
const input = psbt.data.inputs[i];
|
|
353
353
|
|
|
354
354
|
if (!input.tapInternalKey) {
|
|
355
355
|
input.tapInternalKey = toXOnly(MultiSignTransaction.numsPoint);
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
|
|
358
|
+
const partialSignatures: TapScriptSig[] = [];
|
|
359
359
|
if (input.finalScriptWitness) {
|
|
360
360
|
const decoded = TransactionBuilder.readScriptWitnessToWitnessStack(
|
|
361
361
|
input.finalScriptWitness,
|
|
@@ -451,6 +451,7 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
451
451
|
* @throws {Error} If the left over funds script redeem version is required
|
|
452
452
|
* @throws {Error} If the left over funds script redeem output is required
|
|
453
453
|
*/
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
454
455
|
protected override async buildTransaction(): Promise<void> {
|
|
455
456
|
const selectedRedeem = this.targetScriptRedeem;
|
|
456
457
|
if (!selectedRedeem) {
|
|
@@ -136,7 +136,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
136
136
|
protected override async buildTransaction(): Promise<void> {
|
|
137
137
|
if (!this.to) throw new Error('To address is required');
|
|
138
138
|
|
|
139
|
-
const selectedRedeem =
|
|
139
|
+
const selectedRedeem = this.scriptSigner
|
|
140
140
|
? this.targetScriptRedeem
|
|
141
141
|
: this.leftOverFundsScriptRedeem;
|
|
142
142
|
|
|
@@ -186,7 +186,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
for (let i = 0; i < transaction.data.inputs.length; i++) {
|
|
189
|
-
|
|
189
|
+
const input: PsbtInput = transaction.data.inputs[i];
|
|
190
190
|
let finalized: boolean = false;
|
|
191
191
|
let signed: boolean = false;
|
|
192
192
|
|
|
@@ -235,7 +235,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
protected override generateTapData(): Payment {
|
|
238
|
-
const selectedRedeem =
|
|
238
|
+
const selectedRedeem = this.scriptSigner
|
|
239
239
|
? this.targetScriptRedeem
|
|
240
240
|
: this.leftOverFundsScriptRedeem;
|
|
241
241
|
|
|
@@ -446,7 +446,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
446
446
|
);
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
for (
|
|
449
|
+
for (const output of this.outputs) {
|
|
450
450
|
if ('address' in output && output.address === this.to) {
|
|
451
451
|
output.value += Number(value);
|
|
452
452
|
return;
|
|
@@ -476,7 +476,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
476
476
|
*/
|
|
477
477
|
protected calculateTotalUTXOAmount(): bigint {
|
|
478
478
|
let total: bigint = 0n;
|
|
479
|
-
for (
|
|
479
|
+
for (const utxo of this.utxos) {
|
|
480
480
|
total += utxo.value;
|
|
481
481
|
}
|
|
482
482
|
|
|
@@ -490,7 +490,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
490
490
|
*/
|
|
491
491
|
protected calculateTotalVOutAmount(): bigint {
|
|
492
492
|
let total: bigint = 0n;
|
|
493
|
-
for (
|
|
493
|
+
for (const utxo of this.utxos) {
|
|
494
494
|
total += utxo.value;
|
|
495
495
|
}
|
|
496
496
|
|
|
@@ -583,7 +583,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
583
583
|
* @protected
|
|
584
584
|
*/
|
|
585
585
|
protected verifyUTXOValidity(): void {
|
|
586
|
-
for (
|
|
586
|
+
for (const utxo of this.utxos) {
|
|
587
587
|
if (!utxo.scriptPubKey) {
|
|
588
588
|
throw new Error('Address is required');
|
|
589
589
|
}
|
|
@@ -599,7 +599,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
599
599
|
protected async setFeeOutput(output: PsbtOutputExtended): Promise<void> {
|
|
600
600
|
const initialValue = output.value;
|
|
601
601
|
|
|
602
|
-
|
|
602
|
+
const fee = await this.estimateTransactionFees();
|
|
603
603
|
output.value = initialValue - Number(fee);
|
|
604
604
|
|
|
605
605
|
if (output.value < TransactionBuilder.MINIMUM_DUST) {
|
|
@@ -613,7 +613,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
613
613
|
} else {
|
|
614
614
|
this.feeOutput = output;
|
|
615
615
|
|
|
616
|
-
|
|
616
|
+
const fee = await this.estimateTransactionFees();
|
|
617
617
|
if (fee > BigInt(initialValue)) {
|
|
618
618
|
throw new Error(
|
|
619
619
|
`estimateTransactionFees: Insufficient funds to pay the fees. Fee: ${fee} > Value: ${initialValue}. Total input: ${this.totalInputAmount} sat`,
|
|
@@ -188,7 +188,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
188
188
|
public getRefund(): bigint {
|
|
189
189
|
let losses: bigint = -currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
|
|
190
190
|
|
|
191
|
-
for (
|
|
191
|
+
for (const vault of this.vaultUTXOs) {
|
|
192
192
|
for (let i = 0; i < vault.utxos.length; i++) {
|
|
193
193
|
losses += currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
|
|
194
194
|
}
|
|
@@ -206,7 +206,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
206
206
|
* @returns {bigint} - The estimated fee loss or refund
|
|
207
207
|
*/
|
|
208
208
|
public getFeeLossOrRefund(): bigint {
|
|
209
|
-
|
|
209
|
+
const refund: bigint = this.getRefund();
|
|
210
210
|
|
|
211
211
|
return refund - this.estimatedFeeLoss;
|
|
212
212
|
}
|
|
@@ -219,7 +219,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
219
219
|
const totalInputAmount: bigint = this.getVaultTotalOutputAmount(this.vaultUTXOs);
|
|
220
220
|
|
|
221
221
|
let refund: bigint = this.getRefund();
|
|
222
|
-
|
|
222
|
+
const outputLeftAmount = totalInputAmount - refund - this.amount;
|
|
223
223
|
|
|
224
224
|
if (outputLeftAmount === currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT) {
|
|
225
225
|
refund += currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
|
|
@@ -235,7 +235,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
235
235
|
throw new Error('No vaults provided');
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
const hasConsolidation: boolean =
|
|
239
239
|
outputLeftAmount > currentConsensusConfig.VAULT_MINIMUM_AMOUNT &&
|
|
240
240
|
outputLeftAmount - currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT !== 0n;
|
|
241
241
|
|
|
@@ -223,7 +223,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
223
223
|
protected override async buildTransaction(): Promise<void> {
|
|
224
224
|
if (!this.to) throw new Error('To address is required');
|
|
225
225
|
|
|
226
|
-
const selectedRedeem =
|
|
226
|
+
const selectedRedeem = this.scriptSigner
|
|
227
227
|
? this.targetScriptRedeem
|
|
228
228
|
: this.leftOverFundsScriptRedeem;
|
|
229
229
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
1
2
|
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
2
|
-
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
3
3
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
5
5
|
|
|
6
6
|
export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
7
7
|
readonly psbt: Psbt;
|
|
@@ -141,7 +141,7 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
141
141
|
try {
|
|
142
142
|
const inputs = this.transaction.data.inputs;
|
|
143
143
|
for (let i = n; i < inputs.length; i++) {
|
|
144
|
-
|
|
144
|
+
const input = inputs[i];
|
|
145
145
|
if (input.finalScriptWitness) {
|
|
146
146
|
this.transaction.finalizeTaprootInput(i, input.finalScriptWitness);
|
|
147
147
|
} else {
|
|
@@ -151,7 +151,7 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
151
151
|
|
|
152
152
|
return true;
|
|
153
153
|
} catch (e) {
|
|
154
|
-
this.warn((e as Error).stack);
|
|
154
|
+
this.warn((e as Error).stack || "Couldn't finalize inputs");
|
|
155
155
|
return false;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -210,7 +210,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
let signHash: number = 0;
|
|
213
|
-
for (
|
|
213
|
+
for (const sighashType of sighashTypes) {
|
|
214
214
|
signHash |= sighashType;
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -262,7 +262,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
262
262
|
|
|
263
263
|
this.sequence = TransactionSequence.FINAL;
|
|
264
264
|
|
|
265
|
-
for (
|
|
265
|
+
for (const input of this.inputs) {
|
|
266
266
|
input.sequence = TransactionSequence.FINAL;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -379,21 +379,25 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
379
379
|
|
|
380
380
|
try {
|
|
381
381
|
if ('signTaprootInput' in signer) {
|
|
382
|
-
// @ts-
|
|
383
|
-
return await signer.signTaprootInput(
|
|
382
|
+
// @ts-expect-error - we know it's a taproot signer
|
|
383
|
+
return await (signer.signTaprootInput(
|
|
384
|
+
transaction,
|
|
385
|
+
i,
|
|
386
|
+
signHash,
|
|
387
|
+
) as Promise<void>);
|
|
384
388
|
} else {
|
|
385
389
|
transaction.signTaprootInput(i, tweakedSigner, undefined, signHash);
|
|
386
390
|
}
|
|
387
391
|
|
|
388
392
|
return;
|
|
389
|
-
} catch
|
|
393
|
+
} catch {}
|
|
390
394
|
}
|
|
391
395
|
}
|
|
392
396
|
|
|
393
397
|
try {
|
|
394
398
|
if ('signInput' in signer) {
|
|
395
|
-
// @ts-
|
|
396
|
-
return await signer.signInput(transaction, i, signHash);
|
|
399
|
+
// @ts-expect-error - we know it's a signer
|
|
400
|
+
return await (signer.signInput(transaction, i, signHash) as Promise<void>);
|
|
397
401
|
} else {
|
|
398
402
|
transaction.signInput(i, signer, signHash);
|
|
399
403
|
}
|
|
@@ -402,8 +406,12 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
402
406
|
// and we try again taproot...
|
|
403
407
|
|
|
404
408
|
if ('signTaprootInput' in signer) {
|
|
405
|
-
// @ts-
|
|
406
|
-
return await signer.signTaprootInput(
|
|
409
|
+
// @ts-expect-error - we know it's a taproot signer
|
|
410
|
+
return await (signer.signTaprootInput(
|
|
411
|
+
transaction,
|
|
412
|
+
i,
|
|
413
|
+
signHash,
|
|
414
|
+
) as Promise<void>);
|
|
407
415
|
} else if (this.tweakedSigner) {
|
|
408
416
|
transaction.signTaprootInput(i, this.tweakedSigner, undefined, signHash);
|
|
409
417
|
} else {
|
|
@@ -421,7 +429,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
421
429
|
*/
|
|
422
430
|
protected async signInputs(transaction: Psbt): Promise<void> {
|
|
423
431
|
for (let i = 0; i < transaction.data.inputs.length; i++) {
|
|
424
|
-
|
|
432
|
+
const input: PsbtInput = transaction.data.inputs[i];
|
|
425
433
|
|
|
426
434
|
try {
|
|
427
435
|
await this.signInput(transaction, input, i);
|
|
@@ -489,7 +497,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
489
497
|
return;
|
|
490
498
|
}
|
|
491
499
|
|
|
492
|
-
return TweakedSigner.tweakSigner(signer as unknown as ECPairInterface, settings)
|
|
500
|
+
return TweakedSigner.tweakSigner(signer as unknown as ECPairInterface, settings);
|
|
493
501
|
}
|
|
494
502
|
|
|
495
503
|
/**
|
|
@@ -8,9 +8,9 @@ export class BitcoinUtils {
|
|
|
8
8
|
/**
|
|
9
9
|
* Converts satoshi to BTC
|
|
10
10
|
* @param {number} btc - The amount in BTC
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {bigint} The amount in satoshi
|
|
12
12
|
*/
|
|
13
|
-
public static btcToSatoshi(btc: number):
|
|
13
|
+
public static btcToSatoshi(btc: number): bigint {
|
|
14
14
|
return BigInt(btc * 100000000);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -82,7 +82,7 @@ export class BitcoinUtils {
|
|
|
82
82
|
|
|
83
83
|
let mostPublicKeys: number = 0;
|
|
84
84
|
let vault: VaultUTXOs | undefined;
|
|
85
|
-
for (
|
|
85
|
+
for (const v of vaults) {
|
|
86
86
|
if (v.publicKeys.length > mostPublicKeys) {
|
|
87
87
|
mostPublicKeys = v.publicKeys.length;
|
|
88
88
|
vault = v;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { FetchUTXOParams, FetchUTXOParamsMultiAddress, RawUTXOResponse, UTXO } from './interfaces/IUTXO.js';
|
|
2
|
-
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
3
|
-
import { UnwrappedGenerationParameters, WrappedGenerationParameters } from '../wbtc/Generate.js';
|
|
4
|
-
import { BroadcastResponse } from './interfaces/BroadcastResponse.js';
|
|
5
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
-
import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
|
|
7
2
|
import { currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
3
|
+
import { UnwrappedGenerationParameters, WrappedGenerationParameters } from '../wbtc/Generate.js';
|
|
4
|
+
import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
|
|
5
|
+
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
6
|
+
import { BroadcastResponse } from './interfaces/BroadcastResponse.js';
|
|
7
|
+
import {
|
|
8
|
+
FetchUTXOParams,
|
|
9
|
+
FetchUTXOParamsMultiAddress,
|
|
10
|
+
RawUTXOResponse,
|
|
11
|
+
UTXO,
|
|
12
|
+
} from './interfaces/IUTXO.js';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Allows to fetch UTXO data from any OPNET node
|
|
@@ -36,7 +41,7 @@ export class OPNetLimitedProvider {
|
|
|
36
41
|
throw new Error(`Failed to fetch UTXO data: ${resp.statusText}`);
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
const fetchedData: RawUTXOResponse[] = await resp.json();
|
|
44
|
+
const fetchedData: RawUTXOResponse[] = (await resp.json()) as RawUTXOResponse[];
|
|
40
45
|
if (fetchedData.length === 0) {
|
|
41
46
|
throw new Error('No UTXO found');
|
|
42
47
|
}
|
|
@@ -49,7 +54,7 @@ export class OPNetLimitedProvider {
|
|
|
49
54
|
throw new Error('No UTXO found (minAmount)');
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
const finalUTXOs: UTXO[] = [];
|
|
53
58
|
let currentAmount: bigint = 0n;
|
|
54
59
|
|
|
55
60
|
const amountRequested: bigint = settings.requestedAmount;
|
|
@@ -86,7 +91,7 @@ export class OPNetLimitedProvider {
|
|
|
86
91
|
public async fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]> {
|
|
87
92
|
const promises: Promise<UTXO[]>[] = [];
|
|
88
93
|
|
|
89
|
-
for (
|
|
94
|
+
for (const address of settings.addresses) {
|
|
90
95
|
const params: FetchUTXOParams = {
|
|
91
96
|
address: address,
|
|
92
97
|
minAmount: settings.minAmount,
|
|
@@ -107,7 +112,7 @@ export class OPNetLimitedProvider {
|
|
|
107
112
|
const finalUTXOs: UTXO[] = [];
|
|
108
113
|
let currentAmount = 0n;
|
|
109
114
|
for (let i = 0; i < all.length; i++) {
|
|
110
|
-
|
|
115
|
+
const utxo = all[i];
|
|
111
116
|
|
|
112
117
|
if (currentAmount >= settings.requestedAmount) {
|
|
113
118
|
break;
|
|
@@ -168,7 +173,11 @@ export class OPNetLimitedProvider {
|
|
|
168
173
|
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
169
174
|
}
|
|
170
175
|
|
|
171
|
-
const fetchedData = await resp.json()
|
|
176
|
+
const fetchedData = (await resp.json()) as {
|
|
177
|
+
result: {
|
|
178
|
+
error?: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
172
181
|
if (!fetchedData) {
|
|
173
182
|
throw new Error('No data fetched');
|
|
174
183
|
}
|
package/webpack.config.js
CHANGED
package/LICENSE.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Custom Software License Agreement
|
|
2
|
-
|
|
3
|
-
## 1. Definitions
|
|
4
|
-
|
|
5
|
-
- **"Licensor"** refers to the owner(s) and creator(s) of the software. The owner of the github organization "
|
|
6
|
-
btc-vision", "BlobMaster41".
|
|
7
|
-
- **"User"** refers to any person or entity that accesses or uses the software.
|
|
8
|
-
- **"Software"** refers to the source code, binaries, and documentation, whether in electronic or printed format, made
|
|
9
|
-
available by Licensor.
|
|
10
|
-
|
|
11
|
-
## 2. Grant of License
|
|
12
|
-
|
|
13
|
-
This License permits User to view the Software via the repository hosting the Software ("Hosting Service"). Except as
|
|
14
|
-
provided in this Section, no other use of the Software is permitted. The User may not modify, copy, reproduce,
|
|
15
|
-
republish, upload, post, transmit, or distribute the Software in any way.
|
|
16
|
-
|
|
17
|
-
## 3. Restrictions
|
|
18
|
-
|
|
19
|
-
- **Modification and Distribution**: User is prohibited from modifying, merging, distributing, sublicensing, and/or
|
|
20
|
-
selling copies of the Software.
|
|
21
|
-
- **Commercial Use**: User is prohibited from using the Software for any commercial purposes.
|
|
22
|
-
- **Reverse Engineering**: User is prohibited from reverse engineering, decompiling, or disassembling the Software.
|
|
23
|
-
|
|
24
|
-
## 4. Termination
|
|
25
|
-
|
|
26
|
-
This License is effective until terminated by the Licensor. It will terminate immediately without notice from the
|
|
27
|
-
Licensor if User fails to comply with any provision of this License. Upon termination, User must destroy all copies of
|
|
28
|
-
the Software.
|
|
29
|
-
|
|
30
|
-
## 5. Release to Public
|
|
31
|
-
|
|
32
|
-
This License restricts the above rights until the Software is officially released to the public by the Licensor. Upon
|
|
33
|
-
such release, the terms of this License may be modified by the Licensor to allow broader use rights.
|
|
34
|
-
|
|
35
|
-
## 6. Governing Law
|
|
36
|
-
|
|
37
|
-
This License shall be governed by and construed in accordance with the laws of [Toronto, Canada]. Any legal action or
|
|
38
|
-
proceeding arising under this License will be brought exclusively in the courts located in [Toronto], and the parties
|
|
39
|
-
hereby consent to personal jurisdiction and venue therein.
|
|
40
|
-
|
|
41
|
-
## 7. Limitation of Liability
|
|
42
|
-
|
|
43
|
-
In no event will the Licensor be liable for any damages, including, without limitation, indirect, incidental, special,
|
|
44
|
-
consequential, or punitive damages arising out of the use of or inability to use the Software.
|
|
45
|
-
|
|
46
|
-
## 8. Indemnification
|
|
47
|
-
|
|
48
|
-
User agrees to indemnify, defend, and hold harmless the Licensor and its affiliates, officers, agents, employees, and
|
|
49
|
-
partners from any claim or demand, including reasonable attorneys' fees, made by any third party due to or arising out
|
|
50
|
-
of User's use of the Software, User's violation of this License, or User's violation of any rights of another.
|
|
51
|
-
|
|
52
|
-
## 9. Breach of License
|
|
53
|
-
|
|
54
|
-
Any breach of this License will result in immediate termination of User's rights under this License. Additionally, the
|
|
55
|
-
Licensor reserves the right to pursue any legal action against the User in the event of a breach of this License.
|
|
56
|
-
|
|
57
|
-
## 10. Acknowledgment
|
|
58
|
-
|
|
59
|
-
User acknowledges that they have read this License, understand it, and agree to be bound by its terms and conditions.
|
|
60
|
-
User also agrees that this License is the complete and exclusive statement of the agreement between the Licensor and the
|
|
61
|
-
User and supersedes all proposals or prior agreements, oral or written, and any other communications between the
|
|
62
|
-
Licensor and the User relating to the subject matter of this License.
|