@btc-vision/transaction 1.2.13 → 1.2.14

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.
@@ -15,13 +15,6 @@ export interface DeploymentResult {
15
15
  readonly preimage: string;
16
16
  readonly utxos: UTXO[];
17
17
  }
18
- export interface WrapResult {
19
- readonly transaction: [string, string];
20
- readonly vaultAddress: string;
21
- readonly amount: bigint;
22
- readonly receiverAddress: string;
23
- readonly utxos: UTXO[];
24
- }
25
18
  export interface FundingTransactionResponse {
26
19
  readonly tx: Transaction;
27
20
  readonly original: FundingTransaction;
@@ -25,7 +25,7 @@ export interface IChallengeSolutionTransactionParameters extends ITransactionPar
25
25
  export interface SharedInteractionParameters extends ITransactionParameters {
26
26
  calldata?: Buffer;
27
27
  disableAutoRefund?: boolean;
28
- readonly preimage?: Buffer;
28
+ readonly preimage: Buffer;
29
29
  readonly randomBytes?: Buffer;
30
30
  }
31
31
  export interface IInteractionParameters extends SharedInteractionParameters {
@@ -36,5 +36,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
36
36
  readonly bytecode: Buffer;
37
37
  readonly calldata?: Buffer;
38
38
  readonly randomBytes?: Buffer;
39
- readonly preimage?: Buffer;
39
+ readonly preimage: Buffer;
40
40
  }
@@ -7,6 +7,9 @@ export interface WalletUTXOs {
7
7
  readonly pending: RawUTXOResponse[];
8
8
  readonly spentTransactions: RawUTXOResponse[];
9
9
  }
10
+ export interface PreimageData {
11
+ readonly preimage: Buffer;
12
+ }
10
13
  export declare class OPNetLimitedProvider {
11
14
  private readonly opnetAPIUrl;
12
15
  private readonly utxoPath;
@@ -15,6 +18,7 @@ export declare class OPNetLimitedProvider {
15
18
  fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
16
19
  fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
17
20
  broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
21
+ getPreimage(): Promise<PreimageData | undefined>;
18
22
  splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
19
23
  error: string;
20
24
  }>;
@@ -1 +1 @@
1
- export declare const version = "1.2.13";
1
+ export declare const version = "1.2.14";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.13';
1
+ export const version = '1.2.14';
@@ -15,13 +15,6 @@ export interface DeploymentResult {
15
15
  readonly preimage: string;
16
16
  readonly utxos: UTXO[];
17
17
  }
18
- export interface WrapResult {
19
- readonly transaction: [string, string];
20
- readonly vaultAddress: string;
21
- readonly amount: bigint;
22
- readonly receiverAddress: string;
23
- readonly utxos: UTXO[];
24
- }
25
18
  export interface FundingTransactionResponse {
26
19
  readonly tx: Transaction;
27
20
  readonly original: FundingTransaction;
@@ -41,8 +41,10 @@ export class DeploymentTransaction extends TransactionBuilder {
41
41
  this.calldata = parameters.calldata;
42
42
  this.verifyCalldata();
43
43
  }
44
+ if (!parameters.preimage)
45
+ throw new Error('Preimage is required');
44
46
  this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
45
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
47
+ this.preimage = parameters.preimage;
46
48
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(this.preimage, this.network);
47
49
  this.contractSeed = this.getContractSeed();
48
50
  this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
@@ -28,7 +28,10 @@ export class SharedInteractionTransaction extends TransactionBuilder {
28
28
  if (!parameters.calldata) {
29
29
  throw new Error('Calldata is required');
30
30
  }
31
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
31
+ if (!parameters.preimage) {
32
+ throw new Error('Preimage is required');
33
+ }
34
+ this.preimage = parameters.preimage;
32
35
  this.disableAutoRefund = parameters.disableAutoRefund || false;
33
36
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(this.preimage, this.network);
34
37
  this.calldata = Compressor.compress(parameters.calldata);
@@ -25,7 +25,7 @@ export interface IChallengeSolutionTransactionParameters extends ITransactionPar
25
25
  export interface SharedInteractionParameters extends ITransactionParameters {
26
26
  calldata?: Buffer;
27
27
  disableAutoRefund?: boolean;
28
- readonly preimage?: Buffer;
28
+ readonly preimage: Buffer;
29
29
  readonly randomBytes?: Buffer;
30
30
  }
31
31
  export interface IInteractionParameters extends SharedInteractionParameters {
@@ -36,5 +36,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
36
36
  readonly bytecode: Buffer;
37
37
  readonly calldata?: Buffer;
38
38
  readonly randomBytes?: Buffer;
39
- readonly preimage?: Buffer;
39
+ readonly preimage: Buffer;
40
40
  }
@@ -7,6 +7,9 @@ export interface WalletUTXOs {
7
7
  readonly pending: RawUTXOResponse[];
8
8
  readonly spentTransactions: RawUTXOResponse[];
9
9
  }
10
+ export interface PreimageData {
11
+ readonly preimage: Buffer;
12
+ }
10
13
  export declare class OPNetLimitedProvider {
11
14
  private readonly opnetAPIUrl;
12
15
  private readonly utxoPath;
@@ -15,6 +18,7 @@ export declare class OPNetLimitedProvider {
15
18
  fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
16
19
  fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
17
20
  broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
21
+ getPreimage(): Promise<PreimageData | undefined>;
18
22
  splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
19
23
  error: string;
20
24
  }>;
@@ -103,6 +103,13 @@ export class OPNetLimitedProvider {
103
103
  }
104
104
  return result;
105
105
  }
106
+ async getPreimage() {
107
+ const result = await this.rpcMethod('btc_preimage', []);
108
+ if (!result) {
109
+ return;
110
+ }
111
+ return result;
112
+ }
106
113
  async splitUTXOs(wallet, network, splitInputsInto, amountPerUTXO) {
107
114
  const utxoSetting = {
108
115
  addresses: [wallet.p2wpkh, wallet.p2tr],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.2.13",
4
+ "version": "1.2.14",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.13';
1
+ export const version = '1.2.14';
@@ -33,14 +33,6 @@ export interface DeploymentResult {
33
33
  readonly utxos: UTXO[];
34
34
  }
35
35
 
36
- export interface WrapResult {
37
- readonly transaction: [string, string];
38
- readonly vaultAddress: string;
39
- readonly amount: bigint;
40
- readonly receiverAddress: string;
41
- readonly utxos: UTXO[];
42
- }
43
-
44
36
  export interface FundingTransactionResponse {
45
37
  readonly tx: Transaction;
46
38
  readonly original: FundingTransaction;
@@ -118,8 +118,10 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
118
118
  this.verifyCalldata();
119
119
  }
120
120
 
121
+ if(!parameters.preimage) throw new Error('Preimage is required');
122
+
121
123
  this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
122
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
124
+ this.preimage = parameters.preimage;
123
125
 
124
126
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(
125
127
  this.preimage,
@@ -67,7 +67,11 @@ export abstract class SharedInteractionTransaction<
67
67
  throw new Error('Calldata is required');
68
68
  }
69
69
 
70
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
70
+ if(!parameters.preimage) {
71
+ throw new Error('Preimage is required');
72
+ }
73
+
74
+ this.preimage = parameters.preimage;
71
75
 
72
76
  this.disableAutoRefund = parameters.disableAutoRefund || false;
73
77
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(
@@ -37,7 +37,7 @@ export interface SharedInteractionParameters extends ITransactionParameters {
37
37
  calldata?: Buffer;
38
38
  disableAutoRefund?: boolean;
39
39
 
40
- readonly preimage?: Buffer;
40
+ readonly preimage: Buffer;
41
41
  readonly randomBytes?: Buffer;
42
42
  }
43
43
 
@@ -52,5 +52,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
52
52
  readonly calldata?: Buffer;
53
53
 
54
54
  readonly randomBytes?: Buffer;
55
- readonly preimage?: Buffer;
55
+ readonly preimage: Buffer;
56
56
  }
@@ -14,6 +14,10 @@ export interface WalletUTXOs {
14
14
  readonly spentTransactions: RawUTXOResponse[];
15
15
  }
16
16
 
17
+ export interface PreimageData {
18
+ readonly preimage: Buffer;
19
+ }
20
+
17
21
  /**
18
22
  * Allows to fetch UTXO data from any OPNET node
19
23
  */
@@ -177,6 +181,19 @@ export class OPNetLimitedProvider {
177
181
  return result as BroadcastResponse;
178
182
  }
179
183
 
184
+ /**
185
+ * Fetches the preimage from the OPNET node
186
+ * @returns {Promise<PreimageData | undefined>} - The preimage fetched
187
+ */
188
+ public async getPreimage(): Promise<PreimageData | undefined> {
189
+ const result = await this.rpcMethod('btc_preimage', []);
190
+ if (!result) {
191
+ return;
192
+ }
193
+
194
+ return result as PreimageData;
195
+ }
196
+
180
197
  /**
181
198
  * Splits UTXOs into smaller UTXOs
182
199
  * @param {Wallet} wallet - The wallet to split UTXOs