diff --git a/README.md b/README.md
index 4b97c9a..a0edbdb 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,16 @@
> A collection of JS utility functions for RSK.
## Addresses
+
+
+### isAddress(address) ⇒ Boolean
+Check if a string is an address
+
+**Kind**: global function
+**Params**
+
+- address String
+
### toChecksumAddress(address, chainId) ⇒ String
@@ -25,6 +35,29 @@ Validates address checksum
- address String
- chainId Integer
| String
+
+
+### isValidAddress(address, chainId) ⇒ Boolean
+Checks if an address is valid.
+
+**Kind**: global function
+**Params**
+
+- address String
+- chainId Integer
| String
+
+
+
+### searchChecksummedNetworks(address, [networks]) ⇒ Array
+Search network info of checksummed address
+
+**Kind**: global function
+**Params**
+
+- address String
+- [networks] Array
- chainId list
+see: https://chainid.network/chains.json
+
## Arrays
diff --git a/dist/addresses.js b/dist/addresses.js
index 9346206..de4e197 100644
--- a/dist/addresses.js
+++ b/dist/addresses.js
@@ -1,11 +1,12 @@
-"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.isAddress = isAddress;exports.toChecksumAddress = toChecksumAddress;exports.isValidChecksumAddress = isValidChecksumAddress;var _hashes = require("./hashes");
+"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.isAddress = isAddress;exports.toChecksumAddress = toChecksumAddress;exports.isValidChecksumAddress = isValidChecksumAddress;exports.isValidAddress = isValidAddress;exports.searchChecksummedNetworks = searchChecksummedNetworks;var _hashes = require("./hashes");
var _strings = require("./strings");
+var _networks = _interopRequireDefault(require("./networks.json"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
-
-
-
-
-
+/**
+ * @description Check if a string is an address
+ * @param {String} address
+ * @returns {Boolean}
+ */
function isAddress(address) {
return /^(0x)?[0-9a-fA-F]{40}$/.test(address);
}
@@ -32,4 +33,30 @@ function toChecksumAddress(address, chainId) {
*/
function isValidChecksumAddress(address, chainId) {
return isAddress(address) && toChecksumAddress(address, chainId) === address;
+}
+
+/**
+ * @description Checks if an address is valid.
+ * @param {String} address
+ * @param {Integer|String} chainId
+ * @returns {Boolean}
+ */
+function isValidAddress(address, chainId) {
+ if (typeof address !== 'string') return false;
+ if (address.match(/[A-F]/)) {
+ return isValidChecksumAddress(address, chainId);
+ }
+ return isAddress(address);
+}
+
+/**
+ * @description Search network info of checksummed address
+ * @param {String} address
+ * @param {Array} [networks], chainId list
+ * see: https://chainid.network/chains.json
+ * @returns {Array}
+ */
+function searchChecksummedNetworks(address, networks) {
+ networks = networks || _networks.default;
+ return networks.filter(net => toChecksumAddress(address, net.chainId) === address);
}
\ No newline at end of file
diff --git a/dist/hashes.js b/dist/hashes.js
index 7e31332..e8e2f1a 100644
--- a/dist/hashes.js
+++ b/dist/hashes.js
@@ -1,12 +1,11 @@
-"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.keccak256 = keccak256;
-var _keccak = _interopRequireDefault(require("keccak"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
+"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.keccak256 = keccak256;var _keccak = _interopRequireDefault(require("keccak"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
/**
- * @description Creates Keccak sha256 hash
- * @param {String|Number|Array|Buffer} input
- * @param {String} [format='hex']
- * @returns {Buffer}
- */
+ * @description Creates Keccak sha256 hash
+ * @param {String|Number|Array|Buffer} input
+ * @param {String} [format='hex']
+ * @returns {Buffer}
+ */
function keccak256(input, format = 'hex') {
return (0, _keccak.default)('keccak256').update(input).digest(format);
}
\ No newline at end of file
diff --git a/dist/networks.json b/dist/networks.json
new file mode 100644
index 0000000..153e6fc
--- /dev/null
+++ b/dist/networks.json
@@ -0,0 +1,167 @@
+[
+ {
+ "name": "Ethereum Mainnet",
+ "chainId": 1,
+ "shortName": "eth",
+ "chain": "ETH",
+ "network": "mainnet",
+ "networkId": 1,
+ "nativeCurrency": {
+ "name": "Ether",
+ "symbol": "ETH",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://mainnet.infura.io/v3/${INFURA_API_KEY}",
+ "https://api.mycryptoapi.com/eth"
+ ],
+ "faucets": [],
+ "infoURL": "https://ethereum.org",
+ "explorers": [
+ "https://etherscan.io"
+ ]
+ },
+ {
+ "name": "Ethereum Testnet Ropsten",
+ "chainId": 3,
+ "shortName": "rop",
+ "chain": "ETH",
+ "network": "ropsten",
+ "networkId": 3,
+ "nativeCurrency": {
+ "name": "Ropsten Ether",
+ "symbol": "ROP",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://ropsten.infura.io/v3/${INFURA_API_KEY}"
+ ],
+ "faucets": [
+ "https://faucet.ropsten.be?${ADDRESS}"
+ ],
+ "infoURL": "https://github.com/ethereum/ropsten",
+ "explorers": [
+ "https://ropsten.etherscan.io"
+ ]
+ },
+ {
+ "name": "RSK Mainnet",
+ "chainId": 30,
+ "shortName": "rsk",
+ "chain": "RSK",
+ "network": "mainnet",
+ "networkId": 30,
+ "nativeCurrency": {
+ "name": "RSK Mainnet Ether",
+ "symbol": "RSK",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://public-node.rsk.co",
+ "https://mycrypto.rsk.co"
+ ],
+ "faucets": [],
+ "infoURL": "https://rsk.co",
+ "explorers": [
+ "https://explorer.rsk.co",
+ "https://blockscout.com/rsk/mainnet"
+ ]
+ },
+ {
+ "name": "RSK Testnet",
+ "chainId": 31,
+ "shortName": "trsk",
+ "chain": "RSK",
+ "network": "testnet",
+ "networkId": 31,
+ "nativeCurrency": {
+ "name": "RSK Testnet Ether",
+ "symbol": "TRSK",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://public-node.testnet.rsk.co",
+ "https://mycrypto.testnet.rsk.co"
+ ],
+ "faucets": [
+ "https://faucet.testnet.rsk.co"
+ ],
+ "infoURL": "https://rsk.co",
+ "explorers": [
+ "https://explorer.testnet.rsk.co"
+ ]
+ },
+ {
+ "name": "Ethereum Testnet Rinkeby",
+ "chainId": 4,
+ "shortName": "rin",
+ "chain": "ETH",
+ "network": "rinkeby",
+ "networkId": 4,
+ "nativeCurrency": {
+ "name": "Rinkeby Ether",
+ "symbol": "RIN",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://rinkeby.infura.io/v3/${INFURA_API_KEY}"
+ ],
+ "faucets": [
+ "https://faucet.rinkeby.io"
+ ],
+ "infoURL": "https://www.rinkeby.io",
+ "explorers": [
+ "https://rinkeby.etherscan.io"
+ ]
+ },
+ {
+ "name": "Ethereum Testnet Kovan",
+ "chainId": 42,
+ "shortName": "kov",
+ "chain": "ETH",
+ "network": "kovan",
+ "networkId": 42,
+ "nativeCurrency": {
+ "name": "Kovan Ether",
+ "symbol": "KOV",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://kovan.infura.io/v3/${INFURA_API_KEY}"
+ ],
+ "faucets": [
+ "https://faucet.kovan.network",
+ "https://gitter.im/kovan-testnet/faucet"
+ ],
+ "infoURL": "https://kovan-testnet.github.io/website",
+ "explorers": [
+ "https://kovan.etherscan.io"
+ ]
+ },
+ {
+ "name": "Ethereum Testnet Görli",
+ "chainId": 5,
+ "shortName": "gor",
+ "chain": "ETH",
+ "network": "goerli",
+ "networkId": 5,
+ "nativeCurrency": {
+ "name": "Görli Ether",
+ "symbol": "GOR",
+ "decimals": 18
+ },
+ "rpc": [
+ "https://rpc.goerli.mudit.blog/",
+ "https://rpc.slock.it/goerli ",
+ "https://goerli.prylabs.net/"
+ ],
+ "faucets": [
+ "https://goerli-faucet.slock.it/?address=${ADDRESS}",
+ "https://faucet.goerli.mudit.blog"
+ ],
+ "infoURL": "https://goerli.net/#about",
+ "explorers": [
+ "https://goerli.etherscan.io"
+ ]
+ }
+]
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index a85d9a3..fe2d613 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "rsk-utils",
- "version": "0.0.1",
+ "version": "0.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 172b608..b5d8b6c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "rsk-utils",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "A collection of JS utility functions for RSK",
"main": "dist/index.js",
"scripts": {