@btc-vision/transaction 1.0.123 → 1.1.1
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/consensus/ConsensusConfig.d.ts +0 -4
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +0 -6
- package/browser/transaction/TransactionFactory.d.ts +1 -13
- package/browser/transaction/browser/Web3Provider.d.ts +2 -6
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +0 -14
- package/browser/transaction/processor/PsbtTransaction.d.ts +0 -15
- package/browser/transaction/shared/TweakedTransaction.d.ts +1 -1
- package/browser/utils/BitcoinUtils.d.ts +0 -3
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -5
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/consensus/ConsensusConfig.d.ts +0 -4
- package/build/consensus/metadata/RoswellConsensus.js +0 -4
- package/build/opnet.d.ts +0 -6
- package/build/opnet.js +0 -6
- package/build/transaction/TransactionFactory.d.ts +1 -13
- package/build/transaction/TransactionFactory.js +1 -161
- package/build/transaction/browser/Web3Provider.d.ts +2 -6
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +65 -3
- package/build/transaction/interfaces/ITransactionParameters.d.ts +0 -14
- package/build/transaction/processor/PsbtTransaction.d.ts +0 -15
- package/build/transaction/processor/PsbtTransaction.js +0 -9
- package/build/transaction/shared/TweakedTransaction.d.ts +1 -1
- package/build/transaction/shared/TweakedTransaction.js +11 -44
- package/build/utils/BitcoinUtils.d.ts +0 -3
- package/build/utils/BitcoinUtils.js +0 -19
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -5
- package/build/utxo/OPNetLimitedProvider.js +0 -28
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/consensus/ConsensusConfig.ts +4 -4
- package/src/consensus/metadata/RoswellConsensus.ts +4 -4
- package/src/opnet.ts +6 -6
- package/src/transaction/TransactionFactory.ts +13 -25
- package/src/transaction/browser/Web3Provider.ts +1 -9
- package/src/transaction/browser/extensions/UnisatSigner.ts +83 -3
- package/src/transaction/builders/SharedInteractionTransaction.ts +0 -1
- package/src/transaction/builders/{WrapTransaction.ts → WrapTransaction.ts.disabled} +1 -1
- package/src/transaction/interfaces/ITransactionParameters.ts +2 -5
- package/src/transaction/processor/PsbtTransaction.ts +4 -4
- package/src/transaction/shared/TweakedTransaction.ts +27 -7
- package/src/utils/BitcoinUtils.ts +4 -5
- package/src/utxo/OPNetLimitedProvider.ts +5 -9
- package/{src/wbtc/Generate.ts → wbtc_disabled/Generate.ts.disabled} +1 -1
- package/{src/wbtc/UnwrapGeneration.ts → wbtc_disabled/UnwrapGeneration.ts.disabled} +1 -1
- package/browser/metadata/contracts/wBTC.d.ts +0 -13
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -32
- package/browser/transaction/builders/UnwrapTransaction.d.ts +0 -41
- package/browser/transaction/builders/WrapTransaction.d.ts +0 -29
- package/browser/wbtc/Generate.d.ts +0 -18
- package/browser/wbtc/UnwrapGeneration.d.ts +0 -7
- package/browser/wbtc/WrappedGenerationParameters.d.ts +0 -10
- package/build/metadata/contracts/wBTC.d.ts +0 -13
- package/build/metadata/contracts/wBTC.js +0 -34
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -32
- package/build/transaction/builders/UnwrapSegwitTransaction.js +0 -179
- package/build/transaction/builders/UnwrapTransaction.d.ts +0 -41
- package/build/transaction/builders/UnwrapTransaction.js +0 -258
- package/build/transaction/builders/WrapTransaction.d.ts +0 -29
- package/build/transaction/builders/WrapTransaction.js +0 -146
- package/build/wbtc/Generate.d.ts +0 -18
- package/build/wbtc/Generate.js +0 -1
- package/build/wbtc/UnwrapGeneration.d.ts +0 -7
- package/build/wbtc/UnwrapGeneration.js +0 -6
- package/build/wbtc/WrappedGenerationParameters.d.ts +0 -10
- package/build/wbtc/WrappedGenerationParameters.js +0 -10
- package/src/metadata/contracts/wBTC.ts +0 -59
- /package/src/transaction/builders/{UnwrapSegwitTransaction.ts → UnwrapSegwitTransaction.ts.disabled} +0 -0
- /package/src/transaction/builders/{UnwrapTransaction.ts → UnwrapTransaction.ts.disabled} +0 -0
- /package/{src/wbtc/WrappedGenerationParameters.ts → wbtc_disabled/WrappedGenerationParameters.ts.disabled} +0 -0
|
@@ -358,18 +358,38 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
358
358
|
/**
|
|
359
359
|
* Signs an input of the transaction.
|
|
360
360
|
* @param {Psbt} transaction - The transaction to sign
|
|
361
|
-
* @param {PsbtInput}
|
|
361
|
+
* @param {PsbtInput} _input - The input to sign
|
|
362
362
|
* @param {number} i - The index of the input
|
|
363
|
-
* @param {Signer}
|
|
363
|
+
* @param {Signer} signer - The signer to use
|
|
364
364
|
* @protected
|
|
365
365
|
*/
|
|
366
366
|
protected async signInput(
|
|
367
367
|
transaction: Psbt,
|
|
368
|
-
|
|
368
|
+
_input: PsbtInput,
|
|
369
369
|
i: number,
|
|
370
|
-
signer
|
|
370
|
+
signer: Signer | ECPairInterface,
|
|
371
371
|
): Promise<void> {
|
|
372
|
-
|
|
372
|
+
try {
|
|
373
|
+
if ('signInput' in signer) {
|
|
374
|
+
// @ts-expect-error - we know it's a signer
|
|
375
|
+
return await (signer.signInput(transaction, i) as Promise<void>);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
transaction.signInput(i, signer);
|
|
379
|
+
} catch {
|
|
380
|
+
try {
|
|
381
|
+
if ('signTaprootInput' in signer) {
|
|
382
|
+
// @ts-expect-error - we know it's a taproot signer
|
|
383
|
+
return await (signer.signTaprootInput(transaction, i) as Promise<void>);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
transaction.signTaprootInput(i, signer);
|
|
387
|
+
} catch {
|
|
388
|
+
throw new Error('Failed to sign input');
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/*const signHash =
|
|
373
393
|
this.sighashTypes && this.sighashTypes.length
|
|
374
394
|
? [TweakedTransaction.calculateSignHash(this.sighashTypes)]
|
|
375
395
|
: undefined;
|
|
@@ -431,7 +451,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
431
451
|
throw e;
|
|
432
452
|
}
|
|
433
453
|
}
|
|
434
|
-
}
|
|
454
|
+
}*/
|
|
435
455
|
}
|
|
436
456
|
|
|
437
457
|
protected splitArray<T>(arr: T[], chunkSize: number): T[][] {
|
|
@@ -470,7 +490,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
470
490
|
const input = batch[j];
|
|
471
491
|
|
|
472
492
|
try {
|
|
473
|
-
promises.push(this.signInput(transaction, input, index));
|
|
493
|
+
promises.push(this.signInput(transaction, input, index, this.signer));
|
|
474
494
|
} catch (e) {
|
|
475
495
|
this.log(`Failed to sign input ${index}: ${(e as Error).stack}`);
|
|
476
496
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import crypto, { createHash } from 'crypto';
|
|
2
|
-
import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Utility class for Bitcoin related functions
|
|
@@ -62,18 +61,18 @@ export class BitcoinUtils {
|
|
|
62
61
|
* @param {VaultUTXOs[]} vaults - The vaults to order
|
|
63
62
|
* @returns {VaultUTXOs[]} The ordered vaults
|
|
64
63
|
*/
|
|
65
|
-
public static orderVaultsByAddress(vaults: VaultUTXOs[]): VaultUTXOs[] {
|
|
64
|
+
/*public static orderVaultsByAddress(vaults: VaultUTXOs[]): VaultUTXOs[] {
|
|
66
65
|
return vaults.sort((a, b) => {
|
|
67
66
|
return a.vault.localeCompare(b.vault);
|
|
68
67
|
});
|
|
69
|
-
}
|
|
68
|
+
}*/
|
|
70
69
|
|
|
71
70
|
/**
|
|
72
71
|
* Find the vault with the most public keys in a deterministic way.
|
|
73
72
|
* @param {VaultUTXOs[]} vaults - The vaults to search
|
|
74
73
|
* @returns {VaultUTXOs} The vault with the most public keys
|
|
75
74
|
*/
|
|
76
|
-
public static findVaultWithMostPublicKeys(vaults: VaultUTXOs[]): VaultUTXOs {
|
|
75
|
+
/*public static findVaultWithMostPublicKeys(vaults: VaultUTXOs[]): VaultUTXOs {
|
|
77
76
|
vaults = BitcoinUtils.orderVaultsByAddress(vaults);
|
|
78
77
|
|
|
79
78
|
let mostPublicKeys: number = 0;
|
|
@@ -88,5 +87,5 @@ export class BitcoinUtils {
|
|
|
88
87
|
if (!vault) throw new Error('No vault with public keys found.');
|
|
89
88
|
|
|
90
89
|
return vault;
|
|
91
|
-
}
|
|
90
|
+
}*/
|
|
92
91
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import {
|
|
3
|
-
import { Address, IFundingTransactionParameters, TransactionFactory, Wallet } from '../opnet.js';
|
|
4
|
-
import { UnwrappedGenerationParameters, WrappedGenerationParameters } from '../wbtc/Generate.js';
|
|
5
|
-
import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
|
|
6
|
-
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
2
|
+
import { IFundingTransactionParameters, TransactionFactory, Wallet } from '../opnet.js';
|
|
7
3
|
import { BroadcastResponse } from './interfaces/BroadcastResponse.js';
|
|
8
4
|
import {
|
|
9
5
|
FetchUTXOParams,
|
|
@@ -280,7 +276,7 @@ export class OPNetLimitedProvider {
|
|
|
280
276
|
* @returns {Promise<WrappedGeneration | undefined>} - The wrap parameters fetched
|
|
281
277
|
* @throws {Error} - If wrap parameters could not be fetched
|
|
282
278
|
*/
|
|
283
|
-
public async fetchWrapParameters(amount: bigint): Promise<WrappedGeneration | undefined> {
|
|
279
|
+
/*public async fetchWrapParameters(amount: bigint): Promise<WrappedGeneration | undefined> {
|
|
284
280
|
if (amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
285
281
|
throw new Error(
|
|
286
282
|
`Amount must be greater than the minimum consolidation amount ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}sat.`,
|
|
@@ -295,7 +291,7 @@ export class OPNetLimitedProvider {
|
|
|
295
291
|
}
|
|
296
292
|
|
|
297
293
|
return new WrappedGeneration(result as WrappedGenerationParameters);
|
|
298
|
-
}
|
|
294
|
+
}*/
|
|
299
295
|
|
|
300
296
|
/**
|
|
301
297
|
* Fetches the wrap parameters from the OPNET node
|
|
@@ -304,7 +300,7 @@ export class OPNetLimitedProvider {
|
|
|
304
300
|
* @returns {Promise<UnwrapGeneration | undefined>} - The wrap parameters fetched
|
|
305
301
|
* @throws {Error} - If wrap parameters could not be fetched
|
|
306
302
|
*/
|
|
307
|
-
public async fetchUnWrapParameters(
|
|
303
|
+
/*public async fetchUnWrapParameters(
|
|
308
304
|
amount: bigint,
|
|
309
305
|
receiver: Address,
|
|
310
306
|
): Promise<UnwrapGeneration | undefined> {
|
|
@@ -326,5 +322,5 @@ export class OPNetLimitedProvider {
|
|
|
326
322
|
}
|
|
327
323
|
|
|
328
324
|
return new UnwrapGeneration(result as UnwrappedGenerationParameters);
|
|
329
|
-
}
|
|
325
|
+
}*/
|
|
330
326
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnwrappedGenerationParameters } from './Generate.js';
|
|
2
|
-
import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
2
|
+
import { VaultUTXOs } from '../src/transaction/processor/PsbtTransaction.js';
|
|
3
3
|
|
|
4
4
|
export class UnwrapGeneration implements Omit<UnwrappedGenerationParameters, 'balance'> {
|
|
5
5
|
public readonly vaultUTXOs: VaultUTXOs[];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import { ChainId } from '../../network/ChainId.js';
|
|
3
|
-
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
4
|
-
export declare class wBTC extends ContractBaseMetadata {
|
|
5
|
-
protected network: Network;
|
|
6
|
-
readonly tokenName: string;
|
|
7
|
-
readonly tokenSymbol: string;
|
|
8
|
-
readonly decimals: number;
|
|
9
|
-
protected readonly address: string;
|
|
10
|
-
constructor(network?: Network, chainId?: ChainId);
|
|
11
|
-
static getAddress(network?: Network, chainId?: ChainId): string;
|
|
12
|
-
private static getWBTCAddressForChain;
|
|
13
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
-
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Psbt } from '@btc-vision/bitcoin';
|
|
6
|
-
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
export declare class UnwrapSegwitTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
8
|
-
private static readonly UNWRAP_SELECTOR;
|
|
9
|
-
type: TransactionType.WBTC_UNWRAP;
|
|
10
|
-
readonly amount: bigint;
|
|
11
|
-
protected readonly compiledTargetScript: Buffer;
|
|
12
|
-
protected readonly scriptTree: Taptree;
|
|
13
|
-
protected sighashTypes: number[];
|
|
14
|
-
protected readonly contractSecret: Buffer;
|
|
15
|
-
protected readonly vaultUTXOs: VaultUTXOs[];
|
|
16
|
-
private readonly wbtc;
|
|
17
|
-
private readonly calculatedSignHash;
|
|
18
|
-
constructor(parameters: IUnwrapParameters);
|
|
19
|
-
static generateBurnCalldata(amount: bigint): Buffer;
|
|
20
|
-
signPSBT(): Promise<Psbt>;
|
|
21
|
-
mergeVaults(input: VaultUTXOs[]): Promise<void>;
|
|
22
|
-
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
23
|
-
protected generateMultiSignRedeemScript(publicKeys: string[], minimum: number): {
|
|
24
|
-
witnessUtxo: Buffer;
|
|
25
|
-
redeemScript: Buffer;
|
|
26
|
-
witnessScript: Buffer;
|
|
27
|
-
};
|
|
28
|
-
private addVaultUTXO;
|
|
29
|
-
private addVaultInputs;
|
|
30
|
-
private calculateOutputLeftAmountFromVaults;
|
|
31
|
-
private getVaultTotalOutputAmount;
|
|
32
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
-
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Network, Payment, Psbt, PsbtInput } from '@btc-vision/bitcoin';
|
|
6
|
-
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
export declare class UnwrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
8
|
-
private static readonly UNWRAP_SELECTOR;
|
|
9
|
-
type: TransactionType.WBTC_UNWRAP;
|
|
10
|
-
readonly amount: bigint;
|
|
11
|
-
protected readonly compiledTargetScript: Buffer;
|
|
12
|
-
protected readonly scriptTree: Taptree;
|
|
13
|
-
protected sighashTypes: number[];
|
|
14
|
-
protected readonly contractSecret: Buffer;
|
|
15
|
-
protected readonly vaultUTXOs: VaultUTXOs[];
|
|
16
|
-
protected readonly estimatedFeeLoss: bigint;
|
|
17
|
-
private readonly wbtc;
|
|
18
|
-
private readonly calculatedSignHash;
|
|
19
|
-
constructor(parameters: IUnwrapParameters);
|
|
20
|
-
static generateBurnCalldata(amount: bigint): Buffer;
|
|
21
|
-
signPSBT(): Promise<Psbt>;
|
|
22
|
-
getRefund(): bigint;
|
|
23
|
-
getFeeLossOrRefund(): bigint;
|
|
24
|
-
protected mergeVaults(): void;
|
|
25
|
-
protected calculateNumEmptyWitnesses(vault: VaultUTXOs[]): bigint;
|
|
26
|
-
protected calculateNumSignatures(vault: VaultUTXOs[]): bigint;
|
|
27
|
-
protected calculateNumInputs(vault: VaultUTXOs[]): bigint;
|
|
28
|
-
protected internalPubKeyToXOnly(): Buffer;
|
|
29
|
-
protected generateTapDataForInput(pubkeys: Buffer[], minimumSignatures: number): {
|
|
30
|
-
internalPubkey: Buffer;
|
|
31
|
-
network: Network;
|
|
32
|
-
scriptTree: Taptree;
|
|
33
|
-
redeem: Payment;
|
|
34
|
-
};
|
|
35
|
-
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
36
|
-
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
37
|
-
private addVaultUTXO;
|
|
38
|
-
private addVaultInputs;
|
|
39
|
-
private calculateOutputLeftAmountFromVaults;
|
|
40
|
-
private getVaultTotalOutputAmount;
|
|
41
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
-
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
|
-
import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
6
|
-
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
7
|
-
import { Address } from '../../keypair/Address.js';
|
|
8
|
-
export declare class WrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_WRAP> {
|
|
9
|
-
private static readonly WRAP_SELECTOR;
|
|
10
|
-
type: TransactionType.WBTC_WRAP;
|
|
11
|
-
readonly vault: string;
|
|
12
|
-
readonly amount: bigint;
|
|
13
|
-
readonly receiver: Address;
|
|
14
|
-
protected readonly compiledTargetScript: Buffer;
|
|
15
|
-
protected readonly scriptTree: Taptree;
|
|
16
|
-
protected tapLeafScript: TapLeafScript | null;
|
|
17
|
-
protected readonly contractSecret: Buffer;
|
|
18
|
-
protected readonly interactionPubKeys: Buffer[];
|
|
19
|
-
protected readonly minimumSignatures: number;
|
|
20
|
-
private readonly wbtc;
|
|
21
|
-
constructor(parameters: IWrapParameters);
|
|
22
|
-
private static generateMintCalldata;
|
|
23
|
-
verifyPublicKeysConstraints(generation: WrappedGeneration): boolean;
|
|
24
|
-
protected buildTransaction(): Promise<void>;
|
|
25
|
-
private verifyRequiredValue;
|
|
26
|
-
private addVaultOutput;
|
|
27
|
-
private generateVaultAddress;
|
|
28
|
-
private generateChecksumSalt;
|
|
29
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
2
|
-
export interface GenerationConstraints {
|
|
3
|
-
readonly timestamp: number;
|
|
4
|
-
readonly version: string;
|
|
5
|
-
readonly minimum: number;
|
|
6
|
-
readonly transactionMinimum: number;
|
|
7
|
-
}
|
|
8
|
-
export interface WrappedGenerationParameters {
|
|
9
|
-
readonly keys: string[];
|
|
10
|
-
readonly vault: string;
|
|
11
|
-
readonly entities: string[];
|
|
12
|
-
readonly signature: string;
|
|
13
|
-
readonly constraints: GenerationConstraints;
|
|
14
|
-
}
|
|
15
|
-
export interface UnwrappedGenerationParameters {
|
|
16
|
-
readonly vaultUTXOs: VaultUTXOs[];
|
|
17
|
-
readonly balance: string;
|
|
18
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { UnwrappedGenerationParameters } from './Generate.js';
|
|
2
|
-
import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
3
|
-
export declare class UnwrapGeneration implements Omit<UnwrappedGenerationParameters, 'balance'> {
|
|
4
|
-
readonly vaultUTXOs: VaultUTXOs[];
|
|
5
|
-
readonly balance: bigint;
|
|
6
|
-
constructor(params: UnwrappedGenerationParameters);
|
|
7
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { GenerationConstraints, WrappedGenerationParameters } from './Generate.js';
|
|
2
|
-
export declare class WrappedGeneration implements WrappedGenerationParameters {
|
|
3
|
-
readonly constraints: GenerationConstraints;
|
|
4
|
-
readonly entities: string[];
|
|
5
|
-
readonly keys: string[];
|
|
6
|
-
readonly signature: string;
|
|
7
|
-
readonly vault: string;
|
|
8
|
-
readonly pubKeys: Buffer[];
|
|
9
|
-
constructor(params: WrappedGenerationParameters);
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import { ChainId } from '../../network/ChainId.js';
|
|
3
|
-
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
4
|
-
export declare class wBTC extends ContractBaseMetadata {
|
|
5
|
-
protected network: Network;
|
|
6
|
-
readonly tokenName: string;
|
|
7
|
-
readonly tokenSymbol: string;
|
|
8
|
-
readonly decimals: number;
|
|
9
|
-
protected readonly address: string;
|
|
10
|
-
constructor(network?: Network, chainId?: ChainId);
|
|
11
|
-
static getAddress(network?: Network, chainId?: ChainId): string;
|
|
12
|
-
private static getWBTCAddressForChain;
|
|
13
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { networks } from '@btc-vision/bitcoin';
|
|
2
|
-
import { ChainId } from '../../network/ChainId.js';
|
|
3
|
-
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
4
|
-
import { WBTC_ADDRESS_FRACTAL, WBTC_ADDRESS_REGTEST, WBTC_ADDRESS_TESTNET } from '../tokens.js';
|
|
5
|
-
export class wBTC extends ContractBaseMetadata {
|
|
6
|
-
constructor(network = networks.bitcoin, chainId = ChainId.Bitcoin) {
|
|
7
|
-
super(network);
|
|
8
|
-
this.network = network;
|
|
9
|
-
this.tokenName = 'Wrapped Bitcoin';
|
|
10
|
-
this.tokenSymbol = 'wBTC';
|
|
11
|
-
this.decimals = 8;
|
|
12
|
-
this.address = wBTC.getAddress(network, chainId);
|
|
13
|
-
}
|
|
14
|
-
static getAddress(network = networks.bitcoin, chainId) {
|
|
15
|
-
switch (network.bech32) {
|
|
16
|
-
case networks.bitcoin.bech32:
|
|
17
|
-
return this.getWBTCAddressForChain(chainId ?? ChainId.Bitcoin).p2tr(network);
|
|
18
|
-
case networks.regtest.bech32:
|
|
19
|
-
return WBTC_ADDRESS_REGTEST.p2tr(network);
|
|
20
|
-
case networks.testnet.bech32:
|
|
21
|
-
return WBTC_ADDRESS_TESTNET.p2tr(network);
|
|
22
|
-
default:
|
|
23
|
-
throw new Error(`Invalid network: ${network.bech32}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
static getWBTCAddressForChain(chainId) {
|
|
27
|
-
switch (chainId) {
|
|
28
|
-
case ChainId.Fractal:
|
|
29
|
-
return WBTC_ADDRESS_FRACTAL;
|
|
30
|
-
default:
|
|
31
|
-
throw new Error(`Unsupported chainId: ${chainId}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
-
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Psbt } from '@btc-vision/bitcoin';
|
|
6
|
-
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
export declare class UnwrapSegwitTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
8
|
-
private static readonly UNWRAP_SELECTOR;
|
|
9
|
-
type: TransactionType.WBTC_UNWRAP;
|
|
10
|
-
readonly amount: bigint;
|
|
11
|
-
protected readonly compiledTargetScript: Buffer;
|
|
12
|
-
protected readonly scriptTree: Taptree;
|
|
13
|
-
protected sighashTypes: number[];
|
|
14
|
-
protected readonly contractSecret: Buffer;
|
|
15
|
-
protected readonly vaultUTXOs: VaultUTXOs[];
|
|
16
|
-
private readonly wbtc;
|
|
17
|
-
private readonly calculatedSignHash;
|
|
18
|
-
constructor(parameters: IUnwrapParameters);
|
|
19
|
-
static generateBurnCalldata(amount: bigint): Buffer;
|
|
20
|
-
signPSBT(): Promise<Psbt>;
|
|
21
|
-
mergeVaults(input: VaultUTXOs[]): Promise<void>;
|
|
22
|
-
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
23
|
-
protected generateMultiSignRedeemScript(publicKeys: string[], minimum: number): {
|
|
24
|
-
witnessUtxo: Buffer;
|
|
25
|
-
redeemScript: Buffer;
|
|
26
|
-
witnessScript: Buffer;
|
|
27
|
-
};
|
|
28
|
-
private addVaultUTXO;
|
|
29
|
-
private addVaultInputs;
|
|
30
|
-
private calculateOutputLeftAmountFromVaults;
|
|
31
|
-
private getVaultTotalOutputAmount;
|
|
32
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
3
|
-
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
|
-
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
5
|
-
import { payments } from '@btc-vision/bitcoin';
|
|
6
|
-
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
7
|
-
import { PsbtTransaction } from '../processor/PsbtTransaction.js';
|
|
8
|
-
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
9
|
-
import { ABICoder } from '../../abi/ABICoder.js';
|
|
10
|
-
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
11
|
-
const abiCoder = new ABICoder();
|
|
12
|
-
export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
13
|
-
constructor(parameters) {
|
|
14
|
-
if (parameters.amount < TransactionBuilder.MINIMUM_DUST) {
|
|
15
|
-
throw new Error('Amount is below dust limit');
|
|
16
|
-
}
|
|
17
|
-
parameters.disableAutoRefund = true;
|
|
18
|
-
parameters.calldata = UnwrapSegwitTransaction.generateBurnCalldata(parameters.amount);
|
|
19
|
-
super(parameters);
|
|
20
|
-
this.type = TransactionType.WBTC_UNWRAP;
|
|
21
|
-
this.sighashTypes = [];
|
|
22
|
-
this.calculatedSignHash = PsbtTransaction.calculateSignHash(this.sighashTypes);
|
|
23
|
-
this.wbtc = new wBTC(parameters.network, parameters.chainId);
|
|
24
|
-
this.to = this.wbtc.getAddress();
|
|
25
|
-
this.vaultUTXOs = parameters.unwrapUTXOs;
|
|
26
|
-
this.amount = parameters.amount;
|
|
27
|
-
this.contractSecret = this.generateSecret();
|
|
28
|
-
this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret);
|
|
29
|
-
this.scriptTree = this.getScriptTree();
|
|
30
|
-
this.internalInit();
|
|
31
|
-
}
|
|
32
|
-
static generateBurnCalldata(amount) {
|
|
33
|
-
if (!amount)
|
|
34
|
-
throw new Error('Amount is required');
|
|
35
|
-
const bufWriter = new BinaryWriter();
|
|
36
|
-
bufWriter.writeSelector(UnwrapSegwitTransaction.UNWRAP_SELECTOR);
|
|
37
|
-
bufWriter.writeU256(amount);
|
|
38
|
-
return Buffer.from(bufWriter.getBuffer());
|
|
39
|
-
}
|
|
40
|
-
async signPSBT() {
|
|
41
|
-
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
42
|
-
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
43
|
-
}
|
|
44
|
-
if (!this.vaultUTXOs.length) {
|
|
45
|
-
throw new Error('No vault UTXOs provided');
|
|
46
|
-
}
|
|
47
|
-
if (this.signed)
|
|
48
|
-
throw new Error('Transaction is already signed');
|
|
49
|
-
this.signed = true;
|
|
50
|
-
await this.buildTransaction();
|
|
51
|
-
this.ignoreSignatureError();
|
|
52
|
-
await this.mergeVaults(this.vaultUTXOs);
|
|
53
|
-
const builtTx = await this.internalBuildTransaction(this.transaction);
|
|
54
|
-
if (builtTx) {
|
|
55
|
-
return this.transaction;
|
|
56
|
-
}
|
|
57
|
-
throw new Error('Could not sign transaction');
|
|
58
|
-
}
|
|
59
|
-
async mergeVaults(input) {
|
|
60
|
-
const firstVault = input[0];
|
|
61
|
-
if (!firstVault) {
|
|
62
|
-
throw new Error('No vaults provided');
|
|
63
|
-
}
|
|
64
|
-
const total = this.getVaultTotalOutputAmount(input);
|
|
65
|
-
if (total < this.amount) {
|
|
66
|
-
throw new Error(`Total vault amount (${total} sat) is less than the amount to unwrap (${this.amount} sat)`);
|
|
67
|
-
}
|
|
68
|
-
const outputLeftAmount = this.calculateOutputLeftAmountFromVaults(input);
|
|
69
|
-
if (outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT &&
|
|
70
|
-
outputLeftAmount !== currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT) {
|
|
71
|
-
throw new Error(`Output left amount is below minimum consolidation (${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat) amount ${outputLeftAmount} for vault ${firstVault.vault}`);
|
|
72
|
-
}
|
|
73
|
-
this.addOutput({
|
|
74
|
-
address: firstVault.vault,
|
|
75
|
-
value: Number(outputLeftAmount),
|
|
76
|
-
});
|
|
77
|
-
this.addOutput({
|
|
78
|
-
address: this.from,
|
|
79
|
-
value: Number(this.amount),
|
|
80
|
-
});
|
|
81
|
-
for (const vault of input) {
|
|
82
|
-
await this.addVaultInputs(vault);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async internalBuildTransaction(transaction, checkPartialSigs = false) {
|
|
86
|
-
if (transaction.data.inputs.length === 0) {
|
|
87
|
-
const inputs = this.getInputs();
|
|
88
|
-
const outputs = this.getOutputs();
|
|
89
|
-
transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
90
|
-
transaction.addInputs(inputs, checkPartialSigs);
|
|
91
|
-
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
92
|
-
transaction.updateInput(i, this.updateInputs[i]);
|
|
93
|
-
}
|
|
94
|
-
transaction.addOutputs(outputs);
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
await this.signInputs(transaction);
|
|
98
|
-
if (this.finalized) {
|
|
99
|
-
this.transactionFee = BigInt(transaction.getFee());
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
const err = e;
|
|
105
|
-
this.error(`[internalBuildTransaction] Something went wrong while getting building the transaction: ${err.stack}`);
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
generateMultiSignRedeemScript(publicKeys, minimum) {
|
|
110
|
-
const p2ms = payments.p2ms({
|
|
111
|
-
m: minimum,
|
|
112
|
-
pubkeys: publicKeys.map((key) => Buffer.from(key, 'base64')),
|
|
113
|
-
network: this.network,
|
|
114
|
-
});
|
|
115
|
-
const p2wsh = payments.p2wsh({
|
|
116
|
-
redeem: p2ms,
|
|
117
|
-
network: this.network,
|
|
118
|
-
});
|
|
119
|
-
const witnessUtxo = p2wsh.output;
|
|
120
|
-
const redeemScript = p2wsh.redeem?.output;
|
|
121
|
-
const witnessScript = p2ms.output;
|
|
122
|
-
if (!witnessUtxo || !redeemScript || !witnessScript) {
|
|
123
|
-
throw new Error('Failed to generate redeem script');
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
witnessUtxo,
|
|
127
|
-
redeemScript,
|
|
128
|
-
witnessScript,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
addVaultUTXO(utxo, witness) {
|
|
132
|
-
const input = {
|
|
133
|
-
hash: utxo.hash,
|
|
134
|
-
index: utxo.outputIndex,
|
|
135
|
-
witnessUtxo: {
|
|
136
|
-
script: Buffer.from(utxo.output, 'base64'),
|
|
137
|
-
value: Number(utxo.value),
|
|
138
|
-
},
|
|
139
|
-
witnessScript: witness.witnessScript,
|
|
140
|
-
sequence: this.sequence,
|
|
141
|
-
};
|
|
142
|
-
if (this.calculatedSignHash) {
|
|
143
|
-
input.sighashType = this.calculatedSignHash;
|
|
144
|
-
}
|
|
145
|
-
this.addInput(input);
|
|
146
|
-
}
|
|
147
|
-
async addVaultInputs(vault, firstSigner = this.signer) {
|
|
148
|
-
const p2wshOutput = this.generateMultiSignRedeemScript(vault.publicKeys, vault.minimum);
|
|
149
|
-
for (const utxo of vault.utxos) {
|
|
150
|
-
const inputIndex = this.transaction.inputCount;
|
|
151
|
-
this.addVaultUTXO(utxo, p2wshOutput);
|
|
152
|
-
if (firstSigner) {
|
|
153
|
-
try {
|
|
154
|
-
await this.signInput(this.transaction, this.transaction.data.inputs[inputIndex], inputIndex, this.signer);
|
|
155
|
-
this.log(`Signed input ${inputIndex} with ${firstSigner.publicKey.toString('hex')}`);
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
if (!this.ignoreSignatureErrors) {
|
|
159
|
-
this.warn(`Failed to sign input ${inputIndex} with ${firstSigner.publicKey.toString('hex')} ${e.message}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
calculateOutputLeftAmountFromVaults(vaults) {
|
|
166
|
-
const total = this.getVaultTotalOutputAmount(vaults);
|
|
167
|
-
return total - this.amount;
|
|
168
|
-
}
|
|
169
|
-
getVaultTotalOutputAmount(vaults) {
|
|
170
|
-
let total = BigInt(0);
|
|
171
|
-
for (const vault of vaults) {
|
|
172
|
-
for (const utxo of vault.utxos) {
|
|
173
|
-
total += BigInt(utxo.value);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return total;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
UnwrapSegwitTransaction.UNWRAP_SELECTOR = Number('0x' + abiCoder.encodeSelector('burn'));
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
-
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
-
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
|
-
import { Network, Payment, Psbt, PsbtInput } from '@btc-vision/bitcoin';
|
|
6
|
-
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
7
|
-
export declare class UnwrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_UNWRAP> {
|
|
8
|
-
private static readonly UNWRAP_SELECTOR;
|
|
9
|
-
type: TransactionType.WBTC_UNWRAP;
|
|
10
|
-
readonly amount: bigint;
|
|
11
|
-
protected readonly compiledTargetScript: Buffer;
|
|
12
|
-
protected readonly scriptTree: Taptree;
|
|
13
|
-
protected sighashTypes: number[];
|
|
14
|
-
protected readonly contractSecret: Buffer;
|
|
15
|
-
protected readonly vaultUTXOs: VaultUTXOs[];
|
|
16
|
-
protected readonly estimatedFeeLoss: bigint;
|
|
17
|
-
private readonly wbtc;
|
|
18
|
-
private readonly calculatedSignHash;
|
|
19
|
-
constructor(parameters: IUnwrapParameters);
|
|
20
|
-
static generateBurnCalldata(amount: bigint): Buffer;
|
|
21
|
-
signPSBT(): Promise<Psbt>;
|
|
22
|
-
getRefund(): bigint;
|
|
23
|
-
getFeeLossOrRefund(): bigint;
|
|
24
|
-
protected mergeVaults(): void;
|
|
25
|
-
protected calculateNumEmptyWitnesses(vault: VaultUTXOs[]): bigint;
|
|
26
|
-
protected calculateNumSignatures(vault: VaultUTXOs[]): bigint;
|
|
27
|
-
protected calculateNumInputs(vault: VaultUTXOs[]): bigint;
|
|
28
|
-
protected internalPubKeyToXOnly(): Buffer;
|
|
29
|
-
protected generateTapDataForInput(pubkeys: Buffer[], minimumSignatures: number): {
|
|
30
|
-
internalPubkey: Buffer;
|
|
31
|
-
network: Network;
|
|
32
|
-
scriptTree: Taptree;
|
|
33
|
-
redeem: Payment;
|
|
34
|
-
};
|
|
35
|
-
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
36
|
-
protected internalBuildTransaction(transaction: Psbt, checkPartialSigs?: boolean): Promise<boolean>;
|
|
37
|
-
private addVaultUTXO;
|
|
38
|
-
private addVaultInputs;
|
|
39
|
-
private calculateOutputLeftAmountFromVaults;
|
|
40
|
-
private getVaultTotalOutputAmount;
|
|
41
|
-
}
|