essential-eth 0.5.6 → 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.
Files changed (91) hide show
  1. package/lib/cjs/classes/Contract.d.ts +10 -4
  2. package/lib/cjs/classes/Contract.js +15 -4
  3. package/lib/cjs/classes/utils/clean-block.d.ts +115 -0
  4. package/lib/cjs/classes/utils/clean-block.js +122 -9
  5. package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
  6. package/lib/cjs/classes/utils/clean-log.js +37 -0
  7. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +9 -0
  8. package/lib/cjs/classes/utils/clean-transaction-receipt.js +11 -16
  9. package/lib/cjs/classes/utils/clean-transaction.d.ts +9 -0
  10. package/lib/cjs/classes/utils/clean-transaction.js +10 -1
  11. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +12 -0
  12. package/lib/cjs/classes/utils/encode-decode-transaction.js +24 -0
  13. package/lib/cjs/classes/utils/fetchers.d.ts +31 -1
  14. package/lib/cjs/classes/utils/fetchers.js +30 -0
  15. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +14 -1
  16. package/lib/cjs/classes/utils/hex-to-decimal.js +14 -1
  17. package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
  18. package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
  19. package/lib/cjs/index.d.ts +3 -3
  20. package/lib/cjs/index.js +0 -1
  21. package/lib/cjs/logger/package-version.d.ts +1 -1
  22. package/lib/cjs/logger/package-version.js +1 -1
  23. package/lib/cjs/providers/BaseProvider.d.ts +261 -212
  24. package/lib/cjs/providers/BaseProvider.js +332 -225
  25. package/lib/cjs/providers/JsonRpcProvider.d.ts +6 -0
  26. package/lib/cjs/providers/JsonRpcProvider.js +6 -0
  27. package/lib/cjs/providers/utils/chains-info.d.ts +11 -0
  28. package/lib/cjs/providers/utils/chains-info.js +34 -1
  29. package/lib/cjs/shared/tiny-big/helpers.d.ts +16 -0
  30. package/lib/cjs/shared/tiny-big/helpers.js +27 -1
  31. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +30 -4
  32. package/lib/cjs/shared/tiny-big/tiny-big.js +34 -4
  33. package/lib/cjs/types/Block.types.d.ts +11 -7
  34. package/lib/cjs/types/Filter.types.d.ts +16 -0
  35. package/lib/cjs/{providers/types.js → types/Filter.types.js} +0 -0
  36. package/lib/cjs/types/Transaction.types.d.ts +33 -6
  37. package/lib/cjs/utils/bytes.d.ts +150 -33
  38. package/lib/cjs/utils/bytes.js +179 -32
  39. package/lib/cjs/utils/compute-address.d.ts +10 -1
  40. package/lib/cjs/utils/compute-address.js +10 -1
  41. package/lib/cjs/utils/compute-public-key.d.ts +12 -3
  42. package/lib/cjs/utils/compute-public-key.js +12 -3
  43. package/lib/cjs/utils/ether-to-gwei.d.ts +2 -1
  44. package/lib/cjs/utils/ether-to-gwei.js +2 -1
  45. package/lib/cjs/utils/ether-to-wei.d.ts +2 -1
  46. package/lib/cjs/utils/ether-to-wei.js +2 -1
  47. package/lib/cjs/utils/gwei-to-ether.d.ts +2 -1
  48. package/lib/cjs/utils/gwei-to-ether.js +2 -1
  49. package/lib/cjs/utils/hash-message.d.ts +3 -1
  50. package/lib/cjs/utils/hash-message.js +3 -1
  51. package/lib/cjs/utils/is-address.d.ts +2 -2
  52. package/lib/cjs/utils/is-address.js +2 -2
  53. package/lib/cjs/utils/keccak256.d.ts +15 -1
  54. package/lib/cjs/utils/keccak256.js +16 -2
  55. package/lib/cjs/utils/solidity-keccak256.d.ts +17 -7
  56. package/lib/cjs/utils/solidity-keccak256.js +27 -7
  57. package/lib/cjs/utils/split-signature.d.ts +1 -3
  58. package/lib/cjs/utils/split-signature.js +1 -3
  59. package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
  60. package/lib/cjs/utils/to-checksum-address.js +2 -2
  61. package/lib/cjs/utils/to-utf8-bytes.d.ts +14 -0
  62. package/lib/cjs/utils/to-utf8-bytes.js +14 -0
  63. package/lib/cjs/utils/wei-to-ether.d.ts +2 -1
  64. package/lib/cjs/utils/wei-to-ether.js +2 -1
  65. package/lib/esm/classes/utils/clean-block.js +7 -8
  66. package/lib/esm/classes/utils/clean-log.d.ts +2 -0
  67. package/lib/esm/classes/utils/clean-log.js +26 -0
  68. package/lib/esm/classes/utils/clean-transaction-receipt.js +2 -16
  69. package/lib/esm/classes/utils/clean-transaction.js +1 -1
  70. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  71. package/lib/esm/classes/utils/prepare-transaction.d.ts +2 -0
  72. package/lib/esm/classes/utils/prepare-transaction.js +34 -0
  73. package/lib/esm/index.d.ts +3 -3
  74. package/lib/esm/index.js +0 -1
  75. package/lib/esm/logger/package-version.d.ts +1 -1
  76. package/lib/esm/logger/package-version.js +1 -1
  77. package/lib/esm/providers/BaseProvider.d.ts +5 -2
  78. package/lib/esm/providers/BaseProvider.js +56 -13
  79. package/lib/esm/providers/utils/chains-info.d.ts +11 -0
  80. package/lib/esm/providers/utils/chains-info.js +34 -1
  81. package/lib/esm/shared/tiny-big/tiny-big.js +4 -0
  82. package/lib/esm/types/Block.types.d.ts +11 -7
  83. package/lib/esm/types/Filter.types.d.ts +12 -0
  84. package/lib/esm/{providers/types.js → types/Filter.types.js} +0 -0
  85. package/lib/esm/types/Transaction.types.d.ts +31 -5
  86. package/lib/esm/utils/keccak256.d.ts +1 -1
  87. package/lib/esm/utils/keccak256.js +2 -2
  88. package/package.json +30 -6
  89. package/readme.md +643 -291
  90. package/lib/cjs/providers/types.d.ts +0 -7
  91. package/lib/esm/providers/types.d.ts +0 -7
