Skip to content

Commit

Permalink
Build 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Nov 27, 2019
1 parent 7289113 commit e3b547a
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 15 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
> A collection of JS utility functions for RSK.
## Addresses
<a name="isAddress"></a>

### isAddress(address) ⇒ <code>Boolean</code>
Check if a string is an address

**Kind**: global function
**Params**

- address <code>String</code>

<a name="toChecksumAddress"></a>

### toChecksumAddress(address, chainId) ⇒ <code>String</code>
Expand All @@ -25,6 +35,29 @@ Validates address checksum
- address <code>String</code>
- chainId <code>Integer</code> | <code>String</code>

<a name="isValidAddress"></a>

### isValidAddress(address, chainId) ⇒ <code>Boolean</code>
Checks if an address is valid.

**Kind**: global function
**Params**

- address <code>String</code>
- chainId <code>Integer</code> | <code>String</code>

<a name="searchChecksummedNetworks"></a>

### searchChecksummedNetworks(address, [networks]) ⇒ <code>Array</code>
Search network info of checksummed address

**Kind**: global function
**Params**

- address <code>String</code>
- [networks] <code>Array</code> - chainId list
see: https://chainid.network/chains.json


## Arrays
<a name="arrayIntersection"></a>
Expand Down
39 changes: 33 additions & 6 deletions dist/addresses.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand All @@ -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);
}
13 changes: 6 additions & 7 deletions dist/hashes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 167 additions & 0 deletions dist/networks.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit e3b547a

Please sign in to comment.