@btc-vision/transaction 1.0.7 → 1.0.9
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/Deploy.md +186 -0
- package/README.md +7 -0
- package/Wrap.md +192 -0
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +6 -1
- package/browser/tests/deploy.d.ts +1 -0
- package/browser/tests/wrap.d.ts +1 -0
- package/browser/tests/wrapTest.d.ts +1 -0
- package/browser/transaction/TransactionFactory.d.ts +15 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +40 -0
- package/browser/transaction/builders/InteractionTransaction.d.ts +2 -35
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +46 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +8 -1
- package/browser/transaction/builders/WrapTransaction.d.ts +27 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +16 -12
- package/browser/utils/BitcoinUtils.d.ts +1 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +10 -0
- package/browser/wbtc/Generate.d.ts +13 -0
- package/browser/wbtc/WrappedGenerationParameters.d.ts +11 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/opnet.d.ts +6 -1
- package/build/opnet.js +6 -1
- package/build/tests/deploy.d.ts +1 -0
- package/build/tests/deploy.js +60 -0
- package/build/tests/test.js +3 -3
- package/build/tests/transfer.js +2 -2
- package/build/tests/wrap.d.ts +1 -0
- package/build/tests/wrap.js +64 -0
- package/build/tests/wrapTest.d.ts +1 -0
- package/build/tests/wrapTest.js +64 -0
- package/build/tests/wrapTestg.d.ts +1 -0
- package/build/tests/wrapTestg.js +66 -0
- package/build/transaction/TransactionFactory.d.ts +15 -1
- package/build/transaction/TransactionFactory.js +68 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +40 -0
- package/build/transaction/builders/DeploymentTransaction.js +216 -0
- package/build/transaction/builders/FundingTransaction.js +4 -1
- package/build/transaction/builders/InteractionTransaction.d.ts +2 -35
- package/build/transaction/builders/InteractionTransaction.js +4 -207
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +46 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +213 -0
- package/build/transaction/builders/TransactionBuilder.d.ts +8 -1
- package/build/transaction/builders/TransactionBuilder.js +19 -11
- package/build/transaction/builders/WrapTransaction.d.ts +27 -0
- package/build/transaction/builders/WrapTransaction.js +132 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +16 -12
- package/build/utils/BitcoinUtils.d.ts +1 -0
- package/build/utils/BitcoinUtils.js +8 -1
- package/build/utxo/OPNetLimitedProvider.d.ts +10 -0
- package/build/utxo/OPNetLimitedProvider.js +85 -0
- package/build/utxo/OPNetUtils.d.ts +7 -0
- package/build/utxo/OPNetUtils.js +47 -0
- package/build/verification/TapscriptVerificator.js +3 -3
- package/build/wbtc/Generate.d.ts +13 -0
- package/build/wbtc/Generate.js +1 -0
- package/build/wbtc/WrappedGenerationParameters.d.ts +11 -0
- package/build/wbtc/WrappedGenerationParameters.js +16 -0
- package/bytecode/contract.wasm +0 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AddressGenerator.html +2 -2
- package/docs/classes/BitcoinUtils.html +7 -3
- package/docs/classes/CalldataGenerator.html +10 -10
- package/docs/classes/Compressor.html +4 -4
- package/docs/classes/ContractBaseMetadata.html +4 -4
- package/docs/classes/DeploymentGenerator.html +9 -9
- package/docs/classes/DeploymentTransaction.html +368 -0
- package/docs/classes/EcKeyPair.html +16 -16
- package/docs/classes/FundingTransaction.html +50 -47
- package/docs/classes/Generator.html +9 -9
- package/docs/classes/InteractionTransaction.html +89 -109
- package/docs/classes/OPNetLimitedProvider.html +197 -0
- package/docs/classes/SharedInteractionTransaction.html +392 -0
- package/docs/classes/TapscriptVerificator.html +2 -2
- package/docs/classes/TransactionBuilder.html +53 -50
- package/docs/classes/TransactionFactory.html +11 -4
- package/docs/classes/TweakedSigner.html +2 -2
- package/docs/classes/Wallet.html +10 -10
- package/docs/classes/WrapTransaction.html +404 -0
- package/docs/classes/WrappedGeneration.html +187 -0
- package/docs/classes/wBTC.html +7 -7
- package/docs/enums/TransactionSequence.html +177 -0
- package/docs/enums/TransactionType.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +5 -1
- package/docs/interfaces/ContractAddressVerificationParams.html +2 -2
- package/docs/interfaces/DeploymentResult.html +177 -0
- package/docs/interfaces/FetchUTXOParams.html +2 -2
- package/docs/interfaces/GenerationConstraints.html +182 -0
- package/docs/interfaces/IDeploymentParameters.html +183 -0
- package/docs/interfaces/IFundingTransactionParameters.html +3 -3
- package/docs/interfaces/IInteractionParameters.html +4 -6
- package/docs/interfaces/ITransactionParameters.html +3 -3
- package/docs/interfaces/IWallet.html +4 -4
- package/docs/interfaces/IWrapParameters.html +186 -0
- package/docs/interfaces/NetworkInformation.html +2 -2
- package/docs/interfaces/PsbtInputExtended.html +1 -1
- package/docs/interfaces/PsbtOutputExtendedAddress.html +2 -2
- package/docs/interfaces/PsbtOutputExtendedScript.html +2 -2
- package/docs/interfaces/RawUTXOResponse.html +2 -2
- package/docs/interfaces/SharedInteractionParameters.html +183 -0
- package/docs/interfaces/TapLeafScript.html +2 -2
- package/docs/interfaces/TweakSettings.html +3 -3
- package/docs/interfaces/UTXO.html +2 -2
- package/docs/interfaces/UpdateInput.html +2 -2
- package/docs/interfaces/WrapResult.html +178 -0
- package/docs/interfaces/WrappedGenerationParameters.html +184 -0
- package/docs/modules.html +14 -4
- package/docs/types/PsbtOutputExtended.html +1 -1
- package/docs/variables/version.html +1 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/opnet.ts +8 -1
- package/src/tests/deploy.ts +81 -0
- package/src/tests/test.ts +3 -3
- package/src/tests/transfer.ts +2 -2
- package/src/tests/wrap.ts +89 -0
- package/src/tests/wrapTest.ts +88 -0
- package/src/transaction/TransactionFactory.ts +119 -1
- package/src/transaction/builders/DeploymentTransaction.ts +418 -0
- package/src/transaction/builders/FundingTransaction.ts +5 -1
- package/src/transaction/builders/InteractionTransaction.ts +5 -404
- package/src/transaction/builders/SharedInteractionTransaction.ts +432 -0
- package/src/transaction/builders/TransactionBuilder.ts +40 -15
- package/src/transaction/builders/WrapTransaction.ts +286 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +20 -13
- package/src/utils/BitcoinUtils.ts +17 -1
- package/src/utxo/{UTXOManager.ts → OPNetLimitedProvider.ts} +53 -2
- package/src/verification/TapscriptVerificator.ts +3 -3
- package/src/wbtc/Generate.ts +30 -0
- package/src/wbtc/WrappedGenerationParameters.ts +33 -0
- package/tests/TransactionBuilder.test.ts +58 -58
- package/docs/classes/UTXOManager.html +0 -187
- package/docs/interfaces/ITransactionDataContractDeployment.html +0 -184
- package/docs/interfaces/ITransactionDataContractInteractionWrap.html +0 -186
package/browser/opnet.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export * from './transaction/enums/TransactionType.js';
|
|
|
19
19
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
20
20
|
export * from './transaction/builders/FundingTransaction.js';
|
|
21
21
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
22
|
+
export * from './transaction/builders/WrapTransaction.js';
|
|
23
|
+
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
24
|
+
export * from './transaction/builders/DeploymentTransaction.js';
|
|
25
|
+
export * from './wbtc/WrappedGenerationParameters.js';
|
|
26
|
+
export * from './wbtc/Generate.js';
|
|
22
27
|
export * from './utils/BitcoinUtils.js';
|
|
23
28
|
export * from './utxo/interfaces/IUTXO.js';
|
|
24
|
-
export * from './utxo/
|
|
29
|
+
export * from './utxo/OPNetLimitedProvider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { IInteractionParameters } from './interfaces/ITransactionParameters.js';
|
|
1
|
+
import { IDeploymentParameters, IInteractionParameters, IWrapParameters } from './interfaces/ITransactionParameters.js';
|
|
2
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
3
|
+
export interface DeploymentResult {
|
|
4
|
+
readonly transaction: [string, string];
|
|
5
|
+
readonly contractAddress: Address;
|
|
6
|
+
readonly p2trAddress: Address;
|
|
7
|
+
}
|
|
8
|
+
export interface WrapResult {
|
|
9
|
+
readonly transaction: [string, string];
|
|
10
|
+
readonly vaultAddress: Address;
|
|
11
|
+
readonly amount: bigint;
|
|
12
|
+
readonly receiverAddress: Address;
|
|
13
|
+
}
|
|
2
14
|
export declare class TransactionFactory {
|
|
3
15
|
signInteraction(interactionParameters: IInteractionParameters): [string, string];
|
|
16
|
+
signDeployment(deploymentParameters: IDeploymentParameters): DeploymentResult;
|
|
17
|
+
wrap(warpParameters: IWrapParameters): WrapResult;
|
|
4
18
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
+
import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
+
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
5
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
6
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
7
|
+
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
8
|
+
type: TransactionType.DEPLOYMENT;
|
|
9
|
+
protected readonly _contractAddress: Address;
|
|
10
|
+
private targetScriptRedeem;
|
|
11
|
+
private leftOverFundsScriptRedeem;
|
|
12
|
+
private readonly compiledTargetScript;
|
|
13
|
+
private readonly scriptTree;
|
|
14
|
+
private readonly tweakedSigner;
|
|
15
|
+
private tapLeafScript;
|
|
16
|
+
private deploymentGenerator;
|
|
17
|
+
private readonly contractSeed;
|
|
18
|
+
private readonly bytecode;
|
|
19
|
+
private readonly contractSigner;
|
|
20
|
+
private readonly randomBytes;
|
|
21
|
+
constructor(parameters: IDeploymentParameters);
|
|
22
|
+
get contractAddress(): Address;
|
|
23
|
+
get p2trAddress(): Address;
|
|
24
|
+
getRndBytes(): Buffer;
|
|
25
|
+
protected contractSignerXOnlyPubKey(): Buffer;
|
|
26
|
+
protected addInputsFromUTXO(): void;
|
|
27
|
+
protected buildTransaction(): void;
|
|
28
|
+
protected signInputs(transaction: Psbt): void;
|
|
29
|
+
protected getSignerKey(): Signer;
|
|
30
|
+
protected generateScriptAddress(): Payment;
|
|
31
|
+
protected generateTapData(): Payment;
|
|
32
|
+
private getContractSeed;
|
|
33
|
+
private customFinalizer;
|
|
34
|
+
private getTweakerHash;
|
|
35
|
+
private getTweakedSigner;
|
|
36
|
+
private getPubKeys;
|
|
37
|
+
private generateRedeemScripts;
|
|
38
|
+
private getLeafScript;
|
|
39
|
+
private getScriptTree;
|
|
40
|
+
}
|
|
@@ -1,47 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
3
|
-
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
4
2
|
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
5
|
-
import { ECPairInterface } from 'ecpair';
|
|
6
|
-
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
7
3
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
8
4
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
9
|
-
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
10
5
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
11
|
-
|
|
6
|
+
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
7
|
+
export declare class InteractionTransaction extends SharedInteractionTransaction<TransactionType.INTERACTION> {
|
|
12
8
|
type: TransactionType.INTERACTION;
|
|
13
|
-
readonly randomBytes: Buffer;
|
|
14
|
-
protected targetScriptRedeem: Payment | null;
|
|
15
|
-
protected leftOverFundsScriptRedeem: Payment | null;
|
|
16
9
|
protected readonly compiledTargetScript: Buffer;
|
|
17
10
|
protected readonly scriptTree: Taptree;
|
|
18
11
|
protected tapLeafScript: TapLeafScript | null;
|
|
19
|
-
protected calldataGenerator: CalldataGenerator;
|
|
20
|
-
protected readonly calldata: Buffer;
|
|
21
12
|
protected readonly contractSecret: Buffer;
|
|
22
|
-
protected tweakedSigner?: Signer;
|
|
23
|
-
protected readonly scriptSigner: Signer;
|
|
24
|
-
protected readonly interactionPubKeys: Buffer[];
|
|
25
|
-
protected readonly minimumSignatures: number;
|
|
26
13
|
constructor(parameters: IInteractionParameters);
|
|
27
|
-
getContractSecret(): Buffer;
|
|
28
|
-
getRndBytes(): Buffer;
|
|
29
|
-
protected generateSecret(): Buffer;
|
|
30
|
-
protected tweakSigner(): void;
|
|
31
|
-
protected scriptSignerXOnlyPubKey(): Buffer;
|
|
32
|
-
protected generateKeyPairFromSeed(): ECPairInterface;
|
|
33
|
-
protected addInputsFromUTXO(): void;
|
|
34
|
-
protected buildTransaction(): void;
|
|
35
|
-
protected signInputs(transaction: Psbt): void;
|
|
36
|
-
protected getSignerKey(): Signer;
|
|
37
|
-
protected generateScriptAddress(): Payment;
|
|
38
|
-
protected generateTapData(): Payment;
|
|
39
|
-
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
40
|
-
private getPubKeys;
|
|
41
|
-
private customFinalizer;
|
|
42
|
-
private getTweakerHash;
|
|
43
|
-
private getTweakedSigner;
|
|
44
|
-
private generateRedeemScripts;
|
|
45
|
-
private getLeafScript;
|
|
46
|
-
private getScriptTree;
|
|
47
14
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
3
|
+
import { Payment, Psbt, Signer } from 'bitcoinjs-lib';
|
|
4
|
+
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
5
|
+
import { ECPairInterface } from 'ecpair';
|
|
6
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
7
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
8
|
+
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
9
|
+
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
10
|
+
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
11
|
+
export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
|
|
12
|
+
readonly randomBytes: Buffer;
|
|
13
|
+
protected targetScriptRedeem: Payment | null;
|
|
14
|
+
protected leftOverFundsScriptRedeem: Payment | null;
|
|
15
|
+
protected abstract readonly compiledTargetScript: Buffer;
|
|
16
|
+
protected abstract readonly scriptTree: Taptree;
|
|
17
|
+
protected tapLeafScript: TapLeafScript | null;
|
|
18
|
+
protected readonly calldataGenerator: CalldataGenerator;
|
|
19
|
+
protected readonly calldata: Buffer;
|
|
20
|
+
protected abstract readonly contractSecret: Buffer;
|
|
21
|
+
protected tweakedSigner?: Signer;
|
|
22
|
+
protected readonly scriptSigner: Signer;
|
|
23
|
+
protected readonly interactionPubKeys: Buffer[];
|
|
24
|
+
protected readonly minimumSignatures: number;
|
|
25
|
+
protected constructor(parameters: SharedInteractionParameters);
|
|
26
|
+
getContractSecret(): Buffer;
|
|
27
|
+
getRndBytes(): Buffer;
|
|
28
|
+
protected generateSecret(): Buffer;
|
|
29
|
+
protected tweakSigner(): void;
|
|
30
|
+
protected scriptSignerXOnlyPubKey(): Buffer;
|
|
31
|
+
protected generateKeyPairFromSeed(): ECPairInterface;
|
|
32
|
+
protected addInputsFromUTXO(): void;
|
|
33
|
+
protected buildTransaction(): void;
|
|
34
|
+
protected signInputs(transaction: Psbt): void;
|
|
35
|
+
protected getSignerKey(): Signer;
|
|
36
|
+
protected generateScriptAddress(): Payment;
|
|
37
|
+
protected generateTapData(): Payment;
|
|
38
|
+
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
39
|
+
protected getScriptTree(): Taptree;
|
|
40
|
+
private getPubKeys;
|
|
41
|
+
private customFinalizer;
|
|
42
|
+
private getTweakerHash;
|
|
43
|
+
private getTweakedSigner;
|
|
44
|
+
private generateRedeemScripts;
|
|
45
|
+
private getLeafScript;
|
|
46
|
+
}
|
|
@@ -5,13 +5,19 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
5
5
|
import { IFundingTransactionParameters, ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
6
6
|
import { Address } from '@btc-vision/bsi-binary';
|
|
7
7
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
8
|
+
import { ECPairInterface } from 'ecpair';
|
|
8
9
|
import { Logger } from '@btc-vision/logger';
|
|
10
|
+
export declare enum TransactionSequence {
|
|
11
|
+
REPLACE_BY_FEE = 4294967293,
|
|
12
|
+
FINAL = 4294967295
|
|
13
|
+
}
|
|
9
14
|
export declare abstract class TransactionBuilder<T extends TransactionType> extends Logger {
|
|
10
15
|
static readonly LOCK_LEAF_SCRIPT: Buffer;
|
|
11
16
|
static readonly MINIMUM_DUST: bigint;
|
|
12
17
|
abstract readonly type: T;
|
|
13
18
|
readonly logColor: string;
|
|
14
19
|
transactionFee: bigint;
|
|
20
|
+
protected sequence: number;
|
|
15
21
|
protected readonly transaction: Psbt;
|
|
16
22
|
protected readonly inputs: PsbtInputExtended[];
|
|
17
23
|
protected readonly updateInputs: UpdateInput[];
|
|
@@ -26,10 +32,11 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
26
32
|
protected readonly feeRate: number;
|
|
27
33
|
protected readonly priorityFee: bigint;
|
|
28
34
|
protected utxos: UTXO[];
|
|
29
|
-
protected to: Address;
|
|
35
|
+
protected to: Address | undefined;
|
|
30
36
|
protected from: Address;
|
|
31
37
|
private _maximumFeeRate;
|
|
32
38
|
protected constructor(parameters: ITransactionParameters);
|
|
39
|
+
static getFrom(from: string | undefined, keypair: ECPairInterface, network: Network): Address;
|
|
33
40
|
getFundingTransactionParameters(): IFundingTransactionParameters;
|
|
34
41
|
setDestinationAddress(address: Address): void;
|
|
35
42
|
setMaximumFeeRate(feeRate: number): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
3
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
|
+
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
5
|
+
import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
6
|
+
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
7
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
8
|
+
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
9
|
+
export declare class WrapTransaction extends SharedInteractionTransaction<TransactionType.WBTC_WRAP> {
|
|
10
|
+
private static readonly WRAP_SELECTOR;
|
|
11
|
+
type: TransactionType.WBTC_WRAP;
|
|
12
|
+
readonly vault: Address;
|
|
13
|
+
readonly amount: bigint;
|
|
14
|
+
readonly receiver: Address;
|
|
15
|
+
protected readonly compiledTargetScript: Buffer;
|
|
16
|
+
protected readonly scriptTree: Taptree;
|
|
17
|
+
protected tapLeafScript: TapLeafScript | null;
|
|
18
|
+
protected readonly contractSecret: Buffer;
|
|
19
|
+
private readonly wbtc;
|
|
20
|
+
constructor(parameters: IWrapParameters);
|
|
21
|
+
private static generateMintCalldata;
|
|
22
|
+
verifyPublicKeysConstraints(generation: WrappedGeneration): boolean;
|
|
23
|
+
protected buildTransaction(): void;
|
|
24
|
+
private addVaultOutput;
|
|
25
|
+
private generateVaultAddress;
|
|
26
|
+
private generateChecksumSalt;
|
|
27
|
+
}
|
|
@@ -3,9 +3,10 @@ import { Signer } from 'bitcoinjs-lib';
|
|
|
3
3
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
4
4
|
import { Network } from 'bitcoinjs-lib/src/networks.js';
|
|
5
5
|
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
6
7
|
export interface ITransactionParameters {
|
|
7
8
|
readonly from?: Address;
|
|
8
|
-
readonly to
|
|
9
|
+
readonly to?: Address | undefined;
|
|
9
10
|
utxos: UTXO[];
|
|
10
11
|
readonly signer: Signer;
|
|
11
12
|
readonly network: Network;
|
|
@@ -13,21 +14,24 @@ export interface ITransactionParameters {
|
|
|
13
14
|
readonly priorityFee: bigint;
|
|
14
15
|
}
|
|
15
16
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
16
|
-
|
|
17
|
+
childTransactionRequiredValue: bigint;
|
|
17
18
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
readonly pubKeys?: Buffer[];
|
|
21
|
-
readonly minimumSignatures?: number;
|
|
19
|
+
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
20
|
+
calldata?: Buffer | undefined;
|
|
22
21
|
readonly randomBytes?: Buffer;
|
|
23
22
|
}
|
|
24
|
-
export interface
|
|
23
|
+
export interface IInteractionParameters extends SharedInteractionParameters {
|
|
24
|
+
readonly calldata: Buffer;
|
|
25
|
+
readonly to: Address;
|
|
26
|
+
}
|
|
27
|
+
export interface IWrapParameters extends SharedInteractionParameters {
|
|
28
|
+
readonly to?: undefined;
|
|
25
29
|
readonly amount: bigint;
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
30
|
+
readonly receiver?: Address;
|
|
31
|
+
readonly generationParameters: WrappedGeneration;
|
|
28
32
|
}
|
|
29
|
-
export interface
|
|
33
|
+
export interface IDeploymentParameters extends ITransactionParameters {
|
|
30
34
|
readonly bytecode: Buffer;
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
35
|
+
readonly to?: undefined;
|
|
36
|
+
readonly randomBytes?: Buffer;
|
|
33
37
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FetchUTXOParams, UTXO } from './interfaces/IUTXO.js';
|
|
2
|
+
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
3
|
+
export declare class OPNetLimitedProvider {
|
|
4
|
+
private readonly opnetAPIUrl;
|
|
5
|
+
private readonly utxoPath;
|
|
6
|
+
private readonly rpc;
|
|
7
|
+
constructor(opnetAPIUrl: string);
|
|
8
|
+
fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
|
|
9
|
+
fetchWrapParameters(amount: bigint): Promise<WrappedGeneration | undefined>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface GenerationConstraints {
|
|
2
|
+
readonly timestamp: number;
|
|
3
|
+
readonly version: string;
|
|
4
|
+
readonly minimum: number;
|
|
5
|
+
readonly transactionMinimum: number;
|
|
6
|
+
}
|
|
7
|
+
export interface WrappedGenerationParameters {
|
|
8
|
+
readonly keys: string[];
|
|
9
|
+
readonly vault: string;
|
|
10
|
+
readonly entities: string[];
|
|
11
|
+
readonly signature: string;
|
|
12
|
+
readonly constraints: GenerationConstraints;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { GenerationConstraints, WrappedGenerationParameters } from './Generate.js';
|
|
3
|
+
export declare class WrappedGeneration implements WrappedGenerationParameters {
|
|
4
|
+
readonly constraints: GenerationConstraints;
|
|
5
|
+
readonly entities: string[];
|
|
6
|
+
readonly keys: string[];
|
|
7
|
+
readonly signature: string;
|
|
8
|
+
readonly vault: string;
|
|
9
|
+
readonly pubKeys: Buffer[];
|
|
10
|
+
constructor(params: WrappedGenerationParameters);
|
|
11
|
+
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.9";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.9';
|
package/build/opnet.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export * from './transaction/enums/TransactionType.js';
|
|
|
19
19
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
20
20
|
export * from './transaction/builders/FundingTransaction.js';
|
|
21
21
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
22
|
+
export * from './transaction/builders/WrapTransaction.js';
|
|
23
|
+
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
24
|
+
export * from './transaction/builders/DeploymentTransaction.js';
|
|
25
|
+
export * from './wbtc/WrappedGenerationParameters.js';
|
|
26
|
+
export * from './wbtc/Generate.js';
|
|
22
27
|
export * from './utils/BitcoinUtils.js';
|
|
23
28
|
export * from './utxo/interfaces/IUTXO.js';
|
|
24
|
-
export * from './utxo/
|
|
29
|
+
export * from './utxo/OPNetLimitedProvider.js';
|
package/build/opnet.js
CHANGED
|
@@ -19,6 +19,11 @@ export * from './transaction/enums/TransactionType.js';
|
|
|
19
19
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
20
20
|
export * from './transaction/builders/FundingTransaction.js';
|
|
21
21
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
22
|
+
export * from './transaction/builders/WrapTransaction.js';
|
|
23
|
+
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
24
|
+
export * from './transaction/builders/DeploymentTransaction.js';
|
|
25
|
+
export * from './wbtc/WrappedGenerationParameters.js';
|
|
26
|
+
export * from './wbtc/Generate.js';
|
|
22
27
|
export * from './utils/BitcoinUtils.js';
|
|
23
28
|
export * from './utxo/interfaces/IUTXO.js';
|
|
24
|
-
export * from './utxo/
|
|
29
|
+
export * from './utxo/OPNetLimitedProvider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
2
|
+
import { Regtest } from './Regtest.js';
|
|
3
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
4
|
+
import { networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
6
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
const network = networks.regtest;
|
|
9
|
+
const rpc = new BitcoinRPC();
|
|
10
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
11
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
12
|
+
const factory = new TransactionFactory();
|
|
13
|
+
const shouldMineBlock = true;
|
|
14
|
+
async function mineBlock() {
|
|
15
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
16
|
+
if (!ok) {
|
|
17
|
+
throw new Error('Could not mine block');
|
|
18
|
+
}
|
|
19
|
+
console.log(`Mined block`, ok);
|
|
20
|
+
return !!ok.length;
|
|
21
|
+
}
|
|
22
|
+
await rpc.init(Regtest.config);
|
|
23
|
+
const utxoSetting = {
|
|
24
|
+
address: wallet.p2wpkh,
|
|
25
|
+
minAmount: 10000n,
|
|
26
|
+
requestedAmount: 100000n,
|
|
27
|
+
};
|
|
28
|
+
const utxos = await utxoManager.fetchUTXO(utxoSetting);
|
|
29
|
+
if (!utxos) {
|
|
30
|
+
throw new Error('No UTXOs found');
|
|
31
|
+
}
|
|
32
|
+
const bytecode = fs.readFileSync('./bytecode/contract.wasm');
|
|
33
|
+
const deploymentParameters = {
|
|
34
|
+
from: wallet.p2wpkh,
|
|
35
|
+
utxos: utxos,
|
|
36
|
+
signer: wallet.keypair,
|
|
37
|
+
network: network,
|
|
38
|
+
feeRate: 150,
|
|
39
|
+
priorityFee: 50000n,
|
|
40
|
+
bytecode: bytecode,
|
|
41
|
+
};
|
|
42
|
+
const finalTx = factory.signDeployment(deploymentParameters);
|
|
43
|
+
console.log(`Final transaction:`, finalTx);
|
|
44
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
45
|
+
hexstring: finalTx.transaction[0],
|
|
46
|
+
});
|
|
47
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
48
|
+
if (!firstTxBroadcast) {
|
|
49
|
+
throw new Error('Could not broadcast first transaction');
|
|
50
|
+
}
|
|
51
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
52
|
+
hexstring: finalTx.transaction[1],
|
|
53
|
+
});
|
|
54
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
55
|
+
if (!secondTxBroadcast) {
|
|
56
|
+
throw new Error('Could not broadcast second transaction');
|
|
57
|
+
}
|
|
58
|
+
if (shouldMineBlock) {
|
|
59
|
+
await mineBlock();
|
|
60
|
+
}
|
package/build/tests/test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Wallet } from '../keypair/Wallet.js';
|
|
2
2
|
import { Regtest } from './Regtest.js';
|
|
3
|
-
import {
|
|
3
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
4
4
|
import { networks } from 'bitcoinjs-lib';
|
|
5
5
|
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
6
6
|
import { FundingTransaction } from '../transaction/builders/FundingTransaction.js';
|
|
7
7
|
const network = networks.regtest;
|
|
8
8
|
const rpc = new BitcoinRPC();
|
|
9
9
|
const wallet = new Wallet(Regtest.wallet, network);
|
|
10
|
-
const utxoManager = new
|
|
10
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
11
11
|
const shouldMineBlock = true;
|
|
12
12
|
async function mineBlock() {
|
|
13
13
|
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
@@ -36,7 +36,7 @@ async function mineBlock() {
|
|
|
36
36
|
network: network,
|
|
37
37
|
feeRate: 150,
|
|
38
38
|
priorityFee: 1000n,
|
|
39
|
-
|
|
39
|
+
childTransactionRequiredValue: 0n,
|
|
40
40
|
};
|
|
41
41
|
const fundingTransaction = new FundingTransaction(interactionParameters);
|
|
42
42
|
const fundingTx = fundingTransaction.signTransaction();
|
package/build/tests/transfer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { wBTC } from '../metadata/contracts/wBTC.js';
|
|
2
2
|
import { Wallet } from '../keypair/Wallet.js';
|
|
3
3
|
import { Testnet } from './Regtest.js';
|
|
4
|
-
import {
|
|
4
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
5
5
|
import { networks } from 'bitcoinjs-lib';
|
|
6
6
|
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
7
7
|
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
@@ -10,7 +10,7 @@ const network = networks.testnet;
|
|
|
10
10
|
const rpc = new BitcoinRPC();
|
|
11
11
|
const wBtc = new wBTC(network);
|
|
12
12
|
const wallet = new Wallet(Testnet.wallet, network);
|
|
13
|
-
const utxoManager = new
|
|
13
|
+
const utxoManager = new OPNetLimitedProvider('https://testnet.opnet.org');
|
|
14
14
|
const factory = new TransactionFactory();
|
|
15
15
|
const abiCoder = new ABICoder();
|
|
16
16
|
const transferSelector = Number(`0x` + abiCoder.encodeSelector('transfer'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
2
|
+
import { Regtest } from './Regtest.js';
|
|
3
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
4
|
+
import { networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
6
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
7
|
+
const network = networks.regtest;
|
|
8
|
+
const rpc = new BitcoinRPC();
|
|
9
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
10
|
+
const opnet = new OPNetLimitedProvider('http://localhost:9001');
|
|
11
|
+
const factory = new TransactionFactory();
|
|
12
|
+
const shouldMineBlock = true;
|
|
13
|
+
async function mineBlock() {
|
|
14
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
15
|
+
if (!ok) {
|
|
16
|
+
throw new Error('Could not mine block');
|
|
17
|
+
}
|
|
18
|
+
console.log(`Mined block`, ok);
|
|
19
|
+
return !!ok.length;
|
|
20
|
+
}
|
|
21
|
+
await rpc.init(Regtest.config);
|
|
22
|
+
const wrapAmount = 1000000n;
|
|
23
|
+
const utxoSetting = {
|
|
24
|
+
address: wallet.p2wpkh,
|
|
25
|
+
minAmount: 10000n,
|
|
26
|
+
requestedAmount: wrapAmount,
|
|
27
|
+
};
|
|
28
|
+
const utxos = await opnet.fetchUTXO(utxoSetting);
|
|
29
|
+
if (!utxos) {
|
|
30
|
+
throw new Error('No UTXOs found');
|
|
31
|
+
}
|
|
32
|
+
const generationParameters = await opnet.fetchWrapParameters(wrapAmount);
|
|
33
|
+
if (!generationParameters) {
|
|
34
|
+
throw new Error('No generation parameters found');
|
|
35
|
+
}
|
|
36
|
+
const wrapParameters = {
|
|
37
|
+
from: wallet.p2wpkh,
|
|
38
|
+
utxos: utxos,
|
|
39
|
+
signer: wallet.keypair,
|
|
40
|
+
network: network,
|
|
41
|
+
feeRate: 150,
|
|
42
|
+
priorityFee: 50000n,
|
|
43
|
+
amount: wrapAmount,
|
|
44
|
+
generationParameters: generationParameters,
|
|
45
|
+
};
|
|
46
|
+
const finalTx = factory.wrap(wrapParameters);
|
|
47
|
+
console.log(`Final transaction:`, finalTx);
|
|
48
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
49
|
+
hexstring: finalTx.transaction[0],
|
|
50
|
+
});
|
|
51
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
52
|
+
if (!firstTxBroadcast) {
|
|
53
|
+
throw new Error('Could not broadcast first transaction');
|
|
54
|
+
}
|
|
55
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
56
|
+
hexstring: finalTx.transaction[1],
|
|
57
|
+
});
|
|
58
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
59
|
+
if (!secondTxBroadcast) {
|
|
60
|
+
throw new Error('Could not broadcast second transaction');
|
|
61
|
+
}
|
|
62
|
+
if (shouldMineBlock) {
|
|
63
|
+
await mineBlock();
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
2
|
+
import { Testnet } from './Regtest.js';
|
|
3
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
4
|
+
import { networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
6
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
7
|
+
const network = networks.testnet;
|
|
8
|
+
const rpc = new BitcoinRPC();
|
|
9
|
+
const wallet = new Wallet(Testnet.wallet, network);
|
|
10
|
+
const opnet = new OPNetLimitedProvider('https://testnet.opnet.org');
|
|
11
|
+
const factory = new TransactionFactory();
|
|
12
|
+
const shouldMineBlock = true;
|
|
13
|
+
async function mineBlock() {
|
|
14
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
15
|
+
if (!ok) {
|
|
16
|
+
throw new Error('Could not mine block');
|
|
17
|
+
}
|
|
18
|
+
console.log(`Mined block`, ok);
|
|
19
|
+
return !!ok.length;
|
|
20
|
+
}
|
|
21
|
+
await rpc.init(Testnet.config);
|
|
22
|
+
const wrapAmount = 100000000n;
|
|
23
|
+
const utxoSetting = {
|
|
24
|
+
address: wallet.p2wpkh,
|
|
25
|
+
minAmount: 10000n,
|
|
26
|
+
requestedAmount: wrapAmount,
|
|
27
|
+
};
|
|
28
|
+
const utxos = await opnet.fetchUTXO(utxoSetting);
|
|
29
|
+
if (!utxos) {
|
|
30
|
+
throw new Error('No UTXOs found');
|
|
31
|
+
}
|
|
32
|
+
const generationParameters = await opnet.fetchWrapParameters(wrapAmount);
|
|
33
|
+
if (!generationParameters) {
|
|
34
|
+
throw new Error('No generation parameters found');
|
|
35
|
+
}
|
|
36
|
+
const wrapParameters = {
|
|
37
|
+
from: wallet.p2wpkh,
|
|
38
|
+
utxos: utxos,
|
|
39
|
+
signer: wallet.keypair,
|
|
40
|
+
network: network,
|
|
41
|
+
feeRate: 350,
|
|
42
|
+
priorityFee: 50000n,
|
|
43
|
+
amount: wrapAmount,
|
|
44
|
+
generationParameters: generationParameters,
|
|
45
|
+
};
|
|
46
|
+
const finalTx = factory.wrap(wrapParameters);
|
|
47
|
+
console.log(`Final transaction:`, finalTx);
|
|
48
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
49
|
+
hexstring: finalTx.transaction[0],
|
|
50
|
+
});
|
|
51
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
52
|
+
if (!firstTxBroadcast) {
|
|
53
|
+
throw new Error('Could not broadcast first transaction');
|
|
54
|
+
}
|
|
55
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
56
|
+
hexstring: finalTx.transaction[1],
|
|
57
|
+
});
|
|
58
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
59
|
+
if (!secondTxBroadcast) {
|
|
60
|
+
throw new Error('Could not broadcast second transaction');
|
|
61
|
+
}
|
|
62
|
+
if (shouldMineBlock) {
|
|
63
|
+
await mineBlock();
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|