essential-eth 0.5.4 → 0.5.9
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/lib/cjs/classes/Contract.d.ts +10 -4
- package/lib/cjs/classes/Contract.js +15 -4
- package/lib/cjs/classes/utils/clean-block.d.ts +115 -0
- package/lib/cjs/classes/utils/clean-block.js +122 -9
- package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-log.js +37 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +11 -16
- package/lib/cjs/classes/utils/clean-transaction.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction.js +10 -1
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +12 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.js +24 -0
- package/lib/cjs/classes/utils/fetchers.d.ts +31 -1
- package/lib/cjs/classes/utils/fetchers.js +30 -0
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +14 -1
- package/lib/cjs/classes/utils/hex-to-decimal.js +14 -1
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
- package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
- package/lib/cjs/index.d.ts +10 -5
- package/lib/cjs/index.js +10 -2
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +282 -199
- package/lib/cjs/providers/BaseProvider.js +365 -214
- package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
- package/lib/cjs/providers/JsonRpcProvider.d.ts +6 -0
- package/lib/cjs/providers/JsonRpcProvider.js +6 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +27 -0
- package/lib/cjs/providers/utils/chains-info.js +84 -3
- package/lib/cjs/shared/tiny-big/helpers.d.ts +16 -0
- package/lib/cjs/shared/tiny-big/helpers.js +27 -1
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +30 -4
- package/lib/cjs/shared/tiny-big/tiny-big.js +34 -4
- package/lib/cjs/types/Block.types.d.ts +11 -7
- package/lib/cjs/types/Filter.types.d.ts +16 -0
- package/lib/cjs/types/Filter.types.js +2 -0
- package/lib/cjs/types/Transaction.types.d.ts +33 -6
- package/lib/cjs/utils/bytes.d.ts +150 -33
- package/lib/cjs/utils/bytes.js +179 -32
- package/lib/cjs/utils/compute-address.d.ts +17 -0
- package/lib/cjs/utils/compute-address.js +33 -0
- package/lib/cjs/utils/compute-public-key.d.ts +18 -0
- package/lib/cjs/utils/compute-public-key.js +26 -0
- package/lib/cjs/utils/ether-to-gwei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-gwei.js +2 -1
- package/lib/cjs/utils/ether-to-wei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-wei.js +2 -1
- package/lib/cjs/utils/gwei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/gwei-to-ether.js +2 -1
- package/lib/cjs/utils/hash-message.d.ts +3 -1
- package/lib/cjs/utils/hash-message.js +3 -1
- package/lib/cjs/utils/is-address.d.ts +2 -2
- package/lib/cjs/utils/is-address.js +2 -2
- package/lib/cjs/utils/keccak256.d.ts +15 -1
- package/lib/cjs/utils/keccak256.js +16 -2
- package/lib/cjs/utils/solidity-keccak256.d.ts +17 -7
- package/lib/cjs/utils/solidity-keccak256.js +27 -7
- package/lib/cjs/utils/split-signature.d.ts +24 -0
- package/lib/cjs/utils/split-signature.js +163 -0
- package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
- package/lib/cjs/utils/to-checksum-address.js +2 -2
- package/lib/cjs/utils/to-utf8-bytes.d.ts +14 -0
- package/lib/cjs/utils/to-utf8-bytes.js +14 -0
- package/lib/cjs/utils/wei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/wei-to-ether.js +14 -3
- package/lib/esm/classes/utils/clean-block.js +7 -8
- package/lib/esm/classes/utils/clean-log.d.ts +2 -0
- package/lib/esm/classes/utils/clean-log.js +26 -0
- package/lib/esm/classes/utils/clean-transaction-receipt.js +2 -16
- package/lib/esm/classes/utils/clean-transaction.js +1 -1
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/lib/esm/classes/utils/prepare-transaction.js +34 -0
- package/lib/esm/index.d.ts +10 -5
- package/lib/esm/index.js +7 -3
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +7 -1
- package/lib/esm/providers/BaseProvider.js +67 -11
- package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
- package/lib/esm/providers/utils/chains-info.d.ts +27 -0
- package/lib/esm/providers/utils/chains-info.js +84 -3
- package/lib/esm/shared/tiny-big/tiny-big.js +4 -0
- package/lib/esm/types/Block.types.d.ts +11 -7
- package/lib/esm/types/Filter.types.d.ts +12 -0
- package/lib/esm/types/Filter.types.js +1 -0
- package/lib/esm/types/Transaction.types.d.ts +31 -5
- package/lib/esm/utils/compute-address.d.ts +1 -0
- package/lib/esm/utils/compute-address.js +11 -0
- package/lib/esm/utils/compute-public-key.d.ts +2 -0
- package/lib/esm/utils/compute-public-key.js +6 -0
- package/lib/esm/utils/keccak256.d.ts +1 -1
- package/lib/esm/utils/keccak256.js +2 -2
- package/lib/esm/utils/split-signature.d.ts +2 -0
- package/lib/esm/utils/split-signature.js +126 -0
- package/lib/esm/utils/wei-to-ether.js +11 -2
- package/package.json +38 -11
- package/readme.md +1209 -335
package/lib/cjs/utils/bytes.js
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// primary duplicate code from https://github.com/ethers-io/ethers.js/blob/f599d6f23dad0d0acaa3828d6b7acaab2d5e455b/packages/bytes/src.ts/index.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
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
|
+
// primarily duplicate code from https://github.com/ethers-io/ethers.js/blob/f599d6f23dad0d0acaa3828d6b7acaab2d5e455b/packages/bytes/src.ts/index.ts
|
|
5
5
|
const logger_1 = require("../logger/logger");
|
|
6
|
+
/**
|
|
7
|
+
* Check if a value can be converted to a hex string
|
|
8
|
+
*
|
|
9
|
+
* @param value the value to check whether or not it's Hexable
|
|
10
|
+
* @returns whether or not the value is Hexable
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* const val = tinyBig(203);
|
|
14
|
+
* isHexable(val);
|
|
15
|
+
* // true
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
6
18
|
function isHexable(value) {
|
|
7
19
|
return !!value.toHexString;
|
|
8
20
|
}
|
|
9
21
|
/**
|
|
10
22
|
* Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
|
|
11
|
-
*
|
|
23
|
+
* Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
|
|
12
24
|
*
|
|
25
|
+
* @param value the value to check whether or not it matches BytesLike
|
|
26
|
+
* @returns whether or not the value matches BytesLike
|
|
13
27
|
* @example
|
|
14
|
-
* ```
|
|
28
|
+
* ```javascript
|
|
15
29
|
* isBytesLike([1,2,3]);
|
|
16
30
|
* // true
|
|
17
31
|
* ```
|
|
18
|
-
*
|
|
19
32
|
* @example
|
|
20
|
-
* ```
|
|
33
|
+
* ```javascript
|
|
21
34
|
* isBytesLike(false);
|
|
22
35
|
* // false
|
|
23
36
|
* ```
|
|
24
|
-
*
|
|
25
37
|
* @example
|
|
26
|
-
* ```
|
|
38
|
+
* ```javascript
|
|
27
39
|
* isBytesLike(new Uint8Array(1));
|
|
28
40
|
* // true
|
|
29
41
|
* ```
|
|
@@ -32,27 +44,43 @@ function isBytesLike(value) {
|
|
|
32
44
|
return (isHexString(value) && !(value.length % 2)) || isBytes(value);
|
|
33
45
|
}
|
|
34
46
|
exports.isBytesLike = isBytesLike;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a value is an integer
|
|
49
|
+
*
|
|
50
|
+
* @param value the value to check whether or not it's an integer
|
|
51
|
+
* @returns whether or not value is an integer
|
|
52
|
+
* @example
|
|
53
|
+
* ```javascript
|
|
54
|
+
* isInteger(4)
|
|
55
|
+
* // true
|
|
56
|
+
* ```
|
|
57
|
+
* @example
|
|
58
|
+
* ```javascript
|
|
59
|
+
* isInteger(6.2)
|
|
60
|
+
* // false
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
35
63
|
function isInteger(value) {
|
|
36
64
|
return typeof value === 'number' && value == value && value % 1 === 0;
|
|
37
65
|
}
|
|
38
66
|
/**
|
|
39
67
|
* Returns true if and only if value is a valid [Bytes](#bytes)
|
|
40
|
-
*
|
|
68
|
+
* Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
|
|
41
69
|
*
|
|
70
|
+
* @param value the value to check whether or not it matches Bytes
|
|
71
|
+
* @returns whether or not the value matches Bytes
|
|
42
72
|
* @example
|
|
43
|
-
* ```
|
|
73
|
+
* ```javascript
|
|
44
74
|
* isBytes([1,2,3]);
|
|
45
75
|
* // true
|
|
46
76
|
* ```
|
|
47
|
-
*
|
|
48
77
|
* @example
|
|
49
|
-
* ```
|
|
78
|
+
* ```javascript
|
|
50
79
|
* isBytes(false);
|
|
51
80
|
* // false
|
|
52
81
|
* ```
|
|
53
|
-
*
|
|
54
82
|
* @example
|
|
55
|
-
* ```
|
|
83
|
+
* ```javascript
|
|
56
84
|
* isBytes(new Uint8Array(1));
|
|
57
85
|
* // true
|
|
58
86
|
* ```
|
|
@@ -81,22 +109,23 @@ function isBytes(value) {
|
|
|
81
109
|
exports.isBytes = isBytes;
|
|
82
110
|
/**
|
|
83
111
|
* Converts DataHexStringOrArrayish to a Uint8Array
|
|
84
|
-
*
|
|
112
|
+
* Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
|
|
85
113
|
*
|
|
114
|
+
* @param value the value to convert to a Uint8Array
|
|
115
|
+
* @param options options to use when converting the value to a Uint8Array
|
|
116
|
+
* @returns the value represented as a Uint8Array
|
|
86
117
|
* @example
|
|
87
|
-
* ```
|
|
118
|
+
* ```javascript
|
|
88
119
|
* arrayify(1);
|
|
89
120
|
* // Uint8Array(1) [ 1 ]
|
|
90
121
|
* ```
|
|
91
|
-
*
|
|
92
122
|
* @example
|
|
93
|
-
* ```
|
|
123
|
+
* ```javascript
|
|
94
124
|
* arrayify(0x1234);
|
|
95
125
|
* // Uint8Array(2) [ 18, 52 ]
|
|
96
126
|
* ```
|
|
97
|
-
*
|
|
98
127
|
* @example
|
|
99
|
-
* ```
|
|
128
|
+
* ```javascript
|
|
100
129
|
* arrayify('0x1', { hexPad: 'right' });
|
|
101
130
|
* // Uint8Array(1) [ 16 ]
|
|
102
131
|
* ```
|
|
@@ -152,10 +181,12 @@ function arrayify(value, options) {
|
|
|
152
181
|
exports.arrayify = arrayify;
|
|
153
182
|
/**
|
|
154
183
|
* Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
|
|
155
|
-
*
|
|
184
|
+
* Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
|
|
156
185
|
*
|
|
186
|
+
* @param arrayOfBytesLike the array of {@link BytesLike} to concatenate together
|
|
187
|
+
* @returns a concatenated Uint8Array
|
|
157
188
|
* @example
|
|
158
|
-
* ```
|
|
189
|
+
* ```javascript
|
|
159
190
|
* concat([0, 1]);
|
|
160
191
|
* // Uint8Array(2) [ 0, 1 ]
|
|
161
192
|
* ```
|
|
@@ -171,6 +202,18 @@ function concat(arrayOfBytesLike) {
|
|
|
171
202
|
return result;
|
|
172
203
|
}
|
|
173
204
|
exports.concat = concat;
|
|
205
|
+
/**
|
|
206
|
+
* Strips leading zeros from a BytesLike object
|
|
207
|
+
*
|
|
208
|
+
* @param value the value to strip leading zeros from
|
|
209
|
+
* @returns value without leading zeroes, expressed as a Uint8Array
|
|
210
|
+
* @example
|
|
211
|
+
* ```javascript
|
|
212
|
+
* stripZeros('0x00002834');
|
|
213
|
+
* // Uint8Array { [Iterator] 0: 40, 1: 52 }
|
|
214
|
+
* // Equivalent to '0x2834'
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
174
217
|
function stripZeros(value) {
|
|
175
218
|
let result = arrayify(value);
|
|
176
219
|
if (result.length === 0) {
|
|
@@ -188,6 +231,24 @@ function stripZeros(value) {
|
|
|
188
231
|
return result;
|
|
189
232
|
}
|
|
190
233
|
exports.stripZeros = stripZeros;
|
|
234
|
+
/**
|
|
235
|
+
* Pads the beginning of a {@link BytesLike} with zeros so it's the specified length as a Uint8Array
|
|
236
|
+
*
|
|
237
|
+
* @param value the value to pad
|
|
238
|
+
* @param length the desired length of the value
|
|
239
|
+
* @returns the value padded with zeros to the specified length
|
|
240
|
+
* @example
|
|
241
|
+
* ```javascript
|
|
242
|
+
* zeroPad('0x039284');
|
|
243
|
+
* // Uint8Array { [Iterator] 0: 0, 1: 0, 2: 0, 3: 3, 4: 146, 5: 132 }
|
|
244
|
+
* // Equivalent to 0x000000039284
|
|
245
|
+
* ```
|
|
246
|
+
* @example
|
|
247
|
+
* ```javascript
|
|
248
|
+
* zeroPad([39, 25, 103, 45], 5);
|
|
249
|
+
* // Uint8Array { [Iterator] 0: 0, 1: 39, 2: 25, 3: 103, 4: 45 }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
191
252
|
function zeroPad(value, length) {
|
|
192
253
|
value = arrayify(value);
|
|
193
254
|
if (value.length > length) {
|
|
@@ -201,7 +262,22 @@ exports.zeroPad = zeroPad;
|
|
|
201
262
|
/**
|
|
202
263
|
* Returns true if and only if object is a valid hex string.
|
|
203
264
|
* If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
|
|
204
|
-
*
|
|
265
|
+
* Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
|
|
266
|
+
*
|
|
267
|
+
* @param value the value to check whether or not it's a hex string
|
|
268
|
+
* @param length a length of bytes that the value should be equal to
|
|
269
|
+
* @returns whether the value is a valid hex string (and optionally, whether it matches the length specified)
|
|
270
|
+
* @example
|
|
271
|
+
* ```javascript
|
|
272
|
+
* isHexString('0x4924');
|
|
273
|
+
* // true
|
|
274
|
+
* ```
|
|
275
|
+
* @example
|
|
276
|
+
* ```javascript
|
|
277
|
+
* isHexString('0x4924', 4);
|
|
278
|
+
* // false
|
|
279
|
+
* // length of 4 in bytes would mean a hex string with 8 characters
|
|
280
|
+
* ```
|
|
205
281
|
*/
|
|
206
282
|
function isHexString(value, length) {
|
|
207
283
|
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
@@ -215,11 +291,18 @@ function isHexString(value, length) {
|
|
|
215
291
|
exports.isHexString = isHexString;
|
|
216
292
|
const HexCharacters = '0123456789abcdef';
|
|
217
293
|
/**
|
|
294
|
+
* Converts a value into a hex string
|
|
295
|
+
*
|
|
296
|
+
* @param value the value to convert
|
|
297
|
+
* @param options options to use when converting the value to a hex string
|
|
298
|
+
* @returns the value represented as a hex string
|
|
218
299
|
* @example
|
|
219
|
-
* ```
|
|
300
|
+
* ```javascript
|
|
220
301
|
* hexlify(4);
|
|
221
302
|
* // '0x04'
|
|
222
|
-
*
|
|
303
|
+
* ```
|
|
304
|
+
* @example
|
|
305
|
+
* ```javascript
|
|
223
306
|
* hexlify(14);
|
|
224
307
|
* // '0x0e'
|
|
225
308
|
* ```
|
|
@@ -283,6 +366,22 @@ function hexlify(value, options) {
|
|
|
283
366
|
return logger_1.logger.throwArgumentError('invalid hexlify value', 'value', value);
|
|
284
367
|
}
|
|
285
368
|
exports.hexlify = hexlify;
|
|
369
|
+
/**
|
|
370
|
+
* Gets the length of data represented as a hex string
|
|
371
|
+
*
|
|
372
|
+
* @param data the data to check the length of
|
|
373
|
+
* @returns the length of the data
|
|
374
|
+
* @example
|
|
375
|
+
* ```javascript
|
|
376
|
+
* hexDataLength([2, 4, 0, 1]);
|
|
377
|
+
* // 4
|
|
378
|
+
* ```
|
|
379
|
+
* @example
|
|
380
|
+
* ```javascript
|
|
381
|
+
* hexDataLength('0x3925');
|
|
382
|
+
* // 2
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
286
385
|
function hexDataLength(data) {
|
|
287
386
|
if (typeof data !== 'string') {
|
|
288
387
|
data = hexlify(data);
|
|
@@ -293,6 +392,19 @@ function hexDataLength(data) {
|
|
|
293
392
|
return (data.length - 2) / 2;
|
|
294
393
|
}
|
|
295
394
|
exports.hexDataLength = hexDataLength;
|
|
395
|
+
/**
|
|
396
|
+
* Slices a {@link BytesLike} to extract a certain part of the input
|
|
397
|
+
*
|
|
398
|
+
* @param data the data to slice from
|
|
399
|
+
* @param offset the index to start extraction at
|
|
400
|
+
* @param endOffset the index to end extraction at
|
|
401
|
+
* @returns the extracted data as a hex string
|
|
402
|
+
* @example
|
|
403
|
+
* ```javascript
|
|
404
|
+
* hexDataSlice([20, 6, 48], 0, 2);
|
|
405
|
+
* // '0x1406'
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
296
408
|
function hexDataSlice(data, offset, endOffset) {
|
|
297
409
|
if (typeof data !== 'string') {
|
|
298
410
|
data = hexlify(data);
|
|
@@ -307,6 +419,17 @@ function hexDataSlice(data, offset, endOffset) {
|
|
|
307
419
|
return '0x' + data.substring(offset);
|
|
308
420
|
}
|
|
309
421
|
exports.hexDataSlice = hexDataSlice;
|
|
422
|
+
/**
|
|
423
|
+
* Concatenates values together into one hex string
|
|
424
|
+
*
|
|
425
|
+
* @param items the items to concatenate together
|
|
426
|
+
* @returns a single hex string including all of the items to be concatenated
|
|
427
|
+
* @example
|
|
428
|
+
* ```javascript
|
|
429
|
+
* hexConcat([[2, 4, 0, 1], 9, '0x2934', '0x3947']);
|
|
430
|
+
* // '0x020400010929343947'
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
310
433
|
function hexConcat(items) {
|
|
311
434
|
let result = '0x';
|
|
312
435
|
items.forEach((item) => {
|
|
@@ -315,6 +438,22 @@ function hexConcat(items) {
|
|
|
315
438
|
return result;
|
|
316
439
|
}
|
|
317
440
|
exports.hexConcat = hexConcat;
|
|
441
|
+
/**
|
|
442
|
+
* Converts a number of different types into a hex string
|
|
443
|
+
*
|
|
444
|
+
* @param value the value to convert into a hex string
|
|
445
|
+
* @returns the value represented as a hex string
|
|
446
|
+
* @example
|
|
447
|
+
* ```javascript
|
|
448
|
+
* hexValue(39);
|
|
449
|
+
* // '0x27'
|
|
450
|
+
* ```
|
|
451
|
+
* @example
|
|
452
|
+
* ```javascript
|
|
453
|
+
* hexValue([9, 4, 19, 4]);
|
|
454
|
+
* // '0x9041304'
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
318
457
|
function hexValue(value) {
|
|
319
458
|
const trimmed = hexStripZeros(hexlify(value, { hexPad: 'left' }));
|
|
320
459
|
if (trimmed === '0x') {
|
|
@@ -323,6 +462,17 @@ function hexValue(value) {
|
|
|
323
462
|
return trimmed;
|
|
324
463
|
}
|
|
325
464
|
exports.hexValue = hexValue;
|
|
465
|
+
/**
|
|
466
|
+
* Strips the leading zeros from a value and returns it as a hex string
|
|
467
|
+
*
|
|
468
|
+
* @param value the value to strip zeros from
|
|
469
|
+
* @returns a hex string representation of the value, without leading zeros
|
|
470
|
+
* @example
|
|
471
|
+
* ```javascript
|
|
472
|
+
* hexStripZeros([0,0,0,48]);
|
|
473
|
+
* // '0x30'
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
326
476
|
function hexStripZeros(value) {
|
|
327
477
|
if (typeof value !== 'string') {
|
|
328
478
|
value = hexlify(value);
|
|
@@ -345,24 +495,21 @@ exports.hexStripZeros = hexStripZeros;
|
|
|
345
495
|
*
|
|
346
496
|
* Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
|
|
347
497
|
*
|
|
348
|
-
* @param
|
|
349
|
-
* @param length
|
|
350
|
-
*
|
|
351
|
-
* @throws
|
|
352
|
-
* @throws
|
|
353
|
-
*
|
|
498
|
+
* @param value A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
499
|
+
* @param length The final length in bytes
|
|
500
|
+
* @returns A hex string padded to the specified length
|
|
501
|
+
* @throws If the value is not a hex string or number
|
|
502
|
+
* @throws If the value is longer than the length
|
|
354
503
|
* @example
|
|
355
504
|
* ```javascript
|
|
356
505
|
* hexZeroPad('0x60', 2);
|
|
357
506
|
* // '0x0060'
|
|
358
507
|
* ```
|
|
359
|
-
*
|
|
360
508
|
* @example
|
|
361
509
|
* ```javascript
|
|
362
510
|
* hexZeroPad(0x60, 3);
|
|
363
511
|
* // '0x000060'
|
|
364
512
|
* ```
|
|
365
|
-
*
|
|
366
513
|
* @example
|
|
367
514
|
* ```javascript
|
|
368
515
|
* hexZeroPad('12345', 1);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the address that corresponds to a specified public or private key
|
|
3
|
+
*
|
|
4
|
+
* @param key the public or private key to find the address related to
|
|
5
|
+
* @returns the address that corresponds to the key specified
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* computeAddress('0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952'); // public key
|
|
9
|
+
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
10
|
+
* ```
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
|
|
14
|
+
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeAddress(key: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeAddress = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
const keccak256_1 = require("./keccak256");
|
|
7
|
+
/**
|
|
8
|
+
* Computes the address that corresponds to a specified public or private key
|
|
9
|
+
*
|
|
10
|
+
* @param key the public or private key to find the address related to
|
|
11
|
+
* @returns the address that corresponds to the key specified
|
|
12
|
+
* @example
|
|
13
|
+
* ```javascript
|
|
14
|
+
* computeAddress('0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952'); // public key
|
|
15
|
+
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
16
|
+
* ```
|
|
17
|
+
* @example
|
|
18
|
+
* ```javascript
|
|
19
|
+
* computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
|
|
20
|
+
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function computeAddress(key) {
|
|
24
|
+
// compressed public keys start with 0x04
|
|
25
|
+
// uncompressed public keys start with 0x03 or 0x02
|
|
26
|
+
if (!key.startsWith('0x04') &&
|
|
27
|
+
!key.startsWith('0x03') &&
|
|
28
|
+
!key.startsWith('0x02')) {
|
|
29
|
+
key = (0, __1.computePublicKey)(key);
|
|
30
|
+
}
|
|
31
|
+
return (0, __1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
|
|
32
|
+
}
|
|
33
|
+
exports.computeAddress = computeAddress;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BytesLike } from './bytes';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the public key from a given private key
|
|
4
|
+
*
|
|
5
|
+
* @param privKey the private key to find a public key from
|
|
6
|
+
* @returns the public key related to the specified private key
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* computePublicKey('0xb27cc8dea0177d910110e8d3ec5480d56c723abf433529f4063f261ffdb9297c');
|
|
10
|
+
* // '0x045cd0032015eecfde49f82f4e149d804e8ac6e3a0bface32e37c72a71ceac864fe84da7e8df84342f7b11dfb753c4d158f636142b46b29cf7f0f171ae0aa4fb87'
|
|
11
|
+
* ```
|
|
12
|
+
* @example
|
|
13
|
+
* ```javascript
|
|
14
|
+
* computePublicKey([50,102,50,99,52,49,57,97,99,102,52,97,49,100,97,56,99,49,101,98,101,97,55,53,98,98,51,102,99,102,98,100]);
|
|
15
|
+
* // '0x04a9cea77eca949df84f661cee153426fb51f2294b9364b4fac240df57360b9b0ac9c99e4d7966491ab4c81f8c82e0cd24ec5759832ad4ab736d22c7d90b806ee8'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function computePublicKey(privKey: BytesLike): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computePublicKey = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/secp256k1");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
/**
|
|
7
|
+
* Computes the public key from a given private key
|
|
8
|
+
*
|
|
9
|
+
* @param privKey the private key to find a public key from
|
|
10
|
+
* @returns the public key related to the specified private key
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* computePublicKey('0xb27cc8dea0177d910110e8d3ec5480d56c723abf433529f4063f261ffdb9297c');
|
|
14
|
+
* // '0x045cd0032015eecfde49f82f4e149d804e8ac6e3a0bface32e37c72a71ceac864fe84da7e8df84342f7b11dfb753c4d158f636142b46b29cf7f0f171ae0aa4fb87'
|
|
15
|
+
* ```
|
|
16
|
+
* @example
|
|
17
|
+
* ```javascript
|
|
18
|
+
* computePublicKey([50,102,50,99,52,49,57,97,99,102,52,97,49,100,97,56,99,49,101,98,101,97,55,53,98,98,51,102,99,102,98,100]);
|
|
19
|
+
* // '0x04a9cea77eca949df84f661cee153426fb51f2294b9364b4fac240df57360b9b0ac9c99e4d7966491ab4c81f8c82e0cd24ec5759832ad4ab736d22c7d90b806ee8'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function computePublicKey(privKey) {
|
|
23
|
+
privKey = (0, bytes_1.hexlify)(privKey).slice(2);
|
|
24
|
+
return '0x' + secp256k1_1.Point.fromPrivateKey(privKey).toHex();
|
|
25
|
+
}
|
|
26
|
+
exports.computePublicKey = computePublicKey;
|
|
@@ -7,6 +7,8 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
7
7
|
*
|
|
8
8
|
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
9
9
|
*
|
|
10
|
+
* @param etherQuantity the amount of ether to convert to gwei
|
|
11
|
+
* @returns a number of gwei equivalent to the specified ether
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* etherToGwei('1000').toString()
|
|
@@ -14,7 +16,6 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
14
16
|
* etherToGwei(1000).toString()
|
|
15
17
|
* // '1000000000000'
|
|
16
18
|
* ```
|
|
17
|
-
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```javascript
|
|
20
21
|
* etherToGwei('1000').toNumber()
|
|
@@ -10,6 +10,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
10
10
|
*
|
|
11
11
|
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
12
12
|
*
|
|
13
|
+
* @param etherQuantity the amount of ether to convert to gwei
|
|
14
|
+
* @returns a number of gwei equivalent to the specified ether
|
|
13
15
|
* @example
|
|
14
16
|
* ```javascript
|
|
15
17
|
* etherToGwei('1000').toString()
|
|
@@ -17,7 +19,6 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
17
19
|
* etherToGwei(1000).toString()
|
|
18
20
|
* // '1000000000000'
|
|
19
21
|
* ```
|
|
20
|
-
*
|
|
21
22
|
* @example
|
|
22
23
|
* ```javascript
|
|
23
24
|
* etherToGwei('1000').toNumber()
|
|
@@ -7,6 +7,8 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
7
7
|
*
|
|
8
8
|
* Similar to ["toWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#towei)
|
|
9
9
|
*
|
|
10
|
+
* @param etherQuantity the amount of ether to convert to wei
|
|
11
|
+
* @returns a number of wei equivalent to the specified ether
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* etherToWei('1000').toString()
|
|
@@ -14,7 +16,6 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
14
16
|
* etherToWei(1000).toString()
|
|
15
17
|
* // '1000000000000000000000'
|
|
16
18
|
* ```
|
|
17
|
-
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```javascript
|
|
20
21
|
* etherToWei('1000').toNumber()
|
|
@@ -10,6 +10,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
10
10
|
*
|
|
11
11
|
* Similar to ["toWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#towei)
|
|
12
12
|
*
|
|
13
|
+
* @param etherQuantity the amount of ether to convert to wei
|
|
14
|
+
* @returns a number of wei equivalent to the specified ether
|
|
13
15
|
* @example
|
|
14
16
|
* ```javascript
|
|
15
17
|
* etherToWei('1000').toString()
|
|
@@ -17,7 +19,6 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
17
19
|
* etherToWei(1000).toString()
|
|
18
20
|
* // '1000000000000000000000'
|
|
19
21
|
* ```
|
|
20
|
-
*
|
|
21
22
|
* @example
|
|
22
23
|
* ```javascript
|
|
23
24
|
* etherToWei('1000').toNumber()
|
|
@@ -7,6 +7,8 @@ import { TinyBig } from './../shared/tiny-big/tiny-big';
|
|
|
7
7
|
*
|
|
8
8
|
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
9
9
|
*
|
|
10
|
+
* @param gweiQuantity the amount of gwei to convert to ether
|
|
11
|
+
* @returns a number of ether equivalent to the specified gwei
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* gweiToEther('1000000000000').toString()
|
|
@@ -14,7 +16,6 @@ import { TinyBig } from './../shared/tiny-big/tiny-big';
|
|
|
14
16
|
* gweiToEther(1000000000000).toString()
|
|
15
17
|
* // '1000'
|
|
16
18
|
* ```
|
|
17
|
-
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```javascript
|
|
20
21
|
* gweiToEther('1000000000000').toNumber()
|
|
@@ -10,6 +10,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
10
10
|
*
|
|
11
11
|
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
12
12
|
*
|
|
13
|
+
* @param gweiQuantity the amount of gwei to convert to ether
|
|
14
|
+
* @returns a number of ether equivalent to the specified gwei
|
|
13
15
|
* @example
|
|
14
16
|
* ```javascript
|
|
15
17
|
* gweiToEther('1000000000000').toString()
|
|
@@ -17,7 +19,6 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
17
19
|
* gweiToEther(1000000000000).toString()
|
|
18
20
|
* // '1000'
|
|
19
21
|
* ```
|
|
20
|
-
*
|
|
21
22
|
* @example
|
|
22
23
|
* ```javascript
|
|
23
24
|
* gweiToEther('1000000000000').toNumber()
|
|
@@ -3,8 +3,10 @@ import { Bytes } from '../index';
|
|
|
3
3
|
* Computes the EIP-191 personal message digest of message.
|
|
4
4
|
* Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
|
|
5
5
|
*
|
|
6
|
+
* @param message the message to hash
|
|
7
|
+
* @returns a message hashed using Keccak256 that matches the EIP-191 standard
|
|
6
8
|
* @example
|
|
7
|
-
* ```
|
|
9
|
+
* ```javascript
|
|
8
10
|
* hashMessage("Hello World");
|
|
9
11
|
* // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
|
|
10
12
|
* ```
|
|
@@ -7,8 +7,10 @@ const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
|
7
7
|
* Computes the EIP-191 personal message digest of message.
|
|
8
8
|
* Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
|
|
9
9
|
*
|
|
10
|
+
* @param message the message to hash
|
|
11
|
+
* @returns a message hashed using Keccak256 that matches the EIP-191 standard
|
|
10
12
|
* @example
|
|
11
|
-
* ```
|
|
13
|
+
* ```javascript
|
|
12
14
|
* hashMessage("Hello World");
|
|
13
15
|
* // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
|
|
14
16
|
* ```
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* Returns a boolean as to whether the input is a valid address.
|
|
3
3
|
* Does NOT support ICAP addresses
|
|
4
4
|
*
|
|
5
|
+
* @param address the address to check the validity of
|
|
6
|
+
* @returns a boolean for whether the input is a valid address
|
|
5
7
|
* @example
|
|
6
8
|
* ```javascript
|
|
7
9
|
* isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
|
|
8
10
|
* // true
|
|
9
11
|
* ```
|
|
10
|
-
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```javascript
|
|
13
14
|
* isAddress('bad');
|
|
14
15
|
* // false
|
|
15
16
|
* ```
|
|
16
|
-
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```javascript
|
|
19
19
|
* // Does NOT support ENS.
|
|
@@ -7,18 +7,18 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
7
7
|
* Returns a boolean as to whether the input is a valid address.
|
|
8
8
|
* Does NOT support ICAP addresses
|
|
9
9
|
*
|
|
10
|
+
* @param address the address to check the validity of
|
|
11
|
+
* @returns a boolean for whether the input is a valid address
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
|
|
13
15
|
* // true
|
|
14
16
|
* ```
|
|
15
|
-
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```javascript
|
|
18
19
|
* isAddress('bad');
|
|
19
20
|
* // false
|
|
20
21
|
* ```
|
|
21
|
-
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```javascript
|
|
24
24
|
* // Does NOT support ENS.
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
import { BytesLike } from './bytes';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Hashes data into a Keccak256 hex string
|
|
4
|
+
*
|
|
5
|
+
* @param data the data to be hashed using Keccak256
|
|
6
|
+
* @returns a hex string with data hashed using Keccak256
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* keccak256('essential-eth');
|
|
10
|
+
* // '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
|
|
11
|
+
*
|
|
12
|
+
* keccak256('0x123');
|
|
13
|
+
* // '0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function keccak256(data: BytesLike): string;
|
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keccak256 = void 0;
|
|
4
4
|
const sha3_1 = require("sha3");
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Hashes data into a Keccak256 hex string
|
|
7
|
+
*
|
|
8
|
+
* @param data the data to be hashed using Keccak256
|
|
9
|
+
* @returns a hex string with data hashed using Keccak256
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* keccak256('essential-eth');
|
|
13
|
+
* // '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
|
|
14
|
+
*
|
|
15
|
+
* keccak256('0x123');
|
|
16
|
+
* // '0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function keccak256(data) {
|
|
6
20
|
let bufferableData;
|
|
7
21
|
if (typeof data === 'string') {
|
|
8
22
|
bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
@@ -13,5 +27,5 @@ const keccak256 = (data) => {
|
|
|
13
27
|
const keccak = new sha3_1.Keccak(256);
|
|
14
28
|
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
15
29
|
return addressHash;
|
|
16
|
-
}
|
|
30
|
+
}
|
|
17
31
|
exports.keccak256 = keccak256;
|