@btc-vision/transaction 1.0.0
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/.babelrc +7 -0
- package/.gitattributes +2 -0
- package/.github/workflows/node.js.yml +22 -0
- package/.idea/codeStyles/Project.xml +56 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/transaction.iml +16 -0
- package/.idea/vcs.xml +6 -0
- package/.prettierrc.json +12 -0
- package/CONTRIBUTING.md +71 -0
- package/LICENSE.md +16 -0
- package/README.md +213 -0
- package/browser/873e754d6c7c6e9361f1.module.wasm +0 -0
- package/browser/_version.d.ts +1 -0
- package/browser/bytecode/Compressor.d.ts +6 -0
- package/browser/crypto/crypto-browser.d.ts +40 -0
- package/browser/crypto/crypto.d.ts +2 -0
- package/browser/generators/Generator.d.ts +12 -0
- package/browser/generators/builders/CalldataGenerator.d.ts +8 -0
- package/browser/generators/builders/DeploymentGenerator.d.ts +7 -0
- package/browser/index.d.ts +3 -0
- package/browser/index.js +2 -0
- package/browser/index.js.LICENSE.txt +23 -0
- package/browser/keypair/EcKeyPair.d.ts +24 -0
- package/browser/keypair/Wallet.d.ts +16 -0
- package/browser/keypair/interfaces/IWallet.d.ts +5 -0
- package/browser/metadata/ContractBaseMetadata.d.ts +9 -0
- package/browser/metadata/ContractMetadataManager.d.ts +1 -0
- package/browser/metadata/contracts/wBTC.d.ts +12 -0
- package/browser/network/NetworkInformation.d.ts +6 -0
- package/browser/opnet.d.ts +22 -0
- package/browser/scripts/Regtest.d.ts +2 -0
- package/browser/scripts/test.d.ts +1 -0
- package/browser/signer/TweakedSigner.d.ts +9 -0
- package/browser/transaction/TransactionBuilder.d.ts +1 -0
- package/browser/transaction/TransactionFactory.d.ts +4 -0
- package/browser/transaction/builders/FundingTransaction.d.ts +11 -0
- package/browser/transaction/builders/InteractionTransaction.d.ts +47 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +64 -0
- package/browser/transaction/enums/TransactionType.d.ts +7 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +33 -0
- package/browser/transaction/interfaces/Tap.d.ts +22 -0
- package/browser/utils/BitcoinUtils.d.ts +5 -0
- package/browser/utxo/UTXOManager.d.ts +7 -0
- package/browser/utxo/interfaces/IUTXO.d.ts +19 -0
- package/build/Utils.d.ts +0 -0
- package/build/Utils.js +1 -0
- package/build/_version.d.ts +1 -0
- package/build/_version.js +1 -0
- package/build/bytecode/Compressor.d.ts +6 -0
- package/build/bytecode/Compressor.js +13 -0
- package/build/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/contracts/ContractMetadataManager.js +1 -0
- package/build/crypto/crypto.d.ts +2 -0
- package/build/crypto/crypto.js +1 -0
- package/build/generators/Generator.d.ts +12 -0
- package/build/generators/Generator.js +25 -0
- package/build/generators/builders/CalldataGenerator.d.ts +8 -0
- package/build/generators/builders/CalldataGenerator.js +79 -0
- package/build/generators/builders/DeploymentGenerator.d.ts +7 -0
- package/build/generators/builders/DeploymentGenerator.js +38 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +3 -0
- package/build/keypair/EcKeyPair.d.ts +24 -0
- package/build/keypair/EcKeyPair.js +107 -0
- package/build/keypair/Wallet.d.ts +16 -0
- package/build/keypair/Wallet.js +30 -0
- package/build/keypair/interfaces/GeneratedWallet.d.ts +5 -0
- package/build/keypair/interfaces/GeneratedWallet.js +1 -0
- package/build/keypair/interfaces/IWallet.d.ts +5 -0
- package/build/keypair/interfaces/IWallet.js +1 -0
- package/build/metadata/ContractBaseMetadata.d.ts +9 -0
- package/build/metadata/ContractBaseMetadata.js +13 -0
- package/build/metadata/ContractMetadataManager.d.ts +1 -0
- package/build/metadata/ContractMetadataManager.js +9 -0
- package/build/metadata/contracts/ContractBase.d.ts +9 -0
- package/build/metadata/contracts/ContractBase.js +13 -0
- package/build/metadata/contracts/ContractBaseMetadata.d.ts +9 -0
- package/build/metadata/contracts/ContractBaseMetadata.js +13 -0
- package/build/metadata/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/metadata/contracts/ContractMetadataManager.js +1 -0
- package/build/metadata/contracts/wBTC.d.ts +12 -0
- package/build/metadata/contracts/wBTC.js +26 -0
- package/build/network/NetworkConverter.d.ts +0 -0
- package/build/network/NetworkConverter.js +14 -0
- package/build/network/NetworkInformation.d.ts +6 -0
- package/build/network/NetworkInformation.js +1 -0
- package/build/opnet.d.ts +22 -0
- package/build/opnet.js +22 -0
- package/build/scripts/Regtest.d.ts +2 -0
- package/build/scripts/Regtest.js +15 -0
- package/build/scripts/test.d.ts +1 -0
- package/build/scripts/test.js +74 -0
- package/build/signer/Regtest.d.ts +2 -0
- package/build/signer/Regtest.js +15 -0
- package/build/signer/TweakedSigner.d.ts +9 -0
- package/build/signer/TweakedSigner.js +22 -0
- package/build/transaction/TransactionBuilder.d.ts +60 -0
- package/build/transaction/TransactionBuilder.js +244 -0
- package/build/transaction/TransactionFactory.d.ts +4 -0
- package/build/transaction/TransactionFactory.js +32 -0
- package/build/transaction/builders/FundingTransaction.d.ts +11 -0
- package/build/transaction/builders/FundingTransaction.js +23 -0
- package/build/transaction/builders/GenericTransaction.d.ts +11 -0
- package/build/transaction/builders/GenericTransaction.js +23 -0
- package/build/transaction/builders/InteractionTransaction.d.ts +47 -0
- package/build/transaction/builders/InteractionTransaction.js +219 -0
- package/build/transaction/builders/TransactionBuilder.d.ts +64 -0
- package/build/transaction/builders/TransactionBuilder.js +288 -0
- package/build/transaction/enums/TransactionType.d.ts +7 -0
- package/build/transaction/enums/TransactionType.js +8 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +33 -0
- package/build/transaction/interfaces/ITransactionParameters.js +1 -0
- package/build/transaction/interfaces/ITransactions.d.ts +32 -0
- package/build/transaction/interfaces/ITransactions.js +1 -0
- package/build/transaction/interfaces/Tap.d.ts +22 -0
- package/build/transaction/interfaces/Tap.js +1 -0
- package/build/utils/BitcoinUtils.d.ts +5 -0
- package/build/utils/BitcoinUtils.js +9 -0
- package/build/utxo/IUTXO.d.ts +0 -0
- package/build/utxo/IUTXO.js +1 -0
- package/build/utxo/UTXOManager.d.ts +7 -0
- package/build/utxo/UTXOManager.js +47 -0
- package/build/utxo/interfaces/IUTXO.d.ts +19 -0
- package/build/utxo/interfaces/IUTXO.js +1 -0
- package/cjs/_version.d.ts +1 -0
- package/cjs/_version.js +4 -0
- package/cjs/bytecode/Compressor.d.ts +6 -0
- package/cjs/bytecode/Compressor.js +20 -0
- package/cjs/crypto/crypto.d.ts +2 -0
- package/cjs/crypto/crypto.js +8 -0
- package/cjs/generators/Generator.d.ts +13 -0
- package/cjs/generators/Generator.js +31 -0
- package/cjs/generators/builders/CalldataGenerator.d.ts +8 -0
- package/cjs/generators/builders/CalldataGenerator.js +83 -0
- package/cjs/generators/builders/DeploymentGenerator.d.ts +7 -0
- package/cjs/generators/builders/DeploymentGenerator.js +42 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +32 -0
- package/cjs/keypair/EcKeyPair.d.ts +24 -0
- package/cjs/keypair/EcKeyPair.js +137 -0
- package/cjs/keypair/Wallet.d.ts +16 -0
- package/cjs/keypair/Wallet.js +34 -0
- package/cjs/keypair/interfaces/IWallet.d.ts +5 -0
- package/cjs/keypair/interfaces/IWallet.js +2 -0
- package/cjs/metadata/ContractBaseMetadata.d.ts +9 -0
- package/cjs/metadata/ContractBaseMetadata.js +17 -0
- package/cjs/metadata/ContractMetadataManager.d.ts +0 -0
- package/cjs/metadata/ContractMetadataManager.js +1 -0
- package/cjs/metadata/contracts/wBTC.d.ts +12 -0
- package/cjs/metadata/contracts/wBTC.js +30 -0
- package/cjs/network/NetworkInformation.d.ts +6 -0
- package/cjs/network/NetworkInformation.js +2 -0
- package/cjs/opnet.d.ts +1 -0
- package/cjs/opnet.js +5 -0
- package/cjs/scripts/Regtest.d.ts +2 -0
- package/cjs/scripts/Regtest.js +18 -0
- package/cjs/scripts/test.d.ts +1 -0
- package/cjs/scripts/test.js +44 -0
- package/cjs/signer/TweakedSigner.d.ts +9 -0
- package/cjs/signer/TweakedSigner.js +49 -0
- package/cjs/transaction/TransactionBuilder.d.ts +0 -0
- package/cjs/transaction/TransactionBuilder.js +1 -0
- package/cjs/transaction/TransactionFactory.d.ts +4 -0
- package/cjs/transaction/TransactionFactory.js +33 -0
- package/cjs/transaction/builders/FundingTransaction.d.ts +11 -0
- package/cjs/transaction/builders/FundingTransaction.js +27 -0
- package/cjs/transaction/builders/InteractionTransaction.d.ts +45 -0
- package/cjs/transaction/builders/InteractionTransaction.js +214 -0
- package/cjs/transaction/builders/TransactionBuilder.d.ts +64 -0
- package/cjs/transaction/builders/TransactionBuilder.js +304 -0
- package/cjs/transaction/enums/TransactionType.d.ts +7 -0
- package/cjs/transaction/enums/TransactionType.js +11 -0
- package/cjs/transaction/interfaces/ITransactionParameters.d.ts +32 -0
- package/cjs/transaction/interfaces/ITransactionParameters.js +2 -0
- package/cjs/transaction/interfaces/Tap.d.ts +22 -0
- package/cjs/transaction/interfaces/Tap.js +2 -0
- package/cjs/utils/BitcoinUtils.d.ts +5 -0
- package/cjs/utils/BitcoinUtils.js +13 -0
- package/cjs/utxo/UTXOManager.d.ts +7 -0
- package/cjs/utxo/UTXOManager.js +51 -0
- package/cjs/utxo/interfaces/IUTXO.d.ts +19 -0
- package/cjs/utxo/interfaces/IUTXO.js +2 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/icons.js +15 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/material-style.css +247 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1412 -0
- package/docs/classes/BitcoinUtils.html +183 -0
- package/docs/classes/CalldataGenerator.html +211 -0
- package/docs/classes/Compressor.html +185 -0
- package/docs/classes/ContractBaseMetadata.html +182 -0
- package/docs/classes/DeploymentGenerator.html +200 -0
- package/docs/classes/EcKeyPair.html +280 -0
- package/docs/classes/FundingTransaction.html +293 -0
- package/docs/classes/Generator.html +199 -0
- package/docs/classes/InteractionTransaction.html +365 -0
- package/docs/classes/TransactionBuilder.html +303 -0
- package/docs/classes/TransactionFactory.html +180 -0
- package/docs/classes/TweakedSigner.html +181 -0
- package/docs/classes/UTXOManager.html +187 -0
- package/docs/classes/Wallet.html +191 -0
- package/docs/classes/wBTC.html +189 -0
- package/docs/enums/TransactionType.html +179 -0
- package/docs/hierarchy.html +174 -0
- package/docs/index.html +237 -0
- package/docs/interfaces/FetchUTXOParams.html +178 -0
- package/docs/interfaces/IFundingTransactionParameters.html +182 -0
- package/docs/interfaces/IInteractionParameters.html +185 -0
- package/docs/interfaces/ITransactionDataContractDeployment.html +184 -0
- package/docs/interfaces/ITransactionDataContractInteractionWrap.html +186 -0
- package/docs/interfaces/ITransactionParameters.html +181 -0
- package/docs/interfaces/IWallet.html +181 -0
- package/docs/interfaces/NetworkInformation.html +176 -0
- package/docs/interfaces/PsbtInputExtended.html +194 -0
- package/docs/interfaces/PsbtOutputExtendedAddress.html +183 -0
- package/docs/interfaces/PsbtOutputExtendedScript.html +183 -0
- package/docs/interfaces/RawUTXOResponse.html +178 -0
- package/docs/interfaces/TapLeafScript.html +177 -0
- package/docs/interfaces/TweakSettings.html +179 -0
- package/docs/interfaces/UTXO.html +178 -0
- package/docs/interfaces/UpdateInput.html +175 -0
- package/docs/modules.html +208 -0
- package/docs/types/PsbtOutputExtended.html +174 -0
- package/docs/variables/version.html +174 -0
- package/gulpfile.js +152 -0
- package/jest.config.ts +52 -0
- package/package.json +116 -0
- package/src/_version.ts +1 -0
- package/src/bytecode/Compressor.ts +27 -0
- package/src/crypto/crypto-browser.js +71 -0
- package/src/crypto/crypto.ts +1 -0
- package/src/generators/Generator.ts +75 -0
- package/src/generators/builders/CalldataGenerator.ts +143 -0
- package/src/generators/builders/DeploymentGenerator.ts +63 -0
- package/src/index.ts +4 -0
- package/src/keypair/EcKeyPair.ts +265 -0
- package/src/keypair/Wallet.ts +75 -0
- package/src/keypair/interfaces/IWallet.ts +19 -0
- package/src/metadata/ContractBaseMetadata.ts +23 -0
- package/src/metadata/contracts/wBTC.ts +44 -0
- package/src/network/NetworkInformation.ts +7 -0
- package/src/opnet.ts +42 -0
- package/src/scripts/Regtest.ts +19 -0
- package/src/scripts/test.ts +98 -0
- package/src/signer/TweakedSigner.ts +57 -0
- package/src/transaction/TransactionFactory.ts +57 -0
- package/src/transaction/builders/FundingTransaction.ts +36 -0
- package/src/transaction/builders/InteractionTransaction.ts +439 -0
- package/src/transaction/builders/TransactionBuilder.ts +603 -0
- package/src/transaction/enums/TransactionType.ts +7 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +41 -0
- package/src/transaction/interfaces/Tap.ts +26 -0
- package/src/utils/BitcoinUtils.ts +24 -0
- package/src/utxo/UTXOManager.ts +67 -0
- package/src/utxo/interfaces/IUTXO.ts +22 -0
- package/tests/TransactionBuilder.test.ts +58 -0
- package/tests/contracts/wbtc.wasm +0 -0
- package/tsconfig.base.json +43 -0
- package/tsconfig.cjs.json +9 -0
- package/tsconfig.json +8 -0
- package/tsconfig.webpack.json +11 -0
- package/webpack.config.js +77 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalldataGenerator = void 0;
|
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
|
+
const Compressor_js_1 = require("../../bytecode/Compressor.js");
|
|
6
|
+
const Generator_js_1 = require("../Generator.js");
|
|
7
|
+
const EcKeyPair_js_1 = require("../../keypair/EcKeyPair.js");
|
|
8
|
+
class CalldataGenerator extends Generator_js_1.Generator {
|
|
9
|
+
constructor(senderPubKey, contractSaltPubKey, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
10
|
+
super(senderPubKey, contractSaltPubKey, network);
|
|
11
|
+
}
|
|
12
|
+
compile(calldata, contractSecret, vaultPublicKeys = [], minimumSignatures = 0) {
|
|
13
|
+
const dataChunks = this.splitBufferIntoChunks(calldata);
|
|
14
|
+
if (!dataChunks.length)
|
|
15
|
+
throw new Error('No data chunks found');
|
|
16
|
+
let compiledData = [
|
|
17
|
+
this.senderPubKey,
|
|
18
|
+
bitcoinjs_lib_1.opcodes.OP_CHECKSIGVERIFY,
|
|
19
|
+
this.contractSaltPubKey,
|
|
20
|
+
bitcoinjs_lib_1.opcodes.OP_CHECKSIGVERIFY,
|
|
21
|
+
bitcoinjs_lib_1.opcodes.OP_HASH160,
|
|
22
|
+
bitcoinjs_lib_1.crypto.hash160(this.senderPubKey),
|
|
23
|
+
bitcoinjs_lib_1.opcodes.OP_EQUALVERIFY,
|
|
24
|
+
bitcoinjs_lib_1.opcodes.OP_HASH160,
|
|
25
|
+
bitcoinjs_lib_1.crypto.hash160(contractSecret),
|
|
26
|
+
bitcoinjs_lib_1.opcodes.OP_EQUALVERIFY,
|
|
27
|
+
bitcoinjs_lib_1.opcodes.OP_DEPTH,
|
|
28
|
+
bitcoinjs_lib_1.opcodes.OP_1,
|
|
29
|
+
bitcoinjs_lib_1.opcodes.OP_NUMEQUAL,
|
|
30
|
+
bitcoinjs_lib_1.opcodes.OP_IF,
|
|
31
|
+
Generator_js_1.Generator.MAGIC,
|
|
32
|
+
];
|
|
33
|
+
if (vaultPublicKeys.length > 0) {
|
|
34
|
+
const pubKeyBuffer = this.getPubKeyAsBuffer(vaultPublicKeys);
|
|
35
|
+
const pubKeyDataChunks = this.splitBufferIntoChunks(pubKeyBuffer);
|
|
36
|
+
compiledData = compiledData.concat(...[
|
|
37
|
+
bitcoinjs_lib_1.opcodes.OP_0,
|
|
38
|
+
...pubKeyDataChunks,
|
|
39
|
+
]);
|
|
40
|
+
if (minimumSignatures) {
|
|
41
|
+
if (minimumSignatures > 255) {
|
|
42
|
+
throw new Error('Minimum signatures cannot exceed 255');
|
|
43
|
+
}
|
|
44
|
+
const minSigBuffer = Buffer.alloc(2);
|
|
45
|
+
minSigBuffer.writeUint16LE(minimumSignatures, 0);
|
|
46
|
+
compiledData = compiledData.concat(...[
|
|
47
|
+
bitcoinjs_lib_1.opcodes.OP_1,
|
|
48
|
+
minSigBuffer,
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('Minimum signatures must be provided');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
compiledData = compiledData.concat(...[bitcoinjs_lib_1.opcodes.OP_1NEGATE, ...dataChunks, bitcoinjs_lib_1.opcodes.OP_ELSE, bitcoinjs_lib_1.opcodes.OP_1, bitcoinjs_lib_1.opcodes.OP_ENDIF]);
|
|
56
|
+
const asm = compiledData.flat();
|
|
57
|
+
const compiled = bitcoinjs_lib_1.script.compile(asm);
|
|
58
|
+
const decompiled = bitcoinjs_lib_1.script.decompile(compiled);
|
|
59
|
+
if (!decompiled) {
|
|
60
|
+
throw new Error('Failed to decompile script??');
|
|
61
|
+
}
|
|
62
|
+
return compiled;
|
|
63
|
+
}
|
|
64
|
+
getPubKeyAsBuffer(witnessKeys) {
|
|
65
|
+
let finalBuffer = Buffer.alloc(0);
|
|
66
|
+
for (let pubKey of witnessKeys) {
|
|
67
|
+
const key = EcKeyPair_js_1.EcKeyPair.fromPublicKey(pubKey, this.network);
|
|
68
|
+
if (!key.compressed) {
|
|
69
|
+
throw new Error('Public key must be compressed');
|
|
70
|
+
}
|
|
71
|
+
if (pubKey.byteLength !== 33) {
|
|
72
|
+
throw new Error(`Public key must be 33 bytes, got ${pubKey.byteLength} bytes.`);
|
|
73
|
+
}
|
|
74
|
+
finalBuffer = Buffer.concat([finalBuffer, pubKey]);
|
|
75
|
+
}
|
|
76
|
+
const compressed = Compressor_js_1.Compressor.compress(finalBuffer);
|
|
77
|
+
if (compressed.byteLength >= finalBuffer.byteLength) {
|
|
78
|
+
return finalBuffer;
|
|
79
|
+
}
|
|
80
|
+
return compressed;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.CalldataGenerator = CalldataGenerator;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Network } from 'bitcoinjs-lib';
|
|
3
|
+
import { Generator } from '../Generator.js';
|
|
4
|
+
export declare class DeploymentGenerator extends Generator {
|
|
5
|
+
constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
|
|
6
|
+
compile(contractBytecode: Buffer, contractSalt: Buffer): Buffer;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeploymentGenerator = void 0;
|
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
|
+
const Generator_js_1 = require("../Generator.js");
|
|
6
|
+
class DeploymentGenerator extends Generator_js_1.Generator {
|
|
7
|
+
constructor(senderPubKey, contractSaltPubKey, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
8
|
+
super(senderPubKey, contractSaltPubKey, network);
|
|
9
|
+
}
|
|
10
|
+
compile(contractBytecode, contractSalt) {
|
|
11
|
+
const dataChunks = this.splitBufferIntoChunks(contractBytecode);
|
|
12
|
+
const asm = [
|
|
13
|
+
this.senderPubKey,
|
|
14
|
+
bitcoinjs_lib_1.opcodes.OP_CHECKSIGVERIFY,
|
|
15
|
+
this.contractSaltPubKey,
|
|
16
|
+
bitcoinjs_lib_1.opcodes.OP_CHECKSIGVERIFY,
|
|
17
|
+
bitcoinjs_lib_1.opcodes.OP_HASH160,
|
|
18
|
+
bitcoinjs_lib_1.crypto.hash160(this.senderPubKey),
|
|
19
|
+
bitcoinjs_lib_1.opcodes.OP_EQUALVERIFY,
|
|
20
|
+
bitcoinjs_lib_1.opcodes.OP_HASH256,
|
|
21
|
+
bitcoinjs_lib_1.crypto.hash256(contractSalt),
|
|
22
|
+
bitcoinjs_lib_1.opcodes.OP_EQUALVERIFY,
|
|
23
|
+
bitcoinjs_lib_1.opcodes.OP_DEPTH,
|
|
24
|
+
bitcoinjs_lib_1.opcodes.OP_1,
|
|
25
|
+
bitcoinjs_lib_1.opcodes.OP_NUMEQUAL,
|
|
26
|
+
bitcoinjs_lib_1.opcodes.OP_IF,
|
|
27
|
+
Generator_js_1.Generator.MAGIC,
|
|
28
|
+
bitcoinjs_lib_1.opcodes.OP_1NEGATE,
|
|
29
|
+
...dataChunks,
|
|
30
|
+
bitcoinjs_lib_1.opcodes.OP_ELSE,
|
|
31
|
+
bitcoinjs_lib_1.opcodes.OP_1,
|
|
32
|
+
bitcoinjs_lib_1.opcodes.OP_ENDIF,
|
|
33
|
+
].flat();
|
|
34
|
+
const compiled = bitcoinjs_lib_1.script.compile(asm);
|
|
35
|
+
const decompiled = bitcoinjs_lib_1.script.decompile(compiled);
|
|
36
|
+
if (!decompiled) {
|
|
37
|
+
throw new Error('Failed to decompile script??');
|
|
38
|
+
}
|
|
39
|
+
return compiled;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.DeploymentGenerator = DeploymentGenerator;
|
package/cjs/index.d.ts
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.opnet = void 0;
|
|
30
|
+
const opnet = __importStar(require("./opnet.js"));
|
|
31
|
+
exports.opnet = opnet;
|
|
32
|
+
__exportStar(require("./opnet.js"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BIP32Interface } from 'bip32';
|
|
3
|
+
import { Network } from 'bitcoinjs-lib';
|
|
4
|
+
import { ECPairInterface } from 'ecpair';
|
|
5
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
import { IWallet } from './interfaces/IWallet.js';
|
|
7
|
+
export declare class EcKeyPair {
|
|
8
|
+
static BIP32: any;
|
|
9
|
+
static ECPair: import("ecpair").ECPairAPI;
|
|
10
|
+
static fromWIF(wif: string, network?: Network): ECPairInterface;
|
|
11
|
+
static fromPrivateKey(privateKey: Buffer, network?: Network): ECPairInterface;
|
|
12
|
+
static fromPublicKey(publicKey: Buffer, network?: Network): ECPairInterface;
|
|
13
|
+
static generateMultiSigAddress(pubKeys: Buffer[], minimumSignatureRequired: number, network?: Network): Address;
|
|
14
|
+
static verifyPubKeys(pubKeys: Buffer[], network?: Network): Buffer[];
|
|
15
|
+
static getP2WPKHAddress(keyPair: ECPairInterface, network?: Network): Address;
|
|
16
|
+
static generateWallet(network?: Network): IWallet;
|
|
17
|
+
static verifyContractAddress(contractAddress: Address, network?: Network): boolean;
|
|
18
|
+
static getLegacyAddress(keyPair: ECPairInterface, network?: Network): Address;
|
|
19
|
+
static generateRandomKeyPair(network?: Network): ECPairInterface;
|
|
20
|
+
static fromSeed(seed: Buffer, network?: Network): BIP32Interface;
|
|
21
|
+
static getTaprootAddress(keyPair: ECPairInterface, network?: Network): Address;
|
|
22
|
+
static getTaprootAddressFromAddress(inAddr: Address, network?: Network): Address;
|
|
23
|
+
static fromSeedKeyPair(seed: Buffer, network?: Network): ECPairInterface;
|
|
24
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.EcKeyPair = void 0;
|
|
30
|
+
const bip32_1 = __importDefault(require("bip32"));
|
|
31
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
32
|
+
const ecpair_1 = require("ecpair");
|
|
33
|
+
const ecc = __importStar(require("tiny-secp256k1"));
|
|
34
|
+
(0, bitcoinjs_lib_1.initEccLib)(ecc);
|
|
35
|
+
const BIP32Factory = typeof bip32_1.default === 'function' ? bip32_1.default : bip32_1.default.BIP32Factory;
|
|
36
|
+
class EcKeyPair {
|
|
37
|
+
static BIP32 = BIP32Factory(ecc);
|
|
38
|
+
static ECPair = (0, ecpair_1.ECPairFactory)(ecc);
|
|
39
|
+
static fromWIF(wif, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
40
|
+
return this.ECPair.fromWIF(wif, network);
|
|
41
|
+
}
|
|
42
|
+
static fromPrivateKey(privateKey, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
43
|
+
return this.ECPair.fromPrivateKey(privateKey, { network });
|
|
44
|
+
}
|
|
45
|
+
static fromPublicKey(publicKey, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
46
|
+
return this.ECPair.fromPublicKey(publicKey, { network });
|
|
47
|
+
}
|
|
48
|
+
static generateMultiSigAddress(pubKeys, minimumSignatureRequired, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
49
|
+
const publicKeys = this.verifyPubKeys(pubKeys, network);
|
|
50
|
+
const { address } = bitcoinjs_lib_1.payments.p2wsh({
|
|
51
|
+
redeem: bitcoinjs_lib_1.payments.p2ms({
|
|
52
|
+
m: minimumSignatureRequired,
|
|
53
|
+
pubkeys: publicKeys,
|
|
54
|
+
network: network,
|
|
55
|
+
}),
|
|
56
|
+
network: network,
|
|
57
|
+
});
|
|
58
|
+
if (!address) {
|
|
59
|
+
throw new Error('Failed to generate address');
|
|
60
|
+
}
|
|
61
|
+
return address;
|
|
62
|
+
}
|
|
63
|
+
static verifyPubKeys(pubKeys, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
64
|
+
return pubKeys.map((pubKey) => {
|
|
65
|
+
const key = EcKeyPair.fromPublicKey(pubKey, network);
|
|
66
|
+
if (!key) {
|
|
67
|
+
throw new Error('Failed to regenerate key');
|
|
68
|
+
}
|
|
69
|
+
return key.publicKey;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
static getP2WPKHAddress(keyPair, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
73
|
+
const res = bitcoinjs_lib_1.payments.p2wpkh({ pubkey: keyPair.publicKey, network: network });
|
|
74
|
+
if (!res.address) {
|
|
75
|
+
throw new Error('Failed to generate wallet');
|
|
76
|
+
}
|
|
77
|
+
return res.address;
|
|
78
|
+
}
|
|
79
|
+
static generateWallet(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
80
|
+
const keyPair = this.ECPair.makeRandom({
|
|
81
|
+
network: network,
|
|
82
|
+
});
|
|
83
|
+
const wallet = this.getP2WPKHAddress(keyPair, network);
|
|
84
|
+
if (!wallet) {
|
|
85
|
+
throw new Error('Failed to generate wallet');
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
address: wallet,
|
|
89
|
+
privateKey: keyPair.toWIF(),
|
|
90
|
+
publicKey: keyPair.publicKey.toString('hex'),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
static verifyContractAddress(contractAddress, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
94
|
+
return !!bitcoinjs_lib_1.address.toOutputScript(contractAddress, network);
|
|
95
|
+
}
|
|
96
|
+
static getLegacyAddress(keyPair, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
97
|
+
const wallet = bitcoinjs_lib_1.payments.p2pkh({ pubkey: keyPair.publicKey, network: network });
|
|
98
|
+
if (!wallet.address) {
|
|
99
|
+
throw new Error('Failed to generate wallet');
|
|
100
|
+
}
|
|
101
|
+
return wallet.address;
|
|
102
|
+
}
|
|
103
|
+
static generateRandomKeyPair(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
104
|
+
return this.ECPair.makeRandom({
|
|
105
|
+
network: network,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
static fromSeed(seed, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
109
|
+
return this.BIP32.fromSeed(seed, network);
|
|
110
|
+
}
|
|
111
|
+
static getTaprootAddress(keyPair, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
112
|
+
const myXOnlyPubkey = keyPair.publicKey.slice(1, 33);
|
|
113
|
+
const output = Buffer.concat([
|
|
114
|
+
Buffer.from([0x51, 0x20]),
|
|
115
|
+
myXOnlyPubkey,
|
|
116
|
+
]);
|
|
117
|
+
return bitcoinjs_lib_1.address.fromOutputScript(output, network);
|
|
118
|
+
}
|
|
119
|
+
static getTaprootAddressFromAddress(inAddr, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
120
|
+
const { address } = bitcoinjs_lib_1.payments.p2tr({
|
|
121
|
+
address: inAddr,
|
|
122
|
+
network: network,
|
|
123
|
+
});
|
|
124
|
+
if (!address) {
|
|
125
|
+
throw new Error(`Failed to generate sender address for transaction`);
|
|
126
|
+
}
|
|
127
|
+
return address;
|
|
128
|
+
}
|
|
129
|
+
static fromSeedKeyPair(seed, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
130
|
+
const fromSeed = this.BIP32.fromSeed(seed, network);
|
|
131
|
+
const privKey = fromSeed.privateKey;
|
|
132
|
+
if (!privKey)
|
|
133
|
+
throw new Error('Failed to generate key pair');
|
|
134
|
+
return this.ECPair.fromPrivateKey(privKey, { network });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.EcKeyPair = EcKeyPair;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IWallet } from './interfaces/IWallet.js';
|
|
3
|
+
import { ECPairInterface } from 'ecpair';
|
|
4
|
+
import { Network } from 'bitcoinjs-lib';
|
|
5
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
export declare class Wallet {
|
|
7
|
+
readonly network: Network;
|
|
8
|
+
private readonly _keypair;
|
|
9
|
+
private readonly _p2wpkh;
|
|
10
|
+
private readonly _p2tr;
|
|
11
|
+
constructor(wallet: IWallet, network?: Network);
|
|
12
|
+
get keypair(): ECPairInterface;
|
|
13
|
+
get p2wpkh(): Address;
|
|
14
|
+
get p2tr(): Address;
|
|
15
|
+
get publicKey(): Buffer;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Wallet = void 0;
|
|
4
|
+
const EcKeyPair_js_1 = require("./EcKeyPair.js");
|
|
5
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
6
|
+
class Wallet {
|
|
7
|
+
network;
|
|
8
|
+
_keypair;
|
|
9
|
+
_p2wpkh;
|
|
10
|
+
_p2tr;
|
|
11
|
+
constructor(wallet, network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
12
|
+
this.network = network;
|
|
13
|
+
this._keypair = EcKeyPair_js_1.EcKeyPair.fromWIF(wallet.privateKey, this.network);
|
|
14
|
+
this._p2wpkh = EcKeyPair_js_1.EcKeyPair.getP2WPKHAddress(this._keypair, this.network);
|
|
15
|
+
this._p2tr = EcKeyPair_js_1.EcKeyPair.getTaprootAddress(this._keypair, this.network);
|
|
16
|
+
}
|
|
17
|
+
get keypair() {
|
|
18
|
+
if (!this._keypair)
|
|
19
|
+
throw new Error('Keypair not set');
|
|
20
|
+
return this._keypair;
|
|
21
|
+
}
|
|
22
|
+
get p2wpkh() {
|
|
23
|
+
return this._p2wpkh;
|
|
24
|
+
}
|
|
25
|
+
get p2tr() {
|
|
26
|
+
return this._p2tr;
|
|
27
|
+
}
|
|
28
|
+
get publicKey() {
|
|
29
|
+
if (!this.keypair)
|
|
30
|
+
throw new Error('Keypair not set');
|
|
31
|
+
return this.keypair.publicKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Wallet = Wallet;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { Network } from 'bitcoinjs-lib';
|
|
3
|
+
export declare abstract class ContractBaseMetadata {
|
|
4
|
+
protected network: Network;
|
|
5
|
+
protected abstract readonly address: Address;
|
|
6
|
+
protected constructor(network?: Network);
|
|
7
|
+
static getAddress(network?: Network): Address;
|
|
8
|
+
getAddress(): Address;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContractBaseMetadata = void 0;
|
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
|
+
class ContractBaseMetadata {
|
|
6
|
+
network;
|
|
7
|
+
constructor(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
8
|
+
this.network = network;
|
|
9
|
+
}
|
|
10
|
+
static getAddress(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
11
|
+
throw new Error('Method not implemented.');
|
|
12
|
+
}
|
|
13
|
+
getAddress() {
|
|
14
|
+
return this.address;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ContractBaseMetadata = ContractBaseMetadata;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
3
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
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: Address;
|
|
10
|
+
constructor(network?: Network);
|
|
11
|
+
static getAddress(network?: Network): Address;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wBTC = void 0;
|
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
|
+
const ContractBaseMetadata_js_1 = require("../ContractBaseMetadata.js");
|
|
6
|
+
class wBTC extends ContractBaseMetadata_js_1.ContractBaseMetadata {
|
|
7
|
+
network;
|
|
8
|
+
tokenName = 'Wrapped Bitcoin';
|
|
9
|
+
tokenSymbol = 'wBTC';
|
|
10
|
+
decimals = 8;
|
|
11
|
+
address;
|
|
12
|
+
constructor(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
13
|
+
super(network);
|
|
14
|
+
this.network = network;
|
|
15
|
+
this.address = wBTC.getAddress(network);
|
|
16
|
+
}
|
|
17
|
+
static getAddress(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
18
|
+
switch (network) {
|
|
19
|
+
case bitcoinjs_lib_1.networks.bitcoin:
|
|
20
|
+
return 'bcrt1pcw0828yjrtlrc6mkp3lkq30j7wc7slsh7k7dyh53mrs4f8d74l6qumhqp4';
|
|
21
|
+
case bitcoinjs_lib_1.networks.regtest:
|
|
22
|
+
return 'bcrt1pcw0828yjrtlrc6mkp3lkq30j7wc7slsh7k7dyh53mrs4f8d74l6qumhqp4';
|
|
23
|
+
case bitcoinjs_lib_1.networks.testnet:
|
|
24
|
+
return 'tb1pq64lx73fwyrdp4asvl7xt5r5qvxvt9wy82x75taqtzvd64f58nasansurj';
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Invalid network: ${network}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.wBTC = wBTC;
|
package/cjs/opnet.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { version } from './_version.js';
|
package/cjs/opnet.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.version = void 0;
|
|
4
|
+
var _version_js_1 = require("./_version.js");
|
|
5
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return _version_js_1.version; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Regtest = void 0;
|
|
4
|
+
const NetworkInformation_js_1 = require("../network/NetworkInformation.js");
|
|
5
|
+
exports.Regtest = {
|
|
6
|
+
wallet: {
|
|
7
|
+
address: 'bcrt1qfqsr3m7vjxheghcvw4ks0fryqxfq8qzjf8fxes',
|
|
8
|
+
publicKey: '020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c',
|
|
9
|
+
privateKey: 'cRCiYAgCBrU7hSaJBRuPqKVYXQqM5CKXbMfWHb25X4FDAWJ8Ai92',
|
|
10
|
+
},
|
|
11
|
+
config: {
|
|
12
|
+
BITCOIND_NETWORK: NetworkInformation_js_1.Chains.REGTEST,
|
|
13
|
+
BITCOIND_HOST: '51.81.67.34',
|
|
14
|
+
BITCOIND_PORT: 9242,
|
|
15
|
+
BITCOIND_USERNAME: 'HJSiowseujhs',
|
|
16
|
+
BITCOIND_PASSWORD: 'YHEFHSDJ23JOIhjjef2ied9u290efu2930u90U',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const wBTC_js_1 = require("../metadata/contracts/wBTC.js");
|
|
4
|
+
const Wallet_js_1 = require("../keypair/Wallet.js");
|
|
5
|
+
const Regtest_js_1 = require("./Regtest.js");
|
|
6
|
+
const UTXOManager_js_1 = require("../utxo/UTXOManager.js");
|
|
7
|
+
const logger_1 = require("@btc-vision/logger");
|
|
8
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
9
|
+
const TransactionFactory_js_1 = require("../transaction/TransactionFactory.js");
|
|
10
|
+
const bsi_bitcoin_rpc_1 = require("@btc-vision/bsi-bitcoin-rpc");
|
|
11
|
+
const logger = new logger_1.Logger();
|
|
12
|
+
const network = bitcoinjs_lib_1.networks.regtest;
|
|
13
|
+
const rpc = new bsi_bitcoin_rpc_1.BitcoinRPC();
|
|
14
|
+
const wBtc = new wBTC_js_1.wBTC(network);
|
|
15
|
+
const wallet = new Wallet_js_1.Wallet(Regtest_js_1.Regtest.wallet, network);
|
|
16
|
+
logger.log(`Loaded wallet: ${wallet.p2tr} - ${wallet.p2wpkh}`);
|
|
17
|
+
const utxoManager = new UTXOManager_js_1.UTXOManager('http://localhost:9001');
|
|
18
|
+
const factory = new TransactionFactory_js_1.TransactionFactory();
|
|
19
|
+
(async () => {
|
|
20
|
+
await rpc.init(Regtest_js_1.Regtest.config);
|
|
21
|
+
const utxoSetting = {
|
|
22
|
+
address: wallet.p2wpkh,
|
|
23
|
+
minAmount: 10000n,
|
|
24
|
+
requestedAmount: 100000n,
|
|
25
|
+
};
|
|
26
|
+
const utxos = await utxoManager.fetchUTXO(utxoSetting);
|
|
27
|
+
console.log(`UTXOs:`, utxos);
|
|
28
|
+
if (!utxos) {
|
|
29
|
+
throw new Error('No UTXOs found');
|
|
30
|
+
}
|
|
31
|
+
logger.log(`UTXOs fetched. Count: ${utxos.length}`);
|
|
32
|
+
const interactionParameters = {
|
|
33
|
+
from: wallet.p2wpkh,
|
|
34
|
+
to: wBtc.getAddress(),
|
|
35
|
+
utxos: utxos,
|
|
36
|
+
signer: wallet.keypair,
|
|
37
|
+
network: network,
|
|
38
|
+
feeRate: 150,
|
|
39
|
+
priorityFee: 500n,
|
|
40
|
+
calldata: Buffer.from('test'),
|
|
41
|
+
};
|
|
42
|
+
const finalTx = factory.signInteraction(interactionParameters);
|
|
43
|
+
console.log(`Transaction:`, finalTx);
|
|
44
|
+
})();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Network, Signer } from 'bitcoinjs-lib';
|
|
3
|
+
export interface TweakSettings {
|
|
4
|
+
readonly network?: Network;
|
|
5
|
+
tweakHash?: Buffer;
|
|
6
|
+
}
|
|
7
|
+
export declare class TweakedSigner {
|
|
8
|
+
static tweakSigner(signer: Signer, opts?: TweakSettings): Signer;
|
|
9
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.TweakedSigner = void 0;
|
|
27
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
28
|
+
const bip341_js_1 = require("bitcoinjs-lib/src/payments/bip341.js");
|
|
29
|
+
const bip371_js_1 = require("bitcoinjs-lib/src/psbt/bip371.js");
|
|
30
|
+
const ecc = __importStar(require("tiny-secp256k1"));
|
|
31
|
+
const EcKeyPair_js_1 = require("../keypair/EcKeyPair.js");
|
|
32
|
+
(0, bitcoinjs_lib_1.initEccLib)(ecc);
|
|
33
|
+
class TweakedSigner {
|
|
34
|
+
static tweakSigner(signer, opts = {}) {
|
|
35
|
+
let privateKey = signer.privateKey;
|
|
36
|
+
if (!privateKey) {
|
|
37
|
+
throw new Error('Private key is required for tweaking signer!');
|
|
38
|
+
}
|
|
39
|
+
if (signer.publicKey[0] === 3) {
|
|
40
|
+
privateKey = ecc.privateNegate(privateKey);
|
|
41
|
+
}
|
|
42
|
+
const tweakedPrivateKey = ecc.privateAdd(privateKey, (0, bip341_js_1.tapTweakHash)((0, bip371_js_1.toXOnly)(signer.publicKey), opts.tweakHash));
|
|
43
|
+
if (!tweakedPrivateKey) {
|
|
44
|
+
throw new Error('Invalid tweaked private key!');
|
|
45
|
+
}
|
|
46
|
+
return EcKeyPair_js_1.EcKeyPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), opts.network);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.TweakedSigner = TweakedSigner;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|