genosdb 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gdb.min.js +1 -1
- package/dist/gdb.min.js.gz +0 -0
- package/dist/genossrv.min.js +11 -11
- package/dist/genossrv.min.js.gz +0 -0
- package/dist/index.js +1 -1
- package/dist/index.js.gz +0 -0
- package/package.json +1 -1
package/dist/genossrv.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
var log=(()=>{const n=()=>{};return new Proxy(console,{get:(c,m)=>globalThis.__gdbDebug?c[m].bind(c):n})})();
|
|
3
|
-
var $_=Object.create;var{getPrototypeOf:F_,defineProperty:HA,getOwnPropertyNames:S_}=Object;var x_=Object.prototype.hasOwnProperty;function k_(W){return this[W]}var __,y_,
|
|
3
|
+
var $_=Object.create;var{getPrototypeOf:F_,defineProperty:HA,getOwnPropertyNames:S_}=Object;var x_=Object.prototype.hasOwnProperty;function k_(W){return this[W]}var __,y_,v1=(W,Y,G)=>{var X=W!=null&&typeof W==="object";if(X){var J=Y?__??=new WeakMap:y_??=new WeakMap,Z=J.get(W);if(Z)return Z}G=W!=null?$_(F_(W)):{};let V=Y||!W||!W.__esModule?HA(G,"default",{value:W,enumerable:!0}):G;for(let U of S_(W))if(!x_.call(V,U))HA(V,U,{get:k_.bind(W,U),enumerable:!0});if(X)J.set(W,V);return V};var U1=(W,Y)=>()=>(Y||W((Y={exports:{}}).exports,Y),Y.exports);var v_=(W)=>W;function g_(W,Y){this[W]=v_.bind(null,Y)}var NA=(W,Y)=>{for(var G in Y)HA(W,G,{get:Y[G],enumerable:!0,configurable:!0,set:g_.bind(Y,G)})};var x8=import.meta.require;var aT=U1((ve,rT)=>{var qG=1000,AG=qG*60,IG=AG*60,BW=IG*24,_h=BW*7,yh=BW*365.25;rT.exports=function(W,Y){Y=Y||{};var G=typeof W;if(G==="string"&&W.length>0)return vh(W);else if(G==="number"&&isFinite(W))return Y.long?uh(W):gh(W);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(W))};function vh(W){if(W=String(W),W.length>100)return;var Y=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(W);if(!Y)return;var G=parseFloat(Y[1]),X=(Y[2]||"ms").toLowerCase();switch(X){case"years":case"year":case"yrs":case"yr":case"y":return G*yh;case"weeks":case"week":case"w":return G*_h;case"days":case"day":case"d":return G*BW;case"hours":case"hour":case"hrs":case"hr":case"h":return G*IG;case"minutes":case"minute":case"mins":case"min":case"m":return G*AG;case"seconds":case"second":case"secs":case"sec":case"s":return G*qG;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return G;default:return}}function gh(W){var Y=Math.abs(W);if(Y>=BW)return Math.round(W/BW)+"d";if(Y>=IG)return Math.round(W/IG)+"h";if(Y>=AG)return Math.round(W/AG)+"m";if(Y>=qG)return Math.round(W/qG)+"s";return W+"ms"}function uh(W){var Y=Math.abs(W);if(Y>=BW)return PQ(W,Y,BW,"day");if(Y>=IG)return PQ(W,Y,IG,"hour");if(Y>=AG)return PQ(W,Y,AG,"minute");if(Y>=qG)return PQ(W,Y,qG,"second");return W+" ms"}function PQ(W,Y,G,X){var J=Y>=G*1.5;return Math.round(W/G)+" "+X+(J?"s":"")}});var PI=U1((ge,sT)=>{function hh(W){G.debug=G,G.default=G,G.coerce=Q,G.disable=V,G.enable=J,G.enabled=U,G.humanize=aT(),G.destroy=H,Object.keys(W).forEach((N)=>{G[N]=W[N]}),G.names=[],G.skips=[],G.formatters={};function Y(N){let A=0;for(let q=0;q<N.length;q++)A=(A<<5)-A+N.charCodeAt(q),A|=0;return G.colors[Math.abs(A)%G.colors.length]}G.selectColor=Y;function G(N){let A,q=null,z,w;function D(...T){if(!D.enabled)return;let x=D,g=Number(new Date),f=g-(A||g);if(x.diff=f,x.prev=A,x.curr=g,A=g,T[0]=G.coerce(T[0]),typeof T[0]!=="string")T.unshift("%O");let y=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(b,m)=>{if(b==="%%")return"%";y++;let W0=G.formatters[m];if(typeof W0==="function"){let u=T[y];b=W0.call(x,u),T.splice(y,1),y--}return b}),G.formatArgs.call(x,T),(x.log||G.log).apply(x,T)}if(D.namespace=N,D.useColors=G.useColors(),D.color=G.selectColor(N),D.extend=X,D.destroy=G.destroy,Object.defineProperty(D,"enabled",{enumerable:!0,configurable:!1,get:()=>{if(q!==null)return q;if(z!==G.namespaces)z=G.namespaces,w=G.enabled(N);return w},set:(T)=>{q=T}}),typeof G.init==="function")G.init(D);return D}function X(N,A){let q=G(this.namespace+(typeof A>"u"?":":A)+N);return q.log=this.log,q}function J(N){G.save(N),G.namespaces=N,G.names=[],G.skips=[];let A=(typeof N==="string"?N:"").trim().replace(" ",",").split(",").filter(Boolean);for(let q of A)if(q[0]==="-")G.skips.push(q.slice(1));else G.names.push(q)}function Z(N,A){let q=0,z=0,w=-1,D=0;while(q<N.length)if(z<A.length&&(A[z]===N[q]||A[z]==="*"))if(A[z]==="*")w=z,D=q,z++;else q++,z++;else if(w!==-1)z=w+1,D++,q=D;else return!1;while(z<A.length&&A[z]==="*")z++;return z===A.length}function V(){let N=[...G.names,...G.skips.map((A)=>"-"+A)].join(",");return G.enable(""),N}function U(N){for(let A of G.skips)if(Z(N,A))return!1;for(let A of G.names)if(Z(N,A))return!0;return!1}function Q(N){if(N instanceof Error)return N.stack||N.message;return N}function H(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return G.enable(G.load()),G}sT.exports=hh});var eT=U1((tT,BQ)=>{tT.formatArgs=mh;tT.save=fh;tT.load=ch;tT.useColors=bh;tT.storage=ph();tT.destroy=(()=>{let W=!1;return()=>{if(!W)W=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}})();tT.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function bh(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let W;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(W=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(W[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function mh(W){if(W[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+W[0]+(this.useColors?"%c ":" ")+"+"+BQ.exports.humanize(this.diff),!this.useColors)return;let Y="color: "+this.color;W.splice(1,0,Y,"color: inherit");let G=0,X=0;W[0].replace(/%[a-zA-Z%]/g,(J)=>{if(J==="%%")return;if(G++,J==="%c")X=G}),W.splice(X,0,Y)}tT.log=console.debug||console.log||(()=>{});function fh(W){try{if(W)tT.storage.setItem("debug",W);else tT.storage.removeItem("debug")}catch(Y){}}function ch(){let W;try{W=tT.storage.getItem("debug")}catch(Y){}if(!W&&typeof process<"u"&&"env"in process)W=process.env.DEBUG;return W}function ph(){try{return localStorage}catch(W){}}BQ.exports=PI()(tT);var{formatters:lh}=BQ.exports;lh.j=function(W){try{return JSON.stringify(W)}catch(Y){return"[UnexpectedJSONParseError]: "+Y.message}}});var XR=U1((YR,$Q)=>{var th=x8("tty"),EQ=x8("util");YR.init=Zb;YR.log=Gb;YR.formatArgs=Wb;YR.save=Xb;YR.load=Jb;YR.useColors=eh;YR.destroy=EQ.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");YR.colors=[6,2,3,4,5,1];try{let W=(()=>{throw new Error("Cannot require module "+"supports-color");})();if(W&&(W.stderr||W).level>=2)YR.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]}catch(W){}YR.inspectOpts=Object.keys(process.env).filter((W)=>{return/^debug_/i.test(W)}).reduce((W,Y)=>{let G=Y.substring(6).toLowerCase().replace(/_([a-z])/g,(J,Z)=>{return Z.toUpperCase()}),X=process.env[Y];if(/^(yes|on|true|enabled)$/i.test(X))X=!0;else if(/^(no|off|false|disabled)$/i.test(X))X=!1;else if(X==="null")X=null;else X=Number(X);return W[G]=X,W},{});function eh(){return"colors"in YR.inspectOpts?Boolean(YR.inspectOpts.colors):th.isatty(process.stderr.fd)}function Wb(W){let{namespace:Y,useColors:G}=this;if(G){let X=this.color,J="\x1B[3"+(X<8?X:"8;5;"+X),Z=` ${J};1m${Y} \x1B[0m`;W[0]=Z+W[0].split(`
|
|
4
4
|
`).join(`
|
|
5
5
|
`+Z),W.push(J+"m+"+$Q.exports.humanize(this.diff)+"\x1B[0m")}else W[0]=Yb()+Y+" "+W[0]}function Yb(){if(YR.inspectOpts.hideDate)return"";return new Date().toISOString()+" "}function Gb(...W){return process.stderr.write(EQ.formatWithOptions(YR.inspectOpts,...W)+`
|
|
6
6
|
`)}function Xb(W){if(W)process.env.DEBUG=W;else delete process.env.DEBUG}function Jb(){return process.env.DEBUG}function Zb(W){W.inspectOpts={};let Y=Object.keys(YR.inspectOpts);for(let G=0;G<Y.length;G++)W.inspectOpts[Y[G]]=YR.inspectOpts[Y[G]]}$Q.exports=PI()(YR);var{formatters:WR}=$Q.exports;WR.o=function(W){return this.inspectOpts.colors=this.useColors,EQ.inspect(W,this.inspectOpts).split(`
|
|
7
|
-
`).map((Y)=>Y.trim()).join(" ")};WR.O=function(W){return this.inspectOpts.colors=this.useColors,EQ.inspect(W,this.inspectOpts)}});var JR=U1((be,LI)=>{if(typeof process>"u"||process.type==="renderer"||!1||process.__nwjs)LI.exports=eT();else LI.exports=XR()});var FQ=U1((VR)=>{Object.defineProperty(VR,"__esModule",{value:!0});var Ib=x8("net");function zb(W){switch(Ib.isIP(W)){case 4:return Buffer.from(W.split(".").map((J)=>parseInt(J,10)));case 6:let Y=W.split(":"),G=Buffer.alloc(16),X=0;if(Y[Y.length-1]==="")Y[Y.length-1]="0";for(let J=0;J<Y.length;J++){if(Y[J]===""){if(J+1<Y.length&&Y[J+1]!=="")X=16-(Y.length-J-1)*2;continue}G.writeUInt16BE(parseInt(Y[J],16),X),X+=2}return G;default:return null}}VR.bytesFromIP=zb;function wb(W){switch(W.length){case 4:return[W[0],W[1],W[2],W[3]].join(".");case 16:let Y=[],G=-1,X=0,J=-1,Z=0;for(let V=0;V<W.length;V+=2){let U=W[V]<<8|W[V+1];if(U===0){if(X++,G===-1)G=Y.length;if(X>Z)Z=X,J=G}else G=-1,X=0;Y.push(U.toString(16))}if(Z>0){let V="",U=Y.slice(J+Z);if(Y.length=J,Y.length===0)V+=":";if(U.length===0)V+=":";Y.push(V,...U)}return Y.join(":");default:return""}}VR.bytesToIP=wb;var A6=Object.create(null),ZR=/^[0-9.]+$/;function jb(W){if(ZR.test(W)&&A6[W]!=="")return W;return A6[W]==null?"":A6[W]}VR.getOID=jb;function Ob(W){if(!ZR.test(W)&&A6[W]!=="")return W;return A6[W]==null?W:A6[W]}VR.getOIDName=Ob;function z0(W,Y){A6[W]=Y,A6[Y]=W}z0("1.2.840.113549.1.1.1","rsaEncryption");z0("1.2.840.113549.1.1.4","md5WithRsaEncryption");z0("1.2.840.113549.1.1.5","sha1WithRsaEncryption");z0("1.2.840.113549.1.1.8","mgf1");z0("1.2.840.113549.1.1.10","RSASSA-PSS");z0("1.2.840.113549.1.1.11","sha256WithRsaEncryption");z0("1.2.840.113549.1.1.12","sha384WithRsaEncryption");z0("1.2.840.113549.1.1.13","sha512WithRsaEncryption");z0("1.2.840.10045.2.1","ecEncryption");z0("1.2.840.10045.4.1","ecdsaWithSha1");z0("1.2.840.10045.4.3.2","ecdsaWithSha256");z0("1.2.840.10045.4.3.3","ecdsaWithSha384");z0("1.2.840.10045.4.3.4","ecdsaWithSha512");z0("1.2.840.10040.4.3","dsaWithSha1");z0("2.16.840.1.101.3.4.3.2","dsaWithSha256");z0("1.3.14.3.2.7","desCBC");z0("1.3.14.3.2.26","sha1");z0("2.16.840.1.101.3.4.2.1","sha256");z0("2.16.840.1.101.3.4.2.2","sha384");z0("2.16.840.1.101.3.4.2.3","sha512");z0("1.2.840.113549.2.5","md5");z0("1.3.101.110","X25519");z0("1.3.101.111","X448");z0("1.3.101.112","Ed25519");z0("1.3.101.113","Ed448");z0("1.2.840.113549.1.7.1","data");z0("1.2.840.113549.1.7.2","signedData");z0("1.2.840.113549.1.7.3","envelopedData");z0("1.2.840.113549.1.7.4","signedAndEnvelopedData");z0("1.2.840.113549.1.7.5","digestedData");z0("1.2.840.113549.1.7.6","encryptedData");z0("1.2.840.113549.1.9.1","emailAddress");z0("1.2.840.113549.1.9.2","unstructuredName");z0("1.2.840.113549.1.9.3","contentType");z0("1.2.840.113549.1.9.4","messageDigest");z0("1.2.840.113549.1.9.5","signingTime");z0("1.2.840.113549.1.9.6","counterSignature");z0("1.2.840.113549.1.9.7","challengePassword");z0("1.2.840.113549.1.9.8","unstructuredAddress");z0("1.2.840.113549.1.9.14","extensionRequest");z0("1.2.840.113549.1.9.20","friendlyName");z0("1.2.840.113549.1.9.21","localKeyId");z0("1.2.840.113549.1.9.22.1","x509Certificate");z0("1.2.840.113549.1.12.10.1.1","keyBag");z0("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");z0("1.2.840.113549.1.12.10.1.3","certBag");z0("1.2.840.113549.1.12.10.1.4","crlBag");z0("1.2.840.113549.1.12.10.1.5","secretBag");z0("1.2.840.113549.1.12.10.1.6","safeContentsBag");z0("1.2.840.113549.1.5.13","pkcs5PBES2");z0("1.2.840.113549.1.5.12","pkcs5PBKDF2");z0("1.2.840.113549.2.7","hmacWithSha1");z0("1.2.840.113549.2.9","hmacWithSha256");z0("1.2.840.113549.2.10","hmacWithSha384");z0("1.2.840.113549.2.11","hmacWithSha512");z0("1.2.840.113549.3.7","3desCBC");z0("2.16.840.1.101.3.4.1.2","aesCBC128");z0("2.16.840.1.101.3.4.1.42","aesCBC256");z0("2.5.4.3","commonName");z0("2.5.4.5","serialName");z0("2.5.4.6","countryName");z0("2.5.4.7","localityName");z0("2.5.4.8","stateOrProvinceName");z0("2.5.4.10","organizationName");z0("2.5.4.11","organizationalUnitName");z0("2.5.4.15","businessCategory");z0("2.16.840.1.113730.1.1","nsCertType");z0("2.5.29.2","keyAttributes");z0("2.5.29.4","keyUsageRestriction");z0("2.5.29.6","subtreesConstraint");z0("2.5.29.9","subjectDirectoryAttributes");z0("2.5.29.14","subjectKeyIdentifier");z0("2.5.29.15","keyUsage");z0("2.5.29.16","privateKeyUsagePeriod");z0("2.5.29.17","subjectAltName");z0("2.5.29.18","issuerAltName");z0("2.5.29.19","basicConstraints");z0("2.5.29.20","cRLNumber");z0("2.5.29.21","cRLReason");z0("2.5.29.22","expirationDate");z0("2.5.29.23","instructionCode");z0("2.5.29.24","invalidityDate");z0("2.5.29.27","deltaCRLIndicator");z0("2.5.29.28","issuingDistributionPoint");z0("2.5.29.29","certificateIssuer");z0("2.5.29.30","nameConstraints");z0("2.5.29.31","cRLDistributionPoints");z0("2.5.29.32","certificatePolicies");z0("2.5.29.33","policyMappings");z0("2.5.29.35","authorityKeyIdentifier");z0("2.5.29.36","policyConstraints");z0("2.5.29.37","extKeyUsage");z0("2.5.29.46","freshestCRL");z0("2.5.29.54","inhibitAnyPolicy");z0("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST");z0("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC");z0("1.3.6.1.4.1.11129.2.4.2","timestampList");z0("1.3.6.1.5.5.7.1.1","authorityInfoAccess");z0("1.3.6.1.5.5.7.3.1","serverAuth");z0("1.3.6.1.5.5.7.3.2","clientAuth");z0("1.3.6.1.5.5.7.3.3","codeSigning");z0("1.3.6.1.5.5.7.3.4","emailProtection");z0("1.3.6.1.5.5.7.3.8","timeStamping");z0("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp");z0("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")});var xQ=U1((fe,SQ)=>{(function(W){var Y=function(O){var R,C=new Float64Array(16);if(O)for(R=0;R<O.length;R++)C[R]=O[R];return C},G=function(){throw Error("no PRNG")},X=new Uint8Array(16),J=new Uint8Array(32);J[0]=9;var Z=Y(),V=Y([1]),U=Y([56129,1]),Q=Y([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),H=Y([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),N=Y([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),A=Y([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),q=Y([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function z(O,R,C,I){O[R]=C>>24&255,O[R+1]=C>>16&255,O[R+2]=C>>8&255,O[R+3]=C&255,O[R+4]=I>>24&255,O[R+5]=I>>16&255,O[R+6]=I>>8&255,O[R+7]=I&255}function w(O,R,C,I,L){var o,s=0;for(o=0;o<L;o++)s|=O[R+o]^C[I+o];return(1&s-1>>>8)-1}function D(O,R,C,I){return w(O,R,C,I,16)}function T(O,R,C,I){return w(O,R,C,I,32)}function x(O,R,C,I){var L=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,o=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,s=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,N0=C[8]&255|(C[9]&255)<<8|(C[10]&255)<<16|(C[11]&255)<<24,R0=C[12]&255|(C[13]&255)<<8|(C[14]&255)<<16|(C[15]&255)<<24,t0=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,u0=R[0]&255|(R[1]&255)<<8|(R[2]&255)<<16|(R[3]&255)<<24,p1=R[4]&255|(R[5]&255)<<8|(R[6]&255)<<16|(R[7]&255)<<24,c0=R[8]&255|(R[9]&255)<<8|(R[10]&255)<<16|(R[11]&255)<<24,q1=R[12]&255|(R[13]&255)<<8|(R[14]&255)<<16|(R[15]&255)<<24,I1=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,P1=C[16]&255|(C[17]&255)<<8|(C[18]&255)<<16|(C[19]&255)<<24,T1=C[20]&255|(C[21]&255)<<8|(C[22]&255)<<16|(C[23]&255)<<24,z1=C[24]&255|(C[25]&255)<<8|(C[26]&255)<<16|(C[27]&255)<<24,O1=C[28]&255|(C[29]&255)<<8|(C[30]&255)<<16|(C[31]&255)<<24,w1=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,d0=L,Y1=o,h0=s,n0=N0,s0=R0,v0=t0,Z0=u0,V0=p1,w0=c0,H0=q1,q0=I1,K0=P1,N1=T1,L1=z1,E1=O1,B1=w1,_;for(var F1=0;F1<20;F1+=2)_=d0+N1|0,s0^=_<<7|_>>>25,_=s0+d0|0,w0^=_<<9|_>>>23,_=w0+s0|0,N1^=_<<13|_>>>19,_=N1+w0|0,d0^=_<<18|_>>>14,_=v0+Y1|0,H0^=_<<7|_>>>25,_=H0+v0|0,L1^=_<<9|_>>>23,_=L1+H0|0,Y1^=_<<13|_>>>19,_=Y1+L1|0,v0^=_<<18|_>>>14,_=q0+Z0|0,E1^=_<<7|_>>>25,_=E1+q0|0,h0^=_<<9|_>>>23,_=h0+E1|0,Z0^=_<<13|_>>>19,_=Z0+h0|0,q0^=_<<18|_>>>14,_=B1+K0|0,n0^=_<<7|_>>>25,_=n0+B1|0,V0^=_<<9|_>>>23,_=V0+n0|0,K0^=_<<13|_>>>19,_=K0+V0|0,B1^=_<<18|_>>>14,_=d0+n0|0,Y1^=_<<7|_>>>25,_=Y1+d0|0,h0^=_<<9|_>>>23,_=h0+Y1|0,n0^=_<<13|_>>>19,_=n0+h0|0,d0^=_<<18|_>>>14,_=v0+s0|0,Z0^=_<<7|_>>>25,_=Z0+v0|0,V0^=_<<9|_>>>23,_=V0+Z0|0,s0^=_<<13|_>>>19,_=s0+V0|0,v0^=_<<18|_>>>14,_=q0+H0|0,K0^=_<<7|_>>>25,_=K0+q0|0,w0^=_<<9|_>>>23,_=w0+K0|0,H0^=_<<13|_>>>19,_=H0+w0|0,q0^=_<<18|_>>>14,_=B1+E1|0,N1^=_<<7|_>>>25,_=N1+B1|0,L1^=_<<9|_>>>23,_=L1+N1|0,E1^=_<<13|_>>>19,_=E1+L1|0,B1^=_<<18|_>>>14;d0=d0+L|0,Y1=Y1+o|0,h0=h0+s|0,n0=n0+N0|0,s0=s0+R0|0,v0=v0+t0|0,Z0=Z0+u0|0,V0=V0+p1|0,w0=w0+c0|0,H0=H0+q1|0,q0=q0+I1|0,K0=K0+P1|0,N1=N1+T1|0,L1=L1+z1|0,E1=E1+O1|0,B1=B1+w1|0,O[0]=d0>>>0&255,O[1]=d0>>>8&255,O[2]=d0>>>16&255,O[3]=d0>>>24&255,O[4]=Y1>>>0&255,O[5]=Y1>>>8&255,O[6]=Y1>>>16&255,O[7]=Y1>>>24&255,O[8]=h0>>>0&255,O[9]=h0>>>8&255,O[10]=h0>>>16&255,O[11]=h0>>>24&255,O[12]=n0>>>0&255,O[13]=n0>>>8&255,O[14]=n0>>>16&255,O[15]=n0>>>24&255,O[16]=s0>>>0&255,O[17]=s0>>>8&255,O[18]=s0>>>16&255,O[19]=s0>>>24&255,O[20]=v0>>>0&255,O[21]=v0>>>8&255,O[22]=v0>>>16&255,O[23]=v0>>>24&255,O[24]=Z0>>>0&255,O[25]=Z0>>>8&255,O[26]=Z0>>>16&255,O[27]=Z0>>>24&255,O[28]=V0>>>0&255,O[29]=V0>>>8&255,O[30]=V0>>>16&255,O[31]=V0>>>24&255,O[32]=w0>>>0&255,O[33]=w0>>>8&255,O[34]=w0>>>16&255,O[35]=w0>>>24&255,O[36]=H0>>>0&255,O[37]=H0>>>8&255,O[38]=H0>>>16&255,O[39]=H0>>>24&255,O[40]=q0>>>0&255,O[41]=q0>>>8&255,O[42]=q0>>>16&255,O[43]=q0>>>24&255,O[44]=K0>>>0&255,O[45]=K0>>>8&255,O[46]=K0>>>16&255,O[47]=K0>>>24&255,O[48]=N1>>>0&255,O[49]=N1>>>8&255,O[50]=N1>>>16&255,O[51]=N1>>>24&255,O[52]=L1>>>0&255,O[53]=L1>>>8&255,O[54]=L1>>>16&255,O[55]=L1>>>24&255,O[56]=E1>>>0&255,O[57]=E1>>>8&255,O[58]=E1>>>16&255,O[59]=E1>>>24&255,O[60]=B1>>>0&255,O[61]=B1>>>8&255,O[62]=B1>>>16&255,O[63]=B1>>>24&255}function g(O,R,C,I){var L=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,o=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,s=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,N0=C[8]&255|(C[9]&255)<<8|(C[10]&255)<<16|(C[11]&255)<<24,R0=C[12]&255|(C[13]&255)<<8|(C[14]&255)<<16|(C[15]&255)<<24,t0=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,u0=R[0]&255|(R[1]&255)<<8|(R[2]&255)<<16|(R[3]&255)<<24,p1=R[4]&255|(R[5]&255)<<8|(R[6]&255)<<16|(R[7]&255)<<24,c0=R[8]&255|(R[9]&255)<<8|(R[10]&255)<<16|(R[11]&255)<<24,q1=R[12]&255|(R[13]&255)<<8|(R[14]&255)<<16|(R[15]&255)<<24,I1=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,P1=C[16]&255|(C[17]&255)<<8|(C[18]&255)<<16|(C[19]&255)<<24,T1=C[20]&255|(C[21]&255)<<8|(C[22]&255)<<16|(C[23]&255)<<24,z1=C[24]&255|(C[25]&255)<<8|(C[26]&255)<<16|(C[27]&255)<<24,O1=C[28]&255|(C[29]&255)<<8|(C[30]&255)<<16|(C[31]&255)<<24,w1=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,d0=L,Y1=o,h0=s,n0=N0,s0=R0,v0=t0,Z0=u0,V0=p1,w0=c0,H0=q1,q0=I1,K0=P1,N1=T1,L1=z1,E1=O1,B1=w1,_;for(var F1=0;F1<20;F1+=2)_=d0+N1|0,s0^=_<<7|_>>>25,_=s0+d0|0,w0^=_<<9|_>>>23,_=w0+s0|0,N1^=_<<13|_>>>19,_=N1+w0|0,d0^=_<<18|_>>>14,_=v0+Y1|0,H0^=_<<7|_>>>25,_=H0+v0|0,L1^=_<<9|_>>>23,_=L1+H0|0,Y1^=_<<13|_>>>19,_=Y1+L1|0,v0^=_<<18|_>>>14,_=q0+Z0|0,E1^=_<<7|_>>>25,_=E1+q0|0,h0^=_<<9|_>>>23,_=h0+E1|0,Z0^=_<<13|_>>>19,_=Z0+h0|0,q0^=_<<18|_>>>14,_=B1+K0|0,n0^=_<<7|_>>>25,_=n0+B1|0,V0^=_<<9|_>>>23,_=V0+n0|0,K0^=_<<13|_>>>19,_=K0+V0|0,B1^=_<<18|_>>>14,_=d0+n0|0,Y1^=_<<7|_>>>25,_=Y1+d0|0,h0^=_<<9|_>>>23,_=h0+Y1|0,n0^=_<<13|_>>>19,_=n0+h0|0,d0^=_<<18|_>>>14,_=v0+s0|0,Z0^=_<<7|_>>>25,_=Z0+v0|0,V0^=_<<9|_>>>23,_=V0+Z0|0,s0^=_<<13|_>>>19,_=s0+V0|0,v0^=_<<18|_>>>14,_=q0+H0|0,K0^=_<<7|_>>>25,_=K0+q0|0,w0^=_<<9|_>>>23,_=w0+K0|0,H0^=_<<13|_>>>19,_=H0+w0|0,q0^=_<<18|_>>>14,_=B1+E1|0,N1^=_<<7|_>>>25,_=N1+B1|0,L1^=_<<9|_>>>23,_=L1+N1|0,E1^=_<<13|_>>>19,_=E1+L1|0,B1^=_<<18|_>>>14;O[0]=d0>>>0&255,O[1]=d0>>>8&255,O[2]=d0>>>16&255,O[3]=d0>>>24&255,O[4]=v0>>>0&255,O[5]=v0>>>8&255,O[6]=v0>>>16&255,O[7]=v0>>>24&255,O[8]=q0>>>0&255,O[9]=q0>>>8&255,O[10]=q0>>>16&255,O[11]=q0>>>24&255,O[12]=B1>>>0&255,O[13]=B1>>>8&255,O[14]=B1>>>16&255,O[15]=B1>>>24&255,O[16]=Z0>>>0&255,O[17]=Z0>>>8&255,O[18]=Z0>>>16&255,O[19]=Z0>>>24&255,O[20]=V0>>>0&255,O[21]=V0>>>8&255,O[22]=V0>>>16&255,O[23]=V0>>>24&255,O[24]=w0>>>0&255,O[25]=w0>>>8&255,O[26]=w0>>>16&255,O[27]=w0>>>24&255,O[28]=H0>>>0&255,O[29]=H0>>>8&255,O[30]=H0>>>16&255,O[31]=H0>>>24&255}function f(O,R,C,I){x(O,R,C,I)}function y(O,R,C,I){g(O,R,C,I)}var p=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function b(O,R,C,I,L,o,s){var N0=new Uint8Array(16),R0=new Uint8Array(64),t0,u0;for(u0=0;u0<16;u0++)N0[u0]=0;for(u0=0;u0<8;u0++)N0[u0]=o[u0];while(L>=64){f(R0,N0,s,p);for(u0=0;u0<64;u0++)O[R+u0]=C[I+u0]^R0[u0];t0=1;for(u0=8;u0<16;u0++)t0=t0+(N0[u0]&255)|0,N0[u0]=t0&255,t0>>>=8;L-=64,R+=64,I+=64}if(L>0){f(R0,N0,s,p);for(u0=0;u0<L;u0++)O[R+u0]=C[I+u0]^R0[u0]}return 0}function m(O,R,C,I,L){var o=new Uint8Array(16),s=new Uint8Array(64),N0,R0;for(R0=0;R0<16;R0++)o[R0]=0;for(R0=0;R0<8;R0++)o[R0]=I[R0];while(C>=64){f(s,o,L,p);for(R0=0;R0<64;R0++)O[R+R0]=s[R0];N0=1;for(R0=8;R0<16;R0++)N0=N0+(o[R0]&255)|0,o[R0]=N0&255,N0>>>=8;C-=64,R+=64}if(C>0){f(s,o,L,p);for(R0=0;R0<C;R0++)O[R+R0]=s[R0]}return 0}function W0(O,R,C,I,L){var o=new Uint8Array(32);y(o,I,L,p);var s=new Uint8Array(8);for(var N0=0;N0<8;N0++)s[N0]=I[N0+16];return m(O,R,C,s,o)}function u(O,R,C,I,L,o,s){var N0=new Uint8Array(32);y(N0,o,s,p);var R0=new Uint8Array(8);for(var t0=0;t0<8;t0++)R0[t0]=o[t0+16];return b(O,R,C,I,L,R0,N0)}var J0=function(O){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var R,C,I,L,o,s,N0,R0;R=O[0]&255|(O[1]&255)<<8,this.r[0]=R&8191,C=O[2]&255|(O[3]&255)<<8,this.r[1]=(R>>>13|C<<3)&8191,I=O[4]&255|(O[5]&255)<<8,this.r[2]=(C>>>10|I<<6)&7939,L=O[6]&255|(O[7]&255)<<8,this.r[3]=(I>>>7|L<<9)&8191,o=O[8]&255|(O[9]&255)<<8,this.r[4]=(L>>>4|o<<12)&255,this.r[5]=o>>>1&8190,s=O[10]&255|(O[11]&255)<<8,this.r[6]=(o>>>14|s<<2)&8191,N0=O[12]&255|(O[13]&255)<<8,this.r[7]=(s>>>11|N0<<5)&8065,R0=O[14]&255|(O[15]&255)<<8,this.r[8]=(N0>>>8|R0<<8)&8191,this.r[9]=R0>>>5&127,this.pad[0]=O[16]&255|(O[17]&255)<<8,this.pad[1]=O[18]&255|(O[19]&255)<<8,this.pad[2]=O[20]&255|(O[21]&255)<<8,this.pad[3]=O[22]&255|(O[23]&255)<<8,this.pad[4]=O[24]&255|(O[25]&255)<<8,this.pad[5]=O[26]&255|(O[27]&255)<<8,this.pad[6]=O[28]&255|(O[29]&255)<<8,this.pad[7]=O[30]&255|(O[31]&255)<<8};J0.prototype.blocks=function(O,R,C){var I=this.fin?0:2048,L,o,s,N0,R0,t0,u0,p1,c0,q1,I1,P1,T1,z1,O1,w1,d0,Y1,h0,n0=this.h[0],s0=this.h[1],v0=this.h[2],Z0=this.h[3],V0=this.h[4],w0=this.h[5],H0=this.h[6],q0=this.h[7],K0=this.h[8],N1=this.h[9],L1=this.r[0],E1=this.r[1],B1=this.r[2],_=this.r[3],F1=this.r[4],l1=this.r[5],d1=this.r[6],$1=this.r[7],h1=this.r[8],b1=this.r[9];while(C>=16)L=O[R+0]&255|(O[R+1]&255)<<8,n0+=L&8191,o=O[R+2]&255|(O[R+3]&255)<<8,s0+=(L>>>13|o<<3)&8191,s=O[R+4]&255|(O[R+5]&255)<<8,v0+=(o>>>10|s<<6)&8191,N0=O[R+6]&255|(O[R+7]&255)<<8,Z0+=(s>>>7|N0<<9)&8191,R0=O[R+8]&255|(O[R+9]&255)<<8,V0+=(N0>>>4|R0<<12)&8191,w0+=R0>>>1&8191,t0=O[R+10]&255|(O[R+11]&255)<<8,H0+=(R0>>>14|t0<<2)&8191,u0=O[R+12]&255|(O[R+13]&255)<<8,q0+=(t0>>>11|u0<<5)&8191,p1=O[R+14]&255|(O[R+15]&255)<<8,K0+=(u0>>>8|p1<<8)&8191,N1+=p1>>>5|I,c0=0,q1=c0,q1+=n0*L1,q1+=s0*(5*b1),q1+=v0*(5*h1),q1+=Z0*(5*$1),q1+=V0*(5*d1),c0=q1>>>13,q1&=8191,q1+=w0*(5*l1),q1+=H0*(5*F1),q1+=q0*(5*_),q1+=K0*(5*B1),q1+=N1*(5*E1),c0+=q1>>>13,q1&=8191,I1=c0,I1+=n0*E1,I1+=s0*L1,I1+=v0*(5*b1),I1+=Z0*(5*h1),I1+=V0*(5*$1),c0=I1>>>13,I1&=8191,I1+=w0*(5*d1),I1+=H0*(5*l1),I1+=q0*(5*F1),I1+=K0*(5*_),I1+=N1*(5*B1),c0+=I1>>>13,I1&=8191,P1=c0,P1+=n0*B1,P1+=s0*E1,P1+=v0*L1,P1+=Z0*(5*b1),P1+=V0*(5*h1),c0=P1>>>13,P1&=8191,P1+=w0*(5*$1),P1+=H0*(5*d1),P1+=q0*(5*l1),P1+=K0*(5*F1),P1+=N1*(5*_),c0+=P1>>>13,P1&=8191,T1=c0,T1+=n0*_,T1+=s0*B1,T1+=v0*E1,T1+=Z0*L1,T1+=V0*(5*b1),c0=T1>>>13,T1&=8191,T1+=w0*(5*h1),T1+=H0*(5*$1),T1+=q0*(5*d1),T1+=K0*(5*l1),T1+=N1*(5*F1),c0+=T1>>>13,T1&=8191,z1=c0,z1+=n0*F1,z1+=s0*_,z1+=v0*B1,z1+=Z0*E1,z1+=V0*L1,c0=z1>>>13,z1&=8191,z1+=w0*(5*b1),z1+=H0*(5*h1),z1+=q0*(5*$1),z1+=K0*(5*d1),z1+=N1*(5*l1),c0+=z1>>>13,z1&=8191,O1=c0,O1+=n0*l1,O1+=s0*F1,O1+=v0*_,O1+=Z0*B1,O1+=V0*E1,c0=O1>>>13,O1&=8191,O1+=w0*L1,O1+=H0*(5*b1),O1+=q0*(5*h1),O1+=K0*(5*$1),O1+=N1*(5*d1),c0+=O1>>>13,O1&=8191,w1=c0,w1+=n0*d1,w1+=s0*l1,w1+=v0*F1,w1+=Z0*_,w1+=V0*B1,c0=w1>>>13,w1&=8191,w1+=w0*E1,w1+=H0*L1,w1+=q0*(5*b1),w1+=K0*(5*h1),w1+=N1*(5*$1),c0+=w1>>>13,w1&=8191,d0=c0,d0+=n0*$1,d0+=s0*d1,d0+=v0*l1,d0+=Z0*F1,d0+=V0*_,c0=d0>>>13,d0&=8191,d0+=w0*B1,d0+=H0*E1,d0+=q0*L1,d0+=K0*(5*b1),d0+=N1*(5*h1),c0+=d0>>>13,d0&=8191,Y1=c0,Y1+=n0*h1,Y1+=s0*$1,Y1+=v0*d1,Y1+=Z0*l1,Y1+=V0*F1,c0=Y1>>>13,Y1&=8191,Y1+=w0*_,Y1+=H0*B1,Y1+=q0*E1,Y1+=K0*L1,Y1+=N1*(5*b1),c0+=Y1>>>13,Y1&=8191,h0=c0,h0+=n0*b1,h0+=s0*h1,h0+=v0*$1,h0+=Z0*d1,h0+=V0*l1,c0=h0>>>13,h0&=8191,h0+=w0*F1,h0+=H0*_,h0+=q0*B1,h0+=K0*E1,h0+=N1*L1,c0+=h0>>>13,h0&=8191,c0=(c0<<2)+c0|0,c0=c0+q1|0,q1=c0&8191,c0=c0>>>13,I1+=c0,n0=q1,s0=I1,v0=P1,Z0=T1,V0=z1,w0=O1,H0=w1,q0=d0,K0=Y1,N1=h0,R+=16,C-=16;this.h[0]=n0,this.h[1]=s0,this.h[2]=v0,this.h[3]=Z0,this.h[4]=V0,this.h[5]=w0,this.h[6]=H0,this.h[7]=q0,this.h[8]=K0,this.h[9]=N1},J0.prototype.finish=function(O,R){var C=new Uint16Array(10),I,L,o,s;if(this.leftover){s=this.leftover,this.buffer[s++]=1;for(;s<16;s++)this.buffer[s]=0;this.fin=1,this.blocks(this.buffer,0,16)}I=this.h[1]>>>13,this.h[1]&=8191;for(s=2;s<10;s++)this.h[s]+=I,I=this.h[s]>>>13,this.h[s]&=8191;this.h[0]+=I*5,I=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=I,I=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=I,C[0]=this.h[0]+5,I=C[0]>>>13,C[0]&=8191;for(s=1;s<10;s++)C[s]=this.h[s]+I,I=C[s]>>>13,C[s]&=8191;C[9]-=8192,L=(I^1)-1;for(s=0;s<10;s++)C[s]&=L;L=~L;for(s=0;s<10;s++)this.h[s]=this.h[s]&L|C[s];this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,o=this.h[0]+this.pad[0],this.h[0]=o&65535;for(s=1;s<8;s++)o=(this.h[s]+this.pad[s]|0)+(o>>>16)|0,this.h[s]=o&65535;O[R+0]=this.h[0]>>>0&255,O[R+1]=this.h[0]>>>8&255,O[R+2]=this.h[1]>>>0&255,O[R+3]=this.h[1]>>>8&255,O[R+4]=this.h[2]>>>0&255,O[R+5]=this.h[2]>>>8&255,O[R+6]=this.h[3]>>>0&255,O[R+7]=this.h[3]>>>8&255,O[R+8]=this.h[4]>>>0&255,O[R+9]=this.h[4]>>>8&255,O[R+10]=this.h[5]>>>0&255,O[R+11]=this.h[5]>>>8&255,O[R+12]=this.h[6]>>>0&255,O[R+13]=this.h[6]>>>8&255,O[R+14]=this.h[7]>>>0&255,O[R+15]=this.h[7]>>>8&255},J0.prototype.update=function(O,R,C){var I,L;if(this.leftover){if(L=16-this.leftover,L>C)L=C;for(I=0;I<L;I++)this.buffer[this.leftover+I]=O[R+I];if(C-=L,R+=L,this.leftover+=L,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(C>=16)L=C-C%16,this.blocks(O,R,L),R+=L,C-=L;if(C){for(I=0;I<C;I++)this.buffer[this.leftover+I]=O[R+I];this.leftover+=C}};function A0(O,R,C,I,L,o){var s=new J0(o);return s.update(C,I,L),s.finish(O,R),0}function k(O,R,C,I,L,o){var s=new Uint8Array(16);return A0(s,0,C,I,L,o),D(O,R,s,0)}function l(O,R,C,I,L){var o;if(C<32)return-1;u(O,0,R,0,C,I,L),A0(O,16,O,32,C-32,O);for(o=0;o<16;o++)O[o]=0;return 0}function B(O,R,C,I,L){var o,s=new Uint8Array(32);if(C<32)return-1;if(W0(s,0,32,I,L),k(R,16,R,32,C-32,s)!==0)return-1;u(O,0,R,0,C,I,L);for(o=0;o<32;o++)O[o]=0;return 0}function $(O,R){var C;for(C=0;C<16;C++)O[C]=R[C]|0}function h(O){var R,C,I=1;for(R=0;R<16;R++)C=O[R]+I+65535,I=Math.floor(C/65536),O[R]=C-I*65536;O[0]+=I-1+37*(I-1)}function a(O,R,C){var I,L=~(C-1);for(var o=0;o<16;o++)I=L&(O[o]^R[o]),O[o]^=I,R[o]^=I}function n(O,R){var C,I,L,o=Y(),s=Y();for(C=0;C<16;C++)s[C]=R[C];h(s),h(s),h(s);for(I=0;I<2;I++){o[0]=s[0]-65517;for(C=1;C<15;C++)o[C]=s[C]-65535-(o[C-1]>>16&1),o[C-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),L=o[15]>>16&1,o[14]&=65535,a(s,o,1-L)}for(C=0;C<16;C++)O[2*C]=s[C]&255,O[2*C+1]=s[C]>>8}function E(O,R){var C=new Uint8Array(32),I=new Uint8Array(32);return n(C,O),n(I,R),T(C,0,I,0)}function P(O){var R=new Uint8Array(32);return n(R,O),R[0]&1}function v(O,R){var C;for(C=0;C<16;C++)O[C]=R[2*C]+(R[2*C+1]<<8);O[15]&=32767}function M(O,R,C){for(var I=0;I<16;I++)O[I]=R[I]+C[I]}function F(O,R,C){for(var I=0;I<16;I++)O[I]=R[I]-C[I]}function c(O,R,C){var I,L,o=0,s=0,N0=0,R0=0,t0=0,u0=0,p1=0,c0=0,q1=0,I1=0,P1=0,T1=0,z1=0,O1=0,w1=0,d0=0,Y1=0,h0=0,n0=0,s0=0,v0=0,Z0=0,V0=0,w0=0,H0=0,q0=0,K0=0,N1=0,L1=0,E1=0,B1=0,_=C[0],F1=C[1],l1=C[2],d1=C[3],$1=C[4],h1=C[5],b1=C[6],S8=C[7],e1=C[8],C8=C[9],T8=C[10],R8=C[11],h8=C[12],Q9=C[13],H9=C[14],N9=C[15];I=R[0],o+=I*_,s+=I*F1,N0+=I*l1,R0+=I*d1,t0+=I*$1,u0+=I*h1,p1+=I*b1,c0+=I*S8,q1+=I*e1,I1+=I*C8,P1+=I*T8,T1+=I*R8,z1+=I*h8,O1+=I*Q9,w1+=I*H9,d0+=I*N9,I=R[1],s+=I*_,N0+=I*F1,R0+=I*l1,t0+=I*d1,u0+=I*$1,p1+=I*h1,c0+=I*b1,q1+=I*S8,I1+=I*e1,P1+=I*C8,T1+=I*T8,z1+=I*R8,O1+=I*h8,w1+=I*Q9,d0+=I*H9,Y1+=I*N9,I=R[2],N0+=I*_,R0+=I*F1,t0+=I*l1,u0+=I*d1,p1+=I*$1,c0+=I*h1,q1+=I*b1,I1+=I*S8,P1+=I*e1,T1+=I*C8,z1+=I*T8,O1+=I*R8,w1+=I*h8,d0+=I*Q9,Y1+=I*H9,h0+=I*N9,I=R[3],R0+=I*_,t0+=I*F1,u0+=I*l1,p1+=I*d1,c0+=I*$1,q1+=I*h1,I1+=I*b1,P1+=I*S8,T1+=I*e1,z1+=I*C8,O1+=I*T8,w1+=I*R8,d0+=I*h8,Y1+=I*Q9,h0+=I*H9,n0+=I*N9,I=R[4],t0+=I*_,u0+=I*F1,p1+=I*l1,c0+=I*d1,q1+=I*$1,I1+=I*h1,P1+=I*b1,T1+=I*S8,z1+=I*e1,O1+=I*C8,w1+=I*T8,d0+=I*R8,Y1+=I*h8,h0+=I*Q9,n0+=I*H9,s0+=I*N9,I=R[5],u0+=I*_,p1+=I*F1,c0+=I*l1,q1+=I*d1,I1+=I*$1,P1+=I*h1,T1+=I*b1,z1+=I*S8,O1+=I*e1,w1+=I*C8,d0+=I*T8,Y1+=I*R8,h0+=I*h8,n0+=I*Q9,s0+=I*H9,v0+=I*N9,I=R[6],p1+=I*_,c0+=I*F1,q1+=I*l1,I1+=I*d1,P1+=I*$1,T1+=I*h1,z1+=I*b1,O1+=I*S8,w1+=I*e1,d0+=I*C8,Y1+=I*T8,h0+=I*R8,n0+=I*h8,s0+=I*Q9,v0+=I*H9,Z0+=I*N9,I=R[7],c0+=I*_,q1+=I*F1,I1+=I*l1,P1+=I*d1,T1+=I*$1,z1+=I*h1,O1+=I*b1,w1+=I*S8,d0+=I*e1,Y1+=I*C8,h0+=I*T8,n0+=I*R8,s0+=I*h8,v0+=I*Q9,Z0+=I*H9,V0+=I*N9,I=R[8],q1+=I*_,I1+=I*F1,P1+=I*l1,T1+=I*d1,z1+=I*$1,O1+=I*h1,w1+=I*b1,d0+=I*S8,Y1+=I*e1,h0+=I*C8,n0+=I*T8,s0+=I*R8,v0+=I*h8,Z0+=I*Q9,V0+=I*H9,w0+=I*N9,I=R[9],I1+=I*_,P1+=I*F1,T1+=I*l1,z1+=I*d1,O1+=I*$1,w1+=I*h1,d0+=I*b1,Y1+=I*S8,h0+=I*e1,n0+=I*C8,s0+=I*T8,v0+=I*R8,Z0+=I*h8,V0+=I*Q9,w0+=I*H9,H0+=I*N9,I=R[10],P1+=I*_,T1+=I*F1,z1+=I*l1,O1+=I*d1,w1+=I*$1,d0+=I*h1,Y1+=I*b1,h0+=I*S8,n0+=I*e1,s0+=I*C8,v0+=I*T8,Z0+=I*R8,V0+=I*h8,w0+=I*Q9,H0+=I*H9,q0+=I*N9,I=R[11],T1+=I*_,z1+=I*F1,O1+=I*l1,w1+=I*d1,d0+=I*$1,Y1+=I*h1,h0+=I*b1,n0+=I*S8,s0+=I*e1,v0+=I*C8,Z0+=I*T8,V0+=I*R8,w0+=I*h8,H0+=I*Q9,q0+=I*H9,K0+=I*N9,I=R[12],z1+=I*_,O1+=I*F1,w1+=I*l1,d0+=I*d1,Y1+=I*$1,h0+=I*h1,n0+=I*b1,s0+=I*S8,v0+=I*e1,Z0+=I*C8,V0+=I*T8,w0+=I*R8,H0+=I*h8,q0+=I*Q9,K0+=I*H9,N1+=I*N9,I=R[13],O1+=I*_,w1+=I*F1,d0+=I*l1,Y1+=I*d1,h0+=I*$1,n0+=I*h1,s0+=I*b1,v0+=I*S8,Z0+=I*e1,V0+=I*C8,w0+=I*T8,H0+=I*R8,q0+=I*h8,K0+=I*Q9,N1+=I*H9,L1+=I*N9,I=R[14],w1+=I*_,d0+=I*F1,Y1+=I*l1,h0+=I*d1,n0+=I*$1,s0+=I*h1,v0+=I*b1,Z0+=I*S8,V0+=I*e1,w0+=I*C8,H0+=I*T8,q0+=I*R8,K0+=I*h8,N1+=I*Q9,L1+=I*H9,E1+=I*N9,I=R[15],d0+=I*_,Y1+=I*F1,h0+=I*l1,n0+=I*d1,s0+=I*$1,v0+=I*h1,Z0+=I*b1,V0+=I*S8,w0+=I*e1,H0+=I*C8,q0+=I*T8,K0+=I*R8,N1+=I*h8,L1+=I*Q9,E1+=I*H9,B1+=I*N9,o+=38*Y1,s+=38*h0,N0+=38*n0,R0+=38*s0,t0+=38*v0,u0+=38*Z0,p1+=38*V0,c0+=38*w0,q1+=38*H0,I1+=38*q0,P1+=38*K0,T1+=38*N1,z1+=38*L1,O1+=38*E1,w1+=38*B1,L=1,I=o+L+65535,L=Math.floor(I/65536),o=I-L*65536,I=s+L+65535,L=Math.floor(I/65536),s=I-L*65536,I=N0+L+65535,L=Math.floor(I/65536),N0=I-L*65536,I=R0+L+65535,L=Math.floor(I/65536),R0=I-L*65536,I=t0+L+65535,L=Math.floor(I/65536),t0=I-L*65536,I=u0+L+65535,L=Math.floor(I/65536),u0=I-L*65536,I=p1+L+65535,L=Math.floor(I/65536),p1=I-L*65536,I=c0+L+65535,L=Math.floor(I/65536),c0=I-L*65536,I=q1+L+65535,L=Math.floor(I/65536),q1=I-L*65536,I=I1+L+65535,L=Math.floor(I/65536),I1=I-L*65536,I=P1+L+65535,L=Math.floor(I/65536),P1=I-L*65536,I=T1+L+65535,L=Math.floor(I/65536),T1=I-L*65536,I=z1+L+65535,L=Math.floor(I/65536),z1=I-L*65536,I=O1+L+65535,L=Math.floor(I/65536),O1=I-L*65536,I=w1+L+65535,L=Math.floor(I/65536),w1=I-L*65536,I=d0+L+65535,L=Math.floor(I/65536),d0=I-L*65536,o+=L-1+37*(L-1),L=1,I=o+L+65535,L=Math.floor(I/65536),o=I-L*65536,I=s+L+65535,L=Math.floor(I/65536),s=I-L*65536,I=N0+L+65535,L=Math.floor(I/65536),N0=I-L*65536,I=R0+L+65535,L=Math.floor(I/65536),R0=I-L*65536,I=t0+L+65535,L=Math.floor(I/65536),t0=I-L*65536,I=u0+L+65535,L=Math.floor(I/65536),u0=I-L*65536,I=p1+L+65535,L=Math.floor(I/65536),p1=I-L*65536,I=c0+L+65535,L=Math.floor(I/65536),c0=I-L*65536,I=q1+L+65535,L=Math.floor(I/65536),q1=I-L*65536,I=I1+L+65535,L=Math.floor(I/65536),I1=I-L*65536,I=P1+L+65535,L=Math.floor(I/65536),P1=I-L*65536,I=T1+L+65535,L=Math.floor(I/65536),T1=I-L*65536,I=z1+L+65535,L=Math.floor(I/65536),z1=I-L*65536,I=O1+L+65535,L=Math.floor(I/65536),O1=I-L*65536,I=w1+L+65535,L=Math.floor(I/65536),w1=I-L*65536,I=d0+L+65535,L=Math.floor(I/65536),d0=I-L*65536,o+=L-1+37*(L-1),O[0]=o,O[1]=s,O[2]=N0,O[3]=R0,O[4]=t0,O[5]=u0,O[6]=p1,O[7]=c0,O[8]=q1,O[9]=I1,O[10]=P1,O[11]=T1,O[12]=z1,O[13]=O1,O[14]=w1,O[15]=d0}function t(O,R){c(O,R,R)}function Y0(O,R){var C=Y(),I;for(I=0;I<16;I++)C[I]=R[I];for(I=253;I>=0;I--)if(t(C,C),I!==2&&I!==4)c(C,C,R);for(I=0;I<16;I++)O[I]=C[I]}function $0(O,R){var C=Y(),I;for(I=0;I<16;I++)C[I]=R[I];for(I=250;I>=0;I--)if(t(C,C),I!==1)c(C,C,R);for(I=0;I<16;I++)O[I]=C[I]}function S0(O,R,C){var I=new Uint8Array(32),L=new Float64Array(80),o,s,N0=Y(),R0=Y(),t0=Y(),u0=Y(),p1=Y(),c0=Y();for(s=0;s<31;s++)I[s]=R[s];I[31]=R[31]&127|64,I[0]&=248,v(L,C);for(s=0;s<16;s++)R0[s]=L[s],u0[s]=N0[s]=t0[s]=0;N0[0]=u0[0]=1;for(s=254;s>=0;--s)o=I[s>>>3]>>>(s&7)&1,a(N0,R0,o),a(t0,u0,o),M(p1,N0,t0),F(N0,N0,t0),M(t0,R0,u0),F(R0,R0,u0),t(u0,p1),t(c0,N0),c(N0,t0,N0),c(t0,R0,p1),M(p1,N0,t0),F(N0,N0,t0),t(R0,N0),F(t0,u0,c0),c(N0,t0,U),M(N0,N0,u0),c(t0,t0,N0),c(N0,u0,c0),c(u0,R0,L),t(R0,p1),a(N0,R0,o),a(t0,u0,o);for(s=0;s<16;s++)L[s+16]=N0[s],L[s+32]=t0[s],L[s+48]=R0[s],L[s+64]=u0[s];var q1=L.subarray(32),I1=L.subarray(16);return Y0(q1,q1),c(I1,I1,q1),n(O,I1),0}function x0(O,R){return S0(O,R,J)}function D1(O,R){return G(R,32),x0(O,R)}function b0(O,R,C){var I=new Uint8Array(32);return S0(I,C,R),y(O,X,I,p)}var Q0=l,O0=B;function y0(O,R,C,I,L,o){var s=new Uint8Array(32);return b0(s,L,o),Q0(O,R,C,I,s)}function X0(O,R,C,I,L,o){var s=new Uint8Array(32);return b0(s,L,o),O0(O,R,C,I,s)}var D0=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function L0(O,R,C,I){var L=new Int32Array(16),o=new Int32Array(16),s,N0,R0,t0,u0,p1,c0,q1,I1,P1,T1,z1,O1,w1,d0,Y1,h0,n0,s0,v0,Z0,V0,w0,H0,q0,K0,N1=O[0],L1=O[1],E1=O[2],B1=O[3],_=O[4],F1=O[5],l1=O[6],d1=O[7],$1=R[0],h1=R[1],b1=R[2],S8=R[3],e1=R[4],C8=R[5],T8=R[6],R8=R[7],h8=0;while(I>=128){for(s0=0;s0<16;s0++)v0=8*s0+h8,L[s0]=C[v0+0]<<24|C[v0+1]<<16|C[v0+2]<<8|C[v0+3],o[s0]=C[v0+4]<<24|C[v0+5]<<16|C[v0+6]<<8|C[v0+7];for(s0=0;s0<80;s0++)if(s=N1,N0=L1,R0=E1,t0=B1,u0=_,p1=F1,c0=l1,q1=d1,I1=$1,P1=h1,T1=b1,z1=S8,O1=e1,w1=C8,d0=T8,Y1=R8,Z0=d1,V0=R8,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=(_>>>14|e1<<18)^(_>>>18|e1<<14)^(e1>>>9|_<<23),V0=(e1>>>14|_<<18)^(e1>>>18|_<<14)^(_>>>9|e1<<23),w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,Z0=_&F1^~_&l1,V0=e1&C8^~e1&T8,w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,Z0=D0[s0*2],V0=D0[s0*2+1],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,Z0=L[s0%16],V0=o[s0%16],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,h0=q0&65535|K0<<16,n0=w0&65535|H0<<16,Z0=h0,V0=n0,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=(N1>>>28|$1<<4)^($1>>>2|N1<<30)^($1>>>7|N1<<25),V0=($1>>>28|N1<<4)^(N1>>>2|$1<<30)^(N1>>>7|$1<<25),w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,Z0=N1&L1^N1&E1^L1&E1,V0=$1&h1^$1&b1^h1&b1,w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,q1=q0&65535|K0<<16,Y1=w0&65535|H0<<16,Z0=t0,V0=z1,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=h0,V0=n0,w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,t0=q0&65535|K0<<16,z1=w0&65535|H0<<16,L1=s,E1=N0,B1=R0,_=t0,F1=u0,l1=p1,d1=c0,N1=q1,h1=I1,b1=P1,S8=T1,e1=z1,C8=O1,T8=w1,R8=d0,$1=Y1,s0%16===15)for(v0=0;v0<16;v0++)Z0=L[v0],V0=o[v0],w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=L[(v0+9)%16],V0=o[(v0+9)%16],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,h0=L[(v0+1)%16],n0=o[(v0+1)%16],Z0=(h0>>>1|n0<<31)^(h0>>>8|n0<<24)^h0>>>7,V0=(n0>>>1|h0<<31)^(n0>>>8|h0<<24)^(n0>>>7|h0<<25),w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,h0=L[(v0+14)%16],n0=o[(v0+14)%16],Z0=(h0>>>19|n0<<13)^(n0>>>29|h0<<3)^h0>>>6,V0=(n0>>>19|h0<<13)^(h0>>>29|n0<<3)^(n0>>>6|h0<<26),w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,L[v0]=q0&65535|K0<<16,o[v0]=w0&65535|H0<<16;Z0=N1,V0=$1,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[0],V0=R[0],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[0]=N1=q0&65535|K0<<16,R[0]=$1=w0&65535|H0<<16,Z0=L1,V0=h1,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[1],V0=R[1],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[1]=L1=q0&65535|K0<<16,R[1]=h1=w0&65535|H0<<16,Z0=E1,V0=b1,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[2],V0=R[2],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[2]=E1=q0&65535|K0<<16,R[2]=b1=w0&65535|H0<<16,Z0=B1,V0=S8,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[3],V0=R[3],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[3]=B1=q0&65535|K0<<16,R[3]=S8=w0&65535|H0<<16,Z0=_,V0=e1,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[4],V0=R[4],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[4]=_=q0&65535|K0<<16,R[4]=e1=w0&65535|H0<<16,Z0=F1,V0=C8,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[5],V0=R[5],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[5]=F1=q0&65535|K0<<16,R[5]=C8=w0&65535|H0<<16,Z0=l1,V0=T8,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[6],V0=R[6],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[6]=l1=q0&65535|K0<<16,R[6]=T8=w0&65535|H0<<16,Z0=d1,V0=R8,w0=V0&65535,H0=V0>>>16,q0=Z0&65535,K0=Z0>>>16,Z0=O[7],V0=R[7],w0+=V0&65535,H0+=V0>>>16,q0+=Z0&65535,K0+=Z0>>>16,H0+=w0>>>16,q0+=H0>>>16,K0+=q0>>>16,O[7]=d1=q0&65535|K0<<16,R[7]=R8=w0&65535|H0<<16,h8+=128,I-=128}return I}function I0(O,R,C){var I=new Int32Array(8),L=new Int32Array(8),o=new Uint8Array(256),s,N0=C;I[0]=1779033703,I[1]=3144134277,I[2]=1013904242,I[3]=2773480762,I[4]=1359893119,I[5]=2600822924,I[6]=528734635,I[7]=1541459225,L[0]=4089235720,L[1]=2227873595,L[2]=4271175723,L[3]=1595750129,L[4]=2917565137,L[5]=725511199,L[6]=4215389547,L[7]=327033209,L0(I,L,R,C),C%=128;for(s=0;s<C;s++)o[s]=R[N0-C+s];o[C]=128,C=256-128*(C<112?1:0),o[C-9]=0,z(o,C-8,N0/536870912|0,N0<<3),L0(I,L,o,C);for(s=0;s<8;s++)z(O,8*s,I[s],L[s]);return 0}function F0(O,R){var C=Y(),I=Y(),L=Y(),o=Y(),s=Y(),N0=Y(),R0=Y(),t0=Y(),u0=Y();F(C,O[1],O[0]),F(u0,R[1],R[0]),c(C,C,u0),M(I,O[0],O[1]),M(u0,R[0],R[1]),c(I,I,u0),c(L,O[3],R[3]),c(L,L,H),c(o,O[2],R[2]),M(o,o,o),F(s,I,C),F(N0,o,L),M(R0,o,L),M(t0,I,C),c(O[0],s,N0),c(O[1],t0,R0),c(O[2],R0,N0),c(O[3],s,t0)}function V1(O,R,C){var I;for(I=0;I<4;I++)a(O[I],R[I],C)}function H1(O,R){var C=Y(),I=Y(),L=Y();Y0(L,R[2]),c(C,R[0],L),c(I,R[1],L),n(O,I),O[31]^=P(C)<<7}function f1(O,R,C){var I,L;$(O[0],Z),$(O[1],V),$(O[2],V),$(O[3],Z);for(L=255;L>=0;--L)I=C[L/8|0]>>(L&7)&1,V1(O,R,I),F0(R,O),F0(O,O),V1(O,R,I)}function i1(O,R){var C=[Y(),Y(),Y(),Y()];$(C[0],N),$(C[1],A),$(C[2],V),c(C[3],N,A),f1(O,C,R)}function r0(O,R,C){var I=new Uint8Array(64),L=[Y(),Y(),Y(),Y()],o;if(!C)G(R,32);I0(I,R,32),I[0]&=248,I[31]&=127,I[31]|=64,i1(L,I),H1(O,L);for(o=0;o<32;o++)R[o+32]=O[o];return 0}var x1=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function i0(O,R){var C,I,L,o;for(I=63;I>=32;--I){C=0;for(L=I-32,o=I-12;L<o;++L)R[L]+=C-16*R[I]*x1[L-(I-32)],C=Math.floor((R[L]+128)/256),R[L]-=C*256;R[L]+=C,R[I]=0}C=0;for(L=0;L<32;L++)R[L]+=C-(R[31]>>4)*x1[L],C=R[L]>>8,R[L]&=255;for(L=0;L<32;L++)R[L]-=C*x1[L];for(I=0;I<32;I++)R[I+1]+=R[I]>>8,O[I]=R[I]&255}function V8(O){var R=new Float64Array(64),C;for(C=0;C<64;C++)R[C]=O[C];for(C=0;C<64;C++)O[C]=0;i0(O,R)}function F8(O,R,C,I){var L=new Uint8Array(64),o=new Uint8Array(64),s=new Uint8Array(64),N0,R0,t0=new Float64Array(64),u0=[Y(),Y(),Y(),Y()];I0(L,I,32),L[0]&=248,L[31]&=127,L[31]|=64;var p1=C+64;for(N0=0;N0<C;N0++)O[64+N0]=R[N0];for(N0=0;N0<32;N0++)O[32+N0]=L[32+N0];I0(s,O.subarray(32),C+32),V8(s),i1(u0,s),H1(O,u0);for(N0=32;N0<64;N0++)O[N0]=I[N0];I0(o,O,C+64),V8(o);for(N0=0;N0<64;N0++)t0[N0]=0;for(N0=0;N0<32;N0++)t0[N0]=s[N0];for(N0=0;N0<32;N0++)for(R0=0;R0<32;R0++)t0[N0+R0]+=o[N0]*L[R0];return i0(O.subarray(32),t0),p1}function $9(O,R){var C=Y(),I=Y(),L=Y(),o=Y(),s=Y(),N0=Y(),R0=Y();if($(O[2],V),v(O[1],R),t(L,O[1]),c(o,L,Q),F(L,L,O[2]),M(o,O[2],o),t(s,o),t(N0,s),c(R0,N0,s),c(C,R0,L),c(C,C,o),$0(C,C),c(C,C,L),c(C,C,o),c(C,C,o),c(O[0],C,o),t(I,O[0]),c(I,I,o),E(I,L))c(O[0],O[0],q);if(t(I,O[0]),c(I,I,o),E(I,L))return-1;if(P(O[0])===R[31]>>7)F(O[0],Z,O[0]);return c(O[3],O[0],O[1]),0}function Q7(O,R,C,I){var L,o=new Uint8Array(32),s=new Uint8Array(64),N0=[Y(),Y(),Y(),Y()],R0=[Y(),Y(),Y(),Y()];if(C<64)return-1;if($9(R0,I))return-1;for(L=0;L<C;L++)O[L]=R[L];for(L=0;L<32;L++)O[L+32]=I[L];if(I0(s,O,C),V8(s),f1(N0,R0,s),i1(R0,R.subarray(32)),F0(N0,R0),H1(o,N0),C-=64,T(R,0,o,0)){for(L=0;L<C;L++)O[L]=0;return-1}for(L=0;L<C;L++)O[L]=R[L+64];return C}var d=32,e=24,U0=32,T0=16,e0=32,U8=32,q8=32,C1=32,k0=32,m0=e,l0=U0,a0=T0,A1=64,c1=32,Y8=64,F9=32,cY=64;W.lowlevel={crypto_core_hsalsa20:y,crypto_stream_xor:u,crypto_stream:W0,crypto_stream_salsa20_xor:b,crypto_stream_salsa20:m,crypto_onetimeauth:A0,crypto_onetimeauth_verify:k,crypto_verify_16:D,crypto_verify_32:T,crypto_secretbox:l,crypto_secretbox_open:B,crypto_scalarmult:S0,crypto_scalarmult_base:x0,crypto_box_beforenm:b0,crypto_box_afternm:Q0,crypto_box:y0,crypto_box_open:X0,crypto_box_keypair:D1,crypto_hash:I0,crypto_sign:F8,crypto_sign_keypair:r0,crypto_sign_open:Q7,crypto_secretbox_KEYBYTES:d,crypto_secretbox_NONCEBYTES:e,crypto_secretbox_ZEROBYTES:U0,crypto_secretbox_BOXZEROBYTES:T0,crypto_scalarmult_BYTES:e0,crypto_scalarmult_SCALARBYTES:U8,crypto_box_PUBLICKEYBYTES:q8,crypto_box_SECRETKEYBYTES:C1,crypto_box_BEFORENMBYTES:k0,crypto_box_NONCEBYTES:m0,crypto_box_ZEROBYTES:l0,crypto_box_BOXZEROBYTES:a0,crypto_sign_BYTES:A1,crypto_sign_PUBLICKEYBYTES:c1,crypto_sign_SECRETKEYBYTES:Y8,crypto_sign_SEEDBYTES:F9,crypto_hash_BYTES:cY,gf:Y,D:Q,L:x1,pack25519:n,unpack25519:v,M:c,A:M,S:t,Z:F,pow2523:$0,add:F0,set25519:$,modL:i0,scalarmult:f1,scalarbase:i1};function _U(O,R){if(O.length!==d)throw Error("bad key size");if(R.length!==e)throw Error("bad nonce size")}function QA(O,R){if(O.length!==q8)throw Error("bad public key size");if(R.length!==C1)throw Error("bad secret key size")}function e9(){for(var O=0;O<arguments.length;O++)if(!(arguments[O]instanceof Uint8Array))throw TypeError("unexpected type, use Uint8Array")}function UD(O){for(var R=0;R<O.length;R++)O[R]=0}W.randomBytes=function(O){var R=new Uint8Array(O);return G(R,O),R},W.secretbox=function(O,R,C){e9(O,R,C),_U(C,R);var I=new Uint8Array(U0+O.length),L=new Uint8Array(I.length);for(var o=0;o<O.length;o++)I[o+U0]=O[o];return l(L,I,I.length,R,C),L.subarray(T0)},W.secretbox.open=function(O,R,C){e9(O,R,C),_U(C,R);var I=new Uint8Array(T0+O.length),L=new Uint8Array(I.length);for(var o=0;o<O.length;o++)I[o+T0]=O[o];if(I.length<32)return null;if(B(L,I,I.length,R,C)!==0)return null;return L.subarray(U0)},W.secretbox.keyLength=d,W.secretbox.nonceLength=e,W.secretbox.overheadLength=T0,W.scalarMult=function(O,R){if(e9(O,R),O.length!==U8)throw Error("bad n size");if(R.length!==e0)throw Error("bad p size");var C=new Uint8Array(e0);return S0(C,O,R),C},W.scalarMult.base=function(O){if(e9(O),O.length!==U8)throw Error("bad n size");var R=new Uint8Array(e0);return x0(R,O),R},W.scalarMult.scalarLength=U8,W.scalarMult.groupElementLength=e0,W.box=function(O,R,C,I){var L=W.box.before(C,I);return W.secretbox(O,R,L)},W.box.before=function(O,R){e9(O,R),QA(O,R);var C=new Uint8Array(k0);return b0(C,O,R),C},W.box.after=W.secretbox,W.box.open=function(O,R,C,I){var L=W.box.before(C,I);return W.secretbox.open(O,R,L)},W.box.open.after=W.secretbox.open,W.box.keyPair=function(){var O=new Uint8Array(q8),R=new Uint8Array(C1);return D1(O,R),{publicKey:O,secretKey:R}},W.box.keyPair.fromSecretKey=function(O){if(e9(O),O.length!==C1)throw Error("bad secret key size");var R=new Uint8Array(q8);return x0(R,O),{publicKey:R,secretKey:new Uint8Array(O)}},W.box.publicKeyLength=q8,W.box.secretKeyLength=C1,W.box.sharedKeyLength=k0,W.box.nonceLength=m0,W.box.overheadLength=W.secretbox.overheadLength,W.sign=function(O,R){if(e9(O,R),R.length!==Y8)throw Error("bad secret key size");var C=new Uint8Array(A1+O.length);return F8(C,O,O.length,R),C},W.sign.open=function(O,R){if(e9(O,R),R.length!==c1)throw Error("bad public key size");var C=new Uint8Array(O.length),I=Q7(C,O,O.length,R);if(I<0)return null;var L=new Uint8Array(I);for(var o=0;o<L.length;o++)L[o]=C[o];return L},W.sign.detached=function(O,R){var C=W.sign(O,R),I=new Uint8Array(A1);for(var L=0;L<I.length;L++)I[L]=C[L];return I},W.sign.detached.verify=function(O,R,C){if(e9(O,R,C),R.length!==A1)throw Error("bad signature size");if(C.length!==c1)throw Error("bad public key size");var I=new Uint8Array(A1+O.length),L=new Uint8Array(A1+O.length),o;for(o=0;o<A1;o++)I[o]=R[o];for(o=0;o<O.length;o++)I[o+A1]=O[o];return Q7(L,I,I.length,C)>=0},W.sign.keyPair=function(){var O=new Uint8Array(c1),R=new Uint8Array(Y8);return r0(O,R),{publicKey:O,secretKey:R}},W.sign.keyPair.fromSecretKey=function(O){if(e9(O),O.length!==Y8)throw Error("bad secret key size");var R=new Uint8Array(c1);for(var C=0;C<R.length;C++)R[C]=O[32+C];return{publicKey:R,secretKey:new Uint8Array(O)}},W.sign.keyPair.fromSeed=function(O){if(e9(O),O.length!==F9)throw Error("bad seed size");var R=new Uint8Array(c1),C=new Uint8Array(Y8);for(var I=0;I<32;I++)C[I]=O[I];return r0(R,C,!0),{publicKey:R,secretKey:C}},W.sign.publicKeyLength=c1,W.sign.secretKeyLength=Y8,W.sign.seedLength=F9,W.sign.signatureLength=A1,W.hash=function(O){e9(O);var R=new Uint8Array(cY);return I0(R,O,O.length),R},W.hash.hashLength=cY,W.verify=function(O,R){if(e9(O,R),O.length===0||R.length===0)return!1;if(O.length!==R.length)return!1;return w(O,0,R,0,O.length)===0?!0:!1},W.setPRNG=function(O){G=O},function(){var O=typeof self<"u"?self.crypto||self.msCrypto:null;if(O&&O.getRandomValues){var R=65536;W.setPRNG(function(C,I){var L,o=new Uint8Array(I);for(L=0;L<I;L+=R)O.getRandomValues(o.subarray(L,L+Math.min(I-L,R)));for(L=0;L<I;L++)C[L]=o[L];UD(o)})}else if(O=x8("crypto"),O&&O.randomBytes)W.setPRNG(function(C,I){var L,o=O.randomBytes(I);for(L=0;L<I;L++)C[L]=o[L];UD(o)})}()})(typeof SQ<"u"&&fe?fe:self.nacl=self.nacl||{})});var BI=U1((QR)=>{Object.defineProperty(QR,"__esModule",{value:!0});class UR{constructor(W,Y=0,G=0){this.start=Y,this.end=G>Y?G:Y,this.buf=W}get length(){return this.buf.length}reset(W=0,Y=0){if(this.start=W,Y>=this.start)this.end=Y;else if(this.end<this.start)this.end=this.start;return this}walk(W){return this.start=this.end,this.end+=W,this}mustHas(W,Y="Too few bytes to parse."){let G=this.end+W;if(G>this.buf.length){let X=Error(Y);throw X.available=this.buf.length,X.requested=G,X}return this.walk(0),this}mustWalk(W,Y){return this.mustHas(W,Y),this.walk(W),this}}QR.BufferVisitor=UR});var AR=U1((qR)=>{Object.defineProperty(qR,"__esModule",{value:!0});var HR=x8("util"),NR=64,$I="-----BEGIN ",FI="-----END ",mJ="-----",EI="Proc-Type";class SI{static parse(W){let Y=[],G=W.toString("utf8").split(`
|
|
7
|
+
`).map((Y)=>Y.trim()).join(" ")};WR.O=function(W){return this.inspectOpts.colors=this.useColors,EQ.inspect(W,this.inspectOpts)}});var JR=U1((be,LI)=>{if(typeof process>"u"||process.type==="renderer"||!1||process.__nwjs)LI.exports=eT();else LI.exports=XR()});var FQ=U1((VR)=>{Object.defineProperty(VR,"__esModule",{value:!0});var Ib=x8("net");function zb(W){switch(Ib.isIP(W)){case 4:return Buffer.from(W.split(".").map((J)=>parseInt(J,10)));case 6:let Y=W.split(":"),G=Buffer.alloc(16),X=0;if(Y[Y.length-1]==="")Y[Y.length-1]="0";for(let J=0;J<Y.length;J++){if(Y[J]===""){if(J+1<Y.length&&Y[J+1]!=="")X=16-(Y.length-J-1)*2;continue}G.writeUInt16BE(parseInt(Y[J],16),X),X+=2}return G;default:return null}}VR.bytesFromIP=zb;function wb(W){switch(W.length){case 4:return[W[0],W[1],W[2],W[3]].join(".");case 16:let Y=[],G=-1,X=0,J=-1,Z=0;for(let V=0;V<W.length;V+=2){let U=W[V]<<8|W[V+1];if(U===0){if(X++,G===-1)G=Y.length;if(X>Z)Z=X,J=G}else G=-1,X=0;Y.push(U.toString(16))}if(Z>0){let V="",U=Y.slice(J+Z);if(Y.length=J,Y.length===0)V+=":";if(U.length===0)V+=":";Y.push(V,...U)}return Y.join(":");default:return""}}VR.bytesToIP=wb;var A6=Object.create(null),ZR=/^[0-9.]+$/;function jb(W){if(ZR.test(W)&&A6[W]!=="")return W;return A6[W]==null?"":A6[W]}VR.getOID=jb;function Ob(W){if(!ZR.test(W)&&A6[W]!=="")return W;return A6[W]==null?W:A6[W]}VR.getOIDName=Ob;function z0(W,Y){A6[W]=Y,A6[Y]=W}z0("1.2.840.113549.1.1.1","rsaEncryption");z0("1.2.840.113549.1.1.4","md5WithRsaEncryption");z0("1.2.840.113549.1.1.5","sha1WithRsaEncryption");z0("1.2.840.113549.1.1.8","mgf1");z0("1.2.840.113549.1.1.10","RSASSA-PSS");z0("1.2.840.113549.1.1.11","sha256WithRsaEncryption");z0("1.2.840.113549.1.1.12","sha384WithRsaEncryption");z0("1.2.840.113549.1.1.13","sha512WithRsaEncryption");z0("1.2.840.10045.2.1","ecEncryption");z0("1.2.840.10045.4.1","ecdsaWithSha1");z0("1.2.840.10045.4.3.2","ecdsaWithSha256");z0("1.2.840.10045.4.3.3","ecdsaWithSha384");z0("1.2.840.10045.4.3.4","ecdsaWithSha512");z0("1.2.840.10040.4.3","dsaWithSha1");z0("2.16.840.1.101.3.4.3.2","dsaWithSha256");z0("1.3.14.3.2.7","desCBC");z0("1.3.14.3.2.26","sha1");z0("2.16.840.1.101.3.4.2.1","sha256");z0("2.16.840.1.101.3.4.2.2","sha384");z0("2.16.840.1.101.3.4.2.3","sha512");z0("1.2.840.113549.2.5","md5");z0("1.3.101.110","X25519");z0("1.3.101.111","X448");z0("1.3.101.112","Ed25519");z0("1.3.101.113","Ed448");z0("1.2.840.113549.1.7.1","data");z0("1.2.840.113549.1.7.2","signedData");z0("1.2.840.113549.1.7.3","envelopedData");z0("1.2.840.113549.1.7.4","signedAndEnvelopedData");z0("1.2.840.113549.1.7.5","digestedData");z0("1.2.840.113549.1.7.6","encryptedData");z0("1.2.840.113549.1.9.1","emailAddress");z0("1.2.840.113549.1.9.2","unstructuredName");z0("1.2.840.113549.1.9.3","contentType");z0("1.2.840.113549.1.9.4","messageDigest");z0("1.2.840.113549.1.9.5","signingTime");z0("1.2.840.113549.1.9.6","counterSignature");z0("1.2.840.113549.1.9.7","challengePassword");z0("1.2.840.113549.1.9.8","unstructuredAddress");z0("1.2.840.113549.1.9.14","extensionRequest");z0("1.2.840.113549.1.9.20","friendlyName");z0("1.2.840.113549.1.9.21","localKeyId");z0("1.2.840.113549.1.9.22.1","x509Certificate");z0("1.2.840.113549.1.12.10.1.1","keyBag");z0("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");z0("1.2.840.113549.1.12.10.1.3","certBag");z0("1.2.840.113549.1.12.10.1.4","crlBag");z0("1.2.840.113549.1.12.10.1.5","secretBag");z0("1.2.840.113549.1.12.10.1.6","safeContentsBag");z0("1.2.840.113549.1.5.13","pkcs5PBES2");z0("1.2.840.113549.1.5.12","pkcs5PBKDF2");z0("1.2.840.113549.2.7","hmacWithSha1");z0("1.2.840.113549.2.9","hmacWithSha256");z0("1.2.840.113549.2.10","hmacWithSha384");z0("1.2.840.113549.2.11","hmacWithSha512");z0("1.2.840.113549.3.7","3desCBC");z0("2.16.840.1.101.3.4.1.2","aesCBC128");z0("2.16.840.1.101.3.4.1.42","aesCBC256");z0("2.5.4.3","commonName");z0("2.5.4.5","serialName");z0("2.5.4.6","countryName");z0("2.5.4.7","localityName");z0("2.5.4.8","stateOrProvinceName");z0("2.5.4.10","organizationName");z0("2.5.4.11","organizationalUnitName");z0("2.5.4.15","businessCategory");z0("2.16.840.1.113730.1.1","nsCertType");z0("2.5.29.2","keyAttributes");z0("2.5.29.4","keyUsageRestriction");z0("2.5.29.6","subtreesConstraint");z0("2.5.29.9","subjectDirectoryAttributes");z0("2.5.29.14","subjectKeyIdentifier");z0("2.5.29.15","keyUsage");z0("2.5.29.16","privateKeyUsagePeriod");z0("2.5.29.17","subjectAltName");z0("2.5.29.18","issuerAltName");z0("2.5.29.19","basicConstraints");z0("2.5.29.20","cRLNumber");z0("2.5.29.21","cRLReason");z0("2.5.29.22","expirationDate");z0("2.5.29.23","instructionCode");z0("2.5.29.24","invalidityDate");z0("2.5.29.27","deltaCRLIndicator");z0("2.5.29.28","issuingDistributionPoint");z0("2.5.29.29","certificateIssuer");z0("2.5.29.30","nameConstraints");z0("2.5.29.31","cRLDistributionPoints");z0("2.5.29.32","certificatePolicies");z0("2.5.29.33","policyMappings");z0("2.5.29.35","authorityKeyIdentifier");z0("2.5.29.36","policyConstraints");z0("2.5.29.37","extKeyUsage");z0("2.5.29.46","freshestCRL");z0("2.5.29.54","inhibitAnyPolicy");z0("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST");z0("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC");z0("1.3.6.1.4.1.11129.2.4.2","timestampList");z0("1.3.6.1.5.5.7.1.1","authorityInfoAccess");z0("1.3.6.1.5.5.7.3.1","serverAuth");z0("1.3.6.1.5.5.7.3.2","clientAuth");z0("1.3.6.1.5.5.7.3.3","codeSigning");z0("1.3.6.1.5.5.7.3.4","emailProtection");z0("1.3.6.1.5.5.7.3.8","timeStamping");z0("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp");z0("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")});var xQ=U1((fe,SQ)=>{(function(W){var Y=function(O){var R,C=new Float64Array(16);if(O)for(R=0;R<O.length;R++)C[R]=O[R];return C},G=function(){throw Error("no PRNG")},X=new Uint8Array(16),J=new Uint8Array(32);J[0]=9;var Z=Y(),V=Y([1]),U=Y([56129,1]),Q=Y([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),H=Y([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),N=Y([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),A=Y([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),q=Y([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function z(O,R,C,I){O[R]=C>>24&255,O[R+1]=C>>16&255,O[R+2]=C>>8&255,O[R+3]=C&255,O[R+4]=I>>24&255,O[R+5]=I>>16&255,O[R+6]=I>>8&255,O[R+7]=I&255}function w(O,R,C,I,L){var o,s=0;for(o=0;o<L;o++)s|=O[R+o]^C[I+o];return(1&s-1>>>8)-1}function D(O,R,C,I){return w(O,R,C,I,16)}function T(O,R,C,I){return w(O,R,C,I,32)}function x(O,R,C,I){var L=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,o=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,s=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,q0=C[8]&255|(C[9]&255)<<8|(C[10]&255)<<16|(C[11]&255)<<24,R0=C[12]&255|(C[13]&255)<<8|(C[14]&255)<<16|(C[15]&255)<<24,t0=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,u0=R[0]&255|(R[1]&255)<<8|(R[2]&255)<<16|(R[3]&255)<<24,p1=R[4]&255|(R[5]&255)<<8|(R[6]&255)<<16|(R[7]&255)<<24,c0=R[8]&255|(R[9]&255)<<8|(R[10]&255)<<16|(R[11]&255)<<24,q1=R[12]&255|(R[13]&255)<<8|(R[14]&255)<<16|(R[15]&255)<<24,I1=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,P1=C[16]&255|(C[17]&255)<<8|(C[18]&255)<<16|(C[19]&255)<<24,T1=C[20]&255|(C[21]&255)<<8|(C[22]&255)<<16|(C[23]&255)<<24,z1=C[24]&255|(C[25]&255)<<8|(C[26]&255)<<16|(C[27]&255)<<24,O1=C[28]&255|(C[29]&255)<<8|(C[30]&255)<<16|(C[31]&255)<<24,w1=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,d0=L,Y1=o,h0=s,n0=q0,s0=R0,v0=t0,Z0=u0,V0=p1,w0=c0,N0=q1,A0=I1,K0=P1,N1=T1,L1=z1,E1=O1,B1=w1,_;for(var F1=0;F1<20;F1+=2)_=d0+N1|0,s0^=_<<7|_>>>25,_=s0+d0|0,w0^=_<<9|_>>>23,_=w0+s0|0,N1^=_<<13|_>>>19,_=N1+w0|0,d0^=_<<18|_>>>14,_=v0+Y1|0,N0^=_<<7|_>>>25,_=N0+v0|0,L1^=_<<9|_>>>23,_=L1+N0|0,Y1^=_<<13|_>>>19,_=Y1+L1|0,v0^=_<<18|_>>>14,_=A0+Z0|0,E1^=_<<7|_>>>25,_=E1+A0|0,h0^=_<<9|_>>>23,_=h0+E1|0,Z0^=_<<13|_>>>19,_=Z0+h0|0,A0^=_<<18|_>>>14,_=B1+K0|0,n0^=_<<7|_>>>25,_=n0+B1|0,V0^=_<<9|_>>>23,_=V0+n0|0,K0^=_<<13|_>>>19,_=K0+V0|0,B1^=_<<18|_>>>14,_=d0+n0|0,Y1^=_<<7|_>>>25,_=Y1+d0|0,h0^=_<<9|_>>>23,_=h0+Y1|0,n0^=_<<13|_>>>19,_=n0+h0|0,d0^=_<<18|_>>>14,_=v0+s0|0,Z0^=_<<7|_>>>25,_=Z0+v0|0,V0^=_<<9|_>>>23,_=V0+Z0|0,s0^=_<<13|_>>>19,_=s0+V0|0,v0^=_<<18|_>>>14,_=A0+N0|0,K0^=_<<7|_>>>25,_=K0+A0|0,w0^=_<<9|_>>>23,_=w0+K0|0,N0^=_<<13|_>>>19,_=N0+w0|0,A0^=_<<18|_>>>14,_=B1+E1|0,N1^=_<<7|_>>>25,_=N1+B1|0,L1^=_<<9|_>>>23,_=L1+N1|0,E1^=_<<13|_>>>19,_=E1+L1|0,B1^=_<<18|_>>>14;d0=d0+L|0,Y1=Y1+o|0,h0=h0+s|0,n0=n0+q0|0,s0=s0+R0|0,v0=v0+t0|0,Z0=Z0+u0|0,V0=V0+p1|0,w0=w0+c0|0,N0=N0+q1|0,A0=A0+I1|0,K0=K0+P1|0,N1=N1+T1|0,L1=L1+z1|0,E1=E1+O1|0,B1=B1+w1|0,O[0]=d0>>>0&255,O[1]=d0>>>8&255,O[2]=d0>>>16&255,O[3]=d0>>>24&255,O[4]=Y1>>>0&255,O[5]=Y1>>>8&255,O[6]=Y1>>>16&255,O[7]=Y1>>>24&255,O[8]=h0>>>0&255,O[9]=h0>>>8&255,O[10]=h0>>>16&255,O[11]=h0>>>24&255,O[12]=n0>>>0&255,O[13]=n0>>>8&255,O[14]=n0>>>16&255,O[15]=n0>>>24&255,O[16]=s0>>>0&255,O[17]=s0>>>8&255,O[18]=s0>>>16&255,O[19]=s0>>>24&255,O[20]=v0>>>0&255,O[21]=v0>>>8&255,O[22]=v0>>>16&255,O[23]=v0>>>24&255,O[24]=Z0>>>0&255,O[25]=Z0>>>8&255,O[26]=Z0>>>16&255,O[27]=Z0>>>24&255,O[28]=V0>>>0&255,O[29]=V0>>>8&255,O[30]=V0>>>16&255,O[31]=V0>>>24&255,O[32]=w0>>>0&255,O[33]=w0>>>8&255,O[34]=w0>>>16&255,O[35]=w0>>>24&255,O[36]=N0>>>0&255,O[37]=N0>>>8&255,O[38]=N0>>>16&255,O[39]=N0>>>24&255,O[40]=A0>>>0&255,O[41]=A0>>>8&255,O[42]=A0>>>16&255,O[43]=A0>>>24&255,O[44]=K0>>>0&255,O[45]=K0>>>8&255,O[46]=K0>>>16&255,O[47]=K0>>>24&255,O[48]=N1>>>0&255,O[49]=N1>>>8&255,O[50]=N1>>>16&255,O[51]=N1>>>24&255,O[52]=L1>>>0&255,O[53]=L1>>>8&255,O[54]=L1>>>16&255,O[55]=L1>>>24&255,O[56]=E1>>>0&255,O[57]=E1>>>8&255,O[58]=E1>>>16&255,O[59]=E1>>>24&255,O[60]=B1>>>0&255,O[61]=B1>>>8&255,O[62]=B1>>>16&255,O[63]=B1>>>24&255}function g(O,R,C,I){var L=I[0]&255|(I[1]&255)<<8|(I[2]&255)<<16|(I[3]&255)<<24,o=C[0]&255|(C[1]&255)<<8|(C[2]&255)<<16|(C[3]&255)<<24,s=C[4]&255|(C[5]&255)<<8|(C[6]&255)<<16|(C[7]&255)<<24,q0=C[8]&255|(C[9]&255)<<8|(C[10]&255)<<16|(C[11]&255)<<24,R0=C[12]&255|(C[13]&255)<<8|(C[14]&255)<<16|(C[15]&255)<<24,t0=I[4]&255|(I[5]&255)<<8|(I[6]&255)<<16|(I[7]&255)<<24,u0=R[0]&255|(R[1]&255)<<8|(R[2]&255)<<16|(R[3]&255)<<24,p1=R[4]&255|(R[5]&255)<<8|(R[6]&255)<<16|(R[7]&255)<<24,c0=R[8]&255|(R[9]&255)<<8|(R[10]&255)<<16|(R[11]&255)<<24,q1=R[12]&255|(R[13]&255)<<8|(R[14]&255)<<16|(R[15]&255)<<24,I1=I[8]&255|(I[9]&255)<<8|(I[10]&255)<<16|(I[11]&255)<<24,P1=C[16]&255|(C[17]&255)<<8|(C[18]&255)<<16|(C[19]&255)<<24,T1=C[20]&255|(C[21]&255)<<8|(C[22]&255)<<16|(C[23]&255)<<24,z1=C[24]&255|(C[25]&255)<<8|(C[26]&255)<<16|(C[27]&255)<<24,O1=C[28]&255|(C[29]&255)<<8|(C[30]&255)<<16|(C[31]&255)<<24,w1=I[12]&255|(I[13]&255)<<8|(I[14]&255)<<16|(I[15]&255)<<24,d0=L,Y1=o,h0=s,n0=q0,s0=R0,v0=t0,Z0=u0,V0=p1,w0=c0,N0=q1,A0=I1,K0=P1,N1=T1,L1=z1,E1=O1,B1=w1,_;for(var F1=0;F1<20;F1+=2)_=d0+N1|0,s0^=_<<7|_>>>25,_=s0+d0|0,w0^=_<<9|_>>>23,_=w0+s0|0,N1^=_<<13|_>>>19,_=N1+w0|0,d0^=_<<18|_>>>14,_=v0+Y1|0,N0^=_<<7|_>>>25,_=N0+v0|0,L1^=_<<9|_>>>23,_=L1+N0|0,Y1^=_<<13|_>>>19,_=Y1+L1|0,v0^=_<<18|_>>>14,_=A0+Z0|0,E1^=_<<7|_>>>25,_=E1+A0|0,h0^=_<<9|_>>>23,_=h0+E1|0,Z0^=_<<13|_>>>19,_=Z0+h0|0,A0^=_<<18|_>>>14,_=B1+K0|0,n0^=_<<7|_>>>25,_=n0+B1|0,V0^=_<<9|_>>>23,_=V0+n0|0,K0^=_<<13|_>>>19,_=K0+V0|0,B1^=_<<18|_>>>14,_=d0+n0|0,Y1^=_<<7|_>>>25,_=Y1+d0|0,h0^=_<<9|_>>>23,_=h0+Y1|0,n0^=_<<13|_>>>19,_=n0+h0|0,d0^=_<<18|_>>>14,_=v0+s0|0,Z0^=_<<7|_>>>25,_=Z0+v0|0,V0^=_<<9|_>>>23,_=V0+Z0|0,s0^=_<<13|_>>>19,_=s0+V0|0,v0^=_<<18|_>>>14,_=A0+N0|0,K0^=_<<7|_>>>25,_=K0+A0|0,w0^=_<<9|_>>>23,_=w0+K0|0,N0^=_<<13|_>>>19,_=N0+w0|0,A0^=_<<18|_>>>14,_=B1+E1|0,N1^=_<<7|_>>>25,_=N1+B1|0,L1^=_<<9|_>>>23,_=L1+N1|0,E1^=_<<13|_>>>19,_=E1+L1|0,B1^=_<<18|_>>>14;O[0]=d0>>>0&255,O[1]=d0>>>8&255,O[2]=d0>>>16&255,O[3]=d0>>>24&255,O[4]=v0>>>0&255,O[5]=v0>>>8&255,O[6]=v0>>>16&255,O[7]=v0>>>24&255,O[8]=A0>>>0&255,O[9]=A0>>>8&255,O[10]=A0>>>16&255,O[11]=A0>>>24&255,O[12]=B1>>>0&255,O[13]=B1>>>8&255,O[14]=B1>>>16&255,O[15]=B1>>>24&255,O[16]=Z0>>>0&255,O[17]=Z0>>>8&255,O[18]=Z0>>>16&255,O[19]=Z0>>>24&255,O[20]=V0>>>0&255,O[21]=V0>>>8&255,O[22]=V0>>>16&255,O[23]=V0>>>24&255,O[24]=w0>>>0&255,O[25]=w0>>>8&255,O[26]=w0>>>16&255,O[27]=w0>>>24&255,O[28]=N0>>>0&255,O[29]=N0>>>8&255,O[30]=N0>>>16&255,O[31]=N0>>>24&255}function f(O,R,C,I){x(O,R,C,I)}function y(O,R,C,I){g(O,R,C,I)}var p=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function b(O,R,C,I,L,o,s){var q0=new Uint8Array(16),R0=new Uint8Array(64),t0,u0;for(u0=0;u0<16;u0++)q0[u0]=0;for(u0=0;u0<8;u0++)q0[u0]=o[u0];while(L>=64){f(R0,q0,s,p);for(u0=0;u0<64;u0++)O[R+u0]=C[I+u0]^R0[u0];t0=1;for(u0=8;u0<16;u0++)t0=t0+(q0[u0]&255)|0,q0[u0]=t0&255,t0>>>=8;L-=64,R+=64,I+=64}if(L>0){f(R0,q0,s,p);for(u0=0;u0<L;u0++)O[R+u0]=C[I+u0]^R0[u0]}return 0}function m(O,R,C,I,L){var o=new Uint8Array(16),s=new Uint8Array(64),q0,R0;for(R0=0;R0<16;R0++)o[R0]=0;for(R0=0;R0<8;R0++)o[R0]=I[R0];while(C>=64){f(s,o,L,p);for(R0=0;R0<64;R0++)O[R+R0]=s[R0];q0=1;for(R0=8;R0<16;R0++)q0=q0+(o[R0]&255)|0,o[R0]=q0&255,q0>>>=8;C-=64,R+=64}if(C>0){f(s,o,L,p);for(R0=0;R0<C;R0++)O[R+R0]=s[R0]}return 0}function W0(O,R,C,I,L){var o=new Uint8Array(32);y(o,I,L,p);var s=new Uint8Array(8);for(var q0=0;q0<8;q0++)s[q0]=I[q0+16];return m(O,R,C,s,o)}function u(O,R,C,I,L,o,s){var q0=new Uint8Array(32);y(q0,o,s,p);var R0=new Uint8Array(8);for(var t0=0;t0<8;t0++)R0[t0]=o[t0+16];return b(O,R,C,I,L,R0,q0)}var J0=function(O){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var R,C,I,L,o,s,q0,R0;R=O[0]&255|(O[1]&255)<<8,this.r[0]=R&8191,C=O[2]&255|(O[3]&255)<<8,this.r[1]=(R>>>13|C<<3)&8191,I=O[4]&255|(O[5]&255)<<8,this.r[2]=(C>>>10|I<<6)&7939,L=O[6]&255|(O[7]&255)<<8,this.r[3]=(I>>>7|L<<9)&8191,o=O[8]&255|(O[9]&255)<<8,this.r[4]=(L>>>4|o<<12)&255,this.r[5]=o>>>1&8190,s=O[10]&255|(O[11]&255)<<8,this.r[6]=(o>>>14|s<<2)&8191,q0=O[12]&255|(O[13]&255)<<8,this.r[7]=(s>>>11|q0<<5)&8065,R0=O[14]&255|(O[15]&255)<<8,this.r[8]=(q0>>>8|R0<<8)&8191,this.r[9]=R0>>>5&127,this.pad[0]=O[16]&255|(O[17]&255)<<8,this.pad[1]=O[18]&255|(O[19]&255)<<8,this.pad[2]=O[20]&255|(O[21]&255)<<8,this.pad[3]=O[22]&255|(O[23]&255)<<8,this.pad[4]=O[24]&255|(O[25]&255)<<8,this.pad[5]=O[26]&255|(O[27]&255)<<8,this.pad[6]=O[28]&255|(O[29]&255)<<8,this.pad[7]=O[30]&255|(O[31]&255)<<8};J0.prototype.blocks=function(O,R,C){var I=this.fin?0:2048,L,o,s,q0,R0,t0,u0,p1,c0,q1,I1,P1,T1,z1,O1,w1,d0,Y1,h0,n0=this.h[0],s0=this.h[1],v0=this.h[2],Z0=this.h[3],V0=this.h[4],w0=this.h[5],N0=this.h[6],A0=this.h[7],K0=this.h[8],N1=this.h[9],L1=this.r[0],E1=this.r[1],B1=this.r[2],_=this.r[3],F1=this.r[4],l1=this.r[5],d1=this.r[6],$1=this.r[7],b1=this.r[8],m1=this.r[9];while(C>=16)L=O[R+0]&255|(O[R+1]&255)<<8,n0+=L&8191,o=O[R+2]&255|(O[R+3]&255)<<8,s0+=(L>>>13|o<<3)&8191,s=O[R+4]&255|(O[R+5]&255)<<8,v0+=(o>>>10|s<<6)&8191,q0=O[R+6]&255|(O[R+7]&255)<<8,Z0+=(s>>>7|q0<<9)&8191,R0=O[R+8]&255|(O[R+9]&255)<<8,V0+=(q0>>>4|R0<<12)&8191,w0+=R0>>>1&8191,t0=O[R+10]&255|(O[R+11]&255)<<8,N0+=(R0>>>14|t0<<2)&8191,u0=O[R+12]&255|(O[R+13]&255)<<8,A0+=(t0>>>11|u0<<5)&8191,p1=O[R+14]&255|(O[R+15]&255)<<8,K0+=(u0>>>8|p1<<8)&8191,N1+=p1>>>5|I,c0=0,q1=c0,q1+=n0*L1,q1+=s0*(5*m1),q1+=v0*(5*b1),q1+=Z0*(5*$1),q1+=V0*(5*d1),c0=q1>>>13,q1&=8191,q1+=w0*(5*l1),q1+=N0*(5*F1),q1+=A0*(5*_),q1+=K0*(5*B1),q1+=N1*(5*E1),c0+=q1>>>13,q1&=8191,I1=c0,I1+=n0*E1,I1+=s0*L1,I1+=v0*(5*m1),I1+=Z0*(5*b1),I1+=V0*(5*$1),c0=I1>>>13,I1&=8191,I1+=w0*(5*d1),I1+=N0*(5*l1),I1+=A0*(5*F1),I1+=K0*(5*_),I1+=N1*(5*B1),c0+=I1>>>13,I1&=8191,P1=c0,P1+=n0*B1,P1+=s0*E1,P1+=v0*L1,P1+=Z0*(5*m1),P1+=V0*(5*b1),c0=P1>>>13,P1&=8191,P1+=w0*(5*$1),P1+=N0*(5*d1),P1+=A0*(5*l1),P1+=K0*(5*F1),P1+=N1*(5*_),c0+=P1>>>13,P1&=8191,T1=c0,T1+=n0*_,T1+=s0*B1,T1+=v0*E1,T1+=Z0*L1,T1+=V0*(5*m1),c0=T1>>>13,T1&=8191,T1+=w0*(5*b1),T1+=N0*(5*$1),T1+=A0*(5*d1),T1+=K0*(5*l1),T1+=N1*(5*F1),c0+=T1>>>13,T1&=8191,z1=c0,z1+=n0*F1,z1+=s0*_,z1+=v0*B1,z1+=Z0*E1,z1+=V0*L1,c0=z1>>>13,z1&=8191,z1+=w0*(5*m1),z1+=N0*(5*b1),z1+=A0*(5*$1),z1+=K0*(5*d1),z1+=N1*(5*l1),c0+=z1>>>13,z1&=8191,O1=c0,O1+=n0*l1,O1+=s0*F1,O1+=v0*_,O1+=Z0*B1,O1+=V0*E1,c0=O1>>>13,O1&=8191,O1+=w0*L1,O1+=N0*(5*m1),O1+=A0*(5*b1),O1+=K0*(5*$1),O1+=N1*(5*d1),c0+=O1>>>13,O1&=8191,w1=c0,w1+=n0*d1,w1+=s0*l1,w1+=v0*F1,w1+=Z0*_,w1+=V0*B1,c0=w1>>>13,w1&=8191,w1+=w0*E1,w1+=N0*L1,w1+=A0*(5*m1),w1+=K0*(5*b1),w1+=N1*(5*$1),c0+=w1>>>13,w1&=8191,d0=c0,d0+=n0*$1,d0+=s0*d1,d0+=v0*l1,d0+=Z0*F1,d0+=V0*_,c0=d0>>>13,d0&=8191,d0+=w0*B1,d0+=N0*E1,d0+=A0*L1,d0+=K0*(5*m1),d0+=N1*(5*b1),c0+=d0>>>13,d0&=8191,Y1=c0,Y1+=n0*b1,Y1+=s0*$1,Y1+=v0*d1,Y1+=Z0*l1,Y1+=V0*F1,c0=Y1>>>13,Y1&=8191,Y1+=w0*_,Y1+=N0*B1,Y1+=A0*E1,Y1+=K0*L1,Y1+=N1*(5*m1),c0+=Y1>>>13,Y1&=8191,h0=c0,h0+=n0*m1,h0+=s0*b1,h0+=v0*$1,h0+=Z0*d1,h0+=V0*l1,c0=h0>>>13,h0&=8191,h0+=w0*F1,h0+=N0*_,h0+=A0*B1,h0+=K0*E1,h0+=N1*L1,c0+=h0>>>13,h0&=8191,c0=(c0<<2)+c0|0,c0=c0+q1|0,q1=c0&8191,c0=c0>>>13,I1+=c0,n0=q1,s0=I1,v0=P1,Z0=T1,V0=z1,w0=O1,N0=w1,A0=d0,K0=Y1,N1=h0,R+=16,C-=16;this.h[0]=n0,this.h[1]=s0,this.h[2]=v0,this.h[3]=Z0,this.h[4]=V0,this.h[5]=w0,this.h[6]=N0,this.h[7]=A0,this.h[8]=K0,this.h[9]=N1},J0.prototype.finish=function(O,R){var C=new Uint16Array(10),I,L,o,s;if(this.leftover){s=this.leftover,this.buffer[s++]=1;for(;s<16;s++)this.buffer[s]=0;this.fin=1,this.blocks(this.buffer,0,16)}I=this.h[1]>>>13,this.h[1]&=8191;for(s=2;s<10;s++)this.h[s]+=I,I=this.h[s]>>>13,this.h[s]&=8191;this.h[0]+=I*5,I=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=I,I=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=I,C[0]=this.h[0]+5,I=C[0]>>>13,C[0]&=8191;for(s=1;s<10;s++)C[s]=this.h[s]+I,I=C[s]>>>13,C[s]&=8191;C[9]-=8192,L=(I^1)-1;for(s=0;s<10;s++)C[s]&=L;L=~L;for(s=0;s<10;s++)this.h[s]=this.h[s]&L|C[s];this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,o=this.h[0]+this.pad[0],this.h[0]=o&65535;for(s=1;s<8;s++)o=(this.h[s]+this.pad[s]|0)+(o>>>16)|0,this.h[s]=o&65535;O[R+0]=this.h[0]>>>0&255,O[R+1]=this.h[0]>>>8&255,O[R+2]=this.h[1]>>>0&255,O[R+3]=this.h[1]>>>8&255,O[R+4]=this.h[2]>>>0&255,O[R+5]=this.h[2]>>>8&255,O[R+6]=this.h[3]>>>0&255,O[R+7]=this.h[3]>>>8&255,O[R+8]=this.h[4]>>>0&255,O[R+9]=this.h[4]>>>8&255,O[R+10]=this.h[5]>>>0&255,O[R+11]=this.h[5]>>>8&255,O[R+12]=this.h[6]>>>0&255,O[R+13]=this.h[6]>>>8&255,O[R+14]=this.h[7]>>>0&255,O[R+15]=this.h[7]>>>8&255},J0.prototype.update=function(O,R,C){var I,L;if(this.leftover){if(L=16-this.leftover,L>C)L=C;for(I=0;I<L;I++)this.buffer[this.leftover+I]=O[R+I];if(C-=L,R+=L,this.leftover+=L,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(C>=16)L=C-C%16,this.blocks(O,R,L),R+=L,C-=L;if(C){for(I=0;I<C;I++)this.buffer[this.leftover+I]=O[R+I];this.leftover+=C}};function I0(O,R,C,I,L,o){var s=new J0(o);return s.update(C,I,L),s.finish(O,R),0}function k(O,R,C,I,L,o){var s=new Uint8Array(16);return I0(s,0,C,I,L,o),D(O,R,s,0)}function l(O,R,C,I,L){var o;if(C<32)return-1;u(O,0,R,0,C,I,L),I0(O,16,O,32,C-32,O);for(o=0;o<16;o++)O[o]=0;return 0}function B(O,R,C,I,L){var o,s=new Uint8Array(32);if(C<32)return-1;if(W0(s,0,32,I,L),k(R,16,R,32,C-32,s)!==0)return-1;u(O,0,R,0,C,I,L);for(o=0;o<32;o++)O[o]=0;return 0}function $(O,R){var C;for(C=0;C<16;C++)O[C]=R[C]|0}function h(O){var R,C,I=1;for(R=0;R<16;R++)C=O[R]+I+65535,I=Math.floor(C/65536),O[R]=C-I*65536;O[0]+=I-1+37*(I-1)}function a(O,R,C){var I,L=~(C-1);for(var o=0;o<16;o++)I=L&(O[o]^R[o]),O[o]^=I,R[o]^=I}function n(O,R){var C,I,L,o=Y(),s=Y();for(C=0;C<16;C++)s[C]=R[C];h(s),h(s),h(s);for(I=0;I<2;I++){o[0]=s[0]-65517;for(C=1;C<15;C++)o[C]=s[C]-65535-(o[C-1]>>16&1),o[C-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),L=o[15]>>16&1,o[14]&=65535,a(s,o,1-L)}for(C=0;C<16;C++)O[2*C]=s[C]&255,O[2*C+1]=s[C]>>8}function E(O,R){var C=new Uint8Array(32),I=new Uint8Array(32);return n(C,O),n(I,R),T(C,0,I,0)}function P(O){var R=new Uint8Array(32);return n(R,O),R[0]&1}function v(O,R){var C;for(C=0;C<16;C++)O[C]=R[2*C]+(R[2*C+1]<<8);O[15]&=32767}function M(O,R,C){for(var I=0;I<16;I++)O[I]=R[I]+C[I]}function F(O,R,C){for(var I=0;I<16;I++)O[I]=R[I]-C[I]}function c(O,R,C){var I,L,o=0,s=0,q0=0,R0=0,t0=0,u0=0,p1=0,c0=0,q1=0,I1=0,P1=0,T1=0,z1=0,O1=0,w1=0,d0=0,Y1=0,h0=0,n0=0,s0=0,v0=0,Z0=0,V0=0,w0=0,N0=0,A0=0,K0=0,N1=0,L1=0,E1=0,B1=0,_=C[0],F1=C[1],l1=C[2],d1=C[3],$1=C[4],b1=C[5],m1=C[6],S8=C[7],e1=C[8],C8=C[9],T8=C[10],R8=C[11],h8=C[12],Q9=C[13],H9=C[14],N9=C[15];I=R[0],o+=I*_,s+=I*F1,q0+=I*l1,R0+=I*d1,t0+=I*$1,u0+=I*b1,p1+=I*m1,c0+=I*S8,q1+=I*e1,I1+=I*C8,P1+=I*T8,T1+=I*R8,z1+=I*h8,O1+=I*Q9,w1+=I*H9,d0+=I*N9,I=R[1],s+=I*_,q0+=I*F1,R0+=I*l1,t0+=I*d1,u0+=I*$1,p1+=I*b1,c0+=I*m1,q1+=I*S8,I1+=I*e1,P1+=I*C8,T1+=I*T8,z1+=I*R8,O1+=I*h8,w1+=I*Q9,d0+=I*H9,Y1+=I*N9,I=R[2],q0+=I*_,R0+=I*F1,t0+=I*l1,u0+=I*d1,p1+=I*$1,c0+=I*b1,q1+=I*m1,I1+=I*S8,P1+=I*e1,T1+=I*C8,z1+=I*T8,O1+=I*R8,w1+=I*h8,d0+=I*Q9,Y1+=I*H9,h0+=I*N9,I=R[3],R0+=I*_,t0+=I*F1,u0+=I*l1,p1+=I*d1,c0+=I*$1,q1+=I*b1,I1+=I*m1,P1+=I*S8,T1+=I*e1,z1+=I*C8,O1+=I*T8,w1+=I*R8,d0+=I*h8,Y1+=I*Q9,h0+=I*H9,n0+=I*N9,I=R[4],t0+=I*_,u0+=I*F1,p1+=I*l1,c0+=I*d1,q1+=I*$1,I1+=I*b1,P1+=I*m1,T1+=I*S8,z1+=I*e1,O1+=I*C8,w1+=I*T8,d0+=I*R8,Y1+=I*h8,h0+=I*Q9,n0+=I*H9,s0+=I*N9,I=R[5],u0+=I*_,p1+=I*F1,c0+=I*l1,q1+=I*d1,I1+=I*$1,P1+=I*b1,T1+=I*m1,z1+=I*S8,O1+=I*e1,w1+=I*C8,d0+=I*T8,Y1+=I*R8,h0+=I*h8,n0+=I*Q9,s0+=I*H9,v0+=I*N9,I=R[6],p1+=I*_,c0+=I*F1,q1+=I*l1,I1+=I*d1,P1+=I*$1,T1+=I*b1,z1+=I*m1,O1+=I*S8,w1+=I*e1,d0+=I*C8,Y1+=I*T8,h0+=I*R8,n0+=I*h8,s0+=I*Q9,v0+=I*H9,Z0+=I*N9,I=R[7],c0+=I*_,q1+=I*F1,I1+=I*l1,P1+=I*d1,T1+=I*$1,z1+=I*b1,O1+=I*m1,w1+=I*S8,d0+=I*e1,Y1+=I*C8,h0+=I*T8,n0+=I*R8,s0+=I*h8,v0+=I*Q9,Z0+=I*H9,V0+=I*N9,I=R[8],q1+=I*_,I1+=I*F1,P1+=I*l1,T1+=I*d1,z1+=I*$1,O1+=I*b1,w1+=I*m1,d0+=I*S8,Y1+=I*e1,h0+=I*C8,n0+=I*T8,s0+=I*R8,v0+=I*h8,Z0+=I*Q9,V0+=I*H9,w0+=I*N9,I=R[9],I1+=I*_,P1+=I*F1,T1+=I*l1,z1+=I*d1,O1+=I*$1,w1+=I*b1,d0+=I*m1,Y1+=I*S8,h0+=I*e1,n0+=I*C8,s0+=I*T8,v0+=I*R8,Z0+=I*h8,V0+=I*Q9,w0+=I*H9,N0+=I*N9,I=R[10],P1+=I*_,T1+=I*F1,z1+=I*l1,O1+=I*d1,w1+=I*$1,d0+=I*b1,Y1+=I*m1,h0+=I*S8,n0+=I*e1,s0+=I*C8,v0+=I*T8,Z0+=I*R8,V0+=I*h8,w0+=I*Q9,N0+=I*H9,A0+=I*N9,I=R[11],T1+=I*_,z1+=I*F1,O1+=I*l1,w1+=I*d1,d0+=I*$1,Y1+=I*b1,h0+=I*m1,n0+=I*S8,s0+=I*e1,v0+=I*C8,Z0+=I*T8,V0+=I*R8,w0+=I*h8,N0+=I*Q9,A0+=I*H9,K0+=I*N9,I=R[12],z1+=I*_,O1+=I*F1,w1+=I*l1,d0+=I*d1,Y1+=I*$1,h0+=I*b1,n0+=I*m1,s0+=I*S8,v0+=I*e1,Z0+=I*C8,V0+=I*T8,w0+=I*R8,N0+=I*h8,A0+=I*Q9,K0+=I*H9,N1+=I*N9,I=R[13],O1+=I*_,w1+=I*F1,d0+=I*l1,Y1+=I*d1,h0+=I*$1,n0+=I*b1,s0+=I*m1,v0+=I*S8,Z0+=I*e1,V0+=I*C8,w0+=I*T8,N0+=I*R8,A0+=I*h8,K0+=I*Q9,N1+=I*H9,L1+=I*N9,I=R[14],w1+=I*_,d0+=I*F1,Y1+=I*l1,h0+=I*d1,n0+=I*$1,s0+=I*b1,v0+=I*m1,Z0+=I*S8,V0+=I*e1,w0+=I*C8,N0+=I*T8,A0+=I*R8,K0+=I*h8,N1+=I*Q9,L1+=I*H9,E1+=I*N9,I=R[15],d0+=I*_,Y1+=I*F1,h0+=I*l1,n0+=I*d1,s0+=I*$1,v0+=I*b1,Z0+=I*m1,V0+=I*S8,w0+=I*e1,N0+=I*C8,A0+=I*T8,K0+=I*R8,N1+=I*h8,L1+=I*Q9,E1+=I*H9,B1+=I*N9,o+=38*Y1,s+=38*h0,q0+=38*n0,R0+=38*s0,t0+=38*v0,u0+=38*Z0,p1+=38*V0,c0+=38*w0,q1+=38*N0,I1+=38*A0,P1+=38*K0,T1+=38*N1,z1+=38*L1,O1+=38*E1,w1+=38*B1,L=1,I=o+L+65535,L=Math.floor(I/65536),o=I-L*65536,I=s+L+65535,L=Math.floor(I/65536),s=I-L*65536,I=q0+L+65535,L=Math.floor(I/65536),q0=I-L*65536,I=R0+L+65535,L=Math.floor(I/65536),R0=I-L*65536,I=t0+L+65535,L=Math.floor(I/65536),t0=I-L*65536,I=u0+L+65535,L=Math.floor(I/65536),u0=I-L*65536,I=p1+L+65535,L=Math.floor(I/65536),p1=I-L*65536,I=c0+L+65535,L=Math.floor(I/65536),c0=I-L*65536,I=q1+L+65535,L=Math.floor(I/65536),q1=I-L*65536,I=I1+L+65535,L=Math.floor(I/65536),I1=I-L*65536,I=P1+L+65535,L=Math.floor(I/65536),P1=I-L*65536,I=T1+L+65535,L=Math.floor(I/65536),T1=I-L*65536,I=z1+L+65535,L=Math.floor(I/65536),z1=I-L*65536,I=O1+L+65535,L=Math.floor(I/65536),O1=I-L*65536,I=w1+L+65535,L=Math.floor(I/65536),w1=I-L*65536,I=d0+L+65535,L=Math.floor(I/65536),d0=I-L*65536,o+=L-1+37*(L-1),L=1,I=o+L+65535,L=Math.floor(I/65536),o=I-L*65536,I=s+L+65535,L=Math.floor(I/65536),s=I-L*65536,I=q0+L+65535,L=Math.floor(I/65536),q0=I-L*65536,I=R0+L+65535,L=Math.floor(I/65536),R0=I-L*65536,I=t0+L+65535,L=Math.floor(I/65536),t0=I-L*65536,I=u0+L+65535,L=Math.floor(I/65536),u0=I-L*65536,I=p1+L+65535,L=Math.floor(I/65536),p1=I-L*65536,I=c0+L+65535,L=Math.floor(I/65536),c0=I-L*65536,I=q1+L+65535,L=Math.floor(I/65536),q1=I-L*65536,I=I1+L+65535,L=Math.floor(I/65536),I1=I-L*65536,I=P1+L+65535,L=Math.floor(I/65536),P1=I-L*65536,I=T1+L+65535,L=Math.floor(I/65536),T1=I-L*65536,I=z1+L+65535,L=Math.floor(I/65536),z1=I-L*65536,I=O1+L+65535,L=Math.floor(I/65536),O1=I-L*65536,I=w1+L+65535,L=Math.floor(I/65536),w1=I-L*65536,I=d0+L+65535,L=Math.floor(I/65536),d0=I-L*65536,o+=L-1+37*(L-1),O[0]=o,O[1]=s,O[2]=q0,O[3]=R0,O[4]=t0,O[5]=u0,O[6]=p1,O[7]=c0,O[8]=q1,O[9]=I1,O[10]=P1,O[11]=T1,O[12]=z1,O[13]=O1,O[14]=w1,O[15]=d0}function t(O,R){c(O,R,R)}function Y0(O,R){var C=Y(),I;for(I=0;I<16;I++)C[I]=R[I];for(I=253;I>=0;I--)if(t(C,C),I!==2&&I!==4)c(C,C,R);for(I=0;I<16;I++)O[I]=C[I]}function $0(O,R){var C=Y(),I;for(I=0;I<16;I++)C[I]=R[I];for(I=250;I>=0;I--)if(t(C,C),I!==1)c(C,C,R);for(I=0;I<16;I++)O[I]=C[I]}function S0(O,R,C){var I=new Uint8Array(32),L=new Float64Array(80),o,s,q0=Y(),R0=Y(),t0=Y(),u0=Y(),p1=Y(),c0=Y();for(s=0;s<31;s++)I[s]=R[s];I[31]=R[31]&127|64,I[0]&=248,v(L,C);for(s=0;s<16;s++)R0[s]=L[s],u0[s]=q0[s]=t0[s]=0;q0[0]=u0[0]=1;for(s=254;s>=0;--s)o=I[s>>>3]>>>(s&7)&1,a(q0,R0,o),a(t0,u0,o),M(p1,q0,t0),F(q0,q0,t0),M(t0,R0,u0),F(R0,R0,u0),t(u0,p1),t(c0,q0),c(q0,t0,q0),c(t0,R0,p1),M(p1,q0,t0),F(q0,q0,t0),t(R0,q0),F(t0,u0,c0),c(q0,t0,U),M(q0,q0,u0),c(t0,t0,q0),c(q0,u0,c0),c(u0,R0,L),t(R0,p1),a(q0,R0,o),a(t0,u0,o);for(s=0;s<16;s++)L[s+16]=q0[s],L[s+32]=t0[s],L[s+48]=R0[s],L[s+64]=u0[s];var q1=L.subarray(32),I1=L.subarray(16);return Y0(q1,q1),c(I1,I1,q1),n(O,I1),0}function x0(O,R){return S0(O,R,J)}function D1(O,R){return G(R,32),x0(O,R)}function b0(O,R,C){var I=new Uint8Array(32);return S0(I,C,R),y(O,X,I,p)}var Q0=l,O0=B;function y0(O,R,C,I,L,o){var s=new Uint8Array(32);return b0(s,L,o),Q0(O,R,C,I,s)}function X0(O,R,C,I,L,o){var s=new Uint8Array(32);return b0(s,L,o),O0(O,R,C,I,s)}var D0=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function L0(O,R,C,I){var L=new Int32Array(16),o=new Int32Array(16),s,q0,R0,t0,u0,p1,c0,q1,I1,P1,T1,z1,O1,w1,d0,Y1,h0,n0,s0,v0,Z0,V0,w0,N0,A0,K0,N1=O[0],L1=O[1],E1=O[2],B1=O[3],_=O[4],F1=O[5],l1=O[6],d1=O[7],$1=R[0],b1=R[1],m1=R[2],S8=R[3],e1=R[4],C8=R[5],T8=R[6],R8=R[7],h8=0;while(I>=128){for(s0=0;s0<16;s0++)v0=8*s0+h8,L[s0]=C[v0+0]<<24|C[v0+1]<<16|C[v0+2]<<8|C[v0+3],o[s0]=C[v0+4]<<24|C[v0+5]<<16|C[v0+6]<<8|C[v0+7];for(s0=0;s0<80;s0++)if(s=N1,q0=L1,R0=E1,t0=B1,u0=_,p1=F1,c0=l1,q1=d1,I1=$1,P1=b1,T1=m1,z1=S8,O1=e1,w1=C8,d0=T8,Y1=R8,Z0=d1,V0=R8,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=(_>>>14|e1<<18)^(_>>>18|e1<<14)^(e1>>>9|_<<23),V0=(e1>>>14|_<<18)^(e1>>>18|_<<14)^(_>>>9|e1<<23),w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,Z0=_&F1^~_&l1,V0=e1&C8^~e1&T8,w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,Z0=D0[s0*2],V0=D0[s0*2+1],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,Z0=L[s0%16],V0=o[s0%16],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,h0=A0&65535|K0<<16,n0=w0&65535|N0<<16,Z0=h0,V0=n0,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=(N1>>>28|$1<<4)^($1>>>2|N1<<30)^($1>>>7|N1<<25),V0=($1>>>28|N1<<4)^(N1>>>2|$1<<30)^(N1>>>7|$1<<25),w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,Z0=N1&L1^N1&E1^L1&E1,V0=$1&b1^$1&m1^b1&m1,w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,q1=A0&65535|K0<<16,Y1=w0&65535|N0<<16,Z0=t0,V0=z1,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=h0,V0=n0,w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,t0=A0&65535|K0<<16,z1=w0&65535|N0<<16,L1=s,E1=q0,B1=R0,_=t0,F1=u0,l1=p1,d1=c0,N1=q1,b1=I1,m1=P1,S8=T1,e1=z1,C8=O1,T8=w1,R8=d0,$1=Y1,s0%16===15)for(v0=0;v0<16;v0++)Z0=L[v0],V0=o[v0],w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=L[(v0+9)%16],V0=o[(v0+9)%16],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,h0=L[(v0+1)%16],n0=o[(v0+1)%16],Z0=(h0>>>1|n0<<31)^(h0>>>8|n0<<24)^h0>>>7,V0=(n0>>>1|h0<<31)^(n0>>>8|h0<<24)^(n0>>>7|h0<<25),w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,h0=L[(v0+14)%16],n0=o[(v0+14)%16],Z0=(h0>>>19|n0<<13)^(n0>>>29|h0<<3)^h0>>>6,V0=(n0>>>19|h0<<13)^(h0>>>29|n0<<3)^(n0>>>6|h0<<26),w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,L[v0]=A0&65535|K0<<16,o[v0]=w0&65535|N0<<16;Z0=N1,V0=$1,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[0],V0=R[0],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[0]=N1=A0&65535|K0<<16,R[0]=$1=w0&65535|N0<<16,Z0=L1,V0=b1,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[1],V0=R[1],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[1]=L1=A0&65535|K0<<16,R[1]=b1=w0&65535|N0<<16,Z0=E1,V0=m1,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[2],V0=R[2],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[2]=E1=A0&65535|K0<<16,R[2]=m1=w0&65535|N0<<16,Z0=B1,V0=S8,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[3],V0=R[3],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[3]=B1=A0&65535|K0<<16,R[3]=S8=w0&65535|N0<<16,Z0=_,V0=e1,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[4],V0=R[4],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[4]=_=A0&65535|K0<<16,R[4]=e1=w0&65535|N0<<16,Z0=F1,V0=C8,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[5],V0=R[5],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[5]=F1=A0&65535|K0<<16,R[5]=C8=w0&65535|N0<<16,Z0=l1,V0=T8,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[6],V0=R[6],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[6]=l1=A0&65535|K0<<16,R[6]=T8=w0&65535|N0<<16,Z0=d1,V0=R8,w0=V0&65535,N0=V0>>>16,A0=Z0&65535,K0=Z0>>>16,Z0=O[7],V0=R[7],w0+=V0&65535,N0+=V0>>>16,A0+=Z0&65535,K0+=Z0>>>16,N0+=w0>>>16,A0+=N0>>>16,K0+=A0>>>16,O[7]=d1=A0&65535|K0<<16,R[7]=R8=w0&65535|N0<<16,h8+=128,I-=128}return I}function H0(O,R,C){var I=new Int32Array(8),L=new Int32Array(8),o=new Uint8Array(256),s,q0=C;I[0]=1779033703,I[1]=3144134277,I[2]=1013904242,I[3]=2773480762,I[4]=1359893119,I[5]=2600822924,I[6]=528734635,I[7]=1541459225,L[0]=4089235720,L[1]=2227873595,L[2]=4271175723,L[3]=1595750129,L[4]=2917565137,L[5]=725511199,L[6]=4215389547,L[7]=327033209,L0(I,L,R,C),C%=128;for(s=0;s<C;s++)o[s]=R[q0-C+s];o[C]=128,C=256-128*(C<112?1:0),o[C-9]=0,z(o,C-8,q0/536870912|0,q0<<3),L0(I,L,o,C);for(s=0;s<8;s++)z(O,8*s,I[s],L[s]);return 0}function F0(O,R){var C=Y(),I=Y(),L=Y(),o=Y(),s=Y(),q0=Y(),R0=Y(),t0=Y(),u0=Y();F(C,O[1],O[0]),F(u0,R[1],R[0]),c(C,C,u0),M(I,O[0],O[1]),M(u0,R[0],R[1]),c(I,I,u0),c(L,O[3],R[3]),c(L,L,H),c(o,O[2],R[2]),M(o,o,o),F(s,I,C),F(q0,o,L),M(R0,o,L),M(t0,I,C),c(O[0],s,q0),c(O[1],t0,R0),c(O[2],R0,q0),c(O[3],s,t0)}function V1(O,R,C){var I;for(I=0;I<4;I++)a(O[I],R[I],C)}function H1(O,R){var C=Y(),I=Y(),L=Y();Y0(L,R[2]),c(C,R[0],L),c(I,R[1],L),n(O,I),O[31]^=P(C)<<7}function y1(O,R,C){var I,L;$(O[0],Z),$(O[1],V),$(O[2],V),$(O[3],Z);for(L=255;L>=0;--L)I=C[L/8|0]>>(L&7)&1,V1(O,R,I),F0(R,O),F0(O,O),V1(O,R,I)}function i1(O,R){var C=[Y(),Y(),Y(),Y()];$(C[0],N),$(C[1],A),$(C[2],V),c(C[3],N,A),y1(O,C,R)}function r0(O,R,C){var I=new Uint8Array(64),L=[Y(),Y(),Y(),Y()],o;if(!C)G(R,32);H0(I,R,32),I[0]&=248,I[31]&=127,I[31]|=64,i1(L,I),H1(O,L);for(o=0;o<32;o++)R[o+32]=O[o];return 0}var x1=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function i0(O,R){var C,I,L,o;for(I=63;I>=32;--I){C=0;for(L=I-32,o=I-12;L<o;++L)R[L]+=C-16*R[I]*x1[L-(I-32)],C=Math.floor((R[L]+128)/256),R[L]-=C*256;R[L]+=C,R[I]=0}C=0;for(L=0;L<32;L++)R[L]+=C-(R[31]>>4)*x1[L],C=R[L]>>8,R[L]&=255;for(L=0;L<32;L++)R[L]-=C*x1[L];for(I=0;I<32;I++)R[I+1]+=R[I]>>8,O[I]=R[I]&255}function V8(O){var R=new Float64Array(64),C;for(C=0;C<64;C++)R[C]=O[C];for(C=0;C<64;C++)O[C]=0;i0(O,R)}function F8(O,R,C,I){var L=new Uint8Array(64),o=new Uint8Array(64),s=new Uint8Array(64),q0,R0,t0=new Float64Array(64),u0=[Y(),Y(),Y(),Y()];H0(L,I,32),L[0]&=248,L[31]&=127,L[31]|=64;var p1=C+64;for(q0=0;q0<C;q0++)O[64+q0]=R[q0];for(q0=0;q0<32;q0++)O[32+q0]=L[32+q0];H0(s,O.subarray(32),C+32),V8(s),i1(u0,s),H1(O,u0);for(q0=32;q0<64;q0++)O[q0]=I[q0];H0(o,O,C+64),V8(o);for(q0=0;q0<64;q0++)t0[q0]=0;for(q0=0;q0<32;q0++)t0[q0]=s[q0];for(q0=0;q0<32;q0++)for(R0=0;R0<32;R0++)t0[q0+R0]+=o[q0]*L[R0];return i0(O.subarray(32),t0),p1}function $9(O,R){var C=Y(),I=Y(),L=Y(),o=Y(),s=Y(),q0=Y(),R0=Y();if($(O[2],V),v(O[1],R),t(L,O[1]),c(o,L,Q),F(L,L,O[2]),M(o,O[2],o),t(s,o),t(q0,s),c(R0,q0,s),c(C,R0,L),c(C,C,o),$0(C,C),c(C,C,L),c(C,C,o),c(C,C,o),c(O[0],C,o),t(I,O[0]),c(I,I,o),E(I,L))c(O[0],O[0],q);if(t(I,O[0]),c(I,I,o),E(I,L))return-1;if(P(O[0])===R[31]>>7)F(O[0],Z,O[0]);return c(O[3],O[0],O[1]),0}function Q7(O,R,C,I){var L,o=new Uint8Array(32),s=new Uint8Array(64),q0=[Y(),Y(),Y(),Y()],R0=[Y(),Y(),Y(),Y()];if(C<64)return-1;if($9(R0,I))return-1;for(L=0;L<C;L++)O[L]=R[L];for(L=0;L<32;L++)O[L+32]=I[L];if(H0(s,O,C),V8(s),y1(q0,R0,s),i1(R0,R.subarray(32)),F0(q0,R0),H1(o,q0),C-=64,T(R,0,o,0)){for(L=0;L<C;L++)O[L]=0;return-1}for(L=0;L<C;L++)O[L]=R[L+64];return C}var d=32,e=24,U0=32,T0=16,e0=32,U8=32,q8=32,C1=32,k0=32,m0=e,l0=U0,a0=T0,A1=64,c1=32,Y8=64,F9=32,cY=64;W.lowlevel={crypto_core_hsalsa20:y,crypto_stream_xor:u,crypto_stream:W0,crypto_stream_salsa20_xor:b,crypto_stream_salsa20:m,crypto_onetimeauth:I0,crypto_onetimeauth_verify:k,crypto_verify_16:D,crypto_verify_32:T,crypto_secretbox:l,crypto_secretbox_open:B,crypto_scalarmult:S0,crypto_scalarmult_base:x0,crypto_box_beforenm:b0,crypto_box_afternm:Q0,crypto_box:y0,crypto_box_open:X0,crypto_box_keypair:D1,crypto_hash:H0,crypto_sign:F8,crypto_sign_keypair:r0,crypto_sign_open:Q7,crypto_secretbox_KEYBYTES:d,crypto_secretbox_NONCEBYTES:e,crypto_secretbox_ZEROBYTES:U0,crypto_secretbox_BOXZEROBYTES:T0,crypto_scalarmult_BYTES:e0,crypto_scalarmult_SCALARBYTES:U8,crypto_box_PUBLICKEYBYTES:q8,crypto_box_SECRETKEYBYTES:C1,crypto_box_BEFORENMBYTES:k0,crypto_box_NONCEBYTES:m0,crypto_box_ZEROBYTES:l0,crypto_box_BOXZEROBYTES:a0,crypto_sign_BYTES:A1,crypto_sign_PUBLICKEYBYTES:c1,crypto_sign_SECRETKEYBYTES:Y8,crypto_sign_SEEDBYTES:F9,crypto_hash_BYTES:cY,gf:Y,D:Q,L:x1,pack25519:n,unpack25519:v,M:c,A:M,S:t,Z:F,pow2523:$0,add:F0,set25519:$,modL:i0,scalarmult:y1,scalarbase:i1};function _U(O,R){if(O.length!==d)throw Error("bad key size");if(R.length!==e)throw Error("bad nonce size")}function QA(O,R){if(O.length!==q8)throw Error("bad public key size");if(R.length!==C1)throw Error("bad secret key size")}function e9(){for(var O=0;O<arguments.length;O++)if(!(arguments[O]instanceof Uint8Array))throw TypeError("unexpected type, use Uint8Array")}function UD(O){for(var R=0;R<O.length;R++)O[R]=0}W.randomBytes=function(O){var R=new Uint8Array(O);return G(R,O),R},W.secretbox=function(O,R,C){e9(O,R,C),_U(C,R);var I=new Uint8Array(U0+O.length),L=new Uint8Array(I.length);for(var o=0;o<O.length;o++)I[o+U0]=O[o];return l(L,I,I.length,R,C),L.subarray(T0)},W.secretbox.open=function(O,R,C){e9(O,R,C),_U(C,R);var I=new Uint8Array(T0+O.length),L=new Uint8Array(I.length);for(var o=0;o<O.length;o++)I[o+T0]=O[o];if(I.length<32)return null;if(B(L,I,I.length,R,C)!==0)return null;return L.subarray(U0)},W.secretbox.keyLength=d,W.secretbox.nonceLength=e,W.secretbox.overheadLength=T0,W.scalarMult=function(O,R){if(e9(O,R),O.length!==U8)throw Error("bad n size");if(R.length!==e0)throw Error("bad p size");var C=new Uint8Array(e0);return S0(C,O,R),C},W.scalarMult.base=function(O){if(e9(O),O.length!==U8)throw Error("bad n size");var R=new Uint8Array(e0);return x0(R,O),R},W.scalarMult.scalarLength=U8,W.scalarMult.groupElementLength=e0,W.box=function(O,R,C,I){var L=W.box.before(C,I);return W.secretbox(O,R,L)},W.box.before=function(O,R){e9(O,R),QA(O,R);var C=new Uint8Array(k0);return b0(C,O,R),C},W.box.after=W.secretbox,W.box.open=function(O,R,C,I){var L=W.box.before(C,I);return W.secretbox.open(O,R,L)},W.box.open.after=W.secretbox.open,W.box.keyPair=function(){var O=new Uint8Array(q8),R=new Uint8Array(C1);return D1(O,R),{publicKey:O,secretKey:R}},W.box.keyPair.fromSecretKey=function(O){if(e9(O),O.length!==C1)throw Error("bad secret key size");var R=new Uint8Array(q8);return x0(R,O),{publicKey:R,secretKey:new Uint8Array(O)}},W.box.publicKeyLength=q8,W.box.secretKeyLength=C1,W.box.sharedKeyLength=k0,W.box.nonceLength=m0,W.box.overheadLength=W.secretbox.overheadLength,W.sign=function(O,R){if(e9(O,R),R.length!==Y8)throw Error("bad secret key size");var C=new Uint8Array(A1+O.length);return F8(C,O,O.length,R),C},W.sign.open=function(O,R){if(e9(O,R),R.length!==c1)throw Error("bad public key size");var C=new Uint8Array(O.length),I=Q7(C,O,O.length,R);if(I<0)return null;var L=new Uint8Array(I);for(var o=0;o<L.length;o++)L[o]=C[o];return L},W.sign.detached=function(O,R){var C=W.sign(O,R),I=new Uint8Array(A1);for(var L=0;L<I.length;L++)I[L]=C[L];return I},W.sign.detached.verify=function(O,R,C){if(e9(O,R,C),R.length!==A1)throw Error("bad signature size");if(C.length!==c1)throw Error("bad public key size");var I=new Uint8Array(A1+O.length),L=new Uint8Array(A1+O.length),o;for(o=0;o<A1;o++)I[o]=R[o];for(o=0;o<O.length;o++)I[o+A1]=O[o];return Q7(L,I,I.length,C)>=0},W.sign.keyPair=function(){var O=new Uint8Array(c1),R=new Uint8Array(Y8);return r0(O,R),{publicKey:O,secretKey:R}},W.sign.keyPair.fromSecretKey=function(O){if(e9(O),O.length!==Y8)throw Error("bad secret key size");var R=new Uint8Array(c1);for(var C=0;C<R.length;C++)R[C]=O[32+C];return{publicKey:R,secretKey:new Uint8Array(O)}},W.sign.keyPair.fromSeed=function(O){if(e9(O),O.length!==F9)throw Error("bad seed size");var R=new Uint8Array(c1),C=new Uint8Array(Y8);for(var I=0;I<32;I++)C[I]=O[I];return r0(R,C,!0),{publicKey:R,secretKey:C}},W.sign.publicKeyLength=c1,W.sign.secretKeyLength=Y8,W.sign.seedLength=F9,W.sign.signatureLength=A1,W.hash=function(O){e9(O);var R=new Uint8Array(cY);return H0(R,O,O.length),R},W.hash.hashLength=cY,W.verify=function(O,R){if(e9(O,R),O.length===0||R.length===0)return!1;if(O.length!==R.length)return!1;return w(O,0,R,0,O.length)===0?!0:!1},W.setPRNG=function(O){G=O},function(){var O=typeof self<"u"?self.crypto||self.msCrypto:null;if(O&&O.getRandomValues){var R=65536;W.setPRNG(function(C,I){var L,o=new Uint8Array(I);for(L=0;L<I;L+=R)O.getRandomValues(o.subarray(L,L+Math.min(I-L,R)));for(L=0;L<I;L++)C[L]=o[L];UD(o)})}else if(O=x8("crypto"),O&&O.randomBytes)W.setPRNG(function(C,I){var L,o=O.randomBytes(I);for(L=0;L<I;L++)C[L]=o[L];UD(o)})}()})(typeof SQ<"u"&&fe?fe:self.nacl=self.nacl||{})});var BI=U1((QR)=>{Object.defineProperty(QR,"__esModule",{value:!0});class UR{constructor(W,Y=0,G=0){this.start=Y,this.end=G>Y?G:Y,this.buf=W}get length(){return this.buf.length}reset(W=0,Y=0){if(this.start=W,Y>=this.start)this.end=Y;else if(this.end<this.start)this.end=this.start;return this}walk(W){return this.start=this.end,this.end+=W,this}mustHas(W,Y="Too few bytes to parse."){let G=this.end+W;if(G>this.buf.length){let X=Error(Y);throw X.available=this.buf.length,X.requested=G,X}return this.walk(0),this}mustWalk(W,Y){return this.mustHas(W,Y),this.walk(W),this}}QR.BufferVisitor=UR});var AR=U1((qR)=>{Object.defineProperty(qR,"__esModule",{value:!0});var HR=x8("util"),NR=64,$I="-----BEGIN ",FI="-----END ",mJ="-----",EI="Proc-Type";class SI{static parse(W){let Y=[],G=W.toString("utf8").split(`
|
|
8
8
|
`).map((X)=>X.trim()).filter((X)=>X!==""&&!X.startsWith("#"));while(G.length>0)Y.push(Mb(G));if(Y.length===0)throw Error("PEM: no block");return Y}constructor(W,Y){this.type=W,this.body=Y,this.headers=Object.create(null)}get procType(){return this.getHeader(EI)}getHeader(W){let Y=this.headers[W];return Y==null?"":Y}setHeader(W,Y){if(W.includes(":"))throw Error("pem: cannot encode a header key that contains a colon");if(W===""||Y==="")throw Error("pem: invalid header key or value");this.headers[W]=Y}toString(){let W=$I+this.type+mJ+`
|
|
9
9
|
`,Y=Object.keys(this.headers);if(Y.length>0){let J=this.procType;if(J!=="")W+=`${EI}: ${J}
|
|
10
10
|
`;Y.sort();for(let Z of Y)if(Z!==EI)W+=`${Z}: ${this.headers[Z]}
|
|
@@ -24,7 +24,7 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
24
24
|
|
|
25
25
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
26
26
|
and limitations under the License.
|
|
27
|
-
***************************************************************************** */var xR;(function(W){(function(Y){var G=typeof globalThis==="object"?globalThis:typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:U(),X=J(W);if(typeof G.Reflect<"u")X=J(G.Reflect,X);if(Y(X,G),typeof G.Reflect>"u")G.Reflect=W;function J(Q,H){return function(N,A){if(Object.defineProperty(Q,N,{configurable:!0,writable:!0,value:A}),H)H(N,A)}}function Z(){try{return Function("return this;")()}catch(Q){}}function V(){try{return(0,eval)("(function() { return this; })()")}catch(Q){}}function U(){return Z()||V()}})(function(Y,G){var X=Object.prototype.hasOwnProperty,J=typeof Symbol==="function",Z=J&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",V=J&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",U=typeof Object.create==="function",Q={__proto__:[]}instanceof Array,H=!U&&!Q,N={create:U?function(){return Q7(Object.create(null))}:Q?function(){return Q7({__proto__:null})}:function(){return Q7({})},has:H?function(d,e){return X.call(d,e)}:function(d,e){return e in d},get:H?function(d,e){return X.call(d,e)?d[e]:void 0}:function(d,e){return d[e]}},A=Object.getPrototypeOf(Function),q=typeof Map==="function"&&typeof Map.prototype.entries==="function"?Map:V8(),z=typeof Set==="function"&&typeof Set.prototype.entries==="function"?Set:F8(),w=typeof WeakMap==="function"?WeakMap:$9(),D=J?Symbol.for("@reflect-metadata:registry"):void 0,T=i1(),x=r0(T);function g(d,e,U0,T0){if(!M(U0)){if(!b0(d))throw TypeError();if(!t(e))throw TypeError();if(!t(T0)&&!M(T0)&&!F(T0))throw TypeError();if(F(T0))T0=void 0;return U0=D1(U0),l(d,e,U0,T0)}else{if(!b0(d))throw TypeError();if(!O0(e))throw TypeError();return k(d,e)}}Y("decorate",g);function f(d,e){function U0(T0,e0){if(!t(T0))throw TypeError();if(!M(e0)&&!y0(e0))throw TypeError();n(d,e,T0,e0)}return U0}Y("metadata",f);function y(d,e,U0,T0){if(!t(U0))throw TypeError();if(!M(T0))T0=D1(T0);return n(d,e,U0,T0)}Y("defineMetadata",y);function p(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return B(d,e,U0)}Y("hasMetadata",p);function b(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return $(d,e,U0)}Y("hasOwnMetadata",b);function m(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return h(d,e,U0)}Y("getMetadata",m);function W0(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return a(d,e,U0)}Y("getOwnMetadata",W0);function u(d,e){if(!t(d))throw TypeError();if(!M(e))e=D1(e);return E(d,e)}Y("getMetadataKeys",u);function J0(d,e){if(!t(d))throw TypeError();if(!M(e))e=D1(e);return P(d,e)}Y("getOwnMetadataKeys",J0);function A0(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);var T0=i0(e,U0,!1);if(M(T0))return!1;return T0.OrdinaryDeleteMetadata(d,e,U0)}Y("deleteMetadata",A0);function k(d,e){for(var U0=d.length-1;U0>=0;--U0){var T0=d[U0],e0=T0(e);if(!M(e0)&&!F(e0)){if(!O0(e0))throw TypeError();e=e0}}return e}function l(d,e,U0,T0){for(var e0=d.length-1;e0>=0;--e0){var U8=d[e0],q8=U8(e,U0,T0);if(!M(q8)&&!F(q8)){if(!t(q8))throw TypeError();T0=q8}}return T0}function B(d,e,U0){var T0=$(d,e,U0);if(T0)return!0;var e0=H1(e);if(!F(e0))return B(d,e0,U0);return!1}function $(d,e,U0){var T0=i0(e,U0,!1);if(M(T0))return!1;return S0(T0.OrdinaryHasOwnMetadata(d,e,U0))}function h(d,e,U0){var T0=$(d,e,U0);if(T0)return a(d,e,U0);var e0=H1(e);if(!F(e0))return h(d,e0,U0);return}function a(d,e,U0){var T0=i0(e,U0,!1);if(M(T0))return;return T0.OrdinaryGetOwnMetadata(d,e,U0)}function n(d,e,U0,T0){var e0=i0(U0,T0,!0);e0.OrdinaryDefineOwnMetadata(d,e,U0,T0)}function E(d,e){var U0=P(d,e),T0=H1(d);if(T0===null)return U0;var e0=E(T0,e);if(e0.length<=0)return U0;if(U0.length<=0)return e0;var U8=new z,q8=[];for(var C1=0,k0=U0;C1<k0.length;C1++){var m0=k0[C1],l0=U8.has(m0);if(!l0)U8.add(m0),q8.push(m0)}for(var a0=0,A1=e0;a0<A1.length;a0++){var m0=A1[a0],l0=U8.has(m0);if(!l0)U8.add(m0),q8.push(m0)}return q8}function P(d,e){var U0=i0(d,e,!1);if(!U0)return[];return U0.OrdinaryOwnMetadataKeys(d,e)}function v(d){if(d===null)return 1;switch(typeof d){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return d===null?1:6;default:return 6}}function M(d){return d===void 0}function F(d){return d===null}function c(d){return typeof d==="symbol"}function t(d){return typeof d==="object"?d!==null:typeof d==="function"}function Y0(d,e){switch(v(d)){case 0:return d;case 1:return d;case 2:return d;case 3:return d;case 4:return d;case 5:return d}var U0=e===3?"string":e===5?"number":"default",T0=D0(d,Z);if(T0!==void 0){var e0=T0.call(d,U0);if(t(e0))throw TypeError();return e0}return $0(d,U0==="default"?"number":U0)}function $0(d,e){if(e==="string"){var U0=d.toString;if(Q0(U0)){var T0=U0.call(d);if(!t(T0))return T0}var e0=d.valueOf;if(Q0(e0)){var T0=e0.call(d);if(!t(T0))return T0}}else{var e0=d.valueOf;if(Q0(e0)){var T0=e0.call(d);if(!t(T0))return T0}var U8=d.toString;if(Q0(U8)){var T0=U8.call(d);if(!t(T0))return T0}}throw TypeError()}function S0(d){return!!d}function x0(d){return""+d}function D1(d){var e=Y0(d,3);if(c(e))return e;return x0(e)}function b0(d){return Array.isArray?Array.isArray(d):d instanceof Object?d instanceof Array:Object.prototype.toString.call(d)==="[object Array]"}function Q0(d){return typeof d==="function"}function O0(d){return typeof d==="function"}function y0(d){switch(v(d)){case 3:return!0;case 4:return!0;default:return!1}}function X0(d,e){return d===e||d!==d&&e!==e}function D0(d,e){var U0=d[e];if(U0===void 0||U0===null)return;if(!Q0(U0))throw TypeError();return U0}function L0(d){var e=D0(d,V);if(!Q0(e))throw TypeError();var U0=e.call(d);if(!t(U0))throw TypeError();return U0}function I0(d){return d.value}function F0(d){var e=d.next();return e.done?!1:e}function V1(d){var e=d.return;if(e)e.call(d)}function H1(d){var e=Object.getPrototypeOf(d);if(typeof d!=="function"||d===A)return e;if(e!==A)return e;var U0=d.prototype,T0=U0&&Object.getPrototypeOf(U0);if(T0==null||T0===Object.prototype)return e;var e0=T0.constructor;if(typeof e0!=="function")return e;if(e0===d)return e;return e0}function f1(){var d;if(!M(D)&&typeof G.Reflect<"u"&&!(D in G.Reflect)&&typeof G.Reflect.defineMetadata==="function")d=x1(G.Reflect);var e,U0,T0,e0=new w,U8={registerProvider:q8,getProvider:k0,setProvider:l0};return U8;function q8(a0){if(!Object.isExtensible(U8))throw Error("Cannot add provider to a frozen registry.");switch(!0){case d===a0:break;case M(e):e=a0;break;case e===a0:break;case M(U0):U0=a0;break;case U0===a0:break;default:if(T0===void 0)T0=new z;T0.add(a0);break}}function C1(a0,A1){if(!M(e)){if(e.isProviderFor(a0,A1))return e;if(!M(U0)){if(U0.isProviderFor(a0,A1))return e;if(!M(T0)){var c1=L0(T0);while(!0){var Y8=F0(c1);if(!Y8)return;var F9=I0(Y8);if(F9.isProviderFor(a0,A1))return V1(c1),F9}}}}if(!M(d)&&d.isProviderFor(a0,A1))return d;return}function k0(a0,A1){var c1=e0.get(a0),Y8;if(!M(c1))Y8=c1.get(A1);if(!M(Y8))return Y8;if(Y8=C1(a0,A1),!M(Y8)){if(M(c1))c1=new q,e0.set(a0,c1);c1.set(A1,Y8)}return Y8}function m0(a0){if(M(a0))throw TypeError();return e===a0||U0===a0||!M(T0)&&T0.has(a0)}function l0(a0,A1,c1){if(!m0(c1))throw Error("Metadata provider not registered.");var Y8=k0(a0,A1);if(Y8!==c1){if(!M(Y8))return!1;var F9=e0.get(a0);if(M(F9))F9=new q,e0.set(a0,F9);F9.set(A1,c1)}return!0}}function i1(){var d;if(!M(D)&&t(G.Reflect)&&Object.isExtensible(G.Reflect))d=G.Reflect[D];if(M(d))d=f1();if(!M(D)&&t(G.Reflect)&&Object.isExtensible(G.Reflect))Object.defineProperty(G.Reflect,D,{enumerable:!1,configurable:!1,writable:!1,value:d});return d}function r0(d){var e=new w,U0={isProviderFor:function(m0,l0){var a0=e.get(m0);if(M(a0))return!1;return a0.has(l0)},OrdinaryDefineOwnMetadata:q8,OrdinaryHasOwnMetadata:e0,OrdinaryGetOwnMetadata:U8,OrdinaryOwnMetadataKeys:C1,OrdinaryDeleteMetadata:k0};return T.registerProvider(U0),U0;function T0(m0,l0,a0){var A1=e.get(m0),c1=!1;if(M(A1)){if(!a0)return;A1=new q,e.set(m0,A1),c1=!0}var Y8=A1.get(l0);if(M(Y8)){if(!a0)return;if(Y8=new q,A1.set(l0,Y8),!d.setProvider(m0,l0,U0)){if(A1.delete(l0),c1)e.delete(m0);throw Error("Wrong provider for target.")}}return Y8}function e0(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return!1;return S0(A1.has(m0))}function U8(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return;return A1.get(m0)}function q8(m0,l0,a0,A1){var c1=T0(a0,A1,!0);c1.set(m0,l0)}function C1(m0,l0){var a0=[],A1=T0(m0,l0,!1);if(M(A1))return a0;var c1=A1.keys(),Y8=L0(c1),F9=0;while(!0){var cY=F0(Y8);if(!cY)return a0.length=F9,a0;var _U=I0(cY);try{a0[F9]=_U}catch(QA){try{V1(Y8)}finally{throw QA}}F9++}}function k0(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return!1;if(!A1.delete(m0))return!1;if(A1.size===0){var c1=e.get(l0);if(!M(c1)){if(c1.delete(a0),c1.size===0)e.delete(c1)}}return!0}}function x1(d){var{defineMetadata:e,hasOwnMetadata:U0,getOwnMetadata:T0,getOwnMetadataKeys:e0,deleteMetadata:U8}=d,q8=new w,C1={isProviderFor:function(k0,m0){var l0=q8.get(k0);if(!M(l0)&&l0.has(m0))return!0;if(e0(k0,m0).length){if(M(l0))l0=new z,q8.set(k0,l0);return l0.add(m0),!0}return!1},OrdinaryDefineOwnMetadata:e,OrdinaryHasOwnMetadata:U0,OrdinaryGetOwnMetadata:T0,OrdinaryOwnMetadataKeys:e0,OrdinaryDeleteMetadata:U8};return C1}function i0(d,e,U0){var T0=T.getProvider(d,e);if(!M(T0))return T0;if(U0){if(T.setProvider(d,e,x))return x;throw Error("Illegal state.")}return}function V8(){var d={},e=[],U0=function(){function C1(k0,m0,l0){this._index=0,this._keys=k0,this._values=m0,this._selector=l0}return C1.prototype["@@iterator"]=function(){return this},C1.prototype[V]=function(){return this},C1.prototype.next=function(){var k0=this._index;if(k0>=0&&k0<this._keys.length){var m0=this._selector(this._keys[k0],this._values[k0]);if(k0+1>=this._keys.length)this._index=-1,this._keys=e,this._values=e;else this._index++;return{value:m0,done:!1}}return{value:void 0,done:!0}},C1.prototype.throw=function(k0){if(this._index>=0)this._index=-1,this._keys=e,this._values=e;throw k0},C1.prototype.return=function(k0){if(this._index>=0)this._index=-1,this._keys=e,this._values=e;return{value:k0,done:!0}},C1}(),T0=function(){function C1(){this._keys=[],this._values=[],this._cacheKey=d,this._cacheIndex=-2}return Object.defineProperty(C1.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),C1.prototype.has=function(k0){return this._find(k0,!1)>=0},C1.prototype.get=function(k0){var m0=this._find(k0,!1);return m0>=0?this._values[m0]:void 0},C1.prototype.set=function(k0,m0){var l0=this._find(k0,!0);return this._values[l0]=m0,this},C1.prototype.delete=function(k0){var m0=this._find(k0,!1);if(m0>=0){var l0=this._keys.length;for(var a0=m0+1;a0<l0;a0++)this._keys[a0-1]=this._keys[a0],this._values[a0-1]=this._values[a0];if(this._keys.length--,this._values.length--,X0(k0,this._cacheKey))this._cacheKey=d,this._cacheIndex=-2;return!0}return!1},C1.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=d,this._cacheIndex=-2},C1.prototype.keys=function(){return new U0(this._keys,this._values,e0)},C1.prototype.values=function(){return new U0(this._keys,this._values,U8)},C1.prototype.entries=function(){return new U0(this._keys,this._values,q8)},C1.prototype["@@iterator"]=function(){return this.entries()},C1.prototype[V]=function(){return this.entries()},C1.prototype._find=function(k0,m0){if(!X0(this._cacheKey,k0)){this._cacheIndex=-1;for(var l0=0;l0<this._keys.length;l0++)if(X0(this._keys[l0],k0)){this._cacheIndex=l0;break}}if(this._cacheIndex<0&&m0)this._cacheIndex=this._keys.length,this._keys.push(k0),this._values.push(void 0);return this._cacheIndex},C1}();return T0;function e0(C1,k0){return C1}function U8(C1,k0){return k0}function q8(C1,k0){return[C1,k0]}}function F8(){var d=function(){function e(){this._map=new q}return Object.defineProperty(e.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),e.prototype.has=function(U0){return this._map.has(U0)},e.prototype.add=function(U0){return this._map.set(U0,U0),this},e.prototype.delete=function(U0){return this._map.delete(U0)},e.prototype.clear=function(){this._map.clear()},e.prototype.keys=function(){return this._map.keys()},e.prototype.values=function(){return this._map.keys()},e.prototype.entries=function(){return this._map.entries()},e.prototype["@@iterator"]=function(){return this.keys()},e.prototype[V]=function(){return this.keys()},e}();return d}function $9(){var d=16,e=N.create(),U0=T0();return function(){function k0(){this._key=T0()}return k0.prototype.has=function(m0){var l0=e0(m0,!1);return l0!==void 0?N.has(l0,this._key):!1},k0.prototype.get=function(m0){var l0=e0(m0,!1);return l0!==void 0?N.get(l0,this._key):void 0},k0.prototype.set=function(m0,l0){var a0=e0(m0,!0);return a0[this._key]=l0,this},k0.prototype.delete=function(m0){var l0=e0(m0,!1);return l0!==void 0?delete l0[this._key]:!1},k0.prototype.clear=function(){this._key=T0()},k0}();function T0(){var k0;do k0="@@WeakMap@@"+C1();while(N.has(e,k0));return e[k0]=!0,k0}function e0(k0,m0){if(!X.call(k0,U0)){if(!m0)return;Object.defineProperty(k0,U0,{value:N.create()})}return k0[U0]}function U8(k0,m0){for(var l0=0;l0<m0;++l0)k0[l0]=Math.random()*255|0;return k0}function q8(k0){if(typeof Uint8Array==="function"){var m0=new Uint8Array(k0);if(typeof crypto<"u")crypto.getRandomValues(m0);else if(typeof msCrypto<"u")msCrypto.getRandomValues(m0);else U8(m0,k0);return m0}return U8(Array(k0),k0)}function C1(){var k0=q8(d);k0[6]=k0[6]&79|64,k0[8]=k0[8]&191|128;var m0="";for(var l0=0;l0<d;++l0){var a0=k0[l0];if(l0===4||l0===6||l0===8)m0+="-";if(a0<16)m0+="0";m0+=a0.toString(16).toLowerCase()}return m0}}function Q7(d){return d.__=void 0,delete d.__,d}})})(xR||(xR={}))});var XP=U1((R10,JH)=>{var FM,SM,xM,kM,_M,yM,vM,gM,uM,hM,bM,mM,fM,GH,qz,cM,pM,lM,SG,dM,oM,nM,iM,rM,aM,sM,tM,eM,XH,WP,YP,GP;(function(W){var Y=typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:{};if(typeof define==="function"&&define.amd)define("tslib",["exports"],function(X){W(G(Y,G(X)))});else if(typeof JH==="object"&&typeof R10==="object")W(G(Y,G(R10)));else W(G(Y));function G(X,J){if(X!==Y)if(typeof Object.create==="function")Object.defineProperty(X,"__esModule",{value:!0});else X.__esModule=!0;return function(Z,V){return X[Z]=J?J(Z,V):V}}})(function(W){var Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(Z,V){Z.__proto__=V}||function(Z,V){for(var U in V)if(Object.prototype.hasOwnProperty.call(V,U))Z[U]=V[U]};FM=function(Z,V){if(typeof V!=="function"&&V!==null)throw TypeError("Class extends value "+String(V)+" is not a constructor or null");Y(Z,V);function U(){this.constructor=Z}Z.prototype=V===null?Object.create(V):(U.prototype=V.prototype,new U)},SM=Object.assign||function(Z){for(var V,U=1,Q=arguments.length;U<Q;U++){V=arguments[U];for(var H in V)if(Object.prototype.hasOwnProperty.call(V,H))Z[H]=V[H]}return Z},xM=function(Z,V){var U={};for(var Q in Z)if(Object.prototype.hasOwnProperty.call(Z,Q)&&V.indexOf(Q)<0)U[Q]=Z[Q];if(Z!=null&&typeof Object.getOwnPropertySymbols==="function"){for(var H=0,Q=Object.getOwnPropertySymbols(Z);H<Q.length;H++)if(V.indexOf(Q[H])<0&&Object.prototype.propertyIsEnumerable.call(Z,Q[H]))U[Q[H]]=Z[Q[H]]}return U},kM=function(Z,V,U,Q){var H=arguments.length,N=H<3?V:Q===null?Q=Object.getOwnPropertyDescriptor(V,U):Q,A;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")N=Reflect.decorate(Z,V,U,Q);else for(var q=Z.length-1;q>=0;q--)if(A=Z[q])N=(H<3?A(N):H>3?A(V,U,N):A(V,U))||N;return H>3&&N&&Object.defineProperty(V,U,N),N},_M=function(Z,V){return function(U,Q){V(U,Q,Z)}},yM=function(Z,V,U,Q,H,N){function A(b){if(b!==void 0&&typeof b!=="function")throw TypeError("Function expected");return b}var q=Q.kind,z=q==="getter"?"get":q==="setter"?"set":"value",w=!V&&Z?Q.static?Z:Z.prototype:null,D=V||(w?Object.getOwnPropertyDescriptor(w,Q.name):{}),T,x=!1;for(var g=U.length-1;g>=0;g--){var f={};for(var y in Q)f[y]=y==="access"?{}:Q[y];for(var y in Q.access)f.access[y]=Q.access[y];f.addInitializer=function(b){if(x)throw TypeError("Cannot add initializers after decoration has completed");N.push(A(b||null))};var p=(0,U[g])(q==="accessor"?{get:D.get,set:D.set}:D[z],f);if(q==="accessor"){if(p===void 0)continue;if(p===null||typeof p!=="object")throw TypeError("Object expected");if(T=A(p.get))D.get=T;if(T=A(p.set))D.set=T;if(T=A(p.init))H.unshift(T)}else if(T=A(p))if(q==="field")H.unshift(T);else D[z]=T}if(w)Object.defineProperty(w,Q.name,D);x=!0},vM=function(Z,V,U){var Q=arguments.length>2;for(var H=0;H<V.length;H++)U=Q?V[H].call(Z,U):V[H].call(Z);return Q?U:void 0},gM=function(Z){return typeof Z==="symbol"?Z:"".concat(Z)},uM=function(Z,V,U){if(typeof V==="symbol")V=V.description?"[".concat(V.description,"]"):"";return Object.defineProperty(Z,"name",{configurable:!0,value:U?"".concat(U," ",V):V})},hM=function(Z,V){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(Z,V)},bM=function(Z,V,U,Q){function H(N){return N instanceof U?N:new U(function(A){A(N)})}return new(U||(U=Promise))(function(N,A){function q(D){try{w(Q.next(D))}catch(T){A(T)}}function z(D){try{w(Q.throw(D))}catch(T){A(T)}}function w(D){D.done?N(D.value):H(D.value).then(q,z)}w((Q=Q.apply(Z,V||[])).next())})},mM=function(Z,V){var U={label:0,sent:function(){if(N[0]&1)throw N[1];return N[1]},trys:[],ops:[]},Q,H,N,A=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return A.next=q(0),A.throw=q(1),A.return=q(2),typeof Symbol==="function"&&(A[Symbol.iterator]=function(){return this}),A;function q(w){return function(D){return z([w,D])}}function z(w){if(Q)throw TypeError("Generator is already executing.");while(A&&(A=0,w[0]&&(U=0)),U)try{if(Q=1,H&&(N=w[0]&2?H.return:w[0]?H.throw||((N=H.return)&&N.call(H),0):H.next)&&!(N=N.call(H,w[1])).done)return N;if(H=0,N)w=[w[0]&2,N.value];switch(w[0]){case 0:case 1:N=w;break;case 4:return U.label++,{value:w[1],done:!1};case 5:U.label++,H=w[1],w=[0];continue;case 7:w=U.ops.pop(),U.trys.pop();continue;default:if((N=U.trys,!(N=N.length>0&&N[N.length-1]))&&(w[0]===6||w[0]===2)){U=0;continue}if(w[0]===3&&(!N||w[1]>N[0]&&w[1]<N[3])){U.label=w[1];break}if(w[0]===6&&U.label<N[1]){U.label=N[1],N=w;break}if(N&&U.label<N[2]){U.label=N[2],U.ops.push(w);break}if(N[2])U.ops.pop();U.trys.pop();continue}w=V.call(Z,U)}catch(D){w=[6,D],H=0}finally{Q=N=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}},fM=function(Z,V){for(var U in Z)if(U!=="default"&&!Object.prototype.hasOwnProperty.call(V,U))XH(V,Z,U)},XH=Object.create?function(Z,V,U,Q){if(Q===void 0)Q=U;var H=Object.getOwnPropertyDescriptor(V,U);if(!H||("get"in H?!V.__esModule:H.writable||H.configurable))H={enumerable:!0,get:function(){return V[U]}};Object.defineProperty(Z,Q,H)}:function(Z,V,U,Q){if(Q===void 0)Q=U;Z[Q]=V[U]},GH=function(Z){var V=typeof Symbol==="function"&&Symbol.iterator,U=V&&Z[V],Q=0;if(U)return U.call(Z);if(Z&&typeof Z.length==="number")return{next:function(){if(Z&&Q>=Z.length)Z=void 0;return{value:Z&&Z[Q++],done:!Z}}};throw TypeError(V?"Object is not iterable.":"Symbol.iterator is not defined.")},qz=function(Z,V){var U=typeof Symbol==="function"&&Z[Symbol.iterator];if(!U)return Z;var Q=U.call(Z),H,N=[],A;try{while((V===void 0||V-- >0)&&!(H=Q.next()).done)N.push(H.value)}catch(q){A={error:q}}finally{try{if(H&&!H.done&&(U=Q.return))U.call(Q)}finally{if(A)throw A.error}}return N},cM=function(){for(var Z=[],V=0;V<arguments.length;V++)Z=Z.concat(qz(arguments[V]));return Z},pM=function(){for(var Z=0,V=0,U=arguments.length;V<U;V++)Z+=arguments[V].length;for(var Q=Array(Z),H=0,V=0;V<U;V++)for(var N=arguments[V],A=0,q=N.length;A<q;A++,H++)Q[H]=N[A];return Q},lM=function(Z,V,U){if(U||arguments.length===2){for(var Q=0,H=V.length,N;Q<H;Q++)if(N||!(Q in V)){if(!N)N=Array.prototype.slice.call(V,0,Q);N[Q]=V[Q]}}return Z.concat(N||Array.prototype.slice.call(V))},SG=function(Z){return this instanceof SG?(this.v=Z,this):new SG(Z)},dM=function(Z,V,U){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var Q=U.apply(Z,V||[]),H,N=[];return H=Object.create((typeof AsyncIterator==="function"?AsyncIterator:Object).prototype),q("next"),q("throw"),q("return",A),H[Symbol.asyncIterator]=function(){return this},H;function A(g){return function(f){return Promise.resolve(f).then(g,T)}}function q(g,f){if(Q[g]){if(H[g]=function(y){return new Promise(function(p,b){N.push([g,y,p,b])>1||z(g,y)})},f)H[g]=f(H[g])}}function z(g,f){try{w(Q[g](f))}catch(y){x(N[0][3],y)}}function w(g){g.value instanceof SG?Promise.resolve(g.value.v).then(D,T):x(N[0][2],g)}function D(g){z("next",g)}function T(g){z("throw",g)}function x(g,f){if(g(f),N.shift(),N.length)z(N[0][0],N[0][1])}},oM=function(Z){var V,U;return V={},Q("next"),Q("throw",function(H){throw H}),Q("return"),V[Symbol.iterator]=function(){return this},V;function Q(H,N){V[H]=Z[H]?function(A){return(U=!U)?{value:SG(Z[H](A)),done:!1}:N?N(A):A}:N}},nM=function(Z){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var V=Z[Symbol.asyncIterator],U;return V?V.call(Z):(Z=typeof GH==="function"?GH(Z):Z[Symbol.iterator](),U={},Q("next"),Q("throw"),Q("return"),U[Symbol.asyncIterator]=function(){return this},U);function Q(N){U[N]=Z[N]&&function(A){return new Promise(function(q,z){A=Z[N](A),H(q,z,A.done,A.value)})}}function H(N,A,q,z){Promise.resolve(z).then(function(w){N({value:w,done:q})},A)}},iM=function(Z,V){if(Object.defineProperty)Object.defineProperty(Z,"raw",{value:V});else Z.raw=V;return Z};var G=Object.create?function(Z,V){Object.defineProperty(Z,"default",{enumerable:!0,value:V})}:function(Z,V){Z.default=V},X=function(Z){return X=Object.getOwnPropertyNames||function(V){var U=[];for(var Q in V)if(Object.prototype.hasOwnProperty.call(V,Q))U[U.length]=Q;return U},X(Z)};rM=function(Z){if(Z&&Z.__esModule)return Z;var V={};if(Z!=null){for(var U=X(Z),Q=0;Q<U.length;Q++)if(U[Q]!=="default")XH(V,Z,U[Q])}return G(V,Z),V},aM=function(Z){return Z&&Z.__esModule?Z:{default:Z}},sM=function(Z,V,U,Q){if(U==="a"&&!Q)throw TypeError("Private accessor was defined without a getter");if(typeof V==="function"?Z!==V||!Q:!V.has(Z))throw TypeError("Cannot read private member from an object whose class did not declare it");return U==="m"?Q:U==="a"?Q.call(Z):Q?Q.value:V.get(Z)},tM=function(Z,V,U,Q,H){if(Q==="m")throw TypeError("Private method is not writable");if(Q==="a"&&!H)throw TypeError("Private accessor was defined without a setter");if(typeof V==="function"?Z!==V||!H:!V.has(Z))throw TypeError("Cannot write private member to an object whose class did not declare it");return Q==="a"?H.call(Z,U):H?H.value=U:V.set(Z,U),U},eM=function(Z,V){if(V===null||typeof V!=="object"&&typeof V!=="function")throw TypeError("Cannot use 'in' operator on non-object");return typeof Z==="function"?V===Z:Z.has(V)},WP=function(Z,V,U){if(V!==null&&V!==void 0){if(typeof V!=="object"&&typeof V!=="function")throw TypeError("Object expected.");var Q,H;if(U){if(!Symbol.asyncDispose)throw TypeError("Symbol.asyncDispose is not defined.");Q=V[Symbol.asyncDispose]}if(Q===void 0){if(!Symbol.dispose)throw TypeError("Symbol.dispose is not defined.");if(Q=V[Symbol.dispose],U)H=Q}if(typeof Q!=="function")throw TypeError("Object not disposable.");if(H)Q=function(){try{H.call(this)}catch(N){return Promise.reject(N)}};Z.stack.push({value:V,dispose:Q,async:U})}else if(U)Z.stack.push({async:!0});return V};var J=typeof SuppressedError==="function"?SuppressedError:function(Z,V,U){var Q=Error(U);return Q.name="SuppressedError",Q.error=Z,Q.suppressed=V,Q};YP=function(Z){function V(N){Z.error=Z.hasError?new J(N,Z.error,"An error was suppressed during disposal."):N,Z.hasError=!0}var U,Q=0;function H(){while(U=Z.stack.pop())try{if(!U.async&&Q===1)return Q=0,Z.stack.push(U),Promise.resolve().then(H);if(U.dispose){var N=U.dispose.call(U.value);if(U.async)return Q|=2,Promise.resolve(N).then(H,function(A){return V(A),H()})}else Q|=1}catch(A){V(A)}if(Q===1)return Z.hasError?Promise.reject(Z.error):Promise.resolve();if(Z.hasError)throw Z.error}return H()},GP=function(Z,V){if(typeof Z==="string"&&/^\.\.?\//.test(Z))return Z.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(U,Q,H,N,A){return Q?V?".jsx":".js":H&&(!N||!A)?U:H+N+"."+A.toLowerCase()+"js"});return Z},W("__extends",FM),W("__assign",SM),W("__rest",xM),W("__decorate",kM),W("__param",_M),W("__esDecorate",yM),W("__runInitializers",vM),W("__propKey",gM),W("__setFunctionName",uM),W("__metadata",hM),W("__awaiter",bM),W("__generator",mM),W("__exportStar",fM),W("__createBinding",XH),W("__values",GH),W("__read",qz),W("__spread",cM),W("__spreadArrays",pM),W("__spreadArray",lM),W("__await",SG),W("__asyncGenerator",dM),W("__asyncDelegator",oM),W("__asyncValues",nM),W("__makeTemplateObject",iM),W("__importStar",rM),W("__importDefault",aM),W("__classPrivateFieldGet",sM),W("__classPrivateFieldSet",tM),W("__classPrivateFieldIn",eM),W("__addDisposableResource",WP),W("__disposeResources",YP),W("__rewriteRelativeImportExtension",GP)})});var zL=U1((vJ0,fH)=>{/*! *****************************************************************************
|
|
27
|
+
***************************************************************************** */var xR;(function(W){(function(Y){var G=typeof globalThis==="object"?globalThis:typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:U(),X=J(W);if(typeof G.Reflect<"u")X=J(G.Reflect,X);if(Y(X,G),typeof G.Reflect>"u")G.Reflect=W;function J(Q,H){return function(N,A){if(Object.defineProperty(Q,N,{configurable:!0,writable:!0,value:A}),H)H(N,A)}}function Z(){try{return Function("return this;")()}catch(Q){}}function V(){try{return(0,eval)("(function() { return this; })()")}catch(Q){}}function U(){return Z()||V()}})(function(Y,G){var X=Object.prototype.hasOwnProperty,J=typeof Symbol==="function",Z=J&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",V=J&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",U=typeof Object.create==="function",Q={__proto__:[]}instanceof Array,H=!U&&!Q,N={create:U?function(){return Q7(Object.create(null))}:Q?function(){return Q7({__proto__:null})}:function(){return Q7({})},has:H?function(d,e){return X.call(d,e)}:function(d,e){return e in d},get:H?function(d,e){return X.call(d,e)?d[e]:void 0}:function(d,e){return d[e]}},A=Object.getPrototypeOf(Function),q=typeof Map==="function"&&typeof Map.prototype.entries==="function"?Map:V8(),z=typeof Set==="function"&&typeof Set.prototype.entries==="function"?Set:F8(),w=typeof WeakMap==="function"?WeakMap:$9(),D=J?Symbol.for("@reflect-metadata:registry"):void 0,T=i1(),x=r0(T);function g(d,e,U0,T0){if(!M(U0)){if(!b0(d))throw TypeError();if(!t(e))throw TypeError();if(!t(T0)&&!M(T0)&&!F(T0))throw TypeError();if(F(T0))T0=void 0;return U0=D1(U0),l(d,e,U0,T0)}else{if(!b0(d))throw TypeError();if(!O0(e))throw TypeError();return k(d,e)}}Y("decorate",g);function f(d,e){function U0(T0,e0){if(!t(T0))throw TypeError();if(!M(e0)&&!y0(e0))throw TypeError();n(d,e,T0,e0)}return U0}Y("metadata",f);function y(d,e,U0,T0){if(!t(U0))throw TypeError();if(!M(T0))T0=D1(T0);return n(d,e,U0,T0)}Y("defineMetadata",y);function p(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return B(d,e,U0)}Y("hasMetadata",p);function b(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return $(d,e,U0)}Y("hasOwnMetadata",b);function m(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return h(d,e,U0)}Y("getMetadata",m);function W0(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);return a(d,e,U0)}Y("getOwnMetadata",W0);function u(d,e){if(!t(d))throw TypeError();if(!M(e))e=D1(e);return E(d,e)}Y("getMetadataKeys",u);function J0(d,e){if(!t(d))throw TypeError();if(!M(e))e=D1(e);return P(d,e)}Y("getOwnMetadataKeys",J0);function I0(d,e,U0){if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);if(!t(e))throw TypeError();if(!M(U0))U0=D1(U0);var T0=i0(e,U0,!1);if(M(T0))return!1;return T0.OrdinaryDeleteMetadata(d,e,U0)}Y("deleteMetadata",I0);function k(d,e){for(var U0=d.length-1;U0>=0;--U0){var T0=d[U0],e0=T0(e);if(!M(e0)&&!F(e0)){if(!O0(e0))throw TypeError();e=e0}}return e}function l(d,e,U0,T0){for(var e0=d.length-1;e0>=0;--e0){var U8=d[e0],q8=U8(e,U0,T0);if(!M(q8)&&!F(q8)){if(!t(q8))throw TypeError();T0=q8}}return T0}function B(d,e,U0){var T0=$(d,e,U0);if(T0)return!0;var e0=H1(e);if(!F(e0))return B(d,e0,U0);return!1}function $(d,e,U0){var T0=i0(e,U0,!1);if(M(T0))return!1;return S0(T0.OrdinaryHasOwnMetadata(d,e,U0))}function h(d,e,U0){var T0=$(d,e,U0);if(T0)return a(d,e,U0);var e0=H1(e);if(!F(e0))return h(d,e0,U0);return}function a(d,e,U0){var T0=i0(e,U0,!1);if(M(T0))return;return T0.OrdinaryGetOwnMetadata(d,e,U0)}function n(d,e,U0,T0){var e0=i0(U0,T0,!0);e0.OrdinaryDefineOwnMetadata(d,e,U0,T0)}function E(d,e){var U0=P(d,e),T0=H1(d);if(T0===null)return U0;var e0=E(T0,e);if(e0.length<=0)return U0;if(U0.length<=0)return e0;var U8=new z,q8=[];for(var C1=0,k0=U0;C1<k0.length;C1++){var m0=k0[C1],l0=U8.has(m0);if(!l0)U8.add(m0),q8.push(m0)}for(var a0=0,A1=e0;a0<A1.length;a0++){var m0=A1[a0],l0=U8.has(m0);if(!l0)U8.add(m0),q8.push(m0)}return q8}function P(d,e){var U0=i0(d,e,!1);if(!U0)return[];return U0.OrdinaryOwnMetadataKeys(d,e)}function v(d){if(d===null)return 1;switch(typeof d){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return d===null?1:6;default:return 6}}function M(d){return d===void 0}function F(d){return d===null}function c(d){return typeof d==="symbol"}function t(d){return typeof d==="object"?d!==null:typeof d==="function"}function Y0(d,e){switch(v(d)){case 0:return d;case 1:return d;case 2:return d;case 3:return d;case 4:return d;case 5:return d}var U0=e===3?"string":e===5?"number":"default",T0=D0(d,Z);if(T0!==void 0){var e0=T0.call(d,U0);if(t(e0))throw TypeError();return e0}return $0(d,U0==="default"?"number":U0)}function $0(d,e){if(e==="string"){var U0=d.toString;if(Q0(U0)){var T0=U0.call(d);if(!t(T0))return T0}var e0=d.valueOf;if(Q0(e0)){var T0=e0.call(d);if(!t(T0))return T0}}else{var e0=d.valueOf;if(Q0(e0)){var T0=e0.call(d);if(!t(T0))return T0}var U8=d.toString;if(Q0(U8)){var T0=U8.call(d);if(!t(T0))return T0}}throw TypeError()}function S0(d){return!!d}function x0(d){return""+d}function D1(d){var e=Y0(d,3);if(c(e))return e;return x0(e)}function b0(d){return Array.isArray?Array.isArray(d):d instanceof Object?d instanceof Array:Object.prototype.toString.call(d)==="[object Array]"}function Q0(d){return typeof d==="function"}function O0(d){return typeof d==="function"}function y0(d){switch(v(d)){case 3:return!0;case 4:return!0;default:return!1}}function X0(d,e){return d===e||d!==d&&e!==e}function D0(d,e){var U0=d[e];if(U0===void 0||U0===null)return;if(!Q0(U0))throw TypeError();return U0}function L0(d){var e=D0(d,V);if(!Q0(e))throw TypeError();var U0=e.call(d);if(!t(U0))throw TypeError();return U0}function H0(d){return d.value}function F0(d){var e=d.next();return e.done?!1:e}function V1(d){var e=d.return;if(e)e.call(d)}function H1(d){var e=Object.getPrototypeOf(d);if(typeof d!=="function"||d===A)return e;if(e!==A)return e;var U0=d.prototype,T0=U0&&Object.getPrototypeOf(U0);if(T0==null||T0===Object.prototype)return e;var e0=T0.constructor;if(typeof e0!=="function")return e;if(e0===d)return e;return e0}function y1(){var d;if(!M(D)&&typeof G.Reflect<"u"&&!(D in G.Reflect)&&typeof G.Reflect.defineMetadata==="function")d=x1(G.Reflect);var e,U0,T0,e0=new w,U8={registerProvider:q8,getProvider:k0,setProvider:l0};return U8;function q8(a0){if(!Object.isExtensible(U8))throw Error("Cannot add provider to a frozen registry.");switch(!0){case d===a0:break;case M(e):e=a0;break;case e===a0:break;case M(U0):U0=a0;break;case U0===a0:break;default:if(T0===void 0)T0=new z;T0.add(a0);break}}function C1(a0,A1){if(!M(e)){if(e.isProviderFor(a0,A1))return e;if(!M(U0)){if(U0.isProviderFor(a0,A1))return e;if(!M(T0)){var c1=L0(T0);while(!0){var Y8=F0(c1);if(!Y8)return;var F9=H0(Y8);if(F9.isProviderFor(a0,A1))return V1(c1),F9}}}}if(!M(d)&&d.isProviderFor(a0,A1))return d;return}function k0(a0,A1){var c1=e0.get(a0),Y8;if(!M(c1))Y8=c1.get(A1);if(!M(Y8))return Y8;if(Y8=C1(a0,A1),!M(Y8)){if(M(c1))c1=new q,e0.set(a0,c1);c1.set(A1,Y8)}return Y8}function m0(a0){if(M(a0))throw TypeError();return e===a0||U0===a0||!M(T0)&&T0.has(a0)}function l0(a0,A1,c1){if(!m0(c1))throw Error("Metadata provider not registered.");var Y8=k0(a0,A1);if(Y8!==c1){if(!M(Y8))return!1;var F9=e0.get(a0);if(M(F9))F9=new q,e0.set(a0,F9);F9.set(A1,c1)}return!0}}function i1(){var d;if(!M(D)&&t(G.Reflect)&&Object.isExtensible(G.Reflect))d=G.Reflect[D];if(M(d))d=y1();if(!M(D)&&t(G.Reflect)&&Object.isExtensible(G.Reflect))Object.defineProperty(G.Reflect,D,{enumerable:!1,configurable:!1,writable:!1,value:d});return d}function r0(d){var e=new w,U0={isProviderFor:function(m0,l0){var a0=e.get(m0);if(M(a0))return!1;return a0.has(l0)},OrdinaryDefineOwnMetadata:q8,OrdinaryHasOwnMetadata:e0,OrdinaryGetOwnMetadata:U8,OrdinaryOwnMetadataKeys:C1,OrdinaryDeleteMetadata:k0};return T.registerProvider(U0),U0;function T0(m0,l0,a0){var A1=e.get(m0),c1=!1;if(M(A1)){if(!a0)return;A1=new q,e.set(m0,A1),c1=!0}var Y8=A1.get(l0);if(M(Y8)){if(!a0)return;if(Y8=new q,A1.set(l0,Y8),!d.setProvider(m0,l0,U0)){if(A1.delete(l0),c1)e.delete(m0);throw Error("Wrong provider for target.")}}return Y8}function e0(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return!1;return S0(A1.has(m0))}function U8(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return;return A1.get(m0)}function q8(m0,l0,a0,A1){var c1=T0(a0,A1,!0);c1.set(m0,l0)}function C1(m0,l0){var a0=[],A1=T0(m0,l0,!1);if(M(A1))return a0;var c1=A1.keys(),Y8=L0(c1),F9=0;while(!0){var cY=F0(Y8);if(!cY)return a0.length=F9,a0;var _U=H0(cY);try{a0[F9]=_U}catch(QA){try{V1(Y8)}finally{throw QA}}F9++}}function k0(m0,l0,a0){var A1=T0(l0,a0,!1);if(M(A1))return!1;if(!A1.delete(m0))return!1;if(A1.size===0){var c1=e.get(l0);if(!M(c1)){if(c1.delete(a0),c1.size===0)e.delete(c1)}}return!0}}function x1(d){var{defineMetadata:e,hasOwnMetadata:U0,getOwnMetadata:T0,getOwnMetadataKeys:e0,deleteMetadata:U8}=d,q8=new w,C1={isProviderFor:function(k0,m0){var l0=q8.get(k0);if(!M(l0)&&l0.has(m0))return!0;if(e0(k0,m0).length){if(M(l0))l0=new z,q8.set(k0,l0);return l0.add(m0),!0}return!1},OrdinaryDefineOwnMetadata:e,OrdinaryHasOwnMetadata:U0,OrdinaryGetOwnMetadata:T0,OrdinaryOwnMetadataKeys:e0,OrdinaryDeleteMetadata:U8};return C1}function i0(d,e,U0){var T0=T.getProvider(d,e);if(!M(T0))return T0;if(U0){if(T.setProvider(d,e,x))return x;throw Error("Illegal state.")}return}function V8(){var d={},e=[],U0=function(){function C1(k0,m0,l0){this._index=0,this._keys=k0,this._values=m0,this._selector=l0}return C1.prototype["@@iterator"]=function(){return this},C1.prototype[V]=function(){return this},C1.prototype.next=function(){var k0=this._index;if(k0>=0&&k0<this._keys.length){var m0=this._selector(this._keys[k0],this._values[k0]);if(k0+1>=this._keys.length)this._index=-1,this._keys=e,this._values=e;else this._index++;return{value:m0,done:!1}}return{value:void 0,done:!0}},C1.prototype.throw=function(k0){if(this._index>=0)this._index=-1,this._keys=e,this._values=e;throw k0},C1.prototype.return=function(k0){if(this._index>=0)this._index=-1,this._keys=e,this._values=e;return{value:k0,done:!0}},C1}(),T0=function(){function C1(){this._keys=[],this._values=[],this._cacheKey=d,this._cacheIndex=-2}return Object.defineProperty(C1.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),C1.prototype.has=function(k0){return this._find(k0,!1)>=0},C1.prototype.get=function(k0){var m0=this._find(k0,!1);return m0>=0?this._values[m0]:void 0},C1.prototype.set=function(k0,m0){var l0=this._find(k0,!0);return this._values[l0]=m0,this},C1.prototype.delete=function(k0){var m0=this._find(k0,!1);if(m0>=0){var l0=this._keys.length;for(var a0=m0+1;a0<l0;a0++)this._keys[a0-1]=this._keys[a0],this._values[a0-1]=this._values[a0];if(this._keys.length--,this._values.length--,X0(k0,this._cacheKey))this._cacheKey=d,this._cacheIndex=-2;return!0}return!1},C1.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=d,this._cacheIndex=-2},C1.prototype.keys=function(){return new U0(this._keys,this._values,e0)},C1.prototype.values=function(){return new U0(this._keys,this._values,U8)},C1.prototype.entries=function(){return new U0(this._keys,this._values,q8)},C1.prototype["@@iterator"]=function(){return this.entries()},C1.prototype[V]=function(){return this.entries()},C1.prototype._find=function(k0,m0){if(!X0(this._cacheKey,k0)){this._cacheIndex=-1;for(var l0=0;l0<this._keys.length;l0++)if(X0(this._keys[l0],k0)){this._cacheIndex=l0;break}}if(this._cacheIndex<0&&m0)this._cacheIndex=this._keys.length,this._keys.push(k0),this._values.push(void 0);return this._cacheIndex},C1}();return T0;function e0(C1,k0){return C1}function U8(C1,k0){return k0}function q8(C1,k0){return[C1,k0]}}function F8(){var d=function(){function e(){this._map=new q}return Object.defineProperty(e.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),e.prototype.has=function(U0){return this._map.has(U0)},e.prototype.add=function(U0){return this._map.set(U0,U0),this},e.prototype.delete=function(U0){return this._map.delete(U0)},e.prototype.clear=function(){this._map.clear()},e.prototype.keys=function(){return this._map.keys()},e.prototype.values=function(){return this._map.keys()},e.prototype.entries=function(){return this._map.entries()},e.prototype["@@iterator"]=function(){return this.keys()},e.prototype[V]=function(){return this.keys()},e}();return d}function $9(){var d=16,e=N.create(),U0=T0();return function(){function k0(){this._key=T0()}return k0.prototype.has=function(m0){var l0=e0(m0,!1);return l0!==void 0?N.has(l0,this._key):!1},k0.prototype.get=function(m0){var l0=e0(m0,!1);return l0!==void 0?N.get(l0,this._key):void 0},k0.prototype.set=function(m0,l0){var a0=e0(m0,!0);return a0[this._key]=l0,this},k0.prototype.delete=function(m0){var l0=e0(m0,!1);return l0!==void 0?delete l0[this._key]:!1},k0.prototype.clear=function(){this._key=T0()},k0}();function T0(){var k0;do k0="@@WeakMap@@"+C1();while(N.has(e,k0));return e[k0]=!0,k0}function e0(k0,m0){if(!X.call(k0,U0)){if(!m0)return;Object.defineProperty(k0,U0,{value:N.create()})}return k0[U0]}function U8(k0,m0){for(var l0=0;l0<m0;++l0)k0[l0]=Math.random()*255|0;return k0}function q8(k0){if(typeof Uint8Array==="function"){var m0=new Uint8Array(k0);if(typeof crypto<"u")crypto.getRandomValues(m0);else if(typeof msCrypto<"u")msCrypto.getRandomValues(m0);else U8(m0,k0);return m0}return U8(Array(k0),k0)}function C1(){var k0=q8(d);k0[6]=k0[6]&79|64,k0[8]=k0[8]&191|128;var m0="";for(var l0=0;l0<d;++l0){var a0=k0[l0];if(l0===4||l0===6||l0===8)m0+="-";if(a0<16)m0+="0";m0+=a0.toString(16).toLowerCase()}return m0}}function Q7(d){return d.__=void 0,delete d.__,d}})})(xR||(xR={}))});var XP=U1((R10,JH)=>{var FM,SM,xM,kM,_M,yM,vM,gM,uM,hM,bM,mM,fM,GH,qz,cM,pM,lM,SG,dM,oM,nM,iM,rM,aM,sM,tM,eM,XH,WP,YP,GP;(function(W){var Y=typeof global==="object"?global:typeof self==="object"?self:typeof this==="object"?this:{};if(typeof define==="function"&&define.amd)define("tslib",["exports"],function(X){W(G(Y,G(X)))});else if(typeof JH==="object"&&typeof R10==="object")W(G(Y,G(R10)));else W(G(Y));function G(X,J){if(X!==Y)if(typeof Object.create==="function")Object.defineProperty(X,"__esModule",{value:!0});else X.__esModule=!0;return function(Z,V){return X[Z]=J?J(Z,V):V}}})(function(W){var Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(Z,V){Z.__proto__=V}||function(Z,V){for(var U in V)if(Object.prototype.hasOwnProperty.call(V,U))Z[U]=V[U]};FM=function(Z,V){if(typeof V!=="function"&&V!==null)throw TypeError("Class extends value "+String(V)+" is not a constructor or null");Y(Z,V);function U(){this.constructor=Z}Z.prototype=V===null?Object.create(V):(U.prototype=V.prototype,new U)},SM=Object.assign||function(Z){for(var V,U=1,Q=arguments.length;U<Q;U++){V=arguments[U];for(var H in V)if(Object.prototype.hasOwnProperty.call(V,H))Z[H]=V[H]}return Z},xM=function(Z,V){var U={};for(var Q in Z)if(Object.prototype.hasOwnProperty.call(Z,Q)&&V.indexOf(Q)<0)U[Q]=Z[Q];if(Z!=null&&typeof Object.getOwnPropertySymbols==="function"){for(var H=0,Q=Object.getOwnPropertySymbols(Z);H<Q.length;H++)if(V.indexOf(Q[H])<0&&Object.prototype.propertyIsEnumerable.call(Z,Q[H]))U[Q[H]]=Z[Q[H]]}return U},kM=function(Z,V,U,Q){var H=arguments.length,N=H<3?V:Q===null?Q=Object.getOwnPropertyDescriptor(V,U):Q,A;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")N=Reflect.decorate(Z,V,U,Q);else for(var q=Z.length-1;q>=0;q--)if(A=Z[q])N=(H<3?A(N):H>3?A(V,U,N):A(V,U))||N;return H>3&&N&&Object.defineProperty(V,U,N),N},_M=function(Z,V){return function(U,Q){V(U,Q,Z)}},yM=function(Z,V,U,Q,H,N){function A(b){if(b!==void 0&&typeof b!=="function")throw TypeError("Function expected");return b}var q=Q.kind,z=q==="getter"?"get":q==="setter"?"set":"value",w=!V&&Z?Q.static?Z:Z.prototype:null,D=V||(w?Object.getOwnPropertyDescriptor(w,Q.name):{}),T,x=!1;for(var g=U.length-1;g>=0;g--){var f={};for(var y in Q)f[y]=y==="access"?{}:Q[y];for(var y in Q.access)f.access[y]=Q.access[y];f.addInitializer=function(b){if(x)throw TypeError("Cannot add initializers after decoration has completed");N.push(A(b||null))};var p=(0,U[g])(q==="accessor"?{get:D.get,set:D.set}:D[z],f);if(q==="accessor"){if(p===void 0)continue;if(p===null||typeof p!=="object")throw TypeError("Object expected");if(T=A(p.get))D.get=T;if(T=A(p.set))D.set=T;if(T=A(p.init))H.unshift(T)}else if(T=A(p))if(q==="field")H.unshift(T);else D[z]=T}if(w)Object.defineProperty(w,Q.name,D);x=!0},vM=function(Z,V,U){var Q=arguments.length>2;for(var H=0;H<V.length;H++)U=Q?V[H].call(Z,U):V[H].call(Z);return Q?U:void 0},gM=function(Z){return typeof Z==="symbol"?Z:"".concat(Z)},uM=function(Z,V,U){if(typeof V==="symbol")V=V.description?"[".concat(V.description,"]"):"";return Object.defineProperty(Z,"name",{configurable:!0,value:U?"".concat(U," ",V):V})},hM=function(Z,V){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(Z,V)},bM=function(Z,V,U,Q){function H(N){return N instanceof U?N:new U(function(A){A(N)})}return new(U||(U=Promise))(function(N,A){function q(D){try{w(Q.next(D))}catch(T){A(T)}}function z(D){try{w(Q.throw(D))}catch(T){A(T)}}function w(D){D.done?N(D.value):H(D.value).then(q,z)}w((Q=Q.apply(Z,V||[])).next())})},mM=function(Z,V){var U={label:0,sent:function(){if(N[0]&1)throw N[1];return N[1]},trys:[],ops:[]},Q,H,N,A=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return A.next=q(0),A.throw=q(1),A.return=q(2),typeof Symbol==="function"&&(A[Symbol.iterator]=function(){return this}),A;function q(w){return function(D){return z([w,D])}}function z(w){if(Q)throw TypeError("Generator is already executing.");while(A&&(A=0,w[0]&&(U=0)),U)try{if(Q=1,H&&(N=w[0]&2?H.return:w[0]?H.throw||((N=H.return)&&N.call(H),0):H.next)&&!(N=N.call(H,w[1])).done)return N;if(H=0,N)w=[w[0]&2,N.value];switch(w[0]){case 0:case 1:N=w;break;case 4:return U.label++,{value:w[1],done:!1};case 5:U.label++,H=w[1],w=[0];continue;case 7:w=U.ops.pop(),U.trys.pop();continue;default:if((N=U.trys,!(N=N.length>0&&N[N.length-1]))&&(w[0]===6||w[0]===2)){U=0;continue}if(w[0]===3&&(!N||w[1]>N[0]&&w[1]<N[3])){U.label=w[1];break}if(w[0]===6&&U.label<N[1]){U.label=N[1],N=w;break}if(N&&U.label<N[2]){U.label=N[2],U.ops.push(w);break}if(N[2])U.ops.pop();U.trys.pop();continue}w=V.call(Z,U)}catch(D){w=[6,D],H=0}finally{Q=N=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}},fM=function(Z,V){for(var U in Z)if(U!=="default"&&!Object.prototype.hasOwnProperty.call(V,U))XH(V,Z,U)},XH=Object.create?function(Z,V,U,Q){if(Q===void 0)Q=U;var H=Object.getOwnPropertyDescriptor(V,U);if(!H||("get"in H?!V.__esModule:H.writable||H.configurable))H={enumerable:!0,get:function(){return V[U]}};Object.defineProperty(Z,Q,H)}:function(Z,V,U,Q){if(Q===void 0)Q=U;Z[Q]=V[U]},GH=function(Z){var V=typeof Symbol==="function"&&Symbol.iterator,U=V&&Z[V],Q=0;if(U)return U.call(Z);if(Z&&typeof Z.length==="number")return{next:function(){if(Z&&Q>=Z.length)Z=void 0;return{value:Z&&Z[Q++],done:!Z}}};throw TypeError(V?"Object is not iterable.":"Symbol.iterator is not defined.")},qz=function(Z,V){var U=typeof Symbol==="function"&&Z[Symbol.iterator];if(!U)return Z;var Q=U.call(Z),H,N=[],A;try{while((V===void 0||V-- >0)&&!(H=Q.next()).done)N.push(H.value)}catch(q){A={error:q}}finally{try{if(H&&!H.done&&(U=Q.return))U.call(Q)}finally{if(A)throw A.error}}return N},cM=function(){for(var Z=[],V=0;V<arguments.length;V++)Z=Z.concat(qz(arguments[V]));return Z},pM=function(){for(var Z=0,V=0,U=arguments.length;V<U;V++)Z+=arguments[V].length;for(var Q=Array(Z),H=0,V=0;V<U;V++)for(var N=arguments[V],A=0,q=N.length;A<q;A++,H++)Q[H]=N[A];return Q},lM=function(Z,V,U){if(U||arguments.length===2){for(var Q=0,H=V.length,N;Q<H;Q++)if(N||!(Q in V)){if(!N)N=Array.prototype.slice.call(V,0,Q);N[Q]=V[Q]}}return Z.concat(N||Array.prototype.slice.call(V))},SG=function(Z){return this instanceof SG?(this.v=Z,this):new SG(Z)},dM=function(Z,V,U){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var Q=U.apply(Z,V||[]),H,N=[];return H=Object.create((typeof AsyncIterator==="function"?AsyncIterator:Object).prototype),q("next"),q("throw"),q("return",A),H[Symbol.asyncIterator]=function(){return this},H;function A(g){return function(f){return Promise.resolve(f).then(g,T)}}function q(g,f){if(Q[g]){if(H[g]=function(y){return new Promise(function(p,b){N.push([g,y,p,b])>1||z(g,y)})},f)H[g]=f(H[g])}}function z(g,f){try{w(Q[g](f))}catch(y){x(N[0][3],y)}}function w(g){g.value instanceof SG?Promise.resolve(g.value.v).then(D,T):x(N[0][2],g)}function D(g){z("next",g)}function T(g){z("throw",g)}function x(g,f){if(g(f),N.shift(),N.length)z(N[0][0],N[0][1])}},oM=function(Z){var V,U;return V={},Q("next"),Q("throw",function(H){throw H}),Q("return"),V[Symbol.iterator]=function(){return this},V;function Q(H,N){V[H]=Z[H]?function(A){return(U=!U)?{value:SG(Z[H](A)),done:!1}:N?N(A):A}:N}},nM=function(Z){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var V=Z[Symbol.asyncIterator],U;return V?V.call(Z):(Z=typeof GH==="function"?GH(Z):Z[Symbol.iterator](),U={},Q("next"),Q("throw"),Q("return"),U[Symbol.asyncIterator]=function(){return this},U);function Q(N){U[N]=Z[N]&&function(A){return new Promise(function(q,z){A=Z[N](A),H(q,z,A.done,A.value)})}}function H(N,A,q,z){Promise.resolve(z).then(function(w){N({value:w,done:q})},A)}},iM=function(Z,V){if(Object.defineProperty)Object.defineProperty(Z,"raw",{value:V});else Z.raw=V;return Z};var G=Object.create?function(Z,V){Object.defineProperty(Z,"default",{enumerable:!0,value:V})}:function(Z,V){Z.default=V},X=function(Z){return X=Object.getOwnPropertyNames||function(V){var U=[];for(var Q in V)if(Object.prototype.hasOwnProperty.call(V,Q))U[U.length]=Q;return U},X(Z)};rM=function(Z){if(Z&&Z.__esModule)return Z;var V={};if(Z!=null){for(var U=X(Z),Q=0;Q<U.length;Q++)if(U[Q]!=="default")XH(V,Z,U[Q])}return G(V,Z),V},aM=function(Z){return Z&&Z.__esModule?Z:{default:Z}},sM=function(Z,V,U,Q){if(U==="a"&&!Q)throw TypeError("Private accessor was defined without a getter");if(typeof V==="function"?Z!==V||!Q:!V.has(Z))throw TypeError("Cannot read private member from an object whose class did not declare it");return U==="m"?Q:U==="a"?Q.call(Z):Q?Q.value:V.get(Z)},tM=function(Z,V,U,Q,H){if(Q==="m")throw TypeError("Private method is not writable");if(Q==="a"&&!H)throw TypeError("Private accessor was defined without a setter");if(typeof V==="function"?Z!==V||!H:!V.has(Z))throw TypeError("Cannot write private member to an object whose class did not declare it");return Q==="a"?H.call(Z,U):H?H.value=U:V.set(Z,U),U},eM=function(Z,V){if(V===null||typeof V!=="object"&&typeof V!=="function")throw TypeError("Cannot use 'in' operator on non-object");return typeof Z==="function"?V===Z:Z.has(V)},WP=function(Z,V,U){if(V!==null&&V!==void 0){if(typeof V!=="object"&&typeof V!=="function")throw TypeError("Object expected.");var Q,H;if(U){if(!Symbol.asyncDispose)throw TypeError("Symbol.asyncDispose is not defined.");Q=V[Symbol.asyncDispose]}if(Q===void 0){if(!Symbol.dispose)throw TypeError("Symbol.dispose is not defined.");if(Q=V[Symbol.dispose],U)H=Q}if(typeof Q!=="function")throw TypeError("Object not disposable.");if(H)Q=function(){try{H.call(this)}catch(N){return Promise.reject(N)}};Z.stack.push({value:V,dispose:Q,async:U})}else if(U)Z.stack.push({async:!0});return V};var J=typeof SuppressedError==="function"?SuppressedError:function(Z,V,U){var Q=Error(U);return Q.name="SuppressedError",Q.error=Z,Q.suppressed=V,Q};YP=function(Z){function V(N){Z.error=Z.hasError?new J(N,Z.error,"An error was suppressed during disposal."):N,Z.hasError=!0}var U,Q=0;function H(){while(U=Z.stack.pop())try{if(!U.async&&Q===1)return Q=0,Z.stack.push(U),Promise.resolve().then(H);if(U.dispose){var N=U.dispose.call(U.value);if(U.async)return Q|=2,Promise.resolve(N).then(H,function(A){return V(A),H()})}else Q|=1}catch(A){V(A)}if(Q===1)return Z.hasError?Promise.reject(Z.error):Promise.resolve();if(Z.hasError)throw Z.error}return H()},GP=function(Z,V){if(typeof Z==="string"&&/^\.\.?\//.test(Z))return Z.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(U,Q,H,N,A){return Q?V?".jsx":".js":H&&(!N||!A)?U:H+N+"."+A.toLowerCase()+"js"});return Z},W("__extends",FM),W("__assign",SM),W("__rest",xM),W("__decorate",kM),W("__param",_M),W("__esDecorate",yM),W("__runInitializers",vM),W("__propKey",gM),W("__setFunctionName",uM),W("__metadata",hM),W("__awaiter",bM),W("__generator",mM),W("__exportStar",fM),W("__createBinding",XH),W("__values",GH),W("__read",qz),W("__spread",cM),W("__spreadArrays",pM),W("__spreadArray",lM),W("__await",SG),W("__asyncGenerator",dM),W("__asyncDelegator",oM),W("__asyncValues",nM),W("__makeTemplateObject",iM),W("__importStar",rM),W("__importDefault",aM),W("__classPrivateFieldGet",sM),W("__classPrivateFieldSet",tM),W("__classPrivateFieldIn",eM),W("__addDisposableResource",WP),W("__disposeResources",YP),W("__rewriteRelativeImportExtension",GP)})});var zL=U1((vJ0,fH)=>{/*! *****************************************************************************
|
|
28
28
|
Copyright (c) Microsoft Corporation.
|
|
29
29
|
|
|
30
30
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -144,7 +144,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
144
144
|
this.index += bytes;
|
|
145
145
|
return value;
|
|
146
146
|
}
|
|
147
|
-
`),ZN.prototype[W]=Y.toFunction({assertSize:Mj})});JE.exports=ZN;function Mj(W,Y){if(W>Y)throw new fp(W,Y)}});var j8=U1((aH0,IE)=>{var Pj=wV(),cp=uB(),pp=fB(),lp=pB(),dp=dB(),op=iB(),VE=aB(),np=tB(),ip=YE(),{encode:HE}=OV(),{decode:NE}=zX(),{encodingLength:rp}=KV(),ap=ZE(),qE=AX(),AE={array:cp,bool:lp,buffer:pp,reserved:dp,string:op,when:np,select:ip};for(let W of Object.keys(VE))AE[W]=VE[W];var VN=Symbol("schema");function UE(W){let Y=new Pj({readableObjectMode:!1,writableObjectMode:!0,transform:sp});return Y[VN]=W,Y}function QE(W){let Y=null,G=Buffer.isBuffer(W);if(!G)Y=W;let X=new Pj({transform:tp,readableObjectMode:!0,writableObjectMode:!1});if(X[VN]=Y,G)X.append(W);return X}function sp(W,Y,G){try{HE(W,this[VN],this);let X=this.slice();this.consume(X.length),G(null,X)}catch(X){G(X)}}function tp(W,Y,G){this.append(W);try{while(this.length>0){let X=new ap(this),J=NE(X,this[VN]);X.commit(),this.push(J)}G()}catch(X){if(X instanceof qE)G();else G(X)}}IE.exports={createEncodeStream:UE,createDecodeStream:QE,encode:HE,decode:NE,encodingLength:rp,createEncode:UE,createDecode:QE,types:AE,BinaryStream:Pj,NotEnoughDataError:qE}});var A$=U1((N$)=>{Object.defineProperty(N$,"__esModule",{value:!0});N$.LEB128=N$.SignedLEB128=N$.UnsignedLEB128=void 0;var TX;(function(W){W[W.LOWER_7=127]="LOWER_7",W[W.UPPER_1=128]="UPPER_1"})(TX||(TX={}));var H$=(W)=>Number.isSafeInteger(W);class RX{static decode(W,Y=0){let G=this.$scanForNullBytes(W,Y),X=0,J=0;for(let Z=0;Z<=G-Y;Z++){let V=W[Y+Z]&TX.LOWER_7;X|=V<<J,J+=7}return X}static encode(W){if(this.check(W),W<0)throw Error(`An unsigned number must NOT be negative, ${W} is!`);let Y=[],G=W;do{let X=G&TX.LOWER_7;if(G>>=7,G)X=X|TX.UPPER_1;Y.push(X)}while(G);return Uint8Array.from(Y)}static check(W){if(!H$(W))throw Error(`${W} is not a safe integer!`)}static $scanForNullBytes(W,Y=0){let G=Y,X=0;do{if(G>=W.byteLength)throw Error("This is not a LEB128-encoded Uint8Array, no ending found!");X=W.slice(G,G+1)[0],G++}while(X&TX.UPPER_1);return G-1}static getLength(W,Y=0){return this.$scanForNullBytes(W,Y)-Y}}N$.UnsignedLEB128=RX;class CN{static $ceil7mul(W){let Y=W;while(Y%7)Y++;return Y}static check(W){if(!H$(W))throw Error(`${W} is not a safe integer!`)}static encode(W){if(this.check(W),W>=0)throw Error(`A signed number must be negative, ${W} isn't!`);let Y=Math.ceil(Math.log2(-W));return RX.encode((1<<this.$ceil7mul(Y))+W)}static decode(W,Y=0){let G=RX.decode(W,Y);return-((1<<Math.ceil(Math.log2(G)))-G)}}N$.SignedLEB128=CN;class TN{}N$.LEB128=TN;TN.encode=(W)=>(W>=0?RX:CN).encode(W);TN.decode=(W,Y=0,G=!1)=>(G?CN:RX).decode(W,Y)});var z$=U1((dj,I$)=>{/*! MIT License. Copyright 2015-2018 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */(function(W){function Y(E){return parseInt(E)===E}function G(E){if(!Y(E.length))return!1;for(var P=0;P<E.length;P++)if(!Y(E[P])||E[P]<0||E[P]>255)return!1;return!0}function X(E,P){if(E.buffer&&E.name==="Uint8Array"){if(P)if(E.slice)E=E.slice();else E=Array.prototype.slice.call(E);return E}if(Array.isArray(E)){if(!G(E))throw Error("Array contains invalid value: "+E);return new Uint8Array(E)}if(Y(E.length)&&G(E))return new Uint8Array(E);throw Error("unsupported array-like object")}function J(E){return new Uint8Array(E)}function Z(E,P,v,M,F){if(M!=null||F!=null)if(E.slice)E=E.slice(M,F);else E=Array.prototype.slice.call(E,M,F);P.set(E,v)}var V=function(){function E(v){var M=[],F=0;v=encodeURI(v);while(F<v.length){var c=v.charCodeAt(F++);if(c===37)M.push(parseInt(v.substr(F,2),16)),F+=2;else M.push(c)}return X(M)}function P(v){var M=[],F=0;while(F<v.length){var c=v[F];if(c<128)M.push(String.fromCharCode(c)),F++;else if(c>191&&c<224)M.push(String.fromCharCode((c&31)<<6|v[F+1]&63)),F+=2;else M.push(String.fromCharCode((c&15)<<12|(v[F+1]&63)<<6|v[F+2]&63)),F+=3}return M.join("")}return{toBytes:E,fromBytes:P}}(),U=function(){function E(M){var F=[];for(var c=0;c<M.length;c+=2)F.push(parseInt(M.substr(c,2),16));return F}var P="0123456789abcdef";function v(M){var F=[];for(var c=0;c<M.length;c++){var t=M[c];F.push(P[(t&240)>>4]+P[t&15])}return F.join("")}return{toBytes:E,fromBytes:v}}(),Q={16:10,24:12,32:14},H=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],N=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],A=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],q=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],z=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],w=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],D=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],T=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],x=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],g=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239000,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],f=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998000,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],y=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],p=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],b=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239000,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],m=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998000,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function W0(E){var P=[];for(var v=0;v<E.length;v+=4)P.push(E[v]<<24|E[v+1]<<16|E[v+2]<<8|E[v+3]);return P}var u=function(E){if(!(this instanceof u))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:X(E,!0)}),this._prepare()};u.prototype._prepare=function(){var E=Q[this.key.length];if(E==null)throw Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var P=0;P<=E;P++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var v=(E+1)*4,M=this.key.length/4,F=W0(this.key),c;for(var P=0;P<M;P++)c=P>>2,this._Ke[c][P%4]=F[P],this._Kd[E-c][P%4]=F[P];var t=0,Y0=M,$0;while(Y0<v){if($0=F[M-1],F[0]^=N[$0>>16&255]<<24^N[$0>>8&255]<<16^N[$0&255]<<8^N[$0>>24&255]^H[t]<<24,t+=1,M!=8)for(var P=1;P<M;P++)F[P]^=F[P-1];else{for(var P=1;P<M/2;P++)F[P]^=F[P-1];$0=F[M/2-1],F[M/2]^=N[$0&255]^N[$0>>8&255]<<8^N[$0>>16&255]<<16^N[$0>>24&255]<<24;for(var P=M/2+1;P<M;P++)F[P]^=F[P-1]}var P=0,S0,x0;while(P<M&&Y0<v)S0=Y0>>2,x0=Y0%4,this._Ke[S0][x0]=F[P],this._Kd[E-S0][x0]=F[P++],Y0++}for(var S0=1;S0<E;S0++)for(var x0=0;x0<4;x0++)$0=this._Kd[S0][x0],this._Kd[S0][x0]=y[$0>>24&255]^p[$0>>16&255]^b[$0>>8&255]^m[$0&255]},u.prototype.encrypt=function(E){if(E.length!=16)throw Error("invalid plaintext size (must be 16 bytes)");var P=this._Ke.length-1,v=[0,0,0,0],M=W0(E);for(var F=0;F<4;F++)M[F]^=this._Ke[0][F];for(var c=1;c<P;c++){for(var F=0;F<4;F++)v[F]=q[M[F]>>24&255]^z[M[(F+1)%4]>>16&255]^w[M[(F+2)%4]>>8&255]^D[M[(F+3)%4]&255]^this._Ke[c][F];M=v.slice()}var t=J(16),Y0;for(var F=0;F<4;F++)Y0=this._Ke[P][F],t[4*F]=(N[M[F]>>24&255]^Y0>>24)&255,t[4*F+1]=(N[M[(F+1)%4]>>16&255]^Y0>>16)&255,t[4*F+2]=(N[M[(F+2)%4]>>8&255]^Y0>>8)&255,t[4*F+3]=(N[M[(F+3)%4]&255]^Y0)&255;return t},u.prototype.decrypt=function(E){if(E.length!=16)throw Error("invalid ciphertext size (must be 16 bytes)");var P=this._Kd.length-1,v=[0,0,0,0],M=W0(E);for(var F=0;F<4;F++)M[F]^=this._Kd[0][F];for(var c=1;c<P;c++){for(var F=0;F<4;F++)v[F]=T[M[F]>>24&255]^x[M[(F+3)%4]>>16&255]^g[M[(F+2)%4]>>8&255]^f[M[(F+1)%4]&255]^this._Kd[c][F];M=v.slice()}var t=J(16),Y0;for(var F=0;F<4;F++)Y0=this._Kd[P][F],t[4*F]=(A[M[F]>>24&255]^Y0>>24)&255,t[4*F+1]=(A[M[(F+3)%4]>>16&255]^Y0>>16)&255,t[4*F+2]=(A[M[(F+2)%4]>>8&255]^Y0>>8)&255,t[4*F+3]=(A[M[(F+1)%4]&255]^Y0)&255;return t};var J0=function(E){if(!(this instanceof J0))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new u(E)};J0.prototype.encrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16)Z(E,v,0,M,M+16),v=this._aes.encrypt(v),Z(v,P,M);return P},J0.prototype.decrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16)Z(E,v,0,M,M+16),v=this._aes.decrypt(v),Z(v,P,M);return P};var A0=function(E,P){if(!(this instanceof A0))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastCipherblock=X(P,!0),this._aes=new u(E)};A0.prototype.encrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16){Z(E,v,0,M,M+16);for(var F=0;F<16;F++)v[F]^=this._lastCipherblock[F];this._lastCipherblock=this._aes.encrypt(v),Z(this._lastCipherblock,P,M)}return P},A0.prototype.decrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16){Z(E,v,0,M,M+16),v=this._aes.decrypt(v);for(var F=0;F<16;F++)P[M+F]=v[F]^this._lastCipherblock[F];Z(E,this._lastCipherblock,0,M,M+16)}return P};var k=function(E,P,v){if(!(this instanceof k))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 size)");if(!v)v=1;this.segmentSize=v,this._shiftRegister=X(P,!0),this._aes=new u(E)};k.prototype.encrypt=function(E){if(E.length%this.segmentSize!=0)throw Error("invalid plaintext size (must be segmentSize bytes)");var P=X(E,!0),v;for(var M=0;M<P.length;M+=this.segmentSize){v=this._aes.encrypt(this._shiftRegister);for(var F=0;F<this.segmentSize;F++)P[M+F]^=v[F];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(P,this._shiftRegister,16-this.segmentSize,M,M+this.segmentSize)}return P},k.prototype.decrypt=function(E){if(E.length%this.segmentSize!=0)throw Error("invalid ciphertext size (must be segmentSize bytes)");var P=X(E,!0),v;for(var M=0;M<P.length;M+=this.segmentSize){v=this._aes.encrypt(this._shiftRegister);for(var F=0;F<this.segmentSize;F++)P[M+F]^=v[F];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(E,this._shiftRegister,16-this.segmentSize,M,M+this.segmentSize)}return P};var l=function(E,P){if(!(this instanceof l))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastPrecipher=X(P,!0),this._lastPrecipherIndex=16,this._aes=new u(E)};l.prototype.encrypt=function(E){var P=X(E,!0);for(var v=0;v<P.length;v++){if(this._lastPrecipherIndex===16)this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0;P[v]^=this._lastPrecipher[this._lastPrecipherIndex++]}return P},l.prototype.decrypt=l.prototype.encrypt;var B=function(E){if(!(this instanceof B))throw Error("Counter must be instanitated with `new`");if(E!==0&&!E)E=1;if(typeof E==="number")this._counter=J(16),this.setValue(E);else this.setBytes(E)};B.prototype.setValue=function(E){if(typeof E!=="number"||parseInt(E)!=E)throw Error("invalid counter value (must be an integer)");if(E>Number.MAX_SAFE_INTEGER)throw Error("integer value out of safe range");for(var P=15;P>=0;--P)this._counter[P]=E%256,E=parseInt(E/256)},B.prototype.setBytes=function(E){if(E=X(E,!0),E.length!=16)throw Error("invalid counter bytes size (must be 16 bytes)");this._counter=E},B.prototype.increment=function(){for(var E=15;E>=0;E--)if(this._counter[E]===255)this._counter[E]=0;else{this._counter[E]++;break}};var $=function(E,P){if(!(this instanceof $))throw Error("AES must be instanitated with `new`");if(this.description="Counter",this.name="ctr",!(P instanceof B))P=new B(P);this._counter=P,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new u(E)};$.prototype.encrypt=function(E){var P=X(E,!0);for(var v=0;v<P.length;v++){if(this._remainingCounterIndex===16)this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment();P[v]^=this._remainingCounter[this._remainingCounterIndex++]}return P},$.prototype.decrypt=$.prototype.encrypt;function h(E){E=X(E,!0);var P=16-E.length%16,v=J(E.length+P);Z(E,v);for(var M=E.length;M<v.length;M++)v[M]=P;return v}function a(E){if(E=X(E,!0),E.length<16)throw Error("PKCS#7 invalid length");var P=E[E.length-1];if(P>16)throw Error("PKCS#7 padding byte out of range");var v=E.length-P;for(var M=0;M<P;M++)if(E[v+M]!==P)throw Error("PKCS#7 invalid padding byte");var F=J(v);return Z(E,F,0,0,v),F}var n={AES:u,Counter:B,ModeOfOperation:{ecb:J0,cbc:A0,cfb:k,ofb:l,ctr:$},utils:{hex:U,utf8:V},padding:{pkcs7:{pad:h,strip:a}},_arrayTest:{coerceArray:X,createArray:J,copyArray:Z}};if(typeof dj<"u")I$.exports=n;else if(typeof define==="function"&&define.amd)define([],function(){return n});else{if(W.aesjs)n._aesjs=W.aesjs;W.aesjs=n}})(dj)});var rj=U1((C$)=>{var G1=C$,{Buffer:LN}=x8("buffer"),ul=x8("os");G1.toBuffer=function(W,Y,G){G=~~G;let X;if(this.isV4Format(W))X=Y||LN.alloc(G+4),W.split(/\./g).map((J)=>{X[G++]=parseInt(J,10)&255});else if(this.isV6Format(W)){let J=W.split(":",8),Z;for(Z=0;Z<J.length;Z++){let V=this.isV4Format(J[Z]),U;if(V)U=this.toBuffer(J[Z]),J[Z]=U.slice(0,2).toString("hex");if(U&&++Z<8)J.splice(Z,0,U.slice(2,4).toString("hex"))}if(J[0]==="")while(J.length<8)J.unshift("0");else if(J[J.length-1]==="")while(J.length<8)J.push("0");else if(J.length<8){for(Z=0;Z<J.length&&J[Z]!=="";Z++);let V=[Z,1];for(Z=9-J.length;Z>0;Z--)V.push("0");J.splice(...V)}X=Y||LN.alloc(G+16);for(Z=0;Z<J.length;Z++){let V=parseInt(J[Z],16);X[G++]=V>>8&255,X[G++]=V&255}}if(!X)throw Error(`Invalid ip address: ${W}`);return X};G1.toString=function(W,Y,G){Y=~~Y,G=G||W.length-Y;let X=[];if(G===4){for(let J=0;J<G;J++)X.push(W[Y+J]);X=X.join(".")}else if(G===16){for(let J=0;J<G;J+=2)X.push(W.readUInt16BE(Y+J).toString(16));X=X.join(":"),X=X.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),X=X.replace(/:{3,4}/,"::")}return X};var hl=/^(\d{1,3}\.){3,3}\d{1,3}$/,bl=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;G1.isV4Format=function(W){return hl.test(W)};G1.isV6Format=function(W){return bl.test(W)};function FV(W){if(W===4)return"ipv4";if(W===6)return"ipv6";return W?W.toLowerCase():"ipv4"}G1.fromPrefixLen=function(W,Y){if(W>32)Y="ipv6";else Y=FV(Y);let G=4;if(Y==="ipv6")G=16;let X=LN.alloc(G);for(let J=0,Z=X.length;J<Z;++J){let V=8;if(W<8)V=W;W-=V,X[J]=~(255>>V)&255}return G1.toString(X)};G1.mask=function(W,Y){W=G1.toBuffer(W),Y=G1.toBuffer(Y);let G=LN.alloc(Math.max(W.length,Y.length)),X;if(W.length===Y.length)for(X=0;X<W.length;X++)G[X]=W[X]&Y[X];else if(Y.length===4)for(X=0;X<Y.length;X++)G[X]=W[W.length-4+X]&Y[X];else{for(X=0;X<G.length-6;X++)G[X]=0;G[10]=255,G[11]=255;for(X=0;X<W.length;X++)G[X+12]=W[X]&Y[X+12];X+=12}for(;X<G.length;X++)G[X]=0;return G1.toString(G)};G1.cidr=function(W){let Y=W.split("/"),G=Y[0];if(Y.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let X=G1.fromPrefixLen(parseInt(Y[1],10));return G1.mask(G,X)};G1.subnet=function(W,Y){let G=G1.toLong(G1.mask(W,Y)),X=G1.toBuffer(Y),J=0;for(let V=0;V<X.length;V++)if(X[V]===255)J+=8;else{let U=X[V]&255;while(U)U=U<<1&255,J++}let Z=2**(32-J);return{networkAddress:G1.fromLong(G),firstAddress:Z<=2?G1.fromLong(G):G1.fromLong(G+1),lastAddress:Z<=2?G1.fromLong(G+Z-1):G1.fromLong(G+Z-2),broadcastAddress:G1.fromLong(G+Z-1),subnetMask:Y,subnetMaskLength:J,numHosts:Z<=2?Z:Z-2,length:Z,contains(V){return G===G1.toLong(G1.mask(V,Y))}}};G1.cidrSubnet=function(W){let Y=W.split("/"),G=Y[0];if(Y.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let X=G1.fromPrefixLen(parseInt(Y[1],10));return G1.subnet(G,X)};G1.not=function(W){let Y=G1.toBuffer(W);for(let G=0;G<Y.length;G++)Y[G]=255^Y[G];return G1.toString(Y)};G1.or=function(W,Y){if(W=G1.toBuffer(W),Y=G1.toBuffer(Y),W.length===Y.length){for(let Z=0;Z<W.length;++Z)W[Z]|=Y[Z];return G1.toString(W)}let G=W,X=Y;if(Y.length>W.length)G=Y,X=W;let J=G.length-X.length;for(let Z=J;Z<G.length;++Z)G[Z]|=X[Z-J];return G1.toString(G)};G1.isEqual=function(W,Y){if(W=G1.toBuffer(W),Y=G1.toBuffer(Y),W.length===Y.length){for(let X=0;X<W.length;X++)if(W[X]!==Y[X])return!1;return!0}if(Y.length===4){let X=Y;Y=W,W=X}for(let X=0;X<10;X++)if(Y[X]!==0)return!1;let G=Y.readUInt16BE(10);if(G!==0&&G!==65535)return!1;for(let X=0;X<4;X++)if(W[X]!==Y[X+12])return!1;return!0};G1.isPrivate=function(W){if(G1.isLoopback(W))return!0;if(!G1.isV6Format(W)){let Y=G1.normalizeToLong(W);if(Y<0)throw Error("invalid ipv4 address");W=G1.fromLong(Y)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^f[cd][0-9a-f]{2}:/i.test(W)||/^fe80:/i.test(W)||/^::1$/.test(W)||/^::$/.test(W)};G1.isPublic=function(W){return!G1.isPrivate(W)};G1.isLoopback=function(W){if(!/\./.test(W)&&!/:/.test(W))W=G1.fromLong(Number(W));return/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(W)||/^0177\./.test(W)||/^0x7f\./i.test(W)||/^fe80::1$/i.test(W)||/^::1$/.test(W)||/^::$/.test(W)};G1.loopback=function(W){if(W=FV(W),W!=="ipv4"&&W!=="ipv6")throw Error("family must be ipv4 or ipv6");return W==="ipv4"?"127.0.0.1":"fe80::1"};G1.address=function(W,Y){let G=ul.networkInterfaces();if(Y=FV(Y),W&&W!=="private"&&W!=="public"){let J=G[W].filter((Z)=>{return FV(Z.family)===Y});if(J.length===0)return;return J[0].address}let X=Object.keys(G).map((J)=>{let Z=G[J].filter((V)=>{if(V.family=FV(V.family),V.family!==Y||G1.isLoopback(V.address))return!1;if(!W)return!0;return W==="public"?G1.isPrivate(V.address):G1.isPublic(V.address)});return Z.length?Z[0].address:void 0}).filter(Boolean);return!X.length?G1.loopback(Y):X[0]};G1.toLong=function(W){let Y=0;return W.split(".").forEach((G)=>{Y<<=8,Y+=parseInt(G)}),Y>>>0};G1.fromLong=function(W){return`${W>>>24}.${W>>16&255}.${W>>8&255}.${W&255}`};G1.normalizeToLong=function(W){let Y=W.split(".").map((J)=>{if(J.startsWith("0x")||J.startsWith("0X"))return parseInt(J,16);else if(J.startsWith("0")&&J!=="0"&&/^[0-7]+$/.test(J))return parseInt(J,8);else if(/^[1-9]\d*$/.test(J)||J==="0")return parseInt(J,10);else return NaN});if(Y.some(isNaN))return-1;let G=0;switch(Y.length){case 1:G=Y[0];break;case 2:if(Y[0]>255||Y[1]>16777215)return-1;G=Y[0]<<24|Y[1]&16777215;break;case 3:if(Y[0]>255||Y[1]>255||Y[2]>65535)return-1;G=Y[0]<<24|Y[1]<<16|Y[2]&65535;break;case 4:if(Y.some((J)=>J>255))return-1;G=Y[0]<<24|Y[1]<<16|Y[2]<<8|Y[3];break;default:return-1}return G>>>0}});var R$=U1((uN0,T$)=>{T$.exports=function W(Y,G){if(Y===G)return!0;if(Y&&G&&typeof Y=="object"&&typeof G=="object"){if(Y.constructor!==G.constructor)return!1;var X,J,Z;if(Array.isArray(Y)){if(X=Y.length,X!=G.length)return!1;for(J=X;J--!==0;)if(!W(Y[J],G[J]))return!1;return!0}if(Y.constructor===RegExp)return Y.source===G.source&&Y.flags===G.flags;if(Y.valueOf!==Object.prototype.valueOf)return Y.valueOf()===G.valueOf();if(Y.toString!==Object.prototype.toString)return Y.toString()===G.toString();if(Z=Object.keys(Y),X=Z.length,X!==Object.keys(G).length)return!1;for(J=X;J--!==0;)if(!Object.prototype.hasOwnProperty.call(G,Z[J]))return!1;for(J=X;J--!==0;){var V=Z[J];if(!W(Y[V],G[V]))return!1}return!0}return Y!==Y&&G!==G}});var M$=U1((ml)=>{ml.toString=function(W){switch(W){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+W};ml.toType=function(W){switch(W.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}if(W.toUpperCase().startsWith("UNKNOWN_"))return parseInt(W.slice(8));return 0}});var P$=U1((pl)=>{pl.toString=function(W){switch(W){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+W};pl.toRcode=function(W){switch(W.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var L$=U1((ol)=>{ol.toString=function(W){switch(W){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+W};ol.toOpcode=function(W){switch(W.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var B$=U1((rl)=>{rl.toString=function(W){switch(W){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+W};rl.toClass=function(W){switch(W.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var E$=U1((tl)=>{tl.toString=function(W){switch(W){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}if(W<0)return null;return`OPTION_${W}`};tl.toCode=function(W){if(typeof W==="number")return W;if(!W)return-1;switch(W.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let Y=W.match(/_(\d+)$/);if(Y)return parseInt(Y[1],10);return-1}});var S$=U1((F$,aj)=>{var $$=function(W){Object.defineProperty(W,"__esModule",{value:!0}),W.decode=A,W.encode=N,W.familyOf=H,W.name=void 0,W.sizeOf=Q,W.v6=W.v4=void 0;let Y=/^(\d{1,3}\.){3,3}\d{1,3}$/,G=4,X=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,J=16,Z={name:"v4",size:G,isFormat:(q)=>Y.test(q),encode(q,z,w){w=~~w,z=z||new Uint8Array(w+G);let D=q.length,T=0;for(let x=0;x<D;){let g=q.charCodeAt(x++);if(g===46)z[w++]=T,T=0;else T=T*10+(g-48)}return z[w]=T,z},decode(q,z){return z=~~z,`${q[z++]}.${q[z++]}.${q[z++]}.${q[z]}`}};W.v4=Z;let V={name:"v6",size:J,isFormat:(q)=>q.length>0&&X.test(q),encode(q,z,w){w=~~w;let D=w+J,T=-1,x=0,g=0,f=!0,y=!1;z=z||new Uint8Array(w+J);for(let p=0;p<q.length;p++){let b=q.charCodeAt(p);if(b===58){if(f){if(T!==-1){if(w<D)z[w]=0;if(w<D-1)z[w+1]=0;w+=2}else if(w<D)T=w}else{if(y===!0){if(w<D)z[w]=g;w++}else{if(w<D)z[w]=x>>8;if(w<D-1)z[w+1]=x&255;w+=2}x=0,g=0}f=!0,y=!1}else if(b===46){if(w<D)z[w]=g;w++,g=0,x=0,f=!1,y=!0}else{if(f=!1,b>=97)b-=87;else if(b>=65)b-=55;else b-=48,g=g*10+b;x=(x<<4)+b}}if(f===!1)if(y===!0){if(w<D)z[w]=g;w++}else{if(w<D)z[w]=x>>8;if(w<D-1)z[w+1]=x&255;w+=2}else if(T===0){if(w<D)z[w]=0;if(w<D-1)z[w+1]=0;w+=2}else if(T!==-1){w+=2;for(let p=Math.min(w-1,D-1);p>=T+2;p--)z[p]=z[p-2];z[T]=0,z[T+1]=0,T=w}if(T!==w&&T!==-1){if(w>D-2)w=D-2;while(D>T)z[--D]=w<D&&w>T?z[--w]:0}else while(w<D)z[w++]=0;return z},decode(q,z){z=~~z;let w="";for(let D=0;D<J;D+=2){if(D!==0)w+=":";w+=(q[z+D]<<8|q[z+D+1]).toString(16)}return w.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};W.v6=V;let U="ip";W.name=U;function Q(q){if(Z.isFormat(q))return Z.size;if(V.isFormat(q))return V.size;throw Error(`Invalid ip address: ${q}`)}function H(q){return Q(q)===Z.size?1:2}function N(q,z,w){w=~~w;let D=Q(q);if(typeof z==="function")z=z(w+D);if(D===Z.size)return Z.encode(q,z,w);return V.encode(q,z,w)}function A(q,z,w){if(z=~~z,w=w||q.length-z,w===Z.size)return Z.decode(q,z,w);if(w===V.size)return V.decode(q,z,w);throw Error(`Invalid buffer size needs to be ${Z.size} for v4 or ${V.size} for v6.`)}return"default"in W?W.default:W}({});if(typeof define==="function"&&define.amd)define([],function(){return $$});else if(typeof aj==="object"&&typeof F$==="object")aj.exports=$$});var x$=U1((Zd)=>{var Z1=x8("buffer").Buffer,b4=M$(),Yd=P$(),Gd=L$(),EN=B$(),ej=E$(),wY=S$(),g0=Zd.name={};g0.encode=function(W,Y,G,{mail:X=!1}={}){if(!Y)Y=Z1.alloc(g0.encodingLength(W));if(!G)G=0;let J=G,Z=W.replace(/^\.|\.$/gm,"");if(Z.length){let V=[];if(X){let U="";Z.split(".").forEach((Q)=>{if(Q.endsWith("\\"))U+=(U.length?".":"")+Q.slice(0,-1);else if(V.length===0&&U.length)V.push(U+"."+Q);else V.push(Q)})}else V=Z.split(".");for(let U=0;U<V.length;U++){let Q=Y.write(V[U],G+1);Y[G]=Q,G+=Q+1}}return Y[G++]=0,g0.encode.bytes=G-J,Y};g0.encode.bytes=0;g0.decode=function(W,Y,{mail:G=!1}={}){if(!Y)Y=0;let X=[],J=Y,Z=0,V=0,U=!1;while(!0){if(Y>=W.length)throw Error("Cannot decode name (buffer overflow)");let Q=W[Y++];if(V+=U?0:1,Q===0)break;else if((Q&192)===0){if(Y+Q>W.length)throw Error("Cannot decode name (buffer overflow)");if(Z+=Q+1,Z>254)throw Error("Cannot decode name (name too long)");let H=W.toString("utf-8",Y,Y+Q);if(G)H=H.replace(/\./g,"\\.");X.push(H),Y+=Q,V+=U?0:Q}else if((Q&192)===192){if(Y+1>W.length)throw Error("Cannot decode name (buffer overflow)");let H=W.readUInt16BE(Y-1)-49152;if(H>=J)throw Error("Cannot decode name (bad pointer)");Y=H,J=H,V+=U?0:1,U=!0}else throw Error("Cannot decode name (bad label)")}return g0.decode.bytes=V,X.length===0?".":X.join(".")};g0.decode.bytes=0;g0.encodingLength=function(W){if(W==="."||W==="..")return 1;return Z1.byteLength(W.replace(/^\.|\.$/gm,""))+2};var S1={};S1.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(S1.encodingLength(W));if(!G)G=0;let X=Y.write(W,G+1);return Y[G]=X,S1.encode.bytes=X+1,Y};S1.encode.bytes=0;S1.decode=function(W,Y){if(!Y)Y=0;let G=W[Y],X=W.toString("utf-8",Y+1,Y+1+G);return S1.decode.bytes=G+1,X};S1.decode.bytes=0;S1.encodingLength=function(W){return Z1.byteLength(W)+1};var s5={};s5.encode=function(W,Y,G){if(!Y)Y=s5.encodingLength(W);if(!G)G=0;let X=(W.flags||0)&32767,J=W.type==="response"?32768:0;return Y.writeUInt16BE(W.id||0,G),Y.writeUInt16BE(X|J,G+2),Y.writeUInt16BE(W.questions.length,G+4),Y.writeUInt16BE(W.answers.length,G+6),Y.writeUInt16BE(W.authorities.length,G+8),Y.writeUInt16BE(W.additionals.length,G+10),Y};s5.encode.bytes=12;s5.decode=function(W,Y){if(!Y)Y=0;if(W.length<12)throw Error("Header must be 12 bytes");let G=W.readUInt16BE(Y+2);return{id:W.readUInt16BE(Y),type:G&32768?"response":"query",flags:G&32767,flag_qr:(G>>15&1)===1,opcode:Gd.toString(G>>11&15),flag_aa:(G>>10&1)===1,flag_tc:(G>>9&1)===1,flag_rd:(G>>8&1)===1,flag_ra:(G>>7&1)===1,flag_z:(G>>6&1)===1,flag_ad:(G>>5&1)===1,flag_cd:(G>>4&1)===1,rcode:Yd.toString(G&15),questions:Array(W.readUInt16BE(Y+4)),answers:Array(W.readUInt16BE(Y+6)),authorities:Array(W.readUInt16BE(Y+8)),additionals:Array(W.readUInt16BE(Y+10))}};s5.decode.bytes=12;s5.encodingLength=function(){return 12};var S4=Zd.unknown={};S4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(S4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(W.length,G),W.copy(Y,G+2),S4.encode.bytes=W.length+2,Y};S4.encode.bytes=0;S4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X=W.slice(Y+2,Y+2+G);return S4.decode.bytes=G+2,X};S4.decode.bytes=0;S4.encodingLength=function(W){return W.length+2};var x4=Zd.ns={};x4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(x4.encodingLength(W));if(!G)G=0;return g0.encode(W,Y,G+2),Y.writeUInt16BE(g0.encode.bytes,G),x4.encode.bytes=g0.encode.bytes+2,Y};x4.encode.bytes=0;x4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X=g0.decode(W,Y+2);return x4.decode.bytes=G+2,X};x4.decode.bytes=0;x4.encodingLength=function(W){return g0.encodingLength(W)+2};var k4=Zd.soa={};k4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(k4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.mname,Y,G),G+=g0.encode.bytes,g0.encode(W.rname,Y,G,{mail:!0}),G+=g0.encode.bytes,Y.writeUInt32BE(W.serial||0,G),G+=4,Y.writeUInt32BE(W.refresh||0,G),G+=4,Y.writeUInt32BE(W.retry||0,G),G+=4,Y.writeUInt32BE(W.expire||0,G),G+=4,Y.writeUInt32BE(W.minimum||0,G),G+=4,Y.writeUInt16BE(G-X-2,X),k4.encode.bytes=G-X,Y};k4.encode.bytes=0;k4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.mname=g0.decode(W,Y),Y+=g0.decode.bytes,X.rname=g0.decode(W,Y,{mail:!0}),Y+=g0.decode.bytes,X.serial=W.readUInt32BE(Y),Y+=4,X.refresh=W.readUInt32BE(Y),Y+=4,X.retry=W.readUInt32BE(Y),Y+=4,X.expire=W.readUInt32BE(Y),Y+=4,X.minimum=W.readUInt32BE(Y),Y+=4,k4.decode.bytes=Y-G,X};k4.decode.bytes=0;k4.encodingLength=function(W){return 22+g0.encodingLength(W.mname)+g0.encodingLength(W.rname)};var _4=Zd.txt={};_4.encode=function(W,Y,G){if(!Array.isArray(W))W=[W];for(let J=0;J<W.length;J++){if(typeof W[J]==="string")W[J]=Z1.from(W[J]);if(!Z1.isBuffer(W[J]))throw Error("Must be a Buffer")}if(!Y)Y=Z1.alloc(_4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,W.forEach(function(J){Y[G++]=J.length,J.copy(Y,G,0,J.length),G+=J.length}),Y.writeUInt16BE(G-X-2,X),_4.encode.bytes=G-X,Y};_4.encode.bytes=0;_4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=W.readUInt16BE(Y);Y+=2;let J=[];while(X>0){let Z=W[Y++];if(--X,X<Z)throw Error("Buffer overflow");J.push(W.slice(Y,Y+Z)),Y+=Z,X-=Z}return _4.decode.bytes=Y-G,J};_4.decode.bytes=0;_4.encodingLength=function(W){if(!Array.isArray(W))W=[W];let Y=2;return W.forEach(function(G){if(typeof G==="string")Y+=Z1.byteLength(G)+1;else Y+=G.length+1}),Y};var y4=Zd.null={};y4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(y4.encodingLength(W));if(!G)G=0;if(typeof W==="string")W=Z1.from(W);if(!W)W=Z1.alloc(0);let X=G;G+=2;let J=W.length;return W.copy(Y,G,0,J),G+=J,Y.writeUInt16BE(G-X-2,X),y4.encode.bytes=G-X,Y};y4.encode.bytes=0;y4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=W.readUInt16BE(Y);Y+=2;let J=W.slice(Y,Y+X);return Y+=X,y4.decode.bytes=Y-G,J};y4.decode.bytes=0;y4.encodingLength=function(W){if(!W)return 2;return(Z1.isBuffer(W)?W.length:Z1.byteLength(W))+2};var v4=Zd.hinfo={};v4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(v4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,S1.encode(W.cpu,Y,G),G+=S1.encode.bytes,S1.encode(W.os,Y,G),G+=S1.encode.bytes,Y.writeUInt16BE(G-X-2,X),v4.encode.bytes=G-X,Y};v4.encode.bytes=0;v4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.cpu=S1.decode(W,Y),Y+=S1.decode.bytes,X.os=S1.decode(W,Y),Y+=S1.decode.bytes,v4.decode.bytes=Y-G,X};v4.decode.bytes=0;v4.encodingLength=function(W){return S1.encodingLength(W.cpu)+S1.encodingLength(W.os)+2};var r5=Zd.ptr={},Xd=Zd.cname=r5,Jd=Zd.dname=r5;r5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(r5.encodingLength(W));if(!G)G=0;return g0.encode(W,Y,G+2),Y.writeUInt16BE(g0.encode.bytes,G),r5.encode.bytes=g0.encode.bytes+2,Y};r5.encode.bytes=0;r5.decode=function(W,Y){if(!Y)Y=0;let G=g0.decode(W,Y+2);return r5.decode.bytes=g0.decode.bytes+2,G};r5.decode.bytes=0;r5.encodingLength=function(W){return g0.encodingLength(W)+2};var g4=Zd.srv={};g4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g4.encodingLength(W));if(!G)G=0;Y.writeUInt16BE(W.priority||0,G+2),Y.writeUInt16BE(W.weight||0,G+4),Y.writeUInt16BE(W.port||0,G+6),g0.encode(W.target,Y,G+8);let X=g0.encode.bytes+6;return Y.writeUInt16BE(X,G),g4.encode.bytes=X+2,Y};g4.encode.bytes=0;g4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X={};return X.priority=W.readUInt16BE(Y+2),X.weight=W.readUInt16BE(Y+4),X.port=W.readUInt16BE(Y+6),X.target=g0.decode(W,Y+8),g4.decode.bytes=G+2,X};g4.decode.bytes=0;g4.encodingLength=function(W){return 8+g0.encodingLength(W.target)};var H5=Zd.caa={};H5.ISSUER_CRITICAL=128;H5.encode=function(W,Y,G){let X=H5.encodingLength(W);if(!Y)Y=Z1.alloc(H5.encodingLength(W));if(!G)G=0;if(W.issuerCritical)W.flags=H5.ISSUER_CRITICAL;return Y.writeUInt16BE(X-2,G),G+=2,Y.writeUInt8(W.flags||0,G),G+=1,S1.encode(W.tag,Y,G),G+=S1.encode.bytes,Y.write(W.value,G),G+=Z1.byteLength(W.value),H5.encode.bytes=X,Y};H5.encode.bytes=0;H5.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y);Y+=2;let X=Y,J={};return J.flags=W.readUInt8(Y),Y+=1,J.tag=S1.decode(W,Y),Y+=S1.decode.bytes,J.value=W.toString("utf-8",Y,X+G),J.issuerCritical=!!(J.flags&H5.ISSUER_CRITICAL),H5.decode.bytes=G+2,J};H5.decode.bytes=0;H5.encodingLength=function(W){return S1.encodingLength(W.tag)+S1.encodingLength(W.value)+2};var o6=Zd.mx={};o6.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(o6.encodingLength(W));if(!G)G=0;let X=G;return G+=2,Y.writeUInt16BE(W.preference||0,G),G+=2,g0.encode(W.exchange,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(G-X-2,X),o6.encode.bytes=G-X,Y};o6.encode.bytes=0;o6.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.preference=W.readUInt16BE(Y),Y+=2,X.exchange=g0.decode(W,Y),Y+=g0.decode.bytes,o6.decode.bytes=Y-G,X};o6.encodingLength=function(W){return 4+g0.encodingLength(W.exchange)};var u4=Zd.a={};u4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(u4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(4,G),G+=2,wY.v4.encode(W,Y,G),u4.encode.bytes=6,Y};u4.encode.bytes=0;u4.decode=function(W,Y){if(!Y)Y=0;Y+=2;let G=wY.v4.decode(W,Y);return u4.decode.bytes=6,G};u4.decode.bytes=0;u4.encodingLength=function(){return 6};var h4=Zd.aaaa={};h4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(h4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(16,G),G+=2,wY.v6.encode(W,Y,G),h4.encode.bytes=18,Y};h4.encode.bytes=0;h4.decode=function(W,Y){if(!Y)Y=0;Y+=2;let G=wY.v6.decode(W,Y);return h4.decode.bytes=18,G};h4.decode.bytes=0;h4.encodingLength=function(){return 18};var r9=Zd.option={};r9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(r9.encodingLength(W));if(!G)G=0;let X=G,J=ej.toCode(W.code);if(Y.writeUInt16BE(J,G),G+=2,W.data)Y.writeUInt16BE(W.data.length,G),G+=2,W.data.copy(Y,G),G+=W.data.length;else switch(J){case 8:let Z=W.sourcePrefixLength||0,V=W.family||wY.familyOf(W.ip),U=wY.encode(W.ip,Z1.alloc),Q=Math.ceil(Z/8);Y.writeUInt16BE(Q+4,G),G+=2,Y.writeUInt16BE(V,G),G+=2,Y.writeUInt8(Z,G++),Y.writeUInt8(W.scopePrefixLength||0,G++),U.copy(Y,G,0,Q),G+=Q;break;case 11:if(W.timeout)Y.writeUInt16BE(2,G),G+=2,Y.writeUInt16BE(W.timeout,G),G+=2;else Y.writeUInt16BE(0,G),G+=2;break;case 12:let H=W.length||0;Y.writeUInt16BE(H,G),G+=2,Y.fill(0,G,G+H),G+=H;break;case 14:let N=W.tags.length*2;Y.writeUInt16BE(N,G),G+=2;for(let A of W.tags)Y.writeUInt16BE(A,G),G+=2;break;default:throw Error(`Unknown roption code: ${W.code}`)}return r9.encode.bytes=G-X,Y};r9.encode.bytes=0;r9.decode=function(W,Y){if(!Y)Y=0;let G={};G.code=W.readUInt16BE(Y),G.type=ej.toString(G.code),Y+=2;let X=W.readUInt16BE(Y);switch(Y+=2,G.data=W.slice(Y,Y+X),G.code){case 8:G.family=W.readUInt16BE(Y),Y+=2,G.sourcePrefixLength=W.readUInt8(Y++),G.scopePrefixLength=W.readUInt8(Y++);let J=Z1.alloc(G.family===1?4:16);W.copy(J,0,Y,Y+X-4),G.ip=wY.decode(J);break;case 11:if(X>0)G.timeout=W.readUInt16BE(Y),Y+=2;break;case 14:G.tags=[];for(let Z=0;Z<X;Z+=2)G.tags.push(W.readUInt16BE(Y)),Y+=2}return r9.decode.bytes=X+4,G};r9.decode.bytes=0;r9.encodingLength=function(W){if(W.data)return W.data.length+4;switch(ej.toCode(W.code)){case 8:let G=W.sourcePrefixLength||0;return Math.ceil(G/8)+8;case 11:return typeof W.timeout==="number"?6:4;case 12:return W.length+4;case 14:return 4+W.tags.length*2}throw Error(`Unknown roption code: ${W.code}`)};var q5=Zd.opt={};q5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(q5.encodingLength(W));if(!G)G=0;let X=G,J=EX(W,r9);return Y.writeUInt16BE(J,G),G=SV(W,r9,Y,G+2),q5.encode.bytes=G-X,Y};q5.encode.bytes=0;q5.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=[],J=W.readUInt16BE(Y);Y+=2;let Z=0;while(J>0)X[Z++]=r9.decode(W,Y),Y+=r9.decode.bytes,J-=r9.decode.bytes;return q5.decode.bytes=Y-G,X};q5.decode.bytes=0;q5.encodingLength=function(W){return 2+EX(W||[],r9)};var g9=Zd.dnskey={};g9.PROTOCOL_DNSSEC=3;g9.ZONE_KEY=128;g9.SECURE_ENTRYPOINT=32768;g9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g9.encodingLength(W));if(!G)G=0;let X=G,J=W.key;if(!Z1.isBuffer(J))throw Error("Key must be a Buffer");return G+=2,Y.writeUInt16BE(W.flags,G),G+=2,Y.writeUInt8(g9.PROTOCOL_DNSSEC,G),G+=1,Y.writeUInt8(W.algorithm,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,g9.encode.bytes=G-X,Y.writeUInt16BE(g9.encode.bytes-2,X),Y};g9.encode.bytes=0;g9.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);if(Y+=2,X.flags=W.readUInt16BE(Y),Y+=2,W.readUInt8(Y)!==g9.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return Y+=1,X.algorithm=W.readUInt8(Y),Y+=1,X.key=W.slice(Y,G+J+2),Y+=X.key.length,g9.decode.bytes=Y-G,X};g9.decode.bytes=0;g9.encodingLength=function(W){return 6+Z1.byteLength(W.key)};var _7=Zd.rrsig={};_7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(_7.encodingLength(W));if(!G)G=0;let X=G,J=W.signature;if(!Z1.isBuffer(J))throw Error("Signature must be a Buffer");return G+=2,Y.writeUInt16BE(b4.toType(W.typeCovered),G),G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.labels,G),G+=1,Y.writeUInt32BE(W.originalTTL,G),G+=4,Y.writeUInt32BE(W.expiration,G),G+=4,Y.writeUInt32BE(W.inception,G),G+=4,Y.writeUInt16BE(W.keyTag,G),G+=2,g0.encode(W.signersName,Y,G),G+=g0.encode.bytes,J.copy(Y,G,0,J.length),G+=J.length,_7.encode.bytes=G-X,Y.writeUInt16BE(_7.encode.bytes-2,X),Y};_7.encode.bytes=0;_7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.typeCovered=b4.toString(W.readUInt16BE(Y)),Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.labels=W.readUInt8(Y),Y+=1,X.originalTTL=W.readUInt32BE(Y),Y+=4,X.expiration=W.readUInt32BE(Y),Y+=4,X.inception=W.readUInt32BE(Y),Y+=4,X.keyTag=W.readUInt16BE(Y),Y+=2,X.signersName=g0.decode(W,Y),Y+=g0.decode.bytes,X.signature=W.slice(Y,G+J+2),Y+=X.signature.length,_7.decode.bytes=Y-G,X};_7.decode.bytes=0;_7.encodingLength=function(W){return 20+g0.encodingLength(W.signersName)+Z1.byteLength(W.signature)};var y7=Zd.rp={};y7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(y7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.mbox||".",Y,G,{mail:!0}),G+=g0.encode.bytes,g0.encode(W.txt||".",Y,G),G+=g0.encode.bytes,y7.encode.bytes=G-X,Y.writeUInt16BE(y7.encode.bytes-2,X),Y};y7.encode.bytes=0;y7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.mbox=g0.decode(W,Y,{mail:!0})||".",Y+=g0.decode.bytes,X.txt=g0.decode(W,Y)||".",Y+=g0.decode.bytes,y7.decode.bytes=Y-G,X};y7.decode.bytes=0;y7.encodingLength=function(W){return 2+g0.encodingLength(W.mbox||".")+g0.encodingLength(W.txt||".")};var i8={};i8.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(i8.encodingLength(W));if(!G)G=0;let X=G;var J=[];for(var Z=0;Z<W.length;Z++){var V=b4.toType(W[Z]);if(J[V>>8]===void 0)J[V>>8]=[];J[V>>8][V>>3&31]|=1<<7-(V&7)}for(Z=0;Z<J.length;Z++)if(J[Z]!==void 0){var U=Z1.from(J[Z]);Y.writeUInt8(Z,G),G+=1,Y.writeUInt8(U.length,G),G+=1,U.copy(Y,G),G+=U.length}return i8.encode.bytes=G-X,Y};i8.encode.bytes=0;i8.decode=function(W,Y,G){if(!Y)Y=0;let X=Y;var J=[];while(Y-X<G){var Z=W.readUInt8(Y);Y+=1;var V=W.readUInt8(Y);Y+=1;for(var U=0;U<V;U++){var Q=W.readUInt8(Y+U);for(var H=0;H<8;H++)if(Q&1<<7-H){var N=b4.toString(Z<<8|U<<3|H);J.push(N)}}Y+=V}return i8.decode.bytes=Y-X,J};i8.decode.bytes=0;i8.encodingLength=function(W){var Y=[];for(var G=0;G<W.length;G++){var X=b4.toType(W[G]);Y[X>>8]=Math.max(Y[X>>8]||0,X&255)}var J=0;for(G=0;G<Y.length;G++)if(Y[G]!==void 0)J+=2+Math.ceil((Y[G]+1)/8);return J};var v7=Zd.nsec={};v7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(v7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.nextDomain,Y,G),G+=g0.encode.bytes,i8.encode(W.rrtypes,Y,G),G+=i8.encode.bytes,v7.encode.bytes=G-X,Y.writeUInt16BE(v7.encode.bytes-2,X),Y};v7.encode.bytes=0;v7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.nextDomain=g0.decode(W,Y),Y+=g0.decode.bytes,X.rrtypes=i8.decode(W,Y,J-(Y-G)),Y+=i8.decode.bytes,v7.decode.bytes=Y-G,X};v7.decode.bytes=0;v7.encodingLength=function(W){return 2+g0.encodingLength(W.nextDomain)+i8.encodingLength(W.rrtypes)};var g7=Zd.nsec3={};g7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g7.encodingLength(W));if(!G)G=0;let X=G,J=W.salt;if(!Z1.isBuffer(J))throw Error("salt must be a Buffer");let Z=W.nextDomain;if(!Z1.isBuffer(Z))throw Error("nextDomain must be a Buffer");return G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.flags,G),G+=1,Y.writeUInt16BE(W.iterations,G),G+=2,Y.writeUInt8(J.length,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,Y.writeUInt8(Z.length,G),G+=1,Z.copy(Y,G,0,Z.length),G+=Z.length,i8.encode(W.rrtypes,Y,G),G+=i8.encode.bytes,g7.encode.bytes=G-X,Y.writeUInt16BE(g7.encode.bytes-2,X),Y};g7.encode.bytes=0;g7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.flags=W.readUInt8(Y),Y+=1,X.iterations=W.readUInt16BE(Y),Y+=2;let Z=W.readUInt8(Y);Y+=1,X.salt=W.slice(Y,Y+Z),Y+=Z;let V=W.readUInt8(Y);return Y+=1,X.nextDomain=W.slice(Y,Y+V),Y+=V,X.rrtypes=i8.decode(W,Y,J-(Y-G)),Y+=i8.decode.bytes,g7.decode.bytes=Y-G,X};g7.decode.bytes=0;g7.encodingLength=function(W){return 8+W.salt.length+W.nextDomain.length+i8.encodingLength(W.rrtypes)};var u7=Zd.ds={};u7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(u7.encodingLength(W));if(!G)G=0;let X=G,J=W.digest;if(!Z1.isBuffer(J))throw Error("Digest must be a Buffer");return G+=2,Y.writeUInt16BE(W.keyTag,G),G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.digestType,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,u7.encode.bytes=G-X,Y.writeUInt16BE(u7.encode.bytes-2,X),Y};u7.encode.bytes=0;u7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.keyTag=W.readUInt16BE(Y),Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.digestType=W.readUInt8(Y),Y+=1,X.digest=W.slice(Y,G+J+2),Y+=X.digest.length,u7.decode.bytes=Y-G,X};u7.decode.bytes=0;u7.encodingLength=function(W){return 6+Z1.byteLength(W.digest)};var N5=Zd.sshfp={};N5.getFingerprintLengthForHashType=function(Y){switch(Y){case 1:return 20;case 2:return 32}};N5.encode=function(Y,G,X){if(!G)G=Z1.alloc(N5.encodingLength(Y));if(!X)X=0;let J=X;X+=2,G[X]=Y.algorithm,X+=1,G[X]=Y.hash,X+=1;let Z=Z1.from(Y.fingerprint.toUpperCase(),"hex");if(Z.length!==N5.getFingerprintLengthForHashType(Y.hash))throw Error("Invalid fingerprint length");return Z.copy(G,X),X+=Z.byteLength,N5.encode.bytes=X-J,G.writeUInt16BE(N5.encode.bytes-2,J),G};N5.encode.bytes=0;N5.decode=function(Y,G){if(!G)G=0;let X=G,J={};G+=2,J.algorithm=Y[G],G+=1,J.hash=Y[G],G+=1;let Z=N5.getFingerprintLengthForHashType(J.hash);return J.fingerprint=Y.slice(G,G+Z).toString("hex").toUpperCase(),G+=Z,N5.decode.bytes=G-X,J};N5.decode.bytes=0;N5.encodingLength=function(W){return 4+Z1.from(W.fingerprint,"hex").byteLength};var h7=Zd.naptr={};h7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(h7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,Y.writeUInt16BE(W.order||0,G),G+=2,Y.writeUInt16BE(W.preference||0,G),G+=2,S1.encode(W.flags,Y,G),G+=S1.encode.bytes,S1.encode(W.services,Y,G),G+=S1.encode.bytes,S1.encode(W.regexp,Y,G),G+=S1.encode.bytes,g0.encode(W.replacement,Y,G),G+=g0.encode.bytes,h7.encode.bytes=G-X,Y.writeUInt16BE(h7.encode.bytes-2,X),Y};h7.encode.bytes=0;h7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.order=W.readUInt16BE(Y),Y+=2,X.preference=W.readUInt16BE(Y),Y+=2,X.flags=S1.decode(W,Y),Y+=S1.decode.bytes,X.services=S1.decode(W,Y),Y+=S1.decode.bytes,X.regexp=S1.decode(W,Y),Y+=S1.decode.bytes,X.replacement=g0.decode(W,Y),Y+=g0.decode.bytes,h7.decode.bytes=Y-G,X};h7.decode.bytes=0;h7.encodingLength=function(W){return S1.encodingLength(W.flags)+S1.encodingLength(W.services)+S1.encodingLength(W.regexp)+g0.encodingLength(W.replacement)+6};var b7=Zd.tlsa={};b7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(b7.encodingLength(W));if(!G)G=0;let X=G,J=W.certificate;if(!Z1.isBuffer(J))throw Error("Certificate must be a Buffer");return G+=2,Y.writeUInt8(W.usage,G),G+=1,Y.writeUInt8(W.selector,G),G+=1,Y.writeUInt8(W.matchingType,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,b7.encode.bytes=G-X,Y.writeUInt16BE(b7.encode.bytes-2,X),Y};b7.encode.bytes=0;b7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={},J=W.readUInt16BE(Y);return Y+=2,X.usage=W.readUInt8(Y),Y+=1,X.selector=W.readUInt8(Y),Y+=1,X.matchingType=W.readUInt8(Y),Y+=1,X.certificate=W.slice(Y,G+J+2),Y+=X.certificate.length,b7.decode.bytes=Y-G,X};b7.decode.bytes=0;b7.encodingLength=function(W){return 5+Z1.byteLength(W.certificate)};var WO=Zd.record=function(W){switch(W.toUpperCase()){case"A":return u4;case"PTR":return r5;case"CNAME":return Xd;case"DNAME":return Jd;case"TXT":return _4;case"NULL":return y4;case"AAAA":return h4;case"SRV":return g4;case"HINFO":return v4;case"CAA":return H5;case"NS":return x4;case"SOA":return k4;case"MX":return o6;case"OPT":return q5;case"DNSKEY":return g9;case"RRSIG":return _7;case"RP":return y7;case"NSEC":return v7;case"NSEC3":return g7;case"SSHFP":return N5;case"DS":return u7;case"NAPTR":return h7;case"TLSA":return b7}return S4},J9=Zd.answer={};J9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(J9.encodingLength(W));if(!G)G=0;let X=G;if(g0.encode(W.name,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(b4.toType(W.type),G),W.type.toUpperCase()==="OPT"){if(W.name!==".")throw Error("OPT name must be root.");Y.writeUInt16BE(W.udpPayloadSize||4096,G+2),Y.writeUInt8(W.extendedRcode||0,G+4),Y.writeUInt8(W.ednsVersion||0,G+5),Y.writeUInt16BE(W.flags||0,G+6),G+=8,q5.encode(W.options||[],Y,G),G+=q5.encode.bytes}else{let J=EN.toClass(W.class===void 0?"IN":W.class);if(W.flush)J|=32768;Y.writeUInt16BE(J,G+2),Y.writeUInt32BE(W.ttl||0,G+4),G+=8;let Z=WO(W.type);Z.encode(W.data,Y,G),G+=Z.encode.bytes}return J9.encode.bytes=G-X,Y};J9.encode.bytes=0;J9.decode=function(W,Y){if(!Y)Y=0;let G={},X=Y;if(G.name=g0.decode(W,Y),Y+=g0.decode.bytes,G.type=b4.toString(W.readUInt16BE(Y)),G.type==="OPT")G.udpPayloadSize=W.readUInt16BE(Y+2),G.extendedRcode=W.readUInt8(Y+4),G.ednsVersion=W.readUInt8(Y+5),G.flags=W.readUInt16BE(Y+6),G.flag_do=(G.flags>>15&1)===1,G.options=q5.decode(W,Y+8),Y+=8+q5.decode.bytes;else{let J=W.readUInt16BE(Y+2);G.ttl=W.readUInt32BE(Y+4),G.class=EN.toString(J&-32769),G.flush=!!(J&32768);let Z=WO(G.type);G.data=Z.decode(W,Y+8),Y+=8+Z.decode.bytes}return J9.decode.bytes=Y-X,G};J9.decode.bytes=0;J9.encodingLength=function(W){let Y=W.data!==null&&W.data!==void 0?W.data:W.options;return g0.encodingLength(W.name)+8+WO(W.type).encodingLength(Y)};var a5=Zd.question={};a5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(a5.encodingLength(W));if(!G)G=0;let X=G;return g0.encode(W.name,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(b4.toType(W.type),G),G+=2,Y.writeUInt16BE(EN.toClass(W.class===void 0?"IN":W.class),G),G+=2,a5.encode.bytes=G-X,W};a5.encode.bytes=0;a5.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};if(X.name=g0.decode(W,Y),Y+=g0.decode.bytes,X.type=b4.toString(W.readUInt16BE(Y)),Y+=2,X.class=EN.toString(W.readUInt16BE(Y)),Y+=2,!!(X.class&32768))X.class&=-32769;return a5.decode.bytes=Y-G,X};a5.decode.bytes=0;a5.encodingLength=function(W){return g0.encodingLength(W.name)+4};Zd.AUTHORITATIVE_ANSWER=1024;Zd.TRUNCATED_RESPONSE=512;Zd.RECURSION_DESIRED=256;Zd.RECURSION_AVAILABLE=128;Zd.AUTHENTIC_DATA=32;Zd.CHECKING_DISABLED=16;Zd.DNSSEC_OK=32768;Zd.encode=function(W,Y,G){let X=!Y;if(X)Y=Z1.alloc(Zd.encodingLength(W));if(!G)G=0;let J=G;if(!W.questions)W.questions=[];if(!W.answers)W.answers=[];if(!W.authorities)W.authorities=[];if(!W.additionals)W.additionals=[];if(s5.encode(W,Y,G),G+=s5.encode.bytes,G=SV(W.questions,a5,Y,G),G=SV(W.answers,J9,Y,G),G=SV(W.authorities,J9,Y,G),G=SV(W.additionals,J9,Y,G),Zd.encode.bytes=G-J,X&&Zd.encode.bytes!==Y.length)return Y.slice(0,Zd.encode.bytes);return Y};Zd.encode.bytes=0;Zd.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=s5.decode(W,Y);return Y+=s5.decode.bytes,Y=BN(X.questions,a5,W,Y),Y=BN(X.answers,J9,W,Y),Y=BN(X.authorities,J9,W,Y),Y=BN(X.additionals,J9,W,Y),Zd.decode.bytes=Y-G,X};Zd.decode.bytes=0;Zd.encodingLength=function(W){return s5.encodingLength(W)+EX(W.questions||[],a5)+EX(W.answers||[],J9)+EX(W.authorities||[],J9)+EX(W.additionals||[],J9)};Zd.streamEncode=function(W){let Y=Zd.encode(W),G=Z1.alloc(2);G.writeUInt16BE(Y.byteLength);let X=Z1.concat([G,Y]);return Zd.streamEncode.bytes=X.byteLength,X};Zd.streamEncode.bytes=0;Zd.streamDecode=function(W){let Y=W.readUInt16BE(0);if(W.byteLength<Y+2)return null;let G=Zd.decode(W.slice(2));return Zd.streamDecode.bytes=Zd.decode.bytes,G};Zd.streamDecode.bytes=0;function EX(W,Y){let G=0;for(let X=0;X<W.length;X++)G+=Y.encodingLength(W[X]);return G}function SV(W,Y,G,X){for(let J=0;J<W.length;J++)Y.encode(W[J],G,X),X+=Y.encode.bytes;return X}function BN(W,Y,G,X){for(let J=0;J<W.length;J++)W[J]=Y.decode(G,X),X+=Y.decode.bytes;return X}});var y$=U1((Dq0,_$)=>{var k$=Dd;process.nextTick(Kd,42);_$.exports=zd;function zd(W){var Y=X;return G;function G(J){Y(J||jd)}function X(J){var Z=[J];Y=V,W(U);function V(Q){Z.push(Q)}function U(Q){var H=arguments;Y=wd(Q)?X:N;while(Z.length)N(Z.shift());function N(A){k$(Od,A,H)}}}}function wd(W){return Object.prototype.toString.call(W)==="[object Error]"}function jd(){}function Od(W,Y){W.apply(null,Y)}function Kd(W){if(W===42)k$=process.nextTick}function Dd(W,Y,G){process.nextTick(function(){W(Y,G)})}});var u$=U1((Cq0,g$)=>{var YO=x$(),Cd=x8("dgram"),Td=y$(),Rd=x8("events"),XO=x8("os"),GO=function(){};g$.exports=function(W){if(!W)W={};var Y=new Rd.EventEmitter,G=typeof W.port==="number"?W.port:5353,X=W.type||"udp4",J=W.ip||W.host||(X==="udp4"?"224.0.0.251":null),Z={address:J,port:G},V={},U=!1,Q=null;if(X==="udp6"&&(!J||!W.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var H=W.socket||Cd.createSocket({type:X,reuseAddr:W.reuseAddr!==!1,toString:function(){return X}});H.on("error",function(A){if(A.code==="EACCES"||A.code==="EADDRINUSE")Y.emit("error",A);else Y.emit("warning",A)}),H.on("message",function(A,q){try{A=YO.decode(A)}catch(z){Y.emit("warning",z);return}if(Y.emit("packet",A,q),A.type==="query")Y.emit("query",A,q);if(A.type==="response")Y.emit("response",A,q)}),H.on("listening",function(){if(!G)G=Z.port=H.address().port;if(W.multicast!==!1)Y.update(),Q=setInterval(Y.update,5000),H.setMulticastTTL(W.ttl||255),H.setMulticastLoopback(W.loopback!==!1)});var N=Td(function(A){if(!G||W.bind===!1)return A(null);H.once("error",A),H.bind(G,W.bind||W.interface,function(){H.removeListener("error",A),A(null)})});return N(function(A){if(A)return Y.emit("error",A);Y.emit("ready")}),Y.send=function(A,q,z){if(typeof q==="function")return Y.send(A,null,q);if(!z)z=GO;if(!q)q=Z;else if(!q.host&&!q.address)q.address=Z.address;N(w);function w(D){if(U)return z();if(D)return z(D);var T=YO.encode(A);H.send(T,0,T.length,q.port,q.address||q.host,z)}},Y.response=Y.respond=function(A,q,z){if(Array.isArray(A))A={answers:A};A.type="response",A.flags=(A.flags||0)|YO.AUTHORITATIVE_ANSWER,Y.send(A,q,z)},Y.query=function(A,q,z,w){if(typeof q==="function")return Y.query(A,null,null,q);if(typeof q==="object"&&q&&q.port)return Y.query(A,null,q,z);if(typeof z==="function")return Y.query(A,q,null,z);if(!w)w=GO;if(typeof A==="string")A=[{name:A,type:q||"ANY"}];if(Array.isArray(A))A={type:"query",questions:A};A.type="query",Y.send(A,z,w)},Y.destroy=function(A){if(!A)A=GO;if(U)return process.nextTick(A);U=!0,clearInterval(Q);for(var q in V)try{H.dropMembership(J,q)}catch(z){}V={},H.close(A)},Y.update=function(){var A=W.interface?[].concat(W.interface):Pd(),q=!1;for(var z=0;z<A.length;z++){var w=A[z];if(V[w])continue;try{H.addMembership(J,w),V[w]=!0,q=!0}catch(D){Y.emit("warning",D)}}if(q){if(H.setMulticastInterface)try{H.setMulticastInterface(W.interface||Md())}catch(D){Y.emit("warning",D)}Y.emit("networkInterface")}},Y};function Md(){var W=XO.networkInterfaces(),Y=Object.keys(W);for(var G=0;G<Y.length;G++){var X=W[Y[G]];for(var J=0;J<X.length;J++){var Z=X[J];if(v$(Z.family)&&!Z.internal){if(XO.platform()==="darwin"&&Y[G]==="en0")return Z.address;return"0.0.0.0"}}}return"127.0.0.1"}function Pd(){var W=XO.networkInterfaces(),Y=Object.keys(W),G=[];for(var X=0;X<Y.length;X++){var J=W[Y[X]];for(var Z=0;Z<J.length;Z++){var V=J[Z];if(v$(V.family)){G.push(V.address);break}}}return G}function v$(W){return W===4||W==="IPv4"}});import{Database as jt}from"bun:sqlite";import{mkdirSync as Ot}from"fs";import{dirname as Kt}from"path";function QD(W){let Y=W.length,G=0,X=0;while(X<Y){let J=W.charCodeAt(X++);if((J&4294967168)===0){G++;continue}else if((J&4294965248)===0)G+=2;else{if(J>=55296&&J<=56319){if(X<Y){let Z=W.charCodeAt(X);if((Z&64512)===56320)++X,J=((J&1023)<<10)+(Z&1023)+65536}}if((J&4294901760)===0)G+=3;else G+=4}}return G}function u_(W,Y,G){let X=W.length,J=G,Z=0;while(Z<X){let V=W.charCodeAt(Z++);if((V&4294967168)===0){Y[J++]=V;continue}else if((V&4294965248)===0)Y[J++]=V>>6&31|192;else{if(V>=55296&&V<=56319){if(Z<X){let U=W.charCodeAt(Z);if((U&64512)===56320)++Z,V=((V&1023)<<10)+(U&1023)+65536}}if((V&4294901760)===0)Y[J++]=V>>12&15|224,Y[J++]=V>>6&63|128;else Y[J++]=V>>18&7|240,Y[J++]=V>>12&63|128,Y[J++]=V>>6&63|128}Y[J++]=V&63|128}}var h_=new TextEncoder,b_=50;function m_(W,Y,G){h_.encodeInto(W,Y.subarray(G))}function HD(W,Y,G){if(W.length>b_)m_(W,Y,G);else u_(W,Y,G)}var f_=4096;function qA(W,Y,G){let X=Y,J=X+G,Z=[],V="";while(X<J){let U=W[X++];if((U&128)===0)Z.push(U);else if((U&224)===192){let Q=W[X++]&63;Z.push((U&31)<<6|Q)}else if((U&240)===224){let Q=W[X++]&63,H=W[X++]&63;Z.push((U&31)<<12|Q<<6|H)}else if((U&248)===240){let Q=W[X++]&63,H=W[X++]&63,N=W[X++]&63,A=(U&7)<<18|Q<<12|H<<6|N;if(A>65535)A-=65536,Z.push(A>>>10&1023|55296),A=56320|A&1023;Z.push(A)}else Z.push(U);if(Z.length>=f_)V+=String.fromCharCode(...Z),Z.length=0}if(Z.length>0)V+=String.fromCharCode(...Z);return V}var c_=new TextDecoder,p_=200;function l_(W,Y,G){let X=W.subarray(Y,Y+G);return c_.decode(X)}function ND(W,Y,G){if(G>p_)return l_(W,Y,G);else return qA(W,Y,G)}class pY{type;data;constructor(W,Y){this.type=W,this.data=Y}}class S9 extends Error{constructor(W){super(W);let Y=Object.create(S9.prototype);Object.setPrototypeOf(this,Y),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:S9.name})}}var lY=4294967295;function qD(W,Y,G){let X=G/4294967296,J=G;W.setUint32(Y,X),W.setUint32(Y+4,J)}function yU(W,Y,G){let X=Math.floor(G/4294967296),J=G;W.setUint32(Y,X),W.setUint32(Y+4,J)}function vU(W,Y){let G=W.getInt32(Y),X=W.getUint32(Y+4);return G*4294967296+X}function AD(W,Y){let G=W.getUint32(Y),X=W.getUint32(Y+4);return G*4294967296+X}var d_=-1,o_=4294967295,n_=17179869183;function i_({sec:W,nsec:Y}){if(W>=0&&Y>=0&&W<=n_)if(Y===0&&W<=o_){let G=new Uint8Array(4);return new DataView(G.buffer).setUint32(0,W),G}else{let G=W/4294967296,X=W&4294967295,J=new Uint8Array(8),Z=new DataView(J.buffer);return Z.setUint32(0,Y<<2|G&3),Z.setUint32(4,X),J}else{let G=new Uint8Array(12),X=new DataView(G.buffer);return X.setUint32(0,Y),yU(X,4,W),G}}function r_(W){let Y=W.getTime(),G=Math.floor(Y/1000),X=(Y-G*1000)*1e6,J=Math.floor(X/1e9);return{sec:G+J,nsec:X-J*1e9}}function a_(W){if(W instanceof Date){let Y=r_(W);return i_(Y)}else return null}function s_(W){let Y=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let G=Y.getUint32(0),X=0;return{sec:G,nsec:0}}case 8:{let G=Y.getUint32(0),X=Y.getUint32(4),J=(G&3)*4294967296+X,Z=G>>>2;return{sec:J,nsec:Z}}case 12:{let G=vU(Y,4),X=Y.getUint32(0);return{sec:G,nsec:X}}default:throw new S9(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function t_(W){let Y=s_(W);return new Date(Y.sec*1000+Y.nsec/1e6)}var ID={type:d_,encode:a_,decode:t_};class dY{static defaultCodec=new dY;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(ID)}register({type:W,encode:Y,decode:G}){if(W>=0)this.encoders[W]=Y,this.decoders[W]=G;else{let X=-1-W;this.builtInEncoders[X]=Y,this.builtInDecoders[X]=G}}tryToEncode(W,Y){for(let G=0;G<this.builtInEncoders.length;G++){let X=this.builtInEncoders[G];if(X!=null){let J=X(W,Y);if(J!=null){let Z=-1-G;return new pY(Z,J)}}}for(let G=0;G<this.encoders.length;G++){let X=this.encoders[G];if(X!=null){let J=X(W,Y);if(J!=null)return new pY(G,J)}}if(W instanceof pY)return W;return null}decode(W,Y,G){let X=Y<0?this.builtInDecoders[-1-Y]:this.decoders[Y];if(X)return X(W,Y,G);else return new pY(Y,W)}}function e_(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function UJ(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(e_(W))return new Uint8Array(W);else return Uint8Array.from(W)}var Wy=100,Yy=2048;class gU{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??dY.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??Wy,this.initialBufferSize=W?.initialBufferSize??Yy,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new gU({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,Y){if(Y>this.maxDepth)throw Error(`Too deep objects in depth ${Y}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,Y)}ensureBufferSizeToWrite(W){let Y=this.pos+W;if(this.view.byteLength<Y)this.resizeBuffer(Y*2)}resizeBuffer(W){let Y=new ArrayBuffer(W),G=new Uint8Array(Y),X=new DataView(Y);G.set(this.bytes),this.view=X,this.bytes=G}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let G=QD(W);this.ensureBufferSizeToWrite(5+G),this.writeStringHeader(G),HD(W,this.bytes,this.pos),this.pos+=G}encodeObject(W,Y){let G=this.extensionCodec.tryToEncode(W,this.context);if(G!=null)this.encodeExtension(G);else if(Array.isArray(W))this.encodeArray(W,Y);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,Y);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let Y=W.byteLength;if(Y<256)this.writeU8(196),this.writeU8(Y);else if(Y<65536)this.writeU8(197),this.writeU16(Y);else if(Y<4294967296)this.writeU8(198),this.writeU32(Y);else throw Error(`Too large binary: ${Y}`);let G=UJ(W);this.writeU8a(G)}encodeArray(W,Y){let G=W.length;if(G<16)this.writeU8(144+G);else if(G<65536)this.writeU8(220),this.writeU16(G);else if(G<4294967296)this.writeU8(221),this.writeU32(G);else throw Error(`Too large array: ${G}`);for(let X of W)this.doEncode(X,Y+1)}countWithoutUndefined(W,Y){let G=0;for(let X of Y)if(W[X]!==void 0)G++;return G}encodeMap(W,Y){let G=Object.keys(W);if(this.sortKeys)G.sort();let X=this.ignoreUndefined?this.countWithoutUndefined(W,G):G.length;if(X<16)this.writeU8(128+X);else if(X<65536)this.writeU8(222),this.writeU16(X);else if(X<4294967296)this.writeU8(223),this.writeU32(X);else throw Error(`Too large map object: ${X}`);for(let J of G){let Z=W[J];if(!(this.ignoreUndefined&&Z===void 0))this.encodeString(J),this.doEncode(Z,Y+1)}}encodeExtension(W){if(typeof W.data==="function"){let G=W.data(this.pos+6),X=G.length;if(X>=4294967296)throw Error(`Too large extension object: ${X}`);this.writeU8(201),this.writeU32(X),this.writeI8(W.type),this.writeU8a(G);return}let Y=W.data.length;if(Y===1)this.writeU8(212);else if(Y===2)this.writeU8(213);else if(Y===4)this.writeU8(214);else if(Y===8)this.writeU8(215);else if(Y===16)this.writeU8(216);else if(Y<256)this.writeU8(199),this.writeU8(Y);else if(Y<65536)this.writeU8(200),this.writeU16(Y);else if(Y<4294967296)this.writeU8(201),this.writeU32(Y);else throw Error(`Too large extension object: ${Y}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let Y=W.length;this.ensureBufferSizeToWrite(Y),this.bytes.set(W,this.pos),this.pos+=Y}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),qD(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),yU(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}function uU(W,Y){return new gU(Y).encodeSharedRef(W)}function hU(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}var Gy=16,Xy=16;class AA{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Gy,Y=Xy){this.maxKeyLength=W,this.maxLengthPerKey=Y,this.caches=[];for(let G=0;G<this.maxKeyLength;G++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,Y,G){let X=this.caches[G-1];W:for(let J of X){let Z=J.bytes;for(let V=0;V<G;V++)if(Z[V]!==W[Y+V])continue W;return J.str}return null}store(W,Y){let G=this.caches[W.length-1],X={bytes:W,str:Y};if(G.length>=this.maxLengthPerKey)G[Math.random()*G.length|0]=X;else G.push(X)}decode(W,Y,G){let X=this.find(W,Y,G);if(X!=null)return this.hit++,X;this.miss++;let J=qA(W,Y,G),Z=Uint8Array.prototype.slice.call(W,Y,Y+G);return this.store(Z,J),J}}var IA="array",HJ="map_key",wD="map_value",Jy=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new S9("The type of key must be string or number but "+typeof W)};class jD{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let Y=this.getUninitializedStateFromPool();Y.type=IA,Y.position=0,Y.size=W,Y.array=Array(W)}pushMapState(W){let Y=this.getUninitializedStateFromPool();Y.type=HJ,Y.readCount=0,Y.size=W,Y.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===IA){let G=W;G.size=0,G.array=void 0,G.position=0,G.type=void 0}if(W.type===HJ||W.type===wD){let G=W;G.size=0,G.map=void 0,G.readCount=0,G.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var QJ=-1,zA=new DataView(new ArrayBuffer(0)),Zy=new Uint8Array(zA.buffer);try{zA.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var zD=RangeError("Insufficient data"),Vy=new AA;class bU{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=zA;bytes=Zy;headByte=QJ;stack=new jD;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??dY.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??lY,this.maxBinLength=W?.maxBinLength??lY,this.maxArrayLength=W?.maxArrayLength??lY,this.maxMapLength=W?.maxMapLength??lY,this.maxExtLength=W?.maxExtLength??lY,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:Vy,this.mapKeyConverter=W?.mapKeyConverter??Jy}clone(){return new bU({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=QJ,this.stack.reset()}setBuffer(W){let Y=UJ(W);this.bytes=Y,this.view=new DataView(Y.buffer,Y.byteOffset,Y.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===QJ&&!this.hasRemaining(1))this.setBuffer(W);else{let Y=this.bytes.subarray(this.pos),G=UJ(W),X=new Uint8Array(Y.length+G.length);X.set(Y),X.set(G,Y.length),this.setBuffer(X)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:Y,pos:G}=this;return RangeError(`Extra ${Y.byteLength-G} of ${Y.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let Y=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Y}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let Y=!1,G;for await(let V of W){if(Y)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(V);try{G=this.doDecodeSync(),Y=!0}catch(U){if(!(U instanceof RangeError))throw U}this.totalPos+=this.pos}if(Y){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return G}let{headByte:X,pos:J,totalPos:Z}=this;throw RangeError(`Insufficient data in parsing ${hU(X)} at ${Z} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,Y){if(this.entered){yield*this.clone().decodeMultiAsync(W,Y);return}try{this.entered=!0;let G=Y,X=-1;for await(let J of W){if(Y&&X===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),G)X=this.readArraySize(),G=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--X===0)break}catch(Z){if(!(Z instanceof RangeError))throw Z}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),Y;if(W>=224)Y=W-256;else if(W<192)if(W<128)Y=W;else if(W<144){let X=W-128;if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W<160){let X=W-144;if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else{let X=W-160;Y=this.decodeString(X,0)}else if(W===192)Y=null;else if(W===194)Y=!1;else if(W===195)Y=!0;else if(W===202)Y=this.readF32();else if(W===203)Y=this.readF64();else if(W===204)Y=this.readU8();else if(W===205)Y=this.readU16();else if(W===206)Y=this.readU32();else if(W===207)if(this.useBigInt64)Y=this.readU64AsBigInt();else Y=this.readU64();else if(W===208)Y=this.readI8();else if(W===209)Y=this.readI16();else if(W===210)Y=this.readI32();else if(W===211)if(this.useBigInt64)Y=this.readI64AsBigInt();else Y=this.readI64();else if(W===217){let X=this.lookU8();Y=this.decodeString(X,1)}else if(W===218){let X=this.lookU16();Y=this.decodeString(X,2)}else if(W===219){let X=this.lookU32();Y=this.decodeString(X,4)}else if(W===220){let X=this.readU16();if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else if(W===221){let X=this.readU32();if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else if(W===222){let X=this.readU16();if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W===223){let X=this.readU32();if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W===196){let X=this.lookU8();Y=this.decodeBinary(X,1)}else if(W===197){let X=this.lookU16();Y=this.decodeBinary(X,2)}else if(W===198){let X=this.lookU32();Y=this.decodeBinary(X,4)}else if(W===212)Y=this.decodeExtension(1,0);else if(W===213)Y=this.decodeExtension(2,0);else if(W===214)Y=this.decodeExtension(4,0);else if(W===215)Y=this.decodeExtension(8,0);else if(W===216)Y=this.decodeExtension(16,0);else if(W===199){let X=this.lookU8();Y=this.decodeExtension(X,1)}else if(W===200){let X=this.lookU16();Y=this.decodeExtension(X,2)}else if(W===201){let X=this.lookU32();Y=this.decodeExtension(X,4)}else throw new S9(`Unrecognized type byte: ${hU(W)}`);this.complete();let G=this.stack;while(G.length>0){let X=G.top();if(X.type===IA)if(X.array[X.position]=Y,X.position++,X.position===X.size)Y=X.array,G.release(X);else continue W;else if(X.type===HJ){if(Y==="__proto__")throw new S9("The key __proto__ is not allowed");X.key=this.mapKeyConverter(Y),X.type=wD;continue W}else if(X.map[X.key]=Y,X.readCount++,X.readCount===X.size)Y=X.map,G.release(X);else{X.key=null,X.type=HJ;continue W}}return Y}}readHeadByte(){if(this.headByte===QJ)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=QJ}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new S9(`Unrecognized array type byte: ${hU(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new S9(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new S9(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,Y){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,Y);return this.decodeBinary(W,Y)}decodeUtf8String(W,Y){if(W>this.maxStrLength)throw new S9(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Y+W)throw zD;let G=this.pos+Y,X;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))X=this.keyDecoder.decode(this.bytes,G,W);else X=ND(this.bytes,G,W);return this.pos+=Y+W,X}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===HJ;return!1}decodeBinary(W,Y){if(W>this.maxBinLength)throw new S9(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+Y))throw zD;let G=this.pos+Y,X=this.bytes.subarray(G,G+W);return this.pos+=Y+W,X}decodeExtension(W,Y){if(W>this.maxExtLength)throw new S9(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let G=this.view.getInt8(this.pos+Y),X=this.decodeBinary(W,Y+1);return this.extensionCodec.decode(X,G,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=AD(this.view,this.pos);return this.pos+=8,W}readI64(){let W=vU(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}function qW(W,Y){return new bU(Y).decode(W)}/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function sY(W){let Y=W.length;while(--Y>=0)W[Y]=0}var Uy=0,YC=1,Qy=2,Hy=3,Ny=258,hA=29,PJ=256,jJ=PJ+1+hA,iY=30,bA=19,GC=2*jJ+1,AW=15,wA=16,qy=7,mA=256,XC=16,JC=17,ZC=18,FA=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),dU=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Ay=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),VC=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Iy=512,t7=Array((jJ+2)*2);sY(t7);var IJ=Array(iY*2);sY(IJ);var OJ=Array(Iy);sY(OJ);var KJ=Array(Ny-Hy+1);sY(KJ);var fA=Array(hA);sY(fA);var oU=Array(iY);sY(oU);function jA(W,Y,G,X,J){this.static_tree=W,this.extra_bits=Y,this.extra_base=G,this.elems=X,this.max_length=J,this.has_stree=W&&W.length}var UC,QC,HC;function OA(W,Y){this.dyn_tree=W,this.max_code=0,this.stat_desc=Y}var NC=(W)=>{return W<256?OJ[W]:OJ[256+(W>>>7)]},DJ=(W,Y)=>{W.pending_buf[W.pending++]=Y&255,W.pending_buf[W.pending++]=Y>>>8&255},h9=(W,Y,G)=>{if(W.bi_valid>wA-G)W.bi_buf|=Y<<W.bi_valid&65535,DJ(W,W.bi_buf),W.bi_buf=Y>>wA-W.bi_valid,W.bi_valid+=G-wA;else W.bi_buf|=Y<<W.bi_valid&65535,W.bi_valid+=G},N7=(W,Y,G)=>{h9(W,G[Y*2],G[Y*2+1])},qC=(W,Y)=>{let G=0;do G|=W&1,W>>>=1,G<<=1;while(--Y>0);return G>>>1},zy=(W)=>{if(W.bi_valid===16)DJ(W,W.bi_buf),W.bi_buf=0,W.bi_valid=0;else if(W.bi_valid>=8)W.pending_buf[W.pending++]=W.bi_buf&255,W.bi_buf>>=8,W.bi_valid-=8},wy=(W,Y)=>{let{dyn_tree:G,max_code:X}=Y,J=Y.stat_desc.static_tree,Z=Y.stat_desc.has_stree,V=Y.stat_desc.extra_bits,U=Y.stat_desc.extra_base,Q=Y.stat_desc.max_length,H,N,A,q,z,w,D=0;for(q=0;q<=AW;q++)W.bl_count[q]=0;G[W.heap[W.heap_max]*2+1]=0;for(H=W.heap_max+1;H<GC;H++){if(N=W.heap[H],q=G[G[N*2+1]*2+1]+1,q>Q)q=Q,D++;if(G[N*2+1]=q,N>X)continue;if(W.bl_count[q]++,z=0,N>=U)z=V[N-U];if(w=G[N*2],W.opt_len+=w*(q+z),Z)W.static_len+=w*(J[N*2+1]+z)}if(D===0)return;do{q=Q-1;while(W.bl_count[q]===0)q--;W.bl_count[q]--,W.bl_count[q+1]+=2,W.bl_count[Q]--,D-=2}while(D>0);for(q=Q;q!==0;q--){N=W.bl_count[q];while(N!==0){if(A=W.heap[--H],A>X)continue;if(G[A*2+1]!==q)W.opt_len+=(q-G[A*2+1])*G[A*2],G[A*2+1]=q;N--}}},AC=(W,Y,G)=>{let X=Array(AW+1),J=0,Z,V;for(Z=1;Z<=AW;Z++)J=J+G[Z-1]<<1,X[Z]=J;for(V=0;V<=Y;V++){let U=W[V*2+1];if(U===0)continue;W[V*2]=qC(X[U]++,U)}},jy=()=>{let W,Y,G,X,J,Z=Array(AW+1);G=0;for(X=0;X<hA-1;X++){fA[X]=G;for(W=0;W<1<<FA[X];W++)KJ[G++]=X}KJ[G-1]=X,J=0;for(X=0;X<16;X++){oU[X]=J;for(W=0;W<1<<dU[X];W++)OJ[J++]=X}J>>=7;for(;X<iY;X++){oU[X]=J<<7;for(W=0;W<1<<dU[X]-7;W++)OJ[256+J++]=X}for(Y=0;Y<=AW;Y++)Z[Y]=0;W=0;while(W<=143)t7[W*2+1]=8,W++,Z[8]++;while(W<=255)t7[W*2+1]=9,W++,Z[9]++;while(W<=279)t7[W*2+1]=7,W++,Z[7]++;while(W<=287)t7[W*2+1]=8,W++,Z[8]++;AC(t7,jJ+1,Z);for(W=0;W<iY;W++)IJ[W*2+1]=5,IJ[W*2]=qC(W,5);UC=new jA(t7,FA,PJ+1,jJ,AW),QC=new jA(IJ,dU,0,iY,AW),HC=new jA([],Ay,0,bA,qy)},IC=(W)=>{let Y;for(Y=0;Y<jJ;Y++)W.dyn_ltree[Y*2]=0;for(Y=0;Y<iY;Y++)W.dyn_dtree[Y*2]=0;for(Y=0;Y<bA;Y++)W.bl_tree[Y*2]=0;W.dyn_ltree[mA*2]=1,W.opt_len=W.static_len=0,W.sym_next=W.matches=0},zC=(W)=>{if(W.bi_valid>8)DJ(W,W.bi_buf);else if(W.bi_valid>0)W.pending_buf[W.pending++]=W.bi_buf;W.bi_buf=0,W.bi_valid=0},OD=(W,Y,G,X)=>{let J=Y*2,Z=G*2;return W[J]<W[Z]||W[J]===W[Z]&&X[Y]<=X[G]},KA=(W,Y,G)=>{let X=W.heap[G],J=G<<1;while(J<=W.heap_len){if(J<W.heap_len&&OD(Y,W.heap[J+1],W.heap[J],W.depth))J++;if(OD(Y,X,W.heap[J],W.depth))break;W.heap[G]=W.heap[J],G=J,J<<=1}W.heap[G]=X},KD=(W,Y,G)=>{let X,J,Z=0,V,U;if(W.sym_next!==0)do if(X=W.pending_buf[W.sym_buf+Z++]&255,X+=(W.pending_buf[W.sym_buf+Z++]&255)<<8,J=W.pending_buf[W.sym_buf+Z++],X===0)N7(W,J,Y);else{if(V=KJ[J],N7(W,V+PJ+1,Y),U=FA[V],U!==0)J-=fA[V],h9(W,J,U);if(X--,V=NC(X),N7(W,V,G),U=dU[V],U!==0)X-=oU[V],h9(W,X,U)}while(Z<W.sym_next);N7(W,mA,Y)},SA=(W,Y)=>{let G=Y.dyn_tree,X=Y.stat_desc.static_tree,J=Y.stat_desc.has_stree,Z=Y.stat_desc.elems,V,U,Q=-1,H;W.heap_len=0,W.heap_max=GC;for(V=0;V<Z;V++)if(G[V*2]!==0)W.heap[++W.heap_len]=Q=V,W.depth[V]=0;else G[V*2+1]=0;while(W.heap_len<2)if(H=W.heap[++W.heap_len]=Q<2?++Q:0,G[H*2]=1,W.depth[H]=0,W.opt_len--,J)W.static_len-=X[H*2+1];Y.max_code=Q;for(V=W.heap_len>>1;V>=1;V--)KA(W,G,V);H=Z;do V=W.heap[1],W.heap[1]=W.heap[W.heap_len--],KA(W,G,1),U=W.heap[1],W.heap[--W.heap_max]=V,W.heap[--W.heap_max]=U,G[H*2]=G[V*2]+G[U*2],W.depth[H]=(W.depth[V]>=W.depth[U]?W.depth[V]:W.depth[U])+1,G[V*2+1]=G[U*2+1]=H,W.heap[1]=H++,KA(W,G,1);while(W.heap_len>=2);W.heap[--W.heap_max]=W.heap[1],wy(W,Y),AC(G,Q,W.bl_count)},DD=(W,Y,G)=>{let X,J=-1,Z,V=Y[1],U=0,Q=7,H=4;if(V===0)Q=138,H=3;Y[(G+1)*2+1]=65535;for(X=0;X<=G;X++){if(Z=V,V=Y[(X+1)*2+1],++U<Q&&Z===V)continue;else if(U<H)W.bl_tree[Z*2]+=U;else if(Z!==0){if(Z!==J)W.bl_tree[Z*2]++;W.bl_tree[XC*2]++}else if(U<=10)W.bl_tree[JC*2]++;else W.bl_tree[ZC*2]++;if(U=0,J=Z,V===0)Q=138,H=3;else if(Z===V)Q=6,H=3;else Q=7,H=4}},CD=(W,Y,G)=>{let X,J=-1,Z,V=Y[1],U=0,Q=7,H=4;if(V===0)Q=138,H=3;for(X=0;X<=G;X++){if(Z=V,V=Y[(X+1)*2+1],++U<Q&&Z===V)continue;else if(U<H)do N7(W,Z,W.bl_tree);while(--U!==0);else if(Z!==0){if(Z!==J)N7(W,Z,W.bl_tree),U--;N7(W,XC,W.bl_tree),h9(W,U-3,2)}else if(U<=10)N7(W,JC,W.bl_tree),h9(W,U-3,3);else N7(W,ZC,W.bl_tree),h9(W,U-11,7);if(U=0,J=Z,V===0)Q=138,H=3;else if(Z===V)Q=6,H=3;else Q=7,H=4}},Oy=(W)=>{let Y;DD(W,W.dyn_ltree,W.l_desc.max_code),DD(W,W.dyn_dtree,W.d_desc.max_code),SA(W,W.bl_desc);for(Y=bA-1;Y>=3;Y--)if(W.bl_tree[VC[Y]*2+1]!==0)break;return W.opt_len+=3*(Y+1)+5+5+4,Y},Ky=(W,Y,G,X)=>{let J;h9(W,Y-257,5),h9(W,G-1,5),h9(W,X-4,4);for(J=0;J<X;J++)h9(W,W.bl_tree[VC[J]*2+1],3);CD(W,W.dyn_ltree,Y-1),CD(W,W.dyn_dtree,G-1)},Dy=(W)=>{let Y=4093624447,G;for(G=0;G<=31;G++,Y>>>=1)if(Y&1&&W.dyn_ltree[G*2]!==0)return 0;if(W.dyn_ltree[18]!==0||W.dyn_ltree[20]!==0||W.dyn_ltree[26]!==0)return 1;for(G=32;G<PJ;G++)if(W.dyn_ltree[G*2]!==0)return 1;return 0},TD=!1,Cy=(W)=>{if(!TD)jy(),TD=!0;W.l_desc=new OA(W.dyn_ltree,UC),W.d_desc=new OA(W.dyn_dtree,QC),W.bl_desc=new OA(W.bl_tree,HC),W.bi_buf=0,W.bi_valid=0,IC(W)},wC=(W,Y,G,X)=>{if(h9(W,(Uy<<1)+(X?1:0),3),zC(W),DJ(W,G),DJ(W,~G),G)W.pending_buf.set(W.window.subarray(Y,Y+G),W.pending);W.pending+=G},Ty=(W)=>{h9(W,YC<<1,3),N7(W,mA,t7),zy(W)},Ry=(W,Y,G,X)=>{let J,Z,V=0;if(W.level>0){if(W.strm.data_type===2)W.strm.data_type=Dy(W);if(SA(W,W.l_desc),SA(W,W.d_desc),V=Oy(W),J=W.opt_len+3+7>>>3,Z=W.static_len+3+7>>>3,Z<=J)J=Z}else J=Z=G+5;if(G+4<=J&&Y!==-1)wC(W,Y,G,X);else if(W.strategy===4||Z===J)h9(W,(YC<<1)+(X?1:0),3),KD(W,t7,IJ);else h9(W,(Qy<<1)+(X?1:0),3),Ky(W,W.l_desc.max_code+1,W.d_desc.max_code+1,V+1),KD(W,W.dyn_ltree,W.dyn_dtree);if(IC(W),X)zC(W)},My=(W,Y,G)=>{if(W.pending_buf[W.sym_buf+W.sym_next++]=Y,W.pending_buf[W.sym_buf+W.sym_next++]=Y>>8,W.pending_buf[W.sym_buf+W.sym_next++]=G,Y===0)W.dyn_ltree[G*2]++;else W.matches++,Y--,W.dyn_ltree[(KJ[G]+PJ+1)*2]++,W.dyn_dtree[NC(Y)*2]++;return W.sym_next===W.sym_end},Py=Cy,Ly=wC,By=Ry,Ey=My,$y=Ty,Fy={_tr_init:Py,_tr_stored_block:Ly,_tr_flush_block:By,_tr_tally:Ey,_tr_align:$y},Sy=(W,Y,G,X)=>{let J=W&65535|0,Z=W>>>16&65535|0,V=0;while(G!==0){V=G>2000?2000:G,G-=V;do J=J+Y[X++]|0,Z=Z+J|0;while(--V);J%=65521,Z%=65521}return J|Z<<16|0},CJ=Sy,xy=()=>{let W,Y=[];for(var G=0;G<256;G++){W=G;for(var X=0;X<8;X++)W=W&1?3988292384^W>>>1:W>>>1;Y[G]=W}return Y},ky=new Uint32Array(xy()),_y=(W,Y,G,X)=>{let J=ky,Z=X+G;W^=-1;for(let V=X;V<Z;V++)W=W>>>8^J[(W^Y[V])&255];return W^-1},n8=_y,wW={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},KW={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:yy,_tr_stored_block:xA,_tr_flush_block:vy,_tr_tally:V6,_tr_align:gy}=Fy,{Z_NO_FLUSH:U6,Z_PARTIAL_FLUSH:uy,Z_FULL_FLUSH:hy,Z_FINISH:w5,Z_BLOCK:RD,Z_OK:t8,Z_STREAM_END:MD,Z_STREAM_ERROR:q7,Z_DATA_ERROR:by,Z_BUF_ERROR:DA,Z_DEFAULT_COMPRESSION:my,Z_FILTERED:fy,Z_HUFFMAN_ONLY:mU,Z_RLE:cy,Z_FIXED:py,Z_DEFAULT_STRATEGY:ly,Z_UNKNOWN:dy,Z_DEFLATED:rU}=KW,oy=9,ny=15,iy=8,ry=29,ay=256,kA=ay+1+ry,sy=30,ty=19,ey=2*kA+1,Wv=15,v1=3,Z6=258,A7=Z6+v1+1,Yv=32,rY=42,cA=57,_A=69,yA=73,vA=91,gA=103,IW=113,qJ=666,x9=1,tY=2,jW=3,eY=4,Gv=3,zW=(W,Y)=>{return W.msg=wW[Y],Y},PD=(W)=>{return W*2-(W>4?9:0)},J6=(W)=>{let Y=W.length;while(--Y>=0)W[Y]=0},Xv=(W)=>{let Y,G,X,J=W.w_size;Y=W.hash_size,X=Y;do G=W.head[--X],W.head[X]=G>=J?G-J:0;while(--Y);Y=J,X=Y;do G=W.prev[--X],W.prev[X]=G>=J?G-J:0;while(--Y)},Jv=(W,Y,G)=>(Y<<W.hash_shift^G)&W.hash_mask,Q6=Jv,W5=(W)=>{let Y=W.state,G=Y.pending;if(G>W.avail_out)G=W.avail_out;if(G===0)return;if(W.output.set(Y.pending_buf.subarray(Y.pending_out,Y.pending_out+G),W.next_out),W.next_out+=G,Y.pending_out+=G,W.total_out+=G,W.avail_out-=G,Y.pending-=G,Y.pending===0)Y.pending_out=0},Y5=(W,Y)=>{vy(W,W.block_start>=0?W.block_start:-1,W.strstart-W.block_start,Y),W.block_start=W.strstart,W5(W.strm)},r1=(W,Y)=>{W.pending_buf[W.pending++]=Y},NJ=(W,Y)=>{W.pending_buf[W.pending++]=Y>>>8&255,W.pending_buf[W.pending++]=Y&255},uA=(W,Y,G,X)=>{let J=W.avail_in;if(J>X)J=X;if(J===0)return 0;if(W.avail_in-=J,Y.set(W.input.subarray(W.next_in,W.next_in+J),G),W.state.wrap===1)W.adler=CJ(W.adler,Y,J,G);else if(W.state.wrap===2)W.adler=n8(W.adler,Y,J,G);return W.next_in+=J,W.total_in+=J,J},jC=(W,Y)=>{let{max_chain_length:G,strstart:X}=W,J,Z,V=W.prev_length,U=W.nice_match,Q=W.strstart>W.w_size-A7?W.strstart-(W.w_size-A7):0,H=W.window,N=W.w_mask,A=W.prev,q=W.strstart+Z6,z=H[X+V-1],w=H[X+V];if(W.prev_length>=W.good_match)G>>=2;if(U>W.lookahead)U=W.lookahead;do{if(J=Y,H[J+V]!==w||H[J+V-1]!==z||H[J]!==H[X]||H[++J]!==H[X+1])continue;X+=2,J++;do;while(H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&X<q);if(Z=Z6-(q-X),X=q-Z6,Z>V){if(W.match_start=Y,V=Z,Z>=U)break;z=H[X+V-1],w=H[X+V]}}while((Y=A[Y&N])>Q&&--G!==0);if(V<=W.lookahead)return V;return W.lookahead},aY=(W)=>{let Y=W.w_size,G,X,J;do{if(X=W.window_size-W.lookahead-W.strstart,W.strstart>=Y+(Y-A7)){if(W.window.set(W.window.subarray(Y,Y+Y-X),0),W.match_start-=Y,W.strstart-=Y,W.block_start-=Y,W.insert>W.strstart)W.insert=W.strstart;Xv(W),X+=Y}if(W.strm.avail_in===0)break;if(G=uA(W.strm,W.window,W.strstart+W.lookahead,X),W.lookahead+=G,W.lookahead+W.insert>=v1){J=W.strstart-W.insert,W.ins_h=W.window[J],W.ins_h=Q6(W,W.ins_h,W.window[J+1]);while(W.insert)if(W.ins_h=Q6(W,W.ins_h,W.window[J+v1-1]),W.prev[J&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=J,J++,W.insert--,W.lookahead+W.insert<v1)break}}while(W.lookahead<A7&&W.strm.avail_in!==0)},OC=(W,Y)=>{let G=W.pending_buf_size-5>W.w_size?W.w_size:W.pending_buf_size-5,X,J,Z,V=0,U=W.strm.avail_in;do{if(X=65535,Z=W.bi_valid+42>>3,W.strm.avail_out<Z)break;if(Z=W.strm.avail_out-Z,J=W.strstart-W.block_start,X>J+W.strm.avail_in)X=J+W.strm.avail_in;if(X>Z)X=Z;if(X<G&&(X===0&&Y!==w5||Y===U6||X!==J+W.strm.avail_in))break;if(V=Y===w5&&X===J+W.strm.avail_in?1:0,xA(W,0,0,V),W.pending_buf[W.pending-4]=X,W.pending_buf[W.pending-3]=X>>8,W.pending_buf[W.pending-2]=~X,W.pending_buf[W.pending-1]=~X>>8,W5(W.strm),J){if(J>X)J=X;W.strm.output.set(W.window.subarray(W.block_start,W.block_start+J),W.strm.next_out),W.strm.next_out+=J,W.strm.avail_out-=J,W.strm.total_out+=J,W.block_start+=J,X-=J}if(X)uA(W.strm,W.strm.output,W.strm.next_out,X),W.strm.next_out+=X,W.strm.avail_out-=X,W.strm.total_out+=X}while(V===0);if(U-=W.strm.avail_in,U){if(U>=W.w_size)W.matches=2,W.window.set(W.strm.input.subarray(W.strm.next_in-W.w_size,W.strm.next_in),0),W.strstart=W.w_size,W.insert=W.strstart;else{if(W.window_size-W.strstart<=U){if(W.strstart-=W.w_size,W.window.set(W.window.subarray(W.w_size,W.w_size+W.strstart),0),W.matches<2)W.matches++;if(W.insert>W.strstart)W.insert=W.strstart}W.window.set(W.strm.input.subarray(W.strm.next_in-U,W.strm.next_in),W.strstart),W.strstart+=U,W.insert+=U>W.w_size-W.insert?W.w_size-W.insert:U}W.block_start=W.strstart}if(W.high_water<W.strstart)W.high_water=W.strstart;if(V)return eY;if(Y!==U6&&Y!==w5&&W.strm.avail_in===0&&W.strstart===W.block_start)return tY;if(Z=W.window_size-W.strstart,W.strm.avail_in>Z&&W.block_start>=W.w_size){if(W.block_start-=W.w_size,W.strstart-=W.w_size,W.window.set(W.window.subarray(W.w_size,W.w_size+W.strstart),0),W.matches<2)W.matches++;if(Z+=W.w_size,W.insert>W.strstart)W.insert=W.strstart}if(Z>W.strm.avail_in)Z=W.strm.avail_in;if(Z)uA(W.strm,W.window,W.strstart,Z),W.strstart+=Z,W.insert+=Z>W.w_size-W.insert?W.w_size-W.insert:Z;if(W.high_water<W.strstart)W.high_water=W.strstart;if(Z=W.bi_valid+42>>3,Z=W.pending_buf_size-Z>65535?65535:W.pending_buf_size-Z,G=Z>W.w_size?W.w_size:Z,J=W.strstart-W.block_start,J>=G||(J||Y===w5)&&Y!==U6&&W.strm.avail_in===0&&J<=Z)X=J>Z?Z:J,V=Y===w5&&W.strm.avail_in===0&&X===J?1:0,xA(W,W.block_start,X,V),W.block_start+=X,W5(W.strm);return V?jW:x9},CA=(W,Y)=>{let G,X;for(;;){if(W.lookahead<A7){if(aY(W),W.lookahead<A7&&Y===U6)return x9;if(W.lookahead===0)break}if(G=0,W.lookahead>=v1)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+v1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;if(G!==0&&W.strstart-G<=W.w_size-A7)W.match_length=jC(W,G);if(W.match_length>=v1)if(X=V6(W,W.strstart-W.match_start,W.match_length-v1),W.lookahead-=W.match_length,W.match_length<=W.max_lazy_match&&W.lookahead>=v1){W.match_length--;do W.strstart++,W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+v1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;while(--W.match_length!==0);W.strstart++}else W.strstart+=W.match_length,W.match_length=0,W.ins_h=W.window[W.strstart],W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+1]);else X=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(X){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=W.strstart<v1-1?W.strstart:v1-1,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},oY=(W,Y)=>{let G,X,J;for(;;){if(W.lookahead<A7){if(aY(W),W.lookahead<A7&&Y===U6)return x9;if(W.lookahead===0)break}if(G=0,W.lookahead>=v1)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+v1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;if(W.prev_length=W.match_length,W.prev_match=W.match_start,W.match_length=v1-1,G!==0&&W.prev_length<W.max_lazy_match&&W.strstart-G<=W.w_size-A7){if(W.match_length=jC(W,G),W.match_length<=5&&(W.strategy===fy||W.match_length===v1&&W.strstart-W.match_start>4096))W.match_length=v1-1}if(W.prev_length>=v1&&W.match_length<=W.prev_length){J=W.strstart+W.lookahead-v1,X=V6(W,W.strstart-1-W.prev_match,W.prev_length-v1),W.lookahead-=W.prev_length-1,W.prev_length-=2;do if(++W.strstart<=J)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+v1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;while(--W.prev_length!==0);if(W.match_available=0,W.match_length=v1-1,W.strstart++,X){if(Y5(W,!1),W.strm.avail_out===0)return x9}}else if(W.match_available){if(X=V6(W,0,W.window[W.strstart-1]),X)Y5(W,!1);if(W.strstart++,W.lookahead--,W.strm.avail_out===0)return x9}else W.match_available=1,W.strstart++,W.lookahead--}if(W.match_available)X=V6(W,0,W.window[W.strstart-1]),W.match_available=0;if(W.insert=W.strstart<v1-1?W.strstart:v1-1,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},Zv=(W,Y)=>{let G,X,J,Z,V=W.window;for(;;){if(W.lookahead<=Z6){if(aY(W),W.lookahead<=Z6&&Y===U6)return x9;if(W.lookahead===0)break}if(W.match_length=0,W.lookahead>=v1&&W.strstart>0){if(J=W.strstart-1,X=V[J],X===V[++J]&&X===V[++J]&&X===V[++J]){Z=W.strstart+Z6;do;while(X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&J<Z);if(W.match_length=Z6-(Z-J),W.match_length>W.lookahead)W.match_length=W.lookahead}}if(W.match_length>=v1)G=V6(W,1,W.match_length-v1),W.lookahead-=W.match_length,W.strstart+=W.match_length,W.match_length=0;else G=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(G){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=0,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},Vv=(W,Y)=>{let G;for(;;){if(W.lookahead===0){if(aY(W),W.lookahead===0){if(Y===U6)return x9;break}}if(W.match_length=0,G=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++,G){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=0,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY};function H7(W,Y,G,X,J){this.good_length=W,this.max_lazy=Y,this.nice_length=G,this.max_chain=X,this.func=J}var AJ=[new H7(0,0,0,0,OC),new H7(4,4,8,4,CA),new H7(4,5,16,8,CA),new H7(4,6,32,32,CA),new H7(4,4,16,16,oY),new H7(8,16,32,32,oY),new H7(8,16,128,128,oY),new H7(8,32,128,256,oY),new H7(32,128,258,1024,oY),new H7(32,258,258,4096,oY)],Uv=(W)=>{W.window_size=2*W.w_size,J6(W.head),W.max_lazy_match=AJ[W.level].max_lazy,W.good_match=AJ[W.level].good_length,W.nice_match=AJ[W.level].nice_length,W.max_chain_length=AJ[W.level].max_chain,W.strstart=0,W.block_start=0,W.lookahead=0,W.insert=0,W.match_length=W.prev_length=v1-1,W.match_available=0,W.ins_h=0};function Qv(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=rU,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(ey*2),this.dyn_dtree=new Uint16Array((2*sy+1)*2),this.bl_tree=new Uint16Array((2*ty+1)*2),J6(this.dyn_ltree),J6(this.dyn_dtree),J6(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(Wv+1),this.heap=new Uint16Array(2*kA+1),J6(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*kA+1),J6(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var LJ=(W)=>{if(!W)return 1;let Y=W.state;if(!Y||Y.strm!==W||Y.status!==rY&&Y.status!==cA&&Y.status!==_A&&Y.status!==yA&&Y.status!==vA&&Y.status!==gA&&Y.status!==IW&&Y.status!==qJ)return 1;return 0},KC=(W)=>{if(LJ(W))return zW(W,q7);W.total_in=W.total_out=0,W.data_type=dy;let Y=W.state;if(Y.pending=0,Y.pending_out=0,Y.wrap<0)Y.wrap=-Y.wrap;return Y.status=Y.wrap===2?cA:Y.wrap?rY:IW,W.adler=Y.wrap===2?0:1,Y.last_flush=-2,yy(Y),t8},DC=(W)=>{let Y=KC(W);if(Y===t8)Uv(W.state);return Y},Hv=(W,Y)=>{if(LJ(W)||W.state.wrap!==2)return q7;return W.state.gzhead=Y,t8},CC=(W,Y,G,X,J,Z)=>{if(!W)return q7;let V=1;if(Y===my)Y=6;if(X<0)V=0,X=-X;else if(X>15)V=2,X-=16;if(J<1||J>oy||G!==rU||X<8||X>15||Y<0||Y>9||Z<0||Z>py||X===8&&V!==1)return zW(W,q7);if(X===8)X=9;let U=new Qv;return W.state=U,U.strm=W,U.status=rY,U.wrap=V,U.gzhead=null,U.w_bits=X,U.w_size=1<<U.w_bits,U.w_mask=U.w_size-1,U.hash_bits=J+7,U.hash_size=1<<U.hash_bits,U.hash_mask=U.hash_size-1,U.hash_shift=~~((U.hash_bits+v1-1)/v1),U.window=new Uint8Array(U.w_size*2),U.head=new Uint16Array(U.hash_size),U.prev=new Uint16Array(U.w_size),U.lit_bufsize=1<<J+6,U.pending_buf_size=U.lit_bufsize*4,U.pending_buf=new Uint8Array(U.pending_buf_size),U.sym_buf=U.lit_bufsize,U.sym_end=(U.lit_bufsize-1)*3,U.level=Y,U.strategy=Z,U.method=G,DC(W)},Nv=(W,Y)=>{return CC(W,Y,rU,ny,iy,ly)},qv=(W,Y)=>{if(LJ(W)||Y>RD||Y<0)return W?zW(W,q7):q7;let G=W.state;if(!W.output||W.avail_in!==0&&!W.input||G.status===qJ&&Y!==w5)return zW(W,W.avail_out===0?DA:q7);let X=G.last_flush;if(G.last_flush=Y,G.pending!==0){if(W5(W),W.avail_out===0)return G.last_flush=-1,t8}else if(W.avail_in===0&&PD(Y)<=PD(X)&&Y!==w5)return zW(W,DA);if(G.status===qJ&&W.avail_in!==0)return zW(W,DA);if(G.status===rY&&G.wrap===0)G.status=IW;if(G.status===rY){let J=rU+(G.w_bits-8<<4)<<8,Z=-1;if(G.strategy>=mU||G.level<2)Z=0;else if(G.level<6)Z=1;else if(G.level===6)Z=2;else Z=3;if(J|=Z<<6,G.strstart!==0)J|=Yv;if(J+=31-J%31,NJ(G,J),G.strstart!==0)NJ(G,W.adler>>>16),NJ(G,W.adler&65535);if(W.adler=1,G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}if(G.status===cA)if(W.adler=0,r1(G,31),r1(G,139),r1(G,8),!G.gzhead){if(r1(G,0),r1(G,0),r1(G,0),r1(G,0),r1(G,0),r1(G,G.level===9?2:G.strategy>=mU||G.level<2?4:0),r1(G,Gv),G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}else{if(r1(G,(G.gzhead.text?1:0)+(G.gzhead.hcrc?2:0)+(!G.gzhead.extra?0:4)+(!G.gzhead.name?0:8)+(!G.gzhead.comment?0:16)),r1(G,G.gzhead.time&255),r1(G,G.gzhead.time>>8&255),r1(G,G.gzhead.time>>16&255),r1(G,G.gzhead.time>>24&255),r1(G,G.level===9?2:G.strategy>=mU||G.level<2?4:0),r1(G,G.gzhead.os&255),G.gzhead.extra&&G.gzhead.extra.length)r1(G,G.gzhead.extra.length&255),r1(G,G.gzhead.extra.length>>8&255);if(G.gzhead.hcrc)W.adler=n8(W.adler,G.pending_buf,G.pending,0);G.gzindex=0,G.status=_A}if(G.status===_A){if(G.gzhead.extra){let J=G.pending,Z=(G.gzhead.extra.length&65535)-G.gzindex;while(G.pending+Z>G.pending_buf_size){let U=G.pending_buf_size-G.pending;if(G.pending_buf.set(G.gzhead.extra.subarray(G.gzindex,G.gzindex+U),G.pending),G.pending=G.pending_buf_size,G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(G.gzindex+=U,W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0,Z-=U}let V=new Uint8Array(G.gzhead.extra);if(G.pending_buf.set(V.subarray(G.gzindex,G.gzindex+Z),G.pending),G.pending+=Z,G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=yA}if(G.status===yA){if(G.gzhead.name){let J=G.pending,Z;do{if(G.pending===G.pending_buf_size){if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0}if(G.gzindex<G.gzhead.name.length)Z=G.gzhead.name.charCodeAt(G.gzindex++)&255;else Z=0;r1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=vA}if(G.status===vA){if(G.gzhead.comment){let J=G.pending,Z;do{if(G.pending===G.pending_buf_size){if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0}if(G.gzindex<G.gzhead.comment.length)Z=G.gzhead.comment.charCodeAt(G.gzindex++)&255;else Z=0;r1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J)}G.status=gA}if(G.status===gA){if(G.gzhead.hcrc){if(G.pending+2>G.pending_buf_size){if(W5(W),G.pending!==0)return G.last_flush=-1,t8}r1(G,W.adler&255),r1(G,W.adler>>8&255),W.adler=0}if(G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}if(W.avail_in!==0||G.lookahead!==0||Y!==U6&&G.status!==qJ){let J=G.level===0?OC(G,Y):G.strategy===mU?Vv(G,Y):G.strategy===cy?Zv(G,Y):AJ[G.level].func(G,Y);if(J===jW||J===eY)G.status=qJ;if(J===x9||J===jW){if(W.avail_out===0)G.last_flush=-1;return t8}if(J===tY){if(Y===uy)gy(G);else if(Y!==RD){if(xA(G,0,0,!1),Y===hy){if(J6(G.head),G.lookahead===0)G.strstart=0,G.block_start=0,G.insert=0}}if(W5(W),W.avail_out===0)return G.last_flush=-1,t8}}if(Y!==w5)return t8;if(G.wrap<=0)return MD;if(G.wrap===2)r1(G,W.adler&255),r1(G,W.adler>>8&255),r1(G,W.adler>>16&255),r1(G,W.adler>>24&255),r1(G,W.total_in&255),r1(G,W.total_in>>8&255),r1(G,W.total_in>>16&255),r1(G,W.total_in>>24&255);else NJ(G,W.adler>>>16),NJ(G,W.adler&65535);if(W5(W),G.wrap>0)G.wrap=-G.wrap;return G.pending!==0?t8:MD},Av=(W)=>{if(LJ(W))return q7;let Y=W.state.status;return W.state=null,Y===IW?zW(W,by):t8},Iv=(W,Y)=>{let G=Y.length;if(LJ(W))return q7;let X=W.state,J=X.wrap;if(J===2||J===1&&X.status!==rY||X.lookahead)return q7;if(J===1)W.adler=CJ(W.adler,Y,G,0);if(X.wrap=0,G>=X.w_size){if(J===0)J6(X.head),X.strstart=0,X.block_start=0,X.insert=0;let Q=new Uint8Array(X.w_size);Q.set(Y.subarray(G-X.w_size,G),0),Y=Q,G=X.w_size}let{avail_in:Z,next_in:V,input:U}=W;W.avail_in=G,W.next_in=0,W.input=Y,aY(X);while(X.lookahead>=v1){let Q=X.strstart,H=X.lookahead-(v1-1);do X.ins_h=Q6(X,X.ins_h,X.window[Q+v1-1]),X.prev[Q&X.w_mask]=X.head[X.ins_h],X.head[X.ins_h]=Q,Q++;while(--H);X.strstart=Q,X.lookahead=v1-1,aY(X)}return X.strstart+=X.lookahead,X.block_start=X.strstart,X.insert=X.lookahead,X.lookahead=0,X.match_length=X.prev_length=v1-1,X.match_available=0,W.next_in=V,W.input=U,W.avail_in=Z,X.wrap=J,t8},zv=Nv,wv=CC,jv=DC,Ov=KC,Kv=Hv,Dv=qv,Cv=Av,Tv=Iv,Rv="pako deflate (from Nodeca project)",zJ={deflateInit:zv,deflateInit2:wv,deflateReset:jv,deflateResetKeep:Ov,deflateSetHeader:Kv,deflate:Dv,deflateEnd:Cv,deflateSetDictionary:Tv,deflateInfo:Rv},Mv=(W,Y)=>{return Object.prototype.hasOwnProperty.call(W,Y)},Pv=function(W){let Y=Array.prototype.slice.call(arguments,1);while(Y.length){let G=Y.shift();if(!G)continue;if(typeof G!=="object")throw TypeError(G+"must be non-object");for(let X in G)if(Mv(G,X))W[X]=G[X]}return W},Lv=(W)=>{let Y=0;for(let X=0,J=W.length;X<J;X++)Y+=W[X].length;let G=new Uint8Array(Y);for(let X=0,J=0,Z=W.length;X<Z;X++){let V=W[X];G.set(V,J),J+=V.length}return G},aU={assign:Pv,flattenChunks:Lv},TC=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(W){TC=!1}var TJ=new Uint8Array(256);for(let W=0;W<256;W++)TJ[W]=W>=252?6:W>=248?5:W>=240?4:W>=224?3:W>=192?2:1;TJ[254]=TJ[254]=1;var Bv=(W)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(W);let Y,G,X,J,Z,V=W.length,U=0;for(J=0;J<V;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(X=W.charCodeAt(J+1),(X&64512)===56320)G=65536+(G-55296<<10)+(X-56320),J++}U+=G<128?1:G<2048?2:G<65536?3:4}Y=new Uint8Array(U);for(Z=0,J=0;Z<U;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(X=W.charCodeAt(J+1),(X&64512)===56320)G=65536+(G-55296<<10)+(X-56320),J++}if(G<128)Y[Z++]=G;else if(G<2048)Y[Z++]=192|G>>>6,Y[Z++]=128|G&63;else if(G<65536)Y[Z++]=224|G>>>12,Y[Z++]=128|G>>>6&63,Y[Z++]=128|G&63;else Y[Z++]=240|G>>>18,Y[Z++]=128|G>>>12&63,Y[Z++]=128|G>>>6&63,Y[Z++]=128|G&63}return Y},Ev=(W,Y)=>{if(Y<65534){if(W.subarray&&TC)return String.fromCharCode.apply(null,W.length===Y?W:W.subarray(0,Y))}let G="";for(let X=0;X<Y;X++)G+=String.fromCharCode(W[X]);return G},$v=(W,Y)=>{let G=Y||W.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(W.subarray(0,Y));let X,J,Z=Array(G*2);for(J=0,X=0;X<G;){let V=W[X++];if(V<128){Z[J++]=V;continue}let U=TJ[V];if(U>4){Z[J++]=65533,X+=U-1;continue}V&=U===2?31:U===3?15:7;while(U>1&&X<G)V=V<<6|W[X++]&63,U--;if(U>1){Z[J++]=65533;continue}if(V<65536)Z[J++]=V;else V-=65536,Z[J++]=55296|V>>10&1023,Z[J++]=56320|V&1023}return Ev(Z,J)},Fv=(W,Y)=>{if(Y=Y||W.length,Y>W.length)Y=W.length;let G=Y-1;while(G>=0&&(W[G]&192)===128)G--;if(G<0)return Y;if(G===0)return Y;return G+TJ[W[G]]>Y?G:Y},RJ={string2buf:Bv,buf2string:$v,utf8border:Fv};function Sv(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var RC=Sv,MC=Object.prototype.toString,{Z_NO_FLUSH:xv,Z_SYNC_FLUSH:kv,Z_FULL_FLUSH:_v,Z_FINISH:yv,Z_OK:nU,Z_STREAM_END:vv,Z_DEFAULT_COMPRESSION:gv,Z_DEFAULT_STRATEGY:uv,Z_DEFLATED:hv}=KW;function BJ(W){this.options=aU.assign({level:gv,method:hv,chunkSize:16384,windowBits:15,memLevel:8,strategy:uv},W||{});let Y=this.options;if(Y.raw&&Y.windowBits>0)Y.windowBits=-Y.windowBits;else if(Y.gzip&&Y.windowBits>0&&Y.windowBits<16)Y.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new RC,this.strm.avail_out=0;let G=zJ.deflateInit2(this.strm,Y.level,Y.method,Y.windowBits,Y.memLevel,Y.strategy);if(G!==nU)throw Error(wW[G]);if(Y.header)zJ.deflateSetHeader(this.strm,Y.header);if(Y.dictionary){let X;if(typeof Y.dictionary==="string")X=RJ.string2buf(Y.dictionary);else if(MC.call(Y.dictionary)==="[object ArrayBuffer]")X=new Uint8Array(Y.dictionary);else X=Y.dictionary;if(G=zJ.deflateSetDictionary(this.strm,X),G!==nU)throw Error(wW[G]);this._dict_set=!0}}BJ.prototype.push=function(W,Y){let G=this.strm,X=this.options.chunkSize,J,Z;if(this.ended)return!1;if(Y===~~Y)Z=Y;else Z=Y===!0?yv:xv;if(typeof W==="string")G.input=RJ.string2buf(W);else if(MC.call(W)==="[object ArrayBuffer]")G.input=new Uint8Array(W);else G.input=W;G.next_in=0,G.avail_in=G.input.length;for(;;){if(G.avail_out===0)G.output=new Uint8Array(X),G.next_out=0,G.avail_out=X;if((Z===kv||Z===_v)&&G.avail_out<=6){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(J=zJ.deflate(G,Z),J===vv){if(G.next_out>0)this.onData(G.output.subarray(0,G.next_out));return J=zJ.deflateEnd(this.strm),this.onEnd(J),this.ended=!0,J===nU}if(G.avail_out===0){this.onData(G.output);continue}if(Z>0&&G.next_out>0){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(G.avail_in===0)break}return!0};BJ.prototype.onData=function(W){this.chunks.push(W)};BJ.prototype.onEnd=function(W){if(W===nU)this.result=aU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function pA(W,Y){let G=new BJ(Y);if(G.push(W,!0),G.err)throw G.msg||wW[G.err];return G.result}function bv(W,Y){return Y=Y||{},Y.raw=!0,pA(W,Y)}function mv(W,Y){return Y=Y||{},Y.gzip=!0,pA(W,Y)}var fv=BJ,cv=pA,pv=bv,lv=mv,dv=KW,ov={Deflate:fv,deflate:cv,deflateRaw:pv,gzip:lv,constants:dv},fU=16209,nv=16191,iv=function(Y,G){let X,J,Z,V,U,Q,H,N,A,q,z,w,D,T,x,g,f,y,p,b,m,W0,u,J0,A0=Y.state;X=Y.next_in,u=Y.input,J=X+(Y.avail_in-5),Z=Y.next_out,J0=Y.output,V=Z-(G-Y.avail_out),U=Z+(Y.avail_out-257),Q=A0.dmax,H=A0.wsize,N=A0.whave,A=A0.wnext,q=A0.window,z=A0.hold,w=A0.bits,D=A0.lencode,T=A0.distcode,x=(1<<A0.lenbits)-1,g=(1<<A0.distbits)-1;W:do{if(w<15)z+=u[X++]<<w,w+=8,z+=u[X++]<<w,w+=8;f=D[z&x];Y:for(;;){if(y=f>>>24,z>>>=y,w-=y,y=f>>>16&255,y===0)J0[Z++]=f&65535;else if(y&16){if(p=f&65535,y&=15,y){if(w<y)z+=u[X++]<<w,w+=8;p+=z&(1<<y)-1,z>>>=y,w-=y}if(w<15)z+=u[X++]<<w,w+=8,z+=u[X++]<<w,w+=8;f=T[z&g];G:for(;;){if(y=f>>>24,z>>>=y,w-=y,y=f>>>16&255,y&16){if(b=f&65535,y&=15,w<y){if(z+=u[X++]<<w,w+=8,w<y)z+=u[X++]<<w,w+=8}if(b+=z&(1<<y)-1,b>Q){Y.msg="invalid distance too far back",A0.mode=fU;break W}if(z>>>=y,w-=y,y=Z-V,b>y){if(y=b-y,y>N){if(A0.sane){Y.msg="invalid distance too far back",A0.mode=fU;break W}}if(m=0,W0=q,A===0){if(m+=H-y,y<p){p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}}else if(A<y){if(m+=H+A-y,y-=A,y<p){p-=y;do J0[Z++]=q[m++];while(--y);if(m=0,A<p){y=A,p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}}}else if(m+=A-y,y<p){p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}while(p>2)J0[Z++]=W0[m++],J0[Z++]=W0[m++],J0[Z++]=W0[m++],p-=3;if(p){if(J0[Z++]=W0[m++],p>1)J0[Z++]=W0[m++]}}else{m=Z-b;do J0[Z++]=J0[m++],J0[Z++]=J0[m++],J0[Z++]=J0[m++],p-=3;while(p>2);if(p){if(J0[Z++]=J0[m++],p>1)J0[Z++]=J0[m++]}}}else if((y&64)===0){f=T[(f&65535)+(z&(1<<y)-1)];continue G}else{Y.msg="invalid distance code",A0.mode=fU;break W}break}}else if((y&64)===0){f=D[(f&65535)+(z&(1<<y)-1)];continue Y}else if(y&32){A0.mode=nv;break W}else{Y.msg="invalid literal/length code",A0.mode=fU;break W}break}}while(X<J&&Z<U);p=w>>3,X-=p,w-=p<<3,z&=(1<<w)-1,Y.next_in=X,Y.next_out=Z,Y.avail_in=X<J?5+(J-X):5-(X-J),Y.avail_out=Z<U?257+(U-Z):257-(Z-U),A0.hold=z,A0.bits=w;return},nY=15,LD=852,BD=592,ED=0,TA=1,$D=2,rv=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),av=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),sv=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),tv=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),ev=(W,Y,G,X,J,Z,V,U)=>{let Q=U.bits,H=0,N=0,A=0,q=0,z=0,w=0,D=0,T=0,x=0,g=0,f,y,p,b,m,W0=null,u,J0=new Uint16Array(nY+1),A0=new Uint16Array(nY+1),k=null,l,B,$;for(H=0;H<=nY;H++)J0[H]=0;for(N=0;N<X;N++)J0[Y[G+N]]++;z=Q;for(q=nY;q>=1;q--)if(J0[q]!==0)break;if(z>q)z=q;if(q===0)return J[Z++]=20971520,J[Z++]=20971520,U.bits=1,0;for(A=1;A<q;A++)if(J0[A]!==0)break;if(z<A)z=A;T=1;for(H=1;H<=nY;H++)if(T<<=1,T-=J0[H],T<0)return-1;if(T>0&&(W===ED||q!==1))return-1;A0[1]=0;for(H=1;H<nY;H++)A0[H+1]=A0[H]+J0[H];for(N=0;N<X;N++)if(Y[G+N]!==0)V[A0[Y[G+N]]++]=N;if(W===ED)W0=k=V,u=20;else if(W===TA)W0=rv,k=av,u=257;else W0=sv,k=tv,u=0;if(g=0,N=0,H=A,m=Z,w=z,D=0,p=-1,x=1<<z,b=x-1,W===TA&&x>LD||W===$D&&x>BD)return 1;for(;;){if(l=H-D,V[N]+1<u)B=0,$=V[N];else if(V[N]>=u)B=k[V[N]-u],$=W0[V[N]-u];else B=96,$=0;f=1<<H-D,y=1<<w,A=y;do y-=f,J[m+(g>>D)+y]=l<<24|B<<16|$|0;while(y!==0);f=1<<H-1;while(g&f)f>>=1;if(f!==0)g&=f-1,g+=f;else g=0;if(N++,--J0[H]===0){if(H===q)break;H=Y[G+V[N]]}if(H>z&&(g&b)!==p){if(D===0)D=z;m+=A,w=H-D,T=1<<w;while(w+D<q){if(T-=J0[w+D],T<=0)break;w++,T<<=1}if(x+=1<<w,W===TA&&x>LD||W===$D&&x>BD)return 1;p=g&b,J[p]=z<<24|w<<16|m-Z|0}}if(g!==0)J[m+g]=H-D<<24|4194304|0;return U.bits=z,0},wJ=ev,Wg=0,PC=1,LC=2,{Z_FINISH:FD,Z_BLOCK:Yg,Z_TREES:cU,Z_OK:OW,Z_STREAM_END:Gg,Z_NEED_DICT:Xg,Z_STREAM_ERROR:j5,Z_DATA_ERROR:BC,Z_MEM_ERROR:EC,Z_BUF_ERROR:Jg,Z_DEFLATED:SD}=KW,sU=16180,xD=16181,kD=16182,_D=16183,yD=16184,vD=16185,gD=16186,uD=16187,hD=16188,bD=16189,iU=16190,s7=16191,RA=16192,mD=16193,MA=16194,fD=16195,cD=16196,pD=16197,lD=16198,pU=16199,lU=16200,dD=16201,oD=16202,nD=16203,iD=16204,rD=16205,PA=16206,aD=16207,sD=16208,w8=16209,$C=16210,FC=16211,Zg=852,Vg=592,Ug=15,Qg=Ug,tD=(W)=>{return(W>>>24&255)+(W>>>8&65280)+((W&65280)<<8)+((W&255)<<24)};function Hg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var DW=(W)=>{if(!W)return 1;let Y=W.state;if(!Y||Y.strm!==W||Y.mode<sU||Y.mode>FC)return 1;return 0},SC=(W)=>{if(DW(W))return j5;let Y=W.state;if(W.total_in=W.total_out=Y.total=0,W.msg="",Y.wrap)W.adler=Y.wrap&1;return Y.mode=sU,Y.last=0,Y.havedict=0,Y.flags=-1,Y.dmax=32768,Y.head=null,Y.hold=0,Y.bits=0,Y.lencode=Y.lendyn=new Int32Array(Zg),Y.distcode=Y.distdyn=new Int32Array(Vg),Y.sane=1,Y.back=-1,OW},xC=(W)=>{if(DW(W))return j5;let Y=W.state;return Y.wsize=0,Y.whave=0,Y.wnext=0,SC(W)},kC=(W,Y)=>{let G;if(DW(W))return j5;let X=W.state;if(Y<0)G=0,Y=-Y;else if(G=(Y>>4)+5,Y<48)Y&=15;if(Y&&(Y<8||Y>15))return j5;if(X.window!==null&&X.wbits!==Y)X.window=null;return X.wrap=G,X.wbits=Y,xC(W)},_C=(W,Y)=>{if(!W)return j5;let G=new Hg;W.state=G,G.strm=W,G.window=null,G.mode=sU;let X=kC(W,Y);if(X!==OW)W.state=null;return X},Ng=(W)=>{return _C(W,Qg)},eD=!0,LA,BA,qg=(W)=>{if(eD){LA=new Int32Array(512),BA=new Int32Array(32);let Y=0;while(Y<144)W.lens[Y++]=8;while(Y<256)W.lens[Y++]=9;while(Y<280)W.lens[Y++]=7;while(Y<288)W.lens[Y++]=8;wJ(PC,W.lens,0,288,LA,0,W.work,{bits:9}),Y=0;while(Y<32)W.lens[Y++]=5;wJ(LC,W.lens,0,32,BA,0,W.work,{bits:5}),eD=!1}W.lencode=LA,W.lenbits=9,W.distcode=BA,W.distbits=5},yC=(W,Y,G,X)=>{let J,Z=W.state;if(Z.window===null)Z.wsize=1<<Z.wbits,Z.wnext=0,Z.whave=0,Z.window=new Uint8Array(Z.wsize);if(X>=Z.wsize)Z.window.set(Y.subarray(G-Z.wsize,G),0),Z.wnext=0,Z.whave=Z.wsize;else{if(J=Z.wsize-Z.wnext,J>X)J=X;if(Z.window.set(Y.subarray(G-X,G-X+J),Z.wnext),X-=J,X)Z.window.set(Y.subarray(G-X,G),0),Z.wnext=X,Z.whave=Z.wsize;else{if(Z.wnext+=J,Z.wnext===Z.wsize)Z.wnext=0;if(Z.whave<Z.wsize)Z.whave+=J}}return 0},Ag=(W,Y)=>{let G,X,J,Z,V,U,Q,H,N,A,q,z,w,D,T=0,x,g,f,y,p,b,m,W0,u=new Uint8Array(4),J0,A0,k=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(DW(W)||!W.output||!W.input&&W.avail_in!==0)return j5;if(G=W.state,G.mode===s7)G.mode=RA;V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,X=W.input,U=W.avail_in,H=G.hold,N=G.bits,A=U,q=Q,W0=OW;W:for(;;)switch(G.mode){case sU:if(G.wrap===0){G.mode=RA;break}while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&2&&H===35615){if(G.wbits===0)G.wbits=15;G.check=0,u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0),H=0,N=0,G.mode=xD;break}if(G.head)G.head.done=!1;if(!(G.wrap&1)||(((H&255)<<8)+(H>>8))%31){W.msg="incorrect header check",G.mode=w8;break}if((H&15)!==SD){W.msg="unknown compression method",G.mode=w8;break}if(H>>>=4,N-=4,m=(H&15)+8,G.wbits===0)G.wbits=m;if(m>15||m>G.wbits){W.msg="invalid window size",G.mode=w8;break}G.dmax=1<<G.wbits,G.flags=0,W.adler=G.check=1,G.mode=H&512?bD:s7,H=0,N=0;break;case xD:while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.flags=H,(G.flags&255)!==SD){W.msg="unknown compression method",G.mode=w8;break}if(G.flags&57344){W.msg="unknown header flags set",G.mode=w8;break}if(G.head)G.head.text=H>>8&1;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0,G.mode=kD;case kD:while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.head)G.head.time=H;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,u[2]=H>>>16&255,u[3]=H>>>24&255,G.check=n8(G.check,u,4,0);H=0,N=0,G.mode=_D;case _D:while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.head)G.head.xflags=H&255,G.head.os=H>>8;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0,G.mode=yD;case yD:if(G.flags&1024){while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.length=H,G.head)G.head.extra_len=H;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0}else if(G.head)G.head.extra=null;G.mode=vD;case vD:if(G.flags&1024){if(z=G.length,z>U)z=U;if(z){if(G.head){if(m=G.head.extra_len-G.length,!G.head.extra)G.head.extra=new Uint8Array(G.head.extra_len);G.head.extra.set(X.subarray(Z,Z+z),m)}if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);U-=z,Z+=z,G.length-=z}if(G.length)break W}G.length=0,G.mode=gD;case gD:if(G.flags&2048){if(U===0)break W;z=0;do if(m=X[Z+z++],G.head&&m&&G.length<65536)G.head.name+=String.fromCharCode(m);while(m&&z<U);if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);if(U-=z,Z+=z,m)break W}else if(G.head)G.head.name=null;G.length=0,G.mode=uD;case uD:if(G.flags&4096){if(U===0)break W;z=0;do if(m=X[Z+z++],G.head&&m&&G.length<65536)G.head.comment+=String.fromCharCode(m);while(m&&z<U);if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);if(U-=z,Z+=z,m)break W}else if(G.head)G.head.comment=null;G.mode=hD;case hD:if(G.flags&512){while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&4&&H!==(G.check&65535)){W.msg="header crc mismatch",G.mode=w8;break}H=0,N=0}if(G.head)G.head.hcrc=G.flags>>9&1,G.head.done=!0;W.adler=G.check=0,G.mode=s7;break;case bD:while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}W.adler=G.check=tD(H),H=0,N=0,G.mode=iU;case iU:if(G.havedict===0)return W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,Xg;W.adler=G.check=1,G.mode=s7;case s7:if(Y===Yg||Y===cU)break W;case RA:if(G.last){H>>>=N&7,N-=N&7,G.mode=PA;break}while(N<3){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}switch(G.last=H&1,H>>>=1,N-=1,H&3){case 0:G.mode=mD;break;case 1:if(qg(G),G.mode=pU,Y===cU){H>>>=2,N-=2;break W}break;case 2:G.mode=cD;break;case 3:W.msg="invalid block type",G.mode=w8}H>>>=2,N-=2;break;case mD:H>>>=N&7,N-=N&7;while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if((H&65535)!==(H>>>16^65535)){W.msg="invalid stored block lengths",G.mode=w8;break}if(G.length=H&65535,H=0,N=0,G.mode=MA,Y===cU)break W;case MA:G.mode=fD;case fD:if(z=G.length,z){if(z>U)z=U;if(z>Q)z=Q;if(z===0)break W;J.set(X.subarray(Z,Z+z),V),U-=z,Z+=z,Q-=z,V+=z,G.length-=z;break}G.mode=s7;break;case cD:while(N<14){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.nlen=(H&31)+257,H>>>=5,N-=5,G.ndist=(H&31)+1,H>>>=5,N-=5,G.ncode=(H&15)+4,H>>>=4,N-=4,G.nlen>286||G.ndist>30){W.msg="too many length or distance symbols",G.mode=w8;break}G.have=0,G.mode=pD;case pD:while(G.have<G.ncode){while(N<3){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.lens[k[G.have++]]=H&7,H>>>=3,N-=3}while(G.have<19)G.lens[k[G.have++]]=0;if(G.lencode=G.lendyn,G.lenbits=7,J0={bits:G.lenbits},W0=wJ(Wg,G.lens,0,19,G.lencode,0,G.work,J0),G.lenbits=J0.bits,W0){W.msg="invalid code lengths set",G.mode=w8;break}G.have=0,G.mode=lD;case lD:while(G.have<G.nlen+G.ndist){for(;;){if(T=G.lencode[H&(1<<G.lenbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(f<16)H>>>=x,N-=x,G.lens[G.have++]=f;else{if(f===16){A0=x+2;while(N<A0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(H>>>=x,N-=x,G.have===0){W.msg="invalid bit length repeat",G.mode=w8;break}m=G.lens[G.have-1],z=3+(H&3),H>>>=2,N-=2}else if(f===17){A0=x+3;while(N<A0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=x,N-=x,m=0,z=3+(H&7),H>>>=3,N-=3}else{A0=x+7;while(N<A0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=x,N-=x,m=0,z=11+(H&127),H>>>=7,N-=7}if(G.have+z>G.nlen+G.ndist){W.msg="invalid bit length repeat",G.mode=w8;break}while(z--)G.lens[G.have++]=m}}if(G.mode===w8)break;if(G.lens[256]===0){W.msg="invalid code -- missing end-of-block",G.mode=w8;break}if(G.lenbits=9,J0={bits:G.lenbits},W0=wJ(PC,G.lens,0,G.nlen,G.lencode,0,G.work,J0),G.lenbits=J0.bits,W0){W.msg="invalid literal/lengths set",G.mode=w8;break}if(G.distbits=6,G.distcode=G.distdyn,J0={bits:G.distbits},W0=wJ(LC,G.lens,G.nlen,G.ndist,G.distcode,0,G.work,J0),G.distbits=J0.bits,W0){W.msg="invalid distances set",G.mode=w8;break}if(G.mode=pU,Y===cU)break W;case pU:G.mode=lU;case lU:if(U>=6&&Q>=258){if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,iv(W,q),V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,X=W.input,U=W.avail_in,H=G.hold,N=G.bits,G.mode===s7)G.back=-1;break}G.back=0;for(;;){if(T=G.lencode[H&(1<<G.lenbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(g&&(g&240)===0){y=x,p=g,b=f;for(;;){if(T=G.lencode[b+((H&(1<<y+p)-1)>>y)],x=T>>>24,g=T>>>16&255,f=T&65535,y+x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=y,N-=y,G.back+=y}if(H>>>=x,N-=x,G.back+=x,G.length=f,g===0){G.mode=rD;break}if(g&32){G.back=-1,G.mode=s7;break}if(g&64){W.msg="invalid literal/length code",G.mode=w8;break}G.extra=g&15,G.mode=dD;case dD:if(G.extra){A0=G.extra;while(N<A0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.length+=H&(1<<G.extra)-1,H>>>=G.extra,N-=G.extra,G.back+=G.extra}G.was=G.length,G.mode=oD;case oD:for(;;){if(T=G.distcode[H&(1<<G.distbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if((g&240)===0){y=x,p=g,b=f;for(;;){if(T=G.distcode[b+((H&(1<<y+p)-1)>>y)],x=T>>>24,g=T>>>16&255,f=T&65535,y+x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=y,N-=y,G.back+=y}if(H>>>=x,N-=x,G.back+=x,g&64){W.msg="invalid distance code",G.mode=w8;break}G.offset=f,G.extra=g&15,G.mode=nD;case nD:if(G.extra){A0=G.extra;while(N<A0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.offset+=H&(1<<G.extra)-1,H>>>=G.extra,N-=G.extra,G.back+=G.extra}if(G.offset>G.dmax){W.msg="invalid distance too far back",G.mode=w8;break}G.mode=iD;case iD:if(Q===0)break W;if(z=q-Q,G.offset>z){if(z=G.offset-z,z>G.whave){if(G.sane){W.msg="invalid distance too far back",G.mode=w8;break}}if(z>G.wnext)z-=G.wnext,w=G.wsize-z;else w=G.wnext-z;if(z>G.length)z=G.length;D=G.window}else D=J,w=V-G.offset,z=G.length;if(z>Q)z=Q;Q-=z,G.length-=z;do J[V++]=D[w++];while(--z);if(G.length===0)G.mode=lU;break;case rD:if(Q===0)break W;J[V++]=G.length,Q--,G.mode=lU;break;case PA:if(G.wrap){while(N<32){if(U===0)break W;U--,H|=X[Z++]<<N,N+=8}if(q-=Q,W.total_out+=q,G.total+=q,G.wrap&4&&q)W.adler=G.check=G.flags?n8(G.check,J,q,V-q):CJ(G.check,J,q,V-q);if(q=Q,G.wrap&4&&(G.flags?H:tD(H))!==G.check){W.msg="incorrect data check",G.mode=w8;break}H=0,N=0}G.mode=aD;case aD:if(G.wrap&&G.flags){while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&4&&H!==(G.total&4294967295)){W.msg="incorrect length check",G.mode=w8;break}H=0,N=0}G.mode=sD;case sD:W0=Gg;break W;case w8:W0=BC;break W;case $C:return EC;case FC:default:return j5}if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,G.wsize||q!==W.avail_out&&G.mode<w8&&(G.mode<PA||Y!==FD)){if(yC(W,W.output,W.next_out,q-W.avail_out));}if(A-=W.avail_in,q-=W.avail_out,W.total_in+=A,W.total_out+=q,G.total+=q,G.wrap&4&&q)W.adler=G.check=G.flags?n8(G.check,J,q,W.next_out-q):CJ(G.check,J,q,W.next_out-q);if(W.data_type=G.bits+(G.last?64:0)+(G.mode===s7?128:0)+(G.mode===pU||G.mode===MA?256:0),(A===0&&q===0||Y===FD)&&W0===OW)W0=Jg;return W0},Ig=(W)=>{if(DW(W))return j5;let Y=W.state;if(Y.window)Y.window=null;return W.state=null,OW},zg=(W,Y)=>{if(DW(W))return j5;let G=W.state;if((G.wrap&2)===0)return j5;return G.head=Y,Y.done=!1,OW},wg=(W,Y)=>{let G=Y.length,X,J,Z;if(DW(W))return j5;if(X=W.state,X.wrap!==0&&X.mode!==iU)return j5;if(X.mode===iU){if(J=1,J=CJ(J,Y,G,0),J!==X.check)return BC}if(Z=yC(W,Y,G,G),Z)return X.mode=$C,EC;return X.havedict=1,OW},jg=xC,Og=kC,Kg=SC,Dg=Ng,Cg=_C,Tg=Ag,Rg=Ig,Mg=zg,Pg=wg,Lg="pako inflate (from Nodeca project)",e7={inflateReset:jg,inflateReset2:Og,inflateResetKeep:Kg,inflateInit:Dg,inflateInit2:Cg,inflate:Tg,inflateEnd:Rg,inflateGetHeader:Mg,inflateSetDictionary:Pg,inflateInfo:Lg};function Bg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var Eg=Bg,vC=Object.prototype.toString,{Z_NO_FLUSH:$g,Z_FINISH:Fg,Z_OK:MJ,Z_STREAM_END:EA,Z_NEED_DICT:$A,Z_STREAM_ERROR:Sg,Z_DATA_ERROR:WC,Z_MEM_ERROR:xg}=KW;function EJ(W){this.options=aU.assign({chunkSize:65536,windowBits:15,to:""},W||{});let Y=this.options;if(Y.raw&&Y.windowBits>=0&&Y.windowBits<16){if(Y.windowBits=-Y.windowBits,Y.windowBits===0)Y.windowBits=-15}if(Y.windowBits>=0&&Y.windowBits<16&&!(W&&W.windowBits))Y.windowBits+=32;if(Y.windowBits>15&&Y.windowBits<48){if((Y.windowBits&15)===0)Y.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new RC,this.strm.avail_out=0;let G=e7.inflateInit2(this.strm,Y.windowBits);if(G!==MJ)throw Error(wW[G]);if(this.header=new Eg,e7.inflateGetHeader(this.strm,this.header),Y.dictionary){if(typeof Y.dictionary==="string")Y.dictionary=RJ.string2buf(Y.dictionary);else if(vC.call(Y.dictionary)==="[object ArrayBuffer]")Y.dictionary=new Uint8Array(Y.dictionary);if(Y.raw){if(G=e7.inflateSetDictionary(this.strm,Y.dictionary),G!==MJ)throw Error(wW[G])}}}EJ.prototype.push=function(W,Y){let G=this.strm,X=this.options.chunkSize,J=this.options.dictionary,Z,V,U;if(this.ended)return!1;if(Y===~~Y)V=Y;else V=Y===!0?Fg:$g;if(vC.call(W)==="[object ArrayBuffer]")G.input=new Uint8Array(W);else G.input=W;G.next_in=0,G.avail_in=G.input.length;for(;;){if(G.avail_out===0)G.output=new Uint8Array(X),G.next_out=0,G.avail_out=X;if(Z=e7.inflate(G,V),Z===$A&&J){if(Z=e7.inflateSetDictionary(G,J),Z===MJ)Z=e7.inflate(G,V);else if(Z===WC)Z=$A}while(G.avail_in>0&&Z===EA&&G.state.wrap>0&&W[G.next_in]!==0)e7.inflateReset(G),Z=e7.inflate(G,V);switch(Z){case Sg:case WC:case $A:case xg:return this.onEnd(Z),this.ended=!0,!1}if(U=G.avail_out,G.next_out){if(G.avail_out===0||Z===EA)if(this.options.to==="string"){let Q=RJ.utf8border(G.output,G.next_out),H=G.next_out-Q,N=RJ.buf2string(G.output,Q);if(G.next_out=H,G.avail_out=X-H,H)G.output.set(G.output.subarray(Q,Q+H),0);this.onData(N)}else this.onData(G.output.length===G.next_out?G.output:G.output.subarray(0,G.next_out))}if(Z===MJ&&U===0)continue;if(Z===EA)return Z=e7.inflateEnd(this.strm),this.onEnd(Z),this.ended=!0,!0;if(G.avail_in===0)break}return!0};EJ.prototype.onData=function(W){this.chunks.push(W)};EJ.prototype.onEnd=function(W){if(W===MJ)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=aU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function lA(W,Y){let G=new EJ(Y);if(G.push(W),G.err)throw G.msg||wW[G.err];return G.result}function kg(W,Y){return Y=Y||{},Y.raw=!0,lA(W,Y)}var _g=EJ,yg=lA,vg=kg,gg=lA,ug=KW,hg={Inflate:_g,inflate:yg,inflateRaw:vg,ungzip:gg,constants:ug},{Deflate:bg,deflate:mg,deflateRaw:fg,gzip:cg}=ov,{Inflate:pg,inflate:lg,inflateRaw:dg,ungzip:og}=hg,ng=bg,ig=mg,rg=fg,ag=cg,sg=pg,tg=lg,eg=dg,Wu=og,Yu=KW,WG={Deflate:ng,deflate:ig,deflateRaw:rg,gzip:ag,Inflate:sg,inflate:tg,inflateRaw:eg,ungzip:Wu,constants:Yu};function gC(){let W=Date.now(),Y=0;return{now(){return W=Math.max(W,Date.now()),Y++,{physical:W,logical:Y}},update(G){if(!G||typeof G.physical!=="number"||typeof G.logical!=="number")return;W=Math.max(W,G.physical),Y=Math.max(Y,G.logical)+1},compare(G,X){if(!G&&!X)return 0;if(!G)return-1;if(!X)return 1;if(G.physical!==X.physical)return G.physical>X.physical?1:-1;if(G.logical!==X.logical)return G.logical>X.logical?1:-1;return 0}}}function uC(W,Y,G){let X=Y.timestamp;if(X?.physical>Date.now()+7200000)X={physical:Date.now()+7200000,logical:X.logical};if(Y?.value?.priority===!0&&typeof Y.id==="string"&&Y.id.startsWith("user:")&&"role"in Y.value){let{priority:J,...Z}=Y.value;return{resolved:!0,value:Z,timestamp:X}}if(Y?.value?.priority!==void 0){let{priority:J,...Z}=Y.value;Y={...Y,value:Z}}if(!W?.timestamp)return{resolved:!0,value:Y.value,timestamp:X};if(G.compare(X,W.timestamp)<=0)return{resolved:!1};return{resolved:!0,value:Y.value,timestamp:X}}var $J={$eq:(W,Y)=>W===Y,$ne:(W,Y)=>W!==Y,$gt:(W,Y)=>W>Y,$gte:(W,Y)=>W>=Y,$lt:(W,Y)=>W<Y,$lte:(W,Y)=>W<=Y,$in:(W,Y)=>Array.isArray(Y)&&(Array.isArray(W)?W.some((G)=>Y.includes(G)):Y.includes(W)),$between:(W,[Y,G])=>W>=Y&&W<=G,$exists:(W,Y)=>Y?W!==void 0:W===void 0,$startsWith:(W,Y)=>typeof W==="string"&&W.startsWith(Y),$endsWith:(W,Y)=>typeof W==="string"&&W.endsWith(Y),$contains:(W,Y)=>typeof W==="string"&&W.includes(Y),$text:{global:(W,Y)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),X=G(Y);return Object.values(W).some((J)=>typeof J==="object"?null.fieldSearch(J,X):G(J).includes(X))},field:(W,Y)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),X=G(Y);return Array.isArray(W)?W.some((J)=>G(J).includes(X)):G(W).includes(X)}},$like:(W,Y)=>typeof W==="string"&&typeof Y==="string"&&new RegExp(`^${Y.replace(/%/g,".*").replace(/_/g,".")}$`,"i").test(W),$regex:(W,Y)=>typeof W==="string"&&new RegExp(Y.$regex||Y,"i").test(W),$and:(W,Y,G)=>Y.every((X)=>G.createFilter(X,G.allNodes)(W)),$or:(W,Y,G)=>Y.some((X)=>G.createFilter(X,G.allNodes)(W)),$not:(W,Y,G)=>!G.createFilter(Y,G.allNodes)(W),$edge:(W,Y,G)=>{if(!W.edges?.length||typeof Y!=="object"||Y===null)return!1;let X=G.createFilter(Y,G.allNodes),J=[...W.edges],Z=new Set(J).add(W.id),V=[];while(J.length){let U=J.shift(),Q=G.allNodes[U];if(!Q)continue;if(X(Q))V.push(Q);Q.edges?.forEach((H)=>!Z.has(H)&&Z.add(H)&&J.push(H))}if(V.length)W._edgeResult=V;return V.length>0}},tU=(W,Y)=>Y.split(".").reduce((G,X)=>G&&typeof G==="object"&&(X in G)?G[X]:void 0,W),eU=(W,Y)=>{if(Object.keys(W).length===0)return()=>!0;return(G)=>Object.entries(W).every(([X,J])=>{if(X.startsWith("$"))return $J[X](G,J,{createFilter:eU,allNodes:Y});let Z=tU(G.value,X);if(Z===void 0)Z=tU(G,X);if(typeof J!=="object"||J===null)return $J.$eq(Z,J);return Object.entries(J).every(([V,U])=>{if(V==="$text")return $J.$text.field(Z,U);if(V==="$between"&&U.every((Q)=>Q instanceof Date))return $J.$between(new Date(Z),U);return $J[V]?.(Z,U,{createFilter:eU,allNodes:Y})??!1})})},dA=(W,Y)=>{let{$edge:G,...X}=Y.query||{},J=eU(X,W),Z=Object.values(W).filter(J),U=[...G?(()=>{let Q=eU({$edge:G},W);Z.forEach((N)=>Q(N));let H=new Map;return Z.forEach((N)=>{if(N._edgeResult)N._edgeResult.forEach((A)=>H.set(A.id,A)),delete N._edgeResult}),Array.from(H.values())})():Z];if(Y.field){let Q=Y.order==="asc"?1:-1;U.sort((H,N)=>{let A=tU(H.value,Y.field),q=tU(N.value,Y.field);if(typeof A==="string"&&typeof q==="string")return A.localeCompare(q)*Q;return((A??0)-(q??0))*Q})}if(Y.$after){let Q=U.findIndex((H)=>H.id===Y.$after);U=Q>=0?U.slice(Q+1):[]}if(Y.$before){let Q=U.findIndex((H)=>H.id===Y.$before);U=Q>=0?U.slice(0,Q):[]}if(Y.$limit)U=U.slice(0,Y.$limit);return U};var vJ=(()=>{let W=()=>{};return new Proxy(console,{get:(Y,G)=>globalThis.__gdbDebug?Y[G].bind(Y):W})})(),YG=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function TQ(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function XI(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function LW(W,...Y){if(!TQ(W))throw Error("Uint8Array expected");if(Y.length>0&&!Y.includes(W.length))throw Error("Uint8Array expected of length "+Y+", got length="+W.length)}function XT(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");XI(W.outputLen),XI(W.blockLen)}function qQ(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function Gu(W,Y){LW(W);let G=Y.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function AQ(...W){for(let Y=0;Y<W.length;Y++)W[Y].fill(0)}function oA(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function I7(W,Y){return W<<32-Y|W>>>Y}var JT=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),Xu=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function JG(W){if(LW(W),JT)return W.toHex();let Y="";for(let G=0;G<W.length;G++)Y+=Xu[W[G]];return Y}var W4={_0:48,_9:57,A:65,F:70,a:97,f:102};function hC(W){if(W>=W4._0&&W<=W4._9)return W-W4._0;if(W>=W4.A&&W<=W4.F)return W-(W4.A-10);if(W>=W4.a&&W<=W4.f)return W-(W4.a-10);return}function IQ(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(JT)return Uint8Array.fromHex(W);let Y=W.length,G=Y/2;if(Y%2)throw Error("hex string expected, got unpadded hex of length "+Y);let X=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=hC(W.charCodeAt(Z)),U=hC(W.charCodeAt(Z+1));if(V===void 0||U===void 0){let Q=W[Z]+W[Z+1];throw Error('hex string expected, got non-hex character "'+Q+'" at index '+Z)}X[J]=V*16+U}return X}function ZT(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function qI(W){if(typeof W==="string")W=ZT(W);return LW(W),W}function z7(...W){let Y=0;for(let X=0;X<W.length;X++){let J=W[X];LW(J),Y+=J.length}let G=new Uint8Array(Y);for(let X=0,J=0;X<W.length;X++){let Z=W[X];G.set(Z,J),J+=Z.length}return G}class AI{}function Ju(W){let Y=(X)=>W().update(qI(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function RQ(W=32){if(YG&&typeof YG.getRandomValues==="function")return YG.getRandomValues(new Uint8Array(W));if(YG&&typeof YG.randomBytes==="function")return Uint8Array.from(YG.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}function Zu(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}function Vu(W,Y,G){return W&Y^~W&G}function Uu(W,Y,G){return W&Y^W&G^Y&G}class VT extends AI{constructor(W,Y,G,X){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.buffer=new Uint8Array(W),this.view=oA(this.buffer)}update(W){qQ(this),W=qI(W),LW(W);let{view:Y,buffer:G,blockLen:X}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=oA(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){qQ(this),Gu(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,AQ(this.buffer.subarray(Z)),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Zu(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=oA(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=X,W.pos=V,X%Y)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var H6=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qu=Uint32Array.from([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]),N6=new Uint32Array(64);class UT extends VT{constructor(W=32){super(64,W,8,!1);this.A=H6[0]|0,this.B=H6[1]|0,this.C=H6[2]|0,this.D=H6[3]|0,this.E=H6[4]|0,this.F=H6[5]|0,this.G=H6[6]|0,this.H=H6[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)N6[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=N6[N-15],q=N6[N-2],z=I7(A,7)^I7(A,18)^A>>>3,w=I7(q,17)^I7(q,19)^q>>>10;N6[N]=w+N6[N-7]+z+N6[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=I7(V,6)^I7(V,11)^I7(V,25),q=H+A+Vu(V,U,Q)+Qu[N]+N6[N]|0,z=(I7(G,2)^I7(G,13)^I7(G,22))+Uu(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+z|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){AQ(N6)}destroy(){this.set(0,0,0,0,0,0,0,0),AQ(this.buffer)}}var JI=Ju(()=>new UT);class II extends AI{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,XT(W);let G=qI(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),AQ(J)}update(W){return qQ(this),this.iHash.update(W),this}digestInto(W){qQ(this),LW(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var QT=(W,Y,G)=>new II(W,Y).update(G).digest();QT.create=(W,Y)=>new II(W,Y);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var zI=BigInt(0),ZI=BigInt(1);function zQ(W,Y=""){if(typeof W!=="boolean"){let G=Y&&`"${Y}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function CW(W,Y,G=""){let X=TQ(W),J=W?.length,Z=Y!==void 0;if(!X||Z&&J!==Y){let V=G&&`"${G}" `,U=Z?` of length ${Y}`:"",Q=X?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function WQ(W){let Y=W.toString(16);return Y.length&1?"0"+Y:Y}function HT(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?zI:BigInt("0x"+W)}function HG(W){return HT(JG(W))}function NT(W){return LW(W),HT(JG(Uint8Array.from(W).reverse()))}function MQ(W,Y){return IQ(W.toString(16).padStart(Y*2,"0"))}function qT(W,Y){return MQ(W,Y).reverse()}function b8(W,Y,G){let X;if(typeof Y==="string")try{X=IQ(Y)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(TQ(Y))X=Uint8Array.from(Y);else throw Error(W+" must be hex string or Uint8Array");let J=X.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return X}var nA=(W)=>typeof W==="bigint"&&zI<=W;function VI(W,Y,G){return nA(W)&&nA(Y)&&nA(G)&&Y<=W&&W<G}function Hu(W,Y,G,X){if(!VI(Y,G,X))throw Error("expected valid "+W+": "+G+" <= n < "+X+", got "+Y)}function AT(W){let Y;for(Y=0;W>zI;W>>=ZI,Y+=1);return Y}var hJ=(W)=>(ZI<<BigInt(W))-ZI;function Nu(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=(q)=>new Uint8Array(q),J=(q)=>Uint8Array.of(q),Z=X(W),V=X(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},H=(...q)=>G(V,Z,...q),N=(q=X(0))=>{if(V=H(J(0),q),Z=H(),q.length===0)return;V=H(J(1),q),Z=H()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let q=0,z=[];while(q<Y){Z=H();let w=Z.slice();z.push(w),q+=Z.length}return z7(...z)};return(q,z)=>{Q(),N(q);let w=void 0;while(!(w=z(A())))N();return Q(),w}}function wI(W,Y,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function X(J,Z,V){let U=W[J];if(V&&U===void 0)return;let Q=typeof U;if(Q!==Z||U===null)throw Error(`param "${J}" is invalid: expected ${Z}, got ${Q}`)}Object.entries(Y).forEach(([J,Z])=>X(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>X(J,Z,!0))}function bC(W){let Y=new WeakMap;return(G,...X)=>{let J=Y.get(G);if(J!==void 0)return J;let Z=W(G,...X);return Y.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var k9=BigInt(0),q9=BigInt(1),TW=BigInt(2),IT=BigInt(3),zT=BigInt(4),wT=BigInt(5),qu=BigInt(7),jT=BigInt(8),Au=BigInt(9),OT=BigInt(16);function D5(W,Y){let G=W%Y;return G>=k9?G:Y+G}function O5(W,Y,G){let X=W;while(Y-- >k9)X*=X,X%=G;return X}function mC(W,Y){if(W===k9)throw Error("invert: expected non-zero number");if(Y<=k9)throw Error("invert: expected positive modulus, got "+Y);let G=D5(W,Y),X=Y,J=k9,Z=q9,V=q9,U=k9;while(G!==k9){let Q=X/G,H=X%G,N=J-V*Q,A=Z-U*Q;X=G,G=H,J=V,Z=U,V=N,U=A}if(X!==q9)throw Error("invert: does not exist");return D5(J,Y)}function jI(W,Y,G){if(!W.eql(W.sqr(Y),G))throw Error("Cannot find square root")}function KT(W,Y){let G=(W.ORDER+q9)/zT,X=W.pow(Y,G);return jI(W,X,Y),X}function Iu(W,Y){let G=(W.ORDER-wT)/jT,X=W.mul(Y,TW),J=W.pow(X,G),Z=W.mul(Y,J),V=W.mul(W.mul(Z,TW),J),U=W.mul(Z,W.sub(V,W.ONE));return jI(W,U,Y),U}function zu(W){let Y=bJ(W),G=DT(W),X=G(Y,Y.neg(Y.ONE)),J=G(Y,X),Z=G(Y,Y.neg(X)),V=(W+qu)/OT;return(U,Q)=>{let H=U.pow(Q,V),N=U.mul(H,X),A=U.mul(H,J),q=U.mul(H,Z),z=U.eql(U.sqr(N),Q),w=U.eql(U.sqr(A),Q);H=U.cmov(H,N,z),N=U.cmov(q,A,w);let D=U.eql(U.sqr(N),Q),T=U.cmov(H,N,D);return jI(U,T,Q),T}}function DT(W){if(W<IT)throw Error("sqrt is not defined for small field");let Y=W-q9,G=0;while(Y%TW===k9)Y/=TW,G++;let X=TW,J=bJ(W);while(fC(J,X)===1)if(X++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return KT;let Z=J.pow(X,Y),V=(Y+q9)/TW;return function(U,Q){if(U.is0(Q))return Q;if(fC(U,Q)!==1)throw Error("Cannot find square root");let H=G,N=U.mul(U.ONE,Z),A=U.pow(Q,Y),q=U.pow(Q,V);while(!U.eql(A,U.ONE)){if(U.is0(A))return U.ZERO;let z=1,w=U.sqr(A);while(!U.eql(w,U.ONE))if(z++,w=U.sqr(w),z===H)throw Error("Cannot find square root");let D=q9<<BigInt(H-z-1),T=U.pow(N,D);H=z,N=U.sqr(T),A=U.mul(A,N),q=U.mul(q,T)}return q}}function wu(W){if(W%zT===IT)return KT;if(W%jT===wT)return Iu;if(W%OT===Au)return zu(W);return DT(W)}var ju=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ou(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=ju.reduce((X,J)=>{return X[J]="function",X},Y);return wI(W,G),W}function Ku(W,Y,G){if(G<k9)throw Error("invalid exponent, negatives unsupported");if(G===k9)return W.ONE;if(G===q9)return Y;let X=W.ONE,J=Y;while(G>k9){if(G&q9)X=W.mul(X,J);J=W.sqr(J),G>>=q9}return X}function CT(W,Y,G=!1){let X=Array(Y.length).fill(G?W.ZERO:void 0),J=Y.reduce((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return Y.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=W.mul(V,X[Q]),W.mul(V,U)},Z),X}function fC(W,Y){let G=(W.ORDER-q9)/TW,X=W.pow(Y,G),J=W.eql(X,W.ONE),Z=W.eql(X,W.ZERO),V=W.eql(X,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function TT(W,Y){if(Y!==void 0)XI(Y);let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function bJ(W,Y,G=!1,X={}){if(W<=k9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof Y==="object"&&Y!=null){if(X.sqrt||G)throw Error("cannot specify opts in two arguments");let q=Y;if(q.BITS)J=q.BITS;if(q.sqrt)Z=q.sqrt;if(typeof q.isLE==="boolean")G=q.isLE;if(typeof q.modFromBytes==="boolean")V=q.modFromBytes;U=q.allowedLengths}else{if(typeof Y==="number")J=Y;if(X.sqrt)Z=X.sqrt}let{nBitLength:Q,nByteLength:H}=TT(W,J);if(H>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let N,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:H,MASK:hJ(Q),ZERO:k9,ONE:q9,allowedLengths:U,create:(q)=>D5(q,W),isValid:(q)=>{if(typeof q!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof q);return k9<=q&&q<W},is0:(q)=>q===k9,isValidNot0:(q)=>!A.is0(q)&&A.isValid(q),isOdd:(q)=>(q&q9)===q9,neg:(q)=>D5(-q,W),eql:(q,z)=>q===z,sqr:(q)=>D5(q*q,W),add:(q,z)=>D5(q+z,W),sub:(q,z)=>D5(q-z,W),mul:(q,z)=>D5(q*z,W),pow:(q,z)=>Ku(A,q,z),div:(q,z)=>D5(q*mC(z,W),W),sqrN:(q)=>q*q,addN:(q,z)=>q+z,subN:(q,z)=>q-z,mulN:(q,z)=>q*z,inv:(q)=>mC(q,W),sqrt:Z||((q)=>{if(!N)N=wu(W);return N(A,q)}),toBytes:(q)=>G?qT(q,H):MQ(q,H),fromBytes:(q,z=!0)=>{if(U){if(!U.includes(q.length)||q.length>H)throw Error("Field.fromBytes: expected "+U+" bytes, got "+q.length);let D=new Uint8Array(H);D.set(q,G?0:D.length-q.length),q=D}if(q.length!==H)throw Error("Field.fromBytes: expected "+H+" bytes, got "+q.length);let w=G?NT(q):HG(q);if(V)w=D5(w,W);if(!z){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(q)=>CT(A,q),cmov:(q,z,w)=>w?z:q});return Object.freeze(A)}function RT(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function MT(W){let Y=RT(W);return Y+Math.ceil(Y/2)}function PT(W,Y,G=!1){let X=W.length,J=RT(Y),Z=MT(Y);if(X<16||X<Z||X>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+X);let V=G?NT(W):HG(W),U=D5(V,Y-q9)+q9;return G?qT(U,J):MQ(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var UG=BigInt(0),RW=BigInt(1);function wQ(W,Y){let G=Y.negate();return W?G:Y}function iA(W,Y){let G=CT(W.Fp,Y.map((X)=>X.Z));return Y.map((X,J)=>W.fromAffine(X.toAffine(G[J])))}function LT(W,Y){if(!Number.isSafeInteger(W)||W<=0||W>Y)throw Error("invalid window size, expected [1.."+Y+"], got W="+W)}function rA(W,Y){LT(W,Y);let G=Math.ceil(Y/W)+1,X=2**(W-1),J=2**W,Z=hJ(W),V=BigInt(W);return{windows:G,windowSize:X,mask:Z,maxNumber:J,shiftBy:V}}function cC(W,Y,G){let{windowSize:X,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>X)U-=Z,Q+=RW;let H=Y*X,N=H+Math.abs(U)-1,A=U===0,q=U<0,z=Y%2!==0;return{nextN:Q,offset:N,isZero:A,isNeg:q,isNegF:z,offsetF:H}}function Du(W,Y){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,X)=>{if(!(G instanceof Y))throw Error("invalid point at index "+X)})}function Cu(W,Y){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,X)=>{if(!Y.isValid(G))throw Error("invalid scalar at index "+X)})}var aA=new WeakMap,BT=new WeakMap;function sA(W){return BT.get(W)||1}function pC(W){if(W!==UG)throw Error("invalid wNAF")}class ET{constructor(W,Y){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=Y}_unsafeLadder(W,Y,G=this.ZERO){let X=W;while(Y>UG){if(Y&RW)G=G.add(X);X=X.double(),Y>>=RW}return G}precomputeWindow(W,Y){let{windows:G,windowSize:X}=rA(Y,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<X;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,Y,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let X=this.ZERO,J=this.BASE,Z=rA(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:H,isNeg:N,isNegF:A,offsetF:q}=cC(G,V,Z);if(G=U,H)J=J.add(wQ(A,Y[q]));else X=X.add(wQ(N,Y[Q]))}return pC(G),{p:X,f:J}}wNAFUnsafe(W,Y,G,X=this.ZERO){let J=rA(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===UG)break;let{nextN:V,offset:U,isZero:Q,isNeg:H}=cC(G,Z,J);if(G=V,Q)continue;else{let N=Y[U];X=X.add(H?N.negate():N)}}return pC(G),X}getPrecomputes(W,Y,G){let X=aA.get(Y);if(!X){if(X=this.precomputeWindow(Y,W),W!==1){if(typeof G==="function")X=G(X);aA.set(Y,X)}}return X}cached(W,Y,G){let X=sA(W);return this.wNAF(X,this.getPrecomputes(X,W,G),Y)}unsafe(W,Y,G,X){let J=sA(W);if(J===1)return this._unsafeLadder(W,Y,X);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),Y,X)}createCache(W,Y){LT(Y,this.bits),BT.set(W,Y),aA.delete(W)}hasCache(W){return sA(W)!==1}}function Tu(W,Y,G,X){let J=Y,Z=W.ZERO,V=W.ZERO;while(G>UG||X>UG){if(G&RW)Z=Z.add(J);if(X&RW)V=V.add(J);J=J.double(),G>>=RW,X>>=RW}return{p1:Z,p2:V}}function Ru(W,Y,G,X){Du(G,W),Cu(X,Y);let J=G.length,Z=X.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=AT(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let H=hJ(Q),N=Array(Number(H)+1).fill(V),A=Math.floor((Y.BITS-1)/Q)*Q,q=V;for(let z=A;z>=0;z-=Q){N.fill(V);for(let D=0;D<Z;D++){let T=X[D],x=Number(T>>BigInt(z)&H);N[x]=N[x].add(G[D])}let w=V;for(let D=N.length-1,T=V;D>0;D--)T=T.add(N[D]),w=w.add(T);if(q=q.add(w),z!==0)for(let D=0;D<Q;D++)q=q.double()}return q}function lC(W,Y,G){if(Y){if(Y.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return Ou(Y),Y}else return bJ(W,{isLE:G})}function Mu(W,Y,G={},X){if(X===void 0)X=W==="edwards";if(!Y||typeof Y!=="object")throw Error(`expected valid ${W} CURVE object`);for(let U of["p","n","h"]){let Q=Y[U];if(!(typeof Q==="bigint"&&Q>UG))throw Error(`CURVE.${U} must be positive bigint`)}let J=lC(Y.p,G.Fp,X),Z=lC(Y.n,G.Fn,X),V=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let U of V)if(!J.isValid(Y[U]))throw Error(`CURVE.${U} must be valid field element of CURVE.Fp`);return Y=Object.freeze(Object.assign({},Y)),{CURVE:Y,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var dC=(W,Y)=>(W+(W>=0?Y:-Y)/FT)/Y;function Pu(W,Y,G){let[[X,J],[Z,V]]=Y,U=dC(V*W,G),Q=dC(-J*W,G),H=W-U*X-Q*Z,N=-U*J-Q*V,A=H<X4,q=N<X4;if(A)H=-H;if(q)N=-N;let z=hJ(Math.ceil(AT(G)/2))+ZG;if(H<X4||H>=z||N<X4||N>=z)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}function UI(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function tA(W,Y){let G={};for(let X of Object.keys(Y))G[X]=W[X]===void 0?Y[X]:W[X];if(zQ(G.lowS,"lowS"),zQ(G.prehash,"prehash"),G.format!==void 0)UI(G.format);return G}class $T extends Error{constructor(W=""){super(W)}}var G4={Err:$T,_tlv:{encode:(W,Y)=>{let{Err:G}=G4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length&1)throw new G("tlv.encode: unpadded data");let X=Y.length/2,J=WQ(X);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=X>127?WQ(J.length/2|128):"";return WQ(W)+Z+J+Y},decode(W,Y){let{Err:G}=G4,X=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length<2||Y[X++]!==W)throw new G("tlv.decode: wrong tlv");let J=Y[X++],Z=!!(J&128),V=0;if(!Z)V=J;else{let Q=J&127;if(!Q)throw new G("tlv.decode(long): indefinite length not supported");if(Q>4)throw new G("tlv.decode(long): byte length is too big");let H=Y.subarray(X,X+Q);if(H.length!==Q)throw new G("tlv.decode: length bytes not complete");if(H[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let N of H)V=V<<8|N;if(X+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=Y.subarray(X,X+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:Y.subarray(X+V)}}},_int:{encode(W){let{Err:Y}=G4;if(W<X4)throw new Y("integer: negative integers are not allowed");let G=WQ(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new Y("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:Y}=G4;if(W[0]&128)throw new Y("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new Y("invalid signature integer: unnecessary leading zero");return HG(W)}},toSig(W){let{Err:Y,_int:G,_tlv:X}=G4,J=b8("signature",W),{v:Z,l:V}=X.decode(48,J);if(V.length)throw new Y("invalid signature: left bytes after parsing");let{v:U,l:Q}=X.decode(2,Z),{v:H,l:N}=X.decode(2,Q);if(N.length)throw new Y("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(H)}},hexFromSig(W){let{_tlv:Y,_int:G}=G4,X=Y.encode(2,G.encode(W.r)),J=Y.encode(2,G.encode(W.s)),Z=X+J;return Y.encode(48,Z)}},X4=BigInt(0),ZG=BigInt(1),FT=BigInt(2),YQ=BigInt(3),Lu=BigInt(4);function MW(W,Y){let{BYTES:G}=W,X;if(typeof Y==="bigint")X=Y;else{let J=b8("private key",Y);try{X=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof Y}`)}}if(!W.isValidNot0(X))throw Error("invalid private key: out of range [1..N-1]");return X}function Bu(W,Y={}){let G=Mu("weierstrass",W,Y),{Fp:X,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;wI(Y,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=Y;if(Q){if(!X.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let H=xT(X,J);function N(){if(!X.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(k,l,B){let{x:$,y:h}=l.toAffine(),a=X.toBytes($);if(zQ(B,"isCompressed"),B){N();let n=!X.isOdd(h);return z7(ST(n),a)}else return z7(Uint8Array.of(4),a,X.toBytes(h))}function q(k){CW(k,void 0,"Point");let{publicKey:l,publicKeyUncompressed:B}=H,$=k.length,h=k[0],a=k.subarray(1);if($===l&&(h===2||h===3)){let n=X.fromBytes(a);if(!X.isValid(n))throw Error("bad point: is not on curve, wrong x");let E=D(n),P;try{P=X.sqrt(E)}catch(M){let F=M instanceof Error?": "+M.message:"";throw Error("bad point: is not on curve, sqrt error"+F)}N();let v=X.isOdd(P);if((h&1)===1!==v)P=X.neg(P);return{x:n,y:P}}else if($===B&&h===4){let n=X.BYTES,E=X.fromBytes(a.subarray(0,n)),P=X.fromBytes(a.subarray(n,n*2));if(!T(E,P))throw Error("bad point: is not on curve");return{x:E,y:P}}else throw Error(`bad point: got length ${$}, expected compressed=${l} or uncompressed=${B}`)}let z=Y.toBytes||A,w=Y.fromBytes||q;function D(k){let l=X.sqr(k),B=X.mul(l,k);return X.add(X.add(B,X.mul(k,Z.a)),Z.b)}function T(k,l){let B=X.sqr(l),$=D(k);return X.eql(B,$)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=X.mul(X.pow(Z.a,YQ),Lu),g=X.mul(X.sqr(Z.b),BigInt(27));if(X.is0(X.add(x,g)))throw Error("bad curve params: a or b");function f(k,l,B=!1){if(!X.isValid(l)||B&&X.is0(l))throw Error(`bad point coordinate ${k}`);return l}function y(k){if(!(k instanceof u))throw Error("ProjectivePoint expected")}function p(k){if(!Q||!Q.basises)throw Error("no endo");return Pu(k,Q.basises,J.ORDER)}let b=bC((k,l)=>{let{X:B,Y:$,Z:h}=k;if(X.eql(h,X.ONE))return{x:B,y:$};let a=k.is0();if(l==null)l=a?X.ONE:X.inv(h);let n=X.mul(B,l),E=X.mul($,l),P=X.mul(h,l);if(a)return{x:X.ZERO,y:X.ZERO};if(!X.eql(P,X.ONE))throw Error("invZ was invalid");return{x:n,y:E}}),m=bC((k)=>{if(k.is0()){if(Y.allowInfinityPoint&&!X.is0(k.Y))return;throw Error("bad point: ZERO")}let{x:l,y:B}=k.toAffine();if(!X.isValid(l)||!X.isValid(B))throw Error("bad point: x or y not field elements");if(!T(l,B))throw Error("bad point: equation left != right");if(!k.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function W0(k,l,B,$,h){return B=new u(X.mul(B.X,k),B.Y,B.Z),l=wQ($,l),B=wQ(h,B),l.add(B)}class u{constructor(k,l,B){this.X=f("x",k),this.Y=f("y",l,!0),this.Z=f("z",B),Object.freeze(this)}static CURVE(){return Z}static fromAffine(k){let{x:l,y:B}=k||{};if(!k||!X.isValid(l)||!X.isValid(B))throw Error("invalid affine point");if(k instanceof u)throw Error("projective point not allowed");if(X.is0(l)&&X.is0(B))return u.ZERO;return new u(l,B,X.ONE)}static fromBytes(k){let l=u.fromAffine(w(CW(k,void 0,"point")));return l.assertValidity(),l}static fromHex(k){return u.fromBytes(b8("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,l=!0){if(A0.createCache(this,k),!l)this.multiply(YQ);return this}assertValidity(){m(this)}hasEvenY(){let{y:k}=this.toAffine();if(!X.isOdd)throw Error("Field doesn't support isOdd");return!X.isOdd(k)}equals(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.eql(X.mul(l,n),X.mul(h,$)),P=X.eql(X.mul(B,n),X.mul(a,$));return E&&P}negate(){return new u(this.X,X.neg(this.Y),this.Z)}double(){let{a:k,b:l}=Z,B=X.mul(l,YQ),{X:$,Y:h,Z:a}=this,n=X.ZERO,E=X.ZERO,P=X.ZERO,v=X.mul($,$),M=X.mul(h,h),F=X.mul(a,a),c=X.mul($,h);return c=X.add(c,c),P=X.mul($,a),P=X.add(P,P),n=X.mul(k,P),E=X.mul(B,F),E=X.add(n,E),n=X.sub(M,E),E=X.add(M,E),E=X.mul(n,E),n=X.mul(c,n),P=X.mul(B,P),F=X.mul(k,F),c=X.sub(v,F),c=X.mul(k,c),c=X.add(c,P),P=X.add(v,v),v=X.add(P,v),v=X.add(v,F),v=X.mul(v,c),E=X.add(E,v),F=X.mul(h,a),F=X.add(F,F),v=X.mul(F,c),n=X.sub(n,v),P=X.mul(F,M),P=X.add(P,P),P=X.add(P,P),new u(n,E,P)}add(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.ZERO,P=X.ZERO,v=X.ZERO,M=Z.a,F=X.mul(Z.b,YQ),c=X.mul(l,h),t=X.mul(B,a),Y0=X.mul($,n),$0=X.add(l,B),S0=X.add(h,a);$0=X.mul($0,S0),S0=X.add(c,t),$0=X.sub($0,S0),S0=X.add(l,$);let x0=X.add(h,n);return S0=X.mul(S0,x0),x0=X.add(c,Y0),S0=X.sub(S0,x0),x0=X.add(B,$),E=X.add(a,n),x0=X.mul(x0,E),E=X.add(t,Y0),x0=X.sub(x0,E),v=X.mul(M,S0),E=X.mul(F,Y0),v=X.add(E,v),E=X.sub(t,v),v=X.add(t,v),P=X.mul(E,v),t=X.add(c,c),t=X.add(t,c),Y0=X.mul(M,Y0),S0=X.mul(F,S0),t=X.add(t,Y0),Y0=X.sub(c,Y0),Y0=X.mul(M,Y0),S0=X.add(S0,Y0),c=X.mul(t,S0),P=X.add(P,c),c=X.mul(x0,S0),E=X.mul($0,E),E=X.sub(E,c),c=X.mul($0,t),v=X.mul(x0,v),v=X.add(v,c),new u(E,P,v)}subtract(k){return this.add(k.negate())}is0(){return this.equals(u.ZERO)}multiply(k){let{endo:l}=Y;if(!J.isValidNot0(k))throw Error("invalid scalar: out of range");let B,$,h=(a)=>A0.cached(this,a,(n)=>iA(u,n));if(l){let{k1neg:a,k1:n,k2neg:E,k2:P}=p(k),{p:v,f:M}=h(n),{p:F,f:c}=h(P);$=M.add(c),B=W0(l.beta,v,F,a,E)}else{let{p:a,f:n}=h(k);B=a,$=n}return iA(u,[B,$])[0]}multiplyUnsafe(k){let{endo:l}=Y,B=this;if(!J.isValid(k))throw Error("invalid scalar: out of range");if(k===X4||B.is0())return u.ZERO;if(k===ZG)return B;if(A0.hasCache(this))return this.multiply(k);if(l){let{k1neg:$,k1:h,k2neg:a,k2:n}=p(k),{p1:E,p2:P}=Tu(u,B,h,n);return W0(l.beta,E,P,$,a)}else return A0.unsafe(B,k)}multiplyAndAddUnsafe(k,l,B){let $=this.multiplyUnsafe(l).add(k.multiplyUnsafe(B));return $.is0()?void 0:$}toAffine(k){return b(this,k)}isTorsionFree(){let{isTorsionFree:k}=Y;if(V===ZG)return!0;if(k)return k(u,this);return A0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:k}=Y;if(V===ZG)return this;if(k)return k(u,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(k=!0){return zQ(k,"isCompressed"),this.assertValidity(),z(u,this,k)}toHex(k=!0){return JG(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return iA(u,k)}static msm(k,l){return Ru(u,J,k,l)}static fromPrivateKey(k){return u.BASE.multiply(MW(J,k))}}u.BASE=new u(Z.Gx,Z.Gy,X.ONE),u.ZERO=new u(X.ZERO,X.ONE,X.ZERO),u.Fp=X,u.Fn=J;let J0=J.BITS,A0=new ET(u,Y.endo?Math.ceil(J0/2):J0);return u.BASE.precompute(8),u}function ST(W){return Uint8Array.of(W?2:3)}function xT(W,Y){return{secretKey:Y.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*Y.BYTES}}function Eu(W,Y={}){let{Fn:G}=W,X=Y.randomBytes||RQ,J=Object.assign(xT(W.Fp,G),{seed:MT(G.ORDER)});function Z(q){try{return!!MW(G,q)}catch(z){return!1}}function V(q,z){let{publicKey:w,publicKeyUncompressed:D}=J;try{let T=q.length;if(z===!0&&T!==w)return!1;if(z===!1&&T!==D)return!1;return!!W.fromBytes(q)}catch(T){return!1}}function U(q=X(J.seed)){return PT(CW(q,J.seed,"seed"),G.ORDER)}function Q(q,z=!0){return W.BASE.multiply(MW(G,q)).toBytes(z)}function H(q){let z=U(q);return{secretKey:z,publicKey:Q(z)}}function N(q){if(typeof q==="bigint")return!1;if(q instanceof W)return!0;let{secretKey:z,publicKey:w,publicKeyUncompressed:D}=J;if(G.allowedLengths||z===w)return;let T=b8("key",q).length;return T===w||T===D}function A(q,z,w=!0){if(N(q)===!0)throw Error("first arg must be private key");if(N(z)===!1)throw Error("second arg must be public key");let D=MW(G,q);return W.fromHex(z).multiply(D).toBytes(w)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:H,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(q)=>MW(G,q),precompute(q=8,z=W.BASE){return z.precompute(q,!1)}},lengths:J})}function $u(W,Y,G={}){XT(Y),wI(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let X=G.randomBytes||RQ,J=G.hmac||((B,...$)=>QT(Y,B,z7(...$))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z}=Eu(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},D="compact";function T(B){let $=U>>ZG;return B>$}function x(B,$){if(!V.isValidNot0($))throw Error(`invalid signature ${B}: out of range 1..Point.Fn.ORDER`);return $}function g(B,$){UI($);let h=z.signature,a=$==="compact"?h:$==="recovered"?h+1:void 0;return CW(B,a,`${$} signature`)}class f{constructor(B,$,h){if(this.r=x("r",B),this.s=x("s",$),h!=null)this.recovery=h;Object.freeze(this)}static fromBytes(B,$=D){g(B,$);let h;if($==="der"){let{r:P,s:v}=G4.toSig(CW(B));return new f(P,v)}if($==="recovered")h=B[0],$="compact",B=B.subarray(1);let a=V.BYTES,n=B.subarray(0,a),E=B.subarray(a,a*2);return new f(V.fromBytes(n),V.fromBytes(E),h)}static fromHex(B,$){return this.fromBytes(IQ(B),$)}addRecoveryBit(B){return new f(this.r,this.s,B)}recoverPublicKey(B){let $=Z.ORDER,{r:h,s:a,recovery:n}=this;if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");if(U*FT<$&&n>1)throw Error("recovery id is ambiguous for h>1 curve");let E=n===2||n===3?h+U:h;if(!Z.isValid(E))throw Error("recovery id 2 or 3 invalid");let P=Z.toBytes(E),v=W.fromBytes(z7(ST((n&1)===0),P)),M=V.inv(E),F=p(b8("msgHash",B)),c=V.create(-F*M),t=V.create(a*M),Y0=W.BASE.multiplyUnsafe(c).add(v.multiplyUnsafe(t));if(Y0.is0())throw Error("point at infinify");return Y0.assertValidity(),Y0}hasHighS(){return T(this.s)}toBytes(B=D){if(UI(B),B==="der")return IQ(G4.hexFromSig(this));let $=V.toBytes(this.r),h=V.toBytes(this.s);if(B==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return z7(Uint8Array.of(this.recovery),$,h)}return z7($,h)}toHex(B){return JG(this.toBytes(B))}assertValidity(){}static fromCompact(B){return f.fromBytes(b8("sig",B),"compact")}static fromDER(B){return f.fromBytes(b8("sig",B),"der")}normalizeS(){return this.hasHighS()?new f(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return JG(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return JG(this.toBytes("compact"))}}let y=G.bits2int||function(B){if(B.length>8192)throw Error("input is too large");let $=HG(B),h=B.length*8-Q;return h>0?$>>BigInt(h):$},p=G.bits2int_modN||function(B){return V.create(y(B))},b=hJ(Q);function m(B){return Hu("num < 2^"+Q,B,X4,b),V.toBytes(B)}function W0(B,$){return CW(B,void 0,"message"),$?CW(Y(B),void 0,"prehashed message"):B}function u(B,$,h){if(["recovered","canonical"].some((Y0)=>(Y0 in h)))throw Error("sign() legacy options not supported");let{lowS:a,prehash:n,extraEntropy:E}=tA(h,w);B=W0(B,n);let P=p(B),v=MW(V,$),M=[m(v),m(P)];if(E!=null&&E!==!1){let Y0=E===!0?X(z.secretKey):E;M.push(b8("extraEntropy",Y0))}let F=z7(...M),c=P;function t(Y0){let $0=y(Y0);if(!V.isValidNot0($0))return;let S0=V.inv($0),x0=W.BASE.multiply($0).toAffine(),D1=V.create(x0.x);if(D1===X4)return;let b0=V.create(S0*V.create(c+D1*v));if(b0===X4)return;let Q0=(x0.x===D1?0:2)|Number(x0.y&ZG),O0=b0;if(a&&T(b0))O0=V.neg(b0),Q0^=1;return new f(D1,O0,Q0)}return{seed:F,k2sig:t}}function J0(B,$,h={}){B=b8("message",B);let{seed:a,k2sig:n}=u(B,$,h);return Nu(Y.outputLen,V.BYTES,J)(a,n)}function A0(B){let $=void 0,h=typeof B==="string"||TQ(B),a=!h&&B!==null&&typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint";if(!h&&!a)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(a)$=new f(B.r,B.s);else if(h){try{$=f.fromBytes(b8("sig",B),"der")}catch(n){if(!(n instanceof G4.Err))throw n}if(!$)try{$=f.fromBytes(b8("sig",B),"compact")}catch(n){return!1}}if(!$)return!1;return $}function k(B,$,h,a={}){let{lowS:n,prehash:E,format:P}=tA(a,w);if(h=b8("publicKey",h),$=W0(b8("message",$),E),"strict"in a)throw Error("options.strict was renamed to lowS");let v=P===void 0?A0(B):f.fromBytes(b8("sig",B),P);if(v===!1)return!1;try{let M=W.fromBytes(h);if(n&&v.hasHighS())return!1;let{r:F,s:c}=v,t=p($),Y0=V.inv(c),$0=V.create(t*Y0),S0=V.create(F*Y0),x0=W.BASE.multiplyUnsafe($0).add(M.multiplyUnsafe(S0));if(x0.is0())return!1;return V.create(x0.x)===F}catch(M){return!1}}function l(B,$,h={}){let{prehash:a}=tA(h,w);return $=W0($,a),f.fromBytes(B,"recovered").recoverPublicKey($).toBytes()}return Object.freeze({keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z,Point:W,sign:J0,verify:k,recoverPublicKey:l,Signature:f,hash:Y})}function Fu(W){let Y={a:W.a,b:W.b,p:W.Fp.ORDER,n:W.n,h:W.h,Gx:W.Gx,Gy:W.Gy},G=W.Fp,X=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=bJ(Y.n,{BITS:W.nBitLength,allowedLengths:X,modFromBytes:W.wrapPrivateKey}),Z={Fp:G,Fn:J,allowInfinityPoint:W.allowInfinityPoint,endo:W.endo,isTorsionFree:W.isTorsionFree,clearCofactor:W.clearCofactor,fromBytes:W.fromBytes,toBytes:W.toBytes};return{CURVE:Y,curveOpts:Z}}function Su(W){let{CURVE:Y,curveOpts:G}=Fu(W),X={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:Y,curveOpts:G,hash:W.hash,ecdsaOpts:X}}function xu(W,Y){let G=Y.Point;return Object.assign({},Y,{ProjectivePoint:G,CURVE:Object.assign({},W,TT(G.Fn.ORDER,G.Fn.BITS))})}function ku(W){let{CURVE:Y,curveOpts:G,hash:X,ecdsaOpts:J}=Su(W),Z=Bu(Y,G),V=$u(Z,X,J);return xu(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _u(W,Y){let G=(X)=>ku({...W,hash:X});return{...G(Y),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var QG={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},vu=BigInt(0),oC=BigInt(1),QI=BigInt(2);function gu(W){let Y=QG.p,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=O5(N,G,Y)*N%Y,q=O5(A,G,Y)*N%Y,z=O5(q,QI,Y)*H%Y,w=O5(z,J,Y)*z%Y,D=O5(w,Z,Y)*w%Y,T=O5(D,U,Y)*D%Y,x=O5(T,Q,Y)*T%Y,g=O5(x,U,Y)*D%Y,f=O5(g,G,Y)*N%Y,y=O5(f,V,Y)*w%Y,p=O5(y,X,Y)*H%Y,b=O5(p,QI,Y);if(!jQ.eql(jQ.sqr(b),W))throw Error("Cannot find square root");return b}var jQ=bJ(QG.p,{sqrt:gu}),kT=_u({...QG,Fp:jQ,lowS:!0,endo:yu},JI),nC={};function OQ(W,...Y){let G=nC[W];if(G===void 0){let X=JI(ZT(W));G=z7(X,X),nC[W]=G}return JI(z7(G,...Y))}var OI=(W)=>W.toBytes(!0).slice(1),NG=(()=>kT.Point)(),KI=(W)=>W%QI===vu;function HI(W){let{Fn:Y,BASE:G}=NG,X=MW(Y,W),J=G.multiply(X);return{scalar:KI(J.y)?X:Y.neg(X),bytes:OI(J)}}function _T(W){let Y=jQ;if(!Y.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=Y.create(W*W),X=Y.create(G*W+BigInt(7)),J=Y.sqrt(X);if(!KI(J))J=Y.neg(J);let Z=NG.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var gJ=HG;function yT(...W){return NG.Fn.create(gJ(OQ("BIP0340/challenge",...W)))}function iC(W){return HI(W).bytes}function uu(W,Y,G=RQ(32)){let{Fn:X}=NG,J=b8("message",W),{bytes:Z,scalar:V}=HI(Y),U=b8("auxRand",G,32),Q=X.toBytes(V^gJ(OQ("BIP0340/aux",U))),H=OQ("BIP0340/nonce",Q,Z,J),{bytes:N,scalar:A}=HI(H),q=yT(N,Z,J),z=new Uint8Array(64);if(z.set(N,0),z.set(X.toBytes(X.create(A+q*V)),32),!vT(z,J,Z))throw Error("sign: Invalid signature produced");return z}function vT(W,Y,G){let{Fn:X,BASE:J}=NG,Z=b8("signature",W,64),V=b8("message",Y),U=b8("publicKey",G,32);try{let Q=_T(gJ(U)),H=gJ(Z.subarray(0,32));if(!VI(H,oC,QG.p))return!1;let N=gJ(Z.subarray(32,64));if(!VI(N,oC,QG.n))return!1;let A=yT(X.toBytes(H),OI(Q),V),q=J.multiplyUnsafe(N).add(Q.multiplyUnsafe(X.neg(A))),{x:z,y:w}=q.toAffine();if(q.is0()||!KI(w)||z!==H)return!1;return!0}catch(Q){return!1}}var DI=(()=>{let W=(G=RQ(48))=>{return PT(G,QG.n)};kT.utils.randomSecretKey;function Y(G){let X=W(G);return{secretKey:X,publicKey:iC(X)}}return{keygen:Y,getPublicKey:iC,sign:uu,verify:vT,Point:NG,utils:{randomSecretKey:W,randomPrivateKey:W,taggedHash:OQ,lift_x:_T,pointToBytes:OI,numberToBytesBE:MQ,bytesToNumberBE:HG,mod:D5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),hu=new TextEncoder,bu=new TextDecoder,PW=(W)=>hu.encode(W),xJ=(W)=>bu.decode(W),NI=(W)=>Array.from(W,(Y)=>Y.toString(16).padStart(2,"0")).join(""),w7=JSON.stringify,KQ=JSON.parse,gT=(W,Y=Number.MAX_SAFE_INTEGER)=>W.split("").reduce((G,X)=>G+X.charCodeAt(0),0)%Y,CI="AES-GCM",mu={},uT="$",hT=",",fu=(W)=>{let Y=new Uint8Array(W),G=32768,X="";for(let J=0;J<Y.length;J+=32768)X+=String.fromCharCode(...Y.subarray(J,J+32768));return btoa(X)},cu=(W)=>Uint8Array.from(atob(W),(Y)=>Y.charCodeAt(0)).buffer,GQ=(W)=>mu[W]??=crypto.subtle.digest("SHA-1",PW(W)).then((Y)=>{let G=new Uint8Array(Y),X="";for(let J of G)X+=J.toString(36);return X}),pu=async(W,Y,G)=>{let X=await crypto.subtle.digest("SHA-256",PW(`${W}:${Y}:${G}`));return crypto.subtle.importKey("raw",X,{name:CI},!1,["encrypt","decrypt"])},lu=async(W,Y)=>{let G=crypto.getRandomValues(new Uint8Array(12)),X=await W,J=await crypto.subtle.encrypt({name:CI,iv:G},X,PW(Y));return`${G.join(hT)}${uT}${fu(J)}`},du=async(W,Y)=>{let[G,X]=Y.split(uT);if(!G||!X)throw Error("Invalid encrypted payload format");let J=Uint8Array.from(G.split(hT),Number),Z=await W,V=await crypto.subtle.decrypt({name:CI,iv:J},Z,cu(X));return xJ(V)},K5="GenosRTC",TI=(W,Y)=>Array.from({length:W},Y),DQ=(W)=>Array.from(crypto.getRandomValues(new Uint8Array(W)),(Y)=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Y%62]).join(""),A8=typeof sessionStorage<"u"?sessionStorage.__genosrtcId??=DQ(20):DQ(20),XG=Promise.all.bind(Promise),ou=typeof window<"u",{entries:nu,fromEntries:bT,keys:xe}=Object,iu=()=>{},Y4=(W)=>Error(`GenosRTC: ${W}`),XQ=(...W)=>W.join("@"),ru=(W,Y)=>{let G=[...W],X=G.length,J=()=>{let Z=Math.sin(Y++)*1e4;return Z-Math.floor(Z)};while(X){let Z=Math.floor(J()*X--);[G[X],G[Z]]=[G[Z],G[X]]}return G},au=5000,rC="icegatheringstatechange",aC="offer",su="answer",tu=[...TI(3,(W,Y)=>`stun:stun${Y||""}.l.google.com:19302`),"stun:stun.cloudflare.com:3478"].map((W)=>({urls:W})),sC=(W,{rtcConfig:Y,rtcPolyfill:G,turnConfig:X})=>{let J=new(G||RTCPeerConnection)({iceServers:[...tu,...X||[]],...Y}),Z={},V=!1,U=!1,Q,H=(q)=>Object.assign(q,{binaryType:"arraybuffer",bufferedAmountLowThreshold:65535,onmessage:(z)=>Z.data?.(z.data),onopen:()=>Z.connect?.(),onclose:()=>Z.close?.(),onerror:(z)=>!z?.error?.message?.includes("User-Initiated Abort")&&Z.error?.(z)}),N=()=>Promise.race([new Promise((q)=>{let z=()=>{if(J.iceGatheringState==="complete")J.removeEventListener(rC,z),q()};J.addEventListener(rC,z),z()}),new Promise((q)=>setTimeout(q,au))]).then(()=>({type:J.localDescription.type,sdp:J.localDescription.sdp.replace(/a=ice-options:trickle\s\n/g,"")}));if(W?H(Q=J.createDataChannel("data")):J.ondatachannel=({channel:q})=>H(Q=q),J.onnegotiationneeded=async()=>{try{V=!0,await J.setLocalDescription(),Z.signal?.(await N())}catch(q){Z.error?.(q)}finally{V=!1}},J.onconnectionstatechange=()=>{if(["disconnected","failed","closed"].includes(J.connectionState))Z.close?.()},J.ontrack=(q)=>{Z.track?.(q.track,q.streams[0]),Z.stream?.(q.streams[0])},J.onremovestream=(q)=>Z.stream?.(q.stream),W&&!J.canTrickleIceCandidates)J.onnegotiationneeded();let A=()=>J.getSenders();return{created:Date.now(),connection:J,get channel(){return Q},get isDead(){return J.connectionState==="closed"},async signal(q){if(Q?.readyState==="open"&&!q.sdp?.includes("a=rtpmap"))return;try{if(q.type===aC){if(V||J.signalingState!=="stable"&&!U){if(W)return;await XG([J.setLocalDescription({type:"rollback"}),J.setRemoteDescription(q)])}else await J.setRemoteDescription(q);await J.setLocalDescription();let z=await N();return Z.signal?.(z),z}if(q.type===su){U=!0;try{await J.setRemoteDescription(q)}finally{U=!1}}}catch(z){Z.error?.(z)}},sendData:(q)=>{if(Q?.readyState==="open")Q.send(q)},destroy:()=>{Q?.close(),J.close(),V=U=!1},setHandlers:(q)=>Object.assign(Z,q),offerPromise:W?new Promise((q)=>Z.signal=(z)=>z.type===aC&&q(z)):Promise.resolve(),addStream:(q)=>q.getTracks().forEach((z)=>J.addTrack(z,q)),removeStream:(q)=>A().filter((z)=>q.getTracks().includes(z.track)).forEach((z)=>J.removeTrack(z)),addTrack:(q,z)=>J.addTrack(q,z),removeTrack:(q)=>{let z=A().find((w)=>w.track===q);if(z)J.removeTrack(z)},replaceTrack:(q,z)=>A().find((w)=>w.track===q)?.replaceTrack(z)}},eu=Object.getPrototypeOf(Uint8Array),UQ=12,mT=0,QQ=mT+UQ,HQ=QQ+1,kJ=HQ+1,_J=kJ+1,FJ=16384-_J,JQ=255,eA="bufferedamountlow",GG=(W)=>`@_${W}`,tC=GG("ping"),WI=100,Wh=3,Yh=200,Gh=512,eC=(W,Y)=>new Response(new Blob([W]).stream().pipeThrough(new Y("deflate"))).arrayBuffer().then((G)=>new Uint8Array(G)),Xh=(W,Y,G,X)=>{let J=new Map,Z=new Map,V=new Map,U={},Q={},H={},N={},A=new Map,q=new Map,z=Promise.resolve(),w=(M,F)=>{if(!A.has(M))A.set(M,new Set);A.get(M).add(F)},D=(M,F)=>A.get(M)?.delete(F),T=(M,...F)=>A.get(M)?.forEach((c)=>c(...F)),x=(M,F)=>{let c=M?Array.isArray(M)?M:[M]:J.keys();return Array.from(c,(t)=>{let Y0=J.get(t);if(!Y0)return console.warn(`${K5}: no peer with id ${t}`),null;return F(t,Y0)}).filter(Boolean)},g=(M)=>{if(!J.has(M))return;J.delete(M),q.delete(M),P.delete(M),delete U[M],delete Q[M],delete H[M],delete N[M],T("peer:leave",M),Y(M)},f=(M)=>new Promise((F,c)=>{let t=setTimeout(()=>{M.removeEventListener(eA,Y0),c(Error(`${K5}: bufferLow timeout`))},5000);function Y0(){clearTimeout(t),M.removeEventListener(eA,Y0),F()}M.addEventListener(eA,Y0)}),y=(M)=>{if(V.has(M))return V.get(M);if(!M)throw Y4("action type is required");let F=PW(M);if(F.byteLength>UQ)throw Y4(`\u274C "${M}" exceeds ${UQ} bytes. Use a shorter name.`);let c=new Uint8Array(UQ).map((b0,Q0)=>F[Q0]||0),t=0,Y0=new Map([["message",new Set],["progress",new Set]]),$0=(b0,Q0)=>Y0.get(b0)?.add(Q0),S0=(b0,Q0)=>Y0.get(b0)?.delete(Q0),x0=async(b0,Q0,O0,y0)=>{if(O0&&typeof O0!=="object")throw Y4("meta must be object");if(b0===void 0)throw Y4("data cannot be undefined");let X0=b0 instanceof Blob,D0=X0||b0 instanceof ArrayBuffer||b0 instanceof eu,L0=typeof b0!=="string";if(O0&&!D0)throw Y4("meta only allowed with binary");let I0=D0?new Uint8Array(X0?await b0.arrayBuffer():b0):PW(L0?w7(b0):b0),F0=0;if(!D0&&I0.byteLength>=Gh){let i1=await eC(I0,CompressionStream);if(i1.byteLength<I0.byteLength)I0=i1,F0=1}let V1=O0?PW(w7(O0)):null,H1=Math.ceil(I0.byteLength/FJ)+(O0?1:0)||1;if(H1>WI)throw Y4(`Message too large, exceeds max chunks ${WI}`);let f1=TI(H1,(i1,r0)=>{let x1=r0===H1-1,i0=O0&&r0===0,V8=i0?V1:I0.subarray(O0?(r0-1)*FJ:r0*FJ,O0?r0*FJ:(r0+1)*FJ),F8=new Uint8Array(_J+V8.byteLength);return F8.set(c),F8.set([t],QQ),F8.set([x1|i0<<1|D0<<2|L0<<3|F0<<4],HQ),F8.set([Math.round((r0+1)/H1*JQ)],kJ),F8.set(V8,_J),F8});return t=t+1&JQ,XG(x(Q0,async(i1,r0)=>{let{channel:x1}=r0;for(let i0=0;i0<H1;i0++){let V8=0;while(x1.bufferedAmount>x1.bufferedAmountLowThreshold){if(V8++>Wh)throw Y4(`${K5}: send buffer full, max retries reached for peer ${i1}`);try{await f(x1)}catch(F8){console.warn(F8.message),await new Promise(($9)=>setTimeout($9,Yh))}}if(!J.has(i1))break;r0.sendData(f1[i0]),y0?.(f1[i0][kJ]/JQ,i1,O0)}}))};Z.set(M,{listeners:Y0,send:x0});let D1={send:x0,on:$0,off:S0};return V.set(M,D1),D1},p=(M,F)=>{try{q.set(M,Date.now()),P.delete(M);let c=new Uint8Array(F),t=xJ(c.subarray(mT,QQ)).replace(/\x00/g,"");if(!Z.has(t))return console.warn(`${K5}: unregistered type (${t})`);if(t===tC){W0("",M).catch(()=>{});return}let[Y0]=c.subarray(QQ,HQ),[$0]=c.subarray(HQ,kJ),[S0]=c.subarray(kJ,_J),x0=c.subarray(_J),D1=Boolean($0&1),b0=Boolean($0&2),Q0=Boolean($0&4),O0=Boolean($0&8),y0=Boolean($0&16),X0=Z.get(t),D0=(U[M]||={})[t]||={};if(D0[Y0]?.chunks?.length>WI){console.warn(`${K5}: peer ${M} sent too many chunks for nonce ${Y0}, ignoring.`);return}let L0=D0[Y0]||={chunks:[]};if(b0)try{L0.meta=KQ(xJ(x0))}catch{console.warn(`${K5}: failed to parse meta from peer ${M} for type ${t}`);return}else L0.chunks.push(x0);if(X0.listeners.get("progress").forEach((F0)=>{try{F0(S0/JQ,M,L0.meta)}catch(V1){console.error(V1)}}),!D1)return;let I0=new Uint8Array(L0.chunks.reduce((F0,V1)=>F0+V1.byteLength,0));L0.chunks.reduce((F0,V1)=>(I0.set(V1,F0),F0+V1.byteLength),0),delete D0[Y0],z=z.then(async()=>{let F0=y0?await eC(I0,DecompressionStream):I0,V1;if(Q0)V1=F0;else if(O0)try{V1=KQ(xJ(F0))}catch{console.warn(`${K5}: failed to parse JSON message data from peer ${M} for type ${t}`);return}else V1=xJ(F0);X0.listeners.get("message").forEach((H1)=>{try{H1(V1,M,L0.meta)}catch(f1){console.error(f1)}})}).catch((F0)=>console.error(`${K5}: dispatch error from peer ${M}:`,F0))}catch(c){console.error(`${K5}: error handling data from peer ${M}:`,c)}},b=async()=>{try{await h(""),await new Promise((M)=>setTimeout(M,99))}catch(M){console.warn(`${K5}: error sending leave`,M)}for(let[M,F]of J){try{F.destroy()}catch{}J.delete(M)}clearInterval(v),G()},{send:m}=y(tC),{send:W0,on:u}=y(GG("pong")),{send:J0,on:A0}=y(GG("signal")),{send:k,on:l}=y(GG("stream")),{send:B,on:$}=y(GG("track")),{send:h,on:a}=y(GG("leave"));W((M,F)=>{let c=J.get(F);if(c===M)return;if(c){let t=()=>{};c.setHandlers({data:t,stream:t,track:t,signal:t,close:t,error:t})}J.set(F,M),q.set(F,Date.now()),P.delete(F),M.setHandlers({data:(t)=>p(F,t),stream:(t)=>{T("stream:add",t,F,H[F]),delete H[F]},track:(t,Y0)=>{T("track:add",t,Y0,F,N[F]),delete N[F]},signal:(t)=>J0(t,F),close:()=>g(F),error:(t)=>{console.error(`${K5}: peer error for ${F}`,t),g(F)}}),T("peer:join",F,X?.(F))}),u("message",(M,F)=>{Q[F]?.(),delete Q[F]}),A0("message",(M,F)=>J.get(F)?.signal(M)),l("message",(M,F)=>H[F]=M),$("message",(M,F)=>N[F]=M),a("message",(M,F)=>g(F));let n=1e4,E=20000,P=new Map,v=setInterval(()=>{let M=Date.now();for(let[F,c]of J){if(M-(q.get(F)??M)<=n)continue;let t=P.get(F);if(t===void 0)P.set(F,M),m("",F).catch(()=>{});else if(M-t>E){P.delete(F);try{c.destroy()}catch{}g(F)}}},5000);if(ou)addEventListener("beforeunload",b);return{on:w,off:D,channel:y,leave:b,ping:async(M)=>{if(!M)throw Y4("ping() requires target peer ID");let F=Date.now();return m("",M),await new Promise((c)=>Q[M]=c),Date.now()-F},getPeers:()=>bT(Array.from(J,([M,F])=>[M,F.connection])),addStream:(M,F,c)=>x(F,async(t,Y0)=>{if(c)await k(c,t);Y0.addStream(M)}),removeStream:(M,F)=>x(F,(c,t)=>t.removeStream(M)),addTrack:(M,F,c,t)=>x(c,async(Y0,$0)=>{if(t)await B(t,Y0);$0.addTrack(M,F)}),removeTrack:(M,F)=>x(F,(c,t)=>t.removeTrack(M)),replaceTrack:(M,F,c,t)=>x(c,async(Y0,$0)=>{if(t)await B(t,Y0);$0.replaceTrack(M,F)})}},Jh=5,Zh=10,Vh=2500,ZQ=57333,Uh=({init:W,subscribe:Y,announce:G,bye:X})=>{let J={},Z=!1,V,U;return(Q,H,N)=>{let{appId:A}=Q;if(J[A]?.[H])return J[A][H];if(!Q||!H||!A&&!Q.firebaseApp)throw Y4(!Q?"config required":!H?"roomId required":"appId missing");let q=iu;if(!Z){let P=W(Q);U=TI(Jh,()=>{try{return sC(!0,Q)}catch{return null}}).filter(Boolean),V=Array.isArray(P)?P:[P];let v=setInterval(()=>{U=U.filter((M)=>{let F=Date.now()-M.created<ZQ;if(!F)M.destroy();return F})},ZQ);J.offerCleanupTimer||=v,Z=!0}let z={},w={},D=new Map,T=new Map,x=new Map,g={},f=XQ(K5,A,H),y=GQ(f),p=GQ(XQ(f,A8)),b=pu(Q.password||"",A,H),m=(P)=>async(v)=>({type:v.type,sdp:await P(b,v.sdp)}),W0=m(du),u=m(lu),J0=(P)=>{return setTimeout(()=>{if(!P.isDead&&!Object.values(w).includes(P))P.destroy()},ZQ),P},A0=(P)=>{try{return J0(sC(P,Q))}catch{return null}},k=(P,v)=>{if(w[v]===P)return;P.connectedAt=Date.now(),w[v]?.destroy(),w[v]=P,q(P,v),z[v]?.forEach((M)=>M!==P&&M.destroy()),delete z[v]},l=(P,v)=>{if(w[v]===P)delete w[v]},B=(P)=>async(v,M,F)=>{let[c,t]=await XG([y,p]);if(v!==c&&v!==t)return;let{peerId:Y0,offer:$0,answer:S0,type:x0,bye:D1}=typeof M==="string"?KQ(M):M;if(D1){if(Y0&&Y0!==A8)T.delete(Y0),x.set(Y0,Date.now()),delete g[Y0];return}if(Y0&&Y0!==A8)T.set(Y0,Date.now()),x.delete(Y0);if(x0&&Y0)g[Y0]=x0;if(Y0===A8)return;if(w[Y0]){let b0=w[Y0].channel?.readyState==="open";if(!$0||b0||Date.now()-w[Y0].connectedAt<2000)return;w[Y0].destroy(),delete w[Y0]}if(Q.admit&&!Q.admit(Y0))return;if($0){if(z[Y0]?.[P]&&A8>Y0)return;let b0=A0(!1);if(!b0)return;b0.setHandlers({connect:()=>k(b0,Y0),close:()=>l(b0,Y0)});try{let Q0=await W0($0);if(b0.isDead)return;let[O0,y0]=await XG([GQ(XQ(f,Y0)),b0.signal(Q0).then(u)]);F(O0,w7({peerId:A8,answer:y0,...Q.type&&{type:Q.type}}))}catch{N?.({error:"decryption failed (offer)",appId:A,peerId:Y0,roomId:H})}}else if(S0){let b0=z[Y0]?.[P];if(!b0||b0.isDead)return;b0.setHandlers({connect:()=>k(b0,Y0),close:()=>l(b0,Y0)});try{b0.signal(await W0(S0))}catch{N?.({error:"decryption failed (answer)",appId:A,peerId:Y0,roomId:H})}}else{let b0=z[Y0]||=[];if(b0.forEach((y0,X0)=>{if(y0&&(y0.isDead||Date.now()-(y0.dialedAt??y0.created)>ZQ)){if(y0.isDead)D.set(Y0,Date.now()+30000);y0.destroy(),delete b0[X0]}}),b0[P]||b0.filter(Boolean).length>=2||D.get(Y0)>Date.now())return;if(Object.values(z).reduce((y0,X0)=>y0+X0.filter((D0)=>D0&&!D0.isDead).length,0)>=Zh)return;let Q0=U.pop(),O0=Q0?J0(Q0):A0(!0);if(!O0){D.set(Y0,Date.now()+30000);return}O0.dialedAt=Date.now(),b0[P]=O0;try{let[y0,{offer:X0}]=await XG([GQ(XQ(f,Y0)),O0.offerPromise.then(u).then((D0)=>({offer:D0}))]);O0.setHandlers({connect:()=>k(O0,Y0),close:()=>l(O0,Y0)}),F(y0,w7({peerId:A8,offer:X0,peer:O0,...Q.type&&{type:Q.type}}))}catch{if(b0[P]===O0)delete b0[P];O0.destroy()}}},$=[],h=[],a=[],n=()=>a.forEach(({relay:P,rootTopic:v})=>X?.(P,v));V.forEach(async(P,v)=>{let M=await P;if(!M)return;let[F,c]=await XG([y,p]);h[v]=Y(M,F,c,B(v)),a.push({relay:M,rootTopic:F});let t=async()=>{let Y0=await G(M,F,c);$[v]=setTimeout(t,typeof Y0==="number"?Y0:Vh)};t()}),J[A]||={};let E=Xh((P)=>q=P,(P)=>delete w[P],()=>E.onCleanup?.(),(P)=>g[P]);if(typeof window<"u")window.addEventListener("pagehide",n);return E.onCleanup=()=>{if(n(),typeof window<"u")window.removeEventListener("pagehide",n);if(delete J[A][H],$.forEach(clearTimeout),h.forEach((P)=>P?.()),Object.keys(J).length===0)clearInterval(J.offerCleanupTimer),delete J.offerCleanupTimer},E._census=()=>{for(let v of Object.keys(w))T.set(v,Date.now());let P=Date.now()-120000;for(let[v,M]of T)if(M<P)T.delete(v);return[...T.keys()]},E._gone=()=>{let P=Date.now()-60000;for(let[v,M]of x)if(M<P)x.delete(v);return[...x.keys()]},J[A][H]=E}},WT=3333,Qh=30000,SJ={},fT={},Hh=(W,Y)=>{let G={},X=null;G.reopenHandlers=new Set;let J=()=>{if(X)clearTimeout(X),X=null;if(G.socket)G.socket.onclose=null,G.socket.close();let Z=new WebSocket(W);Z.onclose=()=>{SJ[W]??=WT,X=setTimeout(J,SJ[W]),SJ[W]=Math.min(SJ[W]*2,Qh)},Z.onmessage=(V)=>Y(V.data),G.socket=Z,G.url=Z.url,G.ready=new Promise((V)=>{Z.onopen=()=>{SJ[W]=WT,V(G),G.reopenHandlers.forEach((U)=>U())}}),G.send=(V)=>{if(Z.readyState===1)Z.send(V)}};return G.forceReconnect=J,J(),fT[W]=G,G};if(typeof window<"u"){let W=(Y)=>{vJ.info("\u26A1 [GenosRTC] Network event detected. Forcing reconnection\u2026"),Object.values(fT).forEach((G)=>{if(G.socket&&G.socket.readyState!==WebSocket.OPEN&&(Y||G.socket.readyState!==WebSocket.CONNECTING))G.forceReconnect()})};window.addEventListener("online",()=>{vJ.info("\u2705 Reconnected to the network."),W(!0)}),window.addEventListener("offline",async()=>{vJ.info("\u274C Disconnected from the network.")}),document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible")W()})}var Nh=(W)=>()=>bT(nu(W).map(([Y,G])=>[Y,G.socket])),qh=(W,Y,G,X)=>(W.relayUrls??(X?ru(Y,gT(W.appId)):Y)).slice(0,W.relayUrls?.length??W.relayRedundancy??G),Ah=["wss://relay.primal.net","wss://relay.snort.social","wss://nostr.oxtr.dev","wss://nostr.vulpem.com","wss://relay.nostr.net","wss://nostr.sathoarder.com","wss://nostr.data.haus","wss://relay.mostr.pub"],VG={},Ih=10,cT="x",pT="EVENT",zh=/pow:\s*(\d+)\s*bits needed\.?/i,NQ=new Set,lT=DI.utils.randomSecretKey(),wh=NI(DI.getPublicKey(lT)),RI={},yJ={},jh={},dT=()=>Math.floor(Date.now()/1000),oT=(W)=>jh[W]??=gT(W,1e4)+20000,uJ=(W)=>W.replace(/\/$/,""),Oh=(W,Y)=>{let[G,X,J,Z]=KQ(Y);if(G===pT)return yJ[X]?.(RI[X],J.content);if(G==="NOTICE"||G==="OK"&&!J){if(+((G==="NOTICE"?X:Z).match(zh)?.[1]??0)>0){let V=uJ(W);NQ.add(V),VG[V]?.close?.(),delete VG[V]}}},Kh=(W)=>{let Y=uJ(W);if(VG[Y])return VG[Y];let G=Hh(Y,(X)=>Oh(Y,X));return VG[Y]=G},YI=async(W,Y)=>{let G={kind:oT(W),content:Y,pubkey:wh,created_at:dT(),tags:[[cT,W]]},X=PW(w7([0,G.pubkey,G.created_at,G.kind,G.tags,G.content])),J=new Uint8Array(await crypto.subtle.digest("SHA-256",X)),Z=DI.sign(J,lT);return w7([pT,{...G,id:NI(J),sig:NI(Z)}])},YT=(W,Y)=>{return RI[W]=Y,w7(["REQ",W,{kinds:[oT(Y)],since:dT(),["#"+cT]:[Y]}])},GT=(W)=>{return delete RI[W],w7(["CLOSE",W])},nT=Uh({init:(W)=>{let Y=(W?.relayUrls?.length?W.relayUrls:null)??Ah;return qh(W,Y,Ih,!1).map(Kh).map((G)=>G.ready.then(()=>G).catch(()=>null))},subscribe:(W,Y,G,X)=>{let J=DQ(64),Z=DQ(64);yJ[J]=yJ[Z]=(U,Q)=>X(U,Q,async(H,N)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(H,N))});let V=()=>{W.send(YT(J,Y)),W.send(YT(Z,G))};return V(),W.reopenHandlers.add(V),()=>{W.reopenHandlers.delete(V),W.send(GT(J)),W.send(GT(Z)),delete yJ[J],delete yJ[Z]}},announce:async(W,Y)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(Y,w7({peerId:A8})))},bye:async(W,Y)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(Y,w7({peerId:A8,bye:1})))}}),ke=Nh(VG),Dh={cellSize:10},Ch=5000,Th=3000,Rh=2000,Mh=2000,Ph=1e4,Lh=30000,Bh=5000,Eh=30000,CQ=(W)=>{let Y=String(W||"").match(/cell-(\d+)/);return Y?Number(Y[1]):null},GI=(W,Y)=>{let G=CQ(W);if(G==null)return[];let X=[];for(let J=1;J<Y;J*=2){if(G-J>=0)X.push(`cell-${G-J}`);if(G+J<Y)X.push(`cell-${G+J}`)}return X},VQ=(W)=>`c${(CQ(W)||0).toString(36)}`,$h=10,Fh=(W,Y)=>{let G=+Y.cellSize>=2?Y.cellSize|0:$h;return Math.max(1,Math.ceil(W/G))},iT=(W)=>{let Y=0;for(let G=0;G<W.length;G++)Y=Math.imul(Y^W.charCodeAt(G),2654435761);return Y>>>0},q6=(W,Y)=>{let G=0,X=-1;for(let J=0;J<Y;J++){let Z=iT(`${W}:${J}`);if(Z>X)X=Z,G=J}return G};function Sh(W,Y={},G={}){let X={...Dh,...Y},J=1,Z={epoch:0,roster:[A8],set:new Set([A8]),key:A8,C:1,cellId:null,isBridge:!1,bridges:[],edgeBridges:[]},V={cellId:null},U=0,Q=0,H="",N=0,A=0,q=0,z=null,w=null,D=null,T=new Map,x=new Set,g=new Map,f=new Set,y=0,p=new Set,b=new Map,m=()=>Math.min(150,Math.ceil(Math.log2(Z.C+1))*2+3),W0=(X0)=>GI(X0,Z.C),u=W.on?.bind(W),J0=W.off?.bind(W);if(u)W.on=(X0,D0)=>String(X0).startsWith("mesh:")?l(X0,D0):u(X0,D0);if(J0)W.off=(X0,D0)=>String(X0).startsWith("mesh:")?g.get(X0)?.delete(D0):J0(X0,D0);let A0=(X0)=>(x.add(X0),()=>x.delete(X0)),k=(X0,D0)=>{for(let L0 of x)try{L0(X0,D0)}catch(I0){vJ.error("\uD83D\uDD78\uFE0F [Cells] Error in deliver handler:",I0)}},l=(X0,D0)=>{if(!g.has(X0))g.set(X0,new Set);return g.get(X0).add(D0),()=>g.get(X0)?.delete(D0)},B=(X0,...D0)=>{let L0=g.get(X0);if(L0)for(let I0 of L0)try{I0(...D0)}catch{}},$=(X0)=>{try{return typeof X0==="string"?JSON.parse(X0):X0}catch{return null}},h=()=>`${A8}:${Date.now().toString(36)}:${(y++&65535).toString(36)}`,a=()=>{if(f.size>Ch)f.delete(f.values().next().value)},n=()=>[...new Set([...W._census(),A8])].sort(),E=(X0,D0,L0)=>D0.filter((I0)=>q6(I0,L0)===X0),P=(X0,D0,L0)=>{if(X0==null)return null;let I0=(H1)=>iT(`${H1}@${X0}`),F0=null,V1=-1;for(let H1 of E(X0,D0,L0)){let f1=I0(H1);if(f1>V1)V1=f1,F0=H1}return F0},v=(X0)=>{let D0=Z.audience?.get(X0);if(!D0)return[];return Object.keys(W.getPeers?.()||{}).filter((L0)=>D0.has(L0))},M=(X0,D0)=>{if(X0!==w&&!(Z.isBridge&&Z.bridges.some((i0)=>VQ(i0)===X0)))return;let L0=$(D0);if(!L0?.id||!L0?.t)return;if(f.has(L0.id))return;f.add(L0.id),a();let{t:I0,id:F0,ttl:V1,data:H1,origin:f1,originCell:i1}=L0,r0=Z.cellId;if(I0==="ping"&&H1?.pingId&&H1.target===A8&&f1!==A8){let i0={t:"pong",id:h(),ttl:m(),data:{pingId:H1.pingId,receivedAt:Date.now()},origin:A8,originCell:r0},V8=W.getPeers?.()?.[f1]?[f1]:v(r0);z?.send(JSON.stringify(i0),V8)}if(I0==="pong"&&H1?.pingId){let i0=b.get(H1.pingId);if(i0)clearTimeout(i0.timeout),i0.resolve(Date.now()-i0.start),b.delete(H1.pingId)}if(I0==="msg"&&f1!==A8)k(H1,f1);if(!Z.isBridge)return;if((V1??0)<=0)return;let x1=(i0,V8,F8=null)=>{if(!i0||!V8.length)return;let $9={t:I0,id:F0,ttl:F8??(V1??m())-1,data:H1,origin:f1||A8,originCell:i1||r0};i0.send(JSON.stringify($9),V8)};if(X0===w){for(let i0 of W0(r0))x1(F(i0),v(i0));return}x1(z,v(r0));for(let i0 of W0(r0))if(VQ(i0)!==X0)x1(F(i0),v(i0))},F=(X0)=>{let D0=VQ(X0),L0=W.channel(D0);if(!p.has(D0))p.add(D0),L0.on("message",(I0)=>M(D0,I0));return L0},c=()=>{if(!Z.cellId)return;if(w=VQ(Z.cellId),z=W.channel(w),!p.has(w))p.add(w),z.on("message",(X0)=>M(w,X0));if(Z.isBridge)for(let X0 of W0(Z.cellId))F(X0)},t=(X0,D0)=>{if(!X0.cellId||!X0.set.has(D0))return!1;let L0=`cell-${q6(D0,X0.C)}`;return L0===X0.cellId||X0.bridges.includes(L0)||GI(L0,X0.C).includes(X0.cellId)&&P(q6(D0,X0.C),X0.roster,X0.C)===D0},Y0=(X0)=>t(Z,X0)||Date.now()<U&&t(V,X0),$0=()=>{let X0=W.getPeers?.()||{};for(let D0 of Object.keys(X0))if(!Y0(D0))X0[D0].close?.()};G.admit=Y0;let S0=()=>({epoch:Z.epoch,cellId:Z.cellId,isBridge:Z.isBridge,bridges:Z.bridges,roster:[...Z.roster],cellSize:J,dynamicTTL:m(),totalCells:Z.C}),x0=()=>{A=Date.now();for(let[X0,D0]of T){if(X0===A8)continue;B("mesh:peer-state",{id:X0,cell:D0.cell,bridges:D0.bridges,timestamp:A})}},D1=(X0)=>{let D0=Fh(X0.length,X);J=Math.ceil(X0.length/D0);let L0=`cell-${q6(A8,D0)}`,I0=new Map,F0=new Set,V1=new Map,H1=(i0)=>V1.get(i0)??V1.set(i0,new Set).get(i0);for(let i0 of X0)H1(`cell-${q6(i0,D0)}`).add(i0);let f1=new Map,i1=(i0)=>f1.has(i0)?f1.get(i0):f1.set(i0,P(i0,X0,D0)).get(i0);for(let i0 of new Set(X0.map((V8)=>q6(V8,D0)))){let V8=`cell-${i0}`;for(let F8 of GI(V8,D0)){if(CQ(F8)<i0)continue;for(let $9 of[i1(i0),i1(CQ(F8))]){if(!$9)continue;let Q7=`cell-${q6($9,D0)}`===V8?F8:V8,d=I0.get($9)??[];if(!d.includes(Q7))d.push(Q7);if(I0.set($9,d),H1(V8).add($9),H1(F8).add($9),V8===L0||F8===L0)F0.add($9)}}}let r0=I0.get(A8)??[],x1=Z.cellId!==L0||String(Z.bridges)!==String(r0);V=Z,Z={epoch:Z.epoch+1,roster:X0,set:new Set(X0),key:X0.join("|"),C:D0,cellId:L0,isBridge:r0.length>0,bridges:r0,edgeBridges:[...F0],audience:V1},q=Date.now(),T.clear();for(let i0 of X0){let V8=I0.get(i0)??[];T.set(i0,{cell:`cell-${q6(i0,D0)}`,isBridge:V8.length>0,bridges:V8})}if(U=Date.now()+Bh,x1)c();vJ.info("\uD83D\uDD78\uFE0F [Cells] seal",{epoch:Z.epoch,myCell:L0,bridges:r0,C:D0,roster:X0.length}),x0(),B("mesh:state",S0())},b0=()=>{let X0=n(),D0=X0.join("|");if(D0===Z.key)Q=0;else{let L0=Date.now();if(Q||=L0,D0!==H)H=D0,N=L0;if(X0.some((I0)=>!Z.set.has(I0))||Z.edgeBridges.some((I0)=>!X0.includes(I0))||(W._gone?.()??[]).some((I0)=>Z.set.has(I0))?L0-N>=Mh||L0-Q>=Ph:L0-Q>=Lh)Q=0,D1(X0)}if(U&&Date.now()>=U)U=0,$0()},Q0=()=>{if(D)return;D=setInterval(()=>{if(b0(),Date.now()-A>=Eh)x0()},Rh)},O0=()=>{if(D)clearInterval(D),D=null},y0=(X0)=>{return new Promise((D0,L0)=>{let I0=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,F0=Date.now(),V1=setTimeout(()=>{b.delete(I0),L0(Error("Ping timeout"))},Th);b.set(I0,{start:F0,resolve:D0,reject:L0,timeout:V1,peerId:X0});let H1={t:"ping",id:h(),ttl:m(),data:{pingId:I0,target:X0},origin:A8,originCell:Z.cellId};z?.send(JSON.stringify(H1),v(Z.cellId))})};return W.on?.("peer:join",()=>b0()),W.on?.("peer:leave",()=>b0()),D1(n()),Q0(),{send:(X0)=>{let D0={t:"msg",id:h(),ttl:m(),data:X0,origin:A8,originCell:Z.cellId},L0=JSON.stringify(D0);z.send(L0,v(Z.cellId)),M(w,L0)},on:(X0,D0)=>X0==="message"?A0(D0):void 0,ping:y0,getState:()=>({...S0(),knownCells:new Set([...T.values()].map((X0)=>X0.cell)).size}),getPeerInfo:()=>new Map(T),getStableRoster:()=>[...Z.roster],getKnownCells:()=>{let X0=new Map;for(let[D0,{cell:L0}]of T)if(!X0.has(L0))X0.set(L0,{lastSeen:q,peerId:D0});return X0},getCellSize:()=>J,destroy:()=>{O0(),b.forEach((X0)=>clearTimeout(X0.timeout)),b.clear()}}}function xh(W,Y,G){let X={},J=nT({...W,admit:(Q)=>X.admit?.(Q)??!0},Y,G),Z=W.overlay||{},V=Sh(J,Z,X),U=new Map;return{on:(Q,H)=>J.on(Q,H),off:(Q,H)=>J.off?.(Q,H),channel:(Q)=>{if(U.has(Q))return U.get(Q);let H=J.channel(Q),N={send:(A,q)=>{if(q){let z=[].concat(q),w=J.getPeers?.()||{};if(z.every((D)=>w[D]))return H.send(A,q)}V.send({_ch:Q,_d:A,_t:q})},on:(A,q)=>{if(A==="message")V.on("message",(z,w)=>{if(z?._ch!==Q)return;if(z._t&&![].concat(z._t).includes(A8))return;q(z._d,w)}),H.on(A,q);else H.on(A,q)},off:(A,q)=>H.off?.(A,q),_original:H};return U.set(Q,N),N},get id(){return J.id},get peers(){return J.peers},getPeers:()=>J.getPeers?.()||{},mesh:V,_room:J,getState:()=>V.getState(),getPeerInfo:()=>V.getPeerInfo(),ping:(Q)=>V.ping(Q),leave:()=>{V.destroy(),U.clear(),J.leave()},destroy:()=>{V.destroy(),U.clear()}}}var MI=(W,Y,G)=>W?.cells||W?.overlay?xh(W,Y,G):nT(W,Y,G);import{randomBytes as IS}from"crypto";function kh(){var W,Y=!1,G=this;G._DeArray=function(X,J,Z){return[X.slice(J,J+Z)]},G._EnArray=function(X,J,Z,V){for(var U=0;U<Z;X[J+U]=V[U]?V[U]:0,U++);},G._DeChar=function(X,J){return String.fromCharCode(X[J])},G._EnChar=function(X,J,Z){X[J]=Z.charCodeAt(0)},G._DeInt=function(X,J){var Z=Y?W.len-1:0,V=Y?-1:1,U=Z+V*W.len,Q,H,N;for(Q=0,H=Z,N=1;H!=U;Q+=X[J+H]*N,H+=V,N*=256);if(W.bSigned&&Q&Math.pow(2,W.len*8-1))Q-=Math.pow(2,W.len*8);return Q},G._EnInt=function(X,J,Z){var V=Y?W.len-1:0,U=Y?-1:1,Q=V+U*W.len,H;Z=Z<W.min?W.min:Z>W.max?W.max:Z;for(H=V;H!=Q;X[J+H]=Z&255,H+=U,Z>>=8);},G._DeString=function(X,J,Z){for(var V=Array(Z),U=0;U<Z;V[U]=String.fromCharCode(X[J+U]),U++);return V.join("")},G._EnString=function(X,J,Z,V){for(var U,Q=0;Q<Z;X[J+Q]=(U=V.charCodeAt(Q))?U:0,Q++);},G._De754=function(X,J){var Z,V,U,Q,H,N,A,q,z,w;A=W.mLen,q=W.len*8-W.mLen-1,w=(1<<q)-1,z=w>>1,Q=Y?0:W.len-1,H=Y?1:-1,Z=X[J+Q],Q+=H,N=-7;for(V=Z&(1<<-N)-1,Z>>=-N,N+=q;N>0;V=V*256+X[J+Q],Q+=H,N-=8);for(U=V&(1<<-N)-1,V>>=-N,N+=A;N>0;U=U*256+X[J+Q],Q+=H,N-=8);switch(V){case 0:V=1-z;break;case w:return U?NaN:(Z?-1:1)*(1/0);default:U=U+Math.pow(2,A),V=V-z;break}return(Z?-1:1)*U*Math.pow(2,V-A)},G._En754=function(X,J,Z){var V,U,Q,H,N,A,q,z,w,D;if(q=W.mLen,z=W.len*8-W.mLen-1,D=(1<<z)-1,w=D>>1,V=Z<0?1:0,Z=Math.abs(Z),isNaN(Z)||Z==1/0)Q=isNaN(Z)?1:0,U=D;else{if(U=Math.floor(Math.log(Z)/Math.LN2),Z*(A=Math.pow(2,-U))<1)U--,A*=2;if(U+w>=1)Z+=W.rt/A;else Z+=W.rt*Math.pow(2,1-w);if(Z*A>=2)U++,A/=2;if(U+w>=D)Q=0,U=D;else if(U+w>=1)Q=(Z*A-1)*Math.pow(2,q),U=U+w;else Q=Z*Math.pow(2,w-1)*Math.pow(2,q),U=0}for(H=Y?W.len-1:0,N=Y?-1:1;q>=8;X[J+H]=Q&255,H+=N,Q/=256,q-=8);for(U=U<<q|Q,z+=q;z>0;X[J+H]=U&255,H+=N,U/=256,z-=8);X[J+H-N]|=V*128},G._DeInt64=function(X,J){var Z=Y?0:7,V=Y?1:-1,U=Z+V*8,Q=[0,0,!W.bSigned],H,N,A;for(H=Z,A=1,N=0;H!=U;Q[A]=(Q[A]<<8>>>0)+X[J+H],H+=V,N++,A=N<4?1:0);return Q},G._EnInt64=function(X,J,Z){var V=Y?0:7,U=Y?1:-1,Q=V+U*8,H,N,A,q;for(H=V,A=1,N=0,q=24;H!=Q;X[J+H]=Z[A]>>q&255,H+=U,N++,A=N<4?1:0,q=24-8*(N%4));},G._sPattern="(\\d + )?([AxcbBhHsfdiIlLqQ])",G._lenLut={A:1,x:1,c:1,b:1,B:1,h:2,H:2,s:1,f:4,d:8,i:4,I:4,l:4,L:4,q:8,Q:8},G._elLut={A:{en:G._EnArray,de:G._DeArray},s:{en:G._EnString,de:G._DeString},c:{en:G._EnChar,de:G._DeChar},b:{en:G._EnInt,de:G._DeInt,len:1,bSigned:!0,min:-Math.pow(2,7),max:Math.pow(2,7)-1},B:{en:G._EnInt,de:G._DeInt,len:1,bSigned:!1,min:0,max:Math.pow(2,8)-1},h:{en:G._EnInt,de:G._DeInt,len:2,bSigned:!0,min:-Math.pow(2,15),max:Math.pow(2,15)-1},H:{en:G._EnInt,de:G._DeInt,len:2,bSigned:!1,min:0,max:Math.pow(2,16)-1},i:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},I:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},l:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},L:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},f:{en:G._En754,de:G._De754,len:4,mLen:23,rt:Math.pow(2,-24)-Math.pow(2,-77)},d:{en:G._En754,de:G._De754,len:8,mLen:52,rt:0},q:{en:G._EnInt64,de:G._DeInt64,bSigned:!0},Q:{en:G._EnInt64,de:G._DeInt64,bSigned:!1}},G._UnpackSeries=function(X,J,Z,V){for(var U=W.de,Q=[],H=0;H<X;Q.push(U(Z,V+H*J)),H++);return Q},G._PackSeries=function(X,J,Z,V,U,Q){for(var H=W.en,N=0;N<X;H(Z,V+N*J,U[Q+N]),N++);},G.Unpack=function(X,J,Z){Y=X.charAt(0)!="<",Z=Z?Z:0;var V=new RegExp(this._sPattern,"g"),U,Q,H,N=[];while(U=V.exec(X)){if(Q=U[1]==null||U[1]==""?1:parseInt(U[1]),H=this._lenLut[U[2]],Z+Q*H>J.length)return;switch(U[2]){case"A":case"s":N.push(this._elLut[U[2]].de(J,Z,Q));break;case"c":case"b":case"B":case"h":case"H":case"i":case"I":case"l":case"L":case"f":case"d":case"q":case"Q":W=this._elLut[U[2]],N.push(this._UnpackSeries(Q,H,J,Z));break}Z+=Q*H}return Array.prototype.concat.apply([],N)},G.PackTo=function(X,J,Z,V){Y=X.charAt(0)!="<";var U=new RegExp(this._sPattern,"g"),Q,H,N,A,q=0;while(Q=U.exec(X)){if(H=Q[1]==null||Q[1]==""?1:parseInt(Q[1]),N=this._lenLut[Q[2]],Z+H*N>J.length)return!1;switch(Q[2]){case"A":case"s":if(q+1>V.length)return!1;this._elLut[Q[2]].en(J,Z,H,V[q]),q+=1;break;case"c":case"b":case"B":case"h":case"H":case"i":case"I":case"l":case"L":case"f":case"d":case"q":case"Q":if(W=this._elLut[Q[2]],q+H>V.length)return!1;this._PackSeries(H,N,J,Z,V,q),q+=H;break;case"x":for(A=0;A<H;A++)J[Z+A]=0;break}Z+=H*N}return J},G.Pack=function(X,J){return this.PackTo(X,Array(this.CalcLength(X)),0,J)},G.CalcLength=function(X){var J=new RegExp(this._sPattern,"g"),Z=0,V;while(V=J.exec(X))Z+=(V[1]==null||V[1]==""?1:parseInt(V[1]))*this._lenLut[V[2]];return Z}}var s1=new kh;var PS=y1(JR(),1),Hq=y1(gI(),1);import{createSocket as kd}from"dgram";import{createSocket as vd}from"dgram";import*as LS from"net";import{connect as gd}from"net";import{createSign as hd,randomBytes as bd,webcrypto as md}from"crypto";var OH0=y1(kR(),1);var M7={};NA(M7,{verifySchema:()=>lm,fromBER:()=>Q4,compareSchema:()=>J4,VisibleString:()=>FW,ViewWriter:()=>dJ,VideotexString:()=>MG,ValueBlock:()=>e8,Utf8String:()=>u5,UniversalString:()=>DG,UTCTime:()=>SW,TimeOfDay:()=>aQ,TeletexString:()=>RG,TIME:()=>eQ,Set:()=>f9,Sequence:()=>_9,Repeated:()=>zG,RelativeObjectIdentifier:()=>iQ,RawData:()=>MM,PrintableString:()=>TG,Primitive:()=>O6,OctetString:()=>T7,ObjectIdentifier:()=>OG,NumericString:()=>CG,Null:()=>C7,Integer:()=>K6,IA5String:()=>PG,HexBlock:()=>D7,GraphicString:()=>LG,GeneralizedTime:()=>$G,GeneralString:()=>BG,Enumerated:()=>jG,EndOfContent:()=>oQ,Duration:()=>tQ,DateTime:()=>sQ,DEFAULT_MAX_NODES:()=>dR,DEFAULT_MAX_DEPTH:()=>lR,DEFAULT_MAX_CONTENT_LENGTH:()=>oR,DATE:()=>rQ,Constructed:()=>c8,Choice:()=>nJ,CharacterString:()=>EG,Boolean:()=>wG,BmpString:()=>KG,BitString:()=>R7,BaseStringBlock:()=>lQ,BaseBlock:()=>k8,Any:()=>V4});/*!
|
|
147
|
+
`),ZN.prototype[W]=Y.toFunction({assertSize:Mj})});JE.exports=ZN;function Mj(W,Y){if(W>Y)throw new fp(W,Y)}});var j8=U1((aH0,IE)=>{var Pj=wV(),cp=uB(),pp=fB(),lp=pB(),dp=dB(),op=iB(),VE=aB(),np=tB(),ip=YE(),{encode:HE}=OV(),{decode:NE}=zX(),{encodingLength:rp}=KV(),ap=ZE(),qE=AX(),AE={array:cp,bool:lp,buffer:pp,reserved:dp,string:op,when:np,select:ip};for(let W of Object.keys(VE))AE[W]=VE[W];var VN=Symbol("schema");function UE(W){let Y=new Pj({readableObjectMode:!1,writableObjectMode:!0,transform:sp});return Y[VN]=W,Y}function QE(W){let Y=null,G=Buffer.isBuffer(W);if(!G)Y=W;let X=new Pj({transform:tp,readableObjectMode:!0,writableObjectMode:!1});if(X[VN]=Y,G)X.append(W);return X}function sp(W,Y,G){try{HE(W,this[VN],this);let X=this.slice();this.consume(X.length),G(null,X)}catch(X){G(X)}}function tp(W,Y,G){this.append(W);try{while(this.length>0){let X=new ap(this),J=NE(X,this[VN]);X.commit(),this.push(J)}G()}catch(X){if(X instanceof qE)G();else G(X)}}IE.exports={createEncodeStream:UE,createDecodeStream:QE,encode:HE,decode:NE,encodingLength:rp,createEncode:UE,createDecode:QE,types:AE,BinaryStream:Pj,NotEnoughDataError:qE}});var A$=U1((N$)=>{Object.defineProperty(N$,"__esModule",{value:!0});N$.LEB128=N$.SignedLEB128=N$.UnsignedLEB128=void 0;var TX;(function(W){W[W.LOWER_7=127]="LOWER_7",W[W.UPPER_1=128]="UPPER_1"})(TX||(TX={}));var H$=(W)=>Number.isSafeInteger(W);class RX{static decode(W,Y=0){let G=this.$scanForNullBytes(W,Y),X=0,J=0;for(let Z=0;Z<=G-Y;Z++){let V=W[Y+Z]&TX.LOWER_7;X|=V<<J,J+=7}return X}static encode(W){if(this.check(W),W<0)throw Error(`An unsigned number must NOT be negative, ${W} is!`);let Y=[],G=W;do{let X=G&TX.LOWER_7;if(G>>=7,G)X=X|TX.UPPER_1;Y.push(X)}while(G);return Uint8Array.from(Y)}static check(W){if(!H$(W))throw Error(`${W} is not a safe integer!`)}static $scanForNullBytes(W,Y=0){let G=Y,X=0;do{if(G>=W.byteLength)throw Error("This is not a LEB128-encoded Uint8Array, no ending found!");X=W.slice(G,G+1)[0],G++}while(X&TX.UPPER_1);return G-1}static getLength(W,Y=0){return this.$scanForNullBytes(W,Y)-Y}}N$.UnsignedLEB128=RX;class CN{static $ceil7mul(W){let Y=W;while(Y%7)Y++;return Y}static check(W){if(!H$(W))throw Error(`${W} is not a safe integer!`)}static encode(W){if(this.check(W),W>=0)throw Error(`A signed number must be negative, ${W} isn't!`);let Y=Math.ceil(Math.log2(-W));return RX.encode((1<<this.$ceil7mul(Y))+W)}static decode(W,Y=0){let G=RX.decode(W,Y);return-((1<<Math.ceil(Math.log2(G)))-G)}}N$.SignedLEB128=CN;class TN{}N$.LEB128=TN;TN.encode=(W)=>(W>=0?RX:CN).encode(W);TN.decode=(W,Y=0,G=!1)=>(G?CN:RX).decode(W,Y)});var z$=U1((dj,I$)=>{/*! MIT License. Copyright 2015-2018 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */(function(W){function Y(E){return parseInt(E)===E}function G(E){if(!Y(E.length))return!1;for(var P=0;P<E.length;P++)if(!Y(E[P])||E[P]<0||E[P]>255)return!1;return!0}function X(E,P){if(E.buffer&&E.name==="Uint8Array"){if(P)if(E.slice)E=E.slice();else E=Array.prototype.slice.call(E);return E}if(Array.isArray(E)){if(!G(E))throw Error("Array contains invalid value: "+E);return new Uint8Array(E)}if(Y(E.length)&&G(E))return new Uint8Array(E);throw Error("unsupported array-like object")}function J(E){return new Uint8Array(E)}function Z(E,P,v,M,F){if(M!=null||F!=null)if(E.slice)E=E.slice(M,F);else E=Array.prototype.slice.call(E,M,F);P.set(E,v)}var V=function(){function E(v){var M=[],F=0;v=encodeURI(v);while(F<v.length){var c=v.charCodeAt(F++);if(c===37)M.push(parseInt(v.substr(F,2),16)),F+=2;else M.push(c)}return X(M)}function P(v){var M=[],F=0;while(F<v.length){var c=v[F];if(c<128)M.push(String.fromCharCode(c)),F++;else if(c>191&&c<224)M.push(String.fromCharCode((c&31)<<6|v[F+1]&63)),F+=2;else M.push(String.fromCharCode((c&15)<<12|(v[F+1]&63)<<6|v[F+2]&63)),F+=3}return M.join("")}return{toBytes:E,fromBytes:P}}(),U=function(){function E(M){var F=[];for(var c=0;c<M.length;c+=2)F.push(parseInt(M.substr(c,2),16));return F}var P="0123456789abcdef";function v(M){var F=[];for(var c=0;c<M.length;c++){var t=M[c];F.push(P[(t&240)>>4]+P[t&15])}return F.join("")}return{toBytes:E,fromBytes:v}}(),Q={16:10,24:12,32:14},H=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],N=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],A=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],q=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],z=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],w=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],D=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],T=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],x=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],g=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239000,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],f=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998000,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],y=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],p=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],b=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239000,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],m=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998000,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function W0(E){var P=[];for(var v=0;v<E.length;v+=4)P.push(E[v]<<24|E[v+1]<<16|E[v+2]<<8|E[v+3]);return P}var u=function(E){if(!(this instanceof u))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:X(E,!0)}),this._prepare()};u.prototype._prepare=function(){var E=Q[this.key.length];if(E==null)throw Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var P=0;P<=E;P++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var v=(E+1)*4,M=this.key.length/4,F=W0(this.key),c;for(var P=0;P<M;P++)c=P>>2,this._Ke[c][P%4]=F[P],this._Kd[E-c][P%4]=F[P];var t=0,Y0=M,$0;while(Y0<v){if($0=F[M-1],F[0]^=N[$0>>16&255]<<24^N[$0>>8&255]<<16^N[$0&255]<<8^N[$0>>24&255]^H[t]<<24,t+=1,M!=8)for(var P=1;P<M;P++)F[P]^=F[P-1];else{for(var P=1;P<M/2;P++)F[P]^=F[P-1];$0=F[M/2-1],F[M/2]^=N[$0&255]^N[$0>>8&255]<<8^N[$0>>16&255]<<16^N[$0>>24&255]<<24;for(var P=M/2+1;P<M;P++)F[P]^=F[P-1]}var P=0,S0,x0;while(P<M&&Y0<v)S0=Y0>>2,x0=Y0%4,this._Ke[S0][x0]=F[P],this._Kd[E-S0][x0]=F[P++],Y0++}for(var S0=1;S0<E;S0++)for(var x0=0;x0<4;x0++)$0=this._Kd[S0][x0],this._Kd[S0][x0]=y[$0>>24&255]^p[$0>>16&255]^b[$0>>8&255]^m[$0&255]},u.prototype.encrypt=function(E){if(E.length!=16)throw Error("invalid plaintext size (must be 16 bytes)");var P=this._Ke.length-1,v=[0,0,0,0],M=W0(E);for(var F=0;F<4;F++)M[F]^=this._Ke[0][F];for(var c=1;c<P;c++){for(var F=0;F<4;F++)v[F]=q[M[F]>>24&255]^z[M[(F+1)%4]>>16&255]^w[M[(F+2)%4]>>8&255]^D[M[(F+3)%4]&255]^this._Ke[c][F];M=v.slice()}var t=J(16),Y0;for(var F=0;F<4;F++)Y0=this._Ke[P][F],t[4*F]=(N[M[F]>>24&255]^Y0>>24)&255,t[4*F+1]=(N[M[(F+1)%4]>>16&255]^Y0>>16)&255,t[4*F+2]=(N[M[(F+2)%4]>>8&255]^Y0>>8)&255,t[4*F+3]=(N[M[(F+3)%4]&255]^Y0)&255;return t},u.prototype.decrypt=function(E){if(E.length!=16)throw Error("invalid ciphertext size (must be 16 bytes)");var P=this._Kd.length-1,v=[0,0,0,0],M=W0(E);for(var F=0;F<4;F++)M[F]^=this._Kd[0][F];for(var c=1;c<P;c++){for(var F=0;F<4;F++)v[F]=T[M[F]>>24&255]^x[M[(F+3)%4]>>16&255]^g[M[(F+2)%4]>>8&255]^f[M[(F+1)%4]&255]^this._Kd[c][F];M=v.slice()}var t=J(16),Y0;for(var F=0;F<4;F++)Y0=this._Kd[P][F],t[4*F]=(A[M[F]>>24&255]^Y0>>24)&255,t[4*F+1]=(A[M[(F+3)%4]>>16&255]^Y0>>16)&255,t[4*F+2]=(A[M[(F+2)%4]>>8&255]^Y0>>8)&255,t[4*F+3]=(A[M[(F+1)%4]&255]^Y0)&255;return t};var J0=function(E){if(!(this instanceof J0))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new u(E)};J0.prototype.encrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16)Z(E,v,0,M,M+16),v=this._aes.encrypt(v),Z(v,P,M);return P},J0.prototype.decrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16)Z(E,v,0,M,M+16),v=this._aes.decrypt(v),Z(v,P,M);return P};var I0=function(E,P){if(!(this instanceof I0))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastCipherblock=X(P,!0),this._aes=new u(E)};I0.prototype.encrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid plaintext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16){Z(E,v,0,M,M+16);for(var F=0;F<16;F++)v[F]^=this._lastCipherblock[F];this._lastCipherblock=this._aes.encrypt(v),Z(this._lastCipherblock,P,M)}return P},I0.prototype.decrypt=function(E){if(E=X(E),E.length%16!==0)throw Error("invalid ciphertext size (must be multiple of 16 bytes)");var P=J(E.length),v=J(16);for(var M=0;M<E.length;M+=16){Z(E,v,0,M,M+16),v=this._aes.decrypt(v);for(var F=0;F<16;F++)P[M+F]=v[F]^this._lastCipherblock[F];Z(E,this._lastCipherblock,0,M,M+16)}return P};var k=function(E,P,v){if(!(this instanceof k))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 size)");if(!v)v=1;this.segmentSize=v,this._shiftRegister=X(P,!0),this._aes=new u(E)};k.prototype.encrypt=function(E){if(E.length%this.segmentSize!=0)throw Error("invalid plaintext size (must be segmentSize bytes)");var P=X(E,!0),v;for(var M=0;M<P.length;M+=this.segmentSize){v=this._aes.encrypt(this._shiftRegister);for(var F=0;F<this.segmentSize;F++)P[M+F]^=v[F];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(P,this._shiftRegister,16-this.segmentSize,M,M+this.segmentSize)}return P},k.prototype.decrypt=function(E){if(E.length%this.segmentSize!=0)throw Error("invalid ciphertext size (must be segmentSize bytes)");var P=X(E,!0),v;for(var M=0;M<P.length;M+=this.segmentSize){v=this._aes.encrypt(this._shiftRegister);for(var F=0;F<this.segmentSize;F++)P[M+F]^=v[F];Z(this._shiftRegister,this._shiftRegister,0,this.segmentSize),Z(E,this._shiftRegister,16-this.segmentSize,M,M+this.segmentSize)}return P};var l=function(E,P){if(!(this instanceof l))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",!P)P=J(16);else if(P.length!=16)throw Error("invalid initialation vector size (must be 16 bytes)");this._lastPrecipher=X(P,!0),this._lastPrecipherIndex=16,this._aes=new u(E)};l.prototype.encrypt=function(E){var P=X(E,!0);for(var v=0;v<P.length;v++){if(this._lastPrecipherIndex===16)this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0;P[v]^=this._lastPrecipher[this._lastPrecipherIndex++]}return P},l.prototype.decrypt=l.prototype.encrypt;var B=function(E){if(!(this instanceof B))throw Error("Counter must be instanitated with `new`");if(E!==0&&!E)E=1;if(typeof E==="number")this._counter=J(16),this.setValue(E);else this.setBytes(E)};B.prototype.setValue=function(E){if(typeof E!=="number"||parseInt(E)!=E)throw Error("invalid counter value (must be an integer)");if(E>Number.MAX_SAFE_INTEGER)throw Error("integer value out of safe range");for(var P=15;P>=0;--P)this._counter[P]=E%256,E=parseInt(E/256)},B.prototype.setBytes=function(E){if(E=X(E,!0),E.length!=16)throw Error("invalid counter bytes size (must be 16 bytes)");this._counter=E},B.prototype.increment=function(){for(var E=15;E>=0;E--)if(this._counter[E]===255)this._counter[E]=0;else{this._counter[E]++;break}};var $=function(E,P){if(!(this instanceof $))throw Error("AES must be instanitated with `new`");if(this.description="Counter",this.name="ctr",!(P instanceof B))P=new B(P);this._counter=P,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new u(E)};$.prototype.encrypt=function(E){var P=X(E,!0);for(var v=0;v<P.length;v++){if(this._remainingCounterIndex===16)this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment();P[v]^=this._remainingCounter[this._remainingCounterIndex++]}return P},$.prototype.decrypt=$.prototype.encrypt;function h(E){E=X(E,!0);var P=16-E.length%16,v=J(E.length+P);Z(E,v);for(var M=E.length;M<v.length;M++)v[M]=P;return v}function a(E){if(E=X(E,!0),E.length<16)throw Error("PKCS#7 invalid length");var P=E[E.length-1];if(P>16)throw Error("PKCS#7 padding byte out of range");var v=E.length-P;for(var M=0;M<P;M++)if(E[v+M]!==P)throw Error("PKCS#7 invalid padding byte");var F=J(v);return Z(E,F,0,0,v),F}var n={AES:u,Counter:B,ModeOfOperation:{ecb:J0,cbc:I0,cfb:k,ofb:l,ctr:$},utils:{hex:U,utf8:V},padding:{pkcs7:{pad:h,strip:a}},_arrayTest:{coerceArray:X,createArray:J,copyArray:Z}};if(typeof dj<"u")I$.exports=n;else if(typeof define==="function"&&define.amd)define([],function(){return n});else{if(W.aesjs)n._aesjs=W.aesjs;W.aesjs=n}})(dj)});var rj=U1((C$)=>{var G1=C$,{Buffer:LN}=x8("buffer"),ul=x8("os");G1.toBuffer=function(W,Y,G){G=~~G;let X;if(this.isV4Format(W))X=Y||LN.alloc(G+4),W.split(/\./g).map((J)=>{X[G++]=parseInt(J,10)&255});else if(this.isV6Format(W)){let J=W.split(":",8),Z;for(Z=0;Z<J.length;Z++){let V=this.isV4Format(J[Z]),U;if(V)U=this.toBuffer(J[Z]),J[Z]=U.slice(0,2).toString("hex");if(U&&++Z<8)J.splice(Z,0,U.slice(2,4).toString("hex"))}if(J[0]==="")while(J.length<8)J.unshift("0");else if(J[J.length-1]==="")while(J.length<8)J.push("0");else if(J.length<8){for(Z=0;Z<J.length&&J[Z]!=="";Z++);let V=[Z,1];for(Z=9-J.length;Z>0;Z--)V.push("0");J.splice(...V)}X=Y||LN.alloc(G+16);for(Z=0;Z<J.length;Z++){let V=parseInt(J[Z],16);X[G++]=V>>8&255,X[G++]=V&255}}if(!X)throw Error(`Invalid ip address: ${W}`);return X};G1.toString=function(W,Y,G){Y=~~Y,G=G||W.length-Y;let X=[];if(G===4){for(let J=0;J<G;J++)X.push(W[Y+J]);X=X.join(".")}else if(G===16){for(let J=0;J<G;J+=2)X.push(W.readUInt16BE(Y+J).toString(16));X=X.join(":"),X=X.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),X=X.replace(/:{3,4}/,"::")}return X};var hl=/^(\d{1,3}\.){3,3}\d{1,3}$/,bl=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;G1.isV4Format=function(W){return hl.test(W)};G1.isV6Format=function(W){return bl.test(W)};function FV(W){if(W===4)return"ipv4";if(W===6)return"ipv6";return W?W.toLowerCase():"ipv4"}G1.fromPrefixLen=function(W,Y){if(W>32)Y="ipv6";else Y=FV(Y);let G=4;if(Y==="ipv6")G=16;let X=LN.alloc(G);for(let J=0,Z=X.length;J<Z;++J){let V=8;if(W<8)V=W;W-=V,X[J]=~(255>>V)&255}return G1.toString(X)};G1.mask=function(W,Y){W=G1.toBuffer(W),Y=G1.toBuffer(Y);let G=LN.alloc(Math.max(W.length,Y.length)),X;if(W.length===Y.length)for(X=0;X<W.length;X++)G[X]=W[X]&Y[X];else if(Y.length===4)for(X=0;X<Y.length;X++)G[X]=W[W.length-4+X]&Y[X];else{for(X=0;X<G.length-6;X++)G[X]=0;G[10]=255,G[11]=255;for(X=0;X<W.length;X++)G[X+12]=W[X]&Y[X+12];X+=12}for(;X<G.length;X++)G[X]=0;return G1.toString(G)};G1.cidr=function(W){let Y=W.split("/"),G=Y[0];if(Y.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let X=G1.fromPrefixLen(parseInt(Y[1],10));return G1.mask(G,X)};G1.subnet=function(W,Y){let G=G1.toLong(G1.mask(W,Y)),X=G1.toBuffer(Y),J=0;for(let V=0;V<X.length;V++)if(X[V]===255)J+=8;else{let U=X[V]&255;while(U)U=U<<1&255,J++}let Z=2**(32-J);return{networkAddress:G1.fromLong(G),firstAddress:Z<=2?G1.fromLong(G):G1.fromLong(G+1),lastAddress:Z<=2?G1.fromLong(G+Z-1):G1.fromLong(G+Z-2),broadcastAddress:G1.fromLong(G+Z-1),subnetMask:Y,subnetMaskLength:J,numHosts:Z<=2?Z:Z-2,length:Z,contains(V){return G===G1.toLong(G1.mask(V,Y))}}};G1.cidrSubnet=function(W){let Y=W.split("/"),G=Y[0];if(Y.length!==2)throw Error(`invalid CIDR subnet: ${G}`);let X=G1.fromPrefixLen(parseInt(Y[1],10));return G1.subnet(G,X)};G1.not=function(W){let Y=G1.toBuffer(W);for(let G=0;G<Y.length;G++)Y[G]=255^Y[G];return G1.toString(Y)};G1.or=function(W,Y){if(W=G1.toBuffer(W),Y=G1.toBuffer(Y),W.length===Y.length){for(let Z=0;Z<W.length;++Z)W[Z]|=Y[Z];return G1.toString(W)}let G=W,X=Y;if(Y.length>W.length)G=Y,X=W;let J=G.length-X.length;for(let Z=J;Z<G.length;++Z)G[Z]|=X[Z-J];return G1.toString(G)};G1.isEqual=function(W,Y){if(W=G1.toBuffer(W),Y=G1.toBuffer(Y),W.length===Y.length){for(let X=0;X<W.length;X++)if(W[X]!==Y[X])return!1;return!0}if(Y.length===4){let X=Y;Y=W,W=X}for(let X=0;X<10;X++)if(Y[X]!==0)return!1;let G=Y.readUInt16BE(10);if(G!==0&&G!==65535)return!1;for(let X=0;X<4;X++)if(W[X]!==Y[X+12])return!1;return!0};G1.isPrivate=function(W){if(G1.isLoopback(W))return!0;if(!G1.isV6Format(W)){let Y=G1.normalizeToLong(W);if(Y<0)throw Error("invalid ipv4 address");W=G1.fromLong(Y)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(W)||/^f[cd][0-9a-f]{2}:/i.test(W)||/^fe80:/i.test(W)||/^::1$/.test(W)||/^::$/.test(W)};G1.isPublic=function(W){return!G1.isPrivate(W)};G1.isLoopback=function(W){if(!/\./.test(W)&&!/:/.test(W))W=G1.fromLong(Number(W));return/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(W)||/^0177\./.test(W)||/^0x7f\./i.test(W)||/^fe80::1$/i.test(W)||/^::1$/.test(W)||/^::$/.test(W)};G1.loopback=function(W){if(W=FV(W),W!=="ipv4"&&W!=="ipv6")throw Error("family must be ipv4 or ipv6");return W==="ipv4"?"127.0.0.1":"fe80::1"};G1.address=function(W,Y){let G=ul.networkInterfaces();if(Y=FV(Y),W&&W!=="private"&&W!=="public"){let J=G[W].filter((Z)=>{return FV(Z.family)===Y});if(J.length===0)return;return J[0].address}let X=Object.keys(G).map((J)=>{let Z=G[J].filter((V)=>{if(V.family=FV(V.family),V.family!==Y||G1.isLoopback(V.address))return!1;if(!W)return!0;return W==="public"?G1.isPrivate(V.address):G1.isPublic(V.address)});return Z.length?Z[0].address:void 0}).filter(Boolean);return!X.length?G1.loopback(Y):X[0]};G1.toLong=function(W){let Y=0;return W.split(".").forEach((G)=>{Y<<=8,Y+=parseInt(G)}),Y>>>0};G1.fromLong=function(W){return`${W>>>24}.${W>>16&255}.${W>>8&255}.${W&255}`};G1.normalizeToLong=function(W){let Y=W.split(".").map((J)=>{if(J.startsWith("0x")||J.startsWith("0X"))return parseInt(J,16);else if(J.startsWith("0")&&J!=="0"&&/^[0-7]+$/.test(J))return parseInt(J,8);else if(/^[1-9]\d*$/.test(J)||J==="0")return parseInt(J,10);else return NaN});if(Y.some(isNaN))return-1;let G=0;switch(Y.length){case 1:G=Y[0];break;case 2:if(Y[0]>255||Y[1]>16777215)return-1;G=Y[0]<<24|Y[1]&16777215;break;case 3:if(Y[0]>255||Y[1]>255||Y[2]>65535)return-1;G=Y[0]<<24|Y[1]<<16|Y[2]&65535;break;case 4:if(Y.some((J)=>J>255))return-1;G=Y[0]<<24|Y[1]<<16|Y[2]<<8|Y[3];break;default:return-1}return G>>>0}});var R$=U1((uN0,T$)=>{T$.exports=function W(Y,G){if(Y===G)return!0;if(Y&&G&&typeof Y=="object"&&typeof G=="object"){if(Y.constructor!==G.constructor)return!1;var X,J,Z;if(Array.isArray(Y)){if(X=Y.length,X!=G.length)return!1;for(J=X;J--!==0;)if(!W(Y[J],G[J]))return!1;return!0}if(Y.constructor===RegExp)return Y.source===G.source&&Y.flags===G.flags;if(Y.valueOf!==Object.prototype.valueOf)return Y.valueOf()===G.valueOf();if(Y.toString!==Object.prototype.toString)return Y.toString()===G.toString();if(Z=Object.keys(Y),X=Z.length,X!==Object.keys(G).length)return!1;for(J=X;J--!==0;)if(!Object.prototype.hasOwnProperty.call(G,Z[J]))return!1;for(J=X;J--!==0;){var V=Z[J];if(!W(Y[V],G[V]))return!1}return!0}return Y!==Y&&G!==G}});var M$=U1((ml)=>{ml.toString=function(W){switch(W){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+W};ml.toType=function(W){switch(W.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}if(W.toUpperCase().startsWith("UNKNOWN_"))return parseInt(W.slice(8));return 0}});var P$=U1((pl)=>{pl.toString=function(W){switch(W){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+W};pl.toRcode=function(W){switch(W.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var L$=U1((ol)=>{ol.toString=function(W){switch(W){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+W};ol.toOpcode=function(W){switch(W.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var B$=U1((rl)=>{rl.toString=function(W){switch(W){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+W};rl.toClass=function(W){switch(W.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}});var E$=U1((tl)=>{tl.toString=function(W){switch(W){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}if(W<0)return null;return`OPTION_${W}`};tl.toCode=function(W){if(typeof W==="number")return W;if(!W)return-1;switch(W.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let Y=W.match(/_(\d+)$/);if(Y)return parseInt(Y[1],10);return-1}});var S$=U1((F$,aj)=>{var $$=function(W){Object.defineProperty(W,"__esModule",{value:!0}),W.decode=A,W.encode=N,W.familyOf=H,W.name=void 0,W.sizeOf=Q,W.v6=W.v4=void 0;let Y=/^(\d{1,3}\.){3,3}\d{1,3}$/,G=4,X=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,J=16,Z={name:"v4",size:G,isFormat:(q)=>Y.test(q),encode(q,z,w){w=~~w,z=z||new Uint8Array(w+G);let D=q.length,T=0;for(let x=0;x<D;){let g=q.charCodeAt(x++);if(g===46)z[w++]=T,T=0;else T=T*10+(g-48)}return z[w]=T,z},decode(q,z){return z=~~z,`${q[z++]}.${q[z++]}.${q[z++]}.${q[z]}`}};W.v4=Z;let V={name:"v6",size:J,isFormat:(q)=>q.length>0&&X.test(q),encode(q,z,w){w=~~w;let D=w+J,T=-1,x=0,g=0,f=!0,y=!1;z=z||new Uint8Array(w+J);for(let p=0;p<q.length;p++){let b=q.charCodeAt(p);if(b===58){if(f){if(T!==-1){if(w<D)z[w]=0;if(w<D-1)z[w+1]=0;w+=2}else if(w<D)T=w}else{if(y===!0){if(w<D)z[w]=g;w++}else{if(w<D)z[w]=x>>8;if(w<D-1)z[w+1]=x&255;w+=2}x=0,g=0}f=!0,y=!1}else if(b===46){if(w<D)z[w]=g;w++,g=0,x=0,f=!1,y=!0}else{if(f=!1,b>=97)b-=87;else if(b>=65)b-=55;else b-=48,g=g*10+b;x=(x<<4)+b}}if(f===!1)if(y===!0){if(w<D)z[w]=g;w++}else{if(w<D)z[w]=x>>8;if(w<D-1)z[w+1]=x&255;w+=2}else if(T===0){if(w<D)z[w]=0;if(w<D-1)z[w+1]=0;w+=2}else if(T!==-1){w+=2;for(let p=Math.min(w-1,D-1);p>=T+2;p--)z[p]=z[p-2];z[T]=0,z[T+1]=0,T=w}if(T!==w&&T!==-1){if(w>D-2)w=D-2;while(D>T)z[--D]=w<D&&w>T?z[--w]:0}else while(w<D)z[w++]=0;return z},decode(q,z){z=~~z;let w="";for(let D=0;D<J;D+=2){if(D!==0)w+=":";w+=(q[z+D]<<8|q[z+D+1]).toString(16)}return w.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};W.v6=V;let U="ip";W.name=U;function Q(q){if(Z.isFormat(q))return Z.size;if(V.isFormat(q))return V.size;throw Error(`Invalid ip address: ${q}`)}function H(q){return Q(q)===Z.size?1:2}function N(q,z,w){w=~~w;let D=Q(q);if(typeof z==="function")z=z(w+D);if(D===Z.size)return Z.encode(q,z,w);return V.encode(q,z,w)}function A(q,z,w){if(z=~~z,w=w||q.length-z,w===Z.size)return Z.decode(q,z,w);if(w===V.size)return V.decode(q,z,w);throw Error(`Invalid buffer size needs to be ${Z.size} for v4 or ${V.size} for v6.`)}return"default"in W?W.default:W}({});if(typeof define==="function"&&define.amd)define([],function(){return $$});else if(typeof aj==="object"&&typeof F$==="object")aj.exports=$$});var x$=U1((Zd)=>{var Z1=x8("buffer").Buffer,b4=M$(),Yd=P$(),Gd=L$(),EN=B$(),ej=E$(),wY=S$(),g0=Zd.name={};g0.encode=function(W,Y,G,{mail:X=!1}={}){if(!Y)Y=Z1.alloc(g0.encodingLength(W));if(!G)G=0;let J=G,Z=W.replace(/^\.|\.$/gm,"");if(Z.length){let V=[];if(X){let U="";Z.split(".").forEach((Q)=>{if(Q.endsWith("\\"))U+=(U.length?".":"")+Q.slice(0,-1);else if(V.length===0&&U.length)V.push(U+"."+Q);else V.push(Q)})}else V=Z.split(".");for(let U=0;U<V.length;U++){let Q=Y.write(V[U],G+1);Y[G]=Q,G+=Q+1}}return Y[G++]=0,g0.encode.bytes=G-J,Y};g0.encode.bytes=0;g0.decode=function(W,Y,{mail:G=!1}={}){if(!Y)Y=0;let X=[],J=Y,Z=0,V=0,U=!1;while(!0){if(Y>=W.length)throw Error("Cannot decode name (buffer overflow)");let Q=W[Y++];if(V+=U?0:1,Q===0)break;else if((Q&192)===0){if(Y+Q>W.length)throw Error("Cannot decode name (buffer overflow)");if(Z+=Q+1,Z>254)throw Error("Cannot decode name (name too long)");let H=W.toString("utf-8",Y,Y+Q);if(G)H=H.replace(/\./g,"\\.");X.push(H),Y+=Q,V+=U?0:Q}else if((Q&192)===192){if(Y+1>W.length)throw Error("Cannot decode name (buffer overflow)");let H=W.readUInt16BE(Y-1)-49152;if(H>=J)throw Error("Cannot decode name (bad pointer)");Y=H,J=H,V+=U?0:1,U=!0}else throw Error("Cannot decode name (bad label)")}return g0.decode.bytes=V,X.length===0?".":X.join(".")};g0.decode.bytes=0;g0.encodingLength=function(W){if(W==="."||W==="..")return 1;return Z1.byteLength(W.replace(/^\.|\.$/gm,""))+2};var S1={};S1.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(S1.encodingLength(W));if(!G)G=0;let X=Y.write(W,G+1);return Y[G]=X,S1.encode.bytes=X+1,Y};S1.encode.bytes=0;S1.decode=function(W,Y){if(!Y)Y=0;let G=W[Y],X=W.toString("utf-8",Y+1,Y+1+G);return S1.decode.bytes=G+1,X};S1.decode.bytes=0;S1.encodingLength=function(W){return Z1.byteLength(W)+1};var s5={};s5.encode=function(W,Y,G){if(!Y)Y=s5.encodingLength(W);if(!G)G=0;let X=(W.flags||0)&32767,J=W.type==="response"?32768:0;return Y.writeUInt16BE(W.id||0,G),Y.writeUInt16BE(X|J,G+2),Y.writeUInt16BE(W.questions.length,G+4),Y.writeUInt16BE(W.answers.length,G+6),Y.writeUInt16BE(W.authorities.length,G+8),Y.writeUInt16BE(W.additionals.length,G+10),Y};s5.encode.bytes=12;s5.decode=function(W,Y){if(!Y)Y=0;if(W.length<12)throw Error("Header must be 12 bytes");let G=W.readUInt16BE(Y+2);return{id:W.readUInt16BE(Y),type:G&32768?"response":"query",flags:G&32767,flag_qr:(G>>15&1)===1,opcode:Gd.toString(G>>11&15),flag_aa:(G>>10&1)===1,flag_tc:(G>>9&1)===1,flag_rd:(G>>8&1)===1,flag_ra:(G>>7&1)===1,flag_z:(G>>6&1)===1,flag_ad:(G>>5&1)===1,flag_cd:(G>>4&1)===1,rcode:Yd.toString(G&15),questions:Array(W.readUInt16BE(Y+4)),answers:Array(W.readUInt16BE(Y+6)),authorities:Array(W.readUInt16BE(Y+8)),additionals:Array(W.readUInt16BE(Y+10))}};s5.decode.bytes=12;s5.encodingLength=function(){return 12};var S4=Zd.unknown={};S4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(S4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(W.length,G),W.copy(Y,G+2),S4.encode.bytes=W.length+2,Y};S4.encode.bytes=0;S4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X=W.slice(Y+2,Y+2+G);return S4.decode.bytes=G+2,X};S4.decode.bytes=0;S4.encodingLength=function(W){return W.length+2};var x4=Zd.ns={};x4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(x4.encodingLength(W));if(!G)G=0;return g0.encode(W,Y,G+2),Y.writeUInt16BE(g0.encode.bytes,G),x4.encode.bytes=g0.encode.bytes+2,Y};x4.encode.bytes=0;x4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X=g0.decode(W,Y+2);return x4.decode.bytes=G+2,X};x4.decode.bytes=0;x4.encodingLength=function(W){return g0.encodingLength(W)+2};var k4=Zd.soa={};k4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(k4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.mname,Y,G),G+=g0.encode.bytes,g0.encode(W.rname,Y,G,{mail:!0}),G+=g0.encode.bytes,Y.writeUInt32BE(W.serial||0,G),G+=4,Y.writeUInt32BE(W.refresh||0,G),G+=4,Y.writeUInt32BE(W.retry||0,G),G+=4,Y.writeUInt32BE(W.expire||0,G),G+=4,Y.writeUInt32BE(W.minimum||0,G),G+=4,Y.writeUInt16BE(G-X-2,X),k4.encode.bytes=G-X,Y};k4.encode.bytes=0;k4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.mname=g0.decode(W,Y),Y+=g0.decode.bytes,X.rname=g0.decode(W,Y,{mail:!0}),Y+=g0.decode.bytes,X.serial=W.readUInt32BE(Y),Y+=4,X.refresh=W.readUInt32BE(Y),Y+=4,X.retry=W.readUInt32BE(Y),Y+=4,X.expire=W.readUInt32BE(Y),Y+=4,X.minimum=W.readUInt32BE(Y),Y+=4,k4.decode.bytes=Y-G,X};k4.decode.bytes=0;k4.encodingLength=function(W){return 22+g0.encodingLength(W.mname)+g0.encodingLength(W.rname)};var _4=Zd.txt={};_4.encode=function(W,Y,G){if(!Array.isArray(W))W=[W];for(let J=0;J<W.length;J++){if(typeof W[J]==="string")W[J]=Z1.from(W[J]);if(!Z1.isBuffer(W[J]))throw Error("Must be a Buffer")}if(!Y)Y=Z1.alloc(_4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,W.forEach(function(J){Y[G++]=J.length,J.copy(Y,G,0,J.length),G+=J.length}),Y.writeUInt16BE(G-X-2,X),_4.encode.bytes=G-X,Y};_4.encode.bytes=0;_4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=W.readUInt16BE(Y);Y+=2;let J=[];while(X>0){let Z=W[Y++];if(--X,X<Z)throw Error("Buffer overflow");J.push(W.slice(Y,Y+Z)),Y+=Z,X-=Z}return _4.decode.bytes=Y-G,J};_4.decode.bytes=0;_4.encodingLength=function(W){if(!Array.isArray(W))W=[W];let Y=2;return W.forEach(function(G){if(typeof G==="string")Y+=Z1.byteLength(G)+1;else Y+=G.length+1}),Y};var y4=Zd.null={};y4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(y4.encodingLength(W));if(!G)G=0;if(typeof W==="string")W=Z1.from(W);if(!W)W=Z1.alloc(0);let X=G;G+=2;let J=W.length;return W.copy(Y,G,0,J),G+=J,Y.writeUInt16BE(G-X-2,X),y4.encode.bytes=G-X,Y};y4.encode.bytes=0;y4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=W.readUInt16BE(Y);Y+=2;let J=W.slice(Y,Y+X);return Y+=X,y4.decode.bytes=Y-G,J};y4.decode.bytes=0;y4.encodingLength=function(W){if(!W)return 2;return(Z1.isBuffer(W)?W.length:Z1.byteLength(W))+2};var v4=Zd.hinfo={};v4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(v4.encodingLength(W));if(!G)G=0;let X=G;return G+=2,S1.encode(W.cpu,Y,G),G+=S1.encode.bytes,S1.encode(W.os,Y,G),G+=S1.encode.bytes,Y.writeUInt16BE(G-X-2,X),v4.encode.bytes=G-X,Y};v4.encode.bytes=0;v4.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.cpu=S1.decode(W,Y),Y+=S1.decode.bytes,X.os=S1.decode(W,Y),Y+=S1.decode.bytes,v4.decode.bytes=Y-G,X};v4.decode.bytes=0;v4.encodingLength=function(W){return S1.encodingLength(W.cpu)+S1.encodingLength(W.os)+2};var r5=Zd.ptr={},Xd=Zd.cname=r5,Jd=Zd.dname=r5;r5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(r5.encodingLength(W));if(!G)G=0;return g0.encode(W,Y,G+2),Y.writeUInt16BE(g0.encode.bytes,G),r5.encode.bytes=g0.encode.bytes+2,Y};r5.encode.bytes=0;r5.decode=function(W,Y){if(!Y)Y=0;let G=g0.decode(W,Y+2);return r5.decode.bytes=g0.decode.bytes+2,G};r5.decode.bytes=0;r5.encodingLength=function(W){return g0.encodingLength(W)+2};var g4=Zd.srv={};g4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g4.encodingLength(W));if(!G)G=0;Y.writeUInt16BE(W.priority||0,G+2),Y.writeUInt16BE(W.weight||0,G+4),Y.writeUInt16BE(W.port||0,G+6),g0.encode(W.target,Y,G+8);let X=g0.encode.bytes+6;return Y.writeUInt16BE(X,G),g4.encode.bytes=X+2,Y};g4.encode.bytes=0;g4.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y),X={};return X.priority=W.readUInt16BE(Y+2),X.weight=W.readUInt16BE(Y+4),X.port=W.readUInt16BE(Y+6),X.target=g0.decode(W,Y+8),g4.decode.bytes=G+2,X};g4.decode.bytes=0;g4.encodingLength=function(W){return 8+g0.encodingLength(W.target)};var H5=Zd.caa={};H5.ISSUER_CRITICAL=128;H5.encode=function(W,Y,G){let X=H5.encodingLength(W);if(!Y)Y=Z1.alloc(H5.encodingLength(W));if(!G)G=0;if(W.issuerCritical)W.flags=H5.ISSUER_CRITICAL;return Y.writeUInt16BE(X-2,G),G+=2,Y.writeUInt8(W.flags||0,G),G+=1,S1.encode(W.tag,Y,G),G+=S1.encode.bytes,Y.write(W.value,G),G+=Z1.byteLength(W.value),H5.encode.bytes=X,Y};H5.encode.bytes=0;H5.decode=function(W,Y){if(!Y)Y=0;let G=W.readUInt16BE(Y);Y+=2;let X=Y,J={};return J.flags=W.readUInt8(Y),Y+=1,J.tag=S1.decode(W,Y),Y+=S1.decode.bytes,J.value=W.toString("utf-8",Y,X+G),J.issuerCritical=!!(J.flags&H5.ISSUER_CRITICAL),H5.decode.bytes=G+2,J};H5.decode.bytes=0;H5.encodingLength=function(W){return S1.encodingLength(W.tag)+S1.encodingLength(W.value)+2};var o6=Zd.mx={};o6.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(o6.encodingLength(W));if(!G)G=0;let X=G;return G+=2,Y.writeUInt16BE(W.preference||0,G),G+=2,g0.encode(W.exchange,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(G-X-2,X),o6.encode.bytes=G-X,Y};o6.encode.bytes=0;o6.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.preference=W.readUInt16BE(Y),Y+=2,X.exchange=g0.decode(W,Y),Y+=g0.decode.bytes,o6.decode.bytes=Y-G,X};o6.encodingLength=function(W){return 4+g0.encodingLength(W.exchange)};var u4=Zd.a={};u4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(u4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(4,G),G+=2,wY.v4.encode(W,Y,G),u4.encode.bytes=6,Y};u4.encode.bytes=0;u4.decode=function(W,Y){if(!Y)Y=0;Y+=2;let G=wY.v4.decode(W,Y);return u4.decode.bytes=6,G};u4.decode.bytes=0;u4.encodingLength=function(){return 6};var h4=Zd.aaaa={};h4.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(h4.encodingLength(W));if(!G)G=0;return Y.writeUInt16BE(16,G),G+=2,wY.v6.encode(W,Y,G),h4.encode.bytes=18,Y};h4.encode.bytes=0;h4.decode=function(W,Y){if(!Y)Y=0;Y+=2;let G=wY.v6.decode(W,Y);return h4.decode.bytes=18,G};h4.decode.bytes=0;h4.encodingLength=function(){return 18};var r9=Zd.option={};r9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(r9.encodingLength(W));if(!G)G=0;let X=G,J=ej.toCode(W.code);if(Y.writeUInt16BE(J,G),G+=2,W.data)Y.writeUInt16BE(W.data.length,G),G+=2,W.data.copy(Y,G),G+=W.data.length;else switch(J){case 8:let Z=W.sourcePrefixLength||0,V=W.family||wY.familyOf(W.ip),U=wY.encode(W.ip,Z1.alloc),Q=Math.ceil(Z/8);Y.writeUInt16BE(Q+4,G),G+=2,Y.writeUInt16BE(V,G),G+=2,Y.writeUInt8(Z,G++),Y.writeUInt8(W.scopePrefixLength||0,G++),U.copy(Y,G,0,Q),G+=Q;break;case 11:if(W.timeout)Y.writeUInt16BE(2,G),G+=2,Y.writeUInt16BE(W.timeout,G),G+=2;else Y.writeUInt16BE(0,G),G+=2;break;case 12:let H=W.length||0;Y.writeUInt16BE(H,G),G+=2,Y.fill(0,G,G+H),G+=H;break;case 14:let N=W.tags.length*2;Y.writeUInt16BE(N,G),G+=2;for(let A of W.tags)Y.writeUInt16BE(A,G),G+=2;break;default:throw Error(`Unknown roption code: ${W.code}`)}return r9.encode.bytes=G-X,Y};r9.encode.bytes=0;r9.decode=function(W,Y){if(!Y)Y=0;let G={};G.code=W.readUInt16BE(Y),G.type=ej.toString(G.code),Y+=2;let X=W.readUInt16BE(Y);switch(Y+=2,G.data=W.slice(Y,Y+X),G.code){case 8:G.family=W.readUInt16BE(Y),Y+=2,G.sourcePrefixLength=W.readUInt8(Y++),G.scopePrefixLength=W.readUInt8(Y++);let J=Z1.alloc(G.family===1?4:16);W.copy(J,0,Y,Y+X-4),G.ip=wY.decode(J);break;case 11:if(X>0)G.timeout=W.readUInt16BE(Y),Y+=2;break;case 14:G.tags=[];for(let Z=0;Z<X;Z+=2)G.tags.push(W.readUInt16BE(Y)),Y+=2}return r9.decode.bytes=X+4,G};r9.decode.bytes=0;r9.encodingLength=function(W){if(W.data)return W.data.length+4;switch(ej.toCode(W.code)){case 8:let G=W.sourcePrefixLength||0;return Math.ceil(G/8)+8;case 11:return typeof W.timeout==="number"?6:4;case 12:return W.length+4;case 14:return 4+W.tags.length*2}throw Error(`Unknown roption code: ${W.code}`)};var q5=Zd.opt={};q5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(q5.encodingLength(W));if(!G)G=0;let X=G,J=EX(W,r9);return Y.writeUInt16BE(J,G),G=SV(W,r9,Y,G+2),q5.encode.bytes=G-X,Y};q5.encode.bytes=0;q5.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=[],J=W.readUInt16BE(Y);Y+=2;let Z=0;while(J>0)X[Z++]=r9.decode(W,Y),Y+=r9.decode.bytes,J-=r9.decode.bytes;return q5.decode.bytes=Y-G,X};q5.decode.bytes=0;q5.encodingLength=function(W){return 2+EX(W||[],r9)};var g9=Zd.dnskey={};g9.PROTOCOL_DNSSEC=3;g9.ZONE_KEY=128;g9.SECURE_ENTRYPOINT=32768;g9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g9.encodingLength(W));if(!G)G=0;let X=G,J=W.key;if(!Z1.isBuffer(J))throw Error("Key must be a Buffer");return G+=2,Y.writeUInt16BE(W.flags,G),G+=2,Y.writeUInt8(g9.PROTOCOL_DNSSEC,G),G+=1,Y.writeUInt8(W.algorithm,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,g9.encode.bytes=G-X,Y.writeUInt16BE(g9.encode.bytes-2,X),Y};g9.encode.bytes=0;g9.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);if(Y+=2,X.flags=W.readUInt16BE(Y),Y+=2,W.readUInt8(Y)!==g9.PROTOCOL_DNSSEC)throw Error("Protocol must be 3");return Y+=1,X.algorithm=W.readUInt8(Y),Y+=1,X.key=W.slice(Y,G+J+2),Y+=X.key.length,g9.decode.bytes=Y-G,X};g9.decode.bytes=0;g9.encodingLength=function(W){return 6+Z1.byteLength(W.key)};var _7=Zd.rrsig={};_7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(_7.encodingLength(W));if(!G)G=0;let X=G,J=W.signature;if(!Z1.isBuffer(J))throw Error("Signature must be a Buffer");return G+=2,Y.writeUInt16BE(b4.toType(W.typeCovered),G),G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.labels,G),G+=1,Y.writeUInt32BE(W.originalTTL,G),G+=4,Y.writeUInt32BE(W.expiration,G),G+=4,Y.writeUInt32BE(W.inception,G),G+=4,Y.writeUInt16BE(W.keyTag,G),G+=2,g0.encode(W.signersName,Y,G),G+=g0.encode.bytes,J.copy(Y,G,0,J.length),G+=J.length,_7.encode.bytes=G-X,Y.writeUInt16BE(_7.encode.bytes-2,X),Y};_7.encode.bytes=0;_7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.typeCovered=b4.toString(W.readUInt16BE(Y)),Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.labels=W.readUInt8(Y),Y+=1,X.originalTTL=W.readUInt32BE(Y),Y+=4,X.expiration=W.readUInt32BE(Y),Y+=4,X.inception=W.readUInt32BE(Y),Y+=4,X.keyTag=W.readUInt16BE(Y),Y+=2,X.signersName=g0.decode(W,Y),Y+=g0.decode.bytes,X.signature=W.slice(Y,G+J+2),Y+=X.signature.length,_7.decode.bytes=Y-G,X};_7.decode.bytes=0;_7.encodingLength=function(W){return 20+g0.encodingLength(W.signersName)+Z1.byteLength(W.signature)};var y7=Zd.rp={};y7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(y7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.mbox||".",Y,G,{mail:!0}),G+=g0.encode.bytes,g0.encode(W.txt||".",Y,G),G+=g0.encode.bytes,y7.encode.bytes=G-X,Y.writeUInt16BE(y7.encode.bytes-2,X),Y};y7.encode.bytes=0;y7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.mbox=g0.decode(W,Y,{mail:!0})||".",Y+=g0.decode.bytes,X.txt=g0.decode(W,Y)||".",Y+=g0.decode.bytes,y7.decode.bytes=Y-G,X};y7.decode.bytes=0;y7.encodingLength=function(W){return 2+g0.encodingLength(W.mbox||".")+g0.encodingLength(W.txt||".")};var i8={};i8.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(i8.encodingLength(W));if(!G)G=0;let X=G;var J=[];for(var Z=0;Z<W.length;Z++){var V=b4.toType(W[Z]);if(J[V>>8]===void 0)J[V>>8]=[];J[V>>8][V>>3&31]|=1<<7-(V&7)}for(Z=0;Z<J.length;Z++)if(J[Z]!==void 0){var U=Z1.from(J[Z]);Y.writeUInt8(Z,G),G+=1,Y.writeUInt8(U.length,G),G+=1,U.copy(Y,G),G+=U.length}return i8.encode.bytes=G-X,Y};i8.encode.bytes=0;i8.decode=function(W,Y,G){if(!Y)Y=0;let X=Y;var J=[];while(Y-X<G){var Z=W.readUInt8(Y);Y+=1;var V=W.readUInt8(Y);Y+=1;for(var U=0;U<V;U++){var Q=W.readUInt8(Y+U);for(var H=0;H<8;H++)if(Q&1<<7-H){var N=b4.toString(Z<<8|U<<3|H);J.push(N)}}Y+=V}return i8.decode.bytes=Y-X,J};i8.decode.bytes=0;i8.encodingLength=function(W){var Y=[];for(var G=0;G<W.length;G++){var X=b4.toType(W[G]);Y[X>>8]=Math.max(Y[X>>8]||0,X&255)}var J=0;for(G=0;G<Y.length;G++)if(Y[G]!==void 0)J+=2+Math.ceil((Y[G]+1)/8);return J};var v7=Zd.nsec={};v7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(v7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,g0.encode(W.nextDomain,Y,G),G+=g0.encode.bytes,i8.encode(W.rrtypes,Y,G),G+=i8.encode.bytes,v7.encode.bytes=G-X,Y.writeUInt16BE(v7.encode.bytes-2,X),Y};v7.encode.bytes=0;v7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.nextDomain=g0.decode(W,Y),Y+=g0.decode.bytes,X.rrtypes=i8.decode(W,Y,J-(Y-G)),Y+=i8.decode.bytes,v7.decode.bytes=Y-G,X};v7.decode.bytes=0;v7.encodingLength=function(W){return 2+g0.encodingLength(W.nextDomain)+i8.encodingLength(W.rrtypes)};var g7=Zd.nsec3={};g7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(g7.encodingLength(W));if(!G)G=0;let X=G,J=W.salt;if(!Z1.isBuffer(J))throw Error("salt must be a Buffer");let Z=W.nextDomain;if(!Z1.isBuffer(Z))throw Error("nextDomain must be a Buffer");return G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.flags,G),G+=1,Y.writeUInt16BE(W.iterations,G),G+=2,Y.writeUInt8(J.length,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,Y.writeUInt8(Z.length,G),G+=1,Z.copy(Y,G,0,Z.length),G+=Z.length,i8.encode(W.rrtypes,Y,G),G+=i8.encode.bytes,g7.encode.bytes=G-X,Y.writeUInt16BE(g7.encode.bytes-2,X),Y};g7.encode.bytes=0;g7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.flags=W.readUInt8(Y),Y+=1,X.iterations=W.readUInt16BE(Y),Y+=2;let Z=W.readUInt8(Y);Y+=1,X.salt=W.slice(Y,Y+Z),Y+=Z;let V=W.readUInt8(Y);return Y+=1,X.nextDomain=W.slice(Y,Y+V),Y+=V,X.rrtypes=i8.decode(W,Y,J-(Y-G)),Y+=i8.decode.bytes,g7.decode.bytes=Y-G,X};g7.decode.bytes=0;g7.encodingLength=function(W){return 8+W.salt.length+W.nextDomain.length+i8.encodingLength(W.rrtypes)};var u7=Zd.ds={};u7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(u7.encodingLength(W));if(!G)G=0;let X=G,J=W.digest;if(!Z1.isBuffer(J))throw Error("Digest must be a Buffer");return G+=2,Y.writeUInt16BE(W.keyTag,G),G+=2,Y.writeUInt8(W.algorithm,G),G+=1,Y.writeUInt8(W.digestType,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,u7.encode.bytes=G-X,Y.writeUInt16BE(u7.encode.bytes-2,X),Y};u7.encode.bytes=0;u7.decode=function(W,Y){if(!Y)Y=0;let G=Y;var X={},J=W.readUInt16BE(Y);return Y+=2,X.keyTag=W.readUInt16BE(Y),Y+=2,X.algorithm=W.readUInt8(Y),Y+=1,X.digestType=W.readUInt8(Y),Y+=1,X.digest=W.slice(Y,G+J+2),Y+=X.digest.length,u7.decode.bytes=Y-G,X};u7.decode.bytes=0;u7.encodingLength=function(W){return 6+Z1.byteLength(W.digest)};var N5=Zd.sshfp={};N5.getFingerprintLengthForHashType=function(Y){switch(Y){case 1:return 20;case 2:return 32}};N5.encode=function(Y,G,X){if(!G)G=Z1.alloc(N5.encodingLength(Y));if(!X)X=0;let J=X;X+=2,G[X]=Y.algorithm,X+=1,G[X]=Y.hash,X+=1;let Z=Z1.from(Y.fingerprint.toUpperCase(),"hex");if(Z.length!==N5.getFingerprintLengthForHashType(Y.hash))throw Error("Invalid fingerprint length");return Z.copy(G,X),X+=Z.byteLength,N5.encode.bytes=X-J,G.writeUInt16BE(N5.encode.bytes-2,J),G};N5.encode.bytes=0;N5.decode=function(Y,G){if(!G)G=0;let X=G,J={};G+=2,J.algorithm=Y[G],G+=1,J.hash=Y[G],G+=1;let Z=N5.getFingerprintLengthForHashType(J.hash);return J.fingerprint=Y.slice(G,G+Z).toString("hex").toUpperCase(),G+=Z,N5.decode.bytes=G-X,J};N5.decode.bytes=0;N5.encodingLength=function(W){return 4+Z1.from(W.fingerprint,"hex").byteLength};var h7=Zd.naptr={};h7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(h7.encodingLength(W));if(!G)G=0;let X=G;return G+=2,Y.writeUInt16BE(W.order||0,G),G+=2,Y.writeUInt16BE(W.preference||0,G),G+=2,S1.encode(W.flags,Y,G),G+=S1.encode.bytes,S1.encode(W.services,Y,G),G+=S1.encode.bytes,S1.encode(W.regexp,Y,G),G+=S1.encode.bytes,g0.encode(W.replacement,Y,G),G+=g0.encode.bytes,h7.encode.bytes=G-X,Y.writeUInt16BE(h7.encode.bytes-2,X),Y};h7.encode.bytes=0;h7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};return Y+=2,X.order=W.readUInt16BE(Y),Y+=2,X.preference=W.readUInt16BE(Y),Y+=2,X.flags=S1.decode(W,Y),Y+=S1.decode.bytes,X.services=S1.decode(W,Y),Y+=S1.decode.bytes,X.regexp=S1.decode(W,Y),Y+=S1.decode.bytes,X.replacement=g0.decode(W,Y),Y+=g0.decode.bytes,h7.decode.bytes=Y-G,X};h7.decode.bytes=0;h7.encodingLength=function(W){return S1.encodingLength(W.flags)+S1.encodingLength(W.services)+S1.encodingLength(W.regexp)+g0.encodingLength(W.replacement)+6};var b7=Zd.tlsa={};b7.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(b7.encodingLength(W));if(!G)G=0;let X=G,J=W.certificate;if(!Z1.isBuffer(J))throw Error("Certificate must be a Buffer");return G+=2,Y.writeUInt8(W.usage,G),G+=1,Y.writeUInt8(W.selector,G),G+=1,Y.writeUInt8(W.matchingType,G),G+=1,J.copy(Y,G,0,J.length),G+=J.length,b7.encode.bytes=G-X,Y.writeUInt16BE(b7.encode.bytes-2,X),Y};b7.encode.bytes=0;b7.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={},J=W.readUInt16BE(Y);return Y+=2,X.usage=W.readUInt8(Y),Y+=1,X.selector=W.readUInt8(Y),Y+=1,X.matchingType=W.readUInt8(Y),Y+=1,X.certificate=W.slice(Y,G+J+2),Y+=X.certificate.length,b7.decode.bytes=Y-G,X};b7.decode.bytes=0;b7.encodingLength=function(W){return 5+Z1.byteLength(W.certificate)};var WO=Zd.record=function(W){switch(W.toUpperCase()){case"A":return u4;case"PTR":return r5;case"CNAME":return Xd;case"DNAME":return Jd;case"TXT":return _4;case"NULL":return y4;case"AAAA":return h4;case"SRV":return g4;case"HINFO":return v4;case"CAA":return H5;case"NS":return x4;case"SOA":return k4;case"MX":return o6;case"OPT":return q5;case"DNSKEY":return g9;case"RRSIG":return _7;case"RP":return y7;case"NSEC":return v7;case"NSEC3":return g7;case"SSHFP":return N5;case"DS":return u7;case"NAPTR":return h7;case"TLSA":return b7}return S4},J9=Zd.answer={};J9.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(J9.encodingLength(W));if(!G)G=0;let X=G;if(g0.encode(W.name,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(b4.toType(W.type),G),W.type.toUpperCase()==="OPT"){if(W.name!==".")throw Error("OPT name must be root.");Y.writeUInt16BE(W.udpPayloadSize||4096,G+2),Y.writeUInt8(W.extendedRcode||0,G+4),Y.writeUInt8(W.ednsVersion||0,G+5),Y.writeUInt16BE(W.flags||0,G+6),G+=8,q5.encode(W.options||[],Y,G),G+=q5.encode.bytes}else{let J=EN.toClass(W.class===void 0?"IN":W.class);if(W.flush)J|=32768;Y.writeUInt16BE(J,G+2),Y.writeUInt32BE(W.ttl||0,G+4),G+=8;let Z=WO(W.type);Z.encode(W.data,Y,G),G+=Z.encode.bytes}return J9.encode.bytes=G-X,Y};J9.encode.bytes=0;J9.decode=function(W,Y){if(!Y)Y=0;let G={},X=Y;if(G.name=g0.decode(W,Y),Y+=g0.decode.bytes,G.type=b4.toString(W.readUInt16BE(Y)),G.type==="OPT")G.udpPayloadSize=W.readUInt16BE(Y+2),G.extendedRcode=W.readUInt8(Y+4),G.ednsVersion=W.readUInt8(Y+5),G.flags=W.readUInt16BE(Y+6),G.flag_do=(G.flags>>15&1)===1,G.options=q5.decode(W,Y+8),Y+=8+q5.decode.bytes;else{let J=W.readUInt16BE(Y+2);G.ttl=W.readUInt32BE(Y+4),G.class=EN.toString(J&-32769),G.flush=!!(J&32768);let Z=WO(G.type);G.data=Z.decode(W,Y+8),Y+=8+Z.decode.bytes}return J9.decode.bytes=Y-X,G};J9.decode.bytes=0;J9.encodingLength=function(W){let Y=W.data!==null&&W.data!==void 0?W.data:W.options;return g0.encodingLength(W.name)+8+WO(W.type).encodingLength(Y)};var a5=Zd.question={};a5.encode=function(W,Y,G){if(!Y)Y=Z1.alloc(a5.encodingLength(W));if(!G)G=0;let X=G;return g0.encode(W.name,Y,G),G+=g0.encode.bytes,Y.writeUInt16BE(b4.toType(W.type),G),G+=2,Y.writeUInt16BE(EN.toClass(W.class===void 0?"IN":W.class),G),G+=2,a5.encode.bytes=G-X,W};a5.encode.bytes=0;a5.decode=function(W,Y){if(!Y)Y=0;let G=Y,X={};if(X.name=g0.decode(W,Y),Y+=g0.decode.bytes,X.type=b4.toString(W.readUInt16BE(Y)),Y+=2,X.class=EN.toString(W.readUInt16BE(Y)),Y+=2,!!(X.class&32768))X.class&=-32769;return a5.decode.bytes=Y-G,X};a5.decode.bytes=0;a5.encodingLength=function(W){return g0.encodingLength(W.name)+4};Zd.AUTHORITATIVE_ANSWER=1024;Zd.TRUNCATED_RESPONSE=512;Zd.RECURSION_DESIRED=256;Zd.RECURSION_AVAILABLE=128;Zd.AUTHENTIC_DATA=32;Zd.CHECKING_DISABLED=16;Zd.DNSSEC_OK=32768;Zd.encode=function(W,Y,G){let X=!Y;if(X)Y=Z1.alloc(Zd.encodingLength(W));if(!G)G=0;let J=G;if(!W.questions)W.questions=[];if(!W.answers)W.answers=[];if(!W.authorities)W.authorities=[];if(!W.additionals)W.additionals=[];if(s5.encode(W,Y,G),G+=s5.encode.bytes,G=SV(W.questions,a5,Y,G),G=SV(W.answers,J9,Y,G),G=SV(W.authorities,J9,Y,G),G=SV(W.additionals,J9,Y,G),Zd.encode.bytes=G-J,X&&Zd.encode.bytes!==Y.length)return Y.slice(0,Zd.encode.bytes);return Y};Zd.encode.bytes=0;Zd.decode=function(W,Y){if(!Y)Y=0;let G=Y,X=s5.decode(W,Y);return Y+=s5.decode.bytes,Y=BN(X.questions,a5,W,Y),Y=BN(X.answers,J9,W,Y),Y=BN(X.authorities,J9,W,Y),Y=BN(X.additionals,J9,W,Y),Zd.decode.bytes=Y-G,X};Zd.decode.bytes=0;Zd.encodingLength=function(W){return s5.encodingLength(W)+EX(W.questions||[],a5)+EX(W.answers||[],J9)+EX(W.authorities||[],J9)+EX(W.additionals||[],J9)};Zd.streamEncode=function(W){let Y=Zd.encode(W),G=Z1.alloc(2);G.writeUInt16BE(Y.byteLength);let X=Z1.concat([G,Y]);return Zd.streamEncode.bytes=X.byteLength,X};Zd.streamEncode.bytes=0;Zd.streamDecode=function(W){let Y=W.readUInt16BE(0);if(W.byteLength<Y+2)return null;let G=Zd.decode(W.slice(2));return Zd.streamDecode.bytes=Zd.decode.bytes,G};Zd.streamDecode.bytes=0;function EX(W,Y){let G=0;for(let X=0;X<W.length;X++)G+=Y.encodingLength(W[X]);return G}function SV(W,Y,G,X){for(let J=0;J<W.length;J++)Y.encode(W[J],G,X),X+=Y.encode.bytes;return X}function BN(W,Y,G,X){for(let J=0;J<W.length;J++)W[J]=Y.decode(G,X),X+=Y.decode.bytes;return X}});var y$=U1((Dq0,_$)=>{var k$=Dd;process.nextTick(Kd,42);_$.exports=zd;function zd(W){var Y=X;return G;function G(J){Y(J||jd)}function X(J){var Z=[J];Y=V,W(U);function V(Q){Z.push(Q)}function U(Q){var H=arguments;Y=wd(Q)?X:N;while(Z.length)N(Z.shift());function N(A){k$(Od,A,H)}}}}function wd(W){return Object.prototype.toString.call(W)==="[object Error]"}function jd(){}function Od(W,Y){W.apply(null,Y)}function Kd(W){if(W===42)k$=process.nextTick}function Dd(W,Y,G){process.nextTick(function(){W(Y,G)})}});var u$=U1((Cq0,g$)=>{var YO=x$(),Cd=x8("dgram"),Td=y$(),Rd=x8("events"),XO=x8("os"),GO=function(){};g$.exports=function(W){if(!W)W={};var Y=new Rd.EventEmitter,G=typeof W.port==="number"?W.port:5353,X=W.type||"udp4",J=W.ip||W.host||(X==="udp4"?"224.0.0.251":null),Z={address:J,port:G},V={},U=!1,Q=null;if(X==="udp6"&&(!J||!W.interface))throw Error("For IPv6 multicast you must specify `ip` and `interface`");var H=W.socket||Cd.createSocket({type:X,reuseAddr:W.reuseAddr!==!1,toString:function(){return X}});H.on("error",function(A){if(A.code==="EACCES"||A.code==="EADDRINUSE")Y.emit("error",A);else Y.emit("warning",A)}),H.on("message",function(A,q){try{A=YO.decode(A)}catch(z){Y.emit("warning",z);return}if(Y.emit("packet",A,q),A.type==="query")Y.emit("query",A,q);if(A.type==="response")Y.emit("response",A,q)}),H.on("listening",function(){if(!G)G=Z.port=H.address().port;if(W.multicast!==!1)Y.update(),Q=setInterval(Y.update,5000),H.setMulticastTTL(W.ttl||255),H.setMulticastLoopback(W.loopback!==!1)});var N=Td(function(A){if(!G||W.bind===!1)return A(null);H.once("error",A),H.bind(G,W.bind||W.interface,function(){H.removeListener("error",A),A(null)})});return N(function(A){if(A)return Y.emit("error",A);Y.emit("ready")}),Y.send=function(A,q,z){if(typeof q==="function")return Y.send(A,null,q);if(!z)z=GO;if(!q)q=Z;else if(!q.host&&!q.address)q.address=Z.address;N(w);function w(D){if(U)return z();if(D)return z(D);var T=YO.encode(A);H.send(T,0,T.length,q.port,q.address||q.host,z)}},Y.response=Y.respond=function(A,q,z){if(Array.isArray(A))A={answers:A};A.type="response",A.flags=(A.flags||0)|YO.AUTHORITATIVE_ANSWER,Y.send(A,q,z)},Y.query=function(A,q,z,w){if(typeof q==="function")return Y.query(A,null,null,q);if(typeof q==="object"&&q&&q.port)return Y.query(A,null,q,z);if(typeof z==="function")return Y.query(A,q,null,z);if(!w)w=GO;if(typeof A==="string")A=[{name:A,type:q||"ANY"}];if(Array.isArray(A))A={type:"query",questions:A};A.type="query",Y.send(A,z,w)},Y.destroy=function(A){if(!A)A=GO;if(U)return process.nextTick(A);U=!0,clearInterval(Q);for(var q in V)try{H.dropMembership(J,q)}catch(z){}V={},H.close(A)},Y.update=function(){var A=W.interface?[].concat(W.interface):Pd(),q=!1;for(var z=0;z<A.length;z++){var w=A[z];if(V[w])continue;try{H.addMembership(J,w),V[w]=!0,q=!0}catch(D){Y.emit("warning",D)}}if(q){if(H.setMulticastInterface)try{H.setMulticastInterface(W.interface||Md())}catch(D){Y.emit("warning",D)}Y.emit("networkInterface")}},Y};function Md(){var W=XO.networkInterfaces(),Y=Object.keys(W);for(var G=0;G<Y.length;G++){var X=W[Y[G]];for(var J=0;J<X.length;J++){var Z=X[J];if(v$(Z.family)&&!Z.internal){if(XO.platform()==="darwin"&&Y[G]==="en0")return Z.address;return"0.0.0.0"}}}return"127.0.0.1"}function Pd(){var W=XO.networkInterfaces(),Y=Object.keys(W),G=[];for(var X=0;X<Y.length;X++){var J=W[Y[X]];for(var Z=0;Z<J.length;Z++){var V=J[Z];if(v$(V.family)){G.push(V.address);break}}}return G}function v$(W){return W===4||W==="IPv4"}});import{Database as jt}from"bun:sqlite";import{mkdirSync as Ot}from"fs";import{dirname as Kt}from"path";function QD(W){let Y=W.length,G=0,X=0;while(X<Y){let J=W.charCodeAt(X++);if((J&4294967168)===0){G++;continue}else if((J&4294965248)===0)G+=2;else{if(J>=55296&&J<=56319){if(X<Y){let Z=W.charCodeAt(X);if((Z&64512)===56320)++X,J=((J&1023)<<10)+(Z&1023)+65536}}if((J&4294901760)===0)G+=3;else G+=4}}return G}function u_(W,Y,G){let X=W.length,J=G,Z=0;while(Z<X){let V=W.charCodeAt(Z++);if((V&4294967168)===0){Y[J++]=V;continue}else if((V&4294965248)===0)Y[J++]=V>>6&31|192;else{if(V>=55296&&V<=56319){if(Z<X){let U=W.charCodeAt(Z);if((U&64512)===56320)++Z,V=((V&1023)<<10)+(U&1023)+65536}}if((V&4294901760)===0)Y[J++]=V>>12&15|224,Y[J++]=V>>6&63|128;else Y[J++]=V>>18&7|240,Y[J++]=V>>12&63|128,Y[J++]=V>>6&63|128}Y[J++]=V&63|128}}var h_=new TextEncoder,b_=50;function m_(W,Y,G){h_.encodeInto(W,Y.subarray(G))}function HD(W,Y,G){if(W.length>b_)m_(W,Y,G);else u_(W,Y,G)}var f_=4096;function qA(W,Y,G){let X=Y,J=X+G,Z=[],V="";while(X<J){let U=W[X++];if((U&128)===0)Z.push(U);else if((U&224)===192){let Q=W[X++]&63;Z.push((U&31)<<6|Q)}else if((U&240)===224){let Q=W[X++]&63,H=W[X++]&63;Z.push((U&31)<<12|Q<<6|H)}else if((U&248)===240){let Q=W[X++]&63,H=W[X++]&63,N=W[X++]&63,A=(U&7)<<18|Q<<12|H<<6|N;if(A>65535)A-=65536,Z.push(A>>>10&1023|55296),A=56320|A&1023;Z.push(A)}else Z.push(U);if(Z.length>=f_)V+=String.fromCharCode(...Z),Z.length=0}if(Z.length>0)V+=String.fromCharCode(...Z);return V}var c_=new TextDecoder,p_=200;function l_(W,Y,G){let X=W.subarray(Y,Y+G);return c_.decode(X)}function ND(W,Y,G){if(G>p_)return l_(W,Y,G);else return qA(W,Y,G)}class pY{type;data;constructor(W,Y){this.type=W,this.data=Y}}class S9 extends Error{constructor(W){super(W);let Y=Object.create(S9.prototype);Object.setPrototypeOf(this,Y),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:S9.name})}}var lY=4294967295;function qD(W,Y,G){let X=G/4294967296,J=G;W.setUint32(Y,X),W.setUint32(Y+4,J)}function yU(W,Y,G){let X=Math.floor(G/4294967296),J=G;W.setUint32(Y,X),W.setUint32(Y+4,J)}function vU(W,Y){let G=W.getInt32(Y),X=W.getUint32(Y+4);return G*4294967296+X}function AD(W,Y){let G=W.getUint32(Y),X=W.getUint32(Y+4);return G*4294967296+X}var d_=-1,o_=4294967295,n_=17179869183;function i_({sec:W,nsec:Y}){if(W>=0&&Y>=0&&W<=n_)if(Y===0&&W<=o_){let G=new Uint8Array(4);return new DataView(G.buffer).setUint32(0,W),G}else{let G=W/4294967296,X=W&4294967295,J=new Uint8Array(8),Z=new DataView(J.buffer);return Z.setUint32(0,Y<<2|G&3),Z.setUint32(4,X),J}else{let G=new Uint8Array(12),X=new DataView(G.buffer);return X.setUint32(0,Y),yU(X,4,W),G}}function r_(W){let Y=W.getTime(),G=Math.floor(Y/1000),X=(Y-G*1000)*1e6,J=Math.floor(X/1e9);return{sec:G+J,nsec:X-J*1e9}}function a_(W){if(W instanceof Date){let Y=r_(W);return i_(Y)}else return null}function s_(W){let Y=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let G=Y.getUint32(0),X=0;return{sec:G,nsec:0}}case 8:{let G=Y.getUint32(0),X=Y.getUint32(4),J=(G&3)*4294967296+X,Z=G>>>2;return{sec:J,nsec:Z}}case 12:{let G=vU(Y,4),X=Y.getUint32(0);return{sec:G,nsec:X}}default:throw new S9(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function t_(W){let Y=s_(W);return new Date(Y.sec*1000+Y.nsec/1e6)}var ID={type:d_,encode:a_,decode:t_};class dY{static defaultCodec=new dY;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(ID)}register({type:W,encode:Y,decode:G}){if(W>=0)this.encoders[W]=Y,this.decoders[W]=G;else{let X=-1-W;this.builtInEncoders[X]=Y,this.builtInDecoders[X]=G}}tryToEncode(W,Y){for(let G=0;G<this.builtInEncoders.length;G++){let X=this.builtInEncoders[G];if(X!=null){let J=X(W,Y);if(J!=null){let Z=-1-G;return new pY(Z,J)}}}for(let G=0;G<this.encoders.length;G++){let X=this.encoders[G];if(X!=null){let J=X(W,Y);if(J!=null)return new pY(G,J)}}if(W instanceof pY)return W;return null}decode(W,Y,G){let X=Y<0?this.builtInDecoders[-1-Y]:this.decoders[Y];if(X)return X(W,Y,G);else return new pY(Y,W)}}function e_(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function UJ(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(e_(W))return new Uint8Array(W);else return Uint8Array.from(W)}var Wy=100,Yy=2048;class gU{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??dY.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??Wy,this.initialBufferSize=W?.initialBufferSize??Yy,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new gU({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,Y){if(Y>this.maxDepth)throw Error(`Too deep objects in depth ${Y}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,Y)}ensureBufferSizeToWrite(W){let Y=this.pos+W;if(this.view.byteLength<Y)this.resizeBuffer(Y*2)}resizeBuffer(W){let Y=new ArrayBuffer(W),G=new Uint8Array(Y),X=new DataView(Y);G.set(this.bytes),this.view=X,this.bytes=G}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let G=QD(W);this.ensureBufferSizeToWrite(5+G),this.writeStringHeader(G),HD(W,this.bytes,this.pos),this.pos+=G}encodeObject(W,Y){let G=this.extensionCodec.tryToEncode(W,this.context);if(G!=null)this.encodeExtension(G);else if(Array.isArray(W))this.encodeArray(W,Y);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,Y);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let Y=W.byteLength;if(Y<256)this.writeU8(196),this.writeU8(Y);else if(Y<65536)this.writeU8(197),this.writeU16(Y);else if(Y<4294967296)this.writeU8(198),this.writeU32(Y);else throw Error(`Too large binary: ${Y}`);let G=UJ(W);this.writeU8a(G)}encodeArray(W,Y){let G=W.length;if(G<16)this.writeU8(144+G);else if(G<65536)this.writeU8(220),this.writeU16(G);else if(G<4294967296)this.writeU8(221),this.writeU32(G);else throw Error(`Too large array: ${G}`);for(let X of W)this.doEncode(X,Y+1)}countWithoutUndefined(W,Y){let G=0;for(let X of Y)if(W[X]!==void 0)G++;return G}encodeMap(W,Y){let G=Object.keys(W);if(this.sortKeys)G.sort();let X=this.ignoreUndefined?this.countWithoutUndefined(W,G):G.length;if(X<16)this.writeU8(128+X);else if(X<65536)this.writeU8(222),this.writeU16(X);else if(X<4294967296)this.writeU8(223),this.writeU32(X);else throw Error(`Too large map object: ${X}`);for(let J of G){let Z=W[J];if(!(this.ignoreUndefined&&Z===void 0))this.encodeString(J),this.doEncode(Z,Y+1)}}encodeExtension(W){if(typeof W.data==="function"){let G=W.data(this.pos+6),X=G.length;if(X>=4294967296)throw Error(`Too large extension object: ${X}`);this.writeU8(201),this.writeU32(X),this.writeI8(W.type),this.writeU8a(G);return}let Y=W.data.length;if(Y===1)this.writeU8(212);else if(Y===2)this.writeU8(213);else if(Y===4)this.writeU8(214);else if(Y===8)this.writeU8(215);else if(Y===16)this.writeU8(216);else if(Y<256)this.writeU8(199),this.writeU8(Y);else if(Y<65536)this.writeU8(200),this.writeU16(Y);else if(Y<4294967296)this.writeU8(201),this.writeU32(Y);else throw Error(`Too large extension object: ${Y}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let Y=W.length;this.ensureBufferSizeToWrite(Y),this.bytes.set(W,this.pos),this.pos+=Y}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),qD(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),yU(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}function uU(W,Y){return new gU(Y).encodeSharedRef(W)}function hU(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}var Gy=16,Xy=16;class AA{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Gy,Y=Xy){this.maxKeyLength=W,this.maxLengthPerKey=Y,this.caches=[];for(let G=0;G<this.maxKeyLength;G++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,Y,G){let X=this.caches[G-1];W:for(let J of X){let Z=J.bytes;for(let V=0;V<G;V++)if(Z[V]!==W[Y+V])continue W;return J.str}return null}store(W,Y){let G=this.caches[W.length-1],X={bytes:W,str:Y};if(G.length>=this.maxLengthPerKey)G[Math.random()*G.length|0]=X;else G.push(X)}decode(W,Y,G){let X=this.find(W,Y,G);if(X!=null)return this.hit++,X;this.miss++;let J=qA(W,Y,G),Z=Uint8Array.prototype.slice.call(W,Y,Y+G);return this.store(Z,J),J}}var IA="array",HJ="map_key",wD="map_value",Jy=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new S9("The type of key must be string or number but "+typeof W)};class jD{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let Y=this.getUninitializedStateFromPool();Y.type=IA,Y.position=0,Y.size=W,Y.array=Array(W)}pushMapState(W){let Y=this.getUninitializedStateFromPool();Y.type=HJ,Y.readCount=0,Y.size=W,Y.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===IA){let G=W;G.size=0,G.array=void 0,G.position=0,G.type=void 0}if(W.type===HJ||W.type===wD){let G=W;G.size=0,G.map=void 0,G.readCount=0,G.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var QJ=-1,zA=new DataView(new ArrayBuffer(0)),Zy=new Uint8Array(zA.buffer);try{zA.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var zD=RangeError("Insufficient data"),Vy=new AA;class bU{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=zA;bytes=Zy;headByte=QJ;stack=new jD;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??dY.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??lY,this.maxBinLength=W?.maxBinLength??lY,this.maxArrayLength=W?.maxArrayLength??lY,this.maxMapLength=W?.maxMapLength??lY,this.maxExtLength=W?.maxExtLength??lY,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:Vy,this.mapKeyConverter=W?.mapKeyConverter??Jy}clone(){return new bU({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=QJ,this.stack.reset()}setBuffer(W){let Y=UJ(W);this.bytes=Y,this.view=new DataView(Y.buffer,Y.byteOffset,Y.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===QJ&&!this.hasRemaining(1))this.setBuffer(W);else{let Y=this.bytes.subarray(this.pos),G=UJ(W),X=new Uint8Array(Y.length+G.length);X.set(Y),X.set(G,Y.length),this.setBuffer(X)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:Y,pos:G}=this;return RangeError(`Extra ${Y.byteLength-G} of ${Y.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let Y=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Y}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let Y=!1,G;for await(let V of W){if(Y)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(V);try{G=this.doDecodeSync(),Y=!0}catch(U){if(!(U instanceof RangeError))throw U}this.totalPos+=this.pos}if(Y){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return G}let{headByte:X,pos:J,totalPos:Z}=this;throw RangeError(`Insufficient data in parsing ${hU(X)} at ${Z} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,Y){if(this.entered){yield*this.clone().decodeMultiAsync(W,Y);return}try{this.entered=!0;let G=Y,X=-1;for await(let J of W){if(Y&&X===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),G)X=this.readArraySize(),G=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--X===0)break}catch(Z){if(!(Z instanceof RangeError))throw Z}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),Y;if(W>=224)Y=W-256;else if(W<192)if(W<128)Y=W;else if(W<144){let X=W-128;if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W<160){let X=W-144;if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else{let X=W-160;Y=this.decodeString(X,0)}else if(W===192)Y=null;else if(W===194)Y=!1;else if(W===195)Y=!0;else if(W===202)Y=this.readF32();else if(W===203)Y=this.readF64();else if(W===204)Y=this.readU8();else if(W===205)Y=this.readU16();else if(W===206)Y=this.readU32();else if(W===207)if(this.useBigInt64)Y=this.readU64AsBigInt();else Y=this.readU64();else if(W===208)Y=this.readI8();else if(W===209)Y=this.readI16();else if(W===210)Y=this.readI32();else if(W===211)if(this.useBigInt64)Y=this.readI64AsBigInt();else Y=this.readI64();else if(W===217){let X=this.lookU8();Y=this.decodeString(X,1)}else if(W===218){let X=this.lookU16();Y=this.decodeString(X,2)}else if(W===219){let X=this.lookU32();Y=this.decodeString(X,4)}else if(W===220){let X=this.readU16();if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else if(W===221){let X=this.readU32();if(X!==0){this.pushArrayState(X),this.complete();continue W}else Y=[]}else if(W===222){let X=this.readU16();if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W===223){let X=this.readU32();if(X!==0){this.pushMapState(X),this.complete();continue W}else Y={}}else if(W===196){let X=this.lookU8();Y=this.decodeBinary(X,1)}else if(W===197){let X=this.lookU16();Y=this.decodeBinary(X,2)}else if(W===198){let X=this.lookU32();Y=this.decodeBinary(X,4)}else if(W===212)Y=this.decodeExtension(1,0);else if(W===213)Y=this.decodeExtension(2,0);else if(W===214)Y=this.decodeExtension(4,0);else if(W===215)Y=this.decodeExtension(8,0);else if(W===216)Y=this.decodeExtension(16,0);else if(W===199){let X=this.lookU8();Y=this.decodeExtension(X,1)}else if(W===200){let X=this.lookU16();Y=this.decodeExtension(X,2)}else if(W===201){let X=this.lookU32();Y=this.decodeExtension(X,4)}else throw new S9(`Unrecognized type byte: ${hU(W)}`);this.complete();let G=this.stack;while(G.length>0){let X=G.top();if(X.type===IA)if(X.array[X.position]=Y,X.position++,X.position===X.size)Y=X.array,G.release(X);else continue W;else if(X.type===HJ){if(Y==="__proto__")throw new S9("The key __proto__ is not allowed");X.key=this.mapKeyConverter(Y),X.type=wD;continue W}else if(X.map[X.key]=Y,X.readCount++,X.readCount===X.size)Y=X.map,G.release(X);else{X.key=null,X.type=HJ;continue W}}return Y}}readHeadByte(){if(this.headByte===QJ)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=QJ}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new S9(`Unrecognized array type byte: ${hU(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new S9(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new S9(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,Y){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,Y);return this.decodeBinary(W,Y)}decodeUtf8String(W,Y){if(W>this.maxStrLength)throw new S9(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Y+W)throw zD;let G=this.pos+Y,X;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))X=this.keyDecoder.decode(this.bytes,G,W);else X=ND(this.bytes,G,W);return this.pos+=Y+W,X}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===HJ;return!1}decodeBinary(W,Y){if(W>this.maxBinLength)throw new S9(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+Y))throw zD;let G=this.pos+Y,X=this.bytes.subarray(G,G+W);return this.pos+=Y+W,X}decodeExtension(W,Y){if(W>this.maxExtLength)throw new S9(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let G=this.view.getInt8(this.pos+Y),X=this.decodeBinary(W,Y+1);return this.extensionCodec.decode(X,G,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=AD(this.view,this.pos);return this.pos+=8,W}readI64(){let W=vU(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}function qW(W,Y){return new bU(Y).decode(W)}/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function sY(W){let Y=W.length;while(--Y>=0)W[Y]=0}var Uy=0,YC=1,Qy=2,Hy=3,Ny=258,hA=29,PJ=256,jJ=PJ+1+hA,iY=30,bA=19,GC=2*jJ+1,AW=15,wA=16,qy=7,mA=256,XC=16,JC=17,ZC=18,FA=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),dU=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Ay=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),VC=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Iy=512,t7=Array((jJ+2)*2);sY(t7);var IJ=Array(iY*2);sY(IJ);var OJ=Array(Iy);sY(OJ);var KJ=Array(Ny-Hy+1);sY(KJ);var fA=Array(hA);sY(fA);var oU=Array(iY);sY(oU);function jA(W,Y,G,X,J){this.static_tree=W,this.extra_bits=Y,this.extra_base=G,this.elems=X,this.max_length=J,this.has_stree=W&&W.length}var UC,QC,HC;function OA(W,Y){this.dyn_tree=W,this.max_code=0,this.stat_desc=Y}var NC=(W)=>{return W<256?OJ[W]:OJ[256+(W>>>7)]},DJ=(W,Y)=>{W.pending_buf[W.pending++]=Y&255,W.pending_buf[W.pending++]=Y>>>8&255},h9=(W,Y,G)=>{if(W.bi_valid>wA-G)W.bi_buf|=Y<<W.bi_valid&65535,DJ(W,W.bi_buf),W.bi_buf=Y>>wA-W.bi_valid,W.bi_valid+=G-wA;else W.bi_buf|=Y<<W.bi_valid&65535,W.bi_valid+=G},N7=(W,Y,G)=>{h9(W,G[Y*2],G[Y*2+1])},qC=(W,Y)=>{let G=0;do G|=W&1,W>>>=1,G<<=1;while(--Y>0);return G>>>1},zy=(W)=>{if(W.bi_valid===16)DJ(W,W.bi_buf),W.bi_buf=0,W.bi_valid=0;else if(W.bi_valid>=8)W.pending_buf[W.pending++]=W.bi_buf&255,W.bi_buf>>=8,W.bi_valid-=8},wy=(W,Y)=>{let{dyn_tree:G,max_code:X}=Y,J=Y.stat_desc.static_tree,Z=Y.stat_desc.has_stree,V=Y.stat_desc.extra_bits,U=Y.stat_desc.extra_base,Q=Y.stat_desc.max_length,H,N,A,q,z,w,D=0;for(q=0;q<=AW;q++)W.bl_count[q]=0;G[W.heap[W.heap_max]*2+1]=0;for(H=W.heap_max+1;H<GC;H++){if(N=W.heap[H],q=G[G[N*2+1]*2+1]+1,q>Q)q=Q,D++;if(G[N*2+1]=q,N>X)continue;if(W.bl_count[q]++,z=0,N>=U)z=V[N-U];if(w=G[N*2],W.opt_len+=w*(q+z),Z)W.static_len+=w*(J[N*2+1]+z)}if(D===0)return;do{q=Q-1;while(W.bl_count[q]===0)q--;W.bl_count[q]--,W.bl_count[q+1]+=2,W.bl_count[Q]--,D-=2}while(D>0);for(q=Q;q!==0;q--){N=W.bl_count[q];while(N!==0){if(A=W.heap[--H],A>X)continue;if(G[A*2+1]!==q)W.opt_len+=(q-G[A*2+1])*G[A*2],G[A*2+1]=q;N--}}},AC=(W,Y,G)=>{let X=Array(AW+1),J=0,Z,V;for(Z=1;Z<=AW;Z++)J=J+G[Z-1]<<1,X[Z]=J;for(V=0;V<=Y;V++){let U=W[V*2+1];if(U===0)continue;W[V*2]=qC(X[U]++,U)}},jy=()=>{let W,Y,G,X,J,Z=Array(AW+1);G=0;for(X=0;X<hA-1;X++){fA[X]=G;for(W=0;W<1<<FA[X];W++)KJ[G++]=X}KJ[G-1]=X,J=0;for(X=0;X<16;X++){oU[X]=J;for(W=0;W<1<<dU[X];W++)OJ[J++]=X}J>>=7;for(;X<iY;X++){oU[X]=J<<7;for(W=0;W<1<<dU[X]-7;W++)OJ[256+J++]=X}for(Y=0;Y<=AW;Y++)Z[Y]=0;W=0;while(W<=143)t7[W*2+1]=8,W++,Z[8]++;while(W<=255)t7[W*2+1]=9,W++,Z[9]++;while(W<=279)t7[W*2+1]=7,W++,Z[7]++;while(W<=287)t7[W*2+1]=8,W++,Z[8]++;AC(t7,jJ+1,Z);for(W=0;W<iY;W++)IJ[W*2+1]=5,IJ[W*2]=qC(W,5);UC=new jA(t7,FA,PJ+1,jJ,AW),QC=new jA(IJ,dU,0,iY,AW),HC=new jA([],Ay,0,bA,qy)},IC=(W)=>{let Y;for(Y=0;Y<jJ;Y++)W.dyn_ltree[Y*2]=0;for(Y=0;Y<iY;Y++)W.dyn_dtree[Y*2]=0;for(Y=0;Y<bA;Y++)W.bl_tree[Y*2]=0;W.dyn_ltree[mA*2]=1,W.opt_len=W.static_len=0,W.sym_next=W.matches=0},zC=(W)=>{if(W.bi_valid>8)DJ(W,W.bi_buf);else if(W.bi_valid>0)W.pending_buf[W.pending++]=W.bi_buf;W.bi_buf=0,W.bi_valid=0},OD=(W,Y,G,X)=>{let J=Y*2,Z=G*2;return W[J]<W[Z]||W[J]===W[Z]&&X[Y]<=X[G]},KA=(W,Y,G)=>{let X=W.heap[G],J=G<<1;while(J<=W.heap_len){if(J<W.heap_len&&OD(Y,W.heap[J+1],W.heap[J],W.depth))J++;if(OD(Y,X,W.heap[J],W.depth))break;W.heap[G]=W.heap[J],G=J,J<<=1}W.heap[G]=X},KD=(W,Y,G)=>{let X,J,Z=0,V,U;if(W.sym_next!==0)do if(X=W.pending_buf[W.sym_buf+Z++]&255,X+=(W.pending_buf[W.sym_buf+Z++]&255)<<8,J=W.pending_buf[W.sym_buf+Z++],X===0)N7(W,J,Y);else{if(V=KJ[J],N7(W,V+PJ+1,Y),U=FA[V],U!==0)J-=fA[V],h9(W,J,U);if(X--,V=NC(X),N7(W,V,G),U=dU[V],U!==0)X-=oU[V],h9(W,X,U)}while(Z<W.sym_next);N7(W,mA,Y)},SA=(W,Y)=>{let G=Y.dyn_tree,X=Y.stat_desc.static_tree,J=Y.stat_desc.has_stree,Z=Y.stat_desc.elems,V,U,Q=-1,H;W.heap_len=0,W.heap_max=GC;for(V=0;V<Z;V++)if(G[V*2]!==0)W.heap[++W.heap_len]=Q=V,W.depth[V]=0;else G[V*2+1]=0;while(W.heap_len<2)if(H=W.heap[++W.heap_len]=Q<2?++Q:0,G[H*2]=1,W.depth[H]=0,W.opt_len--,J)W.static_len-=X[H*2+1];Y.max_code=Q;for(V=W.heap_len>>1;V>=1;V--)KA(W,G,V);H=Z;do V=W.heap[1],W.heap[1]=W.heap[W.heap_len--],KA(W,G,1),U=W.heap[1],W.heap[--W.heap_max]=V,W.heap[--W.heap_max]=U,G[H*2]=G[V*2]+G[U*2],W.depth[H]=(W.depth[V]>=W.depth[U]?W.depth[V]:W.depth[U])+1,G[V*2+1]=G[U*2+1]=H,W.heap[1]=H++,KA(W,G,1);while(W.heap_len>=2);W.heap[--W.heap_max]=W.heap[1],wy(W,Y),AC(G,Q,W.bl_count)},DD=(W,Y,G)=>{let X,J=-1,Z,V=Y[1],U=0,Q=7,H=4;if(V===0)Q=138,H=3;Y[(G+1)*2+1]=65535;for(X=0;X<=G;X++){if(Z=V,V=Y[(X+1)*2+1],++U<Q&&Z===V)continue;else if(U<H)W.bl_tree[Z*2]+=U;else if(Z!==0){if(Z!==J)W.bl_tree[Z*2]++;W.bl_tree[XC*2]++}else if(U<=10)W.bl_tree[JC*2]++;else W.bl_tree[ZC*2]++;if(U=0,J=Z,V===0)Q=138,H=3;else if(Z===V)Q=6,H=3;else Q=7,H=4}},CD=(W,Y,G)=>{let X,J=-1,Z,V=Y[1],U=0,Q=7,H=4;if(V===0)Q=138,H=3;for(X=0;X<=G;X++){if(Z=V,V=Y[(X+1)*2+1],++U<Q&&Z===V)continue;else if(U<H)do N7(W,Z,W.bl_tree);while(--U!==0);else if(Z!==0){if(Z!==J)N7(W,Z,W.bl_tree),U--;N7(W,XC,W.bl_tree),h9(W,U-3,2)}else if(U<=10)N7(W,JC,W.bl_tree),h9(W,U-3,3);else N7(W,ZC,W.bl_tree),h9(W,U-11,7);if(U=0,J=Z,V===0)Q=138,H=3;else if(Z===V)Q=6,H=3;else Q=7,H=4}},Oy=(W)=>{let Y;DD(W,W.dyn_ltree,W.l_desc.max_code),DD(W,W.dyn_dtree,W.d_desc.max_code),SA(W,W.bl_desc);for(Y=bA-1;Y>=3;Y--)if(W.bl_tree[VC[Y]*2+1]!==0)break;return W.opt_len+=3*(Y+1)+5+5+4,Y},Ky=(W,Y,G,X)=>{let J;h9(W,Y-257,5),h9(W,G-1,5),h9(W,X-4,4);for(J=0;J<X;J++)h9(W,W.bl_tree[VC[J]*2+1],3);CD(W,W.dyn_ltree,Y-1),CD(W,W.dyn_dtree,G-1)},Dy=(W)=>{let Y=4093624447,G;for(G=0;G<=31;G++,Y>>>=1)if(Y&1&&W.dyn_ltree[G*2]!==0)return 0;if(W.dyn_ltree[18]!==0||W.dyn_ltree[20]!==0||W.dyn_ltree[26]!==0)return 1;for(G=32;G<PJ;G++)if(W.dyn_ltree[G*2]!==0)return 1;return 0},TD=!1,Cy=(W)=>{if(!TD)jy(),TD=!0;W.l_desc=new OA(W.dyn_ltree,UC),W.d_desc=new OA(W.dyn_dtree,QC),W.bl_desc=new OA(W.bl_tree,HC),W.bi_buf=0,W.bi_valid=0,IC(W)},wC=(W,Y,G,X)=>{if(h9(W,(Uy<<1)+(X?1:0),3),zC(W),DJ(W,G),DJ(W,~G),G)W.pending_buf.set(W.window.subarray(Y,Y+G),W.pending);W.pending+=G},Ty=(W)=>{h9(W,YC<<1,3),N7(W,mA,t7),zy(W)},Ry=(W,Y,G,X)=>{let J,Z,V=0;if(W.level>0){if(W.strm.data_type===2)W.strm.data_type=Dy(W);if(SA(W,W.l_desc),SA(W,W.d_desc),V=Oy(W),J=W.opt_len+3+7>>>3,Z=W.static_len+3+7>>>3,Z<=J)J=Z}else J=Z=G+5;if(G+4<=J&&Y!==-1)wC(W,Y,G,X);else if(W.strategy===4||Z===J)h9(W,(YC<<1)+(X?1:0),3),KD(W,t7,IJ);else h9(W,(Qy<<1)+(X?1:0),3),Ky(W,W.l_desc.max_code+1,W.d_desc.max_code+1,V+1),KD(W,W.dyn_ltree,W.dyn_dtree);if(IC(W),X)zC(W)},My=(W,Y,G)=>{if(W.pending_buf[W.sym_buf+W.sym_next++]=Y,W.pending_buf[W.sym_buf+W.sym_next++]=Y>>8,W.pending_buf[W.sym_buf+W.sym_next++]=G,Y===0)W.dyn_ltree[G*2]++;else W.matches++,Y--,W.dyn_ltree[(KJ[G]+PJ+1)*2]++,W.dyn_dtree[NC(Y)*2]++;return W.sym_next===W.sym_end},Py=Cy,Ly=wC,By=Ry,Ey=My,$y=Ty,Fy={_tr_init:Py,_tr_stored_block:Ly,_tr_flush_block:By,_tr_tally:Ey,_tr_align:$y},Sy=(W,Y,G,X)=>{let J=W&65535|0,Z=W>>>16&65535|0,V=0;while(G!==0){V=G>2000?2000:G,G-=V;do J=J+Y[X++]|0,Z=Z+J|0;while(--V);J%=65521,Z%=65521}return J|Z<<16|0},CJ=Sy,xy=()=>{let W,Y=[];for(var G=0;G<256;G++){W=G;for(var X=0;X<8;X++)W=W&1?3988292384^W>>>1:W>>>1;Y[G]=W}return Y},ky=new Uint32Array(xy()),_y=(W,Y,G,X)=>{let J=ky,Z=X+G;W^=-1;for(let V=X;V<Z;V++)W=W>>>8^J[(W^Y[V])&255];return W^-1},n8=_y,wW={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},KW={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:yy,_tr_stored_block:xA,_tr_flush_block:vy,_tr_tally:V6,_tr_align:gy}=Fy,{Z_NO_FLUSH:U6,Z_PARTIAL_FLUSH:uy,Z_FULL_FLUSH:hy,Z_FINISH:w5,Z_BLOCK:RD,Z_OK:t8,Z_STREAM_END:MD,Z_STREAM_ERROR:q7,Z_DATA_ERROR:by,Z_BUF_ERROR:DA,Z_DEFAULT_COMPRESSION:my,Z_FILTERED:fy,Z_HUFFMAN_ONLY:mU,Z_RLE:cy,Z_FIXED:py,Z_DEFAULT_STRATEGY:ly,Z_UNKNOWN:dy,Z_DEFLATED:rU}=KW,oy=9,ny=15,iy=8,ry=29,ay=256,kA=ay+1+ry,sy=30,ty=19,ey=2*kA+1,Wv=15,g1=3,Z6=258,A7=Z6+g1+1,Yv=32,rY=42,cA=57,_A=69,yA=73,vA=91,gA=103,IW=113,qJ=666,x9=1,tY=2,jW=3,eY=4,Gv=3,zW=(W,Y)=>{return W.msg=wW[Y],Y},PD=(W)=>{return W*2-(W>4?9:0)},J6=(W)=>{let Y=W.length;while(--Y>=0)W[Y]=0},Xv=(W)=>{let Y,G,X,J=W.w_size;Y=W.hash_size,X=Y;do G=W.head[--X],W.head[X]=G>=J?G-J:0;while(--Y);Y=J,X=Y;do G=W.prev[--X],W.prev[X]=G>=J?G-J:0;while(--Y)},Jv=(W,Y,G)=>(Y<<W.hash_shift^G)&W.hash_mask,Q6=Jv,W5=(W)=>{let Y=W.state,G=Y.pending;if(G>W.avail_out)G=W.avail_out;if(G===0)return;if(W.output.set(Y.pending_buf.subarray(Y.pending_out,Y.pending_out+G),W.next_out),W.next_out+=G,Y.pending_out+=G,W.total_out+=G,W.avail_out-=G,Y.pending-=G,Y.pending===0)Y.pending_out=0},Y5=(W,Y)=>{vy(W,W.block_start>=0?W.block_start:-1,W.strstart-W.block_start,Y),W.block_start=W.strstart,W5(W.strm)},r1=(W,Y)=>{W.pending_buf[W.pending++]=Y},NJ=(W,Y)=>{W.pending_buf[W.pending++]=Y>>>8&255,W.pending_buf[W.pending++]=Y&255},uA=(W,Y,G,X)=>{let J=W.avail_in;if(J>X)J=X;if(J===0)return 0;if(W.avail_in-=J,Y.set(W.input.subarray(W.next_in,W.next_in+J),G),W.state.wrap===1)W.adler=CJ(W.adler,Y,J,G);else if(W.state.wrap===2)W.adler=n8(W.adler,Y,J,G);return W.next_in+=J,W.total_in+=J,J},jC=(W,Y)=>{let{max_chain_length:G,strstart:X}=W,J,Z,V=W.prev_length,U=W.nice_match,Q=W.strstart>W.w_size-A7?W.strstart-(W.w_size-A7):0,H=W.window,N=W.w_mask,A=W.prev,q=W.strstart+Z6,z=H[X+V-1],w=H[X+V];if(W.prev_length>=W.good_match)G>>=2;if(U>W.lookahead)U=W.lookahead;do{if(J=Y,H[J+V]!==w||H[J+V-1]!==z||H[J]!==H[X]||H[++J]!==H[X+1])continue;X+=2,J++;do;while(H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&H[++X]===H[++J]&&X<q);if(Z=Z6-(q-X),X=q-Z6,Z>V){if(W.match_start=Y,V=Z,Z>=U)break;z=H[X+V-1],w=H[X+V]}}while((Y=A[Y&N])>Q&&--G!==0);if(V<=W.lookahead)return V;return W.lookahead},aY=(W)=>{let Y=W.w_size,G,X,J;do{if(X=W.window_size-W.lookahead-W.strstart,W.strstart>=Y+(Y-A7)){if(W.window.set(W.window.subarray(Y,Y+Y-X),0),W.match_start-=Y,W.strstart-=Y,W.block_start-=Y,W.insert>W.strstart)W.insert=W.strstart;Xv(W),X+=Y}if(W.strm.avail_in===0)break;if(G=uA(W.strm,W.window,W.strstart+W.lookahead,X),W.lookahead+=G,W.lookahead+W.insert>=g1){J=W.strstart-W.insert,W.ins_h=W.window[J],W.ins_h=Q6(W,W.ins_h,W.window[J+1]);while(W.insert)if(W.ins_h=Q6(W,W.ins_h,W.window[J+g1-1]),W.prev[J&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=J,J++,W.insert--,W.lookahead+W.insert<g1)break}}while(W.lookahead<A7&&W.strm.avail_in!==0)},OC=(W,Y)=>{let G=W.pending_buf_size-5>W.w_size?W.w_size:W.pending_buf_size-5,X,J,Z,V=0,U=W.strm.avail_in;do{if(X=65535,Z=W.bi_valid+42>>3,W.strm.avail_out<Z)break;if(Z=W.strm.avail_out-Z,J=W.strstart-W.block_start,X>J+W.strm.avail_in)X=J+W.strm.avail_in;if(X>Z)X=Z;if(X<G&&(X===0&&Y!==w5||Y===U6||X!==J+W.strm.avail_in))break;if(V=Y===w5&&X===J+W.strm.avail_in?1:0,xA(W,0,0,V),W.pending_buf[W.pending-4]=X,W.pending_buf[W.pending-3]=X>>8,W.pending_buf[W.pending-2]=~X,W.pending_buf[W.pending-1]=~X>>8,W5(W.strm),J){if(J>X)J=X;W.strm.output.set(W.window.subarray(W.block_start,W.block_start+J),W.strm.next_out),W.strm.next_out+=J,W.strm.avail_out-=J,W.strm.total_out+=J,W.block_start+=J,X-=J}if(X)uA(W.strm,W.strm.output,W.strm.next_out,X),W.strm.next_out+=X,W.strm.avail_out-=X,W.strm.total_out+=X}while(V===0);if(U-=W.strm.avail_in,U){if(U>=W.w_size)W.matches=2,W.window.set(W.strm.input.subarray(W.strm.next_in-W.w_size,W.strm.next_in),0),W.strstart=W.w_size,W.insert=W.strstart;else{if(W.window_size-W.strstart<=U){if(W.strstart-=W.w_size,W.window.set(W.window.subarray(W.w_size,W.w_size+W.strstart),0),W.matches<2)W.matches++;if(W.insert>W.strstart)W.insert=W.strstart}W.window.set(W.strm.input.subarray(W.strm.next_in-U,W.strm.next_in),W.strstart),W.strstart+=U,W.insert+=U>W.w_size-W.insert?W.w_size-W.insert:U}W.block_start=W.strstart}if(W.high_water<W.strstart)W.high_water=W.strstart;if(V)return eY;if(Y!==U6&&Y!==w5&&W.strm.avail_in===0&&W.strstart===W.block_start)return tY;if(Z=W.window_size-W.strstart,W.strm.avail_in>Z&&W.block_start>=W.w_size){if(W.block_start-=W.w_size,W.strstart-=W.w_size,W.window.set(W.window.subarray(W.w_size,W.w_size+W.strstart),0),W.matches<2)W.matches++;if(Z+=W.w_size,W.insert>W.strstart)W.insert=W.strstart}if(Z>W.strm.avail_in)Z=W.strm.avail_in;if(Z)uA(W.strm,W.window,W.strstart,Z),W.strstart+=Z,W.insert+=Z>W.w_size-W.insert?W.w_size-W.insert:Z;if(W.high_water<W.strstart)W.high_water=W.strstart;if(Z=W.bi_valid+42>>3,Z=W.pending_buf_size-Z>65535?65535:W.pending_buf_size-Z,G=Z>W.w_size?W.w_size:Z,J=W.strstart-W.block_start,J>=G||(J||Y===w5)&&Y!==U6&&W.strm.avail_in===0&&J<=Z)X=J>Z?Z:J,V=Y===w5&&W.strm.avail_in===0&&X===J?1:0,xA(W,W.block_start,X,V),W.block_start+=X,W5(W.strm);return V?jW:x9},CA=(W,Y)=>{let G,X;for(;;){if(W.lookahead<A7){if(aY(W),W.lookahead<A7&&Y===U6)return x9;if(W.lookahead===0)break}if(G=0,W.lookahead>=g1)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+g1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;if(G!==0&&W.strstart-G<=W.w_size-A7)W.match_length=jC(W,G);if(W.match_length>=g1)if(X=V6(W,W.strstart-W.match_start,W.match_length-g1),W.lookahead-=W.match_length,W.match_length<=W.max_lazy_match&&W.lookahead>=g1){W.match_length--;do W.strstart++,W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+g1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;while(--W.match_length!==0);W.strstart++}else W.strstart+=W.match_length,W.match_length=0,W.ins_h=W.window[W.strstart],W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+1]);else X=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(X){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=W.strstart<g1-1?W.strstart:g1-1,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},oY=(W,Y)=>{let G,X,J;for(;;){if(W.lookahead<A7){if(aY(W),W.lookahead<A7&&Y===U6)return x9;if(W.lookahead===0)break}if(G=0,W.lookahead>=g1)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+g1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;if(W.prev_length=W.match_length,W.prev_match=W.match_start,W.match_length=g1-1,G!==0&&W.prev_length<W.max_lazy_match&&W.strstart-G<=W.w_size-A7){if(W.match_length=jC(W,G),W.match_length<=5&&(W.strategy===fy||W.match_length===g1&&W.strstart-W.match_start>4096))W.match_length=g1-1}if(W.prev_length>=g1&&W.match_length<=W.prev_length){J=W.strstart+W.lookahead-g1,X=V6(W,W.strstart-1-W.prev_match,W.prev_length-g1),W.lookahead-=W.prev_length-1,W.prev_length-=2;do if(++W.strstart<=J)W.ins_h=Q6(W,W.ins_h,W.window[W.strstart+g1-1]),G=W.prev[W.strstart&W.w_mask]=W.head[W.ins_h],W.head[W.ins_h]=W.strstart;while(--W.prev_length!==0);if(W.match_available=0,W.match_length=g1-1,W.strstart++,X){if(Y5(W,!1),W.strm.avail_out===0)return x9}}else if(W.match_available){if(X=V6(W,0,W.window[W.strstart-1]),X)Y5(W,!1);if(W.strstart++,W.lookahead--,W.strm.avail_out===0)return x9}else W.match_available=1,W.strstart++,W.lookahead--}if(W.match_available)X=V6(W,0,W.window[W.strstart-1]),W.match_available=0;if(W.insert=W.strstart<g1-1?W.strstart:g1-1,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},Zv=(W,Y)=>{let G,X,J,Z,V=W.window;for(;;){if(W.lookahead<=Z6){if(aY(W),W.lookahead<=Z6&&Y===U6)return x9;if(W.lookahead===0)break}if(W.match_length=0,W.lookahead>=g1&&W.strstart>0){if(J=W.strstart-1,X=V[J],X===V[++J]&&X===V[++J]&&X===V[++J]){Z=W.strstart+Z6;do;while(X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&X===V[++J]&&J<Z);if(W.match_length=Z6-(Z-J),W.match_length>W.lookahead)W.match_length=W.lookahead}}if(W.match_length>=g1)G=V6(W,1,W.match_length-g1),W.lookahead-=W.match_length,W.strstart+=W.match_length,W.match_length=0;else G=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++;if(G){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=0,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY},Vv=(W,Y)=>{let G;for(;;){if(W.lookahead===0){if(aY(W),W.lookahead===0){if(Y===U6)return x9;break}}if(W.match_length=0,G=V6(W,0,W.window[W.strstart]),W.lookahead--,W.strstart++,G){if(Y5(W,!1),W.strm.avail_out===0)return x9}}if(W.insert=0,Y===w5){if(Y5(W,!0),W.strm.avail_out===0)return jW;return eY}if(W.sym_next){if(Y5(W,!1),W.strm.avail_out===0)return x9}return tY};function H7(W,Y,G,X,J){this.good_length=W,this.max_lazy=Y,this.nice_length=G,this.max_chain=X,this.func=J}var AJ=[new H7(0,0,0,0,OC),new H7(4,4,8,4,CA),new H7(4,5,16,8,CA),new H7(4,6,32,32,CA),new H7(4,4,16,16,oY),new H7(8,16,32,32,oY),new H7(8,16,128,128,oY),new H7(8,32,128,256,oY),new H7(32,128,258,1024,oY),new H7(32,258,258,4096,oY)],Uv=(W)=>{W.window_size=2*W.w_size,J6(W.head),W.max_lazy_match=AJ[W.level].max_lazy,W.good_match=AJ[W.level].good_length,W.nice_match=AJ[W.level].nice_length,W.max_chain_length=AJ[W.level].max_chain,W.strstart=0,W.block_start=0,W.lookahead=0,W.insert=0,W.match_length=W.prev_length=g1-1,W.match_available=0,W.ins_h=0};function Qv(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=rU,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(ey*2),this.dyn_dtree=new Uint16Array((2*sy+1)*2),this.bl_tree=new Uint16Array((2*ty+1)*2),J6(this.dyn_ltree),J6(this.dyn_dtree),J6(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(Wv+1),this.heap=new Uint16Array(2*kA+1),J6(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*kA+1),J6(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var LJ=(W)=>{if(!W)return 1;let Y=W.state;if(!Y||Y.strm!==W||Y.status!==rY&&Y.status!==cA&&Y.status!==_A&&Y.status!==yA&&Y.status!==vA&&Y.status!==gA&&Y.status!==IW&&Y.status!==qJ)return 1;return 0},KC=(W)=>{if(LJ(W))return zW(W,q7);W.total_in=W.total_out=0,W.data_type=dy;let Y=W.state;if(Y.pending=0,Y.pending_out=0,Y.wrap<0)Y.wrap=-Y.wrap;return Y.status=Y.wrap===2?cA:Y.wrap?rY:IW,W.adler=Y.wrap===2?0:1,Y.last_flush=-2,yy(Y),t8},DC=(W)=>{let Y=KC(W);if(Y===t8)Uv(W.state);return Y},Hv=(W,Y)=>{if(LJ(W)||W.state.wrap!==2)return q7;return W.state.gzhead=Y,t8},CC=(W,Y,G,X,J,Z)=>{if(!W)return q7;let V=1;if(Y===my)Y=6;if(X<0)V=0,X=-X;else if(X>15)V=2,X-=16;if(J<1||J>oy||G!==rU||X<8||X>15||Y<0||Y>9||Z<0||Z>py||X===8&&V!==1)return zW(W,q7);if(X===8)X=9;let U=new Qv;return W.state=U,U.strm=W,U.status=rY,U.wrap=V,U.gzhead=null,U.w_bits=X,U.w_size=1<<U.w_bits,U.w_mask=U.w_size-1,U.hash_bits=J+7,U.hash_size=1<<U.hash_bits,U.hash_mask=U.hash_size-1,U.hash_shift=~~((U.hash_bits+g1-1)/g1),U.window=new Uint8Array(U.w_size*2),U.head=new Uint16Array(U.hash_size),U.prev=new Uint16Array(U.w_size),U.lit_bufsize=1<<J+6,U.pending_buf_size=U.lit_bufsize*4,U.pending_buf=new Uint8Array(U.pending_buf_size),U.sym_buf=U.lit_bufsize,U.sym_end=(U.lit_bufsize-1)*3,U.level=Y,U.strategy=Z,U.method=G,DC(W)},Nv=(W,Y)=>{return CC(W,Y,rU,ny,iy,ly)},qv=(W,Y)=>{if(LJ(W)||Y>RD||Y<0)return W?zW(W,q7):q7;let G=W.state;if(!W.output||W.avail_in!==0&&!W.input||G.status===qJ&&Y!==w5)return zW(W,W.avail_out===0?DA:q7);let X=G.last_flush;if(G.last_flush=Y,G.pending!==0){if(W5(W),W.avail_out===0)return G.last_flush=-1,t8}else if(W.avail_in===0&&PD(Y)<=PD(X)&&Y!==w5)return zW(W,DA);if(G.status===qJ&&W.avail_in!==0)return zW(W,DA);if(G.status===rY&&G.wrap===0)G.status=IW;if(G.status===rY){let J=rU+(G.w_bits-8<<4)<<8,Z=-1;if(G.strategy>=mU||G.level<2)Z=0;else if(G.level<6)Z=1;else if(G.level===6)Z=2;else Z=3;if(J|=Z<<6,G.strstart!==0)J|=Yv;if(J+=31-J%31,NJ(G,J),G.strstart!==0)NJ(G,W.adler>>>16),NJ(G,W.adler&65535);if(W.adler=1,G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}if(G.status===cA)if(W.adler=0,r1(G,31),r1(G,139),r1(G,8),!G.gzhead){if(r1(G,0),r1(G,0),r1(G,0),r1(G,0),r1(G,0),r1(G,G.level===9?2:G.strategy>=mU||G.level<2?4:0),r1(G,Gv),G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}else{if(r1(G,(G.gzhead.text?1:0)+(G.gzhead.hcrc?2:0)+(!G.gzhead.extra?0:4)+(!G.gzhead.name?0:8)+(!G.gzhead.comment?0:16)),r1(G,G.gzhead.time&255),r1(G,G.gzhead.time>>8&255),r1(G,G.gzhead.time>>16&255),r1(G,G.gzhead.time>>24&255),r1(G,G.level===9?2:G.strategy>=mU||G.level<2?4:0),r1(G,G.gzhead.os&255),G.gzhead.extra&&G.gzhead.extra.length)r1(G,G.gzhead.extra.length&255),r1(G,G.gzhead.extra.length>>8&255);if(G.gzhead.hcrc)W.adler=n8(W.adler,G.pending_buf,G.pending,0);G.gzindex=0,G.status=_A}if(G.status===_A){if(G.gzhead.extra){let J=G.pending,Z=(G.gzhead.extra.length&65535)-G.gzindex;while(G.pending+Z>G.pending_buf_size){let U=G.pending_buf_size-G.pending;if(G.pending_buf.set(G.gzhead.extra.subarray(G.gzindex,G.gzindex+U),G.pending),G.pending=G.pending_buf_size,G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(G.gzindex+=U,W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0,Z-=U}let V=new Uint8Array(G.gzhead.extra);if(G.pending_buf.set(V.subarray(G.gzindex,G.gzindex+Z),G.pending),G.pending+=Z,G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=yA}if(G.status===yA){if(G.gzhead.name){let J=G.pending,Z;do{if(G.pending===G.pending_buf_size){if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0}if(G.gzindex<G.gzhead.name.length)Z=G.gzhead.name.charCodeAt(G.gzindex++)&255;else Z=0;r1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);G.gzindex=0}G.status=vA}if(G.status===vA){if(G.gzhead.comment){let J=G.pending,Z;do{if(G.pending===G.pending_buf_size){if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J);if(W5(W),G.pending!==0)return G.last_flush=-1,t8;J=0}if(G.gzindex<G.gzhead.comment.length)Z=G.gzhead.comment.charCodeAt(G.gzindex++)&255;else Z=0;r1(G,Z)}while(Z!==0);if(G.gzhead.hcrc&&G.pending>J)W.adler=n8(W.adler,G.pending_buf,G.pending-J,J)}G.status=gA}if(G.status===gA){if(G.gzhead.hcrc){if(G.pending+2>G.pending_buf_size){if(W5(W),G.pending!==0)return G.last_flush=-1,t8}r1(G,W.adler&255),r1(G,W.adler>>8&255),W.adler=0}if(G.status=IW,W5(W),G.pending!==0)return G.last_flush=-1,t8}if(W.avail_in!==0||G.lookahead!==0||Y!==U6&&G.status!==qJ){let J=G.level===0?OC(G,Y):G.strategy===mU?Vv(G,Y):G.strategy===cy?Zv(G,Y):AJ[G.level].func(G,Y);if(J===jW||J===eY)G.status=qJ;if(J===x9||J===jW){if(W.avail_out===0)G.last_flush=-1;return t8}if(J===tY){if(Y===uy)gy(G);else if(Y!==RD){if(xA(G,0,0,!1),Y===hy){if(J6(G.head),G.lookahead===0)G.strstart=0,G.block_start=0,G.insert=0}}if(W5(W),W.avail_out===0)return G.last_flush=-1,t8}}if(Y!==w5)return t8;if(G.wrap<=0)return MD;if(G.wrap===2)r1(G,W.adler&255),r1(G,W.adler>>8&255),r1(G,W.adler>>16&255),r1(G,W.adler>>24&255),r1(G,W.total_in&255),r1(G,W.total_in>>8&255),r1(G,W.total_in>>16&255),r1(G,W.total_in>>24&255);else NJ(G,W.adler>>>16),NJ(G,W.adler&65535);if(W5(W),G.wrap>0)G.wrap=-G.wrap;return G.pending!==0?t8:MD},Av=(W)=>{if(LJ(W))return q7;let Y=W.state.status;return W.state=null,Y===IW?zW(W,by):t8},Iv=(W,Y)=>{let G=Y.length;if(LJ(W))return q7;let X=W.state,J=X.wrap;if(J===2||J===1&&X.status!==rY||X.lookahead)return q7;if(J===1)W.adler=CJ(W.adler,Y,G,0);if(X.wrap=0,G>=X.w_size){if(J===0)J6(X.head),X.strstart=0,X.block_start=0,X.insert=0;let Q=new Uint8Array(X.w_size);Q.set(Y.subarray(G-X.w_size,G),0),Y=Q,G=X.w_size}let{avail_in:Z,next_in:V,input:U}=W;W.avail_in=G,W.next_in=0,W.input=Y,aY(X);while(X.lookahead>=g1){let Q=X.strstart,H=X.lookahead-(g1-1);do X.ins_h=Q6(X,X.ins_h,X.window[Q+g1-1]),X.prev[Q&X.w_mask]=X.head[X.ins_h],X.head[X.ins_h]=Q,Q++;while(--H);X.strstart=Q,X.lookahead=g1-1,aY(X)}return X.strstart+=X.lookahead,X.block_start=X.strstart,X.insert=X.lookahead,X.lookahead=0,X.match_length=X.prev_length=g1-1,X.match_available=0,W.next_in=V,W.input=U,W.avail_in=Z,X.wrap=J,t8},zv=Nv,wv=CC,jv=DC,Ov=KC,Kv=Hv,Dv=qv,Cv=Av,Tv=Iv,Rv="pako deflate (from Nodeca project)",zJ={deflateInit:zv,deflateInit2:wv,deflateReset:jv,deflateResetKeep:Ov,deflateSetHeader:Kv,deflate:Dv,deflateEnd:Cv,deflateSetDictionary:Tv,deflateInfo:Rv},Mv=(W,Y)=>{return Object.prototype.hasOwnProperty.call(W,Y)},Pv=function(W){let Y=Array.prototype.slice.call(arguments,1);while(Y.length){let G=Y.shift();if(!G)continue;if(typeof G!=="object")throw TypeError(G+"must be non-object");for(let X in G)if(Mv(G,X))W[X]=G[X]}return W},Lv=(W)=>{let Y=0;for(let X=0,J=W.length;X<J;X++)Y+=W[X].length;let G=new Uint8Array(Y);for(let X=0,J=0,Z=W.length;X<Z;X++){let V=W[X];G.set(V,J),J+=V.length}return G},aU={assign:Pv,flattenChunks:Lv},TC=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(W){TC=!1}var TJ=new Uint8Array(256);for(let W=0;W<256;W++)TJ[W]=W>=252?6:W>=248?5:W>=240?4:W>=224?3:W>=192?2:1;TJ[254]=TJ[254]=1;var Bv=(W)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(W);let Y,G,X,J,Z,V=W.length,U=0;for(J=0;J<V;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(X=W.charCodeAt(J+1),(X&64512)===56320)G=65536+(G-55296<<10)+(X-56320),J++}U+=G<128?1:G<2048?2:G<65536?3:4}Y=new Uint8Array(U);for(Z=0,J=0;Z<U;J++){if(G=W.charCodeAt(J),(G&64512)===55296&&J+1<V){if(X=W.charCodeAt(J+1),(X&64512)===56320)G=65536+(G-55296<<10)+(X-56320),J++}if(G<128)Y[Z++]=G;else if(G<2048)Y[Z++]=192|G>>>6,Y[Z++]=128|G&63;else if(G<65536)Y[Z++]=224|G>>>12,Y[Z++]=128|G>>>6&63,Y[Z++]=128|G&63;else Y[Z++]=240|G>>>18,Y[Z++]=128|G>>>12&63,Y[Z++]=128|G>>>6&63,Y[Z++]=128|G&63}return Y},Ev=(W,Y)=>{if(Y<65534){if(W.subarray&&TC)return String.fromCharCode.apply(null,W.length===Y?W:W.subarray(0,Y))}let G="";for(let X=0;X<Y;X++)G+=String.fromCharCode(W[X]);return G},$v=(W,Y)=>{let G=Y||W.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(W.subarray(0,Y));let X,J,Z=Array(G*2);for(J=0,X=0;X<G;){let V=W[X++];if(V<128){Z[J++]=V;continue}let U=TJ[V];if(U>4){Z[J++]=65533,X+=U-1;continue}V&=U===2?31:U===3?15:7;while(U>1&&X<G)V=V<<6|W[X++]&63,U--;if(U>1){Z[J++]=65533;continue}if(V<65536)Z[J++]=V;else V-=65536,Z[J++]=55296|V>>10&1023,Z[J++]=56320|V&1023}return Ev(Z,J)},Fv=(W,Y)=>{if(Y=Y||W.length,Y>W.length)Y=W.length;let G=Y-1;while(G>=0&&(W[G]&192)===128)G--;if(G<0)return Y;if(G===0)return Y;return G+TJ[W[G]]>Y?G:Y},RJ={string2buf:Bv,buf2string:$v,utf8border:Fv};function Sv(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var RC=Sv,MC=Object.prototype.toString,{Z_NO_FLUSH:xv,Z_SYNC_FLUSH:kv,Z_FULL_FLUSH:_v,Z_FINISH:yv,Z_OK:nU,Z_STREAM_END:vv,Z_DEFAULT_COMPRESSION:gv,Z_DEFAULT_STRATEGY:uv,Z_DEFLATED:hv}=KW;function BJ(W){this.options=aU.assign({level:gv,method:hv,chunkSize:16384,windowBits:15,memLevel:8,strategy:uv},W||{});let Y=this.options;if(Y.raw&&Y.windowBits>0)Y.windowBits=-Y.windowBits;else if(Y.gzip&&Y.windowBits>0&&Y.windowBits<16)Y.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new RC,this.strm.avail_out=0;let G=zJ.deflateInit2(this.strm,Y.level,Y.method,Y.windowBits,Y.memLevel,Y.strategy);if(G!==nU)throw Error(wW[G]);if(Y.header)zJ.deflateSetHeader(this.strm,Y.header);if(Y.dictionary){let X;if(typeof Y.dictionary==="string")X=RJ.string2buf(Y.dictionary);else if(MC.call(Y.dictionary)==="[object ArrayBuffer]")X=new Uint8Array(Y.dictionary);else X=Y.dictionary;if(G=zJ.deflateSetDictionary(this.strm,X),G!==nU)throw Error(wW[G]);this._dict_set=!0}}BJ.prototype.push=function(W,Y){let G=this.strm,X=this.options.chunkSize,J,Z;if(this.ended)return!1;if(Y===~~Y)Z=Y;else Z=Y===!0?yv:xv;if(typeof W==="string")G.input=RJ.string2buf(W);else if(MC.call(W)==="[object ArrayBuffer]")G.input=new Uint8Array(W);else G.input=W;G.next_in=0,G.avail_in=G.input.length;for(;;){if(G.avail_out===0)G.output=new Uint8Array(X),G.next_out=0,G.avail_out=X;if((Z===kv||Z===_v)&&G.avail_out<=6){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(J=zJ.deflate(G,Z),J===vv){if(G.next_out>0)this.onData(G.output.subarray(0,G.next_out));return J=zJ.deflateEnd(this.strm),this.onEnd(J),this.ended=!0,J===nU}if(G.avail_out===0){this.onData(G.output);continue}if(Z>0&&G.next_out>0){this.onData(G.output.subarray(0,G.next_out)),G.avail_out=0;continue}if(G.avail_in===0)break}return!0};BJ.prototype.onData=function(W){this.chunks.push(W)};BJ.prototype.onEnd=function(W){if(W===nU)this.result=aU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function pA(W,Y){let G=new BJ(Y);if(G.push(W,!0),G.err)throw G.msg||wW[G.err];return G.result}function bv(W,Y){return Y=Y||{},Y.raw=!0,pA(W,Y)}function mv(W,Y){return Y=Y||{},Y.gzip=!0,pA(W,Y)}var fv=BJ,cv=pA,pv=bv,lv=mv,dv=KW,ov={Deflate:fv,deflate:cv,deflateRaw:pv,gzip:lv,constants:dv},fU=16209,nv=16191,iv=function(Y,G){let X,J,Z,V,U,Q,H,N,A,q,z,w,D,T,x,g,f,y,p,b,m,W0,u,J0,I0=Y.state;X=Y.next_in,u=Y.input,J=X+(Y.avail_in-5),Z=Y.next_out,J0=Y.output,V=Z-(G-Y.avail_out),U=Z+(Y.avail_out-257),Q=I0.dmax,H=I0.wsize,N=I0.whave,A=I0.wnext,q=I0.window,z=I0.hold,w=I0.bits,D=I0.lencode,T=I0.distcode,x=(1<<I0.lenbits)-1,g=(1<<I0.distbits)-1;W:do{if(w<15)z+=u[X++]<<w,w+=8,z+=u[X++]<<w,w+=8;f=D[z&x];Y:for(;;){if(y=f>>>24,z>>>=y,w-=y,y=f>>>16&255,y===0)J0[Z++]=f&65535;else if(y&16){if(p=f&65535,y&=15,y){if(w<y)z+=u[X++]<<w,w+=8;p+=z&(1<<y)-1,z>>>=y,w-=y}if(w<15)z+=u[X++]<<w,w+=8,z+=u[X++]<<w,w+=8;f=T[z&g];G:for(;;){if(y=f>>>24,z>>>=y,w-=y,y=f>>>16&255,y&16){if(b=f&65535,y&=15,w<y){if(z+=u[X++]<<w,w+=8,w<y)z+=u[X++]<<w,w+=8}if(b+=z&(1<<y)-1,b>Q){Y.msg="invalid distance too far back",I0.mode=fU;break W}if(z>>>=y,w-=y,y=Z-V,b>y){if(y=b-y,y>N){if(I0.sane){Y.msg="invalid distance too far back",I0.mode=fU;break W}}if(m=0,W0=q,A===0){if(m+=H-y,y<p){p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}}else if(A<y){if(m+=H+A-y,y-=A,y<p){p-=y;do J0[Z++]=q[m++];while(--y);if(m=0,A<p){y=A,p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}}}else if(m+=A-y,y<p){p-=y;do J0[Z++]=q[m++];while(--y);m=Z-b,W0=J0}while(p>2)J0[Z++]=W0[m++],J0[Z++]=W0[m++],J0[Z++]=W0[m++],p-=3;if(p){if(J0[Z++]=W0[m++],p>1)J0[Z++]=W0[m++]}}else{m=Z-b;do J0[Z++]=J0[m++],J0[Z++]=J0[m++],J0[Z++]=J0[m++],p-=3;while(p>2);if(p){if(J0[Z++]=J0[m++],p>1)J0[Z++]=J0[m++]}}}else if((y&64)===0){f=T[(f&65535)+(z&(1<<y)-1)];continue G}else{Y.msg="invalid distance code",I0.mode=fU;break W}break}}else if((y&64)===0){f=D[(f&65535)+(z&(1<<y)-1)];continue Y}else if(y&32){I0.mode=nv;break W}else{Y.msg="invalid literal/length code",I0.mode=fU;break W}break}}while(X<J&&Z<U);p=w>>3,X-=p,w-=p<<3,z&=(1<<w)-1,Y.next_in=X,Y.next_out=Z,Y.avail_in=X<J?5+(J-X):5-(X-J),Y.avail_out=Z<U?257+(U-Z):257-(Z-U),I0.hold=z,I0.bits=w;return},nY=15,LD=852,BD=592,ED=0,TA=1,$D=2,rv=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),av=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),sv=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),tv=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),ev=(W,Y,G,X,J,Z,V,U)=>{let Q=U.bits,H=0,N=0,A=0,q=0,z=0,w=0,D=0,T=0,x=0,g=0,f,y,p,b,m,W0=null,u,J0=new Uint16Array(nY+1),I0=new Uint16Array(nY+1),k=null,l,B,$;for(H=0;H<=nY;H++)J0[H]=0;for(N=0;N<X;N++)J0[Y[G+N]]++;z=Q;for(q=nY;q>=1;q--)if(J0[q]!==0)break;if(z>q)z=q;if(q===0)return J[Z++]=20971520,J[Z++]=20971520,U.bits=1,0;for(A=1;A<q;A++)if(J0[A]!==0)break;if(z<A)z=A;T=1;for(H=1;H<=nY;H++)if(T<<=1,T-=J0[H],T<0)return-1;if(T>0&&(W===ED||q!==1))return-1;I0[1]=0;for(H=1;H<nY;H++)I0[H+1]=I0[H]+J0[H];for(N=0;N<X;N++)if(Y[G+N]!==0)V[I0[Y[G+N]]++]=N;if(W===ED)W0=k=V,u=20;else if(W===TA)W0=rv,k=av,u=257;else W0=sv,k=tv,u=0;if(g=0,N=0,H=A,m=Z,w=z,D=0,p=-1,x=1<<z,b=x-1,W===TA&&x>LD||W===$D&&x>BD)return 1;for(;;){if(l=H-D,V[N]+1<u)B=0,$=V[N];else if(V[N]>=u)B=k[V[N]-u],$=W0[V[N]-u];else B=96,$=0;f=1<<H-D,y=1<<w,A=y;do y-=f,J[m+(g>>D)+y]=l<<24|B<<16|$|0;while(y!==0);f=1<<H-1;while(g&f)f>>=1;if(f!==0)g&=f-1,g+=f;else g=0;if(N++,--J0[H]===0){if(H===q)break;H=Y[G+V[N]]}if(H>z&&(g&b)!==p){if(D===0)D=z;m+=A,w=H-D,T=1<<w;while(w+D<q){if(T-=J0[w+D],T<=0)break;w++,T<<=1}if(x+=1<<w,W===TA&&x>LD||W===$D&&x>BD)return 1;p=g&b,J[p]=z<<24|w<<16|m-Z|0}}if(g!==0)J[m+g]=H-D<<24|4194304|0;return U.bits=z,0},wJ=ev,Wg=0,PC=1,LC=2,{Z_FINISH:FD,Z_BLOCK:Yg,Z_TREES:cU,Z_OK:OW,Z_STREAM_END:Gg,Z_NEED_DICT:Xg,Z_STREAM_ERROR:j5,Z_DATA_ERROR:BC,Z_MEM_ERROR:EC,Z_BUF_ERROR:Jg,Z_DEFLATED:SD}=KW,sU=16180,xD=16181,kD=16182,_D=16183,yD=16184,vD=16185,gD=16186,uD=16187,hD=16188,bD=16189,iU=16190,s7=16191,RA=16192,mD=16193,MA=16194,fD=16195,cD=16196,pD=16197,lD=16198,pU=16199,lU=16200,dD=16201,oD=16202,nD=16203,iD=16204,rD=16205,PA=16206,aD=16207,sD=16208,w8=16209,$C=16210,FC=16211,Zg=852,Vg=592,Ug=15,Qg=Ug,tD=(W)=>{return(W>>>24&255)+(W>>>8&65280)+((W&65280)<<8)+((W&255)<<24)};function Hg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var DW=(W)=>{if(!W)return 1;let Y=W.state;if(!Y||Y.strm!==W||Y.mode<sU||Y.mode>FC)return 1;return 0},SC=(W)=>{if(DW(W))return j5;let Y=W.state;if(W.total_in=W.total_out=Y.total=0,W.msg="",Y.wrap)W.adler=Y.wrap&1;return Y.mode=sU,Y.last=0,Y.havedict=0,Y.flags=-1,Y.dmax=32768,Y.head=null,Y.hold=0,Y.bits=0,Y.lencode=Y.lendyn=new Int32Array(Zg),Y.distcode=Y.distdyn=new Int32Array(Vg),Y.sane=1,Y.back=-1,OW},xC=(W)=>{if(DW(W))return j5;let Y=W.state;return Y.wsize=0,Y.whave=0,Y.wnext=0,SC(W)},kC=(W,Y)=>{let G;if(DW(W))return j5;let X=W.state;if(Y<0)G=0,Y=-Y;else if(G=(Y>>4)+5,Y<48)Y&=15;if(Y&&(Y<8||Y>15))return j5;if(X.window!==null&&X.wbits!==Y)X.window=null;return X.wrap=G,X.wbits=Y,xC(W)},_C=(W,Y)=>{if(!W)return j5;let G=new Hg;W.state=G,G.strm=W,G.window=null,G.mode=sU;let X=kC(W,Y);if(X!==OW)W.state=null;return X},Ng=(W)=>{return _C(W,Qg)},eD=!0,LA,BA,qg=(W)=>{if(eD){LA=new Int32Array(512),BA=new Int32Array(32);let Y=0;while(Y<144)W.lens[Y++]=8;while(Y<256)W.lens[Y++]=9;while(Y<280)W.lens[Y++]=7;while(Y<288)W.lens[Y++]=8;wJ(PC,W.lens,0,288,LA,0,W.work,{bits:9}),Y=0;while(Y<32)W.lens[Y++]=5;wJ(LC,W.lens,0,32,BA,0,W.work,{bits:5}),eD=!1}W.lencode=LA,W.lenbits=9,W.distcode=BA,W.distbits=5},yC=(W,Y,G,X)=>{let J,Z=W.state;if(Z.window===null)Z.wsize=1<<Z.wbits,Z.wnext=0,Z.whave=0,Z.window=new Uint8Array(Z.wsize);if(X>=Z.wsize)Z.window.set(Y.subarray(G-Z.wsize,G),0),Z.wnext=0,Z.whave=Z.wsize;else{if(J=Z.wsize-Z.wnext,J>X)J=X;if(Z.window.set(Y.subarray(G-X,G-X+J),Z.wnext),X-=J,X)Z.window.set(Y.subarray(G-X,G),0),Z.wnext=X,Z.whave=Z.wsize;else{if(Z.wnext+=J,Z.wnext===Z.wsize)Z.wnext=0;if(Z.whave<Z.wsize)Z.whave+=J}}return 0},Ag=(W,Y)=>{let G,X,J,Z,V,U,Q,H,N,A,q,z,w,D,T=0,x,g,f,y,p,b,m,W0,u=new Uint8Array(4),J0,I0,k=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(DW(W)||!W.output||!W.input&&W.avail_in!==0)return j5;if(G=W.state,G.mode===s7)G.mode=RA;V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,X=W.input,U=W.avail_in,H=G.hold,N=G.bits,A=U,q=Q,W0=OW;W:for(;;)switch(G.mode){case sU:if(G.wrap===0){G.mode=RA;break}while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&2&&H===35615){if(G.wbits===0)G.wbits=15;G.check=0,u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0),H=0,N=0,G.mode=xD;break}if(G.head)G.head.done=!1;if(!(G.wrap&1)||(((H&255)<<8)+(H>>8))%31){W.msg="incorrect header check",G.mode=w8;break}if((H&15)!==SD){W.msg="unknown compression method",G.mode=w8;break}if(H>>>=4,N-=4,m=(H&15)+8,G.wbits===0)G.wbits=m;if(m>15||m>G.wbits){W.msg="invalid window size",G.mode=w8;break}G.dmax=1<<G.wbits,G.flags=0,W.adler=G.check=1,G.mode=H&512?bD:s7,H=0,N=0;break;case xD:while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.flags=H,(G.flags&255)!==SD){W.msg="unknown compression method",G.mode=w8;break}if(G.flags&57344){W.msg="unknown header flags set",G.mode=w8;break}if(G.head)G.head.text=H>>8&1;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0,G.mode=kD;case kD:while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.head)G.head.time=H;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,u[2]=H>>>16&255,u[3]=H>>>24&255,G.check=n8(G.check,u,4,0);H=0,N=0,G.mode=_D;case _D:while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.head)G.head.xflags=H&255,G.head.os=H>>8;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0,G.mode=yD;case yD:if(G.flags&1024){while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.length=H,G.head)G.head.extra_len=H;if(G.flags&512&&G.wrap&4)u[0]=H&255,u[1]=H>>>8&255,G.check=n8(G.check,u,2,0);H=0,N=0}else if(G.head)G.head.extra=null;G.mode=vD;case vD:if(G.flags&1024){if(z=G.length,z>U)z=U;if(z){if(G.head){if(m=G.head.extra_len-G.length,!G.head.extra)G.head.extra=new Uint8Array(G.head.extra_len);G.head.extra.set(X.subarray(Z,Z+z),m)}if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);U-=z,Z+=z,G.length-=z}if(G.length)break W}G.length=0,G.mode=gD;case gD:if(G.flags&2048){if(U===0)break W;z=0;do if(m=X[Z+z++],G.head&&m&&G.length<65536)G.head.name+=String.fromCharCode(m);while(m&&z<U);if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);if(U-=z,Z+=z,m)break W}else if(G.head)G.head.name=null;G.length=0,G.mode=uD;case uD:if(G.flags&4096){if(U===0)break W;z=0;do if(m=X[Z+z++],G.head&&m&&G.length<65536)G.head.comment+=String.fromCharCode(m);while(m&&z<U);if(G.flags&512&&G.wrap&4)G.check=n8(G.check,X,z,Z);if(U-=z,Z+=z,m)break W}else if(G.head)G.head.comment=null;G.mode=hD;case hD:if(G.flags&512){while(N<16){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&4&&H!==(G.check&65535)){W.msg="header crc mismatch",G.mode=w8;break}H=0,N=0}if(G.head)G.head.hcrc=G.flags>>9&1,G.head.done=!0;W.adler=G.check=0,G.mode=s7;break;case bD:while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}W.adler=G.check=tD(H),H=0,N=0,G.mode=iU;case iU:if(G.havedict===0)return W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,Xg;W.adler=G.check=1,G.mode=s7;case s7:if(Y===Yg||Y===cU)break W;case RA:if(G.last){H>>>=N&7,N-=N&7,G.mode=PA;break}while(N<3){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}switch(G.last=H&1,H>>>=1,N-=1,H&3){case 0:G.mode=mD;break;case 1:if(qg(G),G.mode=pU,Y===cU){H>>>=2,N-=2;break W}break;case 2:G.mode=cD;break;case 3:W.msg="invalid block type",G.mode=w8}H>>>=2,N-=2;break;case mD:H>>>=N&7,N-=N&7;while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if((H&65535)!==(H>>>16^65535)){W.msg="invalid stored block lengths",G.mode=w8;break}if(G.length=H&65535,H=0,N=0,G.mode=MA,Y===cU)break W;case MA:G.mode=fD;case fD:if(z=G.length,z){if(z>U)z=U;if(z>Q)z=Q;if(z===0)break W;J.set(X.subarray(Z,Z+z),V),U-=z,Z+=z,Q-=z,V+=z,G.length-=z;break}G.mode=s7;break;case cD:while(N<14){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.nlen=(H&31)+257,H>>>=5,N-=5,G.ndist=(H&31)+1,H>>>=5,N-=5,G.ncode=(H&15)+4,H>>>=4,N-=4,G.nlen>286||G.ndist>30){W.msg="too many length or distance symbols",G.mode=w8;break}G.have=0,G.mode=pD;case pD:while(G.have<G.ncode){while(N<3){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.lens[k[G.have++]]=H&7,H>>>=3,N-=3}while(G.have<19)G.lens[k[G.have++]]=0;if(G.lencode=G.lendyn,G.lenbits=7,J0={bits:G.lenbits},W0=wJ(Wg,G.lens,0,19,G.lencode,0,G.work,J0),G.lenbits=J0.bits,W0){W.msg="invalid code lengths set",G.mode=w8;break}G.have=0,G.mode=lD;case lD:while(G.have<G.nlen+G.ndist){for(;;){if(T=G.lencode[H&(1<<G.lenbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(f<16)H>>>=x,N-=x,G.lens[G.have++]=f;else{if(f===16){I0=x+2;while(N<I0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(H>>>=x,N-=x,G.have===0){W.msg="invalid bit length repeat",G.mode=w8;break}m=G.lens[G.have-1],z=3+(H&3),H>>>=2,N-=2}else if(f===17){I0=x+3;while(N<I0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=x,N-=x,m=0,z=3+(H&7),H>>>=3,N-=3}else{I0=x+7;while(N<I0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=x,N-=x,m=0,z=11+(H&127),H>>>=7,N-=7}if(G.have+z>G.nlen+G.ndist){W.msg="invalid bit length repeat",G.mode=w8;break}while(z--)G.lens[G.have++]=m}}if(G.mode===w8)break;if(G.lens[256]===0){W.msg="invalid code -- missing end-of-block",G.mode=w8;break}if(G.lenbits=9,J0={bits:G.lenbits},W0=wJ(PC,G.lens,0,G.nlen,G.lencode,0,G.work,J0),G.lenbits=J0.bits,W0){W.msg="invalid literal/lengths set",G.mode=w8;break}if(G.distbits=6,G.distcode=G.distdyn,J0={bits:G.distbits},W0=wJ(LC,G.lens,G.nlen,G.ndist,G.distcode,0,G.work,J0),G.distbits=J0.bits,W0){W.msg="invalid distances set",G.mode=w8;break}if(G.mode=pU,Y===cU)break W;case pU:G.mode=lU;case lU:if(U>=6&&Q>=258){if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,iv(W,q),V=W.next_out,J=W.output,Q=W.avail_out,Z=W.next_in,X=W.input,U=W.avail_in,H=G.hold,N=G.bits,G.mode===s7)G.back=-1;break}G.back=0;for(;;){if(T=G.lencode[H&(1<<G.lenbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(g&&(g&240)===0){y=x,p=g,b=f;for(;;){if(T=G.lencode[b+((H&(1<<y+p)-1)>>y)],x=T>>>24,g=T>>>16&255,f=T&65535,y+x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=y,N-=y,G.back+=y}if(H>>>=x,N-=x,G.back+=x,G.length=f,g===0){G.mode=rD;break}if(g&32){G.back=-1,G.mode=s7;break}if(g&64){W.msg="invalid literal/length code",G.mode=w8;break}G.extra=g&15,G.mode=dD;case dD:if(G.extra){I0=G.extra;while(N<I0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.length+=H&(1<<G.extra)-1,H>>>=G.extra,N-=G.extra,G.back+=G.extra}G.was=G.length,G.mode=oD;case oD:for(;;){if(T=G.distcode[H&(1<<G.distbits)-1],x=T>>>24,g=T>>>16&255,f=T&65535,x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if((g&240)===0){y=x,p=g,b=f;for(;;){if(T=G.distcode[b+((H&(1<<y+p)-1)>>y)],x=T>>>24,g=T>>>16&255,f=T&65535,y+x<=N)break;if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}H>>>=y,N-=y,G.back+=y}if(H>>>=x,N-=x,G.back+=x,g&64){W.msg="invalid distance code",G.mode=w8;break}G.offset=f,G.extra=g&15,G.mode=nD;case nD:if(G.extra){I0=G.extra;while(N<I0){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}G.offset+=H&(1<<G.extra)-1,H>>>=G.extra,N-=G.extra,G.back+=G.extra}if(G.offset>G.dmax){W.msg="invalid distance too far back",G.mode=w8;break}G.mode=iD;case iD:if(Q===0)break W;if(z=q-Q,G.offset>z){if(z=G.offset-z,z>G.whave){if(G.sane){W.msg="invalid distance too far back",G.mode=w8;break}}if(z>G.wnext)z-=G.wnext,w=G.wsize-z;else w=G.wnext-z;if(z>G.length)z=G.length;D=G.window}else D=J,w=V-G.offset,z=G.length;if(z>Q)z=Q;Q-=z,G.length-=z;do J[V++]=D[w++];while(--z);if(G.length===0)G.mode=lU;break;case rD:if(Q===0)break W;J[V++]=G.length,Q--,G.mode=lU;break;case PA:if(G.wrap){while(N<32){if(U===0)break W;U--,H|=X[Z++]<<N,N+=8}if(q-=Q,W.total_out+=q,G.total+=q,G.wrap&4&&q)W.adler=G.check=G.flags?n8(G.check,J,q,V-q):CJ(G.check,J,q,V-q);if(q=Q,G.wrap&4&&(G.flags?H:tD(H))!==G.check){W.msg="incorrect data check",G.mode=w8;break}H=0,N=0}G.mode=aD;case aD:if(G.wrap&&G.flags){while(N<32){if(U===0)break W;U--,H+=X[Z++]<<N,N+=8}if(G.wrap&4&&H!==(G.total&4294967295)){W.msg="incorrect length check",G.mode=w8;break}H=0,N=0}G.mode=sD;case sD:W0=Gg;break W;case w8:W0=BC;break W;case $C:return EC;case FC:default:return j5}if(W.next_out=V,W.avail_out=Q,W.next_in=Z,W.avail_in=U,G.hold=H,G.bits=N,G.wsize||q!==W.avail_out&&G.mode<w8&&(G.mode<PA||Y!==FD)){if(yC(W,W.output,W.next_out,q-W.avail_out));}if(A-=W.avail_in,q-=W.avail_out,W.total_in+=A,W.total_out+=q,G.total+=q,G.wrap&4&&q)W.adler=G.check=G.flags?n8(G.check,J,q,W.next_out-q):CJ(G.check,J,q,W.next_out-q);if(W.data_type=G.bits+(G.last?64:0)+(G.mode===s7?128:0)+(G.mode===pU||G.mode===MA?256:0),(A===0&&q===0||Y===FD)&&W0===OW)W0=Jg;return W0},Ig=(W)=>{if(DW(W))return j5;let Y=W.state;if(Y.window)Y.window=null;return W.state=null,OW},zg=(W,Y)=>{if(DW(W))return j5;let G=W.state;if((G.wrap&2)===0)return j5;return G.head=Y,Y.done=!1,OW},wg=(W,Y)=>{let G=Y.length,X,J,Z;if(DW(W))return j5;if(X=W.state,X.wrap!==0&&X.mode!==iU)return j5;if(X.mode===iU){if(J=1,J=CJ(J,Y,G,0),J!==X.check)return BC}if(Z=yC(W,Y,G,G),Z)return X.mode=$C,EC;return X.havedict=1,OW},jg=xC,Og=kC,Kg=SC,Dg=Ng,Cg=_C,Tg=Ag,Rg=Ig,Mg=zg,Pg=wg,Lg="pako inflate (from Nodeca project)",e7={inflateReset:jg,inflateReset2:Og,inflateResetKeep:Kg,inflateInit:Dg,inflateInit2:Cg,inflate:Tg,inflateEnd:Rg,inflateGetHeader:Mg,inflateSetDictionary:Pg,inflateInfo:Lg};function Bg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var Eg=Bg,vC=Object.prototype.toString,{Z_NO_FLUSH:$g,Z_FINISH:Fg,Z_OK:MJ,Z_STREAM_END:EA,Z_NEED_DICT:$A,Z_STREAM_ERROR:Sg,Z_DATA_ERROR:WC,Z_MEM_ERROR:xg}=KW;function EJ(W){this.options=aU.assign({chunkSize:65536,windowBits:15,to:""},W||{});let Y=this.options;if(Y.raw&&Y.windowBits>=0&&Y.windowBits<16){if(Y.windowBits=-Y.windowBits,Y.windowBits===0)Y.windowBits=-15}if(Y.windowBits>=0&&Y.windowBits<16&&!(W&&W.windowBits))Y.windowBits+=32;if(Y.windowBits>15&&Y.windowBits<48){if((Y.windowBits&15)===0)Y.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new RC,this.strm.avail_out=0;let G=e7.inflateInit2(this.strm,Y.windowBits);if(G!==MJ)throw Error(wW[G]);if(this.header=new Eg,e7.inflateGetHeader(this.strm,this.header),Y.dictionary){if(typeof Y.dictionary==="string")Y.dictionary=RJ.string2buf(Y.dictionary);else if(vC.call(Y.dictionary)==="[object ArrayBuffer]")Y.dictionary=new Uint8Array(Y.dictionary);if(Y.raw){if(G=e7.inflateSetDictionary(this.strm,Y.dictionary),G!==MJ)throw Error(wW[G])}}}EJ.prototype.push=function(W,Y){let G=this.strm,X=this.options.chunkSize,J=this.options.dictionary,Z,V,U;if(this.ended)return!1;if(Y===~~Y)V=Y;else V=Y===!0?Fg:$g;if(vC.call(W)==="[object ArrayBuffer]")G.input=new Uint8Array(W);else G.input=W;G.next_in=0,G.avail_in=G.input.length;for(;;){if(G.avail_out===0)G.output=new Uint8Array(X),G.next_out=0,G.avail_out=X;if(Z=e7.inflate(G,V),Z===$A&&J){if(Z=e7.inflateSetDictionary(G,J),Z===MJ)Z=e7.inflate(G,V);else if(Z===WC)Z=$A}while(G.avail_in>0&&Z===EA&&G.state.wrap>0&&W[G.next_in]!==0)e7.inflateReset(G),Z=e7.inflate(G,V);switch(Z){case Sg:case WC:case $A:case xg:return this.onEnd(Z),this.ended=!0,!1}if(U=G.avail_out,G.next_out){if(G.avail_out===0||Z===EA)if(this.options.to==="string"){let Q=RJ.utf8border(G.output,G.next_out),H=G.next_out-Q,N=RJ.buf2string(G.output,Q);if(G.next_out=H,G.avail_out=X-H,H)G.output.set(G.output.subarray(Q,Q+H),0);this.onData(N)}else this.onData(G.output.length===G.next_out?G.output:G.output.subarray(0,G.next_out))}if(Z===MJ&&U===0)continue;if(Z===EA)return Z=e7.inflateEnd(this.strm),this.onEnd(Z),this.ended=!0,!0;if(G.avail_in===0)break}return!0};EJ.prototype.onData=function(W){this.chunks.push(W)};EJ.prototype.onEnd=function(W){if(W===MJ)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=aU.flattenChunks(this.chunks);this.chunks=[],this.err=W,this.msg=this.strm.msg};function lA(W,Y){let G=new EJ(Y);if(G.push(W),G.err)throw G.msg||wW[G.err];return G.result}function kg(W,Y){return Y=Y||{},Y.raw=!0,lA(W,Y)}var _g=EJ,yg=lA,vg=kg,gg=lA,ug=KW,hg={Inflate:_g,inflate:yg,inflateRaw:vg,ungzip:gg,constants:ug},{Deflate:bg,deflate:mg,deflateRaw:fg,gzip:cg}=ov,{Inflate:pg,inflate:lg,inflateRaw:dg,ungzip:og}=hg,ng=bg,ig=mg,rg=fg,ag=cg,sg=pg,tg=lg,eg=dg,Wu=og,Yu=KW,WG={Deflate:ng,deflate:ig,deflateRaw:rg,gzip:ag,Inflate:sg,inflate:tg,inflateRaw:eg,ungzip:Wu,constants:Yu};function gC(){let W=Date.now(),Y=0;return{now(){return W=Math.max(W,Date.now()),Y++,{physical:W,logical:Y}},update(G){if(!G||typeof G.physical!=="number"||typeof G.logical!=="number")return;W=Math.max(W,G.physical),Y=Math.max(Y,G.logical)+1},compare(G,X){if(!G&&!X)return 0;if(!G)return-1;if(!X)return 1;if(G.physical!==X.physical)return G.physical>X.physical?1:-1;if(G.logical!==X.logical)return G.logical>X.logical?1:-1;return 0}}}function uC(W,Y,G){let X=Y.timestamp;if(X?.physical>Date.now()+7200000)X={physical:Date.now()+7200000,logical:X.logical};if(Y?.value?.priority===!0&&typeof Y.id==="string"&&Y.id.startsWith("user:")&&"role"in Y.value){let{priority:J,...Z}=Y.value;return{resolved:!0,value:Z,timestamp:X}}if(Y?.value?.priority!==void 0){let{priority:J,...Z}=Y.value;Y={...Y,value:Z}}if(!W?.timestamp)return{resolved:!0,value:Y.value,timestamp:X};if(G.compare(X,W.timestamp)<=0)return{resolved:!1};return{resolved:!0,value:Y.value,timestamp:X}}var $J={$eq:(W,Y)=>W===Y,$ne:(W,Y)=>W!==Y,$gt:(W,Y)=>W>Y,$gte:(W,Y)=>W>=Y,$lt:(W,Y)=>W<Y,$lte:(W,Y)=>W<=Y,$in:(W,Y)=>Array.isArray(Y)&&(Array.isArray(W)?W.some((G)=>Y.includes(G)):Y.includes(W)),$between:(W,[Y,G])=>W>=Y&&W<=G,$exists:(W,Y)=>Y?W!==void 0:W===void 0,$startsWith:(W,Y)=>typeof W==="string"&&W.startsWith(Y),$endsWith:(W,Y)=>typeof W==="string"&&W.endsWith(Y),$contains:(W,Y)=>typeof W==="string"&&W.includes(Y),$text:{global:(W,Y)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),X=G(Y);return Object.values(W).some((J)=>typeof J==="object"?null.fieldSearch(J,X):G(J).includes(X))},field:(W,Y)=>{let G=(J)=>String(J).normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\w\s]/g,""),X=G(Y);return Array.isArray(W)?W.some((J)=>G(J).includes(X)):G(W).includes(X)}},$like:(W,Y)=>typeof W==="string"&&typeof Y==="string"&&new RegExp(`^${Y.replace(/%/g,".*").replace(/_/g,".")}$`,"i").test(W),$regex:(W,Y)=>typeof W==="string"&&new RegExp(Y.$regex||Y,"i").test(W),$and:(W,Y,G)=>Y.every((X)=>G.createFilter(X,G.allNodes)(W)),$or:(W,Y,G)=>Y.some((X)=>G.createFilter(X,G.allNodes)(W)),$not:(W,Y,G)=>!G.createFilter(Y,G.allNodes)(W),$edge:(W,Y,G)=>{if(!W.edges?.length||typeof Y!=="object"||Y===null)return!1;let X=G.createFilter(Y,G.allNodes),J=[...W.edges],Z=new Set(J).add(W.id),V=[];while(J.length){let U=J.shift(),Q=G.allNodes[U];if(!Q)continue;if(X(Q))V.push(Q);Q.edges?.forEach((H)=>!Z.has(H)&&Z.add(H)&&J.push(H))}if(V.length)W._edgeResult=V;return V.length>0}},tU=(W,Y)=>Y.split(".").reduce((G,X)=>G&&typeof G==="object"&&(X in G)?G[X]:void 0,W),eU=(W,Y)=>{if(Object.keys(W).length===0)return()=>!0;return(G)=>Object.entries(W).every(([X,J])=>{if(X.startsWith("$"))return $J[X](G,J,{createFilter:eU,allNodes:Y});let Z=tU(G.value,X);if(Z===void 0)Z=tU(G,X);if(typeof J!=="object"||J===null)return $J.$eq(Z,J);return Object.entries(J).every(([V,U])=>{if(V==="$text")return $J.$text.field(Z,U);if(V==="$between"&&U.every((Q)=>Q instanceof Date))return $J.$between(new Date(Z),U);return $J[V]?.(Z,U,{createFilter:eU,allNodes:Y})??!1})})},dA=(W,Y)=>{let{$edge:G,...X}=Y.query||{},J=eU(X,W),Z=Object.values(W).filter(J),U=[...G?(()=>{let Q=eU({$edge:G},W);Z.forEach((N)=>Q(N));let H=new Map;return Z.forEach((N)=>{if(N._edgeResult)N._edgeResult.forEach((A)=>H.set(A.id,A)),delete N._edgeResult}),Array.from(H.values())})():Z];if(Y.field){let Q=Y.order==="asc"?1:-1;U.sort((H,N)=>{let A=tU(H.value,Y.field),q=tU(N.value,Y.field);if(typeof A==="string"&&typeof q==="string")return A.localeCompare(q)*Q;return((A??0)-(q??0))*Q})}if(Y.$after){let Q=U.findIndex((H)=>H.id===Y.$after);U=Q>=0?U.slice(Q+1):[]}if(Y.$before){let Q=U.findIndex((H)=>H.id===Y.$before);U=Q>=0?U.slice(0,Q):[]}if(Y.$limit)U=U.slice(0,Y.$limit);return U};var vJ=(()=>{let W=()=>{};return new Proxy(console,{get:(Y,G)=>globalThis.__gdbDebug?Y[G].bind(Y):W})})(),YG=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function TQ(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function XI(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function LW(W,...Y){if(!TQ(W))throw Error("Uint8Array expected");if(Y.length>0&&!Y.includes(W.length))throw Error("Uint8Array expected of length "+Y+", got length="+W.length)}function XT(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");XI(W.outputLen),XI(W.blockLen)}function qQ(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function Gu(W,Y){LW(W);let G=Y.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function AQ(...W){for(let Y=0;Y<W.length;Y++)W[Y].fill(0)}function oA(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function I7(W,Y){return W<<32-Y|W>>>Y}var JT=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),Xu=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function JG(W){if(LW(W),JT)return W.toHex();let Y="";for(let G=0;G<W.length;G++)Y+=Xu[W[G]];return Y}var W4={_0:48,_9:57,A:65,F:70,a:97,f:102};function hC(W){if(W>=W4._0&&W<=W4._9)return W-W4._0;if(W>=W4.A&&W<=W4.F)return W-(W4.A-10);if(W>=W4.a&&W<=W4.f)return W-(W4.a-10);return}function IQ(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(JT)return Uint8Array.fromHex(W);let Y=W.length,G=Y/2;if(Y%2)throw Error("hex string expected, got unpadded hex of length "+Y);let X=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=hC(W.charCodeAt(Z)),U=hC(W.charCodeAt(Z+1));if(V===void 0||U===void 0){let Q=W[Z]+W[Z+1];throw Error('hex string expected, got non-hex character "'+Q+'" at index '+Z)}X[J]=V*16+U}return X}function ZT(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function qI(W){if(typeof W==="string")W=ZT(W);return LW(W),W}function z7(...W){let Y=0;for(let X=0;X<W.length;X++){let J=W[X];LW(J),Y+=J.length}let G=new Uint8Array(Y);for(let X=0,J=0;X<W.length;X++){let Z=W[X];G.set(Z,J),J+=Z.length}return G}class AI{}function Ju(W){let Y=(X)=>W().update(qI(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function RQ(W=32){if(YG&&typeof YG.getRandomValues==="function")return YG.getRandomValues(new Uint8Array(W));if(YG&&typeof YG.randomBytes==="function")return Uint8Array.from(YG.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}function Zu(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}function Vu(W,Y,G){return W&Y^~W&G}function Uu(W,Y,G){return W&Y^W&G^Y&G}class VT extends AI{constructor(W,Y,G,X){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.buffer=new Uint8Array(W),this.view=oA(this.buffer)}update(W){qQ(this),W=qI(W),LW(W);let{view:Y,buffer:G,blockLen:X}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=oA(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){qQ(this),Gu(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,AQ(this.buffer.subarray(Z)),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Zu(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=oA(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=X,W.pos=V,X%Y)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var H6=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Qu=Uint32Array.from([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]),N6=new Uint32Array(64);class UT extends VT{constructor(W=32){super(64,W,8,!1);this.A=H6[0]|0,this.B=H6[1]|0,this.C=H6[2]|0,this.D=H6[3]|0,this.E=H6[4]|0,this.F=H6[5]|0,this.G=H6[6]|0,this.H=H6[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)N6[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=N6[N-15],q=N6[N-2],z=I7(A,7)^I7(A,18)^A>>>3,w=I7(q,17)^I7(q,19)^q>>>10;N6[N]=w+N6[N-7]+z+N6[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=I7(V,6)^I7(V,11)^I7(V,25),q=H+A+Vu(V,U,Q)+Qu[N]+N6[N]|0,z=(I7(G,2)^I7(G,13)^I7(G,22))+Uu(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+z|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){AQ(N6)}destroy(){this.set(0,0,0,0,0,0,0,0),AQ(this.buffer)}}var JI=Ju(()=>new UT);class II extends AI{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,XT(W);let G=qI(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),AQ(J)}update(W){return qQ(this),this.iHash.update(W),this}digestInto(W){qQ(this),LW(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var QT=(W,Y,G)=>new II(W,Y).update(G).digest();QT.create=(W,Y)=>new II(W,Y);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var zI=BigInt(0),ZI=BigInt(1);function zQ(W,Y=""){if(typeof W!=="boolean"){let G=Y&&`"${Y}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function CW(W,Y,G=""){let X=TQ(W),J=W?.length,Z=Y!==void 0;if(!X||Z&&J!==Y){let V=G&&`"${G}" `,U=Z?` of length ${Y}`:"",Q=X?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function WQ(W){let Y=W.toString(16);return Y.length&1?"0"+Y:Y}function HT(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?zI:BigInt("0x"+W)}function HG(W){return HT(JG(W))}function NT(W){return LW(W),HT(JG(Uint8Array.from(W).reverse()))}function MQ(W,Y){return IQ(W.toString(16).padStart(Y*2,"0"))}function qT(W,Y){return MQ(W,Y).reverse()}function b8(W,Y,G){let X;if(typeof Y==="string")try{X=IQ(Y)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(TQ(Y))X=Uint8Array.from(Y);else throw Error(W+" must be hex string or Uint8Array");let J=X.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return X}var nA=(W)=>typeof W==="bigint"&&zI<=W;function VI(W,Y,G){return nA(W)&&nA(Y)&&nA(G)&&Y<=W&&W<G}function Hu(W,Y,G,X){if(!VI(Y,G,X))throw Error("expected valid "+W+": "+G+" <= n < "+X+", got "+Y)}function AT(W){let Y;for(Y=0;W>zI;W>>=ZI,Y+=1);return Y}var hJ=(W)=>(ZI<<BigInt(W))-ZI;function Nu(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=(q)=>new Uint8Array(q),J=(q)=>Uint8Array.of(q),Z=X(W),V=X(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},H=(...q)=>G(V,Z,...q),N=(q=X(0))=>{if(V=H(J(0),q),Z=H(),q.length===0)return;V=H(J(1),q),Z=H()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let q=0,z=[];while(q<Y){Z=H();let w=Z.slice();z.push(w),q+=Z.length}return z7(...z)};return(q,z)=>{Q(),N(q);let w=void 0;while(!(w=z(A())))N();return Q(),w}}function wI(W,Y,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function X(J,Z,V){let U=W[J];if(V&&U===void 0)return;let Q=typeof U;if(Q!==Z||U===null)throw Error(`param "${J}" is invalid: expected ${Z}, got ${Q}`)}Object.entries(Y).forEach(([J,Z])=>X(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>X(J,Z,!0))}function bC(W){let Y=new WeakMap;return(G,...X)=>{let J=Y.get(G);if(J!==void 0)return J;let Z=W(G,...X);return Y.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var k9=BigInt(0),q9=BigInt(1),TW=BigInt(2),IT=BigInt(3),zT=BigInt(4),wT=BigInt(5),qu=BigInt(7),jT=BigInt(8),Au=BigInt(9),OT=BigInt(16);function D5(W,Y){let G=W%Y;return G>=k9?G:Y+G}function O5(W,Y,G){let X=W;while(Y-- >k9)X*=X,X%=G;return X}function mC(W,Y){if(W===k9)throw Error("invert: expected non-zero number");if(Y<=k9)throw Error("invert: expected positive modulus, got "+Y);let G=D5(W,Y),X=Y,J=k9,Z=q9,V=q9,U=k9;while(G!==k9){let Q=X/G,H=X%G,N=J-V*Q,A=Z-U*Q;X=G,G=H,J=V,Z=U,V=N,U=A}if(X!==q9)throw Error("invert: does not exist");return D5(J,Y)}function jI(W,Y,G){if(!W.eql(W.sqr(Y),G))throw Error("Cannot find square root")}function KT(W,Y){let G=(W.ORDER+q9)/zT,X=W.pow(Y,G);return jI(W,X,Y),X}function Iu(W,Y){let G=(W.ORDER-wT)/jT,X=W.mul(Y,TW),J=W.pow(X,G),Z=W.mul(Y,J),V=W.mul(W.mul(Z,TW),J),U=W.mul(Z,W.sub(V,W.ONE));return jI(W,U,Y),U}function zu(W){let Y=bJ(W),G=DT(W),X=G(Y,Y.neg(Y.ONE)),J=G(Y,X),Z=G(Y,Y.neg(X)),V=(W+qu)/OT;return(U,Q)=>{let H=U.pow(Q,V),N=U.mul(H,X),A=U.mul(H,J),q=U.mul(H,Z),z=U.eql(U.sqr(N),Q),w=U.eql(U.sqr(A),Q);H=U.cmov(H,N,z),N=U.cmov(q,A,w);let D=U.eql(U.sqr(N),Q),T=U.cmov(H,N,D);return jI(U,T,Q),T}}function DT(W){if(W<IT)throw Error("sqrt is not defined for small field");let Y=W-q9,G=0;while(Y%TW===k9)Y/=TW,G++;let X=TW,J=bJ(W);while(fC(J,X)===1)if(X++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return KT;let Z=J.pow(X,Y),V=(Y+q9)/TW;return function(U,Q){if(U.is0(Q))return Q;if(fC(U,Q)!==1)throw Error("Cannot find square root");let H=G,N=U.mul(U.ONE,Z),A=U.pow(Q,Y),q=U.pow(Q,V);while(!U.eql(A,U.ONE)){if(U.is0(A))return U.ZERO;let z=1,w=U.sqr(A);while(!U.eql(w,U.ONE))if(z++,w=U.sqr(w),z===H)throw Error("Cannot find square root");let D=q9<<BigInt(H-z-1),T=U.pow(N,D);H=z,N=U.sqr(T),A=U.mul(A,N),q=U.mul(q,T)}return q}}function wu(W){if(W%zT===IT)return KT;if(W%jT===wT)return Iu;if(W%OT===Au)return zu(W);return DT(W)}var ju=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ou(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=ju.reduce((X,J)=>{return X[J]="function",X},Y);return wI(W,G),W}function Ku(W,Y,G){if(G<k9)throw Error("invalid exponent, negatives unsupported");if(G===k9)return W.ONE;if(G===q9)return Y;let X=W.ONE,J=Y;while(G>k9){if(G&q9)X=W.mul(X,J);J=W.sqr(J),G>>=q9}return X}function CT(W,Y,G=!1){let X=Array(Y.length).fill(G?W.ZERO:void 0),J=Y.reduce((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return Y.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=W.mul(V,X[Q]),W.mul(V,U)},Z),X}function fC(W,Y){let G=(W.ORDER-q9)/TW,X=W.pow(Y,G),J=W.eql(X,W.ONE),Z=W.eql(X,W.ZERO),V=W.eql(X,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function TT(W,Y){if(Y!==void 0)XI(Y);let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function bJ(W,Y,G=!1,X={}){if(W<=k9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof Y==="object"&&Y!=null){if(X.sqrt||G)throw Error("cannot specify opts in two arguments");let q=Y;if(q.BITS)J=q.BITS;if(q.sqrt)Z=q.sqrt;if(typeof q.isLE==="boolean")G=q.isLE;if(typeof q.modFromBytes==="boolean")V=q.modFromBytes;U=q.allowedLengths}else{if(typeof Y==="number")J=Y;if(X.sqrt)Z=X.sqrt}let{nBitLength:Q,nByteLength:H}=TT(W,J);if(H>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let N,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:H,MASK:hJ(Q),ZERO:k9,ONE:q9,allowedLengths:U,create:(q)=>D5(q,W),isValid:(q)=>{if(typeof q!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof q);return k9<=q&&q<W},is0:(q)=>q===k9,isValidNot0:(q)=>!A.is0(q)&&A.isValid(q),isOdd:(q)=>(q&q9)===q9,neg:(q)=>D5(-q,W),eql:(q,z)=>q===z,sqr:(q)=>D5(q*q,W),add:(q,z)=>D5(q+z,W),sub:(q,z)=>D5(q-z,W),mul:(q,z)=>D5(q*z,W),pow:(q,z)=>Ku(A,q,z),div:(q,z)=>D5(q*mC(z,W),W),sqrN:(q)=>q*q,addN:(q,z)=>q+z,subN:(q,z)=>q-z,mulN:(q,z)=>q*z,inv:(q)=>mC(q,W),sqrt:Z||((q)=>{if(!N)N=wu(W);return N(A,q)}),toBytes:(q)=>G?qT(q,H):MQ(q,H),fromBytes:(q,z=!0)=>{if(U){if(!U.includes(q.length)||q.length>H)throw Error("Field.fromBytes: expected "+U+" bytes, got "+q.length);let D=new Uint8Array(H);D.set(q,G?0:D.length-q.length),q=D}if(q.length!==H)throw Error("Field.fromBytes: expected "+H+" bytes, got "+q.length);let w=G?NT(q):HG(q);if(V)w=D5(w,W);if(!z){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(q)=>CT(A,q),cmov:(q,z,w)=>w?z:q});return Object.freeze(A)}function RT(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function MT(W){let Y=RT(W);return Y+Math.ceil(Y/2)}function PT(W,Y,G=!1){let X=W.length,J=RT(Y),Z=MT(Y);if(X<16||X<Z||X>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+X);let V=G?NT(W):HG(W),U=D5(V,Y-q9)+q9;return G?qT(U,J):MQ(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var UG=BigInt(0),RW=BigInt(1);function wQ(W,Y){let G=Y.negate();return W?G:Y}function iA(W,Y){let G=CT(W.Fp,Y.map((X)=>X.Z));return Y.map((X,J)=>W.fromAffine(X.toAffine(G[J])))}function LT(W,Y){if(!Number.isSafeInteger(W)||W<=0||W>Y)throw Error("invalid window size, expected [1.."+Y+"], got W="+W)}function rA(W,Y){LT(W,Y);let G=Math.ceil(Y/W)+1,X=2**(W-1),J=2**W,Z=hJ(W),V=BigInt(W);return{windows:G,windowSize:X,mask:Z,maxNumber:J,shiftBy:V}}function cC(W,Y,G){let{windowSize:X,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>X)U-=Z,Q+=RW;let H=Y*X,N=H+Math.abs(U)-1,A=U===0,q=U<0,z=Y%2!==0;return{nextN:Q,offset:N,isZero:A,isNeg:q,isNegF:z,offsetF:H}}function Du(W,Y){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,X)=>{if(!(G instanceof Y))throw Error("invalid point at index "+X)})}function Cu(W,Y){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,X)=>{if(!Y.isValid(G))throw Error("invalid scalar at index "+X)})}var aA=new WeakMap,BT=new WeakMap;function sA(W){return BT.get(W)||1}function pC(W){if(W!==UG)throw Error("invalid wNAF")}class ET{constructor(W,Y){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=Y}_unsafeLadder(W,Y,G=this.ZERO){let X=W;while(Y>UG){if(Y&RW)G=G.add(X);X=X.double(),Y>>=RW}return G}precomputeWindow(W,Y){let{windows:G,windowSize:X}=rA(Y,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<X;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,Y,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let X=this.ZERO,J=this.BASE,Z=rA(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:H,isNeg:N,isNegF:A,offsetF:q}=cC(G,V,Z);if(G=U,H)J=J.add(wQ(A,Y[q]));else X=X.add(wQ(N,Y[Q]))}return pC(G),{p:X,f:J}}wNAFUnsafe(W,Y,G,X=this.ZERO){let J=rA(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===UG)break;let{nextN:V,offset:U,isZero:Q,isNeg:H}=cC(G,Z,J);if(G=V,Q)continue;else{let N=Y[U];X=X.add(H?N.negate():N)}}return pC(G),X}getPrecomputes(W,Y,G){let X=aA.get(Y);if(!X){if(X=this.precomputeWindow(Y,W),W!==1){if(typeof G==="function")X=G(X);aA.set(Y,X)}}return X}cached(W,Y,G){let X=sA(W);return this.wNAF(X,this.getPrecomputes(X,W,G),Y)}unsafe(W,Y,G,X){let J=sA(W);if(J===1)return this._unsafeLadder(W,Y,X);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),Y,X)}createCache(W,Y){LT(Y,this.bits),BT.set(W,Y),aA.delete(W)}hasCache(W){return sA(W)!==1}}function Tu(W,Y,G,X){let J=Y,Z=W.ZERO,V=W.ZERO;while(G>UG||X>UG){if(G&RW)Z=Z.add(J);if(X&RW)V=V.add(J);J=J.double(),G>>=RW,X>>=RW}return{p1:Z,p2:V}}function Ru(W,Y,G,X){Du(G,W),Cu(X,Y);let J=G.length,Z=X.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=AT(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let H=hJ(Q),N=Array(Number(H)+1).fill(V),A=Math.floor((Y.BITS-1)/Q)*Q,q=V;for(let z=A;z>=0;z-=Q){N.fill(V);for(let D=0;D<Z;D++){let T=X[D],x=Number(T>>BigInt(z)&H);N[x]=N[x].add(G[D])}let w=V;for(let D=N.length-1,T=V;D>0;D--)T=T.add(N[D]),w=w.add(T);if(q=q.add(w),z!==0)for(let D=0;D<Q;D++)q=q.double()}return q}function lC(W,Y,G){if(Y){if(Y.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return Ou(Y),Y}else return bJ(W,{isLE:G})}function Mu(W,Y,G={},X){if(X===void 0)X=W==="edwards";if(!Y||typeof Y!=="object")throw Error(`expected valid ${W} CURVE object`);for(let U of["p","n","h"]){let Q=Y[U];if(!(typeof Q==="bigint"&&Q>UG))throw Error(`CURVE.${U} must be positive bigint`)}let J=lC(Y.p,G.Fp,X),Z=lC(Y.n,G.Fn,X),V=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let U of V)if(!J.isValid(Y[U]))throw Error(`CURVE.${U} must be valid field element of CURVE.Fp`);return Y=Object.freeze(Object.assign({},Y)),{CURVE:Y,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var dC=(W,Y)=>(W+(W>=0?Y:-Y)/FT)/Y;function Pu(W,Y,G){let[[X,J],[Z,V]]=Y,U=dC(V*W,G),Q=dC(-J*W,G),H=W-U*X-Q*Z,N=-U*J-Q*V,A=H<X4,q=N<X4;if(A)H=-H;if(q)N=-N;let z=hJ(Math.ceil(AT(G)/2))+ZG;if(H<X4||H>=z||N<X4||N>=z)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}function UI(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function tA(W,Y){let G={};for(let X of Object.keys(Y))G[X]=W[X]===void 0?Y[X]:W[X];if(zQ(G.lowS,"lowS"),zQ(G.prehash,"prehash"),G.format!==void 0)UI(G.format);return G}class $T extends Error{constructor(W=""){super(W)}}var G4={Err:$T,_tlv:{encode:(W,Y)=>{let{Err:G}=G4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length&1)throw new G("tlv.encode: unpadded data");let X=Y.length/2,J=WQ(X);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=X>127?WQ(J.length/2|128):"";return WQ(W)+Z+J+Y},decode(W,Y){let{Err:G}=G4,X=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length<2||Y[X++]!==W)throw new G("tlv.decode: wrong tlv");let J=Y[X++],Z=!!(J&128),V=0;if(!Z)V=J;else{let Q=J&127;if(!Q)throw new G("tlv.decode(long): indefinite length not supported");if(Q>4)throw new G("tlv.decode(long): byte length is too big");let H=Y.subarray(X,X+Q);if(H.length!==Q)throw new G("tlv.decode: length bytes not complete");if(H[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let N of H)V=V<<8|N;if(X+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=Y.subarray(X,X+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:Y.subarray(X+V)}}},_int:{encode(W){let{Err:Y}=G4;if(W<X4)throw new Y("integer: negative integers are not allowed");let G=WQ(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new Y("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:Y}=G4;if(W[0]&128)throw new Y("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new Y("invalid signature integer: unnecessary leading zero");return HG(W)}},toSig(W){let{Err:Y,_int:G,_tlv:X}=G4,J=b8("signature",W),{v:Z,l:V}=X.decode(48,J);if(V.length)throw new Y("invalid signature: left bytes after parsing");let{v:U,l:Q}=X.decode(2,Z),{v:H,l:N}=X.decode(2,Q);if(N.length)throw new Y("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(H)}},hexFromSig(W){let{_tlv:Y,_int:G}=G4,X=Y.encode(2,G.encode(W.r)),J=Y.encode(2,G.encode(W.s)),Z=X+J;return Y.encode(48,Z)}},X4=BigInt(0),ZG=BigInt(1),FT=BigInt(2),YQ=BigInt(3),Lu=BigInt(4);function MW(W,Y){let{BYTES:G}=W,X;if(typeof Y==="bigint")X=Y;else{let J=b8("private key",Y);try{X=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof Y}`)}}if(!W.isValidNot0(X))throw Error("invalid private key: out of range [1..N-1]");return X}function Bu(W,Y={}){let G=Mu("weierstrass",W,Y),{Fp:X,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;wI(Y,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=Y;if(Q){if(!X.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let H=xT(X,J);function N(){if(!X.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(k,l,B){let{x:$,y:h}=l.toAffine(),a=X.toBytes($);if(zQ(B,"isCompressed"),B){N();let n=!X.isOdd(h);return z7(ST(n),a)}else return z7(Uint8Array.of(4),a,X.toBytes(h))}function q(k){CW(k,void 0,"Point");let{publicKey:l,publicKeyUncompressed:B}=H,$=k.length,h=k[0],a=k.subarray(1);if($===l&&(h===2||h===3)){let n=X.fromBytes(a);if(!X.isValid(n))throw Error("bad point: is not on curve, wrong x");let E=D(n),P;try{P=X.sqrt(E)}catch(M){let F=M instanceof Error?": "+M.message:"";throw Error("bad point: is not on curve, sqrt error"+F)}N();let v=X.isOdd(P);if((h&1)===1!==v)P=X.neg(P);return{x:n,y:P}}else if($===B&&h===4){let n=X.BYTES,E=X.fromBytes(a.subarray(0,n)),P=X.fromBytes(a.subarray(n,n*2));if(!T(E,P))throw Error("bad point: is not on curve");return{x:E,y:P}}else throw Error(`bad point: got length ${$}, expected compressed=${l} or uncompressed=${B}`)}let z=Y.toBytes||A,w=Y.fromBytes||q;function D(k){let l=X.sqr(k),B=X.mul(l,k);return X.add(X.add(B,X.mul(k,Z.a)),Z.b)}function T(k,l){let B=X.sqr(l),$=D(k);return X.eql(B,$)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=X.mul(X.pow(Z.a,YQ),Lu),g=X.mul(X.sqr(Z.b),BigInt(27));if(X.is0(X.add(x,g)))throw Error("bad curve params: a or b");function f(k,l,B=!1){if(!X.isValid(l)||B&&X.is0(l))throw Error(`bad point coordinate ${k}`);return l}function y(k){if(!(k instanceof u))throw Error("ProjectivePoint expected")}function p(k){if(!Q||!Q.basises)throw Error("no endo");return Pu(k,Q.basises,J.ORDER)}let b=bC((k,l)=>{let{X:B,Y:$,Z:h}=k;if(X.eql(h,X.ONE))return{x:B,y:$};let a=k.is0();if(l==null)l=a?X.ONE:X.inv(h);let n=X.mul(B,l),E=X.mul($,l),P=X.mul(h,l);if(a)return{x:X.ZERO,y:X.ZERO};if(!X.eql(P,X.ONE))throw Error("invZ was invalid");return{x:n,y:E}}),m=bC((k)=>{if(k.is0()){if(Y.allowInfinityPoint&&!X.is0(k.Y))return;throw Error("bad point: ZERO")}let{x:l,y:B}=k.toAffine();if(!X.isValid(l)||!X.isValid(B))throw Error("bad point: x or y not field elements");if(!T(l,B))throw Error("bad point: equation left != right");if(!k.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function W0(k,l,B,$,h){return B=new u(X.mul(B.X,k),B.Y,B.Z),l=wQ($,l),B=wQ(h,B),l.add(B)}class u{constructor(k,l,B){this.X=f("x",k),this.Y=f("y",l,!0),this.Z=f("z",B),Object.freeze(this)}static CURVE(){return Z}static fromAffine(k){let{x:l,y:B}=k||{};if(!k||!X.isValid(l)||!X.isValid(B))throw Error("invalid affine point");if(k instanceof u)throw Error("projective point not allowed");if(X.is0(l)&&X.is0(B))return u.ZERO;return new u(l,B,X.ONE)}static fromBytes(k){let l=u.fromAffine(w(CW(k,void 0,"point")));return l.assertValidity(),l}static fromHex(k){return u.fromBytes(b8("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,l=!0){if(I0.createCache(this,k),!l)this.multiply(YQ);return this}assertValidity(){m(this)}hasEvenY(){let{y:k}=this.toAffine();if(!X.isOdd)throw Error("Field doesn't support isOdd");return!X.isOdd(k)}equals(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.eql(X.mul(l,n),X.mul(h,$)),P=X.eql(X.mul(B,n),X.mul(a,$));return E&&P}negate(){return new u(this.X,X.neg(this.Y),this.Z)}double(){let{a:k,b:l}=Z,B=X.mul(l,YQ),{X:$,Y:h,Z:a}=this,n=X.ZERO,E=X.ZERO,P=X.ZERO,v=X.mul($,$),M=X.mul(h,h),F=X.mul(a,a),c=X.mul($,h);return c=X.add(c,c),P=X.mul($,a),P=X.add(P,P),n=X.mul(k,P),E=X.mul(B,F),E=X.add(n,E),n=X.sub(M,E),E=X.add(M,E),E=X.mul(n,E),n=X.mul(c,n),P=X.mul(B,P),F=X.mul(k,F),c=X.sub(v,F),c=X.mul(k,c),c=X.add(c,P),P=X.add(v,v),v=X.add(P,v),v=X.add(v,F),v=X.mul(v,c),E=X.add(E,v),F=X.mul(h,a),F=X.add(F,F),v=X.mul(F,c),n=X.sub(n,v),P=X.mul(F,M),P=X.add(P,P),P=X.add(P,P),new u(n,E,P)}add(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.ZERO,P=X.ZERO,v=X.ZERO,M=Z.a,F=X.mul(Z.b,YQ),c=X.mul(l,h),t=X.mul(B,a),Y0=X.mul($,n),$0=X.add(l,B),S0=X.add(h,a);$0=X.mul($0,S0),S0=X.add(c,t),$0=X.sub($0,S0),S0=X.add(l,$);let x0=X.add(h,n);return S0=X.mul(S0,x0),x0=X.add(c,Y0),S0=X.sub(S0,x0),x0=X.add(B,$),E=X.add(a,n),x0=X.mul(x0,E),E=X.add(t,Y0),x0=X.sub(x0,E),v=X.mul(M,S0),E=X.mul(F,Y0),v=X.add(E,v),E=X.sub(t,v),v=X.add(t,v),P=X.mul(E,v),t=X.add(c,c),t=X.add(t,c),Y0=X.mul(M,Y0),S0=X.mul(F,S0),t=X.add(t,Y0),Y0=X.sub(c,Y0),Y0=X.mul(M,Y0),S0=X.add(S0,Y0),c=X.mul(t,S0),P=X.add(P,c),c=X.mul(x0,S0),E=X.mul($0,E),E=X.sub(E,c),c=X.mul($0,t),v=X.mul(x0,v),v=X.add(v,c),new u(E,P,v)}subtract(k){return this.add(k.negate())}is0(){return this.equals(u.ZERO)}multiply(k){let{endo:l}=Y;if(!J.isValidNot0(k))throw Error("invalid scalar: out of range");let B,$,h=(a)=>I0.cached(this,a,(n)=>iA(u,n));if(l){let{k1neg:a,k1:n,k2neg:E,k2:P}=p(k),{p:v,f:M}=h(n),{p:F,f:c}=h(P);$=M.add(c),B=W0(l.beta,v,F,a,E)}else{let{p:a,f:n}=h(k);B=a,$=n}return iA(u,[B,$])[0]}multiplyUnsafe(k){let{endo:l}=Y,B=this;if(!J.isValid(k))throw Error("invalid scalar: out of range");if(k===X4||B.is0())return u.ZERO;if(k===ZG)return B;if(I0.hasCache(this))return this.multiply(k);if(l){let{k1neg:$,k1:h,k2neg:a,k2:n}=p(k),{p1:E,p2:P}=Tu(u,B,h,n);return W0(l.beta,E,P,$,a)}else return I0.unsafe(B,k)}multiplyAndAddUnsafe(k,l,B){let $=this.multiplyUnsafe(l).add(k.multiplyUnsafe(B));return $.is0()?void 0:$}toAffine(k){return b(this,k)}isTorsionFree(){let{isTorsionFree:k}=Y;if(V===ZG)return!0;if(k)return k(u,this);return I0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:k}=Y;if(V===ZG)return this;if(k)return k(u,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(k=!0){return zQ(k,"isCompressed"),this.assertValidity(),z(u,this,k)}toHex(k=!0){return JG(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return iA(u,k)}static msm(k,l){return Ru(u,J,k,l)}static fromPrivateKey(k){return u.BASE.multiply(MW(J,k))}}u.BASE=new u(Z.Gx,Z.Gy,X.ONE),u.ZERO=new u(X.ZERO,X.ONE,X.ZERO),u.Fp=X,u.Fn=J;let J0=J.BITS,I0=new ET(u,Y.endo?Math.ceil(J0/2):J0);return u.BASE.precompute(8),u}function ST(W){return Uint8Array.of(W?2:3)}function xT(W,Y){return{secretKey:Y.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*Y.BYTES}}function Eu(W,Y={}){let{Fn:G}=W,X=Y.randomBytes||RQ,J=Object.assign(xT(W.Fp,G),{seed:MT(G.ORDER)});function Z(q){try{return!!MW(G,q)}catch(z){return!1}}function V(q,z){let{publicKey:w,publicKeyUncompressed:D}=J;try{let T=q.length;if(z===!0&&T!==w)return!1;if(z===!1&&T!==D)return!1;return!!W.fromBytes(q)}catch(T){return!1}}function U(q=X(J.seed)){return PT(CW(q,J.seed,"seed"),G.ORDER)}function Q(q,z=!0){return W.BASE.multiply(MW(G,q)).toBytes(z)}function H(q){let z=U(q);return{secretKey:z,publicKey:Q(z)}}function N(q){if(typeof q==="bigint")return!1;if(q instanceof W)return!0;let{secretKey:z,publicKey:w,publicKeyUncompressed:D}=J;if(G.allowedLengths||z===w)return;let T=b8("key",q).length;return T===w||T===D}function A(q,z,w=!0){if(N(q)===!0)throw Error("first arg must be private key");if(N(z)===!1)throw Error("second arg must be public key");let D=MW(G,q);return W.fromHex(z).multiply(D).toBytes(w)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:H,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(q)=>MW(G,q),precompute(q=8,z=W.BASE){return z.precompute(q,!1)}},lengths:J})}function $u(W,Y,G={}){XT(Y),wI(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let X=G.randomBytes||RQ,J=G.hmac||((B,...$)=>QT(Y,B,z7(...$))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z}=Eu(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},D="compact";function T(B){let $=U>>ZG;return B>$}function x(B,$){if(!V.isValidNot0($))throw Error(`invalid signature ${B}: out of range 1..Point.Fn.ORDER`);return $}function g(B,$){UI($);let h=z.signature,a=$==="compact"?h:$==="recovered"?h+1:void 0;return CW(B,a,`${$} signature`)}class f{constructor(B,$,h){if(this.r=x("r",B),this.s=x("s",$),h!=null)this.recovery=h;Object.freeze(this)}static fromBytes(B,$=D){g(B,$);let h;if($==="der"){let{r:P,s:v}=G4.toSig(CW(B));return new f(P,v)}if($==="recovered")h=B[0],$="compact",B=B.subarray(1);let a=V.BYTES,n=B.subarray(0,a),E=B.subarray(a,a*2);return new f(V.fromBytes(n),V.fromBytes(E),h)}static fromHex(B,$){return this.fromBytes(IQ(B),$)}addRecoveryBit(B){return new f(this.r,this.s,B)}recoverPublicKey(B){let $=Z.ORDER,{r:h,s:a,recovery:n}=this;if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");if(U*FT<$&&n>1)throw Error("recovery id is ambiguous for h>1 curve");let E=n===2||n===3?h+U:h;if(!Z.isValid(E))throw Error("recovery id 2 or 3 invalid");let P=Z.toBytes(E),v=W.fromBytes(z7(ST((n&1)===0),P)),M=V.inv(E),F=p(b8("msgHash",B)),c=V.create(-F*M),t=V.create(a*M),Y0=W.BASE.multiplyUnsafe(c).add(v.multiplyUnsafe(t));if(Y0.is0())throw Error("point at infinify");return Y0.assertValidity(),Y0}hasHighS(){return T(this.s)}toBytes(B=D){if(UI(B),B==="der")return IQ(G4.hexFromSig(this));let $=V.toBytes(this.r),h=V.toBytes(this.s);if(B==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return z7(Uint8Array.of(this.recovery),$,h)}return z7($,h)}toHex(B){return JG(this.toBytes(B))}assertValidity(){}static fromCompact(B){return f.fromBytes(b8("sig",B),"compact")}static fromDER(B){return f.fromBytes(b8("sig",B),"der")}normalizeS(){return this.hasHighS()?new f(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return JG(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return JG(this.toBytes("compact"))}}let y=G.bits2int||function(B){if(B.length>8192)throw Error("input is too large");let $=HG(B),h=B.length*8-Q;return h>0?$>>BigInt(h):$},p=G.bits2int_modN||function(B){return V.create(y(B))},b=hJ(Q);function m(B){return Hu("num < 2^"+Q,B,X4,b),V.toBytes(B)}function W0(B,$){return CW(B,void 0,"message"),$?CW(Y(B),void 0,"prehashed message"):B}function u(B,$,h){if(["recovered","canonical"].some((Y0)=>(Y0 in h)))throw Error("sign() legacy options not supported");let{lowS:a,prehash:n,extraEntropy:E}=tA(h,w);B=W0(B,n);let P=p(B),v=MW(V,$),M=[m(v),m(P)];if(E!=null&&E!==!1){let Y0=E===!0?X(z.secretKey):E;M.push(b8("extraEntropy",Y0))}let F=z7(...M),c=P;function t(Y0){let $0=y(Y0);if(!V.isValidNot0($0))return;let S0=V.inv($0),x0=W.BASE.multiply($0).toAffine(),D1=V.create(x0.x);if(D1===X4)return;let b0=V.create(S0*V.create(c+D1*v));if(b0===X4)return;let Q0=(x0.x===D1?0:2)|Number(x0.y&ZG),O0=b0;if(a&&T(b0))O0=V.neg(b0),Q0^=1;return new f(D1,O0,Q0)}return{seed:F,k2sig:t}}function J0(B,$,h={}){B=b8("message",B);let{seed:a,k2sig:n}=u(B,$,h);return Nu(Y.outputLen,V.BYTES,J)(a,n)}function I0(B){let $=void 0,h=typeof B==="string"||TQ(B),a=!h&&B!==null&&typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint";if(!h&&!a)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(a)$=new f(B.r,B.s);else if(h){try{$=f.fromBytes(b8("sig",B),"der")}catch(n){if(!(n instanceof G4.Err))throw n}if(!$)try{$=f.fromBytes(b8("sig",B),"compact")}catch(n){return!1}}if(!$)return!1;return $}function k(B,$,h,a={}){let{lowS:n,prehash:E,format:P}=tA(a,w);if(h=b8("publicKey",h),$=W0(b8("message",$),E),"strict"in a)throw Error("options.strict was renamed to lowS");let v=P===void 0?I0(B):f.fromBytes(b8("sig",B),P);if(v===!1)return!1;try{let M=W.fromBytes(h);if(n&&v.hasHighS())return!1;let{r:F,s:c}=v,t=p($),Y0=V.inv(c),$0=V.create(t*Y0),S0=V.create(F*Y0),x0=W.BASE.multiplyUnsafe($0).add(M.multiplyUnsafe(S0));if(x0.is0())return!1;return V.create(x0.x)===F}catch(M){return!1}}function l(B,$,h={}){let{prehash:a}=tA(h,w);return $=W0($,a),f.fromBytes(B,"recovered").recoverPublicKey($).toBytes()}return Object.freeze({keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z,Point:W,sign:J0,verify:k,recoverPublicKey:l,Signature:f,hash:Y})}function Fu(W){let Y={a:W.a,b:W.b,p:W.Fp.ORDER,n:W.n,h:W.h,Gx:W.Gx,Gy:W.Gy},G=W.Fp,X=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=bJ(Y.n,{BITS:W.nBitLength,allowedLengths:X,modFromBytes:W.wrapPrivateKey}),Z={Fp:G,Fn:J,allowInfinityPoint:W.allowInfinityPoint,endo:W.endo,isTorsionFree:W.isTorsionFree,clearCofactor:W.clearCofactor,fromBytes:W.fromBytes,toBytes:W.toBytes};return{CURVE:Y,curveOpts:Z}}function Su(W){let{CURVE:Y,curveOpts:G}=Fu(W),X={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:Y,curveOpts:G,hash:W.hash,ecdsaOpts:X}}function xu(W,Y){let G=Y.Point;return Object.assign({},Y,{ProjectivePoint:G,CURVE:Object.assign({},W,TT(G.Fn.ORDER,G.Fn.BITS))})}function ku(W){let{CURVE:Y,curveOpts:G,hash:X,ecdsaOpts:J}=Su(W),Z=Bu(Y,G),V=$u(Z,X,J);return xu(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _u(W,Y){let G=(X)=>ku({...W,hash:X});return{...G(Y),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var QG={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},vu=BigInt(0),oC=BigInt(1),QI=BigInt(2);function gu(W){let Y=QG.p,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=O5(N,G,Y)*N%Y,q=O5(A,G,Y)*N%Y,z=O5(q,QI,Y)*H%Y,w=O5(z,J,Y)*z%Y,D=O5(w,Z,Y)*w%Y,T=O5(D,U,Y)*D%Y,x=O5(T,Q,Y)*T%Y,g=O5(x,U,Y)*D%Y,f=O5(g,G,Y)*N%Y,y=O5(f,V,Y)*w%Y,p=O5(y,X,Y)*H%Y,b=O5(p,QI,Y);if(!jQ.eql(jQ.sqr(b),W))throw Error("Cannot find square root");return b}var jQ=bJ(QG.p,{sqrt:gu}),kT=_u({...QG,Fp:jQ,lowS:!0,endo:yu},JI),nC={};function OQ(W,...Y){let G=nC[W];if(G===void 0){let X=JI(ZT(W));G=z7(X,X),nC[W]=G}return JI(z7(G,...Y))}var OI=(W)=>W.toBytes(!0).slice(1),NG=(()=>kT.Point)(),KI=(W)=>W%QI===vu;function HI(W){let{Fn:Y,BASE:G}=NG,X=MW(Y,W),J=G.multiply(X);return{scalar:KI(J.y)?X:Y.neg(X),bytes:OI(J)}}function _T(W){let Y=jQ;if(!Y.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=Y.create(W*W),X=Y.create(G*W+BigInt(7)),J=Y.sqrt(X);if(!KI(J))J=Y.neg(J);let Z=NG.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var gJ=HG;function yT(...W){return NG.Fn.create(gJ(OQ("BIP0340/challenge",...W)))}function iC(W){return HI(W).bytes}function uu(W,Y,G=RQ(32)){let{Fn:X}=NG,J=b8("message",W),{bytes:Z,scalar:V}=HI(Y),U=b8("auxRand",G,32),Q=X.toBytes(V^gJ(OQ("BIP0340/aux",U))),H=OQ("BIP0340/nonce",Q,Z,J),{bytes:N,scalar:A}=HI(H),q=yT(N,Z,J),z=new Uint8Array(64);if(z.set(N,0),z.set(X.toBytes(X.create(A+q*V)),32),!vT(z,J,Z))throw Error("sign: Invalid signature produced");return z}function vT(W,Y,G){let{Fn:X,BASE:J}=NG,Z=b8("signature",W,64),V=b8("message",Y),U=b8("publicKey",G,32);try{let Q=_T(gJ(U)),H=gJ(Z.subarray(0,32));if(!VI(H,oC,QG.p))return!1;let N=gJ(Z.subarray(32,64));if(!VI(N,oC,QG.n))return!1;let A=yT(X.toBytes(H),OI(Q),V),q=J.multiplyUnsafe(N).add(Q.multiplyUnsafe(X.neg(A))),{x:z,y:w}=q.toAffine();if(q.is0()||!KI(w)||z!==H)return!1;return!0}catch(Q){return!1}}var DI=(()=>{let W=(G=RQ(48))=>{return PT(G,QG.n)};kT.utils.randomSecretKey;function Y(G){let X=W(G);return{secretKey:X,publicKey:iC(X)}}return{keygen:Y,getPublicKey:iC,sign:uu,verify:vT,Point:NG,utils:{randomSecretKey:W,randomPrivateKey:W,taggedHash:OQ,lift_x:_T,pointToBytes:OI,numberToBytesBE:MQ,bytesToNumberBE:HG,mod:D5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),hu=new TextEncoder,bu=new TextDecoder,PW=(W)=>hu.encode(W),xJ=(W)=>bu.decode(W),NI=(W)=>Array.from(W,(Y)=>Y.toString(16).padStart(2,"0")).join(""),w7=JSON.stringify,KQ=JSON.parse,gT=(W,Y=Number.MAX_SAFE_INTEGER)=>W.split("").reduce((G,X)=>G+X.charCodeAt(0),0)%Y,CI="AES-GCM",mu={},uT="$",hT=",",fu=(W)=>{let Y=new Uint8Array(W),G=32768,X="";for(let J=0;J<Y.length;J+=32768)X+=String.fromCharCode(...Y.subarray(J,J+32768));return btoa(X)},cu=(W)=>Uint8Array.from(atob(W),(Y)=>Y.charCodeAt(0)).buffer,GQ=(W)=>mu[W]??=crypto.subtle.digest("SHA-1",PW(W)).then((Y)=>{let G=new Uint8Array(Y),X="";for(let J of G)X+=J.toString(36);return X}),pu=async(W,Y,G)=>{let X=await crypto.subtle.digest("SHA-256",PW(`${W}:${Y}:${G}`));return crypto.subtle.importKey("raw",X,{name:CI},!1,["encrypt","decrypt"])},lu=async(W,Y)=>{let G=crypto.getRandomValues(new Uint8Array(12)),X=await W,J=await crypto.subtle.encrypt({name:CI,iv:G},X,PW(Y));return`${G.join(hT)}${uT}${fu(J)}`},du=async(W,Y)=>{let[G,X]=Y.split(uT);if(!G||!X)throw Error("Invalid encrypted payload format");let J=Uint8Array.from(G.split(hT),Number),Z=await W,V=await crypto.subtle.decrypt({name:CI,iv:J},Z,cu(X));return xJ(V)},K5="GenosRTC",TI=(W,Y)=>Array.from({length:W},Y),DQ=(W)=>Array.from(crypto.getRandomValues(new Uint8Array(W)),(Y)=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Y%62]).join(""),A8=typeof sessionStorage<"u"?sessionStorage.__genosrtcId??=DQ(20):DQ(20),XG=Promise.all.bind(Promise),ou=typeof window<"u",{entries:nu,fromEntries:bT,keys:xe}=Object,iu=()=>{},Y4=(W)=>Error(`GenosRTC: ${W}`),XQ=(...W)=>W.join("@"),ru=(W,Y)=>{let G=[...W],X=G.length,J=()=>{let Z=Math.sin(Y++)*1e4;return Z-Math.floor(Z)};while(X){let Z=Math.floor(J()*X--);[G[X],G[Z]]=[G[Z],G[X]]}return G},au=5000,rC="icegatheringstatechange",aC="offer",su="answer",tu=[...TI(3,(W,Y)=>`stun:stun${Y||""}.l.google.com:19302`),"stun:stun.cloudflare.com:3478"].map((W)=>({urls:W})),sC=(W,{rtcConfig:Y,rtcPolyfill:G,turnConfig:X})=>{let J=new(G||RTCPeerConnection)({iceServers:[...tu,...X||[]],...Y}),Z={},V=!1,U=!1,Q,H=(q)=>Object.assign(q,{binaryType:"arraybuffer",bufferedAmountLowThreshold:65535,onmessage:(z)=>Z.data?.(z.data),onopen:()=>Z.connect?.(),onclose:()=>Z.close?.(),onerror:(z)=>!z?.error?.message?.includes("User-Initiated Abort")&&Z.error?.(z)}),N=()=>Promise.race([new Promise((q)=>{let z=()=>{if(J.iceGatheringState==="complete")J.removeEventListener(rC,z),q()};J.addEventListener(rC,z),z()}),new Promise((q)=>setTimeout(q,au))]).then(()=>({type:J.localDescription.type,sdp:J.localDescription.sdp.replace(/a=ice-options:trickle\s\n/g,"")}));if(W?H(Q=J.createDataChannel("data")):J.ondatachannel=({channel:q})=>H(Q=q),J.onnegotiationneeded=async()=>{try{V=!0,await J.setLocalDescription(),Z.signal?.(await N())}catch(q){Z.error?.(q)}finally{V=!1}},J.onconnectionstatechange=()=>{if(["disconnected","failed","closed"].includes(J.connectionState))Z.close?.()},J.ontrack=(q)=>{Z.track?.(q.track,q.streams[0]),Z.stream?.(q.streams[0])},J.onremovestream=(q)=>Z.stream?.(q.stream),W&&!J.canTrickleIceCandidates)J.onnegotiationneeded();let A=()=>J.getSenders();return{created:Date.now(),connection:J,get channel(){return Q},get isDead(){return J.connectionState==="closed"},async signal(q){if(Q?.readyState==="open"&&!q.sdp?.includes("a=rtpmap"))return;try{if(q.type===aC){if(V||J.signalingState!=="stable"&&!U){if(W)return;await XG([J.setLocalDescription({type:"rollback"}),J.setRemoteDescription(q)])}else await J.setRemoteDescription(q);await J.setLocalDescription();let z=await N();return Z.signal?.(z),z}if(q.type===su){U=!0;try{await J.setRemoteDescription(q)}finally{U=!1}}}catch(z){Z.error?.(z)}},sendData:(q)=>{if(Q?.readyState==="open")Q.send(q)},destroy:()=>{Q?.close(),J.close(),V=U=!1},setHandlers:(q)=>Object.assign(Z,q),offerPromise:W?new Promise((q)=>Z.signal=(z)=>z.type===aC&&q(z)):Promise.resolve(),addStream:(q)=>q.getTracks().forEach((z)=>J.addTrack(z,q)),removeStream:(q)=>A().filter((z)=>q.getTracks().includes(z.track)).forEach((z)=>J.removeTrack(z)),addTrack:(q,z)=>J.addTrack(q,z),removeTrack:(q)=>{let z=A().find((w)=>w.track===q);if(z)J.removeTrack(z)},replaceTrack:(q,z)=>A().find((w)=>w.track===q)?.replaceTrack(z)}},eu=Object.getPrototypeOf(Uint8Array),UQ=12,mT=0,QQ=mT+UQ,HQ=QQ+1,kJ=HQ+1,_J=kJ+1,FJ=16384-_J,JQ=255,eA="bufferedamountlow",GG=(W)=>`@_${W}`,tC=GG("ping"),WI=100,Wh=3,Yh=200,Gh=512,eC=(W,Y)=>new Response(new Blob([W]).stream().pipeThrough(new Y("deflate"))).arrayBuffer().then((G)=>new Uint8Array(G)),Xh=(W,Y,G,X)=>{let J=new Map,Z=new Map,V=new Map,U={},Q={},H={},N={},A=new Map,q=new Map,z=Promise.resolve(),w=(M,F)=>{if(!A.has(M))A.set(M,new Set);A.get(M).add(F)},D=(M,F)=>A.get(M)?.delete(F),T=(M,...F)=>A.get(M)?.forEach((c)=>c(...F)),x=(M,F)=>{let c=M?Array.isArray(M)?M:[M]:J.keys();return Array.from(c,(t)=>{let Y0=J.get(t);if(!Y0)return console.warn(`${K5}: no peer with id ${t}`),null;return F(t,Y0)}).filter(Boolean)},g=(M)=>{if(!J.has(M))return;J.delete(M),q.delete(M),P.delete(M),delete U[M],delete Q[M],delete H[M],delete N[M],T("peer:leave",M),Y(M)},f=(M)=>new Promise((F,c)=>{let t=setTimeout(()=>{M.removeEventListener(eA,Y0),c(Error(`${K5}: bufferLow timeout`))},5000);function Y0(){clearTimeout(t),M.removeEventListener(eA,Y0),F()}M.addEventListener(eA,Y0)}),y=(M)=>{if(V.has(M))return V.get(M);if(!M)throw Y4("action type is required");let F=PW(M);if(F.byteLength>UQ)throw Y4(`\u274C "${M}" exceeds ${UQ} bytes. Use a shorter name.`);let c=new Uint8Array(UQ).map((b0,Q0)=>F[Q0]||0),t=0,Y0=new Map([["message",new Set],["progress",new Set]]),$0=(b0,Q0)=>Y0.get(b0)?.add(Q0),S0=(b0,Q0)=>Y0.get(b0)?.delete(Q0),x0=async(b0,Q0,O0,y0)=>{if(O0&&typeof O0!=="object")throw Y4("meta must be object");if(b0===void 0)throw Y4("data cannot be undefined");let X0=b0 instanceof Blob,D0=X0||b0 instanceof ArrayBuffer||b0 instanceof eu,L0=typeof b0!=="string";if(O0&&!D0)throw Y4("meta only allowed with binary");let H0=D0?new Uint8Array(X0?await b0.arrayBuffer():b0):PW(L0?w7(b0):b0),F0=0;if(!D0&&H0.byteLength>=Gh){let i1=await eC(H0,CompressionStream);if(i1.byteLength<H0.byteLength)H0=i1,F0=1}let V1=O0?PW(w7(O0)):null,H1=Math.ceil(H0.byteLength/FJ)+(O0?1:0)||1;if(H1>WI)throw Y4(`Message too large, exceeds max chunks ${WI}`);let y1=TI(H1,(i1,r0)=>{let x1=r0===H1-1,i0=O0&&r0===0,V8=i0?V1:H0.subarray(O0?(r0-1)*FJ:r0*FJ,O0?r0*FJ:(r0+1)*FJ),F8=new Uint8Array(_J+V8.byteLength);return F8.set(c),F8.set([t],QQ),F8.set([x1|i0<<1|D0<<2|L0<<3|F0<<4],HQ),F8.set([Math.round((r0+1)/H1*JQ)],kJ),F8.set(V8,_J),F8});return t=t+1&JQ,XG(x(Q0,async(i1,r0)=>{let{channel:x1}=r0;for(let i0=0;i0<H1;i0++){let V8=0;while(x1.bufferedAmount>x1.bufferedAmountLowThreshold){if(V8++>Wh)throw Y4(`${K5}: send buffer full, max retries reached for peer ${i1}`);try{await f(x1)}catch(F8){console.warn(F8.message),await new Promise(($9)=>setTimeout($9,Yh))}}if(!J.has(i1))break;r0.sendData(y1[i0]),y0?.(y1[i0][kJ]/JQ,i1,O0)}}))};Z.set(M,{listeners:Y0,send:x0});let D1={send:x0,on:$0,off:S0};return V.set(M,D1),D1},p=(M,F)=>{try{q.set(M,Date.now()),P.delete(M);let c=new Uint8Array(F),t=xJ(c.subarray(mT,QQ)).replace(/\x00/g,"");if(!Z.has(t))return console.warn(`${K5}: unregistered type (${t})`);if(t===tC){W0("",M).catch(()=>{});return}let[Y0]=c.subarray(QQ,HQ),[$0]=c.subarray(HQ,kJ),[S0]=c.subarray(kJ,_J),x0=c.subarray(_J),D1=Boolean($0&1),b0=Boolean($0&2),Q0=Boolean($0&4),O0=Boolean($0&8),y0=Boolean($0&16),X0=Z.get(t),D0=(U[M]||={})[t]||={};if(D0[Y0]?.chunks?.length>WI){console.warn(`${K5}: peer ${M} sent too many chunks for nonce ${Y0}, ignoring.`);return}let L0=D0[Y0]||={chunks:[]};if(b0)try{L0.meta=KQ(xJ(x0))}catch{console.warn(`${K5}: failed to parse meta from peer ${M} for type ${t}`);return}else L0.chunks.push(x0);if(X0.listeners.get("progress").forEach((F0)=>{try{F0(S0/JQ,M,L0.meta)}catch(V1){console.error(V1)}}),!D1)return;let H0=new Uint8Array(L0.chunks.reduce((F0,V1)=>F0+V1.byteLength,0));L0.chunks.reduce((F0,V1)=>(H0.set(V1,F0),F0+V1.byteLength),0),delete D0[Y0],z=z.then(async()=>{let F0=y0?await eC(H0,DecompressionStream):H0,V1;if(Q0)V1=F0;else if(O0)try{V1=KQ(xJ(F0))}catch{console.warn(`${K5}: failed to parse JSON message data from peer ${M} for type ${t}`);return}else V1=xJ(F0);X0.listeners.get("message").forEach((H1)=>{try{H1(V1,M,L0.meta)}catch(y1){console.error(y1)}})}).catch((F0)=>console.error(`${K5}: dispatch error from peer ${M}:`,F0))}catch(c){console.error(`${K5}: error handling data from peer ${M}:`,c)}},b=async()=>{try{await h(""),await new Promise((M)=>setTimeout(M,99))}catch(M){console.warn(`${K5}: error sending leave`,M)}for(let[M,F]of J){try{F.destroy()}catch{}J.delete(M)}clearInterval(v),G()},{send:m}=y(tC),{send:W0,on:u}=y(GG("pong")),{send:J0,on:I0}=y(GG("signal")),{send:k,on:l}=y(GG("stream")),{send:B,on:$}=y(GG("track")),{send:h,on:a}=y(GG("leave"));W((M,F)=>{let c=J.get(F);if(c===M)return;if(c){let t=()=>{};c.setHandlers({data:t,stream:t,track:t,signal:t,close:t,error:t})}J.set(F,M),q.set(F,Date.now()),P.delete(F),M.setHandlers({data:(t)=>p(F,t),stream:(t)=>{T("stream:add",t,F,H[F]),delete H[F]},track:(t,Y0)=>{T("track:add",t,Y0,F,N[F]),delete N[F]},signal:(t)=>J0(t,F),close:()=>g(F),error:(t)=>{console.error(`${K5}: peer error for ${F}`,t),g(F)}}),T("peer:join",F,X?.(F))}),u("message",(M,F)=>{Q[F]?.(),delete Q[F]}),I0("message",(M,F)=>J.get(F)?.signal(M)),l("message",(M,F)=>H[F]=M),$("message",(M,F)=>N[F]=M),a("message",(M,F)=>g(F));let n=1e4,E=20000,P=new Map,v=setInterval(()=>{let M=Date.now();for(let[F,c]of J){if(M-(q.get(F)??M)<=n)continue;let t=P.get(F);if(t===void 0)P.set(F,M),m("",F).catch(()=>{});else if(M-t>E){P.delete(F);try{c.destroy()}catch{}g(F)}}},5000);if(ou)addEventListener("beforeunload",b);return{on:w,off:D,channel:y,leave:b,ping:async(M)=>{if(!M)throw Y4("ping() requires target peer ID");let F=Date.now();return m("",M),await new Promise((c)=>Q[M]=c),Date.now()-F},getPeers:()=>bT(Array.from(J,([M,F])=>[M,F.connection])),addStream:(M,F,c)=>x(F,async(t,Y0)=>{if(c)await k(c,t);Y0.addStream(M)}),removeStream:(M,F)=>x(F,(c,t)=>t.removeStream(M)),addTrack:(M,F,c,t)=>x(c,async(Y0,$0)=>{if(t)await B(t,Y0);$0.addTrack(M,F)}),removeTrack:(M,F)=>x(F,(c,t)=>t.removeTrack(M)),replaceTrack:(M,F,c,t)=>x(c,async(Y0,$0)=>{if(t)await B(t,Y0);$0.replaceTrack(M,F)})}},Jh=5,Zh=10,Vh=2500,ZQ=57333,Uh=({init:W,subscribe:Y,announce:G,bye:X})=>{let J={},Z=!1,V,U;return(Q,H,N)=>{let{appId:A}=Q;if(J[A]?.[H])return J[A][H];if(!Q||!H||!A&&!Q.firebaseApp)throw Y4(!Q?"config required":!H?"roomId required":"appId missing");let q=iu;if(!Z){let P=W(Q);U=TI(Jh,()=>{try{return sC(!0,Q)}catch{return null}}).filter(Boolean),V=Array.isArray(P)?P:[P];let v=setInterval(()=>{U=U.filter((M)=>{let F=Date.now()-M.created<ZQ;if(!F)M.destroy();return F})},ZQ);J.offerCleanupTimer||=v,Z=!0}let z={},w={},D=new Map,T=new Map,x=new Map,g={},f=XQ(K5,A,H),y=GQ(f),p=GQ(XQ(f,A8)),b=pu(Q.password||"",A,H),m=(P)=>async(v)=>({type:v.type,sdp:await P(b,v.sdp)}),W0=m(du),u=m(lu),J0=(P)=>{return setTimeout(()=>{if(!P.isDead&&!Object.values(w).includes(P))P.destroy()},ZQ),P},I0=(P)=>{try{return J0(sC(P,Q))}catch{return null}},k=(P,v)=>{if(w[v]===P)return;P.connectedAt=Date.now(),w[v]?.destroy(),w[v]=P,q(P,v),z[v]?.forEach((M)=>M!==P&&M.destroy()),delete z[v]},l=(P,v)=>{if(w[v]===P)delete w[v]},B=(P)=>async(v,M,F)=>{let[c,t]=await XG([y,p]);if(v!==c&&v!==t)return;let{peerId:Y0,offer:$0,answer:S0,type:x0,bye:D1}=typeof M==="string"?KQ(M):M;if(D1){if(Y0&&Y0!==A8)T.delete(Y0),x.set(Y0,Date.now()),delete g[Y0];return}if(Y0&&Y0!==A8)T.set(Y0,Date.now()),x.delete(Y0);if(x0&&Y0)g[Y0]=x0;if(Y0===A8)return;if(w[Y0]){let b0=w[Y0].channel?.readyState==="open";if(!$0||b0||Date.now()-w[Y0].connectedAt<2000)return;w[Y0].destroy(),delete w[Y0]}if(Q.admit&&!Q.admit(Y0))return;if($0){if(z[Y0]?.[P]&&A8>Y0)return;let b0=I0(!1);if(!b0)return;b0.setHandlers({connect:()=>k(b0,Y0),close:()=>l(b0,Y0)});try{let Q0=await W0($0);if(b0.isDead)return;let[O0,y0]=await XG([GQ(XQ(f,Y0)),b0.signal(Q0).then(u)]);F(O0,w7({peerId:A8,answer:y0,...Q.type&&{type:Q.type}}))}catch{N?.({error:"decryption failed (offer)",appId:A,peerId:Y0,roomId:H})}}else if(S0){let b0=z[Y0]?.[P];if(!b0||b0.isDead)return;b0.setHandlers({connect:()=>k(b0,Y0),close:()=>l(b0,Y0)});try{b0.signal(await W0(S0))}catch{N?.({error:"decryption failed (answer)",appId:A,peerId:Y0,roomId:H})}}else{let b0=z[Y0]||=[];if(b0.forEach((y0,X0)=>{if(y0&&(y0.isDead||Date.now()-(y0.dialedAt??y0.created)>ZQ)){if(y0.isDead)D.set(Y0,Date.now()+30000);y0.destroy(),delete b0[X0]}}),b0[P]||b0.filter(Boolean).length>=2||D.get(Y0)>Date.now())return;if(Object.values(z).reduce((y0,X0)=>y0+X0.filter((D0)=>D0&&!D0.isDead).length,0)>=Zh)return;let Q0=U.pop(),O0=Q0?J0(Q0):I0(!0);if(!O0){D.set(Y0,Date.now()+30000);return}O0.dialedAt=Date.now(),b0[P]=O0;try{let[y0,{offer:X0}]=await XG([GQ(XQ(f,Y0)),O0.offerPromise.then(u).then((D0)=>({offer:D0}))]);O0.setHandlers({connect:()=>k(O0,Y0),close:()=>l(O0,Y0)}),F(y0,w7({peerId:A8,offer:X0,peer:O0,...Q.type&&{type:Q.type}}))}catch{if(b0[P]===O0)delete b0[P];O0.destroy()}}},$=[],h=[],a=[],n=()=>a.forEach(({relay:P,rootTopic:v})=>X?.(P,v));V.forEach(async(P,v)=>{let M=await P;if(!M)return;let[F,c]=await XG([y,p]);h[v]=Y(M,F,c,B(v)),a.push({relay:M,rootTopic:F});let t=async()=>{let Y0=await G(M,F,c);$[v]=setTimeout(t,typeof Y0==="number"?Y0:Vh)};t()}),J[A]||={};let E=Xh((P)=>q=P,(P)=>delete w[P],()=>E.onCleanup?.(),(P)=>g[P]);if(typeof window<"u")window.addEventListener("pagehide",n);return E.onCleanup=()=>{if(n(),typeof window<"u")window.removeEventListener("pagehide",n);if(delete J[A][H],$.forEach(clearTimeout),h.forEach((P)=>P?.()),Object.keys(J).length===0)clearInterval(J.offerCleanupTimer),delete J.offerCleanupTimer},E._census=()=>{for(let v of Object.keys(w))T.set(v,Date.now());let P=Date.now()-120000;for(let[v,M]of T)if(M<P)T.delete(v);return[...T.keys()]},E._gone=()=>{let P=Date.now()-60000;for(let[v,M]of x)if(M<P)x.delete(v);return[...x.keys()]},J[A][H]=E}},WT=3333,Qh=30000,SJ={},fT={},Hh=(W,Y)=>{let G={},X=null;G.reopenHandlers=new Set;let J=()=>{if(X)clearTimeout(X),X=null;if(G.socket)G.socket.onclose=null,G.socket.close();let Z=new WebSocket(W);Z.onclose=()=>{SJ[W]??=WT,X=setTimeout(J,SJ[W]),SJ[W]=Math.min(SJ[W]*2,Qh)},Z.onmessage=(V)=>Y(V.data),G.socket=Z,G.url=Z.url,G.ready=new Promise((V)=>{Z.onopen=()=>{SJ[W]=WT,V(G),G.reopenHandlers.forEach((U)=>U())}}),G.send=(V)=>{if(Z.readyState===1)Z.send(V)}};return G.forceReconnect=J,J(),fT[W]=G,G};if(typeof window<"u"){let W=(Y)=>{vJ.info("\u26A1 [GenosRTC] Network event detected. Forcing reconnection\u2026"),Object.values(fT).forEach((G)=>{if(G.socket&&G.socket.readyState!==WebSocket.OPEN&&(Y||G.socket.readyState!==WebSocket.CONNECTING))G.forceReconnect()})};window.addEventListener("online",()=>{vJ.info("\u2705 Reconnected to the network."),W(!0)}),window.addEventListener("offline",async()=>{vJ.info("\u274C Disconnected from the network.")}),document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible")W()})}var Nh=(W)=>()=>bT(nu(W).map(([Y,G])=>[Y,G.socket])),qh=(W,Y,G,X)=>(W.relayUrls??(X?ru(Y,gT(W.appId)):Y)).slice(0,W.relayUrls?.length??W.relayRedundancy??G),Ah=["wss://relay.primal.net","wss://relay.snort.social","wss://nostr.oxtr.dev","wss://nostr.vulpem.com","wss://relay.nostr.net","wss://nostr.sathoarder.com","wss://nostr.data.haus","wss://relay.mostr.pub"],VG={},Ih=10,cT="x",pT="EVENT",zh=/pow:\s*(\d+)\s*bits needed\.?/i,NQ=new Set,lT=DI.utils.randomSecretKey(),wh=NI(DI.getPublicKey(lT)),RI={},yJ={},jh={},dT=()=>Math.floor(Date.now()/1000),oT=(W)=>jh[W]??=gT(W,1e4)+20000,uJ=(W)=>W.replace(/\/$/,""),Oh=(W,Y)=>{let[G,X,J,Z]=KQ(Y);if(G===pT)return yJ[X]?.(RI[X],J.content);if(G==="NOTICE"||G==="OK"&&!J){if(+((G==="NOTICE"?X:Z).match(zh)?.[1]??0)>0){let V=uJ(W);NQ.add(V),VG[V]?.close?.(),delete VG[V]}}},Kh=(W)=>{let Y=uJ(W);if(VG[Y])return VG[Y];let G=Hh(Y,(X)=>Oh(Y,X));return VG[Y]=G},YI=async(W,Y)=>{let G={kind:oT(W),content:Y,pubkey:wh,created_at:dT(),tags:[[cT,W]]},X=PW(w7([0,G.pubkey,G.created_at,G.kind,G.tags,G.content])),J=new Uint8Array(await crypto.subtle.digest("SHA-256",X)),Z=DI.sign(J,lT);return w7([pT,{...G,id:NI(J),sig:NI(Z)}])},YT=(W,Y)=>{return RI[W]=Y,w7(["REQ",W,{kinds:[oT(Y)],since:dT(),["#"+cT]:[Y]}])},GT=(W)=>{return delete RI[W],w7(["CLOSE",W])},nT=Uh({init:(W)=>{let Y=(W?.relayUrls?.length?W.relayUrls:null)??Ah;return qh(W,Y,Ih,!1).map(Kh).map((G)=>G.ready.then(()=>G).catch(()=>null))},subscribe:(W,Y,G,X)=>{let J=DQ(64),Z=DQ(64);yJ[J]=yJ[Z]=(U,Q)=>X(U,Q,async(H,N)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(H,N))});let V=()=>{W.send(YT(J,Y)),W.send(YT(Z,G))};return V(),W.reopenHandlers.add(V),()=>{W.reopenHandlers.delete(V),W.send(GT(J)),W.send(GT(Z)),delete yJ[J],delete yJ[Z]}},announce:async(W,Y)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(Y,w7({peerId:A8})))},bye:async(W,Y)=>{if(NQ.has(uJ(W.url)))return;W.send(await YI(Y,w7({peerId:A8,bye:1})))}}),ke=Nh(VG),Dh={cellSize:10},Ch=5000,Th=3000,Rh=2000,Mh=2000,Ph=1e4,Lh=30000,Bh=5000,Eh=30000,CQ=(W)=>{let Y=String(W||"").match(/cell-(\d+)/);return Y?Number(Y[1]):null},GI=(W,Y)=>{let G=CQ(W);if(G==null)return[];let X=[];for(let J=1;J<Y;J*=2){if(G-J>=0)X.push(`cell-${G-J}`);if(G+J<Y)X.push(`cell-${G+J}`)}return X},VQ=(W)=>`c${(CQ(W)||0).toString(36)}`,$h=10,Fh=(W,Y)=>{let G=+Y.cellSize>=2?Y.cellSize|0:$h;return Math.max(1,Math.ceil(W/G))},iT=(W)=>{let Y=0;for(let G=0;G<W.length;G++)Y=Math.imul(Y^W.charCodeAt(G),2654435761);return Y>>>0},q6=(W,Y)=>{let G=0,X=-1;for(let J=0;J<Y;J++){let Z=iT(`${W}:${J}`);if(Z>X)X=Z,G=J}return G};function Sh(W,Y={},G={}){let X={...Dh,...Y},J=1,Z={epoch:0,roster:[A8],set:new Set([A8]),key:A8,C:1,cellId:null,isBridge:!1,bridges:[],edgeBridges:[]},V={cellId:null},U=0,Q=0,H="",N=0,A=0,q=0,z=null,w=null,D=null,T=new Map,x=new Set,g=new Map,f=new Set,y=0,p=new Set,b=new Map,m=()=>Math.min(150,Math.ceil(Math.log2(Z.C+1))*2+3),W0=(X0)=>GI(X0,Z.C),u=W.on?.bind(W),J0=W.off?.bind(W);if(u)W.on=(X0,D0)=>String(X0).startsWith("mesh:")?l(X0,D0):u(X0,D0);if(J0)W.off=(X0,D0)=>String(X0).startsWith("mesh:")?g.get(X0)?.delete(D0):J0(X0,D0);let I0=(X0)=>(x.add(X0),()=>x.delete(X0)),k=(X0,D0)=>{for(let L0 of x)try{L0(X0,D0)}catch(H0){vJ.error("\uD83D\uDD78\uFE0F [Cells] Error in deliver handler:",H0)}},l=(X0,D0)=>{if(!g.has(X0))g.set(X0,new Set);return g.get(X0).add(D0),()=>g.get(X0)?.delete(D0)},B=(X0,...D0)=>{let L0=g.get(X0);if(L0)for(let H0 of L0)try{H0(...D0)}catch{}},$=(X0)=>{try{return typeof X0==="string"?JSON.parse(X0):X0}catch{return null}},h=()=>`${A8}:${Date.now().toString(36)}:${(y++&65535).toString(36)}`,a=()=>{if(f.size>Ch)f.delete(f.values().next().value)},n=()=>[...new Set([...W._census(),A8])].sort(),E=(X0,D0,L0)=>D0.filter((H0)=>q6(H0,L0)===X0),P=(X0,D0,L0)=>{if(X0==null)return null;let H0=(H1)=>iT(`${H1}@${X0}`),F0=null,V1=-1;for(let H1 of E(X0,D0,L0)){let y1=H0(H1);if(y1>V1)V1=y1,F0=H1}return F0},v=(X0)=>{let D0=Z.audience?.get(X0);if(!D0)return[];return Object.keys(W.getPeers?.()||{}).filter((L0)=>D0.has(L0))},M=(X0,D0)=>{if(X0!==w&&!(Z.isBridge&&Z.bridges.some((i0)=>VQ(i0)===X0)))return;let L0=$(D0);if(!L0?.id||!L0?.t)return;if(f.has(L0.id))return;f.add(L0.id),a();let{t:H0,id:F0,ttl:V1,data:H1,origin:y1,originCell:i1}=L0,r0=Z.cellId;if(H0==="ping"&&H1?.pingId&&H1.target===A8&&y1!==A8){let i0={t:"pong",id:h(),ttl:m(),data:{pingId:H1.pingId,receivedAt:Date.now()},origin:A8,originCell:r0},V8=W.getPeers?.()?.[y1]?[y1]:v(r0);z?.send(JSON.stringify(i0),V8)}if(H0==="pong"&&H1?.pingId){let i0=b.get(H1.pingId);if(i0)clearTimeout(i0.timeout),i0.resolve(Date.now()-i0.start),b.delete(H1.pingId)}if(H0==="msg"&&y1!==A8)k(H1,y1);if(!Z.isBridge)return;if((V1??0)<=0)return;let x1=(i0,V8,F8=null)=>{if(!i0||!V8.length)return;let $9={t:H0,id:F0,ttl:F8??(V1??m())-1,data:H1,origin:y1||A8,originCell:i1||r0};i0.send(JSON.stringify($9),V8)};if(X0===w){for(let i0 of W0(r0))x1(F(i0),v(i0));return}x1(z,v(r0));for(let i0 of W0(r0))if(VQ(i0)!==X0)x1(F(i0),v(i0))},F=(X0)=>{let D0=VQ(X0),L0=W.channel(D0);if(!p.has(D0))p.add(D0),L0.on("message",(H0)=>M(D0,H0));return L0},c=()=>{if(!Z.cellId)return;if(w=VQ(Z.cellId),z=W.channel(w),!p.has(w))p.add(w),z.on("message",(X0)=>M(w,X0));if(Z.isBridge)for(let X0 of W0(Z.cellId))F(X0)},t=(X0,D0)=>{if(!X0.cellId||!X0.set.has(D0))return!1;let L0=`cell-${q6(D0,X0.C)}`;return L0===X0.cellId||X0.bridges.includes(L0)||GI(L0,X0.C).includes(X0.cellId)&&P(q6(D0,X0.C),X0.roster,X0.C)===D0},Y0=(X0)=>t(Z,X0)||Date.now()<U&&t(V,X0),$0=()=>{let X0=W.getPeers?.()||{};for(let D0 of Object.keys(X0))if(!Y0(D0))X0[D0].close?.()};G.admit=Y0;let S0=()=>({epoch:Z.epoch,cellId:Z.cellId,isBridge:Z.isBridge,bridges:Z.bridges,roster:[...Z.roster],cellSize:J,dynamicTTL:m(),totalCells:Z.C}),x0=()=>{A=Date.now();for(let[X0,D0]of T){if(X0===A8)continue;B("mesh:peer-state",{id:X0,cell:D0.cell,bridges:D0.bridges,timestamp:A})}},D1=(X0)=>{let D0=Fh(X0.length,X);J=Math.ceil(X0.length/D0);let L0=`cell-${q6(A8,D0)}`,H0=new Map,F0=new Set,V1=new Map,H1=(i0)=>V1.get(i0)??V1.set(i0,new Set).get(i0);for(let i0 of X0)H1(`cell-${q6(i0,D0)}`).add(i0);let y1=new Map,i1=(i0)=>y1.has(i0)?y1.get(i0):y1.set(i0,P(i0,X0,D0)).get(i0);for(let i0 of new Set(X0.map((V8)=>q6(V8,D0)))){let V8=`cell-${i0}`;for(let F8 of GI(V8,D0)){if(CQ(F8)<i0)continue;for(let $9 of[i1(i0),i1(CQ(F8))]){if(!$9)continue;let Q7=`cell-${q6($9,D0)}`===V8?F8:V8,d=H0.get($9)??[];if(!d.includes(Q7))d.push(Q7);if(H0.set($9,d),H1(V8).add($9),H1(F8).add($9),V8===L0||F8===L0)F0.add($9)}}}let r0=H0.get(A8)??[],x1=Z.cellId!==L0||String(Z.bridges)!==String(r0);V=Z,Z={epoch:Z.epoch+1,roster:X0,set:new Set(X0),key:X0.join("|"),C:D0,cellId:L0,isBridge:r0.length>0,bridges:r0,edgeBridges:[...F0],audience:V1},q=Date.now(),T.clear();for(let i0 of X0){let V8=H0.get(i0)??[];T.set(i0,{cell:`cell-${q6(i0,D0)}`,isBridge:V8.length>0,bridges:V8})}if(U=Date.now()+Bh,x1)c();vJ.info("\uD83D\uDD78\uFE0F [Cells] seal",{epoch:Z.epoch,myCell:L0,bridges:r0,C:D0,roster:X0.length}),x0(),B("mesh:state",S0())},b0=()=>{let X0=n(),D0=X0.join("|");if(D0===Z.key)Q=0;else{let L0=Date.now();if(Q||=L0,D0!==H)H=D0,N=L0;if(X0.some((H0)=>!Z.set.has(H0))||Z.edgeBridges.some((H0)=>!X0.includes(H0))||(W._gone?.()??[]).some((H0)=>Z.set.has(H0))?L0-N>=Mh||L0-Q>=Ph:L0-Q>=Lh)Q=0,D1(X0)}if(U&&Date.now()>=U)U=0,$0()},Q0=()=>{if(D)return;D=setInterval(()=>{if(b0(),Date.now()-A>=Eh)x0()},Rh)},O0=()=>{if(D)clearInterval(D),D=null},y0=(X0)=>{return new Promise((D0,L0)=>{let H0=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,F0=Date.now(),V1=setTimeout(()=>{b.delete(H0),L0(Error("Ping timeout"))},Th);b.set(H0,{start:F0,resolve:D0,reject:L0,timeout:V1,peerId:X0});let H1={t:"ping",id:h(),ttl:m(),data:{pingId:H0,target:X0},origin:A8,originCell:Z.cellId};z?.send(JSON.stringify(H1),v(Z.cellId))})};return W.on?.("peer:join",()=>b0()),W.on?.("peer:leave",()=>b0()),D1(n()),Q0(),{send:(X0)=>{let D0={t:"msg",id:h(),ttl:m(),data:X0,origin:A8,originCell:Z.cellId},L0=JSON.stringify(D0);z.send(L0,v(Z.cellId)),M(w,L0)},on:(X0,D0)=>X0==="message"?I0(D0):void 0,ping:y0,getState:()=>({...S0(),knownCells:new Set([...T.values()].map((X0)=>X0.cell)).size}),getPeerInfo:()=>new Map(T),getStableRoster:()=>[...Z.roster],getKnownCells:()=>{let X0=new Map;for(let[D0,{cell:L0}]of T)if(!X0.has(L0))X0.set(L0,{lastSeen:q,peerId:D0});return X0},getCellSize:()=>J,destroy:()=>{O0(),b.forEach((X0)=>clearTimeout(X0.timeout)),b.clear()}}}function xh(W,Y,G){let X={},J=nT({...W,admit:(Q)=>X.admit?.(Q)??!0},Y,G),Z=W.overlay||{},V=Sh(J,Z,X),U=new Map;return{on:(Q,H)=>J.on(Q,H),off:(Q,H)=>J.off?.(Q,H),channel:(Q)=>{if(U.has(Q))return U.get(Q);let H=J.channel(Q),N={send:(A,q)=>{if(q){let z=[].concat(q),w=J.getPeers?.()||{};if(z.every((D)=>w[D]))return H.send(A,q)}V.send({_ch:Q,_d:A,_t:q})},on:(A,q)=>{if(A==="message")V.on("message",(z,w)=>{if(z?._ch!==Q)return;if(z._t&&![].concat(z._t).includes(A8))return;q(z._d,w)}),H.on(A,q);else H.on(A,q)},off:(A,q)=>H.off?.(A,q),_original:H};return U.set(Q,N),N},get id(){return J.id},get peers(){return J.peers},getPeers:()=>J.getPeers?.()||{},mesh:V,_room:J,getState:()=>V.getState(),getPeerInfo:()=>V.getPeerInfo(),ping:(Q)=>V.ping(Q),leave:()=>{V.destroy(),U.clear(),J.leave()},destroy:()=>{V.destroy(),U.clear()}}}var MI=(W,Y,G)=>W?.cells||W?.overlay?xh(W,Y,G):nT(W,Y,G);import{randomBytes as IS}from"crypto";function kh(){var W,Y=!1,G=this;G._DeArray=function(X,J,Z){return[X.slice(J,J+Z)]},G._EnArray=function(X,J,Z,V){for(var U=0;U<Z;X[J+U]=V[U]?V[U]:0,U++);},G._DeChar=function(X,J){return String.fromCharCode(X[J])},G._EnChar=function(X,J,Z){X[J]=Z.charCodeAt(0)},G._DeInt=function(X,J){var Z=Y?W.len-1:0,V=Y?-1:1,U=Z+V*W.len,Q,H,N;for(Q=0,H=Z,N=1;H!=U;Q+=X[J+H]*N,H+=V,N*=256);if(W.bSigned&&Q&Math.pow(2,W.len*8-1))Q-=Math.pow(2,W.len*8);return Q},G._EnInt=function(X,J,Z){var V=Y?W.len-1:0,U=Y?-1:1,Q=V+U*W.len,H;Z=Z<W.min?W.min:Z>W.max?W.max:Z;for(H=V;H!=Q;X[J+H]=Z&255,H+=U,Z>>=8);},G._DeString=function(X,J,Z){for(var V=Array(Z),U=0;U<Z;V[U]=String.fromCharCode(X[J+U]),U++);return V.join("")},G._EnString=function(X,J,Z,V){for(var U,Q=0;Q<Z;X[J+Q]=(U=V.charCodeAt(Q))?U:0,Q++);},G._De754=function(X,J){var Z,V,U,Q,H,N,A,q,z,w;A=W.mLen,q=W.len*8-W.mLen-1,w=(1<<q)-1,z=w>>1,Q=Y?0:W.len-1,H=Y?1:-1,Z=X[J+Q],Q+=H,N=-7;for(V=Z&(1<<-N)-1,Z>>=-N,N+=q;N>0;V=V*256+X[J+Q],Q+=H,N-=8);for(U=V&(1<<-N)-1,V>>=-N,N+=A;N>0;U=U*256+X[J+Q],Q+=H,N-=8);switch(V){case 0:V=1-z;break;case w:return U?NaN:(Z?-1:1)*(1/0);default:U=U+Math.pow(2,A),V=V-z;break}return(Z?-1:1)*U*Math.pow(2,V-A)},G._En754=function(X,J,Z){var V,U,Q,H,N,A,q,z,w,D;if(q=W.mLen,z=W.len*8-W.mLen-1,D=(1<<z)-1,w=D>>1,V=Z<0?1:0,Z=Math.abs(Z),isNaN(Z)||Z==1/0)Q=isNaN(Z)?1:0,U=D;else{if(U=Math.floor(Math.log(Z)/Math.LN2),Z*(A=Math.pow(2,-U))<1)U--,A*=2;if(U+w>=1)Z+=W.rt/A;else Z+=W.rt*Math.pow(2,1-w);if(Z*A>=2)U++,A/=2;if(U+w>=D)Q=0,U=D;else if(U+w>=1)Q=(Z*A-1)*Math.pow(2,q),U=U+w;else Q=Z*Math.pow(2,w-1)*Math.pow(2,q),U=0}for(H=Y?W.len-1:0,N=Y?-1:1;q>=8;X[J+H]=Q&255,H+=N,Q/=256,q-=8);for(U=U<<q|Q,z+=q;z>0;X[J+H]=U&255,H+=N,U/=256,z-=8);X[J+H-N]|=V*128},G._DeInt64=function(X,J){var Z=Y?0:7,V=Y?1:-1,U=Z+V*8,Q=[0,0,!W.bSigned],H,N,A;for(H=Z,A=1,N=0;H!=U;Q[A]=(Q[A]<<8>>>0)+X[J+H],H+=V,N++,A=N<4?1:0);return Q},G._EnInt64=function(X,J,Z){var V=Y?0:7,U=Y?1:-1,Q=V+U*8,H,N,A,q;for(H=V,A=1,N=0,q=24;H!=Q;X[J+H]=Z[A]>>q&255,H+=U,N++,A=N<4?1:0,q=24-8*(N%4));},G._sPattern="(\\d + )?([AxcbBhHsfdiIlLqQ])",G._lenLut={A:1,x:1,c:1,b:1,B:1,h:2,H:2,s:1,f:4,d:8,i:4,I:4,l:4,L:4,q:8,Q:8},G._elLut={A:{en:G._EnArray,de:G._DeArray},s:{en:G._EnString,de:G._DeString},c:{en:G._EnChar,de:G._DeChar},b:{en:G._EnInt,de:G._DeInt,len:1,bSigned:!0,min:-Math.pow(2,7),max:Math.pow(2,7)-1},B:{en:G._EnInt,de:G._DeInt,len:1,bSigned:!1,min:0,max:Math.pow(2,8)-1},h:{en:G._EnInt,de:G._DeInt,len:2,bSigned:!0,min:-Math.pow(2,15),max:Math.pow(2,15)-1},H:{en:G._EnInt,de:G._DeInt,len:2,bSigned:!1,min:0,max:Math.pow(2,16)-1},i:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},I:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},l:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!0,min:-Math.pow(2,31),max:Math.pow(2,31)-1},L:{en:G._EnInt,de:G._DeInt,len:4,bSigned:!1,min:0,max:Math.pow(2,32)-1},f:{en:G._En754,de:G._De754,len:4,mLen:23,rt:Math.pow(2,-24)-Math.pow(2,-77)},d:{en:G._En754,de:G._De754,len:8,mLen:52,rt:0},q:{en:G._EnInt64,de:G._DeInt64,bSigned:!0},Q:{en:G._EnInt64,de:G._DeInt64,bSigned:!1}},G._UnpackSeries=function(X,J,Z,V){for(var U=W.de,Q=[],H=0;H<X;Q.push(U(Z,V+H*J)),H++);return Q},G._PackSeries=function(X,J,Z,V,U,Q){for(var H=W.en,N=0;N<X;H(Z,V+N*J,U[Q+N]),N++);},G.Unpack=function(X,J,Z){Y=X.charAt(0)!="<",Z=Z?Z:0;var V=new RegExp(this._sPattern,"g"),U,Q,H,N=[];while(U=V.exec(X)){if(Q=U[1]==null||U[1]==""?1:parseInt(U[1]),H=this._lenLut[U[2]],Z+Q*H>J.length)return;switch(U[2]){case"A":case"s":N.push(this._elLut[U[2]].de(J,Z,Q));break;case"c":case"b":case"B":case"h":case"H":case"i":case"I":case"l":case"L":case"f":case"d":case"q":case"Q":W=this._elLut[U[2]],N.push(this._UnpackSeries(Q,H,J,Z));break}Z+=Q*H}return Array.prototype.concat.apply([],N)},G.PackTo=function(X,J,Z,V){Y=X.charAt(0)!="<";var U=new RegExp(this._sPattern,"g"),Q,H,N,A,q=0;while(Q=U.exec(X)){if(H=Q[1]==null||Q[1]==""?1:parseInt(Q[1]),N=this._lenLut[Q[2]],Z+H*N>J.length)return!1;switch(Q[2]){case"A":case"s":if(q+1>V.length)return!1;this._elLut[Q[2]].en(J,Z,H,V[q]),q+=1;break;case"c":case"b":case"B":case"h":case"H":case"i":case"I":case"l":case"L":case"f":case"d":case"q":case"Q":if(W=this._elLut[Q[2]],q+H>V.length)return!1;this._PackSeries(H,N,J,Z,V,q),q+=H;break;case"x":for(A=0;A<H;A++)J[Z+A]=0;break}Z+=H*N}return J},G.Pack=function(X,J){return this.PackTo(X,Array(this.CalcLength(X)),0,J)},G.CalcLength=function(X){var J=new RegExp(this._sPattern,"g"),Z=0,V;while(V=J.exec(X))Z+=(V[1]==null||V[1]==""?1:parseInt(V[1]))*this._lenLut[V[2]];return Z}}var s1=new kh;var PS=v1(JR(),1),Hq=v1(gI(),1);import{createSocket as kd}from"dgram";import{createSocket as vd}from"dgram";import*as LS from"net";import{connect as gd}from"net";import{createSign as hd,randomBytes as bd,webcrypto as md}from"crypto";var OH0=v1(kR(),1);var M7={};NA(M7,{verifySchema:()=>lm,fromBER:()=>Q4,compareSchema:()=>J4,VisibleString:()=>FW,ViewWriter:()=>dJ,VideotexString:()=>MG,ValueBlock:()=>e8,Utf8String:()=>u5,UniversalString:()=>DG,UTCTime:()=>SW,TimeOfDay:()=>aQ,TeletexString:()=>RG,TIME:()=>eQ,Set:()=>f9,Sequence:()=>_9,Repeated:()=>zG,RelativeObjectIdentifier:()=>iQ,RawData:()=>MM,PrintableString:()=>TG,Primitive:()=>O6,OctetString:()=>T7,ObjectIdentifier:()=>OG,NumericString:()=>CG,Null:()=>C7,Integer:()=>K6,IA5String:()=>PG,HexBlock:()=>D7,GraphicString:()=>LG,GeneralizedTime:()=>$G,GeneralString:()=>BG,Enumerated:()=>jG,EndOfContent:()=>oQ,Duration:()=>tQ,DateTime:()=>sQ,DEFAULT_MAX_NODES:()=>dR,DEFAULT_MAX_DEPTH:()=>lR,DEFAULT_MAX_CONTENT_LENGTH:()=>oR,DATE:()=>rQ,Constructed:()=>c8,Choice:()=>nJ,CharacterString:()=>EG,Boolean:()=>wG,BmpString:()=>KG,BitString:()=>R7,BaseStringBlock:()=>lQ,BaseBlock:()=>k8,Any:()=>V4});/*!
|
|
148
148
|
* MIT License
|
|
149
149
|
*
|
|
150
150
|
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
@@ -205,12 +205,12 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
205
205
|
`).map((X)=>` ${X}`).join(`
|
|
206
206
|
`));let Y=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return W.length?`${Y} :
|
|
207
207
|
${W.join(`
|
|
208
|
-
`)}`:`${Y} :`}}nR=c8;(()=>{f0.Constructed=nR})();c8.NAME="CONSTRUCTED";class oI extends e8{fromBER(W,Y,G){return Y}toBER(W){return K7}}oI.override="EndOfContentValueBlock";var iR;class oQ extends k8{constructor(W={}){super(W,oI);this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}iR=oQ;(()=>{f0.EndOfContent=iR})();oQ.NAME=lJ;var rR;class C7 extends k8{constructor(W={}){super(W,e8);this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(W,Y,G){if(this.lenBlock.length>0)this.warnings.push("Non-zero length of value block for Null type");if(!this.idBlock.error.length)this.blockLength+=this.idBlock.blockLength;if(!this.lenBlock.error.length)this.blockLength+=this.lenBlock.blockLength;if(this.blockLength+=G,Y+G>W.byteLength)return this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1;return Y+G}toBER(W,Y){let G=new ArrayBuffer(2);if(!W){let X=new Uint8Array(G);X[0]=5,X[1]=0}if(Y)Y.write(G);return G}onAsciiEncoding(){return`${this.constructor.NAME}`}}rR=C7;(()=>{f0.Null=rR})();C7.NAME="NULL";class nI extends D7(e8){get value(){for(let W of this.valueHexView)if(W>0)return!0;return!1}set value(W){this.valueHexView[0]=W?255:0}constructor({value:W,...Y}={}){super(Y);if(Y.valueHex)this.valueHexView=_0.toUint8Array(Y.valueHex);else this.valueHexView=new Uint8Array(1);if(W)this.value=W}fromBER(W,Y,G){let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;if(this.valueHexView=X.subarray(Y,Y+G),G>1)this.warnings.push("Boolean value encoded in more then 1 octet");return this.isHexOnly=!0,bI.call(this),this.blockLength=G,Y+G}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}nI.NAME="BooleanValueBlock";var aR;class wG extends k8{getValue(){return this.valueBlock.value}setValue(W){this.valueBlock.value=W}constructor(W={}){super(W,nI);this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}aR=wG;(()=>{f0.Boolean=aR})();wG.NAME="BOOLEAN";class iI extends D7(Z4){constructor({isConstructed:W=!1,...Y}={}){super(Y);this.isConstructed=W}fromBER(W,Y,G,X){let J=0;if(this.isConstructed){if(this.isHexOnly=!1,J=Z4.prototype.fromBER.call(this,W,Y,G,X),J===-1)return J;for(let Z=0;Z<this.value.length;Z++){let V=this.value[Z].constructor.NAME;if(V===lJ)if(this.isIndefiniteForm)break;else return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1;if(V!==mR)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,J=super.fromBER(W,Y,G),this.blockLength=G;return J}toBER(W,Y){if(this.isConstructed)return Z4.prototype.toBER.call(this,W,Y);return W?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}iI.NAME="OctetStringValueBlock";var rI;class T7 extends k8{constructor({idBlock:W={},lenBlock:Y={},...G}={}){var X,J;(X=G.isConstructed)!==null&&X!==void 0||(G.isConstructed=!!((J=G.value)===null||J===void 0?void 0:J.length));super({idBlock:{isConstructed:G.isConstructed,...W},lenBlock:{...Y,isIndefiniteForm:!!G.isIndefiniteForm},...G},iI);this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(W,Y,G,X){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,G===0){if(this.idBlock.error.length===0)this.blockLength+=this.idBlock.blockLength;if(this.lenBlock.error.length===0)this.blockLength+=this.lenBlock.blockLength;return Y}if(!this.valueBlock.isConstructed){let Z=(W instanceof ArrayBuffer?new Uint8Array(W):W).subarray(Y,Y+G);try{if(Z.byteLength){let V=X!==null&&X!==void 0?X:oJ(),U=dI(Z,0,Z.byteLength,V);if(U.offset!==-1&&U.offset===G)this.valueBlock.value=[U.result]}}catch{}}return super.fromBER(W,Y,G,X)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return c8.prototype.onAsciiEncoding.call(this);let W=this.constructor.NAME,Y=o0.ToHex(this.valueBlock.valueHexView);return`${W} : ${Y}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let W=[];for(let Y of this.valueBlock.value)if(Y instanceof rI)W.push(Y.valueBlock.valueHexView);return _0.concat(W)}}rI=T7;(()=>{f0.OctetString=rI})();T7.NAME=mR;class aI extends D7(Z4){constructor({unusedBits:W=0,isConstructed:Y=!1,...G}={}){super(G);this.unusedBits=W,this.isConstructed=Y,this.blockLength=this.valueHexView.byteLength}fromBER(W,Y,G,X){if(!G)return Y;let J=-1;if(this.isConstructed){if(J=Z4.prototype.fromBER.call(this,W,Y,G,X),J===-1)return J;for(let U of this.value){let Q=U.constructor.NAME;if(Q===lJ)if(this.isIndefiniteForm)break;else return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1;if(Q!==fR)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let H=U.valueBlock;if(this.unusedBits>0&&H.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=H.unusedBits}return J}let Z=_0.toUint8Array(W);if(!U4(this,Z,Y,G))return-1;let V=Z.subarray(Y,Y+G);if(this.unusedBits=V[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let U=V.subarray(1);try{if(U.byteLength){let Q=X!==null&&X!==void 0?X:oJ(),H=dI(U,0,U.byteLength,Q);if(H.offset!==-1&&H.offset===G-1)this.value=[H.result]}}catch{}}return this.valueHexView=V.subarray(1),this.blockLength=V.length,Y+G}toBER(W,Y){if(this.isConstructed)return Z4.prototype.toBER.call(this,W,Y);if(W)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){let X=new Uint8Array(1);return X[0]=0,X.buffer}let G=new Uint8Array(this.valueHexView.length+1);return G[0]=this.unusedBits,G.set(this.valueHexView,1),G.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}aI.NAME="BitStringValueBlock";var sR;class R7 extends k8{constructor({idBlock:W={},lenBlock:Y={},...G}={}){var X,J;(X=G.isConstructed)!==null&&X!==void 0||(G.isConstructed=!!((J=G.value)===null||J===void 0?void 0:J.length));super({idBlock:{isConstructed:G.isConstructed,...W},lenBlock:{...Y,isIndefiniteForm:!!G.isIndefiniteForm},...G},aI);this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(W,Y,G,X){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(W,Y,G,X)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return c8.prototype.onAsciiEncoding.call(this);else{let W=[],Y=this.valueBlock.valueHexView;for(let Z of Y)W.push(Z.toString(2).padStart(8,"0"));let G=W.join(""),X=this.constructor.NAME,J=G.substring(0,G.length-this.valueBlock.unusedBits);return`${X} : ${J}`}}}sR=R7;(()=>{f0.BitString=sR})();R7.NAME=fR;var tR;function cm(W,Y){let G=new Uint8Array([0]),X=new Uint8Array(W),J=new Uint8Array(Y),Z=X.slice(0),V=Z.length-1,U=J.slice(0),Q=U.length-1,H=0,N=Q<V?V:Q,A=0;for(let q=N;q>=0;q--,A++){switch(!0){case A<U.length:H=Z[V-A]+U[Q-A]+G[0];break;default:H=Z[V-A]+G[0]}switch(G[0]=H/10,!0){case A>=Z.length:Z=bQ(new Uint8Array([H%10]),Z);break;default:Z[V-A]=H%10}}if(G[0]>0)Z=bQ(G,Z);return Z}function bR(W){if(W>=cJ.length)for(let Y=cJ.length;Y<=W;Y++){let G=new Uint8Array([0]),X=cJ[Y-1].slice(0);for(let J=X.length-1;J>=0;J--){let Z=new Uint8Array([(X[J]<<1)+G[0]]);G[0]=Z[0]/10,X[J]=Z[0]%10}if(G[0]>0)X=bQ(G,X);cJ.push(X)}return cJ[W]}function pm(W,Y){let G=0,X=new Uint8Array(W),J=new Uint8Array(Y),Z=X.slice(0),V=Z.length-1,U=J.slice(0),Q=U.length-1,H,N=0;for(let A=Q;A>=0;A--,N++)switch(H=Z[V-N]-U[Q-N]-G,!0){case H<0:G=1,Z[V-N]=H+10;break;default:G=0,Z[V-N]=H}if(G>0)for(let A=V-Q+1;A>=0;A--,N++)if(H=Z[V-N]-G,H<0)G=1,Z[V-N]=H+10;else{G=0,Z[V-N]=H;break}return Z.slice()}class nQ extends D7(e8){setValueHex(){if(this.valueHexView.length>=4)this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0;else if(this.isHexOnly=!1,this.valueHexView.length>0)this._valueDec=bI.call(this)}constructor({value:W,...Y}={}){super(Y);if(this._valueDec=0,Y.valueHex)this.setValueHex();if(W!==void 0)this.valueDec=W}set valueDec(W){this._valueDec=W,this.isHexOnly=!1,this.valueHexView=new Uint8Array(vR(W))}get valueDec(){return this._valueDec}fromDER(W,Y,G,X=0){let J=this.fromBER(W,Y,G);if(J===-1)return J;let Z=this.valueHexView;if(Z[0]===0&&(Z[1]&128)!==0)this.valueHexView=Z.subarray(1);else if(X!==0){if(Z.length<X){if(X-Z.length>1)X=Z.length+1;this.valueHexView=Z.subarray(X-Z.length)}}return J}toDER(W=!1){let Y=this.valueHexView;switch(!0){case(Y[0]&128)!==0:{let G=new Uint8Array(this.valueHexView.length+1);G[0]=0,G.set(Y,1),this.valueHexView=G}break;case(Y[0]===0&&(Y[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(W)}fromBER(W,Y,G){let X=super.fromBER(W,Y,G);if(X===-1)return X;return this.setValueHex(),X}toBER(W){return W?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let W=this.valueHexView.length*8-1,Y=new Uint8Array(this.valueHexView.length*8/3),G=0,X,J=this.valueHexView,Z="",V=!1;for(let U=J.byteLength-1;U>=0;U--){X=J[U];for(let Q=0;Q<8;Q++){if((X&1)===1)switch(G){case W:Y=pm(bR(G),Y),Z="-";break;default:Y=cm(Y,bR(G))}G++,X>>=1}}for(let U=0;U<Y.length;U++){if(Y[U])V=!0;if(V)Z+=uR.charAt(Y[U])}if(V===!1)Z+=uR.charAt(0);return Z}}tR=nQ;nQ.NAME="IntegerValueBlock";(()=>{Object.defineProperty(tR.prototype,"valueHex",{set:function(W){this.valueHexView=new Uint8Array(W),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}})})();var pJ;class K6 extends k8{constructor(W={}){super(W,nQ);this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return mQ(),BigInt(this.valueBlock.toString())}static fromBigInt(W){mQ();let Y=BigInt(W),G=new dJ,X=Y.toString(16).replace(/^-/,""),J=new Uint8Array(o0.FromHex(X));if(Y<0){let V=new Uint8Array(J.length+(J[0]&128?1:0));V[0]|=128;let Q=BigInt(`0x${o0.ToHex(V)}`)+Y,H=_0.toUint8Array(o0.FromHex(Q.toString(16)));H[0]|=128,G.write(H)}else{if(J[0]&128)G.write(new Uint8Array([0]));G.write(J)}return new pJ({valueHex:G.final()})}convertToDER(){let W=new pJ({valueHex:this.valueBlock.valueHexView});return W.valueBlock.toDER(),W}convertFromDER(){return new pJ({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}pJ=K6;(()=>{f0.Integer=pJ})();K6.NAME="INTEGER";var eR;class jG extends K6{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}eR=jG;(()=>{f0.Enumerated=eR})();jG.NAME="ENUMERATED";class fQ extends D7(e8){constructor({valueDec:W=-1,isFirstSid:Y=!1,...G}={}){super(G);this.valueDec=W,this.isFirstSid=Y}fromBER(W,Y,G){if(!G)return Y;let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;let J=X.subarray(Y,Y+G);this.valueHexView=new Uint8Array(G);for(let V=0;V<G;V++)if(this.valueHexView[V]=J[V]&127,this.blockLength++,(J[V]&128)===0)break;let Z=new Uint8Array(this.blockLength);for(let V=0;V<this.blockLength;V++)Z[V]=this.valueHexView[V];if(this.valueHexView=Z,(J[this.blockLength-1]&128)!==0)return this.error="End of input reached before message was fully decoded",-1;if(this.valueHexView[0]===0)this.warnings.push("Needlessly long format of SID encoding");if(this.blockLength<=8)this.valueDec=$W(this.valueHexView,7);else this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only");return Y+this.blockLength}set valueBigInt(W){mQ();let Y=BigInt(W).toString(2);while(Y.length%7)Y="0"+Y;let G=new Uint8Array(Y.length/7);for(let X=0;X<G.length;X++)G[X]=parseInt(Y.slice(X*7,X*7+7),2)+(X+1<G.length?128:0);this.fromBER(G.buffer,0,G.length)}toBER(W){if(this.isHexOnly){if(W)return new ArrayBuffer(this.valueHexView.byteLength);let X=this.valueHexView,J=new Uint8Array(this.blockLength);for(let Z=0;Z<this.blockLength-1;Z++)J[Z]=X[Z]|128;return J[this.blockLength-1]=X[this.blockLength-1],J.buffer}let Y=w6(this.valueDec,7);if(Y.byteLength===0)return this.error="Error during encoding SID value",K7;let G=new Uint8Array(Y.byteLength);if(!W){let X=new Uint8Array(Y),J=Y.byteLength-1;for(let Z=0;Z<J;Z++)G[Z]=X[Z]|128;G[J]=X[J]}return G}toString(){let W="";if(this.isHexOnly)W=o0.ToHex(this.valueHexView);else if(this.isFirstSid){let Y=this.valueDec;if(this.valueDec<=39)W="0.";else if(this.valueDec<=79)W="1.",Y-=40;else W="2.",Y-=80;W+=Y.toString()}else W=this.valueDec.toString();return W}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}fQ.NAME="sidBlock";class sI extends e8{constructor({value:W=m9,...Y}={}){super(Y);if(this.value=[],W)this.fromString(W)}fromBER(W,Y,G){let X=Y;while(G>0){let J=new fQ;if(X=J.fromBER(W,X,G),X===-1)return this.blockLength=0,this.error=J.error,X;if(this.value.length===0)J.isFirstSid=!0;this.blockLength+=J.blockLength,G-=J.blockLength,this.value.push(J)}return X}toBER(W){let Y=[];for(let G=0;G<this.value.length;G++){let X=this.value[G].toBER(W);if(X.byteLength===0)return this.error=this.value[G].error,K7;Y.push(X)}return fI(Y)}fromString(W){this.value=[];let Y=0,G=0,X="",J=!1;do{if(G=W.indexOf(".",Y),G===-1)X=W.substring(Y);else X=W.substring(Y,G);if(Y=G+1,J){let Z=this.value[0],V=0;switch(Z.valueDec){case 0:break;case 1:V=40;break;case 2:V=80;break;default:this.value=[];return}let U=parseInt(X,10);if(isNaN(U))return;Z.valueDec=U+V,J=!1}else{let Z=new fQ;if(X>Number.MAX_SAFE_INTEGER){mQ();let V=BigInt(X);Z.valueBigInt=V}else if(Z.valueDec=parseInt(X,10),isNaN(Z.valueDec))return;if(!this.value.length)Z.isFirstSid=!0,J=!0;this.value.push(Z)}}while(G!==-1)}toString(){let W="",Y=!1;for(let G=0;G<this.value.length;G++){Y=this.value[G].isHexOnly;let X=this.value[G].toString();if(G!==0)W=`${W}.`;if(Y)if(X=`{${X}}`,this.value[G].isFirstSid)W=`2.{${X} - 80}`;else W+=X;else W+=X}return W}toJSON(){let W={...super.toJSON(),value:this.toString(),sidArray:[]};for(let Y=0;Y<this.value.length;Y++)W.sidArray.push(this.value[Y].toJSON());return W}}sI.NAME="ObjectIdentifierValueBlock";var WM;class OG extends k8{getValue(){return this.valueBlock.toString()}setValue(W){this.valueBlock.fromString(W)}constructor(W={}){super(W,sI);this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}WM=OG;(()=>{f0.ObjectIdentifier=WM})();OG.NAME="OBJECT IDENTIFIER";class cQ extends D7(j6){constructor({valueDec:W=0,...Y}={}){super(Y);this.valueDec=W}fromBER(W,Y,G){if(G===0)return Y;let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;let J=X.subarray(Y,Y+G);this.valueHexView=new Uint8Array(G);for(let V=0;V<G;V++)if(this.valueHexView[V]=J[V]&127,this.blockLength++,(J[V]&128)===0)break;let Z=new Uint8Array(this.blockLength);for(let V=0;V<this.blockLength;V++)Z[V]=this.valueHexView[V];if(this.valueHexView=Z,(J[this.blockLength-1]&128)!==0)return this.error="End of input reached before message was fully decoded",-1;if(this.valueHexView[0]===0)this.warnings.push("Needlessly long format of SID encoding");if(this.blockLength<=8)this.valueDec=$W(this.valueHexView,7);else this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only");return Y+this.blockLength}toBER(W){if(this.isHexOnly){if(W)return new ArrayBuffer(this.valueHexView.byteLength);let X=this.valueHexView,J=new Uint8Array(this.blockLength);for(let Z=0;Z<this.blockLength-1;Z++)J[Z]=X[Z]|128;return J[this.blockLength-1]=X[this.blockLength-1],J.buffer}let Y=w6(this.valueDec,7);if(Y.byteLength===0)return this.error="Error during encoding SID value",K7;let G=new Uint8Array(Y.byteLength);if(!W){let X=new Uint8Array(Y),J=Y.byteLength-1;for(let Z=0;Z<J;Z++)G[Z]=X[Z]|128;G[J]=X[J]}return G.buffer}toString(){let W="";if(this.isHexOnly)W=o0.ToHex(this.valueHexView);else W=this.valueDec.toString();return W}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}cQ.NAME="relativeSidBlock";class tI extends e8{constructor({value:W=m9,...Y}={}){super(Y);if(this.value=[],W)this.fromString(W)}fromBER(W,Y,G){let X=Y;while(G>0){let J=new cQ;if(X=J.fromBER(W,X,G),X===-1)return this.blockLength=0,this.error=J.error,X;this.blockLength+=J.blockLength,G-=J.blockLength,this.value.push(J)}return X}toBER(W,Y){let G=[];for(let X=0;X<this.value.length;X++){let J=this.value[X].toBER(W);if(J.byteLength===0)return this.error=this.value[X].error,K7;G.push(J)}return fI(G)}fromString(W){this.value=[];let Y=0,G=0,X="";do{if(G=W.indexOf(".",Y),G===-1)X=W.substring(Y);else X=W.substring(Y,G);Y=G+1;let J=new cQ;if(J.valueDec=parseInt(X,10),isNaN(J.valueDec))return!0;this.value.push(J)}while(G!==-1);return!0}toString(){let W="",Y=!1;for(let G=0;G<this.value.length;G++){Y=this.value[G].isHexOnly;let X=this.value[G].toString();if(G!==0)W=`${W}.`;if(Y)X=`{${X}}`,W+=X;else W+=X}return W}toJSON(){let W={...super.toJSON(),value:this.toString(),sidArray:[]};for(let Y=0;Y<this.value.length;Y++)W.sidArray.push(this.value[Y].toJSON());return W}}tI.NAME="RelativeObjectIdentifierValueBlock";var YM;class iQ extends k8{getValue(){return this.valueBlock.toString()}setValue(W){this.valueBlock.fromString(W)}constructor(W={}){super(W,tI);this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}YM=iQ;(()=>{f0.RelativeObjectIdentifier=YM})();iQ.NAME="RelativeObjectIdentifier";var GM;class _9 extends c8{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}GM=_9;(()=>{f0.Sequence=GM})();_9.NAME="SEQUENCE";var XM;class f9 extends c8{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}XM=f9;(()=>{f0.Set=XM})();f9.NAME="SET";class eI extends D7(e8){constructor({...W}={}){super(W);this.isHexOnly=!0,this.value=m9}toJSON(){return{...super.toJSON(),value:this.value}}}eI.NAME="StringValueBlock";class Wz extends eI{}Wz.NAME="SimpleStringValueBlock";class c9 extends lQ{constructor({...W}={}){super(W,Wz)}fromBuffer(W){this.valueBlock.value=String.fromCharCode.apply(null,_0.toUint8Array(W))}fromString(W){let Y=W.length,G=this.valueBlock.valueHexView=new Uint8Array(Y);for(let X=0;X<Y;X++)G[X]=W.charCodeAt(X);this.valueBlock.value=W}}c9.NAME="SIMPLE STRING";class Yz extends c9{fromBuffer(W){this.valueBlock.valueHexView=_0.toUint8Array(W);try{this.valueBlock.value=o0.ToUtf8String(W)}catch(Y){this.warnings.push(`Error during "decodeURIComponent": ${Y}, using raw string`),this.valueBlock.value=o0.ToBinary(W)}}fromString(W){this.valueBlock.valueHexView=new Uint8Array(o0.FromUtf8String(W)),this.valueBlock.value=W}}Yz.NAME="Utf8StringValueBlock";var JM;class u5 extends Yz{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}JM=u5;(()=>{f0.Utf8String=JM})();u5.NAME="UTF8String";class Gz extends c9{fromBuffer(W){this.valueBlock.value=o0.ToUtf16String(W),this.valueBlock.valueHexView=_0.toUint8Array(W)}fromString(W){this.valueBlock.value=W,this.valueBlock.valueHexView=new Uint8Array(o0.FromUtf16String(W))}}Gz.NAME="BmpStringValueBlock";var ZM;class KG extends Gz{constructor({...W}={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}ZM=KG;(()=>{f0.BmpString=ZM})();KG.NAME="BMPString";class Xz extends c9{fromBuffer(W){let Y=ArrayBuffer.isView(W)?W.slice().buffer:W.slice(0),G=new Uint8Array(Y);for(let X=0;X<G.length;X+=4)G[X]=G[X+3],G[X+1]=G[X+2],G[X+2]=0,G[X+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(Y))}fromString(W){let Y=W.length,G=this.valueBlock.valueHexView=new Uint8Array(Y*4);for(let X=0;X<Y;X++){let J=w6(W.charCodeAt(X),8),Z=new Uint8Array(J);if(Z.length>4)continue;let V=4-Z.length;for(let U=Z.length-1;U>=0;U--)G[X*4+U+V]=Z[U]}this.valueBlock.value=W}}Xz.NAME="UniversalStringValueBlock";var VM;class DG extends Xz{constructor({...W}={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}VM=DG;(()=>{f0.UniversalString=VM})();DG.NAME="UniversalString";var UM;class CG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}UM=CG;(()=>{f0.NumericString=UM})();CG.NAME="NumericString";var QM;class TG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}QM=TG;(()=>{f0.PrintableString=QM})();TG.NAME="PrintableString";var HM;class RG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}HM=RG;(()=>{f0.TeletexString=HM})();RG.NAME="TeletexString";var NM;class MG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}NM=MG;(()=>{f0.VideotexString=NM})();MG.NAME="VideotexString";var qM;class PG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}qM=PG;(()=>{f0.IA5String=qM})();PG.NAME="IA5String";var AM;class LG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}AM=LG;(()=>{f0.GraphicString=AM})();LG.NAME="GraphicString";var IM;class FW extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}IM=FW;(()=>{f0.VisibleString=IM})();FW.NAME="VisibleString";var zM;class BG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}zM=BG;(()=>{f0.GeneralString=zM})();BG.NAME="GeneralString";var wM;class EG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}wM=EG;(()=>{f0.CharacterString=wM})();EG.NAME="CharacterString";var jM;class SW extends FW{constructor({value:W,valueDate:Y,...G}={}){super(G);if(this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,W){this.fromString(W),this.valueBlock.valueHexView=new Uint8Array(W.length);for(let X=0;X<W.length;X++)this.valueBlock.valueHexView[X]=W.charCodeAt(X)}if(Y)this.fromDate(Y),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer());this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(W){this.fromString(String.fromCharCode.apply(null,_0.toUint8Array(W)))}toBuffer(){let W=this.toString(),Y=new ArrayBuffer(W.length),G=new Uint8Array(Y);for(let X=0;X<W.length;X++)G[X]=W.charCodeAt(X);return Y}fromDate(W){this.year=W.getUTCFullYear(),this.month=W.getUTCMonth()+1,this.day=W.getUTCDate(),this.hour=W.getUTCHours(),this.minute=W.getUTCMinutes(),this.second=W.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(W){let G=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(W);if(G===null){this.error="Wrong input string for conversion";return}let X=parseInt(G[1],10);if(X>=50)this.year=1900+X;else this.year=2000+X;this.month=parseInt(G[2],10),this.day=parseInt(G[3],10),this.hour=parseInt(G[4],10),this.minute=parseInt(G[5],10),this.second=parseInt(G[6],10)}toString(W="iso"){if(W==="iso"){let Y=[,,,,,,,];return Y[0]=b9(this.year<2000?this.year-1900:this.year-2000,2),Y[1]=b9(this.month,2),Y[2]=b9(this.day,2),Y[3]=b9(this.hour,2),Y[4]=b9(this.minute,2),Y[5]=b9(this.second,2),Y[6]="Z",Y.join("")}return super.toString(W)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}jM=SW;(()=>{f0.UTCTime=jM})();SW.NAME="UTCTime";var OM;class $G extends SW{constructor(W={}){var Y;super(W);(Y=this.millisecond)!==null&&Y!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(W){super.fromDate(W),this.millisecond=W.getUTCMilliseconds()}toDate(){let W=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(W)}fromString(W){let Y=!1,G="",X="",J=0,Z,V=0,U=0;if(W[W.length-1]==="Z")G=W.substring(0,W.length-1),Y=!0;else{let N=new Number(W[W.length-1]);if(isNaN(N.valueOf()))throw Error("Wrong input string for conversion");G=W}if(Y){if(G.indexOf("+")!==-1)throw Error("Wrong input string for conversion");if(G.indexOf("-")!==-1)throw Error("Wrong input string for conversion")}else{let N=1,A=G.indexOf("+"),q="";if(A===-1)A=G.indexOf("-"),N=-1;if(A!==-1){if(q=G.substring(A+1),G=G.substring(0,A),q.length!==2&&q.length!==4)throw Error("Wrong input string for conversion");let z=parseInt(q.substring(0,2),10);if(isNaN(z.valueOf()))throw Error("Wrong input string for conversion");if(V=N*z,q.length===4){if(z=parseInt(q.substring(2,4),10),isNaN(z.valueOf()))throw Error("Wrong input string for conversion");U=N*z}}}let Q=G.indexOf(".");if(Q===-1)Q=G.indexOf(",");if(Q!==-1){let N=new Number(`0${G.substring(Q)}`);if(isNaN(N.valueOf()))throw Error("Wrong input string for conversion");J=N.valueOf(),X=G.substring(0,Q)}else X=G;switch(!0){case X.length===8:if(Z=/(\d{4})(\d{2})(\d{2})/ig,Q!==-1)throw Error("Wrong input string for conversion");break;case X.length===10:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=60*J;this.minute=Math.floor(N),N=60*(N-this.minute),this.second=Math.floor(N),N=1000*(N-this.second),this.millisecond=Math.floor(N)}break;case X.length===12:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=60*J;this.second=Math.floor(N),N=1000*(N-this.second),this.millisecond=Math.floor(N)}break;case X.length===14:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=1000*J;this.millisecond=Math.floor(N)}break;default:throw Error("Wrong input string for conversion")}let H=Z.exec(X);if(H===null)throw Error("Wrong input string for conversion");for(let N=1;N<H.length;N++)switch(N){case 1:this.year=parseInt(H[N],10);break;case 2:this.month=parseInt(H[N],10);break;case 3:this.day=parseInt(H[N],10);break;case 4:this.hour=parseInt(H[N],10)+V;break;case 5:this.minute=parseInt(H[N],10)+U;break;case 6:this.second=parseInt(H[N],10);break;default:throw Error("Wrong input string for conversion")}if(Y===!1){let N=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=N.getUTCFullYear(),this.month=N.getUTCMonth(),this.day=N.getUTCDay(),this.hour=N.getUTCHours(),this.minute=N.getUTCMinutes(),this.second=N.getUTCSeconds(),this.millisecond=N.getUTCMilliseconds()}}toString(W="iso"){if(W==="iso"){let Y=[];if(Y.push(b9(this.year,4)),Y.push(b9(this.month,2)),Y.push(b9(this.day,2)),Y.push(b9(this.hour,2)),Y.push(b9(this.minute,2)),Y.push(b9(this.second,2)),this.millisecond!==0)Y.push("."),Y.push(b9(this.millisecond,3));return Y.push("Z"),Y.join("")}return super.toString(W)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}OM=$G;(()=>{f0.GeneralizedTime=OM})();$G.NAME="GeneralizedTime";var KM;class rQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}KM=rQ;(()=>{f0.DATE=KM})();rQ.NAME="DATE";var DM;class aQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}DM=aQ;(()=>{f0.TimeOfDay=DM})();aQ.NAME="TimeOfDay";var CM;class sQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}CM=sQ;(()=>{f0.DateTime=CM})();sQ.NAME="DateTime";var TM;class tQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}TM=tQ;(()=>{f0.Duration=TM})();tQ.NAME="Duration";var RM;class eQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}RM=eQ;(()=>{f0.TIME=RM})();eQ.NAME="TIME";class V4{constructor({name:W=m9,optional:Y=!1}={}){this.name=W,this.optional=Y}}class nJ extends V4{constructor({value:W=[],...Y}={}){super(Y);this.value=W}}class zG extends V4{constructor({value:W=new V4,local:Y=!1,...G}={}){super(G);this.value=W,this.local=Y}}class MM{get data(){return this.dataView.slice().buffer}set data(W){this.dataView=_0.toUint8Array(W)}constructor({data:W=pQ}={}){this.dataView=_0.toUint8Array(W)}fromBER(W,Y,G){let X=Y+G;return this.dataView=_0.toUint8Array(W).subarray(Y,X),X}toBER(W){return this.dataView.slice().buffer}}function J4(W,Y,G){if(G instanceof nJ){for(let Z of G.value)if(J4(W,Y,Z).verified)return{verified:!0,result:W};{let Z={verified:!1,result:{error:"Wrong values for Choice type"}};if(G.hasOwnProperty(mI))Z.name=G.name;return Z}}if(G instanceof V4){if(G.hasOwnProperty(mI))W[G.name]=Y;return{verified:!0,result:W}}if(W instanceof Object===!1)return{verified:!1,result:{error:"Wrong root object"}};if(Y instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(G instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(Em in G===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(xm in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(km in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let X=G.idBlock.toBER(!1);if(X.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(G.idBlock.fromBER(X,0,X.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(G.idBlock.hasOwnProperty($m)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.tagClass!==Y.idBlock.tagClass)return{verified:!1,result:W};if(G.idBlock.hasOwnProperty(Fm)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.tagNumber!==Y.idBlock.tagNumber)return{verified:!1,result:W};if(G.idBlock.hasOwnProperty(Sm)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.isConstructed!==Y.idBlock.isConstructed)return{verified:!1,result:W};if(!(Bm in G.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.isHexOnly!==Y.idBlock.isHexOnly)return{verified:!1,result:W};if(G.idBlock.isHexOnly){if(hR in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let Z=G.idBlock.valueHexView,V=Y.idBlock.valueHexView;if(Z.length!==V.length)return{verified:!1,result:W};for(let U=0;U<Z.length;U++)if(Z[U]!==V[1])return{verified:!1,result:W}}if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)W[G.name]=Y}if(G instanceof f0.Constructed){let Z=0,V={verified:!1,result:{error:"Unknown error"}},U=G.valueBlock.value.length;if(U>0){if(G.valueBlock.value[0]instanceof zG)U=Y.valueBlock.value.length}if(U===0)return{verified:!0,result:W};if(Y.valueBlock.value.length===0&&G.valueBlock.value.length!==0){let Q=!0;for(let H=0;H<G.valueBlock.value.length;H++)Q=Q&&(G.valueBlock.value[H].optional||!1);if(Q)return{verified:!0,result:W};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return W.error="Inconsistent object length",{verified:!1,result:W}}for(let Q=0;Q<U;Q++)if(Q-Z>=Y.valueBlock.value.length){if(G.valueBlock.value[Q].optional===!1){let H={verified:!1,result:W};if(W.error="Inconsistent length between ASN.1 data and schema",G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],H.name=G.name}return H}}else if(G.valueBlock.value[0]instanceof zG){if(V=J4(W,Y.valueBlock.value[Q],G.valueBlock.value[0].value),V.verified===!1)if(G.valueBlock.value[0].optional)Z++;else{if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return V}if(mI in G.valueBlock.value[0]&&G.valueBlock.value[0].name.length>0){let H={};if(_m in G.valueBlock.value[0]&&G.valueBlock.value[0].local)H=Y;else H=W;if(typeof H[G.valueBlock.value[0].name]>"u")H[G.valueBlock.value[0].name]=[];H[G.valueBlock.value[0].name].push(Y.valueBlock.value[Q])}}else if(V=J4(W,Y.valueBlock.value[Q-Z],G.valueBlock.value[Q]),V.verified===!1)if(G.valueBlock.value[Q].optional)Z++;else{if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return V}if(V.verified===!1){let Q={verified:!1,result:W};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],Q.name=G.name}return Q}return{verified:!0,result:W}}if(G.primitiveSchema&&hR in Y.valueBlock){let Z=dQ(Y.valueBlock.valueHexView);if(Z.offset===-1){let V={verified:!1,result:Z.result};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],V.name=G.name}return V}return J4(W,Z.result,G.primitiveSchema)}return{verified:!0,result:W}}function lm(W,Y){if(Y instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let G=dQ(_0.toUint8Array(W));if(G.offset===-1)return{verified:!1,result:G.result};return J4(G.result,G.result,Y)}function PM(W){return Object.prototype.toString.call(W)}function dm(W){if(ArrayBuffer.isView(W))return!0;if(!W||typeof W!=="object")return!1;let Y=W;return typeof Y.byteOffset==="number"&&typeof Y.byteLength==="number"&&WH(Y.buffer)}function Jz(W){return PM(W)==="[object ArrayBuffer]"}function LM(W){return typeof SharedArrayBuffer<"u"&&PM(W)==="[object SharedArrayBuffer]"}function WH(W){return Jz(W)||LM(W)}function BM(W){return dm(W)}function H4(W){return WH(W)||BM(W)}function Zz(W){if(!H4(W))throw TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function C5(W){if(Zz(W),WH(W))return new Uint8Array(W);return new Uint8Array(W.buffer,W.byteOffset,W.byteLength)}function p8(W){if(Zz(W),Jz(W))return W;let Y=new ArrayBuffer(W.byteLength);return new Uint8Array(Y).set(C5(W)),Y}function Vz(W,Y,G={}){let X=C5(W),J=C5(Y);if(!G.constantTime&&X.byteLength!==J.byteLength)return!1;let Z=Math.max(X.byteLength,J.byteLength),V=X.byteLength^J.byteLength;for(let U=0;U<Z;U++)V|=(X[U]??0)^(J[U]??0);return V===0}var i;(function(W){W[W.Sequence=0]="Sequence",W[W.Set=1]="Set",W[W.Choice=2]="Choice"})(i||(i={}));var S;(function(W){W[W.Any=1]="Any",W[W.Boolean=2]="Boolean",W[W.OctetString=3]="OctetString",W[W.BitString=4]="BitString",W[W.Integer=5]="Integer",W[W.Enumerated=6]="Enumerated",W[W.ObjectIdentifier=7]="ObjectIdentifier",W[W.Utf8String=8]="Utf8String",W[W.BmpString=9]="BmpString",W[W.UniversalString=10]="UniversalString",W[W.NumericString=11]="NumericString",W[W.PrintableString=12]="PrintableString",W[W.TeletexString=13]="TeletexString",W[W.VideotexString=14]="VideotexString",W[W.IA5String=15]="IA5String",W[W.GraphicString=16]="GraphicString",W[W.VisibleString=17]="VisibleString",W[W.GeneralString=18]="GeneralString",W[W.CharacterString=19]="CharacterString",W[W.UTCTime=20]="UTCTime",W[W.GeneralizedTime=21]="GeneralizedTime",W[W.DATE=22]="DATE",W[W.TimeOfDay=23]="TimeOfDay",W[W.DateTime=24]="DateTime",W[W.Duration=25]="Duration",W[W.TIME=26]="TIME",W[W.Null=27]="Null"})(S||(S={}));class N4{unusedBits=0;value=new ArrayBuffer(0);constructor(W,Y=0){if(W)if(typeof W==="number")this.fromNumber(W);else if(H4(W))this.unusedBits=Y,this.value=p8(W);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(W){if(!(W instanceof R7))throw TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=W.valueBlock.unusedBits,this.value=p8(W.valueBlock.valueHex),this}toASN(){return new R7({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(W){return new R7({name:W})}toNumber(){let W="",Y=new Uint8Array(this.value);for(let G of Y)W+=G.toString(2).padStart(8,"0");if(W=W.split("").reverse().join(""),this.unusedBits)W=W.slice(this.unusedBits).padStart(this.unusedBits,"0");return parseInt(W,2)}fromNumber(W){let Y=W.toString(2),G=Y.length+7>>3;this.unusedBits=(G<<3)-Y.length;let X=new Uint8Array(G);Y=Y.padStart(G<<3,"0").split("").reverse().join("");let J=0;while(J<G)X[J]=parseInt(Y.slice(J<<3,(J<<3)+8),2),J++;this.value=X.buffer}}class J1{buffer;get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(W){if(typeof W==="number")this.buffer=new ArrayBuffer(W);else if(H4(W))this.buffer=p8(W);else if(Array.isArray(W))this.buffer=new Uint8Array(W).buffer;else this.buffer=new ArrayBuffer(0)}fromASN(W){if(!(W instanceof T7))throw TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=p8(W.valueBlock.valueHex),this}toASN(){return new T7({valueHex:this.buffer})}toSchema(W){return new T7({name:W})}}var im={fromASN:(W)=>W instanceof C7?null:p8(W.valueBeforeDecodeView),toASN:(W)=>{if(W===null)return new C7;let Y=Q4(W);if(Y.result.error)throw Error(Y.result.error);return Y.result}},rm={fromASN:(W)=>W.valueBlock.valueHexView.byteLength>=4?W.valueBlock.toString():W.valueBlock.valueDec,toASN:(W)=>new K6({value:+W})},am={fromASN:(W)=>W.valueBlock.valueDec,toASN:(W)=>new jG({value:W})},_1={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new K6({valueHex:W})};var sm={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new R7({valueHex:W})},tm={fromASN:(W)=>W.valueBlock.toString(),toASN:(W)=>new OG({value:W})},em={fromASN:(W)=>W.valueBlock.value,toASN:(W)=>new wG({value:W})},FG={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new T7({valueHex:W})},EM={fromASN:(W)=>new J1(W.getValue()),toASN:(W)=>W.toASN()};function T5(W){return{fromASN:(Y)=>Y.valueBlock.value,toASN:(Y)=>new W({value:Y})}}var Uz=T5(u5),Wf=T5(KG),Yf=T5(DG),Gf=T5(CG),Xf=T5(TG),Jf=T5(RG),Zf=T5(MG),Vf=T5(PG),Uf=T5(LG),Qf=T5(FW),Hf=T5(BG),Nf=T5(EG),qf={fromASN:(W)=>W.toDate(),toASN:(W)=>new SW({valueDate:W})},Af={fromASN:(W)=>W.toDate(),toASN:(W)=>new $G({valueDate:W})},If={fromASN:()=>null,toASN:()=>{return new C7}};function D6(W){switch(W){case S.Any:return im;case S.BitString:return sm;case S.BmpString:return Wf;case S.Boolean:return em;case S.CharacterString:return Nf;case S.Enumerated:return am;case S.GeneralString:return Hf;case S.GeneralizedTime:return Af;case S.GraphicString:return Uf;case S.IA5String:return Vf;case S.Integer:return rm;case S.Null:return If;case S.NumericString:return Gf;case S.ObjectIdentifier:return tm;case S.OctetString:return FG;case S.PrintableString:return Xf;case S.TeletexString:return Jf;case S.UTCTime:return qf;case S.UniversalString:return Yf;case S.Utf8String:return Uz;case S.VideotexString:return Zf;case S.VisibleString:return Qf;default:return null}}function R5(W){if(typeof W==="function"&&W.prototype)if(W.prototype.toASN&&W.prototype.fromASN)return!0;else return R5(W.prototype);else return!!(W&&typeof W==="object"&&("toASN"in W)&&("fromASN"in W))}function Hz(W){if(W){let Y=Object.getPrototypeOf(W);if(Y?.prototype?.constructor===Array)return!0;return Hz(Y)}return!1}function $M(W,Y){if(!(W&&Y))return!1;if(W.byteLength!==Y.byteLength)return!1;let G=new Uint8Array(W),X=new Uint8Array(Y);for(let J=0;J<W.byteLength;J++)if(G[J]!==X[J])return!1;return!0}class Nz{items=new WeakMap;has(W){return this.items.has(W)}get(W,Y=!1){let G=this.items.get(W);if(!G)throw Error(`Cannot get schema for '${W.prototype.constructor.name}' target`);if(Y&&!G.schema)throw Error(`Schema '${W.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return G}cache(W){let Y=this.get(W);if(!Y.schema)Y.schema=this.create(W,!0)}createDefault(W){let Y={type:i.Sequence,items:{}},G=this.findParentSchema(W);if(G)Object.assign(Y,G),Y.items=Object.assign({},Y.items,G.items);return Y}create(W,Y){let G=this.items.get(W)||this.createDefault(W),X=[];for(let J in G.items){let Z=G.items[J],V=Y?J:"",U;if(typeof Z.type==="number"){let H=S[Z.type],N=M7[H];if(!N)throw Error(`Cannot get ASN1 class by name '${H}'`);U=new N({name:V})}else if(R5(Z.type))U=new Z.type().toSchema(V);else if(Z.optional)if(this.get(Z.type).type===i.Choice)U=new V4({name:V});else U=this.create(Z.type,!1),U.name=V;else U=new V4({name:V});let Q=!!Z.optional||Z.defaultValue!==void 0;if(Z.repeated)U.name="",U=new(Z.repeated==="set"?f9:_9)({name:"",value:[new zG({name:V,value:U})]});if(Z.context!==null&&Z.context!==void 0)if(Z.implicit)if(typeof Z.type==="number"||R5(Z.type)){let H=Z.repeated?c8:O6;X.push(new H({name:V,optional:Q,idBlock:{tagClass:3,tagNumber:Z.context}}))}else{this.cache(Z.type);let H=!!Z.repeated,N=!H?this.get(Z.type,!0).schema:U;N="valueBlock"in N?N.valueBlock.value:N.value,X.push(new c8({name:!H?V:"",optional:Q,idBlock:{tagClass:3,tagNumber:Z.context},value:N}))}else X.push(new c8({optional:Q,idBlock:{tagClass:3,tagNumber:Z.context},value:[U]}));else U.optional=Q,X.push(U)}switch(G.type){case i.Sequence:return new _9({value:X,name:""});case i.Set:return new f9({value:X,name:""});case i.Choice:return new nJ({value:X,name:""});default:throw Error("Unsupported ASN1 type in use")}}set(W,Y){return this.items.set(W,Y),this}findParentSchema(W){let Y=Object.getPrototypeOf(W);if(Y)return this.items.get(Y)||this.findParentSchema(Y);return null}}var _8=new Nz;var G0=(W)=>(Y)=>{let G;if(!_8.has(Y))G=_8.createDefault(Y),_8.set(Y,G);else G=_8.get(Y);Object.assign(G,W)};var K=(W)=>(Y,G)=>{let X;if(!_8.has(Y.constructor))X=_8.createDefault(Y.constructor),_8.set(Y.constructor,X);else X=_8.get(Y.constructor);let J=Object.assign({},W);if(typeof J.type==="number"&&!J.converter){let Z=D6(W.type);if(!Z)throw Error(`Cannot get default converter for property '${G}' of ${Y.constructor.name}`);J.converter=Z}J.raw=W.raw,X.items[G]=J};class xW extends Error{schemas=[]}class YH{static parse(W,Y,G){let X=Q4(p8(W),G?.berOptions);if(X.result.error)throw Error(X.result.error);return this.fromASN(X.result,Y,G)}static fromASN(W,Y,G){try{if(R5(Y))return new Y().fromASN(W);let X=_8.get(Y);_8.cache(Y);let J=X.schema,Z=this.handleChoiceTypes(W,X,Y,J,G);if(Z?.result)return Z.result;if(Z?.targetSchema)J=Z.targetSchema;let V=this.handleSequenceTypes(W,X,Y,J),U=new Y;if(Hz(Y))return this.handleArrayTypes(W,X,Y,G);return this.processSchemaItems(X,V,U,G),U}catch(X){if(X instanceof xW)X.schemas.push(Y.name);throw X}}static handleChoiceTypes(W,Y,G,X,J){if(W.constructor===c8&&Y.type===i.Choice&&W.idBlock.tagClass===3)for(let Z in Y.items){let V=Y.items[Z];if(V.context===W.idBlock.tagNumber&&V.implicit){if(typeof V.type==="function"&&_8.has(V.type)){let U=_8.get(V.type);if(U&&U.type===i.Sequence){let Q=new _9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in Q.valueBlock){Q.valueBlock.value=W.valueBlock.value;let H=this.fromASN(Q,V.type,J),N=new G;return N[Z]=H,{result:N}}}}}}else if(W.constructor===c8&&Y.type!==i.Choice){let Z=new c8({idBlock:{tagClass:3,tagNumber:W.idBlock.tagNumber},value:Y.schema.valueBlock.value});for(let V in Y.items)delete W[V];return{targetSchema:Z}}return null}static handleSequenceTypes(W,Y,G,X){if(Y.type===i.Sequence){let J=J4({},W,X);if(!J.verified)throw new xW(`Data does not match to ${G.name} ASN1 schema.${J.result.error?` ${J.result.error}`:""}`);return J}else{let J=J4({},W,X);if(!J.verified)throw new xW(`Data does not match to ${G.name} ASN1 schema.${J.result.error?` ${J.result.error}`:""}`);return J}}static processRepeatedField(W,Y,G){let X=W.slice(Y);if(X.length===1&&X[0].constructor.name==="Sequence"){let J=X[0];if(J.valueBlock&&J.valueBlock.value&&Array.isArray(J.valueBlock.value))X=J.valueBlock.value}if(typeof G.type==="number"){let J=D6(G.type);if(!J)throw Error(`No converter for ASN.1 type ${G.type}`);return X.filter((Z)=>Z&&Z.valueBlock).map((Z)=>{try{return J.fromASN(Z)}catch{return}}).filter((Z)=>Z!==void 0)}else return X.filter((J)=>J&&J.valueBlock).map((J)=>{try{return this.fromASN(J,G.type)}catch{return}}).filter((J)=>J!==void 0)}static processPrimitiveField(W,Y){let G=D6(Y.type);if(!G)throw Error(`No converter for ASN.1 type ${Y.type}`);return G.fromASN(W)}static isOptionalChoiceField(W){return W.optional&&typeof W.type==="function"&&_8.has(W.type)&&_8.get(W.type).type===i.Choice}static processOptionalChoiceField(W,Y){try{return{processed:!0,value:this.fromASN(W,Y.type)}}catch(G){if(G instanceof xW&&/Wrong values for Choice type/.test(G.message))return{processed:!1};throw G}}static handleArrayTypes(W,Y,G,X){if(!(("value"in W.valueBlock)&&Array.isArray(W.valueBlock.value)))throw Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let J=Y.itemType;if(typeof J==="number"){let Z=D6(J);if(!Z)throw Error(`Cannot get default converter for array item of ${G.name} ASN1 schema`);return G.from(W.valueBlock.value,(V)=>Z.fromASN(V))}else return G.from(W.valueBlock.value,(Z)=>this.fromASN(Z,J,X))}static processSchemaItems(W,Y,G,X){for(let J in W.items){let Z=Y.result[J];if(!Z)continue;let V=W.items[J],U=V.type,Q;if(typeof U==="number"||R5(U))Q=this.processPrimitiveSchemaItem(Z,V,U,X);else Q=this.processComplexSchemaItem(Z,V,U,X);if(Q&&typeof Q==="object"&&"value"in Q&&"raw"in Q)G[J]=Q.value,G[`${J}Raw`]=Q.raw;else G[J]=Q}}static processPrimitiveSchemaItem(W,Y,G,X){let J=Y.converter??(R5(G)?new G:null);if(!J)throw Error("Converter is empty");if(Y.repeated)return this.processRepeatedPrimitiveItem(W,Y,J,X);else return this.processSinglePrimitiveItem(W,Y,G,J,X)}static processRepeatedPrimitiveItem(W,Y,G,X){if(Y.implicit){let Z=new(Y.repeated==="sequence"?_9:f9);Z.valueBlock=W.valueBlock;let V=Q4(Z.toBER(!1),X?.berOptions);if(V.offset===-1)throw Error(`Cannot parse the child item. ${V.result.error}`);if(!(("value"in V.result.valueBlock)&&Array.isArray(V.result.valueBlock.value)))throw Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let U=V.result.valueBlock.value;return Array.from(U,(Q)=>G.fromASN(Q))}else return Array.from(W,(J)=>G.fromASN(J))}static processSinglePrimitiveItem(W,Y,G,X,J){let Z=W;if(Y.implicit){let V;if(R5(G))V=new G().toSchema("");else{let U=S[G],Q=M7[U];if(!Q)throw Error(`Cannot get '${U}' class from asn1js module`);V=new Q}V.valueBlock=Z.valueBlock,Z=Q4(V.toBER(!1),J?.berOptions).result}return X.fromASN(Z)}static processComplexSchemaItem(W,Y,G,X){if(Y.repeated){if(!Array.isArray(W))throw Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(W,(J)=>this.fromASN(J,G,X))}else{let J=this.handleImplicitTagging(W,Y,G);if(this.isOptionalChoiceField(Y))try{return this.fromASN(J,G,X)}catch(Z){if(Z instanceof xW&&/Wrong values for Choice type/.test(Z.message))return;throw Z}else{let Z=this.fromASN(J,G,X);if(Y.raw)return{value:Z,raw:W.valueBeforeDecodeView};return Z}}}static handleImplicitTagging(W,Y,G){if(Y.implicit&&typeof Y.context==="number"){let X=_8.get(G);if(X.type===i.Sequence){let J=new _9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in J.valueBlock)return J.valueBlock.value=W.valueBlock.value,J}else if(X.type===i.Set){let J=new f9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in J.valueBlock)return J.valueBlock.value=W.valueBlock.value,J}}return W}}class iJ{static serialize(W){if(W instanceof k8)return W.toBER(!1);return this.toASN(W).toBER(!1)}static toASN(W){if(W&&typeof W==="object"&&R5(W))return W.toASN();if(!(W&&typeof W==="object"))throw TypeError("Parameter 1 should be type of Object.");let Y=W.constructor,G=_8.get(Y);_8.cache(Y);let X=[];if(G.itemType){if(!Array.isArray(W))throw TypeError("Parameter 1 should be type of Array.");if(typeof G.itemType==="number"){let Z=D6(G.itemType);if(!Z)throw Error(`Cannot get default converter for array item of ${Y.name} ASN1 schema`);X=W.map((V)=>Z.toASN(V))}else X=W.map((Z)=>this.toAsnItem({type:G.itemType},"[]",Y,Z))}else for(let Z in G.items){let V=G.items[Z],U=W[Z];if(U===void 0||V.defaultValue===U||typeof V.defaultValue==="object"&&typeof U==="object"&&$M(this.serialize(V.defaultValue),this.serialize(U)))continue;let Q=iJ.toAsnItem(V,Z,Y,U);if(typeof V.context==="number")if(V.implicit)if(!V.repeated&&(typeof V.type==="number"||R5(V.type))){let H={};H.valueHex=Q instanceof C7?p8(Q.valueBeforeDecodeView):Q.valueBlock.toBER(),X.push(new O6({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},...H}))}else X.push(new c8({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},value:Q.valueBlock.value}));else X.push(new c8({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},value:[Q]}));else if(V.repeated)X=X.concat(Q);else X.push(Q)}let J;switch(G.type){case i.Sequence:J=new _9({value:X});break;case i.Set:J=new f9({value:X});break;case i.Choice:if(!X[0])throw Error(`Schema '${Y.name}' has wrong data. Choice cannot be empty.`);J=X[0];break}return J}static toAsnItem(W,Y,G,X){let J;if(typeof W.type==="number"){let Z=W.converter;if(!Z)throw Error(`Property '${Y}' doesn't have converter for type ${S[W.type]} in schema '${G.name}'`);if(W.repeated){if(!Array.isArray(X))throw TypeError("Parameter 'objProp' should be type of Array.");let V=Array.from(X,(Q)=>Z.toASN(Q));J=new(W.repeated==="sequence"?_9:f9)({value:V})}else J=Z.toASN(X)}else if(W.repeated){if(!Array.isArray(X))throw TypeError("Parameter 'objProp' should be type of Array.");let Z=Array.from(X,(U)=>this.toASN(U));J=new(W.repeated==="sequence"?_9:f9)({value:Z})}else J=this.toASN(X);return J}}class W1 extends Array{constructor(W=[]){if(typeof W==="number")super(W);else{super();for(let Y of W)this.push(Y)}}}class E0{static serialize(W){return iJ.serialize(W)}static parse(W,Y,G){return YH.parse(W,Y,G)}static toString(W,Y){let G=H4(W)?p8(W):E0.serialize(W),X=Q4(G,Y?.berOptions);if(X.offset===-1)throw Error(`Cannot decode ASN.1 data. ${X.result.error}`);return X.result.toString()}}var JP=y1(XP(),1),{__extends:M10,__assign:P10,__rest:L10,__decorate:j,__param:B10,__esDecorate:E10,__runInitializers:$10,__propKey:F10,__setFunctionName:S10,__metadata:x10,__awaiter:k10,__generator:_10,__exportStar:y10,__createBinding:v10,__values:g10,__read:u10,__spread:h10,__spreadArrays:b10,__spreadArray:m10,__await:f10,__asyncGenerator:c10,__asyncDelegator:p10,__asyncValues:l10,__makeTemplateObject:d10,__importStar:o10,__importDefault:n10,__classPrivateFieldGet:R1,__classPrivateFieldSet:I8,__classPrivateFieldIn:i10,__addDisposableResource:r10,__disposeResources:a10,__rewriteRelativeImportExtension:s10}=JP.default;var xG={};NA(xG,{parse:()=>QP,normalize:()=>rJ,is:()=>UP,hex:()=>Lf,formats:()=>NP,format:()=>HP,encode:()=>Az,decode:()=>Iz});var wf=/^[0-9a-f]$/i,jf=[" ","\t",`
|
|
208
|
+
`)}`:`${Y} :`}}nR=c8;(()=>{f0.Constructed=nR})();c8.NAME="CONSTRUCTED";class oI extends e8{fromBER(W,Y,G){return Y}toBER(W){return K7}}oI.override="EndOfContentValueBlock";var iR;class oQ extends k8{constructor(W={}){super(W,oI);this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}iR=oQ;(()=>{f0.EndOfContent=iR})();oQ.NAME=lJ;var rR;class C7 extends k8{constructor(W={}){super(W,e8);this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(W,Y,G){if(this.lenBlock.length>0)this.warnings.push("Non-zero length of value block for Null type");if(!this.idBlock.error.length)this.blockLength+=this.idBlock.blockLength;if(!this.lenBlock.error.length)this.blockLength+=this.lenBlock.blockLength;if(this.blockLength+=G,Y+G>W.byteLength)return this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1;return Y+G}toBER(W,Y){let G=new ArrayBuffer(2);if(!W){let X=new Uint8Array(G);X[0]=5,X[1]=0}if(Y)Y.write(G);return G}onAsciiEncoding(){return`${this.constructor.NAME}`}}rR=C7;(()=>{f0.Null=rR})();C7.NAME="NULL";class nI extends D7(e8){get value(){for(let W of this.valueHexView)if(W>0)return!0;return!1}set value(W){this.valueHexView[0]=W?255:0}constructor({value:W,...Y}={}){super(Y);if(Y.valueHex)this.valueHexView=_0.toUint8Array(Y.valueHex);else this.valueHexView=new Uint8Array(1);if(W)this.value=W}fromBER(W,Y,G){let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;if(this.valueHexView=X.subarray(Y,Y+G),G>1)this.warnings.push("Boolean value encoded in more then 1 octet");return this.isHexOnly=!0,bI.call(this),this.blockLength=G,Y+G}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}nI.NAME="BooleanValueBlock";var aR;class wG extends k8{getValue(){return this.valueBlock.value}setValue(W){this.valueBlock.value=W}constructor(W={}){super(W,nI);this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}aR=wG;(()=>{f0.Boolean=aR})();wG.NAME="BOOLEAN";class iI extends D7(Z4){constructor({isConstructed:W=!1,...Y}={}){super(Y);this.isConstructed=W}fromBER(W,Y,G,X){let J=0;if(this.isConstructed){if(this.isHexOnly=!1,J=Z4.prototype.fromBER.call(this,W,Y,G,X),J===-1)return J;for(let Z=0;Z<this.value.length;Z++){let V=this.value[Z].constructor.NAME;if(V===lJ)if(this.isIndefiniteForm)break;else return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1;if(V!==mR)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,J=super.fromBER(W,Y,G),this.blockLength=G;return J}toBER(W,Y){if(this.isConstructed)return Z4.prototype.toBER.call(this,W,Y);return W?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}iI.NAME="OctetStringValueBlock";var rI;class T7 extends k8{constructor({idBlock:W={},lenBlock:Y={},...G}={}){var X,J;(X=G.isConstructed)!==null&&X!==void 0||(G.isConstructed=!!((J=G.value)===null||J===void 0?void 0:J.length));super({idBlock:{isConstructed:G.isConstructed,...W},lenBlock:{...Y,isIndefiniteForm:!!G.isIndefiniteForm},...G},iI);this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(W,Y,G,X){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,G===0){if(this.idBlock.error.length===0)this.blockLength+=this.idBlock.blockLength;if(this.lenBlock.error.length===0)this.blockLength+=this.lenBlock.blockLength;return Y}if(!this.valueBlock.isConstructed){let Z=(W instanceof ArrayBuffer?new Uint8Array(W):W).subarray(Y,Y+G);try{if(Z.byteLength){let V=X!==null&&X!==void 0?X:oJ(),U=dI(Z,0,Z.byteLength,V);if(U.offset!==-1&&U.offset===G)this.valueBlock.value=[U.result]}}catch{}}return super.fromBER(W,Y,G,X)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return c8.prototype.onAsciiEncoding.call(this);let W=this.constructor.NAME,Y=o0.ToHex(this.valueBlock.valueHexView);return`${W} : ${Y}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let W=[];for(let Y of this.valueBlock.value)if(Y instanceof rI)W.push(Y.valueBlock.valueHexView);return _0.concat(W)}}rI=T7;(()=>{f0.OctetString=rI})();T7.NAME=mR;class aI extends D7(Z4){constructor({unusedBits:W=0,isConstructed:Y=!1,...G}={}){super(G);this.unusedBits=W,this.isConstructed=Y,this.blockLength=this.valueHexView.byteLength}fromBER(W,Y,G,X){if(!G)return Y;let J=-1;if(this.isConstructed){if(J=Z4.prototype.fromBER.call(this,W,Y,G,X),J===-1)return J;for(let U of this.value){let Q=U.constructor.NAME;if(Q===lJ)if(this.isIndefiniteForm)break;else return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1;if(Q!==fR)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let H=U.valueBlock;if(this.unusedBits>0&&H.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=H.unusedBits}return J}let Z=_0.toUint8Array(W);if(!U4(this,Z,Y,G))return-1;let V=Z.subarray(Y,Y+G);if(this.unusedBits=V[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let U=V.subarray(1);try{if(U.byteLength){let Q=X!==null&&X!==void 0?X:oJ(),H=dI(U,0,U.byteLength,Q);if(H.offset!==-1&&H.offset===G-1)this.value=[H.result]}}catch{}}return this.valueHexView=V.subarray(1),this.blockLength=V.length,Y+G}toBER(W,Y){if(this.isConstructed)return Z4.prototype.toBER.call(this,W,Y);if(W)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){let X=new Uint8Array(1);return X[0]=0,X.buffer}let G=new Uint8Array(this.valueHexView.length+1);return G[0]=this.unusedBits,G.set(this.valueHexView,1),G.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}aI.NAME="BitStringValueBlock";var sR;class R7 extends k8{constructor({idBlock:W={},lenBlock:Y={},...G}={}){var X,J;(X=G.isConstructed)!==null&&X!==void 0||(G.isConstructed=!!((J=G.value)===null||J===void 0?void 0:J.length));super({idBlock:{isConstructed:G.isConstructed,...W},lenBlock:{...Y,isIndefiniteForm:!!G.isIndefiniteForm},...G},aI);this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(W,Y,G,X){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(W,Y,G,X)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return c8.prototype.onAsciiEncoding.call(this);else{let W=[],Y=this.valueBlock.valueHexView;for(let Z of Y)W.push(Z.toString(2).padStart(8,"0"));let G=W.join(""),X=this.constructor.NAME,J=G.substring(0,G.length-this.valueBlock.unusedBits);return`${X} : ${J}`}}}sR=R7;(()=>{f0.BitString=sR})();R7.NAME=fR;var tR;function cm(W,Y){let G=new Uint8Array([0]),X=new Uint8Array(W),J=new Uint8Array(Y),Z=X.slice(0),V=Z.length-1,U=J.slice(0),Q=U.length-1,H=0,N=Q<V?V:Q,A=0;for(let q=N;q>=0;q--,A++){switch(!0){case A<U.length:H=Z[V-A]+U[Q-A]+G[0];break;default:H=Z[V-A]+G[0]}switch(G[0]=H/10,!0){case A>=Z.length:Z=bQ(new Uint8Array([H%10]),Z);break;default:Z[V-A]=H%10}}if(G[0]>0)Z=bQ(G,Z);return Z}function bR(W){if(W>=cJ.length)for(let Y=cJ.length;Y<=W;Y++){let G=new Uint8Array([0]),X=cJ[Y-1].slice(0);for(let J=X.length-1;J>=0;J--){let Z=new Uint8Array([(X[J]<<1)+G[0]]);G[0]=Z[0]/10,X[J]=Z[0]%10}if(G[0]>0)X=bQ(G,X);cJ.push(X)}return cJ[W]}function pm(W,Y){let G=0,X=new Uint8Array(W),J=new Uint8Array(Y),Z=X.slice(0),V=Z.length-1,U=J.slice(0),Q=U.length-1,H,N=0;for(let A=Q;A>=0;A--,N++)switch(H=Z[V-N]-U[Q-N]-G,!0){case H<0:G=1,Z[V-N]=H+10;break;default:G=0,Z[V-N]=H}if(G>0)for(let A=V-Q+1;A>=0;A--,N++)if(H=Z[V-N]-G,H<0)G=1,Z[V-N]=H+10;else{G=0,Z[V-N]=H;break}return Z.slice()}class nQ extends D7(e8){setValueHex(){if(this.valueHexView.length>=4)this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0;else if(this.isHexOnly=!1,this.valueHexView.length>0)this._valueDec=bI.call(this)}constructor({value:W,...Y}={}){super(Y);if(this._valueDec=0,Y.valueHex)this.setValueHex();if(W!==void 0)this.valueDec=W}set valueDec(W){this._valueDec=W,this.isHexOnly=!1,this.valueHexView=new Uint8Array(vR(W))}get valueDec(){return this._valueDec}fromDER(W,Y,G,X=0){let J=this.fromBER(W,Y,G);if(J===-1)return J;let Z=this.valueHexView;if(Z[0]===0&&(Z[1]&128)!==0)this.valueHexView=Z.subarray(1);else if(X!==0){if(Z.length<X){if(X-Z.length>1)X=Z.length+1;this.valueHexView=Z.subarray(X-Z.length)}}return J}toDER(W=!1){let Y=this.valueHexView;switch(!0){case(Y[0]&128)!==0:{let G=new Uint8Array(this.valueHexView.length+1);G[0]=0,G.set(Y,1),this.valueHexView=G}break;case(Y[0]===0&&(Y[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(W)}fromBER(W,Y,G){let X=super.fromBER(W,Y,G);if(X===-1)return X;return this.setValueHex(),X}toBER(W){return W?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let W=this.valueHexView.length*8-1,Y=new Uint8Array(this.valueHexView.length*8/3),G=0,X,J=this.valueHexView,Z="",V=!1;for(let U=J.byteLength-1;U>=0;U--){X=J[U];for(let Q=0;Q<8;Q++){if((X&1)===1)switch(G){case W:Y=pm(bR(G),Y),Z="-";break;default:Y=cm(Y,bR(G))}G++,X>>=1}}for(let U=0;U<Y.length;U++){if(Y[U])V=!0;if(V)Z+=uR.charAt(Y[U])}if(V===!1)Z+=uR.charAt(0);return Z}}tR=nQ;nQ.NAME="IntegerValueBlock";(()=>{Object.defineProperty(tR.prototype,"valueHex",{set:function(W){this.valueHexView=new Uint8Array(W),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}})})();var pJ;class K6 extends k8{constructor(W={}){super(W,nQ);this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return mQ(),BigInt(this.valueBlock.toString())}static fromBigInt(W){mQ();let Y=BigInt(W),G=new dJ,X=Y.toString(16).replace(/^-/,""),J=new Uint8Array(o0.FromHex(X));if(Y<0){let V=new Uint8Array(J.length+(J[0]&128?1:0));V[0]|=128;let Q=BigInt(`0x${o0.ToHex(V)}`)+Y,H=_0.toUint8Array(o0.FromHex(Q.toString(16)));H[0]|=128,G.write(H)}else{if(J[0]&128)G.write(new Uint8Array([0]));G.write(J)}return new pJ({valueHex:G.final()})}convertToDER(){let W=new pJ({valueHex:this.valueBlock.valueHexView});return W.valueBlock.toDER(),W}convertFromDER(){return new pJ({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}pJ=K6;(()=>{f0.Integer=pJ})();K6.NAME="INTEGER";var eR;class jG extends K6{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}eR=jG;(()=>{f0.Enumerated=eR})();jG.NAME="ENUMERATED";class fQ extends D7(e8){constructor({valueDec:W=-1,isFirstSid:Y=!1,...G}={}){super(G);this.valueDec=W,this.isFirstSid=Y}fromBER(W,Y,G){if(!G)return Y;let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;let J=X.subarray(Y,Y+G);this.valueHexView=new Uint8Array(G);for(let V=0;V<G;V++)if(this.valueHexView[V]=J[V]&127,this.blockLength++,(J[V]&128)===0)break;let Z=new Uint8Array(this.blockLength);for(let V=0;V<this.blockLength;V++)Z[V]=this.valueHexView[V];if(this.valueHexView=Z,(J[this.blockLength-1]&128)!==0)return this.error="End of input reached before message was fully decoded",-1;if(this.valueHexView[0]===0)this.warnings.push("Needlessly long format of SID encoding");if(this.blockLength<=8)this.valueDec=$W(this.valueHexView,7);else this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only");return Y+this.blockLength}set valueBigInt(W){mQ();let Y=BigInt(W).toString(2);while(Y.length%7)Y="0"+Y;let G=new Uint8Array(Y.length/7);for(let X=0;X<G.length;X++)G[X]=parseInt(Y.slice(X*7,X*7+7),2)+(X+1<G.length?128:0);this.fromBER(G.buffer,0,G.length)}toBER(W){if(this.isHexOnly){if(W)return new ArrayBuffer(this.valueHexView.byteLength);let X=this.valueHexView,J=new Uint8Array(this.blockLength);for(let Z=0;Z<this.blockLength-1;Z++)J[Z]=X[Z]|128;return J[this.blockLength-1]=X[this.blockLength-1],J.buffer}let Y=w6(this.valueDec,7);if(Y.byteLength===0)return this.error="Error during encoding SID value",K7;let G=new Uint8Array(Y.byteLength);if(!W){let X=new Uint8Array(Y),J=Y.byteLength-1;for(let Z=0;Z<J;Z++)G[Z]=X[Z]|128;G[J]=X[J]}return G}toString(){let W="";if(this.isHexOnly)W=o0.ToHex(this.valueHexView);else if(this.isFirstSid){let Y=this.valueDec;if(this.valueDec<=39)W="0.";else if(this.valueDec<=79)W="1.",Y-=40;else W="2.",Y-=80;W+=Y.toString()}else W=this.valueDec.toString();return W}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}fQ.NAME="sidBlock";class sI extends e8{constructor({value:W=m9,...Y}={}){super(Y);if(this.value=[],W)this.fromString(W)}fromBER(W,Y,G){let X=Y;while(G>0){let J=new fQ;if(X=J.fromBER(W,X,G),X===-1)return this.blockLength=0,this.error=J.error,X;if(this.value.length===0)J.isFirstSid=!0;this.blockLength+=J.blockLength,G-=J.blockLength,this.value.push(J)}return X}toBER(W){let Y=[];for(let G=0;G<this.value.length;G++){let X=this.value[G].toBER(W);if(X.byteLength===0)return this.error=this.value[G].error,K7;Y.push(X)}return fI(Y)}fromString(W){this.value=[];let Y=0,G=0,X="",J=!1;do{if(G=W.indexOf(".",Y),G===-1)X=W.substring(Y);else X=W.substring(Y,G);if(Y=G+1,J){let Z=this.value[0],V=0;switch(Z.valueDec){case 0:break;case 1:V=40;break;case 2:V=80;break;default:this.value=[];return}let U=parseInt(X,10);if(isNaN(U))return;Z.valueDec=U+V,J=!1}else{let Z=new fQ;if(X>Number.MAX_SAFE_INTEGER){mQ();let V=BigInt(X);Z.valueBigInt=V}else if(Z.valueDec=parseInt(X,10),isNaN(Z.valueDec))return;if(!this.value.length)Z.isFirstSid=!0,J=!0;this.value.push(Z)}}while(G!==-1)}toString(){let W="",Y=!1;for(let G=0;G<this.value.length;G++){Y=this.value[G].isHexOnly;let X=this.value[G].toString();if(G!==0)W=`${W}.`;if(Y)if(X=`{${X}}`,this.value[G].isFirstSid)W=`2.{${X} - 80}`;else W+=X;else W+=X}return W}toJSON(){let W={...super.toJSON(),value:this.toString(),sidArray:[]};for(let Y=0;Y<this.value.length;Y++)W.sidArray.push(this.value[Y].toJSON());return W}}sI.NAME="ObjectIdentifierValueBlock";var WM;class OG extends k8{getValue(){return this.valueBlock.toString()}setValue(W){this.valueBlock.fromString(W)}constructor(W={}){super(W,sI);this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}WM=OG;(()=>{f0.ObjectIdentifier=WM})();OG.NAME="OBJECT IDENTIFIER";class cQ extends D7(j6){constructor({valueDec:W=0,...Y}={}){super(Y);this.valueDec=W}fromBER(W,Y,G){if(G===0)return Y;let X=_0.toUint8Array(W);if(!U4(this,X,Y,G))return-1;let J=X.subarray(Y,Y+G);this.valueHexView=new Uint8Array(G);for(let V=0;V<G;V++)if(this.valueHexView[V]=J[V]&127,this.blockLength++,(J[V]&128)===0)break;let Z=new Uint8Array(this.blockLength);for(let V=0;V<this.blockLength;V++)Z[V]=this.valueHexView[V];if(this.valueHexView=Z,(J[this.blockLength-1]&128)!==0)return this.error="End of input reached before message was fully decoded",-1;if(this.valueHexView[0]===0)this.warnings.push("Needlessly long format of SID encoding");if(this.blockLength<=8)this.valueDec=$W(this.valueHexView,7);else this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only");return Y+this.blockLength}toBER(W){if(this.isHexOnly){if(W)return new ArrayBuffer(this.valueHexView.byteLength);let X=this.valueHexView,J=new Uint8Array(this.blockLength);for(let Z=0;Z<this.blockLength-1;Z++)J[Z]=X[Z]|128;return J[this.blockLength-1]=X[this.blockLength-1],J.buffer}let Y=w6(this.valueDec,7);if(Y.byteLength===0)return this.error="Error during encoding SID value",K7;let G=new Uint8Array(Y.byteLength);if(!W){let X=new Uint8Array(Y),J=Y.byteLength-1;for(let Z=0;Z<J;Z++)G[Z]=X[Z]|128;G[J]=X[J]}return G.buffer}toString(){let W="";if(this.isHexOnly)W=o0.ToHex(this.valueHexView);else W=this.valueDec.toString();return W}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}cQ.NAME="relativeSidBlock";class tI extends e8{constructor({value:W=m9,...Y}={}){super(Y);if(this.value=[],W)this.fromString(W)}fromBER(W,Y,G){let X=Y;while(G>0){let J=new cQ;if(X=J.fromBER(W,X,G),X===-1)return this.blockLength=0,this.error=J.error,X;this.blockLength+=J.blockLength,G-=J.blockLength,this.value.push(J)}return X}toBER(W,Y){let G=[];for(let X=0;X<this.value.length;X++){let J=this.value[X].toBER(W);if(J.byteLength===0)return this.error=this.value[X].error,K7;G.push(J)}return fI(G)}fromString(W){this.value=[];let Y=0,G=0,X="";do{if(G=W.indexOf(".",Y),G===-1)X=W.substring(Y);else X=W.substring(Y,G);Y=G+1;let J=new cQ;if(J.valueDec=parseInt(X,10),isNaN(J.valueDec))return!0;this.value.push(J)}while(G!==-1);return!0}toString(){let W="",Y=!1;for(let G=0;G<this.value.length;G++){Y=this.value[G].isHexOnly;let X=this.value[G].toString();if(G!==0)W=`${W}.`;if(Y)X=`{${X}}`,W+=X;else W+=X}return W}toJSON(){let W={...super.toJSON(),value:this.toString(),sidArray:[]};for(let Y=0;Y<this.value.length;Y++)W.sidArray.push(this.value[Y].toJSON());return W}}tI.NAME="RelativeObjectIdentifierValueBlock";var YM;class iQ extends k8{getValue(){return this.valueBlock.toString()}setValue(W){this.valueBlock.fromString(W)}constructor(W={}){super(W,tI);this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}YM=iQ;(()=>{f0.RelativeObjectIdentifier=YM})();iQ.NAME="RelativeObjectIdentifier";var GM;class _9 extends c8{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}GM=_9;(()=>{f0.Sequence=GM})();_9.NAME="SEQUENCE";var XM;class f9 extends c8{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}XM=f9;(()=>{f0.Set=XM})();f9.NAME="SET";class eI extends D7(e8){constructor({...W}={}){super(W);this.isHexOnly=!0,this.value=m9}toJSON(){return{...super.toJSON(),value:this.value}}}eI.NAME="StringValueBlock";class Wz extends eI{}Wz.NAME="SimpleStringValueBlock";class c9 extends lQ{constructor({...W}={}){super(W,Wz)}fromBuffer(W){this.valueBlock.value=String.fromCharCode.apply(null,_0.toUint8Array(W))}fromString(W){let Y=W.length,G=this.valueBlock.valueHexView=new Uint8Array(Y);for(let X=0;X<Y;X++)G[X]=W.charCodeAt(X);this.valueBlock.value=W}}c9.NAME="SIMPLE STRING";class Yz extends c9{fromBuffer(W){this.valueBlock.valueHexView=_0.toUint8Array(W);try{this.valueBlock.value=o0.ToUtf8String(W)}catch(Y){this.warnings.push(`Error during "decodeURIComponent": ${Y}, using raw string`),this.valueBlock.value=o0.ToBinary(W)}}fromString(W){this.valueBlock.valueHexView=new Uint8Array(o0.FromUtf8String(W)),this.valueBlock.value=W}}Yz.NAME="Utf8StringValueBlock";var JM;class u5 extends Yz{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}JM=u5;(()=>{f0.Utf8String=JM})();u5.NAME="UTF8String";class Gz extends c9{fromBuffer(W){this.valueBlock.value=o0.ToUtf16String(W),this.valueBlock.valueHexView=_0.toUint8Array(W)}fromString(W){this.valueBlock.value=W,this.valueBlock.valueHexView=new Uint8Array(o0.FromUtf16String(W))}}Gz.NAME="BmpStringValueBlock";var ZM;class KG extends Gz{constructor({...W}={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}ZM=KG;(()=>{f0.BmpString=ZM})();KG.NAME="BMPString";class Xz extends c9{fromBuffer(W){let Y=ArrayBuffer.isView(W)?W.slice().buffer:W.slice(0),G=new Uint8Array(Y);for(let X=0;X<G.length;X+=4)G[X]=G[X+3],G[X+1]=G[X+2],G[X+2]=0,G[X+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(Y))}fromString(W){let Y=W.length,G=this.valueBlock.valueHexView=new Uint8Array(Y*4);for(let X=0;X<Y;X++){let J=w6(W.charCodeAt(X),8),Z=new Uint8Array(J);if(Z.length>4)continue;let V=4-Z.length;for(let U=Z.length-1;U>=0;U--)G[X*4+U+V]=Z[U]}this.valueBlock.value=W}}Xz.NAME="UniversalStringValueBlock";var VM;class DG extends Xz{constructor({...W}={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}VM=DG;(()=>{f0.UniversalString=VM})();DG.NAME="UniversalString";var UM;class CG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}UM=CG;(()=>{f0.NumericString=UM})();CG.NAME="NumericString";var QM;class TG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}QM=TG;(()=>{f0.PrintableString=QM})();TG.NAME="PrintableString";var HM;class RG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}HM=RG;(()=>{f0.TeletexString=HM})();RG.NAME="TeletexString";var NM;class MG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}NM=MG;(()=>{f0.VideotexString=NM})();MG.NAME="VideotexString";var qM;class PG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}qM=PG;(()=>{f0.IA5String=qM})();PG.NAME="IA5String";var AM;class LG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}AM=LG;(()=>{f0.GraphicString=AM})();LG.NAME="GraphicString";var IM;class FW extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}IM=FW;(()=>{f0.VisibleString=IM})();FW.NAME="VisibleString";var zM;class BG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}zM=BG;(()=>{f0.GeneralString=zM})();BG.NAME="GeneralString";var wM;class EG extends c9{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}wM=EG;(()=>{f0.CharacterString=wM})();EG.NAME="CharacterString";var jM;class SW extends FW{constructor({value:W,valueDate:Y,...G}={}){super(G);if(this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,W){this.fromString(W),this.valueBlock.valueHexView=new Uint8Array(W.length);for(let X=0;X<W.length;X++)this.valueBlock.valueHexView[X]=W.charCodeAt(X)}if(Y)this.fromDate(Y),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer());this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(W){this.fromString(String.fromCharCode.apply(null,_0.toUint8Array(W)))}toBuffer(){let W=this.toString(),Y=new ArrayBuffer(W.length),G=new Uint8Array(Y);for(let X=0;X<W.length;X++)G[X]=W.charCodeAt(X);return Y}fromDate(W){this.year=W.getUTCFullYear(),this.month=W.getUTCMonth()+1,this.day=W.getUTCDate(),this.hour=W.getUTCHours(),this.minute=W.getUTCMinutes(),this.second=W.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(W){let G=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(W);if(G===null){this.error="Wrong input string for conversion";return}let X=parseInt(G[1],10);if(X>=50)this.year=1900+X;else this.year=2000+X;this.month=parseInt(G[2],10),this.day=parseInt(G[3],10),this.hour=parseInt(G[4],10),this.minute=parseInt(G[5],10),this.second=parseInt(G[6],10)}toString(W="iso"){if(W==="iso"){let Y=[,,,,,,,];return Y[0]=b9(this.year<2000?this.year-1900:this.year-2000,2),Y[1]=b9(this.month,2),Y[2]=b9(this.day,2),Y[3]=b9(this.hour,2),Y[4]=b9(this.minute,2),Y[5]=b9(this.second,2),Y[6]="Z",Y.join("")}return super.toString(W)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}jM=SW;(()=>{f0.UTCTime=jM})();SW.NAME="UTCTime";var OM;class $G extends SW{constructor(W={}){var Y;super(W);(Y=this.millisecond)!==null&&Y!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(W){super.fromDate(W),this.millisecond=W.getUTCMilliseconds()}toDate(){let W=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(W)}fromString(W){let Y=!1,G="",X="",J=0,Z,V=0,U=0;if(W[W.length-1]==="Z")G=W.substring(0,W.length-1),Y=!0;else{let N=new Number(W[W.length-1]);if(isNaN(N.valueOf()))throw Error("Wrong input string for conversion");G=W}if(Y){if(G.indexOf("+")!==-1)throw Error("Wrong input string for conversion");if(G.indexOf("-")!==-1)throw Error("Wrong input string for conversion")}else{let N=1,A=G.indexOf("+"),q="";if(A===-1)A=G.indexOf("-"),N=-1;if(A!==-1){if(q=G.substring(A+1),G=G.substring(0,A),q.length!==2&&q.length!==4)throw Error("Wrong input string for conversion");let z=parseInt(q.substring(0,2),10);if(isNaN(z.valueOf()))throw Error("Wrong input string for conversion");if(V=N*z,q.length===4){if(z=parseInt(q.substring(2,4),10),isNaN(z.valueOf()))throw Error("Wrong input string for conversion");U=N*z}}}let Q=G.indexOf(".");if(Q===-1)Q=G.indexOf(",");if(Q!==-1){let N=new Number(`0${G.substring(Q)}`);if(isNaN(N.valueOf()))throw Error("Wrong input string for conversion");J=N.valueOf(),X=G.substring(0,Q)}else X=G;switch(!0){case X.length===8:if(Z=/(\d{4})(\d{2})(\d{2})/ig,Q!==-1)throw Error("Wrong input string for conversion");break;case X.length===10:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=60*J;this.minute=Math.floor(N),N=60*(N-this.minute),this.second=Math.floor(N),N=1000*(N-this.second),this.millisecond=Math.floor(N)}break;case X.length===12:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=60*J;this.second=Math.floor(N),N=1000*(N-this.second),this.millisecond=Math.floor(N)}break;case X.length===14:if(Z=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,Q!==-1){let N=1000*J;this.millisecond=Math.floor(N)}break;default:throw Error("Wrong input string for conversion")}let H=Z.exec(X);if(H===null)throw Error("Wrong input string for conversion");for(let N=1;N<H.length;N++)switch(N){case 1:this.year=parseInt(H[N],10);break;case 2:this.month=parseInt(H[N],10);break;case 3:this.day=parseInt(H[N],10);break;case 4:this.hour=parseInt(H[N],10)+V;break;case 5:this.minute=parseInt(H[N],10)+U;break;case 6:this.second=parseInt(H[N],10);break;default:throw Error("Wrong input string for conversion")}if(Y===!1){let N=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=N.getUTCFullYear(),this.month=N.getUTCMonth(),this.day=N.getUTCDay(),this.hour=N.getUTCHours(),this.minute=N.getUTCMinutes(),this.second=N.getUTCSeconds(),this.millisecond=N.getUTCMilliseconds()}}toString(W="iso"){if(W==="iso"){let Y=[];if(Y.push(b9(this.year,4)),Y.push(b9(this.month,2)),Y.push(b9(this.day,2)),Y.push(b9(this.hour,2)),Y.push(b9(this.minute,2)),Y.push(b9(this.second,2)),this.millisecond!==0)Y.push("."),Y.push(b9(this.millisecond,3));return Y.push("Z"),Y.join("")}return super.toString(W)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}OM=$G;(()=>{f0.GeneralizedTime=OM})();$G.NAME="GeneralizedTime";var KM;class rQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}KM=rQ;(()=>{f0.DATE=KM})();rQ.NAME="DATE";var DM;class aQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}DM=aQ;(()=>{f0.TimeOfDay=DM})();aQ.NAME="TimeOfDay";var CM;class sQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}CM=sQ;(()=>{f0.DateTime=CM})();sQ.NAME="DateTime";var TM;class tQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}TM=tQ;(()=>{f0.Duration=TM})();tQ.NAME="Duration";var RM;class eQ extends u5{constructor(W={}){super(W);this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}RM=eQ;(()=>{f0.TIME=RM})();eQ.NAME="TIME";class V4{constructor({name:W=m9,optional:Y=!1}={}){this.name=W,this.optional=Y}}class nJ extends V4{constructor({value:W=[],...Y}={}){super(Y);this.value=W}}class zG extends V4{constructor({value:W=new V4,local:Y=!1,...G}={}){super(G);this.value=W,this.local=Y}}class MM{get data(){return this.dataView.slice().buffer}set data(W){this.dataView=_0.toUint8Array(W)}constructor({data:W=pQ}={}){this.dataView=_0.toUint8Array(W)}fromBER(W,Y,G){let X=Y+G;return this.dataView=_0.toUint8Array(W).subarray(Y,X),X}toBER(W){return this.dataView.slice().buffer}}function J4(W,Y,G){if(G instanceof nJ){for(let Z of G.value)if(J4(W,Y,Z).verified)return{verified:!0,result:W};{let Z={verified:!1,result:{error:"Wrong values for Choice type"}};if(G.hasOwnProperty(mI))Z.name=G.name;return Z}}if(G instanceof V4){if(G.hasOwnProperty(mI))W[G.name]=Y;return{verified:!0,result:W}}if(W instanceof Object===!1)return{verified:!1,result:{error:"Wrong root object"}};if(Y instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(G instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(Em in G===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(xm in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(km in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let X=G.idBlock.toBER(!1);if(X.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(G.idBlock.fromBER(X,0,X.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(G.idBlock.hasOwnProperty($m)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.tagClass!==Y.idBlock.tagClass)return{verified:!1,result:W};if(G.idBlock.hasOwnProperty(Fm)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.tagNumber!==Y.idBlock.tagNumber)return{verified:!1,result:W};if(G.idBlock.hasOwnProperty(Sm)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.isConstructed!==Y.idBlock.isConstructed)return{verified:!1,result:W};if(!(Bm in G.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(G.idBlock.isHexOnly!==Y.idBlock.isHexOnly)return{verified:!1,result:W};if(G.idBlock.isHexOnly){if(hR in G.idBlock===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let Z=G.idBlock.valueHexView,V=Y.idBlock.valueHexView;if(Z.length!==V.length)return{verified:!1,result:W};for(let U=0;U<Z.length;U++)if(Z[U]!==V[1])return{verified:!1,result:W}}if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)W[G.name]=Y}if(G instanceof f0.Constructed){let Z=0,V={verified:!1,result:{error:"Unknown error"}},U=G.valueBlock.value.length;if(U>0){if(G.valueBlock.value[0]instanceof zG)U=Y.valueBlock.value.length}if(U===0)return{verified:!0,result:W};if(Y.valueBlock.value.length===0&&G.valueBlock.value.length!==0){let Q=!0;for(let H=0;H<G.valueBlock.value.length;H++)Q=Q&&(G.valueBlock.value[H].optional||!1);if(Q)return{verified:!0,result:W};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return W.error="Inconsistent object length",{verified:!1,result:W}}for(let Q=0;Q<U;Q++)if(Q-Z>=Y.valueBlock.value.length){if(G.valueBlock.value[Q].optional===!1){let H={verified:!1,result:W};if(W.error="Inconsistent length between ASN.1 data and schema",G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],H.name=G.name}return H}}else if(G.valueBlock.value[0]instanceof zG){if(V=J4(W,Y.valueBlock.value[Q],G.valueBlock.value[0].value),V.verified===!1)if(G.valueBlock.value[0].optional)Z++;else{if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return V}if(mI in G.valueBlock.value[0]&&G.valueBlock.value[0].name.length>0){let H={};if(_m in G.valueBlock.value[0]&&G.valueBlock.value[0].local)H=Y;else H=W;if(typeof H[G.valueBlock.value[0].name]>"u")H[G.valueBlock.value[0].name]=[];H[G.valueBlock.value[0].name].push(Y.valueBlock.value[Q])}}else if(V=J4(W,Y.valueBlock.value[Q-Z],G.valueBlock.value[Q]),V.verified===!1)if(G.valueBlock.value[Q].optional)Z++;else{if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name]}return V}if(V.verified===!1){let Q={verified:!1,result:W};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],Q.name=G.name}return Q}return{verified:!0,result:W}}if(G.primitiveSchema&&hR in Y.valueBlock){let Z=dQ(Y.valueBlock.valueHexView);if(Z.offset===-1){let V={verified:!1,result:Z.result};if(G.name){if(G.name=G.name.replace(/^\s+|\s+$/g,m9),G.name)delete W[G.name],V.name=G.name}return V}return J4(W,Z.result,G.primitiveSchema)}return{verified:!0,result:W}}function lm(W,Y){if(Y instanceof Object===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let G=dQ(_0.toUint8Array(W));if(G.offset===-1)return{verified:!1,result:G.result};return J4(G.result,G.result,Y)}function PM(W){return Object.prototype.toString.call(W)}function dm(W){if(ArrayBuffer.isView(W))return!0;if(!W||typeof W!=="object")return!1;let Y=W;return typeof Y.byteOffset==="number"&&typeof Y.byteLength==="number"&&WH(Y.buffer)}function Jz(W){return PM(W)==="[object ArrayBuffer]"}function LM(W){return typeof SharedArrayBuffer<"u"&&PM(W)==="[object SharedArrayBuffer]"}function WH(W){return Jz(W)||LM(W)}function BM(W){return dm(W)}function H4(W){return WH(W)||BM(W)}function Zz(W){if(!H4(W))throw TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function C5(W){if(Zz(W),WH(W))return new Uint8Array(W);return new Uint8Array(W.buffer,W.byteOffset,W.byteLength)}function p8(W){if(Zz(W),Jz(W))return W;let Y=new ArrayBuffer(W.byteLength);return new Uint8Array(Y).set(C5(W)),Y}function Vz(W,Y,G={}){let X=C5(W),J=C5(Y);if(!G.constantTime&&X.byteLength!==J.byteLength)return!1;let Z=Math.max(X.byteLength,J.byteLength),V=X.byteLength^J.byteLength;for(let U=0;U<Z;U++)V|=(X[U]??0)^(J[U]??0);return V===0}var i;(function(W){W[W.Sequence=0]="Sequence",W[W.Set=1]="Set",W[W.Choice=2]="Choice"})(i||(i={}));var S;(function(W){W[W.Any=1]="Any",W[W.Boolean=2]="Boolean",W[W.OctetString=3]="OctetString",W[W.BitString=4]="BitString",W[W.Integer=5]="Integer",W[W.Enumerated=6]="Enumerated",W[W.ObjectIdentifier=7]="ObjectIdentifier",W[W.Utf8String=8]="Utf8String",W[W.BmpString=9]="BmpString",W[W.UniversalString=10]="UniversalString",W[W.NumericString=11]="NumericString",W[W.PrintableString=12]="PrintableString",W[W.TeletexString=13]="TeletexString",W[W.VideotexString=14]="VideotexString",W[W.IA5String=15]="IA5String",W[W.GraphicString=16]="GraphicString",W[W.VisibleString=17]="VisibleString",W[W.GeneralString=18]="GeneralString",W[W.CharacterString=19]="CharacterString",W[W.UTCTime=20]="UTCTime",W[W.GeneralizedTime=21]="GeneralizedTime",W[W.DATE=22]="DATE",W[W.TimeOfDay=23]="TimeOfDay",W[W.DateTime=24]="DateTime",W[W.Duration=25]="Duration",W[W.TIME=26]="TIME",W[W.Null=27]="Null"})(S||(S={}));class N4{unusedBits=0;value=new ArrayBuffer(0);constructor(W,Y=0){if(W)if(typeof W==="number")this.fromNumber(W);else if(H4(W))this.unusedBits=Y,this.value=p8(W);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(W){if(!(W instanceof R7))throw TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=W.valueBlock.unusedBits,this.value=p8(W.valueBlock.valueHex),this}toASN(){return new R7({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(W){return new R7({name:W})}toNumber(){let W="",Y=new Uint8Array(this.value);for(let G of Y)W+=G.toString(2).padStart(8,"0");if(W=W.split("").reverse().join(""),this.unusedBits)W=W.slice(this.unusedBits).padStart(this.unusedBits,"0");return parseInt(W,2)}fromNumber(W){let Y=W.toString(2),G=Y.length+7>>3;this.unusedBits=(G<<3)-Y.length;let X=new Uint8Array(G);Y=Y.padStart(G<<3,"0").split("").reverse().join("");let J=0;while(J<G)X[J]=parseInt(Y.slice(J<<3,(J<<3)+8),2),J++;this.value=X.buffer}}class J1{buffer;get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(W){if(typeof W==="number")this.buffer=new ArrayBuffer(W);else if(H4(W))this.buffer=p8(W);else if(Array.isArray(W))this.buffer=new Uint8Array(W).buffer;else this.buffer=new ArrayBuffer(0)}fromASN(W){if(!(W instanceof T7))throw TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=p8(W.valueBlock.valueHex),this}toASN(){return new T7({valueHex:this.buffer})}toSchema(W){return new T7({name:W})}}var im={fromASN:(W)=>W instanceof C7?null:p8(W.valueBeforeDecodeView),toASN:(W)=>{if(W===null)return new C7;let Y=Q4(W);if(Y.result.error)throw Error(Y.result.error);return Y.result}},rm={fromASN:(W)=>W.valueBlock.valueHexView.byteLength>=4?W.valueBlock.toString():W.valueBlock.valueDec,toASN:(W)=>new K6({value:+W})},am={fromASN:(W)=>W.valueBlock.valueDec,toASN:(W)=>new jG({value:W})},_1={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new K6({valueHex:W})};var sm={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new R7({valueHex:W})},tm={fromASN:(W)=>W.valueBlock.toString(),toASN:(W)=>new OG({value:W})},em={fromASN:(W)=>W.valueBlock.value,toASN:(W)=>new wG({value:W})},FG={fromASN:(W)=>p8(W.valueBlock.valueHexView),toASN:(W)=>new T7({valueHex:W})},EM={fromASN:(W)=>new J1(W.getValue()),toASN:(W)=>W.toASN()};function T5(W){return{fromASN:(Y)=>Y.valueBlock.value,toASN:(Y)=>new W({value:Y})}}var Uz=T5(u5),Wf=T5(KG),Yf=T5(DG),Gf=T5(CG),Xf=T5(TG),Jf=T5(RG),Zf=T5(MG),Vf=T5(PG),Uf=T5(LG),Qf=T5(FW),Hf=T5(BG),Nf=T5(EG),qf={fromASN:(W)=>W.toDate(),toASN:(W)=>new SW({valueDate:W})},Af={fromASN:(W)=>W.toDate(),toASN:(W)=>new $G({valueDate:W})},If={fromASN:()=>null,toASN:()=>{return new C7}};function D6(W){switch(W){case S.Any:return im;case S.BitString:return sm;case S.BmpString:return Wf;case S.Boolean:return em;case S.CharacterString:return Nf;case S.Enumerated:return am;case S.GeneralString:return Hf;case S.GeneralizedTime:return Af;case S.GraphicString:return Uf;case S.IA5String:return Vf;case S.Integer:return rm;case S.Null:return If;case S.NumericString:return Gf;case S.ObjectIdentifier:return tm;case S.OctetString:return FG;case S.PrintableString:return Xf;case S.TeletexString:return Jf;case S.UTCTime:return qf;case S.UniversalString:return Yf;case S.Utf8String:return Uz;case S.VideotexString:return Zf;case S.VisibleString:return Qf;default:return null}}function R5(W){if(typeof W==="function"&&W.prototype)if(W.prototype.toASN&&W.prototype.fromASN)return!0;else return R5(W.prototype);else return!!(W&&typeof W==="object"&&("toASN"in W)&&("fromASN"in W))}function Hz(W){if(W){let Y=Object.getPrototypeOf(W);if(Y?.prototype?.constructor===Array)return!0;return Hz(Y)}return!1}function $M(W,Y){if(!(W&&Y))return!1;if(W.byteLength!==Y.byteLength)return!1;let G=new Uint8Array(W),X=new Uint8Array(Y);for(let J=0;J<W.byteLength;J++)if(G[J]!==X[J])return!1;return!0}class Nz{items=new WeakMap;has(W){return this.items.has(W)}get(W,Y=!1){let G=this.items.get(W);if(!G)throw Error(`Cannot get schema for '${W.prototype.constructor.name}' target`);if(Y&&!G.schema)throw Error(`Schema '${W.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return G}cache(W){let Y=this.get(W);if(!Y.schema)Y.schema=this.create(W,!0)}createDefault(W){let Y={type:i.Sequence,items:{}},G=this.findParentSchema(W);if(G)Object.assign(Y,G),Y.items=Object.assign({},Y.items,G.items);return Y}create(W,Y){let G=this.items.get(W)||this.createDefault(W),X=[];for(let J in G.items){let Z=G.items[J],V=Y?J:"",U;if(typeof Z.type==="number"){let H=S[Z.type],N=M7[H];if(!N)throw Error(`Cannot get ASN1 class by name '${H}'`);U=new N({name:V})}else if(R5(Z.type))U=new Z.type().toSchema(V);else if(Z.optional)if(this.get(Z.type).type===i.Choice)U=new V4({name:V});else U=this.create(Z.type,!1),U.name=V;else U=new V4({name:V});let Q=!!Z.optional||Z.defaultValue!==void 0;if(Z.repeated)U.name="",U=new(Z.repeated==="set"?f9:_9)({name:"",value:[new zG({name:V,value:U})]});if(Z.context!==null&&Z.context!==void 0)if(Z.implicit)if(typeof Z.type==="number"||R5(Z.type)){let H=Z.repeated?c8:O6;X.push(new H({name:V,optional:Q,idBlock:{tagClass:3,tagNumber:Z.context}}))}else{this.cache(Z.type);let H=!!Z.repeated,N=!H?this.get(Z.type,!0).schema:U;N="valueBlock"in N?N.valueBlock.value:N.value,X.push(new c8({name:!H?V:"",optional:Q,idBlock:{tagClass:3,tagNumber:Z.context},value:N}))}else X.push(new c8({optional:Q,idBlock:{tagClass:3,tagNumber:Z.context},value:[U]}));else U.optional=Q,X.push(U)}switch(G.type){case i.Sequence:return new _9({value:X,name:""});case i.Set:return new f9({value:X,name:""});case i.Choice:return new nJ({value:X,name:""});default:throw Error("Unsupported ASN1 type in use")}}set(W,Y){return this.items.set(W,Y),this}findParentSchema(W){let Y=Object.getPrototypeOf(W);if(Y)return this.items.get(Y)||this.findParentSchema(Y);return null}}var _8=new Nz;var G0=(W)=>(Y)=>{let G;if(!_8.has(Y))G=_8.createDefault(Y),_8.set(Y,G);else G=_8.get(Y);Object.assign(G,W)};var K=(W)=>(Y,G)=>{let X;if(!_8.has(Y.constructor))X=_8.createDefault(Y.constructor),_8.set(Y.constructor,X);else X=_8.get(Y.constructor);let J=Object.assign({},W);if(typeof J.type==="number"&&!J.converter){let Z=D6(W.type);if(!Z)throw Error(`Cannot get default converter for property '${G}' of ${Y.constructor.name}`);J.converter=Z}J.raw=W.raw,X.items[G]=J};class xW extends Error{schemas=[]}class YH{static parse(W,Y,G){let X=Q4(p8(W),G?.berOptions);if(X.result.error)throw Error(X.result.error);return this.fromASN(X.result,Y,G)}static fromASN(W,Y,G){try{if(R5(Y))return new Y().fromASN(W);let X=_8.get(Y);_8.cache(Y);let J=X.schema,Z=this.handleChoiceTypes(W,X,Y,J,G);if(Z?.result)return Z.result;if(Z?.targetSchema)J=Z.targetSchema;let V=this.handleSequenceTypes(W,X,Y,J),U=new Y;if(Hz(Y))return this.handleArrayTypes(W,X,Y,G);return this.processSchemaItems(X,V,U,G),U}catch(X){if(X instanceof xW)X.schemas.push(Y.name);throw X}}static handleChoiceTypes(W,Y,G,X,J){if(W.constructor===c8&&Y.type===i.Choice&&W.idBlock.tagClass===3)for(let Z in Y.items){let V=Y.items[Z];if(V.context===W.idBlock.tagNumber&&V.implicit){if(typeof V.type==="function"&&_8.has(V.type)){let U=_8.get(V.type);if(U&&U.type===i.Sequence){let Q=new _9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in Q.valueBlock){Q.valueBlock.value=W.valueBlock.value;let H=this.fromASN(Q,V.type,J),N=new G;return N[Z]=H,{result:N}}}}}}else if(W.constructor===c8&&Y.type!==i.Choice){let Z=new c8({idBlock:{tagClass:3,tagNumber:W.idBlock.tagNumber},value:Y.schema.valueBlock.value});for(let V in Y.items)delete W[V];return{targetSchema:Z}}return null}static handleSequenceTypes(W,Y,G,X){if(Y.type===i.Sequence){let J=J4({},W,X);if(!J.verified)throw new xW(`Data does not match to ${G.name} ASN1 schema.${J.result.error?` ${J.result.error}`:""}`);return J}else{let J=J4({},W,X);if(!J.verified)throw new xW(`Data does not match to ${G.name} ASN1 schema.${J.result.error?` ${J.result.error}`:""}`);return J}}static processRepeatedField(W,Y,G){let X=W.slice(Y);if(X.length===1&&X[0].constructor.name==="Sequence"){let J=X[0];if(J.valueBlock&&J.valueBlock.value&&Array.isArray(J.valueBlock.value))X=J.valueBlock.value}if(typeof G.type==="number"){let J=D6(G.type);if(!J)throw Error(`No converter for ASN.1 type ${G.type}`);return X.filter((Z)=>Z&&Z.valueBlock).map((Z)=>{try{return J.fromASN(Z)}catch{return}}).filter((Z)=>Z!==void 0)}else return X.filter((J)=>J&&J.valueBlock).map((J)=>{try{return this.fromASN(J,G.type)}catch{return}}).filter((J)=>J!==void 0)}static processPrimitiveField(W,Y){let G=D6(Y.type);if(!G)throw Error(`No converter for ASN.1 type ${Y.type}`);return G.fromASN(W)}static isOptionalChoiceField(W){return W.optional&&typeof W.type==="function"&&_8.has(W.type)&&_8.get(W.type).type===i.Choice}static processOptionalChoiceField(W,Y){try{return{processed:!0,value:this.fromASN(W,Y.type)}}catch(G){if(G instanceof xW&&/Wrong values for Choice type/.test(G.message))return{processed:!1};throw G}}static handleArrayTypes(W,Y,G,X){if(!(("value"in W.valueBlock)&&Array.isArray(W.valueBlock.value)))throw Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let J=Y.itemType;if(typeof J==="number"){let Z=D6(J);if(!Z)throw Error(`Cannot get default converter for array item of ${G.name} ASN1 schema`);return G.from(W.valueBlock.value,(V)=>Z.fromASN(V))}else return G.from(W.valueBlock.value,(Z)=>this.fromASN(Z,J,X))}static processSchemaItems(W,Y,G,X){for(let J in W.items){let Z=Y.result[J];if(!Z)continue;let V=W.items[J],U=V.type,Q;if(typeof U==="number"||R5(U))Q=this.processPrimitiveSchemaItem(Z,V,U,X);else Q=this.processComplexSchemaItem(Z,V,U,X);if(Q&&typeof Q==="object"&&"value"in Q&&"raw"in Q)G[J]=Q.value,G[`${J}Raw`]=Q.raw;else G[J]=Q}}static processPrimitiveSchemaItem(W,Y,G,X){let J=Y.converter??(R5(G)?new G:null);if(!J)throw Error("Converter is empty");if(Y.repeated)return this.processRepeatedPrimitiveItem(W,Y,J,X);else return this.processSinglePrimitiveItem(W,Y,G,J,X)}static processRepeatedPrimitiveItem(W,Y,G,X){if(Y.implicit){let Z=new(Y.repeated==="sequence"?_9:f9);Z.valueBlock=W.valueBlock;let V=Q4(Z.toBER(!1),X?.berOptions);if(V.offset===-1)throw Error(`Cannot parse the child item. ${V.result.error}`);if(!(("value"in V.result.valueBlock)&&Array.isArray(V.result.valueBlock.value)))throw Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let U=V.result.valueBlock.value;return Array.from(U,(Q)=>G.fromASN(Q))}else return Array.from(W,(J)=>G.fromASN(J))}static processSinglePrimitiveItem(W,Y,G,X,J){let Z=W;if(Y.implicit){let V;if(R5(G))V=new G().toSchema("");else{let U=S[G],Q=M7[U];if(!Q)throw Error(`Cannot get '${U}' class from asn1js module`);V=new Q}V.valueBlock=Z.valueBlock,Z=Q4(V.toBER(!1),J?.berOptions).result}return X.fromASN(Z)}static processComplexSchemaItem(W,Y,G,X){if(Y.repeated){if(!Array.isArray(W))throw Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(W,(J)=>this.fromASN(J,G,X))}else{let J=this.handleImplicitTagging(W,Y,G);if(this.isOptionalChoiceField(Y))try{return this.fromASN(J,G,X)}catch(Z){if(Z instanceof xW&&/Wrong values for Choice type/.test(Z.message))return;throw Z}else{let Z=this.fromASN(J,G,X);if(Y.raw)return{value:Z,raw:W.valueBeforeDecodeView};return Z}}}static handleImplicitTagging(W,Y,G){if(Y.implicit&&typeof Y.context==="number"){let X=_8.get(G);if(X.type===i.Sequence){let J=new _9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in J.valueBlock)return J.valueBlock.value=W.valueBlock.value,J}else if(X.type===i.Set){let J=new f9;if("value"in W.valueBlock&&Array.isArray(W.valueBlock.value)&&"value"in J.valueBlock)return J.valueBlock.value=W.valueBlock.value,J}}return W}}class iJ{static serialize(W){if(W instanceof k8)return W.toBER(!1);return this.toASN(W).toBER(!1)}static toASN(W){if(W&&typeof W==="object"&&R5(W))return W.toASN();if(!(W&&typeof W==="object"))throw TypeError("Parameter 1 should be type of Object.");let Y=W.constructor,G=_8.get(Y);_8.cache(Y);let X=[];if(G.itemType){if(!Array.isArray(W))throw TypeError("Parameter 1 should be type of Array.");if(typeof G.itemType==="number"){let Z=D6(G.itemType);if(!Z)throw Error(`Cannot get default converter for array item of ${Y.name} ASN1 schema`);X=W.map((V)=>Z.toASN(V))}else X=W.map((Z)=>this.toAsnItem({type:G.itemType},"[]",Y,Z))}else for(let Z in G.items){let V=G.items[Z],U=W[Z];if(U===void 0||V.defaultValue===U||typeof V.defaultValue==="object"&&typeof U==="object"&&$M(this.serialize(V.defaultValue),this.serialize(U)))continue;let Q=iJ.toAsnItem(V,Z,Y,U);if(typeof V.context==="number")if(V.implicit)if(!V.repeated&&(typeof V.type==="number"||R5(V.type))){let H={};H.valueHex=Q instanceof C7?p8(Q.valueBeforeDecodeView):Q.valueBlock.toBER(),X.push(new O6({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},...H}))}else X.push(new c8({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},value:Q.valueBlock.value}));else X.push(new c8({optional:V.optional,idBlock:{tagClass:3,tagNumber:V.context},value:[Q]}));else if(V.repeated)X=X.concat(Q);else X.push(Q)}let J;switch(G.type){case i.Sequence:J=new _9({value:X});break;case i.Set:J=new f9({value:X});break;case i.Choice:if(!X[0])throw Error(`Schema '${Y.name}' has wrong data. Choice cannot be empty.`);J=X[0];break}return J}static toAsnItem(W,Y,G,X){let J;if(typeof W.type==="number"){let Z=W.converter;if(!Z)throw Error(`Property '${Y}' doesn't have converter for type ${S[W.type]} in schema '${G.name}'`);if(W.repeated){if(!Array.isArray(X))throw TypeError("Parameter 'objProp' should be type of Array.");let V=Array.from(X,(Q)=>Z.toASN(Q));J=new(W.repeated==="sequence"?_9:f9)({value:V})}else J=Z.toASN(X)}else if(W.repeated){if(!Array.isArray(X))throw TypeError("Parameter 'objProp' should be type of Array.");let Z=Array.from(X,(U)=>this.toASN(U));J=new(W.repeated==="sequence"?_9:f9)({value:Z})}else J=this.toASN(X);return J}}class W1 extends Array{constructor(W=[]){if(typeof W==="number")super(W);else{super();for(let Y of W)this.push(Y)}}}class E0{static serialize(W){return iJ.serialize(W)}static parse(W,Y,G){return YH.parse(W,Y,G)}static toString(W,Y){let G=H4(W)?p8(W):E0.serialize(W),X=Q4(G,Y?.berOptions);if(X.offset===-1)throw Error(`Cannot decode ASN.1 data. ${X.result.error}`);return X.result.toString()}}var JP=v1(XP(),1),{__extends:M10,__assign:P10,__rest:L10,__decorate:j,__param:B10,__esDecorate:E10,__runInitializers:$10,__propKey:F10,__setFunctionName:S10,__metadata:x10,__awaiter:k10,__generator:_10,__exportStar:y10,__createBinding:v10,__values:g10,__read:u10,__spread:h10,__spreadArrays:b10,__spreadArray:m10,__await:f10,__asyncGenerator:c10,__asyncDelegator:p10,__asyncValues:l10,__makeTemplateObject:d10,__importStar:o10,__importDefault:n10,__classPrivateFieldGet:R1,__classPrivateFieldSet:I8,__classPrivateFieldIn:i10,__addDisposableResource:r10,__disposeResources:a10,__rewriteRelativeImportExtension:s10}=JP.default;var xG={};NA(xG,{parse:()=>QP,normalize:()=>rJ,is:()=>UP,hex:()=>Lf,formats:()=>NP,format:()=>HP,encode:()=>Az,decode:()=>Iz});var wf=/^[0-9a-f]$/i,jf=[" ","\t",`
|
|
209
209
|
`,"\r",":","-","."];function Of(W){if(W.separators==="none")return[];if(!W.separators||W.separators==="common")return jf;return W.separators}function Kf(W){if(!W)throw TypeError("Hex separators must be non-empty strings")}function Df(W,Y,G){for(let X of G)if(W.startsWith(X,Y))return X;return}function Cf(W){let Y=/[A-F]/.test(W),G=/[a-f]/.test(W);return Y&&!G?"upper":"lower"}function Tf(W){let Y=/\r\n|\n/.exec(W);if(!Y)return;return Y[0]===`\r
|
|
210
210
|
`?`\r
|
|
211
211
|
`:`
|
|
212
212
|
`}function ZP(W){return W.replace(/[^0-9a-f]/gi,"")}function Rf(W){let Y=W.match(/[0-9A-Fa-f]+|[^0-9A-Fa-f]+/g)??[];if(Y.length<3)return;let G=Y.filter((V,U)=>U%2===0),X=Y.filter((V,U)=>U%2===1),J=X[0];if(!J||X.some((V)=>V!==J))return;if(G.some((V)=>V.length===0||V.length%2!==0))return;let Z=G[0]?.length??0;if(!Z)return;if(G.slice(0,-1).some((V)=>V.length!==Z))return;if((G[G.length-1]?.length??0)>Z)return;return{size:Z/2,separator:J}}function Mf(W){let Y=W.trim(),G=/^0x/i.test(Y)?"0x":"",X=G?Y.slice(2):Y,J=Tf(X),Z=X.split(/\r\n|\n/).filter((H)=>H.length>0),V=Z[0]?.trim()??"",U=Rf(V),Q={case:Cf(Y),prefix:G};if(U)Q.group=U;if(J&&Z.length>1){let H=ZP(Z[0]??"").length/2;if(H>0&&Z.slice(0,-1).every((N)=>ZP(N).length/2===H))Q.line={bytesPerLine:H,separator:J}}return Q}function Pf(W,Y){let G=Y.allowPrefix??!0,X=[...Of(Y)].sort((U,Q)=>Q.length-U.length);for(let U of X)Kf(U);let J=W.trim();if(/^0x/i.test(J)){if(!G)throw TypeError("Hexadecimal text must not include a 0x prefix");J=J.slice(2)}let Z="",V=!1;for(let U=0;U<J.length;){let Q=J[U]??"";if(wf.test(Q)){Z+=Q,V=!1,U+=1;continue}let H=Df(J,U,X);if(!H)throw TypeError("Input is not valid hexadecimal text");if(Y.strict&&(V||Z.length===0))throw TypeError("Hexadecimal text contains misplaced separators");V=!0,U+=H.length}if(Y.strict&&V&&Z.length>0)throw TypeError("Hexadecimal text must not end with a separator");if(Z.length%2!==0){if(!Y.allowOddLength)throw TypeError("Hexadecimal text must contain an even number of characters");Z=`0${Z}`}return Z.toLowerCase()}function VP(W,Y){if(!Y)return W.join("");if(!Number.isInteger(Y.size)||Y.size<1)throw RangeError("Hex group size must be a positive integer");let G=[];for(let X=0;X<W.length;X+=Y.size)G.push(W.slice(X,X+Y.size).join(""));return G.join(Y.separator)}function rJ(W,Y={}){return Pf(W,Y)}function UP(W,Y={}){if(typeof W!=="string")return!1;try{return rJ(W,Y),!0}catch{return!1}}function Az(W,Y={}){let G=C5(W),X=Y.case??"lower",J=Array.from(G,(V)=>{let U=V.toString(16).padStart(2,"0");return X==="upper"?U.toUpperCase():U}),Z="";if(Y.line){let V=Y.line.bytesPerLine;if(!Number.isInteger(V)||V<1)throw RangeError("Hex bytesPerLine must be a positive integer");let U=Y.line.separator??`
|
|
213
|
-
`,Q=[];for(let H=0;H<J.length;H+=V)Q.push(VP(J.slice(H,H+V),Y.group));Z=Q.join(U)}else Z=VP(J,Y.group);return`${Y.prefix??""}${Z}`}function Iz(W,Y={}){let G=rJ(W,Y),X=new Uint8Array(G.length/2);for(let J=0;J<G.length;J+=2)X[J/2]=Number.parseInt(G.slice(J,J+2),16);return X}function QP(W,Y={}){let G=rJ(W,Y);return{bytes:Iz(G),format:Mf(W),normalized:G}}function HP(W,Y){return Az(W,Y)}var NP={compact:Object.freeze({}),upper:Object.freeze({case:"upper"}),colon:Object.freeze({group:{size:1,separator:":"}}),colonUpper:Object.freeze({case:"upper",group:{size:1,separator:":"}}),groupsOf4:Object.freeze({group:{size:4,separator:" "}}),prefixed:Object.freeze({prefix:"0x"})},Lf={encode:Az,decode:Iz,format:HP,formats:NP,is:UP,normalize:rJ,parse:QP};class ZH{static isIPv4(W){return/^(\d{1,3}\.){3}\d{1,3}$/.test(W)}static parseIPv4(W){let Y=W.split(".");if(Y.length!==4)throw Error("Invalid IPv4 address");return Y.map((G)=>{let X=parseInt(G,10);if(isNaN(X)||X<0||X>255)throw Error("Invalid IPv4 address part");return X})}static parseIPv6(W){let G=this.expandIPv6(W).split(":");if(G.length!==8)throw Error("Invalid IPv6 address");return G.reduce((X,J)=>{let Z=parseInt(J,16);if(isNaN(Z)||Z<0||Z>65535)throw Error("Invalid IPv6 address part");return X.push(Z>>8&255),X.push(Z&255),X},[])}static expandIPv6(W){if(!W.includes("::"))return W;let Y=W.split("::");if(Y.length>2)throw Error("Invalid IPv6 address");let G=Y[0]?Y[0].split(":"):[],X=Y[1]?Y[1].split(":"):[],J=8-(G.length+X.length);if(J<0)throw Error("Invalid IPv6 address");return[...G,...Array(J).fill("0"),...X].join(":")}static formatIPv6(W){let Y=[];for(let G=0;G<16;G+=2)Y.push((W[G]<<8|W[G+1]).toString(16));return this.compressIPv6(Y.join(":"))}static compressIPv6(W){let Y=W.split(":"),G=-1,X=0,J=-1,Z=0;for(let V=0;V<Y.length;V++)if(Y[V]==="0"){if(J===-1)J=V;Z++}else{if(Z>X)G=J,X=Z;J=-1,Z=0}if(Z>X)G=J,X=Z;if(X>1){let V=Y.slice(0,G).join(":"),U=Y.slice(G+X).join(":");return`${V}::${U}`}return W}static parseCIDR(W){let[Y,G]=W.split("/"),X=parseInt(G,10);if(this.isIPv4(Y)){if(X<0||X>32)throw Error("Invalid IPv4 prefix length");return[this.parseIPv4(Y),X]}else{if(X<0||X>128)throw Error("Invalid IPv6 prefix length");return[this.parseIPv6(Y),X]}}static decodeIP(W){if(W.length===64&&parseInt(W,16)===0)return"::/0";if(W.length!==16)return W;let Y=parseInt(W.slice(8),16).toString(2).split("").reduce((X,J)=>X+ +J,0),G=W.slice(0,8).replace(/(.{2})/g,(X)=>`${parseInt(X,16)}.`);return G=G.slice(0,-1),`${G}/${Y}`}static toString(W){let Y=new Uint8Array(W);if(Y.length===4)return Array.from(Y).join(".");if(Y.length===16)return this.formatIPv6(Y);if(Y.length===8||Y.length===32){let G=Y.length/2,X=Y.slice(0,G),J=Y.slice(G);if(Y.every((U)=>U===0))return Y.length===8?"0.0.0.0/0":"::/0";let V=J.reduce((U,Q)=>U+(Q.toString(2).match(/1/g)||[]).length,0);if(Y.length===8)return`${Array.from(X).join(".")}/${V}`;else return`${this.formatIPv6(X)}/${V}`}return this.decodeIP(xG.encode(W))}static fromString(W){if(W.includes("/")){let[G,X]=this.parseCIDR(W),J=new Uint8Array(G.length),Z=X;for(let U=0;U<J.length;U++)if(Z>=8)J[U]=255,Z-=8;else if(Z>0)J[U]=255<<8-Z,Z=0;let V=new Uint8Array(G.length*2);return V.set(G,0),V.set(J,G.length),V.buffer}let Y=this.isIPv4(W)?this.parseIPv4(W):this.parseIPv6(W);return new Uint8Array(Y).buffer}}var zz,wz,jz,y8=class{teletexString;printableString;universalString;utf8String;bmpString;constructor(Y={}){Object.assign(this,Y)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};j([K({type:S.TeletexString})],y8.prototype,"teletexString",void 0);j([K({type:S.PrintableString})],y8.prototype,"printableString",void 0);j([K({type:S.UniversalString})],y8.prototype,"universalString",void 0);j([K({type:S.Utf8String})],y8.prototype,"utf8String",void 0);j([K({type:S.BmpString})],y8.prototype,"bmpString",void 0);y8=j([G0({type:i.Choice})],y8);var kG=class extends y8{ia5String;anyValue;constructor(Y={}){super(Y);Object.assign(this,Y)}toString(){return this.ia5String||(this.anyValue?xG.encode(this.anyValue):super.toString())}};j([K({type:S.IA5String})],kG.prototype,"ia5String",void 0);j([K({type:S.Any})],kG.prototype,"anyValue",void 0);kG=j([G0({type:i.Choice})],kG);class _G{type="";value=new kG;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],_G.prototype,"type",void 0);j([K({type:kG})],_G.prototype,"value",void 0);var C6=zz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,zz.prototype)}};C6=zz=j([G0({type:i.Set,itemType:_G})],C6);var Oz=wz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,wz.prototype)}};Oz=wz=j([G0({type:i.Sequence,itemType:C6})],Oz);var G8=jz=class extends Oz{constructor(Y){super(Y);Object.setPrototypeOf(this,jz.prototype)}};G8=jz=j([G0({type:i.Sequence})],G8);var Sf={fromASN:(W)=>ZH.toString(FG.fromASN(W)),toASN:(W)=>FG.toASN(ZH.fromString(W))};class kW{typeId="";value=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],kW.prototype,"typeId",void 0);j([K({type:S.Any,context:0})],kW.prototype,"value",void 0);class VH{nameAssigner;partyName=new y8;constructor(W={}){Object.assign(this,W)}}j([K({type:y8,optional:!0,context:0,implicit:!0})],VH.prototype,"nameAssigner",void 0);j([K({type:y8,context:1,implicit:!0})],VH.prototype,"partyName",void 0);var Q1=class{otherName;rfc822Name;dNSName;x400Address;directoryName;ediPartyName;uniformResourceIdentifier;iPAddress;registeredID;constructor(Y={}){Object.assign(this,Y)}};j([K({type:kW,context:0,implicit:!0})],Q1.prototype,"otherName",void 0);j([K({type:S.IA5String,context:1,implicit:!0})],Q1.prototype,"rfc822Name",void 0);j([K({type:S.IA5String,context:2,implicit:!0})],Q1.prototype,"dNSName",void 0);j([K({type:S.Any,context:3,implicit:!0})],Q1.prototype,"x400Address",void 0);j([K({type:G8,context:4,implicit:!1})],Q1.prototype,"directoryName",void 0);j([K({type:VH,context:5})],Q1.prototype,"ediPartyName",void 0);j([K({type:S.IA5String,context:6,implicit:!0})],Q1.prototype,"uniformResourceIdentifier",void 0);j([K({type:S.OctetString,context:7,implicit:!0,converter:Sf})],Q1.prototype,"iPAddress",void 0);j([K({type:S.ObjectIdentifier,context:8,implicit:!0})],Q1.prototype,"registeredID",void 0);Q1=j([G0({type:i.Choice})],Q1);var UH="1.3.6.1.5.5.7",T6="1.3.6.1.5.5.7.1";var _W="1.3.6.1.5.5.7.3";var Kz="1.3.6.1.5.5.7.48.1",Dz="1.3.6.1.5.5.7.48.2",Cz="1.3.6.1.5.5.7.48.3",Tz="1.3.6.1.5.5.7.48.5",j1="2.5.29";var Rz,QH=`${T6}.1`;class R6{accessMethod="";accessLocation=new Q1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],R6.prototype,"accessMethod",void 0);j([K({type:Q1})],R6.prototype,"accessLocation",void 0);var yW=Rz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Rz.prototype)}};yW=Rz=j([G0({type:i.Sequence,itemType:R6})],yW);var HH=`${j1}.35`;class yG extends J1{}class q4{keyIdentifier;authorityCertIssuer;authorityCertSerialNumber;constructor(W={}){if(W)Object.assign(this,W)}}j([K({type:yG,context:0,optional:!0,implicit:!0})],q4.prototype,"keyIdentifier",void 0);j([K({type:Q1,context:1,optional:!0,implicit:!0,repeated:"sequence"})],q4.prototype,"authorityCertIssuer",void 0);j([K({type:S.Integer,context:2,optional:!0,implicit:!0,converter:_1})],q4.prototype,"authorityCertSerialNumber",void 0);var NH=`${j1}.19`;class vG{cA=!1;pathLenConstraint;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Boolean,defaultValue:!1})],vG.prototype,"cA",void 0);j([K({type:S.Integer,optional:!0})],vG.prototype,"pathLenConstraint",void 0);var Mz,z8=Mz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Mz.prototype)}};z8=Mz=j([G0({type:i.Sequence,itemType:Q1})],z8);var Pz,xf=`${j1}.29`,qP=Pz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,Pz.prototype)}};qP=Pz=j([G0({type:i.Sequence})],qP);var Lz,AH=`${j1}.32`,i80=`${AH}.0`,A4=class{ia5String;visibleString;bmpString;utf8String;constructor(Y={}){Object.assign(this,Y)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};j([K({type:S.IA5String})],A4.prototype,"ia5String",void 0);j([K({type:S.VisibleString})],A4.prototype,"visibleString",void 0);j([K({type:S.BmpString})],A4.prototype,"bmpString",void 0);j([K({type:S.Utf8String})],A4.prototype,"utf8String",void 0);A4=j([G0({type:i.Choice})],A4);class IH{organization=new A4;noticeNumbers=[];constructor(W={}){Object.assign(this,W)}}j([K({type:A4})],IH.prototype,"organization",void 0);j([K({type:S.Integer,repeated:"sequence"})],IH.prototype,"noticeNumbers",void 0);class zH{noticeRef;explicitText;constructor(W={}){Object.assign(this,W)}}j([K({type:IH,optional:!0})],zH.prototype,"noticeRef",void 0);j([K({type:A4,optional:!0})],zH.prototype,"explicitText",void 0);var qH=class{cPSuri;userNotice;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.IA5String})],qH.prototype,"cPSuri",void 0);j([K({type:zH})],qH.prototype,"userNotice",void 0);qH=j([G0({type:i.Choice})],qH);class wH{policyQualifierId="";qualifier=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],wH.prototype,"policyQualifierId",void 0);j([K({type:S.Any})],wH.prototype,"qualifier",void 0);class gG{policyIdentifier="";policyQualifiers;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],gG.prototype,"policyIdentifier",void 0);j([K({type:wH,repeated:"sequence",optional:!0})],gG.prototype,"policyQualifiers",void 0);var aJ=Lz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Lz.prototype)}};aJ=Lz=j([G0({type:i.Sequence,itemType:gG})],aJ);var e80=`${j1}.20`,sJ=class{value;constructor(Y=0){this.value=Y}};j([K({type:S.Integer})],sJ.prototype,"value",void 0);sJ=j([G0({type:i.Choice})],sJ);var Z90=`${j1}.27`,AP=class extends sJ{};AP=j([G0({type:i.Choice})],AP);var Bz,jH=`${j1}.31`,h5;(function(W){W[W.unused=1]="unused",W[W.keyCompromise=2]="keyCompromise",W[W.cACompromise=4]="cACompromise",W[W.affiliationChanged=8]="affiliationChanged",W[W.superseded=16]="superseded",W[W.cessationOfOperation=32]="cessationOfOperation",W[W.certificateHold=64]="certificateHold",W[W.privilegeWithdrawn=128]="privilegeWithdrawn",W[W.aACompromise=256]="aACompromise"})(h5||(h5={}));class OH extends N4{toJSON(){let W=[],Y=this.toNumber();if(Y&h5.aACompromise)W.push("aACompromise");if(Y&h5.affiliationChanged)W.push("affiliationChanged");if(Y&h5.cACompromise)W.push("cACompromise");if(Y&h5.certificateHold)W.push("certificateHold");if(Y&h5.cessationOfOperation)W.push("cessationOfOperation");if(Y&h5.keyCompromise)W.push("keyCompromise");if(Y&h5.privilegeWithdrawn)W.push("privilegeWithdrawn");if(Y&h5.superseded)W.push("superseded");if(Y&h5.unused)W.push("unused");return W}toString(){return`[${this.toJSON().join(", ")}]`}}var I4=class{fullName;nameRelativeToCRLIssuer;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,context:0,repeated:"sequence",implicit:!0})],I4.prototype,"fullName",void 0);j([K({type:C6,context:1,implicit:!0})],I4.prototype,"nameRelativeToCRLIssuer",void 0);I4=j([G0({type:i.Choice})],I4);class z4{distributionPoint;reasons;cRLIssuer;constructor(W={}){Object.assign(this,W)}}j([K({type:I4,context:0,optional:!0})],z4.prototype,"distributionPoint",void 0);j([K({type:OH,context:1,optional:!0,implicit:!0})],z4.prototype,"reasons",void 0);j([K({type:Q1,context:2,optional:!0,repeated:"sequence",implicit:!0})],z4.prototype,"cRLIssuer",void 0);var M6=Bz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Bz.prototype)}};M6=Bz=j([G0({type:i.Sequence,itemType:z4})],M6);var Ez,O90=`${j1}.46`,IP=Ez=class extends M6{constructor(Y){super(Y);Object.setPrototypeOf(this,Ez.prototype)}};IP=Ez=j([G0({type:i.Sequence,itemType:z4})],IP);var M90=`${j1}.28`;class y9{static ONLY=!1;distributionPoint;onlyContainsUserCerts=y9.ONLY;onlyContainsCACerts=y9.ONLY;onlySomeReasons;indirectCRL=y9.ONLY;onlyContainsAttributeCerts=y9.ONLY;constructor(W={}){Object.assign(this,W)}}j([K({type:I4,context:0,optional:!0})],y9.prototype,"distributionPoint",void 0);j([K({type:S.Boolean,context:1,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsUserCerts",void 0);j([K({type:S.Boolean,context:2,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsCACerts",void 0);j([K({type:OH,context:3,optional:!0,implicit:!0})],y9.prototype,"onlySomeReasons",void 0);j([K({type:S.Boolean,context:4,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"indirectCRL",void 0);j([K({type:S.Boolean,context:5,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsAttributeCerts",void 0);var zP=`${j1}.21`,tJ;(function(W){W[W.unspecified=0]="unspecified",W[W.keyCompromise=1]="keyCompromise",W[W.cACompromise=2]="cACompromise",W[W.affiliationChanged=3]="affiliationChanged",W[W.superseded=4]="superseded",W[W.cessationOfOperation=5]="cessationOfOperation",W[W.certificateHold=6]="certificateHold",W[W.removeFromCRL=8]="removeFromCRL",W[W.privilegeWithdrawn=9]="privilegeWithdrawn",W[W.aACompromise=10]="aACompromise"})(tJ||(tJ={}));var eJ=class{reason=tJ.unspecified;constructor(Y=tJ.unspecified){this.reason=Y}toJSON(){return tJ[this.reason]}toString(){return this.toJSON()}};j([K({type:S.Enumerated})],eJ.prototype,"reason",void 0);eJ=j([G0({type:i.Choice})],eJ);var $z,KH=`${j1}.37`,WZ=$z=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,$z.prototype)}};WZ=$z=j([G0({type:i.Sequence,itemType:S.ObjectIdentifier})],WZ);var k90=`${KH}.0`,wP=`${_W}.1`,jP=`${_W}.2`,OP=`${_W}.3`,KP=`${_W}.4`,DP=`${_W}.8`,CP=`${_W}.9`;var u90=`${j1}.54`,Fz=class{value;constructor(Y=new ArrayBuffer(0)){this.value=Y}};j([K({type:S.Integer,converter:_1})],Fz.prototype,"value",void 0);Fz=j([G0({type:i.Choice})],Fz);var TP=`${j1}.24`,YZ=class{value=new Date;constructor(Y){if(Y)this.value=Y}};j([K({type:S.GeneralizedTime})],YZ.prototype,"value",void 0);YZ=j([G0({type:i.Choice})],YZ);var Sz,xz=`${j1}.18`,RP=Sz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,Sz.prototype)}};RP=Sz=j([G0({type:i.Sequence})],RP);var DH=`${j1}.15`,b5;(function(W){W[W.digitalSignature=1]="digitalSignature",W[W.nonRepudiation=2]="nonRepudiation",W[W.keyEncipherment=4]="keyEncipherment",W[W.dataEncipherment=8]="dataEncipherment",W[W.keyAgreement=16]="keyAgreement",W[W.keyCertSign=32]="keyCertSign",W[W.cRLSign=64]="cRLSign",W[W.encipherOnly=128]="encipherOnly",W[W.decipherOnly=256]="decipherOnly"})(b5||(b5={}));class GZ extends N4{toJSON(){let W=this.toNumber(),Y=[];if(W&b5.cRLSign)Y.push("crlSign");if(W&b5.dataEncipherment)Y.push("dataEncipherment");if(W&b5.decipherOnly)Y.push("decipherOnly");if(W&b5.digitalSignature)Y.push("digitalSignature");if(W&b5.encipherOnly)Y.push("encipherOnly");if(W&b5.keyAgreement)Y.push("keyAgreement");if(W&b5.keyCertSign)Y.push("keyCertSign");if(W&b5.keyEncipherment)Y.push("keyEncipherment");if(W&b5.nonRepudiation)Y.push("nonRepudiation");return Y}toString(){return`[${this.toJSON().join(", ")}]`}}var kz,Y50=`${j1}.30`;class XZ{base=new Q1;minimum=0;maximum;constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],XZ.prototype,"base",void 0);j([K({type:S.Integer,context:0,defaultValue:0,implicit:!0})],XZ.prototype,"minimum",void 0);j([K({type:S.Integer,context:1,optional:!0,implicit:!0})],XZ.prototype,"maximum",void 0);var CH=kz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,kz.prototype)}};CH=kz=j([G0({type:i.Sequence,itemType:XZ})],CH);class _z{permittedSubtrees;excludedSubtrees;constructor(W={}){Object.assign(this,W)}}j([K({type:CH,context:0,optional:!0,implicit:!0})],_z.prototype,"permittedSubtrees",void 0);j([K({type:CH,context:1,optional:!0,implicit:!0})],_z.prototype,"excludedSubtrees",void 0);var V50=`${j1}.36`;class yz{requireExplicitPolicy;inhibitPolicyMapping;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,context:0,implicit:!0,optional:!0,converter:_1})],yz.prototype,"requireExplicitPolicy",void 0);j([K({type:S.Integer,context:1,implicit:!0,optional:!0,converter:_1})],yz.prototype,"inhibitPolicyMapping",void 0);var vz,q50=`${j1}.33`;class TH{issuerDomainPolicy="";subjectDomainPolicy="";constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],TH.prototype,"issuerDomainPolicy",void 0);j([K({type:S.ObjectIdentifier})],TH.prototype,"subjectDomainPolicy",void 0);var MP=vz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,vz.prototype)}};MP=vz=j([G0({type:i.Sequence,itemType:TH})],MP);var gz,uz=`${j1}.17`,RH=gz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,gz.prototype)}};RH=gz=j([G0({type:i.Sequence})],RH);class z9{type="";values=[];constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],z9.prototype,"type",void 0);j([K({type:S.Any,repeated:"set"})],z9.prototype,"values",void 0);var hz,L50=`${j1}.9`,PP=hz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,hz.prototype)}};PP=hz=j([G0({type:i.Sequence,itemType:z9})],PP);var bz=`${j1}.14`;class G5 extends yG{}var _50=`${j1}.16`;class mz{notBefore;notAfter;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralizedTime,context:0,implicit:!0,optional:!0})],mz.prototype,"notBefore",void 0);j([K({type:S.GeneralizedTime,context:1,implicit:!0,optional:!0})],mz.prototype,"notAfter",void 0);var JZ;(function(W){W[W.keyUpdateAllowed=1]="keyUpdateAllowed",W[W.newExtensions=2]="newExtensions",W[W.pKIXCertificate=4]="pKIXCertificate"})(JZ||(JZ={}));class fz extends N4{toJSON(){let W=[],Y=this.toNumber();if(Y&JZ.pKIXCertificate)W.push("pKIXCertificate");if(Y&JZ.newExtensions)W.push("newExtensions");if(Y&JZ.keyUpdateAllowed)W.push("keyUpdateAllowed");return W}toString(){return`[${this.toJSON().join(", ")}]`}}class cz{entrustVers="";entrustInfoFlags=new fz;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralString})],cz.prototype,"entrustVers",void 0);j([K({type:fz})],cz.prototype,"entrustInfoFlags",void 0);var pz,c50=`${T6}.11`,LP=pz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,pz.prototype)}};LP=pz=j([G0({type:i.Sequence,itemType:R6})],LP);class M0{algorithm="";parameters;constructor(W={}){Object.assign(this,W)}isEqual(W){return W instanceof M0&&W.algorithm==this.algorithm&&(W.parameters&&this.parameters&&Vz(W.parameters,this.parameters)||W.parameters===this.parameters)}}j([K({type:S.ObjectIdentifier})],M0.prototype,"algorithm",void 0);j([K({type:S.Any,optional:!0})],M0.prototype,"parameters",void 0);class w9{algorithm=new M0;subjectPublicKey=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],w9.prototype,"algorithm",void 0);j([K({type:S.BitString})],w9.prototype,"subjectPublicKey",void 0);var P8=class{utcTime;generalTime;constructor(Y){if(Y)if(typeof Y==="string"||typeof Y==="number"||Y instanceof Date){let G=new Date(Y);if(G.setMilliseconds(0),G.getUTCFullYear()>2049)this.generalTime=G;else this.utcTime=G}else Object.assign(this,Y)}getTime(){let Y=this.utcTime||this.generalTime;if(!Y)throw Error("Cannot get time from CHOICE object");return Y}};j([K({type:S.UTCTime})],P8.prototype,"utcTime",void 0);j([K({type:S.GeneralizedTime})],P8.prototype,"generalTime",void 0);P8=j([G0({type:i.Choice})],P8);class P6{notBefore=new P8(new Date);notAfter=new P8(new Date);constructor(W){if(W)this.notBefore=new P8(W.notBefore),this.notAfter=new P8(W.notAfter)}}j([K({type:P8})],P6.prototype,"notBefore",void 0);j([K({type:P8})],P6.prototype,"notAfter",void 0);var lz;class j9{static CRITICAL=!1;extnID="";critical=j9.CRITICAL;extnValue=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],j9.prototype,"extnID",void 0);j([K({type:S.Boolean,defaultValue:j9.CRITICAL})],j9.prototype,"critical",void 0);j([K({type:J1})],j9.prototype,"extnValue",void 0);var X5=lz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,lz.prototype)}};X5=lz=j([G0({type:i.Sequence,itemType:j9})],X5);var P7;(function(W){W[W.v1=0]="v1",W[W.v2=1]="v2",W[W.v3=2]="v3"})(P7||(P7={}));class O9{version=P7.v1;serialNumber=new ArrayBuffer(0);signature=new M0;issuer=new G8;validity=new P6;subject=new G8;subjectPublicKeyInfo=new w9;issuerUniqueID;subjectUniqueID;extensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,context:0,defaultValue:P7.v1})],O9.prototype,"version",void 0);j([K({type:S.Integer,converter:_1})],O9.prototype,"serialNumber",void 0);j([K({type:M0})],O9.prototype,"signature",void 0);j([K({type:G8})],O9.prototype,"issuer",void 0);j([K({type:P6})],O9.prototype,"validity",void 0);j([K({type:G8})],O9.prototype,"subject",void 0);j([K({type:w9})],O9.prototype,"subjectPublicKeyInfo",void 0);j([K({type:S.BitString,context:1,implicit:!0,optional:!0})],O9.prototype,"issuerUniqueID",void 0);j([K({type:S.BitString,context:2,implicit:!0,optional:!0})],O9.prototype,"subjectUniqueID",void 0);j([K({type:X5,context:3,optional:!0})],O9.prototype,"extensions",void 0);class m5{tbsCertificate=new O9;tbsCertificateRaw;signatureAlgorithm=new M0;signatureValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:O9,raw:!0})],m5.prototype,"tbsCertificate",void 0);j([K({type:M0})],m5.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],m5.prototype,"signatureValue",void 0);class uG{userCertificate=new ArrayBuffer(0);revocationDate=new P8;crlEntryExtensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],uG.prototype,"userCertificate",void 0);j([K({type:P8})],uG.prototype,"revocationDate",void 0);j([K({type:j9,optional:!0,repeated:"sequence"})],uG.prototype,"crlEntryExtensions",void 0);class M5{version;signature=new M0;issuer=new G8;thisUpdate=new P8;nextUpdate;revokedCertificates;crlExtensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,optional:!0})],M5.prototype,"version",void 0);j([K({type:M0})],M5.prototype,"signature",void 0);j([K({type:G8})],M5.prototype,"issuer",void 0);j([K({type:P8})],M5.prototype,"thisUpdate",void 0);j([K({type:P8,optional:!0})],M5.prototype,"nextUpdate",void 0);j([K({type:uG,repeated:"sequence",optional:!0})],M5.prototype,"revokedCertificates",void 0);j([K({type:j9,optional:!0,context:0,repeated:"sequence"})],M5.prototype,"crlExtensions",void 0);class hG{tbsCertList=new M5;tbsCertListRaw;signatureAlgorithm=new M0;signature=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M5,raw:!0})],hG.prototype,"tbsCertList",void 0);j([K({type:M0})],hG.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],hG.prototype,"signature",void 0);class L7{issuer=new G8;serialNumber=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:G8})],L7.prototype,"issuer",void 0);j([K({type:S.Integer,converter:_1})],L7.prototype,"serialNumber",void 0);var vW=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0})],vW.prototype,"subjectKeyIdentifier",void 0);j([K({type:L7})],vW.prototype,"issuerAndSerialNumber",void 0);vW=j([G0({type:i.Choice})],vW);var W9;(function(W){W[W.v0=0]="v0",W[W.v1=1]="v1",W[W.v2=2]="v2",W[W.v3=3]="v3",W[W.v4=4]="v4",W[W.v5=5]="v5"})(W9||(W9={}));var gW=class extends M0{};gW=j([G0({type:i.Sequence})],gW);var ZZ=class extends M0{};ZZ=j([G0({type:i.Sequence})],ZZ);var p9=class extends M0{};p9=j([G0({type:i.Sequence})],p9);var VZ=class extends M0{};VZ=j([G0({type:i.Sequence})],VZ);var EP=class extends M0{};EP=j([G0({type:i.Sequence})],EP);var MH=class extends M0{};MH=j([G0({type:i.Sequence})],MH);class B7{attrType="";attrValues=[];constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],B7.prototype,"attrType",void 0);j([K({type:S.Any,repeated:"set"})],B7.prototype,"attrValues",void 0);var dz;class J5{version=W9.v0;sid=new vW;digestAlgorithm=new gW;signedAttrs;signedAttrsRaw;signatureAlgorithm=new ZZ;signature=new J1;unsignedAttrs;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],J5.prototype,"version",void 0);j([K({type:vW})],J5.prototype,"sid",void 0);j([K({type:gW})],J5.prototype,"digestAlgorithm",void 0);j([K({type:B7,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],J5.prototype,"signedAttrs",void 0);j([K({type:ZZ})],J5.prototype,"signatureAlgorithm",void 0);j([K({type:J1})],J5.prototype,"signature",void 0);j([K({type:B7,repeated:"set",context:1,implicit:!0,optional:!0})],J5.prototype,"unsignedAttrs",void 0);var UZ=dz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,dz.prototype)}};UZ=dz=j([G0({type:i.Set,itemType:J5})],UZ);var $P=class extends J5{};$P=j([G0({type:i.Sequence})],$P);var FP=class extends P8{};FP=j([G0({type:i.Choice})],FP);class PH{acIssuer=new Q1;acSerial=0;attrs=[];constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],PH.prototype,"acIssuer",void 0);j([K({type:S.Integer})],PH.prototype,"acSerial",void 0);j([K({type:z9,repeated:"sequence"})],PH.prototype,"attrs",void 0);var oz,QZ=oz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,oz.prototype)}};QZ=oz=j([G0({type:i.Sequence,itemType:S.ObjectIdentifier})],QZ);class HZ{pathLenConstraint;permittedAttrs;excludedAttrs;permitUnSpecified=!0;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,optional:!0})],HZ.prototype,"pathLenConstraint",void 0);j([K({type:QZ,implicit:!0,context:0,optional:!0})],HZ.prototype,"permittedAttrs",void 0);j([K({type:QZ,implicit:!0,context:1,optional:!0})],HZ.prototype,"excludedAttrs",void 0);j([K({type:S.Boolean,defaultValue:!0})],HZ.prototype,"permitUnSpecified",void 0);class f5{issuer=new z8;serial=new ArrayBuffer(0);issuerUID=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:z8})],f5.prototype,"issuer",void 0);j([K({type:S.Integer,converter:_1})],f5.prototype,"serial",void 0);j([K({type:S.BitString,optional:!0})],f5.prototype,"issuerUID",void 0);var nz;(function(W){W[W.publicKey=0]="publicKey",W[W.publicKeyCert=1]="publicKeyCert",W[W.otherObjectTypes=2]="otherObjectTypes"})(nz||(nz={}));class c5{digestedObjectType=nz.publicKey;otherObjectTypeID;digestAlgorithm=new M0;objectDigest=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Enumerated})],c5.prototype,"digestedObjectType",void 0);j([K({type:S.ObjectIdentifier,optional:!0})],c5.prototype,"otherObjectTypeID",void 0);j([K({type:M0})],c5.prototype,"digestAlgorithm",void 0);j([K({type:S.BitString})],c5.prototype,"objectDigest",void 0);class bG{issuerName;baseCertificateID;objectDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:z8,optional:!0})],bG.prototype,"issuerName",void 0);j([K({type:f5,context:0,implicit:!0,optional:!0})],bG.prototype,"baseCertificateID",void 0);j([K({type:c5,context:1,implicit:!0,optional:!0})],bG.prototype,"objectDigestInfo",void 0);var uW=class{v1Form;v2Form;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,repeated:"sequence"})],uW.prototype,"v1Form",void 0);j([K({type:bG,context:0,implicit:!0})],uW.prototype,"v2Form",void 0);uW=j([G0({type:i.Choice})],uW);class mG{notBeforeTime=new Date;notAfterTime=new Date;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralizedTime})],mG.prototype,"notBeforeTime",void 0);j([K({type:S.GeneralizedTime})],mG.prototype,"notAfterTime",void 0);class hW{baseCertificateID;entityName;objectDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:f5,implicit:!0,context:0,optional:!0})],hW.prototype,"baseCertificateID",void 0);j([K({type:z8,implicit:!0,context:1,optional:!0})],hW.prototype,"entityName",void 0);j([K({type:c5,implicit:!0,context:2,optional:!0})],hW.prototype,"objectDigestInfo",void 0);var iz;(function(W){W[W.v2=1]="v2"})(iz||(iz={}));class Z5{version=iz.v2;holder=new hW;issuer=new uW;signature=new M0;serialNumber=new ArrayBuffer(0);attrCertValidityPeriod=new mG;attributes=[];issuerUniqueID;extensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],Z5.prototype,"version",void 0);j([K({type:hW})],Z5.prototype,"holder",void 0);j([K({type:uW})],Z5.prototype,"issuer",void 0);j([K({type:M0})],Z5.prototype,"signature",void 0);j([K({type:S.Integer,converter:_1})],Z5.prototype,"serialNumber",void 0);j([K({type:mG})],Z5.prototype,"attrCertValidityPeriod",void 0);j([K({type:z9,repeated:"sequence"})],Z5.prototype,"attributes",void 0);j([K({type:S.BitString,optional:!0})],Z5.prototype,"issuerUniqueID",void 0);j([K({type:X5,optional:!0})],Z5.prototype,"extensions",void 0);class fG{acinfo=new Z5;signatureAlgorithm=new M0;signatureValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:Z5})],fG.prototype,"acinfo",void 0);j([K({type:M0})],fG.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],fG.prototype,"signatureValue",void 0);var NZ;(function(W){W[W.unmarked=1]="unmarked",W[W.unclassified=2]="unclassified",W[W.restricted=4]="restricted",W[W.confidential=8]="confidential",W[W.secret=16]="secret",W[W.topSecret=32]="topSecret"})(NZ||(NZ={}));class qZ extends N4{}class AZ{type="";value=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier,implicit:!0,context:0})],AZ.prototype,"type",void 0);j([K({type:S.Any,implicit:!0,context:1})],AZ.prototype,"value",void 0);class LH{policyId="";classList=new qZ(NZ.unclassified);securityCategories;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],LH.prototype,"policyId",void 0);j([K({type:qZ,defaultValue:new qZ(NZ.unclassified)})],LH.prototype,"classList",void 0);j([K({type:AZ,repeated:"set"})],LH.prototype,"securityCategories",void 0);class IZ{cotets;oid;string;constructor(W={}){Object.assign(this,W)}}j([K({type:J1})],IZ.prototype,"cotets",void 0);j([K({type:S.ObjectIdentifier})],IZ.prototype,"oid",void 0);j([K({type:S.Utf8String})],IZ.prototype,"string",void 0);class rz{policyAuthority;values=[];constructor(W={}){Object.assign(this,W)}}j([K({type:z8,implicit:!0,context:0,optional:!0})],rz.prototype,"policyAuthority",void 0);j([K({type:IZ,repeated:"sequence"})],rz.prototype,"values",void 0);var OW0=`${T6}.4`,KW0=`${T6}.6`,DW0=`${T6}.10`,CW0=`${j1}.55`,zZ=`${UH}.10`,TW0=`${zZ}.1`,RW0=`${zZ}.2`,MW0=`${zZ}.3`,PW0=`${zZ}.4`,LW0=`${zZ}.6`,az="2.5.4",BW0=`${az}.72`;var sz;class wZ{targetCertificate=new f5;targetName;certDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:f5})],wZ.prototype,"targetCertificate",void 0);j([K({type:Q1,optional:!0})],wZ.prototype,"targetName",void 0);j([K({type:c5,optional:!0})],wZ.prototype,"certDigestInfo",void 0);var cG=class{targetName;targetGroup;targetCert;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,context:0,implicit:!0})],cG.prototype,"targetName",void 0);j([K({type:Q1,context:1,implicit:!0})],cG.prototype,"targetGroup",void 0);j([K({type:wZ,context:2,implicit:!0})],cG.prototype,"targetCert",void 0);cG=j([G0({type:i.Choice})],cG);var BH=sz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,sz.prototype)}};BH=sz=j([G0({type:i.Sequence,itemType:cG})],BH);var tz,SP=tz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,tz.prototype)}};SP=tz=j([G0({type:i.Sequence,itemType:BH})],SP);class ez{roleAuthority;roleName;constructor(W={}){Object.assign(this,W)}}j([K({type:z8,implicit:!0,context:0,optional:!0})],ez.prototype,"roleAuthority",void 0);j([K({type:Q1,implicit:!0,context:1})],ez.prototype,"roleName",void 0);class EH{service=new Q1;ident=new Q1;authInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],EH.prototype,"service",void 0);j([K({type:Q1})],EH.prototype,"ident",void 0);j([K({type:J1,optional:!0})],EH.prototype,"authInfo",void 0);var Ww;class $H{otherCertFormat="";otherCert=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],$H.prototype,"otherCertFormat",void 0);j([K({type:S.Any})],$H.prototype,"otherCert",void 0);var bW=class{certificate;v2AttrCert;other;constructor(Y={}){Object.assign(this,Y)}};j([K({type:m5})],bW.prototype,"certificate",void 0);j([K({type:fG,context:2,implicit:!0})],bW.prototype,"v2AttrCert",void 0);j([K({type:$H,context:3,implicit:!0})],bW.prototype,"other",void 0);bW=j([G0({type:i.Choice})],bW);var mW=Ww=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Ww.prototype)}};mW=Ww=j([G0({type:i.Set,itemType:bW})],mW);class p5{contentType="";content=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],p5.prototype,"contentType",void 0);j([K({type:S.Any,context:0})],p5.prototype,"content",void 0);var pG=class{single;any;constructor(Y={}){Object.assign(this,Y)}};j([K({type:J1})],pG.prototype,"single",void 0);j([K({type:S.Any})],pG.prototype,"any",void 0);pG=j([G0({type:i.Choice})],pG);class lG{eContentType="";eContent;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],lG.prototype,"eContentType",void 0);j([K({type:pG,context:0,optional:!0})],lG.prototype,"eContent",void 0);var jZ=class{value;constructedValue;constructor(Y={}){Object.assign(this,Y)}};j([K({type:J1,context:0,implicit:!0,optional:!0})],jZ.prototype,"value",void 0);j([K({type:J1,converter:EM,context:0,implicit:!0,optional:!0,repeated:"sequence"})],jZ.prototype,"constructedValue",void 0);jZ=j([G0({type:i.Choice})],jZ);class fW{contentType="";contentEncryptionAlgorithm=new VZ;encryptedContent;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],fW.prototype,"contentType",void 0);j([K({type:VZ})],fW.prototype,"contentEncryptionAlgorithm",void 0);j([K({type:jZ,optional:!0})],fW.prototype,"encryptedContent",void 0);class cW{keyAttrId="";keyAttr;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],cW.prototype,"keyAttrId",void 0);j([K({type:S.Any,optional:!0})],cW.prototype,"keyAttr",void 0);var Yw;class OZ{subjectKeyIdentifier=new G5;date;other;constructor(W={}){Object.assign(this,W)}}j([K({type:G5})],OZ.prototype,"subjectKeyIdentifier",void 0);j([K({type:S.GeneralizedTime,optional:!0})],OZ.prototype,"date",void 0);j([K({type:cW,optional:!0})],OZ.prototype,"other",void 0);var dG=class{rKeyId;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:OZ,context:0,implicit:!0,optional:!0})],dG.prototype,"rKeyId",void 0);j([K({type:L7,optional:!0})],dG.prototype,"issuerAndSerialNumber",void 0);dG=j([G0({type:i.Choice})],dG);class SH{rid=new dG;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:dG})],SH.prototype,"rid",void 0);j([K({type:J1})],SH.prototype,"encryptedKey",void 0);var FH=Yw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Yw.prototype)}};FH=Yw=j([G0({type:i.Sequence,itemType:SH})],FH);class xH{algorithm=new M0;publicKey=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],xH.prototype,"algorithm",void 0);j([K({type:S.BitString})],xH.prototype,"publicKey",void 0);var pW=class{subjectKeyIdentifier;originatorKey;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0,optional:!0})],pW.prototype,"subjectKeyIdentifier",void 0);j([K({type:xH,context:1,implicit:!0,optional:!0})],pW.prototype,"originatorKey",void 0);j([K({type:L7,optional:!0})],pW.prototype,"issuerAndSerialNumber",void 0);pW=j([G0({type:i.Choice})],pW);class L6{version=W9.v3;originator=new pW;ukm;keyEncryptionAlgorithm=new p9;recipientEncryptedKeys=new FH;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],L6.prototype,"version",void 0);j([K({type:pW,context:0})],L6.prototype,"originator",void 0);j([K({type:J1,context:1,optional:!0})],L6.prototype,"ukm",void 0);j([K({type:p9})],L6.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:FH})],L6.prototype,"recipientEncryptedKeys",void 0);var oG=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0})],oG.prototype,"subjectKeyIdentifier",void 0);j([K({type:L7})],oG.prototype,"issuerAndSerialNumber",void 0);oG=j([G0({type:i.Choice})],oG);class lW{version=W9.v0;rid=new oG;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],lW.prototype,"version",void 0);j([K({type:oG})],lW.prototype,"rid",void 0);j([K({type:p9})],lW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],lW.prototype,"encryptedKey",void 0);class nG{keyIdentifier=new J1;date;other;constructor(W={}){Object.assign(this,W)}}j([K({type:J1})],nG.prototype,"keyIdentifier",void 0);j([K({type:S.GeneralizedTime,optional:!0})],nG.prototype,"date",void 0);j([K({type:cW,optional:!0})],nG.prototype,"other",void 0);class dW{version=W9.v4;kekid=new nG;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],dW.prototype,"version",void 0);j([K({type:nG})],dW.prototype,"kekid",void 0);j([K({type:p9})],dW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],dW.prototype,"encryptedKey",void 0);class oW{version=W9.v0;keyDerivationAlgorithm;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],oW.prototype,"version",void 0);j([K({type:MH,context:0,optional:!0})],oW.prototype,"keyDerivationAlgorithm",void 0);j([K({type:p9})],oW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],oW.prototype,"encryptedKey",void 0);class kH{oriType="";oriValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],kH.prototype,"oriType",void 0);j([K({type:S.Any})],kH.prototype,"oriValue",void 0);var w4=class{ktri;kari;kekri;pwri;ori;constructor(Y={}){Object.assign(this,Y)}};j([K({type:lW,optional:!0})],w4.prototype,"ktri",void 0);j([K({type:L6,context:1,implicit:!0,optional:!0})],w4.prototype,"kari",void 0);j([K({type:dW,context:2,implicit:!0,optional:!0})],w4.prototype,"kekri",void 0);j([K({type:oW,context:3,implicit:!0,optional:!0})],w4.prototype,"pwri",void 0);j([K({type:kH,context:4,implicit:!0,optional:!0})],w4.prototype,"ori",void 0);w4=j([G0({type:i.Choice})],w4);var Gw,KZ=Gw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Gw.prototype)}};KZ=Gw=j([G0({type:i.Set,itemType:w4})],KZ);var Xw,xP=`${UH}.16`,AG0=`${xP}.2`,IG0=`${xP}.4`;class DZ{otherRevInfoFormat="";otherRevInfo=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],DZ.prototype,"otherRevInfoFormat",void 0);j([K({type:S.Any})],DZ.prototype,"otherRevInfo",void 0);var _H=class{other=new DZ;constructor(Y={}){Object.assign(this,Y)}};j([K({type:DZ,context:1,implicit:!0})],_H.prototype,"other",void 0);_H=j([G0({type:i.Choice})],_H);var iG=Xw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Xw.prototype)}};iG=Xw=j([G0({type:i.Set,itemType:_H})],iG);class CZ{certs;crls;constructor(W={}){Object.assign(this,W)}}j([K({type:mW,context:0,implicit:!0,optional:!0})],CZ.prototype,"certs",void 0);j([K({type:iG,context:1,implicit:!0,optional:!0})],CZ.prototype,"crls",void 0);var Jw,Zw=Jw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Jw.prototype)}};Zw=Jw=j([G0({type:i.Set,itemType:B7})],Zw);class rG{version=W9.v0;originatorInfo;recipientInfos=new KZ;encryptedContentInfo=new fW;unprotectedAttrs;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],rG.prototype,"version",void 0);j([K({type:CZ,context:0,implicit:!0,optional:!0})],rG.prototype,"originatorInfo",void 0);j([K({type:KZ})],rG.prototype,"recipientInfos",void 0);j([K({type:fW})],rG.prototype,"encryptedContentInfo",void 0);j([K({type:Zw,context:1,implicit:!0,optional:!0})],rG.prototype,"unprotectedAttrs",void 0);var kP="1.2.840.113549.1.7.2";var Vw,yH=Vw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Vw.prototype)}};yH=Vw=j([G0({type:i.Set,itemType:gW})],yH);class B6{version=W9.v0;digestAlgorithms=new yH;encapContentInfo=new lG;certificates;crls;signerInfos=new UZ;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],B6.prototype,"version",void 0);j([K({type:yH})],B6.prototype,"digestAlgorithms",void 0);j([K({type:lG})],B6.prototype,"encapContentInfo",void 0);j([K({type:mW,context:0,implicit:!0,optional:!0})],B6.prototype,"certificates",void 0);j([K({type:iG,context:1,implicit:!0,optional:!0})],B6.prototype,"crls",void 0);j([K({type:UZ})],B6.prototype,"signerInfos",void 0);var nW="1.2.840.10045.2.1";var TZ="1.2.840.10045.4.1",vH="1.2.840.10045.4.3.1",RZ="1.2.840.10045.4.3.2",MZ="1.2.840.10045.4.3.3",PZ="1.2.840.10045.4.3.4";var Uw="1.2.840.10045.3.1.7";var Qw="1.3.132.0.34";var Hw="1.3.132.0.35";function LZ(W){return new M0({algorithm:W})}var yP=LZ(TZ),ZX0=LZ(vH),vP=LZ(RZ),gP=LZ(MZ),uP=LZ(PZ);var BZ=class{fieldType;parameters;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.ObjectIdentifier})],BZ.prototype,"fieldType",void 0);j([K({type:S.Any})],BZ.prototype,"parameters",void 0);BZ=j([G0({type:i.Sequence})],BZ);class hP extends J1{}var aG=class{a;b;seed;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.OctetString})],aG.prototype,"a",void 0);j([K({type:S.OctetString})],aG.prototype,"b",void 0);j([K({type:S.BitString,optional:!0})],aG.prototype,"seed",void 0);aG=j([G0({type:i.Sequence})],aG);var Nw;(function(W){W[W.ecpVer1=1]="ecpVer1"})(Nw||(Nw={}));var E7=class{version=Nw.ecpVer1;fieldID;curve;base;order;cofactor;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.Integer})],E7.prototype,"version",void 0);j([K({type:BZ})],E7.prototype,"fieldID",void 0);j([K({type:aG})],E7.prototype,"curve",void 0);j([K({type:hP})],E7.prototype,"base",void 0);j([K({type:S.Integer,converter:_1})],E7.prototype,"order",void 0);j([K({type:S.Integer,optional:!0})],E7.prototype,"cofactor",void 0);E7=j([G0({type:i.Sequence})],E7);var $7=class{namedCurve;implicitCurve;specifiedCurve;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.ObjectIdentifier})],$7.prototype,"namedCurve",void 0);j([K({type:S.Null})],$7.prototype,"implicitCurve",void 0);j([K({type:E7})],$7.prototype,"specifiedCurve",void 0);$7=j([G0({type:i.Choice})],$7);class EZ{version=1;privateKey=new J1;parameters;publicKey;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],EZ.prototype,"version",void 0);j([K({type:J1})],EZ.prototype,"privateKey",void 0);j([K({type:$7,context:0,optional:!0})],EZ.prototype,"parameters",void 0);j([K({type:S.BitString,context:1,optional:!0})],EZ.prototype,"publicKey",void 0);class sG{r=new ArrayBuffer(0);s=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],sG.prototype,"r",void 0);j([K({type:S.Integer,converter:_1})],sG.prototype,"s",void 0);var F7="1.2.840.113549.1.1.1",bP="1.2.840.113549.1.1.7",mP="1.2.840.113549.1.1.9",E6="1.2.840.113549.1.1.10",fP="1.2.840.113549.1.1.2",cP="1.2.840.113549.1.1.4",tG="1.2.840.113549.1.1.5",pP="1.2.840.113549.1.1.14";var gH="1.2.840.113549.1.1.11",eG="1.2.840.113549.1.1.12",WX="1.2.840.113549.1.1.13",qw="1.2.840.113549.1.1.15",Aw="1.2.840.113549.1.1.16",iW="1.3.14.3.2.26",uH="2.16.840.1.101.3.4.2.4",rW="2.16.840.1.101.3.4.2.1",aW="2.16.840.1.101.3.4.2.2",sW="2.16.840.1.101.3.4.2.3",lP="2.16.840.1.101.3.4.2.5",dP="2.16.840.1.101.3.4.2.6",oP="1.2.840.113549.2.2",nP="1.2.840.113549.2.5",$6="1.2.840.113549.1.1.8";function l8(W){return new M0({algorithm:W,parameters:null})}var FX0=l8(oP),SX0=l8(nP),j4=l8(iW),xX0=l8(uH),kX0=l8(rW),_X0=l8(aW),yX0=l8(sW),vX0=l8(lP),gX0=l8(dP),hH=new M0({algorithm:$6,parameters:E0.serialize(j4)}),Iw=new M0({algorithm:mP,parameters:E0.serialize(FG.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),uX0=l8(F7),hX0=l8(fP),bX0=l8(cP),mX0=l8(tG),fX0=l8(qw),cX0=l8(Aw),pX0=l8(eG),lX0=l8(WX),dX0=l8(qw),oX0=l8(Aw);class $Z{hashAlgorithm=new M0(j4);maskGenAlgorithm=new M0({algorithm:$6,parameters:E0.serialize(j4)});pSourceAlgorithm=new M0(Iw);constructor(W={}){Object.assign(this,W)}}j([K({type:M0,context:0,defaultValue:j4})],$Z.prototype,"hashAlgorithm",void 0);j([K({type:M0,context:1,defaultValue:hH})],$Z.prototype,"maskGenAlgorithm",void 0);j([K({type:M0,context:2,defaultValue:Iw})],$Z.prototype,"pSourceAlgorithm",void 0);var eX0=new M0({algorithm:bP,parameters:E0.serialize(new $Z)});class O4{hashAlgorithm=new M0(j4);maskGenAlgorithm=new M0({algorithm:$6,parameters:E0.serialize(j4)});saltLength=20;trailerField=1;constructor(W={}){Object.assign(this,W)}}j([K({type:M0,context:0,defaultValue:j4})],O4.prototype,"hashAlgorithm",void 0);j([K({type:M0,context:1,defaultValue:hH})],O4.prototype,"maskGenAlgorithm",void 0);j([K({type:S.Integer,context:2,defaultValue:20})],O4.prototype,"saltLength",void 0);j([K({type:S.Integer,context:3,defaultValue:1})],O4.prototype,"trailerField",void 0);var VJ0=new M0({algorithm:E6,parameters:E0.serialize(new O4)});class YX{digestAlgorithm=new M0;digest=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],YX.prototype,"digestAlgorithm",void 0);j([K({type:J1})],YX.prototype,"digest",void 0);var zw;class FZ{prime=new ArrayBuffer(0);exponent=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],FZ.prototype,"prime",void 0);j([K({type:S.Integer,converter:_1})],FZ.prototype,"exponent",void 0);j([K({type:S.Integer,converter:_1})],FZ.prototype,"coefficient",void 0);var bH=zw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,zw.prototype)}};bH=zw=j([G0({type:i.Sequence,itemType:FZ})],bH);class l5{version=0;modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);privateExponent=new ArrayBuffer(0);prime1=new ArrayBuffer(0);prime2=new ArrayBuffer(0);exponent1=new ArrayBuffer(0);exponent2=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);otherPrimeInfos;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],l5.prototype,"version",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"modulus",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"publicExponent",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"privateExponent",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"prime1",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"prime2",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"exponent1",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"exponent2",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"coefficient",void 0);j([K({type:bH,optional:!0})],l5.prototype,"otherPrimeInfos",void 0);class SZ{modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],SZ.prototype,"modulus",void 0);j([K({type:S.Integer,converter:_1})],SZ.prototype,"publicExponent",void 0);var ww;(function(W){W[W.Transient=0]="Transient",W[W.Singleton=1]="Singleton",W[W.ResolutionScoped=2]="ResolutionScoped",W[W.ContainerScoped=3]="ContainerScoped"})(ww||(ww={}));var Y9=ww;var wL=y1(zL(),1),{__extends:xZ,__assign:gJ0,__rest:uJ0,__decorate:hJ0,__param:bJ0,__metadata:mJ0,__awaiter:jL,__generator:OL,__exportStar:fJ0,__createBinding:cJ0,__values:kZ,__read:XX,__spread:S7,__spreadArrays:pJ0,__await:lJ0,__asyncGenerator:dJ0,__asyncDelegator:oJ0,__asyncValues:nJ0,__makeTemplateObject:iJ0,__importStar:rJ0,__importDefault:aJ0,__classPrivateFieldGet:sJ0,__classPrivateFieldSet:tJ0}=wL.default;var uf="injectionTokens";function Ow(W){var Y=Reflect.getMetadata("design:paramtypes",W)||[],G=Reflect.getOwnMetadata(uf,W)||{};return Object.keys(G).forEach(function(X){Y[+X]=G[X]}),Y}function _Z(W){return!!W.useClass}function JX(W){return!!W.useFactory}var cH=function(){function W(Y){this.wrap=Y,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return W.prototype.createProxy=function(Y){var G=this,X={},J=!1,Z,V=function(){if(!J)Z=Y(G.wrap()),J=!0;return Z};return new Proxy(X,this.createHandler(V))},W.prototype.createHandler=function(Y){var G={},X=function(J){G[J]=function(){var Z=[];for(var V=0;V<arguments.length;V++)Z[V]=arguments[V];Z[0]=Y();var U=Reflect[J];return U.apply(void 0,S7(Z))}};return this.reflectMethods.forEach(X),G},W}();function F6(W){return typeof W==="string"||typeof W==="symbol"}function Kw(W){return typeof W==="object"&&"token"in W&&"multiple"in W}function pH(W){return typeof W==="object"&&"token"in W&&"transform"in W}function KL(W){return typeof W==="function"||W instanceof cH}function tW(W){return!!W.useToken}function eW(W){return W.useValue!=null}function DL(W){return _Z(W)||eW(W)||tW(W)||JX(W)}var hf=function(){function W(){this._registryMap=new Map}return W.prototype.entries=function(){return this._registryMap.entries()},W.prototype.getAll=function(Y){return this.ensure(Y),this._registryMap.get(Y)},W.prototype.get=function(Y){this.ensure(Y);var G=this._registryMap.get(Y);return G[G.length-1]||null},W.prototype.set=function(Y,G){this.ensure(Y),this._registryMap.get(Y).push(G)},W.prototype.setAll=function(Y,G){this._registryMap.set(Y,G)},W.prototype.has=function(Y){return this.ensure(Y),this._registryMap.get(Y).length>0},W.prototype.clear=function(){this._registryMap.clear()},W.prototype.ensure=function(Y){if(!this._registryMap.has(Y))this._registryMap.set(Y,[])},W}(),yZ=hf;var bf=function(W){xZ(Y,W);function Y(){return W!==null&&W.apply(this,arguments)||this}return Y}(yZ),CL=bf;var mf=function(){function W(){this.scopedResolutions=new Map}return W}(),vZ=mf;function ff(W,Y){if(W===null)return"at position #"+Y;var G=W.split(",")[Y].trim();return'"'+G+'" at position #'+Y}function cf(W,Y,G){if(G===void 0)G=" ";return S7([W],Y.message.split(`
|
|
213
|
+
`,Q=[];for(let H=0;H<J.length;H+=V)Q.push(VP(J.slice(H,H+V),Y.group));Z=Q.join(U)}else Z=VP(J,Y.group);return`${Y.prefix??""}${Z}`}function Iz(W,Y={}){let G=rJ(W,Y),X=new Uint8Array(G.length/2);for(let J=0;J<G.length;J+=2)X[J/2]=Number.parseInt(G.slice(J,J+2),16);return X}function QP(W,Y={}){let G=rJ(W,Y);return{bytes:Iz(G),format:Mf(W),normalized:G}}function HP(W,Y){return Az(W,Y)}var NP={compact:Object.freeze({}),upper:Object.freeze({case:"upper"}),colon:Object.freeze({group:{size:1,separator:":"}}),colonUpper:Object.freeze({case:"upper",group:{size:1,separator:":"}}),groupsOf4:Object.freeze({group:{size:4,separator:" "}}),prefixed:Object.freeze({prefix:"0x"})},Lf={encode:Az,decode:Iz,format:HP,formats:NP,is:UP,normalize:rJ,parse:QP};class ZH{static isIPv4(W){return/^(\d{1,3}\.){3}\d{1,3}$/.test(W)}static parseIPv4(W){let Y=W.split(".");if(Y.length!==4)throw Error("Invalid IPv4 address");return Y.map((G)=>{let X=parseInt(G,10);if(isNaN(X)||X<0||X>255)throw Error("Invalid IPv4 address part");return X})}static parseIPv6(W){let G=this.expandIPv6(W).split(":");if(G.length!==8)throw Error("Invalid IPv6 address");return G.reduce((X,J)=>{let Z=parseInt(J,16);if(isNaN(Z)||Z<0||Z>65535)throw Error("Invalid IPv6 address part");return X.push(Z>>8&255),X.push(Z&255),X},[])}static expandIPv6(W){if(!W.includes("::"))return W;let Y=W.split("::");if(Y.length>2)throw Error("Invalid IPv6 address");let G=Y[0]?Y[0].split(":"):[],X=Y[1]?Y[1].split(":"):[],J=8-(G.length+X.length);if(J<0)throw Error("Invalid IPv6 address");return[...G,...Array(J).fill("0"),...X].join(":")}static formatIPv6(W){let Y=[];for(let G=0;G<16;G+=2)Y.push((W[G]<<8|W[G+1]).toString(16));return this.compressIPv6(Y.join(":"))}static compressIPv6(W){let Y=W.split(":"),G=-1,X=0,J=-1,Z=0;for(let V=0;V<Y.length;V++)if(Y[V]==="0"){if(J===-1)J=V;Z++}else{if(Z>X)G=J,X=Z;J=-1,Z=0}if(Z>X)G=J,X=Z;if(X>1){let V=Y.slice(0,G).join(":"),U=Y.slice(G+X).join(":");return`${V}::${U}`}return W}static parseCIDR(W){let[Y,G]=W.split("/"),X=parseInt(G,10);if(this.isIPv4(Y)){if(X<0||X>32)throw Error("Invalid IPv4 prefix length");return[this.parseIPv4(Y),X]}else{if(X<0||X>128)throw Error("Invalid IPv6 prefix length");return[this.parseIPv6(Y),X]}}static decodeIP(W){if(W.length===64&&parseInt(W,16)===0)return"::/0";if(W.length!==16)return W;let Y=parseInt(W.slice(8),16).toString(2).split("").reduce((X,J)=>X+ +J,0),G=W.slice(0,8).replace(/(.{2})/g,(X)=>`${parseInt(X,16)}.`);return G=G.slice(0,-1),`${G}/${Y}`}static toString(W){let Y=new Uint8Array(W);if(Y.length===4)return Array.from(Y).join(".");if(Y.length===16)return this.formatIPv6(Y);if(Y.length===8||Y.length===32){let G=Y.length/2,X=Y.slice(0,G),J=Y.slice(G);if(Y.every((U)=>U===0))return Y.length===8?"0.0.0.0/0":"::/0";let V=J.reduce((U,Q)=>U+(Q.toString(2).match(/1/g)||[]).length,0);if(Y.length===8)return`${Array.from(X).join(".")}/${V}`;else return`${this.formatIPv6(X)}/${V}`}return this.decodeIP(xG.encode(W))}static fromString(W){if(W.includes("/")){let[G,X]=this.parseCIDR(W),J=new Uint8Array(G.length),Z=X;for(let U=0;U<J.length;U++)if(Z>=8)J[U]=255,Z-=8;else if(Z>0)J[U]=255<<8-Z,Z=0;let V=new Uint8Array(G.length*2);return V.set(G,0),V.set(J,G.length),V.buffer}let Y=this.isIPv4(W)?this.parseIPv4(W):this.parseIPv6(W);return new Uint8Array(Y).buffer}}var zz,wz,jz,y8=class{teletexString;printableString;universalString;utf8String;bmpString;constructor(Y={}){Object.assign(this,Y)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};j([K({type:S.TeletexString})],y8.prototype,"teletexString",void 0);j([K({type:S.PrintableString})],y8.prototype,"printableString",void 0);j([K({type:S.UniversalString})],y8.prototype,"universalString",void 0);j([K({type:S.Utf8String})],y8.prototype,"utf8String",void 0);j([K({type:S.BmpString})],y8.prototype,"bmpString",void 0);y8=j([G0({type:i.Choice})],y8);var kG=class extends y8{ia5String;anyValue;constructor(Y={}){super(Y);Object.assign(this,Y)}toString(){return this.ia5String||(this.anyValue?xG.encode(this.anyValue):super.toString())}};j([K({type:S.IA5String})],kG.prototype,"ia5String",void 0);j([K({type:S.Any})],kG.prototype,"anyValue",void 0);kG=j([G0({type:i.Choice})],kG);class _G{type="";value=new kG;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],_G.prototype,"type",void 0);j([K({type:kG})],_G.prototype,"value",void 0);var C6=zz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,zz.prototype)}};C6=zz=j([G0({type:i.Set,itemType:_G})],C6);var Oz=wz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,wz.prototype)}};Oz=wz=j([G0({type:i.Sequence,itemType:C6})],Oz);var G8=jz=class extends Oz{constructor(Y){super(Y);Object.setPrototypeOf(this,jz.prototype)}};G8=jz=j([G0({type:i.Sequence})],G8);var Sf={fromASN:(W)=>ZH.toString(FG.fromASN(W)),toASN:(W)=>FG.toASN(ZH.fromString(W))};class kW{typeId="";value=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],kW.prototype,"typeId",void 0);j([K({type:S.Any,context:0})],kW.prototype,"value",void 0);class VH{nameAssigner;partyName=new y8;constructor(W={}){Object.assign(this,W)}}j([K({type:y8,optional:!0,context:0,implicit:!0})],VH.prototype,"nameAssigner",void 0);j([K({type:y8,context:1,implicit:!0})],VH.prototype,"partyName",void 0);var Q1=class{otherName;rfc822Name;dNSName;x400Address;directoryName;ediPartyName;uniformResourceIdentifier;iPAddress;registeredID;constructor(Y={}){Object.assign(this,Y)}};j([K({type:kW,context:0,implicit:!0})],Q1.prototype,"otherName",void 0);j([K({type:S.IA5String,context:1,implicit:!0})],Q1.prototype,"rfc822Name",void 0);j([K({type:S.IA5String,context:2,implicit:!0})],Q1.prototype,"dNSName",void 0);j([K({type:S.Any,context:3,implicit:!0})],Q1.prototype,"x400Address",void 0);j([K({type:G8,context:4,implicit:!1})],Q1.prototype,"directoryName",void 0);j([K({type:VH,context:5})],Q1.prototype,"ediPartyName",void 0);j([K({type:S.IA5String,context:6,implicit:!0})],Q1.prototype,"uniformResourceIdentifier",void 0);j([K({type:S.OctetString,context:7,implicit:!0,converter:Sf})],Q1.prototype,"iPAddress",void 0);j([K({type:S.ObjectIdentifier,context:8,implicit:!0})],Q1.prototype,"registeredID",void 0);Q1=j([G0({type:i.Choice})],Q1);var UH="1.3.6.1.5.5.7",T6="1.3.6.1.5.5.7.1";var _W="1.3.6.1.5.5.7.3";var Kz="1.3.6.1.5.5.7.48.1",Dz="1.3.6.1.5.5.7.48.2",Cz="1.3.6.1.5.5.7.48.3",Tz="1.3.6.1.5.5.7.48.5",j1="2.5.29";var Rz,QH=`${T6}.1`;class R6{accessMethod="";accessLocation=new Q1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],R6.prototype,"accessMethod",void 0);j([K({type:Q1})],R6.prototype,"accessLocation",void 0);var yW=Rz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Rz.prototype)}};yW=Rz=j([G0({type:i.Sequence,itemType:R6})],yW);var HH=`${j1}.35`;class yG extends J1{}class q4{keyIdentifier;authorityCertIssuer;authorityCertSerialNumber;constructor(W={}){if(W)Object.assign(this,W)}}j([K({type:yG,context:0,optional:!0,implicit:!0})],q4.prototype,"keyIdentifier",void 0);j([K({type:Q1,context:1,optional:!0,implicit:!0,repeated:"sequence"})],q4.prototype,"authorityCertIssuer",void 0);j([K({type:S.Integer,context:2,optional:!0,implicit:!0,converter:_1})],q4.prototype,"authorityCertSerialNumber",void 0);var NH=`${j1}.19`;class vG{cA=!1;pathLenConstraint;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Boolean,defaultValue:!1})],vG.prototype,"cA",void 0);j([K({type:S.Integer,optional:!0})],vG.prototype,"pathLenConstraint",void 0);var Mz,z8=Mz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Mz.prototype)}};z8=Mz=j([G0({type:i.Sequence,itemType:Q1})],z8);var Pz,xf=`${j1}.29`,qP=Pz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,Pz.prototype)}};qP=Pz=j([G0({type:i.Sequence})],qP);var Lz,AH=`${j1}.32`,i80=`${AH}.0`,A4=class{ia5String;visibleString;bmpString;utf8String;constructor(Y={}){Object.assign(this,Y)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};j([K({type:S.IA5String})],A4.prototype,"ia5String",void 0);j([K({type:S.VisibleString})],A4.prototype,"visibleString",void 0);j([K({type:S.BmpString})],A4.prototype,"bmpString",void 0);j([K({type:S.Utf8String})],A4.prototype,"utf8String",void 0);A4=j([G0({type:i.Choice})],A4);class IH{organization=new A4;noticeNumbers=[];constructor(W={}){Object.assign(this,W)}}j([K({type:A4})],IH.prototype,"organization",void 0);j([K({type:S.Integer,repeated:"sequence"})],IH.prototype,"noticeNumbers",void 0);class zH{noticeRef;explicitText;constructor(W={}){Object.assign(this,W)}}j([K({type:IH,optional:!0})],zH.prototype,"noticeRef",void 0);j([K({type:A4,optional:!0})],zH.prototype,"explicitText",void 0);var qH=class{cPSuri;userNotice;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.IA5String})],qH.prototype,"cPSuri",void 0);j([K({type:zH})],qH.prototype,"userNotice",void 0);qH=j([G0({type:i.Choice})],qH);class wH{policyQualifierId="";qualifier=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],wH.prototype,"policyQualifierId",void 0);j([K({type:S.Any})],wH.prototype,"qualifier",void 0);class gG{policyIdentifier="";policyQualifiers;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],gG.prototype,"policyIdentifier",void 0);j([K({type:wH,repeated:"sequence",optional:!0})],gG.prototype,"policyQualifiers",void 0);var aJ=Lz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Lz.prototype)}};aJ=Lz=j([G0({type:i.Sequence,itemType:gG})],aJ);var e80=`${j1}.20`,sJ=class{value;constructor(Y=0){this.value=Y}};j([K({type:S.Integer})],sJ.prototype,"value",void 0);sJ=j([G0({type:i.Choice})],sJ);var Z90=`${j1}.27`,AP=class extends sJ{};AP=j([G0({type:i.Choice})],AP);var Bz,jH=`${j1}.31`,h5;(function(W){W[W.unused=1]="unused",W[W.keyCompromise=2]="keyCompromise",W[W.cACompromise=4]="cACompromise",W[W.affiliationChanged=8]="affiliationChanged",W[W.superseded=16]="superseded",W[W.cessationOfOperation=32]="cessationOfOperation",W[W.certificateHold=64]="certificateHold",W[W.privilegeWithdrawn=128]="privilegeWithdrawn",W[W.aACompromise=256]="aACompromise"})(h5||(h5={}));class OH extends N4{toJSON(){let W=[],Y=this.toNumber();if(Y&h5.aACompromise)W.push("aACompromise");if(Y&h5.affiliationChanged)W.push("affiliationChanged");if(Y&h5.cACompromise)W.push("cACompromise");if(Y&h5.certificateHold)W.push("certificateHold");if(Y&h5.cessationOfOperation)W.push("cessationOfOperation");if(Y&h5.keyCompromise)W.push("keyCompromise");if(Y&h5.privilegeWithdrawn)W.push("privilegeWithdrawn");if(Y&h5.superseded)W.push("superseded");if(Y&h5.unused)W.push("unused");return W}toString(){return`[${this.toJSON().join(", ")}]`}}var I4=class{fullName;nameRelativeToCRLIssuer;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,context:0,repeated:"sequence",implicit:!0})],I4.prototype,"fullName",void 0);j([K({type:C6,context:1,implicit:!0})],I4.prototype,"nameRelativeToCRLIssuer",void 0);I4=j([G0({type:i.Choice})],I4);class z4{distributionPoint;reasons;cRLIssuer;constructor(W={}){Object.assign(this,W)}}j([K({type:I4,context:0,optional:!0})],z4.prototype,"distributionPoint",void 0);j([K({type:OH,context:1,optional:!0,implicit:!0})],z4.prototype,"reasons",void 0);j([K({type:Q1,context:2,optional:!0,repeated:"sequence",implicit:!0})],z4.prototype,"cRLIssuer",void 0);var M6=Bz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Bz.prototype)}};M6=Bz=j([G0({type:i.Sequence,itemType:z4})],M6);var Ez,O90=`${j1}.46`,IP=Ez=class extends M6{constructor(Y){super(Y);Object.setPrototypeOf(this,Ez.prototype)}};IP=Ez=j([G0({type:i.Sequence,itemType:z4})],IP);var M90=`${j1}.28`;class y9{static ONLY=!1;distributionPoint;onlyContainsUserCerts=y9.ONLY;onlyContainsCACerts=y9.ONLY;onlySomeReasons;indirectCRL=y9.ONLY;onlyContainsAttributeCerts=y9.ONLY;constructor(W={}){Object.assign(this,W)}}j([K({type:I4,context:0,optional:!0})],y9.prototype,"distributionPoint",void 0);j([K({type:S.Boolean,context:1,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsUserCerts",void 0);j([K({type:S.Boolean,context:2,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsCACerts",void 0);j([K({type:OH,context:3,optional:!0,implicit:!0})],y9.prototype,"onlySomeReasons",void 0);j([K({type:S.Boolean,context:4,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"indirectCRL",void 0);j([K({type:S.Boolean,context:5,defaultValue:y9.ONLY,implicit:!0})],y9.prototype,"onlyContainsAttributeCerts",void 0);var zP=`${j1}.21`,tJ;(function(W){W[W.unspecified=0]="unspecified",W[W.keyCompromise=1]="keyCompromise",W[W.cACompromise=2]="cACompromise",W[W.affiliationChanged=3]="affiliationChanged",W[W.superseded=4]="superseded",W[W.cessationOfOperation=5]="cessationOfOperation",W[W.certificateHold=6]="certificateHold",W[W.removeFromCRL=8]="removeFromCRL",W[W.privilegeWithdrawn=9]="privilegeWithdrawn",W[W.aACompromise=10]="aACompromise"})(tJ||(tJ={}));var eJ=class{reason=tJ.unspecified;constructor(Y=tJ.unspecified){this.reason=Y}toJSON(){return tJ[this.reason]}toString(){return this.toJSON()}};j([K({type:S.Enumerated})],eJ.prototype,"reason",void 0);eJ=j([G0({type:i.Choice})],eJ);var $z,KH=`${j1}.37`,WZ=$z=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,$z.prototype)}};WZ=$z=j([G0({type:i.Sequence,itemType:S.ObjectIdentifier})],WZ);var k90=`${KH}.0`,wP=`${_W}.1`,jP=`${_W}.2`,OP=`${_W}.3`,KP=`${_W}.4`,DP=`${_W}.8`,CP=`${_W}.9`;var u90=`${j1}.54`,Fz=class{value;constructor(Y=new ArrayBuffer(0)){this.value=Y}};j([K({type:S.Integer,converter:_1})],Fz.prototype,"value",void 0);Fz=j([G0({type:i.Choice})],Fz);var TP=`${j1}.24`,YZ=class{value=new Date;constructor(Y){if(Y)this.value=Y}};j([K({type:S.GeneralizedTime})],YZ.prototype,"value",void 0);YZ=j([G0({type:i.Choice})],YZ);var Sz,xz=`${j1}.18`,RP=Sz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,Sz.prototype)}};RP=Sz=j([G0({type:i.Sequence})],RP);var DH=`${j1}.15`,b5;(function(W){W[W.digitalSignature=1]="digitalSignature",W[W.nonRepudiation=2]="nonRepudiation",W[W.keyEncipherment=4]="keyEncipherment",W[W.dataEncipherment=8]="dataEncipherment",W[W.keyAgreement=16]="keyAgreement",W[W.keyCertSign=32]="keyCertSign",W[W.cRLSign=64]="cRLSign",W[W.encipherOnly=128]="encipherOnly",W[W.decipherOnly=256]="decipherOnly"})(b5||(b5={}));class GZ extends N4{toJSON(){let W=this.toNumber(),Y=[];if(W&b5.cRLSign)Y.push("crlSign");if(W&b5.dataEncipherment)Y.push("dataEncipherment");if(W&b5.decipherOnly)Y.push("decipherOnly");if(W&b5.digitalSignature)Y.push("digitalSignature");if(W&b5.encipherOnly)Y.push("encipherOnly");if(W&b5.keyAgreement)Y.push("keyAgreement");if(W&b5.keyCertSign)Y.push("keyCertSign");if(W&b5.keyEncipherment)Y.push("keyEncipherment");if(W&b5.nonRepudiation)Y.push("nonRepudiation");return Y}toString(){return`[${this.toJSON().join(", ")}]`}}var kz,Y50=`${j1}.30`;class XZ{base=new Q1;minimum=0;maximum;constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],XZ.prototype,"base",void 0);j([K({type:S.Integer,context:0,defaultValue:0,implicit:!0})],XZ.prototype,"minimum",void 0);j([K({type:S.Integer,context:1,optional:!0,implicit:!0})],XZ.prototype,"maximum",void 0);var CH=kz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,kz.prototype)}};CH=kz=j([G0({type:i.Sequence,itemType:XZ})],CH);class _z{permittedSubtrees;excludedSubtrees;constructor(W={}){Object.assign(this,W)}}j([K({type:CH,context:0,optional:!0,implicit:!0})],_z.prototype,"permittedSubtrees",void 0);j([K({type:CH,context:1,optional:!0,implicit:!0})],_z.prototype,"excludedSubtrees",void 0);var V50=`${j1}.36`;class yz{requireExplicitPolicy;inhibitPolicyMapping;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,context:0,implicit:!0,optional:!0,converter:_1})],yz.prototype,"requireExplicitPolicy",void 0);j([K({type:S.Integer,context:1,implicit:!0,optional:!0,converter:_1})],yz.prototype,"inhibitPolicyMapping",void 0);var vz,q50=`${j1}.33`;class TH{issuerDomainPolicy="";subjectDomainPolicy="";constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],TH.prototype,"issuerDomainPolicy",void 0);j([K({type:S.ObjectIdentifier})],TH.prototype,"subjectDomainPolicy",void 0);var MP=vz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,vz.prototype)}};MP=vz=j([G0({type:i.Sequence,itemType:TH})],MP);var gz,uz=`${j1}.17`,RH=gz=class extends z8{constructor(Y){super(Y);Object.setPrototypeOf(this,gz.prototype)}};RH=gz=j([G0({type:i.Sequence})],RH);class z9{type="";values=[];constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],z9.prototype,"type",void 0);j([K({type:S.Any,repeated:"set"})],z9.prototype,"values",void 0);var hz,L50=`${j1}.9`,PP=hz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,hz.prototype)}};PP=hz=j([G0({type:i.Sequence,itemType:z9})],PP);var bz=`${j1}.14`;class G5 extends yG{}var _50=`${j1}.16`;class mz{notBefore;notAfter;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralizedTime,context:0,implicit:!0,optional:!0})],mz.prototype,"notBefore",void 0);j([K({type:S.GeneralizedTime,context:1,implicit:!0,optional:!0})],mz.prototype,"notAfter",void 0);var JZ;(function(W){W[W.keyUpdateAllowed=1]="keyUpdateAllowed",W[W.newExtensions=2]="newExtensions",W[W.pKIXCertificate=4]="pKIXCertificate"})(JZ||(JZ={}));class fz extends N4{toJSON(){let W=[],Y=this.toNumber();if(Y&JZ.pKIXCertificate)W.push("pKIXCertificate");if(Y&JZ.newExtensions)W.push("newExtensions");if(Y&JZ.keyUpdateAllowed)W.push("keyUpdateAllowed");return W}toString(){return`[${this.toJSON().join(", ")}]`}}class cz{entrustVers="";entrustInfoFlags=new fz;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralString})],cz.prototype,"entrustVers",void 0);j([K({type:fz})],cz.prototype,"entrustInfoFlags",void 0);var pz,c50=`${T6}.11`,LP=pz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,pz.prototype)}};LP=pz=j([G0({type:i.Sequence,itemType:R6})],LP);class M0{algorithm="";parameters;constructor(W={}){Object.assign(this,W)}isEqual(W){return W instanceof M0&&W.algorithm==this.algorithm&&(W.parameters&&this.parameters&&Vz(W.parameters,this.parameters)||W.parameters===this.parameters)}}j([K({type:S.ObjectIdentifier})],M0.prototype,"algorithm",void 0);j([K({type:S.Any,optional:!0})],M0.prototype,"parameters",void 0);class w9{algorithm=new M0;subjectPublicKey=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],w9.prototype,"algorithm",void 0);j([K({type:S.BitString})],w9.prototype,"subjectPublicKey",void 0);var P8=class{utcTime;generalTime;constructor(Y){if(Y)if(typeof Y==="string"||typeof Y==="number"||Y instanceof Date){let G=new Date(Y);if(G.setMilliseconds(0),G.getUTCFullYear()>2049)this.generalTime=G;else this.utcTime=G}else Object.assign(this,Y)}getTime(){let Y=this.utcTime||this.generalTime;if(!Y)throw Error("Cannot get time from CHOICE object");return Y}};j([K({type:S.UTCTime})],P8.prototype,"utcTime",void 0);j([K({type:S.GeneralizedTime})],P8.prototype,"generalTime",void 0);P8=j([G0({type:i.Choice})],P8);class P6{notBefore=new P8(new Date);notAfter=new P8(new Date);constructor(W){if(W)this.notBefore=new P8(W.notBefore),this.notAfter=new P8(W.notAfter)}}j([K({type:P8})],P6.prototype,"notBefore",void 0);j([K({type:P8})],P6.prototype,"notAfter",void 0);var lz;class j9{static CRITICAL=!1;extnID="";critical=j9.CRITICAL;extnValue=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],j9.prototype,"extnID",void 0);j([K({type:S.Boolean,defaultValue:j9.CRITICAL})],j9.prototype,"critical",void 0);j([K({type:J1})],j9.prototype,"extnValue",void 0);var X5=lz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,lz.prototype)}};X5=lz=j([G0({type:i.Sequence,itemType:j9})],X5);var P7;(function(W){W[W.v1=0]="v1",W[W.v2=1]="v2",W[W.v3=2]="v3"})(P7||(P7={}));class O9{version=P7.v1;serialNumber=new ArrayBuffer(0);signature=new M0;issuer=new G8;validity=new P6;subject=new G8;subjectPublicKeyInfo=new w9;issuerUniqueID;subjectUniqueID;extensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,context:0,defaultValue:P7.v1})],O9.prototype,"version",void 0);j([K({type:S.Integer,converter:_1})],O9.prototype,"serialNumber",void 0);j([K({type:M0})],O9.prototype,"signature",void 0);j([K({type:G8})],O9.prototype,"issuer",void 0);j([K({type:P6})],O9.prototype,"validity",void 0);j([K({type:G8})],O9.prototype,"subject",void 0);j([K({type:w9})],O9.prototype,"subjectPublicKeyInfo",void 0);j([K({type:S.BitString,context:1,implicit:!0,optional:!0})],O9.prototype,"issuerUniqueID",void 0);j([K({type:S.BitString,context:2,implicit:!0,optional:!0})],O9.prototype,"subjectUniqueID",void 0);j([K({type:X5,context:3,optional:!0})],O9.prototype,"extensions",void 0);class m5{tbsCertificate=new O9;tbsCertificateRaw;signatureAlgorithm=new M0;signatureValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:O9,raw:!0})],m5.prototype,"tbsCertificate",void 0);j([K({type:M0})],m5.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],m5.prototype,"signatureValue",void 0);class uG{userCertificate=new ArrayBuffer(0);revocationDate=new P8;crlEntryExtensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],uG.prototype,"userCertificate",void 0);j([K({type:P8})],uG.prototype,"revocationDate",void 0);j([K({type:j9,optional:!0,repeated:"sequence"})],uG.prototype,"crlEntryExtensions",void 0);class M5{version;signature=new M0;issuer=new G8;thisUpdate=new P8;nextUpdate;revokedCertificates;crlExtensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,optional:!0})],M5.prototype,"version",void 0);j([K({type:M0})],M5.prototype,"signature",void 0);j([K({type:G8})],M5.prototype,"issuer",void 0);j([K({type:P8})],M5.prototype,"thisUpdate",void 0);j([K({type:P8,optional:!0})],M5.prototype,"nextUpdate",void 0);j([K({type:uG,repeated:"sequence",optional:!0})],M5.prototype,"revokedCertificates",void 0);j([K({type:j9,optional:!0,context:0,repeated:"sequence"})],M5.prototype,"crlExtensions",void 0);class hG{tbsCertList=new M5;tbsCertListRaw;signatureAlgorithm=new M0;signature=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M5,raw:!0})],hG.prototype,"tbsCertList",void 0);j([K({type:M0})],hG.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],hG.prototype,"signature",void 0);class L7{issuer=new G8;serialNumber=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:G8})],L7.prototype,"issuer",void 0);j([K({type:S.Integer,converter:_1})],L7.prototype,"serialNumber",void 0);var vW=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0})],vW.prototype,"subjectKeyIdentifier",void 0);j([K({type:L7})],vW.prototype,"issuerAndSerialNumber",void 0);vW=j([G0({type:i.Choice})],vW);var W9;(function(W){W[W.v0=0]="v0",W[W.v1=1]="v1",W[W.v2=2]="v2",W[W.v3=3]="v3",W[W.v4=4]="v4",W[W.v5=5]="v5"})(W9||(W9={}));var gW=class extends M0{};gW=j([G0({type:i.Sequence})],gW);var ZZ=class extends M0{};ZZ=j([G0({type:i.Sequence})],ZZ);var p9=class extends M0{};p9=j([G0({type:i.Sequence})],p9);var VZ=class extends M0{};VZ=j([G0({type:i.Sequence})],VZ);var EP=class extends M0{};EP=j([G0({type:i.Sequence})],EP);var MH=class extends M0{};MH=j([G0({type:i.Sequence})],MH);class B7{attrType="";attrValues=[];constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],B7.prototype,"attrType",void 0);j([K({type:S.Any,repeated:"set"})],B7.prototype,"attrValues",void 0);var dz;class J5{version=W9.v0;sid=new vW;digestAlgorithm=new gW;signedAttrs;signedAttrsRaw;signatureAlgorithm=new ZZ;signature=new J1;unsignedAttrs;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],J5.prototype,"version",void 0);j([K({type:vW})],J5.prototype,"sid",void 0);j([K({type:gW})],J5.prototype,"digestAlgorithm",void 0);j([K({type:B7,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],J5.prototype,"signedAttrs",void 0);j([K({type:ZZ})],J5.prototype,"signatureAlgorithm",void 0);j([K({type:J1})],J5.prototype,"signature",void 0);j([K({type:B7,repeated:"set",context:1,implicit:!0,optional:!0})],J5.prototype,"unsignedAttrs",void 0);var UZ=dz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,dz.prototype)}};UZ=dz=j([G0({type:i.Set,itemType:J5})],UZ);var $P=class extends J5{};$P=j([G0({type:i.Sequence})],$P);var FP=class extends P8{};FP=j([G0({type:i.Choice})],FP);class PH{acIssuer=new Q1;acSerial=0;attrs=[];constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],PH.prototype,"acIssuer",void 0);j([K({type:S.Integer})],PH.prototype,"acSerial",void 0);j([K({type:z9,repeated:"sequence"})],PH.prototype,"attrs",void 0);var oz,QZ=oz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,oz.prototype)}};QZ=oz=j([G0({type:i.Sequence,itemType:S.ObjectIdentifier})],QZ);class HZ{pathLenConstraint;permittedAttrs;excludedAttrs;permitUnSpecified=!0;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,optional:!0})],HZ.prototype,"pathLenConstraint",void 0);j([K({type:QZ,implicit:!0,context:0,optional:!0})],HZ.prototype,"permittedAttrs",void 0);j([K({type:QZ,implicit:!0,context:1,optional:!0})],HZ.prototype,"excludedAttrs",void 0);j([K({type:S.Boolean,defaultValue:!0})],HZ.prototype,"permitUnSpecified",void 0);class f5{issuer=new z8;serial=new ArrayBuffer(0);issuerUID=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:z8})],f5.prototype,"issuer",void 0);j([K({type:S.Integer,converter:_1})],f5.prototype,"serial",void 0);j([K({type:S.BitString,optional:!0})],f5.prototype,"issuerUID",void 0);var nz;(function(W){W[W.publicKey=0]="publicKey",W[W.publicKeyCert=1]="publicKeyCert",W[W.otherObjectTypes=2]="otherObjectTypes"})(nz||(nz={}));class c5{digestedObjectType=nz.publicKey;otherObjectTypeID;digestAlgorithm=new M0;objectDigest=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Enumerated})],c5.prototype,"digestedObjectType",void 0);j([K({type:S.ObjectIdentifier,optional:!0})],c5.prototype,"otherObjectTypeID",void 0);j([K({type:M0})],c5.prototype,"digestAlgorithm",void 0);j([K({type:S.BitString})],c5.prototype,"objectDigest",void 0);class bG{issuerName;baseCertificateID;objectDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:z8,optional:!0})],bG.prototype,"issuerName",void 0);j([K({type:f5,context:0,implicit:!0,optional:!0})],bG.prototype,"baseCertificateID",void 0);j([K({type:c5,context:1,implicit:!0,optional:!0})],bG.prototype,"objectDigestInfo",void 0);var uW=class{v1Form;v2Form;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,repeated:"sequence"})],uW.prototype,"v1Form",void 0);j([K({type:bG,context:0,implicit:!0})],uW.prototype,"v2Form",void 0);uW=j([G0({type:i.Choice})],uW);class mG{notBeforeTime=new Date;notAfterTime=new Date;constructor(W={}){Object.assign(this,W)}}j([K({type:S.GeneralizedTime})],mG.prototype,"notBeforeTime",void 0);j([K({type:S.GeneralizedTime})],mG.prototype,"notAfterTime",void 0);class hW{baseCertificateID;entityName;objectDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:f5,implicit:!0,context:0,optional:!0})],hW.prototype,"baseCertificateID",void 0);j([K({type:z8,implicit:!0,context:1,optional:!0})],hW.prototype,"entityName",void 0);j([K({type:c5,implicit:!0,context:2,optional:!0})],hW.prototype,"objectDigestInfo",void 0);var iz;(function(W){W[W.v2=1]="v2"})(iz||(iz={}));class Z5{version=iz.v2;holder=new hW;issuer=new uW;signature=new M0;serialNumber=new ArrayBuffer(0);attrCertValidityPeriod=new mG;attributes=[];issuerUniqueID;extensions;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],Z5.prototype,"version",void 0);j([K({type:hW})],Z5.prototype,"holder",void 0);j([K({type:uW})],Z5.prototype,"issuer",void 0);j([K({type:M0})],Z5.prototype,"signature",void 0);j([K({type:S.Integer,converter:_1})],Z5.prototype,"serialNumber",void 0);j([K({type:mG})],Z5.prototype,"attrCertValidityPeriod",void 0);j([K({type:z9,repeated:"sequence"})],Z5.prototype,"attributes",void 0);j([K({type:S.BitString,optional:!0})],Z5.prototype,"issuerUniqueID",void 0);j([K({type:X5,optional:!0})],Z5.prototype,"extensions",void 0);class fG{acinfo=new Z5;signatureAlgorithm=new M0;signatureValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:Z5})],fG.prototype,"acinfo",void 0);j([K({type:M0})],fG.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],fG.prototype,"signatureValue",void 0);var NZ;(function(W){W[W.unmarked=1]="unmarked",W[W.unclassified=2]="unclassified",W[W.restricted=4]="restricted",W[W.confidential=8]="confidential",W[W.secret=16]="secret",W[W.topSecret=32]="topSecret"})(NZ||(NZ={}));class qZ extends N4{}class AZ{type="";value=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier,implicit:!0,context:0})],AZ.prototype,"type",void 0);j([K({type:S.Any,implicit:!0,context:1})],AZ.prototype,"value",void 0);class LH{policyId="";classList=new qZ(NZ.unclassified);securityCategories;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],LH.prototype,"policyId",void 0);j([K({type:qZ,defaultValue:new qZ(NZ.unclassified)})],LH.prototype,"classList",void 0);j([K({type:AZ,repeated:"set"})],LH.prototype,"securityCategories",void 0);class IZ{cotets;oid;string;constructor(W={}){Object.assign(this,W)}}j([K({type:J1})],IZ.prototype,"cotets",void 0);j([K({type:S.ObjectIdentifier})],IZ.prototype,"oid",void 0);j([K({type:S.Utf8String})],IZ.prototype,"string",void 0);class rz{policyAuthority;values=[];constructor(W={}){Object.assign(this,W)}}j([K({type:z8,implicit:!0,context:0,optional:!0})],rz.prototype,"policyAuthority",void 0);j([K({type:IZ,repeated:"sequence"})],rz.prototype,"values",void 0);var OW0=`${T6}.4`,KW0=`${T6}.6`,DW0=`${T6}.10`,CW0=`${j1}.55`,zZ=`${UH}.10`,TW0=`${zZ}.1`,RW0=`${zZ}.2`,MW0=`${zZ}.3`,PW0=`${zZ}.4`,LW0=`${zZ}.6`,az="2.5.4",BW0=`${az}.72`;var sz;class wZ{targetCertificate=new f5;targetName;certDigestInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:f5})],wZ.prototype,"targetCertificate",void 0);j([K({type:Q1,optional:!0})],wZ.prototype,"targetName",void 0);j([K({type:c5,optional:!0})],wZ.prototype,"certDigestInfo",void 0);var cG=class{targetName;targetGroup;targetCert;constructor(Y={}){Object.assign(this,Y)}};j([K({type:Q1,context:0,implicit:!0})],cG.prototype,"targetName",void 0);j([K({type:Q1,context:1,implicit:!0})],cG.prototype,"targetGroup",void 0);j([K({type:wZ,context:2,implicit:!0})],cG.prototype,"targetCert",void 0);cG=j([G0({type:i.Choice})],cG);var BH=sz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,sz.prototype)}};BH=sz=j([G0({type:i.Sequence,itemType:cG})],BH);var tz,SP=tz=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,tz.prototype)}};SP=tz=j([G0({type:i.Sequence,itemType:BH})],SP);class ez{roleAuthority;roleName;constructor(W={}){Object.assign(this,W)}}j([K({type:z8,implicit:!0,context:0,optional:!0})],ez.prototype,"roleAuthority",void 0);j([K({type:Q1,implicit:!0,context:1})],ez.prototype,"roleName",void 0);class EH{service=new Q1;ident=new Q1;authInfo;constructor(W={}){Object.assign(this,W)}}j([K({type:Q1})],EH.prototype,"service",void 0);j([K({type:Q1})],EH.prototype,"ident",void 0);j([K({type:J1,optional:!0})],EH.prototype,"authInfo",void 0);var Ww;class $H{otherCertFormat="";otherCert=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],$H.prototype,"otherCertFormat",void 0);j([K({type:S.Any})],$H.prototype,"otherCert",void 0);var bW=class{certificate;v2AttrCert;other;constructor(Y={}){Object.assign(this,Y)}};j([K({type:m5})],bW.prototype,"certificate",void 0);j([K({type:fG,context:2,implicit:!0})],bW.prototype,"v2AttrCert",void 0);j([K({type:$H,context:3,implicit:!0})],bW.prototype,"other",void 0);bW=j([G0({type:i.Choice})],bW);var mW=Ww=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Ww.prototype)}};mW=Ww=j([G0({type:i.Set,itemType:bW})],mW);class p5{contentType="";content=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],p5.prototype,"contentType",void 0);j([K({type:S.Any,context:0})],p5.prototype,"content",void 0);var pG=class{single;any;constructor(Y={}){Object.assign(this,Y)}};j([K({type:J1})],pG.prototype,"single",void 0);j([K({type:S.Any})],pG.prototype,"any",void 0);pG=j([G0({type:i.Choice})],pG);class lG{eContentType="";eContent;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],lG.prototype,"eContentType",void 0);j([K({type:pG,context:0,optional:!0})],lG.prototype,"eContent",void 0);var jZ=class{value;constructedValue;constructor(Y={}){Object.assign(this,Y)}};j([K({type:J1,context:0,implicit:!0,optional:!0})],jZ.prototype,"value",void 0);j([K({type:J1,converter:EM,context:0,implicit:!0,optional:!0,repeated:"sequence"})],jZ.prototype,"constructedValue",void 0);jZ=j([G0({type:i.Choice})],jZ);class fW{contentType="";contentEncryptionAlgorithm=new VZ;encryptedContent;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],fW.prototype,"contentType",void 0);j([K({type:VZ})],fW.prototype,"contentEncryptionAlgorithm",void 0);j([K({type:jZ,optional:!0})],fW.prototype,"encryptedContent",void 0);class cW{keyAttrId="";keyAttr;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],cW.prototype,"keyAttrId",void 0);j([K({type:S.Any,optional:!0})],cW.prototype,"keyAttr",void 0);var Yw;class OZ{subjectKeyIdentifier=new G5;date;other;constructor(W={}){Object.assign(this,W)}}j([K({type:G5})],OZ.prototype,"subjectKeyIdentifier",void 0);j([K({type:S.GeneralizedTime,optional:!0})],OZ.prototype,"date",void 0);j([K({type:cW,optional:!0})],OZ.prototype,"other",void 0);var dG=class{rKeyId;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:OZ,context:0,implicit:!0,optional:!0})],dG.prototype,"rKeyId",void 0);j([K({type:L7,optional:!0})],dG.prototype,"issuerAndSerialNumber",void 0);dG=j([G0({type:i.Choice})],dG);class SH{rid=new dG;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:dG})],SH.prototype,"rid",void 0);j([K({type:J1})],SH.prototype,"encryptedKey",void 0);var FH=Yw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Yw.prototype)}};FH=Yw=j([G0({type:i.Sequence,itemType:SH})],FH);class xH{algorithm=new M0;publicKey=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],xH.prototype,"algorithm",void 0);j([K({type:S.BitString})],xH.prototype,"publicKey",void 0);var pW=class{subjectKeyIdentifier;originatorKey;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0,optional:!0})],pW.prototype,"subjectKeyIdentifier",void 0);j([K({type:xH,context:1,implicit:!0,optional:!0})],pW.prototype,"originatorKey",void 0);j([K({type:L7,optional:!0})],pW.prototype,"issuerAndSerialNumber",void 0);pW=j([G0({type:i.Choice})],pW);class L6{version=W9.v3;originator=new pW;ukm;keyEncryptionAlgorithm=new p9;recipientEncryptedKeys=new FH;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],L6.prototype,"version",void 0);j([K({type:pW,context:0})],L6.prototype,"originator",void 0);j([K({type:J1,context:1,optional:!0})],L6.prototype,"ukm",void 0);j([K({type:p9})],L6.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:FH})],L6.prototype,"recipientEncryptedKeys",void 0);var oG=class{subjectKeyIdentifier;issuerAndSerialNumber;constructor(Y={}){Object.assign(this,Y)}};j([K({type:G5,context:0,implicit:!0})],oG.prototype,"subjectKeyIdentifier",void 0);j([K({type:L7})],oG.prototype,"issuerAndSerialNumber",void 0);oG=j([G0({type:i.Choice})],oG);class lW{version=W9.v0;rid=new oG;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],lW.prototype,"version",void 0);j([K({type:oG})],lW.prototype,"rid",void 0);j([K({type:p9})],lW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],lW.prototype,"encryptedKey",void 0);class nG{keyIdentifier=new J1;date;other;constructor(W={}){Object.assign(this,W)}}j([K({type:J1})],nG.prototype,"keyIdentifier",void 0);j([K({type:S.GeneralizedTime,optional:!0})],nG.prototype,"date",void 0);j([K({type:cW,optional:!0})],nG.prototype,"other",void 0);class dW{version=W9.v4;kekid=new nG;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],dW.prototype,"version",void 0);j([K({type:nG})],dW.prototype,"kekid",void 0);j([K({type:p9})],dW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],dW.prototype,"encryptedKey",void 0);class oW{version=W9.v0;keyDerivationAlgorithm;keyEncryptionAlgorithm=new p9;encryptedKey=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],oW.prototype,"version",void 0);j([K({type:MH,context:0,optional:!0})],oW.prototype,"keyDerivationAlgorithm",void 0);j([K({type:p9})],oW.prototype,"keyEncryptionAlgorithm",void 0);j([K({type:J1})],oW.prototype,"encryptedKey",void 0);class kH{oriType="";oriValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],kH.prototype,"oriType",void 0);j([K({type:S.Any})],kH.prototype,"oriValue",void 0);var w4=class{ktri;kari;kekri;pwri;ori;constructor(Y={}){Object.assign(this,Y)}};j([K({type:lW,optional:!0})],w4.prototype,"ktri",void 0);j([K({type:L6,context:1,implicit:!0,optional:!0})],w4.prototype,"kari",void 0);j([K({type:dW,context:2,implicit:!0,optional:!0})],w4.prototype,"kekri",void 0);j([K({type:oW,context:3,implicit:!0,optional:!0})],w4.prototype,"pwri",void 0);j([K({type:kH,context:4,implicit:!0,optional:!0})],w4.prototype,"ori",void 0);w4=j([G0({type:i.Choice})],w4);var Gw,KZ=Gw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Gw.prototype)}};KZ=Gw=j([G0({type:i.Set,itemType:w4})],KZ);var Xw,xP=`${UH}.16`,AG0=`${xP}.2`,IG0=`${xP}.4`;class DZ{otherRevInfoFormat="";otherRevInfo=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],DZ.prototype,"otherRevInfoFormat",void 0);j([K({type:S.Any})],DZ.prototype,"otherRevInfo",void 0);var _H=class{other=new DZ;constructor(Y={}){Object.assign(this,Y)}};j([K({type:DZ,context:1,implicit:!0})],_H.prototype,"other",void 0);_H=j([G0({type:i.Choice})],_H);var iG=Xw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Xw.prototype)}};iG=Xw=j([G0({type:i.Set,itemType:_H})],iG);class CZ{certs;crls;constructor(W={}){Object.assign(this,W)}}j([K({type:mW,context:0,implicit:!0,optional:!0})],CZ.prototype,"certs",void 0);j([K({type:iG,context:1,implicit:!0,optional:!0})],CZ.prototype,"crls",void 0);var Jw,Zw=Jw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Jw.prototype)}};Zw=Jw=j([G0({type:i.Set,itemType:B7})],Zw);class rG{version=W9.v0;originatorInfo;recipientInfos=new KZ;encryptedContentInfo=new fW;unprotectedAttrs;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],rG.prototype,"version",void 0);j([K({type:CZ,context:0,implicit:!0,optional:!0})],rG.prototype,"originatorInfo",void 0);j([K({type:KZ})],rG.prototype,"recipientInfos",void 0);j([K({type:fW})],rG.prototype,"encryptedContentInfo",void 0);j([K({type:Zw,context:1,implicit:!0,optional:!0})],rG.prototype,"unprotectedAttrs",void 0);var kP="1.2.840.113549.1.7.2";var Vw,yH=Vw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Vw.prototype)}};yH=Vw=j([G0({type:i.Set,itemType:gW})],yH);class B6{version=W9.v0;digestAlgorithms=new yH;encapContentInfo=new lG;certificates;crls;signerInfos=new UZ;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],B6.prototype,"version",void 0);j([K({type:yH})],B6.prototype,"digestAlgorithms",void 0);j([K({type:lG})],B6.prototype,"encapContentInfo",void 0);j([K({type:mW,context:0,implicit:!0,optional:!0})],B6.prototype,"certificates",void 0);j([K({type:iG,context:1,implicit:!0,optional:!0})],B6.prototype,"crls",void 0);j([K({type:UZ})],B6.prototype,"signerInfos",void 0);var nW="1.2.840.10045.2.1";var TZ="1.2.840.10045.4.1",vH="1.2.840.10045.4.3.1",RZ="1.2.840.10045.4.3.2",MZ="1.2.840.10045.4.3.3",PZ="1.2.840.10045.4.3.4";var Uw="1.2.840.10045.3.1.7";var Qw="1.3.132.0.34";var Hw="1.3.132.0.35";function LZ(W){return new M0({algorithm:W})}var yP=LZ(TZ),ZX0=LZ(vH),vP=LZ(RZ),gP=LZ(MZ),uP=LZ(PZ);var BZ=class{fieldType;parameters;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.ObjectIdentifier})],BZ.prototype,"fieldType",void 0);j([K({type:S.Any})],BZ.prototype,"parameters",void 0);BZ=j([G0({type:i.Sequence})],BZ);class hP extends J1{}var aG=class{a;b;seed;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.OctetString})],aG.prototype,"a",void 0);j([K({type:S.OctetString})],aG.prototype,"b",void 0);j([K({type:S.BitString,optional:!0})],aG.prototype,"seed",void 0);aG=j([G0({type:i.Sequence})],aG);var Nw;(function(W){W[W.ecpVer1=1]="ecpVer1"})(Nw||(Nw={}));var E7=class{version=Nw.ecpVer1;fieldID;curve;base;order;cofactor;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.Integer})],E7.prototype,"version",void 0);j([K({type:BZ})],E7.prototype,"fieldID",void 0);j([K({type:aG})],E7.prototype,"curve",void 0);j([K({type:hP})],E7.prototype,"base",void 0);j([K({type:S.Integer,converter:_1})],E7.prototype,"order",void 0);j([K({type:S.Integer,optional:!0})],E7.prototype,"cofactor",void 0);E7=j([G0({type:i.Sequence})],E7);var $7=class{namedCurve;implicitCurve;specifiedCurve;constructor(Y={}){Object.assign(this,Y)}};j([K({type:S.ObjectIdentifier})],$7.prototype,"namedCurve",void 0);j([K({type:S.Null})],$7.prototype,"implicitCurve",void 0);j([K({type:E7})],$7.prototype,"specifiedCurve",void 0);$7=j([G0({type:i.Choice})],$7);class EZ{version=1;privateKey=new J1;parameters;publicKey;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],EZ.prototype,"version",void 0);j([K({type:J1})],EZ.prototype,"privateKey",void 0);j([K({type:$7,context:0,optional:!0})],EZ.prototype,"parameters",void 0);j([K({type:S.BitString,context:1,optional:!0})],EZ.prototype,"publicKey",void 0);class sG{r=new ArrayBuffer(0);s=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],sG.prototype,"r",void 0);j([K({type:S.Integer,converter:_1})],sG.prototype,"s",void 0);var F7="1.2.840.113549.1.1.1",bP="1.2.840.113549.1.1.7",mP="1.2.840.113549.1.1.9",E6="1.2.840.113549.1.1.10",fP="1.2.840.113549.1.1.2",cP="1.2.840.113549.1.1.4",tG="1.2.840.113549.1.1.5",pP="1.2.840.113549.1.1.14";var gH="1.2.840.113549.1.1.11",eG="1.2.840.113549.1.1.12",WX="1.2.840.113549.1.1.13",qw="1.2.840.113549.1.1.15",Aw="1.2.840.113549.1.1.16",iW="1.3.14.3.2.26",uH="2.16.840.1.101.3.4.2.4",rW="2.16.840.1.101.3.4.2.1",aW="2.16.840.1.101.3.4.2.2",sW="2.16.840.1.101.3.4.2.3",lP="2.16.840.1.101.3.4.2.5",dP="2.16.840.1.101.3.4.2.6",oP="1.2.840.113549.2.2",nP="1.2.840.113549.2.5",$6="1.2.840.113549.1.1.8";function l8(W){return new M0({algorithm:W,parameters:null})}var FX0=l8(oP),SX0=l8(nP),j4=l8(iW),xX0=l8(uH),kX0=l8(rW),_X0=l8(aW),yX0=l8(sW),vX0=l8(lP),gX0=l8(dP),hH=new M0({algorithm:$6,parameters:E0.serialize(j4)}),Iw=new M0({algorithm:mP,parameters:E0.serialize(FG.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),uX0=l8(F7),hX0=l8(fP),bX0=l8(cP),mX0=l8(tG),fX0=l8(qw),cX0=l8(Aw),pX0=l8(eG),lX0=l8(WX),dX0=l8(qw),oX0=l8(Aw);class $Z{hashAlgorithm=new M0(j4);maskGenAlgorithm=new M0({algorithm:$6,parameters:E0.serialize(j4)});pSourceAlgorithm=new M0(Iw);constructor(W={}){Object.assign(this,W)}}j([K({type:M0,context:0,defaultValue:j4})],$Z.prototype,"hashAlgorithm",void 0);j([K({type:M0,context:1,defaultValue:hH})],$Z.prototype,"maskGenAlgorithm",void 0);j([K({type:M0,context:2,defaultValue:Iw})],$Z.prototype,"pSourceAlgorithm",void 0);var eX0=new M0({algorithm:bP,parameters:E0.serialize(new $Z)});class O4{hashAlgorithm=new M0(j4);maskGenAlgorithm=new M0({algorithm:$6,parameters:E0.serialize(j4)});saltLength=20;trailerField=1;constructor(W={}){Object.assign(this,W)}}j([K({type:M0,context:0,defaultValue:j4})],O4.prototype,"hashAlgorithm",void 0);j([K({type:M0,context:1,defaultValue:hH})],O4.prototype,"maskGenAlgorithm",void 0);j([K({type:S.Integer,context:2,defaultValue:20})],O4.prototype,"saltLength",void 0);j([K({type:S.Integer,context:3,defaultValue:1})],O4.prototype,"trailerField",void 0);var VJ0=new M0({algorithm:E6,parameters:E0.serialize(new O4)});class YX{digestAlgorithm=new M0;digest=new J1;constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],YX.prototype,"digestAlgorithm",void 0);j([K({type:J1})],YX.prototype,"digest",void 0);var zw;class FZ{prime=new ArrayBuffer(0);exponent=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],FZ.prototype,"prime",void 0);j([K({type:S.Integer,converter:_1})],FZ.prototype,"exponent",void 0);j([K({type:S.Integer,converter:_1})],FZ.prototype,"coefficient",void 0);var bH=zw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,zw.prototype)}};bH=zw=j([G0({type:i.Sequence,itemType:FZ})],bH);class l5{version=0;modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);privateExponent=new ArrayBuffer(0);prime1=new ArrayBuffer(0);prime2=new ArrayBuffer(0);exponent1=new ArrayBuffer(0);exponent2=new ArrayBuffer(0);coefficient=new ArrayBuffer(0);otherPrimeInfos;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],l5.prototype,"version",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"modulus",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"publicExponent",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"privateExponent",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"prime1",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"prime2",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"exponent1",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"exponent2",void 0);j([K({type:S.Integer,converter:_1})],l5.prototype,"coefficient",void 0);j([K({type:bH,optional:!0})],l5.prototype,"otherPrimeInfos",void 0);class SZ{modulus=new ArrayBuffer(0);publicExponent=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer,converter:_1})],SZ.prototype,"modulus",void 0);j([K({type:S.Integer,converter:_1})],SZ.prototype,"publicExponent",void 0);var ww;(function(W){W[W.Transient=0]="Transient",W[W.Singleton=1]="Singleton",W[W.ResolutionScoped=2]="ResolutionScoped",W[W.ContainerScoped=3]="ContainerScoped"})(ww||(ww={}));var Y9=ww;var wL=v1(zL(),1),{__extends:xZ,__assign:gJ0,__rest:uJ0,__decorate:hJ0,__param:bJ0,__metadata:mJ0,__awaiter:jL,__generator:OL,__exportStar:fJ0,__createBinding:cJ0,__values:kZ,__read:XX,__spread:S7,__spreadArrays:pJ0,__await:lJ0,__asyncGenerator:dJ0,__asyncDelegator:oJ0,__asyncValues:nJ0,__makeTemplateObject:iJ0,__importStar:rJ0,__importDefault:aJ0,__classPrivateFieldGet:sJ0,__classPrivateFieldSet:tJ0}=wL.default;var uf="injectionTokens";function Ow(W){var Y=Reflect.getMetadata("design:paramtypes",W)||[],G=Reflect.getOwnMetadata(uf,W)||{};return Object.keys(G).forEach(function(X){Y[+X]=G[X]}),Y}function _Z(W){return!!W.useClass}function JX(W){return!!W.useFactory}var cH=function(){function W(Y){this.wrap=Y,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return W.prototype.createProxy=function(Y){var G=this,X={},J=!1,Z,V=function(){if(!J)Z=Y(G.wrap()),J=!0;return Z};return new Proxy(X,this.createHandler(V))},W.prototype.createHandler=function(Y){var G={},X=function(J){G[J]=function(){var Z=[];for(var V=0;V<arguments.length;V++)Z[V]=arguments[V];Z[0]=Y();var U=Reflect[J];return U.apply(void 0,S7(Z))}};return this.reflectMethods.forEach(X),G},W}();function F6(W){return typeof W==="string"||typeof W==="symbol"}function Kw(W){return typeof W==="object"&&"token"in W&&"multiple"in W}function pH(W){return typeof W==="object"&&"token"in W&&"transform"in W}function KL(W){return typeof W==="function"||W instanceof cH}function tW(W){return!!W.useToken}function eW(W){return W.useValue!=null}function DL(W){return _Z(W)||eW(W)||tW(W)||JX(W)}var hf=function(){function W(){this._registryMap=new Map}return W.prototype.entries=function(){return this._registryMap.entries()},W.prototype.getAll=function(Y){return this.ensure(Y),this._registryMap.get(Y)},W.prototype.get=function(Y){this.ensure(Y);var G=this._registryMap.get(Y);return G[G.length-1]||null},W.prototype.set=function(Y,G){this.ensure(Y),this._registryMap.get(Y).push(G)},W.prototype.setAll=function(Y,G){this._registryMap.set(Y,G)},W.prototype.has=function(Y){return this.ensure(Y),this._registryMap.get(Y).length>0},W.prototype.clear=function(){this._registryMap.clear()},W.prototype.ensure=function(Y){if(!this._registryMap.has(Y))this._registryMap.set(Y,[])},W}(),yZ=hf;var bf=function(W){xZ(Y,W);function Y(){return W!==null&&W.apply(this,arguments)||this}return Y}(yZ),CL=bf;var mf=function(){function W(){this.scopedResolutions=new Map}return W}(),vZ=mf;function ff(W,Y){if(W===null)return"at position #"+Y;var G=W.split(",")[Y].trim();return'"'+G+'" at position #'+Y}function cf(W,Y,G){if(G===void 0)G=" ";return S7([W],Y.message.split(`
|
|
214
214
|
`).map(function(X){return G+X})).join(`
|
|
215
215
|
`)}function Dw(W,Y,G){var X=XX(W.toString().match(/constructor\(([\w, ]+)\)/)||[],2),J=X[1],Z=J===void 0?null:J,V=ff(Z,Y);return cf("Cannot inject the dependency "+V+' of "'+W.name+'" constructor. Reason:',G)}function TL(W){if(typeof W.dispose!=="function")return!1;var Y=W.dispose;if(Y.length>0)return!1;return!0}var pf=function(W){xZ(Y,W);function Y(){return W!==null&&W.apply(this,arguments)||this}return Y}(yZ);var lf=function(W){xZ(Y,W);function Y(){return W!==null&&W.apply(this,arguments)||this}return Y}(yZ);var df=function(){function W(){this.preResolution=new pf,this.postResolution=new lf}return W}(),RL=df;var Cw=new Map,of=function(){function W(Y){this.parent=Y,this._registry=new CL,this.interceptors=new RL,this.disposed=!1,this.disposables=new Set}return W.prototype.register=function(Y,G,X){if(X===void 0)X={lifecycle:Y9.Transient};this.ensureNotDisposed();var J;if(!DL(G))J={useClass:G};else J=G;if(tW(J)){var Z=[Y],V=J;while(V!=null){var U=V.useToken;if(Z.includes(U))throw Error("Token registration cycle detected! "+S7(Z,[U]).join(" -> "));Z.push(U);var Q=this._registry.get(U);if(Q&&tW(Q.provider))V=Q.provider;else V=null}}if(X.lifecycle===Y9.Singleton||X.lifecycle==Y9.ContainerScoped||X.lifecycle==Y9.ResolutionScoped){if(eW(J)||JX(J))throw Error('Cannot use lifecycle "'+Y9[X.lifecycle]+'" with ValueProviders or FactoryProviders')}return this._registry.set(Y,{provider:J,options:X}),this},W.prototype.registerType=function(Y,G){if(this.ensureNotDisposed(),F6(G))return this.register(Y,{useToken:G});return this.register(Y,{useClass:G})},W.prototype.registerInstance=function(Y,G){return this.ensureNotDisposed(),this.register(Y,{useValue:G})},W.prototype.registerSingleton=function(Y,G){if(this.ensureNotDisposed(),F6(Y)){if(F6(G))return this.register(Y,{useToken:G},{lifecycle:Y9.Singleton});else if(G)return this.register(Y,{useClass:G},{lifecycle:Y9.Singleton});throw Error('Cannot register a type name as a singleton without a "to" token')}var X=Y;if(G&&!F6(G))X=G;return this.register(Y,{useClass:X},{lifecycle:Y9.Singleton})},W.prototype.resolve=function(Y,G,X){if(G===void 0)G=new vZ;if(X===void 0)X=!1;this.ensureNotDisposed();var J=this.getRegistration(Y);if(!J&&F6(Y)){if(X)return;throw Error('Attempted to resolve unregistered dependency token: "'+Y.toString()+'"')}if(this.executePreResolutionInterceptor(Y,"Single"),J){var Z=this.resolveRegistration(J,G);return this.executePostResolutionInterceptor(Y,Z,"Single"),Z}if(KL(Y)){var Z=this.construct(Y,G);return this.executePostResolutionInterceptor(Y,Z,"Single"),Z}throw Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},W.prototype.executePreResolutionInterceptor=function(Y,G){var X,J;if(this.interceptors.preResolution.has(Y)){var Z=[];try{for(var V=kZ(this.interceptors.preResolution.getAll(Y)),U=V.next();!U.done;U=V.next()){var Q=U.value;if(Q.options.frequency!="Once")Z.push(Q);Q.callback(Y,G)}}catch(H){X={error:H}}finally{try{if(U&&!U.done&&(J=V.return))J.call(V)}finally{if(X)throw X.error}}this.interceptors.preResolution.setAll(Y,Z)}},W.prototype.executePostResolutionInterceptor=function(Y,G,X){var J,Z;if(this.interceptors.postResolution.has(Y)){var V=[];try{for(var U=kZ(this.interceptors.postResolution.getAll(Y)),Q=U.next();!Q.done;Q=U.next()){var H=Q.value;if(H.options.frequency!="Once")V.push(H);H.callback(Y,G,X)}}catch(N){J={error:N}}finally{try{if(Q&&!Q.done&&(Z=U.return))Z.call(U)}finally{if(J)throw J.error}}this.interceptors.postResolution.setAll(Y,V)}},W.prototype.resolveRegistration=function(Y,G){if(this.ensureNotDisposed(),Y.options.lifecycle===Y9.ResolutionScoped&&G.scopedResolutions.has(Y))return G.scopedResolutions.get(Y);var X=Y.options.lifecycle===Y9.Singleton,J=Y.options.lifecycle===Y9.ContainerScoped,Z=X||J,V;if(eW(Y.provider))V=Y.provider.useValue;else if(tW(Y.provider))V=Z?Y.instance||(Y.instance=this.resolve(Y.provider.useToken,G)):this.resolve(Y.provider.useToken,G);else if(_Z(Y.provider))V=Z?Y.instance||(Y.instance=this.construct(Y.provider.useClass,G)):this.construct(Y.provider.useClass,G);else if(JX(Y.provider))V=Y.provider.useFactory(this);else V=this.construct(Y.provider,G);if(Y.options.lifecycle===Y9.ResolutionScoped)G.scopedResolutions.set(Y,V);return V},W.prototype.resolveAll=function(Y,G,X){var J=this;if(G===void 0)G=new vZ;if(X===void 0)X=!1;this.ensureNotDisposed();var Z=this.getAllRegistrations(Y);if(!Z&&F6(Y)){if(X)return[];throw Error('Attempted to resolve unregistered dependency token: "'+Y.toString()+'"')}if(this.executePreResolutionInterceptor(Y,"All"),Z){var V=Z.map(function(Q){return J.resolveRegistration(Q,G)});return this.executePostResolutionInterceptor(Y,V,"All"),V}var U=[this.construct(Y,G)];return this.executePostResolutionInterceptor(Y,U,"All"),U},W.prototype.isRegistered=function(Y,G){if(G===void 0)G=!1;return this.ensureNotDisposed(),this._registry.has(Y)||G&&(this.parent||!1)&&this.parent.isRegistered(Y,!0)},W.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},W.prototype.clearInstances=function(){var Y,G;this.ensureNotDisposed();try{for(var X=kZ(this._registry.entries()),J=X.next();!J.done;J=X.next()){var Z=XX(J.value,2),V=Z[0],U=Z[1];this._registry.setAll(V,U.filter(function(Q){return!eW(Q.provider)}).map(function(Q){return Q.instance=void 0,Q}))}}catch(Q){Y={error:Q}}finally{try{if(J&&!J.done&&(G=X.return))G.call(X)}finally{if(Y)throw Y.error}}},W.prototype.createChildContainer=function(){var Y,G;this.ensureNotDisposed();var X=new W(this);try{for(var J=kZ(this._registry.entries()),Z=J.next();!Z.done;Z=J.next()){var V=XX(Z.value,2),U=V[0],Q=V[1];if(Q.some(function(H){var N=H.options;return N.lifecycle===Y9.ContainerScoped}))X._registry.setAll(U,Q.map(function(H){if(H.options.lifecycle===Y9.ContainerScoped)return{provider:H.provider,options:H.options};return H}))}}catch(H){Y={error:H}}finally{try{if(Z&&!Z.done&&(G=J.return))G.call(J)}finally{if(Y)throw Y.error}}return X},W.prototype.beforeResolution=function(Y,G,X){if(X===void 0)X={frequency:"Always"};this.interceptors.preResolution.set(Y,{callback:G,options:X})},W.prototype.afterResolution=function(Y,G,X){if(X===void 0)X={frequency:"Always"};this.interceptors.postResolution.set(Y,{callback:G,options:X})},W.prototype.dispose=function(){return jL(this,void 0,void 0,function(){var Y;return OL(this,function(G){switch(G.label){case 0:return this.disposed=!0,Y=[],this.disposables.forEach(function(X){var J=X.dispose();if(J)Y.push(J)}),[4,Promise.all(Y)];case 1:return G.sent(),[2]}})})},W.prototype.getRegistration=function(Y){if(this.isRegistered(Y))return this._registry.get(Y);if(this.parent)return this.parent.getRegistration(Y);return null},W.prototype.getAllRegistrations=function(Y){if(this.isRegistered(Y))return this._registry.getAll(Y);if(this.parent)return this.parent.getAllRegistrations(Y);return null},W.prototype.construct=function(Y,G){var X=this;if(Y instanceof cH)return Y.createProxy(function(Z){return X.resolve(Z,G)});var J=function(){var Z=Cw.get(Y);if(!Z||Z.length===0)if(Y.length===0)return new Y;else throw Error('TypeInfo not known for "'+Y.name+'"');var V=Z.map(X.resolveParams(G,Y));return new(Y.bind.apply(Y,S7([void 0],V)))}();if(TL(J))this.disposables.add(J);return J},W.prototype.resolveParams=function(Y,G){var X=this;return function(J,Z){var V,U,Q;try{if(Kw(J))if(pH(J))return J.multiple?(V=X.resolve(J.transform)).transform.apply(V,S7([X.resolveAll(J.token,new vZ,J.isOptional)],J.transformArgs)):(U=X.resolve(J.transform)).transform.apply(U,S7([X.resolve(J.token,Y,J.isOptional)],J.transformArgs));else return J.multiple?X.resolveAll(J.token,new vZ,J.isOptional):X.resolve(J.token,Y,J.isOptional);else if(pH(J))return(Q=X.resolve(J.transform,Y)).transform.apply(Q,S7([X.resolve(J.token,Y)],J.transformArgs));return X.resolve(J,Y)}catch(H){throw Error(Dw(G,Z,H))}}},W.prototype.ensureNotDisposed=function(){if(this.disposed)throw Error("This container has been disposed, you cannot interact with a disposed container")},W}(),Q8=new of;function nf(W){return function(Y){if(Cw.set(Y,Ow(Y)),W&&W.token)if(!Array.isArray(W.token))Q8.register(W.token,Y);else W.token.forEach(function(G){Q8.register(G,Y)})}}var S6=nf;if(typeof Reflect>"u"||!Reflect.getMetadata)throw Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var Rw;class ZX{attrId="";attrValues=[];constructor(W={}){Object.assign(W)}}j([K({type:S.ObjectIdentifier})],ZX.prototype,"attrId",void 0);j([K({type:S.Any,repeated:"set"})],ZX.prototype,"attrValues",void 0);var ML=Rw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Rw.prototype)}};ML=Rw=j([G0({type:i.Sequence,itemType:ZX})],ML);var Mw,PL=Mw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Mw.prototype)}};PL=Mw=j([G0({type:i.Sequence,itemType:p5})],PL);var WY="1.2.840.113549.1.12.10.1";var ZU0=`${WY}.1`,VU0=`${WY}.2`,UU0=`${WY}.3`,QU0=`${WY}.4`,HU0=`${WY}.5`,NU0=`${WY}.6`,lH="1.2.840.113549.1.9";class Pw{certId="";certValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],Pw.prototype,"certId",void 0);j([K({type:S.Any,context:0})],Pw.prototype,"certValue",void 0);var LL=`${lH}.22`,wU0=`${LL}.1`,jU0=`${LL}.2`;class Lw{crlId="";crltValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],Lw.prototype,"crlId",void 0);j([K({type:S.Any,context:0})],Lw.prototype,"crltValue",void 0);var rf=`${lH}.23`,TU0=`${rf}.1`;class Bw extends J1{}class YY{encryptionAlgorithm=new M0;encryptedData=new Bw;constructor(W={}){Object.assign(this,W)}}j([K({type:M0})],YY.prototype,"encryptionAlgorithm",void 0);j([K({type:Bw})],YY.prototype,"encryptedData",void 0);var Ew,$w;(function(W){W[W.v1=0]="v1"})($w||($w={}));class Sw extends J1{}var Fw=Ew=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,Ew.prototype)}};Fw=Ew=j([G0({type:i.Sequence,itemType:z9})],Fw);class GY{version=$w.v1;privateKeyAlgorithm=new M0;privateKey=new Sw;attributes;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],GY.prototype,"version",void 0);j([K({type:M0})],GY.prototype,"privateKeyAlgorithm",void 0);j([K({type:Sw})],GY.prototype,"privateKey",void 0);j([K({type:Fw,implicit:!0,context:0,optional:!0})],GY.prototype,"attributes",void 0);var BL=class extends GY{};BL=j([G0({type:i.Sequence})],BL);var EL=class extends YY{};EL=j([G0({type:i.Sequence})],EL);class xw{secretTypeId="";secretValue=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],xw.prototype,"secretTypeId",void 0);j([K({type:S.Any,context:0})],xw.prototype,"secretValue",void 0);class XY{mac=new YX;macSalt=new J1;iterations=1;constructor(W={}){Object.assign(this,W)}}j([K({type:YX})],XY.prototype,"mac",void 0);j([K({type:J1})],XY.prototype,"macSalt",void 0);j([K({type:S.Integer,defaultValue:1})],XY.prototype,"iterations",void 0);class VX{version=3;authSafe=new p5;macData=new XY;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],VX.prototype,"version",void 0);j([K({type:p5})],VX.prototype,"authSafe",void 0);j([K({type:XY,optional:!0})],VX.prototype,"macData",void 0);var kw;class gZ{bagId="";bagValue=new ArrayBuffer(0);bagAttributes;constructor(W={}){Object.assign(this,W)}}j([K({type:S.ObjectIdentifier})],gZ.prototype,"bagId",void 0);j([K({type:S.Any,context:0})],gZ.prototype,"bagValue",void 0);j([K({type:ZX,repeated:"set",optional:!0})],gZ.prototype,"bagAttributes",void 0);var $L=kw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,kw.prototype)}};$L=kw=j([G0({type:i.Sequence,itemType:gZ})],$L);var _w,yw,vw,L8="1.2.840.113549.1.9",DQ0=`${L8}.0`,cL=`${L8}.24`,hZ=`${L8}.25`,pL=`${L8}.26`,lL=`${L8}.27`,CQ0=`${cL}.1`,TQ0=`${cL}.2`,RQ0=`${L8}.1`,MQ0=`${L8}.2`,PQ0=`${L8}.3`,LQ0=`${L8}.4`,BQ0=`${L8}.5`,EQ0=`${L8}.6`,pw=`${L8}.7`,$Q0=`${L8}.8`,FQ0=`${L8}.9`,SQ0=`${L8}.13`,bZ=`${L8}.14`,xQ0=`${L8}.15`,kQ0=`${L8}.20`,_Q0=`${L8}.21`;var yQ0=`${hZ}.1`,vQ0=`${hZ}.2`,gQ0=`${hZ}.3`,uQ0=`${hZ}.4`,hQ0=`${hZ}.5`,mZ="1.3.6.1.5.5.7.9",bQ0=`${mZ}.1`,mQ0=`${mZ}.2`,fQ0=`${mZ}.3`,cQ0=`${mZ}.4`,pQ0=`${mZ}.5`,lQ0=`${pL}.1`,dQ0=`${pL}.2`,oQ0=`${lL}.1`,nQ0=`${lL}.2`,iQ0=`${L8}.16`,rQ0=`${L8}.22`,aQ0=`${L8}.23`,sQ0=`${az}.65`,dH=class extends y8{ia5String;constructor(Y={}){super(Y)}toString(){return{}.toString(),this.ia5String||super.toString()}};j([K({type:S.IA5String})],dH.prototype,"ia5String",void 0);dH=j([G0({type:i.Choice})],dH);var FL=class extends p5{};FL=j([G0({type:i.Sequence})],FL);var SL=class extends VX{};SL=j([G0({type:i.Sequence})],SL);var xL=class extends YY{};xL=j([G0({type:i.Sequence})],xL);var gw=class{value;constructor(Y=""){this.value=Y}toString(){return this.value}};j([K({type:S.IA5String})],gw.prototype,"value",void 0);gw=j([G0({type:i.Choice})],gw);var kL=class extends dH{};kL=j([G0({type:i.Choice})],kL);var _L=class extends y8{};_L=j([G0({type:i.Choice})],_L);var uw=class{value;constructor(Y=new Date){this.value=Y}};j([K({type:S.GeneralizedTime})],uw.prototype,"value",void 0);uw=j([G0({type:i.Choice})],uw);var yL=class extends y8{};yL=j([G0({type:i.Choice})],yL);var hw=class{value;constructor(Y="M"){this.value=Y}toString(){return this.value}};j([K({type:S.PrintableString})],hw.prototype,"value",void 0);hw=j([G0({type:i.Choice})],hw);var oH=class{value;constructor(Y=""){this.value=Y}toString(){return this.value}};j([K({type:S.PrintableString})],oH.prototype,"value",void 0);oH=j([G0({type:i.Choice})],oH);var vL=class extends oH{};vL=j([G0({type:i.Choice})],vL);var gL=class extends y8{};gL=j([G0({type:i.Choice})],gL);var bw=class{value;constructor(Y=""){this.value=Y}toString(){return this.value}};j([K({type:S.ObjectIdentifier})],bw.prototype,"value",void 0);bw=j([G0({type:i.Choice})],bw);var uL=class extends P8{};uL=j([G0({type:i.Choice})],uL);var mw=class{value;constructor(Y=0){this.value=Y}toString(){return this.value.toString()}};j([K({type:S.Integer})],mw.prototype,"value",void 0);mw=j([G0({type:i.Choice})],mw);var hL=class extends J5{};hL=j([G0({type:i.Sequence})],hL);var uZ=class extends y8{};uZ=j([G0({type:i.Choice})],uZ);var bL=_w=class extends X5{constructor(Y){super(Y);Object.setPrototypeOf(this,_w.prototype)}};bL=_w=j([G0({type:i.Sequence})],bL);var mL=yw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,yw.prototype)}};mL=yw=j([G0({type:i.Set,itemType:B7})],mL);var fw=class{value;constructor(Y=""){this.value=Y}toString(){return this.value}};j([K({type:S.BmpString})],fw.prototype,"value",void 0);fw=j([G0({type:i.Choice})],fw);var cw=class extends M0{};cw=j([G0({type:i.Sequence})],cw);var fL=vw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,vw.prototype)}};fL=vw=j([G0({type:i.Sequence,itemType:cw})],fL);var lw,fZ=lw=class extends W1{constructor(Y){super(Y);Object.setPrototypeOf(this,lw.prototype)}};fZ=lw=j([G0({type:i.Sequence,itemType:z9})],fZ);class K4{version=0;subject=new G8;subjectPKInfo=new w9;attributes=new fZ;constructor(W={}){Object.assign(this,W)}}j([K({type:S.Integer})],K4.prototype,"version",void 0);j([K({type:G8})],K4.prototype,"subject",void 0);j([K({type:w9})],K4.prototype,"subjectPKInfo",void 0);j([K({type:fZ,implicit:!0,context:0,optional:!0})],K4.prototype,"attributes",void 0);class JY{certificationRequestInfo=new K4;certificationRequestInfoRaw;signatureAlgorithm=new M0;signature=new ArrayBuffer(0);constructor(W={}){Object.assign(this,W)}}j([K({type:K4,raw:!0})],JY.prototype,"certificationRequestInfo",void 0);j([K({type:M0})],JY.prototype,"signatureAlgorithm",void 0);j([K({type:S.BitString})],JY.prototype,"signature",void 0);/*!
|
|
216
216
|
* MIT License
|
|
@@ -239,18 +239,18 @@ ${W.join(`
|
|
|
239
239
|
`)}static pad(W=0){return"".padStart(2*W," ")}static serializeObj(W,Y=0){let G=[],X=this.pad(Y++),J="",Z=W[o1.VALUE];if(Z)J=` ${Z}`;G.push(`${X}${W[o1.NAME]}:${J}`),X=this.pad(Y);for(let V in W){if(typeof V==="symbol")continue;let U=W[V],Q=V?`${V}: `:"";if(typeof U==="string"||typeof U==="number"||typeof U==="boolean")G.push(`${X}${Q}${U}`);else if(U instanceof Date)G.push(`${X}${Q}${U.toUTCString()}`);else if(Array.isArray(U))for(let H of U)H[o1.NAME]=V,G.push(...this.serializeObj(H,Y));else if(U instanceof o1)U[o1.NAME]=V,G.push(...this.serializeObj(U,Y));else if(_0.isBufferSource(U))if(V)G.push(`${X}${Q}`),G.push(...this.serializeBufferSource(U,Y+1));else G.push(...this.serializeBufferSource(U,Y));else if("toTextObject"in U){let H=U.toTextObject();H[o1.NAME]=V,G.push(...this.serializeObj(H,Y))}else throw TypeError("Cannot serialize data in text format. Unsupported type.")}return G}static serializeBufferSource(W,Y=0){let G=this.pad(Y),X=_0.toUint8Array(W),J=[];for(let Z=0;Z<X.length;){let V=[];for(let U=0;U<16&&Z<X.length;U++){if(U===8)V.push("");let Q=X[Z++].toString(16).padStart(2,"0");V.push(Q)}J.push(`${G}${V.join(" ")}`)}return J}static serializeAlgorithm(W){return this.algorithmSerializer.toTextObject(W)}}k6.oidSerializer=T4;k6.algorithmSerializer=k3;var UX;class y6{get rawData(){if(!R1(this,UX,"f"))I8(this,UX,E0.serialize(this.asn),"f");return R1(this,UX,"f")}constructor(...W){if(UX.set(this,void 0),_0.isBufferSource(W[0]))this.asn=E0.parse(W[0],W[1]),I8(this,UX,_0.toArrayBuffer(W[0]),"f"),this.onInit(this.asn);else this.asn=W[0],this.onInit(this.asn)}equal(W){if(W instanceof y6)return yR(W.rawData,this.rawData);return!1}toString(W="text"){switch(W){case"asn":return E0.toString(this.rawData);case"text":return k6.serialize(this.toTextObject());case"hex":return o0.ToHex(this.rawData);case"base64":return o0.ToBase64(this.rawData);case"base64url":return o0.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let W=this.toTextObjectEmpty();return W[""]=this.rawData,W}toTextObjectEmpty(W){return new o1(this.getTextName(),{},W)}}UX=new WeakMap;y6.NAME="ASN";class V5 extends y6{constructor(...W){let Y;if(_0.isBufferSource(W[0]))Y=_0.toArrayBuffer(W[0]);else Y=E0.serialize(new j9({extnID:W[0],critical:W[1],extnValue:new J1(_0.toArrayBuffer(W[2]))}));super(Y,j9)}onInit(W){this.type=W.extnID,this.critical=W.critical,this.value=W.extnValue.buffer}toTextObject(){let W=this.toTextObjectWithoutValue();return W[""]=this.value,W}toTextObjectWithoutValue(){let W=this.toTextObjectEmpty(this.critical?"critical":void 0);if(W[o1.NAME]===V5.NAME)W[o1.NAME]=T4.toString(this.type);return W}}var _3;class x6{static isCryptoKeyPair(W){return W&&W.privateKey&&W.publicKey}static isCryptoKey(W){return W&&W.usages&&W.type&&W.algorithm&&W.extractable!==void 0}constructor(){if(this.items=new Map,this[_3]="CryptoProvider",typeof self<"u"&&typeof crypto<"u")this.set(x6.DEFAULT,crypto);else if(typeof global<"u"&&global.crypto&&global.crypto.subtle)this.set(x6.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(W){return this.items.delete(W)}forEach(W,Y){return this.items.forEach(W,Y)}has(W){return this.items.has(W)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(W=x6.DEFAULT){let Y=this.items.get(W.toLowerCase());if(!Y)throw Error(`Cannot get Crypto by name '${W}'`);return Y}set(W,Y){if(typeof W==="string"){if(!Y)throw TypeError("Argument 'value' is required");this.items.set(W.toLowerCase(),Y)}else this.items.set(x6.DEFAULT,W);return this}}_3=Symbol.toStringTag;x6.DEFAULT="default";var v8=new x6,ef=/^[0-2](?:\.[1-9][0-9]*)+$/;function Wc(W){return new RegExp(ef).test(W)}class Xj{constructor(W={}){this.items={};for(let Y in W)this.register(Y,W[Y])}get(W){return this.items[W]||null}findId(W){if(!Wc(W))return this.get(W);return W}register(W,Y){this.items[W]=Y,this.items[Y]=W}}var l9=new Xj;l9.register("CN","2.5.4.3");l9.register("L","2.5.4.7");l9.register("ST","2.5.4.8");l9.register("O","2.5.4.10");l9.register("OU","2.5.4.11");l9.register("C","2.5.4.6");l9.register("DC","0.9.2342.19200300.100.1.25");l9.register("E","1.2.840.113549.1.9.1");l9.register("G","2.5.4.42");l9.register("I","2.5.4.43");l9.register("SN","2.5.4.4");l9.register("T","2.5.4.12");function Yc(W,Y){return`\\${o0.ToHex(o0.FromUtf8String(Y)).toUpperCase()}`}function Gc(W){return W.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,Yc)}class d5{static isASCII(W){for(let Y=0;Y<W.length;Y++)if(W.charCodeAt(Y)>255)return!1;return!0}static isPrintableString(W){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(W)}constructor(W,Y={}){this.extraNames=new Xj,this.asn=new G8;for(let G in Y)if(Object.prototype.hasOwnProperty.call(Y,G)){let X=Y[G];this.extraNames.register(G,X)}if(typeof W==="string")this.asn=this.fromString(W);else if(W instanceof G8)this.asn=W;else if(_0.isBufferSource(W))this.asn=E0.parse(W,G8);else this.asn=this.fromJSON(W)}getField(W){let Y=this.extraNames.findId(W)||l9.findId(W),G=[];for(let X of this.asn)for(let J of X)if(J.type===Y)G.push(J.value.toString());return G}getName(W){return this.extraNames.get(W)||l9.get(W)}toString(){return this.asn.map((W)=>W.map((Y)=>{let G=this.getName(Y.type)||Y.type,X=Y.value.anyValue?`#${o0.ToHex(Y.value.anyValue)}`:Gc(Y.value.toString());return`${G}=${X}`}).join("+")).join(", ")}toJSON(){var W;let Y=[];for(let G of this.asn){let X={};for(let J of G){let Z=this.getName(J.type)||J.type;(W=X[Z])!==null&&W!==void 0||(X[Z]=[]),X[Z].push(J.value.anyValue?`#${o0.ToHex(J.value.anyValue)}`:J.value.toString())}Y.push(X)}return Y}fromString(W){let Y=new G8,G=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,X=null,J=",";while(X=G.exec(`${W},`)){let[,Z,V]=X,U=V[V.length-1];if(U===","||U==="+")V=V.slice(0,V.length-1),X[3]=U;let Q=X[3];Z=this.getTypeOid(Z);let H=this.createAttribute(Z,V);if(J==="+")Y[Y.length-1].push(H);else Y.push(new C6([H]));J=Q}return Y}fromJSON(W){let Y=new G8;for(let G of W){let X=new C6;for(let J in G){let Z=this.getTypeOid(J),V=G[J];for(let U of V){let Q=this.createAttribute(Z,U);X.push(Q)}}Y.push(X)}return Y}getTypeOid(W){if(!/[\d.]+/.test(W))W=this.getName(W)||"";if(!W)throw Error(`Cannot get OID for name type '${W}'`);return W}createAttribute(W,Y){let G=new _G({type:W});if(typeof Y==="object")for(let X in Y)switch(X){case"ia5String":G.value.ia5String=Y[X];break;case"utf8String":G.value.utf8String=Y[X];break;case"universalString":G.value.universalString=Y[X];break;case"bmpString":G.value.bmpString=Y[X];break;case"printableString":G.value.printableString=Y[X];break}else if(Y[0]==="#")G.value.anyValue=o0.FromHex(Y.slice(1));else{let X=this.processStringValue(Y);if(W===this.getName("E")||W===this.getName("DC"))G.value.ia5String=X;else if(d5.isPrintableString(X))G.value.printableString=X;else G.value.utf8String=X}return G}processStringValue(W){let Y=/"(.*?[^\\])?"/.exec(W);if(Y)W=Y[1];return W.replace(/\\0a/ig,`
|
|
240
240
|
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig,"\t").replace(/\\(.)/g,"$1")}toArrayBuffer(){return E0.serialize(this.asn)}async getThumbprint(...W){var Y;let G,X="SHA-1";if(W.length>=1&&!((Y=W[0])===null||Y===void 0?void 0:Y.subtle))X=W[0]||X,G=W[1]||v8.get();else G=W[0]||v8.get();return await G.subtle.digest(X,this.toArrayBuffer())}}var y3="Cannot initialize GeneralName from ASN.1 data.",D3=`${y3} Unsupported string format in use.`,Xc=`${y3} Value doesn't match to GUID regular expression.`,C3=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,T3="1.3.6.1.4.1.311.25.1",R3="1.3.6.1.4.1.311.20.2.3",dw="dns",ow="dn",nw="email",iw="ip",rw="url",aw="guid",sw="upn",nH="id";class D4 extends y6{constructor(...W){let Y;if(W.length===2)switch(W[0]){case ow:{let G=new d5(W[1]).toArrayBuffer(),X=E0.parse(G,G8);Y=new Q1({directoryName:X});break}case dw:Y=new Q1({dNSName:W[1]});break;case nw:Y=new Q1({rfc822Name:W[1]});break;case aw:{let G=new RegExp(C3,"i").exec(W[1]);if(!G)throw Error("Cannot parse GUID value. Value doesn't match to regular expression");let X=G.slice(1).map((J,Z)=>{if(Z<3)return o0.ToHex(new Uint8Array(o0.FromHex(J)).reverse());return J}).join("");Y=new Q1({otherName:new kW({typeId:T3,value:E0.serialize(new J1(o0.FromHex(X)))})});break}case iw:Y=new Q1({iPAddress:W[1]});break;case nH:Y=new Q1({registeredID:W[1]});break;case sw:{Y=new Q1({otherName:new kW({typeId:R3,value:E0.serialize(Uz.toASN(W[1]))})});break}case rw:Y=new Q1({uniformResourceIdentifier:W[1]});break;default:throw Error("Cannot create GeneralName. Unsupported type of the name")}else if(_0.isBufferSource(W[0]))Y=E0.parse(W[0],Q1);else Y=W[0];super(Y)}onInit(W){if(W.dNSName!=null)this.type=dw,this.value=W.dNSName;else if(W.rfc822Name!=null)this.type=nw,this.value=W.rfc822Name;else if(W.iPAddress!=null)this.type=iw,this.value=W.iPAddress;else if(W.uniformResourceIdentifier!=null)this.type=rw,this.value=W.uniformResourceIdentifier;else if(W.registeredID!=null)this.type=nH,this.value=W.registeredID;else if(W.directoryName!=null)this.type=ow,this.value=new d5(W.directoryName).toString();else if(W.otherName!=null)if(W.otherName.typeId===T3){this.type=aw;let Y=E0.parse(W.otherName.value,J1),G=new RegExp(C3,"i").exec(o0.ToHex(Y));if(!G)throw Error(Xc);this.value=G.slice(1).map((X,J)=>{if(J<3)return o0.ToHex(new Uint8Array(o0.FromHex(X)).reverse());return X}).join("-")}else if(W.otherName.typeId===R3)this.type=sw,this.value=E0.parse(W.otherName.value,y8).toString();else throw Error(D3);else throw Error(D3)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let W;switch(this.type){case ow:case dw:case aw:case iw:case nH:case sw:case rw:W=this.type.toUpperCase();break;case nw:W="Email";break;default:throw Error("Unsupported GeneralName type")}let Y=this.value;if(this.type===nH)Y=T4.toString(Y);return new o1(W,void 0,Y)}}class _6 extends y6{constructor(W){let Y;if(W instanceof z8)Y=W;else if(Array.isArray(W)){let G=[];for(let X of W)if(X instanceof Q1)G.push(X);else{let J=E0.parse(new D4(X.type,X.value).rawData,Q1);G.push(J)}Y=new z8(G)}else if(_0.isBufferSource(W))Y=E0.parse(W,z8);else throw Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(Y)}onInit(W){let Y=[];for(let G of W){let X=null;try{X=new D4(G)}catch{continue}Y.push(X)}this.items=Y}toJSON(){return this.items.map((W)=>W.toJSON())}toTextObject(){let W=super.toTextObjectEmpty();for(let Y of this.items){let G=Y.toTextObject(),X=W[G[o1.NAME]];if(!Array.isArray(X))X=[],W[G[o1.NAME]]=X;X.push(G)}return W}}_6.NAME="GeneralNames";var VV="-{5}",QV="\\n",Jc=`[^${QV}]+`,Zc=`${VV}BEGIN (${Jc}(?=${VV}))${VV}`,Vc=`${VV}END \\1${VV}`,NX="\\n",Uc=`[^:${QV}]+`,Qc=`(?:[^${QV}]+${NX}(?: +[^${QV}]+${NX})*)`,Hc="[a-zA-Z0-9=+/]+",Nc=`(?:${Hc}${NX})+`,M3=`${Zc}${NX}(?:((?:${Uc}: ${Qc})+))?${NX}?(${Nc})${Vc}`;class K9{static isPem(W){return typeof W==="string"&&new RegExp(M3,"g").test(W.replace(/\r/g,""))}static decodeWithHeaders(W){W=W.replace(/\r/g,"");let Y=new RegExp(M3,"g"),G=[],X=null;while(X=Y.exec(W)){let J=X[3].replace(new RegExp(`[${QV}]+`,"g"),""),Z={type:X[1],headers:[],rawData:o0.FromBase64(J)},V=X[2];if(V){let U=V.split(new RegExp(NX,"g")),Q=null;for(let H of U){let[N,A]=H.split(/:(.*)/);if(A===void 0){if(!Q)throw Error("Cannot parse PEM string. Incorrect header value");Q.value+=N.trim()}else{if(Q)Z.headers.push(Q);Q={key:N,value:A.trim()}}}if(Q)Z.headers.push(Q)}G.push(Z)}return G}static decode(W){return this.decodeWithHeaders(W).map((G)=>G.rawData)}static decodeFirst(W){let Y=this.decode(W);if(!Y.length)throw RangeError("PEM string doesn't contain any objects");return Y[0]}static encode(W,Y){if(Array.isArray(W)){let G=[];if(Y)W.forEach((X)=>{if(!_0.isBufferSource(X))throw TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");G.push(this.encodeStruct({type:Y,rawData:_0.toArrayBuffer(X)}))});else W.forEach((X)=>{if(!("type"in X))throw TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");G.push(this.encodeStruct(X))});return G.join(`
|
|
241
241
|
`)}else{if(!Y)throw Error("Required argument 'tag' is missed");return this.encodeStruct({type:Y,rawData:_0.toArrayBuffer(W)})}}static encodeStruct(W){var Y;let G=W.type.toLocaleUpperCase(),X=[];if(X.push(`-----BEGIN ${G}-----`),(Y=W.headers)===null||Y===void 0?void 0:Y.length){for(let Q of W.headers)X.push(`${Q.key}: ${Q.value}`);X.push("")}let J=o0.ToBase64(W.rawData),Z,V=0,U=Array();while(V<J.length){if(J.length-V<64)Z=J.substring(V);else Z=J.substring(V,V+64),V+=64;if(Z.length!==0){if(U.push(Z),Z.length<64)break}else break}return X.push(...U),X.push(`-----END ${G}-----`),X.join(`
|
|
242
|
-
`)}}K9.CertificateTag="CERTIFICATE";K9.CrlTag="CRL";K9.CertificateRequestTag="CERTIFICATE REQUEST";K9.PublicKeyTag="PUBLIC KEY";K9.PrivateKeyTag="PRIVATE KEY";class C4 extends y6{static isAsnEncoded(W){return _0.isBufferSource(W)||typeof W==="string"}static toArrayBuffer(W){if(typeof W==="string")if(K9.isPem(W))return K9.decode(W)[0];else if(o0.isHex(W))return o0.FromHex(W);else if(o0.isBase64(W))return o0.FromBase64(W);else if(o0.isBase64Url(W))return o0.FromBase64Url(W);else throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url");else{let Y=_0.toUint8Array(W);if(Y.length>0&&Y[0]===48)return _0.toArrayBuffer(W);let G=o0.ToBinary(W);if(K9.isPem(G))return K9.decode(G)[0];else if(o0.isHex(G))return o0.FromHex(G);else if(o0.isBase64(G))return o0.FromBase64(G);else if(o0.isBase64Url(G))return o0.FromBase64Url(G);throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...W){if(C4.isAsnEncoded(W[0]))super(C4.toArrayBuffer(W[0]),W[1]);else super(W[0])}toString(W="pem"){switch(W){case"pem":return K9.encode(this.rawData,this.tag);default:return super.toString(W)}}}class o5 extends C4{static async create(W,Y=v8.get()){if(W instanceof o5)return W;else if(x6.isCryptoKey(W)){if(W.type!=="public")throw TypeError("Public key is required");let G=await Y.subtle.exportKey("spki",W);return new o5(G)}else if(W.publicKey)return W.publicKey;else if(_0.isBufferSource(W))return new o5(W);else throw TypeError("Unsupported PublicKeyType")}constructor(W){if(C4.isAsnEncoded(W))super(W,w9);else super(W);this.tag=K9.PublicKeyTag}async export(...W){let Y,G=["verify"],X={hash:"SHA-256",...this.algorithm};if(W.length>1)X=W[0]||X,G=W[1]||G,Y=W[2]||v8.get();else Y=W[0]||v8.get();let J=this.rawData,Z=E0.parse(this.rawData,w9);if(Z.algorithm.algorithm===E6)J=qc(Z,J);return Y.subtle.importKey("spki",J,X,!0,G)}onInit(W){let Y=Q8.resolve(ZY),G=this.algorithm=Y.toWebAlgorithm(W.algorithm);switch(W.algorithm.algorithm){case F7:{let X=E0.parse(W.subjectPublicKey,SZ),J=_0.toUint8Array(X.modulus);G.publicExponent=_0.toUint8Array(X.publicExponent),G.modulusLength=(!J[0]?J.slice(1):J).byteLength<<3;break}}}async getThumbprint(...W){var Y;let G,X="SHA-1";if(W.length>=1&&!((Y=W[0])===null||Y===void 0?void 0:Y.subtle))X=W[0]||X,G=W[1]||v8.get();else G=W[0]||v8.get();return await G.subtle.digest(X,this.rawData)}async getKeyIdentifier(...W){let Y,G="SHA-1";if(W.length===1)if(typeof W[0]==="string")G=W[0],Y=v8.get();else Y=W[0];else if(W.length===2)G=W[0],Y=W[1];else Y=v8.get();let X=E0.parse(this.rawData,w9);return await Y.subtle.digest(G,X.subjectPublicKey)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,w9);switch(W.Algorithm=k6.serializeAlgorithm(Y.algorithm),Y.algorithm.algorithm){case nW:W["EC Point"]=Y.subjectPublicKey;break;case F7:default:W["Raw Data"]=Y.subjectPublicKey}return W}}function qc(W,Y){return W.algorithm=new M0({algorithm:F7,parameters:null}),Y=E0.serialize(W),Y}class HV extends V5{static async create(W,Y=!1,G=v8.get()){if("name"in W&&"serialNumber"in W)return new HV(W,Y);let J=await(await o5.create(W,G)).getKeyIdentifier(G);return new HV(o0.ToHex(J),Y)}constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else if(typeof W[0]==="string"){let Y=new q4({keyIdentifier:new yG(o0.FromHex(W[0]))});super(HH,W[1],E0.serialize(Y))}else{let Y=W[0],G=Y.name instanceof _6?E0.parse(Y.name.rawData,z8):Y.name,X=new q4({authorityCertIssuer:G,authorityCertSerialNumber:o0.FromHex(Y.serialNumber)});super(HH,W[1],E0.serialize(X))}}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,q4);if(Y.keyIdentifier)this.keyId=o0.ToHex(Y.keyIdentifier);if(Y.authorityCertIssuer||Y.authorityCertSerialNumber)this.certId={name:Y.authorityCertIssuer||[],serialNumber:Y.authorityCertSerialNumber?o0.ToHex(Y.authorityCertSerialNumber):""}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,q4);if(Y.authorityCertIssuer)W["Authority Issuer"]=new _6(Y.authorityCertIssuer).toTextObject();if(Y.authorityCertSerialNumber)W["Authority Serial Number"]=Y.authorityCertSerialNumber;if(Y.keyIdentifier)W[""]=Y.keyIdentifier;return W}}HV.NAME="Authority Key Identifier";class Jj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,vG);this.ca=Y.cA,this.pathLength=Y.pathLenConstraint}else{let Y=new vG({cA:W[0],pathLenConstraint:W[1]});super(NH,W[2],E0.serialize(Y));this.ca=W[0],this.pathLength=W[1]}}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ca)W.CA=this.ca;if(this.pathLength!==void 0)W["Path Length"]=this.pathLength;return W}}Jj.NAME="Basic Constraints";var P3;(function(W){W.serverAuth="1.3.6.1.5.5.7.3.1",W.clientAuth="1.3.6.1.5.5.7.3.2",W.codeSigning="1.3.6.1.5.5.7.3.3",W.emailProtection="1.3.6.1.5.5.7.3.4",W.timeStamping="1.3.6.1.5.5.7.3.8",W.ocspSigning="1.3.6.1.5.5.7.3.9"})(P3||(P3={}));class Zj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,WZ);this.usages=Y.map((G)=>G)}else{let Y=new WZ(W[0]);super(KH,W[1],E0.serialize(Y));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[""]=this.usages.map((Y)=>T4.toString(Y)).join(", "),W}}Zj.NAME="Extended Key Usages";var L3;(function(W){W[W.digitalSignature=1]="digitalSignature",W[W.nonRepudiation=2]="nonRepudiation",W[W.keyEncipherment=4]="keyEncipherment",W[W.dataEncipherment=8]="dataEncipherment",W[W.keyAgreement=16]="keyAgreement",W[W.keyCertSign=32]="keyCertSign",W[W.cRLSign=64]="cRLSign",W[W.encipherOnly=128]="encipherOnly",W[W.decipherOnly=256]="decipherOnly"})(L3||(L3={}));class Vj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,GZ);this.usages=Y.toNumber()}else{let Y=new GZ(W[0]);super(DH,W[1],E0.serialize(Y));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,GZ);return W[""]=Y.toJSON().join(", "),W}}Vj.NAME="Key Usages";class tH extends V5{static async create(W,Y=!1,G=v8.get()){let J=await(await o5.create(W,G)).getKeyIdentifier(G);return new tH(o0.ToHex(J),Y)}constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,G5);this.keyId=o0.ToHex(Y)}else{let Y=typeof W[0]==="string"?o0.FromHex(W[0]):W[0],G=new G5(Y);super(bz,W[1],E0.serialize(G));this.keyId=o0.ToHex(Y)}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,G5);return W[""]=Y,W}}tH.NAME="Subject Key Identifier";class Uj extends V5{constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else super(uz,W[1],new _6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,RH);this.names=new _6(Y)}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.names.toTextObject();for(let G in Y)W[G]=Y[G];return W}}Uj.NAME="Subject Alternative Name";class o9{static register(W,Y){this.items.set(W,Y)}static create(W){let Y=new V5(W),G=this.items.get(Y.type);if(G)return new G(W);return Y}}o9.items=new Map;class Qj extends V5{constructor(...W){var Y;if(_0.isBufferSource(W[0])){super(W[0]);let G=E0.parse(this.value,aJ);this.policies=G.map((X)=>X.policyIdentifier)}else{let G=W[0],X=(Y=W[1])!==null&&Y!==void 0?Y:!1,J=new aJ(G.map((Z)=>new gG({policyIdentifier:Z})));super(AH,X,E0.serialize(J));this.policies=G}}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Policy=this.policies.map((Y)=>new o1("",{},T4.toString(Y))),W}}Qj.NAME="Certificate Policies";o9.register(AH,Qj);class Hj extends V5{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else if(Array.isArray(W[0])&&typeof W[0][0]==="string"){let X=W[0].map((Z)=>{return new z4({distributionPoint:new I4({fullName:[new Q1({uniformResourceIdentifier:Z})]})})}),J=new M6(X);super(jH,W[1],E0.serialize(J))}else{let G=new M6(W[0]);super(jH,W[1],E0.serialize(G))}(Y=this.distributionPoints)!==null&&Y!==void 0||(this.distributionPoints=[])}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,M6);this.distributionPoints=Y}toTextObject(){let W=this.toTextObjectWithoutValue();return W["Distribution Point"]=this.distributionPoints.map((Y)=>{var G;let X={};if(Y.distributionPoint)X[""]=(G=Y.distributionPoint.fullName)===null||G===void 0?void 0:G.map((J)=>new D4(J).toString()).join(", ");if(Y.reasons)X.Reasons=Y.reasons.toString();if(Y.cRLIssuer)X["CRL Issuer"]=Y.cRLIssuer.map((J)=>J.toString()).join(", ");return X}),W}}Hj.NAME="CRL Distribution Points";class Nj extends V5{constructor(...W){var Y,G,X,J;if(_0.isBufferSource(W[0]))super(W[0]);else if(W[0]instanceof yW){let Z=new yW(W[0]);super(QH,W[1],E0.serialize(Z))}else{let Z=W[0],V=new yW;rH(V,Z,Kz,"ocsp"),rH(V,Z,Dz,"caIssuers"),rH(V,Z,Cz,"timeStamping"),rH(V,Z,Tz,"caRepository");super(QH,W[1],E0.serialize(V))}(Y=this.ocsp)!==null&&Y!==void 0||(this.ocsp=[]),(G=this.caIssuers)!==null&&G!==void 0||(this.caIssuers=[]),(X=this.timeStamping)!==null&&X!==void 0||(this.timeStamping=[]),(J=this.caRepository)!==null&&J!==void 0||(this.caRepository=[])}onInit(W){super.onInit(W),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],E0.parse(W.extnValue,yW).forEach((G)=>{switch(G.accessMethod){case Kz:this.ocsp.push(new D4(G.accessLocation));break;case Dz:this.caIssuers.push(new D4(G.accessLocation));break;case Cz:this.timeStamping.push(new D4(G.accessLocation));break;case Tz:this.caRepository.push(new D4(G.accessLocation));break}})}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ocsp.length)iH(W,"OCSP",this.ocsp);if(this.caIssuers.length)iH(W,"CA Issuers",this.caIssuers);if(this.timeStamping.length)iH(W,"Time Stamping",this.timeStamping);if(this.caRepository.length)iH(W,"CA Repository",this.caRepository);return W}}Nj.NAME="Authority Info Access";function iH(W,Y,G){if(G.length===1)W[Y]=G[0].toTextObject();else{let X=new o1("");G.forEach((J,Z)=>{let V=J.toTextObject(),U=`${V[o1.NAME]} ${Z+1}`,Q=X[U];if(!Array.isArray(Q))Q=[],X[U]=Q;Q.push(V)}),W[Y]=X}}function rH(W,Y,G,X){let J=Y[X];if(J)(Array.isArray(J)?J:[J]).forEach((V)=>{if(typeof V==="string")V=new D4("url",V);W.push(new R6({accessMethod:G,accessLocation:E0.parse(V.rawData,Q1)}))})}class qj extends V5{constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else super(xz,W[1],new _6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,z8);this.names=new _6(Y)}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.names.toTextObject();for(let G in Y)W[G]=Y[G];return W}}qj.NAME="Issuer Alternative Name";class qX extends y6{constructor(...W){let Y;if(_0.isBufferSource(W[0]))Y=_0.toArrayBuffer(W[0]);else{let G=W[0],X=Array.isArray(W[1])?W[1].map((J)=>_0.toArrayBuffer(J)):[];Y=E0.serialize(new z9({type:G,values:X}))}super(Y,z9)}onInit(W){this.type=W.type,this.values=W.values}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Value=this.values.map((Y)=>new o1("",{"":Y})),W}toTextObjectWithoutValue(){let W=this.toTextObjectEmpty();if(W[o1.NAME]===qX.NAME)W[o1.NAME]=T4.toString(this.type);return W}}qX.NAME="Attribute";class Aj extends qX{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else{let G=new uZ({printableString:W[0]});super(pw,[E0.serialize(G)])}(Y=this.password)!==null&&Y!==void 0||(this.password="")}onInit(W){if(super.onInit(W),this.values[0]){let Y=E0.parse(this.values[0],uZ);this.password=Y.toString()}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[o1.VALUE]=this.password,W}}Aj.NAME="Challenge Password";class eH extends qX{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else{let G=W[0],X=new X5;for(let J of G)X.push(E0.parse(J.rawData,j9));super(bZ,[E0.serialize(X)])}(Y=this.items)!==null&&Y!==void 0||(this.items=[])}onInit(W){if(super.onInit(W),this.values[0]){let Y=E0.parse(this.values[0],X5);this.items=Y.map((G)=>o9.create(E0.serialize(G)))}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.items.map((G)=>G.toTextObject());for(let G of Y)W[G[o1.NAME]]=G;return W}}eH.NAME="Extensions";class qV{static register(W,Y){this.items.set(W,Y)}static create(W){let Y=new qX(W),G=this.items.get(Y.type);if(G)return new G(W);return Y}}qV.items=new Map;var AV="crypto.signatureFormatter";class v3{toAsnSignature(W,Y){return _0.toArrayBuffer(Y)}toWebSignature(W,Y){return _0.toArrayBuffer(Y)}}var sH,Wj=sH=class{static createPssParams(Y,G){let X=sH.getHashAlgorithm(Y);if(!X)return null;return new O4({hashAlgorithm:X,maskGenAlgorithm:new M0({algorithm:$6,parameters:E0.serialize(X)}),saltLength:G})}static getHashAlgorithm(Y){let G=Q8.resolve(ZY);if(typeof Y==="string")return G.toAsnAlgorithm({name:Y});if(typeof Y==="object"&&Y&&"name"in Y)return G.toAsnAlgorithm(Y);return null}toAsnAlgorithm(Y){switch(Y.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in Y){let G;if(typeof Y.hash==="string")G=Y.hash;else if(Y.hash&&typeof Y.hash==="object"&&"name"in Y.hash&&typeof Y.hash.name==="string")G=Y.hash.name.toUpperCase();else throw Error("Cannot get hash algorithm name");switch(G.toLowerCase()){case"sha-1":return new M0({algorithm:tG,parameters:null});case"sha-256":return new M0({algorithm:gH,parameters:null});case"sha-384":return new M0({algorithm:eG,parameters:null});case"sha-512":return new M0({algorithm:WX,parameters:null})}}else return new M0({algorithm:F7,parameters:null});break;case"rsa-pss":if("hash"in Y){if(!(("saltLength"in Y)&&typeof Y.saltLength==="number"))throw Error("Cannot get 'saltLength' from 'alg' argument");let G=sH.createPssParams(Y.hash,Y.saltLength);if(!G)throw Error("Cannot create PSS parameters");return new M0({algorithm:E6,parameters:E0.serialize(G)})}else return new M0({algorithm:E6,parameters:null})}return null}toWebAlgorithm(Y){switch(Y.algorithm){case F7:return{name:"RSASSA-PKCS1-v1_5"};case tG:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case gH:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case eG:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case WX:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case E6:if(Y.parameters){let G=E0.parse(Y.parameters,O4);return{name:"RSA-PSS",hash:Q8.resolve(ZY).toWebAlgorithm(G.hashAlgorithm),saltLength:G.saltLength}}else return{name:"RSA-PSS"}}return null}};Wj=sH=j([S6()],Wj);Q8.registerSingleton(NV,Wj);var Yj=class{toAsnAlgorithm(Y){switch(Y.name.toLowerCase()){case"sha-1":return new M0({algorithm:iW});case"sha-256":return new M0({algorithm:rW});case"sha-384":return new M0({algorithm:aW});case"sha-512":return new M0({algorithm:sW})}return null}toWebAlgorithm(Y){switch(Y.algorithm){case iW:return{name:"SHA-1"};case rW:return{name:"SHA-256"};case aW:return{name:"SHA-384"};case sW:return{name:"SHA-512"}}return null}};Yj=j([S6()],Yj);Q8.registerSingleton(NV,Yj);class P5{addPadding(W,Y){let G=_0.toUint8Array(Y),X=new Uint8Array(W);return X.set(G,W-G.length),X.buffer}removePadding(W,Y=!1){let G=_0.toUint8Array(W);for(let X=0;X<G.length;X++){if(!G[X])continue;G=G.slice(X);break}if(Y&&G[0]>127){let X=new Uint8Array(G.length+1);return X.set(G,1),X.buffer}return G.buffer}toAsnSignature(W,Y){if(W.name==="ECDSA"){let G=W.namedCurve,X=P5.namedCurveSize.get(G)||P5.defaultNamedCurveSize,J=new sG,Z=_0.toUint8Array(Y);return J.r=this.removePadding(Z.slice(0,X),!0),J.s=this.removePadding(Z.slice(X,X+X),!0),E0.serialize(J)}return null}toWebSignature(W,Y){if(W.name==="ECDSA"){let G=E0.parse(Y,sG),X=W.namedCurve,J=P5.namedCurveSize.get(X)||P5.defaultNamedCurveSize,Z=this.addPadding(J,this.removePadding(G.r)),V=this.addPadding(J,this.removePadding(G.s));return _R(Z,V)}return null}}P5.namedCurveSize=new Map;P5.defaultNamedCurveSize=32;var tw="1.3.101.110",B3="1.3.101.111",ew="1.3.101.112",E3="1.3.101.113",Gj=class{toAsnAlgorithm(Y){let G=null;switch(Y.name.toLowerCase()){case"ed25519":G=ew;break;case"x25519":G=tw;break;case"eddsa":switch(Y.namedCurve.toLowerCase()){case"ed25519":G=ew;break;case"ed448":G=E3;break}break;case"ecdh-es":switch(Y.namedCurve.toLowerCase()){case"x25519":G=tw;break;case"x448":G=B3;break}}if(G)return new M0({algorithm:G});return null}toWebAlgorithm(Y){switch(Y.algorithm){case ew:return{name:"Ed25519"};case E3:return{name:"EdDSA",namedCurve:"Ed448"};case tw:return{name:"X25519"};case B3:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Gj=j([S6()],Gj);Q8.registerSingleton(NV,Gj);var cZ,pZ,lZ,dZ,oZ,nZ,iZ,QX;class g3 extends C4{get subjectName(){if(!R1(this,pZ,"f"))I8(this,pZ,new d5(this.asn.certificationRequestInfo.subject),"f");return R1(this,pZ,"f")}get subject(){if(!R1(this,lZ,"f"))I8(this,lZ,this.subjectName.toString(),"f");return R1(this,lZ,"f")}get signatureAlgorithm(){if(!R1(this,dZ,"f")){let W=Q8.resolve(ZY);I8(this,dZ,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return R1(this,dZ,"f")}get signature(){if(!R1(this,oZ,"f"))I8(this,oZ,this.asn.signature,"f");return R1(this,oZ,"f")}get publicKey(){if(!R1(this,nZ,"f"))I8(this,nZ,new o5(this.asn.certificationRequestInfo.subjectPKInfo),"f");return R1(this,nZ,"f")}get attributes(){if(!R1(this,iZ,"f"))I8(this,iZ,this.asn.certificationRequestInfo.attributes.map((W)=>qV.create(E0.serialize(W))),"f");return R1(this,iZ,"f")}get extensions(){if(!R1(this,QX,"f")){I8(this,QX,[],"f");let W=this.getAttribute(bZ);if(W instanceof eH)I8(this,QX,W.items,"f")}return R1(this,QX,"f")}get tbs(){if(!R1(this,cZ,"f"))I8(this,cZ,this.asn.certificationRequestInfoRaw||E0.serialize(this.asn.certificationRequestInfo),"f");return R1(this,cZ,"f")}constructor(W){let Y=C4.isAsnEncoded(W)?[W,JY]:[W];super(Y[0],Y[1]);cZ.set(this,void 0),pZ.set(this,void 0),lZ.set(this,void 0),dZ.set(this,void 0),oZ.set(this,void 0),nZ.set(this,void 0),iZ.set(this,void 0),QX.set(this,void 0),this.tag=K9.CertificateRequestTag}onInit(W){}getAttribute(W){for(let Y of this.attributes)if(Y.type===W)return Y;return null}getAttributes(W){return this.attributes.filter((Y)=>Y.type===W)}getExtension(W){for(let Y of this.extensions)if(Y.type===W)return Y;return null}getExtensions(W){return this.extensions.filter((Y)=>Y.type===W)}async verify(W=v8.get()){let Y={...this.publicKey.algorithm,...this.signatureAlgorithm},G=await this.publicKey.export(Y,["verify"],W),X=Q8.resolveAll(AV).reverse(),J=null;for(let V of X)if(J=V.toWebSignature(Y,this.signature),J)break;if(!J)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await W.subtle.verify(this.signatureAlgorithm,G,J,this.tbs)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,JY),G=Y.certificationRequestInfo,X=new o1("",{Version:`${P7[G.version]} (${G.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let J=new o1("");for(let Z of this.attributes){let V=Z.toTextObject();J[V[o1.NAME]]=V}X.Attributes=J}return W.Data=X,W.Signature=new o1("",{Algorithm:k6.serializeAlgorithm(Y.signatureAlgorithm),"":Y.signature}),W}}cZ=new WeakMap,pZ=new WeakMap,lZ=new WeakMap,dZ=new WeakMap,oZ=new WeakMap,nZ=new WeakMap,iZ=new WeakMap,QX=new WeakMap;g3.NAME="PKCS#10 Certificate Request";var rZ,aZ,sZ,tZ,eZ,WV,YV,GV,XV,JV,HX,ZV;class Ij extends C4{get publicKey(){if(!R1(this,ZV,"f"))I8(this,ZV,new o5(this.asn.tbsCertificate.subjectPublicKeyInfo),"f");return R1(this,ZV,"f")}get serialNumber(){if(!R1(this,aZ,"f")){let W=this.asn.tbsCertificate,Y=new Uint8Array(W.serialNumber);if(Y.length>1&&Y[0]===0&&Y[1]>127)Y=Y.slice(1);I8(this,aZ,o0.ToHex(Y),"f")}return R1(this,aZ,"f")}get subjectName(){if(!R1(this,sZ,"f"))I8(this,sZ,new d5(this.asn.tbsCertificate.subject),"f");return R1(this,sZ,"f")}get subject(){if(!R1(this,tZ,"f"))I8(this,tZ,this.subjectName.toString(),"f");return R1(this,tZ,"f")}get issuerName(){if(!R1(this,eZ,"f"))I8(this,eZ,new d5(this.asn.tbsCertificate.issuer),"f");return R1(this,eZ,"f")}get issuer(){if(!R1(this,WV,"f"))I8(this,WV,this.issuerName.toString(),"f");return R1(this,WV,"f")}get notBefore(){if(!R1(this,YV,"f")){let W=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!W)throw Error("Cannot get 'notBefore' value");I8(this,YV,W,"f")}return R1(this,YV,"f")}get notAfter(){if(!R1(this,GV,"f")){let W=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!W)throw Error("Cannot get 'notAfter' value");I8(this,GV,W,"f")}return R1(this,GV,"f")}get signatureAlgorithm(){if(!R1(this,XV,"f")){let W=Q8.resolve(ZY);I8(this,XV,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return R1(this,XV,"f")}get signature(){if(!R1(this,JV,"f"))I8(this,JV,this.asn.signatureValue,"f");return R1(this,JV,"f")}get extensions(){if(!R1(this,HX,"f")){if(I8(this,HX,[],"f"),this.asn.tbsCertificate.extensions)I8(this,HX,this.asn.tbsCertificate.extensions.map((W)=>o9.create(E0.serialize(W))),"f")}return R1(this,HX,"f")}get tbs(){if(!R1(this,rZ,"f"))I8(this,rZ,this.asn.tbsCertificateRaw||E0.serialize(this.asn.tbsCertificate),"f");return R1(this,rZ,"f")}constructor(W){let Y=C4.isAsnEncoded(W)?[W,m5]:[W];super(Y[0],Y[1]);rZ.set(this,void 0),aZ.set(this,void 0),sZ.set(this,void 0),tZ.set(this,void 0),eZ.set(this,void 0),WV.set(this,void 0),YV.set(this,void 0),GV.set(this,void 0),XV.set(this,void 0),JV.set(this,void 0),HX.set(this,void 0),ZV.set(this,void 0),this.tag=K9.CertificateTag}onInit(W){}getExtension(W){for(let Y of this.extensions)if(typeof W==="string"){if(Y.type===W)return Y}else if(Y instanceof W)return Y;return null}getExtensions(W){return this.extensions.filter((Y)=>{if(typeof W==="string")return Y.type===W;else return Y instanceof W})}async verify(W={},Y=v8.get()){let G,X,J=W.publicKey;try{if(!J)G={...this.publicKey.algorithm,...this.signatureAlgorithm},X=await this.publicKey.export(G,["verify"],Y);else if("publicKey"in J)G={...J.publicKey.algorithm,...this.signatureAlgorithm},X=await J.publicKey.export(G,["verify"],Y);else if(J instanceof o5)G={...J.algorithm,...this.signatureAlgorithm},X=await J.export(G,["verify"],Y);else if(_0.isBufferSource(J)){let Q=new o5(J);G={...Q.algorithm,...this.signatureAlgorithm},X=await Q.export(G,["verify"],Y)}else G={...J.algorithm,...this.signatureAlgorithm},X=J}catch{return!1}let Z=Q8.resolveAll(AV).reverse(),V=null;for(let Q of Z)if(V=Q.toWebSignature(G,this.signature),V)break;if(!V)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let U=await Y.subtle.verify(this.signatureAlgorithm,X,V,this.tbs);if(W.signatureOnly)return U;else{let H=(W.date||new Date).getTime();return U&&this.notBefore.getTime()<H&&H<this.notAfter.getTime()}}async getThumbprint(...W){let Y,G="SHA-1";if(W[0])if(!W[0].subtle)G=W[0]||G,Y=W[1];else Y=W[0];return Y!==null&&Y!==void 0||(Y=v8.get()),await Y.subtle.digest(G,this.rawData)}async isSelfSigned(W=v8.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},W)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,m5),G=Y.tbsCertificate,X=new o1("",{Version:`${P7[G.version]} (${G.version})`,"Serial Number":G.serialNumber,"Signature Algorithm":k6.serializeAlgorithm(G.signature),Issuer:this.issuer,Validity:new o1("",{"Not Before":G.validity.notBefore.getTime(),"Not After":G.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(G.issuerUniqueID)X["Issuer Unique ID"]=G.issuerUniqueID;if(G.subjectUniqueID)X["Subject Unique ID"]=G.subjectUniqueID;if(this.extensions.length){let J=new o1("");for(let Z of this.extensions){let V=Z.toTextObject();J[V[o1.NAME]]=V}X.Extensions=J}return W.Data=X,W.Signature=new o1("",{Algorithm:k6.serializeAlgorithm(Y.signatureAlgorithm),"":Y.signatureValue}),W}}rZ=new WeakMap,aZ=new WeakMap,sZ=new WeakMap,tZ=new WeakMap,eZ=new WeakMap,WV=new WeakMap,YV=new WeakMap,GV=new WeakMap,XV=new WeakMap,JV=new WeakMap,HX=new WeakMap,ZV=new WeakMap;Ij.NAME="Certificate";function Ac(W,Y=v8.get()){let G=_0.toUint8Array(o0.FromHex(W||"")),X=G&&G.length&&G.some((Z)=>Z>0)?new Uint8Array(G):void 0;if(!X)X=Y.getRandomValues(new Uint8Array(16));let J=0;while(J<X.length-1&&X[J]===0)J++;if(X=X.slice(J),X[0]>127){let Z=new Uint8Array(X.length+1);Z[0]=0,Z.set(X,1),X=Z}return X.buffer}class zj{static async createSelfSigned(W,Y=v8.get()){if(!W.keys.privateKey)throw Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!W.keys.publicKey)throw Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:W.serialNumber,subject:W.name,issuer:W.name,notBefore:W.notBefore,notAfter:W.notAfter,publicKey:W.keys.publicKey,signingKey:W.keys.privateKey,signingAlgorithm:W.signingAlgorithm,extensions:W.extensions},Y)}static async create(W,Y=v8.get()){var G;let X;if(W.publicKey instanceof o5)X=W.publicKey.rawData;else if("publicKey"in W.publicKey)X=W.publicKey.publicKey.rawData;else if(_0.isBufferSource(W.publicKey))X=W.publicKey;else X=await Y.subtle.exportKey("spki",W.publicKey);let J=Ac(W.serialNumber,Y),Z=W.notBefore||new Date,V=W.notAfter||new Date(Z.getTime()+31536000000),U=new m5({tbsCertificate:new O9({version:P7.v3,serialNumber:J,validity:new P6({notBefore:Z,notAfter:V}),extensions:new X5(((G=W.extensions)===null||G===void 0?void 0:G.map((D)=>E0.parse(D.rawData,j9)))||[]),subjectPublicKeyInfo:E0.parse(X,w9)})});if(W.subject){let D=W.subject instanceof d5?W.subject:new d5(W.subject);U.tbsCertificate.subject=E0.parse(D.toArrayBuffer(),G8)}if(W.issuer){let D=W.issuer instanceof d5?W.issuer:new d5(W.issuer);U.tbsCertificate.issuer=E0.parse(D.toArrayBuffer(),G8)}let Q={hash:"SHA-256"},H="signingKey"in W?{...Q,...W.signingAlgorithm,...W.signingKey.algorithm}:{...Q,...W.signingAlgorithm},N=Q8.resolve(ZY);U.tbsCertificate.signature=U.signatureAlgorithm=N.toAsnAlgorithm(H);let A=E0.serialize(U.tbsCertificate),q="signingKey"in W?await Y.subtle.sign(H,W.signingKey,A):W.signature,z=Q8.resolveAll(AV).reverse(),w=null;for(let D of z)if(w=D.toAsnSignature(H,q),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return U.signatureValue=w,new Ij(E0.serialize(U))}}var Ic,zc,wc,jc,Oc,$3;(function(W){W[W.unspecified=0]="unspecified",W[W.keyCompromise=1]="keyCompromise",W[W.cACompromise=2]="cACompromise",W[W.affiliationChanged=3]="affiliationChanged",W[W.superseded=4]="superseded",W[W.cessationOfOperation=5]="cessationOfOperation",W[W.certificateHold=6]="certificateHold",W[W.removeFromCRL=8]="removeFromCRL",W[W.privilegeWithdrawn=9]="privilegeWithdrawn",W[W.aACompromise=10]="aACompromise"})($3||($3={}));Ic=new WeakMap,zc=new WeakMap,wc=new WeakMap,jc=new WeakMap,Oc=new WeakMap;var Kc,Dc,Cc,Tc,Rc,Mc,Pc;Kc=new WeakMap,Dc=new WeakMap,Cc=new WeakMap,Tc=new WeakMap,Rc=new WeakMap,Mc=new WeakMap,Pc=new WeakMap;o9.register(NH,Jj);o9.register(KH,Zj);o9.register(DH,Vj);o9.register(bz,tH);o9.register(HH,HV);o9.register(uz,Uj);o9.register(jH,Hj);o9.register(QH,Nj);o9.register(xz,qj);qV.register(pw,Aj);qV.register(bZ,eH);Q8.registerSingleton(AV,v3);Q8.registerSingleton(AV,P5);P5.namedCurveSize.set("P-256",32);P5.namedCurveSize.set("K-256",32);P5.namedCurveSize.set("P-384",48);P5.namedCurveSize.set("P-521",66);var gX=y1(j8(),1),FS=y1(j8(),1),SS=y1(xQ(),1);import{createHash as pd,createHmac as ld}from"crypto";import*as R4 from"crypto";var UY=R4&&typeof R4==="object"&&"webcrypto"in R4?R4.webcrypto:R4&&typeof R4==="object"&&("randomBytes"in R4)?R4:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function QY(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function DV(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function n5(W,...Y){if(!QY(W))throw Error("Uint8Array expected");if(Y.length>0&&!Y.includes(W.length))throw Error("Uint8Array expected of length "+Y+", got length="+W.length)}function UN(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");DV(W.outputLen),DV(W.blockLen)}function wX(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function wE(W,Y){n5(W);let G=Y.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function P4(...W){for(let Y=0;Y<W.length;Y++)W[Y].fill(0)}function QN(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function i5(W,Y){return W<<32-Y|W>>>Y}var jE=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),ep=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function L4(W){if(n5(W),jE)return W.toHex();let Y="";for(let G=0;G<W.length;G++)Y+=ep[W[G]];return Y}var M4={_0:48,_9:57,A:65,F:70,a:97,f:102};function zE(W){if(W>=M4._0&&W<=M4._9)return W-M4._0;if(W>=M4.A&&W<=M4.F)return W-(M4.A-10);if(W>=M4.a&&W<=M4.f)return W-(M4.a-10);return}function HY(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(jE)return Uint8Array.fromHex(W);let Y=W.length,G=Y/2;if(Y%2)throw Error("hex string expected, got unpadded hex of length "+Y);let X=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=zE(W.charCodeAt(Z)),U=zE(W.charCodeAt(Z+1));if(V===void 0||U===void 0){let Q=W[Z]+W[Z+1];throw Error('hex string expected, got non-hex character "'+Q+'" at index '+Z)}X[J]=V*16+U}return X}function HN(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function CV(W){if(typeof W==="string")W=HN(W);return n5(W),W}function i9(...W){let Y=0;for(let X=0;X<W.length;X++){let J=W[X];n5(J),Y+=J.length}let G=new Uint8Array(Y);for(let X=0,J=0;X<W.length;X++){let Z=W[X];G.set(Z,J),J+=Z.length}return G}class TV{}function NN(W){let Y=(X)=>W().update(CV(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function NY(W=32){if(UY&&typeof UY.getRandomValues==="function")return UY.getRandomValues(new Uint8Array(W));if(UY&&typeof UY.randomBytes==="function")return Uint8Array.from(UY.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Ej=BigInt(0),Bj=BigInt(1);function RV(W,Y=""){if(typeof W!=="boolean"){let G=Y&&`"${Y}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function m6(W,Y,G=""){let X=QY(W),J=W?.length,Z=Y!==void 0;if(!X||Z&&J!==Y){let V=G&&`"${G}" `,U=Z?` of length ${Y}`:"",Q=X?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function MV(W){let Y=W.toString(16);return Y.length&1?"0"+Y:Y}function OE(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Ej:BigInt("0x"+W)}function B4(W){return OE(L4(W))}function $j(W){return n5(W),OE(L4(Uint8Array.from(W).reverse()))}function jX(W,Y){return HY(W.toString(16).padStart(Y*2,"0"))}function Fj(W,Y){return jX(W,Y).reverse()}function B8(W,Y,G){let X;if(typeof Y==="string")try{X=HY(Y)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(QY(Y))X=Uint8Array.from(Y);else throw Error(W+" must be hex string or Uint8Array");let J=X.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return X}var Lj=(W)=>typeof W==="bigint"&&Ej<=W;function PV(W,Y,G){return Lj(W)&&Lj(Y)&&Lj(G)&&Y<=W&&W<G}function KE(W,Y,G,X){if(!PV(Y,G,X))throw Error("expected valid "+W+": "+G+" <= n < "+X+", got "+Y)}function qN(W){let Y;for(Y=0;W>Ej;W>>=Bj,Y+=1);return Y}var f6=(W)=>(Bj<<BigInt(W))-Bj;function DE(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=(z)=>new Uint8Array(z),J=(z)=>Uint8Array.of(z),Z=X(W),V=X(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},H=(...z)=>G(V,Z,...z),N=(z=X(0))=>{if(V=H(J(0),z),Z=H(),z.length===0)return;V=H(J(1),z),Z=H()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let z=0,w=[];while(z<Y){Z=H();let D=Z.slice();w.push(D),z+=Z.length}return i9(...w)};return(z,w)=>{Q(),N(z);let D=void 0;while(!(D=w(A())))N();return Q(),D}}function LV(W,Y,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function X(J,Z,V){let U=W[J];if(V&&U===void 0)return;let Q=typeof U;if(Q!==Z||U===null)throw Error(`param "${J}" is invalid: expected ${Z}, got ${Q}`)}Object.entries(Y).forEach(([J,Z])=>X(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>X(J,Z,!0))}function Sj(W){let Y=new WeakMap;return(G,...X)=>{let J=Y.get(G);if(J!==void 0)return J;let Z=W(G,...X);return Y.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var v9=BigInt(0),D9=BigInt(1),qY=BigInt(2),RE=BigInt(3),ME=BigInt(4),PE=BigInt(5),Wl=BigInt(7),LE=BigInt(8),Yl=BigInt(9),BE=BigInt(16);function U5(W,Y){let G=W%Y;return G>=v9?G:Y+G}function Q5(W,Y,G){let X=W;while(Y-- >v9)X*=X,X%=G;return X}function CE(W,Y){if(W===v9)throw Error("invert: expected non-zero number");if(Y<=v9)throw Error("invert: expected positive modulus, got "+Y);let G=U5(W,Y),X=Y,J=v9,Z=D9,V=D9,U=v9;while(G!==v9){let H=X/G,N=X%G,A=J-V*H,q=Z-U*H;X=G,G=N,J=V,Z=U,V=A,U=q}if(X!==D9)throw Error("invert: does not exist");return U5(J,Y)}function xj(W,Y,G){if(!W.eql(W.sqr(Y),G))throw Error("Cannot find square root")}function EE(W,Y){let G=(W.ORDER+D9)/ME,X=W.pow(Y,G);return xj(W,X,Y),X}function Gl(W,Y){let G=(W.ORDER-PE)/LE,X=W.mul(Y,qY),J=W.pow(X,G),Z=W.mul(Y,J),V=W.mul(W.mul(Z,qY),J),U=W.mul(Z,W.sub(V,W.ONE));return xj(W,U,Y),U}function Xl(W){let Y=B5(W),G=$E(W),X=G(Y,Y.neg(Y.ONE)),J=G(Y,X),Z=G(Y,Y.neg(X)),V=(W+Wl)/BE;return(U,Q)=>{let H=U.pow(Q,V),N=U.mul(H,X),A=U.mul(H,J),q=U.mul(H,Z),z=U.eql(U.sqr(N),Q),w=U.eql(U.sqr(A),Q);H=U.cmov(H,N,z),N=U.cmov(q,A,w);let D=U.eql(U.sqr(N),Q),T=U.cmov(H,N,D);return xj(U,T,Q),T}}function $E(W){if(W<RE)throw Error("sqrt is not defined for small field");let Y=W-D9,G=0;while(Y%qY===v9)Y/=qY,G++;let X=qY,J=B5(W);while(TE(J,X)===1)if(X++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return EE;let Z=J.pow(X,Y),V=(Y+D9)/qY;return function(Q,H){if(Q.is0(H))return H;if(TE(Q,H)!==1)throw Error("Cannot find square root");let N=G,A=Q.mul(Q.ONE,Z),q=Q.pow(H,Y),z=Q.pow(H,V);while(!Q.eql(q,Q.ONE)){if(Q.is0(q))return Q.ZERO;let w=1,D=Q.sqr(q);while(!Q.eql(D,Q.ONE))if(w++,D=Q.sqr(D),w===N)throw Error("Cannot find square root");let T=D9<<BigInt(N-w-1),x=Q.pow(A,T);N=w,A=Q.sqr(x),q=Q.mul(q,A),z=Q.mul(z,x)}return z}}function Jl(W){if(W%ME===RE)return EE;if(W%LE===PE)return Gl;if(W%BE===Yl)return Xl(W);return $E(W)}var Zl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kj(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Zl.reduce((X,J)=>{return X[J]="function",X},Y);return LV(W,G),W}function Vl(W,Y,G){if(G<v9)throw Error("invalid exponent, negatives unsupported");if(G===v9)return W.ONE;if(G===D9)return Y;let X=W.ONE,J=Y;while(G>v9){if(G&D9)X=W.mul(X,J);J=W.sqr(J),G>>=D9}return X}function AN(W,Y,G=!1){let X=Array(Y.length).fill(G?W.ZERO:void 0),J=Y.reduce((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return Y.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=W.mul(V,X[Q]),W.mul(V,U)},Z),X}function TE(W,Y){let G=(W.ORDER-D9)/qY,X=W.pow(Y,G),J=W.eql(X,W.ONE),Z=W.eql(X,W.ZERO),V=W.eql(X,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function IN(W,Y){if(Y!==void 0)DV(Y);let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function B5(W,Y,G=!1,X={}){if(W<=v9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof Y==="object"&&Y!=null){if(X.sqrt||G)throw Error("cannot specify opts in two arguments");let q=Y;if(q.BITS)J=q.BITS;if(q.sqrt)Z=q.sqrt;if(typeof q.isLE==="boolean")G=q.isLE;if(typeof q.modFromBytes==="boolean")V=q.modFromBytes;U=q.allowedLengths}else{if(typeof Y==="number")J=Y;if(X.sqrt)Z=X.sqrt}let{nBitLength:Q,nByteLength:H}=IN(W,J);if(H>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let N,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:H,MASK:f6(Q),ZERO:v9,ONE:D9,allowedLengths:U,create:(q)=>U5(q,W),isValid:(q)=>{if(typeof q!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof q);return v9<=q&&q<W},is0:(q)=>q===v9,isValidNot0:(q)=>!A.is0(q)&&A.isValid(q),isOdd:(q)=>(q&D9)===D9,neg:(q)=>U5(-q,W),eql:(q,z)=>q===z,sqr:(q)=>U5(q*q,W),add:(q,z)=>U5(q+z,W),sub:(q,z)=>U5(q-z,W),mul:(q,z)=>U5(q*z,W),pow:(q,z)=>Vl(A,q,z),div:(q,z)=>U5(q*CE(z,W),W),sqrN:(q)=>q*q,addN:(q,z)=>q+z,subN:(q,z)=>q-z,mulN:(q,z)=>q*z,inv:(q)=>CE(q,W),sqrt:Z||((q)=>{if(!N)N=Jl(W);return N(A,q)}),toBytes:(q)=>G?Fj(q,H):jX(q,H),fromBytes:(q,z=!0)=>{if(U){if(!U.includes(q.length)||q.length>H)throw Error("Field.fromBytes: expected "+U+" bytes, got "+q.length);let D=new Uint8Array(H);D.set(q,G?0:D.length-q.length),q=D}if(q.length!==H)throw Error("Field.fromBytes: expected "+H+" bytes, got "+q.length);let w=G?$j(q):B4(q);if(V)w=U5(w,W);if(!z){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(q)=>AN(A,q),cmov:(q,z,w)=>w?z:q});return Object.freeze(A)}function FE(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function _j(W){let Y=FE(W);return Y+Math.ceil(Y/2)}function zN(W,Y,G=!1){let X=W.length,J=FE(Y),Z=_j(Y);if(X<16||X<Z||X>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+X);let V=G?$j(W):B4(W),U=U5(V,Y-D9)+D9;return G?Fj(U,J):jX(U,J)}function Ul(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}function SE(W,Y,G){return W&Y^~W&G}function xE(W,Y,G){return W&Y^W&G^Y&G}class wN extends TV{constructor(W,Y,G,X){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.buffer=new Uint8Array(W),this.view=QN(this.buffer)}update(W){wX(this),W=CV(W),n5(W);let{view:Y,buffer:G,blockLen:X}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=QN(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){wX(this),wE(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,P4(this.buffer.subarray(Z)),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Ul(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=QN(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=X,W.pos=V,X%Y)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var E4=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var G9=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),X9=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var jN=BigInt(4294967295),kE=BigInt(32);function Ql(W,Y=!1){if(Y)return{h:Number(W&jN),l:Number(W>>kE&jN)};return{h:Number(W>>kE&jN)|0,l:Number(W&jN)|0}}function _E(W,Y=!1){let G=W.length,X=new Uint32Array(G),J=new Uint32Array(G);for(let Z=0;Z<G;Z++){let{h:V,l:U}=Ql(W[Z],Y);[X[Z],J[Z]]=[V,U]}return[X,J]}var yj=(W,Y,G)=>W>>>G,vj=(W,Y,G)=>W<<32-G|Y>>>G,AY=(W,Y,G)=>W>>>G|Y<<32-G,IY=(W,Y,G)=>W<<32-G|Y>>>G,BV=(W,Y,G)=>W<<64-G|Y>>>G-32,EV=(W,Y,G)=>W>>>G-32|Y<<64-G;function k7(W,Y,G,X){let J=(Y>>>0)+(X>>>0);return{h:W+G+(J/4294967296|0)|0,l:J|0}}var yE=(W,Y,G)=>(W>>>0)+(Y>>>0)+(G>>>0),vE=(W,Y,G,X)=>Y+G+X+(W/4294967296|0)|0,gE=(W,Y,G,X)=>(W>>>0)+(Y>>>0)+(G>>>0)+(X>>>0),uE=(W,Y,G,X,J)=>Y+G+X+J+(W/4294967296|0)|0,hE=(W,Y,G,X,J)=>(W>>>0)+(Y>>>0)+(G>>>0)+(X>>>0)+(J>>>0),bE=(W,Y,G,X,J,Z)=>Y+G+X+J+Z+(W/4294967296|0)|0;var Nl=Uint32Array.from([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]),c6=new Uint32Array(64);class mE extends wN{constructor(W=32){super(64,W,8,!1);this.A=E4[0]|0,this.B=E4[1]|0,this.C=E4[2]|0,this.D=E4[3]|0,this.E=E4[4]|0,this.F=E4[5]|0,this.G=E4[6]|0,this.H=E4[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)c6[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=c6[N-15],q=c6[N-2],z=i5(A,7)^i5(A,18)^A>>>3,w=i5(q,17)^i5(q,19)^q>>>10;c6[N]=w+c6[N-7]+z+c6[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=i5(V,6)^i5(V,11)^i5(V,25),q=H+A+SE(V,U,Q)+Nl[N]+c6[N]|0,w=(i5(G,2)^i5(G,13)^i5(G,22))+xE(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+w|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){P4(c6)}destroy(){this.set(0,0,0,0,0,0,0,0),P4(this.buffer)}}var fE=(()=>_E(["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((W)=>BigInt(W))))(),ql=(()=>fE[0])(),Al=(()=>fE[1])(),p6=new Uint32Array(80),l6=new Uint32Array(80);class gj extends wN{constructor(W=64){super(128,W,16,!1);this.Ah=X9[0]|0,this.Al=X9[1]|0,this.Bh=X9[2]|0,this.Bl=X9[3]|0,this.Ch=X9[4]|0,this.Cl=X9[5]|0,this.Dh=X9[6]|0,this.Dl=X9[7]|0,this.Eh=X9[8]|0,this.El=X9[9]|0,this.Fh=X9[10]|0,this.Fl=X9[11]|0,this.Gh=X9[12]|0,this.Gl=X9[13]|0,this.Hh=X9[14]|0,this.Hl=X9[15]|0}get(){let{Ah:W,Al:Y,Bh:G,Bl:X,Ch:J,Cl:Z,Dh:V,Dl:U,Eh:Q,El:H,Fh:N,Fl:A,Gh:q,Gl:z,Hh:w,Hl:D}=this;return[W,Y,G,X,J,Z,V,U,Q,H,N,A,q,z,w,D]}set(W,Y,G,X,J,Z,V,U,Q,H,N,A,q,z,w,D){this.Ah=W|0,this.Al=Y|0,this.Bh=G|0,this.Bl=X|0,this.Ch=J|0,this.Cl=Z|0,this.Dh=V|0,this.Dl=U|0,this.Eh=Q|0,this.El=H|0,this.Fh=N|0,this.Fl=A|0,this.Gh=q|0,this.Gl=z|0,this.Hh=w|0,this.Hl=D|0}process(W,Y){for(let g=0;g<16;g++,Y+=4)p6[g]=W.getUint32(Y),l6[g]=W.getUint32(Y+=4);for(let g=16;g<80;g++){let f=p6[g-15]|0,y=l6[g-15]|0,p=AY(f,y,1)^AY(f,y,8)^yj(f,y,7),b=IY(f,y,1)^IY(f,y,8)^vj(f,y,7),m=p6[g-2]|0,W0=l6[g-2]|0,u=AY(m,W0,19)^BV(m,W0,61)^yj(m,W0,6),J0=IY(m,W0,19)^EV(m,W0,61)^vj(m,W0,6),A0=gE(b,J0,l6[g-7],l6[g-16]),k=uE(A0,p,u,p6[g-7],p6[g-16]);p6[g]=k|0,l6[g]=A0|0}let{Ah:G,Al:X,Bh:J,Bl:Z,Ch:V,Cl:U,Dh:Q,Dl:H,Eh:N,El:A,Fh:q,Fl:z,Gh:w,Gl:D,Hh:T,Hl:x}=this;for(let g=0;g<80;g++){let f=AY(N,A,14)^AY(N,A,18)^BV(N,A,41),y=IY(N,A,14)^IY(N,A,18)^EV(N,A,41),p=N&q^~N&w,b=A&z^~A&D,m=hE(x,y,b,Al[g],l6[g]),W0=bE(m,T,f,p,ql[g],p6[g]),u=m|0,J0=AY(G,X,28)^BV(G,X,34)^BV(G,X,39),A0=IY(G,X,28)^EV(G,X,34)^EV(G,X,39),k=G&J^G&V^J&V,l=X&Z^X&U^Z&U;T=w|0,x=D|0,w=q|0,D=z|0,q=N|0,z=A|0,{h:N,l:A}=k7(Q|0,H|0,W0|0,u|0),Q=V|0,H=U|0,V=J|0,U=Z|0,J=G|0,Z=X|0;let B=yE(u,A0,l);G=vE(B,W0,J0,k),X=B|0}({h:G,l:X}=k7(this.Ah|0,this.Al|0,G|0,X|0)),{h:J,l:Z}=k7(this.Bh|0,this.Bl|0,J|0,Z|0),{h:V,l:U}=k7(this.Ch|0,this.Cl|0,V|0,U|0),{h:Q,l:H}=k7(this.Dh|0,this.Dl|0,Q|0,H|0),{h:N,l:A}=k7(this.Eh|0,this.El|0,N|0,A|0),{h:q,l:z}=k7(this.Fh|0,this.Fl|0,q|0,z|0),{h:w,l:D}=k7(this.Gh|0,this.Gl|0,w|0,D|0),{h:T,l:x}=k7(this.Hh|0,this.Hl|0,T|0,x|0),this.set(G,X,J,Z,V,U,Q,H,N,A,q,z,w,D,T,x)}roundClean(){P4(p6,l6)}destroy(){P4(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class cE extends gj{constructor(){super(48);this.Ah=G9[0]|0,this.Al=G9[1]|0,this.Bh=G9[2]|0,this.Bl=G9[3]|0,this.Ch=G9[4]|0,this.Cl=G9[5]|0,this.Dh=G9[6]|0,this.Dl=G9[7]|0,this.Eh=G9[8]|0,this.El=G9[9]|0,this.Fh=G9[10]|0,this.Fl=G9[11]|0,this.Gh=G9[12]|0,this.Gl=G9[13]|0,this.Hh=G9[14]|0,this.Hl=G9[15]|0}}var OX=NN(()=>new mE);var pE=NN(()=>new gj),lE=NN(()=>new cE);class uj extends TV{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,UN(W);let G=CV(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),P4(J)}update(W){return wX(this),this.iHash.update(W),this}digestInto(W){wX(this),n5(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var hj=(W,Y,G)=>new uj(W,Y).update(G).digest();hj.create=(W,Y)=>new uj(W,Y);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var KX=BigInt(0),zY=BigInt(1);function $V(W,Y){let G=Y.negate();return W?G:Y}function ON(W,Y){let G=AN(W.Fp,Y.map((X)=>X.Z));return Y.map((X,J)=>W.fromAffine(X.toAffine(G[J])))}function iE(W,Y){if(!Number.isSafeInteger(W)||W<=0||W>Y)throw Error("invalid window size, expected [1.."+Y+"], got W="+W)}function bj(W,Y){iE(W,Y);let G=Math.ceil(Y/W)+1,X=2**(W-1),J=2**W,Z=f6(W),V=BigInt(W);return{windows:G,windowSize:X,mask:Z,maxNumber:J,shiftBy:V}}function dE(W,Y,G){let{windowSize:X,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>X)U-=Z,Q+=zY;let H=Y*X,N=H+Math.abs(U)-1,A=U===0,q=U<0,z=Y%2!==0;return{nextN:Q,offset:N,isZero:A,isNeg:q,isNegF:z,offsetF:H}}function Il(W,Y){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,X)=>{if(!(G instanceof Y))throw Error("invalid point at index "+X)})}function zl(W,Y){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,X)=>{if(!Y.isValid(G))throw Error("invalid scalar at index "+X)})}var mj=new WeakMap,rE=new WeakMap;function fj(W){return rE.get(W)||1}function oE(W){if(W!==KX)throw Error("invalid wNAF")}class cj{constructor(W,Y){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=Y}_unsafeLadder(W,Y,G=this.ZERO){let X=W;while(Y>KX){if(Y&zY)G=G.add(X);X=X.double(),Y>>=zY}return G}precomputeWindow(W,Y){let{windows:G,windowSize:X}=bj(Y,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<X;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,Y,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let X=this.ZERO,J=this.BASE,Z=bj(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:H,isNeg:N,isNegF:A,offsetF:q}=dE(G,V,Z);if(G=U,H)J=J.add($V(A,Y[q]));else X=X.add($V(N,Y[Q]))}return oE(G),{p:X,f:J}}wNAFUnsafe(W,Y,G,X=this.ZERO){let J=bj(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===KX)break;let{nextN:V,offset:U,isZero:Q,isNeg:H}=dE(G,Z,J);if(G=V,Q)continue;else{let N=Y[U];X=X.add(H?N.negate():N)}}return oE(G),X}getPrecomputes(W,Y,G){let X=mj.get(Y);if(!X){if(X=this.precomputeWindow(Y,W),W!==1){if(typeof G==="function")X=G(X);mj.set(Y,X)}}return X}cached(W,Y,G){let X=fj(W);return this.wNAF(X,this.getPrecomputes(X,W,G),Y)}unsafe(W,Y,G,X){let J=fj(W);if(J===1)return this._unsafeLadder(W,Y,X);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),Y,X)}createCache(W,Y){iE(Y,this.bits),rE.set(W,Y),mj.delete(W)}hasCache(W){return fj(W)!==1}}function aE(W,Y,G,X){let J=Y,Z=W.ZERO,V=W.ZERO;while(G>KX||X>KX){if(G&zY)Z=Z.add(J);if(X&zY)V=V.add(J);J=J.double(),G>>=zY,X>>=zY}return{p1:Z,p2:V}}function sE(W,Y,G,X){Il(G,W),zl(X,Y);let J=G.length,Z=X.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=qN(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let H=f6(Q),N=Array(Number(H)+1).fill(V),A=Math.floor((Y.BITS-1)/Q)*Q,q=V;for(let z=A;z>=0;z-=Q){N.fill(V);for(let D=0;D<Z;D++){let T=X[D],x=Number(T>>BigInt(z)&H);N[x]=N[x].add(G[D])}let w=V;for(let D=N.length-1,T=V;D>0;D--)T=T.add(N[D]),w=w.add(T);if(q=q.add(w),z!==0)for(let D=0;D<Q;D++)q=q.double()}return q}function nE(W,Y,G){if(Y){if(Y.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return kj(Y),Y}else return B5(W,{isLE:G})}function tE(W,Y,G={},X){if(X===void 0)X=W==="edwards";if(!Y||typeof Y!=="object")throw Error(`expected valid ${W} CURVE object`);for(let Q of["p","n","h"]){let H=Y[Q];if(!(typeof H==="bigint"&&H>KX))throw Error(`CURVE.${Q} must be positive bigint`)}let J=nE(Y.p,G.Fp,X),Z=nE(Y.n,G.Fn,X),U=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let Q of U)if(!J.isValid(Y[Q]))throw Error(`CURVE.${Q} must be valid field element of CURVE.Fp`);return Y=Object.freeze(Object.assign({},Y)),{CURVE:Y,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var eE=(W,Y)=>(W+(W>=0?Y:-Y)/Y$)/Y;function wl(W,Y,G){let[[X,J],[Z,V]]=Y,U=eE(V*W,G),Q=eE(-J*W,G),H=W-U*X-Q*Z,N=-U*J-Q*V,A=H<F4,q=N<F4;if(A)H=-H;if(q)N=-N;let z=f6(Math.ceil(qN(G)/2))+DX;if(H<F4||H>=z||N<F4||N>=z)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}function lj(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function pj(W,Y){let G={};for(let X of Object.keys(Y))G[X]=W[X]===void 0?Y[X]:W[X];if(RV(G.lowS,"lowS"),RV(G.prehash,"prehash"),G.format!==void 0)lj(G.format);return G}class W$ extends Error{constructor(W=""){super(W)}}var $4={Err:W$,_tlv:{encode:(W,Y)=>{let{Err:G}=$4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length&1)throw new G("tlv.encode: unpadded data");let X=Y.length/2,J=MV(X);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=X>127?MV(J.length/2|128):"";return MV(W)+Z+J+Y},decode(W,Y){let{Err:G}=$4,X=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length<2||Y[X++]!==W)throw new G("tlv.decode: wrong tlv");let J=Y[X++],Z=!!(J&128),V=0;if(!Z)V=J;else{let Q=J&127;if(!Q)throw new G("tlv.decode(long): indefinite length not supported");if(Q>4)throw new G("tlv.decode(long): byte length is too big");let H=Y.subarray(X,X+Q);if(H.length!==Q)throw new G("tlv.decode: length bytes not complete");if(H[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let N of H)V=V<<8|N;if(X+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=Y.subarray(X,X+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:Y.subarray(X+V)}}},_int:{encode(W){let{Err:Y}=$4;if(W<F4)throw new Y("integer: negative integers are not allowed");let G=MV(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new Y("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:Y}=$4;if(W[0]&128)throw new Y("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new Y("invalid signature integer: unnecessary leading zero");return B4(W)}},toSig(W){let{Err:Y,_int:G,_tlv:X}=$4,J=B8("signature",W),{v:Z,l:V}=X.decode(48,J);if(V.length)throw new Y("invalid signature: left bytes after parsing");let{v:U,l:Q}=X.decode(2,Z),{v:H,l:N}=X.decode(2,Q);if(N.length)throw new Y("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(H)}},hexFromSig(W){let{_tlv:Y,_int:G}=$4,X=Y.encode(2,G.encode(W.r)),J=Y.encode(2,G.encode(W.s)),Z=X+J;return Y.encode(48,Z)}},F4=BigInt(0),DX=BigInt(1),Y$=BigInt(2),KN=BigInt(3),jl=BigInt(4);function d6(W,Y){let{BYTES:G}=W,X;if(typeof Y==="bigint")X=Y;else{let J=B8("private key",Y);try{X=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof Y}`)}}if(!W.isValidNot0(X))throw Error("invalid private key: out of range [1..N-1]");return X}function Ol(W,Y={}){let G=tE("weierstrass",W,Y),{Fp:X,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;LV(Y,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=Y;if(Q){if(!X.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let H=X$(X,J);function N(){if(!X.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(k,l,B){let{x:$,y:h}=l.toAffine(),a=X.toBytes($);if(RV(B,"isCompressed"),B){N();let n=!X.isOdd(h);return i9(G$(n),a)}else return i9(Uint8Array.of(4),a,X.toBytes(h))}function q(k){m6(k,void 0,"Point");let{publicKey:l,publicKeyUncompressed:B}=H,$=k.length,h=k[0],a=k.subarray(1);if($===l&&(h===2||h===3)){let n=X.fromBytes(a);if(!X.isValid(n))throw Error("bad point: is not on curve, wrong x");let E=D(n),P;try{P=X.sqrt(E)}catch(F){let c=F instanceof Error?": "+F.message:"";throw Error("bad point: is not on curve, sqrt error"+c)}N();let v=X.isOdd(P);if((h&1)===1!==v)P=X.neg(P);return{x:n,y:P}}else if($===B&&h===4){let n=X.BYTES,E=X.fromBytes(a.subarray(0,n)),P=X.fromBytes(a.subarray(n,n*2));if(!T(E,P))throw Error("bad point: is not on curve");return{x:E,y:P}}else throw Error(`bad point: got length ${$}, expected compressed=${l} or uncompressed=${B}`)}let z=Y.toBytes||A,w=Y.fromBytes||q;function D(k){let l=X.sqr(k),B=X.mul(l,k);return X.add(X.add(B,X.mul(k,Z.a)),Z.b)}function T(k,l){let B=X.sqr(l),$=D(k);return X.eql(B,$)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=X.mul(X.pow(Z.a,KN),jl),g=X.mul(X.sqr(Z.b),BigInt(27));if(X.is0(X.add(x,g)))throw Error("bad curve params: a or b");function f(k,l,B=!1){if(!X.isValid(l)||B&&X.is0(l))throw Error(`bad point coordinate ${k}`);return l}function y(k){if(!(k instanceof u))throw Error("ProjectivePoint expected")}function p(k){if(!Q||!Q.basises)throw Error("no endo");return wl(k,Q.basises,J.ORDER)}let b=Sj((k,l)=>{let{X:B,Y:$,Z:h}=k;if(X.eql(h,X.ONE))return{x:B,y:$};let a=k.is0();if(l==null)l=a?X.ONE:X.inv(h);let n=X.mul(B,l),E=X.mul($,l),P=X.mul(h,l);if(a)return{x:X.ZERO,y:X.ZERO};if(!X.eql(P,X.ONE))throw Error("invZ was invalid");return{x:n,y:E}}),m=Sj((k)=>{if(k.is0()){if(Y.allowInfinityPoint&&!X.is0(k.Y))return;throw Error("bad point: ZERO")}let{x:l,y:B}=k.toAffine();if(!X.isValid(l)||!X.isValid(B))throw Error("bad point: x or y not field elements");if(!T(l,B))throw Error("bad point: equation left != right");if(!k.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function W0(k,l,B,$,h){return B=new u(X.mul(B.X,k),B.Y,B.Z),l=$V($,l),B=$V(h,B),l.add(B)}class u{constructor(k,l,B){this.X=f("x",k),this.Y=f("y",l,!0),this.Z=f("z",B),Object.freeze(this)}static CURVE(){return Z}static fromAffine(k){let{x:l,y:B}=k||{};if(!k||!X.isValid(l)||!X.isValid(B))throw Error("invalid affine point");if(k instanceof u)throw Error("projective point not allowed");if(X.is0(l)&&X.is0(B))return u.ZERO;return new u(l,B,X.ONE)}static fromBytes(k){let l=u.fromAffine(w(m6(k,void 0,"point")));return l.assertValidity(),l}static fromHex(k){return u.fromBytes(B8("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,l=!0){if(A0.createCache(this,k),!l)this.multiply(KN);return this}assertValidity(){m(this)}hasEvenY(){let{y:k}=this.toAffine();if(!X.isOdd)throw Error("Field doesn't support isOdd");return!X.isOdd(k)}equals(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.eql(X.mul(l,n),X.mul(h,$)),P=X.eql(X.mul(B,n),X.mul(a,$));return E&&P}negate(){return new u(this.X,X.neg(this.Y),this.Z)}double(){let{a:k,b:l}=Z,B=X.mul(l,KN),{X:$,Y:h,Z:a}=this,n=X.ZERO,E=X.ZERO,P=X.ZERO,v=X.mul($,$),M=X.mul(h,h),F=X.mul(a,a),c=X.mul($,h);return c=X.add(c,c),P=X.mul($,a),P=X.add(P,P),n=X.mul(k,P),E=X.mul(B,F),E=X.add(n,E),n=X.sub(M,E),E=X.add(M,E),E=X.mul(n,E),n=X.mul(c,n),P=X.mul(B,P),F=X.mul(k,F),c=X.sub(v,F),c=X.mul(k,c),c=X.add(c,P),P=X.add(v,v),v=X.add(P,v),v=X.add(v,F),v=X.mul(v,c),E=X.add(E,v),F=X.mul(h,a),F=X.add(F,F),v=X.mul(F,c),n=X.sub(n,v),P=X.mul(F,M),P=X.add(P,P),P=X.add(P,P),new u(n,E,P)}add(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.ZERO,P=X.ZERO,v=X.ZERO,M=Z.a,F=X.mul(Z.b,KN),c=X.mul(l,h),t=X.mul(B,a),Y0=X.mul($,n),$0=X.add(l,B),S0=X.add(h,a);$0=X.mul($0,S0),S0=X.add(c,t),$0=X.sub($0,S0),S0=X.add(l,$);let x0=X.add(h,n);return S0=X.mul(S0,x0),x0=X.add(c,Y0),S0=X.sub(S0,x0),x0=X.add(B,$),E=X.add(a,n),x0=X.mul(x0,E),E=X.add(t,Y0),x0=X.sub(x0,E),v=X.mul(M,S0),E=X.mul(F,Y0),v=X.add(E,v),E=X.sub(t,v),v=X.add(t,v),P=X.mul(E,v),t=X.add(c,c),t=X.add(t,c),Y0=X.mul(M,Y0),S0=X.mul(F,S0),t=X.add(t,Y0),Y0=X.sub(c,Y0),Y0=X.mul(M,Y0),S0=X.add(S0,Y0),c=X.mul(t,S0),P=X.add(P,c),c=X.mul(x0,S0),E=X.mul($0,E),E=X.sub(E,c),c=X.mul($0,t),v=X.mul(x0,v),v=X.add(v,c),new u(E,P,v)}subtract(k){return this.add(k.negate())}is0(){return this.equals(u.ZERO)}multiply(k){let{endo:l}=Y;if(!J.isValidNot0(k))throw Error("invalid scalar: out of range");let B,$,h=(a)=>A0.cached(this,a,(n)=>ON(u,n));if(l){let{k1neg:a,k1:n,k2neg:E,k2:P}=p(k),{p:v,f:M}=h(n),{p:F,f:c}=h(P);$=M.add(c),B=W0(l.beta,v,F,a,E)}else{let{p:a,f:n}=h(k);B=a,$=n}return ON(u,[B,$])[0]}multiplyUnsafe(k){let{endo:l}=Y,B=this;if(!J.isValid(k))throw Error("invalid scalar: out of range");if(k===F4||B.is0())return u.ZERO;if(k===DX)return B;if(A0.hasCache(this))return this.multiply(k);if(l){let{k1neg:$,k1:h,k2neg:a,k2:n}=p(k),{p1:E,p2:P}=aE(u,B,h,n);return W0(l.beta,E,P,$,a)}else return A0.unsafe(B,k)}multiplyAndAddUnsafe(k,l,B){let $=this.multiplyUnsafe(l).add(k.multiplyUnsafe(B));return $.is0()?void 0:$}toAffine(k){return b(this,k)}isTorsionFree(){let{isTorsionFree:k}=Y;if(V===DX)return!0;if(k)return k(u,this);return A0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:k}=Y;if(V===DX)return this;if(k)return k(u,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(k=!0){return RV(k,"isCompressed"),this.assertValidity(),z(u,this,k)}toHex(k=!0){return L4(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return ON(u,k)}static msm(k,l){return sE(u,J,k,l)}static fromPrivateKey(k){return u.BASE.multiply(d6(J,k))}}u.BASE=new u(Z.Gx,Z.Gy,X.ONE),u.ZERO=new u(X.ZERO,X.ONE,X.ZERO),u.Fp=X,u.Fn=J;let J0=J.BITS,A0=new cj(u,Y.endo?Math.ceil(J0/2):J0);return u.BASE.precompute(8),u}function G$(W){return Uint8Array.of(W?2:3)}function X$(W,Y){return{secretKey:Y.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*Y.BYTES}}function Kl(W,Y={}){let{Fn:G}=W,X=Y.randomBytes||NY,J=Object.assign(X$(W.Fp,G),{seed:_j(G.ORDER)});function Z(z){try{return!!d6(G,z)}catch(w){return!1}}function V(z,w){let{publicKey:D,publicKeyUncompressed:T}=J;try{let x=z.length;if(w===!0&&x!==D)return!1;if(w===!1&&x!==T)return!1;return!!W.fromBytes(z)}catch(x){return!1}}function U(z=X(J.seed)){return zN(m6(z,J.seed,"seed"),G.ORDER)}function Q(z,w=!0){return W.BASE.multiply(d6(G,z)).toBytes(w)}function H(z){let w=U(z);return{secretKey:w,publicKey:Q(w)}}function N(z){if(typeof z==="bigint")return!1;if(z instanceof W)return!0;let{secretKey:w,publicKey:D,publicKeyUncompressed:T}=J;if(G.allowedLengths||w===D)return;let x=B8("key",z).length;return x===D||x===T}function A(z,w,D=!0){if(N(z)===!0)throw Error("first arg must be private key");if(N(w)===!1)throw Error("second arg must be public key");let T=d6(G,z);return W.fromHex(w).multiply(T).toBytes(D)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:H,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(z)=>d6(G,z),precompute(z=8,w=W.BASE){return w.precompute(z,!1)}},lengths:J})}function Dl(W,Y,G={}){UN(Y),LV(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let X=G.randomBytes||NY,J=G.hmac||((B,...$)=>hj(Y,B,i9(...$))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z}=Kl(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},D="compact";function T(B){let $=U>>DX;return B>$}function x(B,$){if(!V.isValidNot0($))throw Error(`invalid signature ${B}: out of range 1..Point.Fn.ORDER`);return $}function g(B,$){lj($);let h=z.signature,a=$==="compact"?h:$==="recovered"?h+1:void 0;return m6(B,a,`${$} signature`)}class f{constructor(B,$,h){if(this.r=x("r",B),this.s=x("s",$),h!=null)this.recovery=h;Object.freeze(this)}static fromBytes(B,$=D){g(B,$);let h;if($==="der"){let{r:P,s:v}=$4.toSig(m6(B));return new f(P,v)}if($==="recovered")h=B[0],$="compact",B=B.subarray(1);let a=V.BYTES,n=B.subarray(0,a),E=B.subarray(a,a*2);return new f(V.fromBytes(n),V.fromBytes(E),h)}static fromHex(B,$){return this.fromBytes(HY(B),$)}addRecoveryBit(B){return new f(this.r,this.s,B)}recoverPublicKey(B){let $=Z.ORDER,{r:h,s:a,recovery:n}=this;if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");if(U*Y$<$&&n>1)throw Error("recovery id is ambiguous for h>1 curve");let P=n===2||n===3?h+U:h;if(!Z.isValid(P))throw Error("recovery id 2 or 3 invalid");let v=Z.toBytes(P),M=W.fromBytes(i9(G$((n&1)===0),v)),F=V.inv(P),c=p(B8("msgHash",B)),t=V.create(-c*F),Y0=V.create(a*F),$0=W.BASE.multiplyUnsafe(t).add(M.multiplyUnsafe(Y0));if($0.is0())throw Error("point at infinify");return $0.assertValidity(),$0}hasHighS(){return T(this.s)}toBytes(B=D){if(lj(B),B==="der")return HY($4.hexFromSig(this));let $=V.toBytes(this.r),h=V.toBytes(this.s);if(B==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return i9(Uint8Array.of(this.recovery),$,h)}return i9($,h)}toHex(B){return L4(this.toBytes(B))}assertValidity(){}static fromCompact(B){return f.fromBytes(B8("sig",B),"compact")}static fromDER(B){return f.fromBytes(B8("sig",B),"der")}normalizeS(){return this.hasHighS()?new f(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return L4(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return L4(this.toBytes("compact"))}}let y=G.bits2int||function($){if($.length>8192)throw Error("input is too large");let h=B4($),a=$.length*8-Q;return a>0?h>>BigInt(a):h},p=G.bits2int_modN||function($){return V.create(y($))},b=f6(Q);function m(B){return KE("num < 2^"+Q,B,F4,b),V.toBytes(B)}function W0(B,$){return m6(B,void 0,"message"),$?m6(Y(B),void 0,"prehashed message"):B}function u(B,$,h){if(["recovered","canonical"].some((Y0)=>(Y0 in h)))throw Error("sign() legacy options not supported");let{lowS:a,prehash:n,extraEntropy:E}=pj(h,w);B=W0(B,n);let P=p(B),v=d6(V,$),M=[m(v),m(P)];if(E!=null&&E!==!1){let Y0=E===!0?X(z.secretKey):E;M.push(B8("extraEntropy",Y0))}let F=i9(...M),c=P;function t(Y0){let $0=y(Y0);if(!V.isValidNot0($0))return;let S0=V.inv($0),x0=W.BASE.multiply($0).toAffine(),D1=V.create(x0.x);if(D1===F4)return;let b0=V.create(S0*V.create(c+D1*v));if(b0===F4)return;let Q0=(x0.x===D1?0:2)|Number(x0.y&DX),O0=b0;if(a&&T(b0))O0=V.neg(b0),Q0^=1;return new f(D1,O0,Q0)}return{seed:F,k2sig:t}}function J0(B,$,h={}){B=B8("message",B);let{seed:a,k2sig:n}=u(B,$,h);return DE(Y.outputLen,V.BYTES,J)(a,n)}function A0(B){let $=void 0,h=typeof B==="string"||QY(B),a=!h&&B!==null&&typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint";if(!h&&!a)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(a)$=new f(B.r,B.s);else if(h){try{$=f.fromBytes(B8("sig",B),"der")}catch(n){if(!(n instanceof $4.Err))throw n}if(!$)try{$=f.fromBytes(B8("sig",B),"compact")}catch(n){return!1}}if(!$)return!1;return $}function k(B,$,h,a={}){let{lowS:n,prehash:E,format:P}=pj(a,w);if(h=B8("publicKey",h),$=W0(B8("message",$),E),"strict"in a)throw Error("options.strict was renamed to lowS");let v=P===void 0?A0(B):f.fromBytes(B8("sig",B),P);if(v===!1)return!1;try{let M=W.fromBytes(h);if(n&&v.hasHighS())return!1;let{r:F,s:c}=v,t=p($),Y0=V.inv(c),$0=V.create(t*Y0),S0=V.create(F*Y0),x0=W.BASE.multiplyUnsafe($0).add(M.multiplyUnsafe(S0));if(x0.is0())return!1;return V.create(x0.x)===F}catch(M){return!1}}function l(B,$,h={}){let{prehash:a}=pj(h,w);return $=W0($,a),f.fromBytes(B,"recovered").recoverPublicKey($).toBytes()}return Object.freeze({keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z,Point:W,sign:J0,verify:k,recoverPublicKey:l,Signature:f,hash:Y})}function Cl(W){let Y={a:W.a,b:W.b,p:W.Fp.ORDER,n:W.n,h:W.h,Gx:W.Gx,Gy:W.Gy},G=W.Fp,X=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=B5(Y.n,{BITS:W.nBitLength,allowedLengths:X,modFromBytes:W.wrapPrivateKey}),Z={Fp:G,Fn:J,allowInfinityPoint:W.allowInfinityPoint,endo:W.endo,isTorsionFree:W.isTorsionFree,clearCofactor:W.clearCofactor,fromBytes:W.fromBytes,toBytes:W.toBytes};return{CURVE:Y,curveOpts:Z}}function Tl(W){let{CURVE:Y,curveOpts:G}=Cl(W),X={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:Y,curveOpts:G,hash:W.hash,ecdsaOpts:X}}function Rl(W,Y){let G=Y.Point;return Object.assign({},Y,{ProjectivePoint:G,CURVE:Object.assign({},W,IN(G.Fn.ORDER,G.Fn.BITS))})}function J$(W){let{CURVE:Y,curveOpts:G,hash:X,ecdsaOpts:J}=Tl(W),Z=Ol(Y,G),V=Dl(Z,X,J);return Rl(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function CX(W,Y){let G=(X)=>J$({...W,hash:X});return{...G(Y),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Z$={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},V$={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},U$={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},Ml=B5(Z$.p),Pl=B5(V$.p),Ll=B5(U$.p);var Q$=CX({...Z$,Fp:Ml,lowS:!1},OX);var FN0=CX({...V$,Fp:Pl,lowS:!1},lE);var SN0=CX({...U$,Fp:Ll,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},pE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var DN=Q$;var Z9=y1(j8(),1),G7=y1(j8(),1),uS=y1(j8(),1),CY=y1(j8(),1),c4=y1(j8(),1),pS=y1(xQ(),1),RY=y1(j8(),1),i6=y1(j8(),1),MY=y1(j8(),1),cX=y1(j8(),1),r6=y1(j8(),1),PY=y1(j8(),1),X7=y1(j8(),1),J7=y1(j8(),1),Iq=y1(j8(),1),Y7=y1(j8(),1),sS=y1(j8(),1),Lo=y1(A$(),1);import{randomBytes as Vo}from"crypto";import{setTimeout as Uo}from"timers/promises";import{createCipheriv as Ko,createDecipheriv as Do}from"crypto";var vN=y1(z$(),1),LY=y1(j8(),1),KY=y1(j8(),1),l7=y1(j8(),1),c7=y1(j8(),1),BY=y1(j8(),1);import{createHmac as ZO}from"crypto";import{createCipheriv as YF,createDecipheriv as GF,createHmac as XF,timingSafeEqual as Yn}from"crypto";import{createCipheriv as UF,createDecipheriv as QF}from"crypto";import{setTimeout as qn}from"timers/promises";import{randomBytes as jn}from"crypto";import{createHmac as O2}from"crypto";import{randomBytes as K2}from"crypto";var MN="undefined",LX=MN!==typeof Buffer&&Buffer,PX=MN!==typeof Uint8Array&&Uint8Array,RN=MN!==typeof ArrayBuffer&&ArrayBuffer,w$=[0,0,0,0,0,0,0,0],$l=Array.isArray||gl,MX=4294967296,Fl=16777216,BX,PN=O$("Uint64BE",!0,!0),nj=O$("Int64BE",!0,!1);function O$(W,Y,G){var X=Y?0:4,J=Y?4:0,Z=Y?0:3,V=Y?1:2,U=Y?2:1,Q=Y?3:0,H=Y?kl:yl,N=Y?_l:vl,A=w.prototype,q="is"+W,z="_"+q;if(A.buffer=void 0,A.offset=0,A[z]=!0,A.toNumber=g,A.toString=f,A.toJSON=g,A.toArray=Sl,LX)A.toBuffer=xl;if(PX)A.toArrayBuffer=K$;return w[q]=D,w;function w(b,m,W0,u){if(!(this instanceof w))return new w(b,m,W0,u);return T(this,b,m,W0,u)}function D(b){return!!(b&&b[z])}function T(b,m,W0,u,J0){if(PX&&RN){if(m instanceof RN)m=new PX(m);if(u instanceof RN)u=new PX(u)}if(!m&&!W0&&!u&&!BX){b.buffer=D$(w$,0);return}if(!j$(m,W0)){var A0=BX||Array;J0=W0,u=m,W0=0,m=BX===LX?LX.alloc(8):new A0(8)}if(b.buffer=m,b.offset=W0|=0,MN===typeof u)return;if(typeof u==="string")x(m,W0,u,J0||10);else if(j$(u,J0))oj(m,W0,u,J0);else if(typeof J0==="number")y(m,W0+X,u),y(m,W0+J,J0);else if(u>0)H(m,W0,u);else if(u<0)N(m,W0,u);else oj(m,W0,w$,0)}function x(b,m,W0,u){var J0=0,A0=W0.length,k=0,l=0;if(W0[0]==="-")J0++;var B=J0;while(J0<A0){var $=parseInt(W0[J0++],u);if(!($>=0))break;l=l*u+$,k=k*u+Math.floor(l/MX),l%=MX}if(B)if(k=~k,l)l=MX-l;else k++;y(b,m+X,k),y(b,m+J,l)}function g(){var b=this.buffer,m=this.offset,W0=p(b,m+X),u=p(b,m+J);if(!G)W0|=0;return W0?W0*MX+u:u}function f(b){var m=this.buffer,W0=this.offset,u=p(m,W0+X),J0=p(m,W0+J),A0="",k=!G&&u&2147483648;if(k)u=~u,J0=MX-J0;b=b||10;while(!0){var l=u%b*MX+J0;if(u=Math.floor(u/b),J0=Math.floor(l/b),A0=(l%b).toString(b)+A0,!u&&!J0)break}if(k)A0="-"+A0;return A0}function y(b,m,W0){b[m+Q]=W0&255,W0=W0>>8,b[m+U]=W0&255,W0=W0>>8,b[m+V]=W0&255,W0=W0>>8,b[m+Z]=W0&255}function p(b,m){return b[m+Z]*Fl+(b[m+V]<<16)+(b[m+U]<<8)+b[m+Q]}}function Sl(W){var Y=this.buffer,G=this.offset;if(BX=null,W!==!1&&$l(Y))return Y.length===8?Y:Y.slice(G,G+8);return D$(Y,G)}function xl(W){var Y=this.buffer,G=this.offset;if(BX=LX,W!==!1&&LX.isBuffer(Y))return Y.length===8?Y:Y.slice(G,G+8);return LX.from(K$.call(this,W))}function K$(W){var Y=this.buffer,G=this.offset,X=Y.buffer;if(BX=PX,W!==!1&&!Y.offset&&X instanceof RN)return X.byteLength===8?X:X.slice(G,G+8);var J=new PX(8);return oj(J,0,Y,G),J.buffer}function j$(W,Y){var G=W&&W.length;return Y|=0,G&&Y+8<=G&&typeof W[Y]!=="string"}function oj(W,Y,G,X){Y|=0,X|=0;for(var J=0;J<8;J++)W[Y++]=G[X++]&255}function D$(W,Y){return Array.prototype.slice.call(W,Y,Y+8)}function kl(W,Y,G){var X=Y+8;while(X>Y)W[--X]=G&255,G/=256}function _l(W,Y,G){var X=Y+8;G++;while(X>Y)W[--X]=-G&255^255,G/=256}function yl(W,Y,G){var X=Y+8;while(Y<X)W[Y++]=G&255,G/=256}function vl(W,Y,G){var X=Y+8;G++;while(Y<X)W[Y++]=-G&255^255,G/=256}function gl(W){return!!W&&Object.prototype.toString.call(W)=="[object Array]"}var sV=y1(rj(),1);import{createHash as yn}from"crypto";import{setTimeout as vn}from"timers/promises";import{createHash as pn}from"crypto";import{isIPv4 as $F}from"net";import{randomBytes as ln}from"crypto";import{isIPv4 as FF}from"net";var bN=y1(R$(),1),B2=y1(u$(),1),$2=y1(rj(),1);import*as yO from"timers/promises";import{randomUUID as on}from"crypto";import*as E2 from"os";import{EventEmitter as Ji}from"events";import{randomUUID as wi}from"crypto";import{setTimeout as zO}from"timers/promises";import{createHash as ji}from"crypto";import{performance as FN}from"perf_hooks";import{randomUUID as Oi}from"crypto";import{randomUUID as m2}from"crypto";import{setTimeout as bi}from"timers/promises";import{randomBytes as pi}from"crypto";import{isIPv4 as li}from"net";var tV=y1(gI(),1);import{randomUUID as di}from"crypto";import{setTimeout as oi}from"timers/promises";import{randomUUID as si}from"crypto";import{randomUUID as Gr}from"crypto";import{createHmac as rF,randomBytes as Xr}from"crypto";import{randomBytes as US}from"crypto";import{randomUUID as QS}from"crypto";import{setTimeout as HS}from"timers/promises";import{randomUUID as xr}from"crypto";function zS(){return s1.Unpack("!H",IS(2))[0]}function CO(){return s1.Unpack("!L",IS(4))[0]}var nN=class{constructor(W){this.bitLength=W}value=0;set(W,Y,G){return G&=(1<<W)-1,this.value|=G<<this.bitLength-W-Y,this}get buffer(){let W=Math.ceil(this.bitLength/8),Y=Buffer.alloc(W);return Y.writeUIntBE(this.value,0,W),Y}},wS=class{constructor(W){if(this.bitLength=W,W>32)throw Error()}_value=0n;offset=0n;set(W,Y=1){let G=BigInt(W),X=BigInt(Y);return G&=(1n<<X)-1n,this._value|=G<<BigInt(this.bitLength)-X-this.offset,this.offset+=X,this}get value(){return Number(this._value)}get buffer(){let W=Math.ceil(this.bitLength/8),Y=Buffer.alloc(W);return Y.writeUIntBE(this.value,0,W),Y}};function u8(W,Y,G=1){let X=W.toString(2).split("");X=[...Array(8-X.length).fill("0"),...X];let J=X.slice(Y,Y+G).join("");return Number.parseInt(J,2)}function E8(W,Y){return _N(W)(Y)}function _N(W,Y){let G=W.reduce((J,Z)=>J+Z,0),X=Y?Buffer.alloc(G):void 0;return(J)=>{let Z=X||Buffer.alloc(G),V=0;return J.forEach((U,Q)=>{let H=W[Q];if(H===8)Z.writeBigUInt64BE(U,V);else Z.writeUIntBE(U,V,H);V+=H}),Z}}function s9(W,Y){let G=0;return Y.map((X)=>{let J;if(X===8)J=W.readBigUInt64BE(G);else J=W.readUIntBE(G,X);return G+=X,J})}var pV=class{constructor(W){this.uint8Array=W}position=0;bitsPending=0;writeBits(W,Y){if(W==0)return this;Y&=4294967295>>>32-W;let G;if(this.bitsPending>0)if(this.bitsPending>W)this.uint8Array[this.position-1]|=Y<<this.bitsPending-W,G=W,this.bitsPending-=W;else if(this.bitsPending==W)this.uint8Array[this.position-1]|=Y,G=W,this.bitsPending=0;else this.uint8Array[this.position-1]|=Y>>W-this.bitsPending,G=this.bitsPending,this.bitsPending=0;else G=Math.min(8,W),this.bitsPending=8-G,this.uint8Array[this.position++]=Y>>W-G<<this.bitsPending;if(W-=G,W>0)this.writeBits(W,Y);return this}readBits(W){return this._readBits(W)}_readBits(W,Y){if(typeof Y>"u")Y=0;if(W==0)return Y;let G,X;if(this.bitsPending>0){let J=this.uint8Array[this.position-1]&255>>8-this.bitsPending;X=Math.min(this.bitsPending,W),this.bitsPending-=X,G=J>>this.bitsPending}else X=Math.min(8,W),this.bitsPending=8-X,G=this.uint8Array[this.position++]>>this.bitsPending;return W-=X,Y=Y<<X|G,W>0?this._readBits(W,Y):Y}seekTo(W){if(this.position=W/8|0,this.bitsPending=W%8,this.bitsPending>0)this.bitsPending=8-this.bitsPending,this.position++}},Ld=3988292384,Bd=2197175160;function jS(W){return typeof W!=="string"}function OS(W){let Y=Array(256),G=0;for(let X=0;X<256;++X)G=X,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,Y[X]=G;return new Int32Array(Y)}function KS(W){let Y=new Int32Array(4096),G=0,X=0,J=0;for(J=0;J<256;++J)Y[J]=W[J];for(J=0;J<256;++J){X=W[J];for(G=256+J;G<4096;G+=256)X=Y[G]=X>>>8^W[X&255]}let Z=[];for(J=1;J<16;++J)Z[J-1]=Y.subarray(J*256,J*256+256);return Z}function DS(W,Y,G){let X=Y^-1,J=0,Z=W.length,V=0,U=0;while(J<Z)if(V=W.charCodeAt(J++),V<128)X=X>>>8^G[(X^V)&255];else if(V<2048)X=X>>>8^G[(X^(192|V>>6&31))&255],X=X>>>8^G[(X^(128|V&63))&255];else if(V>=55296&&V<57344)V=(V&1023)+64,U=W.charCodeAt(J++)&1023,X=X>>>8^G[(X^(240|V>>8&7))&255],X=X>>>8^G[(X^(128|V>>2&63))&255],X=X>>>8^G[(X^(128|U>>6&15|(V&3)<<4))&255],X=X>>>8^G[(X^(128|U&63))&255];else X=X>>>8^G[(X^(224|V>>12&15))&255],X=X>>>8^G[(X^(128|V>>6&63))&255],X=X>>>8^G[(X^(128|V&63))&255];return~X>>>0}function CS(W,Y,G,X){let[J,Z,V,U,Q,H,N,A,q,z,w,D,T,x,g]=X,f=Y^-1,y=0,p=W.length-15;while(y<p)f=g[W[y++]^f&255]^x[W[y++]^f>>>8&255]^T[W[y++]^f>>>16&255]^D[W[y++]^f>>>24]^w[W[y++]]^z[W[y++]]^q[W[y++]]^A[W[y++]]^N[W[y++]]^H[W[y++]]^Q[W[y++]]^U[W[y++]]^V[W[y++]]^Z[W[y++]]^J[W[y++]]^G[W[y++]];for(p+=15;y<p;)f=f>>>8^G[(f^W[y++])&255];return~f>>>0}var TO=OS(Ld),Ed=KS(TO),RO=OS(Bd),$d=KS(RO);function Fd(W,Y=0){if(jS(W))return CS(W,Y,TO,Ed);return DS(W,Y,TO)}function TS(W,Y=0){if(jS(W))return CS(W,Y,RO,$d);return DS(W,Y,RO)}function Sd(W,Y){return W+Y&255}function T9(W,Y){return W+Y&65535}function vX(W,Y){return Number(BigInt(W)+BigInt(Y)&0xffffffffn)}function xd(W){return W&16777215}function RS(W,Y){return W<Y&&Y-W>32768||W>Y&&W-Y<32768}function f4(W,Y){return W<Y&&Y-W>2147483648||W>Y&&W-Y<2147483648}function mV(W,Y){return W===Y||f4(W,Y)}var lV=(W)=>Number.parseInt(W,10);var MS=(W,Y)=>Y?Y[W]:void 0;async function _d(W,Y,G="udp4",X){let J;for(let Z=W;Z<=Y;Z++){let V=kd(G);if(setImmediate(()=>V.bind({port:Z,address:MS(G,X)})),await new Promise((Q)=>{V.once("error",(H)=>Q(H)),V.once("listening",()=>Q())})){await new Promise((Q)=>V.close(()=>Q()));continue}if(J=V.address()?.port,await new Promise((Q)=>V.close(()=>Q())),W<=J&&J<=Y)break}if(!J)throw Error("port not found");return J}function iN(W){if(W==="IPv4")return 4;if(W==="IPv6")return 6;return W}var M1=PS.default.debug,p0=class{event={stack:[],promiseStack:[],eventId:0};ended=!1;onended;onerror=(W)=>{};execute=(...W)=>{if(this.ended)return;for(let Y of this.event.stack)Y.execute(...W);(async()=>{for(let Y of this.event.promiseStack)await Y.execute(...W)})().catch((Y)=>{this.onerror(Y)})};complete=()=>{if(this.ended)return;for(let W of this.event.stack)if(W.complete)W.complete();if(this.allUnsubscribe(),this.ended=!0,this.onended)this.onended(),this.onended=void 0};error=(W)=>{if(this.ended)return;for(let Y of this.event.stack)if(Y.error)Y.error(W);this.allUnsubscribe()};allUnsubscribe=()=>{if(this.ended)throw Error("event completed");this.event={stack:[],promiseStack:[],eventId:0}};subscribe=(W,Y,G)=>{let X=this.event.eventId;this.event.stack.push({execute:W,id:X,complete:Y,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==X&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};pipe(W){this.subscribe((...Y)=>{W.execute(...Y)})}queuingSubscribe=(W,Y,G)=>{if(this.ended)throw Error("event completed");let X=this.event.eventId;this.event.promiseStack.push({execute:W,id:X,complete:Y,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==X&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};once=(W,Y,G)=>{let X=this.subscribe((...J)=>{X.unSubscribe(),W(...J)},Y,G)};watch=(W,Y)=>new Promise((G,X)=>{let J=Y&&setTimeout(()=>{X("Event watch timeout")},Y),{unSubscribe:Z}=this.subscribe((...V)=>{if(W(...V)){if(J)clearTimeout(J);Z(),G(V)}})});asPromise=(W)=>new Promise((Y,G)=>{let X=W&&setTimeout(()=>{G("Event asPromise timeout")},W);this.once((...J)=>{if(X)clearTimeout(X);Y(J)},()=>{if(X)clearTimeout(X);Y([])},(J)=>{if(X)clearTimeout(X);G(J)})});get returnTrigger(){let{execute:W,error:Y,complete:G}=this;return{execute:W,error:Y,complete:G}}get returnListener(){let{subscribe:W,once:Y,asPromise:G}=this;return{subscribe:W,once:Y,asPromise:G}}get length(){return this.event.stack.length}},yd=class{_disposer=[];push(W){this._disposer.push(W)}dispose(){this._disposer.forEach((W)=>W()),this._disposer=[]}},h$=M1("werift-ice:packages/ice/src/transport.ts"),MO=class W{constructor(Y,G={}){this.socketType=Y,this.options=G,this.socket=vd(Y),this.socket.on("message",(X,J)=>{if(iN(J.family)===6)[J.address]=J.address.split("%");this.rinfo=J;try{this.onData(X,[J.address,J.port])}catch(Z){h$("onData error",Z)}})}type="udp";socket;rinfo;onData=()=>{};closed=!1;static async init(Y,G={}){let X=new W(Y,G);return await X.init(),X}async init(){let Y=MS(this.socketType,this.options.interfaceAddresses);if(this.options.port)this.socket.bind({port:this.options.port,address:Y});else if(this.options.portRange){let G=await _d(this.options.portRange[0],this.options.portRange[1],this.socketType,this.options.interfaceAddresses);this.socket.bind({port:G,address:Y})}else this.socket.bind({address:Y});await new Promise((G)=>this.socket.once("listening",G))}send=async(Y,G)=>{if(G&&!LS.isIP(G[0]))return new Promise((X,J)=>{this.socket.send(Y,G[1],G[0],(Z)=>{if(Z)h$("send error",G,Y),J(Z);else X()})});else G=G??[this.rinfo?.address,this.rinfo?.port],this.socket.send(Y,G[1],G[0])};get address(){return this.socket.address()}get host(){return this.socket.address().address}get port(){return this.socket.address().port}close=()=>new Promise((Y)=>{this.closed=!0,this.socket.once("close",Y);try{this.socket.close()}catch(G){Y()}})},ud=class W{constructor(Y){this.addr=Y,this.connect()}type="tcp";connecting;client;onData=()=>{};closed=!1;connect(){if(this.closed)return;if(this.client)this.client.destroy();this.connecting=new Promise((Y,G)=>{try{this.client=gd({port:this.addr[1],host:this.addr[0]},Y)}catch(X){G(X)}}),this.client.on("data",(Y)=>{let G=[this.client.remoteAddress,this.client.remotePort];this.onData(Y,G)}),this.client.on("end",()=>{this.connect()}),this.client.on("error",(Y)=>{console.log("error",Y)})}async init(){await this.connecting}static async init(Y){let G=new W(Y);return await G.init(),G}get address(){return{}}send=async(Y,G)=>{await this.connecting,this.client.write(Y,(X)=>{if(X)console.log("err",X)})};close=async()=>{this.closed=!0,this.client.destroy()}},l4={rsa_1:1,ecdsa_3:3},rN={sha256_4:4},PO={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195:49195,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199:49199},fd=Object.values(PO),a6={x25519_29:29,secp256r1_23:23},BS=Object.values(a6),ES={named_curve_3:3},b$={rsa_pkcs1_sha256:1025,ecdsa_secp256r1_sha256:1027},cd=[1,64],$S=[{hash:rN.sha256_4,signature:l4.rsa_1},{hash:rN.sha256_4,signature:l4.ecdsa_3}],dd=()=>{let W=DN.utils.randomPrivateKey(),Y=DN.getPublicKey(W,!1),G=Buffer.from(W),X=Buffer.from(Y);return{privateKey:G,publicKey:X}},od=({publicKey:W,privateKey:Y})=>{let G=DN.getSharedSecret(Y,W);return Buffer.from(G).subarray(1)};function xS(W,Y,G){switch(G){case a6.secp256r1_23:return od({publicKey:W,privateKey:Y});case a6.x25519_29:return Buffer.from(SS.default.scalarMult(Y,W));default:throw Error()}}function m$(W,Y,G){let X=ld(W,Y);return X.update(G),X.digest()}function WU(W,Y,G,X="sha256"){let J=G,Z=[],V=Y;do{V=m$(X,W,V);let U=m$(X,W,Buffer.concat([V,Y]));Z.push(U),G-=U.length}while(G>0);return Buffer.concat(Z,J)}function kS(W,Y,G){let X=Buffer.concat([Buffer.from("master secret"),Y,G]);return WU(W,X,48)}function _S(W,Y){let G=yS("sha256",Y),X="extended master secret";return WU(W,Buffer.concat([Buffer.from("extended master secret"),G]),48)}function nd(W,Y,G,X,J,Z){let V=Z?X:J,U=Z?J:X,Q=Buffer.concat([Buffer.from(W),V,U]);return WU(G,Q,Y)}function yS(W,Y){return pd(W).update(Y).digest()}function vS(W,Y,G,X=12){let J=yS("sha256",Y);return WU(W,Buffer.concat([Buffer.from(G),J]),X)}function id(W,Y){return vS(W,Y,"client finished")}function rd(W,Y){return vS(W,Y,"server finished")}function ad(W,Y,G,X,J,Z,V="sha256"){let U=X*2+J*2,Q=W,H=Buffer.concat([G,Y]),N=WU(Q,Buffer.concat([Buffer.from("key expansion"),H]),U,V),A=FS.createDecode(N),q=A.readBuffer(X),z=A.readBuffer(X),w=A.readBuffer(J),D=A.readBuffer(J),T=Buffer.alloc(Z,0),x=Buffer.alloc(Z,0);return w.copy(T,0),D.copy(x,0),{clientWriteKey:q,serverWriteKey:z,clientNonce:T,serverNonce:x}}var p4={CLIENT:1,SERVER:2},sd=class{id=0;name;hashAlgorithm;verifyDataLength=12;blockAlgorithm;kx;init(...W){throw Error("not implemented")}encrypt(...W){throw Error("not implemented")}decrypt(...W){throw Error("not implemented")}toString(){return this.name}},LO=md;v8.set(LO);var aN=class{constructor(W,Y,G,X){if(this.sessionType=W,this.certPem=Y,this.keyPem=G,Y&&G&&X)this.parseX509(Y,G,X)}localRandom;remoteRandom;cipherSuite;remoteCertificate;remoteKeyPair;localKeyPair;masterSecret;cipher;namedCurve;signatureHashAlgorithm;localCert;localPrivateKey;static createSelfSignedCertificateWithKey=async(W,Y)=>{let G=(()=>{switch(W.signature){case l4.rsa_1:return"RSASSA-PKCS1-v1_5";case l4.ecdsa_3:return"ECDSA"}})(),X=(()=>{switch(W.hash){case rN.sha256_4:return"SHA-256"}})(),J=(()=>{switch(Y){case a6.secp256r1_23:return"P-256";case a6.x25519_29:if(G==="ECDSA")return"P-256";return"X25519";default:{if(G==="ECDSA")return"P-256";if(G==="RSASSA-PKCS1-v1_5")return"X25519"}}})(),Z=(()=>{switch(G){case"ECDSA":return{name:G,hash:X,namedCurve:J};case"RSASSA-PKCS1-v1_5":return{name:G,hash:X,publicExponent:new Uint8Array([1,0,1]),modulusLength:2048}}})(),V=await LO.subtle.generateKey(Z,!0,["sign","verify"]),Q=(await zj.createSelfSigned({serialNumber:bd(8).toString("hex"),name:"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",notBefore:new Date,notAfter:new Date(Date.now()+315360000000),signingAlgorithm:Z,keys:V})).toString("pem"),H=K9.encode(await LO.subtle.exportKey("pkcs8",V.privateKey),"private key");return{certPem:Q,keyPem:H,signatureHash:W}};encryptPacket(W){let Y=W.recordLayerHeader,G=Y.protocolVersion.major<<8|Y.protocolVersion.minor,X=this.cipher.encrypt(this.sessionType,W.fragment,{type:Y.contentType,version:G,epoch:Y.epoch,sequenceNumber:Y.sequenceNumber});return W.fragment=X,W.recordLayerHeader.contentLen=X.length,W}decryptPacket(W){let Y=W.recordLayerHeader,G=Y.protocolVersion.major<<8|Y.protocolVersion.minor;return this.cipher.decrypt(this.sessionType,W.fragment,{type:Y.contentType,version:G,epoch:Y.epoch,sequenceNumber:Y.sequenceNumber})}verifyData(W){if(this.sessionType===p4.CLIENT)return id(this.masterSecret,W);else return rd(this.masterSecret,W)}signatureData(W,Y){let G=hd(Y).update(W),X=this.localPrivateKey.toPEM().toString();return G.sign(X)}generateKeySignature(W){let Y=this.sessionType===p4.CLIENT?this.localRandom:this.remoteRandom,G=this.sessionType===p4.SERVER?this.localRandom:this.remoteRandom,X=this.valueKeySignature(Y.serialize(),G.serialize(),this.localKeyPair.publicKey,this.namedCurve);return this.localPrivateKey.sign(X,W)}parseX509(W,Y,G){let X=Hq.Certificate.fromPEM(Buffer.from(W)),J=Hq.PrivateKey.fromPEM(Buffer.from(Y));this.localCert=X.raw,this.localPrivateKey=J,this.signatureHashAlgorithm=G}valueKeySignature(W,Y,G,X){let J=Buffer.from(gX.encode({type:ES.named_curve_3,curve:X,len:G.length},{type:gX.types.uint8,curve:gX.types.uint16be,len:gX.types.uint8}).slice());return Buffer.concat([W,Y,J,G])}},sN=class{srtpProfile;static findMatchingSRTPProfile(W,Y){for(let G of Y)if(W.includes(G))return G}},eO=(W)=>"0x"+W.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter((Y)=>Y!=null&&Y.length>0).join(",0x"),gS=(W)=>Object.entries({...W}).reduce((Y,[G,X])=>{if(typeof X==="number"||typeof X==="string")Y[G]=X;if(Buffer.isBuffer(X))Y[G]=eO(X);return Y},{}),E5=class W{constructor(Y,G,X,J,Z,V){this.msg_type=Y,this.length=G,this.message_seq=X,this.fragment_offset=J,this.fragment_length=Z,this.fragment=V}static spec={msg_type:G7.types.uint8,length:G7.types.uint24be,message_seq:G7.types.uint16be,fragment_offset:G7.types.uint24be,fragment_length:G7.types.uint24be,fragment:G7.types.buffer((Y)=>Y.current.fragment_length)};get summary(){return gS(this)}static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(G7.decode(Y,W.spec)))}serialize(){let Y=G7.encode(this,W.spec).slice();return Buffer.from(Y)}chunk(Y){let G=0,X=this.fragment.length;if(X===0)return[new W(this.msg_type,X,this.message_seq,G,0,this.fragment)];let J=[];if(!Y)Y=1240;while(G<X){let Z=Math.min(Y,X-G),V=Buffer.from(this.fragment.slice(G,G+Z));if(V.length<=0)throw Error("Zero or less bytes processed while fragmenting handshake message.");J.push(new W(this.msg_type,X,this.message_seq,G,V.length,V)),G+=V.length}return J}static assemble(Y){if(!Y?.length)throw Error("cannot reassemble handshake from empty array");Y=Y.sort((X,J)=>X.fragment_offset-J.fragment_offset);let G=Buffer.alloc(Y[0].length);for(let X of Y)X.fragment.copy(G,X.fragment_offset);return new W(Y[0].msg_type,Y[0].length,Y[0].message_seq,0,G.length,G)}static findAllFragments(Y,G){let X=Y.find((J)=>J.msg_type===G);if(!X)return[];if(!Y?.length)return[];return Y.filter((J)=>{return J.msg_type===X.msg_type&&J.message_seq===X.message_seq&&J.length===X.length})}},{uint16be:tN,uint24be:td,buffer:hS,array:ed,uint8:nV,string:Wo}=uS.types,Yo={type:tN,data:hS(tN)},BO=ed(Yo,tN,"bytes"),Go=hS(td),Xo=nV,Jo=Wo(tN),Zo={hash:nV,signature:nV},WK={major:nV,minor:nV},TY=class W{constructor(Y=Math.floor(Date.now()/1000),G=Vo(28)){this.gmt_unix_time=Y,this.random_bytes=G}static spec={gmt_unix_time:CY.types.uint32be,random_bytes:CY.types.buffer(28)};static deSerialize(Y){return new W(...Object.values(CY.decode(Y,W.spec)))}static from(Y){return new W(...Object.values(Y))}serialize(){let Y=CY.encode(this,W.spec).slice();return Buffer.from(Y)}},bS=class W{constructor(Y,G,X,J,Z,V,U){this.clientVersion=Y,this.random=G,this.sessionId=X,this.cookie=J,this.cipherSuites=Z,this.compressionMethods=V,this.extensions=U}msgType=1;messageSeq=0;static spec={clientVersion:{major:Z9.types.uint8,minor:Z9.types.uint8},random:TY.spec,sessionId:Z9.types.buffer(Z9.types.uint8),cookie:Z9.types.buffer(Z9.types.uint8),cipherSuites:Z9.types.array(Z9.types.uint16be,Z9.types.uint16be,"bytes"),compressionMethods:Z9.types.array(Z9.types.uint8,Z9.types.uint8,"bytes"),extensions:BO};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(Z9.decode(Y,W.spec)))}serialize(){let Y=Z9.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},Qo=class W{constructor(Y,G,X,J,Z){this.epoch=Y,this.sequenceNumber=G,this.contentType=X,this.protocolVersion=J,this.contentLen=Z}static spec={epoch:c4.types.uint16be,sequenceNumber:c4.types.uint48be,contentType:c4.types.uint8,protocolVersion:WK,contentLen:c4.types.uint16be};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(c4.decode(Y,W.spec)))}serialize(){let Y=c4.encode(this,W.spec).slice();return Buffer.from(Y)}},mS=class W{constructor(Y,G){this.recordLayerHeader=Y,this.fragment=G}get summary(){return{header:this.recordLayerHeader,fragment:eO(this.fragment)}}static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){if(Y.length<13)throw Error("Invalid DTLS record: buffer is too short");let G=Y.readUInt8(0),X=Y.readUInt8(1),J=Y.readUInt8(2),Z=Y.readUInt16BE(3),V=Y.slice(5,11).readUIntBE(0,6),U=Y.readUInt16BE(11);if(Y.length<13+U)throw Error("Invalid DTLS record: fragment length exceeds buffer");let Q=Y.slice(13,13+U);return new W({contentType:G,protocolVersion:{major:X,minor:J},epoch:Z,sequenceNumber:V,contentLen:U},Q)}serialize(){let Y=this.fragment.length,G=13+Y,X=Buffer.alloc(G);return X.writeUInt8(this.recordLayerHeader.contentType,0),X.writeUInt8(this.recordLayerHeader.protocolVersion.major,1),X.writeUInt8(this.recordLayerHeader.protocolVersion.minor,2),X.writeUInt16BE(this.recordLayerHeader.epoch,3),X.writeUIntBE(this.recordLayerHeader.sequenceNumber,5,6),X.writeUInt16BE(Y,11),this.fragment.copy(X,13),X}computeMACHeader(){return new Qo(this.recordLayerHeader.epoch,this.recordLayerHeader.sequenceNumber,this.recordLayerHeader.contentType,this.recordLayerHeader.protocolVersion,this.recordLayerHeader.contentLen).serialize()}},fS=(W)=>(Y)=>{return W.lastFlight=Y,Y.flatMap((G)=>{return G.messageSeq=W.sequenceNumber++,G.toFragment().chunk()})},YU=(W)=>(Y,G)=>{return Y.map((X)=>{return new mS({contentType:X.type,protocolVersion:W.version,epoch:W.epoch,sequenceNumber:G,contentLen:X.fragment.length},X.fragment)})},EO=((W)=>{return W[W.CloseNotify=0]="CloseNotify",W[W.UnexpectedMessage=10]="UnexpectedMessage",W[W.BadRecordMac=20]="BadRecordMac",W[W.DecryptionFailed=21]="DecryptionFailed",W[W.RecordOverflow=22]="RecordOverflow",W[W.DecompressionFailure=30]="DecompressionFailure",W[W.HandshakeFailure=40]="HandshakeFailure",W[W.NoCertificate=41]="NoCertificate",W[W.BadCertificate=42]="BadCertificate",W[W.UnsupportedCertificate=43]="UnsupportedCertificate",W[W.CertificateRevoked=44]="CertificateRevoked",W[W.CertificateExpired=45]="CertificateExpired",W[W.CertificateUnknown=46]="CertificateUnknown",W[W.IllegalParameter=47]="IllegalParameter",W[W.UnknownCa=48]="UnknownCa",W[W.AccessDenied=49]="AccessDenied",W[W.DecodeError=50]="DecodeError",W[W.DecryptError=51]="DecryptError",W[W.ExportRestriction=60]="ExportRestriction",W[W.ProtocolVersion=70]="ProtocolVersion",W[W.InsufficientSecurity=71]="InsufficientSecurity",W[W.InternalError=80]="InternalError",W[W.UserCanceled=90]="UserCanceled",W[W.NoRenegotiation=100]="NoRenegotiation",W[W.UnsupportedExtension=110]="UnsupportedExtension",W})(EO||{}),Ho=M1("werift-dtls : packages/dtls/src/flight/flight.ts : warn"),JO=M1("werift-dtls : packages/dtls/src/flight/flight.ts : err"),GU=class W{constructor(Y,G,X,J){this.transport=Y,this.dtls=G,this.flight=X,this.nextFlight=J}state="PREPARING";static RetransmitCount=10;createPacket(Y){let G=fS(this.dtls)(Y);return this.dtls.bufferHandshakeCache(G,!0,this.flight),YU(this.dtls)(G.map((J)=>({type:22,fragment:J.serialize()})),++this.dtls.recordSequenceNumber)}async transmit(Y){let G=0;for(;G<=W.RetransmitCount;G++){if(this.setState("SENDING"),this.send(Y).catch((X)=>{JO("fail to send",JO)}),this.setState("WAITING"),this.nextFlight===void 0){this.setState("FINISHED");break}if(await Uo(1000*((G+1)/2)),this.dtls.flight>=this.nextFlight){this.setState("FINISHED");break}else Ho(this.dtls.sessionId,"retransmit",G,this.dtls.flight)}if(G>W.RetransmitCount)throw JO(this.dtls.sessionId,"retransmit failed",G),Error(`over retransmitCount : ${this.flight} ${this.nextFlight}`)}send=(Y)=>Promise.all(Y.map((G)=>this.transport.send(G)));setState(Y){this.state=Y}},No=class extends GU{constructor(W,Y,G){super(W,Y,1,3);this.cipher=G}async exec(W){if(this.dtls.flight===1)throw Error();this.dtls.flight=1;let Y=new bS({major:254,minor:253},new TY,Buffer.from([]),Buffer.from([]),fd,[0],W);this.dtls.version=Y.clientVersion,this.cipher.localRandom=TY.from(Y.random);let G=this.createPacket([Y]),X=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([X])}},qo=M1("werift-dtls : packages/dtls/src/flight/client/flight3.ts : log"),Ao=class extends GU{constructor(W,Y){super(W,Y,3,5)}async exec(W){if(this.dtls.flight===3)throw Error();this.dtls.flight=3,this.dtls.handshakeCache=[];let[Y]=this.dtls.lastFlight;qo("dtls version",Y.clientVersion),Y.cookie=W.cookie,this.dtls.cookie=W.cookie;let G=this.createPacket([Y]),X=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([X])}},Nq={NULL:0,ECDHE:1},XU={NULL:0,RSA:1,ECDSA:2,PSK:3},JU={NULL:0,RSA:1,ECDHE_RSA:2,ECDHE_ECDSA:3,PSK:4,ECDHE_PSK:5},ZU=class{id=0;name;signType;keyType;toString(){return this.name}};function Io(){let W=new ZU;return W.id=JU.RSA,W.name="RSA",W.keyType=XU.RSA,W}function zo(){let W=new ZU;return W.id=JU.ECDHE_RSA,W.name="ECDHE_RSA",W.signType=Nq.ECDHE,W.keyType=XU.RSA,W}function wo(){let W=new ZU;return W.id=JU.ECDHE_ECDSA,W.name="ECDHE_ECDSA",W.signType=Nq.ECDHE,W.keyType=XU.ECDSA,W}function jo(){let W=new ZU;return W.id=JU.PSK,W.name="PSK",W.signType=Nq.NULL,W.keyType=XU.PSK,W}function Oo(){let W=new ZU;return W.id=JU.ECDHE_PSK,W.name="ECDHE_PSK",W.signType=Nq.ECDHE,W.keyType=XU.PSK,W}var Co=M1("werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err"),To=class extends sd{keyLength=0;nonceLength=0;ivLength=0;authTagLength=0;nonceImplicitLength=0;nonceExplicitLength=0;clientWriteKey;serverWriteKey;clientNonce;serverNonce;constructor(){super()}get summary(){return gS(this)}init(W,Y,G){let X=ad(W,G,Y,this.keyLength,this.ivLength,this.nonceLength,this.hashAlgorithm);this.clientWriteKey=X.clientWriteKey,this.serverWriteKey=X.serverWriteKey,this.clientNonce=X.clientNonce,this.serverNonce=X.serverNonce}encrypt(W,Y,G){let X=W===p4.CLIENT,J=X?this.clientNonce:this.serverNonce,Z=X?this.clientWriteKey:this.serverWriteKey;if(!J||!Z)throw Error();J.writeUInt16BE(G.epoch,this.nonceImplicitLength),J.writeUIntBE(G.sequenceNumber,this.nonceImplicitLength+2,6);let V=J.slice(this.nonceImplicitLength),U=this.encodeAdditionalBuffer(G,Y.length),Q=Ko(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});Q.setAAD(U,{plaintextLength:Y.length});let H=Q.update(Y),N=Q.final(),A=Q.getAuthTag();return Buffer.concat([V,H,N,A])}encodeAdditionalBuffer(W,Y){let G=Buffer.alloc(13);return G.writeUInt16BE(W.epoch,0),G.writeUintBE(W.sequenceNumber,2,6),G.writeUInt8(W.type,8),G.writeUInt16BE(W.version,9),G.writeUInt16BE(Y,11),G}decrypt(W,Y,G){let X=W===p4.CLIENT,J=X?this.serverNonce:this.clientNonce,Z=X?this.serverWriteKey:this.clientWriteKey;if(!J||!Z)throw Error();Y.subarray(0,this.nonceExplicitLength).copy(J,this.nonceImplicitLength);let U=Y.subarray(this.nonceExplicitLength,Y.length-this.authTagLength),Q=Y.subarray(Y.length-this.authTagLength),H=this.encodeAdditionalBuffer(G,U.length),N=Do(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});N.setAuthTag(Q),N.setAAD(H,{plaintextLength:U.length});let A=N.update(U);try{let q=N.final();return q.length>0?Buffer.concat([A,q]):A}catch(q){throw Co("decrypt failed",q,W,eO(Y),G,this.summary),q}}},g8={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:49195,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:49196,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:49199,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:49200,TLS_RSA_WITH_AES_128_GCM_SHA256:156,TLS_RSA_WITH_AES_256_GCM_SHA384:157,TLS_PSK_WITH_AES_128_GCM_SHA256:168,TLS_PSK_WITH_AES_256_GCM_SHA384:169,TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:53249,TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:53250,TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256:52396,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:52393,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:52392,TLS_PSK_WITH_CHACHA20_POLY1305_SHA256:52395},kV={K_LEN:16,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},_V={K_LEN:32,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},f$=Io(),c$=zo(),p$=wo(),l$=jo(),d$=Oo();function cS(W){switch(W){case g8.TLS_RSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_RSA_WITH_AES_128_GCM_SHA256,"TLS_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",f$,kV);case g8.TLS_RSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_RSA_WITH_AES_256_GCM_SHA384,"TLS_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",f$,_V,"sha384");case g8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",c$,kV);case g8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",c$,_V,"sha384");case g8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",p$,kV);case g8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",p$,_V,"sha384");case g8.TLS_PSK_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_PSK_WITH_AES_128_GCM_SHA256,"TLS_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",l$,kV,"sha256");case g8.TLS_PSK_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_PSK_WITH_AES_256_GCM_SHA384,"TLS_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",l$,_V,"sha384");case g8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",d$,kV,"sha256");case g8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",d$,_V,"sha384");default:break}return null}function m7(W,Y,G,X,J,Z="sha256"){let V=new To;return V.id=W,V.name=Y,V.blockAlgorithm=G,V.kx=X,V.hashAlgorithm=Z,V.keyLength=J.K_LEN,V.nonceLength=J.N_MAX,V.nonceImplicitLength=4,V.nonceExplicitLength=8,V.ivLength=V.nonceImplicitLength,V.authTagLength=16,V}function lS(W){switch(W){case a6.secp256r1_23:{let{privateKey:Y,publicKey:G}=dd();return{curve:W,privateKey:Y,publicKey:G}}case a6.x25519_29:{let Y=pS.default.box.keyPair();return{curve:W,privateKey:Buffer.from(Y.secretKey.buffer),publicKey:Buffer.from(Y.publicKey.buffer)}}default:throw Error()}}var qq=class{static type=23},Aq=class W{static type=65281;static spec={type:RY.types.uint16be,data:RY.types.uint8};type=W.type;data=0;constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static deSerialize(Y){return new W(RY.decode(Y,W.spec))}serialize(){let Y=RY.encode(this,W.spec).slice();return Buffer.from(Y)}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},uX=class W{static type=14;static spec={type:i6.types.uint16be,data:i6.types.buffer(i6.types.uint16be)};type=W.type;data=Buffer.from([]);profiles=[];mki=Buffer.from([0]);constructor(Y={}){Object.assign(this,Y)}static create(Y,G){return new W({profiles:Y,mki:G})}static deSerialize(Y){let G=new W(i6.decode(Y,W.spec)),X=G.data.readUInt16BE(),J=Array(X/2);for(let Z=0;Z<J.length;Z++)J[Z]=G.data.readUInt16BE(Z*2+2);return G.profiles=J,G.mki=G.data.slice(X+2),G}serialize(){let Y=Buffer.alloc(2);Y.writeUInt16BE(this.profiles.length*2);let G=Buffer.concat([Y,...this.profiles.map((J)=>{let Z=Buffer.alloc(2);return Z.writeUInt16BE(J),Z}),this.mki]);this.data=G;let X=i6.encode(this,W.spec).slice();return Buffer.from(X)}static fromData(Y){let G=Buffer.alloc(4);return G.writeUInt16BE(W.type),G.writeUInt16BE(Y.length,2),W.deSerialize(Buffer.concat([G,Y]))}get extension(){return{type:this.type,data:this.serialize().slice(4)}}},eN=class W{constructor(Y){this.certificateList=Y}msgType=11;messageSeq;static spec={certificateList:MY.types.array(Go,MY.types.uint24be,"bytes")};static createEmpty(){return new W(void 0)}static deSerialize(Y){return new W(...Object.values(MY.decode(Y,W.spec)))}serialize(){let Y=MY.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},dS=class W{constructor(Y=1){this.type=Y}static spec={type:cX.types.uint8};static createEmpty(){return new W}static deSerialize(Y){return new W(...Object.values(cX.decode(Y,W.spec)))}serialize(){let Y=cX.encode(this,W.spec).slice();return Buffer.from(Y)}},oS=class W{constructor(Y,G){this.algorithm=Y,this.signature=G}msgType=15;messageSeq;static spec={algorithm:r6.types.uint16be,signature:r6.types.buffer(r6.types.uint16be)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){let G=r6.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){let Y=r6.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},nS=class W{constructor(Y){this.publicKey=Y}msgType=16;messageSeq;static spec={publicKey:PY.types.buffer(PY.types.uint8)};static createEmpty(){return new W(void 0)}static deSerialize(Y){let G=PY.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){let Y=PY.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},$O=class W{constructor(Y){this.verifyData=Y}msgType=20;messageSeq;static createEmpty(){return new W(void 0)}static deSerialize(Y){return new W(Y)}serialize(){return this.verifyData}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},iS=class W{constructor(Y,G,X){this.certificateTypes=Y,this.signatures=G,this.authorities=X}msgType=13;messageSeq;static spec={certificateTypes:X7.types.array(Xo,X7.types.uint8,"bytes"),signatures:X7.types.array(Zo,X7.types.uint16be,"bytes"),authorities:X7.types.array(Jo,X7.types.uint16be,"bytes")};static createEmpty(){return new W(void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(X7.decode(Y,W.spec)))}serialize(){let Y=X7.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},rS=class W{constructor(Y,G,X,J,Z,V){this.serverVersion=Y,this.random=G,this.sessionId=X,this.cipherSuite=J,this.compressionMethod=Z,this.extensions=V}msgType=2;messageSeq;static spec={serverVersion:WK,random:TY.spec,sessionId:J7.types.buffer(J7.types.uint8),cipherSuite:J7.types.uint16be,compressionMethod:J7.types.uint8};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){let G=J7.decode(Y,W.spec),X=new W(...Object.values(G));if(X.serialize().length<Y.length)return new W(...Object.values(J7.decode(Y,{...W.spec,extensions:BO})));return X}serialize(){let Y=this.extensions===void 0?J7.encode(this,W.spec).slice():J7.encode(this,{...W.spec,extensions:BO}).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},aS=class W{msgType=14;messageSeq;static spec={};static createEmpty(){return new W}static deSerialize(Y){return new W(...Object.values(Iq.decode(Y,W.spec)))}serialize(){let Y=Iq.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}};function Ro(W,Y){return Buffer.from(sS.encode(W,Y).slice())}var tS=class W{constructor(Y,G,X,J,Z,V,U,Q){this.ellipticCurveType=Y,this.namedCurve=G,this.publicKeyLength=X,this.publicKey=J,this.hashAlgorithm=Z,this.signatureAlgorithm=V,this.signatureLength=U,this.signature=Q}msgType=12;messageSeq;static spec={ellipticCurveType:Y7.types.uint8,namedCurve:Y7.types.uint16be,publicKeyLength:Y7.types.uint8,publicKey:Y7.types.buffer((Y)=>Y.current.publicKeyLength),hashAlgorithm:Y7.types.uint8,signatureAlgorithm:Y7.types.uint8,signatureLength:Y7.types.uint16be,signature:Y7.types.buffer((Y)=>Y.current.signatureLength)};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){let G=Y7.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){return Ro(this,W.spec)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},zq=1,VU=7;var Mo=(W)=>{switch(W){case zq:case VU:return 16}},Po=(W)=>{switch(W){case zq:return 14;case VU:return 12}},kq0=M1("werift-rtp : packages/rtp/src/codec/av1.ts");var Bo={0:"Reserved",1:"OBU_SEQUENCE_HEADER",2:"OBU_TEMPORAL_DELIMITER",3:"OBU_FRAME_HEADER",4:"OBU_TILE_GROUP",5:"OBU_METADATA",6:"OBU_FRAME",7:"OBU_REDUNDANT_FRAME_HEADER",8:"OBU_TILE_LIST",15:"OBU_PADDING"},_q0=Object.entries(Bo).reduce((W,[Y,G])=>{return W[G]=Number(Y),W},{});var yq0=Buffer.from([0,0,0,1]);function o$(W,Y){let G=Buffer.alloc(Y);return W.copy(G),G}function Wq(W){return Number.parseInt(W.toString(),10)}function Eo(W){let Y=W[0];return Y>127&&Y<192}var FO=4,e6=class W{version=2;padding=!1;count=0;type=0;length=0;constructor(Y={}){Object.assign(this,Y)}static serialize(Y,G,X,J){let V=new W({type:Y,count:G,version:2,length:J}).serialize();return Buffer.concat([V,X])}serialize(){let Y=new nN(8);if(Y.set(2,0,this.version),this.padding)Y.set(1,2,1);return Y.set(5,3,this.count),E8([1,1,2],[Y.value,this.type,this.length])}static deSerialize(Y){let[G,X,J]=s9(Y,[1,1,2]),Z=u8(G,0,2),V=u8(G,2,1)>0,U=u8(G,3,5);return new W({version:Z,padding:V,count:U,type:X,length:J})}},n$=class W{static count=4;count=W.count;senderSsrc;mediaSsrc;fir=[];constructor(Y={}){Object.assign(this,Y)}get length(){return Math.floor(this.serialize().length/4-1)}static deSerialize(Y){let[G,X]=s9(Y,[4,4]),J=[];for(let Z=8;Z<Y.length;Z+=8)J.push({ssrc:Y.readUInt32BE(Z),sequenceNumber:Y[Z+4]});return new W({senderSsrc:G,mediaSsrc:X,fir:J})}serialize(){let Y=E8([4,4],[this.senderSsrc,this.mediaSsrc]),G=Buffer.alloc(this.fir.length*8);return this.fir.forEach(({ssrc:X,sequenceNumber:J},Z)=>{G.writeUInt32BE(X,Z*8),G[Z*8+4]=J}),Buffer.concat([Y,G])}},Yq=class W{static count=1;count=W.count;length=2;senderSsrc;mediaSsrc;constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let[G,X]=s9(Y,[4,4]);return new W({senderSsrc:G,mediaSsrc:X})}serialize(){return E8([4,4],[this.senderSsrc,this.mediaSsrc])}},Gq=class W{static count=15;length;count=W.count;senderSsrc;mediaSsrc;uniqueID="REMB";ssrcNum=0;brExp;brMantissa;bitrate;ssrcFeedbacks=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let[G,X,J,Z,V]=s9(Y,[4,4,4,1,1]),U=u8(V,0,6),Q=(u8(V,6,2)<<16)+(Y[14]<<8)+Y[15],H=U>46?18446744073709551615n:BigInt(Q)<<BigInt(U),N=[];for(let A=16;A<Y.length;A+=4){let q=Y.slice(A).readUIntBE(0,4);N.push(q)}return new W({senderSsrc:G,mediaSsrc:X,uniqueID:E8([4],[J]).toString(),ssrcNum:Z,brExp:U,brMantissa:Q,ssrcFeedbacks:N,bitrate:H})}serialize(){let Y=Buffer.concat([E8([4,4],[this.senderSsrc,this.mediaSsrc]),Buffer.from(this.uniqueID),E8([1],[this.ssrcNum])]),G=new nN(24);G.set(6,0,this.brExp).set(18,6,this.brMantissa);let X=Buffer.concat(this.ssrcFeedbacks.map((Z)=>E8([4],[Z]))),J=Buffer.concat([Y,E8([3],[G.value]),X]);return this.length=J.length/4,J}},$o=M1("werift-rtp: /rtcp/psfb/index"),iV=class W{static type=206;type=W.type;feedback;constructor(Y={}){Object.assign(this,Y)}serialize(){let Y=this.feedback.serialize();return e6.serialize(this.type,this.feedback.count,Y,this.feedback.length)}static deSerialize(Y,G){let X;switch(G.count){case n$.count:X=n$.deSerialize(Y);break;case Yq.count:X=Yq.deSerialize(Y);break;case Gq.count:X=Gq.deSerialize(Y);break;default:$o("unknown psfb packet",G.count);break}return new W({feedback:X})}},rV=class W{ssrc=0;reports=[];static type=201;type=W.type;constructor(Y={}){Object.assign(this,Y)}serialize(){let Y=E8([4],[this.ssrc]);return Y=Buffer.concat([Y,...this.reports.map((G)=>G.serialize())]),e6.serialize(W.type,this.reports.length,Y,Math.floor(Y.length/4))}static deSerialize(Y,G){let[X]=s9(Y,[4]),J=4,Z=[];for(let V=0;V<G;V++)Z.push(YK.deSerialize(Y.slice(J,J+24))),J+=24;return new W({ssrc:X,reports:Z})}},YK=class W{ssrc;fractionLost;packetsLost;highestSequence;jitter;lsr;dlsr;constructor(Y={}){Object.assign(this,Y)}toJSON(){return{ssrc:this.ssrc,fractionLost:this.fractionLost,packetsLost:this.packetsLost,highestSequence:this.highestSequence,jitter:this.jitter,lsr:this.lsr,dlsr:this.dlsr}}serialize(){return E8([4,1,3,4,4,4,4],[this.ssrc,this.fractionLost,this.packetsLost,this.highestSequence,this.jitter,this.lsr,this.dlsr])}static deSerialize(Y){let[G,X,J,Z,V,U,Q]=s9(Y,[4,1,3,4,4,4,4]);return new W({ssrc:G,fractionLost:X,packetsLost:J,highestSequence:Z,jitter:V,lsr:U,dlsr:Q})}},eS=205,Xq=class W{static count=1;count=W.count;header;senderSsrc;mediaSourceSsrc;lost=[];toJSON(){return{lost:this.lost,senderSsrc:this.senderSsrc,mediaSourceSsrc:this.mediaSourceSsrc}}constructor(Y={}){if(Object.assign(this,Y),!this.header)this.header=new e6({type:eS,count:this.count,version:2})}static deSerialize(Y,G){let[X,J]=s9(Y,[4,4]),Z=[];for(let V=8;V<Y.length;V+=4){let[U,Q]=s9(Y.subarray(V),[2,2]);Z.push(U);for(let H=0;H<16;H++)if(Q>>H&1)Z.push(U+H+1)}return new W({header:G,senderSsrc:X,mediaSourceSsrc:J,lost:Z})}serialize(){let Y=E8([4,4],[this.senderSsrc,this.mediaSourceSsrc]),G=[];if(this.lost.length>0){let J=this.lost[0],Z=0;this.lost.slice(1).forEach((V)=>{let U=V-J-1;if(U>=0&&U<16)Z|=1<<U;else G.push(E8([2,2],[J,Z])),J=V,Z=0}),G.push(E8([2,2],[J,Z]))}let X=Buffer.concat([Y,Buffer.concat(G)]);return this.header.length=X.length/4,Buffer.concat([this.header.serialize(),X])}},Fo=M1("werift/rtp/rtcp/rtpfb/twcc"),Jq=class W{static count=15;count=W.count;length=2;senderSsrc;mediaSourceSsrc;baseSequenceNumber;packetStatusCount;referenceTime;fbPktCount;packetChunks=[];recvDeltas=[];header;constructor(Y={}){if(Object.assign(this,Y),!this.header)this.header=new e6({type:205,count:this.count,version:2})}static deSerialize(Y,G){let[X,J,Z,V,U,Q]=s9(Y,[4,4,2,2,3,1]),H=[],N=[],A=16;for(let z=0;z<V;){let w=u8(Y.slice(A,A+1)[0],0,1),D;switch(w){case 0:{let T=dV.deSerialize(Y.slice(A,A+2));D=T;let x=Math.min(V-z,T.runLength);if(T.packetStatus===1||T.packetStatus===2)for(let g=0;g<x;g++)N.push(new yN({type:T.packetStatus}));z+=x}break;case 1:{let T=So.deSerialize(Y.slice(A,A+2));if(D=T,T.symbolSize===0)T.symbolList.forEach((x)=>{if(x===1)N.push(new yN({type:1}))});if(T.symbolSize===1)T.symbolList.forEach((x)=>{if(x===1||x===2)N.push(new yN({type:x}))});z+=T.symbolList.length}break}if(!D)throw Error();A+=2,H.push(D)}let q=A;return N.forEach((z)=>{if(z.type===1)z.deSerialize(Y.slice(q,q+1)),q++;if(z.type===2)z.deSerialize(Y.slice(q,q+2)),q+=2}),new W({senderSsrc:X,mediaSourceSsrc:J,baseSequenceNumber:Z,packetStatusCount:V,referenceTime:U,fbPktCount:Q,recvDeltas:N,packetChunks:H,header:G})}serialize(){let Y=E8([4,4,2,2,3,1],[this.senderSsrc,this.mediaSourceSsrc,this.baseSequenceNumber,this.packetStatusCount,this.referenceTime,this.fbPktCount]),G=Buffer.concat(this.packetChunks.map((Z)=>Z.serialize())),X=Buffer.concat(this.recvDeltas.map((Z)=>{try{return Z.serialize()}catch(V){Fo(V?.message);return}}).filter((Z)=>Z)),J=Buffer.concat([Y,G,X]);if(this.header.padding&&J.length%4!==0){let Z=4-J.length%4,V=Buffer.alloc(Z);return V[V.length-1]=V.length,this.header.length=Math.floor((J.length+V.length)/4),Buffer.concat([this.header.serialize(),J,V])}return this.header.length=Math.floor(J.length/4),Buffer.concat([this.header.serialize(),J])}get packetResults(){let Y=this.baseSequenceNumber-1,G=this.packetChunks.filter((V)=>V instanceof dV).flatMap((V)=>V.results(Y)),X=0,Z=BigInt(this.referenceTime)*64n;for(let V of G){let U=this.recvDeltas[X];if(!V.received||!U)continue;Z+=BigInt(U.delta)/1000n,V.delta=U.delta,V.receivedAtMs=Number(Z),X++}return G}},dV=class W{type;packetStatus;runLength;constructor(Y={}){Object.assign(this,Y),this.type=0}static deSerialize(Y){let G=u8(Y[0],1,2),X=(u8(Y[0],3,5)<<8)+Y[1];return new W({type:0,packetStatus:G,runLength:X})}serialize(){return new wS(16).set(0).set(this.packetStatus,2).set(this.runLength,13).buffer}results(Y){let G=this.packetStatus===1||this.packetStatus===2,X=[];for(let J=0;J<=this.runLength;++J)X.push(new xo({sequenceNumber:++Y,received:G}));return X}},So=class W{type;symbolSize;symbolList=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let X=u8(Y[0],1,1),J=[];function Z(V,U){for(let Q=0;Q<V;Q++)U(Q)}switch(X){case 0:Z(6,(V)=>J.push(u8(Y[0],2+V,1))),Z(8,(V)=>J.push(u8(Y[1],V,1)));break;case 1:Z(3,(V)=>J.push(u8(Y[0],2+V*2,2))),Z(4,(V)=>J.push(u8(Y[1],V*2,2)));break;default:X=(u8(Y[0],2,6)<<8)+Y[1]}return new W({type:1,symbolSize:X,symbolList:J})}serialize(){let Y=Buffer.alloc(2),G=new wS(16).set(1).set(this.symbolSize),X=this.symbolSize===0?1:2;return this.symbolList.forEach((J)=>{G.set(J,X)}),Y.writeUInt16BE(G.value),Y}},yN=class W{type;delta;constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let G,X;if(Y.length===1)G=1,X=250*Y[0];else if(Y.length===2)G=2,X=250*Y.readInt16BE();if(G===void 0||X===void 0)throw Error();return new W({type:G,delta:X})}deSerialize(Y){let G=W.deSerialize(Y);this.delta=G.delta}parsed=!1;parseDelta(){if(this.delta=Math.floor(this.delta/250),this.delta<0||this.delta>255){if(this.delta>32767)this.delta=32767;if(this.delta<-32768)this.delta=-32768;if(!this.type)this.type=2}else if(!this.type)this.type=1;this.parsed=!0}serialize(){if(!this.parsed)this.parseDelta();if(this.type===1){let Y=Buffer.alloc(1);return Y.writeUInt8(this.delta),Y}else if(this.type===2){let Y=Buffer.alloc(2);return Y.writeInt16BE(this.delta),Y}throw Error("errDeltaExceedLimit "+this.delta+" "+this.type)}};var xo=class{sequenceNumber=0;delta=0;received=!1;receivedAtMs=0;constructor(W){Object.assign(this,W)}},ko=M1("werift-rtp:packages/rtp/rtcp/rtpfb/index"),hX=class W{static type=eS;type=W.type;feedback;header;constructor(Y={}){Object.assign(this,Y)}serialize(){return this.feedback.serialize()}static deSerialize(Y,G){let X;switch(G.count){case Xq.count:X=Xq.deSerialize(Y,G);break;case Jq.count:X=Jq.deSerialize(Y,G);break;default:ko("unknown rtpfb packet",G.count);break}return new W({feedback:X,header:G})}},Zq=class W{static type=202;type=W.type;chunks=[];constructor(Y){Object.assign(this,Y)}get length(){let Y=0;return this.chunks.forEach((G)=>Y+=G.length),Y}serialize(){let Y=Buffer.concat(this.chunks.map((G)=>G.serialize()));while(Y.length%4)Y=Buffer.concat([Y,Buffer.from([0])]);return e6.serialize(this.type,this.chunks.length,Y,Y.length/4)}static deSerialize(Y,G){let X=[];for(let J=0;J<Y.length;){let Z=W2.deSerialize(Y.slice(J));X.push(Z),J+=Z.length}return new W({chunks:X})}},W2=class W{source;items=[];constructor(Y={}){Object.assign(this,Y)}get length(){let Y=4;return this.items.forEach((G)=>Y+=G.length),Y+=1,Y+=i$(Y),Y}serialize(){let Y=Buffer.concat([E8([4],[this.source]),Buffer.concat(this.items.map((X)=>X.serialize()))]);return Buffer.concat([Y,Buffer.alloc(i$(Y.length))])}static deSerialize(Y){let G=Y.readUInt32BE(),X=[];for(let J=4;J<Y.length;){if(Y[J]===0)break;let V=Y2.deSerialize(Y.slice(J));X.push(V),J+=V.length}return new W({source:G,items:X})}},Y2=class W{type;text;constructor(Y){Object.assign(this,Y)}get length(){return 2+Buffer.from(this.text).length}serialize(){let Y=Buffer.from(this.text);return Buffer.concat([E8([1,1],[this.type,Y.length]),Y])}static deSerialize(Y){let G=Y[0],X=Y[1],J=Y.slice(2,2+X).toString();return new W({type:G,text:J})}};function i$(W){if(W%4==0)return 0;return 4-W%4}var bX=class W{ssrc=0;senderInfo;reports=[];static type=200;type=W.type;constructor(Y){Object.assign(this,Y)}toJSON(){return{ssrc:this.ssrc,senderInfo:this.senderInfo.toJSON(),reports:this.reports.map((Y)=>Y.toJSON())}}serialize(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.ssrc),Y=Buffer.concat([Y,this.senderInfo.serialize()]),Y=Buffer.concat([Y,...this.reports.map((G)=>G.serialize())]),e6.serialize(W.type,this.reports.length,Y,Math.floor(Y.length/4))}static deSerialize(Y,G){let X=Y.readUInt32BE(),J=G2.deSerialize(Y.subarray(4,24)),Z=24,V=[];for(let Q=0;Q<G;Q++)V.push(YK.deSerialize(Y.subarray(Z,Z+24))),Z+=24;return new W({ssrc:X,senderInfo:J,reports:V})}},G2=class W{ntpTimestamp;rtpTimestamp;packetCount;octetCount;constructor(Y={}){Object.assign(this,Y)}toJSON(){return{ntpTimestamp:_o(this.ntpTimestamp),rtpTimestamp:this.rtpTimestamp}}serialize(){return E8([8,4,4,4],[this.ntpTimestamp,this.rtpTimestamp,this.packetCount,this.octetCount])}static deSerialize(Y){let[G,X,J,Z]=s9(Y,[8,4,4,4]);return new W({ntpTimestamp:G,rtpTimestamp:X,packetCount:J,octetCount:Z})}},_o=(W)=>{let[Y,G]=s9(E8([8],[W]),[4,4]);return Number(`${Y}.${G}`)},yo=M1("werift-rtp:packages/rtp/src/rtcp/rtcp.ts"),vo=class{static deSerialize(W){let Y=0,G=[];while(Y<W.length){let X=e6.deSerialize(W.subarray(Y,Y+FO));Y+=FO;let J=W.subarray(Y);if(Y+=X.length*4,X.padding)J=J.subarray(0,J.length-J.subarray(-1)[0]);try{switch(X.type){case bX.type:G.push(bX.deSerialize(J,X.count));break;case rV.type:G.push(rV.deSerialize(J,X.count));break;case Zq.type:G.push(Zq.deSerialize(J,X));break;case hX.type:G.push(hX.deSerialize(J,X));break;case iV.type:G.push(iV.deSerialize(J,X));break;default:break}}catch(Z){yo("deSerialize RTCP",Z)}}return G}};function go(W){return W.length>=2&&W[1]>=192&&W[1]<=208}var C9={sdesMid:"urn:ietf:params:rtp-hdrext:sdes:mid",sdesRTPStreamID:"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",repairedRtpStreamId:"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",transportWideCC:"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",absSendTime:"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",dependencyDescriptor:"https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension",audioLevelIndication:"urn:ietf:params:rtp-hdrext:ssrc-audio-level",videoOrientation:"urn:3gpp:video-orientation"};function uo(W,Y){return W.map((G)=>{let X=Y[G.id];if(!X)return{uri:"unknown",value:G.payload};switch(X){case C9.sdesMid:case C9.sdesRTPStreamID:case C9.repairedRtpStreamId:return{uri:X,value:po(G.payload)};case C9.transportWideCC:return{uri:X,value:lo(G.payload)};case C9.absSendTime:return{uri:X,value:oo(G.payload)};case C9.audioLevelIndication:return{uri:X,value:no(G.payload)};case C9.videoOrientation:return{uri:X,value:io(G.payload)};default:return{uri:X,value:G.payload}}}).reduce((G,X)=>{if(X)G[X.uri]=X.value;return G},{})}function ho(W){return Buffer.from(W)}function bo(W){return Buffer.from(W)}function mo(W){return Buffer.from(W)}function fo(W){return E8([2],[W])}function co(W){let Y=Buffer.alloc(3),G=W>>14n&0x00ffffffn;return Y.writeUIntBE(Number(G),0,3),Y}function po(W){return W.toString()}function lo(W){return W.readUInt16BE()}function oo(W){return s9(W,[3])[0]}function no(W){let Y=new pV(W);return{v:Y.readBits(1)===1,level:Y.readBits(7)}}function io(W){let Y=new pV(W);return Y.readBits(4),{c:Y.readBits(1),f:Y.readBits(1),r1:Y.readBits(1),r0:Y.readBits(1)}}var ro=M1("packages/rtp/src/rtp/red/packet.ts"),X2=class W{header;blocks=[];static deSerialize(Y){let G=Y instanceof ArrayBuffer?Buffer.from(Y):Y,X=new W,J=0;return[X.header,J]=r$.deSerialize(G),X.header.fields.forEach(({blockLength:Z,timestampOffset:V,blockPT:U})=>{if(Z&&V){let Q=G.subarray(J,J+Z);X.blocks.push({block:Q,blockPT:U,timestampOffset:V}),J+=Z}else{let Q=G.subarray(J);X.blocks.push({block:Q,blockPT:U})}}),X}serialize(){this.header=new r$;for(let{timestampOffset:G,blockPT:X,block:J}of this.blocks)if(G)this.header.fields.push({fBit:1,blockPT:X,blockLength:J.length,timestampOffset:G});else this.header.fields.push({fBit:0,blockPT:X});let Y=this.header.serialize();for(let{block:G}of this.blocks)Y=Buffer.concat([Y,G]);return Y}},r$=class W{fields=[];static deSerialize(Y){let G=0,X=new W;for(;;){let J={};X.fields.push(J);let Z=new pV(Y.subarray(G));if(J.fBit=Z.readBits(1),J.blockPT=Z.readBits(7),G++,J.fBit===0)break;J.timestampOffset=Z.readBits(14),J.blockLength=Z.readBits(10),G+=3}return[X,G]}serialize(){let Y=Buffer.alloc(0);for(let G of this.fields)try{if(G.timestampOffset&&G.blockLength){let X=new pV(Buffer.alloc(4)).writeBits(1,G.fBit).writeBits(7,G.blockPT).writeBits(14,G.timestampOffset).writeBits(10,G.blockLength);Y=Buffer.concat([Y,X.uint8Array])}else{let X=new pV(Buffer.alloc(1)).writeBits(1,0).writeBits(7,G.blockPT);Y=Buffer.concat([Y,X.uint8Array])}}catch(X){ro(X?.message)}return Y}},ao=class{constructor(W=1){this.distance=W}cache=[];cacheSize=10;push(W){if(this.cache.push(W),this.cache.length>this.cacheSize)this.cache.shift()}build(){let W=new X2,Y=this.cache.slice(-(this.distance+1)),G=Y.pop();if(!G)return W;return Y.forEach((X)=>{let J=vX(G.timestamp,-X.timestamp);if(J>so)return;W.blocks.push({block:X.block,blockPT:X.blockPT,timestampOffset:J})}),W.blocks.push({block:G.block,blockPT:G.blockPT}),W}},so=16383,to=class{size=150;sequenceNumbers=[];push(W,Y){let G=[];return W.blocks.forEach(({blockPT:J,timestampOffset:Z,block:V},U)=>{let Q=T9(Y.header.sequenceNumber,-(W.blocks.length-(U+1)));if(Z)G.push(new t6(new s6({timestamp:vX(Y.header.timestamp,-Z),payloadType:J,ssrc:Y.header.ssrc,sequenceNumber:Q,marker:!0}),V));else G.push(new t6(new s6({timestamp:Y.header.timestamp,payloadType:J,ssrc:Y.header.ssrc,sequenceNumber:Q,marker:!0}),V))}),G.filter((J)=>{if(this.sequenceNumbers.includes(J.header.sequenceNumber))return!1;else{if(this.sequenceNumbers.length>this.size)this.sequenceNumbers.shift();return this.sequenceNumbers.push(J.header.sequenceNumber),!0}})}},jY={OneByte:48862,TwoByte:4096},a$=2,s$=4,t$=8,e$=12,WF=4,s6=class W{version=2;padding=!1;paddingSize=0;extension=!1;marker=!1;payloadOffset=0;payloadType=0;sequenceNumber=0;timestamp=0;ssrc=0;csrcLength=0;csrc=[];extensionProfile=jY.OneByte;extensionLength;extensions=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let G=new W,X=0,J=Y[X++];G.version=u8(J,0,2),G.padding=u8(J,2)>0,G.extension=u8(J,3)>0,G.csrcLength=u8(J,4,4),G.csrc=[...Array(G.csrcLength)].map(()=>{let V=Y.readUInt32BE(X);return X+=4,V}),X+=e$-1;let Z=Y[1];G.marker=u8(Z,0)>0,G.payloadType=u8(Z,1,7),G.sequenceNumber=Y.readUInt16BE(a$),G.timestamp=Y.readUInt32BE(s$),G.ssrc=Y.readUInt32BE(t$);for(let V=0;V<G.csrc.length;V++){let U=e$+V*WF;G.csrc[V]=Y.subarray(U).readUInt32BE()}if(G.extension){G.extensionProfile=Y.subarray(X).readUInt16BE(),X+=2;let V=Y.subarray(X).readUInt16BE()*4;switch(G.extensionLength=V,X+=2,G.extensionProfile){case jY.OneByte:{let U=X+V;while(X<U){if(Y[X]===0){X++;continue}let Q=Y[X]>>4,H=(Y[X]&(Y[X]^240))+1;if(X++,Q===15)break;let N={id:Q,payload:Y.subarray(X,X+H)};G.extensions=[...G.extensions,N],X+=H}}break;case jY.TwoByte:{let U=X+V;while(X<U){if(Y[X]===0){X++;continue}let Q=Y[X];X++;let H=Y[X];X++;let N={id:Q,payload:Y.subarray(X,X+H)};G.extensions=[...G.extensions,N],X+=H}}break;default:{let U={id:0,payload:Y.subarray(X,X+V)};G.extensions=[...G.extensions,U],X+=G.extensions[0].payload.length}break}}if(G.payloadOffset=X,G.padding)G.paddingSize=Y[Y.length-1];return G}get serializeSize(){let{csrc:Y,extensionProfile:G,extensions:X}=this,J=12+Y.length*WF;if(X.length>0||this.extension===!0){let Z=4;switch(G){case jY.OneByte:for(let V of X)Z+=1+V.payload.length;break;case jY.TwoByte:for(let V of X)Z+=2+V.payload.length;break;default:Z+=X[0].payload.length}J+=Math.floor((Z+3)/4)*4}return J}serialize(Y){let G=Buffer.alloc(Y),X=0,J=new nN(8);if(J.set(2,0,this.version),this.padding)J.set(1,2,1);if(this.extensions.length>0)this.extension=!0;if(this.extension)J.set(1,3,1);J.set(4,4,this.csrc.length),G.writeUInt8(J.value,X++);let Z=new nN(8);if(this.marker)Z.set(1,0,1);Z.set(7,1,this.payloadType),G.writeUInt8(Z.value,X++),G.writeUInt16BE(this.sequenceNumber,a$),X+=2,G.writeUInt32BE(this.timestamp,s$),X+=4,G.writeUInt32BE(this.ssrc,t$),X+=4;for(let V of this.csrc)G.writeUInt32BE(V,X),X+=4;if(this.extension){let V=X;G.writeUInt16BE(this.extensionProfile,X),X+=4;let U=X;switch(this.extensionProfile){case jY.OneByte:for(let N of this.extensions)G.writeUInt8(N.id<<4|N.payload.length-1,X++),N.payload.copy(G,X),X+=N.payload.length;break;case jY.TwoByte:for(let N of this.extensions)G.writeUInt8(N.id,X++),G.writeUInt8(N.payload.length,X++),N.payload.copy(G,X),X+=N.payload.length;break;default:{let N=this.extensions[0].payload.length;if(N%4!=0)throw Error();this.extensions[0].payload.copy(G,X),X+=N}}let Q=X-U,H=Math.trunc((Q+3)/4)*4;G.writeUInt16BE(Math.trunc(H/4),V+2);for(let N=0;N<H-Q;N++)G.writeUInt8(0,X),X++}return this.payloadOffset=X,G}},t6=class W{constructor(Y,G){this.header=Y,this.payload=G}get serializeSize(){return this.header.serializeSize+this.payload.length}clone(){return new W(new s6({...this.header}),this.payload)}serialize(){let Y=this.header.serialize(this.header.serializeSize+this.payload.length),{payloadOffset:G}=this.header;if(this.payload.copy(Y,G),this.header.padding){let X=Buffer.alloc(this.header.paddingSize);X.writeUInt8(this.header.paddingSize,this.header.paddingSize-1),Y=Buffer.concat([Y,X])}return Y}static deSerialize(Y){let G=s6.deSerialize(Y);return new W(G,Y.subarray(G.payloadOffset,Y.length-G.paddingSize))}clear(){this.payload=null}};function eo(W,Y,G){return new t6(new s6({payloadType:Y,marker:W.header.marker,sequenceNumber:s1.Unpack("!H",W.payload.subarray(0,2))[0],timestamp:W.header.timestamp,ssrc:G}),W.payload.subarray(2))}function Wn(W,Y,G,X){return new t6(new s6({payloadType:Y,marker:W.header.marker,sequenceNumber:G,timestamp:W.header.timestamp,ssrc:X,csrc:W.header.csrc,extensions:W.header.extensions}),Buffer.concat([Buffer.from(s1.Pack("!H",[W.header.sequenceNumber])),W.payload]))}var J2=class{constructor(W,Y,G,X){this.srtpSessionKey=W,this.srtpSessionSalt=Y,this.srtcpSessionKey=G,this.srtcpSessionSalt=X}encryptRtp(W,Y,G){return Buffer.from([])}decryptRtp(W,Y,G){return[]}encryptRTCP(W,Y){return Buffer.from([])}decryptRTCP(W){return[]}},mX=class extends Error{constructor(W){super(W);this.name="SrtpAuthenticationError"}},JF=12,Gn=8;function GK(W,Y,G="Failed to authenticate SRTP packet"){let X=W.length-Y;aV(W.length>=JF+Y,G);let J=V2(()=>s6.deSerialize(W.subarray(0,X)),G);return J.paddingSize=0,aV(J.payloadOffset>=JF&&J.payloadOffset<=X,G),J}function Z2(W,Y,G,X="Failed to authenticate SRTCP packet"){return aV(W.length>=Gn+Y+G,X),V2(()=>e6.deSerialize(W.subarray(0,FO)),X)}function aV(W,Y){if(!W)throw new mX(Y)}function V2(W,Y){try{return W()}catch{throw new mX(Y)}}function U2(W,Y,G="Failed to authenticate SRTP packet"){if(!W.padding)return W.paddingSize=0,W;aV(Y.length>W.payloadOffset,G);let X=Y[Y.length-1];return aV(X>0&&X<=Y.length-W.payloadOffset,G),W.paddingSize=X,W}var Xn=class extends J2{constructor(W,Y,G,X,J,Z){super(W,Y,G,X);this.srtpSessionAuthTag=J,this.srtcpSessionAuthTag=Z}authTagLength=10;encryptRtp(W,Y,G){let X=W.serialize(W.serializeSize),J=this.generateCounter(W.sequenceNumber,G,W.ssrc,this.srtpSessionSalt),V=YF("aes-128-ctr",this.srtpSessionKey,J).update(Y),U=this.generateSrtpAuthTag(G,X,V);return Buffer.concat([X,V,U])}decryptRtp(W,Y,G=GK(W,this.authTagLength)){let X=W.length-this.authTagLength,J=W.subarray(0,X),Z=W.subarray(X),V=this.generateSrtpAuthTag(Y,J.subarray(0,G.payloadOffset),J.subarray(G.payloadOffset));VF(Z,V,"Failed to authenticate SRTP packet");let U=this.generateCounter(G.sequenceNumber,Y,G.ssrc,this.srtpSessionSalt),Q=GF("aes-128-ctr",this.srtpSessionKey,U),H=J.subarray(G.payloadOffset),N=Q.update(H),A=Buffer.concat([J.subarray(0,G.payloadOffset),N]);return[A,U2(G,A,"Failed to authenticate SRTP packet")]}encryptRTCP(W,Y){let G=Buffer.from(W),X=G.readUInt32BE(4),J=this.generateCounter(Y&65535,Y>>16,X,this.srtcpSessionSalt);YF("aes-128-ctr",this.srtcpSessionKey,J).update(G.slice(8)).copy(G,8),G=Buffer.concat([G,Buffer.alloc(4)]),G.writeUInt32BE(Y,G.length-4),G[G.length-4]|=128;let U=this.generateSrtcpAuthTag(G);return G=Buffer.concat([G,U]),G}decryptRTCP(W){let Y=Z2(W,this.authTagLength,ZF),G=W.length-(this.authTagLength+ZF),X=W.subarray(0,W.length-this.authTagLength),J=W.subarray(W.length-this.authTagLength),Z=this.generateSrtcpAuthTag(X);VF(J,Z,"Failed to authenticate SRTCP packet");let V=Buffer.from(W).slice(0,G);if(W[G]>>>7===0)return[V,Y];let Q=W.readUInt32BE(G);Q&=2147483647;let H=W.readUInt32BE(4),N=this.generateCounter(Q&65535,Q>>16,H,this.srtcpSessionSalt);return GF("aes-128-ctr",this.srtcpSessionKey,N).update(V.subarray(8)).copy(V,8),[V,Y]}generateSrtcpAuthTag(W){return XF("sha1",this.srtcpSessionAuthTag).update(W).digest().slice(0,10)}generateCounter(W,Y,G,X){let J=Buffer.alloc(16);J.writeUInt32BE(G,4),J.writeUInt32BE(Y,8),J.writeUInt32BE(Number(BigInt(W)<<16n),12);for(let Z=0;Z<X.length;Z++)J[Z]^=X[Z];return J}generateSrtpAuthTag(W,...Y){let G=XF("sha1",this.srtpSessionAuthTag),X=Buffer.alloc(4);X.writeUInt32BE(W);for(let J of Y)G.update(J);return G.update(X).digest().subarray(0,10)}},ZF=4;function VF(W,Y,G){if(W.length!==Y.length||!Yn(W,Y))throw new mX(G)}var Jn=class extends J2{aeadAuthTagLen=16;rtpIvWriter=_N([2,4,4,2],!0);rtcpIvWriter=_N([2,4,2,4],!0);aadWriter=_N([4],!0);constructor(W,Y,G,X){super(W,Y,G,X)}encryptRtp(W,Y,G){let X=W.serialize(W.serializeSize),J=this.rtpInitializationVector(W,G),Z=UF("aes-128-gcm",this.srtpSessionKey,J);Z.setAAD(X);let V=Z.update(Y);Z.final();let U=Z.getAuthTag();return Buffer.concat([X,V,U])}decryptRtp(W,Y,G=GK(W,this.aeadAuthTagLen)){let X=W.subarray(0,G.payloadOffset),J=W.length-this.aeadAuthTagLen,Z=W.subarray(J),V=Buffer.from([]);V=o$(V,W.length-this.aeadAuthTagLen),X.copy(V);let U=this.rtpInitializationVector(G,Y),Q=W.slice(G.payloadOffset,J),H=QF("aes-128-gcm",this.srtpSessionKey,U);H.setAAD(X),H.setAuthTag(Z);let N=H.update(Q);return NF(H,"SRTP"),N.copy(V,G.payloadOffset),[V,U2(G,V,"Failed to authenticate SRTP packet")]}encryptRTCP(W,Y){let G=W.readUInt32BE(4),X=W.length+this.aeadAuthTagLen,J=Buffer.from([]);J=o$(J,X+VO),W.slice(0,8).copy(J);let Z=this.rtcpInitializationVector(G,Y),V=this.rtcpAdditionalAuthenticatedData(W,Y),U=UF("aes-128-gcm",this.srtcpSessionKey,Z);U.setAAD(V);let Q=U.update(W.slice(8));return U.final(),Q.copy(J,8),U.getAuthTag().copy(J,8+Q.length),V.slice(8,12).copy(J,X),J}decryptRTCP(W){let Y=Z2(W,this.aeadAuthTagLen,VO),G=W.length-VO,X=G-this.aeadAuthTagLen,J=W.readUInt32BE(4),Z=W.readUInt32BE(G),V=Z>>>31===1,U=Z&~(HF<<24),Q=this.rtcpInitializationVector(J,U),H=V?Buffer.concat([W.subarray(0,8),W.subarray(G)]):Buffer.concat([W.subarray(0,X),W.subarray(G)]),N=V?W.slice(8,X):Buffer.alloc(0),A=V?Buffer.alloc(X):Buffer.from(W.subarray(0,X));if(V)W.slice(0,8).copy(A);let q=QF("aes-128-gcm",this.srtcpSessionKey,Q);q.setAAD(H),q.setAuthTag(W.subarray(X,G));let z=q.update(N);if(NF(q,"SRTCP"),V)z.copy(A,8);return[A,Y]}rtpInitializationVector(W,Y){let G=this.rtpIvWriter([0,W.ssrc,Y,W.sequenceNumber]);for(let X=0;X<G.length;X++)G[X]^=this.srtpSessionSalt[X];return G}rtcpInitializationVector(W,Y){let G=this.rtcpIvWriter([0,W,0,Y]);for(let X=0;X<G.length;X++)G[X]^=this.srtcpSessionSalt[X];return G}rtcpAdditionalAuthenticatedData(W,Y){let G=Buffer.concat([W.subarray(0,8),this.aadWriter([Y])]);return G[8]|=HF,G}},VO=4,HF=128;function NF(W,Y){try{W.final()}catch{throw new mX(`Failed to authenticate ${Y} packet`)}}var Q2=class{constructor(W,Y,G){this.masterKey=W,this.masterSalt=Y,this.profile=G;{let X=14-Y.length;if(X>0)this.masterSalt=Buffer.concat([Y,Buffer.alloc(X)])}switch(this.srtpSessionKey=this.generateSessionKey(0),this.srtpSessionSalt=this.generateSessionSalt(2),this.srtpSessionAuthTag=this.generateSessionAuthTag(1),this.srtpSessionAuth=ZO("sha1",this.srtpSessionAuthTag),this.srtcpSessionKey=this.generateSessionKey(3),this.srtcpSessionSalt=this.generateSessionSalt(5),this.srtcpSessionAuthTag=this.generateSessionAuthTag(4),this.srtcpSessionAuth=ZO("sha1",this.srtcpSessionAuthTag),G){case zq:this.cipher=new Xn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt,this.srtpSessionAuthTag,this.srtcpSessionAuthTag);break;case VU:this.cipher=new Jn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt);break}}srtpSSRCStates={};srtpSessionKey;srtpSessionSalt;srtpSessionAuthTag;srtpSessionAuth;srtcpSSRCStates={};srtcpSessionKey;srtcpSessionSalt;srtcpSessionAuthTag;srtcpSessionAuth;cipher;generateSessionKey(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=Y.length-1;J>=0;J--,Z--)Y[Z]=Y[Z]^G[J];Y=Buffer.concat([Y,Buffer.from([0,0])]);let X=new vN.default.AES(this.masterKey);return Buffer.from(X.encrypt(Y))}generateSessionSalt(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=Y.length-1;J>=0;J--,Z--)Y[Z]=Y[Z]^G[J];Y=Buffer.concat([Y,Buffer.from([0,0])]);let X=new vN.default.AES(this.masterKey);return Y=Buffer.from(X.encrypt(Y)),Y.subarray(0,14)}generateSessionAuthTag(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let V=G.length-1,U=Y.length-1;V>=0;V--,U--)Y[U]=Y[U]^G[V];let X=Buffer.concat([Y,Buffer.from([0,0])]),J=Buffer.concat([Y,Buffer.from([0,1])]),Z=new vN.default.AES(this.masterKey);return X=Buffer.from(Z.encrypt(X)),J=Buffer.from(Z.encrypt(J)),Buffer.concat([X,J.subarray(0,4)])}getSrtpSsrcState(W){let Y=this.srtpSSRCStates[W];if(Y)return Y;return Y={ssrc:W,rolloverCounter:0,lastSequenceNumber:0},this.srtpSSRCStates[W]=Y,Y}getSrtcpSsrcState(W){let Y=this.srtcpSSRCStates[W];if(Y)return Y;return Y={srtcpIndex:0,ssrc:W},this.srtcpSSRCStates[W]=Y,Y}updateRolloverCount(W,Y){if(!Y.rolloverHasProcessed)Y.rolloverHasProcessed=!0;else if(W===0){if(Y.lastSequenceNumber>yV)Y.rolloverCounter++}else if(Y.lastSequenceNumber<yV&&W>qF-yV){if(Y.rolloverCounter>0)Y.rolloverCounter--}else if(W<yV&&Y.lastSequenceNumber>qF-yV)Y.rolloverCounter++;Y.lastSequenceNumber=W}generateSrtpAuthTag(W,Y){this.srtpSessionAuth=ZO("sha1",this.srtpSessionAuthTag);let G=Buffer.alloc(4);return G.writeUInt32BE(Y),this.srtpSessionAuth.update(W).update(G).digest().slice(0,10)}index(W){let Y=this.srtcpSSRCStates[W];if(!Y)return 0;return Y.srtcpIndex}setIndex(W,Y){let G=this.getSrtcpSsrcState(W);G.srtcpIndex=Y%2147483647}},yV=100,qF=65535,Zn=class extends Q2{constructor(W,Y,G){super(W,Y,G)}encryptRTCP(W){let Y=W.readUInt32BE(4),G=this.getSrtcpSsrcState(Y);if(G.srtcpIndex++,G.srtcpIndex>>Vn)G.srtcpIndex=0;return this.cipher.encryptRTCP(W,G.srtcpIndex)}decryptRTCP(W){return this.cipher.decryptRTCP(W)}},Vn=2147483647,H2=class{constructor(W){this.ContextCls=W}localContext;remoteContext;onData;start(W,Y,G,X,J){this.localContext=new this.ContextCls(W,Y,J),this.remoteContext=new this.ContextCls(G,X,J)}},Un=class extends H2{constructor(W){super(Zn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[Y]=this.remoteContext.decryptRTCP(W);return Y};encrypt(W){return this.localContext.encryptRTCP(W)}},Qn=class extends Q2{constructor(W,Y,G){super(W,Y,G)}encryptRtp(W,Y){let G=this.getSrtpSsrcState(Y.ssrc);return this.updateRolloverCount(Y.sequenceNumber,G),this.cipher.encryptRtp(Y,W,G.rolloverCounter)}decryptRtp(W){let Y=GK(W,this.rtpAuthTagLength),G=this.srtpSSRCStates[Y.ssrc],X=G?{...G}:{ssrc:Y.ssrc,rolloverCounter:0,lastSequenceNumber:0};this.updateRolloverCount(Y.sequenceNumber,X);let J=this.cipher.decryptRtp(W,X.rolloverCounter,Y);if(G)Object.assign(G,X);else this.srtpSSRCStates[Y.ssrc]=X;return J}get rtpAuthTagLength(){return this.profile===VU?16:10}},Hn=class extends H2{constructor(W){super(Qn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[Y]=this.remoteContext.decryptRtp(W);return Y};encrypt(W,Y){return this.localContext.encryptRtp(W,Y)}},bq0=class{constructor(W){this.props=W}sequenceNumber=zS();timestamp=CO();create(W){this.sequenceNumber=T9(this.sequenceNumber,1);let Y=this.props.between*this.props.clockRate/1000;this.timestamp=vX(this.timestamp,Y);let G=new s6({sequenceNumber:this.sequenceNumber,timestamp:Number(this.timestamp),payloadType:96,extension:!0,marker:!1,padding:!1});return new t6(G,W)}},u9=M1("werift-dtls : packages/dtls/src/flight/client/flight5.ts : log"),Nn=class extends GU{constructor(W,Y,G,X){super(W,Y,5,7);this.cipher=G,this.srtp=X}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,4);let Y=(()=>{switch(W.msg_type){case 2:return rS.deSerialize(W.fragment);case 11:return eN.deSerialize(W.fragment);case 12:return tS.deSerialize(W.fragment);case 13:return iS.deSerialize(W.fragment);case 14:return aS.deSerialize(W.fragment)}})();if(Y)pX[Y.msgType]({dtls:this.dtls,cipher:this.cipher,srtp:this.srtp})(Y)}async exec(){if(this.dtls.flight===5){u9(this.dtls.sessionId,"flight5 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=5;let W=this.dtls.requestedCertificateTypes.length>0;u9(this.dtls.sessionId,"send flight5",W);let Y=[W&&this.sendCertificate(),this.sendClientKeyExchange(),W&&this.sendCertificateVerify(),this.sendChangeCipherSpec(),this.sendFinished()].filter((G)=>G);this.dtls.lastMessage=Y,await this.transmit(Y)}sendCertificate(){let W=new eN([Buffer.from(this.cipher.localCert)]),Y=this.createPacket([W]);return Buffer.concat(Y.map((X)=>X.serialize()))}sendClientKeyExchange(){if(!this.cipher.localKeyPair)throw Error();let W=new nS(this.cipher.localKeyPair.publicKey),Y=this.createPacket([W]),G=Buffer.concat(Y.map((U)=>U.serialize())),X=this.cipher.localKeyPair,J=this.cipher.remoteKeyPair;if(!J.publicKey)throw Error("not exist");let Z=xS(J.publicKey,X.privateKey,X.curve);u9(this.dtls.sessionId,"extendedMasterSecret",this.dtls.options.extendedMasterSecret,this.dtls.remoteExtendedMasterSecret);let V=Buffer.concat(this.dtls.sortedHandshakeCache.map((U)=>U.serialize()));return this.cipher.masterSecret=this.dtls.options.extendedMasterSecret&&this.dtls.remoteExtendedMasterSecret?_S(Z,V):kS(Z,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize()),this.cipher.cipher=cS(this.cipher.cipherSuite),this.cipher.cipher.init(this.cipher.masterSecret,this.cipher.remoteRandom.serialize(),this.cipher.localRandom.serialize()),u9(this.dtls.sessionId,"cipher",this.cipher.cipher.summary),G}sendCertificateVerify(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((V)=>V.serialize())),Y=this.cipher.signatureData(W,"sha256"),G=(()=>{switch(this.cipher.signatureHashAlgorithm?.signature){case l4.ecdsa_3:return b$.ecdsa_secp256r1_sha256;case l4.rsa_1:return b$.rsa_pkcs1_sha256}})();if(!G)throw Error();u9(this.dtls.sessionId,"signatureScheme",this.cipher.signatureHashAlgorithm?.signature,G);let X=new oS(G,Y),J=this.createPacket([X]);return Buffer.concat(J.map((V)=>V.serialize()))}sendChangeCipherSpec(){let W=dS.createEmpty().serialize(),Y=YU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(Y.map((X)=>X.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),Y=this.cipher.verifyData(W),G=new $O(Y);this.dtls.epoch=1;let[X]=this.createPacket([G]);this.dtls.recordSequenceNumber=0;let J=this.cipher.encryptPacket(X).serialize();return u9(this.dtls.sessionId,"finished",this.cipher.cipher.summary),J}},pX={};pX[2]=({cipher:W,srtp:Y,dtls:G})=>(X)=>{if(u9(G.sessionId,"serverHello",X.cipherSuite),W.remoteRandom=TY.from(X.random),W.cipherSuite=X.cipherSuite,u9(G.sessionId,"selected cipherSuite",W.cipherSuite),X.extensions)X.extensions.forEach((J)=>{switch(J.type){case uX.type:{let Z=uX.fromData(J.data),V=sN.findMatchingSRTPProfile(Z.profiles,G.options.srtpProfiles||[]);if(u9(G.sessionId,"selected srtp profile",V),V==null)return;Y.srtpProfile=V}break;case qq.type:G.remoteExtendedMasterSecret=!0;break;case Aq.type:u9(G.sessionId,"RenegotiationIndication");break}})};pX[11]=({cipher:W,dtls:Y})=>(G)=>{u9(Y.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};pX[12]=({cipher:W,dtls:Y})=>(G)=>{if(!W.localRandom||!W.remoteRandom)throw Error();u9(Y.sessionId,"ServerKeyExchange",G),u9(Y.sessionId,"selected curve",G.namedCurve),W.remoteKeyPair={curve:G.namedCurve,publicKey:G.publicKey},W.localKeyPair=lS(G.namedCurve)};pX[13]=({dtls:W})=>(Y)=>{u9(W.sessionId,"certificate_request",Y),W.requestedCertificateTypes=Y.certificateTypes,W.requestedSignatureAlgorithms=Y.signatures};pX[14]=({dtls:W})=>(Y)=>{u9(W.sessionId,"server_hello_done",Y)};var N2=class W{constructor(Y,G){this.serverVersion=Y,this.cookie=G}msgType=3;messageSeq;static spec={serverVersion:WK,cookie:LY.types.buffer(LY.types.uint8)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){return new W(...Object.values(LY.decode(Y,W.spec)))}serialize(){let Y=LY.encode(this,W.spec).slice();return Buffer.from(Y)}get version(){return{major:255-this.serverVersion.major,minor:255-this.serverVersion.minor}}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},An=M1("werift-dtls : packages/dtls/src/context/dtls.ts : log"),AF=class{constructor(W,Y){this.options=W,this.sessionType=Y}version={major:254,minor:253};lastFlight=[];lastMessage=[];recordSequenceNumber=0;sequenceNumber=0;epoch=0;flight=0;handshakeCache={};cookie;requestedCertificateTypes=[];requestedSignatureAlgorithms=[];remoteExtendedMasterSecret=!1;get sessionId(){return this.cookie?this.cookie.toString("hex").slice(0,10):""}get sortedHandshakeCache(){return Object.entries(this.handshakeCache).sort(([W],[Y])=>Number(W)-Number(Y)).flatMap(([,{data:W}])=>W.sort((Y,G)=>Y.message_seq-G.message_seq))}checkHandshakesExist=(W)=>!W.find((Y)=>this.sortedHandshakeCache.find((G)=>G.msg_type===Y)==null);bufferHandshakeCache(W,Y,G){if(!this.handshakeCache[G])this.handshakeCache[G]={data:[],isLocal:Y,flight:G};let X=W.filter((J)=>{let Z=this.handshakeCache[G].data.find((V)=>V.msg_type===J.msg_type);if(Z)return An(this.sessionId,"exist",Z.summary,Y,G),!1;return!0});this.handshakeCache[G].data=[...this.handshakeCache[G].data,...X]}},In=class{constructor(W){this.socket=W}send=(W)=>{return this.socket.send(W)}},SO=class W{static type=10;static spec={type:l7.types.uint16be,data:l7.types.array(l7.types.uint16be,l7.types.uint16be,"bytes")};type=W.type;data=[];constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static fromData(Y){return new W({type:W.type,data:l7.decode(Y,W.spec.data)})}static deSerialize(Y){return new W(l7.decode(Y,W.spec))}serialize(){return Buffer.from(l7.encode(this,W.spec).slice())}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},xO=class W{static type=13;static spec={type:c7.types.uint16be,data:c7.types.array({hash:c7.types.uint8,signature:c7.types.uint8},c7.types.uint16be,"bytes")};type=W.type;data=[];constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static deSerialize(Y){return new W(c7.decode(Y,W.spec))}serialize(){let Y=c7.encode(this,W.spec).slice();return Buffer.from(Y)}static fromData(Y){let G=Buffer.alloc(2);return G.writeUInt16BE(W.type),W.deSerialize(Buffer.concat([G,Y]))}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},IF=class W{constructor(Y,G){this.level=Y,this.description=G}static spec={level:BY.types.uint8,description:BY.types.uint8};static deSerialize(Y){return new W(...Object.values(BY.decode(Y,W.spec)))}serialize(){let Y=BY.encode(this,W.spec).slice();return Buffer.from(Y)}},zF=M1("werift-dtls : packages/dtls/record/receive.ts : log"),UO=M1("werift-dtls : packages/dtls/record/receive.ts : err"),zn=(W)=>{let Y=0,G=[];while(W.length>Y){let X=W.readUInt16BE(Y+11);if(W.length<Y+(12+X))break;let J=mS.deSerialize(W.subarray(Y));G.push(J),Y+=13+X}return G},wn=(W,Y)=>(G)=>{switch(G.recordLayerHeader.contentType){case 20:return zF(W.sessionId,"change cipher spec"),[{type:20,data:void 0}];case 22:{let J=G.fragment;try{if(G.recordLayerHeader.epoch>0)zF(W.sessionId,"decrypt handshake"),J=Y.decryptPacket(G)}catch(Z){throw UO(W.sessionId,"decrypt failed",Z),Z}try{let Z=0,V=[];while(J.length>Z){let U=E5.deSerialize(J.subarray(Z));V.push({type:22,data:U}),Z+=U.fragment_length+12}return V}catch(Z){throw UO(W.sessionId,"decSerialize failed",Z,J),Z}}case 23:return[{type:23,data:Y.decryptPacket(G)}];case 21:{let J=IF.deSerialize(G.fragment);if(EO[J.description]==null){let Z=Y.decryptPacket(G);J=IF.deSerialize(Z)}if(UO(W.sessionId,"ContentType.alert",J,EO[J.description],"flight",W.flight,"lastFlight",W.lastFlight),J.level>1)throw Error("alert fatal error");return[{type:21,data:void 0}]}default:return[{type:21,data:void 0}]}},wF=M1("werift-dtls : packages/dtls/src/socket.ts : log"),jF=M1("werift-dtls : packages/dtls/src/socket.ts : err"),q2=class{constructor(W,Y){this.options=W,this.sessionType=Y,this.dtls=new AF(this.options,this.sessionType),this.cipher=new aN(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.transport=new In(this.options.transport),this.setupExtensions(),this.transport.socket.onData=this.udpOnMessage}onConnect=new p0;onData=new p0;onError=new p0;onClose=new p0;transport;cipher;dtls;srtp=new sN;connected=!1;extensions=[];onHandleHandshakes;bufferFragmentedHandshakes=[];renegotiation(){wF("renegotiation",this.sessionType),this.connected=!1,this.cipher=new aN(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.dtls=new AF(this.options,this.sessionType),this.srtp=new sN,this.extensions=[],this.bufferFragmentedHandshakes=[]}udpOnMessage=(W)=>{let Y=zn(W);for(let G of Y)try{let X=wn(this.dtls,this.cipher)(G);for(let J of X)switch(J.type){case 22:{let Z=J.data,V=this.handleFragmentHandshake([Z]),U=Object.values(V.reduce((Q,H)=>{if(!Q[H.msg_type])Q[H.msg_type]=[];return Q[H.msg_type].push(H),Q},{})).map((Q)=>E5.assemble(Q)).sort((Q,H)=>Q.msg_type-H.msg_type);this.onHandleHandshakes(U).catch((Q)=>{jF(this.dtls.sessionId,"onHandleHandshakes error",Q),this.onError.execute(Q)})}break;case 23:this.onData.execute(J.data);break;case 21:this.onClose.execute();break}}catch(X){jF(this.dtls.sessionId,"catch udpOnMessage error",X)}};setupExtensions(){if(wF(this.dtls.sessionId,"support srtpProfiles",this.options.srtpProfiles),this.options.srtpProfiles&&this.options.srtpProfiles.length>0){let W=uX.create(this.options.srtpProfiles,Buffer.from([0]));this.extensions.push(W.extension)}{let W=SO.createEmpty();W.data=BS,this.extensions.push(W.extension)}{let W=xO.createEmpty();W.data=$S,this.extensions.push(W.extension)}if(this.options.extendedMasterSecret)this.extensions.push({type:qq.type,data:Buffer.alloc(0)});{let W=Aq.createEmpty();this.extensions.push(W.extension)}}waitForReady=(W)=>new Promise(async(Y,G)=>{for(let X=0;X<10;X++)if(W()){Y();break}else await qn(100*X);G("waitForReady timeout")});handleFragmentHandshake(W){let Y=W.filter((G)=>{if(G.fragment_length!==G.length)return this.bufferFragmentedHandshakes.push(G),!1;return!0});if(this.bufferFragmentedHandshakes.length>1){let[G]=this.bufferFragmentedHandshakes.slice(-1);if(G.fragment_offset+G.fragment_length===G.length)Y=[...this.bufferFragmentedHandshakes,...Y],this.bufferFragmentedHandshakes=[]}return Y}send=async(W)=>{let Y=YU(this.dtls)([{type:23,fragment:W}],++this.dtls.recordSequenceNumber)[0];await this.transport.send(this.cipher.encryptPacket(Y).serialize())};close(){this.transport.socket.close()}extractSessionKeys(W,Y){let G=this.exportKeyingMaterial("EXTRACTOR-dtls_srtp",W*2+Y*2),{clientKey:X,serverKey:J,clientSalt:Z,serverSalt:V}=KY.decode(G,{clientKey:KY.types.buffer(W),serverKey:KY.types.buffer(W),clientSalt:KY.types.buffer(Y),serverSalt:KY.types.buffer(Y)});if(this.sessionType===p4.CLIENT)return{localKey:X,localSalt:Z,remoteKey:J,remoteSalt:V};else return{localKey:J,localSalt:V,remoteKey:X,remoteSalt:Z}}exportKeyingMaterial(W,Y){return nd(W,Y,this.cipher.masterSecret,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize(),this.sessionType===p4.CLIENT)}get remoteCertificate(){return this.cipher.remoteCertificate}},QO=M1("werift-dtls : packages/dtls/src/client.ts : log"),OF=class extends q2{constructor(W){super(W,p4.CLIENT);this.onHandleHandshakes=this.handleHandshakes,QO(this.dtls.sessionId,"start client")}async connect(){await new No(this.transport,this.dtls,this.cipher).exec(this.extensions)}flight5;handleHandshakes=async(W)=>{QO(this.dtls.sessionId,"handleHandshakes",W.map((Y)=>Y.msg_type));for(let Y of W)switch(Y.msg_type){case 3:{let G=N2.deSerialize(Y.fragment);await new Ao(this.transport,this.dtls).exec(G)}break;case 2:{if(this.connected)return;this.flight5=new Nn(this.transport,this.dtls,this.cipher,this.srtp),this.flight5.handleHandshake(Y)}break;case 11:case 12:case 13:await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(Y);break;case 14:{await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(Y);let G=[11,12,this.options.certificateRequest&&13].filter((X)=>typeof X==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight5?.exec()}break;case 20:this.dtls.flight=7,this.connected=!0,this.onConnect.execute(),QO(this.dtls.sessionId,"dtls connected");break}}},f7=M1("werift-dtls : packages/dtls/flight/server/flight2.ts : log"),On=(W,Y,G,X)=>(J)=>{f7("dtls version",J.clientVersion),Y.flight=2,Y.recordSequenceNumber=0,Y.sequenceNumber=0,J.extensions.forEach((A)=>{switch(A.type){case SO.type:{let q=SO.fromData(A.data).data;f7(Y.sessionId,"curves",q);let z=q.filter((w)=>BS.includes(w))[0];G.namedCurve=z,f7(Y.sessionId,"curve selected",G.namedCurve)}break;case xO.type:{if(!G.signatureHashAlgorithm)throw Error("need to set certificate");let q=xO.fromData(A.data).data;f7(Y.sessionId,"hash,signature",q);let z=q.find((D)=>D.signature===G.signatureHashAlgorithm?.signature)?.signature,w=q.find((D)=>D.hash===G.signatureHashAlgorithm?.hash)?.hash;if(z==null||w==null)throw Error("invalid signatureHash")}break;case uX.type:{if(!Y.options?.srtpProfiles)return;if(Y.options.srtpProfiles.length===0)return;let q=uX.fromData(A.data);f7(Y.sessionId,"srtp profiles",q.profiles);let z=sN.findMatchingSRTPProfile(q.profiles,Y.options?.srtpProfiles);if(!z)throw Error();X.srtpProfile=z,f7(Y.sessionId,"srtp profile selected",X.srtpProfile)}break;case qq.type:Y.remoteExtendedMasterSecret=!0;break;case Aq.type:f7(Y.sessionId,"RenegotiationIndication",A.data);break;case 43:{let z=[...A.data.subarray(1)].map((w)=>w.toString(10));f7("dtls supported version",z)}break}}),G.localRandom=new TY,G.remoteRandom=TY.from(J.random);let Z=J.cipherSuites;f7(Y.sessionId,"cipher suites",Z);let V=(()=>{switch(G.signatureHashAlgorithm?.signature){case l4.ecdsa_3:return PO.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195;case l4.rsa_1:return PO.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199}})();if(V===void 0||!Z.includes(V))throw Error("dtls cipher suite negotiation failed");G.cipherSuite=V,f7(Y.sessionId,"selected cipherSuite",G.cipherSuite),G.localKeyPair=lS(G.namedCurve),Y.cookie||=jn(20);let U=new N2({major:254,minor:253},Y.cookie),Q=fS(Y)([U]),N=YU(Y)(Q.map((A)=>({type:22,fragment:A.serialize()})),++Y.recordSequenceNumber).map((A)=>A.serialize());for(let A of N)W.send(A)},KF=M1("werift-dtls : packages/dtls/flight/server/flight4.ts : log"),Kn=class extends GU{constructor(W,Y,G,X){super(W,Y,4,6);this.cipher=G,this.srtp=X}async exec(W,Y=!1){if(this.dtls.flight===4){KF(this.dtls.sessionId,"flight4 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=4,this.dtls.sequenceNumber=1,this.dtls.bufferHandshakeCache([W],!1,4);let G=[this.sendServerHello(),this.sendCertificate(),this.sendServerKeyExchange(),Y&&this.sendCertificateRequest(),this.sendServerHelloDone()].filter((X)=>X);this.dtls.lastMessage=G,await this.transmit(G)}sendServerHello(){let W=[];if(this.srtp.srtpProfile)W.push(uX.create([this.srtp.srtpProfile],Buffer.from([0])).extension);if(this.dtls.options.extendedMasterSecret)W.push({type:qq.type,data:Buffer.alloc(0)});let Y=Aq.createEmpty();W.push(Y.extension);let G=new rS(this.dtls.version,this.cipher.localRandom,Buffer.from([0]),this.cipher.cipherSuite,0,W),X=this.createPacket([G]);return Buffer.concat(X.map((J)=>J.serialize()))}sendCertificate(){let W=new eN([Buffer.from(this.cipher.localCert)]),Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}sendServerKeyExchange(){let W=this.cipher.generateKeySignature("sha256");if(!this.cipher.signatureHashAlgorithm)throw Error("not exist");let Y=new tS(ES.named_curve_3,this.cipher.namedCurve,this.cipher.localKeyPair.publicKey.length,this.cipher.localKeyPair.publicKey,this.cipher.signatureHashAlgorithm.hash,this.cipher.signatureHashAlgorithm.signature,W.length,W),G=this.createPacket([Y]);return Buffer.concat(G.map((X)=>X.serialize()))}sendCertificateRequest(){let W=new iS(cd,$S,[]);KF(this.dtls.sessionId,"sendCertificateRequest",W);let Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}sendServerHelloDone(){let W=new aS,Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}},fX=M1("werift-dtls : packages/dtls/flight/server/flight6.ts"),Dn=class extends GU{constructor(W,Y,G){super(W,Y,6);this.cipher=G}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,5);let Y=(()=>{switch(W.msg_type){case 11:return eN.deSerialize(W.fragment);case 15:return oS.deSerialize(W.fragment);case 16:return nS.deSerialize(W.fragment);case 20:return $O.deSerialize(W.fragment)}})();if(Y){let G=UU[Y.msgType];if(!G)return;G({dtls:this.dtls,cipher:this.cipher})(Y)}}async exec(){if(this.dtls.flight===6){fX(this.dtls.sessionId,"flight6 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=6;let W=[this.sendChangeCipherSpec(),this.sendFinished()];this.dtls.lastMessage=W,await this.transmit(W)}sendChangeCipherSpec(){let W=dS.createEmpty().serialize(),Y=YU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(Y.map((X)=>X.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),Y=this.cipher.verifyData(W),G=new $O(Y);this.dtls.epoch=1;let[X]=this.createPacket([G]);return this.dtls.recordSequenceNumber=0,this.cipher.encryptPacket(X).serialize()}},UU={};UU[16]=({cipher:W,dtls:Y})=>(G)=>{if(W.remoteKeyPair={curve:W.namedCurve,publicKey:G.publicKey},!W.remoteKeyPair.publicKey||!W.localKeyPair||!W.remoteRandom||!W.localRandom)throw Error("not exist");let X=xS(W.remoteKeyPair.publicKey,W.localKeyPair.privateKey,W.localKeyPair.curve);fX(Y.sessionId,"extendedMasterSecret",Y.options.extendedMasterSecret,Y.remoteExtendedMasterSecret);let J=Buffer.concat(Y.sortedHandshakeCache.map((Z)=>Z.serialize()));W.masterSecret=Y.options.extendedMasterSecret&&Y.remoteExtendedMasterSecret?_S(X,J):kS(X,W.remoteRandom.serialize(),W.localRandom.serialize()),W.cipher=cS(W.cipherSuite),W.cipher.init(W.masterSecret,W.localRandom.serialize(),W.remoteRandom.serialize()),fX(Y.sessionId,"setup cipher",W.cipher.summary)};UU[11]=({cipher:W,dtls:Y})=>(G)=>{fX(Y.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};UU[15]=({cipher:W,dtls:Y})=>(G)=>{if(!W.remoteCertificate)throw Error("client certificate missing before certificate verify");fX(Y.sessionId,"certificate_verify",G.algorithm)};UU[20]=({dtls:W})=>(Y)=>{fX(W.sessionId,"finished",Y)};var FX=M1("werift-dtls : packages/dtls/src/server.ts : log"),Cn=class extends q2{constructor(W){super(W,p4.SERVER);this.onHandleHandshakes=this.handleHandshakes,FX(this.dtls.sessionId,"start server")}flight6;handleHandshakes=async(W)=>{FX(this.dtls.sessionId,"handleHandshakes",W.map((Y)=>Y.msg_type));for(let Y of W)switch(Y.msg_type){case 1:{if(this.connected)this.renegotiation();let G=bS.deSerialize(Y.fragment);if(G.cookie.length===0)FX(this.dtls.sessionId,"send flight2"),On(this.transport,this.dtls,this.cipher,this.srtp)(G);else if(this.dtls.cookie&&G.cookie.equals(this.dtls.cookie))FX(this.dtls.sessionId,"send flight4"),await new Kn(this.transport,this.dtls,this.cipher,this.srtp).exec(Y,this.options.certificateRequest);else FX("wrong state",{dtlsCookie:this.dtls.cookie?.toString("hex").slice(10),helloCookie:G.cookie.toString("hex").slice(10)})}break;case 11:case 15:case 16:{if(this.connected)return;this.flight6=new Dn(this.transport,this.dtls,this.cipher),this.flight6.handleHandshake(Y)}break;case 20:{await this.waitForReady(()=>!!this.flight6),this.flight6?.handleHandshake(Y);let G=[16,this.options.certificateRequest&&11,this.options.certificateRequest&&15].filter((X)=>typeof X==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight6?.exec(),this.connected=!0,this.onConnect.execute(),FX(this.dtls.sessionId,"dtls connected")}break}}},XK=554869826,Tn=8,Rn=1398035790,n6=20,A2=24,I2=1,z2=2,Mn=6,Pn=50;var w2=((W)=>{return W[W.REQUEST=0]="REQUEST",W[W.INDICATION=16]="INDICATION",W[W.RESPONSE=256]="RESPONSE",W[W.ERROR=272]="ERROR",W})(w2||{}),j2=((W)=>{return W[W.BINDING=1]="BINDING",W[W.SHARED_SECRET=2]="SHARED_SECRET",W[W.ALLOCATE=3]="ALLOCATE",W[W.REFRESH=4]="REFRESH",W[W.SEND=6]="SEND",W[W.DATA=7]="DATA",W[W.CREATE_PERMISSION=8]="CREATE_PERMISSION",W[W.CHANNEL_BIND=9]="CHANNEL_BIND",W})(j2||{});function vV(W){return K2(W).toString("hex").substring(0,W)}function D2(){return K2(12)}var DF=class{queue=[];wait=new p0;put(W){if(this.queue.push(W),this.queue.length===1)this.wait.execute(W)}get(){let W=this.queue.shift();if(!W)return new Promise((Y)=>{this.wait.subscribe((G)=>{this.queue.shift(),Y(G)})});return W}},kO=(W)=>{let Y,G,X=new Promise((Z,V)=>{Y=Z,G=V});X.then(()=>{J.execute(void 0),J.complete()}).catch((Z)=>{J.execute(Z??Error()),J.complete()});let J=new p0;return W(Y,G,J).catch(()=>{}),{awaitable:X,resolve:Y,reject:G}};function kX(W){let[Y]=W,G=sV.default.isV4Format(Y)?I2:z2,X=Buffer.alloc(4);return X.writeUInt8(0,0),X.writeUInt8(G,1),X.writeUInt16BE(W[1],2),Buffer.concat([X,sV.default.toBuffer(Y)])}function Ln(W){if(W.length<4)throw Error("STUN error code is less than 4 bytes");let Y=W.readUInt8(2),G=W.readUInt8(3),X=W.slice(4).toString("utf8");return[Y*100+G,X]}function _X(W){if(W.length<4)throw Error("STUN address length is less than 4 bytes");let Y=W.readUInt8(1),G=W.readUInt16BE(2),X=W.slice(4);switch(Y){case I2:if(X.length!=4)throw Error("STUN address has invalid length for IPv4");return[sV.default.toString(X),G];case z2:if(X.length!=16)throw Error("STUN address has invalid length for IPv6");return[sV.default.toString(X),G];default:throw Error("STUN address has unknown protocol")}}var JK=Buffer.alloc(6);JK.writeUInt16BE(XK>>16,0);JK.writeUInt32BE(XK,2);function C2(W,Y){let G=[...JK,...Y],X=W.slice(0,2);for(let J=2;J<W.length;J++){let Z=W[J]^G[J-2],V=Buffer.alloc(1);V.writeUIntBE(Z,0,1),X=Buffer.concat([X,V])}return X}function gN(W,Y){return _X(C2(W,Y))}function Bn(W){let Y=Buffer.alloc(4);Y.writeUInt16BE(0,0),Y.writeUInt8(Math.floor(W[0]/100),2),Y.writeUInt8(W[0]%100,3);let G=Buffer.from(W[1],"utf8");return Buffer.concat([Y,G])}function uN(W,Y){return C2(kX(W),Y)}var gV=(W)=>{let Y=Buffer.alloc(4);return Y.writeUInt32BE(W,0),Y},uV=(W)=>W.readUInt32BE(0),En=(W)=>{let Y=Buffer.alloc(4);return Y.writeUInt16BE(W,0),Y},$n=(W)=>W.readUInt16BE(0),CF=(W)=>{return new nj(W.toString()).toBuffer()},TF=(W)=>{let Y=new nj(W);return BigInt(Y.toString())},HO=(W)=>Buffer.from(W,"utf8"),NO=(W)=>W.toString("utf8"),qO=(W)=>W,AO=(W)=>W,Fn=(W)=>Buffer.from([]),Sn=(W)=>null,T2=[[1,"MAPPED-ADDRESS",kX,_X],[3,"CHANGE-REQUEST",gV,uV],[4,"SOURCE-ADDRESS",kX,_X],[5,"CHANGED-ADDRESS",kX,_X],[6,"USERNAME",HO,NO],[8,"MESSAGE-INTEGRITY",qO,AO],[9,"ERROR-CODE",Bn,Ln],[12,"CHANNEL-NUMBER",En,$n],[13,"LIFETIME",gV,uV],[18,"XOR-PEER-ADDRESS",uN,gN],[19,"DATA",qO,AO],[20,"REALM",HO,NO],[21,"NONCE",qO,AO],[22,"XOR-RELAYED-ADDRESS",uN,gN],[25,"REQUESTED-TRANSPORT",gV,uV],[32,"XOR-MAPPED-ADDRESS",uN,gN],[36,"PRIORITY",gV,uV],[37,"USE-CANDIDATE",Fn,Sn],[32802,"SOFTWARE",HO,NO],[32808,"FINGERPRINT",gV,uV],[32809,"ICE-CONTROLLED",CF,TF],[32810,"ICE-CONTROLLING",CF,TF],[32811,"RESPONSE-ORIGIN",kX,_X],[32812,"OTHER-ADDRESS",kX,_X]],R2=class{constructor(W=[]){this.attributes=W}getAttributes(){return this.attributes}setAttribute(W,Y){let G=this.attributes.find((X)=>X[0]===W);if(G)G[1]=Y;else this.attributes.push([W,Y]);return this}getAttributeValue(W){let Y=this.attributes.find((G)=>G[0]===W);if(!Y)return;return Y[1]}get attributesKeys(){return this.attributes.map((W)=>W[0])}clear(){this.attributes=[]}},RF=T2.reduce((W,Y)=>{return W[Y[0]]=Y,W},{}),xn=T2.reduce((W,Y)=>{return W[Y[1]]=Y,W},{});function ZK(W,Y){if(W.length<n6)return;let G=W.readUint16BE(2);if(W.length!==n6+G)return;let X=W.readUint16BE(0),J=Buffer.from(W.slice(n6-12,n6)),Z=new R2;for(let U=n6;U<=W.length-4;){let Q=W.readUInt16BE(U),H=W.readUInt16BE(U+2),N=W.slice(U+4,U+4+H),A=4*Math.floor((H+3)/4)-H;if(Object.keys(RF).includes(Q.toString())){let[,z,,w]=RF[Q];if(w.name===gN.name)Z.setAttribute(z,w(N,J));else Z.setAttribute(z,w(N));if(z==="FINGERPRINT"){let D=M2(W.slice(0,U));if(Z.getAttributeValue("FINGERPRINT")!==D)return}else if(z==="MESSAGE-INTEGRITY"){if(Y){let D=kn(W.slice(0,U),Y),T=Z.getAttributeValue("MESSAGE-INTEGRITY");if(!D.equals(T))return}}}U+=4+H+A}let V=Z.getAttributes();return Z.clear(),new p7(X&16111,X&272,J,V)}var p7=class extends R2{constructor(W,Y,G=D2(),X=[]){super(X);this.messageMethod=W,this.messageClass=Y,this.transactionId=G}toJSON(){return this.json}get json(){return{messageMethod:j2[this.messageMethod],messageClass:w2[this.messageClass],attributes:this.attributes}}get transactionIdHex(){return this.transactionId.toString("hex")}get bytes(){let W=Buffer.from([]);for(let G of this.attributesKeys){let X=this.getAttributeValue(G),[J,,Z]=xn[G],V=Z.name===uN.name?Z(X,this.transactionId):Z(X),U=V.length,Q=4*Math.floor((U+3)/4)-U,H=Buffer.alloc(4);H.writeUInt16BE(J,0),H.writeUInt16BE(U,2),W=Buffer.concat([W,H,V,Buffer.alloc(Q,0)])}let Y=Buffer.alloc(8);return Y.writeUInt16BE(this.messageMethod|this.messageClass,0),Y.writeUInt16BE(W.length,2),Y.writeUInt32BE(XK,4),Buffer.concat([Y,this.transactionId,W])}addMessageIntegrity(W){return this.setAttribute("MESSAGE-INTEGRITY",this.messageIntegrity(W)),this}messageIntegrity(W){let Y=VK(this.bytes,this.bytes.length-n6+A2);return Buffer.from(O2("sha1",W).update(Y).digest("hex"),"hex")}addFingerprint(){this.setAttribute("FINGERPRINT",M2(this.bytes))}},VK=(W,Y)=>{let G=Buffer.alloc(W.length);return W.copy(G,0,0,2),G.writeUInt16BE(Y,2),W.copy(G,4,4),G};function M2(W){let Y=VK(W,W.length-n6+Tn);return(Fd(Y)^Rn)>>>0}function kn(W,Y){let G=VK(W,W.length-n6+A2);return Buffer.from(O2("sha1",Y).update(G).digest("hex"),"hex")}function MF(W){let Y=W%4;if(Y===0)return 0;else return 4-Y}var P2=class extends Error{response;addr},L2=class extends P2{constructor(W,Y){super();this.response=W,this.addr=Y}get str(){let W="STUN transaction failed",Y=this.response.getAttributeValue("ERROR-CODE");if(Y){let[G,X]=Y;W+=` (${G} - ${X})`}return W}},_n=class extends P2{get str(){return"STUN transaction timed out"}},IO=M1("werift-ice:packages/ice/src/stun/transaction.ts"),UK=class{constructor(W,Y,G,X){this.request=W,this.addr=Y,this.protocol=G,this.retransmissions=X,this.triesMax=1+(this.retransmissions?this.retransmissions:Mn)}timeoutDelay=Pn;ended=!1;tries=0;triesMax;onResponse=new p0;responseReceived=(W,Y)=>{if(this.onResponse.length>0)if(W.messageClass===256)this.onResponse.execute(W,Y),this.onResponse.complete();else this.onResponse.error(new L2(W,Y))};run=async()=>{try{return this.retry().catch((Y)=>{IO("retry failed",Y)}),await this.onResponse.asPromise()}catch(W){throw W}finally{this.cancel()}};retry=async()=>{while(this.tries<this.triesMax&&!this.ended){if(this.protocol.sendStun(this.request,this.addr).catch((W)=>{IO("send stun failed",W)}),await new Promise((W)=>setTimeout(W,this.timeoutDelay)),this.ended)break;this.timeoutDelay*=2,this.tries++}if(this.tries>=this.triesMax)IO(`retry failed times:${this.tries} maxLimit:${this.triesMax}`),this.onResponse.error(new _n)};cancel(){this.ended=!0}},PF=M1("werift-ice : packages/ice/src/stun/protocol.ts"),LF=class W{static type="stun";type=W.type;transport;transactions={};get transactionsKeys(){return Object.keys(this.transactions)}localCandidate;sentMessage;localIp;onRequestReceived=new p0;onDataReceived=new p0;constructor(){}connectionMade=async(Y,G,X)=>{if(Y)this.transport=await MO.init("udp4",{portRange:G,interfaceAddresses:X});else this.transport=await MO.init("udp6",{portRange:G,interfaceAddresses:X});this.transport.onData=(J,Z)=>{this.datagramReceived(J,Z)}};datagramReceived(Y,G){try{let X=ZK(Y);if(!X){if(this.localCandidate)this.onDataReceived.execute(Y);return}if((X.messageClass===256||X.messageClass===272)&&this.transactionsKeys.includes(X.transactionIdHex))this.transactions[X.transactionIdHex].responseReceived(X,G);else if(X.messageClass===0)this.onRequestReceived.execute(X,G,Y)}catch(X){PF("datagramReceived error",X)}}getExtraInfo(){let{address:Y,port:G}=this.transport.address;return[Y,G]}async sendStun(Y,G){if(this.transport.closed)return;let X=Y.bytes;await this.transport.send(X,G).catch(()=>{PF("sendStun failed",G,Y)})}async sendData(Y,G){if(this.transport.closed)return;await this.transport.send(Y,G)}async request(Y,G,X,J){if(this.transactionsKeys.includes(Y.transactionIdHex))throw Error("already request ed");if(X)Y.addMessageIntegrity(X),Y.addFingerprint();let Z=new UK(Y,G,this,J);this.transactions[Y.transactionIdHex]=Z;try{return await Z.run()}catch(V){throw V}finally{delete this.transactions[Y.transactionIdHex]}}async close(){Object.values(this.transactions).forEach((Y)=>{Y.cancel()}),await this.transport.close(),this.onRequestReceived.complete(),this.onDataReceived.complete()}},a9=M1("werift-ice:packages/ice/src/turn/protocol.ts"),gn=500,un=600,hn=285212672,bn=class W{constructor(Y){this.turn=Y,Y.onData.subscribe((G,X)=>{this.handleStunMessage(G,X)}).disposer(this.disposer)}static type="turn";type=W.type;localCandidate;disposer=new yd;onRequestReceived=new p0;onDataReceived=new p0;handleStunMessage=(Y,G)=>{try{let X=ZK(Y);if(!X){this.onDataReceived.execute(Y);return}if(X.messageClass===256||X.messageClass===272){let J=this.turn.transactions[X.transactionIdHex];if(J)J.responseReceived(X,G)}else if(X.messageClass===0)this.onRequestReceived.execute(X,G,Y)}catch(X){a9("datagramReceived error",X)}};async request(Y,G,X){if(this.turn.transactions[Y.transactionIdHex])throw Error("exist");if(X)Y.addMessageIntegrity(X),Y.addFingerprint();let J=new UK(Y,G,this);this.turn.transactions[Y.transactionIdHex]=J;try{return await J.run()}catch(Z){throw Z}finally{delete this.turn.transactions[Y.transactionIdHex]}}async connectionMade(){}async sendData(Y,G){await this.turn.sendData(Y,G)}async sendStun(Y,G){await this.turn.sendData(Y.bytes,G)}async close(){return this.disposer.dispose(),this.turn.close()}},mn=class W{constructor(Y,G,X,J,Z,V={}){this.server=Y,this.username=G,this.password=X,this.lifetime=J,this.transport=Z,this.options=V,this.channelRefreshTime=this.options.channelRefreshTime??gn}static type="turn";type=W.type;onData=new p0;onRequestReceived=new p0;onDataReceived=new p0;integrityKey;nonce;realm;relayedAddress;mappedAddress;localCandidate;transactions={};refreshHandle;channelNumber=16384;channelByAddr={};addrByChannel={};channelRefreshTime;channelBinding;channelRefreshAt=0;tcpBuffer=Buffer.alloc(0);permissionByAddr={};creatingPermission=Promise.resolve();async connectionMade(){this.transport.onData=(J,Z)=>{this.dataReceived(J,Z)};let Y=new p7(3,0);Y.setAttribute("LIFETIME",this.lifetime).setAttribute("REQUESTED-TRANSPORT",hn);let[G]=await this.requestWithRetry(Y,this.server).catch((J)=>{throw a9("connect error",J),J});this.relayedAddress=G.getAttributeValue("XOR-RELAYED-ADDRESS"),this.mappedAddress=G.getAttributeValue("XOR-MAPPED-ADDRESS");let X=G.getAttributeValue("LIFETIME");a9("connect",this.relayedAddress,this.mappedAddress,{exp:X}),this.refresh(X)}handleChannelData(Y){let[G,X]=s1.Unpack("!HH",Y.slice(0,4)),J=this.addrByChannel[G];if(J){let Z=Y.subarray(4,4+X);this.onData.execute(Z,J)}}handleSTUNMessage(Y,G){try{let X=ZK(Y);if(!X)throw Error("not stun message");if(X.messageClass===256||X.messageClass===272){let J=this.transactions[X.transactionIdHex];if(J)J.responseReceived(X,G)}else if(X.messageClass===0)this.onData.execute(Y,G);if(X.getAttributeValue("DATA")){let J=X.getAttributeValue("DATA");this.onData.execute(J,G)}}catch(X){a9("parse error",Y.toString())}}dataReceived(Y,G){let X=(J,Z)=>{if(J.length>=4&&EF(J))this.handleChannelData(J);else this.handleSTUNMessage(J,Z)};if(this.transport.type==="tcp"){this.tcpBuffer=Buffer.concat([this.tcpBuffer,Y]);while(this.tcpBuffer.length>=4){let[,J]=s9(this.tcpBuffer.subarray(0,4),[2,2]);J+=MF(J);let Z=EF(this.tcpBuffer)?4+J:20+J;if(this.tcpBuffer.length<Z)break;X(this.tcpBuffer.subarray(0,Z),G),this.tcpBuffer=this.tcpBuffer.subarray(Z)}}else X(Y,G)}async send(Y,G){if(this.transport.closed)return;if(this.transport.type==="tcp"){let X=MF(Y.length);await this.transport.send(X>0?Buffer.concat([Y,Buffer.alloc(X)]):Y,G)}else await this.transport.send(Y,G)}async createPermission(Y){let G=new p7(8,0);G.setAttribute("XOR-PEER-ADDRESS",Y).setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce),await this.request(G,this.server).catch((X)=>{throw X})}refresh=(Y)=>{this.refreshHandle=kO(async(G,X,J)=>{let Z=!0;J.once(()=>{Z=!1});while(Z){let V=0.8333333333333334*Y*1000;a9("refresh delay",V,{exp:Y}),await vn(V);let U=new p7(4,0);U.setAttribute("LIFETIME",Y);try{let[Q]=await this.requestWithRetry(U,this.server);Y=Q.getAttributeValue("LIFETIME"),a9("refresh",{exp:Y})}catch(Q){a9("refresh error",Q)}}})};async request(Y,G){if(this.transactions[Y.transactionIdHex])throw Error("exist");if(this.integrityKey)Y.setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce).addMessageIntegrity(this.integrityKey).addFingerprint();let X=new UK(Y,G,this);this.transactions[Y.transactionIdHex]=X;try{return await X.run()}catch(J){throw J}finally{delete this.transactions[Y.transactionIdHex]}}async requestWithRetry(Y,G){let X,J;try{[X,J]=await this.request(Y,G)}catch(Z){if(Z instanceof L2==!1)throw a9("requestWithRetry error",Z),Z;this.server=Z.addr;let[V]=Z.response.getAttributeValue("ERROR-CODE"),U=Z.response.getAttributeValue("NONCE"),Q=Z.response.getAttributeValue("REALM");if((V===401&&Q||V===438&&this.realm)&&U){if(a9("retry with nonce",V),this.nonce=U,V===401)this.realm=Q;this.integrityKey=cn(this.username,this.realm,this.password),Y.transactionId=D2(),[X,J]=await this.request(Y,this.server)}else throw Z}return[X,J]}async sendData(Y,G){let X=await this.getChannel(G).catch((Z)=>{return Error("channelBind error")});if(X instanceof Error){await this.getPermission(G);let Z=new p7(6,16).setAttribute("DATA",Y).setAttribute("XOR-PEER-ADDRESS",G);await this.sendStun(Z,this.server);return}let J=s1.Pack("!HH",[X.number,Y.length]);await this.send(Buffer.concat([Buffer.from(J),Y]),this.server)}async getPermission(Y){if(await this.creatingPermission,!this.permissionByAddr[Y.join(":")])this.creatingPermission=this.createPermission(Y),this.permissionByAddr[Y.join(":")]=!0,await this.creatingPermission.catch((X)=>{throw a9("createPermission error",X),X})}async getChannel(Y){if(this.channelBinding)await this.channelBinding;let G=this.channelByAddr[Y.join(":")];if(!G)this.channelByAddr[Y.join(":")]={number:this.channelNumber++,address:Y},G=this.channelByAddr[Y.join(":")],this.addrByChannel[G.number]=Y,this.channelBinding=this.channelBind(G.number,Y),await this.channelBinding.catch((X)=>{throw a9("channelBind error",X),X}),this.channelRefreshAt=lV(Date.now()/1000)+this.channelRefreshTime,this.channelBinding=void 0,a9("channelBind",G);else if(this.channelRefreshAt<lV(Date.now()/1000))this.channelBinding=this.channelBind(G.number,Y),this.channelRefreshAt=lV(Date.now()/1000)+this.channelRefreshTime,await this.channelBinding.catch((X)=>{throw a9("channelBind error",X),X}),this.channelBinding=void 0,a9("channelBind refresh",G);return G}async channelBind(Y,G){let X=new p7(9,0);X.setAttribute("CHANNEL-NUMBER",Y).setAttribute("XOR-PEER-ADDRESS",G);let[J]=await this.requestWithRetry(X,this.server);if(J.messageMethod!==9)throw Error("should be CHANNEL_BIND")}async sendStun(Y,G){await this.send(Y.bytes,G)}async close(){this.refreshHandle?.resolve?.(),await this.transport.close()}};async function fn({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V}={}){X??=un,V??="udp";let U=V==="udp"?await MO.init("udp4",{portRange:J,interfaceAddresses:Z}):await ud.init(W),Q=new mn(W,Y,G,X,U);return await Q.connectionMade(),Q}async function BF({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V}={}){let U=await fn({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V});return new bn(U)}function cn(W,Y,G){return yn("md5").update(Buffer.from([W,Y,G].join(":"))).digest()}function EF(W){return(W[0]&192)==64}var DY=class W{constructor(Y,G,X,J,Z,V,U,Q,H,N,A,q){this.foundation=Y,this.component=G,this.transport=X,this.priority=J,this.host=Z,this.port=V,this.type=U,this.relatedAddress=Q,this.relatedPort=H,this.tcptype=N,this.generation=A,this.ufrag=q}static fromSdp(Y){let G=Y.split(" ");if(G.length<8)throw Error("SDP does not have enough properties");let X={foundation:G[0],component:Number(G[1]),transport:G[2],priority:Number(G[3]),host:G[4],port:Number(G[5]),type:G[7]};for(let A=8,q=G.length-1;A<q;A+=2)if(G[A]==="raddr")X.related_address=G[A+1];else if(G[A]==="rport")X.related_port=Number(G[A+1]);else if(G[A]==="tcptype")X.tcptype=G[A+1];else if(G[A]==="generation")X.generation=Number(G[A+1]);else if(G[A]==="ufrag")X.ufrag=G[A+1];let{foundation:J,component:Z,transport:V,priority:U,host:Q,port:H,type:N}=X;return new W(J,Z,V,U,Q,H,N,X.related_address,X.related_port,X.tcptype,X.generation,X.ufrag)}canPairWith(Y){let G=$F(this.host),X=$F(Y.host);return this.component===Y.component&&this.transport.toLowerCase()===Y.transport.toLowerCase()&&G===X}toSdp(){let Y=`${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;if(this.relatedAddress)Y+=` raddr ${this.relatedAddress}`;if(this.relatedPort!=null)Y+=` rport ${this.relatedPort}`;if(this.tcptype)Y+=` tcptype ${this.tcptype}`;if(this.generation!=null)Y+=` generation ${this.generation}`;if(this.ufrag!=null)Y+=` ufrag ${this.ufrag}`;return Y}};function _O(W,Y,G){let X=`${W}|${Y}|${G}`;return pn("md5").update(X,"ascii").digest("hex").slice(7)}function hN(W,Y=65535){let X=0;if(W==="host")X=126;else if(W==="prflx")X=110;else if(W==="srflx")X=100;else X=0;return 16777216*X+256*Y+255}var dn=class{cache=new Map;mdnsInstance=B2.default();constructor(){this.mdnsInstance.setMaxListeners(50)}lookup(W){return new Promise((Y,G)=>{let X=()=>{this.mdnsInstance.removeListener("response",Z),clearTimeout(J)},J=setTimeout(()=>{X(),G(Error("No mDNS response"))},1e4),Z=(V)=>{let U=V.answers?.[0];if(U?.type!=="A")return;if(U.name!==W)return;X(),Y(U.data)};this.mdnsInstance.on("response",Z),this.mdnsInstance.query(W,"A")})}close(){this.mdnsInstance.destroy()}},nn=M1("werift-ice : packages/ice/src/ice.ts : log"),SF=class{constructor(W,Y,G){this.protocol=W,this.remoteCandidate=Y,this.iceControlling=G}id=on().toString();handle;nominated=!1;remoteNominated=!1;_state=0;get state(){return this._state}packetsSent=0;packetsReceived=0;bytesSent=0;bytesReceived=0;rtt;totalRoundTripTime=0;roundTripTimeMeasurements=0;toJSON(){return this.json}get json(){return{protocol:this.protocol.type,localCandidate:this.localCandidate.toSdp(),remoteCandidate:this.remoteCandidate.toSdp()}}updateState(W){this._state=W}get localCandidate(){if(!this.protocol.localCandidate)throw Error("localCandidate not exist");return this.protocol.localCandidate}get remoteAddr(){return[this.remoteCandidate.host,this.remoteCandidate.port]}get component(){return this.localCandidate.component}get priority(){return vO(this.localCandidate,this.remoteCandidate,this.iceControlling)}get foundation(){return this.localCandidate.foundation}},xF=1,$N=2,rn=5,kF=6;var an={useIpv4:!0,useIpv6:!0};function _F(W){if(!["host","relay","srflx"].includes(W.type))throw Error(`Unexpected candidate type "${W.type}"`);return W}function sn(W,Y){return W.sort((G,X)=>vO(G.localCandidate,G.remoteCandidate,Y)-vO(X.localCandidate,X.remoteCandidate,Y)).reverse()}function vO(W,Y,G){let X=G&&W.priority||Y.priority,J=G&&Y.priority||W.priority;return 1*Math.min(X,J)+2*Math.max(X,J)+(X>J?1:0)}async function tn(W,Y){let G=new p7(1,0);try{let[X]=await W.request(G,Y),J=W.localCandidate;if(!J)throw Error("not exist");return new DY(_O("srflx","udp",J.host),J.component,J.transport,hN("srflx"),X.getAttributeValue("XOR-MAPPED-ADDRESS")[0],X.getAttributeValue("XOR-MAPPED-ADDRESS")[1],"srflx",J.host,J.port)}catch(X){nn("error serverReflexiveCandidate",X)}}function yF(W){if(W&&Number.isNaN(W[1]))return[W[0],443];return W}var en=M1("werift-ice : packages/ice/src/utils.ts");function Wi(W){return iN(W.family)===4&&W.address?.startsWith("169.254.")||iN(W.family)===6&&W.address?.startsWith("fe80::")}function vF(W,{useLinkLocalAddress:Y}={}){let G=["ipsec","tun","utun","tap"],X=["vmnet","veth"],J=E2.networkInterfaces();en(J);let Z=Object.keys(J).map((V)=>{for(let Q of[...G,...X])if(V.startsWith(Q))return{nic:V,addresses:[]};let U=J[V].filter((Q)=>iN(Q.family)===W&&!$2.default.isLoopback(Q.address)&&(Y?!0:!Wi(Q)));return{nic:V,addresses:U.map((Q)=>Q.address)}}).filter((V)=>!!V);return Z.sort((V,U)=>V.nic.localeCompare(U.nic)),Object.values(Z).flatMap((V)=>V.addresses)}function Yi(W,Y,G={}){let X=[];if(W)X.push(...vF(4,G));if(Y)X.push(...vF(6,G));return X}var W8=M1("werift-ice : packages/ice/src/ice.ts : log"),Gi=class{constructor(W,Y){this._iceControlling=W,this.options={...an,...Y};let{stunServer:G,turnServer:X}=this.options;this.stunServer=yF(G)??["stun.l.google.com",19302],this.turnServer=yF(X),this.restart(),W8("new Connection",this.options)}localUsername=vV(4);localPassword=vV(22);remoteIsLite=!1;remotePassword="";remoteUsername="";checkList=[];localCandidates=[];stunServer;turnServer;options;remoteCandidatesEnd=!1;localCandidatesEnd=!1;generation=-1;userHistory={};tieBreaker=BigInt(new PN(ln(64)).toString());state="new";lookup;_remoteCandidates=[];nominated;nominating=!1;checkListDone=!1;checkListState=new DF;earlyChecks=[];earlyChecksDone=!1;localCandidatesStart=!1;protocols=[];queryConsentHandle;onData=new p0;stateChanged=new p0;onIceCandidate=new p0;get iceControlling(){return this._iceControlling}set iceControlling(W){if(this.generation>0||this.nominated)return;this._iceControlling=W;for(let Y of this.checkList)Y.iceControlling=W}async restart(){if(this.generation++,this.localUsername=vV(4),this.localPassword=vV(22),this.options.localPasswordPrefix)this.localPassword=this.options.localPasswordPrefix+this.localPassword.slice(this.options.localPasswordPrefix.length);this.userHistory[this.localUsername]=this.localPassword,this.remoteUsername="",this.remotePassword="",this.localCandidates=[],this._remoteCandidates=[],this.remoteCandidatesEnd=!1,this.localCandidatesEnd=!1,this.state="new",this.lookup?.close?.(),this.lookup=void 0,this.nominated=void 0,this.nominating=!1,this.checkList=[],this.checkListDone=!1,this.checkListState=new DF,this.earlyChecks=[],this.earlyChecksDone=!1,this.localCandidatesStart=!1;for(let W of this.protocols)if(W.localCandidate)W.localCandidate.generation=this.generation,W.localCandidate.ufrag=this.localUsername;this.queryConsentHandle?.resolve?.(),this.queryConsentHandle=void 0}resetNominatedPair(){W8("resetNominatedPair"),this.nominated=void 0,this.nominating=!1}setRemoteParams({iceLite:W,usernameFragment:Y,password:G}){W8("setRemoteParams",{iceLite:W,usernameFragment:Y,password:G}),this.remoteIsLite=W,this.remoteUsername=Y,this.remotePassword=G}async gatherCandidates(){if(!this.localCandidatesStart){this.localCandidatesStart=!0;let W=Yi(this.options.useIpv4,this.options.useIpv6,{useLinkLocalAddress:this.options.useLinkLocalAddress}),{interfaceAddresses:Y}=this.options;if(Y){let X=W.filter((J)=>Object.values(Y).includes(J));if(X.length)W=X}if(this.options.additionalHostAddresses)W=Array.from(new Set([...this.options.additionalHostAddresses,...W]));let G=this.getCandidatePromises(W,5);await Promise.allSettled(G),this.localCandidatesEnd=!0}this.setState("completed")}appendLocalCandidate(W){this.localCandidates.push(W),this.onIceCandidate.execute(W)}ensureProtocol(W){W.onRequestReceived.subscribe((Y,G,X)=>{if(Y.messageMethod!==1){this.respondError(Y,G,W,[400,"Bad Request"]);return}let J=Y.getAttributeValue("USERNAME"),{remoteUsername:Z}=gF(J),V=this.userHistory[Z]??this.localPassword,{iceControlling:U}=this;if(U&&Y.attributesKeys.includes("ICE-CONTROLLING"))if(this.tieBreaker>=Y.getAttributeValue("ICE-CONTROLLING")){this.respondError(Y,G,W,[487,"Role Conflict"]);return}else this.switchRole(!1);else if(!U&&Y.attributesKeys.includes("ICE-CONTROLLED"))if(this.tieBreaker<Y.getAttributeValue("ICE-CONTROLLED"))this.respondError(Y,G,W,[487,"Role Conflict"]);else{this.switchRole(!0);return}if(this.options.filterStunResponse&&!this.options.filterStunResponse(Y,G,W))return;let Q=new p7(1,256,Y.transactionId);if(Q.setAttribute("XOR-MAPPED-ADDRESS",G).addMessageIntegrity(Buffer.from(V,"utf8")).addFingerprint(),W.sendStun(Q,G).catch((H)=>{W8("sendStun error",H)}),this.checkList.length===0&&!this.earlyChecksDone)this.earlyChecks.push([Y,G,W]);else this.checkIncoming(Y,G,W)}),W.onDataReceived.subscribe((Y)=>{try{let G=this.nominated;if(G&&G.protocol===W)G.packetsReceived++,G.bytesReceived+=Y.length;this.onData.execute(Y)}catch(G){W8("dataReceived",G)}})}getCandidatePromises(W,Y=5){let G=[];W=W.filter((Q)=>{if(this.protocols.find((H)=>H.localIp===Q))return!1;return!0});let X=W.map(async(Q)=>{let H=new LF;this.ensureProtocol(H);try{await H.connectionMade(FF(Q),this.options.portRange,this.options.interfaceAddresses),H.localIp=Q,this.protocols.push(H),W8("protocol",H.localIp);let N=[Q,H.getExtraInfo()[1]];return H.localCandidate=new DY(_O("host","udp",N[0]),1,"udp",hN("host"),N[0],N[1],"host",void 0,void 0,void 0,this.generation,this.localUsername),this.pairLocalProtocol(H),this.appendLocalCandidate(H.localCandidate),H}catch(N){W8("error protocol STUN",N)}});G.push(...X.map((Q)=>Q.then((H)=>H?.localCandidate)));let{stunServer:J,turnServer:Z}=this;if(J){let Q=X.map(async(H)=>{let N=await H;if(!N)return;return new Promise(async(q,z)=>{let w=setTimeout(z,Y*1000);if(N.localCandidate?.host&&FF(N.localCandidate?.host)){let D=await tn(N,J).catch((T)=>{W8("error",T)});if(D)this.appendLocalCandidate(D);clearTimeout(w),q(D)}else clearTimeout(w),q()}).catch((q)=>{W8("query STUN server",q)})});G.push(...Q)}let{turnUsername:V,turnPassword:U}=this.options;if(Z&&V&&U){let Q=(async()=>{let H=await BF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:this.options.turnTransport==="tcp"?"tcp":"udp"}).catch(async(q)=>{if(this.options.turnTransport!=="tcp")return await BF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:"tcp"});else throw q});this.ensureProtocol(H),this.protocols.push(H);let N=H.turn.relayedAddress,A=H.turn.mappedAddress;return W8("turn candidateAddress",N),H.localCandidate=new DY(_O("relay","udp",N[0]),1,"udp",hN("relay"),N[0],N[1],"relay",A[0],A[1],void 0,this.generation,this.localUsername),this.appendLocalCandidate(H.localCandidate),H.localCandidate})().catch((H)=>{W8("query TURN server",H)});if(this.options.forceTurn)G=[];G.push(Q)}return G}async connect(){if(W8("start connect ice"),!this.localCandidatesEnd){if(!this.localCandidatesStart)throw Error("Local candidates gathering was not performed")}if(!this.remoteUsername||!this.remotePassword)throw Error("Remote username or password is missing");for(let Y of this.remoteCandidates)this.pairRemoteCandidate(Y);this.sortCheckList(),this.unfreezeInitial(),W8("earlyChecks",this.localPassword,this.earlyChecks.length);for(let Y of this.earlyChecks)this.checkIncoming(...Y);this.earlyChecks=[],this.earlyChecksDone=!0;for(;;){if(this.state==="closed")break;if(!this.schedulingChecks())break;await yO.setTimeout(20)}let W=$N;while(this.checkList.length>0&&W===$N)W=await this.checkListState.get(),W8("checkListState",W);for(let Y of this.checkList)Y.handle?.resolve?.();if(W!==xF)throw Error("ICE negotiation failed");this.queryConsent(),this.setState("connected")}unfreezeInitial(){let[W]=this.checkList;if(!W)return;if(W.state===0)W.updateState(1);let Y=new Set(W.localCandidate.foundation);for(let G of this.checkList)if(G.component===W.component&&!Y.has(G.localCandidate.foundation)&&G.state===0)G.updateState(1),Y.add(G.localCandidate.foundation)}schedulingChecks(){{let W=this.checkList.filter((Y)=>{if(this.options.forceTurn&&Y.protocol.type===LF.type)return!1;return!0}).find((Y)=>Y.state===1);if(W)return W.handle=this.checkStart(W),!0}{let W=this.checkList.find((Y)=>Y.state===0);if(W)return W.handle=this.checkStart(W),!0}if(!this.remoteCandidatesEnd)return!this.checkListDone;return!1}queryConsent=()=>{if(this.queryConsentHandle)this.queryConsentHandle.resolve();this.queryConsentHandle=kO(async(W,Y,G)=>{let X=0,J=!1,Z=new AbortController;G.once(()=>{J=!0,X+=kF,Z.abort(),this.queryConsentHandle=void 0});let{localUsername:V,remoteUsername:U,iceControlling:Q}=this;try{while(this.state!=="closed"&&!J){await yO.setTimeout(rn*(0.8+0.4*Math.random())*1000,void 0,{signal:Z.signal});let H=this.nominated;if(!H||J)break;let N=this.buildRequest({nominate:!1,localUsername:V,remoteUsername:U,iceControlling:Q});try{if(await H.protocol.request(N,H.remoteAddr,Buffer.from(this.remotePassword,"utf8"),0),X=0,this.state==="disconnected")this.setState("connected")}catch(A){if(H.id===this.nominated?.id){W8("no stun response"),X++,this.setState("disconnected");break}}if(X>=kF){W8("Consent to send expired"),this.queryConsentHandle=void 0,this.setState("closed");break}}}catch(H){}})};async close(){if(this.setState("closed"),this.queryConsentHandle?.resolve?.(),this.checkList&&!this.checkListDone)this.checkListState.put(new Promise((W)=>{W($N)}));this.nominated=void 0;for(let W of this.protocols)if(W.close)await W.close();this.protocols=[],this.localCandidates=[],this.lookup?.close?.(),this.lookup=void 0}setState(W){this.state=W,this.stateChanged.execute(W)}async addRemoteCandidate(W){if(!W){this.remoteCandidatesEnd=!0;return}if(W.host.includes(".local"))try{if(!this.lookup)this.lookup=new dn;let Y=await this.lookup.lookup(W.host);W.host=Y}catch(Y){return}try{_F(W)}catch(Y){return}W8("addRemoteCandidate",W),this._remoteCandidates.push(W),this.pairRemoteCandidate(W),this.sortCheckList()}send=async(W)=>{let Y=this.nominated;if(Y)await Y.protocol.sendData(W,Y.remoteAddr),Y.packetsSent++,Y.bytesSent+=W.length;else return};getDefaultCandidate(){let W=this.localCandidates.sort((G,X)=>G.priority-X.priority),[Y]=W;return Y}set remoteCandidates(W){if(this.remoteCandidatesEnd)throw Error("Cannot set remote candidates after end-of-candidates.");this._remoteCandidates=[];for(let Y of W){try{_F(Y)}catch(G){continue}this._remoteCandidates.push(Y)}this.remoteCandidatesEnd=!0}get remoteCandidates(){return this._remoteCandidates}get candidatePairs(){return this.checkList}sortCheckList(){sn(this.checkList,this.iceControlling)}findPair(W,Y){return this.checkList.find((X)=>bN.default(X.protocol,W)&&bN.default(X.remoteCandidate,Y))}switchRole(W){W8("switch role",W),this.iceControlling=W,this.sortCheckList()}checkComplete(W){if(W.handle=void 0,W.state===3){if(W.nominated&&(W.remoteCandidate.generation!=null?W.remoteCandidate.generation===this.generation:!0)&&this.nominated==null){W8("nominated",W.toJSON()),this.nominated=W,this.nominating=!1;for(let Y of this.checkList)if(Y.component===W.component&&[1,0].includes(Y.state))Y.updateState(4)}if(this.nominated){if(!this.checkListDone)W8("ICE completed"),this.checkListState.put(new Promise((Y)=>Y(xF))),this.checkListDone=!0;return}W8("not completed",W.toJSON());for(let Y of this.checkList)if(Y.localCandidate.foundation===W.localCandidate.foundation&&Y.state===0)Y.updateState(1)}{let Y=[3,4];if(this.checkList.find(({state:G})=>!Y.includes(G)))return}if(!this.iceControlling){if(this.checkList.find(({state:G})=>G===3))return}if(!this.checkListDone)W8("ICE failed"),this.checkListState.put(new Promise((Y)=>{Y($N)}))}checkStart=(W)=>kO(async(Y)=>{W8("check start",W.toJSON()),W.updateState(2);let G={},{remotePassword:X,remoteUsername:J,generation:Z}=this,V=W.localCandidate.ufrag??this.localUsername,U=this.iceControlling&&!this.remoteIsLite,Q=this.buildRequest({nominate:U,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling}),H=performance.now();try{let[N,A]=await W.protocol.request(Q,W.remoteAddr,Buffer.from(X,"utf8"),4),z=(performance.now()-H)/1000;W.rtt=z,W.totalRoundTripTime+=z,W.roundTripTimeMeasurements++,W8("response received",Q.toJSON(),N.toJSON(),A,{localUsername:V,remoteUsername:J,remotePassword:X,generation:Z,rtt:z}),G.response=N,G.addr=A}catch(N){let A=N;if(W8("failure case",Q.toJSON(),A.response?JSON.stringify(A.response.toJSON(),null,2):N,{localUsername:V,remoteUsername:J,remotePassword:X,generation:Z},W.remoteAddr),A.response?.getAttributeValue("ERROR-CODE")[0]===487){if(Q.attributesKeys.includes("ICE-CONTROLLED"))this.switchRole(!0);else if(Q.attributesKeys.includes("ICE-CONTROLLING"))this.switchRole(!1);await this.checkStart(W).awaitable,Y();return}if(A.response?.getAttributeValue("ERROR-CODE")[0]===401){W8("retry 401",W.toJSON()),await this.checkStart(W).awaitable,Y();return}else{W8("checkStart CandidatePairState.FAILED",W.toJSON()),W.updateState(4),this.checkComplete(W),Y();return}}if(!bN.default(G.addr,W.remoteAddr)){W.updateState(4),this.checkComplete(W),Y();return}if(U||W.remoteNominated)W.nominated=!0;else if(this.iceControlling&&!this.nominating){this.nominating=!0;let N=this.buildRequest({nominate:!0,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling});try{await W.protocol.request(N,W.remoteAddr,Buffer.from(this.remotePassword,"utf8"))}catch(A){W.updateState(4),this.checkComplete(W);return}W.nominated=!0}W.updateState(3),this.checkComplete(W),Y()});addPair(W){this.checkList.push(W),this.sortCheckList()}checkIncoming(W,Y,G){let X=W.getAttributeValue("USERNAME"),{remoteUsername:J}=gF(X),Z,[V,U]=Y;for(let H of this.remoteCandidates)if(H.host===V&&H.port===U){Z=H;break}if(!Z)Z=new DY(vV(10),1,"udp",W.getAttributeValue("PRIORITY"),V,U,"prflx",void 0,void 0,void 0,void 0,void 0),this._remoteCandidates.push(Z);let Q=this.findPair(G,Z);if(!Q)Q=new SF(G,Z,this.iceControlling),Q.updateState(1),this.addPair(Q);if(Q.localCandidate.ufrag=J,W8("Triggered Checks",W.toJSON(),Q.toJSON(),{localUsername:this.localUsername,remoteUsername:this.remoteUsername,localPassword:this.localPassword,remotePassword:this.remotePassword,generation:this.generation}),[1,4].includes(Q.state))Q.handle=this.checkStart(Q);if(W.attributesKeys.includes("USE-CANDIDATE")&&!this.iceControlling){if(Q.remoteNominated=!0,Q.state===3)Q.nominated=!0,this.checkComplete(Q)}}tryPair(W,Y){if(W.localCandidate?.canPairWith(Y)&&!this.findPair(W,Y)){let G=new SF(W,Y,this.iceControlling);if(this.options.filterCandidatePair&&!this.options.filterCandidatePair(G))return;G.updateState(1),this.addPair(G)}}pairLocalProtocol(W){for(let Y of this.remoteCandidates)this.tryPair(W,Y)}pairRemoteCandidate=(W)=>{for(let Y of this.protocols)this.tryPair(Y,W)};buildRequest({nominate:W,remoteUsername:Y,localUsername:G,iceControlling:X}){let J=Xi({remoteUsername:Y,localUsername:G}),Z=new p7(1,0);if(Z.setAttribute("USERNAME",J).setAttribute("PRIORITY",hN("prflx")),X){if(Z.setAttribute("ICE-CONTROLLING",this.tieBreaker),W)Z.setAttribute("USE-CANDIDATE",null)}else Z.setAttribute("ICE-CONTROLLED",this.tieBreaker);return Z}respondError(W,Y,G,X){let J=new p7(W.messageMethod,272,W.transactionId);J.setAttribute("ERROR-CODE",X).addMessageIntegrity(Buffer.from(this.localPassword,"utf8")).addFingerprint(),G.sendStun(J,Y).catch((Z)=>{W8("sendStun error",Z)})}},Xi=({remoteUsername:W,localUsername:Y})=>{return`${W}:${Y}`},gF=(W)=>{let[Y,G]=W.split(":");return{remoteUsername:Y,localUsername:G}};function uF(W){return W.map((Y,G)=>[G,Y])}function m4(W,Y){let G=W.split(Y);return[G[0],G.slice(1).join(Y)]}var QK=class extends Ji{addEventListener=(W,Y)=>{this.addListener(W,Y)};removeEventListener=(W,Y)=>{this.removeListener(W,Y)}},Zi=M1("werift:packages/webrtc/src/dataChannel.ts");function Vi(W){return Buffer.isBuffer(W)?W.length:Buffer.byteLength(W)}var F2=class extends QK{constructor(W,Y,G=!0){super();if(this.sctp=W,this.parameters=Y,this.sendOpen=G,this.id=this.parameters.id,Y.negotiated){if(this.id==null||this.id<0||this.id>65534)throw Error("ID must be in range 0-65534 if data channel is negotiated out-of-band");this.sctp.dataChannelAddNegotiated(this)}else if(G)this.sendOpen=!1,this.sctp.dataChannelOpen(this)}stateChange=new p0;stateChanged=new p0;onMessage=new p0;error=new p0;bufferedAmountLow=new p0;onopen;onclose;onclosing;onmessage;onerror;isCreatedByRemote=!1;id;readyState="connecting";bufferedAmount=0;_bufferedAmountLowThreshold=0;messagesSent=0;bytesSent=0;messagesReceived=0;bytesReceived=0;get ordered(){return this.parameters.ordered}get maxRetransmits(){return this.parameters.maxRetransmits}get maxPacketLifeTime(){return this.parameters.maxPacketLifeTime}get label(){return this.parameters.label}get protocol(){return this.parameters.protocol}get negotiated(){return this.parameters.negotiated}get bufferedAmountLowThreshold(){return this._bufferedAmountLowThreshold}set bufferedAmountLowThreshold(W){if(W<0||W>4294967295)throw Error("bufferedAmountLowThreshold must be in range 0 - 4294967295");this._bufferedAmountLowThreshold=W}setId(W){this.id=W}setReadyState(W){if(W!==this.readyState){switch(this.readyState=W,this.stateChange.execute(W),this.stateChanged.execute(W),W){case"open":if(this.onopen)this.onopen();this.emit("open");break;case"closed":if(this.onclose)this.onclose();this.emit("close");break;case"closing":if(this.onclosing)this.onclosing();break}Zi("change state",W)}}addBufferedAmount(W){let Y=this.bufferedAmount>this.bufferedAmountLowThreshold&&this.bufferedAmount+W<=this.bufferedAmountLowThreshold;if(this.bufferedAmount+=W,Y)this.bufferedAmountLow.execute(),this.emit("bufferedamountlow")}send(W){let Y=this.sctp.datachannelSend(this,W);this.messagesSent++,this.bytesSent+=Y}close(){this.sctp.dataChannelClose(this)}},S2=class{label="";maxPacketLifeTime;maxRetransmits;ordered=!0;protocol="";negotiated=!1;id;constructor(W={}){Object.assign(this,W)}};var wq=()=>({type:"nack"}),QU=()=>({type:"nack",parameter:"pli"}),jq=()=>({type:"goog-remb"}),Ui=()=>({type:"transport-cc"}),EY=class{payloadType;mimeType;clockRate;channels;rtcpFeedback=[];parameters;direction="all";constructor(W){Object.assign(this,W)}get name(){return this.mimeType.split("/")[1]}get contentType(){return this.mimeType.split("/")[0]}get str(){let W=`${this.name}/${this.clockRate}`;if(this.channels===2)W+="/2";return W}},Qi=class{id;uri;constructor(W){Object.assign(this,W)}};var Hi=class{type;parameter;constructor(W={}){Object.assign(this,W)}},Ni=class{ssrc;constructor(W={}){Object.assign(this,W)}},qi=class{ssrc;payloadType;rtx;constructor(W){Object.assign(this,W)}},x2=class{rid;direction;constructor(W){Object.assign(this,W)}},Ai=(W={})=>new EY({mimeType:"video/h264",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],parameters:"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1",...W}),k2=(W={})=>new EY({mimeType:"video/VP8",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),Ii=(W={})=>new EY({mimeType:"video/VP9",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),zi=(W={})=>new EY({mimeType:"video/AV1X",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),_2=(W={})=>new EY({mimeType:"audio/OPUS",clockRate:48000,channels:2,...W}),y2=(W={})=>new EY({mimeType:"audio/PCMU",clockRate:8000,channels:1,payloadType:0,...W}),v2=[zi(),Ii(),k2(),Ai(),_2(),y2()].map((W)=>W.mimeType),eq0=v2.filter((W)=>W.toLowerCase().startsWith("video/")),WA0=v2.filter((W)=>W.toLowerCase().startsWith("audio/"));var hF=2,bF=3,Ki=0,SN=50,mF=51,fF=53,Di=56,Ci=57,Ti="0.0.0.0",cF=9,gO={auto:"actpass",client:"active",server:"passive"},pF=Object.keys(gO).reduce((W,Y)=>{let G=gO[Y];return W[G]=Y,W},{}),Ri=["apt","max-fr","max-fs","maxplaybackrate","minptime","stereo","useinbandfec"],g2=["cname","msid","mslabel","label"],lF={SRTP_AES128_CM_HMAC_SHA1_80:zq,SRTP_AEAD_AES_128_GCM:VU},mN=["sendonly","sendrecv"],Mi=["sendrecv","recvonly"],Pi=class extends Map{constructor(W){super();if(W)for(let Y of W)this.set(Y.id,Y)}};function Z8(W,...Y){let G=Y.filter((X)=>X!==void 0);return`${W}_${G.join("_")}`}function $Y(){return performance.now()}var Li=class{constructor(W,Y,G,X,J){if(this.kind=W,this.receiver=G,this.sender=X,this._direction=J,Y)this.setDtlsTransport(Y)}id=Oi().toString();onTrack=new p0;mid;mLineIndex;usedForSender=!1;_currentDirection;offerDirection;_codecs=[];set codecs(W){this._codecs=W}get codecs(){return this._codecs}headerExtensions=[];options={};stopping=!1;stopped=!1;get dtlsTransport(){return this.receiver.dtlsTransport}get direction(){return this._direction}setDirection(W){if(this._direction=W,mN.includes(this._currentDirection??""))this.usedForSender=!0}get currentDirection(){return this._currentDirection}setCurrentDirection(W){this._currentDirection=W}setDtlsTransport(W){this.receiver.setDtlsTransport(W),this.sender.setDtlsTransport(W)}get msid(){return`${this.sender.streamId} ${this.sender.trackId}`}addTrack(W){if(this.receiver.addTrack(W))this.onTrack.execute(W,this)}stop(){if(this.stopping)return;this.stopping=!0}getPayloadType(W){return this.codecs.find((Y)=>Y.mimeType.toLowerCase().includes(W.toLowerCase()))?.payloadType}getCodecStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id);for(let X of this.codecs){let J={type:"codec",id:Z8("codec",X.payloadType,G),timestamp:W,payloadType:X.payloadType,transportId:G,mimeType:X.mimeType,clockRate:X.clockRate,channels:X.channels,sdpFmtpLine:X.parameters};Y.push(J)}return Y}},Bi="inactive",u2="sendonly",h2="recvonly",b2="sendrecv",wO=[Bi,u2,h2,b2],uO=class extends QK{uuid=m2().toString();streamId;remote=!1;label;kind;id;ssrc;rid;header;codec;enabled=!0;onReceiveRtp=new p0;onReceiveRtcp=new p0;onSourceChanged=new p0;stopped=!1;muted=!0;constructor(W){super();Object.assign(this,W),this.onReceiveRtp.subscribe((Y)=>{this.muted=!1,this.header=Y.header}),this.label=`${this.remote?"remote":"local"} ${this.kind}`}stop=()=>{this.stopped=!0,this.muted=!0,this.onReceiveRtp.complete(),this.emit("ended")};writeRtp=(W)=>{if(this.remote)throw Error("this is remoteTrack");if(this.stopped)return;let Y=Buffer.isBuffer(W)?t6.deSerialize(W):W;Y.header.payloadType=this.codec?.payloadType??Y.header.payloadType,this.onReceiveRtp.execute(Y)}},Ei=class{id;tracks=[];constructor(W){if(Array.isArray(W))this.tracks=W;else Object.assign(this,W);this.id??=m2().toString()}addTrack(W){W.streamId=this.id,this.tracks.push(W)}getTracks(){return this.tracks}getAudioTracks(){return this.tracks.filter((W)=>W.kind==="audio")}getVideoTracks(){return this.tracks.filter((W)=>W.kind==="video")}},$i=M1("werift:packages/webrtc/src/utils.ts");function f2(W,Y){let G=(Z)=>Z.toUpperCase(),X=(Z)=>Z.match(/(.{2})/g).join(":"),J=ji(Y).update(W).digest("hex");return X(G(J))}var Fi={sha1:"sha1","sha-1":"sha1",sha224:"sha224","sha-224":"sha224",sha256:"sha256","sha-256":"sha256",sha384:"sha384","sha-384":"sha384",sha512:"sha512","sha-512":"sha512"};function c2(W){return Fi[W.trim().toLowerCase()]}function hO(W){return W.replace(/[^0-9a-f]/gi,"").toLowerCase()}function Si(W){let Y=W[0];return Y>19&&Y<64}var p2=(W,Y)=>wO[wO.indexOf(W)&wO.indexOf(Y)];function xi(W){if(W==="sendonly")return"recvonly";if(W==="recvonly")return"sendonly";return W}var l2=Date.now,ki=BigInt(Date.now())*1000n-process.hrtime.bigint()/1000n,_i=()=>{return ki+process.hrtime.bigint()/1000n},Vq=()=>Date.now()/1000,yi=()=>{let Y=(FN.timeOrigin+FN.now()-Date.UTC(1900,0,1))/1000,[G,X]=Y.toString().split(".").map(Number);return E8([4,4],[G,X]).readBigUInt64BE()},d2=(W)=>{let Y=E8([8],[W]),[,G,X]=s9(Y,[2,2,2,2]);return E8([2,2],[G,X]).readUInt32BE()};function vi(W){let Y=(U)=>{if(!U)return;let[Q,H]=U.split(":");return[Q,Number.parseInt(H)]},G=Y(W.find(({urls:U})=>U.includes("stun:"))?.urls.slice(5)),X=Y(W.find(({urls:U})=>U.includes("turn:"))?.urls.slice(5)),{credential:J,username:Z}=W.find(({urls:U})=>U.includes("turn:"))||{},V={stunServer:G,turnServer:X,turnUsername:Z,turnPassword:J};return $i("iceOptions",V),V}var UA0=aN.createSelfSignedCertificateWithKey;var gi=(W,Y)=>{if(!W||typeof W!=="object")if(Y!==null&&typeof Y==="object")return Y;else return W;if(!Y||typeof Y!=="object"){if(Y==null)return W;return Y}for(let G in Y)if(Object.prototype.hasOwnProperty.call(Y,G)){let X=Y[G];if(X!=null)W[G]=X}return W},ui=M1("werift:packages/webrtc/src/media/receiver/nack.ts"),dF=150,hi=class{constructor(W){this.receiver=W}newEstSeqNum=0;_lost={};nackLoop;onPacketLost=new p0;mediaSourceSsrc;retryCount=10;closed=!1;get lostSeqNumbers(){return Object.keys(this._lost).map(Number).sort()}getLost(W){return this._lost[W]}setLost(W,Y){if(this._lost[W]=Y,this.nackLoop||this.closed)return;this.nackLoop=setInterval(async()=>{try{if(await this.sendNack(),!Object.keys(this._lost).length)clearInterval(this.nackLoop),this.nackLoop=void 0}catch(G){ui("failed to send nack",G)}},5)}removeLost(W){delete this._lost[W]}addPacket(W){let{sequenceNumber:Y,ssrc:G}=W.header;if(this.mediaSourceSsrc=G,this.newEstSeqNum===0){this.newEstSeqNum=Y;return}if(this.getLost(Y)){this.removeLost(Y);return}if(Y===T9(this.newEstSeqNum,1))this.newEstSeqNum=Y;else if(Y>T9(this.newEstSeqNum,1)){for(let X=T9(this.newEstSeqNum,1);X<Y;X=T9(X,1))this.setLost(X,1);this.newEstSeqNum=Y,this.pruneLost()}}pruneLost(){if(this.lostSeqNumbers.length>dF)this._lost=Object.entries(this._lost).slice(-dF).reduce((W,[Y,G])=>{return W[Y]=G,W},{})}close(){this.closed=!0,clearInterval(this.nackLoop),this._lost={}}updateRetryCount(){this.lostSeqNumbers.forEach((W)=>{if(this._lost[W]++>this.retryCount)return this.removeLost(W),W})}sendNack=()=>new Promise((W,Y)=>{if(this.lostSeqNumbers.length>0&&this.mediaSourceSsrc){let G=new Xq({senderSsrc:this.receiver.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,lost:this.lostSeqNumbers}),X=new hX({feedback:G});this.receiver.dtlsTransport.sendRtcp([X]).then(W).catch(Y),this.updateRetryCount(),this.onPacketLost.execute(G)}})},mi=M1("werift:packages/webrtc/media/receiver/receiverTwcc"),fi=class{constructor(W,Y,G){this.dtlsTransport=W,this.rtcpSsrc=Y,this.mediaSourceSsrc=G,this.runTWCC()}extensionInfo={};twccRunning=!1;fbPktCount=0;lastTimestamp;handleTWCC(W){if(this.extensionInfo[W]={tsn:W,timestamp:_i()},Object.keys(this.extensionInfo).length>10)this.sendTWCC()}async runTWCC(){while(this.twccRunning)this.sendTWCC(),await bi(100)}sendTWCC(){if(Object.keys(this.extensionInfo).length===0)return;let W=Object.values(this.extensionInfo).sort((N,A)=>N.tsn-A.tsn),Y=W[0].tsn,G=W.slice(-1)[0].tsn,X=[],J=W[0].tsn,Z=T9(G-Y,1),V,U,Q=[];for(let N=Y;N<=G;N++){let A=this.extensionInfo[N]?.timestamp;if(A){if(!this.lastTimestamp)this.lastTimestamp=A;if(!V)V=this.lastTimestamp;let q=A-this.lastTimestamp;this.lastTimestamp=A;let z=new yN({delta:Number(q)});if(z.parseDelta(),Q.push(z),U!=null&&U.status!==z.type)X.push(new dV({packetStatus:U.status,runLength:N-U.minTSN})),U={minTSN:N,status:z.type};if(N===G)if(U!=null)X.push(new dV({packetStatus:U.status,runLength:N-U.minTSN+1}));else X.push(new dV({packetStatus:z.type,runLength:1}));if(U==null)U={minTSN:N,status:z.type}}}if(!V)return;let H=new hX({feedback:new Jq({senderSsrc:this.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,baseSequenceNumber:J,packetStatusCount:Z,referenceTime:xd(Math.floor(Number(V/1000n/64n))),fbPktCount:this.fbPktCount,recvDeltas:Q,packetChunks:X})});this.dtlsTransport.sendRtcp([H]).catch((N)=>{mi(N)}),this.extensionInfo={},this.fbPktCount=Sd(this.fbPktCount,1)}},ci=class{base_seq;max_seq;cycles=0;packets_received=0;clockRate;jitter_q4=0;last_arrival;last_timestamp;expected_prior=0;received_prior=0;constructor(W){this.clockRate=W}add(W,Y=Date.now()/1000){let G=this.max_seq==null||RS(W.header.sequenceNumber,this.max_seq);if(this.packets_received++,this.base_seq==null)this.base_seq=W.header.sequenceNumber;if(G){let X=lV(Y*this.clockRate);if(this.max_seq!=null&&W.header.sequenceNumber<this.max_seq)this.cycles+=65536;if(this.max_seq=W.header.sequenceNumber,W.header.timestamp!==this.last_timestamp&&this.packets_received>1){let J=Math.abs(X-(this.last_arrival??0)-(W.header.timestamp-(this.last_timestamp??0)));this.jitter_q4+=J-(this.jitter_q4+8>>4)}this.last_arrival=X,this.last_timestamp=W.header.timestamp}}get fraction_lost(){let W=this.packets_expected-this.expected_prior;this.expected_prior=this.packets_expected;let Y=this.packets_received-this.received_prior;this.received_prior=this.packets_received;let G=W-Y;if(W==0||G<=0)return 0;else return Math.floor((G<<8)/W)}get jitter(){return this.jitter_q4>>4}get packets_expected(){return this.cycles+(this.max_seq??0)-(this.base_seq??0)+1}get packets_lost(){let W=this.packets_expected-this.packets_received;return W<0?0:W}},t5=M1("werift:packages/webrtc/src/transport/dtls.ts"),oF=class W{constructor(Y,G,X,J=[]){this.config=Y,this.iceTransport=G,this.localCertificate=X,this.srtpProfiles=J,this.localCertificate??=W.localCertificate}id=di().toString();state="new";role="auto";srtpStarted=!1;transportSequenceNumber=0;bytesSent=0;bytesReceived=0;packetsSent=0;packetsReceived=0;dataReceiver=()=>{};dtls;srtp;srtcp;onStateChange=new p0;onRtcp=new p0;onRtp=new p0;static localCertificate;static localCertificatePromise;remoteParameters;get localParameters(){return new mO(this.localCertificate?this.localCertificate.getFingerprints():[],this.role)}static async SetupCertificate(){if(this.localCertificate)return this.localCertificate;if(this.localCertificatePromise)return this.localCertificatePromise;return this.localCertificatePromise=(async()=>{let{certPem:Y,keyPem:G,signatureHash:X}=await aN.createSelfSignedCertificateWithKey({signature:l4.ecdsa_3,hash:rN.sha256_4},a6.secp256r1_23);return this.localCertificate=new o2(G,Y,X),this.localCertificate})(),this.localCertificatePromise}setRemoteParams(Y){let G=ni([...this.remoteParameters?.fingerprints??[],...Y.fingerprints]),X=Y.role==="auto"&&this.remoteParameters?.role?this.remoteParameters.role:Y.role;this.remoteParameters=new mO(G,X)}async start(){if(this.state!=="new")throw Error("state must be new");if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");if(this.role==="auto")if(this.iceTransport.role==="controlling")this.role="server";else this.role="client";this.setState("connecting"),await new Promise(async(Y,G)=>{if(this.role==="server")this.dtls=new Cn({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:nF(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0,certificateRequest:!0});else this.dtls=new OF({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:nF(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0});if(this.dtls.onData.subscribe((X)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;this.dataReceiver(X)}),this.dtls.onClose.subscribe(()=>{if(this.state!=="failed")this.setState("closed")}),this.dtls.onConnect.once(Y),this.dtls.onError.once((X)=>{this.setState("failed"),t5("dtls failed",X),G(X)}),this.dtls instanceof OF)await oi(100),this.dtls.connect().catch((X)=>{this.setState("failed"),t5("dtls connect failed",X),G(X)})});try{this.verifyRemoteCertificateFingerprint()}catch(Y){throw this.setState("failed"),this.dtls?.close(),Y}if(this.srtpProfiles.length>0)this.startSrtp();this.setState("connected"),t5("dtls connected")}verifyRemoteCertificateFingerprint(){if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");let Y=this.dtls?.remoteCertificate;if(!Y)throw Error("remote certificate not available");let G=this.remoteParameters.fingerprints.flatMap(({algorithm:U,value:Q})=>{let H=c2(U);if(!H)return[];let N=hO(Q);if(!N)throw Error("remote fingerprint value is empty");return[{normalizedAlgorithm:H,normalizedValue:N}]});if(G.length===0)throw Error("no supported remote fingerprint algorithms");let X=ri(G),J=G.filter(({normalizedAlgorithm:U})=>U===X),Z=J.reduce((U,{normalizedAlgorithm:Q})=>{if(!U.has(Q))U.set(Q,hO(f2(Y,Q)));return U},new Map);if(!J.some(({normalizedAlgorithm:U,normalizedValue:Q})=>Z.get(U)===Q))throw Error("remote certificate fingerprint mismatch")}updateSrtpSession(){if(!this.dtls)throw Error();let Y=this.dtls.srtp.srtpProfile;if(!Y)throw Error("need srtpProfile");t5("selected SRTP Profile",Y);let{localKey:G,localSalt:X,remoteKey:J,remoteSalt:Z}=this.dtls.extractSessionKeys(Mo(Y),Po(Y)),V={keys:{localMasterKey:G,localMasterSalt:X,remoteMasterKey:J,remoteMasterSalt:Z},profile:Y};this.srtp=new Hn(V),this.srtcp=new Un(V)}startSrtp(){if(this.srtpStarted)return;this.srtpStarted=!0,this.updateSrtpSession(),this.iceTransport.connection.onData.subscribe((Y)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;if(!Eo(Y))return;if(this.bytesReceived+=Y.length,this.packetsReceived++,go(Y)){let G;try{G=this.srtcp.decrypt(Y)}catch(J){if(J instanceof mX){t5("dropping invalid SRTCP packet",J);return}throw J}let X;try{X=vo.deSerialize(G)}catch(J){t5("dropping malformed SRTCP packet",J);return}for(let J of X)try{this.onRtcp.execute(J)}catch(Z){t5("RTCP error",Z)}}else{let G;try{G=this.srtp.decrypt(Y)}catch(J){if(J instanceof mX){t5("dropping invalid SRTP packet",J);return}throw J}let X;try{X=t6.deSerialize(G)}catch(J){t5("dropping malformed SRTP packet",J);return}try{this.onRtp.execute(X)}catch(J){t5("RTP error",J)}}})}sendData=async(Y)=>{if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return;if(!this.dtls)throw Error("dtls not established");await this.dtls.send(Y)};async sendRtp(Y,G){try{let X=this.srtp.encrypt(Y,G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return X.length;return this.bytesSent+=X.length,this.packetsSent++,await this.iceTransport.connection.send(X).catch(()=>{}),X.length}catch(X){return t5("failed to send",X),0}}async sendRtcp(Y){let G=Buffer.concat(Y.map((J)=>J.serialize())),X=this.srtcp.encrypt(G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return X.length;this.bytesSent+=X.length,this.packetsSent++,await this.iceTransport.connection.send(X).catch(()=>{})}setState(Y){if(Y!=this.state)this.state=Y,this.onStateChange.execute(Y)}async stop(){this.setState("closed"),await this.iceTransport.stop()}async getStats(){let Y=$Y(),G=[],J={type:"transport",id:Z8("transport",this.id),timestamp:Y,bytesSent:this.bytesSent,bytesReceived:this.bytesReceived,packetsSent:this.packetsSent,packetsReceived:this.packetsReceived,dtlsState:this.state,iceState:this.iceTransport.state,selectedCandidatePairId:this.iceTransport.connection.nominated?Z8("candidate-pair",this.iceTransport.connection.nominated.localCandidate.foundation,this.iceTransport.connection.nominated.remoteCandidate.foundation):void 0,localCertificateId:this.localCertificate?Z8("certificate","local"):void 0,remoteCertificateId:this.remoteParameters?Z8("certificate","remote"):void 0,dtlsRole:this.role==="auto"?void 0:this.role};if(G.push(J),this.localCertificate){let V=this.localCertificate.getFingerprints();if(V.length>0){let U={type:"certificate",id:Z8("certificate","local"),timestamp:Y,fingerprint:V[0].value,fingerprintAlgorithm:V[0].algorithm,base64Certificate:Buffer.from(this.localCertificate.certPem).toString("base64")};G.push(U)}}if(this.remoteParameters&&this.remoteParameters.fingerprints.length>0){let V={type:"certificate",id:Z8("certificate","remote"),timestamp:Y,fingerprint:this.remoteParameters.fingerprints[0].value,fingerprintAlgorithm:this.remoteParameters.fingerprints[0].algorithm,base64Certificate:""};G.push(V)}let Z=await this.iceTransport.getStats();return G.push(...Z),G}};var o2=class{constructor(W,Y,G){this.certPem=Y,this.signatureHash=G;let X=tV.Certificate.fromPEM(Buffer.from(Y));this.publicKey=X.publicKey.toPEM(),this.privateKey=tV.PrivateKey.fromPEM(Buffer.from(W)).toPEM()}publicKey;privateKey;getFingerprints(){return[new bO("sha-256",f2(tV.Certificate.fromPEM(Buffer.from(this.certPem)).raw,"sha256"))]}},bO=class{constructor(W,Y){this.algorithm=W,this.value=Y}},mO=class{constructor(W=[],Y){this.fingerprints=W,this.role=Y}},ni=(W)=>{let Y=new Set;return W.filter(({algorithm:G,value:X})=>{let J=`${c2(G)??G.trim().toLowerCase()}:${hO(X)}`;if(Y.has(J))return!1;return Y.add(J),!0})},ii=["sha512","sha384","sha256","sha224","sha1"],ri=(W)=>{return ii.find((Y)=>W.some(({normalizedAlgorithm:G})=>G===Y))??W[0].normalizedAlgorithm},ai=class{constructor(W){this.ice=W,W.onData.subscribe((Y)=>{if(Si(Y)){if(this.onData)this.onData(Y)}})}closed=!1;onData=()=>{};get address(){return{}}type="ice";send=(W)=>{return this.ice.send(W)};async close(){this.closed=!0,this.ice.close()}},nF=(W)=>new ai(W),iF=M1("werift:packages/webrtc/src/transport/ice.ts"),ti=class{constructor(W){this.iceGather=W,this.connection=this.iceGather.connection,this.connection.stateChanged.subscribe((Y)=>{this.setState(Y)}),this.iceGather.onIceCandidate=(Y)=>{this.onIceCandidate.execute(Y)}}id=si().toString();connection;state="new";waitStart;renominating=!1;onStateChange=new p0;onIceCandidate=new p0;onNegotiationNeeded=new p0;get role(){if(this.connection.iceControlling)return"controlling";else return"controlled"}get gatheringState(){return this.iceGather.gatheringState}get localCandidates(){return this.iceGather.localCandidates}get localParameters(){return this.iceGather.localParameters}setState(W){if(W!==this.state)this.state=W,this.onStateChange.execute(W)}gather(){return this.iceGather.gather()}addRemoteCandidate=(W)=>{if(!this.connection.remoteCandidatesEnd)if(!W)return this.connection.addRemoteCandidate(void 0);else return this.connection.addRemoteCandidate(Wr(W))};setRemoteParams(W,Y=!1){if(Y)this.renominating=!0;if(this.connection.remoteUsername&&this.connection.remotePassword&&(this.connection.remoteUsername!==W.usernameFragment||this.connection.remotePassword!==W.password))if(this.renominating)iF("renomination",W),this.connection.resetNominatedPair(),this.renominating=!1;else iF("restart",W),this.restart();this.connection.setRemoteParams(W)}restart(){this.connection.restart(),this.setState("new"),this.iceGather.gatheringState="new",this.waitStart=void 0,this.onNegotiationNeeded.execute()}async start(){if(this.state==="closed")throw Error("RTCIceTransport is closed");if(!this.connection.remotePassword||!this.connection.remoteUsername)throw Error("remoteParams missing");if(this.waitStart)await this.waitStart.asPromise();this.waitStart=new p0,this.setState("checking");try{await this.connection.connect()}catch(W){throw this.setState("failed"),W}this.waitStart.execute(),this.waitStart.complete(),this.waitStart=void 0}async stop(){if(this.state!=="closed")this.setState("closed"),await this.connection.close();this.onStateChange.complete(),this.onIceCandidate.complete(),this.onNegotiationNeeded.complete()}async getStats(){let W=$Y(),Y=[];for(let X of this.localCandidates){let J={type:"local-candidate",id:Z8("local-candidate",X.foundation),timestamp:W,transportId:Z8("transport",this.id),address:X.ip,port:X.port,protocol:X.protocol,candidateType:X.type,priority:X.priority,foundation:X.foundation};Y.push(J)}for(let X of this.connection.remoteCandidates){let J=eV(X),Z={type:"remote-candidate",id:Z8("remote-candidate",J.foundation),timestamp:W,transportId:Z8("transport",this.id),address:J.ip,port:J.port,protocol:J.protocol,candidateType:J.type,priority:J.priority,foundation:J.foundation};Y.push(Z)}let G=this.connection?.candidatePairs?[...this.connection.candidatePairs.filter((X)=>X.nominated),...this.connection.candidatePairs.filter((X)=>!X.nominated)]:[];for(let X of G){let J={type:"candidate-pair",id:Z8("candidate-pair",X.foundation),timestamp:W,transportId:Z8("transport",this.id),localCandidateId:Z8("local-candidate",X.localCandidate.foundation),remoteCandidateId:Z8("remote-candidate",X.remoteCandidate.foundation),state:X.state,nominated:X.nominated,packetsSent:X.packetsSent,packetsReceived:X.packetsReceived,bytesSent:X.bytesSent,bytesReceived:X.bytesReceived,currentRoundTripTime:X.rtt};Y.push(J)}return Y}};var ei=class{constructor(W={}){this.options=W,this.connection=new Gi(!1,this.options),this.connection.onIceCandidate.subscribe((Y)=>{this.onIceCandidate(eV(Y))})}onIceCandidate=()=>{};gatheringState="new";connection;onGatheringStateChange=new p0;async gather(){if(this.gatheringState==="new")this.setState("gathering"),await this.connection.gatherCandidates(),this.onIceCandidate(void 0),this.setState("complete")}get localCandidates(){return this.connection.localCandidates.map(eV)}get localParameters(){return new i2({usernameFragment:this.connection.localUsername,password:this.connection.localPassword})}setState(W){if(W!==this.gatheringState)this.gatheringState=W,this.onGatheringStateChange.execute(W)}};function eV(W){let Y=new n2(W.component,W.foundation,W.host,W.port,W.priority,W.transport,W.type,W.generation,W.ufrag);return Y.relatedAddress=W.relatedAddress,Y.relatedPort=W.relatedPort,Y.tcpType=W.tcptype,Y}function Wr(W){return new DY(W.foundation,W.component,W.protocol,W.priority,W.ip,W.port,W.type,W.relatedAddress,W.relatedPort,W.tcpType,W.generation,W.ufrag)}var Yr=class{candidate;sdpMid;sdpMLineIndex;usernameFragment;constructor(W){Object.assign(this,W)}static fromSdp(W){let Y=DY.fromSdp(W);return eV(Y).toJSON()}static isThis(W){if(typeof W?.candidate==="string")return!0}toJSON(){return{candidate:this.candidate,sdpMid:this.sdpMid,sdpMLineIndex:this.sdpMLineIndex,usernameFragment:this.usernameFragment}}},n2=class{constructor(W,Y,G,X,J,Z,V,U,Q){this.component=W,this.foundation=Y,this.ip=G,this.port=X,this.priority=J,this.protocol=Z,this.type=V,this.generation=U,this.ufrag=Q}relatedAddress;relatedPort;sdpMid;sdpMLineIndex;tcpType;toJSON(){return new Yr({candidate:Jx(this),sdpMLineIndex:this.sdpMLineIndex,sdpMid:this.sdpMid,usernameFragment:this.ufrag})}static fromJSON(W){try{if(!W.candidate)throw Error("candidate is required");let Y=Zx(W.candidate);return Y.sdpMLineIndex=W.sdpMLineIndex??void 0,Y.sdpMid=W.sdpMid??void 0,Y}catch(Y){}}},i2=class{iceLite=!1;usernameFragment;password;constructor(W={}){Object.assign(this,W)}},d7=class W{constructor(Y=0,G=Buffer.from("")){this.flags=Y,this._body=G}get body(){return this._body}set body(Y){this._body=Y}static type=-1;get type(){return W.type}get bytes(){if(!this.body)throw Error();let Y=Buffer.alloc(4);return Y.writeUInt8(this.type,0),Y.writeUInt8(this.flags,1),Y.writeUInt16BE(this.body.length+4,2),Buffer.concat([Y,this.body,...[...Array(NU(this.body.length))].map(()=>Buffer.from("\x00"))])}},HK=class extends d7{constructor(W=0,Y){super(W,Y);if(this.flags=W,Y)this.initiateTag=Y.readUInt32BE(0),this.advertisedRwnd=Y.readUInt32BE(4),this.outboundStreams=Y.readUInt16BE(8),this.inboundStreams=Y.readUInt16BE(10),this.initialTsn=Y.readUInt32BE(12),this.params=Wx(Y.slice(16));else this.initiateTag=0,this.advertisedRwnd=0,this.outboundStreams=0,this.inboundStreams=0,this.initialTsn=0,this.params=[]}initiateTag;advertisedRwnd;outboundStreams;inboundStreams;initialTsn;params;get body(){let W=Buffer.alloc(16);return W.writeUInt32BE(this.initiateTag,0),W.writeUInt32BE(this.advertisedRwnd,4),W.writeUInt16BE(this.outboundStreams,8),W.writeUInt16BE(this.inboundStreams,10),W.writeUInt32BE(this.initialTsn,12),Buffer.concat([W,e2(this.params)])}},fN=class W extends HK{static type=1;get type(){return W.type}},fO=class W extends HK{static type=2;get type(){return W.type}},Jr=class W extends HK{static type=130;get type(){return W.type}},cN=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G){this.cumulativeTsn=G.readUInt32BE(0);let X=4;while(X<G.length)this.streams.push([G.readUInt16BE(X),G.readUInt16BE(X+2)]),X+=4}else this.cumulativeTsn=0}static type=192;streams=[];cumulativeTsn;get type(){return W.type}set body(Y){}get body(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.cumulativeTsn,0),Buffer.concat([Y,...this.streams.map(([G,X])=>{let J=Buffer.alloc(4);return J.writeUInt16BE(G,0),J.writeUInt16BE(X,2),J})])}},pN=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G)this.tsn=G.readUInt32BE(0),this.streamId=G.readUInt16BE(4),this.streamSeqNum=G.readUInt16BE(6),this.protocol=G.readUInt32BE(8),this.userData=G.slice(12)}static type=0;get type(){return W.type}tsn=0;streamId=0;streamSeqNum=0;protocol=0;userData=Buffer.from("");abandoned=!1;acked=!1;misses=0;retransmit=!1;sentCount=0;bookSize=0;expiry;maxRetransmits;sentTime;get bytes(){let Y=16+this.userData.length,G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(Y,2),G.writeUInt32BE(this.tsn,4),G.writeUInt16BE(this.streamId,8),G.writeUInt16BE(this.streamSeqNum,10),G.writeUInt32BE(this.protocol,12);let X=Buffer.concat([G,this.userData]);if(Y%4)X=Buffer.concat([X,...[...Array(NU(Y))].map(()=>Buffer.from("\x00"))]);return X}},cO=class W extends d7{static type=10;get type(){return W.type}},pO=class W extends d7{static type=11;get type(){return W.type}},HU=class extends d7{constructor(W=0,Y=void 0){super(W,Y);if(this.flags=W,Y)this.params=Wx(Y)}params=[];get body(){return e2(this.params)}},lO=class W extends HU{static type=6;get type(){return W.type}},lN=class W extends HU{static type=9;static CODE={InvalidStreamIdentifier:1,MissingMandatoryParameter:2,StaleCookieError:3,OutofResource:4,UnresolvableAddress:5,UnrecognizedChunkType:6,InvalidMandatoryParameter:7,UnrecognizedParameters:8,NoUserData:9,CookieReceivedWhileShuttingDown:10,RestartofanAssociationwithNewAddresses:11,UserInitiatedAbort:12,ProtocolViolation:13};get type(){return W.type}get descriptions(){return this.params.map(([Y,G])=>{return{name:(Object.entries(W.CODE).find(([,J])=>J===Y)||[])[0],body:G}})}},dO=class W extends HU{static type=4;get type(){return W.type}},r2=class W extends HU{static type=5;get type(){return W.type}},oO=class W extends HU{static type=130;get type(){return W.type}},nO=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G){this.cumulativeTsn=G.readUInt32BE(0),this.advertisedRwnd=G.readUInt32BE(4);let X=G.readUInt16BE(8),J=G.readUInt16BE(10),Z=12;[...Array(X)].forEach(()=>{this.gaps.push([G.readUInt16BE(Z),G.readUInt16BE(Z+2)]),Z+=4}),[...Array(J)].forEach(()=>{this.duplicates.push(G.readUInt32BE(Z)),Z+=4})}}static type=3;get type(){return W.type}gaps=[];duplicates=[];cumulativeTsn=0;advertisedRwnd=0;get bytes(){let Y=16+4*(this.gaps.length+this.duplicates.length),G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(Y,2),G.writeUInt32BE(this.cumulativeTsn,4),G.writeUInt32BE(this.advertisedRwnd,8),G.writeUInt16BE(this.gaps.length,12),G.writeUInt16BE(this.duplicates.length,14);let X=Buffer.concat([G,...this.gaps.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt16BE(J[0],0),Z.writeUInt16BE(J[1],2),Z})]);return X=Buffer.concat([X,...this.duplicates.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt32BE(J,0),Z})]),X}},a2=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G)this.cumulativeTsn=G.readUInt32BE(0)}static type=7;get type(){return W.type}cumulativeTsn=0;get body(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.cumulativeTsn,0),Y}},s2=class W extends d7{static type=8;get type(){return W.type}},t2=class W extends d7{static type=14;get type(){return W.type}},Zr=[pN,fN,fO,nO,dO,r2,lO,a2,s2,lN,cO,pO,t2,oO,cN],Vr=Zr.reduce((W,Y)=>{return W[Y.type]=Y,W},{});function NU(W){let Y=W%4;return Y?4-Y:0}function e2(W){let Y=Buffer.from(""),G=Buffer.from("");return W.forEach(([X,J])=>{let Z=J.length+4,V=Buffer.alloc(4);V.writeUInt16BE(X,0),V.writeUInt16BE(Z,2),Y=Buffer.concat([Y,G,V,J]),G=Buffer.concat([...Array(NU(Z))].map(()=>Buffer.from("\x00")))}),Y}function Wx(W){let Y=[],G=0;while(G<=W.length-4){let X=W.readUInt16BE(G),J=W.readUInt16BE(G+2);Y.push([X,W.slice(G+4,G+J)]),G+=J+NU(J)}return Y}function Ur(W){if(W.length<12)throw Error("SCTP packet length is less than 12 bytes");let Y=W.readUInt16BE(0),G=W.readUInt16BE(2),X=W.readUInt32BE(4),J=W.readUInt32LE(8),Z=TS(Buffer.concat([W.slice(0,8),Buffer.from("\x00\x00\x00\x00"),W.slice(12)]));if(J!==Z)throw Error("SCTP packet has invalid checksum");let V=[],U=12;while(U+4<=W.length){let Q=W.readUInt8(U),H=W.readUInt8(U+1),N=W.readUInt16BE(U+2),A=W.slice(U+4,U+N),q=Vr[Q.toString()];if(q)V.push(new q(H,A));else throw Error("unknown");U+=N+NU(N)}return[Y,G,X,V]}function Qr(W,Y,G,X){let J=Buffer.alloc(8);J.writeUInt16BE(W,0),J.writeUInt16BE(Y,2),J.writeUInt32BE(G,4);let Z=X.bytes,V=TS(Buffer.concat([J,Buffer.from("\x00\x00\x00\x00"),Z])),U=Buffer.alloc(4);return U.writeUInt32LE(V,0),Buffer.concat([J,U,Z])}function Hr(W){return W.map((Y,G)=>[G,Y])}function Nr(W){return W.reduce((Y,G)=>{return Y[G]=new p0,Y},{})}var iO=class W{constructor(Y,G,X,J){this.requestSequence=Y,this.responseSequence=G,this.lastTsn=X,this.streams=J}static type=13;get type(){return W.type}get bytes(){let Y=Buffer.from(s1.Pack("!LLL",[this.requestSequence,this.responseSequence,this.lastTsn]));return Buffer.concat([Y,...this.streams.map((G)=>Buffer.from(s1.Pack("!H",[G])))])}static parse(Y){let[G,X,J]=s1.Unpack("!LLL",Y),Z=[];for(let V=12;V<Y.length;V+=2)Z.push(s1.Unpack("!H",Y.slice(V))[0]);return new W(G,X,J,Z)}},Yx=class W{constructor(Y,G){this.requestSequence=Y,this.newStreams=G}static type=17;get type(){return W.type}get bytes(){return Buffer.from(s1.Pack("!LHH",[this.requestSequence,this.newStreams,0]))}static parse(Y){let[G,X]=s1.Unpack("!LHH",Y);return new W(G,X)}},xN={ReconfigResultSuccessPerformed:1,BadSequenceNumber:5},dN=class W{constructor(Y,G){this.responseSequence=Y,this.result=G}static type=16;get type(){return W.type}get bytes(){return Buffer.from(s1.Pack("!LL",[this.responseSequence,this.result]))}static parse(Y){let[G,X]=s1.Unpack("!LL",Y);return new W(G,X)}},aF={13:iO,16:dN,17:Yx},a1=M1("werift/sctp/sctp"),qr=24,Ar=60,sF=65535,e5=1200,fV=1,Gx=2,rO=4,tF=10,Ir=8,eF=0.125,WS=0.25,YS=3,zr=1,wr=60,Uq=4294967296,jr=200,Or=30,GS=135,XS=7,JS=32776,ZS=49152,Kr=["new","closed","connected","connecting"],Dr=class W{constructor(Y,G=5000){this.transport=Y,this.port=G,this.localPort=this.port,this.transport.onData=(X)=>{this.handleData(X)}}flush=new p0;stateChanged=Nr(Kr);onReconfigStreams=new p0;onReceive=new p0;onSackReceived=async()=>{};associationState=1;started=!1;state="new";isServer=!0;isStopping=!1;isClosed=!1;hmacKey=Xr(16);localPartialReliability=!0;localPort;localVerificationTag=CO();remoteExtensions=[];remotePartialReliability=!0;remotePort;remoteVerificationTag=0;advertisedRwnd=1048576;peerAdvertisedRwnd=this.advertisedRwnd;get peerRwnd(){return Math.max(0,this.peerAdvertisedRwnd-this.flightSize)}inboundStreams={};_inboundStreamsCount=0;_inboundStreamsMax=sF;lastReceivedTsn;sackDuplicates=[];sackMisOrdered=new Set;sackNeeded=!1;sackPacketCount=0;sackHasNewDataInPacket=!1;sackImmediate=!1;sackTimeout;cwnd=3*e5;fastRecoveryExit;fastRecoveryTransmit=!1;forwardTsnChunk;flightSize=0;outboundQueue=[];outboundStreamSeq={};_outboundStreamsCount=sF;localTsn=Number(CO());lastSackedTsn=OY(this.localTsn);advancedPeerAckTsn=OY(this.localTsn);partialBytesAcked=0;sentQueue=[];transmitting=!1;transmitRequested=!1;reconfigRequestSeq=this.localTsn;reconfigResponseSeq=0;reconfigRequest;reconfigQueue=[];srtt;rttvar;rto=YS;timer1Handle;timer1Chunk;timer1Failures=0;timer2Handle;timer2Chunk;timer2Failures=0;timer3Handle;timerReconfigHandle;timerReconfigFailures=0;timerHeartbeatHandle;heartbeatInterval=Or;ssthresh;get isStopped(){return this.isStopping||this.isClosed}get maxChannels(){if(this._inboundStreamsCount>0)return Math.min(this._inboundStreamsCount,this._outboundStreamsCount);return}static client(Y,G=5000){let X=new W(Y,G);return X.isServer=!1,X}static server(Y,G=5000){let X=new W(Y,G);return X.isServer=!0,X}async handleData(Y){if(this.isStopped)return;let G,[,,X,J]=Ur(Y);if(J.filter((V)=>V.type===fN.type).length>0){if(J.length!=1)throw Error();G=0}else G=this.localVerificationTag;if(X!==G)return;this.sackHasNewDataInPacket=!1;for(let V of J)await this.receiveChunk(V);if(this.sackNeeded){if(this.sackHasNewDataInPacket)this.sackPacketCount++;if(this.sackPacketCount>=2)this.sackImmediate=!0;await this.scheduleSack()}}async scheduleSack(){if(this.isStopped)return;if(!this.sackNeeded)return;if(this.sackImmediate){if(this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;await this.sendSack();return}if(this.sackTimeout)return;this.sackTimeout=setTimeout(()=>{this.sackTimeout=void 0,this.sendSack().catch((Y)=>{a1("send delayed sack failed",Y.message)})},jr)}async sendSack(){if(this.isStopped)return;if(!this.sackNeeded)return;let Y=[],G;[...this.sackMisOrdered].sort().forEach((J)=>{let Z=(J-this.lastReceivedTsn)%Uq;if(J===G)Y[Y.length-1][1]=Z;else Y.push([Z,Z]);G=yX(J)});let X=new nO(0,void 0);X.cumulativeTsn=this.lastReceivedTsn,X.advertisedRwnd=Math.max(0,this.advertisedRwnd),X.duplicates=[...this.sackDuplicates],X.gaps=Y,await this.sendChunk(X).catch((J)=>{a1("send sack failed",J.message)}),this.sackDuplicates=[],this.sackNeeded=!1,this.sackPacketCount=0,this.sackImmediate=!1}async receiveChunk(Y){switch(Y.type){case pN.type:this.receiveDataChunk(Y);break;case fN.type:{if(!this.isServer)return;let G=Y;a1("receive init",G),this.lastReceivedTsn=OY(G.initialTsn),this.reconfigResponseSeq=OY(G.initialTsn),this.remoteVerificationTag=G.initiateTag,this.ssthresh=G.advertisedRwnd,this.peerAdvertisedRwnd=G.advertisedRwnd,this.getExtensions(G.params),this._inboundStreamsCount=Math.min(G.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,G.inboundStreams);let X=new fO;X.initiateTag=this.localVerificationTag,X.advertisedRwnd=this.advertisedRwnd,X.outboundStreams=this._outboundStreamsCount,X.inboundStreams=this._inboundStreamsCount,X.initialTsn=this.localTsn,this.setExtensions(X.params);let J=Date.now()/1000,Z=Buffer.from(s1.Pack("!L",[J]));Z=Buffer.concat([Z,rF("sha1",this.hmacKey).update(Z).digest()]),X.params.push([XS,Z]),a1("send initAck",X),await this.sendChunk(X).catch((V)=>{a1("send initAck failed",V.message)})}break;case fO.type:{if(this.associationState!=2)return;let G=Y;this.timer1Cancel(),this.lastReceivedTsn=OY(G.initialTsn),this.reconfigResponseSeq=OY(G.initialTsn),this.remoteVerificationTag=G.initiateTag,this.ssthresh=G.advertisedRwnd,this.peerAdvertisedRwnd=G.advertisedRwnd,this.getExtensions(G.params),this._inboundStreamsCount=Math.min(G.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,G.inboundStreams);let X=new cO;for(let[J,Z]of G.params)if(J===XS){X.body=Z;break}await this.sendChunk(X).catch((J)=>{a1("send echo failed",J.message)}),this.timer1Start(X),this.setState(3)}break;case nO.type:await this.receiveSackChunk(Y);break;case dO.type:{let G=new r2;G.params=Y.params,await this.sendChunk(G).catch((X)=>{a1("send heartbeat ack failed",X.message)})}break;case lO.type:this.setState(1);break;case a2.type:{this.timer2Cancel(),this.setState(7);let G=new s2;await this.sendChunk(G).catch((X)=>{a1("send shutdown ack failed",X.message)}),this.t2Start(G),this.setState(6)}break;case lN.type:a1("ErrorChunk",Y.descriptions);break;case cO.type:{if(!this.isServer)return;let X=Y.body,J=rF("sha1",this.hmacKey).update(X.slice(0,4)).digest();if(X?.length!=qr||!X.slice(4).equals(J)){a1("x State cookie is invalid");return}let Z=Date.now()/1000,V=s1.Unpack("!L",X)[0];if(V<Z-Ar||V>Z){let Q=new lN(0,void 0);Q.params.push([lN.CODE.StaleCookieError,Buffer.concat([...Array(8)].map(()=>Buffer.from("\x00")))]),await this.sendChunk(Q).catch((H)=>{a1("send errorChunk failed",H.message)});return}let U=new pO;await this.sendChunk(U).catch((Q)=>{a1("send cookieAck failed",Q.message)}),this.setState(4)}break;case pO.type:{if(this.associationState!=3)return;this.timer1Cancel(),this.setState(4)}break;case t2.type:{if(this.associationState!=8)return;this.timer2Cancel(),this.setState(1)}break;case oO.type:{if(this.associationState!=4)return;let G=Y;for(let[X,J]of G.params){let Z=aF[X];if(Z)await this.receiveReconfigParam(Z.parse(J))}}break;case cN.type:this.receiveForwardTsnChunk(Y);break}}getExtensions(Y){for(let[G,X]of Y)if(G===ZS)this.remotePartialReliability=!0;else if(G===JS)this.remoteExtensions=[...X]}async receiveReconfigParam(Y){switch(a1("receiveReconfigParam",aF[Y.type]),Y.type){case iO.type:{let G=Y,X=new dN(G.requestSequence,xN.ReconfigResultSuccessPerformed);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(X),await Promise.all(G.streams.map(async(J)=>{if(delete this.inboundStreams[J],this.outboundStreamSeq[J]){if(!this.reconfigQueue.includes(J))this.reconfigQueue.push(J)}})),await this.transmitReconfigRequest(),this.onReconfigStreams.execute(G.streams)}break;case dN.type:{let G=Y;if(G.result!==xN.ReconfigResultSuccessPerformed)a1("OutgoingSSNResetRequestParam failed",Object.keys(xN).find((X)=>xN[X]===G.result));else if(G.responseSequence===this.reconfigRequest?.requestSequence){let X=this.reconfigRequest.streams.map((J)=>{return delete this.outboundStreamSeq[J],J});if(this.onReconfigStreams.execute(X),this.reconfigRequest=void 0,this.timerReconfigCancel(),this.rto=YS,this.timerReconfigFailures=0,this.reconfigQueue.length>0)await this.transmitReconfigRequest()}}break;case Yx.type:{let G=Y;this._inboundStreamsCount+=G.newStreams;let X=new dN(G.requestSequence,1);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(X)}break}}receiveDataChunk(Y){if(this.sackNeeded=!0,this.markReceived(Y.tsn)){this.sackImmediate=!0;return}if(this.sackHasNewDataInPacket=!0,this.sackImmediate=!0,(Y.flags&fV)===0)this.sackImmediate=!0;if(this.sackMisOrdered.size>0)this.sackImmediate=!0;let G=this.getInboundStream(Y.streamId);G.addChunk(Y),this.advertisedRwnd-=Y.userData.length;for(let X of G.popMessages())this.advertisedRwnd+=X[2].length,this.receive(...X)}async receiveSackChunk(Y){if(f4(this.lastSackedTsn,Y.cumulativeTsn))return;let G=Date.now()/1000;this.lastSackedTsn=Y.cumulativeTsn;let X=this.flightSize>=this.cwnd,J=0,Z=0;while(this.sentQueue.length>0&&mV(this.lastSackedTsn,this.sentQueue[0].tsn)){let U=this.sentQueue.shift();if(J++,!U?.acked)Z+=U.bookSize,this.flightSizeDecrease(U);if(J===1&&U.sentCount===1)this.updateRto(G-U.sentTime)}if(!this.sentQueue.length)this.sentQueue=[];let V=!1;if(Y.gaps.length>0){let U=new Set,Q;Y.gaps.forEach((N)=>{for(let A=N[0];A<N[1]+1;A++)Q=(Y.cumulativeTsn+A)%Uq,U.add(Q)});let H=Y.cumulativeTsn;for(let N of this.sentQueue){if(f4(N.tsn,Q))break;if(U.has(N.tsn)&&!N.acked)Z+=N.bookSize,N.acked=!0,this.flightSizeDecrease(N),H=N.tsn}for(let N of this.sentQueue){if(f4(N.tsn,H))break;if(!U.has(N.tsn)){if(N.misses++,N.misses===3){if(N.misses=0,!this.maybeAbandon(N))N.retransmit=!0;N.acked=!1,this.flightSizeDecrease(N),V=!0}}}}if(this.fastRecoveryExit===void 0){if(J&&X){if(this.cwnd<=this.ssthresh)this.cwnd+=Math.min(Z,e5);else if(this.partialBytesAcked+=Z,this.partialBytesAcked>=this.cwnd)this.partialBytesAcked-=this.cwnd,this.cwnd+=e5}if(V)this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*e5),this.cwnd=this.ssthresh,this.partialBytesAcked=0,this.fastRecoveryExit=this.sentQueue[this.sentQueue.length-1].tsn,this.fastRecoveryTransmit=!0}else if(mV(Y.cumulativeTsn,this.fastRecoveryExit))this.fastRecoveryExit=void 0;if(this.sentQueue.length===0)this.timer3Cancel();else if(J>0)this.timer3Restart();this.peerAdvertisedRwnd=Y.advertisedRwnd,this.updateAdvancedPeerAckPoint(),await this.onSackReceived(),await this.transmit()}receiveForwardTsnChunk(Y){if(this.sackNeeded=!0,this.sackImmediate=!0,mV(this.lastReceivedTsn,Y.cumulativeTsn))return;let G=(X)=>f4(X,this.lastReceivedTsn);this.lastReceivedTsn=Y.cumulativeTsn,this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let X of[...this.sackMisOrdered].sort())if(X===yX(this.lastReceivedTsn))this.lastReceivedTsn=X;else break;this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let[X,J]of Y.streams){let Z=this.getInboundStream(X);Z.streamSequenceNumber=T9(J,1);for(let V of Z.popMessages())this.advertisedRwnd+=V[2].length,this.receive(...V)}Object.values(this.inboundStreams).forEach((X)=>{this.advertisedRwnd+=X.pruneChunks(this.lastReceivedTsn)})}updateRto(Y){if(!this.srtt)this.rttvar=Y/2,this.srtt=Y;else this.rttvar=(1-WS)*this.rttvar+WS*Math.abs(this.srtt-Y),this.srtt=(1-eF)*this.srtt+eF*Y;this.rto=Math.max(zr,Math.min(this.srtt+4*this.rttvar,wr))}receive(Y,G,X){this.onReceive.execute(Y,G,X)}getInboundStream(Y){if(!this.inboundStreams[Y])this.inboundStreams[Y]=new Cr;return this.inboundStreams[Y]}markReceived(Y){if(mV(this.lastReceivedTsn,Y)||this.sackMisOrdered.has(Y))return this.sackDuplicates.push(Y),!0;this.sackMisOrdered.add(Y);for(let X of[...this.sackMisOrdered].sort())if(X===yX(this.lastReceivedTsn))this.lastReceivedTsn=X;else break;let G=(X)=>f4(X,this.lastReceivedTsn);return this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G)),!1}send=async(Y,G,X,{expiry:J,maxRetransmits:Z,ordered:V}={expiry:void 0,maxRetransmits:void 0,ordered:!0})=>{let U=V?this.outboundStreamSeq[Y]||0:0,Q=Math.ceil(X.length/e5),H=0,N=[];for(let A=0;A<Q;A++){let q=new pN(0,void 0);if(q.flags=0,!V)q.flags=rO;if(A===0)q.flags|=Gx;if(A===Q-1)q.flags|=fV;q.tsn=this.localTsn,q.streamId=Y,q.streamSeqNum=U,q.protocol=G,q.userData=X.slice(H,H+e5),q.bookSize=q.userData.length,q.expiry=J,q.maxRetransmits=Z,H+=e5,this.localTsn=yX(this.localTsn),N.push(q)}if(N.forEach((A)=>{this.outboundQueue.push(A)}),V)this.outboundStreamSeq[Y]=T9(U,1);await this.transmit();while(this.outboundQueue.length)await this.flush.asPromise()};async transmit(){if(this.isStopped)return;if(this.transmitting){this.transmitRequested=!0;return}this.transmitting=!0;try{do this.transmitRequested=!1,await this.transmitOnce();while(this.transmitRequested)}finally{this.transmitting=!1}}async transmitOnce(){if(this.isStopped)return;if(this.forwardTsnChunk){if(await this.sendChunk(this.forwardTsnChunk).catch((J)=>{a1("send forwardTsn failed",J.message)}),this.forwardTsnChunk=void 0,!this.timer3Handle)this.timer3Start()}let Y=this.fastRecoveryExit!=null?2*e5:4*e5,G=Math.min(this.flightSize+Y,this.cwnd),X=!0;for(let J of this.sentQueue){if(J.retransmit){if(this.fastRecoveryTransmit)this.fastRecoveryTransmit=!1;else if(this.flightSize>=G)break;if(this.flightSizeIncrease(J),J.misses=0,J.retransmit=!1,J.sentCount++,await this.sendChunk(J).catch((Z)=>{a1("send data failed",Z.message)}),X)this.timer3Restart()}X=!1}while(this.outboundQueue.length>0&&this.flightSize<G&&this.peerRwnd>0){let J=this.outboundQueue.shift();if(!J)break;if(J.bookSize>this.peerRwnd&&this.flightSize>0){this.outboundQueue.unshift(J);break}if(this.sentQueue.push(J),this.flightSizeIncrease(J),J.sentCount++,J.sentTime=Date.now()/1000,await this.sendChunk(J).catch((Z)=>{a1("send data outboundQueue failed",Z.message)}),!this.timer3Handle)this.timer3Start()}if(!this.outboundQueue.length)this.outboundQueue=[];this.flush.execute()}async transmitReconfigRequest(){if(this.reconfigQueue.length>0&&this.associationState===4&&!this.reconfigRequest){let Y=[...new Set(this.reconfigQueue)],G=Y.slice(0,GS);this.reconfigQueue=Y.slice(GS);let X=new iO(this.reconfigRequestSeq,this.reconfigResponseSeq,OY(this.localTsn),G);this.reconfigRequestSeq=yX(this.reconfigRequestSeq),this.reconfigRequest=X,await this.sendReconfigParam(X),this.timerReconfigHandleStart()}}async sendReconfigParam(Y){a1("sendReconfigParam",Y);let G=new oO;G.params.push([Y.type,Y.bytes]),await this.sendChunk(G).catch((X)=>{a1("send reconfig failed",X.message)})}async sendResetRequest(Y){a1("sendResetRequest",Y);let G=new pN(0,void 0);if(G.streamId=Y,this.outboundQueue.push(G),!this.timer3Handle)await this.transmit()}flightSizeIncrease(Y){this.flightSize+=Y.bookSize}flightSizeDecrease(Y){this.flightSize=Math.max(0,this.flightSize-Y.bookSize)}timer1Start(Y){if(this.timer1Handle)throw Error();this.timer1Chunk=Y,this.timer1Failures=0,this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1000)}timer1Expired=()=>{if(this.isStopped)return;if(this.timer1Failures++,this.timer1Handle=void 0,this.timer1Failures>Ir)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer1Chunk).catch((Y)=>{a1("send timer1 chunk failed",Y.message)})}),this.isStopped)return;this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1000)}};timer1Cancel(){if(this.timer1Handle)clearTimeout(this.timer1Handle),this.timer1Handle=void 0,this.timer1Chunk=void 0}t2Start(Y){if(this.timer2Handle)throw Error();this.timer2Chunk=Y,this.timer2Failures=0,this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1000)}timer2Expired=()=>{if(this.isStopped)return;if(this.timer2Failures++,this.timer2Handle=void 0,this.timer2Failures>tF)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer2Chunk).catch((Y)=>{a1("send timer2Chunk failed",Y.message)})}),this.isStopped)return;this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1000)}};timer2Cancel(){if(this.timer2Handle)clearTimeout(this.timer2Handle),this.timer2Handle=void 0,this.timer2Chunk=void 0}timer3Start(){if(this.isStopped)return;if(this.timer3Handle)throw Error();this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1000)}timer3Restart(){if(this.isStopped)return;this.timer3Cancel(),this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1000)}timer3Expired=()=>{if(this.isStopped)return;this.timer3Handle=void 0,this.sentQueue.forEach((Y)=>{if(!this.maybeAbandon(Y))Y.retransmit=!0}),this.updateAdvancedPeerAckPoint(),this.fastRecoveryExit=void 0,this.flightSize=0,this.partialBytesAcked=0,this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*e5),this.cwnd=e5,this.transmit()};timer3Cancel(){if(this.timer3Handle)clearTimeout(this.timer3Handle),this.timer3Handle=void 0}timerReconfigHandleStart(){if(this.isStopped)return;if(this.timerReconfigHandle)return;a1("timerReconfigHandleStart",{rto:this.rto}),this.timerReconfigFailures=0,this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1000)}timerReconfigHandleExpired=async()=>{if(this.isStopped)return;if(this.timerReconfigFailures++,this.rto=Math.ceil(this.rto*1.5),this.timerReconfigFailures>tF)a1("timerReconfigFailures",this.timerReconfigFailures),this.setState(1),this.timerReconfigHandle=void 0;else if(this.reconfigRequest){if(a1("timerReconfigHandleExpired",this.timerReconfigFailures,this.rto),await this.sendReconfigParam(this.reconfigRequest),this.isStopped)return;this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1000)}};timerReconfigCancel(){if(this.timerReconfigHandle)a1("timerReconfigCancel"),clearTimeout(this.timerReconfigHandle),this.timerReconfigHandle=void 0,this.timerReconfigFailures=0}heartbeatStart(){if(this.timerHeartbeatHandle||this.associationState!==4)return;this.timerHeartbeatHandle=setTimeout(this.timerHeartbeatExpired,(this.rto+this.heartbeatInterval)*1000)}heartbeatRestart(){this.heartbeatCancel(),this.heartbeatStart()}heartbeatCancel(){if(this.timerHeartbeatHandle)clearTimeout(this.timerHeartbeatHandle),this.timerHeartbeatHandle=void 0}timerHeartbeatExpired=async()=>{if(this.timerHeartbeatHandle=void 0,this.associationState!==4)return;if(this.flightSize===0&&this.outboundQueue.length===0){let Y=new dO;Y.params.push([1,Buffer.from(s1.Pack("!L",[Math.floor(Date.now()/1000)]))]),await this.sendChunk(Y).catch((G)=>{a1("send heartbeat failed",G.message)})}this.heartbeatStart()};setHeartbeatInterval(Y){if(Y<=0)throw Error("heartbeat interval must be > 0");this.heartbeatInterval=Y,this.heartbeatRestart()}updateAdvancedPeerAckPoint(){if(f4(this.lastSackedTsn,this.advancedPeerAckTsn))this.advancedPeerAckTsn=this.lastSackedTsn;let Y=0,G={};while(this.sentQueue.length>0&&this.sentQueue[0].abandoned){let X=this.sentQueue.shift();if(this.advancedPeerAckTsn=X.tsn,Y++,!(X.flags&rO))G[X.streamId]=X.streamSeqNum}if(!this.sentQueue.length)this.sentQueue=[];if(Y)this.forwardTsnChunk=new cN(0,void 0),this.forwardTsnChunk.cumulativeTsn=this.advancedPeerAckTsn,this.forwardTsnChunk.streams=Object.entries(G).map(([X,J])=>[Number(X),J])}maybeAbandon(Y){if(Y.abandoned)return!0;if(!(!!Y.maxRetransmits&&Y.maxRetransmits<Y.sentCount||!!Y.expiry&&Y.expiry<Date.now()/1000))return!1;let X=this.sentQueue.findIndex((J)=>J.type===Y.type);for(let J=X;J>=0;J--){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&fV)break}for(let J=X;J<this.sentQueue.length;J++){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&fV)break}return!0}static getCapabilities(){return new Tr(65536)}setRemotePort(Y){this.remotePort=Y}async start(Y){if(!this.started){if(this.started=!0,this.setConnectionState("connecting"),Y)this.setRemotePort(Y);if(!this.isServer)await this.init()}}async init(){let Y=new fN;Y.initiateTag=this.localVerificationTag,Y.advertisedRwnd=this.advertisedRwnd,Y.outboundStreams=this._outboundStreamsCount,Y.inboundStreams=this._inboundStreamsMax,Y.initialTsn=this.localTsn,this.setExtensions(Y.params),a1("send init",Y);try{await this.sendChunk(Y),this.timer1Start(Y),this.setState(2)}catch(G){a1("send init failed",G.message)}}setExtensions(Y){let G=[];if(this.localPartialReliability)Y.push([ZS,Buffer.from("")]),G.push(cN.type);G.push(Jr.type),Y.push([JS,Buffer.from(G)])}async sendChunk(Y){if(this.state==="closed")return;if(this.remotePort===void 0)throw Error("invalid remote port");let G=Qr(this.localPort,this.remotePort,this.remoteVerificationTag,Y);await this.transport.send(G)}setState(Y){if(Y!=this.associationState)this.associationState=Y;if(Y===4)this.isStopping=!1,this.isClosed=!1,this.setConnectionState("connected"),this.heartbeatStart();else if(Y===1){if(this.isClosed=!0,this.timer1Cancel(),this.timer2Cancel(),this.timer3Cancel(),this.timerReconfigCancel(),this.heartbeatCancel(),this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;this.setConnectionState("closed"),this.removeAllListeners()}}setConnectionState(Y){this.state=Y,a1("setConnectionState",Y),this.stateChanged[Y].execute()}async stop(){if(this.isStopped){this.setState(1);return}if(this.isStopping=!0,this.transport.onData=void 0,this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;if(this.associationState!==1)await this.abort();this.setState(1),clearTimeout(this.timer1Handle),clearTimeout(this.timer2Handle),clearTimeout(this.timer3Handle),clearTimeout(this.timerReconfigHandle),clearTimeout(this.timerHeartbeatHandle),clearTimeout(this.sackTimeout)}async abort(){let Y=new lO;await this.sendChunk(Y).catch((G)=>{a1("send abort failed",G.message)})}removeAllListeners(){Object.values(this.stateChanged).forEach((Y)=>Y.allUnsubscribe())}},Cr=class{reassembly=[];streamSequenceNumber=0;constructor(){}addChunk(W){if(this.reassembly.length===0||f4(W.tsn,this.reassembly[this.reassembly.length-1].tsn)){this.reassembly.push(W);return}for(let[Y,G]of Hr(this.reassembly)){if(G.tsn===W.tsn)throw Error("duplicate chunk in reassembly");if(f4(G.tsn,W.tsn)){this.reassembly.splice(Y,0,W);break}}}*popMessages(){let W=0,Y,G,X;while(W<this.reassembly.length){let J=this.reassembly[W];if(Y===void 0){if(X=!(J.flags&rO),!(J.flags&Gx))if(X)break;else{W++;continue}if(X&&RS(J.streamSeqNum,this.streamSequenceNumber))break;G=J.tsn,Y=W}else if(J.tsn!==G)if(X)break;else{Y=void 0,W++;continue}if(J.flags&fV){let Z=this.reassembly.slice(Y,W+1).map((U)=>U.userData).reduce((U,Q)=>{return U.push(Q),U.push(Buffer.from("")),U},[]);Z.pop();let V=Buffer.concat(Z);if(this.reassembly=[...this.reassembly.slice(0,Y),...this.reassembly.slice(W+1)],X&&J.streamSeqNum===this.streamSequenceNumber)this.streamSequenceNumber=T9(this.streamSequenceNumber,1);W=Y,yield[J.streamId,J.protocol,V]}else W++;G=yX(G)}}pruneChunks(W){let Y=-1,G=0;for(let[X,J]of this.reassembly.entries())if(mV(W,J.tsn))Y=X,G+=J.userData.length;else break;return this.reassembly=this.reassembly.slice(Y+1),G}},Tr=class{constructor(W){this.maxMessageSize=W}};function OY(W){return(W-1)%Uq}function yX(W){return(W+1)%Uq}var SX=M1("werift:packages/webrtc/src/transport/sctp.ts"),cV=65536,Rr=class W{constructor(Y=5000,G=cV){this.port=Y,this.maxMessageSize=G}dtlsTransport;sctp;onDataChannel=new p0;id=Gr().toString();mid;mLineIndex;bundled=!1;dataChannels={};remoteMaxMessageSize=cV;dataChannelQueue=[];dataChannelId;eventDisposer=[];setDtlsTransport(Y){if(this.dtlsTransport&&this.dtlsTransport.id===Y.id)return;this.eventDisposer.forEach((G)=>G()),this.dtlsTransport=Y,this.sctp=new Dr(new Mr(this.dtlsTransport),this.port),this.eventDisposer=[...[this.sctp.onReceive.subscribe(this.datachannelReceive),this.sctp.onReconfigStreams.subscribe((G)=>{G.forEach((X)=>{let J=this.dataChannels[X];if(!J)return;J.setReadyState("closing"),J.setReadyState("closed"),delete this.dataChannels[X]})}),this.sctp.stateChanged.connected.subscribe(()=>{Object.values(this.dataChannels).forEach((G)=>{if(G.negotiated&&G.readyState!=="open")G.setReadyState("open")}),this.dataChannelFlush()}),this.sctp.stateChanged.closed.subscribe(()=>{Object.values(this.dataChannels).forEach((G)=>{G.setReadyState("closed")}),this.dataChannels={}}),this.dtlsTransport.onStateChange.subscribe((G)=>{if(G==="closed")this.sctp.setState(1)})].map((G)=>G.unSubscribe),()=>this.sctp.onSackReceived=async()=>{}],this.sctp.onSackReceived=async()=>{await this.dataChannelFlush()}}get isServer(){return this.dtlsTransport.iceTransport.role!=="controlling"}channelByLabel(Y){return Object.values(this.dataChannels).find((G)=>G.label===Y)}datachannelReceive=async(Y,G,X)=>{if(G===SN&&X.length>0)switch(SX("DCEP",Y,G,X),X[0]){case bF:{if(X.length<12){SX("DATA_CHANNEL_OPEN data.length not enough");return}if(!Object.keys(this.dataChannels).includes(Y.toString())){let[,Z,,V,U,Q]=s1.Unpack("!BBHLHH",X),H=12,N=X.slice(H,H+U).toString("utf8");H+=U;let A=X.slice(H,H+Q).toString("utf8");SX("DATA_CHANNEL_OPEN",{channelType:Z,reliability:V,streamId:Y,label:N,protocol:A});let q=(Z&3)===1?V:void 0,z=(Z&3)===2?V:void 0,w=new S2({label:N,ordered:(Z&128)===0,maxPacketLifeTime:z,maxRetransmits:q,protocol:A,id:Y}),D=new F2(this,w,!1);D.isCreatedByRemote=!0,this.dataChannels[Y]=D,this.onDataChannel.execute(D),D.setReadyState("open")}else SX("datachannel already opened","retransmit ack");let J=this.dataChannels[Y];this.dataChannelQueue.push([J,SN,Buffer.from(s1.Pack("!B",[hF]))]),await this.dataChannelFlush()}break;case hF:{SX("DATA_CHANNEL_ACK",Y,G);let J=this.dataChannels[Y];if(!J)throw Error("channel not found");J.setReadyState("open")}break}else{let J=this.dataChannels[Y];if(J){let Z=(()=>{switch(G){case mF:return X.toString("utf8");case Di:return"";case fF:return X;case Ci:return Buffer.from([]);default:throw Error()}})();if(J.messagesReceived++,J.bytesReceived+=X.length,J.onMessage.execute(Z),J.emit("message",{data:Z}),J.onmessage)J.onmessage({data:Z})}}};dataChannelAddNegotiated(Y){if(Y.id==null)throw Error();if(this.dataChannels[Y.id])throw Error();if(this.dataChannels[Y.id]=Y,this.sctp.associationState===4)Y.setReadyState("open")}dataChannelOpen(Y){if(Y.id){if(this.dataChannels[Y.id])throw Error(`Data channel with ID ${Y.id} already registered`);this.dataChannels[Y.id]=Y}let G=Ki,X=0,J=0;if(!Y.ordered)G=128;if(Y.maxRetransmits)G=1,J=Y.maxRetransmits;else if(Y.maxPacketLifeTime)G=2,J=Y.maxPacketLifeTime;let Z=s1.Pack("!BBHLHH",[bF,G,X,J,Y.label.length,Y.protocol.length]),V=Buffer.concat([Buffer.from(Z),Buffer.from(Y.label,"utf8"),Buffer.from(Y.protocol,"utf8")]);this.dataChannelQueue.push([Y,SN,V]),this.dataChannelFlush()}async dataChannelFlush(){if(this.sctp.associationState!=4)return;while(this.dataChannelQueue.length>0){let[Y,G,X]=this.dataChannelQueue.shift(),J=Y.id;if(J===void 0){J=this.dataChannelId;while(Object.keys(this.dataChannels).includes(J.toString()))J+=2;this.dataChannels[J]=Y,Y.setId(J)}if(G===SN)await this.sctp.send(J,G,X,{ordered:!0});else{let Z=Y.maxPacketLifeTime?Date.now()+Y.maxPacketLifeTime/1000:void 0;await this.sctp.send(J,G,X,{expiry:Z,maxRetransmits:Y.maxRetransmits,ordered:Y.ordered}),Y.addBufferedAmount(-X.length)}}this.dataChannelQueue=[]}assertSendableMessageSize(Y){if(this.remoteMaxMessageSize!==0&&Y>this.remoteMaxMessageSize)throw Error(`max-message-size exceeded: ${Y} > ${this.remoteMaxMessageSize}`)}datachannelSend=(Y,G)=>{let X=Buffer.isBuffer(G)?G:Buffer.from(G),J=Vi(G);if(this.assertSendableMessageSize(J),Y.addBufferedAmount(J),this.dataChannelQueue.push(typeof G==="string"?[Y,mF,X]:[Y,fF,X]),this.sctp.associationState!==4)SX("sctp not established",this.sctp.associationState);return this.dataChannelFlush(),J};getCapabilities(){return W.getCapabilities(this.maxMessageSize)}static getCapabilities(Y=cV){return new Xx(Y)}setRemoteMaxMessageSize(Y){this.remoteMaxMessageSize=Y??cV}setRemotePort(Y){this.sctp.setRemotePort(Y)}async start(Y){if(this.isServer)this.dataChannelId=0;else this.dataChannelId=1;this.sctp.isServer=this.isServer,await this.sctp.start(Y)}async stop(){this.dtlsTransport.dataReceiver=()=>{},await this.sctp.stop()}dataChannelClose(Y){if(!["closing","closed"].includes(Y.readyState))if(Y.setReadyState("closing"),this.sctp.associationState===4){if(!this.sctp.reconfigQueue.includes(Y.id))this.sctp.reconfigQueue.push(Y.id);if(this.sctp.reconfigQueue.length===1)this.sctp.transmitReconfigRequest()}else{if(this.dataChannelQueue=this.dataChannelQueue.filter((G)=>G[0].id!==Y.id),this.sctp.reconfigQueue=this.sctp.reconfigQueue.filter((G)=>G!==Y.id),Y.id)delete this.dataChannels[Y.id];Y.setReadyState("closed")}}},Xx=class{constructor(W){this.maxMessageSize=W}},Mr=class{constructor(W){this.dtls=W}set onData(W){this.dtls.dataReceiver=W}send=(W)=>{return this.dtls.sendData(W)};close(){}},oN=class W{version=0;origin;name="-";time="0 0";host;group=[];extMapAllowMixed=!0;msidSemantic=[];media=[];type;dtlsRole;iceOptions;iceLite;icePassword;iceUsernameFragment;dtlsFingerprints=[];static parse(Y){let[G,X]=Pr(Y),J=new W;G.forEach((V)=>{if(V.startsWith("v="))J.version=Number.parseInt(V.slice(2),10);else if(V.startsWith("o="))J.origin=V.slice(2);else if(V.startsWith("s="))J.name=V.slice(2);else if(V.startsWith("c="))J.host=jO(V.slice(2));else if(V.startsWith("t="))J.time=V.slice(2);else if(V.startsWith("a=")){let[U,Q]=OO(V);switch(U){case"fingerprint":{let[H,N]=Q?.split(" ")||[];J.dtlsFingerprints.push(new bO(H,N))}break;case"ice-lite":J.iceLite=!0;break;case"ice-options":J.iceOptions=Q;break;case"ice-pwd":J.icePassword=Q;break;case"ice-ufrag":J.iceUsernameFragment=Q;break;case"group":KO(J.group,Q);break;case"msid-semantic":KO(J.msidSemantic,Q);break;case"setup":J.dtlsRole=pF[Q];break;case"extmap-allow-mixed":J.extMapAllowMixed=!0;break}}});let Z=J.group.find((V)=>V.semantic==="BUNDLE");return X.forEach((V)=>{let Q=V[0].match(/^m=([^ ]+) ([0-9]+) ([A-Z/]+) (.+)/);if(!Q)throw Error("m line not found");let H=Q[1],N=Q[4].split(" "),A=["audio","video"].includes(H)?N.map((w)=>Number(w)):void 0,q=new aO(H,Number.parseInt(Q[2]),Q[3],A||N);if(q.dtlsParams=new mO([...J.dtlsFingerprints],J.dtlsRole),q.iceParams=new i2({iceLite:J.iceLite,usernameFragment:J.iceUsernameFragment,password:J.icePassword}),q.iceOptions=J.iceOptions,J.media.push(q),V.slice(1).forEach((w)=>{if(w.startsWith("c="))q.host=jO(w.slice(2));else if(w.startsWith("a=")){let[D,T]=OO(w);switch(D){case"candidate":if(!T)throw Error();q.iceCandidates.push(Zx(T));break;case"end-of-candidates":q.iceCandidatesComplete=!0;break;case"extmap":{let[x,g]=T.split(" ");if(x.includes("/"))[x]=x.split("/");q.rtp.headerExtensions.push(new Qi({id:Number.parseInt(x),uri:g}))}break;case"fingerprint":{if(!T)throw Error();let[x,g]=T.split(" ");q.dtlsParams?.fingerprints.push(new bO(x,g))}break;case"ice-options":q.iceOptions=T;break;case"ice-pwd":q.iceParams.password=T;break;case"ice-ufrag":q.iceParams.usernameFragment=T;break;case"ice-lite":q.iceParams.iceLite=!0;break;case"max-message-size":q.sctpCapabilities=new Xx(Number.parseInt(T,10));break;case"mid":q.rtp.muxId=T;break;case"msid":q.msid=T;break;case"rtcp":{let[x,g]=m4(T," ");q.rtcpPort=Number.parseInt(x),q.rtcpHost=jO(g)}break;case"rtcp-mux":q.rtcpMux=!0;break;case"setup":q.dtlsParams.role=pF[T];break;case"recvonly":case"sendonly":case"sendrecv":case"inactive":q.direction=D;break;case"rtpmap":{let[x,g]=m4(T," "),[f,y,p]=g.split("/"),b;if(q.kind==="audio")b=p?Number.parseInt(p):1;let m=new EY({mimeType:q.kind+"/"+f,channels:b,clockRate:Number.parseInt(y),payloadType:Number.parseInt(x)});q.rtp.codecs.push(m)}break;case"sctpmap":{if(!T)throw Error();let[x,g]=m4(T," ");q.sctpMap[Number.parseInt(x)]=g,q.sctpPort=Number.parseInt(x)}break;case"sctp-port":if(!T)throw Error();q.sctpPort=Number.parseInt(T);break;case"ssrc":{let[x,g]=m4(T," "),f=Number.parseInt(x),[y,p]=m4(g,":"),b=q.ssrc.find((m)=>m.ssrc===f);if(!b)b=new tO({ssrc:f}),q.ssrc.push(b);if(g2.includes(y))b[y]=p}break;case"ssrc-group":KO(q.ssrcGroup,T);break;case"rid":{let[x,g]=m4(T," ");q.simulcastParameters.push(new x2({rid:x,direction:g}))}break}}}),!q.iceParams.usernameFragment||!q.iceParams.password){if(q.rtp.muxId&&Z&&Z.items.includes(q.rtp.muxId))for(let w=0;w<Z.items.length;w++){if(!Z.items.includes(w.toString()))continue;let D=J.media[w];if(D.iceParams?.usernameFragment&&D.iceParams.password){q.iceParams={...D.iceParams};break}}}if(!q.dtlsParams.role)q.dtlsParams=void 0;let z=(w)=>q.rtp.codecs.find((D)=>D.payloadType===w);V.slice(1).forEach((w)=>{if(w.startsWith("a=")){let[D,T]=OO(w);if(D==="fmtp"){let[x,g]=m4(T," "),f=z(Number(x));f.parameters=g}else if(D==="rtcp-fb"){let[x,g,f]=T.split(" ");q.rtp.codecs.forEach((y)=>{if(["*",y.payloadType.toString()].includes(x))y.rtcpFeedback.push(new Hi({type:g,parameter:f}))})}}})}),J}webrtcTrackId(Y){if(Y.msid?.includes(" ")){let G=Y.msid.split(" ");for(let X of this.msidSemantic)if(X.semantic==="WMS"&&(X.items.includes(G[0])||X.items.includes("*")))return G[1]}return}get string(){let Y=[`v=${this.version}`,`o=${this.origin}`,`s=${this.name}`];if(this.host)Y.push(`c=${sO(this.host)}`);if(Y.push(`t=${this.time}`),this.group.forEach((J)=>Y.push(`a=group:${J.str}`)),this.extMapAllowMixed)Y.push("a=extmap-allow-mixed");this.msidSemantic.forEach((J)=>Y.push(`a=msid-semantic:${J.str}`));let G=this.media.map((J)=>J.toString()).join("");return Y.join(`\r
|
|
242
|
+
`)}}K9.CertificateTag="CERTIFICATE";K9.CrlTag="CRL";K9.CertificateRequestTag="CERTIFICATE REQUEST";K9.PublicKeyTag="PUBLIC KEY";K9.PrivateKeyTag="PRIVATE KEY";class C4 extends y6{static isAsnEncoded(W){return _0.isBufferSource(W)||typeof W==="string"}static toArrayBuffer(W){if(typeof W==="string")if(K9.isPem(W))return K9.decode(W)[0];else if(o0.isHex(W))return o0.FromHex(W);else if(o0.isBase64(W))return o0.FromBase64(W);else if(o0.isBase64Url(W))return o0.FromBase64Url(W);else throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url");else{let Y=_0.toUint8Array(W);if(Y.length>0&&Y[0]===48)return _0.toArrayBuffer(W);let G=o0.ToBinary(W);if(K9.isPem(G))return K9.decode(G)[0];else if(o0.isHex(G))return o0.FromHex(G);else if(o0.isBase64(G))return o0.FromBase64(G);else if(o0.isBase64Url(G))return o0.FromBase64Url(G);throw TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...W){if(C4.isAsnEncoded(W[0]))super(C4.toArrayBuffer(W[0]),W[1]);else super(W[0])}toString(W="pem"){switch(W){case"pem":return K9.encode(this.rawData,this.tag);default:return super.toString(W)}}}class o5 extends C4{static async create(W,Y=v8.get()){if(W instanceof o5)return W;else if(x6.isCryptoKey(W)){if(W.type!=="public")throw TypeError("Public key is required");let G=await Y.subtle.exportKey("spki",W);return new o5(G)}else if(W.publicKey)return W.publicKey;else if(_0.isBufferSource(W))return new o5(W);else throw TypeError("Unsupported PublicKeyType")}constructor(W){if(C4.isAsnEncoded(W))super(W,w9);else super(W);this.tag=K9.PublicKeyTag}async export(...W){let Y,G=["verify"],X={hash:"SHA-256",...this.algorithm};if(W.length>1)X=W[0]||X,G=W[1]||G,Y=W[2]||v8.get();else Y=W[0]||v8.get();let J=this.rawData,Z=E0.parse(this.rawData,w9);if(Z.algorithm.algorithm===E6)J=qc(Z,J);return Y.subtle.importKey("spki",J,X,!0,G)}onInit(W){let Y=Q8.resolve(ZY),G=this.algorithm=Y.toWebAlgorithm(W.algorithm);switch(W.algorithm.algorithm){case F7:{let X=E0.parse(W.subjectPublicKey,SZ),J=_0.toUint8Array(X.modulus);G.publicExponent=_0.toUint8Array(X.publicExponent),G.modulusLength=(!J[0]?J.slice(1):J).byteLength<<3;break}}}async getThumbprint(...W){var Y;let G,X="SHA-1";if(W.length>=1&&!((Y=W[0])===null||Y===void 0?void 0:Y.subtle))X=W[0]||X,G=W[1]||v8.get();else G=W[0]||v8.get();return await G.subtle.digest(X,this.rawData)}async getKeyIdentifier(...W){let Y,G="SHA-1";if(W.length===1)if(typeof W[0]==="string")G=W[0],Y=v8.get();else Y=W[0];else if(W.length===2)G=W[0],Y=W[1];else Y=v8.get();let X=E0.parse(this.rawData,w9);return await Y.subtle.digest(G,X.subjectPublicKey)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,w9);switch(W.Algorithm=k6.serializeAlgorithm(Y.algorithm),Y.algorithm.algorithm){case nW:W["EC Point"]=Y.subjectPublicKey;break;case F7:default:W["Raw Data"]=Y.subjectPublicKey}return W}}function qc(W,Y){return W.algorithm=new M0({algorithm:F7,parameters:null}),Y=E0.serialize(W),Y}class HV extends V5{static async create(W,Y=!1,G=v8.get()){if("name"in W&&"serialNumber"in W)return new HV(W,Y);let J=await(await o5.create(W,G)).getKeyIdentifier(G);return new HV(o0.ToHex(J),Y)}constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else if(typeof W[0]==="string"){let Y=new q4({keyIdentifier:new yG(o0.FromHex(W[0]))});super(HH,W[1],E0.serialize(Y))}else{let Y=W[0],G=Y.name instanceof _6?E0.parse(Y.name.rawData,z8):Y.name,X=new q4({authorityCertIssuer:G,authorityCertSerialNumber:o0.FromHex(Y.serialNumber)});super(HH,W[1],E0.serialize(X))}}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,q4);if(Y.keyIdentifier)this.keyId=o0.ToHex(Y.keyIdentifier);if(Y.authorityCertIssuer||Y.authorityCertSerialNumber)this.certId={name:Y.authorityCertIssuer||[],serialNumber:Y.authorityCertSerialNumber?o0.ToHex(Y.authorityCertSerialNumber):""}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,q4);if(Y.authorityCertIssuer)W["Authority Issuer"]=new _6(Y.authorityCertIssuer).toTextObject();if(Y.authorityCertSerialNumber)W["Authority Serial Number"]=Y.authorityCertSerialNumber;if(Y.keyIdentifier)W[""]=Y.keyIdentifier;return W}}HV.NAME="Authority Key Identifier";class Jj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,vG);this.ca=Y.cA,this.pathLength=Y.pathLenConstraint}else{let Y=new vG({cA:W[0],pathLenConstraint:W[1]});super(NH,W[2],E0.serialize(Y));this.ca=W[0],this.pathLength=W[1]}}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ca)W.CA=this.ca;if(this.pathLength!==void 0)W["Path Length"]=this.pathLength;return W}}Jj.NAME="Basic Constraints";var P3;(function(W){W.serverAuth="1.3.6.1.5.5.7.3.1",W.clientAuth="1.3.6.1.5.5.7.3.2",W.codeSigning="1.3.6.1.5.5.7.3.3",W.emailProtection="1.3.6.1.5.5.7.3.4",W.timeStamping="1.3.6.1.5.5.7.3.8",W.ocspSigning="1.3.6.1.5.5.7.3.9"})(P3||(P3={}));class Zj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,WZ);this.usages=Y.map((G)=>G)}else{let Y=new WZ(W[0]);super(KH,W[1],E0.serialize(Y));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[""]=this.usages.map((Y)=>T4.toString(Y)).join(", "),W}}Zj.NAME="Extended Key Usages";var L3;(function(W){W[W.digitalSignature=1]="digitalSignature",W[W.nonRepudiation=2]="nonRepudiation",W[W.keyEncipherment=4]="keyEncipherment",W[W.dataEncipherment=8]="dataEncipherment",W[W.keyAgreement=16]="keyAgreement",W[W.keyCertSign=32]="keyCertSign",W[W.cRLSign=64]="cRLSign",W[W.encipherOnly=128]="encipherOnly",W[W.decipherOnly=256]="decipherOnly"})(L3||(L3={}));class Vj extends V5{constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,GZ);this.usages=Y.toNumber()}else{let Y=new GZ(W[0]);super(DH,W[1],E0.serialize(Y));this.usages=W[0]}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,GZ);return W[""]=Y.toJSON().join(", "),W}}Vj.NAME="Key Usages";class tH extends V5{static async create(W,Y=!1,G=v8.get()){let J=await(await o5.create(W,G)).getKeyIdentifier(G);return new tH(o0.ToHex(J),Y)}constructor(...W){if(_0.isBufferSource(W[0])){super(W[0]);let Y=E0.parse(this.value,G5);this.keyId=o0.ToHex(Y)}else{let Y=typeof W[0]==="string"?o0.FromHex(W[0]):W[0],G=new G5(Y);super(bz,W[1],E0.serialize(G));this.keyId=o0.ToHex(Y)}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=E0.parse(this.value,G5);return W[""]=Y,W}}tH.NAME="Subject Key Identifier";class Uj extends V5{constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else super(uz,W[1],new _6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,RH);this.names=new _6(Y)}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.names.toTextObject();for(let G in Y)W[G]=Y[G];return W}}Uj.NAME="Subject Alternative Name";class o9{static register(W,Y){this.items.set(W,Y)}static create(W){let Y=new V5(W),G=this.items.get(Y.type);if(G)return new G(W);return Y}}o9.items=new Map;class Qj extends V5{constructor(...W){var Y;if(_0.isBufferSource(W[0])){super(W[0]);let G=E0.parse(this.value,aJ);this.policies=G.map((X)=>X.policyIdentifier)}else{let G=W[0],X=(Y=W[1])!==null&&Y!==void 0?Y:!1,J=new aJ(G.map((Z)=>new gG({policyIdentifier:Z})));super(AH,X,E0.serialize(J));this.policies=G}}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Policy=this.policies.map((Y)=>new o1("",{},T4.toString(Y))),W}}Qj.NAME="Certificate Policies";o9.register(AH,Qj);class Hj extends V5{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else if(Array.isArray(W[0])&&typeof W[0][0]==="string"){let X=W[0].map((Z)=>{return new z4({distributionPoint:new I4({fullName:[new Q1({uniformResourceIdentifier:Z})]})})}),J=new M6(X);super(jH,W[1],E0.serialize(J))}else{let G=new M6(W[0]);super(jH,W[1],E0.serialize(G))}(Y=this.distributionPoints)!==null&&Y!==void 0||(this.distributionPoints=[])}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,M6);this.distributionPoints=Y}toTextObject(){let W=this.toTextObjectWithoutValue();return W["Distribution Point"]=this.distributionPoints.map((Y)=>{var G;let X={};if(Y.distributionPoint)X[""]=(G=Y.distributionPoint.fullName)===null||G===void 0?void 0:G.map((J)=>new D4(J).toString()).join(", ");if(Y.reasons)X.Reasons=Y.reasons.toString();if(Y.cRLIssuer)X["CRL Issuer"]=Y.cRLIssuer.map((J)=>J.toString()).join(", ");return X}),W}}Hj.NAME="CRL Distribution Points";class Nj extends V5{constructor(...W){var Y,G,X,J;if(_0.isBufferSource(W[0]))super(W[0]);else if(W[0]instanceof yW){let Z=new yW(W[0]);super(QH,W[1],E0.serialize(Z))}else{let Z=W[0],V=new yW;rH(V,Z,Kz,"ocsp"),rH(V,Z,Dz,"caIssuers"),rH(V,Z,Cz,"timeStamping"),rH(V,Z,Tz,"caRepository");super(QH,W[1],E0.serialize(V))}(Y=this.ocsp)!==null&&Y!==void 0||(this.ocsp=[]),(G=this.caIssuers)!==null&&G!==void 0||(this.caIssuers=[]),(X=this.timeStamping)!==null&&X!==void 0||(this.timeStamping=[]),(J=this.caRepository)!==null&&J!==void 0||(this.caRepository=[])}onInit(W){super.onInit(W),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],E0.parse(W.extnValue,yW).forEach((G)=>{switch(G.accessMethod){case Kz:this.ocsp.push(new D4(G.accessLocation));break;case Dz:this.caIssuers.push(new D4(G.accessLocation));break;case Cz:this.timeStamping.push(new D4(G.accessLocation));break;case Tz:this.caRepository.push(new D4(G.accessLocation));break}})}toTextObject(){let W=this.toTextObjectWithoutValue();if(this.ocsp.length)iH(W,"OCSP",this.ocsp);if(this.caIssuers.length)iH(W,"CA Issuers",this.caIssuers);if(this.timeStamping.length)iH(W,"Time Stamping",this.timeStamping);if(this.caRepository.length)iH(W,"CA Repository",this.caRepository);return W}}Nj.NAME="Authority Info Access";function iH(W,Y,G){if(G.length===1)W[Y]=G[0].toTextObject();else{let X=new o1("");G.forEach((J,Z)=>{let V=J.toTextObject(),U=`${V[o1.NAME]} ${Z+1}`,Q=X[U];if(!Array.isArray(Q))Q=[],X[U]=Q;Q.push(V)}),W[Y]=X}}function rH(W,Y,G,X){let J=Y[X];if(J)(Array.isArray(J)?J:[J]).forEach((V)=>{if(typeof V==="string")V=new D4("url",V);W.push(new R6({accessMethod:G,accessLocation:E0.parse(V.rawData,Q1)}))})}class qj extends V5{constructor(...W){if(_0.isBufferSource(W[0]))super(W[0]);else super(xz,W[1],new _6(W[0]||[]).rawData)}onInit(W){super.onInit(W);let Y=E0.parse(W.extnValue,z8);this.names=new _6(Y)}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.names.toTextObject();for(let G in Y)W[G]=Y[G];return W}}qj.NAME="Issuer Alternative Name";class qX extends y6{constructor(...W){let Y;if(_0.isBufferSource(W[0]))Y=_0.toArrayBuffer(W[0]);else{let G=W[0],X=Array.isArray(W[1])?W[1].map((J)=>_0.toArrayBuffer(J)):[];Y=E0.serialize(new z9({type:G,values:X}))}super(Y,z9)}onInit(W){this.type=W.type,this.values=W.values}toTextObject(){let W=this.toTextObjectWithoutValue();return W.Value=this.values.map((Y)=>new o1("",{"":Y})),W}toTextObjectWithoutValue(){let W=this.toTextObjectEmpty();if(W[o1.NAME]===qX.NAME)W[o1.NAME]=T4.toString(this.type);return W}}qX.NAME="Attribute";class Aj extends qX{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else{let G=new uZ({printableString:W[0]});super(pw,[E0.serialize(G)])}(Y=this.password)!==null&&Y!==void 0||(this.password="")}onInit(W){if(super.onInit(W),this.values[0]){let Y=E0.parse(this.values[0],uZ);this.password=Y.toString()}}toTextObject(){let W=this.toTextObjectWithoutValue();return W[o1.VALUE]=this.password,W}}Aj.NAME="Challenge Password";class eH extends qX{constructor(...W){var Y;if(_0.isBufferSource(W[0]))super(W[0]);else{let G=W[0],X=new X5;for(let J of G)X.push(E0.parse(J.rawData,j9));super(bZ,[E0.serialize(X)])}(Y=this.items)!==null&&Y!==void 0||(this.items=[])}onInit(W){if(super.onInit(W),this.values[0]){let Y=E0.parse(this.values[0],X5);this.items=Y.map((G)=>o9.create(E0.serialize(G)))}}toTextObject(){let W=this.toTextObjectWithoutValue(),Y=this.items.map((G)=>G.toTextObject());for(let G of Y)W[G[o1.NAME]]=G;return W}}eH.NAME="Extensions";class qV{static register(W,Y){this.items.set(W,Y)}static create(W){let Y=new qX(W),G=this.items.get(Y.type);if(G)return new G(W);return Y}}qV.items=new Map;var AV="crypto.signatureFormatter";class v3{toAsnSignature(W,Y){return _0.toArrayBuffer(Y)}toWebSignature(W,Y){return _0.toArrayBuffer(Y)}}var sH,Wj=sH=class{static createPssParams(Y,G){let X=sH.getHashAlgorithm(Y);if(!X)return null;return new O4({hashAlgorithm:X,maskGenAlgorithm:new M0({algorithm:$6,parameters:E0.serialize(X)}),saltLength:G})}static getHashAlgorithm(Y){let G=Q8.resolve(ZY);if(typeof Y==="string")return G.toAsnAlgorithm({name:Y});if(typeof Y==="object"&&Y&&"name"in Y)return G.toAsnAlgorithm(Y);return null}toAsnAlgorithm(Y){switch(Y.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in Y){let G;if(typeof Y.hash==="string")G=Y.hash;else if(Y.hash&&typeof Y.hash==="object"&&"name"in Y.hash&&typeof Y.hash.name==="string")G=Y.hash.name.toUpperCase();else throw Error("Cannot get hash algorithm name");switch(G.toLowerCase()){case"sha-1":return new M0({algorithm:tG,parameters:null});case"sha-256":return new M0({algorithm:gH,parameters:null});case"sha-384":return new M0({algorithm:eG,parameters:null});case"sha-512":return new M0({algorithm:WX,parameters:null})}}else return new M0({algorithm:F7,parameters:null});break;case"rsa-pss":if("hash"in Y){if(!(("saltLength"in Y)&&typeof Y.saltLength==="number"))throw Error("Cannot get 'saltLength' from 'alg' argument");let G=sH.createPssParams(Y.hash,Y.saltLength);if(!G)throw Error("Cannot create PSS parameters");return new M0({algorithm:E6,parameters:E0.serialize(G)})}else return new M0({algorithm:E6,parameters:null})}return null}toWebAlgorithm(Y){switch(Y.algorithm){case F7:return{name:"RSASSA-PKCS1-v1_5"};case tG:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case gH:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case eG:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case WX:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case E6:if(Y.parameters){let G=E0.parse(Y.parameters,O4);return{name:"RSA-PSS",hash:Q8.resolve(ZY).toWebAlgorithm(G.hashAlgorithm),saltLength:G.saltLength}}else return{name:"RSA-PSS"}}return null}};Wj=sH=j([S6()],Wj);Q8.registerSingleton(NV,Wj);var Yj=class{toAsnAlgorithm(Y){switch(Y.name.toLowerCase()){case"sha-1":return new M0({algorithm:iW});case"sha-256":return new M0({algorithm:rW});case"sha-384":return new M0({algorithm:aW});case"sha-512":return new M0({algorithm:sW})}return null}toWebAlgorithm(Y){switch(Y.algorithm){case iW:return{name:"SHA-1"};case rW:return{name:"SHA-256"};case aW:return{name:"SHA-384"};case sW:return{name:"SHA-512"}}return null}};Yj=j([S6()],Yj);Q8.registerSingleton(NV,Yj);class P5{addPadding(W,Y){let G=_0.toUint8Array(Y),X=new Uint8Array(W);return X.set(G,W-G.length),X.buffer}removePadding(W,Y=!1){let G=_0.toUint8Array(W);for(let X=0;X<G.length;X++){if(!G[X])continue;G=G.slice(X);break}if(Y&&G[0]>127){let X=new Uint8Array(G.length+1);return X.set(G,1),X.buffer}return G.buffer}toAsnSignature(W,Y){if(W.name==="ECDSA"){let G=W.namedCurve,X=P5.namedCurveSize.get(G)||P5.defaultNamedCurveSize,J=new sG,Z=_0.toUint8Array(Y);return J.r=this.removePadding(Z.slice(0,X),!0),J.s=this.removePadding(Z.slice(X,X+X),!0),E0.serialize(J)}return null}toWebSignature(W,Y){if(W.name==="ECDSA"){let G=E0.parse(Y,sG),X=W.namedCurve,J=P5.namedCurveSize.get(X)||P5.defaultNamedCurveSize,Z=this.addPadding(J,this.removePadding(G.r)),V=this.addPadding(J,this.removePadding(G.s));return _R(Z,V)}return null}}P5.namedCurveSize=new Map;P5.defaultNamedCurveSize=32;var tw="1.3.101.110",B3="1.3.101.111",ew="1.3.101.112",E3="1.3.101.113",Gj=class{toAsnAlgorithm(Y){let G=null;switch(Y.name.toLowerCase()){case"ed25519":G=ew;break;case"x25519":G=tw;break;case"eddsa":switch(Y.namedCurve.toLowerCase()){case"ed25519":G=ew;break;case"ed448":G=E3;break}break;case"ecdh-es":switch(Y.namedCurve.toLowerCase()){case"x25519":G=tw;break;case"x448":G=B3;break}}if(G)return new M0({algorithm:G});return null}toWebAlgorithm(Y){switch(Y.algorithm){case ew:return{name:"Ed25519"};case E3:return{name:"EdDSA",namedCurve:"Ed448"};case tw:return{name:"X25519"};case B3:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Gj=j([S6()],Gj);Q8.registerSingleton(NV,Gj);var cZ,pZ,lZ,dZ,oZ,nZ,iZ,QX;class g3 extends C4{get subjectName(){if(!R1(this,pZ,"f"))I8(this,pZ,new d5(this.asn.certificationRequestInfo.subject),"f");return R1(this,pZ,"f")}get subject(){if(!R1(this,lZ,"f"))I8(this,lZ,this.subjectName.toString(),"f");return R1(this,lZ,"f")}get signatureAlgorithm(){if(!R1(this,dZ,"f")){let W=Q8.resolve(ZY);I8(this,dZ,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return R1(this,dZ,"f")}get signature(){if(!R1(this,oZ,"f"))I8(this,oZ,this.asn.signature,"f");return R1(this,oZ,"f")}get publicKey(){if(!R1(this,nZ,"f"))I8(this,nZ,new o5(this.asn.certificationRequestInfo.subjectPKInfo),"f");return R1(this,nZ,"f")}get attributes(){if(!R1(this,iZ,"f"))I8(this,iZ,this.asn.certificationRequestInfo.attributes.map((W)=>qV.create(E0.serialize(W))),"f");return R1(this,iZ,"f")}get extensions(){if(!R1(this,QX,"f")){I8(this,QX,[],"f");let W=this.getAttribute(bZ);if(W instanceof eH)I8(this,QX,W.items,"f")}return R1(this,QX,"f")}get tbs(){if(!R1(this,cZ,"f"))I8(this,cZ,this.asn.certificationRequestInfoRaw||E0.serialize(this.asn.certificationRequestInfo),"f");return R1(this,cZ,"f")}constructor(W){let Y=C4.isAsnEncoded(W)?[W,JY]:[W];super(Y[0],Y[1]);cZ.set(this,void 0),pZ.set(this,void 0),lZ.set(this,void 0),dZ.set(this,void 0),oZ.set(this,void 0),nZ.set(this,void 0),iZ.set(this,void 0),QX.set(this,void 0),this.tag=K9.CertificateRequestTag}onInit(W){}getAttribute(W){for(let Y of this.attributes)if(Y.type===W)return Y;return null}getAttributes(W){return this.attributes.filter((Y)=>Y.type===W)}getExtension(W){for(let Y of this.extensions)if(Y.type===W)return Y;return null}getExtensions(W){return this.extensions.filter((Y)=>Y.type===W)}async verify(W=v8.get()){let Y={...this.publicKey.algorithm,...this.signatureAlgorithm},G=await this.publicKey.export(Y,["verify"],W),X=Q8.resolveAll(AV).reverse(),J=null;for(let V of X)if(J=V.toWebSignature(Y,this.signature),J)break;if(!J)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await W.subtle.verify(this.signatureAlgorithm,G,J,this.tbs)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,JY),G=Y.certificationRequestInfo,X=new o1("",{Version:`${P7[G.version]} (${G.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let J=new o1("");for(let Z of this.attributes){let V=Z.toTextObject();J[V[o1.NAME]]=V}X.Attributes=J}return W.Data=X,W.Signature=new o1("",{Algorithm:k6.serializeAlgorithm(Y.signatureAlgorithm),"":Y.signature}),W}}cZ=new WeakMap,pZ=new WeakMap,lZ=new WeakMap,dZ=new WeakMap,oZ=new WeakMap,nZ=new WeakMap,iZ=new WeakMap,QX=new WeakMap;g3.NAME="PKCS#10 Certificate Request";var rZ,aZ,sZ,tZ,eZ,WV,YV,GV,XV,JV,HX,ZV;class Ij extends C4{get publicKey(){if(!R1(this,ZV,"f"))I8(this,ZV,new o5(this.asn.tbsCertificate.subjectPublicKeyInfo),"f");return R1(this,ZV,"f")}get serialNumber(){if(!R1(this,aZ,"f")){let W=this.asn.tbsCertificate,Y=new Uint8Array(W.serialNumber);if(Y.length>1&&Y[0]===0&&Y[1]>127)Y=Y.slice(1);I8(this,aZ,o0.ToHex(Y),"f")}return R1(this,aZ,"f")}get subjectName(){if(!R1(this,sZ,"f"))I8(this,sZ,new d5(this.asn.tbsCertificate.subject),"f");return R1(this,sZ,"f")}get subject(){if(!R1(this,tZ,"f"))I8(this,tZ,this.subjectName.toString(),"f");return R1(this,tZ,"f")}get issuerName(){if(!R1(this,eZ,"f"))I8(this,eZ,new d5(this.asn.tbsCertificate.issuer),"f");return R1(this,eZ,"f")}get issuer(){if(!R1(this,WV,"f"))I8(this,WV,this.issuerName.toString(),"f");return R1(this,WV,"f")}get notBefore(){if(!R1(this,YV,"f")){let W=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!W)throw Error("Cannot get 'notBefore' value");I8(this,YV,W,"f")}return R1(this,YV,"f")}get notAfter(){if(!R1(this,GV,"f")){let W=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!W)throw Error("Cannot get 'notAfter' value");I8(this,GV,W,"f")}return R1(this,GV,"f")}get signatureAlgorithm(){if(!R1(this,XV,"f")){let W=Q8.resolve(ZY);I8(this,XV,W.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return R1(this,XV,"f")}get signature(){if(!R1(this,JV,"f"))I8(this,JV,this.asn.signatureValue,"f");return R1(this,JV,"f")}get extensions(){if(!R1(this,HX,"f")){if(I8(this,HX,[],"f"),this.asn.tbsCertificate.extensions)I8(this,HX,this.asn.tbsCertificate.extensions.map((W)=>o9.create(E0.serialize(W))),"f")}return R1(this,HX,"f")}get tbs(){if(!R1(this,rZ,"f"))I8(this,rZ,this.asn.tbsCertificateRaw||E0.serialize(this.asn.tbsCertificate),"f");return R1(this,rZ,"f")}constructor(W){let Y=C4.isAsnEncoded(W)?[W,m5]:[W];super(Y[0],Y[1]);rZ.set(this,void 0),aZ.set(this,void 0),sZ.set(this,void 0),tZ.set(this,void 0),eZ.set(this,void 0),WV.set(this,void 0),YV.set(this,void 0),GV.set(this,void 0),XV.set(this,void 0),JV.set(this,void 0),HX.set(this,void 0),ZV.set(this,void 0),this.tag=K9.CertificateTag}onInit(W){}getExtension(W){for(let Y of this.extensions)if(typeof W==="string"){if(Y.type===W)return Y}else if(Y instanceof W)return Y;return null}getExtensions(W){return this.extensions.filter((Y)=>{if(typeof W==="string")return Y.type===W;else return Y instanceof W})}async verify(W={},Y=v8.get()){let G,X,J=W.publicKey;try{if(!J)G={...this.publicKey.algorithm,...this.signatureAlgorithm},X=await this.publicKey.export(G,["verify"],Y);else if("publicKey"in J)G={...J.publicKey.algorithm,...this.signatureAlgorithm},X=await J.publicKey.export(G,["verify"],Y);else if(J instanceof o5)G={...J.algorithm,...this.signatureAlgorithm},X=await J.export(G,["verify"],Y);else if(_0.isBufferSource(J)){let Q=new o5(J);G={...Q.algorithm,...this.signatureAlgorithm},X=await Q.export(G,["verify"],Y)}else G={...J.algorithm,...this.signatureAlgorithm},X=J}catch{return!1}let Z=Q8.resolveAll(AV).reverse(),V=null;for(let Q of Z)if(V=Q.toWebSignature(G,this.signature),V)break;if(!V)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let U=await Y.subtle.verify(this.signatureAlgorithm,X,V,this.tbs);if(W.signatureOnly)return U;else{let H=(W.date||new Date).getTime();return U&&this.notBefore.getTime()<H&&H<this.notAfter.getTime()}}async getThumbprint(...W){let Y,G="SHA-1";if(W[0])if(!W[0].subtle)G=W[0]||G,Y=W[1];else Y=W[0];return Y!==null&&Y!==void 0||(Y=v8.get()),await Y.subtle.digest(G,this.rawData)}async isSelfSigned(W=v8.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},W)}toTextObject(){let W=this.toTextObjectEmpty(),Y=E0.parse(this.rawData,m5),G=Y.tbsCertificate,X=new o1("",{Version:`${P7[G.version]} (${G.version})`,"Serial Number":G.serialNumber,"Signature Algorithm":k6.serializeAlgorithm(G.signature),Issuer:this.issuer,Validity:new o1("",{"Not Before":G.validity.notBefore.getTime(),"Not After":G.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(G.issuerUniqueID)X["Issuer Unique ID"]=G.issuerUniqueID;if(G.subjectUniqueID)X["Subject Unique ID"]=G.subjectUniqueID;if(this.extensions.length){let J=new o1("");for(let Z of this.extensions){let V=Z.toTextObject();J[V[o1.NAME]]=V}X.Extensions=J}return W.Data=X,W.Signature=new o1("",{Algorithm:k6.serializeAlgorithm(Y.signatureAlgorithm),"":Y.signatureValue}),W}}rZ=new WeakMap,aZ=new WeakMap,sZ=new WeakMap,tZ=new WeakMap,eZ=new WeakMap,WV=new WeakMap,YV=new WeakMap,GV=new WeakMap,XV=new WeakMap,JV=new WeakMap,HX=new WeakMap,ZV=new WeakMap;Ij.NAME="Certificate";function Ac(W,Y=v8.get()){let G=_0.toUint8Array(o0.FromHex(W||"")),X=G&&G.length&&G.some((Z)=>Z>0)?new Uint8Array(G):void 0;if(!X)X=Y.getRandomValues(new Uint8Array(16));let J=0;while(J<X.length-1&&X[J]===0)J++;if(X=X.slice(J),X[0]>127){let Z=new Uint8Array(X.length+1);Z[0]=0,Z.set(X,1),X=Z}return X.buffer}class zj{static async createSelfSigned(W,Y=v8.get()){if(!W.keys.privateKey)throw Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!W.keys.publicKey)throw Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:W.serialNumber,subject:W.name,issuer:W.name,notBefore:W.notBefore,notAfter:W.notAfter,publicKey:W.keys.publicKey,signingKey:W.keys.privateKey,signingAlgorithm:W.signingAlgorithm,extensions:W.extensions},Y)}static async create(W,Y=v8.get()){var G;let X;if(W.publicKey instanceof o5)X=W.publicKey.rawData;else if("publicKey"in W.publicKey)X=W.publicKey.publicKey.rawData;else if(_0.isBufferSource(W.publicKey))X=W.publicKey;else X=await Y.subtle.exportKey("spki",W.publicKey);let J=Ac(W.serialNumber,Y),Z=W.notBefore||new Date,V=W.notAfter||new Date(Z.getTime()+31536000000),U=new m5({tbsCertificate:new O9({version:P7.v3,serialNumber:J,validity:new P6({notBefore:Z,notAfter:V}),extensions:new X5(((G=W.extensions)===null||G===void 0?void 0:G.map((D)=>E0.parse(D.rawData,j9)))||[]),subjectPublicKeyInfo:E0.parse(X,w9)})});if(W.subject){let D=W.subject instanceof d5?W.subject:new d5(W.subject);U.tbsCertificate.subject=E0.parse(D.toArrayBuffer(),G8)}if(W.issuer){let D=W.issuer instanceof d5?W.issuer:new d5(W.issuer);U.tbsCertificate.issuer=E0.parse(D.toArrayBuffer(),G8)}let Q={hash:"SHA-256"},H="signingKey"in W?{...Q,...W.signingAlgorithm,...W.signingKey.algorithm}:{...Q,...W.signingAlgorithm},N=Q8.resolve(ZY);U.tbsCertificate.signature=U.signatureAlgorithm=N.toAsnAlgorithm(H);let A=E0.serialize(U.tbsCertificate),q="signingKey"in W?await Y.subtle.sign(H,W.signingKey,A):W.signature,z=Q8.resolveAll(AV).reverse(),w=null;for(let D of z)if(w=D.toAsnSignature(H,q),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return U.signatureValue=w,new Ij(E0.serialize(U))}}var Ic,zc,wc,jc,Oc,$3;(function(W){W[W.unspecified=0]="unspecified",W[W.keyCompromise=1]="keyCompromise",W[W.cACompromise=2]="cACompromise",W[W.affiliationChanged=3]="affiliationChanged",W[W.superseded=4]="superseded",W[W.cessationOfOperation=5]="cessationOfOperation",W[W.certificateHold=6]="certificateHold",W[W.removeFromCRL=8]="removeFromCRL",W[W.privilegeWithdrawn=9]="privilegeWithdrawn",W[W.aACompromise=10]="aACompromise"})($3||($3={}));Ic=new WeakMap,zc=new WeakMap,wc=new WeakMap,jc=new WeakMap,Oc=new WeakMap;var Kc,Dc,Cc,Tc,Rc,Mc,Pc;Kc=new WeakMap,Dc=new WeakMap,Cc=new WeakMap,Tc=new WeakMap,Rc=new WeakMap,Mc=new WeakMap,Pc=new WeakMap;o9.register(NH,Jj);o9.register(KH,Zj);o9.register(DH,Vj);o9.register(bz,tH);o9.register(HH,HV);o9.register(uz,Uj);o9.register(jH,Hj);o9.register(QH,Nj);o9.register(xz,qj);qV.register(pw,Aj);qV.register(bZ,eH);Q8.registerSingleton(AV,v3);Q8.registerSingleton(AV,P5);P5.namedCurveSize.set("P-256",32);P5.namedCurveSize.set("K-256",32);P5.namedCurveSize.set("P-384",48);P5.namedCurveSize.set("P-521",66);var gX=v1(j8(),1),FS=v1(j8(),1),SS=v1(xQ(),1);import{createHash as pd,createHmac as ld}from"crypto";import*as R4 from"crypto";var UY=R4&&typeof R4==="object"&&"webcrypto"in R4?R4.webcrypto:R4&&typeof R4==="object"&&("randomBytes"in R4)?R4:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function QY(W){return W instanceof Uint8Array||ArrayBuffer.isView(W)&&W.constructor.name==="Uint8Array"}function DV(W){if(!Number.isSafeInteger(W)||W<0)throw Error("positive integer expected, got "+W)}function n5(W,...Y){if(!QY(W))throw Error("Uint8Array expected");if(Y.length>0&&!Y.includes(W.length))throw Error("Uint8Array expected of length "+Y+", got length="+W.length)}function UN(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");DV(W.outputLen),DV(W.blockLen)}function wX(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function wE(W,Y){n5(W);let G=Y.outputLen;if(W.length<G)throw Error("digestInto() expects output buffer of length at least "+G)}function P4(...W){for(let Y=0;Y<W.length;Y++)W[Y].fill(0)}function QN(W){return new DataView(W.buffer,W.byteOffset,W.byteLength)}function i5(W,Y){return W<<32-Y|W>>>Y}var jE=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")(),ep=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function L4(W){if(n5(W),jE)return W.toHex();let Y="";for(let G=0;G<W.length;G++)Y+=ep[W[G]];return Y}var M4={_0:48,_9:57,A:65,F:70,a:97,f:102};function zE(W){if(W>=M4._0&&W<=M4._9)return W-M4._0;if(W>=M4.A&&W<=M4.F)return W-(M4.A-10);if(W>=M4.a&&W<=M4.f)return W-(M4.a-10);return}function HY(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);if(jE)return Uint8Array.fromHex(W);let Y=W.length,G=Y/2;if(Y%2)throw Error("hex string expected, got unpadded hex of length "+Y);let X=new Uint8Array(G);for(let J=0,Z=0;J<G;J++,Z+=2){let V=zE(W.charCodeAt(Z)),U=zE(W.charCodeAt(Z+1));if(V===void 0||U===void 0){let Q=W[Z]+W[Z+1];throw Error('hex string expected, got non-hex character "'+Q+'" at index '+Z)}X[J]=V*16+U}return X}function HN(W){if(typeof W!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(W))}function CV(W){if(typeof W==="string")W=HN(W);return n5(W),W}function i9(...W){let Y=0;for(let X=0;X<W.length;X++){let J=W[X];n5(J),Y+=J.length}let G=new Uint8Array(Y);for(let X=0,J=0;X<W.length;X++){let Z=W[X];G.set(Z,J),J+=Z.length}return G}class TV{}function NN(W){let Y=(X)=>W().update(CV(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function NY(W=32){if(UY&&typeof UY.getRandomValues==="function")return UY.getRandomValues(new Uint8Array(W));if(UY&&typeof UY.randomBytes==="function")return Uint8Array.from(UY.randomBytes(W));throw Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Ej=BigInt(0),Bj=BigInt(1);function RV(W,Y=""){if(typeof W!=="boolean"){let G=Y&&`"${Y}"`;throw Error(G+"expected boolean, got type="+typeof W)}return W}function m6(W,Y,G=""){let X=QY(W),J=W?.length,Z=Y!==void 0;if(!X||Z&&J!==Y){let V=G&&`"${G}" `,U=Z?` of length ${Y}`:"",Q=X?`length=${J}`:`type=${typeof W}`;throw Error(V+"expected Uint8Array"+U+", got "+Q)}return W}function MV(W){let Y=W.toString(16);return Y.length&1?"0"+Y:Y}function OE(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return W===""?Ej:BigInt("0x"+W)}function B4(W){return OE(L4(W))}function $j(W){return n5(W),OE(L4(Uint8Array.from(W).reverse()))}function jX(W,Y){return HY(W.toString(16).padStart(Y*2,"0"))}function Fj(W,Y){return jX(W,Y).reverse()}function B8(W,Y,G){let X;if(typeof Y==="string")try{X=HY(Y)}catch(Z){throw Error(W+" must be hex string or Uint8Array, cause: "+Z)}else if(QY(Y))X=Uint8Array.from(Y);else throw Error(W+" must be hex string or Uint8Array");let J=X.length;if(typeof G==="number"&&J!==G)throw Error(W+" of length "+G+" expected, got "+J);return X}var Lj=(W)=>typeof W==="bigint"&&Ej<=W;function PV(W,Y,G){return Lj(W)&&Lj(Y)&&Lj(G)&&Y<=W&&W<G}function KE(W,Y,G,X){if(!PV(Y,G,X))throw Error("expected valid "+W+": "+G+" <= n < "+X+", got "+Y)}function qN(W){let Y;for(Y=0;W>Ej;W>>=Bj,Y+=1);return Y}var f6=(W)=>(Bj<<BigInt(W))-Bj;function DE(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=(z)=>new Uint8Array(z),J=(z)=>Uint8Array.of(z),Z=X(W),V=X(W),U=0,Q=()=>{Z.fill(1),V.fill(0),U=0},H=(...z)=>G(V,Z,...z),N=(z=X(0))=>{if(V=H(J(0),z),Z=H(),z.length===0)return;V=H(J(1),z),Z=H()},A=()=>{if(U++>=1000)throw Error("drbg: tried 1000 values");let z=0,w=[];while(z<Y){Z=H();let D=Z.slice();w.push(D),z+=Z.length}return i9(...w)};return(z,w)=>{Q(),N(z);let D=void 0;while(!(D=w(A())))N();return Q(),D}}function LV(W,Y,G={}){if(!W||typeof W!=="object")throw Error("expected valid options object");function X(J,Z,V){let U=W[J];if(V&&U===void 0)return;let Q=typeof U;if(Q!==Z||U===null)throw Error(`param "${J}" is invalid: expected ${Z}, got ${Q}`)}Object.entries(Y).forEach(([J,Z])=>X(J,Z,!1)),Object.entries(G).forEach(([J,Z])=>X(J,Z,!0))}function Sj(W){let Y=new WeakMap;return(G,...X)=>{let J=Y.get(G);if(J!==void 0)return J;let Z=W(G,...X);return Y.set(G,Z),Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var v9=BigInt(0),D9=BigInt(1),qY=BigInt(2),RE=BigInt(3),ME=BigInt(4),PE=BigInt(5),Wl=BigInt(7),LE=BigInt(8),Yl=BigInt(9),BE=BigInt(16);function U5(W,Y){let G=W%Y;return G>=v9?G:Y+G}function Q5(W,Y,G){let X=W;while(Y-- >v9)X*=X,X%=G;return X}function CE(W,Y){if(W===v9)throw Error("invert: expected non-zero number");if(Y<=v9)throw Error("invert: expected positive modulus, got "+Y);let G=U5(W,Y),X=Y,J=v9,Z=D9,V=D9,U=v9;while(G!==v9){let H=X/G,N=X%G,A=J-V*H,q=Z-U*H;X=G,G=N,J=V,Z=U,V=A,U=q}if(X!==D9)throw Error("invert: does not exist");return U5(J,Y)}function xj(W,Y,G){if(!W.eql(W.sqr(Y),G))throw Error("Cannot find square root")}function EE(W,Y){let G=(W.ORDER+D9)/ME,X=W.pow(Y,G);return xj(W,X,Y),X}function Gl(W,Y){let G=(W.ORDER-PE)/LE,X=W.mul(Y,qY),J=W.pow(X,G),Z=W.mul(Y,J),V=W.mul(W.mul(Z,qY),J),U=W.mul(Z,W.sub(V,W.ONE));return xj(W,U,Y),U}function Xl(W){let Y=B5(W),G=$E(W),X=G(Y,Y.neg(Y.ONE)),J=G(Y,X),Z=G(Y,Y.neg(X)),V=(W+Wl)/BE;return(U,Q)=>{let H=U.pow(Q,V),N=U.mul(H,X),A=U.mul(H,J),q=U.mul(H,Z),z=U.eql(U.sqr(N),Q),w=U.eql(U.sqr(A),Q);H=U.cmov(H,N,z),N=U.cmov(q,A,w);let D=U.eql(U.sqr(N),Q),T=U.cmov(H,N,D);return xj(U,T,Q),T}}function $E(W){if(W<RE)throw Error("sqrt is not defined for small field");let Y=W-D9,G=0;while(Y%qY===v9)Y/=qY,G++;let X=qY,J=B5(W);while(TE(J,X)===1)if(X++>1000)throw Error("Cannot find square root: probably non-prime P");if(G===1)return EE;let Z=J.pow(X,Y),V=(Y+D9)/qY;return function(Q,H){if(Q.is0(H))return H;if(TE(Q,H)!==1)throw Error("Cannot find square root");let N=G,A=Q.mul(Q.ONE,Z),q=Q.pow(H,Y),z=Q.pow(H,V);while(!Q.eql(q,Q.ONE)){if(Q.is0(q))return Q.ZERO;let w=1,D=Q.sqr(q);while(!Q.eql(D,Q.ONE))if(w++,D=Q.sqr(D),w===N)throw Error("Cannot find square root");let T=D9<<BigInt(N-w-1),x=Q.pow(A,T);N=w,A=Q.sqr(x),q=Q.mul(q,A),z=Q.mul(z,x)}return z}}function Jl(W){if(W%ME===RE)return EE;if(W%LE===PE)return Gl;if(W%BE===Yl)return Xl(W);return $E(W)}var Zl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kj(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=Zl.reduce((X,J)=>{return X[J]="function",X},Y);return LV(W,G),W}function Vl(W,Y,G){if(G<v9)throw Error("invalid exponent, negatives unsupported");if(G===v9)return W.ONE;if(G===D9)return Y;let X=W.ONE,J=Y;while(G>v9){if(G&D9)X=W.mul(X,J);J=W.sqr(J),G>>=D9}return X}function AN(W,Y,G=!1){let X=Array(Y.length).fill(G?W.ZERO:void 0),J=Y.reduce((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=V,W.mul(V,U)},W.ONE),Z=W.inv(J);return Y.reduceRight((V,U,Q)=>{if(W.is0(U))return V;return X[Q]=W.mul(V,X[Q]),W.mul(V,U)},Z),X}function TE(W,Y){let G=(W.ORDER-D9)/qY,X=W.pow(Y,G),J=W.eql(X,W.ONE),Z=W.eql(X,W.ZERO),V=W.eql(X,W.neg(W.ONE));if(!J&&!Z&&!V)throw Error("invalid Legendre symbol result");return J?1:Z?0:-1}function IN(W,Y){if(Y!==void 0)DV(Y);let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function B5(W,Y,G=!1,X={}){if(W<=v9)throw Error("invalid field: expected ORDER > 0, got "+W);let J=void 0,Z=void 0,V=!1,U=void 0;if(typeof Y==="object"&&Y!=null){if(X.sqrt||G)throw Error("cannot specify opts in two arguments");let q=Y;if(q.BITS)J=q.BITS;if(q.sqrt)Z=q.sqrt;if(typeof q.isLE==="boolean")G=q.isLE;if(typeof q.modFromBytes==="boolean")V=q.modFromBytes;U=q.allowedLengths}else{if(typeof Y==="number")J=Y;if(X.sqrt)Z=X.sqrt}let{nBitLength:Q,nByteLength:H}=IN(W,J);if(H>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let N,A=Object.freeze({ORDER:W,isLE:G,BITS:Q,BYTES:H,MASK:f6(Q),ZERO:v9,ONE:D9,allowedLengths:U,create:(q)=>U5(q,W),isValid:(q)=>{if(typeof q!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof q);return v9<=q&&q<W},is0:(q)=>q===v9,isValidNot0:(q)=>!A.is0(q)&&A.isValid(q),isOdd:(q)=>(q&D9)===D9,neg:(q)=>U5(-q,W),eql:(q,z)=>q===z,sqr:(q)=>U5(q*q,W),add:(q,z)=>U5(q+z,W),sub:(q,z)=>U5(q-z,W),mul:(q,z)=>U5(q*z,W),pow:(q,z)=>Vl(A,q,z),div:(q,z)=>U5(q*CE(z,W),W),sqrN:(q)=>q*q,addN:(q,z)=>q+z,subN:(q,z)=>q-z,mulN:(q,z)=>q*z,inv:(q)=>CE(q,W),sqrt:Z||((q)=>{if(!N)N=Jl(W);return N(A,q)}),toBytes:(q)=>G?Fj(q,H):jX(q,H),fromBytes:(q,z=!0)=>{if(U){if(!U.includes(q.length)||q.length>H)throw Error("Field.fromBytes: expected "+U+" bytes, got "+q.length);let D=new Uint8Array(H);D.set(q,G?0:D.length-q.length),q=D}if(q.length!==H)throw Error("Field.fromBytes: expected "+H+" bytes, got "+q.length);let w=G?$j(q):B4(q);if(V)w=U5(w,W);if(!z){if(!A.isValid(w))throw Error("invalid field element: outside of range 0..ORDER")}return w},invertBatch:(q)=>AN(A,q),cmov:(q,z,w)=>w?z:q});return Object.freeze(A)}function FE(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function _j(W){let Y=FE(W);return Y+Math.ceil(Y/2)}function zN(W,Y,G=!1){let X=W.length,J=FE(Y),Z=_j(Y);if(X<16||X<Z||X>1024)throw Error("expected "+Z+"-1024 bytes of input, got "+X);let V=G?$j(W):B4(W),U=U5(V,Y-D9)+D9;return G?Fj(U,J):jX(U,J)}function Ul(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}function SE(W,Y,G){return W&Y^~W&G}function xE(W,Y,G){return W&Y^W&G^Y&G}class wN extends TV{constructor(W,Y,G,X){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.buffer=new Uint8Array(W),this.view=QN(this.buffer)}update(W){wX(this),W=CV(W),n5(W);let{view:Y,buffer:G,blockLen:X}=this,J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=QN(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){wX(this),wE(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,P4(this.buffer.subarray(Z)),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Ul(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=QN(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.destroyed=Z,W.finished=J,W.length=X,W.pos=V,X%Y)W.buffer.set(G);return W}clone(){return this._cloneInto()}}var E4=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var G9=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),X9=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var jN=BigInt(4294967295),kE=BigInt(32);function Ql(W,Y=!1){if(Y)return{h:Number(W&jN),l:Number(W>>kE&jN)};return{h:Number(W>>kE&jN)|0,l:Number(W&jN)|0}}function _E(W,Y=!1){let G=W.length,X=new Uint32Array(G),J=new Uint32Array(G);for(let Z=0;Z<G;Z++){let{h:V,l:U}=Ql(W[Z],Y);[X[Z],J[Z]]=[V,U]}return[X,J]}var yj=(W,Y,G)=>W>>>G,vj=(W,Y,G)=>W<<32-G|Y>>>G,AY=(W,Y,G)=>W>>>G|Y<<32-G,IY=(W,Y,G)=>W<<32-G|Y>>>G,BV=(W,Y,G)=>W<<64-G|Y>>>G-32,EV=(W,Y,G)=>W>>>G-32|Y<<64-G;function k7(W,Y,G,X){let J=(Y>>>0)+(X>>>0);return{h:W+G+(J/4294967296|0)|0,l:J|0}}var yE=(W,Y,G)=>(W>>>0)+(Y>>>0)+(G>>>0),vE=(W,Y,G,X)=>Y+G+X+(W/4294967296|0)|0,gE=(W,Y,G,X)=>(W>>>0)+(Y>>>0)+(G>>>0)+(X>>>0),uE=(W,Y,G,X,J)=>Y+G+X+J+(W/4294967296|0)|0,hE=(W,Y,G,X,J)=>(W>>>0)+(Y>>>0)+(G>>>0)+(X>>>0)+(J>>>0),bE=(W,Y,G,X,J,Z)=>Y+G+X+J+Z+(W/4294967296|0)|0;var Nl=Uint32Array.from([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]),c6=new Uint32Array(64);class mE extends wN{constructor(W=32){super(64,W,8,!1);this.A=E4[0]|0,this.B=E4[1]|0,this.C=E4[2]|0,this.D=E4[3]|0,this.E=E4[4]|0,this.F=E4[5]|0,this.G=E4[6]|0,this.H=E4[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)c6[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=c6[N-15],q=c6[N-2],z=i5(A,7)^i5(A,18)^A>>>3,w=i5(q,17)^i5(q,19)^q>>>10;c6[N]=w+c6[N-7]+z+c6[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=i5(V,6)^i5(V,11)^i5(V,25),q=H+A+SE(V,U,Q)+Nl[N]+c6[N]|0,w=(i5(G,2)^i5(G,13)^i5(G,22))+xE(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+w|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){P4(c6)}destroy(){this.set(0,0,0,0,0,0,0,0),P4(this.buffer)}}var fE=(()=>_E(["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((W)=>BigInt(W))))(),ql=(()=>fE[0])(),Al=(()=>fE[1])(),p6=new Uint32Array(80),l6=new Uint32Array(80);class gj extends wN{constructor(W=64){super(128,W,16,!1);this.Ah=X9[0]|0,this.Al=X9[1]|0,this.Bh=X9[2]|0,this.Bl=X9[3]|0,this.Ch=X9[4]|0,this.Cl=X9[5]|0,this.Dh=X9[6]|0,this.Dl=X9[7]|0,this.Eh=X9[8]|0,this.El=X9[9]|0,this.Fh=X9[10]|0,this.Fl=X9[11]|0,this.Gh=X9[12]|0,this.Gl=X9[13]|0,this.Hh=X9[14]|0,this.Hl=X9[15]|0}get(){let{Ah:W,Al:Y,Bh:G,Bl:X,Ch:J,Cl:Z,Dh:V,Dl:U,Eh:Q,El:H,Fh:N,Fl:A,Gh:q,Gl:z,Hh:w,Hl:D}=this;return[W,Y,G,X,J,Z,V,U,Q,H,N,A,q,z,w,D]}set(W,Y,G,X,J,Z,V,U,Q,H,N,A,q,z,w,D){this.Ah=W|0,this.Al=Y|0,this.Bh=G|0,this.Bl=X|0,this.Ch=J|0,this.Cl=Z|0,this.Dh=V|0,this.Dl=U|0,this.Eh=Q|0,this.El=H|0,this.Fh=N|0,this.Fl=A|0,this.Gh=q|0,this.Gl=z|0,this.Hh=w|0,this.Hl=D|0}process(W,Y){for(let g=0;g<16;g++,Y+=4)p6[g]=W.getUint32(Y),l6[g]=W.getUint32(Y+=4);for(let g=16;g<80;g++){let f=p6[g-15]|0,y=l6[g-15]|0,p=AY(f,y,1)^AY(f,y,8)^yj(f,y,7),b=IY(f,y,1)^IY(f,y,8)^vj(f,y,7),m=p6[g-2]|0,W0=l6[g-2]|0,u=AY(m,W0,19)^BV(m,W0,61)^yj(m,W0,6),J0=IY(m,W0,19)^EV(m,W0,61)^vj(m,W0,6),I0=gE(b,J0,l6[g-7],l6[g-16]),k=uE(I0,p,u,p6[g-7],p6[g-16]);p6[g]=k|0,l6[g]=I0|0}let{Ah:G,Al:X,Bh:J,Bl:Z,Ch:V,Cl:U,Dh:Q,Dl:H,Eh:N,El:A,Fh:q,Fl:z,Gh:w,Gl:D,Hh:T,Hl:x}=this;for(let g=0;g<80;g++){let f=AY(N,A,14)^AY(N,A,18)^BV(N,A,41),y=IY(N,A,14)^IY(N,A,18)^EV(N,A,41),p=N&q^~N&w,b=A&z^~A&D,m=hE(x,y,b,Al[g],l6[g]),W0=bE(m,T,f,p,ql[g],p6[g]),u=m|0,J0=AY(G,X,28)^BV(G,X,34)^BV(G,X,39),I0=IY(G,X,28)^EV(G,X,34)^EV(G,X,39),k=G&J^G&V^J&V,l=X&Z^X&U^Z&U;T=w|0,x=D|0,w=q|0,D=z|0,q=N|0,z=A|0,{h:N,l:A}=k7(Q|0,H|0,W0|0,u|0),Q=V|0,H=U|0,V=J|0,U=Z|0,J=G|0,Z=X|0;let B=yE(u,I0,l);G=vE(B,W0,J0,k),X=B|0}({h:G,l:X}=k7(this.Ah|0,this.Al|0,G|0,X|0)),{h:J,l:Z}=k7(this.Bh|0,this.Bl|0,J|0,Z|0),{h:V,l:U}=k7(this.Ch|0,this.Cl|0,V|0,U|0),{h:Q,l:H}=k7(this.Dh|0,this.Dl|0,Q|0,H|0),{h:N,l:A}=k7(this.Eh|0,this.El|0,N|0,A|0),{h:q,l:z}=k7(this.Fh|0,this.Fl|0,q|0,z|0),{h:w,l:D}=k7(this.Gh|0,this.Gl|0,w|0,D|0),{h:T,l:x}=k7(this.Hh|0,this.Hl|0,T|0,x|0),this.set(G,X,J,Z,V,U,Q,H,N,A,q,z,w,D,T,x)}roundClean(){P4(p6,l6)}destroy(){P4(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class cE extends gj{constructor(){super(48);this.Ah=G9[0]|0,this.Al=G9[1]|0,this.Bh=G9[2]|0,this.Bl=G9[3]|0,this.Ch=G9[4]|0,this.Cl=G9[5]|0,this.Dh=G9[6]|0,this.Dl=G9[7]|0,this.Eh=G9[8]|0,this.El=G9[9]|0,this.Fh=G9[10]|0,this.Fl=G9[11]|0,this.Gh=G9[12]|0,this.Gl=G9[13]|0,this.Hh=G9[14]|0,this.Hl=G9[15]|0}}var OX=NN(()=>new mE);var pE=NN(()=>new gj),lE=NN(()=>new cE);class uj extends TV{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,UN(W);let G=CV(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),P4(J)}update(W){return wX(this),this.iHash.update(W),this}digestInto(W){wX(this),n5(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var hj=(W,Y,G)=>new uj(W,Y).update(G).digest();hj.create=(W,Y)=>new uj(W,Y);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var KX=BigInt(0),zY=BigInt(1);function $V(W,Y){let G=Y.negate();return W?G:Y}function ON(W,Y){let G=AN(W.Fp,Y.map((X)=>X.Z));return Y.map((X,J)=>W.fromAffine(X.toAffine(G[J])))}function iE(W,Y){if(!Number.isSafeInteger(W)||W<=0||W>Y)throw Error("invalid window size, expected [1.."+Y+"], got W="+W)}function bj(W,Y){iE(W,Y);let G=Math.ceil(Y/W)+1,X=2**(W-1),J=2**W,Z=f6(W),V=BigInt(W);return{windows:G,windowSize:X,mask:Z,maxNumber:J,shiftBy:V}}function dE(W,Y,G){let{windowSize:X,mask:J,maxNumber:Z,shiftBy:V}=G,U=Number(W&J),Q=W>>V;if(U>X)U-=Z,Q+=zY;let H=Y*X,N=H+Math.abs(U)-1,A=U===0,q=U<0,z=Y%2!==0;return{nextN:Q,offset:N,isZero:A,isNeg:q,isNegF:z,offsetF:H}}function Il(W,Y){if(!Array.isArray(W))throw Error("array expected");W.forEach((G,X)=>{if(!(G instanceof Y))throw Error("invalid point at index "+X)})}function zl(W,Y){if(!Array.isArray(W))throw Error("array of scalars expected");W.forEach((G,X)=>{if(!Y.isValid(G))throw Error("invalid scalar at index "+X)})}var mj=new WeakMap,rE=new WeakMap;function fj(W){return rE.get(W)||1}function oE(W){if(W!==KX)throw Error("invalid wNAF")}class cj{constructor(W,Y){this.BASE=W.BASE,this.ZERO=W.ZERO,this.Fn=W.Fn,this.bits=Y}_unsafeLadder(W,Y,G=this.ZERO){let X=W;while(Y>KX){if(Y&zY)G=G.add(X);X=X.double(),Y>>=zY}return G}precomputeWindow(W,Y){let{windows:G,windowSize:X}=bj(Y,this.bits),J=[],Z=W,V=Z;for(let U=0;U<G;U++){V=Z,J.push(V);for(let Q=1;Q<X;Q++)V=V.add(Z),J.push(V);Z=V.double()}return J}wNAF(W,Y,G){if(!this.Fn.isValid(G))throw Error("invalid scalar");let X=this.ZERO,J=this.BASE,Z=bj(W,this.bits);for(let V=0;V<Z.windows;V++){let{nextN:U,offset:Q,isZero:H,isNeg:N,isNegF:A,offsetF:q}=dE(G,V,Z);if(G=U,H)J=J.add($V(A,Y[q]));else X=X.add($V(N,Y[Q]))}return oE(G),{p:X,f:J}}wNAFUnsafe(W,Y,G,X=this.ZERO){let J=bj(W,this.bits);for(let Z=0;Z<J.windows;Z++){if(G===KX)break;let{nextN:V,offset:U,isZero:Q,isNeg:H}=dE(G,Z,J);if(G=V,Q)continue;else{let N=Y[U];X=X.add(H?N.negate():N)}}return oE(G),X}getPrecomputes(W,Y,G){let X=mj.get(Y);if(!X){if(X=this.precomputeWindow(Y,W),W!==1){if(typeof G==="function")X=G(X);mj.set(Y,X)}}return X}cached(W,Y,G){let X=fj(W);return this.wNAF(X,this.getPrecomputes(X,W,G),Y)}unsafe(W,Y,G,X){let J=fj(W);if(J===1)return this._unsafeLadder(W,Y,X);return this.wNAFUnsafe(J,this.getPrecomputes(J,W,G),Y,X)}createCache(W,Y){iE(Y,this.bits),rE.set(W,Y),mj.delete(W)}hasCache(W){return fj(W)!==1}}function aE(W,Y,G,X){let J=Y,Z=W.ZERO,V=W.ZERO;while(G>KX||X>KX){if(G&zY)Z=Z.add(J);if(X&zY)V=V.add(J);J=J.double(),G>>=zY,X>>=zY}return{p1:Z,p2:V}}function sE(W,Y,G,X){Il(G,W),zl(X,Y);let J=G.length,Z=X.length;if(J!==Z)throw Error("arrays of points and scalars must have equal length");let V=W.ZERO,U=qN(BigInt(J)),Q=1;if(U>12)Q=U-3;else if(U>4)Q=U-2;else if(U>0)Q=2;let H=f6(Q),N=Array(Number(H)+1).fill(V),A=Math.floor((Y.BITS-1)/Q)*Q,q=V;for(let z=A;z>=0;z-=Q){N.fill(V);for(let D=0;D<Z;D++){let T=X[D],x=Number(T>>BigInt(z)&H);N[x]=N[x].add(G[D])}let w=V;for(let D=N.length-1,T=V;D>0;D--)T=T.add(N[D]),w=w.add(T);if(q=q.add(w),z!==0)for(let D=0;D<Q;D++)q=q.double()}return q}function nE(W,Y,G){if(Y){if(Y.ORDER!==W)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return kj(Y),Y}else return B5(W,{isLE:G})}function tE(W,Y,G={},X){if(X===void 0)X=W==="edwards";if(!Y||typeof Y!=="object")throw Error(`expected valid ${W} CURVE object`);for(let Q of["p","n","h"]){let H=Y[Q];if(!(typeof H==="bigint"&&H>KX))throw Error(`CURVE.${Q} must be positive bigint`)}let J=nE(Y.p,G.Fp,X),Z=nE(Y.n,G.Fn,X),U=["Gx","Gy","a",W==="weierstrass"?"b":"d"];for(let Q of U)if(!J.isValid(Y[Q]))throw Error(`CURVE.${Q} must be valid field element of CURVE.Fp`);return Y=Object.freeze(Object.assign({},Y)),{CURVE:Y,Fp:J,Fn:Z}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var eE=(W,Y)=>(W+(W>=0?Y:-Y)/Y$)/Y;function wl(W,Y,G){let[[X,J],[Z,V]]=Y,U=eE(V*W,G),Q=eE(-J*W,G),H=W-U*X-Q*Z,N=-U*J-Q*V,A=H<F4,q=N<F4;if(A)H=-H;if(q)N=-N;let z=f6(Math.ceil(qN(G)/2))+DX;if(H<F4||H>=z||N<F4||N>=z)throw Error("splitScalar (endomorphism): failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}function lj(W){if(!["compact","recovered","der"].includes(W))throw Error('Signature format must be "compact", "recovered", or "der"');return W}function pj(W,Y){let G={};for(let X of Object.keys(Y))G[X]=W[X]===void 0?Y[X]:W[X];if(RV(G.lowS,"lowS"),RV(G.prehash,"prehash"),G.format!==void 0)lj(G.format);return G}class W$ extends Error{constructor(W=""){super(W)}}var $4={Err:W$,_tlv:{encode:(W,Y)=>{let{Err:G}=$4;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length&1)throw new G("tlv.encode: unpadded data");let X=Y.length/2,J=MV(X);if(J.length/2&128)throw new G("tlv.encode: long form length too big");let Z=X>127?MV(J.length/2|128):"";return MV(W)+Z+J+Y},decode(W,Y){let{Err:G}=$4,X=0;if(W<0||W>256)throw new G("tlv.encode: wrong tag");if(Y.length<2||Y[X++]!==W)throw new G("tlv.decode: wrong tlv");let J=Y[X++],Z=!!(J&128),V=0;if(!Z)V=J;else{let Q=J&127;if(!Q)throw new G("tlv.decode(long): indefinite length not supported");if(Q>4)throw new G("tlv.decode(long): byte length is too big");let H=Y.subarray(X,X+Q);if(H.length!==Q)throw new G("tlv.decode: length bytes not complete");if(H[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let N of H)V=V<<8|N;if(X+=Q,V<128)throw new G("tlv.decode(long): not minimal encoding")}let U=Y.subarray(X,X+V);if(U.length!==V)throw new G("tlv.decode: wrong value length");return{v:U,l:Y.subarray(X+V)}}},_int:{encode(W){let{Err:Y}=$4;if(W<F4)throw new Y("integer: negative integers are not allowed");let G=MV(W);if(Number.parseInt(G[0],16)&8)G="00"+G;if(G.length&1)throw new Y("unexpected DER parsing assertion: unpadded hex");return G},decode(W){let{Err:Y}=$4;if(W[0]&128)throw new Y("invalid signature integer: negative");if(W[0]===0&&!(W[1]&128))throw new Y("invalid signature integer: unnecessary leading zero");return B4(W)}},toSig(W){let{Err:Y,_int:G,_tlv:X}=$4,J=B8("signature",W),{v:Z,l:V}=X.decode(48,J);if(V.length)throw new Y("invalid signature: left bytes after parsing");let{v:U,l:Q}=X.decode(2,Z),{v:H,l:N}=X.decode(2,Q);if(N.length)throw new Y("invalid signature: left bytes after parsing");return{r:G.decode(U),s:G.decode(H)}},hexFromSig(W){let{_tlv:Y,_int:G}=$4,X=Y.encode(2,G.encode(W.r)),J=Y.encode(2,G.encode(W.s)),Z=X+J;return Y.encode(48,Z)}},F4=BigInt(0),DX=BigInt(1),Y$=BigInt(2),KN=BigInt(3),jl=BigInt(4);function d6(W,Y){let{BYTES:G}=W,X;if(typeof Y==="bigint")X=Y;else{let J=B8("private key",Y);try{X=W.fromBytes(J)}catch(Z){throw Error(`invalid private key: expected ui8a of size ${G}, got ${typeof Y}`)}}if(!W.isValidNot0(X))throw Error("invalid private key: out of range [1..N-1]");return X}function Ol(W,Y={}){let G=tE("weierstrass",W,Y),{Fp:X,Fn:J}=G,Z=G.CURVE,{h:V,n:U}=Z;LV(Y,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:Q}=Y;if(Q){if(!X.is0(Z.a)||typeof Q.beta!=="bigint"||!Array.isArray(Q.basises))throw Error('invalid endo: expected "beta": bigint and "basises": array')}let H=X$(X,J);function N(){if(!X.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")}function A(k,l,B){let{x:$,y:h}=l.toAffine(),a=X.toBytes($);if(RV(B,"isCompressed"),B){N();let n=!X.isOdd(h);return i9(G$(n),a)}else return i9(Uint8Array.of(4),a,X.toBytes(h))}function q(k){m6(k,void 0,"Point");let{publicKey:l,publicKeyUncompressed:B}=H,$=k.length,h=k[0],a=k.subarray(1);if($===l&&(h===2||h===3)){let n=X.fromBytes(a);if(!X.isValid(n))throw Error("bad point: is not on curve, wrong x");let E=D(n),P;try{P=X.sqrt(E)}catch(F){let c=F instanceof Error?": "+F.message:"";throw Error("bad point: is not on curve, sqrt error"+c)}N();let v=X.isOdd(P);if((h&1)===1!==v)P=X.neg(P);return{x:n,y:P}}else if($===B&&h===4){let n=X.BYTES,E=X.fromBytes(a.subarray(0,n)),P=X.fromBytes(a.subarray(n,n*2));if(!T(E,P))throw Error("bad point: is not on curve");return{x:E,y:P}}else throw Error(`bad point: got length ${$}, expected compressed=${l} or uncompressed=${B}`)}let z=Y.toBytes||A,w=Y.fromBytes||q;function D(k){let l=X.sqr(k),B=X.mul(l,k);return X.add(X.add(B,X.mul(k,Z.a)),Z.b)}function T(k,l){let B=X.sqr(l),$=D(k);return X.eql(B,$)}if(!T(Z.Gx,Z.Gy))throw Error("bad curve params: generator point");let x=X.mul(X.pow(Z.a,KN),jl),g=X.mul(X.sqr(Z.b),BigInt(27));if(X.is0(X.add(x,g)))throw Error("bad curve params: a or b");function f(k,l,B=!1){if(!X.isValid(l)||B&&X.is0(l))throw Error(`bad point coordinate ${k}`);return l}function y(k){if(!(k instanceof u))throw Error("ProjectivePoint expected")}function p(k){if(!Q||!Q.basises)throw Error("no endo");return wl(k,Q.basises,J.ORDER)}let b=Sj((k,l)=>{let{X:B,Y:$,Z:h}=k;if(X.eql(h,X.ONE))return{x:B,y:$};let a=k.is0();if(l==null)l=a?X.ONE:X.inv(h);let n=X.mul(B,l),E=X.mul($,l),P=X.mul(h,l);if(a)return{x:X.ZERO,y:X.ZERO};if(!X.eql(P,X.ONE))throw Error("invZ was invalid");return{x:n,y:E}}),m=Sj((k)=>{if(k.is0()){if(Y.allowInfinityPoint&&!X.is0(k.Y))return;throw Error("bad point: ZERO")}let{x:l,y:B}=k.toAffine();if(!X.isValid(l)||!X.isValid(B))throw Error("bad point: x or y not field elements");if(!T(l,B))throw Error("bad point: equation left != right");if(!k.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});function W0(k,l,B,$,h){return B=new u(X.mul(B.X,k),B.Y,B.Z),l=$V($,l),B=$V(h,B),l.add(B)}class u{constructor(k,l,B){this.X=f("x",k),this.Y=f("y",l,!0),this.Z=f("z",B),Object.freeze(this)}static CURVE(){return Z}static fromAffine(k){let{x:l,y:B}=k||{};if(!k||!X.isValid(l)||!X.isValid(B))throw Error("invalid affine point");if(k instanceof u)throw Error("projective point not allowed");if(X.is0(l)&&X.is0(B))return u.ZERO;return new u(l,B,X.ONE)}static fromBytes(k){let l=u.fromAffine(w(m6(k,void 0,"point")));return l.assertValidity(),l}static fromHex(k){return u.fromBytes(B8("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,l=!0){if(I0.createCache(this,k),!l)this.multiply(KN);return this}assertValidity(){m(this)}hasEvenY(){let{y:k}=this.toAffine();if(!X.isOdd)throw Error("Field doesn't support isOdd");return!X.isOdd(k)}equals(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.eql(X.mul(l,n),X.mul(h,$)),P=X.eql(X.mul(B,n),X.mul(a,$));return E&&P}negate(){return new u(this.X,X.neg(this.Y),this.Z)}double(){let{a:k,b:l}=Z,B=X.mul(l,KN),{X:$,Y:h,Z:a}=this,n=X.ZERO,E=X.ZERO,P=X.ZERO,v=X.mul($,$),M=X.mul(h,h),F=X.mul(a,a),c=X.mul($,h);return c=X.add(c,c),P=X.mul($,a),P=X.add(P,P),n=X.mul(k,P),E=X.mul(B,F),E=X.add(n,E),n=X.sub(M,E),E=X.add(M,E),E=X.mul(n,E),n=X.mul(c,n),P=X.mul(B,P),F=X.mul(k,F),c=X.sub(v,F),c=X.mul(k,c),c=X.add(c,P),P=X.add(v,v),v=X.add(P,v),v=X.add(v,F),v=X.mul(v,c),E=X.add(E,v),F=X.mul(h,a),F=X.add(F,F),v=X.mul(F,c),n=X.sub(n,v),P=X.mul(F,M),P=X.add(P,P),P=X.add(P,P),new u(n,E,P)}add(k){y(k);let{X:l,Y:B,Z:$}=this,{X:h,Y:a,Z:n}=k,E=X.ZERO,P=X.ZERO,v=X.ZERO,M=Z.a,F=X.mul(Z.b,KN),c=X.mul(l,h),t=X.mul(B,a),Y0=X.mul($,n),$0=X.add(l,B),S0=X.add(h,a);$0=X.mul($0,S0),S0=X.add(c,t),$0=X.sub($0,S0),S0=X.add(l,$);let x0=X.add(h,n);return S0=X.mul(S0,x0),x0=X.add(c,Y0),S0=X.sub(S0,x0),x0=X.add(B,$),E=X.add(a,n),x0=X.mul(x0,E),E=X.add(t,Y0),x0=X.sub(x0,E),v=X.mul(M,S0),E=X.mul(F,Y0),v=X.add(E,v),E=X.sub(t,v),v=X.add(t,v),P=X.mul(E,v),t=X.add(c,c),t=X.add(t,c),Y0=X.mul(M,Y0),S0=X.mul(F,S0),t=X.add(t,Y0),Y0=X.sub(c,Y0),Y0=X.mul(M,Y0),S0=X.add(S0,Y0),c=X.mul(t,S0),P=X.add(P,c),c=X.mul(x0,S0),E=X.mul($0,E),E=X.sub(E,c),c=X.mul($0,t),v=X.mul(x0,v),v=X.add(v,c),new u(E,P,v)}subtract(k){return this.add(k.negate())}is0(){return this.equals(u.ZERO)}multiply(k){let{endo:l}=Y;if(!J.isValidNot0(k))throw Error("invalid scalar: out of range");let B,$,h=(a)=>I0.cached(this,a,(n)=>ON(u,n));if(l){let{k1neg:a,k1:n,k2neg:E,k2:P}=p(k),{p:v,f:M}=h(n),{p:F,f:c}=h(P);$=M.add(c),B=W0(l.beta,v,F,a,E)}else{let{p:a,f:n}=h(k);B=a,$=n}return ON(u,[B,$])[0]}multiplyUnsafe(k){let{endo:l}=Y,B=this;if(!J.isValid(k))throw Error("invalid scalar: out of range");if(k===F4||B.is0())return u.ZERO;if(k===DX)return B;if(I0.hasCache(this))return this.multiply(k);if(l){let{k1neg:$,k1:h,k2neg:a,k2:n}=p(k),{p1:E,p2:P}=aE(u,B,h,n);return W0(l.beta,E,P,$,a)}else return I0.unsafe(B,k)}multiplyAndAddUnsafe(k,l,B){let $=this.multiplyUnsafe(l).add(k.multiplyUnsafe(B));return $.is0()?void 0:$}toAffine(k){return b(this,k)}isTorsionFree(){let{isTorsionFree:k}=Y;if(V===DX)return!0;if(k)return k(u,this);return I0.unsafe(this,U).is0()}clearCofactor(){let{clearCofactor:k}=Y;if(V===DX)return this;if(k)return k(u,this);return this.multiplyUnsafe(V)}isSmallOrder(){return this.multiplyUnsafe(V).is0()}toBytes(k=!0){return RV(k,"isCompressed"),this.assertValidity(),z(u,this,k)}toHex(k=!0){return L4(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return ON(u,k)}static msm(k,l){return sE(u,J,k,l)}static fromPrivateKey(k){return u.BASE.multiply(d6(J,k))}}u.BASE=new u(Z.Gx,Z.Gy,X.ONE),u.ZERO=new u(X.ZERO,X.ONE,X.ZERO),u.Fp=X,u.Fn=J;let J0=J.BITS,I0=new cj(u,Y.endo?Math.ceil(J0/2):J0);return u.BASE.precompute(8),u}function G$(W){return Uint8Array.of(W?2:3)}function X$(W,Y){return{secretKey:Y.BYTES,publicKey:1+W.BYTES,publicKeyUncompressed:1+2*W.BYTES,publicKeyHasPrefix:!0,signature:2*Y.BYTES}}function Kl(W,Y={}){let{Fn:G}=W,X=Y.randomBytes||NY,J=Object.assign(X$(W.Fp,G),{seed:_j(G.ORDER)});function Z(z){try{return!!d6(G,z)}catch(w){return!1}}function V(z,w){let{publicKey:D,publicKeyUncompressed:T}=J;try{let x=z.length;if(w===!0&&x!==D)return!1;if(w===!1&&x!==T)return!1;return!!W.fromBytes(z)}catch(x){return!1}}function U(z=X(J.seed)){return zN(m6(z,J.seed,"seed"),G.ORDER)}function Q(z,w=!0){return W.BASE.multiply(d6(G,z)).toBytes(w)}function H(z){let w=U(z);return{secretKey:w,publicKey:Q(w)}}function N(z){if(typeof z==="bigint")return!1;if(z instanceof W)return!0;let{secretKey:w,publicKey:D,publicKeyUncompressed:T}=J;if(G.allowedLengths||w===D)return;let x=B8("key",z).length;return x===D||x===T}function A(z,w,D=!0){if(N(z)===!0)throw Error("first arg must be private key");if(N(w)===!1)throw Error("second arg must be public key");let T=d6(G,z);return W.fromHex(w).multiply(T).toBytes(D)}return Object.freeze({getPublicKey:Q,getSharedSecret:A,keygen:H,Point:W,utils:{isValidSecretKey:Z,isValidPublicKey:V,randomSecretKey:U,isValidPrivateKey:Z,randomPrivateKey:U,normPrivateKeyToScalar:(z)=>d6(G,z),precompute(z=8,w=W.BASE){return w.precompute(z,!1)}},lengths:J})}function Dl(W,Y,G={}){UN(Y),LV(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let X=G.randomBytes||NY,J=G.hmac||((B,...$)=>hj(Y,B,i9(...$))),{Fp:Z,Fn:V}=W,{ORDER:U,BITS:Q}=V,{keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z}=Kl(W,G),w={prehash:!1,lowS:typeof G.lowS==="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},D="compact";function T(B){let $=U>>DX;return B>$}function x(B,$){if(!V.isValidNot0($))throw Error(`invalid signature ${B}: out of range 1..Point.Fn.ORDER`);return $}function g(B,$){lj($);let h=z.signature,a=$==="compact"?h:$==="recovered"?h+1:void 0;return m6(B,a,`${$} signature`)}class f{constructor(B,$,h){if(this.r=x("r",B),this.s=x("s",$),h!=null)this.recovery=h;Object.freeze(this)}static fromBytes(B,$=D){g(B,$);let h;if($==="der"){let{r:P,s:v}=$4.toSig(m6(B));return new f(P,v)}if($==="recovered")h=B[0],$="compact",B=B.subarray(1);let a=V.BYTES,n=B.subarray(0,a),E=B.subarray(a,a*2);return new f(V.fromBytes(n),V.fromBytes(E),h)}static fromHex(B,$){return this.fromBytes(HY(B),$)}addRecoveryBit(B){return new f(this.r,this.s,B)}recoverPublicKey(B){let $=Z.ORDER,{r:h,s:a,recovery:n}=this;if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");if(U*Y$<$&&n>1)throw Error("recovery id is ambiguous for h>1 curve");let P=n===2||n===3?h+U:h;if(!Z.isValid(P))throw Error("recovery id 2 or 3 invalid");let v=Z.toBytes(P),M=W.fromBytes(i9(G$((n&1)===0),v)),F=V.inv(P),c=p(B8("msgHash",B)),t=V.create(-c*F),Y0=V.create(a*F),$0=W.BASE.multiplyUnsafe(t).add(M.multiplyUnsafe(Y0));if($0.is0())throw Error("point at infinify");return $0.assertValidity(),$0}hasHighS(){return T(this.s)}toBytes(B=D){if(lj(B),B==="der")return HY($4.hexFromSig(this));let $=V.toBytes(this.r),h=V.toBytes(this.s);if(B==="recovered"){if(this.recovery==null)throw Error("recovery bit must be present");return i9(Uint8Array.of(this.recovery),$,h)}return i9($,h)}toHex(B){return L4(this.toBytes(B))}assertValidity(){}static fromCompact(B){return f.fromBytes(B8("sig",B),"compact")}static fromDER(B){return f.fromBytes(B8("sig",B),"der")}normalizeS(){return this.hasHighS()?new f(this.r,V.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return L4(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return L4(this.toBytes("compact"))}}let y=G.bits2int||function($){if($.length>8192)throw Error("input is too large");let h=B4($),a=$.length*8-Q;return a>0?h>>BigInt(a):h},p=G.bits2int_modN||function($){return V.create(y($))},b=f6(Q);function m(B){return KE("num < 2^"+Q,B,F4,b),V.toBytes(B)}function W0(B,$){return m6(B,void 0,"message"),$?m6(Y(B),void 0,"prehashed message"):B}function u(B,$,h){if(["recovered","canonical"].some((Y0)=>(Y0 in h)))throw Error("sign() legacy options not supported");let{lowS:a,prehash:n,extraEntropy:E}=pj(h,w);B=W0(B,n);let P=p(B),v=d6(V,$),M=[m(v),m(P)];if(E!=null&&E!==!1){let Y0=E===!0?X(z.secretKey):E;M.push(B8("extraEntropy",Y0))}let F=i9(...M),c=P;function t(Y0){let $0=y(Y0);if(!V.isValidNot0($0))return;let S0=V.inv($0),x0=W.BASE.multiply($0).toAffine(),D1=V.create(x0.x);if(D1===F4)return;let b0=V.create(S0*V.create(c+D1*v));if(b0===F4)return;let Q0=(x0.x===D1?0:2)|Number(x0.y&DX),O0=b0;if(a&&T(b0))O0=V.neg(b0),Q0^=1;return new f(D1,O0,Q0)}return{seed:F,k2sig:t}}function J0(B,$,h={}){B=B8("message",B);let{seed:a,k2sig:n}=u(B,$,h);return DE(Y.outputLen,V.BYTES,J)(a,n)}function I0(B){let $=void 0,h=typeof B==="string"||QY(B),a=!h&&B!==null&&typeof B==="object"&&typeof B.r==="bigint"&&typeof B.s==="bigint";if(!h&&!a)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(a)$=new f(B.r,B.s);else if(h){try{$=f.fromBytes(B8("sig",B),"der")}catch(n){if(!(n instanceof $4.Err))throw n}if(!$)try{$=f.fromBytes(B8("sig",B),"compact")}catch(n){return!1}}if(!$)return!1;return $}function k(B,$,h,a={}){let{lowS:n,prehash:E,format:P}=pj(a,w);if(h=B8("publicKey",h),$=W0(B8("message",$),E),"strict"in a)throw Error("options.strict was renamed to lowS");let v=P===void 0?I0(B):f.fromBytes(B8("sig",B),P);if(v===!1)return!1;try{let M=W.fromBytes(h);if(n&&v.hasHighS())return!1;let{r:F,s:c}=v,t=p($),Y0=V.inv(c),$0=V.create(t*Y0),S0=V.create(F*Y0),x0=W.BASE.multiplyUnsafe($0).add(M.multiplyUnsafe(S0));if(x0.is0())return!1;return V.create(x0.x)===F}catch(M){return!1}}function l(B,$,h={}){let{prehash:a}=pj(h,w);return $=W0($,a),f.fromBytes(B,"recovered").recoverPublicKey($).toBytes()}return Object.freeze({keygen:H,getPublicKey:N,getSharedSecret:A,utils:q,lengths:z,Point:W,sign:J0,verify:k,recoverPublicKey:l,Signature:f,hash:Y})}function Cl(W){let Y={a:W.a,b:W.b,p:W.Fp.ORDER,n:W.n,h:W.h,Gx:W.Gx,Gy:W.Gy},G=W.Fp,X=W.allowedPrivateKeyLengths?Array.from(new Set(W.allowedPrivateKeyLengths.map((V)=>Math.ceil(V/2)))):void 0,J=B5(Y.n,{BITS:W.nBitLength,allowedLengths:X,modFromBytes:W.wrapPrivateKey}),Z={Fp:G,Fn:J,allowInfinityPoint:W.allowInfinityPoint,endo:W.endo,isTorsionFree:W.isTorsionFree,clearCofactor:W.clearCofactor,fromBytes:W.fromBytes,toBytes:W.toBytes};return{CURVE:Y,curveOpts:Z}}function Tl(W){let{CURVE:Y,curveOpts:G}=Cl(W),X={hmac:W.hmac,randomBytes:W.randomBytes,lowS:W.lowS,bits2int:W.bits2int,bits2int_modN:W.bits2int_modN};return{CURVE:Y,curveOpts:G,hash:W.hash,ecdsaOpts:X}}function Rl(W,Y){let G=Y.Point;return Object.assign({},Y,{ProjectivePoint:G,CURVE:Object.assign({},W,IN(G.Fn.ORDER,G.Fn.BITS))})}function J$(W){let{CURVE:Y,curveOpts:G,hash:X,ecdsaOpts:J}=Tl(W),Z=Ol(Y,G),V=Dl(Z,X,J);return Rl(W,V)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function CX(W,Y){let G=(X)=>J$({...W,hash:X});return{...G(Y),create:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var Z$={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},V$={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},U$={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},Ml=B5(Z$.p),Pl=B5(V$.p),Ll=B5(U$.p);var Q$=CX({...Z$,Fp:Ml,lowS:!1},OX);var FN0=CX({...V$,Fp:Pl,lowS:!1},lE);var SN0=CX({...U$,Fp:Ll,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},pE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var DN=Q$;var Z9=v1(j8(),1),G7=v1(j8(),1),uS=v1(j8(),1),CY=v1(j8(),1),c4=v1(j8(),1),pS=v1(xQ(),1),RY=v1(j8(),1),i6=v1(j8(),1),MY=v1(j8(),1),cX=v1(j8(),1),r6=v1(j8(),1),PY=v1(j8(),1),X7=v1(j8(),1),J7=v1(j8(),1),Iq=v1(j8(),1),Y7=v1(j8(),1),sS=v1(j8(),1),Lo=v1(A$(),1);import{randomBytes as Vo}from"crypto";import{setTimeout as Uo}from"timers/promises";import{createCipheriv as Ko,createDecipheriv as Do}from"crypto";var vN=v1(z$(),1),LY=v1(j8(),1),KY=v1(j8(),1),l7=v1(j8(),1),c7=v1(j8(),1),BY=v1(j8(),1);import{createHmac as ZO}from"crypto";import{createCipheriv as YF,createDecipheriv as GF,createHmac as XF,timingSafeEqual as Yn}from"crypto";import{createCipheriv as UF,createDecipheriv as QF}from"crypto";import{setTimeout as qn}from"timers/promises";import{randomBytes as jn}from"crypto";import{createHmac as O2}from"crypto";import{randomBytes as K2}from"crypto";var MN="undefined",LX=MN!==typeof Buffer&&Buffer,PX=MN!==typeof Uint8Array&&Uint8Array,RN=MN!==typeof ArrayBuffer&&ArrayBuffer,w$=[0,0,0,0,0,0,0,0],$l=Array.isArray||gl,MX=4294967296,Fl=16777216,BX,PN=O$("Uint64BE",!0,!0),nj=O$("Int64BE",!0,!1);function O$(W,Y,G){var X=Y?0:4,J=Y?4:0,Z=Y?0:3,V=Y?1:2,U=Y?2:1,Q=Y?3:0,H=Y?kl:yl,N=Y?_l:vl,A=w.prototype,q="is"+W,z="_"+q;if(A.buffer=void 0,A.offset=0,A[z]=!0,A.toNumber=g,A.toString=f,A.toJSON=g,A.toArray=Sl,LX)A.toBuffer=xl;if(PX)A.toArrayBuffer=K$;return w[q]=D,w;function w(b,m,W0,u){if(!(this instanceof w))return new w(b,m,W0,u);return T(this,b,m,W0,u)}function D(b){return!!(b&&b[z])}function T(b,m,W0,u,J0){if(PX&&RN){if(m instanceof RN)m=new PX(m);if(u instanceof RN)u=new PX(u)}if(!m&&!W0&&!u&&!BX){b.buffer=D$(w$,0);return}if(!j$(m,W0)){var I0=BX||Array;J0=W0,u=m,W0=0,m=BX===LX?LX.alloc(8):new I0(8)}if(b.buffer=m,b.offset=W0|=0,MN===typeof u)return;if(typeof u==="string")x(m,W0,u,J0||10);else if(j$(u,J0))oj(m,W0,u,J0);else if(typeof J0==="number")y(m,W0+X,u),y(m,W0+J,J0);else if(u>0)H(m,W0,u);else if(u<0)N(m,W0,u);else oj(m,W0,w$,0)}function x(b,m,W0,u){var J0=0,I0=W0.length,k=0,l=0;if(W0[0]==="-")J0++;var B=J0;while(J0<I0){var $=parseInt(W0[J0++],u);if(!($>=0))break;l=l*u+$,k=k*u+Math.floor(l/MX),l%=MX}if(B)if(k=~k,l)l=MX-l;else k++;y(b,m+X,k),y(b,m+J,l)}function g(){var b=this.buffer,m=this.offset,W0=p(b,m+X),u=p(b,m+J);if(!G)W0|=0;return W0?W0*MX+u:u}function f(b){var m=this.buffer,W0=this.offset,u=p(m,W0+X),J0=p(m,W0+J),I0="",k=!G&&u&2147483648;if(k)u=~u,J0=MX-J0;b=b||10;while(!0){var l=u%b*MX+J0;if(u=Math.floor(u/b),J0=Math.floor(l/b),I0=(l%b).toString(b)+I0,!u&&!J0)break}if(k)I0="-"+I0;return I0}function y(b,m,W0){b[m+Q]=W0&255,W0=W0>>8,b[m+U]=W0&255,W0=W0>>8,b[m+V]=W0&255,W0=W0>>8,b[m+Z]=W0&255}function p(b,m){return b[m+Z]*Fl+(b[m+V]<<16)+(b[m+U]<<8)+b[m+Q]}}function Sl(W){var Y=this.buffer,G=this.offset;if(BX=null,W!==!1&&$l(Y))return Y.length===8?Y:Y.slice(G,G+8);return D$(Y,G)}function xl(W){var Y=this.buffer,G=this.offset;if(BX=LX,W!==!1&&LX.isBuffer(Y))return Y.length===8?Y:Y.slice(G,G+8);return LX.from(K$.call(this,W))}function K$(W){var Y=this.buffer,G=this.offset,X=Y.buffer;if(BX=PX,W!==!1&&!Y.offset&&X instanceof RN)return X.byteLength===8?X:X.slice(G,G+8);var J=new PX(8);return oj(J,0,Y,G),J.buffer}function j$(W,Y){var G=W&&W.length;return Y|=0,G&&Y+8<=G&&typeof W[Y]!=="string"}function oj(W,Y,G,X){Y|=0,X|=0;for(var J=0;J<8;J++)W[Y++]=G[X++]&255}function D$(W,Y){return Array.prototype.slice.call(W,Y,Y+8)}function kl(W,Y,G){var X=Y+8;while(X>Y)W[--X]=G&255,G/=256}function _l(W,Y,G){var X=Y+8;G++;while(X>Y)W[--X]=-G&255^255,G/=256}function yl(W,Y,G){var X=Y+8;while(Y<X)W[Y++]=G&255,G/=256}function vl(W,Y,G){var X=Y+8;G++;while(Y<X)W[Y++]=-G&255^255,G/=256}function gl(W){return!!W&&Object.prototype.toString.call(W)=="[object Array]"}var sV=v1(rj(),1);import{createHash as yn}from"crypto";import{setTimeout as vn}from"timers/promises";import{createHash as pn}from"crypto";import{isIPv4 as $F}from"net";import{randomBytes as ln}from"crypto";import{isIPv4 as FF}from"net";var bN=v1(R$(),1),B2=v1(u$(),1),$2=v1(rj(),1);import*as yO from"timers/promises";import{randomUUID as on}from"crypto";import*as E2 from"os";import{EventEmitter as Ji}from"events";import{randomUUID as wi}from"crypto";import{setTimeout as zO}from"timers/promises";import{createHash as ji}from"crypto";import{performance as FN}from"perf_hooks";import{randomUUID as Oi}from"crypto";import{randomUUID as m2}from"crypto";import{setTimeout as bi}from"timers/promises";import{randomBytes as pi}from"crypto";import{isIPv4 as li}from"net";var tV=v1(gI(),1);import{randomUUID as di}from"crypto";import{setTimeout as oi}from"timers/promises";import{randomUUID as si}from"crypto";import{randomUUID as Gr}from"crypto";import{createHmac as rF,randomBytes as Xr}from"crypto";import{randomBytes as US}from"crypto";import{randomUUID as QS}from"crypto";import{setTimeout as HS}from"timers/promises";import{randomUUID as xr}from"crypto";function zS(){return s1.Unpack("!H",IS(2))[0]}function CO(){return s1.Unpack("!L",IS(4))[0]}var nN=class{constructor(W){this.bitLength=W}value=0;set(W,Y,G){return G&=(1<<W)-1,this.value|=G<<this.bitLength-W-Y,this}get buffer(){let W=Math.ceil(this.bitLength/8),Y=Buffer.alloc(W);return Y.writeUIntBE(this.value,0,W),Y}},wS=class{constructor(W){if(this.bitLength=W,W>32)throw Error()}_value=0n;offset=0n;set(W,Y=1){let G=BigInt(W),X=BigInt(Y);return G&=(1n<<X)-1n,this._value|=G<<BigInt(this.bitLength)-X-this.offset,this.offset+=X,this}get value(){return Number(this._value)}get buffer(){let W=Math.ceil(this.bitLength/8),Y=Buffer.alloc(W);return Y.writeUIntBE(this.value,0,W),Y}};function u8(W,Y,G=1){let X=W.toString(2).split("");X=[...Array(8-X.length).fill("0"),...X];let J=X.slice(Y,Y+G).join("");return Number.parseInt(J,2)}function E8(W,Y){return _N(W)(Y)}function _N(W,Y){let G=W.reduce((J,Z)=>J+Z,0),X=Y?Buffer.alloc(G):void 0;return(J)=>{let Z=X||Buffer.alloc(G),V=0;return J.forEach((U,Q)=>{let H=W[Q];if(H===8)Z.writeBigUInt64BE(U,V);else Z.writeUIntBE(U,V,H);V+=H}),Z}}function s9(W,Y){let G=0;return Y.map((X)=>{let J;if(X===8)J=W.readBigUInt64BE(G);else J=W.readUIntBE(G,X);return G+=X,J})}var pV=class{constructor(W){this.uint8Array=W}position=0;bitsPending=0;writeBits(W,Y){if(W==0)return this;Y&=4294967295>>>32-W;let G;if(this.bitsPending>0)if(this.bitsPending>W)this.uint8Array[this.position-1]|=Y<<this.bitsPending-W,G=W,this.bitsPending-=W;else if(this.bitsPending==W)this.uint8Array[this.position-1]|=Y,G=W,this.bitsPending=0;else this.uint8Array[this.position-1]|=Y>>W-this.bitsPending,G=this.bitsPending,this.bitsPending=0;else G=Math.min(8,W),this.bitsPending=8-G,this.uint8Array[this.position++]=Y>>W-G<<this.bitsPending;if(W-=G,W>0)this.writeBits(W,Y);return this}readBits(W){return this._readBits(W)}_readBits(W,Y){if(typeof Y>"u")Y=0;if(W==0)return Y;let G,X;if(this.bitsPending>0){let J=this.uint8Array[this.position-1]&255>>8-this.bitsPending;X=Math.min(this.bitsPending,W),this.bitsPending-=X,G=J>>this.bitsPending}else X=Math.min(8,W),this.bitsPending=8-X,G=this.uint8Array[this.position++]>>this.bitsPending;return W-=X,Y=Y<<X|G,W>0?this._readBits(W,Y):Y}seekTo(W){if(this.position=W/8|0,this.bitsPending=W%8,this.bitsPending>0)this.bitsPending=8-this.bitsPending,this.position++}},Ld=3988292384,Bd=2197175160;function jS(W){return typeof W!=="string"}function OS(W){let Y=Array(256),G=0;for(let X=0;X<256;++X)G=X,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,G=G&1?W^G>>>1:G>>>1,Y[X]=G;return new Int32Array(Y)}function KS(W){let Y=new Int32Array(4096),G=0,X=0,J=0;for(J=0;J<256;++J)Y[J]=W[J];for(J=0;J<256;++J){X=W[J];for(G=256+J;G<4096;G+=256)X=Y[G]=X>>>8^W[X&255]}let Z=[];for(J=1;J<16;++J)Z[J-1]=Y.subarray(J*256,J*256+256);return Z}function DS(W,Y,G){let X=Y^-1,J=0,Z=W.length,V=0,U=0;while(J<Z)if(V=W.charCodeAt(J++),V<128)X=X>>>8^G[(X^V)&255];else if(V<2048)X=X>>>8^G[(X^(192|V>>6&31))&255],X=X>>>8^G[(X^(128|V&63))&255];else if(V>=55296&&V<57344)V=(V&1023)+64,U=W.charCodeAt(J++)&1023,X=X>>>8^G[(X^(240|V>>8&7))&255],X=X>>>8^G[(X^(128|V>>2&63))&255],X=X>>>8^G[(X^(128|U>>6&15|(V&3)<<4))&255],X=X>>>8^G[(X^(128|U&63))&255];else X=X>>>8^G[(X^(224|V>>12&15))&255],X=X>>>8^G[(X^(128|V>>6&63))&255],X=X>>>8^G[(X^(128|V&63))&255];return~X>>>0}function CS(W,Y,G,X){let[J,Z,V,U,Q,H,N,A,q,z,w,D,T,x,g]=X,f=Y^-1,y=0,p=W.length-15;while(y<p)f=g[W[y++]^f&255]^x[W[y++]^f>>>8&255]^T[W[y++]^f>>>16&255]^D[W[y++]^f>>>24]^w[W[y++]]^z[W[y++]]^q[W[y++]]^A[W[y++]]^N[W[y++]]^H[W[y++]]^Q[W[y++]]^U[W[y++]]^V[W[y++]]^Z[W[y++]]^J[W[y++]]^G[W[y++]];for(p+=15;y<p;)f=f>>>8^G[(f^W[y++])&255];return~f>>>0}var TO=OS(Ld),Ed=KS(TO),RO=OS(Bd),$d=KS(RO);function Fd(W,Y=0){if(jS(W))return CS(W,Y,TO,Ed);return DS(W,Y,TO)}function TS(W,Y=0){if(jS(W))return CS(W,Y,RO,$d);return DS(W,Y,RO)}function Sd(W,Y){return W+Y&255}function T9(W,Y){return W+Y&65535}function vX(W,Y){return Number(BigInt(W)+BigInt(Y)&0xffffffffn)}function xd(W){return W&16777215}function RS(W,Y){return W<Y&&Y-W>32768||W>Y&&W-Y<32768}function f4(W,Y){return W<Y&&Y-W>2147483648||W>Y&&W-Y<2147483648}function mV(W,Y){return W===Y||f4(W,Y)}var lV=(W)=>Number.parseInt(W,10);var MS=(W,Y)=>Y?Y[W]:void 0;async function _d(W,Y,G="udp4",X){let J;for(let Z=W;Z<=Y;Z++){let V=kd(G);if(setImmediate(()=>V.bind({port:Z,address:MS(G,X)})),await new Promise((Q)=>{V.once("error",(H)=>Q(H)),V.once("listening",()=>Q())})){await new Promise((Q)=>V.close(()=>Q()));continue}if(J=V.address()?.port,await new Promise((Q)=>V.close(()=>Q())),W<=J&&J<=Y)break}if(!J)throw Error("port not found");return J}function iN(W){if(W==="IPv4")return 4;if(W==="IPv6")return 6;return W}var M1=PS.default.debug,p0=class{event={stack:[],promiseStack:[],eventId:0};ended=!1;onended;onerror=(W)=>{};execute=(...W)=>{if(this.ended)return;for(let Y of this.event.stack)Y.execute(...W);(async()=>{for(let Y of this.event.promiseStack)await Y.execute(...W)})().catch((Y)=>{this.onerror(Y)})};complete=()=>{if(this.ended)return;for(let W of this.event.stack)if(W.complete)W.complete();if(this.allUnsubscribe(),this.ended=!0,this.onended)this.onended(),this.onended=void 0};error=(W)=>{if(this.ended)return;for(let Y of this.event.stack)if(Y.error)Y.error(W);this.allUnsubscribe()};allUnsubscribe=()=>{if(this.ended)throw Error("event completed");this.event={stack:[],promiseStack:[],eventId:0}};subscribe=(W,Y,G)=>{let X=this.event.eventId;this.event.stack.push({execute:W,id:X,complete:Y,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==X&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};pipe(W){this.subscribe((...Y)=>{W.execute(...Y)})}queuingSubscribe=(W,Y,G)=>{if(this.ended)throw Error("event completed");let X=this.event.eventId;this.event.promiseStack.push({execute:W,id:X,complete:Y,error:G}),this.event.eventId++;let J=()=>{this.event.stack=this.event.stack.filter((V)=>V.id!==X&&V)};return{unSubscribe:J,disposer:(V)=>{V.push(J)}}};once=(W,Y,G)=>{let X=this.subscribe((...J)=>{X.unSubscribe(),W(...J)},Y,G)};watch=(W,Y)=>new Promise((G,X)=>{let J=Y&&setTimeout(()=>{X("Event watch timeout")},Y),{unSubscribe:Z}=this.subscribe((...V)=>{if(W(...V)){if(J)clearTimeout(J);Z(),G(V)}})});asPromise=(W)=>new Promise((Y,G)=>{let X=W&&setTimeout(()=>{G("Event asPromise timeout")},W);this.once((...J)=>{if(X)clearTimeout(X);Y(J)},()=>{if(X)clearTimeout(X);Y([])},(J)=>{if(X)clearTimeout(X);G(J)})});get returnTrigger(){let{execute:W,error:Y,complete:G}=this;return{execute:W,error:Y,complete:G}}get returnListener(){let{subscribe:W,once:Y,asPromise:G}=this;return{subscribe:W,once:Y,asPromise:G}}get length(){return this.event.stack.length}},yd=class{_disposer=[];push(W){this._disposer.push(W)}dispose(){this._disposer.forEach((W)=>W()),this._disposer=[]}},h$=M1("werift-ice:packages/ice/src/transport.ts"),MO=class W{constructor(Y,G={}){this.socketType=Y,this.options=G,this.socket=vd(Y),this.socket.on("message",(X,J)=>{if(iN(J.family)===6)[J.address]=J.address.split("%");this.rinfo=J;try{this.onData(X,[J.address,J.port])}catch(Z){h$("onData error",Z)}})}type="udp";socket;rinfo;onData=()=>{};closed=!1;static async init(Y,G={}){let X=new W(Y,G);return await X.init(),X}async init(){let Y=MS(this.socketType,this.options.interfaceAddresses);if(this.options.port)this.socket.bind({port:this.options.port,address:Y});else if(this.options.portRange){let G=await _d(this.options.portRange[0],this.options.portRange[1],this.socketType,this.options.interfaceAddresses);this.socket.bind({port:G,address:Y})}else this.socket.bind({address:Y});await new Promise((G)=>this.socket.once("listening",G))}send=async(Y,G)=>{if(G&&!LS.isIP(G[0]))return new Promise((X,J)=>{this.socket.send(Y,G[1],G[0],(Z)=>{if(Z)h$("send error",G,Y),J(Z);else X()})});else G=G??[this.rinfo?.address,this.rinfo?.port],this.socket.send(Y,G[1],G[0])};get address(){return this.socket.address()}get host(){return this.socket.address().address}get port(){return this.socket.address().port}close=()=>new Promise((Y)=>{this.closed=!0,this.socket.once("close",Y);try{this.socket.close()}catch(G){Y()}})},ud=class W{constructor(Y){this.addr=Y,this.connect()}type="tcp";connecting;client;onData=()=>{};closed=!1;connect(){if(this.closed)return;if(this.client)this.client.destroy();this.connecting=new Promise((Y,G)=>{try{this.client=gd({port:this.addr[1],host:this.addr[0]},Y)}catch(X){G(X)}}),this.client.on("data",(Y)=>{let G=[this.client.remoteAddress,this.client.remotePort];this.onData(Y,G)}),this.client.on("end",()=>{this.connect()}),this.client.on("error",(Y)=>{console.log("error",Y)})}async init(){await this.connecting}static async init(Y){let G=new W(Y);return await G.init(),G}get address(){return{}}send=async(Y,G)=>{await this.connecting,this.client.write(Y,(X)=>{if(X)console.log("err",X)})};close=async()=>{this.closed=!0,this.client.destroy()}},l4={rsa_1:1,ecdsa_3:3},rN={sha256_4:4},PO={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195:49195,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199:49199},fd=Object.values(PO),a6={x25519_29:29,secp256r1_23:23},BS=Object.values(a6),ES={named_curve_3:3},b$={rsa_pkcs1_sha256:1025,ecdsa_secp256r1_sha256:1027},cd=[1,64],$S=[{hash:rN.sha256_4,signature:l4.rsa_1},{hash:rN.sha256_4,signature:l4.ecdsa_3}],dd=()=>{let W=DN.utils.randomPrivateKey(),Y=DN.getPublicKey(W,!1),G=Buffer.from(W),X=Buffer.from(Y);return{privateKey:G,publicKey:X}},od=({publicKey:W,privateKey:Y})=>{let G=DN.getSharedSecret(Y,W);return Buffer.from(G).subarray(1)};function xS(W,Y,G){switch(G){case a6.secp256r1_23:return od({publicKey:W,privateKey:Y});case a6.x25519_29:return Buffer.from(SS.default.scalarMult(Y,W));default:throw Error()}}function m$(W,Y,G){let X=ld(W,Y);return X.update(G),X.digest()}function WU(W,Y,G,X="sha256"){let J=G,Z=[],V=Y;do{V=m$(X,W,V);let U=m$(X,W,Buffer.concat([V,Y]));Z.push(U),G-=U.length}while(G>0);return Buffer.concat(Z,J)}function kS(W,Y,G){let X=Buffer.concat([Buffer.from("master secret"),Y,G]);return WU(W,X,48)}function _S(W,Y){let G=yS("sha256",Y),X="extended master secret";return WU(W,Buffer.concat([Buffer.from("extended master secret"),G]),48)}function nd(W,Y,G,X,J,Z){let V=Z?X:J,U=Z?J:X,Q=Buffer.concat([Buffer.from(W),V,U]);return WU(G,Q,Y)}function yS(W,Y){return pd(W).update(Y).digest()}function vS(W,Y,G,X=12){let J=yS("sha256",Y);return WU(W,Buffer.concat([Buffer.from(G),J]),X)}function id(W,Y){return vS(W,Y,"client finished")}function rd(W,Y){return vS(W,Y,"server finished")}function ad(W,Y,G,X,J,Z,V="sha256"){let U=X*2+J*2,Q=W,H=Buffer.concat([G,Y]),N=WU(Q,Buffer.concat([Buffer.from("key expansion"),H]),U,V),A=FS.createDecode(N),q=A.readBuffer(X),z=A.readBuffer(X),w=A.readBuffer(J),D=A.readBuffer(J),T=Buffer.alloc(Z,0),x=Buffer.alloc(Z,0);return w.copy(T,0),D.copy(x,0),{clientWriteKey:q,serverWriteKey:z,clientNonce:T,serverNonce:x}}var p4={CLIENT:1,SERVER:2},sd=class{id=0;name;hashAlgorithm;verifyDataLength=12;blockAlgorithm;kx;init(...W){throw Error("not implemented")}encrypt(...W){throw Error("not implemented")}decrypt(...W){throw Error("not implemented")}toString(){return this.name}},LO=md;v8.set(LO);var aN=class{constructor(W,Y,G,X){if(this.sessionType=W,this.certPem=Y,this.keyPem=G,Y&&G&&X)this.parseX509(Y,G,X)}localRandom;remoteRandom;cipherSuite;remoteCertificate;remoteKeyPair;localKeyPair;masterSecret;cipher;namedCurve;signatureHashAlgorithm;localCert;localPrivateKey;static createSelfSignedCertificateWithKey=async(W,Y)=>{let G=(()=>{switch(W.signature){case l4.rsa_1:return"RSASSA-PKCS1-v1_5";case l4.ecdsa_3:return"ECDSA"}})(),X=(()=>{switch(W.hash){case rN.sha256_4:return"SHA-256"}})(),J=(()=>{switch(Y){case a6.secp256r1_23:return"P-256";case a6.x25519_29:if(G==="ECDSA")return"P-256";return"X25519";default:{if(G==="ECDSA")return"P-256";if(G==="RSASSA-PKCS1-v1_5")return"X25519"}}})(),Z=(()=>{switch(G){case"ECDSA":return{name:G,hash:X,namedCurve:J};case"RSASSA-PKCS1-v1_5":return{name:G,hash:X,publicExponent:new Uint8Array([1,0,1]),modulusLength:2048}}})(),V=await LO.subtle.generateKey(Z,!0,["sign","verify"]),Q=(await zj.createSelfSigned({serialNumber:bd(8).toString("hex"),name:"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",notBefore:new Date,notAfter:new Date(Date.now()+315360000000),signingAlgorithm:Z,keys:V})).toString("pem"),H=K9.encode(await LO.subtle.exportKey("pkcs8",V.privateKey),"private key");return{certPem:Q,keyPem:H,signatureHash:W}};encryptPacket(W){let Y=W.recordLayerHeader,G=Y.protocolVersion.major<<8|Y.protocolVersion.minor,X=this.cipher.encrypt(this.sessionType,W.fragment,{type:Y.contentType,version:G,epoch:Y.epoch,sequenceNumber:Y.sequenceNumber});return W.fragment=X,W.recordLayerHeader.contentLen=X.length,W}decryptPacket(W){let Y=W.recordLayerHeader,G=Y.protocolVersion.major<<8|Y.protocolVersion.minor;return this.cipher.decrypt(this.sessionType,W.fragment,{type:Y.contentType,version:G,epoch:Y.epoch,sequenceNumber:Y.sequenceNumber})}verifyData(W){if(this.sessionType===p4.CLIENT)return id(this.masterSecret,W);else return rd(this.masterSecret,W)}signatureData(W,Y){let G=hd(Y).update(W),X=this.localPrivateKey.toPEM().toString();return G.sign(X)}generateKeySignature(W){let Y=this.sessionType===p4.CLIENT?this.localRandom:this.remoteRandom,G=this.sessionType===p4.SERVER?this.localRandom:this.remoteRandom,X=this.valueKeySignature(Y.serialize(),G.serialize(),this.localKeyPair.publicKey,this.namedCurve);return this.localPrivateKey.sign(X,W)}parseX509(W,Y,G){let X=Hq.Certificate.fromPEM(Buffer.from(W)),J=Hq.PrivateKey.fromPEM(Buffer.from(Y));this.localCert=X.raw,this.localPrivateKey=J,this.signatureHashAlgorithm=G}valueKeySignature(W,Y,G,X){let J=Buffer.from(gX.encode({type:ES.named_curve_3,curve:X,len:G.length},{type:gX.types.uint8,curve:gX.types.uint16be,len:gX.types.uint8}).slice());return Buffer.concat([W,Y,J,G])}},sN=class{srtpProfile;static findMatchingSRTPProfile(W,Y){for(let G of Y)if(W.includes(G))return G}},eO=(W)=>"0x"+W.toString("hex").replace(/(.)(.)/g,"$1$2 ").split(" ").filter((Y)=>Y!=null&&Y.length>0).join(",0x"),gS=(W)=>Object.entries({...W}).reduce((Y,[G,X])=>{if(typeof X==="number"||typeof X==="string")Y[G]=X;if(Buffer.isBuffer(X))Y[G]=eO(X);return Y},{}),E5=class W{constructor(Y,G,X,J,Z,V){this.msg_type=Y,this.length=G,this.message_seq=X,this.fragment_offset=J,this.fragment_length=Z,this.fragment=V}static spec={msg_type:G7.types.uint8,length:G7.types.uint24be,message_seq:G7.types.uint16be,fragment_offset:G7.types.uint24be,fragment_length:G7.types.uint24be,fragment:G7.types.buffer((Y)=>Y.current.fragment_length)};get summary(){return gS(this)}static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(G7.decode(Y,W.spec)))}serialize(){let Y=G7.encode(this,W.spec).slice();return Buffer.from(Y)}chunk(Y){let G=0,X=this.fragment.length;if(X===0)return[new W(this.msg_type,X,this.message_seq,G,0,this.fragment)];let J=[];if(!Y)Y=1240;while(G<X){let Z=Math.min(Y,X-G),V=Buffer.from(this.fragment.slice(G,G+Z));if(V.length<=0)throw Error("Zero or less bytes processed while fragmenting handshake message.");J.push(new W(this.msg_type,X,this.message_seq,G,V.length,V)),G+=V.length}return J}static assemble(Y){if(!Y?.length)throw Error("cannot reassemble handshake from empty array");Y=Y.sort((X,J)=>X.fragment_offset-J.fragment_offset);let G=Buffer.alloc(Y[0].length);for(let X of Y)X.fragment.copy(G,X.fragment_offset);return new W(Y[0].msg_type,Y[0].length,Y[0].message_seq,0,G.length,G)}static findAllFragments(Y,G){let X=Y.find((J)=>J.msg_type===G);if(!X)return[];if(!Y?.length)return[];return Y.filter((J)=>{return J.msg_type===X.msg_type&&J.message_seq===X.message_seq&&J.length===X.length})}},{uint16be:tN,uint24be:td,buffer:hS,array:ed,uint8:nV,string:Wo}=uS.types,Yo={type:tN,data:hS(tN)},BO=ed(Yo,tN,"bytes"),Go=hS(td),Xo=nV,Jo=Wo(tN),Zo={hash:nV,signature:nV},WK={major:nV,minor:nV},TY=class W{constructor(Y=Math.floor(Date.now()/1000),G=Vo(28)){this.gmt_unix_time=Y,this.random_bytes=G}static spec={gmt_unix_time:CY.types.uint32be,random_bytes:CY.types.buffer(28)};static deSerialize(Y){return new W(...Object.values(CY.decode(Y,W.spec)))}static from(Y){return new W(...Object.values(Y))}serialize(){let Y=CY.encode(this,W.spec).slice();return Buffer.from(Y)}},bS=class W{constructor(Y,G,X,J,Z,V,U){this.clientVersion=Y,this.random=G,this.sessionId=X,this.cookie=J,this.cipherSuites=Z,this.compressionMethods=V,this.extensions=U}msgType=1;messageSeq=0;static spec={clientVersion:{major:Z9.types.uint8,minor:Z9.types.uint8},random:TY.spec,sessionId:Z9.types.buffer(Z9.types.uint8),cookie:Z9.types.buffer(Z9.types.uint8),cipherSuites:Z9.types.array(Z9.types.uint16be,Z9.types.uint16be,"bytes"),compressionMethods:Z9.types.array(Z9.types.uint8,Z9.types.uint8,"bytes"),extensions:BO};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(Z9.decode(Y,W.spec)))}serialize(){let Y=Z9.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},Qo=class W{constructor(Y,G,X,J,Z){this.epoch=Y,this.sequenceNumber=G,this.contentType=X,this.protocolVersion=J,this.contentLen=Z}static spec={epoch:c4.types.uint16be,sequenceNumber:c4.types.uint48be,contentType:c4.types.uint8,protocolVersion:WK,contentLen:c4.types.uint16be};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(c4.decode(Y,W.spec)))}serialize(){let Y=c4.encode(this,W.spec).slice();return Buffer.from(Y)}},mS=class W{constructor(Y,G){this.recordLayerHeader=Y,this.fragment=G}get summary(){return{header:this.recordLayerHeader,fragment:eO(this.fragment)}}static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){if(Y.length<13)throw Error("Invalid DTLS record: buffer is too short");let G=Y.readUInt8(0),X=Y.readUInt8(1),J=Y.readUInt8(2),Z=Y.readUInt16BE(3),V=Y.slice(5,11).readUIntBE(0,6),U=Y.readUInt16BE(11);if(Y.length<13+U)throw Error("Invalid DTLS record: fragment length exceeds buffer");let Q=Y.slice(13,13+U);return new W({contentType:G,protocolVersion:{major:X,minor:J},epoch:Z,sequenceNumber:V,contentLen:U},Q)}serialize(){let Y=this.fragment.length,G=13+Y,X=Buffer.alloc(G);return X.writeUInt8(this.recordLayerHeader.contentType,0),X.writeUInt8(this.recordLayerHeader.protocolVersion.major,1),X.writeUInt8(this.recordLayerHeader.protocolVersion.minor,2),X.writeUInt16BE(this.recordLayerHeader.epoch,3),X.writeUIntBE(this.recordLayerHeader.sequenceNumber,5,6),X.writeUInt16BE(Y,11),this.fragment.copy(X,13),X}computeMACHeader(){return new Qo(this.recordLayerHeader.epoch,this.recordLayerHeader.sequenceNumber,this.recordLayerHeader.contentType,this.recordLayerHeader.protocolVersion,this.recordLayerHeader.contentLen).serialize()}},fS=(W)=>(Y)=>{return W.lastFlight=Y,Y.flatMap((G)=>{return G.messageSeq=W.sequenceNumber++,G.toFragment().chunk()})},YU=(W)=>(Y,G)=>{return Y.map((X)=>{return new mS({contentType:X.type,protocolVersion:W.version,epoch:W.epoch,sequenceNumber:G,contentLen:X.fragment.length},X.fragment)})},EO=((W)=>{return W[W.CloseNotify=0]="CloseNotify",W[W.UnexpectedMessage=10]="UnexpectedMessage",W[W.BadRecordMac=20]="BadRecordMac",W[W.DecryptionFailed=21]="DecryptionFailed",W[W.RecordOverflow=22]="RecordOverflow",W[W.DecompressionFailure=30]="DecompressionFailure",W[W.HandshakeFailure=40]="HandshakeFailure",W[W.NoCertificate=41]="NoCertificate",W[W.BadCertificate=42]="BadCertificate",W[W.UnsupportedCertificate=43]="UnsupportedCertificate",W[W.CertificateRevoked=44]="CertificateRevoked",W[W.CertificateExpired=45]="CertificateExpired",W[W.CertificateUnknown=46]="CertificateUnknown",W[W.IllegalParameter=47]="IllegalParameter",W[W.UnknownCa=48]="UnknownCa",W[W.AccessDenied=49]="AccessDenied",W[W.DecodeError=50]="DecodeError",W[W.DecryptError=51]="DecryptError",W[W.ExportRestriction=60]="ExportRestriction",W[W.ProtocolVersion=70]="ProtocolVersion",W[W.InsufficientSecurity=71]="InsufficientSecurity",W[W.InternalError=80]="InternalError",W[W.UserCanceled=90]="UserCanceled",W[W.NoRenegotiation=100]="NoRenegotiation",W[W.UnsupportedExtension=110]="UnsupportedExtension",W})(EO||{}),Ho=M1("werift-dtls : packages/dtls/src/flight/flight.ts : warn"),JO=M1("werift-dtls : packages/dtls/src/flight/flight.ts : err"),GU=class W{constructor(Y,G,X,J){this.transport=Y,this.dtls=G,this.flight=X,this.nextFlight=J}state="PREPARING";static RetransmitCount=10;createPacket(Y){let G=fS(this.dtls)(Y);return this.dtls.bufferHandshakeCache(G,!0,this.flight),YU(this.dtls)(G.map((J)=>({type:22,fragment:J.serialize()})),++this.dtls.recordSequenceNumber)}async transmit(Y){let G=0;for(;G<=W.RetransmitCount;G++){if(this.setState("SENDING"),this.send(Y).catch((X)=>{JO("fail to send",JO)}),this.setState("WAITING"),this.nextFlight===void 0){this.setState("FINISHED");break}if(await Uo(1000*((G+1)/2)),this.dtls.flight>=this.nextFlight){this.setState("FINISHED");break}else Ho(this.dtls.sessionId,"retransmit",G,this.dtls.flight)}if(G>W.RetransmitCount)throw JO(this.dtls.sessionId,"retransmit failed",G),Error(`over retransmitCount : ${this.flight} ${this.nextFlight}`)}send=(Y)=>Promise.all(Y.map((G)=>this.transport.send(G)));setState(Y){this.state=Y}},No=class extends GU{constructor(W,Y,G){super(W,Y,1,3);this.cipher=G}async exec(W){if(this.dtls.flight===1)throw Error();this.dtls.flight=1;let Y=new bS({major:254,minor:253},new TY,Buffer.from([]),Buffer.from([]),fd,[0],W);this.dtls.version=Y.clientVersion,this.cipher.localRandom=TY.from(Y.random);let G=this.createPacket([Y]),X=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([X])}},qo=M1("werift-dtls : packages/dtls/src/flight/client/flight3.ts : log"),Ao=class extends GU{constructor(W,Y){super(W,Y,3,5)}async exec(W){if(this.dtls.flight===3)throw Error();this.dtls.flight=3,this.dtls.handshakeCache=[];let[Y]=this.dtls.lastFlight;qo("dtls version",Y.clientVersion),Y.cookie=W.cookie,this.dtls.cookie=W.cookie;let G=this.createPacket([Y]),X=Buffer.concat(G.map((J)=>J.serialize()));await this.transmit([X])}},Nq={NULL:0,ECDHE:1},XU={NULL:0,RSA:1,ECDSA:2,PSK:3},JU={NULL:0,RSA:1,ECDHE_RSA:2,ECDHE_ECDSA:3,PSK:4,ECDHE_PSK:5},ZU=class{id=0;name;signType;keyType;toString(){return this.name}};function Io(){let W=new ZU;return W.id=JU.RSA,W.name="RSA",W.keyType=XU.RSA,W}function zo(){let W=new ZU;return W.id=JU.ECDHE_RSA,W.name="ECDHE_RSA",W.signType=Nq.ECDHE,W.keyType=XU.RSA,W}function wo(){let W=new ZU;return W.id=JU.ECDHE_ECDSA,W.name="ECDHE_ECDSA",W.signType=Nq.ECDHE,W.keyType=XU.ECDSA,W}function jo(){let W=new ZU;return W.id=JU.PSK,W.name="PSK",W.signType=Nq.NULL,W.keyType=XU.PSK,W}function Oo(){let W=new ZU;return W.id=JU.ECDHE_PSK,W.name="ECDHE_PSK",W.signType=Nq.ECDHE,W.keyType=XU.PSK,W}var Co=M1("werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err"),To=class extends sd{keyLength=0;nonceLength=0;ivLength=0;authTagLength=0;nonceImplicitLength=0;nonceExplicitLength=0;clientWriteKey;serverWriteKey;clientNonce;serverNonce;constructor(){super()}get summary(){return gS(this)}init(W,Y,G){let X=ad(W,G,Y,this.keyLength,this.ivLength,this.nonceLength,this.hashAlgorithm);this.clientWriteKey=X.clientWriteKey,this.serverWriteKey=X.serverWriteKey,this.clientNonce=X.clientNonce,this.serverNonce=X.serverNonce}encrypt(W,Y,G){let X=W===p4.CLIENT,J=X?this.clientNonce:this.serverNonce,Z=X?this.clientWriteKey:this.serverWriteKey;if(!J||!Z)throw Error();J.writeUInt16BE(G.epoch,this.nonceImplicitLength),J.writeUIntBE(G.sequenceNumber,this.nonceImplicitLength+2,6);let V=J.slice(this.nonceImplicitLength),U=this.encodeAdditionalBuffer(G,Y.length),Q=Ko(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});Q.setAAD(U,{plaintextLength:Y.length});let H=Q.update(Y),N=Q.final(),A=Q.getAuthTag();return Buffer.concat([V,H,N,A])}encodeAdditionalBuffer(W,Y){let G=Buffer.alloc(13);return G.writeUInt16BE(W.epoch,0),G.writeUintBE(W.sequenceNumber,2,6),G.writeUInt8(W.type,8),G.writeUInt16BE(W.version,9),G.writeUInt16BE(Y,11),G}decrypt(W,Y,G){let X=W===p4.CLIENT,J=X?this.serverNonce:this.clientNonce,Z=X?this.serverWriteKey:this.clientWriteKey;if(!J||!Z)throw Error();Y.subarray(0,this.nonceExplicitLength).copy(J,this.nonceImplicitLength);let U=Y.subarray(this.nonceExplicitLength,Y.length-this.authTagLength),Q=Y.subarray(Y.length-this.authTagLength),H=this.encodeAdditionalBuffer(G,U.length),N=Do(this.blockAlgorithm,Z,J,{authTagLength:this.authTagLength});N.setAuthTag(Q),N.setAAD(H,{plaintextLength:U.length});let A=N.update(U);try{let q=N.final();return q.length>0?Buffer.concat([A,q]):A}catch(q){throw Co("decrypt failed",q,W,eO(Y),G,this.summary),q}}},g8={TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:49195,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:49196,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:49199,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:49200,TLS_RSA_WITH_AES_128_GCM_SHA256:156,TLS_RSA_WITH_AES_256_GCM_SHA384:157,TLS_PSK_WITH_AES_128_GCM_SHA256:168,TLS_PSK_WITH_AES_256_GCM_SHA384:169,TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:53249,TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:53250,TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256:52396,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:52393,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:52392,TLS_PSK_WITH_CHACHA20_POLY1305_SHA256:52395},kV={K_LEN:16,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},_V={K_LEN:32,N_MIN:12,N_MAX:12,P_MAX:68719476705,A_MAX:9007199254740991,C_MAX:68719476721},f$=Io(),c$=zo(),p$=wo(),l$=jo(),d$=Oo();function cS(W){switch(W){case g8.TLS_RSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_RSA_WITH_AES_128_GCM_SHA256,"TLS_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",f$,kV);case g8.TLS_RSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_RSA_WITH_AES_256_GCM_SHA384,"TLS_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",f$,_V,"sha384");case g8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",c$,kV);case g8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",c$,_V,"sha384");case g8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","aes-128-gcm",p$,kV);case g8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","aes-256-gcm",p$,_V,"sha384");case g8.TLS_PSK_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_PSK_WITH_AES_128_GCM_SHA256,"TLS_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",l$,kV,"sha256");case g8.TLS_PSK_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_PSK_WITH_AES_256_GCM_SHA384,"TLS_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",l$,_V,"sha384");case g8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256:return m7(g8.TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,"TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256","aes-128-gcm",d$,kV,"sha256");case g8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384:return m7(g8.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,"TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384","aes-256-gcm",d$,_V,"sha384");default:break}return null}function m7(W,Y,G,X,J,Z="sha256"){let V=new To;return V.id=W,V.name=Y,V.blockAlgorithm=G,V.kx=X,V.hashAlgorithm=Z,V.keyLength=J.K_LEN,V.nonceLength=J.N_MAX,V.nonceImplicitLength=4,V.nonceExplicitLength=8,V.ivLength=V.nonceImplicitLength,V.authTagLength=16,V}function lS(W){switch(W){case a6.secp256r1_23:{let{privateKey:Y,publicKey:G}=dd();return{curve:W,privateKey:Y,publicKey:G}}case a6.x25519_29:{let Y=pS.default.box.keyPair();return{curve:W,privateKey:Buffer.from(Y.secretKey.buffer),publicKey:Buffer.from(Y.publicKey.buffer)}}default:throw Error()}}var qq=class{static type=23},Aq=class W{static type=65281;static spec={type:RY.types.uint16be,data:RY.types.uint8};type=W.type;data=0;constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static deSerialize(Y){return new W(RY.decode(Y,W.spec))}serialize(){let Y=RY.encode(this,W.spec).slice();return Buffer.from(Y)}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},uX=class W{static type=14;static spec={type:i6.types.uint16be,data:i6.types.buffer(i6.types.uint16be)};type=W.type;data=Buffer.from([]);profiles=[];mki=Buffer.from([0]);constructor(Y={}){Object.assign(this,Y)}static create(Y,G){return new W({profiles:Y,mki:G})}static deSerialize(Y){let G=new W(i6.decode(Y,W.spec)),X=G.data.readUInt16BE(),J=Array(X/2);for(let Z=0;Z<J.length;Z++)J[Z]=G.data.readUInt16BE(Z*2+2);return G.profiles=J,G.mki=G.data.slice(X+2),G}serialize(){let Y=Buffer.alloc(2);Y.writeUInt16BE(this.profiles.length*2);let G=Buffer.concat([Y,...this.profiles.map((J)=>{let Z=Buffer.alloc(2);return Z.writeUInt16BE(J),Z}),this.mki]);this.data=G;let X=i6.encode(this,W.spec).slice();return Buffer.from(X)}static fromData(Y){let G=Buffer.alloc(4);return G.writeUInt16BE(W.type),G.writeUInt16BE(Y.length,2),W.deSerialize(Buffer.concat([G,Y]))}get extension(){return{type:this.type,data:this.serialize().slice(4)}}},eN=class W{constructor(Y){this.certificateList=Y}msgType=11;messageSeq;static spec={certificateList:MY.types.array(Go,MY.types.uint24be,"bytes")};static createEmpty(){return new W(void 0)}static deSerialize(Y){return new W(...Object.values(MY.decode(Y,W.spec)))}serialize(){let Y=MY.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},dS=class W{constructor(Y=1){this.type=Y}static spec={type:cX.types.uint8};static createEmpty(){return new W}static deSerialize(Y){return new W(...Object.values(cX.decode(Y,W.spec)))}serialize(){let Y=cX.encode(this,W.spec).slice();return Buffer.from(Y)}},oS=class W{constructor(Y,G){this.algorithm=Y,this.signature=G}msgType=15;messageSeq;static spec={algorithm:r6.types.uint16be,signature:r6.types.buffer(r6.types.uint16be)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){let G=r6.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){let Y=r6.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},nS=class W{constructor(Y){this.publicKey=Y}msgType=16;messageSeq;static spec={publicKey:PY.types.buffer(PY.types.uint8)};static createEmpty(){return new W(void 0)}static deSerialize(Y){let G=PY.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){let Y=PY.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},$O=class W{constructor(Y){this.verifyData=Y}msgType=20;messageSeq;static createEmpty(){return new W(void 0)}static deSerialize(Y){return new W(Y)}serialize(){return this.verifyData}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},iS=class W{constructor(Y,G,X){this.certificateTypes=Y,this.signatures=G,this.authorities=X}msgType=13;messageSeq;static spec={certificateTypes:X7.types.array(Xo,X7.types.uint8,"bytes"),signatures:X7.types.array(Zo,X7.types.uint16be,"bytes"),authorities:X7.types.array(Jo,X7.types.uint16be,"bytes")};static createEmpty(){return new W(void 0,void 0,void 0)}static deSerialize(Y){return new W(...Object.values(X7.decode(Y,W.spec)))}serialize(){let Y=X7.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},rS=class W{constructor(Y,G,X,J,Z,V){this.serverVersion=Y,this.random=G,this.sessionId=X,this.cipherSuite=J,this.compressionMethod=Z,this.extensions=V}msgType=2;messageSeq;static spec={serverVersion:WK,random:TY.spec,sessionId:J7.types.buffer(J7.types.uint8),cipherSuite:J7.types.uint16be,compressionMethod:J7.types.uint8};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){let G=J7.decode(Y,W.spec),X=new W(...Object.values(G));if(X.serialize().length<Y.length)return new W(...Object.values(J7.decode(Y,{...W.spec,extensions:BO})));return X}serialize(){let Y=this.extensions===void 0?J7.encode(this,W.spec).slice():J7.encode(this,{...W.spec,extensions:BO}).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},aS=class W{msgType=14;messageSeq;static spec={};static createEmpty(){return new W}static deSerialize(Y){return new W(...Object.values(Iq.decode(Y,W.spec)))}serialize(){let Y=Iq.encode(this,W.spec).slice();return Buffer.from(Y)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}};function Ro(W,Y){return Buffer.from(sS.encode(W,Y).slice())}var tS=class W{constructor(Y,G,X,J,Z,V,U,Q){this.ellipticCurveType=Y,this.namedCurve=G,this.publicKeyLength=X,this.publicKey=J,this.hashAlgorithm=Z,this.signatureAlgorithm=V,this.signatureLength=U,this.signature=Q}msgType=12;messageSeq;static spec={ellipticCurveType:Y7.types.uint8,namedCurve:Y7.types.uint16be,publicKeyLength:Y7.types.uint8,publicKey:Y7.types.buffer((Y)=>Y.current.publicKeyLength),hashAlgorithm:Y7.types.uint8,signatureAlgorithm:Y7.types.uint8,signatureLength:Y7.types.uint16be,signature:Y7.types.buffer((Y)=>Y.current.signatureLength)};static createEmpty(){return new W(void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}static deSerialize(Y){let G=Y7.decode(Y,W.spec);return new W(...Object.values(G))}serialize(){return Ro(this,W.spec)}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},zq=1,VU=7;var Mo=(W)=>{switch(W){case zq:case VU:return 16}},Po=(W)=>{switch(W){case zq:return 14;case VU:return 12}},kq0=M1("werift-rtp : packages/rtp/src/codec/av1.ts");var Bo={0:"Reserved",1:"OBU_SEQUENCE_HEADER",2:"OBU_TEMPORAL_DELIMITER",3:"OBU_FRAME_HEADER",4:"OBU_TILE_GROUP",5:"OBU_METADATA",6:"OBU_FRAME",7:"OBU_REDUNDANT_FRAME_HEADER",8:"OBU_TILE_LIST",15:"OBU_PADDING"},_q0=Object.entries(Bo).reduce((W,[Y,G])=>{return W[G]=Number(Y),W},{});var yq0=Buffer.from([0,0,0,1]);function o$(W,Y){let G=Buffer.alloc(Y);return W.copy(G),G}function Wq(W){return Number.parseInt(W.toString(),10)}function Eo(W){let Y=W[0];return Y>127&&Y<192}var FO=4,e6=class W{version=2;padding=!1;count=0;type=0;length=0;constructor(Y={}){Object.assign(this,Y)}static serialize(Y,G,X,J){let V=new W({type:Y,count:G,version:2,length:J}).serialize();return Buffer.concat([V,X])}serialize(){let Y=new nN(8);if(Y.set(2,0,this.version),this.padding)Y.set(1,2,1);return Y.set(5,3,this.count),E8([1,1,2],[Y.value,this.type,this.length])}static deSerialize(Y){let[G,X,J]=s9(Y,[1,1,2]),Z=u8(G,0,2),V=u8(G,2,1)>0,U=u8(G,3,5);return new W({version:Z,padding:V,count:U,type:X,length:J})}},n$=class W{static count=4;count=W.count;senderSsrc;mediaSsrc;fir=[];constructor(Y={}){Object.assign(this,Y)}get length(){return Math.floor(this.serialize().length/4-1)}static deSerialize(Y){let[G,X]=s9(Y,[4,4]),J=[];for(let Z=8;Z<Y.length;Z+=8)J.push({ssrc:Y.readUInt32BE(Z),sequenceNumber:Y[Z+4]});return new W({senderSsrc:G,mediaSsrc:X,fir:J})}serialize(){let Y=E8([4,4],[this.senderSsrc,this.mediaSsrc]),G=Buffer.alloc(this.fir.length*8);return this.fir.forEach(({ssrc:X,sequenceNumber:J},Z)=>{G.writeUInt32BE(X,Z*8),G[Z*8+4]=J}),Buffer.concat([Y,G])}},Yq=class W{static count=1;count=W.count;length=2;senderSsrc;mediaSsrc;constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let[G,X]=s9(Y,[4,4]);return new W({senderSsrc:G,mediaSsrc:X})}serialize(){return E8([4,4],[this.senderSsrc,this.mediaSsrc])}},Gq=class W{static count=15;length;count=W.count;senderSsrc;mediaSsrc;uniqueID="REMB";ssrcNum=0;brExp;brMantissa;bitrate;ssrcFeedbacks=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let[G,X,J,Z,V]=s9(Y,[4,4,4,1,1]),U=u8(V,0,6),Q=(u8(V,6,2)<<16)+(Y[14]<<8)+Y[15],H=U>46?18446744073709551615n:BigInt(Q)<<BigInt(U),N=[];for(let A=16;A<Y.length;A+=4){let q=Y.slice(A).readUIntBE(0,4);N.push(q)}return new W({senderSsrc:G,mediaSsrc:X,uniqueID:E8([4],[J]).toString(),ssrcNum:Z,brExp:U,brMantissa:Q,ssrcFeedbacks:N,bitrate:H})}serialize(){let Y=Buffer.concat([E8([4,4],[this.senderSsrc,this.mediaSsrc]),Buffer.from(this.uniqueID),E8([1],[this.ssrcNum])]),G=new nN(24);G.set(6,0,this.brExp).set(18,6,this.brMantissa);let X=Buffer.concat(this.ssrcFeedbacks.map((Z)=>E8([4],[Z]))),J=Buffer.concat([Y,E8([3],[G.value]),X]);return this.length=J.length/4,J}},$o=M1("werift-rtp: /rtcp/psfb/index"),iV=class W{static type=206;type=W.type;feedback;constructor(Y={}){Object.assign(this,Y)}serialize(){let Y=this.feedback.serialize();return e6.serialize(this.type,this.feedback.count,Y,this.feedback.length)}static deSerialize(Y,G){let X;switch(G.count){case n$.count:X=n$.deSerialize(Y);break;case Yq.count:X=Yq.deSerialize(Y);break;case Gq.count:X=Gq.deSerialize(Y);break;default:$o("unknown psfb packet",G.count);break}return new W({feedback:X})}},rV=class W{ssrc=0;reports=[];static type=201;type=W.type;constructor(Y={}){Object.assign(this,Y)}serialize(){let Y=E8([4],[this.ssrc]);return Y=Buffer.concat([Y,...this.reports.map((G)=>G.serialize())]),e6.serialize(W.type,this.reports.length,Y,Math.floor(Y.length/4))}static deSerialize(Y,G){let[X]=s9(Y,[4]),J=4,Z=[];for(let V=0;V<G;V++)Z.push(YK.deSerialize(Y.slice(J,J+24))),J+=24;return new W({ssrc:X,reports:Z})}},YK=class W{ssrc;fractionLost;packetsLost;highestSequence;jitter;lsr;dlsr;constructor(Y={}){Object.assign(this,Y)}toJSON(){return{ssrc:this.ssrc,fractionLost:this.fractionLost,packetsLost:this.packetsLost,highestSequence:this.highestSequence,jitter:this.jitter,lsr:this.lsr,dlsr:this.dlsr}}serialize(){return E8([4,1,3,4,4,4,4],[this.ssrc,this.fractionLost,this.packetsLost,this.highestSequence,this.jitter,this.lsr,this.dlsr])}static deSerialize(Y){let[G,X,J,Z,V,U,Q]=s9(Y,[4,1,3,4,4,4,4]);return new W({ssrc:G,fractionLost:X,packetsLost:J,highestSequence:Z,jitter:V,lsr:U,dlsr:Q})}},eS=205,Xq=class W{static count=1;count=W.count;header;senderSsrc;mediaSourceSsrc;lost=[];toJSON(){return{lost:this.lost,senderSsrc:this.senderSsrc,mediaSourceSsrc:this.mediaSourceSsrc}}constructor(Y={}){if(Object.assign(this,Y),!this.header)this.header=new e6({type:eS,count:this.count,version:2})}static deSerialize(Y,G){let[X,J]=s9(Y,[4,4]),Z=[];for(let V=8;V<Y.length;V+=4){let[U,Q]=s9(Y.subarray(V),[2,2]);Z.push(U);for(let H=0;H<16;H++)if(Q>>H&1)Z.push(U+H+1)}return new W({header:G,senderSsrc:X,mediaSourceSsrc:J,lost:Z})}serialize(){let Y=E8([4,4],[this.senderSsrc,this.mediaSourceSsrc]),G=[];if(this.lost.length>0){let J=this.lost[0],Z=0;this.lost.slice(1).forEach((V)=>{let U=V-J-1;if(U>=0&&U<16)Z|=1<<U;else G.push(E8([2,2],[J,Z])),J=V,Z=0}),G.push(E8([2,2],[J,Z]))}let X=Buffer.concat([Y,Buffer.concat(G)]);return this.header.length=X.length/4,Buffer.concat([this.header.serialize(),X])}},Fo=M1("werift/rtp/rtcp/rtpfb/twcc"),Jq=class W{static count=15;count=W.count;length=2;senderSsrc;mediaSourceSsrc;baseSequenceNumber;packetStatusCount;referenceTime;fbPktCount;packetChunks=[];recvDeltas=[];header;constructor(Y={}){if(Object.assign(this,Y),!this.header)this.header=new e6({type:205,count:this.count,version:2})}static deSerialize(Y,G){let[X,J,Z,V,U,Q]=s9(Y,[4,4,2,2,3,1]),H=[],N=[],A=16;for(let z=0;z<V;){let w=u8(Y.slice(A,A+1)[0],0,1),D;switch(w){case 0:{let T=dV.deSerialize(Y.slice(A,A+2));D=T;let x=Math.min(V-z,T.runLength);if(T.packetStatus===1||T.packetStatus===2)for(let g=0;g<x;g++)N.push(new yN({type:T.packetStatus}));z+=x}break;case 1:{let T=So.deSerialize(Y.slice(A,A+2));if(D=T,T.symbolSize===0)T.symbolList.forEach((x)=>{if(x===1)N.push(new yN({type:1}))});if(T.symbolSize===1)T.symbolList.forEach((x)=>{if(x===1||x===2)N.push(new yN({type:x}))});z+=T.symbolList.length}break}if(!D)throw Error();A+=2,H.push(D)}let q=A;return N.forEach((z)=>{if(z.type===1)z.deSerialize(Y.slice(q,q+1)),q++;if(z.type===2)z.deSerialize(Y.slice(q,q+2)),q+=2}),new W({senderSsrc:X,mediaSourceSsrc:J,baseSequenceNumber:Z,packetStatusCount:V,referenceTime:U,fbPktCount:Q,recvDeltas:N,packetChunks:H,header:G})}serialize(){let Y=E8([4,4,2,2,3,1],[this.senderSsrc,this.mediaSourceSsrc,this.baseSequenceNumber,this.packetStatusCount,this.referenceTime,this.fbPktCount]),G=Buffer.concat(this.packetChunks.map((Z)=>Z.serialize())),X=Buffer.concat(this.recvDeltas.map((Z)=>{try{return Z.serialize()}catch(V){Fo(V?.message);return}}).filter((Z)=>Z)),J=Buffer.concat([Y,G,X]);if(this.header.padding&&J.length%4!==0){let Z=4-J.length%4,V=Buffer.alloc(Z);return V[V.length-1]=V.length,this.header.length=Math.floor((J.length+V.length)/4),Buffer.concat([this.header.serialize(),J,V])}return this.header.length=Math.floor(J.length/4),Buffer.concat([this.header.serialize(),J])}get packetResults(){let Y=this.baseSequenceNumber-1,G=this.packetChunks.filter((V)=>V instanceof dV).flatMap((V)=>V.results(Y)),X=0,Z=BigInt(this.referenceTime)*64n;for(let V of G){let U=this.recvDeltas[X];if(!V.received||!U)continue;Z+=BigInt(U.delta)/1000n,V.delta=U.delta,V.receivedAtMs=Number(Z),X++}return G}},dV=class W{type;packetStatus;runLength;constructor(Y={}){Object.assign(this,Y),this.type=0}static deSerialize(Y){let G=u8(Y[0],1,2),X=(u8(Y[0],3,5)<<8)+Y[1];return new W({type:0,packetStatus:G,runLength:X})}serialize(){return new wS(16).set(0).set(this.packetStatus,2).set(this.runLength,13).buffer}results(Y){let G=this.packetStatus===1||this.packetStatus===2,X=[];for(let J=0;J<=this.runLength;++J)X.push(new xo({sequenceNumber:++Y,received:G}));return X}},So=class W{type;symbolSize;symbolList=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let X=u8(Y[0],1,1),J=[];function Z(V,U){for(let Q=0;Q<V;Q++)U(Q)}switch(X){case 0:Z(6,(V)=>J.push(u8(Y[0],2+V,1))),Z(8,(V)=>J.push(u8(Y[1],V,1)));break;case 1:Z(3,(V)=>J.push(u8(Y[0],2+V*2,2))),Z(4,(V)=>J.push(u8(Y[1],V*2,2)));break;default:X=(u8(Y[0],2,6)<<8)+Y[1]}return new W({type:1,symbolSize:X,symbolList:J})}serialize(){let Y=Buffer.alloc(2),G=new wS(16).set(1).set(this.symbolSize),X=this.symbolSize===0?1:2;return this.symbolList.forEach((J)=>{G.set(J,X)}),Y.writeUInt16BE(G.value),Y}},yN=class W{type;delta;constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let G,X;if(Y.length===1)G=1,X=250*Y[0];else if(Y.length===2)G=2,X=250*Y.readInt16BE();if(G===void 0||X===void 0)throw Error();return new W({type:G,delta:X})}deSerialize(Y){let G=W.deSerialize(Y);this.delta=G.delta}parsed=!1;parseDelta(){if(this.delta=Math.floor(this.delta/250),this.delta<0||this.delta>255){if(this.delta>32767)this.delta=32767;if(this.delta<-32768)this.delta=-32768;if(!this.type)this.type=2}else if(!this.type)this.type=1;this.parsed=!0}serialize(){if(!this.parsed)this.parseDelta();if(this.type===1){let Y=Buffer.alloc(1);return Y.writeUInt8(this.delta),Y}else if(this.type===2){let Y=Buffer.alloc(2);return Y.writeInt16BE(this.delta),Y}throw Error("errDeltaExceedLimit "+this.delta+" "+this.type)}};var xo=class{sequenceNumber=0;delta=0;received=!1;receivedAtMs=0;constructor(W){Object.assign(this,W)}},ko=M1("werift-rtp:packages/rtp/rtcp/rtpfb/index"),hX=class W{static type=eS;type=W.type;feedback;header;constructor(Y={}){Object.assign(this,Y)}serialize(){return this.feedback.serialize()}static deSerialize(Y,G){let X;switch(G.count){case Xq.count:X=Xq.deSerialize(Y,G);break;case Jq.count:X=Jq.deSerialize(Y,G);break;default:ko("unknown rtpfb packet",G.count);break}return new W({feedback:X,header:G})}},Zq=class W{static type=202;type=W.type;chunks=[];constructor(Y){Object.assign(this,Y)}get length(){let Y=0;return this.chunks.forEach((G)=>Y+=G.length),Y}serialize(){let Y=Buffer.concat(this.chunks.map((G)=>G.serialize()));while(Y.length%4)Y=Buffer.concat([Y,Buffer.from([0])]);return e6.serialize(this.type,this.chunks.length,Y,Y.length/4)}static deSerialize(Y,G){let X=[];for(let J=0;J<Y.length;){let Z=W2.deSerialize(Y.slice(J));X.push(Z),J+=Z.length}return new W({chunks:X})}},W2=class W{source;items=[];constructor(Y={}){Object.assign(this,Y)}get length(){let Y=4;return this.items.forEach((G)=>Y+=G.length),Y+=1,Y+=i$(Y),Y}serialize(){let Y=Buffer.concat([E8([4],[this.source]),Buffer.concat(this.items.map((X)=>X.serialize()))]);return Buffer.concat([Y,Buffer.alloc(i$(Y.length))])}static deSerialize(Y){let G=Y.readUInt32BE(),X=[];for(let J=4;J<Y.length;){if(Y[J]===0)break;let V=Y2.deSerialize(Y.slice(J));X.push(V),J+=V.length}return new W({source:G,items:X})}},Y2=class W{type;text;constructor(Y){Object.assign(this,Y)}get length(){return 2+Buffer.from(this.text).length}serialize(){let Y=Buffer.from(this.text);return Buffer.concat([E8([1,1],[this.type,Y.length]),Y])}static deSerialize(Y){let G=Y[0],X=Y[1],J=Y.slice(2,2+X).toString();return new W({type:G,text:J})}};function i$(W){if(W%4==0)return 0;return 4-W%4}var bX=class W{ssrc=0;senderInfo;reports=[];static type=200;type=W.type;constructor(Y){Object.assign(this,Y)}toJSON(){return{ssrc:this.ssrc,senderInfo:this.senderInfo.toJSON(),reports:this.reports.map((Y)=>Y.toJSON())}}serialize(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.ssrc),Y=Buffer.concat([Y,this.senderInfo.serialize()]),Y=Buffer.concat([Y,...this.reports.map((G)=>G.serialize())]),e6.serialize(W.type,this.reports.length,Y,Math.floor(Y.length/4))}static deSerialize(Y,G){let X=Y.readUInt32BE(),J=G2.deSerialize(Y.subarray(4,24)),Z=24,V=[];for(let Q=0;Q<G;Q++)V.push(YK.deSerialize(Y.subarray(Z,Z+24))),Z+=24;return new W({ssrc:X,senderInfo:J,reports:V})}},G2=class W{ntpTimestamp;rtpTimestamp;packetCount;octetCount;constructor(Y={}){Object.assign(this,Y)}toJSON(){return{ntpTimestamp:_o(this.ntpTimestamp),rtpTimestamp:this.rtpTimestamp}}serialize(){return E8([8,4,4,4],[this.ntpTimestamp,this.rtpTimestamp,this.packetCount,this.octetCount])}static deSerialize(Y){let[G,X,J,Z]=s9(Y,[8,4,4,4]);return new W({ntpTimestamp:G,rtpTimestamp:X,packetCount:J,octetCount:Z})}},_o=(W)=>{let[Y,G]=s9(E8([8],[W]),[4,4]);return Number(`${Y}.${G}`)},yo=M1("werift-rtp:packages/rtp/src/rtcp/rtcp.ts"),vo=class{static deSerialize(W){let Y=0,G=[];while(Y<W.length){let X=e6.deSerialize(W.subarray(Y,Y+FO));Y+=FO;let J=W.subarray(Y);if(Y+=X.length*4,X.padding)J=J.subarray(0,J.length-J.subarray(-1)[0]);try{switch(X.type){case bX.type:G.push(bX.deSerialize(J,X.count));break;case rV.type:G.push(rV.deSerialize(J,X.count));break;case Zq.type:G.push(Zq.deSerialize(J,X));break;case hX.type:G.push(hX.deSerialize(J,X));break;case iV.type:G.push(iV.deSerialize(J,X));break;default:break}}catch(Z){yo("deSerialize RTCP",Z)}}return G}};function go(W){return W.length>=2&&W[1]>=192&&W[1]<=208}var C9={sdesMid:"urn:ietf:params:rtp-hdrext:sdes:mid",sdesRTPStreamID:"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",repairedRtpStreamId:"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",transportWideCC:"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",absSendTime:"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",dependencyDescriptor:"https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension",audioLevelIndication:"urn:ietf:params:rtp-hdrext:ssrc-audio-level",videoOrientation:"urn:3gpp:video-orientation"};function uo(W,Y){return W.map((G)=>{let X=Y[G.id];if(!X)return{uri:"unknown",value:G.payload};switch(X){case C9.sdesMid:case C9.sdesRTPStreamID:case C9.repairedRtpStreamId:return{uri:X,value:po(G.payload)};case C9.transportWideCC:return{uri:X,value:lo(G.payload)};case C9.absSendTime:return{uri:X,value:oo(G.payload)};case C9.audioLevelIndication:return{uri:X,value:no(G.payload)};case C9.videoOrientation:return{uri:X,value:io(G.payload)};default:return{uri:X,value:G.payload}}}).reduce((G,X)=>{if(X)G[X.uri]=X.value;return G},{})}function ho(W){return Buffer.from(W)}function bo(W){return Buffer.from(W)}function mo(W){return Buffer.from(W)}function fo(W){return E8([2],[W])}function co(W){let Y=Buffer.alloc(3),G=W>>14n&0x00ffffffn;return Y.writeUIntBE(Number(G),0,3),Y}function po(W){return W.toString()}function lo(W){return W.readUInt16BE()}function oo(W){return s9(W,[3])[0]}function no(W){let Y=new pV(W);return{v:Y.readBits(1)===1,level:Y.readBits(7)}}function io(W){let Y=new pV(W);return Y.readBits(4),{c:Y.readBits(1),f:Y.readBits(1),r1:Y.readBits(1),r0:Y.readBits(1)}}var ro=M1("packages/rtp/src/rtp/red/packet.ts"),X2=class W{header;blocks=[];static deSerialize(Y){let G=Y instanceof ArrayBuffer?Buffer.from(Y):Y,X=new W,J=0;return[X.header,J]=r$.deSerialize(G),X.header.fields.forEach(({blockLength:Z,timestampOffset:V,blockPT:U})=>{if(Z&&V){let Q=G.subarray(J,J+Z);X.blocks.push({block:Q,blockPT:U,timestampOffset:V}),J+=Z}else{let Q=G.subarray(J);X.blocks.push({block:Q,blockPT:U})}}),X}serialize(){this.header=new r$;for(let{timestampOffset:G,blockPT:X,block:J}of this.blocks)if(G)this.header.fields.push({fBit:1,blockPT:X,blockLength:J.length,timestampOffset:G});else this.header.fields.push({fBit:0,blockPT:X});let Y=this.header.serialize();for(let{block:G}of this.blocks)Y=Buffer.concat([Y,G]);return Y}},r$=class W{fields=[];static deSerialize(Y){let G=0,X=new W;for(;;){let J={};X.fields.push(J);let Z=new pV(Y.subarray(G));if(J.fBit=Z.readBits(1),J.blockPT=Z.readBits(7),G++,J.fBit===0)break;J.timestampOffset=Z.readBits(14),J.blockLength=Z.readBits(10),G+=3}return[X,G]}serialize(){let Y=Buffer.alloc(0);for(let G of this.fields)try{if(G.timestampOffset&&G.blockLength){let X=new pV(Buffer.alloc(4)).writeBits(1,G.fBit).writeBits(7,G.blockPT).writeBits(14,G.timestampOffset).writeBits(10,G.blockLength);Y=Buffer.concat([Y,X.uint8Array])}else{let X=new pV(Buffer.alloc(1)).writeBits(1,0).writeBits(7,G.blockPT);Y=Buffer.concat([Y,X.uint8Array])}}catch(X){ro(X?.message)}return Y}},ao=class{constructor(W=1){this.distance=W}cache=[];cacheSize=10;push(W){if(this.cache.push(W),this.cache.length>this.cacheSize)this.cache.shift()}build(){let W=new X2,Y=this.cache.slice(-(this.distance+1)),G=Y.pop();if(!G)return W;return Y.forEach((X)=>{let J=vX(G.timestamp,-X.timestamp);if(J>so)return;W.blocks.push({block:X.block,blockPT:X.blockPT,timestampOffset:J})}),W.blocks.push({block:G.block,blockPT:G.blockPT}),W}},so=16383,to=class{size=150;sequenceNumbers=[];push(W,Y){let G=[];return W.blocks.forEach(({blockPT:J,timestampOffset:Z,block:V},U)=>{let Q=T9(Y.header.sequenceNumber,-(W.blocks.length-(U+1)));if(Z)G.push(new t6(new s6({timestamp:vX(Y.header.timestamp,-Z),payloadType:J,ssrc:Y.header.ssrc,sequenceNumber:Q,marker:!0}),V));else G.push(new t6(new s6({timestamp:Y.header.timestamp,payloadType:J,ssrc:Y.header.ssrc,sequenceNumber:Q,marker:!0}),V))}),G.filter((J)=>{if(this.sequenceNumbers.includes(J.header.sequenceNumber))return!1;else{if(this.sequenceNumbers.length>this.size)this.sequenceNumbers.shift();return this.sequenceNumbers.push(J.header.sequenceNumber),!0}})}},jY={OneByte:48862,TwoByte:4096},a$=2,s$=4,t$=8,e$=12,WF=4,s6=class W{version=2;padding=!1;paddingSize=0;extension=!1;marker=!1;payloadOffset=0;payloadType=0;sequenceNumber=0;timestamp=0;ssrc=0;csrcLength=0;csrc=[];extensionProfile=jY.OneByte;extensionLength;extensions=[];constructor(Y={}){Object.assign(this,Y)}static deSerialize(Y){let G=new W,X=0,J=Y[X++];G.version=u8(J,0,2),G.padding=u8(J,2)>0,G.extension=u8(J,3)>0,G.csrcLength=u8(J,4,4),G.csrc=[...Array(G.csrcLength)].map(()=>{let V=Y.readUInt32BE(X);return X+=4,V}),X+=e$-1;let Z=Y[1];G.marker=u8(Z,0)>0,G.payloadType=u8(Z,1,7),G.sequenceNumber=Y.readUInt16BE(a$),G.timestamp=Y.readUInt32BE(s$),G.ssrc=Y.readUInt32BE(t$);for(let V=0;V<G.csrc.length;V++){let U=e$+V*WF;G.csrc[V]=Y.subarray(U).readUInt32BE()}if(G.extension){G.extensionProfile=Y.subarray(X).readUInt16BE(),X+=2;let V=Y.subarray(X).readUInt16BE()*4;switch(G.extensionLength=V,X+=2,G.extensionProfile){case jY.OneByte:{let U=X+V;while(X<U){if(Y[X]===0){X++;continue}let Q=Y[X]>>4,H=(Y[X]&(Y[X]^240))+1;if(X++,Q===15)break;let N={id:Q,payload:Y.subarray(X,X+H)};G.extensions=[...G.extensions,N],X+=H}}break;case jY.TwoByte:{let U=X+V;while(X<U){if(Y[X]===0){X++;continue}let Q=Y[X];X++;let H=Y[X];X++;let N={id:Q,payload:Y.subarray(X,X+H)};G.extensions=[...G.extensions,N],X+=H}}break;default:{let U={id:0,payload:Y.subarray(X,X+V)};G.extensions=[...G.extensions,U],X+=G.extensions[0].payload.length}break}}if(G.payloadOffset=X,G.padding)G.paddingSize=Y[Y.length-1];return G}get serializeSize(){let{csrc:Y,extensionProfile:G,extensions:X}=this,J=12+Y.length*WF;if(X.length>0||this.extension===!0){let Z=4;switch(G){case jY.OneByte:for(let V of X)Z+=1+V.payload.length;break;case jY.TwoByte:for(let V of X)Z+=2+V.payload.length;break;default:Z+=X[0].payload.length}J+=Math.floor((Z+3)/4)*4}return J}serialize(Y){let G=Buffer.alloc(Y),X=0,J=new nN(8);if(J.set(2,0,this.version),this.padding)J.set(1,2,1);if(this.extensions.length>0)this.extension=!0;if(this.extension)J.set(1,3,1);J.set(4,4,this.csrc.length),G.writeUInt8(J.value,X++);let Z=new nN(8);if(this.marker)Z.set(1,0,1);Z.set(7,1,this.payloadType),G.writeUInt8(Z.value,X++),G.writeUInt16BE(this.sequenceNumber,a$),X+=2,G.writeUInt32BE(this.timestamp,s$),X+=4,G.writeUInt32BE(this.ssrc,t$),X+=4;for(let V of this.csrc)G.writeUInt32BE(V,X),X+=4;if(this.extension){let V=X;G.writeUInt16BE(this.extensionProfile,X),X+=4;let U=X;switch(this.extensionProfile){case jY.OneByte:for(let N of this.extensions)G.writeUInt8(N.id<<4|N.payload.length-1,X++),N.payload.copy(G,X),X+=N.payload.length;break;case jY.TwoByte:for(let N of this.extensions)G.writeUInt8(N.id,X++),G.writeUInt8(N.payload.length,X++),N.payload.copy(G,X),X+=N.payload.length;break;default:{let N=this.extensions[0].payload.length;if(N%4!=0)throw Error();this.extensions[0].payload.copy(G,X),X+=N}}let Q=X-U,H=Math.trunc((Q+3)/4)*4;G.writeUInt16BE(Math.trunc(H/4),V+2);for(let N=0;N<H-Q;N++)G.writeUInt8(0,X),X++}return this.payloadOffset=X,G}},t6=class W{constructor(Y,G){this.header=Y,this.payload=G}get serializeSize(){return this.header.serializeSize+this.payload.length}clone(){return new W(new s6({...this.header}),this.payload)}serialize(){let Y=this.header.serialize(this.header.serializeSize+this.payload.length),{payloadOffset:G}=this.header;if(this.payload.copy(Y,G),this.header.padding){let X=Buffer.alloc(this.header.paddingSize);X.writeUInt8(this.header.paddingSize,this.header.paddingSize-1),Y=Buffer.concat([Y,X])}return Y}static deSerialize(Y){let G=s6.deSerialize(Y);return new W(G,Y.subarray(G.payloadOffset,Y.length-G.paddingSize))}clear(){this.payload=null}};function eo(W,Y,G){return new t6(new s6({payloadType:Y,marker:W.header.marker,sequenceNumber:s1.Unpack("!H",W.payload.subarray(0,2))[0],timestamp:W.header.timestamp,ssrc:G}),W.payload.subarray(2))}function Wn(W,Y,G,X){return new t6(new s6({payloadType:Y,marker:W.header.marker,sequenceNumber:G,timestamp:W.header.timestamp,ssrc:X,csrc:W.header.csrc,extensions:W.header.extensions}),Buffer.concat([Buffer.from(s1.Pack("!H",[W.header.sequenceNumber])),W.payload]))}var J2=class{constructor(W,Y,G,X){this.srtpSessionKey=W,this.srtpSessionSalt=Y,this.srtcpSessionKey=G,this.srtcpSessionSalt=X}encryptRtp(W,Y,G){return Buffer.from([])}decryptRtp(W,Y,G){return[]}encryptRTCP(W,Y){return Buffer.from([])}decryptRTCP(W){return[]}},mX=class extends Error{constructor(W){super(W);this.name="SrtpAuthenticationError"}},JF=12,Gn=8;function GK(W,Y,G="Failed to authenticate SRTP packet"){let X=W.length-Y;aV(W.length>=JF+Y,G);let J=V2(()=>s6.deSerialize(W.subarray(0,X)),G);return J.paddingSize=0,aV(J.payloadOffset>=JF&&J.payloadOffset<=X,G),J}function Z2(W,Y,G,X="Failed to authenticate SRTCP packet"){return aV(W.length>=Gn+Y+G,X),V2(()=>e6.deSerialize(W.subarray(0,FO)),X)}function aV(W,Y){if(!W)throw new mX(Y)}function V2(W,Y){try{return W()}catch{throw new mX(Y)}}function U2(W,Y,G="Failed to authenticate SRTP packet"){if(!W.padding)return W.paddingSize=0,W;aV(Y.length>W.payloadOffset,G);let X=Y[Y.length-1];return aV(X>0&&X<=Y.length-W.payloadOffset,G),W.paddingSize=X,W}var Xn=class extends J2{constructor(W,Y,G,X,J,Z){super(W,Y,G,X);this.srtpSessionAuthTag=J,this.srtcpSessionAuthTag=Z}authTagLength=10;encryptRtp(W,Y,G){let X=W.serialize(W.serializeSize),J=this.generateCounter(W.sequenceNumber,G,W.ssrc,this.srtpSessionSalt),V=YF("aes-128-ctr",this.srtpSessionKey,J).update(Y),U=this.generateSrtpAuthTag(G,X,V);return Buffer.concat([X,V,U])}decryptRtp(W,Y,G=GK(W,this.authTagLength)){let X=W.length-this.authTagLength,J=W.subarray(0,X),Z=W.subarray(X),V=this.generateSrtpAuthTag(Y,J.subarray(0,G.payloadOffset),J.subarray(G.payloadOffset));VF(Z,V,"Failed to authenticate SRTP packet");let U=this.generateCounter(G.sequenceNumber,Y,G.ssrc,this.srtpSessionSalt),Q=GF("aes-128-ctr",this.srtpSessionKey,U),H=J.subarray(G.payloadOffset),N=Q.update(H),A=Buffer.concat([J.subarray(0,G.payloadOffset),N]);return[A,U2(G,A,"Failed to authenticate SRTP packet")]}encryptRTCP(W,Y){let G=Buffer.from(W),X=G.readUInt32BE(4),J=this.generateCounter(Y&65535,Y>>16,X,this.srtcpSessionSalt);YF("aes-128-ctr",this.srtcpSessionKey,J).update(G.slice(8)).copy(G,8),G=Buffer.concat([G,Buffer.alloc(4)]),G.writeUInt32BE(Y,G.length-4),G[G.length-4]|=128;let U=this.generateSrtcpAuthTag(G);return G=Buffer.concat([G,U]),G}decryptRTCP(W){let Y=Z2(W,this.authTagLength,ZF),G=W.length-(this.authTagLength+ZF),X=W.subarray(0,W.length-this.authTagLength),J=W.subarray(W.length-this.authTagLength),Z=this.generateSrtcpAuthTag(X);VF(J,Z,"Failed to authenticate SRTCP packet");let V=Buffer.from(W).slice(0,G);if(W[G]>>>7===0)return[V,Y];let Q=W.readUInt32BE(G);Q&=2147483647;let H=W.readUInt32BE(4),N=this.generateCounter(Q&65535,Q>>16,H,this.srtcpSessionSalt);return GF("aes-128-ctr",this.srtcpSessionKey,N).update(V.subarray(8)).copy(V,8),[V,Y]}generateSrtcpAuthTag(W){return XF("sha1",this.srtcpSessionAuthTag).update(W).digest().slice(0,10)}generateCounter(W,Y,G,X){let J=Buffer.alloc(16);J.writeUInt32BE(G,4),J.writeUInt32BE(Y,8),J.writeUInt32BE(Number(BigInt(W)<<16n),12);for(let Z=0;Z<X.length;Z++)J[Z]^=X[Z];return J}generateSrtpAuthTag(W,...Y){let G=XF("sha1",this.srtpSessionAuthTag),X=Buffer.alloc(4);X.writeUInt32BE(W);for(let J of Y)G.update(J);return G.update(X).digest().subarray(0,10)}},ZF=4;function VF(W,Y,G){if(W.length!==Y.length||!Yn(W,Y))throw new mX(G)}var Jn=class extends J2{aeadAuthTagLen=16;rtpIvWriter=_N([2,4,4,2],!0);rtcpIvWriter=_N([2,4,2,4],!0);aadWriter=_N([4],!0);constructor(W,Y,G,X){super(W,Y,G,X)}encryptRtp(W,Y,G){let X=W.serialize(W.serializeSize),J=this.rtpInitializationVector(W,G),Z=UF("aes-128-gcm",this.srtpSessionKey,J);Z.setAAD(X);let V=Z.update(Y);Z.final();let U=Z.getAuthTag();return Buffer.concat([X,V,U])}decryptRtp(W,Y,G=GK(W,this.aeadAuthTagLen)){let X=W.subarray(0,G.payloadOffset),J=W.length-this.aeadAuthTagLen,Z=W.subarray(J),V=Buffer.from([]);V=o$(V,W.length-this.aeadAuthTagLen),X.copy(V);let U=this.rtpInitializationVector(G,Y),Q=W.slice(G.payloadOffset,J),H=QF("aes-128-gcm",this.srtpSessionKey,U);H.setAAD(X),H.setAuthTag(Z);let N=H.update(Q);return NF(H,"SRTP"),N.copy(V,G.payloadOffset),[V,U2(G,V,"Failed to authenticate SRTP packet")]}encryptRTCP(W,Y){let G=W.readUInt32BE(4),X=W.length+this.aeadAuthTagLen,J=Buffer.from([]);J=o$(J,X+VO),W.slice(0,8).copy(J);let Z=this.rtcpInitializationVector(G,Y),V=this.rtcpAdditionalAuthenticatedData(W,Y),U=UF("aes-128-gcm",this.srtcpSessionKey,Z);U.setAAD(V);let Q=U.update(W.slice(8));return U.final(),Q.copy(J,8),U.getAuthTag().copy(J,8+Q.length),V.slice(8,12).copy(J,X),J}decryptRTCP(W){let Y=Z2(W,this.aeadAuthTagLen,VO),G=W.length-VO,X=G-this.aeadAuthTagLen,J=W.readUInt32BE(4),Z=W.readUInt32BE(G),V=Z>>>31===1,U=Z&~(HF<<24),Q=this.rtcpInitializationVector(J,U),H=V?Buffer.concat([W.subarray(0,8),W.subarray(G)]):Buffer.concat([W.subarray(0,X),W.subarray(G)]),N=V?W.slice(8,X):Buffer.alloc(0),A=V?Buffer.alloc(X):Buffer.from(W.subarray(0,X));if(V)W.slice(0,8).copy(A);let q=QF("aes-128-gcm",this.srtcpSessionKey,Q);q.setAAD(H),q.setAuthTag(W.subarray(X,G));let z=q.update(N);if(NF(q,"SRTCP"),V)z.copy(A,8);return[A,Y]}rtpInitializationVector(W,Y){let G=this.rtpIvWriter([0,W.ssrc,Y,W.sequenceNumber]);for(let X=0;X<G.length;X++)G[X]^=this.srtpSessionSalt[X];return G}rtcpInitializationVector(W,Y){let G=this.rtcpIvWriter([0,W,0,Y]);for(let X=0;X<G.length;X++)G[X]^=this.srtcpSessionSalt[X];return G}rtcpAdditionalAuthenticatedData(W,Y){let G=Buffer.concat([W.subarray(0,8),this.aadWriter([Y])]);return G[8]|=HF,G}},VO=4,HF=128;function NF(W,Y){try{W.final()}catch{throw new mX(`Failed to authenticate ${Y} packet`)}}var Q2=class{constructor(W,Y,G){this.masterKey=W,this.masterSalt=Y,this.profile=G;{let X=14-Y.length;if(X>0)this.masterSalt=Buffer.concat([Y,Buffer.alloc(X)])}switch(this.srtpSessionKey=this.generateSessionKey(0),this.srtpSessionSalt=this.generateSessionSalt(2),this.srtpSessionAuthTag=this.generateSessionAuthTag(1),this.srtpSessionAuth=ZO("sha1",this.srtpSessionAuthTag),this.srtcpSessionKey=this.generateSessionKey(3),this.srtcpSessionSalt=this.generateSessionSalt(5),this.srtcpSessionAuthTag=this.generateSessionAuthTag(4),this.srtcpSessionAuth=ZO("sha1",this.srtcpSessionAuthTag),G){case zq:this.cipher=new Xn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt,this.srtpSessionAuthTag,this.srtcpSessionAuthTag);break;case VU:this.cipher=new Jn(this.srtpSessionKey,this.srtpSessionSalt,this.srtcpSessionKey,this.srtcpSessionSalt);break}}srtpSSRCStates={};srtpSessionKey;srtpSessionSalt;srtpSessionAuthTag;srtpSessionAuth;srtcpSSRCStates={};srtcpSessionKey;srtcpSessionSalt;srtcpSessionAuthTag;srtcpSessionAuth;cipher;generateSessionKey(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=Y.length-1;J>=0;J--,Z--)Y[Z]=Y[Z]^G[J];Y=Buffer.concat([Y,Buffer.from([0,0])]);let X=new vN.default.AES(this.masterKey);return Buffer.from(X.encrypt(Y))}generateSessionSalt(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let J=G.length-1,Z=Y.length-1;J>=0;J--,Z--)Y[Z]=Y[Z]^G[J];Y=Buffer.concat([Y,Buffer.from([0,0])]);let X=new vN.default.AES(this.masterKey);return Y=Buffer.from(X.encrypt(Y)),Y.subarray(0,14)}generateSessionAuthTag(W){let Y=Buffer.from(this.masterSalt),G=Buffer.from([W,0,0,0,0,0,0]);for(let V=G.length-1,U=Y.length-1;V>=0;V--,U--)Y[U]=Y[U]^G[V];let X=Buffer.concat([Y,Buffer.from([0,0])]),J=Buffer.concat([Y,Buffer.from([0,1])]),Z=new vN.default.AES(this.masterKey);return X=Buffer.from(Z.encrypt(X)),J=Buffer.from(Z.encrypt(J)),Buffer.concat([X,J.subarray(0,4)])}getSrtpSsrcState(W){let Y=this.srtpSSRCStates[W];if(Y)return Y;return Y={ssrc:W,rolloverCounter:0,lastSequenceNumber:0},this.srtpSSRCStates[W]=Y,Y}getSrtcpSsrcState(W){let Y=this.srtcpSSRCStates[W];if(Y)return Y;return Y={srtcpIndex:0,ssrc:W},this.srtcpSSRCStates[W]=Y,Y}updateRolloverCount(W,Y){if(!Y.rolloverHasProcessed)Y.rolloverHasProcessed=!0;else if(W===0){if(Y.lastSequenceNumber>yV)Y.rolloverCounter++}else if(Y.lastSequenceNumber<yV&&W>qF-yV){if(Y.rolloverCounter>0)Y.rolloverCounter--}else if(W<yV&&Y.lastSequenceNumber>qF-yV)Y.rolloverCounter++;Y.lastSequenceNumber=W}generateSrtpAuthTag(W,Y){this.srtpSessionAuth=ZO("sha1",this.srtpSessionAuthTag);let G=Buffer.alloc(4);return G.writeUInt32BE(Y),this.srtpSessionAuth.update(W).update(G).digest().slice(0,10)}index(W){let Y=this.srtcpSSRCStates[W];if(!Y)return 0;return Y.srtcpIndex}setIndex(W,Y){let G=this.getSrtcpSsrcState(W);G.srtcpIndex=Y%2147483647}},yV=100,qF=65535,Zn=class extends Q2{constructor(W,Y,G){super(W,Y,G)}encryptRTCP(W){let Y=W.readUInt32BE(4),G=this.getSrtcpSsrcState(Y);if(G.srtcpIndex++,G.srtcpIndex>>Vn)G.srtcpIndex=0;return this.cipher.encryptRTCP(W,G.srtcpIndex)}decryptRTCP(W){return this.cipher.decryptRTCP(W)}},Vn=2147483647,H2=class{constructor(W){this.ContextCls=W}localContext;remoteContext;onData;start(W,Y,G,X,J){this.localContext=new this.ContextCls(W,Y,J),this.remoteContext=new this.ContextCls(G,X,J)}},Un=class extends H2{constructor(W){super(Zn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[Y]=this.remoteContext.decryptRTCP(W);return Y};encrypt(W){return this.localContext.encryptRTCP(W)}},Qn=class extends Q2{constructor(W,Y,G){super(W,Y,G)}encryptRtp(W,Y){let G=this.getSrtpSsrcState(Y.ssrc);return this.updateRolloverCount(Y.sequenceNumber,G),this.cipher.encryptRtp(Y,W,G.rolloverCounter)}decryptRtp(W){let Y=GK(W,this.rtpAuthTagLength),G=this.srtpSSRCStates[Y.ssrc],X=G?{...G}:{ssrc:Y.ssrc,rolloverCounter:0,lastSequenceNumber:0};this.updateRolloverCount(Y.sequenceNumber,X);let J=this.cipher.decryptRtp(W,X.rolloverCounter,Y);if(G)Object.assign(G,X);else this.srtpSSRCStates[Y.ssrc]=X;return J}get rtpAuthTagLength(){return this.profile===VU?16:10}},Hn=class extends H2{constructor(W){super(Qn);this.config=W,this.start(W.keys.localMasterKey,W.keys.localMasterSalt,W.keys.remoteMasterKey,W.keys.remoteMasterSalt,W.profile)}decrypt=(W)=>{let[Y]=this.remoteContext.decryptRtp(W);return Y};encrypt(W,Y){return this.localContext.encryptRtp(W,Y)}},bq0=class{constructor(W){this.props=W}sequenceNumber=zS();timestamp=CO();create(W){this.sequenceNumber=T9(this.sequenceNumber,1);let Y=this.props.between*this.props.clockRate/1000;this.timestamp=vX(this.timestamp,Y);let G=new s6({sequenceNumber:this.sequenceNumber,timestamp:Number(this.timestamp),payloadType:96,extension:!0,marker:!1,padding:!1});return new t6(G,W)}},u9=M1("werift-dtls : packages/dtls/src/flight/client/flight5.ts : log"),Nn=class extends GU{constructor(W,Y,G,X){super(W,Y,5,7);this.cipher=G,this.srtp=X}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,4);let Y=(()=>{switch(W.msg_type){case 2:return rS.deSerialize(W.fragment);case 11:return eN.deSerialize(W.fragment);case 12:return tS.deSerialize(W.fragment);case 13:return iS.deSerialize(W.fragment);case 14:return aS.deSerialize(W.fragment)}})();if(Y)pX[Y.msgType]({dtls:this.dtls,cipher:this.cipher,srtp:this.srtp})(Y)}async exec(){if(this.dtls.flight===5){u9(this.dtls.sessionId,"flight5 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=5;let W=this.dtls.requestedCertificateTypes.length>0;u9(this.dtls.sessionId,"send flight5",W);let Y=[W&&this.sendCertificate(),this.sendClientKeyExchange(),W&&this.sendCertificateVerify(),this.sendChangeCipherSpec(),this.sendFinished()].filter((G)=>G);this.dtls.lastMessage=Y,await this.transmit(Y)}sendCertificate(){let W=new eN([Buffer.from(this.cipher.localCert)]),Y=this.createPacket([W]);return Buffer.concat(Y.map((X)=>X.serialize()))}sendClientKeyExchange(){if(!this.cipher.localKeyPair)throw Error();let W=new nS(this.cipher.localKeyPair.publicKey),Y=this.createPacket([W]),G=Buffer.concat(Y.map((U)=>U.serialize())),X=this.cipher.localKeyPair,J=this.cipher.remoteKeyPair;if(!J.publicKey)throw Error("not exist");let Z=xS(J.publicKey,X.privateKey,X.curve);u9(this.dtls.sessionId,"extendedMasterSecret",this.dtls.options.extendedMasterSecret,this.dtls.remoteExtendedMasterSecret);let V=Buffer.concat(this.dtls.sortedHandshakeCache.map((U)=>U.serialize()));return this.cipher.masterSecret=this.dtls.options.extendedMasterSecret&&this.dtls.remoteExtendedMasterSecret?_S(Z,V):kS(Z,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize()),this.cipher.cipher=cS(this.cipher.cipherSuite),this.cipher.cipher.init(this.cipher.masterSecret,this.cipher.remoteRandom.serialize(),this.cipher.localRandom.serialize()),u9(this.dtls.sessionId,"cipher",this.cipher.cipher.summary),G}sendCertificateVerify(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((V)=>V.serialize())),Y=this.cipher.signatureData(W,"sha256"),G=(()=>{switch(this.cipher.signatureHashAlgorithm?.signature){case l4.ecdsa_3:return b$.ecdsa_secp256r1_sha256;case l4.rsa_1:return b$.rsa_pkcs1_sha256}})();if(!G)throw Error();u9(this.dtls.sessionId,"signatureScheme",this.cipher.signatureHashAlgorithm?.signature,G);let X=new oS(G,Y),J=this.createPacket([X]);return Buffer.concat(J.map((V)=>V.serialize()))}sendChangeCipherSpec(){let W=dS.createEmpty().serialize(),Y=YU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(Y.map((X)=>X.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),Y=this.cipher.verifyData(W),G=new $O(Y);this.dtls.epoch=1;let[X]=this.createPacket([G]);this.dtls.recordSequenceNumber=0;let J=this.cipher.encryptPacket(X).serialize();return u9(this.dtls.sessionId,"finished",this.cipher.cipher.summary),J}},pX={};pX[2]=({cipher:W,srtp:Y,dtls:G})=>(X)=>{if(u9(G.sessionId,"serverHello",X.cipherSuite),W.remoteRandom=TY.from(X.random),W.cipherSuite=X.cipherSuite,u9(G.sessionId,"selected cipherSuite",W.cipherSuite),X.extensions)X.extensions.forEach((J)=>{switch(J.type){case uX.type:{let Z=uX.fromData(J.data),V=sN.findMatchingSRTPProfile(Z.profiles,G.options.srtpProfiles||[]);if(u9(G.sessionId,"selected srtp profile",V),V==null)return;Y.srtpProfile=V}break;case qq.type:G.remoteExtendedMasterSecret=!0;break;case Aq.type:u9(G.sessionId,"RenegotiationIndication");break}})};pX[11]=({cipher:W,dtls:Y})=>(G)=>{u9(Y.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};pX[12]=({cipher:W,dtls:Y})=>(G)=>{if(!W.localRandom||!W.remoteRandom)throw Error();u9(Y.sessionId,"ServerKeyExchange",G),u9(Y.sessionId,"selected curve",G.namedCurve),W.remoteKeyPair={curve:G.namedCurve,publicKey:G.publicKey},W.localKeyPair=lS(G.namedCurve)};pX[13]=({dtls:W})=>(Y)=>{u9(W.sessionId,"certificate_request",Y),W.requestedCertificateTypes=Y.certificateTypes,W.requestedSignatureAlgorithms=Y.signatures};pX[14]=({dtls:W})=>(Y)=>{u9(W.sessionId,"server_hello_done",Y)};var N2=class W{constructor(Y,G){this.serverVersion=Y,this.cookie=G}msgType=3;messageSeq;static spec={serverVersion:WK,cookie:LY.types.buffer(LY.types.uint8)};static createEmpty(){return new W(void 0,void 0)}static deSerialize(Y){return new W(...Object.values(LY.decode(Y,W.spec)))}serialize(){let Y=LY.encode(this,W.spec).slice();return Buffer.from(Y)}get version(){return{major:255-this.serverVersion.major,minor:255-this.serverVersion.minor}}toFragment(){let Y=this.serialize();return new E5(this.msgType,Y.length,this.messageSeq,0,Y.length,Y)}},An=M1("werift-dtls : packages/dtls/src/context/dtls.ts : log"),AF=class{constructor(W,Y){this.options=W,this.sessionType=Y}version={major:254,minor:253};lastFlight=[];lastMessage=[];recordSequenceNumber=0;sequenceNumber=0;epoch=0;flight=0;handshakeCache={};cookie;requestedCertificateTypes=[];requestedSignatureAlgorithms=[];remoteExtendedMasterSecret=!1;get sessionId(){return this.cookie?this.cookie.toString("hex").slice(0,10):""}get sortedHandshakeCache(){return Object.entries(this.handshakeCache).sort(([W],[Y])=>Number(W)-Number(Y)).flatMap(([,{data:W}])=>W.sort((Y,G)=>Y.message_seq-G.message_seq))}checkHandshakesExist=(W)=>!W.find((Y)=>this.sortedHandshakeCache.find((G)=>G.msg_type===Y)==null);bufferHandshakeCache(W,Y,G){if(!this.handshakeCache[G])this.handshakeCache[G]={data:[],isLocal:Y,flight:G};let X=W.filter((J)=>{let Z=this.handshakeCache[G].data.find((V)=>V.msg_type===J.msg_type);if(Z)return An(this.sessionId,"exist",Z.summary,Y,G),!1;return!0});this.handshakeCache[G].data=[...this.handshakeCache[G].data,...X]}},In=class{constructor(W){this.socket=W}send=(W)=>{return this.socket.send(W)}},SO=class W{static type=10;static spec={type:l7.types.uint16be,data:l7.types.array(l7.types.uint16be,l7.types.uint16be,"bytes")};type=W.type;data=[];constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static fromData(Y){return new W({type:W.type,data:l7.decode(Y,W.spec.data)})}static deSerialize(Y){return new W(l7.decode(Y,W.spec))}serialize(){return Buffer.from(l7.encode(this,W.spec).slice())}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},xO=class W{static type=13;static spec={type:c7.types.uint16be,data:c7.types.array({hash:c7.types.uint8,signature:c7.types.uint8},c7.types.uint16be,"bytes")};type=W.type;data=[];constructor(Y={}){Object.assign(this,Y)}static createEmpty(){return new W}static deSerialize(Y){return new W(c7.decode(Y,W.spec))}serialize(){let Y=c7.encode(this,W.spec).slice();return Buffer.from(Y)}static fromData(Y){let G=Buffer.alloc(2);return G.writeUInt16BE(W.type),W.deSerialize(Buffer.concat([G,Y]))}get extension(){return{type:this.type,data:this.serialize().slice(2)}}},IF=class W{constructor(Y,G){this.level=Y,this.description=G}static spec={level:BY.types.uint8,description:BY.types.uint8};static deSerialize(Y){return new W(...Object.values(BY.decode(Y,W.spec)))}serialize(){let Y=BY.encode(this,W.spec).slice();return Buffer.from(Y)}},zF=M1("werift-dtls : packages/dtls/record/receive.ts : log"),UO=M1("werift-dtls : packages/dtls/record/receive.ts : err"),zn=(W)=>{let Y=0,G=[];while(W.length>Y){let X=W.readUInt16BE(Y+11);if(W.length<Y+(12+X))break;let J=mS.deSerialize(W.subarray(Y));G.push(J),Y+=13+X}return G},wn=(W,Y)=>(G)=>{switch(G.recordLayerHeader.contentType){case 20:return zF(W.sessionId,"change cipher spec"),[{type:20,data:void 0}];case 22:{let J=G.fragment;try{if(G.recordLayerHeader.epoch>0)zF(W.sessionId,"decrypt handshake"),J=Y.decryptPacket(G)}catch(Z){throw UO(W.sessionId,"decrypt failed",Z),Z}try{let Z=0,V=[];while(J.length>Z){let U=E5.deSerialize(J.subarray(Z));V.push({type:22,data:U}),Z+=U.fragment_length+12}return V}catch(Z){throw UO(W.sessionId,"decSerialize failed",Z,J),Z}}case 23:return[{type:23,data:Y.decryptPacket(G)}];case 21:{let J=IF.deSerialize(G.fragment);if(EO[J.description]==null){let Z=Y.decryptPacket(G);J=IF.deSerialize(Z)}if(UO(W.sessionId,"ContentType.alert",J,EO[J.description],"flight",W.flight,"lastFlight",W.lastFlight),J.level>1)throw Error("alert fatal error");return[{type:21,data:void 0}]}default:return[{type:21,data:void 0}]}},wF=M1("werift-dtls : packages/dtls/src/socket.ts : log"),jF=M1("werift-dtls : packages/dtls/src/socket.ts : err"),q2=class{constructor(W,Y){this.options=W,this.sessionType=Y,this.dtls=new AF(this.options,this.sessionType),this.cipher=new aN(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.transport=new In(this.options.transport),this.setupExtensions(),this.transport.socket.onData=this.udpOnMessage}onConnect=new p0;onData=new p0;onError=new p0;onClose=new p0;transport;cipher;dtls;srtp=new sN;connected=!1;extensions=[];onHandleHandshakes;bufferFragmentedHandshakes=[];renegotiation(){wF("renegotiation",this.sessionType),this.connected=!1,this.cipher=new aN(this.sessionType,this.options.cert,this.options.key,this.options.signatureHash),this.dtls=new AF(this.options,this.sessionType),this.srtp=new sN,this.extensions=[],this.bufferFragmentedHandshakes=[]}udpOnMessage=(W)=>{let Y=zn(W);for(let G of Y)try{let X=wn(this.dtls,this.cipher)(G);for(let J of X)switch(J.type){case 22:{let Z=J.data,V=this.handleFragmentHandshake([Z]),U=Object.values(V.reduce((Q,H)=>{if(!Q[H.msg_type])Q[H.msg_type]=[];return Q[H.msg_type].push(H),Q},{})).map((Q)=>E5.assemble(Q)).sort((Q,H)=>Q.msg_type-H.msg_type);this.onHandleHandshakes(U).catch((Q)=>{jF(this.dtls.sessionId,"onHandleHandshakes error",Q),this.onError.execute(Q)})}break;case 23:this.onData.execute(J.data);break;case 21:this.onClose.execute();break}}catch(X){jF(this.dtls.sessionId,"catch udpOnMessage error",X)}};setupExtensions(){if(wF(this.dtls.sessionId,"support srtpProfiles",this.options.srtpProfiles),this.options.srtpProfiles&&this.options.srtpProfiles.length>0){let W=uX.create(this.options.srtpProfiles,Buffer.from([0]));this.extensions.push(W.extension)}{let W=SO.createEmpty();W.data=BS,this.extensions.push(W.extension)}{let W=xO.createEmpty();W.data=$S,this.extensions.push(W.extension)}if(this.options.extendedMasterSecret)this.extensions.push({type:qq.type,data:Buffer.alloc(0)});{let W=Aq.createEmpty();this.extensions.push(W.extension)}}waitForReady=(W)=>new Promise(async(Y,G)=>{for(let X=0;X<10;X++)if(W()){Y();break}else await qn(100*X);G("waitForReady timeout")});handleFragmentHandshake(W){let Y=W.filter((G)=>{if(G.fragment_length!==G.length)return this.bufferFragmentedHandshakes.push(G),!1;return!0});if(this.bufferFragmentedHandshakes.length>1){let[G]=this.bufferFragmentedHandshakes.slice(-1);if(G.fragment_offset+G.fragment_length===G.length)Y=[...this.bufferFragmentedHandshakes,...Y],this.bufferFragmentedHandshakes=[]}return Y}send=async(W)=>{let Y=YU(this.dtls)([{type:23,fragment:W}],++this.dtls.recordSequenceNumber)[0];await this.transport.send(this.cipher.encryptPacket(Y).serialize())};close(){this.transport.socket.close()}extractSessionKeys(W,Y){let G=this.exportKeyingMaterial("EXTRACTOR-dtls_srtp",W*2+Y*2),{clientKey:X,serverKey:J,clientSalt:Z,serverSalt:V}=KY.decode(G,{clientKey:KY.types.buffer(W),serverKey:KY.types.buffer(W),clientSalt:KY.types.buffer(Y),serverSalt:KY.types.buffer(Y)});if(this.sessionType===p4.CLIENT)return{localKey:X,localSalt:Z,remoteKey:J,remoteSalt:V};else return{localKey:J,localSalt:V,remoteKey:X,remoteSalt:Z}}exportKeyingMaterial(W,Y){return nd(W,Y,this.cipher.masterSecret,this.cipher.localRandom.serialize(),this.cipher.remoteRandom.serialize(),this.sessionType===p4.CLIENT)}get remoteCertificate(){return this.cipher.remoteCertificate}},QO=M1("werift-dtls : packages/dtls/src/client.ts : log"),OF=class extends q2{constructor(W){super(W,p4.CLIENT);this.onHandleHandshakes=this.handleHandshakes,QO(this.dtls.sessionId,"start client")}async connect(){await new No(this.transport,this.dtls,this.cipher).exec(this.extensions)}flight5;handleHandshakes=async(W)=>{QO(this.dtls.sessionId,"handleHandshakes",W.map((Y)=>Y.msg_type));for(let Y of W)switch(Y.msg_type){case 3:{let G=N2.deSerialize(Y.fragment);await new Ao(this.transport,this.dtls).exec(G)}break;case 2:{if(this.connected)return;this.flight5=new Nn(this.transport,this.dtls,this.cipher,this.srtp),this.flight5.handleHandshake(Y)}break;case 11:case 12:case 13:await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(Y);break;case 14:{await this.waitForReady(()=>!!this.flight5),this.flight5?.handleHandshake(Y);let G=[11,12,this.options.certificateRequest&&13].filter((X)=>typeof X==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight5?.exec()}break;case 20:this.dtls.flight=7,this.connected=!0,this.onConnect.execute(),QO(this.dtls.sessionId,"dtls connected");break}}},f7=M1("werift-dtls : packages/dtls/flight/server/flight2.ts : log"),On=(W,Y,G,X)=>(J)=>{f7("dtls version",J.clientVersion),Y.flight=2,Y.recordSequenceNumber=0,Y.sequenceNumber=0,J.extensions.forEach((A)=>{switch(A.type){case SO.type:{let q=SO.fromData(A.data).data;f7(Y.sessionId,"curves",q);let z=q.filter((w)=>BS.includes(w))[0];G.namedCurve=z,f7(Y.sessionId,"curve selected",G.namedCurve)}break;case xO.type:{if(!G.signatureHashAlgorithm)throw Error("need to set certificate");let q=xO.fromData(A.data).data;f7(Y.sessionId,"hash,signature",q);let z=q.find((D)=>D.signature===G.signatureHashAlgorithm?.signature)?.signature,w=q.find((D)=>D.hash===G.signatureHashAlgorithm?.hash)?.hash;if(z==null||w==null)throw Error("invalid signatureHash")}break;case uX.type:{if(!Y.options?.srtpProfiles)return;if(Y.options.srtpProfiles.length===0)return;let q=uX.fromData(A.data);f7(Y.sessionId,"srtp profiles",q.profiles);let z=sN.findMatchingSRTPProfile(q.profiles,Y.options?.srtpProfiles);if(!z)throw Error();X.srtpProfile=z,f7(Y.sessionId,"srtp profile selected",X.srtpProfile)}break;case qq.type:Y.remoteExtendedMasterSecret=!0;break;case Aq.type:f7(Y.sessionId,"RenegotiationIndication",A.data);break;case 43:{let z=[...A.data.subarray(1)].map((w)=>w.toString(10));f7("dtls supported version",z)}break}}),G.localRandom=new TY,G.remoteRandom=TY.from(J.random);let Z=J.cipherSuites;f7(Y.sessionId,"cipher suites",Z);let V=(()=>{switch(G.signatureHashAlgorithm?.signature){case l4.ecdsa_3:return PO.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195;case l4.rsa_1:return PO.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199}})();if(V===void 0||!Z.includes(V))throw Error("dtls cipher suite negotiation failed");G.cipherSuite=V,f7(Y.sessionId,"selected cipherSuite",G.cipherSuite),G.localKeyPair=lS(G.namedCurve),Y.cookie||=jn(20);let U=new N2({major:254,minor:253},Y.cookie),Q=fS(Y)([U]),N=YU(Y)(Q.map((A)=>({type:22,fragment:A.serialize()})),++Y.recordSequenceNumber).map((A)=>A.serialize());for(let A of N)W.send(A)},KF=M1("werift-dtls : packages/dtls/flight/server/flight4.ts : log"),Kn=class extends GU{constructor(W,Y,G,X){super(W,Y,4,6);this.cipher=G,this.srtp=X}async exec(W,Y=!1){if(this.dtls.flight===4){KF(this.dtls.sessionId,"flight4 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=4,this.dtls.sequenceNumber=1,this.dtls.bufferHandshakeCache([W],!1,4);let G=[this.sendServerHello(),this.sendCertificate(),this.sendServerKeyExchange(),Y&&this.sendCertificateRequest(),this.sendServerHelloDone()].filter((X)=>X);this.dtls.lastMessage=G,await this.transmit(G)}sendServerHello(){let W=[];if(this.srtp.srtpProfile)W.push(uX.create([this.srtp.srtpProfile],Buffer.from([0])).extension);if(this.dtls.options.extendedMasterSecret)W.push({type:qq.type,data:Buffer.alloc(0)});let Y=Aq.createEmpty();W.push(Y.extension);let G=new rS(this.dtls.version,this.cipher.localRandom,Buffer.from([0]),this.cipher.cipherSuite,0,W),X=this.createPacket([G]);return Buffer.concat(X.map((J)=>J.serialize()))}sendCertificate(){let W=new eN([Buffer.from(this.cipher.localCert)]),Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}sendServerKeyExchange(){let W=this.cipher.generateKeySignature("sha256");if(!this.cipher.signatureHashAlgorithm)throw Error("not exist");let Y=new tS(ES.named_curve_3,this.cipher.namedCurve,this.cipher.localKeyPair.publicKey.length,this.cipher.localKeyPair.publicKey,this.cipher.signatureHashAlgorithm.hash,this.cipher.signatureHashAlgorithm.signature,W.length,W),G=this.createPacket([Y]);return Buffer.concat(G.map((X)=>X.serialize()))}sendCertificateRequest(){let W=new iS(cd,$S,[]);KF(this.dtls.sessionId,"sendCertificateRequest",W);let Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}sendServerHelloDone(){let W=new aS,Y=this.createPacket([W]);return Buffer.concat(Y.map((G)=>G.serialize()))}},fX=M1("werift-dtls : packages/dtls/flight/server/flight6.ts"),Dn=class extends GU{constructor(W,Y,G){super(W,Y,6);this.cipher=G}handleHandshake(W){this.dtls.bufferHandshakeCache([W],!1,5);let Y=(()=>{switch(W.msg_type){case 11:return eN.deSerialize(W.fragment);case 15:return oS.deSerialize(W.fragment);case 16:return nS.deSerialize(W.fragment);case 20:return $O.deSerialize(W.fragment)}})();if(Y){let G=UU[Y.msgType];if(!G)return;G({dtls:this.dtls,cipher:this.cipher})(Y)}}async exec(){if(this.dtls.flight===6){fX(this.dtls.sessionId,"flight6 twice"),this.send(this.dtls.lastMessage);return}this.dtls.flight=6;let W=[this.sendChangeCipherSpec(),this.sendFinished()];this.dtls.lastMessage=W,await this.transmit(W)}sendChangeCipherSpec(){let W=dS.createEmpty().serialize(),Y=YU(this.dtls)([{type:20,fragment:W}],++this.dtls.recordSequenceNumber);return Buffer.concat(Y.map((X)=>X.serialize()))}sendFinished(){let W=Buffer.concat(this.dtls.sortedHandshakeCache.map((Z)=>Z.serialize())),Y=this.cipher.verifyData(W),G=new $O(Y);this.dtls.epoch=1;let[X]=this.createPacket([G]);return this.dtls.recordSequenceNumber=0,this.cipher.encryptPacket(X).serialize()}},UU={};UU[16]=({cipher:W,dtls:Y})=>(G)=>{if(W.remoteKeyPair={curve:W.namedCurve,publicKey:G.publicKey},!W.remoteKeyPair.publicKey||!W.localKeyPair||!W.remoteRandom||!W.localRandom)throw Error("not exist");let X=xS(W.remoteKeyPair.publicKey,W.localKeyPair.privateKey,W.localKeyPair.curve);fX(Y.sessionId,"extendedMasterSecret",Y.options.extendedMasterSecret,Y.remoteExtendedMasterSecret);let J=Buffer.concat(Y.sortedHandshakeCache.map((Z)=>Z.serialize()));W.masterSecret=Y.options.extendedMasterSecret&&Y.remoteExtendedMasterSecret?_S(X,J):kS(X,W.remoteRandom.serialize(),W.localRandom.serialize()),W.cipher=cS(W.cipherSuite),W.cipher.init(W.masterSecret,W.localRandom.serialize(),W.remoteRandom.serialize()),fX(Y.sessionId,"setup cipher",W.cipher.summary)};UU[11]=({cipher:W,dtls:Y})=>(G)=>{fX(Y.sessionId,"handshake certificate",G),W.remoteCertificate=G.certificateList[0]};UU[15]=({cipher:W,dtls:Y})=>(G)=>{if(!W.remoteCertificate)throw Error("client certificate missing before certificate verify");fX(Y.sessionId,"certificate_verify",G.algorithm)};UU[20]=({dtls:W})=>(Y)=>{fX(W.sessionId,"finished",Y)};var FX=M1("werift-dtls : packages/dtls/src/server.ts : log"),Cn=class extends q2{constructor(W){super(W,p4.SERVER);this.onHandleHandshakes=this.handleHandshakes,FX(this.dtls.sessionId,"start server")}flight6;handleHandshakes=async(W)=>{FX(this.dtls.sessionId,"handleHandshakes",W.map((Y)=>Y.msg_type));for(let Y of W)switch(Y.msg_type){case 1:{if(this.connected)this.renegotiation();let G=bS.deSerialize(Y.fragment);if(G.cookie.length===0)FX(this.dtls.sessionId,"send flight2"),On(this.transport,this.dtls,this.cipher,this.srtp)(G);else if(this.dtls.cookie&&G.cookie.equals(this.dtls.cookie))FX(this.dtls.sessionId,"send flight4"),await new Kn(this.transport,this.dtls,this.cipher,this.srtp).exec(Y,this.options.certificateRequest);else FX("wrong state",{dtlsCookie:this.dtls.cookie?.toString("hex").slice(10),helloCookie:G.cookie.toString("hex").slice(10)})}break;case 11:case 15:case 16:{if(this.connected)return;this.flight6=new Dn(this.transport,this.dtls,this.cipher),this.flight6.handleHandshake(Y)}break;case 20:{await this.waitForReady(()=>!!this.flight6),this.flight6?.handleHandshake(Y);let G=[16,this.options.certificateRequest&&11,this.options.certificateRequest&&15].filter((X)=>typeof X==="number");await this.waitForReady(()=>this.dtls.checkHandshakesExist(G)),await this.flight6?.exec(),this.connected=!0,this.onConnect.execute(),FX(this.dtls.sessionId,"dtls connected")}break}}},XK=554869826,Tn=8,Rn=1398035790,n6=20,A2=24,I2=1,z2=2,Mn=6,Pn=50;var w2=((W)=>{return W[W.REQUEST=0]="REQUEST",W[W.INDICATION=16]="INDICATION",W[W.RESPONSE=256]="RESPONSE",W[W.ERROR=272]="ERROR",W})(w2||{}),j2=((W)=>{return W[W.BINDING=1]="BINDING",W[W.SHARED_SECRET=2]="SHARED_SECRET",W[W.ALLOCATE=3]="ALLOCATE",W[W.REFRESH=4]="REFRESH",W[W.SEND=6]="SEND",W[W.DATA=7]="DATA",W[W.CREATE_PERMISSION=8]="CREATE_PERMISSION",W[W.CHANNEL_BIND=9]="CHANNEL_BIND",W})(j2||{});function vV(W){return K2(W).toString("hex").substring(0,W)}function D2(){return K2(12)}var DF=class{queue=[];wait=new p0;put(W){if(this.queue.push(W),this.queue.length===1)this.wait.execute(W)}get(){let W=this.queue.shift();if(!W)return new Promise((Y)=>{this.wait.subscribe((G)=>{this.queue.shift(),Y(G)})});return W}},kO=(W)=>{let Y,G,X=new Promise((Z,V)=>{Y=Z,G=V});X.then(()=>{J.execute(void 0),J.complete()}).catch((Z)=>{J.execute(Z??Error()),J.complete()});let J=new p0;return W(Y,G,J).catch(()=>{}),{awaitable:X,resolve:Y,reject:G}};function kX(W){let[Y]=W,G=sV.default.isV4Format(Y)?I2:z2,X=Buffer.alloc(4);return X.writeUInt8(0,0),X.writeUInt8(G,1),X.writeUInt16BE(W[1],2),Buffer.concat([X,sV.default.toBuffer(Y)])}function Ln(W){if(W.length<4)throw Error("STUN error code is less than 4 bytes");let Y=W.readUInt8(2),G=W.readUInt8(3),X=W.slice(4).toString("utf8");return[Y*100+G,X]}function _X(W){if(W.length<4)throw Error("STUN address length is less than 4 bytes");let Y=W.readUInt8(1),G=W.readUInt16BE(2),X=W.slice(4);switch(Y){case I2:if(X.length!=4)throw Error("STUN address has invalid length for IPv4");return[sV.default.toString(X),G];case z2:if(X.length!=16)throw Error("STUN address has invalid length for IPv6");return[sV.default.toString(X),G];default:throw Error("STUN address has unknown protocol")}}var JK=Buffer.alloc(6);JK.writeUInt16BE(XK>>16,0);JK.writeUInt32BE(XK,2);function C2(W,Y){let G=[...JK,...Y],X=W.slice(0,2);for(let J=2;J<W.length;J++){let Z=W[J]^G[J-2],V=Buffer.alloc(1);V.writeUIntBE(Z,0,1),X=Buffer.concat([X,V])}return X}function gN(W,Y){return _X(C2(W,Y))}function Bn(W){let Y=Buffer.alloc(4);Y.writeUInt16BE(0,0),Y.writeUInt8(Math.floor(W[0]/100),2),Y.writeUInt8(W[0]%100,3);let G=Buffer.from(W[1],"utf8");return Buffer.concat([Y,G])}function uN(W,Y){return C2(kX(W),Y)}var gV=(W)=>{let Y=Buffer.alloc(4);return Y.writeUInt32BE(W,0),Y},uV=(W)=>W.readUInt32BE(0),En=(W)=>{let Y=Buffer.alloc(4);return Y.writeUInt16BE(W,0),Y},$n=(W)=>W.readUInt16BE(0),CF=(W)=>{return new nj(W.toString()).toBuffer()},TF=(W)=>{let Y=new nj(W);return BigInt(Y.toString())},HO=(W)=>Buffer.from(W,"utf8"),NO=(W)=>W.toString("utf8"),qO=(W)=>W,AO=(W)=>W,Fn=(W)=>Buffer.from([]),Sn=(W)=>null,T2=[[1,"MAPPED-ADDRESS",kX,_X],[3,"CHANGE-REQUEST",gV,uV],[4,"SOURCE-ADDRESS",kX,_X],[5,"CHANGED-ADDRESS",kX,_X],[6,"USERNAME",HO,NO],[8,"MESSAGE-INTEGRITY",qO,AO],[9,"ERROR-CODE",Bn,Ln],[12,"CHANNEL-NUMBER",En,$n],[13,"LIFETIME",gV,uV],[18,"XOR-PEER-ADDRESS",uN,gN],[19,"DATA",qO,AO],[20,"REALM",HO,NO],[21,"NONCE",qO,AO],[22,"XOR-RELAYED-ADDRESS",uN,gN],[25,"REQUESTED-TRANSPORT",gV,uV],[32,"XOR-MAPPED-ADDRESS",uN,gN],[36,"PRIORITY",gV,uV],[37,"USE-CANDIDATE",Fn,Sn],[32802,"SOFTWARE",HO,NO],[32808,"FINGERPRINT",gV,uV],[32809,"ICE-CONTROLLED",CF,TF],[32810,"ICE-CONTROLLING",CF,TF],[32811,"RESPONSE-ORIGIN",kX,_X],[32812,"OTHER-ADDRESS",kX,_X]],R2=class{constructor(W=[]){this.attributes=W}getAttributes(){return this.attributes}setAttribute(W,Y){let G=this.attributes.find((X)=>X[0]===W);if(G)G[1]=Y;else this.attributes.push([W,Y]);return this}getAttributeValue(W){let Y=this.attributes.find((G)=>G[0]===W);if(!Y)return;return Y[1]}get attributesKeys(){return this.attributes.map((W)=>W[0])}clear(){this.attributes=[]}},RF=T2.reduce((W,Y)=>{return W[Y[0]]=Y,W},{}),xn=T2.reduce((W,Y)=>{return W[Y[1]]=Y,W},{});function ZK(W,Y){if(W.length<n6)return;let G=W.readUint16BE(2);if(W.length!==n6+G)return;let X=W.readUint16BE(0),J=Buffer.from(W.slice(n6-12,n6)),Z=new R2;for(let U=n6;U<=W.length-4;){let Q=W.readUInt16BE(U),H=W.readUInt16BE(U+2),N=W.slice(U+4,U+4+H),A=4*Math.floor((H+3)/4)-H;if(Object.keys(RF).includes(Q.toString())){let[,z,,w]=RF[Q];if(w.name===gN.name)Z.setAttribute(z,w(N,J));else Z.setAttribute(z,w(N));if(z==="FINGERPRINT"){let D=M2(W.slice(0,U));if(Z.getAttributeValue("FINGERPRINT")!==D)return}else if(z==="MESSAGE-INTEGRITY"){if(Y){let D=kn(W.slice(0,U),Y),T=Z.getAttributeValue("MESSAGE-INTEGRITY");if(!D.equals(T))return}}}U+=4+H+A}let V=Z.getAttributes();return Z.clear(),new p7(X&16111,X&272,J,V)}var p7=class extends R2{constructor(W,Y,G=D2(),X=[]){super(X);this.messageMethod=W,this.messageClass=Y,this.transactionId=G}toJSON(){return this.json}get json(){return{messageMethod:j2[this.messageMethod],messageClass:w2[this.messageClass],attributes:this.attributes}}get transactionIdHex(){return this.transactionId.toString("hex")}get bytes(){let W=Buffer.from([]);for(let G of this.attributesKeys){let X=this.getAttributeValue(G),[J,,Z]=xn[G],V=Z.name===uN.name?Z(X,this.transactionId):Z(X),U=V.length,Q=4*Math.floor((U+3)/4)-U,H=Buffer.alloc(4);H.writeUInt16BE(J,0),H.writeUInt16BE(U,2),W=Buffer.concat([W,H,V,Buffer.alloc(Q,0)])}let Y=Buffer.alloc(8);return Y.writeUInt16BE(this.messageMethod|this.messageClass,0),Y.writeUInt16BE(W.length,2),Y.writeUInt32BE(XK,4),Buffer.concat([Y,this.transactionId,W])}addMessageIntegrity(W){return this.setAttribute("MESSAGE-INTEGRITY",this.messageIntegrity(W)),this}messageIntegrity(W){let Y=VK(this.bytes,this.bytes.length-n6+A2);return Buffer.from(O2("sha1",W).update(Y).digest("hex"),"hex")}addFingerprint(){this.setAttribute("FINGERPRINT",M2(this.bytes))}},VK=(W,Y)=>{let G=Buffer.alloc(W.length);return W.copy(G,0,0,2),G.writeUInt16BE(Y,2),W.copy(G,4,4),G};function M2(W){let Y=VK(W,W.length-n6+Tn);return(Fd(Y)^Rn)>>>0}function kn(W,Y){let G=VK(W,W.length-n6+A2);return Buffer.from(O2("sha1",Y).update(G).digest("hex"),"hex")}function MF(W){let Y=W%4;if(Y===0)return 0;else return 4-Y}var P2=class extends Error{response;addr},L2=class extends P2{constructor(W,Y){super();this.response=W,this.addr=Y}get str(){let W="STUN transaction failed",Y=this.response.getAttributeValue("ERROR-CODE");if(Y){let[G,X]=Y;W+=` (${G} - ${X})`}return W}},_n=class extends P2{get str(){return"STUN transaction timed out"}},IO=M1("werift-ice:packages/ice/src/stun/transaction.ts"),UK=class{constructor(W,Y,G,X){this.request=W,this.addr=Y,this.protocol=G,this.retransmissions=X,this.triesMax=1+(this.retransmissions?this.retransmissions:Mn)}timeoutDelay=Pn;ended=!1;tries=0;triesMax;onResponse=new p0;responseReceived=(W,Y)=>{if(this.onResponse.length>0)if(W.messageClass===256)this.onResponse.execute(W,Y),this.onResponse.complete();else this.onResponse.error(new L2(W,Y))};run=async()=>{try{return this.retry().catch((Y)=>{IO("retry failed",Y)}),await this.onResponse.asPromise()}catch(W){throw W}finally{this.cancel()}};retry=async()=>{while(this.tries<this.triesMax&&!this.ended){if(this.protocol.sendStun(this.request,this.addr).catch((W)=>{IO("send stun failed",W)}),await new Promise((W)=>setTimeout(W,this.timeoutDelay)),this.ended)break;this.timeoutDelay*=2,this.tries++}if(this.tries>=this.triesMax)IO(`retry failed times:${this.tries} maxLimit:${this.triesMax}`),this.onResponse.error(new _n)};cancel(){this.ended=!0}},PF=M1("werift-ice : packages/ice/src/stun/protocol.ts"),LF=class W{static type="stun";type=W.type;transport;transactions={};get transactionsKeys(){return Object.keys(this.transactions)}localCandidate;sentMessage;localIp;onRequestReceived=new p0;onDataReceived=new p0;constructor(){}connectionMade=async(Y,G,X)=>{if(Y)this.transport=await MO.init("udp4",{portRange:G,interfaceAddresses:X});else this.transport=await MO.init("udp6",{portRange:G,interfaceAddresses:X});this.transport.onData=(J,Z)=>{this.datagramReceived(J,Z)}};datagramReceived(Y,G){try{let X=ZK(Y);if(!X){if(this.localCandidate)this.onDataReceived.execute(Y);return}if((X.messageClass===256||X.messageClass===272)&&this.transactionsKeys.includes(X.transactionIdHex))this.transactions[X.transactionIdHex].responseReceived(X,G);else if(X.messageClass===0)this.onRequestReceived.execute(X,G,Y)}catch(X){PF("datagramReceived error",X)}}getExtraInfo(){let{address:Y,port:G}=this.transport.address;return[Y,G]}async sendStun(Y,G){if(this.transport.closed)return;let X=Y.bytes;await this.transport.send(X,G).catch(()=>{PF("sendStun failed",G,Y)})}async sendData(Y,G){if(this.transport.closed)return;await this.transport.send(Y,G)}async request(Y,G,X,J){if(this.transactionsKeys.includes(Y.transactionIdHex))throw Error("already request ed");if(X)Y.addMessageIntegrity(X),Y.addFingerprint();let Z=new UK(Y,G,this,J);this.transactions[Y.transactionIdHex]=Z;try{return await Z.run()}catch(V){throw V}finally{delete this.transactions[Y.transactionIdHex]}}async close(){Object.values(this.transactions).forEach((Y)=>{Y.cancel()}),await this.transport.close(),this.onRequestReceived.complete(),this.onDataReceived.complete()}},a9=M1("werift-ice:packages/ice/src/turn/protocol.ts"),gn=500,un=600,hn=285212672,bn=class W{constructor(Y){this.turn=Y,Y.onData.subscribe((G,X)=>{this.handleStunMessage(G,X)}).disposer(this.disposer)}static type="turn";type=W.type;localCandidate;disposer=new yd;onRequestReceived=new p0;onDataReceived=new p0;handleStunMessage=(Y,G)=>{try{let X=ZK(Y);if(!X){this.onDataReceived.execute(Y);return}if(X.messageClass===256||X.messageClass===272){let J=this.turn.transactions[X.transactionIdHex];if(J)J.responseReceived(X,G)}else if(X.messageClass===0)this.onRequestReceived.execute(X,G,Y)}catch(X){a9("datagramReceived error",X)}};async request(Y,G,X){if(this.turn.transactions[Y.transactionIdHex])throw Error("exist");if(X)Y.addMessageIntegrity(X),Y.addFingerprint();let J=new UK(Y,G,this);this.turn.transactions[Y.transactionIdHex]=J;try{return await J.run()}catch(Z){throw Z}finally{delete this.turn.transactions[Y.transactionIdHex]}}async connectionMade(){}async sendData(Y,G){await this.turn.sendData(Y,G)}async sendStun(Y,G){await this.turn.sendData(Y.bytes,G)}async close(){return this.disposer.dispose(),this.turn.close()}},mn=class W{constructor(Y,G,X,J,Z,V={}){this.server=Y,this.username=G,this.password=X,this.lifetime=J,this.transport=Z,this.options=V,this.channelRefreshTime=this.options.channelRefreshTime??gn}static type="turn";type=W.type;onData=new p0;onRequestReceived=new p0;onDataReceived=new p0;integrityKey;nonce;realm;relayedAddress;mappedAddress;localCandidate;transactions={};refreshHandle;channelNumber=16384;channelByAddr={};addrByChannel={};channelRefreshTime;channelBinding;channelRefreshAt=0;tcpBuffer=Buffer.alloc(0);permissionByAddr={};creatingPermission=Promise.resolve();async connectionMade(){this.transport.onData=(J,Z)=>{this.dataReceived(J,Z)};let Y=new p7(3,0);Y.setAttribute("LIFETIME",this.lifetime).setAttribute("REQUESTED-TRANSPORT",hn);let[G]=await this.requestWithRetry(Y,this.server).catch((J)=>{throw a9("connect error",J),J});this.relayedAddress=G.getAttributeValue("XOR-RELAYED-ADDRESS"),this.mappedAddress=G.getAttributeValue("XOR-MAPPED-ADDRESS");let X=G.getAttributeValue("LIFETIME");a9("connect",this.relayedAddress,this.mappedAddress,{exp:X}),this.refresh(X)}handleChannelData(Y){let[G,X]=s1.Unpack("!HH",Y.slice(0,4)),J=this.addrByChannel[G];if(J){let Z=Y.subarray(4,4+X);this.onData.execute(Z,J)}}handleSTUNMessage(Y,G){try{let X=ZK(Y);if(!X)throw Error("not stun message");if(X.messageClass===256||X.messageClass===272){let J=this.transactions[X.transactionIdHex];if(J)J.responseReceived(X,G)}else if(X.messageClass===0)this.onData.execute(Y,G);if(X.getAttributeValue("DATA")){let J=X.getAttributeValue("DATA");this.onData.execute(J,G)}}catch(X){a9("parse error",Y.toString())}}dataReceived(Y,G){let X=(J,Z)=>{if(J.length>=4&&EF(J))this.handleChannelData(J);else this.handleSTUNMessage(J,Z)};if(this.transport.type==="tcp"){this.tcpBuffer=Buffer.concat([this.tcpBuffer,Y]);while(this.tcpBuffer.length>=4){let[,J]=s9(this.tcpBuffer.subarray(0,4),[2,2]);J+=MF(J);let Z=EF(this.tcpBuffer)?4+J:20+J;if(this.tcpBuffer.length<Z)break;X(this.tcpBuffer.subarray(0,Z),G),this.tcpBuffer=this.tcpBuffer.subarray(Z)}}else X(Y,G)}async send(Y,G){if(this.transport.closed)return;if(this.transport.type==="tcp"){let X=MF(Y.length);await this.transport.send(X>0?Buffer.concat([Y,Buffer.alloc(X)]):Y,G)}else await this.transport.send(Y,G)}async createPermission(Y){let G=new p7(8,0);G.setAttribute("XOR-PEER-ADDRESS",Y).setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce),await this.request(G,this.server).catch((X)=>{throw X})}refresh=(Y)=>{this.refreshHandle=kO(async(G,X,J)=>{let Z=!0;J.once(()=>{Z=!1});while(Z){let V=0.8333333333333334*Y*1000;a9("refresh delay",V,{exp:Y}),await vn(V);let U=new p7(4,0);U.setAttribute("LIFETIME",Y);try{let[Q]=await this.requestWithRetry(U,this.server);Y=Q.getAttributeValue("LIFETIME"),a9("refresh",{exp:Y})}catch(Q){a9("refresh error",Q)}}})};async request(Y,G){if(this.transactions[Y.transactionIdHex])throw Error("exist");if(this.integrityKey)Y.setAttribute("USERNAME",this.username).setAttribute("REALM",this.realm).setAttribute("NONCE",this.nonce).addMessageIntegrity(this.integrityKey).addFingerprint();let X=new UK(Y,G,this);this.transactions[Y.transactionIdHex]=X;try{return await X.run()}catch(J){throw J}finally{delete this.transactions[Y.transactionIdHex]}}async requestWithRetry(Y,G){let X,J;try{[X,J]=await this.request(Y,G)}catch(Z){if(Z instanceof L2==!1)throw a9("requestWithRetry error",Z),Z;this.server=Z.addr;let[V]=Z.response.getAttributeValue("ERROR-CODE"),U=Z.response.getAttributeValue("NONCE"),Q=Z.response.getAttributeValue("REALM");if((V===401&&Q||V===438&&this.realm)&&U){if(a9("retry with nonce",V),this.nonce=U,V===401)this.realm=Q;this.integrityKey=cn(this.username,this.realm,this.password),Y.transactionId=D2(),[X,J]=await this.request(Y,this.server)}else throw Z}return[X,J]}async sendData(Y,G){let X=await this.getChannel(G).catch((Z)=>{return Error("channelBind error")});if(X instanceof Error){await this.getPermission(G);let Z=new p7(6,16).setAttribute("DATA",Y).setAttribute("XOR-PEER-ADDRESS",G);await this.sendStun(Z,this.server);return}let J=s1.Pack("!HH",[X.number,Y.length]);await this.send(Buffer.concat([Buffer.from(J),Y]),this.server)}async getPermission(Y){if(await this.creatingPermission,!this.permissionByAddr[Y.join(":")])this.creatingPermission=this.createPermission(Y),this.permissionByAddr[Y.join(":")]=!0,await this.creatingPermission.catch((X)=>{throw a9("createPermission error",X),X})}async getChannel(Y){if(this.channelBinding)await this.channelBinding;let G=this.channelByAddr[Y.join(":")];if(!G)this.channelByAddr[Y.join(":")]={number:this.channelNumber++,address:Y},G=this.channelByAddr[Y.join(":")],this.addrByChannel[G.number]=Y,this.channelBinding=this.channelBind(G.number,Y),await this.channelBinding.catch((X)=>{throw a9("channelBind error",X),X}),this.channelRefreshAt=lV(Date.now()/1000)+this.channelRefreshTime,this.channelBinding=void 0,a9("channelBind",G);else if(this.channelRefreshAt<lV(Date.now()/1000))this.channelBinding=this.channelBind(G.number,Y),this.channelRefreshAt=lV(Date.now()/1000)+this.channelRefreshTime,await this.channelBinding.catch((X)=>{throw a9("channelBind error",X),X}),this.channelBinding=void 0,a9("channelBind refresh",G);return G}async channelBind(Y,G){let X=new p7(9,0);X.setAttribute("CHANNEL-NUMBER",Y).setAttribute("XOR-PEER-ADDRESS",G);let[J]=await this.requestWithRetry(X,this.server);if(J.messageMethod!==9)throw Error("should be CHANNEL_BIND")}async sendStun(Y,G){await this.send(Y.bytes,G)}async close(){this.refreshHandle?.resolve?.(),await this.transport.close()}};async function fn({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V}={}){X??=un,V??="udp";let U=V==="udp"?await MO.init("udp4",{portRange:J,interfaceAddresses:Z}):await ud.init(W),Q=new mn(W,Y,G,X,U);return await Q.connectionMade(),Q}async function BF({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V}={}){let U=await fn({address:W,username:Y,password:G},{lifetime:X,portRange:J,interfaceAddresses:Z,transport:V});return new bn(U)}function cn(W,Y,G){return yn("md5").update(Buffer.from([W,Y,G].join(":"))).digest()}function EF(W){return(W[0]&192)==64}var DY=class W{constructor(Y,G,X,J,Z,V,U,Q,H,N,A,q){this.foundation=Y,this.component=G,this.transport=X,this.priority=J,this.host=Z,this.port=V,this.type=U,this.relatedAddress=Q,this.relatedPort=H,this.tcptype=N,this.generation=A,this.ufrag=q}static fromSdp(Y){let G=Y.split(" ");if(G.length<8)throw Error("SDP does not have enough properties");let X={foundation:G[0],component:Number(G[1]),transport:G[2],priority:Number(G[3]),host:G[4],port:Number(G[5]),type:G[7]};for(let A=8,q=G.length-1;A<q;A+=2)if(G[A]==="raddr")X.related_address=G[A+1];else if(G[A]==="rport")X.related_port=Number(G[A+1]);else if(G[A]==="tcptype")X.tcptype=G[A+1];else if(G[A]==="generation")X.generation=Number(G[A+1]);else if(G[A]==="ufrag")X.ufrag=G[A+1];let{foundation:J,component:Z,transport:V,priority:U,host:Q,port:H,type:N}=X;return new W(J,Z,V,U,Q,H,N,X.related_address,X.related_port,X.tcptype,X.generation,X.ufrag)}canPairWith(Y){let G=$F(this.host),X=$F(Y.host);return this.component===Y.component&&this.transport.toLowerCase()===Y.transport.toLowerCase()&&G===X}toSdp(){let Y=`${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;if(this.relatedAddress)Y+=` raddr ${this.relatedAddress}`;if(this.relatedPort!=null)Y+=` rport ${this.relatedPort}`;if(this.tcptype)Y+=` tcptype ${this.tcptype}`;if(this.generation!=null)Y+=` generation ${this.generation}`;if(this.ufrag!=null)Y+=` ufrag ${this.ufrag}`;return Y}};function _O(W,Y,G){let X=`${W}|${Y}|${G}`;return pn("md5").update(X,"ascii").digest("hex").slice(7)}function hN(W,Y=65535){let X=0;if(W==="host")X=126;else if(W==="prflx")X=110;else if(W==="srflx")X=100;else X=0;return 16777216*X+256*Y+255}var dn=class{cache=new Map;mdnsInstance=B2.default();constructor(){this.mdnsInstance.setMaxListeners(50)}lookup(W){return new Promise((Y,G)=>{let X=()=>{this.mdnsInstance.removeListener("response",Z),clearTimeout(J)},J=setTimeout(()=>{X(),G(Error("No mDNS response"))},1e4),Z=(V)=>{let U=V.answers?.[0];if(U?.type!=="A")return;if(U.name!==W)return;X(),Y(U.data)};this.mdnsInstance.on("response",Z),this.mdnsInstance.query(W,"A")})}close(){this.mdnsInstance.destroy()}},nn=M1("werift-ice : packages/ice/src/ice.ts : log"),SF=class{constructor(W,Y,G){this.protocol=W,this.remoteCandidate=Y,this.iceControlling=G}id=on().toString();handle;nominated=!1;remoteNominated=!1;_state=0;get state(){return this._state}packetsSent=0;packetsReceived=0;bytesSent=0;bytesReceived=0;rtt;totalRoundTripTime=0;roundTripTimeMeasurements=0;toJSON(){return this.json}get json(){return{protocol:this.protocol.type,localCandidate:this.localCandidate.toSdp(),remoteCandidate:this.remoteCandidate.toSdp()}}updateState(W){this._state=W}get localCandidate(){if(!this.protocol.localCandidate)throw Error("localCandidate not exist");return this.protocol.localCandidate}get remoteAddr(){return[this.remoteCandidate.host,this.remoteCandidate.port]}get component(){return this.localCandidate.component}get priority(){return vO(this.localCandidate,this.remoteCandidate,this.iceControlling)}get foundation(){return this.localCandidate.foundation}},xF=1,$N=2,rn=5,kF=6;var an={useIpv4:!0,useIpv6:!0};function _F(W){if(!["host","relay","srflx"].includes(W.type))throw Error(`Unexpected candidate type "${W.type}"`);return W}function sn(W,Y){return W.sort((G,X)=>vO(G.localCandidate,G.remoteCandidate,Y)-vO(X.localCandidate,X.remoteCandidate,Y)).reverse()}function vO(W,Y,G){let X=G&&W.priority||Y.priority,J=G&&Y.priority||W.priority;return 1*Math.min(X,J)+2*Math.max(X,J)+(X>J?1:0)}async function tn(W,Y){let G=new p7(1,0);try{let[X]=await W.request(G,Y),J=W.localCandidate;if(!J)throw Error("not exist");return new DY(_O("srflx","udp",J.host),J.component,J.transport,hN("srflx"),X.getAttributeValue("XOR-MAPPED-ADDRESS")[0],X.getAttributeValue("XOR-MAPPED-ADDRESS")[1],"srflx",J.host,J.port)}catch(X){nn("error serverReflexiveCandidate",X)}}function yF(W){if(W&&Number.isNaN(W[1]))return[W[0],443];return W}var en=M1("werift-ice : packages/ice/src/utils.ts");function Wi(W){return iN(W.family)===4&&W.address?.startsWith("169.254.")||iN(W.family)===6&&W.address?.startsWith("fe80::")}function vF(W,{useLinkLocalAddress:Y}={}){let G=["ipsec","tun","utun","tap"],X=["vmnet","veth"],J=E2.networkInterfaces();en(J);let Z=Object.keys(J).map((V)=>{for(let Q of[...G,...X])if(V.startsWith(Q))return{nic:V,addresses:[]};let U=J[V].filter((Q)=>iN(Q.family)===W&&!$2.default.isLoopback(Q.address)&&(Y?!0:!Wi(Q)));return{nic:V,addresses:U.map((Q)=>Q.address)}}).filter((V)=>!!V);return Z.sort((V,U)=>V.nic.localeCompare(U.nic)),Object.values(Z).flatMap((V)=>V.addresses)}function Yi(W,Y,G={}){let X=[];if(W)X.push(...vF(4,G));if(Y)X.push(...vF(6,G));return X}var W8=M1("werift-ice : packages/ice/src/ice.ts : log"),Gi=class{constructor(W,Y){this._iceControlling=W,this.options={...an,...Y};let{stunServer:G,turnServer:X}=this.options;this.stunServer=yF(G)??["stun.l.google.com",19302],this.turnServer=yF(X),this.restart(),W8("new Connection",this.options)}localUsername=vV(4);localPassword=vV(22);remoteIsLite=!1;remotePassword="";remoteUsername="";checkList=[];localCandidates=[];stunServer;turnServer;options;remoteCandidatesEnd=!1;localCandidatesEnd=!1;generation=-1;userHistory={};tieBreaker=BigInt(new PN(ln(64)).toString());state="new";lookup;_remoteCandidates=[];nominated;nominating=!1;checkListDone=!1;checkListState=new DF;earlyChecks=[];earlyChecksDone=!1;localCandidatesStart=!1;protocols=[];queryConsentHandle;onData=new p0;stateChanged=new p0;onIceCandidate=new p0;get iceControlling(){return this._iceControlling}set iceControlling(W){if(this.generation>0||this.nominated)return;this._iceControlling=W;for(let Y of this.checkList)Y.iceControlling=W}async restart(){if(this.generation++,this.localUsername=vV(4),this.localPassword=vV(22),this.options.localPasswordPrefix)this.localPassword=this.options.localPasswordPrefix+this.localPassword.slice(this.options.localPasswordPrefix.length);this.userHistory[this.localUsername]=this.localPassword,this.remoteUsername="",this.remotePassword="",this.localCandidates=[],this._remoteCandidates=[],this.remoteCandidatesEnd=!1,this.localCandidatesEnd=!1,this.state="new",this.lookup?.close?.(),this.lookup=void 0,this.nominated=void 0,this.nominating=!1,this.checkList=[],this.checkListDone=!1,this.checkListState=new DF,this.earlyChecks=[],this.earlyChecksDone=!1,this.localCandidatesStart=!1;for(let W of this.protocols)if(W.localCandidate)W.localCandidate.generation=this.generation,W.localCandidate.ufrag=this.localUsername;this.queryConsentHandle?.resolve?.(),this.queryConsentHandle=void 0}resetNominatedPair(){W8("resetNominatedPair"),this.nominated=void 0,this.nominating=!1}setRemoteParams({iceLite:W,usernameFragment:Y,password:G}){W8("setRemoteParams",{iceLite:W,usernameFragment:Y,password:G}),this.remoteIsLite=W,this.remoteUsername=Y,this.remotePassword=G}async gatherCandidates(){if(!this.localCandidatesStart){this.localCandidatesStart=!0;let W=Yi(this.options.useIpv4,this.options.useIpv6,{useLinkLocalAddress:this.options.useLinkLocalAddress}),{interfaceAddresses:Y}=this.options;if(Y){let X=W.filter((J)=>Object.values(Y).includes(J));if(X.length)W=X}if(this.options.additionalHostAddresses)W=Array.from(new Set([...this.options.additionalHostAddresses,...W]));let G=this.getCandidatePromises(W,5);await Promise.allSettled(G),this.localCandidatesEnd=!0}this.setState("completed")}appendLocalCandidate(W){this.localCandidates.push(W),this.onIceCandidate.execute(W)}ensureProtocol(W){W.onRequestReceived.subscribe((Y,G,X)=>{if(Y.messageMethod!==1){this.respondError(Y,G,W,[400,"Bad Request"]);return}let J=Y.getAttributeValue("USERNAME"),{remoteUsername:Z}=gF(J),V=this.userHistory[Z]??this.localPassword,{iceControlling:U}=this;if(U&&Y.attributesKeys.includes("ICE-CONTROLLING"))if(this.tieBreaker>=Y.getAttributeValue("ICE-CONTROLLING")){this.respondError(Y,G,W,[487,"Role Conflict"]);return}else this.switchRole(!1);else if(!U&&Y.attributesKeys.includes("ICE-CONTROLLED"))if(this.tieBreaker<Y.getAttributeValue("ICE-CONTROLLED"))this.respondError(Y,G,W,[487,"Role Conflict"]);else{this.switchRole(!0);return}if(this.options.filterStunResponse&&!this.options.filterStunResponse(Y,G,W))return;let Q=new p7(1,256,Y.transactionId);if(Q.setAttribute("XOR-MAPPED-ADDRESS",G).addMessageIntegrity(Buffer.from(V,"utf8")).addFingerprint(),W.sendStun(Q,G).catch((H)=>{W8("sendStun error",H)}),this.checkList.length===0&&!this.earlyChecksDone)this.earlyChecks.push([Y,G,W]);else this.checkIncoming(Y,G,W)}),W.onDataReceived.subscribe((Y)=>{try{let G=this.nominated;if(G&&G.protocol===W)G.packetsReceived++,G.bytesReceived+=Y.length;this.onData.execute(Y)}catch(G){W8("dataReceived",G)}})}getCandidatePromises(W,Y=5){let G=[];W=W.filter((Q)=>{if(this.protocols.find((H)=>H.localIp===Q))return!1;return!0});let X=W.map(async(Q)=>{let H=new LF;this.ensureProtocol(H);try{await H.connectionMade(FF(Q),this.options.portRange,this.options.interfaceAddresses),H.localIp=Q,this.protocols.push(H),W8("protocol",H.localIp);let N=[Q,H.getExtraInfo()[1]];return H.localCandidate=new DY(_O("host","udp",N[0]),1,"udp",hN("host"),N[0],N[1],"host",void 0,void 0,void 0,this.generation,this.localUsername),this.pairLocalProtocol(H),this.appendLocalCandidate(H.localCandidate),H}catch(N){W8("error protocol STUN",N)}});G.push(...X.map((Q)=>Q.then((H)=>H?.localCandidate)));let{stunServer:J,turnServer:Z}=this;if(J){let Q=X.map(async(H)=>{let N=await H;if(!N)return;return new Promise(async(q,z)=>{let w=setTimeout(z,Y*1000);if(N.localCandidate?.host&&FF(N.localCandidate?.host)){let D=await tn(N,J).catch((T)=>{W8("error",T)});if(D)this.appendLocalCandidate(D);clearTimeout(w),q(D)}else clearTimeout(w),q()}).catch((q)=>{W8("query STUN server",q)})});G.push(...Q)}let{turnUsername:V,turnPassword:U}=this.options;if(Z&&V&&U){let Q=(async()=>{let H=await BF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:this.options.turnTransport==="tcp"?"tcp":"udp"}).catch(async(q)=>{if(this.options.turnTransport!=="tcp")return await BF({address:Z,username:V,password:U},{portRange:this.options.portRange,interfaceAddresses:this.options.interfaceAddresses,transport:"tcp"});else throw q});this.ensureProtocol(H),this.protocols.push(H);let N=H.turn.relayedAddress,A=H.turn.mappedAddress;return W8("turn candidateAddress",N),H.localCandidate=new DY(_O("relay","udp",N[0]),1,"udp",hN("relay"),N[0],N[1],"relay",A[0],A[1],void 0,this.generation,this.localUsername),this.appendLocalCandidate(H.localCandidate),H.localCandidate})().catch((H)=>{W8("query TURN server",H)});if(this.options.forceTurn)G=[];G.push(Q)}return G}async connect(){if(W8("start connect ice"),!this.localCandidatesEnd){if(!this.localCandidatesStart)throw Error("Local candidates gathering was not performed")}if(!this.remoteUsername||!this.remotePassword)throw Error("Remote username or password is missing");for(let Y of this.remoteCandidates)this.pairRemoteCandidate(Y);this.sortCheckList(),this.unfreezeInitial(),W8("earlyChecks",this.localPassword,this.earlyChecks.length);for(let Y of this.earlyChecks)this.checkIncoming(...Y);this.earlyChecks=[],this.earlyChecksDone=!0;for(;;){if(this.state==="closed")break;if(!this.schedulingChecks())break;await yO.setTimeout(20)}let W=$N;while(this.checkList.length>0&&W===$N)W=await this.checkListState.get(),W8("checkListState",W);for(let Y of this.checkList)Y.handle?.resolve?.();if(W!==xF)throw Error("ICE negotiation failed");this.queryConsent(),this.setState("connected")}unfreezeInitial(){let[W]=this.checkList;if(!W)return;if(W.state===0)W.updateState(1);let Y=new Set(W.localCandidate.foundation);for(let G of this.checkList)if(G.component===W.component&&!Y.has(G.localCandidate.foundation)&&G.state===0)G.updateState(1),Y.add(G.localCandidate.foundation)}schedulingChecks(){{let W=this.checkList.filter((Y)=>{if(this.options.forceTurn&&Y.protocol.type===LF.type)return!1;return!0}).find((Y)=>Y.state===1);if(W)return W.handle=this.checkStart(W),!0}{let W=this.checkList.find((Y)=>Y.state===0);if(W)return W.handle=this.checkStart(W),!0}if(!this.remoteCandidatesEnd)return!this.checkListDone;return!1}queryConsent=()=>{if(this.queryConsentHandle)this.queryConsentHandle.resolve();this.queryConsentHandle=kO(async(W,Y,G)=>{let X=0,J=!1,Z=new AbortController;G.once(()=>{J=!0,X+=kF,Z.abort(),this.queryConsentHandle=void 0});let{localUsername:V,remoteUsername:U,iceControlling:Q}=this;try{while(this.state!=="closed"&&!J){await yO.setTimeout(rn*(0.8+0.4*Math.random())*1000,void 0,{signal:Z.signal});let H=this.nominated;if(!H||J)break;let N=this.buildRequest({nominate:!1,localUsername:V,remoteUsername:U,iceControlling:Q});try{if(await H.protocol.request(N,H.remoteAddr,Buffer.from(this.remotePassword,"utf8"),0),X=0,this.state==="disconnected")this.setState("connected")}catch(A){if(H.id===this.nominated?.id){W8("no stun response"),X++,this.setState("disconnected");break}}if(X>=kF){W8("Consent to send expired"),this.queryConsentHandle=void 0,this.setState("closed");break}}}catch(H){}})};async close(){if(this.setState("closed"),this.queryConsentHandle?.resolve?.(),this.checkList&&!this.checkListDone)this.checkListState.put(new Promise((W)=>{W($N)}));this.nominated=void 0;for(let W of this.protocols)if(W.close)await W.close();this.protocols=[],this.localCandidates=[],this.lookup?.close?.(),this.lookup=void 0}setState(W){this.state=W,this.stateChanged.execute(W)}async addRemoteCandidate(W){if(!W){this.remoteCandidatesEnd=!0;return}if(W.host.includes(".local"))try{if(!this.lookup)this.lookup=new dn;let Y=await this.lookup.lookup(W.host);W.host=Y}catch(Y){return}try{_F(W)}catch(Y){return}W8("addRemoteCandidate",W),this._remoteCandidates.push(W),this.pairRemoteCandidate(W),this.sortCheckList()}send=async(W)=>{let Y=this.nominated;if(Y)await Y.protocol.sendData(W,Y.remoteAddr),Y.packetsSent++,Y.bytesSent+=W.length;else return};getDefaultCandidate(){let W=this.localCandidates.sort((G,X)=>G.priority-X.priority),[Y]=W;return Y}set remoteCandidates(W){if(this.remoteCandidatesEnd)throw Error("Cannot set remote candidates after end-of-candidates.");this._remoteCandidates=[];for(let Y of W){try{_F(Y)}catch(G){continue}this._remoteCandidates.push(Y)}this.remoteCandidatesEnd=!0}get remoteCandidates(){return this._remoteCandidates}get candidatePairs(){return this.checkList}sortCheckList(){sn(this.checkList,this.iceControlling)}findPair(W,Y){return this.checkList.find((X)=>bN.default(X.protocol,W)&&bN.default(X.remoteCandidate,Y))}switchRole(W){W8("switch role",W),this.iceControlling=W,this.sortCheckList()}checkComplete(W){if(W.handle=void 0,W.state===3){if(W.nominated&&(W.remoteCandidate.generation!=null?W.remoteCandidate.generation===this.generation:!0)&&this.nominated==null){W8("nominated",W.toJSON()),this.nominated=W,this.nominating=!1;for(let Y of this.checkList)if(Y.component===W.component&&[1,0].includes(Y.state))Y.updateState(4)}if(this.nominated){if(!this.checkListDone)W8("ICE completed"),this.checkListState.put(new Promise((Y)=>Y(xF))),this.checkListDone=!0;return}W8("not completed",W.toJSON());for(let Y of this.checkList)if(Y.localCandidate.foundation===W.localCandidate.foundation&&Y.state===0)Y.updateState(1)}{let Y=[3,4];if(this.checkList.find(({state:G})=>!Y.includes(G)))return}if(!this.iceControlling){if(this.checkList.find(({state:G})=>G===3))return}if(!this.checkListDone)W8("ICE failed"),this.checkListState.put(new Promise((Y)=>{Y($N)}))}checkStart=(W)=>kO(async(Y)=>{W8("check start",W.toJSON()),W.updateState(2);let G={},{remotePassword:X,remoteUsername:J,generation:Z}=this,V=W.localCandidate.ufrag??this.localUsername,U=this.iceControlling&&!this.remoteIsLite,Q=this.buildRequest({nominate:U,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling}),H=performance.now();try{let[N,A]=await W.protocol.request(Q,W.remoteAddr,Buffer.from(X,"utf8"),4),z=(performance.now()-H)/1000;W.rtt=z,W.totalRoundTripTime+=z,W.roundTripTimeMeasurements++,W8("response received",Q.toJSON(),N.toJSON(),A,{localUsername:V,remoteUsername:J,remotePassword:X,generation:Z,rtt:z}),G.response=N,G.addr=A}catch(N){let A=N;if(W8("failure case",Q.toJSON(),A.response?JSON.stringify(A.response.toJSON(),null,2):N,{localUsername:V,remoteUsername:J,remotePassword:X,generation:Z},W.remoteAddr),A.response?.getAttributeValue("ERROR-CODE")[0]===487){if(Q.attributesKeys.includes("ICE-CONTROLLED"))this.switchRole(!0);else if(Q.attributesKeys.includes("ICE-CONTROLLING"))this.switchRole(!1);await this.checkStart(W).awaitable,Y();return}if(A.response?.getAttributeValue("ERROR-CODE")[0]===401){W8("retry 401",W.toJSON()),await this.checkStart(W).awaitable,Y();return}else{W8("checkStart CandidatePairState.FAILED",W.toJSON()),W.updateState(4),this.checkComplete(W),Y();return}}if(!bN.default(G.addr,W.remoteAddr)){W.updateState(4),this.checkComplete(W),Y();return}if(U||W.remoteNominated)W.nominated=!0;else if(this.iceControlling&&!this.nominating){this.nominating=!0;let N=this.buildRequest({nominate:!0,localUsername:V,remoteUsername:J,iceControlling:this.iceControlling});try{await W.protocol.request(N,W.remoteAddr,Buffer.from(this.remotePassword,"utf8"))}catch(A){W.updateState(4),this.checkComplete(W);return}W.nominated=!0}W.updateState(3),this.checkComplete(W),Y()});addPair(W){this.checkList.push(W),this.sortCheckList()}checkIncoming(W,Y,G){let X=W.getAttributeValue("USERNAME"),{remoteUsername:J}=gF(X),Z,[V,U]=Y;for(let H of this.remoteCandidates)if(H.host===V&&H.port===U){Z=H;break}if(!Z)Z=new DY(vV(10),1,"udp",W.getAttributeValue("PRIORITY"),V,U,"prflx",void 0,void 0,void 0,void 0,void 0),this._remoteCandidates.push(Z);let Q=this.findPair(G,Z);if(!Q)Q=new SF(G,Z,this.iceControlling),Q.updateState(1),this.addPair(Q);if(Q.localCandidate.ufrag=J,W8("Triggered Checks",W.toJSON(),Q.toJSON(),{localUsername:this.localUsername,remoteUsername:this.remoteUsername,localPassword:this.localPassword,remotePassword:this.remotePassword,generation:this.generation}),[1,4].includes(Q.state))Q.handle=this.checkStart(Q);if(W.attributesKeys.includes("USE-CANDIDATE")&&!this.iceControlling){if(Q.remoteNominated=!0,Q.state===3)Q.nominated=!0,this.checkComplete(Q)}}tryPair(W,Y){if(W.localCandidate?.canPairWith(Y)&&!this.findPair(W,Y)){let G=new SF(W,Y,this.iceControlling);if(this.options.filterCandidatePair&&!this.options.filterCandidatePair(G))return;G.updateState(1),this.addPair(G)}}pairLocalProtocol(W){for(let Y of this.remoteCandidates)this.tryPair(W,Y)}pairRemoteCandidate=(W)=>{for(let Y of this.protocols)this.tryPair(Y,W)};buildRequest({nominate:W,remoteUsername:Y,localUsername:G,iceControlling:X}){let J=Xi({remoteUsername:Y,localUsername:G}),Z=new p7(1,0);if(Z.setAttribute("USERNAME",J).setAttribute("PRIORITY",hN("prflx")),X){if(Z.setAttribute("ICE-CONTROLLING",this.tieBreaker),W)Z.setAttribute("USE-CANDIDATE",null)}else Z.setAttribute("ICE-CONTROLLED",this.tieBreaker);return Z}respondError(W,Y,G,X){let J=new p7(W.messageMethod,272,W.transactionId);J.setAttribute("ERROR-CODE",X).addMessageIntegrity(Buffer.from(this.localPassword,"utf8")).addFingerprint(),G.sendStun(J,Y).catch((Z)=>{W8("sendStun error",Z)})}},Xi=({remoteUsername:W,localUsername:Y})=>{return`${W}:${Y}`},gF=(W)=>{let[Y,G]=W.split(":");return{remoteUsername:Y,localUsername:G}};function uF(W){return W.map((Y,G)=>[G,Y])}function m4(W,Y){let G=W.split(Y);return[G[0],G.slice(1).join(Y)]}var QK=class extends Ji{addEventListener=(W,Y)=>{this.addListener(W,Y)};removeEventListener=(W,Y)=>{this.removeListener(W,Y)}},Zi=M1("werift:packages/webrtc/src/dataChannel.ts");function Vi(W){return Buffer.isBuffer(W)?W.length:Buffer.byteLength(W)}var F2=class extends QK{constructor(W,Y,G=!0){super();if(this.sctp=W,this.parameters=Y,this.sendOpen=G,this.id=this.parameters.id,Y.negotiated){if(this.id==null||this.id<0||this.id>65534)throw Error("ID must be in range 0-65534 if data channel is negotiated out-of-band");this.sctp.dataChannelAddNegotiated(this)}else if(G)this.sendOpen=!1,this.sctp.dataChannelOpen(this)}stateChange=new p0;stateChanged=new p0;onMessage=new p0;error=new p0;bufferedAmountLow=new p0;onopen;onclose;onclosing;onmessage;onerror;isCreatedByRemote=!1;id;readyState="connecting";bufferedAmount=0;_bufferedAmountLowThreshold=0;messagesSent=0;bytesSent=0;messagesReceived=0;bytesReceived=0;get ordered(){return this.parameters.ordered}get maxRetransmits(){return this.parameters.maxRetransmits}get maxPacketLifeTime(){return this.parameters.maxPacketLifeTime}get label(){return this.parameters.label}get protocol(){return this.parameters.protocol}get negotiated(){return this.parameters.negotiated}get bufferedAmountLowThreshold(){return this._bufferedAmountLowThreshold}set bufferedAmountLowThreshold(W){if(W<0||W>4294967295)throw Error("bufferedAmountLowThreshold must be in range 0 - 4294967295");this._bufferedAmountLowThreshold=W}setId(W){this.id=W}setReadyState(W){if(W!==this.readyState){switch(this.readyState=W,this.stateChange.execute(W),this.stateChanged.execute(W),W){case"open":if(this.onopen)this.onopen();this.emit("open");break;case"closed":if(this.onclose)this.onclose();this.emit("close");break;case"closing":if(this.onclosing)this.onclosing();break}Zi("change state",W)}}addBufferedAmount(W){let Y=this.bufferedAmount>this.bufferedAmountLowThreshold&&this.bufferedAmount+W<=this.bufferedAmountLowThreshold;if(this.bufferedAmount+=W,Y)this.bufferedAmountLow.execute(),this.emit("bufferedamountlow")}send(W){let Y=this.sctp.datachannelSend(this,W);this.messagesSent++,this.bytesSent+=Y}close(){this.sctp.dataChannelClose(this)}},S2=class{label="";maxPacketLifeTime;maxRetransmits;ordered=!0;protocol="";negotiated=!1;id;constructor(W={}){Object.assign(this,W)}};var wq=()=>({type:"nack"}),QU=()=>({type:"nack",parameter:"pli"}),jq=()=>({type:"goog-remb"}),Ui=()=>({type:"transport-cc"}),EY=class{payloadType;mimeType;clockRate;channels;rtcpFeedback=[];parameters;direction="all";constructor(W){Object.assign(this,W)}get name(){return this.mimeType.split("/")[1]}get contentType(){return this.mimeType.split("/")[0]}get str(){let W=`${this.name}/${this.clockRate}`;if(this.channels===2)W+="/2";return W}},Qi=class{id;uri;constructor(W){Object.assign(this,W)}};var Hi=class{type;parameter;constructor(W={}){Object.assign(this,W)}},Ni=class{ssrc;constructor(W={}){Object.assign(this,W)}},qi=class{ssrc;payloadType;rtx;constructor(W){Object.assign(this,W)}},x2=class{rid;direction;constructor(W){Object.assign(this,W)}},Ai=(W={})=>new EY({mimeType:"video/h264",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],parameters:"profile-level-id=42e01f;packetization-mode=1;level-asymmetry-allowed=1",...W}),k2=(W={})=>new EY({mimeType:"video/VP8",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),Ii=(W={})=>new EY({mimeType:"video/VP9",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),zi=(W={})=>new EY({mimeType:"video/AV1X",clockRate:90000,rtcpFeedback:[wq(),QU(),jq()],...W}),_2=(W={})=>new EY({mimeType:"audio/OPUS",clockRate:48000,channels:2,...W}),y2=(W={})=>new EY({mimeType:"audio/PCMU",clockRate:8000,channels:1,payloadType:0,...W}),v2=[zi(),Ii(),k2(),Ai(),_2(),y2()].map((W)=>W.mimeType),eq0=v2.filter((W)=>W.toLowerCase().startsWith("video/")),WA0=v2.filter((W)=>W.toLowerCase().startsWith("audio/"));var hF=2,bF=3,Ki=0,SN=50,mF=51,fF=53,Di=56,Ci=57,Ti="0.0.0.0",cF=9,gO={auto:"actpass",client:"active",server:"passive"},pF=Object.keys(gO).reduce((W,Y)=>{let G=gO[Y];return W[G]=Y,W},{}),Ri=["apt","max-fr","max-fs","maxplaybackrate","minptime","stereo","useinbandfec"],g2=["cname","msid","mslabel","label"],lF={SRTP_AES128_CM_HMAC_SHA1_80:zq,SRTP_AEAD_AES_128_GCM:VU},mN=["sendonly","sendrecv"],Mi=["sendrecv","recvonly"],Pi=class extends Map{constructor(W){super();if(W)for(let Y of W)this.set(Y.id,Y)}};function Z8(W,...Y){let G=Y.filter((X)=>X!==void 0);return`${W}_${G.join("_")}`}function $Y(){return performance.now()}var Li=class{constructor(W,Y,G,X,J){if(this.kind=W,this.receiver=G,this.sender=X,this._direction=J,Y)this.setDtlsTransport(Y)}id=Oi().toString();onTrack=new p0;mid;mLineIndex;usedForSender=!1;_currentDirection;offerDirection;_codecs=[];set codecs(W){this._codecs=W}get codecs(){return this._codecs}headerExtensions=[];options={};stopping=!1;stopped=!1;get dtlsTransport(){return this.receiver.dtlsTransport}get direction(){return this._direction}setDirection(W){if(this._direction=W,mN.includes(this._currentDirection??""))this.usedForSender=!0}get currentDirection(){return this._currentDirection}setCurrentDirection(W){this._currentDirection=W}setDtlsTransport(W){this.receiver.setDtlsTransport(W),this.sender.setDtlsTransport(W)}get msid(){return`${this.sender.streamId} ${this.sender.trackId}`}addTrack(W){if(this.receiver.addTrack(W))this.onTrack.execute(W,this)}stop(){if(this.stopping)return;this.stopping=!0}getPayloadType(W){return this.codecs.find((Y)=>Y.mimeType.toLowerCase().includes(W.toLowerCase()))?.payloadType}getCodecStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id);for(let X of this.codecs){let J={type:"codec",id:Z8("codec",X.payloadType,G),timestamp:W,payloadType:X.payloadType,transportId:G,mimeType:X.mimeType,clockRate:X.clockRate,channels:X.channels,sdpFmtpLine:X.parameters};Y.push(J)}return Y}},Bi="inactive",u2="sendonly",h2="recvonly",b2="sendrecv",wO=[Bi,u2,h2,b2],uO=class extends QK{uuid=m2().toString();streamId;remote=!1;label;kind;id;ssrc;rid;header;codec;enabled=!0;onReceiveRtp=new p0;onReceiveRtcp=new p0;onSourceChanged=new p0;stopped=!1;muted=!0;constructor(W){super();Object.assign(this,W),this.onReceiveRtp.subscribe((Y)=>{this.muted=!1,this.header=Y.header}),this.label=`${this.remote?"remote":"local"} ${this.kind}`}stop=()=>{this.stopped=!0,this.muted=!0,this.onReceiveRtp.complete(),this.emit("ended")};writeRtp=(W)=>{if(this.remote)throw Error("this is remoteTrack");if(this.stopped)return;let Y=Buffer.isBuffer(W)?t6.deSerialize(W):W;Y.header.payloadType=this.codec?.payloadType??Y.header.payloadType,this.onReceiveRtp.execute(Y)}},Ei=class{id;tracks=[];constructor(W){if(Array.isArray(W))this.tracks=W;else Object.assign(this,W);this.id??=m2().toString()}addTrack(W){W.streamId=this.id,this.tracks.push(W)}getTracks(){return this.tracks}getAudioTracks(){return this.tracks.filter((W)=>W.kind==="audio")}getVideoTracks(){return this.tracks.filter((W)=>W.kind==="video")}},$i=M1("werift:packages/webrtc/src/utils.ts");function f2(W,Y){let G=(Z)=>Z.toUpperCase(),X=(Z)=>Z.match(/(.{2})/g).join(":"),J=ji(Y).update(W).digest("hex");return X(G(J))}var Fi={sha1:"sha1","sha-1":"sha1",sha224:"sha224","sha-224":"sha224",sha256:"sha256","sha-256":"sha256",sha384:"sha384","sha-384":"sha384",sha512:"sha512","sha-512":"sha512"};function c2(W){return Fi[W.trim().toLowerCase()]}function hO(W){return W.replace(/[^0-9a-f]/gi,"").toLowerCase()}function Si(W){let Y=W[0];return Y>19&&Y<64}var p2=(W,Y)=>wO[wO.indexOf(W)&wO.indexOf(Y)];function xi(W){if(W==="sendonly")return"recvonly";if(W==="recvonly")return"sendonly";return W}var l2=Date.now,ki=BigInt(Date.now())*1000n-process.hrtime.bigint()/1000n,_i=()=>{return ki+process.hrtime.bigint()/1000n},Vq=()=>Date.now()/1000,yi=()=>{let Y=(FN.timeOrigin+FN.now()-Date.UTC(1900,0,1))/1000,[G,X]=Y.toString().split(".").map(Number);return E8([4,4],[G,X]).readBigUInt64BE()},d2=(W)=>{let Y=E8([8],[W]),[,G,X]=s9(Y,[2,2,2,2]);return E8([2,2],[G,X]).readUInt32BE()};function vi(W){let Y=(U)=>{if(!U)return;let[Q,H]=U.split(":");return[Q,Number.parseInt(H)]},G=Y(W.find(({urls:U})=>U.includes("stun:"))?.urls.slice(5)),X=Y(W.find(({urls:U})=>U.includes("turn:"))?.urls.slice(5)),{credential:J,username:Z}=W.find(({urls:U})=>U.includes("turn:"))||{},V={stunServer:G,turnServer:X,turnUsername:Z,turnPassword:J};return $i("iceOptions",V),V}var UA0=aN.createSelfSignedCertificateWithKey;var gi=(W,Y)=>{if(!W||typeof W!=="object")if(Y!==null&&typeof Y==="object")return Y;else return W;if(!Y||typeof Y!=="object"){if(Y==null)return W;return Y}for(let G in Y)if(Object.prototype.hasOwnProperty.call(Y,G)){let X=Y[G];if(X!=null)W[G]=X}return W},ui=M1("werift:packages/webrtc/src/media/receiver/nack.ts"),dF=150,hi=class{constructor(W){this.receiver=W}newEstSeqNum=0;_lost={};nackLoop;onPacketLost=new p0;mediaSourceSsrc;retryCount=10;closed=!1;get lostSeqNumbers(){return Object.keys(this._lost).map(Number).sort()}getLost(W){return this._lost[W]}setLost(W,Y){if(this._lost[W]=Y,this.nackLoop||this.closed)return;this.nackLoop=setInterval(async()=>{try{if(await this.sendNack(),!Object.keys(this._lost).length)clearInterval(this.nackLoop),this.nackLoop=void 0}catch(G){ui("failed to send nack",G)}},5)}removeLost(W){delete this._lost[W]}addPacket(W){let{sequenceNumber:Y,ssrc:G}=W.header;if(this.mediaSourceSsrc=G,this.newEstSeqNum===0){this.newEstSeqNum=Y;return}if(this.getLost(Y)){this.removeLost(Y);return}if(Y===T9(this.newEstSeqNum,1))this.newEstSeqNum=Y;else if(Y>T9(this.newEstSeqNum,1)){for(let X=T9(this.newEstSeqNum,1);X<Y;X=T9(X,1))this.setLost(X,1);this.newEstSeqNum=Y,this.pruneLost()}}pruneLost(){if(this.lostSeqNumbers.length>dF)this._lost=Object.entries(this._lost).slice(-dF).reduce((W,[Y,G])=>{return W[Y]=G,W},{})}close(){this.closed=!0,clearInterval(this.nackLoop),this._lost={}}updateRetryCount(){this.lostSeqNumbers.forEach((W)=>{if(this._lost[W]++>this.retryCount)return this.removeLost(W),W})}sendNack=()=>new Promise((W,Y)=>{if(this.lostSeqNumbers.length>0&&this.mediaSourceSsrc){let G=new Xq({senderSsrc:this.receiver.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,lost:this.lostSeqNumbers}),X=new hX({feedback:G});this.receiver.dtlsTransport.sendRtcp([X]).then(W).catch(Y),this.updateRetryCount(),this.onPacketLost.execute(G)}})},mi=M1("werift:packages/webrtc/media/receiver/receiverTwcc"),fi=class{constructor(W,Y,G){this.dtlsTransport=W,this.rtcpSsrc=Y,this.mediaSourceSsrc=G,this.runTWCC()}extensionInfo={};twccRunning=!1;fbPktCount=0;lastTimestamp;handleTWCC(W){if(this.extensionInfo[W]={tsn:W,timestamp:_i()},Object.keys(this.extensionInfo).length>10)this.sendTWCC()}async runTWCC(){while(this.twccRunning)this.sendTWCC(),await bi(100)}sendTWCC(){if(Object.keys(this.extensionInfo).length===0)return;let W=Object.values(this.extensionInfo).sort((N,A)=>N.tsn-A.tsn),Y=W[0].tsn,G=W.slice(-1)[0].tsn,X=[],J=W[0].tsn,Z=T9(G-Y,1),V,U,Q=[];for(let N=Y;N<=G;N++){let A=this.extensionInfo[N]?.timestamp;if(A){if(!this.lastTimestamp)this.lastTimestamp=A;if(!V)V=this.lastTimestamp;let q=A-this.lastTimestamp;this.lastTimestamp=A;let z=new yN({delta:Number(q)});if(z.parseDelta(),Q.push(z),U!=null&&U.status!==z.type)X.push(new dV({packetStatus:U.status,runLength:N-U.minTSN})),U={minTSN:N,status:z.type};if(N===G)if(U!=null)X.push(new dV({packetStatus:U.status,runLength:N-U.minTSN+1}));else X.push(new dV({packetStatus:z.type,runLength:1}));if(U==null)U={minTSN:N,status:z.type}}}if(!V)return;let H=new hX({feedback:new Jq({senderSsrc:this.rtcpSsrc,mediaSourceSsrc:this.mediaSourceSsrc,baseSequenceNumber:J,packetStatusCount:Z,referenceTime:xd(Math.floor(Number(V/1000n/64n))),fbPktCount:this.fbPktCount,recvDeltas:Q,packetChunks:X})});this.dtlsTransport.sendRtcp([H]).catch((N)=>{mi(N)}),this.extensionInfo={},this.fbPktCount=Sd(this.fbPktCount,1)}},ci=class{base_seq;max_seq;cycles=0;packets_received=0;clockRate;jitter_q4=0;last_arrival;last_timestamp;expected_prior=0;received_prior=0;constructor(W){this.clockRate=W}add(W,Y=Date.now()/1000){let G=this.max_seq==null||RS(W.header.sequenceNumber,this.max_seq);if(this.packets_received++,this.base_seq==null)this.base_seq=W.header.sequenceNumber;if(G){let X=lV(Y*this.clockRate);if(this.max_seq!=null&&W.header.sequenceNumber<this.max_seq)this.cycles+=65536;if(this.max_seq=W.header.sequenceNumber,W.header.timestamp!==this.last_timestamp&&this.packets_received>1){let J=Math.abs(X-(this.last_arrival??0)-(W.header.timestamp-(this.last_timestamp??0)));this.jitter_q4+=J-(this.jitter_q4+8>>4)}this.last_arrival=X,this.last_timestamp=W.header.timestamp}}get fraction_lost(){let W=this.packets_expected-this.expected_prior;this.expected_prior=this.packets_expected;let Y=this.packets_received-this.received_prior;this.received_prior=this.packets_received;let G=W-Y;if(W==0||G<=0)return 0;else return Math.floor((G<<8)/W)}get jitter(){return this.jitter_q4>>4}get packets_expected(){return this.cycles+(this.max_seq??0)-(this.base_seq??0)+1}get packets_lost(){let W=this.packets_expected-this.packets_received;return W<0?0:W}},t5=M1("werift:packages/webrtc/src/transport/dtls.ts"),oF=class W{constructor(Y,G,X,J=[]){this.config=Y,this.iceTransport=G,this.localCertificate=X,this.srtpProfiles=J,this.localCertificate??=W.localCertificate}id=di().toString();state="new";role="auto";srtpStarted=!1;transportSequenceNumber=0;bytesSent=0;bytesReceived=0;packetsSent=0;packetsReceived=0;dataReceiver=()=>{};dtls;srtp;srtcp;onStateChange=new p0;onRtcp=new p0;onRtp=new p0;static localCertificate;static localCertificatePromise;remoteParameters;get localParameters(){return new mO(this.localCertificate?this.localCertificate.getFingerprints():[],this.role)}static async SetupCertificate(){if(this.localCertificate)return this.localCertificate;if(this.localCertificatePromise)return this.localCertificatePromise;return this.localCertificatePromise=(async()=>{let{certPem:Y,keyPem:G,signatureHash:X}=await aN.createSelfSignedCertificateWithKey({signature:l4.ecdsa_3,hash:rN.sha256_4},a6.secp256r1_23);return this.localCertificate=new o2(G,Y,X),this.localCertificate})(),this.localCertificatePromise}setRemoteParams(Y){let G=ni([...this.remoteParameters?.fingerprints??[],...Y.fingerprints]),X=Y.role==="auto"&&this.remoteParameters?.role?this.remoteParameters.role:Y.role;this.remoteParameters=new mO(G,X)}async start(){if(this.state!=="new")throw Error("state must be new");if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");if(this.role==="auto")if(this.iceTransport.role==="controlling")this.role="server";else this.role="client";this.setState("connecting"),await new Promise(async(Y,G)=>{if(this.role==="server")this.dtls=new Cn({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:nF(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0,certificateRequest:!0});else this.dtls=new OF({cert:this.localCertificate?.certPem,key:this.localCertificate?.privateKey,signatureHash:this.localCertificate?.signatureHash,transport:nF(this.iceTransport.connection),srtpProfiles:this.srtpProfiles,extendedMasterSecret:!0});if(this.dtls.onData.subscribe((X)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;this.dataReceiver(X)}),this.dtls.onClose.subscribe(()=>{if(this.state!=="failed")this.setState("closed")}),this.dtls.onConnect.once(Y),this.dtls.onError.once((X)=>{this.setState("failed"),t5("dtls failed",X),G(X)}),this.dtls instanceof OF)await oi(100),this.dtls.connect().catch((X)=>{this.setState("failed"),t5("dtls connect failed",X),G(X)})});try{this.verifyRemoteCertificateFingerprint()}catch(Y){throw this.setState("failed"),this.dtls?.close(),Y}if(this.srtpProfiles.length>0)this.startSrtp();this.setState("connected"),t5("dtls connected")}verifyRemoteCertificateFingerprint(){if(!this.remoteParameters||this.remoteParameters.fingerprints.length===0)throw Error("remote fingerprint not exist");let Y=this.dtls?.remoteCertificate;if(!Y)throw Error("remote certificate not available");let G=this.remoteParameters.fingerprints.flatMap(({algorithm:U,value:Q})=>{let H=c2(U);if(!H)return[];let N=hO(Q);if(!N)throw Error("remote fingerprint value is empty");return[{normalizedAlgorithm:H,normalizedValue:N}]});if(G.length===0)throw Error("no supported remote fingerprint algorithms");let X=ri(G),J=G.filter(({normalizedAlgorithm:U})=>U===X),Z=J.reduce((U,{normalizedAlgorithm:Q})=>{if(!U.has(Q))U.set(Q,hO(f2(Y,Q)));return U},new Map);if(!J.some(({normalizedAlgorithm:U,normalizedValue:Q})=>Z.get(U)===Q))throw Error("remote certificate fingerprint mismatch")}updateSrtpSession(){if(!this.dtls)throw Error();let Y=this.dtls.srtp.srtpProfile;if(!Y)throw Error("need srtpProfile");t5("selected SRTP Profile",Y);let{localKey:G,localSalt:X,remoteKey:J,remoteSalt:Z}=this.dtls.extractSessionKeys(Mo(Y),Po(Y)),V={keys:{localMasterKey:G,localMasterSalt:X,remoteMasterKey:J,remoteMasterSalt:Z},profile:Y};this.srtp=new Hn(V),this.srtcp=new Un(V)}startSrtp(){if(this.srtpStarted)return;this.srtpStarted=!0,this.updateSrtpSession(),this.iceTransport.connection.onData.subscribe((Y)=>{if(this.config.debug.inboundPacketLoss&&this.config.debug.inboundPacketLoss/100<Math.random())return;if(!Eo(Y))return;if(this.bytesReceived+=Y.length,this.packetsReceived++,go(Y)){let G;try{G=this.srtcp.decrypt(Y)}catch(J){if(J instanceof mX){t5("dropping invalid SRTCP packet",J);return}throw J}let X;try{X=vo.deSerialize(G)}catch(J){t5("dropping malformed SRTCP packet",J);return}for(let J of X)try{this.onRtcp.execute(J)}catch(Z){t5("RTCP error",Z)}}else{let G;try{G=this.srtp.decrypt(Y)}catch(J){if(J instanceof mX){t5("dropping invalid SRTP packet",J);return}throw J}let X;try{X=t6.deSerialize(G)}catch(J){t5("dropping malformed SRTP packet",J);return}try{this.onRtp.execute(X)}catch(J){t5("RTP error",J)}}})}sendData=async(Y)=>{if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return;if(!this.dtls)throw Error("dtls not established");await this.dtls.send(Y)};async sendRtp(Y,G){try{let X=this.srtp.encrypt(Y,G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return X.length;return this.bytesSent+=X.length,this.packetsSent++,await this.iceTransport.connection.send(X).catch(()=>{}),X.length}catch(X){return t5("failed to send",X),0}}async sendRtcp(Y){let G=Buffer.concat(Y.map((J)=>J.serialize())),X=this.srtcp.encrypt(G);if(this.config.debug.outboundPacketLoss&&this.config.debug.outboundPacketLoss/100<Math.random())return X.length;this.bytesSent+=X.length,this.packetsSent++,await this.iceTransport.connection.send(X).catch(()=>{})}setState(Y){if(Y!=this.state)this.state=Y,this.onStateChange.execute(Y)}async stop(){this.setState("closed"),await this.iceTransport.stop()}async getStats(){let Y=$Y(),G=[],J={type:"transport",id:Z8("transport",this.id),timestamp:Y,bytesSent:this.bytesSent,bytesReceived:this.bytesReceived,packetsSent:this.packetsSent,packetsReceived:this.packetsReceived,dtlsState:this.state,iceState:this.iceTransport.state,selectedCandidatePairId:this.iceTransport.connection.nominated?Z8("candidate-pair",this.iceTransport.connection.nominated.localCandidate.foundation,this.iceTransport.connection.nominated.remoteCandidate.foundation):void 0,localCertificateId:this.localCertificate?Z8("certificate","local"):void 0,remoteCertificateId:this.remoteParameters?Z8("certificate","remote"):void 0,dtlsRole:this.role==="auto"?void 0:this.role};if(G.push(J),this.localCertificate){let V=this.localCertificate.getFingerprints();if(V.length>0){let U={type:"certificate",id:Z8("certificate","local"),timestamp:Y,fingerprint:V[0].value,fingerprintAlgorithm:V[0].algorithm,base64Certificate:Buffer.from(this.localCertificate.certPem).toString("base64")};G.push(U)}}if(this.remoteParameters&&this.remoteParameters.fingerprints.length>0){let V={type:"certificate",id:Z8("certificate","remote"),timestamp:Y,fingerprint:this.remoteParameters.fingerprints[0].value,fingerprintAlgorithm:this.remoteParameters.fingerprints[0].algorithm,base64Certificate:""};G.push(V)}let Z=await this.iceTransport.getStats();return G.push(...Z),G}};var o2=class{constructor(W,Y,G){this.certPem=Y,this.signatureHash=G;let X=tV.Certificate.fromPEM(Buffer.from(Y));this.publicKey=X.publicKey.toPEM(),this.privateKey=tV.PrivateKey.fromPEM(Buffer.from(W)).toPEM()}publicKey;privateKey;getFingerprints(){return[new bO("sha-256",f2(tV.Certificate.fromPEM(Buffer.from(this.certPem)).raw,"sha256"))]}},bO=class{constructor(W,Y){this.algorithm=W,this.value=Y}},mO=class{constructor(W=[],Y){this.fingerprints=W,this.role=Y}},ni=(W)=>{let Y=new Set;return W.filter(({algorithm:G,value:X})=>{let J=`${c2(G)??G.trim().toLowerCase()}:${hO(X)}`;if(Y.has(J))return!1;return Y.add(J),!0})},ii=["sha512","sha384","sha256","sha224","sha1"],ri=(W)=>{return ii.find((Y)=>W.some(({normalizedAlgorithm:G})=>G===Y))??W[0].normalizedAlgorithm},ai=class{constructor(W){this.ice=W,W.onData.subscribe((Y)=>{if(Si(Y)){if(this.onData)this.onData(Y)}})}closed=!1;onData=()=>{};get address(){return{}}type="ice";send=(W)=>{return this.ice.send(W)};async close(){this.closed=!0,this.ice.close()}},nF=(W)=>new ai(W),iF=M1("werift:packages/webrtc/src/transport/ice.ts"),ti=class{constructor(W){this.iceGather=W,this.connection=this.iceGather.connection,this.connection.stateChanged.subscribe((Y)=>{this.setState(Y)}),this.iceGather.onIceCandidate=(Y)=>{this.onIceCandidate.execute(Y)}}id=si().toString();connection;state="new";waitStart;renominating=!1;onStateChange=new p0;onIceCandidate=new p0;onNegotiationNeeded=new p0;get role(){if(this.connection.iceControlling)return"controlling";else return"controlled"}get gatheringState(){return this.iceGather.gatheringState}get localCandidates(){return this.iceGather.localCandidates}get localParameters(){return this.iceGather.localParameters}setState(W){if(W!==this.state)this.state=W,this.onStateChange.execute(W)}gather(){return this.iceGather.gather()}addRemoteCandidate=(W)=>{if(!this.connection.remoteCandidatesEnd)if(!W)return this.connection.addRemoteCandidate(void 0);else return this.connection.addRemoteCandidate(Wr(W))};setRemoteParams(W,Y=!1){if(Y)this.renominating=!0;if(this.connection.remoteUsername&&this.connection.remotePassword&&(this.connection.remoteUsername!==W.usernameFragment||this.connection.remotePassword!==W.password))if(this.renominating)iF("renomination",W),this.connection.resetNominatedPair(),this.renominating=!1;else iF("restart",W),this.restart();this.connection.setRemoteParams(W)}restart(){this.connection.restart(),this.setState("new"),this.iceGather.gatheringState="new",this.waitStart=void 0,this.onNegotiationNeeded.execute()}async start(){if(this.state==="closed")throw Error("RTCIceTransport is closed");if(!this.connection.remotePassword||!this.connection.remoteUsername)throw Error("remoteParams missing");if(this.waitStart)await this.waitStart.asPromise();this.waitStart=new p0,this.setState("checking");try{await this.connection.connect()}catch(W){throw this.setState("failed"),W}this.waitStart.execute(),this.waitStart.complete(),this.waitStart=void 0}async stop(){if(this.state!=="closed")this.setState("closed"),await this.connection.close();this.onStateChange.complete(),this.onIceCandidate.complete(),this.onNegotiationNeeded.complete()}async getStats(){let W=$Y(),Y=[];for(let X of this.localCandidates){let J={type:"local-candidate",id:Z8("local-candidate",X.foundation),timestamp:W,transportId:Z8("transport",this.id),address:X.ip,port:X.port,protocol:X.protocol,candidateType:X.type,priority:X.priority,foundation:X.foundation};Y.push(J)}for(let X of this.connection.remoteCandidates){let J=eV(X),Z={type:"remote-candidate",id:Z8("remote-candidate",J.foundation),timestamp:W,transportId:Z8("transport",this.id),address:J.ip,port:J.port,protocol:J.protocol,candidateType:J.type,priority:J.priority,foundation:J.foundation};Y.push(Z)}let G=this.connection?.candidatePairs?[...this.connection.candidatePairs.filter((X)=>X.nominated),...this.connection.candidatePairs.filter((X)=>!X.nominated)]:[];for(let X of G){let J={type:"candidate-pair",id:Z8("candidate-pair",X.foundation),timestamp:W,transportId:Z8("transport",this.id),localCandidateId:Z8("local-candidate",X.localCandidate.foundation),remoteCandidateId:Z8("remote-candidate",X.remoteCandidate.foundation),state:X.state,nominated:X.nominated,packetsSent:X.packetsSent,packetsReceived:X.packetsReceived,bytesSent:X.bytesSent,bytesReceived:X.bytesReceived,currentRoundTripTime:X.rtt};Y.push(J)}return Y}};var ei=class{constructor(W={}){this.options=W,this.connection=new Gi(!1,this.options),this.connection.onIceCandidate.subscribe((Y)=>{this.onIceCandidate(eV(Y))})}onIceCandidate=()=>{};gatheringState="new";connection;onGatheringStateChange=new p0;async gather(){if(this.gatheringState==="new")this.setState("gathering"),await this.connection.gatherCandidates(),this.onIceCandidate(void 0),this.setState("complete")}get localCandidates(){return this.connection.localCandidates.map(eV)}get localParameters(){return new i2({usernameFragment:this.connection.localUsername,password:this.connection.localPassword})}setState(W){if(W!==this.gatheringState)this.gatheringState=W,this.onGatheringStateChange.execute(W)}};function eV(W){let Y=new n2(W.component,W.foundation,W.host,W.port,W.priority,W.transport,W.type,W.generation,W.ufrag);return Y.relatedAddress=W.relatedAddress,Y.relatedPort=W.relatedPort,Y.tcpType=W.tcptype,Y}function Wr(W){return new DY(W.foundation,W.component,W.protocol,W.priority,W.ip,W.port,W.type,W.relatedAddress,W.relatedPort,W.tcpType,W.generation,W.ufrag)}var Yr=class{candidate;sdpMid;sdpMLineIndex;usernameFragment;constructor(W){Object.assign(this,W)}static fromSdp(W){let Y=DY.fromSdp(W);return eV(Y).toJSON()}static isThis(W){if(typeof W?.candidate==="string")return!0}toJSON(){return{candidate:this.candidate,sdpMid:this.sdpMid,sdpMLineIndex:this.sdpMLineIndex,usernameFragment:this.usernameFragment}}},n2=class{constructor(W,Y,G,X,J,Z,V,U,Q){this.component=W,this.foundation=Y,this.ip=G,this.port=X,this.priority=J,this.protocol=Z,this.type=V,this.generation=U,this.ufrag=Q}relatedAddress;relatedPort;sdpMid;sdpMLineIndex;tcpType;toJSON(){return new Yr({candidate:Jx(this),sdpMLineIndex:this.sdpMLineIndex,sdpMid:this.sdpMid,usernameFragment:this.ufrag})}static fromJSON(W){try{if(!W.candidate)throw Error("candidate is required");let Y=Zx(W.candidate);return Y.sdpMLineIndex=W.sdpMLineIndex??void 0,Y.sdpMid=W.sdpMid??void 0,Y}catch(Y){}}},i2=class{iceLite=!1;usernameFragment;password;constructor(W={}){Object.assign(this,W)}},d7=class W{constructor(Y=0,G=Buffer.from("")){this.flags=Y,this._body=G}get body(){return this._body}set body(Y){this._body=Y}static type=-1;get type(){return W.type}get bytes(){if(!this.body)throw Error();let Y=Buffer.alloc(4);return Y.writeUInt8(this.type,0),Y.writeUInt8(this.flags,1),Y.writeUInt16BE(this.body.length+4,2),Buffer.concat([Y,this.body,...[...Array(NU(this.body.length))].map(()=>Buffer.from("\x00"))])}},HK=class extends d7{constructor(W=0,Y){super(W,Y);if(this.flags=W,Y)this.initiateTag=Y.readUInt32BE(0),this.advertisedRwnd=Y.readUInt32BE(4),this.outboundStreams=Y.readUInt16BE(8),this.inboundStreams=Y.readUInt16BE(10),this.initialTsn=Y.readUInt32BE(12),this.params=Wx(Y.slice(16));else this.initiateTag=0,this.advertisedRwnd=0,this.outboundStreams=0,this.inboundStreams=0,this.initialTsn=0,this.params=[]}initiateTag;advertisedRwnd;outboundStreams;inboundStreams;initialTsn;params;get body(){let W=Buffer.alloc(16);return W.writeUInt32BE(this.initiateTag,0),W.writeUInt32BE(this.advertisedRwnd,4),W.writeUInt16BE(this.outboundStreams,8),W.writeUInt16BE(this.inboundStreams,10),W.writeUInt32BE(this.initialTsn,12),Buffer.concat([W,e2(this.params)])}},fN=class W extends HK{static type=1;get type(){return W.type}},fO=class W extends HK{static type=2;get type(){return W.type}},Jr=class W extends HK{static type=130;get type(){return W.type}},cN=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G){this.cumulativeTsn=G.readUInt32BE(0);let X=4;while(X<G.length)this.streams.push([G.readUInt16BE(X),G.readUInt16BE(X+2)]),X+=4}else this.cumulativeTsn=0}static type=192;streams=[];cumulativeTsn;get type(){return W.type}set body(Y){}get body(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.cumulativeTsn,0),Buffer.concat([Y,...this.streams.map(([G,X])=>{let J=Buffer.alloc(4);return J.writeUInt16BE(G,0),J.writeUInt16BE(X,2),J})])}},pN=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G)this.tsn=G.readUInt32BE(0),this.streamId=G.readUInt16BE(4),this.streamSeqNum=G.readUInt16BE(6),this.protocol=G.readUInt32BE(8),this.userData=G.slice(12)}static type=0;get type(){return W.type}tsn=0;streamId=0;streamSeqNum=0;protocol=0;userData=Buffer.from("");abandoned=!1;acked=!1;misses=0;retransmit=!1;sentCount=0;bookSize=0;expiry;maxRetransmits;sentTime;get bytes(){let Y=16+this.userData.length,G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(Y,2),G.writeUInt32BE(this.tsn,4),G.writeUInt16BE(this.streamId,8),G.writeUInt16BE(this.streamSeqNum,10),G.writeUInt32BE(this.protocol,12);let X=Buffer.concat([G,this.userData]);if(Y%4)X=Buffer.concat([X,...[...Array(NU(Y))].map(()=>Buffer.from("\x00"))]);return X}},cO=class W extends d7{static type=10;get type(){return W.type}},pO=class W extends d7{static type=11;get type(){return W.type}},HU=class extends d7{constructor(W=0,Y=void 0){super(W,Y);if(this.flags=W,Y)this.params=Wx(Y)}params=[];get body(){return e2(this.params)}},lO=class W extends HU{static type=6;get type(){return W.type}},lN=class W extends HU{static type=9;static CODE={InvalidStreamIdentifier:1,MissingMandatoryParameter:2,StaleCookieError:3,OutofResource:4,UnresolvableAddress:5,UnrecognizedChunkType:6,InvalidMandatoryParameter:7,UnrecognizedParameters:8,NoUserData:9,CookieReceivedWhileShuttingDown:10,RestartofanAssociationwithNewAddresses:11,UserInitiatedAbort:12,ProtocolViolation:13};get type(){return W.type}get descriptions(){return this.params.map(([Y,G])=>{return{name:(Object.entries(W.CODE).find(([,J])=>J===Y)||[])[0],body:G}})}},dO=class W extends HU{static type=4;get type(){return W.type}},r2=class W extends HU{static type=5;get type(){return W.type}},oO=class W extends HU{static type=130;get type(){return W.type}},nO=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G){this.cumulativeTsn=G.readUInt32BE(0),this.advertisedRwnd=G.readUInt32BE(4);let X=G.readUInt16BE(8),J=G.readUInt16BE(10),Z=12;[...Array(X)].forEach(()=>{this.gaps.push([G.readUInt16BE(Z),G.readUInt16BE(Z+2)]),Z+=4}),[...Array(J)].forEach(()=>{this.duplicates.push(G.readUInt32BE(Z)),Z+=4})}}static type=3;get type(){return W.type}gaps=[];duplicates=[];cumulativeTsn=0;advertisedRwnd=0;get bytes(){let Y=16+4*(this.gaps.length+this.duplicates.length),G=Buffer.alloc(16);G.writeUInt8(this.type,0),G.writeUInt8(this.flags,1),G.writeUInt16BE(Y,2),G.writeUInt32BE(this.cumulativeTsn,4),G.writeUInt32BE(this.advertisedRwnd,8),G.writeUInt16BE(this.gaps.length,12),G.writeUInt16BE(this.duplicates.length,14);let X=Buffer.concat([G,...this.gaps.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt16BE(J[0],0),Z.writeUInt16BE(J[1],2),Z})]);return X=Buffer.concat([X,...this.duplicates.map((J)=>{let Z=Buffer.alloc(4);return Z.writeUInt32BE(J,0),Z})]),X}},a2=class W extends d7{constructor(Y=0,G){super(Y,G);if(this.flags=Y,G)this.cumulativeTsn=G.readUInt32BE(0)}static type=7;get type(){return W.type}cumulativeTsn=0;get body(){let Y=Buffer.alloc(4);return Y.writeUInt32BE(this.cumulativeTsn,0),Y}},s2=class W extends d7{static type=8;get type(){return W.type}},t2=class W extends d7{static type=14;get type(){return W.type}},Zr=[pN,fN,fO,nO,dO,r2,lO,a2,s2,lN,cO,pO,t2,oO,cN],Vr=Zr.reduce((W,Y)=>{return W[Y.type]=Y,W},{});function NU(W){let Y=W%4;return Y?4-Y:0}function e2(W){let Y=Buffer.from(""),G=Buffer.from("");return W.forEach(([X,J])=>{let Z=J.length+4,V=Buffer.alloc(4);V.writeUInt16BE(X,0),V.writeUInt16BE(Z,2),Y=Buffer.concat([Y,G,V,J]),G=Buffer.concat([...Array(NU(Z))].map(()=>Buffer.from("\x00")))}),Y}function Wx(W){let Y=[],G=0;while(G<=W.length-4){let X=W.readUInt16BE(G),J=W.readUInt16BE(G+2);Y.push([X,W.slice(G+4,G+J)]),G+=J+NU(J)}return Y}function Ur(W){if(W.length<12)throw Error("SCTP packet length is less than 12 bytes");let Y=W.readUInt16BE(0),G=W.readUInt16BE(2),X=W.readUInt32BE(4),J=W.readUInt32LE(8),Z=TS(Buffer.concat([W.slice(0,8),Buffer.from("\x00\x00\x00\x00"),W.slice(12)]));if(J!==Z)throw Error("SCTP packet has invalid checksum");let V=[],U=12;while(U+4<=W.length){let Q=W.readUInt8(U),H=W.readUInt8(U+1),N=W.readUInt16BE(U+2),A=W.slice(U+4,U+N),q=Vr[Q.toString()];if(q)V.push(new q(H,A));else throw Error("unknown");U+=N+NU(N)}return[Y,G,X,V]}function Qr(W,Y,G,X){let J=Buffer.alloc(8);J.writeUInt16BE(W,0),J.writeUInt16BE(Y,2),J.writeUInt32BE(G,4);let Z=X.bytes,V=TS(Buffer.concat([J,Buffer.from("\x00\x00\x00\x00"),Z])),U=Buffer.alloc(4);return U.writeUInt32LE(V,0),Buffer.concat([J,U,Z])}function Hr(W){return W.map((Y,G)=>[G,Y])}function Nr(W){return W.reduce((Y,G)=>{return Y[G]=new p0,Y},{})}var iO=class W{constructor(Y,G,X,J){this.requestSequence=Y,this.responseSequence=G,this.lastTsn=X,this.streams=J}static type=13;get type(){return W.type}get bytes(){let Y=Buffer.from(s1.Pack("!LLL",[this.requestSequence,this.responseSequence,this.lastTsn]));return Buffer.concat([Y,...this.streams.map((G)=>Buffer.from(s1.Pack("!H",[G])))])}static parse(Y){let[G,X,J]=s1.Unpack("!LLL",Y),Z=[];for(let V=12;V<Y.length;V+=2)Z.push(s1.Unpack("!H",Y.slice(V))[0]);return new W(G,X,J,Z)}},Yx=class W{constructor(Y,G){this.requestSequence=Y,this.newStreams=G}static type=17;get type(){return W.type}get bytes(){return Buffer.from(s1.Pack("!LHH",[this.requestSequence,this.newStreams,0]))}static parse(Y){let[G,X]=s1.Unpack("!LHH",Y);return new W(G,X)}},xN={ReconfigResultSuccessPerformed:1,BadSequenceNumber:5},dN=class W{constructor(Y,G){this.responseSequence=Y,this.result=G}static type=16;get type(){return W.type}get bytes(){return Buffer.from(s1.Pack("!LL",[this.responseSequence,this.result]))}static parse(Y){let[G,X]=s1.Unpack("!LL",Y);return new W(G,X)}},aF={13:iO,16:dN,17:Yx},a1=M1("werift/sctp/sctp"),qr=24,Ar=60,sF=65535,e5=1200,fV=1,Gx=2,rO=4,tF=10,Ir=8,eF=0.125,WS=0.25,YS=3,zr=1,wr=60,Uq=4294967296,jr=200,Or=30,GS=135,XS=7,JS=32776,ZS=49152,Kr=["new","closed","connected","connecting"],Dr=class W{constructor(Y,G=5000){this.transport=Y,this.port=G,this.localPort=this.port,this.transport.onData=(X)=>{this.handleData(X)}}flush=new p0;stateChanged=Nr(Kr);onReconfigStreams=new p0;onReceive=new p0;onSackReceived=async()=>{};associationState=1;started=!1;state="new";isServer=!0;isStopping=!1;isClosed=!1;hmacKey=Xr(16);localPartialReliability=!0;localPort;localVerificationTag=CO();remoteExtensions=[];remotePartialReliability=!0;remotePort;remoteVerificationTag=0;advertisedRwnd=1048576;peerAdvertisedRwnd=this.advertisedRwnd;get peerRwnd(){return Math.max(0,this.peerAdvertisedRwnd-this.flightSize)}inboundStreams={};_inboundStreamsCount=0;_inboundStreamsMax=sF;lastReceivedTsn;sackDuplicates=[];sackMisOrdered=new Set;sackNeeded=!1;sackPacketCount=0;sackHasNewDataInPacket=!1;sackImmediate=!1;sackTimeout;cwnd=3*e5;fastRecoveryExit;fastRecoveryTransmit=!1;forwardTsnChunk;flightSize=0;outboundQueue=[];outboundStreamSeq={};_outboundStreamsCount=sF;localTsn=Number(CO());lastSackedTsn=OY(this.localTsn);advancedPeerAckTsn=OY(this.localTsn);partialBytesAcked=0;sentQueue=[];transmitting=!1;transmitRequested=!1;reconfigRequestSeq=this.localTsn;reconfigResponseSeq=0;reconfigRequest;reconfigQueue=[];srtt;rttvar;rto=YS;timer1Handle;timer1Chunk;timer1Failures=0;timer2Handle;timer2Chunk;timer2Failures=0;timer3Handle;timerReconfigHandle;timerReconfigFailures=0;timerHeartbeatHandle;heartbeatInterval=Or;ssthresh;get isStopped(){return this.isStopping||this.isClosed}get maxChannels(){if(this._inboundStreamsCount>0)return Math.min(this._inboundStreamsCount,this._outboundStreamsCount);return}static client(Y,G=5000){let X=new W(Y,G);return X.isServer=!1,X}static server(Y,G=5000){let X=new W(Y,G);return X.isServer=!0,X}async handleData(Y){if(this.isStopped)return;let G,[,,X,J]=Ur(Y);if(J.filter((V)=>V.type===fN.type).length>0){if(J.length!=1)throw Error();G=0}else G=this.localVerificationTag;if(X!==G)return;this.sackHasNewDataInPacket=!1;for(let V of J)await this.receiveChunk(V);if(this.sackNeeded){if(this.sackHasNewDataInPacket)this.sackPacketCount++;if(this.sackPacketCount>=2)this.sackImmediate=!0;await this.scheduleSack()}}async scheduleSack(){if(this.isStopped)return;if(!this.sackNeeded)return;if(this.sackImmediate){if(this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;await this.sendSack();return}if(this.sackTimeout)return;this.sackTimeout=setTimeout(()=>{this.sackTimeout=void 0,this.sendSack().catch((Y)=>{a1("send delayed sack failed",Y.message)})},jr)}async sendSack(){if(this.isStopped)return;if(!this.sackNeeded)return;let Y=[],G;[...this.sackMisOrdered].sort().forEach((J)=>{let Z=(J-this.lastReceivedTsn)%Uq;if(J===G)Y[Y.length-1][1]=Z;else Y.push([Z,Z]);G=yX(J)});let X=new nO(0,void 0);X.cumulativeTsn=this.lastReceivedTsn,X.advertisedRwnd=Math.max(0,this.advertisedRwnd),X.duplicates=[...this.sackDuplicates],X.gaps=Y,await this.sendChunk(X).catch((J)=>{a1("send sack failed",J.message)}),this.sackDuplicates=[],this.sackNeeded=!1,this.sackPacketCount=0,this.sackImmediate=!1}async receiveChunk(Y){switch(Y.type){case pN.type:this.receiveDataChunk(Y);break;case fN.type:{if(!this.isServer)return;let G=Y;a1("receive init",G),this.lastReceivedTsn=OY(G.initialTsn),this.reconfigResponseSeq=OY(G.initialTsn),this.remoteVerificationTag=G.initiateTag,this.ssthresh=G.advertisedRwnd,this.peerAdvertisedRwnd=G.advertisedRwnd,this.getExtensions(G.params),this._inboundStreamsCount=Math.min(G.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,G.inboundStreams);let X=new fO;X.initiateTag=this.localVerificationTag,X.advertisedRwnd=this.advertisedRwnd,X.outboundStreams=this._outboundStreamsCount,X.inboundStreams=this._inboundStreamsCount,X.initialTsn=this.localTsn,this.setExtensions(X.params);let J=Date.now()/1000,Z=Buffer.from(s1.Pack("!L",[J]));Z=Buffer.concat([Z,rF("sha1",this.hmacKey).update(Z).digest()]),X.params.push([XS,Z]),a1("send initAck",X),await this.sendChunk(X).catch((V)=>{a1("send initAck failed",V.message)})}break;case fO.type:{if(this.associationState!=2)return;let G=Y;this.timer1Cancel(),this.lastReceivedTsn=OY(G.initialTsn),this.reconfigResponseSeq=OY(G.initialTsn),this.remoteVerificationTag=G.initiateTag,this.ssthresh=G.advertisedRwnd,this.peerAdvertisedRwnd=G.advertisedRwnd,this.getExtensions(G.params),this._inboundStreamsCount=Math.min(G.outboundStreams,this._inboundStreamsMax),this._outboundStreamsCount=Math.min(this._outboundStreamsCount,G.inboundStreams);let X=new cO;for(let[J,Z]of G.params)if(J===XS){X.body=Z;break}await this.sendChunk(X).catch((J)=>{a1("send echo failed",J.message)}),this.timer1Start(X),this.setState(3)}break;case nO.type:await this.receiveSackChunk(Y);break;case dO.type:{let G=new r2;G.params=Y.params,await this.sendChunk(G).catch((X)=>{a1("send heartbeat ack failed",X.message)})}break;case lO.type:this.setState(1);break;case a2.type:{this.timer2Cancel(),this.setState(7);let G=new s2;await this.sendChunk(G).catch((X)=>{a1("send shutdown ack failed",X.message)}),this.t2Start(G),this.setState(6)}break;case lN.type:a1("ErrorChunk",Y.descriptions);break;case cO.type:{if(!this.isServer)return;let X=Y.body,J=rF("sha1",this.hmacKey).update(X.slice(0,4)).digest();if(X?.length!=qr||!X.slice(4).equals(J)){a1("x State cookie is invalid");return}let Z=Date.now()/1000,V=s1.Unpack("!L",X)[0];if(V<Z-Ar||V>Z){let Q=new lN(0,void 0);Q.params.push([lN.CODE.StaleCookieError,Buffer.concat([...Array(8)].map(()=>Buffer.from("\x00")))]),await this.sendChunk(Q).catch((H)=>{a1("send errorChunk failed",H.message)});return}let U=new pO;await this.sendChunk(U).catch((Q)=>{a1("send cookieAck failed",Q.message)}),this.setState(4)}break;case pO.type:{if(this.associationState!=3)return;this.timer1Cancel(),this.setState(4)}break;case t2.type:{if(this.associationState!=8)return;this.timer2Cancel(),this.setState(1)}break;case oO.type:{if(this.associationState!=4)return;let G=Y;for(let[X,J]of G.params){let Z=aF[X];if(Z)await this.receiveReconfigParam(Z.parse(J))}}break;case cN.type:this.receiveForwardTsnChunk(Y);break}}getExtensions(Y){for(let[G,X]of Y)if(G===ZS)this.remotePartialReliability=!0;else if(G===JS)this.remoteExtensions=[...X]}async receiveReconfigParam(Y){switch(a1("receiveReconfigParam",aF[Y.type]),Y.type){case iO.type:{let G=Y,X=new dN(G.requestSequence,xN.ReconfigResultSuccessPerformed);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(X),await Promise.all(G.streams.map(async(J)=>{if(delete this.inboundStreams[J],this.outboundStreamSeq[J]){if(!this.reconfigQueue.includes(J))this.reconfigQueue.push(J)}})),await this.transmitReconfigRequest(),this.onReconfigStreams.execute(G.streams)}break;case dN.type:{let G=Y;if(G.result!==xN.ReconfigResultSuccessPerformed)a1("OutgoingSSNResetRequestParam failed",Object.keys(xN).find((X)=>xN[X]===G.result));else if(G.responseSequence===this.reconfigRequest?.requestSequence){let X=this.reconfigRequest.streams.map((J)=>{return delete this.outboundStreamSeq[J],J});if(this.onReconfigStreams.execute(X),this.reconfigRequest=void 0,this.timerReconfigCancel(),this.rto=YS,this.timerReconfigFailures=0,this.reconfigQueue.length>0)await this.transmitReconfigRequest()}}break;case Yx.type:{let G=Y;this._inboundStreamsCount+=G.newStreams;let X=new dN(G.requestSequence,1);this.reconfigResponseSeq=G.requestSequence,await this.sendReconfigParam(X)}break}}receiveDataChunk(Y){if(this.sackNeeded=!0,this.markReceived(Y.tsn)){this.sackImmediate=!0;return}if(this.sackHasNewDataInPacket=!0,this.sackImmediate=!0,(Y.flags&fV)===0)this.sackImmediate=!0;if(this.sackMisOrdered.size>0)this.sackImmediate=!0;let G=this.getInboundStream(Y.streamId);G.addChunk(Y),this.advertisedRwnd-=Y.userData.length;for(let X of G.popMessages())this.advertisedRwnd+=X[2].length,this.receive(...X)}async receiveSackChunk(Y){if(f4(this.lastSackedTsn,Y.cumulativeTsn))return;let G=Date.now()/1000;this.lastSackedTsn=Y.cumulativeTsn;let X=this.flightSize>=this.cwnd,J=0,Z=0;while(this.sentQueue.length>0&&mV(this.lastSackedTsn,this.sentQueue[0].tsn)){let U=this.sentQueue.shift();if(J++,!U?.acked)Z+=U.bookSize,this.flightSizeDecrease(U);if(J===1&&U.sentCount===1)this.updateRto(G-U.sentTime)}if(!this.sentQueue.length)this.sentQueue=[];let V=!1;if(Y.gaps.length>0){let U=new Set,Q;Y.gaps.forEach((N)=>{for(let A=N[0];A<N[1]+1;A++)Q=(Y.cumulativeTsn+A)%Uq,U.add(Q)});let H=Y.cumulativeTsn;for(let N of this.sentQueue){if(f4(N.tsn,Q))break;if(U.has(N.tsn)&&!N.acked)Z+=N.bookSize,N.acked=!0,this.flightSizeDecrease(N),H=N.tsn}for(let N of this.sentQueue){if(f4(N.tsn,H))break;if(!U.has(N.tsn)){if(N.misses++,N.misses===3){if(N.misses=0,!this.maybeAbandon(N))N.retransmit=!0;N.acked=!1,this.flightSizeDecrease(N),V=!0}}}}if(this.fastRecoveryExit===void 0){if(J&&X){if(this.cwnd<=this.ssthresh)this.cwnd+=Math.min(Z,e5);else if(this.partialBytesAcked+=Z,this.partialBytesAcked>=this.cwnd)this.partialBytesAcked-=this.cwnd,this.cwnd+=e5}if(V)this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*e5),this.cwnd=this.ssthresh,this.partialBytesAcked=0,this.fastRecoveryExit=this.sentQueue[this.sentQueue.length-1].tsn,this.fastRecoveryTransmit=!0}else if(mV(Y.cumulativeTsn,this.fastRecoveryExit))this.fastRecoveryExit=void 0;if(this.sentQueue.length===0)this.timer3Cancel();else if(J>0)this.timer3Restart();this.peerAdvertisedRwnd=Y.advertisedRwnd,this.updateAdvancedPeerAckPoint(),await this.onSackReceived(),await this.transmit()}receiveForwardTsnChunk(Y){if(this.sackNeeded=!0,this.sackImmediate=!0,mV(this.lastReceivedTsn,Y.cumulativeTsn))return;let G=(X)=>f4(X,this.lastReceivedTsn);this.lastReceivedTsn=Y.cumulativeTsn,this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let X of[...this.sackMisOrdered].sort())if(X===yX(this.lastReceivedTsn))this.lastReceivedTsn=X;else break;this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G));for(let[X,J]of Y.streams){let Z=this.getInboundStream(X);Z.streamSequenceNumber=T9(J,1);for(let V of Z.popMessages())this.advertisedRwnd+=V[2].length,this.receive(...V)}Object.values(this.inboundStreams).forEach((X)=>{this.advertisedRwnd+=X.pruneChunks(this.lastReceivedTsn)})}updateRto(Y){if(!this.srtt)this.rttvar=Y/2,this.srtt=Y;else this.rttvar=(1-WS)*this.rttvar+WS*Math.abs(this.srtt-Y),this.srtt=(1-eF)*this.srtt+eF*Y;this.rto=Math.max(zr,Math.min(this.srtt+4*this.rttvar,wr))}receive(Y,G,X){this.onReceive.execute(Y,G,X)}getInboundStream(Y){if(!this.inboundStreams[Y])this.inboundStreams[Y]=new Cr;return this.inboundStreams[Y]}markReceived(Y){if(mV(this.lastReceivedTsn,Y)||this.sackMisOrdered.has(Y))return this.sackDuplicates.push(Y),!0;this.sackMisOrdered.add(Y);for(let X of[...this.sackMisOrdered].sort())if(X===yX(this.lastReceivedTsn))this.lastReceivedTsn=X;else break;let G=(X)=>f4(X,this.lastReceivedTsn);return this.sackDuplicates=this.sackDuplicates.filter(G),this.sackMisOrdered=new Set([...this.sackMisOrdered].filter(G)),!1}send=async(Y,G,X,{expiry:J,maxRetransmits:Z,ordered:V}={expiry:void 0,maxRetransmits:void 0,ordered:!0})=>{let U=V?this.outboundStreamSeq[Y]||0:0,Q=Math.ceil(X.length/e5),H=0,N=[];for(let A=0;A<Q;A++){let q=new pN(0,void 0);if(q.flags=0,!V)q.flags=rO;if(A===0)q.flags|=Gx;if(A===Q-1)q.flags|=fV;q.tsn=this.localTsn,q.streamId=Y,q.streamSeqNum=U,q.protocol=G,q.userData=X.slice(H,H+e5),q.bookSize=q.userData.length,q.expiry=J,q.maxRetransmits=Z,H+=e5,this.localTsn=yX(this.localTsn),N.push(q)}if(N.forEach((A)=>{this.outboundQueue.push(A)}),V)this.outboundStreamSeq[Y]=T9(U,1);await this.transmit();while(this.outboundQueue.length)await this.flush.asPromise()};async transmit(){if(this.isStopped)return;if(this.transmitting){this.transmitRequested=!0;return}this.transmitting=!0;try{do this.transmitRequested=!1,await this.transmitOnce();while(this.transmitRequested)}finally{this.transmitting=!1}}async transmitOnce(){if(this.isStopped)return;if(this.forwardTsnChunk){if(await this.sendChunk(this.forwardTsnChunk).catch((J)=>{a1("send forwardTsn failed",J.message)}),this.forwardTsnChunk=void 0,!this.timer3Handle)this.timer3Start()}let Y=this.fastRecoveryExit!=null?2*e5:4*e5,G=Math.min(this.flightSize+Y,this.cwnd),X=!0;for(let J of this.sentQueue){if(J.retransmit){if(this.fastRecoveryTransmit)this.fastRecoveryTransmit=!1;else if(this.flightSize>=G)break;if(this.flightSizeIncrease(J),J.misses=0,J.retransmit=!1,J.sentCount++,await this.sendChunk(J).catch((Z)=>{a1("send data failed",Z.message)}),X)this.timer3Restart()}X=!1}while(this.outboundQueue.length>0&&this.flightSize<G&&this.peerRwnd>0){let J=this.outboundQueue.shift();if(!J)break;if(J.bookSize>this.peerRwnd&&this.flightSize>0){this.outboundQueue.unshift(J);break}if(this.sentQueue.push(J),this.flightSizeIncrease(J),J.sentCount++,J.sentTime=Date.now()/1000,await this.sendChunk(J).catch((Z)=>{a1("send data outboundQueue failed",Z.message)}),!this.timer3Handle)this.timer3Start()}if(!this.outboundQueue.length)this.outboundQueue=[];this.flush.execute()}async transmitReconfigRequest(){if(this.reconfigQueue.length>0&&this.associationState===4&&!this.reconfigRequest){let Y=[...new Set(this.reconfigQueue)],G=Y.slice(0,GS);this.reconfigQueue=Y.slice(GS);let X=new iO(this.reconfigRequestSeq,this.reconfigResponseSeq,OY(this.localTsn),G);this.reconfigRequestSeq=yX(this.reconfigRequestSeq),this.reconfigRequest=X,await this.sendReconfigParam(X),this.timerReconfigHandleStart()}}async sendReconfigParam(Y){a1("sendReconfigParam",Y);let G=new oO;G.params.push([Y.type,Y.bytes]),await this.sendChunk(G).catch((X)=>{a1("send reconfig failed",X.message)})}async sendResetRequest(Y){a1("sendResetRequest",Y);let G=new pN(0,void 0);if(G.streamId=Y,this.outboundQueue.push(G),!this.timer3Handle)await this.transmit()}flightSizeIncrease(Y){this.flightSize+=Y.bookSize}flightSizeDecrease(Y){this.flightSize=Math.max(0,this.flightSize-Y.bookSize)}timer1Start(Y){if(this.timer1Handle)throw Error();this.timer1Chunk=Y,this.timer1Failures=0,this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1000)}timer1Expired=()=>{if(this.isStopped)return;if(this.timer1Failures++,this.timer1Handle=void 0,this.timer1Failures>Ir)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer1Chunk).catch((Y)=>{a1("send timer1 chunk failed",Y.message)})}),this.isStopped)return;this.timer1Handle=setTimeout(this.timer1Expired,this.rto*1000)}};timer1Cancel(){if(this.timer1Handle)clearTimeout(this.timer1Handle),this.timer1Handle=void 0,this.timer1Chunk=void 0}t2Start(Y){if(this.timer2Handle)throw Error();this.timer2Chunk=Y,this.timer2Failures=0,this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1000)}timer2Expired=()=>{if(this.isStopped)return;if(this.timer2Failures++,this.timer2Handle=void 0,this.timer2Failures>tF)this.setState(1);else{if(setImmediate(()=>{if(this.isStopped)return;this.sendChunk(this.timer2Chunk).catch((Y)=>{a1("send timer2Chunk failed",Y.message)})}),this.isStopped)return;this.timer2Handle=setTimeout(this.timer2Expired,this.rto*1000)}};timer2Cancel(){if(this.timer2Handle)clearTimeout(this.timer2Handle),this.timer2Handle=void 0,this.timer2Chunk=void 0}timer3Start(){if(this.isStopped)return;if(this.timer3Handle)throw Error();this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1000)}timer3Restart(){if(this.isStopped)return;this.timer3Cancel(),this.timer3Handle=setTimeout(this.timer3Expired,this.rto*1000)}timer3Expired=()=>{if(this.isStopped)return;this.timer3Handle=void 0,this.sentQueue.forEach((Y)=>{if(!this.maybeAbandon(Y))Y.retransmit=!0}),this.updateAdvancedPeerAckPoint(),this.fastRecoveryExit=void 0,this.flightSize=0,this.partialBytesAcked=0,this.ssthresh=Math.max(Math.floor(this.cwnd/2),4*e5),this.cwnd=e5,this.transmit()};timer3Cancel(){if(this.timer3Handle)clearTimeout(this.timer3Handle),this.timer3Handle=void 0}timerReconfigHandleStart(){if(this.isStopped)return;if(this.timerReconfigHandle)return;a1("timerReconfigHandleStart",{rto:this.rto}),this.timerReconfigFailures=0,this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1000)}timerReconfigHandleExpired=async()=>{if(this.isStopped)return;if(this.timerReconfigFailures++,this.rto=Math.ceil(this.rto*1.5),this.timerReconfigFailures>tF)a1("timerReconfigFailures",this.timerReconfigFailures),this.setState(1),this.timerReconfigHandle=void 0;else if(this.reconfigRequest){if(a1("timerReconfigHandleExpired",this.timerReconfigFailures,this.rto),await this.sendReconfigParam(this.reconfigRequest),this.isStopped)return;this.timerReconfigHandle=setTimeout(this.timerReconfigHandleExpired,this.rto*1000)}};timerReconfigCancel(){if(this.timerReconfigHandle)a1("timerReconfigCancel"),clearTimeout(this.timerReconfigHandle),this.timerReconfigHandle=void 0,this.timerReconfigFailures=0}heartbeatStart(){if(this.timerHeartbeatHandle||this.associationState!==4)return;this.timerHeartbeatHandle=setTimeout(this.timerHeartbeatExpired,(this.rto+this.heartbeatInterval)*1000)}heartbeatRestart(){this.heartbeatCancel(),this.heartbeatStart()}heartbeatCancel(){if(this.timerHeartbeatHandle)clearTimeout(this.timerHeartbeatHandle),this.timerHeartbeatHandle=void 0}timerHeartbeatExpired=async()=>{if(this.timerHeartbeatHandle=void 0,this.associationState!==4)return;if(this.flightSize===0&&this.outboundQueue.length===0){let Y=new dO;Y.params.push([1,Buffer.from(s1.Pack("!L",[Math.floor(Date.now()/1000)]))]),await this.sendChunk(Y).catch((G)=>{a1("send heartbeat failed",G.message)})}this.heartbeatStart()};setHeartbeatInterval(Y){if(Y<=0)throw Error("heartbeat interval must be > 0");this.heartbeatInterval=Y,this.heartbeatRestart()}updateAdvancedPeerAckPoint(){if(f4(this.lastSackedTsn,this.advancedPeerAckTsn))this.advancedPeerAckTsn=this.lastSackedTsn;let Y=0,G={};while(this.sentQueue.length>0&&this.sentQueue[0].abandoned){let X=this.sentQueue.shift();if(this.advancedPeerAckTsn=X.tsn,Y++,!(X.flags&rO))G[X.streamId]=X.streamSeqNum}if(!this.sentQueue.length)this.sentQueue=[];if(Y)this.forwardTsnChunk=new cN(0,void 0),this.forwardTsnChunk.cumulativeTsn=this.advancedPeerAckTsn,this.forwardTsnChunk.streams=Object.entries(G).map(([X,J])=>[Number(X),J])}maybeAbandon(Y){if(Y.abandoned)return!0;if(!(!!Y.maxRetransmits&&Y.maxRetransmits<Y.sentCount||!!Y.expiry&&Y.expiry<Date.now()/1000))return!1;let X=this.sentQueue.findIndex((J)=>J.type===Y.type);for(let J=X;J>=0;J--){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&fV)break}for(let J=X;J<this.sentQueue.length;J++){let Z=this.sentQueue[J];if(Z.abandoned=!0,Z.retransmit=!1,Z.flags&fV)break}return!0}static getCapabilities(){return new Tr(65536)}setRemotePort(Y){this.remotePort=Y}async start(Y){if(!this.started){if(this.started=!0,this.setConnectionState("connecting"),Y)this.setRemotePort(Y);if(!this.isServer)await this.init()}}async init(){let Y=new fN;Y.initiateTag=this.localVerificationTag,Y.advertisedRwnd=this.advertisedRwnd,Y.outboundStreams=this._outboundStreamsCount,Y.inboundStreams=this._inboundStreamsMax,Y.initialTsn=this.localTsn,this.setExtensions(Y.params),a1("send init",Y);try{await this.sendChunk(Y),this.timer1Start(Y),this.setState(2)}catch(G){a1("send init failed",G.message)}}setExtensions(Y){let G=[];if(this.localPartialReliability)Y.push([ZS,Buffer.from("")]),G.push(cN.type);G.push(Jr.type),Y.push([JS,Buffer.from(G)])}async sendChunk(Y){if(this.state==="closed")return;if(this.remotePort===void 0)throw Error("invalid remote port");let G=Qr(this.localPort,this.remotePort,this.remoteVerificationTag,Y);await this.transport.send(G)}setState(Y){if(Y!=this.associationState)this.associationState=Y;if(Y===4)this.isStopping=!1,this.isClosed=!1,this.setConnectionState("connected"),this.heartbeatStart();else if(Y===1){if(this.isClosed=!0,this.timer1Cancel(),this.timer2Cancel(),this.timer3Cancel(),this.timerReconfigCancel(),this.heartbeatCancel(),this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;this.setConnectionState("closed"),this.removeAllListeners()}}setConnectionState(Y){this.state=Y,a1("setConnectionState",Y),this.stateChanged[Y].execute()}async stop(){if(this.isStopped){this.setState(1);return}if(this.isStopping=!0,this.transport.onData=void 0,this.sackTimeout)clearTimeout(this.sackTimeout),this.sackTimeout=void 0;if(this.associationState!==1)await this.abort();this.setState(1),clearTimeout(this.timer1Handle),clearTimeout(this.timer2Handle),clearTimeout(this.timer3Handle),clearTimeout(this.timerReconfigHandle),clearTimeout(this.timerHeartbeatHandle),clearTimeout(this.sackTimeout)}async abort(){let Y=new lO;await this.sendChunk(Y).catch((G)=>{a1("send abort failed",G.message)})}removeAllListeners(){Object.values(this.stateChanged).forEach((Y)=>Y.allUnsubscribe())}},Cr=class{reassembly=[];streamSequenceNumber=0;constructor(){}addChunk(W){if(this.reassembly.length===0||f4(W.tsn,this.reassembly[this.reassembly.length-1].tsn)){this.reassembly.push(W);return}for(let[Y,G]of Hr(this.reassembly)){if(G.tsn===W.tsn)throw Error("duplicate chunk in reassembly");if(f4(G.tsn,W.tsn)){this.reassembly.splice(Y,0,W);break}}}*popMessages(){let W=0,Y,G,X;while(W<this.reassembly.length){let J=this.reassembly[W];if(Y===void 0){if(X=!(J.flags&rO),!(J.flags&Gx))if(X)break;else{W++;continue}if(X&&RS(J.streamSeqNum,this.streamSequenceNumber))break;G=J.tsn,Y=W}else if(J.tsn!==G)if(X)break;else{Y=void 0,W++;continue}if(J.flags&fV){let Z=this.reassembly.slice(Y,W+1).map((U)=>U.userData).reduce((U,Q)=>{return U.push(Q),U.push(Buffer.from("")),U},[]);Z.pop();let V=Buffer.concat(Z);if(this.reassembly=[...this.reassembly.slice(0,Y),...this.reassembly.slice(W+1)],X&&J.streamSeqNum===this.streamSequenceNumber)this.streamSequenceNumber=T9(this.streamSequenceNumber,1);W=Y,yield[J.streamId,J.protocol,V]}else W++;G=yX(G)}}pruneChunks(W){let Y=-1,G=0;for(let[X,J]of this.reassembly.entries())if(mV(W,J.tsn))Y=X,G+=J.userData.length;else break;return this.reassembly=this.reassembly.slice(Y+1),G}},Tr=class{constructor(W){this.maxMessageSize=W}};function OY(W){return(W-1)%Uq}function yX(W){return(W+1)%Uq}var SX=M1("werift:packages/webrtc/src/transport/sctp.ts"),cV=65536,Rr=class W{constructor(Y=5000,G=cV){this.port=Y,this.maxMessageSize=G}dtlsTransport;sctp;onDataChannel=new p0;id=Gr().toString();mid;mLineIndex;bundled=!1;dataChannels={};remoteMaxMessageSize=cV;dataChannelQueue=[];dataChannelId;eventDisposer=[];setDtlsTransport(Y){if(this.dtlsTransport&&this.dtlsTransport.id===Y.id)return;this.eventDisposer.forEach((G)=>G()),this.dtlsTransport=Y,this.sctp=new Dr(new Mr(this.dtlsTransport),this.port),this.eventDisposer=[...[this.sctp.onReceive.subscribe(this.datachannelReceive),this.sctp.onReconfigStreams.subscribe((G)=>{G.forEach((X)=>{let J=this.dataChannels[X];if(!J)return;J.setReadyState("closing"),J.setReadyState("closed"),delete this.dataChannels[X]})}),this.sctp.stateChanged.connected.subscribe(()=>{Object.values(this.dataChannels).forEach((G)=>{if(G.negotiated&&G.readyState!=="open")G.setReadyState("open")}),this.dataChannelFlush()}),this.sctp.stateChanged.closed.subscribe(()=>{Object.values(this.dataChannels).forEach((G)=>{G.setReadyState("closed")}),this.dataChannels={}}),this.dtlsTransport.onStateChange.subscribe((G)=>{if(G==="closed")this.sctp.setState(1)})].map((G)=>G.unSubscribe),()=>this.sctp.onSackReceived=async()=>{}],this.sctp.onSackReceived=async()=>{await this.dataChannelFlush()}}get isServer(){return this.dtlsTransport.iceTransport.role!=="controlling"}channelByLabel(Y){return Object.values(this.dataChannels).find((G)=>G.label===Y)}datachannelReceive=async(Y,G,X)=>{if(G===SN&&X.length>0)switch(SX("DCEP",Y,G,X),X[0]){case bF:{if(X.length<12){SX("DATA_CHANNEL_OPEN data.length not enough");return}if(!Object.keys(this.dataChannels).includes(Y.toString())){let[,Z,,V,U,Q]=s1.Unpack("!BBHLHH",X),H=12,N=X.slice(H,H+U).toString("utf8");H+=U;let A=X.slice(H,H+Q).toString("utf8");SX("DATA_CHANNEL_OPEN",{channelType:Z,reliability:V,streamId:Y,label:N,protocol:A});let q=(Z&3)===1?V:void 0,z=(Z&3)===2?V:void 0,w=new S2({label:N,ordered:(Z&128)===0,maxPacketLifeTime:z,maxRetransmits:q,protocol:A,id:Y}),D=new F2(this,w,!1);D.isCreatedByRemote=!0,this.dataChannels[Y]=D,this.onDataChannel.execute(D),D.setReadyState("open")}else SX("datachannel already opened","retransmit ack");let J=this.dataChannels[Y];this.dataChannelQueue.push([J,SN,Buffer.from(s1.Pack("!B",[hF]))]),await this.dataChannelFlush()}break;case hF:{SX("DATA_CHANNEL_ACK",Y,G);let J=this.dataChannels[Y];if(!J)throw Error("channel not found");J.setReadyState("open")}break}else{let J=this.dataChannels[Y];if(J){let Z=(()=>{switch(G){case mF:return X.toString("utf8");case Di:return"";case fF:return X;case Ci:return Buffer.from([]);default:throw Error()}})();if(J.messagesReceived++,J.bytesReceived+=X.length,J.onMessage.execute(Z),J.emit("message",{data:Z}),J.onmessage)J.onmessage({data:Z})}}};dataChannelAddNegotiated(Y){if(Y.id==null)throw Error();if(this.dataChannels[Y.id])throw Error();if(this.dataChannels[Y.id]=Y,this.sctp.associationState===4)Y.setReadyState("open")}dataChannelOpen(Y){if(Y.id){if(this.dataChannels[Y.id])throw Error(`Data channel with ID ${Y.id} already registered`);this.dataChannels[Y.id]=Y}let G=Ki,X=0,J=0;if(!Y.ordered)G=128;if(Y.maxRetransmits)G=1,J=Y.maxRetransmits;else if(Y.maxPacketLifeTime)G=2,J=Y.maxPacketLifeTime;let Z=s1.Pack("!BBHLHH",[bF,G,X,J,Y.label.length,Y.protocol.length]),V=Buffer.concat([Buffer.from(Z),Buffer.from(Y.label,"utf8"),Buffer.from(Y.protocol,"utf8")]);this.dataChannelQueue.push([Y,SN,V]),this.dataChannelFlush()}async dataChannelFlush(){if(this.sctp.associationState!=4)return;while(this.dataChannelQueue.length>0){let[Y,G,X]=this.dataChannelQueue.shift(),J=Y.id;if(J===void 0){J=this.dataChannelId;while(Object.keys(this.dataChannels).includes(J.toString()))J+=2;this.dataChannels[J]=Y,Y.setId(J)}if(G===SN)await this.sctp.send(J,G,X,{ordered:!0});else{let Z=Y.maxPacketLifeTime?Date.now()+Y.maxPacketLifeTime/1000:void 0;await this.sctp.send(J,G,X,{expiry:Z,maxRetransmits:Y.maxRetransmits,ordered:Y.ordered}),Y.addBufferedAmount(-X.length)}}this.dataChannelQueue=[]}assertSendableMessageSize(Y){if(this.remoteMaxMessageSize!==0&&Y>this.remoteMaxMessageSize)throw Error(`max-message-size exceeded: ${Y} > ${this.remoteMaxMessageSize}`)}datachannelSend=(Y,G)=>{let X=Buffer.isBuffer(G)?G:Buffer.from(G),J=Vi(G);if(this.assertSendableMessageSize(J),Y.addBufferedAmount(J),this.dataChannelQueue.push(typeof G==="string"?[Y,mF,X]:[Y,fF,X]),this.sctp.associationState!==4)SX("sctp not established",this.sctp.associationState);return this.dataChannelFlush(),J};getCapabilities(){return W.getCapabilities(this.maxMessageSize)}static getCapabilities(Y=cV){return new Xx(Y)}setRemoteMaxMessageSize(Y){this.remoteMaxMessageSize=Y??cV}setRemotePort(Y){this.sctp.setRemotePort(Y)}async start(Y){if(this.isServer)this.dataChannelId=0;else this.dataChannelId=1;this.sctp.isServer=this.isServer,await this.sctp.start(Y)}async stop(){this.dtlsTransport.dataReceiver=()=>{},await this.sctp.stop()}dataChannelClose(Y){if(!["closing","closed"].includes(Y.readyState))if(Y.setReadyState("closing"),this.sctp.associationState===4){if(!this.sctp.reconfigQueue.includes(Y.id))this.sctp.reconfigQueue.push(Y.id);if(this.sctp.reconfigQueue.length===1)this.sctp.transmitReconfigRequest()}else{if(this.dataChannelQueue=this.dataChannelQueue.filter((G)=>G[0].id!==Y.id),this.sctp.reconfigQueue=this.sctp.reconfigQueue.filter((G)=>G!==Y.id),Y.id)delete this.dataChannels[Y.id];Y.setReadyState("closed")}}},Xx=class{constructor(W){this.maxMessageSize=W}},Mr=class{constructor(W){this.dtls=W}set onData(W){this.dtls.dataReceiver=W}send=(W)=>{return this.dtls.sendData(W)};close(){}},oN=class W{version=0;origin;name="-";time="0 0";host;group=[];extMapAllowMixed=!0;msidSemantic=[];media=[];type;dtlsRole;iceOptions;iceLite;icePassword;iceUsernameFragment;dtlsFingerprints=[];static parse(Y){let[G,X]=Pr(Y),J=new W;G.forEach((V)=>{if(V.startsWith("v="))J.version=Number.parseInt(V.slice(2),10);else if(V.startsWith("o="))J.origin=V.slice(2);else if(V.startsWith("s="))J.name=V.slice(2);else if(V.startsWith("c="))J.host=jO(V.slice(2));else if(V.startsWith("t="))J.time=V.slice(2);else if(V.startsWith("a=")){let[U,Q]=OO(V);switch(U){case"fingerprint":{let[H,N]=Q?.split(" ")||[];J.dtlsFingerprints.push(new bO(H,N))}break;case"ice-lite":J.iceLite=!0;break;case"ice-options":J.iceOptions=Q;break;case"ice-pwd":J.icePassword=Q;break;case"ice-ufrag":J.iceUsernameFragment=Q;break;case"group":KO(J.group,Q);break;case"msid-semantic":KO(J.msidSemantic,Q);break;case"setup":J.dtlsRole=pF[Q];break;case"extmap-allow-mixed":J.extMapAllowMixed=!0;break}}});let Z=J.group.find((V)=>V.semantic==="BUNDLE");return X.forEach((V)=>{let Q=V[0].match(/^m=([^ ]+) ([0-9]+) ([A-Z/]+) (.+)/);if(!Q)throw Error("m line not found");let H=Q[1],N=Q[4].split(" "),A=["audio","video"].includes(H)?N.map((w)=>Number(w)):void 0,q=new aO(H,Number.parseInt(Q[2]),Q[3],A||N);if(q.dtlsParams=new mO([...J.dtlsFingerprints],J.dtlsRole),q.iceParams=new i2({iceLite:J.iceLite,usernameFragment:J.iceUsernameFragment,password:J.icePassword}),q.iceOptions=J.iceOptions,J.media.push(q),V.slice(1).forEach((w)=>{if(w.startsWith("c="))q.host=jO(w.slice(2));else if(w.startsWith("a=")){let[D,T]=OO(w);switch(D){case"candidate":if(!T)throw Error();q.iceCandidates.push(Zx(T));break;case"end-of-candidates":q.iceCandidatesComplete=!0;break;case"extmap":{let[x,g]=T.split(" ");if(x.includes("/"))[x]=x.split("/");q.rtp.headerExtensions.push(new Qi({id:Number.parseInt(x),uri:g}))}break;case"fingerprint":{if(!T)throw Error();let[x,g]=T.split(" ");q.dtlsParams?.fingerprints.push(new bO(x,g))}break;case"ice-options":q.iceOptions=T;break;case"ice-pwd":q.iceParams.password=T;break;case"ice-ufrag":q.iceParams.usernameFragment=T;break;case"ice-lite":q.iceParams.iceLite=!0;break;case"max-message-size":q.sctpCapabilities=new Xx(Number.parseInt(T,10));break;case"mid":q.rtp.muxId=T;break;case"msid":q.msid=T;break;case"rtcp":{let[x,g]=m4(T," ");q.rtcpPort=Number.parseInt(x),q.rtcpHost=jO(g)}break;case"rtcp-mux":q.rtcpMux=!0;break;case"setup":q.dtlsParams.role=pF[T];break;case"recvonly":case"sendonly":case"sendrecv":case"inactive":q.direction=D;break;case"rtpmap":{let[x,g]=m4(T," "),[f,y,p]=g.split("/"),b;if(q.kind==="audio")b=p?Number.parseInt(p):1;let m=new EY({mimeType:q.kind+"/"+f,channels:b,clockRate:Number.parseInt(y),payloadType:Number.parseInt(x)});q.rtp.codecs.push(m)}break;case"sctpmap":{if(!T)throw Error();let[x,g]=m4(T," ");q.sctpMap[Number.parseInt(x)]=g,q.sctpPort=Number.parseInt(x)}break;case"sctp-port":if(!T)throw Error();q.sctpPort=Number.parseInt(T);break;case"ssrc":{let[x,g]=m4(T," "),f=Number.parseInt(x),[y,p]=m4(g,":"),b=q.ssrc.find((m)=>m.ssrc===f);if(!b)b=new tO({ssrc:f}),q.ssrc.push(b);if(g2.includes(y))b[y]=p}break;case"ssrc-group":KO(q.ssrcGroup,T);break;case"rid":{let[x,g]=m4(T," ");q.simulcastParameters.push(new x2({rid:x,direction:g}))}break}}}),!q.iceParams.usernameFragment||!q.iceParams.password){if(q.rtp.muxId&&Z&&Z.items.includes(q.rtp.muxId))for(let w=0;w<Z.items.length;w++){if(!Z.items.includes(w.toString()))continue;let D=J.media[w];if(D.iceParams?.usernameFragment&&D.iceParams.password){q.iceParams={...D.iceParams};break}}}if(!q.dtlsParams.role)q.dtlsParams=void 0;let z=(w)=>q.rtp.codecs.find((D)=>D.payloadType===w);V.slice(1).forEach((w)=>{if(w.startsWith("a=")){let[D,T]=OO(w);if(D==="fmtp"){let[x,g]=m4(T," "),f=z(Number(x));f.parameters=g}else if(D==="rtcp-fb"){let[x,g,f]=T.split(" ");q.rtp.codecs.forEach((y)=>{if(["*",y.payloadType.toString()].includes(x))y.rtcpFeedback.push(new Hi({type:g,parameter:f}))})}}})}),J}webrtcTrackId(Y){if(Y.msid?.includes(" ")){let G=Y.msid.split(" ");for(let X of this.msidSemantic)if(X.semantic==="WMS"&&(X.items.includes(G[0])||X.items.includes("*")))return G[1]}return}get string(){let Y=[`v=${this.version}`,`o=${this.origin}`,`s=${this.name}`];if(this.host)Y.push(`c=${sO(this.host)}`);if(Y.push(`t=${this.time}`),this.group.forEach((J)=>Y.push(`a=group:${J.str}`)),this.extMapAllowMixed)Y.push("a=extmap-allow-mixed");this.msidSemantic.forEach((J)=>Y.push(`a=msid-semantic:${J.str}`));let G=this.media.map((J)=>J.toString()).join("");return Y.join(`\r
|
|
243
243
|
`)+`\r
|
|
244
244
|
`+G}toJSON(){return new Lr(this.string,this.type)}toSdp(){return{type:this.type,sdp:this.string}}},aO=class{constructor(W,Y,G,X){this.kind=W,this.port=Y,this.profile=G,this.fmt=X}host;direction;msid;rtcpPort;rtcpHost;rtcpMux=!1;ssrc=[];ssrcGroup=[];rtp={codecs:[],headerExtensions:[]};sctpCapabilities;sctpMap={};sctpPort;dtlsParams;iceParams;iceCandidates=[];iceCandidatesComplete=!1;iceOptions;simulcastParameters=[];toString(){let W=[];if(W.push(`m=${this.kind} ${this.port} ${this.profile} ${this.fmt.map((Y)=>Y.toString()).join(" ")}`),this.host)W.push(`c=${sO(this.host)}`);if(this.iceCandidates.forEach((Y)=>{W.push(`a=candidate:${Jx(Y)}`)}),this.iceCandidatesComplete)W.push("a=end-of-candidates");if(this.iceParams?.usernameFragment)W.push(`a=ice-ufrag:${this.iceParams.usernameFragment}`);if(this.iceParams?.password)W.push(`a=ice-pwd:${this.iceParams.password}`);if(this.iceParams?.iceLite)W.push("a=ice-lite");if(this.iceOptions)W.push(`a=ice-options:${this.iceOptions}`);if(this.dtlsParams)this.dtlsParams.fingerprints.forEach((Y)=>{W.push(`a=fingerprint:${Y.algorithm} ${Y.value}`)}),W.push(`a=setup:${gO[this.dtlsParams.role]}`);if(this.direction)W.push(`a=${this.direction}`);if(this.rtp.muxId)W.push(`a=mid:${this.rtp.muxId}`);if(this.msid)W.push(`a=msid:${this.msid}`);if(this.rtcpPort&&this.rtcpHost){if(W.push(`a=rtcp:${this.rtcpPort} ${sO(this.rtcpHost)}`),this.rtcpMux)W.push("a=rtcp-mux")}if(this.ssrcGroup.forEach((Y)=>{W.push(`a=ssrc-group:${Y.str}`)}),this.ssrc.forEach((Y)=>{g2.forEach((G)=>{let X=Y[G];if(X!==void 0)W.push(`a=ssrc:${Y.ssrc} ${G}:${X}`)})}),this.rtp.codecs.forEach((Y)=>{if(W.push(`a=rtpmap:${Y.payloadType} ${Y.str}`),Y.rtcpFeedback.forEach((G)=>{let X=G.type;if(G.parameter)X+=` ${G.parameter}`;W.push(`a=rtcp-fb:${Y.payloadType} ${X}`)}),Y.parameters)W.push(`a=fmtp:${Y.payloadType} ${Y.parameters}`)}),Object.keys(this.sctpMap).forEach((Y)=>{let G=this.sctpMap[Number(Y)];W.push(`a=sctpmap:${Y} ${G}`)}),this.sctpPort)W.push(`a=sctp-port:${this.sctpPort}`);if(this.sctpCapabilities)W.push(`a=max-message-size:${this.sctpCapabilities.maxMessageSize}`);if(this.rtp.headerExtensions.forEach((Y)=>W.push(`a=extmap:${Y.id} ${Y.uri}`)),this.simulcastParameters.length){this.simulcastParameters.forEach((J)=>{W.push(`a=rid:${J.rid} ${J.direction}`)});let Y="a=simulcast:",G=this.simulcastParameters.filter((J)=>J.direction==="recv");if(G.length)Y+=`recv ${G.map((J)=>J.rid).join(";")} `;let X=this.simulcastParameters.filter((J)=>J.direction==="send");if(X.length)Y+=`send ${X.map((J)=>J.rid).join(";")}`;W.push(Y)}return W.join(`\r
|
|
245
245
|
`)+`\r
|
|
246
246
|
`}},oV=class{constructor(W,Y){this.semantic=W,this.items=Y}get str(){return`${this.semantic} ${this.items.join(" ")}`}};function jO(W){let Y=W.match(/^IN (IP4|IP6) ([^ ]+)$/);if(!Y)throw Error("exception");return Y[2]}function sO(W){return`IN IP${li(W)?4:6} ${W}`}function Jx(W){let Y=`${W.foundation} ${W.component} ${W.protocol} ${W.priority} ${W.ip} ${W.port} typ ${W.type}`;if(W.relatedAddress!=null)Y+=` raddr ${W.relatedAddress}`;if(W.relatedPort!=null)Y+=` rport ${W.relatedPort}`;if(W.tcpType!=null)Y+=` tcptype ${W.tcpType}`;if(W.generation!=null)Y+=` generation ${W.generation}`;if(W.ufrag!=null)Y+=` ufrag ${W.ufrag}`;return Y}function Pr(W){let Y=[],G=[],X=W.split(`\r
|
|
247
247
|
`);if(X.length===1)X=W.split(`
|
|
248
|
-
`);return X.forEach((J)=>{if(J.startsWith("m="))G.push([J]);else if(G.length>0)G[G.length-1].push(J);else Y.push(J)}),[Y,G]}function OO(W){if(W.includes(":")){let Y=m4(W.slice(2),":");return[Y[0],Y[1]]}else return[W.slice(2),void 0]}function KO(W,Y,G=(X)=>X.toString()){let X=Y.split(" ");if(X.length>0)W.push(new oV(X[0],X.slice(1).map(G)))}function Zx(W){let Y=DY.fromSdp(W);return eV(Y)}var Lr=class{constructor(W,Y){this.sdp=W,this.type=Y}static isThis(W){if(typeof W?.sdp==="string")return!0}toSdp(){return{sdp:this.sdp,type:this.type}}};function VS(W,Y){let X=new PN(pi(64)).toString().slice(0,8),J=0;Y.origin=`- ${X} 0 IN IP4 0.0.0.0`,Y.msidSemantic.push(new oV("WMS",["*"])),Y.type=W}function Qq(W){let Y={};return W.split(";").forEach((G)=>{if(G.includes("=")){let[X,J]=m4(G,"=");if(Ri.includes(X))Y[X]=Number(J);else Y[X]=J}else if(G.includes(":")){let[X,J]=G.split(":");Y[X]=Number.isNaN(Number(J))?J:Number(J)}else Y[G]=void 0}),Y}var tO=class{ssrc;cname;msid;msLabel;label;constructor(W){Object.assign(this,W)}},kN=M1("werift:packages/webrtc/src/media/rtpReceiver.ts"),Vx=class{constructor(W,Y,G){this.config=W,this.kind=Y,this.rtcpSsrc=G}codecs={};get codecArray(){return Object.values(this.codecs).sort((W,Y)=>W.payloadType-Y.payloadType)}ssrcByRtx={};nack=new hi(this);audioRedHandler=new to;type="receiver";uuid=wi().toString();tracks=[];trackBySSRC={};trackByRID={};lastSRtimestamp={};receiveLastSRTimestamp={};onPacketLost=this.nack.onPacketLost;onRtcp=new p0;dtlsTransport;sdesMid;latestRid;latestRepairedRid;receiverTWCC;stopped=!1;remoteStreamId;remoteTrackId;rtcpRunning=!1;rtcpCancel=new AbortController;remoteStreams={};setDtlsTransport(W){this.dtlsTransport=W}get track(){return this.tracks[0]??new uO({kind:this.kind})}get nackEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type==="nack")}get twccEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===Ui().type)}get pliEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===QU().type)}prepareReceive(W){W.codecs.forEach((Y)=>{this.codecs[Y.payloadType]=Y}),W.encodings.forEach((Y)=>{if(Y.rtx)this.ssrcByRtx[Y.rtx.ssrc]=Y.ssrc})}setupTWCC(W){if(this.twccEnabled&&!this.receiverTWCC)this.receiverTWCC=new fi(this.dtlsTransport,this.rtcpSsrc,W)}addTrack(W){if(this.tracks.find((G)=>{if(G.rid)return G.rid===W.rid;if(G.ssrc)return G.ssrc===W.ssrc}))return!1;if(this.tracks.push(W),W.ssrc)this.trackBySSRC[W.ssrc]=W;if(W.rid)this.trackByRID[W.rid]=W;return!0}stop(){if(this.stopped=!0,this.rtcpRunning=!1,this.rtcpCancel.abort(),this.receiverTWCC)this.receiverTWCC.twccRunning=!1;this.nack.close()}async runRtcp(){if(this.rtcpRunning||this.stopped)return;this.rtcpRunning=!0;try{while(this.rtcpRunning){await zO(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=Object.entries(this.remoteStreams).map(([G,X])=>{let J=0,Z=0;if(this.lastSRtimestamp[G]){J=this.lastSRtimestamp[G];let V=Vq()-this.receiveLastSRTimestamp[G];if(V>0&&V<65536)Z=lV(V*65536)}return new YK({ssrc:Number(G),fractionLost:X.fraction_lost,packetsLost:X.packets_lost,highestSequence:X.max_seq,jitter:X.jitter,lsr:J,dlsr:Z})}),Y=new rV({ssrc:this.rtcpSsrc,reports:W});try{if(this.config.debug.receiverReportDelay)await zO(this.config.debug.receiverReportDelay);await this.dtlsTransport.sendRtcp([Y])}catch(G){kN("sendRtcp failed",G),await zO(500+Math.random()*1000)}}}catch(W){}}async getStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id);for(let X of this.tracks){if(!X.ssrc)continue;let J=this.remoteStreams[X.ssrc];if(!J)continue;let Z={type:"inbound-rtp",id:Z8("inbound-rtp",X.ssrc),timestamp:W,ssrc:X.ssrc,kind:this.kind,transportId:G,codecId:this.codecs[0]?Z8("codec",this.codecs[0].payloadType,G):void 0,mid:this.sdesMid,trackIdentifier:X.id,packetsReceived:J.packets_received,packetsLost:J.packets_lost,jitter:J.jitter};if(Y.push(Z),this.lastSRtimestamp[X.ssrc]){let V={type:"remote-outbound-rtp",id:Z8("remote-outbound-rtp",X.ssrc),timestamp:W,ssrc:X.ssrc,kind:this.kind,transportId:G,codecId:Z.codecId,localId:Z.id,remoteTimestamp:this.receiveLastSRTimestamp[X.ssrc]*1000};Y.push(V)}}return Y}async sendRtcpPLI(W){if(!this.pliEnabled){kN("pli not supported",{mediaSsrc:W});return}if(this.stopped)return;kN("sendRtcpPLI",{mediaSsrc:W});let Y=new iV({feedback:new Yq({senderSsrc:this.rtcpSsrc,mediaSsrc:W})});try{await this.dtlsTransport.sendRtcp([Y])}catch(G){kN(G)}}handleRtcpPacket(W){switch(W.type){case bX.type:{let Y=W;this.lastSRtimestamp[Y.ssrc]=d2(Y.senderInfo.ntpTimestamp),this.receiveLastSRTimestamp[Y.ssrc]=Vq();let G=this.trackBySSRC[W.ssrc];if(G)G.onReceiveRtcp.execute(W)}break}this.onRtcp.execute(W)}handleRtpBySsrc=(W,Y)=>{let G=this.trackBySSRC[W.header.ssrc];this.handleRTP(W,Y,G)};handleRtpByRid=(W,Y,G)=>{let X=this.trackByRID[Y];if(!this.trackBySSRC[W.header.ssrc])this.trackBySSRC[W.header.ssrc]=X;this.handleRTP(W,G,X)};handleRTP(W,Y,G){if(this.stopped)return;let X=this.codecs[W.header.payloadType];if(!X)return;if(this.remoteStreams[W.header.ssrc]=this.remoteStreams[W.header.ssrc]??new ci(X.clockRate),this.remoteStreams[W.header.ssrc].add(W),this.receiverTWCC){let Z=Y[C9.transportWideCC];if(!Z==null)throw Error("undefined");this.receiverTWCC.handleTWCC(Z)}else if(this.twccEnabled)this.setupTWCC(W.header.ssrc);if(X.name.toLowerCase()==="rtx"){let Z=this.ssrcByRtx[W.header.ssrc],V=Qq(X.parameters??""),U=this.codecs[V.apt];if(W.payload.length<2)return;W=eo(W,U.payloadType,Z),G=this.trackBySSRC[Z]}let J;if(X.name.toLowerCase()==="red"){if(J=X2.deSerialize(W.payload),!Object.keys(this.codecs).includes(J.header.fields[0].blockPT.toString()))return}if(G?.kind==="video"&&this.nackEnabled)this.nack.addPacket(W);if(G)if(J){if(G.kind==="audio"){let Z=this.audioRedHandler.push(J,W);for(let V of Z)G.onReceiveRtp.execute(V.clone(),Y)}}else G.onReceiveRtp.execute(W.clone(),Y);this.runRtcp()}},hV=M1("werift:packages/webrtc/src/media/router.ts"),Br=class{ssrcTable={};ridTable={};extIdUriMap={};constructor(){}registerRtpSender(W){this.ssrcTable[W.ssrc]=W}registerRtpReceiver(W,Y){hV("registerRtpReceiver",Y),this.ssrcTable[Y]=W}registerRtpReceiverBySsrc(W,Y){hV("registerRtpReceiverBySsrc",Y),Y.encodings.filter((G)=>G.ssrc!=null).forEach((G,X)=>{if(this.registerRtpReceiver(W.receiver,G.ssrc),W.addTrack(new uO({ssrc:G.ssrc,kind:W.kind,id:W.sender.trackId,remote:!0,codec:Y.codecs[X]})),G.rtx)this.registerRtpReceiver(W.receiver,G.rtx.ssrc)}),Y.headerExtensions.forEach((G)=>{this.extIdUriMap[G.id]=G.uri})}registerRtpReceiverByRid(W,Y,G){let[X]=G.codecs;hV("registerRtpReceiverByRid",Y),W.addTrack(new uO({rid:Y.rid,kind:W.kind,id:W.sender.trackId,remote:!0,codec:X})),this.ridTable[Y.rid]=W.receiver}routeRtp=(W)=>{let Y=uo(W.header.extensions,this.extIdUriMap),G=this.ssrcTable[W.header.ssrc],X=Y[C9.sdesRTPStreamID];if(typeof X==="string")G=this.ridTable[X],G.latestRid=X,G.handleRtpByRid(W,X,Y);else if(G)G.handleRtpBySsrc(W,Y);else if(G=Object.values(this.ridTable).filter((V)=>V instanceof Vx).find((V)=>V.trackBySSRC[W.header.ssrc]),G)hV("simulcast register receiver by ssrc",W.header.ssrc),this.registerRtpReceiver(G,W.header.ssrc),G.handleRtpBySsrc(W,Y);if(!G){hV("ssrcReceiver not found");return}let J=Y[C9.sdesMid];if(typeof J==="string")G.sdesMid=J;let Z=Y[C9.repairedRtpStreamId];if(typeof Z==="string")G.latestRepairedRid=Z};routeRtcp=(W)=>{let Y=[];switch(W.type){case bX.type:W=W,Y.push(this.ssrcTable[W.ssrc]);break;case rV.type:W=W,W.reports.forEach((G)=>{Y.push(this.ssrcTable[G.ssrc])});break;case Zq.type:{let G=W}break;case hX.type:{let G=W;if(G.feedback)Y.push(this.ssrcTable[G.feedback.mediaSourceSsrc])}break;case iV.type:{let G=W;switch(G.feedback.count){case Gq.count:{let X=G.feedback;Y.push(this.ssrcTable[X.ssrcFeedbacks[0]])}break;default:Y.push(this.ssrcTable[G.feedback.senderSsrc]||this.ssrcTable[G.feedback.mediaSsrc])}}break}Y.filter((G)=>G).forEach((G)=>G.handleRtcpPacket(W))}},Er=class{numPackets=0;totalSize=0;firstPacketSentAtMs=0;lastPacketSentAtMs=0;firstPacketReceivedAtMs=0;lastPacketReceivedAtMs=0;addPacket(W,Y,G){if(this.numPackets===0)this.firstPacketSentAtMs=Y,this.firstPacketReceivedAtMs=G,this.lastPacketSentAtMs=Y,this.lastPacketReceivedAtMs=G;else{if(Y<this.firstPacketSentAtMs)this.firstPacketSentAtMs=Y;if(G<this.firstPacketReceivedAtMs)this.firstPacketReceivedAtMs=G;if(Y>this.lastPacketSentAtMs)this.lastPacketSentAtMs=Y;if(G>this.lastPacketReceivedAtMs)this.lastPacketReceivedAtMs=G}this.numPackets++,this.totalSize+=W}reset(){this.numPackets=0,this.totalSize=0,this.firstPacketSentAtMs=0,this.lastPacketSentAtMs=0,this.firstPacketReceivedAtMs=0,this.lastPacketReceivedAtMs=0}get receiveBitrate(){let W=this.lastPacketReceivedAtMs-this.firstPacketReceivedAtMs,Y=this.totalSize/W*8*1000;return Wq(Y)}get sendBitrate(){let W=this.lastPacketSentAtMs-this.firstPacketSentAtMs,Y=this.totalSize/W*8*1000;return Wq(Y)}},xX=20,$r=10,Fr=class{congestion=!1;onAvailableBitrate=new p0;onCongestion=new p0;onCongestionScore=new p0;congestionCounter=0;cumulativeResult=new Er;sentInfos={};_congestionScore=1;get congestionScore(){return this._congestionScore}set congestionScore(W){this._congestionScore=W,this.onCongestionScore.execute(W)}_availableBitrate=0;get availableBitrate(){return this._availableBitrate}set availableBitrate(W){this._availableBitrate=W,this.onAvailableBitrate.execute(W)}constructor(){}receiveTWCC(W){let G=l2()-this.cumulativeResult.firstPacketSentAtMs;if(G>1000){if(this.cumulativeResult.reset(),this.congestionCounter<xX)this.congestionCounter++;else if(this.congestionScore<$r)this.congestionScore++;if(this.congestionCounter>=xX&&!this.congestion)this.congestion=!0,this.onCongestion.execute(this.congestion)}for(let X of W.packetResults){if(!X.received)continue;let J=X.sequenceNumber,Z=this.sentInfos[J];if(!Z)continue;if(!X.receivedAtMs)continue;this.cumulativeResult.addPacket(Z.size,Z.sendingAtMs,X.receivedAtMs)}if(G>=100&&this.cumulativeResult.numPackets>=20){if(this.availableBitrate=Math.min(this.cumulativeResult.sendBitrate,this.cumulativeResult.receiveBitrate),this.cumulativeResult.reset(),this.congestionCounter>-xX){let X=Wq(xX/2)+1,J=Wq(xX/4)+1,Z=X-(X-J)/10*this.congestionScore;this.congestionCounter=this.congestionCounter-Z}if(this.congestionCounter<=-xX){if(this.congestionScore>1)this.congestionScore--,this.onCongestion.execute(!1);this.congestionCounter=0}if(this.congestionCounter<=0&&this.congestion)this.congestion=!1,this.onCongestion.execute(this.congestion)}}rtpPacketSent(W){Object.keys(W).map((Y)=>Number(Y)).sort().filter((Y)=>Y<W.wideSeq).forEach((Y)=>{delete this.sentInfos[Y]}),this.sentInfos[W.wideSeq]=W}},DO=M1("werift:packages/webrtc/src/media/rtpSender.ts"),NS=128,qS=0.85,Sr=class{constructor(W){if(this.trackOrKind=W,this.kind=typeof this.trackOrKind==="string"?this.trackOrKind:this.trackOrKind.kind,typeof W!=="string"){if(W.streamId)this.streamId=W.streamId;this.registerTrack(W)}}type="sender";kind;ssrc=s1.Unpack("!L",US(4))[0];rtxSsrc=s1.Unpack("!L",US(4))[0];streamId=QS().toString();trackId=QS().toString();onReady=new p0;onRtcp=new p0;onPictureLossIndication=new p0;onGenericNack=new p0;senderBWE=new Fr;cname;mid;rtpStreamId;repairedRtpStreamId;rtxPayloadType;rtxSequenceNumber=zS();redRedundantPayloadType;_redDistance=2;redEncoder=new ao(this._redDistance);headerExtensions=[];disposeTrack;lastSRtimestamp;lastSentSRTimestamp;ntpTimestamp=0n;rtpTimestamp=0;octetCount=0;packetCount=0;rtt;receiverEstimatedMaxBitrate=0n;sequenceNumber;timestamp;timestampOffset=0;seqOffset=0;rtpCache=[];codec;dtlsTransport;dtlsDisposer=[];track;stopped=!1;rtcpRunning=!1;rtcpCancel=new AbortController;setDtlsTransport(W){if(this.dtlsTransport)this.dtlsDisposer.forEach((Y)=>Y());this.dtlsTransport=W,this.dtlsDisposer=[this.dtlsTransport.onStateChange.subscribe((Y)=>{if(Y==="connected")this.onReady.execute()}).unSubscribe]}get redDistance(){return this._redDistance}set redDistance(W){this._redDistance=W,this.redEncoder.distance=W}prepareSend(W){if(this.cname=W.rtcp?.cname,this.mid=W.muxId,this.headerExtensions=W.headerExtensions,this.rtpStreamId=W.rtpStreamId,this.repairedRtpStreamId=W.repairedRtpStreamId,this.codec=W.codecs[0],this.track)this.track.codec=this.codec;W.codecs.forEach((Y)=>{let G=Qq(Y.parameters??"");if(Y.name.toLowerCase()==="rtx"&&G.apt===this.codec?.payloadType)this.rtxPayloadType=Y.payloadType;if(Y.name.toLowerCase()==="red")this.redRedundantPayloadType=Number((Y.parameters??"").split("/")[0])})}registerTrack(W){if(W.stopped)throw Error("track is ended");if(this.disposeTrack)this.disposeTrack();W.id=this.trackId;let{unSubscribe:Y}=W.onReceiveRtp.subscribe(async(G)=>{await this.sendRtp(G)});if(this.track=W,this.disposeTrack=Y,this.codec)W.codec=this.codec;W.onSourceChanged.subscribe((G)=>{this.replaceRTP(G)})}async replaceTrack(W){if(W===null)return;if(W.stopped)throw Error("track is ended");if(this.sequenceNumber!=null){let Y=W.header||(await W.onReceiveRtp.asPromise())[0].header;this.replaceRTP(Y)}this.registerTrack(W),DO("replaceTrack","ssrc",W.ssrc,"rid",W.rid)}stop(){if(this.stopped=!0,this.rtcpRunning=!1,this.rtcpCancel.abort(),this.disposeTrack)this.disposeTrack();this.track=void 0}async runRtcp(){if(this.rtcpRunning||this.stopped)return;this.rtcpRunning=!0;try{while(this.rtcpRunning){await HS(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=[new bX({ssrc:this.ssrc,senderInfo:new G2({ntpTimestamp:this.ntpTimestamp,rtpTimestamp:this.rtpTimestamp,packetCount:this.packetCount,octetCount:this.octetCount})})];if(this.lastSRtimestamp=d2(this.ntpTimestamp),this.lastSentSRTimestamp=Vq(),this.cname)W.push(new Zq({chunks:[new W2({source:this.ssrc,items:[new Y2({type:1,text:this.cname})]})]}));try{await this.dtlsTransport.sendRtcp(W)}catch(Y){DO("sendRtcp failed",Y),await HS(500+Math.random()*1000)}}}catch(W){}}replaceRTP({sequenceNumber:W,timestamp:Y},G=!1){if(this.sequenceNumber!=null){if(this.seqOffset=T9(this.sequenceNumber,-W),G)this.seqOffset=T9(this.seqOffset,2)}if(this.timestamp!=null){if(this.timestampOffset=vX(this.timestamp,-Y),G)this.timestampOffset=T9(this.timestampOffset,1)}this.rtpCache=[],DO("replaceRTP",this.sequenceNumber,W,this.seqOffset)}async sendRtp(W){if(this.dtlsTransport.state!=="connected"||!this.codec)return;W=Buffer.isBuffer(W)?t6.deSerialize(W):W;let{header:Y,payload:G}=W;Y.ssrc=this.ssrc,Y.payloadType=this.codec.payloadType,Y.timestamp=vX(Y.timestamp,this.timestampOffset),Y.sequenceNumber=T9(Y.sequenceNumber,this.seqOffset),this.timestamp=Y.timestamp,this.sequenceNumber=Y.sequenceNumber;let X=yi(),J=[...Y.extensions];Y.extensions=this.headerExtensions.map((H)=>{let N=(()=>{switch(H.uri){case C9.sdesMid:if(this.mid)return ho(this.mid);return;case C9.sdesRTPStreamID:if(this.rtpStreamId)return bo(this.rtpStreamId);return;case C9.repairedRtpStreamId:if(this.repairedRtpStreamId)return mo(this.repairedRtpStreamId);return;case C9.transportWideCC:return this.dtlsTransport.transportSequenceNumber=T9(this.dtlsTransport.transportSequenceNumber,1),fo(this.dtlsTransport.transportSequenceNumber);case C9.absSendTime:return co(X)}})();if(N)return{id:H.id,payload:N}}).filter((H)=>H);for(let H of J){let N=Y.extensions.find((A)=>A.id===H.id);if(N)N.payload=H.payload;else Y.extensions.push(H)}Y.extensions=Y.extensions.sort((H,N)=>H.id-N.id),this.ntpTimestamp=X,this.rtpTimestamp=Y.timestamp,this.octetCount+=G.length,this.packetCount=vX(this.packetCount,1),this.rtpCache[Y.sequenceNumber%NS]=W;let Z=G;if(this.redRedundantPayloadType)this.redEncoder.push({block:Z,timestamp:Y.timestamp,blockPT:this.redRedundantPayloadType}),Z=this.redEncoder.build().serialize();let V=await this.dtlsTransport.sendRtp(Z,Y);this.runRtcp();let U=l2(),Q={wideSeq:this.dtlsTransport.transportSequenceNumber,size:V,sendingAtMs:U,sentAtMs:U};this.senderBWE.rtpPacketSent(Q)}handleRtcpPacket(W){switch(W.type){case bX.type:case rV.type:W.reports.filter((G)=>G.ssrc===this.ssrc).forEach((G)=>{if(this.lastSRtimestamp===G.lsr&&G.dlsr){if(this.lastSentSRTimestamp){let X=Vq()-this.lastSentSRTimestamp-G.dlsr/65536;if(this.rtt===void 0)this.rtt=X;else this.rtt=qS*this.rtt+(1-qS)*X}}});break;case hX.type:{let Y=W;switch(Y.feedback.count){case Jq.count:{let G=Y.feedback;this.senderBWE.receiveTWCC(G)}break;case Xq.count:{let G=Y.feedback;G.lost.forEach(async(X)=>{let J=this.rtpCache[X%NS];if(J&&J.header.sequenceNumber!==X)J=void 0;if(J){if(this.rtxPayloadType!=null)J=Wn(J,this.rtxPayloadType,this.rtxSequenceNumber,this.rtxSsrc),this.rtxSequenceNumber=T9(this.rtxSequenceNumber,1);await this.dtlsTransport.sendRtp(J.payload,J.header)}}),this.onGenericNack.execute(G)}break}}break;case iV.type:{let Y=W;switch(Y.feedback.count){case Gq.count:{let G=Y.feedback;this.receiverEstimatedMaxBitrate=G.bitrate}break;case Yq.count:this.onPictureLossIndication.execute();break}}break}this.onRtcp.execute(W)}getParameters(){return{encodings:[]}}setParameters(W){}async getStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id),X={type:"outbound-rtp",id:Z8("outbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:this.codec?Z8("codec",this.codec.payloadType,G):void 0,mid:this.mid,packetsSent:this.packetCount,bytesSent:this.octetCount,rtxSsrc:this.rtxPayloadType?this.rtxSsrc:void 0};if(Y.push(X),this.track){let J={type:"media-source",id:Z8("media-source",this.trackId),timestamp:W,trackIdentifier:this.trackId,kind:this.kind};Y.push(J)}if(this.rtt!==void 0){let J={type:"remote-inbound-rtp",id:Z8("remote-inbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:X.codecId,localId:X.id,roundTripTime:this.rtt};Y.push(J)}return Y}},kr=M1("werift:packages/webrtc/src/transport/sctpManager.ts"),_r=class{sctpTransport;sctpRemotePort;dataChannelsOpened=0;dataChannelsClosed=0;dataChannels=[];onDataChannel=new p0;constructor(){}createSctpTransport(W){let Y=new Rr(5000,W);return Y.mid=void 0,Y.onDataChannel.subscribe((G)=>{this.dataChannelsOpened++,this.dataChannels.push(G),this.onDataChannel.execute(G)}),this.sctpTransport=Y,Y}createDataChannel(W,Y={}){let X={...{protocol:"",ordered:!0,negotiated:!1},...Y};if(X.maxPacketLifeTime&&X.maxRetransmits)throw Error("can not select both");if(!this.sctpTransport)this.sctpTransport=this.createSctpTransport();let J=new S2({id:X.id,label:W,maxPacketLifeTime:X.maxPacketLifeTime,maxRetransmits:X.maxRetransmits,negotiated:X.negotiated,ordered:X.ordered,protocol:X.protocol}),Z=new F2(this.sctpTransport,J);return this.dataChannelsOpened++,this.dataChannels.push(Z),Z.stateChange.subscribe((V)=>{if(V==="closed"){this.dataChannelsClosed++;let U=this.dataChannels.indexOf(Z);if(U!==-1)this.dataChannels.splice(U,1)}}),Z}async connectSctp(){if(!this.sctpTransport||!this.sctpRemotePort)return;await this.sctpTransport.start(this.sctpRemotePort),await this.sctpTransport.sctp.stateChanged.connected.asPromise(),kr("sctp connected")}setRemoteSCTP(W,Y){if(!this.sctpTransport)return;if(this.sctpTransport.setRemoteMaxMessageSize(W.sctpCapabilities?.maxMessageSize),this.sctpRemotePort=W.sctpPort,!this.sctpRemotePort)throw Error("sctpRemotePort not exist");if(this.sctpTransport.setRemotePort(this.sctpRemotePort),this.sctpTransport.mLineIndex=Y,!this.sctpTransport.mid)this.sctpTransport.mid=W.rtp.muxId}async close(){if(this.sctpTransport)await this.sctpTransport.stop();this.onDataChannel.allUnsubscribe()}async getStats(){let W=$Y(),Y=[];for(let G of this.dataChannels){let X={type:"data-channel",id:Z8("data-channel",G.id),timestamp:W,label:G.label,protocol:G.protocol,dataChannelIdentifier:G.id,state:G.readyState,messagesSent:G.messagesSent||0,bytesSent:G.bytesSent||0,messagesReceived:G.messagesReceived||0,bytesReceived:G.bytesReceived||0};Y.push(X)}return Y}},yr=class{currentLocalDescription;currentRemoteDescription;pendingLocalDescription;pendingRemoteDescription;cname;midSuffix;bundlePolicy;seenMid=new Set;constructor({cname:W,midSuffix:Y,bundlePolicy:G}){this.cname=W,this.midSuffix=Y??!1,this.bundlePolicy=G}get localDescription(){if(!this._localDescription)return;return this._localDescription.toJSON()}get remoteDescription(){if(!this._remoteDescription)return;return this._remoteDescription.toJSON()}get _localDescription(){return this.pendingLocalDescription||this.currentLocalDescription}get _remoteDescription(){return this.pendingRemoteDescription||this.currentRemoteDescription}get inactiveRemoteMedia(){return this._remoteDescription?.media?.find?.((W)=>W.direction==="inactive")}createMediaDescriptionForTransceiver(W,Y){let G=new aO(W.kind,9,"UDP/TLS/RTP/SAVPF",W.codecs.map((X)=>X.payloadType));if(G.direction=Y,G.msid=W.msid,G.rtp={codecs:W.codecs,headerExtensions:W.headerExtensions,muxId:W.mid},G.rtcpHost="0.0.0.0",G.rtcpPort=9,G.rtcpMux=!0,G.ssrc=[new tO({ssrc:W.sender.ssrc,cname:this.cname})],W.options.simulcast)G.simulcastParameters=W.options.simulcast.map((X)=>new x2(X));if(G.rtp.codecs.find((X)=>X.name.toLowerCase()==="rtx"))G.ssrc.push(new tO({ssrc:W.sender.rtxSsrc,cname:this.cname})),G.ssrcGroup=[new oV("FID",[W.sender.ssrc.toString(),W.sender.rtxSsrc.toString()])];return this.addTransportDescription(G,W.dtlsTransport),G}createMediaDescriptionForSctp(W){let Y=new aO("application",cF,"UDP/DTLS/SCTP",["webrtc-datachannel"]);return Y.sctpPort=W.port,Y.rtp.muxId=W.mid,Y.sctpCapabilities=W.getCapabilities(),this.addTransportDescription(Y,W.dtlsTransport),Y}addTransportDescription(W,Y){let G=Y.iceTransport;if(W.iceCandidates=G.localCandidates,W.iceCandidatesComplete=G.gatheringState==="complete",W.iceParams=G.localParameters,W.iceOptions="trickle",W.host=Ti,W.port=cF,W.direction==="inactive")W.port=0,W.msid=void 0;if(!W.dtlsParams){if(W.dtlsParams=Y.localParameters,!W.dtlsParams.fingerprints)W.dtlsParams.fingerprints=Y.localParameters.fingerprints}}allocateMid(W=""){let Y="";for(let G=0;;)if(Y=(G++).toString()+W,!this.seenMid.has(Y))break;return this.seenMid.add(Y),Y}parseSdp({sdp:W,isLocal:Y,signalingState:G,type:X}){let J=oN.parse(W);return this.validateDescription({description:J,isLocal:Y,signalingState:G}),J.type=X,J}validateDescription({description:W,isLocal:Y,signalingState:G}){if(Y){if(W.type==="offer"){if(!["stable","have-local-offer"].includes(G))throw Error("Cannot handle offer in signaling state")}else if(W.type==="answer"){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("Cannot handle answer in signaling state")}}else if(W.type==="offer"){if(!["stable","have-remote-offer"].includes(G))throw Error("Cannot handle offer in signaling state")}else if(W.type==="answer"){if(!["have-local-offer","have-remote-pranswer"].includes(G))throw Error("Cannot handle answer in signaling state")}}buildOfferSdp(W,Y){let G=new oN;VS("offer",G),(this.currentLocalDescription?.media??[]).forEach((J,Z)=>{let V=J.rtp.muxId;if(!V)return;if(J.kind==="application"){if(!Y)throw Error("sctpTransport not found");Y.mLineIndex=Z,G.media.push(this.createMediaDescriptionForSctp(Y))}else{let U=W.find((Q)=>Q.mid===V);if(!U){if(J.direction==="inactive"){G.media.push(J);return}throw Error("transceiver not found")}U.mLineIndex=Z,G.media.push(this.createMediaDescriptionForTransceiver(U,U.direction))}});for(let J of W.filter((Z)=>!G.media.find((V)=>V.rtp.muxId===Z.mid))){if(J.mid==null)J.mid=this.allocateMid(this.midSuffix?"av":"");let Z=this.createMediaDescriptionForTransceiver(J,J.direction);if(J.mLineIndex===void 0)J.mLineIndex=G.media.length,G.media.push(Z);else G.media[J.mLineIndex]=Z}if(Y&&!G.media.find((J)=>J.kind==="application")){if(Y.mLineIndex=G.media.length,Y.mid==null)Y.mid=this.allocateMid(this.midSuffix?"dc":"");G.media.push(this.createMediaDescriptionForSctp(Y))}if(this.bundlePolicy!=="disable"){let J=G.media.map((Z)=>Z.rtp.muxId).filter((Z)=>Z);if(J.length){let Z=new oV("BUNDLE",J);G.group.push(Z)}}return G}buildAnswerSdp({transceivers:W,sctpTransport:Y,signalingState:G}){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("createAnswer failed");if(!this._remoteDescription)throw Error("wrong state");let X=new oN;VS("answer",X);for(let J of this._remoteDescription.media){let Z,V;if(["audio","video"].includes(J.kind)){let U=W.find((Q)=>Q.mid===J.rtp.muxId);if(!U)throw Error(`Transceiver with mid=${J.rtp.muxId} not found`);V=this.createMediaDescriptionForTransceiver(U,p2(U.direction,U.offerDirection)),Z=U.dtlsTransport}else if(J.kind==="application"){if(!Y||!Y.mid)throw Error("sctpTransport not found");V=this.createMediaDescriptionForSctp(Y),Z=Y.dtlsTransport}else throw Error("invalid kind");if(V.dtlsParams)if(Z.role==="auto")V.dtlsParams.role="client";else V.dtlsParams.role=Z.role;if(J.simulcastParameters&&J.simulcastParameters.length>0)V.simulcastParameters=J.simulcastParameters.map((U)=>({...U,direction:U.direction==="send"?"recv":"send"}));X.media.push(V)}if(this.bundlePolicy!=="disable"){let J=new oV("BUNDLE",[]);for(let Z of X.media)if(Z.rtp.muxId)J.items.push(Z.rtp.muxId);X.group.push(J)}return X}setLocalDescription(W){if(this.currentLocalDescription=W,W.type==="answer")this.pendingLocalDescription=void 0;else this.pendingLocalDescription=W}setRemoteDescription(W,Y){if(!W.sdp||!W.type||W.type==="rollback"||W.type==="pranswer")throw Error("invalid sessionDescription");let G=this.parseSdp({sdp:W.sdp,isLocal:!1,signalingState:Y,type:W.type});if(G.type==="answer")this.currentRemoteDescription=G,this.pendingRemoteDescription=void 0;else this.pendingRemoteDescription=G;return G}registerMid(W){this.seenMid.add(W)}get remoteIsBundled(){let W=this._remoteDescription;if(!W)return;return W.group.find((G)=>G.semantic==="BUNDLE"&&this.bundlePolicy!=="disable")}setLocal(W,Y,G){let X=new Map(Y.map((V)=>[V?.mLineIndex,V])),J=Y.find((V)=>V?.dtlsTransport)?.dtlsTransport??G?.dtlsTransport;W.media.filter((V)=>["audio","video"].includes(V.kind)).forEach((V,U)=>{let H=(X.get(U)??Y[U])?.dtlsTransport??J;if(!H)throw Error(`dtls transport not found for media index ${U}`);this.addTransportDescription(V,H)});let Z=W.media.find((V)=>V.kind==="application");if(G&&Z)this.addTransportDescription(Z,G.dtlsTransport);this.setLocalDescription(W)}},bV=M1("werift:packages/webrtc/src/transport/secureTransportManager.ts"),vr=class{connectionState="new";iceConnectionState="new";iceGatheringState="new";certificate;iceGatheringStateChange=new p0;iceConnectionStateChange=new p0;onIceCandidate=new p0;connectionStateChange=new p0;config;transceiverManager;sctpManager;constructor({config:W,transceiverManager:Y,sctpManager:G}){if(this.config=W,this.transceiverManager=Y,this.sctpManager=G,this.config.dtls){let{keys:X}=this.config.dtls;if(X)this.setupCertificate(X)}}get dtlsTransports(){return[...this.transceiverManager.getTransceivers().map((Y)=>Y?.dtlsTransport),this.sctpManager.sctpTransport?.dtlsTransport].filter((Y)=>Y!=null).reduce((Y,G)=>{if(!Y.map((X)=>X.id).includes(G.id))Y.push(G);return Y},[])}get iceTransports(){return this.dtlsTransports.map((W)=>W.iceTransport)}setupCertificate(W){this.certificate=new o2(W.keyPem,W.certPem,W.signatureHash)}createTransport(){let W=this.iceTransports.find((J)=>J.state!=="closed"),Y=new ei({...vi(this.config.iceServers),forceTurn:this.config.iceTransportPolicy==="relay",portRange:this.config.icePortRange,interfaceAddresses:this.config.iceInterfaceAddresses,additionalHostAddresses:this.config.iceAdditionalHostAddresses,filterStunResponse:this.config.iceFilterStunResponse,filterCandidatePair:this.config.iceFilterCandidatePair,localPasswordPrefix:this.config.icePasswordPrefix,useIpv4:this.config.iceUseIpv4,useIpv6:this.config.iceUseIpv6,turnTransport:this.config.forceTurnTCP===!0?"tcp":"udp",useLinkLocalAddress:this.config.iceUseLinkLocalAddress});if(W)Y.connection.localUsername=W.connection.localUsername,Y.connection.localPassword=W.connection.localPassword;Y.onGatheringStateChange.subscribe(()=>{this.updateIceGatheringState()}),this.updateIceGatheringState();let G=new ti(Y);return G.onStateChange.subscribe(()=>{this.updateIceConnectionState()}),new oF(this.config,G,this.certificate,gr)}handleNewIceCandidate({candidate:W,media:Y,remoteIsBundled:G,transceiver:X,sctpTransport:J,bundlePolicy:Z}){if(Z==="max-bundle"||G){if(W.sdpMLineIndex=0,Y)W.sdpMid=Y.rtp.muxId}else{if(X)W.sdpMLineIndex=X.mLineIndex,W.sdpMid=X.mid;if(J)W.sdpMLineIndex=J.mLineIndex,W.sdpMid=J.mid}if(W.foundation&&!W.foundation.startsWith("candidate:"))W.foundation="candidate:"+W.foundation;return this.onIceCandidate.execute(W),W}async addIceCandidate(W,Y){let G=n2.fromJSON(Y);if(!G)return;let X;if(typeof G.sdpMid==="number")X=this.getTransportByMid(G.sdpMid);if(!X&&typeof G.sdpMLineIndex==="number")X=this.getTransportByMLineIndex(W,G.sdpMLineIndex);if(!X)X=this.iceTransports[0];if(X)await X.addRemoteCandidate(G);else bV("iceTransport not found for candidate",G)}getTransportByMid(W){let Y,G=this.transceiverManager.getTransceivers().find((X)=>X.mid===W);if(G)Y=G.dtlsTransport.iceTransport;else if(!Y&&this.sctpManager.sctpTransport?.mid===W)Y=this.sctpManager.sctpTransport.dtlsTransport.iceTransport;return Y}getTransportByMLineIndex(W,Y){let G=W.media[Y];if(!G)return;return this.getTransportByMid(G.rtp.muxId)}restartIce(){for(let W of this.iceTransports)W.restart()}setLocalRole({type:W,role:Y}){for(let G of this.dtlsTransports){let X=G.iceTransport;if(W==="offer")X.connection.iceControlling=!0;else X.connection.iceControlling=!1;if(X.connection.remoteIsLite)X.connection.iceControlling=!0;if(W==="answer"){if(Y)G.role=Y}}}updateIceGatheringState(){let W=this.iceTransports;function Y(...X){return W.filter((J)=>X.includes(J.gatheringState)).length===W.length}let G;if(W.length&&Y("complete"))G="complete";else if(!W.length||Y("new","complete"))G="new";else if(W.map((X)=>X.gatheringState).includes("gathering"))G="gathering";else G="new";if(this.iceGatheringState===G)return;this.iceGatheringState=G,this.iceGatheringStateChange.execute(G)}updateIceConnectionState(){let W=this.iceTransports,Y;function G(...J){return W.filter((Z)=>J.includes(Z.state)).length===W.length}function X(...J){return W.some((Z)=>J.includes(Z.state))}if(this.connectionState==="closed")Y="closed";else if(X("failed"))Y="failed";else if(X("disconnected"))Y="disconnected";else if(G("new","closed"))Y="new";else if(X("new","checking"))Y="checking";else if(G("completed","closed"))Y="completed";else if(G("connected","completed","closed"))Y="connected";else Y="new";if(this.iceConnectionState===Y)return;bV("iceConnectionStateChange",Y),this.iceConnectionState=Y,this.iceConnectionStateChange.execute(Y)}async gatherCandidates(W){let Y=this.iceTransports.find((G)=>G.state==="connected"||G.state==="completed");if(W&&Y)bV("skipping ICE gathering for bundled connection");else await Promise.allSettled(this.iceTransports.map((G)=>G.gather())).catch((G)=>{bV("gatherCandidates failed",G)})}setConnectionState(W){bV("connectionStateChange",W),this.connectionState=W,this.connectionStateChange.execute(W)}async getStats(){let W=[];for(let Y of this.dtlsTransports){let G=await Y.getStats();if(G)W.push(...G)}return W}async ensureCerts(){if(!this.certificate)this.certificate=await oF.SetupCertificate();for(let W of this.dtlsTransports)W.localCertificate=this.certificate}async close(){this.setConnectionState("closed"),await Promise.allSettled([...this.dtlsTransports.map((W)=>W.stop())]),this.iceGatheringStateChange.allUnsubscribe(),this.iceConnectionStateChange.allUnsubscribe(),this.onIceCandidate.allUnsubscribe(),this.connectionStateChange.allUnsubscribe()}},gr=[lF.SRTP_AEAD_AES_128_GCM,lF.SRTP_AES128_CM_HMAC_SHA1_80],W7=M1("werift:packages/webrtc/src/peerConnection.ts"),Ux=class extends QK{cname=xr().toString();config=Qx();signalingState="stable";negotiationneeded=!1;needRestart=!1;router=new Br;sdpManager;transceiverManager;sctpManager;secureManager;isClosed=!1;shouldNegotiationneeded=!1;remoteBundleNegotiated=!1;iceGatheringStateChange=new p0;iceConnectionStateChange=new p0;signalingStateChange=new p0;connectionStateChange=new p0;onDataChannel=new p0;onRemoteTransceiverAdded=new p0;onTransceiverAdded=new p0;onIceCandidate=new p0;onNegotiationneeded=new p0;onTrack=new p0;ondatachannel;onicecandidate;onicecandidateerror;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;onconnectionstatechange;oniceconnectionstatechange;constructor(W={}){super();this.setConfiguration(W),this.sdpManager=new yr({cname:this.cname,bundlePolicy:this.config.bundlePolicy}),this.transceiverManager=new hr(this.cname,this.config,this.router),this.transceiverManager.onTransceiverAdded.pipe(this.onTransceiverAdded),this.transceiverManager.onRemoteTransceiverAdded.pipe(this.onRemoteTransceiverAdded),this.transceiverManager.onTrack.subscribe(({track:Y,stream:G,transceiver:X})=>{let J={track:Y,streams:[G],transceiver:X,receiver:X.receiver};if(this.onTrack.execute(Y),this.emit("track",J),this.ontrack)this.ontrack(J)}),this.transceiverManager.onNegotiationNeeded.subscribe(()=>this.needNegotiation()),this.sctpManager=new _r,this.sctpManager.onDataChannel.subscribe((Y)=>{this.onDataChannel.execute(Y);let G={channel:Y};this.ondatachannel?.(G),this.emit("datachannel",G)}),this.secureManager=new vr({config:this.config,sctpManager:this.sctpManager,transceiverManager:this.transceiverManager}),this.secureManager.iceGatheringStateChange.pipe(this.iceGatheringStateChange),this.secureManager.iceConnectionStateChange.subscribe((Y)=>{if(Y==="closed")this.close();this.iceConnectionStateChange.execute(Y)}),this.secureManager.connectionStateChange.subscribe((Y)=>{this.connectionStateChange.execute(Y),this.onconnectionstatechange?.(),this.emit("connectionstatechange")}),this.secureManager.onIceCandidate.subscribe((Y)=>{let G=Y?Y.toJSON():void 0;this.onIceCandidate.execute(G),this.onicecandidate?.({candidate:G}),this.emit("icecandidate",{candidate:G})})}get connectionState(){return this.secureManager.connectionState}get iceConnectionState(){return this.secureManager.iceConnectionState}get iceGathererState(){return this.secureManager.iceGatheringState}get iceGatheringState(){return this.secureManager.iceGatheringState}get dtlsTransports(){return this.secureManager.dtlsTransports}get sctpTransport(){return this.sctpManager.sctpTransport}get sctpRemotePort(){return this.sctpManager.sctpRemotePort}get iceTransports(){return this.secureManager.iceTransports}get extIdUriMap(){return this.router.extIdUriMap}get iceGeneration(){return this.iceTransports[0].connection.generation}get localDescription(){return this.sdpManager.localDescription}get remoteDescription(){return this.sdpManager.remoteDescription}get remoteIsBundled(){return this.sdpManager.remoteIsBundled}get _localDescription(){return this.sdpManager._localDescription}get _remoteDescription(){return this.sdpManager._remoteDescription}getTransceivers(){return this.transceiverManager.getTransceivers()}getSenders(){return this.transceiverManager.getSenders()}getReceivers(){return this.transceiverManager.getReceivers()}setConfiguration(W){if(gi(this.config,W),this.config.icePortRange){let[Y,G]=this.config.icePortRange;if(Y===G)throw Error("should not be same value");if(Y>=G)throw Error("The min must be less than max")}if(!Number.isInteger(this.config.maxMessageSize)||this.config.maxMessageSize<0)throw Error("maxMessageSize must be a non-negative integer");if(this.sctpManager?.sctpTransport)this.sctpManager.sctpTransport.maxMessageSize=this.config.maxMessageSize;for(let[Y,G]of uF([...this.config.codecs.audio||[],...this.config.codecs.video||[]])){if(G.payloadType!=null)continue;switch(G.payloadType=96+Y,G.name.toLowerCase()){case"rtx":G.parameters=`apt=${G.payloadType-1}`;break;case"red":if(G.contentType==="audio"){let X=G.payloadType+1;G.parameters=`${X}/${X}`,G.payloadType=63}break}}[...this.config.headerExtensions.audio||[],...this.config.headerExtensions.video||[]].forEach((Y,G)=>{Y.id=1+G})}getConfiguration(){return this.config}async createOffer({iceRestart:W}={}){if(W||this.needRestart)this.needRestart=!1,this.secureManager.restartIce();await this.secureManager.ensureCerts();for(let G of this.transceiverManager.getTransceivers()){if(G.codecs.length===0)this.transceiverManager.assignTransceiverCodecs(G);if(G.headerExtensions.length===0)G.headerExtensions=this.config.headerExtensions[G.kind]??[]}return this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport).toJSON()}createSctpTransport(){let W=this.sctpManager.createSctpTransport(this.config.maxMessageSize),Y=this.findOrCreateTransport();return W.setDtlsTransport(Y),W}createDataChannel(W,Y={}){if(!this.sctpTransport)this.createSctpTransport(),this.needNegotiation();let G=this.sctpManager.createDataChannel(W,Y);if(!G.sctp.dtlsTransport){let X=this.findOrCreateTransport();G.sctp.setDtlsTransport(X)}return G}removeTrack(W){if(this.isClosed)throw Error("peer closed");this.transceiverManager.removeTrack(W),this.needNegotiation()}needNegotiation=async()=>{if(this.shouldNegotiationneeded=!0,this.negotiationneeded||this.signalingState!=="stable")return;this.shouldNegotiationneeded=!1,setImmediate(()=>{if(this.negotiationneeded=!0,this.onNegotiationneeded.execute(),this.onnegotiationneeded)this.onnegotiationneeded({})})};findOrCreateTransport(){let W=this.dtlsTransports.find((J)=>J.state!=="closed"),Y=W?.iceTransport;if(this.sdpManager.bundlePolicy==="max-bundle"||this.sdpManager.bundlePolicy!=="disable"&&(this.remoteIsBundled||this.remoteBundleNegotiated)){if(W)return W}let G=this.secureManager.createTransport();G.onRtp.subscribe((J)=>{this.router.routeRtp(J)}),G.onRtcp.subscribe((J)=>{this.router.routeRtcp(J)});let X=G.iceTransport;return X.onNegotiationNeeded.subscribe(()=>{this.needNegotiation()}),X.onIceCandidate.subscribe((J)=>{if(!this.localDescription){W7("localDescription not found when ice candidate was gathered");return}if(!J){if(this.sdpManager.setLocal(this._localDescription,this.transceiverManager.getTransceivers(),this.sctpTransport),this.onIceCandidate.execute(void 0),this.onicecandidate)this.onicecandidate({candidate:void 0});this.emit("icecandidate",{candidate:void 0});return}if(!this._localDescription){W7("localDescription not found when ice candidate was gathered");return}this.secureManager.handleNewIceCandidate({candidate:J,bundlePolicy:this.sdpManager.bundlePolicy,remoteIsBundled:!!this.sdpManager.remoteIsBundled,media:this._localDescription.media[0],transceiver:this.transceiverManager.getTransceivers().find((Z)=>Z?.dtlsTransport?.iceTransport.id===X.id),sctpTransport:this.sctpTransport?.dtlsTransport.iceTransport.id===X.id?this.sctpTransport:void 0})}),G}async setLocalDescription(W){W=W??(["stable","have-local-offer","have-remote-pranswer"].includes(this.signalingState)?await this.createOffer():await this.createAnswer());let G=this.sdpManager.parseSdp({sdp:W.sdp,isLocal:!0,signalingState:this.signalingState,type:W.type});if(G.type==="offer")this.setSignalingState("have-local-offer");else if(G.type==="answer")this.setSignalingState("stable");for(let[J,Z]of uF(G.media)){let V=Z.rtp.muxId;if(this.sdpManager.registerMid(V),["audio","video"].includes(Z.kind)){let U=this.transceiverManager.getTransceiverByMLineIndex(J);if(U)U.mid=V}if(Z.kind==="application"&&this.sctpTransport)this.sctpTransport.mid=V}let X=G.media.find((J)=>J.dtlsParams)?.dtlsParams?.role;if(this.secureManager.setLocalRole({type:G.type,role:X}),["answer","pranswer"].includes(G.type))for(let J of this.transceiverManager.getTransceivers()){let Z=p2(J.direction,J.offerDirection);J.setCurrentDirection(Z)}if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),await this.gatherCandidates().catch((J)=>{W7("gatherCandidates failed",J)}),G.type==="answer")this.connect().catch((J)=>{W7("connect failed",J),this.secureManager.setConnectionState("failed")});if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),this.shouldNegotiationneeded)this.needNegotiation();return G}async gatherCandidates(){await this.secureManager.gatherCandidates(!!this.sdpManager.remoteIsBundled)}async addIceCandidate(W){let Y=this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport);await this.secureManager.addIceCandidate(Y,W)}async connect(){if(W7("start connect"),(await Promise.allSettled(this.dtlsTransports.map(async(Y)=>{let{iceTransport:G}=Y;if(G.state==="connected")return;let X=()=>Y.state==="connected";if(X())return;if(this.secureManager.setConnectionState("connecting"),await G.start().catch((J)=>{throw W7("iceTransport.start failed",J),J}),X())return;if(await Y.start().catch((J)=>{throw W7("dtlsTransport.start failed",J),J}),this.sctpTransport&&this.sctpTransport.dtlsTransport.id===Y.id)await this.sctpManager.connectSctp()}))).find((Y)=>Y.status==="rejected"))this.secureManager.setConnectionState("failed");else this.secureManager.setConnectionState("connected")}restartIce(){this.needRestart=!0,this.needNegotiation()}async setRemoteDescription(W){if(W instanceof oN)W=W.toSdp();let Y=this.sdpManager.setRemoteDescription(W,this.signalingState);if(Y.group.some((V)=>V.semantic==="BUNDLE"&&V.items.length>0))this.remoteBundleNegotiated=!0;let G,X=(V,U)=>V.kind===U.kind&&[void 0,U.rtp.muxId].includes(V.mid),J=Y.media.map((V,U)=>{let Q;if(["audio","video"].includes(V.kind)){let N=this.transceiverManager.getTransceivers().find((A)=>X(A,V));if(!N)N=this.addTransceiver(V.kind,{direction:"recvonly"}),N.mid=V.rtp.muxId,this.onRemoteTransceiverAdded.execute(N);else if(N.direction==="inactive"&&N.stopping){if(N.stopped=!0,W.type==="answer")N.setCurrentDirection("inactive");return}if(this.sdpManager.remoteIsBundled)if(!G)G=N.dtlsTransport;else N.setDtlsTransport(G);Q=N.dtlsTransport,this.transceiverManager.setRemoteRTP(N,V,Y.type,U)}else if(V.kind==="application"){let N=this.sctpTransport;if(!N)N=this.createSctpTransport(),N.mid=V.rtp.muxId;if(this.sdpManager.remoteIsBundled)if(!G)G=N.dtlsTransport;else N.setDtlsTransport(G);Q=N.dtlsTransport,this.sctpManager.setRemoteSCTP(V,U)}else throw Error("invalid media kind");let H=Q.iceTransport;if(V.iceParams){let N=!!this.sdpManager.inactiveRemoteMedia;if(H.setRemoteParams(V.iceParams,N),V.iceParams?.iceLite)H.connection.iceControlling=!0}if(V.dtlsParams)Q.setRemoteParams(V.dtlsParams);if(V.iceCandidates.forEach(H.addRemoteCandidate),V.iceCandidatesComplete)H.addRemoteCandidate(void 0);if(Y.type==="answer"&&V.dtlsParams?.role)Q.role=V.dtlsParams.role==="client"?"server":"client";return H});J=J.filter((V)=>!!V);let Z=this.transceiverManager.getTransceivers().filter((V)=>Y.media.find((U)=>X(V,U))==null);if(W.type==="answer")for(let V of Z)V.stop(),V.stopped=!0;if(Y.type==="offer")this.setSignalingState("have-remote-offer");else if(Y.type==="answer")this.setSignalingState("stable");if(Y.type==="answer")W7("caller start connect"),this.connect().catch((V)=>{W7("connect failed",V),this.secureManager.setConnectionState("failed")});if(this.negotiationneeded=!1,this.shouldNegotiationneeded)this.needNegotiation()}addTransceiver(W,Y={}){let G=this.findOrCreateTransport(),X=this.transceiverManager.addTransceiver(W,G,Y);return this.secureManager.updateIceConnectionState(),this.needNegotiation(),X}addTrack(W,Y){if(this.isClosed)throw Error("is closed");let G=this.transceiverManager.addTrack(W,Y);if(!G.dtlsTransport){let X=this.findOrCreateTransport();G.setDtlsTransport(X)}return this.needNegotiation(),G.sender}async createAnswer(){return this.assertNotClosed(),await this.secureManager.ensureCerts(),this.sdpManager.buildAnswerSdp({transceivers:this.transceiverManager.getTransceivers(),sctpTransport:this.sctpTransport,signalingState:this.signalingState}).toJSON()}assertNotClosed(){if(this.isClosed)throw Error("RTCPeerConnection is closed")}setSignalingState(W){if(W7("signalingStateChange",W),this.signalingState=W,this.signalingStateChange.execute(W),this.onsignalingstatechange)this.onsignalingstatechange({})}createPeerConnectionStats(){let W=$Y();return{type:"peer-connection",id:Z8("peer-connection"),timestamp:W,dataChannelsOpened:this.sctpManager.dataChannelsOpened,dataChannelsClosed:this.sctpManager.dataChannelsClosed}}async getStats(W){let Y=[];Y.push(this.createPeerConnectionStats());let G=await this.transceiverManager.getStats(W);Y.push(...G);let X=await this.secureManager.getStats();if(Y.push(...X),this.sctpTransport){let J=await this.sctpManager.getStats();if(J)Y.push(...J)}return new Pi(Y)}async close(){if(this.isClosed)return;this.isClosed=!0,this.setSignalingState("closed"),this.transceiverManager.close(),await this.secureManager.close(),await this.sctpManager.close(),this.onDataChannel.allUnsubscribe(),this.iceGatheringStateChange.allUnsubscribe(),this.iceConnectionStateChange.allUnsubscribe(),this.signalingStateChange.allUnsubscribe(),this.onTransceiverAdded.allUnsubscribe(),this.onRemoteTransceiverAdded.allUnsubscribe(),this.onIceCandidate.allUnsubscribe(),W7("peerConnection closed")}},AS=(W,Y)=>W.find((G)=>G.mimeType.toLowerCase()===Y.mimeType.toLowerCase())?Y:void 0;function Qx(){return{codecs:{audio:[_2(),y2()],video:[k2()]},headerExtensions:{audio:[],video:[]},iceTransportPolicy:"all",iceServers:[{urls:"stun:stun.l.google.com:19302"}],icePortRange:void 0,iceInterfaceAddresses:void 0,iceAdditionalHostAddresses:void 0,iceUseIpv4:!0,iceUseIpv6:!0,iceFilterStunResponse:void 0,iceFilterCandidatePair:void 0,icePasswordPrefix:void 0,iceUseLinkLocalAddress:void 0,dtls:{},bundlePolicy:"max-compat",debug:{},midSuffix:!1,forceTurnTCP:!1,maxMessageSize:cV}}var PA0=Qx(),ur=M1("werift:packages/webrtc/src/media/rtpTransceiverManager.ts"),hr=class{constructor(W,Y,G){this.cname=W,this.config=Y,this.router=G}transceivers=[];onTransceiverAdded=new p0;onRemoteTransceiverAdded=new p0;onTrack=new p0;onNegotiationNeeded=new p0;getTransceivers(){return this.transceivers}getSenders(){return this.getTransceivers().map((W)=>W.sender)}getReceivers(){return this.getTransceivers().map((W)=>W.receiver)}getTransceiverByMLineIndex(W){return this.transceivers.find((Y)=>Y.mLineIndex===W)}pushTransceiver(W){this.transceivers.push(W)}replaceTransceiver(W,Y){this.transceivers[Y]=W}addTransceiver(W,Y,G={}){let X=typeof W==="string"?W:W.kind,J=G.direction||"sendrecv",Z=new Sr(W),V=new Vx(this.config,X,Z.ssrc),U=new Li(X,Y,V,Z,J);U.options=G,this.router.registerRtpSender(U.sender);let Q=this.transceivers.findIndex((N)=>N.currentDirection==="inactive"&&!N.usedForSender),H=this.transceivers.find((N)=>N.currentDirection==="inactive"&&!N.usedForSender);if(Q>-1&&H)this.replaceTransceiver(U,Q),U.mLineIndex=H.mLineIndex,U.mid=H.mid,H.setCurrentDirection(void 0);else this.pushTransceiver(U);return this.onTransceiverAdded.execute(U),U}addTrack(W,Y){if(this.getSenders().find((J)=>J.track?.uuid===W.uuid))throw Error("Track already added");let G=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&mN.includes(J.direction)===!0);if(G)return G.sender.registerTrack(W),G;let X=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&mN.includes(J.direction)===!1&&!J.usedForSender);if(X){switch(X.sender.registerTrack(W),X.direction){case"recvonly":X.setDirection("sendrecv");break;case"inactive":X.setDirection("sendonly");break}return X}else return this.addTransceiver(W,void 0,{direction:"sendrecv"})}removeTrack(W){if(!this.getSenders().find(({ssrc:G})=>W.ssrc===G))throw Error("Sender does not exist");let Y=this.transceivers.find(({sender:{ssrc:G}})=>W.ssrc===G);if(!Y)throw Error("No matching transceiver found");if(W.stop(),Y.currentDirection==="recvonly"){this.onNegotiationNeeded.execute();return}if(Y.stopping||Y.stopped)Y.setDirection("inactive");else if(Y.direction==="sendrecv")Y.setDirection("recvonly");else if(Y.direction==="sendonly"||Y.direction==="recvonly")Y.setDirection("inactive")}assignTransceiverCodecs(W){let Y=this.config.codecs[W.kind].filter((G)=>{switch(G.direction){case"recvonly":{if(Mi.includes(W.direction))return!0;return!1}case"sendonly":{if(mN.includes(W.direction))return!0;return!1}case"sendrecv":{if([b2,h2,u2].includes(W.direction))return!0;return!1}case"all":return!0;default:return!1}});W.codecs=Y}getLocalRtpParams(W){if(W.mid==null)throw Error("mid not assigned");return{codecs:W.codecs,muxId:W.mid,headerExtensions:W.headerExtensions,rtcp:{cname:this.cname,ssrc:W.sender.ssrc,mux:!0}}}getRemoteRtpParams(W,Y){return{muxId:W.rtp.muxId,rtcp:W.rtp.rtcp,codecs:Y.codecs,headerExtensions:Y.headerExtensions,encodings:Object.values(Y.codecs.reduce((X,J)=>{if(J.name.toLowerCase()==="rtx"){let Z=Qq(J.parameters??""),V=X[Z.apt];if(V&&W.ssrc.length===2)V.rtx=new Ni({ssrc:W.ssrc[1].ssrc});return X}return X[J.payloadType]=new qi({ssrc:W.ssrc[0]?.ssrc,payloadType:J.payloadType}),X},{}))}}setRemoteRTP(W,Y,G,X){if(!W.mid)W.mid=Y.rtp.muxId;if(W.mLineIndex=X,W.codecs=Y.rtp.codecs.filter((U)=>{let Q=this.config.codecs[Y.kind]||[],H=AS(Q,U);if(!H)return!1;if(H?.name.toLowerCase()==="rtx"){let A=Qq(H.parameters??"").apt,q=Y.rtp.codecs.find((z)=>z.payloadType===A);if(!q)return!1;return!!AS(Q,q)}return!0}),ur("negotiated codecs",W.codecs),W.codecs.length===0)throw Error("negotiate codecs failed.");W.headerExtensions=Y.rtp.headerExtensions.filter((U)=>(this.config.headerExtensions[Y.kind]||[]).find((Q)=>Q.uri===U.uri));let J=Y.direction??"inactive",Z=xi(J);if(["answer","pranswer"].includes(G))W.setCurrentDirection(Z);else W.offerDirection=Z;let V=this.getLocalRtpParams(W);if(W.sender.prepareSend(V),["recvonly","sendrecv"].includes(W.direction)){let U=this.getRemoteRtpParams(Y,W);for(let Q of Y.simulcastParameters)this.router.registerRtpReceiverByRid(W,Q,U);W.receiver.prepareReceive(U),this.router.registerRtpReceiverBySsrc(W,U)}if(["sendonly","sendrecv"].includes(J)){if(Y.msid){let[U,Q]=Y.msid.split(" ");W.receiver.remoteStreamId=U,W.receiver.remoteTrackId=Q}this.onTrack.execute({track:W.receiver.track,transceiver:W,stream:new Ei({id:W.receiver.remoteStreamId,tracks:[W.receiver.track]})})}if(Y.ssrc[0]?.ssrc)W.receiver.setupTWCC(Y.ssrc[0].ssrc)}async getStats(W){let Y=[];for(let G of this.transceivers){let X=!W||G.sender.track===W||G.receiver.track===W;if(G.sender){let J=await G.sender.getStats();if(J)for(let Z of J)if(Z.type==="outbound-rtp"||Z.type==="media-source"){if(X)Y.push(Z)}else Y.push(Z)}if(G.receiver){let J=await G.receiver.getStats();if(J)for(let Z of J)if(Z.type==="inbound-rtp"||Z.type==="remote-outbound-rtp"){if(X)Y.push(Z)}else Y.push(Z)}if(X){let J=G.getCodecStats();if(J)Y.push(...J)}}return Y}close(){for(let W of this.transceivers)W.receiver.stop(),W.sender.stop();this.onTransceiverAdded.allUnsubscribe(),this.onRemoteTransceiverAdded.allUnsubscribe(),this.onTrack.allUnsubscribe(),this.onNegotiationNeeded.allUnsubscribe()}};class NK extends Ux{toJSON(){return{}}createDataChannel(...W){let Y=super.createDataChannel(...W);try{Y.toJSON=()=>({})}catch{}return Y}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var lX={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},br={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},mr=BigInt(0),Hx=BigInt(1),qK=BigInt(2);function fr(W){let Y=lX.p,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=Q5(N,G,Y)*N%Y,q=Q5(A,G,Y)*N%Y,z=Q5(q,qK,Y)*H%Y,w=Q5(z,J,Y)*z%Y,D=Q5(w,Z,Y)*w%Y,T=Q5(D,U,Y)*D%Y,x=Q5(T,Q,Y)*T%Y,g=Q5(x,U,Y)*D%Y,f=Q5(g,G,Y)*N%Y,y=Q5(f,V,Y)*w%Y,p=Q5(y,X,Y)*H%Y,b=Q5(p,qK,Y);if(!Oq.eql(Oq.sqr(b),W))throw Error("Cannot find square root");return b}var Oq=B5(lX.p,{sqrt:fr}),Ax=CX({...lX,Fp:Oq,lowS:!0,endo:br},OX),Nx={};function Kq(W,...Y){let G=Nx[W];if(G===void 0){let X=OX(HN(W));G=i9(X,X),Nx[W]=G}return OX(i9(G,...Y))}var IK=(W)=>W.toBytes(!0).slice(1),dX=(()=>Ax.Point)(),zK=(W)=>W%qK===mr;function AK(W){let{Fn:Y,BASE:G}=dX,X=d6(Y,W),J=G.multiply(X);return{scalar:zK(J.y)?X:Y.neg(X),bytes:IK(J)}}function Ix(W){let Y=Oq;if(!Y.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=Y.create(W*W),X=Y.create(G*W+BigInt(7)),J=Y.sqrt(X);if(!zK(J))J=Y.neg(J);let Z=dX.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var qU=B4;function zx(...W){return dX.Fn.create(qU(Kq("BIP0340/challenge",...W)))}function qx(W){return AK(W).bytes}function cr(W,Y,G=NY(32)){let{Fn:X}=dX,J=B8("message",W),{bytes:Z,scalar:V}=AK(Y),U=B8("auxRand",G,32),Q=X.toBytes(V^qU(Kq("BIP0340/aux",U))),H=Kq("BIP0340/nonce",Q,Z,J),{bytes:N,scalar:A}=AK(H),q=zx(N,Z,J),z=new Uint8Array(64);if(z.set(N,0),z.set(X.toBytes(X.create(A+q*V)),32),!wx(z,J,Z))throw Error("sign: Invalid signature produced");return z}function wx(W,Y,G){let{Fn:X,BASE:J}=dX,Z=B8("signature",W,64),V=B8("message",Y),U=B8("publicKey",G,32);try{let Q=Ix(qU(U)),H=qU(Z.subarray(0,32));if(!PV(H,Hx,lX.p))return!1;let N=qU(Z.subarray(32,64));if(!PV(N,Hx,lX.n))return!1;let A=zx(X.toBytes(H),IK(Q),V),q=J.multiplyUnsafe(N).add(Q.multiplyUnsafe(X.neg(A))),{x:z,y:w}=q.toAffine();if(q.is0()||!zK(w)||z!==H)return!1;return!0}catch(Q){return!1}}var jx=(()=>{let G=(J=NY(48))=>{return zN(J,lX.n)};Ax.utils.randomSecretKey;function X(J){let Z=G(J);return{secretKey:Z,publicKey:qx(Z)}}return{keygen:X,getPublicKey:qx,sign:cr,verify:wx,Point:dX,utils:{randomSecretKey:G,randomPrivateKey:G,taggedHash:Kq,lift_x:Ix,pointToBytes:IK,numberToBytesBE:jX,bytesToNumberBE:B4,mod:U5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Ox=(W)=>Uint8Array.from(W.match(/.{2}/g).map((Y)=>parseInt(Y,16))),pr=(W)=>[...W].map((Y)=>Y.toString(16).padStart(2,"0")).join(""),lr=async(W)=>{try{if(typeof W.pubkey!=="string"||typeof W.sig!=="string"||typeof W.id!=="string")return!1;let Y=new TextEncoder().encode(JSON.stringify([0,W.pubkey,W.created_at,W.kind,W.tags,W.content])),G=new Uint8Array(await crypto.subtle.digest("SHA-256",Y));if(pr(G)!==W.id)return!1;return jx.verify(Ox(W.sig),G,Ox(W.pubkey))}catch{return!1}},dr=(W,Y)=>{if(W.kinds&&!W.kinds.includes(Y.kind))return!1;if(W.since&&Y.created_at<W.since-60)return!1;if(W["#x"]){let G=(Y.tags??[]).filter((X)=>X?.[0]==="x").map((X)=>X[1]);if(!W["#x"].some((X)=>G.includes(X)))return!1}return!0};function Kx({port:W=Number(process.env.PORT)||8080}={}){let Y=new Map,G=0,X=0,J=Bun.serve({port:W,fetch(Z,V){if(V.upgrade(Z))return;return Response.json({relay:"GenosSRV embedded relay",protocol:"nostr (ephemeral subset)",connections:Y.size,events:G,dropped:X})},websocket:{open(Z){Y.set(Z,new Map)},close(Z){Y.delete(Z)},async message(Z,V){let U;try{U=JSON.parse(String(V))}catch{return}if(!Array.isArray(U))return;let[Q,H,N]=U;if(Q==="REQ"&&typeof H==="string"&&N&&typeof N==="object"){Y.get(Z)?.set(H,N),Z.send(JSON.stringify(["EOSE",H]));return}if(Q==="CLOSE"&&typeof H==="string"){Y.get(Z)?.delete(H);return}if(Q==="EVENT"&&H&&typeof H==="object"){if(!await lr(H)){X++,Z.send(JSON.stringify(["OK",H.id??"",!1,"invalid: bad signature"]));return}G++,Z.send(JSON.stringify(["OK",H.id,!0,""]));for(let[A,q]of Y)for(let[z,w]of q)if(dr(w,H)){try{A.send(JSON.stringify(["EVENT",z,H]))}catch{}break}}}}});return console.info(`\uD83D\uDCE1 Relay listening on :${J.port} (ephemeral, schnorr-verified)`),{port:J.port,stats:()=>({connections:Y.size,events:G,dropped:X}),stop:()=>J.stop(!0)}}var Dq="6.15.0";function or(W,Y,G){let X=Y.split("|").map((Z)=>Z.trim());for(let Z=0;Z<X.length;Z++)switch(Y){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof W===Y)return}let J=Error(`invalid value for type ${Y}`);throw J.code="INVALID_ARGUMENT",J.argument=`value.${G}`,J.value=W,J}async function o7(W){let Y=Object.keys(W);return(await Promise.all(Y.map((X)=>Promise.resolve(W[X])))).reduce((X,J,Z)=>{return X[Y[Z]]=J,X},{})}function H8(W,Y,G){for(let X in Y){let J=Y[X],Z=G?G[X]:null;if(Z)or(J,Z,X);Object.defineProperty(W,X,{enumerable:!0,value:J,writable:!1})}}function oX(W,Y){if(W==null)return"null";if(Y==null)Y=new Set;if(typeof W==="object"){if(Y.has(W))return"[Circular]";Y.add(W)}if(Array.isArray(W))return"[ "+W.map((G)=>oX(G,Y)).join(", ")+" ]";if(W instanceof Uint8Array){let X="0x";for(let J=0;J<W.length;J++)X+="0123456789abcdef"[W[J]>>4],X+="0123456789abcdef"[W[J]&15];return X}if(typeof W==="object"&&typeof W.toJSON==="function")return oX(W.toJSON(),Y);switch(typeof W){case"boolean":case"number":case"symbol":return W.toString();case"bigint":return BigInt(W).toString();case"string":return JSON.stringify(W);case"object":{let G=Object.keys(W);return G.sort(),"{ "+G.map((X)=>`${oX(X,Y)}: ${oX(W[X],Y)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function Cq(W,Y){return W&&W.code===Y}function AU(W,Y,G){let X=W;{let Z=[];if(G){if("message"in G||"code"in G||"name"in G)throw Error(`value will overwrite populated values: ${oX(G)}`);for(let V in G){if(V==="shortMessage")continue;let U=G[V];Z.push(V+"="+oX(U))}}if(Z.push(`code=${Y}`),Z.push(`version=${Dq}`),Z.length)W+=" ("+Z.join(", ")+")"}let J;switch(Y){case"INVALID_ARGUMENT":J=TypeError(W);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":J=RangeError(W);break;default:J=Error(W)}if(H8(J,{code:Y}),G)Object.assign(J,G);if(J.shortMessage==null)H8(J,{shortMessage:X});return J}function X1(W,Y,G,X){if(!W)throw AU(Y,G,X)}function r(W,Y,G,X){X1(W,Y,"INVALID_ARGUMENT",{argument:G,value:X})}var nr=["NFD","NFC","NFKD","NFKC"].reduce((W,Y)=>{try{if("test".normalize(Y)!=="test")throw Error("bad");if(Y==="NFD"){let G=String.fromCharCode(233).normalize("NFD"),X=String.fromCharCode(101,769);if(G!==X)throw Error("broken")}W.push(Y)}catch(G){}return W},[]);function nX(W){X1(nr.indexOf(W)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:W}})}function d4(W,Y,G){if(G==null)G="";if(W!==Y){let X=G,J="new";if(G)X+=".",J+=" "+G;X1(!1,`private constructor; use ${X}from* methods`,"UNSUPPORTED_OPERATION",{operation:J})}}function Cx(W,Y,G){if(W instanceof Uint8Array){if(G)return new Uint8Array(W);return W}if(typeof W==="string"&&W.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)){let X=new Uint8Array((W.length-2)/2),J=2;for(let Z=0;Z<X.length;Z++)X[Z]=parseInt(W.substring(J,J+2),16),J+=2;return X}r(!1,"invalid BytesLike value",Y||"value",W)}function B0(W,Y){return Cx(W,Y,!1)}function Z7(W,Y){return Cx(W,Y,!0)}function R9(W,Y){if(typeof W!=="string"||!W.match(/^0x[0-9A-Fa-f]*$/))return!1;if(typeof Y==="number"&&W.length!==2+2*Y)return!1;if(Y===!0&&W.length%2!==0)return!1;return!0}function n7(W){return R9(W,!0)||W instanceof Uint8Array}var Dx="0123456789abcdef";function C0(W){let Y=B0(W),G="0x";for(let X=0;X<Y.length;X++){let J=Y[X];G+=Dx[(J&240)>>4]+Dx[J&15]}return G}function t1(W){return"0x"+W.map((Y)=>C0(Y).substring(2)).join("")}function o4(W){if(R9(W,!0))return(W.length-2)/2;return B0(W).length}function iX(W,Y,G){let X=B0(W);if(G!=null&&G>X.length)X1(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:X,length:X.length,offset:G});return C0(X.slice(Y==null?0:Y,G==null?X.length:G))}function ir(W,Y,G){let X=B0(W);X1(Y>=X.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(X),length:Y,offset:Y+1});let J=new Uint8Array(Y);if(J.fill(0),G)J.set(X,Y-X.length);else J.set(X,0);return C0(J)}function A5(W,Y){return ir(W,Y,!0)}var wK=BigInt(0),FY=BigInt(1),rX=9007199254740991;function Tq(W,Y){let G=g1(W,"value"),X=BigInt(r8(Y,"width")),J=FY<<X-FY;if(G<wK){G=-G,X1(G<=J,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});let Z=(FY<<X)-FY;return(~G&Z)+FY}else X1(G<J,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});return G}function Rq(W,Y){let G=IU(W,"value"),X=BigInt(r8(Y,"bits"));return G&(FY<<X)-FY}function g1(W,Y){switch(typeof W){case"bigint":return W;case"number":return r(Number.isInteger(W),"underflow",Y||"value",W),r(W>=-rX&&W<=rX,"overflow",Y||"value",W),BigInt(W);case"string":try{if(W==="")throw Error("empty string");if(W[0]==="-"&&W[1]!=="-")return-BigInt(W.substring(1));return BigInt(W)}catch(G){r(!1,`invalid BigNumberish string: ${G.message}`,Y||"value",W)}}r(!1,"invalid BigNumberish value",Y||"value",W)}function IU(W,Y){let G=g1(W,Y);return X1(G>=wK,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:W}),G}var Tx="0123456789abcdef";function aX(W){if(W instanceof Uint8Array){let Y="0x0";for(let G of W)Y+=Tx[G>>4],Y+=Tx[G&15];return BigInt(Y)}return g1(W)}function r8(W,Y){switch(typeof W){case"bigint":return r(W>=-rX&&W<=rX,"overflow",Y||"value",W),Number(W);case"number":return r(Number.isInteger(W),"underflow",Y||"value",W),r(W>=-rX&&W<=rX,"overflow",Y||"value",W),W;case"string":try{if(W==="")throw Error("empty string");return r8(BigInt(W),Y)}catch(G){r(!1,`invalid numeric string: ${G.message}`,Y||"value",W)}}r(!1,"invalid numeric value",Y||"value",W)}function V7(W,Y){let X=IU(W,"value").toString(16);if(Y==null){if(X.length%2)X="0"+X}else{let J=r8(Y,"width");X1(J*2>=X.length,`value exceeds width (${J} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:W});while(X.length<J*2)X="0"+X}return"0x"+X}function N8(W){let Y=IU(W,"value");if(Y===wK)return new Uint8Array([]);let G=Y.toString(16);if(G.length%2)G="0"+G;let X=new Uint8Array(G.length/2);for(let J=0;J<X.length;J++){let Z=J*2;X[J]=parseInt(G.substring(Z,Z+2),16)}return X}function Mq(W){let Y=C0(n7(W)?W:N8(W)).substring(2);while(Y.startsWith("0"))Y=Y.substring(1);if(Y==="")Y="0";return"0x"+Y}var Lq="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Pq=null;function rr(W){if(Pq==null){Pq={};for(let G=0;G<Lq.length;G++)Pq[Lq[G]]=BigInt(G)}let Y=Pq[W];return r(Y!=null,"invalid base58 value","letter",W),Y}var ar=BigInt(0),jK=BigInt(58);function Bq(W){let Y=B0(W),G=aX(Y),X="";while(G)X=Lq[Number(G%jK)]+X,G/=jK;for(let J=0;J<Y.length;J++){if(Y[J])break;X=Lq[0]+X}return X}function Eq(W){let Y=ar;for(let G=0;G<W.length;G++)Y*=jK,Y+=rr(W[G]);return Y}function sr(W,Y,G,X,J){r(!1,`invalid codepoint at offset ${Y}; ${W}`,"bytes",G)}function Rx(W,Y,G,X,J){if(W==="BAD_PREFIX"||W==="UNEXPECTED_CONTINUE"){let Z=0;for(let V=Y+1;V<G.length;V++){if(G[V]>>6!==2)break;Z++}return Z}if(W==="OVERRUN")return G.length-Y-1;return 0}function tr(W,Y,G,X,J){if(W==="OVERLONG")return r(typeof J==="number","invalid bad code point for replacement","badCodepoint",J),X.push(J),0;return X.push(65533),Rx(W,Y,G,X,J)}var Mx=Object.freeze({error:sr,ignore:Rx,replace:tr});function M9(W,Y){if(r(typeof W==="string","invalid string value","str",W),Y!=null)nX(Y),W=W.normalize(Y);let G=[];for(let X=0;X<W.length;X++){let J=W.charCodeAt(X);if(J<128)G.push(J);else if(J<2048)G.push(J>>6|192),G.push(J&63|128);else if((J&64512)==55296){X++;let Z=W.charCodeAt(X);r(X<W.length&&(Z&64512)===56320,"invalid surrogate pair","str",W);let V=65536+((J&1023)<<10)+(Z&1023);G.push(V>>18|240),G.push(V>>12&63|128),G.push(V>>6&63|128),G.push(V&63|128)}else G.push(J>>12|224),G.push(J>>6&63|128),G.push(J&63|128)}return new Uint8Array(G)}function er(W){let Y=W.toString(16);while(Y.length<2)Y="0"+Y;return"0x"+Y}function Px(W,Y,G){let X=0;for(let J=0;J<G;J++)X=X*256+W[Y+J];return X}function Lx(W,Y,G,X){let J=[];while(G<Y+1+X){let Z=Bx(W,G);J.push(Z.result),G+=Z.consumed,X1(G<=Y+1+X,"child data too short","BUFFER_OVERRUN",{buffer:W,length:X,offset:Y})}return{consumed:1+X,result:J}}function Bx(W,Y){X1(W.length!==0,"data too short","BUFFER_OVERRUN",{buffer:W,length:0,offset:1});let G=(X)=>{X1(X<=W.length,"data short segment too short","BUFFER_OVERRUN",{buffer:W,length:W.length,offset:X})};if(W[Y]>=248){let X=W[Y]-247;G(Y+1+X);let J=Px(W,Y+1,X);return G(Y+1+X+J),Lx(W,Y,Y+1+X,X+J)}else if(W[Y]>=192){let X=W[Y]-192;return G(Y+1+X),Lx(W,Y,Y+1,X)}else if(W[Y]>=184){let X=W[Y]-183;G(Y+1+X);let J=Px(W,Y+1,X);G(Y+1+X+J);let Z=C0(W.slice(Y+1+X,Y+1+X+J));return{consumed:1+X+J,result:Z}}else if(W[Y]>=128){let X=W[Y]-128;G(Y+1+X);let J=C0(W.slice(Y+1,Y+1+X));return{consumed:1+X,result:J}}return{consumed:1,result:er(W[Y])}}function WW(W){let Y=B0(W,"data"),G=Bx(Y,0);return r(G.consumed===Y.length,"unexpected junk after rlp payload","data",W),G.result}function Ex(W){let Y=[];while(W)Y.unshift(W&255),W>>=8;return Y}function Fx(W){if(Array.isArray(W)){let X=[];if(W.forEach(function(Z){X=X.concat(Fx(Z))}),X.length<=55)return X.unshift(192+X.length),X;let J=Ex(X.length);return J.unshift(247+J.length),J.concat(X)}let Y=Array.prototype.slice.call(B0(W,"object"));if(Y.length===1&&Y[0]<=127)return Y;else if(Y.length<=55)return Y.unshift(128+Y.length),Y;let G=Ex(Y.length);return G.unshift(183+G.length),G.concat(Y)}var $x="0123456789abcdef";function $5(W){let Y="0x";for(let G of Fx(W))Y+=$x[G>>4],Y+=$x[G&15];return Y}function $q(W){let Y=B0(W,"randomBytes");Y[6]=Y[6]&15|64,Y[8]=Y[8]&63|128;let G=C0(Y);return[G.substring(2,10),G.substring(10,14),G.substring(14,18),G.substring(18,22),G.substring(22,34)].join("-")}import{createHash as OK,createHmac as Sx,pbkdf2Sync as xx,randomBytes as kx}from"crypto";var _x=!1,yx=function(W,Y,G){return Sx(W,Y).update(G).digest()},vx=yx;function YW(W,Y,G){let X=B0(Y,"key"),J=B0(G,"data");return C0(vx(W,X,J))}YW._=yx;YW.lock=function(){_x=!0};YW.register=function(W){if(_x)throw Error("computeHmac is locked");vx=W};Object.freeze(YW);function P9(W){if(!Number.isSafeInteger(W)||W<0)throw Error(`Wrong positive integer: ${W}`)}function zU(W,...Y){if(!(W instanceof Uint8Array))throw Error("Expected Uint8Array");if(Y.length>0&&!Y.includes(W.length))throw Error(`Expected Uint8Array of length ${Y}, not of length=${W.length}`)}function Fq(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.wrapConstructor");P9(W.outputLen),P9(W.blockLen)}function n4(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function Sq(W,Y){zU(W);let G=Y.outputLen;if(W.length<G)throw Error(`digestInto() expects output buffer of length at least ${G}`)}var xq=BigInt(4294967295),gx=BigInt(32);function Qa(W,Y=!1){if(Y)return{h:Number(W&xq),l:Number(W>>gx&xq)};return{h:Number(W>>gx&xq)|0,l:Number(W&xq)|0}}function ux(W,Y=!1){let G=new Uint32Array(W.length),X=new Uint32Array(W.length);for(let J=0;J<W.length;J++){let{h:Z,l:V}=Qa(W[J],Y);[G[J],X[J]]=[Z,V]}return[G,X]}var hx=(W,Y,G)=>W<<G|Y>>>32-G,bx=(W,Y,G)=>Y<<G|W>>>32-G,mx=(W,Y,G)=>Y<<G-32|W>>>64-G,fx=(W,Y,G)=>W<<G-32|Y>>>64-G;import*as wU from"crypto";var kq=wU&&typeof wU==="object"&&"webcrypto"in wU?wU.webcrypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var cx=(W)=>W instanceof Uint8Array;var sX=(W)=>new Uint32Array(W.buffer,W.byteOffset,Math.floor(W.byteLength/4)),tX=(W)=>new DataView(W.buffer,W.byteOffset,W.byteLength),U7=(W,Y)=>W<<32-Y|W>>>Y,Ha=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ha)throw Error("Non little-endian hardware is not supported");var Na=async()=>{};async function _q(W,Y,G){let X=Date.now();for(let J=0;J<W;J++){G(J);let Z=Date.now()-X;if(Z>=0&&Z<Y)continue;await Na(),X+=Z}}function qa(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function i7(W){if(typeof W==="string")W=qa(W);if(!cx(W))throw Error(`expected Uint8Array, got ${typeof W}`);return W}function px(...W){let Y=new Uint8Array(W.reduce((X,J)=>X+J.length,0)),G=0;return W.forEach((X)=>{if(!cx(X))throw Error("Uint8Array expected");Y.set(X,G),G+=X.length}),Y}class SY{clone(){return this._cloneInto()}}var Aa={}.toString;function yq(W,Y){if(Y!==void 0&&Aa.call(Y)!=="[object Object]")throw Error("Options should be object or undefined");return Object.assign(W,Y)}function eX(W){let Y=(X)=>W().update(i7(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function lx(W=32){if(kq&&typeof kq.getRandomValues==="function")return kq.getRandomValues(new Uint8Array(W));throw Error("crypto.getRandomValues must be defined")}var[nx,ix,rx]=[[],[],[]],Ia=BigInt(0),jU=BigInt(1),za=BigInt(2),wa=BigInt(7),ja=BigInt(256),Oa=BigInt(113);for(let W=0,Y=jU,G=1,X=0;W<24;W++){[G,X]=[X,(2*G+3*X)%5],nx.push(2*(5*X+G)),ix.push((W+1)*(W+2)/2%64);let J=Ia;for(let Z=0;Z<7;Z++)if(Y=(Y<<jU^(Y>>wa)*Oa)%ja,Y&za)J^=jU<<(jU<<BigInt(Z))-jU;rx.push(J)}var[Ka,Da]=ux(rx,!0),dx=(W,Y,G)=>G>32?mx(W,Y,G):hx(W,Y,G),ox=(W,Y,G)=>G>32?fx(W,Y,G):bx(W,Y,G);function Ca(W,Y=24){let G=new Uint32Array(10);for(let X=24-Y;X<24;X++){for(let V=0;V<10;V++)G[V]=W[V]^W[V+10]^W[V+20]^W[V+30]^W[V+40];for(let V=0;V<10;V+=2){let U=(V+8)%10,Q=(V+2)%10,H=G[Q],N=G[Q+1],A=dx(H,N,1)^G[U],q=ox(H,N,1)^G[U+1];for(let z=0;z<50;z+=10)W[V+z]^=A,W[V+z+1]^=q}let J=W[2],Z=W[3];for(let V=0;V<24;V++){let U=ix[V],Q=dx(J,Z,U),H=ox(J,Z,U),N=nx[V];J=W[N],Z=W[N+1],W[N]=Q,W[N+1]=H}for(let V=0;V<50;V+=10){for(let U=0;U<10;U++)G[U]=W[V+U];for(let U=0;U<10;U++)W[V+U]^=~G[(U+2)%10]&G[(U+4)%10]}W[0]^=Ka[X],W[1]^=Da[X]}G.fill(0)}class KK extends SY{constructor(W,Y,G,X=!1,J=24){super();if(this.blockLen=W,this.suffix=Y,this.outputLen=G,this.enableXOF=X,this.rounds=J,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,P9(G),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=sX(this.state)}keccak(){Ca(this.state32,this.rounds),this.posOut=0,this.pos=0}update(W){n4(this);let{blockLen:Y,state:G}=this;W=i7(W);let X=W.length;for(let J=0;J<X;){let Z=Math.min(Y-this.pos,X-J);for(let V=0;V<Z;V++)G[this.pos++]^=W[J++];if(this.pos===Y)this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:W,suffix:Y,pos:G,blockLen:X}=this;if(W[G]^=Y,(Y&128)!==0&&G===X-1)this.keccak();W[X-1]^=128,this.keccak()}writeInto(W){n4(this,!1),zU(W),this.finish();let Y=this.state,{blockLen:G}=this;for(let X=0,J=W.length;X<J;){if(this.posOut>=G)this.keccak();let Z=Math.min(G-this.posOut,J-X);W.set(Y.subarray(this.posOut,this.posOut+Z),X),this.posOut+=Z,X+=Z}return W}xofInto(W){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(W)}xof(W){return P9(W),this.xofInto(new Uint8Array(W))}digestInto(W){if(Sq(W,this),this.finished)throw Error("digest() was already called");return this.writeInto(W),this.destroy(),W}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(W){let{blockLen:Y,suffix:G,outputLen:X,rounds:J,enableXOF:Z}=this;return W||(W=new KK(Y,G,X,Z,J)),W.state32.set(this.state32),W.pos=this.pos,W.posOut=this.posOut,W.finished=this.finished,W.rounds=J,W.suffix=G,W.outputLen=X,W.enableXOF=Z,W.destroyed=this.destroyed,W}}var Ta=(W,Y,G)=>eX(()=>new KK(Y,W,G));var ax=Ta(1,136,32);var sx=!1,tx=function(W){return ax(W)},ex=tx;function X8(W){let Y=B0(W,"data");return C0(ex(Y))}X8._=tx;X8.lock=function(){sx=!0};X8.register=function(W){if(sx)throw TypeError("keccak256 is locked");ex=W};Object.freeze(X8);function Ra(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}class OU extends SY{constructor(W,Y,G,X){super();this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(W),this.view=tX(this.buffer)}update(W){n4(this);let{view:Y,buffer:G,blockLen:X}=this;W=i7(W);let J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=tX(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){n4(this),Sq(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,this.buffer.subarray(Z).fill(0),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Ra(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=tX(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.length=X,W.pos=V,W.finished=J,W.destroyed=Z,X%Y)W.buffer.set(G);return W}}var Ma=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Yk=Uint8Array.from({length:16},(W,Y)=>Y),Pa=Yk.map((W)=>(9*W+5)%16),DK=[Yk],CK=[Pa];for(let W=0;W<4;W++)for(let Y of[DK,CK])Y.push(Y[W].map((G)=>Ma[G]));var Gk=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((W)=>new Uint8Array(W)),La=DK.map((W,Y)=>W.map((G)=>Gk[Y][G])),Ba=CK.map((W,Y)=>W.map((G)=>Gk[Y][G])),Ea=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),$a=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),vq=(W,Y)=>W<<Y|W>>>32-Y;function Wk(W,Y,G,X){if(W===0)return Y^G^X;else if(W===1)return Y&G|~Y&X;else if(W===2)return(Y|~G)^X;else if(W===3)return Y&X|G&~X;else return Y^(G|~X)}var gq=new Uint32Array(16);class Xk extends OU{constructor(){super(64,20,8,!0);this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:W,h1:Y,h2:G,h3:X,h4:J}=this;return[W,Y,G,X,J]}set(W,Y,G,X,J){this.h0=W|0,this.h1=Y|0,this.h2=G|0,this.h3=X|0,this.h4=J|0}process(W,Y){for(let q=0;q<16;q++,Y+=4)gq[q]=W.getUint32(Y,!0);let G=this.h0|0,X=G,J=this.h1|0,Z=J,V=this.h2|0,U=V,Q=this.h3|0,H=Q,N=this.h4|0,A=N;for(let q=0;q<5;q++){let z=4-q,w=Ea[q],D=$a[q],T=DK[q],x=CK[q],g=La[q],f=Ba[q];for(let y=0;y<16;y++){let p=vq(G+Wk(q,J,V,Q)+gq[T[y]]+w,g[y])+N|0;G=N,N=Q,Q=vq(V,10)|0,V=J,J=p}for(let y=0;y<16;y++){let p=vq(X+Wk(z,Z,U,H)+gq[x[y]]+D,f[y])+A|0;X=A,A=H,H=vq(U,10)|0,U=Z,Z=p}}this.set(this.h1+V+H|0,this.h2+Q+A|0,this.h3+N+X|0,this.h4+G+Z|0,this.h0+J+U|0)}roundClean(){gq.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}var Jk=eX(()=>new Xk);var Zk=!1,Vk=function(W){return Jk(W)},Uk=Vk;function GW(W){let Y=B0(W,"data");return C0(Uk(Y))}GW._=Vk;GW.lock=function(){Zk=!0};GW.register=function(W){if(Zk)throw TypeError("ripemd160 is locked");Uk=W};Object.freeze(GW);var Qk=!1,Hk=function(W,Y,G,X,J){return xx(W,Y,G,X,J)},Nk=Hk;function F5(W,Y,G,X,J){let Z=B0(W,"password"),V=B0(Y,"salt");return C0(Nk(Z,V,G,X,J))}F5._=Hk;F5.lock=function(){Qk=!0};F5.register=function(W){if(Qk)throw Error("pbkdf2 is locked");Nk=W};Object.freeze(F5);var qk=!1,Ak=function(W){return new Uint8Array(kx(W))},Ik=Ak;function S5(W){return Ik(W)}S5._=Ak;S5.lock=function(){qk=!0};S5.register=function(W){if(qk)throw Error("randomBytes is locked");Ik=W};Object.freeze(S5);var Fa=(W,Y,G)=>W&Y^~W&G,Sa=(W,Y,G)=>W&Y^W&G^Y&G,xa=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]),XW=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),JW=new Uint32Array(64);class zk extends OU{constructor(){super(64,32,8,!1);this.A=XW[0]|0,this.B=XW[1]|0,this.C=XW[2]|0,this.D=XW[3]|0,this.E=XW[4]|0,this.F=XW[5]|0,this.G=XW[6]|0,this.H=XW[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)JW[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=JW[N-15],q=JW[N-2],z=U7(A,7)^U7(A,18)^A>>>3,w=U7(q,17)^U7(q,19)^q>>>10;JW[N]=w+JW[N-7]+z+JW[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=U7(V,6)^U7(V,11)^U7(V,25),q=H+A+Fa(V,U,Q)+xa[N]+JW[N]|0,w=(U7(G,2)^U7(G,13)^U7(G,22))+Sa(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+w|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){JW.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}var KU=eX(()=>new zk);class TK extends SY{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,Fq(W);let G=i7(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),J.fill(0)}update(W){return n4(this),this.iHash.update(W),this}digestInto(W){n4(this),zU(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var DU=(W,Y,G)=>new TK(W,Y).update(G).digest();DU.create=(W,Y)=>new TK(W,Y);function ka(W,Y,G,X){Fq(W);let J=yq({dkLen:32,asyncTick:10},X),{c:Z,dkLen:V,asyncTick:U}=J;if(P9(Z),P9(V),P9(U),Z<1)throw Error("PBKDF2: iterations (c) should be >= 1");let Q=i7(Y),H=i7(G),N=new Uint8Array(V),A=DU.create(W,Q),q=A._cloneInto().update(H);return{c:Z,dkLen:V,asyncTick:U,DK:N,PRF:A,PRFSalt:q}}function _a(W,Y,G,X,J){if(W.destroy(),Y.destroy(),X)X.destroy();return J.fill(0),G}function RK(W,Y,G,X){let{c:J,dkLen:Z,DK:V,PRF:U,PRFSalt:Q}=ka(W,Y,G,X),H,N=new Uint8Array(4),A=tX(N),q=new Uint8Array(U.outputLen);for(let z=1,w=0;w<Z;z++,w+=U.outputLen){let D=V.subarray(w,w+U.outputLen);A.setInt32(0,z,!1),(H=Q._cloneInto(H)).update(N).digestInto(q),D.set(q.subarray(0,D.length));for(let T=1;T<J;T++){U._cloneInto(H).update(q).digestInto(q);for(let x=0;x<D.length;x++)D[x]^=q[x]}}return _a(U,Q,V,H,q)}var n1=(W,Y)=>W<<Y|W>>>32-Y;function wk(W,Y,G,X,J,Z){let V=W[Y++]^G[X++],U=W[Y++]^G[X++],Q=W[Y++]^G[X++],H=W[Y++]^G[X++],N=W[Y++]^G[X++],A=W[Y++]^G[X++],q=W[Y++]^G[X++],z=W[Y++]^G[X++],w=W[Y++]^G[X++],D=W[Y++]^G[X++],T=W[Y++]^G[X++],x=W[Y++]^G[X++],g=W[Y++]^G[X++],f=W[Y++]^G[X++],y=W[Y++]^G[X++],p=W[Y++]^G[X++],b=V,m=U,W0=Q,u=H,J0=N,A0=A,k=q,l=z,B=w,$=D,h=T,a=x,n=g,E=f,P=y,v=p;for(let M=0;M<8;M+=2)J0^=n1(b+n|0,7),B^=n1(J0+b|0,9),n^=n1(B+J0|0,13),b^=n1(n+B|0,18),$^=n1(A0+m|0,7),E^=n1($+A0|0,9),m^=n1(E+$|0,13),A0^=n1(m+E|0,18),P^=n1(h+k|0,7),W0^=n1(P+h|0,9),k^=n1(W0+P|0,13),h^=n1(k+W0|0,18),u^=n1(v+a|0,7),l^=n1(u+v|0,9),a^=n1(l+u|0,13),v^=n1(a+l|0,18),m^=n1(b+u|0,7),W0^=n1(m+b|0,9),u^=n1(W0+m|0,13),b^=n1(u+W0|0,18),k^=n1(A0+J0|0,7),l^=n1(k+A0|0,9),J0^=n1(l+k|0,13),A0^=n1(J0+l|0,18),a^=n1(h+$|0,7),B^=n1(a+h|0,9),$^=n1(B+a|0,13),h^=n1($+B|0,18),n^=n1(v+P|0,7),E^=n1(n+v|0,9),P^=n1(E+n|0,13),v^=n1(P+E|0,18);J[Z++]=V+b|0,J[Z++]=U+m|0,J[Z++]=Q+W0|0,J[Z++]=H+u|0,J[Z++]=N+J0|0,J[Z++]=A+A0|0,J[Z++]=q+k|0,J[Z++]=z+l|0,J[Z++]=w+B|0,J[Z++]=D+$|0,J[Z++]=T+h|0,J[Z++]=x+a|0,J[Z++]=g+n|0,J[Z++]=f+E|0,J[Z++]=y+P|0,J[Z++]=p+v|0}function WJ(W,Y,G,X,J){let Z=X+0,V=X+16*J;for(let U=0;U<16;U++)G[V+U]=W[Y+(2*J-1)*16+U];for(let U=0;U<J;U++,Z+=16,Y+=16){if(wk(G,V,W,Y,G,Z),U>0)V+=16;wk(G,Z,W,Y+=16,G,V)}}function jk(W,Y,G){let X=yq({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:J,r:Z,p:V,dkLen:U,asyncTick:Q,maxmem:H,onProgress:N}=X;if(P9(J),P9(Z),P9(V),P9(U),P9(Q),P9(H),N!==void 0&&typeof N!=="function")throw Error("progressCb should be function");let A=128*Z,q=A/4;if(J<=1||(J&J-1)!==0||J>=2**(A/8)||J>4294967296)throw Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");if(V<0||V>137438953440/A)throw Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(U<0||U>137438953440)throw Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");let z=A*(J+V);if(z>H)throw Error(`Scrypt: parameters too large, ${z} (128 * r * (N + p)) > ${H} (maxmem)`);let w=RK(KU,W,Y,{c:1,dkLen:A*V}),D=sX(w),T=sX(new Uint8Array(A*J)),x=sX(new Uint8Array(A)),g=()=>{};if(N){let f=2*J*V,y=Math.max(Math.floor(f/1e4),1),p=0;g=()=>{if(p++,N&&(!(p%y)||p===f))N(p/f)}}return{N:J,r:Z,p:V,dkLen:U,blockSize32:q,V:T,B32:D,B:w,tmp:x,blockMixCb:g,asyncTick:Q}}function Ok(W,Y,G,X,J){let Z=RK(KU,W,G,{c:1,dkLen:Y});return G.fill(0),X.fill(0),J.fill(0),Z}function Kk(W,Y,G){let{N:X,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:H,B:N,tmp:A,blockMixCb:q}=jk(W,Y,G);for(let z=0;z<Z;z++){let w=U*z;for(let D=0;D<U;D++)Q[D]=H[w+D];for(let D=0,T=0;D<X-1;D++)WJ(Q,T,Q,T+=U,J),q();WJ(Q,(X-1)*U,H,w,J),q();for(let D=0;D<X;D++){let T=H[w+U-16]%X;for(let x=0;x<U;x++)A[x]=H[w+x]^Q[T*U+x];WJ(A,0,H,w,J),q()}}return Ok(W,V,N,Q,A)}async function Dk(W,Y,G){let{N:X,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:H,B:N,tmp:A,blockMixCb:q,asyncTick:z}=jk(W,Y,G);for(let w=0;w<Z;w++){let D=U*w;for(let x=0;x<U;x++)Q[x]=H[D+x];let T=0;await _q(X-1,z,()=>{WJ(Q,T,Q,T+=U,J),q()}),WJ(Q,(X-1)*U,H,D,J),q(),await _q(X,z,()=>{let x=H[D+U-16]%X;for(let g=0;g<U;g++)A[g]=H[D+g]^Q[x*U+g];WJ(A,0,H,D,J),q()})}return Ok(W,V,N,Q,A)}var Ck=!1,Tk=!1,Rk=async function(W,Y,G,X,J,Z,V){return await Dk(W,Y,{N:G,r:X,p:J,dkLen:Z,onProgress:V})},Mk=function(W,Y,G,X,J,Z){return Kk(W,Y,{N:G,r:X,p:J,dkLen:Z})},Pk=Rk,Lk=Mk;async function ZW(W,Y,G,X,J,Z,V){let U=B0(W,"passwd"),Q=B0(Y,"salt");return C0(await Pk(U,Q,G,X,J,Z,V))}ZW._=Rk;ZW.lock=function(){Tk=!0};ZW.register=function(W){if(Tk)throw Error("scrypt is locked");Pk=W};Object.freeze(ZW);function VW(W,Y,G,X,J,Z){let V=B0(W,"passwd"),U=B0(Y,"salt");return C0(Lk(V,U,G,X,J,Z))}VW._=Mk;VW.lock=function(){Ck=!0};VW.register=function(W){if(Ck)throw Error("scryptSync is locked");Lk=W};Object.freeze(VW);var Bk=function(W){return OK("sha256").update(W).digest()},Ek=function(W){return OK("sha512").update(W).digest()},$k=Bk,Fk=Ek,Sk=!1,xk=!1;function L9(W){let Y=B0(W,"data");return C0($k(Y))}L9._=Bk;L9.lock=function(){Sk=!0};L9.register=function(W){if(Sk)throw Error("sha256 is locked");$k=W};Object.freeze(L9);function uq(W){let Y=B0(W,"data");return C0(Fk(Y))}uq._=Ek;uq.lock=function(){xk=!0};uq.register=function(W){if(xk)throw Error("sha512 is locked");Fk=W};Object.freeze(L9);var BK={};NA(BK,{validateObject:()=>QW,utf8ToBytes:()=>ha,numberToVarBytesBE:()=>ga,numberToHexUnpadded:()=>yk,numberToBytesLE:()=>fq,numberToBytesBE:()=>UW,hexToNumber:()=>PK,hexToBytes:()=>kY,equalBytes:()=>ua,ensureBytes:()=>I5,createHmacDrbg:()=>LK,concatBytes:()=>YJ,bytesToNumberLE:()=>mq,bytesToNumberBE:()=>i4,bytesToHex:()=>xY,bitSet:()=>fa,bitMask:()=>CU,bitLen:()=>ba,bitGet:()=>ma});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var _k=BigInt(0),hq=BigInt(1),ya=BigInt(2),bq=(W)=>W instanceof Uint8Array,va=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function xY(W){if(!bq(W))throw Error("Uint8Array expected");let Y="";for(let G=0;G<W.length;G++)Y+=va[W[G]];return Y}function yk(W){let Y=W.toString(16);return Y.length&1?`0${Y}`:Y}function PK(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return BigInt(W===""?"0":`0x${W}`)}function kY(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);let Y=W.length;if(Y%2)throw Error("padded hex string expected, got unpadded hex of length "+Y);let G=new Uint8Array(Y/2);for(let X=0;X<G.length;X++){let J=X*2,Z=W.slice(J,J+2),V=Number.parseInt(Z,16);if(Number.isNaN(V)||V<0)throw Error("Invalid byte sequence");G[X]=V}return G}function i4(W){return PK(xY(W))}function mq(W){if(!bq(W))throw Error("Uint8Array expected");return PK(xY(Uint8Array.from(W).reverse()))}function UW(W,Y){return kY(W.toString(16).padStart(Y*2,"0"))}function fq(W,Y){return UW(W,Y).reverse()}function ga(W){return kY(yk(W))}function I5(W,Y,G){let X;if(typeof Y==="string")try{X=kY(Y)}catch(Z){throw Error(`${W} must be valid hex string, got "${Y}". Cause: ${Z}`)}else if(bq(Y))X=Uint8Array.from(Y);else throw Error(`${W} must be hex string or Uint8Array`);let J=X.length;if(typeof G==="number"&&J!==G)throw Error(`${W} expected ${G} bytes, got ${J}`);return X}function YJ(...W){let Y=new Uint8Array(W.reduce((X,J)=>X+J.length,0)),G=0;return W.forEach((X)=>{if(!bq(X))throw Error("Uint8Array expected");Y.set(X,G),G+=X.length}),Y}function ua(W,Y){if(W.length!==Y.length)return!1;for(let G=0;G<W.length;G++)if(W[G]!==Y[G])return!1;return!0}function ha(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function ba(W){let Y;for(Y=0;W>_k;W>>=hq,Y+=1);return Y}function ma(W,Y){return W>>BigInt(Y)&hq}var fa=(W,Y,G)=>{return W|(G?hq:_k)<<BigInt(Y)},CU=(W)=>(ya<<BigInt(W-1))-hq,MK=(W)=>new Uint8Array(W),kk=(W)=>Uint8Array.from(W);function LK(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=MK(W),J=MK(W),Z=0,V=()=>{X.fill(1),J.fill(0),Z=0},U=(...A)=>G(J,X,...A),Q=(A=MK())=>{if(J=U(kk([0]),A),X=U(),A.length===0)return;J=U(kk([1]),A),X=U()},H=()=>{if(Z++>=1000)throw Error("drbg: tried 1000 values");let A=0,q=[];while(A<Y){X=U();let z=X.slice();q.push(z),A+=X.length}return YJ(...q)};return(A,q)=>{V(),Q(A);let z=void 0;while(!(z=q(H())))Q();return V(),z}}var ca={bigint:(W)=>typeof W==="bigint",function:(W)=>typeof W==="function",boolean:(W)=>typeof W==="boolean",string:(W)=>typeof W==="string",stringOrUint8Array:(W)=>typeof W==="string"||W instanceof Uint8Array,isSafeInteger:(W)=>Number.isSafeInteger(W),array:(W)=>Array.isArray(W),field:(W,Y)=>Y.Fp.isValid(W),hash:(W)=>typeof W==="function"&&Number.isSafeInteger(W.outputLen)};function QW(W,Y,G={}){let X=(J,Z,V)=>{let U=ca[Z];if(typeof U!=="function")throw Error(`Invalid validator "${Z}", expected function`);let Q=W[J];if(V&&Q===void 0)return;if(!U(Q,W))throw Error(`Invalid param ${String(J)}=${Q} (${typeof Q}), expected ${Z}`)};for(let[J,Z]of Object.entries(Y))X(J,Z,!1);for(let[J,Z]of Object.entries(G))X(J,Z,!0);return W}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var d8=BigInt(0),$8=BigInt(1),_Y=BigInt(2),pa=BigInt(3),EK=BigInt(4),vk=BigInt(5),gk=BigInt(8),la=BigInt(9),da=BigInt(16);function B9(W,Y){let G=W%Y;return G>=d8?G:Y+G}function oa(W,Y,G){if(G<=d8||Y<d8)throw Error("Expected power/modulo > 0");if(G===$8)return d8;let X=$8;while(Y>d8){if(Y&$8)X=X*W%G;W=W*W%G,Y>>=$8}return X}function z5(W,Y,G){let X=W;while(Y-- >d8)X*=X,X%=G;return X}function cq(W,Y){if(W===d8||Y<=d8)throw Error(`invert: expected positive integers, got n=${W} mod=${Y}`);let G=B9(W,Y),X=Y,J=d8,Z=$8,V=$8,U=d8;while(G!==d8){let H=X/G,N=X%G,A=J-V*H,q=Z-U*H;X=G,G=N,J=V,Z=U,V=A,U=q}if(X!==$8)throw Error("invert: does not exist");return B9(J,Y)}function na(W){let Y=(W-$8)/_Y,G,X,J;for(G=W-$8,X=0;G%_Y===d8;G/=_Y,X++);for(J=_Y;J<W&&oa(J,Y,W)!==W-$8;J++);if(X===1){let V=(W+$8)/EK;return function(Q,H){let N=Q.pow(H,V);if(!Q.eql(Q.sqr(N),H))throw Error("Cannot find square root");return N}}let Z=(G+$8)/_Y;return function(U,Q){if(U.pow(Q,Y)===U.neg(U.ONE))throw Error("Cannot find square root");let H=X,N=U.pow(U.mul(U.ONE,J),G),A=U.pow(Q,Z),q=U.pow(Q,G);while(!U.eql(q,U.ONE)){if(U.eql(q,U.ZERO))return U.ZERO;let z=1;for(let D=U.sqr(q);z<H;z++){if(U.eql(D,U.ONE))break;D=U.sqr(D)}let w=U.pow(N,$8<<BigInt(H-z-1));N=U.sqr(w),A=U.mul(A,w),q=U.mul(q,N),H=z}return A}}function ia(W){if(W%EK===pa){let Y=(W+$8)/EK;return function(X,J){let Z=X.pow(J,Y);if(!X.eql(X.sqr(Z),J))throw Error("Cannot find square root");return Z}}if(W%gk===vk){let Y=(W-vk)/gk;return function(X,J){let Z=X.mul(J,_Y),V=X.pow(Z,Y),U=X.mul(J,V),Q=X.mul(X.mul(U,_Y),V),H=X.mul(U,X.sub(Q,X.ONE));if(!X.eql(X.sqr(H),J))throw Error("Cannot find square root");return H}}if(W%da===la);return na(W)}var ra=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $K(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},G=ra.reduce((X,J)=>{return X[J]="function",X},Y);return QW(W,G)}function aa(W,Y,G){if(G<d8)throw Error("Expected power > 0");if(G===d8)return W.ONE;if(G===$8)return Y;let X=W.ONE,J=Y;while(G>d8){if(G&$8)X=W.mul(X,J);J=W.sqr(J),G>>=$8}return X}function sa(W,Y){let G=Array(Y.length),X=Y.reduce((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=Z,W.mul(Z,V)},W.ONE),J=W.inv(X);return Y.reduceRight((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=W.mul(Z,G[U]),W.mul(Z,V)},J),G}function FK(W,Y){let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function uk(W,Y,G=!1,X={}){if(W<=d8)throw Error(`Expected Field ORDER > 0, got ${W}`);let{nBitLength:J,nByteLength:Z}=FK(W,Y);if(Z>2048)throw Error("Field lengths over 2048 bytes are not supported");let V=ia(W),U=Object.freeze({ORDER:W,BITS:J,BYTES:Z,MASK:CU(J),ZERO:d8,ONE:$8,create:(Q)=>B9(Q,W),isValid:(Q)=>{if(typeof Q!=="bigint")throw Error(`Invalid field element: expected bigint, got ${typeof Q}`);return d8<=Q&&Q<W},is0:(Q)=>Q===d8,isOdd:(Q)=>(Q&$8)===$8,neg:(Q)=>B9(-Q,W),eql:(Q,H)=>Q===H,sqr:(Q)=>B9(Q*Q,W),add:(Q,H)=>B9(Q+H,W),sub:(Q,H)=>B9(Q-H,W),mul:(Q,H)=>B9(Q*H,W),pow:(Q,H)=>aa(U,Q,H),div:(Q,H)=>B9(Q*cq(H,W),W),sqrN:(Q)=>Q*Q,addN:(Q,H)=>Q+H,subN:(Q,H)=>Q-H,mulN:(Q,H)=>Q*H,inv:(Q)=>cq(Q,W),sqrt:X.sqrt||((Q)=>V(U,Q)),invertBatch:(Q)=>sa(U,Q),cmov:(Q,H,N)=>N?H:Q,toBytes:(Q)=>G?fq(Q,Z):UW(Q,Z),fromBytes:(Q)=>{if(Q.length!==Z)throw Error(`Fp.fromBytes: expected ${Z}, got ${Q.length}`);return G?mq(Q):i4(Q)}});return Object.freeze(U)}function hk(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function SK(W){let Y=hk(W);return Y+Math.ceil(Y/2)}function bk(W,Y,G=!1){let X=W.length,J=hk(Y),Z=SK(Y);if(X<16||X<Z||X>1024)throw Error(`expected ${Z}-1024 bytes of input, got ${X}`);let V=G?i4(W):mq(W),U=B9(V,Y-$8)+$8;return G?fq(U,J):UW(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ea=BigInt(0),xK=BigInt(1);function mk(W,Y){let G=(J,Z)=>{let V=Z.negate();return J?V:Z},X=(J)=>{let Z=Math.ceil(Y/J)+1,V=2**(J-1);return{windows:Z,windowSize:V}};return{constTimeNegate:G,unsafeLadder(J,Z){let V=W.ZERO,U=J;while(Z>ea){if(Z&xK)V=V.add(U);U=U.double(),Z>>=xK}return V},precomputeWindow(J,Z){let{windows:V,windowSize:U}=X(Z),Q=[],H=J,N=H;for(let A=0;A<V;A++){N=H,Q.push(N);for(let q=1;q<U;q++)N=N.add(H),Q.push(N);H=N.double()}return Q},wNAF(J,Z,V){let{windows:U,windowSize:Q}=X(J),H=W.ZERO,N=W.BASE,A=BigInt(2**J-1),q=2**J,z=BigInt(J);for(let w=0;w<U;w++){let D=w*Q,T=Number(V&A);if(V>>=z,T>Q)T-=q,V+=xK;let x=D,g=D+Math.abs(T)-1,f=w%2!==0,y=T<0;if(T===0)N=N.add(G(f,Z[x]));else H=H.add(G(y,Z[g]))}return{p:H,f:N}},wNAFCached(J,Z,V,U){let Q=J._WINDOW_SIZE||1,H=Z.get(J);if(!H){if(H=this.precomputeWindow(J,Q),Q!==1)Z.set(J,U(H))}return this.wNAF(Q,H,V)}}}function kK(W){return $K(W.Fp),QW(W,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...FK(W.n,W.nBitLength),...W,...{p:W.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ws(W){let Y=kK(W);QW(Y,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:G,Fp:X,a:J}=Y;if(G){if(!X.eql(J,X.ZERO))throw Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof G!=="object"||typeof G.beta!=="bigint"||typeof G.splitScalar!=="function")throw Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...Y})}var{bytesToNumberBE:Ys,hexToBytes:Gs}=BK,yY={Err:class extends Error{constructor(Y=""){super(Y)}},_parseInt(W){let{Err:Y}=yY;if(W.length<2||W[0]!==2)throw new Y("Invalid signature integer tag");let G=W[1],X=W.subarray(2,G+2);if(!G||X.length!==G)throw new Y("Invalid signature integer: wrong length");if(X[0]&128)throw new Y("Invalid signature integer: negative");if(X[0]===0&&!(X[1]&128))throw new Y("Invalid signature integer: unnecessary leading zero");return{d:Ys(X),l:W.subarray(G+2)}},toSig(W){let{Err:Y}=yY,G=typeof W==="string"?Gs(W):W;if(!(G instanceof Uint8Array))throw Error("ui8a expected");let X=G.length;if(X<2||G[0]!=48)throw new Y("Invalid signature tag");if(G[1]!==X-2)throw new Y("Invalid signature: incorrect length");let{d:J,l:Z}=yY._parseInt(G.subarray(2)),{d:V,l:U}=yY._parseInt(Z);if(U.length)throw new Y("Invalid signature: left bytes after parsing");return{r:J,s:V}},hexFromSig(W){let Y=(H)=>Number.parseInt(H[0],16)&8?"00"+H:H,G=(H)=>{let N=H.toString(16);return N.length&1?`0${N}`:N},X=Y(G(W.s)),J=Y(G(W.r)),Z=X.length/2,V=J.length/2,U=G(Z),Q=G(V);return`30${G(V+Z+4)}02${Q}${J}02${U}${X}`}},r4=BigInt(0),x5=BigInt(1),Vj0=BigInt(2),fk=BigInt(3),Uj0=BigInt(4);function Xs(W){let Y=Ws(W),{Fp:G}=Y,X=Y.toBytes||((w,D,T)=>{let x=D.toAffine();return YJ(Uint8Array.from([4]),G.toBytes(x.x),G.toBytes(x.y))}),J=Y.fromBytes||((w)=>{let D=w.subarray(1),T=G.fromBytes(D.subarray(0,G.BYTES)),x=G.fromBytes(D.subarray(G.BYTES,2*G.BYTES));return{x:T,y:x}});function Z(w){let{a:D,b:T}=Y,x=G.sqr(w),g=G.mul(x,w);return G.add(G.add(g,G.mul(w,D)),T)}if(!G.eql(G.sqr(Y.Gy),Z(Y.Gx)))throw Error("bad generator point: equation left != right");function V(w){return typeof w==="bigint"&&r4<w&&w<Y.n}function U(w){if(!V(w))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function Q(w){let{allowedPrivateKeyLengths:D,nByteLength:T,wrapPrivateKey:x,n:g}=Y;if(D&&typeof w!=="bigint"){if(w instanceof Uint8Array)w=xY(w);if(typeof w!=="string"||!D.includes(w.length))throw Error("Invalid key");w=w.padStart(T*2,"0")}let f;try{f=typeof w==="bigint"?w:i4(I5("private key",w,T))}catch(y){throw Error(`private key must be ${T} bytes, hex or bigint, not ${typeof w}`)}if(x)f=B9(f,g);return U(f),f}let H=new Map;function N(w){if(!(w instanceof A))throw Error("ProjectivePoint expected")}class A{constructor(w,D,T){if(this.px=w,this.py=D,this.pz=T,w==null||!G.isValid(w))throw Error("x required");if(D==null||!G.isValid(D))throw Error("y required");if(T==null||!G.isValid(T))throw Error("z required")}static fromAffine(w){let{x:D,y:T}=w||{};if(!w||!G.isValid(D)||!G.isValid(T))throw Error("invalid affine point");if(w instanceof A)throw Error("projective point not allowed");let x=(g)=>G.eql(g,G.ZERO);if(x(D)&&x(T))return A.ZERO;return new A(D,T,G.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(w){let D=G.invertBatch(w.map((T)=>T.pz));return w.map((T,x)=>T.toAffine(D[x])).map(A.fromAffine)}static fromHex(w){let D=A.fromAffine(J(I5("pointHex",w)));return D.assertValidity(),D}static fromPrivateKey(w){return A.BASE.multiply(Q(w))}_setWindowSize(w){this._WINDOW_SIZE=w,H.delete(this)}assertValidity(){if(this.is0()){if(Y.allowInfinityPoint&&!G.is0(this.py))return;throw Error("bad point: ZERO")}let{x:w,y:D}=this.toAffine();if(!G.isValid(w)||!G.isValid(D))throw Error("bad point: x or y not FE");let T=G.sqr(D),x=Z(w);if(!G.eql(T,x))throw Error("bad point: equation left != right");if(!this.isTorsionFree())throw Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:w}=this.toAffine();if(G.isOdd)return!G.isOdd(w);throw Error("Field doesn't support isOdd")}equals(w){N(w);let{px:D,py:T,pz:x}=this,{px:g,py:f,pz:y}=w,p=G.eql(G.mul(D,y),G.mul(g,x)),b=G.eql(G.mul(T,y),G.mul(f,x));return p&&b}negate(){return new A(this.px,G.neg(this.py),this.pz)}double(){let{a:w,b:D}=Y,T=G.mul(D,fk),{px:x,py:g,pz:f}=this,y=G.ZERO,p=G.ZERO,b=G.ZERO,m=G.mul(x,x),W0=G.mul(g,g),u=G.mul(f,f),J0=G.mul(x,g);return J0=G.add(J0,J0),b=G.mul(x,f),b=G.add(b,b),y=G.mul(w,b),p=G.mul(T,u),p=G.add(y,p),y=G.sub(W0,p),p=G.add(W0,p),p=G.mul(y,p),y=G.mul(J0,y),b=G.mul(T,b),u=G.mul(w,u),J0=G.sub(m,u),J0=G.mul(w,J0),J0=G.add(J0,b),b=G.add(m,m),m=G.add(b,m),m=G.add(m,u),m=G.mul(m,J0),p=G.add(p,m),u=G.mul(g,f),u=G.add(u,u),m=G.mul(u,J0),y=G.sub(y,m),b=G.mul(u,W0),b=G.add(b,b),b=G.add(b,b),new A(y,p,b)}add(w){N(w);let{px:D,py:T,pz:x}=this,{px:g,py:f,pz:y}=w,p=G.ZERO,b=G.ZERO,m=G.ZERO,W0=Y.a,u=G.mul(Y.b,fk),J0=G.mul(D,g),A0=G.mul(T,f),k=G.mul(x,y),l=G.add(D,T),B=G.add(g,f);l=G.mul(l,B),B=G.add(J0,A0),l=G.sub(l,B),B=G.add(D,x);let $=G.add(g,y);return B=G.mul(B,$),$=G.add(J0,k),B=G.sub(B,$),$=G.add(T,x),p=G.add(f,y),$=G.mul($,p),p=G.add(A0,k),$=G.sub($,p),m=G.mul(W0,B),p=G.mul(u,k),m=G.add(p,m),p=G.sub(A0,m),m=G.add(A0,m),b=G.mul(p,m),A0=G.add(J0,J0),A0=G.add(A0,J0),k=G.mul(W0,k),B=G.mul(u,B),A0=G.add(A0,k),k=G.sub(J0,k),k=G.mul(W0,k),B=G.add(B,k),J0=G.mul(A0,B),b=G.add(b,J0),J0=G.mul($,B),p=G.mul(l,p),p=G.sub(p,J0),J0=G.mul(l,A0),m=G.mul($,m),m=G.add(m,J0),new A(p,b,m)}subtract(w){return this.add(w.negate())}is0(){return this.equals(A.ZERO)}wNAF(w){return z.wNAFCached(this,H,w,(D)=>{let T=G.invertBatch(D.map((x)=>x.pz));return D.map((x,g)=>x.toAffine(T[g])).map(A.fromAffine)})}multiplyUnsafe(w){let D=A.ZERO;if(w===r4)return D;if(U(w),w===x5)return this;let{endo:T}=Y;if(!T)return z.unsafeLadder(this,w);let{k1neg:x,k1:g,k2neg:f,k2:y}=T.splitScalar(w),p=D,b=D,m=this;while(g>r4||y>r4){if(g&x5)p=p.add(m);if(y&x5)b=b.add(m);m=m.double(),g>>=x5,y>>=x5}if(x)p=p.negate();if(f)b=b.negate();return b=new A(G.mul(b.px,T.beta),b.py,b.pz),p.add(b)}multiply(w){U(w);let D=w,T,x,{endo:g}=Y;if(g){let{k1neg:f,k1:y,k2neg:p,k2:b}=g.splitScalar(D),{p:m,f:W0}=this.wNAF(y),{p:u,f:J0}=this.wNAF(b);m=z.constTimeNegate(f,m),u=z.constTimeNegate(p,u),u=new A(G.mul(u.px,g.beta),u.py,u.pz),T=m.add(u),x=W0.add(J0)}else{let{p:f,f:y}=this.wNAF(D);T=f,x=y}return A.normalizeZ([T,x])[0]}multiplyAndAddUnsafe(w,D,T){let x=A.BASE,g=(y,p)=>p===r4||p===x5||!y.equals(x)?y.multiplyUnsafe(p):y.multiply(p),f=g(this,D).add(g(w,T));return f.is0()?void 0:f}toAffine(w){let{px:D,py:T,pz:x}=this,g=this.is0();if(w==null)w=g?G.ONE:G.inv(x);let f=G.mul(D,w),y=G.mul(T,w),p=G.mul(x,w);if(g)return{x:G.ZERO,y:G.ZERO};if(!G.eql(p,G.ONE))throw Error("invZ was invalid");return{x:f,y}}isTorsionFree(){let{h:w,isTorsionFree:D}=Y;if(w===x5)return!0;if(D)return D(A,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:w,clearCofactor:D}=Y;if(w===x5)return this;if(D)return D(A,this);return this.multiplyUnsafe(Y.h)}toRawBytes(w=!0){return this.assertValidity(),X(A,this,w)}toHex(w=!0){return xY(this.toRawBytes(w))}}A.BASE=new A(Y.Gx,Y.Gy,G.ONE),A.ZERO=new A(G.ZERO,G.ONE,G.ZERO);let q=Y.nBitLength,z=mk(A,Y.endo?Math.ceil(q/2):q);return{CURVE:Y,ProjectivePoint:A,normPrivateKeyToScalar:Q,weierstrassEquation:Z,isWithinCurveOrder:V}}function Js(W){let Y=kK(W);return QW(Y,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...Y})}function ck(W){let Y=Js(W),{Fp:G,n:X}=Y,J=G.BYTES+1,Z=2*G.BYTES+1;function V($){return r4<$&&$<G.ORDER}function U($){return B9($,X)}function Q($){return cq($,X)}let{ProjectivePoint:H,normPrivateKeyToScalar:N,weierstrassEquation:A,isWithinCurveOrder:q}=Xs({...Y,toBytes($,h,a){let n=h.toAffine(),E=G.toBytes(n.x),P=YJ;if(a)return P(Uint8Array.from([h.hasEvenY()?2:3]),E);else return P(Uint8Array.from([4]),E,G.toBytes(n.y))},fromBytes($){let h=$.length,a=$[0],n=$.subarray(1);if(h===J&&(a===2||a===3)){let E=i4(n);if(!V(E))throw Error("Point is not on curve");let P=A(E),v=G.sqrt(P),M=(v&x5)===x5;if((a&1)===1!==M)v=G.neg(v);return{x:E,y:v}}else if(h===Z&&a===4){let E=G.fromBytes(n.subarray(0,G.BYTES)),P=G.fromBytes(n.subarray(G.BYTES,2*G.BYTES));return{x:E,y:P}}else throw Error(`Point of length ${h} was invalid. Expected ${J} compressed bytes or ${Z} uncompressed bytes`)}}),z=($)=>xY(UW($,Y.nByteLength));function w($){let h=X>>x5;return $>h}function D($){return w($)?U(-$):$}let T=($,h,a)=>i4($.slice(h,a));class x{constructor($,h,a){this.r=$,this.s=h,this.recovery=a,this.assertValidity()}static fromCompact($){let h=Y.nByteLength;return $=I5("compactSignature",$,h*2),new x(T($,0,h),T($,h,2*h))}static fromDER($){let{r:h,s:a}=yY.toSig(I5("DER",$));return new x(h,a)}assertValidity(){if(!q(this.r))throw Error("r must be 0 < r < CURVE.n");if(!q(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit($){return new x(this.r,this.s,$)}recoverPublicKey($){let{r:h,s:a,recovery:n}=this,E=m(I5("msgHash",$));if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");let P=n===2||n===3?h+Y.n:h;if(P>=G.ORDER)throw Error("recovery id 2 or 3 invalid");let v=(n&1)===0?"02":"03",M=H.fromHex(v+z(P)),F=Q(P),c=U(-E*F),t=U(a*F),Y0=H.BASE.multiplyAndAddUnsafe(M,c,t);if(!Y0)throw Error("point at infinify");return Y0.assertValidity(),Y0}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,U(-this.s),this.recovery):this}toDERRawBytes(){return kY(this.toDERHex())}toDERHex(){return yY.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return kY(this.toCompactHex())}toCompactHex(){return z(this.r)+z(this.s)}}let g={isValidPrivateKey($){try{return N($),!0}catch(h){return!1}},normPrivateKeyToScalar:N,randomPrivateKey:()=>{let $=SK(Y.n);return bk(Y.randomBytes($),Y.n)},precompute($=8,h=H.BASE){return h._setWindowSize($),h.multiply(BigInt(3)),h}};function f($,h=!0){return H.fromPrivateKey($).toRawBytes(h)}function y($){let h=$ instanceof Uint8Array,a=typeof $==="string",n=(h||a)&&$.length;if(h)return n===J||n===Z;if(a)return n===2*J||n===2*Z;if($ instanceof H)return!0;return!1}function p($,h,a=!0){if(y($))throw Error("first arg must be private key");if(!y(h))throw Error("second arg must be public key");return H.fromHex(h).multiply(N($)).toRawBytes(a)}let b=Y.bits2int||function($){let h=i4($),a=$.length*8-Y.nBitLength;return a>0?h>>BigInt(a):h},m=Y.bits2int_modN||function($){return U(b($))},W0=CU(Y.nBitLength);function u($){if(typeof $!=="bigint")throw Error("bigint expected");if(!(r4<=$&&$<W0))throw Error(`bigint expected < 2^${Y.nBitLength}`);return UW($,Y.nByteLength)}function J0($,h,a=A0){if(["recovered","canonical"].some((x0)=>(x0 in a)))throw Error("sign() legacy options not supported");let{hash:n,randomBytes:E}=Y,{lowS:P,prehash:v,extraEntropy:M}=a;if(P==null)P=!0;if($=I5("msgHash",$),v)$=I5("prehashed msgHash",n($));let F=m($),c=N(h),t=[u(c),u(F)];if(M!=null){let x0=M===!0?E(G.BYTES):M;t.push(I5("extraEntropy",x0))}let Y0=YJ(...t),$0=F;function S0(x0){let D1=b(x0);if(!q(D1))return;let b0=Q(D1),Q0=H.BASE.multiply(D1).toAffine(),O0=U(Q0.x);if(O0===r4)return;let y0=U(b0*U($0+O0*c));if(y0===r4)return;let X0=(Q0.x===O0?0:2)|Number(Q0.y&x5),D0=y0;if(P&&w(y0))D0=D(y0),X0^=1;return new x(O0,D0,X0)}return{seed:Y0,k2sig:S0}}let A0={lowS:Y.lowS,prehash:!1},k={lowS:Y.lowS,prehash:!1};function l($,h,a=A0){let{seed:n,k2sig:E}=J0($,h,a),P=Y;return LK(P.hash.outputLen,P.nByteLength,P.hmac)(n,E)}H.BASE._setWindowSize(8);function B($,h,a,n=k){let E=$;if(h=I5("msgHash",h),a=I5("publicKey",a),"strict"in n)throw Error("options.strict was renamed to lowS");let{lowS:P,prehash:v}=n,M=void 0,F;try{if(typeof E==="string"||E instanceof Uint8Array)try{M=x.fromDER(E)}catch(Q0){if(!(Q0 instanceof yY.Err))throw Q0;M=x.fromCompact(E)}else if(typeof E==="object"&&typeof E.r==="bigint"&&typeof E.s==="bigint"){let{r:Q0,s:O0}=E;M=new x(Q0,O0)}else throw Error("PARSE");F=H.fromHex(a)}catch(Q0){if(Q0.message==="PARSE")throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&M.hasHighS())return!1;if(v)h=Y.hash(h);let{r:c,s:t}=M,Y0=m(h),$0=Q(t),S0=U(Y0*$0),x0=U(c*$0),D1=H.BASE.multiplyAndAddUnsafe(F,S0,x0)?.toAffine();if(!D1)return!1;return U(D1.x)===c}return{CURVE:Y,getPublicKey:f,getSharedSecret:p,sign:l,verify:B,ProjectivePoint:H,Signature:x,utils:g}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Zs(W){return{hash:W,hmac:(Y,...G)=>DU(W,Y,px(...G)),randomBytes:lx}}function pk(W,Y){let G=(X)=>ck({...W,...Zs(X)});return Object.freeze({...G(Y),create:G})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ok=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),lk=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Vs=BigInt(1),_K=BigInt(2),dk=(W,Y)=>(W+Y/_K)/Y;function Us(W){let Y=ok,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=z5(N,G,Y)*N%Y,q=z5(A,G,Y)*N%Y,z=z5(q,_K,Y)*H%Y,w=z5(z,J,Y)*z%Y,D=z5(w,Z,Y)*w%Y,T=z5(D,U,Y)*D%Y,x=z5(T,Q,Y)*T%Y,g=z5(x,U,Y)*D%Y,f=z5(g,G,Y)*N%Y,y=z5(f,V,Y)*w%Y,p=z5(y,X,Y)*H%Y,b=z5(p,_K,Y);if(!yK.eql(yK.sqr(b),W))throw Error("Cannot find square root");return b}var yK=uk(ok,void 0,void 0,{sqrt:Us}),a4=pk({a:BigInt(0),b:BigInt(7),Fp:yK,n:lk,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:(W)=>{let Y=lk,G=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),X=-Vs*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),J=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),Z=G,V=BigInt("0x100000000000000000000000000000000"),U=dk(Z*W,Y),Q=dk(-X*W,Y),H=B9(W-U*G-Q*J,Y),N=B9(-U*X-Q*Z,Y),A=H>V,q=N>V;if(A)H=Y-H;if(q)N=Y-N;if(H>V||N>V)throw Error("splitScalar: Endomorphism failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}}},KU),jj0=BigInt(0);var Oj0=a4.ProjectivePoint;var vK="0x0000000000000000000000000000000000000000";var pq="0x0000000000000000000000000000000000000000000000000000000000000000";var gK=`\x19Ethereum Signed Message:
|
|
249
|
-
`;var nk=BigInt(0),ik=BigInt(1),rk=BigInt(2),ak=BigInt(27),sk=BigInt(28),lq=BigInt(35),GJ={};function tk(W){return A5(N8(W),32)}class K8{#W;#Y;#G;#X;get r(){return this.#W}set r(W){r(o4(W)===32,"invalid r","value",W),this.#W=C0(W)}get s(){return r(parseInt(this.#Y.substring(0,3))<8,"non-canonical s; use ._s","s",this.#Y),this.#Y}set s(W){r(o4(W)===32,"invalid s","value",W),this.#Y=C0(W)}get _s(){return this.#Y}isValid(){return parseInt(this.#Y.substring(0,3))<8}get v(){return this.#G}set v(W){let Y=r8(W,"value");r(Y===27||Y===28,"invalid v","v",W),this.#G=Y}get networkV(){return this.#X}get legacyChainId(){let W=this.networkV;if(W==null)return null;return K8.getChainId(W)}get yParity(){return this.v===27?0:1}get yParityAndS(){let W=B0(this.s);if(this.yParity)W[0]|=128;return C0(W)}get compactSerialized(){return t1([this.r,this.yParityAndS])}get serialized(){return t1([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(W,Y,G,X){d4(W,GJ,"Signature"),this.#W=Y,this.#Y=G,this.#G=X,this.#X=null}[Symbol.for("nodejs.util.inspect.custom")](){return`Signature { r: "${this.r}", s: "${this._s}"${this.isValid()?"":', valid: "false"'}, yParity: ${this.yParity}, networkV: ${this.networkV} }`}clone(){let W=new K8(GJ,this.r,this._s,this.v);if(this.networkV)W.#X=this.networkV;return W}toJSON(){let W=this.networkV;return{_type:"signature",networkV:W!=null?W.toString():null,r:this.r,s:this._s,v:this.v}}static getChainId(W){let Y=g1(W,"v");if(Y==ak||Y==sk)return nk;return r(Y>=lq,"invalid EIP-155 v","v",W),(Y-lq)/rk}static getChainIdV(W,Y){return g1(W)*rk+BigInt(35+Y-27)}static getNormalizedV(W){let Y=g1(W);if(Y===nk||Y===ak)return 27;if(Y===ik||Y===sk)return 28;return r(Y>=lq,"invalid v","v",W),Y&ik?27:28}static from(W){function Y(Q,H){r(Q,H,"signature",W)}if(W==null)return new K8(GJ,pq,pq,27);if(typeof W==="string"){let Q=B0(W,"signature");if(Q.length===64){let H=C0(Q.slice(0,32)),N=Q.slice(32,64),A=N[0]&128?28:27;return N[0]&=127,new K8(GJ,H,C0(N),A)}if(Q.length===65){let H=C0(Q.slice(0,32)),N=C0(Q.slice(32,64)),A=K8.getNormalizedV(Q[64]);return new K8(GJ,H,N,A)}Y(!1,"invalid raw signature length")}if(W instanceof K8)return W.clone();let G=W.r;Y(G!=null,"missing r");let X=tk(G),J=function(Q,H){if(Q!=null)return tk(Q);if(H!=null){Y(R9(H,32),"invalid yParityAndS");let N=B0(H);return N[0]&=127,C0(N)}Y(!1,"missing s")}(W.s,W.yParityAndS),{networkV:Z,v:V}=function(Q,H,N){if(Q!=null){let A=g1(Q);return{networkV:A>=lq?A:void 0,v:K8.getNormalizedV(A)}}if(H!=null)return Y(R9(H,32),"invalid yParityAndS"),{v:B0(H)[0]&128?28:27};if(N!=null){switch(r8(N,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}Y(!1,"invalid yParity")}Y(!1,"missing v")}(W.v,W.yParityAndS,W.yParity),U=new K8(GJ,X,J,V);if(Z)U.#X=Z;return Y(W.yParity==null||r8(W.yParity,"sig.yParity")===U.yParity,"yParity mismatch"),Y(W.yParityAndS==null||W.yParityAndS===U.yParityAndS,"yParityAndS mismatch"),U}}class o8{#W;constructor(W){r(o4(W)===32,"invalid private key","privateKey","[REDACTED]"),this.#W=C0(W)}get privateKey(){return this.#W}get publicKey(){return o8.computePublicKey(this.#W)}get compressedPublicKey(){return o8.computePublicKey(this.#W,!0)}sign(W){r(o4(W)===32,"invalid digest length","digest",W);let Y=a4.sign(Z7(W),Z7(this.#W),{lowS:!0});return K8.from({r:V7(Y.r,32),s:V7(Y.s,32),v:Y.recovery?28:27})}computeSharedSecret(W){let Y=o8.computePublicKey(W);return C0(a4.getSharedSecret(Z7(this.#W),B0(Y),!1))}static computePublicKey(W,Y){let G=B0(W,"key");if(G.length===32){let J=a4.getPublicKey(G,!!Y);return C0(J)}if(G.length===64){let J=new Uint8Array(65);J[0]=4,J.set(G,1),G=J}let X=a4.ProjectivePoint.fromHex(G);return C0(X.toRawBytes(Y))}static recoverPublicKey(W,Y){r(o4(W)===32,"invalid digest length","digest",W);let G=K8.from(Y),X=a4.Signature.fromCompact(Z7(t1([G.r,G.s])));X=X.addRecoveryBit(G.yParity);let J=X.recoverPublicKey(Z7(W));return r(J!=null,"invalid signature for digest","signature",Y),"0x"+J.toHex(!1)}static addPoints(W,Y,G){let X=a4.ProjectivePoint.fromHex(o8.computePublicKey(W).substring(2)),J=a4.ProjectivePoint.fromHex(o8.computePublicKey(Y).substring(2));return"0x"+X.add(J).toHex(!!G)}}var Qs=BigInt(0),Hs=BigInt(36);function ek(W){W=W.toLowerCase();let Y=W.substring(2).split(""),G=new Uint8Array(40);for(let J=0;J<40;J++)G[J]=Y[J].charCodeAt(0);let X=B0(X8(G));for(let J=0;J<40;J+=2){if(X[J>>1]>>4>=8)Y[J]=Y[J].toUpperCase();if((X[J>>1]&15)>=8)Y[J+1]=Y[J+1].toUpperCase()}return"0x"+Y.join("")}var uK={};for(let W=0;W<10;W++)uK[String(W)]=String(W);for(let W=0;W<26;W++)uK[String.fromCharCode(65+W)]=String(10+W);var W_=15;function Ns(W){W=W.toUpperCase(),W=W.substring(4)+W.substring(0,2)+"00";let Y=W.split("").map((X)=>{return uK[X]}).join("");while(Y.length>=W_){let X=Y.substring(0,W_);Y=parseInt(X,10)%97+Y.substring(X.length)}let G=String(98-parseInt(Y,10)%97);while(G.length<2)G="0"+G;return G}var qs=function(){let W={};for(let Y=0;Y<36;Y++){let G="0123456789abcdefghijklmnopqrstuvwxyz"[Y];W[G]=BigInt(Y)}return W}();function As(W){W=W.toLowerCase();let Y=Qs;for(let G=0;G<W.length;G++)Y=Y*Hs+qs[W[G]];return Y}function m1(W){if(r(typeof W==="string","invalid address","address",W),W.match(/^(0x)?[0-9a-fA-F]{40}$/)){if(!W.startsWith("0x"))W="0x"+W;let Y=ek(W);return r(!W.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||Y===W,"bad address checksum","address",W),Y}if(W.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){r(W.substring(2,4)===Ns(W),"bad icap checksum","address",W);let Y=As(W.substring(4)).toString(16);while(Y.length<40)Y="0"+Y;return ek("0x"+Y)}r(!1,"invalid address","address",W)}function bK(W){return W&&typeof W.getAddress==="function"}async function hK(W,Y){let G=await Y;if(G==null||G==="0x0000000000000000000000000000000000000000")X1(typeof W!=="string","unconfigured name","UNCONFIGURED_NAME",{value:W}),r(!1,"invalid AddressLike value; did not resolve to a value address","target",W);return m1(G)}function s4(W,Y){if(typeof W==="string"){if(W.match(/^0x[0-9a-f]{40}$/i))return m1(W);return X1(Y!=null,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),hK(W,Y.resolveName(W))}else if(bK(W))return hK(W,W.getAddress());else if(W&&typeof W.then==="function")return hK(W,W);r(!1,"unsupported addressable value","target",W)}function mK(W,Y){return{address:m1(W),storageKeys:Y.map((G,X)=>{return r(R9(G,32),"invalid slot",`storageKeys[${X}]`,G),G.toLowerCase()})}}function vY(W){if(Array.isArray(W))return W.map((G,X)=>{if(Array.isArray(G))return r(G.length===2,"invalid slot set",`value[${X}]`,G),mK(G[0],G[1]);return r(G!=null&&typeof G==="object","invalid address-slot set","value",W),mK(G.address,G.storageKeys)});r(W!=null&&typeof W==="object","invalid access list","value",W);let Y=Object.keys(W).map((G)=>{let X=W[G].reduce((J,Z)=>{return J[Z]=!0,J},{});return mK(G,Object.keys(X).sort())});return Y.sort((G,X)=>G.address.localeCompare(X.address)),Y}function Y_(W){return{address:m1(W.address),nonce:g1(W.nonce!=null?W.nonce:0),chainId:g1(W.chainId!=null?W.chainId:0),signature:K8.from(W.signature)}}function t4(W){let Y;if(typeof W==="string")Y=o8.computePublicKey(W,!1);else Y=W.publicKey;return m1(X8("0x"+Y.substring(4)).substring(26))}function TU(W,Y){return t4(o8.recoverPublicKey(W,Y))}var a8=BigInt(0),ws=BigInt(2),js=BigInt(27),Os=BigInt(28),Ks=BigInt(35),Ds=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),fK=131072;function Cs(W){return{blobToKzgCommitment:(X)=>{if("computeBlobProof"in W){if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return B0(W.blobToKzgCommitment(C0(X)))}else if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return B0(W.blobToKzgCommitment(X));if("blobToKZGCommitment"in W&&typeof W.blobToKZGCommitment==="function")return B0(W.blobToKZGCommitment(C0(X)));r(!1,"unsupported KZG library","kzg",W)},computeBlobKzgProof:(X,J)=>{if("computeBlobProof"in W&&typeof W.computeBlobProof==="function")return B0(W.computeBlobProof(C0(X),C0(J)));if("computeBlobKzgProof"in W&&typeof W.computeBlobKzgProof==="function")return W.computeBlobKzgProof(X,J);if("computeBlobKZGProof"in W&&typeof W.computeBlobKZGProof==="function")return B0(W.computeBlobKZGProof(C0(X),C0(J)));r(!1,"unsupported KZG library","kzg",W)}}}function G_(W,Y){let G=W.toString(16);while(G.length<2)G="0"+G;return G+=L9(Y).substring(4),"0x"+G}function XJ(W){if(W==="0x")return null;return m1(W)}function dq(W,Y){try{return vY(W)}catch(G){r(!1,G.message,Y,W)}}function Ts(W,Y){try{if(!Array.isArray(W))throw Error("authorizationList: invalid array");let G=[];for(let X=0;X<W.length;X++){let J=W[X];if(!Array.isArray(J))throw Error(`authorization[${X}]: invalid array`);if(J.length!==6)throw Error(`authorization[${X}]: wrong length`);if(!J[1])throw Error(`authorization[${X}]: null address`);G.push({address:XJ(J[1]),nonce:J8(J[2],"nonce"),chainId:J8(J[0],"chainId"),signature:K8.from({yParity:gY(J[3],"yParity"),r:A5(J[4],32),s:A5(J[5],32)})})}return G}catch(G){r(!1,G.message,Y,W)}}function gY(W,Y){if(W==="0x")return 0;return r8(W,Y)}function J8(W,Y){if(W==="0x")return a8;let G=g1(W,Y);return r(G<=Ds,"value exceeds uint size",Y,G),G}function u1(W,Y){let G=g1(W,"value"),X=N8(G);return r(X.length<=32,"value too large",`tx.${Y}`,G),X}function oq(W){return vY(W).map((Y)=>[Y.address,Y.storageKeys])}function Rs(W){return W.map((Y)=>{return[u1(Y.chainId,"chainId"),Y.address,u1(Y.nonce,"nonce"),u1(Y.signature.yParity,"yParity"),N8(Y.signature.r),N8(Y.signature.s)]})}function Ms(W,Y){r(Array.isArray(W),`invalid ${Y}`,"value",W);for(let G=0;G<W.length;G++)r(R9(W[G],32),"invalid ${ param } hash",`value[${G}]`,W[G]);return W}function Ps(W){let Y=WW(W);r(Array.isArray(Y)&&(Y.length===9||Y.length===6),"invalid field count for legacy transaction","data",W);let G={type:0,nonce:gY(Y[0],"nonce"),gasPrice:J8(Y[1],"gasPrice"),gasLimit:J8(Y[2],"gasLimit"),to:XJ(Y[3]),value:J8(Y[4],"value"),data:C0(Y[5]),chainId:a8};if(Y.length===6)return G;let X=J8(Y[6],"v"),J=J8(Y[7],"r"),Z=J8(Y[8],"s");if(J===a8&&Z===a8)G.chainId=X;else{let V=(X-Ks)/ws;if(V<a8)V=a8;G.chainId=V,r(V!==a8||(X===js||X===Os),"non-canonical legacy v","v",Y[6]),G.signature=K8.from({r:A5(Y[7],32),s:A5(Y[8],32),v:X})}return G}function Ls(W,Y){let G=[u1(W.nonce,"nonce"),u1(W.gasPrice||0,"gasPrice"),u1(W.gasLimit,"gasLimit"),W.to||"0x",u1(W.value,"value"),W.data],X=a8;if(W.chainId!=a8)X=g1(W.chainId,"tx.chainId"),r(!Y||Y.networkV==null||Y.legacyChainId===X,"tx.chainId/sig.v mismatch","sig",Y);else if(W.signature){let Z=W.signature.legacyChainId;if(Z!=null)X=Z}if(!Y){if(X!==a8)G.push(N8(X)),G.push("0x"),G.push("0x");return $5(G)}let J=BigInt(27+Y.yParity);if(X!==a8)J=K8.getChainIdV(X,Y.v);else if(BigInt(Y.v)!==J)r(!1,"tx.chainId/sig.v mismatch","sig",Y);return G.push(N8(J)),G.push(N8(Y.r)),G.push(N8(Y.s)),$5(G)}function nq(W,Y){let G;try{if(G=gY(Y[0],"yParity"),G!==0&&G!==1)throw Error("bad yParity")}catch(V){r(!1,"invalid yParity","yParity",Y[0])}let X=A5(Y[1],32),J=A5(Y[2],32),Z=K8.from({r:X,s:J,yParity:G});W.signature=Z}function Bs(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===9||Y.length===12),"invalid field count for transaction type: 2","data",C0(W));let G={type:2,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList")};if(Y.length===9)return G;return nq(G,Y.slice(9)),G}function Es(W,Y){let G=[u1(W.chainId,"chainId"),u1(W.nonce,"nonce"),u1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),u1(W.maxFeePerGas||0,"maxFeePerGas"),u1(W.gasLimit,"gasLimit"),W.to||"0x",u1(W.value,"value"),W.data,oq(W.accessList||[])];if(Y)G.push(u1(Y.yParity,"yParity")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x02",$5(G)])}function $s(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===8||Y.length===11),"invalid field count for transaction type: 1","data",C0(W));let G={type:1,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),gasPrice:J8(Y[2],"gasPrice"),gasLimit:J8(Y[3],"gasLimit"),to:XJ(Y[4]),value:J8(Y[5],"value"),data:C0(Y[6]),accessList:dq(Y[7],"accessList")};if(Y.length===8)return G;return nq(G,Y.slice(8)),G}function Fs(W,Y){let G=[u1(W.chainId,"chainId"),u1(W.nonce,"nonce"),u1(W.gasPrice||0,"gasPrice"),u1(W.gasLimit,"gasLimit"),W.to||"0x",u1(W.value,"value"),W.data,oq(W.accessList||[])];if(Y)G.push(u1(Y.yParity,"recoveryParam")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x01",$5(G)])}function Ss(W){let Y=WW(B0(W).slice(1)),G="3",X=null;if(Y.length===4&&Array.isArray(Y[0])){G="3 (network format)";let Z=Y[1],V=Y[2],U=Y[3];r(Array.isArray(Z),"invalid network format: blobs not an array","fields[1]",Z),r(Array.isArray(V),"invalid network format: commitments not an array","fields[2]",V),r(Array.isArray(U),"invalid network format: proofs not an array","fields[3]",U),r(Z.length===V.length,"invalid network format: blobs/commitments length mismatch","fields",Y),r(Z.length===U.length,"invalid network format: blobs/proofs length mismatch","fields",Y),X=[];for(let Q=0;Q<Y[1].length;Q++)X.push({data:Z[Q],commitment:V[Q],proof:U[Q]});Y=Y[0]}r(Array.isArray(Y)&&(Y.length===11||Y.length===14),`invalid field count for transaction type: ${G}`,"data",C0(W));let J={type:3,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList"),maxFeePerBlobGas:J8(Y[9],"maxFeePerBlobGas"),blobVersionedHashes:Y[10]};if(X)J.blobs=X;r(J.to!=null,`invalid address for transaction type: ${G}`,"data",W),r(Array.isArray(J.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",W);for(let Z=0;Z<J.blobVersionedHashes.length;Z++)r(R9(J.blobVersionedHashes[Z],32),`invalid blobVersionedHash at index ${Z}: must be length 32`,"data",W);if(Y.length===11)return J;return nq(J,Y.slice(11)),J}function xs(W,Y,G){let X=[u1(W.chainId,"chainId"),u1(W.nonce,"nonce"),u1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),u1(W.maxFeePerGas||0,"maxFeePerGas"),u1(W.gasLimit,"gasLimit"),W.to||vK,u1(W.value,"value"),W.data,oq(W.accessList||[]),u1(W.maxFeePerBlobGas||0,"maxFeePerBlobGas"),Ms(W.blobVersionedHashes||[],"blobVersionedHashes")];if(Y){if(X.push(u1(Y.yParity,"yParity")),X.push(N8(Y.r)),X.push(N8(Y.s)),G)return t1(["0x03",$5([X,G.map((J)=>J.data),G.map((J)=>J.commitment),G.map((J)=>J.proof)])])}return t1(["0x03",$5(X)])}function ks(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===10||Y.length===13),"invalid field count for transaction type: 4","data",C0(W));let G={type:4,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList"),authorizationList:Ts(Y[9],"authorizationList")};if(Y.length===10)return G;return nq(G,Y.slice(10)),G}function _s(W,Y){let G=[u1(W.chainId,"chainId"),u1(W.nonce,"nonce"),u1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),u1(W.maxFeePerGas||0,"maxFeePerGas"),u1(W.gasLimit,"gasLimit"),W.to||"0x",u1(W.value,"value"),W.data,oq(W.accessList||[]),Rs(W.authorizationList||[])];if(Y)G.push(u1(Y.yParity,"yParity")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x04",$5(G)])}class t9{#W;#Y;#G;#X;#Q;#H;#N;#q;#A;#I;#z;#w;#U;#Z;#J;#V;#j;get type(){return this.#W}set type(W){switch(W){case null:this.#W=null;break;case 0:case"legacy":this.#W=0;break;case 1:case"berlin":case"eip-2930":this.#W=1;break;case 2:case"london":case"eip-1559":this.#W=2;break;case 3:case"cancun":case"eip-4844":this.#W=3;break;case 4:case"pectra":case"eip-7702":this.#W=4;break;default:r(!1,"unsupported transaction type","type",W)}}get typeName(){switch(this.type){case 0:return"legacy";case 1:return"eip-2930";case 2:return"eip-1559";case 3:return"eip-4844";case 4:return"eip-7702"}return null}get to(){let W=this.#Y;if(W==null&&this.type===3)return vK;return W}set to(W){this.#Y=W==null?null:m1(W)}get nonce(){return this.#X}set nonce(W){this.#X=r8(W,"value")}get gasLimit(){return this.#Q}set gasLimit(W){this.#Q=g1(W)}get gasPrice(){let W=this.#H;if(W==null&&(this.type===0||this.type===1))return a8;return W}set gasPrice(W){this.#H=W==null?null:g1(W,"gasPrice")}get maxPriorityFeePerGas(){let W=this.#N;if(W==null){if(this.type===2||this.type===3)return a8;return null}return W}set maxPriorityFeePerGas(W){this.#N=W==null?null:g1(W,"maxPriorityFeePerGas")}get maxFeePerGas(){let W=this.#q;if(W==null){if(this.type===2||this.type===3)return a8;return null}return W}set maxFeePerGas(W){this.#q=W==null?null:g1(W,"maxFeePerGas")}get data(){return this.#G}set data(W){this.#G=C0(W)}get value(){return this.#A}set value(W){this.#A=g1(W,"value")}get chainId(){return this.#I}set chainId(W){this.#I=g1(W)}get signature(){return this.#z||null}set signature(W){this.#z=W==null?null:K8.from(W)}get accessList(){let W=this.#w||null;if(W==null){if(this.type===1||this.type===2||this.type===3)return[];return null}return W}set accessList(W){this.#w=W==null?null:vY(W)}get authorizationList(){let W=this.#j||null;if(W==null){if(this.type===4)return[]}return W}set authorizationList(W){this.#j=W==null?null:W.map((Y)=>Y_(Y))}get maxFeePerBlobGas(){let W=this.#U;if(W==null&&this.type===3)return a8;return W}set maxFeePerBlobGas(W){this.#U=W==null?null:g1(W,"maxFeePerBlobGas")}get blobVersionedHashes(){let W=this.#Z;if(W==null&&this.type===3)return[];return W}set blobVersionedHashes(W){if(W!=null){r(Array.isArray(W),"blobVersionedHashes must be an Array","value",W),W=W.slice();for(let Y=0;Y<W.length;Y++)r(R9(W[Y],32),"invalid blobVersionedHash",`value[${Y}]`,W[Y])}this.#Z=W}get blobs(){if(this.#V==null)return null;return this.#V.map((W)=>Object.assign({},W))}set blobs(W){if(W==null){this.#V=null;return}let Y=[],G=[];for(let X=0;X<W.length;X++){let J=W[X];if(n7(J)){X1(this.#J,"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let Z=B0(J);if(r(Z.length<=fK,"blob is too large",`blobs[${X}]`,J),Z.length!==fK){let Q=new Uint8Array(fK);Q.set(Z),Z=Q}let V=this.#J.blobToKzgCommitment(Z),U=C0(this.#J.computeBlobKzgProof(Z,V));Y.push({data:C0(Z),commitment:C0(V),proof:U}),G.push(G_(1,V))}else{let Z=C0(J.commitment);Y.push({data:C0(J.data),commitment:Z,proof:C0(J.proof)}),G.push(G_(1,Z))}}this.#V=Y,this.#Z=G}get kzg(){return this.#J}set kzg(W){if(W==null)this.#J=null;else this.#J=Cs(W)}constructor(){this.#W=null,this.#Y=null,this.#X=0,this.#Q=a8,this.#H=null,this.#N=null,this.#q=null,this.#G="0x",this.#A=a8,this.#I=a8,this.#z=null,this.#w=null,this.#U=null,this.#Z=null,this.#J=null,this.#V=null,this.#j=null}get hash(){if(this.signature==null)return null;return X8(this.#O(!0,!1))}get unsignedHash(){return X8(this.unsignedSerialized)}get from(){if(this.signature==null)return null;return TU(this.unsignedHash,this.signature)}get fromPublicKey(){if(this.signature==null)return null;return o8.recoverPublicKey(this.unsignedHash,this.signature)}isSigned(){return this.signature!=null}#O(W,Y){X1(!W||this.signature!=null,"cannot serialize unsigned transaction; maybe you meant .unsignedSerialized","UNSUPPORTED_OPERATION",{operation:".serialized"});let G=W?this.signature:null;switch(this.inferType()){case 0:return Ls(this,G);case 1:return Fs(this,G);case 2:return Es(this,G);case 3:return xs(this,G,Y?this.blobs:null);case 4:return _s(this,G)}X1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})}get serialized(){return this.#O(!0,!0)}get unsignedSerialized(){return this.#O(!1,!1)}inferType(){let W=this.inferTypes();if(W.indexOf(2)>=0)return 2;return W.pop()}inferTypes(){let W=this.gasPrice!=null,Y=this.maxFeePerGas!=null||this.maxPriorityFeePerGas!=null,G=this.accessList!=null,X=this.#U!=null||this.#Z;if(this.maxFeePerGas!=null&&this.maxPriorityFeePerGas!=null)X1(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this});X1(!Y||this.type!==0&&this.type!==1,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),X1(this.type!==0||!G,"legacy transaction cannot have accessList","BAD_DATA",{value:this});let J=[];if(this.type!=null)J.push(this.type);else if(this.authorizationList&&this.authorizationList.length)J.push(4);else if(Y)J.push(2);else if(W){if(J.push(1),!G)J.push(0)}else if(G)J.push(1),J.push(2);else if(X&&this.to)J.push(3);else J.push(0),J.push(1),J.push(2),J.push(3);return J.sort(),J}isLegacy(){return this.type===0}isBerlin(){return this.type===1}isLondon(){return this.type===2}isCancun(){return this.type===3}clone(){return t9.from(this)}toJSON(){let W=(Y)=>{if(Y==null)return null;return Y.toString()};return{type:this.type,to:this.to,data:this.data,nonce:this.nonce,gasLimit:W(this.gasLimit),gasPrice:W(this.gasPrice),maxPriorityFeePerGas:W(this.maxPriorityFeePerGas),maxFeePerGas:W(this.maxFeePerGas),value:W(this.value),chainId:W(this.chainId),sig:this.signature?this.signature.toJSON():null,accessList:this.accessList}}static from(W){if(W==null)return new t9;if(typeof W==="string"){let G=B0(W);if(G[0]>=127)return t9.from(Ps(G));switch(G[0]){case 1:return t9.from($s(G));case 2:return t9.from(Bs(G));case 3:return t9.from(Ss(G));case 4:return t9.from(ks(G))}X1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}let Y=new t9;if(W.type!=null)Y.type=W.type;if(W.to!=null)Y.to=W.to;if(W.nonce!=null)Y.nonce=W.nonce;if(W.gasLimit!=null)Y.gasLimit=W.gasLimit;if(W.gasPrice!=null)Y.gasPrice=W.gasPrice;if(W.maxPriorityFeePerGas!=null)Y.maxPriorityFeePerGas=W.maxPriorityFeePerGas;if(W.maxFeePerGas!=null)Y.maxFeePerGas=W.maxFeePerGas;if(W.maxFeePerBlobGas!=null)Y.maxFeePerBlobGas=W.maxFeePerBlobGas;if(W.data!=null)Y.data=W.data;if(W.value!=null)Y.value=W.value;if(W.chainId!=null)Y.chainId=W.chainId;if(W.signature!=null)Y.signature=K8.from(W.signature);if(W.accessList!=null)Y.accessList=W.accessList;if(W.authorizationList!=null)Y.authorizationList=W.authorizationList;if(W.blobVersionedHashes!=null)Y.blobVersionedHashes=W.blobVersionedHashes;if(W.kzg!=null)Y.kzg=W.kzg;if(W.blobs!=null)Y.blobs=W.blobs;if(W.hash!=null)r(Y.isSigned(),"unsigned transaction cannot define '.hash'","tx",W),r(Y.hash===W.hash,"hash mismatch","tx",W);if(W.from!=null)r(Y.isSigned(),"unsigned transaction cannot define '.from'","tx",W),r(Y.from.toLowerCase()===(W.from||"").toLowerCase(),"from mismatch","tx",W);return Y}}function iq(W){return r(typeof W.address==="string","invalid address for hashAuthorization","auth.address",W),X8(t1(["0x05",$5([W.chainId!=null?N8(W.chainId):"0x",m1(W.address),W.nonce!=null?N8(W.nonce):"0x"])]))}function e4(W){return X8(M9(W))}function RU(W){if(typeof W==="string")W=M9(W);return X8(t1([M9(gK),M9(String(W.length)),W]))}function rq(W,Y){let G=RU(W);return TU(G,Y)}var V_=new Uint8Array(32);V_.fill(0);var ys=BigInt(-1),U_=BigInt(0),Q_=BigInt(1),vs=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function gs(W){let Y=B0(W),G=Y.length%32;if(G)return t1([Y,V_.slice(G)]);return C0(Y)}var us=V7(Q_,32),hs=V7(U_,32),X_={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},cK=["name","version","chainId","verifyingContract","salt"];function J_(W){return function(Y){return r(typeof Y==="string",`invalid domain value for ${JSON.stringify(W)}`,`domain.${W}`,Y),Y}}var bs={name:J_("name"),version:J_("version"),chainId:function(W){let Y=g1(W,"domain.chainId");if(r(Y>=0,"invalid chain ID","domain.chainId",W),Number.isSafeInteger(Y))return Number(Y);return Mq(Y)},verifyingContract:function(W){try{return m1(W).toLowerCase()}catch(Y){}r(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",W)},salt:function(W){let Y=B0(W,"domain.salt");return r(Y.length===32,'invalid domain value "salt"',"domain.salt",W),C0(Y)}};function pK(W){{let Y=W.match(/^(u?)int(\d+)$/);if(Y){let G=Y[1]==="",X=parseInt(Y[2]);r(X%8===0&&X!==0&&X<=256&&Y[2]===String(X),"invalid numeric width","type",W);let J=Rq(vs,G?X-1:X),Z=G?(J+Q_)*ys:U_;return function(V){let U=g1(V,"value");return r(U>=Z&&U<=J,`value out-of-bounds for ${W}`,"value",U),V7(G?Tq(U,256):U,32)}}}{let Y=W.match(/^bytes(\d+)$/);if(Y){let G=parseInt(Y[1]);return r(G!==0&&G<=32&&Y[1]===String(G),"invalid bytes width","type",W),function(X){let J=B0(X);return r(J.length===G,`invalid length for ${W}`,"value",X),gs(X)}}}switch(W){case"address":return function(Y){return A5(m1(Y),32)};case"bool":return function(Y){return!Y?hs:us};case"bytes":return function(Y){return X8(Y)};case"string":return function(Y){return e4(Y)}}return null}function Z_(W,Y){return`${W}(${Y.map(({name:G,type:X})=>X+" "+G).join(",")})`}function aq(W){let Y=W.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);if(Y)return{base:Y[1],index:Y[2]+Y[4],array:{base:Y[1],prefix:Y[1]+Y[2],count:Y[5]?parseInt(Y[5]):-1}};return{base:W}}class E9{primaryType;#W;get types(){return JSON.parse(this.#W)}#Y;#G;constructor(W){this.#Y=new Map,this.#G=new Map;let Y=new Map,G=new Map,X=new Map,J={};Object.keys(W).forEach((U)=>{J[U]=W[U].map(({name:Q,type:H})=>{let{base:N,index:A}=aq(H);if(N==="int"&&!W.int)N="int256";if(N==="uint"&&!W.uint)N="uint256";return{name:Q,type:N+(A||"")}}),Y.set(U,new Set),G.set(U,[]),X.set(U,new Set)}),this.#W=JSON.stringify(J);for(let U in J){let Q=new Set;for(let H of J[U]){r(!Q.has(H.name),`duplicate variable name ${JSON.stringify(H.name)} in ${JSON.stringify(U)}`,"types",W),Q.add(H.name);let N=aq(H.type).base;if(r(N!==U,`circular type reference to ${JSON.stringify(N)}`,"types",W),pK(N))continue;r(G.has(N),`unknown type ${JSON.stringify(N)}`,"types",W),G.get(N).push(U),Y.get(U).add(N)}}let Z=Array.from(G.keys()).filter((U)=>G.get(U).length===0);r(Z.length!==0,"missing primary type","types",W),r(Z.length===1,`ambiguous primary types or unused types: ${Z.map((U)=>JSON.stringify(U)).join(", ")}`,"types",W),H8(this,{primaryType:Z[0]});function V(U,Q){r(!Q.has(U),`circular type reference to ${JSON.stringify(U)}`,"types",W),Q.add(U);for(let H of Y.get(U)){if(!G.has(H))continue;V(H,Q);for(let N of Q)X.get(N).add(H)}Q.delete(U)}V(this.primaryType,new Set);for(let[U,Q]of X){let H=Array.from(Q);H.sort(),this.#Y.set(U,Z_(U,J[U])+H.map((N)=>Z_(N,J[N])).join(""))}}getEncoder(W){let Y=this.#G.get(W);if(!Y)Y=this.#X(W),this.#G.set(W,Y);return Y}#X(W){{let X=pK(W);if(X)return X}let Y=aq(W).array;if(Y){let X=Y.prefix,J=this.getEncoder(X);return(Z)=>{r(Y.count===-1||Y.count===Z.length,`array length mismatch; expected length ${Y.count}`,"value",Z);let V=Z.map(J);if(this.#Y.has(X))V=V.map(X8);return X8(t1(V))}}let G=this.types[W];if(G){let X=e4(this.#Y.get(W));return(J)=>{let Z=G.map(({name:V,type:U})=>{let Q=this.getEncoder(U)(J[V]);if(this.#Y.has(U))return X8(Q);return Q});return Z.unshift(X),t1(Z)}}r(!1,`unknown type: ${W}`,"type",W)}encodeType(W){let Y=this.#Y.get(W);return r(Y,`unknown type: ${JSON.stringify(W)}`,"name",W),Y}encodeData(W,Y){return this.getEncoder(W)(Y)}hashStruct(W,Y){return X8(this.encodeData(W,Y))}encode(W){return this.encodeData(this.primaryType,W)}hash(W){return this.hashStruct(this.primaryType,W)}_visit(W,Y,G){if(pK(W))return G(W,Y);let X=aq(W).array;if(X)return r(X.count===-1||X.count===Y.length,`array length mismatch; expected length ${X.count}`,"value",Y),Y.map((Z)=>this._visit(X.prefix,Z,G));let J=this.types[W];if(J)return J.reduce((Z,{name:V,type:U})=>{return Z[V]=this._visit(U,Y[V],G),Z},{});r(!1,`unknown type: ${W}`,"type",W)}visit(W,Y){return this._visit(this.primaryType,W,Y)}static from(W){return new E9(W)}static getPrimaryType(W){return E9.from(W).primaryType}static hashStruct(W,Y,G){return E9.from(Y).hashStruct(W,G)}static hashDomain(W){let Y=[];for(let G in W){if(W[G]==null)continue;let X=X_[G];r(X,`invalid typed-data domain key: ${JSON.stringify(G)}`,"domain",W),Y.push({name:G,type:X})}return Y.sort((G,X)=>{return cK.indexOf(G.name)-cK.indexOf(X.name)}),E9.hashStruct("EIP712Domain",{EIP712Domain:Y},W)}static encode(W,Y,G){return t1(["0x1901",E9.hashDomain(W),E9.from(Y).hash(G)])}static hash(W,Y,G){return X8(E9.encode(W,Y,G))}static async resolveNames(W,Y,G,X){W=Object.assign({},W);for(let V in W)if(W[V]==null)delete W[V];let J={};if(W.verifyingContract&&!R9(W.verifyingContract,20))J[W.verifyingContract]="0x";let Z=E9.from(Y);Z.visit(G,(V,U)=>{if(V==="address"&&!R9(U,20))J[U]="0x";return U});for(let V in J)J[V]=await X(V);if(W.verifyingContract&&J[W.verifyingContract])W.verifyingContract=J[W.verifyingContract];return G=Z.visit(G,(V,U)=>{if(V==="address"&&J[U])return J[U];return U}),{domain:W,value:G}}static getPayload(W,Y,G){E9.hashDomain(W);let X={},J=[];cK.forEach((U)=>{let Q=W[U];if(Q==null)return;X[U]=bs[U](Q),J.push({name:U,type:X_[U]})});let Z=E9.from(Y);Y=Z.types;let V=Object.assign({},Y);return r(V.EIP712Domain==null,"types must not contain EIP712Domain type","types.EIP712Domain",Y),V.EIP712Domain=J,Z.encode(G),{types:V,domain:X,primaryType:Z.primaryType,message:Z.visit(G,(U,Q)=>{if(U.match(/^bytes(\d*)/))return C0(B0(Q));if(U.match(/^u?int/))return g1(Q).toString();switch(U){case"address":return Q.toLowerCase();case"bool":return!!Q;case"string":return r(typeof Q==="string","invalid string","value",Q),Q}r(!1,"unsupported type","type",U)})}}}var H_=BigInt(0);function lK(W){if(W==null)return null;return W}function s8(W){if(W==null)return null;return W.toString()}function MU(W){let Y={};if(W.to)Y.to=W.to;if(W.from)Y.from=W.from;if(W.data)Y.data=C0(W.data);let G="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(let J of G){if(!(J in W)||W[J]==null)continue;Y[J]=g1(W[J],`request.${J}`)}let X="type,nonce".split(/,/);for(let J of X){if(!(J in W)||W[J]==null)continue;Y[J]=r8(W[J],`request.${J}`)}if(W.accessList)Y.accessList=vY(W.accessList);if(W.authorizationList)Y.authorizationList=W.authorizationList.slice();if("blockTag"in W)Y.blockTag=W.blockTag;if("enableCcipRead"in W)Y.enableCcipRead=!!W.enableCcipRead;if("customData"in W)Y.customData=W.customData;if("blobVersionedHashes"in W&&W.blobVersionedHashes)Y.blobVersionedHashes=W.blobVersionedHashes.slice();if("kzg"in W)Y.kzg=W.kzg;if("blobs"in W&&W.blobs)Y.blobs=W.blobs.map((J)=>{if(n7(J))return C0(J);return Object.assign({},J)});return Y}class N_{provider;number;hash;timestamp;parentHash;parentBeaconBlockRoot;nonce;difficulty;gasLimit;gasUsed;stateRoot;receiptsRoot;blobGasUsed;excessBlobGas;miner;prevRandao;extraData;baseFeePerGas;#W;constructor(W,Y){this.#W=W.transactions.map((G)=>{if(typeof G!=="string")return new sq(G,Y);return G}),H8(this,{provider:Y,hash:lK(W.hash),number:W.number,timestamp:W.timestamp,parentHash:W.parentHash,parentBeaconBlockRoot:W.parentBeaconBlockRoot,nonce:W.nonce,difficulty:W.difficulty,gasLimit:W.gasLimit,gasUsed:W.gasUsed,blobGasUsed:W.blobGasUsed,excessBlobGas:W.excessBlobGas,miner:W.miner,prevRandao:lK(W.prevRandao),extraData:W.extraData,baseFeePerGas:lK(W.baseFeePerGas),stateRoot:W.stateRoot,receiptsRoot:W.receiptsRoot})}get transactions(){return this.#W.map((W)=>{if(typeof W==="string")return W;return W.hash})}get prefetchedTransactions(){let W=this.#W.slice();if(W.length===0)return[];return X1(typeof W[0]==="object","transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),W}toJSON(){let{baseFeePerGas:W,difficulty:Y,extraData:G,gasLimit:X,gasUsed:J,hash:Z,miner:V,prevRandao:U,nonce:Q,number:H,parentHash:N,parentBeaconBlockRoot:A,stateRoot:q,receiptsRoot:z,timestamp:w,transactions:D}=this;return{_type:"Block",baseFeePerGas:s8(W),difficulty:s8(Y),extraData:G,gasLimit:s8(X),gasUsed:s8(J),blobGasUsed:s8(this.blobGasUsed),excessBlobGas:s8(this.excessBlobGas),hash:Z,miner:V,prevRandao:U,nonce:Q,number:H,parentHash:N,timestamp:w,parentBeaconBlockRoot:A,stateRoot:q,receiptsRoot:z,transactions:D}}[Symbol.iterator](){let W=0,Y=this.transactions;return{next:()=>{if(W<this.length)return{value:Y[W++],done:!1};return{value:void 0,done:!0}}}}get length(){return this.#W.length}get date(){if(this.timestamp==null)return null;return new Date(this.timestamp*1000)}async getTransaction(W){let Y=void 0;if(typeof W==="number")Y=this.#W[W];else{let G=W.toLowerCase();for(let X of this.#W)if(typeof X==="string"){if(X!==G)continue;Y=X;break}else{if(X.hash!==G)continue;Y=X;break}}if(Y==null)throw Error("no such tx");if(typeof Y==="string")return await this.provider.getTransaction(Y);else return Y}getPrefetchedTransaction(W){let Y=this.prefetchedTransactions;if(typeof W==="number")return Y[W];W=W.toLowerCase();for(let G of Y)if(G.hash===W)return G;r(!1,"no matching transaction","indexOrHash",W)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw Error("");return cs(this)}}class dK{provider;transactionHash;blockHash;blockNumber;removed;address;data;topics;index;transactionIndex;constructor(W,Y){this.provider=Y;let G=Object.freeze(W.topics.slice());H8(this,{transactionHash:W.transactionHash,blockHash:W.blockHash,blockNumber:W.blockNumber,removed:W.removed,address:W.address,data:W.data,topics:G,index:W.index,transactionIndex:W.transactionIndex})}toJSON(){let{address:W,blockHash:Y,blockNumber:G,data:X,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}=this;return{_type:"log",address:W,blockHash:Y,blockNumber:G,data:X,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}}async getBlock(){let W=await this.provider.getBlock(this.blockHash);return X1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransaction(){let W=await this.provider.getTransaction(this.transactionHash);return X1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransactionReceipt(){let W=await this.provider.getTransactionReceipt(this.transactionHash);return X1(!!W,"failed to find transaction receipt","UNKNOWN_ERROR",{}),W}removedEvent(){return ps(this)}}class q_{provider;to;from;contractAddress;hash;index;blockHash;blockNumber;logsBloom;gasUsed;blobGasUsed;cumulativeGasUsed;gasPrice;blobGasPrice;type;status;root;#W;constructor(W,Y){this.#W=Object.freeze(W.logs.map((X)=>{return new dK(X,Y)}));let G=H_;if(W.effectiveGasPrice!=null)G=W.effectiveGasPrice;else if(W.gasPrice!=null)G=W.gasPrice;H8(this,{provider:Y,to:W.to,from:W.from,contractAddress:W.contractAddress,hash:W.hash,index:W.index,blockHash:W.blockHash,blockNumber:W.blockNumber,logsBloom:W.logsBloom,gasUsed:W.gasUsed,cumulativeGasUsed:W.cumulativeGasUsed,blobGasUsed:W.blobGasUsed,gasPrice:G,blobGasPrice:W.blobGasPrice,type:W.type,status:W.status,root:W.root})}get logs(){return this.#W}toJSON(){let{to:W,from:Y,contractAddress:G,hash:X,index:J,blockHash:Z,blockNumber:V,logsBloom:U,logs:Q,status:H,root:N}=this;return{_type:"TransactionReceipt",blockHash:Z,blockNumber:V,contractAddress:G,cumulativeGasUsed:s8(this.cumulativeGasUsed),from:Y,gasPrice:s8(this.gasPrice),blobGasUsed:s8(this.blobGasUsed),blobGasPrice:s8(this.blobGasPrice),gasUsed:s8(this.gasUsed),hash:X,index:J,logs:Q,logsBloom:U,root:N,status:H,to:W}}get length(){return this.logs.length}[Symbol.iterator](){let W=0;return{next:()=>{if(W<this.length)return{value:this.logs[W++],done:!1};return{value:void 0,done:!0}}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){let W=await this.provider.getBlock(this.blockHash);if(W==null)throw Error("TODO");return W}async getTransaction(){let W=await this.provider.getTransaction(this.hash);if(W==null)throw Error("TODO");return W}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return I_(this)}reorderedEvent(W){return X1(!W||W.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),A_(this,W)}}class sq{provider;blockNumber;blockHash;index;hash;type;to;from;nonce;gasLimit;gasPrice;maxPriorityFeePerGas;maxFeePerGas;maxFeePerBlobGas;data;value;chainId;signature;accessList;blobVersionedHashes;authorizationList;#W;constructor(W,Y){this.provider=Y,this.blockNumber=W.blockNumber!=null?W.blockNumber:null,this.blockHash=W.blockHash!=null?W.blockHash:null,this.hash=W.hash,this.index=W.index,this.type=W.type,this.from=W.from,this.to=W.to||null,this.gasLimit=W.gasLimit,this.nonce=W.nonce,this.data=W.data,this.value=W.value,this.gasPrice=W.gasPrice,this.maxPriorityFeePerGas=W.maxPriorityFeePerGas!=null?W.maxPriorityFeePerGas:null,this.maxFeePerGas=W.maxFeePerGas!=null?W.maxFeePerGas:null,this.maxFeePerBlobGas=W.maxFeePerBlobGas!=null?W.maxFeePerBlobGas:null,this.chainId=W.chainId,this.signature=W.signature,this.accessList=W.accessList!=null?W.accessList:null,this.blobVersionedHashes=W.blobVersionedHashes!=null?W.blobVersionedHashes:null,this.authorizationList=W.authorizationList!=null?W.authorizationList:null,this.#W=-1}toJSON(){let{blockNumber:W,blockHash:Y,index:G,hash:X,type:J,to:Z,from:V,nonce:U,data:Q,signature:H,accessList:N,blobVersionedHashes:A}=this;return{_type:"TransactionResponse",accessList:N,blockNumber:W,blockHash:Y,blobVersionedHashes:A,chainId:s8(this.chainId),data:Q,from:V,gasLimit:s8(this.gasLimit),gasPrice:s8(this.gasPrice),hash:X,maxFeePerGas:s8(this.maxFeePerGas),maxPriorityFeePerGas:s8(this.maxPriorityFeePerGas),maxFeePerBlobGas:s8(this.maxFeePerBlobGas),nonce:U,signature:H,to:Z,index:G,type:J,value:s8(this.value)}}async getBlock(){let W=this.blockNumber;if(W==null){let G=await this.getTransaction();if(G)W=G.blockNumber}if(W==null)return null;let Y=this.provider.getBlock(W);if(Y==null)throw Error("TODO");return Y}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(this.blockNumber==null){let{tx:Y,blockNumber:G}=await o7({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});if(Y==null||Y.blockNumber==null)return 0;return G-Y.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(W,Y){let G=W==null?1:W,X=Y==null?0:Y,J=this.#W,Z=-1,V=J===-1?!0:!1,U=async()=>{if(V)return null;let{blockNumber:A,nonce:q}=await o7({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(q<this.nonce){J=A;return}if(V)return null;let z=await this.getTransaction();if(z&&z.blockNumber!=null)return;if(Z===-1){if(Z=J-3,Z<this.#W)Z=this.#W}while(Z<=A){if(V)return null;let w=await this.provider.getBlock(Z,!0);if(w==null)return;for(let D of w)if(D===this.hash)return;for(let D=0;D<w.length;D++){let T=await w.getTransaction(D);if(T.from===this.from&&T.nonce===this.nonce){if(V)return null;let x=await this.provider.getTransactionReceipt(T.hash);if(x==null)return;if(A-x.blockNumber+1<G)return;let g="replaced";if(T.data===this.data&&T.to===this.to&&T.value===this.value)g="repriced";else if(T.data==="0x"&&T.from===T.to&&T.value===H_)g="cancelled";X1(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:g==="replaced"||g==="cancelled",reason:g,replacement:T.replaceableTransaction(J),hash:T.hash,receipt:x})}}Z++}return},Q=(A)=>{if(A==null||A.status!==0)return A;X1(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:A.to,from:A.from,data:""},receipt:A})},H=await this.provider.getTransactionReceipt(this.hash);if(G===0)return Q(H);if(H){if(G===1||await H.confirmations()>=G)return Q(H)}else if(await U(),G===0)return null;return await new Promise((A,q)=>{let z=[],w=()=>{z.forEach((T)=>T())};if(z.push(()=>{V=!0}),X>0){let T=setTimeout(()=>{w(),q(AU("wait for transaction timeout","TIMEOUT"))},X);z.push(()=>{clearTimeout(T)})}let D=async(T)=>{if(await T.confirmations()>=G){w();try{A(Q(T))}catch(x){q(x)}}};if(z.push(()=>{this.provider.off(this.hash,D)}),this.provider.on(this.hash,D),J>=0){let T=async()=>{try{await U()}catch(x){if(Cq(x,"TRANSACTION_REPLACED")){w(),q(x);return}}if(!V)this.provider.once("block",T)};z.push(()=>{this.provider.off("block",T)}),this.provider.once("block",T)}})}isMined(){return this.blockHash!=null}isLegacy(){return this.type===0}isBerlin(){return this.type===1}isLondon(){return this.type===2}isCancun(){return this.type===3}removedEvent(){return X1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),I_(this)}reorderedEvent(W){return X1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),X1(!W||W.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),A_(this,W)}replaceableTransaction(W){r(Number.isInteger(W)&&W>=0,"invalid startBlock","startBlock",W);let Y=new sq(this,this.provider);return Y.#W=W,Y}}function cs(W){return{orphan:"drop-block",hash:W.hash,number:W.number}}function A_(W,Y){return{orphan:"reorder-transaction",tx:W,other:Y}}function I_(W){return{orphan:"drop-transaction",tx:W}}function ps(W){return{orphan:"drop-log",log:{transactionHash:W.transactionHash,blockHash:W.blockHash,blockNumber:W.blockNumber,address:W.address,data:W.data,topics:Object.freeze(W.topics.slice()),index:W.index}}}function uY(W,Y){if(W.provider)return W.provider;X1(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:Y})}async function z_(W,Y){let G=MU(Y);if(G.to!=null)G.to=s4(G.to,W);if(G.from!=null){let X=G.from;G.from=Promise.all([W.getAddress(),s4(X,W)]).then(([J,Z])=>{return r(J.toLowerCase()===Z.toLowerCase(),"transaction from mismatch","tx.from",Z),J})}else G.from=W.getAddress();return await o7(G)}class PU{provider;constructor(W){H8(this,{provider:W||null})}async getNonce(W){return uY(this,"getTransactionCount").getTransactionCount(await this.getAddress(),W)}async populateCall(W){return await z_(this,W)}async populateTransaction(W){let Y=uY(this,"populateTransaction"),G=await z_(this,W);if(G.nonce==null)G.nonce=await this.getNonce("pending");if(G.gasLimit==null)G.gasLimit=await this.estimateGas(G);let X=await this.provider.getNetwork();if(G.chainId!=null){let Z=g1(G.chainId);r(Z===X.chainId,"transaction chainId mismatch","tx.chainId",W.chainId)}else G.chainId=X.chainId;let J=G.maxFeePerGas!=null||G.maxPriorityFeePerGas!=null;if(G.gasPrice!=null&&(G.type===2||J))r(!1,"eip-1559 transaction do not support gasPrice","tx",W);else if((G.type===0||G.type===1)&&J)r(!1,"pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","tx",W);if((G.type===2||G.type==null)&&(G.maxFeePerGas!=null&&G.maxPriorityFeePerGas!=null))G.type=2;else if(G.type===0||G.type===1){let Z=await Y.getFeeData();if(X1(Z.gasPrice!=null,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),G.gasPrice==null)G.gasPrice=Z.gasPrice}else{let Z=await Y.getFeeData();if(G.type==null)if(Z.maxFeePerGas!=null&&Z.maxPriorityFeePerGas!=null){if(G.authorizationList&&G.authorizationList.length)G.type=4;else G.type=2;if(G.gasPrice!=null){let V=G.gasPrice;delete G.gasPrice,G.maxFeePerGas=V,G.maxPriorityFeePerGas=V}else{if(G.maxFeePerGas==null)G.maxFeePerGas=Z.maxFeePerGas;if(G.maxPriorityFeePerGas==null)G.maxPriorityFeePerGas=Z.maxPriorityFeePerGas}}else if(Z.gasPrice!=null){if(X1(!J,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),G.gasPrice==null)G.gasPrice=Z.gasPrice;G.type=0}else X1(!1,"failed to get consistent fee data","UNSUPPORTED_OPERATION",{operation:"signer.getFeeData"});else if(G.type===2||G.type===3||G.type===4){if(G.maxFeePerGas==null)G.maxFeePerGas=Z.maxFeePerGas;if(G.maxPriorityFeePerGas==null)G.maxPriorityFeePerGas=Z.maxPriorityFeePerGas}}return await o7(G)}async populateAuthorization(W){let Y=Object.assign({},W);if(Y.chainId==null)Y.chainId=(await uY(this,"getNetwork").getNetwork()).chainId;if(Y.nonce==null)Y.nonce=await this.getNonce();return Y}async estimateGas(W){return uY(this,"estimateGas").estimateGas(await this.populateCall(W))}async call(W){return uY(this,"call").call(await this.populateCall(W))}async resolveName(W){return await uY(this,"resolveName").resolveName(W)}async sendTransaction(W){let Y=uY(this,"sendTransaction"),G=await this.populateTransaction(W);delete G.from;let X=t9.from(G);return await Y.broadcastTransaction(await this.signTransaction(X))}authorize(W){X1(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}class LU extends PU{address;constructor(W,Y){super(Y);H8(this,{address:W})}async getAddress(){return this.address}connect(W){return new LU(this.address,W)}#W(W,Y){X1(!1,`VoidSigner cannot sign ${W}`,"UNSUPPORTED_OPERATION",{operation:Y})}async signTransaction(W){this.#W("transactions","signTransaction")}async signMessage(W){this.#W("messages","signMessage")}async signTypedData(W,Y,G){this.#W("typed-data","signTypedData")}}class hY extends PU{address;#W;constructor(W,Y){super(Y);r(W&&typeof W.sign==="function","invalid private key","privateKey","[ REDACTED ]"),this.#W=W;let G=t4(this.signingKey.publicKey);H8(this,{address:G})}get signingKey(){return this.#W}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(W){return new hY(this.#W,W)}async signTransaction(W){W=MU(W);let{to:Y,from:G}=await o7({to:W.to?s4(W.to,this):void 0,from:W.from?s4(W.from,this):void 0});if(Y!=null)W.to=Y;if(G!=null)W.from=G;if(W.from!=null)r(m1(W.from)===this.address,"transaction from address mismatch","tx.from",W.from),delete W.from;let X=t9.from(W);return X.signature=this.signingKey.sign(X.unsignedHash),X.serialized}async signMessage(W){return this.signMessageSync(W)}signMessageSync(W){return this.signingKey.sign(RU(W)).serialized}authorizeSync(W){r(typeof W.address==="string","invalid address for authorizeSync","auth.address",W);let Y=this.signingKey.sign(iq(W));return Object.assign({},{address:m1(W.address),nonce:g1(W.nonce||0),chainId:g1(W.chainId||0)},{signature:Y})}async authorize(W){return W=Object.assign({},W,{address:await s4(W.address,this)}),this.authorizeSync(await this.populateAuthorization(W))}async signTypedData(W,Y,G){let X=await E9.resolveNames(W,Y,G,async(J)=>{X1(this.provider!=null,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:J}});let Z=await this.provider.resolveName(J);return X1(Z!=null,"unconfigured ENS name","UNCONFIGURED_NAME",{value:J}),Z});return this.signingKey.sign(E9.hash(X.domain,Y,X.value)).serialized}}var tq=" !#$%&'()*+,-./<=>?@[]^_`{|}~",ls=/^[a-z]*$/i;function w_(W,Y){let G=97;return W.reduce((X,J)=>{if(J===Y)G++;else if(J.match(ls))X.push(String.fromCharCode(G)+J);else G=97,X.push(J);return X},[])}function ds(W,Y){for(let J=tq.length-1;J>=0;J--)W=W.split(tq[J]).join(Y.substring(2*J,2*J+2));let G=[],X=W.replace(/(:|([0-9])|([A-Z][a-z]*))/g,(J,Z,V,U)=>{if(V)for(let Q=parseInt(V);Q>=0;Q--)G.push(";");else G.push(Z.toLowerCase());return""});if(X)throw Error(`leftovers: ${JSON.stringify(X)}`);return w_(w_(G,";"),":")}function j_(W){return r(W[0]==="0","unsupported auwl data","data",W),ds(W.substring(1+2*tq.length),W.substring(1,1+2*tq.length))}class oK{locale;constructor(W){H8(this,{locale:W})}split(W){return W.toLowerCase().split(/\s+/g)}join(W){return W.join(" ")}}class nK extends oK{#W;#Y;constructor(W,Y,G){super(W);this.#W=Y,this.#Y=G,this.#G=null}get _data(){return this.#W}_decodeWords(){return j_(this.#W)}#G;#X(){if(this.#G==null){let W=this._decodeWords();if(e4(W.join(`
|
|
248
|
+
`);return X.forEach((J)=>{if(J.startsWith("m="))G.push([J]);else if(G.length>0)G[G.length-1].push(J);else Y.push(J)}),[Y,G]}function OO(W){if(W.includes(":")){let Y=m4(W.slice(2),":");return[Y[0],Y[1]]}else return[W.slice(2),void 0]}function KO(W,Y,G=(X)=>X.toString()){let X=Y.split(" ");if(X.length>0)W.push(new oV(X[0],X.slice(1).map(G)))}function Zx(W){let Y=DY.fromSdp(W);return eV(Y)}var Lr=class{constructor(W,Y){this.sdp=W,this.type=Y}static isThis(W){if(typeof W?.sdp==="string")return!0}toSdp(){return{sdp:this.sdp,type:this.type}}};function VS(W,Y){let X=new PN(pi(64)).toString().slice(0,8),J=0;Y.origin=`- ${X} 0 IN IP4 0.0.0.0`,Y.msidSemantic.push(new oV("WMS",["*"])),Y.type=W}function Qq(W){let Y={};return W.split(";").forEach((G)=>{if(G.includes("=")){let[X,J]=m4(G,"=");if(Ri.includes(X))Y[X]=Number(J);else Y[X]=J}else if(G.includes(":")){let[X,J]=G.split(":");Y[X]=Number.isNaN(Number(J))?J:Number(J)}else Y[G]=void 0}),Y}var tO=class{ssrc;cname;msid;msLabel;label;constructor(W){Object.assign(this,W)}},kN=M1("werift:packages/webrtc/src/media/rtpReceiver.ts"),Vx=class{constructor(W,Y,G){this.config=W,this.kind=Y,this.rtcpSsrc=G}codecs={};get codecArray(){return Object.values(this.codecs).sort((W,Y)=>W.payloadType-Y.payloadType)}ssrcByRtx={};nack=new hi(this);audioRedHandler=new to;type="receiver";uuid=wi().toString();tracks=[];trackBySSRC={};trackByRID={};lastSRtimestamp={};receiveLastSRTimestamp={};onPacketLost=this.nack.onPacketLost;onRtcp=new p0;dtlsTransport;sdesMid;latestRid;latestRepairedRid;receiverTWCC;stopped=!1;remoteStreamId;remoteTrackId;rtcpRunning=!1;rtcpCancel=new AbortController;remoteStreams={};setDtlsTransport(W){this.dtlsTransport=W}get track(){return this.tracks[0]??new uO({kind:this.kind})}get nackEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type==="nack")}get twccEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===Ui().type)}get pliEnabled(){return this.codecArray[0]?.rtcpFeedback.find((W)=>W.type===QU().type)}prepareReceive(W){W.codecs.forEach((Y)=>{this.codecs[Y.payloadType]=Y}),W.encodings.forEach((Y)=>{if(Y.rtx)this.ssrcByRtx[Y.rtx.ssrc]=Y.ssrc})}setupTWCC(W){if(this.twccEnabled&&!this.receiverTWCC)this.receiverTWCC=new fi(this.dtlsTransport,this.rtcpSsrc,W)}addTrack(W){if(this.tracks.find((G)=>{if(G.rid)return G.rid===W.rid;if(G.ssrc)return G.ssrc===W.ssrc}))return!1;if(this.tracks.push(W),W.ssrc)this.trackBySSRC[W.ssrc]=W;if(W.rid)this.trackByRID[W.rid]=W;return!0}stop(){if(this.stopped=!0,this.rtcpRunning=!1,this.rtcpCancel.abort(),this.receiverTWCC)this.receiverTWCC.twccRunning=!1;this.nack.close()}async runRtcp(){if(this.rtcpRunning||this.stopped)return;this.rtcpRunning=!0;try{while(this.rtcpRunning){await zO(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=Object.entries(this.remoteStreams).map(([G,X])=>{let J=0,Z=0;if(this.lastSRtimestamp[G]){J=this.lastSRtimestamp[G];let V=Vq()-this.receiveLastSRTimestamp[G];if(V>0&&V<65536)Z=lV(V*65536)}return new YK({ssrc:Number(G),fractionLost:X.fraction_lost,packetsLost:X.packets_lost,highestSequence:X.max_seq,jitter:X.jitter,lsr:J,dlsr:Z})}),Y=new rV({ssrc:this.rtcpSsrc,reports:W});try{if(this.config.debug.receiverReportDelay)await zO(this.config.debug.receiverReportDelay);await this.dtlsTransport.sendRtcp([Y])}catch(G){kN("sendRtcp failed",G),await zO(500+Math.random()*1000)}}}catch(W){}}async getStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id);for(let X of this.tracks){if(!X.ssrc)continue;let J=this.remoteStreams[X.ssrc];if(!J)continue;let Z={type:"inbound-rtp",id:Z8("inbound-rtp",X.ssrc),timestamp:W,ssrc:X.ssrc,kind:this.kind,transportId:G,codecId:this.codecs[0]?Z8("codec",this.codecs[0].payloadType,G):void 0,mid:this.sdesMid,trackIdentifier:X.id,packetsReceived:J.packets_received,packetsLost:J.packets_lost,jitter:J.jitter};if(Y.push(Z),this.lastSRtimestamp[X.ssrc]){let V={type:"remote-outbound-rtp",id:Z8("remote-outbound-rtp",X.ssrc),timestamp:W,ssrc:X.ssrc,kind:this.kind,transportId:G,codecId:Z.codecId,localId:Z.id,remoteTimestamp:this.receiveLastSRTimestamp[X.ssrc]*1000};Y.push(V)}}return Y}async sendRtcpPLI(W){if(!this.pliEnabled){kN("pli not supported",{mediaSsrc:W});return}if(this.stopped)return;kN("sendRtcpPLI",{mediaSsrc:W});let Y=new iV({feedback:new Yq({senderSsrc:this.rtcpSsrc,mediaSsrc:W})});try{await this.dtlsTransport.sendRtcp([Y])}catch(G){kN(G)}}handleRtcpPacket(W){switch(W.type){case bX.type:{let Y=W;this.lastSRtimestamp[Y.ssrc]=d2(Y.senderInfo.ntpTimestamp),this.receiveLastSRTimestamp[Y.ssrc]=Vq();let G=this.trackBySSRC[W.ssrc];if(G)G.onReceiveRtcp.execute(W)}break}this.onRtcp.execute(W)}handleRtpBySsrc=(W,Y)=>{let G=this.trackBySSRC[W.header.ssrc];this.handleRTP(W,Y,G)};handleRtpByRid=(W,Y,G)=>{let X=this.trackByRID[Y];if(!this.trackBySSRC[W.header.ssrc])this.trackBySSRC[W.header.ssrc]=X;this.handleRTP(W,G,X)};handleRTP(W,Y,G){if(this.stopped)return;let X=this.codecs[W.header.payloadType];if(!X)return;if(this.remoteStreams[W.header.ssrc]=this.remoteStreams[W.header.ssrc]??new ci(X.clockRate),this.remoteStreams[W.header.ssrc].add(W),this.receiverTWCC){let Z=Y[C9.transportWideCC];if(!Z==null)throw Error("undefined");this.receiverTWCC.handleTWCC(Z)}else if(this.twccEnabled)this.setupTWCC(W.header.ssrc);if(X.name.toLowerCase()==="rtx"){let Z=this.ssrcByRtx[W.header.ssrc],V=Qq(X.parameters??""),U=this.codecs[V.apt];if(W.payload.length<2)return;W=eo(W,U.payloadType,Z),G=this.trackBySSRC[Z]}let J;if(X.name.toLowerCase()==="red"){if(J=X2.deSerialize(W.payload),!Object.keys(this.codecs).includes(J.header.fields[0].blockPT.toString()))return}if(G?.kind==="video"&&this.nackEnabled)this.nack.addPacket(W);if(G)if(J){if(G.kind==="audio"){let Z=this.audioRedHandler.push(J,W);for(let V of Z)G.onReceiveRtp.execute(V.clone(),Y)}}else G.onReceiveRtp.execute(W.clone(),Y);this.runRtcp()}},hV=M1("werift:packages/webrtc/src/media/router.ts"),Br=class{ssrcTable={};ridTable={};extIdUriMap={};constructor(){}registerRtpSender(W){this.ssrcTable[W.ssrc]=W}registerRtpReceiver(W,Y){hV("registerRtpReceiver",Y),this.ssrcTable[Y]=W}registerRtpReceiverBySsrc(W,Y){hV("registerRtpReceiverBySsrc",Y),Y.encodings.filter((G)=>G.ssrc!=null).forEach((G,X)=>{if(this.registerRtpReceiver(W.receiver,G.ssrc),W.addTrack(new uO({ssrc:G.ssrc,kind:W.kind,id:W.sender.trackId,remote:!0,codec:Y.codecs[X]})),G.rtx)this.registerRtpReceiver(W.receiver,G.rtx.ssrc)}),Y.headerExtensions.forEach((G)=>{this.extIdUriMap[G.id]=G.uri})}registerRtpReceiverByRid(W,Y,G){let[X]=G.codecs;hV("registerRtpReceiverByRid",Y),W.addTrack(new uO({rid:Y.rid,kind:W.kind,id:W.sender.trackId,remote:!0,codec:X})),this.ridTable[Y.rid]=W.receiver}routeRtp=(W)=>{let Y=uo(W.header.extensions,this.extIdUriMap),G=this.ssrcTable[W.header.ssrc],X=Y[C9.sdesRTPStreamID];if(typeof X==="string")G=this.ridTable[X],G.latestRid=X,G.handleRtpByRid(W,X,Y);else if(G)G.handleRtpBySsrc(W,Y);else if(G=Object.values(this.ridTable).filter((V)=>V instanceof Vx).find((V)=>V.trackBySSRC[W.header.ssrc]),G)hV("simulcast register receiver by ssrc",W.header.ssrc),this.registerRtpReceiver(G,W.header.ssrc),G.handleRtpBySsrc(W,Y);if(!G){hV("ssrcReceiver not found");return}let J=Y[C9.sdesMid];if(typeof J==="string")G.sdesMid=J;let Z=Y[C9.repairedRtpStreamId];if(typeof Z==="string")G.latestRepairedRid=Z};routeRtcp=(W)=>{let Y=[];switch(W.type){case bX.type:W=W,Y.push(this.ssrcTable[W.ssrc]);break;case rV.type:W=W,W.reports.forEach((G)=>{Y.push(this.ssrcTable[G.ssrc])});break;case Zq.type:{let G=W}break;case hX.type:{let G=W;if(G.feedback)Y.push(this.ssrcTable[G.feedback.mediaSourceSsrc])}break;case iV.type:{let G=W;switch(G.feedback.count){case Gq.count:{let X=G.feedback;Y.push(this.ssrcTable[X.ssrcFeedbacks[0]])}break;default:Y.push(this.ssrcTable[G.feedback.senderSsrc]||this.ssrcTable[G.feedback.mediaSsrc])}}break}Y.filter((G)=>G).forEach((G)=>G.handleRtcpPacket(W))}},Er=class{numPackets=0;totalSize=0;firstPacketSentAtMs=0;lastPacketSentAtMs=0;firstPacketReceivedAtMs=0;lastPacketReceivedAtMs=0;addPacket(W,Y,G){if(this.numPackets===0)this.firstPacketSentAtMs=Y,this.firstPacketReceivedAtMs=G,this.lastPacketSentAtMs=Y,this.lastPacketReceivedAtMs=G;else{if(Y<this.firstPacketSentAtMs)this.firstPacketSentAtMs=Y;if(G<this.firstPacketReceivedAtMs)this.firstPacketReceivedAtMs=G;if(Y>this.lastPacketSentAtMs)this.lastPacketSentAtMs=Y;if(G>this.lastPacketReceivedAtMs)this.lastPacketReceivedAtMs=G}this.numPackets++,this.totalSize+=W}reset(){this.numPackets=0,this.totalSize=0,this.firstPacketSentAtMs=0,this.lastPacketSentAtMs=0,this.firstPacketReceivedAtMs=0,this.lastPacketReceivedAtMs=0}get receiveBitrate(){let W=this.lastPacketReceivedAtMs-this.firstPacketReceivedAtMs,Y=this.totalSize/W*8*1000;return Wq(Y)}get sendBitrate(){let W=this.lastPacketSentAtMs-this.firstPacketSentAtMs,Y=this.totalSize/W*8*1000;return Wq(Y)}},xX=20,$r=10,Fr=class{congestion=!1;onAvailableBitrate=new p0;onCongestion=new p0;onCongestionScore=new p0;congestionCounter=0;cumulativeResult=new Er;sentInfos={};_congestionScore=1;get congestionScore(){return this._congestionScore}set congestionScore(W){this._congestionScore=W,this.onCongestionScore.execute(W)}_availableBitrate=0;get availableBitrate(){return this._availableBitrate}set availableBitrate(W){this._availableBitrate=W,this.onAvailableBitrate.execute(W)}constructor(){}receiveTWCC(W){let G=l2()-this.cumulativeResult.firstPacketSentAtMs;if(G>1000){if(this.cumulativeResult.reset(),this.congestionCounter<xX)this.congestionCounter++;else if(this.congestionScore<$r)this.congestionScore++;if(this.congestionCounter>=xX&&!this.congestion)this.congestion=!0,this.onCongestion.execute(this.congestion)}for(let X of W.packetResults){if(!X.received)continue;let J=X.sequenceNumber,Z=this.sentInfos[J];if(!Z)continue;if(!X.receivedAtMs)continue;this.cumulativeResult.addPacket(Z.size,Z.sendingAtMs,X.receivedAtMs)}if(G>=100&&this.cumulativeResult.numPackets>=20){if(this.availableBitrate=Math.min(this.cumulativeResult.sendBitrate,this.cumulativeResult.receiveBitrate),this.cumulativeResult.reset(),this.congestionCounter>-xX){let X=Wq(xX/2)+1,J=Wq(xX/4)+1,Z=X-(X-J)/10*this.congestionScore;this.congestionCounter=this.congestionCounter-Z}if(this.congestionCounter<=-xX){if(this.congestionScore>1)this.congestionScore--,this.onCongestion.execute(!1);this.congestionCounter=0}if(this.congestionCounter<=0&&this.congestion)this.congestion=!1,this.onCongestion.execute(this.congestion)}}rtpPacketSent(W){Object.keys(W).map((Y)=>Number(Y)).sort().filter((Y)=>Y<W.wideSeq).forEach((Y)=>{delete this.sentInfos[Y]}),this.sentInfos[W.wideSeq]=W}},DO=M1("werift:packages/webrtc/src/media/rtpSender.ts"),NS=128,qS=0.85,Sr=class{constructor(W){if(this.trackOrKind=W,this.kind=typeof this.trackOrKind==="string"?this.trackOrKind:this.trackOrKind.kind,typeof W!=="string"){if(W.streamId)this.streamId=W.streamId;this.registerTrack(W)}}type="sender";kind;ssrc=s1.Unpack("!L",US(4))[0];rtxSsrc=s1.Unpack("!L",US(4))[0];streamId=QS().toString();trackId=QS().toString();onReady=new p0;onRtcp=new p0;onPictureLossIndication=new p0;onGenericNack=new p0;senderBWE=new Fr;cname;mid;rtpStreamId;repairedRtpStreamId;rtxPayloadType;rtxSequenceNumber=zS();redRedundantPayloadType;_redDistance=2;redEncoder=new ao(this._redDistance);headerExtensions=[];disposeTrack;lastSRtimestamp;lastSentSRTimestamp;ntpTimestamp=0n;rtpTimestamp=0;octetCount=0;packetCount=0;rtt;receiverEstimatedMaxBitrate=0n;sequenceNumber;timestamp;timestampOffset=0;seqOffset=0;rtpCache=[];codec;dtlsTransport;dtlsDisposer=[];track;stopped=!1;rtcpRunning=!1;rtcpCancel=new AbortController;setDtlsTransport(W){if(this.dtlsTransport)this.dtlsDisposer.forEach((Y)=>Y());this.dtlsTransport=W,this.dtlsDisposer=[this.dtlsTransport.onStateChange.subscribe((Y)=>{if(Y==="connected")this.onReady.execute()}).unSubscribe]}get redDistance(){return this._redDistance}set redDistance(W){this._redDistance=W,this.redEncoder.distance=W}prepareSend(W){if(this.cname=W.rtcp?.cname,this.mid=W.muxId,this.headerExtensions=W.headerExtensions,this.rtpStreamId=W.rtpStreamId,this.repairedRtpStreamId=W.repairedRtpStreamId,this.codec=W.codecs[0],this.track)this.track.codec=this.codec;W.codecs.forEach((Y)=>{let G=Qq(Y.parameters??"");if(Y.name.toLowerCase()==="rtx"&&G.apt===this.codec?.payloadType)this.rtxPayloadType=Y.payloadType;if(Y.name.toLowerCase()==="red")this.redRedundantPayloadType=Number((Y.parameters??"").split("/")[0])})}registerTrack(W){if(W.stopped)throw Error("track is ended");if(this.disposeTrack)this.disposeTrack();W.id=this.trackId;let{unSubscribe:Y}=W.onReceiveRtp.subscribe(async(G)=>{await this.sendRtp(G)});if(this.track=W,this.disposeTrack=Y,this.codec)W.codec=this.codec;W.onSourceChanged.subscribe((G)=>{this.replaceRTP(G)})}async replaceTrack(W){if(W===null)return;if(W.stopped)throw Error("track is ended");if(this.sequenceNumber!=null){let Y=W.header||(await W.onReceiveRtp.asPromise())[0].header;this.replaceRTP(Y)}this.registerTrack(W),DO("replaceTrack","ssrc",W.ssrc,"rid",W.rid)}stop(){if(this.stopped=!0,this.rtcpRunning=!1,this.rtcpCancel.abort(),this.disposeTrack)this.disposeTrack();this.track=void 0}async runRtcp(){if(this.rtcpRunning||this.stopped)return;this.rtcpRunning=!0;try{while(this.rtcpRunning){await HS(500+Math.random()*1000,void 0,{signal:this.rtcpCancel.signal});let W=[new bX({ssrc:this.ssrc,senderInfo:new G2({ntpTimestamp:this.ntpTimestamp,rtpTimestamp:this.rtpTimestamp,packetCount:this.packetCount,octetCount:this.octetCount})})];if(this.lastSRtimestamp=d2(this.ntpTimestamp),this.lastSentSRTimestamp=Vq(),this.cname)W.push(new Zq({chunks:[new W2({source:this.ssrc,items:[new Y2({type:1,text:this.cname})]})]}));try{await this.dtlsTransport.sendRtcp(W)}catch(Y){DO("sendRtcp failed",Y),await HS(500+Math.random()*1000)}}}catch(W){}}replaceRTP({sequenceNumber:W,timestamp:Y},G=!1){if(this.sequenceNumber!=null){if(this.seqOffset=T9(this.sequenceNumber,-W),G)this.seqOffset=T9(this.seqOffset,2)}if(this.timestamp!=null){if(this.timestampOffset=vX(this.timestamp,-Y),G)this.timestampOffset=T9(this.timestampOffset,1)}this.rtpCache=[],DO("replaceRTP",this.sequenceNumber,W,this.seqOffset)}async sendRtp(W){if(this.dtlsTransport.state!=="connected"||!this.codec)return;W=Buffer.isBuffer(W)?t6.deSerialize(W):W;let{header:Y,payload:G}=W;Y.ssrc=this.ssrc,Y.payloadType=this.codec.payloadType,Y.timestamp=vX(Y.timestamp,this.timestampOffset),Y.sequenceNumber=T9(Y.sequenceNumber,this.seqOffset),this.timestamp=Y.timestamp,this.sequenceNumber=Y.sequenceNumber;let X=yi(),J=[...Y.extensions];Y.extensions=this.headerExtensions.map((H)=>{let N=(()=>{switch(H.uri){case C9.sdesMid:if(this.mid)return ho(this.mid);return;case C9.sdesRTPStreamID:if(this.rtpStreamId)return bo(this.rtpStreamId);return;case C9.repairedRtpStreamId:if(this.repairedRtpStreamId)return mo(this.repairedRtpStreamId);return;case C9.transportWideCC:return this.dtlsTransport.transportSequenceNumber=T9(this.dtlsTransport.transportSequenceNumber,1),fo(this.dtlsTransport.transportSequenceNumber);case C9.absSendTime:return co(X)}})();if(N)return{id:H.id,payload:N}}).filter((H)=>H);for(let H of J){let N=Y.extensions.find((A)=>A.id===H.id);if(N)N.payload=H.payload;else Y.extensions.push(H)}Y.extensions=Y.extensions.sort((H,N)=>H.id-N.id),this.ntpTimestamp=X,this.rtpTimestamp=Y.timestamp,this.octetCount+=G.length,this.packetCount=vX(this.packetCount,1),this.rtpCache[Y.sequenceNumber%NS]=W;let Z=G;if(this.redRedundantPayloadType)this.redEncoder.push({block:Z,timestamp:Y.timestamp,blockPT:this.redRedundantPayloadType}),Z=this.redEncoder.build().serialize();let V=await this.dtlsTransport.sendRtp(Z,Y);this.runRtcp();let U=l2(),Q={wideSeq:this.dtlsTransport.transportSequenceNumber,size:V,sendingAtMs:U,sentAtMs:U};this.senderBWE.rtpPacketSent(Q)}handleRtcpPacket(W){switch(W.type){case bX.type:case rV.type:W.reports.filter((G)=>G.ssrc===this.ssrc).forEach((G)=>{if(this.lastSRtimestamp===G.lsr&&G.dlsr){if(this.lastSentSRTimestamp){let X=Vq()-this.lastSentSRTimestamp-G.dlsr/65536;if(this.rtt===void 0)this.rtt=X;else this.rtt=qS*this.rtt+(1-qS)*X}}});break;case hX.type:{let Y=W;switch(Y.feedback.count){case Jq.count:{let G=Y.feedback;this.senderBWE.receiveTWCC(G)}break;case Xq.count:{let G=Y.feedback;G.lost.forEach(async(X)=>{let J=this.rtpCache[X%NS];if(J&&J.header.sequenceNumber!==X)J=void 0;if(J){if(this.rtxPayloadType!=null)J=Wn(J,this.rtxPayloadType,this.rtxSequenceNumber,this.rtxSsrc),this.rtxSequenceNumber=T9(this.rtxSequenceNumber,1);await this.dtlsTransport.sendRtp(J.payload,J.header)}}),this.onGenericNack.execute(G)}break}}break;case iV.type:{let Y=W;switch(Y.feedback.count){case Gq.count:{let G=Y.feedback;this.receiverEstimatedMaxBitrate=G.bitrate}break;case Yq.count:this.onPictureLossIndication.execute();break}}break}this.onRtcp.execute(W)}getParameters(){return{encodings:[]}}setParameters(W){}async getStats(){let W=$Y(),Y=[];if(!this.dtlsTransport)return Y;let G=Z8("transport",this.dtlsTransport.id),X={type:"outbound-rtp",id:Z8("outbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:this.codec?Z8("codec",this.codec.payloadType,G):void 0,mid:this.mid,packetsSent:this.packetCount,bytesSent:this.octetCount,rtxSsrc:this.rtxPayloadType?this.rtxSsrc:void 0};if(Y.push(X),this.track){let J={type:"media-source",id:Z8("media-source",this.trackId),timestamp:W,trackIdentifier:this.trackId,kind:this.kind};Y.push(J)}if(this.rtt!==void 0){let J={type:"remote-inbound-rtp",id:Z8("remote-inbound-rtp",this.ssrc),timestamp:W,ssrc:this.ssrc,kind:this.kind,transportId:G,codecId:X.codecId,localId:X.id,roundTripTime:this.rtt};Y.push(J)}return Y}},kr=M1("werift:packages/webrtc/src/transport/sctpManager.ts"),_r=class{sctpTransport;sctpRemotePort;dataChannelsOpened=0;dataChannelsClosed=0;dataChannels=[];onDataChannel=new p0;constructor(){}createSctpTransport(W){let Y=new Rr(5000,W);return Y.mid=void 0,Y.onDataChannel.subscribe((G)=>{this.dataChannelsOpened++,this.dataChannels.push(G),this.onDataChannel.execute(G)}),this.sctpTransport=Y,Y}createDataChannel(W,Y={}){let X={...{protocol:"",ordered:!0,negotiated:!1},...Y};if(X.maxPacketLifeTime&&X.maxRetransmits)throw Error("can not select both");if(!this.sctpTransport)this.sctpTransport=this.createSctpTransport();let J=new S2({id:X.id,label:W,maxPacketLifeTime:X.maxPacketLifeTime,maxRetransmits:X.maxRetransmits,negotiated:X.negotiated,ordered:X.ordered,protocol:X.protocol}),Z=new F2(this.sctpTransport,J);return this.dataChannelsOpened++,this.dataChannels.push(Z),Z.stateChange.subscribe((V)=>{if(V==="closed"){this.dataChannelsClosed++;let U=this.dataChannels.indexOf(Z);if(U!==-1)this.dataChannels.splice(U,1)}}),Z}async connectSctp(){if(!this.sctpTransport||!this.sctpRemotePort)return;await this.sctpTransport.start(this.sctpRemotePort),await this.sctpTransport.sctp.stateChanged.connected.asPromise(),kr("sctp connected")}setRemoteSCTP(W,Y){if(!this.sctpTransport)return;if(this.sctpTransport.setRemoteMaxMessageSize(W.sctpCapabilities?.maxMessageSize),this.sctpRemotePort=W.sctpPort,!this.sctpRemotePort)throw Error("sctpRemotePort not exist");if(this.sctpTransport.setRemotePort(this.sctpRemotePort),this.sctpTransport.mLineIndex=Y,!this.sctpTransport.mid)this.sctpTransport.mid=W.rtp.muxId}async close(){if(this.sctpTransport)await this.sctpTransport.stop();this.onDataChannel.allUnsubscribe()}async getStats(){let W=$Y(),Y=[];for(let G of this.dataChannels){let X={type:"data-channel",id:Z8("data-channel",G.id),timestamp:W,label:G.label,protocol:G.protocol,dataChannelIdentifier:G.id,state:G.readyState,messagesSent:G.messagesSent||0,bytesSent:G.bytesSent||0,messagesReceived:G.messagesReceived||0,bytesReceived:G.bytesReceived||0};Y.push(X)}return Y}},yr=class{currentLocalDescription;currentRemoteDescription;pendingLocalDescription;pendingRemoteDescription;cname;midSuffix;bundlePolicy;seenMid=new Set;constructor({cname:W,midSuffix:Y,bundlePolicy:G}){this.cname=W,this.midSuffix=Y??!1,this.bundlePolicy=G}get localDescription(){if(!this._localDescription)return;return this._localDescription.toJSON()}get remoteDescription(){if(!this._remoteDescription)return;return this._remoteDescription.toJSON()}get _localDescription(){return this.pendingLocalDescription||this.currentLocalDescription}get _remoteDescription(){return this.pendingRemoteDescription||this.currentRemoteDescription}get inactiveRemoteMedia(){return this._remoteDescription?.media?.find?.((W)=>W.direction==="inactive")}createMediaDescriptionForTransceiver(W,Y){let G=new aO(W.kind,9,"UDP/TLS/RTP/SAVPF",W.codecs.map((X)=>X.payloadType));if(G.direction=Y,G.msid=W.msid,G.rtp={codecs:W.codecs,headerExtensions:W.headerExtensions,muxId:W.mid},G.rtcpHost="0.0.0.0",G.rtcpPort=9,G.rtcpMux=!0,G.ssrc=[new tO({ssrc:W.sender.ssrc,cname:this.cname})],W.options.simulcast)G.simulcastParameters=W.options.simulcast.map((X)=>new x2(X));if(G.rtp.codecs.find((X)=>X.name.toLowerCase()==="rtx"))G.ssrc.push(new tO({ssrc:W.sender.rtxSsrc,cname:this.cname})),G.ssrcGroup=[new oV("FID",[W.sender.ssrc.toString(),W.sender.rtxSsrc.toString()])];return this.addTransportDescription(G,W.dtlsTransport),G}createMediaDescriptionForSctp(W){let Y=new aO("application",cF,"UDP/DTLS/SCTP",["webrtc-datachannel"]);return Y.sctpPort=W.port,Y.rtp.muxId=W.mid,Y.sctpCapabilities=W.getCapabilities(),this.addTransportDescription(Y,W.dtlsTransport),Y}addTransportDescription(W,Y){let G=Y.iceTransport;if(W.iceCandidates=G.localCandidates,W.iceCandidatesComplete=G.gatheringState==="complete",W.iceParams=G.localParameters,W.iceOptions="trickle",W.host=Ti,W.port=cF,W.direction==="inactive")W.port=0,W.msid=void 0;if(!W.dtlsParams){if(W.dtlsParams=Y.localParameters,!W.dtlsParams.fingerprints)W.dtlsParams.fingerprints=Y.localParameters.fingerprints}}allocateMid(W=""){let Y="";for(let G=0;;)if(Y=(G++).toString()+W,!this.seenMid.has(Y))break;return this.seenMid.add(Y),Y}parseSdp({sdp:W,isLocal:Y,signalingState:G,type:X}){let J=oN.parse(W);return this.validateDescription({description:J,isLocal:Y,signalingState:G}),J.type=X,J}validateDescription({description:W,isLocal:Y,signalingState:G}){if(Y){if(W.type==="offer"){if(!["stable","have-local-offer"].includes(G))throw Error("Cannot handle offer in signaling state")}else if(W.type==="answer"){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("Cannot handle answer in signaling state")}}else if(W.type==="offer"){if(!["stable","have-remote-offer"].includes(G))throw Error("Cannot handle offer in signaling state")}else if(W.type==="answer"){if(!["have-local-offer","have-remote-pranswer"].includes(G))throw Error("Cannot handle answer in signaling state")}}buildOfferSdp(W,Y){let G=new oN;VS("offer",G),(this.currentLocalDescription?.media??[]).forEach((J,Z)=>{let V=J.rtp.muxId;if(!V)return;if(J.kind==="application"){if(!Y)throw Error("sctpTransport not found");Y.mLineIndex=Z,G.media.push(this.createMediaDescriptionForSctp(Y))}else{let U=W.find((Q)=>Q.mid===V);if(!U){if(J.direction==="inactive"){G.media.push(J);return}throw Error("transceiver not found")}U.mLineIndex=Z,G.media.push(this.createMediaDescriptionForTransceiver(U,U.direction))}});for(let J of W.filter((Z)=>!G.media.find((V)=>V.rtp.muxId===Z.mid))){if(J.mid==null)J.mid=this.allocateMid(this.midSuffix?"av":"");let Z=this.createMediaDescriptionForTransceiver(J,J.direction);if(J.mLineIndex===void 0)J.mLineIndex=G.media.length,G.media.push(Z);else G.media[J.mLineIndex]=Z}if(Y&&!G.media.find((J)=>J.kind==="application")){if(Y.mLineIndex=G.media.length,Y.mid==null)Y.mid=this.allocateMid(this.midSuffix?"dc":"");G.media.push(this.createMediaDescriptionForSctp(Y))}if(this.bundlePolicy!=="disable"){let J=G.media.map((Z)=>Z.rtp.muxId).filter((Z)=>Z);if(J.length){let Z=new oV("BUNDLE",J);G.group.push(Z)}}return G}buildAnswerSdp({transceivers:W,sctpTransport:Y,signalingState:G}){if(!["have-remote-offer","have-local-pranswer"].includes(G))throw Error("createAnswer failed");if(!this._remoteDescription)throw Error("wrong state");let X=new oN;VS("answer",X);for(let J of this._remoteDescription.media){let Z,V;if(["audio","video"].includes(J.kind)){let U=W.find((Q)=>Q.mid===J.rtp.muxId);if(!U)throw Error(`Transceiver with mid=${J.rtp.muxId} not found`);V=this.createMediaDescriptionForTransceiver(U,p2(U.direction,U.offerDirection)),Z=U.dtlsTransport}else if(J.kind==="application"){if(!Y||!Y.mid)throw Error("sctpTransport not found");V=this.createMediaDescriptionForSctp(Y),Z=Y.dtlsTransport}else throw Error("invalid kind");if(V.dtlsParams)if(Z.role==="auto")V.dtlsParams.role="client";else V.dtlsParams.role=Z.role;if(J.simulcastParameters&&J.simulcastParameters.length>0)V.simulcastParameters=J.simulcastParameters.map((U)=>({...U,direction:U.direction==="send"?"recv":"send"}));X.media.push(V)}if(this.bundlePolicy!=="disable"){let J=new oV("BUNDLE",[]);for(let Z of X.media)if(Z.rtp.muxId)J.items.push(Z.rtp.muxId);X.group.push(J)}return X}setLocalDescription(W){if(this.currentLocalDescription=W,W.type==="answer")this.pendingLocalDescription=void 0;else this.pendingLocalDescription=W}setRemoteDescription(W,Y){if(!W.sdp||!W.type||W.type==="rollback"||W.type==="pranswer")throw Error("invalid sessionDescription");let G=this.parseSdp({sdp:W.sdp,isLocal:!1,signalingState:Y,type:W.type});if(G.type==="answer")this.currentRemoteDescription=G,this.pendingRemoteDescription=void 0;else this.pendingRemoteDescription=G;return G}registerMid(W){this.seenMid.add(W)}get remoteIsBundled(){let W=this._remoteDescription;if(!W)return;return W.group.find((G)=>G.semantic==="BUNDLE"&&this.bundlePolicy!=="disable")}setLocal(W,Y,G){let X=new Map(Y.map((V)=>[V?.mLineIndex,V])),J=Y.find((V)=>V?.dtlsTransport)?.dtlsTransport??G?.dtlsTransport;W.media.filter((V)=>["audio","video"].includes(V.kind)).forEach((V,U)=>{let H=(X.get(U)??Y[U])?.dtlsTransport??J;if(!H)throw Error(`dtls transport not found for media index ${U}`);this.addTransportDescription(V,H)});let Z=W.media.find((V)=>V.kind==="application");if(G&&Z)this.addTransportDescription(Z,G.dtlsTransport);this.setLocalDescription(W)}},bV=M1("werift:packages/webrtc/src/transport/secureTransportManager.ts"),vr=class{connectionState="new";iceConnectionState="new";iceGatheringState="new";certificate;iceGatheringStateChange=new p0;iceConnectionStateChange=new p0;onIceCandidate=new p0;connectionStateChange=new p0;config;transceiverManager;sctpManager;constructor({config:W,transceiverManager:Y,sctpManager:G}){if(this.config=W,this.transceiverManager=Y,this.sctpManager=G,this.config.dtls){let{keys:X}=this.config.dtls;if(X)this.setupCertificate(X)}}get dtlsTransports(){return[...this.transceiverManager.getTransceivers().map((Y)=>Y?.dtlsTransport),this.sctpManager.sctpTransport?.dtlsTransport].filter((Y)=>Y!=null).reduce((Y,G)=>{if(!Y.map((X)=>X.id).includes(G.id))Y.push(G);return Y},[])}get iceTransports(){return this.dtlsTransports.map((W)=>W.iceTransport)}setupCertificate(W){this.certificate=new o2(W.keyPem,W.certPem,W.signatureHash)}createTransport(){let W=this.iceTransports.find((J)=>J.state!=="closed"),Y=new ei({...vi(this.config.iceServers),forceTurn:this.config.iceTransportPolicy==="relay",portRange:this.config.icePortRange,interfaceAddresses:this.config.iceInterfaceAddresses,additionalHostAddresses:this.config.iceAdditionalHostAddresses,filterStunResponse:this.config.iceFilterStunResponse,filterCandidatePair:this.config.iceFilterCandidatePair,localPasswordPrefix:this.config.icePasswordPrefix,useIpv4:this.config.iceUseIpv4,useIpv6:this.config.iceUseIpv6,turnTransport:this.config.forceTurnTCP===!0?"tcp":"udp",useLinkLocalAddress:this.config.iceUseLinkLocalAddress});if(W)Y.connection.localUsername=W.connection.localUsername,Y.connection.localPassword=W.connection.localPassword;Y.onGatheringStateChange.subscribe(()=>{this.updateIceGatheringState()}),this.updateIceGatheringState();let G=new ti(Y);return G.onStateChange.subscribe(()=>{this.updateIceConnectionState()}),new oF(this.config,G,this.certificate,gr)}handleNewIceCandidate({candidate:W,media:Y,remoteIsBundled:G,transceiver:X,sctpTransport:J,bundlePolicy:Z}){if(Z==="max-bundle"||G){if(W.sdpMLineIndex=0,Y)W.sdpMid=Y.rtp.muxId}else{if(X)W.sdpMLineIndex=X.mLineIndex,W.sdpMid=X.mid;if(J)W.sdpMLineIndex=J.mLineIndex,W.sdpMid=J.mid}if(W.foundation&&!W.foundation.startsWith("candidate:"))W.foundation="candidate:"+W.foundation;return this.onIceCandidate.execute(W),W}async addIceCandidate(W,Y){let G=n2.fromJSON(Y);if(!G)return;let X;if(typeof G.sdpMid==="number")X=this.getTransportByMid(G.sdpMid);if(!X&&typeof G.sdpMLineIndex==="number")X=this.getTransportByMLineIndex(W,G.sdpMLineIndex);if(!X)X=this.iceTransports[0];if(X)await X.addRemoteCandidate(G);else bV("iceTransport not found for candidate",G)}getTransportByMid(W){let Y,G=this.transceiverManager.getTransceivers().find((X)=>X.mid===W);if(G)Y=G.dtlsTransport.iceTransport;else if(!Y&&this.sctpManager.sctpTransport?.mid===W)Y=this.sctpManager.sctpTransport.dtlsTransport.iceTransport;return Y}getTransportByMLineIndex(W,Y){let G=W.media[Y];if(!G)return;return this.getTransportByMid(G.rtp.muxId)}restartIce(){for(let W of this.iceTransports)W.restart()}setLocalRole({type:W,role:Y}){for(let G of this.dtlsTransports){let X=G.iceTransport;if(W==="offer")X.connection.iceControlling=!0;else X.connection.iceControlling=!1;if(X.connection.remoteIsLite)X.connection.iceControlling=!0;if(W==="answer"){if(Y)G.role=Y}}}updateIceGatheringState(){let W=this.iceTransports;function Y(...X){return W.filter((J)=>X.includes(J.gatheringState)).length===W.length}let G;if(W.length&&Y("complete"))G="complete";else if(!W.length||Y("new","complete"))G="new";else if(W.map((X)=>X.gatheringState).includes("gathering"))G="gathering";else G="new";if(this.iceGatheringState===G)return;this.iceGatheringState=G,this.iceGatheringStateChange.execute(G)}updateIceConnectionState(){let W=this.iceTransports,Y;function G(...J){return W.filter((Z)=>J.includes(Z.state)).length===W.length}function X(...J){return W.some((Z)=>J.includes(Z.state))}if(this.connectionState==="closed")Y="closed";else if(X("failed"))Y="failed";else if(X("disconnected"))Y="disconnected";else if(G("new","closed"))Y="new";else if(X("new","checking"))Y="checking";else if(G("completed","closed"))Y="completed";else if(G("connected","completed","closed"))Y="connected";else Y="new";if(this.iceConnectionState===Y)return;bV("iceConnectionStateChange",Y),this.iceConnectionState=Y,this.iceConnectionStateChange.execute(Y)}async gatherCandidates(W){let Y=this.iceTransports.find((G)=>G.state==="connected"||G.state==="completed");if(W&&Y)bV("skipping ICE gathering for bundled connection");else await Promise.allSettled(this.iceTransports.map((G)=>G.gather())).catch((G)=>{bV("gatherCandidates failed",G)})}setConnectionState(W){bV("connectionStateChange",W),this.connectionState=W,this.connectionStateChange.execute(W)}async getStats(){let W=[];for(let Y of this.dtlsTransports){let G=await Y.getStats();if(G)W.push(...G)}return W}async ensureCerts(){if(!this.certificate)this.certificate=await oF.SetupCertificate();for(let W of this.dtlsTransports)W.localCertificate=this.certificate}async close(){this.setConnectionState("closed"),await Promise.allSettled([...this.dtlsTransports.map((W)=>W.stop())]),this.iceGatheringStateChange.allUnsubscribe(),this.iceConnectionStateChange.allUnsubscribe(),this.onIceCandidate.allUnsubscribe(),this.connectionStateChange.allUnsubscribe()}},gr=[lF.SRTP_AEAD_AES_128_GCM,lF.SRTP_AES128_CM_HMAC_SHA1_80],W7=M1("werift:packages/webrtc/src/peerConnection.ts"),Ux=class extends QK{cname=xr().toString();config=Qx();signalingState="stable";negotiationneeded=!1;needRestart=!1;router=new Br;sdpManager;transceiverManager;sctpManager;secureManager;isClosed=!1;shouldNegotiationneeded=!1;remoteBundleNegotiated=!1;iceGatheringStateChange=new p0;iceConnectionStateChange=new p0;signalingStateChange=new p0;connectionStateChange=new p0;onDataChannel=new p0;onRemoteTransceiverAdded=new p0;onTransceiverAdded=new p0;onIceCandidate=new p0;onNegotiationneeded=new p0;onTrack=new p0;ondatachannel;onicecandidate;onicecandidateerror;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;onconnectionstatechange;oniceconnectionstatechange;constructor(W={}){super();this.setConfiguration(W),this.sdpManager=new yr({cname:this.cname,bundlePolicy:this.config.bundlePolicy}),this.transceiverManager=new hr(this.cname,this.config,this.router),this.transceiverManager.onTransceiverAdded.pipe(this.onTransceiverAdded),this.transceiverManager.onRemoteTransceiverAdded.pipe(this.onRemoteTransceiverAdded),this.transceiverManager.onTrack.subscribe(({track:Y,stream:G,transceiver:X})=>{let J={track:Y,streams:[G],transceiver:X,receiver:X.receiver};if(this.onTrack.execute(Y),this.emit("track",J),this.ontrack)this.ontrack(J)}),this.transceiverManager.onNegotiationNeeded.subscribe(()=>this.needNegotiation()),this.sctpManager=new _r,this.sctpManager.onDataChannel.subscribe((Y)=>{this.onDataChannel.execute(Y);let G={channel:Y};this.ondatachannel?.(G),this.emit("datachannel",G)}),this.secureManager=new vr({config:this.config,sctpManager:this.sctpManager,transceiverManager:this.transceiverManager}),this.secureManager.iceGatheringStateChange.pipe(this.iceGatheringStateChange),this.secureManager.iceConnectionStateChange.subscribe((Y)=>{if(Y==="closed")this.close();this.iceConnectionStateChange.execute(Y)}),this.secureManager.connectionStateChange.subscribe((Y)=>{this.connectionStateChange.execute(Y),this.onconnectionstatechange?.(),this.emit("connectionstatechange")}),this.secureManager.onIceCandidate.subscribe((Y)=>{let G=Y?Y.toJSON():void 0;this.onIceCandidate.execute(G),this.onicecandidate?.({candidate:G}),this.emit("icecandidate",{candidate:G})})}get connectionState(){return this.secureManager.connectionState}get iceConnectionState(){return this.secureManager.iceConnectionState}get iceGathererState(){return this.secureManager.iceGatheringState}get iceGatheringState(){return this.secureManager.iceGatheringState}get dtlsTransports(){return this.secureManager.dtlsTransports}get sctpTransport(){return this.sctpManager.sctpTransport}get sctpRemotePort(){return this.sctpManager.sctpRemotePort}get iceTransports(){return this.secureManager.iceTransports}get extIdUriMap(){return this.router.extIdUriMap}get iceGeneration(){return this.iceTransports[0].connection.generation}get localDescription(){return this.sdpManager.localDescription}get remoteDescription(){return this.sdpManager.remoteDescription}get remoteIsBundled(){return this.sdpManager.remoteIsBundled}get _localDescription(){return this.sdpManager._localDescription}get _remoteDescription(){return this.sdpManager._remoteDescription}getTransceivers(){return this.transceiverManager.getTransceivers()}getSenders(){return this.transceiverManager.getSenders()}getReceivers(){return this.transceiverManager.getReceivers()}setConfiguration(W){if(gi(this.config,W),this.config.icePortRange){let[Y,G]=this.config.icePortRange;if(Y===G)throw Error("should not be same value");if(Y>=G)throw Error("The min must be less than max")}if(!Number.isInteger(this.config.maxMessageSize)||this.config.maxMessageSize<0)throw Error("maxMessageSize must be a non-negative integer");if(this.sctpManager?.sctpTransport)this.sctpManager.sctpTransport.maxMessageSize=this.config.maxMessageSize;for(let[Y,G]of uF([...this.config.codecs.audio||[],...this.config.codecs.video||[]])){if(G.payloadType!=null)continue;switch(G.payloadType=96+Y,G.name.toLowerCase()){case"rtx":G.parameters=`apt=${G.payloadType-1}`;break;case"red":if(G.contentType==="audio"){let X=G.payloadType+1;G.parameters=`${X}/${X}`,G.payloadType=63}break}}[...this.config.headerExtensions.audio||[],...this.config.headerExtensions.video||[]].forEach((Y,G)=>{Y.id=1+G})}getConfiguration(){return this.config}async createOffer({iceRestart:W}={}){if(W||this.needRestart)this.needRestart=!1,this.secureManager.restartIce();await this.secureManager.ensureCerts();for(let G of this.transceiverManager.getTransceivers()){if(G.codecs.length===0)this.transceiverManager.assignTransceiverCodecs(G);if(G.headerExtensions.length===0)G.headerExtensions=this.config.headerExtensions[G.kind]??[]}return this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport).toJSON()}createSctpTransport(){let W=this.sctpManager.createSctpTransport(this.config.maxMessageSize),Y=this.findOrCreateTransport();return W.setDtlsTransport(Y),W}createDataChannel(W,Y={}){if(!this.sctpTransport)this.createSctpTransport(),this.needNegotiation();let G=this.sctpManager.createDataChannel(W,Y);if(!G.sctp.dtlsTransport){let X=this.findOrCreateTransport();G.sctp.setDtlsTransport(X)}return G}removeTrack(W){if(this.isClosed)throw Error("peer closed");this.transceiverManager.removeTrack(W),this.needNegotiation()}needNegotiation=async()=>{if(this.shouldNegotiationneeded=!0,this.negotiationneeded||this.signalingState!=="stable")return;this.shouldNegotiationneeded=!1,setImmediate(()=>{if(this.negotiationneeded=!0,this.onNegotiationneeded.execute(),this.onnegotiationneeded)this.onnegotiationneeded({})})};findOrCreateTransport(){let W=this.dtlsTransports.find((J)=>J.state!=="closed"),Y=W?.iceTransport;if(this.sdpManager.bundlePolicy==="max-bundle"||this.sdpManager.bundlePolicy!=="disable"&&(this.remoteIsBundled||this.remoteBundleNegotiated)){if(W)return W}let G=this.secureManager.createTransport();G.onRtp.subscribe((J)=>{this.router.routeRtp(J)}),G.onRtcp.subscribe((J)=>{this.router.routeRtcp(J)});let X=G.iceTransport;return X.onNegotiationNeeded.subscribe(()=>{this.needNegotiation()}),X.onIceCandidate.subscribe((J)=>{if(!this.localDescription){W7("localDescription not found when ice candidate was gathered");return}if(!J){if(this.sdpManager.setLocal(this._localDescription,this.transceiverManager.getTransceivers(),this.sctpTransport),this.onIceCandidate.execute(void 0),this.onicecandidate)this.onicecandidate({candidate:void 0});this.emit("icecandidate",{candidate:void 0});return}if(!this._localDescription){W7("localDescription not found when ice candidate was gathered");return}this.secureManager.handleNewIceCandidate({candidate:J,bundlePolicy:this.sdpManager.bundlePolicy,remoteIsBundled:!!this.sdpManager.remoteIsBundled,media:this._localDescription.media[0],transceiver:this.transceiverManager.getTransceivers().find((Z)=>Z?.dtlsTransport?.iceTransport.id===X.id),sctpTransport:this.sctpTransport?.dtlsTransport.iceTransport.id===X.id?this.sctpTransport:void 0})}),G}async setLocalDescription(W){W=W??(["stable","have-local-offer","have-remote-pranswer"].includes(this.signalingState)?await this.createOffer():await this.createAnswer());let G=this.sdpManager.parseSdp({sdp:W.sdp,isLocal:!0,signalingState:this.signalingState,type:W.type});if(G.type==="offer")this.setSignalingState("have-local-offer");else if(G.type==="answer")this.setSignalingState("stable");for(let[J,Z]of uF(G.media)){let V=Z.rtp.muxId;if(this.sdpManager.registerMid(V),["audio","video"].includes(Z.kind)){let U=this.transceiverManager.getTransceiverByMLineIndex(J);if(U)U.mid=V}if(Z.kind==="application"&&this.sctpTransport)this.sctpTransport.mid=V}let X=G.media.find((J)=>J.dtlsParams)?.dtlsParams?.role;if(this.secureManager.setLocalRole({type:G.type,role:X}),["answer","pranswer"].includes(G.type))for(let J of this.transceiverManager.getTransceivers()){let Z=p2(J.direction,J.offerDirection);J.setCurrentDirection(Z)}if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),await this.gatherCandidates().catch((J)=>{W7("gatherCandidates failed",J)}),G.type==="answer")this.connect().catch((J)=>{W7("connect failed",J),this.secureManager.setConnectionState("failed")});if(this.sdpManager.setLocal(G,this.transceiverManager.getTransceivers(),this.sctpTransport),this.shouldNegotiationneeded)this.needNegotiation();return G}async gatherCandidates(){await this.secureManager.gatherCandidates(!!this.sdpManager.remoteIsBundled)}async addIceCandidate(W){let Y=this.sdpManager.buildOfferSdp(this.transceiverManager.getTransceivers(),this.sctpTransport);await this.secureManager.addIceCandidate(Y,W)}async connect(){if(W7("start connect"),(await Promise.allSettled(this.dtlsTransports.map(async(Y)=>{let{iceTransport:G}=Y;if(G.state==="connected")return;let X=()=>Y.state==="connected";if(X())return;if(this.secureManager.setConnectionState("connecting"),await G.start().catch((J)=>{throw W7("iceTransport.start failed",J),J}),X())return;if(await Y.start().catch((J)=>{throw W7("dtlsTransport.start failed",J),J}),this.sctpTransport&&this.sctpTransport.dtlsTransport.id===Y.id)await this.sctpManager.connectSctp()}))).find((Y)=>Y.status==="rejected"))this.secureManager.setConnectionState("failed");else this.secureManager.setConnectionState("connected")}restartIce(){this.needRestart=!0,this.needNegotiation()}async setRemoteDescription(W){if(W instanceof oN)W=W.toSdp();let Y=this.sdpManager.setRemoteDescription(W,this.signalingState);if(Y.group.some((V)=>V.semantic==="BUNDLE"&&V.items.length>0))this.remoteBundleNegotiated=!0;let G,X=(V,U)=>V.kind===U.kind&&[void 0,U.rtp.muxId].includes(V.mid),J=Y.media.map((V,U)=>{let Q;if(["audio","video"].includes(V.kind)){let N=this.transceiverManager.getTransceivers().find((A)=>X(A,V));if(!N)N=this.addTransceiver(V.kind,{direction:"recvonly"}),N.mid=V.rtp.muxId,this.onRemoteTransceiverAdded.execute(N);else if(N.direction==="inactive"&&N.stopping){if(N.stopped=!0,W.type==="answer")N.setCurrentDirection("inactive");return}if(this.sdpManager.remoteIsBundled)if(!G)G=N.dtlsTransport;else N.setDtlsTransport(G);Q=N.dtlsTransport,this.transceiverManager.setRemoteRTP(N,V,Y.type,U)}else if(V.kind==="application"){let N=this.sctpTransport;if(!N)N=this.createSctpTransport(),N.mid=V.rtp.muxId;if(this.sdpManager.remoteIsBundled)if(!G)G=N.dtlsTransport;else N.setDtlsTransport(G);Q=N.dtlsTransport,this.sctpManager.setRemoteSCTP(V,U)}else throw Error("invalid media kind");let H=Q.iceTransport;if(V.iceParams){let N=!!this.sdpManager.inactiveRemoteMedia;if(H.setRemoteParams(V.iceParams,N),V.iceParams?.iceLite)H.connection.iceControlling=!0}if(V.dtlsParams)Q.setRemoteParams(V.dtlsParams);if(V.iceCandidates.forEach(H.addRemoteCandidate),V.iceCandidatesComplete)H.addRemoteCandidate(void 0);if(Y.type==="answer"&&V.dtlsParams?.role)Q.role=V.dtlsParams.role==="client"?"server":"client";return H});J=J.filter((V)=>!!V);let Z=this.transceiverManager.getTransceivers().filter((V)=>Y.media.find((U)=>X(V,U))==null);if(W.type==="answer")for(let V of Z)V.stop(),V.stopped=!0;if(Y.type==="offer")this.setSignalingState("have-remote-offer");else if(Y.type==="answer")this.setSignalingState("stable");if(Y.type==="answer")W7("caller start connect"),this.connect().catch((V)=>{W7("connect failed",V),this.secureManager.setConnectionState("failed")});if(this.negotiationneeded=!1,this.shouldNegotiationneeded)this.needNegotiation()}addTransceiver(W,Y={}){let G=this.findOrCreateTransport(),X=this.transceiverManager.addTransceiver(W,G,Y);return this.secureManager.updateIceConnectionState(),this.needNegotiation(),X}addTrack(W,Y){if(this.isClosed)throw Error("is closed");let G=this.transceiverManager.addTrack(W,Y);if(!G.dtlsTransport){let X=this.findOrCreateTransport();G.setDtlsTransport(X)}return this.needNegotiation(),G.sender}async createAnswer(){return this.assertNotClosed(),await this.secureManager.ensureCerts(),this.sdpManager.buildAnswerSdp({transceivers:this.transceiverManager.getTransceivers(),sctpTransport:this.sctpTransport,signalingState:this.signalingState}).toJSON()}assertNotClosed(){if(this.isClosed)throw Error("RTCPeerConnection is closed")}setSignalingState(W){if(W7("signalingStateChange",W),this.signalingState=W,this.signalingStateChange.execute(W),this.onsignalingstatechange)this.onsignalingstatechange({})}createPeerConnectionStats(){let W=$Y();return{type:"peer-connection",id:Z8("peer-connection"),timestamp:W,dataChannelsOpened:this.sctpManager.dataChannelsOpened,dataChannelsClosed:this.sctpManager.dataChannelsClosed}}async getStats(W){let Y=[];Y.push(this.createPeerConnectionStats());let G=await this.transceiverManager.getStats(W);Y.push(...G);let X=await this.secureManager.getStats();if(Y.push(...X),this.sctpTransport){let J=await this.sctpManager.getStats();if(J)Y.push(...J)}return new Pi(Y)}async close(){if(this.isClosed)return;this.isClosed=!0,this.setSignalingState("closed"),this.transceiverManager.close(),await this.secureManager.close(),await this.sctpManager.close(),this.onDataChannel.allUnsubscribe(),this.iceGatheringStateChange.allUnsubscribe(),this.iceConnectionStateChange.allUnsubscribe(),this.signalingStateChange.allUnsubscribe(),this.onTransceiverAdded.allUnsubscribe(),this.onRemoteTransceiverAdded.allUnsubscribe(),this.onIceCandidate.allUnsubscribe(),W7("peerConnection closed")}},AS=(W,Y)=>W.find((G)=>G.mimeType.toLowerCase()===Y.mimeType.toLowerCase())?Y:void 0;function Qx(){return{codecs:{audio:[_2(),y2()],video:[k2()]},headerExtensions:{audio:[],video:[]},iceTransportPolicy:"all",iceServers:[{urls:"stun:stun.l.google.com:19302"}],icePortRange:void 0,iceInterfaceAddresses:void 0,iceAdditionalHostAddresses:void 0,iceUseIpv4:!0,iceUseIpv6:!0,iceFilterStunResponse:void 0,iceFilterCandidatePair:void 0,icePasswordPrefix:void 0,iceUseLinkLocalAddress:void 0,dtls:{},bundlePolicy:"max-compat",debug:{},midSuffix:!1,forceTurnTCP:!1,maxMessageSize:cV}}var PA0=Qx(),ur=M1("werift:packages/webrtc/src/media/rtpTransceiverManager.ts"),hr=class{constructor(W,Y,G){this.cname=W,this.config=Y,this.router=G}transceivers=[];onTransceiverAdded=new p0;onRemoteTransceiverAdded=new p0;onTrack=new p0;onNegotiationNeeded=new p0;getTransceivers(){return this.transceivers}getSenders(){return this.getTransceivers().map((W)=>W.sender)}getReceivers(){return this.getTransceivers().map((W)=>W.receiver)}getTransceiverByMLineIndex(W){return this.transceivers.find((Y)=>Y.mLineIndex===W)}pushTransceiver(W){this.transceivers.push(W)}replaceTransceiver(W,Y){this.transceivers[Y]=W}addTransceiver(W,Y,G={}){let X=typeof W==="string"?W:W.kind,J=G.direction||"sendrecv",Z=new Sr(W),V=new Vx(this.config,X,Z.ssrc),U=new Li(X,Y,V,Z,J);U.options=G,this.router.registerRtpSender(U.sender);let Q=this.transceivers.findIndex((N)=>N.currentDirection==="inactive"&&!N.usedForSender),H=this.transceivers.find((N)=>N.currentDirection==="inactive"&&!N.usedForSender);if(Q>-1&&H)this.replaceTransceiver(U,Q),U.mLineIndex=H.mLineIndex,U.mid=H.mid,H.setCurrentDirection(void 0);else this.pushTransceiver(U);return this.onTransceiverAdded.execute(U),U}addTrack(W,Y){if(this.getSenders().find((J)=>J.track?.uuid===W.uuid))throw Error("Track already added");let G=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&mN.includes(J.direction)===!0);if(G)return G.sender.registerTrack(W),G;let X=this.transceivers.find((J)=>J.sender.track==null&&J.kind===W.kind&&mN.includes(J.direction)===!1&&!J.usedForSender);if(X){switch(X.sender.registerTrack(W),X.direction){case"recvonly":X.setDirection("sendrecv");break;case"inactive":X.setDirection("sendonly");break}return X}else return this.addTransceiver(W,void 0,{direction:"sendrecv"})}removeTrack(W){if(!this.getSenders().find(({ssrc:G})=>W.ssrc===G))throw Error("Sender does not exist");let Y=this.transceivers.find(({sender:{ssrc:G}})=>W.ssrc===G);if(!Y)throw Error("No matching transceiver found");if(W.stop(),Y.currentDirection==="recvonly"){this.onNegotiationNeeded.execute();return}if(Y.stopping||Y.stopped)Y.setDirection("inactive");else if(Y.direction==="sendrecv")Y.setDirection("recvonly");else if(Y.direction==="sendonly"||Y.direction==="recvonly")Y.setDirection("inactive")}assignTransceiverCodecs(W){let Y=this.config.codecs[W.kind].filter((G)=>{switch(G.direction){case"recvonly":{if(Mi.includes(W.direction))return!0;return!1}case"sendonly":{if(mN.includes(W.direction))return!0;return!1}case"sendrecv":{if([b2,h2,u2].includes(W.direction))return!0;return!1}case"all":return!0;default:return!1}});W.codecs=Y}getLocalRtpParams(W){if(W.mid==null)throw Error("mid not assigned");return{codecs:W.codecs,muxId:W.mid,headerExtensions:W.headerExtensions,rtcp:{cname:this.cname,ssrc:W.sender.ssrc,mux:!0}}}getRemoteRtpParams(W,Y){return{muxId:W.rtp.muxId,rtcp:W.rtp.rtcp,codecs:Y.codecs,headerExtensions:Y.headerExtensions,encodings:Object.values(Y.codecs.reduce((X,J)=>{if(J.name.toLowerCase()==="rtx"){let Z=Qq(J.parameters??""),V=X[Z.apt];if(V&&W.ssrc.length===2)V.rtx=new Ni({ssrc:W.ssrc[1].ssrc});return X}return X[J.payloadType]=new qi({ssrc:W.ssrc[0]?.ssrc,payloadType:J.payloadType}),X},{}))}}setRemoteRTP(W,Y,G,X){if(!W.mid)W.mid=Y.rtp.muxId;if(W.mLineIndex=X,W.codecs=Y.rtp.codecs.filter((U)=>{let Q=this.config.codecs[Y.kind]||[],H=AS(Q,U);if(!H)return!1;if(H?.name.toLowerCase()==="rtx"){let A=Qq(H.parameters??"").apt,q=Y.rtp.codecs.find((z)=>z.payloadType===A);if(!q)return!1;return!!AS(Q,q)}return!0}),ur("negotiated codecs",W.codecs),W.codecs.length===0)throw Error("negotiate codecs failed.");W.headerExtensions=Y.rtp.headerExtensions.filter((U)=>(this.config.headerExtensions[Y.kind]||[]).find((Q)=>Q.uri===U.uri));let J=Y.direction??"inactive",Z=xi(J);if(["answer","pranswer"].includes(G))W.setCurrentDirection(Z);else W.offerDirection=Z;let V=this.getLocalRtpParams(W);if(W.sender.prepareSend(V),["recvonly","sendrecv"].includes(W.direction)){let U=this.getRemoteRtpParams(Y,W);for(let Q of Y.simulcastParameters)this.router.registerRtpReceiverByRid(W,Q,U);W.receiver.prepareReceive(U),this.router.registerRtpReceiverBySsrc(W,U)}if(["sendonly","sendrecv"].includes(J)){if(Y.msid){let[U,Q]=Y.msid.split(" ");W.receiver.remoteStreamId=U,W.receiver.remoteTrackId=Q}this.onTrack.execute({track:W.receiver.track,transceiver:W,stream:new Ei({id:W.receiver.remoteStreamId,tracks:[W.receiver.track]})})}if(Y.ssrc[0]?.ssrc)W.receiver.setupTWCC(Y.ssrc[0].ssrc)}async getStats(W){let Y=[];for(let G of this.transceivers){let X=!W||G.sender.track===W||G.receiver.track===W;if(G.sender){let J=await G.sender.getStats();if(J)for(let Z of J)if(Z.type==="outbound-rtp"||Z.type==="media-source"){if(X)Y.push(Z)}else Y.push(Z)}if(G.receiver){let J=await G.receiver.getStats();if(J)for(let Z of J)if(Z.type==="inbound-rtp"||Z.type==="remote-outbound-rtp"){if(X)Y.push(Z)}else Y.push(Z)}if(X){let J=G.getCodecStats();if(J)Y.push(...J)}}return Y}close(){for(let W of this.transceivers)W.receiver.stop(),W.sender.stop();this.onTransceiverAdded.allUnsubscribe(),this.onRemoteTransceiverAdded.allUnsubscribe(),this.onTrack.allUnsubscribe(),this.onNegotiationNeeded.allUnsubscribe()}};class NK extends Ux{toJSON(){return{}}createDataChannel(...W){let Y=super.createDataChannel(...W);try{Y.toJSON=()=>({})}catch{}return Y}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var lX={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},br={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},mr=BigInt(0),Hx=BigInt(1),qK=BigInt(2);function fr(W){let Y=lX.p,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=Q5(N,G,Y)*N%Y,q=Q5(A,G,Y)*N%Y,z=Q5(q,qK,Y)*H%Y,w=Q5(z,J,Y)*z%Y,D=Q5(w,Z,Y)*w%Y,T=Q5(D,U,Y)*D%Y,x=Q5(T,Q,Y)*T%Y,g=Q5(x,U,Y)*D%Y,f=Q5(g,G,Y)*N%Y,y=Q5(f,V,Y)*w%Y,p=Q5(y,X,Y)*H%Y,b=Q5(p,qK,Y);if(!Oq.eql(Oq.sqr(b),W))throw Error("Cannot find square root");return b}var Oq=B5(lX.p,{sqrt:fr}),Ax=CX({...lX,Fp:Oq,lowS:!0,endo:br},OX),Nx={};function Kq(W,...Y){let G=Nx[W];if(G===void 0){let X=OX(HN(W));G=i9(X,X),Nx[W]=G}return OX(i9(G,...Y))}var IK=(W)=>W.toBytes(!0).slice(1),dX=(()=>Ax.Point)(),zK=(W)=>W%qK===mr;function AK(W){let{Fn:Y,BASE:G}=dX,X=d6(Y,W),J=G.multiply(X);return{scalar:zK(J.y)?X:Y.neg(X),bytes:IK(J)}}function Ix(W){let Y=Oq;if(!Y.isValidNot0(W))throw Error("invalid x: Fail if x \u2265 p");let G=Y.create(W*W),X=Y.create(G*W+BigInt(7)),J=Y.sqrt(X);if(!zK(J))J=Y.neg(J);let Z=dX.fromAffine({x:W,y:J});return Z.assertValidity(),Z}var qU=B4;function zx(...W){return dX.Fn.create(qU(Kq("BIP0340/challenge",...W)))}function qx(W){return AK(W).bytes}function cr(W,Y,G=NY(32)){let{Fn:X}=dX,J=B8("message",W),{bytes:Z,scalar:V}=AK(Y),U=B8("auxRand",G,32),Q=X.toBytes(V^qU(Kq("BIP0340/aux",U))),H=Kq("BIP0340/nonce",Q,Z,J),{bytes:N,scalar:A}=AK(H),q=zx(N,Z,J),z=new Uint8Array(64);if(z.set(N,0),z.set(X.toBytes(X.create(A+q*V)),32),!wx(z,J,Z))throw Error("sign: Invalid signature produced");return z}function wx(W,Y,G){let{Fn:X,BASE:J}=dX,Z=B8("signature",W,64),V=B8("message",Y),U=B8("publicKey",G,32);try{let Q=Ix(qU(U)),H=qU(Z.subarray(0,32));if(!PV(H,Hx,lX.p))return!1;let N=qU(Z.subarray(32,64));if(!PV(N,Hx,lX.n))return!1;let A=zx(X.toBytes(H),IK(Q),V),q=J.multiplyUnsafe(N).add(Q.multiplyUnsafe(X.neg(A))),{x:z,y:w}=q.toAffine();if(q.is0()||!zK(w)||z!==H)return!1;return!0}catch(Q){return!1}}var jx=(()=>{let G=(J=NY(48))=>{return zN(J,lX.n)};Ax.utils.randomSecretKey;function X(J){let Z=G(J);return{secretKey:Z,publicKey:qx(Z)}}return{keygen:X,getPublicKey:qx,sign:cr,verify:wx,Point:dX,utils:{randomSecretKey:G,randomPrivateKey:G,taggedHash:Kq,lift_x:Ix,pointToBytes:IK,numberToBytesBE:jX,bytesToNumberBE:B4,mod:U5},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Ox=(W)=>Uint8Array.from(W.match(/.{2}/g).map((Y)=>parseInt(Y,16))),pr=(W)=>[...W].map((Y)=>Y.toString(16).padStart(2,"0")).join(""),lr=async(W)=>{try{if(typeof W.pubkey!=="string"||typeof W.sig!=="string"||typeof W.id!=="string")return!1;let Y=new TextEncoder().encode(JSON.stringify([0,W.pubkey,W.created_at,W.kind,W.tags,W.content])),G=new Uint8Array(await crypto.subtle.digest("SHA-256",Y));if(pr(G)!==W.id)return!1;return jx.verify(Ox(W.sig),G,Ox(W.pubkey))}catch{return!1}},dr=(W,Y)=>{if(W.kinds&&!W.kinds.includes(Y.kind))return!1;if(W.since&&Y.created_at<W.since-60)return!1;if(W["#x"]){let G=(Y.tags??[]).filter((X)=>X?.[0]==="x").map((X)=>X[1]);if(!W["#x"].some((X)=>G.includes(X)))return!1}return!0};function Kx({port:W=Number(process.env.PORT)||8080}={}){let Y=new Map,G=0,X=0,J=Bun.serve({port:W,fetch(Z,V){if(V.upgrade(Z))return;return Response.json({relay:"GenosSRV embedded relay",protocol:"nostr (ephemeral subset)",connections:Y.size,events:G,dropped:X})},websocket:{open(Z){Y.set(Z,new Map)},close(Z){Y.delete(Z)},async message(Z,V){let U;try{U=JSON.parse(String(V))}catch{return}if(!Array.isArray(U))return;let[Q,H,N]=U;if(Q==="REQ"&&typeof H==="string"&&N&&typeof N==="object"){Y.get(Z)?.set(H,N),Z.send(JSON.stringify(["EOSE",H]));return}if(Q==="CLOSE"&&typeof H==="string"){Y.get(Z)?.delete(H);return}if(Q==="EVENT"&&H&&typeof H==="object"){if(!await lr(H)){X++,Z.send(JSON.stringify(["OK",H.id??"",!1,"invalid: bad signature"]));return}G++,Z.send(JSON.stringify(["OK",H.id,!0,""]));for(let[A,q]of Y)for(let[z,w]of q)if(dr(w,H)){try{A.send(JSON.stringify(["EVENT",z,H]))}catch{}break}}}}});return console.info(`\uD83D\uDCE1 Relay listening on :${J.port} (ephemeral, schnorr-verified)`),{port:J.port,stats:()=>({connections:Y.size,events:G,dropped:X}),stop:()=>J.stop(!0)}}var Dq="6.15.0";function or(W,Y,G){let X=Y.split("|").map((Z)=>Z.trim());for(let Z=0;Z<X.length;Z++)switch(Y){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof W===Y)return}let J=Error(`invalid value for type ${Y}`);throw J.code="INVALID_ARGUMENT",J.argument=`value.${G}`,J.value=W,J}async function o7(W){let Y=Object.keys(W);return(await Promise.all(Y.map((X)=>Promise.resolve(W[X])))).reduce((X,J,Z)=>{return X[Y[Z]]=J,X},{})}function H8(W,Y,G){for(let X in Y){let J=Y[X],Z=G?G[X]:null;if(Z)or(J,Z,X);Object.defineProperty(W,X,{enumerable:!0,value:J,writable:!1})}}function oX(W,Y){if(W==null)return"null";if(Y==null)Y=new Set;if(typeof W==="object"){if(Y.has(W))return"[Circular]";Y.add(W)}if(Array.isArray(W))return"[ "+W.map((G)=>oX(G,Y)).join(", ")+" ]";if(W instanceof Uint8Array){let X="0x";for(let J=0;J<W.length;J++)X+="0123456789abcdef"[W[J]>>4],X+="0123456789abcdef"[W[J]&15];return X}if(typeof W==="object"&&typeof W.toJSON==="function")return oX(W.toJSON(),Y);switch(typeof W){case"boolean":case"number":case"symbol":return W.toString();case"bigint":return BigInt(W).toString();case"string":return JSON.stringify(W);case"object":{let G=Object.keys(W);return G.sort(),"{ "+G.map((X)=>`${oX(X,Y)}: ${oX(W[X],Y)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function Cq(W,Y){return W&&W.code===Y}function AU(W,Y,G){let X=W;{let Z=[];if(G){if("message"in G||"code"in G||"name"in G)throw Error(`value will overwrite populated values: ${oX(G)}`);for(let V in G){if(V==="shortMessage")continue;let U=G[V];Z.push(V+"="+oX(U))}}if(Z.push(`code=${Y}`),Z.push(`version=${Dq}`),Z.length)W+=" ("+Z.join(", ")+")"}let J;switch(Y){case"INVALID_ARGUMENT":J=TypeError(W);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":J=RangeError(W);break;default:J=Error(W)}if(H8(J,{code:Y}),G)Object.assign(J,G);if(J.shortMessage==null)H8(J,{shortMessage:X});return J}function X1(W,Y,G,X){if(!W)throw AU(Y,G,X)}function r(W,Y,G,X){X1(W,Y,"INVALID_ARGUMENT",{argument:G,value:X})}var nr=["NFD","NFC","NFKD","NFKC"].reduce((W,Y)=>{try{if("test".normalize(Y)!=="test")throw Error("bad");if(Y==="NFD"){let G=String.fromCharCode(233).normalize("NFD"),X=String.fromCharCode(101,769);if(G!==X)throw Error("broken")}W.push(Y)}catch(G){}return W},[]);function nX(W){X1(nr.indexOf(W)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:W}})}function d4(W,Y,G){if(G==null)G="";if(W!==Y){let X=G,J="new";if(G)X+=".",J+=" "+G;X1(!1,`private constructor; use ${X}from* methods`,"UNSUPPORTED_OPERATION",{operation:J})}}function Cx(W,Y,G){if(W instanceof Uint8Array){if(G)return new Uint8Array(W);return W}if(typeof W==="string"&&W.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)){let X=new Uint8Array((W.length-2)/2),J=2;for(let Z=0;Z<X.length;Z++)X[Z]=parseInt(W.substring(J,J+2),16),J+=2;return X}r(!1,"invalid BytesLike value",Y||"value",W)}function B0(W,Y){return Cx(W,Y,!1)}function Z7(W,Y){return Cx(W,Y,!0)}function R9(W,Y){if(typeof W!=="string"||!W.match(/^0x[0-9A-Fa-f]*$/))return!1;if(typeof Y==="number"&&W.length!==2+2*Y)return!1;if(Y===!0&&W.length%2!==0)return!1;return!0}function n7(W){return R9(W,!0)||W instanceof Uint8Array}var Dx="0123456789abcdef";function C0(W){let Y=B0(W),G="0x";for(let X=0;X<Y.length;X++){let J=Y[X];G+=Dx[(J&240)>>4]+Dx[J&15]}return G}function t1(W){return"0x"+W.map((Y)=>C0(Y).substring(2)).join("")}function o4(W){if(R9(W,!0))return(W.length-2)/2;return B0(W).length}function iX(W,Y,G){let X=B0(W);if(G!=null&&G>X.length)X1(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:X,length:X.length,offset:G});return C0(X.slice(Y==null?0:Y,G==null?X.length:G))}function ir(W,Y,G){let X=B0(W);X1(Y>=X.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(X),length:Y,offset:Y+1});let J=new Uint8Array(Y);if(J.fill(0),G)J.set(X,Y-X.length);else J.set(X,0);return C0(J)}function A5(W,Y){return ir(W,Y,!0)}var wK=BigInt(0),FY=BigInt(1),rX=9007199254740991;function Tq(W,Y){let G=u1(W,"value"),X=BigInt(r8(Y,"width")),J=FY<<X-FY;if(G<wK){G=-G,X1(G<=J,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});let Z=(FY<<X)-FY;return(~G&Z)+FY}else X1(G<J,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:W});return G}function Rq(W,Y){let G=IU(W,"value"),X=BigInt(r8(Y,"bits"));return G&(FY<<X)-FY}function u1(W,Y){switch(typeof W){case"bigint":return W;case"number":return r(Number.isInteger(W),"underflow",Y||"value",W),r(W>=-rX&&W<=rX,"overflow",Y||"value",W),BigInt(W);case"string":try{if(W==="")throw Error("empty string");if(W[0]==="-"&&W[1]!=="-")return-BigInt(W.substring(1));return BigInt(W)}catch(G){r(!1,`invalid BigNumberish string: ${G.message}`,Y||"value",W)}}r(!1,"invalid BigNumberish value",Y||"value",W)}function IU(W,Y){let G=u1(W,Y);return X1(G>=wK,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:W}),G}var Tx="0123456789abcdef";function aX(W){if(W instanceof Uint8Array){let Y="0x0";for(let G of W)Y+=Tx[G>>4],Y+=Tx[G&15];return BigInt(Y)}return u1(W)}function r8(W,Y){switch(typeof W){case"bigint":return r(W>=-rX&&W<=rX,"overflow",Y||"value",W),Number(W);case"number":return r(Number.isInteger(W),"underflow",Y||"value",W),r(W>=-rX&&W<=rX,"overflow",Y||"value",W),W;case"string":try{if(W==="")throw Error("empty string");return r8(BigInt(W),Y)}catch(G){r(!1,`invalid numeric string: ${G.message}`,Y||"value",W)}}r(!1,"invalid numeric value",Y||"value",W)}function V7(W,Y){let X=IU(W,"value").toString(16);if(Y==null){if(X.length%2)X="0"+X}else{let J=r8(Y,"width");X1(J*2>=X.length,`value exceeds width (${J} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:W});while(X.length<J*2)X="0"+X}return"0x"+X}function N8(W){let Y=IU(W,"value");if(Y===wK)return new Uint8Array([]);let G=Y.toString(16);if(G.length%2)G="0"+G;let X=new Uint8Array(G.length/2);for(let J=0;J<X.length;J++){let Z=J*2;X[J]=parseInt(G.substring(Z,Z+2),16)}return X}function Mq(W){let Y=C0(n7(W)?W:N8(W)).substring(2);while(Y.startsWith("0"))Y=Y.substring(1);if(Y==="")Y="0";return"0x"+Y}var Lq="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Pq=null;function rr(W){if(Pq==null){Pq={};for(let G=0;G<Lq.length;G++)Pq[Lq[G]]=BigInt(G)}let Y=Pq[W];return r(Y!=null,"invalid base58 value","letter",W),Y}var ar=BigInt(0),jK=BigInt(58);function Bq(W){let Y=B0(W),G=aX(Y),X="";while(G)X=Lq[Number(G%jK)]+X,G/=jK;for(let J=0;J<Y.length;J++){if(Y[J])break;X=Lq[0]+X}return X}function Eq(W){let Y=ar;for(let G=0;G<W.length;G++)Y*=jK,Y+=rr(W[G]);return Y}function sr(W,Y,G,X,J){r(!1,`invalid codepoint at offset ${Y}; ${W}`,"bytes",G)}function Rx(W,Y,G,X,J){if(W==="BAD_PREFIX"||W==="UNEXPECTED_CONTINUE"){let Z=0;for(let V=Y+1;V<G.length;V++){if(G[V]>>6!==2)break;Z++}return Z}if(W==="OVERRUN")return G.length-Y-1;return 0}function tr(W,Y,G,X,J){if(W==="OVERLONG")return r(typeof J==="number","invalid bad code point for replacement","badCodepoint",J),X.push(J),0;return X.push(65533),Rx(W,Y,G,X,J)}var Mx=Object.freeze({error:sr,ignore:Rx,replace:tr});function M9(W,Y){if(r(typeof W==="string","invalid string value","str",W),Y!=null)nX(Y),W=W.normalize(Y);let G=[];for(let X=0;X<W.length;X++){let J=W.charCodeAt(X);if(J<128)G.push(J);else if(J<2048)G.push(J>>6|192),G.push(J&63|128);else if((J&64512)==55296){X++;let Z=W.charCodeAt(X);r(X<W.length&&(Z&64512)===56320,"invalid surrogate pair","str",W);let V=65536+((J&1023)<<10)+(Z&1023);G.push(V>>18|240),G.push(V>>12&63|128),G.push(V>>6&63|128),G.push(V&63|128)}else G.push(J>>12|224),G.push(J>>6&63|128),G.push(J&63|128)}return new Uint8Array(G)}function er(W){let Y=W.toString(16);while(Y.length<2)Y="0"+Y;return"0x"+Y}function Px(W,Y,G){let X=0;for(let J=0;J<G;J++)X=X*256+W[Y+J];return X}function Lx(W,Y,G,X){let J=[];while(G<Y+1+X){let Z=Bx(W,G);J.push(Z.result),G+=Z.consumed,X1(G<=Y+1+X,"child data too short","BUFFER_OVERRUN",{buffer:W,length:X,offset:Y})}return{consumed:1+X,result:J}}function Bx(W,Y){X1(W.length!==0,"data too short","BUFFER_OVERRUN",{buffer:W,length:0,offset:1});let G=(X)=>{X1(X<=W.length,"data short segment too short","BUFFER_OVERRUN",{buffer:W,length:W.length,offset:X})};if(W[Y]>=248){let X=W[Y]-247;G(Y+1+X);let J=Px(W,Y+1,X);return G(Y+1+X+J),Lx(W,Y,Y+1+X,X+J)}else if(W[Y]>=192){let X=W[Y]-192;return G(Y+1+X),Lx(W,Y,Y+1,X)}else if(W[Y]>=184){let X=W[Y]-183;G(Y+1+X);let J=Px(W,Y+1,X);G(Y+1+X+J);let Z=C0(W.slice(Y+1+X,Y+1+X+J));return{consumed:1+X+J,result:Z}}else if(W[Y]>=128){let X=W[Y]-128;G(Y+1+X);let J=C0(W.slice(Y+1,Y+1+X));return{consumed:1+X,result:J}}return{consumed:1,result:er(W[Y])}}function WW(W){let Y=B0(W,"data"),G=Bx(Y,0);return r(G.consumed===Y.length,"unexpected junk after rlp payload","data",W),G.result}function Ex(W){let Y=[];while(W)Y.unshift(W&255),W>>=8;return Y}function Fx(W){if(Array.isArray(W)){let X=[];if(W.forEach(function(Z){X=X.concat(Fx(Z))}),X.length<=55)return X.unshift(192+X.length),X;let J=Ex(X.length);return J.unshift(247+J.length),J.concat(X)}let Y=Array.prototype.slice.call(B0(W,"object"));if(Y.length===1&&Y[0]<=127)return Y;else if(Y.length<=55)return Y.unshift(128+Y.length),Y;let G=Ex(Y.length);return G.unshift(183+G.length),G.concat(Y)}var $x="0123456789abcdef";function $5(W){let Y="0x";for(let G of Fx(W))Y+=$x[G>>4],Y+=$x[G&15];return Y}function $q(W){let Y=B0(W,"randomBytes");Y[6]=Y[6]&15|64,Y[8]=Y[8]&63|128;let G=C0(Y);return[G.substring(2,10),G.substring(10,14),G.substring(14,18),G.substring(18,22),G.substring(22,34)].join("-")}import{createHash as OK,createHmac as Sx,pbkdf2Sync as xx,randomBytes as kx}from"crypto";var _x=!1,yx=function(W,Y,G){return Sx(W,Y).update(G).digest()},vx=yx;function YW(W,Y,G){let X=B0(Y,"key"),J=B0(G,"data");return C0(vx(W,X,J))}YW._=yx;YW.lock=function(){_x=!0};YW.register=function(W){if(_x)throw Error("computeHmac is locked");vx=W};Object.freeze(YW);function P9(W){if(!Number.isSafeInteger(W)||W<0)throw Error(`Wrong positive integer: ${W}`)}function zU(W,...Y){if(!(W instanceof Uint8Array))throw Error("Expected Uint8Array");if(Y.length>0&&!Y.includes(W.length))throw Error(`Expected Uint8Array of length ${Y}, not of length=${W.length}`)}function Fq(W){if(typeof W!=="function"||typeof W.create!=="function")throw Error("Hash should be wrapped by utils.wrapConstructor");P9(W.outputLen),P9(W.blockLen)}function n4(W,Y=!0){if(W.destroyed)throw Error("Hash instance has been destroyed");if(Y&&W.finished)throw Error("Hash#digest() has already been called")}function Sq(W,Y){zU(W);let G=Y.outputLen;if(W.length<G)throw Error(`digestInto() expects output buffer of length at least ${G}`)}var xq=BigInt(4294967295),gx=BigInt(32);function Qa(W,Y=!1){if(Y)return{h:Number(W&xq),l:Number(W>>gx&xq)};return{h:Number(W>>gx&xq)|0,l:Number(W&xq)|0}}function ux(W,Y=!1){let G=new Uint32Array(W.length),X=new Uint32Array(W.length);for(let J=0;J<W.length;J++){let{h:Z,l:V}=Qa(W[J],Y);[G[J],X[J]]=[Z,V]}return[G,X]}var hx=(W,Y,G)=>W<<G|Y>>>32-G,bx=(W,Y,G)=>Y<<G|W>>>32-G,mx=(W,Y,G)=>Y<<G-32|W>>>64-G,fx=(W,Y,G)=>W<<G-32|Y>>>64-G;import*as wU from"crypto";var kq=wU&&typeof wU==="object"&&"webcrypto"in wU?wU.webcrypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */var cx=(W)=>W instanceof Uint8Array;var sX=(W)=>new Uint32Array(W.buffer,W.byteOffset,Math.floor(W.byteLength/4)),tX=(W)=>new DataView(W.buffer,W.byteOffset,W.byteLength),U7=(W,Y)=>W<<32-Y|W>>>Y,Ha=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ha)throw Error("Non little-endian hardware is not supported");var Na=async()=>{};async function _q(W,Y,G){let X=Date.now();for(let J=0;J<W;J++){G(J);let Z=Date.now()-X;if(Z>=0&&Z<Y)continue;await Na(),X+=Z}}function qa(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function i7(W){if(typeof W==="string")W=qa(W);if(!cx(W))throw Error(`expected Uint8Array, got ${typeof W}`);return W}function px(...W){let Y=new Uint8Array(W.reduce((X,J)=>X+J.length,0)),G=0;return W.forEach((X)=>{if(!cx(X))throw Error("Uint8Array expected");Y.set(X,G),G+=X.length}),Y}class SY{clone(){return this._cloneInto()}}var Aa={}.toString;function yq(W,Y){if(Y!==void 0&&Aa.call(Y)!=="[object Object]")throw Error("Options should be object or undefined");return Object.assign(W,Y)}function eX(W){let Y=(X)=>W().update(i7(X)).digest(),G=W();return Y.outputLen=G.outputLen,Y.blockLen=G.blockLen,Y.create=()=>W(),Y}function lx(W=32){if(kq&&typeof kq.getRandomValues==="function")return kq.getRandomValues(new Uint8Array(W));throw Error("crypto.getRandomValues must be defined")}var[nx,ix,rx]=[[],[],[]],Ia=BigInt(0),jU=BigInt(1),za=BigInt(2),wa=BigInt(7),ja=BigInt(256),Oa=BigInt(113);for(let W=0,Y=jU,G=1,X=0;W<24;W++){[G,X]=[X,(2*G+3*X)%5],nx.push(2*(5*X+G)),ix.push((W+1)*(W+2)/2%64);let J=Ia;for(let Z=0;Z<7;Z++)if(Y=(Y<<jU^(Y>>wa)*Oa)%ja,Y&za)J^=jU<<(jU<<BigInt(Z))-jU;rx.push(J)}var[Ka,Da]=ux(rx,!0),dx=(W,Y,G)=>G>32?mx(W,Y,G):hx(W,Y,G),ox=(W,Y,G)=>G>32?fx(W,Y,G):bx(W,Y,G);function Ca(W,Y=24){let G=new Uint32Array(10);for(let X=24-Y;X<24;X++){for(let V=0;V<10;V++)G[V]=W[V]^W[V+10]^W[V+20]^W[V+30]^W[V+40];for(let V=0;V<10;V+=2){let U=(V+8)%10,Q=(V+2)%10,H=G[Q],N=G[Q+1],A=dx(H,N,1)^G[U],q=ox(H,N,1)^G[U+1];for(let z=0;z<50;z+=10)W[V+z]^=A,W[V+z+1]^=q}let J=W[2],Z=W[3];for(let V=0;V<24;V++){let U=ix[V],Q=dx(J,Z,U),H=ox(J,Z,U),N=nx[V];J=W[N],Z=W[N+1],W[N]=Q,W[N+1]=H}for(let V=0;V<50;V+=10){for(let U=0;U<10;U++)G[U]=W[V+U];for(let U=0;U<10;U++)W[V+U]^=~G[(U+2)%10]&G[(U+4)%10]}W[0]^=Ka[X],W[1]^=Da[X]}G.fill(0)}class KK extends SY{constructor(W,Y,G,X=!1,J=24){super();if(this.blockLen=W,this.suffix=Y,this.outputLen=G,this.enableXOF=X,this.rounds=J,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,P9(G),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=sX(this.state)}keccak(){Ca(this.state32,this.rounds),this.posOut=0,this.pos=0}update(W){n4(this);let{blockLen:Y,state:G}=this;W=i7(W);let X=W.length;for(let J=0;J<X;){let Z=Math.min(Y-this.pos,X-J);for(let V=0;V<Z;V++)G[this.pos++]^=W[J++];if(this.pos===Y)this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:W,suffix:Y,pos:G,blockLen:X}=this;if(W[G]^=Y,(Y&128)!==0&&G===X-1)this.keccak();W[X-1]^=128,this.keccak()}writeInto(W){n4(this,!1),zU(W),this.finish();let Y=this.state,{blockLen:G}=this;for(let X=0,J=W.length;X<J;){if(this.posOut>=G)this.keccak();let Z=Math.min(G-this.posOut,J-X);W.set(Y.subarray(this.posOut,this.posOut+Z),X),this.posOut+=Z,X+=Z}return W}xofInto(W){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(W)}xof(W){return P9(W),this.xofInto(new Uint8Array(W))}digestInto(W){if(Sq(W,this),this.finished)throw Error("digest() was already called");return this.writeInto(W),this.destroy(),W}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(W){let{blockLen:Y,suffix:G,outputLen:X,rounds:J,enableXOF:Z}=this;return W||(W=new KK(Y,G,X,Z,J)),W.state32.set(this.state32),W.pos=this.pos,W.posOut=this.posOut,W.finished=this.finished,W.rounds=J,W.suffix=G,W.outputLen=X,W.enableXOF=Z,W.destroyed=this.destroyed,W}}var Ta=(W,Y,G)=>eX(()=>new KK(Y,W,G));var ax=Ta(1,136,32);var sx=!1,tx=function(W){return ax(W)},ex=tx;function X8(W){let Y=B0(W,"data");return C0(ex(Y))}X8._=tx;X8.lock=function(){sx=!0};X8.register=function(W){if(sx)throw TypeError("keccak256 is locked");ex=W};Object.freeze(X8);function Ra(W,Y,G,X){if(typeof W.setBigUint64==="function")return W.setBigUint64(Y,G,X);let J=BigInt(32),Z=BigInt(4294967295),V=Number(G>>J&Z),U=Number(G&Z),Q=X?4:0,H=X?0:4;W.setUint32(Y+Q,V,X),W.setUint32(Y+H,U,X)}class OU extends SY{constructor(W,Y,G,X){super();this.blockLen=W,this.outputLen=Y,this.padOffset=G,this.isLE=X,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(W),this.view=tX(this.buffer)}update(W){n4(this);let{view:Y,buffer:G,blockLen:X}=this;W=i7(W);let J=W.length;for(let Z=0;Z<J;){let V=Math.min(X-this.pos,J-Z);if(V===X){let U=tX(W);for(;X<=J-Z;Z+=X)this.process(U,Z);continue}if(G.set(W.subarray(Z,Z+V),this.pos),this.pos+=V,Z+=V,this.pos===X)this.process(Y,0),this.pos=0}return this.length+=W.length,this.roundClean(),this}digestInto(W){n4(this),Sq(W,this),this.finished=!0;let{buffer:Y,view:G,blockLen:X,isLE:J}=this,{pos:Z}=this;if(Y[Z++]=128,this.buffer.subarray(Z).fill(0),this.padOffset>X-Z)this.process(G,0),Z=0;for(let N=Z;N<X;N++)Y[N]=0;Ra(G,X-8,BigInt(this.length*8),J),this.process(G,0);let V=tX(W),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen should be aligned to 32bit");let Q=U/4,H=this.get();if(Q>H.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<Q;N++)V.setUint32(4*N,H[N],J)}digest(){let{buffer:W,outputLen:Y}=this;this.digestInto(W);let G=W.slice(0,Y);return this.destroy(),G}_cloneInto(W){W||(W=new this.constructor),W.set(...this.get());let{blockLen:Y,buffer:G,length:X,finished:J,destroyed:Z,pos:V}=this;if(W.length=X,W.pos=V,W.finished=J,W.destroyed=Z,X%Y)W.buffer.set(G);return W}}var Ma=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Yk=Uint8Array.from({length:16},(W,Y)=>Y),Pa=Yk.map((W)=>(9*W+5)%16),DK=[Yk],CK=[Pa];for(let W=0;W<4;W++)for(let Y of[DK,CK])Y.push(Y[W].map((G)=>Ma[G]));var Gk=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((W)=>new Uint8Array(W)),La=DK.map((W,Y)=>W.map((G)=>Gk[Y][G])),Ba=CK.map((W,Y)=>W.map((G)=>Gk[Y][G])),Ea=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),$a=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),vq=(W,Y)=>W<<Y|W>>>32-Y;function Wk(W,Y,G,X){if(W===0)return Y^G^X;else if(W===1)return Y&G|~Y&X;else if(W===2)return(Y|~G)^X;else if(W===3)return Y&X|G&~X;else return Y^(G|~X)}var gq=new Uint32Array(16);class Xk extends OU{constructor(){super(64,20,8,!0);this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:W,h1:Y,h2:G,h3:X,h4:J}=this;return[W,Y,G,X,J]}set(W,Y,G,X,J){this.h0=W|0,this.h1=Y|0,this.h2=G|0,this.h3=X|0,this.h4=J|0}process(W,Y){for(let q=0;q<16;q++,Y+=4)gq[q]=W.getUint32(Y,!0);let G=this.h0|0,X=G,J=this.h1|0,Z=J,V=this.h2|0,U=V,Q=this.h3|0,H=Q,N=this.h4|0,A=N;for(let q=0;q<5;q++){let z=4-q,w=Ea[q],D=$a[q],T=DK[q],x=CK[q],g=La[q],f=Ba[q];for(let y=0;y<16;y++){let p=vq(G+Wk(q,J,V,Q)+gq[T[y]]+w,g[y])+N|0;G=N,N=Q,Q=vq(V,10)|0,V=J,J=p}for(let y=0;y<16;y++){let p=vq(X+Wk(z,Z,U,H)+gq[x[y]]+D,f[y])+A|0;X=A,A=H,H=vq(U,10)|0,U=Z,Z=p}}this.set(this.h1+V+H|0,this.h2+Q+A|0,this.h3+N+X|0,this.h4+G+Z|0,this.h0+J+U|0)}roundClean(){gq.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}var Jk=eX(()=>new Xk);var Zk=!1,Vk=function(W){return Jk(W)},Uk=Vk;function GW(W){let Y=B0(W,"data");return C0(Uk(Y))}GW._=Vk;GW.lock=function(){Zk=!0};GW.register=function(W){if(Zk)throw TypeError("ripemd160 is locked");Uk=W};Object.freeze(GW);var Qk=!1,Hk=function(W,Y,G,X,J){return xx(W,Y,G,X,J)},Nk=Hk;function F5(W,Y,G,X,J){let Z=B0(W,"password"),V=B0(Y,"salt");return C0(Nk(Z,V,G,X,J))}F5._=Hk;F5.lock=function(){Qk=!0};F5.register=function(W){if(Qk)throw Error("pbkdf2 is locked");Nk=W};Object.freeze(F5);var qk=!1,Ak=function(W){return new Uint8Array(kx(W))},Ik=Ak;function S5(W){return Ik(W)}S5._=Ak;S5.lock=function(){qk=!0};S5.register=function(W){if(qk)throw Error("randomBytes is locked");Ik=W};Object.freeze(S5);var Fa=(W,Y,G)=>W&Y^~W&G,Sa=(W,Y,G)=>W&Y^W&G^Y&G,xa=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]),XW=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),JW=new Uint32Array(64);class zk extends OU{constructor(){super(64,32,8,!1);this.A=XW[0]|0,this.B=XW[1]|0,this.C=XW[2]|0,this.D=XW[3]|0,this.E=XW[4]|0,this.F=XW[5]|0,this.G=XW[6]|0,this.H=XW[7]|0}get(){let{A:W,B:Y,C:G,D:X,E:J,F:Z,G:V,H:U}=this;return[W,Y,G,X,J,Z,V,U]}set(W,Y,G,X,J,Z,V,U){this.A=W|0,this.B=Y|0,this.C=G|0,this.D=X|0,this.E=J|0,this.F=Z|0,this.G=V|0,this.H=U|0}process(W,Y){for(let N=0;N<16;N++,Y+=4)JW[N]=W.getUint32(Y,!1);for(let N=16;N<64;N++){let A=JW[N-15],q=JW[N-2],z=U7(A,7)^U7(A,18)^A>>>3,w=U7(q,17)^U7(q,19)^q>>>10;JW[N]=w+JW[N-7]+z+JW[N-16]|0}let{A:G,B:X,C:J,D:Z,E:V,F:U,G:Q,H}=this;for(let N=0;N<64;N++){let A=U7(V,6)^U7(V,11)^U7(V,25),q=H+A+Fa(V,U,Q)+xa[N]+JW[N]|0,w=(U7(G,2)^U7(G,13)^U7(G,22))+Sa(G,X,J)|0;H=Q,Q=U,U=V,V=Z+q|0,Z=J,J=X,X=G,G=q+w|0}G=G+this.A|0,X=X+this.B|0,J=J+this.C|0,Z=Z+this.D|0,V=V+this.E|0,U=U+this.F|0,Q=Q+this.G|0,H=H+this.H|0,this.set(G,X,J,Z,V,U,Q,H)}roundClean(){JW.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}var KU=eX(()=>new zk);class TK extends SY{constructor(W,Y){super();this.finished=!1,this.destroyed=!1,Fq(W);let G=i7(Y);if(this.iHash=W.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let X=this.blockLen,J=new Uint8Array(X);J.set(G.length>X?W.create().update(G).digest():G);for(let Z=0;Z<J.length;Z++)J[Z]^=54;this.iHash.update(J),this.oHash=W.create();for(let Z=0;Z<J.length;Z++)J[Z]^=106;this.oHash.update(J),J.fill(0)}update(W){return n4(this),this.iHash.update(W),this}digestInto(W){n4(this),zU(W,this.outputLen),this.finished=!0,this.iHash.digestInto(W),this.oHash.update(W),this.oHash.digestInto(W),this.destroy()}digest(){let W=new Uint8Array(this.oHash.outputLen);return this.digestInto(W),W}_cloneInto(W){W||(W=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Y,iHash:G,finished:X,destroyed:J,blockLen:Z,outputLen:V}=this;return W=W,W.finished=X,W.destroyed=J,W.blockLen=Z,W.outputLen=V,W.oHash=Y._cloneInto(W.oHash),W.iHash=G._cloneInto(W.iHash),W}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var DU=(W,Y,G)=>new TK(W,Y).update(G).digest();DU.create=(W,Y)=>new TK(W,Y);function ka(W,Y,G,X){Fq(W);let J=yq({dkLen:32,asyncTick:10},X),{c:Z,dkLen:V,asyncTick:U}=J;if(P9(Z),P9(V),P9(U),Z<1)throw Error("PBKDF2: iterations (c) should be >= 1");let Q=i7(Y),H=i7(G),N=new Uint8Array(V),A=DU.create(W,Q),q=A._cloneInto().update(H);return{c:Z,dkLen:V,asyncTick:U,DK:N,PRF:A,PRFSalt:q}}function _a(W,Y,G,X,J){if(W.destroy(),Y.destroy(),X)X.destroy();return J.fill(0),G}function RK(W,Y,G,X){let{c:J,dkLen:Z,DK:V,PRF:U,PRFSalt:Q}=ka(W,Y,G,X),H,N=new Uint8Array(4),A=tX(N),q=new Uint8Array(U.outputLen);for(let z=1,w=0;w<Z;z++,w+=U.outputLen){let D=V.subarray(w,w+U.outputLen);A.setInt32(0,z,!1),(H=Q._cloneInto(H)).update(N).digestInto(q),D.set(q.subarray(0,D.length));for(let T=1;T<J;T++){U._cloneInto(H).update(q).digestInto(q);for(let x=0;x<D.length;x++)D[x]^=q[x]}}return _a(U,Q,V,H,q)}var n1=(W,Y)=>W<<Y|W>>>32-Y;function wk(W,Y,G,X,J,Z){let V=W[Y++]^G[X++],U=W[Y++]^G[X++],Q=W[Y++]^G[X++],H=W[Y++]^G[X++],N=W[Y++]^G[X++],A=W[Y++]^G[X++],q=W[Y++]^G[X++],z=W[Y++]^G[X++],w=W[Y++]^G[X++],D=W[Y++]^G[X++],T=W[Y++]^G[X++],x=W[Y++]^G[X++],g=W[Y++]^G[X++],f=W[Y++]^G[X++],y=W[Y++]^G[X++],p=W[Y++]^G[X++],b=V,m=U,W0=Q,u=H,J0=N,I0=A,k=q,l=z,B=w,$=D,h=T,a=x,n=g,E=f,P=y,v=p;for(let M=0;M<8;M+=2)J0^=n1(b+n|0,7),B^=n1(J0+b|0,9),n^=n1(B+J0|0,13),b^=n1(n+B|0,18),$^=n1(I0+m|0,7),E^=n1($+I0|0,9),m^=n1(E+$|0,13),I0^=n1(m+E|0,18),P^=n1(h+k|0,7),W0^=n1(P+h|0,9),k^=n1(W0+P|0,13),h^=n1(k+W0|0,18),u^=n1(v+a|0,7),l^=n1(u+v|0,9),a^=n1(l+u|0,13),v^=n1(a+l|0,18),m^=n1(b+u|0,7),W0^=n1(m+b|0,9),u^=n1(W0+m|0,13),b^=n1(u+W0|0,18),k^=n1(I0+J0|0,7),l^=n1(k+I0|0,9),J0^=n1(l+k|0,13),I0^=n1(J0+l|0,18),a^=n1(h+$|0,7),B^=n1(a+h|0,9),$^=n1(B+a|0,13),h^=n1($+B|0,18),n^=n1(v+P|0,7),E^=n1(n+v|0,9),P^=n1(E+n|0,13),v^=n1(P+E|0,18);J[Z++]=V+b|0,J[Z++]=U+m|0,J[Z++]=Q+W0|0,J[Z++]=H+u|0,J[Z++]=N+J0|0,J[Z++]=A+I0|0,J[Z++]=q+k|0,J[Z++]=z+l|0,J[Z++]=w+B|0,J[Z++]=D+$|0,J[Z++]=T+h|0,J[Z++]=x+a|0,J[Z++]=g+n|0,J[Z++]=f+E|0,J[Z++]=y+P|0,J[Z++]=p+v|0}function WJ(W,Y,G,X,J){let Z=X+0,V=X+16*J;for(let U=0;U<16;U++)G[V+U]=W[Y+(2*J-1)*16+U];for(let U=0;U<J;U++,Z+=16,Y+=16){if(wk(G,V,W,Y,G,Z),U>0)V+=16;wk(G,Z,W,Y+=16,G,V)}}function jk(W,Y,G){let X=yq({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:J,r:Z,p:V,dkLen:U,asyncTick:Q,maxmem:H,onProgress:N}=X;if(P9(J),P9(Z),P9(V),P9(U),P9(Q),P9(H),N!==void 0&&typeof N!=="function")throw Error("progressCb should be function");let A=128*Z,q=A/4;if(J<=1||(J&J-1)!==0||J>=2**(A/8)||J>4294967296)throw Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");if(V<0||V>137438953440/A)throw Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(U<0||U>137438953440)throw Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");let z=A*(J+V);if(z>H)throw Error(`Scrypt: parameters too large, ${z} (128 * r * (N + p)) > ${H} (maxmem)`);let w=RK(KU,W,Y,{c:1,dkLen:A*V}),D=sX(w),T=sX(new Uint8Array(A*J)),x=sX(new Uint8Array(A)),g=()=>{};if(N){let f=2*J*V,y=Math.max(Math.floor(f/1e4),1),p=0;g=()=>{if(p++,N&&(!(p%y)||p===f))N(p/f)}}return{N:J,r:Z,p:V,dkLen:U,blockSize32:q,V:T,B32:D,B:w,tmp:x,blockMixCb:g,asyncTick:Q}}function Ok(W,Y,G,X,J){let Z=RK(KU,W,G,{c:1,dkLen:Y});return G.fill(0),X.fill(0),J.fill(0),Z}function Kk(W,Y,G){let{N:X,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:H,B:N,tmp:A,blockMixCb:q}=jk(W,Y,G);for(let z=0;z<Z;z++){let w=U*z;for(let D=0;D<U;D++)Q[D]=H[w+D];for(let D=0,T=0;D<X-1;D++)WJ(Q,T,Q,T+=U,J),q();WJ(Q,(X-1)*U,H,w,J),q();for(let D=0;D<X;D++){let T=H[w+U-16]%X;for(let x=0;x<U;x++)A[x]=H[w+x]^Q[T*U+x];WJ(A,0,H,w,J),q()}}return Ok(W,V,N,Q,A)}async function Dk(W,Y,G){let{N:X,r:J,p:Z,dkLen:V,blockSize32:U,V:Q,B32:H,B:N,tmp:A,blockMixCb:q,asyncTick:z}=jk(W,Y,G);for(let w=0;w<Z;w++){let D=U*w;for(let x=0;x<U;x++)Q[x]=H[D+x];let T=0;await _q(X-1,z,()=>{WJ(Q,T,Q,T+=U,J),q()}),WJ(Q,(X-1)*U,H,D,J),q(),await _q(X,z,()=>{let x=H[D+U-16]%X;for(let g=0;g<U;g++)A[g]=H[D+g]^Q[x*U+g];WJ(A,0,H,D,J),q()})}return Ok(W,V,N,Q,A)}var Ck=!1,Tk=!1,Rk=async function(W,Y,G,X,J,Z,V){return await Dk(W,Y,{N:G,r:X,p:J,dkLen:Z,onProgress:V})},Mk=function(W,Y,G,X,J,Z){return Kk(W,Y,{N:G,r:X,p:J,dkLen:Z})},Pk=Rk,Lk=Mk;async function ZW(W,Y,G,X,J,Z,V){let U=B0(W,"passwd"),Q=B0(Y,"salt");return C0(await Pk(U,Q,G,X,J,Z,V))}ZW._=Rk;ZW.lock=function(){Tk=!0};ZW.register=function(W){if(Tk)throw Error("scrypt is locked");Pk=W};Object.freeze(ZW);function VW(W,Y,G,X,J,Z){let V=B0(W,"passwd"),U=B0(Y,"salt");return C0(Lk(V,U,G,X,J,Z))}VW._=Mk;VW.lock=function(){Ck=!0};VW.register=function(W){if(Ck)throw Error("scryptSync is locked");Lk=W};Object.freeze(VW);var Bk=function(W){return OK("sha256").update(W).digest()},Ek=function(W){return OK("sha512").update(W).digest()},$k=Bk,Fk=Ek,Sk=!1,xk=!1;function L9(W){let Y=B0(W,"data");return C0($k(Y))}L9._=Bk;L9.lock=function(){Sk=!0};L9.register=function(W){if(Sk)throw Error("sha256 is locked");$k=W};Object.freeze(L9);function uq(W){let Y=B0(W,"data");return C0(Fk(Y))}uq._=Ek;uq.lock=function(){xk=!0};uq.register=function(W){if(xk)throw Error("sha512 is locked");Fk=W};Object.freeze(L9);var BK={};NA(BK,{validateObject:()=>QW,utf8ToBytes:()=>ha,numberToVarBytesBE:()=>ga,numberToHexUnpadded:()=>yk,numberToBytesLE:()=>fq,numberToBytesBE:()=>UW,hexToNumber:()=>PK,hexToBytes:()=>kY,equalBytes:()=>ua,ensureBytes:()=>I5,createHmacDrbg:()=>LK,concatBytes:()=>YJ,bytesToNumberLE:()=>mq,bytesToNumberBE:()=>i4,bytesToHex:()=>xY,bitSet:()=>fa,bitMask:()=>CU,bitLen:()=>ba,bitGet:()=>ma});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var _k=BigInt(0),hq=BigInt(1),ya=BigInt(2),bq=(W)=>W instanceof Uint8Array,va=Array.from({length:256},(W,Y)=>Y.toString(16).padStart(2,"0"));function xY(W){if(!bq(W))throw Error("Uint8Array expected");let Y="";for(let G=0;G<W.length;G++)Y+=va[W[G]];return Y}function yk(W){let Y=W.toString(16);return Y.length&1?`0${Y}`:Y}function PK(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);return BigInt(W===""?"0":`0x${W}`)}function kY(W){if(typeof W!=="string")throw Error("hex string expected, got "+typeof W);let Y=W.length;if(Y%2)throw Error("padded hex string expected, got unpadded hex of length "+Y);let G=new Uint8Array(Y/2);for(let X=0;X<G.length;X++){let J=X*2,Z=W.slice(J,J+2),V=Number.parseInt(Z,16);if(Number.isNaN(V)||V<0)throw Error("Invalid byte sequence");G[X]=V}return G}function i4(W){return PK(xY(W))}function mq(W){if(!bq(W))throw Error("Uint8Array expected");return PK(xY(Uint8Array.from(W).reverse()))}function UW(W,Y){return kY(W.toString(16).padStart(Y*2,"0"))}function fq(W,Y){return UW(W,Y).reverse()}function ga(W){return kY(yk(W))}function I5(W,Y,G){let X;if(typeof Y==="string")try{X=kY(Y)}catch(Z){throw Error(`${W} must be valid hex string, got "${Y}". Cause: ${Z}`)}else if(bq(Y))X=Uint8Array.from(Y);else throw Error(`${W} must be hex string or Uint8Array`);let J=X.length;if(typeof G==="number"&&J!==G)throw Error(`${W} expected ${G} bytes, got ${J}`);return X}function YJ(...W){let Y=new Uint8Array(W.reduce((X,J)=>X+J.length,0)),G=0;return W.forEach((X)=>{if(!bq(X))throw Error("Uint8Array expected");Y.set(X,G),G+=X.length}),Y}function ua(W,Y){if(W.length!==Y.length)return!1;for(let G=0;G<W.length;G++)if(W[G]!==Y[G])return!1;return!0}function ha(W){if(typeof W!=="string")throw Error(`utf8ToBytes expected string, got ${typeof W}`);return new Uint8Array(new TextEncoder().encode(W))}function ba(W){let Y;for(Y=0;W>_k;W>>=hq,Y+=1);return Y}function ma(W,Y){return W>>BigInt(Y)&hq}var fa=(W,Y,G)=>{return W|(G?hq:_k)<<BigInt(Y)},CU=(W)=>(ya<<BigInt(W-1))-hq,MK=(W)=>new Uint8Array(W),kk=(W)=>Uint8Array.from(W);function LK(W,Y,G){if(typeof W!=="number"||W<2)throw Error("hashLen must be a number");if(typeof Y!=="number"||Y<2)throw Error("qByteLen must be a number");if(typeof G!=="function")throw Error("hmacFn must be a function");let X=MK(W),J=MK(W),Z=0,V=()=>{X.fill(1),J.fill(0),Z=0},U=(...A)=>G(J,X,...A),Q=(A=MK())=>{if(J=U(kk([0]),A),X=U(),A.length===0)return;J=U(kk([1]),A),X=U()},H=()=>{if(Z++>=1000)throw Error("drbg: tried 1000 values");let A=0,q=[];while(A<Y){X=U();let z=X.slice();q.push(z),A+=X.length}return YJ(...q)};return(A,q)=>{V(),Q(A);let z=void 0;while(!(z=q(H())))Q();return V(),z}}var ca={bigint:(W)=>typeof W==="bigint",function:(W)=>typeof W==="function",boolean:(W)=>typeof W==="boolean",string:(W)=>typeof W==="string",stringOrUint8Array:(W)=>typeof W==="string"||W instanceof Uint8Array,isSafeInteger:(W)=>Number.isSafeInteger(W),array:(W)=>Array.isArray(W),field:(W,Y)=>Y.Fp.isValid(W),hash:(W)=>typeof W==="function"&&Number.isSafeInteger(W.outputLen)};function QW(W,Y,G={}){let X=(J,Z,V)=>{let U=ca[Z];if(typeof U!=="function")throw Error(`Invalid validator "${Z}", expected function`);let Q=W[J];if(V&&Q===void 0)return;if(!U(Q,W))throw Error(`Invalid param ${String(J)}=${Q} (${typeof Q}), expected ${Z}`)};for(let[J,Z]of Object.entries(Y))X(J,Z,!1);for(let[J,Z]of Object.entries(G))X(J,Z,!0);return W}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var d8=BigInt(0),$8=BigInt(1),_Y=BigInt(2),pa=BigInt(3),EK=BigInt(4),vk=BigInt(5),gk=BigInt(8),la=BigInt(9),da=BigInt(16);function B9(W,Y){let G=W%Y;return G>=d8?G:Y+G}function oa(W,Y,G){if(G<=d8||Y<d8)throw Error("Expected power/modulo > 0");if(G===$8)return d8;let X=$8;while(Y>d8){if(Y&$8)X=X*W%G;W=W*W%G,Y>>=$8}return X}function z5(W,Y,G){let X=W;while(Y-- >d8)X*=X,X%=G;return X}function cq(W,Y){if(W===d8||Y<=d8)throw Error(`invert: expected positive integers, got n=${W} mod=${Y}`);let G=B9(W,Y),X=Y,J=d8,Z=$8,V=$8,U=d8;while(G!==d8){let H=X/G,N=X%G,A=J-V*H,q=Z-U*H;X=G,G=N,J=V,Z=U,V=A,U=q}if(X!==$8)throw Error("invert: does not exist");return B9(J,Y)}function na(W){let Y=(W-$8)/_Y,G,X,J;for(G=W-$8,X=0;G%_Y===d8;G/=_Y,X++);for(J=_Y;J<W&&oa(J,Y,W)!==W-$8;J++);if(X===1){let V=(W+$8)/EK;return function(Q,H){let N=Q.pow(H,V);if(!Q.eql(Q.sqr(N),H))throw Error("Cannot find square root");return N}}let Z=(G+$8)/_Y;return function(U,Q){if(U.pow(Q,Y)===U.neg(U.ONE))throw Error("Cannot find square root");let H=X,N=U.pow(U.mul(U.ONE,J),G),A=U.pow(Q,Z),q=U.pow(Q,G);while(!U.eql(q,U.ONE)){if(U.eql(q,U.ZERO))return U.ZERO;let z=1;for(let D=U.sqr(q);z<H;z++){if(U.eql(D,U.ONE))break;D=U.sqr(D)}let w=U.pow(N,$8<<BigInt(H-z-1));N=U.sqr(w),A=U.mul(A,w),q=U.mul(q,N),H=z}return A}}function ia(W){if(W%EK===pa){let Y=(W+$8)/EK;return function(X,J){let Z=X.pow(J,Y);if(!X.eql(X.sqr(Z),J))throw Error("Cannot find square root");return Z}}if(W%gk===vk){let Y=(W-vk)/gk;return function(X,J){let Z=X.mul(J,_Y),V=X.pow(Z,Y),U=X.mul(J,V),Q=X.mul(X.mul(U,_Y),V),H=X.mul(U,X.sub(Q,X.ONE));if(!X.eql(X.sqr(H),J))throw Error("Cannot find square root");return H}}if(W%da===la);return na(W)}var ra=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $K(W){let Y={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},G=ra.reduce((X,J)=>{return X[J]="function",X},Y);return QW(W,G)}function aa(W,Y,G){if(G<d8)throw Error("Expected power > 0");if(G===d8)return W.ONE;if(G===$8)return Y;let X=W.ONE,J=Y;while(G>d8){if(G&$8)X=W.mul(X,J);J=W.sqr(J),G>>=$8}return X}function sa(W,Y){let G=Array(Y.length),X=Y.reduce((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=Z,W.mul(Z,V)},W.ONE),J=W.inv(X);return Y.reduceRight((Z,V,U)=>{if(W.is0(V))return Z;return G[U]=W.mul(Z,G[U]),W.mul(Z,V)},J),G}function FK(W,Y){let G=Y!==void 0?Y:W.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function uk(W,Y,G=!1,X={}){if(W<=d8)throw Error(`Expected Field ORDER > 0, got ${W}`);let{nBitLength:J,nByteLength:Z}=FK(W,Y);if(Z>2048)throw Error("Field lengths over 2048 bytes are not supported");let V=ia(W),U=Object.freeze({ORDER:W,BITS:J,BYTES:Z,MASK:CU(J),ZERO:d8,ONE:$8,create:(Q)=>B9(Q,W),isValid:(Q)=>{if(typeof Q!=="bigint")throw Error(`Invalid field element: expected bigint, got ${typeof Q}`);return d8<=Q&&Q<W},is0:(Q)=>Q===d8,isOdd:(Q)=>(Q&$8)===$8,neg:(Q)=>B9(-Q,W),eql:(Q,H)=>Q===H,sqr:(Q)=>B9(Q*Q,W),add:(Q,H)=>B9(Q+H,W),sub:(Q,H)=>B9(Q-H,W),mul:(Q,H)=>B9(Q*H,W),pow:(Q,H)=>aa(U,Q,H),div:(Q,H)=>B9(Q*cq(H,W),W),sqrN:(Q)=>Q*Q,addN:(Q,H)=>Q+H,subN:(Q,H)=>Q-H,mulN:(Q,H)=>Q*H,inv:(Q)=>cq(Q,W),sqrt:X.sqrt||((Q)=>V(U,Q)),invertBatch:(Q)=>sa(U,Q),cmov:(Q,H,N)=>N?H:Q,toBytes:(Q)=>G?fq(Q,Z):UW(Q,Z),fromBytes:(Q)=>{if(Q.length!==Z)throw Error(`Fp.fromBytes: expected ${Z}, got ${Q.length}`);return G?mq(Q):i4(Q)}});return Object.freeze(U)}function hk(W){if(typeof W!=="bigint")throw Error("field order must be bigint");let Y=W.toString(2).length;return Math.ceil(Y/8)}function SK(W){let Y=hk(W);return Y+Math.ceil(Y/2)}function bk(W,Y,G=!1){let X=W.length,J=hk(Y),Z=SK(Y);if(X<16||X<Z||X>1024)throw Error(`expected ${Z}-1024 bytes of input, got ${X}`);let V=G?i4(W):mq(W),U=B9(V,Y-$8)+$8;return G?fq(U,J):UW(U,J)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ea=BigInt(0),xK=BigInt(1);function mk(W,Y){let G=(J,Z)=>{let V=Z.negate();return J?V:Z},X=(J)=>{let Z=Math.ceil(Y/J)+1,V=2**(J-1);return{windows:Z,windowSize:V}};return{constTimeNegate:G,unsafeLadder(J,Z){let V=W.ZERO,U=J;while(Z>ea){if(Z&xK)V=V.add(U);U=U.double(),Z>>=xK}return V},precomputeWindow(J,Z){let{windows:V,windowSize:U}=X(Z),Q=[],H=J,N=H;for(let A=0;A<V;A++){N=H,Q.push(N);for(let q=1;q<U;q++)N=N.add(H),Q.push(N);H=N.double()}return Q},wNAF(J,Z,V){let{windows:U,windowSize:Q}=X(J),H=W.ZERO,N=W.BASE,A=BigInt(2**J-1),q=2**J,z=BigInt(J);for(let w=0;w<U;w++){let D=w*Q,T=Number(V&A);if(V>>=z,T>Q)T-=q,V+=xK;let x=D,g=D+Math.abs(T)-1,f=w%2!==0,y=T<0;if(T===0)N=N.add(G(f,Z[x]));else H=H.add(G(y,Z[g]))}return{p:H,f:N}},wNAFCached(J,Z,V,U){let Q=J._WINDOW_SIZE||1,H=Z.get(J);if(!H){if(H=this.precomputeWindow(J,Q),Q!==1)Z.set(J,U(H))}return this.wNAF(Q,H,V)}}}function kK(W){return $K(W.Fp),QW(W,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...FK(W.n,W.nBitLength),...W,...{p:W.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ws(W){let Y=kK(W);QW(Y,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:G,Fp:X,a:J}=Y;if(G){if(!X.eql(J,X.ZERO))throw Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof G!=="object"||typeof G.beta!=="bigint"||typeof G.splitScalar!=="function")throw Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...Y})}var{bytesToNumberBE:Ys,hexToBytes:Gs}=BK,yY={Err:class extends Error{constructor(Y=""){super(Y)}},_parseInt(W){let{Err:Y}=yY;if(W.length<2||W[0]!==2)throw new Y("Invalid signature integer tag");let G=W[1],X=W.subarray(2,G+2);if(!G||X.length!==G)throw new Y("Invalid signature integer: wrong length");if(X[0]&128)throw new Y("Invalid signature integer: negative");if(X[0]===0&&!(X[1]&128))throw new Y("Invalid signature integer: unnecessary leading zero");return{d:Ys(X),l:W.subarray(G+2)}},toSig(W){let{Err:Y}=yY,G=typeof W==="string"?Gs(W):W;if(!(G instanceof Uint8Array))throw Error("ui8a expected");let X=G.length;if(X<2||G[0]!=48)throw new Y("Invalid signature tag");if(G[1]!==X-2)throw new Y("Invalid signature: incorrect length");let{d:J,l:Z}=yY._parseInt(G.subarray(2)),{d:V,l:U}=yY._parseInt(Z);if(U.length)throw new Y("Invalid signature: left bytes after parsing");return{r:J,s:V}},hexFromSig(W){let Y=(H)=>Number.parseInt(H[0],16)&8?"00"+H:H,G=(H)=>{let N=H.toString(16);return N.length&1?`0${N}`:N},X=Y(G(W.s)),J=Y(G(W.r)),Z=X.length/2,V=J.length/2,U=G(Z),Q=G(V);return`30${G(V+Z+4)}02${Q}${J}02${U}${X}`}},r4=BigInt(0),x5=BigInt(1),Vj0=BigInt(2),fk=BigInt(3),Uj0=BigInt(4);function Xs(W){let Y=Ws(W),{Fp:G}=Y,X=Y.toBytes||((w,D,T)=>{let x=D.toAffine();return YJ(Uint8Array.from([4]),G.toBytes(x.x),G.toBytes(x.y))}),J=Y.fromBytes||((w)=>{let D=w.subarray(1),T=G.fromBytes(D.subarray(0,G.BYTES)),x=G.fromBytes(D.subarray(G.BYTES,2*G.BYTES));return{x:T,y:x}});function Z(w){let{a:D,b:T}=Y,x=G.sqr(w),g=G.mul(x,w);return G.add(G.add(g,G.mul(w,D)),T)}if(!G.eql(G.sqr(Y.Gy),Z(Y.Gx)))throw Error("bad generator point: equation left != right");function V(w){return typeof w==="bigint"&&r4<w&&w<Y.n}function U(w){if(!V(w))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function Q(w){let{allowedPrivateKeyLengths:D,nByteLength:T,wrapPrivateKey:x,n:g}=Y;if(D&&typeof w!=="bigint"){if(w instanceof Uint8Array)w=xY(w);if(typeof w!=="string"||!D.includes(w.length))throw Error("Invalid key");w=w.padStart(T*2,"0")}let f;try{f=typeof w==="bigint"?w:i4(I5("private key",w,T))}catch(y){throw Error(`private key must be ${T} bytes, hex or bigint, not ${typeof w}`)}if(x)f=B9(f,g);return U(f),f}let H=new Map;function N(w){if(!(w instanceof A))throw Error("ProjectivePoint expected")}class A{constructor(w,D,T){if(this.px=w,this.py=D,this.pz=T,w==null||!G.isValid(w))throw Error("x required");if(D==null||!G.isValid(D))throw Error("y required");if(T==null||!G.isValid(T))throw Error("z required")}static fromAffine(w){let{x:D,y:T}=w||{};if(!w||!G.isValid(D)||!G.isValid(T))throw Error("invalid affine point");if(w instanceof A)throw Error("projective point not allowed");let x=(g)=>G.eql(g,G.ZERO);if(x(D)&&x(T))return A.ZERO;return new A(D,T,G.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(w){let D=G.invertBatch(w.map((T)=>T.pz));return w.map((T,x)=>T.toAffine(D[x])).map(A.fromAffine)}static fromHex(w){let D=A.fromAffine(J(I5("pointHex",w)));return D.assertValidity(),D}static fromPrivateKey(w){return A.BASE.multiply(Q(w))}_setWindowSize(w){this._WINDOW_SIZE=w,H.delete(this)}assertValidity(){if(this.is0()){if(Y.allowInfinityPoint&&!G.is0(this.py))return;throw Error("bad point: ZERO")}let{x:w,y:D}=this.toAffine();if(!G.isValid(w)||!G.isValid(D))throw Error("bad point: x or y not FE");let T=G.sqr(D),x=Z(w);if(!G.eql(T,x))throw Error("bad point: equation left != right");if(!this.isTorsionFree())throw Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:w}=this.toAffine();if(G.isOdd)return!G.isOdd(w);throw Error("Field doesn't support isOdd")}equals(w){N(w);let{px:D,py:T,pz:x}=this,{px:g,py:f,pz:y}=w,p=G.eql(G.mul(D,y),G.mul(g,x)),b=G.eql(G.mul(T,y),G.mul(f,x));return p&&b}negate(){return new A(this.px,G.neg(this.py),this.pz)}double(){let{a:w,b:D}=Y,T=G.mul(D,fk),{px:x,py:g,pz:f}=this,y=G.ZERO,p=G.ZERO,b=G.ZERO,m=G.mul(x,x),W0=G.mul(g,g),u=G.mul(f,f),J0=G.mul(x,g);return J0=G.add(J0,J0),b=G.mul(x,f),b=G.add(b,b),y=G.mul(w,b),p=G.mul(T,u),p=G.add(y,p),y=G.sub(W0,p),p=G.add(W0,p),p=G.mul(y,p),y=G.mul(J0,y),b=G.mul(T,b),u=G.mul(w,u),J0=G.sub(m,u),J0=G.mul(w,J0),J0=G.add(J0,b),b=G.add(m,m),m=G.add(b,m),m=G.add(m,u),m=G.mul(m,J0),p=G.add(p,m),u=G.mul(g,f),u=G.add(u,u),m=G.mul(u,J0),y=G.sub(y,m),b=G.mul(u,W0),b=G.add(b,b),b=G.add(b,b),new A(y,p,b)}add(w){N(w);let{px:D,py:T,pz:x}=this,{px:g,py:f,pz:y}=w,p=G.ZERO,b=G.ZERO,m=G.ZERO,W0=Y.a,u=G.mul(Y.b,fk),J0=G.mul(D,g),I0=G.mul(T,f),k=G.mul(x,y),l=G.add(D,T),B=G.add(g,f);l=G.mul(l,B),B=G.add(J0,I0),l=G.sub(l,B),B=G.add(D,x);let $=G.add(g,y);return B=G.mul(B,$),$=G.add(J0,k),B=G.sub(B,$),$=G.add(T,x),p=G.add(f,y),$=G.mul($,p),p=G.add(I0,k),$=G.sub($,p),m=G.mul(W0,B),p=G.mul(u,k),m=G.add(p,m),p=G.sub(I0,m),m=G.add(I0,m),b=G.mul(p,m),I0=G.add(J0,J0),I0=G.add(I0,J0),k=G.mul(W0,k),B=G.mul(u,B),I0=G.add(I0,k),k=G.sub(J0,k),k=G.mul(W0,k),B=G.add(B,k),J0=G.mul(I0,B),b=G.add(b,J0),J0=G.mul($,B),p=G.mul(l,p),p=G.sub(p,J0),J0=G.mul(l,I0),m=G.mul($,m),m=G.add(m,J0),new A(p,b,m)}subtract(w){return this.add(w.negate())}is0(){return this.equals(A.ZERO)}wNAF(w){return z.wNAFCached(this,H,w,(D)=>{let T=G.invertBatch(D.map((x)=>x.pz));return D.map((x,g)=>x.toAffine(T[g])).map(A.fromAffine)})}multiplyUnsafe(w){let D=A.ZERO;if(w===r4)return D;if(U(w),w===x5)return this;let{endo:T}=Y;if(!T)return z.unsafeLadder(this,w);let{k1neg:x,k1:g,k2neg:f,k2:y}=T.splitScalar(w),p=D,b=D,m=this;while(g>r4||y>r4){if(g&x5)p=p.add(m);if(y&x5)b=b.add(m);m=m.double(),g>>=x5,y>>=x5}if(x)p=p.negate();if(f)b=b.negate();return b=new A(G.mul(b.px,T.beta),b.py,b.pz),p.add(b)}multiply(w){U(w);let D=w,T,x,{endo:g}=Y;if(g){let{k1neg:f,k1:y,k2neg:p,k2:b}=g.splitScalar(D),{p:m,f:W0}=this.wNAF(y),{p:u,f:J0}=this.wNAF(b);m=z.constTimeNegate(f,m),u=z.constTimeNegate(p,u),u=new A(G.mul(u.px,g.beta),u.py,u.pz),T=m.add(u),x=W0.add(J0)}else{let{p:f,f:y}=this.wNAF(D);T=f,x=y}return A.normalizeZ([T,x])[0]}multiplyAndAddUnsafe(w,D,T){let x=A.BASE,g=(y,p)=>p===r4||p===x5||!y.equals(x)?y.multiplyUnsafe(p):y.multiply(p),f=g(this,D).add(g(w,T));return f.is0()?void 0:f}toAffine(w){let{px:D,py:T,pz:x}=this,g=this.is0();if(w==null)w=g?G.ONE:G.inv(x);let f=G.mul(D,w),y=G.mul(T,w),p=G.mul(x,w);if(g)return{x:G.ZERO,y:G.ZERO};if(!G.eql(p,G.ONE))throw Error("invZ was invalid");return{x:f,y}}isTorsionFree(){let{h:w,isTorsionFree:D}=Y;if(w===x5)return!0;if(D)return D(A,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:w,clearCofactor:D}=Y;if(w===x5)return this;if(D)return D(A,this);return this.multiplyUnsafe(Y.h)}toRawBytes(w=!0){return this.assertValidity(),X(A,this,w)}toHex(w=!0){return xY(this.toRawBytes(w))}}A.BASE=new A(Y.Gx,Y.Gy,G.ONE),A.ZERO=new A(G.ZERO,G.ONE,G.ZERO);let q=Y.nBitLength,z=mk(A,Y.endo?Math.ceil(q/2):q);return{CURVE:Y,ProjectivePoint:A,normPrivateKeyToScalar:Q,weierstrassEquation:Z,isWithinCurveOrder:V}}function Js(W){let Y=kK(W);return QW(Y,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...Y})}function ck(W){let Y=Js(W),{Fp:G,n:X}=Y,J=G.BYTES+1,Z=2*G.BYTES+1;function V($){return r4<$&&$<G.ORDER}function U($){return B9($,X)}function Q($){return cq($,X)}let{ProjectivePoint:H,normPrivateKeyToScalar:N,weierstrassEquation:A,isWithinCurveOrder:q}=Xs({...Y,toBytes($,h,a){let n=h.toAffine(),E=G.toBytes(n.x),P=YJ;if(a)return P(Uint8Array.from([h.hasEvenY()?2:3]),E);else return P(Uint8Array.from([4]),E,G.toBytes(n.y))},fromBytes($){let h=$.length,a=$[0],n=$.subarray(1);if(h===J&&(a===2||a===3)){let E=i4(n);if(!V(E))throw Error("Point is not on curve");let P=A(E),v=G.sqrt(P),M=(v&x5)===x5;if((a&1)===1!==M)v=G.neg(v);return{x:E,y:v}}else if(h===Z&&a===4){let E=G.fromBytes(n.subarray(0,G.BYTES)),P=G.fromBytes(n.subarray(G.BYTES,2*G.BYTES));return{x:E,y:P}}else throw Error(`Point of length ${h} was invalid. Expected ${J} compressed bytes or ${Z} uncompressed bytes`)}}),z=($)=>xY(UW($,Y.nByteLength));function w($){let h=X>>x5;return $>h}function D($){return w($)?U(-$):$}let T=($,h,a)=>i4($.slice(h,a));class x{constructor($,h,a){this.r=$,this.s=h,this.recovery=a,this.assertValidity()}static fromCompact($){let h=Y.nByteLength;return $=I5("compactSignature",$,h*2),new x(T($,0,h),T($,h,2*h))}static fromDER($){let{r:h,s:a}=yY.toSig(I5("DER",$));return new x(h,a)}assertValidity(){if(!q(this.r))throw Error("r must be 0 < r < CURVE.n");if(!q(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit($){return new x(this.r,this.s,$)}recoverPublicKey($){let{r:h,s:a,recovery:n}=this,E=m(I5("msgHash",$));if(n==null||![0,1,2,3].includes(n))throw Error("recovery id invalid");let P=n===2||n===3?h+Y.n:h;if(P>=G.ORDER)throw Error("recovery id 2 or 3 invalid");let v=(n&1)===0?"02":"03",M=H.fromHex(v+z(P)),F=Q(P),c=U(-E*F),t=U(a*F),Y0=H.BASE.multiplyAndAddUnsafe(M,c,t);if(!Y0)throw Error("point at infinify");return Y0.assertValidity(),Y0}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,U(-this.s),this.recovery):this}toDERRawBytes(){return kY(this.toDERHex())}toDERHex(){return yY.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return kY(this.toCompactHex())}toCompactHex(){return z(this.r)+z(this.s)}}let g={isValidPrivateKey($){try{return N($),!0}catch(h){return!1}},normPrivateKeyToScalar:N,randomPrivateKey:()=>{let $=SK(Y.n);return bk(Y.randomBytes($),Y.n)},precompute($=8,h=H.BASE){return h._setWindowSize($),h.multiply(BigInt(3)),h}};function f($,h=!0){return H.fromPrivateKey($).toRawBytes(h)}function y($){let h=$ instanceof Uint8Array,a=typeof $==="string",n=(h||a)&&$.length;if(h)return n===J||n===Z;if(a)return n===2*J||n===2*Z;if($ instanceof H)return!0;return!1}function p($,h,a=!0){if(y($))throw Error("first arg must be private key");if(!y(h))throw Error("second arg must be public key");return H.fromHex(h).multiply(N($)).toRawBytes(a)}let b=Y.bits2int||function($){let h=i4($),a=$.length*8-Y.nBitLength;return a>0?h>>BigInt(a):h},m=Y.bits2int_modN||function($){return U(b($))},W0=CU(Y.nBitLength);function u($){if(typeof $!=="bigint")throw Error("bigint expected");if(!(r4<=$&&$<W0))throw Error(`bigint expected < 2^${Y.nBitLength}`);return UW($,Y.nByteLength)}function J0($,h,a=I0){if(["recovered","canonical"].some((x0)=>(x0 in a)))throw Error("sign() legacy options not supported");let{hash:n,randomBytes:E}=Y,{lowS:P,prehash:v,extraEntropy:M}=a;if(P==null)P=!0;if($=I5("msgHash",$),v)$=I5("prehashed msgHash",n($));let F=m($),c=N(h),t=[u(c),u(F)];if(M!=null){let x0=M===!0?E(G.BYTES):M;t.push(I5("extraEntropy",x0))}let Y0=YJ(...t),$0=F;function S0(x0){let D1=b(x0);if(!q(D1))return;let b0=Q(D1),Q0=H.BASE.multiply(D1).toAffine(),O0=U(Q0.x);if(O0===r4)return;let y0=U(b0*U($0+O0*c));if(y0===r4)return;let X0=(Q0.x===O0?0:2)|Number(Q0.y&x5),D0=y0;if(P&&w(y0))D0=D(y0),X0^=1;return new x(O0,D0,X0)}return{seed:Y0,k2sig:S0}}let I0={lowS:Y.lowS,prehash:!1},k={lowS:Y.lowS,prehash:!1};function l($,h,a=I0){let{seed:n,k2sig:E}=J0($,h,a),P=Y;return LK(P.hash.outputLen,P.nByteLength,P.hmac)(n,E)}H.BASE._setWindowSize(8);function B($,h,a,n=k){let E=$;if(h=I5("msgHash",h),a=I5("publicKey",a),"strict"in n)throw Error("options.strict was renamed to lowS");let{lowS:P,prehash:v}=n,M=void 0,F;try{if(typeof E==="string"||E instanceof Uint8Array)try{M=x.fromDER(E)}catch(Q0){if(!(Q0 instanceof yY.Err))throw Q0;M=x.fromCompact(E)}else if(typeof E==="object"&&typeof E.r==="bigint"&&typeof E.s==="bigint"){let{r:Q0,s:O0}=E;M=new x(Q0,O0)}else throw Error("PARSE");F=H.fromHex(a)}catch(Q0){if(Q0.message==="PARSE")throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&M.hasHighS())return!1;if(v)h=Y.hash(h);let{r:c,s:t}=M,Y0=m(h),$0=Q(t),S0=U(Y0*$0),x0=U(c*$0),D1=H.BASE.multiplyAndAddUnsafe(F,S0,x0)?.toAffine();if(!D1)return!1;return U(D1.x)===c}return{CURVE:Y,getPublicKey:f,getSharedSecret:p,sign:l,verify:B,ProjectivePoint:H,Signature:x,utils:g}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Zs(W){return{hash:W,hmac:(Y,...G)=>DU(W,Y,px(...G)),randomBytes:lx}}function pk(W,Y){let G=(X)=>ck({...W,...Zs(X)});return Object.freeze({...G(Y),create:G})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var ok=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),lk=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Vs=BigInt(1),_K=BigInt(2),dk=(W,Y)=>(W+Y/_K)/Y;function Us(W){let Y=ok,G=BigInt(3),X=BigInt(6),J=BigInt(11),Z=BigInt(22),V=BigInt(23),U=BigInt(44),Q=BigInt(88),H=W*W*W%Y,N=H*H*W%Y,A=z5(N,G,Y)*N%Y,q=z5(A,G,Y)*N%Y,z=z5(q,_K,Y)*H%Y,w=z5(z,J,Y)*z%Y,D=z5(w,Z,Y)*w%Y,T=z5(D,U,Y)*D%Y,x=z5(T,Q,Y)*T%Y,g=z5(x,U,Y)*D%Y,f=z5(g,G,Y)*N%Y,y=z5(f,V,Y)*w%Y,p=z5(y,X,Y)*H%Y,b=z5(p,_K,Y);if(!yK.eql(yK.sqr(b),W))throw Error("Cannot find square root");return b}var yK=uk(ok,void 0,void 0,{sqrt:Us}),a4=pk({a:BigInt(0),b:BigInt(7),Fp:yK,n:lk,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:(W)=>{let Y=lk,G=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),X=-Vs*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),J=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),Z=G,V=BigInt("0x100000000000000000000000000000000"),U=dk(Z*W,Y),Q=dk(-X*W,Y),H=B9(W-U*G-Q*J,Y),N=B9(-U*X-Q*Z,Y),A=H>V,q=N>V;if(A)H=Y-H;if(q)N=Y-N;if(H>V||N>V)throw Error("splitScalar: Endomorphism failed, k="+W);return{k1neg:A,k1:H,k2neg:q,k2:N}}}},KU),jj0=BigInt(0);var Oj0=a4.ProjectivePoint;var vK="0x0000000000000000000000000000000000000000";var pq="0x0000000000000000000000000000000000000000000000000000000000000000";var gK=`\x19Ethereum Signed Message:
|
|
249
|
+
`;var nk=BigInt(0),ik=BigInt(1),rk=BigInt(2),ak=BigInt(27),sk=BigInt(28),lq=BigInt(35),GJ={};function tk(W){return A5(N8(W),32)}class K8{#W;#Y;#G;#X;get r(){return this.#W}set r(W){r(o4(W)===32,"invalid r","value",W),this.#W=C0(W)}get s(){return r(parseInt(this.#Y.substring(0,3))<8,"non-canonical s; use ._s","s",this.#Y),this.#Y}set s(W){r(o4(W)===32,"invalid s","value",W),this.#Y=C0(W)}get _s(){return this.#Y}isValid(){return parseInt(this.#Y.substring(0,3))<8}get v(){return this.#G}set v(W){let Y=r8(W,"value");r(Y===27||Y===28,"invalid v","v",W),this.#G=Y}get networkV(){return this.#X}get legacyChainId(){let W=this.networkV;if(W==null)return null;return K8.getChainId(W)}get yParity(){return this.v===27?0:1}get yParityAndS(){let W=B0(this.s);if(this.yParity)W[0]|=128;return C0(W)}get compactSerialized(){return t1([this.r,this.yParityAndS])}get serialized(){return t1([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(W,Y,G,X){d4(W,GJ,"Signature"),this.#W=Y,this.#Y=G,this.#G=X,this.#X=null}[Symbol.for("nodejs.util.inspect.custom")](){return`Signature { r: "${this.r}", s: "${this._s}"${this.isValid()?"":', valid: "false"'}, yParity: ${this.yParity}, networkV: ${this.networkV} }`}clone(){let W=new K8(GJ,this.r,this._s,this.v);if(this.networkV)W.#X=this.networkV;return W}toJSON(){let W=this.networkV;return{_type:"signature",networkV:W!=null?W.toString():null,r:this.r,s:this._s,v:this.v}}static getChainId(W){let Y=u1(W,"v");if(Y==ak||Y==sk)return nk;return r(Y>=lq,"invalid EIP-155 v","v",W),(Y-lq)/rk}static getChainIdV(W,Y){return u1(W)*rk+BigInt(35+Y-27)}static getNormalizedV(W){let Y=u1(W);if(Y===nk||Y===ak)return 27;if(Y===ik||Y===sk)return 28;return r(Y>=lq,"invalid v","v",W),Y&ik?27:28}static from(W){function Y(Q,H){r(Q,H,"signature",W)}if(W==null)return new K8(GJ,pq,pq,27);if(typeof W==="string"){let Q=B0(W,"signature");if(Q.length===64){let H=C0(Q.slice(0,32)),N=Q.slice(32,64),A=N[0]&128?28:27;return N[0]&=127,new K8(GJ,H,C0(N),A)}if(Q.length===65){let H=C0(Q.slice(0,32)),N=C0(Q.slice(32,64)),A=K8.getNormalizedV(Q[64]);return new K8(GJ,H,N,A)}Y(!1,"invalid raw signature length")}if(W instanceof K8)return W.clone();let G=W.r;Y(G!=null,"missing r");let X=tk(G),J=function(Q,H){if(Q!=null)return tk(Q);if(H!=null){Y(R9(H,32),"invalid yParityAndS");let N=B0(H);return N[0]&=127,C0(N)}Y(!1,"missing s")}(W.s,W.yParityAndS),{networkV:Z,v:V}=function(Q,H,N){if(Q!=null){let A=u1(Q);return{networkV:A>=lq?A:void 0,v:K8.getNormalizedV(A)}}if(H!=null)return Y(R9(H,32),"invalid yParityAndS"),{v:B0(H)[0]&128?28:27};if(N!=null){switch(r8(N,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}Y(!1,"invalid yParity")}Y(!1,"missing v")}(W.v,W.yParityAndS,W.yParity),U=new K8(GJ,X,J,V);if(Z)U.#X=Z;return Y(W.yParity==null||r8(W.yParity,"sig.yParity")===U.yParity,"yParity mismatch"),Y(W.yParityAndS==null||W.yParityAndS===U.yParityAndS,"yParityAndS mismatch"),U}}class o8{#W;constructor(W){r(o4(W)===32,"invalid private key","privateKey","[REDACTED]"),this.#W=C0(W)}get privateKey(){return this.#W}get publicKey(){return o8.computePublicKey(this.#W)}get compressedPublicKey(){return o8.computePublicKey(this.#W,!0)}sign(W){r(o4(W)===32,"invalid digest length","digest",W);let Y=a4.sign(Z7(W),Z7(this.#W),{lowS:!0});return K8.from({r:V7(Y.r,32),s:V7(Y.s,32),v:Y.recovery?28:27})}computeSharedSecret(W){let Y=o8.computePublicKey(W);return C0(a4.getSharedSecret(Z7(this.#W),B0(Y),!1))}static computePublicKey(W,Y){let G=B0(W,"key");if(G.length===32){let J=a4.getPublicKey(G,!!Y);return C0(J)}if(G.length===64){let J=new Uint8Array(65);J[0]=4,J.set(G,1),G=J}let X=a4.ProjectivePoint.fromHex(G);return C0(X.toRawBytes(Y))}static recoverPublicKey(W,Y){r(o4(W)===32,"invalid digest length","digest",W);let G=K8.from(Y),X=a4.Signature.fromCompact(Z7(t1([G.r,G.s])));X=X.addRecoveryBit(G.yParity);let J=X.recoverPublicKey(Z7(W));return r(J!=null,"invalid signature for digest","signature",Y),"0x"+J.toHex(!1)}static addPoints(W,Y,G){let X=a4.ProjectivePoint.fromHex(o8.computePublicKey(W).substring(2)),J=a4.ProjectivePoint.fromHex(o8.computePublicKey(Y).substring(2));return"0x"+X.add(J).toHex(!!G)}}var Qs=BigInt(0),Hs=BigInt(36);function ek(W){W=W.toLowerCase();let Y=W.substring(2).split(""),G=new Uint8Array(40);for(let J=0;J<40;J++)G[J]=Y[J].charCodeAt(0);let X=B0(X8(G));for(let J=0;J<40;J+=2){if(X[J>>1]>>4>=8)Y[J]=Y[J].toUpperCase();if((X[J>>1]&15)>=8)Y[J+1]=Y[J+1].toUpperCase()}return"0x"+Y.join("")}var uK={};for(let W=0;W<10;W++)uK[String(W)]=String(W);for(let W=0;W<26;W++)uK[String.fromCharCode(65+W)]=String(10+W);var W_=15;function Ns(W){W=W.toUpperCase(),W=W.substring(4)+W.substring(0,2)+"00";let Y=W.split("").map((X)=>{return uK[X]}).join("");while(Y.length>=W_){let X=Y.substring(0,W_);Y=parseInt(X,10)%97+Y.substring(X.length)}let G=String(98-parseInt(Y,10)%97);while(G.length<2)G="0"+G;return G}var qs=function(){let W={};for(let Y=0;Y<36;Y++){let G="0123456789abcdefghijklmnopqrstuvwxyz"[Y];W[G]=BigInt(Y)}return W}();function As(W){W=W.toLowerCase();let Y=Qs;for(let G=0;G<W.length;G++)Y=Y*Hs+qs[W[G]];return Y}function f1(W){if(r(typeof W==="string","invalid address","address",W),W.match(/^(0x)?[0-9a-fA-F]{40}$/)){if(!W.startsWith("0x"))W="0x"+W;let Y=ek(W);return r(!W.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||Y===W,"bad address checksum","address",W),Y}if(W.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){r(W.substring(2,4)===Ns(W),"bad icap checksum","address",W);let Y=As(W.substring(4)).toString(16);while(Y.length<40)Y="0"+Y;return ek("0x"+Y)}r(!1,"invalid address","address",W)}function bK(W){return W&&typeof W.getAddress==="function"}async function hK(W,Y){let G=await Y;if(G==null||G==="0x0000000000000000000000000000000000000000")X1(typeof W!=="string","unconfigured name","UNCONFIGURED_NAME",{value:W}),r(!1,"invalid AddressLike value; did not resolve to a value address","target",W);return f1(G)}function s4(W,Y){if(typeof W==="string"){if(W.match(/^0x[0-9a-f]{40}$/i))return f1(W);return X1(Y!=null,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),hK(W,Y.resolveName(W))}else if(bK(W))return hK(W,W.getAddress());else if(W&&typeof W.then==="function")return hK(W,W);r(!1,"unsupported addressable value","target",W)}function mK(W,Y){return{address:f1(W),storageKeys:Y.map((G,X)=>{return r(R9(G,32),"invalid slot",`storageKeys[${X}]`,G),G.toLowerCase()})}}function vY(W){if(Array.isArray(W))return W.map((G,X)=>{if(Array.isArray(G))return r(G.length===2,"invalid slot set",`value[${X}]`,G),mK(G[0],G[1]);return r(G!=null&&typeof G==="object","invalid address-slot set","value",W),mK(G.address,G.storageKeys)});r(W!=null&&typeof W==="object","invalid access list","value",W);let Y=Object.keys(W).map((G)=>{let X=W[G].reduce((J,Z)=>{return J[Z]=!0,J},{});return mK(G,Object.keys(X).sort())});return Y.sort((G,X)=>G.address.localeCompare(X.address)),Y}function Y_(W){return{address:f1(W.address),nonce:u1(W.nonce!=null?W.nonce:0),chainId:u1(W.chainId!=null?W.chainId:0),signature:K8.from(W.signature)}}function t4(W){let Y;if(typeof W==="string")Y=o8.computePublicKey(W,!1);else Y=W.publicKey;return f1(X8("0x"+Y.substring(4)).substring(26))}function TU(W,Y){return t4(o8.recoverPublicKey(W,Y))}var a8=BigInt(0),ws=BigInt(2),js=BigInt(27),Os=BigInt(28),Ks=BigInt(35),Ds=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),fK=131072;function Cs(W){return{blobToKzgCommitment:(X)=>{if("computeBlobProof"in W){if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return B0(W.blobToKzgCommitment(C0(X)))}else if("blobToKzgCommitment"in W&&typeof W.blobToKzgCommitment==="function")return B0(W.blobToKzgCommitment(X));if("blobToKZGCommitment"in W&&typeof W.blobToKZGCommitment==="function")return B0(W.blobToKZGCommitment(C0(X)));r(!1,"unsupported KZG library","kzg",W)},computeBlobKzgProof:(X,J)=>{if("computeBlobProof"in W&&typeof W.computeBlobProof==="function")return B0(W.computeBlobProof(C0(X),C0(J)));if("computeBlobKzgProof"in W&&typeof W.computeBlobKzgProof==="function")return W.computeBlobKzgProof(X,J);if("computeBlobKZGProof"in W&&typeof W.computeBlobKZGProof==="function")return B0(W.computeBlobKZGProof(C0(X),C0(J)));r(!1,"unsupported KZG library","kzg",W)}}}function G_(W,Y){let G=W.toString(16);while(G.length<2)G="0"+G;return G+=L9(Y).substring(4),"0x"+G}function XJ(W){if(W==="0x")return null;return f1(W)}function dq(W,Y){try{return vY(W)}catch(G){r(!1,G.message,Y,W)}}function Ts(W,Y){try{if(!Array.isArray(W))throw Error("authorizationList: invalid array");let G=[];for(let X=0;X<W.length;X++){let J=W[X];if(!Array.isArray(J))throw Error(`authorization[${X}]: invalid array`);if(J.length!==6)throw Error(`authorization[${X}]: wrong length`);if(!J[1])throw Error(`authorization[${X}]: null address`);G.push({address:XJ(J[1]),nonce:J8(J[2],"nonce"),chainId:J8(J[0],"chainId"),signature:K8.from({yParity:gY(J[3],"yParity"),r:A5(J[4],32),s:A5(J[5],32)})})}return G}catch(G){r(!1,G.message,Y,W)}}function gY(W,Y){if(W==="0x")return 0;return r8(W,Y)}function J8(W,Y){if(W==="0x")return a8;let G=u1(W,Y);return r(G<=Ds,"value exceeds uint size",Y,G),G}function h1(W,Y){let G=u1(W,"value"),X=N8(G);return r(X.length<=32,"value too large",`tx.${Y}`,G),X}function oq(W){return vY(W).map((Y)=>[Y.address,Y.storageKeys])}function Rs(W){return W.map((Y)=>{return[h1(Y.chainId,"chainId"),Y.address,h1(Y.nonce,"nonce"),h1(Y.signature.yParity,"yParity"),N8(Y.signature.r),N8(Y.signature.s)]})}function Ms(W,Y){r(Array.isArray(W),`invalid ${Y}`,"value",W);for(let G=0;G<W.length;G++)r(R9(W[G],32),"invalid ${ param } hash",`value[${G}]`,W[G]);return W}function Ps(W){let Y=WW(W);r(Array.isArray(Y)&&(Y.length===9||Y.length===6),"invalid field count for legacy transaction","data",W);let G={type:0,nonce:gY(Y[0],"nonce"),gasPrice:J8(Y[1],"gasPrice"),gasLimit:J8(Y[2],"gasLimit"),to:XJ(Y[3]),value:J8(Y[4],"value"),data:C0(Y[5]),chainId:a8};if(Y.length===6)return G;let X=J8(Y[6],"v"),J=J8(Y[7],"r"),Z=J8(Y[8],"s");if(J===a8&&Z===a8)G.chainId=X;else{let V=(X-Ks)/ws;if(V<a8)V=a8;G.chainId=V,r(V!==a8||(X===js||X===Os),"non-canonical legacy v","v",Y[6]),G.signature=K8.from({r:A5(Y[7],32),s:A5(Y[8],32),v:X})}return G}function Ls(W,Y){let G=[h1(W.nonce,"nonce"),h1(W.gasPrice||0,"gasPrice"),h1(W.gasLimit,"gasLimit"),W.to||"0x",h1(W.value,"value"),W.data],X=a8;if(W.chainId!=a8)X=u1(W.chainId,"tx.chainId"),r(!Y||Y.networkV==null||Y.legacyChainId===X,"tx.chainId/sig.v mismatch","sig",Y);else if(W.signature){let Z=W.signature.legacyChainId;if(Z!=null)X=Z}if(!Y){if(X!==a8)G.push(N8(X)),G.push("0x"),G.push("0x");return $5(G)}let J=BigInt(27+Y.yParity);if(X!==a8)J=K8.getChainIdV(X,Y.v);else if(BigInt(Y.v)!==J)r(!1,"tx.chainId/sig.v mismatch","sig",Y);return G.push(N8(J)),G.push(N8(Y.r)),G.push(N8(Y.s)),$5(G)}function nq(W,Y){let G;try{if(G=gY(Y[0],"yParity"),G!==0&&G!==1)throw Error("bad yParity")}catch(V){r(!1,"invalid yParity","yParity",Y[0])}let X=A5(Y[1],32),J=A5(Y[2],32),Z=K8.from({r:X,s:J,yParity:G});W.signature=Z}function Bs(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===9||Y.length===12),"invalid field count for transaction type: 2","data",C0(W));let G={type:2,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList")};if(Y.length===9)return G;return nq(G,Y.slice(9)),G}function Es(W,Y){let G=[h1(W.chainId,"chainId"),h1(W.nonce,"nonce"),h1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),h1(W.maxFeePerGas||0,"maxFeePerGas"),h1(W.gasLimit,"gasLimit"),W.to||"0x",h1(W.value,"value"),W.data,oq(W.accessList||[])];if(Y)G.push(h1(Y.yParity,"yParity")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x02",$5(G)])}function $s(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===8||Y.length===11),"invalid field count for transaction type: 1","data",C0(W));let G={type:1,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),gasPrice:J8(Y[2],"gasPrice"),gasLimit:J8(Y[3],"gasLimit"),to:XJ(Y[4]),value:J8(Y[5],"value"),data:C0(Y[6]),accessList:dq(Y[7],"accessList")};if(Y.length===8)return G;return nq(G,Y.slice(8)),G}function Fs(W,Y){let G=[h1(W.chainId,"chainId"),h1(W.nonce,"nonce"),h1(W.gasPrice||0,"gasPrice"),h1(W.gasLimit,"gasLimit"),W.to||"0x",h1(W.value,"value"),W.data,oq(W.accessList||[])];if(Y)G.push(h1(Y.yParity,"recoveryParam")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x01",$5(G)])}function Ss(W){let Y=WW(B0(W).slice(1)),G="3",X=null;if(Y.length===4&&Array.isArray(Y[0])){G="3 (network format)";let Z=Y[1],V=Y[2],U=Y[3];r(Array.isArray(Z),"invalid network format: blobs not an array","fields[1]",Z),r(Array.isArray(V),"invalid network format: commitments not an array","fields[2]",V),r(Array.isArray(U),"invalid network format: proofs not an array","fields[3]",U),r(Z.length===V.length,"invalid network format: blobs/commitments length mismatch","fields",Y),r(Z.length===U.length,"invalid network format: blobs/proofs length mismatch","fields",Y),X=[];for(let Q=0;Q<Y[1].length;Q++)X.push({data:Z[Q],commitment:V[Q],proof:U[Q]});Y=Y[0]}r(Array.isArray(Y)&&(Y.length===11||Y.length===14),`invalid field count for transaction type: ${G}`,"data",C0(W));let J={type:3,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList"),maxFeePerBlobGas:J8(Y[9],"maxFeePerBlobGas"),blobVersionedHashes:Y[10]};if(X)J.blobs=X;r(J.to!=null,`invalid address for transaction type: ${G}`,"data",W),r(Array.isArray(J.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",W);for(let Z=0;Z<J.blobVersionedHashes.length;Z++)r(R9(J.blobVersionedHashes[Z],32),`invalid blobVersionedHash at index ${Z}: must be length 32`,"data",W);if(Y.length===11)return J;return nq(J,Y.slice(11)),J}function xs(W,Y,G){let X=[h1(W.chainId,"chainId"),h1(W.nonce,"nonce"),h1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),h1(W.maxFeePerGas||0,"maxFeePerGas"),h1(W.gasLimit,"gasLimit"),W.to||vK,h1(W.value,"value"),W.data,oq(W.accessList||[]),h1(W.maxFeePerBlobGas||0,"maxFeePerBlobGas"),Ms(W.blobVersionedHashes||[],"blobVersionedHashes")];if(Y){if(X.push(h1(Y.yParity,"yParity")),X.push(N8(Y.r)),X.push(N8(Y.s)),G)return t1(["0x03",$5([X,G.map((J)=>J.data),G.map((J)=>J.commitment),G.map((J)=>J.proof)])])}return t1(["0x03",$5(X)])}function ks(W){let Y=WW(B0(W).slice(1));r(Array.isArray(Y)&&(Y.length===10||Y.length===13),"invalid field count for transaction type: 4","data",C0(W));let G={type:4,chainId:J8(Y[0],"chainId"),nonce:gY(Y[1],"nonce"),maxPriorityFeePerGas:J8(Y[2],"maxPriorityFeePerGas"),maxFeePerGas:J8(Y[3],"maxFeePerGas"),gasPrice:null,gasLimit:J8(Y[4],"gasLimit"),to:XJ(Y[5]),value:J8(Y[6],"value"),data:C0(Y[7]),accessList:dq(Y[8],"accessList"),authorizationList:Ts(Y[9],"authorizationList")};if(Y.length===10)return G;return nq(G,Y.slice(10)),G}function _s(W,Y){let G=[h1(W.chainId,"chainId"),h1(W.nonce,"nonce"),h1(W.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),h1(W.maxFeePerGas||0,"maxFeePerGas"),h1(W.gasLimit,"gasLimit"),W.to||"0x",h1(W.value,"value"),W.data,oq(W.accessList||[]),Rs(W.authorizationList||[])];if(Y)G.push(h1(Y.yParity,"yParity")),G.push(N8(Y.r)),G.push(N8(Y.s));return t1(["0x04",$5(G)])}class t9{#W;#Y;#G;#X;#Q;#H;#N;#q;#A;#I;#z;#w;#U;#Z;#J;#V;#j;get type(){return this.#W}set type(W){switch(W){case null:this.#W=null;break;case 0:case"legacy":this.#W=0;break;case 1:case"berlin":case"eip-2930":this.#W=1;break;case 2:case"london":case"eip-1559":this.#W=2;break;case 3:case"cancun":case"eip-4844":this.#W=3;break;case 4:case"pectra":case"eip-7702":this.#W=4;break;default:r(!1,"unsupported transaction type","type",W)}}get typeName(){switch(this.type){case 0:return"legacy";case 1:return"eip-2930";case 2:return"eip-1559";case 3:return"eip-4844";case 4:return"eip-7702"}return null}get to(){let W=this.#Y;if(W==null&&this.type===3)return vK;return W}set to(W){this.#Y=W==null?null:f1(W)}get nonce(){return this.#X}set nonce(W){this.#X=r8(W,"value")}get gasLimit(){return this.#Q}set gasLimit(W){this.#Q=u1(W)}get gasPrice(){let W=this.#H;if(W==null&&(this.type===0||this.type===1))return a8;return W}set gasPrice(W){this.#H=W==null?null:u1(W,"gasPrice")}get maxPriorityFeePerGas(){let W=this.#N;if(W==null){if(this.type===2||this.type===3)return a8;return null}return W}set maxPriorityFeePerGas(W){this.#N=W==null?null:u1(W,"maxPriorityFeePerGas")}get maxFeePerGas(){let W=this.#q;if(W==null){if(this.type===2||this.type===3)return a8;return null}return W}set maxFeePerGas(W){this.#q=W==null?null:u1(W,"maxFeePerGas")}get data(){return this.#G}set data(W){this.#G=C0(W)}get value(){return this.#A}set value(W){this.#A=u1(W,"value")}get chainId(){return this.#I}set chainId(W){this.#I=u1(W)}get signature(){return this.#z||null}set signature(W){this.#z=W==null?null:K8.from(W)}get accessList(){let W=this.#w||null;if(W==null){if(this.type===1||this.type===2||this.type===3)return[];return null}return W}set accessList(W){this.#w=W==null?null:vY(W)}get authorizationList(){let W=this.#j||null;if(W==null){if(this.type===4)return[]}return W}set authorizationList(W){this.#j=W==null?null:W.map((Y)=>Y_(Y))}get maxFeePerBlobGas(){let W=this.#U;if(W==null&&this.type===3)return a8;return W}set maxFeePerBlobGas(W){this.#U=W==null?null:u1(W,"maxFeePerBlobGas")}get blobVersionedHashes(){let W=this.#Z;if(W==null&&this.type===3)return[];return W}set blobVersionedHashes(W){if(W!=null){r(Array.isArray(W),"blobVersionedHashes must be an Array","value",W),W=W.slice();for(let Y=0;Y<W.length;Y++)r(R9(W[Y],32),"invalid blobVersionedHash",`value[${Y}]`,W[Y])}this.#Z=W}get blobs(){if(this.#V==null)return null;return this.#V.map((W)=>Object.assign({},W))}set blobs(W){if(W==null){this.#V=null;return}let Y=[],G=[];for(let X=0;X<W.length;X++){let J=W[X];if(n7(J)){X1(this.#J,"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let Z=B0(J);if(r(Z.length<=fK,"blob is too large",`blobs[${X}]`,J),Z.length!==fK){let Q=new Uint8Array(fK);Q.set(Z),Z=Q}let V=this.#J.blobToKzgCommitment(Z),U=C0(this.#J.computeBlobKzgProof(Z,V));Y.push({data:C0(Z),commitment:C0(V),proof:U}),G.push(G_(1,V))}else{let Z=C0(J.commitment);Y.push({data:C0(J.data),commitment:Z,proof:C0(J.proof)}),G.push(G_(1,Z))}}this.#V=Y,this.#Z=G}get kzg(){return this.#J}set kzg(W){if(W==null)this.#J=null;else this.#J=Cs(W)}constructor(){this.#W=null,this.#Y=null,this.#X=0,this.#Q=a8,this.#H=null,this.#N=null,this.#q=null,this.#G="0x",this.#A=a8,this.#I=a8,this.#z=null,this.#w=null,this.#U=null,this.#Z=null,this.#J=null,this.#V=null,this.#j=null}get hash(){if(this.signature==null)return null;return X8(this.#O(!0,!1))}get unsignedHash(){return X8(this.unsignedSerialized)}get from(){if(this.signature==null)return null;return TU(this.unsignedHash,this.signature)}get fromPublicKey(){if(this.signature==null)return null;return o8.recoverPublicKey(this.unsignedHash,this.signature)}isSigned(){return this.signature!=null}#O(W,Y){X1(!W||this.signature!=null,"cannot serialize unsigned transaction; maybe you meant .unsignedSerialized","UNSUPPORTED_OPERATION",{operation:".serialized"});let G=W?this.signature:null;switch(this.inferType()){case 0:return Ls(this,G);case 1:return Fs(this,G);case 2:return Es(this,G);case 3:return xs(this,G,Y?this.blobs:null);case 4:return _s(this,G)}X1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})}get serialized(){return this.#O(!0,!0)}get unsignedSerialized(){return this.#O(!1,!1)}inferType(){let W=this.inferTypes();if(W.indexOf(2)>=0)return 2;return W.pop()}inferTypes(){let W=this.gasPrice!=null,Y=this.maxFeePerGas!=null||this.maxPriorityFeePerGas!=null,G=this.accessList!=null,X=this.#U!=null||this.#Z;if(this.maxFeePerGas!=null&&this.maxPriorityFeePerGas!=null)X1(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this});X1(!Y||this.type!==0&&this.type!==1,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),X1(this.type!==0||!G,"legacy transaction cannot have accessList","BAD_DATA",{value:this});let J=[];if(this.type!=null)J.push(this.type);else if(this.authorizationList&&this.authorizationList.length)J.push(4);else if(Y)J.push(2);else if(W){if(J.push(1),!G)J.push(0)}else if(G)J.push(1),J.push(2);else if(X&&this.to)J.push(3);else J.push(0),J.push(1),J.push(2),J.push(3);return J.sort(),J}isLegacy(){return this.type===0}isBerlin(){return this.type===1}isLondon(){return this.type===2}isCancun(){return this.type===3}clone(){return t9.from(this)}toJSON(){let W=(Y)=>{if(Y==null)return null;return Y.toString()};return{type:this.type,to:this.to,data:this.data,nonce:this.nonce,gasLimit:W(this.gasLimit),gasPrice:W(this.gasPrice),maxPriorityFeePerGas:W(this.maxPriorityFeePerGas),maxFeePerGas:W(this.maxFeePerGas),value:W(this.value),chainId:W(this.chainId),sig:this.signature?this.signature.toJSON():null,accessList:this.accessList}}static from(W){if(W==null)return new t9;if(typeof W==="string"){let G=B0(W);if(G[0]>=127)return t9.from(Ps(G));switch(G[0]){case 1:return t9.from($s(G));case 2:return t9.from(Bs(G));case 3:return t9.from(Ss(G));case 4:return t9.from(ks(G))}X1(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}let Y=new t9;if(W.type!=null)Y.type=W.type;if(W.to!=null)Y.to=W.to;if(W.nonce!=null)Y.nonce=W.nonce;if(W.gasLimit!=null)Y.gasLimit=W.gasLimit;if(W.gasPrice!=null)Y.gasPrice=W.gasPrice;if(W.maxPriorityFeePerGas!=null)Y.maxPriorityFeePerGas=W.maxPriorityFeePerGas;if(W.maxFeePerGas!=null)Y.maxFeePerGas=W.maxFeePerGas;if(W.maxFeePerBlobGas!=null)Y.maxFeePerBlobGas=W.maxFeePerBlobGas;if(W.data!=null)Y.data=W.data;if(W.value!=null)Y.value=W.value;if(W.chainId!=null)Y.chainId=W.chainId;if(W.signature!=null)Y.signature=K8.from(W.signature);if(W.accessList!=null)Y.accessList=W.accessList;if(W.authorizationList!=null)Y.authorizationList=W.authorizationList;if(W.blobVersionedHashes!=null)Y.blobVersionedHashes=W.blobVersionedHashes;if(W.kzg!=null)Y.kzg=W.kzg;if(W.blobs!=null)Y.blobs=W.blobs;if(W.hash!=null)r(Y.isSigned(),"unsigned transaction cannot define '.hash'","tx",W),r(Y.hash===W.hash,"hash mismatch","tx",W);if(W.from!=null)r(Y.isSigned(),"unsigned transaction cannot define '.from'","tx",W),r(Y.from.toLowerCase()===(W.from||"").toLowerCase(),"from mismatch","tx",W);return Y}}function iq(W){return r(typeof W.address==="string","invalid address for hashAuthorization","auth.address",W),X8(t1(["0x05",$5([W.chainId!=null?N8(W.chainId):"0x",f1(W.address),W.nonce!=null?N8(W.nonce):"0x"])]))}function e4(W){return X8(M9(W))}function RU(W){if(typeof W==="string")W=M9(W);return X8(t1([M9(gK),M9(String(W.length)),W]))}function rq(W,Y){let G=RU(W);return TU(G,Y)}var V_=new Uint8Array(32);V_.fill(0);var ys=BigInt(-1),U_=BigInt(0),Q_=BigInt(1),vs=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function gs(W){let Y=B0(W),G=Y.length%32;if(G)return t1([Y,V_.slice(G)]);return C0(Y)}var us=V7(Q_,32),hs=V7(U_,32),X_={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},cK=["name","version","chainId","verifyingContract","salt"];function J_(W){return function(Y){return r(typeof Y==="string",`invalid domain value for ${JSON.stringify(W)}`,`domain.${W}`,Y),Y}}var bs={name:J_("name"),version:J_("version"),chainId:function(W){let Y=u1(W,"domain.chainId");if(r(Y>=0,"invalid chain ID","domain.chainId",W),Number.isSafeInteger(Y))return Number(Y);return Mq(Y)},verifyingContract:function(W){try{return f1(W).toLowerCase()}catch(Y){}r(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",W)},salt:function(W){let Y=B0(W,"domain.salt");return r(Y.length===32,'invalid domain value "salt"',"domain.salt",W),C0(Y)}};function pK(W){{let Y=W.match(/^(u?)int(\d+)$/);if(Y){let G=Y[1]==="",X=parseInt(Y[2]);r(X%8===0&&X!==0&&X<=256&&Y[2]===String(X),"invalid numeric width","type",W);let J=Rq(vs,G?X-1:X),Z=G?(J+Q_)*ys:U_;return function(V){let U=u1(V,"value");return r(U>=Z&&U<=J,`value out-of-bounds for ${W}`,"value",U),V7(G?Tq(U,256):U,32)}}}{let Y=W.match(/^bytes(\d+)$/);if(Y){let G=parseInt(Y[1]);return r(G!==0&&G<=32&&Y[1]===String(G),"invalid bytes width","type",W),function(X){let J=B0(X);return r(J.length===G,`invalid length for ${W}`,"value",X),gs(X)}}}switch(W){case"address":return function(Y){return A5(f1(Y),32)};case"bool":return function(Y){return!Y?hs:us};case"bytes":return function(Y){return X8(Y)};case"string":return function(Y){return e4(Y)}}return null}function Z_(W,Y){return`${W}(${Y.map(({name:G,type:X})=>X+" "+G).join(",")})`}function aq(W){let Y=W.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);if(Y)return{base:Y[1],index:Y[2]+Y[4],array:{base:Y[1],prefix:Y[1]+Y[2],count:Y[5]?parseInt(Y[5]):-1}};return{base:W}}class E9{primaryType;#W;get types(){return JSON.parse(this.#W)}#Y;#G;constructor(W){this.#Y=new Map,this.#G=new Map;let Y=new Map,G=new Map,X=new Map,J={};Object.keys(W).forEach((U)=>{J[U]=W[U].map(({name:Q,type:H})=>{let{base:N,index:A}=aq(H);if(N==="int"&&!W.int)N="int256";if(N==="uint"&&!W.uint)N="uint256";return{name:Q,type:N+(A||"")}}),Y.set(U,new Set),G.set(U,[]),X.set(U,new Set)}),this.#W=JSON.stringify(J);for(let U in J){let Q=new Set;for(let H of J[U]){r(!Q.has(H.name),`duplicate variable name ${JSON.stringify(H.name)} in ${JSON.stringify(U)}`,"types",W),Q.add(H.name);let N=aq(H.type).base;if(r(N!==U,`circular type reference to ${JSON.stringify(N)}`,"types",W),pK(N))continue;r(G.has(N),`unknown type ${JSON.stringify(N)}`,"types",W),G.get(N).push(U),Y.get(U).add(N)}}let Z=Array.from(G.keys()).filter((U)=>G.get(U).length===0);r(Z.length!==0,"missing primary type","types",W),r(Z.length===1,`ambiguous primary types or unused types: ${Z.map((U)=>JSON.stringify(U)).join(", ")}`,"types",W),H8(this,{primaryType:Z[0]});function V(U,Q){r(!Q.has(U),`circular type reference to ${JSON.stringify(U)}`,"types",W),Q.add(U);for(let H of Y.get(U)){if(!G.has(H))continue;V(H,Q);for(let N of Q)X.get(N).add(H)}Q.delete(U)}V(this.primaryType,new Set);for(let[U,Q]of X){let H=Array.from(Q);H.sort(),this.#Y.set(U,Z_(U,J[U])+H.map((N)=>Z_(N,J[N])).join(""))}}getEncoder(W){let Y=this.#G.get(W);if(!Y)Y=this.#X(W),this.#G.set(W,Y);return Y}#X(W){{let X=pK(W);if(X)return X}let Y=aq(W).array;if(Y){let X=Y.prefix,J=this.getEncoder(X);return(Z)=>{r(Y.count===-1||Y.count===Z.length,`array length mismatch; expected length ${Y.count}`,"value",Z);let V=Z.map(J);if(this.#Y.has(X))V=V.map(X8);return X8(t1(V))}}let G=this.types[W];if(G){let X=e4(this.#Y.get(W));return(J)=>{let Z=G.map(({name:V,type:U})=>{let Q=this.getEncoder(U)(J[V]);if(this.#Y.has(U))return X8(Q);return Q});return Z.unshift(X),t1(Z)}}r(!1,`unknown type: ${W}`,"type",W)}encodeType(W){let Y=this.#Y.get(W);return r(Y,`unknown type: ${JSON.stringify(W)}`,"name",W),Y}encodeData(W,Y){return this.getEncoder(W)(Y)}hashStruct(W,Y){return X8(this.encodeData(W,Y))}encode(W){return this.encodeData(this.primaryType,W)}hash(W){return this.hashStruct(this.primaryType,W)}_visit(W,Y,G){if(pK(W))return G(W,Y);let X=aq(W).array;if(X)return r(X.count===-1||X.count===Y.length,`array length mismatch; expected length ${X.count}`,"value",Y),Y.map((Z)=>this._visit(X.prefix,Z,G));let J=this.types[W];if(J)return J.reduce((Z,{name:V,type:U})=>{return Z[V]=this._visit(U,Y[V],G),Z},{});r(!1,`unknown type: ${W}`,"type",W)}visit(W,Y){return this._visit(this.primaryType,W,Y)}static from(W){return new E9(W)}static getPrimaryType(W){return E9.from(W).primaryType}static hashStruct(W,Y,G){return E9.from(Y).hashStruct(W,G)}static hashDomain(W){let Y=[];for(let G in W){if(W[G]==null)continue;let X=X_[G];r(X,`invalid typed-data domain key: ${JSON.stringify(G)}`,"domain",W),Y.push({name:G,type:X})}return Y.sort((G,X)=>{return cK.indexOf(G.name)-cK.indexOf(X.name)}),E9.hashStruct("EIP712Domain",{EIP712Domain:Y},W)}static encode(W,Y,G){return t1(["0x1901",E9.hashDomain(W),E9.from(Y).hash(G)])}static hash(W,Y,G){return X8(E9.encode(W,Y,G))}static async resolveNames(W,Y,G,X){W=Object.assign({},W);for(let V in W)if(W[V]==null)delete W[V];let J={};if(W.verifyingContract&&!R9(W.verifyingContract,20))J[W.verifyingContract]="0x";let Z=E9.from(Y);Z.visit(G,(V,U)=>{if(V==="address"&&!R9(U,20))J[U]="0x";return U});for(let V in J)J[V]=await X(V);if(W.verifyingContract&&J[W.verifyingContract])W.verifyingContract=J[W.verifyingContract];return G=Z.visit(G,(V,U)=>{if(V==="address"&&J[U])return J[U];return U}),{domain:W,value:G}}static getPayload(W,Y,G){E9.hashDomain(W);let X={},J=[];cK.forEach((U)=>{let Q=W[U];if(Q==null)return;X[U]=bs[U](Q),J.push({name:U,type:X_[U]})});let Z=E9.from(Y);Y=Z.types;let V=Object.assign({},Y);return r(V.EIP712Domain==null,"types must not contain EIP712Domain type","types.EIP712Domain",Y),V.EIP712Domain=J,Z.encode(G),{types:V,domain:X,primaryType:Z.primaryType,message:Z.visit(G,(U,Q)=>{if(U.match(/^bytes(\d*)/))return C0(B0(Q));if(U.match(/^u?int/))return u1(Q).toString();switch(U){case"address":return Q.toLowerCase();case"bool":return!!Q;case"string":return r(typeof Q==="string","invalid string","value",Q),Q}r(!1,"unsupported type","type",U)})}}}var H_=BigInt(0);function lK(W){if(W==null)return null;return W}function s8(W){if(W==null)return null;return W.toString()}function MU(W){let Y={};if(W.to)Y.to=W.to;if(W.from)Y.from=W.from;if(W.data)Y.data=C0(W.data);let G="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(let J of G){if(!(J in W)||W[J]==null)continue;Y[J]=u1(W[J],`request.${J}`)}let X="type,nonce".split(/,/);for(let J of X){if(!(J in W)||W[J]==null)continue;Y[J]=r8(W[J],`request.${J}`)}if(W.accessList)Y.accessList=vY(W.accessList);if(W.authorizationList)Y.authorizationList=W.authorizationList.slice();if("blockTag"in W)Y.blockTag=W.blockTag;if("enableCcipRead"in W)Y.enableCcipRead=!!W.enableCcipRead;if("customData"in W)Y.customData=W.customData;if("blobVersionedHashes"in W&&W.blobVersionedHashes)Y.blobVersionedHashes=W.blobVersionedHashes.slice();if("kzg"in W)Y.kzg=W.kzg;if("blobs"in W&&W.blobs)Y.blobs=W.blobs.map((J)=>{if(n7(J))return C0(J);return Object.assign({},J)});return Y}class N_{provider;number;hash;timestamp;parentHash;parentBeaconBlockRoot;nonce;difficulty;gasLimit;gasUsed;stateRoot;receiptsRoot;blobGasUsed;excessBlobGas;miner;prevRandao;extraData;baseFeePerGas;#W;constructor(W,Y){this.#W=W.transactions.map((G)=>{if(typeof G!=="string")return new sq(G,Y);return G}),H8(this,{provider:Y,hash:lK(W.hash),number:W.number,timestamp:W.timestamp,parentHash:W.parentHash,parentBeaconBlockRoot:W.parentBeaconBlockRoot,nonce:W.nonce,difficulty:W.difficulty,gasLimit:W.gasLimit,gasUsed:W.gasUsed,blobGasUsed:W.blobGasUsed,excessBlobGas:W.excessBlobGas,miner:W.miner,prevRandao:lK(W.prevRandao),extraData:W.extraData,baseFeePerGas:lK(W.baseFeePerGas),stateRoot:W.stateRoot,receiptsRoot:W.receiptsRoot})}get transactions(){return this.#W.map((W)=>{if(typeof W==="string")return W;return W.hash})}get prefetchedTransactions(){let W=this.#W.slice();if(W.length===0)return[];return X1(typeof W[0]==="object","transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),W}toJSON(){let{baseFeePerGas:W,difficulty:Y,extraData:G,gasLimit:X,gasUsed:J,hash:Z,miner:V,prevRandao:U,nonce:Q,number:H,parentHash:N,parentBeaconBlockRoot:A,stateRoot:q,receiptsRoot:z,timestamp:w,transactions:D}=this;return{_type:"Block",baseFeePerGas:s8(W),difficulty:s8(Y),extraData:G,gasLimit:s8(X),gasUsed:s8(J),blobGasUsed:s8(this.blobGasUsed),excessBlobGas:s8(this.excessBlobGas),hash:Z,miner:V,prevRandao:U,nonce:Q,number:H,parentHash:N,timestamp:w,parentBeaconBlockRoot:A,stateRoot:q,receiptsRoot:z,transactions:D}}[Symbol.iterator](){let W=0,Y=this.transactions;return{next:()=>{if(W<this.length)return{value:Y[W++],done:!1};return{value:void 0,done:!0}}}}get length(){return this.#W.length}get date(){if(this.timestamp==null)return null;return new Date(this.timestamp*1000)}async getTransaction(W){let Y=void 0;if(typeof W==="number")Y=this.#W[W];else{let G=W.toLowerCase();for(let X of this.#W)if(typeof X==="string"){if(X!==G)continue;Y=X;break}else{if(X.hash!==G)continue;Y=X;break}}if(Y==null)throw Error("no such tx");if(typeof Y==="string")return await this.provider.getTransaction(Y);else return Y}getPrefetchedTransaction(W){let Y=this.prefetchedTransactions;if(typeof W==="number")return Y[W];W=W.toLowerCase();for(let G of Y)if(G.hash===W)return G;r(!1,"no matching transaction","indexOrHash",W)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw Error("");return cs(this)}}class dK{provider;transactionHash;blockHash;blockNumber;removed;address;data;topics;index;transactionIndex;constructor(W,Y){this.provider=Y;let G=Object.freeze(W.topics.slice());H8(this,{transactionHash:W.transactionHash,blockHash:W.blockHash,blockNumber:W.blockNumber,removed:W.removed,address:W.address,data:W.data,topics:G,index:W.index,transactionIndex:W.transactionIndex})}toJSON(){let{address:W,blockHash:Y,blockNumber:G,data:X,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}=this;return{_type:"log",address:W,blockHash:Y,blockNumber:G,data:X,index:J,removed:Z,topics:V,transactionHash:U,transactionIndex:Q}}async getBlock(){let W=await this.provider.getBlock(this.blockHash);return X1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransaction(){let W=await this.provider.getTransaction(this.transactionHash);return X1(!!W,"failed to find transaction","UNKNOWN_ERROR",{}),W}async getTransactionReceipt(){let W=await this.provider.getTransactionReceipt(this.transactionHash);return X1(!!W,"failed to find transaction receipt","UNKNOWN_ERROR",{}),W}removedEvent(){return ps(this)}}class q_{provider;to;from;contractAddress;hash;index;blockHash;blockNumber;logsBloom;gasUsed;blobGasUsed;cumulativeGasUsed;gasPrice;blobGasPrice;type;status;root;#W;constructor(W,Y){this.#W=Object.freeze(W.logs.map((X)=>{return new dK(X,Y)}));let G=H_;if(W.effectiveGasPrice!=null)G=W.effectiveGasPrice;else if(W.gasPrice!=null)G=W.gasPrice;H8(this,{provider:Y,to:W.to,from:W.from,contractAddress:W.contractAddress,hash:W.hash,index:W.index,blockHash:W.blockHash,blockNumber:W.blockNumber,logsBloom:W.logsBloom,gasUsed:W.gasUsed,cumulativeGasUsed:W.cumulativeGasUsed,blobGasUsed:W.blobGasUsed,gasPrice:G,blobGasPrice:W.blobGasPrice,type:W.type,status:W.status,root:W.root})}get logs(){return this.#W}toJSON(){let{to:W,from:Y,contractAddress:G,hash:X,index:J,blockHash:Z,blockNumber:V,logsBloom:U,logs:Q,status:H,root:N}=this;return{_type:"TransactionReceipt",blockHash:Z,blockNumber:V,contractAddress:G,cumulativeGasUsed:s8(this.cumulativeGasUsed),from:Y,gasPrice:s8(this.gasPrice),blobGasUsed:s8(this.blobGasUsed),blobGasPrice:s8(this.blobGasPrice),gasUsed:s8(this.gasUsed),hash:X,index:J,logs:Q,logsBloom:U,root:N,status:H,to:W}}get length(){return this.logs.length}[Symbol.iterator](){let W=0;return{next:()=>{if(W<this.length)return{value:this.logs[W++],done:!1};return{value:void 0,done:!0}}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){let W=await this.provider.getBlock(this.blockHash);if(W==null)throw Error("TODO");return W}async getTransaction(){let W=await this.provider.getTransaction(this.hash);if(W==null)throw Error("TODO");return W}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return I_(this)}reorderedEvent(W){return X1(!W||W.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),A_(this,W)}}class sq{provider;blockNumber;blockHash;index;hash;type;to;from;nonce;gasLimit;gasPrice;maxPriorityFeePerGas;maxFeePerGas;maxFeePerBlobGas;data;value;chainId;signature;accessList;blobVersionedHashes;authorizationList;#W;constructor(W,Y){this.provider=Y,this.blockNumber=W.blockNumber!=null?W.blockNumber:null,this.blockHash=W.blockHash!=null?W.blockHash:null,this.hash=W.hash,this.index=W.index,this.type=W.type,this.from=W.from,this.to=W.to||null,this.gasLimit=W.gasLimit,this.nonce=W.nonce,this.data=W.data,this.value=W.value,this.gasPrice=W.gasPrice,this.maxPriorityFeePerGas=W.maxPriorityFeePerGas!=null?W.maxPriorityFeePerGas:null,this.maxFeePerGas=W.maxFeePerGas!=null?W.maxFeePerGas:null,this.maxFeePerBlobGas=W.maxFeePerBlobGas!=null?W.maxFeePerBlobGas:null,this.chainId=W.chainId,this.signature=W.signature,this.accessList=W.accessList!=null?W.accessList:null,this.blobVersionedHashes=W.blobVersionedHashes!=null?W.blobVersionedHashes:null,this.authorizationList=W.authorizationList!=null?W.authorizationList:null,this.#W=-1}toJSON(){let{blockNumber:W,blockHash:Y,index:G,hash:X,type:J,to:Z,from:V,nonce:U,data:Q,signature:H,accessList:N,blobVersionedHashes:A}=this;return{_type:"TransactionResponse",accessList:N,blockNumber:W,blockHash:Y,blobVersionedHashes:A,chainId:s8(this.chainId),data:Q,from:V,gasLimit:s8(this.gasLimit),gasPrice:s8(this.gasPrice),hash:X,maxFeePerGas:s8(this.maxFeePerGas),maxPriorityFeePerGas:s8(this.maxPriorityFeePerGas),maxFeePerBlobGas:s8(this.maxFeePerBlobGas),nonce:U,signature:H,to:Z,index:G,type:J,value:s8(this.value)}}async getBlock(){let W=this.blockNumber;if(W==null){let G=await this.getTransaction();if(G)W=G.blockNumber}if(W==null)return null;let Y=this.provider.getBlock(W);if(Y==null)throw Error("TODO");return Y}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(this.blockNumber==null){let{tx:Y,blockNumber:G}=await o7({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});if(Y==null||Y.blockNumber==null)return 0;return G-Y.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(W,Y){let G=W==null?1:W,X=Y==null?0:Y,J=this.#W,Z=-1,V=J===-1?!0:!1,U=async()=>{if(V)return null;let{blockNumber:A,nonce:q}=await o7({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(q<this.nonce){J=A;return}if(V)return null;let z=await this.getTransaction();if(z&&z.blockNumber!=null)return;if(Z===-1){if(Z=J-3,Z<this.#W)Z=this.#W}while(Z<=A){if(V)return null;let w=await this.provider.getBlock(Z,!0);if(w==null)return;for(let D of w)if(D===this.hash)return;for(let D=0;D<w.length;D++){let T=await w.getTransaction(D);if(T.from===this.from&&T.nonce===this.nonce){if(V)return null;let x=await this.provider.getTransactionReceipt(T.hash);if(x==null)return;if(A-x.blockNumber+1<G)return;let g="replaced";if(T.data===this.data&&T.to===this.to&&T.value===this.value)g="repriced";else if(T.data==="0x"&&T.from===T.to&&T.value===H_)g="cancelled";X1(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:g==="replaced"||g==="cancelled",reason:g,replacement:T.replaceableTransaction(J),hash:T.hash,receipt:x})}}Z++}return},Q=(A)=>{if(A==null||A.status!==0)return A;X1(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:A.to,from:A.from,data:""},receipt:A})},H=await this.provider.getTransactionReceipt(this.hash);if(G===0)return Q(H);if(H){if(G===1||await H.confirmations()>=G)return Q(H)}else if(await U(),G===0)return null;return await new Promise((A,q)=>{let z=[],w=()=>{z.forEach((T)=>T())};if(z.push(()=>{V=!0}),X>0){let T=setTimeout(()=>{w(),q(AU("wait for transaction timeout","TIMEOUT"))},X);z.push(()=>{clearTimeout(T)})}let D=async(T)=>{if(await T.confirmations()>=G){w();try{A(Q(T))}catch(x){q(x)}}};if(z.push(()=>{this.provider.off(this.hash,D)}),this.provider.on(this.hash,D),J>=0){let T=async()=>{try{await U()}catch(x){if(Cq(x,"TRANSACTION_REPLACED")){w(),q(x);return}}if(!V)this.provider.once("block",T)};z.push(()=>{this.provider.off("block",T)}),this.provider.once("block",T)}})}isMined(){return this.blockHash!=null}isLegacy(){return this.type===0}isBerlin(){return this.type===1}isLondon(){return this.type===2}isCancun(){return this.type===3}removedEvent(){return X1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),I_(this)}reorderedEvent(W){return X1(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),X1(!W||W.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),A_(this,W)}replaceableTransaction(W){r(Number.isInteger(W)&&W>=0,"invalid startBlock","startBlock",W);let Y=new sq(this,this.provider);return Y.#W=W,Y}}function cs(W){return{orphan:"drop-block",hash:W.hash,number:W.number}}function A_(W,Y){return{orphan:"reorder-transaction",tx:W,other:Y}}function I_(W){return{orphan:"drop-transaction",tx:W}}function ps(W){return{orphan:"drop-log",log:{transactionHash:W.transactionHash,blockHash:W.blockHash,blockNumber:W.blockNumber,address:W.address,data:W.data,topics:Object.freeze(W.topics.slice()),index:W.index}}}function uY(W,Y){if(W.provider)return W.provider;X1(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:Y})}async function z_(W,Y){let G=MU(Y);if(G.to!=null)G.to=s4(G.to,W);if(G.from!=null){let X=G.from;G.from=Promise.all([W.getAddress(),s4(X,W)]).then(([J,Z])=>{return r(J.toLowerCase()===Z.toLowerCase(),"transaction from mismatch","tx.from",Z),J})}else G.from=W.getAddress();return await o7(G)}class PU{provider;constructor(W){H8(this,{provider:W||null})}async getNonce(W){return uY(this,"getTransactionCount").getTransactionCount(await this.getAddress(),W)}async populateCall(W){return await z_(this,W)}async populateTransaction(W){let Y=uY(this,"populateTransaction"),G=await z_(this,W);if(G.nonce==null)G.nonce=await this.getNonce("pending");if(G.gasLimit==null)G.gasLimit=await this.estimateGas(G);let X=await this.provider.getNetwork();if(G.chainId!=null){let Z=u1(G.chainId);r(Z===X.chainId,"transaction chainId mismatch","tx.chainId",W.chainId)}else G.chainId=X.chainId;let J=G.maxFeePerGas!=null||G.maxPriorityFeePerGas!=null;if(G.gasPrice!=null&&(G.type===2||J))r(!1,"eip-1559 transaction do not support gasPrice","tx",W);else if((G.type===0||G.type===1)&&J)r(!1,"pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","tx",W);if((G.type===2||G.type==null)&&(G.maxFeePerGas!=null&&G.maxPriorityFeePerGas!=null))G.type=2;else if(G.type===0||G.type===1){let Z=await Y.getFeeData();if(X1(Z.gasPrice!=null,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),G.gasPrice==null)G.gasPrice=Z.gasPrice}else{let Z=await Y.getFeeData();if(G.type==null)if(Z.maxFeePerGas!=null&&Z.maxPriorityFeePerGas!=null){if(G.authorizationList&&G.authorizationList.length)G.type=4;else G.type=2;if(G.gasPrice!=null){let V=G.gasPrice;delete G.gasPrice,G.maxFeePerGas=V,G.maxPriorityFeePerGas=V}else{if(G.maxFeePerGas==null)G.maxFeePerGas=Z.maxFeePerGas;if(G.maxPriorityFeePerGas==null)G.maxPriorityFeePerGas=Z.maxPriorityFeePerGas}}else if(Z.gasPrice!=null){if(X1(!J,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),G.gasPrice==null)G.gasPrice=Z.gasPrice;G.type=0}else X1(!1,"failed to get consistent fee data","UNSUPPORTED_OPERATION",{operation:"signer.getFeeData"});else if(G.type===2||G.type===3||G.type===4){if(G.maxFeePerGas==null)G.maxFeePerGas=Z.maxFeePerGas;if(G.maxPriorityFeePerGas==null)G.maxPriorityFeePerGas=Z.maxPriorityFeePerGas}}return await o7(G)}async populateAuthorization(W){let Y=Object.assign({},W);if(Y.chainId==null)Y.chainId=(await uY(this,"getNetwork").getNetwork()).chainId;if(Y.nonce==null)Y.nonce=await this.getNonce();return Y}async estimateGas(W){return uY(this,"estimateGas").estimateGas(await this.populateCall(W))}async call(W){return uY(this,"call").call(await this.populateCall(W))}async resolveName(W){return await uY(this,"resolveName").resolveName(W)}async sendTransaction(W){let Y=uY(this,"sendTransaction"),G=await this.populateTransaction(W);delete G.from;let X=t9.from(G);return await Y.broadcastTransaction(await this.signTransaction(X))}authorize(W){X1(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}class LU extends PU{address;constructor(W,Y){super(Y);H8(this,{address:W})}async getAddress(){return this.address}connect(W){return new LU(this.address,W)}#W(W,Y){X1(!1,`VoidSigner cannot sign ${W}`,"UNSUPPORTED_OPERATION",{operation:Y})}async signTransaction(W){this.#W("transactions","signTransaction")}async signMessage(W){this.#W("messages","signMessage")}async signTypedData(W,Y,G){this.#W("typed-data","signTypedData")}}class hY extends PU{address;#W;constructor(W,Y){super(Y);r(W&&typeof W.sign==="function","invalid private key","privateKey","[ REDACTED ]"),this.#W=W;let G=t4(this.signingKey.publicKey);H8(this,{address:G})}get signingKey(){return this.#W}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(W){return new hY(this.#W,W)}async signTransaction(W){W=MU(W);let{to:Y,from:G}=await o7({to:W.to?s4(W.to,this):void 0,from:W.from?s4(W.from,this):void 0});if(Y!=null)W.to=Y;if(G!=null)W.from=G;if(W.from!=null)r(f1(W.from)===this.address,"transaction from address mismatch","tx.from",W.from),delete W.from;let X=t9.from(W);return X.signature=this.signingKey.sign(X.unsignedHash),X.serialized}async signMessage(W){return this.signMessageSync(W)}signMessageSync(W){return this.signingKey.sign(RU(W)).serialized}authorizeSync(W){r(typeof W.address==="string","invalid address for authorizeSync","auth.address",W);let Y=this.signingKey.sign(iq(W));return Object.assign({},{address:f1(W.address),nonce:u1(W.nonce||0),chainId:u1(W.chainId||0)},{signature:Y})}async authorize(W){return W=Object.assign({},W,{address:await s4(W.address,this)}),this.authorizeSync(await this.populateAuthorization(W))}async signTypedData(W,Y,G){let X=await E9.resolveNames(W,Y,G,async(J)=>{X1(this.provider!=null,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:J}});let Z=await this.provider.resolveName(J);return X1(Z!=null,"unconfigured ENS name","UNCONFIGURED_NAME",{value:J}),Z});return this.signingKey.sign(E9.hash(X.domain,Y,X.value)).serialized}}var tq=" !#$%&'()*+,-./<=>?@[]^_`{|}~",ls=/^[a-z]*$/i;function w_(W,Y){let G=97;return W.reduce((X,J)=>{if(J===Y)G++;else if(J.match(ls))X.push(String.fromCharCode(G)+J);else G=97,X.push(J);return X},[])}function ds(W,Y){for(let J=tq.length-1;J>=0;J--)W=W.split(tq[J]).join(Y.substring(2*J,2*J+2));let G=[],X=W.replace(/(:|([0-9])|([A-Z][a-z]*))/g,(J,Z,V,U)=>{if(V)for(let Q=parseInt(V);Q>=0;Q--)G.push(";");else G.push(Z.toLowerCase());return""});if(X)throw Error(`leftovers: ${JSON.stringify(X)}`);return w_(w_(G,";"),":")}function j_(W){return r(W[0]==="0","unsupported auwl data","data",W),ds(W.substring(1+2*tq.length),W.substring(1,1+2*tq.length))}class oK{locale;constructor(W){H8(this,{locale:W})}split(W){return W.toLowerCase().split(/\s+/g)}join(W){return W.join(" ")}}class nK extends oK{#W;#Y;constructor(W,Y,G){super(W);this.#W=Y,this.#Y=G,this.#G=null}get _data(){return this.#W}_decodeWords(){return j_(this.#W)}#G;#X(){if(this.#G==null){let W=this._decodeWords();if(e4(W.join(`
|
|
250
250
|
`)+`
|
|
251
|
-
`)!==this.#Y)throw Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#G=W}return this.#G}getWord(W){let Y=this.#X();return r(W>=0&&W<Y.length,`invalid word index: ${W}`,"index",W),Y[W]}getWordIndex(W){return this.#X().indexOf(W)}}var os="0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly,Ch%Ci|G G!GryIm$K!Noun)Nu$O` Sw T&naTiqueXietyY1ArtOlogyPe?P!Pro=Ril1ChCt-EaEnaGueMMedM%MyOundR<+Re,Ri=RowTTefa@Ti,Tw%k0KPe@SaultSetSi,SumeThma0H!>OmTa{T&dT.udeTra@0Ct]D.Gu,NtTh%ToTumn0Era+OcadoOid0AkeA*AyEsomeFulKw?d0Is:ByChel%C#D+GL<)Lc#y~MbooN<aNn RRelyRga(R*lSeS-SketTt!3A^AnAutyCau'ComeEfF%eG(Ha=H(dLie=LowLtN^Nef./TrayTt Twe&Y#d3Cyc!DKeNdOlogyRdR`Tt _{AdeAmeAnketA,EakE[IndOodO[omOu'UeUrUsh_rdAtDyIlMbNeNusOkO,Rd R(gRrowSsTtomUn)XY_{etA(AndA[A=EadEezeI{Id+IefIghtIngIskOccoliOk&OnzeOomO` OwnUsh2Bb!DdyD+tFf$oIldLbLkL!tNd!Nk Rd&Rg R,SS(e[SyTt Y Zz:Bba+B(B!CtusGeKe~LmM aMpNN$N)lNdyNn#NoeNvasNy#Pab!P.$Pta(RRb#RdRgoRpetRryRtSeShS(o/!Su$TT$ogT^Teg%yTt!UghtU'Ut]Ve3Il(gL yM|NsusNturyRe$Rta(_irAlkAmp]An+AosApt Ar+A'AtEapE{Ee'EfErryE,I{&IefIldIm}yOi)Oo'R#-U{!UnkUrn0G?Nnam#Rc!Tiz&TyVil_imApArifyAwAyE<ErkEv I{I|IffImbIn-IpO{OgO'O`OudOwnUbUmpU, Ut^_^A,C#utDeFfeeIlInL!@L%LumnMb(eMeMf%tM-Mm#Mp<yNc tNdu@NfirmNg*[N}@Nsid NtrolNv()OkOlPp PyR$ReRnR*@/Tt#U^UntryUp!Ur'Us(V Yo>_{Ad!AftAmA}AshAt AwlAzyEamEd.EekEwI{etImeIspIt-OpO[Ou^OwdUci$UelUi'Umb!Un^UshYY,$2BeLtu*PPbo?dRiousRr|Rta(R=Sh]/omTe3C!:DMa+MpN)Ng R(gShUght WnY3AlBa>BrisCadeCemb CideCl(eC%a>C*a'ErF&'F(eFyG*eLayLiv M<dMi'Ni$Nti,NyP?tP&dPos.P`PutyRi=ScribeS tSignSkSpair/royTailTe@VelopVi)Vo>3AgramAlAm#dAryCeE'lEtFf G.$Gn.yLemmaNn NosaurRe@RtSag*eScov Sea'ShSmi[S%d Splay/<)V tVideV%)Zzy5Ct%Cum|G~Lph(Ma(Na>NkeyN%OrSeUb!Ve_ftAg#AmaA,-AwEamE[IftIllInkIpI=OpUmY2CkMbNeR(g/T^Ty1Arf1Nam-:G G!RlyRnR`Sily/Sy1HoOlogyOnomy0GeItUca>1F%t0G1GhtTh 2BowD E@r-Eg<tEm|Eph<tEvat%I>Se0B?kBodyBra)Er+Ot]PloyPow Pty0Ab!A@DD![D%'EmyErgyF%)Ga+G(eH<)JoyLi,OughR-hRollSu*T Ti*TryVelope1Isode0U$Uip0AA'OdeOs]R%Upt0CapeSayS&)Ta>0Ern$H-s1Id&)IlOkeOl=1A@Amp!Ce[Ch<+C.eCludeCu'Ecu>Erci'Hau,Hib.I!I,ItOt-P<dPe@Pi*Pla(Po'P*[T&dTra0EEbrow:Br-CeCultyDeIntI`~L'MeMilyMousNNcyNtasyRmSh]TT$Th TigueUltV%.e3Atu*Bru?yD $EEdElMa!N)/iv$T^V W3B Ct]EldGu*LeLmLt N$NdNeNg NishReRmR,Sc$ShTT}[X_gAmeAshAtAv%EeIghtIpOatO{O%Ow UidUshY_mCusGIlLd~owOdOtR)Re,R+tRkRtu}RumRw?dSsil/ UndX_gi!AmeEqu|EshI&dIn+OgOntO,OwnOz&U.2ElNNnyRna)RyTu*:D+tInLaxy~ yMePRa+Rba+Rd&Rl-Rm|SSpTeTh U+Ze3N $NiusN*Nt!Nu(e/u*2O,0AntFtGg!Ng RaffeRlVe_dAn)A*A[IdeImp'ObeOomOryO=OwUe_tDde[LdOdO'RillaSpelSsipV nWn_bA)A(AntApeA[Av.yEatE&IdIefItOc yOupOwUnt_rdE[IdeIltIt?N3M:B.IrLfMm M, NdPpyRb%RdRshR=,TVeWkZ?d3AdAl`ArtAvyD+hogIght~oLmetLpNRo3Dd&Gh~NtPRe/%y5BbyCkeyLdLeLiday~owMeNeyOdPeRnRr%R'Sp.$/TelUrV 5BGeM<Mb!M%Nd*dNgryNtRd!RryRtSb<d3Brid:1EOn0EaEntifyLe2N%e4LLeg$L}[0A+Ita>M&'Mu}Pa@Po'Pro=Pul'0ChCludeComeC*a'DexD-a>Do%Du,ryF<tFl-tF%mHa!H .Iti$Je@JuryMa>N Noc|PutQuiryS<eSe@SideSpi*/$lTa@T e,ToVe,V.eVol=3On0L<dOla>Sue0Em1Ory:CketGu?RZz3AlousAns~yWel9BInKeUr}yY5D+I)MpNg!Ni%Nk/:Ng?oo3EnEpT^upY3CkDD}yNdNgdomSsTT^&TeTt&Wi4EeIfeO{Ow:BBelB%Dd DyKeMpNgua+PtopR+T T(UghUndryVaWWnWsu.Y Zy3Ad AfArnA=Ctu*FtGG$G&dIsu*M#NdNg`NsOp?dSs#Tt Vel3ArB tyBr?yC&'FeFtGhtKeMbM.NkOnQuid/Tt!VeZ?d5AdAnB, C$CkG-NelyNgOpTt yUdUn+VeY$5CkyGga+Mb N?N^Xury3R-s:Ch(eDG-G}tIdIlInJ%KeMm$NNa+Nda>NgoNs]Nu$P!Rb!R^Rg(R(eRketRria+SkSs/ T^T i$ThTrixTt XimumZe3AdowAnAsu*AtCh<-D$DiaLodyLtMb M%yNt]NuRcyR+R.RryShSsa+T$Thod3Dd!DnightLk~]M-NdNimumN%Nu>Rac!Rr%S ySs/akeXXedXtu*5Bi!DelDifyMM|N.%NkeyN, N`OnR$ReRn(gSqu.oTh T]T%Unta(U'VeVie5ChFf(LeLtiplySc!SeumShroomS-/Tu$3Self/ yTh:I=MePk(Rrow/yT]Tu*3ArCkEdGati=G!@I` PhewR=/TTw%kUtr$V WsXt3CeGht5B!I'M(eeOd!Rm$R`SeTab!TeTh(gTi)VelW5C!?Mb R'T:K0EyJe@Li+Scu*S =Ta(Vious0CurE<Tob 0Or1FF Fi)T&2L1Ay0DI=Ymp-0It0CeEI#L(eLy1EnEraIn]Po'T]1An+B.Ch?dD D(?yG<I|Ig($Ph<0Tr-h0H 0Tdo%T TputTside0AlEnEr0NN 0Yg&0/ 0O}:CtDd!GeIrLa)LmNdaNelN-N` P RadeR|RkRrotRtySsT^ThTi|TrolTt nU'VeYm|3A)AnutArAs<tL-<NN$tyNcilOp!Pp Rfe@Rm.Rs#T2O}OtoRa'Ys-$0AnoCn-Ctu*E)GGe#~LotNkO} Pe/olT^Zza_)A}tA,-A>AyEa'Ed+U{UgUn+2EmEtIntL?LeLi)NdNyOlPul?Rt]S.]Ssib!/TatoTt yV tyWd W _@i)Ai'Ed-tEf Epa*Es|EttyEv|I)IdeIm?yIntI%.yIs#Iva>IzeOb!mO)[Odu)Of.OgramOje@Omo>OofOp tyOsp O>@OudOvide2Bl-Dd(g~LpL'Mpk(N^PilPpyR^a'R.yRpo'R'ShTZz!3Ramid:99Al.yAntumArt E,]I{ItIzO>:Bb.Cco#CeCkD?DioIlInI'~yMpN^NdomN+PidReTeTh V&WZ%3AdyAlAs#BelBuildC$lCei=CipeC%dCyc!Du)F!@F%mFu'G]G*tGul?Je@LaxLea'LiefLyMa(Memb M(dMo=Nd NewNtOp&PairPeatPla)P%tQui*ScueSemb!Si,Sour)Sp#'SultTi*T*atTurnUn]Ve$ViewW?d2Y`m0BBb#CeChDeD+F!GhtGidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOg<OtOwUsh0AllArtI!OkeOo`0A{AkeApIffOw0ApCc Ci$CkDaFtL?Ldi LidLut]L=Me#eNgOnRryRtUlUndUpUr)U`0A)A*Ati$AwnEakEci$EedEllEndH eI)Id IkeInIr.L.OilOns%O#OrtOtRayReadR(gY0Ua*UeezeUir*l_b!AdiumAffA+AirsAmpAndArtA>AyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NN<tNnisNtRm/Xt_nkAtEmeEnE%yE*EyIngIsOughtReeRi=RowUmbUnd 0CketDeG LtMb MeNyPRedSsueT!5A,BaccoDayDdl EGe` I!tK&MatoM%rowNeNgueNightOlO`PP-Pp!R^RnadoRtoi'SsT$Uri,W?dW WnY_{AdeAff-Ag-A(Ansf ApAshA=lAyEatEeEndI$IbeI{Igg ImIpOphyOub!U{UeUlyUmpetU,U`Y2BeIt]Mb!NaN}lRkeyRnRt!1El=EntyI)InI,O1PeP-$:5Ly5B*lla0Ab!Awa*C!Cov D DoFairFoldHappyIf%mIqueItIv 'KnownLo{TilUsu$Veil1Da>GradeHoldOnP Set1B<Ge0A+EEdEfulE![U$0Il.y:C<tCuumGueLidL!yL=NNishP%Rious/Ult3H-!L=tNd%Ntu*NueRbRifyRs]RyS'lT <3Ab!Br<tCiousCt%yDeoEw~a+Nta+Ol(Rtu$RusSaS.Su$T$Vid5C$I)IdLc<oLumeTeYa+:GeG#ItLk~LnutNtRfa*RmRri%ShSp/eT VeY3Al`Ap#ArA'lA` BDd(gEk&dIrdLcome/T_!AtEatEelEnE*IpIsp 0DeD`FeLd~NNdowNeNgNkNn Nt ReSdomSeShT}[5LfM<Nd OdOlRdRkRldRryR`_pE{E,!I,I>Ong::Rd3Ar~ow9UUngU`:3BraRo9NeO",ns="0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60",iK=null;class W6 extends nK{constructor(){super("en",os,ns)}static wordlist(){if(iK==null)iK=new W6;return iK}}function O_(W){return(1<<W)-1<<8-W&255}function is(W){return(1<<W)-1&255}function rK(W,Y){if(nX("NFKD"),Y==null)Y=W6.wordlist();let G=Y.split(W);r(G.length%3===0&&G.length>=12&&G.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");let X=new Uint8Array(Math.ceil(11*G.length/8)),J=0;for(let H=0;H<G.length;H++){let N=Y.getWordIndex(G[H].normalize("NFKD"));r(N>=0,`invalid mnemonic word at index ${H}`,"mnemonic","[ REDACTED ]");for(let A=0;A<11;A++){if(N&1<<10-A)X[J>>3]|=1<<7-J%8;J++}}let Z=32*G.length/3,V=G.length/3,U=O_(V),Q=B0(L9(X.slice(0,Z/8)))[0]&U;return r(Q===(X[X.length-1]&U),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),C0(X.slice(0,Z/8))}function aK(W,Y){if(r(W.length%4===0&&W.length>=16&&W.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),Y==null)Y=W6.wordlist();let G=[0],X=11;for(let V=0;V<W.length;V++)if(X>8)G[G.length-1]<<=8,G[G.length-1]|=W[V],X-=8;else G[G.length-1]<<=X,G[G.length-1]|=W[V]>>8-X,G.push(W[V]&is(8-X)),X+=3;let J=W.length/4,Z=parseInt(L9(W).substring(2,4),16)&O_(J);return G[G.length-1]<<=J,G[G.length-1]|=Z>>8-J,Y.join(G.map((V)=>Y.getWord(V)))}var sK={};class Y6{phrase;password;wordlist;entropy;constructor(W,Y,G,X,J){if(X==null)X="";if(J==null)J=W6.wordlist();d4(W,sK,"Mnemonic"),H8(this,{phrase:G,password:X,wordlist:J,entropy:Y})}computeSeed(){let W=M9("mnemonic"+this.password,"NFKD");return F5(M9(this.phrase,"NFKD"),W,2048,64,"sha512")}static fromPhrase(W,Y,G){let X=rK(W,G);return W=aK(B0(X),G),new Y6(sK,X,W,Y,G)}static fromEntropy(W,Y,G){let X=B0(W,"entropy"),J=aK(X,G);return new Y6(sK,C0(X),J,Y,G)}static entropyToPhrase(W,Y){let G=B0(W,"entropy");return aK(G,Y)}static phraseToEntropy(W,Y){return rK(W,Y)}static isValidMnemonic(W,Y){try{return rK(W,Y),!0}catch(G){}return!1}}/*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */var V9=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},tK=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},WA,_5,r7,rs={16:10,24:12,32:14},as=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],k5=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],eq=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],ss=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],ts=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],es=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],Wt=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],Yt=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],Gt=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],Xt=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239000,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],Jt=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998000,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],Zt=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],Vt=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],Ut=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239000,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],Qt=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998000,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function eK(W){let Y=[];for(let G=0;G<W.length;G+=4)Y.push(W[G]<<24|W[G+1]<<16|W[G+2]<<8|W[G+3]);return Y}class YA{get key(){return V9(this,WA,"f").slice()}constructor(W){if(WA.set(this,void 0),_5.set(this,void 0),r7.set(this,void 0),!(this instanceof YA))throw Error("AES must be instanitated with `new`");tK(this,WA,new Uint8Array(W),"f");let Y=rs[this.key.length];if(Y==null)throw TypeError("invalid key size (must be 16, 24 or 32 bytes)");tK(this,r7,[],"f"),tK(this,_5,[],"f");for(let H=0;H<=Y;H++)V9(this,r7,"f").push([0,0,0,0]),V9(this,_5,"f").push([0,0,0,0]);let G=(Y+1)*4,X=this.key.length/4,J=eK(this.key),Z;for(let H=0;H<X;H++)Z=H>>2,V9(this,r7,"f")[Z][H%4]=J[H],V9(this,_5,"f")[Y-Z][H%4]=J[H];let V=0,U=X,Q;while(U<G){if(Q=J[X-1],J[0]^=k5[Q>>16&255]<<24^k5[Q>>8&255]<<16^k5[Q&255]<<8^k5[Q>>24&255]^as[V]<<24,V+=1,X!=8)for(let q=1;q<X;q++)J[q]^=J[q-1];else{for(let q=1;q<X/2;q++)J[q]^=J[q-1];Q=J[X/2-1],J[X/2]^=k5[Q&255]^k5[Q>>8&255]<<8^k5[Q>>16&255]<<16^k5[Q>>24&255]<<24;for(let q=X/2+1;q<X;q++)J[q]^=J[q-1]}let H=0,N,A;while(H<X&&U<G)N=U>>2,A=U%4,V9(this,r7,"f")[N][A]=J[H],V9(this,_5,"f")[Y-N][A]=J[H++],U++}for(let H=1;H<Y;H++)for(let N=0;N<4;N++)Q=V9(this,_5,"f")[H][N],V9(this,_5,"f")[H][N]=Zt[Q>>24&255]^Vt[Q>>16&255]^Ut[Q>>8&255]^Qt[Q&255]}encrypt(W){if(W.length!=16)throw TypeError("invalid plaintext size (must be 16 bytes)");let Y=V9(this,r7,"f").length-1,G=[0,0,0,0],X=eK(W);for(let V=0;V<4;V++)X[V]^=V9(this,r7,"f")[0][V];for(let V=1;V<Y;V++){for(let U=0;U<4;U++)G[U]=ss[X[U]>>24&255]^ts[X[(U+1)%4]>>16&255]^es[X[(U+2)%4]>>8&255]^Wt[X[(U+3)%4]&255]^V9(this,r7,"f")[V][U];X=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=V9(this,r7,"f")[Y][V],J[4*V]=(k5[X[V]>>24&255]^Z>>24)&255,J[4*V+1]=(k5[X[(V+1)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(k5[X[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(k5[X[(V+3)%4]&255]^Z)&255;return J}decrypt(W){if(W.length!=16)throw TypeError("invalid ciphertext size (must be 16 bytes)");let Y=V9(this,_5,"f").length-1,G=[0,0,0,0],X=eK(W);for(let V=0;V<4;V++)X[V]^=V9(this,_5,"f")[0][V];for(let V=1;V<Y;V++){for(let U=0;U<4;U++)G[U]=Yt[X[U]>>24&255]^Gt[X[(U+3)%4]>>16&255]^Xt[X[(U+2)%4]>>8&255]^Jt[X[(U+1)%4]&255]^V9(this,_5,"f")[V][U];X=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=V9(this,_5,"f")[Y][V],J[4*V]=(eq[X[V]>>24&255]^Z>>24)&255,J[4*V+1]=(eq[X[(V+3)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(eq[X[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(eq[X[(V+1)%4]&255]^Z)&255;return J}}WA=new WeakMap,_5=new WeakMap,r7=new WeakMap;class BU{constructor(W,Y,G){if(G&&!(this instanceof G))throw Error(`${W} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new YA(Y)},name:{enumerable:!0,value:W}})}}var GA=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},JJ=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},EU,G6;class $U extends BU{constructor(W,Y){super("ECC",W,$U);if(EU.set(this,void 0),G6.set(this,void 0),Y){if(Y.length%16)throw TypeError("invalid iv size (must be 16 bytes)");GA(this,EU,new Uint8Array(Y),"f")}else GA(this,EU,new Uint8Array(16),"f");GA(this,G6,this.iv,"f")}get iv(){return new Uint8Array(JJ(this,EU,"f"))}encrypt(W){if(W.length%16)throw TypeError("invalid plaintext size (must be multiple of 16 bytes)");let Y=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){for(let X=0;X<16;X++)JJ(this,G6,"f")[X]^=W[G+X];GA(this,G6,this.aes.encrypt(JJ(this,G6,"f")),"f"),Y.set(JJ(this,G6,"f"),G)}return Y}decrypt(W){if(W.length%16)throw TypeError("invalid ciphertext size (must be multiple of 16 bytes)");let Y=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){let X=this.aes.decrypt(W.subarray(G,G+16));for(let J=0;J<16;J++)Y[G+J]=X[J]^JJ(this,G6,"f")[J],JJ(this,G6,"f")[J]=W[G+J]}return Y}}EU=new WeakMap,G6=new WeakMap;var ZJ=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},y5=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},FU,bY,v5;class HW extends BU{constructor(W,Y){super("CTR",W,HW);if(FU.set(this,void 0),bY.set(this,void 0),v5.set(this,void 0),ZJ(this,v5,new Uint8Array(16),"f"),y5(this,v5,"f").fill(0),ZJ(this,FU,y5(this,v5,"f"),"f"),ZJ(this,bY,16,"f"),Y==null)Y=1;if(typeof Y==="number")this.setCounterValue(Y);else this.setCounterBytes(Y)}get counter(){return new Uint8Array(y5(this,v5,"f"))}setCounterValue(W){if(!Number.isInteger(W)||W<0||W>Number.MAX_SAFE_INTEGER)throw TypeError("invalid counter initial integer value");for(let Y=15;Y>=0;--Y)y5(this,v5,"f")[Y]=W%256,W=Math.floor(W/256)}setCounterBytes(W){if(W.length!==16)throw TypeError("invalid counter initial Uint8Array value length");y5(this,v5,"f").set(W)}increment(){for(let W=15;W>=0;W--)if(y5(this,v5,"f")[W]===255)y5(this,v5,"f")[W]=0;else{y5(this,v5,"f")[W]++;break}}encrypt(W){var Y,G;let X=new Uint8Array(W);for(let J=0;J<X.length;J++){if(y5(this,bY,"f")===16)ZJ(this,FU,this.aes.encrypt(y5(this,v5,"f")),"f"),ZJ(this,bY,0,"f"),this.increment();X[J]^=y5(this,FU,"f")[ZJ(this,bY,(G=y5(this,bY,"f"),Y=G++,G),"f"),Y]}return X}decrypt(W){return this.encrypt(W)}}FU=new WeakMap,bY=new WeakMap,v5=new WeakMap;function WD(W){if(W.length<16)throw TypeError("PKCS#7 invalid length");let Y=W[W.length-1];if(Y>16)throw TypeError("PKCS#7 padding byte out of range");let G=W.length-Y;for(let X=0;X<Y;X++)if(W[G+X]!==Y)throw TypeError("PKCS#7 invalid padding byte");return new Uint8Array(W.subarray(0,G))}function YD(W){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;return Z7(W)}function VJ(W,Y){W=String(W);while(W.length<Y)W="0"+W;return W}function mY(W){if(typeof W==="string")return M9(W,"NFKC");return Z7(W)}function D8(W,Y){let G=Y.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);r(G!=null,"invalid path","path",Y);let X=G[1],J=G[3],Z=G[4]==="!",V=W;for(let U of X.toLowerCase().split(".")){if(Array.isArray(V)){if(!U.match(/^[0-9]+$/))break;V=V[parseInt(U)]}else if(typeof V==="object"){let Q=null;for(let H in V)if(H.toLowerCase()===U){Q=V[H];break}V=Q}else V=null;if(V==null)break}if(r(!Z||V!=null,"missing required value","path",X),J&&V!=null){if(J==="int"){if(typeof V==="string"&&V.match(/^-?[0-9]+$/))return parseInt(V);else if(Number.isSafeInteger(V))return V}if(J==="number"){if(typeof V==="string"&&V.match(/^-?[0-9.]*$/))return parseFloat(V)}if(J==="data"){if(typeof V==="string")return YD(V)}if(J==="array"&&Array.isArray(V))return V;if(J===typeof V)return V;r(!1,`wrong type found for ${J} `,"path",X)}return V}var D_="m/44'/60'/0'/0/0";function JA(W){try{let Y=JSON.parse(W);if((Y.version!=null?parseInt(Y.version):0)===3)return!0}catch(Y){}return!1}function Ht(W,Y,G){if(D8(W,"crypto.cipher:string")==="aes-128-ctr"){let J=D8(W,"crypto.cipherparams.iv:data!"),Z=new HW(Y,J);return C0(Z.decrypt(G))}X1(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}function XA(W,Y){let G=B0(Y),X=D8(W,"crypto.ciphertext:data!"),J=C0(X8(t1([G.slice(16,32),X]))).substring(2);r(J===D8(W,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");let Z=Ht(W,G.slice(0,16),X),V=t4(Z);if(W.address){let H=W.address.toLowerCase();if(!H.startsWith("0x"))H="0x"+H;r(m1(H)===V,"keystore address/privateKey mismatch","address",W.address)}let U={address:V,privateKey:Z};if(D8(W,"x-ethers.version:string")==="0.1"){let H=G.slice(32,64),N=D8(W,"x-ethers.mnemonicCiphertext:data!"),A=D8(W,"x-ethers.mnemonicCounter:data!"),q=new HW(H,A);U.mnemonic={path:D8(W,"x-ethers.path:string")||D_,locale:D8(W,"x-ethers.locale:string")||"en",entropy:C0(B0(q.decrypt(N)))}}return U}function C_(W){let Y=D8(W,"crypto.kdf:string");if(Y&&typeof Y==="string"){if(Y.toLowerCase()==="scrypt"){let G=D8(W,"crypto.kdfparams.salt:data!"),X=D8(W,"crypto.kdfparams.n:int!"),J=D8(W,"crypto.kdfparams.r:int!"),Z=D8(W,"crypto.kdfparams.p:int!");r(X>0&&(X&X-1)===0,"invalid kdf.N","kdf.N",X),r(J>0&&Z>0,"invalid kdf","kdf",Y);let V=D8(W,"crypto.kdfparams.dklen:int!");return r(V===32,"invalid kdf.dklen","kdf.dflen",V),{name:"scrypt",salt:G,N:X,r:J,p:Z,dkLen:64}}else if(Y.toLowerCase()==="pbkdf2"){let G=D8(W,"crypto.kdfparams.salt:data!"),X=D8(W,"crypto.kdfparams.prf:string!"),J=X.split("-").pop();r(J==="sha256"||J==="sha512","invalid kdf.pdf","kdf.pdf",X);let Z=D8(W,"crypto.kdfparams.c:int!"),V=D8(W,"crypto.kdfparams.dklen:int!");return r(V===32,"invalid kdf.dklen","kdf.dklen",V),{name:"pbkdf2",salt:G,count:Z,dkLen:V,algorithm:J}}}r(!1,"unsupported key-derivation function","kdf",Y)}function GD(W,Y){let G=JSON.parse(W),X=mY(Y),J=C_(G);if(J.name==="pbkdf2"){let{salt:A,count:q,dkLen:z,algorithm:w}=J,D=F5(X,A,q,z,w);return XA(G,D)}X1(J.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:J});let{salt:Z,N:V,r:U,p:Q,dkLen:H}=J,N=VW(X,Z,V,U,Q,H);return XA(G,N)}function K_(W){return new Promise((Y)=>{setTimeout(()=>{Y()},W)})}async function XD(W,Y,G){let X=JSON.parse(W),J=mY(Y),Z=C_(X);if(Z.name==="pbkdf2"){if(G)G(0),await K_(0);let{salt:q,count:z,dkLen:w,algorithm:D}=Z,T=F5(J,q,z,w,D);if(G)G(1),await K_(0);return XA(X,T)}X1(Z.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:Z});let{salt:V,N:U,r:Q,p:H,dkLen:N}=Z,A=await ZW(J,V,U,Q,H,N,G);return XA(X,A)}function T_(W){let Y=W.salt!=null?B0(W.salt,"options.salt"):S5(32),G=131072,X=8,J=1;if(W.scrypt){if(W.scrypt.N)G=W.scrypt.N;if(W.scrypt.r)X=W.scrypt.r;if(W.scrypt.p)J=W.scrypt.p}return r(typeof G==="number"&&G>0&&Number.isSafeInteger(G)&&(BigInt(G)&BigInt(G-1))===BigInt(0),"invalid scrypt N parameter","options.N",G),r(typeof X==="number"&&X>0&&Number.isSafeInteger(X),"invalid scrypt r parameter","options.r",X),r(typeof J==="number"&&J>0&&Number.isSafeInteger(J),"invalid scrypt p parameter","options.p",J),{name:"scrypt",dkLen:32,salt:Y,N:G,r:X,p:J}}function R_(W,Y,G,X){let J=B0(G.privateKey,"privateKey"),Z=X.iv!=null?B0(X.iv,"options.iv"):S5(16);r(Z.length===16,"invalid options.iv length","options.iv",X.iv);let V=X.uuid!=null?B0(X.uuid,"options.uuid"):S5(16);r(V.length===16,"invalid options.uuid length","options.uuid",X.iv);let U=W.slice(0,16),Q=W.slice(16,32),H=new HW(U,Z),N=B0(H.encrypt(J)),A=X8(t1([Q,N])),q={address:G.address.substring(2).toLowerCase(),id:$q(V),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:C0(Z).substring(2)},ciphertext:C0(N).substring(2),kdf:"scrypt",kdfparams:{salt:C0(Y.salt).substring(2),n:Y.N,dklen:32,p:Y.p,r:Y.r},mac:A.substring(2)}};if(G.mnemonic){let z=X.client!=null?X.client:`ethers/${Dq}`,w=G.mnemonic.path||D_,D=G.mnemonic.locale||"en",T=W.slice(32,64),x=B0(G.mnemonic.entropy,"account.mnemonic.entropy"),g=S5(16),f=new HW(T,g),y=B0(f.encrypt(x)),p=new Date,m="UTC--"+(p.getUTCFullYear()+"-"+VJ(p.getUTCMonth()+1,2)+"-"+VJ(p.getUTCDate(),2)+"T"+VJ(p.getUTCHours(),2)+"-"+VJ(p.getUTCMinutes(),2)+"-"+VJ(p.getUTCSeconds(),2)+".0Z")+"--"+q.address;q["x-ethers"]={client:z,gethFilename:m,path:w,locale:D,mnemonicCounter:C0(g).substring(2),mnemonicCiphertext:C0(y).substring(2),version:"0.1"}}return JSON.stringify(q)}function SU(W,Y,G){if(G==null)G={};let X=mY(Y),J=T_(G),Z=VW(X,J.salt,J.N,J.r,J.p,64);return R_(B0(Z),J,W,G)}async function xU(W,Y,G){if(G==null)G={};let X=mY(Y),J=T_(G),Z=await ZW(X,J.salt,J.N,J.r,J.p,64,G.progressCallback);return R_(B0(Z),J,W,G)}var kU="m/44'/60'/0'/0/0",Nt=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),NW=2147483648,qt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),At="0123456789abcdef";function ZA(W,Y){let G="";while(W)G=At[W%16]+G,W=Math.trunc(W/16);while(G.length<Y*2)G="0"+G;return"0x"+G}function JD(W){let Y=B0(W),G=iX(L9(L9(Y)),0,4),X=t1([Y,G]);return Bq(X)}var a7={};function M_(W,Y,G,X){let J=new Uint8Array(37);if(W&NW)X1(X!=null,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),J.set(B0(X),1);else J.set(B0(G));for(let V=24;V>=0;V-=8)J[33+(V>>3)]=W>>24-V&255;let Z=B0(YW("sha512",Y,J));return{IL:Z.slice(0,32),IR:Z.slice(32)}}function P_(W,Y){let G=Y.split("/");if(r(G.length>0,"invalid path","path",Y),G[0]==="m")r(W.depth===0,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${W.depth}`,"path",Y),G.shift();let X=W;for(let J=0;J<G.length;J++){let Z=G[J];if(Z.match(/^[0-9]+'$/)){let V=parseInt(Z.substring(0,Z.length-1));r(V<NW,"invalid path index",`path[${J}]`,Z),X=X.deriveChild(NW+V)}else if(Z.match(/^[0-9]+$/)){let V=parseInt(Z);r(V<NW,"invalid path index",`path[${J}]`,Z),X=X.deriveChild(V)}else r(!1,"invalid path component",`path[${J}]`,Z)}return X}class U9 extends hY{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(W,Y,G,X,J,Z,V,U,Q){super(Y,Q);d4(W,a7,"HDNodeWallet"),H8(this,{publicKey:Y.compressedPublicKey});let H=iX(GW(L9(this.publicKey)),0,4);H8(this,{parentFingerprint:G,fingerprint:H,chainCode:X,path:J,index:Z,depth:V}),H8(this,{mnemonic:U})}connect(W){return new U9(a7,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,W)}#W(){let W={address:this.address,privateKey:this.privateKey},Y=this.mnemonic;if(this.path&&Y&&Y.wordlist.locale==="en"&&Y.password==="")W.mnemonic={path:this.path,locale:"en",entropy:Y.entropy};return W}async encrypt(W,Y){return await xU(this.#W(),W,{progressCallback:Y})}encryptSync(W){return SU(this.#W(),W)}get extendedKey(){return X1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),JD(t1(["0x0488ADE4",ZA(this.depth,1),this.parentFingerprint,ZA(this.index,4),this.chainCode,t1(["0x00",this.privateKey])]))}hasPath(){return this.path!=null}neuter(){return new fY(a7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(W){let Y=r8(W,"index");r(Y<=4294967295,"invalid index","index",Y);let G=this.path;if(G){if(G+="/"+(Y&~NW),Y&NW)G+="'"}let{IR:X,IL:J}=M_(Y,this.chainCode,this.publicKey,this.privateKey),Z=new o8(V7((aX(J)+BigInt(this.privateKey))%qt,32));return new U9(a7,Z,this.fingerprint,C0(X),G,Y,this.depth+1,this.mnemonic,this.provider)}derivePath(W){return P_(this,W)}static#Y(W,Y){r(n7(W),"invalid seed","seed","[REDACTED]");let G=B0(W,"seed");r(G.length>=16&&G.length<=64,"invalid seed","seed","[REDACTED]");let X=B0(YW("sha512",Nt,G)),J=new o8(C0(X.slice(0,32)));return new U9(a7,J,"0x00000000",C0(X.slice(32)),"m",0,0,Y,null)}static fromExtendedKey(W){let Y=N8(Eq(W));r(Y.length===82||JD(Y.slice(0,78))===W,"invalid extended key","extendedKey","[ REDACTED ]");let G=Y[4],X=C0(Y.slice(5,9)),J=parseInt(C0(Y.slice(9,13)).substring(2),16),Z=C0(Y.slice(13,45)),V=Y.slice(45,78);switch(C0(Y.slice(0,4))){case"0x0488b21e":case"0x043587cf":{let U=C0(V);return new fY(a7,t4(U),U,X,Z,null,J,G,null)}case"0x0488ade4":case"0x04358394 ":if(V[0]!==0)break;return new U9(a7,new o8(V.slice(1)),X,Z,null,J,G,null,null)}r(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(W,Y,G){if(W==null)W="";if(Y==null)Y=kU;if(G==null)G=W6.wordlist();let X=Y6.fromEntropy(S5(16),W,G);return U9.#Y(X.computeSeed(),X).derivePath(Y)}static fromMnemonic(W,Y){if(!Y)Y=kU;return U9.#Y(W.computeSeed(),W).derivePath(Y)}static fromPhrase(W,Y,G,X){if(Y==null)Y="";if(G==null)G=kU;if(X==null)X=W6.wordlist();let J=Y6.fromPhrase(W,Y,X);return U9.#Y(J.computeSeed(),J).derivePath(G)}static fromSeed(W){return U9.#Y(W,null)}}class fY extends LU{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(W,Y,G,X,J,Z,V,U,Q){super(Y,Q);d4(W,a7,"HDNodeVoidWallet"),H8(this,{publicKey:G});let H=iX(GW(L9(G)),0,4);H8(this,{publicKey:G,fingerprint:H,parentFingerprint:X,chainCode:J,path:Z,index:V,depth:U})}connect(W){return new fY(a7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,W)}get extendedKey(){return X1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),JD(t1(["0x0488B21E",ZA(this.depth,1),this.parentFingerprint,ZA(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return this.path!=null}deriveChild(W){let Y=r8(W,"index");r(Y<=4294967295,"invalid index","index",Y);let G=this.path;if(G){if(G+="/"+(Y&~NW),Y&NW)G+="'"}let{IR:X,IL:J}=M_(Y,this.chainCode,this.publicKey,null),Z=o8.addPoints(J,this.publicKey,!0),V=t4(Z);return new fY(a7,V,Z,this.fingerprint,C0(X),G,Y,this.depth+1,this.provider)}derivePath(W){return P_(this,W)}}function VA(W){try{if(JSON.parse(W).encseed)return!0}catch(Y){}return!1}function UA(W,Y){let G=JSON.parse(W),X=mY(Y),J=m1(D8(G,"ethaddr:string!")),Z=YD(D8(G,"encseed:string!"));r(Z&&Z.length%16===0,"invalid encseed","json",W);let V=B0(F5(X,X,2000,32,"sha256")).slice(0,16),U=Z.slice(0,16),Q=Z.slice(16),H=new $U(V,U),N=WD(B0(H.decrypt(Q))),A="";for(let q=0;q<N.length;q++)A+=String.fromCharCode(N[q]);return{address:J,privateKey:e4(A)}}function L_(W){return new Promise((Y)=>{setTimeout(()=>{Y()},W)})}class X6 extends hY{constructor(W,Y){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;let G=typeof W==="string"?new o8(W):W;super(G,Y)}connect(W){return new X6(this.signingKey,W)}async encrypt(W,Y){let G={address:this.address,privateKey:this.privateKey};return await xU(G,W,{progressCallback:Y})}encryptSync(W){let Y={address:this.address,privateKey:this.privateKey};return SU(Y,W)}static#W(W){if(r(W,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in W&&W.mnemonic&&W.mnemonic.locale==="en"){let G=Y6.fromEntropy(W.mnemonic.entropy),X=U9.fromMnemonic(G,W.mnemonic.path);if(X.address===W.address&&X.privateKey===W.privateKey)return X;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}let Y=new X6(W.privateKey);return r(Y.address===W.address,"address/privateKey mismatch","json","[ REDACTED ]"),Y}static async fromEncryptedJson(W,Y,G){let X=null;if(JA(W))X=await XD(W,Y,G);else if(VA(W)){if(G)G(0),await L_(0);if(X=UA(W,Y),G)G(1),await L_(0)}return X6.#W(X)}static fromEncryptedJsonSync(W,Y){let G=null;if(JA(W))G=GD(W,Y);else if(VA(W))G=UA(W,Y);else r(!1,"invalid JSON wallet","json","[ REDACTED ]");return X6.#W(G)}static createRandom(W){let Y=U9.createRandom();if(W)return Y.connect(W);return Y}static fromPhrase(W,Y){let G=U9.fromPhrase(W);if(Y)return G.connect(Y);return G}}function B_(W,Y=[]){let G=String(W??"").trim();if(!G)throw Error("sm-server: signing key required (GDB_SM_KEY)");let X=G.includes(" ")?U9.fromPhrase(G):new X6(G),J=m1(X.address),Z=new Set([...Y,J].map((N)=>{try{return m1(N)}catch{return null}}).filter(Boolean)),V=(N)=>{let A=(q)=>q&&typeof q==="object"&&!Array.isArray(q)?Object.keys(q).sort().reduce((z,w)=>(z[w]=A(q[w]),z),{}):Array.isArray(q)?q.map(A):q;return JSON.stringify(A(N))};return{address:J,superAdmins:Z,canonicalize:V,signOps:async(N)=>{let A=[];for(let q of N){if(q?.signature&&q?.originEthAddress&&q?.originUser){A.push(q);continue}let z={...q,originUser:J},w=await X.signMessage(M9(V(z)));A.push({...q,originUser:J,originEthAddress:J,signature:w})}return A},verifyOp:(N)=>{if(!N?.signature||!N?.originEthAddress||!N?.originUser)return{ok:!1,reason:"missing-fields"};let A;try{if(A=m1(N.originEthAddress),m1(N.originUser)!==A)return{ok:!1,reason:"address-mismatch"}}catch{return{ok:!1,reason:"invalid-address"}}let{signature:q,originEthAddress:z,...w}=N;try{let D=rq(M9(V(w)),q);if(m1(D)!==A)return{ok:!1,reason:"invalid-signature"};let{originUser:T,...x}=w;return{ok:!0,normalizedOriginEthAddress:A,payload:x}}catch(D){return{ok:!1,reason:"verify-error",error:D}}},isSuperAdmin:(N)=>{try{return Z.has(m1(N))}catch{return!1}}}}var wt=["guest","user","manager","admin","superadmin"];function E_(W,Y,G,{intervalMs:X=4000,settleMs:J=15000,customRoles:Z=null}={}){let V=new Set([...wt,...Object.keys(Z??{})]),U=async(A,q,z=null)=>{let w=m1(A);if(!V.has(q))throw Error(`Role '${q}' is not a defined role.`);let D=`user:${w}`,T=(await W.get(D)).result?.value||{};await W.put({...T,ethAddress:w,role:q,assignedByEthAddress:Y.address,expiresAt:z?new Date(z).toISOString():null,priority:!0},D)},Q=async()=>{let A=new Map;for(let q of G){let z=q.then?.assignRole;if(!z)continue;let w=[];try{({results:w=[]}=W.map({query:q.if}))}catch(D){console.error("\u274C GOVERNANCE: rule evaluation failed:",D.message);continue}for(let D of w){if(!D.id.startsWith("user:"))continue;if(Y.isSuperAdmin(D.id.slice(5)))continue;if(q.offsetTimestamp&&(D.timestamp?.physical??0)>Date.now()-q.offsetTimestamp)continue;A.set(D.id,{role:z,current:D.value?.role})}}for(let[q,{role:z,current:w}]of A){if(w===z)continue;try{await U(q.slice(5),z),console.info(`\uD83D\uDCDC GOVERNANCE: ${q.slice(5)} '${w}' -> '${z}'`)}catch(D){console.error("\u274C GOVERNANCE: assignRole failed:",D.message)}}},H=null,N=setTimeout(()=>{H=setInterval(Q,X),console.info(`\uD83D\uDCDC GOVERNANCE ENGINE: active \u2014 ${G.length} rule(s), every ${X} ms.`)},J);return{assignRole:U,stop:()=>{if(clearTimeout(N),H)clearInterval(H)}}}var VD=(W)=>W&&typeof W==="object"?structuredClone(W):W,ZD=(W,Y=16)=>{let G=null,X=null;return(...J)=>{if(X??=Promise.withResolvers(),G!==null)clearTimeout(G);return G=setTimeout(async()=>{G=null;try{X.resolve(await W(...J))}catch(Z){X.reject(Z)}finally{X=null}},Y),X.promise}},Dt=(W)=>{let Y=!1;return()=>{if(Y)return;Y=!0,setImmediate(()=>{Y=!1,W()})}};function Ct(W=1000){let Y=[];return{add(G){if(G?.timestamp){if(Y.push(G),Y.length>W)Y.splice(0,Y.length-W)}},getOldest:()=>Y[0]??null,getDelta:(G,X)=>G?Y.filter((J)=>X(J.timestamp,G)>0):[...Y],clear(){Y=[]},entries:()=>[...Y],setEntries(G=[]){if(Y=Array.isArray(G)?[...G]:[],Y.length>W)Y.splice(0,Y.length-W)}}}function Tt(){let W={nodes:{}};return{get nodes(){return W.nodes},set nodes(Y){W.nodes=Y??{}},upsert(Y,G,X){let J=W.nodes[Y];W.nodes[Y]={id:Y,value:VD(G),edges:J?.edges?[...J.edges]:[],timestamp:X}},get:(Y)=>W.nodes[Y]??null,link(Y,G,X){let J=W.nodes[Y],Z=W.nodes[G];if(J&&Z&&!J.edges.includes(G))W.nodes[Y]={...J,edges:[...J.edges,G],timestamp:X}},getAllNodes:()=>Object.values(W.nodes),serialize:()=>WG.deflate(uU(W.nodes)),deserialize(Y){let G=Y instanceof Uint8Array?Y:new Uint8Array(Y);W.nodes=qW(WG.inflate(G))}}}function Rt(W,Y){let G=Kt(W);if(G&&G!==".")Ot(G,{recursive:!0});let X=new jt(W);X.exec("PRAGMA journal_mode = WAL"),X.exec("PRAGMA synchronous = NORMAL"),X.exec(`
|
|
251
|
+
`)!==this.#Y)throw Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#G=W}return this.#G}getWord(W){let Y=this.#X();return r(W>=0&&W<Y.length,`invalid word index: ${W}`,"index",W),Y[W]}getWordIndex(W){return this.#X().indexOf(W)}}var os="0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly,Ch%Ci|G G!GryIm$K!Noun)Nu$O` Sw T&naTiqueXietyY1ArtOlogyPe?P!Pro=Ril1ChCt-EaEnaGueMMedM%MyOundR<+Re,Ri=RowTTefa@Ti,Tw%k0KPe@SaultSetSi,SumeThma0H!>OmTa{T&dT.udeTra@0Ct]D.Gu,NtTh%ToTumn0Era+OcadoOid0AkeA*AyEsomeFulKw?d0Is:ByChel%C#D+GL<)Lc#y~MbooN<aNn RRelyRga(R*lSeS-SketTt!3A^AnAutyCau'ComeEfF%eG(Ha=H(dLie=LowLtN^Nef./TrayTt Twe&Y#d3Cyc!DKeNdOlogyRdR`Tt _{AdeAmeAnketA,EakE[IndOodO[omOu'UeUrUsh_rdAtDyIlMbNeNusOkO,Rd R(gRrowSsTtomUn)XY_{etA(AndA[A=EadEezeI{Id+IefIghtIngIskOccoliOk&OnzeOomO` OwnUsh2Bb!DdyD+tFf$oIldLbLkL!tNd!Nk Rd&Rg R,SS(e[SyTt Y Zz:Bba+B(B!CtusGeKe~LmM aMpNN$N)lNdyNn#NoeNvasNy#Pab!P.$Pta(RRb#RdRgoRpetRryRtSeShS(o/!Su$TT$ogT^Teg%yTt!UghtU'Ut]Ve3Il(gL yM|NsusNturyRe$Rta(_irAlkAmp]An+AosApt Ar+A'AtEapE{Ee'EfErryE,I{&IefIldIm}yOi)Oo'R#-U{!UnkUrn0G?Nnam#Rc!Tiz&TyVil_imApArifyAwAyE<ErkEv I{I|IffImbIn-IpO{OgO'O`OudOwnUbUmpU, Ut^_^A,C#utDeFfeeIlInL!@L%LumnMb(eMeMf%tM-Mm#Mp<yNc tNdu@NfirmNg*[N}@Nsid NtrolNv()OkOlPp PyR$ReRnR*@/Tt#U^UntryUp!Ur'Us(V Yo>_{Ad!AftAmA}AshAt AwlAzyEamEd.EekEwI{etImeIspIt-OpO[Ou^OwdUci$UelUi'Umb!Un^UshYY,$2BeLtu*PPbo?dRiousRr|Rta(R=Sh]/omTe3C!:DMa+MpN)Ng R(gShUght WnY3AlBa>BrisCadeCemb CideCl(eC%a>C*a'ErF&'F(eFyG*eLayLiv M<dMi'Ni$Nti,NyP?tP&dPos.P`PutyRi=ScribeS tSignSkSpair/royTailTe@VelopVi)Vo>3AgramAlAm#dAryCeE'lEtFf G.$Gn.yLemmaNn NosaurRe@RtSag*eScov Sea'ShSmi[S%d Splay/<)V tVideV%)Zzy5Ct%Cum|G~Lph(Ma(Na>NkeyN%OrSeUb!Ve_ftAg#AmaA,-AwEamE[IftIllInkIpI=OpUmY2CkMbNeR(g/T^Ty1Arf1Nam-:G G!RlyRnR`Sily/Sy1HoOlogyOnomy0GeItUca>1F%t0G1GhtTh 2BowD E@r-Eg<tEm|Eph<tEvat%I>Se0B?kBodyBra)Er+Ot]PloyPow Pty0Ab!A@DD![D%'EmyErgyF%)Ga+G(eH<)JoyLi,OughR-hRollSu*T Ti*TryVelope1Isode0U$Uip0AA'OdeOs]R%Upt0CapeSayS&)Ta>0Ern$H-s1Id&)IlOkeOl=1A@Amp!Ce[Ch<+C.eCludeCu'Ecu>Erci'Hau,Hib.I!I,ItOt-P<dPe@Pi*Pla(Po'P*[T&dTra0EEbrow:Br-CeCultyDeIntI`~L'MeMilyMousNNcyNtasyRmSh]TT$Th TigueUltV%.e3Atu*Bru?yD $EEdElMa!N)/iv$T^V W3B Ct]EldGu*LeLmLt N$NdNeNg NishReRmR,Sc$ShTT}[X_gAmeAshAtAv%EeIghtIpOatO{O%Ow UidUshY_mCusGIlLd~owOdOtR)Re,R+tRkRtu}RumRw?dSsil/ UndX_gi!AmeEqu|EshI&dIn+OgOntO,OwnOz&U.2ElNNnyRna)RyTu*:D+tInLaxy~ yMePRa+Rba+Rd&Rl-Rm|SSpTeTh U+Ze3N $NiusN*Nt!Nu(e/u*2O,0AntFtGg!Ng RaffeRlVe_dAn)A*A[IdeImp'ObeOomOryO=OwUe_tDde[LdOdO'RillaSpelSsipV nWn_bA)A(AntApeA[Av.yEatE&IdIefItOc yOupOwUnt_rdE[IdeIltIt?N3M:B.IrLfMm M, NdPpyRb%RdRshR=,TVeWkZ?d3AdAl`ArtAvyD+hogIght~oLmetLpNRo3Dd&Gh~NtPRe/%y5BbyCkeyLdLeLiday~owMeNeyOdPeRnRr%R'Sp.$/TelUrV 5BGeM<Mb!M%Nd*dNgryNtRd!RryRtSb<d3Brid:1EOn0EaEntifyLe2N%e4LLeg$L}[0A+Ita>M&'Mu}Pa@Po'Pro=Pul'0ChCludeComeC*a'DexD-a>Do%Du,ryF<tFl-tF%mHa!H .Iti$Je@JuryMa>N Noc|PutQuiryS<eSe@SideSpi*/$lTa@T e,ToVe,V.eVol=3On0L<dOla>Sue0Em1Ory:CketGu?RZz3AlousAns~yWel9BInKeUr}yY5D+I)MpNg!Ni%Nk/:Ng?oo3EnEpT^upY3CkDD}yNdNgdomSsTT^&TeTt&Wi4EeIfeO{Ow:BBelB%Dd DyKeMpNgua+PtopR+T T(UghUndryVaWWnWsu.Y Zy3Ad AfArnA=Ctu*FtGG$G&dIsu*M#NdNg`NsOp?dSs#Tt Vel3ArB tyBr?yC&'FeFtGhtKeMbM.NkOnQuid/Tt!VeZ?d5AdAnB, C$CkG-NelyNgOpTt yUdUn+VeY$5CkyGga+Mb N?N^Xury3R-s:Ch(eDG-G}tIdIlInJ%KeMm$NNa+Nda>NgoNs]Nu$P!Rb!R^Rg(R(eRketRria+SkSs/ T^T i$ThTrixTt XimumZe3AdowAnAsu*AtCh<-D$DiaLodyLtMb M%yNt]NuRcyR+R.RryShSsa+T$Thod3Dd!DnightLk~]M-NdNimumN%Nu>Rac!Rr%S ySs/akeXXedXtu*5Bi!DelDifyMM|N.%NkeyN, N`OnR$ReRn(gSqu.oTh T]T%Unta(U'VeVie5ChFf(LeLtiplySc!SeumShroomS-/Tu$3Self/ yTh:I=MePk(Rrow/yT]Tu*3ArCkEdGati=G!@I` PhewR=/TTw%kUtr$V WsXt3CeGht5B!I'M(eeOd!Rm$R`SeTab!TeTh(gTi)VelW5C!?Mb R'T:K0EyJe@Li+Scu*S =Ta(Vious0CurE<Tob 0Or1FF Fi)T&2L1Ay0DI=Ymp-0It0CeEI#L(eLy1EnEraIn]Po'T]1An+B.Ch?dD D(?yG<I|Ig($Ph<0Tr-h0H 0Tdo%T TputTside0AlEnEr0NN 0Yg&0/ 0O}:CtDd!GeIrLa)LmNdaNelN-N` P RadeR|RkRrotRtySsT^ThTi|TrolTt nU'VeYm|3A)AnutArAs<tL-<NN$tyNcilOp!Pp Rfe@Rm.Rs#T2O}OtoRa'Ys-$0AnoCn-Ctu*E)GGe#~LotNkO} Pe/olT^Zza_)A}tA,-A>AyEa'Ed+U{UgUn+2EmEtIntL?LeLi)NdNyOlPul?Rt]S.]Ssib!/TatoTt yV tyWd W _@i)Ai'Ed-tEf Epa*Es|EttyEv|I)IdeIm?yIntI%.yIs#Iva>IzeOb!mO)[Odu)Of.OgramOje@Omo>OofOp tyOsp O>@OudOvide2Bl-Dd(g~LpL'Mpk(N^PilPpyR^a'R.yRpo'R'ShTZz!3Ramid:99Al.yAntumArt E,]I{ItIzO>:Bb.Cco#CeCkD?DioIlInI'~yMpN^NdomN+PidReTeTh V&WZ%3AdyAlAs#BelBuildC$lCei=CipeC%dCyc!Du)F!@F%mFu'G]G*tGul?Je@LaxLea'LiefLyMa(Memb M(dMo=Nd NewNtOp&PairPeatPla)P%tQui*ScueSemb!Si,Sour)Sp#'SultTi*T*atTurnUn]Ve$ViewW?d2Y`m0BBb#CeChDeD+F!GhtGidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOg<OtOwUsh0AllArtI!OkeOo`0A{AkeApIffOw0ApCc Ci$CkDaFtL?Ldi LidLut]L=Me#eNgOnRryRtUlUndUpUr)U`0A)A*Ati$AwnEakEci$EedEllEndH eI)Id IkeInIr.L.OilOns%O#OrtOtRayReadR(gY0Ua*UeezeUir*l_b!AdiumAffA+AirsAmpAndArtA>AyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NN<tNnisNtRm/Xt_nkAtEmeEnE%yE*EyIngIsOughtReeRi=RowUmbUnd 0CketDeG LtMb MeNyPRedSsueT!5A,BaccoDayDdl EGe` I!tK&MatoM%rowNeNgueNightOlO`PP-Pp!R^RnadoRtoi'SsT$Uri,W?dW WnY_{AdeAff-Ag-A(Ansf ApAshA=lAyEatEeEndI$IbeI{Igg ImIpOphyOub!U{UeUlyUmpetU,U`Y2BeIt]Mb!NaN}lRkeyRnRt!1El=EntyI)InI,O1PeP-$:5Ly5B*lla0Ab!Awa*C!Cov D DoFairFoldHappyIf%mIqueItIv 'KnownLo{TilUsu$Veil1Da>GradeHoldOnP Set1B<Ge0A+EEdEfulE![U$0Il.y:C<tCuumGueLidL!yL=NNishP%Rious/Ult3H-!L=tNd%Ntu*NueRbRifyRs]RyS'lT <3Ab!Br<tCiousCt%yDeoEw~a+Nta+Ol(Rtu$RusSaS.Su$T$Vid5C$I)IdLc<oLumeTeYa+:GeG#ItLk~LnutNtRfa*RmRri%ShSp/eT VeY3Al`Ap#ArA'lA` BDd(gEk&dIrdLcome/T_!AtEatEelEnE*IpIsp 0DeD`FeLd~NNdowNeNgNkNn Nt ReSdomSeShT}[5LfM<Nd OdOlRdRkRldRryR`_pE{E,!I,I>Ong::Rd3Ar~ow9UUngU`:3BraRo9NeO",ns="0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60",iK=null;class W6 extends nK{constructor(){super("en",os,ns)}static wordlist(){if(iK==null)iK=new W6;return iK}}function O_(W){return(1<<W)-1<<8-W&255}function is(W){return(1<<W)-1&255}function rK(W,Y){if(nX("NFKD"),Y==null)Y=W6.wordlist();let G=Y.split(W);r(G.length%3===0&&G.length>=12&&G.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");let X=new Uint8Array(Math.ceil(11*G.length/8)),J=0;for(let H=0;H<G.length;H++){let N=Y.getWordIndex(G[H].normalize("NFKD"));r(N>=0,`invalid mnemonic word at index ${H}`,"mnemonic","[ REDACTED ]");for(let A=0;A<11;A++){if(N&1<<10-A)X[J>>3]|=1<<7-J%8;J++}}let Z=32*G.length/3,V=G.length/3,U=O_(V),Q=B0(L9(X.slice(0,Z/8)))[0]&U;return r(Q===(X[X.length-1]&U),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),C0(X.slice(0,Z/8))}function aK(W,Y){if(r(W.length%4===0&&W.length>=16&&W.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),Y==null)Y=W6.wordlist();let G=[0],X=11;for(let V=0;V<W.length;V++)if(X>8)G[G.length-1]<<=8,G[G.length-1]|=W[V],X-=8;else G[G.length-1]<<=X,G[G.length-1]|=W[V]>>8-X,G.push(W[V]&is(8-X)),X+=3;let J=W.length/4,Z=parseInt(L9(W).substring(2,4),16)&O_(J);return G[G.length-1]<<=J,G[G.length-1]|=Z>>8-J,Y.join(G.map((V)=>Y.getWord(V)))}var sK={};class Y6{phrase;password;wordlist;entropy;constructor(W,Y,G,X,J){if(X==null)X="";if(J==null)J=W6.wordlist();d4(W,sK,"Mnemonic"),H8(this,{phrase:G,password:X,wordlist:J,entropy:Y})}computeSeed(){let W=M9("mnemonic"+this.password,"NFKD");return F5(M9(this.phrase,"NFKD"),W,2048,64,"sha512")}static fromPhrase(W,Y,G){let X=rK(W,G);return W=aK(B0(X),G),new Y6(sK,X,W,Y,G)}static fromEntropy(W,Y,G){let X=B0(W,"entropy"),J=aK(X,G);return new Y6(sK,C0(X),J,Y,G)}static entropyToPhrase(W,Y){let G=B0(W,"entropy");return aK(G,Y)}static phraseToEntropy(W,Y){return rK(W,Y)}static isValidMnemonic(W,Y){try{return rK(W,Y),!0}catch(G){}return!1}}/*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */var V9=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},tK=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},WA,_5,r7,rs={16:10,24:12,32:14},as=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],k5=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],eq=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],ss=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],ts=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],es=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],Wt=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],Yt=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],Gt=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],Xt=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239000,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],Jt=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998000,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],Zt=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],Vt=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],Ut=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239000,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],Qt=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998000,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function eK(W){let Y=[];for(let G=0;G<W.length;G+=4)Y.push(W[G]<<24|W[G+1]<<16|W[G+2]<<8|W[G+3]);return Y}class YA{get key(){return V9(this,WA,"f").slice()}constructor(W){if(WA.set(this,void 0),_5.set(this,void 0),r7.set(this,void 0),!(this instanceof YA))throw Error("AES must be instanitated with `new`");tK(this,WA,new Uint8Array(W),"f");let Y=rs[this.key.length];if(Y==null)throw TypeError("invalid key size (must be 16, 24 or 32 bytes)");tK(this,r7,[],"f"),tK(this,_5,[],"f");for(let H=0;H<=Y;H++)V9(this,r7,"f").push([0,0,0,0]),V9(this,_5,"f").push([0,0,0,0]);let G=(Y+1)*4,X=this.key.length/4,J=eK(this.key),Z;for(let H=0;H<X;H++)Z=H>>2,V9(this,r7,"f")[Z][H%4]=J[H],V9(this,_5,"f")[Y-Z][H%4]=J[H];let V=0,U=X,Q;while(U<G){if(Q=J[X-1],J[0]^=k5[Q>>16&255]<<24^k5[Q>>8&255]<<16^k5[Q&255]<<8^k5[Q>>24&255]^as[V]<<24,V+=1,X!=8)for(let q=1;q<X;q++)J[q]^=J[q-1];else{for(let q=1;q<X/2;q++)J[q]^=J[q-1];Q=J[X/2-1],J[X/2]^=k5[Q&255]^k5[Q>>8&255]<<8^k5[Q>>16&255]<<16^k5[Q>>24&255]<<24;for(let q=X/2+1;q<X;q++)J[q]^=J[q-1]}let H=0,N,A;while(H<X&&U<G)N=U>>2,A=U%4,V9(this,r7,"f")[N][A]=J[H],V9(this,_5,"f")[Y-N][A]=J[H++],U++}for(let H=1;H<Y;H++)for(let N=0;N<4;N++)Q=V9(this,_5,"f")[H][N],V9(this,_5,"f")[H][N]=Zt[Q>>24&255]^Vt[Q>>16&255]^Ut[Q>>8&255]^Qt[Q&255]}encrypt(W){if(W.length!=16)throw TypeError("invalid plaintext size (must be 16 bytes)");let Y=V9(this,r7,"f").length-1,G=[0,0,0,0],X=eK(W);for(let V=0;V<4;V++)X[V]^=V9(this,r7,"f")[0][V];for(let V=1;V<Y;V++){for(let U=0;U<4;U++)G[U]=ss[X[U]>>24&255]^ts[X[(U+1)%4]>>16&255]^es[X[(U+2)%4]>>8&255]^Wt[X[(U+3)%4]&255]^V9(this,r7,"f")[V][U];X=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=V9(this,r7,"f")[Y][V],J[4*V]=(k5[X[V]>>24&255]^Z>>24)&255,J[4*V+1]=(k5[X[(V+1)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(k5[X[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(k5[X[(V+3)%4]&255]^Z)&255;return J}decrypt(W){if(W.length!=16)throw TypeError("invalid ciphertext size (must be 16 bytes)");let Y=V9(this,_5,"f").length-1,G=[0,0,0,0],X=eK(W);for(let V=0;V<4;V++)X[V]^=V9(this,_5,"f")[0][V];for(let V=1;V<Y;V++){for(let U=0;U<4;U++)G[U]=Yt[X[U]>>24&255]^Gt[X[(U+3)%4]>>16&255]^Xt[X[(U+2)%4]>>8&255]^Jt[X[(U+1)%4]&255]^V9(this,_5,"f")[V][U];X=G.slice()}let J=new Uint8Array(16),Z=0;for(let V=0;V<4;V++)Z=V9(this,_5,"f")[Y][V],J[4*V]=(eq[X[V]>>24&255]^Z>>24)&255,J[4*V+1]=(eq[X[(V+3)%4]>>16&255]^Z>>16)&255,J[4*V+2]=(eq[X[(V+2)%4]>>8&255]^Z>>8)&255,J[4*V+3]=(eq[X[(V+1)%4]&255]^Z)&255;return J}}WA=new WeakMap,_5=new WeakMap,r7=new WeakMap;class BU{constructor(W,Y,G){if(G&&!(this instanceof G))throw Error(`${W} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new YA(Y)},name:{enumerable:!0,value:W}})}}var GA=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},JJ=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},EU,G6;class $U extends BU{constructor(W,Y){super("ECC",W,$U);if(EU.set(this,void 0),G6.set(this,void 0),Y){if(Y.length%16)throw TypeError("invalid iv size (must be 16 bytes)");GA(this,EU,new Uint8Array(Y),"f")}else GA(this,EU,new Uint8Array(16),"f");GA(this,G6,this.iv,"f")}get iv(){return new Uint8Array(JJ(this,EU,"f"))}encrypt(W){if(W.length%16)throw TypeError("invalid plaintext size (must be multiple of 16 bytes)");let Y=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){for(let X=0;X<16;X++)JJ(this,G6,"f")[X]^=W[G+X];GA(this,G6,this.aes.encrypt(JJ(this,G6,"f")),"f"),Y.set(JJ(this,G6,"f"),G)}return Y}decrypt(W){if(W.length%16)throw TypeError("invalid ciphertext size (must be multiple of 16 bytes)");let Y=new Uint8Array(W.length);for(let G=0;G<W.length;G+=16){let X=this.aes.decrypt(W.subarray(G,G+16));for(let J=0;J<16;J++)Y[G+J]=X[J]^JJ(this,G6,"f")[J],JJ(this,G6,"f")[J]=W[G+J]}return Y}}EU=new WeakMap,G6=new WeakMap;var ZJ=function(W,Y,G,X,J){if(X==="m")throw TypeError("Private method is not writable");if(X==="a"&&!J)throw TypeError("Private accessor was defined without a setter");if(typeof Y==="function"?W!==Y||!J:!Y.has(W))throw TypeError("Cannot write private member to an object whose class did not declare it");return X==="a"?J.call(W,G):J?J.value=G:Y.set(W,G),G},y5=function(W,Y,G,X){if(G==="a"&&!X)throw TypeError("Private accessor was defined without a getter");if(typeof Y==="function"?W!==Y||!X:!Y.has(W))throw TypeError("Cannot read private member from an object whose class did not declare it");return G==="m"?X:G==="a"?X.call(W):X?X.value:Y.get(W)},FU,bY,v5;class HW extends BU{constructor(W,Y){super("CTR",W,HW);if(FU.set(this,void 0),bY.set(this,void 0),v5.set(this,void 0),ZJ(this,v5,new Uint8Array(16),"f"),y5(this,v5,"f").fill(0),ZJ(this,FU,y5(this,v5,"f"),"f"),ZJ(this,bY,16,"f"),Y==null)Y=1;if(typeof Y==="number")this.setCounterValue(Y);else this.setCounterBytes(Y)}get counter(){return new Uint8Array(y5(this,v5,"f"))}setCounterValue(W){if(!Number.isInteger(W)||W<0||W>Number.MAX_SAFE_INTEGER)throw TypeError("invalid counter initial integer value");for(let Y=15;Y>=0;--Y)y5(this,v5,"f")[Y]=W%256,W=Math.floor(W/256)}setCounterBytes(W){if(W.length!==16)throw TypeError("invalid counter initial Uint8Array value length");y5(this,v5,"f").set(W)}increment(){for(let W=15;W>=0;W--)if(y5(this,v5,"f")[W]===255)y5(this,v5,"f")[W]=0;else{y5(this,v5,"f")[W]++;break}}encrypt(W){var Y,G;let X=new Uint8Array(W);for(let J=0;J<X.length;J++){if(y5(this,bY,"f")===16)ZJ(this,FU,this.aes.encrypt(y5(this,v5,"f")),"f"),ZJ(this,bY,0,"f"),this.increment();X[J]^=y5(this,FU,"f")[ZJ(this,bY,(G=y5(this,bY,"f"),Y=G++,G),"f"),Y]}return X}decrypt(W){return this.encrypt(W)}}FU=new WeakMap,bY=new WeakMap,v5=new WeakMap;function WD(W){if(W.length<16)throw TypeError("PKCS#7 invalid length");let Y=W[W.length-1];if(Y>16)throw TypeError("PKCS#7 padding byte out of range");let G=W.length-Y;for(let X=0;X<Y;X++)if(W[G+X]!==Y)throw TypeError("PKCS#7 invalid padding byte");return new Uint8Array(W.subarray(0,G))}function YD(W){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;return Z7(W)}function VJ(W,Y){W=String(W);while(W.length<Y)W="0"+W;return W}function mY(W){if(typeof W==="string")return M9(W,"NFKC");return Z7(W)}function D8(W,Y){let G=Y.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);r(G!=null,"invalid path","path",Y);let X=G[1],J=G[3],Z=G[4]==="!",V=W;for(let U of X.toLowerCase().split(".")){if(Array.isArray(V)){if(!U.match(/^[0-9]+$/))break;V=V[parseInt(U)]}else if(typeof V==="object"){let Q=null;for(let H in V)if(H.toLowerCase()===U){Q=V[H];break}V=Q}else V=null;if(V==null)break}if(r(!Z||V!=null,"missing required value","path",X),J&&V!=null){if(J==="int"){if(typeof V==="string"&&V.match(/^-?[0-9]+$/))return parseInt(V);else if(Number.isSafeInteger(V))return V}if(J==="number"){if(typeof V==="string"&&V.match(/^-?[0-9.]*$/))return parseFloat(V)}if(J==="data"){if(typeof V==="string")return YD(V)}if(J==="array"&&Array.isArray(V))return V;if(J===typeof V)return V;r(!1,`wrong type found for ${J} `,"path",X)}return V}var D_="m/44'/60'/0'/0/0";function JA(W){try{let Y=JSON.parse(W);if((Y.version!=null?parseInt(Y.version):0)===3)return!0}catch(Y){}return!1}function Ht(W,Y,G){if(D8(W,"crypto.cipher:string")==="aes-128-ctr"){let J=D8(W,"crypto.cipherparams.iv:data!"),Z=new HW(Y,J);return C0(Z.decrypt(G))}X1(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}function XA(W,Y){let G=B0(Y),X=D8(W,"crypto.ciphertext:data!"),J=C0(X8(t1([G.slice(16,32),X]))).substring(2);r(J===D8(W,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");let Z=Ht(W,G.slice(0,16),X),V=t4(Z);if(W.address){let H=W.address.toLowerCase();if(!H.startsWith("0x"))H="0x"+H;r(f1(H)===V,"keystore address/privateKey mismatch","address",W.address)}let U={address:V,privateKey:Z};if(D8(W,"x-ethers.version:string")==="0.1"){let H=G.slice(32,64),N=D8(W,"x-ethers.mnemonicCiphertext:data!"),A=D8(W,"x-ethers.mnemonicCounter:data!"),q=new HW(H,A);U.mnemonic={path:D8(W,"x-ethers.path:string")||D_,locale:D8(W,"x-ethers.locale:string")||"en",entropy:C0(B0(q.decrypt(N)))}}return U}function C_(W){let Y=D8(W,"crypto.kdf:string");if(Y&&typeof Y==="string"){if(Y.toLowerCase()==="scrypt"){let G=D8(W,"crypto.kdfparams.salt:data!"),X=D8(W,"crypto.kdfparams.n:int!"),J=D8(W,"crypto.kdfparams.r:int!"),Z=D8(W,"crypto.kdfparams.p:int!");r(X>0&&(X&X-1)===0,"invalid kdf.N","kdf.N",X),r(J>0&&Z>0,"invalid kdf","kdf",Y);let V=D8(W,"crypto.kdfparams.dklen:int!");return r(V===32,"invalid kdf.dklen","kdf.dflen",V),{name:"scrypt",salt:G,N:X,r:J,p:Z,dkLen:64}}else if(Y.toLowerCase()==="pbkdf2"){let G=D8(W,"crypto.kdfparams.salt:data!"),X=D8(W,"crypto.kdfparams.prf:string!"),J=X.split("-").pop();r(J==="sha256"||J==="sha512","invalid kdf.pdf","kdf.pdf",X);let Z=D8(W,"crypto.kdfparams.c:int!"),V=D8(W,"crypto.kdfparams.dklen:int!");return r(V===32,"invalid kdf.dklen","kdf.dklen",V),{name:"pbkdf2",salt:G,count:Z,dkLen:V,algorithm:J}}}r(!1,"unsupported key-derivation function","kdf",Y)}function GD(W,Y){let G=JSON.parse(W),X=mY(Y),J=C_(G);if(J.name==="pbkdf2"){let{salt:A,count:q,dkLen:z,algorithm:w}=J,D=F5(X,A,q,z,w);return XA(G,D)}X1(J.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:J});let{salt:Z,N:V,r:U,p:Q,dkLen:H}=J,N=VW(X,Z,V,U,Q,H);return XA(G,N)}function K_(W){return new Promise((Y)=>{setTimeout(()=>{Y()},W)})}async function XD(W,Y,G){let X=JSON.parse(W),J=mY(Y),Z=C_(X);if(Z.name==="pbkdf2"){if(G)G(0),await K_(0);let{salt:q,count:z,dkLen:w,algorithm:D}=Z,T=F5(J,q,z,w,D);if(G)G(1),await K_(0);return XA(X,T)}X1(Z.name==="scrypt","cannot be reached","UNKNOWN_ERROR",{params:Z});let{salt:V,N:U,r:Q,p:H,dkLen:N}=Z,A=await ZW(J,V,U,Q,H,N,G);return XA(X,A)}function T_(W){let Y=W.salt!=null?B0(W.salt,"options.salt"):S5(32),G=131072,X=8,J=1;if(W.scrypt){if(W.scrypt.N)G=W.scrypt.N;if(W.scrypt.r)X=W.scrypt.r;if(W.scrypt.p)J=W.scrypt.p}return r(typeof G==="number"&&G>0&&Number.isSafeInteger(G)&&(BigInt(G)&BigInt(G-1))===BigInt(0),"invalid scrypt N parameter","options.N",G),r(typeof X==="number"&&X>0&&Number.isSafeInteger(X),"invalid scrypt r parameter","options.r",X),r(typeof J==="number"&&J>0&&Number.isSafeInteger(J),"invalid scrypt p parameter","options.p",J),{name:"scrypt",dkLen:32,salt:Y,N:G,r:X,p:J}}function R_(W,Y,G,X){let J=B0(G.privateKey,"privateKey"),Z=X.iv!=null?B0(X.iv,"options.iv"):S5(16);r(Z.length===16,"invalid options.iv length","options.iv",X.iv);let V=X.uuid!=null?B0(X.uuid,"options.uuid"):S5(16);r(V.length===16,"invalid options.uuid length","options.uuid",X.iv);let U=W.slice(0,16),Q=W.slice(16,32),H=new HW(U,Z),N=B0(H.encrypt(J)),A=X8(t1([Q,N])),q={address:G.address.substring(2).toLowerCase(),id:$q(V),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:C0(Z).substring(2)},ciphertext:C0(N).substring(2),kdf:"scrypt",kdfparams:{salt:C0(Y.salt).substring(2),n:Y.N,dklen:32,p:Y.p,r:Y.r},mac:A.substring(2)}};if(G.mnemonic){let z=X.client!=null?X.client:`ethers/${Dq}`,w=G.mnemonic.path||D_,D=G.mnemonic.locale||"en",T=W.slice(32,64),x=B0(G.mnemonic.entropy,"account.mnemonic.entropy"),g=S5(16),f=new HW(T,g),y=B0(f.encrypt(x)),p=new Date,m="UTC--"+(p.getUTCFullYear()+"-"+VJ(p.getUTCMonth()+1,2)+"-"+VJ(p.getUTCDate(),2)+"T"+VJ(p.getUTCHours(),2)+"-"+VJ(p.getUTCMinutes(),2)+"-"+VJ(p.getUTCSeconds(),2)+".0Z")+"--"+q.address;q["x-ethers"]={client:z,gethFilename:m,path:w,locale:D,mnemonicCounter:C0(g).substring(2),mnemonicCiphertext:C0(y).substring(2),version:"0.1"}}return JSON.stringify(q)}function SU(W,Y,G){if(G==null)G={};let X=mY(Y),J=T_(G),Z=VW(X,J.salt,J.N,J.r,J.p,64);return R_(B0(Z),J,W,G)}async function xU(W,Y,G){if(G==null)G={};let X=mY(Y),J=T_(G),Z=await ZW(X,J.salt,J.N,J.r,J.p,64,G.progressCallback);return R_(B0(Z),J,W,G)}var kU="m/44'/60'/0'/0/0",Nt=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),NW=2147483648,qt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),At="0123456789abcdef";function ZA(W,Y){let G="";while(W)G=At[W%16]+G,W=Math.trunc(W/16);while(G.length<Y*2)G="0"+G;return"0x"+G}function JD(W){let Y=B0(W),G=iX(L9(L9(Y)),0,4),X=t1([Y,G]);return Bq(X)}var a7={};function M_(W,Y,G,X){let J=new Uint8Array(37);if(W&NW)X1(X!=null,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),J.set(B0(X),1);else J.set(B0(G));for(let V=24;V>=0;V-=8)J[33+(V>>3)]=W>>24-V&255;let Z=B0(YW("sha512",Y,J));return{IL:Z.slice(0,32),IR:Z.slice(32)}}function P_(W,Y){let G=Y.split("/");if(r(G.length>0,"invalid path","path",Y),G[0]==="m")r(W.depth===0,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${W.depth}`,"path",Y),G.shift();let X=W;for(let J=0;J<G.length;J++){let Z=G[J];if(Z.match(/^[0-9]+'$/)){let V=parseInt(Z.substring(0,Z.length-1));r(V<NW,"invalid path index",`path[${J}]`,Z),X=X.deriveChild(NW+V)}else if(Z.match(/^[0-9]+$/)){let V=parseInt(Z);r(V<NW,"invalid path index",`path[${J}]`,Z),X=X.deriveChild(V)}else r(!1,"invalid path component",`path[${J}]`,Z)}return X}class U9 extends hY{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(W,Y,G,X,J,Z,V,U,Q){super(Y,Q);d4(W,a7,"HDNodeWallet"),H8(this,{publicKey:Y.compressedPublicKey});let H=iX(GW(L9(this.publicKey)),0,4);H8(this,{parentFingerprint:G,fingerprint:H,chainCode:X,path:J,index:Z,depth:V}),H8(this,{mnemonic:U})}connect(W){return new U9(a7,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,W)}#W(){let W={address:this.address,privateKey:this.privateKey},Y=this.mnemonic;if(this.path&&Y&&Y.wordlist.locale==="en"&&Y.password==="")W.mnemonic={path:this.path,locale:"en",entropy:Y.entropy};return W}async encrypt(W,Y){return await xU(this.#W(),W,{progressCallback:Y})}encryptSync(W){return SU(this.#W(),W)}get extendedKey(){return X1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),JD(t1(["0x0488ADE4",ZA(this.depth,1),this.parentFingerprint,ZA(this.index,4),this.chainCode,t1(["0x00",this.privateKey])]))}hasPath(){return this.path!=null}neuter(){return new fY(a7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(W){let Y=r8(W,"index");r(Y<=4294967295,"invalid index","index",Y);let G=this.path;if(G){if(G+="/"+(Y&~NW),Y&NW)G+="'"}let{IR:X,IL:J}=M_(Y,this.chainCode,this.publicKey,this.privateKey),Z=new o8(V7((aX(J)+BigInt(this.privateKey))%qt,32));return new U9(a7,Z,this.fingerprint,C0(X),G,Y,this.depth+1,this.mnemonic,this.provider)}derivePath(W){return P_(this,W)}static#Y(W,Y){r(n7(W),"invalid seed","seed","[REDACTED]");let G=B0(W,"seed");r(G.length>=16&&G.length<=64,"invalid seed","seed","[REDACTED]");let X=B0(YW("sha512",Nt,G)),J=new o8(C0(X.slice(0,32)));return new U9(a7,J,"0x00000000",C0(X.slice(32)),"m",0,0,Y,null)}static fromExtendedKey(W){let Y=N8(Eq(W));r(Y.length===82||JD(Y.slice(0,78))===W,"invalid extended key","extendedKey","[ REDACTED ]");let G=Y[4],X=C0(Y.slice(5,9)),J=parseInt(C0(Y.slice(9,13)).substring(2),16),Z=C0(Y.slice(13,45)),V=Y.slice(45,78);switch(C0(Y.slice(0,4))){case"0x0488b21e":case"0x043587cf":{let U=C0(V);return new fY(a7,t4(U),U,X,Z,null,J,G,null)}case"0x0488ade4":case"0x04358394 ":if(V[0]!==0)break;return new U9(a7,new o8(V.slice(1)),X,Z,null,J,G,null,null)}r(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(W,Y,G){if(W==null)W="";if(Y==null)Y=kU;if(G==null)G=W6.wordlist();let X=Y6.fromEntropy(S5(16),W,G);return U9.#Y(X.computeSeed(),X).derivePath(Y)}static fromMnemonic(W,Y){if(!Y)Y=kU;return U9.#Y(W.computeSeed(),W).derivePath(Y)}static fromPhrase(W,Y,G,X){if(Y==null)Y="";if(G==null)G=kU;if(X==null)X=W6.wordlist();let J=Y6.fromPhrase(W,Y,X);return U9.#Y(J.computeSeed(),J).derivePath(G)}static fromSeed(W){return U9.#Y(W,null)}}class fY extends LU{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(W,Y,G,X,J,Z,V,U,Q){super(Y,Q);d4(W,a7,"HDNodeVoidWallet"),H8(this,{publicKey:G});let H=iX(GW(L9(G)),0,4);H8(this,{publicKey:G,fingerprint:H,parentFingerprint:X,chainCode:J,path:Z,index:V,depth:U})}connect(W){return new fY(a7,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,W)}get extendedKey(){return X1(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),JD(t1(["0x0488B21E",ZA(this.depth,1),this.parentFingerprint,ZA(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return this.path!=null}deriveChild(W){let Y=r8(W,"index");r(Y<=4294967295,"invalid index","index",Y);let G=this.path;if(G){if(G+="/"+(Y&~NW),Y&NW)G+="'"}let{IR:X,IL:J}=M_(Y,this.chainCode,this.publicKey,null),Z=o8.addPoints(J,this.publicKey,!0),V=t4(Z);return new fY(a7,V,Z,this.fingerprint,C0(X),G,Y,this.depth+1,this.provider)}derivePath(W){return P_(this,W)}}function VA(W){try{if(JSON.parse(W).encseed)return!0}catch(Y){}return!1}function UA(W,Y){let G=JSON.parse(W),X=mY(Y),J=f1(D8(G,"ethaddr:string!")),Z=YD(D8(G,"encseed:string!"));r(Z&&Z.length%16===0,"invalid encseed","json",W);let V=B0(F5(X,X,2000,32,"sha256")).slice(0,16),U=Z.slice(0,16),Q=Z.slice(16),H=new $U(V,U),N=WD(B0(H.decrypt(Q))),A="";for(let q=0;q<N.length;q++)A+=String.fromCharCode(N[q]);return{address:J,privateKey:e4(A)}}function L_(W){return new Promise((Y)=>{setTimeout(()=>{Y()},W)})}class X6 extends hY{constructor(W,Y){if(typeof W==="string"&&!W.startsWith("0x"))W="0x"+W;let G=typeof W==="string"?new o8(W):W;super(G,Y)}connect(W){return new X6(this.signingKey,W)}async encrypt(W,Y){let G={address:this.address,privateKey:this.privateKey};return await xU(G,W,{progressCallback:Y})}encryptSync(W){let Y={address:this.address,privateKey:this.privateKey};return SU(Y,W)}static#W(W){if(r(W,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in W&&W.mnemonic&&W.mnemonic.locale==="en"){let G=Y6.fromEntropy(W.mnemonic.entropy),X=U9.fromMnemonic(G,W.mnemonic.path);if(X.address===W.address&&X.privateKey===W.privateKey)return X;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}let Y=new X6(W.privateKey);return r(Y.address===W.address,"address/privateKey mismatch","json","[ REDACTED ]"),Y}static async fromEncryptedJson(W,Y,G){let X=null;if(JA(W))X=await XD(W,Y,G);else if(VA(W)){if(G)G(0),await L_(0);if(X=UA(W,Y),G)G(1),await L_(0)}return X6.#W(X)}static fromEncryptedJsonSync(W,Y){let G=null;if(JA(W))G=GD(W,Y);else if(VA(W))G=UA(W,Y);else r(!1,"invalid JSON wallet","json","[ REDACTED ]");return X6.#W(G)}static createRandom(W){let Y=U9.createRandom();if(W)return Y.connect(W);return Y}static fromPhrase(W,Y){let G=U9.fromPhrase(W);if(Y)return G.connect(Y);return G}}function B_(W,Y=[]){let G=String(W??"").trim();if(!G)throw Error("sm-server: signing key required (GDB_SM_KEY)");let X=G.includes(" ")?U9.fromPhrase(G):new X6(G),J=f1(X.address),Z=new Set([...Y,J].map((N)=>{try{return f1(N)}catch{return null}}).filter(Boolean)),V=(N)=>{let A=(q)=>q&&typeof q==="object"&&!Array.isArray(q)?Object.keys(q).sort().reduce((z,w)=>(z[w]=A(q[w]),z),{}):Array.isArray(q)?q.map(A):q;return JSON.stringify(A(N))};return{address:J,superAdmins:Z,canonicalize:V,signOps:async(N)=>{let A=[];for(let q of N){if(q?.signature&&q?.originEthAddress&&q?.originUser){A.push(q);continue}let z={...q,originUser:J},w=await X.signMessage(M9(V(z)));A.push({...q,originUser:J,originEthAddress:J,signature:w})}return A},verifyOp:(N)=>{if(!N?.signature||!N?.originEthAddress||!N?.originUser)return{ok:!1,reason:"missing-fields"};let A;try{if(A=f1(N.originEthAddress),f1(N.originUser)!==A)return{ok:!1,reason:"address-mismatch"}}catch{return{ok:!1,reason:"invalid-address"}}let{signature:q,originEthAddress:z,...w}=N;try{let D=rq(M9(V(w)),q);if(f1(D)!==A)return{ok:!1,reason:"invalid-signature"};let{originUser:T,...x}=w;return{ok:!0,normalizedOriginEthAddress:A,payload:x}}catch(D){return{ok:!1,reason:"verify-error",error:D}}},isSuperAdmin:(N)=>{try{return Z.has(f1(N))}catch{return!1}}}}var wt=["guest","user","manager","admin","superadmin"];function E_(W,Y,G,{intervalMs:X=4000,settleMs:J=15000,customRoles:Z=null}={}){let V=new Set([...wt,...Object.keys(Z??{})]),U=async(A,q,z=null)=>{let w=f1(A);if(!V.has(q))throw Error(`Role '${q}' is not a defined role.`);let D=`user:${w}`,T=(await W.get(D)).result?.value||{};await W.put({...T,ethAddress:w,role:q,assignedByEthAddress:Y.address,expiresAt:z?new Date(z).toISOString():null,priority:!0},D)},Q=async()=>{let A=new Map;for(let q of G){let z=q.then?.assignRole;if(!z)continue;let w=[];try{({results:w=[]}=W.map({query:q.if}))}catch(D){console.error("\u274C GOVERNANCE: rule evaluation failed:",D.message);continue}for(let D of w){if(!D.id.startsWith("user:"))continue;if(Y.isSuperAdmin(D.id.slice(5)))continue;if(q.offsetTimestamp&&(D.timestamp?.physical??0)>Date.now()-q.offsetTimestamp)continue;A.set(D.id,{role:z,current:D.value?.role})}}for(let[q,{role:z,current:w}]of A){if(w===z)continue;try{await U(q.slice(5),z),console.info(`\uD83D\uDCDC GOVERNANCE: ${q.slice(5)} '${w}' -> '${z}'`)}catch(D){console.error("\u274C GOVERNANCE: assignRole failed:",D.message)}}},H=null,N=setTimeout(()=>{H=setInterval(Q,X),console.info(`\uD83D\uDCDC GOVERNANCE ENGINE: active \u2014 ${G.length} rule(s), every ${X} ms.`)},J);return{assignRole:U,stop:()=>{if(clearTimeout(N),H)clearInterval(H)}}}var VD=(W)=>W&&typeof W==="object"?structuredClone(W):W,ZD=(W,Y=16)=>{let G=null,X=null;return(...J)=>{if(X??=Promise.withResolvers(),G!==null)clearTimeout(G);return G=setTimeout(async()=>{G=null;try{X.resolve(await W(...J))}catch(Z){X.reject(Z)}finally{X=null}},Y),X.promise}},Dt=(W)=>{let Y=!1;return()=>{if(Y)return;Y=!0,setImmediate(()=>{Y=!1,W()})}};function Ct(W=1000){let Y=[];return{add(G){if(G?.timestamp){if(Y.push(G),Y.length>W)Y.splice(0,Y.length-W)}},getOldest:()=>Y[0]??null,getDelta:(G,X)=>G?Y.filter((J)=>X(J.timestamp,G)>0):[...Y],clear(){Y=[]},entries:()=>[...Y],setEntries(G=[]){if(Y=Array.isArray(G)?[...G]:[],Y.length>W)Y.splice(0,Y.length-W)}}}function Tt(){let W={nodes:{}};return{get nodes(){return W.nodes},set nodes(Y){W.nodes=Y??{}},upsert(Y,G,X){let J=W.nodes[Y];W.nodes[Y]={id:Y,value:VD(G),edges:J?.edges?[...J.edges]:[],timestamp:X}},get:(Y)=>W.nodes[Y]??null,link(Y,G,X){let J=W.nodes[Y],Z=W.nodes[G];if(J&&Z&&!J.edges.includes(G))W.nodes[Y]={...J,edges:[...J.edges,G],timestamp:X}},getAllNodes:()=>Object.values(W.nodes),serialize:()=>WG.deflate(uU(W.nodes)),deserialize(Y){let G=Y instanceof Uint8Array?Y:new Uint8Array(Y);W.nodes=qW(WG.inflate(G))}}}function Rt(W,Y){let G=Kt(W);if(G&&G!==".")Ot(G,{recursive:!0});let X=new jt(W);X.exec("PRAGMA journal_mode = WAL"),X.exec("PRAGMA synchronous = NORMAL"),X.exec(`
|
|
252
252
|
CREATE TABLE IF NOT EXISTS kv (
|
|
253
253
|
key TEXT PRIMARY KEY,
|
|
254
254
|
value BLOB NOT NULL
|
|
255
255
|
)
|
|
256
|
-
`);let J=X.prepare("SELECT value FROM kv WHERE key = ?"),Z=X.prepare("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)"),V=X.prepare("DELETE FROM kv WHERE key = ?"),U=Y;return{getBlob(Q){let H=J.get(`${U}:${Q}`);return H?new Uint8Array(H.value):null},getText(Q){let H=J.get(`${U}:${Q}`);return H?Buffer.from(H.value).toString("utf8"):null},putBlob(Q,H){Z.run(`${U}:${Q}`,Buffer.from(H))},putText(Q,H){Z.run(`${U}:${Q}`,Buffer.from(H,"utf8"))},del(Q){V.run(`${U}:${Q}`)},close(){X.close()}}}async function Mt(W=process.env.GDB_ROOM||process.argv.slice(2).find((X)=>!X.startsWith("--"))||"default",Y={},G=process.env.GDB_DB_PATH||"./data.sqlite"){console.info(`\u26A1 GDBServer [${W}] initializing (bun:sqlite)`);let{password:X,saveDelay:J=200,oplogSize:Z=1000,rtcPolyfill:V=null,rtc:U=!0,room:Q=null,sm:H=null,relay:N=null}=Y,A=U?.constructor===Object?U:{},{turnConfig:q=null}=A,z=A.relayUrls??((process.env.GDB_RELAY_URLS??"").split(",").map((Q0)=>Q0.trim()).filter(Boolean).length?process.env.GDB_RELAY_URLS.split(",").map((Q0)=>Q0.trim()).filter(Boolean):null),w=N??(process.argv.includes("--relay")||["1","true"].includes(process.env.GDB_RELAY??"")),D=null;if(w)D=Kx(N?.constructor===Object?N:{}),z=[...z??[],`ws://127.0.0.1:${D.port}`];let T=A.cells??(process.argv.includes("--cells")||["1","true"].includes(process.env.GDB_CELLS??"")),x=Q??process.argv.includes("--room"),g=H?.constructor===Object?H:null,f=g?.key??process.env.GDB_SM_KEY??null,y=g?.superAdmins??(process.env.GDB_SUPERADMINS??"").split(",").map((Q0)=>Q0.trim()).filter(Boolean),p=null;if(f)p=B_(f,y),console.info(`\uD83D\uDEE1\uFE0F SM: signing as ${p.address}`);else if(g)console.warn("\u26A0\uFE0F SM: sm configured but no signing key (GDB_SM_KEY) \u2014 running unsigned, memory-only role.");let b=Tt(),m=gC(),W0=Ct(Z),u=Rt(G,W),J0=[],A0=[],k=[],l=null,B=null,$=null,h={},a=()=>{let Q0=u.getBlob("graph");if(Q0?.byteLength)b.deserialize(Q0),console.info(`\u2705 Graph loaded: ${b.getAllNodes().length} nodes`)},n=()=>{u.putBlob("graph",b.serialize())},E=()=>{let Q0=u.getText("timestamp");if(Q0){let O0=JSON.parse(Q0);if(O0?.physical&&O0?.logical)l=O0,m.update(l)}},P=()=>{u.putText("timestamp",JSON.stringify(l??null))},v=()=>{let Q0=u.getBlob("oplog");if(Q0?.byteLength){let O0=qW(WG.inflate(Q0));if(Array.isArray(O0))W0.setEntries(O0),console.info(`\u2705 Oplog loaded: ${O0.length} ops`)}},M=()=>{u.putBlob("oplog",WG.deflate(uU(W0.entries())))},F=(Q0)=>{if(!Q0)return;if(!l||m.compare(Q0,l)>0)l=Q0,P()},c=ZD(()=>n(),J),t=ZD(()=>M(),J),Y0=()=>{let Q0={...b.nodes};J0.forEach((O0)=>O0(Q0))},$0=Dt(()=>Y0()),S0=async(Q0)=>{if(!Q0?.length||!B)return!1;try{return await B.send(Q0),!0}catch(O0){return console.error("\u274C safeSend failed:",O0?.message),!1}},x0=async(Q0)=>{let O0=await S0(Q0);return setTimeout(()=>S0(Q0),2500),O0},D1=async(Q0)=>{let O0=!1,y0=null,X0=(I0)=>{if(I0&&(!y0||m.compare(I0,y0)>0))y0=I0},D0=(I0)=>{try{if(I0 instanceof Uint8Array||I0 instanceof ArrayBuffer){let F0=qW(I0);return Array.isArray(F0)?F0:[F0]}if(Array.isArray(I0))return I0;if(I0&&typeof I0==="object")return qW(WG.inflate(new Uint8Array(Object.values(I0))))}catch(F0){console.error("\u274C decode failed",F0)}return null},L0={upsert(I0){let{resolved:F0,value:V1,timestamp:H1}=uC(b.get(I0.id),I0,m);if(!F0)return;b.upsert(I0.id,V1,H1),m.update(H1),W0.add({type:"upsert",id:I0.id,timestamp:H1}),O0=!0,X0(H1)},remove(I0){let F0=b.get(I0.id);if(!F0||m.compare(F0.timestamp,I0.timestamp)>=0)return;delete b.nodes[I0.id],Object.values(b.nodes).forEach((V1)=>{V1.edges=(V1.edges??[]).filter((H1)=>H1!==I0.id)}),m.update(I0.timestamp),W0.add({type:"remove",id:I0.id,timestamp:I0.timestamp}),O0=!0,X0(I0.timestamp)},link(I0){let F0=b.get(I0.sourceId),V1=b.get(I0.targetId);if(!F0||!V1||m.compare(F0.timestamp,I0.timestamp)>=0)return;b.link(I0.sourceId,I0.targetId,I0.timestamp),m.update(I0.timestamp),W0.add({type:"link",...I0}),O0=!0,X0(I0.timestamp)},async sync({timestamp:I0}){let F0=W0.getOldest();if(I0==null||F0&&m.compare(I0,F0.timestamp)<0){console.info("\uD83D\uDCA5 Sending FULL state sync:",b.getAllNodes().length,"nodes"),await x0([{type:"fullStateSync",graphData:b.nodes,removals:W0.getDelta(null).filter((i1)=>i1.type==="remove"),timestamp:l}]);return}let H1=W0.getDelta(null);if(!H1.length)return;let f1=H1.map((i1)=>i1.type==="upsert"?{...i1,value:b.get(i1.id)?.value}:i1);console.info("\uD83D\uDE80 Sending DELTA sync:",f1.length,"ops"),await x0([{type:"deltaSync",operations:f1,timestamp:l}])},deltaSync({operations:I0}){let F0=D0(I0);if(!Array.isArray(F0))return;console.info("\uD83D\uDCE5 deltaSync:",F0.length,"ops");for(let V1 of F0)if(V1&&L0[V1.type])L0[V1.type](V1)},async fullStateSync({graphData:I0,removals:F0,timestamp:V1}){if(!I0||typeof I0!=="object")return;let H1=I0,f1=new Map;for(let r0 of W0.getDelta(null))if(r0.type==="remove")f1.set(r0.id,r0.timestamp);for(let[r0,x1]of Object.entries(H1)){let i0=b.nodes[r0]?.timestamp??f1.get(r0);if(!i0||m.compare(i0,x1.timestamp)<0)b.nodes[r0]=x1,W0.add({type:"upsert",id:r0,timestamp:x1.timestamp})}for(let r0 of F0??[]){let x1=b.nodes[r0.id];if(x1&&m.compare(x1.timestamp,r0.timestamp)<0)delete b.nodes[r0.id],W0.add({type:"remove",id:r0.id,timestamp:r0.timestamp})}let i1=new Set(Object.keys(H1));if(Object.keys(b.nodes).some((r0)=>!i1.has(r0)))await x0([{type:"fullStateSync",graphData:b.nodes,removals:W0.getDelta(null).filter((r0)=>r0.type==="remove"),timestamp:l}]);if(O0=!0,console.info("\u2705 fullStateSync merged:",b.getAllNodes().length,"nodes"),V1)X0(V1),m.update(V1)}};for(let I0 of Q0)if(L0[I0.type])await L0[I0.type](I0);if(y0&&(!l||m.compare(y0,l)>0))F(y0);if(O0)await Promise.all([c(),t()]),$0()},b0=ZD(async()=>{let Q0=k.splice(0);return Q0.length?await S0(Q0):!1},16);Object.assign(h,{use(Q0){if(typeof Q0==="function")A0.push(Q0)},async put(Q0,O0){let y0=m.now();F(y0),O0??=crypto.randomUUID(),b.upsert(O0,Q0,y0),W0.add({type:"upsert",id:O0,timestamp:y0}),c(),t();try{k.push({type:"upsert",id:O0,value:Q0,timestamp:y0}),b0().catch(()=>{})}finally{$0()}return O0},async get(Q0){if(typeof Q0!=="string")return{result:null};let O0=b.get(Q0);if(!O0)return{result:null};return{result:{...O0,value:VD(O0.value)}}},map(...Q0){let y0={...{realtime:!1,query:{},field:null,order:"asc",$limit:null,$after:null,$before:null}},X0=null,D0=!1;Q0.forEach((F0)=>typeof F0==="function"?X0=F0:F0&&typeof F0==="object"&&(D0=D0||("realtime"in F0),Object.assign(y0,F0))),X0&&!D0&&(y0.realtime=!0);let L0=dA(b.nodes,y0),I0=null;if(X0){if(L0.forEach((F0)=>X0({id:F0.id,value:F0.value,edges:F0.edges,timestamp:F0.timestamp,action:"initial"})),y0.realtime){let F0=(V1)=>`${V1.id}:${V1.timestamp?.physical??0}:${V1.timestamp?.logical??0}:${(V1.edges??[]).join(",")}`;I0=(V1)=>{let H1=dA(V1,y0),f1=new Map(L0.map((r0)=>[r0.id,r0])),i1=new Map(H1.map((r0)=>[r0.id,r0]));if(H1.length!==L0.length||!H1.map(F0).every((r0,x1)=>r0===L0.map(F0)[x1])){for(let[r0,x1]of i1){let i0=f1.get(r0);if(!i0)X0({id:r0,value:x1.value,edges:x1.edges,timestamp:x1.timestamp,action:"added"});else if(F0(x1)!==F0(i0))X0({id:r0,value:x1.value,edges:x1.edges,timestamp:x1.timestamp,action:"updated"})}for(let[r0,x1]of f1)if(!i1.has(r0))X0({id:r0,value:null,edges:x1.edges,timestamp:x1.timestamp,action:"removed"});L0=H1}},J0.push(I0)}}return{results:L0,...y0.realtime&&X0&&I0&&{unsubscribe:()=>{let F0=J0.indexOf(I0);if(F0>=0)J0.splice(F0,1)}}}},async link(Q0,O0){if(!b.nodes[Q0]||!b.nodes[O0])return;let y0=m.now();b.link(Q0,O0,y0),W0.add({type:"link",sourceId:Q0,targetId:O0,timestamp:y0}),c(),t(),F(y0);try{k.push({type:"link",sourceId:Q0,targetId:O0,timestamp:y0}),b0().catch(()=>{})}finally{$0()}},async remove(Q0){let O0=b.get(Q0);if(!O0)return;let y0=m.now();delete b.nodes[Q0],Object.values(b.nodes).forEach((X0)=>{X0.edges=(X0.edges??[]).filter((D0)=>D0!==Q0)}),W0.add({type:"remove",id:Q0,timestamp:y0}),c(),t(),F(y0);try{k.push({type:"remove",id:Q0,value:O0.value,timestamp:y0}),b0().catch(()=>{})}finally{$0()}},async clear(){b.nodes={},W0.clear(),u.del("graph"),u.del("oplog"),Y0()},on(Q0){return J0.push(Q0),()=>{let O0=J0.indexOf(Q0);if(O0>=0)J0.splice(O0,1)}},close(){u.close()}});try{let Q0=`graph-sync-room-${W}`,O0={appId:"1234",type:"superpeer",...X&&{password:X},...z&&{relayUrls:z},...q&&{turnConfig:q},...T&&{cells:!0},...T&&T!==!0&&{overlay:T},rtcPolyfill:V??NK};if($=MI(O0,Q0),B=$.channel("syncGraph"),console.info(`\u26A1 Transport: ${T?"cellular mesh":"full mesh"}`),p){let y0=B.send;B={...B,send:async(X0)=>y0(await p.signOps(X0))},h.sm=p}if(!T){let y0=!1;$.channel("c0").on("message",()=>{if(y0)return;y0=!0,console.warn("\u26A0\uFE0F This room speaks Cellular Mesh \u2014 restart with --cells / GDB_CELLS=1 (CLI) or rtc: { cells: true } (module), or browser writes will never reach this superpeer.")})}if(x)h.room=MI(O0,`app-sync-${W}`),console.info("\u26A1 db.room joined \u2014 visible to monitors/presence");$.on("peer:join",(y0)=>{console.info("\u26A1 Peer connected:",y0);for(let X0 of[0,1500,4000,9000])setTimeout(()=>S0([{type:"sync",timestamp:l}]),X0)}),$.on("peer:leave",(y0)=>console.info("\u26A1 Peer disconnected:",y0)),B.on("message",async(y0)=>{let X0;try{X0=y0 instanceof Uint8Array||y0 instanceof ArrayBuffer?(()=>{let L0=qW(y0);return Array.isArray(L0)?L0:[L0]})():Array.isArray(y0)?y0:[y0]}catch(L0){return console.error("\u274C decode failed:",L0)}let D0=new Map([...new Set(X0.flatMap((L0)=>["id","sourceId","targetId"].map((I0)=>L0?.[I0]).filter(Boolean)))].map((L0)=>b.get(L0)?[L0,VD(b.get(L0))]:null).filter(Boolean));for(let L0 of A0)try{if(X0=await L0(X0,D0),!X0?.length)return}catch(I0){console.error("\u274C Middleware error:",I0);return}await D1(X0)}),console.info("\u2705 GenosRTC sync enabled")}catch(Q0){console.warn("\u26A0\uFE0F GenosRTC not available:",Q0.message)}if(a(),E(),v(),p){let Q0=g?.governanceRules??null;if(!Q0&&process.env.GDB_SM_RULES){let O0=process.env.GDB_SM_RULES.trim();try{if(O0.startsWith("["))Q0=JSON.parse(O0);else if(O0.startsWith("{"))Q0=[JSON.parse(O0)];else Q0=(await import(new URL(O0,`file://${process.cwd()}/`).href)).default}catch(y0){console.error("\u274C GOVERNANCE: could not load GDB_SM_RULES:",y0.message)}}if(Array.isArray(Q0)&&Q0.length)h.governance=E_(h,p,Q0,{customRoles:g?.customRoles??null})}if(D)h.relay=D;return Object.defineProperties(h,{syncChannel:{get:()=>B},hybridClock:{get:()=>m},graph:{get:()=>({getAllNodes:()=>b.getAllNodes(),get:(Q0)=>b.get(Q0)})}}),console.info(`\u2705 GDBServer [${W}] ready (bun:sqlite)`),h}if(import.meta.main){let W=new Set(["ECONNREFUSED","ECONNRESET","EHOSTUNREACH","ENETUNREACH","EADDRNOTAVAIL","ETIMEDOUT","EPIPE"]),Y=(Z)=>W.has(Z?.code)||W.has(Z?.errno),G=new Map,X=null,J=(Z="UNKNOWN")=>{let V=(G.get(Z)??0)+1;if(G.set(Z,V),V===1)console.warn("\u26A0\uFE0F Transient network error (ignored):",Z);X??=setTimeout(()=>{X=null;let U=[...G].filter(([,Q])=>Q>1).map(([Q,H])=>`${Q} \xD7${H}`).join(", ");if(U)console.warn("\u26A0\uFE0F Transient network errors (ignored, last 60s):",U);G.clear()},60000)};process.on("uncaughtException",(Z)=>{if(Y(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal:",Z?.message??Z),process.exit(1)}),process.on("unhandledRejection",(Z)=>{if(Y(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal (rejection):",Z?.message??Z),process.exit(1)}),Mt().catch((Z)=>{console.error("\u274C Fatal:",Z.message),process.exit(1)})}export{Mt as gdbServer};
|
|
256
|
+
`);let J=X.prepare("SELECT value FROM kv WHERE key = ?"),Z=X.prepare("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)"),V=X.prepare("DELETE FROM kv WHERE key = ?"),U=Y;return{getBlob(Q){let H=J.get(`${U}:${Q}`);return H?new Uint8Array(H.value):null},getText(Q){let H=J.get(`${U}:${Q}`);return H?Buffer.from(H.value).toString("utf8"):null},putBlob(Q,H){Z.run(`${U}:${Q}`,Buffer.from(H))},putText(Q,H){Z.run(`${U}:${Q}`,Buffer.from(H,"utf8"))},del(Q){V.run(`${U}:${Q}`)},close(){X.close()}}}async function Mt(W=process.env.GDB_ROOM||process.argv.slice(2).find((X)=>!X.startsWith("--"))||"default",Y={},G=process.env.GDB_DB_PATH||"./data.sqlite"){console.info(`\u26A1 GDBServer [${W}] initializing (bun:sqlite)`);let{password:X,saveDelay:J=200,oplogSize:Z=1000,rtcPolyfill:V=null,rtc:U=!0,room:Q=null,sm:H=null,relay:N=null}=Y,A=U?.constructor===Object?U:{},{turnConfig:q=null}=A,z=A.relayUrls??((process.env.GDB_RELAY_URLS??"").split(",").map((Q0)=>Q0.trim()).filter(Boolean).length?process.env.GDB_RELAY_URLS.split(",").map((Q0)=>Q0.trim()).filter(Boolean):null),w=N??(process.argv.includes("--relay")||["1","true"].includes(process.env.GDB_RELAY??"")),D=null;if(w)D=Kx(N?.constructor===Object?N:{}),z=[...z??[],`ws://127.0.0.1:${D.port}`];let T=A.cells??(process.argv.includes("--cells")||["1","true"].includes(process.env.GDB_CELLS??"")),x=Q??process.argv.includes("--room"),g=H?.constructor===Object?H:null,f=g?.key??process.env.GDB_SM_KEY??null,y=g?.superAdmins??(process.env.GDB_SUPERADMINS??"").split(",").map((Q0)=>Q0.trim()).filter(Boolean),p=null;if(f)p=B_(f,y),console.info(`\uD83D\uDEE1\uFE0F SM: signing as ${p.address}`);else if(g)console.warn("\u26A0\uFE0F SM: sm configured but no signing key (GDB_SM_KEY) \u2014 running unsigned, memory-only role.");let b=Tt(),m=gC(),W0=Ct(Z),u=Rt(G,W),J0=[],I0=[],k=[],l=null,B=null,$=null,h={},a=()=>{let Q0=u.getBlob("graph");if(Q0?.byteLength)b.deserialize(Q0),console.info(`\u2705 Graph loaded: ${b.getAllNodes().length} nodes`)},n=()=>{u.putBlob("graph",b.serialize())},E=()=>{let Q0=u.getText("timestamp");if(Q0){let O0=JSON.parse(Q0);if(O0?.physical&&O0?.logical)l=O0,m.update(l)}},P=()=>{u.putText("timestamp",JSON.stringify(l??null))},v=()=>{let Q0=u.getBlob("oplog");if(Q0?.byteLength){let O0=qW(WG.inflate(Q0));if(Array.isArray(O0))W0.setEntries(O0),console.info(`\u2705 Oplog loaded: ${O0.length} ops`)}},M=()=>{u.putBlob("oplog",WG.deflate(uU(W0.entries())))},F=(Q0)=>{if(!Q0)return;if(!l||m.compare(Q0,l)>0)l=Q0,P()},c=ZD(()=>n(),J),t=ZD(()=>M(),J),Y0=()=>{let Q0={...b.nodes};J0.forEach((O0)=>O0(Q0))},$0=Dt(()=>Y0()),S0=async(Q0)=>{if(!Q0?.length||!B)return!1;try{return await B.send(Q0),!0}catch(O0){return console.error("\u274C safeSend failed:",O0?.message),!1}},x0=async(Q0)=>{let O0=await S0(Q0);return setTimeout(()=>S0(Q0),2500),O0},D1=async(Q0)=>{let O0=!1,y0=null,X0=(H0)=>{if(H0&&(!y0||m.compare(H0,y0)>0))y0=H0},D0=(H0)=>{try{if(H0 instanceof Uint8Array||H0 instanceof ArrayBuffer){let F0=qW(H0);return Array.isArray(F0)?F0:[F0]}if(Array.isArray(H0))return H0;if(H0&&typeof H0==="object")return qW(WG.inflate(new Uint8Array(Object.values(H0))))}catch(F0){console.error("\u274C decode failed",F0)}return null},L0={upsert(H0){if(!b.get(H0.id)){for(let y1 of W0.getDelta(null))if(y1.type==="remove"&&y1.id===H0.id&&m.compare(y1.timestamp,H0.timestamp)>=0)return}let{resolved:F0,value:V1,timestamp:H1}=uC(b.get(H0.id),H0,m);if(!F0)return;b.upsert(H0.id,V1,H1),m.update(H1),W0.add({type:"upsert",id:H0.id,timestamp:H1}),O0=!0,X0(H1)},remove(H0){let F0=b.get(H0.id);if(!F0||m.compare(F0.timestamp,H0.timestamp)>=0)return;delete b.nodes[H0.id],Object.values(b.nodes).forEach((V1)=>{V1.edges=(V1.edges??[]).filter((H1)=>H1!==H0.id)}),m.update(H0.timestamp),W0.add({type:"remove",id:H0.id,timestamp:H0.timestamp}),O0=!0,X0(H0.timestamp)},link(H0){let F0=b.get(H0.sourceId),V1=b.get(H0.targetId);if(!F0||!V1||m.compare(F0.timestamp,H0.timestamp)>=0)return;b.link(H0.sourceId,H0.targetId,H0.timestamp),m.update(H0.timestamp),W0.add({type:"link",...H0}),O0=!0,X0(H0.timestamp)},async sync({timestamp:H0}){let F0=W0.getOldest();if(H0==null||F0&&m.compare(H0,F0.timestamp)<0){console.info("\uD83D\uDCA5 Sending FULL state sync:",b.getAllNodes().length,"nodes"),await x0([{type:"fullStateSync",graphData:b.nodes,removals:W0.getDelta(null).filter((i1)=>i1.type==="remove"),timestamp:l}]);return}let H1=W0.getDelta(null);if(!H1.length)return;let y1=H1.map((i1)=>i1.type==="upsert"?{...i1,value:b.get(i1.id)?.value}:i1);console.info("\uD83D\uDE80 Sending DELTA sync:",y1.length,"ops"),await x0([{type:"deltaSync",operations:y1,timestamp:l}])},deltaSync({operations:H0}){let F0=D0(H0);if(!Array.isArray(F0))return;console.info("\uD83D\uDCE5 deltaSync:",F0.length,"ops");for(let V1 of F0)if(V1&&L0[V1.type])L0[V1.type](V1)},async fullStateSync({graphData:H0,removals:F0,timestamp:V1}){if(!H0||typeof H0!=="object")return;let H1=H0,y1=new Map;for(let r0 of W0.getDelta(null))if(r0.type==="remove")y1.set(r0.id,r0.timestamp);for(let[r0,x1]of Object.entries(H1)){let i0=b.nodes[r0]?.timestamp??y1.get(r0);if(!i0||m.compare(i0,x1.timestamp)<0)b.nodes[r0]=x1,W0.add({type:"upsert",id:r0,timestamp:x1.timestamp})}for(let r0 of F0??[]){let x1=b.nodes[r0.id];if(x1&&m.compare(x1.timestamp,r0.timestamp)<0)delete b.nodes[r0.id],W0.add({type:"remove",id:r0.id,timestamp:r0.timestamp})}let i1=new Set(Object.keys(H1));if(Object.keys(b.nodes).some((r0)=>!i1.has(r0)))await x0([{type:"fullStateSync",graphData:b.nodes,removals:W0.getDelta(null).filter((r0)=>r0.type==="remove"),timestamp:l}]);if(O0=!0,console.info("\u2705 fullStateSync merged:",b.getAllNodes().length,"nodes"),V1)X0(V1),m.update(V1)}};for(let H0 of Q0)if(L0[H0.type])await L0[H0.type](H0);if(y0&&(!l||m.compare(y0,l)>0))F(y0);if(O0)await Promise.all([c(),t()]),$0()},b0=ZD(async()=>{let Q0=k.splice(0);return Q0.length?await S0(Q0):!1},16);Object.assign(h,{use(Q0){if(typeof Q0==="function")I0.push(Q0)},async put(Q0,O0){let y0=m.now();F(y0),O0??=crypto.randomUUID(),b.upsert(O0,Q0,y0),W0.add({type:"upsert",id:O0,timestamp:y0}),c(),t();try{k.push({type:"upsert",id:O0,value:Q0,timestamp:y0}),b0().catch(()=>{})}finally{$0()}return O0},async get(Q0){if(typeof Q0!=="string")return{result:null};let O0=b.get(Q0);if(!O0)return{result:null};return{result:{...O0,value:VD(O0.value)}}},map(...Q0){let y0={...{realtime:!1,query:{},field:null,order:"asc",$limit:null,$after:null,$before:null}},X0=null,D0=!1;Q0.forEach((F0)=>typeof F0==="function"?X0=F0:F0&&typeof F0==="object"&&(D0=D0||("realtime"in F0),Object.assign(y0,F0))),X0&&!D0&&(y0.realtime=!0);let L0=dA(b.nodes,y0),H0=null;if(X0){if(L0.forEach((F0)=>X0({id:F0.id,value:F0.value,edges:F0.edges,timestamp:F0.timestamp,action:"initial"})),y0.realtime){let F0=(V1)=>`${V1.id}:${V1.timestamp?.physical??0}:${V1.timestamp?.logical??0}:${(V1.edges??[]).join(",")}`;H0=(V1)=>{let H1=dA(V1,y0),y1=new Map(L0.map((r0)=>[r0.id,r0])),i1=new Map(H1.map((r0)=>[r0.id,r0]));if(H1.length!==L0.length||!H1.map(F0).every((r0,x1)=>r0===L0.map(F0)[x1])){for(let[r0,x1]of i1){let i0=y1.get(r0);if(!i0)X0({id:r0,value:x1.value,edges:x1.edges,timestamp:x1.timestamp,action:"added"});else if(F0(x1)!==F0(i0))X0({id:r0,value:x1.value,edges:x1.edges,timestamp:x1.timestamp,action:"updated"})}for(let[r0,x1]of y1)if(!i1.has(r0))X0({id:r0,value:null,edges:x1.edges,timestamp:x1.timestamp,action:"removed"});L0=H1}},J0.push(H0)}}return{results:L0,...y0.realtime&&X0&&H0&&{unsubscribe:()=>{let F0=J0.indexOf(H0);if(F0>=0)J0.splice(F0,1)}}}},async link(Q0,O0){if(!b.nodes[Q0]||!b.nodes[O0])return;let y0=m.now();b.link(Q0,O0,y0),W0.add({type:"link",sourceId:Q0,targetId:O0,timestamp:y0}),c(),t(),F(y0);try{k.push({type:"link",sourceId:Q0,targetId:O0,timestamp:y0}),b0().catch(()=>{})}finally{$0()}},async remove(Q0){let O0=b.get(Q0);if(!O0)return;let y0=m.now();delete b.nodes[Q0],Object.values(b.nodes).forEach((X0)=>{X0.edges=(X0.edges??[]).filter((D0)=>D0!==Q0)}),W0.add({type:"remove",id:Q0,timestamp:y0}),c(),t(),F(y0);try{k.push({type:"remove",id:Q0,value:O0.value,timestamp:y0}),b0().catch(()=>{})}finally{$0()}},async clear(){b.nodes={},W0.clear(),u.del("graph"),u.del("oplog"),Y0()},on(Q0){return J0.push(Q0),()=>{let O0=J0.indexOf(Q0);if(O0>=0)J0.splice(O0,1)}},close(){u.close()}});try{let Q0=`graph-sync-room-${W}`,O0={appId:"1234",type:"superpeer",...X&&{password:X},...z&&{relayUrls:z},...q&&{turnConfig:q},...T&&{cells:!0},...T&&T!==!0&&{overlay:T},rtcPolyfill:V??NK};if($=MI(O0,Q0),B=$.channel("syncGraph"),console.info(`\u26A1 Transport: ${T?"cellular mesh":"full mesh"}`),p){let y0=B.send;B={...B,send:async(X0)=>y0(await p.signOps(X0))},h.sm=p}if(!T){let y0=!1;$.channel("c0").on("message",()=>{if(y0)return;y0=!0,console.warn("\u26A0\uFE0F This room speaks Cellular Mesh \u2014 restart with --cells / GDB_CELLS=1 (CLI) or rtc: { cells: true } (module), or browser writes will never reach this superpeer.")})}if(x)h.room=MI(O0,`app-sync-${W}`),console.info("\u26A1 db.room joined \u2014 visible to monitors/presence");$.on("peer:join",(y0)=>{console.info("\u26A1 Peer connected:",y0);for(let X0 of[0,1500,4000,9000])setTimeout(()=>S0([{type:"sync",timestamp:l}]),X0)}),$.on("peer:leave",(y0)=>console.info("\u26A1 Peer disconnected:",y0)),B.on("message",async(y0)=>{let X0;try{X0=y0 instanceof Uint8Array||y0 instanceof ArrayBuffer?(()=>{let L0=qW(y0);return Array.isArray(L0)?L0:[L0]})():Array.isArray(y0)?y0:[y0]}catch(L0){return console.error("\u274C decode failed:",L0)}let D0=new Map([...new Set(X0.flatMap((L0)=>["id","sourceId","targetId"].map((H0)=>L0?.[H0]).filter(Boolean)))].map((L0)=>b.get(L0)?[L0,VD(b.get(L0))]:null).filter(Boolean));for(let L0 of I0)try{if(X0=await L0(X0,D0),!X0?.length)return}catch(H0){console.error("\u274C Middleware error:",H0);return}await D1(X0)}),console.info("\u2705 GenosRTC sync enabled")}catch(Q0){console.warn("\u26A0\uFE0F GenosRTC not available:",Q0.message)}if(a(),E(),v(),p){let Q0=g?.governanceRules??null;if(!Q0&&process.env.GDB_SM_RULES){let O0=process.env.GDB_SM_RULES.trim();try{if(O0.startsWith("["))Q0=JSON.parse(O0);else if(O0.startsWith("{"))Q0=[JSON.parse(O0)];else Q0=(await import(new URL(O0,`file://${process.cwd()}/`).href)).default}catch(y0){console.error("\u274C GOVERNANCE: could not load GDB_SM_RULES:",y0.message)}}if(Array.isArray(Q0)&&Q0.length)h.governance=E_(h,p,Q0,{customRoles:g?.customRoles??null})}if(D)h.relay=D;return Object.defineProperties(h,{syncChannel:{get:()=>B},hybridClock:{get:()=>m},graph:{get:()=>({getAllNodes:()=>b.getAllNodes(),get:(Q0)=>b.get(Q0)})}}),console.info(`\u2705 GDBServer [${W}] ready (bun:sqlite)`),h}if(import.meta.main){let W=new Set(["ECONNREFUSED","ECONNRESET","EHOSTUNREACH","ENETUNREACH","EADDRNOTAVAIL","ETIMEDOUT","EPIPE"]),Y=(Z)=>W.has(Z?.code)||W.has(Z?.errno),G=new Map,X=null,J=(Z="UNKNOWN")=>{let V=(G.get(Z)??0)+1;if(G.set(Z,V),V===1)console.warn("\u26A0\uFE0F Transient network error (ignored):",Z);X??=setTimeout(()=>{X=null;let U=[...G].filter(([,Q])=>Q>1).map(([Q,H])=>`${Q} \xD7${H}`).join(", ");if(U)console.warn("\u26A0\uFE0F Transient network errors (ignored, last 60s):",U);G.clear()},60000)};process.on("uncaughtException",(Z)=>{if(Y(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal:",Z?.message??Z),process.exit(1)}),process.on("unhandledRejection",(Z)=>{if(Y(Z))return J(Z?.code??Z?.errno);console.error("\u274C Fatal (rejection):",Z?.message??Z),process.exit(1)}),Mt().catch((Z)=>{console.error("\u274C Fatal:",Z.message),process.exit(1)})}export{Mt as gdbServer};
|