@btc-vision/transaction 1.0.113 → 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 +1 -2
- package/browser/keypair/EcKeyPair.d.ts +9 -9
- package/browser/keypair/Wallet.d.ts +11 -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/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/MultiSignTransaction.d.ts +4 -5
- package/browser/transaction/builders/TransactionBuilder.d.ts +5 -6
- 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/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 +1 -2
- package/build/keypair/AddressVerificator.js +7 -2
- package/build/keypair/EcKeyPair.d.ts +9 -9
- package/build/keypair/EcKeyPair.js +9 -2
- package/build/keypair/Wallet.d.ts +11 -5
- package/build/keypair/Wallet.js +14 -1
- 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/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/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +6 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +4 -5
- package/build/transaction/builders/TransactionBuilder.d.ts +5 -6
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +2 -1
- 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/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 +3 -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 +9 -5
- package/src/keypair/EcKeyPair.ts +39 -37
- package/src/keypair/Wallet.ts +61 -12
- 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/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 +4 -5
- package/src/transaction/builders/DeploymentTransaction.ts +17 -4
- package/src/transaction/builders/MultiSignTransaction.ts +4 -5
- package/src/transaction/builders/TransactionBuilder.ts +8 -9
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +3 -1
- package/src/transaction/builders/UnwrapTransaction.ts +3 -17
- package/src/transaction/builders/WrapTransaction.ts +7 -8
- 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/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
package/src/metadata/tokens.ts
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { ChainId } from '../network/ChainId.js';
|
|
2
|
+
import { Address } from '../keypair/Address.js';
|
|
3
|
+
|
|
4
|
+
function deadAddress(): Address {
|
|
5
|
+
return Address.dead();
|
|
6
|
+
}
|
|
3
7
|
|
|
4
8
|
// Addresses Regtest
|
|
5
|
-
export const FACTORY_ADDRESS_REGTEST: Address =
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
9
|
+
export const FACTORY_ADDRESS_REGTEST: Address = deadAddress();
|
|
10
|
+
|
|
11
|
+
export const POOL_ADDRESS_REGTEST: Address = deadAddress();
|
|
12
|
+
export const WBTC_ADDRESS_REGTEST: Address = deadAddress();
|
|
13
|
+
export const MOTO_ADDRESS_REGTEST: Address = deadAddress();
|
|
14
|
+
export const ROUTER_ADDRESS_REGTEST: Address = deadAddress();
|
|
10
15
|
|
|
11
16
|
// Addresses Testnet
|
|
12
|
-
export const FACTORY_ADDRESS_TESTNET: Address =
|
|
13
|
-
export const POOL_ADDRESS_TESTNET: Address =
|
|
14
|
-
export const WBTC_ADDRESS_TESTNET: Address =
|
|
15
|
-
export const MOTO_ADDRESS_TESTNET: Address =
|
|
16
|
-
export const ROUTER_ADDRESS_TESTNET: Address =
|
|
17
|
+
export const FACTORY_ADDRESS_TESTNET: Address = deadAddress();
|
|
18
|
+
export const POOL_ADDRESS_TESTNET: Address = deadAddress();
|
|
19
|
+
export const WBTC_ADDRESS_TESTNET: Address = deadAddress();
|
|
20
|
+
export const MOTO_ADDRESS_TESTNET: Address = deadAddress();
|
|
21
|
+
export const ROUTER_ADDRESS_TESTNET: Address = deadAddress();
|
|
17
22
|
|
|
18
23
|
// Addresses Fractal
|
|
19
|
-
export const FACTORY_ADDRESS_FRACTAL: Address =
|
|
20
|
-
export const POOL_ADDRESS_FRACTAL: Address =
|
|
21
|
-
export const WBTC_ADDRESS_FRACTAL: Address =
|
|
22
|
-
export const MOTO_ADDRESS_FRACTAL: Address =
|
|
23
|
-
export const ROUTER_ADDRESS_FRACTAL: Address =
|
|
24
|
+
export const FACTORY_ADDRESS_FRACTAL: Address = deadAddress();
|
|
25
|
+
export const POOL_ADDRESS_FRACTAL: Address = deadAddress();
|
|
26
|
+
export const WBTC_ADDRESS_FRACTAL: Address = deadAddress();
|
|
27
|
+
export const MOTO_ADDRESS_FRACTAL: Address = deadAddress();
|
|
28
|
+
export const ROUTER_ADDRESS_FRACTAL: Address = deadAddress();
|
|
24
29
|
|
|
25
30
|
export enum OPNetNetwork {
|
|
26
31
|
Mainnet = 'mainnet',
|
package/src/opnet.ts
CHANGED
|
@@ -73,6 +73,19 @@ export * from './consensus/ConsensusConfig.js';
|
|
|
73
73
|
export * from './consensus/Consensus.js';
|
|
74
74
|
export * from './consensus/metadata/RoswellConsensus.js';
|
|
75
75
|
|
|
76
|
+
/** Binary */
|
|
77
|
+
export * from './utils/BufferHelper.js';
|
|
78
|
+
export * from './utils/types.js';
|
|
79
|
+
export * from './keypair/Address.js';
|
|
80
|
+
export * from './event/NetEvent.js';
|
|
81
|
+
export * from './deterministic/DeterministicMap.js';
|
|
82
|
+
export * from './deterministic/DeterministicSet.js';
|
|
83
|
+
export * from './deterministic/AddressMap.js';
|
|
84
|
+
export * from './deterministic/AddressSet.js';
|
|
85
|
+
export * from './abi/ABICoder.js';
|
|
86
|
+
export * from './buffer/BinaryWriter.js';
|
|
87
|
+
export * from './buffer/BinaryReader.js';
|
|
88
|
+
|
|
76
89
|
/** Custom signers */
|
|
77
90
|
export * from './transaction/browser/BrowserSignerBase.js';
|
|
78
91
|
export * from './transaction/browser/extensions/UnisatSigner.js';
|
|
@@ -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';
|
|
@@ -17,7 +16,7 @@ export interface ICustomTransactionParameters extends SharedInteractionParameter
|
|
|
17
16
|
readonly script: (Buffer | Stack)[];
|
|
18
17
|
readonly witnesses: Buffer[];
|
|
19
18
|
|
|
20
|
-
readonly to:
|
|
19
|
+
readonly to: string;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
/**
|
|
@@ -31,7 +30,7 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
31
30
|
* The contract address
|
|
32
31
|
* @protected
|
|
33
32
|
*/
|
|
34
|
-
protected readonly _scriptAddress:
|
|
33
|
+
protected readonly _scriptAddress: string;
|
|
35
34
|
/**
|
|
36
35
|
* The tap leaf script
|
|
37
36
|
* @private
|
|
@@ -113,14 +112,14 @@ export class CustomScriptTransaction extends TransactionBuilder<TransactionType.
|
|
|
113
112
|
/**
|
|
114
113
|
* @description Get the contract address (PKSH)
|
|
115
114
|
*/
|
|
116
|
-
public get scriptAddress():
|
|
115
|
+
public get scriptAddress(): string {
|
|
117
116
|
return this._scriptAddress;
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
/**
|
|
121
120
|
* @description Get the P2TR address
|
|
122
121
|
*/
|
|
123
|
-
public get p2trAddress():
|
|
122
|
+
public get p2trAddress(): string {
|
|
124
123
|
return this.to || this.getScriptAddress();
|
|
125
124
|
}
|
|
126
125
|
|
|
@@ -10,10 +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';
|
|
16
14
|
import { ECPairInterface } from 'ecpair';
|
|
15
|
+
import { Address } from '../../keypair/Address.js';
|
|
17
16
|
|
|
18
17
|
export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
19
18
|
public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
@@ -78,6 +77,12 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
78
77
|
*/
|
|
79
78
|
private readonly contractSigner: Signer | ECPairInterface;
|
|
80
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The contract public key
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private readonly _contractPubKey: string;
|
|
85
|
+
|
|
81
86
|
/**
|
|
82
87
|
* The contract salt random bytes
|
|
83
88
|
* @private
|
|
@@ -116,7 +121,15 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
116
121
|
|
|
117
122
|
this.internalInit();
|
|
118
123
|
|
|
119
|
-
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;
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
/**
|
|
@@ -129,7 +142,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
129
142
|
/**
|
|
130
143
|
* @description Get the P2TR address
|
|
131
144
|
*/
|
|
132
|
-
public get p2trAddress():
|
|
145
|
+
public get p2trAddress(): string {
|
|
133
146
|
return this.to || this.getScriptAddress();
|
|
134
147
|
}
|
|
135
148
|
|
|
@@ -6,7 +6,6 @@ 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';
|
|
@@ -19,9 +18,9 @@ export interface MultiSignParameters
|
|
|
19
18
|
readonly from?: undefined;
|
|
20
19
|
readonly to?: undefined;
|
|
21
20
|
readonly psbt?: Psbt;
|
|
22
|
-
readonly receiver:
|
|
21
|
+
readonly receiver: string;
|
|
23
22
|
readonly requestedAmount: bigint;
|
|
24
|
-
readonly refundVault:
|
|
23
|
+
readonly refundVault: string;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export interface MultiSignFromBase64Params extends Omit<MultiSignParameters, 'psbt'> {
|
|
@@ -62,8 +61,8 @@ export class MultiSignTransaction extends TransactionBuilder<TransactionType.MUL
|
|
|
62
61
|
protected readonly originalInputCount: number = 0;
|
|
63
62
|
protected readonly requestedAmount: bigint;
|
|
64
63
|
|
|
65
|
-
protected readonly receiver:
|
|
66
|
-
protected readonly refundVault:
|
|
64
|
+
protected readonly receiver: string;
|
|
65
|
+
protected readonly refundVault: string;
|
|
67
66
|
/**
|
|
68
67
|
* @description Sign hash types
|
|
69
68
|
* @protected
|
|
@@ -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';
|
|
@@ -108,13 +107,13 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
108
107
|
* @description The address where the transaction is sent to
|
|
109
108
|
* @protected
|
|
110
109
|
*/
|
|
111
|
-
protected to:
|
|
110
|
+
protected to: string | undefined;
|
|
112
111
|
|
|
113
112
|
/**
|
|
114
113
|
* @description The address where the transaction is sent from
|
|
115
114
|
* @protected
|
|
116
115
|
*/
|
|
117
|
-
protected from:
|
|
116
|
+
protected from: string;
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
119
|
* @description The maximum fee rate of the transaction
|
|
@@ -163,7 +162,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
163
162
|
from: string | undefined,
|
|
164
163
|
keypair: ECPairInterface | Signer,
|
|
165
164
|
network: Network,
|
|
166
|
-
):
|
|
165
|
+
): string {
|
|
167
166
|
return from || EcKeyPair.getTaprootAddress(keypair, network);
|
|
168
167
|
}
|
|
169
168
|
|
|
@@ -223,9 +222,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
223
222
|
|
|
224
223
|
/**
|
|
225
224
|
* Set the destination address of the transaction
|
|
226
|
-
* @param {
|
|
225
|
+
* @param {string} address - The address to set
|
|
227
226
|
*/
|
|
228
|
-
public setDestinationAddress(address:
|
|
227
|
+
public setDestinationAddress(address: string): void {
|
|
229
228
|
this.to = address; // this.getScriptAddress()
|
|
230
229
|
}
|
|
231
230
|
|
|
@@ -354,7 +353,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
354
353
|
/**
|
|
355
354
|
* Receiver address.
|
|
356
355
|
* @public
|
|
357
|
-
* @returns {
|
|
356
|
+
* @returns {string} - The receiver address
|
|
358
357
|
*/
|
|
359
358
|
public toAddress(): string | undefined {
|
|
360
359
|
return this.to;
|
|
@@ -362,9 +361,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
362
361
|
|
|
363
362
|
/**
|
|
364
363
|
* @description Returns the script address
|
|
365
|
-
* @returns {
|
|
364
|
+
* @returns {string} - The script address
|
|
366
365
|
*/
|
|
367
|
-
public address():
|
|
366
|
+
public address(): string | undefined {
|
|
368
367
|
return this.tapData?.address;
|
|
369
368
|
}
|
|
370
369
|
|
|
@@ -3,7 +3,6 @@ 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';
|
|
@@ -11,6 +10,9 @@ import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/Psb
|
|
|
11
10
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
12
11
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
13
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';
|
|
14
16
|
|
|
15
17
|
const abiCoder: ABICoder = new ABICoder();
|
|
16
18
|
|
|
@@ -3,7 +3,6 @@ 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 { Network, Payment, payments, Psbt } from 'bitcoinjs-lib';
|
|
9
8
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
@@ -17,6 +16,9 @@ import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
|
17
16
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
18
17
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
19
18
|
import { Features } from '../../generators/Features.js';
|
|
19
|
+
import { ABICoder } from '../../abi/ABICoder.js';
|
|
20
|
+
import { Selector } from '../../utils/types.js';
|
|
21
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
20
22
|
|
|
21
23
|
const abiCoder: ABICoder = new ABICoder();
|
|
22
24
|
const numsPoint: Buffer = Buffer.from(
|
|
@@ -140,22 +142,6 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
140
142
|
return Buffer.from(bufWriter.getBuffer());
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
/*public tweakScalarPoints(): Uint8Array {
|
|
144
|
-
const key: Uint8Array = (this.signer as ECPairInterface).privateKey as Uint8Array;
|
|
145
|
-
//const r = bitcoin.crypto.sha256(Buffer.from('WTF_IS_OP_NET!', 'utf-8'));
|
|
146
|
-
const rG = ecc.pointMultiply(
|
|
147
|
-
Buffer.from(this.internalPubKeyToXOnly()), //EcKeyPair.fromPrivateKey(r).publicKey.subarray(1)
|
|
148
|
-
key,
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (!rG) throw new Error('Failed to tweak rG');
|
|
152
|
-
|
|
153
|
-
const tweaked = ecc.pointAdd(this.numsPoint, rG);
|
|
154
|
-
if (!tweaked) throw new Error('Failed to tweak rG');
|
|
155
|
-
|
|
156
|
-
return Buffer.from(tweaked);
|
|
157
|
-
}*/
|
|
158
|
-
|
|
159
145
|
/**
|
|
160
146
|
* @description Signs the transaction
|
|
161
147
|
* @public
|
|
@@ -4,14 +4,15 @@ import { PsbtOutputExtendedAddress, TapLeafScript } from '../interfaces/Tap.js';
|
|
|
4
4
|
import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
5
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
6
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
7
|
-
import { ABICoder, Address, BinaryWriter, Selector } from '@btc-vision/bsi-binary';
|
|
8
|
-
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
9
7
|
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
10
8
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
11
|
-
import { AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
12
9
|
import { Network } from 'bitcoinjs-lib';
|
|
13
10
|
import { P2TR_MS } from '../shared/P2TR_MS.js';
|
|
14
11
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
12
|
+
import { Selector } from '../../utils/types.js';
|
|
13
|
+
import { ABICoder } from '../../abi/ABICoder.js';
|
|
14
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
15
|
+
import { Address } from '../../keypair/Address.js';
|
|
15
16
|
|
|
16
17
|
const abiCoder: ABICoder = new ABICoder();
|
|
17
18
|
|
|
@@ -31,7 +32,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
31
32
|
* @private
|
|
32
33
|
* @readonly
|
|
33
34
|
*/
|
|
34
|
-
public readonly vault:
|
|
35
|
+
public readonly vault: string;
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* The amount to wrap
|
|
@@ -91,9 +92,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
91
92
|
);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
const receiver: Address =
|
|
95
|
-
parameters.receiver ||
|
|
96
|
-
TransactionBuilder.getFrom(parameters.from, parameters.signer, parameters.network);
|
|
95
|
+
const receiver: Address = parameters.receiver || new Address(parameters.signer.publicKey);
|
|
97
96
|
|
|
98
97
|
parameters.calldata = WrapTransaction.generateMintCalldata(
|
|
99
98
|
parameters.amount,
|
|
@@ -146,7 +145,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
146
145
|
if (!amount) throw new Error('Amount is required');
|
|
147
146
|
if (!to) throw new Error('To address is required');
|
|
148
147
|
|
|
149
|
-
if (!
|
|
148
|
+
if (!to.isValid(network)) {
|
|
150
149
|
throw new Error(
|
|
151
150
|
`Oops! The address ${to} is not a valid P2TR address! If you wrap at this address, your funds will be lost!`,
|
|
152
151
|
);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
4
3
|
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
4
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
5
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
6
|
import { PsbtOutputExtended } from './Tap.js';
|
|
7
|
+
import { Address } from '../../keypair/Address.js';
|
|
8
8
|
|
|
9
9
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
10
|
-
readonly from?:
|
|
11
|
-
readonly to?:
|
|
10
|
+
readonly from?: string;
|
|
11
|
+
readonly to?: string;
|
|
12
|
+
|
|
12
13
|
utxos: UTXO[];
|
|
13
14
|
|
|
14
15
|
nonWitnessUtxo?: Buffer;
|
|
@@ -39,13 +40,13 @@ export interface IInteractionParameters
|
|
|
39
40
|
extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
40
41
|
readonly calldata: Buffer;
|
|
41
42
|
|
|
42
|
-
readonly to:
|
|
43
|
+
readonly to: string;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
46
|
-
readonly to?:
|
|
47
|
+
readonly to?: string;
|
|
48
|
+
readonly from: string;
|
|
47
49
|
|
|
48
|
-
readonly from: Address;
|
|
49
50
|
readonly amount: bigint;
|
|
50
51
|
readonly receiver?: Address;
|
|
51
52
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
2
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
4
3
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
@@ -10,7 +9,7 @@ export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export interface IWBTCUTXODocument {
|
|
13
|
-
readonly vault:
|
|
12
|
+
readonly vault: string;
|
|
14
13
|
readonly blockId: bigint;
|
|
15
14
|
|
|
16
15
|
readonly hash: string;
|
|
@@ -21,8 +20,8 @@ export interface IWBTCUTXODocument {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export interface VaultUTXOs {
|
|
24
|
-
readonly vault:
|
|
25
|
-
readonly publicKeys:
|
|
23
|
+
readonly vault: string;
|
|
24
|
+
readonly publicKeys: string[];
|
|
26
25
|
readonly minimum: number;
|
|
27
26
|
readonly utxos: IWBTCUTXODocument[];
|
|
28
27
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Network, networks } from 'bitcoinjs-lib';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
4
3
|
import { MultiSignParameters, MultiSignTransaction } from '../builders/MultiSignTransaction.js';
|
|
5
4
|
|
|
@@ -9,14 +8,14 @@ export class P2TR_MS {
|
|
|
9
8
|
* @param {Buffer[]} pubKeys - The public keys to use
|
|
10
9
|
* @param {number} minimumSignatureRequired - The minimum number of signatures required
|
|
11
10
|
* @param {Network} network - The network to use
|
|
12
|
-
* @returns {
|
|
11
|
+
* @returns {string} - The generated address
|
|
13
12
|
* @throws {Error} - If the address cannot be generated
|
|
14
13
|
*/
|
|
15
14
|
public static generateMultiSigAddress(
|
|
16
15
|
pubKeys: Buffer[],
|
|
17
16
|
minimumSignatureRequired: number,
|
|
18
17
|
network: Network = networks.bitcoin,
|
|
19
|
-
):
|
|
18
|
+
): string {
|
|
20
19
|
const publicKeys: Buffer[] = EcKeyPair.verifyPubKeys(pubKeys, network);
|
|
21
20
|
if (publicKeys.length !== pubKeys.length) throw new Error(`Contains invalid public keys`);
|
|
22
21
|
|