UNPKG

ethwrapper

Version:

♻️ Utility class to wrap/unwrap ETH on compatible networks

1 lines 306 kB
(function(_,K){typeof exports=="object"&&typeof module<"u"?module.exports=K():typeof define=="function"&&define.amd?define(K):(_=typeof globalThis<"u"?globalThis:_||self,_.ethwrapper=K())})(this,function(){var ts,jn,yn,ns,rs,it,Mt,ss,is,ae,Be,Gt,Zn,Xn,qn,wt,Ht,er,Wi,Ei,Ii,Ni,at,as,tr,ct,Q,Ne,_t,kr,ot,en,Ti,I0,Ci,N0,ki,T0,Pi,C0,wn,Kt,nr,cs,tc,Le,Ve,Ja,pu,os,fs,ls,rr,zt,ir,Qt,us,ds,xs,hs,bs,ps,gs,ys,ms,ws,As,Ri,Jt,Es,Ya,gu,le,lt,Si,k0,Is,rc,En,Ks,At,Et,It,be,vi,P0,Bi,O0,Yt,Li,In,Ts,Ui,Fi,Np,Nn,ar,cr,ji,Za,yu,Cs,ks,Tn,$t,Ye,Cn,Nt,Os,sc,or,fr,kn,Xa,Rs,Wt,Ss,vs,Pn,$e,qa,mu,pe,On,ge,Ue,lr,Rn,jt,Mi,We,Bs,Pe,Ze,Gi,R0,Hi,S0,ur,Zi,ec,wu,dr,Xi,Ls,ic,Us,ac,Oe,Zt,xr,Sn,hr,Fs,_i,v0,Ki,B0,br,pr,Ds,gr,yr,ut,Xt,zi,L0,vn,Ms,Gs,Hs,Vi,mr,Qi,U0,Ji,F0,wr,qi,Yi,D0;"use strict";var Tp=Object.defineProperty;var Cp=(_,K,F)=>K in _?Tp(_,K,{enumerable:!0,configurable:!0,writable:!0,value:F}):_[K]=F;var p=(_,K,F)=>(Cp(_,typeof K!="symbol"?K+"":K,F),F),E0=(_,K,F)=>{if(!K.has(_))throw TypeError("Cannot "+F)};var f=(_,K,F)=>(E0(_,K,"read from private field"),F?F.call(_):K.get(_)),y=(_,K,F)=>{if(K.has(_))throw TypeError("Cannot add the same private member more than once");K instanceof WeakSet?K.add(_):K.set(_,F)},x=(_,K,F,P)=>(E0(_,K,"write to private field"),P?P.call(_,F):K.set(_,F),F),$i=(_,K,F,P)=>({set _(tn){x(_,K,tn,F)},get _(){return f(_,K,P)}}),E=(_,K,F)=>(E0(_,K,"access private method"),F);const _="6.0.2";function K(r,e,t){const n=e.split("|").map(i=>i.trim());for(let i=0;i<n.length;i++)switch(e){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof r===e)return}const s=new Error(`invalid value for type ${e}`);throw s.code="INVALID_ARGUMENT",s.argument=`value.${t}`,s.value=r,s}async function F(r){const e=Object.keys(r);return(await Promise.all(e.map(n=>Promise.resolve(r[n])))).reduce((n,s,i)=>(n[e[i]]=s,n),{})}function P(r,e,t){for(let n in e){let s=e[n];const i=t?t[n]:null;i&&K(s,i,n),Object.defineProperty(r,n,{enumerable:!0,value:s,writable:!1})}}function tn(r){if(r==null)return"null";if(Array.isArray(r))return"[ "+r.map(tn).join(", ")+" ]";if(r instanceof Uint8Array){const e="0123456789abcdef";let t="0x";for(let n=0;n<r.length;n++)t+=e[r[n]>>4],t+=e[r[n]&15];return t}if(typeof r=="object"&&typeof r.toJSON=="function")return tn(r.toJSON());switch(typeof r){case"boolean":case"symbol":return r.toString();case"bigint":return BigInt(r).toString();case"number":return r.toString();case"string":return JSON.stringify(r);case"object":{const e=Object.keys(r);return e.sort(),"{ "+e.map(t=>`${tn(t)}: ${tn(r[t])}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function Bn(r,e){return r&&r.code===e}function cc(r){return Bn(r,"CALL_EXCEPTION")}function Re(r,e,t){{const s=[];if(t){if("message"in t||"code"in t||"name"in t)throw new Error(`value will overwrite populated values: ${tn(t)}`);for(const i in t){const a=t[i];s.push(i+"="+tn(a))}}s.push(`code=${e}`),s.push(`version=${_}`),s.length&&(r+=" ("+s.join(", ")+")")}let n;switch(e){case"INVALID_ARGUMENT":n=new TypeError(r);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":n=new RangeError(r);break;default:n=new Error(r)}return P(n,{code:e}),t&&P(n,t),n}function m(r,e,t,n){if(!r)throw Re(e,t,n)}function h(r,e,t,n){m(r,e,"INVALID_ARGUMENT",{argument:t,value:n})}function M0(r,e,t){t==null&&(t=""),t&&(t=": "+t),m(r>=e,"missing arguemnt"+t,"MISSING_ARGUMENT",{count:r,expectedCount:e}),m(r<=e,"too many arguemnts"+t,"UNEXPECTED_ARGUMENT",{count:r,expectedCount:e})}const Au=["NFD","NFC","NFKD","NFKC"].reduce((r,e)=>{try{if("test".normalize(e)!=="test")throw new Error("bad");if(e==="NFD"){const t=String.fromCharCode(233).normalize("NFD"),n=String.fromCharCode(101,769);if(t!==n)throw new Error("broken")}r.push(e)}catch{}return r},[]);function G0(r){m(Au.indexOf(r)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:r}})}function nn(r,e,t){if(t==null&&(t=""),r!==e){let n=t,s="new";t&&(n+=".",s+=" "+t),m(!1,`private constructor; use ${n}from* methods`,"UNSUPPORTED_OPERATION",{operation:s})}}function H0(r,e,t){if(r instanceof Uint8Array)return t?new Uint8Array(r):r;if(typeof r=="string"&&r.match(/^0x([0-9a-f][0-9a-f])*$/i)){const n=new Uint8Array((r.length-2)/2);let s=2;for(let i=0;i<n.length;i++)n[i]=parseInt(r.substring(s,s+2),16),s+=2;return n}h(!1,"invalid BytesLike value",e||"value",r)}function T(r,e){return H0(r,e,!1)}function de(r,e){return H0(r,e,!0)}function ne(r,e){return!(typeof r!="string"||!r.match(/^0x[0-9A-Fa-f]*$/)||typeof e=="number"&&r.length!==2+2*e||e===!0&&r.length%2!==0)}function _0(r){return ne(r,!0)||r instanceof Uint8Array}const K0="0123456789abcdef";function N(r){const e=T(r);let t="0x";for(let n=0;n<e.length;n++){const s=e[n];t+=K0[(s&240)>>4]+K0[s&15]}return t}function Y(r){return"0x"+r.map(e=>N(e).substring(2)).join("")}function Pr(r){return ne(r,!0)?(r.length-2)/2:T(r).length}function j(r,e,t){const n=T(r);return t!=null&&t>n.length&&m(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:n,length:n.length,offset:t}),N(n.slice(e??0,t??n.length))}function Eu(r,e,t){const n=T(r);m(e>=n.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(n),length:e,offset:e+1});const s=new Uint8Array(e);return s.fill(0),t?s.set(n,e-n.length):s.set(n,0),N(s)}function Ln(r,e){return Eu(r,e,!0)}const ea=BigInt(0),Xe=BigInt(1),Or=9007199254740991;function ta(r,e){const t=na(r,"value"),n=BigInt(U(e,"width"));if(m(t>>n===ea,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:r}),t>>n-Xe){const s=(Xe<<n)-Xe;return-((~t&s)+Xe)}return t}function z0(r,e){let t=S(r,"value");const n=BigInt(U(e,"width")),s=Xe<<n-Xe;if(t<ea){t=-t,m(t<=s,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:r});const i=(Xe<<n)-Xe;return(~t&i)+Xe}else m(t<s,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:r});return t}function Un(r,e){const t=na(r,"value"),n=BigInt(U(e,"bits"));return t&(Xe<<n)-Xe}function S(r,e){switch(typeof r){case"bigint":return r;case"number":return h(Number.isInteger(r),"underflow",e||"value",r),h(r>=-Or&&r<=Or,"overflow",e||"value",r),BigInt(r);case"string":try{if(r==="")throw new Error("empty string");return r[0]==="-"&&r[1]!=="-"?-BigInt(r.substring(1)):BigInt(r)}catch(t){h(!1,`invalid BigNumberish string: ${t.message}`,e||"value",r)}}h(!1,"invalid BigNumberish value",e||"value",r)}function na(r,e){const t=S(r,e);return m(t>=ea,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:r}),t}const V0="0123456789abcdef";function zs(r){if(r instanceof Uint8Array){let e="0x0";for(const t of r)e+=V0[t>>4],e+=V0[t&15];return BigInt(e)}return S(r)}function U(r,e){switch(typeof r){case"bigint":return h(r>=-Or&&r<=Or,"overflow",e||"value",r),Number(r);case"number":return h(Number.isInteger(r),"underflow",e||"value",r),h(r>=-Or&&r<=Or,"overflow",e||"value",r),r;case"string":try{if(r==="")throw new Error("empty string");return U(BigInt(r),e)}catch(t){h(!1,`invalid numeric string: ${t.message}`,e||"value",r)}}h(!1,"invalid numeric value",e||"value",r)}function Iu(r){return U(zs(r))}function kt(r,e){let n=na(r,"value").toString(16);if(e==null)n.length%2&&(n="0"+n);else{const s=U(e,"width");for(m(s*2>=n.length,`value exceeds width (${s} bits)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:r});n.length<s*2;)n="0"+n}return"0x"+n}function Te(r){const e=na(r,"value");if(e===ea)return new Uint8Array([]);let t=e.toString(16);t.length%2&&(t="0"+t);const n=new Uint8Array(t.length/2);for(let s=0;s<n.length;s++){const i=s*2;n[s]=parseInt(t.substring(i,i+2),16)}return n}function Vs(r){let e=N(_0(r)?r:Te(r)).substring(2);for(;e.substring(0,1)==="0";)e=e.substring(1);return e===""&&(e="0"),"0x"+e}const oc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";let ra=null;function Nu(r){if(ra==null){ra={};for(let t=0;t<oc.length;t++)ra[oc[t]]=BigInt(t)}const e=ra[r];return h(e!=null,"invalid base58 value","letter",r),e}const Tu=BigInt(0),fc=BigInt(58);function Q0(r){let e=zs(T(r)),t="";for(;e;)t=oc[Number(e%fc)]+t,e/=fc;return t}function Cu(r){let e=Tu;for(let t=0;t<r.length;t++)e*=fc,e+=Nu(r[t]);return e}function ku(r){r=atob(r);const e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return T(e)}function Pu(r){const e=T(r);let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}class J0{constructor(e,t,n){p(this,"filter");p(this,"emitter");y(this,ts,void 0);x(this,ts,t),P(this,{emitter:e,filter:n})}async removeListener(){f(this,ts)!=null&&await this.emitter.off(this.filter,f(this,ts))}}ts=new WeakMap;function Ou(r,e,t,n,s){h(!1,`invalid codepoint at offset ${e}; ${r}`,"bytes",t)}function Y0(r,e,t,n,s){if(r==="BAD_PREFIX"||r==="UNEXPECTED_CONTINUE"){let i=0;for(let a=e+1;a<t.length&&t[a]>>6===2;a++)i++;return i}return r==="OVERRUN"?t.length-e-1:0}function Ru(r,e,t,n,s){return r==="OVERLONG"?(h(typeof s=="number","invalid bad code point for replacement","badCodepoint",s),n.push(s),0):(n.push(65533),Y0(r,e,t))}const Su=Object.freeze({error:Ou,ignore:Y0,replace:Ru});function vu(r,e){e==null&&(e=Su.error);const t=T(r,"bytes"),n=[];let s=0;for(;s<t.length;){const i=t[s++];if(!(i>>7)){n.push(i);continue}let a=null,c=null;if((i&224)===192)a=1,c=127;else if((i&240)===224)a=2,c=2047;else if((i&248)===240)a=3,c=65535;else{(i&192)===128?s+=e("UNEXPECTED_CONTINUE",s-1,t,n):s+=e("BAD_PREFIX",s-1,t,n);continue}if(s-1+a>=t.length){s+=e("OVERRUN",s-1,t,n);continue}let o=i&(1<<8-a-1)-1;for(let l=0;l<a;l++){let u=t[s];if((u&192)!=128){s+=e("MISSING_CONTINUE",s,t,n),o=null;break}o=o<<6|u&63,s++}if(o!==null){if(o>1114111){s+=e("OUT_OF_RANGE",s-1-a,t,n,o);continue}if(o>=55296&&o<=57343){s+=e("UTF16_SURROGATE",s-1-a,t,n,o);continue}if(o<=c){s+=e("OVERLONG",s-1-a,t,n,o);continue}n.push(o)}}return n}function me(r,e){e!=null&&(G0(e),r=r.normalize(e));let t=[];for(let n=0;n<r.length;n++){const s=r.charCodeAt(n);if(s<128)t.push(s);else if(s<2048)t.push(s>>6|192),t.push(s&63|128);else if((s&64512)==55296){n++;const i=r.charCodeAt(n);h(n<r.length&&(i&64512)===56320,"invalid surrogate pair","str",r);const a=65536+((s&1023)<<10)+(i&1023);t.push(a>>18|240),t.push(a>>12&63|128),t.push(a>>6&63|128),t.push(a&63|128)}else t.push(s>>12|224),t.push(s>>6&63|128),t.push(s&63|128)}return new Uint8Array(t)}function Bu(r){return r.map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10&1023)+55296,(e&1023)+56320))).join("")}function lc(r,e){return Bu(vu(r,e))}async function Lu(r,e){const t=r.url.split(":")[0].toLowerCase();m(t==="http"||t==="https",`unsupported protocol ${t}`,"UNSUPPORTED_OPERATION",{info:{protocol:t},operation:"request"}),m(!r.credentials||r.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let n;if(e){const l=new AbortController;n=l.signal,e.addListener(()=>{l.abort()})}const s={method:r.method,headers:new Headers(Array.from(r)),body:r.body||void 0,signal:n},i=await fetch(r.url,s),a={};i.headers.forEach((l,u)=>{a[u.toLowerCase()]=l});const c=await i.arrayBuffer(),o=c==null?null:new Uint8Array(c);return{statusCode:i.status,statusMessage:i.statusText,headers:a,body:o}}const Uu=12,Fu=250;let $0=Lu;const Du=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),Mu=new RegExp("^ipfs://(ipfs/)?(.*)$","i");let uc=!1;async function W0(r,e){try{const t=r.match(Du);if(!t)throw new Error("invalid data");return new sn(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?ku(t[3]):Hu(t[3]))}catch{return new sn(599,"BAD REQUEST (invalid data: URI)",{},null,new rn(r))}}function j0(r){async function e(t,n){try{const s=t.match(Mu);if(!s)throw new Error("invalid link");return new rn(`${r}${s[2]}`)}catch{return new sn(599,"BAD REQUEST (invalid IPFS URI)",{},null,new rn(t))}}return e}const sa={data:W0,ipfs:j0("https://gateway.ipfs.io/ipfs/")},Z0=new WeakMap;class Gu{constructor(e){y(this,jn,void 0);y(this,yn,void 0);x(this,jn,[]),x(this,yn,!1),Z0.set(e,()=>{if(!f(this,yn)){x(this,yn,!0);for(const t of f(this,jn))setTimeout(()=>{t()},0);x(this,jn,[])}})}addListener(e){m(!f(this,yn),"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),f(this,jn).push(e)}get cancelled(){return f(this,yn)}checkSignal(){m(!this.cancelled,"cancelled","CANCELLED",{})}}jn=new WeakMap,yn=new WeakMap;function ia(r){if(r==null)throw new Error("missing signal; should not happen");return r.checkSignal(),r}const Qa=class{constructor(e){y(this,er);y(this,ns,void 0);y(this,rs,void 0);y(this,it,void 0);y(this,Mt,void 0);y(this,ss,void 0);y(this,is,void 0);y(this,ae,void 0);y(this,Be,void 0);y(this,Gt,void 0);y(this,Zn,void 0);y(this,Xn,void 0);y(this,qn,void 0);y(this,wt,void 0);y(this,Ht,void 0);x(this,is,String(e)),x(this,ns,!1),x(this,rs,!0),x(this,it,{}),x(this,Mt,""),x(this,ss,3e5),x(this,Ht,{slotInterval:Fu,maxAttempts:Uu})}get url(){return f(this,is)}set url(e){x(this,is,String(e))}get body(){return f(this,ae)==null?null:new Uint8Array(f(this,ae))}set body(e){if(e==null)x(this,ae,void 0),x(this,Be,void 0);else if(typeof e=="string")x(this,ae,me(e)),x(this,Be,"text/plain");else if(e instanceof Uint8Array)x(this,ae,e),x(this,Be,"application/octet-stream");else if(typeof e=="object")x(this,ae,me(JSON.stringify(e))),x(this,Be,"application/json");else throw new Error("invalid body")}hasBody(){return f(this,ae)!=null}get method(){return f(this,Mt)?f(this,Mt):this.hasBody()?"POST":"GET"}set method(e){e==null&&(e=""),x(this,Mt,String(e).toUpperCase())}get headers(){const e=Object.assign({},f(this,it));return f(this,Gt)&&(e.authorization=`Basic ${Pu(me(f(this,Gt)))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),e["content-type"]==null&&f(this,Be)&&(e["content-type"]=f(this,Be)),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){f(this,it)[String(e).toLowerCase()]=String(t)}clearHeaders(){x(this,it,{})}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const s=t[n++];return{value:[s,e[s]],done:!1}}return{value:void 0,done:!0}}}}get credentials(){return f(this,Gt)||null}setCredentials(e,t){h(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),x(this,Gt,`${e}:${t}`)}get allowGzip(){return f(this,rs)}set allowGzip(e){x(this,rs,!!e)}get allowInsecureAuthentication(){return!!f(this,ns)}set allowInsecureAuthentication(e){x(this,ns,!!e)}get timeout(){return f(this,ss)}set timeout(e){h(e>=0,"timeout must be non-zero","timeout",e),x(this,ss,e)}get preflightFunc(){return f(this,Zn)||null}set preflightFunc(e){x(this,Zn,e)}get processFunc(){return f(this,Xn)||null}set processFunc(e){x(this,Xn,e)}get retryFunc(){return f(this,qn)||null}set retryFunc(e){x(this,qn,e)}toString(){return`<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${f(this,ae)?N(f(this,ae)):"null"}>`}setThrottleParams(e){e.slotInterval!=null&&(f(this,Ht).slotInterval=e.slotInterval),e.maxAttempts!=null&&(f(this,Ht).maxAttempts=e.maxAttempts)}send(){return m(f(this,wt)==null,"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),x(this,wt,new Gu(this)),E(this,er,Wi).call(this,0,X0()+this.timeout,0,this,new sn(0,"",{},null,this))}cancel(){m(f(this,wt)!=null,"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});const e=Z0.get(this);if(!e)throw new Error("missing signal; should not happen");e()}redirect(e){const t=this.url.split(":")[0].toLowerCase(),n=e.split(":")[0].toLowerCase();m(this.method==="GET"&&(t!=="https"||n!=="http")&&e.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`});const s=new Qa(e);return s.method="GET",s.allowGzip=this.allowGzip,s.timeout=this.timeout,x(s,it,Object.assign({},f(this,it))),f(this,ae)&&x(s,ae,new Uint8Array(f(this,ae))),x(s,Be,f(this,Be)),s}clone(){const e=new Qa(this.url);return x(e,Mt,f(this,Mt)),f(this,ae)&&x(e,ae,f(this,ae)),x(e,Be,f(this,Be)),x(e,it,Object.assign({},f(this,it))),x(e,Gt,f(this,Gt)),this.allowGzip&&(e.allowGzip=!0),e.timeout=this.timeout,this.allowInsecureAuthentication&&(e.allowInsecureAuthentication=!0),x(e,Zn,f(this,Zn)),x(e,Xn,f(this,Xn)),x(e,qn,f(this,qn)),e}static lockConfig(){uc=!0}static getGateway(e){return sa[e.toLowerCase()]||null}static registerGateway(e,t){if(e=e.toLowerCase(),e==="http"||e==="https")throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(uc)throw new Error("gateways locked");sa[e]=t}static registerGetUrl(e){if(uc)throw new Error("gateways locked");$0=e}static createDataGateway(){return W0}static createIpfsGatewayFunc(e){return j0(e)}};let rn=Qa;ns=new WeakMap,rs=new WeakMap,it=new WeakMap,Mt=new WeakMap,ss=new WeakMap,is=new WeakMap,ae=new WeakMap,Be=new WeakMap,Gt=new WeakMap,Zn=new WeakMap,Xn=new WeakMap,qn=new WeakMap,wt=new WeakMap,Ht=new WeakMap,er=new WeakSet,Wi=async function(e,t,n,s,i){var u,d,b;if(e>=f(this,Ht).maxAttempts)return i.makeServerError("exceeded maximum retry limit");m(X0()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:s}),n>0&&await _u(n);let a=this.clone();const c=(a.url.split(":")[0]||"").toLowerCase();if(c in sa){const g=await sa[c](a.url,ia(f(s,wt)));if(g instanceof sn){let A=g;if(this.processFunc){ia(f(s,wt));try{A=await this.processFunc(a,A)}catch(w){(w.throttle==null||typeof w.stall!="number")&&A.makeServerError("error in post-processing function",w).assertOk()}}return A}a=g}this.preflightFunc&&(a=await this.preflightFunc(a));const o=await $0(a,ia(f(s,wt)));let l=new sn(o.statusCode,o.statusMessage,o.headers,o.body,s);if(l.statusCode===301||l.statusCode===302){try{const g=l.headers.location||"";return E(u=a.redirect(g),er,Wi).call(u,e+1,t,0,s,l)}catch{}return l}else if(l.statusCode===429&&(this.retryFunc==null||await this.retryFunc(a,l,e))){const g=l.headers["retry-after"];let A=f(this,Ht).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return typeof g=="string"&&g.match(/^[1-9][0-9]*$/)&&(A=parseInt(g)),E(d=a.clone(),er,Wi).call(d,e+1,t,A,s,l)}if(this.processFunc){ia(f(s,wt));try{l=await this.processFunc(a,l)}catch(g){(g.throttle==null||typeof g.stall!="number")&&l.makeServerError("error in post-processing function",g).assertOk();let A=f(this,Ht).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return g.stall>=0&&(A=g.stall),E(b=a.clone(),er,Wi).call(b,e+1,t,A,s,l)}}return l};const g0=class{constructor(e,t,n,s,i){y(this,Ei,void 0);y(this,Ii,void 0);y(this,Ni,void 0);y(this,at,void 0);y(this,as,void 0);y(this,tr,void 0);x(this,Ei,e),x(this,Ii,t),x(this,Ni,Object.keys(n).reduce((a,c)=>(a[c.toLowerCase()]=String(n[c]),a),{})),x(this,at,s==null?null:new Uint8Array(s)),x(this,as,i||null),x(this,tr,{message:""})}toString(){return`<FetchResponse status=${this.statusCode} body=${f(this,at)?N(f(this,at)):"null"}>`}get statusCode(){return f(this,Ei)}get statusMessage(){return f(this,Ii)}get headers(){return Object.assign({},f(this,Ni))}get body(){return f(this,at)==null?null:new Uint8Array(f(this,at))}get bodyText(){try{return f(this,at)==null?"":lc(f(this,at))}catch{m(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}})}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch{m(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}})}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const s=t[n++];return{value:[s,e[s]],done:!1}}return{value:void 0,done:!0}}}}makeServerError(e,t){let n;e?n=`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})`:(e=`${this.statusCode} ${this.statusMessage}`,n=`CLIENT ESCALATED SERVER ERROR (${e})`);const s=new g0(599,n,this.headers,this.body,f(this,as)||void 0);return x(s,tr,{message:e,error:t}),s}throwThrottleError(e,t){t==null?t=-1:h(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);const n=new Error(e||"throttling requests");throw P(n,{stall:t,throttle:!0}),n}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return f(this,at)!=null}get request(){return f(this,as)}ok(){return f(this,tr).message===""&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=f(this,tr);e===""&&(e=`server response ${this.statusCode} ${this.statusMessage}`),m(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t})}};let sn=g0;Ei=new WeakMap,Ii=new WeakMap,Ni=new WeakMap,at=new WeakMap,as=new WeakMap,tr=new WeakMap;function X0(){return new Date().getTime()}function Hu(r){return me(r.replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16))))}function _u(r){return new Promise(e=>setTimeout(e,r))}const Ku=BigInt(-1),qe=BigInt(0),Rr=BigInt(1),zu=BigInt(5),Sr={};let vr="0000";for(;vr.length<80;)vr+=vr;function Fn(r){let e=vr;for(;e.length<r;)e+=e;return BigInt("1"+e.substring(0,r))}function Qs(r,e,t){const n=BigInt(e.width);if(e.signed){const s=Rr<<n-Rr;m(t==null||r>=-s&&r<s,"overflow","NUMERIC_FAULT",{operation:t,fault:"overflow",value:r}),r>qe?r=ta(Un(r,n),n):r=-ta(Un(-r,n),n)}else{const s=Rr<<n;m(t==null||r>=0&&r<s,"overflow","NUMERIC_FAULT",{operation:t,fault:"overflow",value:r}),r=(r%s+s)%s&s-Rr}return r}function dc(r){typeof r=="number"&&(r=`fixed128x${r}`);let e=!0,t=128,n=18;if(typeof r=="string"){if(r!=="fixed")if(r==="ufixed")e=!1;else{const i=r.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);h(i,"invalid fixed format","format",r),e=i[1]!=="u",t=parseInt(i[2]),n=parseInt(i[3])}}else if(r){const i=r,a=(c,o,l)=>i[c]==null?l:(h(typeof i[c]===o,"invalid fixed format ("+c+" not "+o+")","format."+c,i[c]),i[c]);e=a("signed","boolean",e),t=a("width","number",t),n=a("decimals","number",n)}h(t%8===0,"invalid FixedNumber width (not byte aligned)","format.width",t),h(n<=80,"invalid FixedNumber decimals (too large)","format.decimals",n);const s=(e?"":"u")+"fixed"+String(t)+"x"+String(n);return{signed:e,width:t,decimals:n,name:s}}function Vu(r,e){let t="";r<qe&&(t="-",r*=Ku);let n=r.toString();if(e===0)return t+n;for(;n.length<=e;)n=vr+n;const s=n.length-e;for(n=n.substring(0,s)+"."+n.substring(s);n[0]==="0"&&n[1]!==".";)n=n.substring(1);for(;n[n.length-1]==="0"&&n[n.length-2]!==".";)n=n.substring(0,n.length-1);return t+n}const mn=class{constructor(e,t,n){y(this,_t);y(this,ot);y(this,Ti);y(this,Ci);y(this,ki);y(this,Pi);p(this,"format");y(this,ct,void 0);y(this,Q,void 0);y(this,Ne,void 0);p(this,"_value");nn(e,Sr,"FixedNumber"),x(this,Q,t),x(this,ct,n);const s=Vu(t,n.decimals);P(this,{format:n.name,_value:s}),x(this,Ne,Fn(n.decimals))}get signed(){return f(this,ct).signed}get width(){return f(this,ct).width}get decimals(){return f(this,ct).decimals}get value(){return f(this,Q)}addUnsafe(e){return E(this,Ti,I0).call(this,e)}add(e){return E(this,Ti,I0).call(this,e,"add")}subUnsafe(e){return E(this,Ci,N0).call(this,e)}sub(e){return E(this,Ci,N0).call(this,e,"sub")}mulUnsafe(e){return E(this,ki,T0).call(this,e)}mul(e){return E(this,ki,T0).call(this,e,"mul")}mulSignal(e){E(this,_t,kr).call(this,e);const t=f(this,Q)*f(e,Q);return m(t%f(this,Ne)===qe,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),E(this,ot,en).call(this,t/f(this,Ne),"mulSignal")}divUnsafe(e){return E(this,Pi,C0).call(this,e)}div(e){return E(this,Pi,C0).call(this,e,"div")}divSignal(e){m(f(e,Q)!==qe,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),E(this,_t,kr).call(this,e);const t=f(this,Q)*f(this,Ne);return m(t%f(e,Q)===qe,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),E(this,ot,en).call(this,t/f(e,Q),"divSignal")}cmp(e){let t=this.value,n=e.value;const s=this.decimals-e.decimals;return s>0?n*=Fn(s):s<0&&(t*=Fn(-s)),t<n||t>n?-1:0}eq(e){return this.cmp(e)===0}lt(e){return this.cmp(e)<0}lte(e){return this.cmp(e)<=0}gt(e){return this.cmp(e)>0}gte(e){return this.cmp(e)>=0}floor(){let e=f(this,Q);return f(this,Q)<qe&&(e-=f(this,Ne)-Rr),e=f(this,Q)/f(this,Ne)*f(this,Ne),E(this,ot,en).call(this,e,"floor")}ceiling(){let e=f(this,Q);return f(this,Q)>qe&&(e+=f(this,Ne)-Rr),e=f(this,Q)/f(this,Ne)*f(this,Ne),E(this,ot,en).call(this,e,"ceiling")}round(e){if(e==null&&(e=0),e>=this.decimals)return this;const t=this.decimals-e,n=zu*Fn(t-1);let s=this.value+n;const i=Fn(t);return s=s/i*i,Qs(s,f(this,ct),"round"),new mn(Sr,s,f(this,ct))}isZero(){return f(this,Q)===qe}isNegative(){return f(this,Q)<qe}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(e){return mn.fromString(this.toString(),e)}static fromValue(e,t,n){t==null&&(t=0);const s=dc(n);let i=S(e,"value");const a=t-s.decimals;if(a>0){const c=Fn(a);m(i%c===qe,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:e}),i/=c}else a<0&&(i*=Fn(-a));return Qs(i,s,"fromValue"),new mn(Sr,i,s)}static fromString(e,t){const n=e.match(/^(-?)([0-9]*)\.?([0-9]*)$/);h(n&&n[2].length+n[3].length>0,"invalid FixedNumber string value","value",e);const s=dc(t);let i=n[2]||"0",a=n[3]||"";for(;a.length<s.decimals;)a+=vr;m(a.substring(s.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:e}),a=a.substring(0,s.decimals);const c=BigInt(n[1]+i+a);return Qs(c,s,"fromString"),new mn(Sr,c,s)}static fromBytes(e,t){let n=zs(T(e,"value"));const s=dc(t);return s.signed&&(n=ta(n,s.width)),Qs(n,s,"fromBytes"),new mn(Sr,n,s)}};let xc=mn;ct=new WeakMap,Q=new WeakMap,Ne=new WeakMap,_t=new WeakSet,kr=function(e){h(this.format===e.format,"incompatible format; use fixedNumber.toFormat","other",e)},ot=new WeakSet,en=function(e,t){return e=Qs(e,f(this,ct),t),new mn(Sr,e,f(this,ct))},Ti=new WeakSet,I0=function(e,t){return E(this,_t,kr).call(this,e),E(this,ot,en).call(this,f(this,Q)+f(e,Q),t)},Ci=new WeakSet,N0=function(e,t){return E(this,_t,kr).call(this,e),E(this,ot,en).call(this,f(this,Q)-f(e,Q),t)},ki=new WeakSet,T0=function(e,t){return E(this,_t,kr).call(this,e),E(this,ot,en).call(this,f(this,Q)*f(e,Q)/f(this,Ne),t)},Pi=new WeakSet,C0=function(e,t){return m(f(e,Q)!==qe,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),E(this,_t,kr).call(this,e),E(this,ot,en).call(this,f(this,Q)*f(this,Ne)/f(e,Q),t)};function Qu(r){let e=r.toString(16);for(;e.length<2;)e="0"+e;return"0x"+e}function q0(r,e,t){let n=0;for(let s=0;s<t;s++)n=n*256+r[e+s];return n}function eo(r,e,t,n){const s=[];for(;t<e+1+n;){const i=to(r,t);s.push(i.result),t+=i.consumed,m(t<=e+1+n,"child data too short","BUFFER_OVERRUN",{buffer:r,length:n,offset:e})}return{consumed:1+n,result:s}}function to(r,e){m(r.length!==0,"data too short","BUFFER_OVERRUN",{buffer:r,length:0,offset:1});const t=n=>{m(n<=r.length,"data short segment too short","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n})};if(r[e]>=248){const n=r[e]-247;t(e+1+n);const s=q0(r,e+1,n);return t(e+1+n+s),eo(r,e,e+1+n,n+s)}else if(r[e]>=192){const n=r[e]-192;return t(e+1+n),eo(r,e,e+1,n)}else if(r[e]>=184){const n=r[e]-183;t(e+1+n);const s=q0(r,e+1,n);t(e+1+n+s);const i=N(r.slice(e+1+n,e+1+n+s));return{consumed:1+n+s,result:i}}else if(r[e]>=128){const n=r[e]-128;t(e+1+n);const s=N(r.slice(e+1,e+1+n));return{consumed:1+n,result:s}}return{consumed:1,result:Qu(r[e])}}function hc(r){const e=T(r,"data"),t=to(e,0);return h(t.consumed===e.length,"unexpected junk after rlp payload","data",r),t.result}function no(r){const e=[];for(;r;)e.unshift(r&255),r>>=8;return e}function ro(r){if(Array.isArray(r)){let n=[];if(r.forEach(function(i){n=n.concat(ro(i))}),n.length<=55)return n.unshift(192+n.length),n;const s=no(n.length);return s.unshift(247+s.length),s.concat(n)}const e=Array.prototype.slice.call(T(r,"object"));if(e.length===1&&e[0]<=127)return e;if(e.length<=55)return e.unshift(128+e.length),e;const t=no(e.length);return t.unshift(183+t.length),t.concat(e)}const so="0123456789abcdef";function Js(r){let e="0x";for(const t of ro(r))e+=so[t>>4],e+=so[t&15];return e}const Ju=["wei","kwei","mwei","gwei","szabo","finney","ether"];function Yu(r,e){h(typeof r=="string","value must be a string","value",r);let t=18;if(typeof e=="string"){const n=Ju.indexOf(e);h(n>=0,"invalid unit","unit",e),t=3*n}else e!=null&&(t=U(e,"unit"));return xc.fromString(r,{decimals:t}).value}function io(r){return Yu(r,18)}function $u(r){const e=T(r,"randomBytes");e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=N(e);return[t.substring(2,10),t.substring(10,14),t.substring(14,18),t.substring(18,22),t.substring(22,34)].join("-")}const we=32,bc=new Uint8Array(we),Wu=["then"],aa={};function ca(r,e){const t=new Error(`deferred error during ABI decoding triggered accessing ${r}`);throw t.error=e,t}const Oi=class extends Array{constructor(...t){const n=t[0];let s=t[1],i=(t[2]||[]).slice(),a=!0;n!==aa&&(s=t,i=[],a=!1);super(s.length);y(this,wn,void 0);s.forEach((o,l)=>{this[l]=o});const c=i.reduce((o,l)=>(typeof l=="string"&&o.set(l,(o.get(l)||0)+1),o),new Map);if(x(this,wn,Object.freeze(s.map((o,l)=>{const u=i[l];return u!=null&&c.get(u)===1?u:null}))),!!a)return Object.freeze(this),new Proxy(this,{get:(o,l,u)=>{if(typeof l=="string"){if(l.match(/^[0-9]+$/)){const b=U(l,"%index");if(b<0||b>=this.length)throw new RangeError("out of result range");const g=o[b];return g instanceof Error&&ca(`index ${b}`,g),g}if(Wu.indexOf(l)>=0)return Reflect.get(o,l,u);const d=o[l];if(d instanceof Function)return function(...b){return d.apply(this===u?o:this,b)};if(!(l in o))return o.getValue.apply(this===u?o:this,[l])}return Reflect.get(o,l,u)}})}toArray(){return this.forEach((t,n)=>{t instanceof Error&&ca(`index ${n}`,t)}),Array.of(this)}toObject(){return f(this,wn).reduce((t,n,s)=>(m(n!=null,"value at index ${ index } unnamed","UNSUPPORTED_OPERATION",{operation:"toObject()"}),n in t||(t[n]=this.getValue(n)),t),{})}slice(t,n){t==null&&(t=0),n==null&&(n=this.length);const s=[],i=[];for(let a=t;a<n;a++)s.push(this[a]),i.push(f(this,wn)[a]);return new Oi(aa,s,i)}filter(t,n){const s=[],i=[];for(let a=0;a<this.length;a++){const c=this[a];c instanceof Error&&ca(`index ${a}`,c),t.call(n,c,a,this)&&(s.push(c),i.push(f(this,wn)[a]))}return new Oi(aa,s,i)}getValue(t){const n=f(this,wn).indexOf(t);if(n===-1)return;const s=this[n];return s instanceof Error&&ca(`property ${JSON.stringify(t)}`,s.error),s}static fromItems(t,n){return new Oi(aa,t,n)}};let oa=Oi;wn=new WeakMap;function ao(r){let e=Te(r);return m(e.length<=we,"value out-of-bounds","BUFFER_OVERRUN",{buffer:e,length:we,offset:e.length}),e.length!==we&&(e=de(Y([bc.slice(e.length%we),e]))),e}class Pt{constructor(e,t,n,s){p(this,"name");p(this,"type");p(this,"localName");p(this,"dynamic");P(this,{name:e,type:t,localName:n,dynamic:s},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(e,t){h(!1,e,this.localName,t)}}class pc{constructor(){y(this,cs);y(this,Kt,void 0);y(this,nr,void 0);x(this,Kt,[]),x(this,nr,0)}get data(){return Y(f(this,Kt))}get length(){return f(this,nr)}appendWriter(e){return E(this,cs,tc).call(this,de(e.data))}writeBytes(e){let t=de(e);const n=t.length%we;return n&&(t=de(Y([t,bc.slice(n)]))),E(this,cs,tc).call(this,t)}writeValue(e){return E(this,cs,tc).call(this,ao(e))}writeUpdatableValue(){const e=f(this,Kt).length;return f(this,Kt).push(bc),x(this,nr,f(this,nr)+we),t=>{f(this,Kt)[e]=ao(t)}}}Kt=new WeakMap,nr=new WeakMap,cs=new WeakSet,tc=function(e){return f(this,Kt).push(e),x(this,nr,f(this,nr)+e.length),e.length};const y0=class{constructor(e,t){y(this,Ja);p(this,"allowLoose");y(this,Le,void 0);y(this,Ve,void 0);P(this,{allowLoose:!!t}),x(this,Le,de(e)),x(this,Ve,0)}get data(){return N(f(this,Le))}get dataLength(){return f(this,Le).length}get consumed(){return f(this,Ve)}get bytes(){return new Uint8Array(f(this,Le))}subReader(e){return new y0(f(this,Le).slice(f(this,Ve)+e),this.allowLoose)}readBytes(e,t){let n=E(this,Ja,pu).call(this,0,e,!!t);return x(this,Ve,f(this,Ve)+n.length),n.slice(0,e)}readValue(){return zs(this.readBytes(we))}readIndex(){return Iu(this.readBytes(we))}};let gc=y0;Le=new WeakMap,Ve=new WeakMap,Ja=new WeakSet,pu=function(e,t,n){let s=Math.ceil(t/we)*we;return f(this,Ve)+s>f(this,Le).length&&(this.allowLoose&&n&&f(this,Ve)+t<=f(this,Le).length?s=t:m(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:de(f(this,Le)),length:f(this,Le).length,offset:f(this,Ve)+s})),f(this,Le).slice(f(this,Ve),f(this,Ve)+s)};function yc(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function ju(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function co(r,...e){if(!(r instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Zu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yc(r.outputLen),yc(r.blockLen)}function Xu(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function qu(r,e){co(r);const t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}const ee={number:yc,bool:ju,bytes:co,hash:Zu,exists:Xu,output:qu};/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fa=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),la=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ht=(r,e)=>r<<32-e|r>>>e;if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));const ed=async()=>{};async function oo(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);const i=Date.now()-n;i>=0&&i<e||(await ed(),n+=i)}}function td(r){if(typeof r!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof r}`);return new TextEncoder().encode(r)}function Dn(r){if(typeof r=="string"&&(r=td(r)),!(r instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof r})`);return r}class ua{clone(){return this._cloneInto()}}const nd=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function fo(r,e){if(e!==void 0&&(typeof e!="object"||!nd(e)))throw new TypeError("Options should be object or undefined");return Object.assign(r,e)}function Br(r){const e=n=>r().update(Dn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function rd(r){const e=(n,s)=>r(s).update(Dn(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}class lo extends ua{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ee.hash(e);const n=Dn(t);if(this.iHash=e.create(),!(this.iHash instanceof ua))throw new TypeError("Expected instance of class which extends utils.Hash");const s=this.blockLen=this.iHash.blockLen;this.outputLen=this.iHash.outputLen;const i=new Uint8Array(s);i.set(n.length>this.iHash.blockLen?e.create().update(n).digest():n);for(let a=0;a<i.length;a++)i[a]^=54;this.iHash.update(i),this.oHash=e.create();for(let a=0;a<i.length;a++)i[a]^=106;this.oHash.update(i),i.fill(0)}update(e){return ee.exists(this),this.iHash.update(e),this}digestInto(e){ee.exists(this),ee.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:s,destroyed:i,blockLen:a,outputLen:c}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=a,e.outputLen=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const mc=(r,e,t)=>new lo(r,e).update(t).digest();mc.create=(r,e)=>new lo(r,e);function sd(r,e,t,n){ee.hash(r);const s=fo({dkLen:32,asyncTick:10},n),{c:i,dkLen:a,asyncTick:c}=s;if(ee.number(i),ee.number(a),ee.number(c),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const o=Dn(e),l=Dn(t),u=new Uint8Array(a),d=mc.create(r,o),b=d._cloneInto().update(l);return{c:i,dkLen:a,asyncTick:c,DK:u,PRF:d,PRFSalt:b}}function id(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}function wc(r,e,t,n){const{c:s,dkLen:i,DK:a,PRF:c,PRFSalt:o}=sd(r,e,t,n);let l;const u=new Uint8Array(4),d=la(u),b=new Uint8Array(c.outputLen);for(let g=1,A=0;A<i;g++,A+=c.outputLen){const w=a.subarray(A,A+c.outputLen);d.setInt32(0,g,!1),(l=o._cloneInto(l)).update(u).digestInto(b),w.set(b.subarray(0,w.length));for(let I=1;I<s;I++){c._cloneInto(l).update(b).digestInto(b);for(let O=0;O<w.length;O++)w[O]^=b[O]}}return id(c,o,a,l,b)}function ad(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);const s=BigInt(32),i=BigInt(4294967295),a=Number(t>>s&i),c=Number(t&i),o=n?4:0,l=n?0:4;r.setUint32(e+o,a,n),r.setUint32(e+l,c,n)}class Ac extends ua{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=la(this.buffer)}update(e){ee.exists(this);const{view:t,buffer:n,blockLen:s}=this;e=Dn(e);const i=e.length;for(let a=0;a<i;){const c=Math.min(s-this.pos,i-a);if(c===s){const o=la(e);for(;s<=i-a;a+=s)this.process(o,a);continue}n.set(e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ee.exists(this),ee.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:s,isLE:i}=this;let{pos:a}=this;t[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>s-a&&(this.process(n,0),a=0);for(let o=a;o<s;o++)t[o]=0;ad(n,s-8,BigInt(this.length*8),i),this.process(n,0);const c=la(e);this.get().forEach((o,l)=>c.setUint32(4*l,o,i))}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:s,finished:i,destroyed:a,pos:c}=this;return e.length=s,e.pos=c,e.finished=i,e.destroyed=a,s%t&&e.buffer.set(n),e}}const cd=(r,e,t)=>r&e^~r&t,od=(r,e,t)=>r&e^r&t^e&t,fd=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),an=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),cn=new Uint32Array(64);class ld extends Ac{constructor(){super(64,32,8,!1),this.A=an[0]|0,this.B=an[1]|0,this.C=an[2]|0,this.D=an[3]|0,this.E=an[4]|0,this.F=an[5]|0,this.G=an[6]|0,this.H=an[7]|0}get(){const{A:e,B:t,C:n,D:s,E:i,F:a,G:c,H:o}=this;return[e,t,n,s,i,a,c,o]}set(e,t,n,s,i,a,c,o){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=o|0}process(e,t){for(let d=0;d<16;d++,t+=4)cn[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){const b=cn[d-15],g=cn[d-2],A=ht(b,7)^ht(b,18)^b>>>3,w=ht(g,17)^ht(g,19)^g>>>10;cn[d]=w+cn[d-7]+A+cn[d-16]|0}let{A:n,B:s,C:i,D:a,E:c,F:o,G:l,H:u}=this;for(let d=0;d<64;d++){const b=ht(c,6)^ht(c,11)^ht(c,25),g=u+b+cd(c,o,l)+fd[d]+cn[d]|0,w=(ht(n,2)^ht(n,13)^ht(n,22))+od(n,s,i)|0;u=l,l=o,o=c,c=a+g|0,a=i,i=s,s=n,n=g+w|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,o=o+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,i,a,c,o,l,u)}roundClean(){cn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Ys=Br(()=>new ld),da=BigInt(2**32-1),Ec=BigInt(32);function uo(r,e=!1){return e?{h:Number(r&da),l:Number(r>>Ec&da)}:{h:Number(r>>Ec&da)|0,l:Number(r&da)|0}}function ud(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){const{h:i,l:a}=uo(r[s],e);[t[s],n[s]]=[i,a]}return[t,n]}const dd=(r,e)=>BigInt(r>>>0)<<Ec|BigInt(e>>>0),xd=(r,e,t)=>r>>>t,hd=(r,e,t)=>r<<32-t|e>>>t,bd=(r,e,t)=>r>>>t|e<<32-t,pd=(r,e,t)=>r<<32-t|e>>>t,gd=(r,e,t)=>r<<64-t|e>>>t-32,yd=(r,e,t)=>r>>>t-32|e<<64-t,md=(r,e)=>e,wd=(r,e)=>r,Ad=(r,e,t)=>r<<t|e>>>32-t,Ed=(r,e,t)=>e<<t|r>>>32-t,Id=(r,e,t)=>e<<t-32|r>>>64-t,Nd=(r,e,t)=>r<<t-32|e>>>64-t;function Td(r,e,t,n){const s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}const B={fromBig:uo,split:ud,toBig:dd,shrSH:xd,shrSL:hd,rotrSH:bd,rotrSL:pd,rotrBH:gd,rotrBL:yd,rotr32H:md,rotr32L:wd,rotlSH:Ad,rotlSL:Ed,rotlBH:Id,rotlBL:Nd,add:Td,add3L:(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),add3H:(r,e,t,n)=>e+t+n+(r/2**32|0)|0,add4L:(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),add4H:(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,add5H:(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0,add5L:(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0)},[Cd,kd]=B.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),on=new Uint32Array(80),fn=new Uint32Array(80);class Ic extends Ac{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:n,Bl:s,Ch:i,Cl:a,Dh:c,Dl:o,Eh:l,El:u,Fh:d,Fl:b,Gh:g,Gl:A,Hh:w,Hl:I}=this;return[e,t,n,s,i,a,c,o,l,u,d,b,g,A,w,I]}set(e,t,n,s,i,a,c,o,l,u,d,b,g,A,w,I){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=o|0,this.Eh=l|0,this.El=u|0,this.Fh=d|0,this.Fl=b|0,this.Gh=g|0,this.Gl=A|0,this.Hh=w|0,this.Hl=I|0}process(e,t){for(let R=0;R<16;R++,t+=4)on[R]=e.getUint32(t),fn[R]=e.getUint32(t+=4);for(let R=16;R<80;R++){const J=on[R-15]|0,v=fn[R-15]|0,Z=B.rotrSH(J,v,1)^B.rotrSH(J,v,8)^B.shrSH(J,v,7),ue=B.rotrSL(J,v,1)^B.rotrSL(J,v,8)^B.shrSL(J,v,7),W=on[R-2]|0,X=fn[R-2]|0,ye=B.rotrSH(W,X,19)^B.rotrBH(W,X,61)^B.shrSH(W,X,6),dt=B.rotrSL(W,X,19)^B.rotrBL(W,X,61)^B.shrSL(W,X,6),je=B.add4L(ue,dt,fn[R-7],fn[R-16]),xt=B.add4H(je,Z,ye,on[R-7],on[R-16]);on[R]=xt|0,fn[R]=je|0}let{Ah:n,Al:s,Bh:i,Bl:a,Ch:c,Cl:o,Dh:l,Dl:u,Eh:d,El:b,Fh:g,Fl:A,Gh:w,Gl:I,Hh:O,Hl:L}=this;for(let R=0;R<80;R++){const J=B.rotrSH(d,b,14)^B.rotrSH(d,b,18)^B.rotrBH(d,b,41),v=B.rotrSL(d,b,14)^B.rotrSL(d,b,18)^B.rotrBL(d,b,41),Z=d&g^~d&w,ue=b&A^~b&I,W=B.add5L(L,v,ue,kd[R],fn[R]),X=B.add5H(W,O,J,Z,Cd[R],on[R]),ye=W|0,dt=B.rotrSH(n,s,28)^B.rotrBH(n,s,34)^B.rotrBH(n,s,39),je=B.rotrSL(n,s,28)^B.rotrBL(n,s,34)^B.rotrBL(n,s,39),xt=n&i^n&c^i&c,qt=s&a^s&o^a&o;O=w|0,L=I|0,w=g|0,I=A|0,g=d|0,A=b|0,{h:d,l:b}=B.add(l|0,u|0,X|0,ye|0),l=c|0,u=o|0,c=i|0,o=a|0,i=n|0,a=s|0;const Ct=B.add3L(ye,je,qt);n=B.add3H(Ct,X,dt,xt),s=Ct|0}({h:n,l:s}=B.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:a}=B.add(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:o}=B.add(this.Ch|0,this.Cl|0,c|0,o|0),{h:l,l:u}=B.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:d,l:b}=B.add(this.Eh|0,this.El|0,d|0,b|0),{h:g,l:A}=B.add(this.Fh|0,this.Fl|0,g|0,A|0),{h:w,l:I}=B.add(this.Gh|0,this.Gl|0,w|0,I|0),{h:O,l:L}=B.add(this.Hh|0,this.Hl|0,O|0,L|0),this.set(n,s,i,a,c,o,l,u,d,b,g,A,w,I,O,L)}roundClean(){on.fill(0),fn.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Pd extends Ic{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class Od extends Ic{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const Nc=Br(()=>new Ic);Br(()=>new Pd),Br(()=>new Od);function Rd(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}const xo=Rd(),ho=xo.crypto||xo.msCrypto;function Sd(r){switch(r){case"sha256":return Ys.create();case"sha512":return Nc.create()}h(!1,"invalid hashing algorithm name","algorithm",r)}function vd(r,e){const t={sha256:Ys,sha512:Nc}[r];return h(t!=null,"invalid hmac algorithm","algorithm",r),mc.create(t,e)}function Bd(r,e,t,n,s){const i={sha256:Ys,sha512:Nc}[s];return h(i!=null,"invalid pbkdf2 algorithm","algorithm",s),wc(i,r,e,{c:t,dkLen:n})}function Ld(r){m(ho!=null,"platform does not support secure random numbers","UNSUPPORTED_OPERATION",{operation:"randomBytes"}),h(Number.isInteger(r)&&r>0&&r<=1024,"invalid length","length",r);const e=new Uint8Array(r);return ho.getRandomValues(e),e}let bo=!1;const po=function(r,e,t){return vd(r,e).update(t).digest()};let go=po;function Mn(r,e,t){const n=T(e,"key"),s=T(t,"data");return N(go(r,n,s))}Mn._=po,Mn.lock=function(){bo=!0},Mn.register=function(r){if(bo)throw new Error("computeHmac is locked");go=r},Object.freeze(Mn);const[yo,mo,wo]=[[],[],[]],Ud=BigInt(0),$s=BigInt(1),Fd=BigInt(2),Dd=BigInt(7),Md=BigInt(256),Gd=BigInt(113);for(let r=0,e=$s,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],yo.push(2*(5*n+t)),mo.push((r+1)*(r+2)/2%64);let s=Ud;for(let i=0;i<7;i++)e=(e<<$s^(e>>Dd)*Gd)%Md,e&Fd&&(s^=$s<<($s<<BigInt(i))-$s);wo.push(s)}const[Hd,_d]=B.split(wo,!0),Ao=(r,e,t)=>t>32?B.rotlBH(r,e,t):B.rotlSH(r,e,t),Eo=(r,e,t)=>t>32?B.rotlBL(r,e,t):B.rotlSL(r,e,t);function Kd(r,e=24){const t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let a=0;a<10;a++)t[a]=r[a]^r[a+10]^r[a+20]^r[a+30]^r[a+40];for(let a=0;a<10;a+=2){const c=(a+8)%10,o=(a+2)%10,l=t[o],u=t[o+1],d=Ao(l,u,1)^t[c],b=Eo(l,u,1)^t[c+1];for(let g=0;g<50;g+=10)r[a+g]^=d,r[a+g+1]^=b}let s=r[2],i=r[3];for(let a=0;a<24;a++){const c=mo[a],o=Ao(s,i,c),l=Eo(s,i,c),u=yo[a];s=r[u],i=r[u+1],r[u]=o,r[u+1]=l}for(let a=0;a<50;a+=10){for(let c=0;c<10;c++)t[c]=r[a+c];for(let c=0;c<10;c++)r[a+c]^=~t[(c+2)%10]&t[(c+4)%10]}r[0]^=Hd[n],r[1]^=_d[n]}t.fill(0)}class xa extends ua{constructor(e,t,n,s=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=s,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,ee.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=fa(this.state)}keccak(){Kd(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){ee.exists(this);const{blockLen:t,state:n}=this;e=Dn(e);const s=e.length;for(let i=0;i<s;){const a=Math.min(t-this.pos,s-i);for(let c=0;c<a;c++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:s}=this;e[n]^=t,t&128&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){ee.exists(this,!1),ee.bytes(e),this.finish();const t=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();const a=Math.min(n-this.posOut,i-s);e.set(t.subarray(this.posOut,this.posOut+a),s),this.posOut+=a,s+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ee.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ee.output(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fi