essential-eth 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +17 -3
- package/lib/cjs/logger/logger.d.ts +11 -0
- package/lib/cjs/logger/logger.js +36 -0
- package/lib/cjs/logger/package-version.d.ts +1 -0
- package/lib/cjs/logger/package-version.js +5 -0
- package/lib/cjs/providers/JsonRpcProvider.d.ts +1 -1
- package/lib/cjs/providers/JsonRpcProvider.js +1 -1
- package/lib/cjs/providers/utils/chains-info.d.ts +4 -0
- package/lib/cjs/providers/utils/chains-info.js +12 -0
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +7 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +25 -7
- package/lib/cjs/utils/bytes.d.ts +90 -0
- package/lib/cjs/utils/bytes.js +484 -0
- package/lib/cjs/utils/solidity-keccak256.d.ts +30 -0
- package/lib/cjs/utils/solidity-keccak256.js +125 -0
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +3 -2
- package/lib/esm/logger/logger.d.ts +11 -0
- package/lib/esm/logger/logger.js +33 -0
- package/lib/esm/logger/package-version.d.ts +1 -0
- package/lib/esm/logger/package-version.js +1 -0
- package/lib/esm/providers/JsonRpcProvider.d.ts +1 -1
- package/lib/esm/providers/JsonRpcProvider.js +1 -1
- package/lib/esm/providers/utils/chains-info.d.ts +4 -0
- package/lib/esm/providers/utils/chains-info.js +12 -0
- package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -0
- package/lib/esm/shared/tiny-big/tiny-big.js +20 -7
- package/lib/esm/utils/bytes.d.ts +39 -0
- package/lib/esm/utils/bytes.js +245 -0
- package/lib/esm/utils/solidity-keccak256.d.ts +3 -0
- package/lib/esm/utils/solidity-keccak256.js +91 -0
- package/package.json +12 -14
- package/lib/cjs/utils/hex-zero-pad.d.ts +0 -32
- package/lib/cjs/utils/hex-zero-pad.js +0 -52
- package/lib/esm/utils/hex-zero-pad.d.ts +0 -1
- package/lib/esm/utils/hex-zero-pad.js +0 -17
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hexZeroPad = void 0;
|
|
4
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
5
|
-
/**
|
|
6
|
-
* Returns a hex string padded to a specified length of bytes.
|
|
7
|
-
*
|
|
8
|
-
* Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
|
|
9
|
-
*
|
|
10
|
-
* 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.
|
|
11
|
-
*
|
|
12
|
-
* @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
13
|
-
* @param length - The final length in bytes
|
|
14
|
-
*
|
|
15
|
-
* @throws - If the value is not a hex string or number
|
|
16
|
-
* @throws - If the value is longer than the length
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```javascript
|
|
20
|
-
* hexZeroPad('0x60', 2);
|
|
21
|
-
* // '0x0060'
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```javascript
|
|
26
|
-
* hexZeroPad(0x60, 3);
|
|
27
|
-
* // '0x000060'
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```javascript
|
|
32
|
-
* hexZeroPad('12345', 1);
|
|
33
|
-
* // Throws
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
function hexZeroPad(hexValue, length) {
|
|
37
|
-
(0, validate_type_1.validateType)(hexValue, ['string', 'number']);
|
|
38
|
-
let val;
|
|
39
|
-
if (typeof hexValue === 'string') {
|
|
40
|
-
if (!hexValue.startsWith('0x'))
|
|
41
|
-
throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
|
|
42
|
-
val = hexValue.substring(2);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
val = hexValue.toString(16);
|
|
46
|
-
}
|
|
47
|
-
if (val.length > length * 2) {
|
|
48
|
-
throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
|
|
49
|
-
}
|
|
50
|
-
return `0x${val.padStart(length * 2, '0')}`;
|
|
51
|
-
}
|
|
52
|
-
exports.hexZeroPad = hexZeroPad;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function hexZeroPad(hexValue: string | number, length: number): string;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { validateType } from '../shared/validate-type';
|
|
2
|
-
export function hexZeroPad(hexValue, length) {
|
|
3
|
-
validateType(hexValue, ['string', 'number']);
|
|
4
|
-
let val;
|
|
5
|
-
if (typeof hexValue === 'string') {
|
|
6
|
-
if (!hexValue.startsWith('0x'))
|
|
7
|
-
throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
|
|
8
|
-
val = hexValue.substring(2);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
val = hexValue.toString(16);
|
|
12
|
-
}
|
|
13
|
-
if (val.length > length * 2) {
|
|
14
|
-
throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
|
|
15
|
-
}
|
|
16
|
-
return `0x${val.padStart(length * 2, '0')}`;
|
|
17
|
-
}
|