UNPKG

@coinmeca/wallet-sdk

Version:
3 lines (2 loc) 24.5 kB
import{C as t}from"./core-ByiNW7VX.js";import{fetchFromProvider as e}from"@ethereumjs/util";import{formatChainId as r,loadStorage as a,valid as i,parseChainId as o,chainUrls as s,chainUrl as n,quantityHex as c,dataHex as h,transactionRequest as d,requestRoute as l,openWindow as u,getFaviconUri as p,getAppName as w,erc20ApproveCall as f,parse as m}from"./utils.js";import"eventemitter3";import"ethereum-cryptography/utils";import"./constants-BBbo8WQE.js";const y=v;function g(){const t=["createElement","3fCLoDO","load","emit","call","appendChild","No selected account.","close"," is not supported. Subscription methods are not available in this wallet","contentWindow","Coinmeca Wallet","No contract address provided.","defineProperty","test","Requested chain is not active.","iframe","svm","100vw","modal","hostname","discordsays.com","RPC Error: ","eth_filterChanges","providers","1078076HPySza","add","mainnet","ready","56ScUCiv","isSafeInteger","' not supported","block","state","coinmeca-wallet-modal","addEventListener","catch","unknown","WebApp","position","src","latest","coinmeca","Invalid transaction request.","parent","object","some","chainName","focus","eth_accounts","Invalid filter address.","reject","tabIndex","bind","values","eth_getTransactionCount","isInteger","hasOwnProperty","portal","gasLimit","stringify","has","eip6963:requestProvider","CoinmecaWallet","undefined","value","Invalid transaction recipient.","black","No active chain.","1302cEFdxn","No transaction parameters provided","symbol","Invalid contract address.","from","balance","none","Invalid filter parameters.","push","cleanup","eth_coinbase","isArray",":chainId","then","popup","string","Invalid transaction gas limit.","getTime","77917VvWosf","personal_sign","getElementById","flex","search","eth_signTypedData","eth_estimateGas","name","source","gasPrice","evm","137089boQroB","coinmeca-wallet-proxy-","location","2101563oiSrKA","set","rpc","filter","trim","954792fPQONb","message","Invalid transaction sender.","22garvZC","dispatchEvent","hidden","eth_sign","entries","eth_getBalance","origin","get","coinmeca:wallet","eth_signTransaction","exportState","20NOBVRU","eth_chainId","resolve","platform","Invalid filter id.","params","eth_subscribe","eip6963:announceProvider","eth_syncing","wallet_switchEthereumChain","No address or position provided","100%","size","Invalid transaction data.","frame_id","isCoinmecaWallet","User rejected the request.","eth_unsubscribe","style","address","assign","Wallet request shell could not be created.","proxy","1px solid rgba(255,255,255,.3)","iconUrls","Telegram","splice","eth_sendTransaction","body","toString","result","postMessage","eth_signTypedData_v4","accountChanged","gas","delete","chain","rpcUrls","request","div","-999999999","Invalid chain id.","ethereum","storage","chainChanged","width","base","removeEventListener","prototype","storageArea","height","freeze","Invalid account address.","method","https://wallet.coinmeca.net",":address","Wallet request shell was closed before approving the request.","URL","decimals","url","Invalid transaction chain id.","target","toLowerCase","blockExplorerUrls","Invalid transaction gas.","number","Invalid transaction value.","nonce","No filter ID provided","999999999","eth_uninstallFilter","closed","'eth_sign' is depreacted request method. Please request again with 'personal_sign' or 'eth_signTypedData'.","absolute","net_version","testnet","coinmeca-wallet","wallet",":chain","wallet_watchAsset","rgba(0, 0, 0, 0.6)","error","floor","logo","net.coinmeca.wallet","maxPriorityFeePerGas","200032xeOosQ","devnet","eth_getCode","remove","1585mHWCUY","Unsupported wallet request method.","providerMap","erc20_approve","type","coinmeca-wallet-panel","chainId","data","nativeCurrency","endsWith","strategy","100vh","randomUUID","length","Invalid transaction nonce.","maxFeePerGas"];return(g=function(){return t})()}function v(t,e){const r=g();return(v=function(t,e){return r[t-=282]})(t,e)}!function(){const t=v,e=g();for(;;)try{if(422174===parseInt(t(384))/1+parseInt(t(492))/2+parseInt(t(288))/3*(-parseInt(t(311))/4)+parseInt(t(496))/5*(parseInt(t(355))/6)+parseInt(t(373))/7*(parseInt(t(315))/8)+-parseInt(t(387))/9*(-parseInt(t(406))/10)+parseInt(t(395))/11*(-parseInt(t(392))/12))break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const b=y(460);class I extends t{#t=y(403);#e;#r;#a=new Map;constructor(t){const e=y;super(),this.#r=t?.[e(465)];const{chainId:r,rpcUrls:a,nativeCurrency:i}=t?.[e(442)]||{};r&&a&&a[e(284)]&&i&&i?.decimals&&this.#i(t?.[e(442)]);window[e(321)](e(449),t=>{const r=e;if(t[r(455)]!==localStorage)return;const{key:a,newValue:i}=t;if(a!==this.#t+":address"&&a!==this.#t+r(484)&&a!==this.#t+":chainId")return;if(!i){switch(a){case this.#t+r(461):this.#o();break;case this.#t+":chain":case this.#t+r(367):this.#s()}return}const o=m(i);if(o)switch(a){case this.#t+":address":this.#n(o);break;case this.#t+":chain":o?.[r(502)]&&this.#i(o);break;case this.#t+":chainId":this.#i(o)}});const o=new CustomEvent(e(413),{detail:{info:{name:e(297),icon:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFT0lEQVR4AbVWBWxbVxQ975ND3+GkzBBORmVmZqYxB8bMvBXGaQdWmSHpmJkXLDMF1YBaq3O5Z35WubYbPNKR7E/vwrmAqsLeeF3okeavTSlvOsJW3CYxa39is7I9XcJP7xkaePrAjIDyg0/5Z9kXB3x0/F//ydxuhqGuUG5ujyryX23bYNxxaL3SnrMQwBRonCwUjhSCoxTBqarg/T6C74ULftdDcM+L6mH7j8b8438Y8agp/sJf1h2WrTN/UtMdr6E7RyKE7aAzCIIWgKqTylnK3/JaiADjFHCaLzg/HtzxmuJw5Bozy7bBRHWQZZRH/aRtynsdz7IfYhgBX2oQBFAl6k42U8DpAeDnw8GKb5S849uNKFQF/+j/3bBc2VoyAw+zJVpQh0oANaJFgDcY4PsJYPEqpfREiX4DvGGN0/M56o7S/niUoWhM4cXrqlJxsq0GzmwHFq9WSugpErawMvNxy4G8G/AKrWhKnD28LijOGpGeAFZ8q+RW/AUrLkdySNnMeLGcJuKueriqqgwMDGTjxo0l5W957aqRkOn4fAToyDdm4mKMb1UQn+SX4wgQYyhgePyIj48PR4wYwYyMDBYWFvLo0aMuFhQUcN26dRw2bBgtFotXTUw3wZ1vKI7j5Rel4trWRfMD1HepioYeX27atCkzMzN56tQpesLJkyddxjVs6OU7Kjg/ATzyu2GDxHWT7WFhTTYe1sQ4AprHw7Ozs1kVnDlzhqmpqV5LdJofuO9V7RALzVBETq6crJuZFKK9+7BZLNJztwdJjyXl73PX5s2bRz8/P696iFPB73oJHs+1ToE5rugjYbxOIMjtw8OHD3cdcjH27dvHlJQUxsbGMi4ujsnJydy9ezfT09OvejjOdsx3IwXtS/xt8Bm9K0to9xAw3Kpdiuti7N27lzExMRTiQqXI3yEhITQMo2oNysn7fQUPPu2fBWPs5nKhjifcdDxZXlLhF4f93nvvrXVfUJ2cqgkW3GyWQZ+afxraMHe1L2tcltnFKpdhr5PuKKfo3uFBzrPv8GxAo0aN6s0AOcr3dAt3nv3IpjJYJhJQ3KZANpyLUyDFJ4SodQomC5X7k5qXQ5uzLQsByVUWoawAKUIAl4gwNDS0yiI0nEyBweK2iVnQ1++1oclMQgl2+7BsvbL7XW6ELL1zZZiWluYqw7lz51apDOVSM0uYrGw++kMYWwumYEAGoUV76v+yvdZpI2oHg+uVKDpavDEZsNtDldezDyFgktdWnJOTw6rgrE48Hq5BcCRCudFy12G2+zEMEvofu21ITCe0xlcdRtJjT5CpkprxNowi4MfX0YNF/hnzcQ5G+d4o8dpfDlgnEcL7OJatWaZENqjLx7G8520ca1DZH7H8WZ3nOBJcEI+LoW3eMxNDVhCWa+tlIREQbIUWfAPPc49l10xcgYqdVuXrTXmIn03orep0JQOEa8e8EY/wN217XhnKTLiDYS+OUlbklaDti3VohKAVzTgAj3OlsqN0u3E8Ct6glx+4QVmRW+qKhM+1bjRRdQoYtCKeHfEq31J3leTqJ25AVSBFqXyzOQ9DVxCBk89Wh1aNwzXXemeKsUxQVvAp36Lcr03peXVQts2UwnRVR1I6YU4i9GhCCTobFcVJcZbyt0GIINdmpTkPNtX3mOSf50gNqZy5JKTCiprCqCyI13/fNV+ZmX1YDMwgms0irMmEz0TCGEahS4538h4qljdoWDMZ3nTToWvbHrTd1M4ehbqCaS8OM7YWTdY/3feh/ta2LOcULdfvzD+tT99w2jJhS5nvmN1ZzvXO1mhq5ZQOM+yhqCL+B+AWe5nrKa3ZAAAAAElFTkSuQmCC",uuid:crypto[e(283)](),rdns:e(490)},provider:this}});window[e(396)](o),window[e(321)](e(348),()=>window[e(396)](o)),window[e(321)](e(393),this.#c[e(339)](this)),typeof window!==e(350)&&this.#h(),Object[e(457)](this)}get#d(){const t=y;return typeof window!==t(350)?window[t(431)]?.[t(324)]:void 0}get#l(){const t=y,e=window[t(386)][t(377)].includes(t(420))||window.location[t(306)][t(505)](t(307)),r=!!this.#d&&this.#d?.[t(409)]!==t(323);return Object[t(457)]({discord:e,frame:window[t(330)]!==window,telegram:r})}get#u(){const t=y;return window?.coinmeca?.[t(483)]}#p(){const t=y,e=this.#r||(typeof process!==t(350)?process.env?.NEXT_PUBLIC_WALLET_URL||process.env?.[t(463)]:void 0)||(typeof window!==t(350)?window.location[t(401)]:void 0)||b;try{return new URL(e)}catch{return new URL(b)}}#w(){const t=y;if(!window.ethereum){const e={isCoinmecaWallet:!0};return Object[t(299)](window,t(448),{value:e,writable:!0,configurable:!0,enumerable:!1}),e}return window[t(448)]}#f(t,e){const r=y;if(t&&e)try{const a=t[r(328)]&&typeof t[r(328)]===r(331)?t[r(328)]:{};Object[r(399)](e).forEach(([t,e])=>{const i=r;Object[i(454)][i(343)][i(291)](a,t)?a[t]=e:Object[i(299)](a,t,{value:e,writable:!0,configurable:!0,enumerable:!1})}),(!t[r(328)]||typeof t[r(328)]!==r(331))&&Object[r(299)](t,r(328),{value:a,writable:!0,configurable:!0,enumerable:!1})}catch{}}get[y(421)](){return!0}get[y(425)](){const t=y,e=this.#u;return e?e?.isLocked?void 0:this.#m(e[t(425)]):this.#m(this.#y({storage:sessionStorage})?.[t(402)](t(425))||this.#y()?.[t(402)]("address"))}get[y(442)](){const t=y,e=this.#u;return e?this.#g(e[t(442)]):this.#v()}get chainId(){const t=y,e=this.#u,a=e?this.#b(e?.chain?.[t(502)])||this.#g(e?.[t(442)])?.[t(502)]:this.#I(sessionStorage)||this.#I()||this.#v()?.chainId;return typeof a!==t(350)?r(a):void 0}async getAddress(){return this[y(425)]}async[y(360)](){const t=y,e=this.address;if(!e)throw new Error("No selected account.");return await this.#A[t(389)]("eth_getBalance",[e,t(327)])}#y(t){const e=y,r=a(this.#t,t?.storage||localStorage,!1);return Object[e(457)](r)}#m(t){const e=y;t&&"object"==typeof t&&!Array[e(366)](t)&&(t=t.address);const r="string"==typeof t?t[e(391)]():void 0;return r&&i[e(425)](r)?r:void 0}#E(t){const e=y;if(!Array[e(366)](t))return[];const r=[],a=new Set;for(const i of t){const t=this.#m(i),o=t?.toLowerCase();t&&o&&!a[e(347)](o)&&(a[e(312)](o),r[e(363)](t))}return r}#b(t){const e=y;return t&&"object"==typeof t&&!Array[e(366)](t)&&(t=t[e(502)]),i[e(502)](t)?o(t):void 0}#g(t){const e=y;if(!t||typeof t!==e(331)||Array[e(366)](t))return;const r=this.#b(t?.[e(502)]);if(!r)return;const a=Number[e(342)](t?.[e(504)]?.[e(464)])&&t[e(504)][e(464)]>=0?t[e(504)].decimals:void 0,i=t?.[e(504)]&&typeof t[e(504)]===e(331)&&typeof t.nativeCurrency?.[e(380)]===e(370)&&""!==t[e(504)][e(380)][e(391)]()&&typeof t.nativeCurrency?.[e(357)]===e(370)&&""!==t[e(504)][e(357)][e(391)]()&&"number"==typeof a?{name:t[e(504)][e(380)].trim(),symbol:t.nativeCurrency[e(357)][e(391)](),decimals:a}:void 0;return{base:t?.base===e(383)||t?.base===e(303)?t[e(452)]:void 0,type:t?.type===e(313)||"mainnet-beta"===t?.[e(500)]||t?.[e(500)]===e(481)||t?.type===e(493)?t[e(500)]:void 0,logo:n(t?.[e(489)],"icon"),chainId:r,chainName:"string"==typeof t?.[e(333)]&&""!==t[e(333)][e(391)]()?t[e(333)].trim():void 0,nativeCurrency:i,rpcUrls:s(t?.[e(443)],e(389)),blockExplorerUrls:s(t?.[e(469)],"explorer"),iconUrls:s(t?.[e(430)],"icon")}}#C(t){const e=y;if(!t||typeof t!==e(331)||Array[e(366)](t))return;const r=typeof t?.from!==e(350)?this.#m(t[e(359)]):void 0,a=typeof t?.to!==e(350)?this.#m(t.to):void 0,i=typeof t?.[e(502)]!==e(350)?c(t[e(502)]):void 0,o=typeof i!==e(350)?Number(BigInt(i)):void 0,s=typeof t?.[e(503)]!==e(350)?h(t[e(503)]):void 0,n=typeof t?.[e(351)]!==e(350)?c(t.value):void 0,l=typeof t?.gas!==e(350)?c(t[e(440)]):void 0,u=typeof t?.[e(345)]!==e(350)?c(t.gasLimit):void 0,p=typeof t?.[e(382)]!==e(350)?c(t.gasPrice):void 0,w=typeof t?.nonce!==e(350)?c(t.nonce):void 0,f=typeof t?.[e(286)]!==e(350)?c(t.maxFeePerGas):void 0,m=typeof t?.[e(491)]!==e(350)?c(t.maxPriorityFeePerGas):void 0,g=typeof t?.[e(500)]!==e(350)?c(t[e(500)]):void 0;if(typeof t?.[e(359)]!==e(350)&&!r)throw new Error(e(394));if(typeof t?.to!==e(350)&&!a)throw new Error(e(352));if(typeof t?.[e(502)]!==e(350)&&(!Number[e(316)](o)||"number"!=typeof o))throw new Error(e(466));if(void 0!==t?.[e(503)]&&typeof s===e(350))throw new Error(e(419));if(typeof t?.[e(351)]!==e(350)&&void 0===n)throw new Error(e(472));if(typeof t?.[e(440)]!==e(350)&&void 0===l)throw new Error(e(470));if(typeof t?.[e(345)]!==e(350)&&typeof u===e(350))throw new Error(e(371));if(typeof t?.[e(382)]!==e(350)&&typeof p===e(350))throw new Error("Invalid transaction gas price.");if(typeof t?.[e(473)]!==e(350)&&void 0===w)throw new Error(e(285));if(typeof t?.[e(286)]!==e(350)&&typeof f===e(350))throw new Error("Invalid transaction max fee per gas.");if(typeof t?.[e(491)]!==e(350)&&typeof m===e(350))throw new Error("Invalid transaction priority fee per gas.");if(void 0!==t?.type&&void 0===g)throw new Error("Invalid transaction type.");return d(t)}#q(t){const e=y;if(!t||typeof t!==e(331)||Array[e(366)](t))return;let r=t?.[e(425)];if(typeof r!==e(350))if(Array[e(366)](r)){const t=this.#E(r);if(!t.length||t[e(284)]!==r[e(284)])throw new Error("Invalid filter address.");r=t}else if(r=this.#m(r),!r)throw new Error(e(336));return{...t,...typeof r!==e(350)?{address:r}:{}}}#x(t){const e=y;if("number"==typeof t)return Number[e(342)](t)&&t>=0?r(t):void 0;if(typeof t!==e(370))return;const a=t.trim();return a?/^0x[0-9a-f]+$/i[e(300)](a)?a.toLowerCase():/^[0-9]+$/.test(a)?r(parseInt(a,10)):void 0:void 0}#v(){const t=y,e=this.#y()?.[t(402)](t(442)),r=this.#g(e);return void 0!==e&&(r&&JSON[t(346)](e)!==JSON[t(346)](r)?this.#y()?.[t(388)](t(442),r):r||this.#y()?.[t(495)](t(442))),r}#I(t){const e=y,r=this.#y(t?{storage:t}:void 0),a=r?.[e(402)]("chainId"),i=this.#b(a);return typeof a!==e(350)&&typeof i===e(350)&&r?.[e(495)](e(502)),i}#n(t){const e=y,r=this.#m(t);if(!r)return this.#o();const a=this[e(425)]?.[e(468)]();this.#y({storage:sessionStorage})?.[e(388)](e(425),r),this.#y()?.[e(388)]("address",r);const i=this[e(425)];a!==i?.[e(468)]()&&this[e(290)](e(439),i)}#o(){const t=y,e=this[t(425)]?.[t(468)]();this.#y({storage:sessionStorage})?.[t(495)](t(425)),this.#y()?.[t(495)](t(425));const r=this[t(425)];e!==r?.[t(468)]()&&this[t(290)](t(439),r)}#i(t){const e=y,r=this.chainId;let a,i=this.#b(t);const o=this.#v();if(typeof t===e(331)?(a=this.#g(t),i=this.#b(a?.[e(502)])):i&&this.#u?.[e(442)]?.[e(502)]&&this.#b(this.#u[e(442)][e(502)])===i?a=this.#g(this.#u[e(442)]):i&&o?.[e(502)]&&this.#b(o[e(502)])===i&&(a=o),!i)return this.#s();a?.[e(502)]?this.#y()?.[e(388)](e(442),a):this.#y()?.remove(e(442)),this.#y({storage:sessionStorage})?.[e(388)](e(502),i),this.#y()?.[e(388)]("chainId",i);const s=this.chainId;if(typeof window!==e(350)){const t=this.#w();t?.[e(421)]&&(t[e(502)]=s)}r!==s&&this[e(290)]("chainChanged",s)}#s(){const t=y,e=this.chainId;this.#y({storage:sessionStorage})?.[t(495)](t(502)),this.#y()?.[t(495)](t(502)),this.#y()?.[t(495)](t(442));const r=this[t(502)];if(typeof window!==t(350)){const e=this.#w();e?.[t(421)]&&(e[t(502)]=r)}e!==r&&this[t(290)](t(450),r)}#j(t,e=y(369)){const r=y;try{if(!t||e===r(428))return;if(e===r(369))return void t.focus?.();window[r(334)]?.();const a=document?.getElementById(r(501)),i=document?.[r(375)]("coinmeca-wallet-modal");a&&(a[r(338)]=-1,a.focus?.()),i?.[r(334)]?.(),t.focus?.()}catch{}}#h(){const t=y,e=this.#w(),r=Array[t(366)](e[t(310)])?e.providers:void 0,a=e.providerMap instanceof Map?e[t(498)]:void 0,i=[...(r||[]).filter(t=>t&&t!==this&&!t?.isCoinmecaWallet),this],o=a||new Map;o.set(t(349),this),Object[t(454)][t(343)][t(291)](e,t(310))?r?r[t(432)](0,r[t(284)],...i):e[t(310)]=i:Object[t(299)](e,"providers",{value:i,writable:!0,configurable:!0,enumerable:!1}),Object[t(454)][t(343)].call(e,t(498))?a||(e[t(498)]=o):Object[t(299)](e,t(498),{value:o,writable:!0,configurable:!0,enumerable:!1})}#W(t,e){const r=y,a=t?this.#a[r(402)](t):void 0;if(a){if(a[r(364)]?.(),this.#a[r(441)](t),"popup"===a[r(506)]&&this.#e===a[r(344)]){return void(![...this.#a[r(340)]()][r(332)](t=>t?.strategy===r(369)&&t?.portal===a[r(344)])&&(e?.[r(294)]||a[r(344)]?.[r(477)])&&(this.#e=void 0))}if(a.strategy===r(305)){return void(![...this.#a[r(340)]()][r(332)](t=>t?.[r(506)]===r(305)&&t?.[r(344)]===a[r(344)])&&e?.[r(294)]&&document?.[r(375)]("coinmeca-wallet-panel")?.[r(495)]())}document?.[r(375)](r(385)+t)?.[r(495)]()}}#L(t){const e=y;return typeof t===e(370)&&""!==t[e(391)]()&&!!l(t,e(444))}#N(t=y(369),e){const r=y;if(t===r(428))return t;const{discord:a,frame:i,telegram:o}=this.#l;return o||a||i?r(305):this.#L(e)?r(369):t}#U(t,e=y(369),r){const a=y;e=this.#N(e,t?.[a(459)]);const i=crypto[a(283)](),o=crypto.randomUUID(),s=this.#p(),n=s.origin,c=l(t?.[a(459)],e===a(428)?a(428):a(444));if(!c)throw new Error(a(497));let h=null;const d=document?.getElementById("coinmeca-wallet-panel"),p=document?.getElementById(a(320));switch(e===a(369)?this.#e&&!this.#e?.[a(477)]&&(h=this.#e,e=a(369),this.#f(h,{isPopup:!0}),this.#j(h,e)):"modal"===e&&d&&p?.[a(296)]&&(h=p[a(296)],e="modal",this.#f(h,{isModal:!0}),this.#j(h,e)),e){case a(369):if(h)break;if(this.#e&&!this.#e?.[a(477)])h=this.#e;else{this.#e=void 0;const t=new URL(c,s);h=this.#e=u(t.toString(),r)}h?(this.#f(h,{isPopup:!0}),this.#j(h,a(369))):e=a(305);break;case a(428):const t=document[a(287)](a(302));Object[a(426)](t.style,{position:a(479),display:a(361),bottom:"0",left:"0",width:"0",height:"0",margin:"0",padding:"0",opacity:"0",zIndex:a(446),border:a(361),pointerEvents:"none"});const o=new URL(c,s);t[a(326)]=o[a(435)](),t.id="coinmeca-wallet-proxy-"+i,document[a(434)].appendChild(t),h=t[a(296)],t[a(321)](a(289),()=>{const e=a;this.#f(t[e(296)],{isProxy:!0})})}switch(e){case a(305):if(h)break;if(d&&p?.[a(296)]){h=p.contentWindow,this.#f(h,{isModal:!0});break}document?.[a(375)](a(501))?.[a(495)]();const t=document[a(287)](a(445));t.id=a(501),Object.assign(t[a(424)],{position:"fixed",top:"0",left:"0",width:a(304),height:a(282),backgroundColor:a(486),zIndex:a(475),display:a(376),justifyContent:"center",alignItems:"center",overflow:a(397)});const e=document[a(287)](a(302));Object.assign(e[a(424)],{background:a(353),width:a(417),height:a(417),maxWidth:(typeof r===a(471)?r:r?.[a(451)]||384)+"px",maxHeight:(typeof r===a(471)?r:r?.[a(456)]||640)+"px",border:a(429),pointerEvents:"initial"});const i=new URL(c,s);e[a(326)]=i.toString(),e.id="coinmeca-wallet-modal",document[a(434)][a(292)](t),t[a(292)](e),h=e[a(296)],e.addEventListener("load",()=>{const t=a;this.#f(e[t(296)],{isModal:!0})}),this.#j(h,a(305))}const w={target:"coinmeca-wallet",id:i,nonce:o,strategy:e,request:t,storage:this.#u?.[a(405)]?.(),time:Math[a(488)]((new Date)[a(372)]()/1e3)};if(!h)throw e===a(428)?document?.getElementById(a(385)+i)?.[a(495)]():"modal"===e&&document?.[a(375)](a(501))?.[a(495)](),new Error(a(427));return{id:i,nonce:o,origin:n,portal:h,strategy:e,ready:!1,data:w}}async#k(t,e){const r=y;if(this.#N(e?.strategy||r(369),t)!==r(428))if(this.#e&&!this.#e?.[r(477)])this.#j(this.#e,"popup");else{const t=document?.getElementById(r(501)),e=document?.[r(375)](r(320));t&&e?.contentWindow&&this.#j(e.contentWindow,r(305))}const a=await p()[r(322)](()=>{})||void 0,i={method:t,params:e?.params,chainId:this[r(442)]?.chainId||this.#y({storage:sessionStorage})?.[r(402)](r(502))||this.#y()?.[r(402)](r(502)),app:{url:window.location[r(401)],name:w(),logo:a}},o=e?.size,s=e?.[r(506)]||"popup";return new Promise((t,e)=>{const a=r;let n,c,h,d,l,u,p,w,f,m,y;try{({portal:n,id:c,nonce:h,origin:d,strategy:l,ready:u,data:p}=this.#U(i,s,o))}catch(t){return void e(t)}const g=()=>{const t=v;try{n?.[t(437)](p,d)}catch{}},b=t=>{const e=v;t?.[e(503)]?.[e(467)]===e(482)&&t?.[e(503)]?.[e(319)]===e(314)&&(I(),g())},I=()=>{window[v(453)]("message",b),w&&clearInterval(w)},A=()=>{I(),f&&clearInterval(f),m&&clearInterval(m),y&&clearTimeout(y)};if(this.#a[a(388)](c,{method:i[a(459)],resolve:t,reject:e,portal:n,origin:d,nonce:h,strategy:l,cleanup:A}),u?g():(window[a(321)](a(393),b),g(),w=setInterval(()=>{const t=a;this.#a[t(347)](c)?g():I()},250)),n&&l===a(369))f=setInterval(()=>{const t=a;if(!n||n?.[t(477)]){if(A(),!this.#a[t(418)])return;[...this.#a[t(399)]()][t(390)](([,e])=>"popup"===e?.[t(506)]&&e?.[t(344)]===n).forEach(([e,r])=>{const a=t;this.#W(e),r[a(337)](new Error("User closed the window before approving the request."))})}},100);else{const t=l===a(428)?a(385)+c:"coinmeca-wallet-panel";m=setInterval(()=>{document?.getElementById(t)||(A(),y=setTimeout(()=>{const t=v;this.#a[t(347)](c)&&(this.#W(c),e(new Error(t(462))))},300))},100)}})}#c(t){const e=y,{target:r,id:a,nonce:i,method:o,state:s,result:n,error:c,close:h,strategy:d}=t[e(503)]||{},l=a?this.#a[e(402)](a):void 0,u=l?.[e(408)],p=l?.[e(337)];if(r===e(482)){if(!a&&h){const r=document?.[e(375)](e(320))?.[e(296)];if("modal"===d&&t.source===r)return void document?.[e(375)](e(501))?.[e(495)]();if(d===e(369)&&this.#e&&t[e(381)]===this.#e)return void(this.#e=void 0)}if(a&&l){if(t.origin!==l[e(401)]||i!==l.nonce||t[e(381)]!==l.portal)return;if(o!==l[e(459)])return;if(void 0!==n&&u)u(t[e(503)][e(436)]);else if(typeof c!==e(350))p&&p(new Error(t[e(503)][e(487)]));else if(h)p&&p(new Error(e(422)));else{if(void 0===h||!p)return;p(new Error("Wallet request response was empty."))}this.#W(a,{close:h})}}}#A={wallet:async(t,e)=>{const r=y,a=e?.[r(411)]?.data;return a&&f(a)?await this.#k(r(499),e):await this.#k(t,e)},rpc:async(t,r)=>{const a=y,i=this[a(442)]?.[a(443)]?.[0];if(!i)throw new Error(a(354));const o=await e(i,{method:t,params:r});if(o[a(503)][a(487)])throw new Error(a(308)+o[a(503)].error[a(393)]);return o[a(503)].result}};async[y(444)]({method:t,params:e}){const r=y;switch(t){case r(365):return this[r(425)];case r(407):return this[r(502)];case r(480):return this[r(502)]?o(this[r(502)]):void 0;case r(379):if(Array[r(366)](e)?!e?.[r(284)]:!e)throw new Error(r(356));const a=Array[r(366)](e)?e[0]:e,i=this.#C(a);if(!i)throw new Error(r(329));const s=this.#b(i[r(502)]),n=this.#b(this[r(502)]);if("number"==typeof s&&s!==n)throw new Error(r(301));if(typeof s!==r(471)&&typeof n!==r(471))throw new Error(r(354));return await this.#A[r(389)](t,Array[r(366)](e)?[i,...typeof e[1]!==r(350)?[e[1]]:[]]:[i]);case r(341):const c=this.#m(Array[r(366)](e)?e[0]:e);if((Array[r(366)](e)?typeof e?.[0]!==r(350):typeof e!==r(350))&&!c)throw new Error(r(458));const h=c||this[r(425)];if(!h)throw new Error(r(293));return await this.#A[r(389)](t,[h,Array[r(366)](e)&&void 0!==e?.[1]?e[1]:r(327)]);case r(494):const d=Array.isArray(e)?e[0]:e,l=this.#m(d);if(void 0!==d&&!l)throw new Error(r(358));if(!l)throw new Error(r(298));return await this.#A[r(389)](t,[l,Array.isArray(e)&&typeof e?.[1]!==r(350)?e[1]:r(327)]);case r(335):return await this.#A[r(483)](t,{strategy:r(428)})[r(368)](t=>this.#E(t));case"eth_requestAccounts":return await this.#A[r(483)](t)[r(368)](t=>{const e=r,a=this.#E(t);return a[e(284)]?(this.#n(a[0]),a):a});case r(400):const u=this.#m(Array.isArray(e)?e[0]:e);if((Array[r(366)](e)?void 0!==e?.[0]:typeof e!==r(350))&&!u)throw new Error(r(458));const p=u||this[r(425)];if(!p)throw new Error(r(293));return await this.#A[r(389)](t,[p,Array[r(366)](e)&&void 0!==e?.[1]?e[1]:r(327)]);case r(398):throw new Error(r(478));case r(374):return await this.#A[r(483)](t,{params:e}).then(t=>{if(t)return t});case r(378):return await this.#A[r(483)](r(378),{params:e})[r(368)](t=>{if(t)return t});case r(438):return await this.#A[r(483)](r(438),{params:e})[r(368)](t=>{if(t)return t});case r(404):return await this.#A[r(483)](t,{params:Array.isArray(e)?e[0]:e}).then(t=>{if(t)return t});case r(433):return await this.#A.wallet(t,{params:Array[r(366)](e)?e[0]:e}).then(t=>{if(t)return t});case"wallet_addEthereumChain":return await this.#A[r(483)](t,{params:Array[r(366)](e)?e[0]:e})[r(368)](t=>{if(t)return!0});case r(415):const w=this.#b(Array[r(366)](e)?e[0]:e);if("number"!=typeof w)throw new Error(r(447));const f=this.#b(this[r(502)]);return typeof f===r(471)&&f===w||await this.#A[r(483)](t,{params:Array[r(366)](e)?e[0]:e}).then(t=>{if(t)return typeof w===r(471)&&this.#i(w),!0});case r(485):return await this.#A.wallet(t,{params:Array[r(366)](e)?e[0]:e}).then(t=>{if(t)return t});case"eth_newFilter":const m=Array[r(366)](e)?e[0]:e,y=this.#q(m);if(!y)throw new Error(r(362));return await this.#A[r(389)](t,[y]);case r(309):const g=this.#x(Array[r(366)](e)?e[0]:e);if(!g)throw new Error("Invalid filter id.");return await this.#A[r(389)](t,[g]);case r(476):if(Array.isArray(e)?!e?.length:!e)throw new Error(r(474));const v=this.#x(Array.isArray(e)?e[0]:e);if(!v)throw new Error(r(410));return await this.#A.rpc(t,[v]);case"eth_getStorageAt":if(Array[r(366)](e)?!e?.[r(284)]:!e)throw new Error("No address or position provided");const b=Array[r(366)](e)?e[0]:e,I=this.#m(b);if(!I)throw new Error(r(358));const A=Array[r(366)](e)?e[1]:e?.[r(325)];if(typeof A===r(350))throw new Error(r(416));return await this.#A[r(389)](t,Array[r(366)](e)?[I,A,void 0!==e[2]?e[2]:r(327)]:[I,A,typeof e?.block!==r(350)?e[r(318)]:"latest"]);case"eth_blockNumber":case"eth_gasPrice":case"eth_protocolVersion":case r(414):case"eth_mining":case"eth_hashrate":return await this.#A[r(389)](t);case r(412):case r(423):throw new Error(t+r(295));default:throw new Error("Method '"+t+r(317))}}}export{I as CoinmecaWalletAdapter}; //# sourceMappingURL=adapter.js.map