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.
- 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 +3 -3
- package/lib/cjs/index.js +0 -1
- 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 +261 -212
- package/lib/cjs/providers/BaseProvider.js +332 -225
- 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 +11 -0
- package/lib/cjs/providers/utils/chains-info.js +34 -1
- 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/{providers/types.js → types/Filter.types.js} +0 -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 +10 -1
- package/lib/cjs/utils/compute-address.js +10 -1
- package/lib/cjs/utils/compute-public-key.d.ts +12 -3
- package/lib/cjs/utils/compute-public-key.js +12 -3
- 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 +1 -3
- package/lib/cjs/utils/split-signature.js +1 -3
- 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 +2 -1
- 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 +3 -3
- package/lib/esm/index.js +0 -1
- 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 +5 -2
- package/lib/esm/providers/BaseProvider.js +56 -13
- package/lib/esm/providers/utils/chains-info.d.ts +11 -0
- package/lib/esm/providers/utils/chains-info.js +34 -1
- 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/{providers/types.js → types/Filter.types.js} +0 -0
- package/lib/esm/types/Transaction.types.d.ts +31 -5
- package/lib/esm/utils/keccak256.d.ts +1 -1
- package/lib/esm/utils/keccak256.js +2 -2
- package/package.json +30 -6
- package/readme.md +643 -291
- package/lib/cjs/providers/types.d.ts +0 -7
- package/lib/esm/providers/types.d.ts +0 -7
|
@@ -2,8 +2,17 @@ import { BytesLike } from './bytes';
|
|
|
2
2
|
/**
|
|
3
3
|
* Computes the public key from a given private key
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
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
|
+
* ```
|
|
8
17
|
*/
|
|
9
18
|
export declare function computePublicKey(privKey: BytesLike): string;
|
|
@@ -6,9 +6,18 @@ const bytes_1 = require("./bytes");
|
|
|
6
6
|
/**
|
|
7
7
|
* Computes the public key from a given private key
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
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
|
+
* ```
|
|
12
21
|
*/
|
|
13
22
|
function computePublicKey(privKey) {
|
|
14
23
|
privKey = (0, bytes_1.hexlify)(privKey).slice(2);
|
|
@@ -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;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts arrays with types and values into a hex string that can be hashed
|
|
3
|
+
*
|
|
4
|
+
* @param types array of Solidity types, where `type[0]` is the type for `value[0]`
|
|
5
|
+
* @param values array of values, where `value[0]` is of type `type[0]`
|
|
6
|
+
* @returns a hex string with the data given, packed to include its types
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* const types = ['bool', 'string', 'uint64'];
|
|
10
|
+
* const values = [true, 'text', 30];
|
|
11
|
+
* pack(types, values);
|
|
12
|
+
* // '0x0174657874000000000000001e'
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
|
|
2
16
|
/**
|
|
3
17
|
* Hashes data from Solidity using the Keccak256 algorithm.
|
|
4
18
|
*
|
|
5
19
|
* Similar to ["solidityKeccak256" in ethers.js](https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256)
|
|
6
20
|
*
|
|
7
|
-
* @param types
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @returns - A Keccak256 hash (hex string) based on the values provided
|
|
12
|
-
*
|
|
21
|
+
* @param types Each [Solidity type](https://docs.soliditylang.org/en/v0.8.13/types.html) corresponding to the values passed in. Helps the function parse and pack data properly.
|
|
22
|
+
* @param values Data to be concatenated (combined) and then hashed.
|
|
23
|
+
* @returns A Keccak256 hash (hex string) based on the values provided
|
|
13
24
|
* @example
|
|
14
25
|
* ```javascript
|
|
15
26
|
* const types = ['string', 'bool', 'uint32'];
|
|
@@ -17,7 +28,6 @@ export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray
|
|
|
17
28
|
* solidityKeccak256(types, values);
|
|
18
29
|
* // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
19
30
|
* ```
|
|
20
|
-
*
|
|
21
31
|
* @example
|
|
22
32
|
* ```javascript
|
|
23
33
|
* const types = ['bytes4', 'uint32[5]'];
|
|
@@ -10,6 +10,16 @@ const keccak256_1 = require("./keccak256");
|
|
|
10
10
|
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
11
11
|
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
12
12
|
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
13
|
+
/**
|
|
14
|
+
* Packs a type and value together into a UTF-8 Byte Array
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
* @param type the Solidity type used for the value given
|
|
18
|
+
* @param value the value to pack with its type
|
|
19
|
+
* @param isArray whether the specified data is in an array
|
|
20
|
+
* @returns packed data consisting of the type and value
|
|
21
|
+
* @example N/A - internal function
|
|
22
|
+
*/
|
|
13
23
|
function _pack(type, value, isArray) {
|
|
14
24
|
switch (type) {
|
|
15
25
|
case 'address':
|
|
@@ -74,6 +84,20 @@ function _pack(type, value, isArray) {
|
|
|
74
84
|
}
|
|
75
85
|
return logger_1.logger.throwArgumentError('invalid type', 'type', type);
|
|
76
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts arrays with types and values into a hex string that can be hashed
|
|
89
|
+
*
|
|
90
|
+
* @param types array of Solidity types, where `type[0]` is the type for `value[0]`
|
|
91
|
+
* @param values array of values, where `value[0]` is of type `type[0]`
|
|
92
|
+
* @returns a hex string with the data given, packed to include its types
|
|
93
|
+
* @example
|
|
94
|
+
* ```javascript
|
|
95
|
+
* const types = ['bool', 'string', 'uint64'];
|
|
96
|
+
* const values = [true, 'text', 30];
|
|
97
|
+
* pack(types, values);
|
|
98
|
+
* // '0x0174657874000000000000001e'
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
77
101
|
function pack(types, values) {
|
|
78
102
|
if (types.length != values.length) {
|
|
79
103
|
logger_1.logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
|
|
@@ -90,12 +114,9 @@ exports.pack = pack;
|
|
|
90
114
|
*
|
|
91
115
|
* Similar to ["solidityKeccak256" in ethers.js](https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256)
|
|
92
116
|
*
|
|
93
|
-
* @param types
|
|
94
|
-
*
|
|
95
|
-
* @
|
|
96
|
-
*
|
|
97
|
-
* @returns - A Keccak256 hash (hex string) based on the values provided
|
|
98
|
-
*
|
|
117
|
+
* @param types Each [Solidity type](https://docs.soliditylang.org/en/v0.8.13/types.html) corresponding to the values passed in. Helps the function parse and pack data properly.
|
|
118
|
+
* @param values Data to be concatenated (combined) and then hashed.
|
|
119
|
+
* @returns A Keccak256 hash (hex string) based on the values provided
|
|
99
120
|
* @example
|
|
100
121
|
* ```javascript
|
|
101
122
|
* const types = ['string', 'bool', 'uint32'];
|
|
@@ -103,7 +124,6 @@ exports.pack = pack;
|
|
|
103
124
|
* solidityKeccak256(types, values);
|
|
104
125
|
* // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
105
126
|
* ```
|
|
106
|
-
*
|
|
107
127
|
* @example
|
|
108
128
|
* ```javascript
|
|
109
129
|
* const types = ['bytes4', 'uint32[5]'];
|
|
@@ -2,12 +2,10 @@ import { Signature, SignatureLike } from './bytes';
|
|
|
2
2
|
/**
|
|
3
3
|
* Expands a signature into the full signature object and fills in missing properties.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
6
6
|
*
|
|
7
7
|
* @param signature the signature object to split, parse, and compute missing properties from
|
|
8
|
-
*
|
|
9
8
|
* @returns a full signature object with all properties filled
|
|
10
|
-
*
|
|
11
9
|
* @example
|
|
12
10
|
* ```javascript
|
|
13
11
|
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
@@ -6,12 +6,10 @@ const bytes_1 = require("./bytes");
|
|
|
6
6
|
/**
|
|
7
7
|
* Expands a signature into the full signature object and fills in missing properties.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
10
10
|
*
|
|
11
11
|
* @param signature the signature object to split, parse, and compute missing properties from
|
|
12
|
-
*
|
|
13
12
|
* @returns a full signature object with all properties filled
|
|
14
|
-
*
|
|
15
13
|
* @example
|
|
16
14
|
* ```javascript
|
|
17
15
|
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Returns an Ethereum address in proper mixed-case checksum.
|
|
3
3
|
* Does NOT support ICAP
|
|
4
4
|
*
|
|
5
|
-
* @param address
|
|
6
|
-
*
|
|
5
|
+
* @param address An Ethereum address. Mixed, lower, and uppercase are all valid
|
|
6
|
+
* @returns a valid checksum address
|
|
7
7
|
* @example
|
|
8
8
|
* ```javascript
|
|
9
9
|
* toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
@@ -7,8 +7,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
7
7
|
* Returns an Ethereum address in proper mixed-case checksum.
|
|
8
8
|
* Does NOT support ICAP
|
|
9
9
|
*
|
|
10
|
-
* @param address
|
|
11
|
-
*
|
|
10
|
+
* @param address An Ethereum address. Mixed, lower, and uppercase are all valid
|
|
11
|
+
* @returns a valid checksum address
|
|
12
12
|
* @example
|
|
13
13
|
* ```javascript
|
|
14
14
|
* toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
@@ -1 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string into a UTF-8 Byte Array
|
|
3
|
+
*
|
|
4
|
+
* @param data the input to be converted to a UTF-8 Byte Array
|
|
5
|
+
* @returns the specified data as a UTF-8 Byte Array
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* toUtf8Bytes('essential-eth');
|
|
9
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
|
|
10
|
+
*
|
|
11
|
+
* toUtf8Bytes('ethereum');
|
|
12
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export declare function toUtf8Bytes(data: string): Uint8Array;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toUtf8Bytes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string into a UTF-8 Byte Array
|
|
6
|
+
*
|
|
7
|
+
* @param data the input to be converted to a UTF-8 Byte Array
|
|
8
|
+
* @returns the specified data as a UTF-8 Byte Array
|
|
9
|
+
* @example
|
|
10
|
+
* ```javascript
|
|
11
|
+
* toUtf8Bytes('essential-eth');
|
|
12
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
|
|
13
|
+
*
|
|
14
|
+
* toUtf8Bytes('ethereum');
|
|
15
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
function toUtf8Bytes(data) {
|
|
5
19
|
return new Uint8Array(Buffer.from(data));
|
|
6
20
|
}
|
|
@@ -7,6 +7,8 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
7
7
|
*
|
|
8
8
|
* Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
|
|
9
9
|
*
|
|
10
|
+
* @param weiQuantity the amount of wei to convert to ether
|
|
11
|
+
* @returns a number of ether equivalent to the specified wei
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* weiToEther('1000000000000000000000').toString()
|
|
@@ -14,7 +16,6 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
14
16
|
* weiToEther(1000000000000000000000).toString()
|
|
15
17
|
* // '1000'
|
|
16
18
|
* ```
|
|
17
|
-
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```javascript
|
|
20
21
|
* weiToEther('1000000000000000000000').toNumber()
|
|
@@ -10,6 +10,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
10
10
|
*
|
|
11
11
|
* Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
|
|
12
12
|
*
|
|
13
|
+
* @param weiQuantity the amount of wei to convert to ether
|
|
14
|
+
* @returns a number of ether equivalent to the specified wei
|
|
13
15
|
* @example
|
|
14
16
|
* ```javascript
|
|
15
17
|
* weiToEther('1000000000000000000000').toString()
|
|
@@ -17,7 +19,6 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
17
19
|
* weiToEther(1000000000000000000000).toString()
|
|
18
20
|
* // '1000'
|
|
19
21
|
* ```
|
|
20
|
-
*
|
|
21
22
|
* @example
|
|
22
23
|
* ```javascript
|
|
23
24
|
* weiToEther('1000000000000000000000').toNumber()
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toChecksumAddress } from '../..';
|
|
2
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
3
|
import { cleanTransaction } from './clean-transaction';
|
|
3
4
|
import { hexToDecimal } from './hex-to-decimal';
|
|
4
5
|
export function cleanBlock(block, returnTransactionObjects) {
|
|
@@ -7,22 +8,20 @@ export function cleanBlock(block, returnTransactionObjects) {
|
|
|
7
8
|
if (!block[key])
|
|
8
9
|
return;
|
|
9
10
|
switch (key) {
|
|
11
|
+
case 'difficulty':
|
|
12
|
+
case 'totalDifficulty':
|
|
10
13
|
case 'gasLimit':
|
|
11
14
|
case 'gasUsed':
|
|
12
|
-
case 'number':
|
|
13
15
|
case 'size':
|
|
14
16
|
case 'timestamp':
|
|
15
17
|
case 'baseFeePerGas':
|
|
16
|
-
cleanedBlock[key] =
|
|
18
|
+
cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
|
|
17
19
|
break;
|
|
18
|
-
case '
|
|
19
|
-
|
|
20
|
-
cleanedBlock[key] = hexToDecimal(block[key]);
|
|
20
|
+
case 'number':
|
|
21
|
+
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
21
22
|
break;
|
|
22
23
|
case 'miner':
|
|
23
|
-
|
|
24
|
-
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
25
|
-
}
|
|
24
|
+
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
26
25
|
break;
|
|
27
26
|
}
|
|
28
27
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
2
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
+
export function cleanLog(log, receiptLog) {
|
|
4
|
+
const cleanedLog = Object.assign({}, log);
|
|
5
|
+
Object.keys(log).forEach((key) => {
|
|
6
|
+
switch (key) {
|
|
7
|
+
case 'address':
|
|
8
|
+
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
9
|
+
break;
|
|
10
|
+
case 'blockNumber':
|
|
11
|
+
case 'logIndex':
|
|
12
|
+
case 'transactionIndex':
|
|
13
|
+
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
14
|
+
break;
|
|
15
|
+
case 'removed':
|
|
16
|
+
if (receiptLog) {
|
|
17
|
+
delete cleanedLog[key];
|
|
18
|
+
}
|
|
19
|
+
else if (log[key] == null) {
|
|
20
|
+
cleanedLog[key] === false;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return cleanedLog;
|
|
26
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
|
+
import { cleanLog } from './clean-log';
|
|
2
3
|
import { cleanTransaction } from './clean-transaction';
|
|
3
4
|
import { hexToDecimal } from './hex-to-decimal';
|
|
4
5
|
export function cleanTransactionReceipt(transactionReceipt) {
|
|
@@ -23,22 +24,7 @@ export function cleanTransactionReceipt(transactionReceipt) {
|
|
|
23
24
|
break;
|
|
24
25
|
case 'logs':
|
|
25
26
|
transactionReceipt[key].forEach((log, index) => {
|
|
26
|
-
|
|
27
|
-
switch (logKey) {
|
|
28
|
-
case 'address':
|
|
29
|
-
cleanedTransactionReceipt[key][index][logKey] =
|
|
30
|
-
toChecksumAddress(log[logKey]);
|
|
31
|
-
break;
|
|
32
|
-
case 'blockNumber':
|
|
33
|
-
case 'logIndex':
|
|
34
|
-
case 'transactionIndex':
|
|
35
|
-
cleanedTransactionReceipt[key][index][logKey] = Number(hexToDecimal(log[logKey]));
|
|
36
|
-
break;
|
|
37
|
-
case 'removed':
|
|
38
|
-
delete log[logKey];
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
27
|
+
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
42
28
|
});
|
|
43
29
|
}
|
|
44
30
|
});
|
|
@@ -8,7 +8,6 @@ export function cleanTransaction(transaction) {
|
|
|
8
8
|
switch (key) {
|
|
9
9
|
case 'blockNumber':
|
|
10
10
|
case 'chainId':
|
|
11
|
-
case 'nonce':
|
|
12
11
|
case 'transactionIndex':
|
|
13
12
|
case 'type':
|
|
14
13
|
case 'v':
|
|
@@ -25,6 +24,7 @@ export function cleanTransaction(transaction) {
|
|
|
25
24
|
case 'gasPrice':
|
|
26
25
|
case 'maxFeePerGas':
|
|
27
26
|
case 'maxPriorityFeePerGas':
|
|
27
|
+
case 'nonce':
|
|
28
28
|
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
-
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber' | 'eth_estimateGas';
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|