@btc-vision/transaction 1.1.6 → 1.1.8
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 +1 -0
- package/browser/buffer/BinaryReader.d.ts +1 -0
- package/browser/buffer/BinaryWriter.d.ts +1 -0
- package/browser/index.js +1 -1
- package/browser/utils/BufferHelper.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +1 -0
- package/build/abi/ABICoder.js +4 -0
- package/build/buffer/BinaryReader.d.ts +1 -0
- package/build/buffer/BinaryReader.js +8 -0
- package/build/buffer/BinaryWriter.d.ts +1 -0
- package/build/buffer/BinaryWriter.js +9 -1
- package/build/utils/BufferHelper.d.ts +1 -1
- package/build/utils/BufferHelper.js +5 -5
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +4 -0
- package/src/buffer/BinaryReader.ts +11 -0
- package/src/buffer/BinaryWriter.ts +11 -1
- package/src/utils/BufferHelper.ts +5 -6
|
@@ -6,6 +6,6 @@ export declare class BufferHelper {
|
|
|
6
6
|
static hexToUint8Array(input: string): Uint8Array;
|
|
7
7
|
static pointerToUint8Array(pointer: MemorySlotPointer): Uint8Array;
|
|
8
8
|
static uint8ArrayToPointer(input: Uint8Array): MemorySlotPointer;
|
|
9
|
-
static valueToUint8Array(value: bigint): Uint8Array;
|
|
9
|
+
static valueToUint8Array(value: bigint, length?: number): Uint8Array;
|
|
10
10
|
static uint8ArrayToValue(input: Uint8Array): bigint;
|
|
11
11
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.8";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.8';
|
package/build/abi/ABICoder.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare enum ABIDataTypes {
|
|
|
14
14
|
ADDRESS_UINT256_TUPLE = "ADDRESS_UINT256_TUPLE",
|
|
15
15
|
ARRAY_OF_ADDRESSES = "ARRAY_OF_ADDRESSES",
|
|
16
16
|
ARRAY_OF_UINT256 = "ARRAY_OF_UINT256",
|
|
17
|
+
ARRAY_OF_UINT128 = "ARRAY_OF_UINT128",
|
|
17
18
|
ARRAY_OF_UINT64 = "ARRAY_OF_UINT64",
|
|
18
19
|
ARRAY_OF_UINT32 = "ARRAY_OF_UINT32",
|
|
19
20
|
ARRAY_OF_UINT16 = "ARRAY_OF_UINT16",
|
package/build/abi/ABICoder.js
CHANGED
|
@@ -18,6 +18,7 @@ export var ABIDataTypes;
|
|
|
18
18
|
ABIDataTypes["ADDRESS_UINT256_TUPLE"] = "ADDRESS_UINT256_TUPLE";
|
|
19
19
|
ABIDataTypes["ARRAY_OF_ADDRESSES"] = "ARRAY_OF_ADDRESSES";
|
|
20
20
|
ABIDataTypes["ARRAY_OF_UINT256"] = "ARRAY_OF_UINT256";
|
|
21
|
+
ABIDataTypes["ARRAY_OF_UINT128"] = "ARRAY_OF_UINT128";
|
|
21
22
|
ABIDataTypes["ARRAY_OF_UINT64"] = "ARRAY_OF_UINT64";
|
|
22
23
|
ABIDataTypes["ARRAY_OF_UINT32"] = "ARRAY_OF_UINT32";
|
|
23
24
|
ABIDataTypes["ARRAY_OF_UINT16"] = "ARRAY_OF_UINT16";
|
|
@@ -77,6 +78,9 @@ export class ABICoder {
|
|
|
77
78
|
case ABIDataTypes.ARRAY_OF_UINT256:
|
|
78
79
|
result.push(byteReader.readU256Array());
|
|
79
80
|
break;
|
|
81
|
+
case ABIDataTypes.ARRAY_OF_UINT128:
|
|
82
|
+
result.push(byteReader.readU128Array());
|
|
83
|
+
break;
|
|
80
84
|
case ABIDataTypes.ARRAY_OF_UINT64:
|
|
81
85
|
result.push(byteReader.readU64Array());
|
|
82
86
|
break;
|
|
@@ -43,6 +43,14 @@ export class BinaryReader {
|
|
|
43
43
|
}
|
|
44
44
|
return result;
|
|
45
45
|
}
|
|
46
|
+
readU128Array() {
|
|
47
|
+
const length = this.readU16();
|
|
48
|
+
const result = new Array(length);
|
|
49
|
+
for (let i = 0; i < length; i++) {
|
|
50
|
+
result[i] = this.readU128();
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
46
54
|
readU64Array() {
|
|
47
55
|
const length = this.readU16();
|
|
48
56
|
const result = new Array(length);
|
|
@@ -33,6 +33,7 @@ export declare class BinaryWriter {
|
|
|
33
33
|
writeAddressArray(value: Address[]): void;
|
|
34
34
|
writeU32Array(value: u32[]): void;
|
|
35
35
|
writeU256Array(value: bigint[]): void;
|
|
36
|
+
writeU128Array(value: bigint[]): void;
|
|
36
37
|
writeStringArray(value: string[]): void;
|
|
37
38
|
writeU16Array(value: u16[]): void;
|
|
38
39
|
writeU8Array(value: u8[]): void;
|
|
@@ -58,7 +58,7 @@ export class BinaryWriter {
|
|
|
58
58
|
throw new Error('Value is too large.');
|
|
59
59
|
}
|
|
60
60
|
this.allocSafe(16);
|
|
61
|
-
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
|
|
61
|
+
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, 16);
|
|
62
62
|
if (bytesToHex.byteLength !== 16) {
|
|
63
63
|
throw new Error(`Invalid u128 value: ${bigIntValue}`);
|
|
64
64
|
}
|
|
@@ -190,6 +190,14 @@ export class BinaryWriter {
|
|
|
190
190
|
this.writeU256(value[i]);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
+
writeU128Array(value) {
|
|
194
|
+
if (value.length > 65535)
|
|
195
|
+
throw new Error('Array size is too large');
|
|
196
|
+
this.writeU16(value.length);
|
|
197
|
+
for (let i = 0; i < value.length; i++) {
|
|
198
|
+
this.writeU128(value[i]);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
193
201
|
writeStringArray(value) {
|
|
194
202
|
if (value.length > 65535)
|
|
195
203
|
throw new Error('Array size is too large');
|
|
@@ -6,6 +6,6 @@ export declare class BufferHelper {
|
|
|
6
6
|
static hexToUint8Array(input: string): Uint8Array;
|
|
7
7
|
static pointerToUint8Array(pointer: MemorySlotPointer): Uint8Array;
|
|
8
8
|
static uint8ArrayToPointer(input: Uint8Array): MemorySlotPointer;
|
|
9
|
-
static valueToUint8Array(value: bigint): Uint8Array;
|
|
9
|
+
static valueToUint8Array(value: bigint, length?: number): Uint8Array;
|
|
10
10
|
static uint8ArrayToValue(input: Uint8Array): bigint;
|
|
11
11
|
}
|
|
@@ -21,9 +21,9 @@ export class BufferHelper {
|
|
|
21
21
|
if (input.length % 2 !== 0) {
|
|
22
22
|
input = '0' + input;
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
const buffer = new Uint8Array(
|
|
26
|
-
for (let i = 0; i <
|
|
24
|
+
const lengthS = input.length / 2;
|
|
25
|
+
const buffer = new Uint8Array(lengthS);
|
|
26
|
+
for (let i = 0; i < lengthS; i++) {
|
|
27
27
|
buffer[i] = parseInt(input.substring(i * 2, i * 2 + 2), 16);
|
|
28
28
|
}
|
|
29
29
|
return buffer;
|
|
@@ -36,8 +36,8 @@ export class BufferHelper {
|
|
|
36
36
|
const hex = BufferHelper.uint8ArrayToHex(input);
|
|
37
37
|
return BigInt('0x' + hex);
|
|
38
38
|
}
|
|
39
|
-
static valueToUint8Array(value) {
|
|
40
|
-
const valueHex = value.toString(16).padStart(
|
|
39
|
+
static valueToUint8Array(value, length = 32) {
|
|
40
|
+
const valueHex = value.toString(16).padStart(length * 2, '0');
|
|
41
41
|
return BufferHelper.hexToUint8Array(valueHex);
|
|
42
42
|
}
|
|
43
43
|
static uint8ArrayToValue(input) {
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.8';
|
package/src/abi/ABICoder.ts
CHANGED
|
@@ -19,6 +19,7 @@ export enum ABIDataTypes {
|
|
|
19
19
|
ADDRESS_UINT256_TUPLE = 'ADDRESS_UINT256_TUPLE',
|
|
20
20
|
ARRAY_OF_ADDRESSES = 'ARRAY_OF_ADDRESSES',
|
|
21
21
|
ARRAY_OF_UINT256 = 'ARRAY_OF_UINT256',
|
|
22
|
+
ARRAY_OF_UINT128 = 'ARRAY_OF_UINT128',
|
|
22
23
|
ARRAY_OF_UINT64 = 'ARRAY_OF_UINT64',
|
|
23
24
|
ARRAY_OF_UINT32 = 'ARRAY_OF_UINT32',
|
|
24
25
|
ARRAY_OF_UINT16 = 'ARRAY_OF_UINT16',
|
|
@@ -80,6 +81,9 @@ export class ABICoder {
|
|
|
80
81
|
case ABIDataTypes.ARRAY_OF_UINT256:
|
|
81
82
|
result.push(byteReader.readU256Array());
|
|
82
83
|
break;
|
|
84
|
+
case ABIDataTypes.ARRAY_OF_UINT128:
|
|
85
|
+
result.push(byteReader.readU128Array());
|
|
86
|
+
break;
|
|
83
87
|
case ABIDataTypes.ARRAY_OF_UINT64:
|
|
84
88
|
result.push(byteReader.readU64Array());
|
|
85
89
|
break;
|
|
@@ -55,6 +55,17 @@ export class BinaryReader {
|
|
|
55
55
|
return result;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
public readU128Array(): bigint[] {
|
|
59
|
+
const length = this.readU16();
|
|
60
|
+
const result: bigint[] = new Array<bigint>(length);
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < length; i++) {
|
|
63
|
+
result[i] = this.readU128();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
public readU64Array(): bigint[] {
|
|
59
70
|
const length = this.readU16();
|
|
60
71
|
const result: bigint[] = new Array<bigint>(length);
|
|
@@ -78,7 +78,7 @@ export class BinaryWriter {
|
|
|
78
78
|
|
|
79
79
|
this.allocSafe(16);
|
|
80
80
|
|
|
81
|
-
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
|
|
81
|
+
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, 16);
|
|
82
82
|
if (bytesToHex.byteLength !== 16) {
|
|
83
83
|
throw new Error(`Invalid u128 value: ${bigIntValue}`);
|
|
84
84
|
}
|
|
@@ -244,6 +244,16 @@ export class BinaryWriter {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
public writeU128Array(value: bigint[]): void {
|
|
248
|
+
if (value.length > 65535) throw new Error('Array size is too large');
|
|
249
|
+
|
|
250
|
+
this.writeU16(value.length);
|
|
251
|
+
|
|
252
|
+
for (let i = 0; i < value.length; i++) {
|
|
253
|
+
this.writeU128(value[i]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
247
257
|
public writeStringArray(value: string[]): void {
|
|
248
258
|
if (value.length > 65535) throw new Error('Array size is too large');
|
|
249
259
|
|
|
@@ -32,11 +32,10 @@ export class BufferHelper {
|
|
|
32
32
|
input = '0' + input; // Pad with a leading zero if the length is odd
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
const buffer = new Uint8Array(
|
|
35
|
+
const lengthS = input.length / 2;
|
|
36
|
+
const buffer = new Uint8Array(lengthS);
|
|
37
37
|
|
|
38
|
-
for (let i = 0; i <
|
|
39
|
-
// Use substring(i * 2, i * 2 + 2) to replace substr(i * 2, 2)
|
|
38
|
+
for (let i = 0; i < lengthS; i++) {
|
|
40
39
|
buffer[i] = parseInt(input.substring(i * 2, i * 2 + 2), 16);
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -55,8 +54,8 @@ export class BufferHelper {
|
|
|
55
54
|
return BigInt('0x' + hex);
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
public static valueToUint8Array(value: bigint): Uint8Array {
|
|
59
|
-
const valueHex = value.toString(16).padStart(
|
|
57
|
+
public static valueToUint8Array(value: bigint, length: number = 32): Uint8Array {
|
|
58
|
+
const valueHex = value.toString(16).padStart(length * 2, '0');
|
|
60
59
|
|
|
61
60
|
return BufferHelper.hexToUint8Array(valueHex);
|
|
62
61
|
}
|