@@ -2,10 +2,8 @@ export declare type Bytes = ArrayLike<number>;
2
2
  /**
3
3
  * @example
4
4
  * [1,2,3]
5
- *
6
5
  * @example
7
6
  * 0x123
8
- *
9
7
  * @example
10
8
  * '0x123'
11
9
  */
@@ -36,22 +34,22 @@ export interface Signature {
36
34
  }
37
35
  /**
38
36
  * Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
39
- * * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
37
+ * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
40
38
  *
39
+ * @param value the value to check whether or not it matches BytesLike
40
+ * @returns whether or not the value matches BytesLike
41
41
  * @example
42
- * ```js
42
+ * ```javascript
43
43
  * isBytesLike([1,2,3]);
44
44
  * // true
45
45
  * ```
46
- *
47
46
  * @example
48
- * ```js
47
+ * ```javascript
49
48
  * isBytesLike(false);
50
49
  * // false
51
50
  * ```
52
- *
53
51
  * @example
54
- * ```js
52
+ * ```javascript
55
53
  * isBytesLike(new Uint8Array(1));
56
54
  * // true
57
55
  * ```
@@ -59,22 +57,22 @@ export interface Signature {
59
57
  export declare function isBytesLike(value: any): value is BytesLike;
60
58
  /**
61
59
  * Returns true if and only if value is a valid [Bytes](#bytes)
62
- * * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
60
+ * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
63
61
  *
62
+ * @param value the value to check whether or not it matches Bytes
63
+ * @returns whether or not the value matches Bytes
64
64
  * @example
65
- * ```js
65
+ * ```javascript
66
66
  * isBytes([1,2,3]);
67
67
  * // true
68
68
  * ```
69
- *
70
69
  * @example
71
- * ```js
70
+ * ```javascript
72
71
  * isBytes(false);
73
72
  * // false
74
73
  * ```
75
- *
76
74
  * @example
77
- * ```js
75
+ * ```javascript
78
76
  * isBytes(new Uint8Array(1));
79
77
  * // true
80
78
  * ```
@@ -82,22 +80,23 @@ export declare function isBytesLike(value: any): value is BytesLike;
82
80
  export declare function isBytes(value: any): value is Bytes;
83
81
  /**
84
82
  * Converts DataHexStringOrArrayish to a Uint8Array
85
- * * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
83
+ * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
86
84
  *
85
+ * @param value the value to convert to a Uint8Array
86
+ * @param options options to use when converting the value to a Uint8Array
87
+ * @returns the value represented as a Uint8Array
87
88
  * @example
88
- * ```js
89
+ * ```javascript
89
90
  * arrayify(1);
90
91
  * // Uint8Array(1) [ 1 ]
91
92
  * ```
92
- *
93
93
  * @example
94
- * ```js
94
+ * ```javascript
95
95
  * arrayify(0x1234);
96
96
  * // Uint8Array(2) [ 18, 52 ]
97
97
  * ```
98
- *
99
98
  * @example
100
- * ```js
99
+ * ```javascript
101
100
  * arrayify('0x1', { hexPad: 'right' });
102
101
  * // Uint8Array(1) [ 16 ]
103
102
  * ```
@@ -105,38 +104,159 @@ export declare function isBytes(value: any): value is Bytes;
105
104
  export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
106
105
  /**
107
106
  * Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
108
- * * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
107
+ * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
109
108
  *
109
+ * @param arrayOfBytesLike the array of {@link BytesLike} to concatenate together
110
+ * @returns a concatenated Uint8Array
110
111
  * @example
111
- * ```js
112
+ * ```javascript
112
113
  * concat([0, 1]);
113
114
  * // Uint8Array(2) [ 0, 1 ]
114
115
  * ```
115
116
  */
