'use strict'; var zod = require('abitype/zod'); var zod$1 = require('zod'); // src/common/createError.js var createError = (name, message, input) => ({ name, _tag: name, message: `${name}: ${message}`, ...input === void 0 ? {} : { input } }); var zAbi = zod.Abi.describe("A valid ABI"); var zAddress = zod.Address.describe("A valid ethereum address"); var zBlock = zod$1.z.strictObject({ number: zod$1.z.bigint().min(0n).describe("The block number (height) in the blockchain."), coinbase: zAddress.describe("The address of the miner or validator who mined or validated the block."), timestamp: zod$1.z.bigint().min(0n).describe("The timestamp at which the block was mined or validated."), difficulty: zod$1.z.bigint().min(0n).describe("The difficulty level of the block (relevant in PoW chains)."), gasLimit: zod$1.z.bigint().min(0n).describe( "The gas limit for the block, i.e., the maximum amount of gas that can be used by the transactions in the block." ), baseFeePerGas: zod$1.z.bigint().min(0n).optional().describe( "(Optional) The base fee per gas in the block, introduced in EIP-1559 for dynamic transaction fee calculation." ), blobGasPrice: zod$1.z.bigint().min(0n).optional().describe("The gas price for the block; may be undefined in blocks after EIP-1559.") }).describe("A valid block header"); var hexRegex = /^0x[0-9a-fA-F]*$/; var zHex = zod$1.z.string().transform((value, ctx) => { if (!hexRegex.test(value)) { ctx.addIssue({ code: zod$1.z.ZodIssueCode.custom, message: "value must be a hex string" }); } return ( /** @type {import('@tevm/utils').Hex}*/ value ); }).describe("A hex string"); var strictHex = /^0x([1-9a-f]+[0-9a-f]*|0)$/; var zStrictHex = zod$1.z.string().transform((value, ctx) => { if (!strictHex.test(value)) { ctx.addIssue({ code: zod$1.z.ZodIssueCode.custom, message: "value must be a hex string" }); } return ( /** @type {import('@tevm/utils').Hex}*/ value ); }); // src/common/zBytecode.js var isValidEthereumBytecode = (bytecode) => { const rawBytecode = bytecode.slice(2); if (rawBytecode.length === 0 || rawBytecode.length % 2 !== 0) { return false; } return true; }; var zBytecode = zHex.refine(isValidEthereumBytecode, { message: "InvalidLength" }).describe("Valid bytecode"); var zJsonRpcRequest = zod$1.z.object({ jsonrpc: zod$1.z.literal("2.0"), id: zod$1.z.union([zod$1.z.string(), zod$1.z.number(), zod$1.z.null()]).optional(), method: zod$1.z.string(), // Could be strictor here // The actual type is any object any array of json serializable values params: zod$1.z.union([zod$1.z.record(zod$1.z.any()), zod$1.z.array(zod$1.z.any())]).optional() }).strict().describe("A valid JsonRpcRequest"); var storageRootRegex = /^0x[0-9a-fA-F]{64}$/; var zStorageRoot = zod$1.z.string().transform((value, ctx) => { if (!storageRootRegex.test(value)) { ctx.addIssue({ code: zod$1.z.ZodIssueCode.custom, message: "Value must be a 32-byte hex string (64 hex characters with a 0x prefix)" }); } return value; }).describe("Valid ethereum storage root"); var zBlockParam = zod$1.z.union([ zod$1.z.literal("latest"), zod$1.z.literal("earliest"), zod$1.z.literal("pending"), zod$1.z.literal("safe"), zod$1.z.literal("finalized"), zod$1.z.bigint(), zHex ]); // src/common/zNetworkConfig.js var zNetworkConfig = zod$1.z.object({ url: zod$1.z.string().url().describe("The URL of the network to connect to"), blockTag: zBlockParam.optional().describe("The block tag to use for the connection. Uses latest if not specified") }).describe("The configuration for a network connection to another JSON-RPC provider"); var zBlockOverrideSet = zod$1.z.strictObject({ number: zod$1.z.bigint().gte(0n).optional(), time: zod$1.z.bigint().gte(0n).optional(), gasLimit: zod$1.z.bigint().gte(0n).optional(), coinbase: zAddress.optional(), baseFee: zod$1.z.bigint().gte(0n).optional(), blobBaseFee: zod$1.z.bigint().gte(0n).optional() }); var zStateOverrideSet = zod$1.z.record( zAddress, zod$1.z.strictObject({ balance: zod$1.z.bigint().gte(0n).optional(), nonce: zod$1.z.bigint().gte(0n).optional(), code: zHex.optional(), state: zod$1.z.record(zHex, zHex).optional(), stateDiff: zod$1.z.record(zHex, zHex).optional() }) ); var zBaseParams = zod$1.z.object({ throwOnFail: zod$1.z.boolean().optional().describe( "If true the action handler will throw errors rather than returning errors an the `errors` property. Defaults to true." ) }).describe("Properties shared across actions"); // src/params/zGetAccountParams.js var zGetAccountParams = zBaseParams.extend({ address: zAddress, returnStorage: zod$1.z.boolean().optional().describe("If true will return storage. Defaults to false. This can be expensive") }).describe("Params to create an account or contract"); var zSetAccountParams = zBaseParams.extend({ address: zAddress.describe("The ethereum address of the account"), balance: zod$1.z.bigint().nonnegative().optional().describe("The balance to give the account"), nonce: zod$1.z.bigint().nonnegative().optional().describe("The nonce to give the account"), deployedBytecode: zBytecode.optional().describe("The contract bytecode to set at the account address as a >0 byte hex string"), storageRoot: zStorageRoot.optional().describe("The storage root to set at the account address as a 32 byte hex strign"), state: zod$1.z.record(zHex, zHex).optional().describe("Overrides entire state with provided state"), stateDiff: zod$1.z.record(zHex, zHex).optional().describe("Patches the state with the provided state") }).refine( (data) => { if (data.state && data.stateDiff) { return false; } return true; }, { message: "Cannot have both state and stateDiff" } ).describe("Params to create an account or contract"); var zBaseCallParams = zBaseParams.extend({ createTrace: zod$1.z.boolean().optional().describe("If true, the call will also return a `trace` on the trace property"), createAccessList: zod$1.z.boolean().optional().describe("If true, the call will also return a `accessList` on the accessList property"), createTransaction: zod$1.z.union([ zod$1.z.boolean().optional().describe("If true, this call is a create transaction. Defaults to false."), zod$1.z.literal("on-success"), zod$1.z.literal("always"), zod$1.z.literal("never") ]), skipBalance: zod$1.z.boolean().optional().describe("Set caller to msg.value of less than msg.value Defaults to false."), gasRefund: zod$1.z.bigint().optional().describe("Refund counter. Defaults to 0"), blockTag: zBlockParam.optional().describe('The block tag as a block number, block hash or one of "latest", "earliest", "pending" or "safe"'), gasPrice: zod$1.z.bigint().optional().describe("The gas price for the call. Defaults to `0`"), origin: zAddress.optional().describe("The address where the call originated from. Defaults to the zero address."), caller: zAddress.optional().describe("The address that ran this code (`msg.sender`). Defaults to the zero address."), gas: zod$1.z.bigint().optional().describe("The gas limit for the call. Defaults to `16777215` (`0xffffff`)"), value: zod$1.z.bigint().optional().describe("The value in ether that is being sent to `opts.address`. Defaults to `0`"), depth: zod$1.z.number().optional().describe("The call depth. Defaults to `0`"), selfdestruct: zod$1.z.set(zAddress).optional().describe("Addresses to selfdestruct. Defaults to the empty set."), to: zAddress.optional().describe( "The address of the account that is executing this code (`address(this)`). Defaults to the zero address." ), blobVersionedHashes: zod$1.z.array(zHex).optional().describe("Versioned hashes for each blob in a blob transaction"), stateOverrideSet: zStateOverrideSet.optional().describe("State override set for the call"), blockOverrideSet: zBlockOverrideSet.optional().describe("Block override set for the call") }).describe("Properties shared across call-like actions"); // src/params/zCallParams.js var zCallParams = zBaseCallParams.extend({ data: zHex.optional().describe("the data to send"), salt: zHex.optional().describe("the salt to use for the call"), deployedBytecode: zHex.optional().describe("the deployed bytecode to use for the call") }).refine( (params) => { if (params.createTransaction && params.stateOverrideSet) { return false; } if (params.createTransaction && params.blockOverrideSet) { return false; } return true; }, { message: "Cannot have stateOverrideSet or blockOverrideSet for createTransaction" } ).describe("Params to make a call to the tevm EVM"); var zContractParams = zBaseCallParams.extend({ to: zAddress.describe("The required address of the contract to call"), abi: zAbi.describe("The abi of the contract"), args: zod$1.z.array(zod$1.z.any()).optional().describe("The arguments to pass to the function"), functionName: zod$1.z.string().describe("The name of the function to call") }).refine( (params) => { if (params.createTransaction && params.stateOverrideSet) { return false; } if (params.createTransaction && params.blockOverrideSet) { return false; } return true; }, { message: "Cannot have stateOverrideSet or blockOverrideSet for createTransaction" } ).describe("Params to execute a contract method in the tevm EVM"); var zScriptParams = zBaseCallParams.extend({ abi: zAbi.describe("The abi of the contract"), args: zod$1.z.array(zod$1.z.any()).optional().describe("The arguments to pass to the function"), functionName: zod$1.z.string().describe("The name of the function to call"), deployedBytecode: zHex.describe("The deployed bytecode of the contract") }).refine( (params) => { if (params.createTransaction && params.stateOverrideSet) { return false; } if (params.createTransaction && params.blockOverrideSet) { return false; } return true; }, { message: "Cannot have stateOverrideSet or blockOverrideSet for createTransaction" } ).describe("Params to run a script or contract"); var zMineParams = zBaseParams.extend({ blockCount: zod$1.z.number().int().gte(0).optional(), interval: zod$1.z.number().int().gte(0).optional() }); // src/validators/validateGetAccountParams.js var validateGetAccountParams = (action) => { const errors = []; const parsedParams = zGetAccountParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); formattedErrors._errors.forEach((error) => { errors.push(createError("InvalidRequestError", error, String(action))); }); } return errors; }; // src/validators/validateSetAccountParams.js var validateSetAccountParams = (action) => { const errors = []; const parsedParams = zSetAccountParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); formattedErrors._errors.forEach((error) => { errors.push(createError("InvalidRequestError", error, String(action))); }); if (formattedErrors.address) { formattedErrors.address._errors.forEach((error) => { errors.push(createError("InvalidAddressError", error, String(action.address))); }); } if (formattedErrors.nonce) { formattedErrors.nonce._errors.forEach((error) => { errors.push(createError("InvalidNonceError", error, String(action.nonce))); }); } if (formattedErrors.balance) { formattedErrors.balance._errors.forEach((error) => { errors.push(createError("InvalidBalanceError", error, String(action.balance))); }); } if (formattedErrors.deployedBytecode) { formattedErrors.deployedBytecode._errors.forEach((error) => { errors.push(createError("InvalidBytecodeError", error, String(action.deployedBytecode))); }); } if (formattedErrors.storageRoot) { formattedErrors.storageRoot._errors.forEach((error) => { errors.push(createError("InvalidStorageRootError", error, String(action.storageRoot))); }); } } return errors; }; // src/validators/validateBaseCallParams.js var validateBaseCallParams = (action) => { const errors = []; const parsedParams = zBaseCallParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); formattedErrors._errors.forEach((error) => { errors.push(createError("InvalidRequestError", error, JSON.stringify(action))); }); if (formattedErrors.skipBalance) { formattedErrors.skipBalance._errors.forEach((error) => { errors.push(createError("InvalidSkipBalanceError", error, String(action.skipBalance))); }); } if (formattedErrors.gasRefund) { formattedErrors.gasRefund._errors.forEach((error) => { errors.push(createError("InvalidGasRefundError", error, String(action.gasRefund))); }); } if (formattedErrors.blockTag) { formattedErrors.blockTag._errors.forEach((error) => { errors.push(createError("InvalidBlockError", error, action.blockTag?.toString() ?? "undefined")); }); } if (formattedErrors.gas) { formattedErrors.gas._errors.forEach((error) => { errors.push(createError("InvalidGasPriceError", error, String(action.gas))); }); } if (formattedErrors.origin) { formattedErrors.origin._errors.forEach((error) => { errors.push(createError("InvalidOriginError", error, String(action.origin))); }); } if (formattedErrors.caller) { formattedErrors.caller._errors.forEach((error) => { errors.push(createError("InvalidCallerError", error, String(action.caller))); }); } if (formattedErrors.gas) { formattedErrors.gas._errors.forEach((error) => { errors.push(createError("InvalidGasLimitError", error, String(action.gas))); }); } if (formattedErrors.value) { formattedErrors.value._errors.forEach((error) => { errors.push(createError("InvalidValueError", error, String(action.value))); }); } if (formattedErrors.depth) { formattedErrors.depth._errors.forEach((error) => { errors.push(createError("InvalidDepthError", error, String(action.depth))); }); } if (formattedErrors.selfdestruct) { formattedErrors.selfdestruct._errors.forEach((error) => { errors.push(createError("InvalidSelfdestructError", error, JSON.stringify(action.selfdestruct))); }); } if (formattedErrors.to) { formattedErrors.to._errors.forEach((error) => { errors.push(createError("InvalidToError", error, String(action.to))); }); } if (formattedErrors.blobVersionedHashes) { formattedErrors.blobVersionedHashes._errors.forEach((error) => { errors.push(createError("InvalidBlobVersionedHashesError", error, JSON.stringify(action.blobVersionedHashes))); }); } } return errors; }; // src/validators/validateCallParams.js var validateCallParams = (action) => { const errors = validateBaseCallParams(action); const parsedParams = zCallParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); if (formattedErrors.salt) { formattedErrors.salt._errors.forEach((error) => { errors.push(createError("InvalidSaltError", error, String(action.salt))); }); } if (formattedErrors.data) { formattedErrors.data._errors.forEach((error) => { errors.push(createError("InvalidDataError", error, String(action.data))); }); } if (formattedErrors.deployedBytecode) { formattedErrors.deployedBytecode._errors.forEach((error) => { errors.push(createError("InvalidDeployedBytecodeError", error, String(action.deployedBytecode))); }); } } return errors; }; // src/validators/validateContractParams.js var validateContractParams = (action) => { const errors = validateBaseCallParams(action); const parsedParams = zContractParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); if (formattedErrors.abi) { formattedErrors.abi._errors.forEach((error) => { errors.push(createError("InvalidAbiError", error, JSON.stringify(action.abi))); }); } if (formattedErrors.args) { formattedErrors.args._errors.forEach((error) => { errors.push(createError("InvalidArgsError", error)); }); } if (formattedErrors.functionName) { formattedErrors.functionName._errors.forEach((error) => { errors.push(createError("InvalidFunctionNameError", error, String(action.functionName))); }); } if (formattedErrors.to) { formattedErrors.to._errors.forEach((error) => { errors.push(createError("InvalidAddressError", error, action.to)); }); } } return errors; }; // src/validators/validateScriptParams.js var validateScriptParams = (action) => { const errors = validateBaseCallParams(action); const parsedParams = zScriptParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); if (formattedErrors.deployedBytecode) { formattedErrors.deployedBytecode._errors.forEach((error) => { errors.push(createError("InvalidDeployedBytecodeError", error, String(action.deployedBytecode))); }); } if (formattedErrors.abi) { formattedErrors.abi._errors.forEach((error) => { errors.push(createError("InvalidAbiError", error, JSON.stringify(action.abi))); }); } if (formattedErrors.args) { formattedErrors.args._errors.forEach((error) => { errors.push(createError("InvalidArgsError", error)); }); } if (formattedErrors.functionName) { formattedErrors.functionName._errors.forEach((error) => { errors.push(createError("InvalidFunctionNameError", error, String(action.functionName))); }); } } return errors; }; var AccountStorage = zBaseParams.extend({ nonce: zod$1.z.bigint().describe("The nonce of the account"), balance: zod$1.z.bigint().describe("The balance of the account"), storageRoot: zHex.describe("The storage root of the account"), codeHash: zHex.describe("The code hash of the account"), storage: zod$1.z.optional(zod$1.z.record(zHex)).describe("The storage of the account") }); var zLoadStateParams = zod$1.z.object({ state: zod$1.z.record(AccountStorage) }).describe("Properties shared across the load state"); // src/validators/validateLoadStateParams.js var validateLoadStateParams = (action) => { const errors = []; const parsedParams = zLoadStateParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); if (formattedErrors._errors) { formattedErrors._errors.forEach((error) => { errors.push(createError("InvalidRequestError", error, JSON.stringify(action))); }); } } return errors; }; // src/validators/validateMineParams.js var validateMineParams = (action) => { const errors = []; const parsedParams = zMineParams.safeParse(action); if (parsedParams.success === false) { const formattedErrors = parsedParams.error.format(); formattedErrors._errors.forEach((error) => { errors.push(createError("InvalidRequestError", error, String(action))); }); if (formattedErrors.blockCount) { formattedErrors.blockCount._errors.forEach((error) => { errors.push(createError("InvalidAddressError", error, String(action.blockCount))); }); } if (formattedErrors.interval) { formattedErrors.interval._errors.forEach((error) => { errors.push(createError("InvalidNonceError", error, String(action.interval))); }); } if (formattedErrors.throwOnFail) { formattedErrors.throwOnFail._errors.forEach((error) => { errors.push(createError("InvalidBalanceError", error, String(action.throwOnFail))); }); } } return errors; }; exports.validateBaseCallParams = validateBaseCallParams; exports.validateCallParams = validateCallParams; exports.validateContractParams = validateContractParams; exports.validateGetAccountParams = validateGetAccountParams; exports.validateLoadStateParams = validateLoadStateParams; exports.validateMineParams = validateMineParams; exports.validateScriptParams = validateScriptParams; exports.validateSetAccountParams = validateSetAccountParams; exports.zAbi = zAbi; exports.zAddress = zAddress; exports.zBaseCallParams = zBaseCallParams; exports.zBlock = zBlock; exports.zBlockParam = zBlockParam; exports.zBytecode = zBytecode; exports.zCallParams = zCallParams; exports.zContractParams = zContractParams; exports.zGetAccountParams = zGetAccountParams; exports.zHex = zHex; exports.zJsonRpcRequest = zJsonRpcRequest; exports.zMineParams = zMineParams; exports.zNetworkConfig = zNetworkConfig; exports.zScriptParams = zScriptParams; exports.zSetAccountParams = zSetAccountParams; exports.zStorageRoot = zStorageRoot; exports.zStrictHex = zStrictHex; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.cjs.map