UNPKG

@etherspot/remote-signer

Version:

Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler

1,440 lines (1,408 loc) 186 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result; if (kind && result) __defProp(target, key, result); return result; }; // node_modules/abitype/dist/esm/version.js var version; var init_version = __esm({ "node_modules/abitype/dist/esm/version.js"() { version = "1.0.4"; } }); // node_modules/abitype/dist/esm/errors.js var BaseError; var init_errors = __esm({ "node_modules/abitype/dist/esm/errors.js"() { init_version(); BaseError = class _BaseError extends Error { constructor(shortMessage, args = {}) { const details = args.cause instanceof _BaseError ? args.cause.details : args.cause?.message ? args.cause.message : args.details; const docsPath2 = args.cause instanceof _BaseError ? args.cause.docsPath || args.docsPath : args.docsPath; const message = [ shortMessage || "An error occurred.", "", ...args.metaMessages ? [...args.metaMessages, ""] : [], ...docsPath2 ? [`Docs: https://abitype.dev${docsPath2}`] : [], ...details ? [`Details: ${details}`] : [], `Version: abitype@${version}` ].join("\n"); super(message); Object.defineProperty(this, "details", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "docsPath", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "metaMessages", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "shortMessage", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiTypeError" }); if (args.cause) this.cause = args.cause; this.details = details; this.docsPath = docsPath2; this.metaMessages = args.metaMessages; this.shortMessage = shortMessage; } }; } }); // node_modules/abitype/dist/esm/regex.js function execTyped(regex, string) { const match = regex.exec(string); return match?.groups; } var bytesRegex, integerRegex, isTupleRegex; var init_regex = __esm({ "node_modules/abitype/dist/esm/regex.js"() { bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/; integerRegex = /^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/; isTupleRegex = /^\(.+?\).*?$/; } }); // node_modules/abitype/dist/esm/human-readable/formatAbiParameter.js function formatAbiParameter(abiParameter) { let type = abiParameter.type; if (tupleRegex.test(abiParameter.type) && "components" in abiParameter) { type = "("; const length = abiParameter.components.length; for (let i = 0; i < length; i++) { const component = abiParameter.components[i]; type += formatAbiParameter(component); if (i < length - 1) type += ", "; } const result = execTyped(tupleRegex, abiParameter.type); type += `)${result?.array ?? ""}`; return formatAbiParameter({ ...abiParameter, type }); } if ("indexed" in abiParameter && abiParameter.indexed) type = `${type} indexed`; if (abiParameter.name) return `${type} ${abiParameter.name}`; return type; } var tupleRegex; var init_formatAbiParameter = __esm({ "node_modules/abitype/dist/esm/human-readable/formatAbiParameter.js"() { init_regex(); tupleRegex = /^tuple(?<array>(\[(\d*)\])*)$/; } }); // node_modules/abitype/dist/esm/human-readable/formatAbiParameters.js function formatAbiParameters(abiParameters) { let params = ""; const length = abiParameters.length; for (let i = 0; i < length; i++) { const abiParameter = abiParameters[i]; params += formatAbiParameter(abiParameter); if (i !== length - 1) params += ", "; } return params; } var init_formatAbiParameters = __esm({ "node_modules/abitype/dist/esm/human-readable/formatAbiParameters.js"() { init_formatAbiParameter(); } }); // node_modules/abitype/dist/esm/human-readable/formatAbiItem.js function formatAbiItem(abiItem) { if (abiItem.type === "function") return `function ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})${abiItem.stateMutability && abiItem.stateMutability !== "nonpayable" ? ` ${abiItem.stateMutability}` : ""}${abiItem.outputs.length ? ` returns (${formatAbiParameters(abiItem.outputs)})` : ""}`; if (abiItem.type === "event") return `event ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})`; if (abiItem.type === "error") return `error ${abiItem.name}(${formatAbiParameters(abiItem.inputs)})`; if (abiItem.type === "constructor") return `constructor(${formatAbiParameters(abiItem.inputs)})${abiItem.stateMutability === "payable" ? " payable" : ""}`; if (abiItem.type === "fallback") return "fallback()"; return "receive() external payable"; } var init_formatAbiItem = __esm({ "node_modules/abitype/dist/esm/human-readable/formatAbiItem.js"() { init_formatAbiParameters(); } }); // node_modules/abitype/dist/esm/human-readable/runtime/signatures.js function isErrorSignature(signature) { return errorSignatureRegex.test(signature); } function execErrorSignature(signature) { return execTyped(errorSignatureRegex, signature); } function isEventSignature(signature) { return eventSignatureRegex.test(signature); } function execEventSignature(signature) { return execTyped(eventSignatureRegex, signature); } function isFunctionSignature(signature) { return functionSignatureRegex.test(signature); } function execFunctionSignature(signature) { return execTyped(functionSignatureRegex, signature); } function isStructSignature(signature) { return structSignatureRegex.test(signature); } function execStructSignature(signature) { return execTyped(structSignatureRegex, signature); } function isConstructorSignature(signature) { return constructorSignatureRegex.test(signature); } function execConstructorSignature(signature) { return execTyped(constructorSignatureRegex, signature); } function isFallbackSignature(signature) { return fallbackSignatureRegex.test(signature); } function isReceiveSignature(signature) { return receiveSignatureRegex.test(signature); } var errorSignatureRegex, eventSignatureRegex, functionSignatureRegex, structSignatureRegex, constructorSignatureRegex, fallbackSignatureRegex, receiveSignatureRegex, modifiers, eventModifiers, functionModifiers; var init_signatures = __esm({ "node_modules/abitype/dist/esm/human-readable/runtime/signatures.js"() { init_regex(); errorSignatureRegex = /^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/; eventSignatureRegex = /^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/; functionSignatureRegex = /^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/; structSignatureRegex = /^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/; constructorSignatureRegex = /^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/; fallbackSignatureRegex = /^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/; receiveSignatureRegex = /^receive\(\) external payable$/; modifiers = /* @__PURE__ */ new Set([ "memory", "indexed", "storage", "calldata" ]); eventModifiers = /* @__PURE__ */ new Set(["indexed"]); functionModifiers = /* @__PURE__ */ new Set([ "calldata", "memory", "storage" ]); } }); // node_modules/abitype/dist/esm/human-readable/errors/abiItem.js var InvalidAbiItemError, UnknownTypeError, UnknownSolidityTypeError; var init_abiItem = __esm({ "node_modules/abitype/dist/esm/human-readable/errors/abiItem.js"() { init_errors(); InvalidAbiItemError = class extends BaseError { constructor({ signature }) { super("Failed to parse ABI item.", { details: `parseAbiItem(${JSON.stringify(signature, null, 2)})`, docsPath: "/api/human#parseabiitem-1" }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidAbiItemError" }); } }; UnknownTypeError = class extends BaseError { constructor({ type }) { super("Unknown type.", { metaMessages: [ `Type "${type}" is not a valid ABI type. Perhaps you forgot to include a struct signature?` ] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "UnknownTypeError" }); } }; UnknownSolidityTypeError = class extends BaseError { constructor({ type }) { super("Unknown type.", { metaMessages: [`Type "${type}" is not a valid ABI type.`] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "UnknownSolidityTypeError" }); } }; } }); // node_modules/abitype/dist/esm/human-readable/errors/abiParameter.js var InvalidAbiParametersError, InvalidParameterError, SolidityProtectedKeywordError, InvalidModifierError, InvalidFunctionModifierError, InvalidAbiTypeParameterError; var init_abiParameter = __esm({ "node_modules/abitype/dist/esm/human-readable/errors/abiParameter.js"() { init_errors(); InvalidAbiParametersError = class extends BaseError { constructor({ params }) { super("Failed to parse ABI parameters.", { details: `parseAbiParameters(${JSON.stringify(params, null, 2)})`, docsPath: "/api/human#parseabiparameters-1" }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidAbiParametersError" }); } }; InvalidParameterError = class extends BaseError { constructor({ param }) { super("Invalid ABI parameter.", { details: param }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidParameterError" }); } }; SolidityProtectedKeywordError = class extends BaseError { constructor({ param, name }) { super("Invalid ABI parameter.", { details: param, metaMessages: [ `"${name}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html` ] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "SolidityProtectedKeywordError" }); } }; InvalidModifierError = class extends BaseError { constructor({ param, type, modifier }) { super("Invalid ABI parameter.", { details: param, metaMessages: [ `Modifier "${modifier}" not allowed${type ? ` in "${type}" type` : ""}.` ] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidModifierError" }); } }; InvalidFunctionModifierError = class extends BaseError { constructor({ param, type, modifier }) { super("Invalid ABI parameter.", { details: param, metaMessages: [ `Modifier "${modifier}" not allowed${type ? ` in "${type}" type` : ""}.`, `Data location can only be specified for array, struct, or mapping types, but "${modifier}" was given.` ] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidFunctionModifierError" }); } }; InvalidAbiTypeParameterError = class extends BaseError { constructor({ abiParameter }) { super("Invalid ABI parameter.", { details: JSON.stringify(abiParameter, null, 2), metaMessages: ["ABI parameter type is invalid."] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidAbiTypeParameterError" }); } }; } }); // node_modules/abitype/dist/esm/human-readable/errors/signature.js var InvalidSignatureError, UnknownSignatureError, InvalidStructSignatureError; var init_signature = __esm({ "node_modules/abitype/dist/esm/human-readable/errors/signature.js"() { init_errors(); InvalidSignatureError = class extends BaseError { constructor({ signature, type }) { super(`Invalid ${type} signature.`, { details: signature }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidSignatureError" }); } }; UnknownSignatureError = class extends BaseError { constructor({ signature }) { super("Unknown signature.", { details: signature }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "UnknownSignatureError" }); } }; InvalidStructSignatureError = class extends BaseError { constructor({ signature }) { super("Invalid struct signature.", { details: signature, metaMessages: ["No properties exist."] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidStructSignatureError" }); } }; } }); // node_modules/abitype/dist/esm/human-readable/errors/struct.js var CircularReferenceError; var init_struct = __esm({ "node_modules/abitype/dist/esm/human-readable/errors/struct.js"() { init_errors(); CircularReferenceError = class extends BaseError { constructor({ type }) { super("Circular reference detected.", { metaMessages: [`Struct "${type}" is a circular reference.`] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "CircularReferenceError" }); } }; } }); // node_modules/abitype/dist/esm/human-readable/errors/splitParameters.js var InvalidParenthesisError; var init_splitParameters = __esm({ "node_modules/abitype/dist/esm/human-readable/errors/splitParameters.js"() { init_errors(); InvalidParenthesisError = class extends BaseError { constructor({ current, depth }) { super("Unbalanced parentheses.", { metaMessages: [ `"${current.trim()}" has too many ${depth > 0 ? "opening" : "closing"} parentheses.` ], details: `Depth "${depth}"` }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidParenthesisError" }); } }; } }); // node_modules/abitype/dist/esm/human-readable/runtime/cache.js function getParameterCacheKey(param, type) { if (type) return `${type}:${param}`; return param; } var parameterCache; var init_cache = __esm({ "node_modules/abitype/dist/esm/human-readable/runtime/cache.js"() { parameterCache = /* @__PURE__ */ new Map([ // Unnamed ["address", { type: "address" }], ["bool", { type: "bool" }], ["bytes", { type: "bytes" }], ["bytes32", { type: "bytes32" }], ["int", { type: "int256" }], ["int256", { type: "int256" }], ["string", { type: "string" }], ["uint", { type: "uint256" }], ["uint8", { type: "uint8" }], ["uint16", { type: "uint16" }], ["uint24", { type: "uint24" }], ["uint32", { type: "uint32" }], ["uint64", { type: "uint64" }], ["uint96", { type: "uint96" }], ["uint112", { type: "uint112" }], ["uint160", { type: "uint160" }], ["uint192", { type: "uint192" }], ["uint256", { type: "uint256" }], // Named ["address owner", { type: "address", name: "owner" }], ["address to", { type: "address", name: "to" }], ["bool approved", { type: "bool", name: "approved" }], ["bytes _data", { type: "bytes", name: "_data" }], ["bytes data", { type: "bytes", name: "data" }], ["bytes signature", { type: "bytes", name: "signature" }], ["bytes32 hash", { type: "bytes32", name: "hash" }], ["bytes32 r", { type: "bytes32", name: "r" }], ["bytes32 root", { type: "bytes32", name: "root" }], ["bytes32 s", { type: "bytes32", name: "s" }], ["string name", { type: "string", name: "name" }], ["string symbol", { type: "string", name: "symbol" }], ["string tokenURI", { type: "string", name: "tokenURI" }], ["uint tokenId", { type: "uint256", name: "tokenId" }], ["uint8 v", { type: "uint8", name: "v" }], ["uint256 balance", { type: "uint256", name: "balance" }], ["uint256 tokenId", { type: "uint256", name: "tokenId" }], ["uint256 value", { type: "uint256", name: "value" }], // Indexed [ "event:address indexed from", { type: "address", name: "from", indexed: true } ], ["event:address indexed to", { type: "address", name: "to", indexed: true }], [ "event:uint indexed tokenId", { type: "uint256", name: "tokenId", indexed: true } ], [ "event:uint256 indexed tokenId", { type: "uint256", name: "tokenId", indexed: true } ] ]); } }); // node_modules/abitype/dist/esm/human-readable/runtime/utils.js function parseSignature(signature, structs = {}) { if (isFunctionSignature(signature)) { const match = execFunctionSignature(signature); if (!match) throw new InvalidSignatureError({ signature, type: "function" }); const inputParams = splitParameters(match.parameters); const inputs = []; const inputLength = inputParams.length; for (let i = 0; i < inputLength; i++) { inputs.push(parseAbiParameter(inputParams[i], { modifiers: functionModifiers, structs, type: "function" })); } const outputs = []; if (match.returns) { const outputParams = splitParameters(match.returns); const outputLength = outputParams.length; for (let i = 0; i < outputLength; i++) { outputs.push(parseAbiParameter(outputParams[i], { modifiers: functionModifiers, structs, type: "function" })); } } return { name: match.name, type: "function", stateMutability: match.stateMutability ?? "nonpayable", inputs, outputs }; } if (isEventSignature(signature)) { const match = execEventSignature(signature); if (!match) throw new InvalidSignatureError({ signature, type: "event" }); const params = splitParameters(match.parameters); const abiParameters = []; const length = params.length; for (let i = 0; i < length; i++) { abiParameters.push(parseAbiParameter(params[i], { modifiers: eventModifiers, structs, type: "event" })); } return { name: match.name, type: "event", inputs: abiParameters }; } if (isErrorSignature(signature)) { const match = execErrorSignature(signature); if (!match) throw new InvalidSignatureError({ signature, type: "error" }); const params = splitParameters(match.parameters); const abiParameters = []; const length = params.length; for (let i = 0; i < length; i++) { abiParameters.push(parseAbiParameter(params[i], { structs, type: "error" })); } return { name: match.name, type: "error", inputs: abiParameters }; } if (isConstructorSignature(signature)) { const match = execConstructorSignature(signature); if (!match) throw new InvalidSignatureError({ signature, type: "constructor" }); const params = splitParameters(match.parameters); const abiParameters = []; const length = params.length; for (let i = 0; i < length; i++) { abiParameters.push(parseAbiParameter(params[i], { structs, type: "constructor" })); } return { type: "constructor", stateMutability: match.stateMutability ?? "nonpayable", inputs: abiParameters }; } if (isFallbackSignature(signature)) return { type: "fallback" }; if (isReceiveSignature(signature)) return { type: "receive", stateMutability: "payable" }; throw new UnknownSignatureError({ signature }); } function parseAbiParameter(param, options) { const parameterCacheKey = getParameterCacheKey(param, options?.type); if (parameterCache.has(parameterCacheKey)) return parameterCache.get(parameterCacheKey); const isTuple = isTupleRegex.test(param); const match = execTyped(isTuple ? abiParameterWithTupleRegex : abiParameterWithoutTupleRegex, param); if (!match) throw new InvalidParameterError({ param }); if (match.name && isSolidityKeyword(match.name)) throw new SolidityProtectedKeywordError({ param, name: match.name }); const name = match.name ? { name: match.name } : {}; const indexed = match.modifier === "indexed" ? { indexed: true } : {}; const structs = options?.structs ?? {}; let type; let components = {}; if (isTuple) { type = "tuple"; const params = splitParameters(match.type); const components_ = []; const length = params.length; for (let i = 0; i < length; i++) { components_.push(parseAbiParameter(params[i], { structs })); } components = { components: components_ }; } else if (match.type in structs) { type = "tuple"; components = { components: structs[match.type] }; } else if (dynamicIntegerRegex.test(match.type)) { type = `${match.type}256`; } else { type = match.type; if (!(options?.type === "struct") && !isSolidityType(type)) throw new UnknownSolidityTypeError({ type }); } if (match.modifier) { if (!options?.modifiers?.has?.(match.modifier)) throw new InvalidModifierError({ param, type: options?.type, modifier: match.modifier }); if (functionModifiers.has(match.modifier) && !isValidDataLocation(type, !!match.array)) throw new InvalidFunctionModifierError({ param, type: options?.type, modifier: match.modifier }); } const abiParameter = { type: `${type}${match.array ?? ""}`, ...name, ...indexed, ...components }; parameterCache.set(parameterCacheKey, abiParameter); return abiParameter; } function splitParameters(params, result = [], current = "", depth = 0) { const length = params.trim().length; for (let i = 0; i < length; i++) { const char = params[i]; const tail = params.slice(i + 1); switch (char) { case ",": return depth === 0 ? splitParameters(tail, [...result, current.trim()]) : splitParameters(tail, result, `${current}${char}`, depth); case "(": return splitParameters(tail, result, `${current}${char}`, depth + 1); case ")": return splitParameters(tail, result, `${current}${char}`, depth - 1); default: return splitParameters(tail, result, `${current}${char}`, depth); } } if (current === "") return result; if (depth !== 0) throw new InvalidParenthesisError({ current, depth }); result.push(current.trim()); return result; } function isSolidityType(type) { return type === "address" || type === "bool" || type === "function" || type === "string" || bytesRegex.test(type) || integerRegex.test(type); } function isSolidityKeyword(name) { return name === "address" || name === "bool" || name === "function" || name === "string" || name === "tuple" || bytesRegex.test(name) || integerRegex.test(name) || protectedKeywordsRegex.test(name); } function isValidDataLocation(type, isArray) { return isArray || type === "bytes" || type === "string" || type === "tuple"; } var abiParameterWithoutTupleRegex, abiParameterWithTupleRegex, dynamicIntegerRegex, protectedKeywordsRegex; var init_utils = __esm({ "node_modules/abitype/dist/esm/human-readable/runtime/utils.js"() { init_regex(); init_abiItem(); init_abiParameter(); init_signature(); init_splitParameters(); init_cache(); init_signatures(); abiParameterWithoutTupleRegex = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/; abiParameterWithTupleRegex = /^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/; dynamicIntegerRegex = /^u?int$/; protectedKeywordsRegex = /^(?:after|alias|anonymous|apply|auto|byte|calldata|case|catch|constant|copyof|default|defined|error|event|external|false|final|function|immutable|implements|in|indexed|inline|internal|let|mapping|match|memory|mutable|null|of|override|partial|private|promise|public|pure|reference|relocatable|return|returns|sizeof|static|storage|struct|super|supports|switch|this|true|try|typedef|typeof|var|view|virtual)$/; } }); // node_modules/abitype/dist/esm/human-readable/runtime/structs.js function parseStructs(signatures) { const shallowStructs = {}; const signaturesLength = signatures.length; for (let i = 0; i < signaturesLength; i++) { const signature = signatures[i]; if (!isStructSignature(signature)) continue; const match = execStructSignature(signature); if (!match) throw new InvalidSignatureError({ signature, type: "struct" }); const properties = match.properties.split(";"); const components = []; const propertiesLength = properties.length; for (let k = 0; k < propertiesLength; k++) { const property = properties[k]; const trimmed = property.trim(); if (!trimmed) continue; const abiParameter = parseAbiParameter(trimmed, { type: "struct" }); components.push(abiParameter); } if (!components.length) throw new InvalidStructSignatureError({ signature }); shallowStructs[match.name] = components; } const resolvedStructs = {}; const entries = Object.entries(shallowStructs); const entriesLength = entries.length; for (let i = 0; i < entriesLength; i++) { const [name, parameters] = entries[i]; resolvedStructs[name] = resolveStructs(parameters, shallowStructs); } return resolvedStructs; } function resolveStructs(abiParameters, structs, ancestors = /* @__PURE__ */ new Set()) { const components = []; const length = abiParameters.length; for (let i = 0; i < length; i++) { const abiParameter = abiParameters[i]; const isTuple = isTupleRegex.test(abiParameter.type); if (isTuple) components.push(abiParameter); else { const match = execTyped(typeWithoutTupleRegex, abiParameter.type); if (!match?.type) throw new InvalidAbiTypeParameterError({ abiParameter }); const { array, type } = match; if (type in structs) { if (ancestors.has(type)) throw new CircularReferenceError({ type }); components.push({ ...abiParameter, type: `tuple${array ?? ""}`, components: resolveStructs(structs[type] ?? [], structs, /* @__PURE__ */ new Set([...ancestors, type])) }); } else { if (isSolidityType(type)) components.push(abiParameter); else throw new UnknownTypeError({ type }); } } } return components; } var typeWithoutTupleRegex; var init_structs = __esm({ "node_modules/abitype/dist/esm/human-readable/runtime/structs.js"() { init_regex(); init_abiItem(); init_abiParameter(); init_signature(); init_struct(); init_signatures(); init_utils(); typeWithoutTupleRegex = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/; } }); // node_modules/abitype/dist/esm/human-readable/parseAbi.js function parseAbi(signatures) { const structs = parseStructs(signatures); const abi = []; const length = signatures.length; for (let i = 0; i < length; i++) { const signature = signatures[i]; if (isStructSignature(signature)) continue; abi.push(parseSignature(signature, structs)); } return abi; } var init_parseAbi = __esm({ "node_modules/abitype/dist/esm/human-readable/parseAbi.js"() { init_signatures(); init_structs(); init_utils(); } }); // node_modules/abitype/dist/esm/human-readable/parseAbiItem.js function parseAbiItem(signature) { let abiItem; if (typeof signature === "string") abiItem = parseSignature(signature); else { const structs = parseStructs(signature); const length = signature.length; for (let i = 0; i < length; i++) { const signature_ = signature[i]; if (isStructSignature(signature_)) continue; abiItem = parseSignature(signature_, structs); break; } } if (!abiItem) throw new InvalidAbiItemError({ signature }); return abiItem; } var init_parseAbiItem = __esm({ "node_modules/abitype/dist/esm/human-readable/parseAbiItem.js"() { init_abiItem(); init_signatures(); init_structs(); init_utils(); } }); // node_modules/abitype/dist/esm/human-readable/parseAbiParameters.js function parseAbiParameters(params) { const abiParameters = []; if (typeof params === "string") { const parameters = splitParameters(params); const length = parameters.length; for (let i = 0; i < length; i++) { abiParameters.push(parseAbiParameter(parameters[i], { modifiers })); } } else { const structs = parseStructs(params); const length = params.length; for (let i = 0; i < length; i++) { const signature = params[i]; if (isStructSignature(signature)) continue; const parameters = splitParameters(signature); const length2 = parameters.length; for (let k = 0; k < length2; k++) { abiParameters.push(parseAbiParameter(parameters[k], { modifiers, structs })); } } } if (abiParameters.length === 0) throw new InvalidAbiParametersError({ params }); return abiParameters; } var init_parseAbiParameters = __esm({ "node_modules/abitype/dist/esm/human-readable/parseAbiParameters.js"() { init_abiParameter(); init_signatures(); init_structs(); init_utils(); init_utils(); } }); // node_modules/abitype/dist/esm/exports/index.js var init_exports = __esm({ "node_modules/abitype/dist/esm/exports/index.js"() { init_formatAbiItem(); init_parseAbi(); init_parseAbiItem(); init_parseAbiParameters(); } }); // node_modules/viem/_esm/utils/abi/formatAbiItem.js function formatAbiItem2(abiItem, { includeName = false } = {}) { if (abiItem.type !== "function" && abiItem.type !== "event" && abiItem.type !== "error") throw new InvalidDefinitionTypeError(abiItem.type); return `${abiItem.name}(${formatAbiParams(abiItem.inputs, { includeName })})`; } function formatAbiParams(params, { includeName = false } = {}) { if (!params) return ""; return params.map((param) => formatAbiParam(param, { includeName })).join(includeName ? ", " : ","); } function formatAbiParam(param, { includeName }) { if (param.type.startsWith("tuple")) { return `(${formatAbiParams(param.components, { includeName })})${param.type.slice("tuple".length)}`; } return param.type + (includeName && param.name ? ` ${param.name}` : ""); } var init_formatAbiItem2 = __esm({ "node_modules/viem/_esm/utils/abi/formatAbiItem.js"() { init_abi(); } }); // node_modules/viem/_esm/utils/data/isHex.js function isHex(value, { strict = true } = {}) { if (!value) return false; if (typeof value !== "string") return false; return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith("0x"); } var init_isHex = __esm({ "node_modules/viem/_esm/utils/data/isHex.js"() { } }); // node_modules/viem/_esm/utils/data/size.js function size(value) { if (isHex(value, { strict: false })) return Math.ceil((value.length - 2) / 2); return value.length; } var init_size = __esm({ "node_modules/viem/_esm/utils/data/size.js"() { init_isHex(); } }); // node_modules/viem/_esm/errors/version.js var version2; var init_version2 = __esm({ "node_modules/viem/_esm/errors/version.js"() { version2 = "2.16.3"; } }); // node_modules/viem/_esm/errors/utils.js var getVersion; var init_utils2 = __esm({ "node_modules/viem/_esm/errors/utils.js"() { init_version2(); getVersion = () => `viem@${version2}`; } }); // node_modules/viem/_esm/errors/base.js function walk(err, fn) { if (fn?.(err)) return err; if (err && typeof err === "object" && "cause" in err) return walk(err.cause, fn); return fn ? null : err; } var BaseError2; var init_base = __esm({ "node_modules/viem/_esm/errors/base.js"() { init_utils2(); BaseError2 = class _BaseError extends Error { constructor(shortMessage, args = {}) { super(); Object.defineProperty(this, "details", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "docsPath", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "metaMessages", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "shortMessage", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "ViemError" }); Object.defineProperty(this, "version", { enumerable: true, configurable: true, writable: true, value: getVersion() }); const details = args.cause instanceof _BaseError ? args.cause.details : args.cause?.message ? args.cause.message : args.details; const docsPath2 = args.cause instanceof _BaseError ? args.cause.docsPath || args.docsPath : args.docsPath; this.message = [ shortMessage || "An error occurred.", "", ...args.metaMessages ? [...args.metaMessages, ""] : [], ...docsPath2 ? [ `Docs: ${args.docsBaseUrl ?? "https://viem.sh"}${docsPath2}${args.docsSlug ? `#${args.docsSlug}` : ""}` ] : [], ...details ? [`Details: ${details}`] : [], `Version: ${this.version}` ].join("\n"); if (args.cause) this.cause = args.cause; this.details = details; this.docsPath = docsPath2; this.metaMessages = args.metaMessages; this.shortMessage = shortMessage; } walk(fn) { return walk(this, fn); } }; } }); // node_modules/viem/_esm/errors/abi.js var AbiEncodingArrayLengthMismatchError, AbiEncodingBytesSizeMismatchError, AbiEncodingLengthMismatchError, AbiFunctionNotFoundError, AbiItemAmbiguityError, InvalidAbiEncodingTypeError, InvalidArrayError, InvalidDefinitionTypeError; var init_abi = __esm({ "node_modules/viem/_esm/errors/abi.js"() { init_formatAbiItem2(); init_size(); init_base(); AbiEncodingArrayLengthMismatchError = class extends BaseError2 { constructor({ expectedLength, givenLength, type }) { super([ `ABI encoding array length mismatch for type ${type}.`, `Expected length: ${expectedLength}`, `Given length: ${givenLength}` ].join("\n")); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiEncodingArrayLengthMismatchError" }); } }; AbiEncodingBytesSizeMismatchError = class extends BaseError2 { constructor({ expectedSize, value }) { super(`Size of bytes "${value}" (bytes${size(value)}) does not match expected size (bytes${expectedSize}).`); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiEncodingBytesSizeMismatchError" }); } }; AbiEncodingLengthMismatchError = class extends BaseError2 { constructor({ expectedLength, givenLength }) { super([ "ABI encoding params/values length mismatch.", `Expected length (params): ${expectedLength}`, `Given length (values): ${givenLength}` ].join("\n")); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiEncodingLengthMismatchError" }); } }; AbiFunctionNotFoundError = class extends BaseError2 { constructor(functionName, { docsPath: docsPath2 } = {}) { super([ `Function ${functionName ? `"${functionName}" ` : ""}not found on ABI.`, "Make sure you are using the correct ABI and that the function exists on it." ].join("\n"), { docsPath: docsPath2 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiFunctionNotFoundError" }); } }; AbiItemAmbiguityError = class extends BaseError2 { constructor(x, y) { super("Found ambiguous types in overloaded ABI items.", { metaMessages: [ `\`${x.type}\` in \`${formatAbiItem2(x.abiItem)}\`, and`, `\`${y.type}\` in \`${formatAbiItem2(y.abiItem)}\``, "", "These types encode differently and cannot be distinguished at runtime.", "Remove one of the ambiguous items in the ABI." ] }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "AbiItemAmbiguityError" }); } }; InvalidAbiEncodingTypeError = class extends BaseError2 { constructor(type, { docsPath: docsPath2 }) { super([ `Type "${type}" is not a valid encoding type.`, "Please provide a valid ABI type." ].join("\n"), { docsPath: docsPath2 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidAbiEncodingType" }); } }; InvalidArrayError = class extends BaseError2 { constructor(value) { super([`Value "${value}" is not a valid array.`].join("\n")); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidArrayError" }); } }; InvalidDefinitionTypeError = class extends BaseError2 { constructor(type) { super([ `"${type}" is not a valid definition type.`, 'Valid types: "function", "event", "error"' ].join("\n")); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "InvalidDefinitionTypeError" }); } }; } }); // node_modules/viem/_esm/errors/data.js var SliceOffsetOutOfBoundsError, SizeExceedsPaddingSizeError; var init_data = __esm({ "node_modules/viem/_esm/errors/data.js"() { init_base(); SliceOffsetOutOfBoundsError = class extends BaseError2 { constructor({ offset, position, size: size2 }) { super(`Slice ${position === "start" ? "starting" : "ending"} at offset "${offset}" is out-of-bounds (size: ${size2}).`); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "SliceOffsetOutOfBoundsError" }); } }; SizeExceedsPaddingSizeError = class extends BaseError2 { constructor({ size: size2, targetSize, type }) { super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size2}) exceeds padding size (${targetSize}).`); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "SizeExceedsPaddingSizeError" }); } }; } }); // node_modules/viem/_esm/utils/data/pad.js function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) { if (typeof hexOrBytes === "string") return padHex(hexOrBytes, { dir, size: size2 }); return padBytes(hexOrBytes, { dir, size: size2 }); } function padHex(hex_, { dir, size: size2 = 32 } = {}) { if (size2 === null) return hex_; const hex = hex_.replace("0x", ""); if (hex.length > size2 * 2) throw new SizeExceedsPaddingSizeError({ size: Math.ceil(hex.length / 2), targetSize: size2, type: "hex" }); return `0x${hex[dir === "right" ? "padEnd" : "padStart"](size2 * 2, "0")}`; } function padBytes(bytes2, { dir, size: size2 = 32 } = {}) { if (size2 === null) return bytes2; if (bytes2.length > size2) throw new SizeExceedsPaddingSizeError({ size: bytes2.length, targetSize: size2, type: "bytes" }); const paddedBytes = new Uint8Array(size2); for (let i = 0; i < size2; i++) { const padEnd = dir === "right"; paddedBytes[padEnd ? i : size2 - i - 1] = bytes2[padEnd ? i : bytes2.length - i - 1]; } return paddedBytes; } var init_pad = __esm({ "node_modules/viem/_esm/utils/data/pad.js"() { init_data(); } }); // node_modules/viem/_esm/errors/encoding.js var IntegerOutOfRangeError, SizeOverflowError; var init_encoding = __esm({ "node_modules/viem/_esm/errors/encoding.js"() { init_base(); IntegerOutOfRangeError = class extends BaseError2 { constructor({ max, min, signed, size: size2, value }) { super(`Number "${value}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "IntegerOutOfRangeError" }); } }; SizeOverflowError = class extends BaseError2 { constructor({ givenSize, maxSize }) { super(`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: "SizeOverflowError" }); } }; } }); // node_modules/viem/_esm/utils/encoding/fromHex.js function assertSize(hexOrBytes, { size: size2 }) { if (size(hexOrBytes) > size2) throw new SizeOverflowError({ givenSize: size(hexOrBytes), maxSize: size2 }); } var init_fromHex = __esm({ "node_modules/viem/_esm/utils/encoding/fromHex.js"() { init_encoding(); init_size(); } }); // node_modules/viem/_esm/utils/encoding/toHex.js function toHex(value, opts = {}) { if (typeof value === "number" || typeof value === "bigint") return numberToHex(value, opts); if (typeof value === "string") { return stringToHex(value, opts); } if (typeof value === "boolean") return boolToHex(value, opts); return bytesToHex(value, opts); } function boolToHex(value, opts = {}) { const hex = `0x${Number(value)}`; if (typeof opts.size === "number") { assertSize(hex, { size: opts.size }); return pad(hex, { size: opts.size }); } return hex; } function bytesToHex(value, opts = {}) { let string = ""; for (let i = 0; i < value.length; i++) { string += hexes[value[i]]; } const hex = `0x${string}`; if (typeof opts.size === "number") { assertSize(hex, { size: opts.size }); return pad(hex, { dir: "right", size: opts.size }); } return hex; } function numberToHex(value_, opts = {}) { const { signed, size: size2 } = opts; const value = BigInt(value_); let maxValue; if (size2) { if (signed) maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n; else maxValue = 2n ** (BigInt(size2) * 8n) - 1n; } else if (typeof value_ === "number") { maxValue = BigInt(Number.MAX_SAFE_INTEGER); } const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0; if (maxValue && value > maxValue || value < minValue) { const suffix = typeof value_ === "bigint" ? "n" : ""; throw new IntegerOutOfRangeError({ max: maxValue ? `${maxValue}${suffix}` : void 0, min: `${minValue}${suffix}`, signed, size: size2, value: `${value_}${suffix}` }); } const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`; if (size2) return pad(hex, { size: size2 }); return hex; } function stringToHex(value_, opts = {}) { const value = encoder.encode(value_); return bytesToHex(value, opts); } var hexes, encoder; var init_toHex = __esm({ "node_modules/viem/_esm/utils/encoding/toHex.js"() { init_encoding(); init_pad(); init_fromHex(); hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0")); encoder = /* @__PURE__ */ new TextEncoder(); } }); // node_modules/viem/_esm/utils/encoding/toBytes.js function toBytes(value, opts = {}) { if (typeof value === "number" || typeof value === "bigint") return numberToBytes(value, opts); if (typeof value === "boolean") return boolToBytes(value, opts); if (isHex(value)) return hexToBytes(value, opts); return stringToBytes(value, opts); } function boolToBytes(value, opts = {}) { const bytes2 = new Uint8Array(1); bytes2[0] = Number(value); if (typeof opts.size === "number") { assertSize(bytes2, { size: opts.size }); return pad(bytes2, { size: opts.size }); } return bytes2; } function charCodeToBase16(char) { if (char >= charCodeMap.zero && char <= charCodeMap.nine) return char - charCodeMap.zero; if (char >= charCodeMap.A && char <= charCodeMap.F) return char - (charCodeMap.A - 10); if (char >= charCodeMap.a && char <= charCodeMap.f) return char - (charCodeMap.a - 10); return void 0; } function hexToBytes(hex_, opts = {}) { let hex = hex_; if (opts.size) { assertSize(hex, { size: opts.size }); hex = pad(hex, { dir: "right", size: opts.size }); } let hexString = hex.slice(2); if (hexString.length % 2) hexString = `0${hexString}`; const length = hexString.length / 2; const bytes2 = new Uint8Array(length); for (let index = 0, j = 0; index < length; index++) { const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++)); const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++)); if (nibbleLeft === void 0 || nibbleRight === void 0) { throw new BaseError2(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`); } bytes2[index] = nibb