@btc-vision/transaction 1.0.2 → 1.0.3
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/generators/AddressGenerator.d.ts +7 -0
- package/browser/generators/builders/DeploymentGenerator.d.ts +1 -0
- package/browser/index.js +2 -2
- package/browser/keypair/Wallet.d.ts +1 -0
- package/browser/opnet.d.ts +2 -0
- package/browser/tests/gen.d.ts +1 -0
- package/browser/tests/transfer.d.ts +1 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/browser/verification/TapscriptVerificator.d.ts +17 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/AddressGenerator.d.ts +7 -0
- package/build/generators/AddressGenerator.js +21 -0
- package/build/generators/OPNetAddressGenerator.d.ts +0 -0
- package/build/generators/OPNetAddressGenerator.js +1 -0
- package/build/generators/builders/DeploymentGenerator.d.ts +1 -0
- package/build/generators/builders/DeploymentGenerator.js +10 -7
- package/build/keypair/Wallet.d.ts +1 -0
- package/build/keypair/Wallet.js +6 -0
- package/build/opnet.d.ts +2 -0
- package/build/opnet.js +2 -0
- package/build/tests/gen.d.ts +1 -0
- package/build/tests/gen.js +15 -0
- package/build/tests/test.js +15 -38
- package/build/tests/transfer.d.ts +1 -0
- package/build/tests/transfer.js +74 -0
- package/build/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/transaction/builders/TransactionBuilder.js +4 -1
- package/build/verification/TapscriptVerificator.d.ts +17 -0
- package/build/verification/TapscriptVerificator.js +43 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AddressGenerator.html +178 -0
- package/docs/classes/BitcoinUtils.html +182 -182
- package/docs/classes/CalldataGenerator.html +210 -210
- package/docs/classes/Compressor.html +184 -184
- package/docs/classes/ContractBaseMetadata.html +181 -181
- package/docs/classes/DeploymentGenerator.html +200 -199
- package/docs/classes/EcKeyPair.html +279 -279
- package/docs/classes/FundingTransaction.html +315 -315
- package/docs/classes/Generator.html +198 -198
- package/docs/classes/InteractionTransaction.html +387 -387
- package/docs/classes/TapscriptVerificator.html +180 -0
- package/docs/classes/TransactionBuilder.html +325 -325
- package/docs/classes/TransactionFactory.html +179 -179
- package/docs/classes/TweakedSigner.html +180 -180
- package/docs/classes/UTXOManager.html +186 -186
- package/docs/classes/Wallet.html +192 -190
- package/docs/classes/wBTC.html +188 -188
- package/docs/enums/TransactionType.html +178 -178
- package/docs/interfaces/ContractAddressVerificationParams.html +179 -0
- package/docs/interfaces/FetchUTXOParams.html +177 -177
- package/docs/interfaces/IFundingTransactionParameters.html +181 -181
- package/docs/interfaces/IInteractionParameters.html +184 -184
- package/docs/interfaces/ITransactionDataContractDeployment.html +183 -183
- package/docs/interfaces/ITransactionDataContractInteractionWrap.html +185 -185
- package/docs/interfaces/ITransactionParameters.html +180 -180
- package/docs/interfaces/IWallet.html +180 -180
- package/docs/interfaces/NetworkInformation.html +175 -175
- package/docs/interfaces/PsbtInputExtended.html +193 -193
- package/docs/interfaces/PsbtOutputExtendedAddress.html +182 -182
- package/docs/interfaces/PsbtOutputExtendedScript.html +182 -182
- package/docs/interfaces/RawUTXOResponse.html +177 -177
- package/docs/interfaces/TapLeafScript.html +176 -176
- package/docs/interfaces/TweakSettings.html +178 -178
- package/docs/interfaces/UTXO.html +177 -177
- package/docs/interfaces/UpdateInput.html +174 -174
- package/docs/modules.html +5 -2
- package/docs/types/PsbtOutputExtended.html +173 -173
- package/docs/variables/version.html +173 -173
- package/package.json +2 -1
- package/src/_version.ts +1 -1
- package/src/generators/AddressGenerator.ts +29 -0
- package/src/generators/builders/DeploymentGenerator.ts +16 -13
- package/src/keypair/Wallet.ts +12 -0
- package/src/opnet.ts +4 -0
- package/src/tests/gen.ts +24 -0
- package/src/tests/test.ts +17 -54
- package/src/{scripts/test.ts → tests/transfer.ts} +102 -98
- package/src/transaction/builders/TransactionBuilder.ts +610 -606
- package/src/verification/TapscriptVerificator.ts +89 -0
- package/src/scripts/Regtest.ts +0 -19
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import bitcoin, { Network, networks, Payment, payments } from 'bitcoinjs-lib';
|
|
2
|
+
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
3
|
+
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
4
|
+
import { DeploymentGenerator } from '../generators/builders/DeploymentGenerator.js';
|
|
5
|
+
import { TransactionBuilder } from '../transaction/builders/TransactionBuilder.js';
|
|
6
|
+
import { AddressGenerator } from '../generators/AddressGenerator.js';
|
|
7
|
+
|
|
8
|
+
export interface ContractAddressVerificationParams {
|
|
9
|
+
readonly deployerPubKeyXOnly: Buffer;
|
|
10
|
+
readonly contractSaltPubKey: Buffer;
|
|
11
|
+
readonly originalSalt: Buffer;
|
|
12
|
+
readonly bytecode: Buffer;
|
|
13
|
+
readonly network?: Network;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class TapscriptVerificator {
|
|
17
|
+
private static readonly TAP_SCRIPT_VERSION: number = 192;
|
|
18
|
+
|
|
19
|
+
public static getContractAddress(
|
|
20
|
+
params: ContractAddressVerificationParams,
|
|
21
|
+
): string | undefined {
|
|
22
|
+
const network = params.network || networks.bitcoin;
|
|
23
|
+
const scriptBuilder: DeploymentGenerator = new DeploymentGenerator(
|
|
24
|
+
params.deployerPubKeyXOnly,
|
|
25
|
+
toXOnly(params.contractSaltPubKey),
|
|
26
|
+
network,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const compiledTargetScript: Buffer = scriptBuilder.compile(
|
|
30
|
+
params.bytecode,
|
|
31
|
+
params.originalSalt,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const scriptTree: Taptree = [
|
|
35
|
+
{
|
|
36
|
+
output: compiledTargetScript,
|
|
37
|
+
version: TapscriptVerificator.TAP_SCRIPT_VERSION,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
output: TransactionBuilder.LOCK_LEAF_SCRIPT,
|
|
41
|
+
version: TapscriptVerificator.TAP_SCRIPT_VERSION,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
return TapscriptVerificator.generateAddressFromScript(params, scriptTree);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static getContractSeed(
|
|
49
|
+
deployerPubKey: Buffer,
|
|
50
|
+
bytecode: Buffer,
|
|
51
|
+
saltHash: Buffer,
|
|
52
|
+
): Buffer {
|
|
53
|
+
const sha256OfBytecode: Buffer = bitcoin.crypto.hash256(bytecode);
|
|
54
|
+
const buf: Buffer = Buffer.concat([deployerPubKey, saltHash, sha256OfBytecode]);
|
|
55
|
+
|
|
56
|
+
return bitcoin.crypto.hash256(buf);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public static generateContractVirtualAddress(
|
|
60
|
+
deployerPubKey: Buffer,
|
|
61
|
+
bytecode: Buffer,
|
|
62
|
+
saltHash: Buffer,
|
|
63
|
+
network: Network = networks.bitcoin,
|
|
64
|
+
): string {
|
|
65
|
+
const virtualAddress: Buffer = TapscriptVerificator.getContractSeed(
|
|
66
|
+
deployerPubKey,
|
|
67
|
+
bytecode,
|
|
68
|
+
saltHash,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return AddressGenerator.generatePKSH(virtualAddress, network);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public static generateAddressFromScript(
|
|
75
|
+
params: ContractAddressVerificationParams,
|
|
76
|
+
scriptTree: Taptree,
|
|
77
|
+
): string | undefined {
|
|
78
|
+
const network = params.network || networks.bitcoin;
|
|
79
|
+
|
|
80
|
+
const transactionData: Payment = {
|
|
81
|
+
internalPubkey: params.deployerPubKeyXOnly,
|
|
82
|
+
network: network,
|
|
83
|
+
scriptTree: scriptTree,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const tx: Payment = payments.p2tr(transactionData);
|
|
87
|
+
return tx.address;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/scripts/Regtest.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NetworkInformation } from '../network/NetworkInformation.js';
|
|
2
|
-
import { BitcoinNetwork } from '@btc-vision/bsi-common';
|
|
3
|
-
|
|
4
|
-
export const Regtest: NetworkInformation = {
|
|
5
|
-
wallet: {
|
|
6
|
-
address: 'bcrt1qfqsr3m7vjxheghcvw4ks0fryqxfq8qzjf8fxes',
|
|
7
|
-
publicKey: '020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c',
|
|
8
|
-
privateKey: 'cRCiYAgCBrU7hSaJBRuPqKVYXQqM5CKXbMfWHb25X4FDAWJ8Ai92',
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
config: {
|
|
12
|
-
BITCOIND_NETWORK: BitcoinNetwork.Regtest,
|
|
13
|
-
BITCOIND_HOST: '51.81.67.34',
|
|
14
|
-
BITCOIND_PORT: 9242,
|
|
15
|
-
|
|
16
|
-
BITCOIND_USERNAME: 'HJSiowseujhs',
|
|
17
|
-
BITCOIND_PASSWORD: 'YHEFHSDJ23JOIhjjef2ied9u290efu2930u90U',
|
|
18
|
-
},
|
|
19
|
-
};
|