UNPKG

@turnkey/eip-1193-provider

Version:

EIP-1193 Provider for Turnkey.

91 lines (87 loc) 3.69 kB
'use strict'; var viem = require('viem'); var constants = require('./constants.js'); // https://docs.metamask.io/wallet/reference/wallet_switchethereumchain/ class UnrecognizedChainError extends viem.ProviderRpcError { constructor(chainId) { const errorMessage = `${constants.PROVIDER_ERROR_MESSAGE.UNRECOGNIZED_CHAIN_ID}${chainId}`; super(new Error(errorMessage), { code: 4902, shortMessage: "Unrecognized chain ID", }); } } class ChainIdMismatchError extends viem.ProviderRpcError { constructor(providerChainId, rpcChainId) { super(new Error(`${constants.PROVIDER_ERROR_MESSAGE.CHAIN_ID_RPC_MISMATCH}${viem.hexToNumber(providerChainId)} RPC Chain ID: ${viem.hexToNumber(rpcChainId)}`), { code: 4905, shortMessage: "Chain ID mismatch", }); } } class BlockExplorerUrlError extends viem.ProviderRpcError { constructor() { super(new Error(constants.PROVIDER_ERROR_MESSAGE.BLOCK_EXPLORER_URL), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: constants.PROVIDER_ERROR_MESSAGE.BLOCK_EXPLORER_URL, }); } } class RpcUrlsRequiredError extends viem.ProviderRpcError { constructor() { super(new Error(constants.PROVIDER_ERROR_MESSAGE.RPC_URLS_REQUIRED), { code: -32602, shortMessage: "rpcUrls field is required and cannot be empty", }); } } class InvalidChainIdFormatError extends viem.ProviderRpcError { constructor(chainId) { super(new Error(constants.PROVIDER_ERROR_MESSAGE.INVALID_CHAIN_ID_HEX + chainId), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: "Invalid chain ID format", }); } } class ChainIdValueExceedsError extends viem.ProviderRpcError { constructor(chainId) { super(new Error(constants.PROVIDER_ERROR_MESSAGE.INVALID_CHAIN_ID_VALUE + chainId), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: "Chain ID value exceeds max safe integer", }); } } class InvalidRpcUrlError extends viem.ProviderRpcError { constructor() { super(new Error(constants.PROVIDER_ERROR_MESSAGE.INVALID_RPC_URL), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: "Invalid rpcUrls", }); } } class NativeCurrencySymbolLengthError extends viem.ProviderRpcError { constructor(symbol) { super(new Error(constants.PROVIDER_ERROR_MESSAGE.NATIVE_CURRENCY_SYMBOL_LENGTH + symbol), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: "Invalid native currency symbol length", }); } } class NativeCurrencySymbolMismatchError extends viem.ProviderRpcError { constructor(symbol) { super(new Error(constants.PROVIDER_ERROR_MESSAGE.NATIVE_CURRENCY_SYMBOL_MISMATCH + symbol), { code: constants.PROVIDER_ERROR_CODE.ADD_ETHEREUM_CHAIN, shortMessage: "Native currency symbol mismatch", }); } } exports.BlockExplorerUrlError = BlockExplorerUrlError; exports.ChainIdMismatchError = ChainIdMismatchError; exports.ChainIdValueExceedsError = ChainIdValueExceedsError; exports.InvalidChainIdFormatError = InvalidChainIdFormatError; exports.InvalidRpcUrlError = InvalidRpcUrlError; exports.NativeCurrencySymbolLengthError = NativeCurrencySymbolLengthError; exports.NativeCurrencySymbolMismatchError = NativeCurrencySymbolMismatchError; exports.RpcUrlsRequiredError = RpcUrlsRequiredError; exports.UnrecognizedChainError = UnrecognizedChainError; //# sourceMappingURL=errors.js.map