UNPKG

@coinmeca/wallet-sdk

Version:
3 lines (2 loc) 12.8 kB
import{C as e}from"./core-C6VcTWK5.js";import{fetchFromProvider as t}from"@ethereumjs/util";import{formatChainId as r,loadStorage as a,openWindow as n,getFaviconUri as s,getAppName as i,parseChainId as o,parse as c}from"./utils.js";import"eventemitter3";import"crypto-js";import"ethereum-cryptography/utils";function h(e,t){const r=l();return(h=function(e,t){return r[e-=392]})(e,t)}const d=h;function l(){const e=["Method '","1248672YtVdTV","-999999999","length","eth_newFilter","1px solid rgba(255,255,255,.3)","latest","clear","result","coinmeca-wallet-proxy-","freeze","999999999","rgba(0, 0, 0, 0.6)",":chain","381648SKRvZK","4499852tOvHtC","eth_filterChanges","contentWindow","51713VnjgvD",'[id^="coinmeca-wallet-panel-"]',"removeEventListener","ready","center","black","assign","coinmeca:wallet","eth_getBalance","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+SX4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iprCqCyI13/fNV+ZmX1YDMwgms0irMmEz0TCGEahS4538h4qljdoWDMZ3nTToWvbHrTd1M4ehbqCaS8OM7YWTdY/3feh/ta2LOcULdfvzD+tT99w2jJhS5nvmN1ZzvXO1mhq5ZQOM+yhqCL+B+AWe5nrKa3ZAAAAAElFTkSuQmCC","net.coinmeca.wallet","proxy","undefined","getElementById","eth_signTypedData_v4","request","closed","remove","ethereum","providerMap","get",":chainId","location","eth_syncing","eth_unsubscribe","wallet_switchEthereumChain","then","eth_blockNumber","Provider URL was not setup yet.","eth_gasPrice","iframe","method","host","message","No transaction parameters provided","body","0x095ea7b3","eth_protocolVersion","tdesktop","eth_accounts","eth_getCode","100vh","load","delete","2119950XoTCRv","dispatchEvent","bind","none"," is not supported. Subscription methods are not available in this wallet",'[id^="coinmeca-wallet-proxy-"]',"732hiRjFs","100%","eth_coinbase","chain","coinmeca-wallet","storage","modal","resolve","addEventListener","eth_signTransaction","origin","postMessage","/request/","WebApp","eip6963:announceProvider","erc20_approve","The given parameter is incorrect.","div","eth_signTypedData","absolute","chainId","createElement","No chainId provided","error","99VlGhFu","randomUUID","CoinmecaWallet","rpcUrls","popup","style","flex","forEach","User closed the window before approving the request.","key","11757OTyZkQ","wallet_addEthereumChain","balance","No filter ID provided","eth_mining","hidden","rpc","set",":address","coinmeca-wallet-","5806880wuHKSh","startsWith","target","appendChild","isCoinmecaWallet","decimals","strategy","eth_hashrate","src","wallet_watchAsset","newValue","No chain information provided","' was rejected.","eip6963:requestProvider","eth_uninstallFilter","https://wallet.coinmeca.net","object","wallet","querySelectorAll","'eth_sign' is depreacted request method. Please request again with 'personal_sign' or 'eth_signTypedData'.","platform","size","address","storageArea","fixed","Request '","state","20VqgoCY","getTime","initial","number","100vw","isArray","Error rejecting '","' not supported","data","coinmeca","height","eth_sendTransaction"];return(l=function(){return e})()}!function(){const e=h,t=l();for(;;)try{if(478449===-parseInt(e(410))/1*(-parseInt(e(531))/2)+parseInt(e(494))/3*(-parseInt(e(460))/4)+parseInt(e(454))/5+-parseInt(e(393))/6+-parseInt(e(407))/7+-parseInt(e(406))/8*(-parseInt(e(484))/9)+parseInt(e(504))/10)break;t.push(t.shift())}catch(e){t.push(t.shift())}}();class w extends e{#e=d(417);#t;#r=new Map;constructor(e){const t=d;super();const{chainId:r,rpcUrls:a,nativeCurrency:n}=e?.[t(463)]||{};r&&a&&a[t(395)]&&n&&n?.[t(509)]&&this.#a(e?.[t(463)]);window[t(468)]("storage",(e=>{const r=t;if(e[r(527)]!==localStorage||!e[r(514)])return;const{key:a,newValue:n}=e,s=c(n);if(s)switch(a){case this.#e+r(502):this.#n(s);break;case this.#e+r(405):s?.chainId&&this.#a(s[r(480)]);break;case this.#e+r(431):this.#a(s)}}));const s=new CustomEvent(t(474),{detail:{info:{name:"Coinmeca Wallet",icon:t(419),uuid:crypto.randomUUID(),rdns:t(420)},provider:this}});window[t(455)](s),window[t(468)](t(517),(()=>window[t(455)](s))),window[t(468)](t(443),this.#s[t(456)](this)),window[t(428)]={...window[t(428)],providers:[...window?.[t(428)]?.providers?.filter((e=>e?.isCoinmecaWallet))||[],this],providerMap:new Map([...window[t(428)]?.[t(429)]||[],[t(486),this]])},Object[t(402)](this)}get#i(){const e=d;return typeof window!==e(422)?window.Telegram?.[e(473)]:void 0}get#o(){const e=d;return window?.[e(540)]?.wallet}get[d(508)](){return!0}get[d(526)](){const e=d;return this.#o?.[e(526)]||this.#c({storage:sessionStorage})?.[e(430)]("address")||this.#c()?.[e(430)]("address")}get[d(463)](){const e=d;return this.#o?.[e(463)]||this.#c()?.[e(430)](e(463))}get[d(480)](){const e=d;return r(this.#o?.[e(463)]?.[e(480)]||this.chain?.[e(480)])||"0x1"}async getAddress(){return this.address}async balance(){const e=d;return await this.#h[e(500)](e(418),[this[e(526)],e(398)])}#c(e){const t=d,r=a(this.#e,e?.[t(465)]||localStorage,!1,e?.[t(493)]);return Object.freeze(r)}#n(e){const t=d;this.#c({storage:sessionStorage})?.[t(501)](t(526),e),this.#c()?.[t(501)](t(526),e)}#a(e){const t=d;typeof e===t(520)&&(this.#c()?.[t(501)](t(463),e),e=e?.chainId),typeof window!==t(422)&&(window[t(428)][t(480)]=r(e)),this.#c({storage:sessionStorage})?.[t(501)](t(480),e),this.#c()?.[t(501)]("chainId",e)}#d(e,t="popup",r){const a=d;t=t!==a(421)&&this.#i?.[a(524)]===a(448)?a(466):t;const s=crypto[a(485)](),i={target:a(464),id:s,strategy:t,request:e,time:Math.floor((new Date)[a(532)]()/1e3)};let o;switch(window[a(471)]({target:i[a(506)]},window[a(432)][a(470)]),t){case a(488):o=this.#t?this.#t:this.#t=n("https://wallet.coinmeca.net"+a(472)+e?.[a(441)],r);break;case a(421):const t=document[a(481)](a(440));Object.assign(t[a(489)],{position:a(479),display:a(457),bottom:"0",left:"0",width:"0",height:"0",margin:"0",padding:"0",opacity:"0",zIndex:a(394),border:"none",pointerEvents:a(457)}),t.src=(a(519)||window[a(432)].origin)+"/proxy/request/"+e?.method,t.id=a(401)+s,document[a(445)].appendChild(t),o=t[a(409)],o[a(468)](a(452),(()=>{o[a(540)]={isProxy:!0}}));break;case"modal":const i=document[a(481)](a(477));i.id="coinmeca-wallet-panel-"+s,Object.assign(i[a(489)],{position:a(528),top:"0",left:"0",width:a(535),height:a(451),backgroundColor:a(404),zIndex:a(403),display:a(490),justifyContent:a(414),alignItems:"center",overflow:a(499)});const c=document[a(481)](a(440));Object[a(416)](c[a(489)],{background:a(415),width:a(461),height:a(461),maxWidth:("number"==typeof r?r:r?.width||384)+"px",maxHeight:(typeof r===a(534)?r:r?.[a(541)]||640)+"px",border:a(397),pointerEvents:a(533)}),c[a(512)]=(a(519)||window[a(432)][a(470)])+a(472)+e?.method,c.id="coinmeca-wallet-modal-"+s,document[a(445)][a(507)](i),i[a(507)](c),o=c.contentWindow,o[a(468)](a(452),(()=>{o.coinmeca={isModal:!0}}))}const c=e=>{const t=a;e?.[t(539)]?.target===t(464)&&e?.[t(539)]?.[t(530)]===t(413)&&(o[t(471)](i,t(519)||window[t(432)].origin),window[t(412)](t(443),c))};return window.addEventListener(a(443),c),{id:s,portal:o,strategy:t}}async#l(e,t){const r=d,a={method:e,params:t?.params,chainId:this[r(463)]?.[r(480)],app:{url:window[r(432)][r(442)],name:i(),logo:await s()}},n=t?.[r(525)],o=t?.[r(510)]||r(488);return new Promise((async(e,t)=>{const s=r,{portal:i,id:c}=this.#d(a,o,n);if(this.#r[s(501)](c,{method:a[s(441)],resolve:e,reject:t}),i&&o===s(488)){const e=setInterval((()=>{const r=s;(!i||i?.[r(426)])&&(this.#t=void 0,clearInterval(e),this.#r[r(525)]&&(this.#r[r(491)]((({method:e,reject:t},a)=>{const n=r;try{t(new Error(n(529)+e+n(516)))}catch(t){console[n(483)](n(537)+e+"':",t)}})),this.#r[r(399)](),t(new Error(r(492)))))}),100)}this.#r.set(c,{method:a.method,resolve:e,reject:t})}))}#s(e){const t=d,{target:r,id:a,strategy:n,result:s,error:i,close:o}=e[t(539)],c=this.#r[t(430)](a)?.[t(467)],h=this.#r[t(430)](a)?.reject;"coinmeca-wallet"===r&&(a&&this.#r.has(a)?(typeof s!==t(422)&&c&&c(e[t(539)][t(400)]),typeof i!==t(422)&&h&&h(new Error(e[t(539)].error)),o?(document?.[t(423)](t(503)+(n===t(421)?t(421):"panel")+"-"+a)?.[t(427)](),1===this.#r[t(525)]&&(this.#t=void 0)):new Error(e[t(539)][t(483)]),this.#r[t(453)](a)):(n===t(421)||n===t(466))&&(document.querySelectorAll(t(411))[t(491)]((e=>e[t(427)]())),document[t(522)](t(459)).forEach((e=>e[t(427)]()))))}#h={wallet:async(e,t)=>{const r=d,a=t?.params?.data;return a&&a?.[r(505)](r(446))?await this.#l(r(475),t):await this.#l(e,t)},rpc:async(e,r)=>{const a=d,n=this[a(463)]?.[a(487)]?.[0];if(!n)return new Error(a(438));const s=await t(n,{method:e,params:r});if(s.data[a(483)])throw new Error("RPC Error: "+s[a(539)][a(483)][a(443)]);return s[a(539)][a(400)]}};async[d(425)]({method:e,params:t}){const a=d;switch(e){case a(462):return this[a(526)];case"eth_chainId":return this[a(480)];case"net_version":return o(this[a(480)]);case"eth_estimateGas":if(Array[a(536)](t)?!t?.length:!t)throw new Error("No transaction parameters provided");return await this.#h.rpc(e,t);case"eth_getTransactionCount":return await this.#h[a(500)](e,[this[a(526)],a(398)]);case a(450):return await this.#h[a(500)](e,[(t?.[0]||t)?.[a(526)],a(398)]);case a(449):return await this.#h.wallet(e,{strategy:a(421)});case"eth_requestAccounts":return await this.#h[a(521)](a(449),{strategy:a(421)})[a(436)]((async t=>{const r=a;return t?.[r(395)]?[t[0]]:await this.#h[r(521)](e).then((e=>{if(e)return this.#n(e?.[0]),e}))}));case a(418):return await this[a(496)]();case"eth_sign":throw new Error(a(523));case"personal_sign":if(!t||!t.length)throw new Error(a(476));return await this.#h.wallet(e,{params:t}).then((e=>{if(e)return e}));case"eth_signTypedData":if(!t||!t?.[a(395)])throw new Error(a(476));return await this.#h[a(521)](a(478),{params:t}).then((e=>{if(e)return e}));case"eth_signTypedData_v4":if(!t||!t?.[a(395)])throw new Error(a(476));return await this.#h[a(521)](a(424),{params:t})[a(436)]((e=>{if(e)return e}));case a(469):throw new Error("'eth_signTransaction' is depreacted request method.");case a(542):if(Array[a(536)](t)?!t?.[a(395)]:!t)throw new Error("No transaction parameters provided");return await this.#h.wallet(e,{params:t?.[0]||t}).then((e=>{if(e)return e}));case a(495):if(Array[a(536)](t)?!t?.[a(395)]:!t)throw new Error(a(515));return await this.#h[a(521)](e,{params:t?.[0]||t})[a(436)]((e=>{if(e)return this.#a(e),e}));case a(435):if(Array[a(536)](t)?!t?.length:!t)throw new Error(a(482));return this[a(480)]&&this[a(480)]===r((t?.[0]||t)?.[a(480)])?this[a(463)]:await this.#h[a(521)](e,{params:t?.[0]||t})[a(436)]((e=>{if(e)return this.#a(e),e}));case a(513):if(Array[a(536)](t)?!t?.length:!t)throw new Error("No asset information provided");return await this.#h[a(521)](e,{params:t?.[0]||t})[a(436)]((e=>{if(e)return e}));case a(396):case a(408):return await this.#h.rpc(e,t);case a(518):if(Array.isArray(t)?!t?.[a(395)]:!t)throw new Error(a(497));return await this.#h[a(500)](e,t);case"eth_getStorageAt":if(Array[a(536)](t)?!t?.length:!t)throw new Error("No address or position provided");return await this.#h[a(500)](e,t);case a(437):case a(439):case a(447):case a(433):case a(498):case a(511):return await this.#h[a(500)](e);case"eth_subscribe":case a(434):throw new Error(e+a(458));default:throw new Error(a(392)+e+a(538))}}}export{w as CoinmecaWalletAdapter}; //# sourceMappingURL=adapter.js.map