UNPKG

zksync-cli

Version:

CLI tool that simplifies the process of developing applications and interacting with the ZKsync network

56 lines 1.44 kB
import { Wallet, getAddress } from "ethers"; import { ETH_TOKEN } from "./constants.js"; import { useDecimals } from "./formatters.js"; export const isDecimalAmount = (amount, decimals = ETH_TOKEN.decimals) => { try { const { decimalToBigNumber } = useDecimals(decimals); const result = decimalToBigNumber(amount); if (typeof result === "bigint") { return true; } } catch { // ignore since we return error message below } return "Incorrect amount"; }; export const isAddress = (address) => { try { return Boolean(getAddress(address)); } catch { return "Incorrect address"; } }; export const isTransactionHash = (s) => { const valid = /^0x([A-Fa-f0-9]{64})$/.test(s); if (!valid) { return "Incorrect transaction hash"; } return true; }; export const isPrivateKey = (hash) => { try { if (new Wallet(hash).address) { return true; } } catch { // ignore since we return error message below } return "Incorrect private key"; }; export const isUrl = (url) => { if (!url.startsWith("http")) { return "URL must start with http:// or https://"; } try { new URL(url); return true; } catch { // ignore since we return error message below } return "Invalid URL"; }; //# sourceMappingURL=validators.js.map