essential-eth 0.9.1 → 0.9.2-beta.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/dist/essential-eth.esm.mjs +2 -0
- package/dist/essential-eth.esm.mjs.map +1 -0
- package/dist/essential-eth.js +2 -0
- package/dist/essential-eth.js.map +1 -0
- package/dist/essential-eth.modern.mjs +2 -0
- package/dist/essential-eth.modern.mjs.map +1 -0
- package/dist/essential-eth.umd.js +2 -0
- package/dist/essential-eth.umd.js.map +1 -0
- package/dist/logger/package-version.d.ts +1 -0
- package/package.json +12 -13
- package/readme.md +1 -1
- package/dist/cjs/classes/Contract.js +0 -138
- package/dist/cjs/classes/test/Contract/crv-abi.js +0 -488
- package/dist/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/dist/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/dist/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/dist/cjs/classes/utils/clean-block.js +0 -160
- package/dist/cjs/classes/utils/clean-log.js +0 -37
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +0 -51
- package/dist/cjs/classes/utils/clean-transaction.js +0 -52
- package/dist/cjs/classes/utils/encode-decode-transaction.js +0 -177
- package/dist/cjs/classes/utils/fetchers.js +0 -94
- package/dist/cjs/classes/utils/hex-to-decimal.js +0 -24
- package/dist/cjs/classes/utils/prepare-transaction.js +0 -45
- package/dist/cjs/index.js +0 -56
- package/dist/cjs/index.umd.js +0 -2
- package/dist/cjs/index.umd.js.map +0 -1
- package/dist/cjs/logger/logger.js +0 -36
- package/dist/cjs/logger/package-version.d.ts +0 -1
- package/dist/cjs/logger/package-version.js +0 -5
- package/dist/cjs/providers/AlchemyProvider.js +0 -11
- package/dist/cjs/providers/BaseProvider.js +0 -549
- package/dist/cjs/providers/FallthroughProvider.js +0 -73
- package/dist/cjs/providers/JsonRpcProvider.js +0 -46
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +0 -152
- package/dist/cjs/providers/test/mock-of.js +0 -12
- package/dist/cjs/providers/test/rpc-urls.js +0 -25
- package/dist/cjs/providers/utils/chains-info.js +0 -71
- package/dist/cjs/shared/tiny-big/helpers.js +0 -97
- package/dist/cjs/shared/tiny-big/tiny-big.js +0 -101
- package/dist/cjs/shared/validate-type.js +0 -9
- package/dist/cjs/types/Block.types.js +0 -2
- package/dist/cjs/types/Contract.types.js +0 -2
- package/dist/cjs/types/FeeData.types.js +0 -2
- package/dist/cjs/types/Filter.types.js +0 -2
- package/dist/cjs/types/Network.types.js +0 -2
- package/dist/cjs/types/Transaction.types.js +0 -2
- package/dist/cjs/utils/bytes.js +0 -711
- package/dist/cjs/utils/compute-address.js +0 -34
- package/dist/cjs/utils/compute-public-key.js +0 -26
- package/dist/cjs/utils/ether-to-gwei.js +0 -35
- package/dist/cjs/utils/ether-to-wei.js +0 -35
- package/dist/cjs/utils/gwei-to-ether.js +0 -35
- package/dist/cjs/utils/hash-message.js +0 -30
- package/dist/cjs/utils/is-address.js +0 -39
- package/dist/cjs/utils/keccak256.js +0 -31
- package/dist/cjs/utils/solidity-keccak256.js +0 -138
- package/dist/cjs/utils/split-signature.js +0 -163
- package/dist/cjs/utils/to-checksum-address.js +0 -46
- package/dist/cjs/utils/to-utf8-bytes.js +0 -21
- package/dist/cjs/utils/wei-to-ether.js +0 -45
- package/dist/esm/classes/Contract.d.ts +0 -11
- package/dist/esm/classes/Contract.js +0 -61
- package/dist/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/crv-abi.js +0 -470
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/ens-abi.js +0 -435
- package/dist/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/fei-abi.js +0 -521
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/foo-abi.js +0 -33
- package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/dist/esm/classes/utils/clean-block.d.ts +0 -2
- package/dist/esm/classes/utils/clean-block.js +0 -35
- package/dist/esm/classes/utils/clean-log.d.ts +0 -2
- package/dist/esm/classes/utils/clean-log.js +0 -26
- package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +0 -2
- package/dist/esm/classes/utils/clean-transaction-receipt.js +0 -35
- package/dist/esm/classes/utils/clean-transaction.d.ts +0 -2
- package/dist/esm/classes/utils/clean-transaction.js +0 -34
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
- package/dist/esm/classes/utils/encode-decode-transaction.js +0 -134
- package/dist/esm/classes/utils/fetchers.d.ts +0 -15
- package/dist/esm/classes/utils/fetchers.js +0 -46
- package/dist/esm/classes/utils/hex-to-decimal.d.ts +0 -1
- package/dist/esm/classes/utils/hex-to-decimal.js +0 -3
- package/dist/esm/classes/utils/prepare-transaction.d.ts +0 -2
- package/dist/esm/classes/utils/prepare-transaction.js +0 -34
- package/dist/esm/index.d.ts +0 -25
- package/dist/esm/index.js +0 -20
- package/dist/esm/logger/logger.d.ts +0 -11
- package/dist/esm/logger/logger.js +0 -33
- package/dist/esm/logger/package-version.d.ts +0 -1
- package/dist/esm/logger/package-version.js +0 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +0 -4
- package/dist/esm/providers/AlchemyProvider.js +0 -7
- package/dist/esm/providers/BaseProvider.d.ts +0 -26
- package/dist/esm/providers/BaseProvider.js +0 -172
- package/dist/esm/providers/FallthroughProvider.d.ts +0 -11
- package/dist/esm/providers/FallthroughProvider.js +0 -49
- package/dist/esm/providers/JsonRpcProvider.d.ts +0 -7
- package/dist/esm/providers/JsonRpcProvider.js +0 -15
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +0 -142
- package/dist/esm/providers/test/mock-of.d.ts +0 -2
- package/dist/esm/providers/test/mock-of.js +0 -1
- package/dist/esm/providers/test/rpc-urls.d.ts +0 -12
- package/dist/esm/providers/test/rpc-urls.js +0 -19
- package/dist/esm/providers/utils/chains-info.d.ts +0 -24
- package/dist/esm/providers/utils/chains-info.js +0 -67
- package/dist/esm/shared/tiny-big/helpers.d.ts +0 -1
- package/dist/esm/shared/tiny-big/helpers.js +0 -58
- package/dist/esm/shared/tiny-big/tiny-big.d.ts +0 -10
- package/dist/esm/shared/tiny-big/tiny-big.js +0 -45
- package/dist/esm/shared/validate-type.d.ts +0 -3
- package/dist/esm/shared/validate-type.js +0 -5
- package/dist/esm/types/Block.types.d.ts +0 -40
- package/dist/esm/types/Block.types.js +0 -1
- package/dist/esm/types/Contract.types.d.ts +0 -24
- package/dist/esm/types/Contract.types.js +0 -1
- package/dist/esm/types/FeeData.types.d.ts +0 -7
- package/dist/esm/types/FeeData.types.js +0 -1
- package/dist/esm/types/Filter.types.d.ts +0 -12
- package/dist/esm/types/Filter.types.js +0 -1
- package/dist/esm/types/Network.types.d.ts +0 -5
- package/dist/esm/types/Network.types.js +0 -1
- package/dist/esm/types/Transaction.types.d.ts +0 -113
- package/dist/esm/types/Transaction.types.js +0 -1
- package/dist/esm/utils/bytes.d.ts +0 -40
- package/dist/esm/utils/bytes.js +0 -245
- package/dist/esm/utils/compute-address.d.ts +0 -1
- package/dist/esm/utils/compute-address.js +0 -12
- package/dist/esm/utils/compute-public-key.d.ts +0 -2
- package/dist/esm/utils/compute-public-key.js +0 -6
- package/dist/esm/utils/ether-to-gwei.d.ts +0 -3
- package/dist/esm/utils/ether-to-gwei.js +0 -7
- package/dist/esm/utils/ether-to-wei.d.ts +0 -3
- package/dist/esm/utils/ether-to-wei.js +0 -7
- package/dist/esm/utils/gwei-to-ether.d.ts +0 -3
- package/dist/esm/utils/gwei-to-ether.js +0 -7
- package/dist/esm/utils/hash-message.d.ts +0 -2
- package/dist/esm/utils/hash-message.js +0 -14
- package/dist/esm/utils/is-address.d.ts +0 -1
- package/dist/esm/utils/is-address.js +0 -12
- package/dist/esm/utils/keccak256.d.ts +0 -2
- package/dist/esm/utils/keccak256.js +0 -13
- package/dist/esm/utils/solidity-keccak256.d.ts +0 -2
- package/dist/esm/utils/solidity-keccak256.js +0 -85
- package/dist/esm/utils/split-signature.d.ts +0 -2
- package/dist/esm/utils/split-signature.js +0 -126
- package/dist/esm/utils/to-checksum-address.d.ts +0 -1
- package/dist/esm/utils/to-checksum-address.js +0 -25
- package/dist/esm/utils/to-utf8-bytes.d.ts +0 -1
- package/dist/esm/utils/to-utf8-bytes.js +0 -3
- package/dist/esm/utils/wei-to-ether.d.ts +0 -3
- package/dist/esm/utils/wei-to-ether.js +0 -16
- /package/dist/{cjs/classes → classes}/Contract.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/test/Contract/crv-abi.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/test/Contract/ens-abi.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/test/Contract/fei-abi.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/test/Contract/foo-abi.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/test/Contract/uniswap-abi.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/clean-block.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/clean-log.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/clean-transaction-receipt.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/clean-transaction.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/encode-decode-transaction.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/fetchers.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/hex-to-decimal.d.ts +0 -0
- /package/dist/{cjs/classes → classes}/utils/prepare-transaction.d.ts +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/logger → logger}/logger.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/AlchemyProvider.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/BaseProvider.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/FallthroughProvider.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/JsonRpcProvider.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/test/json-rpc-provider/get-logs/mocks.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/test/mock-of.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/test/rpc-urls.d.ts +0 -0
- /package/dist/{cjs/providers → providers}/utils/chains-info.d.ts +0 -0
- /package/dist/{cjs/shared → shared}/tiny-big/helpers.d.ts +0 -0
- /package/dist/{cjs/shared → shared}/tiny-big/tiny-big.d.ts +0 -0
- /package/dist/{cjs/shared → shared}/validate-type.d.ts +0 -0
- /package/dist/{cjs/types → types}/Block.types.d.ts +0 -0
- /package/dist/{cjs/types → types}/Contract.types.d.ts +0 -0
- /package/dist/{cjs/types → types}/FeeData.types.d.ts +0 -0
- /package/dist/{cjs/types → types}/Filter.types.d.ts +0 -0
- /package/dist/{cjs/types → types}/Network.types.d.ts +0 -0
- /package/dist/{cjs/types → types}/Transaction.types.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/bytes.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/compute-address.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/compute-public-key.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/ether-to-gwei.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/ether-to-wei.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/gwei-to-ether.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/hash-message.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/is-address.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/keccak256.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/solidity-keccak256.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/split-signature.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/to-checksum-address.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/to-utf8-bytes.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/wei-to-ether.d.ts +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeAddress = void 0;
|
|
4
|
-
const bytes_1 = require("./bytes");
|
|
5
|
-
const compute_public_key_1 = require("./compute-public-key");
|
|
6
|
-
const keccak256_1 = require("./keccak256");
|
|
7
|
-
const to_checksum_address_1 = require("./to-checksum-address");
|
|
8
|
-
/**
|
|
9
|
-
* Computes the address that corresponds to a specified public or private key
|
|
10
|
-
*
|
|
11
|
-
* @param key the public or private key to find the address related to
|
|
12
|
-
* @returns the address that corresponds to the key specified
|
|
13
|
-
* @example
|
|
14
|
-
* ```javascript
|
|
15
|
-
* computeAddress('0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952'); // public key
|
|
16
|
-
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
17
|
-
* ```
|
|
18
|
-
* @example
|
|
19
|
-
* ```javascript
|
|
20
|
-
* computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
|
|
21
|
-
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
function computeAddress(key) {
|
|
25
|
-
// compressed public keys start with 0x04
|
|
26
|
-
// uncompressed public keys start with 0x03 or 0x02
|
|
27
|
-
if (!key.startsWith('0x04') &&
|
|
28
|
-
!key.startsWith('0x03') &&
|
|
29
|
-
!key.startsWith('0x02')) {
|
|
30
|
-
key = (0, compute_public_key_1.computePublicKey)(key);
|
|
31
|
-
}
|
|
32
|
-
return (0, to_checksum_address_1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
|
|
33
|
-
}
|
|
34
|
-
exports.computeAddress = computeAddress;
|
|
@@ -1,26 +0,0 @@
|
|
|
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;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.etherToGwei = void 0;
|
|
4
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
6
|
-
/**
|
|
7
|
-
* Convert from Ether to Gwei
|
|
8
|
-
*
|
|
9
|
-
* No direct equivalent in ether.js; requires multiple functions to achieve.
|
|
10
|
-
*
|
|
11
|
-
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
12
|
-
*
|
|
13
|
-
* @param etherQuantity the amount of ether to convert to gwei
|
|
14
|
-
* @returns a number of gwei equivalent to the specified ether
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* etherToGwei('1000').toString()
|
|
18
|
-
* // '1000000000000'
|
|
19
|
-
* etherToGwei(1000).toString()
|
|
20
|
-
* // '1000000000000'
|
|
21
|
-
* ```
|
|
22
|
-
* @example
|
|
23
|
-
* ```javascript
|
|
24
|
-
* etherToGwei('1000').toNumber()
|
|
25
|
-
* // 1000000000000
|
|
26
|
-
* etherToGwei(1000).toNumber()
|
|
27
|
-
* // 1000000000000
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function etherToGwei(etherQuantity) {
|
|
31
|
-
(0, validate_type_1.validateType)(etherQuantity, ['string', 'number', 'object']);
|
|
32
|
-
const result = (0, tiny_big_1.tinyBig)(etherQuantity).times('1000000000');
|
|
33
|
-
return (0, tiny_big_1.tinyBig)(result);
|
|
34
|
-
}
|
|
35
|
-
exports.etherToGwei = etherToGwei;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.etherToWei = void 0;
|
|
4
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
6
|
-
/**
|
|
7
|
-
* Convert Ether to Wei
|
|
8
|
-
*
|
|
9
|
-
* Similar to ["parseEther" in ethers.js](https://docs.ethers.io/v5/api/utils/display-logic/#utils-parseEther)
|
|
10
|
-
*
|
|
11
|
-
* Similar to ["toWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#towei)
|
|
12
|
-
*
|
|
13
|
-
* @param etherQuantity the amount of ether to convert to wei
|
|
14
|
-
* @returns a number of wei equivalent to the specified ether
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* etherToWei('1000').toString()
|
|
18
|
-
* // '1000000000000000000000'
|
|
19
|
-
* etherToWei(1000).toString()
|
|
20
|
-
* // '1000000000000000000000'
|
|
21
|
-
* ```
|
|
22
|
-
* @example
|
|
23
|
-
* ```javascript
|
|
24
|
-
* etherToWei('1000').toNumber()
|
|
25
|
-
* // 1000000000000000000000
|
|
26
|
-
* etherToWei(1000).toNumber()
|
|
27
|
-
* // 1000000000000000000000
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function etherToWei(etherQuantity) {
|
|
31
|
-
(0, validate_type_1.validateType)(etherQuantity, ['string', 'number', 'object']);
|
|
32
|
-
const result = (0, tiny_big_1.tinyBig)(etherQuantity).times('1000000000000000000');
|
|
33
|
-
return (0, tiny_big_1.tinyBig)(result);
|
|
34
|
-
}
|
|
35
|
-
exports.etherToWei = etherToWei;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gweiToEther = void 0;
|
|
4
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
6
|
-
/**
|
|
7
|
-
* Convert from Gwei to Ether
|
|
8
|
-
*
|
|
9
|
-
* No direct equivalent in ethers.js; requires multiple functions to achieve.
|
|
10
|
-
*
|
|
11
|
-
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
12
|
-
*
|
|
13
|
-
* @param gweiQuantity the amount of gwei to convert to ether
|
|
14
|
-
* @returns a number of ether equivalent to the specified gwei
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* gweiToEther('1000000000000').toString()
|
|
18
|
-
* // '1000'
|
|
19
|
-
* gweiToEther(1000000000000).toString()
|
|
20
|
-
* // '1000'
|
|
21
|
-
* ```
|
|
22
|
-
* @example
|
|
23
|
-
* ```javascript
|
|
24
|
-
* gweiToEther('1000000000000').toNumber()
|
|
25
|
-
* // 1000
|
|
26
|
-
* gweiToEther(1000000000000).toNumber()
|
|
27
|
-
* // 1000
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function gweiToEther(gweiQuantity) {
|
|
31
|
-
(0, validate_type_1.validateType)(gweiQuantity, ['string', 'number', 'object']);
|
|
32
|
-
const result = (0, tiny_big_1.tinyBig)(gweiQuantity).div('1000000000');
|
|
33
|
-
return (0, tiny_big_1.tinyBig)(result);
|
|
34
|
-
}
|
|
35
|
-
exports.gweiToEther = gweiToEther;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hashMessage = void 0;
|
|
4
|
-
const bytes_1 = require("./bytes");
|
|
5
|
-
const keccak256_1 = require("./keccak256");
|
|
6
|
-
const to_utf8_bytes_1 = require("./to-utf8-bytes");
|
|
7
|
-
const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
8
|
-
/**
|
|
9
|
-
* Computes the EIP-191 personal message digest of message.
|
|
10
|
-
* Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
|
|
11
|
-
*
|
|
12
|
-
* @param message the message to hash
|
|
13
|
-
* @returns a message hashed using Keccak256 that matches the EIP-191 standard
|
|
14
|
-
* @example
|
|
15
|
-
* ```javascript
|
|
16
|
-
* hashMessage("Hello World");
|
|
17
|
-
* // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
function hashMessage(message) {
|
|
21
|
-
if (typeof message === 'string') {
|
|
22
|
-
message = (0, to_utf8_bytes_1.toUtf8Bytes)(message);
|
|
23
|
-
}
|
|
24
|
-
return (0, keccak256_1.keccak256)((0, bytes_1.concat)([
|
|
25
|
-
(0, to_utf8_bytes_1.toUtf8Bytes)(messagePrefix),
|
|
26
|
-
(0, to_utf8_bytes_1.toUtf8Bytes)(String(message.length)),
|
|
27
|
-
message,
|
|
28
|
-
]));
|
|
29
|
-
}
|
|
30
|
-
exports.hashMessage = hashMessage;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAddress = void 0;
|
|
4
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
5
|
-
const to_checksum_address_1 = require("./to-checksum-address");
|
|
6
|
-
/**
|
|
7
|
-
* Returns a boolean as to whether the input is a valid address.
|
|
8
|
-
* Does NOT support ICAP addresses
|
|
9
|
-
*
|
|
10
|
-
* @param address the address to check the validity of
|
|
11
|
-
* @returns a boolean for whether the input is a valid address
|
|
12
|
-
* @example
|
|
13
|
-
* ```javascript
|
|
14
|
-
* isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
|
|
15
|
-
* // true
|
|
16
|
-
* ```
|
|
17
|
-
* @example
|
|
18
|
-
* ```javascript
|
|
19
|
-
* isAddress('bad');
|
|
20
|
-
* // false
|
|
21
|
-
* ```
|
|
22
|
-
* @example
|
|
23
|
-
* ```javascript
|
|
24
|
-
* // Does NOT support ENS.
|
|
25
|
-
* isAddress('vitalik.eth');
|
|
26
|
-
* // false
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
function isAddress(address) {
|
|
30
|
-
(0, validate_type_1.validateType)(address, ['string']);
|
|
31
|
-
try {
|
|
32
|
-
(0, to_checksum_address_1.toChecksumAddress)(address);
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.isAddress = isAddress;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keccak256 = void 0;
|
|
4
|
-
const sha3_1 = require("sha3");
|
|
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) {
|
|
20
|
-
let bufferableData;
|
|
21
|
-
if (typeof data === 'string') {
|
|
22
|
-
bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
bufferableData = Buffer.from(data);
|
|
26
|
-
}
|
|
27
|
-
const keccak = new sha3_1.Keccak(256);
|
|
28
|
-
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
29
|
-
return addressHash;
|
|
30
|
-
}
|
|
31
|
-
exports.keccak256 = keccak256;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.solidityKeccak256 = exports.pack = void 0;
|
|
4
|
-
const buffer_1 = require("buffer");
|
|
5
|
-
const encode_decode_transaction_1 = require("../classes/utils/encode-decode-transaction");
|
|
6
|
-
const logger_1 = require("../logger/logger");
|
|
7
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
8
|
-
const bytes_1 = require("./bytes");
|
|
9
|
-
const keccak256_1 = require("./keccak256");
|
|
10
|
-
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
11
|
-
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
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
|
-
*/
|
|
23
|
-
function _pack(type, value, isArray) {
|
|
24
|
-
switch (type) {
|
|
25
|
-
case 'address':
|
|
26
|
-
if (isArray) {
|
|
27
|
-
return (0, bytes_1.zeroPad)(value, 32);
|
|
28
|
-
}
|
|
29
|
-
return (0, bytes_1.arrayify)(value);
|
|
30
|
-
case 'string':
|
|
31
|
-
return buffer_1.Buffer.from(value);
|
|
32
|
-
case 'bytes':
|
|
33
|
-
return (0, bytes_1.arrayify)(value);
|
|
34
|
-
case 'bool':
|
|
35
|
-
value = value ? '0x01' : '0x00';
|
|
36
|
-
if (isArray) {
|
|
37
|
-
return (0, bytes_1.zeroPad)(value, 32);
|
|
38
|
-
}
|
|
39
|
-
return (0, bytes_1.arrayify)(value);
|
|
40
|
-
}
|
|
41
|
-
let match = type.match(regexNumber);
|
|
42
|
-
if (match) {
|
|
43
|
-
//let signed = (match[1] === "int")
|
|
44
|
-
let size = parseInt(match[2] || '256');
|
|
45
|
-
if ((match[2] && String(size) !== match[2]) ||
|
|
46
|
-
size % 8 !== 0 ||
|
|
47
|
-
size === 0 ||
|
|
48
|
-
size > 256) {
|
|
49
|
-
logger_1.logger.throwArgumentError('invalid number type', 'type', type);
|
|
50
|
-
}
|
|
51
|
-
if (isArray) {
|
|
52
|
-
size = 256;
|
|
53
|
-
}
|
|
54
|
-
value = (0, tiny_big_1.tinyBig)(value).toTwos(size).toNumber();
|
|
55
|
-
const hexValue = (0, bytes_1.hexlify)(value);
|
|
56
|
-
return (0, bytes_1.zeroPad)(hexValue, size / 8);
|
|
57
|
-
}
|
|
58
|
-
match = type.match(regexBytes);
|
|
59
|
-
if (match) {
|
|
60
|
-
const size = parseInt(match[1]);
|
|
61
|
-
if (String(size) !== match[1] || size === 0 || size > 32) {
|
|
62
|
-
logger_1.logger.throwArgumentError('invalid bytes type', 'type', type);
|
|
63
|
-
}
|
|
64
|
-
if ((0, bytes_1.arrayify)(value).byteLength !== size) {
|
|
65
|
-
logger_1.logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
|
|
66
|
-
}
|
|
67
|
-
if (isArray) {
|
|
68
|
-
return (0, bytes_1.arrayify)((value + encode_decode_transaction_1.hexFalse).substring(0, 66));
|
|
69
|
-
}
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
match = type.match(regexArray);
|
|
73
|
-
if (match && Array.isArray(value)) {
|
|
74
|
-
const baseType = match[1];
|
|
75
|
-
const count = parseInt(match[2] || String(value.length));
|
|
76
|
-
if (count != value.length) {
|
|
77
|
-
logger_1.logger.throwArgumentError(`invalid array length for ${type}`, 'value', value);
|
|
78
|
-
}
|
|
79
|
-
const result = [];
|
|
80
|
-
value.forEach(function (value) {
|
|
81
|
-
result.push(_pack(baseType, value, true));
|
|
82
|
-
});
|
|
83
|
-
return (0, bytes_1.concat)(result);
|
|
84
|
-
}
|
|
85
|
-
return logger_1.logger.throwArgumentError('invalid type', 'type', type);
|
|
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
|
-
*/
|
|
101
|
-
function pack(types, values) {
|
|
102
|
-
if (types.length != values.length) {
|
|
103
|
-
logger_1.logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
|
|
104
|
-
}
|
|
105
|
-
const tight = [];
|
|
106
|
-
types.forEach(function (type, index) {
|
|
107
|
-
tight.push(_pack(type, values[index]));
|
|
108
|
-
});
|
|
109
|
-
return (0, bytes_1.hexlify)((0, bytes_1.concat)(tight));
|
|
110
|
-
}
|
|
111
|
-
exports.pack = pack;
|
|
112
|
-
/**
|
|
113
|
-
* Hashes data from Solidity using the Keccak256 algorithm.
|
|
114
|
-
*
|
|
115
|
-
* Similar to ["solidityKeccak256" in ethers.js](https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256)
|
|
116
|
-
*
|
|
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
|
|
120
|
-
* @example
|
|
121
|
-
* ```javascript
|
|
122
|
-
* const types = ['string', 'bool', 'uint32'];
|
|
123
|
-
* const values = ['essential-eth is great', true, 14];
|
|
124
|
-
* solidityKeccak256(types, values);
|
|
125
|
-
* // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
126
|
-
* ```
|
|
127
|
-
* @example
|
|
128
|
-
* ```javascript
|
|
129
|
-
* const types = ['bytes4', 'uint32[5]'];
|
|
130
|
-
* const values = [[116, 101, 115, 116], [5, 3, 4, 9, 18]];
|
|
131
|
-
* solidityKeccak256(types, values);
|
|
132
|
-
* // '0x038707a887f09355dc545412b058e7ba8f3c74047050c7c5e5e52eec608053d9'
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
function solidityKeccak256(types, values) {
|
|
136
|
-
return (0, keccak256_1.keccak256)(pack(types, values));
|
|
137
|
-
}
|
|
138
|
-
exports.solidityKeccak256 = solidityKeccak256;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitSignature = void 0;
|
|
4
|
-
const logger_1 = require("./../logger/logger");
|
|
5
|
-
const bytes_1 = require("./bytes");
|
|
6
|
-
/**
|
|
7
|
-
* Expands a signature into the full signature object and fills in missing properties.
|
|
8
|
-
*
|
|
9
|
-
* Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
10
|
-
*
|
|
11
|
-
* @param signature the signature object to split, parse, and compute missing properties from
|
|
12
|
-
* @returns a full signature object with all properties filled
|
|
13
|
-
* @example
|
|
14
|
-
* ```javascript
|
|
15
|
-
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
16
|
-
* splitSignature(signature);
|
|
17
|
-
* {
|
|
18
|
-
* r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
19
|
-
* s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
20
|
-
* _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
21
|
-
* recoveryParam: 0,
|
|
22
|
-
* v: 27,
|
|
23
|
-
* yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
24
|
-
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
function splitSignature(signature) {
|
|
29
|
-
const result = {
|
|
30
|
-
r: '0x',
|
|
31
|
-
s: '0x',
|
|
32
|
-
_vs: '0x',
|
|
33
|
-
recoveryParam: 0,
|
|
34
|
-
v: 0,
|
|
35
|
-
yParityAndS: '0x',
|
|
36
|
-
compact: '0x',
|
|
37
|
-
};
|
|
38
|
-
if ((0, bytes_1.isBytesLike)(signature)) {
|
|
39
|
-
const bytes = (0, bytes_1.arrayify)(signature);
|
|
40
|
-
// Get the r, s and v
|
|
41
|
-
if (bytes.length === 64) {
|
|
42
|
-
// EIP-2098; pull the v from the top bit of s and clear it
|
|
43
|
-
result.v = 27 + (bytes[32] >> 7);
|
|
44
|
-
bytes[32] &= 0x7f;
|
|
45
|
-
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
46
|
-
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
47
|
-
}
|
|
48
|
-
else if (bytes.length === 65) {
|
|
49
|
-
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
50
|
-
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
51
|
-
result.v = bytes[64];
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
logger_1.logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
55
|
-
}
|
|
56
|
-
// Allow a recid to be used as the v
|
|
57
|
-
if (result.v < 27) {
|
|
58
|
-
if (result.v === 0 || result.v === 1) {
|
|
59
|
-
result.v += 27;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
logger_1.logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Compute recoveryParam from v
|
|
66
|
-
result.recoveryParam = 1 - (result.v % 2);
|
|
67
|
-
// Compute _vs from recoveryParam and s
|
|
68
|
-
if (result.recoveryParam) {
|
|
69
|
-
bytes[32] |= 0x80;
|
|
70
|
-
}
|
|
71
|
-
result._vs = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
result.r = signature.r;
|
|
75
|
-
result.s = signature.s;
|
|
76
|
-
result.v = signature.v;
|
|
77
|
-
result.recoveryParam = signature.recoveryParam;
|
|
78
|
-
result._vs = signature._vs;
|
|
79
|
-
// If the _vs is available, use it to populate missing s, v and recoveryParam
|
|
80
|
-
// and verify non-missing s, v and recoveryParam
|
|
81
|
-
if (result._vs != null) {
|
|
82
|
-
const vs_1 = (0, bytes_1.zeroPad)((0, bytes_1.arrayify)(result._vs), 32);
|
|
83
|
-
result._vs = (0, bytes_1.hexlify)(vs_1);
|
|
84
|
-
// Set or check the recid
|
|
85
|
-
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
86
|
-
if (result.recoveryParam == null) {
|
|
87
|
-
result.recoveryParam = recoveryParam;
|
|
88
|
-
}
|
|
89
|
-
else if (result.recoveryParam !== recoveryParam) {
|
|
90
|
-
logger_1.logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
91
|
-
}
|
|
92
|
-
// Set or check the s
|
|
93
|
-
vs_1[0] &= 0x7f;
|
|
94
|
-
const s = (0, bytes_1.hexlify)(vs_1);
|
|
95
|
-
if (result.s == null) {
|
|
96
|
-
result.s = s;
|
|
97
|
-
}
|
|
98
|
-
else if (result.s !== s) {
|
|
99
|
-
logger_1.logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Use recid and v to populate each other
|
|
103
|
-
if (result.recoveryParam == null) {
|
|
104
|
-
if (result.v == null) {
|
|
105
|
-
logger_1.logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
106
|
-
}
|
|
107
|
-
else if (result.v === 0 || result.v === 1) {
|
|
108
|
-
result.recoveryParam = result.v;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
result.recoveryParam = 1 - (result.v % 2);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
if (result.v == null) {
|
|
116
|
-
result.v = 27 + result.recoveryParam;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
120
|
-
if (result.recoveryParam !== recId) {
|
|
121
|
-
logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
|
|
126
|
-
logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
|
|
130
|
-
}
|
|
131
|
-
if (result.s == null || !(0, bytes_1.isHexString)(result.s)) {
|
|
132
|
-
logger_1.logger.throwArgumentError('signature missing or invalid s', 'signature', signature);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
result.s = (0, bytes_1.hexZeroPad)(result.s, 32);
|
|
136
|
-
}
|
|
137
|
-
const vs = (0, bytes_1.arrayify)(result.s);
|
|
138
|
-
if (vs[0] >= 128) {
|
|
139
|
-
logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
140
|
-
}
|
|
141
|
-
if (result.recoveryParam) {
|
|
142
|
-
vs[0] |= 0x80;
|
|
143
|
-
}
|
|
144
|
-
const _vs = (0, bytes_1.hexlify)(vs);
|
|
145
|
-
if (result._vs) {
|
|
146
|
-
if (!(0, bytes_1.isHexString)(result._vs)) {
|
|
147
|
-
logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
148
|
-
}
|
|
149
|
-
result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
|
|
150
|
-
}
|
|
151
|
-
// Set or check the _vs
|
|
152
|
-
if (result._vs == null) {
|
|
153
|
-
result._vs = _vs;
|
|
154
|
-
}
|
|
155
|
-
else if (result._vs !== _vs) {
|
|
156
|
-
logger_1.logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
result.yParityAndS = result._vs;
|
|
160
|
-
result.compact = result.r + result.yParityAndS.substring(2);
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
exports.splitSignature = splitSignature;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toChecksumAddress = void 0;
|
|
4
|
-
const sha3_1 = require("sha3");
|
|
5
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
6
|
-
/**
|
|
7
|
-
* Returns an Ethereum address in proper mixed-case checksum.
|
|
8
|
-
* Does NOT support ICAP
|
|
9
|
-
*
|
|
10
|
-
* @param address An Ethereum address. Mixed, lower, and uppercase are all valid
|
|
11
|
-
* @returns a valid checksum address
|
|
12
|
-
* @example
|
|
13
|
-
* ```javascript
|
|
14
|
-
* toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
15
|
-
* // '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* Similar to ["getAddress" in ethers.js](https://docs.ethers.io/v5/api/utils/address/#utils-getAddress)
|
|
19
|
-
*
|
|
20
|
-
* Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#tochecksumaddress)
|
|
21
|
-
*/
|
|
22
|
-
function toChecksumAddress(address) {
|
|
23
|
-
(0, validate_type_1.validateType)(address, ['string']);
|
|
24
|
-
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
|
|
25
|
-
throw new Error(`Invalid Ethereum address "${address}"`);
|
|
26
|
-
}
|
|
27
|
-
const _address = address.toLowerCase().replace(/^0x/i, '');
|
|
28
|
-
const keccak = new sha3_1.Keccak(256);
|
|
29
|
-
const addressHash = keccak.update(_address).digest('hex').replace(/^0x/i, '');
|
|
30
|
-
let checksumAddress = '0x';
|
|
31
|
-
for (let i = 0; i < _address.length; i++) {
|
|
32
|
-
// If ith character is 8 to f then make it uppercase
|
|
33
|
-
if (parseInt(addressHash[i], 16) > 7) {
|
|
34
|
-
checksumAddress += _address[i].toUpperCase();
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
checksumAddress += _address[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) &&
|
|
41
|
-
checksumAddress !== address) {
|
|
42
|
-
throw new Error(`Invalid Checksum address for "${address}"`);
|
|
43
|
-
}
|
|
44
|
-
return checksumAddress;
|
|
45
|
-
}
|
|
46
|
-
exports.toChecksumAddress = toChecksumAddress;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
*/
|
|
18
|
-
function toUtf8Bytes(data) {
|
|
19
|
-
return new Uint8Array(Buffer.from(data));
|
|
20
|
-
}
|
|
21
|
-
exports.toUtf8Bytes = toUtf8Bytes;
|