116
117
  export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLikeWithNumber>): Uint8Array;
118
+ /**
119
+ * Strips leading zeros from a BytesLike object
120
+ *
121
+ * @param value the value to strip leading zeros from
122
+ * @returns value without leading zeroes, expressed as a Uint8Array
123
+ * @example
124
+ * ```javascript
125
+ * stripZeros('0x00002834');
126
+ * // Uint8Array { [Iterator] 0: 40, 1: 52 }
127
+ * // Equivalent to '0x2834'
128
+ * ```
129
+ */
117
130
  export declare function stripZeros(value: BytesLike): Uint8Array;
131
+ /**
132
+ * Pads the beginning of a {@link BytesLike} with zeros so it's the specified length as a Uint8Array
133
+ *
134
+ * @param value the value to pad
135
+ * @param length the desired length of the value
136
+ * @returns the value padded with zeros to the specified length
137
+ * @example
138
+ * ```javascript
139
+ * zeroPad('0x039284');
140
+ * // Uint8Array { [Iterator] 0: 0, 1: 0, 2: 0, 3: 3, 4: 146, 5: 132 }
141
+ * // Equivalent to 0x000000039284
142
+ * ```
143
+ * @example
144
+ * ```javascript
145
+ * zeroPad([39, 25, 103, 45], 5);
146
+ * // Uint8Array { [Iterator] 0: 0, 1: 39, 2: 25, 3: 103, 4: 45 }
147
+ * ```
148
+ */
118
149
  export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
119
150
  /**
120
151
  * Returns true if and only if object is a valid hex string.
121
152
  * If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
122
- * * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
153
+ * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
154
+ *
155
+ * @param value the value to check whether or not it's a hex string
156
+ * @param length a length of bytes that the value should be equal to
157
+ * @returns whether the value is a valid hex string (and optionally, whether it matches the length specified)
158
+ * @example
159
+ * ```javascript
160
+ * isHexString('0x4924');
161
+ * // true
162
+ * ```
163
+ * @example
164
+ * ```javascript
165
+ * isHexString('0x4924', 4);
166
+ * // false
167
+ * // length of 4 in bytes would mean a hex string with 8 characters
168
+ * ```
123
169
  */
124
170
  export declare function isHexString(value: any, length?: number): boolean;
125
171
  /**
172
+ * Converts a value into a hex string
173
+ *
174
+ * @param value the value to convert
175
+ * @param options options to use when converting the value to a hex string
176
+ * @returns the value represented as a hex string
126
177
  * @example
127
- * ```js
178
+ * ```javascript
128
179
  * hexlify(4);
129
180
  * // '0x04'
130
- *
181
+ * ```
182
+ * @example
183
+ * ```javascript
131
184
  * hexlify(14);
132
185
  * // '0x0e'
133
186
  * ```
134
187
  */
135
188
  export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
189
+ /**
190
+ * Gets the length of data represented as a hex string
191
+ *
192
+ * @param data the data to check the length of
193
+ * @returns the length of the data
194
+ * @example
195
+ * ```javascript
196
+ * hexDataLength([2, 4, 0, 1]);
197
+ * // 4
198
+ * ```
199
+ * @example
200
+ * ```javascript
201
+ * hexDataLength('0x3925');
202
+ * // 2
203
+ * ```
204
+ */
136
205
  export declare function hexDataLength(data: BytesLike): number | null;
206
+ /**
207
+ * Slices a {@link BytesLike} to extract a certain part of the input
208
+ *
209
+ * @param data the data to slice from
210
+ * @param offset the index to start extraction at
211
+ * @param endOffset the index to end extraction at
212
+ * @returns the extracted data as a hex string
213
+ * @example
214
+ * ```javascript
215
+ * hexDataSlice([20, 6, 48], 0, 2);
216
+ * // '0x1406'
217
+ * ```
218
+ */
137
219
  export declare function hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset?: number): string;
