diff --git a/CHANGELOG.md b/CHANGELOG.md index 06e6efd..0612dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### [0.10.1](https://github.com/juliancwirko/elven.js/releases/tag/v0.10.1) (2023-05-23) +- fix native auth when used with web wallet provider + ### [0.10.0](https://github.com/juliancwirko/elven.js/releases/tag/v0.10.0) (2023-05-23) - **Breaking** switch to using `sdk-native-auth-client` instead passing string-based login tokens, there is no fallback or other option, so it is a breaking change. Native Auth is recommended. The old way of doing that will be deprecated. Please freeze the previous version if you are not ready to switch yet diff --git a/build/elven.js b/build/elven.js index 4e7899c..64263d3 100644 --- a/build/elven.js +++ b/build/elven.js @@ -37,7 +37,7 @@ Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),t.put(r,13)}};EF.exp The chosen QR Code version cannot contain this amount of data. Minimum version required to store current data is: `+s+`. `);let o=Zee(e,r,i),a=m0.getSymbolSize(e),u=new Hee(a);return Kee(u,e),$ee(u),Yee(u,e),A_(u,r,0),e>=7&&Jee(u,e),Xee(u,o),isNaN(n)&&(n=b_.getBestMask(u,A_.bind(null,u,r))),b_.applyMask(n,u),A_(u,r,n),{modules:u,version:e,errorCorrectionLevel:r,maskPattern:n,segments:i}}OF.create=function(e,r){if(typeof e>"u"||e==="")throw new Error("No input text");let n=E_.M,i,s;return typeof r<"u"&&(n=E_.from(r.errorCorrectionLevel,E_.M),i=y0.from(r.version),s=b_.from(r.maskPattern),r.toSJISFunc&&m0.setToSJISFunction(r.toSJISFunc)),tte(e,i,n,s)}});var I_=w(Uo=>{c();function PF(t){if(typeof t=="number"&&(t=t.toString()),typeof t!="string")throw new Error("Color should be defined as hex string");let e=t.slice().replace("#","").split("");if(e.length<3||e.length===5||e.length>8)throw new Error("Invalid hex color: "+t);(e.length===3||e.length===4)&&(e=Array.prototype.concat.apply([],e.map(function(n){return[n,n]}))),e.length===6&&e.push("F","F");let r=parseInt(e.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+e.slice(0,6).join("")}}Uo.getOptions=function(e){e||(e={}),e.color||(e.color={});let r=typeof e.margin>"u"||e.margin===null||e.margin<0?4:e.margin,n=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:n,scale:n?4:i,margin:r,color:{dark:PF(e.color.dark||"#000000ff"),light:PF(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}};Uo.getScale=function(e,r){return r.width&&r.width>=e+r.margin*2?r.width/(e+r.margin*2):r.scale};Uo.getImageWidth=function(e,r){let n=Uo.getScale(e,r);return Math.floor((e+r.margin*2)*n)};Uo.qrToImageData=function(e,r,n){let i=r.modules.size,s=r.modules.data,o=Uo.getScale(i,n),a=Math.floor((i+n.margin*2)*o),u=n.margin*o,l=[n.color.light,n.color.dark];for(let f=0;f=u&&d>=u&&f{c();var S_=I_();function rte(t,e,r){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=r,e.width=r,e.style.height=r+"px",e.style.width=r+"px"}function nte(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}w0.render=function(e,r,n){let i=n,s=r;typeof i>"u"&&(!r||!r.getContext)&&(i=r,r=void 0),r||(s=nte()),i=S_.getOptions(i);let o=S_.getImageWidth(e.modules.size,i),a=s.getContext("2d"),u=a.createImageData(o,o);return S_.qrToImageData(u.data,e,i),rte(a,s,o),a.putImageData(u,0,0),s};w0.renderToDataURL=function(e,r,n){let i=n;typeof i>"u"&&(!r||!r.getContext)&&(i=r,r=void 0),i||(i={});let s=w0.render(e,r,i),o=i.type||"image/png",a=i.rendererOpts||{};return s.toDataURL(o,a.quality)}});var FF=w(LF=>{c();var ite=I_();function BF(t,e){let r=t.a/255,n=e+'="'+t.hex+'"';return r<1?n+" "+e+'-opacity="'+r.toFixed(2).slice(1)+'"':n}function C_(t,e,r){let n=t+e;return typeof r<"u"&&(n+=" "+r),n}function ste(t,e,r){let n="",i=0,s=!1,o=0;for(let a=0;a0&&u>0&&t[a-1]||(n+=s?C_("M",u+r,.5+l+r):C_("m",i,0),i=0,s=!1),u+1':"",l="',f='viewBox="0 0 '+a+" "+a+'"',y=''+u+l+` -`;return typeof n=="function"&&n(null,y),y}});var UF=w(If=>{c();var ote=UL(),T_=DF(),MF=RF(),ate=FF();function x_(t,e,r,n,i){let s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!ote())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=r,r=e,e=n=void 0):o===3&&(e.getContext&&typeof i>"u"?(i=n,n=void 0):(i=n,n=r,r=e,e=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(r=e,e=n=void 0):o===2&&!e.getContext&&(n=r,r=e,e=void 0),new Promise(function(u,l){try{let f=T_.create(r,n);u(t(f,e,n))}catch(f){l(f)}})}try{let u=T_.create(r,n);i(null,t(u,e,n))}catch(u){i(u)}}If.create=T_.create;If.toCanvas=x_.bind(null,MF.render);If.toDataURL=x_.bind(null,MF.renderToDataURL);If.toString=x_.bind(null,function(t,e,r){return ate.render(t,r)})});var JF=w(ps=>{"use strict";c();var Ete=ps&&ps.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),YF=ps&&ps.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&Ete(e,t,r)};Object.defineProperty(ps,"__esModule",{value:!0});YF(uf(),ps);YF(_b(),ps)});c();var vte=_e(iI(),1),Ate=_e(HT(),1),bte=_e(QT(),1),_te=_e(tr(),1),Ite=_e($h(),1),Ste=_e(Wc(),1),Cte=_e(jc(),1),Tte=_e(Rw(),1),xte=_e(D2(),1),Nte=_e(Zh(),1),i5=_e(yi(),1),Bn=_e(Rc(),1),s5=_e(Oc(),1),o5=_e(aa(),1);c();c();var q2=_e(RE(),1);c();c();var Id="elvenjs_state",F2="https://devnet-api.multiversx.com";var Sd="/dapp/init",Cd="devnet",M2="https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://xportal.com/",U2=["wss://relay.walletconnect.com"],An={devnet:{id:"devnet",shortId:"D",name:"Devnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://devnet-wallet.multiversx.com",apiAddress:"https://devnet-api.multiversx.com",explorerAddress:"https://devnet-explorer.multiversx.com",apiTimeout:1e4},testnet:{id:"testnet",shortId:"T",name:"Testnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://testnet-wallet.multiversx.com",apiAddress:"https://testnet-api.multiversx.com",explorerAddress:"https://testnet-explorer.multiversx.com",apiTimeout:1e4},mainnet:{id:"mainnet",shortId:"1",name:"Mainnet",egldLabel:"EGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://wallet.multiversx.com",apiAddress:"https://api.multiversx.com",explorerAddress:"https://explorer.multiversx.com",apiTimeout:1e4}};var Ie={get(t){let e=localStorage.getItem(Id);if(!e)return{};let r=JSON.parse(e);return t?r[t]:r},set(t,e){let r=this.get();r[t]=e,localStorage.setItem(Id,JSON.stringify(r))},clear(){localStorage.removeItem(Id)}};var Td=()=>Te(void 0,null,function*(){let t=q2.ExtensionProvider.getInstance();try{let e=yield t.init(),r=Ie.get();if(r!=null&&r.address&&t.setAddress(r.address),!e){console.warn("Something went wrong when trying to initialize the ExtensionProvider..");return}return t}catch(e){console.warn("Can't initialize the Dapp Provider!")}});var e5=_e(RE(),1),t5=_e(tf(),1),r5=_e(uf(),1),n5=_e(Zb(),1);c();var fL=_e(tf(),1);c();c();var Ce=class{static set(e,r){if(!e)return;let n=R_(xf({},this.events),{[e]:r});this.events=n}static get(e){if(!(!e||!this.events))return this.events[e]}static run(e,...r){var n,i;!e||!this.events||(i=(n=this.events)[e])==null||i.call(n,...r)}static clear(){this.events=void 0}};c();var Ro=(i=>(i.ledger="ledger",i.mobile="mobile",i.webWallet="web-wallet",i.browserExtension="browser-extension",i))(Ro||{});var lc=t=>Te(void 0,null,function*(){if(!t.dappProvider)throw new Error("Error: Logout failed: There is no active session!");Ce.run("onLoginPending");let e=yield t.dappProvider.logout();return e&&(Ie.clear(),Ce.run("onLogout")),e});c();var cL=_e(tr(),1),lL=_e($h(),1);c();var Lt=t=>typeof t=="string"?t.toUpperCase():t instanceof Error?t.message:`Error: ${JSON.stringify(t)}`;c();var fc=()=>new Date().setHours(new Date().getHours()+24),Xg=t=>Date.now()>t;var us=t=>Te(void 0,null,function*(){let e=Ie.get("address"),r=Ie.get("expires");if(!(r&&Xg(r))&&e&&t.networkProvider){let i=new cL.Address(e),s=new lL.Account(i);try{let o=yield t.networkProvider.getAccount(i);Ie.set("address",e),Ie.set("nonce",o.nonce.valueOf()),Ie.set("balance",o.balance.toString()),s.update(o)}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to synchronize the user account: ${a}`)}}});c();function Zg(t){return t[Math.floor(Math.random()*t.length)]}var hL=t=>Te(void 0,null,function*(){if(!t.initOptions.walletConnectV2ProjectId||!t.initOptions.chainType)return;let e={onClientLogin:()=>{us(t),Ce.run("onLoggedIn")},onClientLogout:()=>lc(t),onClientEvent:i=>{console.log("wc2 session event: ",i)}},r=Zg(t.initOptions.walletConnectV2RelayAddresses),n=new fL.WalletConnectV2Provider(e,An[t.initOptions.chainType].shortId,r,t.initOptions.walletConnectV2ProjectId);try{return yield n.init(),n}catch(i){console.warn("Can't initialize the Dapp Provider!")}});c();var xL=_e(Yt(),1),o0=_e(tr(),1),NL=_e(dL(),1),OL=_e(wL(),1),DL=_e(i_(),1),PL=_e(IL(),1),RL=_e(CL(),1),BL=_e(TL(),1),LL=_e(td(),1);var a0=class{constructor({apiUrl:e,chainType:r,apiTimeout:n}){var i,s;this.chainType=r||Cd,this.apiUrl=e||((i=An[this.chainType])==null?void 0:i.apiAddress),this.apiTimeout=n||((s=An[this.chainType])==null?void 0:s.apiTimeout)}apiGet(e,r){return Te(this,null,function*(){if(typeof fetch!="undefined"){let n=new AbortController,i=setTimeout(()=>n.abort(),this.apiTimeout),s={method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},signal:n.signal};try{let o=yield fetch(this.apiUrl+"/"+e,Object.assign(s,r||{})),a=yield o.json();if(!o.ok){let u=(a==null?void 0:a.error)||o.status;return clearTimeout(i),Promise.reject(u)}return clearTimeout(i),a}catch(o){this.handleApiError(o,e)}}})}apiPost(e,r,n){return Te(this,null,function*(){if(typeof fetch!="undefined"){let i=new AbortController,s=setTimeout(()=>i.abort(),this.apiTimeout),o={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r||{}),signal:i.signal};try{let a=yield fetch(this.apiUrl+"/"+e,Object.assign(o,n||{})),u=yield a.json();if(!a.ok){let l=(u==null?void 0:u.error)||a.status;return clearTimeout(s),Promise.reject(l)}return clearTimeout(s),u}catch(a){this.handleApiError(a,e)}}})}handleApiError(e,r){if(!e.response)throw new Error(`Request error on url [${r}]: [${e.toString()}]`);let n=e.response.data,i=n.error||n.message||JSON.stringify(n);throw new Error(i)}sendTransaction(e){return Te(this,null,function*(){return(yield this.apiPost("transactions",e.toSendable())).txHash})}getAccount(e){return Te(this,null,function*(){let r=yield this.apiGet(`accounts/${e.bech32()}`);return{address:new o0.Address((r==null?void 0:r.address)||""),nonce:Number((r==null?void 0:r.nonce)||0),balance:new xL.default((r==null?void 0:r.balance)||0),code:(r==null?void 0:r.code)||"",userName:(r==null?void 0:r.username)||""}})}getTransaction(e){return Te(this,null,function*(){let r=yield this.apiGet(`transactions/${e}`),n=new NL.TransactionStatus(r.status);return{hash:e,type:r.type||"",nonce:r.nonce||0,round:r.round,epoch:r.epoch||0,value:(r.value||0).toString(),sender:new o0.Address(r.sender),receiver:new o0.Address(r.receiver),gasPrice:r.gasPrice||0,gasLimit:r.gasLimit||0,data:h.Buffer.from(r.data||"","base64"),status:n,timestamp:r.timestamp||0,blockNonce:r.blockNonce||0,hyperblockNonce:r.hyperblockNonce||0,hyperblockHash:r.hyperblockHash||"",receipt:OL.TransactionReceipt.fromHttpResponse(r.receipt||{}),logs:DL.TransactionLogs.fromHttpResponse(r.logs||{}),contractResults:PL.ContractResults.fromApiHttpResponse(r.results||[]),isCompleted:!n.isPending()}})}queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n,value:i,caller:s}){try{let a=new LL.Query({address:e,func:r,args:n,value:i,caller:s}),u=new BL.ContractQueryRequest(a).toHttpRequest(),l=yield this.apiPost("query",u);return RL.ContractQueryResponse.fromHttpResponse(l)}catch(a){this.handleApiError(a,"query")}})}};c();var FL=(t,e,r)=>Te(void 0,null,function*(){let n=yield Td();try{n&&(yield n.login()),Ce.run("onLoginPending")}catch(s){let o=Lt(s);console.warn(`Something went wrong trying to login the user: ${o}`)}if(!n)throw new Error("Error: There were problems with auth provider initialization!");let{signature:i}=n.account;if(Ie.set("loginToken",e),i&&Ie.set("signature",i),t.networkProvider&&i)try{let s=yield n.getAddress();if(!s)throw new Error("Canceled!");Ie.set("address",s),Ie.set("loginMethod","browser-extension"),Ie.set("expires",fc()),yield us(t),Ce.run("onLoggedIn");let o=r.getToken(s,e,i);return Ie.set("accessToken",o),n}catch(s){console.warn(`Something went wrong trying to synchronize the user account: ${s==null?void 0:s.message}`),Ce.run("onLogout")}});c();c();var qF=_e(UF(),1),VF=_e(tf(),1);var cte=t=>{var r;let e=document.createElement("template");return e.innerHTML=t.trim(),(r=e.content.firstChild)==null?void 0:r.cloneNode(!0)},lte=t=>{let e=`${M2}?wallet-connect=${encodeURIComponent(t)}`,r=document.createElement("a");return r.setAttribute("href",e),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank"),r.textContent="xPortal login",r.classList.add("elven-qr-code-deep-link"),r},fte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairings"),t},hte=()=>{let t=document.createElement("div");return t.textContent="Existing WalletConnect pairings:",t.classList.add("elven-wc-pairings-header"),t},N_={},dte=(t,e)=>{let r=document.createElement("button");return r.classList.add("elven-wc-pairings-remove-btn"),r.textContent="\u2716",N_[t.topic]=new AbortController,r.addEventListener("click",n=>{n.stopImmediatePropagation(),e(t.topic)},{signal:N_[t.topic].signal}),r},E0={},pte=(t,e,r)=>{var o,a;let n=document.createElement("div"),i=document.createElement("div");n.classList.add("elven-wc-pairing-item"),n.setAttribute("id",t.topic),i.classList.add("elven-wc-pairing-item-description"),i.textContent=`${(o=t.peerMetadata)==null?void 0:o.description} (${(a=t.peerMetadata)==null?void 0:a.url})`,n.appendChild(i);let s=dte(t,e);return n.appendChild(s),E0[t.topic]=new AbortController,n.addEventListener("click",()=>r(t.topic),{signal:E0[t.topic].signal}),n},gte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairing-item-confirm-msessage"),t.setAttribute("id","elven-wc-pairing-item-confirm-msessage"),t.innerText="Confirm on xPortal app!",t},yte=t=>{if(!t)return;let e=document.getElementById(t);e==null||e.remove()},mte=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),wte=t=>Te(void 0,null,function*(){return t?yield qF.default.toString(t,{type:"svg"}):void 0}),jF=(t,e,r,n)=>Te(void 0,null,function*(){if(!t)throw new Error("Please provide the QR Code and WalletConnect Pairings container id!");let i=null;typeof t=="string"?i=document.getElementById(t):t instanceof HTMLElement&&(i=t);let s=yield wte(e),o;if(s&&(o=cte(s)),i&&o&&(i.replaceChildren(),i.appendChild(o),mte()&&i.appendChild(lte(e))),i&&r instanceof VF.WalletConnectV2Provider){let a=r.pairings,u=f=>Te(void 0,null,function*(){try{f&&(yield r.logout({topic:f}),yte(f))}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to remove the existing pairing: ${y}`)}finally{E0[f].abort()}}),l=f=>Te(void 0,null,function*(){try{let{approval:d}=yield r.connect({topic:f,methods:["mvx_cancelAction"]});if(!document.getElementById("elven-wc-pairing-item-confirm-msessage")){let m=document.getElementById(f);m==null||m.after(gte())}yield r.login({approval:d,token:n})}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to login the user: ${y}`)}finally{for(let d of Object.values(E0))d==null||d.abort();for(let d of Object.values(N_))d==null||d.abort()}});if(a&&a.length>0){let f=fte();i.appendChild(f);let d=hte();f.appendChild(d);for(let y of a){let m=pte(y,u,l);f.appendChild(m)}}}return i});var v0=_e(tf(),1);var HF=(t,e,r,n)=>Te(void 0,null,function*(){if(!n)throw new Error("You haven't provided the QR code container DOM element id");let i=Zg(t.initOptions.walletConnectV2RelayAddresses);if(!i||!t.networkProvider)throw new Error("Something wen't wrong with the initialization (ApiNetworkProvider or Wallet Connect Bridge address), plese try to refresh the page!");if(!t.initOptions.walletConnectV2ProjectId)throw new Error("Please provide your WalletConnect project id. You can get it here: https://cloud.walletconnect.com)");if(!t.initOptions.chainType)throw new Error("Please provide the chain type in ElvenJS.init function!");let s,o={onClientLogin:()=>Te(void 0,null,function*(){if(t.dappProvider instanceof v0.WalletConnectV2Provider){Ce.run("onLoginPending");let u=yield t.dappProvider.getAddress(),l=yield t.dappProvider.getSignature();Ie.set("address",u),Ie.set("loginMethod","mobile"),Ie.set("expires",fc()),yield us(t),l&&Ie.set("signature",l),Ie.set("loginToken",e);let f=r.getToken(u,e,l);Ie.set("accessToken",f),Ce.run("onLoggedIn"),s==null||s.replaceChildren()}}),onClientLogout:()=>Te(void 0,null,function*(){t.dappProvider instanceof v0.WalletConnectV2Provider&&(yield lc(t),Ce.run("onLogout"))}),onClientEvent:u=>{console.log("wc2 session event: ",u)}},a=new v0.WalletConnectV2Provider(o,An[t.initOptions.chainType].shortId,i,t.initOptions.walletConnectV2ProjectId);try{if(a){t.dappProvider=a,Ce.run("onQrPending"),yield a.init();let{uri:u,approval:l}=yield a.connect({methods:["mvx_cancelAction"]}),f=e?`${u}&token=${e}`:u;return n&&f&&(s=yield jF(n,f,a,e),Ce.run("onQrLoaded")),yield a.login({approval:l,token:e}),a}}catch(u){let l=Lt(u);console.warn(`Something went wrong trying to login the user: ${l}`),Ce.run("onLogout")}});c();var GF=_e(uf(),1);var QF=(t,e,r)=>Te(void 0,null,function*(){let n=new GF.WalletProvider(`${t}${Sd}`),s={callbackUrl:typeof window!="undefined"?encodeURIComponent(`${window.location.origin}${r||"/"}`):"/",token:e};try{return Ce.run("onLoginPending"),Ie.set("loginMethod","web-wallet"),yield n.login(s),Ie.set("expires",fc()),Ie.set("loginToken",e),n}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to login the user: ${a}`),Ie.set("loginMethod",""),Ce.run("onLogout")}});c();var qo=t=>{if(typeof window!="undefined"){let e=new URL(window.location.href);return new URLSearchParams(e.search).get(t)}};c();var kF=_e(uf(),1);var zF=_e(Zb(),1);var WF=(t,e)=>Te(void 0,null,function*(){let r=qo("signature"),n=qo("address"),i=Ie.get("address"),s=Ie.get("loginToken");if(r&&Ie.set("signature",r),n||i){n&&(Ie.set("address",n),window.history.replaceState(null,"",window.location.pathname));let o=new kF.WalletProvider(`${t}${Sd}`);if(r&&e&&i){let u=new zF.NativeAuthClient({apiUrl:e}).getToken(i,s,r);Ie.set("accessToken",u)}return o}});c();var KF=_e($h(),1),$F=_e(Rw(),1);var A0=(t,e)=>Te(void 0,null,function*(){Ce.run("onTxSent",t),yield new $F.TransactionWatcher(e).awaitCompleted(t);let n=t.getSender(),i=new KF.Account(n),s=yield e.getAccount(n);i.update(s),Ie.set("address",i.address.bech32()),Ie.set("nonce",i.getNonceThenIncrement().valueOf()),Ie.set("balance",i.balance.toString()),Ce.run("onTxFinalized",t)});c();var b0=_e(JF(),1),XF=_e(Wc(),1);var ZF=(t,e,r)=>Te(void 0,null,function*(){if(qo(b0.WALLET_PROVIDER_CALLBACK_PARAM)===b0.WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED&&t&&e&&"getTransactionsFromWalletUrl"in t){let i=t.getTransactionsFromWalletUrl();window.history.replaceState(null,"",window.location.pathname);let s=i==null?void 0:i[0];if(s){s.data=h.Buffer.from(s.data).toString("base64");let o=XF.Transaction.fromPlainObject(s);o.setNonce(r);try{Ce.run("onTxStarted",o),yield e.sendTransaction(o),yield A0(o,e)}catch(a){let u=Lt(a);throw Ce.run("onTxError",o,u),new Error(`Error: Transaction signing failed! ${u}`)}}}});var Cf=class{static init(e){return Te(this,null,function*(){let r=Ie.get();if(r.expires&&Xg(r.expires)){Ie.clear(),this.dappProvider=void 0;return}this.initOptions=xf({chainType:Cd,apiUrl:F2,apiTimeout:1e4,walletConnectV2ProjectId:"",walletConnectV2RelayAddresses:U2},e),this.networkProvider=new a0(this.initOptions),this.initOptions.onLoginPending&&Ce.set("onLoginPending",this.initOptions.onLoginPending),this.initOptions.onLoggedIn&&Ce.set("onLoggedIn",this.initOptions.onLoggedIn),this.initOptions.onQrPending&&Ce.set("onQrPending",this.initOptions.onQrPending),this.initOptions.onQrLoaded&&Ce.set("onQrLoaded",this.initOptions.onQrLoaded),this.initOptions.onLogout&&Ce.set("onLogout",this.initOptions.onLogout),this.initOptions.onTxStarted&&Ce.set("onTxStarted",this.initOptions.onTxStarted),this.initOptions.onTxSent&&Ce.set("onTxSent",this.initOptions.onTxSent),this.initOptions.onTxFinalized&&Ce.set("onTxFinalized",this.initOptions.onTxFinalized),this.initOptions.onTxError&&Ce.set("onTxError",this.initOptions.onTxError),((r==null?void 0:r.address)||r.loginMethod==="web-wallet"&&qo("address"))&&(r!=null&&r.loginMethod)&&(Ce.run("onLoginPending"),r.loginMethod==="browser-extension"&&(this.dappProvider=yield Td()),r.loginMethod==="mobile"&&(this.dappProvider=yield hL(this)),r.loginMethod==="web-wallet"&&this.initOptions.chainType&&(this.dappProvider=yield WF(An[this.initOptions.chainType].walletAddress,this.initOptions.apiUrl)),yield us(this),Ce.run("onLoggedIn"),r.loginMethod==="web-wallet"&&(yield ZF(this.dappProvider,this.networkProvider,r.nonce)))})}static login(e,r){return Te(this,null,function*(){var o,a;if(!Object.values(Ro).includes(e))throw new Error("Error: Wrong login method!");if(!this.networkProvider)throw new Error("Error: Login failed: Use ElvenJs.init() first!");let i=new n5.NativeAuthClient({apiUrl:(o=this.initOptions)==null?void 0:o.apiUrl}),s=yield i.initialize();try{if(e==="browser-extension"){let u=yield FL(this,s,i);this.dappProvider=u}if(e==="mobile"){let u=yield HF(this,s,i,r==null?void 0:r.qrCodeContainer);this.dappProvider=u}if(e==="web-wallet"&&((a=this.initOptions)!=null&&a.chainType)){let u=yield QF(An[this.initOptions.chainType].walletAddress,s,r==null?void 0:r.callbackRoute);this.dappProvider=u}}catch(u){let l=Lt(u);throw new Error(`Error: ${l}`)}})}static logout(){return Te(this,null,function*(){try{let e=yield lc(this);return this.dappProvider=void 0,e}catch(e){let r=Lt(e);console.warn("Something went wrong when logging out: ",r)}})}static signAndSendTransaction(e){return Te(this,null,function*(){if(!this.dappProvider)throw new Error("Error: Transaction signing failed: There is no active session!");if(!this.networkProvider)throw new Error("Error: Transaction signing failed: There is no active network provider!");try{Ce.run("onTxStarted",e);let r=Ie.get();e.setNonce(r.nonce),this.dappProvider instanceof e5.ExtensionProvider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof t5.WalletConnectV2Provider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof r5.WalletProvider&&(yield this.dappProvider.signTransaction(e)),r.loginMethod!=="web-wallet"&&(yield this.networkProvider.sendTransaction(e),yield A0(e,this.networkProvider))}catch(r){let n=Lt(r);throw Ce.run("onTxError",e,n),new Error(`Error: Transaction signing failed! ${n}`)}return e})}static queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n=[],value:i=0,caller:s}){if(!this.networkProvider)throw new Error("Error: Query failed: There is no active network provider!");if(!e||!r)throw new Error("Error: Query failed: The Query arguments are not valid! Address and func required");try{return yield this.networkProvider.queryContract({address:e,func:r,args:n,value:i,caller:s})}catch(a){let u=Lt(a);throw new Error(`Error: Smart contract query failed! ${u}`)}})}},Sf=Cf;Sf.storage=Ie,Sf.destroy=()=>{Cf.networkProvider=void 0,Cf.dappProvider=void 0,Cf.initOptions=void 0,Ce.clear()};var export_Account=Ite.Account;var export_Address=_te.Address;var export_AddressType=o5.AddressType;var export_AddressValue=o5.AddressValue;var export_BigUIntType=Bn.BigUIntType;var export_BigUIntValue=Bn.BigUIntValue;var export_BooleanType=s5.BooleanType;var export_BooleanValue=s5.BooleanValue;var export_BytesType=i5.BytesType;var export_BytesValue=i5.BytesValue;var export_ContractFunction=Nte.ContractFunction;var export_GasEstimator=bte.GasEstimator;var export_SmartContract=xte.SmartContract;var export_TokenTransfer=vte.TokenTransfer;var export_Transaction=Ste.Transaction;var export_TransactionPayload=Cte.TransactionPayload;var export_TransactionWatcher=Tte.TransactionWatcher;var export_TransferTransactionsFactory=Ate.TransferTransactionsFactory;var export_U16Type=Bn.U16Type;var export_U16Value=Bn.U16Value;var export_U32Type=Bn.U32Type;var export_U32Value=Bn.U32Value;var export_U64Type=Bn.U64Type;var export_U64Value=Bn.U64Value;var export_U8Type=Bn.U8Type;var export_U8Value=Bn.U8Value;export{export_Account as Account,export_Address as Address,export_AddressType as AddressType,export_AddressValue as AddressValue,export_BigUIntType as BigUIntType,export_BigUIntValue as BigUIntValue,export_BooleanType as BooleanType,export_BooleanValue as BooleanValue,export_BytesType as BytesType,export_BytesValue as BytesValue,export_ContractFunction as ContractFunction,Sf as ElvenJS,export_GasEstimator as GasEstimator,Ro as LoginMethodsEnum,export_SmartContract as SmartContract,export_TokenTransfer as TokenTransfer,export_Transaction as Transaction,export_TransactionPayload as TransactionPayload,export_TransactionWatcher as TransactionWatcher,export_TransferTransactionsFactory as TransferTransactionsFactory,export_U16Type as U16Type,export_U16Value as U16Value,export_U32Type as U32Type,export_U32Value as U32Value,export_U64Type as U64Type,export_U64Value as U64Value,export_U8Type as U8Type,export_U8Value as U8Value}; +`;return typeof n=="function"&&n(null,y),y}});var UF=w(If=>{c();var ote=UL(),T_=DF(),MF=RF(),ate=FF();function x_(t,e,r,n,i){let s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!ote())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=r,r=e,e=n=void 0):o===3&&(e.getContext&&typeof i>"u"?(i=n,n=void 0):(i=n,n=r,r=e,e=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(r=e,e=n=void 0):o===2&&!e.getContext&&(n=r,r=e,e=void 0),new Promise(function(u,l){try{let f=T_.create(r,n);u(t(f,e,n))}catch(f){l(f)}})}try{let u=T_.create(r,n);i(null,t(u,e,n))}catch(u){i(u)}}If.create=T_.create;If.toCanvas=x_.bind(null,MF.render);If.toDataURL=x_.bind(null,MF.renderToDataURL);If.toString=x_.bind(null,function(t,e,r){return ate.render(t,r)})});var JF=w(ps=>{"use strict";c();var Ete=ps&&ps.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),YF=ps&&ps.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&Ete(e,t,r)};Object.defineProperty(ps,"__esModule",{value:!0});YF(uf(),ps);YF(_b(),ps)});c();var vte=_e(iI(),1),Ate=_e(HT(),1),bte=_e(QT(),1),_te=_e(tr(),1),Ite=_e($h(),1),Ste=_e(Wc(),1),Cte=_e(jc(),1),Tte=_e(Rw(),1),xte=_e(D2(),1),Nte=_e(Zh(),1),i5=_e(yi(),1),Bn=_e(Rc(),1),s5=_e(Oc(),1),o5=_e(aa(),1);c();c();var q2=_e(RE(),1);c();c();var Id="elvenjs_state",F2="https://devnet-api.multiversx.com";var Sd="/dapp/init",Cd="devnet",M2="https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://xportal.com/",U2=["wss://relay.walletconnect.com"],An={devnet:{id:"devnet",shortId:"D",name:"Devnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://devnet-wallet.multiversx.com",apiAddress:"https://devnet-api.multiversx.com",explorerAddress:"https://devnet-explorer.multiversx.com",apiTimeout:1e4},testnet:{id:"testnet",shortId:"T",name:"Testnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://testnet-wallet.multiversx.com",apiAddress:"https://testnet-api.multiversx.com",explorerAddress:"https://testnet-explorer.multiversx.com",apiTimeout:1e4},mainnet:{id:"mainnet",shortId:"1",name:"Mainnet",egldLabel:"EGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://wallet.multiversx.com",apiAddress:"https://api.multiversx.com",explorerAddress:"https://explorer.multiversx.com",apiTimeout:1e4}};var Ie={get(t){let e=localStorage.getItem(Id);if(!e)return{};let r=JSON.parse(e);return t?r[t]:r},set(t,e){let r=this.get();r[t]=e,localStorage.setItem(Id,JSON.stringify(r))},clear(){localStorage.removeItem(Id)}};var Td=()=>Te(void 0,null,function*(){let t=q2.ExtensionProvider.getInstance();try{let e=yield t.init(),r=Ie.get();if(r!=null&&r.address&&t.setAddress(r.address),!e){console.warn("Something went wrong when trying to initialize the ExtensionProvider..");return}return t}catch(e){console.warn("Can't initialize the Dapp Provider!")}});var e5=_e(RE(),1),t5=_e(tf(),1),r5=_e(uf(),1),n5=_e(Zb(),1);c();var fL=_e(tf(),1);c();c();var Ce=class{static set(e,r){if(!e)return;let n=R_(xf({},this.events),{[e]:r});this.events=n}static get(e){if(!(!e||!this.events))return this.events[e]}static run(e,...r){var n,i;!e||!this.events||(i=(n=this.events)[e])==null||i.call(n,...r)}static clear(){this.events=void 0}};c();var Ro=(i=>(i.ledger="ledger",i.mobile="mobile",i.webWallet="web-wallet",i.browserExtension="browser-extension",i))(Ro||{});var lc=t=>Te(void 0,null,function*(){if(!t.dappProvider)throw new Error("Error: Logout failed: There is no active session!");Ce.run("onLoginPending");let e=yield t.dappProvider.logout();return e&&(Ie.clear(),Ce.run("onLogout")),e});c();var cL=_e(tr(),1),lL=_e($h(),1);c();var Lt=t=>typeof t=="string"?t.toUpperCase():t instanceof Error?t.message:`Error: ${JSON.stringify(t)}`;c();var fc=()=>new Date().setHours(new Date().getHours()+24),Xg=t=>Date.now()>t;var us=t=>Te(void 0,null,function*(){let e=Ie.get("address"),r=Ie.get("expires");if(!(r&&Xg(r))&&e&&t.networkProvider){let i=new cL.Address(e),s=new lL.Account(i);try{let o=yield t.networkProvider.getAccount(i);Ie.set("address",e),Ie.set("nonce",o.nonce.valueOf()),Ie.set("balance",o.balance.toString()),s.update(o)}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to synchronize the user account: ${a}`)}}});c();function Zg(t){return t[Math.floor(Math.random()*t.length)]}var hL=t=>Te(void 0,null,function*(){if(!t.initOptions.walletConnectV2ProjectId||!t.initOptions.chainType)return;let e={onClientLogin:()=>{us(t),Ce.run("onLoggedIn")},onClientLogout:()=>lc(t),onClientEvent:i=>{console.log("wc2 session event: ",i)}},r=Zg(t.initOptions.walletConnectV2RelayAddresses),n=new fL.WalletConnectV2Provider(e,An[t.initOptions.chainType].shortId,r,t.initOptions.walletConnectV2ProjectId);try{return yield n.init(),n}catch(i){console.warn("Can't initialize the Dapp Provider!")}});c();var xL=_e(Yt(),1),o0=_e(tr(),1),NL=_e(dL(),1),OL=_e(wL(),1),DL=_e(i_(),1),PL=_e(IL(),1),RL=_e(CL(),1),BL=_e(TL(),1),LL=_e(td(),1);var a0=class{constructor({apiUrl:e,chainType:r,apiTimeout:n}){var i,s;this.chainType=r||Cd,this.apiUrl=e||((i=An[this.chainType])==null?void 0:i.apiAddress),this.apiTimeout=n||((s=An[this.chainType])==null?void 0:s.apiTimeout)}apiGet(e,r){return Te(this,null,function*(){if(typeof fetch!="undefined"){let n=new AbortController,i=setTimeout(()=>n.abort(),this.apiTimeout),s={method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},signal:n.signal};try{let o=yield fetch(this.apiUrl+"/"+e,Object.assign(s,r||{})),a=yield o.json();if(!o.ok){let u=(a==null?void 0:a.error)||o.status;return clearTimeout(i),Promise.reject(u)}return clearTimeout(i),a}catch(o){this.handleApiError(o,e)}}})}apiPost(e,r,n){return Te(this,null,function*(){if(typeof fetch!="undefined"){let i=new AbortController,s=setTimeout(()=>i.abort(),this.apiTimeout),o={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r||{}),signal:i.signal};try{let a=yield fetch(this.apiUrl+"/"+e,Object.assign(o,n||{})),u=yield a.json();if(!a.ok){let l=(u==null?void 0:u.error)||a.status;return clearTimeout(s),Promise.reject(l)}return clearTimeout(s),u}catch(a){this.handleApiError(a,e)}}})}handleApiError(e,r){if(!e.response)throw new Error(`Request error on url [${r}]: [${e.toString()}]`);let n=e.response.data,i=n.error||n.message||JSON.stringify(n);throw new Error(i)}sendTransaction(e){return Te(this,null,function*(){return(yield this.apiPost("transactions",e.toSendable())).txHash})}getAccount(e){return Te(this,null,function*(){let r=yield this.apiGet(`accounts/${e.bech32()}`);return{address:new o0.Address((r==null?void 0:r.address)||""),nonce:Number((r==null?void 0:r.nonce)||0),balance:new xL.default((r==null?void 0:r.balance)||0),code:(r==null?void 0:r.code)||"",userName:(r==null?void 0:r.username)||""}})}getTransaction(e){return Te(this,null,function*(){let r=yield this.apiGet(`transactions/${e}`),n=new NL.TransactionStatus(r.status);return{hash:e,type:r.type||"",nonce:r.nonce||0,round:r.round,epoch:r.epoch||0,value:(r.value||0).toString(),sender:new o0.Address(r.sender),receiver:new o0.Address(r.receiver),gasPrice:r.gasPrice||0,gasLimit:r.gasLimit||0,data:h.Buffer.from(r.data||"","base64"),status:n,timestamp:r.timestamp||0,blockNonce:r.blockNonce||0,hyperblockNonce:r.hyperblockNonce||0,hyperblockHash:r.hyperblockHash||"",receipt:OL.TransactionReceipt.fromHttpResponse(r.receipt||{}),logs:DL.TransactionLogs.fromHttpResponse(r.logs||{}),contractResults:PL.ContractResults.fromApiHttpResponse(r.results||[]),isCompleted:!n.isPending()}})}queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n,value:i,caller:s}){try{let a=new LL.Query({address:e,func:r,args:n,value:i,caller:s}),u=new BL.ContractQueryRequest(a).toHttpRequest(),l=yield this.apiPost("query",u);return RL.ContractQueryResponse.fromHttpResponse(l)}catch(a){this.handleApiError(a,"query")}})}};c();var FL=(t,e,r)=>Te(void 0,null,function*(){let n=yield Td();try{n&&(yield n.login()),Ce.run("onLoginPending")}catch(s){let o=Lt(s);console.warn(`Something went wrong trying to login the user: ${o}`)}if(!n)throw new Error("Error: There were problems with auth provider initialization!");let{signature:i}=n.account;if(Ie.set("loginToken",e),i&&Ie.set("signature",i),t.networkProvider&&i)try{let s=yield n.getAddress();if(!s)throw new Error("Canceled!");Ie.set("address",s),Ie.set("loginMethod","browser-extension"),Ie.set("expires",fc()),yield us(t),Ce.run("onLoggedIn");let o=r.getToken(s,e,i);return Ie.set("accessToken",o),n}catch(s){console.warn(`Something went wrong trying to synchronize the user account: ${s==null?void 0:s.message}`),Ce.run("onLogout")}});c();c();var qF=_e(UF(),1),VF=_e(tf(),1);var cte=t=>{var r;let e=document.createElement("template");return e.innerHTML=t.trim(),(r=e.content.firstChild)==null?void 0:r.cloneNode(!0)},lte=t=>{let e=`${M2}?wallet-connect=${encodeURIComponent(t)}`,r=document.createElement("a");return r.setAttribute("href",e),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank"),r.textContent="xPortal login",r.classList.add("elven-qr-code-deep-link"),r},fte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairings"),t},hte=()=>{let t=document.createElement("div");return t.textContent="Existing WalletConnect pairings:",t.classList.add("elven-wc-pairings-header"),t},N_={},dte=(t,e)=>{let r=document.createElement("button");return r.classList.add("elven-wc-pairings-remove-btn"),r.textContent="\u2716",N_[t.topic]=new AbortController,r.addEventListener("click",n=>{n.stopImmediatePropagation(),e(t.topic)},{signal:N_[t.topic].signal}),r},E0={},pte=(t,e,r)=>{var o,a;let n=document.createElement("div"),i=document.createElement("div");n.classList.add("elven-wc-pairing-item"),n.setAttribute("id",t.topic),i.classList.add("elven-wc-pairing-item-description"),i.textContent=`${(o=t.peerMetadata)==null?void 0:o.description} (${(a=t.peerMetadata)==null?void 0:a.url})`,n.appendChild(i);let s=dte(t,e);return n.appendChild(s),E0[t.topic]=new AbortController,n.addEventListener("click",()=>r(t.topic),{signal:E0[t.topic].signal}),n},gte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairing-item-confirm-msessage"),t.setAttribute("id","elven-wc-pairing-item-confirm-msessage"),t.innerText="Confirm on xPortal app!",t},yte=t=>{if(!t)return;let e=document.getElementById(t);e==null||e.remove()},mte=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),wte=t=>Te(void 0,null,function*(){return t?yield qF.default.toString(t,{type:"svg"}):void 0}),jF=(t,e,r,n)=>Te(void 0,null,function*(){if(!t)throw new Error("Please provide the QR Code and WalletConnect Pairings container id!");let i=null;typeof t=="string"?i=document.getElementById(t):t instanceof HTMLElement&&(i=t);let s=yield wte(e),o;if(s&&(o=cte(s)),i&&o&&(i.replaceChildren(),i.appendChild(o),mte()&&i.appendChild(lte(e))),i&&r instanceof VF.WalletConnectV2Provider){let a=r.pairings,u=f=>Te(void 0,null,function*(){try{f&&(yield r.logout({topic:f}),yte(f))}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to remove the existing pairing: ${y}`)}finally{E0[f].abort()}}),l=f=>Te(void 0,null,function*(){try{let{approval:d}=yield r.connect({topic:f,methods:["mvx_cancelAction"]});if(!document.getElementById("elven-wc-pairing-item-confirm-msessage")){let m=document.getElementById(f);m==null||m.after(gte())}yield r.login({approval:d,token:n})}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to login the user: ${y}`)}finally{for(let d of Object.values(E0))d==null||d.abort();for(let d of Object.values(N_))d==null||d.abort()}});if(a&&a.length>0){let f=fte();i.appendChild(f);let d=hte();f.appendChild(d);for(let y of a){let m=pte(y,u,l);f.appendChild(m)}}}return i});var v0=_e(tf(),1);var HF=(t,e,r,n)=>Te(void 0,null,function*(){if(!n)throw new Error("You haven't provided the QR code container DOM element id");let i=Zg(t.initOptions.walletConnectV2RelayAddresses);if(!i||!t.networkProvider)throw new Error("Something wen't wrong with the initialization (ApiNetworkProvider or Wallet Connect Bridge address), plese try to refresh the page!");if(!t.initOptions.walletConnectV2ProjectId)throw new Error("Please provide your WalletConnect project id. You can get it here: https://cloud.walletconnect.com)");if(!t.initOptions.chainType)throw new Error("Please provide the chain type in ElvenJS.init function!");let s,o={onClientLogin:()=>Te(void 0,null,function*(){if(t.dappProvider instanceof v0.WalletConnectV2Provider){Ce.run("onLoginPending");let u=yield t.dappProvider.getAddress(),l=yield t.dappProvider.getSignature();Ie.set("address",u),Ie.set("loginMethod","mobile"),Ie.set("expires",fc()),yield us(t),l&&Ie.set("signature",l),Ie.set("loginToken",e);let f=r.getToken(u,e,l);Ie.set("accessToken",f),Ce.run("onLoggedIn"),s==null||s.replaceChildren()}}),onClientLogout:()=>Te(void 0,null,function*(){t.dappProvider instanceof v0.WalletConnectV2Provider&&(yield lc(t),Ce.run("onLogout"))}),onClientEvent:u=>{console.log("wc2 session event: ",u)}},a=new v0.WalletConnectV2Provider(o,An[t.initOptions.chainType].shortId,i,t.initOptions.walletConnectV2ProjectId);try{if(a){t.dappProvider=a,Ce.run("onQrPending"),yield a.init();let{uri:u,approval:l}=yield a.connect({methods:["mvx_cancelAction"]}),f=e?`${u}&token=${e}`:u;return n&&f&&(s=yield jF(n,f,a,e),Ce.run("onQrLoaded")),yield a.login({approval:l,token:e}),a}}catch(u){let l=Lt(u);console.warn(`Something went wrong trying to login the user: ${l}`),Ce.run("onLogout")}});c();var GF=_e(uf(),1);var QF=(t,e,r)=>Te(void 0,null,function*(){let n=new GF.WalletProvider(`${t}${Sd}`),s={callbackUrl:typeof window!="undefined"?encodeURIComponent(`${window.location.origin}${r||"/"}`):"/",token:e};try{return Ce.run("onLoginPending"),Ie.set("loginMethod","web-wallet"),yield n.login(s),Ie.set("expires",fc()),Ie.set("loginToken",e),n}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to login the user: ${a}`),Ie.set("loginMethod",""),Ce.run("onLogout")}});c();var qo=t=>{if(typeof window!="undefined"){let e=new URL(window.location.href);return new URLSearchParams(e.search).get(t)}};c();var kF=_e(uf(),1);var zF=_e(Zb(),1);var WF=(t,e)=>Te(void 0,null,function*(){let r=qo("signature"),n=qo("address"),i=Ie.get("address"),s=Ie.get("loginToken");if(r&&Ie.set("signature",r),n||i){n&&(Ie.set("address",n),window.history.replaceState(null,"",window.location.pathname));let o=new kF.WalletProvider(`${t}${Sd}`);if(r&&e&&n){let u=new zF.NativeAuthClient({apiUrl:e}).getToken(n,s,r);Ie.set("accessToken",u)}return o}});c();var KF=_e($h(),1),$F=_e(Rw(),1);var A0=(t,e)=>Te(void 0,null,function*(){Ce.run("onTxSent",t),yield new $F.TransactionWatcher(e).awaitCompleted(t);let n=t.getSender(),i=new KF.Account(n),s=yield e.getAccount(n);i.update(s),Ie.set("address",i.address.bech32()),Ie.set("nonce",i.getNonceThenIncrement().valueOf()),Ie.set("balance",i.balance.toString()),Ce.run("onTxFinalized",t)});c();var b0=_e(JF(),1),XF=_e(Wc(),1);var ZF=(t,e,r)=>Te(void 0,null,function*(){if(qo(b0.WALLET_PROVIDER_CALLBACK_PARAM)===b0.WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED&&t&&e&&"getTransactionsFromWalletUrl"in t){let i=t.getTransactionsFromWalletUrl();window.history.replaceState(null,"",window.location.pathname);let s=i==null?void 0:i[0];if(s){s.data=h.Buffer.from(s.data).toString("base64");let o=XF.Transaction.fromPlainObject(s);o.setNonce(r);try{Ce.run("onTxStarted",o),yield e.sendTransaction(o),yield A0(o,e)}catch(a){let u=Lt(a);throw Ce.run("onTxError",o,u),new Error(`Error: Transaction signing failed! ${u}`)}}}});var Cf=class{static init(e){return Te(this,null,function*(){let r=Ie.get();if(r.expires&&Xg(r.expires)){Ie.clear(),this.dappProvider=void 0;return}this.initOptions=xf({chainType:Cd,apiUrl:F2,apiTimeout:1e4,walletConnectV2ProjectId:"",walletConnectV2RelayAddresses:U2},e),this.networkProvider=new a0(this.initOptions),this.initOptions.onLoginPending&&Ce.set("onLoginPending",this.initOptions.onLoginPending),this.initOptions.onLoggedIn&&Ce.set("onLoggedIn",this.initOptions.onLoggedIn),this.initOptions.onQrPending&&Ce.set("onQrPending",this.initOptions.onQrPending),this.initOptions.onQrLoaded&&Ce.set("onQrLoaded",this.initOptions.onQrLoaded),this.initOptions.onLogout&&Ce.set("onLogout",this.initOptions.onLogout),this.initOptions.onTxStarted&&Ce.set("onTxStarted",this.initOptions.onTxStarted),this.initOptions.onTxSent&&Ce.set("onTxSent",this.initOptions.onTxSent),this.initOptions.onTxFinalized&&Ce.set("onTxFinalized",this.initOptions.onTxFinalized),this.initOptions.onTxError&&Ce.set("onTxError",this.initOptions.onTxError),((r==null?void 0:r.address)||r.loginMethod==="web-wallet"&&qo("address"))&&(r!=null&&r.loginMethod)&&(Ce.run("onLoginPending"),r.loginMethod==="browser-extension"&&(this.dappProvider=yield Td()),r.loginMethod==="mobile"&&(this.dappProvider=yield hL(this)),r.loginMethod==="web-wallet"&&this.initOptions.chainType&&(this.dappProvider=yield WF(An[this.initOptions.chainType].walletAddress,this.initOptions.apiUrl)),yield us(this),Ce.run("onLoggedIn"),r.loginMethod==="web-wallet"&&(yield ZF(this.dappProvider,this.networkProvider,r.nonce)))})}static login(e,r){return Te(this,null,function*(){var o,a;if(!Object.values(Ro).includes(e))throw new Error("Error: Wrong login method!");if(!this.networkProvider)throw new Error("Error: Login failed: Use ElvenJs.init() first!");let i=new n5.NativeAuthClient({apiUrl:(o=this.initOptions)==null?void 0:o.apiUrl}),s=yield i.initialize();try{if(e==="browser-extension"){let u=yield FL(this,s,i);this.dappProvider=u}if(e==="mobile"){let u=yield HF(this,s,i,r==null?void 0:r.qrCodeContainer);this.dappProvider=u}if(e==="web-wallet"&&((a=this.initOptions)!=null&&a.chainType)){let u=yield QF(An[this.initOptions.chainType].walletAddress,s,r==null?void 0:r.callbackRoute);this.dappProvider=u}}catch(u){let l=Lt(u);throw new Error(`Error: ${l}`)}})}static logout(){return Te(this,null,function*(){try{let e=yield lc(this);return this.dappProvider=void 0,e}catch(e){let r=Lt(e);console.warn("Something went wrong when logging out: ",r)}})}static signAndSendTransaction(e){return Te(this,null,function*(){if(!this.dappProvider)throw new Error("Error: Transaction signing failed: There is no active session!");if(!this.networkProvider)throw new Error("Error: Transaction signing failed: There is no active network provider!");try{Ce.run("onTxStarted",e);let r=Ie.get();e.setNonce(r.nonce),this.dappProvider instanceof e5.ExtensionProvider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof t5.WalletConnectV2Provider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof r5.WalletProvider&&(yield this.dappProvider.signTransaction(e)),r.loginMethod!=="web-wallet"&&(yield this.networkProvider.sendTransaction(e),yield A0(e,this.networkProvider))}catch(r){let n=Lt(r);throw Ce.run("onTxError",e,n),new Error(`Error: Transaction signing failed! ${n}`)}return e})}static queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n=[],value:i=0,caller:s}){if(!this.networkProvider)throw new Error("Error: Query failed: There is no active network provider!");if(!e||!r)throw new Error("Error: Query failed: The Query arguments are not valid! Address and func required");try{return yield this.networkProvider.queryContract({address:e,func:r,args:n,value:i,caller:s})}catch(a){let u=Lt(a);throw new Error(`Error: Smart contract query failed! ${u}`)}})}},Sf=Cf;Sf.storage=Ie,Sf.destroy=()=>{Cf.networkProvider=void 0,Cf.dappProvider=void 0,Cf.initOptions=void 0,Ce.clear()};var export_Account=Ite.Account;var export_Address=_te.Address;var export_AddressType=o5.AddressType;var export_AddressValue=o5.AddressValue;var export_BigUIntType=Bn.BigUIntType;var export_BigUIntValue=Bn.BigUIntValue;var export_BooleanType=s5.BooleanType;var export_BooleanValue=s5.BooleanValue;var export_BytesType=i5.BytesType;var export_BytesValue=i5.BytesValue;var export_ContractFunction=Nte.ContractFunction;var export_GasEstimator=bte.GasEstimator;var export_SmartContract=xte.SmartContract;var export_TokenTransfer=vte.TokenTransfer;var export_Transaction=Ste.Transaction;var export_TransactionPayload=Cte.TransactionPayload;var export_TransactionWatcher=Tte.TransactionWatcher;var export_TransferTransactionsFactory=Ate.TransferTransactionsFactory;var export_U16Type=Bn.U16Type;var export_U16Value=Bn.U16Value;var export_U32Type=Bn.U32Type;var export_U32Value=Bn.U32Value;var export_U64Type=Bn.U64Type;var export_U64Value=Bn.U64Value;var export_U8Type=Bn.U8Type;var export_U8Value=Bn.U8Value;export{export_Account as Account,export_Address as Address,export_AddressType as AddressType,export_AddressValue as AddressValue,export_BigUIntType as BigUIntType,export_BigUIntValue as BigUIntValue,export_BooleanType as BooleanType,export_BooleanValue as BooleanValue,export_BytesType as BytesType,export_BytesValue as BytesValue,export_ContractFunction as ContractFunction,Sf as ElvenJS,export_GasEstimator as GasEstimator,Ro as LoginMethodsEnum,export_SmartContract as SmartContract,export_TokenTransfer as TokenTransfer,export_Transaction as Transaction,export_TransactionPayload as TransactionPayload,export_TransactionWatcher as TransactionWatcher,export_TransferTransactionsFactory as TransferTransactionsFactory,export_U16Type as U16Type,export_U16Value as U16Value,export_U32Type as U32Type,export_U32Value as U32Value,export_U64Type as U64Type,export_U64Value as U64Value,export_U8Type as U8Type,export_U8Value as U8Value}; /*! Bundled license information: ieee754/index.js: diff --git a/example/elven.js b/example/elven.js index 4e7899c..64263d3 100644 --- a/example/elven.js +++ b/example/elven.js @@ -37,7 +37,7 @@ Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),t.put(r,13)}};EF.exp The chosen QR Code version cannot contain this amount of data. Minimum version required to store current data is: `+s+`. `);let o=Zee(e,r,i),a=m0.getSymbolSize(e),u=new Hee(a);return Kee(u,e),$ee(u),Yee(u,e),A_(u,r,0),e>=7&&Jee(u,e),Xee(u,o),isNaN(n)&&(n=b_.getBestMask(u,A_.bind(null,u,r))),b_.applyMask(n,u),A_(u,r,n),{modules:u,version:e,errorCorrectionLevel:r,maskPattern:n,segments:i}}OF.create=function(e,r){if(typeof e>"u"||e==="")throw new Error("No input text");let n=E_.M,i,s;return typeof r<"u"&&(n=E_.from(r.errorCorrectionLevel,E_.M),i=y0.from(r.version),s=b_.from(r.maskPattern),r.toSJISFunc&&m0.setToSJISFunction(r.toSJISFunc)),tte(e,i,n,s)}});var I_=w(Uo=>{c();function PF(t){if(typeof t=="number"&&(t=t.toString()),typeof t!="string")throw new Error("Color should be defined as hex string");let e=t.slice().replace("#","").split("");if(e.length<3||e.length===5||e.length>8)throw new Error("Invalid hex color: "+t);(e.length===3||e.length===4)&&(e=Array.prototype.concat.apply([],e.map(function(n){return[n,n]}))),e.length===6&&e.push("F","F");let r=parseInt(e.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+e.slice(0,6).join("")}}Uo.getOptions=function(e){e||(e={}),e.color||(e.color={});let r=typeof e.margin>"u"||e.margin===null||e.margin<0?4:e.margin,n=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:n,scale:n?4:i,margin:r,color:{dark:PF(e.color.dark||"#000000ff"),light:PF(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}};Uo.getScale=function(e,r){return r.width&&r.width>=e+r.margin*2?r.width/(e+r.margin*2):r.scale};Uo.getImageWidth=function(e,r){let n=Uo.getScale(e,r);return Math.floor((e+r.margin*2)*n)};Uo.qrToImageData=function(e,r,n){let i=r.modules.size,s=r.modules.data,o=Uo.getScale(i,n),a=Math.floor((i+n.margin*2)*o),u=n.margin*o,l=[n.color.light,n.color.dark];for(let f=0;f=u&&d>=u&&f{c();var S_=I_();function rte(t,e,r){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=r,e.width=r,e.style.height=r+"px",e.style.width=r+"px"}function nte(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}w0.render=function(e,r,n){let i=n,s=r;typeof i>"u"&&(!r||!r.getContext)&&(i=r,r=void 0),r||(s=nte()),i=S_.getOptions(i);let o=S_.getImageWidth(e.modules.size,i),a=s.getContext("2d"),u=a.createImageData(o,o);return S_.qrToImageData(u.data,e,i),rte(a,s,o),a.putImageData(u,0,0),s};w0.renderToDataURL=function(e,r,n){let i=n;typeof i>"u"&&(!r||!r.getContext)&&(i=r,r=void 0),i||(i={});let s=w0.render(e,r,i),o=i.type||"image/png",a=i.rendererOpts||{};return s.toDataURL(o,a.quality)}});var FF=w(LF=>{c();var ite=I_();function BF(t,e){let r=t.a/255,n=e+'="'+t.hex+'"';return r<1?n+" "+e+'-opacity="'+r.toFixed(2).slice(1)+'"':n}function C_(t,e,r){let n=t+e;return typeof r<"u"&&(n+=" "+r),n}function ste(t,e,r){let n="",i=0,s=!1,o=0;for(let a=0;a0&&u>0&&t[a-1]||(n+=s?C_("M",u+r,.5+l+r):C_("m",i,0),i=0,s=!1),u+1':"",l="',f='viewBox="0 0 '+a+" "+a+'"',y=''+u+l+` -`;return typeof n=="function"&&n(null,y),y}});var UF=w(If=>{c();var ote=UL(),T_=DF(),MF=RF(),ate=FF();function x_(t,e,r,n,i){let s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!ote())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=r,r=e,e=n=void 0):o===3&&(e.getContext&&typeof i>"u"?(i=n,n=void 0):(i=n,n=r,r=e,e=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(r=e,e=n=void 0):o===2&&!e.getContext&&(n=r,r=e,e=void 0),new Promise(function(u,l){try{let f=T_.create(r,n);u(t(f,e,n))}catch(f){l(f)}})}try{let u=T_.create(r,n);i(null,t(u,e,n))}catch(u){i(u)}}If.create=T_.create;If.toCanvas=x_.bind(null,MF.render);If.toDataURL=x_.bind(null,MF.renderToDataURL);If.toString=x_.bind(null,function(t,e,r){return ate.render(t,r)})});var JF=w(ps=>{"use strict";c();var Ete=ps&&ps.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),YF=ps&&ps.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&Ete(e,t,r)};Object.defineProperty(ps,"__esModule",{value:!0});YF(uf(),ps);YF(_b(),ps)});c();var vte=_e(iI(),1),Ate=_e(HT(),1),bte=_e(QT(),1),_te=_e(tr(),1),Ite=_e($h(),1),Ste=_e(Wc(),1),Cte=_e(jc(),1),Tte=_e(Rw(),1),xte=_e(D2(),1),Nte=_e(Zh(),1),i5=_e(yi(),1),Bn=_e(Rc(),1),s5=_e(Oc(),1),o5=_e(aa(),1);c();c();var q2=_e(RE(),1);c();c();var Id="elvenjs_state",F2="https://devnet-api.multiversx.com";var Sd="/dapp/init",Cd="devnet",M2="https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://xportal.com/",U2=["wss://relay.walletconnect.com"],An={devnet:{id:"devnet",shortId:"D",name:"Devnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://devnet-wallet.multiversx.com",apiAddress:"https://devnet-api.multiversx.com",explorerAddress:"https://devnet-explorer.multiversx.com",apiTimeout:1e4},testnet:{id:"testnet",shortId:"T",name:"Testnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://testnet-wallet.multiversx.com",apiAddress:"https://testnet-api.multiversx.com",explorerAddress:"https://testnet-explorer.multiversx.com",apiTimeout:1e4},mainnet:{id:"mainnet",shortId:"1",name:"Mainnet",egldLabel:"EGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://wallet.multiversx.com",apiAddress:"https://api.multiversx.com",explorerAddress:"https://explorer.multiversx.com",apiTimeout:1e4}};var Ie={get(t){let e=localStorage.getItem(Id);if(!e)return{};let r=JSON.parse(e);return t?r[t]:r},set(t,e){let r=this.get();r[t]=e,localStorage.setItem(Id,JSON.stringify(r))},clear(){localStorage.removeItem(Id)}};var Td=()=>Te(void 0,null,function*(){let t=q2.ExtensionProvider.getInstance();try{let e=yield t.init(),r=Ie.get();if(r!=null&&r.address&&t.setAddress(r.address),!e){console.warn("Something went wrong when trying to initialize the ExtensionProvider..");return}return t}catch(e){console.warn("Can't initialize the Dapp Provider!")}});var e5=_e(RE(),1),t5=_e(tf(),1),r5=_e(uf(),1),n5=_e(Zb(),1);c();var fL=_e(tf(),1);c();c();var Ce=class{static set(e,r){if(!e)return;let n=R_(xf({},this.events),{[e]:r});this.events=n}static get(e){if(!(!e||!this.events))return this.events[e]}static run(e,...r){var n,i;!e||!this.events||(i=(n=this.events)[e])==null||i.call(n,...r)}static clear(){this.events=void 0}};c();var Ro=(i=>(i.ledger="ledger",i.mobile="mobile",i.webWallet="web-wallet",i.browserExtension="browser-extension",i))(Ro||{});var lc=t=>Te(void 0,null,function*(){if(!t.dappProvider)throw new Error("Error: Logout failed: There is no active session!");Ce.run("onLoginPending");let e=yield t.dappProvider.logout();return e&&(Ie.clear(),Ce.run("onLogout")),e});c();var cL=_e(tr(),1),lL=_e($h(),1);c();var Lt=t=>typeof t=="string"?t.toUpperCase():t instanceof Error?t.message:`Error: ${JSON.stringify(t)}`;c();var fc=()=>new Date().setHours(new Date().getHours()+24),Xg=t=>Date.now()>t;var us=t=>Te(void 0,null,function*(){let e=Ie.get("address"),r=Ie.get("expires");if(!(r&&Xg(r))&&e&&t.networkProvider){let i=new cL.Address(e),s=new lL.Account(i);try{let o=yield t.networkProvider.getAccount(i);Ie.set("address",e),Ie.set("nonce",o.nonce.valueOf()),Ie.set("balance",o.balance.toString()),s.update(o)}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to synchronize the user account: ${a}`)}}});c();function Zg(t){return t[Math.floor(Math.random()*t.length)]}var hL=t=>Te(void 0,null,function*(){if(!t.initOptions.walletConnectV2ProjectId||!t.initOptions.chainType)return;let e={onClientLogin:()=>{us(t),Ce.run("onLoggedIn")},onClientLogout:()=>lc(t),onClientEvent:i=>{console.log("wc2 session event: ",i)}},r=Zg(t.initOptions.walletConnectV2RelayAddresses),n=new fL.WalletConnectV2Provider(e,An[t.initOptions.chainType].shortId,r,t.initOptions.walletConnectV2ProjectId);try{return yield n.init(),n}catch(i){console.warn("Can't initialize the Dapp Provider!")}});c();var xL=_e(Yt(),1),o0=_e(tr(),1),NL=_e(dL(),1),OL=_e(wL(),1),DL=_e(i_(),1),PL=_e(IL(),1),RL=_e(CL(),1),BL=_e(TL(),1),LL=_e(td(),1);var a0=class{constructor({apiUrl:e,chainType:r,apiTimeout:n}){var i,s;this.chainType=r||Cd,this.apiUrl=e||((i=An[this.chainType])==null?void 0:i.apiAddress),this.apiTimeout=n||((s=An[this.chainType])==null?void 0:s.apiTimeout)}apiGet(e,r){return Te(this,null,function*(){if(typeof fetch!="undefined"){let n=new AbortController,i=setTimeout(()=>n.abort(),this.apiTimeout),s={method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},signal:n.signal};try{let o=yield fetch(this.apiUrl+"/"+e,Object.assign(s,r||{})),a=yield o.json();if(!o.ok){let u=(a==null?void 0:a.error)||o.status;return clearTimeout(i),Promise.reject(u)}return clearTimeout(i),a}catch(o){this.handleApiError(o,e)}}})}apiPost(e,r,n){return Te(this,null,function*(){if(typeof fetch!="undefined"){let i=new AbortController,s=setTimeout(()=>i.abort(),this.apiTimeout),o={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r||{}),signal:i.signal};try{let a=yield fetch(this.apiUrl+"/"+e,Object.assign(o,n||{})),u=yield a.json();if(!a.ok){let l=(u==null?void 0:u.error)||a.status;return clearTimeout(s),Promise.reject(l)}return clearTimeout(s),u}catch(a){this.handleApiError(a,e)}}})}handleApiError(e,r){if(!e.response)throw new Error(`Request error on url [${r}]: [${e.toString()}]`);let n=e.response.data,i=n.error||n.message||JSON.stringify(n);throw new Error(i)}sendTransaction(e){return Te(this,null,function*(){return(yield this.apiPost("transactions",e.toSendable())).txHash})}getAccount(e){return Te(this,null,function*(){let r=yield this.apiGet(`accounts/${e.bech32()}`);return{address:new o0.Address((r==null?void 0:r.address)||""),nonce:Number((r==null?void 0:r.nonce)||0),balance:new xL.default((r==null?void 0:r.balance)||0),code:(r==null?void 0:r.code)||"",userName:(r==null?void 0:r.username)||""}})}getTransaction(e){return Te(this,null,function*(){let r=yield this.apiGet(`transactions/${e}`),n=new NL.TransactionStatus(r.status);return{hash:e,type:r.type||"",nonce:r.nonce||0,round:r.round,epoch:r.epoch||0,value:(r.value||0).toString(),sender:new o0.Address(r.sender),receiver:new o0.Address(r.receiver),gasPrice:r.gasPrice||0,gasLimit:r.gasLimit||0,data:h.Buffer.from(r.data||"","base64"),status:n,timestamp:r.timestamp||0,blockNonce:r.blockNonce||0,hyperblockNonce:r.hyperblockNonce||0,hyperblockHash:r.hyperblockHash||"",receipt:OL.TransactionReceipt.fromHttpResponse(r.receipt||{}),logs:DL.TransactionLogs.fromHttpResponse(r.logs||{}),contractResults:PL.ContractResults.fromApiHttpResponse(r.results||[]),isCompleted:!n.isPending()}})}queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n,value:i,caller:s}){try{let a=new LL.Query({address:e,func:r,args:n,value:i,caller:s}),u=new BL.ContractQueryRequest(a).toHttpRequest(),l=yield this.apiPost("query",u);return RL.ContractQueryResponse.fromHttpResponse(l)}catch(a){this.handleApiError(a,"query")}})}};c();var FL=(t,e,r)=>Te(void 0,null,function*(){let n=yield Td();try{n&&(yield n.login()),Ce.run("onLoginPending")}catch(s){let o=Lt(s);console.warn(`Something went wrong trying to login the user: ${o}`)}if(!n)throw new Error("Error: There were problems with auth provider initialization!");let{signature:i}=n.account;if(Ie.set("loginToken",e),i&&Ie.set("signature",i),t.networkProvider&&i)try{let s=yield n.getAddress();if(!s)throw new Error("Canceled!");Ie.set("address",s),Ie.set("loginMethod","browser-extension"),Ie.set("expires",fc()),yield us(t),Ce.run("onLoggedIn");let o=r.getToken(s,e,i);return Ie.set("accessToken",o),n}catch(s){console.warn(`Something went wrong trying to synchronize the user account: ${s==null?void 0:s.message}`),Ce.run("onLogout")}});c();c();var qF=_e(UF(),1),VF=_e(tf(),1);var cte=t=>{var r;let e=document.createElement("template");return e.innerHTML=t.trim(),(r=e.content.firstChild)==null?void 0:r.cloneNode(!0)},lte=t=>{let e=`${M2}?wallet-connect=${encodeURIComponent(t)}`,r=document.createElement("a");return r.setAttribute("href",e),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank"),r.textContent="xPortal login",r.classList.add("elven-qr-code-deep-link"),r},fte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairings"),t},hte=()=>{let t=document.createElement("div");return t.textContent="Existing WalletConnect pairings:",t.classList.add("elven-wc-pairings-header"),t},N_={},dte=(t,e)=>{let r=document.createElement("button");return r.classList.add("elven-wc-pairings-remove-btn"),r.textContent="\u2716",N_[t.topic]=new AbortController,r.addEventListener("click",n=>{n.stopImmediatePropagation(),e(t.topic)},{signal:N_[t.topic].signal}),r},E0={},pte=(t,e,r)=>{var o,a;let n=document.createElement("div"),i=document.createElement("div");n.classList.add("elven-wc-pairing-item"),n.setAttribute("id",t.topic),i.classList.add("elven-wc-pairing-item-description"),i.textContent=`${(o=t.peerMetadata)==null?void 0:o.description} (${(a=t.peerMetadata)==null?void 0:a.url})`,n.appendChild(i);let s=dte(t,e);return n.appendChild(s),E0[t.topic]=new AbortController,n.addEventListener("click",()=>r(t.topic),{signal:E0[t.topic].signal}),n},gte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairing-item-confirm-msessage"),t.setAttribute("id","elven-wc-pairing-item-confirm-msessage"),t.innerText="Confirm on xPortal app!",t},yte=t=>{if(!t)return;let e=document.getElementById(t);e==null||e.remove()},mte=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),wte=t=>Te(void 0,null,function*(){return t?yield qF.default.toString(t,{type:"svg"}):void 0}),jF=(t,e,r,n)=>Te(void 0,null,function*(){if(!t)throw new Error("Please provide the QR Code and WalletConnect Pairings container id!");let i=null;typeof t=="string"?i=document.getElementById(t):t instanceof HTMLElement&&(i=t);let s=yield wte(e),o;if(s&&(o=cte(s)),i&&o&&(i.replaceChildren(),i.appendChild(o),mte()&&i.appendChild(lte(e))),i&&r instanceof VF.WalletConnectV2Provider){let a=r.pairings,u=f=>Te(void 0,null,function*(){try{f&&(yield r.logout({topic:f}),yte(f))}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to remove the existing pairing: ${y}`)}finally{E0[f].abort()}}),l=f=>Te(void 0,null,function*(){try{let{approval:d}=yield r.connect({topic:f,methods:["mvx_cancelAction"]});if(!document.getElementById("elven-wc-pairing-item-confirm-msessage")){let m=document.getElementById(f);m==null||m.after(gte())}yield r.login({approval:d,token:n})}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to login the user: ${y}`)}finally{for(let d of Object.values(E0))d==null||d.abort();for(let d of Object.values(N_))d==null||d.abort()}});if(a&&a.length>0){let f=fte();i.appendChild(f);let d=hte();f.appendChild(d);for(let y of a){let m=pte(y,u,l);f.appendChild(m)}}}return i});var v0=_e(tf(),1);var HF=(t,e,r,n)=>Te(void 0,null,function*(){if(!n)throw new Error("You haven't provided the QR code container DOM element id");let i=Zg(t.initOptions.walletConnectV2RelayAddresses);if(!i||!t.networkProvider)throw new Error("Something wen't wrong with the initialization (ApiNetworkProvider or Wallet Connect Bridge address), plese try to refresh the page!");if(!t.initOptions.walletConnectV2ProjectId)throw new Error("Please provide your WalletConnect project id. You can get it here: https://cloud.walletconnect.com)");if(!t.initOptions.chainType)throw new Error("Please provide the chain type in ElvenJS.init function!");let s,o={onClientLogin:()=>Te(void 0,null,function*(){if(t.dappProvider instanceof v0.WalletConnectV2Provider){Ce.run("onLoginPending");let u=yield t.dappProvider.getAddress(),l=yield t.dappProvider.getSignature();Ie.set("address",u),Ie.set("loginMethod","mobile"),Ie.set("expires",fc()),yield us(t),l&&Ie.set("signature",l),Ie.set("loginToken",e);let f=r.getToken(u,e,l);Ie.set("accessToken",f),Ce.run("onLoggedIn"),s==null||s.replaceChildren()}}),onClientLogout:()=>Te(void 0,null,function*(){t.dappProvider instanceof v0.WalletConnectV2Provider&&(yield lc(t),Ce.run("onLogout"))}),onClientEvent:u=>{console.log("wc2 session event: ",u)}},a=new v0.WalletConnectV2Provider(o,An[t.initOptions.chainType].shortId,i,t.initOptions.walletConnectV2ProjectId);try{if(a){t.dappProvider=a,Ce.run("onQrPending"),yield a.init();let{uri:u,approval:l}=yield a.connect({methods:["mvx_cancelAction"]}),f=e?`${u}&token=${e}`:u;return n&&f&&(s=yield jF(n,f,a,e),Ce.run("onQrLoaded")),yield a.login({approval:l,token:e}),a}}catch(u){let l=Lt(u);console.warn(`Something went wrong trying to login the user: ${l}`),Ce.run("onLogout")}});c();var GF=_e(uf(),1);var QF=(t,e,r)=>Te(void 0,null,function*(){let n=new GF.WalletProvider(`${t}${Sd}`),s={callbackUrl:typeof window!="undefined"?encodeURIComponent(`${window.location.origin}${r||"/"}`):"/",token:e};try{return Ce.run("onLoginPending"),Ie.set("loginMethod","web-wallet"),yield n.login(s),Ie.set("expires",fc()),Ie.set("loginToken",e),n}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to login the user: ${a}`),Ie.set("loginMethod",""),Ce.run("onLogout")}});c();var qo=t=>{if(typeof window!="undefined"){let e=new URL(window.location.href);return new URLSearchParams(e.search).get(t)}};c();var kF=_e(uf(),1);var zF=_e(Zb(),1);var WF=(t,e)=>Te(void 0,null,function*(){let r=qo("signature"),n=qo("address"),i=Ie.get("address"),s=Ie.get("loginToken");if(r&&Ie.set("signature",r),n||i){n&&(Ie.set("address",n),window.history.replaceState(null,"",window.location.pathname));let o=new kF.WalletProvider(`${t}${Sd}`);if(r&&e&&i){let u=new zF.NativeAuthClient({apiUrl:e}).getToken(i,s,r);Ie.set("accessToken",u)}return o}});c();var KF=_e($h(),1),$F=_e(Rw(),1);var A0=(t,e)=>Te(void 0,null,function*(){Ce.run("onTxSent",t),yield new $F.TransactionWatcher(e).awaitCompleted(t);let n=t.getSender(),i=new KF.Account(n),s=yield e.getAccount(n);i.update(s),Ie.set("address",i.address.bech32()),Ie.set("nonce",i.getNonceThenIncrement().valueOf()),Ie.set("balance",i.balance.toString()),Ce.run("onTxFinalized",t)});c();var b0=_e(JF(),1),XF=_e(Wc(),1);var ZF=(t,e,r)=>Te(void 0,null,function*(){if(qo(b0.WALLET_PROVIDER_CALLBACK_PARAM)===b0.WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED&&t&&e&&"getTransactionsFromWalletUrl"in t){let i=t.getTransactionsFromWalletUrl();window.history.replaceState(null,"",window.location.pathname);let s=i==null?void 0:i[0];if(s){s.data=h.Buffer.from(s.data).toString("base64");let o=XF.Transaction.fromPlainObject(s);o.setNonce(r);try{Ce.run("onTxStarted",o),yield e.sendTransaction(o),yield A0(o,e)}catch(a){let u=Lt(a);throw Ce.run("onTxError",o,u),new Error(`Error: Transaction signing failed! ${u}`)}}}});var Cf=class{static init(e){return Te(this,null,function*(){let r=Ie.get();if(r.expires&&Xg(r.expires)){Ie.clear(),this.dappProvider=void 0;return}this.initOptions=xf({chainType:Cd,apiUrl:F2,apiTimeout:1e4,walletConnectV2ProjectId:"",walletConnectV2RelayAddresses:U2},e),this.networkProvider=new a0(this.initOptions),this.initOptions.onLoginPending&&Ce.set("onLoginPending",this.initOptions.onLoginPending),this.initOptions.onLoggedIn&&Ce.set("onLoggedIn",this.initOptions.onLoggedIn),this.initOptions.onQrPending&&Ce.set("onQrPending",this.initOptions.onQrPending),this.initOptions.onQrLoaded&&Ce.set("onQrLoaded",this.initOptions.onQrLoaded),this.initOptions.onLogout&&Ce.set("onLogout",this.initOptions.onLogout),this.initOptions.onTxStarted&&Ce.set("onTxStarted",this.initOptions.onTxStarted),this.initOptions.onTxSent&&Ce.set("onTxSent",this.initOptions.onTxSent),this.initOptions.onTxFinalized&&Ce.set("onTxFinalized",this.initOptions.onTxFinalized),this.initOptions.onTxError&&Ce.set("onTxError",this.initOptions.onTxError),((r==null?void 0:r.address)||r.loginMethod==="web-wallet"&&qo("address"))&&(r!=null&&r.loginMethod)&&(Ce.run("onLoginPending"),r.loginMethod==="browser-extension"&&(this.dappProvider=yield Td()),r.loginMethod==="mobile"&&(this.dappProvider=yield hL(this)),r.loginMethod==="web-wallet"&&this.initOptions.chainType&&(this.dappProvider=yield WF(An[this.initOptions.chainType].walletAddress,this.initOptions.apiUrl)),yield us(this),Ce.run("onLoggedIn"),r.loginMethod==="web-wallet"&&(yield ZF(this.dappProvider,this.networkProvider,r.nonce)))})}static login(e,r){return Te(this,null,function*(){var o,a;if(!Object.values(Ro).includes(e))throw new Error("Error: Wrong login method!");if(!this.networkProvider)throw new Error("Error: Login failed: Use ElvenJs.init() first!");let i=new n5.NativeAuthClient({apiUrl:(o=this.initOptions)==null?void 0:o.apiUrl}),s=yield i.initialize();try{if(e==="browser-extension"){let u=yield FL(this,s,i);this.dappProvider=u}if(e==="mobile"){let u=yield HF(this,s,i,r==null?void 0:r.qrCodeContainer);this.dappProvider=u}if(e==="web-wallet"&&((a=this.initOptions)!=null&&a.chainType)){let u=yield QF(An[this.initOptions.chainType].walletAddress,s,r==null?void 0:r.callbackRoute);this.dappProvider=u}}catch(u){let l=Lt(u);throw new Error(`Error: ${l}`)}})}static logout(){return Te(this,null,function*(){try{let e=yield lc(this);return this.dappProvider=void 0,e}catch(e){let r=Lt(e);console.warn("Something went wrong when logging out: ",r)}})}static signAndSendTransaction(e){return Te(this,null,function*(){if(!this.dappProvider)throw new Error("Error: Transaction signing failed: There is no active session!");if(!this.networkProvider)throw new Error("Error: Transaction signing failed: There is no active network provider!");try{Ce.run("onTxStarted",e);let r=Ie.get();e.setNonce(r.nonce),this.dappProvider instanceof e5.ExtensionProvider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof t5.WalletConnectV2Provider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof r5.WalletProvider&&(yield this.dappProvider.signTransaction(e)),r.loginMethod!=="web-wallet"&&(yield this.networkProvider.sendTransaction(e),yield A0(e,this.networkProvider))}catch(r){let n=Lt(r);throw Ce.run("onTxError",e,n),new Error(`Error: Transaction signing failed! ${n}`)}return e})}static queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n=[],value:i=0,caller:s}){if(!this.networkProvider)throw new Error("Error: Query failed: There is no active network provider!");if(!e||!r)throw new Error("Error: Query failed: The Query arguments are not valid! Address and func required");try{return yield this.networkProvider.queryContract({address:e,func:r,args:n,value:i,caller:s})}catch(a){let u=Lt(a);throw new Error(`Error: Smart contract query failed! ${u}`)}})}},Sf=Cf;Sf.storage=Ie,Sf.destroy=()=>{Cf.networkProvider=void 0,Cf.dappProvider=void 0,Cf.initOptions=void 0,Ce.clear()};var export_Account=Ite.Account;var export_Address=_te.Address;var export_AddressType=o5.AddressType;var export_AddressValue=o5.AddressValue;var export_BigUIntType=Bn.BigUIntType;var export_BigUIntValue=Bn.BigUIntValue;var export_BooleanType=s5.BooleanType;var export_BooleanValue=s5.BooleanValue;var export_BytesType=i5.BytesType;var export_BytesValue=i5.BytesValue;var export_ContractFunction=Nte.ContractFunction;var export_GasEstimator=bte.GasEstimator;var export_SmartContract=xte.SmartContract;var export_TokenTransfer=vte.TokenTransfer;var export_Transaction=Ste.Transaction;var export_TransactionPayload=Cte.TransactionPayload;var export_TransactionWatcher=Tte.TransactionWatcher;var export_TransferTransactionsFactory=Ate.TransferTransactionsFactory;var export_U16Type=Bn.U16Type;var export_U16Value=Bn.U16Value;var export_U32Type=Bn.U32Type;var export_U32Value=Bn.U32Value;var export_U64Type=Bn.U64Type;var export_U64Value=Bn.U64Value;var export_U8Type=Bn.U8Type;var export_U8Value=Bn.U8Value;export{export_Account as Account,export_Address as Address,export_AddressType as AddressType,export_AddressValue as AddressValue,export_BigUIntType as BigUIntType,export_BigUIntValue as BigUIntValue,export_BooleanType as BooleanType,export_BooleanValue as BooleanValue,export_BytesType as BytesType,export_BytesValue as BytesValue,export_ContractFunction as ContractFunction,Sf as ElvenJS,export_GasEstimator as GasEstimator,Ro as LoginMethodsEnum,export_SmartContract as SmartContract,export_TokenTransfer as TokenTransfer,export_Transaction as Transaction,export_TransactionPayload as TransactionPayload,export_TransactionWatcher as TransactionWatcher,export_TransferTransactionsFactory as TransferTransactionsFactory,export_U16Type as U16Type,export_U16Value as U16Value,export_U32Type as U32Type,export_U32Value as U32Value,export_U64Type as U64Type,export_U64Value as U64Value,export_U8Type as U8Type,export_U8Value as U8Value}; +`;return typeof n=="function"&&n(null,y),y}});var UF=w(If=>{c();var ote=UL(),T_=DF(),MF=RF(),ate=FF();function x_(t,e,r,n,i){let s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!ote())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=r,r=e,e=n=void 0):o===3&&(e.getContext&&typeof i>"u"?(i=n,n=void 0):(i=n,n=r,r=e,e=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(r=e,e=n=void 0):o===2&&!e.getContext&&(n=r,r=e,e=void 0),new Promise(function(u,l){try{let f=T_.create(r,n);u(t(f,e,n))}catch(f){l(f)}})}try{let u=T_.create(r,n);i(null,t(u,e,n))}catch(u){i(u)}}If.create=T_.create;If.toCanvas=x_.bind(null,MF.render);If.toDataURL=x_.bind(null,MF.renderToDataURL);If.toString=x_.bind(null,function(t,e,r){return ate.render(t,r)})});var JF=w(ps=>{"use strict";c();var Ete=ps&&ps.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),YF=ps&&ps.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&Ete(e,t,r)};Object.defineProperty(ps,"__esModule",{value:!0});YF(uf(),ps);YF(_b(),ps)});c();var vte=_e(iI(),1),Ate=_e(HT(),1),bte=_e(QT(),1),_te=_e(tr(),1),Ite=_e($h(),1),Ste=_e(Wc(),1),Cte=_e(jc(),1),Tte=_e(Rw(),1),xte=_e(D2(),1),Nte=_e(Zh(),1),i5=_e(yi(),1),Bn=_e(Rc(),1),s5=_e(Oc(),1),o5=_e(aa(),1);c();c();var q2=_e(RE(),1);c();c();var Id="elvenjs_state",F2="https://devnet-api.multiversx.com";var Sd="/dapp/init",Cd="devnet",M2="https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://xportal.com/",U2=["wss://relay.walletconnect.com"],An={devnet:{id:"devnet",shortId:"D",name:"Devnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://devnet-wallet.multiversx.com",apiAddress:"https://devnet-api.multiversx.com",explorerAddress:"https://devnet-explorer.multiversx.com",apiTimeout:1e4},testnet:{id:"testnet",shortId:"T",name:"Testnet",egldLabel:"xEGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://testnet-wallet.multiversx.com",apiAddress:"https://testnet-api.multiversx.com",explorerAddress:"https://testnet-explorer.multiversx.com",apiTimeout:1e4},mainnet:{id:"mainnet",shortId:"1",name:"Mainnet",egldLabel:"EGLD",egldDenomination:"18",decimals:"4",gasPerDataByte:"1500",walletAddress:"https://wallet.multiversx.com",apiAddress:"https://api.multiversx.com",explorerAddress:"https://explorer.multiversx.com",apiTimeout:1e4}};var Ie={get(t){let e=localStorage.getItem(Id);if(!e)return{};let r=JSON.parse(e);return t?r[t]:r},set(t,e){let r=this.get();r[t]=e,localStorage.setItem(Id,JSON.stringify(r))},clear(){localStorage.removeItem(Id)}};var Td=()=>Te(void 0,null,function*(){let t=q2.ExtensionProvider.getInstance();try{let e=yield t.init(),r=Ie.get();if(r!=null&&r.address&&t.setAddress(r.address),!e){console.warn("Something went wrong when trying to initialize the ExtensionProvider..");return}return t}catch(e){console.warn("Can't initialize the Dapp Provider!")}});var e5=_e(RE(),1),t5=_e(tf(),1),r5=_e(uf(),1),n5=_e(Zb(),1);c();var fL=_e(tf(),1);c();c();var Ce=class{static set(e,r){if(!e)return;let n=R_(xf({},this.events),{[e]:r});this.events=n}static get(e){if(!(!e||!this.events))return this.events[e]}static run(e,...r){var n,i;!e||!this.events||(i=(n=this.events)[e])==null||i.call(n,...r)}static clear(){this.events=void 0}};c();var Ro=(i=>(i.ledger="ledger",i.mobile="mobile",i.webWallet="web-wallet",i.browserExtension="browser-extension",i))(Ro||{});var lc=t=>Te(void 0,null,function*(){if(!t.dappProvider)throw new Error("Error: Logout failed: There is no active session!");Ce.run("onLoginPending");let e=yield t.dappProvider.logout();return e&&(Ie.clear(),Ce.run("onLogout")),e});c();var cL=_e(tr(),1),lL=_e($h(),1);c();var Lt=t=>typeof t=="string"?t.toUpperCase():t instanceof Error?t.message:`Error: ${JSON.stringify(t)}`;c();var fc=()=>new Date().setHours(new Date().getHours()+24),Xg=t=>Date.now()>t;var us=t=>Te(void 0,null,function*(){let e=Ie.get("address"),r=Ie.get("expires");if(!(r&&Xg(r))&&e&&t.networkProvider){let i=new cL.Address(e),s=new lL.Account(i);try{let o=yield t.networkProvider.getAccount(i);Ie.set("address",e),Ie.set("nonce",o.nonce.valueOf()),Ie.set("balance",o.balance.toString()),s.update(o)}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to synchronize the user account: ${a}`)}}});c();function Zg(t){return t[Math.floor(Math.random()*t.length)]}var hL=t=>Te(void 0,null,function*(){if(!t.initOptions.walletConnectV2ProjectId||!t.initOptions.chainType)return;let e={onClientLogin:()=>{us(t),Ce.run("onLoggedIn")},onClientLogout:()=>lc(t),onClientEvent:i=>{console.log("wc2 session event: ",i)}},r=Zg(t.initOptions.walletConnectV2RelayAddresses),n=new fL.WalletConnectV2Provider(e,An[t.initOptions.chainType].shortId,r,t.initOptions.walletConnectV2ProjectId);try{return yield n.init(),n}catch(i){console.warn("Can't initialize the Dapp Provider!")}});c();var xL=_e(Yt(),1),o0=_e(tr(),1),NL=_e(dL(),1),OL=_e(wL(),1),DL=_e(i_(),1),PL=_e(IL(),1),RL=_e(CL(),1),BL=_e(TL(),1),LL=_e(td(),1);var a0=class{constructor({apiUrl:e,chainType:r,apiTimeout:n}){var i,s;this.chainType=r||Cd,this.apiUrl=e||((i=An[this.chainType])==null?void 0:i.apiAddress),this.apiTimeout=n||((s=An[this.chainType])==null?void 0:s.apiTimeout)}apiGet(e,r){return Te(this,null,function*(){if(typeof fetch!="undefined"){let n=new AbortController,i=setTimeout(()=>n.abort(),this.apiTimeout),s={method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},signal:n.signal};try{let o=yield fetch(this.apiUrl+"/"+e,Object.assign(s,r||{})),a=yield o.json();if(!o.ok){let u=(a==null?void 0:a.error)||o.status;return clearTimeout(i),Promise.reject(u)}return clearTimeout(i),a}catch(o){this.handleApiError(o,e)}}})}apiPost(e,r,n){return Te(this,null,function*(){if(typeof fetch!="undefined"){let i=new AbortController,s=setTimeout(()=>i.abort(),this.apiTimeout),o={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r||{}),signal:i.signal};try{let a=yield fetch(this.apiUrl+"/"+e,Object.assign(o,n||{})),u=yield a.json();if(!a.ok){let l=(u==null?void 0:u.error)||a.status;return clearTimeout(s),Promise.reject(l)}return clearTimeout(s),u}catch(a){this.handleApiError(a,e)}}})}handleApiError(e,r){if(!e.response)throw new Error(`Request error on url [${r}]: [${e.toString()}]`);let n=e.response.data,i=n.error||n.message||JSON.stringify(n);throw new Error(i)}sendTransaction(e){return Te(this,null,function*(){return(yield this.apiPost("transactions",e.toSendable())).txHash})}getAccount(e){return Te(this,null,function*(){let r=yield this.apiGet(`accounts/${e.bech32()}`);return{address:new o0.Address((r==null?void 0:r.address)||""),nonce:Number((r==null?void 0:r.nonce)||0),balance:new xL.default((r==null?void 0:r.balance)||0),code:(r==null?void 0:r.code)||"",userName:(r==null?void 0:r.username)||""}})}getTransaction(e){return Te(this,null,function*(){let r=yield this.apiGet(`transactions/${e}`),n=new NL.TransactionStatus(r.status);return{hash:e,type:r.type||"",nonce:r.nonce||0,round:r.round,epoch:r.epoch||0,value:(r.value||0).toString(),sender:new o0.Address(r.sender),receiver:new o0.Address(r.receiver),gasPrice:r.gasPrice||0,gasLimit:r.gasLimit||0,data:h.Buffer.from(r.data||"","base64"),status:n,timestamp:r.timestamp||0,blockNonce:r.blockNonce||0,hyperblockNonce:r.hyperblockNonce||0,hyperblockHash:r.hyperblockHash||"",receipt:OL.TransactionReceipt.fromHttpResponse(r.receipt||{}),logs:DL.TransactionLogs.fromHttpResponse(r.logs||{}),contractResults:PL.ContractResults.fromApiHttpResponse(r.results||[]),isCompleted:!n.isPending()}})}queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n,value:i,caller:s}){try{let a=new LL.Query({address:e,func:r,args:n,value:i,caller:s}),u=new BL.ContractQueryRequest(a).toHttpRequest(),l=yield this.apiPost("query",u);return RL.ContractQueryResponse.fromHttpResponse(l)}catch(a){this.handleApiError(a,"query")}})}};c();var FL=(t,e,r)=>Te(void 0,null,function*(){let n=yield Td();try{n&&(yield n.login()),Ce.run("onLoginPending")}catch(s){let o=Lt(s);console.warn(`Something went wrong trying to login the user: ${o}`)}if(!n)throw new Error("Error: There were problems with auth provider initialization!");let{signature:i}=n.account;if(Ie.set("loginToken",e),i&&Ie.set("signature",i),t.networkProvider&&i)try{let s=yield n.getAddress();if(!s)throw new Error("Canceled!");Ie.set("address",s),Ie.set("loginMethod","browser-extension"),Ie.set("expires",fc()),yield us(t),Ce.run("onLoggedIn");let o=r.getToken(s,e,i);return Ie.set("accessToken",o),n}catch(s){console.warn(`Something went wrong trying to synchronize the user account: ${s==null?void 0:s.message}`),Ce.run("onLogout")}});c();c();var qF=_e(UF(),1),VF=_e(tf(),1);var cte=t=>{var r;let e=document.createElement("template");return e.innerHTML=t.trim(),(r=e.content.firstChild)==null?void 0:r.cloneNode(!0)},lte=t=>{let e=`${M2}?wallet-connect=${encodeURIComponent(t)}`,r=document.createElement("a");return r.setAttribute("href",e),r.setAttribute("rel","noopener noreferrer nofollow"),r.setAttribute("target","_blank"),r.textContent="xPortal login",r.classList.add("elven-qr-code-deep-link"),r},fte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairings"),t},hte=()=>{let t=document.createElement("div");return t.textContent="Existing WalletConnect pairings:",t.classList.add("elven-wc-pairings-header"),t},N_={},dte=(t,e)=>{let r=document.createElement("button");return r.classList.add("elven-wc-pairings-remove-btn"),r.textContent="\u2716",N_[t.topic]=new AbortController,r.addEventListener("click",n=>{n.stopImmediatePropagation(),e(t.topic)},{signal:N_[t.topic].signal}),r},E0={},pte=(t,e,r)=>{var o,a;let n=document.createElement("div"),i=document.createElement("div");n.classList.add("elven-wc-pairing-item"),n.setAttribute("id",t.topic),i.classList.add("elven-wc-pairing-item-description"),i.textContent=`${(o=t.peerMetadata)==null?void 0:o.description} (${(a=t.peerMetadata)==null?void 0:a.url})`,n.appendChild(i);let s=dte(t,e);return n.appendChild(s),E0[t.topic]=new AbortController,n.addEventListener("click",()=>r(t.topic),{signal:E0[t.topic].signal}),n},gte=()=>{let t=document.createElement("div");return t.classList.add("elven-wc-pairing-item-confirm-msessage"),t.setAttribute("id","elven-wc-pairing-item-confirm-msessage"),t.innerText="Confirm on xPortal app!",t},yte=t=>{if(!t)return;let e=document.getElementById(t);e==null||e.remove()},mte=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),wte=t=>Te(void 0,null,function*(){return t?yield qF.default.toString(t,{type:"svg"}):void 0}),jF=(t,e,r,n)=>Te(void 0,null,function*(){if(!t)throw new Error("Please provide the QR Code and WalletConnect Pairings container id!");let i=null;typeof t=="string"?i=document.getElementById(t):t instanceof HTMLElement&&(i=t);let s=yield wte(e),o;if(s&&(o=cte(s)),i&&o&&(i.replaceChildren(),i.appendChild(o),mte()&&i.appendChild(lte(e))),i&&r instanceof VF.WalletConnectV2Provider){let a=r.pairings,u=f=>Te(void 0,null,function*(){try{f&&(yield r.logout({topic:f}),yte(f))}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to remove the existing pairing: ${y}`)}finally{E0[f].abort()}}),l=f=>Te(void 0,null,function*(){try{let{approval:d}=yield r.connect({topic:f,methods:["mvx_cancelAction"]});if(!document.getElementById("elven-wc-pairing-item-confirm-msessage")){let m=document.getElementById(f);m==null||m.after(gte())}yield r.login({approval:d,token:n})}catch(d){let y=Lt(d);console.warn(`Something went wrong trying to login the user: ${y}`)}finally{for(let d of Object.values(E0))d==null||d.abort();for(let d of Object.values(N_))d==null||d.abort()}});if(a&&a.length>0){let f=fte();i.appendChild(f);let d=hte();f.appendChild(d);for(let y of a){let m=pte(y,u,l);f.appendChild(m)}}}return i});var v0=_e(tf(),1);var HF=(t,e,r,n)=>Te(void 0,null,function*(){if(!n)throw new Error("You haven't provided the QR code container DOM element id");let i=Zg(t.initOptions.walletConnectV2RelayAddresses);if(!i||!t.networkProvider)throw new Error("Something wen't wrong with the initialization (ApiNetworkProvider or Wallet Connect Bridge address), plese try to refresh the page!");if(!t.initOptions.walletConnectV2ProjectId)throw new Error("Please provide your WalletConnect project id. You can get it here: https://cloud.walletconnect.com)");if(!t.initOptions.chainType)throw new Error("Please provide the chain type in ElvenJS.init function!");let s,o={onClientLogin:()=>Te(void 0,null,function*(){if(t.dappProvider instanceof v0.WalletConnectV2Provider){Ce.run("onLoginPending");let u=yield t.dappProvider.getAddress(),l=yield t.dappProvider.getSignature();Ie.set("address",u),Ie.set("loginMethod","mobile"),Ie.set("expires",fc()),yield us(t),l&&Ie.set("signature",l),Ie.set("loginToken",e);let f=r.getToken(u,e,l);Ie.set("accessToken",f),Ce.run("onLoggedIn"),s==null||s.replaceChildren()}}),onClientLogout:()=>Te(void 0,null,function*(){t.dappProvider instanceof v0.WalletConnectV2Provider&&(yield lc(t),Ce.run("onLogout"))}),onClientEvent:u=>{console.log("wc2 session event: ",u)}},a=new v0.WalletConnectV2Provider(o,An[t.initOptions.chainType].shortId,i,t.initOptions.walletConnectV2ProjectId);try{if(a){t.dappProvider=a,Ce.run("onQrPending"),yield a.init();let{uri:u,approval:l}=yield a.connect({methods:["mvx_cancelAction"]}),f=e?`${u}&token=${e}`:u;return n&&f&&(s=yield jF(n,f,a,e),Ce.run("onQrLoaded")),yield a.login({approval:l,token:e}),a}}catch(u){let l=Lt(u);console.warn(`Something went wrong trying to login the user: ${l}`),Ce.run("onLogout")}});c();var GF=_e(uf(),1);var QF=(t,e,r)=>Te(void 0,null,function*(){let n=new GF.WalletProvider(`${t}${Sd}`),s={callbackUrl:typeof window!="undefined"?encodeURIComponent(`${window.location.origin}${r||"/"}`):"/",token:e};try{return Ce.run("onLoginPending"),Ie.set("loginMethod","web-wallet"),yield n.login(s),Ie.set("expires",fc()),Ie.set("loginToken",e),n}catch(o){let a=Lt(o);console.warn(`Something went wrong trying to login the user: ${a}`),Ie.set("loginMethod",""),Ce.run("onLogout")}});c();var qo=t=>{if(typeof window!="undefined"){let e=new URL(window.location.href);return new URLSearchParams(e.search).get(t)}};c();var kF=_e(uf(),1);var zF=_e(Zb(),1);var WF=(t,e)=>Te(void 0,null,function*(){let r=qo("signature"),n=qo("address"),i=Ie.get("address"),s=Ie.get("loginToken");if(r&&Ie.set("signature",r),n||i){n&&(Ie.set("address",n),window.history.replaceState(null,"",window.location.pathname));let o=new kF.WalletProvider(`${t}${Sd}`);if(r&&e&&n){let u=new zF.NativeAuthClient({apiUrl:e}).getToken(n,s,r);Ie.set("accessToken",u)}return o}});c();var KF=_e($h(),1),$F=_e(Rw(),1);var A0=(t,e)=>Te(void 0,null,function*(){Ce.run("onTxSent",t),yield new $F.TransactionWatcher(e).awaitCompleted(t);let n=t.getSender(),i=new KF.Account(n),s=yield e.getAccount(n);i.update(s),Ie.set("address",i.address.bech32()),Ie.set("nonce",i.getNonceThenIncrement().valueOf()),Ie.set("balance",i.balance.toString()),Ce.run("onTxFinalized",t)});c();var b0=_e(JF(),1),XF=_e(Wc(),1);var ZF=(t,e,r)=>Te(void 0,null,function*(){if(qo(b0.WALLET_PROVIDER_CALLBACK_PARAM)===b0.WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED&&t&&e&&"getTransactionsFromWalletUrl"in t){let i=t.getTransactionsFromWalletUrl();window.history.replaceState(null,"",window.location.pathname);let s=i==null?void 0:i[0];if(s){s.data=h.Buffer.from(s.data).toString("base64");let o=XF.Transaction.fromPlainObject(s);o.setNonce(r);try{Ce.run("onTxStarted",o),yield e.sendTransaction(o),yield A0(o,e)}catch(a){let u=Lt(a);throw Ce.run("onTxError",o,u),new Error(`Error: Transaction signing failed! ${u}`)}}}});var Cf=class{static init(e){return Te(this,null,function*(){let r=Ie.get();if(r.expires&&Xg(r.expires)){Ie.clear(),this.dappProvider=void 0;return}this.initOptions=xf({chainType:Cd,apiUrl:F2,apiTimeout:1e4,walletConnectV2ProjectId:"",walletConnectV2RelayAddresses:U2},e),this.networkProvider=new a0(this.initOptions),this.initOptions.onLoginPending&&Ce.set("onLoginPending",this.initOptions.onLoginPending),this.initOptions.onLoggedIn&&Ce.set("onLoggedIn",this.initOptions.onLoggedIn),this.initOptions.onQrPending&&Ce.set("onQrPending",this.initOptions.onQrPending),this.initOptions.onQrLoaded&&Ce.set("onQrLoaded",this.initOptions.onQrLoaded),this.initOptions.onLogout&&Ce.set("onLogout",this.initOptions.onLogout),this.initOptions.onTxStarted&&Ce.set("onTxStarted",this.initOptions.onTxStarted),this.initOptions.onTxSent&&Ce.set("onTxSent",this.initOptions.onTxSent),this.initOptions.onTxFinalized&&Ce.set("onTxFinalized",this.initOptions.onTxFinalized),this.initOptions.onTxError&&Ce.set("onTxError",this.initOptions.onTxError),((r==null?void 0:r.address)||r.loginMethod==="web-wallet"&&qo("address"))&&(r!=null&&r.loginMethod)&&(Ce.run("onLoginPending"),r.loginMethod==="browser-extension"&&(this.dappProvider=yield Td()),r.loginMethod==="mobile"&&(this.dappProvider=yield hL(this)),r.loginMethod==="web-wallet"&&this.initOptions.chainType&&(this.dappProvider=yield WF(An[this.initOptions.chainType].walletAddress,this.initOptions.apiUrl)),yield us(this),Ce.run("onLoggedIn"),r.loginMethod==="web-wallet"&&(yield ZF(this.dappProvider,this.networkProvider,r.nonce)))})}static login(e,r){return Te(this,null,function*(){var o,a;if(!Object.values(Ro).includes(e))throw new Error("Error: Wrong login method!");if(!this.networkProvider)throw new Error("Error: Login failed: Use ElvenJs.init() first!");let i=new n5.NativeAuthClient({apiUrl:(o=this.initOptions)==null?void 0:o.apiUrl}),s=yield i.initialize();try{if(e==="browser-extension"){let u=yield FL(this,s,i);this.dappProvider=u}if(e==="mobile"){let u=yield HF(this,s,i,r==null?void 0:r.qrCodeContainer);this.dappProvider=u}if(e==="web-wallet"&&((a=this.initOptions)!=null&&a.chainType)){let u=yield QF(An[this.initOptions.chainType].walletAddress,s,r==null?void 0:r.callbackRoute);this.dappProvider=u}}catch(u){let l=Lt(u);throw new Error(`Error: ${l}`)}})}static logout(){return Te(this,null,function*(){try{let e=yield lc(this);return this.dappProvider=void 0,e}catch(e){let r=Lt(e);console.warn("Something went wrong when logging out: ",r)}})}static signAndSendTransaction(e){return Te(this,null,function*(){if(!this.dappProvider)throw new Error("Error: Transaction signing failed: There is no active session!");if(!this.networkProvider)throw new Error("Error: Transaction signing failed: There is no active network provider!");try{Ce.run("onTxStarted",e);let r=Ie.get();e.setNonce(r.nonce),this.dappProvider instanceof e5.ExtensionProvider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof t5.WalletConnectV2Provider&&(yield this.dappProvider.signTransaction(e)),this.dappProvider instanceof r5.WalletProvider&&(yield this.dappProvider.signTransaction(e)),r.loginMethod!=="web-wallet"&&(yield this.networkProvider.sendTransaction(e),yield A0(e,this.networkProvider))}catch(r){let n=Lt(r);throw Ce.run("onTxError",e,n),new Error(`Error: Transaction signing failed! ${n}`)}return e})}static queryContract(o){return Te(this,arguments,function*({address:e,func:r,args:n=[],value:i=0,caller:s}){if(!this.networkProvider)throw new Error("Error: Query failed: There is no active network provider!");if(!e||!r)throw new Error("Error: Query failed: The Query arguments are not valid! Address and func required");try{return yield this.networkProvider.queryContract({address:e,func:r,args:n,value:i,caller:s})}catch(a){let u=Lt(a);throw new Error(`Error: Smart contract query failed! ${u}`)}})}},Sf=Cf;Sf.storage=Ie,Sf.destroy=()=>{Cf.networkProvider=void 0,Cf.dappProvider=void 0,Cf.initOptions=void 0,Ce.clear()};var export_Account=Ite.Account;var export_Address=_te.Address;var export_AddressType=o5.AddressType;var export_AddressValue=o5.AddressValue;var export_BigUIntType=Bn.BigUIntType;var export_BigUIntValue=Bn.BigUIntValue;var export_BooleanType=s5.BooleanType;var export_BooleanValue=s5.BooleanValue;var export_BytesType=i5.BytesType;var export_BytesValue=i5.BytesValue;var export_ContractFunction=Nte.ContractFunction;var export_GasEstimator=bte.GasEstimator;var export_SmartContract=xte.SmartContract;var export_TokenTransfer=vte.TokenTransfer;var export_Transaction=Ste.Transaction;var export_TransactionPayload=Cte.TransactionPayload;var export_TransactionWatcher=Tte.TransactionWatcher;var export_TransferTransactionsFactory=Ate.TransferTransactionsFactory;var export_U16Type=Bn.U16Type;var export_U16Value=Bn.U16Value;var export_U32Type=Bn.U32Type;var export_U32Value=Bn.U32Value;var export_U64Type=Bn.U64Type;var export_U64Value=Bn.U64Value;var export_U8Type=Bn.U8Type;var export_U8Value=Bn.U8Value;export{export_Account as Account,export_Address as Address,export_AddressType as AddressType,export_AddressValue as AddressValue,export_BigUIntType as BigUIntType,export_BigUIntValue as BigUIntValue,export_BooleanType as BooleanType,export_BooleanValue as BooleanValue,export_BytesType as BytesType,export_BytesValue as BytesValue,export_ContractFunction as ContractFunction,Sf as ElvenJS,export_GasEstimator as GasEstimator,Ro as LoginMethodsEnum,export_SmartContract as SmartContract,export_TokenTransfer as TokenTransfer,export_Transaction as Transaction,export_TransactionPayload as TransactionPayload,export_TransactionWatcher as TransactionWatcher,export_TransferTransactionsFactory as TransferTransactionsFactory,export_U16Type as U16Type,export_U16Value as U16Value,export_U32Type as U32Type,export_U32Value as U32Value,export_U64Type as U64Type,export_U64Value as U64Value,export_U8Type as U8Type,export_U8Value as U8Value}; /*! Bundled license information: ieee754/index.js: diff --git a/package.json b/package.json index 5120c40..ef8cc0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elven.js", - "version": "0.10.0", + "version": "0.10.1", "description": "Authenticate, sign and send transactions on the MultiversX blockchain in the browser.", "type": "module", "module": "build/elven.js", diff --git a/src/auth/init-web-wallet-provider.ts b/src/auth/init-web-wallet-provider.ts index 5e789bd..7c2f2b0 100644 --- a/src/auth/init-web-wallet-provider.ts +++ b/src/auth/init-web-wallet-provider.ts @@ -25,12 +25,12 @@ export const initWebWalletProvider = async ( `${webWalletAddress}${DAPP_INIT_ROUTE}` ); - if (signature && apiUrl && lsAddress) { + if (signature && apiUrl && urlAddress) { const nativeAuthClient = new NativeAuthClient({ apiUrl, }); const accessToken = nativeAuthClient.getToken( - lsAddress, + urlAddress, loginToken, signature );