essential-eth 0.6.2 → 0.8.0

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.
Files changed (119) hide show
  1. package/dist/cjs/classes/Contract.js +307 -66
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
  3. package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
  5. package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
  6. package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
  7. package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
  8. package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
  9. package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
  10. package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
  11. package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
  12. package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
  13. package/dist/cjs/classes/utils/clean-block.js +52 -30
  14. package/dist/cjs/classes/utils/clean-log.js +42 -20
  15. package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
  16. package/dist/cjs/classes/utils/clean-transaction.js +52 -29
  17. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
  18. package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
  19. package/dist/cjs/classes/utils/fetchers.js +165 -41
  20. package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
  21. package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
  22. package/dist/cjs/index.js +25 -54
  23. package/dist/cjs/index.umd.js +1 -1
  24. package/dist/cjs/index.umd.js.map +1 -1
  25. package/dist/cjs/logger/logger.js +79 -23
  26. package/dist/cjs/logger/package-version.d.ts +1 -1
  27. package/dist/cjs/logger/package-version.js +1 -4
  28. package/dist/cjs/providers/BaseProvider.d.ts +2 -0
  29. package/dist/cjs/providers/BaseProvider.js +883 -475
  30. package/dist/cjs/providers/FallthroughProvider.js +118 -37
  31. package/dist/cjs/providers/JsonRpcProvider.js +93 -28
  32. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
  33. package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
  34. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
  35. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
  36. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
  37. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +212 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
  42. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
  43. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
  44. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
  45. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
  46. package/dist/cjs/providers/test/rpc-urls.js +9 -12
  47. package/dist/cjs/providers/utils/chains-info.js +1 -3
  48. package/dist/cjs/shared/tiny-big/helpers.js +93 -42
  49. package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
  50. package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
  51. package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
  52. package/dist/cjs/shared/validate-type.js +7 -7
  53. package/dist/cjs/types/Block.types.js +1 -2
  54. package/dist/cjs/types/Contract.types.js +1 -2
  55. package/dist/cjs/types/FeeData.types.d.ts +7 -0
  56. package/dist/cjs/types/FeeData.types.js +1 -0
  57. package/dist/cjs/types/Filter.types.js +1 -2
  58. package/dist/cjs/types/Network.types.js +3 -2
  59. package/dist/cjs/types/Transaction.types.js +1 -2
  60. package/dist/cjs/utils/bytes.js +286 -318
  61. package/dist/cjs/utils/compute-address.js +8 -14
  62. package/dist/cjs/utils/compute-public-key.js +5 -10
  63. package/dist/cjs/utils/ether-to-gwei.js +10 -11
  64. package/dist/cjs/utils/ether-to-wei.js +10 -11
  65. package/dist/cjs/utils/gwei-to-ether.js +10 -11
  66. package/dist/cjs/utils/hash-message.d.ts +1 -1
  67. package/dist/cjs/utils/hash-message.js +11 -14
  68. package/dist/cjs/utils/is-address.js +8 -12
  69. package/dist/cjs/utils/keccak256.js +8 -14
  70. package/dist/cjs/utils/solidity-keccak256.js +49 -60
  71. package/dist/cjs/utils/split-signature.js +55 -73
  72. package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
  73. package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
  74. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
  75. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
  76. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
  77. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
  78. package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
  79. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
  80. package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
  81. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
  82. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
  83. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
  84. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
  85. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
  86. package/dist/cjs/utils/tests/compute-address.test.js +27 -0
  87. package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
  88. package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
  89. package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
  90. package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
  91. package/dist/cjs/utils/tests/hash-message.test.js +21 -0
  92. package/dist/cjs/utils/tests/is-address.test.js +55 -0
  93. package/dist/cjs/utils/tests/keccak256.test.js +97 -0
  94. package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
  95. package/dist/cjs/utils/tests/split-signature.test.js +25 -0
  96. package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
  97. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
  98. package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
  99. package/dist/cjs/utils/to-checksum-address.js +15 -20
  100. package/dist/cjs/utils/to-utf8-bytes.js +1 -6
  101. package/dist/cjs/utils/wei-to-ether.js +13 -15
  102. package/dist/esm/classes/utils/clean-block.d.ts +1 -2
  103. package/dist/esm/classes/utils/clean-block.js +1 -1
  104. package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
  105. package/dist/esm/classes/utils/clean-transaction.js +2 -1
  106. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
  107. package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
  108. package/dist/esm/logger/package-version.d.ts +1 -1
  109. package/dist/esm/logger/package-version.js +1 -1
  110. package/dist/esm/providers/BaseProvider.d.ts +2 -0
  111. package/dist/esm/providers/BaseProvider.js +15 -0
  112. package/dist/esm/types/FeeData.types.d.ts +7 -0
  113. package/dist/esm/types/FeeData.types.js +1 -0
  114. package/dist/esm/utils/compute-address.js +2 -1
  115. package/dist/esm/utils/hash-message.d.ts +1 -1
  116. package/dist/esm/utils/hash-message.js +3 -1
  117. package/dist/esm/utils/is-address.js +1 -1
  118. package/package.json +10 -8
  119. package/readme.md +63 -3