220
+ /**
221
+ * Concatenates values together into one hex string
222
+ *
223
+ * @param items the items to concatenate together
224
+ * @returns a single hex string including all of the items to be concatenated
225
+ * @example
226
+ * ```javascript
227
+ * hexConcat([[2, 4, 0, 1], 9, '0x2934', '0x3947']);
228
+ * // '0x020400010929343947'
229
+ * ```
230
+ */
138
231
  export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
232
+ /**
233
+ * Converts a number of different types into a hex string
234
+ *
235
+ * @param value the value to convert into a hex string
236
+ * @returns the value represented as a hex string
237
+ * @example
238
+ * ```javascript
239
+ * hexValue(39);
240
+ * // '0x27'
241
+ * ```
242
+ * @example
243
+ * ```javascript
244
+ * hexValue([9, 4, 19, 4]);
245
+ * // '0x9041304'
246
+ * ```
247
+ */
139
248
  export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
249
+ /**
250
+ * Strips the leading zeros from a value and returns it as a hex string
251
+ *
252
+ * @param value the value to strip zeros from
253
+ * @returns a hex string representation of the value, without leading zeros
254
+ * @example
255
+ * ```javascript
256
+ * hexStripZeros([0,0,0,48]);
257
+ * // '0x30'
258
+ * ```
259
+ */
140
260
  export declare function hexStripZeros(value: BytesLike): string;
141
261
  /**
142
262
  * Returns a hex string padded to a specified length of bytes.
@@ -145,24 +265,21 @@ export declare function hexStripZeros(value: BytesLike): string;
145
265
  *
146
266
  * 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.
147
267
  *
148
- * @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
149
- * @param length - The final length in bytes
150
- *
151
- * @throws - If the value is not a hex string or number
152
- * @throws - If the value is longer than the length
153
- *
268
+ * @param value A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
269
+ * @param length The final length in bytes
270
+ * @returns A hex string padded to the specified length
271
+ * @throws If the value is not a hex string or number
272
+ * @throws If the value is longer than the length
154
273
  * @example
155
274
  * ```javascript
156
275
  * hexZeroPad('0x60', 2);
157
276
  * // '0x0060'
158
277
  * ```
159
- *
160
278
  * @example
161
279
  * ```javascript
162
280
  * hexZeroPad(0x60, 3);
163
281
  * // '0x000060'
164
282
  * ```
165
- *
166
283
  * @example
167
284
  * ```javascript
168
285
  * hexZeroPad('12345', 1);
@@ -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
- * * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
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
- * ```js
28
+ * ```javascript
15
29
  * isBytesLike([1,2,3]);
16
30
  * // true
17
31
  * ```
18
- *
19
32
  * @example
20
- * ```js
33
+ * ```javascript
21
34
  * isBytesLike(false);
22
35
  * // false
23
36
  * ```
24
- *
25
37
  * @example
26
- * ```js
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
- * * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
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
- * ```js
73
+ * ```javascript
44
74
  * isBytes([1,2,3]);
45
75
  * // true
46
76
  * ```
47
- *
48
77
  * @example
49
- * ```js
78
+ * ```javascript
50
79
  * isBytes(false);
51
80
  * // false
52
81
  * ```
53
- *
54
82
  * @example
55
- * ```js
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
- * * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
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
- * ```js
118
+ * ```javascript
88
119
  * arrayify(1);
89
120
  * // Uint8Array(1) [ 1 ]
90
121
  * ```
91
- *
92
122
  * @example
93
- * ```js
123
+ * ```javascript
94
124
  * arrayify(0x1234);
95
125
  * // Uint8Array(2) [ 18, 52 ]
96
126
  * ```
97
- *
98
127
  * @example
99
- * ```js
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
- * * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
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
- * ```js
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
- * * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
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
- * ```js
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 hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
349
- * @param length - The final length in bytes
350
- *
351
- * @throws - If the value is not a hex string or number
352
- * @throws - If the value is longer than the length
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);
@@ -2,7 +2,16 @@
2
2
  * Computes the address that corresponds to a specified public or private key
3
3
  *
4
4
  * @param key the public or private key to find the address related to
5
- *
6
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
+ * ```
7
16
  */
8
17
  export declare function computeAddress(key: string): string;
@@ -8,8 +8,17 @@ const keccak256_1 = require("./keccak256");
8
8
  * Computes the address that corresponds to a specified public or private key
9
9
  *
10
10
  * @param key the public or private key to find the address related to
11
- *
12
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
+ * ```
13
22
  */
14
23
  function computeAddress(key) {
15
24
  // compressed public keys start with 0x04