@coinmeca/wallet-sdk
Version:
3 lines (2 loc) • 17.3 kB
JavaScript
import{Common as t}from"@ethereumjs/common";import{Wallet as e}from"@ethereumjs/wallet";import{fetchFromProvider as s,ecsign as n,toRpcSig as r}from"@ethereumjs/util";import{TransactionFactory as i}from"@ethereumjs/tx";import{keccak256 as o}from"ethereum-cryptography/keccak";import a from"crypto-js";import{C as c}from"./core-DZgYDyNF.js";import{selectors as h}from"./selectors.js";import{encrypt as d,parse as u,formatChainId as f,parseChainId as g,valid as l,flattenMessage as m}from"./utils.js";import{CoinmecaSecureStorage as p}from"./storage.js";import"eventemitter3";import"ethereum-cryptography/utils";const w=y;function y(t,e){const s=b();return(y=function(t,e){return s[t-=320]})(t,e)}function b(){const t=["import",":chain","emit",":address","some","lock","There is no accounts that setup yet.","map",") is something wrong","fungibles","reset","Notification clicked!","Notification closed!","The given tokenId(","resolve","eth_sendRawTransaction","value","chainId","Chain not registered yet.","utf-8","Invalid app information.","chainUpdated","focus","1126825lSKJEP","length","substring","warn","getAddressString","updateReceipts","561701xMtzJB","fromTxData","nftUpdated","Couldn't found a current account information.","There is no message to sign.","48162NqePNf","Not found account info","1413pdxPcy","freeze","onclose","options","pending","type","accountChanged","unlock","addNonFungibleAsset","custom","Account ","coinmeca","The account information for adding the asset could not be found.","send","eth_getTransactionReceipt","hash","hasOwnProperty","removeNonFungibleAsset","Wallet already initialized.","user","number","toString","ethereum","There is no any chain registered.","string","txUpdated","isInitialized"," failed.","Transaction Confirmed","init","binary","clear","appUpdated","WebApp","2038872aRYNGd","21256WaaiPC","No receipt found for transaction ","concat","fromPrivateKey","SHA256","toLowerCase","address","The account information for removing the asset could not be found.","Invalid key entered.","Wallet is not setup yet.","disable","status","chains","nonFungibles","chainChanged","Notification permission is denied. Please enable it in your browser settings.","EIP712Domain","secure","denied","changeChain","Invalid typed data structure. Required fields: domain, types, primaryType, message.","serialize","filter","wait","The given address(","check","changeAccount","updateContacts","842022BSUvOE","0x1","Address does not match selected wallet address.","change"," was confirmed.","updateApp","find","Provider URL was not setup yet.","There is no signer information.","Transaction Failed","get","initDataUnsafe","Cannot access to the information of accounts.","contact","object","undefined","common","497lnosSD","randomUUID","revokeApp","from","requestPermission","signTypedData","addEthereumChain","tokenUpdated","coinmeca:wallet","key","url",", retrying...","switchEthereumChain","floor","hex","index","contactUpdated","removeEthereumChain","accountUpdated","then","updateAccount","startsWith","Your transaction ","permission","trim","isLocked","Notification permission denied.","tokens","set","account","remove","log","1286992dUUTlT","revokeAccount","Telegram","userId","apps","defineProperty","chain","name","evm","accounts","addFungibleAsset","getSenderAddress",":seed"];return(b=function(){return t})()}!function(){const t=y,e=b();for(;;)try{if(342208===parseInt(t(328))/1+parseInt(t(447))/2+-parseInt(t(398))/3+-parseInt(t(369))/4+-parseInt(t(322))/5+-parseInt(t(333))/6*(-parseInt(t(415))/7)+-parseInt(t(370))/8*(parseInt(t(335))/9))break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const I=({icon:t,title:e,body:s,onClick:n,onClose:r})=>{const i=y;function o(){const n=y,r=new Notification(e,{icon:t,body:s});r.onclick=()=>{const t=y;console[t(446)](t(471)),window[t(321)]()},r[n(337)]=()=>{const t=n;console[t(446)](t(472))}}"granted"===Notification[i(438)]?o():Notification[i(438)]!==i(388)?Notification[i(419)]()[i(434)]((t=>{const e=i;"granted"===t?o():console.log(e(441))})):console[i(446)](i(385))};class k extends c{#t=w(423);#e;#s;#n;constructor(t){const e=w;super();const s=this.#r?this.#i?.CloudStorage:localStorage;this.#s=new p(s,d(this.#t,this.#t),{codename:this.#t,emit:(t,e)=>{const s=y,n=e?.[s(424)],r=e?.[s(476)];if(this.emit(t),r)switch(n){case this.#t+s(463):return this[s(396)](u(r));case this.#t+s(461):return this.changeChain(u(r)?.[s(477)]);case this.#t+":chainId":return this[s(389)](u(r));default:console[s(446)]("event",{key:n,value:r})}}});const{key:n,address:r,chainId:i,sessionId:o}=t||{},a=this.#o();if(this.#e=n,this.#n=o,r)n?this[e(396)](r):a?.set(e(376),r);else{const t=a?.get("address");t&&this[e(396)](t)}if(typeof window!==e(413)&&(window[e(357)]={...window?.[e(357)],chainId:this[e(477)]}),i&&a?.get(e(382))?.[e(404)]((t=>t?.chainId===i)))this[e(389)](i);else{const t=a?.[e(408)](e(477));t&&this.changeChain(t?.[e(477)])}Object[e(336)](this),Object[e(452)](window,e(346),{value:{wallet:this},writable:!1,configurable:!1,enumerable:!1})}#a(t){const e=w;return this.#c?t(this.#c):this[e(361)]?void 0:new Error(e(410))}#o(t){const e=w;return this.#s?.[e(387)](t)}#h(t){const s=w;return e[s(373)](Buffer[s(418)](t[s(356)]()[s(439)]()[s(324)](0,64),"hex"))}#d(t){const e=w;return t=a[e(374)](this.#u+":"+t)[e(356)](),this.#o(t).get(t)}#f(t){const e=w;return"string"==typeof t&&(t=this.#g?.get(t?.[e(375)]())?.index),this.#a((s=>{const n=e,r=this.#g?.[n(408)](s+n(459));if(r?.[n(323)]){const e=r[t];if(e)return e;throw new Error(n(334))}throw new Error(n(379))}))}get#u(){const t=w;return this.#o()?.[t(408)](t(450))}get#c(){return this.#e}get#g(){return this.#a((t=>this.#o(t)))}get#l(){}get#i(){const t=w;return"undefined"!=typeof window?window.Telegram?.[t(368)]:void 0}get#r(){const t=w,e=this.#i?.[t(409)]?.[t(354)];return!(!this.#i||!e?.id)}async#m(t,e){const n=w,r=this.chain?.rpcUrls?.[0];return r?await s(r,{method:t,params:e}):new Error(n(405))}get isInitialized(){return!!this.#u}get[w(440)](){return!this.#c}get address(){return this.#o()?.get("address")}account(t){const e=w;return this.#g?.[e(408)]?.((t||this.address)?.toLowerCase())}[w(456)](t){const e=w;try{return((t&&""!==t?this.apps?.find((s=>s?.[e(425)]?.[e(375)]()===t?.toLowerCase()))?.[e(456)]:this.#a((t=>this.#g?.[e(408)](t+e(459))?.[e(467)]((t=>this.#h(t)?.[e(326)]()))))?.map((t=>this.#g?.[e(408)](t?.[e(375)]()))))||[])[e(392)]((t=>t))}catch(t){return[]}}allowance(t,e){const s=w;return e=e||this[s(376)],!!t&&""!==t&&!!e&&""!==e&&this[s(456)](t)?.[s(464)]((t=>t?.toLowerCase()===e?.[s(375)]()))}get[w(477)](){const t=w;return f(this.#o()?.[t(408)]("chainId")||1)}get[w(453)](){const t=w;return this[t(382)]?.[t(404)]((e=>e?.[t(477)]===g(this[t(477)]||t(399))))}get[w(382)](){const t=w;return this.#o()[t(408)](t(382))||[]}get[w(451)](){const t=w;return this.#o()[t(408)](t(451))||[]}get[w(411)](){const t=w;return this.#o()[t(408)](t(411))||[]}[w(364)](t){const e=w;this.#u&&new Error(e(353));const s=this.#r?window?.[e(449)]?.WebApp?.[e(409)]?.[e(354)]:crypto[e(416)]();this.#o()?.[e(443)]("userId",s);const n=a[e(374)](s+":"+t)[e(356)]();this.#e=n,this.#g?.set(n,n),this[e(389)](1)}[w(470)](){const t=w;this.#o()?.[t(366)]()}[w(465)](){const t=w;this.#o()?.[t(443)](t(376),this[t(444)]()?.address),this.#e=void 0}[w(395)](t){const e=w;return!!this.#d(t)?.[e(375)]()}[w(342)](t){const e=w,s=this.#d(t);if(this[e(395)](t)){this.#e=s;const t=this[e(456)]();let n;if(t?.[e(323)]){const s=this[e(376)]||this.#g?.[e(408)]("address")||t?.[0]?.[e(376)];n=s&&this.#g?.[e(408)](s?.[e(375)]()),n&&this[e(396)](n?.[e(430)])}return this[e(462)]("unlock",n||!0),!0}throw new Error(e(378))}exist(t){return this.#a((e=>{const s=y;if(t&&""!==t&&t?.startsWith("0x"))switch(t?.[s(323)]){case 42:const n=t;return this.accounts()?.[s(464)]((t=>t?.address?.[s(375)]()===n?.[s(375)]()))??!1;case 64:const r=t,i=this.#g?.get(e+s(459))||[];return i?.[s(464)]((t=>t?.[s(375)]()===r?.toLowerCase()))??!1;default:return}}))}create(){return this.#a((t=>{const e=y,s=this.#g?.get(t+e(459))||[],n=s?.[e(323)],r=a[e(374)](t+":"+n)[e(356)](),i=this.#h(r)?.[e(326)]();return!!i&&(s?.some((t=>t?.toLowerCase()===r?.[e(375)]()))||this.#g?.[e(443)](t+e(459),[...s,r]),this.#o()?.[e(408)](i?.[e(375)]())||this.#g?.set(i?.toLowerCase(),{address:i,index:n,name:e(345)+(n+1)}),this[e(396)](n),!0)}))}[w(460)](t){return this.#a((e=>{const s=y,n=this.#g?.[s(408)](e+s(459))||[],r=this.#o()?.[s(408)]("accounts")||[],i=this.#h(t)[s(326)]();let o=r?.[s(323)];return!!i&&(n?.some(((e,n)=>{const r=s,i=e?.[r(375)]()===t?.[r(375)]();if(i)return o=n,i}))||this.#g?.[s(443)](e+s(459),[...n,t]),this.#o()?.[s(408)](i?.[s(375)]())||this.#g?.[s(443)](i?.[s(375)](),{address:i,index:o,name:s(345)+(o+1)}),this[s(396)](o),!0)}))}[w(401)](t,e){const s=w,n=this.#d(t),r=a[s(374)](this.#u+":"+t)[s(356)]();this.#o(r)[s(445)](r);const i=a.SHA256(this.#u+":"+e)[s(356)]();this.#o(i)[s(443)](i,n)}changeAccount(t){const e=w;if(typeof t===e(413))return;if("number"!=typeof(t=typeof t===e(359)?this.#g?.[e(408)](t?.[e(375)]())?.[e(430)]:t))return;const s=this[e(456)]()?.[t];if(!s)throw new Error(e(466));return this.#o()?.[e(443)](e(376),s?.[e(376)]),this[e(462)](e(341),s?.[e(376)]),s?.[e(376)]}changeChain(t){const e=w;if(!t)return;t=typeof t===e(359)?t?.startsWith("0x")?g(t):parseInt(t):t;const s=this[e(382)];if(s?.[e(323)]&&s?.[e(404)]((s=>s?.[e(477)]===t)))return this.#o()?.[e(443)]("chainId",t),this[e(462)](e(384),f(t)),t;throw new Error(e(358))}[w(435)](t){const e=w;this.#g?.[e(443)](t?.[e(376)]?.[e(375)](),{...this.#g?.get(t?.[e(376)]?.[e(375)]()),name:t?.[e(454)],disable:t?.[e(380)]}),this[e(462)](e(433),t)}updateChain(t){const e=w;this.#o()?.set(e(382),[t,...this[e(382)]?.[e(392)]((s=>s?.[e(477)]!==t?.[e(477)]))]),this[e(462)](e(320),t)}[w(403)](t){const e=w;return this.#o()?.[e(443)](e(451),[t,...this[e(451)]?.[e(392)]((s=>s?.url?.[e(375)]()!==t?.[e(425)]?.[e(375)]()))]),this.emit(e(367))}[w(417)](t){const e=w;return this.#o()?.[e(443)](e(451),this[e(451)]?.filter((s=>s?.[e(425)]?.[e(375)]()!==t?.[e(375)]()))),this[e(462)](e(367))}[w(448)](t,e){const s=w;if(typeof(e=typeof e===s(359)?this.#g?.[s(408)](e?.[s(375)]())?.index:e)!==s(355))return;const n=this[s(456)]()?.[e];return this.#o()?.set(s(451),this[s(451)]?.[s(467)]((e=>e?.[s(425)]?.toLowerCase()===t?.[s(375)]()?{...e,accounts:e?.[s(456)]?.[s(392)]((t=>t?.[s(375)]()!==n?.[s(376)]?.[s(375)]()))}:e))),this[s(462)](s(367))}async[w(421)](t){const e=w,{chainId:s,rpcUrls:n,nativeCurrency:r,base:i}=t;if(i&&i!==e(455))throw new Error("Chain base doesn't EVM based.");if(!(s&&n&&n[e(323)]&&r.decimals))throw new Error("Invalid chain parameters. `chainId` and at least one `rpcUrls` are required.");const o=this.#o()?.[e(408)](e(382))||[],a=o?.find((s=>s?.[e(477)]===t[e(477)]));return this.#o()?.[e(443)](e(382),[{...a,...t},...o?.filter((t=>t?.[e(477)]!==s))]),this[e(462)]("chainUpdated"),!0}[w(432)](t){const e=w;if(!t)return;let s=typeof t===e(412)?t?.[e(477)]:t;s=typeof s===e(359)?s?.[e(436)]("0x")?g(s):parseInt(s):s;let n=this[e(382)];if(s===this[e(453)][e(477)]&&this.changeChain(1),n?.[e(323)]&&n?.[e(404)]((t=>t?.[e(477)]===s)))return this.#o()?.set(e(382),n?.[e(392)]((t=>t?.[e(477)]!==s))),this[e(462)]("chainUpdated"),s;throw new Error(e(358))}async[w(427)](t){const e=w;t=typeof t===e(359)?t?.[e(436)]("0x")?g(t):parseInt(t):t;const s=this.#o()?.get(e(382))||[],n=s?.[e(404)]((s=>s?.[e(477)]===t));if(n)return this[e(453)]?.[e(477)]!==n?.chainId&&this[e(389)](t),n;throw new Error(e(478))}async requestAccounts(t,e){const s=w;if(e=e||this[s(376)]){const n=this[s(451)];if(t?.url){const r={...n?.find((e=>e?.[s(425)]?.[s(375)]()===t?.[s(425)]?.[s(375)]())),...t},i=[e,...(r?.accounts||[])?.filter((t=>t?.[s(375)]()!==e?.toLowerCase()))][s(392)]((t=>t));return t={...r,accounts:i},this.#o()[s(443)](s(451),[t,...n?.[s(392)]((e=>e?.[s(425)]?.[s(375)]()!==t?.[s(425)]?.toLowerCase()))]),this[s(462)](s(367)),i}throw new Error(s(480))}throw new Error(s(331))}async sign(e,s){const n=w;s="object"==typeof s?s?.[n(430)]:this.#g?.[n(408)](s?.toLowerCase())?.[n(430)];const r=this[n(382)]?.[n(404)]((t=>t?.[n(477)]===g(e?.chainId)))||this[n(453)],o=i.fromTxData(e,{common:t[n(344)]({chainId:r?.[n(477)]})}).sign(Buffer.from(this.#f(s),n(429)));return"0x"+Buffer[n(418)](o[n(391)]())[n(356)](n(429))}async signMessage(t){const e=w,s=l[e(376)](t[0]),i=l.address(t[1]);let a,c;if(!s&&!i)throw new Error(e(406));if(i?(c=t[1],a=t[0]):(c=t[0],a=t[1]),!a||!a?.length)throw new Error(e(332));if(c.toLowerCase()!==this.address.toLowerCase())throw new Error(e(400));const{v:h,r:d,s:u}=n(o(Buffer[e(418)]("Ethereum Signed Message:\n"+a[e(323)]+a,e(479))),this.#f(c));return r(h,d,u)}async[w(420)](t,e){const s=w;typeof t===s(359)&&(t=u(t));const{domain:i,primaryType:a,types:c,message:h,signer:d}=t;if(!(i&&c&&a&&h))throw new Error(s(390));isNaN(Number(i?.options?.[s(477)]))||Number(i?.[s(338)]?.[s(477)]),e=e||d||this[s(376)];const f=m(c,i,s(386)),g=m(c,h,a),l=o(Buffer[s(372)](f)),p=o(Buffer.concat(g)),y=o(Buffer[s(372)]([Buffer[s(418)]("",s(365)),l,p])),{v:b,r:I,s:k}=n(y,this.#f(this.address));return r(b,I,k)}async[w(348)](e,s){const n=w;s=typeof s===n(412)?s?.[n(430)]:this.#g?.[n(408)](s?.[n(375)]())?.[n(430)];const r=this.chains?.[n(404)]((t=>t?.[n(477)]===g(e?.chainId)))||this.chain,o=i[n(329)](e,{common:t[n(344)]({chainId:r?.chainId})}).sign(Buffer.from(this.#f(s),n(429))),a=await this.#m(n(475),["0x"+Buffer[n(418)](o[n(391)]()).toString(n(429))]),c=o?.[n(414)]?.chainId()?.[n(356)]();let d=this[n(444)](o[n(458)]()?.[n(356)]());return c&&d&&(this.#g?.[n(443)](d?.[n(376)]?.[n(375)](),{...d,tx:{...d?.tx,[c]:[{hash:a,status:n(339),category:h?.[("0x"+Buffer[n(418)](o.data)[n(356)](n(429)))[n(324)](0,10)],time:Math[n(428)]((new Date).getTime()/1e3),no:d?.tx?.[c]?.[n(323)]||0,to:e?.to},...(d?.tx?.[c]||[]).filter((t=>t?.[n(350)]?.toLowerCase()!==a?.toLowerCase()))]}}),this[n(462)](n(360)),e?.to&&this[n(397)](e?.to?.[n(356)](),{type:"recent"})),Promise[n(474)]()[n(434)]((()=>this[n(393)](a))),a}async receipt(t,e){const s=w;if(e&&g(e)!==this.chain?.[s(477)]&&!this[s(389)](e))return;const n=await this.#m(s(349),[t]);return n||void 0}async[w(393)](t,e){const s=w;for(;;){const e=await this.receipt(t);if(e){if(console[s(446)](s(393),e),1===e.status){I({title:s(363),body:s(437)+t+s(402)});break}if(0===e[s(381)]){I({title:s(407),body:"Your transaction "+t+s(362)});break}await new Promise((t=>setTimeout(t,1e3)))}else console[s(325)](s(371)+t+s(426)),await new Promise((t=>setTimeout(t,1e3)))}}updateContacts(t,e){const s=w,n=e?.[s(340)]||"recent",r=e?.[s(454)],i=this.#o()?.[s(408)](s(411));!i?.[n]?.[s(464)]((e=>e?.address?.[s(375)]()===t?.[s(375)]()))&&this.exist(t)&&(this.#o()?.[s(443)](s(411),{...i,[n]:[...i?.[n]?.slice?.(0,19)||[],{name:r,address:t}]}),this[s(462)](s(431)))}[w(327)](t,e){const s=w,n=this[s(444)](e?.[s(376)]),r=e?.[s(477)]?g(e?.[s(477)]):this[s(453)]?.[s(477)],i=n?.tx?.[r];if(t&&t[s(323)]){if(i&&t?.[s(323)]!==i?.[s(323)])return console[s(446)]({receipts:t,exist:i}),void console[s(446)]("wrong")}else if(i)return void console[s(446)]("wrong");this.#g?.[s(443)](n?.address?.[s(375)](),{...n,tx:{...n?.tx,[r]:t}}),this[s(462)](s(360))}[w(457)](t,e){if(t)return this.#a((()=>{const s=y;t=t?.[s(375)]();const n=this.chain?.[s(477)]?.[s(356)]();let r=this[s(444)](e);if(n&&r)return r={...r,tokens:{...r?.[s(442)],fungibles:{...r?.[s(442)]?.[s(469)],[n]:[t,...(r?.tokens?.[s(469)]?.[n]||[])?.[s(392)]((e=>e!==t))]}}},this.#g?.[s(443)](r?.[s(376)]?.[s(375)](),r),this.emit(s(422),r[s(442)]?.fungibles),!0;throw new Error(s(347))}))}removeFungibleAsset(t,e){if(t)return this.#a((()=>{const s=y;let n=this[s(444)](e);const r=this.chain?.chainId?.[s(356)]();if(r&&n)return n={...n,tokens:{...n?.tokens,fungibles:{...n?.[s(442)]?.[s(469)],[r]:(n?.tokens?.[s(469)]?.[r]||[])?.[s(392)]((e=>e!==t))}}},this.#g?.[s(443)](n?.[s(376)]?.[s(375)](),n),this[s(462)]("tokenUpdated",n[s(442)]?.fungibles),!0;throw new Error(s(377))}))}[w(343)](t,e,s){const n=w;if(!t||""===t)throw new Error(n(394)+t+n(468));if(!e||""===e)throw new Error(n(473)+e+n(468));return this.#a((()=>{const r=n;t=t?.[r(375)]();const i=this[r(453)]?.[r(477)]?.[r(356)]();let o=this[r(444)](s);if(i&&o)return o={...o,tokens:{...o?.[r(442)],nonFungibles:{...o?.tokens?.[r(383)],[i]:[...(o?.[r(442)]?.[r(383)]?.[i]||[])?.filter((e=>e&&!e?.[r(351)](t))),{[t]:[e,...(o?.tokens?.[r(383)]?.[i]?.[r(404)]((e=>e?.[t]))?.[t]||[])?.[r(392)]((t=>t!==e))]}]}}},this.#g?.set(o?.[r(376)]?.[r(375)](),o),this[r(462)]("nftUpdated",o[r(442)]?.[r(469)]),!0;throw new Error(r(347))}))}[w(352)](t,e,s){const n=w;if(!t||""===t)throw new Error(n(394)+t+n(468));if(!e||isNaN(Number(e)))throw new Error(n(473)+e+n(468));return this.#a((()=>{const r=n;let i=this[r(444)](s);const o=this[r(453)]?.[r(477)]?.[r(356)]();if(i)return i={...i,tokens:{...i?.tokens,nonFungibles:{...i?.tokens?.nonFungibles,[o]:[...(i?.[r(442)]?.nonFungibles?.[o]||[])?.[r(392)]((e=>e&&!t?.hasOwnProperty(t))),{[t]:(i?.[r(442)]?.nonFungibles?.[o]?.[r(404)]((e=>e?.[t]))?.[t]||[])?.filter((t=>t!==e))}]}}},this.#g?.set(i?.[r(376)]?.[r(375)](),i),this[r(462)](r(330),i[r(442)]?.[r(469)]),!0;throw new Error("The account information for removing the asset could not be found.")}))}}export{k as CoinmecaWalletProvider};
//# sourceMappingURL=provider.js.map