@btc-vision/transaction 1.6.9 → 1.6.11

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.
@@ -12,6 +12,7 @@ export interface DeploymentResult {
12
12
  readonly contractAddress: string;
13
13
  readonly contractPubKey: string;
14
14
  readonly challenge: RawChallenge;
15
+ readonly rawTransaction: Transaction;
15
16
  readonly utxos: UTXO[];
16
17
  }
17
18
  export interface FundingTransactionResponse {
@@ -31,6 +32,7 @@ export interface InteractionResponse {
31
32
  readonly estimatedFees: bigint;
32
33
  readonly nextUTXOs: UTXO[];
33
34
  readonly challenge: RawChallenge;
35
+ readonly rawTransaction: Transaction;
34
36
  }
35
37
  export interface BitcoinTransferResponse extends BitcoinTransferBase {
36
38
  readonly original: FundingTransaction;
@@ -1 +1 @@
1
- export declare const version = "1.6.9";
1
+ export declare const version = "1.6.11";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.6.9';
1
+ export const version = '1.6.11';
@@ -21,7 +21,8 @@ export declare enum ABIDataTypes {
21
21
  ARRAY_OF_UINT16 = "ARRAY_OF_UINT16",
22
22
  ARRAY_OF_UINT8 = "ARRAY_OF_UINT8",
23
23
  ARRAY_OF_STRING = "ARRAY_OF_STRING",
24
- ARRAY_OF_BYTES = "ARRAY_OF_BYTES"
24
+ ARRAY_OF_BYTES = "ARRAY_OF_BYTES",
25
+ ARRAY_OF_BUFFERS = "ARRAY_OF_BUFFERS"
25
26
  }
26
27
  export declare class ABICoder {
27
28
  decodeData(data: Uint8Array, types: ABIDataTypes[]): unknown[];
@@ -26,6 +26,7 @@ export var ABIDataTypes;
26
26
  ABIDataTypes["ARRAY_OF_UINT8"] = "ARRAY_OF_UINT8";
27
27
  ABIDataTypes["ARRAY_OF_STRING"] = "ARRAY_OF_STRING";
28
28
  ABIDataTypes["ARRAY_OF_BYTES"] = "ARRAY_OF_BYTES";
29
+ ABIDataTypes["ARRAY_OF_BUFFERS"] = "ARRAY_OF_BUFFERS";
29
30
  })(ABIDataTypes || (ABIDataTypes = {}));
30
31
  export class ABICoder {
31
32
  decodeData(data, types) {
@@ -102,6 +103,10 @@ export class ABICoder {
102
103
  break;
103
104
  case ABIDataTypes.ARRAY_OF_BYTES:
104
105
  result.push(byteReader.readBytesArray());
106
+ break;
107
+ case ABIDataTypes.ARRAY_OF_BUFFERS:
108
+ result.push(byteReader.readArrayOfBuffer());
109
+ break;
105
110
  }
106
111
  }
107
112
  return result;
@@ -25,6 +25,7 @@ export declare class BinaryReader {
25
25
  readStringWithLength(be?: boolean): string;
26
26
  readAddress(): Address;
27
27
  readBytesWithLength(maxLength?: number, be?: boolean): Uint8Array;
28
+ readArrayOfBuffer(be?: boolean): Uint8Array[];
28
29
  readAddressArray(be?: boolean): Address[];
29
30
  readU256Array(be?: boolean): bigint[];
30
31
  readU128Array(be?: boolean): bigint[];
@@ -126,6 +126,14 @@ export class BinaryReader {
126
126
  }
127
127
  return this.readBytes(length);
128
128
  }
129
+ readArrayOfBuffer(be = true) {
130
+ const length = this.readU16(be);
131
+ const result = new Array(length);
132
+ for (let i = 0; i < length; i++) {
133
+ result[i] = this.readBytesWithLength();
134
+ }
135
+ return result;
136
+ }
129
137
  readAddressArray(be = true) {
130
138
  const length = this.readU16(be);
131
139
  const result = new Array(length);
@@ -6,6 +6,7 @@ export declare class BinaryWriter {
6
6
  private currentOffset;
7
7
  private buffer;
8
8
  constructor(length?: number);
9
+ static estimateArrayOfBufferLength(values: Uint8Array[]): u32;
9
10
  writeU8(value: u8): void;
10
11
  writeU16(value: u16, be?: boolean): void;
11
12
  writeU32(value: u32, be?: boolean): void;
@@ -28,6 +29,7 @@ export declare class BinaryWriter {
28
29
  allocSafe(size: u32): void;
29
30
  writeAddressValueTuple(map: AddressMap<bigint>, be?: boolean): void;
30
31
  writeBytesWithLength(value: Uint8Array): void;
32
+ writeArrayOfBuffer(values: Uint8Array[], be?: boolean): void;
31
33
  writeAddressArray(value: Address[]): void;
32
34
  writeU32Array(value: u32[], be?: boolean): void;
33
35
  writeU256Array(value: bigint[], be?: boolean): void;
@@ -6,6 +6,15 @@ export class BinaryWriter {
6
6
  this.currentOffset = 0;
7
7
  this.buffer = this.getDefaultBuffer(length);
8
8
  }
9
+ static estimateArrayOfBufferLength(values) {
10
+ if (values.length > 65535)
11
+ throw new Error('Array size is too large');
12
+ let totalLength = U16_BYTE_LENGTH;
13
+ for (let i = 0; i < values.length; i++) {
14
+ totalLength += U32_BYTE_LENGTH + values[i].length;
15
+ }
16
+ return totalLength;
17
+ }
9
18
  writeU8(value) {
10
19
  if (value > 255)
11
20
  throw new Error('u8 value is too large.');
@@ -174,6 +183,15 @@ export class BinaryWriter {
174
183
  this.writeU32(value.length);
175
184
  this.writeBytes(value);
176
185
  }
186
+ writeArrayOfBuffer(values, be = true) {
187
+ const totalLength = BinaryWriter.estimateArrayOfBufferLength(values);
188
+ this.allocSafe(totalLength);
189
+ this.writeU16(values.length, be);
190
+ for (let i = 0; i < values.length; i++) {
191
+ this.writeU32(values[i].length, be);
192
+ this.writeBytes(values[i]);
193
+ }
194
+ }
177
195
  writeAddressArray(value) {
178
196
  if (value.length > 65535)
179
197
  throw new Error('Array size is too large');
@@ -12,6 +12,7 @@ export interface DeploymentResult {
12
12
  readonly contractAddress: string;
13
13
  readonly contractPubKey: string;
14
14
  readonly challenge: RawChallenge;
15
+ readonly rawTransaction: Transaction;
15
16
  readonly utxos: UTXO[];
16
17
  }
17
18
  export interface FundingTransactionResponse {
@@ -31,6 +32,7 @@ export interface InteractionResponse {
31
32
  readonly estimatedFees: bigint;
32
33
  readonly nextUTXOs: UTXO[];
33
34
  readonly challenge: RawChallenge;
35
+ readonly rawTransaction: Transaction;
34
36
  }
35
37
  export interface BitcoinTransferResponse extends BitcoinTransferBase {
36
38
  readonly original: FundingTransaction;
@@ -138,6 +138,7 @@ export class TransactionFactory {
138
138
  const interactionTx = new InteractionTransaction(newParams);
139
139
  const outTx = await interactionTx.signTransaction();
140
140
  return {
141
+ rawTransaction: signedTransaction.tx,
141
142
  fundingTransaction: signedTransaction.tx.toHex(),
142
143
  interactionTransaction: outTx.toHex(),
143
144
  estimatedFees: interactionTx.transactionFee,
@@ -216,6 +217,7 @@ export class TransactionFactory {
216
217
  value: BigInt(out2.value),
217
218
  };
218
219
  return {
220
+ rawTransaction: outTx,
219
221
  transaction: [signedTransaction.toHex(), outTx.toHex()],
220
222
  contractAddress: deploymentTx.getContractAddress(),
221
223
  contractPubKey: deploymentTx.contractPubKey,
@@ -341,6 +343,7 @@ export class TransactionFactory {
341
343
  const signedTx = await p2wdaTransaction.signTransaction();
342
344
  const txHex = signedTx.toHex();
343
345
  return {
346
+ rawTransaction: signedTx,
344
347
  fundingTransaction: null,
345
348
  interactionTransaction: txHex,
346
349
  estimatedFees: p2wdaTransaction.estimatedFees,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.6.9",
4
+ "version": "1.6.11",
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.6.9';
1
+ export const version = '1.6.11';
@@ -27,6 +27,7 @@ export enum ABIDataTypes {
27
27
  ARRAY_OF_UINT8 = 'ARRAY_OF_UINT8',
28
28
  ARRAY_OF_STRING = 'ARRAY_OF_STRING',
29
29
  ARRAY_OF_BYTES = 'ARRAY_OF_BYTES',
30
+ ARRAY_OF_BUFFERS = 'ARRAY_OF_BUFFERS',
30
31
  }
31
32
 
32
33
  export class ABICoder {
@@ -105,6 +106,10 @@ export class ABICoder {
105
106
  break;
106
107
  case ABIDataTypes.ARRAY_OF_BYTES:
107
108
  result.push(byteReader.readBytesArray());
109
+ break;
110
+ case ABIDataTypes.ARRAY_OF_BUFFERS:
111
+ result.push(byteReader.readArrayOfBuffer());
112
+ break;
108
113
  }
109
114
  }
110
115
 
@@ -220,6 +220,15 @@ export class BinaryReader {
220
220
 
221
221
  // ------------------ Array readers ------------------ //
222
222
 
223
+ public readArrayOfBuffer(be: boolean = true): Uint8Array[] {
224
+ const length = this.readU16(be);
225
+ const result: Uint8Array[] = new Array<Uint8Array>(length);
226
+ for (let i: number = 0; i < length; i++) {
227
+ result[i] = this.readBytesWithLength();
228
+ }
229
+ return result;
230
+ }
231
+
223
232
  public readAddressArray(be: boolean = true): Address[] {
224
233
  const length = this.readU16(be);
225
234
  const result: Address[] = new Array<Address>(length);
@@ -22,6 +22,17 @@ export class BinaryWriter {
22
22
  this.buffer = this.getDefaultBuffer(length);
23
23
  }
24
24
 
25
+ public static estimateArrayOfBufferLength(values: Uint8Array[]): u32 {
26
+ if (values.length > 65535) throw new Error('Array size is too large');
27
+ let totalLength: u32 = U16_BYTE_LENGTH;
28
+
29
+ for (let i = 0; i < values.length; i++) {
30
+ totalLength += U32_BYTE_LENGTH + values[i].length; // each entry has a u32 length prefix
31
+ }
32
+
33
+ return totalLength;
34
+ }
35
+
25
36
  public writeU8(value: u8): void {
26
37
  if (value > 255) throw new Error('u8 value is too large.');
27
38
 
@@ -229,6 +240,18 @@ export class BinaryWriter {
229
240
  this.writeBytes(value);
230
241
  }
231
242
 
243
+ public writeArrayOfBuffer(values: Uint8Array[], be: boolean = true): void {
244
+ const totalLength = BinaryWriter.estimateArrayOfBufferLength(values);
245
+
246
+ this.allocSafe(totalLength);
247
+ this.writeU16(values.length, be);
248
+
249
+ for (let i = 0; i < values.length; i++) {
250
+ this.writeU32(values[i].length, be);
251
+ this.writeBytes(values[i]);
252
+ }
253
+ }
254
+
232
255
  public writeAddressArray(value: Address[]): void {
233
256
  if (value.length > 65535) throw new Error('Array size is too large');
234
257
 
@@ -36,6 +36,7 @@ export interface DeploymentResult {
36
36
  readonly contractPubKey: string;
37
37
  readonly challenge: RawChallenge;
38
38
 
39
+ readonly rawTransaction: Transaction;
39
40
  readonly utxos: UTXO[];
40
41
  }
41
42
 
@@ -58,6 +59,7 @@ export interface InteractionResponse {
58
59
  readonly estimatedFees: bigint;
59
60
  readonly nextUTXOs: UTXO[];
60
61
  readonly challenge: RawChallenge;
62
+ readonly rawTransaction: Transaction;
61
63
  }
62
64
 
63
65
  export interface BitcoinTransferResponse extends BitcoinTransferBase {
@@ -158,10 +160,6 @@ export class TransactionFactory {
158
160
  ];
159
161
  }
160
162
 
161
- /**
162
- * @description Generates the required transactions.
163
- * @returns {Promise<InteractionResponse>} - The signed transaction
164
- */
165
163
  /**
166
164
  * @description Generates the required transactions.
167
165
  * @returns {Promise<InteractionResponse>} - The signed transaction
@@ -257,6 +255,7 @@ export class TransactionFactory {
257
255
  const outTx = await interactionTx.signTransaction();
258
256
 
259
257
  return {
258
+ rawTransaction: signedTransaction.tx,
260
259
  fundingTransaction: signedTransaction.tx.toHex(),
261
260
  interactionTransaction: outTx.toHex(),
262
261
  estimatedFees: interactionTx.transactionFee,
@@ -370,6 +369,7 @@ export class TransactionFactory {
370
369
  };
371
370
 
372
371
  return {
372
+ rawTransaction: outTx,
373
373
  transaction: [signedTransaction.toHex(), outTx.toHex()],
374
374
  contractAddress: deploymentTx.getContractAddress(),
375
375
  contractPubKey: deploymentTx.contractPubKey,
@@ -587,6 +587,7 @@ export class TransactionFactory {
587
587
  const txHex = signedTx.toHex();
588
588
 
589
589
  return {
590
+ rawTransaction: signedTx,
590
591
  fundingTransaction: null,
591
592
  interactionTransaction: txHex,
592
593
  estimatedFees: p2wdaTransaction.estimatedFees,