import{n as he,aZ as jn,U as Re,a_ as mi,W as Z,V as vi,a$ as mt,b0 as nt,b1 as bi,m as Un,b2 as Wr,b3 as it,b4 as wi,b5 as Xr,b6 as _i}from"./index-f9496d0e.js";function Si(e,t){if(e==null)return{};var r={},n=Object.keys(e),i,o;for(o=0;o=0)&&(r[i]=e[i]);return r}function Ei(e,t){if(e==null)return{};var r=Si(e,t),n,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function me(e){return me=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},me(e)}function Oi(e,t){if(me(e)!=="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t||"default");if(me(n)!=="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function xn(e){var t=Oi(e,"string");return me(t)==="symbol"?t:String(t)}function P(e,t,r){return t=xn(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var dt={},Ci={get exports(){return dt},set exports(e){dt=e}};(function(e){(function(t,r){e.exports?e.exports=r():t.log=r()})(he,function(){var t=function(){},r="undefined",n=typeof window!==r&&typeof window.navigator!==r&&/Trident\/|MSIE /.test(window.navigator.userAgent),i=["trace","debug","info","warn","error"];function o(_,T){var A=_[T];if(typeof A.bind=="function")return A.bind(_);try{return Function.prototype.bind.call(A,_)}catch{return function(){return Function.prototype.apply.apply(A,[_,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(_){return _==="debug"&&(_="log"),typeof console===r?!1:_==="trace"&&n?a:console[_]!==void 0?o(console,_):console.log!==void 0?o(console,"log"):t}function d(_,T){for(var A=0;A=0&&L<=E.levels.SILENT){if(U=L,G!==!1&&q(L),d.call(E,L,_),typeof console===r&&L1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n={mode:"cors",headers:{}};r.useAPIKey&&(n.headers=Zr(Zr({},n.headers),Ti()));const i=jn(n,t,{method:"GET"}),o=await Pi(e,i);if(o.ok)return o.json();throw Mi(o),o};function We(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Qr(e,t){for(var r=0;r=0;--g){var w=this.tryEntries[g],M=w.completion;if(w.tryLoc==="root")return f("end");if(w.tryLoc<=this.prev){var I=o.call(w,"catchLoc"),x=o.call(w,"finallyLoc");if(I&&x){if(this.prev=0;--f){var g=this.tryEntries[f];if(g.tryLoc<=this.prev&&o.call(g,"finallyLoc")&&this.prev=0;--l){var f=this.tryEntries[l];if(f.finallyLoc===v)return this.complete(f.completion,f.afterLoc),H(f),O}},catch:function(v){for(var l=this.tryEntries.length-1;l>=0;--l){var f=this.tryEntries[l];if(f.tryLoc===v){var g=f.completion;if(g.type==="throw"){var w=g.arg;H(f)}return w}}throw new Error("illegal catch attempt")},delegateYield:function(v,l,f){return this.delegate={iterator:se(v),resultName:l,nextLoc:f},this.method==="next"&&(this.arg=void 0),O}},n}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports})(Ii);var ut=Dr(),ee=ut;try{regeneratorRuntime=ut}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=ut:Function("r","regeneratorRuntime = r")(ut)}function Li(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function Ni(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function lt(e,t,r){return Ni()?lt=Reflect.construct.bind():lt=function(i,o,a){var c=[null];c.push.apply(c,o);var d=Function.bind.apply(i,c),m=new d;return a&&Ze(m,a.prototype),m},lt.apply(null,arguments)}function Nr(e){var t=typeof Map=="function"?new Map:void 0;return Nr=function(n){if(n===null||!Li(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(n))return t.get(n);t.set(n,i)}function i(){return lt(n,arguments,re(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),Ze(i,n)},Nr(e)}var tn={},ki={get exports(){return tn},set exports(e){tn=e}},Hr={},Fr={};Object.defineProperty(Fr,"__esModule",{value:!0});function Bi(e){var t=4,r=e.length,n=r%t;if(!n)return e;var i=r,o=t-n,a=r+o,c=Re.Buffer.alloc(a);for(c.write(e);o--;)c.write("=",i++);return c.toString()}Fr.default=Bi;Object.defineProperty(Hr,"__esModule",{value:!0});var ji=Fr;function Fn(e,t){return t===void 0&&(t="utf8"),Re.Buffer.isBuffer(e)?kr(e.toString("base64")):kr(Re.Buffer.from(e,t).toString("base64"))}function Ui(e,t){return t===void 0&&(t="utf8"),Re.Buffer.from($r(e),"base64").toString(t)}function $r(e){return e=e.toString(),ji.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function kr(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function xi(e){return Re.Buffer.from($r(e),"base64")}var qe=Fn;qe.encode=Fn;qe.decode=Ui;qe.toBase64=$r;qe.fromBase64=kr;qe.toBuffer=xi;Hr.default=qe;(function(e){e.exports=Hr.default,e.exports.default=e.exports})(ki);var $n={};const rn=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648];$n.p1600=function(e){for(let t=0;t<24;++t){const r=e[0]^e[10]^e[20]^e[30]^e[40],n=e[1]^e[11]^e[21]^e[31]^e[41],i=e[2]^e[12]^e[22]^e[32]^e[42],o=e[3]^e[13]^e[23]^e[33]^e[43],a=e[4]^e[14]^e[24]^e[34]^e[44],c=e[5]^e[15]^e[25]^e[35]^e[45],d=e[6]^e[16]^e[26]^e[36]^e[46],m=e[7]^e[17]^e[27]^e[37]^e[47],y=e[8]^e[18]^e[28]^e[38]^e[48],p=e[9]^e[19]^e[29]^e[39]^e[49];let h=y^(i<<1|o>>>31),b=p^(o<<1|i>>>31);const O=e[0]^h,_=e[1]^b,T=e[10]^h,A=e[11]^b,E=e[20]^h,U=e[21]^b,k=e[30]^h,q=e[31]^b,j=e[40]^h,V=e[41]^b;h=r^(a<<1|c>>>31),b=n^(c<<1|a>>>31);const X=e[2]^h,L=e[3]^b,G=e[12]^h,H=e[13]^b,ne=e[22]^h,se=e[23]^b,ie=e[32]^h,C=e[33]^b,v=e[42]^h,l=e[43]^b;h=i^(d<<1|m>>>31),b=o^(m<<1|d>>>31);const f=e[4]^h,g=e[5]^b,w=e[14]^h,M=e[15]^b,I=e[24]^h,x=e[25]^b,F=e[34]^h,z=e[35]^b,J=e[44]^h,s=e[45]^b;h=a^(y<<1|p>>>31),b=c^(p<<1|y>>>31);const u=e[6]^h,S=e[7]^b,R=e[16]^h,B=e[17]^b,D=e[26]^h,N=e[27]^b,we=e[36]^h,Pe=e[37]^b,Ve=e[46]^h,at=e[47]^b;h=d^(r<<1|n>>>31),b=m^(n<<1|r>>>31);const Te=e[8]^h,Ge=e[9]^b,Me=e[18]^h,Ie=e[19]^b,De=e[28]^h,ge=e[29]^b,fe=e[38]^h,ye=e[39]^b,zr=e[48]^h,Yr=e[49]^b,Pt=O,Tt=_,Mt=A<<4|T>>>28,It=T<<4|A>>>28,Dt=E<<3|U>>>29,Lt=U<<3|E>>>29,Nt=q<<9|k>>>23,kt=k<<9|q>>>23,Bt=j<<18|V>>>14,jt=V<<18|j>>>14,Ut=X<<1|L>>>31,xt=L<<1|X>>>31,Wt=H<<12|G>>>20,Ht=G<<12|H>>>20,Ft=ne<<10|se>>>22,$t=se<<10|ne>>>22,qt=C<<13|ie>>>19,Kt=ie<<13|C>>>19,Vt=v<<2|l>>>30,Gt=l<<2|v>>>30,zt=g<<30|f>>>2,Yt=f<<30|g>>>2,Xt=w<<6|M>>>26,Jt=M<<6|w>>>26,Zt=x<<11|I>>>21,Qt=I<<11|x>>>21,er=F<<15|z>>>17,tr=z<<15|F>>>17,rr=s<<29|J>>>3,nr=J<<29|s>>>3,ir=u<<28|S>>>4,or=S<<28|u>>>4,ar=B<<23|R>>>9,sr=R<<23|B>>>9,ur=D<<25|N>>>7,lr=N<<25|D>>>7,cr=we<<21|Pe>>>11,fr=Pe<<21|we>>>11,dr=at<<24|Ve>>>8,hr=Ve<<24|at>>>8,pr=Te<<27|Ge>>>5,gr=Ge<<27|Te>>>5,yr=Me<<20|Ie>>>12,mr=Ie<<20|Me>>>12,vr=ge<<7|De>>>25,br=De<<7|ge>>>25,wr=fe<<8|ye>>>24,_r=ye<<8|fe>>>24,Sr=zr<<14|Yr>>>18,Er=Yr<<14|zr>>>18;e[0]=Pt^~Wt&Zt,e[1]=Tt^~Ht&Qt,e[10]=ir^~yr&Dt,e[11]=or^~mr&Lt,e[20]=Ut^~Xt&ur,e[21]=xt^~Jt&lr,e[30]=pr^~Mt&Ft,e[31]=gr^~It&$t,e[40]=zt^~ar&vr,e[41]=Yt^~sr&br,e[2]=Wt^~Zt&cr,e[3]=Ht^~Qt&fr,e[12]=yr^~Dt&qt,e[13]=mr^~Lt&Kt,e[22]=Xt^~ur&wr,e[23]=Jt^~lr&_r,e[32]=Mt^~Ft&er,e[33]=It^~$t&tr,e[42]=ar^~vr&Nt,e[43]=sr^~br&kt,e[4]=Zt^~cr&Sr,e[5]=Qt^~fr&Er,e[14]=Dt^~qt&rr,e[15]=Lt^~Kt&nr,e[24]=ur^~wr&Bt,e[25]=lr^~_r&jt,e[34]=Ft^~er&dr,e[35]=$t^~tr&hr,e[44]=vr^~Nt&Vt,e[45]=br^~kt&Gt,e[6]=cr^~Sr&Pt,e[7]=fr^~Er&Tt,e[16]=qt^~rr&ir,e[17]=Kt^~nr&or,e[26]=wr^~Bt&Ut,e[27]=_r^~jt&xt,e[36]=er^~dr&pr,e[37]=tr^~hr&gr,e[46]=Nt^~Vt&zt,e[47]=kt^~Gt&Yt,e[8]=Sr^~Pt&Wt,e[9]=Er^~Tt&Ht,e[18]=rr^~ir&yr,e[19]=nr^~or&mr,e[28]=Bt^~Ut&Xt,e[29]=jt^~xt&Jt,e[38]=dr^~pr&Mt,e[39]=hr^~gr&It,e[48]=Vt^~zt&ar,e[49]=Gt^~Yt&sr,e[0]^=rn[t*2],e[1]^=rn[t*2+1]}};const ht=$n;function ot(){this.state=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.blockSize=null,this.count=0,this.squeezing=!1}ot.prototype.initialize=function(e,t){for(let r=0;r<50;++r)this.state[r]=0;this.blockSize=e/8,this.count=0,this.squeezing=!1};ot.prototype.absorb=function(e){for(let t=0;t>>8*(this.count%4)&255,this.count+=1,this.count===this.blockSize&&(ht.p1600(this.state),this.count=0);return t};ot.prototype.copy=function(e){for(let t=0;t<50;++t)e.state[t]=this.state[t];e.blockSize=this.blockSize,e.count=this.count,e.squeezing=this.squeezing};var Wi=function(){return mi(32).toString("hex")},qn=Qe;Qe.default=Qe;Qe.stable=Gn;Qe.stableStringify=Gn;var pt="[...]",Kn="[Circular]",Ae=[],Ce=[];function Vn(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function Qe(e,t,r,n){typeof n>"u"&&(n=Vn()),Br(e,"",0,[],void 0,0,n);var i;try{Ce.length===0?i=JSON.stringify(e,t,r):i=JSON.stringify(e,zn(t),r)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;Ae.length!==0;){var o=Ae.pop();o.length===4?Object.defineProperty(o[0],o[1],o[3]):o[0][o[1]]=o[2]}}return i}function Ne(e,t,r,n){var i=Object.getOwnPropertyDescriptor(n,r);i.get!==void 0?i.configurable?(Object.defineProperty(n,r,{value:e}),Ae.push([n,r,t,i])):Ce.push([t,r,e]):(n[r]=e,Ae.push([n,r,t]))}function Br(e,t,r,n,i,o,a){o+=1;var c;if(typeof e=="object"&&e!==null){for(c=0;ca.depthLimit){Ne(pt,e,t,i);return}if(typeof a.edgesLimit<"u"&&r+1>a.edgesLimit){Ne(pt,e,t,i);return}if(n.push(e),Array.isArray(e))for(c=0;ct?1:0}function Gn(e,t,r,n){typeof n>"u"&&(n=Vn());var i=jr(e,"",0,[],void 0,0,n)||e,o;try{Ce.length===0?o=JSON.stringify(i,t,r):o=JSON.stringify(i,zn(t),r)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;Ae.length!==0;){var a=Ae.pop();a.length===4?Object.defineProperty(a[0],a[1],a[3]):a[0][a[1]]=a[2]}}return o}function jr(e,t,r,n,i,o,a){o+=1;var c;if(typeof e=="object"&&e!==null){for(c=0;ca.depthLimit){Ne(pt,e,t,i);return}if(typeof a.edgesLimit<"u"&&r+1>a.edgesLimit){Ne(pt,e,t,i);return}if(n.push(e),Array.isArray(e))for(c=0;c0)for(var n=0;ne.length)&&(t=e.length);for(var r=0,n=new Array(t);r=1e3&&e<=4999}function Yi(e,t){if(t!=="[Circular]")return t}var qr={},be={};Object.defineProperty(be,"__esModule",{value:!0});be.errorValues=be.errorCodes=void 0;be.errorCodes={rpc:{invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},provider:{userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901}};be.errorValues={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."}};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.serializeError=e.isValidCode=e.getMessageFromCode=e.JSON_RPC_SERVER_ERROR_MESSAGE=void 0;const t=be,r=ve,n=t.errorCodes.rpc.internal,i="Unspecified error message. This is a bug, please report it.",o={code:n,message:a(n)};e.JSON_RPC_SERVER_ERROR_MESSAGE="Unspecified server error.";function a(h,b=i){if(Number.isInteger(h)){const O=h.toString();if(p(t.errorValues,O))return t.errorValues[O].message;if(m(h))return e.JSON_RPC_SERVER_ERROR_MESSAGE}return b}e.getMessageFromCode=a;function c(h){if(!Number.isInteger(h))return!1;const b=h.toString();return!!(t.errorValues[b]||m(h))}e.isValidCode=c;function d(h,{fallbackError:b=o,shouldIncludeStack:O=!1}={}){var _,T;if(!b||!Number.isInteger(b.code)||typeof b.message!="string")throw new Error("Must provide fallback error with integer number code and string message.");if(h instanceof r.EthereumRpcError)return h.serialize();const A={};if(h&&typeof h=="object"&&!Array.isArray(h)&&p(h,"code")&&c(h.code)){const U=h;A.code=U.code,U.message&&typeof U.message=="string"?(A.message=U.message,p(U,"data")&&(A.data=U.data)):(A.message=a(A.code),A.data={originalError:y(h)})}else{A.code=b.code;const U=(_=h)===null||_===void 0?void 0:_.message;A.message=U&&typeof U=="string"?U:b.message,A.data={originalError:y(h)}}const E=(T=h)===null||T===void 0?void 0:T.stack;return O&&h&&E&&typeof E=="string"&&(A.stack=E),A}e.serializeError=d;function m(h){return h>=-32099&&h<=-32e3}function y(h){return h&&typeof h=="object"&&!Array.isArray(h)?Object.assign({},h):h}function p(h,b){return Object.prototype.hasOwnProperty.call(h,b)}})(qr);var vt={};Object.defineProperty(vt,"__esModule",{value:!0});vt.ethErrors=void 0;const Kr=ve,Xn=qr,te=be;vt.ethErrors={rpc:{parse:e=>oe(te.errorCodes.rpc.parse,e),invalidRequest:e=>oe(te.errorCodes.rpc.invalidRequest,e),invalidParams:e=>oe(te.errorCodes.rpc.invalidParams,e),methodNotFound:e=>oe(te.errorCodes.rpc.methodNotFound,e),internal:e=>oe(te.errorCodes.rpc.internal,e),server:e=>{if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Ethereum RPC Server errors must provide single object argument.");const{code:t}=e;if(!Number.isInteger(t)||t>-32005||t<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return oe(t,e)},invalidInput:e=>oe(te.errorCodes.rpc.invalidInput,e),resourceNotFound:e=>oe(te.errorCodes.rpc.resourceNotFound,e),resourceUnavailable:e=>oe(te.errorCodes.rpc.resourceUnavailable,e),transactionRejected:e=>oe(te.errorCodes.rpc.transactionRejected,e),methodNotSupported:e=>oe(te.errorCodes.rpc.methodNotSupported,e),limitExceeded:e=>oe(te.errorCodes.rpc.limitExceeded,e)},provider:{userRejectedRequest:e=>ze(te.errorCodes.provider.userRejectedRequest,e),unauthorized:e=>ze(te.errorCodes.provider.unauthorized,e),unsupportedMethod:e=>ze(te.errorCodes.provider.unsupportedMethod,e),disconnected:e=>ze(te.errorCodes.provider.disconnected,e),chainDisconnected:e=>ze(te.errorCodes.provider.chainDisconnected,e),custom:e=>{if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Ethereum Provider custom errors must provide single object argument.");const{code:t,message:r,data:n}=e;if(!r||typeof r!="string")throw new Error('"message" must be a nonempty string');return new Kr.EthereumProviderError(t,r,n)}}};function oe(e,t){const[r,n]=Jn(t);return new Kr.EthereumRpcError(e,r||Xn.getMessageFromCode(e),n)}function ze(e,t){const[r,n]=Jn(t);return new Kr.EthereumProviderError(e,r||Xn.getMessageFromCode(e),n)}function Jn(e){if(e){if(typeof e=="string")return[e];if(typeof e=="object"&&!Array.isArray(e)){const{message:t,data:r}=e;if(t&&typeof t!="string")throw new Error("Must specify string message.");return[t||void 0,r]}}return[]}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getMessageFromCode=e.serializeError=e.EthereumProviderError=e.EthereumRpcError=e.ethErrors=e.errorCodes=void 0;const t=ve;Object.defineProperty(e,"EthereumRpcError",{enumerable:!0,get:function(){return t.EthereumRpcError}}),Object.defineProperty(e,"EthereumProviderError",{enumerable:!0,get:function(){return t.EthereumProviderError}});const r=qr;Object.defineProperty(e,"serializeError",{enumerable:!0,get:function(){return r.serializeError}}),Object.defineProperty(e,"getMessageFromCode",{enumerable:!0,get:function(){return r.getMessageFromCode}});const n=vt;Object.defineProperty(e,"ethErrors",{enumerable:!0,get:function(){return n.ethErrors}});const i=be;Object.defineProperty(e,"errorCodes",{enumerable:!0,get:function(){return i.errorCodes}})})(de);var ke={},Xi={get exports(){return ke},set exports(e){ke=e}},Ji=Zn;function Zn(e,t){if(e&&t)return Zn(e)(t);if(typeof e!="function")throw new TypeError("need wrapper function");return Object.keys(e).forEach(function(n){r[n]=e[n]}),r;function r(){for(var n=new Array(arguments.length),i=0;i0;return co(i,a,c,function(d){r||(r=d),d&&n.forEach(on),!a&&(n.forEach(on),t(r))})});return e.reduce(fo)},ft=ho;function po(e){var t=go();return function(){var n=re(e),i;if(t){var o=re(this).constructor;i=Reflect.construct(n,arguments,o)}else i=n.apply(this,arguments);return $e(this,i)}}function go(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function st(){}var an="SYN",Rr="ACK",sn="BRK",un=function(e){Fe(r,e);var t=po(r);function r(n){var i,o=n.name,a=n.target,c=n.targetWindow,d=c===void 0?window:c,m=n.targetOrigin,y=m===void 0?"*":m;if(We(this,r),i=t.call(this,{objectMode:!0}),P(Q(i),"_init",void 0),P(Q(i),"_haveSyn",void 0),P(Q(i),"_name",void 0),P(Q(i),"_target",void 0),P(Q(i),"_targetWindow",void 0),P(Q(i),"_targetOrigin",void 0),P(Q(i),"_onMessage",void 0),P(Q(i),"_synIntervalId",void 0),!o||!a)throw new Error("Invalid input.");return i._init=!1,i._haveSyn=!1,i._name=o,i._target=a,i._targetWindow=d,i._targetOrigin=y,i._onMessage=i.onMessage.bind(Q(i)),i._synIntervalId=null,window.addEventListener("message",i._onMessage,!1),i._handShake(),i}return He(r,[{key:"_break",value:function(){this.cork(),this._write(sn,null,st),this._haveSyn=!1,this._init=!1}},{key:"_handShake",value:function(){this._write(an,null,st),this.cork()}},{key:"_onData",value:function(i){if(!this._init)i===an?(this._haveSyn=!0,this._write(Rr,null,st)):i===Rr&&(this._init=!0,this._haveSyn||this._write(Rr,null,st),this.uncork());else if(i===sn)this._break();else try{this.push(i)}catch(o){this.emit("error",o)}}},{key:"_postMessage",value:function(i){var o=this._targetOrigin;this._targetWindow.postMessage({target:this._target,data:i},o)}},{key:"onMessage",value:function(i){var o=i.data;this._targetOrigin!=="*"&&i.origin!==this._targetOrigin||i.source!==this._targetWindow||me(o)!=="object"||o.target!==this._name||!o.data||this._onData(o.data)}},{key:"_read",value:function(){}},{key:"_write",value:function(i,o,a){this._postMessage(i),a()}},{key:"_destroy",value:function(){window.removeEventListener("message",this._onMessage,!1)}}]),r}(mt.Duplex);function yo(e){var t=mo();return function(){var n=re(e),i;if(t){var o=re(this).constructor;i=Reflect.construct(n,arguments,o)}else i=n.apply(this,arguments);return $e(this,i)}}function mo(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ln(e,t,r){try{Reflect.apply(e,t,r)}catch(n){setTimeout(function(){throw n})}}function vo(e){for(var t=e.length,r=new Array(t),n=0;n1?c-1:0),m=1;m0&&(y=d[0]),y instanceof Error)throw y;var p=new Error("Unhandled error.".concat(y?" (".concat(y.message,")"):""));throw p.context=y,p}var h=a[i];if(h===void 0)return!1;if(typeof h=="function")ln(h,this,d);else for(var b=h.length,O=vo(h),_=0;_"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}var Ye=function(e){Fe(r,e);var t=bo(r);function r(n){var i,o=n.code,a=n.message,c=n.data;if(We(this,r),!Number.isInteger(o))throw new Error("code must be an integer");if(!a||typeof a!="string")throw new Error("message must be string");return i=t.call(this,a),P(Q(i),"code",void 0),P(Q(i),"data",void 0),i.code=o,c!==void 0&&(i.data=c),i}return He(r,[{key:"toString",value:function(){return qn({code:this.code,message:this.message,data:this.data,stack:this.stack})}}]),r}(Nr(Error));function _o(){var e={};function t(){return!1}var r=new wt;function n(d){var m=e[d.id];if(!m)throw new Error('StreamMiddleware - Unknown response id "'.concat(d.id,'"'));delete e[d.id],Object.assign(m.res,d),setTimeout(m.end)}function i(d){r.emit("notification",d)}function o(d,m,y){var p;try{var h=!d.id;h?i(d):n(d)}catch(b){p=b}y(p)}var a=new mt.Duplex({objectMode:!0,read:t,write:o}),c=function(m,y,p,h){a.push(m),e[m.id]={req:m,res:y,next:p,end:h}};return{events:r,middleware:c,stream:a}}function So(){return function(e,t,r,n){var i=e.id,o=Wi();e.id=o,t.id=o,r(function(a){e.id=i,t.id=i,a()})}}function cn(e,t){var r=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Eo(e))||t&&e&&typeof e.length=="number"){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(m){throw m},f:i}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,a=!1,c;return{s:function(){r=r.call(e)},n:function(){var m=r.next();return o=m.done,m},e:function(m){a=!0,c=m},f:function(){try{!o&&r.return!=null&&r.return()}finally{if(a)throw c}}}}function Eo(e,t){if(e){if(typeof e=="string")return fn(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return fn(e,t)}}function fn(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}var Ao=function(e){Fe(r,e);var t=Co(r);function r(){var n;return We(this,r),n=t.call(this),P(Q(n),"_middleware",void 0),n._middleware=[],n}return He(r,[{key:"push",value:function(i){this._middleware.push(i)}},{key:"handle",value:function(i,o){if(o&&typeof o!="function")throw new Error('"callback" must be a function if provided.');return Array.isArray(i)?o?this._handleBatch(i,o):this._handleBatch(i):o?this._handle(i,o):this._promiseHandle(i)}},{key:"asMiddleware",value:function(){var i=this;return function(){var o=_e(ee.mark(function a(c,d,m,y){var p,h,b,O,_;return ee.wrap(function(A){for(;;)switch(A.prev=A.next){case 0:return A.prev=0,A.next=3,r._runAllMiddleware(c,d,i._middleware);case 3:if(p=A.sent,h=Or(p,3),b=h[0],O=h[1],_=h[2],!O){A.next=12;break}return A.next=11,r._runReturnHandlers(_);case 11:return A.abrupt("return",y(b));case 12:return A.abrupt("return",m(function(){var E=_e(ee.mark(function U(k){return ee.wrap(function(j){for(;;)switch(j.prev=j.next){case 0:return j.prev=0,j.next=3,r._runReturnHandlers(_);case 3:j.next=8;break;case 5:return j.prev=5,j.t0=j.catch(0),j.abrupt("return",k(j.t0));case 8:return j.abrupt("return",k());case 9:case"end":return j.stop()}},U,null,[[0,5]])}));return function(U){return E.apply(this,arguments)}}()));case 15:return A.prev=15,A.t0=A.catch(0),A.abrupt("return",y(A.t0));case 18:case"end":return A.stop()}},a,null,[[0,15]])}));return function(a,c,d,m){return o.apply(this,arguments)}}()}},{key:"_handleBatch",value:function(){var n=_e(ee.mark(function o(a,c){var d;return ee.wrap(function(y){for(;;)switch(y.prev=y.next){case 0:return y.prev=0,y.next=3,Promise.all(a.map(this._promiseHandle.bind(this)));case 3:if(d=y.sent,!c){y.next=6;break}return y.abrupt("return",c(null,d));case 6:return y.abrupt("return",d);case 9:if(y.prev=9,y.t0=y.catch(0),!c){y.next=13;break}return y.abrupt("return",c(y.t0));case 13:throw y.t0;case 14:case"end":return y.stop()}},o,this,[[0,9]])}));function i(o,a){return n.apply(this,arguments)}return i}()},{key:"_promiseHandle",value:function(i){var o=this;return new Promise(function(a){o._handle(i,function(c,d){a(d)})})}},{key:"_handle",value:function(){var n=_e(ee.mark(function o(a,c){var d,m,y,p,h;return ee.wrap(function(O){for(;;)switch(O.prev=O.next){case 0:if(!(!a||Array.isArray(a)||me(a)!=="object")){O.next=3;break}return d=new Ye({code:-32603,message:"request must be plain object"}),O.abrupt("return",c(d,{id:void 0,jsonrpc:"2.0",error:d}));case 3:if(typeof a.method=="string"){O.next=6;break}return m=new Ye({code:-32603,message:"method must be string"}),O.abrupt("return",c(m,{id:a.id,jsonrpc:"2.0",error:m}));case 6:return y=Oo({},a),p={id:y.id,jsonrpc:y.jsonrpc},h=null,O.prev=9,O.next=12,this._processRequest(y,p);case 12:O.next=17;break;case 14:O.prev=14,O.t0=O.catch(9),h=O.t0;case 17:return h&&(delete p.result,p.error||(p.error=de.serializeError(h))),O.abrupt("return",c(h,p));case 19:case"end":return O.stop()}},o,this,[[9,14]])}));function i(o,a){return n.apply(this,arguments)}return i}()},{key:"_processRequest",value:function(){var n=_e(ee.mark(function o(a,c){var d,m,y,p,h;return ee.wrap(function(O){for(;;)switch(O.prev=O.next){case 0:return O.next=2,r._runAllMiddleware(a,c,this._middleware);case 2:return d=O.sent,m=Or(d,3),y=m[0],p=m[1],h=m[2],r._checkForCompletion(a,c,p),O.next=10,r._runReturnHandlers(h);case 10:if(!y){O.next=12;break}throw y;case 12:case"end":return O.stop()}},o,this)}));function i(o,a){return n.apply(this,arguments)}return i}()}],[{key:"_runAllMiddleware",value:function(){var n=_e(ee.mark(function o(a,c,d){var m,y,p,h,b,O,_,T;return ee.wrap(function(E){for(;;)switch(E.prev=E.next){case 0:m=[],y=null,p=!1,h=cn(d),E.prev=4,h.s();case 6:if((b=h.n()).done){E.next=18;break}return O=b.value,E.next=10,r._runMiddleware(a,c,O,m);case 10:if(_=E.sent,T=Or(_,2),y=T[0],p=T[1],!p){E.next=16;break}return E.abrupt("break",18);case 16:E.next=6;break;case 18:E.next=23;break;case 20:E.prev=20,E.t0=E.catch(4),h.e(E.t0);case 23:return E.prev=23,h.f(),E.finish(23);case 26:return E.abrupt("return",[y,p,m.reverse()]);case 27:case"end":return E.stop()}},o,null,[[4,20,23,26]])}));function i(o,a,c){return n.apply(this,arguments)}return i}()},{key:"_runMiddleware",value:function(i,o,a,c){return new Promise(function(d){var m=function(h){var b=h||o.error;b&&(o.error=de.serializeError(b)),d([b,!0])},y=function(h){o.error?m(o.error):(h&&(typeof h!="function"&&m(new Ye({code:-32603,message:"JRPCEngine: 'next' return handlers must be functions"})),c.push(h)),d([null,!1]))};try{a(i,o,y,m)}catch(p){m(p)}})}},{key:"_runReturnHandlers",value:function(){var n=_e(ee.mark(function o(a){var c,d,m;return ee.wrap(function(p){for(;;)switch(p.prev=p.next){case 0:c=cn(a),p.prev=1,m=ee.mark(function h(){var b;return ee.wrap(function(_){for(;;)switch(_.prev=_.next){case 0:return b=d.value,_.next=3,new Promise(function(T,A){b(function(E){return E?A(E):T()})});case 3:case"end":return _.stop()}},h)}),c.s();case 4:if((d=c.n()).done){p.next=8;break}return p.delegateYield(m(),"t0",6);case 6:p.next=4;break;case 8:p.next=13;break;case 10:p.prev=10,p.t1=p.catch(1),c.e(p.t1);case 13:return p.prev=13,c.f(),p.finish(13);case 16:case"end":return p.stop()}},o,null,[[1,10,13,16]])}));function i(o){return n.apply(this,arguments)}return i}()},{key:"_checkForCompletion",value:function(i,o,a){if(!("result"in o)&&!("error"in o))throw new Ye({code:-32603,message:"Response has no error or result for request"});if(!a)throw new Ye({code:-32603,message:"Nothing ended request"})}}]),r}(wt);function Po(e){var t=To();return function(){var n=re(e),i;if(t){var o=re(this).constructor;i=Reflect.construct(n,arguments,o)}else i=n.apply(this,arguments);return $e(this,i)}}function To(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}var Mo=function(e){Fe(r,e);var t=Po(r);function r(n){var i,o=n.parent,a=n.name;return We(this,r),i=t.call(this,{objectMode:!0}),P(Q(i),"_parent",void 0),P(Q(i),"_name",void 0),i._parent=o,i._name=a,i}return He(r,[{key:"_read",value:function(){}},{key:"_write",value:function(i,o,a){this._parent.push({name:this._name,data:i}),a()}}]),r}(mt.Duplex);function hn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function pn(e){for(var t=1;t"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}var gn=Symbol("IGNORE_SUBSTREAM"),ri=function(e){Fe(r,e);var t=Io(r);function r(){var n,i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return We(this,r),n=t.call(this,pn(pn({},i),{},{objectMode:!0})),P(Q(n),"_substreams",void 0),P(Q(n),"getStream",void 0),n._substreams={},n}return He(r,[{key:"createStream",value:function(i){if(!i)throw new Error("ObjectMultiplex - name must not be empty");if(this._substreams[i])throw new Error('ObjectMultiplex - Substream for name "'.concat(i,'" already exists'));var o=new Mo({parent:this,name:i});return this._substreams[i]=o,Lo(this,function(a){return o.destroy(a||void 0)}),o}},{key:"ignoreStream",value:function(i){if(!i)throw new Error("ObjectMultiplex - name must not be empty");if(this._substreams[i])throw new Error('ObjectMultiplex - Substream for name "'.concat(i,'" already exists'));this._substreams[i]=gn}},{key:"_read",value:function(){}},{key:"_write",value:function(i,o,a){var c=i.name,d=i.data;if(!c)return window.console.warn('ObjectMultiplex - malformed chunk without name "'.concat(i,'"')),a();var m=this._substreams[c];return m?(m!==gn&&m.push(d),a()):(window.console.warn('ObjectMultiplex - orphaned data for stream "'.concat(c,'"')),a())}}]),r}(mt.Duplex);function Lo(e,t){var r=ke(t);Ur(e,{readable:!1},r),Ur(e,{writable:!1},r)}function No(e){var t=new ri;return t.getStream=function(n){return this._substreams[n]?this._substreams[n]:this.createStream(n)},ft(e,t,e,function(r){r&&window.console.error(r)}),t}var xr={},_t={};Object.defineProperty(_t,"__esModule",{value:!0});_t.storeAsStream=void 0;const ko=bi;class Bo extends ko.Duplex{constructor(t){super({objectMode:!0}),this.resume(),this.handler=r=>this.push(r),this.obsStore=t,this.obsStore.subscribe(this.handler)}pipe(t,r){const n=super.pipe(t,r);return t.write(this.obsStore.getState()),n}_write(t,r,n){this.obsStore.putState(t),n()}_read(t){}_destroy(t,r){this.obsStore.unsubscribe(this.handler),super._destroy(t,r)}}function jo(e){return new Bo(e)}_t.storeAsStream=jo;var St={},Ke={},Vr={};Object.defineProperty(Vr,"__esModule",{value:!0});const Uo=nt;function yn(e,t,r){try{Reflect.apply(e,t,r)}catch(n){setTimeout(()=>{throw n})}}function xo(e){const t=e.length,r=new Array(t);for(let n=0;n0&&([a]=r),a instanceof Error)throw a;const c=new Error(`Unhandled error.${a?` (${a.message})`:""}`);throw c.context=a,c}const o=i[t];if(o===void 0)return!1;if(typeof o=="function")yn(o,this,r);else{const a=o.length,c=xo(o);for(let d=0;d{const n=this._children[r];this._addChild(r,n)})}_addChild(t,r){const n=i=>{const o=this.getState();o[t]=i,this.putState(o)};r.subscribe(n),n(r.getState())}}St.ComposedStore=Ko;var Et={};Object.defineProperty(Et,"__esModule",{value:!0});Et.MergedStore=void 0;const Vo=Ke;class Go extends Vo.ObservableStore{constructor(t=[]){super({}),this._children=t,t.forEach(r=>this._addChild(r)),this._updateWholeState()}_addChild(t){t.subscribe(()=>this._updateWholeState())}_updateWholeState(){const t=this._children.map(n=>n.getState()),r=Object.assign({},...t);this.putState(r)}}Et.MergedStore=Go;var Ot={},tt={},zo={get exports(){return tt},set exports(e){tt=e}},gt={},Yo={get exports(){return gt},set exports(e){gt=e}},Be={},mn={get exports(){return Be},set exports(e){Be=e}};typeof Z>"u"||!Z.version||Z.version.indexOf("v0.")===0||Z.version.indexOf("v1.")===0&&Z.version.indexOf("v1.8.")!==0?mn.exports={nextTick:Xo}:mn.exports=Z;function Xo(e,t,r,n){if(typeof e!="function")throw new TypeError('"callback" argument must be a function');var i=arguments.length,o,a;switch(i){case 0:case 1:return Z.nextTick(e);case 2:return Z.nextTick(function(){e.call(null,t)});case 3:return Z.nextTick(function(){e.call(null,t,r)});case 4:return Z.nextTick(function(){e.call(null,t,r,n)});default:for(o=new Array(i-1),a=0;a"u"}K.isPrimitive=ha;K.isBuffer=Un().Buffer.isBuffer;function Ct(e){return Object.prototype.toString.call(e)}var yt={},pa={get exports(){return yt},set exports(e){yt=e}},vn;function ga(){return vn||(vn=1,function(e){function t(o,a){if(!(o instanceof a))throw new TypeError("Cannot call a class as a function")}var r=je.Buffer,n=Wr;function i(o,a,c){o.copy(a,c)}e.exports=function(){function o(){t(this,o),this.head=null,this.tail=null,this.length=0}return o.prototype.push=function(c){var d={data:c,next:null};this.length>0?this.tail.next=d:this.head=d,this.tail=d,++this.length},o.prototype.unshift=function(c){var d={data:c,next:this.head};this.length===0&&(this.tail=d),this.head=d,++this.length},o.prototype.shift=function(){if(this.length!==0){var c=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,c}},o.prototype.clear=function(){this.head=this.tail=null,this.length=0},o.prototype.join=function(c){if(this.length===0)return"";for(var d=this.head,m=""+d.data;d=d.next;)m+=c+d.data;return m},o.prototype.concat=function(c){if(this.length===0)return r.alloc(0);if(this.length===1)return this.head.data;for(var d=r.allocUnsafe(c>>>0),m=this.head,y=0;m;)i(m.data,d,y),y+=m.data.length,m=m.next;return d},o}(),n&&n.inspect&&n.inspect.custom&&(e.exports.prototype[n.inspect.custom]=function(){var o=n.inspect({length:this.length});return this.constructor.name+" "+o})}(pa)),yt}var bn=Be;function ya(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return n||i?(t?t(e):e&&(!this._writableState||!this._writableState.errorEmitted)&&bn.nextTick(wn,this,e),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(o){!t&&o?(bn.nextTick(wn,r,o),r._writableState&&(r._writableState.errorEmitted=!0)):t&&t(o)}),this)}function ma(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function wn(e,t){e.emit("error",t)}var ii={destroy:ya,undestroy:ma},Ar,_n;function oi(){if(_n)return Ar;_n=1;var e=Be;Ar=_;function t(l){var f=this;this.next=null,this.entry=null,this.finish=function(){v(f,l)}}var r=!Z.browser&&["v0.10","v0.9."].indexOf(Z.version.slice(0,5))>-1?setImmediate:e.nextTick,n;_.WritableState=b;var i=Object.create(K);i.inherits=it;var o={deprecate:wi},a=ni,c=je.Buffer,d=he.Uint8Array||function(){};function m(l){return c.from(l)}function y(l){return c.isBuffer(l)||l instanceof d}var p=ii;i.inherits(_,a);function h(){}function b(l,f){n=n||Ue(),l=l||{};var g=f instanceof n;this.objectMode=!!l.objectMode,g&&(this.objectMode=this.objectMode||!!l.writableObjectMode);var w=l.highWaterMark,M=l.writableHighWaterMark,I=this.objectMode?16:16*1024;w||w===0?this.highWaterMark=w:g&&(M||M===0)?this.highWaterMark=M:this.highWaterMark=I,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var x=l.decodeStrings===!1;this.decodeStrings=!x,this.defaultEncoding=l.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(F){V(f,F)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new t(this)}b.prototype.getBuffer=function(){for(var f=this.bufferedRequest,g=[];f;)g.push(f),f=f.next;return g},function(){try{Object.defineProperty(b.prototype,"buffer",{get:o.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var O;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(O=Function.prototype[Symbol.hasInstance],Object.defineProperty(_,Symbol.hasInstance,{value:function(l){return O.call(this,l)?!0:this!==_?!1:l&&l._writableState instanceof b}})):O=function(l){return l instanceof this};function _(l){if(n=n||Ue(),!O.call(_,this)&&!(this instanceof n))return new _(l);this._writableState=new b(l,this),this.writable=!0,l&&(typeof l.write=="function"&&(this._write=l.write),typeof l.writev=="function"&&(this._writev=l.writev),typeof l.destroy=="function"&&(this._destroy=l.destroy),typeof l.final=="function"&&(this._final=l.final)),a.call(this)}_.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function T(l,f){var g=new Error("write after end");l.emit("error",g),e.nextTick(f,g)}function A(l,f,g,w){var M=!0,I=!1;return g===null?I=new TypeError("May not write null values to stream"):typeof g!="string"&&g!==void 0&&!f.objectMode&&(I=new TypeError("Invalid non-string/buffer chunk")),I&&(l.emit("error",I),e.nextTick(w,I),M=!1),M}_.prototype.write=function(l,f,g){var w=this._writableState,M=!1,I=!w.objectMode&&y(l);return I&&!c.isBuffer(l)&&(l=m(l)),typeof f=="function"&&(g=f,f=null),I?f="buffer":f||(f=w.defaultEncoding),typeof g!="function"&&(g=h),w.ended?T(this,g):(I||A(this,w,l,g))&&(w.pendingcb++,M=U(this,w,I,l,f,g)),M},_.prototype.cork=function(){var l=this._writableState;l.corked++},_.prototype.uncork=function(){var l=this._writableState;l.corked&&(l.corked--,!l.writing&&!l.corked&&!l.finished&&!l.bufferProcessing&&l.bufferedRequest&&G(this,l))},_.prototype.setDefaultEncoding=function(f){if(typeof f=="string"&&(f=f.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((f+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+f);return this._writableState.defaultEncoding=f,this};function E(l,f,g){return!l.objectMode&&l.decodeStrings!==!1&&typeof f=="string"&&(f=c.from(f,g)),f}Object.defineProperty(_.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function U(l,f,g,w,M,I){if(!g){var x=E(f,w,M);w!==x&&(g=!0,M="buffer",w=x)}var F=f.objectMode?1:w.length;f.length+=F;var z=f.length0?(typeof u!="string"&&!D.objectMode&&Object.getPrototypeOf(u)!==o.prototype&&(u=c(u)),R?D.endEmitted?s.emit("error",new Error("stream.unshift() after end event")):k(s,D,u,!0):D.ended?s.emit("error",new Error("stream.push() after EOF")):(D.reading=!1,D.decoder&&!S?(u=D.decoder.write(u),D.objectMode||u.length!==0?k(s,D,u,!1):se(s,D)):k(s,D,u,!1))):R||(D.reading=!1)}return j(D)}function k(s,u,S,R){u.flowing&&u.length===0&&!u.sync?(s.emit("data",S),s.read(0)):(u.length+=u.objectMode?1:S.length,R?u.buffer.unshift(S):u.buffer.push(S),u.needReadable&&H(s)),se(s,u)}function q(s,u){var S;return!d(u)&&typeof u!="string"&&u!==void 0&&!s.objectMode&&(S=new TypeError("Invalid non-string/buffer chunk")),S}function j(s){return!s.ended&&(s.needReadable||s.length=V?s=V:(s--,s|=s>>>1,s|=s>>>2,s|=s>>>4,s|=s>>>8,s|=s>>>16,s++),s}function L(s,u){return s<=0||u.length===0&&u.ended?0:u.objectMode?1:s!==s?u.flowing&&u.length?u.buffer.head.data.length:u.length:(s>u.highWaterMark&&(u.highWaterMark=X(s)),s<=u.length?s:u.ended?u.length:(u.needReadable=!0,0))}E.prototype.read=function(s){p("read",s),s=parseInt(s,10);var u=this._readableState,S=s;if(s!==0&&(u.emittedReadable=!1),s===0&&u.needReadable&&(u.length>=u.highWaterMark||u.ended))return p("read: emitReadable",u.length,u.ended),u.length===0&&u.ended?F(this):H(this),null;if(s=L(s,u),s===0&&u.ended)return u.length===0&&F(this),null;var R=u.needReadable;p("need readable",R),(u.length===0||u.length-s0?B=w(s,u):B=null,B===null?(u.needReadable=!0,s=0):u.length-=s,u.length===0&&(u.ended||(u.needReadable=!0),S!==s&&u.ended&&F(this)),B!==null&&this.emit("data",B),B};function G(s,u){if(!u.ended){if(u.decoder){var S=u.decoder.end();S&&S.length&&(u.buffer.push(S),u.length+=u.objectMode?1:S.length)}u.ended=!0,H(s)}}function H(s){var u=s._readableState;u.needReadable=!1,u.emittedReadable||(p("emitReadable",u.flowing),u.emittedReadable=!0,u.sync?e.nextTick(ne,s):ne(s))}function ne(s){p("emit readable"),s.emit("readable"),g(s)}function se(s,u){u.readingMore||(u.readingMore=!0,e.nextTick(ie,s,u))}function ie(s,u){for(var S=u.length;!u.reading&&!u.flowing&&!u.ended&&u.length1&&J(R.pipes,s)!==-1)&&!Ve&&(p("false write response, pause",S._readableState.awaitDrain),S._readableState.awaitDrain++,Te=!0),S.pause())}function Me(fe){p("onerror",fe),ge(),s.removeListener("error",Me),n(s,"error")===0&&s.emit("error",fe)}T(s,"error",Me);function Ie(){s.removeListener("finish",De),ge()}s.once("close",Ie);function De(){p("onfinish"),s.removeListener("close",Ie),ge()}s.once("finish",De);function ge(){p("unpipe"),S.unpipe(s)}return s.emit("pipe",S),R.flowing||(p("pipe resume"),S.resume()),s};function C(s){return function(){var u=s._readableState;p("pipeOnDrain",u.awaitDrain),u.awaitDrain&&u.awaitDrain--,u.awaitDrain===0&&n(s,"data")&&(u.flowing=!0,g(s))}}E.prototype.unpipe=function(s){var u=this._readableState,S={hasUnpiped:!1};if(u.pipesCount===0)return this;if(u.pipesCount===1)return s&&s!==u.pipes?this:(s||(s=u.pipes),u.pipes=null,u.pipesCount=0,u.flowing=!1,s&&s.emit("unpipe",this,S),this);if(!s){var R=u.pipes,B=u.pipesCount;u.pipes=null,u.pipesCount=0,u.flowing=!1;for(var D=0;D=u.length?(u.decoder?S=u.buffer.join(""):u.buffer.length===1?S=u.buffer.head.data:S=u.buffer.concat(u.length),u.buffer.clear()):S=M(s,u.buffer,u.decoder),S}function M(s,u,S){var R;return sD.length?D.length:s;if(N===D.length?B+=D:B+=D.slice(0,s),s-=N,s===0){N===D.length?(++R,S.next?u.head=S.next:u.head=u.tail=null):(u.head=S,S.data=D.slice(N));break}++R}return u.length-=R,B}function x(s,u){var S=o.allocUnsafe(s),R=u.head,B=1;for(R.data.copy(S),s-=R.data.length;R=R.next;){var D=R.data,N=s>D.length?D.length:s;if(D.copy(S,S.length-s,0,N),s-=N,s===0){N===D.length?(++B,R.next?u.head=R.next:u.head=u.tail=null):(u.head=R,R.data=D.slice(N));break}++B}return u.length-=B,S}function F(s){var u=s._readableState;if(u.length>0)throw new Error('"endReadable()" called on non-empty stream');u.endEmitted||(u.ended=!0,e.nextTick(z,u,s))}function z(s,u){!s.endEmitted&&s.length===0&&(s.endEmitted=!0,u.readable=!1,u.emit("end"))}function J(s,u){for(var S=0,R=s.length;S{try{const i=e(t);n(null,i);return}catch(i){n(i);return}})}Ot.storeTransformStream=Ra;(function(e){var t=he&&he.__createBinding||(Object.create?function(n,i,o,a){a===void 0&&(a=o),Object.defineProperty(n,a,{enumerable:!0,get:function(){return i[o]}})}:function(n,i,o,a){a===void 0&&(a=o),n[a]=i[o]}),r=he&&he.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(_t,e),r(St,e),r(Et,e),r(Ke,e),r(Ot,e)})(xr);var Aa=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var n,i,o;if(Array.isArray(t)){if(n=t.length,n!=r.length)return!1;for(i=n;i--!==0;)if(!e(t[i],r[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(o=Object.keys(t),n=o.length,n!==Object.keys(r).length)return!1;for(i=n;i--!==0;)if(!Object.prototype.hasOwnProperty.call(r,o[i]))return!1;for(i=n;i--!==0;){var a=o[i];if(!e(t[a],r[a]))return!1}return!0}return t!==t&&r!==r};const ce=e=>e!==null&&typeof e=="object"&&typeof e.pipe=="function";ce.writable=e=>ce(e)&&e.writable!==!1&&typeof e._write=="function"&&typeof e._writableState=="object";ce.readable=e=>ce(e)&&e.readable!==!1&&typeof e._read=="function"&&typeof e._readableState=="object";ce.duplex=e=>ce.writable(e)&&ce.readable(e);ce.transform=e=>ce.duplex(e)&&typeof e._transform=="function";var Pa=ce;const Xe={GOOGLE:"google",FACEBOOK:"facebook",TWITCH:"twitch",REDDIT:"reddit",DISCORD:"discord"},Ee={GOOGLE:"google",FACEBOOK:"facebook",TWITCH:"twitch",REDDIT:"reddit",DISCORD:"discord",EMAIL_PASSWORDLESS:"torus-auth0-email-passwordless"},Cn={[Ee.GOOGLE]:"tkey-google",[Ee.FACEBOOK]:"tkey-facebook",[Ee.TWITCH]:"tkey-twitch",[Ee.REDDIT]:"tkey-reddit",[Ee.DISCORD]:"tkey-discord",[Ee.EMAIL_PASSWORDLESS]:"tkey-auth0-email-passwordless"},$={MOONPAY:"moonpay",WYRE:"wyre",RAMPNETWORK:"rampnetwork",XANPOOL:"xanpool",MERCURYO:"mercuryo",TRANSAK:"transak",BANXA:"banxa"},Y={MAINNET:"mainnet",MATIC:"matic",BSC_MAINNET:"bsc_mainnet",AVALANCHE_MAINNET:"avalanche_mainnet",XDAI:"xdai"},Ta={PRODUCTION:"production",DEVELOPMENT:"development",BINANCE:"binance",TESTING:"testing",LRC:"lrc",BETA:"beta",BNB:"bnb",POLYGON:"polygon"},Le={BOTTOM_LEFT:"bottom-left",TOP_LEFT:"top-left",BOTTOM_RIGHT:"bottom-right",TOP_RIGHT:"top-right"},Ma=["ETH","USDT","USDC","TUSD","EOSDT","USD","DAI","GUSD","DKKT","PAX","ILS","RUB","BYN","EUR","GBP","JPY","KRW","PLN","MXN","AUD","BRL","CAD","CHF","KPW","LAK","LBP","LKR","XOF","CNHT","DOGE","UAH","TRY","HKD","XJP","SGD","USC","NZD","NGN","RUR","COP","GHS","EGP","IDR","BHD","CRC","PEN","AED","DOP","PKR","HUF","VND","XAR","LTC","RON","OMR","MYR","DKK","UGX","ZMW","SAR","SEK","GEL","RWF","IRR","TZS","CNY","VEF","BDT","HRK","CLP","THB","XAF","ARS","UYU","SZL","KZT","NOK","KES","PAB","INR","CZK","MAD","TWD","PHP","ZAR","BOB","CDF","DASH","VES","ISK","MWK","BAM","TTD","XRP","JOD","RSD","HNL","BGN","GTQ","BWP","XMR","MMK","QAR","AOA","KWD","MUR","WUSD","WEUR","WAVES","WTRY","LRD","LSL","LYD","AWG","MDL","BTO","EURS","CHFT","MKD","MNT","MOP","MRO","MVR","VOLLAR","CKUSD","KHR","VUV","BITCNY","QC","BBD","NAD","NPR","PGK","PYG","BIF","BMD","BND","XLM","BNB","SCR","BAT","CRO","HT","KCS","LEO","LINK","MKR","NPXS","OMG","REP","ZB","ZIL","ZRX","BCH","BZD","CUP","CVE","DJF","DZD","ERN","ETB","FJD","FKP","BUSD","ANCT","ALL","AMD","ANG","CNYX","IQD","UZS","TND","GGP","XAU","KGS","GIP","JMD","ZEC","USDP","BSV","EMC2","SNT","GTO","POWR","EUSD","EURT","BCY","BTS","ATM","BLOCKPAY","ARDR","AMP","B2X","BITGOLD","BITEUR","ATB","BITUSD","AGRS","DFXT","HIKEN","BIX","KNC","EOS","COB","COSS","BMH","NANO","BDG","BNT","XVG","LKK1Y","LKK","USDK","EURN","NZDT","JSE","GMD","GNF","GYD","YER","XPF","HTG","SLL","SOS","WST","SVC","SYP","NEO","KMF","JUMP","AYA","BLAST","WGR","BCN","BTG","URALS","INN","USDQ","CNH","HUSD","BKRW","NZDX","EURX","CADX","USDEX","JPYX","AUDX","VNDC","EON","GBPX","CHFX","USDJ","IDRT","USDS","USDN","BIDR","IDK","BSD","BTN","KYD","NIO","SBD","SDG","SHP","TOP","XCD","XCHF","CNYT","GYEN","ZUSD","GOLD","TRX","TRYB","PLATC","STRAX","UST","GLM","VAI","BRZ","DDRST","XAUT","MIM"],Ia={[$.MOONPAY]:["AUD","BGN","BRL","CAD","CHF","CNY","COP","CZK","DKK","DOP","EGP","EUR","GBP","HKD","HRK","IDR","ILS","JPY","JOD","KES","KRW","KWD","LKR","MAD","MXN","MYR","NGN","NOK","NZD","OMR","PEN","PKR","PLN","RON","RUB","SEK","SGD","THB","TRY","TWD","USD","VND","ZAR"],[$.WYRE]:["USD","EUR","GBP","AUD","CAD","NZD","ARS","BRL","CHF","CLP","COP","CZK","DKK","HKD","ILS","INR","ISK","JPY","KRW","MXN","MYR","NOK","PHP","PLN","SEK","THB","VND","ZAR"],[$.RAMPNETWORK]:["USD","EUR","GBP"],[$.XANPOOL]:["SGD","HKD","THB","PHP","INR","IDR","MYR","AUD","NZD","KRW"],[$.MERCURYO]:["EUR","USD","GBP","TRY","JPY","BRL","NGN","VND","MXN","KRW"],[$.TRANSAK]:["ARS","AUD","BBD","BGN","BMD","BRL","CAD","CHF","CLP","CRC","CZK","DKK","DOP","EUR","FJD","FKP","GBP","GIP","HRK","HUF","IDR","ILS","ISK","JMD","JPY","KES","KRW","MDL","MXN","MYR","NOK","NZD","PEN","PHP","PLN","PYG","RON","SEK","SGD","THB","TRY","TZS","USD","ZAR"],[$.BANXA]:["EUR","GBP","USD"]},Da=new Set(Ma);function Se(e){return Ia[e].filter(r=>Da.has(r))}const La={[$.MOONPAY]:{line1:"Credit/ Debit Card/ Apple Pay",line2:"4.5% or 5 USD",line3:"2,000€/day, 10,000€/mo",supportPage:"https://help.moonpay.io/en/",minOrderValue:24.99,maxOrderValue:5e4,validCurrencies:Se($.MOONPAY),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"aave",display:"AAVE"},{value:"bat",display:"BAT"},{value:"dai",display:"DAI"},{value:"eth",display:"ETH"},{value:"mkr",display:"MKR"},{value:"matic",display:"MATIC"},{value:"usdt",display:"USDT"},{value:"usdc",display:"USDC"}],[Y.MATIC]:[{value:"eth_polygon",display:"ETH"},{value:"matic_polygon",display:"MATIC"},{value:"usdc_polygon",display:"USDC"}],[Y.BSC_MAINNET]:[{value:"bnb_bsc",display:"BNB"},{value:"busd_bsc",display:"BUSD"}],[Y.AVALANCHE_MAINNET]:[{value:"avax_cchain",display:"AVAX"}]},includeFees:!0,api:!0,enforceMax:!1},[$.WYRE]:{line1:"Apple Pay/ Debit/ Credit Card",line2:"4.9% + 30¢ or 5 USD",line3:"$250/day",supportPage:"https://support.sendwyre.com/en/",minOrderValue:5,maxOrderValue:500,validCurrencies:Se($.WYRE),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"AAVE",display:"AAVE"},{value:"BAT",display:"BAT"},{value:"BUSD",display:"BUSD"},{value:"DAI",display:"DAI"},{value:"ETH",display:"ETH"},{value:"MKR",display:"MKR"},{value:"UNI",display:"UNI"},{value:"USDC",display:"USDC"},{value:"USDT",display:"USDT"}],[Y.MATIC]:[{value:"MUSDC",display:"USDC"}],[Y.AVALANCHE_MAINNET]:[{value:"AVAXC",display:"AVAXC"}]},includeFees:!1,api:!0,enforceMax:!1},[$.RAMPNETWORK]:{line1:"Debit Card/
Apple Pay/ Bank transfer",line2:"0.49% - 2.9%",line3:"5,000€/purchase, 20,000€/mo",supportPage:"https://instant.ramp.network/",minOrderValue:50,maxOrderValue:2e4,validCurrencies:Se($.RAMPNETWORK),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"ETH",display:"ETH"},{value:"DAI",display:"DAI"},{value:"USDC",display:"USDC"},{value:"USDT",display:"USDT"}],[Y.MATIC]:[{value:"MATIC_DAI",display:"DAI"},{value:"MATIC_MATIC",display:"MATIC"},{value:"MATIC_USDC",display:"USDC"}],[Y.AVALANCHE_MAINNET]:[{value:"AVAX",display:"AVAX"}]},includeFees:!0,api:!0,receiveHint:"walletTopUp.receiveHintRamp",enforceMax:!1},[$.XANPOOL]:{line1:"PayNow/ InstaPay/ FPS/ GoJekPay/ UPI/ PromptPay/
ViettelPay/ DuitNow",line2:"2.5% buying, 3% selling",line3:"$2,500 / day",supportPage:"mailto:support@xanpool.com",minOrderValue:100,maxOrderValue:2500,validCurrencies:Se($.XANPOOL),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"ETH",display:"ETH"},{value:"USDT",display:"USDT"}]},includeFees:!0,api:!0,sell:!0,enforceMax:!1},[$.MERCURYO]:{line1:"Credit/ Debit Card/ Apple Pay",line2:"3.95% or 4 USD",line3:"10,000€/day, 25,000€/mo",supportPage:"mailto:support@mercuryo.io",minOrderValue:30,maxOrderValue:5e3,validCurrencies:Se($.MERCURYO),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"ETH",display:"ETH"},{value:"BAT",display:"BAT"},{value:"USDT",display:"USDT"},{value:"DAI",display:"DAI"}],[Y.BSC_MAINNET]:[{value:"BNB",display:"BNB"},{value:"BUSD",display:"BUSD"},{value:"1INCH",display:"1INCH"}]},includeFees:!0,api:!0,enforceMax:!1},[$.TRANSAK]:{line1:"Apple & Google Pay / Credit/Debit Card
Bangkok Bank Mobile & iPay
Bank Transfer (sepa/gbp) / SCB Mobile & Easy",line2:"0.99% - 5.5% or 5 USD",line3:"$5,000/day, $28,000/mo",supportPage:"https://support.transak.com/hc/en-US",minOrderValue:30,maxOrderValue:500,validCurrencies:Se($.TRANSAK),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"AAVE",display:"AAVE"},{value:"DAI",display:"DAI"},{value:"ETH",display:"ETH"},{value:"USDC",display:"USDC"},{value:"USDT",display:"USDT"}],[Y.MATIC]:[{value:"AAVE",display:"AAVE"},{value:"DAI",display:"DAI"},{value:"MATIC",display:"MATIC"},{value:"USDC",display:"USDC"},{value:"USDT",display:"USDT"},{value:"WETH",display:"WETH"}],[Y.BSC_MAINNET]:[{value:"BNB",display:"BNB"},{value:"BUSD",display:"BUSD"}],[Y.AVALANCHE_MAINNET]:[{value:"AVAX",display:"AVAX"}]},includeFees:!0,enforceMax:!0},[$.BANXA]:{line1:"Debit Card/
Apple Pay/ Bank transfer",line2:"0.49% - 2.9%",line3:"5,000€/purchase, 20,000€/mo",supportPage:"https://support.banxa.com",minOrderValue:20,maxOrderValue:15e3,validCurrencies:Se($.BANXA),validCryptoCurrenciesByChain:{[Y.MAINNET]:[{value:"ETH",display:"ETH"},{value:"USDT",display:"USDT"},{value:"BUSD",display:"BUSD"},{value:"LINK",display:"LINK"},{value:"USDC",display:"USDC"},{value:"CHZ",display:"CHZ"},{value:"BAT",display:"BAT"},{value:"MANA",display:"MANA"},{value:"AAVE",display:"AAVE"},{value:"COMP",display:"COMP"},{value:"ENJ",display:"ENJ"}],[Y.MATIC]:[{value:"MATIC",display:"MATIC"}]},includeFees:!0,enforceMax:!0}},Na={en:{embed:{continue:"Continue",actionRequired:"Authorization required",pendingAction:"Click continue to proceed with your request in a popup",cookiesRequired:"Cookies Required",enableCookies:"Please enable cookies in your browser preferences to access Torus",clickHere:"More Info"}},de:{embed:{continue:"Fortsetzen",actionRequired:"Autorisierung erforderlich",pendingAction:"Klicken Sie in einem Popup auf Weiter, um mit Ihrer Anfrage fortzufahren",cookiesRequired:"Cookies benötigt",enableCookies:"Bitte aktivieren Sie Cookies in Ihren Browsereinstellungen, um auf Torus zuzugreifen",clickHere:"Mehr Info"}},ja:{embed:{continue:"継続する",actionRequired:"認証が必要です",pendingAction:"続行をクリックして、ポップアップでリクエストを続行します",cookiesRequired:"必要なクッキー",enableCookies:"Torusにアクセスするには、ブラウザの設定でCookieを有効にしてください。",clickHere:"詳しくは"}},ko:{embed:{continue:"계속하다",actionRequired:"승인 필요",pendingAction:"팝업에서 요청을 진행하려면 계속을 클릭하십시오.",cookiesRequired:"쿠키 필요",enableCookies:"브라우저 환경 설정에서 쿠키를 활성화하여 Torus에 액세스하십시오.",clickHere:"더 많은 정보"}},zh:{embed:{continue:"继续",actionRequired:"需要授权",pendingAction:"单击继续以在弹出窗口中继续您的请求",cookiesRequired:"必填Cookie",enableCookies:"请在您的浏览器首选项中启用cookie以访问Torus。",clickHere:"更多信息"}}};var le={supportedVerifierList:Object.values(Ee),paymentProviders:La,api:"https://api.tor.us",translations:Na,prodTorusUrl:"",localStorageKeyPrefix:"torus-"};const Rn=e=>new Promise((t,r)=>{window.document.body!=null?Promise.resolve(e()).then(t).catch(r):window.document.addEventListener("DOMContentLoaded",()=>{Promise.resolve(e()).then(t).catch(r)})}),Je=e=>{const t=window.document.createElement("template"),r=e.trim();return t.innerHTML=r,t.content.firstChild},ka=function(e,t,r){for(var n=arguments.length,i=new Array(n>3?n-3:0),o=3;o{r(...i),e.removeEventListener(t,a)};e.addEventListener(t,a)},ue=(e,t,r)=>{const n=i=>{r(i),e.removeListener(t,n)};e.on(t,n)};async function Ba(){return new Promise(e=>{document.readyState!=="loading"?e():ka(document,"DOMContentLoaded",e)})}var W=Wn.getLogger("torus-embed"),ae={errors:{disconnected:()=>"Torus: Lost connection to Torus.",permanentlyDisconnected:()=>"Torus: Disconnected from iframe. Page reload required.",sendSiteMetadata:()=>"Torus: Failed to send site metadata. This is an internal error, please report this bug.",unsupportedSync:e=>`Torus: The Torus Ethereum provider does not support synchronous methods like ${e} without a callback parameter.`,invalidDuplexStream:()=>"Must provide a Node.js-style duplex stream.",invalidOptions:(e,t)=>`Invalid options. Received: { maxEventListeners: ${e}, shouldSendMetadata: ${t} }`,invalidRequestArgs:()=>"Expected a single, non-array, object argument.",invalidRequestMethod:()=>"'args.method' must be a non-empty string.",invalidRequestParams:()=>"'args.params' must be an object or array if provided.",invalidLoggerObject:()=>"'args.logger' must be an object if provided.",invalidLoggerMethod:e=>`'args.logger' must include required method '${e}'.`},info:{connected:e=>`Torus: Connected to chain with ID "${e}".`},warnings:{enableDeprecation:'Torus: ""ethereum.enable()" is deprecated and may be removed in the future. Please use "ethereum.send("eth_requestAccounts")" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1102',sendDeprecation:`Torus: "ethereum.send(...)" is deprecated and may be removed in the future. Please use "ethereum.sendAsync(...)" or "ethereum.request(...)" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1193`,events:{close:`Torus: The event "close" is deprecated and may be removed in the future. Please use "disconnect" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1193`,data:`Torus: The event "data" is deprecated and will be removed in the future.Use "message" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1193#message`,networkChanged:`Torus: The event "networkChanged" is deprecated and may be removed in the future. Please use "chainChanged" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1193`,notification:`Torus: The event "notification" is deprecated and may be removed in the future. Please use "message" instead. For more information, see: https://eips.ethereum.org/EIPS/eip-1193`},publicConfigStore:'Torus: The property "publicConfigStore" is deprecated and WILL be removed in the future.'}};const{paymentProviders:An}=le,ja=(e,t)=>{const r={};if(!e)return{errors:r,isValid:!0};if(e&&!An[e])return r.provider="Invalid Provider",{errors:r,isValid:Object.keys(r).length===0};const n=An[e],i=t||{};if(i.fiatValue){const o=+parseFloat(i.fiatValue.toString())||0;on.maxOrderValue&&n.enforceMax&&(r.fiatValue="Requested amount is higher than supported")}if(i.selectedCurrency&&!n.validCurrencies.includes(i.selectedCurrency)&&(r.selectedCurrency="Unsupported currency"),i.selectedCryptoCurrency){const o=Object.values(n.validCryptoCurrenciesByChain).flat().map(c=>c.value),a=e===$.MOONPAY?i.selectedCryptoCurrency.toLowerCase():i.selectedCryptoCurrency;o&&!o.includes(a)&&(r.selectedCryptoCurrency="Unsupported cryptoCurrency")}return{errors:r,isValid:Object.keys(r).length===0}};function Ua(){return(e,t,r)=>{(typeof e.method!="string"||!e.method)&&(t.error=de.ethErrors.rpc.invalidRequest({message:"The request 'method' must be a non-empty string.",data:e})),r(n=>{const{error:i}=t;return i&&W.error(`MetaMask - RPC Error: ${i.message}`,i),n()})}}function Pn(e,t,r){let n=`MetaMask: Lost connection to "${e}".`;t!=null&&t.stack&&(n+=` ${t.stack}`),W.warn(n),r&&r.listenerCount("error")>0&&r.emit("error",n)}const Oe=()=>Math.random().toString(36).slice(2),pi=async(e,t)=>{let r,n;const i="1.38.2";let o=t.version||i;try{if((e==="binance"||e==="production")&&!t.version){let a;le.prodTorusUrl?a={data:le.prodTorusUrl}:a=await Hn(`${le.api}/latestversion?name=@toruslabs/torus-embed&version=${i}`,{},{useAPIKey:!0}),o=a.data,le.prodTorusUrl=a.data}}catch(a){W.error(a,"unable to fetch latest version")}switch(W.info("version used: ",o),e){case"binance":r=`https://binance.tor.us/v${o}`,n="info";break;case"testing":r="https://testing.tor.us",n="debug";break;case"bnb":r="https://bnb.tor.us",n="error";break;case"polygon":r="https://polygon.tor.us",n="error";break;case"lrc":r="https://lrc.tor.us",n="debug";break;case"beta":r="https://beta.tor.us",n="debug";break;case"development":r="http://localhost:4050",n="debug";break;default:r=`https://app.tor.us/v${o}`,n="error";break}return{torusUrl:r,logLevel:n}},Tn=()=>{let e=window.navigator.language||"en-US";const t=e.split("-");return e=Object.prototype.hasOwnProperty.call(le.translations,t[0])?t[0]:"en",e},xa=["eth_subscription"],gi=()=>{},Mn="directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=660,width=375",Wa="directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=740,width=1315",In="directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=700,width=450";function Ha(){const e=window.screenLeft!==void 0?window.screenLeft:window.screenX,t=window.screenTop!==void 0?window.screenTop:window.screenY,r=1200,n=700,i=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height,a=1,c=Math.abs((i-r)/2/a+e),d=Math.abs((o-n)/2/a+t);return`titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=${n/a},width=${r/a},top=${d},left=${c}`}function Dn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function Fa(e){for(var t=1;t2&&arguments[2]!==void 0?arguments[2]:!0;return(n,i)=>n||i.error?t(n||i.error):!r||Array.isArray(i)?e(i):e(i.result)};class At extends wt{constructor(t){let{maxEventListeners:r=100,shouldSendMetadata:n=!0,jsonRpcStreamName:i="provider"}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(super(),P(this,"chainId",void 0),P(this,"selectedAddress",void 0),P(this,"_rpcEngine",void 0),P(this,"networkVersion",void 0),P(this,"shouldSendMetadata",void 0),P(this,"isTorus",void 0),P(this,"_publicConfigStore",void 0),P(this,"tryPreopenHandle",void 0),P(this,"enable",void 0),P(this,"_state",void 0),P(this,"_jsonRpcConnection",void 0),P(this,"_sentWarnings",{enable:!1,experimentalMethods:!1,send:!1,publicConfigStore:!1,events:{close:!1,data:!1,networkChanged:!1,notification:!1}}),!Pa.duplex(t))throw new Error(ae.errors.invalidDuplexStream());this.isTorus=!0,this.setMaxListeners(r),this._state=Fa({},At._defaultState),this.selectedAddress=null,this.networkVersion=null,this.chainId=null,this.shouldSendMetadata=n,this._handleAccountsChanged=this._handleAccountsChanged.bind(this),this._handleChainChanged=this._handleChainChanged.bind(this),this._handleUnlockStateChanged=this._handleUnlockStateChanged.bind(this),this._handleConnect=this._handleConnect.bind(this),this._handleDisconnect=this._handleDisconnect.bind(this),this._handleStreamDisconnect=this._handleStreamDisconnect.bind(this),this._sendSync=this._sendSync.bind(this),this._rpcRequest=this._rpcRequest.bind(this),this._warnOfDeprecation=this._warnOfDeprecation.bind(this),this._initializeState=this._initializeState.bind(this),this.request=this.request.bind(this),this.send=this.send.bind(this),this.sendAsync=this.sendAsync.bind(this);const o=new ri;ft(t,o,t,this._handleStreamDisconnect.bind(this,"MetaMask")),this._publicConfigStore=new xr.ObservableStore({storageKey:"Metamask-Config"}),ft(o.createStream("publicConfig"),xr.storeAsStream(this._publicConfigStore),Pn.bind(this,"MetaMask PublicConfigStore")),o.ignoreStream("phishing"),this.on("connect",()=>{this._state.isConnected=!0});const a=_o();ft(a.stream,o.createStream(i),a.stream,this._handleStreamDisconnect.bind(this,"MetaMask RpcProvider"));const c=new Ao;c.push(So()),c.push(Ua()),c.push(a.middleware),this._rpcEngine=c,a.events.on("notification",d=>{const{method:m,params:y}=d;m==="wallet_accountsChanged"?this._handleAccountsChanged(y):m==="wallet_unlockStateChanged"?this._handleUnlockStateChanged(y):m==="wallet_chainChanged"?this._handleChainChanged(y):xa.includes(d.method)&&(this.emit("data",d),this.emit("notification",y.result),this.emit("message",{type:m,data:y}))})}get publicConfigStore(){return this._sentWarnings.publicConfigStore||(W.warn(ae.warnings.publicConfigStore),this._sentWarnings.publicConfigStore=!0),this._publicConfigStore}isConnected(){return this._state.isConnected}async request(t){if(!t||typeof t!="object"||Array.isArray(t))throw de.ethErrors.rpc.invalidRequest({message:ae.errors.invalidRequestArgs(),data:t});const{method:r,params:n}=t;if(typeof r!="string"||r.length===0)throw de.ethErrors.rpc.invalidRequest({message:ae.errors.invalidRequestMethod(),data:t});if(n!==void 0&&!Array.isArray(n)&&(typeof n!="object"||n===null))throw de.ethErrors.rpc.invalidRequest({message:ae.errors.invalidRequestParams(),data:t});return new Promise((i,o)=>{this._rpcRequest({method:r,params:n},Ln(i,o))})}sendAsync(t,r){this._rpcRequest(t,r)}addListener(t,r){return this._warnOfDeprecation(t),super.addListener(t,r)}on(t,r){return this._warnOfDeprecation(t),super.on(t,r)}once(t,r){return this._warnOfDeprecation(t),super.once(t,r)}prependListener(t,r){return this._warnOfDeprecation(t),super.prependListener(t,r)}prependOnceListener(t,r){return this._warnOfDeprecation(t),super.prependOnceListener(t,r)}async _initializeState(){try{const{accounts:t,chainId:r,isUnlocked:n,networkVersion:i}=await this.request({method:"wallet_getProviderState"});this.emit("connect",{chainId:r}),this._handleChainChanged({chainId:r,networkVersion:i}),this._handleUnlockStateChanged({accounts:t,isUnlocked:n}),this._handleAccountsChanged(t)}catch(t){W.error("MetaMask: Failed to get initial state. Please report this bug.",t)}finally{W.info("initialized state"),this._state.initialized=!0,this.emit("_initialized")}}_rpcRequest(t,r){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,i=r;const o=t;if(!Array.isArray(o)){if(o.jsonrpc||(o.jsonrpc="2.0"),o.method==="eth_accounts"||o.method==="eth_requestAccounts")i=(a,c)=>{this._handleAccountsChanged(c.result||[],o.method==="eth_accounts",n),r(a,c)};else if(o.method==="wallet_getProviderState"){this._rpcEngine.handle(t,i);return}}this.tryPreopenHandle(o,i)}send(t,r){return this._sentWarnings.send||(W.warn(ae.warnings.sendDeprecation),this._sentWarnings.send=!0),typeof t=="string"&&(!r||Array.isArray(r))?new Promise((n,i)=>{try{this._rpcRequest({method:t,params:r},Ln(n,i,!1))}catch(o){i(o)}}):t&&typeof t=="object"&&typeof r=="function"?this._rpcRequest(t,r):this._sendSync(t)}_sendSync(t){let r;switch(t.method){case"eth_accounts":r=this.selectedAddress?[this.selectedAddress]:[];break;case"eth_coinbase":r=this.selectedAddress||null;break;case"eth_uninstallFilter":this._rpcRequest(t,gi),r=!0;break;case"net_version":r=this.networkVersion||null;break;default:throw new Error(ae.errors.unsupportedSync(t.method))}return{id:t.id,jsonrpc:t.jsonrpc,result:r}}_handleConnect(t){this._state.isConnected||(this._state.isConnected=!0,this.emit("connect",{chainId:t}),W.debug(ae.info.connected(t)))}_handleDisconnect(t,r){if(this._state.isConnected||!this._state.isPermanentlyDisconnected&&!t){this._state.isConnected=!1;let n;t?(n=new de.EthereumRpcError(1013,r||ae.errors.disconnected()),W.debug(n)):(n=new de.EthereumRpcError(1011,r||ae.errors.permanentlyDisconnected()),W.error(n),this.chainId=null,this._state.accounts=null,this.selectedAddress=null,this._state.isUnlocked=!1,this._state.isPermanentlyDisconnected=!0),this.emit("disconnect",n)}}_handleStreamDisconnect(t,r){Pn(t,r,this),this._handleDisconnect(!1,r?r.message:void 0)}_handleAccountsChanged(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,i=t;Array.isArray(i)||(W.error("MetaMask: Received non-array accounts parameter. Please report this bug.",i),i=[]);for(const o of t)if(typeof o!="string"){W.error("MetaMask: Received non-string account. Please report this bug.",t),i=[];break}Aa(this._state.accounts,i)||(r&&Array.isArray(this._state.accounts)&&this._state.accounts.length>0&&!n&&W.error('MetaMask: "eth_accounts" unexpectedly updated accounts. Please report this bug.',i),this._state.accounts=i,this.emit("accountsChanged",i)),this.selectedAddress!==i[0]&&(this.selectedAddress=i[0]||null)}_handleChainChanged(){let{chainId:t,networkVersion:r}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!t||!r){W.error("MetaMask: Received invalid network parameters. Please report this bug.",{chainId:t,networkVersion:r});return}r==="loading"?this._handleDisconnect(!0):(this._handleConnect(t),t!==this.chainId&&(this.chainId=t,this._state.initialized&&this.emit("chainChanged",this.chainId)))}_handleUnlockStateChanged(){let{accounts:t,isUnlocked:r}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(typeof r!="boolean"){W.error("MetaMask: Received invalid isUnlocked parameter. Please report this bug.",{isUnlocked:r});return}r!==this._state.isUnlocked&&(this._state.isUnlocked=r,this._handleAccountsChanged(t||[]))}_warnOfDeprecation(t){this._sentWarnings.events[t]===!1&&(W.warn(ae.warnings.events[t]),this._sentWarnings.events[t]=!0)}}P(At,"_defaultState",{accounts:null,isConnected:!1,isUnlocked:!1,initialized:!1,isPermanentlyDisconnected:!1,hasEmittedConnection:!1});const $a=e=>({algorithms:e.algorithms||["sha256"],delimiter:e.delimiter||" ",full:e.full||!1}),qa=(e,t)=>{const r={};return e.algorithms.forEach(n=>{r[n]=_i(n).update(t,"utf8").digest("base64")}),r},Ka=(e,t)=>{let r="";return r+=Object.keys(t.hashes).map(n=>`${n}-${t.hashes[n]}`).join(e.delimiter),r},Va=(e,t)=>{const r=$a(e),n={hashes:qa(r,t),integrity:void 0};return n.integrity=Ka(r,n),r.full?n:n.integrity};class Nn extends nt.EventEmitter{constructor(t){let{url:r,target:n,features:i}=t;super(),P(this,"url",void 0),P(this,"target",void 0),P(this,"features",void 0),P(this,"window",void 0),P(this,"windowTimer",void 0),P(this,"iClosedWindow",void 0),this.url=r,this.target=n||"_blank",this.features=i||Ha(),this.window=void 0,this.windowTimer=void 0,this.iClosedWindow=!1,this._setupTimer()}_setupTimer(){this.windowTimer=Number(setInterval(()=>{this.window&&this.window.closed&&(clearInterval(this.windowTimer),this.iClosedWindow||this.emit("close"),this.iClosedWindow=!1,this.window=void 0),this.window===void 0&&clearInterval(this.windowTimer)},500))}open(){var t;return this.window=window.open(this.url.href,this.target,this.features),(t=this.window)!==null&&t!==void 0&&t.focus&&this.window.focus(),Promise.resolve()}close(){this.iClosedWindow=!0,this.window&&this.window.close()}redirect(t){t?window.location.replace(this.url.href):window.location.href=this.url.href}}function kn(e){return new Promise((t,r)=>{try{const n=document.createElement("img");n.onload=()=>t(!0),n.onerror=()=>t(!1),n.src=e}catch(n){r(n)}})}const Ga=e=>{const{document:t}=e,r=t.querySelector('head > meta[property="og:site_name"]');if(r)return r.content;const n=t.querySelector('head > meta[name="title"]');return n?n.content:t.title&&t.title.length>0?t.title:e.location.hostname};async function za(e){const{document:t}=e;let r=t.querySelector('head > link[rel="shortcut icon"]');return r&&await kn(r.href)||(r=Array.from(t.querySelectorAll('head > link[rel="icon"]')).find(n=>Boolean(n.href)),r&&await kn(r.href))?r.href:null}const Ya=async()=>({name:Ga(window),icon:await za(window)});async function Xa(e){try{const t=await Ya();e.handle({jsonrpc:"2.0",id:Oe(),method:"wallet_sendDomainMetadata",params:t},gi)}catch(t){W.error({message:ae.errors.sendSiteMetadata(),originalError:t})}}const Ja=["host","chainId","networkName"];function Bn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function Za(e){for(var t=1;t"u")return;const t=document.createElement("link"),{torusUrl:r}=await pi("production",{check:!1,hash:yi,version:""});t.href=`${r}/popup`,t.crossOrigin="anonymous",t.type="text/html",t.rel="prefetch",t.relList&&t.relList.supports&&t.relList.supports("prefetch")&&document.head.appendChild(t)}catch(t){W.warn(t)}})();class ns{constructor(){let{buttonPosition:t=Le.BOTTOM_LEFT,buttonSize:r=56,modalZIndex:n=99999,apiKey:i="torus-default"}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};P(this,"buttonPosition",Le.BOTTOM_LEFT),P(this,"buttonSize",void 0),P(this,"torusUrl",void 0),P(this,"torusIframe",void 0),P(this,"styleLink",void 0),P(this,"isLoggedIn",void 0),P(this,"isInitialized",void 0),P(this,"torusWidgetVisibility",void 0),P(this,"torusAlert",void 0),P(this,"apiKey",void 0),P(this,"modalZIndex",void 0),P(this,"alertZIndex",void 0),P(this,"torusAlertContainer",void 0),P(this,"isIframeFullScreen",void 0),P(this,"whiteLabel",void 0),P(this,"requestedVerifier",void 0),P(this,"currentVerifier",void 0),P(this,"embedTranslations",void 0),P(this,"ethereum",void 0),P(this,"provider",void 0),P(this,"communicationMux",void 0),P(this,"isLoginCallback",void 0),P(this,"paymentProviders",le.paymentProviders),P(this,"loginHint",""),P(this,"useWalletConnect",void 0),P(this,"isCustomLogin",!1),this.buttonPosition=t,this.buttonSize=r,this.torusUrl="",this.isLoggedIn=!1,this.isInitialized=!1,this.torusWidgetVisibility=!0,this.requestedVerifier="",this.currentVerifier="",this.apiKey=i,Ai(i),this.modalZIndex=n,this.alertZIndex=n+1e3,this.isIframeFullScreen=!1}async init(){let{buildEnv:t=Ta.PRODUCTION,enableLogging:r=!1,enabledVerifiers:n=Qa,network:i={host:"mainnet",chainId:null,networkName:"",blockExplorer:"",ticker:"",tickerName:""},loginConfig:o={},showTorusButton:a=!0,integrity:c={check:!1,hash:yi,version:""},whiteLabel:d,skipTKey:m=!1,useWalletConnect:y=!1,mfaLevel:p="default"}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.isInitialized)throw new Error("Already initialized");const{torusUrl:h,logLevel:b}=await pi(t,c);W.info(h,"url loaded"),this.torusUrl=h,this.whiteLabel=d,this.useWalletConnect=y,this.isCustomLogin=!!(o&&Object.keys(o).length>0)||!!(d&&Object.keys(d).length>0),W.setDefaultLevel(b),r?W.enableAll():W.disableAll(),this.torusWidgetVisibility=a;const O=new URL(h);O.pathname.endsWith("/")?O.pathname+="popup":O.pathname+="/popup",O.hash=`#isCustomLogin=${this.isCustomLogin}`,this.torusIframe=Je(``),this.torusAlertContainer=Je('
'),this.torusAlertContainer.style.display="none",this.torusAlertContainer.style.setProperty("z-index",this.alertZIndex.toString());const _=window.document.createElement("link");_.setAttribute("rel","stylesheet"),_.setAttribute("type","text/css"),_.setAttribute("href",`${h}/css/widget.css`),this.styleLink=_;const{defaultLanguage:T=Tn(),customTranslations:A={}}=this.whiteLabel||{},U=jn(le.translations,A)[T]||le.translations[Tn()];this.embedTranslations=U.embed;const k=async()=>(await Ba(),new Promise((q,j)=>{this.torusIframe.onload=async()=>{this._setupWeb3();const V=this.communicationMux.getStream("init_stream");V.on("data",X=>{const{name:L,data:G,error:H}=X;L==="init_complete"&&G.success?(this.isInitialized=!0,this._displayIframe(this.isIframeFullScreen),q(void 0)):H&&j(new Error(H))}),V.write({name:"init_stream",data:{enabledVerifiers:n,loginConfig:o,whiteLabel:this.whiteLabel,buttonPosition:this.buttonPosition,buttonSize:this.buttonSize,torusWidgetVisibility:this.torusWidgetVisibility,apiKey:this.apiKey,skipTKey:m,network:i,mfaLevel:p}})},window.document.head.appendChild(this.styleLink),window.document.body.appendChild(this.torusIframe),window.document.body.appendChild(this.torusAlertContainer)}));if(t==="production"&&c.check){const q=`${h}/popup`,j=await fetch(q,{cache:"reload"});if(j.headers.get("Cache-Control")!==es)throw new Error(`Unexpected Cache-Control headers, got ${j.headers.get("Cache-Control")}`);const V=await j.text(),X=Va({algorithms:["sha384"]},V);if(W.info(X,"integrity"),X===c.hash)await k();else throw this.clearInit(),new Error("Integrity check failed")}else await k()}login(){let{verifier:t="",login_hint:r=""}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this.isInitialized)throw new Error("Call init() first");return this.requestedVerifier=t,this.loginHint=r,this.ethereum.enable()}logout(){return new Promise((t,r)=>{if(!this.isLoggedIn){r(new Error("User has not logged in yet"));return}this.communicationMux.getStream("logout").write({name:"logOut"});const i=this.communicationMux.getStream("status");ue(i,"data",a=>{a.loggedIn?r(new Error("Some Error Occured")):(this.isLoggedIn=!1,this.currentVerifier="",this.requestedVerifier="",t())})})}async cleanUp(){this.isLoggedIn&&await this.logout(),this.clearInit()}clearInit(){function t(r){return r instanceof Element||r instanceof HTMLDocument}t(this.styleLink)&&window.document.body.contains(this.styleLink)&&(this.styleLink.remove(),this.styleLink=void 0),t(this.torusIframe)&&window.document.body.contains(this.torusIframe)&&(this.torusIframe.remove(),this.torusIframe=void 0),t(this.torusAlertContainer)&&window.document.body.contains(this.torusAlertContainer)&&(this.torusAlert=void 0,this.torusAlertContainer.remove(),this.torusAlertContainer=void 0),this.isInitialized=!1}hideTorusButton(){this.torusWidgetVisibility=!1,this._sendWidgetVisibilityStatus(!1),this._displayIframe()}showTorusButton(){this.torusWidgetVisibility=!0,this._sendWidgetVisibilityStatus(!0),this._displayIframe()}setProvider(t){let{host:r="mainnet",chainId:n=null,networkName:i=""}=t,o=Ei(t,Ja);return new Promise((a,c)=>{const d=this.communicationMux.getStream("provider_change");ue(d,"data",p=>{const{err:h,success:b}=p.data;W.info(p),h?c(h):b?a():c(new Error("some error occured"))});const y=Oe();this._handleWindow(y,{target:"_blank",features:Mn}),d.write({name:"show_provider_change",data:{network:Za({host:r,chainId:n,networkName:i},o),preopenInstanceId:y,override:!1}})})}showWallet(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const n=this.communicationMux.getStream("show_wallet"),i=t?`/${t}`:"";n.write({name:"show_wallet",data:{path:i}}),ue(n,"data",a=>{if(a.name==="show_wallet_instance"){const{instanceId:c}=a.data,d=new URL(`${this.torusUrl}/wallet${i}`);d.searchParams.append("integrity","true"),d.searchParams.append("instanceId",c),Object.keys(r).forEach(y=>{d.searchParams.append(y,r[y])}),d.hash=`#isCustomLogin=${this.isCustomLogin}`,new Nn({url:d,features:Wa}).open()}})}async getPublicAddress(t){let{verifier:r,verifierId:n,isExtended:i=!1}=t;if(!le.supportedVerifierList.includes(r)||!Cn[r])throw new Error("Unsupported verifier");const o=r,a=Cn[r],c=new URL("https://api.tor.us/lookup/torus");return c.searchParams.append("verifier",a),c.searchParams.append("verifierId",n),c.searchParams.append("walletVerifier",o),c.searchParams.append("network","mainnet"),c.searchParams.append("isExtended",i.toString()),Hn(c.href,{headers:{"Content-Type":"application/json; charset=utf-8"}},{useAPIKey:!0})}getUserInfo(t){return new Promise((r,n)=>{if(this.isLoggedIn){const i=this.communicationMux.getStream("user_info_access");i.write({name:"user_info_access_request"}),ue(i,"data",a=>{const{name:c,data:{approved:d,payload:m,rejected:y,newRequest:p}}=a;if(c==="user_info_access_response"){if(d)r(m);else if(y)n(new Error("User rejected the request"));else if(p){const h=this.communicationMux.getStream("user_info");ue(h,"data",_=>{_.name==="user_info_response"&&(_.data.approved?r(_.data.payload):n(new Error("User rejected the request")))});const O=Oe();this._handleWindow(O,{target:"_blank",features:Mn}),h.write({name:"user_info_request",data:{message:t,preopenInstanceId:O}})}}})}else n(new Error("User has not logged in yet"))})}initiateTopup(t,r){return new Promise((n,i)=>{if(this.isInitialized){const{errors:o,isValid:a}=ja(t,r);if(!a){i(new Error(JSON.stringify(o)));return}const c=this.communicationMux.getStream("topup");ue(c,"data",y=>{y.name==="topup_response"&&(y.data.success?n(y.data.success):i(new Error(y.data.error)))});const m=Oe();this._handleWindow(m),c.write({name:"topup_request",data:{provider:t,params:r,preopenInstanceId:m}})}else i(new Error("Torus is not initialized yet"))})}async loginWithPrivateKey(t){const{privateKey:r,userInfo:n}=t;return new Promise((i,o)=>{if(this.isInitialized){if(Re.Buffer.from(r,"hex").length!==32){o(new Error("Invalid private key, Please provide a 32 byte valid secp25k1 private key"));return}const a=this.communicationMux.getStream("login_with_private_key");ue(a,"data",d=>{d.name==="login_with_private_key_response"&&(d.data.success?i(d.data.success):o(new Error(d.data.error)))}),a.write({name:"login_with_private_key_request",data:{privateKey:r,userInfo:n}})}else o(new Error("Torus is not initialized yet"))})}async showWalletConnectScanner(){if(!this.useWalletConnect)throw new Error("Set `useWalletConnect` as true in init function options to use wallet connect scanner");return new Promise((t,r)=>{if(this.isLoggedIn){const n=this.communicationMux.getStream("wallet_connect_stream");ue(n,"data",o=>{o.name==="wallet_connect_stream_res"&&(o.data.success?t(o.data.success):r(new Error(o.data.error)),this._displayIframe())}),n.write({name:"wallet_connect_stream_req"}),this._displayIframe(!0)}else r(new Error("User has not logged in yet"))})}_handleWindow(t){let{url:r,target:n,features:i}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(t){const o=this.communicationMux.getStream("window"),a=new URL(r||`${this.torusUrl}/redirect?preopenInstanceId=${t}`);a.hash?a.hash+=`&isCustomLogin=${this.isCustomLogin}`:a.hash=`#isCustomLogin=${this.isCustomLogin}`;const c=new Nn({url:a,target:n,features:i});if(c.open(),!c.window){this._createPopupBlockAlert(t,a.href);return}o.write({name:"opened_window",data:{preopenInstanceId:t}});const d=m=>{let{preopenInstanceId:y,close:p}=m;y===t&&p&&(c.close(),o.removeListener("data",d))};o.on("data",d),c.once("close",()=>{o.write({data:{preopenInstanceId:t,closed:!0}}),o.removeListener("data",d)})}}_setEmbedWhiteLabel(t){const{theme:r}=this.whiteLabel||{};if(r){const{isDark:n=!1,colors:i={}}=r;n&&t.classList.add("torus-dark"),i.torusBrand1&&t.style.setProperty("--torus-brand-1",i.torusBrand1),i.torusGray2&&t.style.setProperty("--torus-gray-2",i.torusGray2)}}_getLogoUrl(){var t,r;let n=`${this.torusUrl}/images/torus_icon-blue.svg`;if((t=this.whiteLabel)!==null&&t!==void 0&&(r=t.theme)!==null&&r!==void 0&&r.isDark){var i;n=((i=this.whiteLabel)===null||i===void 0?void 0:i.logoLight)||n}else{var o;n=((o=this.whiteLabel)===null||o===void 0?void 0:o.logoDark)||n}return n}_sendWidgetVisibilityStatus(t){this.communicationMux.getStream("torus-widget-visibility").write({data:t})}_displayIframe(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;const r={},n=this.buttonSize+14;if(t)r.display="block",r.width="100%",r.height="100%",r.top="0px",r.right="0px",r.left="0px",r.bottom="0px";else switch(r.display=this.torusWidgetVisibility?"block":"none",r.height=`${n}px`,r.width=`${n}px`,this.buttonPosition){case Le.TOP_LEFT:r.top="0px",r.left="0px",r.right="auto",r.bottom="auto";break;case Le.TOP_RIGHT:r.top="0px",r.right="0px",r.left="auto",r.bottom="auto";break;case Le.BOTTOM_RIGHT:r.bottom="0px",r.right="0px",r.top="auto",r.left="auto";break;case Le.BOTTOM_LEFT:default:r.bottom="0px",r.left="0px",r.top="auto",r.right="auto";break}Object.assign(this.torusIframe.style,r),this.isIframeFullScreen=t}_setupWeb3(){W.info("setupWeb3 running");const t=new un({name:"embed_metamask",target:"iframe_metamask",targetWindow:this.torusIframe.contentWindow,targetOrigin:new URL(this.torusUrl).origin}),r=new un({name:"embed_comm",target:"iframe_comm",targetWindow:this.torusIframe.contentWindow,targetOrigin:new URL(this.torusUrl).origin}),n=new At(t),i=y=>{const p=n[y];n[y]=function(b){if(b&&b==="eth_requestAccounts")return n.enable();for(var O=arguments.length,_=new Array(O>1?O-1:0),T=1;Tnew Promise((y,p)=>{n.sendAsync({jsonrpc:"2.0",id:Oe(),method:"eth_requestAccounts",params:[]},(h,b)=>{const{result:O}=b||{};if(h)setTimeout(()=>{p(h)},50);else if(Array.isArray(O)&&O.length>0){const _=()=>{if(this.requestedVerifier!==""&&this.currentVerifier!==this.requestedVerifier){const{requestedVerifier:T}=this;this.logout().then(A=>{this.requestedVerifier=T,this._showLoginPopup(!0,y,p)}).catch(A=>p(A))}else y(O)};this.isLoggedIn?_():this.isLoginCallback=_}else this._showLoginPopup(!0,y,p)})}),n.tryPreopenHandle=(y,p)=>{const h=y;if(!Array.isArray(h)&&ts.includes(h.method)){const b=Oe();this._handleWindow(b,{target:"_blank",features:In}),h.preopenInstanceId=b}n._rpcEngine.handle(h,p)};const o=new Proxy(n,{deleteProperty:()=>!0});this.ethereum=o;const a=No(r);this.communicationMux=a,a.getStream("window").on("data",y=>{y.name==="create_window"&&this._createPopupBlockAlert(y.data.preopenInstanceId,y.data.url)}),a.getStream("widget").on("data",y=>{const{data:p}=y;this._displayIframe(p)}),a.getStream("status").on("data",y=>{y.loggedIn?(this.isLoggedIn=y.loggedIn,this.currentVerifier=y.verifier):this._displayIframe(),this.isLoginCallback&&(this.isLoginCallback(),delete this.isLoginCallback)}),this.provider=o,this.provider.shouldSendMetadata&&Xa(this.provider._rpcEngine),n._initializeState(),W.debug("Torus - injected provider")}_showLoginPopup(t,r,n){const i=a=>{const{err:c,selectedAddress:d}=a;c?(W.error(c),n&&n(c)):r&&r([d]),this.isIframeFullScreen&&this._displayIframe()},o=this.communicationMux.getStream("oauth");if(!this.requestedVerifier)this._displayIframe(!0),ue(o,"data",i),o.write({name:"oauth_modal",data:{calledFromEmbed:t}});else{ue(o,"data",i);const a=Oe();this._handleWindow(a),o.write({name:"oauth",data:{calledFromEmbed:t,verifier:this.requestedVerifier,preopenInstanceId:a,login_hint:this.loginHint}})}}_createPopupBlockAlert(t,r){const n=this._getLogoUrl(),i=Je(`

${this.embedTranslations.actionRequired}

${this.embedTranslations.pendingAction}

`),o=Je(``),a=Je('
');a.appendChild(o),i.appendChild(a);const c=()=>{o.addEventListener("click",()=>{this._handleWindow(t,{url:r,target:"_blank",features:In}),i.remove(),this.torusAlertContainer.children.length===0&&(this.torusAlertContainer.style.display="none")})};this._setEmbedWhiteLabel(i),Rn(()=>{this.torusAlertContainer.style.display="block",this.torusAlertContainer.appendChild(i)}),Rn(c)}}export{Le as BUTTON_POSITION,Xe as LOGIN_PROVIDER,$ as PAYMENT_PROVIDER,Y as SUPPORTED_PAYMENT_NETWORK,Ta as TORUS_BUILD_ENV,At as TorusInpageProvider,Cn as WALLET_OPENLOGIN_VERIFIER_MAP,Ee as WALLET_VERIFIERS,ns as default};