@btc-vision/transaction 1.2.12 → 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.
- package/browser/_version.d.ts +1 -1
- package/browser/buffer/BinaryWriter.d.ts +1 -0
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +0 -7
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +2 -2
- package/browser/utxo/OPNetLimitedProvider.d.ts +4 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryWriter.d.ts +1 -0
- package/build/buffer/BinaryWriter.js +15 -1
- package/build/transaction/TransactionFactory.d.ts +0 -7
- package/build/transaction/builders/DeploymentTransaction.js +3 -1
- package/build/transaction/builders/SharedInteractionTransaction.js +4 -1
- package/build/transaction/interfaces/ITransactionParameters.d.ts +2 -2
- package/build/utxo/OPNetLimitedProvider.d.ts +4 -0
- package/build/utxo/OPNetLimitedProvider.js +7 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryWriter.ts +21 -0
- package/src/transaction/TransactionFactory.ts +0 -8
- package/src/transaction/builders/DeploymentTransaction.ts +3 -1
- package/src/transaction/builders/SharedInteractionTransaction.ts +5 -1
- package/src/transaction/interfaces/ITransactionParameters.ts +2 -2
- package/src/utxo/OPNetLimitedProvider.ts +17 -0
|
@@ -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
|
|
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
|
|
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
|
}>;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.2.
|
|
1
|
+
export declare const version = "1.2.14";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.14';
|
|
@@ -12,6 +12,7 @@ export declare class BinaryWriter {
|
|
|
12
12
|
writeU64(value: u64): void;
|
|
13
13
|
writeSelector(value: Selector): void;
|
|
14
14
|
writeBoolean(value: boolean): void;
|
|
15
|
+
writeI128(bigIntValue: bigint): void;
|
|
15
16
|
writeU256(bigIntValue: bigint): void;
|
|
16
17
|
writeU128(bigIntValue: bigint): void;
|
|
17
18
|
writeBytes(value: Uint8Array | Buffer): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BufferHelper } from '../utils/BufferHelper.js';
|
|
2
|
-
import { ADDRESS_BYTE_LENGTH, U128_BYTE_LENGTH, U16_BYTE_LENGTH, U256_BYTE_LENGTH, U32_BYTE_LENGTH, U64_BYTE_LENGTH, U8_BYTE_LENGTH, } from '../utils/lengths.js';
|
|
2
|
+
import { ADDRESS_BYTE_LENGTH, I128_BYTE_LENGTH, U128_BYTE_LENGTH, U16_BYTE_LENGTH, U256_BYTE_LENGTH, U32_BYTE_LENGTH, U64_BYTE_LENGTH, U8_BYTE_LENGTH, } from '../utils/lengths.js';
|
|
3
3
|
import { BinaryReader } from './BinaryReader.js';
|
|
4
4
|
export class BinaryWriter {
|
|
5
5
|
constructor(length = 0) {
|
|
@@ -39,6 +39,20 @@ export class BinaryWriter {
|
|
|
39
39
|
writeBoolean(value) {
|
|
40
40
|
this.writeU8(value ? 1 : 0);
|
|
41
41
|
}
|
|
42
|
+
writeI128(bigIntValue) {
|
|
43
|
+
if (bigIntValue > 170141183460469231731687303715884105727n ||
|
|
44
|
+
bigIntValue < -170141183460469231731687303715884105728n) {
|
|
45
|
+
throw new Error('i128 value is too large.');
|
|
46
|
+
}
|
|
47
|
+
this.allocSafe(I128_BYTE_LENGTH);
|
|
48
|
+
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, I128_BYTE_LENGTH);
|
|
49
|
+
if (bytesToHex.byteLength !== I128_BYTE_LENGTH) {
|
|
50
|
+
throw new Error(`Invalid i128 value: ${bigIntValue}`);
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < bytesToHex.byteLength; i++) {
|
|
53
|
+
this.writeU8(bytesToHex[i]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
42
56
|
writeU256(bigIntValue) {
|
|
43
57
|
if (bigIntValue >
|
|
44
58
|
115792089237316195423570985008687907853269984665640564039457584007913129639935n) {
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.14';
|
|
@@ -3,6 +3,7 @@ import { Address } from '../keypair/Address.js';
|
|
|
3
3
|
import { BufferHelper } from '../utils/BufferHelper.js';
|
|
4
4
|
import {
|
|
5
5
|
ADDRESS_BYTE_LENGTH,
|
|
6
|
+
I128_BYTE_LENGTH,
|
|
6
7
|
U128_BYTE_LENGTH,
|
|
7
8
|
U16_BYTE_LENGTH,
|
|
8
9
|
U256_BYTE_LENGTH,
|
|
@@ -60,6 +61,26 @@ export class BinaryWriter {
|
|
|
60
61
|
this.writeU8(value ? 1 : 0);
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
public writeI128(bigIntValue: bigint): void {
|
|
65
|
+
if (
|
|
66
|
+
bigIntValue > 170141183460469231731687303715884105727n ||
|
|
67
|
+
bigIntValue < -170141183460469231731687303715884105728n
|
|
68
|
+
) {
|
|
69
|
+
throw new Error('i128 value is too large.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.allocSafe(I128_BYTE_LENGTH);
|
|
73
|
+
|
|
74
|
+
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, I128_BYTE_LENGTH);
|
|
75
|
+
if (bytesToHex.byteLength !== I128_BYTE_LENGTH) {
|
|
76
|
+
throw new Error(`Invalid i128 value: ${bigIntValue}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < bytesToHex.byteLength; i++) {
|
|
80
|
+
this.writeU8(bytesToHex[i]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
63
84
|
public writeU256(bigIntValue: bigint): void {
|
|
64
85
|
if (
|
|
65
86
|
bigIntValue >
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|