UNPKG

@base-org/account

Version:
3 lines 549 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).base={})}(this,function(e){"use strict";const t="https://rpc.wallet.coinbase.com",n="@base-org/account",r="2.0.1";function a(e,t){let n;try{n=e()}catch(e){return}const r={getItem:e=>{var t;const r=e=>null===e?null:JSON.parse(e,void 0),a=null!=(t=n.getItem(e))?t:null;return a instanceof Promise?a.then(r):r(a)},setItem:(e,t)=>n.setItem(e,JSON.stringify(t,void 0)),removeItem:e=>n.removeItem(e)};return r}const s=e=>t=>{try{const n=e(t);return n instanceof Promise?n:{then:e=>s(e)(n),catch(e){return this}}}catch(e){return{then(e){return this},catch:t=>s(t)(e)}}},i=(e,t)=>(n,r,i)=>{let o={storage:a(()=>localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...t},c=!1;const u=new Set,l=new Set;let d=o.storage;if(!d)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),n(...e)},r,i);const p=()=>{const e=o.partialize({...r()});return d.setItem(o.name,{state:e,version:o.version})},f=i.setState;i.setState=(e,t)=>{f(e,t),p()};const m=e((...e)=>{n(...e),p()},r,i);let h;i.getInitialState=()=>m;const y=()=>{var e,t;if(!d)return;c=!1,u.forEach(e=>{var t;return e(null!=(t=r())?t:m)});const a=(null==(t=o.onRehydrateStorage)?void 0:t.call(o,null!=(e=r())?e:m))||void 0;return s(d.getItem.bind(d))(o.name).then(e=>{if(e){if("number"!=typeof e.version||e.version===o.version)return[!1,e.state];if(o.migrate){const t=o.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}return[!1,void 0]}).then(e=>{var t;const[a,s]=e;if(h=o.merge(s,null!=(t=r())?t:m),n(h,!0),a)return p()}).then(()=>{null==a||a(h,void 0),h=r(),c=!0,l.forEach(e=>e(h))}).catch(e=>{null==a||a(void 0,e)})};return i.persist={setOptions:e=>{o={...o,...e},e.storage&&(d=e.storage)},clearStorage:()=>{null==d||d.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>y(),hasHydrated:()=>c,onHydrate:e=>(u.add(e),()=>{u.delete(e)}),onFinishHydration:e=>(l.add(e),()=>{l.delete(e)})},o.skipHydration||y(),h||m},o=e=>{let t;const n=new Set,r=(e,r)=>{const a="function"==typeof e?e(t):e;if(!Object.is(a,t)){const e=t;t=(null!=r?r:"object"!=typeof a||null===a)?a:Object.assign({},t,a),n.forEach(n=>n(t,e))}},a=()=>t,s={setState:r,getState:a,getInitialState:()=>i,subscribe:e=>(n.add(e),()=>n.delete(e))},i=t=e(r,a,s);return s},c=e=>e?o(e):o,u=c(i((...e)=>Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},{chains:[]}),{keys:{}}),{account:{}}),{subAccount:void 0}),{spendPermissions:[]}),(()=>({config:{version:r}}))(...e)),{subAccountConfig:{}}),{name:"base-acc-sdk.store",storage:a(()=>localStorage),partialize:e=>({chains:e.chains,keys:e.keys,account:e.account,subAccount:e.subAccount,spendPermissions:e.spendPermissions,config:e.config})})),l={get:()=>u.getState().config,set:e=>{u.setState(t=>({config:Object.assign(Object.assign({},t.config),e)}))}},d={subAccounts:{get:()=>u.getState().subAccount,set:e=>{u.setState(t=>({subAccount:t.subAccount?Object.assign(Object.assign({},t.subAccount),e):Object.assign({address:e.address},e)}))},clear:()=>{u.setState({subAccount:void 0})}},subAccountsConfig:{get:()=>u.getState().subAccountConfig,set:e=>{u.setState(t=>({subAccountConfig:Object.assign(Object.assign({},t.subAccountConfig),e)}))},clear:()=>{u.setState({subAccountConfig:{}})}},spendPermissions:{get:()=>u.getState().spendPermissions,set:e=>{u.setState({spendPermissions:e})},clear:()=>{u.setState({spendPermissions:[]})}},account:{get:()=>u.getState().account,set:e=>{u.setState(t=>({account:Object.assign(Object.assign({},t.account),e)}))},clear:()=>{u.setState({account:{}})}},chains:{get:()=>u.getState().chains,set:e=>{u.setState({chains:e})},clear:()=>{u.setState({chains:[]})}},keys:{get:e=>u.getState().keys[e],set:(e,t)=>{u.setState(n=>({keys:Object.assign(Object.assign({},n.keys),{[e]:t})}))},clear:()=>{u.setState({keys:{}})}},config:l},p=Object.assign(Object.assign({},u),d),f=()=>{var e,t,n;if("undefined"!=typeof window){const r=null!==(n=null!==(e=p.config.get().deviceId)&&void 0!==e?e:null===(t=window.crypto)||void 0===t?void 0:t.randomUUID())&&void 0!==n?n:"";if(window.ClientAnalytics){const{init:e,identify:t,PlatformName:n}=window.ClientAnalytics;e({isProd:!0,amplitudeApiKey:"c66737ad47ec354ced777935b0af822e",platform:n.web,projectName:"base_account_sdk",showDebugLogging:!1,version:"1.0.0",apiEndpoint:"https://cca-lite.coinbase.com"}),t({deviceId:r}),p.config.set({deviceId:r})}}},m="0xf85210B21cC50302F477BA56686d2019dC9b67Ad",h=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[{name:"owner",type:"bytes"}],name:"AlreadyOwner",type:"error"},{inputs:[],name:"Initialized",type:"error"},{inputs:[{name:"owner",type:"bytes"}],name:"InvalidEthereumAddressOwner",type:"error"},{inputs:[{name:"key",type:"uint256"}],name:"InvalidNonceKey",type:"error"},{inputs:[{name:"owner",type:"bytes"}],name:"InvalidOwnerBytesLength",type:"error"},{inputs:[],name:"LastOwner",type:"error"},{inputs:[{name:"index",type:"uint256"}],name:"NoOwnerAtIndex",type:"error"},{inputs:[{name:"ownersRemaining",type:"uint256"}],name:"NotLastOwner",type:"error"},{inputs:[{name:"selector",type:"bytes4"}],name:"SelectorNotAllowed",type:"error"},{inputs:[],name:"Unauthorized",type:"error"},{inputs:[],name:"UnauthorizedCallContext",type:"error"},{inputs:[],name:"UpgradeFailed",type:"error"},{inputs:[{name:"index",type:"uint256"},{name:"expectedOwner",type:"bytes"},{name:"actualOwner",type:"bytes"}],name:"WrongOwnerAtIndex",type:"error"},{anonymous:!1,inputs:[{indexed:!0,name:"index",type:"uint256"},{indexed:!1,name:"owner",type:"bytes"}],name:"AddOwner",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"index",type:"uint256"},{indexed:!1,name:"owner",type:"bytes"}],name:"RemoveOwner",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{stateMutability:"payable",type:"fallback"},{inputs:[],name:"REPLAYABLE_NONCE_KEY",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"owner",type:"address"}],name:"addOwnerAddress",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"x",type:"bytes32"},{name:"y",type:"bytes32"}],name:"addOwnerPublicKey",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"functionSelector",type:"bytes4"}],name:"canSkipChainIdValidation",outputs:[{name:"",type:"bool"}],stateMutability:"pure",type:"function"},{inputs:[],name:"domainSeparator",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"entryPoint",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{name:"target",type:"address"},{name:"value",type:"uint256"},{name:"data",type:"bytes"}],name:"execute",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"target",type:"address"},{name:"value",type:"uint256"},{name:"data",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"executeBatch",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{name:"calls",type:"bytes[]"}],name:"executeWithoutChainIdValidation",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"sender",type:"address"},{name:"nonce",type:"uint256"},{name:"initCode",type:"bytes"},{name:"callData",type:"bytes"},{name:"callGasLimit",type:"uint256"},{name:"verificationGasLimit",type:"uint256"},{name:"preVerificationGas",type:"uint256"},{name:"maxFeePerGas",type:"uint256"},{name:"maxPriorityFeePerGas",type:"uint256"},{name:"paymasterAndData",type:"bytes"},{name:"signature",type:"bytes"}],name:"userOp",type:"tuple"}],name:"getUserOpHashWithoutChainId",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"implementation",outputs:[{name:"$",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{name:"owners",type:"bytes[]"}],name:"initialize",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{name:"account",type:"address"}],name:"isOwnerAddress",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"account",type:"bytes"}],name:"isOwnerBytes",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"x",type:"bytes32"},{name:"y",type:"bytes32"}],name:"isOwnerPublicKey",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"hash",type:"bytes32"},{name:"signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"result",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[],name:"nextOwnerIndex",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"index",type:"uint256"}],name:"ownerAtIndex",outputs:[{name:"",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[],name:"ownerCount",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"proxiableUUID",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{name:"index",type:"uint256"},{name:"owner",type:"bytes"}],name:"removeLastOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"index",type:"uint256"},{name:"owner",type:"bytes"}],name:"removeOwnerAtIndex",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"removedOwnersCount",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"hash",type:"bytes32"}],name:"replaySafeHash",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{name:"newImplementation",type:"address"},{name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"sender",type:"address"},{name:"nonce",type:"uint256"},{name:"initCode",type:"bytes"},{name:"callData",type:"bytes"},{name:"callGasLimit",type:"uint256"},{name:"verificationGasLimit",type:"uint256"},{name:"preVerificationGas",type:"uint256"},{name:"maxFeePerGas",type:"uint256"},{name:"maxPriorityFeePerGas",type:"uint256"},{name:"paymasterAndData",type:"bytes"},{name:"signature",type:"bytes"}],name:"userOp",type:"tuple"},{name:"userOpHash",type:"bytes32"},{name:"missingAccountFunds",type:"uint256"}],name:"validateUserOp",outputs:[{name:"validationData",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],y=[{inputs:[{name:"implementation_",type:"address"}],stateMutability:"payable",type:"constructor"},{inputs:[],name:"OwnerRequired",type:"error"},{inputs:[{name:"owners",type:"bytes[]"},{name:"nonce",type:"uint256"}],name:"createAccount",outputs:[{name:"account",type:"address"}],stateMutability:"payable",type:"function"},{inputs:[{name:"owners",type:"bytes[]"},{name:"nonce",type:"uint256"}],name:"getAddress",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"implementation",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initCodeHash",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"}],g={invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},b={userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901,unsupportedChain:4902},w={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."},4902:{standard:"EIP-3085",message:"Unrecognized chain ID."}},v="Unspecified error message.";function x(e,t=v){if(e&&Number.isInteger(e)){const t=e.toString();if(I(w,t))return w[t].message;if(P(e))return"Unspecified server error."}return t}function k(e,{shouldIncludeStack:t=!1}={}){const n={};if(e&&"object"==typeof e&&!Array.isArray(e)&&I(e,"code")&&function(e){if(!Number.isInteger(e))return!1;const t=e.toString();return!!w[t]||!!P(e)}(e.code)){const t=e;n.code=t.code,t.message&&"string"==typeof t.message?(n.message=t.message,I(t,"data")&&(n.data=t.data)):(n.message=x(n.code),n.data={originalError:E(e)})}else n.code=g.internal,n.message=A(e,"message")?e.message:v,n.data={originalError:E(e)};return t&&(n.stack=A(e,"stack")?e.stack:void 0),n}function P(e){return e>=-32099&&e<=-32e3}function E(e){return e&&"object"==typeof e&&!Array.isArray(e)?Object.assign({},e):e}function I(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function A(e,t){return"object"==typeof e&&null!==e&&t in e&&"string"==typeof e[t]}const O={parse:e=>T(g.parse,e),invalidRequest:e=>T(g.invalidRequest,e),invalidParams:e=>T(g.invalidParams,e),methodNotFound:e=>T(g.methodNotFound,e),internal:e=>T(g.internal,e),server:e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Ethereum RPC Server errors must provide single object argument.");const{code:t}=e;if(!Number.isInteger(t)||t>-32005||t<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return T(t,e)},invalidInput:e=>T(g.invalidInput,e),resourceNotFound:e=>T(g.resourceNotFound,e),resourceUnavailable:e=>T(g.resourceUnavailable,e),transactionRejected:e=>T(g.transactionRejected,e),methodNotSupported:e=>T(g.methodNotSupported,e),limitExceeded:e=>T(g.limitExceeded,e)},S={userRejectedRequest:e=>B(b.userRejectedRequest,e),unauthorized:e=>B(b.unauthorized,e),unsupportedMethod:e=>B(b.unsupportedMethod,e),disconnected:e=>B(b.disconnected,e),chainDisconnected:e=>B(b.chainDisconnected,e),unsupportedChain:e=>B(b.unsupportedChain,e),custom:e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Ethereum Provider custom errors must provide single object argument.");const{code:t,message:n,data:r}=e;if(!n||"string"!=typeof n)throw new Error('"message" must be a nonempty string');return new j(t,n,r)}};function T(e,t){const[n,r]=C(t);return new N(e,n||x(e),r)}function B(e,t){const[n,r]=C(t);return new j(e,n||x(e),r)}function C(e){if(e){if("string"==typeof e)return[e];if("object"==typeof e&&!Array.isArray(e)){const{message:t,data:n}=e;if(t&&"string"!=typeof t)throw new Error("Must specify string message.");return[t||void 0,n]}}return[]}class N extends Error{constructor(e,t,n){if(!Number.isInteger(e))throw new Error('"code" must be an integer.');if(!t||"string"!=typeof t)throw new Error('"message" must be a nonempty string.');super(t),this.code=e,void 0!==n&&(this.data=n)}}class j extends N{constructor(e,t,n){if(!function(e){return Number.isInteger(e)&&e>=1e3&&e<=4999}(e))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');super(e,t,n)}}function U(e){return"object"==typeof e&&null!==e&&"code"in e&&"data"in e&&-32090===e.code&&"object"==typeof e.data&&null!==e.data&&"type"in e.data&&"INSUFFICIENT_FUNDS"===e.data.type}function R(e){return"object"==typeof e&&null!==e&&"details"in e}function M(e,t,n){if(null==e)throw null!=t?t:O.invalidParams({message:"value must be present",data:e})}function L(e,t){if(!Array.isArray(e))throw O.invalidParams({message:null!=t?t:"value must be an array",data:e})}const{checkCrossOriginOpenerPolicy:F,getCrossOriginOpenerPolicy:_}=(()=>{let e;return{getCrossOriginOpenerPolicy:()=>void 0===e?"undefined":e,checkCrossOriginOpenerPolicy:async()=>{if("undefined"!=typeof window)try{const t=`${window.location.origin}${window.location.pathname}`,n=await fetch(t,{method:"HEAD"});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const r=n.headers.get("Cross-Origin-Opener-Policy");e=null!=r?r:"null","same-origin"===e&&console.error("Base Account SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Base Account app.\n\nPlease see https://docs.base.org/smart-wallet/quickstart#cross-origin-opener-policy for more information.")}catch(t){console.error("Error checking Cross-Origin-Opener-Policy:",t.message),e="error"}else e="non-browser-env"}}})();function D(e){if("function"!=typeof e)throw new Error("toAccount is not a function")}let z=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,a=n.cause instanceof e&&n.cause.docsPath||n.docsPath;super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...a?[`Docs: https://abitype.dev${a}`]:[],...r?[`Details: ${r}`]:[],"Version: abitype@1.0.8"].join("\n")),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),n.cause&&(this.cause=n.cause),this.details=r,this.docsPath=a,this.metaMessages=n.metaMessages,this.shortMessage=t}};function q(e,t){const n=e.exec(t);return n?.groups}const G=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,H=/^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)?$/,V=/^\(.+?\).*?$/,K=/^tuple(?<array>(\[(\d*)\])*)$/;function Z(e){let t=e.type;if(K.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=Z(e.components[r]),r<n-1&&(t+=", ")}const r=q(K,e.type);return t+=`)${r?.array??""}`,Z({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function W(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=Z(e[r]),r!==n-1&&(t+=", ")}return t}function J(e){return"function"===e.type?`function ${e.name}(${W(e.inputs)})${e.stateMutability&&"nonpayable"!==e.stateMutability?` ${e.stateMutability}`:""}${e.outputs?.length?` returns (${W(e.outputs)})`:""}`:"event"===e.type?`event ${e.name}(${W(e.inputs)})`:"error"===e.type?`error ${e.name}(${W(e.inputs)})`:"constructor"===e.type?`constructor(${W(e.inputs)})${"payable"===e.stateMutability?" payable":""}`:"fallback"===e.type?"fallback() external"+("payable"===e.stateMutability?" payable":""):"receive() external payable"}const Y=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const Q=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const X=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;const $=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function ee(e){return $.test(e)}function te(e){return q($,e)}const ne=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const re=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const ae=/^receive\(\) external payable$/;const se=new Set(["indexed"]),ie=new Set(["calldata","memory","storage"]);class oe extends z{constructor({signature:e}){super("Failed to parse ABI item.",{details:`parseAbiItem(${JSON.stringify(e,null,2)})`,docsPath:"/api/human#parseabiitem-1"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiItemError"})}}class ce extends z{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownTypeError"})}}class ue extends z{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class le extends z{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class de extends z{constructor({param:e,name:t}){super("Invalid ABI parameter.",{details:e,metaMessages:[`"${t}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SolidityProtectedKeywordError"})}}class pe extends z{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class fe extends z{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${n}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class me extends z{constructor({abiParameter:e}){super("Invalid ABI parameter.",{details:JSON.stringify(e,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class he extends z{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class ye extends z{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class ge extends z{constructor({signature:e}){super("Invalid struct signature.",{details:e,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class be extends z{constructor({type:e}){super("Circular reference detected.",{metaMessages:[`Struct "${e}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class we extends z{constructor({current:e,depth:t}){super("Unbalanced parentheses.",{metaMessages:[`"${e.trim()}" has too many ${t>0?"opening":"closing"} parentheses.`],details:`Depth "${t}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}const ve=new Map([["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"}],["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"}],["event:address indexed from",{type:"address",name:"from",indexed:!0}],["event:address indexed to",{type:"address",name:"to",indexed:!0}],["event:uint indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}],["event:uint256 indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}]]);function xe(e,t={}){if(function(e){return X.test(e)}(e))return function(e,t={}){const n=function(e){return q(X,e)}(e);if(!n)throw new he({signature:e,type:"function"});const r=Ae(n.parameters),a=[],s=r.length;for(let e=0;e<s;e++)a.push(Ie(r[e],{modifiers:ie,structs:t,type:"function"}));const i=[];if(n.returns){const e=Ae(n.returns),r=e.length;for(let n=0;n<r;n++)i.push(Ie(e[n],{modifiers:ie,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:a,outputs:i}}(e,t);if(function(e){return Q.test(e)}(e))return function(e,t={}){const n=function(e){return q(Q,e)}(e);if(!n)throw new he({signature:e,type:"event"});const r=Ae(n.parameters),a=[],s=r.length;for(let e=0;e<s;e++)a.push(Ie(r[e],{modifiers:se,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:a}}(e,t);if(function(e){return Y.test(e)}(e))return function(e,t={}){const n=function(e){return q(Y,e)}(e);if(!n)throw new he({signature:e,type:"error"});const r=Ae(n.parameters),a=[],s=r.length;for(let e=0;e<s;e++)a.push(Ie(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:a}}(e,t);if(function(e){return ne.test(e)}(e))return function(e,t={}){const n=function(e){return q(ne,e)}(e);if(!n)throw new he({signature:e,type:"constructor"});const r=Ae(n.parameters),a=[],s=r.length;for(let e=0;e<s;e++)a.push(Ie(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:a}}(e,t);if(function(e){return re.test(e)}(e))return function(e){const t=function(e){return q(re,e)}(e);if(!t)throw new he({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return ae.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new ye({signature:e})}const ke=/^(?<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$_]*))?$/,Pe=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Ee=/^u?int$/;function Ie(e,t){const n=function(e,t,n){let r="";if(n)for(const e of Object.entries(n)){if(!e)continue;let t="";for(const n of e[1])t+=`[${n.type}${n.name?`:${n.name}`:""}]`;r+=`(${e[0]}{${t}})`}return t?`${t}:${e}${r}`:e}(e,t?.type,t?.structs);if(ve.has(n))return ve.get(n);const r=V.test(e),a=q(r?Pe:ke,e);if(!a)throw new le({param:e});if(a.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||G.test(e)||H.test(e)||Se.test(e)}(a.name))throw new de({param:e,name:a.name});const s=a.name?{name:a.name}:{},i="indexed"===a.modifier?{indexed:!0}:{},o=t?.structs??{};let c,u={};if(r){c="tuple";const e=Ae(a.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(Ie(e[r],{structs:o}));u={components:t}}else if(a.type in o)c="tuple",u={components:o[a.type]};else if(Ee.test(a.type))c=`${a.type}256`;else if(c=a.type,"struct"!==t?.type&&!Oe(c))throw new ue({type:c});if(a.modifier){if(!t?.modifiers?.has?.(a.modifier))throw new pe({param:e,type:t?.type,modifier:a.modifier});if(ie.has(a.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(c,!!a.array))throw new fe({param:e,type:t?.type,modifier:a.modifier})}const l={type:`${c}${a.array??""}`,...s,...i,...u};return ve.set(n,l),l}function Ae(e,t=[],n="",r=0){const a=e.trim().length;for(let s=0;s<a;s++){const a=e[s],i=e.slice(s+1);switch(a){case",":return 0===r?Ae(i,[...t,n.trim()]):Ae(i,t,`${n}${a}`,r);case"(":return Ae(i,t,`${n}${a}`,r+1);case")":return Ae(i,t,`${n}${a}`,r-1);default:return Ae(i,t,`${n}${a}`,r)}}if(""===n)return t;if(0!==r)throw new we({current:n,depth:r});return t.push(n.trim()),t}function Oe(e){return"address"===e||"bool"===e||"function"===e||"string"===e||G.test(e)||H.test(e)}const Se=/^(?: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)$/;function Te(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!ee(n))continue;const a=te(n);if(!a)throw new he({signature:n,type:"struct"});const s=a.properties.split(";"),i=[],o=s.length;for(let e=0;e<o;e++){const t=s[e].trim();if(!t)continue;const n=Ie(t,{type:"struct"});i.push(n)}if(!i.length)throw new ge({signature:n});t[a.name]=i}const r={},a=Object.entries(t),s=a.length;for(let e=0;e<s;e++){const[n,s]=a[e];r[n]=Ce(s,t)}return r}const Be=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function Ce(e,t,n=new Set){const r=[],a=e.length;for(let s=0;s<a;s++){const a=e[s];if(V.test(a.type))r.push(a);else{const e=q(Be,a.type);if(!e?.type)throw new me({abiParameter:a});const{array:s,type:i}=e;if(i in t){if(n.has(i))throw new be({type:i});r.push({...a,type:`tuple${s??""}`,components:Ce(t[i]??[],t,new Set([...n,i]))})}else{if(!Oe(i))throw new ce({type:i});r.push(a)}}}return r}function Ne(e){const t=Te(e),n=[],r=e.length;for(let a=0;a<r;a++){const r=e[a];ee(r)||n.push(xe(r,t))}return n}function je(e){let t;if("string"==typeof e)t=xe(e);else{const n=Te(e),r=e.length;for(let a=0;a<r;a++){const r=e[a];if(!ee(r)){t=xe(r,n);break}}}if(!t)throw new oe({signature:e});return t}function Ue(e,t,n){const r=e[t.name];if("function"==typeof r)return r;const a=e[n];return"function"==typeof a?a:n=>t(e,n)}function Re(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new ft(e.type);return`${e.name}(${Me(e.inputs,{includeName:t})})`}function Me(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${Me(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}function Le(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function Fe(e){return Le(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const _e="2.31.7";let De=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,ze=`viem@${_e}`,qe=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,a=n.cause instanceof e&&n.cause.docsPath||n.docsPath,s=De?.({...n,docsPath:a});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...r?[`Details: ${r}`]:[],...ze?[`Version: ${ze}`]:[]].join("\n"),n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=r,this.docsPath=a,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=_e}walk(e){return Ge(this,e)}};function Ge(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?Ge(e.cause,t):t?null:e}class He extends qe{constructor({docsPath:e}){super(["A constructor was not found on the ABI.","Make sure you are using the correct ABI and that the constructor exists on it."].join("\n"),{docsPath:e,name:"AbiConstructorNotFoundError"})}}class Ve extends qe{constructor({docsPath:e}){super(["Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.","Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."].join("\n"),{docsPath:e,name:"AbiConstructorParamsNotFoundError"})}}class Ke extends qe{constructor({data:e,params:t,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join("\n"),{metaMessages:[`Params: (${Me(t,{includeName:!0})})`,`Data: ${e} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=e,this.params=t,this.size=n}}class Ze extends qe{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class We extends qe{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join("\n"),{name:"AbiEncodingArrayLengthMismatchError"})}}class Je extends qe{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${Fe(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class Ye extends qe{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${t}`].join("\n"),{name:"AbiEncodingLengthMismatchError"})}}class Qe extends qe{constructor(e,{docsPath:t}){super([`Arguments (\`args\`) were provided to "${e}", but "${e}" on the ABI does not contain any parameters (\`inputs\`).`,"Cannot encode error result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the inputs exist on it."].join("\n"),{docsPath:t,name:"AbiErrorInputsNotFoundError"})}}class Xe extends qe{constructor(e,{docsPath:t}={}){super([`Error ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it."].join("\n"),{docsPath:t,name:"AbiErrorNotFoundError"})}}class $e extends qe{constructor(e,{docsPath:t}){super([`Encoded error signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=e}}class et extends qe{constructor({docsPath:e}){super("Cannot extract event signature from empty topics.",{docsPath:e,name:"AbiEventSignatureEmptyTopicsError"})}}class tt extends qe{constructor(e,{docsPath:t}){super([`Encoded event signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiEventSignatureNotFoundError"})}}class nt extends qe{constructor(e,{docsPath:t}={}){super([`Event ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the event exists on it."].join("\n"),{docsPath:t,name:"AbiEventNotFoundError"})}}class rt extends qe{constructor(e,{docsPath:t}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionNotFoundError"})}}class at extends qe{constructor(e,{docsPath:t}){super([`Function "${e}" does not contain any \`outputs\` on ABI.`,"Cannot decode function result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionOutputsNotFoundError"})}}class st extends qe{constructor(e,{docsPath:t}){super([`Encoded function signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiFunctionSignatureNotFoundError"})}}class it extends qe{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${Re(e.abiItem)}\`, and`,`\`${t.type}\` in \`${Re(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}let ot=class extends qe{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:"BytesSizeMismatchError"})}};class ct extends qe{constructor({abiItem:e,data:t,params:n,size:r}){super([`Data size of ${r} bytes is too small for non-indexed event parameters.`].join("\n"),{metaMessages:[`Params: (${Me(n,{includeName:!0})})`,`Data: ${t} (${r} bytes)`],name:"DecodeLogDataMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e,this.data=t,this.params=n,this.size=r}}class ut extends qe{constructor({abiItem:e,param:t}){super([`Expected a topic for indexed event parameter${t.name?` "${t.name}"`:""} on event "${Re(e,{includeName:!0})}".`].join("\n"),{name:"DecodeLogTopicsMismatch"}),Object.defineProperty(this,"abiItem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.abiItem=e}}class lt extends qe{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiEncodingType"})}}class dt extends qe{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiDecodingType"})}}let pt=class extends qe{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}};class ft extends qe{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class mt extends qe{constructor(e){super(`Type "${e}" is not supported for packed encoding.`,{name:"UnsupportedPackedAbiType"})}}class ht extends qe{constructor(e){super(`Filter type "${e}" is not supported.`,{name:"FilterTypeNotSupportedError"})}}let yt=class extends qe{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}},gt=class extends qe{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}};class bt extends qe{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} is expected to be ${t} ${n} long, but is ${e} ${n} long.`,{name:"InvalidBytesLengthError"})}}function wt(e,{dir:t,size:n=32}={}){return"string"==typeof e?vt(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new gt({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let a=0;a<n;a++){const s="right"===t;r[s?a:n-a-1]=e[s?a:e.length-a-1]}return r}(e,{dir:t,size:n})}function vt(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new gt({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}let xt=class extends qe{constructor({max:e,min:t,signed:n,size:r,value:a}){super(`Number "${a}" is not in safe ${r?`${8*r}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}};class kt extends qe{constructor(e){super(`Bytes value "${e}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class Pt extends qe{constructor(e){super(`Hex value "${e}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,{name:"InvalidHexBooleanError"})}}let Et=class extends qe{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}};function It(e,{dir:t="left"}={}){let n="string"==typeof e?e.replace("0x",""):e,r=0;for(let e=0;e<n.length-1&&"0"===n["left"===t?e:n.length-e-1].toString();e++)r++;return n="left"===t?n.slice(r):n.slice(0,n.length-r),"string"==typeof e?(1===n.length&&"right"===t&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}function At(e,{size:t}){if(Fe(e)>t)throw new Et({givenSize:Fe(e),maxSize:t})}function Ot(e,t={}){const{signed:n}=t;t.size&&At(e,{size:t.size});const r=BigInt(e);if(!n)return r;const a=(e.length-2)/2;return r<=(1n<<8n*BigInt(a)-1n)-1n?r:r-BigInt(`0x${"f".padStart(2*a,"f")}`)-1n}function St(e,t={}){return Number(Ot(e,t))}function Tt(e,t={}){let n=zt(e);return t.size&&(At(n,{size:t.size}),n=It(n,{dir:"right"})),(new TextDecoder).decode(n)}const Bt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ct(e,t={}){return"number"==typeof e||"bigint"==typeof e?Ut(e,t):"string"==typeof e?Mt(e,t):"boolean"==typeof e?Nt(e,t):jt(e,t)}function Nt(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(At(n,{size:t.size}),wt(n,{size:t.size})):n}function jt(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=Bt[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(At(r,{size:t.size}),wt(r,{dir:"right",size:t.size})):r}function Ut(e,t={}){const{signed:n,size:r}=t,a=BigInt(e);let s;r?s=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(s=BigInt(Number.MAX_SAFE_INTEGER));const i="bigint"==typeof s&&n?-s-1n:0;if(s&&a>s||a<i){const t="bigint"==typeof e?"n":"";throw new xt({max:s?`${s}${t}`:void 0,min:`${i}${t}`,signed:n,size:r,value:`${e}${t}`})}const o=`0x${(n&&a<0?(1n<<BigInt(8*r))+BigInt(a):a).toString(16)}`;return r?wt(o,{size:r}):o}const Rt=new TextEncoder;function Mt(e,t={}){return jt(Rt.encode(e),t)}const Lt=new TextEncoder;function Ft(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=Ut(e,t);return zt(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return At(n,{size:t.size}),wt(n,{size:t.size});return n}(e,t):Le(e)?zt(e,t):qt(e,t)}const _t={zero:48,nine:57,A:65,F:70,a:97,f:102};function Dt(e){return e>=_t.zero&&e<=_t.nine?e-_t.zero:e>=_t.A&&e<=_t.F?e-(_t.A-10):e>=_t.a&&e<=_t.f?e-(_t.a-10):void 0}function zt(e,t={}){let n=e;t.size&&(At(n,{size:t.size}),n=wt(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const a=r.length/2,s=new Uint8Array(a);for(let e=0,t=0;e<a;e++){const n=Dt(r.charCodeAt(t++)),a=Dt(r.charCodeAt(t++));if(void 0===n||void 0===a)throw new qe(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);s[e]=16*n+a}return s}function qt(e,t={}){const n=Lt.encode(e);return"number"==typeof t.size?(At(n,{size:t.size}),wt(n,{dir:"right",size:t.size})):n}const Gt=BigInt(2**32-1),Ht=BigInt(32);function Vt(e,t=!1){return t?{h:Number(e&Gt),l:Number(e>>Ht&Gt)}:{h:0|Number(e>>Ht&Gt),l:0|Number(e&Gt)}}function Kt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Zt(e,...t){if(! /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ function(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Wt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Jt(e,t){Zt(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Yt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Qt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Xt(e,t){return e<<32-t|e>>>t}function $t(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const en=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=$t(e[t]);return e};function tn(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Zt(e),e}let nn=class{};function rn(e){const t=t=>e().update(tn(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}const an=BigInt(0),sn=BigInt(1),on=BigInt(2),cn=BigInt(7),un=BigInt(256),ln=BigInt(113),dn=[],pn=[],fn=[];for(let e=0,t=sn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],dn.push(2*(5*r+n)),pn.push((e+1)*(e+2)/2%64);let a=an;for(let e=0;e<7;e++)t=(t<<sn^(t>>cn)*ln)%un,t&on&&(a^=sn<<(sn<<BigInt(e))-sn);fn.push(a)}const mn=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),a=new Uint32Array(n);for(let s=0;s<n;s++){const{h:n,l:i}=Vt(e[s],t);[r[s],a[s]]=[n,i]}return[r,a]}(fn,!0),hn=mn[0],yn=mn[1],gn=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),bn=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);let wn=class e extends nn{constructor(e,t,n,r=!1,a=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=a,Kt(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}clone(){return this._cloneInto()}keccak(){en(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,a=(t+2)%10,s=n[a],i=n[a+1],o=gn(s,i,1)^n[r],c=bn(s,i,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=c}let t=e[2],a=e[3];for(let n=0;n<24;n++){const r=pn[n],s=gn(t,a,r),i=bn(t,a,r),o=dn[n];t=e[o],a=e[o+1],e[o]=s,e[o+1]=i}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=hn[r],e[1]^=yn[r]}Yt(n)}(this.state32,this.rounds),en(this.state32),this.posOut=0,this.pos=0}update(e){Wt(this),Zt(e=tn(e));const{blockLen:t,state:n}=this,r=e.length;for(let a=0;a<r;){const s=Math.min(t-this.pos,r-a);for(let t=0;t<s;t++)n[this.pos++]^=e[a++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Wt(this,!1),Zt(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,a=e.length;r<a;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,a-r);e.set(t.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Kt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Jt(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Yt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:a,rounds:s,enableXOF:i}=this;return t||(t=new e(n,r,a,i,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=r,t.outputLen=a,t.enableXOF=i,t.des