@btc-vision/transaction 1.0.94 → 1.0.96
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/builders/MultiSignGenerator.d.ts +1 -0
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +0 -1
- package/browser/transaction/browser/Web3Provider.d.ts +2 -2
- package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -0
- package/browser/transaction/processor/PsbtTransaction.d.ts +0 -1
- package/browser/utils/BitcoinUtils.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/builders/MultisignGenerator.d.ts +1 -0
- package/build/generators/builders/MultisignGenerator.js +4 -2
- package/build/opnet.d.ts +0 -1
- package/build/opnet.js +0 -1
- package/build/transaction/TransactionFactory.js +7 -2
- package/build/transaction/browser/Web3Provider.d.ts +2 -2
- package/build/transaction/builders/DeploymentTransaction.d.ts +1 -0
- package/build/transaction/builders/DeploymentTransaction.js +3 -0
- package/build/transaction/processor/PsbtTransaction.d.ts +0 -1
- package/build/transaction/processor/PsbtTransaction.js +0 -14
- package/build/utils/BitcoinUtils.d.ts +1 -1
- package/build/utils/BitcoinUtils.js +2 -2
- package/package.json +4 -5
- package/src/_version.ts +1 -1
- package/src/generators/builders/MultiSignGenerator.ts +9 -2
- package/src/opnet.ts +0 -3
- package/src/transaction/TransactionFactory.ts +559 -544
- package/src/transaction/browser/Web3Provider.ts +2 -2
- package/src/transaction/builders/DeploymentTransaction.ts +3 -0
- package/src/transaction/processor/PsbtTransaction.ts +0 -19
- package/src/utils/BitcoinUtils.ts +2 -2
- package/src/network/NetworkInformation.ts +0 -7
package/browser/opnet.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export * from './keypair/interfaces/IWallet.js';
|
|
|
12
12
|
export * from './keypair/AddressVerificator.js';
|
|
13
13
|
export * from './metadata/contracts/wBTC.js';
|
|
14
14
|
export * from './metadata/ContractBaseMetadata.js';
|
|
15
|
-
export * from './network/NetworkInformation.js';
|
|
16
15
|
export * from './signer/TweakedSigner.js';
|
|
17
16
|
export * from './transaction/TransactionFactory.js';
|
|
18
17
|
export * from './transaction/interfaces/ITransactionParameters.js';
|
|
@@ -3,7 +3,7 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
|
3
3
|
import { DeploymentResult, UnwrapResult, WrapResult } from '../TransactionFactory';
|
|
4
4
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
|
|
5
5
|
export type IWrapParametersWithoutSigner = Omit<IWrapParameters, 'signer'>;
|
|
6
|
-
export type
|
|
6
|
+
export type IUnwrapParametersWithoutSigner = Omit<IUnwrapParameters, 'signer'>;
|
|
7
7
|
export type IDeploymentParametersWithoutSigner = Omit<IDeploymentParameters, 'signer' | 'network'>;
|
|
8
8
|
export interface BroadcastTransactionOptions {
|
|
9
9
|
raw: string;
|
|
@@ -22,5 +22,5 @@ export interface Web3Provider {
|
|
|
22
22
|
deployContract(params: IDeploymentParametersWithoutSigner): Promise<DeploymentResult>;
|
|
23
23
|
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
24
24
|
wrap(wrapParameters: IWrapParametersWithoutSigner): Promise<WrapResult>;
|
|
25
|
-
unwrap(unwrapParameters:
|
|
25
|
+
unwrap(unwrapParameters: IUnwrapParametersWithoutSigner): Promise<UnwrapResult>;
|
|
26
26
|
}
|
|
@@ -7,6 +7,7 @@ import { TapLeafScript } from '../interfaces/Tap.js';
|
|
|
7
7
|
import { Address } from '@btc-vision/bsi-binary';
|
|
8
8
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
9
9
|
type: TransactionType.DEPLOYMENT;
|
|
10
|
+
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
10
11
|
protected readonly _contractAddress: Address;
|
|
11
12
|
protected tapLeafScript: TapLeafScript | null;
|
|
12
13
|
private targetScriptRedeem;
|
|
@@ -36,7 +36,6 @@ export declare class PsbtTransaction extends TweakedTransaction {
|
|
|
36
36
|
toHex(): string;
|
|
37
37
|
addInput(input: PsbtInputExtended): void;
|
|
38
38
|
addOutput(output: PsbtOutputExtended): void;
|
|
39
|
-
attemptSignAllInputs(): Promise<boolean>;
|
|
40
39
|
attemptFinalizeInputs(n?: number): boolean;
|
|
41
40
|
getPSBT(): Psbt;
|
|
42
41
|
private getTotalOutputAmount;
|
|
@@ -3,7 +3,7 @@ import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
|
3
3
|
export declare class BitcoinUtils {
|
|
4
4
|
static btcToSatoshi(btc: number): BigInt;
|
|
5
5
|
static rndBytes(): Buffer;
|
|
6
|
-
static
|
|
6
|
+
static getUnsafeRandomValues(length: number): Buffer;
|
|
7
7
|
static opnetHash(data: Buffer): string;
|
|
8
8
|
static orderVaultsByAddress(vaults: VaultUTXOs[]): VaultUTXOs[];
|
|
9
9
|
static findVaultWithMostPublicKeys(vaults: VaultUTXOs[]): VaultUTXOs;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.96";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.96';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { opcodes, script } from 'bitcoinjs-lib';
|
|
2
2
|
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
3
3
|
export class MultiSignGenerator {
|
|
4
|
+
static MAXIMUM_SUPPORTED_SIGNATURE = 255;
|
|
4
5
|
static compile(vaultPublicKeys, minimumSignatures = 0, internal) {
|
|
5
6
|
if (minimumSignatures < 2) {
|
|
6
7
|
throw new Error('Minimum signatures must be greater than 1');
|
|
@@ -8,11 +9,12 @@ export class MultiSignGenerator {
|
|
|
8
9
|
if (vaultPublicKeys.length < minimumSignatures) {
|
|
9
10
|
throw new Error('The amount of public keys is lower than the minimum required');
|
|
10
11
|
}
|
|
11
|
-
if (minimumSignatures >
|
|
12
|
-
throw new Error(
|
|
12
|
+
if (minimumSignatures > MultiSignGenerator.MAXIMUM_SUPPORTED_SIGNATURE) {
|
|
13
|
+
throw new Error(`The maximum amount of signatures is ${MultiSignGenerator.MAXIMUM_SUPPORTED_SIGNATURE}`);
|
|
13
14
|
}
|
|
14
15
|
const minimumRequired = Buffer.alloc(1);
|
|
15
16
|
minimumRequired.writeUInt8(minimumSignatures);
|
|
17
|
+
vaultPublicKeys = vaultPublicKeys.filter((buf, index, self) => index === self.findIndex(otherBuf => buf.equals(otherBuf)));
|
|
16
18
|
vaultPublicKeys = vaultPublicKeys.sort((a, b) => a.compare(b));
|
|
17
19
|
let included = false;
|
|
18
20
|
const data = vaultPublicKeys.map((key) => {
|
package/build/opnet.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export * from './keypair/interfaces/IWallet.js';
|
|
|
12
12
|
export * from './keypair/AddressVerificator.js';
|
|
13
13
|
export * from './metadata/contracts/wBTC.js';
|
|
14
14
|
export * from './metadata/ContractBaseMetadata.js';
|
|
15
|
-
export * from './network/NetworkInformation.js';
|
|
16
15
|
export * from './signer/TweakedSigner.js';
|
|
17
16
|
export * from './transaction/TransactionFactory.js';
|
|
18
17
|
export * from './transaction/interfaces/ITransactionParameters.js';
|
package/build/opnet.js
CHANGED
|
@@ -12,7 +12,6 @@ export * from './keypair/interfaces/IWallet.js';
|
|
|
12
12
|
export * from './keypair/AddressVerificator.js';
|
|
13
13
|
export * from './metadata/contracts/wBTC.js';
|
|
14
14
|
export * from './metadata/ContractBaseMetadata.js';
|
|
15
|
-
export * from './network/NetworkInformation.js';
|
|
16
15
|
export * from './signer/TweakedSigner.js';
|
|
17
16
|
export * from './transaction/TransactionFactory.js';
|
|
18
17
|
export * from './transaction/interfaces/ITransactionParameters.js';
|
|
@@ -23,7 +23,8 @@ export class TransactionFactory {
|
|
|
23
23
|
await preTransaction.generateTransactionMinimalSignatures();
|
|
24
24
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
25
25
|
parameters.utxos = interactionParameters.utxos;
|
|
26
|
-
parameters.amount =
|
|
26
|
+
parameters.amount =
|
|
27
|
+
(await preTransaction.estimateTransactionFees()) + interactionParameters.priorityFee;
|
|
27
28
|
const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
|
|
28
29
|
if (!feeEstimationFundingTransaction) {
|
|
29
30
|
throw new Error('Could not sign funding transaction.');
|
|
@@ -112,6 +113,7 @@ export class TransactionFactory {
|
|
|
112
113
|
const preTransaction = new WrapTransaction(wrapParameters);
|
|
113
114
|
await preTransaction.signTransaction();
|
|
114
115
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
116
|
+
console.log('wrap parameters', parameters);
|
|
115
117
|
parameters.amount += childTransactionRequiredValue;
|
|
116
118
|
parameters.utxos = fundingParameters.utxos;
|
|
117
119
|
const signedTransaction = await this.createFundTransaction(parameters);
|
|
@@ -143,6 +145,7 @@ export class TransactionFactory {
|
|
|
143
145
|
throw new Error('To address is required');
|
|
144
146
|
const estimatedGas = await transaction.estimateTransactionFees();
|
|
145
147
|
const estimatedFees = transaction.preEstimateTransactionFees(BigInt(unwrapParameters.feeRate), this.calculateNumInputs(unwrapParameters.unwrapUTXOs), 2n, this.calculateNumSignatures(unwrapParameters.unwrapUTXOs), this.maxPubKeySize(unwrapParameters.unwrapUTXOs));
|
|
148
|
+
console.log('estimatedFees', estimatedFees, 'estimatedGas', estimatedGas, 'priority', unwrapParameters.priorityFee);
|
|
146
149
|
const fundingParameters = {
|
|
147
150
|
...unwrapParameters,
|
|
148
151
|
amount: estimatedGas + estimatedFees,
|
|
@@ -203,7 +206,9 @@ export class TransactionFactory {
|
|
|
203
206
|
await preTransaction.signTransaction();
|
|
204
207
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
205
208
|
parameters.utxos = fundingParameters.utxos;
|
|
206
|
-
parameters.amount =
|
|
209
|
+
parameters.amount =
|
|
210
|
+
(await preTransaction.estimateTransactionFees()) + unwrapParameters.priorityFee;
|
|
211
|
+
console.log('parameters', parameters);
|
|
207
212
|
const signedTransaction = await this.createFundTransaction(parameters);
|
|
208
213
|
if (!signedTransaction) {
|
|
209
214
|
throw new Error('Could not sign funding transaction.');
|
|
@@ -3,7 +3,7 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
|
3
3
|
import { DeploymentResult, UnwrapResult, WrapResult } from '../TransactionFactory';
|
|
4
4
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
|
|
5
5
|
export type IWrapParametersWithoutSigner = Omit<IWrapParameters, 'signer'>;
|
|
6
|
-
export type
|
|
6
|
+
export type IUnwrapParametersWithoutSigner = Omit<IUnwrapParameters, 'signer'>;
|
|
7
7
|
export type IDeploymentParametersWithoutSigner = Omit<IDeploymentParameters, 'signer' | 'network'>;
|
|
8
8
|
export interface BroadcastTransactionOptions {
|
|
9
9
|
raw: string;
|
|
@@ -22,5 +22,5 @@ export interface Web3Provider {
|
|
|
22
22
|
deployContract(params: IDeploymentParametersWithoutSigner): Promise<DeploymentResult>;
|
|
23
23
|
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
24
24
|
wrap(wrapParameters: IWrapParametersWithoutSigner): Promise<WrapResult>;
|
|
25
|
-
unwrap(unwrapParameters:
|
|
25
|
+
unwrap(unwrapParameters: IUnwrapParametersWithoutSigner): Promise<UnwrapResult>;
|
|
26
26
|
}
|
|
@@ -7,6 +7,7 @@ import { TapLeafScript } from '../interfaces/Tap.js';
|
|
|
7
7
|
import { Address } from '@btc-vision/bsi-binary';
|
|
8
8
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
9
9
|
type: TransactionType.DEPLOYMENT;
|
|
10
|
+
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
10
11
|
protected readonly _contractAddress: Address;
|
|
11
12
|
protected tapLeafScript: TapLeafScript | null;
|
|
12
13
|
private targetScriptRedeem;
|
|
@@ -9,6 +9,7 @@ import { Compressor } from '../../bytecode/Compressor.js';
|
|
|
9
9
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
10
10
|
export class DeploymentTransaction extends TransactionBuilder {
|
|
11
11
|
type = TransactionType.DEPLOYMENT;
|
|
12
|
+
static MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
12
13
|
_contractAddress;
|
|
13
14
|
tapLeafScript = null;
|
|
14
15
|
targetScriptRedeem = null;
|
|
@@ -25,6 +26,8 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
25
26
|
this.bytecode = Compressor.compress(parameters.bytecode);
|
|
26
27
|
if (!this.bytecode)
|
|
27
28
|
throw new Error('Bytecode is required');
|
|
29
|
+
if (this.bytecode.length > DeploymentTransaction.MAXIMUM_CONTRACT_SIZE)
|
|
30
|
+
throw new Error('Contract size overflow.');
|
|
28
31
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
29
32
|
this.contractSeed = this.getContractSeed();
|
|
30
33
|
this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
|
|
@@ -36,7 +36,6 @@ export declare class PsbtTransaction extends TweakedTransaction {
|
|
|
36
36
|
toHex(): string;
|
|
37
37
|
addInput(input: PsbtInputExtended): void;
|
|
38
38
|
addOutput(output: PsbtOutputExtended): void;
|
|
39
|
-
attemptSignAllInputs(): Promise<boolean>;
|
|
40
39
|
attemptFinalizeInputs(n?: number): boolean;
|
|
41
40
|
getPSBT(): Psbt;
|
|
42
41
|
private getTotalOutputAmount;
|
|
@@ -56,20 +56,6 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
56
56
|
return;
|
|
57
57
|
this.transaction.addOutput(output);
|
|
58
58
|
}
|
|
59
|
-
async attemptSignAllInputs() {
|
|
60
|
-
let signed = false;
|
|
61
|
-
for (let i = 0; i < this.transaction.data.inputs.length; i++) {
|
|
62
|
-
const input = this.transaction.data.inputs[i];
|
|
63
|
-
try {
|
|
64
|
-
await this.signInput(this.transaction, input, i, this.signer);
|
|
65
|
-
signed = true;
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
console.log(`can not sign. input ${i}`, e);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return signed;
|
|
72
|
-
}
|
|
73
59
|
attemptFinalizeInputs(n = 1) {
|
|
74
60
|
try {
|
|
75
61
|
const inputs = this.transaction.data.inputs;
|
|
@@ -3,7 +3,7 @@ import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
|
|
|
3
3
|
export declare class BitcoinUtils {
|
|
4
4
|
static btcToSatoshi(btc: number): BigInt;
|
|
5
5
|
static rndBytes(): Buffer;
|
|
6
|
-
static
|
|
6
|
+
static getUnsafeRandomValues(length: number): Buffer;
|
|
7
7
|
static opnetHash(data: Buffer): string;
|
|
8
8
|
static orderVaultsByAddress(vaults: VaultUTXOs[]): VaultUTXOs[];
|
|
9
9
|
static findVaultWithMostPublicKeys(vaults: VaultUTXOs[]): VaultUTXOs;
|
|
@@ -4,10 +4,10 @@ export class BitcoinUtils {
|
|
|
4
4
|
return BigInt(btc * 100000000);
|
|
5
5
|
}
|
|
6
6
|
static rndBytes() {
|
|
7
|
-
const buf = BitcoinUtils.
|
|
7
|
+
const buf = BitcoinUtils.getUnsafeRandomValues(64);
|
|
8
8
|
return Buffer.from(buf);
|
|
9
9
|
}
|
|
10
|
-
static
|
|
10
|
+
static getUnsafeRandomValues(length) {
|
|
11
11
|
if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) {
|
|
12
12
|
const array = new Uint8Array(length);
|
|
13
13
|
window.crypto.getRandomValues(array);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.96",
|
|
4
4
|
"author": "BlobMaster41",
|
|
5
5
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
6
6
|
"engines": {
|
|
@@ -87,10 +87,9 @@
|
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
89
89
|
"@bitcoinerlab/secp256k1": "^1.1.1",
|
|
90
|
-
"@btc-vision/bsi-binary": "^1.0.
|
|
91
|
-
"@btc-vision/bsi-bitcoin-rpc": "^1.0.
|
|
92
|
-
"@btc-vision/
|
|
93
|
-
"@btc-vision/logger": "^1.0.2",
|
|
90
|
+
"@btc-vision/bsi-binary": "^1.0.38",
|
|
91
|
+
"@btc-vision/bsi-bitcoin-rpc": "^1.0.25",
|
|
92
|
+
"@btc-vision/logger": "^1.0.3",
|
|
94
93
|
"assert": "^2.1.0",
|
|
95
94
|
"babel-loader": "^9.1.3",
|
|
96
95
|
"babel-plugin-transform-import-meta": "^2.2.1",
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.96';
|
|
@@ -5,6 +5,8 @@ import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
|
5
5
|
* Generate a bitcoin script for a multisign interaction
|
|
6
6
|
*/
|
|
7
7
|
export class MultiSignGenerator {
|
|
8
|
+
public static readonly MAXIMUM_SUPPORTED_SIGNATURE = 255;
|
|
9
|
+
|
|
8
10
|
public static compile(
|
|
9
11
|
vaultPublicKeys: Buffer[],
|
|
10
12
|
minimumSignatures: number = 0,
|
|
@@ -18,13 +20,18 @@ export class MultiSignGenerator {
|
|
|
18
20
|
throw new Error('The amount of public keys is lower than the minimum required');
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
if (minimumSignatures >
|
|
22
|
-
throw new Error(
|
|
23
|
+
if (minimumSignatures > MultiSignGenerator.MAXIMUM_SUPPORTED_SIGNATURE) {
|
|
24
|
+
throw new Error(`The maximum amount of signatures is ${MultiSignGenerator.MAXIMUM_SUPPORTED_SIGNATURE}`);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const minimumRequired = Buffer.alloc(1);
|
|
26
28
|
minimumRequired.writeUInt8(minimumSignatures);
|
|
27
29
|
|
|
30
|
+
/** Remove duplicates **/
|
|
31
|
+
vaultPublicKeys = vaultPublicKeys.filter((buf, index, self) =>
|
|
32
|
+
index === self.findIndex(otherBuf => buf.equals(otherBuf))
|
|
33
|
+
);
|
|
34
|
+
|
|
28
35
|
/** We must order the pub keys. */
|
|
29
36
|
vaultPublicKeys = vaultPublicKeys.sort((a, b) => a.compare(b));
|
|
30
37
|
|
package/src/opnet.ts
CHANGED
|
@@ -23,9 +23,6 @@ export * from './keypair/AddressVerificator.js';
|
|
|
23
23
|
export * from './metadata/contracts/wBTC.js';
|
|
24
24
|
export * from './metadata/ContractBaseMetadata.js';
|
|
25
25
|
|
|
26
|
-
/** Network */
|
|
27
|
-
export * from './network/NetworkInformation.js';
|
|
28
|
-
|
|
29
26
|
/** Signer */
|
|
30
27
|
export * from './signer/TweakedSigner.js';
|
|
31
28
|
|