UNPKG

@web3-wallet/core

Version:
37 lines (36 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toHexChainId = exports.parseChainId = exports.isValidChainId = exports.validateChainId = exports.MAX_SAFE_CHAIN_ID = void 0; /** * The largest possible chain ID we can handle. * Explanation: https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553 */ exports.MAX_SAFE_CHAIN_ID = 4503599627370476; const validateChainId = (chainId) => { if (!Number.isInteger(chainId) || chainId <= 0 || chainId > exports.MAX_SAFE_CHAIN_ID) { throw new Error(`Invalid chainId ${chainId}`); } }; exports.validateChainId = validateChainId; const isValidChainId = (chainId) => { try { (0, exports.validateChainId)(chainId); return true; } catch (_) { return false; } }; exports.isValidChainId = isValidChainId; const parseChainId = (chainId) => { return typeof chainId === 'number' ? chainId : Number.parseInt(`${chainId}`, `${chainId}`.startsWith('0x') ? 16 : 10); }; exports.parseChainId = parseChainId; const toHexChainId = (chainId) => { return `0x${chainId.toString(16)}`; }; exports.toHexChainId = toHexChainId;