@btc-vision/transaction 1.6.8 → 1.6.10
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/abi/ABICoder.d.ts +2 -1
- package/browser/buffer/BinaryReader.d.ts +1 -0
- package/browser/buffer/BinaryWriter.d.ts +2 -0
- package/browser/index.js +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +2 -1
- package/build/abi/ABICoder.js +5 -0
- package/build/buffer/BinaryReader.d.ts +1 -0
- package/build/buffer/BinaryReader.js +8 -0
- package/build/buffer/BinaryWriter.d.ts +2 -0
- package/build/buffer/BinaryWriter.js +18 -0
- package/build/transaction/TransactionFactory.js +1 -5
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +5 -0
- package/src/buffer/BinaryReader.ts +9 -0
- package/src/buffer/BinaryWriter.ts +23 -0
- package/src/transaction/TransactionFactory.ts +1 -4
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.9";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.9';
|
package/build/abi/ABICoder.d.ts
CHANGED
|
@@ -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[];
|
package/build/abi/ABICoder.js
CHANGED
|
@@ -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');
|
|
@@ -7,7 +7,6 @@ import { InteractionTransaction } from './builders/InteractionTransaction.js';
|
|
|
7
7
|
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
8
8
|
import { P2WDADetector } from '../p2wda/P2WDADetector.js';
|
|
9
9
|
import { InteractionTransactionP2WDA } from './builders/InteractionTransactionP2WDA.js';
|
|
10
|
-
import { ChallengeSolution } from '../epoch/ChallengeSolution.js';
|
|
11
10
|
import { Address } from '../keypair/Address.js';
|
|
12
11
|
import { BitcoinUtils } from '../utils/BitcoinUtils.js';
|
|
13
12
|
export class TransactionFactory {
|
|
@@ -423,10 +422,7 @@ export class TransactionFactory {
|
|
|
423
422
|
finalPreTransaction = preTransaction;
|
|
424
423
|
if ('getChallenge' in preTransaction &&
|
|
425
424
|
typeof preTransaction.getChallenge === 'function') {
|
|
426
|
-
|
|
427
|
-
if (result instanceof ChallengeSolution) {
|
|
428
|
-
challenge = result;
|
|
429
|
-
}
|
|
425
|
+
challenge = preTransaction.getChallenge();
|
|
430
426
|
}
|
|
431
427
|
iterations++;
|
|
432
428
|
if (this.debug) {
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.9';
|
package/src/abi/ABICoder.ts
CHANGED
|
@@ -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
|
|
|
@@ -703,10 +703,7 @@ export class TransactionFactory {
|
|
|
703
703
|
'getChallenge' in preTransaction &&
|
|
704
704
|
typeof preTransaction.getChallenge === 'function'
|
|
705
705
|
) {
|
|
706
|
-
|
|
707
|
-
if (result instanceof ChallengeSolution) {
|
|
708
|
-
challenge = result;
|
|
709
|
-
}
|
|
706
|
+
challenge = preTransaction.getChallenge();
|
|
710
707
|
}
|
|
711
708
|
|
|
712
709
|
iterations++;
|