@btc-vision/transaction 1.2.15 → 1.3.1
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/BinaryReader.d.ts +22 -20
- package/browser/buffer/BinaryWriter.d.ts +12 -17
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryReader.d.ts +22 -20
- package/build/buffer/BinaryReader.js +134 -113
- package/build/buffer/BinaryWriter.d.ts +12 -17
- package/build/buffer/BinaryWriter.js +60 -82
- package/build/keypair/Address.d.ts +1 -0
- package/build/keypair/Address.js +3 -0
- package/package.json +15 -15
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryReader.ts +230 -173
- package/src/buffer/BinaryWriter.ts +57 -93
- package/src/keypair/Address.ts +4 -0
|
@@ -12,34 +12,34 @@ export class BinaryWriter {
|
|
|
12
12
|
this.allocSafe(U8_BYTE_LENGTH);
|
|
13
13
|
this.buffer.setUint8(this.currentOffset++, value);
|
|
14
14
|
}
|
|
15
|
-
writeU16(value) {
|
|
15
|
+
writeU16(value, be = true) {
|
|
16
16
|
if (value > 65535)
|
|
17
17
|
throw new Error('u16 value is too large.');
|
|
18
18
|
this.allocSafe(U16_BYTE_LENGTH);
|
|
19
|
-
this.buffer.setUint16(this.currentOffset, value,
|
|
19
|
+
this.buffer.setUint16(this.currentOffset, value, !be);
|
|
20
20
|
this.currentOffset += 2;
|
|
21
21
|
}
|
|
22
|
-
writeU32(value,
|
|
22
|
+
writeU32(value, be = true) {
|
|
23
23
|
if (value > 4294967295)
|
|
24
24
|
throw new Error('u32 value is too large.');
|
|
25
25
|
this.allocSafe(U32_BYTE_LENGTH);
|
|
26
|
-
this.buffer.setUint32(this.currentOffset, value,
|
|
26
|
+
this.buffer.setUint32(this.currentOffset, value, !be);
|
|
27
27
|
this.currentOffset += 4;
|
|
28
28
|
}
|
|
29
|
-
writeU64(value) {
|
|
29
|
+
writeU64(value, be = true) {
|
|
30
30
|
if (value > 18446744073709551615n)
|
|
31
31
|
throw new Error('u64 value is too large.');
|
|
32
32
|
this.allocSafe(U64_BYTE_LENGTH);
|
|
33
|
-
this.buffer.setBigUint64(this.currentOffset, value,
|
|
33
|
+
this.buffer.setBigUint64(this.currentOffset, value, !be);
|
|
34
34
|
this.currentOffset += 8;
|
|
35
35
|
}
|
|
36
36
|
writeSelector(value) {
|
|
37
|
-
this.writeU32(value,
|
|
37
|
+
this.writeU32(value, true);
|
|
38
38
|
}
|
|
39
39
|
writeBoolean(value) {
|
|
40
40
|
this.writeU8(value ? 1 : 0);
|
|
41
41
|
}
|
|
42
|
-
writeI128(bigIntValue) {
|
|
42
|
+
writeI128(bigIntValue, be = true) {
|
|
43
43
|
if (bigIntValue > 170141183460469231731687303715884105727n ||
|
|
44
44
|
bigIntValue < -170141183460469231731687303715884105728n) {
|
|
45
45
|
throw new Error('i128 value is too large.');
|
|
@@ -49,35 +49,57 @@ export class BinaryWriter {
|
|
|
49
49
|
if (bytesToHex.byteLength !== I128_BYTE_LENGTH) {
|
|
50
50
|
throw new Error(`Invalid i128 value: ${bigIntValue}`);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (be) {
|
|
53
|
+
for (let i = 0; i < bytesToHex.byteLength; i++) {
|
|
54
|
+
this.writeU8(bytesToHex[i]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
for (let i = bytesToHex.byteLength - 1; i >= 0; i--) {
|
|
59
|
+
this.writeU8(bytesToHex[i]);
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
writeU256(bigIntValue) {
|
|
63
|
+
writeU256(bigIntValue, be = true) {
|
|
57
64
|
if (bigIntValue >
|
|
58
|
-
115792089237316195423570985008687907853269984665640564039457584007913129639935n
|
|
59
|
-
|
|
65
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935n &&
|
|
66
|
+
bigIntValue < 0n) {
|
|
67
|
+
throw new Error('u256 value is too large or negative.');
|
|
60
68
|
}
|
|
61
69
|
this.allocSafe(U256_BYTE_LENGTH);
|
|
62
70
|
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
|
|
63
71
|
if (bytesToHex.byteLength !== U256_BYTE_LENGTH) {
|
|
64
72
|
throw new Error(`Invalid u256 value: ${bigIntValue}`);
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
if (be) {
|
|
75
|
+
for (let i = 0; i < bytesToHex.byteLength; i++) {
|
|
76
|
+
this.writeU8(bytesToHex[i]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
for (let i = bytesToHex.byteLength - 1; i >= 0; i--) {
|
|
81
|
+
this.writeU8(bytesToHex[i]);
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
|
-
writeU128(bigIntValue) {
|
|
71
|
-
if (bigIntValue > 340282366920938463463374607431768211455n) {
|
|
72
|
-
throw new Error('u128 value is too large.');
|
|
85
|
+
writeU128(bigIntValue, be = true) {
|
|
86
|
+
if (bigIntValue > 340282366920938463463374607431768211455n && bigIntValue < 0n) {
|
|
87
|
+
throw new Error('u128 value is too large or negative.');
|
|
73
88
|
}
|
|
74
89
|
this.allocSafe(U128_BYTE_LENGTH);
|
|
75
90
|
const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, U128_BYTE_LENGTH);
|
|
76
91
|
if (bytesToHex.byteLength !== U128_BYTE_LENGTH) {
|
|
77
92
|
throw new Error(`Invalid u128 value: ${bigIntValue}`);
|
|
78
93
|
}
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
if (be) {
|
|
95
|
+
for (let i = 0; i < bytesToHex.byteLength; i++) {
|
|
96
|
+
this.writeU8(bytesToHex[i]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
for (let i = bytesToHex.byteLength - 1; i >= 0; i--) {
|
|
101
|
+
this.writeU8(bytesToHex[i]);
|
|
102
|
+
}
|
|
81
103
|
}
|
|
82
104
|
}
|
|
83
105
|
writeBytes(value) {
|
|
@@ -132,14 +154,10 @@ export class BinaryWriter {
|
|
|
132
154
|
this.resize(size);
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
|
-
|
|
136
|
-
this.writeStringWithLength(name);
|
|
137
|
-
this.writeSelector(selector);
|
|
138
|
-
}
|
|
139
|
-
writeAddressValueTuple(map) {
|
|
157
|
+
writeAddressValueTuple(map, be = true) {
|
|
140
158
|
if (map.size > 65535)
|
|
141
159
|
throw new Error('Map size is too large');
|
|
142
|
-
this.writeU16(map.size);
|
|
160
|
+
this.writeU16(map.size, be);
|
|
143
161
|
const keys = Array.from(map.keys());
|
|
144
162
|
for (let i = 0; i < keys.length; i++) {
|
|
145
163
|
const key = keys[i];
|
|
@@ -147,26 +165,7 @@ export class BinaryWriter {
|
|
|
147
165
|
if (value === null || value === undefined)
|
|
148
166
|
throw new Error('Value not found');
|
|
149
167
|
this.writeAddress(key);
|
|
150
|
-
this.writeU256(value);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
writeLimitedAddressBytesMap(map) {
|
|
154
|
-
if (map.size > 8)
|
|
155
|
-
throw new Error('Too many contract calls');
|
|
156
|
-
this.writeU8(map.size);
|
|
157
|
-
const keys = Array.from(map.keys());
|
|
158
|
-
for (let i = 0; i < keys.length; i++) {
|
|
159
|
-
const address = keys[i];
|
|
160
|
-
const calls = map.get(address);
|
|
161
|
-
if (!calls)
|
|
162
|
-
throw new Error('Calls not found');
|
|
163
|
-
if (calls.length > 10)
|
|
164
|
-
throw new Error('Too many calls.');
|
|
165
|
-
this.writeAddress(address);
|
|
166
|
-
this.writeU8(calls.length);
|
|
167
|
-
for (let j = 0; j < calls.length; j++) {
|
|
168
|
-
this.writeBytesWithLength(calls[j]);
|
|
169
|
-
}
|
|
168
|
+
this.writeU256(value, be);
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
writeBytesWithLength(value) {
|
|
@@ -181,28 +180,28 @@ export class BinaryWriter {
|
|
|
181
180
|
this.writeAddress(value[i]);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
|
-
writeU32Array(value) {
|
|
183
|
+
writeU32Array(value, be = true) {
|
|
185
184
|
if (value.length > 65535)
|
|
186
185
|
throw new Error('Array size is too large');
|
|
187
|
-
this.writeU16(value.length);
|
|
186
|
+
this.writeU16(value.length, be);
|
|
188
187
|
for (let i = 0; i < value.length; i++) {
|
|
189
|
-
this.writeU32(value[i]);
|
|
188
|
+
this.writeU32(value[i], be);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
writeU256Array(value) {
|
|
191
|
+
writeU256Array(value, be = true) {
|
|
193
192
|
if (value.length > 65535)
|
|
194
193
|
throw new Error('Array size is too large');
|
|
195
|
-
this.writeU16(value.length);
|
|
194
|
+
this.writeU16(value.length, be);
|
|
196
195
|
for (let i = 0; i < value.length; i++) {
|
|
197
|
-
this.writeU256(value[i]);
|
|
196
|
+
this.writeU256(value[i], be);
|
|
198
197
|
}
|
|
199
198
|
}
|
|
200
|
-
writeU128Array(value) {
|
|
199
|
+
writeU128Array(value, be = true) {
|
|
201
200
|
if (value.length > 65535)
|
|
202
201
|
throw new Error('Array size is too large');
|
|
203
|
-
this.writeU16(value.length);
|
|
202
|
+
this.writeU16(value.length, be);
|
|
204
203
|
for (let i = 0; i < value.length; i++) {
|
|
205
|
-
this.writeU128(value[i]);
|
|
204
|
+
this.writeU128(value[i], be);
|
|
206
205
|
}
|
|
207
206
|
}
|
|
208
207
|
writeStringArray(value) {
|
|
@@ -213,12 +212,12 @@ export class BinaryWriter {
|
|
|
213
212
|
this.writeStringWithLength(value[i]);
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
|
-
writeU16Array(value) {
|
|
215
|
+
writeU16Array(value, be = true) {
|
|
217
216
|
if (value.length > 65535)
|
|
218
217
|
throw new Error('Array size is too large');
|
|
219
|
-
this.writeU16(value.length);
|
|
218
|
+
this.writeU16(value.length, be);
|
|
220
219
|
for (let i = 0; i < value.length; i++) {
|
|
221
|
-
this.writeU16(value[i]);
|
|
220
|
+
this.writeU16(value[i], be);
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
223
|
writeU8Array(value) {
|
|
@@ -229,12 +228,12 @@ export class BinaryWriter {
|
|
|
229
228
|
this.writeU8(value[i]);
|
|
230
229
|
}
|
|
231
230
|
}
|
|
232
|
-
writeU64Array(value) {
|
|
231
|
+
writeU64Array(value, be = true) {
|
|
233
232
|
if (value.length > 65535)
|
|
234
233
|
throw new Error('Array size is too large');
|
|
235
|
-
this.writeU16(value.length);
|
|
234
|
+
this.writeU16(value.length, be);
|
|
236
235
|
for (let i = 0; i < value.length; i++) {
|
|
237
|
-
this.writeU64(value[i]);
|
|
236
|
+
this.writeU64(value[i], be);
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
239
|
writeBytesArray(value) {
|
|
@@ -245,27 +244,6 @@ export class BinaryWriter {
|
|
|
245
244
|
this.writeBytesWithLength(value[i]);
|
|
246
245
|
}
|
|
247
246
|
}
|
|
248
|
-
writeSelectorArray(value) {
|
|
249
|
-
if (value.length > 65535)
|
|
250
|
-
throw new Error('Array size is too large');
|
|
251
|
-
this.writeU16(value.length);
|
|
252
|
-
for (let i = 0; i < value.length; i++) {
|
|
253
|
-
this.writeSelector(value[i]);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
getChecksum() {
|
|
257
|
-
let checksum = 0;
|
|
258
|
-
for (let i = 0; i < this.buffer.byteLength; i++) {
|
|
259
|
-
checksum += this.buffer.getUint8(i);
|
|
260
|
-
}
|
|
261
|
-
return checksum % 2 ** 32;
|
|
262
|
-
}
|
|
263
|
-
writeMethodSelectorMap(value) {
|
|
264
|
-
this.writeU16(value.size);
|
|
265
|
-
value.forEach((selector, _value, _set) => {
|
|
266
|
-
this.writeSelector(selector);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
247
|
verifyAddress(pubKey) {
|
|
270
248
|
if (pubKey.byteLength > ADDRESS_BYTE_LENGTH) {
|
|
271
249
|
throw new Error(`Address is too long ${pubKey.byteLength} > ${ADDRESS_BYTE_LENGTH} bytes`);
|
|
@@ -5,6 +5,7 @@ export declare class Address extends Uint8Array {
|
|
|
5
5
|
get originalPublicKey(): Uint8Array | undefined;
|
|
6
6
|
private get keyPair();
|
|
7
7
|
static dead(): Address;
|
|
8
|
+
static zero(): Address;
|
|
8
9
|
static fromString(pubKey: string): Address;
|
|
9
10
|
static wrap(bytes: ArrayLike<number>): Address;
|
|
10
11
|
static uncompressedToCompressed(publicKey: ArrayLike<number>): Buffer;
|
package/build/keypair/Address.js
CHANGED
|
@@ -42,6 +42,9 @@ export class Address extends Uint8Array {
|
|
|
42
42
|
static dead() {
|
|
43
43
|
return Address.fromString('0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f');
|
|
44
44
|
}
|
|
45
|
+
static zero() {
|
|
46
|
+
return new Address();
|
|
47
|
+
}
|
|
45
48
|
static fromString(pubKey) {
|
|
46
49
|
if (!pubKey) {
|
|
47
50
|
throw new Error('Invalid public key');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/transaction",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"author": "BlobMaster41",
|
|
6
6
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
7
7
|
"engines": {
|
|
@@ -64,26 +64,26 @@
|
|
|
64
64
|
"docs": "typedoc --out docs --exclude 'src/tests/*.ts' --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/tests/test.ts --exclude src/index.ts src"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@babel/core": "^7.26.
|
|
67
|
+
"@babel/core": "^7.26.9",
|
|
68
68
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
69
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
70
|
-
"@babel/preset-env": "^7.26.
|
|
69
|
+
"@babel/plugin-transform-runtime": "^7.26.9",
|
|
70
|
+
"@babel/preset-env": "^7.26.9",
|
|
71
71
|
"@babel/preset-flow": "^7.25.9",
|
|
72
|
-
"@babel/preset-react": "^7.
|
|
72
|
+
"@babel/preset-react": "^7.26.3",
|
|
73
73
|
"@babel/preset-typescript": "^7.26.0",
|
|
74
|
-
"@types/node": "^22.10
|
|
74
|
+
"@types/node": "^22.13.10",
|
|
75
75
|
"@types/sha.js": "^2.4.4",
|
|
76
|
-
"eslint": "^9.
|
|
76
|
+
"eslint": "^9.22.0",
|
|
77
77
|
"gulp": "^5.0.0",
|
|
78
78
|
"gulp-cached": "^1.1.1",
|
|
79
79
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
80
80
|
"https-browserify": "^1.0.0",
|
|
81
81
|
"os-browserify": "^0.3.0",
|
|
82
|
-
"prettier": "^3.
|
|
82
|
+
"prettier": "^3.5.3",
|
|
83
83
|
"stream-browserify": "^3.0.0",
|
|
84
84
|
"stream-http": "^3.2.0",
|
|
85
|
-
"typedoc": "^0.27.
|
|
86
|
-
"typescript-eslint": "^8.
|
|
85
|
+
"typedoc": "^0.27.9",
|
|
86
|
+
"typescript-eslint": "^8.26.0",
|
|
87
87
|
"webpack-cli": "^6.0.1"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"@btc-vision/bitcoin": "^6.3.6",
|
|
93
93
|
"@btc-vision/bitcoin-rpc": "^1.0.0",
|
|
94
94
|
"@btc-vision/logger": "^1.0.6",
|
|
95
|
-
"@eslint/js": "^9.
|
|
95
|
+
"@eslint/js": "^9.22.0",
|
|
96
96
|
"@noble/secp256k1": "^2.1.0",
|
|
97
97
|
"assert": "^2.1.0",
|
|
98
98
|
"babel-loader": "^9.2.1",
|
|
99
|
-
"babel-plugin-transform-import-meta": "^2.2
|
|
99
|
+
"babel-plugin-transform-import-meta": "^2.3.2",
|
|
100
100
|
"babel-preset-react": "^6.24.1",
|
|
101
101
|
"babelify": "^10.0.0",
|
|
102
102
|
"bech32": "^2.0.0",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"gulp-logger-new": "^1.0.1",
|
|
111
111
|
"process": "^0.11.10",
|
|
112
112
|
"sha.js": "^2.4.11",
|
|
113
|
-
"ts-loader": "^9.5.
|
|
113
|
+
"ts-loader": "^9.5.2",
|
|
114
114
|
"ts-node": "^10.9.2",
|
|
115
|
-
"typescript": "^5.7.
|
|
116
|
-
"webpack": "^5.
|
|
115
|
+
"typescript": "^5.7.3",
|
|
116
|
+
"webpack": "^5.98.0"
|
|
117
117
|
}
|
|
118
118
|
}
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.
|
|
1
|
+
export const version = '1.3.0';
|