metahunt/Assets/WebGLTemplates/Web3GL-2020x/assets/index-27fffd64.js
2024-02-11 13:53:18 +05:30

2 lines
75 KiB
JavaScript
Raw Blame History

import{i as pr,g as mr,d as vr,a as Ke,s as gr,r as Qe,b as Fe,c as yr,m as Le}from"./mobile-b423cf06.js";import{m as Ft,n as Tt,U as Mr,V as he,W as _r,_ as Pe}from"./index-c4efa424.js";import{t as wr}from"./tslib.es6-c2094241.js";const br=["session_request","session_update","exchange_key","connect","disconnect","display_uri","modal_closed","transport_open","transport_close","transport_error"],Ge=["eth_sendTransaction","eth_signTransaction","eth_sign","eth_signTypedData","eth_signTypedData_v1","eth_signTypedData_v2","eth_signTypedData_v3","eth_signTypedData_v4","personal_sign","wallet_addEthereumChain","wallet_switchEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"];var le={},Sr={get exports(){return le},set exports(s){le=s}};(function(s){(function(i,a){function p(l,t){if(!l)throw new Error(t||"Assertion failed")}function v(l,t){l.super_=t;var r=function(){};r.prototype=t.prototype,l.prototype=new r,l.prototype.constructor=l}function c(l,t,r){if(c.isBN(l))return l;this.negative=0,this.words=null,this.length=0,this.red=null,l!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(l||0,t||10,r||"be"))}typeof i=="object"?i.exports=c:a.BN=c,c.BN=c,c.wordSize=26;var T;try{T=Ft.Buffer}catch{}c.isBN=function(t){return t instanceof c?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===c.wordSize&&Array.isArray(t.words)},c.max=function(t,r){return t.cmp(r)>0?t:r},c.min=function(t,r){return t.cmp(r)<0?t:r},c.prototype._init=function(t,r,n){if(typeof t=="number")return this._initNumber(t,r,n);if(typeof t=="object")return this._initArray(t,r,n);r==="hex"&&(r=16),p(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var o=0;t[0]==="-"&&o++,r===16?this._parseHex(t,o):this._parseBase(t,r,o),t[0]==="-"&&(this.negative=1),this.strip(),n==="le"&&this._initArray(this.toArray(),r,n)},c.prototype._initNumber=function(t,r,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(p(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),n==="le"&&this._initArray(this.toArray(),r,n)},c.prototype._initArray=function(t,r,n){if(p(typeof t.length=="number"),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var u,d,m=0;if(n==="be")for(o=t.length-1,u=0;o>=0;o-=3)d=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[u]|=d<<m&67108863,this.words[u+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,u++);else if(n==="le")for(o=0,u=0;o<t.length;o+=3)d=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[u]|=d<<m&67108863,this.words[u+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,u++);return this.strip()};function mt(l,t,r){for(var n=0,o=Math.min(l.length,r),u=t;u<o;u++){var d=l.charCodeAt(u)-48;n<<=4,d>=49&&d<=54?n|=d-49+10:d>=17&&d<=22?n|=d-17+10:n|=d&15}return n}c.prototype._parseHex=function(t,r){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,u,d=0;for(n=t.length-6,o=0;n>=r;n-=6)u=mt(t,n,n+6),this.words[o]|=u<<d&67108863,this.words[o+1]|=u>>>26-d&4194303,d+=24,d>=26&&(d-=26,o++);n+6!==r&&(u=mt(t,r,n+6),this.words[o]|=u<<d&67108863,this.words[o+1]|=u>>>26-d&4194303),this.strip()};function k(l,t,r,n){for(var o=0,u=Math.min(l.length,r),d=t;d<u;d++){var m=l.charCodeAt(d)-48;o*=n,m>=49?o+=m-49+10:m>=17?o+=m-17+10:o+=m}return o}c.prototype._parseBase=function(t,r,n){this.words=[0],this.length=1;for(var o=0,u=1;u<=67108863;u*=r)o++;o--,u=u/r|0;for(var d=t.length-n,m=d%o,h=Math.min(d,d-m)+n,e=0,f=n;f<h;f+=o)e=k(t,f,f+o,r),this.imuln(u),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(m!==0){var _=1;for(e=k(t,f,t.length,r),f=0;f<m;f++)_*=r;this.imuln(_),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e)}},c.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},c.prototype.clone=function(){var t=new c(null);return this.copy(t),t},c.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},c.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},c.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},c.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var vt=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],It=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],Mt=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];c.prototype.toString=function(t,r){t=t||10,r=r|0||1;var n;if(t===16||t==="hex"){n="";for(var o=0,u=0,d=0;d<this.length;d++){var m=this.words[d],h=((m<<o|u)&16777215).toString(16);u=m>>>24-o&16777215,u!==0||d!==this.length-1?n=vt[6-h.length]+h+n:n=h+n,o+=2,o>=26&&(o-=26,d--)}for(u!==0&&(n=u.toString(16)+n);n.length%r!==0;)n="0"+n;return this.negative!==0&&(n="-"+n),n}if(t===(t|0)&&t>=2&&t<=36){var e=It[t],f=Mt[t];n="";var _=this.clone();for(_.negative=0;!_.isZero();){var b=_.modn(f).toString(t);_=_.idivn(f),_.isZero()?n=b+n:n=vt[e-b.length]+b+n}for(this.isZero()&&(n="0"+n);n.length%r!==0;)n="0"+n;return this.negative!==0&&(n="-"+n),n}p(!1,"Base should be between 2 and 36")},c.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&p(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},c.prototype.toJSON=function(){return this.toString(16)},c.prototype.toBuffer=function(t,r){return p(typeof T<"u"),this.toArrayLike(T,t,r)},c.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},c.prototype.toArrayLike=function(t,r,n){var o=this.byteLength(),u=n||Math.max(1,o);p(o<=u,"byte array longer than desired length"),p(u>0,"Requested array length <= 0"),this.strip();var d=r==="le",m=new t(u),h,e,f=this.clone();if(d){for(e=0;!f.isZero();e++)h=f.andln(255),f.iushrn(8),m[e]=h;for(;e<u;e++)m[e]=0}else{for(e=0;e<u-o;e++)m[e]=0;for(e=0;!f.isZero();e++)h=f.andln(255),f.iushrn(8),m[u-e-1]=h}return m},Math.clz32?c.prototype._countBits=function(t){return 32-Math.clz32(t)}:c.prototype._countBits=function(t){var r=t,n=0;return r>=4096&&(n+=13,r>>>=13),r>=64&&(n+=7,r>>>=7),r>=8&&(n+=4,r>>>=4),r>=2&&(n+=2,r>>>=2),n+r},c.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,n=0;return r&8191||(n+=13,r>>>=13),r&127||(n+=7,r>>>=7),r&15||(n+=4,r>>>=4),r&3||(n+=2,r>>>=2),r&1||n++,n},c.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function _t(l){for(var t=new Array(l.bitLength()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=(l.words[n]&1<<o)>>>o}return t}c.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var n=this._zeroBits(this.words[r]);if(t+=n,n!==26)break}return t},c.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},c.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},c.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},c.prototype.isNeg=function(){return this.negative!==0},c.prototype.neg=function(){return this.clone().ineg()},c.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},c.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},c.prototype.ior=function(t){return p((this.negative|t.negative)===0),this.iuor(t)},c.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},c.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},c.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var n=0;n<r.length;n++)this.words[n]=this.words[n]&t.words[n];return this.length=r.length,this.strip()},c.prototype.iand=function(t){return p((this.negative|t.negative)===0),this.iuand(t)},c.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},c.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},c.prototype.iuxor=function(t){var r,n;this.length>t.length?(r=this,n=t):(r=t,n=this);for(var o=0;o<n.length;o++)this.words[o]=r.words[o]^n.words[o];if(this!==r)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=r.length,this.strip()},c.prototype.ixor=function(t){return p((this.negative|t.negative)===0),this.iuxor(t)},c.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},c.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},c.prototype.inotn=function(t){p(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,n=t%26;this._expand(r),n>0&&r--;for(var o=0;o<r;o++)this.words[o]=~this.words[o]&67108863;return n>0&&(this.words[o]=~this.words[o]&67108863>>26-n),this.strip()},c.prototype.notn=function(t){return this.clone().inotn(t)},c.prototype.setn=function(t,r){p(typeof t=="number"&&t>=0);var n=t/26|0,o=t%26;return this._expand(n+1),r?this.words[n]=this.words[n]|1<<o:this.words[n]=this.words[n]&~(1<<o),this.strip()},c.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var n,o;this.length>t.length?(n=this,o=t):(n=t,o=this);for(var u=0,d=0;d<o.length;d++)r=(n.words[d]|0)+(o.words[d]|0)+u,this.words[d]=r&67108863,u=r>>>26;for(;u!==0&&d<n.length;d++)r=(n.words[d]|0)+u,this.words[d]=r&67108863,u=r>>>26;if(this.length=n.length,u!==0)this.words[this.length]=u,this.length++;else if(n!==this)for(;d<n.length;d++)this.words[d]=n.words[d];return this},c.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},c.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var n=this.cmp(t);if(n===0)return this.negative=0,this.length=1,this.words[0]=0,this;var o,u;n>0?(o=this,u=t):(o=t,u=this);for(var d=0,m=0;m<u.length;m++)r=(o.words[m]|0)-(u.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;for(;d!==0&&m<o.length;m++)r=(o.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;if(d===0&&m<o.length&&o!==this)for(;m<o.length;m++)this.words[m]=o.words[m];return this.length=Math.max(this.length,m),o!==this&&(this.negative=1),this.strip()},c.prototype.sub=function(t){return this.clone().isub(t)};function yt(l,t,r){r.negative=t.negative^l.negative;var n=l.length+t.length|0;r.length=n,n=n-1|0;var o=l.words[0]|0,u=t.words[0]|0,d=o*u,m=d&67108863,h=d/67108864|0;r.words[0]=m;for(var e=1;e<n;e++){for(var f=h>>>26,_=h&67108863,b=Math.min(e,t.length-1),S=Math.max(0,e-l.length+1);S<=b;S++){var x=e-S|0;o=l.words[x]|0,u=t.words[S]|0,d=o*u+_,f+=d/67108864|0,_=d&67108863}r.words[e]=_|0,h=f|0}return h!==0?r.words[e]=h|0:r.length--,r.strip()}var Ot=function(t,r,n){var o=t.words,u=r.words,d=n.words,m=0,h,e,f,_=o[0]|0,b=_&8191,S=_>>>13,x=o[1]|0,E=x&8191,O=x>>>13,St=o[2]|0,q=St&8191,A=St>>>13,_e=o[3]|0,B=_e&8191,U=_e>>>13,we=o[4]|0,F=we&8191,L=we>>>13,be=o[5]|0,P=be&8191,j=be>>>13,Se=o[6]|0,H=Se&8191,$=Se>>>13,xe=o[7]|0,Z=xe&8191,D=xe>>>13,Re=o[8]|0,J=Re&8191,W=Re>>>13,Ie=o[9]|0,z=Ie&8191,K=Ie>>>13,ke=u[0]|0,Q=ke&8191,G=ke>>>13,Ee=u[1]|0,V=Ee&8191,Y=Ee>>>13,Te=u[2]|0,X=Te&8191,tt=Te>>>13,Oe=u[3]|0,et=Oe&8191,rt=Oe>>>13,qe=u[4]|0,it=qe&8191,nt=qe>>>13,Ae=u[5]|0,st=Ae&8191,ot=Ae>>>13,Ce=u[6]|0,at=Ce&8191,ht=Ce>>>13,Ne=u[7]|0,ft=Ne&8191,ut=Ne>>>13,Be=u[8]|0,ct=Be&8191,lt=Be>>>13,Ue=u[9]|0,dt=Ue&8191,pt=Ue>>>13;n.negative=t.negative^r.negative,n.length=19,h=Math.imul(b,Q),e=Math.imul(b,G),e=e+Math.imul(S,Q)|0,f=Math.imul(S,G);var Zt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,h=Math.imul(E,Q),e=Math.imul(E,G),e=e+Math.imul(O,Q)|0,f=Math.imul(O,G),h=h+Math.imul(b,V)|0,e=e+Math.imul(b,Y)|0,e=e+Math.imul(S,V)|0,f=f+Math.imul(S,Y)|0;var Dt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,h=Math.imul(q,Q),e=Math.imul(q,G),e=e+Math.imul(A,Q)|0,f=Math.imul(A,G),h=h+Math.imul(E,V)|0,e=e+Math.imul(E,Y)|0,e=e+Math.imul(O,V)|0,f=f+Math.imul(O,Y)|0,h=h+Math.imul(b,X)|0,e=e+Math.imul(b,tt)|0,e=e+Math.imul(S,X)|0,f=f+Math.imul(S,tt)|0;var Jt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,h=Math.imul(B,Q),e=Math.imul(B,G),e=e+Math.imul(U,Q)|0,f=Math.imul(U,G),h=h+Math.imul(q,V)|0,e=e+Math.imul(q,Y)|0,e=e+Math.imul(A,V)|0,f=f+Math.imul(A,Y)|0,h=h+Math.imul(E,X)|0,e=e+Math.imul(E,tt)|0,e=e+Math.imul(O,X)|0,f=f+Math.imul(O,tt)|0,h=h+Math.imul(b,et)|0,e=e+Math.imul(b,rt)|0,e=e+Math.imul(S,et)|0,f=f+Math.imul(S,rt)|0;var Wt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,h=Math.imul(F,Q),e=Math.imul(F,G),e=e+Math.imul(L,Q)|0,f=Math.imul(L,G),h=h+Math.imul(B,V)|0,e=e+Math.imul(B,Y)|0,e=e+Math.imul(U,V)|0,f=f+Math.imul(U,Y)|0,h=h+Math.imul(q,X)|0,e=e+Math.imul(q,tt)|0,e=e+Math.imul(A,X)|0,f=f+Math.imul(A,tt)|0,h=h+Math.imul(E,et)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(O,et)|0,f=f+Math.imul(O,rt)|0,h=h+Math.imul(b,it)|0,e=e+Math.imul(b,nt)|0,e=e+Math.imul(S,it)|0,f=f+Math.imul(S,nt)|0;var zt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(zt>>>26)|0,zt&=67108863,h=Math.imul(P,Q),e=Math.imul(P,G),e=e+Math.imul(j,Q)|0,f=Math.imul(j,G),h=h+Math.imul(F,V)|0,e=e+Math.imul(F,Y)|0,e=e+Math.imul(L,V)|0,f=f+Math.imul(L,Y)|0,h=h+Math.imul(B,X)|0,e=e+Math.imul(B,tt)|0,e=e+Math.imul(U,X)|0,f=f+Math.imul(U,tt)|0,h=h+Math.imul(q,et)|0,e=e+Math.imul(q,rt)|0,e=e+Math.imul(A,et)|0,f=f+Math.imul(A,rt)|0,h=h+Math.imul(E,it)|0,e=e+Math.imul(E,nt)|0,e=e+Math.imul(O,it)|0,f=f+Math.imul(O,nt)|0,h=h+Math.imul(b,st)|0,e=e+Math.imul(b,ot)|0,e=e+Math.imul(S,st)|0,f=f+Math.imul(S,ot)|0;var Kt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,h=Math.imul(H,Q),e=Math.imul(H,G),e=e+Math.imul($,Q)|0,f=Math.imul($,G),h=h+Math.imul(P,V)|0,e=e+Math.imul(P,Y)|0,e=e+Math.imul(j,V)|0,f=f+Math.imul(j,Y)|0,h=h+Math.imul(F,X)|0,e=e+Math.imul(F,tt)|0,e=e+Math.imul(L,X)|0,f=f+Math.imul(L,tt)|0,h=h+Math.imul(B,et)|0,e=e+Math.imul(B,rt)|0,e=e+Math.imul(U,et)|0,f=f+Math.imul(U,rt)|0,h=h+Math.imul(q,it)|0,e=e+Math.imul(q,nt)|0,e=e+Math.imul(A,it)|0,f=f+Math.imul(A,nt)|0,h=h+Math.imul(E,st)|0,e=e+Math.imul(E,ot)|0,e=e+Math.imul(O,st)|0,f=f+Math.imul(O,ot)|0,h=h+Math.imul(b,at)|0,e=e+Math.imul(b,ht)|0,e=e+Math.imul(S,at)|0,f=f+Math.imul(S,ht)|0;var Qt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,h=Math.imul(Z,Q),e=Math.imul(Z,G),e=e+Math.imul(D,Q)|0,f=Math.imul(D,G),h=h+Math.imul(H,V)|0,e=e+Math.imul(H,Y)|0,e=e+Math.imul($,V)|0,f=f+Math.imul($,Y)|0,h=h+Math.imul(P,X)|0,e=e+Math.imul(P,tt)|0,e=e+Math.imul(j,X)|0,f=f+Math.imul(j,tt)|0,h=h+Math.imul(F,et)|0,e=e+Math.imul(F,rt)|0,e=e+Math.imul(L,et)|0,f=f+Math.imul(L,rt)|0,h=h+Math.imul(B,it)|0,e=e+Math.imul(B,nt)|0,e=e+Math.imul(U,it)|0,f=f+Math.imul(U,nt)|0,h=h+Math.imul(q,st)|0,e=e+Math.imul(q,ot)|0,e=e+Math.imul(A,st)|0,f=f+Math.imul(A,ot)|0,h=h+Math.imul(E,at)|0,e=e+Math.imul(E,ht)|0,e=e+Math.imul(O,at)|0,f=f+Math.imul(O,ht)|0,h=h+Math.imul(b,ft)|0,e=e+Math.imul(b,ut)|0,e=e+Math.imul(S,ft)|0,f=f+Math.imul(S,ut)|0;var Gt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,h=Math.imul(J,Q),e=Math.imul(J,G),e=e+Math.imul(W,Q)|0,f=Math.imul(W,G),h=h+Math.imul(Z,V)|0,e=e+Math.imul(Z,Y)|0,e=e+Math.imul(D,V)|0,f=f+Math.imul(D,Y)|0,h=h+Math.imul(H,X)|0,e=e+Math.imul(H,tt)|0,e=e+Math.imul($,X)|0,f=f+Math.imul($,tt)|0,h=h+Math.imul(P,et)|0,e=e+Math.imul(P,rt)|0,e=e+Math.imul(j,et)|0,f=f+Math.imul(j,rt)|0,h=h+Math.imul(F,it)|0,e=e+Math.imul(F,nt)|0,e=e+Math.imul(L,it)|0,f=f+Math.imul(L,nt)|0,h=h+Math.imul(B,st)|0,e=e+Math.imul(B,ot)|0,e=e+Math.imul(U,st)|0,f=f+Math.imul(U,ot)|0,h=h+Math.imul(q,at)|0,e=e+Math.imul(q,ht)|0,e=e+Math.imul(A,at)|0,f=f+Math.imul(A,ht)|0,h=h+Math.imul(E,ft)|0,e=e+Math.imul(E,ut)|0,e=e+Math.imul(O,ft)|0,f=f+Math.imul(O,ut)|0,h=h+Math.imul(b,ct)|0,e=e+Math.imul(b,lt)|0,e=e+Math.imul(S,ct)|0,f=f+Math.imul(S,lt)|0;var Vt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,h=Math.imul(z,Q),e=Math.imul(z,G),e=e+Math.imul(K,Q)|0,f=Math.imul(K,G),h=h+Math.imul(J,V)|0,e=e+Math.imul(J,Y)|0,e=e+Math.imul(W,V)|0,f=f+Math.imul(W,Y)|0,h=h+Math.imul(Z,X)|0,e=e+Math.imul(Z,tt)|0,e=e+Math.imul(D,X)|0,f=f+Math.imul(D,tt)|0,h=h+Math.imul(H,et)|0,e=e+Math.imul(H,rt)|0,e=e+Math.imul($,et)|0,f=f+Math.imul($,rt)|0,h=h+Math.imul(P,it)|0,e=e+Math.imul(P,nt)|0,e=e+Math.imul(j,it)|0,f=f+Math.imul(j,nt)|0,h=h+Math.imul(F,st)|0,e=e+Math.imul(F,ot)|0,e=e+Math.imul(L,st)|0,f=f+Math.imul(L,ot)|0,h=h+Math.imul(B,at)|0,e=e+Math.imul(B,ht)|0,e=e+Math.imul(U,at)|0,f=f+Math.imul(U,ht)|0,h=h+Math.imul(q,ft)|0,e=e+Math.imul(q,ut)|0,e=e+Math.imul(A,ft)|0,f=f+Math.imul(A,ut)|0,h=h+Math.imul(E,ct)|0,e=e+Math.imul(E,lt)|0,e=e+Math.imul(O,ct)|0,f=f+Math.imul(O,lt)|0,h=h+Math.imul(b,dt)|0,e=e+Math.imul(b,pt)|0,e=e+Math.imul(S,dt)|0,f=f+Math.imul(S,pt)|0;var Yt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,h=Math.imul(z,V),e=Math.imul(z,Y),e=e+Math.imul(K,V)|0,f=Math.imul(K,Y),h=h+Math.imul(J,X)|0,e=e+Math.imul(J,tt)|0,e=e+Math.imul(W,X)|0,f=f+Math.imul(W,tt)|0,h=h+Math.imul(Z,et)|0,e=e+Math.imul(Z,rt)|0,e=e+Math.imul(D,et)|0,f=f+Math.imul(D,rt)|0,h=h+Math.imul(H,it)|0,e=e+Math.imul(H,nt)|0,e=e+Math.imul($,it)|0,f=f+Math.imul($,nt)|0,h=h+Math.imul(P,st)|0,e=e+Math.imul(P,ot)|0,e=e+Math.imul(j,st)|0,f=f+Math.imul(j,ot)|0,h=h+Math.imul(F,at)|0,e=e+Math.imul(F,ht)|0,e=e+Math.imul(L,at)|0,f=f+Math.imul(L,ht)|0,h=h+Math.imul(B,ft)|0,e=e+Math.imul(B,ut)|0,e=e+Math.imul(U,ft)|0,f=f+Math.imul(U,ut)|0,h=h+Math.imul(q,ct)|0,e=e+Math.imul(q,lt)|0,e=e+Math.imul(A,ct)|0,f=f+Math.imul(A,lt)|0,h=h+Math.imul(E,dt)|0,e=e+Math.imul(E,pt)|0,e=e+Math.imul(O,dt)|0,f=f+Math.imul(O,pt)|0;var Xt=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,h=Math.imul(z,X),e=Math.imul(z,tt),e=e+Math.imul(K,X)|0,f=Math.imul(K,tt),h=h+Math.imul(J,et)|0,e=e+Math.imul(J,rt)|0,e=e+Math.imul(W,et)|0,f=f+Math.imul(W,rt)|0,h=h+Math.imul(Z,it)|0,e=e+Math.imul(Z,nt)|0,e=e+Math.imul(D,it)|0,f=f+Math.imul(D,nt)|0,h=h+Math.imul(H,st)|0,e=e+Math.imul(H,ot)|0,e=e+Math.imul($,st)|0,f=f+Math.imul($,ot)|0,h=h+Math.imul(P,at)|0,e=e+Math.imul(P,ht)|0,e=e+Math.imul(j,at)|0,f=f+Math.imul(j,ht)|0,h=h+Math.imul(F,ft)|0,e=e+Math.imul(F,ut)|0,e=e+Math.imul(L,ft)|0,f=f+Math.imul(L,ut)|0,h=h+Math.imul(B,ct)|0,e=e+Math.imul(B,lt)|0,e=e+Math.imul(U,ct)|0,f=f+Math.imul(U,lt)|0,h=h+Math.imul(q,dt)|0,e=e+Math.imul(q,pt)|0,e=e+Math.imul(A,dt)|0,f=f+Math.imul(A,pt)|0;var te=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(te>>>26)|0,te&=67108863,h=Math.imul(z,et),e=Math.imul(z,rt),e=e+Math.imul(K,et)|0,f=Math.imul(K,rt),h=h+Math.imul(J,it)|0,e=e+Math.imul(J,nt)|0,e=e+Math.imul(W,it)|0,f=f+Math.imul(W,nt)|0,h=h+Math.imul(Z,st)|0,e=e+Math.imul(Z,ot)|0,e=e+Math.imul(D,st)|0,f=f+Math.imul(D,ot)|0,h=h+Math.imul(H,at)|0,e=e+Math.imul(H,ht)|0,e=e+Math.imul($,at)|0,f=f+Math.imul($,ht)|0,h=h+Math.imul(P,ft)|0,e=e+Math.imul(P,ut)|0,e=e+Math.imul(j,ft)|0,f=f+Math.imul(j,ut)|0,h=h+Math.imul(F,ct)|0,e=e+Math.imul(F,lt)|0,e=e+Math.imul(L,ct)|0,f=f+Math.imul(L,lt)|0,h=h+Math.imul(B,dt)|0,e=e+Math.imul(B,pt)|0,e=e+Math.imul(U,dt)|0,f=f+Math.imul(U,pt)|0;var ee=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,h=Math.imul(z,it),e=Math.imul(z,nt),e=e+Math.imul(K,it)|0,f=Math.imul(K,nt),h=h+Math.imul(J,st)|0,e=e+Math.imul(J,ot)|0,e=e+Math.imul(W,st)|0,f=f+Math.imul(W,ot)|0,h=h+Math.imul(Z,at)|0,e=e+Math.imul(Z,ht)|0,e=e+Math.imul(D,at)|0,f=f+Math.imul(D,ht)|0,h=h+Math.imul(H,ft)|0,e=e+Math.imul(H,ut)|0,e=e+Math.imul($,ft)|0,f=f+Math.imul($,ut)|0,h=h+Math.imul(P,ct)|0,e=e+Math.imul(P,lt)|0,e=e+Math.imul(j,ct)|0,f=f+Math.imul(j,lt)|0,h=h+Math.imul(F,dt)|0,e=e+Math.imul(F,pt)|0,e=e+Math.imul(L,dt)|0,f=f+Math.imul(L,pt)|0;var re=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(re>>>26)|0,re&=67108863,h=Math.imul(z,st),e=Math.imul(z,ot),e=e+Math.imul(K,st)|0,f=Math.imul(K,ot),h=h+Math.imul(J,at)|0,e=e+Math.imul(J,ht)|0,e=e+Math.imul(W,at)|0,f=f+Math.imul(W,ht)|0,h=h+Math.imul(Z,ft)|0,e=e+Math.imul(Z,ut)|0,e=e+Math.imul(D,ft)|0,f=f+Math.imul(D,ut)|0,h=h+Math.imul(H,ct)|0,e=e+Math.imul(H,lt)|0,e=e+Math.imul($,ct)|0,f=f+Math.imul($,lt)|0,h=h+Math.imul(P,dt)|0,e=e+Math.imul(P,pt)|0,e=e+Math.imul(j,dt)|0,f=f+Math.imul(j,pt)|0;var ie=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,h=Math.imul(z,at),e=Math.imul(z,ht),e=e+Math.imul(K,at)|0,f=Math.imul(K,ht),h=h+Math.imul(J,ft)|0,e=e+Math.imul(J,ut)|0,e=e+Math.imul(W,ft)|0,f=f+Math.imul(W,ut)|0,h=h+Math.imul(Z,ct)|0,e=e+Math.imul(Z,lt)|0,e=e+Math.imul(D,ct)|0,f=f+Math.imul(D,lt)|0,h=h+Math.imul(H,dt)|0,e=e+Math.imul(H,pt)|0,e=e+Math.imul($,dt)|0,f=f+Math.imul($,pt)|0;var ne=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,h=Math.imul(z,ft),e=Math.imul(z,ut),e=e+Math.imul(K,ft)|0,f=Math.imul(K,ut),h=h+Math.imul(J,ct)|0,e=e+Math.imul(J,lt)|0,e=e+Math.imul(W,ct)|0,f=f+Math.imul(W,lt)|0,h=h+Math.imul(Z,dt)|0,e=e+Math.imul(Z,pt)|0,e=e+Math.imul(D,dt)|0,f=f+Math.imul(D,pt)|0;var se=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(se>>>26)|0,se&=67108863,h=Math.imul(z,ct),e=Math.imul(z,lt),e=e+Math.imul(K,ct)|0,f=Math.imul(K,lt),h=h+Math.imul(J,dt)|0,e=e+Math.imul(J,pt)|0,e=e+Math.imul(W,dt)|0,f=f+Math.imul(W,pt)|0;var oe=(m+h|0)+((e&8191)<<13)|0;m=(f+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,h=Math.imul(z,dt),e=Math.imul(z,pt),e=e+Math.imul(K,dt)|0,f=Math.imul(K,pt);var ae=(m+h|0)+((e&8191)<<13)|0;return m=(f+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,d[0]=Zt,d[1]=Dt,d[2]=Jt,d[3]=Wt,d[4]=zt,d[5]=Kt,d[6]=Qt,d[7]=Gt,d[8]=Vt,d[9]=Yt,d[10]=Xt,d[11]=te,d[12]=ee,d[13]=re,d[14]=ie,d[15]=ne,d[16]=se,d[17]=oe,d[18]=ae,m!==0&&(d[19]=m,n.length++),n};Math.imul||(Ot=yt);function Lt(l,t,r){r.negative=t.negative^l.negative,r.length=l.length+t.length;for(var n=0,o=0,u=0;u<r.length-1;u++){var d=o;o=0;for(var m=n&67108863,h=Math.min(u,t.length-1),e=Math.max(0,u-l.length+1);e<=h;e++){var f=u-e,_=l.words[f]|0,b=t.words[e]|0,S=_*b,x=S&67108863;d=d+(S/67108864|0)|0,x=x+m|0,m=x&67108863,d=d+(x>>>26)|0,o+=d>>>26,d&=67108863}r.words[u]=m,n=d,d=o}return n!==0?r.words[u]=n:r.length--,r.strip()}function g(l,t,r){var n=new y;return n.mulp(l,t,r)}c.prototype.mulTo=function(t,r){var n,o=this.length+t.length;return this.length===10&&t.length===10?n=Ot(this,t,r):o<63?n=yt(this,t,r):o<1024?n=Lt(this,t,r):n=g(this,t,r),n};function y(l,t){this.x=l,this.y=t}y.prototype.makeRBT=function(t){for(var r=new Array(t),n=c.prototype._countBits(t)-1,o=0;o<t;o++)r[o]=this.revBin(o,n,t);return r},y.prototype.revBin=function(t,r,n){if(t===0||t===n-1)return t;for(var o=0,u=0;u<r;u++)o|=(t&1)<<r-u-1,t>>=1;return o},y.prototype.permute=function(t,r,n,o,u,d){for(var m=0;m<d;m++)o[m]=r[t[m]],u[m]=n[t[m]]},y.prototype.transform=function(t,r,n,o,u,d){this.permute(d,t,r,n,o,u);for(var m=1;m<u;m<<=1)for(var h=m<<1,e=Math.cos(2*Math.PI/h),f=Math.sin(2*Math.PI/h),_=0;_<u;_+=h)for(var b=e,S=f,x=0;x<m;x++){var E=n[_+x],O=o[_+x],St=n[_+x+m],q=o[_+x+m],A=b*St-S*q;q=b*q+S*St,St=A,n[_+x]=E+St,o[_+x]=O+q,n[_+x+m]=E-St,o[_+x+m]=O-q,x!==h&&(A=e*b-f*S,S=e*S+f*b,b=A)}},y.prototype.guessLen13b=function(t,r){var n=Math.max(r,t)|1,o=n&1,u=0;for(n=n/2|0;n;n=n>>>1)u++;return 1<<u+1+o},y.prototype.conjugate=function(t,r,n){if(!(n<=1))for(var o=0;o<n/2;o++){var u=t[o];t[o]=t[n-o-1],t[n-o-1]=u,u=r[o],r[o]=-r[n-o-1],r[n-o-1]=-u}},y.prototype.normalize13b=function(t,r){for(var n=0,o=0;o<r/2;o++){var u=Math.round(t[2*o+1]/r)*8192+Math.round(t[2*o]/r)+n;t[o]=u&67108863,u<67108864?n=0:n=u/67108864|0}return t},y.prototype.convert13b=function(t,r,n,o){for(var u=0,d=0;d<r;d++)u=u+(t[d]|0),n[2*d]=u&8191,u=u>>>13,n[2*d+1]=u&8191,u=u>>>13;for(d=2*r;d<o;++d)n[d]=0;p(u===0),p((u&-8192)===0)},y.prototype.stub=function(t){for(var r=new Array(t),n=0;n<t;n++)r[n]=0;return r},y.prototype.mulp=function(t,r,n){var o=2*this.guessLen13b(t.length,r.length),u=this.makeRBT(o),d=this.stub(o),m=new Array(o),h=new Array(o),e=new Array(o),f=new Array(o),_=new Array(o),b=new Array(o),S=n.words;S.length=o,this.convert13b(t.words,t.length,m,o),this.convert13b(r.words,r.length,f,o),this.transform(m,d,h,e,o,u),this.transform(f,d,_,b,o,u);for(var x=0;x<o;x++){var E=h[x]*_[x]-e[x]*b[x];e[x]=h[x]*b[x]+e[x]*_[x],h[x]=E}return this.conjugate(h,e,o),this.transform(h,e,S,d,o,u),this.conjugate(S,d,o),this.normalize13b(S,o),n.negative=t.negative^r.negative,n.length=t.length+r.length,n.strip()},c.prototype.mul=function(t){var r=new c(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},c.prototype.mulf=function(t){var r=new c(null);return r.words=new Array(this.length+t.length),g(this,t,r)},c.prototype.imul=function(t){return this.clone().mulTo(t,this)},c.prototype.imuln=function(t){p(typeof t=="number"),p(t<67108864);for(var r=0,n=0;n<this.length;n++){var o=(this.words[n]|0)*t,u=(o&67108863)+(r&67108863);r>>=26,r+=o/67108864|0,r+=u>>>26,this.words[n]=u&67108863}return r!==0&&(this.words[n]=r,this.length++),this},c.prototype.muln=function(t){return this.clone().imuln(t)},c.prototype.sqr=function(){return this.mul(this)},c.prototype.isqr=function(){return this.imul(this.clone())},c.prototype.pow=function(t){var r=_t(t);if(r.length===0)return new c(1);for(var n=this,o=0;o<r.length&&r[o]===0;o++,n=n.sqr());if(++o<r.length)for(var u=n.sqr();o<r.length;o++,u=u.sqr())r[o]!==0&&(n=n.mul(u));return n},c.prototype.iushln=function(t){p(typeof t=="number"&&t>=0);var r=t%26,n=(t-r)/26,o=67108863>>>26-r<<26-r,u;if(r!==0){var d=0;for(u=0;u<this.length;u++){var m=this.words[u]&o,h=(this.words[u]|0)-m<<r;this.words[u]=h|d,d=m>>>26-r}d&&(this.words[u]=d,this.length++)}if(n!==0){for(u=this.length-1;u>=0;u--)this.words[u+n]=this.words[u];for(u=0;u<n;u++)this.words[u]=0;this.length+=n}return this.strip()},c.prototype.ishln=function(t){return p(this.negative===0),this.iushln(t)},c.prototype.iushrn=function(t,r,n){p(typeof t=="number"&&t>=0);var o;r?o=(r-r%26)/26:o=0;var u=t%26,d=Math.min((t-u)/26,this.length),m=67108863^67108863>>>u<<u,h=n;if(o-=d,o=Math.max(0,o),h){for(var e=0;e<d;e++)h.words[e]=this.words[e];h.length=d}if(d!==0)if(this.length>d)for(this.length-=d,e=0;e<this.length;e++)this.words[e]=this.words[e+d];else this.words[0]=0,this.length=1;var f=0;for(e=this.length-1;e>=0&&(f!==0||e>=o);e--){var _=this.words[e]|0;this.words[e]=f<<26-u|_>>>u,f=_&m}return h&&f!==0&&(h.words[h.length++]=f),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},c.prototype.ishrn=function(t,r,n){return p(this.negative===0),this.iushrn(t,r,n)},c.prototype.shln=function(t){return this.clone().ishln(t)},c.prototype.ushln=function(t){return this.clone().iushln(t)},c.prototype.shrn=function(t){return this.clone().ishrn(t)},c.prototype.ushrn=function(t){return this.clone().iushrn(t)},c.prototype.testn=function(t){p(typeof t=="number"&&t>=0);var r=t%26,n=(t-r)/26,o=1<<r;if(this.length<=n)return!1;var u=this.words[n];return!!(u&o)},c.prototype.imaskn=function(t){p(typeof t=="number"&&t>=0);var r=t%26,n=(t-r)/26;if(p(this.negative===0,"imaskn works only with positive numbers"),this.length<=n)return this;if(r!==0&&n++,this.length=Math.min(n,this.length),r!==0){var o=67108863^67108863>>>r<<r;this.words[this.length-1]&=o}return this.strip()},c.prototype.maskn=function(t){return this.clone().imaskn(t)},c.prototype.iaddn=function(t){return p(typeof t=="number"),p(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},c.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},c.prototype.isubn=function(t){if(p(typeof t=="number"),p(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},c.prototype.addn=function(t){return this.clone().iaddn(t)},c.prototype.subn=function(t){return this.clone().isubn(t)},c.prototype.iabs=function(){return this.negative=0,this},c.prototype.abs=function(){return this.clone().iabs()},c.prototype._ishlnsubmul=function(t,r,n){var o=t.length+n,u;this._expand(o);var d,m=0;for(u=0;u<t.length;u++){d=(this.words[u+n]|0)+m;var h=(t.words[u]|0)*r;d-=h&67108863,m=(d>>26)-(h/67108864|0),this.words[u+n]=d&67108863}for(;u<this.length-n;u++)d=(this.words[u+n]|0)+m,m=d>>26,this.words[u+n]=d&67108863;if(m===0)return this.strip();for(p(m===-1),m=0,u=0;u<this.length;u++)d=-(this.words[u]|0)+m,m=d>>26,this.words[u]=d&67108863;return this.negative=1,this.strip()},c.prototype._wordDiv=function(t,r){var n=this.length-t.length,o=this.clone(),u=t,d=u.words[u.length-1]|0,m=this._countBits(d);n=26-m,n!==0&&(u=u.ushln(n),o.iushln(n),d=u.words[u.length-1]|0);var h=o.length-u.length,e;if(r!=="mod"){e=new c(null),e.length=h+1,e.words=new Array(e.length);for(var f=0;f<e.length;f++)e.words[f]=0}var _=o.clone()._ishlnsubmul(u,1,h);_.negative===0&&(o=_,e&&(e.words[h]=1));for(var b=h-1;b>=0;b--){var S=(o.words[u.length+b]|0)*67108864+(o.words[u.length+b-1]|0);for(S=Math.min(S/d|0,67108863),o._ishlnsubmul(u,S,b);o.negative!==0;)S--,o.negative=0,o._ishlnsubmul(u,1,b),o.isZero()||(o.negative^=1);e&&(e.words[b]=S)}return e&&e.strip(),o.strip(),r!=="div"&&n!==0&&o.iushrn(n),{div:e||null,mod:o}},c.prototype.divmod=function(t,r,n){if(p(!t.isZero()),this.isZero())return{div:new c(0),mod:new c(0)};var o,u,d;return this.negative!==0&&t.negative===0?(d=this.neg().divmod(t,r),r!=="mod"&&(o=d.div.neg()),r!=="div"&&(u=d.mod.neg(),n&&u.negative!==0&&u.iadd(t)),{div:o,mod:u}):this.negative===0&&t.negative!==0?(d=this.divmod(t.neg(),r),r!=="mod"&&(o=d.div.neg()),{div:o,mod:d.mod}):this.negative&t.negative?(d=this.neg().divmod(t.neg(),r),r!=="div"&&(u=d.mod.neg(),n&&u.negative!==0&&u.isub(t)),{div:d.div,mod:u}):t.length>this.length||this.cmp(t)<0?{div:new c(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new c(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new c(this.modn(t.words[0]))}:this._wordDiv(t,r)},c.prototype.div=function(t){return this.divmod(t,"div",!1).div},c.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},c.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},c.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var n=r.div.negative!==0?r.mod.isub(t):r.mod,o=t.ushrn(1),u=t.andln(1),d=n.cmp(o);return d<0||u===1&&d===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},c.prototype.modn=function(t){p(t<=67108863);for(var r=(1<<26)%t,n=0,o=this.length-1;o>=0;o--)n=(r*n+(this.words[o]|0))%t;return n},c.prototype.idivn=function(t){p(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var o=(this.words[n]|0)+r*67108864;this.words[n]=o/t|0,r=o%t}return this.strip()},c.prototype.divn=function(t){return this.clone().idivn(t)},c.prototype.egcd=function(t){p(t.negative===0),p(!t.isZero());var r=this,n=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new c(1),u=new c(0),d=new c(0),m=new c(1),h=0;r.isEven()&&n.isEven();)r.iushrn(1),n.iushrn(1),++h;for(var e=n.clone(),f=r.clone();!r.isZero();){for(var _=0,b=1;!(r.words[0]&b)&&_<26;++_,b<<=1);if(_>0)for(r.iushrn(_);_-- >0;)(o.isOdd()||u.isOdd())&&(o.iadd(e),u.isub(f)),o.iushrn(1),u.iushrn(1);for(var S=0,x=1;!(n.words[0]&x)&&S<26;++S,x<<=1);if(S>0)for(n.iushrn(S);S-- >0;)(d.isOdd()||m.isOdd())&&(d.iadd(e),m.isub(f)),d.iushrn(1),m.iushrn(1);r.cmp(n)>=0?(r.isub(n),o.isub(d),u.isub(m)):(n.isub(r),d.isub(o),m.isub(u))}return{a:d,b:m,gcd:n.iushln(h)}},c.prototype._invmp=function(t){p(t.negative===0),p(!t.isZero());var r=this,n=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new c(1),u=new c(0),d=n.clone();r.cmpn(1)>0&&n.cmpn(1)>0;){for(var m=0,h=1;!(r.words[0]&h)&&m<26;++m,h<<=1);if(m>0)for(r.iushrn(m);m-- >0;)o.isOdd()&&o.iadd(d),o.iushrn(1);for(var e=0,f=1;!(n.words[0]&f)&&e<26;++e,f<<=1);if(e>0)for(n.iushrn(e);e-- >0;)u.isOdd()&&u.iadd(d),u.iushrn(1);r.cmp(n)>=0?(r.isub(n),o.isub(u)):(n.isub(r),u.isub(o))}var _;return r.cmpn(1)===0?_=o:_=u,_.cmpn(0)<0&&_.iadd(t),_},c.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),n=t.clone();r.negative=0,n.negative=0;for(var o=0;r.isEven()&&n.isEven();o++)r.iushrn(1),n.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;n.isEven();)n.iushrn(1);var u=r.cmp(n);if(u<0){var d=r;r=n,n=d}else if(u===0||n.cmpn(1)===0)break;r.isub(n)}while(!0);return n.iushln(o)},c.prototype.invm=function(t){return this.egcd(t).a.umod(t)},c.prototype.isEven=function(){return(this.words[0]&1)===0},c.prototype.isOdd=function(){return(this.words[0]&1)===1},c.prototype.andln=function(t){return this.words[0]&t},c.prototype.bincn=function(t){p(typeof t=="number");var r=t%26,n=(t-r)/26,o=1<<r;if(this.length<=n)return this._expand(n+1),this.words[n]|=o,this;for(var u=o,d=n;u!==0&&d<this.length;d++){var m=this.words[d]|0;m+=u,u=m>>>26,m&=67108863,this.words[d]=m}return u!==0&&(this.words[d]=u,this.length++),this},c.prototype.isZero=function(){return this.length===1&&this.words[0]===0},c.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this.strip();var n;if(this.length>1)n=1;else{r&&(t=-t),p(t<=67108863,"Number is too big");var o=this.words[0]|0;n=o===t?0:o<t?-1:1}return this.negative!==0?-n|0:n},c.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},c.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,n=this.length-1;n>=0;n--){var o=this.words[n]|0,u=t.words[n]|0;if(o!==u){o<u?r=-1:o>u&&(r=1);break}}return r},c.prototype.gtn=function(t){return this.cmpn(t)===1},c.prototype.gt=function(t){return this.cmp(t)===1},c.prototype.gten=function(t){return this.cmpn(t)>=0},c.prototype.gte=function(t){return this.cmp(t)>=0},c.prototype.ltn=function(t){return this.cmpn(t)===-1},c.prototype.lt=function(t){return this.cmp(t)===-1},c.prototype.lten=function(t){return this.cmpn(t)<=0},c.prototype.lte=function(t){return this.cmp(t)<=0},c.prototype.eqn=function(t){return this.cmpn(t)===0},c.prototype.eq=function(t){return this.cmp(t)===0},c.red=function(t){return new N(t)},c.prototype.toRed=function(t){return p(!this.red,"Already a number in reduction context"),p(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},c.prototype.fromRed=function(){return p(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},c.prototype._forceRed=function(t){return this.red=t,this},c.prototype.forceRed=function(t){return p(!this.red,"Already a number in reduction context"),this._forceRed(t)},c.prototype.redAdd=function(t){return p(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},c.prototype.redIAdd=function(t){return p(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},c.prototype.redSub=function(t){return p(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},c.prototype.redISub=function(t){return p(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},c.prototype.redShl=function(t){return p(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},c.prototype.redMul=function(t){return p(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},c.prototype.redIMul=function(t){return p(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},c.prototype.redSqr=function(){return p(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},c.prototype.redISqr=function(){return p(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},c.prototype.redSqrt=function(){return p(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},c.prototype.redInvm=function(){return p(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},c.prototype.redNeg=function(){return p(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},c.prototype.redPow=function(t){return p(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function M(l,t){this.name=l,this.p=new c(t,16),this.n=this.p.bitLength(),this.k=new c(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}M.prototype._tmp=function(){var t=new c(null);return t.words=new Array(Math.ceil(this.n/13)),t},M.prototype.ireduce=function(t){var r=t,n;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),n=r.bitLength();while(n>this.n);var o=n<this.n?-1:r.ucmp(this.p);return o===0?(r.words[0]=0,r.length=1):o>0?r.isub(this.p):r.strip(),r},M.prototype.split=function(t,r){t.iushrn(this.n,0,r)},M.prototype.imulK=function(t){return t.imul(this.k)};function R(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}v(R,M),R.prototype.split=function(t,r){for(var n=4194303,o=Math.min(t.length,9),u=0;u<o;u++)r.words[u]=t.words[u];if(r.length=o,t.length<=9){t.words[0]=0,t.length=1;return}var d=t.words[9];for(r.words[r.length++]=d&n,u=10;u<t.length;u++){var m=t.words[u]|0;t.words[u-10]=(m&n)<<4|d>>>22,d=m}d>>>=22,t.words[u-10]=d,d===0&&t.length>10?t.length-=10:t.length-=9},R.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,n=0;n<t.length;n++){var o=t.words[n]|0;r+=o*977,t.words[n]=r&67108863,r=o*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function C(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}v(C,M);function I(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}v(I,M);function gt(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}v(gt,M),gt.prototype.imulK=function(t){for(var r=0,n=0;n<t.length;n++){var o=(t.words[n]|0)*19+r,u=o&67108863;o>>>=26,t.words[n]=u,r=o}return r!==0&&(t.words[t.length++]=r),t},c._prime=function(t){if(w[t])return w[t];var r;if(t==="k256")r=new R;else if(t==="p224")r=new C;else if(t==="p192")r=new I;else if(t==="p25519")r=new gt;else throw new Error("Unknown prime "+t);return w[t]=r,r};function N(l){if(typeof l=="string"){var t=c._prime(l);this.m=t.p,this.prime=t}else p(l.gtn(1),"modulus must be greater than 1"),this.m=l,this.prime=null}N.prototype._verify1=function(t){p(t.negative===0,"red works only with positives"),p(t.red,"red works only with red numbers")},N.prototype._verify2=function(t,r){p((t.negative|r.negative)===0,"red works only with positives"),p(t.red&&t.red===r.red,"red works only with red numbers")},N.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},N.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},N.prototype.add=function(t,r){this._verify2(t,r);var n=t.add(r);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},N.prototype.iadd=function(t,r){this._verify2(t,r);var n=t.iadd(r);return n.cmp(this.m)>=0&&n.isub(this.m),n},N.prototype.sub=function(t,r){this._verify2(t,r);var n=t.sub(r);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},N.prototype.isub=function(t,r){this._verify2(t,r);var n=t.isub(r);return n.cmpn(0)<0&&n.iadd(this.m),n},N.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},N.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},N.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},N.prototype.isqr=function(t){return this.imul(t,t.clone())},N.prototype.sqr=function(t){return this.mul(t,t)},N.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(p(r%2===1),r===3){var n=this.m.add(new c(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),u=0;!o.isZero()&&o.andln(1)===0;)u++,o.iushrn(1);p(!o.isZero());var d=new c(1).toRed(this),m=d.redNeg(),h=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new c(2*e*e).toRed(this);this.pow(e,h).cmp(m)!==0;)e.redIAdd(m);for(var f=this.pow(e,o),_=this.pow(t,o.addn(1).iushrn(1)),b=this.pow(t,o),S=u;b.cmp(d)!==0;){for(var x=b,E=0;x.cmp(d)!==0;E++)x=x.redSqr();p(E<S);var O=this.pow(f,new c(1).iushln(S-E-1));_=_.redMul(O),f=O.redSqr(),b=b.redMul(f),S=E}return _},N.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},N.prototype.pow=function(t,r){if(r.isZero())return new c(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var n=4,o=new Array(1<<n);o[0]=new c(1).toRed(this),o[1]=t;for(var u=2;u<o.length;u++)o[u]=this.mul(o[u-1],t);var d=o[0],m=0,h=0,e=r.bitLength()%26;for(e===0&&(e=26),u=r.length-1;u>=0;u--){for(var f=r.words[u],_=e-1;_>=0;_--){var b=f>>_&1;if(d!==o[0]&&(d=this.sqr(d)),b===0&&m===0){h=0;continue}m<<=1,m|=b,h++,!(h!==n&&(u!==0||_!==0))&&(d=this.mul(d,o[m]),h=0,m=0)}e=26}return d},N.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},N.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},c.mont=function(t){return new kt(t)};function kt(l){N.call(this,l),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new c(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v(kt,N),kt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},kt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},kt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var n=t.imul(r),o=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),u=n.isub(o).iushrn(this.shift),d=u;return u.cmp(this.m)>=0?d=u.isub(this.m):u.cmpn(0)<0&&(d=u.iadd(this.m)),d._forceRed(this)},kt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new c(0)._forceRed(this);var n=t.mul(r),o=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),u=n.isub(o).iushrn(this.shift),d=u;return u.cmp(this.m)>=0?d=u.isub(this.m):u.cmpn(0)<0&&(d=u.iadd(this.m)),d._forceRed(this)},kt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(s,Tt)})(Sr);const xr=le;var Rr=ve;ve.strict=Ve;ve.loose=Ye;var Ir=Object.prototype.toString,kr={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0};function ve(s){return Ve(s)||Ye(s)}function Ve(s){return s instanceof Int8Array||s instanceof Int16Array||s instanceof Int32Array||s instanceof Uint8Array||s instanceof Uint8ClampedArray||s instanceof Uint16Array||s instanceof Uint32Array||s instanceof Float32Array||s instanceof Float64Array}function Ye(s){return kr[Ir.call(s)]}var Er=Rr.strict,Tr=function(i){if(Er(i)){var a=Ft.Buffer.from(i.buffer);return i.byteLength!==i.buffer.byteLength&&(a=a.slice(i.byteOffset,i.byteOffset+i.byteLength)),a}else return Ft.Buffer.from(i)};const Xe="hex",tr="utf8",Ht="0";function Ct(s){return new Uint8Array(s)}function er(s,i=!1){const a=s.toString(Xe);return i?Nt(a):a}function Or(s){return s.toString(tr)}function $t(s){return Tr(s)}function qt(s,i=!1){return er($t(s),i)}function qr(s){return Or($t(s))}function Ar(s){return Ft.Buffer.from(xt(s),Xe)}function At(s){return Ct(Ar(s))}function ge(s){return Ft.Buffer.from(s,tr)}function Cr(s){return Ct(ge(s))}function Nr(s,i=!1){return er(ge(s),i)}function Br(s,i){return!(typeof s!="string"||!s.match(/^0x[0-9A-Fa-f]*$/)||i&&s.length!==2+2*i)}function rr(...s){let i=[];return s.forEach(a=>i=i.concat(Array.from(a))),new Uint8Array([...i])}function Ur(s,i=8){const a=s%i;return a?(s-a)/i*i+i:s}function Fr(s,i=8,a=Ht){return Lr(s,Ur(s.length,i),a)}function Lr(s,i,a=Ht){return jr(s,i,!0,a)}function xt(s){return s.replace(/^0x/,"")}function Nt(s){return s.startsWith("0x")?s:`0x${s}`}function ir(s){return s=xt(s),s=Fr(s,2),s&&(s=Nt(s)),s}function Pr(s){const i=s.startsWith("0x");return s=xt(s),s=s.startsWith(Ht)?s.substring(1):s,i?Nt(s):s}function jr(s,i,a,p=Ht){const v=i-s.length;let c=s;if(v>0){const T=p.repeat(v);c=a?T+s:s+T}return c}function de(s){return $t(new Uint8Array(s))}function Hr(s,i){return qt(new Uint8Array(s),!i)}function $r(s){return Ct(s).buffer}function Zr(s){return ge(s)}function Dr(s,i){return Nr(s,!i)}function Jr(s){return At(s).buffer}function nr(s,i){const a=xt(ir(new xr(s).toString(16)));return i?a:Nt(a)}var Bt={};const Wr=Mr(wr);var wt={},je;function zr(){if(je)return wt;je=1,Object.defineProperty(wt,"__esModule",{value:!0}),wt.isBrowserCryptoAvailable=wt.getSubtleCrypto=wt.getBrowerCrypto=void 0;function s(){return(Tt===null||Tt===void 0?void 0:Tt.crypto)||(Tt===null||Tt===void 0?void 0:Tt.msCrypto)||{}}wt.getBrowerCrypto=s;function i(){const p=s();return p.subtle||p.webkitSubtle}wt.getSubtleCrypto=i;function a(){return!!s()&&!!i()}return wt.isBrowserCryptoAvailable=a,wt}var bt={},He;function Kr(){if(He)return bt;He=1,Object.defineProperty(bt,"__esModule",{value:!0}),bt.isBrowser=bt.isNode=bt.isReactNative=void 0;function s(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}bt.isReactNative=s;function i(){return typeof he<"u"&&typeof he.versions<"u"&&typeof he.versions.node<"u"}bt.isNode=i;function a(){return!s()&&!i()}return bt.isBrowser=a,bt}(function(s){Object.defineProperty(s,"__esModule",{value:!0});const i=Wr;i.__exportStar(zr(),s),i.__exportStar(Kr(),s)})(Bt);function Qr(){const s=Date.now()*Math.pow(10,3),i=Math.floor(Math.random()*Math.pow(10,3));return s+i}function Pt(s){return ir(s)}function Gr(s){return Pr(Nt(s))}const Vr=Qr;function fe(){return((i,a)=>{for(a=i="";i++<36;a+=i*51&52?(i^15?8^Math.random()*(i^20?16:4):4).toString(16):"-");return a})()}function Yr(s){return s===""||typeof s=="string"&&s.trim()===""}function Xr(s){return!(s&&s.length)}function sr(s,i){return Br(s,i)}function ti(s){return typeof s.method<"u"}function Ut(s){return typeof s.result<"u"}function jt(s){return typeof s.error<"u"}function $e(s){return typeof s.event<"u"}function ei(s){return br.includes(s)||s.startsWith("wc_")}function ri(s){return s.method.startsWith("wc_")?!0:!Ge.includes(s.method)}function ii(s){s=xt(s.toLowerCase());const i=xt(_r.keccak_256(Zr(s)));let a="";for(let p=0;p<s.length;p++)parseInt(i[p],16)>7?a+=s[p].toUpperCase():a+=s[p];return Nt(a)}const ni=s=>s?s.toLowerCase().substring(0,2)!=="0x"?!1:/^(0x)?[0-9a-f]{40}$/i.test(s)?/^(0x)?[0-9a-f]{40}$/.test(s)||/^(0x)?[0-9A-F]{40}$/.test(s)?!0:s===ii(s):!1:!1;function Ze(s){return!Xr(s)&&!sr(s[0])&&(s[0]=Dr(s[0])),s}function ue(s){if(typeof s.type<"u"&&s.type!=="0")return s;if(typeof s.from>"u"||!ni(s.from))throw new Error("Transaction object must include a valid 'from' value.");function i(v){let c=v;return(typeof v=="number"||typeof v=="string"&&!Yr(v))&&(sr(v)?typeof v=="string"&&(c=Pt(v)):c=nr(v)),typeof c=="string"&&(c=Gr(c)),c}const a={from:Pt(s.from),to:typeof s.to>"u"?void 0:Pt(s.to),gasPrice:typeof s.gasPrice>"u"?"":i(s.gasPrice),gas:typeof s.gas>"u"?typeof s.gasLimit>"u"?"":i(s.gasLimit):i(s.gas),value:typeof s.value>"u"?"":i(s.value),nonce:typeof s.nonce>"u"?"":i(s.nonce),data:typeof s.data>"u"?"":Pt(s.data)||"0x"},p=["gasPrice","gas","value","nonce"];return Object.keys(a).forEach(v=>{(typeof a[v]>"u"||typeof a[v]=="string"&&!a[v].trim().length)&&p.includes(v)&&delete a[v]}),a}function si(s){const i=s.message||"Failed or Rejected Request";let a=-32e3;if(s&&!s.code)switch(i){case"Parse error":a=-32700;break;case"Invalid request":a=-32600;break;case"Method not found":a=-32601;break;case"Invalid params":a=-32602;break;case"Internal error":a=-32603;break;default:a=-32e3;break}const p={code:a,message:i};return s.data&&(p.data=s.data),p}var ye={},oi=s=>encodeURIComponent(s).replace(/[!'()*]/g,i=>`%${i.charCodeAt(0).toString(16).toUpperCase()}`),or="%[a-f0-9]{2}",De=new RegExp("("+or+")|([^%]+?)","gi"),Je=new RegExp("("+or+")+","gi");function pe(s,i){try{return[decodeURIComponent(s.join(""))]}catch{}if(s.length===1)return s;i=i||1;var a=s.slice(0,i),p=s.slice(i);return Array.prototype.concat.call([],pe(a),pe(p))}function ai(s){try{return decodeURIComponent(s)}catch{for(var i=s.match(De)||[],a=1;a<i.length;a++)s=pe(i,a).join(""),i=s.match(De)||[];return s}}function hi(s){for(var i={"%FE%FF":"<22><>","%FF%FE":"<22><>"},a=Je.exec(s);a;){try{i[a[0]]=decodeURIComponent(a[0])}catch{var p=ai(a[0]);p!==a[0]&&(i[a[0]]=p)}a=Je.exec(s)}i["%C2"]="<22>";for(var v=Object.keys(i),c=0;c<v.length;c++){var T=v[c];s=s.replace(new RegExp(T,"g"),i[T])}return s}var fi=function(s){if(typeof s!="string")throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof s+"`");try{return s=s.replace(/\+/g," "),decodeURIComponent(s)}catch{return hi(s)}},ui=(s,i)=>{if(!(typeof s=="string"&&typeof i=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(i==="")return[s];const a=s.indexOf(i);return a===-1?[s]:[s.slice(0,a),s.slice(a+i.length)]};(function(s){const i=oi,a=fi,p=ui,v=g=>g==null;function c(g){switch(g.arrayFormat){case"index":return y=>(w,M)=>{const R=w.length;return M===void 0||g.skipNull&&M===null||g.skipEmptyString&&M===""?w:M===null?[...w,[k(y,g),"[",R,"]"].join("")]:[...w,[k(y,g),"[",k(R,g),"]=",k(M,g)].join("")]};case"bracket":return y=>(w,M)=>M===void 0||g.skipNull&&M===null||g.skipEmptyString&&M===""?w:M===null?[...w,[k(y,g),"[]"].join("")]:[...w,[k(y,g),"[]=",k(M,g)].join("")];case"comma":case"separator":return y=>(w,M)=>M==null||M.length===0?w:w.length===0?[[k(y,g),"=",k(M,g)].join("")]:[[w,k(M,g)].join(g.arrayFormatSeparator)];default:return y=>(w,M)=>M===void 0||g.skipNull&&M===null||g.skipEmptyString&&M===""?w:M===null?[...w,k(y,g)]:[...w,[k(y,g),"=",k(M,g)].join("")]}}function T(g){let y;switch(g.arrayFormat){case"index":return(w,M,R)=>{if(y=/\[(\d*)\]$/.exec(w),w=w.replace(/\[\d*\]$/,""),!y){R[w]=M;return}R[w]===void 0&&(R[w]={}),R[w][y[1]]=M};case"bracket":return(w,M,R)=>{if(y=/(\[\])$/.exec(w),w=w.replace(/\[\]$/,""),!y){R[w]=M;return}if(R[w]===void 0){R[w]=[M];return}R[w]=[].concat(R[w],M)};case"comma":case"separator":return(w,M,R)=>{const I=typeof M=="string"&&M.split("").indexOf(g.arrayFormatSeparator)>-1?M.split(g.arrayFormatSeparator).map(gt=>vt(gt,g)):M===null?M:vt(M,g);R[w]=I};default:return(w,M,R)=>{if(R[w]===void 0){R[w]=M;return}R[w]=[].concat(R[w],M)}}}function mt(g){if(typeof g!="string"||g.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function k(g,y){return y.encode?y.strict?i(g):encodeURIComponent(g):g}function vt(g,y){return y.decode?a(g):g}function It(g){return Array.isArray(g)?g.sort():typeof g=="object"?It(Object.keys(g)).sort((y,w)=>Number(y)-Number(w)).map(y=>g[y]):g}function Mt(g){const y=g.indexOf("#");return y!==-1&&(g=g.slice(0,y)),g}function _t(g){let y="";const w=g.indexOf("#");return w!==-1&&(y=g.slice(w)),y}function yt(g){g=Mt(g);const y=g.indexOf("?");return y===-1?"":g.slice(y+1)}function Ot(g,y){return y.parseNumbers&&!Number.isNaN(Number(g))&&typeof g=="string"&&g.trim()!==""?g=Number(g):y.parseBooleans&&g!==null&&(g.toLowerCase()==="true"||g.toLowerCase()==="false")&&(g=g.toLowerCase()==="true"),g}function Lt(g,y){y=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},y),mt(y.arrayFormatSeparator);const w=T(y),M=Object.create(null);if(typeof g!="string"||(g=g.trim().replace(/^[?#&]/,""),!g))return M;for(const R of g.split("&")){let[C,I]=p(y.decode?R.replace(/\+/g," "):R,"=");I=I===void 0?null:["comma","separator"].includes(y.arrayFormat)?I:vt(I,y),w(vt(C,y),I,M)}for(const R of Object.keys(M)){const C=M[R];if(typeof C=="object"&&C!==null)for(const I of Object.keys(C))C[I]=Ot(C[I],y);else M[R]=Ot(C,y)}return y.sort===!1?M:(y.sort===!0?Object.keys(M).sort():Object.keys(M).sort(y.sort)).reduce((R,C)=>{const I=M[C];return Boolean(I)&&typeof I=="object"&&!Array.isArray(I)?R[C]=It(I):R[C]=I,R},Object.create(null))}s.extract=yt,s.parse=Lt,s.stringify=(g,y)=>{if(!g)return"";y=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},y),mt(y.arrayFormatSeparator);const w=I=>y.skipNull&&v(g[I])||y.skipEmptyString&&g[I]==="",M=c(y),R={};for(const I of Object.keys(g))w(I)||(R[I]=g[I]);const C=Object.keys(R);return y.sort!==!1&&C.sort(y.sort),C.map(I=>{const gt=g[I];return gt===void 0?"":gt===null?k(I,y):Array.isArray(gt)?gt.reduce(M(I),[]).join("&"):k(I,y)+"="+k(gt,y)}).filter(I=>I.length>0).join("&")},s.parseUrl=(g,y)=>{y=Object.assign({decode:!0},y);const[w,M]=p(g,"#");return Object.assign({url:w.split("?")[0]||"",query:Lt(yt(g),y)},y&&y.parseFragmentIdentifier&&M?{fragmentIdentifier:vt(M,y)}:{})},s.stringifyUrl=(g,y)=>{y=Object.assign({encode:!0,strict:!0},y);const w=Mt(g.url).split("?")[0]||"",M=s.extract(g.url),R=s.parse(M,{sort:!1}),C=Object.assign(R,g.query);let I=s.stringify(C,y);I&&(I=`?${I}`);let gt=_t(g.url);return g.fragmentIdentifier&&(gt=`#${k(g.fragmentIdentifier,y)}`),`${w}${I}${gt}`}})(ye);function ci(s){const i=s.indexOf("?")!==-1?s.indexOf("?"):void 0;return typeof i<"u"?s.substr(i):""}function li(s,i){let a=ar(s);return a=Object.assign(Object.assign({},a),i),s=di(a),s}function ar(s){return ye.parse(s)}function di(s){return ye.stringify(s)}function pi(s){return typeof s.bridge<"u"}function mi(s){const i=s.indexOf(":"),a=s.indexOf("?")!==-1?s.indexOf("?"):void 0,p=s.substring(0,i),v=s.substring(i+1,a);function c(Mt){const _t="@",yt=Mt.split(_t);return{handshakeTopic:yt[0],version:parseInt(yt[1],10)}}const T=c(v),mt=typeof a<"u"?s.substr(a):"";function k(Mt){const _t=ar(Mt);return{key:_t.key||"",bridge:_t.bridge||""}}const vt=k(mt);return Object.assign(Object.assign({protocol:p},T),vt)}class vi{constructor(){this._eventEmitters=[],typeof window<"u"&&typeof window.addEventListener<"u"&&(window.addEventListener("online",()=>this.trigger("online")),window.addEventListener("offline",()=>this.trigger("offline")))}on(i,a){this._eventEmitters.push({event:i,callback:a})}trigger(i){let a=[];i&&(a=this._eventEmitters.filter(p=>p.event===i)),a.forEach(p=>{p.callback()})}}const gi=typeof Pe.WebSocket<"u"?Pe.WebSocket:require("ws");class yi{constructor(i){if(this.opts=i,this._queue=[],this._events=[],this._subscriptions=[],this._protocol=i.protocol,this._version=i.version,this._url="",this._netMonitor=null,this._socket=null,this._nextSocket=null,this._subscriptions=i.subscriptions||[],this._netMonitor=i.netMonitor||new vi,!i.url||typeof i.url!="string")throw new Error("Missing or invalid WebSocket url");this._url=i.url,this._netMonitor.on("online",()=>this._socketCreate())}set readyState(i){}get readyState(){return this._socket?this._socket.readyState:-1}set connecting(i){}get connecting(){return this.readyState===0}set connected(i){}get connected(){return this.readyState===1}set closing(i){}get closing(){return this.readyState===2}set closed(i){}get closed(){return this.readyState===3}open(){this._socketCreate()}close(){this._socketClose()}send(i,a,p){if(!a||typeof a!="string")throw new Error("Missing or invalid topic field");this._socketSend({topic:a,type:"pub",payload:i,silent:!!p})}subscribe(i){this._socketSend({topic:i,type:"sub",payload:"",silent:!0})}on(i,a){this._events.push({event:i,callback:a})}_socketCreate(){if(this._nextSocket)return;const i=Mi(this._url,this._protocol,this._version);if(this._nextSocket=new gi(i),!this._nextSocket)throw new Error("Failed to create socket");this._nextSocket.onmessage=a=>this._socketReceive(a),this._nextSocket.onopen=()=>this._socketOpen(),this._nextSocket.onerror=a=>this._socketError(a),this._nextSocket.onclose=()=>{setTimeout(()=>{this._nextSocket=null,this._socketCreate()},1e3)}}_socketOpen(){this._socketClose(),this._socket=this._nextSocket,this._nextSocket=null,this._queueSubscriptions(),this._pushQueue()}_socketClose(){this._socket&&(this._socket.onclose=()=>{},this._socket.close())}_socketSend(i){const a=JSON.stringify(i);this._socket&&this._socket.readyState===1?this._socket.send(a):(this._setToQueue(i),this._socketCreate())}async _socketReceive(i){let a;try{a=JSON.parse(i.data)}catch{return}if(this._socketSend({topic:a.topic,type:"ack",payload:"",silent:!0}),this._socket&&this._socket.readyState===1){const p=this._events.filter(v=>v.event==="message");p&&p.length&&p.forEach(v=>v.callback(a))}}_socketError(i){const a=this._events.filter(p=>p.event==="error");a&&a.length&&a.forEach(p=>p.callback(i))}_queueSubscriptions(){this._subscriptions.forEach(a=>this._queue.push({topic:a,type:"sub",payload:"",silent:!0})),this._subscriptions=this.opts.subscriptions||[]}_setToQueue(i){this._queue.push(i)}_pushQueue(){this._queue.forEach(a=>this._socketSend(a)),this._queue=[]}}function Mi(s,i,a){var p,v;const T=(s.startsWith("https")?s.replace("https","wss"):s.startsWith("http")?s.replace("http","ws"):s).split("?"),mt=pr()?{protocol:i,version:a,env:"browser",host:((p=mr())===null||p===void 0?void 0:p.host)||""}:{protocol:i,version:a,env:((v=vr())===null||v===void 0?void 0:v.name)||""},k=li(ci(T[1]||""),mt);return T[0]+"?"+k}const ce="Session currently connected",Et="Session currently disconnected",_i="Session Rejected",wi="Missing JSON RPC response",bi='JSON-RPC success response must include "result" field',Si='JSON-RPC error response must include "error" field',xi='JSON RPC request must have valid "method" value',Ri='JSON RPC request must have valid "id" value',Ii="Missing one of the required parameters: bridge / uri / session",We="JSON RPC response format is invalid",ki="URI format is invalid",Ei="QRCode Modal not provided",ze="User close QRCode Modal";class Ti{constructor(){this._eventEmitters=[]}subscribe(i){this._eventEmitters.push(i)}unsubscribe(i){this._eventEmitters=this._eventEmitters.filter(a=>a.event!==i)}trigger(i){let a=[],p;ti(i)?p=i.method:Ut(i)||jt(i)?p=`response:${i.id}`:$e(i)?p=i.event:p="",p&&(a=this._eventEmitters.filter(v=>v.event===p)),(!a||!a.length)&&!ei(p)&&!$e(p)&&(a=this._eventEmitters.filter(v=>v.event==="call_request")),a.forEach(v=>{if(jt(i)){const c=new Error(i.error.message);v.callback(c,null)}else v.callback(null,i)})}}class Oi{constructor(i="walletconnect"){this.storageId=i}getSession(){let i=null;const a=Ke(this.storageId);return a&&pi(a)&&(i=a),i}setSession(i){return gr(this.storageId,i),i}removeSession(){Qe(this.storageId)}}const qi="walletconnect.org",Ai="abcdefghijklmnopqrstuvwxyz0123456789",hr=Ai.split("").map(s=>`https://${s}.bridge.walletconnect.org`);function Ci(s){let i=s.indexOf("//")>-1?s.split("/")[2]:s.split("/")[0];return i=i.split(":")[0],i=i.split("?")[0],i}function Ni(s){return Ci(s).split(".").slice(-2).join(".")}function Bi(){return Math.floor(Math.random()*hr.length)}function Ui(){return hr[Bi()]}function Fi(s){return Ni(s)===qi}function Li(s){return Fi(s)?Ui():s}class Pi{constructor(i){if(this.protocol="wc",this.version=1,this._bridge="",this._key=null,this._clientId="",this._clientMeta=null,this._peerId="",this._peerMeta=null,this._handshakeId=0,this._handshakeTopic="",this._connected=!1,this._accounts=[],this._chainId=0,this._networkId=0,this._rpcUrl="",this._eventManager=new Ti,this._clientMeta=Fe()||i.connectorOpts.clientMeta||null,this._cryptoLib=i.cryptoLib,this._sessionStorage=i.sessionStorage||new Oi(i.connectorOpts.storageId),this._qrcodeModal=i.connectorOpts.qrcodeModal,this._qrcodeModalOptions=i.connectorOpts.qrcodeModalOptions,this._signingMethods=[...Ge,...i.connectorOpts.signingMethods||[]],!i.connectorOpts.bridge&&!i.connectorOpts.uri&&!i.connectorOpts.session)throw new Error(Ii);i.connectorOpts.bridge&&(this.bridge=Li(i.connectorOpts.bridge)),i.connectorOpts.uri&&(this.uri=i.connectorOpts.uri);const a=i.connectorOpts.session||this._getStorageSession();a&&(this.session=a),this.handshakeId&&this._subscribeToSessionResponse(this.handshakeId,"Session request rejected"),this._transport=i.transport||new yi({protocol:this.protocol,version:this.version,url:this.bridge,subscriptions:[this.clientId]}),this._subscribeToInternalEvents(),this._initTransport(),i.connectorOpts.uri&&this._subscribeToSessionRequest(),i.pushServerOpts&&this._registerPushServer(i.pushServerOpts)}set bridge(i){i&&(this._bridge=i)}get bridge(){return this._bridge}set key(i){if(!i)return;const a=Jr(i);this._key=a}get key(){return this._key?Hr(this._key,!0):""}set clientId(i){i&&(this._clientId=i)}get clientId(){let i=this._clientId;return i||(i=this._clientId=fe()),this._clientId}set peerId(i){i&&(this._peerId=i)}get peerId(){return this._peerId}set clientMeta(i){}get clientMeta(){let i=this._clientMeta;return i||(i=this._clientMeta=Fe()),i}set peerMeta(i){this._peerMeta=i}get peerMeta(){return this._peerMeta}set handshakeTopic(i){i&&(this._handshakeTopic=i)}get handshakeTopic(){return this._handshakeTopic}set handshakeId(i){i&&(this._handshakeId=i)}get handshakeId(){return this._handshakeId}get uri(){return this._formatUri()}set uri(i){if(!i)return;const{handshakeTopic:a,bridge:p,key:v}=this._parseUri(i);this.handshakeTopic=a,this.bridge=p,this.key=v}set chainId(i){this._chainId=i}get chainId(){return this._chainId}set networkId(i){this._networkId=i}get networkId(){return this._networkId}set accounts(i){this._accounts=i}get accounts(){return this._accounts}set rpcUrl(i){this._rpcUrl=i}get rpcUrl(){return this._rpcUrl}set connected(i){}get connected(){return this._connected}set pending(i){}get pending(){return!!this._handshakeTopic}get session(){return{connected:this.connected,accounts:this.accounts,chainId:this.chainId,bridge:this.bridge,key:this.key,clientId:this.clientId,clientMeta:this.clientMeta,peerId:this.peerId,peerMeta:this.peerMeta,handshakeId:this.handshakeId,handshakeTopic:this.handshakeTopic}}set session(i){i&&(this._connected=i.connected,this.accounts=i.accounts,this.chainId=i.chainId,this.bridge=i.bridge,this.key=i.key,this.clientId=i.clientId,this.clientMeta=i.clientMeta,this.peerId=i.peerId,this.peerMeta=i.peerMeta,this.handshakeId=i.handshakeId,this.handshakeTopic=i.handshakeTopic)}on(i,a){const p={event:i,callback:a};this._eventManager.subscribe(p)}off(i){this._eventManager.unsubscribe(i)}async createInstantRequest(i){this._key=await this._generateKey();const a=this._formatRequest({method:"wc_instantRequest",params:[{peerId:this.clientId,peerMeta:this.clientMeta,request:this._formatRequest(i)}]});this.handshakeId=a.id,this.handshakeTopic=fe(),this._eventManager.trigger({event:"display_uri",params:[this.uri]}),this.on("modal_closed",()=>{throw new Error(ze)});const p=()=>{this.killSession()};try{const v=await this._sendCallRequest(a);return v&&p(),v}catch(v){throw p(),v}}async connect(i){if(!this._qrcodeModal)throw new Error(Ei);return this.connected?{chainId:this.chainId,accounts:this.accounts}:(await this.createSession(i),new Promise(async(a,p)=>{this.on("modal_closed",()=>p(new Error(ze))),this.on("connect",(v,c)=>{if(v)return p(v);a(c.params[0])})}))}async createSession(i){if(this._connected)throw new Error(ce);if(this.pending)return;this._key=await this._generateKey();const a=this._formatRequest({method:"wc_sessionRequest",params:[{peerId:this.clientId,peerMeta:this.clientMeta,chainId:i&&i.chainId?i.chainId:null}]});this.handshakeId=a.id,this.handshakeTopic=fe(),this._sendSessionRequest(a,"Session update rejected",{topic:this.handshakeTopic}),this._eventManager.trigger({event:"display_uri",params:[this.uri]})}approveSession(i){if(this._connected)throw new Error(ce);this.chainId=i.chainId,this.accounts=i.accounts,this.networkId=i.networkId||0,this.rpcUrl=i.rpcUrl||"";const a={approved:!0,chainId:this.chainId,networkId:this.networkId,accounts:this.accounts,rpcUrl:this.rpcUrl,peerId:this.clientId,peerMeta:this.clientMeta},p={id:this.handshakeId,jsonrpc:"2.0",result:a};this._sendResponse(p),this._connected=!0,this._setStorageSession(),this._eventManager.trigger({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]})}rejectSession(i){if(this._connected)throw new Error(ce);const a=i&&i.message?i.message:_i,p=this._formatResponse({id:this.handshakeId,error:{message:a}});this._sendResponse(p),this._connected=!1,this._eventManager.trigger({event:"disconnect",params:[{message:a}]}),this._removeStorageSession()}updateSession(i){if(!this._connected)throw new Error(Et);this.chainId=i.chainId,this.accounts=i.accounts,this.networkId=i.networkId||0,this.rpcUrl=i.rpcUrl||"";const a={approved:!0,chainId:this.chainId,networkId:this.networkId,accounts:this.accounts,rpcUrl:this.rpcUrl},p=this._formatRequest({method:"wc_sessionUpdate",params:[a]});this._sendSessionRequest(p,"Session update rejected"),this._eventManager.trigger({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]}),this._manageStorageSession()}async killSession(i){const a=i?i.message:"Session Disconnected",p={approved:!1,chainId:null,networkId:null,accounts:null},v=this._formatRequest({method:"wc_sessionUpdate",params:[p]});await this._sendRequest(v),this._handleSessionDisconnect(a)}async sendTransaction(i){if(!this._connected)throw new Error(Et);const a=ue(i),p=this._formatRequest({method:"eth_sendTransaction",params:[a]});return await this._sendCallRequest(p)}async signTransaction(i){if(!this._connected)throw new Error(Et);const a=ue(i),p=this._formatRequest({method:"eth_signTransaction",params:[a]});return await this._sendCallRequest(p)}async signMessage(i){if(!this._connected)throw new Error(Et);const a=this._formatRequest({method:"eth_sign",params:i});return await this._sendCallRequest(a)}async signPersonalMessage(i){if(!this._connected)throw new Error(Et);i=Ze(i);const a=this._formatRequest({method:"personal_sign",params:i});return await this._sendCallRequest(a)}async signTypedData(i){if(!this._connected)throw new Error(Et);const a=this._formatRequest({method:"eth_signTypedData",params:i});return await this._sendCallRequest(a)}async updateChain(i){if(!this._connected)throw new Error("Session currently disconnected");const a=this._formatRequest({method:"wallet_updateChain",params:[i]});return await this._sendCallRequest(a)}unsafeSend(i,a){return this._sendRequest(i,a),this._eventManager.trigger({event:"call_request_sent",params:[{request:i,options:a}]}),new Promise((p,v)=>{this._subscribeToResponse(i.id,(c,T)=>{if(c){v(c);return}if(!T)throw new Error(wi);p(T)})})}async sendCustomRequest(i,a){if(!this._connected)throw new Error(Et);switch(i.method){case"eth_accounts":return this.accounts;case"eth_chainId":return nr(this.chainId);case"eth_sendTransaction":case"eth_signTransaction":i.params&&(i.params[0]=ue(i.params[0]));break;case"personal_sign":i.params&&(i.params=Ze(i.params));break}const p=this._formatRequest(i);return await this._sendCallRequest(p,a)}approveRequest(i){if(Ut(i)){const a=this._formatResponse(i);this._sendResponse(a)}else throw new Error(bi)}rejectRequest(i){if(jt(i)){const a=this._formatResponse(i);this._sendResponse(a)}else throw new Error(Si)}transportClose(){this._transport.close()}async _sendRequest(i,a){const p=this._formatRequest(i),v=await this._encrypt(p),c=typeof(a==null?void 0:a.topic)<"u"?a.topic:this.peerId,T=JSON.stringify(v),mt=typeof(a==null?void 0:a.forcePushNotification)<"u"?!a.forcePushNotification:ri(p);this._transport.send(T,c,mt)}async _sendResponse(i){const a=await this._encrypt(i),p=this.peerId,v=JSON.stringify(a),c=!0;this._transport.send(v,p,c)}async _sendSessionRequest(i,a,p){this._sendRequest(i,p),this._subscribeToSessionResponse(i.id,a)}_sendCallRequest(i,a){return this._sendRequest(i,a),this._eventManager.trigger({event:"call_request_sent",params:[{request:i,options:a}]}),this._subscribeToCallResponse(i.id)}_formatRequest(i){if(typeof i.method>"u")throw new Error(xi);return{id:typeof i.id>"u"?Vr():i.id,jsonrpc:"2.0",method:i.method,params:typeof i.params>"u"?[]:i.params}}_formatResponse(i){if(typeof i.id>"u")throw new Error(Ri);const a={id:i.id,jsonrpc:"2.0"};if(jt(i)){const p=si(i.error);return Object.assign(Object.assign(Object.assign({},a),i),{error:p})}else if(Ut(i))return Object.assign(Object.assign({},a),i);throw new Error(We)}_handleSessionDisconnect(i){const a=i||"Session Disconnected";this._connected||(this._qrcodeModal&&this._qrcodeModal.close(),Qe(Le)),this._connected&&(this._connected=!1),this._handshakeId&&(this._handshakeId=0),this._handshakeTopic&&(this._handshakeTopic=""),this._peerId&&(this._peerId=""),this._eventManager.trigger({event:"disconnect",params:[{message:a}]}),this._removeStorageSession(),this.transportClose()}_handleSessionResponse(i,a){a?a.approved?(this._connected?(a.chainId&&(this.chainId=a.chainId),a.accounts&&(this.accounts=a.accounts),this._eventManager.trigger({event:"session_update",params:[{chainId:this.chainId,accounts:this.accounts}]})):(this._connected=!0,a.chainId&&(this.chainId=a.chainId),a.accounts&&(this.accounts=a.accounts),a.peerId&&!this.peerId&&(this.peerId=a.peerId),a.peerMeta&&!this.peerMeta&&(this.peerMeta=a.peerMeta),this._eventManager.trigger({event:"connect",params:[{peerId:this.peerId,peerMeta:this.peerMeta,chainId:this.chainId,accounts:this.accounts}]})),this._manageStorageSession()):this._handleSessionDisconnect(i):this._handleSessionDisconnect(i)}async _handleIncomingMessages(i){if(![this.clientId,this.handshakeTopic].includes(i.topic))return;let p;try{p=JSON.parse(i.payload)}catch{return}const v=await this._decrypt(p);v&&this._eventManager.trigger(v)}_subscribeToSessionRequest(){this._transport.subscribe(this.handshakeTopic)}_subscribeToResponse(i,a){this.on(`response:${i}`,a)}_subscribeToSessionResponse(i,a){this._subscribeToResponse(i,(p,v)=>{if(p){this._handleSessionResponse(p.message);return}Ut(v)?this._handleSessionResponse(a,v.result):v.error&&v.error.message?this._handleSessionResponse(v.error.message):this._handleSessionResponse(a)})}_subscribeToCallResponse(i){return new Promise((a,p)=>{this._subscribeToResponse(i,(v,c)=>{if(v){p(v);return}Ut(c)?a(c.result):c.error&&c.error.message?p(c.error):p(new Error(We))})})}_subscribeToInternalEvents(){this.on("display_uri",()=>{this._qrcodeModal&&this._qrcodeModal.open(this.uri,()=>{this._eventManager.trigger({event:"modal_closed",params:[]})},this._qrcodeModalOptions)}),this.on("connect",()=>{this._qrcodeModal&&this._qrcodeModal.close()}),this.on("call_request_sent",(i,a)=>{const{request:p}=a.params[0];if(yr()&&this._signingMethods.includes(p.method)){const v=Ke(Le);v&&(window.location.href=v.href)}}),this.on("wc_sessionRequest",(i,a)=>{i&&this._eventManager.trigger({event:"error",params:[{code:"SESSION_REQUEST_ERROR",message:i.toString()}]}),this.handshakeId=a.id,this.peerId=a.params[0].peerId,this.peerMeta=a.params[0].peerMeta;const p=Object.assign(Object.assign({},a),{method:"session_request"});this._eventManager.trigger(p)}),this.on("wc_sessionUpdate",(i,a)=>{i&&this._handleSessionResponse(i.message),this._handleSessionResponse("Session disconnected",a.params[0])})}_initTransport(){this._transport.on("message",i=>this._handleIncomingMessages(i)),this._transport.on("open",()=>this._eventManager.trigger({event:"transport_open",params:[]})),this._transport.on("close",()=>this._eventManager.trigger({event:"transport_close",params:[]})),this._transport.on("error",()=>this._eventManager.trigger({event:"transport_error",params:["Websocket connection failed"]})),this._transport.open()}_formatUri(){const i=this.protocol,a=this.handshakeTopic,p=this.version,v=encodeURIComponent(this.bridge),c=this.key;return`${i}:${a}@${p}?bridge=${v}&key=${c}`}_parseUri(i){const a=mi(i);if(a.protocol===this.protocol){if(!a.handshakeTopic)throw Error("Invalid or missing handshakeTopic parameter value");const p=a.handshakeTopic;if(!a.bridge)throw Error("Invalid or missing bridge url parameter value");const v=decodeURIComponent(a.bridge);if(!a.key)throw Error("Invalid or missing key parameter value");const c=a.key;return{handshakeTopic:p,bridge:v,key:c}}else throw new Error(ki)}async _generateKey(){return this._cryptoLib?await this._cryptoLib.generateKey():null}async _encrypt(i){const a=this._key;return this._cryptoLib&&a?await this._cryptoLib.encrypt(i,a):null}async _decrypt(i){const a=this._key;return this._cryptoLib&&a?await this._cryptoLib.decrypt(i,a):null}_getStorageSession(){let i=null;return this._sessionStorage&&(i=this._sessionStorage.getSession()),i}_setStorageSession(){this._sessionStorage&&this._sessionStorage.setSession(this.session)}_removeStorageSession(){this._sessionStorage&&this._sessionStorage.removeSession()}_manageStorageSession(){this._connected?this._setStorageSession():this._removeStorageSession()}_registerPushServer(i){if(!i.url||typeof i.url!="string")throw Error("Invalid or missing pushServerOpts.url parameter value");if(!i.type||typeof i.type!="string")throw Error("Invalid or missing pushServerOpts.type parameter value");if(!i.token||typeof i.token!="string")throw Error("Invalid or missing pushServerOpts.token parameter value");const a={bridge:this.bridge,topic:this.clientId,type:i.type,token:i.token,peerName:"",language:i.language||""};this.on("connect",async(p,v)=>{if(p)throw p;if(i.peerMeta){const c=v.params[0].peerMeta.name;a.peerName=c}try{if(!(await(await fetch(`${i.url}/new`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(a)})).json()).success)throw Error("Failed to register in Push Server")}catch{throw Error("Failed to register in Push Server")}})}}function ji(s){return Bt.getBrowerCrypto().getRandomValues(new Uint8Array(s))}const fr=256,ur=fr,Hi=fr,Rt="AES-CBC",$i=`SHA-${ur}`,me="HMAC",Zi="encrypt",Di="decrypt",Ji="sign",Wi="verify";function zi(s){return s===Rt?{length:ur,name:Rt}:{hash:{name:$i},name:me}}function Ki(s){return s===Rt?[Zi,Di]:[Ji,Wi]}async function Me(s,i=Rt){return Bt.getSubtleCrypto().importKey("raw",s,zi(i),!0,Ki(i))}async function Qi(s,i,a){const p=Bt.getSubtleCrypto(),v=await Me(i,Rt),c=await p.encrypt({iv:s,name:Rt},v,a);return new Uint8Array(c)}async function Gi(s,i,a){const p=Bt.getSubtleCrypto(),v=await Me(i,Rt),c=await p.decrypt({iv:s,name:Rt},v,a);return new Uint8Array(c)}async function Vi(s,i){const a=Bt.getSubtleCrypto(),p=await Me(s,me),v=await a.sign({length:Hi,name:me},p,i);return new Uint8Array(v)}function Yi(s,i,a){return Qi(s,i,a)}function Xi(s,i,a){return Gi(s,i,a)}async function cr(s,i){return await Vi(s,i)}async function lr(s){const i=(s||256)/8,a=ji(i);return $r($t(a))}async function dr(s,i){const a=At(s.data),p=At(s.iv),v=At(s.hmac),c=qt(v,!1),T=rr(a,p),mt=await cr(i,T),k=qt(mt,!1);return xt(c)===xt(k)}async function tn(s,i,a){const p=Ct(de(i)),v=a||await lr(128),c=Ct(de(v)),T=qt(c,!1),mt=JSON.stringify(s),k=Cr(mt),vt=await Yi(c,p,k),It=qt(vt,!1),Mt=rr(vt,c),_t=await cr(p,Mt),yt=qt(_t,!1);return{data:It,hmac:yt,iv:T}}async function en(s,i){const a=Ct(de(i));if(!a)throw new Error("Missing key: required for decryption");if(!await dr(s,a))return null;const v=At(s.data),c=At(s.iv),T=await Xi(c,a,v),mt=qr(T);let k;try{k=JSON.parse(mt)}catch{return null}return k}const rn=Object.freeze(Object.defineProperty({__proto__:null,decrypt:en,encrypt:tn,generateKey:lr,verifyHmac:dr},Symbol.toStringTag,{value:"Module"}));class an extends Pi{constructor(i,a){super({cryptoLib:rn,connectorOpts:i,pushServerOpts:a})}}export{an as default};