@@ -1,8 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexZeroPad = exports.hexStripZeros = exports.hexValue = exports.hexConcat = exports.hexDataSlice = exports.hexDataLength = exports.hexlify = exports.isHexString = exports.zeroPad = exports.stripZeros = exports.concat = exports.arrayify = exports.isBytes = exports.isBytesLike = void 0;
4
1
  // primarily duplicate code from https://github.com/ethers-io/ethers.js/blob/f599d6f23dad0d0acaa3828d6b7acaab2d5e455b/packages/bytes/src.ts/index.ts
5
- const logger_1 = require("../logger/logger");
2
+ var _typeof = function(obj) {
3
+ "@swc/helpers - typeof";
4
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
+ };
6
+ import { logger } from "../logger/logger";
6
7
  /**
7
8
  * Check if a value can be converted to a hex string
8
9
  *
@@ -14,8 +15,7 @@ const logger_1 = require("../logger/logger");
14
15
  * isHexable(val);
15
16
  * // true
16
17
  * ```
17
- */
18
- function isHexable(value) {
18
+ */ function isHexable(value) {
19
19
  return !!value.toHexString;
20
20
  }
21
21
  /**
@@ -39,11 +39,9 @@ function isHexable(value) {
39
39
  * isBytesLike(new Uint8Array(1));
40
40
  * // true
41
41
  * ```
42
- */
43
- function isBytesLike(value) {
44
- return (isHexString(value) && !(value.length % 2)) || isBytes(value);
42
+ */ export function isBytesLike(value) {
43
+ return isHexString(value) && !(value.length % 2) || isBytes(value);
45
44
  }
46
- exports.isBytesLike = isBytesLike;
47
45
  /**
48
46
  * Checks if a value is an integer
49
47
  *
@@ -59,9 +57,8 @@ exports.isBytesLike = isBytesLike;
59
57
  * isInteger(6.2)
60
58
  * // false
61
59
  * ```
62
- */
63
- function isInteger(value) {
64
- return typeof value === 'number' && value == value && value % 1 === 0;
60
+ */ function isInteger(value) {
61
+ return typeof value === "number" && value == value && value % 1 === 0;
65
62
  }
66
63
  /**
67
64
  * Returns true if and only if value is a valid [Bytes](#bytes)
@@ -84,29 +81,27 @@ function isInteger(value) {
84
81
  * isBytes(new Uint8Array(1));
85
82
  * // true
86
83
  * ```
87
- */
88
- function isBytes(value) {
84
+ */ export function isBytes(value) {
89
85
  if (value == null) {
90
86
  return false;
91
87
  }
92
88
  if (value.constructor === Uint8Array) {
93
89
  return true;
94
90
  }
95
- if (typeof value === 'string') {
91
+ if (typeof value === "string") {
96
92
  return false;
97
93
  }
98
94
  if (!isInteger(value.length) || value.length < 0) {
99
95
  return false;
100
96
  }
101
- for (let i = 0; i < value.length; i++) {
102
- const v = value[i];
97
+ for(var i = 0; i < value.length; i++){
98
+ var v = value[i];
103
99
  if (!isInteger(v) || v < 0 || v >= 256) {
104
100
  return false;
105
101
  }
106
102
  }
107
103
  return true;
108
104
  }
109
- exports.isBytes = isBytes;
110
105
  /**
111
106
  * Converts DataHexStringOrArrayish to a Uint8Array
112
107
  * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
@@ -129,15 +124,14 @@ exports.isBytes = isBytes;
129
124
  * arrayify('0x1', { hexPad: 'right' });
130
125
  * // Uint8Array(1) [ 16 ]
131
126
  * ```
132
- */
133
- function arrayify(value, options) {
127
+ */ export function arrayify(value, options) {
134
128
  if (!options) {
135
129
  options = {};
136
130
  }
137
- if (typeof value === 'number') {
138
- logger_1.logger.checkSafeUint53(value, 'invalid arrayify value');
139
- const result = [];
140
- while (value) {
131
+ if (typeof value === "number") {
132
+ logger.checkSafeUint53(value, "invalid arrayify value");
133
+ var result = [];
134
+ while(value){
141
135
  result.unshift(value & 0xff);
142
136
  value = parseInt(String(value / 256));
143
137
  }
@@ -146,39 +140,34 @@ function arrayify(value, options) {
146
140
  }
147
141
  return new Uint8Array(result);
148
142
  }
149
- if (options.allowMissingPrefix &&
150
- typeof value === 'string' &&
151
- value.substring(0, 2) !== '0x') {
152
- value = '0x' + value;
143
+ if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
144
+ value = "0x" + value;
153
145
  }
154
146
  if (isHexable(value)) {
155
147
  value = value.toHexString();
156
148
  }
157
149
  if (isHexString(value)) {
158
- let hex = value.substring(2);
150
+ var hex = value.substring(2);
159
151
  if (hex.length % 2) {
160
- if (options.hexPad === 'left') {
161
- hex = '0' + hex;
162
- }
163
- else if (options.hexPad === 'right') {
164
- hex += '0';
165
- }
166
- else {
167
- logger_1.logger.throwArgumentError('hex data is odd-length', 'value', value);
152
+ if (options.hexPad === "left") {
153
+ hex = "0" + hex;
154
+ } else if (options.hexPad === "right") {
155
+ hex += "0";
156
+ } else {
157
+ logger.throwArgumentError("hex data is odd-length", "value", value);
168
158
  }
169
159
  }
170
- const result = [];
171
- for (let i = 0; i < hex.length; i += 2) {
172
- result.push(parseInt(hex.substring(i, i + 2), 16));
160
+ var result1 = [];
161
+ for(var i = 0; i < hex.length; i += 2){
162
+ result1.push(parseInt(hex.substring(i, i + 2), 16));
173
163
  }
174
- return new Uint8Array(result);
164
+ return new Uint8Array(result1);
175
165
  }
176
166
  if (isBytes(value)) {
177
167
  return new Uint8Array(value);
178
168
  }
179
- return logger_1.logger.throwArgumentError('invalid arrayify value', 'value', value);
169
+ return logger.throwArgumentError("invalid arrayify value", "value", value);
180
170
  }
181
- exports.arrayify = arrayify;
182
171
  /**
183
172
  * Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
184
173
  * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
@@ -190,18 +179,20 @@ exports.arrayify = arrayify;
190
179
  * concat([0, 1]);
191
180
  * // Uint8Array(2) [ 0, 1 ]
192
181
  * ```
193
- */
194
- function concat(arrayOfBytesLike) {
195
- const objects = arrayOfBytesLike.map((item) => arrayify(item));
196
- const length = objects.reduce((accum, item) => accum + item.length, 0);
197
- const result = new Uint8Array(length);
198
- objects.reduce((offset, object) => {
182
+ */ export function concat(arrayOfBytesLike) {
183
+ var objects = arrayOfBytesLike.map(function(item) {
184
+ return arrayify(item);
185
+ });
186
+ var length = objects.reduce(function(accum, item) {
187
+ return accum + item.length;
188
+ }, 0);
189
+ var result = new Uint8Array(length);
190
+ objects.reduce(function(offset, object) {
199
191
  result.set(object, offset);
200
192
  return offset + object.length;
201
193
  }, 0);
202
194
  return result;
203
195
  }
204
- exports.concat = concat;
205
196
  /**
206
197
  * Strips leading zeros from a BytesLike object
207
198
  *
@@ -213,15 +204,14 @@ exports.concat = concat;
213
204
  * // Uint8Array { [Iterator] 0: 40, 1: 52 }
214
205
  * // Equivalent to '0x2834'
215
206
  * ```
216
- */
217
- function stripZeros(value) {
218
- let result = arrayify(value);
207
+ */ export function stripZeros(value) {
208
+ var result = arrayify(value);
219
209
  if (result.length === 0) {
220
210
  return result;
221
211
  }
222
212
  // Find the first non-zero entry
223
- let start = 0;
224
- while (start < result.length && result[start] === 0) {
213
+ var start = 0;
214
+ while(start < result.length && result[start] === 0){
225
215
  start++;
226
216
  }
227
217
  // If we started with zeros, strip them
@@ -230,7 +220,6 @@ function stripZeros(value) {
230
220
  }
231
221
  return result;
232
222
  }
233
- exports.stripZeros = stripZeros;
234
223
  /**
235
224
  * Pads the beginning of a {@link BytesLike} with zeros so it's the specified length as a Uint8Array
236
225
  *
@@ -248,17 +237,15 @@ exports.stripZeros = stripZeros;
248
237
  * zeroPad([39, 25, 103, 45], 5);
249
238
  * // Uint8Array { [Iterator] 0: 0, 1: 39, 2: 25, 3: 103, 4: 45 }
250
239
  * ```
251
- */
252
- function zeroPad(value, length) {
240
+ */ export function zeroPad(value, length) {
253
241
  value = arrayify(value);
254
242
  if (value.length > length) {
255
- logger_1.logger.throwArgumentError('value out of range', 'value', value);
243
+ logger.throwArgumentError("value out of range", "value", value);
256
244
  }
257
- const result = new Uint8Array(length);
245
+ var result = new Uint8Array(length);
258
246
  result.set(value, length - value.length);
259
247
  return result;
260
248
  }
261
- exports.zeroPad = zeroPad;
262
249
  /**
263
250
  * Returns true if and only if object is a valid hex string.
264
251
  * If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
@@ -278,9 +265,8 @@ exports.zeroPad = zeroPad;
278
265
  * // false
279
266
  * // length of 4 in bytes would mean a hex string with 8 characters
280
267
  * ```
281
- */
282
- function isHexString(value, length) {
283
- if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
268
+ */ export function isHexString(value, length) {
269
+ if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
284
270
  return false;
285
271
  }
286
272
  if (length && value.length !== 2 + 2 * length) {
@@ -288,8 +274,7 @@ function isHexString(value, length) {
288
274
  }
289
275
  return true;
290
276
  }
291
- exports.isHexString = isHexString;
292
- const HexCharacters = '0123456789abcdef';
277
+ var HexCharacters = "0123456789abcdef";
293
278
  /**
294
279
  * Converts a value into a hex string
295
280
  *
@@ -306,66 +291,60 @@ const HexCharacters = '0123456789abcdef';
306
291
  * hexlify(14);
307
292
  * // '0x0e'
308
293
  * ```
309
- */
310
- function hexlify(value, options) {
294
+ */ export function hexlify(value, options) {
311
295
  if (!options) {
312
296
  options = {};
313
297
  }
314
- if (typeof value === 'number') {
315
- logger_1.logger.checkSafeUint53(value, 'invalid hexlify value');
316
- let hex = '';
317
- while (value) {
298
+ if (typeof value === "number") {
299
+ logger.checkSafeUint53(value, "invalid hexlify value");
300
+ var hex = "";
301
+ while(value){
318
302
  hex = HexCharacters[value & 0xf] + hex;
319
303
  value = Math.floor(value / 16);
320
304
  }
321
305
  if (hex.length) {
322
306
  if (hex.length % 2) {
323
- hex = '0' + hex;
307
+ hex = "0" + hex;
324
308
  }
325
- return '0x' + hex;
309
+ return "0x" + hex;
326
310
  }
327
- return '0x00';
311
+ return "0x00";
328
312
  }
329
- if (typeof value === 'bigint') {
313
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint") {
330
314
  value = value.toString(16);
331
315
  if (value.length % 2) {
332
- return '0x0' + value;
316
+ return "0x0" + value;
333
317
  }
334
- return '0x' + value;
318
+ return "0x" + value;
335
319
  }
336
- if (options.allowMissingPrefix &&
337
- typeof value === 'string' &&
338
- value.substring(0, 2) !== '0x') {
339
- value = '0x' + value;
320
+ if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
321
+ value = "0x" + value;
340
322
  }
341
323
  if (isHexable(value)) {
342
324
  return value.toHexString();
343
325
  }
344
326
  if (isHexString(value)) {
345
327
  if (value.length % 2) {
346
- if (options.hexPad === 'left') {
347
- value = '0x0' + value.substring(2);
348
- }
349
- else if (options.hexPad === 'right') {
350
- value += '0';
351
- }
352
- else {
353
- logger_1.logger.throwArgumentError('hex data is odd-length', 'value', value);
328
+ if (options.hexPad === "left") {
329
+ value = "0x0" + value.substring(2);
330
+ } else if (options.hexPad === "right") {
331
+ value += "0";
332
+ } else {
333
+ logger.throwArgumentError("hex data is odd-length", "value", value);
354
334
  }
355
335
  }
356
336
  return value.toLowerCase();
357
337
  }
358
338
  if (isBytes(value)) {
359
- let result = '0x';
360
- for (let i = 0; i < value.length; i++) {
361
- const v = value[i];
339
+ var result = "0x";
340
+ for(var i = 0; i < value.length; i++){
341
+ var v = value[i];
362
342
  result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
363
343
  }
364
344
  return result;
365
345
  }
366
- return logger_1.logger.throwArgumentError('invalid hexlify value', 'value', value);
346
+ return logger.throwArgumentError("invalid hexlify value", "value", value);
367
347
  }
368
- exports.hexlify = hexlify;
369
348
  /**
370
349
  * Gets the length of data represented as a hex string
371
350
  *
@@ -381,17 +360,14 @@ exports.hexlify = hexlify;
381
360
  * hexDataLength('0x3925');
382
361
  * // 2
383
362
  * ```
384
- */
385
- function hexDataLength(data) {
386
- if (typeof data !== 'string') {
363
+ */ export function hexDataLength(data) {
364
+ if (typeof data !== "string") {
387
365
  data = hexlify(data);
388
- }
389
- else if (!isHexString(data) || data.length % 2) {
366
+ } else if (!isHexString(data) || data.length % 2) {
390
367
  return null;
391
368
  }
392
369
  return (data.length - 2) / 2;
393
370
  }
394
- exports.hexDataLength = hexDataLength;
395
371
  /**
396
372
  * Slices a {@link BytesLike} to extract a certain part of the input
397
373
  *
@@ -404,21 +380,18 @@ exports.hexDataLength = hexDataLength;
404
380
  * hexDataSlice([20, 6, 48], 0, 2);
405
381
  * // '0x1406'
406
382
  * ```
407
- */
408
- function hexDataSlice(data, offset, endOffset) {
409
- if (typeof data !== 'string') {
383
+ */ export function hexDataSlice(data, offset, endOffset) {
384
+ if (typeof data !== "string") {
410
385
  data = hexlify(data);
411
- }
412
- else if (!isHexString(data) || data.length % 2) {
413
- logger_1.logger.throwArgumentError('invalid hexData', 'value', data);
386
+ } else if (!isHexString(data) || data.length % 2) {
387
+ logger.throwArgumentError("invalid hexData", "value", data);
414
388
  }
415
389
  offset = 2 + 2 * offset;
416
390
  if (endOffset != null) {
417
- return '0x' + data.substring(offset, 2 + 2 * endOffset);
391
+ return "0x" + data.substring(offset, 2 + 2 * endOffset);
418
392
  }
419
- return '0x' + data.substring(offset);
393
+ return "0x" + data.substring(offset);
420
394
  }
421
- exports.hexDataSlice = hexDataSlice;
422
395
  /**
423
396
  * Concatenates values together into one hex string
424
397
  *
@@ -429,15 +402,13 @@ exports.hexDataSlice = hexDataSlice;
429
402
  * hexConcat([[2, 4, 0, 1], 9, '0x2934', '0x3947']);
430
403
  * // '0x020400010929343947'
431
404
  * ```
432
- */
433
- function hexConcat(items) {
434
- let result = '0x';
435
- items.forEach((item) => {
405
+ */ export function hexConcat(items) {
406
+ var result = "0x";
407
+ items.forEach(function(item) {
436
408
  result += hexlify(item).substring(2);
437
409
  });
438
410
  return result;
439
411
  }
440
- exports.hexConcat = hexConcat;
441
412
  /**
442
413
  * Converts a number of different types into a hex string
443
414
  *
@@ -453,15 +424,15 @@ exports.hexConcat = hexConcat;
453
424
  * hexValue([9, 4, 19, 4]);
454
425
  * // '0x9041304'
455
426
  * ```
456
- */
457
- function hexValue(value) {
458
- const trimmed = hexStripZeros(hexlify(value, { hexPad: 'left' }));
459
- if (trimmed === '0x') {
460
- return '0x0';
427
+ */ export function hexValue(value) {
428
+ var trimmed = hexStripZeros(hexlify(value, {
429
+ hexPad: "left"
430
+ }));
431
+ if (trimmed === "0x") {
432
+ return "0x0";
461
433
  }
462
434
  return trimmed;
463
435
  }
464
- exports.hexValue = hexValue;
465
436
  /**
466
437
  * Strips the leading zeros from a value and returns it as a hex string
467
438
  *
@@ -472,22 +443,20 @@ exports.hexValue = hexValue;
472
443
  * hexStripZeros([0,0,0,48]);
473
444
  * // '0x30'
474
445
  * ```
475
- */
476
- function hexStripZeros(value) {
477
- if (typeof value !== 'string') {
446
+ */ export function hexStripZeros(value) {
447
+ if (typeof value !== "string") {
478
448
  value = hexlify(value);
479
449
  }
480
450
  if (!isHexString(value)) {
481
- logger_1.logger.throwArgumentError('invalid hex string', 'value', value);
451
+ logger.throwArgumentError("invalid hex string", "value", value);
482
452
  }
483
453
  value = value.substring(2);
484
- let offset = 0;
485
- while (offset < value.length && value[offset] === '0') {
454
+ var offset = 0;
455
+ while(offset < value.length && value[offset] === "0"){
486
456
  offset++;
487
457
  }
488
- return '0x' + value.substring(offset);
458
+ return "0x" + value.substring(offset);
489
459
  }
490
- exports.hexStripZeros = hexStripZeros;
491
460
  /**
492
461
  * Returns a hex string padded to a specified length of bytes.
493
462
  *
@@ -515,197 +484,196 @@ exports.hexStripZeros = hexStripZeros;
515
484
  * hexZeroPad('12345', 1);
516
485
  * // Throws
517
486
  * ```
518
- */
519
- function hexZeroPad(value, length) {
520
- if (typeof value !== 'string') {
487
+ */ export function hexZeroPad(value, length) {
488
+ if (typeof value !== "string") {
521
489
  value = hexlify(value);
522
- }
523
- else if (!isHexString(value)) {
524
- logger_1.logger.throwArgumentError('invalid hex string', 'value', value);
490
+ } else if (!isHexString(value)) {
491
+ logger.throwArgumentError("invalid hex string", "value", value);
525
492
  }
526
493
  if (value.length > 2 * length + 2) {
527
- logger_1.logger.throwError('value out of range', { value, length });
494
+ logger.throwError("value out of range", {
495
+ value: value,
496
+ length: length
497
+ });
528
498
  }
529
- while (value.length < 2 * length + 2) {
530
- value = '0x0' + value.substring(2);
499
+ while(value.length < 2 * length + 2){
500
+ value = "0x0" + value.substring(2);
531
501
  }
532
502
  return value;
533
- }
534
- exports.hexZeroPad = hexZeroPad;
535
- // export function splitSignature(signature: SignatureLike): Signature {
536
- // const result: Signature = {
537
- // r: '0x',
538
- // s: '0x',
539
- // _vs: '0x',
540
- // recoveryParam: 0,
541
- // v: 0,
542
- // yParityAndS: '0x',
543
- // compact: '0x',
544
- // };
545
- // if (isBytesLike(signature)) {
546
- // const bytes: Uint8Array = arrayify(signature);
547
- // // Get the r, s and v
548
- // if (bytes.length === 64) {
549
- // // EIP-2098; pull the v from the top bit of s and clear it
550
- // result.v = 27 + (bytes[32] >> 7);
551
- // bytes[32] &= 0x7f;
552
- // result.r = hexlify(bytes.slice(0, 32));
553
- // result.s = hexlify(bytes.slice(32, 64));
554
- // } else if (bytes.length === 65) {
555
- // result.r = hexlify(bytes.slice(0, 32));
556
- // result.s = hexlify(bytes.slice(32, 64));
557
- // result.v = bytes[64];
558
- // } else {
559
- // logger.throwArgumentError(
560
- // 'invalid signature string',
561
- // 'signature',
562
- // signature,
563
- // );
564
- // }
565
- // // Allow a recid to be used as the v
566
- // if (result.v < 27) {
567
- // if (result.v === 0 || result.v === 1) {
568
- // result.v += 27;
569
- // } else {
570
- // logger.throwArgumentError(
571
- // 'signature invalid v byte',
572
- // 'signature',
573
- // signature,
574
- // );
575
- // }
576
- // }
577
- // // Compute recoveryParam from v
578
- // result.recoveryParam = 1 - (result.v % 2);
579
- // // Compute _vs from recoveryParam and s
580
- // if (result.recoveryParam) {
581
- // bytes[32] |= 0x80;
582
- // }
583
- // result._vs = hexlify(bytes.slice(32, 64));
584
- // } else {
585
- // result.r = signature.r;
586
- // result.s = signature.s;
587
- // result.v = signature.v;
588
- // result.recoveryParam = signature.recoveryParam;
589
- // result._vs = signature._vs;
590
- // // If the _vs is available, use it to populate missing s, v and recoveryParam
591
- // // and verify non-missing s, v and recoveryParam
592
- // if (result._vs != null) {
593
- // const vs = zeroPad(arrayify(result._vs), 32);
594
- // result._vs = hexlify(vs);
595
- // // Set or check the recid
596
- // const recoveryParam = vs[0] >= 128 ? 1 : 0;
597
- // if (result.recoveryParam == null) {
598
- // result.recoveryParam = recoveryParam;
599
- // } else if (result.recoveryParam !== recoveryParam) {
600
- // logger.throwArgumentError(
601
- // 'signature recoveryParam mismatch _vs',
602
- // 'signature',
603
- // signature,
604
- // );
605
- // }
606
- // // Set or check the s
607
- // vs[0] &= 0x7f;
608
- // const s = hexlify(vs);
609
- // if (result.s == null) {
610
- // result.s = s;
611
- // } else if (result.s !== s) {
612
- // logger.throwArgumentError(
613
- // 'signature v mismatch _vs',
614
- // 'signature',
615
- // signature,
616
- // );
617
- // }
618
- // }
619
- // // Use recid and v to populate each other
620
- // if (result.recoveryParam == null) {
621
- // if (result.v == null) {
622
- // logger.throwArgumentError(
623
- // 'signature missing v and recoveryParam',
624
- // 'signature',
625
- // signature,
626
- // );
627
- // } else if (result.v === 0 || result.v === 1) {
628
- // result.recoveryParam = result.v;
629
- // } else {
630
- // result.recoveryParam = 1 - (result.v % 2);
631
- // }
632
- // } else {
633
- // if (result.v == null) {
634
- // result.v = 27 + result.recoveryParam;
635
- // } else {
636
- // const recId =
637
- // result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
638
- // if (result.recoveryParam !== recId) {
639
- // logger.throwArgumentError(
640
- // 'signature recoveryParam mismatch v',
641
- // 'signature',
642
- // signature,
643
- // );
644
- // }
645
- // }
646
- // }
647
- // if (result.r == null || !isHexString(result.r)) {
648
- // logger.throwArgumentError(
649
- // 'signature missing or invalid r',
650
- // 'signature',
651
- // signature,
652
- // );
653
- // } else {
654
- // result.r = hexZeroPad(result.r, 32);
655
- // }
656
- // if (result.s == null || !isHexString(result.s)) {
657
- // logger.throwArgumentError(
658
- // 'signature missing or invalid s',
659
- // 'signature',
660
- // signature,
661
- // );
662
- // } else {
663
- // result.s = hexZeroPad(result.s, 32);
664
- // }
665
- // const vs = arrayify(result.s);
666
- // if (vs[0] >= 128) {
667
- // logger.throwArgumentError(
668
- // 'signature s out of range',
669
- // 'signature',
670
- // signature,
671
- // );
672
- // }
673
- // if (result.recoveryParam) {
674
- // vs[0] |= 0x80;
675
- // }
676
- // const _vs = hexlify(vs);
677
- // if (result._vs) {
678
- // if (!isHexString(result._vs)) {
679
- // logger.throwArgumentError(
680
- // 'signature invalid _vs',
681
- // 'signature',
682
- // signature,
683
- // );
684
- // }
685
- // result._vs = hexZeroPad(result._vs, 32);
686
- // }
687
- // // Set or check the _vs
688
- // if (result._vs == null) {
689
- // result._vs = _vs;
690
- // } else if (result._vs !== _vs) {
691
- // logger.throwArgumentError(
692
- // 'signature _vs mismatch v and s',
693
- // 'signature',
694
- // signature,
695
- // );
696
- // }
697
- // }
698
- // result.yParityAndS = result._vs;
699
- // result.compact = result.r + result.yParityAndS.substring(2);
700
- // return result;
701
- // }
702
- // export function joinSignature(signature: SignatureLike): string {
703
- // signature = splitSignature(signature);
704
- // return hexlify(
705
- // concat([
706
- // signature.r,
707
- // signature.s,
708
- // signature.recoveryParam ? '0x1c' : '0x1b',
709
- // ]),
710
- // );
711
- // }
503
+ } // export function splitSignature(signature: SignatureLike): Signature {
504
+ // const result: Signature = {
505
+ // r: '0x',
506
+ // s: '0x',
507
+ // _vs: '0x',
508
+ // recoveryParam: 0,
509
+ // v: 0,
510
+ // yParityAndS: '0x',
511
+ // compact: '0x',
512
+ // };
513
+ // if (isBytesLike(signature)) {
514
+ // const bytes: Uint8Array = arrayify(signature);
515
+ // // Get the r, s and v
516
+ // if (bytes.length === 64) {
517
+ // // EIP-2098; pull the v from the top bit of s and clear it
518
+ // result.v = 27 + (bytes[32] >> 7);
519
+ // bytes[32] &= 0x7f;
520
+ // result.r = hexlify(bytes.slice(0, 32));
521
+ // result.s = hexlify(bytes.slice(32, 64));
522
+ // } else if (bytes.length === 65) {
523
+ // result.r = hexlify(bytes.slice(0, 32));
524
+ // result.s = hexlify(bytes.slice(32, 64));
525
+ // result.v = bytes[64];
526
+ // } else {
527
+ // logger.throwArgumentError(
528
+ // 'invalid signature string',
529
+ // 'signature',
530
+ // signature,
531
+ // );
532
+ // }
533
+ // // Allow a recid to be used as the v
534
+ // if (result.v < 27) {
535
+ // if (result.v === 0 || result.v === 1) {
536
+ // result.v += 27;
537
+ // } else {
538
+ // logger.throwArgumentError(
539
+ // 'signature invalid v byte',
540
+ // 'signature',
541
+ // signature,
542
+ // );
543
+ // }
544
+ // }
545
+ // // Compute recoveryParam from v
546
+ // result.recoveryParam = 1 - (result.v % 2);
547
+ // // Compute _vs from recoveryParam and s
548
+ // if (result.recoveryParam) {
549
+ // bytes[32] |= 0x80;
550
+ // }
551
+ // result._vs = hexlify(bytes.slice(32, 64));
552
+ // } else {
553
+ // result.r = signature.r;
554
+ // result.s = signature.s;
555
+ // result.v = signature.v;
556
+ // result.recoveryParam = signature.recoveryParam;
557
+ // result._vs = signature._vs;
558
+ // // If the _vs is available, use it to populate missing s, v and recoveryParam
559
+ // // and verify non-missing s, v and recoveryParam
560
+ // if (result._vs != null) {
561
+ // const vs = zeroPad(arrayify(result._vs), 32);
562
+ // result._vs = hexlify(vs);
563
+ // // Set or check the recid
564
+ // const recoveryParam = vs[0] >= 128 ? 1 : 0;
565
+ // if (result.recoveryParam == null) {
566
+ // result.recoveryParam = recoveryParam;
567
+ // } else if (result.recoveryParam !== recoveryParam) {
568
+ // logger.throwArgumentError(
569
+ // 'signature recoveryParam mismatch _vs',
570
+ // 'signature',
571
+ // signature,
572
+ // );
573
+ // }
574
+ // // Set or check the s
575
+ // vs[0] &= 0x7f;
576
+ // const s = hexlify(vs);
577
+ // if (result.s == null) {
578
+ // result.s = s;
579
+ // } else if (result.s !== s) {
580
+ // logger.throwArgumentError(
581
+ // 'signature v mismatch _vs',
582
+ // 'signature',
583
+ // signature,
584
+ // );
585
+ // }
586
+ // }
587
+ // // Use recid and v to populate each other
588
+ // if (result.recoveryParam == null) {
589
+ // if (result.v == null) {
590
+ // logger.throwArgumentError(
591
+ // 'signature missing v and recoveryParam',
592
+ // 'signature',
593
+ // signature,
594
+ // );
595
+ // } else if (result.v === 0 || result.v === 1) {
596
+ // result.recoveryParam = result.v;
597
+ // } else {
598
+ // result.recoveryParam = 1 - (result.v % 2);
599
+ // }
600
+ // } else {
601
+ // if (result.v == null) {
602
+ // result.v = 27 + result.recoveryParam;
603
+ // } else {
604
+ // const recId =
605
+ // result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
606
+ // if (result.recoveryParam !== recId) {
607
+ // logger.throwArgumentError(
608
+ // 'signature recoveryParam mismatch v',
609
+ // 'signature',
610
+ // signature,
611
+ // );
612
+ // }
613
+ // }
614
+ // }
615
+ // if (result.r == null || !isHexString(result.r)) {
616
+ // logger.throwArgumentError(
617
+ // 'signature missing or invalid r',
618
+ // 'signature',
619
+ // signature,
620
+ // );
621
+ // } else {
622
+ // result.r = hexZeroPad(result.r, 32);
623
+ // }
624
+ // if (result.s == null || !isHexString(result.s)) {
625
+ // logger.throwArgumentError(
626
+ // 'signature missing or invalid s',
627
+ // 'signature',
628
+ // signature,
629
+ // );
630
+ // } else {
631
+ // result.s = hexZeroPad(result.s, 32);
632
+ // }
633
+ // const vs = arrayify(result.s);
634
+ // if (vs[0] >= 128) {
635
+ // logger.throwArgumentError(
636
+ // 'signature s out of range',
637
+ // 'signature',
638
+ // signature,
639
+ // );
640
+ // }
641
+ // if (result.recoveryParam) {
642
+ // vs[0] |= 0x80;
643
+ // }
644
+ // const _vs = hexlify(vs);
645
+ // if (result._vs) {
646
+ // if (!isHexString(result._vs)) {
647
+ // logger.throwArgumentError(
648
+ // 'signature invalid _vs',
649
+ // 'signature',
650
+ // signature,
651
+ // );
652
+ // }
653
+ // result._vs = hexZeroPad(result._vs, 32);
654
+ // }
655
+ // // Set or check the _vs
656
+ // if (result._vs == null) {
657
+ // result._vs = _vs;
658
+ // } else if (result._vs !== _vs) {
659
+ // logger.throwArgumentError(
660
+ // 'signature _vs mismatch v and s',
661
+ // 'signature',
662
+ // signature,
663
+ // );
664
+ // }
665
+ // }
666
+ // result.yParityAndS = result._vs;
667
+ // result.compact = result.r + result.yParityAndS.substring(2);
668
+ // return result;
669
+ // }
670
+ // export function joinSignature(signature: SignatureLike): string {
671
+ // signature = splitSignature(signature);
672
+ // return hexlify(
673
+ // concat([
674
+ // signature.r,
675
+ // signature.s,
676
+ // signature.recoveryParam ? '0x1c' : '0x1b',
677
+ // ]),
678
+ // );
679
+ // }