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