2022-07-24 03:16:34 +00:00
|
|
|
import * as chainNetworks from "./networks.json";
|
2022-07-05 20:14:39 +00:00
|
|
|
|
|
|
|
type networks = { [net: string]: string };
|
2022-07-04 23:17:58 +00:00
|
|
|
|
|
|
|
export function maybeMapChainId(chain: string): string | boolean {
|
2022-07-19 22:31:15 +00:00
|
|
|
if (chain in chainNetworks) {
|
|
|
|
return (chainNetworks as networks)[chain];
|
|
|
|
}
|
2022-07-04 23:17:58 +00:00
|
|
|
|
2022-07-19 22:31:15 +00:00
|
|
|
if (
|
|
|
|
[parseInt(chain, 16).toString(), parseInt(chain, 10).toString()].includes(
|
|
|
|
chain.toLowerCase()
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return chain;
|
|
|
|
}
|
2022-07-04 23:17:58 +00:00
|
|
|
|
2022-07-19 22:31:15 +00:00
|
|
|
return false;
|
2022-07-04 23:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function reverseMapChainId(chainId: string): string | boolean {
|
2022-07-19 22:31:15 +00:00
|
|
|
let vals = Object.values(chainNetworks);
|
|
|
|
if (!vals.includes(chainId)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-04 23:17:58 +00:00
|
|
|
|
2022-07-19 22:31:15 +00:00
|
|
|
return Object.keys(chainNetworks)[vals.indexOf(chainId)];
|
2022-07-04 23:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isIp(ip: string) {
|
2022-07-19 22:31:15 +00:00
|
|
|
return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
|
|
|
|
ip
|
|
|
|
);
|
2022-07-19 22:24:53 +00:00
|
|
|
}
|