(function(se,Oe){typeof exports=="object"&&typeof module<"u"?Oe(exports):typeof define=="function"&&define.amd?define(["exports"],Oe):(se=typeof globalThis<"u"?globalThis:se||self,Oe(se.index={}))})(this,function(se){"use strict";var Oe=Object.defineProperty,ti=(e,t,n)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ot=(e,t,n)=>(ti(e,typeof t!="symbol"?t+"":t,n),n),Mt=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},H=(e,t,n)=>(Mt(e,t,"read from private field"),n?n.call(e):t.get(e)),Z=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},Me=(e,t,n,r)=>(Mt(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Ae=(e,t,n)=>(Mt(e,t,"access private method"),n);const ni="1.10.8",vn=e=>e,ri=()=>`viem@${ni}`;class v extends Error{constructor(t,n={}){var r;super(),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:"ViemError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:ri()});const i=n.cause instanceof v?n.cause.details:(r=n.cause)!=null&&r.message?n.cause.message:n.details,o=n.cause instanceof v&&n.cause.docsPath||n.docsPath;this.message=[t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...o?[`Docs: https://viem.sh${o}.html${n.docsSlug?`#${n.docsSlug}`:""}`]:[],...i?[`Details: ${i}`]:[],`Version: ${this.version}`].join(` `),n.cause&&(this.cause=n.cause),this.details=i,this.docsPath=o,this.metaMessages=n.metaMessages,this.shortMessage=t}walk(t){return bn(this,t)}}function bn(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e?bn(e.cause,t):t?null:e}class ii extends v{constructor({chain:t,currentChainId:n}){super(`The current chain of the wallet (id: ${n}) does not match the target chain for the transaction (id: ${t.id} – ${t.name}).`,{metaMessages:[`Current Chain ID: ${n}`,`Expected Chain ID: ${t.id} – ${t.name}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ChainMismatchError"})}}class oi extends v{constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ChainNotFoundError"})}}function wn({chain:e,currentChainId:t}){if(!e)throw new oi;if(t!==e.id)throw new ii({chain:e,currentChainId:t})}function Pn(e,t={}){const{fees:n=e.fees,formatters:r=e.formatters,serializers:i=e.serializers}=t;return{...e,fees:n,formatters:r,serializers:i}}class si extends v{constructor({max:t,min:n,signed:r,size:i,value:o}){super(`Number "${o}" is not in safe ${i?`${i*8}-bit ${r?"signed":"unsigned"} `:""}integer range ${t?`(${n} to ${t})`:`(above ${n})`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"IntegerOutOfRangeError"})}}class ai extends v{constructor({givenSize:t,maxSize:n}){super(`Size cannot exceed ${n} bytes. Given size: ${t} bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SizeOverflowError"})}}function fe(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function R(e){return fe(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}class En extends v{constructor({offset:t,position:n,size:r}){super(`Slice ${n==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${r}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SliceOffsetOutOfBoundsError"})}}class In extends v{constructor({size:t,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (${t}) exceeds padding size (${n}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SizeExceedsPaddingSizeError"})}}function pe(e,{dir:t,size:n=32}={}){return typeof e=="string"?X(e,{dir:t,size:n}):ci(e,{dir:t,size:n})}function X(e,{dir:t,size:n=32}={}){if(n===null)return e;const r=e.replace("0x","");if(r.length>n*2)throw new In({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r[t==="right"?"padEnd":"padStart"](n*2,"0")}`}function ci(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new In({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let i=0;it.toString(16).padStart(2,"0"));function xn(e,t={}){return typeof e=="number"||typeof e=="bigint"?M(e,t):typeof e=="string"?At(e,t):typeof e=="boolean"?On(e,t):Mn(e,t)}function On(e,t={}){const n=`0x${Number(e)}`;return typeof t.size=="number"?(ge(n,{size:t.size}),pe(n,{size:t.size})):n}function Mn(e,t={}){let n="";for(let i=0;io||it)throw new ai({givenSize:R(e),maxSize:t})}function Tn(e,t={}){const{signed:n}=t;t.size&&ge(e,{size:t.size});const r=BigInt(e);if(!n)return r;const i=(e.length-2)/2,o=(1n<typeof r=="string"?r:gi(r));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,difficulty:e.difficulty?BigInt(e.difficulty):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:n,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const yi={legacy:"0x0",eip2930:"0x1",eip1559:"0x2"};function jt(e){return{...e,gas:typeof e.gas<"u"?M(e.gas):void 0,gasPrice:typeof e.gasPrice<"u"?M(e.gasPrice):void 0,maxFeePerGas:typeof e.maxFeePerGas<"u"?M(e.maxFeePerGas):void 0,maxPriorityFeePerGas:typeof e.maxPriorityFeePerGas<"u"?M(e.maxPriorityFeePerGas):void 0,nonce:typeof e.nonce<"u"?M(e.nonce):void 0,type:typeof e.type<"u"?yi[e.type]:void 0,value:typeof e.value<"u"?M(e.value):void 0}}class je extends v{constructor({address:t}){super(`Address "${t}" is invalid.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAddressError"})}}const vi={gwei:9,wei:18},bi={ether:-9,wei:9};function Cn(e,t){let n=e.toString();const r=n.startsWith("-");r&&(n=n.slice(1)),n=n.padStart(t,"0");let[i,o]=[n.slice(0,n.length-t),n.slice(n.length-t)];return o=o.replace(/(0+)$/,""),`${r?"-":""}${i||"0"}${o?`.${o}`:""}`}function q(e,t="wei"){return Cn(e,bi[t])}class me extends v{constructor({cause:t,message:n}={}){var r;const i=(r=n==null?void 0:n.replace("execution reverted: ",""))==null?void 0:r.replace("execution reverted","");super(`Execution reverted ${i?`with reason: ${i}`:"for an unknown reason"}.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ExecutionRevertedError"})}}Object.defineProperty(me,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(me,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class nt extends v{constructor({cause:t,maxFeePerGas:n}={}){super(`The fee cap (\`maxFeePerGas\`${n?` = ${q(n)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"FeeCapTooHigh"})}}Object.defineProperty(nt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class St extends v{constructor({cause:t,maxFeePerGas:n}={}){super(`The fee cap (\`maxFeePerGas\`${n?` = ${q(n)}`:""} gwei) cannot be lower than the block base fee.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"FeeCapTooLow"})}}Object.defineProperty(St,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/});class Tt extends v{constructor({cause:t,nonce:n}={}){super(`Nonce provided for the transaction ${n?`(${n}) `:""}is higher than the next one expected.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"NonceTooHighError"})}}Object.defineProperty(Tt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class Ct extends v{constructor({cause:t,nonce:n}={}){super([`Nonce provided for the transaction ${n?`(${n}) `:""}is lower than the current nonce of the account.`,"Try increasing the nonce or find the latest nonce with `getTransactionCount`."].join(` `),{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"NonceTooLowError"})}}Object.defineProperty(Ct,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class Nt extends v{constructor({cause:t,nonce:n}={}){super(`Nonce provided for the transaction ${n?`(${n}) `:""}exceeds the maximum allowed nonce.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"NonceMaxValueError"})}}Object.defineProperty(Nt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class _t extends v{constructor({cause:t}={}){super(["The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."].join(` `),{cause:t,metaMessages:["This error could arise when the account does not have enough funds to:"," - pay for the total gas fee,"," - pay for the value to send."," ","The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InsufficientFundsError"})}}Object.defineProperty(_t,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds/});class Rt extends v{constructor({cause:t,gas:n}={}){super(`The amount of gas ${n?`(${n}) `:""}provided for the transaction exceeds the limit allowed for the block.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"IntrinsicGasTooHighError"})}}Object.defineProperty(Rt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class kt extends v{constructor({cause:t,gas:n}={}){super(`The amount of gas ${n?`(${n}) `:""}provided for the transaction is too low.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"IntrinsicGasTooLowError"})}}Object.defineProperty(kt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class Dt extends v{constructor({cause:t}){super("The transaction type is not supported for this chain.",{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"TransactionTypeNotSupportedError"})}}Object.defineProperty(Dt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class rt extends v{constructor({cause:t,maxPriorityFeePerGas:n,maxFeePerGas:r}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${n?` = ${q(n)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${r?` = ${q(r)} gwei`:""}).`].join(` `),{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"TipAboveFeeCapError"})}}Object.defineProperty(rt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Lt extends v{constructor({cause:t}){super(`An error occurred while executing: ${t==null?void 0:t.shortMessage}`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownNodeError"})}}const wi=/^0x[a-fA-F0-9]{40}$/;function ye(e){return wi.test(e)}function ve(e){return typeof e[0]=="string"?zt(e):Pi(e)}function Pi(e){let t=0;for(const i of e)t+=i.length;const n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.length;return n}function zt(e){return`0x${e.reduce((t,n)=>t+n.replace("0x",""),"")}`}function Nn(e,t="wei"){return Cn(e,vi[t])}function $t(e){const t=Object.entries(e).map(([r,i])=>i===void 0||i===!1?null:[r,i]).filter(Boolean),n=t.reduce((r,[i])=>Math.max(r,i.length),0);return t.map(([r,i])=>` ${`${r}:`.padEnd(n+1)} ${i}`).join(` `)}class Ei extends v{constructor(){super(["Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.","Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"FeeConflictError"})}}class Ii extends v{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",$t(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- a Legacy Transaction with `gasPrice`"]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSerializableTransactionError"})}}class xi extends v{constructor(t,{account:n,docsPath:r,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:l,to:f,value:d}){const h=$t({chain:i&&`${i==null?void 0:i.name} (id: ${i==null?void 0:i.id})`,from:n==null?void 0:n.address,to:f,value:typeof d<"u"&&`${Nn(d)} ${(i==null?void 0:i.nativeCurrency.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${q(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${q(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${q(u)} gwei`,nonce:l});super(t.shortMessage,{cause:t,docsPath:r,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Request Arguments:",h].filter(Boolean)}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"TransactionExecutionError"}),this.cause=t}}function Oi(e){if(e.type)return e.type;if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new Ii({transaction:e})}const Mi=Pn({id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0x56522D00C410a43BFfDF00a9A569489297385790",blockCreated:8765204},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:6507670}},testnet:!0}),Ai=Pn({id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc0497E381f536Be9ce14B0dD3817cBcAe57d2F62",blockCreated:16966585},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}});var ji=class extends Error{constructor(){super(...arguments),this.name="ConnectorNotFoundError",this.message="Connector not found"}};function Si(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _n={exports:{}};(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,u,l){this.fn=c,this.context=u,this.once=l||!1}function o(c,u,l,f,d){if(typeof l!="function")throw new TypeError("The listener must be a function");var h=new i(l,f||c,d),g=n?n+u:u;return c._events[g]?c._events[g].fn?c._events[g]=[c._events[g],h]:c._events[g].push(h):(c._events[g]=h,c._eventsCount++),c}function s(c,u){--c._eventsCount===0?c._events=new r:delete c._events[u]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,l;if(this._eventsCount===0)return c;for(l in u=this._events)t.call(u,l)&&c.push(n?l.slice(1):l);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=n?n+c:c,l=this._events[u];if(!l)return[];if(l.fn)return[l.fn];for(var f=0,d=l.length,h=new Array(d);fr.url)]}isChainUnsupported(e){return!this.chains.some(t=>t.id===e)}setStorage(e){this.storage=e}};function Rn(e,{includeName:t=!1}={}){if(e.type!=="function"&&e.type!=="event"&&e.type!=="error")throw new Bi(e.type);return`${e.name}(${kn(e.inputs,{includeName:t})})`}function kn(e,{includeName:t=!1}={}){return e?e.map(n=>_i(n,{includeName:t})).join(t?", ":","):""}function _i(e,{includeName:t}){return e.type.startsWith("tuple")?`(${kn(e.components,{includeName:t})})${e.type.slice(5)}`:e.type+(t&&e.name?` ${e.name}`:"")}class Ri extends v{constructor({docsPath:t}){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(` `),{docsPath:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiConstructorNotFoundError"})}}class Dn extends v{constructor({docsPath:t}){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(` `),{docsPath:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiConstructorParamsNotFoundError"})}}class ki extends v{constructor({expectedLength:t,givenLength:n,type:r}){super([`ABI encoding array length mismatch for type ${r}.`,`Expected length: ${t}`,`Given length: ${n}`].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiEncodingArrayLengthMismatchError"})}}class Di extends v{constructor({expectedSize:t,value:n}){super(`Size of bytes "${n}" (bytes${R(n)}) does not match expected size (bytes${t}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiEncodingBytesSizeMismatchError"})}}class Li extends v{constructor({expectedLength:t,givenLength:n}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${t}`,`Given length (values): ${n}`].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiEncodingLengthMismatchError"})}}class Ln extends v{constructor(t,{docsPath:n}={}){super([`Function ${t?`"${t}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join(` `),{docsPath:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiFunctionNotFoundError"})}}class zi extends v{constructor({expectedSize:t,givenSize:n}){super(`Expected bytes${t}, got bytes${n}.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BytesSizeMismatchError"})}}class $i extends v{constructor(t,{docsPath:n}){super([`Type "${t}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(` `),{docsPath:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiEncodingType"})}}class Fi extends v{constructor(t){super([`Value "${t}" is not a valid array.`].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidArrayError"})}}class Bi extends v{constructor(t){super([`"${t}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join(` `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidDefinitionTypeError"})}}const Ui=/((function|event)\s)?(.*)(\((.*)\))/;function zn(e){const t=e.match(Ui),n=(t==null?void 0:t[2])||void 0,r=t==null?void 0:t[3],i=(t==null?void 0:t[5])||void 0;return{type:n,name:r,params:i}}function Gi(e){return zn(e).name}function qi(e){const t=zn(e).params,n=t==null?void 0:t.split(",").map(r=>r.trim().split(" "));return n==null?void 0:n.map(r=>({type:r[0],name:r[1]==="indexed"?r[2]:r[1],...r[1]==="indexed"?{indexed:!0}:{}}))}function $n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Fn(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Bn(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 Ki(e,t){Fn(e);const n=t.outputLen;if(e.length>Un&it)}:{h:Number(e>>Un&it)|0,l:Number(e&it)|0}}function Vi(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let i=0;ie<>>32-n,Hi=(e,t,n)=>t<>>32-n,Qi=(e,t,n)=>t<>>64-n,Wi=(e,t,n)=>e<>>64-n;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Zi=e=>e instanceof Uint8Array,Xi=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function eo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Gn(e){if(typeof e=="string"&&(e=eo(e)),!Zi(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}class to{clone(){return this._cloneInto()}}function no(e){const t=r=>e().update(Gn(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}const[qn,Kn,Yn]=[[],[],[]],ro=BigInt(0),Se=BigInt(1),io=BigInt(2),oo=BigInt(7),so=BigInt(256),ao=BigInt(113);for(let e=0,t=Se,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],qn.push(2*(5*r+n)),Kn.push((e+1)*(e+2)/2%64);let i=ro;for(let o=0;o<7;o++)t=(t<>oo)*ao)%so,t&io&&(i^=Se<<(Se<n>32?Qi(e,t,n):Ji(e,t,n),Jn=(e,t,n)=>n>32?Wi(e,t,n):Hi(e,t,n);function lo(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let s=0;s<10;s++)n[s]=e[s]^e[s+10]^e[s+20]^e[s+30]^e[s+40];for(let s=0;s<10;s+=2){const a=(s+8)%10,c=(s+2)%10,u=n[c],l=n[c+1],f=Vn(u,l,1)^n[a],d=Jn(u,l,1)^n[a+1];for(let h=0;h<50;h+=10)e[s+h]^=f,e[s+h+1]^=d}let i=e[2],o=e[3];for(let s=0;s<24;s++){const a=Kn[s],c=Vn(i,o,a),u=Jn(i,o,a),l=qn[s];i=e[l],o=e[l+1],e[l]=c,e[l+1]=u}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)n[a]=e[s+a];for(let a=0;a<10;a++)e[s+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=co[r],e[1]^=uo[r]}n.fill(0)}class Ft extends to{constructor(t,n,r,i=!1,o=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,$n(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Xi(this.state)}keccak(){lo(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){Bn(this);const{blockLen:n,state:r}=this;t=Gn(t);const i=t.length;for(let o=0;o=r&&this.keccak();const s=Math.min(r-this.posOut,o-i);t.set(n.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return $n(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Ki(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:i,rounds:o,enableXOF:s}=this;return t||(t=new Ft(n,r,i,s,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=i,t.enableXOF=s,t.destroyed=this.destroyed,t}}const ho=(e,t,n)=>no(()=>new Ft(t,e,n)),fo=ho(1,136,256/8);function Hn(e,t){const n=t||"hex",r=fo(fe(e,{strict:!1})?An(e):e);return n==="bytes"?r:xn(r)}const Qn=e=>Hn(An(e));function Wn(e){const t=Gi(e),n=qi(e)||[];return Qn(`${t}(${n.map(({type:r})=>r).join(",")})`)}function Zn(e){return Qn(Rn(e))}const po=e=>typeof e=="string"?Wn(e):Zn(e);function Xn(e,t,n,{strict:r}={}){return fe(e,{strict:!1})?mo(e,t,n,{strict:r}):go(e,t,n,{strict:r})}function er(e,t){if(typeof t=="number"&&t>0&&t>R(e)-1)throw new En({offset:t,position:"start",size:R(e)})}function tr(e,t,n){if(typeof t=="number"&&typeof n=="number"&&R(e)!==n-t)throw new En({offset:n,position:"end",size:R(e)})}function go(e,t,n,{strict:r}={}){er(e,t);const i=e.slice(t,n);return r&&tr(i,t,n),i}function mo(e,t,n,{strict:r}={}){er(e,t);const i=`0x${e.replace("0x","").slice((t??0)*2,(n??e.length)*2)}`;return r&&tr(i,t,n),i}function nr(e,t){if(e.length!==t.length)throw new Li({expectedLength:e.length,givenLength:t.length});const n=yo({params:e,values:t}),r=Ut(n);return r.length===0?"0x":r}function yo({params:e,values:t}){const n=[];for(let r=0;r0?ve([a,s]):a}}if(i)return{dynamic:!0,encoded:s}}return{dynamic:!1,encoded:ve(o.map(({encoded:s})=>s))}}function wo(e,{param:t}){const[,n]=t.type.split("bytes"),r=R(e);if(!n){let i=e;return r%32!==0&&(i=X(i,{dir:"right",size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:ve([X(M(r,{size:32})),i])}}if(r!==parseInt(n))throw new Di({expectedSize:parseInt(n),value:e});return{dynamic:!1,encoded:X(e,{dir:"right"})}}function Po(e){return{dynamic:!1,encoded:X(On(e))}}function Eo(e,{signed:t}){return{dynamic:!1,encoded:M(e,{size:32,signed:t})}}function Io(e){const t=At(e),n=Math.ceil(R(t)/32),r=[];for(let i=0;ii))}}function Oo(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const rr=e=>Xn(typeof e=="string"?Wn(e):Zn(e),0,4);function Mo({abi:e,args:t=[],name:n}){const r=fe(n,{strict:!1}),i=e.filter(o=>r?o.type==="function"?rr(o)===n:o.type==="event"?po(o)===n:!1:"name"in o&&o.name===n);if(i.length!==0){if(i.length===1)return i[0];for(const o of i)if("inputs"in o){if(!t||t.length===0){if(!o.inputs||o.inputs.length===0)return o;continue}if(!(!o.inputs||o.inputs.length===0||o.inputs.length!==t.length)&&t.every((s,a)=>{const c="inputs"in o&&o.inputs[a];return c?Gt(s,c):!1}))return o}return i[0]}}function Gt(e,t){const n=typeof e,r=t.type;switch(r){case"address":return ye(e);case"bool":return n==="boolean";case"function":return n==="string";case"string":return n==="string";default:return r==="tuple"&&"components"in t?Object.values(t.components).every((i,o)=>Gt(Object.values(e)[o],i)):/^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)?$/.test(r)?n==="number"||n==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(r)?n==="string"||e instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(r)?Array.isArray(e)&&e.every(i=>Gt(i,{...t,type:r.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function ee(e){return typeof e=="string"?{address:e,type:"json-rpc"}:e}function Ao({abi:e,args:t,functionName:n}){let r=e[0];if(n&&(r=Mo({abi:e,args:t,name:n}),!r))throw new Ln(n,{docsPath:"/docs/contract/encodeFunctionData"});if(r.type!=="function")throw new Ln(void 0,{docsPath:"/docs/contract/encodeFunctionData"});const i=Rn(r),o=rr(i),s="inputs"in r&&r.inputs?nr(r.inputs,t??[]):void 0;return zt([o,s??"0x"])}function ir(e,t){const n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Hn(Sn(n),"bytes"),i=(t?n.substring(`${t}0x`.length):n).split("");for(let o=0;o<40;o+=2)r[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(r[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());return`0x${i.join("")}`}function jo(e,t){if(!ye(e))throw new je({address:e});return ir(e,t)}const qt=(e,t,n)=>JSON.stringify(e,(r,i)=>{const o=typeof i=="bigint"?i.toString():i;return typeof t=="function"?t(r,o):o},n);class or extends v{constructor({body:t,details:n,headers:r,status:i,url:o}){super("HTTP request failed.",{details:n,metaMessages:[i&&`Status: ${i}`,`URL: ${vn(o)}`,t&&`Request body: ${qt(t)}`].filter(Boolean)}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"HttpRequestError"}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"url",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.body=t,this.headers=r,this.status=i,this.url=o}}class So extends v{constructor({body:t,error:n,url:r}){super("RPC Request failed.",{cause:n,details:n.message,metaMessages:[`URL: ${vn(r)}`,`Request body: ${qt(t)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"RpcRequestError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.code=n.code}}const To=-1;class k extends v{constructor(t,{code:n,docsPath:r,metaMessages:i,shortMessage:o}){super(o,{cause:t,docsPath:r,metaMessages:i||(t==null?void 0:t.metaMessages)}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"RpcError"}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=t.name,this.code=t instanceof So?t.code:n??To}}class be extends k{constructor(t,n){super(t,n),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ProviderRpcError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=n.data}}class Te extends k{constructor(t){super(t,{code:Te.code,shortMessage:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ParseRpcError"})}}Object.defineProperty(Te,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32700});class Ce extends k{constructor(t){super(t,{code:Ce.code,shortMessage:"JSON is not a valid request object."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidRequestRpcError"})}}Object.defineProperty(Ce,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32600});class Ne extends k{constructor(t){super(t,{code:Ne.code,shortMessage:"The method does not exist / is not available."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"MethodNotFoundRpcError"})}}Object.defineProperty(Ne,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32601});class _e extends k{constructor(t){super(t,{code:_e.code,shortMessage:["Invalid parameters were provided to the RPC method.","Double check you have provided the correct parameters."].join(` `)}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParamsRpcError"})}}Object.defineProperty(_e,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32602});class Re extends k{constructor(t){super(t,{code:Re.code,shortMessage:"An internal error was received."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InternalRpcError"})}}Object.defineProperty(Re,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32603});class ke extends k{constructor(t){super(t,{code:ke.code,shortMessage:["Missing or invalid parameters.","Double check you have provided the correct parameters."].join(` `)}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidInputRpcError"})}}Object.defineProperty(ke,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32e3});class De extends k{constructor(t){super(t,{code:De.code,shortMessage:"Requested resource not found."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceNotFoundRpcError"})}}Object.defineProperty(De,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32001});class Le extends k{constructor(t){super(t,{code:Le.code,shortMessage:"Requested resource not available."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ResourceUnavailableRpcError"})}}Object.defineProperty(Le,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32002});class ze extends k{constructor(t){super(t,{code:ze.code,shortMessage:"Transaction creation failed."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"TransactionRejectedRpcError"})}}Object.defineProperty(ze,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32003});class $e extends k{constructor(t){super(t,{code:$e.code,shortMessage:"Method is not implemented."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"MethodNotSupportedRpcError"})}}Object.defineProperty($e,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32004});class Fe extends k{constructor(t){super(t,{code:Fe.code,shortMessage:"Request exceeds defined limit."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"LimitExceededRpcError"})}}Object.defineProperty(Fe,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32005});class Be extends k{constructor(t){super(t,{code:Be.code,shortMessage:"Version of JSON-RPC protocol is not supported."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"JsonRpcVersionUnsupportedError"})}}Object.defineProperty(Be,"code",{enumerable:!0,configurable:!0,writable:!0,value:-32006});class we extends be{constructor(t){super(t,{code:we.code,shortMessage:"User rejected the request."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UserRejectedRequestError"})}}Object.defineProperty(we,"code",{enumerable:!0,configurable:!0,writable:!0,value:4001});class Ue extends be{constructor(t){super(t,{code:Ue.code,shortMessage:"The requested method and/or account has not been authorized by the user."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnauthorizedProviderError"})}}Object.defineProperty(Ue,"code",{enumerable:!0,configurable:!0,writable:!0,value:4100});class Ge extends be{constructor(t){super(t,{code:Ge.code,shortMessage:"The Provider does not support the requested method."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnsupportedProviderMethodError"})}}Object.defineProperty(Ge,"code",{enumerable:!0,configurable:!0,writable:!0,value:4200});class qe extends be{constructor(t){super(t,{code:qe.code,shortMessage:"The Provider is disconnected from all chains."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ProviderDisconnectedError"})}}Object.defineProperty(qe,"code",{enumerable:!0,configurable:!0,writable:!0,value:4900});class Ke extends be{constructor(t){super(t,{code:Ke.code,shortMessage:"The Provider is not connected to the requested chain."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ChainDisconnectedError"})}}Object.defineProperty(Ke,"code",{enumerable:!0,configurable:!0,writable:!0,value:4901});class ae extends be{constructor(t){super(t,{code:ae.code,shortMessage:"An error occurred when attempting to switch chain."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SwitchChainError"})}}Object.defineProperty(ae,"code",{enumerable:!0,configurable:!0,writable:!0,value:4902});class Co extends k{constructor(t){super(t,{shortMessage:"An unknown RPC error occurred."}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownRpcError"})}}class Pe extends v{constructor({docsPath:t}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the WalletClient."].join(` `),{docsPath:t,docsSlug:"account"}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AccountNotFoundError"})}}class No extends v{constructor(t,{account:n,docsPath:r,chain:i,data:o,gas:s,gasPrice:a,maxFeePerGas:c,maxPriorityFeePerGas:u,nonce:l,to:f,value:d}){const h=$t({from:n==null?void 0:n.address,to:f,value:typeof d<"u"&&`${Nn(d)} ${(i==null?void 0:i.nativeCurrency.symbol)||"ETH"}`,data:o,gas:s,gasPrice:typeof a<"u"&&`${q(a)} gwei`,maxFeePerGas:typeof c<"u"&&`${q(c)} gwei`,maxPriorityFeePerGas:typeof u<"u"&&`${q(u)} gwei`,nonce:l});super(t.shortMessage,{cause:t,docsPath:r,metaMessages:[...t.metaMessages?[...t.metaMessages," "]:[],"Estimate Gas Arguments:",h].filter(Boolean)}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"EstimateGasExecutionError"}),this.cause=t}}function sr(e,t){const n=(e.details||"").toLowerCase(),r=e.walk(i=>i.code===me.code);return r instanceof v?new me({cause:e,message:r.details}):me.nodeMessage.test(n)?new me({cause:e,message:e.details}):nt.nodeMessage.test(n)?new nt({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):St.nodeMessage.test(n)?new St({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas}):Tt.nodeMessage.test(n)?new Tt({cause:e,nonce:t==null?void 0:t.nonce}):Ct.nodeMessage.test(n)?new Ct({cause:e,nonce:t==null?void 0:t.nonce}):Nt.nodeMessage.test(n)?new Nt({cause:e,nonce:t==null?void 0:t.nonce}):_t.nodeMessage.test(n)?new _t({cause:e}):Rt.nodeMessage.test(n)?new Rt({cause:e,gas:t==null?void 0:t.gas}):kt.nodeMessage.test(n)?new kt({cause:e,gas:t==null?void 0:t.gas}):Dt.nodeMessage.test(n)?new Dt({cause:e}):rt.nodeMessage.test(n)?new rt({cause:e,maxFeePerGas:t==null?void 0:t.maxFeePerGas,maxPriorityFeePerGas:t==null?void 0:t.maxPriorityFeePerGas}):new Lt({cause:e})}function _o(e,{docsPath:t,...n}){let r=sr(e,n);return r instanceof Lt&&(r=e),new No(r,{docsPath:t,...n})}function ar(e,{format:t}){return t?Object.keys(t({})).reduce((n,r)=>(e!=null&&e.hasOwnProperty(r)&&(n[r]=e[r]),n),{}):{}}function ot(e){const{account:t,gasPrice:n,maxFeePerGas:r,maxPriorityFeePerGas:i,to:o}=e,s=t?ee(t):void 0;if(s&&!ye(s.address))throw new je({address:s.address});if(o&&!ye(o))throw new je({address:o});if(typeof n<"u"&&(typeof r<"u"||typeof i<"u"))throw new Ei;if(r&&r>2n**256n-1n)throw new nt({maxFeePerGas:r});if(i&&r&&i>r)throw new rt({maxFeePerGas:r,maxPriorityFeePerGas:i})}class Ro extends v{constructor(){super("`baseFeeMultiplier` must be greater than 1."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseFeeScalarError"})}}class Kt extends v{constructor(){super("Chain does not support EIP-1559 fees."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Eip1559FeesNotSupportedError"})}}class ko extends v{constructor({maxPriorityFeePerGas:t}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${q(t)} gwei).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"MaxFeePerGasTooLowError"})}}class Do extends v{constructor({blockHash:t,blockNumber:n}){let r="Block";t&&(r=`Block at hash "${t}"`),n&&(r=`Block at number "${n}"`),super(`${r} could not be found.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BlockNotFoundError"})}}async function st(e,{blockHash:t,blockNumber:n,blockTag:r,includeTransactions:i}={}){var o,s,a;const c=r??"latest",u=i??!1,l=n!==void 0?M(n):void 0;let f=null;if(t?f=await e.request({method:"eth_getBlockByHash",params:[t,u]}):f=await e.request({method:"eth_getBlockByNumber",params:[l||c,u]}),!f)throw new Do({blockHash:t,blockNumber:n});return(((a=(s=(o=e.chain)==null?void 0:o.formatters)==null?void 0:s.block)==null?void 0:a.format)||mi)(f)}async function cr(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function Lo(e,t){var n,r,i;const{block:o,chain:s=e.chain,request:a}=t||{};if(typeof((n=s==null?void 0:s.fees)==null?void 0:n.defaultPriorityFee)=="function"){const c=o||await st(e);return s.fees.defaultPriorityFee({block:c,client:e,request:a})}else if((r=s==null?void 0:s.fees)!=null&&r.defaultPriorityFee)return(i=s==null?void 0:s.fees)==null?void 0:i.defaultPriorityFee;try{const c=await e.request({method:"eth_maxPriorityFeePerGas"});return Tn(c)}catch{const[c,u]=await Promise.all([o?Promise.resolve(o):st(e),cr(e)]);if(typeof c.baseFeePerGas!="bigint")throw new Kt;const l=u-c.baseFeePerGas;return l<0n?0n:l}}async function ur(e,t){var n;const{block:r,chain:i=e.chain,request:o,type:s="eip1559"}=t||{},a=await(async()=>{var f,d;return typeof((f=i==null?void 0:i.fees)==null?void 0:f.baseFeeMultiplier)=="function"?i.fees.baseFeeMultiplier({block:r,client:e,request:o}):((d=i==null?void 0:i.fees)==null?void 0:d.baseFeeMultiplier)??1.2})();if(a<1)throw new Ro;const c=10**a.toString().split(".")[1].length,u=f=>f*BigInt(a*c)/BigInt(c),l=r||await st(e);if(typeof((n=i==null?void 0:i.fees)==null?void 0:n.estimateFeesPerGas)=="function")return i.fees.estimateFeesPerGas({block:r,client:e,multiply:u,request:o,type:s});if(s==="eip1559"){if(typeof l.baseFeePerGas!="bigint")throw new Kt;const f=o!=null&&o.maxPriorityFeePerGas?o.maxPriorityFeePerGas:await Lo(e,{block:l,chain:i,request:o}),d=u(l.baseFeePerGas);return{maxFeePerGas:(o==null?void 0:o.maxFeePerGas)??d+f,maxPriorityFeePerGas:f}}return{gasPrice:(o==null?void 0:o.gasPrice)??u(await cr(e))}}async function zo(e,{address:t,blockTag:n="latest",blockNumber:r}){const i=await e.request({method:"eth_getTransactionCount",params:[t,r?M(r):n]});return tt(i)}async function Yt(e,t){const{account:n=e.account,chain:r,gas:i,nonce:o,type:s}=t;if(!n)throw new Pe;const a=ee(n),c=await st(e,{blockTag:"latest"}),u={...t,from:a.address};if(typeof o>"u"&&(u.nonce=await zo(e,{address:a.address,blockTag:"pending"})),typeof s>"u")try{u.type=Oi(u)}catch{u.type=typeof c.baseFeePerGas=="bigint"?"eip1559":"legacy"}if(u.type==="eip1559"){const{maxFeePerGas:l,maxPriorityFeePerGas:f}=await ur(e,{block:c,chain:r,request:u});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas"u"&&(u.gas=await $o(e,{...u,account:{address:a.address,type:"json-rpc"}})),ot(u),u}async function $o(e,t){var n,r,i;const o=t.account??e.account;if(!o)throw new Pe({docsPath:"/docs/actions/public/estimateGas"});const s=ee(o);try{const{accessList:a,blockNumber:c,blockTag:u,data:l,gas:f,gasPrice:d,maxFeePerGas:h,maxPriorityFeePerGas:g,nonce:m,to:b,value:w,...y}=s.type==="local"?await Yt(e,t):t,A=(c?M(c):void 0)||u;ot(t);const I=((i=(r=(n=e.chain)==null?void 0:n.formatters)==null?void 0:r.transactionRequest)==null?void 0:i.format)||jt,S=I({...ar(y,{format:I}),from:s.address,accessList:a,data:l,gas:f,gasPrice:d,maxFeePerGas:h,maxPriorityFeePerGas:g,nonce:m,to:b,value:w}),L=await e.request({method:"eth_estimateGas",params:A?[S,A]:[S]});return BigInt(L)}catch(a){throw _o(a,{...t,account:s,chain:e.chain})}}async function Fo(e){return new Promise(t=>setTimeout(t,e))}function Bo(e,{docsPath:t,...n}){let r=sr(e,n);return r instanceof Lt&&(r=e),new xi(r,{docsPath:t,...n})}async function at(e){const t=await e.request({method:"eth_chainId"});return tt(t)}async function lr(e,{serializedTransaction:t}){return e.request({method:"eth_sendRawTransaction",params:[t]})}async function Vt(e,t){var n,r,i;const{account:o=e.account,chain:s=e.chain,accessList:a,data:c,gas:u,gasPrice:l,maxFeePerGas:f,maxPriorityFeePerGas:d,nonce:h,to:g,value:m,...b}=t;if(!o)throw new Pe({docsPath:"/docs/actions/wallet/sendTransaction"});const w=ee(o);try{ot(t);let y;if(s!==null&&(y=await at(e),wn({currentChainId:y,chain:s})),w.type==="local"){const S=await Yt(e,{account:w,accessList:a,chain:s,data:c,gas:u,gasPrice:l,maxFeePerGas:f,maxPriorityFeePerGas:d,nonce:h,to:g,value:m,...b});y||(y=await at(e));const L=(n=s==null?void 0:s.serializers)==null?void 0:n.transaction,U=await w.signTransaction({...S,chainId:y},{serializer:L});return await lr(e,{serializedTransaction:U})}const A=((i=(r=s==null?void 0:s.formatters)==null?void 0:r.transactionRequest)==null?void 0:i.format)||jt,I=A({...ar(b,{format:A}),accessList:a,data:c,from:w.address,gas:u,gasPrice:l,maxFeePerGas:f,maxPriorityFeePerGas:d,nonce:h,to:g,value:m});return await e.request({method:"eth_sendTransaction",params:[I]})}catch(y){throw Bo(y,{...t,account:w,chain:t.chain||void 0})}}async function Uo(e,{abi:t,address:n,args:r,dataSuffix:i,functionName:o,...s}){const a=Ao({abi:t,args:r,functionName:o});return await Vt(e,{data:`${a}${i?i.replace("0x",""):""}`,to:n,...s})}async function Go(e,{chain:t}){const{id:n,name:r,nativeCurrency:i,rpcUrls:o,blockExplorers:s}=t;await e.request({method:"wallet_addEthereumChain",params:[{chainId:M(n),chainName:r,nativeCurrency:i,rpcUrls:o.default.http,blockExplorerUrls:s?Object.values(s).map(({url:a})=>a):void 0}]})}const Jt=256;let ct=Jt,ut;function qo(e=11){if(!ut||ct+e>Jt*2){ut="",ct=0;for(let t=0;t{const w=b(m);for(const A in h)delete w[A];const y={...m,...w};return Object.assign(y,{extend:g(y)})}}return Object.assign(h,{extend:g(h)})}function Yo(e,{delay:t=100,retryCount:n=2,shouldRetry:r=()=>!0}={}){return new Promise((i,o)=>{const s=async({count:a=0}={})=>{const c=async({error:u})=>{const l=typeof t=="function"?t({count:a,error:u}):t;l&&await Fo(l),s({count:a+1})};try{const u=await e();i(u)}catch(u){if(a"code"in e?e.code!==-1&&e.code!==-32004&&e.code!==-32005&&e.code!==-32042&&e.code!==-32603:e instanceof or&&e.status?e.status!==403&&e.status!==408&&e.status!==413&&e.status!==429&&e.status!==500&&e.status!==502&&e.status!==503&&e.status!==504:!1;function Jo(e,{retryDelay:t=150,retryCount:n=3}={}){return async r=>Yo(async()=>{try{return await e(r)}catch(i){const o=i;switch(o.code){case Te.code:throw new Te(o);case Ce.code:throw new Ce(o);case Ne.code:throw new Ne(o);case _e.code:throw new _e(o);case Re.code:throw new Re(o);case ke.code:throw new ke(o);case De.code:throw new De(o);case Le.code:throw new Le(o);case ze.code:throw new ze(o);case $e.code:throw new $e(o);case Fe.code:throw new Fe(o);case Be.code:throw new Be(o);case we.code:throw new we(o);case Ue.code:throw new Ue(o);case Ge.code:throw new Ge(o);case qe.code:throw new qe(o);case Ke.code:throw new Ke(o);case ae.code:throw new ae(o);case 5e3:throw new we(o);default:throw i instanceof v?i:new Co(o)}}},{delay:({count:i,error:o})=>{var s;if(o&&o instanceof or){const a=(s=o==null?void 0:o.headers)==null?void 0:s.get("Retry-After");if(a!=null&&a.match(/\d/))return parseInt(a)*1e3}return~~(1<!Vo(i)})}function Ho({key:e,name:t,request:n,retryCount:r=3,retryDelay:i=150,timeout:o,type:s},a){return{config:{key:e,name:t,request:n,retryCount:r,retryDelay:i,timeout:o,type:s},request:Jo(n,{retryCount:r,retryDelay:i}),value:a}}function Qo(e,t={}){const{key:n="custom",name:r="Custom Provider",retryDelay:i}=t;return({retryCount:o})=>Ho({key:n,name:r,request:e.request.bind(e),retryCount:t.retryCount??o,retryDelay:i,type:"custom"})}const Wo=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,Zo=/^(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)?$/;function Xo({domain:e,message:t,primaryType:n,types:r}){const i=r,o=(s,a)=>{for(const c of s){const{name:u,type:l}=c,f=l,d=a[u],h=f.match(Zo);if(h&&(typeof d=="number"||typeof d=="bigint")){const[b,w,y]=h;M(d,{signed:w==="int",size:parseInt(y)/8})}if(f==="address"&&typeof d=="string"&&!ye(d))throw new je({address:d});const g=f.match(Wo);if(g){const[b,w]=g;if(w&&R(d)!==parseInt(w))throw new zi({expectedSize:parseInt(w),givenSize:R(d)})}const m=i[f];m&&o(m,d)}};if(i.EIP712Domain&&e&&o(i.EIP712Domain,e),n!=="EIP712Domain"){const s=i[n];o(s,t)}}function es({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},typeof(e==null?void 0:e.chainId)=="number"&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}const Ht="/docs/contract/encodeDeployData";function ts({abi:e,args:t,bytecode:n}){if(!t||t.length===0)return n;const r=e.find(o=>"type"in o&&o.type==="constructor");if(!r)throw new Ri({docsPath:Ht});if(!("inputs"in r))throw new Dn({docsPath:Ht});if(!r.inputs||r.inputs.length===0)throw new Dn({docsPath:Ht});const i=nr(r.inputs,t);return zt([n,i])}function ns(e,{abi:t,args:n,bytecode:r,...i}){const o=ts({abi:t,args:n,bytecode:r});return Vt(e,{...i,data:o})}async function rs(e){return(await e.request({method:"eth_accounts"})).map(t=>ir(t))}async function is(e){return await e.request({method:"wallet_getPermissions"})}async function os(e){return(await e.request({method:"eth_requestAccounts"})).map(t=>jo(t))}async function ss(e,t){return e.request({method:"wallet_requestPermissions",params:[t]})}async function as(e,{account:t=e.account,message:n}){if(!t)throw new Pe({docsPath:"/docs/actions/wallet/signMessage"});const r=ee(t);if(r.type==="local")return r.signMessage({message:n});const i=(()=>typeof n=="string"?At(n):n.raw instanceof Uint8Array?xn(n.raw):n.raw)();return e.request({method:"personal_sign",params:[i,r.address]})}async function cs(e,t){var n,r,i,o;const{account:s=e.account,chain:a=e.chain,...c}=t;if(!s)throw new Pe({docsPath:"/docs/actions/wallet/signTransaction"});const u=ee(s);ot({account:u,...t});const l=await at(e);a!==null&&wn({currentChainId:l,chain:a});const f=(a==null?void 0:a.formatters)||((n=e.chain)==null?void 0:n.formatters),d=((r=f==null?void 0:f.transactionRequest)==null?void 0:r.format)||jt;return u.type==="local"?u.signTransaction({chainId:l,...c},{serializer:(o=(i=e.chain)==null?void 0:i.serializers)==null?void 0:o.transaction}):await e.request({method:"eth_signTransaction",params:[{...d(c),chainId:M(l),from:u.address}]})}async function us(e,{account:t=e.account,domain:n,message:r,primaryType:i,types:o}){if(!t)throw new Pe({docsPath:"/docs/actions/wallet/signTypedData"});const s=ee(t),a={EIP712Domain:es({domain:n}),...o};if(Xo({domain:n,message:r,primaryType:i,types:a}),s.type==="local")return s.signTypedData({domain:n,primaryType:i,types:a,message:r});const c=qt({domain:n??{},primaryType:i,types:a,message:r},(u,l)=>fe(l)?l.toLowerCase():l);return e.request({method:"eth_signTypedData_v4",params:[s.address,c]})}async function ls(e,{id:t}){await e.request({method:"wallet_switchEthereumChain",params:[{chainId:M(t)}]})}async function ds(e,t){return await e.request({method:"wallet_watchAsset",params:t})}function hs(e){return{addChain:t=>Go(e,t),deployContract:t=>ns(e,t),getAddresses:()=>rs(e),getChainId:()=>at(e),getPermissions:()=>is(e),prepareTransactionRequest:t=>Yt(e,t),requestAddresses:()=>os(e),requestPermissions:t=>ss(e,t),sendRawTransaction:t=>lr(e,t),sendTransaction:t=>Vt(e,t),signMessage:t=>as(e,t),signTransaction:t=>cs(e,t),signTypedData:t=>us(e,t),switchChain:t=>ls(e,t),watchAsset:t=>ds(e,t),writeContract:t=>Uo(e,t)}}function fs(e){const{key:t="wallet",name:n="Wallet Client",transport:r}=e;return Ko({...e,key:t,name:n,transport:i=>r({...i,retryCount:0}),type:"walletClient"}).extend(hs)}function E(e,t,n,r){function i(o){return o instanceof n?o:new n(function(s){s(o)})}return new(n||(n=Promise))(function(o,s){function a(l){try{u(r.next(l))}catch(f){s(f)}}function c(l){try{u(r.throw(l))}catch(f){s(f)}}function u(l){l.done?o(l.value):i(l.value).then(a,c)}u((r=r.apply(e,t||[])).next())})}function O(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)}function Ee(e,t){if(!e)throw new Error(t)}var K;(function(e){e.prod="BLOCTO_SDK",e.dev="BLOCTO_SDK_DEV",e.staging="BLOCTO_SDK_STAGING"})(K||(K={}));var j;(function(e){e.ETHEREUM="ethereum",e.APTOS="aptos"})(j||(j={}));const Qt={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545",137:"https://rpc-mainnet.maticvigil.com/",80001:"https://rpc-mumbai.matic.today/",43114:"https://api.avax.network/ext/bc/C/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",42161:"https://arb1.arbitrum.io/rpc",421613:"https://endpoints.omniatech.io/v1/arbitrum/goerli/public",421614:"https://arbitrum-sepolia.blockpi.network/v1/rpc/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io",11155420:"https://sepolia.optimism.io",8453:"https://mainnet.base.org",84531:"https://goerli.base.org",84532:"https://sepolia.base.org",7777777:"https://rpc.zora.energy",999:"https://testnet.rpc.zora.energy",999999999:"https://sepolia.rpc.zora.energy",534352:"https://rpc.scroll.io",534353:"https://alpha-rpc.scroll.io/l2",534351:"https://sepolia-rpc.scroll.io",59144:"https://rpc.linea.build",59140:"https://rpc.goerli.linea.build",1261120:"https://rpc.startale.com/zkatana"},dr={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},ps={prod:K.prod,staging:K.staging,dev:K.dev},gs={1:K.prod,2:K.dev,3:K.dev,4:K.dev,5:K.staging},ms={1:"https://wallet-v2.blocto.app",2:"https://wallet-v2-dev.blocto.app",3:"https://wallet-v2-dev.blocto.app",4:"https://wallet-v2-dev.blocto.app",5:"https://wallet-v2-staging.blocto.app"};var ce;(function(e){e.Mainnet="mainnet",e.Testnet="testnet",e.Devnet="devnet",e.Testing="testing",e.Premainnet="premainnet"})(ce||(ce={}));const ys={1:ce.Mainnet,2:ce.Testnet,3:ce.Devnet,4:ce.Testing,5:ce.Premainnet},vs={1:"https://fullnode.mainnet.aptoslabs.com/v1",2:"https://fullnode.testnet.aptoslabs.com/v1",3:"https://fullnode.devnet.aptoslabs.com/v1",4:"",5:"https://premainnet.aptosdev.com/v1"},hr=["connect","disconnect","message","chainChanged","accountsChanged"],bs=86400*1e3,Wt="00000000-0000-0000-0000-000000000000",lt="0.9.1";class fr{constructor(){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.off=this.removeListener,hr.forEach(t=>{this.eventListeners[t]=[]}),this.appId=Wt}request(t){return E(this,void 0,void 0,function*(){})}on(t,n){hr.includes(t)&&this.eventListeners[t].push(n)}once(){}removeListener(t,n){const r=this.eventListeners[t].findIndex(i=>i===n);r!==-1&&this.eventListeners[t].splice(r,1)}}const ws="width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;box-sizing:border-box;color-scheme:light;inset:0px;display:block;pointer-events:auto;";function dt(e){const t=document.createElement("iframe");return t.setAttribute("src",e),t.setAttribute("style",ws),t}function ht(e){document.body.appendChild(e)}function z(e){const t=e&&e.parentNode;t&&t.removeChild instanceof Function&&t.removeChild(e)}var te=(e,t,n=window)=>{function r(i){t(i,()=>n.removeEventListener(e,r))}n.addEventListener(e,r)};const Ps=()=>{if(typeof window>"u")return!1;try{window.sessionStorage.setItem("local_storage_supported","1");const e=window.sessionStorage.getItem("local_storage_supported");return window.sessionStorage.removeItem("local_storage_supported"),e==="1"}catch{return!1}};class Es{constructor(){this.storage={}}getItem(t){return this[t]||null}setItem(t,n){this.storage[t]=n}removeItem(t){delete this.storage[t]}}const Is=typeof window<"u"?window.memoryStorage:new Es,Zt=Ps()?window.sessionStorage:Is,Xt=(e,t=null)=>{const n=Zt.getItem(e);try{return n&&JSON.parse(n)||t}catch{return n||t}},en=(e,t)=>Zt.setItem(e,typeof t=="string"?t:JSON.stringify(t)),ft=e=>{en(e,""),Zt.removeItem(e)},ne=e=>{const t=Xt(e,null);return t?new Date().getTime()>t.expiry||t.v!==lt?(ft(e),null):t==null?void 0:t.data:null},Ie=(e,t,n)=>{var r,i,o;const s=Xt(e),a={data:{code:(t==null?void 0:t.code)||((r=s==null?void 0:s.data)===null||r===void 0?void 0:r.code),accounts:Object.assign(Object.assign({},(i=s==null?void 0:s.data)===null||i===void 0?void 0:i.accounts),t==null?void 0:t.accounts),evm:Object.assign(Object.assign({},(o=s==null?void 0:s.data)===null||o===void 0?void 0:o.evm),t==null?void 0:t.evm)},expiry:n||(s==null?void 0:s.expiry)||new Date().getTime()+bs,v:lt};en(e,a)},Y=(e,t)=>{var n,r,i;return!((n=ne(e))===null||n===void 0)&&n.code?((i=(r=ne(e))===null||r===void 0?void 0:r.accounts)===null||i===void 0?void 0:i[t])||null:(ft(e),null)},xs=(e,t,n)=>{Ie(e,{accounts:{[t]:n}})},Os=(e,t)=>{Ie(e,{accounts:{[t]:void 0}})},Ye=(e,t)=>{var n,r,i;return!((n=ne(e))===null||n===void 0)&&n.code?((i=(r=ne(e))===null||r===void 0?void 0:r.evm)===null||i===void 0?void 0:i[t])||null:(ft(e),null)},pr=(e,t,n)=>{Ie(e,{evm:{[t]:n}})},gr=e=>{const t=Xt(e);t&&(t.data.evm={},en(e,t))};function pt(e,t,n){return E(this,void 0,void 0,function*(){if((e.status===403||e.status===401)&&(n&&n(),ft(t)),!e.ok){const r=yield e.json(),i=new Error((r==null?void 0:r.message)||"unknown error");throw i.error_code=r==null?void 0:r.error_code,i}return e.json()})}const mr=e=>/\S+@\S+\.\S+/.test(e);var Ve;(function(e){e.INVALID_TRANSACTION="Invalid transaction",e.INVALID_TRANSACTIONS="Invalid transactions",e.INVALID_TRANSACTION_VALUE='Transaction params "value" should be hex-encoded string'})(Ve||(Ve={}));var yr=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},V=[],F=[],Ms=typeof Uint8Array<"u"?Uint8Array:Array,tn=!1;function vr(){tn=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,n=e.length;t0)throw new Error("Invalid string. Length must be a multiple of 4");o=e[a-2]==="="?2:e[a-1]==="="?1:0,s=new Ms(a*3/4-o),r=o>0?a-4:a;var c=0;for(t=0,n=0;t>16&255,s[c++]=i>>8&255,s[c++]=i&255;return o===2?(i=F[e.charCodeAt(t)]<<2|F[e.charCodeAt(t+1)]>>4,s[c++]=i&255):o===1&&(i=F[e.charCodeAt(t)]<<10|F[e.charCodeAt(t+1)]<<4|F[e.charCodeAt(t+2)]>>2,s[c++]=i>>8&255,s[c++]=i&255),s}function js(e){return V[e>>18&63]+V[e>>12&63]+V[e>>6&63]+V[e&63]}function Ss(e,t,n){for(var r,i=[],o=t;oc?c:a+s));return r===1?(t=e[n-1],i+=V[t>>2],i+=V[t<<4&63],i+="=="):r===2&&(t=(e[n-2]<<8)+e[n-1],i+=V[t>>10],i+=V[t>>4&63],i+=V[t<<2&63],i+="="),o.push(i),o.join("")}function gt(e,t,n,r,i){var o,s,a=i*8-r-1,c=(1<>1,l=-7,f=n?i-1:0,d=n?-1:1,h=e[t+f];for(f+=d,o=h&(1<<-l)-1,h>>=-l,l+=a;l>0;o=o*256+e[t+f],f+=d,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=s*256+e[t+f],f+=d,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,r),o=o-u}return(h?-1:1)*s*Math.pow(2,o-r)}function wr(e,t,n,r,i,o){var s,a,c,u=o*8-i-1,l=(1<>1,d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:o-1,g=r?1:-1,m=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+f>=1?t+=d/c:t+=d*Math.pow(2,1-f),t*c>=2&&(s++,c/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(t*c-1)*Math.pow(2,i),s=s+f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;e[n+h]=a&255,h+=g,a/=256,i-=8);for(s=s<0;e[n+h]=s&255,h+=g,s/=256,u-=8);e[n+h-g]|=m*128}var Ts={}.toString,Pr=Array.isArray||function(e){return Ts.call(e)=="[object Array]"};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */var Cs=50;p.TYPED_ARRAY_SUPPORT=yr.TYPED_ARRAY_SUPPORT!==void 0?yr.TYPED_ARRAY_SUPPORT:!0,mt();function mt(){return p.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Q(e,t){if(mt()=mt())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+mt().toString(16)+" bytes");return e|0}p.isBuffer=ta;function J(e){return!!(e!=null&&e._isBuffer)}p.compare=function(e,t){if(!J(e)||!J(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i>>1;case"base64":return _r(e).length;default:if(r)return bt(e).length;t=(""+t).toLowerCase(),r=!0}}p.byteLength=xr;function Ds(e,t,n){var r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Ys(this,t,n);case"utf8":case"utf-8":return jr(this,t,n);case"ascii":return qs(this,t,n);case"latin1":case"binary":return Ks(this,t,n);case"base64":return Us(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Vs(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}p.prototype._isBuffer=!0;function ue(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}p.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},p.prototype.compare=function(e,t,n,r,i){if(!J(e))throw new TypeError("Argument must be a Buffer");if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;for(var o=i-r,s=n-t,a=Math.min(o,s),c=this.slice(r,i),u=e.slice(t,n),l=0;l2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0)if(i)n=0;else return-1;if(typeof t=="string"&&(t=p.from(t,r)),J(t))return t.length===0?-1:Mr(e,t,n,r,i);if(typeof t=="number")return t=t&255,p.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):Mr(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function Mr(e,t,n,r,i){var o=1,s=e.length,a=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(e.length<2||t.length<2)return-1;o=2,s/=2,a/=2,n/=2}function c(h,g){return o===1?h[g]:h.readUInt16BE(g*o)}var u;if(i){var l=-1;for(u=n;us&&(n=s-a),u=n;u>=0;u--){for(var f=!0,d=0;di&&(r=i)):r=i;var o=t.length;if(o%2!==0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;si)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return Ls(this,e,t,n);case"utf8":case"utf-8":return zs(this,e,t,n);case"ascii":return Ar(this,e,t,n);case"latin1":case"binary":return $s(this,e,t,n);case"base64":return Fs(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Bs(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},p.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Us(e,t,n){return t===0&&n===e.length?br(e):br(e.slice(t,n))}function jr(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i239?4:o>223?3:o>191?2:1;if(i+a<=n){var c,u,l,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=e[i+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=e[i+1],u=e[i+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=e[i+1],u=e[i+2],l=e[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),i+=a}return Gs(r)}var Sr=4096;function Gs(e){var t=e.length;if(t<=Sr)return String.fromCharCode.apply(String,e);for(var n="",r=0;rr)&&(n=r);for(var i="",o=t;on&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),tn)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUIntLE=function(e,t,n){e=e|0,t=t|0,n||T(e,t,this.length);for(var r=this[e],i=1,o=0;++o0&&(i*=256);)r+=this[e+--t]*i;return r},p.prototype.readUInt8=function(e,t){return t||T(e,1,this.length),this[e]},p.prototype.readUInt16LE=function(e,t){return t||T(e,2,this.length),this[e]|this[e+1]<<8},p.prototype.readUInt16BE=function(e,t){return t||T(e,2,this.length),this[e]<<8|this[e+1]},p.prototype.readUInt32LE=function(e,t){return t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},p.prototype.readUInt32BE=function(e,t){return t||T(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},p.prototype.readIntLE=function(e,t,n){e=e|0,t=t|0,n||T(e,t,this.length);for(var r=this[e],i=1,o=0;++o=i&&(r-=Math.pow(2,8*t)),r},p.prototype.readIntBE=function(e,t,n){e=e|0,t=t|0,n||T(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},p.prototype.readInt8=function(e,t){return t||T(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},p.prototype.readInt16LE=function(e,t){t||T(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},p.prototype.readInt16BE=function(e,t){t||T(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},p.prototype.readInt32LE=function(e,t){return t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},p.prototype.readInt32BE=function(e,t){return t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},p.prototype.readFloatLE=function(e,t){return t||T(e,4,this.length),gt(this,e,!0,23,4)},p.prototype.readFloatBE=function(e,t){return t||T(e,4,this.length),gt(this,e,!1,23,4)},p.prototype.readDoubleLE=function(e,t){return t||T(e,8,this.length),gt(this,e,!0,52,8)},p.prototype.readDoubleBE=function(e,t){return t||T(e,8,this.length),gt(this,e,!1,52,8)};function D(e,t,n,r,i,o){if(!J(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}p.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t=t|0,n=n|0,!r){var i=Math.pow(2,8*n)-1;D(this,e,t,n,i,0)}var o=1,s=0;for(this[t]=e&255;++s=0&&(s*=256);)this[t+o]=e/s&255;return t+n},p.prototype.writeUInt8=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,1,255,0),p.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=e&255,t+1};function yt(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i>>(r?i:1-i)*8}p.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,2,65535,0),p.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):yt(this,e,t,!0),t+2},p.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,2,65535,0),p.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):yt(this,e,t,!1),t+2};function vt(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i>>(r?i:3-i)*8&255}p.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,4,4294967295,0),p.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255):vt(this,e,t,!0),t+4},p.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,4,4294967295,0),p.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):vt(this,e,t,!1),t+4},p.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t=t|0,!r){var i=Math.pow(2,8*n-1);D(this,e,t,n,i-1,-i)}var o=0,s=1,a=0;for(this[t]=e&255;++o>0)-a&255;return t+n},p.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t=t|0,!r){var i=Math.pow(2,8*n-1);D(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},p.prototype.writeInt8=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,1,127,-128),p.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=e&255,t+1},p.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,2,32767,-32768),p.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):yt(this,e,t,!0),t+2},p.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,2,32767,-32768),p.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):yt(this,e,t,!1),t+2},p.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,4,2147483647,-2147483648),p.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):vt(this,e,t,!0),t+4},p.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t|0,n||D(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),p.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):vt(this,e,t,!1),t+4};function Tr(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Cr(e,t,n,r,i){return i||Tr(e,t,n,4),wr(e,t,n,r,23,4),n+4}p.prototype.writeFloatLE=function(e,t,n){return Cr(this,e,t,!0,n)},p.prototype.writeFloatBE=function(e,t,n){return Cr(this,e,t,!1,n)};function Nr(e,t,n,r,i){return i||Tr(e,t,n,8),wr(e,t,n,r,52,8),n+8}p.prototype.writeDoubleLE=function(e,t,n){return Nr(this,e,t,!0,n)},p.prototype.writeDoubleBE=function(e,t,n){return Nr(this,e,t,!1,n)},p.prototype.copy=function(e,t,n,r){if(n||(n=0),!r&&r!==0&&(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t=0;--o)e[o+t]=this[o+n];else if(i<1e3||!p.TYPED_ARRAY_SUPPORT)for(o=0;o>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var o;if(typeof e=="number")for(o=t;o55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return o}function Zs(e){for(var t=[],n=0;n>8,i=n%256,o.push(i),o.push(r);return o}function _r(e){return As(Hs(e))}function wt(e,t,n,r){for(var i=0;i=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function ea(e){return e!==e}function ta(e){return e!=null&&(!!e._isBuffer||Rr(e)||na(e))}function Rr(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function na(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&Rr(e.slice(0,0))}const sn=e=>typeof e=="string"&&/^0x[0-9A-Fa-f]*$/.test(e),ra=e=>p.from(e,"utf8").toString("hex"),kr=e=>!e||typeof e!="object"||!("from"in e)?{isValid:!1,invalidMsg:Ve.INVALID_TRANSACTION}:e.value&&!sn(e.value)?{isValid:!1,invalidMsg:Ve.INVALID_TRANSACTION_VALUE}:{isValid:!0},ia=e=>{if(!Array.isArray(e))return{isValid:!1,invalidMsg:Ve.INVALID_TRANSACTIONS};for(let t=0;tt.json());return e.reduce((t,n)=>Object.assign(Object.assign({},t),{[n.chain_id]:n}),{})})}var P={};function Dr(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function $(e){"@babel/helpers - typeof";return $=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$(e)}function oa(e,t){if($(e)!=="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if($(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function sa(e){var t=oa(e,"string");return $(t)==="symbol"?t:String(t)}function Lr(e,t){for(var n=0;n"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Pt(e,t,n){return la()?Pt=Reflect.construct.bind():Pt=function(r,i,o){var s=[null];s.push.apply(s,i);var a=Function.bind.apply(r,s),c=new a;return o&&Je(c,o.prototype),c},Pt.apply(null,arguments)}function cn(e){var t=typeof Map=="function"?new Map:void 0;return cn=function(n){if(n===null||!ua(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return Pt(n,arguments,He(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Je(r,n)},cn(e)}var re={},da=Qe;Qe.default=Qe,Qe.stable=Ur,Qe.stableStringify=Ur;var Et="[...]",Fr="[Circular]",le=[],de=[];function Br(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function Qe(e,t,n,r){typeof r>"u"&&(r=Br()),un(e,"",0,[],void 0,0,r);var i;try{de.length===0?i=JSON.stringify(e,t,n):i=JSON.stringify(e,Gr(t),n)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;le.length!==0;){var o=le.pop();o.length===4?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function xe(e,t,n,r){var i=Object.getOwnPropertyDescriptor(r,n);i.get!==void 0?i.configurable?(Object.defineProperty(r,n,{value:e}),le.push([r,n,t,i])):de.push([t,n,e]):(r[n]=e,le.push([r,n,t]))}function un(e,t,n,r,i,o,s){o+=1;var a;if($(e)==="object"&&e!==null){for(a=0;as.depthLimit){xe(Et,e,t,i);return}if(typeof s.edgesLimit<"u"&&n+1>s.edgesLimit){xe(Et,e,t,i);return}if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Ur(e,t,n,r){typeof r>"u"&&(r=Br());var i=ln(e,"",0,[],void 0,0,r)||e,o;try{de.length===0?o=JSON.stringify(i,t,n):o=JSON.stringify(i,Gr(t),n)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;le.length!==0;){var s=le.pop();s.length===4?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function ln(e,t,n,r,i,o,s){o+=1;var a;if($(e)==="object"&&e!==null){for(a=0;as.depthLimit){xe(Et,e,t,i);return}if(typeof s.edgesLimit<"u"&&n+1>s.edgesLimit){xe(Et,e,t,i);return}if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}Object.defineProperty(re,"__esModule",{value:!0}),re.EthereumProviderError=re.EthereumRpcError=void 0;var pa=da,Kr=function(e){$r(n,e);var t=qr(n);function n(r,i,o){var s;if(Dr(this,n),!Number.isInteger(r))throw new Error('"code" must be an integer.');if(!i||typeof i!="string")throw new Error('"message" must be a nonempty string.');return s=t.call(this,i),s.code=r,o!==void 0&&(s.data=o),s}return zr(n,[{key:"serialize",value:function(){var r={code:this.code,message:this.message};return this.data!==void 0&&(r.data=this.data),this.stack&&(r.stack=this.stack),r}},{key:"toString",value:function(){return pa.default(this.serialize(),ya,2)}}]),n}(cn(Error));re.EthereumRpcError=Kr;var ga=function(e){$r(n,e);var t=qr(n);function n(r,i,o){if(Dr(this,n),!ma(r))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');return t.call(this,r,i,o)}return zr(n)}(Kr);re.EthereumProviderError=ga;function ma(e){return Number.isInteger(e)&&e>=1e3&&e<=4999}function ya(e,t){if(t!=="[Circular]")return t}var dn={},ie={};Object.defineProperty(ie,"__esModule",{value:!0}),ie.errorValues=ie.errorCodes=void 0,ie.errorCodes={rpc:{invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},provider:{userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901}},ie.errorValues={"-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."}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.serializeError=e.isValidCode=e.getMessageFromCode=e.JSON_RPC_SERVER_ERROR_MESSAGE=void 0;var t=ie,n=re,r=t.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:r,message:s(r)};e.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.";function s(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:i;if(Number.isInteger(d)){var g=d.toString();if(f(t.errorValues,g))return t.errorValues[g].message;if(u(d))return e.JSON_RPC_SERVER_ERROR_MESSAGE}return h}e.getMessageFromCode=s;function a(d){if(!Number.isInteger(d))return!1;var h=d.toString();return!!(t.errorValues[h]||u(d))}e.isValidCode=a;function c(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},g=h.fallbackError,m=g===void 0?o:g,b=h.shouldIncludeStack,w=b===void 0?!1:b,y,A;if(!m||!Number.isInteger(m.code)||typeof m.message!="string")throw new Error("Must provide fallback error with integer number code and string message.");if(d instanceof n.EthereumRpcError)return d.serialize();var I={};if(d&&$(d)==="object"&&!Array.isArray(d)&&f(d,"code")&&a(d.code)){var S=d;I.code=S.code,S.message&&typeof S.message=="string"?(I.message=S.message,f(S,"data")&&(I.data=S.data)):(I.message=s(I.code),I.data={originalError:l(d)})}else{I.code=m.code;var L=(y=d)===null||y===void 0?void 0:y.message;I.message=L&&typeof L=="string"?L:m.message,I.data={originalError:l(d)}}var U=(A=d)===null||A===void 0?void 0:A.stack;return w&&d&&U&&typeof U=="string"&&(I.stack=U),I}e.serializeError=c;function u(d){return d>=-32099&&d<=-32e3}function l(d){return d&&$(d)==="object"&&!Array.isArray(d)?Object.assign({},d):d}function f(d,h){return Object.prototype.hasOwnProperty.call(d,h)}}(dn);function va(e){if(Array.isArray(e))return e}function ba(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,i,o,s,a=[],c=!0,u=!1;try{if(o=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);c=!0);}catch(l){u=!0,i=l}finally{try{if(!c&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}function Yr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n-32005||t<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return B(t,e)},invalidInput:function(e){return B(C.errorCodes.rpc.invalidInput,e)},resourceNotFound:function(e){return B(C.errorCodes.rpc.resourceNotFound,e)},resourceUnavailable:function(e){return B(C.errorCodes.rpc.resourceUnavailable,e)},transactionRejected:function(e){return B(C.errorCodes.rpc.transactionRejected,e)},methodNotSupported:function(e){return B(C.errorCodes.rpc.methodNotSupported,e)},limitExceeded:function(e){return B(C.errorCodes.rpc.limitExceeded,e)}},provider:{userRejectedRequest:function(e){return We(C.errorCodes.provider.userRejectedRequest,e)},unauthorized:function(e){return We(C.errorCodes.provider.unauthorized,e)},unsupportedMethod:function(e){return We(C.errorCodes.provider.unsupportedMethod,e)},disconnected:function(e){return We(C.errorCodes.provider.disconnected,e)},chainDisconnected:function(e){return We(C.errorCodes.provider.chainDisconnected,e)},custom:function(e){if(!e||$(e)!=="object"||Array.isArray(e))throw new Error("Ethereum Provider custom errors must provide single object argument.");var t=e.code,n=e.message,r=e.data;if(!n||typeof n!="string")throw new Error('"message" must be a nonempty string');return new hn.EthereumProviderError(t,n,r)}}};function B(e,t){var n=Hr(t),r=Vr(n,2),i=r[0],o=r[1];return new hn.EthereumRpcError(e,i||Jr.getMessageFromCode(e),o)}function We(e,t){var n=Hr(t),r=Vr(n,2),i=r[0],o=r[1];return new hn.EthereumProviderError(e,i||Jr.getMessageFromCode(e),o)}function Hr(e){if(e){if(typeof e=="string")return[e];if($(e)==="object"&&!Array.isArray(e)){var t=e.message,n=e.data;if(t&&typeof t!="string")throw new Error("Must specify string message.");return[t||void 0,n]}}return[]}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getMessageFromCode=e.serializeError=e.EthereumProviderError=e.EthereumRpcError=e.ethErrors=e.errorCodes=void 0;var t=re;Object.defineProperty(e,"EthereumRpcError",{enumerable:!0,get:function(){return t.EthereumRpcError}}),Object.defineProperty(e,"EthereumProviderError",{enumerable:!0,get:function(){return t.EthereumProviderError}});var n=dn;Object.defineProperty(e,"serializeError",{enumerable:!0,get:function(){return n.serializeError}}),Object.defineProperty(e,"getMessageFromCode",{enumerable:!0,get:function(){return n.getMessageFromCode}});var r=It;Object.defineProperty(e,"ethErrors",{enumerable:!0,get:function(){return r.ethErrors}});var i=ie;Object.defineProperty(e,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})})(P);var x,_,Qr,oe,fn;function N(e){return e?typeof e=="number"?e:e.startsWith("0x")?parseInt(e,16):parseInt(e,10):1}class Ea extends fr{get existedSDK(){if(!(typeof window>"u"))return window.ethereum}constructor(t){var n;if(super(),x.add(this),this.networkVersion="1",this.off=this.removeListener,this.injectedWalletServer=t.walletServer,this._blocto={sessionKeyEnv:K.prod,walletServer:this.injectedWalletServer||"",blockchainName:"",networkType:"",switchableNetwork:{}},this.appId=t.appId||Wt,"chainId"in t){const{chainId:r,rpc:i}=t;Ee(r,"'chainId' is required"),this.networkVersion=`${N(r)}`,this.chainId=`0x${N(r).toString(16)}`,this.rpc=i||Qt[this.networkVersion],Ee(this.rpc,"'rpc' is required")}else{const{defaultChainId:r,switchableChains:i}=t;Ee(r,"'defaultChainId' is required"),this.networkVersion=`${N(r)}`,this.chainId=`0x${N(r).toString(16)}`;const o=i.find(s=>N(s.chainId)===N(r));if(!o)throw P.ethErrors.provider.custom({code:1001,message:`Chain ${r} is not in switchableChains list`});this.rpc=((n=o.rpcUrls)===null||n===void 0?void 0:n[0])||Qt[this.networkVersion],Ee(this.rpc,"'rpc' is required"),this._blocto.unloadedNetwork=i}}send(t,n){return E(this,void 0,void 0,function*(){switch(!0){case n instanceof Function:return this.sendAsync(t,n);case(typeof t=="string"&&Array.isArray(n)):return this.sendAsync({jsonrpc:"2.0",method:t,params:n});default:return this.sendAsync(t)}})}sendAsync(t,n){return E(this,void 0,void 0,function*(){const r=a=>a.reduce((c,u)=>{var l;return u.method==="eth_sendTransaction"?c.sendRequests.push((l=u.params)===null||l===void 0?void 0:l[0]):c.otherRequests.push(this.request(u)),c},{sendRequests:[],otherRequests:[]});function i(a){return{id:String(a.id),jsonrpc:"2.0",method:a.method}}function o(a,c){const u=[];let l=1;return a.forEach(f=>{const d=i(f);f.method==="eth_sendTransaction"?(d.result=c[0].value,d.error=c[0].status!=="fulfilled"?c[0].reason:void 0):l{if(Array.isArray(t)){const{sendRequests:c,otherRequests:u}=r(t),l={method:"wallet_sendMultiCallTransaction",params:[c,!1]},f=c.length===0,d=Math.floor(Math.random()*1e4),h=f?[...u]:[this.request(l),...u];Promise.allSettled(h).then(g=>{if(f)return a(g.map((b,w)=>{var y;return{id:String(((y=t[w])===null||y===void 0?void 0:y.id)||d+w+1),jsonrpc:"2.0",method:t[w].method,result:b.status==="fulfilled"?b.value:void 0,error:b.status!=="fulfilled"?b.reason:void 0}}));const m=o(t,g);return a(m)}).catch(g=>{throw P.ethErrors.rpc.internal(g==null?void 0:g.message)})}else this.request(Object.assign(Object.assign({},t),{id:Number(t.id)})).then(a)});if(typeof n=="function")s.then(a=>n(null,a)).catch(a=>n(a));else return s})}sendUserOperation(t){return E(this,void 0,void 0,function*(){return this.request({method:"eth_sendUserOperation",params:[t]})})}request(t){var n,r,i,o,s,a,c,u;return E(this,void 0,void 0,function*(){if(Array.isArray(t))return this.sendAsync(t);if(!(t!=null&&t.method))throw P.ethErrors.rpc.invalidRequest();const{blockchainName:l,switchableNetwork:f,sessionKeyEnv:d}=yield O(this,x,"m",_).call(this);if(!((n=this.existedSDK)===null||n===void 0)&&n.isBlocto){if(t.method==="wallet_switchEthereumChain"){if(!(!((i=(r=t==null?void 0:t.params)===null||r===void 0?void 0:r[0])===null||i===void 0)&&i.chainId))throw P.ethErrors.rpc.invalidParams();return this.existedSDK.request(t).then(()=>{var h,g,m;return this.networkVersion=`${N((h=t==null?void 0:t.params)===null||h===void 0?void 0:h[0].chainId)}`,this.chainId=`0x${N((g=t==null?void 0:t.params)===null||g===void 0?void 0:g[0].chainId).toString(16)}`,this.rpc=(m=f==null?void 0:f[this.networkVersion])===null||m===void 0?void 0:m.rpc_url,null})}return this.existedSDK.request(t)}switch(t.method){case"eth_chainId":return this.chainId;case"net_version":return this.networkVersion;case"wallet_addEthereumChain":return this.loadSwitchableNetwork((t==null?void 0:t.params)||[]);case"eth_blockNumber":case"web3_clientVersion":case"eth_call":{const h=yield this.handleReadRequests(t);if(!h||h&&!h.result&&h.error){const g=!((o=h==null?void 0:h.error)===null||o===void 0)&&o.message?h.error.message:"Request failed";throw P.ethErrors.rpc.internal(g)}return typeof(t==null?void 0:t.callback)=="function"&&t.callback(null,h.result),h.result}case"wallet_switchEthereumChain":return this.handleSwitchChain((a=(s=t==null?void 0:t.params)===null||s===void 0?void 0:s[0])===null||a===void 0?void 0:a.chainId);case"wallet_disconnect":return this.handleDisconnect();case"eth_accounts":return Ye(d,l)||[]}if(!Ye(d,l)){const h=(c=t==null?void 0:t.params)===null||c===void 0?void 0:c[0];t.method==="eth_requestAccounts"&&mr(h)?yield this.enable(h):yield this.enable()}try{let h=null,g=null;switch(t.method){case"eth_requestAccounts":{g=yield this.fetchAccounts();break}case"eth_coinbase":{g=(u=Ye(d,l))===null||u===void 0?void 0:u[0];break}case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":{g=yield this.handleSign(t);break}case"eth_sign":throw P.ethErrors.rpc.methodNotFound("Method Not Supported: eth_sign has been disabled");case"eth_sendTransaction":g=yield this.handleSendTransaction(t);break;case"wallet_sendMultiCallTransaction":g=yield this.handleSendBatchTransaction(t);break;case"eth_signTransaction":case"eth_sendRawTransaction":throw P.ethErrors.rpc.methodNotSupported("Method Not Supported: "+t.method);case"eth_sendUserOperation":g=yield this.handleSendUserOperation(t);break;case"eth_estimateUserOperationGas":case"eth_getUserOperationByHash":case"eth_getUserOperationReceipt":case"eth_supportedEntryPoints":g=yield this.handleBundler(t);break;default:h=yield this.handleReadRequests(t)}if(h&&!h.result&&h.error){const m=h.error.message?h.error.message:"Request failed";throw P.ethErrors.rpc.internal(m)}return h?h.result:g}catch(h){throw P.ethErrors.rpc.internal(h==null?void 0:h.message)}})}bloctoApi(t,n){var r;return E(this,void 0,void 0,function*(){const{walletServer:i,blockchainName:o,sessionKeyEnv:s}=yield O(this,x,"m",_).call(this),a=((r=ne(s))===null||r===void 0?void 0:r.code)||"";if(!a)throw P.ethErrors.provider.unauthorized();return fetch(`${i}/api/${o}${t}`,Object.assign({headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":a}},n)).then(c=>pt(c,s,()=>{var u;(u=this.eventListeners)===null||u===void 0||u.disconnect.forEach(l=>l(P.ethErrors.provider.disconnected()))})).catch(c=>{throw(c==null?void 0:c.error_code)==="unsupported_method"?P.ethErrors.rpc.methodNotSupported("Method Not Supported: "+c.message):P.ethErrors.rpc.server({code:-32005,message:`Blocto server error: ${c.message}`})})})}responseListener(t,n){return E(this,void 0,void 0,function*(){const{walletServer:r}=yield O(this,x,"m",_).call(this);return new Promise((i,o)=>te("message",(s,a)=>{const c=s;c.origin===r&&c.data.type==="ETH:FRAME:RESPONSE"&&(c.data.status==="APPROVED"&&(a(),z(t),i(c.data[n])),c.data.status==="DECLINED"&&(a(),z(t),c.data.errorCode==="incorrect_session_id"&&this.handleDisconnect(),o(P.ethErrors.provider.userRejectedRequest(c.data.errorMessage)))),c.data.type==="ETH:FRAME:CLOSE"&&(a(),z(t),o(P.ethErrors.provider.userRejectedRequest("User declined the request")))}))})}setIframe(t,n){return E(this,void 0,void 0,function*(){if(typeof window>"u")throw P.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:r,blockchainName:i}=yield O(this,x,"m",_).call(this),o=dt(`${r}/${this.appId}/${n||i}${t}`);return ht(o),o})}enable(t){var n;return E(this,void 0,void 0,function*(){if(typeof window>"u")throw P.ethErrors.provider.custom({code:1001,message:"Blocto SDK only works in browser environment"});const{walletServer:r,blockchainName:i,sessionKeyEnv:o}=yield O(this,x,"m",_).call(this);if(!((n=this.existedSDK)===null||n===void 0)&&n.isBlocto)return this.existedSDK.chainId!==this.chainId&&(yield this.existedSDK.request({method:"wallet_addEthereumChain",params:[{chainId:this.chainId}]}),yield this.existedSDK.request({method:"wallet_switchEthereumChain",params:[{chainId:this.chainId}]}),pr(o,i,[this.existedSDK.address])),new Promise((l,f)=>setTimeout(()=>this.existedSDK.enable().then(l).catch(f),10));const s=Ye(o,i);if(s)return new Promise(l=>{l(s)});const a=new URLSearchParams;a.set("l6n",window.location.origin),a.set("v",lt);const c=t&&mr(t)?`/${t}`:"",u=yield this.setIframe(`/authn${c}?${a.toString()}`);return new Promise((l,f)=>{te("message",(d,h)=>{var g,m;const b=d;b.origin===r&&(b.data.type==="ETH:FRAME:RESPONSE"&&(h(),z(u),(g=this.eventListeners)===null||g===void 0||g.connect.forEach(w=>w({chainId:this.chainId})),Ie(o,{code:b.data.code,evm:{[i]:[b.data.addr]}},b.data.exp),!((m=b.data)===null||m===void 0)&&m.isAccountChanged&&postMessage({originChain:j.ETHEREUM,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),te("message",(w,y)=>{var A,I,S;const L=w,U=((A=L.data)===null||A===void 0?void 0:A.type)==="BLOCTO_SDK:ACCOUNT_CHANGED",G=((I=L.data)===null||I===void 0?void 0:I.originChain)!==j.ETHEREUM;U&&((S=this.eventListeners)===null||S===void 0||S.accountsChanged.forEach(W=>W([b.data.addr]))),U&&G&&(this.handleDisconnect(),y())}),l([b.data.addr])),b.data.type==="ETH:FRAME:CLOSE"&&(h(),z(u),f(P.ethErrors.provider.userRejectedRequest())))})})})}fetchAccounts(){return E(this,void 0,void 0,function*(){O(this,x,"m",oe).call(this);const{blockchainName:t,sessionKeyEnv:n}=yield O(this,x,"m",_).call(this),{accounts:r}=yield this.bloctoApi("/accounts");return pr(n,t,r),r})}handleReadRequests(t){return E(this,void 0,void 0,function*(){return O(this,x,"m",oe).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then(n=>n.json()).catch(n=>{throw P.ethErrors.rpc.internal(n)})})}handleSign({method:t,params:n}){return E(this,void 0,void 0,function*(){let r="";if(Array.isArray(n)){if(t==="personal_sign")r=sn(n[0])?n[0].slice(2):ra(n[0]);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(t)){r=n[1];const{domain:s}=JSON.parse(r);if(sn(s.chainId))throw P.ethErrors.rpc.invalidParams(`Provided chainId "${s.chainId}" must be a number`);if(N(s.chainId)!==N(this.chainId))throw P.ethErrors.rpc.invalidParams(`Provided chainId "${s.chainId}" must match the active chainId "${N(this.chainId)}"`)}}O(this,x,"m",oe).call(this);const{signatureId:i}=yield this.bloctoApi("/user-signature",{method:"POST",body:JSON.stringify({method:t,message:r})}),o=yield this.setIframe(`/user-signature/${i}`);return this.responseListener(o,"signature")})}handleSwitchChain(t){var n,r;return E(this,void 0,void 0,function*(){if(!t)throw P.ethErrors.rpc.invalidParams();const{walletServer:i,blockchainName:o,sessionKeyEnv:s,switchableNetwork:a}=yield O(this,x,"m",_).call(this),c=(n=Ye(s,o))===null||n===void 0?void 0:n[0],u=N(this.chainId),l=N(t);if(u===l)return null;if(!a[l])throw P.ethErrors.provider.custom({code:4902,message:`Unrecognized chain ID "${l}". Try adding the chain using wallet_addEthereumChain first.`});if(this.networkVersion=`${l}`,this.chainId=`0x${l.toString(16)}`,this.rpc=a[l].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),!c)return(r=this.eventListeners)===null||r===void 0||r.chainChanged.forEach(d=>d(this.chainId)),yield O(this,x,"m",_).call(this),null;if(a[l].wallet_web_url!==a[u].wallet_web_url)return this.enable().then(([d])=>{var h;return d!==c&&((h=this.eventListeners)===null||h===void 0||h.accountsChanged.forEach(g=>g([d]))),this.eventListeners.chainChanged.forEach(g=>g(this.chainId)),null}).catch(d=>{throw this.networkVersion=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),O(this,x,"m",_).call(this),d});const f=yield this.setIframe(`/switch-chain?to=${a[l].name}`,a[u].name);return new Promise((d,h)=>{te("message",(g,m)=>{var b,w,y,A,I,S,L,U;const G=g;G.origin===i&&(G.data.type==="ETH:FRAME:RESPONSE"&&(m(),z(f),!((b=G.data)===null||b===void 0)&&b.addr&&c&&(Ie(s,{code:(w=G.data)===null||w===void 0?void 0:w.code,evm:{[a[l].name]:[G.data.addr]}},(y=G.data)===null||y===void 0?void 0:y.exp),G.data.addr!==c&&((A=this.eventListeners)===null||A===void 0||A.accountsChanged.forEach(W=>W([G.data.addr])))),(I=this.eventListeners)===null||I===void 0||I.chainChanged.forEach(W=>W(this.chainId)),O(this,x,"m",_).call(this),d(null)),G.data.type==="ETH:FRAME:CLOSE"&&(m(),z(f),!((S=G.data)===null||S===void 0)&&S.hasApprovedSwitchChain?((L=this.eventListeners)===null||L===void 0||L.chainChanged.forEach(W=>W(this.chainId)),gr(s),(U=this.eventListeners)===null||U===void 0||U.disconnect.forEach(W=>W(P.ethErrors.provider.disconnected())),O(this,x,"m",_).call(this),d(null)):(this.networkVersion=`${u}`,this.chainId=`0x${u.toString(16)}`,this.rpc=a[u].rpc_url,this._blocto=Object.assign(Object.assign({},this._blocto),{blockchainName:"",networkType:""}),O(this,x,"m",_).call(this),h(P.ethErrors.provider.userRejectedRequest()))))})})})}handleSendTransaction(t){var n;return E(this,void 0,void 0,function*(){O(this,x,"m",oe).call(this);const{isValid:r,invalidMsg:i}=kr((n=t.params)===null||n===void 0?void 0:n[0]);if(!r)throw P.ethErrors.rpc.invalidParams(i);return O(this,x,"m",fn).call(this,t.params)})}handleSendBatchTransaction(t){return E(this,void 0,void 0,function*(){O(this,x,"m",oe).call(this);let n,r;Array.isArray(t.params)&&t.params.length>=2?[n,r]=t.params:(n=t.params,r=!1);const i=r||!1,{isValid:o,invalidMsg:s}=ia(n);if(!o)throw P.ethErrors.rpc.invalidParams(s);return O(this,x,"m",fn).call(this,n,i)})}handleSendUserOperation(t){return E(this,void 0,void 0,function*(){O(this,x,"m",oe).call(this);const{authorizationId:n}=yield this.bloctoApi("/user-operation",{method:"POST",body:JSON.stringify(t.params)}),r=yield this.setIframe(`/user-operation/${n}`);return this.responseListener(r,"userOpHash")})}handleBundler(t){return E(this,void 0,void 0,function*(){return O(this,x,"m",oe).call(this),this.bloctoApi("/rpc/bundler",{method:"POST",body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))})})}handleDisconnect(){var t,n;return E(this,void 0,void 0,function*(){if(!((t=this.existedSDK)===null||t===void 0)&&t.isBlocto)return this.existedSDK.request({method:"wallet_disconnect"});const{sessionKeyEnv:r}=yield O(this,x,"m",_).call(this);gr(r),(n=this.eventListeners)===null||n===void 0||n.disconnect.forEach(i=>i(P.ethErrors.provider.disconnected()))})}loadSwitchableNetwork(t){return E(this,void 0,void 0,function*(){if(t!=null&&t.length){const n=t.map(({chainId:r,rpcUrls:i})=>{if(!r)throw P.ethErrors.rpc.invalidParams("Empty chainId");const o=`${N(r)}`;if(this._blocto.switchableNetwork[o])return null;const s=(i==null?void 0:i[0])||Qt[o];if(!s)throw P.ethErrors.rpc.invalidParams("rpcUrls required");return O(this,x,"m",Qr).call(this,{chainId:o,rpcUrls:[s]})});return Promise.all(n).then(()=>null)}else throw P.ethErrors.rpc.invalidParams("Empty networkList")})}supportChainList(){return E(this,void 0,void 0,function*(){const t=yield an().catch(n=>{throw P.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${n.message}`})});return Object.keys(t).map(n=>{const{display_name:r}=t[n];return{chainId:n,chainName:r}})})}on(t,n){var r;!((r=this.existedSDK)===null||r===void 0)&&r.isBlocto&&this.existedSDK.on(t,n),super.on(t,n)}removeListener(t,n){var r;!((r=this.existedSDK)===null||r===void 0)&&r.isBlocto&&this.existedSDK.off(t,n),super.removeListener(t,n)}}x=new WeakSet,_=function(){var e,t;return E(this,void 0,void 0,function*(){if(!((e=this._blocto)===null||e===void 0)&&e.unloadedNetwork&&(yield this.loadSwitchableNetwork(this._blocto.unloadedNetwork),delete this._blocto.unloadedNetwork),this._blocto.sessionKeyEnv&&this._blocto.walletServer&&this._blocto.blockchainName&&this._blocto.networkType&&this._blocto.switchableNetwork)return this._blocto;const n=yield an().catch(u=>{throw P.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${u.message}`})}),{chain_id:r,name:i,network_type:o,blocto_service_environment:s,display_name:a}=(t=n[this.networkVersion])!==null&&t!==void 0?t:{};if(!r)throw P.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${this.networkVersion} might not be supported yet.`);const c=this.injectedWalletServer||dr[s];return this._blocto=Object.assign(Object.assign({},this._blocto),{sessionKeyEnv:ps[s],walletServer:c,blockchainName:i,networkType:o,switchableNetwork:Object.assign(Object.assign({},this._blocto.switchableNetwork),{[r]:{name:i,display_name:a,network_type:o,wallet_web_url:c,rpc_url:this.rpc}})}),this._blocto})},Qr=function({chainId:e,rpcUrls:t}){var n;return E(this,void 0,void 0,function*(){yield O(this,x,"m",_).call(this);const r=yield an().catch(l=>{throw P.ethErrors.provider.custom({code:1001,message:`Get blocto server failed: ${l.message}`})}),{chain_id:i,name:o,display_name:s,network_type:a,blocto_service_environment:c}=(n=r[e])!==null&&n!==void 0?n:{};if(!i)throw P.ethErrors.provider.unsupportedMethod(`Get support chain failed: ${e} might not be supported yet.`);const u=dr[c];this._blocto.switchableNetwork[i]={name:o,display_name:s,network_type:a,wallet_web_url:u,rpc_url:t[0]}})},oe=function(){var e;if(!((e=this.existedSDK)===null||e===void 0)&&e.isBlocto&&N(this.existedSDK.chainId)!==N(this.chainId))throw P.ethErrors.provider.chainDisconnected()},fn=function(e,t=!0){return E(this,void 0,void 0,function*(){const{authorizationId:n}=yield this.bloctoApi("/authz",{method:"POST",body:JSON.stringify([e,t])}),r=yield this.setIframe(`/authz/${n}`);return this.responseListener(r,"txHash")})};const Ia=e=>{var t,n;const r=Object.assign({},e),{message:i,nonce:o,address:s,application:a,chainId:c}=e;return typeof i!="string"&&(r.message=(t=String(i))!==null&&t!==void 0?t:""),typeof o!="string"&&(r.nonce=(n=String(o))!==null&&n!==void 0?n:""),s&&typeof s!="boolean"&&(r.address=!!s),a&&typeof a!="boolean"&&(r.application=!!a),c&&typeof c!="boolean"&&(r.chainId=!!c),r};class xa extends fr{get existedSDK(){if(!(typeof window>"u"))return window.bloctoAptos}constructor({chainId:t,server:n,appId:r}){super(),this.publicKey=[],this.authKey="",this.off=this.removeListener,Ee(t,"'chainId' is required"),Ee(r,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=t,this.networkName=ys[t],this.api=vs[t],this.sessionKey=gs[t];const i=ms[t];this.appId=r||Wt,this.server=n||i||""}get publicAccount(){var t;return{address:((t=Y(this.sessionKey,j.APTOS))===null||t===void 0?void 0:t[0])||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return E(this,void 0,void 0,function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}})}isConnected(){var t;return E(this,void 0,void 0,function*(){return!!(!((t=Y(this.sessionKey,j.APTOS))===null||t===void 0)&&t.length)})}signTransaction(t){var n;return E(this,void 0,void 0,function*(){if(this.existedSDK)return this.existedSDK.signTransaction(t);throw(yield this.isConnected())||(yield this.connect()),!((n=Y(this.sessionKey,j.APTOS))===null||n===void 0)&&n.length?new Error("signTransaction method not supported."):new Error("Fail to get account")})}disconnect(){var t;return E(this,void 0,void 0,function*(){if(this.existedSDK){yield this.existedSDK.disconnect();return}Os(this.sessionKey,j.APTOS),(t=this.eventListeners)===null||t===void 0||t.disconnect.forEach(n=>n({code:4900,message:"Wallet disconnected"}))})}signAndSubmitTransaction(t,n={}){var r,i;return E(this,void 0,void 0,function*(){if(this.existedSDK)return this.existedSDK.signAndSubmitTransaction(t,n);if((yield this.isConnected())||(yield this.connect()),!(!((r=Y(this.sessionKey,j.APTOS))===null||r===void 0)&&r.length))throw new Error("Fail to get account");const o=((i=ne(this.sessionKey))===null||i===void 0?void 0:i.code)||"",{authorizationId:s}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":o},body:JSON.stringify(Object.assign(Object.assign({},t),n))}).then(c=>pt(c,this.sessionKey));if(typeof window>"u")throw new Error("Currently only supported in browser");const a=dt(`${this.server}/${this.appId}/aptos/authz/${s}`);return ht(a),new Promise((c,u)=>te("message",(l,f)=>{const d=l;d.origin===this.server&&d.data.type==="APTOS:FRAME:RESPONSE"&&(d.data.status==="APPROVED"&&(f(),z(a),c({hash:d.data.txHash})),d.data.status==="DECLINED"&&(f(),z(a),d.data.errorCode==="incorrect_session_id"&&this.disconnect(),u(new Error(d.data.errorMessage))))}))})}signMessage(t){var n,r;return E(this,void 0,void 0,function*(){const i=Ia(t);if(this.existedSDK)return this.existedSDK.signMessage(i);if((yield this.isConnected())||(yield this.connect()),!(!((n=Y(this.sessionKey,j.APTOS))===null||n===void 0)&&n.length))throw new Error("Fail to get account");if(typeof window>"u")throw new Error("Currently only supported in browser");const o=((r=ne(this.sessionKey))===null||r===void 0?void 0:r.code)||"",{signatureId:s}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":o},body:JSON.stringify(i)}).then(u=>pt(u,this.sessionKey)),a=`${this.server}/${this.appId}/aptos/user-signature/${s}`,c=dt(a);return ht(c),new Promise((u,l)=>te("message",(f,d)=>{const h=f;h.origin===this.server&&h.data.type==="APTOS:FRAME:RESPONSE"&&(h.data.status==="APPROVED"&&(d(),z(c),u(h.data)),h.data.status==="DECLINED"&&(d(),z(c),h.data.errorCode==="incorrect_session_id"&&this.disconnect(),l(new Error(h.data.errorMessage))))}))})}connect(){return E(this,void 0,void 0,function*(){return this.existedSDK?new Promise((t,n)=>setTimeout(()=>this.existedSDK.connect().then(t).catch(n),10)):new Promise((t,n)=>{var r,i;if(typeof window>"u")return n("Currently only supported in browser");if(!((r=Y(this.sessionKey,j.APTOS))===null||r===void 0)&&r.length)return t({address:((i=Y(this.sessionKey,j.APTOS))===null||i===void 0?void 0:i[0])||null,publicKey:this.publicKey,authKey:null,minKeysRequired:2});const o=encodeURIComponent(window.location.origin),s=dt(`${this.server}/${this.appId}/aptos/authn?l6n=${o}&v=${lt}}`);ht(s),te("message",(a,c)=>E(this,void 0,void 0,function*(){var u,l,f,d;const h=a;if(h.origin===this.server){if(h.data.type==="APTOS:FRAME:RESPONSE")if(c(),z(s),Ie(this.sessionKey,{code:h.data.code,accounts:{[j.APTOS]:[h.data.addr]}},h.data.exp),!((u=h.data)===null||u===void 0)&&u.isAccountChanged&&postMessage({originChain:j.APTOS,type:"BLOCTO_SDK:ACCOUNT_CHANGED"}),te("message",(g,m)=>{var b,w;const y=g;((b=y.data)===null||b===void 0?void 0:b.type)==="BLOCTO_SDK:ACCOUNT_CHANGED"&&((w=y.data)===null||w===void 0?void 0:w.originChain)!==j.APTOS&&(this.disconnect(),m())}),!((l=Y(this.sessionKey,j.APTOS))===null||l===void 0)&&l.length)try{const{public_keys:g}=yield fetch(`${this.server}/blocto/aptos/accounts/${(f=Y(this.sessionKey,j.APTOS))===null||f===void 0?void 0:f[0]}`).then(m=>m.json());this.publicKey=g||[],t({address:((d=Y(this.sessionKey,j.APTOS))===null||d===void 0?void 0:d[0])||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch{return n(h)}else return n();h.data.type==="APTOS:FRAME:CLOSE"&&(c(),z(s),n(new Error("User declined the login request")))}}))})})}fetchAddress(){var t;return E(this,void 0,void 0,function*(){const n=((t=ne(this.sessionKey))===null||t===void 0?void 0:t.code)||"",{accounts:r}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":n}}).then(i=>pt(i,this.sessionKey));return xs(this.sessionKey,j.APTOS,r),(r==null?void 0:r[0])||""})}on(t,n){this.existedSDK&&this.existedSDK.on(t,n),super.on(t,n)}removeListener(t,n){this.existedSDK&&this.existedSDK.off(t,n),super.removeListener(t,n)}}class Oa{constructor({appId:t,ethereum:n,aptos:r}){n&&(this.ethereum=new Ea(Object.assign(Object.assign({},n),{appId:t}))),r&&(this.aptos=new xa(Object.assign(Object.assign({},r),{appId:t})))}}function Wr(e){return typeof e=="string"?Number.parseInt(e,e.trim().substring(0,2)==="0x"?16:10):typeof e=="bigint"?Number(e):e}var he,Ze,Xe,et,pn,Zr,gn,Xr,xt,mn,yn,ei;class Ma extends Ni{constructor({chains:t,options:n={}}){super({chains:t,options:n}),Z(this,pn),Z(this,gn),Z(this,xt),Z(this,yn),Ot(this,"id","blocto"),Ot(this,"name","Blocto"),Ot(this,"ready",!0),Z(this,he,void 0),Z(this,Ze,void 0),Z(this,Xe,void 0),Z(this,et,void 0),Me(this,Ze,this.onAccountsChanged.bind(this)),Me(this,Xe,this.onChainChanged.bind(this)),Me(this,et,this.onDisconnect.bind(this))}getProvider({chainId:t}={}){var n,r,i,o;if(!H(this,he)){const{appId:s}=this.options,a=t??((n=this.chains[0])==null?void 0:n.id),c={chainId:a,rpc:(i=(r=this.chains.find(u=>u.id===a))==null?void 0:r.rpcUrls.default.http)==null?void 0:i[0]};Me(this,he,(o=new Oa({ethereum:c,appId:s}))==null?void 0:o.ethereum)}if(!H(this,he))throw new ji;return Promise.resolve(H(this,he))}async connect(t){try{const n=await this.getProvider(t);Ae(this,pn,Zr).call(this),this.emit("message",{type:"connecting"}),await n.request({method:"eth_requestAccounts"});const r=await this.getAccount(),i=await this.getChainId(),o=this.isChainUnsupported(i);return{account:r,chain:{id:i,unsupported:o}}}catch(n){throw Ae(this,xt,mn).call(this),n}}async disconnect(){await(await this.getProvider()).request({method:"wallet_disconnect"}),Ae(this,gn,Xr).call(this),Ae(this,xt,mn).call(this)}async getAccount(){const t=await(await this.getProvider()).request({method:"eth_accounts"}),[n]=t||[];if(!n)throw new Error("No accounts found");return n}async getChainId(){const t=await(await this.getProvider()).request({method:"eth_chainId"});return Wr(t)}async isAuthorized(){var t,n;const r=(t=this.storage)==null?void 0:t.getItem("wallet"),i=!!((n=this.storage)!=null&&n.getItem("connected")),o=r==="blocto"&&i;return Promise.resolve(o)}async switchChain(t){try{const n=await this.getProvider(),r=M(t),i=this.chains.find(s=>s.id===t),o=(await n.supportChainList()).reduce((s,a)=>({...s,[a.chainId]:a}),{})[`${t}`];if(!i||!o)throw new ae(new Error(`Blocto unsupported chain: ${r}`));return await n.request({method:"wallet_addEthereumChain",params:[{chainId:r,rpcUrls:i==null?void 0:i.rpcUrls.default.http}]}),await n.request({method:"wallet_switchEthereumChain",params:[{chainId:r}]}),i}catch(n){throw Ae(this,yn,ei).call(this,n)?n:new ae(n)}}async getWalletClient({chainId:t}){const[n,r]=await Promise.all([this.getProvider(),this.getAccount()]),i=this.chains.find(o=>o.id===t);if(!n)throw new Error("provider is required.");return fs({account:r,chain:i,transport:Qo(n)})}onAccountsChanged(){}async onChainChanged(t){const n=Wr(t),r=this.isChainUnsupported(n),i=await this.getAccount();this.emit("change",{chain:{id:n,unsupported:r},account:i})}onDisconnect(){this.emit("disconnect")}}he=new WeakMap,Ze=new WeakMap,Xe=new WeakMap,et=new WeakMap,pn=new WeakSet,Zr=async function(){const e=await this.getProvider();e.on("accountsChanged",H(this,Ze)),e.on("chainChanged",H(this,Xe)),e.on("disconnect",H(this,et))},gn=new WeakSet,Xr=async function(){const e=await this.getProvider();e.off("accountsChanged",H(this,Ze)),e.off("chainChanged",H(this,Xe)),e.off("disconnect",H(this,et))},xt=new WeakSet,mn=function(){Me(this,he,void 0)},yn=new WeakSet,ei=function(e){return/(user rejected)/i.test(e.message)};const Aa={walletImages:{blocto:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjAiIGhlaWdodD0iNjAiIHZpZXdCb3g9IjAgMCA2MCA2MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzIyMzNfMjM4NykiPgo8cmVjdCB3aWR0aD0iNjAiIGhlaWdodD0iNjAiIHJ4PSIxMiIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTMyLjkwMjggMTguMzA2M0MyOC4zOTExIDE4LjMwNjMgMjMuOTg3MyAyMC4wNDU5IDIwLjY5NTIgMjMuMTMxOUMxNy4wODQzIDI2LjUxNzYgMTQuNzk5MiAzMS41MTc3IDEzLjQ4OTMgMzYuMjIxMkMxMi42MzE0IDM5LjI5OTIgMTIuMjAxNiA0Mi40OTE1IDEyLjIwMTYgNDUuNjg1M0MxMi4yMDE2IDQ2LjY1MTEgMTIuMjQxMiA0Ny42MDg5IDEyLjMxNzQgNDguNTU1NkMxMi40MTA5IDQ5LjcwNjkgMTMuNTMyMSA1MC41MDQ2IDE0LjY0ODUgNTAuMjAzM0MxNS42MjIyIDQ5Ljk0MTYgMTYuNjQ2NiA0OS44MDA1IDE3LjcwMjggNDkuODAwNUMxOS44NzIyIDQ5LjgwMDUgMjEuOTA1MiA1MC4zOTA0IDIzLjY0OCA1MS40MjEyQzIzLjY5MDggNTEuNDQ2NiAyMy43MzIgNTEuNDcxOSAyMy43NzQ4IDUxLjQ5NTdDMjYuNjA3MSA1My4xODQ2IDI5Ljk0ODQgNTQuMTEyMyAzMy41MTE3IDUzLjk5MzRDNDIuODA2MiA1My42ODU3IDUwLjM5OSA0Ni4xMjMgNTAuNzQxNiAzNi44MzAxQzUxLjExNTggMjYuNjYzNSA0Mi45ODY5IDE4LjMwNDcgMzIuOTA0NCAxOC4zMDQ3TDMyLjkwMjggMTguMzA2M1pNMzIuOTAyOCA0NC4zMTJDMjguMzk3NSA0NC4zMTIgMjQuNzQ1NCA0MC42NTk5IDI0Ljc0NTQgMzYuMTU2MkMyNC43NDU0IDMxLjY1MjUgMjguMzk3NSAyNy45OTg3IDMyLjkwMjggMjcuOTk4N0MzNy40MDgxIDI3Ljk5ODcgNDEuMDYwMiAzMS42NTA5IDQxLjA2MDIgMzYuMTU2MkM0MS4wNjAyIDQwLjY2MTQgMzcuNDA4MSA0NC4zMTIgMzIuOTAyOCA0NC4zMTJaIiBmaWxsPSIjMTRBQUZGIi8+CjxwYXRoIGQ9Ik0yNS41NjM2IDEyLjY4MjZDMjUuNTYzNiAxNS4wMzQ0IDI0LjMzMTUgMTcuMjE2NCAyMi4zMDggMTguNDE1M0MyMS4wMzc3IDE5LjE2ODYgMTkuODQ2OCAyMC4wNTgyIDE4Ljc2ODQgMjEuMDcxNUMxNi4zNzU1IDIzLjMxMzkgMTQuNTg5OCAyNi4wNjUzIDEzLjI2NzMgMjguNzkyOUMxMy4wMDcyIDI5LjMzMDQgMTIuMiAyOS4xNDAyIDEyLjIgMjguNTQyM1YxMi42ODI2QzEyLjIgOC45OTI0MiAxNS4xOTI0IDYgMTguODgyNiA2QzIyLjU3MjggNiAyNS41NjUyIDguOTkyNDIgMjUuNTY1MiAxMi42ODI2SDI1LjU2MzZaIiBmaWxsPSIjMDA3NUZGIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDBfMjIzM18yMzg3Ij4KPHJlY3Qgd2lkdGg9IjYwIiBoZWlnaHQ9IjYwIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo="}};se.BloctoConnector=Ma,se.BloctoWeb3ModalConfig=Aa,Object.defineProperty(se,Symbol.toStringTag,{value:"Module"})});