@btc-vision/transaction 1.0.112 → 1.0.114
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/abi/ABICoder.d.ts +31 -0
- package/browser/buffer/BinaryReader.d.ts +37 -0
- package/browser/buffer/BinaryWriter.d.ts +46 -0
- package/browser/deterministic/AddressMap.d.ts +10 -0
- package/browser/deterministic/AddressSet.d.ts +13 -0
- package/browser/deterministic/DeterministicMap.d.ts +17 -0
- package/browser/deterministic/DeterministicSet.d.ts +13 -0
- package/browser/deterministic/Map.d.ts +14 -0
- package/browser/event/NetEvent.d.ts +5 -0
- package/browser/generators/AddressGenerator.d.ts +3 -0
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +23 -0
- package/browser/keypair/AddressVerificator.d.ts +15 -4
- package/browser/keypair/EcKeyPair.d.ts +15 -12
- package/browser/keypair/Wallet.d.ts +12 -5
- package/browser/metadata/ContractBaseMetadata.d.ts +3 -4
- package/browser/metadata/contracts/wBTC.d.ts +2 -3
- package/browser/metadata/tokens.d.ts +1 -1
- package/browser/opnet.d.ts +11 -0
- package/browser/signer/TweakedSigner.d.ts +2 -2
- package/browser/transaction/TransactionFactory.d.ts +6 -6
- package/browser/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/browser/transaction/browser/types/Unisat.d.ts +2 -3
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/browser/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/browser/transaction/builders/FundingTransaction.d.ts +2 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +6 -7
- package/browser/transaction/builders/WrapTransaction.d.ts +2 -2
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/browser/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -2
- package/browser/transaction/shared/TweakedTransaction.d.ts +8 -7
- package/browser/utils/BufferHelper.d.ts +11 -0
- package/browser/utils/types.d.ts +12 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +31 -0
- package/build/abi/ABICoder.js +137 -0
- package/build/buffer/BinaryReader.d.ts +37 -0
- package/build/buffer/BinaryReader.js +192 -0
- package/build/buffer/BinaryWriter.d.ts +46 -0
- package/build/buffer/BinaryWriter.js +258 -0
- package/build/deterministic/AddressMap.d.ts +10 -0
- package/build/deterministic/AddressMap.js +46 -0
- package/build/deterministic/AddressSet.d.ts +13 -0
- package/build/deterministic/AddressSet.js +44 -0
- package/build/deterministic/DeterministicMap.d.ts +17 -0
- package/build/deterministic/DeterministicMap.js +83 -0
- package/build/deterministic/DeterministicSet.d.ts +13 -0
- package/build/deterministic/DeterministicSet.js +46 -0
- package/build/deterministic/Map.d.ts +14 -0
- package/build/deterministic/Map.js +56 -0
- package/build/event/NetEvent.d.ts +5 -0
- package/build/event/NetEvent.js +6 -0
- package/build/generators/AddressGenerator.d.ts +3 -0
- package/build/generators/AddressGenerator.js +8 -1
- package/build/keypair/Address.d.ts +23 -0
- package/build/keypair/Address.js +129 -0
- package/build/keypair/AddressVerificator.d.ts +15 -4
- package/build/keypair/AddressVerificator.js +79 -3
- package/build/keypair/EcKeyPair.d.ts +15 -12
- package/build/keypair/EcKeyPair.js +61 -9
- package/build/keypair/Wallet.d.ts +12 -5
- package/build/keypair/Wallet.js +19 -5
- package/build/metadata/ContractBaseMetadata.d.ts +3 -4
- package/build/metadata/contracts/wBTC.d.ts +2 -3
- package/build/metadata/contracts/wBTC.js +4 -6
- package/build/metadata/tokens.d.ts +1 -1
- package/build/metadata/tokens.js +19 -15
- package/build/opnet.d.ts +11 -0
- package/build/opnet.js +11 -0
- package/build/signer/TweakedSigner.d.ts +2 -2
- package/build/signer/TweakedSigner.js +1 -1
- package/build/transaction/TransactionFactory.d.ts +6 -6
- package/build/transaction/TransactionFactory.js +3 -2
- package/build/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/build/transaction/browser/types/Unisat.d.ts +2 -3
- package/build/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/build/transaction/builders/CustomScriptTransaction.js +3 -3
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +10 -6
- package/build/transaction/builders/FundingTransaction.d.ts +2 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
- package/build/transaction/builders/TransactionBuilder.d.ts +6 -7
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +4 -3
- package/build/transaction/builders/WrapTransaction.d.ts +2 -2
- package/build/transaction/builders/WrapTransaction.js +5 -6
- package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/build/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/build/transaction/shared/P2TR_MS.d.ts +1 -2
- package/build/transaction/shared/TweakedTransaction.d.ts +8 -7
- package/build/transaction/shared/TweakedTransaction.js +1 -1
- package/build/utils/BufferHelper.d.ts +11 -0
- package/build/utils/BufferHelper.js +50 -0
- package/build/utils/types.d.ts +12 -0
- package/build/utils/types.js +1 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/utxo/OPNetLimitedProvider.js +1 -1
- package/build/verification/TapscriptVerificator.js +3 -2
- package/package.json +4 -2
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +158 -0
- package/src/buffer/BinaryReader.ts +260 -0
- package/src/buffer/BinaryWriter.ts +331 -0
- package/src/deterministic/AddressMap.ts +57 -0
- package/src/deterministic/AddressSet.ts +62 -0
- package/src/deterministic/DeterministicMap.ts +88 -0
- package/src/deterministic/DeterministicSet.ts +56 -0
- package/src/deterministic/Map.ts +66 -0
- package/src/event/NetEvent.ts +6 -0
- package/src/generators/AddressGenerator.ts +15 -1
- package/src/keypair/Address.ts +235 -0
- package/src/keypair/AddressVerificator.ts +149 -6
- package/src/keypair/EcKeyPair.ts +146 -47
- package/src/keypair/Wallet.ts +72 -15
- package/src/metadata/ContractBaseMetadata.ts +3 -4
- package/src/metadata/contracts/wBTC.ts +8 -9
- package/src/metadata/tokens.ts +21 -16
- package/src/opnet.ts +13 -0
- package/src/signer/TweakedSigner.ts +3 -2
- package/src/transaction/TransactionFactory.ts +11 -10
- package/src/transaction/browser/BrowserSignerBase.ts +3 -4
- package/src/transaction/browser/extensions/UnisatSigner.ts +6 -7
- package/src/transaction/browser/types/Unisat.ts +2 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +10 -10
- package/src/transaction/builders/DeploymentTransaction.ts +23 -9
- package/src/transaction/builders/FundingTransaction.ts +2 -1
- package/src/transaction/builders/MultiSignTransaction.ts +10 -7
- package/src/transaction/builders/SharedInteractionTransaction.ts +5 -5
- package/src/transaction/builders/TransactionBuilder.ts +26 -17
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +10 -4
- package/src/transaction/builders/UnwrapTransaction.ts +5 -19
- package/src/transaction/builders/WrapTransaction.ts +7 -13
- package/src/transaction/interfaces/ITransactionParameters.ts +7 -6
- package/src/transaction/processor/PsbtTransaction.ts +3 -4
- package/src/transaction/shared/P2TR_MS.ts +2 -3
- package/src/transaction/shared/TweakedTransaction.ts +12 -12
- package/src/utils/BufferHelper.ts +71 -0
- package/src/utils/types.ts +19 -0
- package/src/utxo/OPNetLimitedProvider.ts +3 -8
- package/src/verification/TapscriptVerificator.ts +4 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { Psbt, Transaction } from 'bitcoinjs-lib';
|
|
3
2
|
import { Output } from 'bitcoinjs-lib/src/transaction.js';
|
|
4
3
|
import { currentConsensus, currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
@@ -30,17 +29,18 @@ import { PSBTTypes } from './psbt/PSBTTypes.js';
|
|
|
30
29
|
export interface DeploymentResult {
|
|
31
30
|
readonly transaction: [string, string];
|
|
32
31
|
|
|
33
|
-
readonly contractAddress:
|
|
34
|
-
readonly
|
|
32
|
+
readonly contractAddress: string;
|
|
33
|
+
readonly contractPubKey: string;
|
|
34
|
+
readonly p2trAddress: string;
|
|
35
35
|
|
|
36
36
|
readonly utxos: UTXO[];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface WrapResult {
|
|
40
40
|
readonly transaction: [string, string];
|
|
41
|
-
readonly vaultAddress:
|
|
41
|
+
readonly vaultAddress: string;
|
|
42
42
|
readonly amount: bigint;
|
|
43
|
-
readonly receiverAddress:
|
|
43
|
+
readonly receiverAddress: string;
|
|
44
44
|
readonly utxos: UTXO[];
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -277,7 +277,8 @@ export class TransactionFactory {
|
|
|
277
277
|
|
|
278
278
|
return {
|
|
279
279
|
transaction: [signedTransaction.toHex(), outTx.toHex()],
|
|
280
|
-
contractAddress: finalTransaction.contractAddress,
|
|
280
|
+
contractAddress: finalTransaction.contractAddress.p2tr(deploymentParameters.network),
|
|
281
|
+
contractPubKey: finalTransaction.contractPubKey,
|
|
281
282
|
p2trAddress: finalTransaction.p2trAddress,
|
|
282
283
|
utxos: [refundUTXO],
|
|
283
284
|
};
|
|
@@ -344,7 +345,7 @@ export class TransactionFactory {
|
|
|
344
345
|
transaction: [signedTransaction.tx.toHex(), outTx.toHex()],
|
|
345
346
|
vaultAddress: finalTransaction.vault,
|
|
346
347
|
amount: finalTransaction.amount,
|
|
347
|
-
receiverAddress: finalTransaction.receiver,
|
|
348
|
+
receiverAddress: finalTransaction.receiver.p2tr(wrapParameters.network),
|
|
348
349
|
utxos: this.getUTXOAsTransaction(signedTransaction.tx, wrapParameters.from, 1),
|
|
349
350
|
};
|
|
350
351
|
}
|
|
@@ -522,12 +523,12 @@ export class TransactionFactory {
|
|
|
522
523
|
* Get all new UTXOs of a generated transaction.
|
|
523
524
|
* @param {TransactionBuilder<TransactionType>} original - The original transaction
|
|
524
525
|
* @param {Transaction} tx - The transaction
|
|
525
|
-
* @param {
|
|
526
|
+
* @param {string} to - The address to filter
|
|
526
527
|
*/
|
|
527
528
|
public getAllNewUTXOs(
|
|
528
529
|
original: TransactionBuilder<TransactionType>,
|
|
529
530
|
tx: Transaction,
|
|
530
|
-
to:
|
|
531
|
+
to: string,
|
|
531
532
|
): UTXO[] {
|
|
532
533
|
const outputs = original.getOutputs();
|
|
533
534
|
|
|
@@ -613,7 +614,7 @@ export class TransactionFactory {
|
|
|
613
614
|
return params.priorityFee;
|
|
614
615
|
}
|
|
615
616
|
|
|
616
|
-
private getUTXOAsTransaction(tx: Transaction, to:
|
|
617
|
+
private getUTXOAsTransaction(tx: Transaction, to: string, index: number): UTXO[] {
|
|
617
618
|
if (!tx.outs[index]) return [];
|
|
618
619
|
|
|
619
620
|
const out: Output = tx.outs[index];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Network, Psbt, Signer } from 'bitcoinjs-lib';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Create a custom keypair.
|
|
@@ -10,10 +9,10 @@ export abstract class CustomKeypair implements Signer {
|
|
|
10
9
|
|
|
11
10
|
public abstract publicKey: Buffer;
|
|
12
11
|
|
|
13
|
-
public abstract addresses:
|
|
12
|
+
public abstract addresses: string[];
|
|
14
13
|
|
|
15
|
-
public abstract p2tr:
|
|
16
|
-
public abstract p2wpkh:
|
|
14
|
+
public abstract p2tr: string;
|
|
15
|
+
public abstract p2wpkh: string;
|
|
17
16
|
|
|
18
17
|
protected constructor() {}
|
|
19
18
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { TapScriptSig } from 'bip174/src/lib/interfaces.js';
|
|
3
2
|
import { Network, networks, Psbt } from 'bitcoinjs-lib';
|
|
4
3
|
import { ECPairInterface } from 'ecpair';
|
|
@@ -24,9 +23,9 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
private _p2tr:
|
|
26
|
+
private _p2tr: string | undefined;
|
|
28
27
|
|
|
29
|
-
public get p2tr():
|
|
28
|
+
public get p2tr(): string {
|
|
30
29
|
if (!this._p2tr) {
|
|
31
30
|
throw new Error('P2TR address not set');
|
|
32
31
|
}
|
|
@@ -34,9 +33,9 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
34
33
|
return this._p2tr;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
private _p2wpkh:
|
|
36
|
+
private _p2wpkh: string | undefined;
|
|
38
37
|
|
|
39
|
-
public get p2wpkh():
|
|
38
|
+
public get p2wpkh(): string {
|
|
40
39
|
if (!this._p2wpkh) {
|
|
41
40
|
throw new Error('P2PKH address not set');
|
|
42
41
|
}
|
|
@@ -44,9 +43,9 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
44
43
|
return this._p2wpkh;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
private _addresses:
|
|
46
|
+
private _addresses: string[] | undefined;
|
|
48
47
|
|
|
49
|
-
public get addresses():
|
|
48
|
+
public get addresses(): string[] {
|
|
50
49
|
if (!this._addresses) {
|
|
51
50
|
throw new Error('Addresses not set');
|
|
52
51
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { Web3Provider } from '../Web3Provider.js';
|
|
3
2
|
|
|
4
3
|
export enum UnisatNetwork {
|
|
@@ -45,7 +44,7 @@ export interface ToSignInputPublicKey extends ToSignInputBase {
|
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export interface ToSignInputAddress extends ToSignInputBase {
|
|
48
|
-
readonly address:
|
|
47
|
+
readonly address: string;
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
export type ToSignInput = ToSignInputPublicKey | ToSignInputAddress;
|
|
@@ -59,7 +58,7 @@ export interface Unisat {
|
|
|
59
58
|
web3?: Web3Provider;
|
|
60
59
|
|
|
61
60
|
sendBitcoin(
|
|
62
|
-
toAddress:
|
|
61
|
+
toAddress: string,
|
|
63
62
|
satoshis: number,
|
|
64
63
|
options: { feeRate: number; memo?: string; memos?: string[] },
|
|
65
64
|
): Promise<string>;
|
|
@@ -2,7 +2,6 @@ import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
4
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
6
5
|
import { crypto as bitCrypto, Payment, Psbt, Signer, Stack } from 'bitcoinjs-lib';
|
|
7
6
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
8
7
|
import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
|
|
@@ -11,12 +10,13 @@ import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
|
11
10
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
12
11
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
13
12
|
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
13
|
+
import { ECPairInterface } from 'ecpair';
|
|
14
14
|
|
|
15
15
|
export interface ICustomTransactionParameters extends SharedInteractionParameters {
|
|
16
16
|
readonly script: (Buffer | Stack)[];
|
|
17
17
|
readonly witnesses: Buffer[];
|
|
18
18
|
|
|
19
|
-
readonly to:
|
|
19
|
+
readonly to: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -30,7 +30,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
30
30
|
* The contract address
|
|
31
31
|
* @protected
|
|
32
32
|
*/
|
|
33
|
-
protected readonly _scriptAddress:
|
|
33
|
+
protected readonly _scriptAddress: string;
|
|
34
34
|
/**
|
|
35
35
|
* The tap leaf script
|
|
36
36
|
* @private
|
|
@@ -72,7 +72,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
72
72
|
* The contract signer
|
|
73
73
|
* @private
|
|
74
74
|
*/
|
|
75
|
-
private readonly contractSigner: Signer;
|
|
75
|
+
private readonly contractSigner: Signer | ECPairInterface;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* The contract salt random bytes
|
|
@@ -112,14 +112,14 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
112
112
|
/**
|
|
113
113
|
* @description Get the contract address (PKSH)
|
|
114
114
|
*/
|
|
115
|
-
public get scriptAddress():
|
|
115
|
+
public get scriptAddress(): string {
|
|
116
116
|
return this._scriptAddress;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* @description Get the P2TR address
|
|
121
121
|
*/
|
|
122
|
-
public get p2trAddress():
|
|
122
|
+
public get p2trAddress(): string {
|
|
123
123
|
return this.to || this.getScriptAddress();
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -136,7 +136,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
136
136
|
* @protected
|
|
137
137
|
*/
|
|
138
138
|
protected contractSignerXOnlyPubKey(): Buffer {
|
|
139
|
-
return toXOnly(this.contractSigner.publicKey);
|
|
139
|
+
return toXOnly(Buffer.from(this.contractSigner.publicKey));
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -261,7 +261,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
261
261
|
if (!this.tapLeafScript) {
|
|
262
262
|
throw new Error('Tap leaf script is required');
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
const scriptSolution = this.witnesses;
|
|
266
266
|
const witness = scriptSolution
|
|
267
267
|
.concat(this.tapLeafScript.script)
|
|
@@ -277,10 +277,10 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
277
277
|
* @private
|
|
278
278
|
*/
|
|
279
279
|
private getPubKeys(): Buffer[] {
|
|
280
|
-
const pubkeys = [this.signer.publicKey];
|
|
280
|
+
const pubkeys = [Buffer.from(this.signer.publicKey)];
|
|
281
281
|
|
|
282
282
|
if (this.contractSigner) {
|
|
283
|
-
pubkeys.push(this.contractSigner.publicKey);
|
|
283
|
+
pubkeys.push(Buffer.from(this.contractSigner.publicKey));
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
return pubkeys;
|
|
@@ -10,9 +10,9 @@ import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
|
10
10
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
11
11
|
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
12
12
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
13
|
-
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
14
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
15
13
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
14
|
+
import { ECPairInterface } from 'ecpair';
|
|
15
|
+
import { Address } from '../../keypair/Address.js';
|
|
16
16
|
|
|
17
17
|
export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
18
18
|
public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
@@ -75,7 +75,13 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
75
75
|
* The contract signer
|
|
76
76
|
* @private
|
|
77
77
|
*/
|
|
78
|
-
private readonly contractSigner: Signer;
|
|
78
|
+
private readonly contractSigner: Signer | ECPairInterface;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The contract public key
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private readonly _contractPubKey: string;
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
87
|
* The contract salt random bytes
|
|
@@ -100,7 +106,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
100
106
|
this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
|
|
101
107
|
|
|
102
108
|
this.deploymentGenerator = new DeploymentGenerator(
|
|
103
|
-
this.signer.publicKey,
|
|
109
|
+
Buffer.from(this.signer.publicKey),
|
|
104
110
|
this.contractSignerXOnlyPubKey(),
|
|
105
111
|
this.network,
|
|
106
112
|
);
|
|
@@ -115,7 +121,15 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
115
121
|
|
|
116
122
|
this.internalInit();
|
|
117
123
|
|
|
118
|
-
this.
|
|
124
|
+
this._contractPubKey = '0x' + this.contractSigner.publicKey.toString('hex');
|
|
125
|
+
this._contractAddress = new Address(this.contractSigner.publicKey); //AddressGenerator.generatePKSH(this.contractSeed, this.network);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get the contract public key
|
|
130
|
+
*/
|
|
131
|
+
public get contractPubKey(): string {
|
|
132
|
+
return this._contractPubKey;
|
|
119
133
|
}
|
|
120
134
|
|
|
121
135
|
/**
|
|
@@ -128,7 +142,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
128
142
|
/**
|
|
129
143
|
* @description Get the P2TR address
|
|
130
144
|
*/
|
|
131
|
-
public get p2trAddress():
|
|
145
|
+
public get p2trAddress(): string {
|
|
132
146
|
return this.to || this.getScriptAddress();
|
|
133
147
|
}
|
|
134
148
|
|
|
@@ -145,7 +159,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
145
159
|
* @protected
|
|
146
160
|
*/
|
|
147
161
|
protected contractSignerXOnlyPubKey(): Buffer {
|
|
148
|
-
return toXOnly(this.contractSigner.publicKey);
|
|
162
|
+
return toXOnly(Buffer.from(this.contractSigner.publicKey));
|
|
149
163
|
}
|
|
150
164
|
|
|
151
165
|
/**
|
|
@@ -323,10 +337,10 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
323
337
|
* @private
|
|
324
338
|
*/
|
|
325
339
|
private getPubKeys(): Buffer[] {
|
|
326
|
-
const pubkeys = [this.signer.publicKey];
|
|
340
|
+
const pubkeys = [Buffer.from(this.signer.publicKey)];
|
|
327
341
|
|
|
328
342
|
if (this.contractSigner) {
|
|
329
|
-
pubkeys.push(this.contractSigner.publicKey);
|
|
343
|
+
pubkeys.push(Buffer.from(this.contractSigner.publicKey));
|
|
330
344
|
}
|
|
331
345
|
|
|
332
346
|
return pubkeys;
|
|
@@ -2,6 +2,7 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
2
2
|
import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
3
|
import { Signer } from 'bitcoinjs-lib';
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
|
+
import { ECPairInterface } from 'ecpair';
|
|
5
6
|
|
|
6
7
|
export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
7
8
|
public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
|
|
@@ -64,7 +65,7 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
protected override getSignerKey(): Signer {
|
|
68
|
+
protected override getSignerKey(): Signer | ECPairInterface {
|
|
68
69
|
return this.signer;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -6,10 +6,10 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
6
6
|
import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
7
7
|
import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
|
|
8
8
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
9
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
10
9
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
11
10
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
12
11
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
12
|
+
import { ECPairInterface } from 'ecpair';
|
|
13
13
|
|
|
14
14
|
export interface MultiSignParameters
|
|
15
15
|
extends Omit<ITransactionParameters, 'priorityFee' | 'signer'> {
|
|
@@ -18,9 +18,9 @@ export interface MultiSignParameters
|
|
|
18
18
|
readonly from?: undefined;
|
|
19
19
|
readonly to?: undefined;
|
|
20
20
|
readonly psbt?: Psbt;
|
|
21
|
-
readonly receiver:
|
|
21
|
+
readonly receiver: string;
|
|
22
22
|
readonly requestedAmount: bigint;
|
|
23
|
-
readonly refundVault:
|
|
23
|
+
readonly refundVault: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface MultiSignFromBase64Params extends Omit<MultiSignParameters, 'psbt'> {
|
|
@@ -61,8 +61,8 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
61
61
|
protected readonly originalInputCount: number = 0;
|
|
62
62
|
protected readonly requestedAmount: bigint;
|
|
63
63
|
|
|
64
|
-
protected readonly receiver:
|
|
65
|
-
protected readonly refundVault:
|
|
64
|
+
protected readonly receiver: string;
|
|
65
|
+
protected readonly refundVault: string;
|
|
66
66
|
/**
|
|
67
67
|
* @description Sign hash types
|
|
68
68
|
* @protected
|
|
@@ -172,7 +172,7 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
172
172
|
*/
|
|
173
173
|
public static signPartial(
|
|
174
174
|
psbt: Psbt,
|
|
175
|
-
signer: Signer,
|
|
175
|
+
signer: Signer | ECPairInterface,
|
|
176
176
|
originalInputCount: number,
|
|
177
177
|
minimums: number[],
|
|
178
178
|
): {
|
|
@@ -498,7 +498,10 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
498
498
|
* @returns {Promise<boolean>}
|
|
499
499
|
* @throws {Error} - If something went wrong while building the transaction
|
|
500
500
|
*/
|
|
501
|
-
protected override async internalBuildTransaction(
|
|
501
|
+
protected override async internalBuildTransaction(
|
|
502
|
+
transaction: Psbt,
|
|
503
|
+
checkPartialSigs: boolean = false,
|
|
504
|
+
): Promise<boolean> {
|
|
502
505
|
const inputs: PsbtInputExtended[] = this.getInputs();
|
|
503
506
|
const outputs: PsbtOutputExtended[] = this.getOutputs();
|
|
504
507
|
|
|
@@ -50,7 +50,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
50
50
|
* Script signer for the interaction
|
|
51
51
|
* @protected
|
|
52
52
|
*/
|
|
53
|
-
protected readonly scriptSigner: Signer;
|
|
53
|
+
protected readonly scriptSigner: Signer | ECPairInterface;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Disable auto refund
|
|
@@ -73,7 +73,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
73
73
|
this.scriptSigner = this.generateKeyPairFromSeed();
|
|
74
74
|
|
|
75
75
|
this.calldataGenerator = new CalldataGenerator(
|
|
76
|
-
this.signer.publicKey,
|
|
76
|
+
Buffer.from(this.signer.publicKey),
|
|
77
77
|
this.scriptSignerXOnlyPubKey(),
|
|
78
78
|
this.network,
|
|
79
79
|
);
|
|
@@ -113,7 +113,7 @@ export abstract class SharedInteractionTransaction<
|
|
|
113
113
|
* @returns {Buffer} The internal pubkey as an x-only key
|
|
114
114
|
*/
|
|
115
115
|
protected scriptSignerXOnlyPubKey(): Buffer {
|
|
116
|
-
return toXOnly(this.scriptSigner.publicKey);
|
|
116
|
+
return toXOnly(Buffer.from(this.scriptSigner.publicKey));
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -362,10 +362,10 @@ export abstract class SharedInteractionTransaction<
|
|
|
362
362
|
* @returns {Buffer[]} The public keys
|
|
363
363
|
*/
|
|
364
364
|
private getPubKeys(): Buffer[] {
|
|
365
|
-
const pubkeys = [this.signer.publicKey];
|
|
365
|
+
const pubkeys = [Buffer.from(this.signer.publicKey)];
|
|
366
366
|
|
|
367
367
|
if (this.scriptSigner) {
|
|
368
|
-
pubkeys.push(this.scriptSigner.publicKey);
|
|
368
|
+
pubkeys.push(Buffer.from(this.scriptSigner.publicKey));
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
return pubkeys;
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
ITransactionParameters,
|
|
9
9
|
} from '../interfaces/ITransactionParameters.js';
|
|
10
10
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
11
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
12
11
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
13
12
|
import { ECPairInterface } from 'ecpair';
|
|
14
13
|
import { AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
@@ -43,65 +42,79 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
43
42
|
* @description Cost in satoshis of the transaction fee
|
|
44
43
|
*/
|
|
45
44
|
public transactionFee: bigint = 0n;
|
|
45
|
+
|
|
46
46
|
/**
|
|
47
47
|
* @description The estimated fees of the transaction
|
|
48
48
|
*/
|
|
49
49
|
public estimatedFees: bigint = 0n;
|
|
50
|
+
|
|
50
51
|
/**
|
|
51
52
|
* @param {ITransactionParameters} parameters - The transaction parameters
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
54
|
public optionalOutputs: PsbtOutputExtended[] | undefined;
|
|
55
|
+
|
|
55
56
|
/**
|
|
56
57
|
* @description The transaction itself.
|
|
57
58
|
*/
|
|
58
59
|
protected transaction: Psbt;
|
|
60
|
+
|
|
59
61
|
/**
|
|
60
62
|
* @description Inputs to update later on.
|
|
61
63
|
*/
|
|
62
64
|
protected readonly updateInputs: UpdateInput[] = [];
|
|
65
|
+
|
|
63
66
|
/**
|
|
64
67
|
* @description The outputs of the transaction
|
|
65
68
|
*/
|
|
66
69
|
protected readonly outputs: PsbtOutputExtended[] = [];
|
|
70
|
+
|
|
67
71
|
/**
|
|
68
72
|
* @description Output that will be used to pay the fees
|
|
69
73
|
*/
|
|
70
74
|
protected feeOutput: PsbtOutputExtended | null = null;
|
|
75
|
+
|
|
71
76
|
/**
|
|
72
77
|
* @description The total amount of satoshis in the inputs
|
|
73
78
|
*/
|
|
74
79
|
protected totalInputAmount: bigint;
|
|
80
|
+
|
|
75
81
|
/**
|
|
76
82
|
* @description The signer of the transaction
|
|
77
83
|
*/
|
|
78
|
-
protected readonly signer: Signer;
|
|
84
|
+
protected readonly signer: Signer | ECPairInterface;
|
|
85
|
+
|
|
79
86
|
/**
|
|
80
87
|
* @description The network where the transaction will be broadcasted
|
|
81
88
|
*/
|
|
82
89
|
protected readonly network: Network;
|
|
90
|
+
|
|
83
91
|
/**
|
|
84
92
|
* @description The fee rate of the transaction
|
|
85
93
|
*/
|
|
86
94
|
protected readonly feeRate: number;
|
|
95
|
+
|
|
87
96
|
/**
|
|
88
97
|
* @description The opnet priority fee of the transaction
|
|
89
98
|
*/
|
|
90
99
|
protected priorityFee: bigint;
|
|
100
|
+
|
|
91
101
|
/**
|
|
92
102
|
* @description The utxos used in the transaction
|
|
93
103
|
*/
|
|
94
104
|
protected utxos: UTXO[];
|
|
105
|
+
|
|
95
106
|
/**
|
|
96
107
|
* @description The address where the transaction is sent to
|
|
97
108
|
* @protected
|
|
98
109
|
*/
|
|
99
|
-
protected to:
|
|
110
|
+
protected to: string | undefined;
|
|
111
|
+
|
|
100
112
|
/**
|
|
101
113
|
* @description The address where the transaction is sent from
|
|
102
114
|
* @protected
|
|
103
115
|
*/
|
|
104
|
-
protected from:
|
|
116
|
+
protected from: string;
|
|
117
|
+
|
|
105
118
|
/**
|
|
106
119
|
* @description The maximum fee rate of the transaction
|
|
107
120
|
*/
|
|
@@ -131,11 +144,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
131
144
|
|
|
132
145
|
this.optionalOutputs = parameters.optionalOutputs;
|
|
133
146
|
|
|
134
|
-
this.from = TransactionBuilder.getFrom(
|
|
135
|
-
parameters.from,
|
|
136
|
-
this.signer as ECPairInterface,
|
|
137
|
-
this.network,
|
|
138
|
-
);
|
|
147
|
+
this.from = TransactionBuilder.getFrom(parameters.from, this.signer, this.network);
|
|
139
148
|
|
|
140
149
|
this.totalInputAmount = this.calculateTotalUTXOAmount();
|
|
141
150
|
|
|
@@ -151,9 +160,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
151
160
|
|
|
152
161
|
public static getFrom(
|
|
153
162
|
from: string | undefined,
|
|
154
|
-
keypair: ECPairInterface,
|
|
163
|
+
keypair: ECPairInterface | Signer,
|
|
155
164
|
network: Network,
|
|
156
|
-
):
|
|
165
|
+
): string {
|
|
157
166
|
return from || EcKeyPair.getTaprootAddress(keypair, network);
|
|
158
167
|
}
|
|
159
168
|
|
|
@@ -213,9 +222,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
213
222
|
|
|
214
223
|
/**
|
|
215
224
|
* Set the destination address of the transaction
|
|
216
|
-
* @param {
|
|
225
|
+
* @param {string} address - The address to set
|
|
217
226
|
*/
|
|
218
|
-
public setDestinationAddress(address:
|
|
227
|
+
public setDestinationAddress(address: string): void {
|
|
219
228
|
this.to = address; // this.getScriptAddress()
|
|
220
229
|
}
|
|
221
230
|
|
|
@@ -344,7 +353,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
344
353
|
/**
|
|
345
354
|
* Receiver address.
|
|
346
355
|
* @public
|
|
347
|
-
* @returns {
|
|
356
|
+
* @returns {string} - The receiver address
|
|
348
357
|
*/
|
|
349
358
|
public toAddress(): string | undefined {
|
|
350
359
|
return this.to;
|
|
@@ -352,9 +361,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
352
361
|
|
|
353
362
|
/**
|
|
354
363
|
* @description Returns the script address
|
|
355
|
-
* @returns {
|
|
364
|
+
* @returns {string} - The script address
|
|
356
365
|
*/
|
|
357
|
-
public address():
|
|
366
|
+
public address(): string | undefined {
|
|
358
367
|
return this.tapData?.address;
|
|
359
368
|
}
|
|
360
369
|
|
|
@@ -3,13 +3,16 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
3
3
|
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
4
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
5
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
6
|
-
import { ABICoder, BinaryWriter, Selector } from '@btc-vision/bsi-binary';
|
|
7
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
8
7
|
import { payments, Psbt, Signer } from 'bitcoinjs-lib';
|
|
9
8
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
10
9
|
import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
11
10
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
12
11
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
12
|
+
import { ECPairInterface } from 'ecpair';
|
|
13
|
+
import { Selector } from '../../utils/types.js';
|
|
14
|
+
import { ABICoder } from '../../abi/ABICoder.js';
|
|
15
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
13
16
|
|
|
14
17
|
const abiCoder: ABICoder = new ABICoder();
|
|
15
18
|
|
|
@@ -196,7 +199,10 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction<Transa
|
|
|
196
199
|
* @returns {Promise<boolean>}
|
|
197
200
|
* @throws {Error} - If something went wrong while building the transaction
|
|
198
201
|
*/
|
|
199
|
-
protected async internalBuildTransaction(
|
|
202
|
+
protected async internalBuildTransaction(
|
|
203
|
+
transaction: Psbt,
|
|
204
|
+
checkPartialSigs: boolean = false,
|
|
205
|
+
): Promise<boolean> {
|
|
200
206
|
if (transaction.data.inputs.length === 0) {
|
|
201
207
|
const inputs: PsbtInputExtended[] = this.getInputs();
|
|
202
208
|
const outputs: PsbtOutputExtended[] = this.getOutputs();
|
|
@@ -300,12 +306,12 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction<Transa
|
|
|
300
306
|
/**
|
|
301
307
|
* @description Add vault inputs to the transaction
|
|
302
308
|
* @param {VaultUTXOs} vault The vault UTXOs
|
|
303
|
-
* @param {Signer} [firstSigner] The first signer
|
|
309
|
+
* @param {Signer | ECPairInterface} [firstSigner] The first signer
|
|
304
310
|
* @private
|
|
305
311
|
*/
|
|
306
312
|
private async addVaultInputs(
|
|
307
313
|
vault: VaultUTXOs,
|
|
308
|
-
firstSigner: Signer = this.signer,
|
|
314
|
+
firstSigner: Signer | ECPairInterface = this.signer,
|
|
309
315
|
): Promise<void> {
|
|
310
316
|
const p2wshOutput = this.generateMultiSignRedeemScript(vault.publicKeys, vault.minimum);
|
|
311
317
|
for (const utxo of vault.utxos) {
|